~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to modules/utils/utils.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (C) 2008 Juha Heinanen
5
5
 * Copyright (C) 2009 1&1 Internet AG
 
6
 * Copyright (C) 2013 Carsten Bock, ng-voice GmbH
6
7
 *
7
8
 * This file is part of Kamailio, a free SIP server.
8
9
 *
88
89
static void destroy(void);
89
90
 
90
91
/* Fixup functions to be defined later */
91
 
static int fixup_http_query(void** param, int param_no);
92
 
static int fixup_free_http_query(void** param, int param_no);
 
92
static int fixup_http_query_get(void** param, int param_no);
 
93
static int fixup_free_http_query_get(void** param, int param_no);
 
94
static int fixup_http_query_post(void** param, int param_no);
 
95
static int fixup_free_http_query_post(void** param, int param_no);
 
96
 
 
97
/* Wrappers for http_query to be defined later */
 
98
static int w_http_query(struct sip_msg* _m, char* _url, char* _result);
 
99
static int w_http_query_post(struct sip_msg* _m, char* _url, char* _post, char* _result);
93
100
 
94
101
/* forward function */
95
102
int utils_forward(struct sip_msg *msg, int id, int proto);
96
103
 
97
104
/* Exported functions */
98
105
static cmd_export_t cmds[] = {
99
 
    {"http_query", (cmd_function)http_query, 2, fixup_http_query,
100
 
     fixup_free_http_query,
 
106
    {"http_query", (cmd_function)w_http_query, 2, fixup_http_query_get,
 
107
     fixup_free_http_query_get,
 
108
     REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
 
109
    {"http_query", (cmd_function)w_http_query_post, 3, fixup_http_query_post,
 
110
     fixup_free_http_query_post,
101
111
     REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
102
112
    {"xcap_auth_status", (cmd_function)xcap_auth_status, 2, fixup_pvar_pvar,
103
113
     fixup_free_pvar_pvar, REQUEST_ROUTE},
319
329
 * Fix http_query params: url (string that may contain pvars) and
320
330
 * result (writable pvar).
321
331
 */
322
 
static int fixup_http_query(void** param, int param_no)
323
 
{
324
 
    if (param_no == 1) {
325
 
        return fixup_spve_null(param, 1);
326
 
    }
327
 
 
328
 
    if (param_no == 2) {
329
 
        if (fixup_pvar_null(param, 1) != 0) {
330
 
            LM_ERR("failed to fixup result pvar\n");
331
 
            return -1;
332
 
        }
333
 
        if (((pv_spec_t *)(*param))->setf == NULL) {
334
 
            LM_ERR("result pvar is not writeble\n");
335
 
            return -1;
336
 
        }
337
 
        return 0;
338
 
    }
339
 
 
340
 
    LM_ERR("invalid parameter number <%d>\n", param_no);
341
 
    return -1;
342
 
}
343
 
 
344
 
/*
345
 
 * Free http_query params.
346
 
 */
347
 
static int fixup_free_http_query(void** param, int param_no)
348
 
{
349
 
    if (param_no == 1) {
350
 
        LM_WARN("free function has not been defined for spve\n");
351
 
        return 0;
352
 
    }
353
 
 
354
 
    if (param_no == 2) {
355
 
        return fixup_free_pvar_null(param, 1);
356
 
    }
357
 
    
358
 
    LM_ERR("invalid parameter number <%d>\n", param_no);
359
 
    return -1;
360
 
}
361
 
 
 
332
static int fixup_http_query_get(void** param, int param_no)
 
333
{
 
334
    if (param_no == 1) {
 
335
        return fixup_spve_null(param, 1);
 
336
    }
 
337
 
 
338
    if (param_no == 2) {
 
339
        if (fixup_pvar_null(param, 1) != 0) {
 
340
            LM_ERR("failed to fixup result pvar\n");
 
341
            return -1;
 
342
        }
 
343
        if (((pv_spec_t *)(*param))->setf == NULL) {
 
344
            LM_ERR("result pvar is not writeble\n");
 
345
            return -1;
 
346
        }
 
347
        return 0;
 
348
    }
 
349
 
 
350
    LM_ERR("invalid parameter number <%d>\n", param_no);
 
351
    return -1;
 
352
}
 
353
 
 
354
/*
 
355
 * Free http_query params.
 
356
 */
 
357
static int fixup_free_http_query_get(void** param, int param_no)
 
358
{
 
359
    if (param_no == 1) {
 
360
        LM_WARN("free function has not been defined for spve\n");
 
361
        return 0;
 
362
    }
 
363
 
 
364
    if (param_no == 2) {
 
365
        return fixup_free_pvar_null(param, 1);
 
366
    }
 
367
    
 
368
    LM_ERR("invalid parameter number <%d>\n", param_no);
 
369
    return -1;
 
370
}
 
371
 
 
372
 
 
373
/*
 
374
 * Fix http_query params: url (string that may contain pvars) and
 
375
 * result (writable pvar).
 
376
 */
 
377
static int fixup_http_query_post(void** param, int param_no)
 
378
{
 
379
    if ((param_no == 1) || (param_no == 2)) {
 
380
        return fixup_spve_null(param, 1);
 
381
    }
 
382
 
 
383
    if (param_no == 3) {
 
384
        if (fixup_pvar_null(param, 1) != 0) {
 
385
            LM_ERR("failed to fixup result pvar\n");
 
386
            return -1;
 
387
        }
 
388
        if (((pv_spec_t *)(*param))->setf == NULL) {
 
389
            LM_ERR("result pvar is not writeble\n");
 
390
            return -1;
 
391
        }
 
392
        return 0;
 
393
    }
 
394
 
 
395
    LM_ERR("invalid parameter number <%d>\n", param_no);
 
396
    return -1;
 
397
}
 
398
 
 
399
/*
 
400
 * Free http_query params.
 
401
 */
 
402
static int fixup_free_http_query_post(void** param, int param_no)
 
403
{
 
404
    if ((param_no == 1) || (param_no == 2)) {
 
405
        LM_WARN("free function has not been defined for spve\n");
 
406
        return 0;
 
407
    }
 
408
 
 
409
    if (param_no == 3) {
 
410
        return fixup_free_pvar_null(param, 1);
 
411
    }
 
412
    
 
413
    LM_ERR("invalid parameter number <%d>\n", param_no);
 
414
    return -1;
 
415
}
 
416
 
 
417
/*
 
418
 * Wrapper for HTTP-Query (GET)
 
419
 */
 
420
static int w_http_query(struct sip_msg* _m, char* _url, char* _result) {
 
421
        return http_query(_m, _url, _result, NULL);
 
422
}
 
423
 
 
424
 
 
425
/*
 
426
 * Wrapper for HTTP-Query (POST-Variant)
 
427
 */
 
428
static int w_http_query_post(struct sip_msg* _m, char* _url, char* _post, char* _result) {
 
429
        return http_query(_m, _url, _result, _post);
 
430
}
362
431
 
363
432
/*!
364
433
 * \brief checks precondition, switch, filter and forwards msg if necessary