h350_mod.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: $
00003  *
00004  * Kamailio H.350 Module
00005  *
00006  * Copyright (C) 2007 University of North Carolina
00007  *
00008  * Original author: Christian Schlatter, cs@unc.edu
00009  * 
00010  *
00011  * This file is part of Kamailio, a free SIP server.
00012  *
00013  * Kamailio is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version
00017  *
00018  * Kamailio is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * History:
00028  * --------
00029  * 2007-03-12: Initial version
00030  */
00031 
00032 #include "../../ut.h"
00033 #include "../../sr_module.h"
00034 #include "h350_mod.h"
00035 #include "h350_exp_fn.h"
00036 
00037 
00038 MODULE_VERSION
00039 
00040 /*
00041  * Module management function prototypes
00042  */
00043 static int mod_init(void);
00044 static int child_init(int rank);
00045 
00046 /*
00047  * fixup functions
00048  */
00049 static int one_str_pv_elem_fixup(void** param, int param_no);
00050 static int h350_auth_lookup_fixup(void** param, int param_no);
00051 
00052 /*
00053  * exported functions
00054  */
00055 
00056 static int w_h350_sipuri_lookup(struct sip_msg* msg, char* sip_uri, char* s2);
00057 static int w_h350_auth_lookup(struct sip_msg* msg, char* digest_username, char* avp_specs);
00058 static int w_h350_call_preferences(struct sip_msg* msg, char* avp_name_prefix, char* s2);
00059 static int w_h350_service_level(struct sip_msg* msg, char* avp_name_prefix, char* s2);
00060 
00061 /*
00062  * Module parameter variables
00063  */
00064 str h350_ldap_session = str_init(H350_LDAP_SESSION);
00065 str h350_base_dn = str_init(H350_BASE_DN);
00066 str h350_search_scope = str_init(H350_SEARCH_SCOPE);
00067 int h350_search_scope_int = -1;
00068 
00069 
00070 /*
00071  * LDAP API
00072  */
00073 ldap_api_t ldap_api;
00074 
00075 /*
00076  * Exported functions
00077  */
00078 static cmd_export_t cmds[] = {
00079    {"h350_sipuri_lookup",           (cmd_function)w_h350_sipuri_lookup,     1,
00080     one_str_pv_elem_fixup, 0,
00081     REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00082    {"h350_auth_lookup",             (cmd_function)w_h350_auth_lookup,       2,
00083     h350_auth_lookup_fixup, 0,
00084     REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00085    {"h350_result_call_preferences", (cmd_function)w_h350_call_preferences,  1,
00086     one_str_pv_elem_fixup, 0,
00087     REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00088    {"h350_result_service_level",    (cmd_function)w_h350_service_level,     1,
00089     one_str_pv_elem_fixup, 0,
00090     REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00091    {0, 0, 0, 0, 0, 0}
00092 };
00093 
00094 
00095 /*
00096  * Exported parameters
00097  */
00098 static param_export_t params[] = {
00099    {"ldap_session",     STR_PARAM, &h350_ldap_session.s},
00100    {"base_dn",          STR_PARAM, &h350_base_dn.s},
00101    {"search_scope",     STR_PARAM, &h350_search_scope.s},
00102    {0, 0, 0}
00103 };
00104 
00105 
00106 /*
00107  * Module interface
00108  */
00109 struct module_exports exports = {
00110    "h350", 
00111    DEFAULT_DLFLAGS, /* dlopen flags */
00112    cmds,       /* Exported functions */
00113    params,     /* Exported parameters */
00114    0,          /* exported statistics */
00115    0,          /* exported MI functions */
00116    0,          /* exported pseudo-variables */
00117    0,          /* extra processes */
00118    mod_init,   /* module initialization function */
00119    0,          /* response function */
00120    0,          /* destroy function */
00121    child_init  /* child initialization function */
00122 };
00123 
00124 static int child_init(int rank)
00125 {
00126    
00127    /* don't do anything for non-worker process */
00128         if (rank < 1) {
00129          return 0;
00130    }
00131 
00132    h350_search_scope_int = ldap_api.ldap_str2scope(h350_search_scope.s);
00133 
00134         /*
00135          * initialize h350_exp_fn
00136          */
00137         if (h350_exp_fn_init() != 0)
00138         {
00139                  LM_ERR("h350_exp_fn_init failed\n");
00140                  return -1;
00141         }
00142 
00143    
00144    return 0;
00145 }
00146 
00147 
00148 static int mod_init(void)
00149 {
00150    /*
00151     * load the LDAP API
00152     */
00153    if (load_ldap_api(&ldap_api) != 0)
00154    {
00155       LM_ERR("Unable to load LDAP API - this module requires ldap module\n");
00156       return -1;
00157    }
00158 
00159    return 0;
00160 
00161    /*
00162     * check module parameters
00163     */
00164    if (ldap_api.ldap_str2scope(h350_search_scope.s) == -1)
00165    {
00166       LM_ERR("Invalid search_scope [%s]\n", h350_search_scope.s);
00167       return -1;
00168    }
00169    
00170 }
00171 
00172 
00173 /*
00174  * EXPORTED functions
00175  */
00176 static int w_h350_sipuri_lookup(struct sip_msg* msg, char* sip_uri, char* s2)
00177 {
00178    return h350_sipuri_lookup(msg, (pv_elem_t*)sip_uri);
00179 }
00180 
00181 static int w_h350_auth_lookup(struct sip_msg* msg, char* digest_username, char* avp_specs)
00182 {
00183    return h350_auth_lookup(
00184       msg, 
00185       (pv_elem_t*)digest_username, 
00186       (struct h350_auth_lookup_avp_params*)avp_specs);
00187 }
00188 
00189 static int w_h350_call_preferences(struct sip_msg* msg, char* avp_name_prefix, char* s2)
00190 {
00191    return h350_call_preferences(msg, (pv_elem_t*)avp_name_prefix);
00192 }
00193 
00194 static int w_h350_service_level(struct sip_msg* msg, char* avp_name_prefix, char* s2)
00195 {
00196    return h350_service_level(msg, (pv_elem_t*)avp_name_prefix);
00197 }
00198 
00199 /*
00200  * FIXUP functions
00201  */
00202 
00203 static int one_str_pv_elem_fixup(void** param, int param_no)
00204 {
00205    pv_elem_t *model;
00206    str s;
00207 
00208    if (param_no == 1) {
00209       s.s = (char*)*param;
00210       if (s.s==0 || s.s[0]==0) {
00211          model = 0;
00212       } else {
00213          s.len = strlen(s.s);
00214          if (pv_parse_format(&s,&model)<0) {
00215             LM_ERR("pv_parse_format failed\n");
00216             return E_OUT_OF_MEM;
00217          }
00218       }
00219       *param = (void*)model;
00220    }
00221 
00222    return 0;
00223 }
00224 
00225 static int h350_auth_lookup_fixup(void** param, int param_no)
00226 {
00227    pv_elem_t *model;
00228     char *p, *username_avp_spec_str, *pwd_avp_spec_str;
00229    str s;
00230    struct h350_auth_lookup_avp_params *params;
00231 
00232     if (param_no == 1) 
00233    {
00234       s.s = (char*)*param;
00235       if (s.s==0 || s.s[0]==0) {
00236             model = 0;
00237       } else {
00238             if (pv_parse_format(&s,&model)<0) {
00239                 LM_ERR("pv_parse_format failed\n");
00240                 return E_OUT_OF_MEM;
00241             }
00242         }
00243         *param = (void*)model;
00244     } else if (param_no == 2) {
00245       /*
00246        * parse *param into username_avp_spec_str and pwd_avp_spec_str
00247        */
00248       
00249       username_avp_spec_str = (char*)*param;
00250       if ((pwd_avp_spec_str = strchr(username_avp_spec_str, '/')) == 0)
00251       {
00252          /* no '/' found in username_avp_spec_str */
00253          LM_ERR("invalid second argument [%s]\n", username_avp_spec_str);
00254          return E_UNSPEC;
00255       }
00256       *(pwd_avp_spec_str++) = 0;
00257 
00258       /*
00259        * parse avp specs into pv_spec_t and store in params
00260        */
00261       params = (struct h350_auth_lookup_avp_params*)pkg_malloc
00262             (sizeof(struct h350_auth_lookup_avp_params));
00263       if (params == NULL)
00264       {
00265          LM_ERR("no memory\n");
00266          return E_OUT_OF_MEM;
00267       }
00268       memset(params, 0, sizeof(struct h350_auth_lookup_avp_params));
00269       s.s = username_avp_spec_str; s.len = strlen(s.s);
00270       p = pv_parse_spec(&s, &params->username_avp_spec);
00271       if (p == 0)
00272       {
00273          pkg_free(params);
00274          LM_ERR("parse error for [%s]\n", username_avp_spec_str);
00275          return E_UNSPEC;
00276       }
00277       if (params->username_avp_spec.type != PVT_AVP)
00278       {
00279          pkg_free(params);
00280          LM_ERR("invalid AVP specification [%s]\n", username_avp_spec_str);
00281          return E_UNSPEC;
00282       }
00283       s.s = pwd_avp_spec_str; s.len =  strlen(s.s);
00284       p = pv_parse_spec(&s, &params->password_avp_spec);
00285                 if (p == 0)
00286                 {
00287                         pkg_free(params);
00288                         LM_ERR("parse error for [%s]\n", pwd_avp_spec_str);
00289                         return E_UNSPEC;
00290                 }
00291                 if (params->password_avp_spec.type != PVT_AVP)
00292                 {
00293                         pkg_free(params);
00294                         LM_ERR("invalid AVP specification [%s]\n", pwd_avp_spec_str);
00295                         return E_UNSPEC;
00296                 }
00297 
00298       *param = (void*)params;
00299    }
00300 
00301         return 0;
00302 }

Generated on Wed May 23 06:00:45 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6