• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

sr_module.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2003 FhG Fokus
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * For a license to use the ser software under conditions
00012  * other than those described here, or to purchase support for this
00013  * software, please contact iptel.org by e-mail at the following addresses:
00014  *    info@iptel.org
00015  *
00016  * ser is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 /*
00027  * History:
00028  * --------
00029  *  2003-03-10  changed module exports interface: added struct cmd_export
00030  *               and param_export (andrei)
00031  *  2003-03-16  Added flags field to cmd_export_ (janakj)
00032  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
00033  *  2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
00034  *              instead of copying the param value, a func is called (bogdan)
00035  *  2004-09-19  switched to version.h for the module versions checks (andrei)
00036  *  2004-12-03  changed param_func_t to (modparam_t, void*), killed
00037  *               param_func_param_t   (andrei)
00038  *  2007-06-07  added PROC_INIT, called in the main process context
00039  *               (same as PROC_MAIN), buf guaranteed to be called before
00040  *               any other process is forked (andrei)
00041  *  2008-11-17  sip-router version: includes some of the openser/kamailio
00042  *               changes: f(void) instead of f(), free_fixup_function()
00043  *              dual module interface support: ser & kamailio (andrei)
00044  *  2008-11-18  prototypes for various fixed parameters numbers module
00045  *               functions (3, 4, 5 & 6) and variable parameters (andrei)
00046  *  2008-11-26  added fparam_free_contents() and fix_param_types (andrei)
00047  */
00048 
00057 #ifndef sr_module_h
00058 #define sr_module_h
00059 
00060 #include <dlfcn.h>
00061 
00062 #include "parser/msg_parser.h" /* for sip_msg */
00063 #include "ver_defs.h"
00064 #include "rpc.h"
00065 #include "route_struct.h"
00066 #include "route.h"
00067 #include "str.h"
00068 
00069 /* kamailio compat */
00070 #include "kstats_types.h"
00071 #include "mi/mi_types.h"
00072 #include "pvar.h"
00073 
00074 
00075 
00076 #if defined KAMAILIO_MOD_INTERFACE || defined OPENSER_MOD_INTERFACE || \
00077         defined MOD_INTERFACE_V1
00078 
00079 #define MODULE_INTERFACE_VER 1
00080 #define cmd_export_t kam_cmd_export_t
00081 #define module_exports kam_module_exports
00082 
00083 #elif defined SER_MOD_INTERFACE || defined MOD_INTERFACE_V0
00084 
00085 #define MODULE_INTERFACE_VER 0
00086 #define cmd_export_t ser_cmd_export_t
00087 #define module_exports ser_module_exports
00088 
00089 #else
00090 
00091 /* do nothing for core */
00092 
00093 #endif
00094 
00109 typedef  int (*mod_register_function)(char* path, int* dlflags, void* reserved1, void* reserved2);
00110 
00111 typedef  struct module_exports* (*module_register)(void);
00112 
00122 typedef  int (*cmd_function)(struct sip_msg*, char* param1, char* param2);
00123 typedef  int (*cmd_function3)(struct sip_msg*, char*, char*, char*);
00124 typedef  int (*cmd_function4)(struct sip_msg*, char*, char*, char*, char*);
00125 typedef  int (*cmd_function5)(struct sip_msg*,  char*, char*, char*,
00126                                                                                                 char*, char*);
00127 typedef  int (*cmd_function6)(struct sip_msg*,  char*, char*, char*,
00128                                                                                                 char*, char*, char*);
00139 typedef int (*cmd_function_var)(struct sip_msg*, int no, action_u_t* vals );
00140 typedef int (*fixup_function)(void** param, int param_no);
00141 typedef int (*free_fixup_function)(void** param, int param_no);
00142 
00148 typedef int (*response_function)(struct sip_msg*);
00149 typedef void (*onbreak_function)(struct sip_msg*);
00150 typedef void (*destroy_function)(void);
00151 
00152 typedef int (*init_function)(void);
00153 typedef int (*child_init_function)(int rank);
00154 
00155 
00156 #define PARAM_STRING     (1U<<0)  
00157 #define PARAM_INT        (1U<<1)  
00158 #define PARAM_STR        (1U<<2)  
00159 #define PARAM_USE_FUNC   (1U<<(8*sizeof(int)-1))
00160 #define PARAM_TYPE_MASK(_x)   ((_x)&(~PARAM_USE_FUNC))
00161 
00162 /* temporary, for backward compatibility only until all modules adjust it */
00163 #define STR_PARAM PARAM_STRING
00164 #define INT_PARAM PARAM_INT
00165 #define USE_FUNC_PARAM PARAM_USE_FUNC
00166 
00167 typedef unsigned int modparam_t;
00168 
00169 typedef int (*param_func_t)( modparam_t type, void* val);
00170 
00171 /* magic parameter number values */
00172 
00173 #define NO_SCRIPT     -1    
00174 #define VAR_PARAM_NO  -128  
00181 #define FIXUP_F_FPARAM_RVE (unsigned long)1
00182 
00183 #define call_fixup(fixup, param, param_no) \
00184         ((fixup) ? (fixup)(param, param_no) : 0)
00185 
00186 /* Macros - used as rank in child_init function */
00187 #define PROC_MAIN      0  
00188 #define PROC_TIMER    -1  
00189 #define PROC_RPC      -2  
00190 #define PROC_FIFO      PROC_RPC  
00191 #define PROC_TCP_MAIN -4  
00192 #define PROC_UNIXSOCK -5  
00193 #define PROC_ATTENDANT -10  
00194 #define PROC_INIT     -127 
00204 #define PROC_NOCHLDINIT -128 
00207 #define PROC_SIPINIT      1  
00209 #define PROC_SIPRPC       127  
00214 #define PROC_MIN PROC_NOCHLDINIT 
00217 #define DEFAULT_DLFLAGS 0 
00219 #ifndef RTLD_NOW
00220 /* for openbsd */
00221 #define RTLD_NOW DL_LAZY
00222 #endif
00223 
00224 #define KAMAILIO_DLFLAGS        RTLD_NOW
00225 
00226 
00227 #define MODULE_VERSION \
00228         char *module_version=SER_FULL_VERSION; \
00229         char *module_flags=SER_COMPILE_FLAGS; \
00230         unsigned int module_interface_ver=MODULE_INTERFACE_VER; 
00231 
00233 struct ser_cmd_export_ {
00234         char* name;             
00235         cmd_function function;  
00236         int param_no;           
00237         fixup_function fixup;   
00239         int flags;              
00240 };
00241 
00242 
00244 struct kam_cmd_export_ {
00245         char* name;             
00246         cmd_function function;  
00247         int param_no;           
00248         fixup_function fixup;   
00250         free_fixup_function free_fixup; 
00252         int flags;              
00253 };
00254 
00256 struct sr31_cmd_export_ {
00257         char* name;             
00258         cmd_function function;  
00259         int param_no;           
00260         fixup_function fixup;   
00262         free_fixup_function free_fixup; 
00264         int flags;              
00265         int fixup_flags;
00266         void* module_exports; 
00267 };
00268 
00269 
00272 struct cmd_export_common_ {
00273         char* name;
00274         cmd_function function; 
00275         int param_no;
00276         fixup_function fixup;
00277 };
00278 
00279 
00280 struct param_export_ {
00281         char* name;             
00282         modparam_t type;        
00283         void* param_pointer;    
00284 };
00285 
00286 
00287 /*
00288  * Allowed parameter types, the types _must_ be in "fallback" order,
00289  * e.g. FPARAM_STR should be the last to allow fallback to it,
00290  * F_PARAM_PVS should be in front of F_PARAM_AVP (so that
00291  * for fix_param_types(FPARAM_AVP|FPARAM_PVS|FPARAM_STR, param) and $foo
00292  * the pvars will be checked first and only if no pvar is found the
00293  * param will be resolved to an avp)
00294  */
00295 enum {
00296         FPARAM_UNSPEC = 0,
00297         FPARAM_INT    = (1 << 0),
00298         FPARAM_SELECT = (1 << 1),
00299         FPARAM_PVS    = (1 << 2),
00300         FPARAM_AVP    = (1 << 3),
00301         FPARAM_STRING = (1 << 4),
00302         FPARAM_STR    = (1 << 5),
00303         /* special types: no fallback between them possible */
00304         FPARAM_REGEX  = (1 << 6),
00305         FPARAM_SUBST  = (1 << 7),
00306         FPARAM_PVE    = (1 << 8)
00307 };
00308 
00312 typedef struct fparam {
00313         char* orig;                       
00314         int type;                         
00315         union {
00316                 char* asciiz;             
00317                 struct _str str;          
00318                 int i;                    
00319                 regex_t* regex;           
00320                 avp_ident_t avp;          
00321                 select_t* select;         
00322                 struct subst_expr* subst; 
00323                 pv_spec_t* pvs;    
00324                 pv_elem_t* pve;    
00325         } v;
00326         void *fixed;
00327 } fparam_t;
00328 
00329 
00330 typedef struct param_export_ param_export_t;  
00331 typedef struct ser_cmd_export_ ser_cmd_export_t;
00332 typedef struct kam_cmd_export_ kam_cmd_export_t;
00333 typedef struct cmd_export_common_ cmd_export_common_t;
00334 typedef struct sr31_cmd_export_ sr31_cmd_export_t;
00335 
00336 
00338 struct ser_module_exports {
00339         char* name;                     
00340         ser_cmd_export_t* cmds;         
00342         rpc_export_t* rpc_methods;      
00343         param_export_t* params;         
00345         init_function init_f;           
00346         response_function response_f;   
00348         destroy_function destroy_f;     
00351         onbreak_function onbreak_f;
00352         child_init_function init_child_f;  
00354 };
00355 
00356 
00358 typedef void (*mod_proc)(int no);
00359 
00360 typedef int (*mod_proc_wrapper)(void);
00361 
00362 struct proc_export_ {
00363         char *name;
00364         mod_proc_wrapper pre_fork_function;
00365         mod_proc_wrapper post_fork_function;
00366         mod_proc function;
00367         unsigned int no;
00368 };
00369 
00370 typedef struct proc_export_ proc_export_t;
00371 
00372 
00374 struct kam_module_exports {
00375         char* name;                             
00376         unsigned int dlflags;                   
00377         kam_cmd_export_t* cmds;                 
00379         param_export_t* params;                 
00381         stat_export_t* stats;                   
00383         mi_export_t* mi_cmds;                   
00385         pv_export_t* items;                             
00387         proc_export_t* procs;                   
00390         init_function init_f;                   
00391         response_function response_f;           
00393         destroy_function destroy_f;                     
00396         child_init_function init_child_f;       
00398 };
00399 
00400 
00401 
00411 struct sr31_module_exports {
00412         char* name;                     
00413         sr31_cmd_export_t* cmds;        
00415         param_export_t* params;         
00417         init_function init_f;           
00418         response_function response_f;   
00420         destroy_function destroy_f;     
00423         onbreak_function onbreak_f;
00424         child_init_function init_child_f;
00426         unsigned int dlflags;           
00427         /* ser specific exports
00428            (to be obsoleted and replaced by register_...) */
00429         rpc_export_t* rpc_methods;      
00431         /* kamailio specific exports
00432            (to be obsoleted and replaced by register_...) */
00433         stat_export_t* stats;                   
00435         mi_export_t* mi_cmds;                   
00437         pv_export_t* items;                     
00439         proc_export_t* procs;                   
00442 };
00443 
00444 
00445 
00447 struct module_exports_common {
00448         char* name;
00449 };
00450 
00451 
00452 union module_exports_u {
00453                 struct module_exports_common c; 
00454                 struct ser_module_exports v0;
00455                 struct kam_module_exports v1;
00456 };
00457 
00458 
00459 struct sr_module {
00460         char* path;
00461         void* handle;
00462         unsigned int orig_mod_interface_ver;
00463         struct sr31_module_exports exports;
00464         struct sr_module* next;
00465 };
00466 
00467 
00468 extern struct sr_module* modules; 
00469 extern response_function* mod_response_cbks; 
00470 extern int mod_response_cbk_no; 
00472 int register_builtin_modules(void);
00473 int load_module(char* path);
00474 sr31_cmd_export_t* find_export_record(char* name, int param_no, int flags,
00475                                                                                 unsigned *ver);
00476 cmd_function find_export(char* name, int param_no, int flags);
00477 cmd_function find_mod_export(char* mod, char* name, int param_no, int flags);
00478 rpc_export_t* find_rpc_export(char* name, int flags);
00479 void destroy_modules(void);
00480 int init_child(int rank);
00481 int init_modules(void);
00482 struct sr_module* find_module_by_name(char* mod);
00483 
00485 #define module_loaded(mod_name) (find_module_by_name(mod_name)!=0)
00486 
00487 
00496 void* find_param_export(struct sr_module* mod, char* name, modparam_t type_mask, modparam_t *param_type);
00497 
00498 
00500 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
00501 int fixup_get_param_count(void **cur_param, int cur_param_no);
00502 
00503 int fix_flag( modparam_t type, void* val,
00504                                         char* mod_name, char* param_name, int* flag);
00505 
00506 
00507 /*
00508  * Common function parameter fixups
00509  */
00510 
00520 int fix_param(int type, void** param);
00521 void fparam_free_contents(fparam_t* fp);
00522 
00525 int fix_param_types(int types, void** param);
00526 
00537 int fixup_var_str_12(void** param, int param_no);
00538 
00540 int fixup_var_str_1(void** param, int param_no);
00541 
00543 int fixup_var_str_2(void** param, int param_no);
00544 
00546 int fixup_var_pve_12(void** param, int param_no);
00547 
00552 int fixup_var_pve_str_12(void** param, int param_no);
00553 
00555 int fixup_var_pve_str_1(void** param, int param_no);
00556 
00558 int fixup_var_pve_str_2(void** param, int param_no);
00559 
00571 int fixup_var_int_12(void** param, int param_no);
00572 
00574 int fixup_var_int_1(void** param, int param_no);
00575 
00577 int fixup_var_int_2(void** param, int param_no);
00578 
00583 int fixup_regex_12(void** param, int param_no);
00584 
00586 int fixup_regex_1(void** param, int param_no);
00587 
00589 int fixup_regex_2(void** param, int param_no);
00590 
00594 int fixup_int_12(void** param, int param_no);
00595 
00597 int fixup_int_1(void** param, int param_no);
00598 
00600 int fixup_int_2(void** param, int param_no);
00601 
00606 int fixup_str_12(void** param, int param_no);
00607 
00609 int fixup_str_1(void** param, int param_no);
00610 
00612 int fixup_str_2(void** param, int param_no);
00613 
00621 int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param);
00622 
00630 int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param);
00631 
00639 int get_regex_fparam(regex_t *dst, struct sip_msg* msg, fparam_t* param);
00640 
00641 
00642 int is_fparam_rve_fixup(fixup_function f);
00643 
00652 void fparam_free_restore(void** param);
00653 int fixup_free_fparam_all(void** param, int param_no);
00654 int fixup_free_fparam_1(void** param, int param_no);
00655 int fixup_free_fparam_2(void** param, int param_no);
00656 
00666 free_fixup_function get_fixup_free(fixup_function f);
00667 
00668 void set_child_sip_rpc_mode(void);
00669 void set_child_rpc_sip_mode(void);
00670 int is_sip_worker(int rank);
00671 int is_rpc_worker(int rank);
00672 
00673 #endif /* sr_module_h */

Generated on Tue May 22 2012 13:10:15 for SIP Router by  doxygen 1.7.1