siputils.c

Go to the documentation of this file.
00001 /*
00002  * $Id: siputils.c 5397 2008-12-30 08:51:56Z miconda $
00003  *
00004  * Copyright (C) 2008-2009 1&1 Internet AG
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of Kamailio, a free SIP server.
00008  *
00009  * Kamailio is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * Kamailio is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License 
00020  * along with this program; if not, write to the Free Software 
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 /**
00025  * \file
00026  * \brief Module with several utiltity functions related to SIP messages handling
00027  * \ingroup utils
00028  * - Module; \ref utils
00029  */
00030 
00031 /*!
00032  * \defgroup utils UTILS :: Module definitions
00033  */
00034 
00035 #include <assert.h>
00036 
00037 #include "../../sr_module.h"
00038 #include "../../mem/mem.h"
00039 #include "../../dprint.h"
00040 #include "../../script_cb.h"
00041 #include "../../locking.h"
00042 #include "../../ut.h"
00043 #include "../../mod_fix.h"
00044 #include "../../error.h"
00045 
00046 #include "ring.h"
00047 #include "options.h"
00048 
00049 #include "checks.h"
00050 
00051 #include "utils.h"
00052 #include "contact_ops.h"
00053 #include "sipops.h"
00054 
00055 MODULE_VERSION
00056 
00057 gen_lock_t *ring_lock = NULL;
00058 unsigned int ring_timeout = 0;
00059 /* for options functionality */
00060 str opt_accept = str_init(ACPT_DEF);
00061 str opt_accept_enc = str_init(ACPT_ENC_DEF);
00062 str opt_accept_lang = str_init(ACPT_LAN_DEF);
00063 str opt_supported = str_init(SUPT_DEF);
00064 /** SL binds */
00065 struct sl_binds opt_slb;
00066 
00067 static int mod_init(void);
00068 static void mod_destroy(void);
00069 
00070 char *contact_flds_separator = DEFAULT_SEPARATOR;
00071 
00072 static cmd_export_t cmds[]={
00073    {"ring_insert_callid", (cmd_function)ring_insert_callid, 0, ring_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00074    {"options_reply",      (cmd_function)opt_reply, 0, 0, 0, REQUEST_ROUTE},
00075    {"is_user",            (cmd_function)is_user,        1, fixup_str_null, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00076    {"has_totag",         (cmd_function)has_totag,      0, 0, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00077    {"uri_param",          (cmd_function)uri_param_1,    1, fixup_str_null, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00078    {"uri_param",          (cmd_function)uri_param_2,    2, fixup_str_str, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00079    {"add_uri_param",      (cmd_function)add_uri_param,  1, fixup_str_null, 0, REQUEST_ROUTE},
00080    {"tel2sip",            (cmd_function)tel2sip,        0, 0,         0, REQUEST_ROUTE},
00081    {"is_uri_user_e164",   (cmd_function)is_uri_user_e164, 1, fixup_pvar_null, fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
00082    {"encode_contact",     (cmd_function)encode_contact,2,0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
00083    {"decode_contact",     (cmd_function)decode_contact,0,0, 0, REQUEST_ROUTE},
00084    {"decode_contact_header", (cmd_function)decode_contact_header,0,0,0,REQUEST_ROUTE|ONREPLY_ROUTE},
00085    {"cmp_uri",  (cmd_function)w_cmp_uri, 2,
00086       fixup_spve_spve, 0,
00087       REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
00088    {"cmp_aor",  (cmd_function)w_cmp_aor, 2,
00089       fixup_spve_spve, 0,
00090       REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
00091    {0,0,0,0,0,0}
00092 };
00093 
00094 static param_export_t params[] = {
00095    {"ring_timeout",            INT_PARAM, &ring_timeout},
00096    {"options_accept",          STR_PARAM, &opt_accept.s},
00097    {"options_accept_encoding", STR_PARAM, &opt_accept_enc.s},
00098    {"options_accept_language", STR_PARAM, &opt_accept_lang.s},
00099    {"options_support",         STR_PARAM, &opt_supported.s},
00100    {"contact_flds_separator",  STR_PARAM,&contact_flds_separator},
00101    {0, 0, 0}
00102 };
00103 
00104 
00105 struct module_exports exports= {
00106    "siputils",
00107    DEFAULT_DLFLAGS, /* dlopen flags */
00108    cmds,            /* Exported functions */
00109    params,          /* param exports */
00110    0,               /* exported statistics */
00111    0,               /* exported MI functions */
00112    0,               /* exported pseudo-variables */
00113    0,               /* extra processes */
00114    mod_init,        /* initialization function */
00115    0,               /* Response function */
00116    mod_destroy,     /* Destroy function */
00117    0,               /* Child init function */
00118 };
00119 
00120 
00121 static int mod_init(void)
00122 {
00123    if(ring_timeout > 0) {
00124       ring_init_hashtable();
00125 
00126       ring_lock = lock_alloc();
00127       assert(ring_lock);
00128       if (lock_init(ring_lock) == 0) {
00129          LM_CRIT("cannot initialize lock.\n");
00130          return -1;
00131       }
00132       if (register_script_cb(ring_filter, PRE_SCRIPT_CB|RPL_TYPE_CB, 0) != 0) {
00133          LM_ERR("could not insert callback");
00134          return -1;
00135       }
00136    }
00137 
00138       /* load the SL API */
00139    if (load_sl_api(&opt_slb)!=0) {
00140       LM_ERR("can't load SL API\n");
00141       return -1;
00142    }
00143 
00144    opt_accept.len = strlen(opt_accept.s);
00145    opt_accept_enc.len = strlen(opt_accept_enc.s);
00146    opt_accept_lang.len = strlen(opt_accept_lang.s);
00147    opt_supported.len = strlen(opt_supported.s);
00148 
00149    return 0;
00150 }
00151 
00152 
00153 static void mod_destroy(void)
00154 {
00155    if (ring_lock) {
00156       lock_destroy(ring_lock);
00157       lock_dealloc((void *)ring_lock);
00158       ring_lock = NULL;
00159    }
00160 
00161    ring_destroy_hashtable();
00162 }

Generated on Thu May 24 12:00:30 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6