sr_module.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * @brief Kamailio core :: modules loading, structures declarations and utilities
  23. * @ingroup core
  24. * Module: \ref core
  25. */
  26. #include "sr_module.h"
  27. #include "mod_fix.h"
  28. #include "dprint.h"
  29. #include "error.h"
  30. #include "mem/mem.h"
  31. #include "core_cmd.h"
  32. #include "ut.h"
  33. #include "re.h"
  34. #include "route_struct.h"
  35. #include "flags.h"
  36. #include "trim.h"
  37. #include "pvapi.h"
  38. #include "globals.h"
  39. #include "rpc_lookup.h"
  40. #include "sr_compat.h"
  41. #include "ppcfg.h"
  42. #include "async_task.h"
  43. #include <sys/stat.h>
  44. #include <regex.h>
  45. #include <dlfcn.h>
  46. #include <strings.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stddef.h> /* for offsetof */
  50. struct sr_module* modules=0;
  51. /*We need to define this symbol on Solaris becuase libcurl relies on libnspr which looks for this symbol.
  52. If it is not defined, dynamic module loading (dlsym) fails */
  53. #ifdef __OS_solaris
  54. int nspr_use_zone_allocator = 0;
  55. #endif
  56. #ifdef STATIC_EXEC
  57. extern struct module_exports exec_exports;
  58. #endif
  59. #ifdef STATIC_TM
  60. extern struct module_exports tm_exports;
  61. #endif
  62. #ifdef STATIC_MAXFWD
  63. extern struct module_exports maxfwd_exports;
  64. #endif
  65. #ifdef STATIC_AUTH
  66. extern struct module_exports auth_exports;
  67. #endif
  68. #ifdef STATIC_RR
  69. extern struct module_exports rr_exports;
  70. #endif
  71. #ifdef STATIC_USRLOC
  72. extern struct module_exports usrloc_exports;
  73. #endif
  74. #ifdef STATIC_SL
  75. extern struct module_exports sl_exports;
  76. #endif
  77. #ifndef offsetof
  78. #warning "use null pointer dereference for offsetof"
  79. #define offsetof(st, m) \
  80. ((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))
  81. #endif
  82. int mod_response_cbk_no=0;
  83. response_function* mod_response_cbks=0;
  84. /* number of usec to wait before initializing a module */
  85. static unsigned int modinit_delay = 0;
  86. unsigned int set_modinit_delay(unsigned int v)
  87. {
  88. unsigned int r;
  89. r = modinit_delay;
  90. modinit_delay = v;
  91. return r;
  92. }
  93. /**
  94. * if bit 1 set, SIP worker processes handle RPC commands as well
  95. * if bit 2 set, RPC worker processes handle SIP commands as well
  96. */
  97. static int child_sip_rpc_mode = 0;
  98. #define CHILD_SIP_RPC 1<<0
  99. #define CHILD_RPC_SIP 1<<1
  100. void set_child_sip_rpc_mode(void)
  101. {
  102. child_sip_rpc_mode |= CHILD_SIP_RPC;
  103. }
  104. void set_child_rpc_sip_mode(void)
  105. {
  106. child_sip_rpc_mode |= CHILD_RPC_SIP;
  107. }
  108. int is_rpc_worker(int rank)
  109. {
  110. if(rank==PROC_RPC
  111. || (rank>PROC_MAIN && (child_sip_rpc_mode&CHILD_SIP_RPC)!=0))
  112. return 1;
  113. return 0;
  114. }
  115. int is_sip_worker(int rank)
  116. {
  117. if(rank>PROC_MAIN
  118. || ((rank==PROC_RPC || rank==PROC_NOCHLDINIT)
  119. && (child_sip_rpc_mode&CHILD_RPC_SIP)!=0))
  120. return 1;
  121. return 0;
  122. }
  123. /* initializes statically built (compiled in) modules*/
  124. int register_builtin_modules()
  125. {
  126. int ret;
  127. ret=0;
  128. #ifdef STATIC_TM
  129. ret=register_module(MODULE_INTERFACE_VER, &tm_exports,"built-in", 0);
  130. if (ret<0) return ret;
  131. #endif
  132. #ifdef STATIC_EXEC
  133. ret=register_module(MODULE_INTERFACE_VER, &exec_exports,"built-in", 0);
  134. if (ret<0) return ret;
  135. #endif
  136. #ifdef STATIC_MAXFWD
  137. ret=register_module(MODULE_INTERFACE_VER, &maxfwd_exports, "built-in", 0);
  138. if (ret<0) return ret;
  139. #endif
  140. #ifdef STATIC_AUTH
  141. ret=register_module(MODULE_INTERFACE_VER, &auth_exports, "built-in", 0);
  142. if (ret<0) return ret;
  143. #endif
  144. #ifdef STATIC_RR
  145. ret=register_module(MODULE_INTERFACE_VER, &rr_exports, "built-in", 0);
  146. if (ret<0) return ret;
  147. #endif
  148. #ifdef STATIC_USRLOC
  149. ret=register_module(MODULE_INTERFACE_VER, &usrloc_exports, "built-in", 0);
  150. if (ret<0) return ret;
  151. #endif
  152. #ifdef STATIC_SL
  153. ret=register_module(MODULE_INTERFACE_VER, &sl_exports, "built-in", 0);
  154. if (ret<0) return ret;
  155. #endif
  156. return ret;
  157. }
  158. /** convert cmd exports to current format.
  159. * @param ver - module interface versions (0 == ser, 1 == kam).
  160. * @param src - null terminated array of cmd exports
  161. * (either ser_cmd_export_t or kam_cmd_export_t, depending
  162. * on ver).
  163. * @param mod - pointer to module exports structure.
  164. * @return - pkg_malloc'ed null terminated sr_cmd_export_v31_t array with
  165. * the converted cmd exports or 0 on error.
  166. */
  167. static sr31_cmd_export_t* sr_cmd_exports_convert(unsigned ver,
  168. void* src, void* mod)
  169. {
  170. int i, n;
  171. ser_cmd_export_t* ser_cmd;
  172. kam_cmd_export_t* kam_cmd;
  173. sr31_cmd_export_t* ret;
  174. ser_cmd = 0;
  175. kam_cmd = 0;
  176. ret = 0;
  177. n = 0;
  178. /* count the number of elements */
  179. if (ver == 0) {
  180. ser_cmd = src;
  181. for (; ser_cmd[n].name; n++);
  182. } else if (ver == 1) {
  183. kam_cmd = src;
  184. for (; kam_cmd[n].name; n++);
  185. } else goto error; /* unknown interface version */
  186. /* alloc & init new array */
  187. ret = pkg_malloc(sizeof(*ret)*(n+1));
  188. memset(ret, 0, sizeof(*ret)*(n+1));
  189. /* convert/copy */
  190. for (i=0; i < n; i++) {
  191. if (ver == 0) {
  192. ret[i].name = ser_cmd[i].name;
  193. ret[i].function = ser_cmd[i].function;
  194. ret[i].param_no = ser_cmd[i].param_no;
  195. ret[i].fixup = ser_cmd[i].fixup;
  196. ret[i].free_fixup = 0; /* no present in ser <= 2.1 */
  197. ret[i].flags = ser_cmd[i].flags;
  198. } else {
  199. ret[i].name = kam_cmd[i].name;
  200. ret[i].function = kam_cmd[i].function;
  201. ret[i].param_no = kam_cmd[i].param_no;
  202. ret[i].fixup = kam_cmd[i].fixup;
  203. ret[i].free_fixup = kam_cmd[i].free_fixup;
  204. ret[i].flags = kam_cmd[i].flags;
  205. }
  206. /* 3.1+ specific stuff */
  207. ret[i].fixup_flags = 0;
  208. ret[i].module_exports = mod;
  209. /* fill known free fixups */
  210. if (ret[i].fixup && ret[i].free_fixup == 0)
  211. ret[i].free_fixup = get_fixup_free(ret[i].fixup);
  212. }
  213. return ret;
  214. error:
  215. return 0;
  216. }
  217. /* registers a module, register_f= module register functions
  218. * returns <0 on error, 0 on success */
  219. static int register_module(unsigned ver, union module_exports_u* e,
  220. char* path, void* handle)
  221. {
  222. int ret, i;
  223. struct sr_module* mod;
  224. char defmod[64];
  225. ret=-1;
  226. /* add module to the list */
  227. if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
  228. LM_ERR("memory allocation failure\n");
  229. ret=E_OUT_OF_MEM;
  230. goto error;
  231. }
  232. memset(mod,0, sizeof(struct sr_module));
  233. mod->path=path;
  234. mod->handle=handle;
  235. mod->orig_mod_interface_ver=ver;
  236. /* convert exports to sr31 format */
  237. if (ver == 0) {
  238. /* ser <= 3.0 */
  239. mod->exports.name = e->v0.name;
  240. if (e->v0.cmds) {
  241. mod->exports.cmds = sr_cmd_exports_convert(ver, e->v0.cmds, mod);
  242. if (mod->exports.cmds == 0) {
  243. LM_ERR("failed to convert module command exports to 3.1 format"
  244. " for module \"%s\" (%s), interface version %d\n",
  245. mod->exports.name, mod->path, ver);
  246. ret = E_UNSPEC;
  247. goto error;
  248. }
  249. }
  250. mod->exports.params = e->v0.params;
  251. mod->exports.init_f = e->v0.init_f;
  252. mod->exports.response_f = e->v0.response_f;
  253. mod->exports.destroy_f = e->v0.destroy_f;
  254. mod->exports.onbreak_f = e->v0.onbreak_f;
  255. mod->exports.init_child_f = e->v0.init_child_f;
  256. mod->exports.dlflags = 0; /* not used in ser <= 3.0 */
  257. mod->exports.rpc_methods = e->v0.rpc_methods;
  258. /* the rest are 0, not used in ser */
  259. } else if (ver == 1) {
  260. /* kamailio <= 3.0 */
  261. mod->exports.name = e->v1.name;
  262. if (e->v1.cmds) {
  263. mod->exports.cmds = sr_cmd_exports_convert(ver, e->v1.cmds, mod);
  264. if (mod->exports.cmds == 0) {
  265. LM_ERR("failed to convert module command exports to 3.1 format"
  266. " for module \"%s\" (%s), interface version %d\n",
  267. mod->exports.name, mod->path, ver);
  268. ret = E_UNSPEC;
  269. goto error;
  270. }
  271. }
  272. mod->exports.params = e->v1.params;
  273. mod->exports.init_f = e->v1.init_f;
  274. mod->exports.response_f = e->v1.response_f;
  275. mod->exports.destroy_f = e->v1.destroy_f;
  276. mod->exports.onbreak_f = 0; /* not used in k <= 3.0 */
  277. mod->exports.init_child_f = e->v1.init_child_f;
  278. mod->exports.dlflags = e->v1.dlflags;
  279. mod->exports.rpc_methods = 0; /* not used in k <= 3.0 */
  280. mod->exports.stats = e->v1.stats;
  281. mod->exports.mi_cmds = e->v1.mi_cmds;
  282. mod->exports.items = e->v1.items;
  283. mod->exports.procs = e->v1.procs;
  284. } else {
  285. LM_ERR("unsupported module interface version %d\n", ver);
  286. ret = E_UNSPEC;
  287. goto error;
  288. }
  289. if (mod->exports.items) {
  290. /* register module pseudo-variables for kamailio modules */
  291. LM_DBG("register PV from: %s\n", mod->exports.name);
  292. if (register_pvars_mod(mod->exports.name, mod->exports.items)!=0) {
  293. LM_ERR("failed to register pseudo-variables for module %s (%s)\n",
  294. mod->exports.name, path);
  295. ret = E_UNSPEC;
  296. goto error;
  297. }
  298. }
  299. if (mod->exports.rpc_methods){
  300. /* register rpcs for ser modules */
  301. i=rpc_register_array(mod->exports.rpc_methods);
  302. if (i<0){
  303. LM_ERR("failed to register RPCs for module %s (%s)\n",
  304. mod->exports.name, path);
  305. ret = E_UNSPEC;
  306. goto error;
  307. }else if (i>0){
  308. LM_ERR("%d duplicate RPCs name detected while registering RPCs"
  309. " declared in module %s (%s)\n",
  310. i, mod->exports.name, path);
  311. ret = E_UNSPEC;
  312. goto error;
  313. }
  314. /* i==0 => success */
  315. }
  316. /* add cfg define for each module: MOD_modulename */
  317. if(strlen(mod->exports.name)>=60) {
  318. LM_ERR("too long module name: %s\n", mod->exports.name);
  319. goto error;
  320. }
  321. strcpy(defmod, "MOD_");
  322. strcat(defmod, mod->exports.name);
  323. pp_define_set_type(0);
  324. if(pp_define(strlen(defmod), defmod)<0) {
  325. LM_ERR("unable to set cfg define for module: %s\n",
  326. mod->exports.name);
  327. goto error;
  328. }
  329. /* link module in the list */
  330. mod->next=modules;
  331. modules=mod;
  332. return 0;
  333. error:
  334. if (mod)
  335. pkg_free(mod);
  336. return ret;
  337. }
  338. #ifndef DLSYM_PREFIX
  339. /* define it to null */
  340. #define DLSYM_PREFIX
  341. #endif
  342. static inline int version_control(void *handle, char *path)
  343. {
  344. char **m_ver;
  345. char **m_flags;
  346. char* error;
  347. m_ver=(char **)dlsym(handle, DLSYM_PREFIX "module_version");
  348. if ((error=(char *)dlerror())!=0) {
  349. LM_ERR("no version info in module <%s>: %s\n", path, error);
  350. return 0;
  351. }
  352. m_flags=(char **)dlsym(handle, DLSYM_PREFIX "module_flags");
  353. if ((error=(char *)dlerror())!=0) {
  354. LM_ERR("no compile flags info in module <%s>: %s\n", path, error);
  355. return 0;
  356. }
  357. if (!m_ver || !(*m_ver)) {
  358. LM_ERR("no version in module <%s>\n", path );
  359. return 0;
  360. }
  361. if (!m_flags || !(*m_flags)) {
  362. LM_ERR("no compile flags in module <%s>\n", path );
  363. return 0;
  364. }
  365. if (strcmp(SER_FULL_VERSION, *m_ver)==0){
  366. if (strcmp(SER_COMPILE_FLAGS, *m_flags)==0)
  367. return 1;
  368. else {
  369. LM_ERR("module compile flags mismatch for %s "
  370. " \ncore: %s \nmodule: %s\n",
  371. path, SER_COMPILE_FLAGS, *m_flags);
  372. return 0;
  373. }
  374. }
  375. LM_ERR("module version mismatch for %s; "
  376. "core: %s; module: %s\n", path, SER_FULL_VERSION, *m_ver );
  377. return 0;
  378. }
  379. /**
  380. * \brief load a sr module
  381. *
  382. * tries to load the module specified by mod_path.
  383. * If mod_path is 'modname' or 'modname.so' then
  384. * \<MODS_DIR\>/\<modname\>.so will be tried and if this fails
  385. * \<MODS_DIR\>/\<modname\>/\<modname\>.so
  386. * If mod_path contain a '/' it is assumed to be the
  387. * path to the module and tried first. If fails and mod_path is not
  388. * absolute path (not starting with '/') then will try:
  389. * \<MODS_DIR\>/mod_path
  390. * @param mod_path path or module name
  391. * @return 0 on success , <0 on error
  392. */
  393. int load_module(char* mod_path)
  394. {
  395. void* handle;
  396. char* error;
  397. mod_register_function mr;
  398. union module_exports_u* exp;
  399. unsigned* mod_if_ver;
  400. struct sr_module* t;
  401. struct stat stat_buf;
  402. str modname;
  403. char* mdir;
  404. char* nxt_mdir;
  405. char* path;
  406. int mdir_len;
  407. int len;
  408. int dlflags;
  409. int new_dlflags;
  410. int retries;
  411. int path_type;
  412. #ifndef RTLD_NOW
  413. /* for openbsd */
  414. #define RTLD_NOW DL_LAZY
  415. #endif
  416. path=mod_path;
  417. path_type = 0;
  418. modname.s = path;
  419. modname.len = strlen(mod_path);
  420. if(modname.len>3 && strcmp(modname.s+modname.len-3, ".so")==0) {
  421. path_type = 1;
  422. modname.len -= 3;
  423. }
  424. if (!strchr(path, '/'))
  425. path_type |= 2;
  426. if((path_type&2) || path[0] != '/') {
  427. /* module name was given, we try to construct the path */
  428. mdir=mods_dir; /* search path */
  429. do{
  430. nxt_mdir=strchr(mdir, ':');
  431. if (nxt_mdir) mdir_len=(int)(nxt_mdir-mdir);
  432. else mdir_len=strlen(mdir);
  433. if(path_type&2) {
  434. /* try path <MODS_DIR>/<modname>.so */
  435. path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
  436. modname.len + 3 /* ".so" */ + 1);
  437. if (path==0) goto error;
  438. memcpy(path, mdir, mdir_len);
  439. len = mdir_len;
  440. if (len != 0 && path[len - 1] != '/'){
  441. path[len]='/';
  442. len++;
  443. }
  444. path[len]=0;
  445. strcat(path, modname.s);
  446. if(!(path_type&1))
  447. strcat(path, ".so");
  448. if (stat(path, &stat_buf) == -1) {
  449. LM_DBG("module file not found <%s>\n", path);
  450. pkg_free(path);
  451. /* try path <MODS_DIR>/<modname>/<modname>.so */
  452. path = (char*)pkg_malloc(
  453. mdir_len + 1 /* "/" */ +
  454. modname.len + 1 /* "/" */ +
  455. modname.len + 3 /* ".so" */ + 1);
  456. if (path==0) goto error;
  457. memcpy(path, mdir, mdir_len);
  458. len = mdir_len;
  459. if (len != 0 && path[len - 1] != '/') {
  460. path[len]='/';
  461. len++;
  462. }
  463. path[len]=0;
  464. strncat(path, modname.s, modname.len);
  465. strcat(path, "/");
  466. strcat(path, modname.s);
  467. if(!(path_type&1))
  468. strcat(path, ".so");
  469. if (stat(path, &stat_buf) == -1) {
  470. LM_DBG("module file not found <%s>\n", path);
  471. pkg_free(path);
  472. path=0;
  473. }
  474. }
  475. } else {
  476. /* try mod_path - S compat */
  477. if(path==mod_path) {
  478. if (stat(path, &stat_buf) == -1) {
  479. LM_DBG("module file not found <%s>\n", path);
  480. path=0;
  481. }
  482. }
  483. if(path==0) {
  484. /* try path <MODS_DIR>/mod_path - K compat */
  485. path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
  486. strlen(mod_path) + 1);
  487. if (path==0) goto error;
  488. memcpy(path, mdir, mdir_len);
  489. len = mdir_len;
  490. if (len != 0 && path[len - 1] != '/'){
  491. path[len]='/';
  492. len++;
  493. }
  494. path[len]=0;
  495. strcat(path, mod_path);
  496. if (stat(path, &stat_buf) == -1) {
  497. LM_DBG("module file not found <%s>\n", path);
  498. pkg_free(path);
  499. path=0;
  500. }
  501. }
  502. }
  503. mdir=nxt_mdir?nxt_mdir+1:0;
  504. }while(path==0 && mdir);
  505. if (path==0){
  506. LM_ERR("could not find module <%.*s> in <%s>\n",
  507. modname.len, modname.s, mods_dir);
  508. goto error;
  509. }
  510. }
  511. LM_DBG("trying to load <%s>\n", path);
  512. retries=2;
  513. dlflags=RTLD_NOW;
  514. reload:
  515. handle=dlopen(path, dlflags); /* resolve all symbols now */
  516. if (handle==0){
  517. LM_ERR("could not open module <%s>: %s\n", path, dlerror());
  518. goto error;
  519. }
  520. for(t=modules;t; t=t->next){
  521. if (t->handle==handle){
  522. LM_WARN("attempting to load the same module twice (%s)\n", path);
  523. goto skip;
  524. }
  525. }
  526. /* version control */
  527. if (!version_control(handle, path)) {
  528. exit(-1);
  529. }
  530. mod_if_ver = (unsigned *)dlsym(handle,
  531. DLSYM_PREFIX "module_interface_ver");
  532. if ( (error =(char*)dlerror())!=0 ){
  533. LM_ERR("no module interface version in module <%s>\n", path );
  534. goto error1;
  535. }
  536. /* launch register */
  537. mr = (mod_register_function)dlsym(handle, DLSYM_PREFIX "mod_register");
  538. if (((error =(char*)dlerror())==0) && mr) {
  539. /* no error call it */
  540. new_dlflags=dlflags;
  541. if (mr(path, &new_dlflags, 0, 0)!=0) {
  542. LM_ERR("%s: mod_register failed\n", path);
  543. goto error1;
  544. }
  545. if (new_dlflags!=dlflags && new_dlflags!=0) {
  546. /* we have to reload the module */
  547. dlclose(handle);
  548. dlflags=new_dlflags;
  549. retries--;
  550. if (retries>0) goto reload;
  551. LM_ERR("%s: cannot agree on the dlflags\n", path);
  552. goto error;
  553. }
  554. }
  555. exp = (union module_exports_u*)dlsym(handle, DLSYM_PREFIX "exports");
  556. if ( (error =(char*)dlerror())!=0 ){
  557. LM_ERR("%s\n", error);
  558. goto error1;
  559. }
  560. /* hack to allow for kamailio style dlflags inside exports */
  561. if (*mod_if_ver == 1) {
  562. new_dlflags = exp->v1.dlflags;
  563. if (new_dlflags!=dlflags && new_dlflags!=DEFAULT_DLFLAGS) {
  564. /* we have to reload the module */
  565. dlclose(handle);
  566. DEBUG("%s: exports dlflags interface is deprecated and it will not"
  567. " be supported in newer versions; consider using"
  568. " mod_register() instead\n", path);
  569. dlflags=new_dlflags;
  570. retries--;
  571. if (retries>0) goto reload;
  572. LM_ERR("%s: cannot agree on the dlflags\n", path);
  573. goto error;
  574. }
  575. }
  576. if (register_module(*mod_if_ver, exp, path, handle)<0) goto error1;
  577. return 0;
  578. error1:
  579. dlclose(handle);
  580. error:
  581. skip:
  582. if (path && path!=mod_path)
  583. pkg_free(path);
  584. return -1;
  585. }
  586. /* searches the module list for function name in module mod and returns
  587. * a pointer to the "name" function record union or 0 if not found
  588. * sets also *mod_if_ver to the original module interface version.
  589. * mod==0 is a wildcard matching all modules
  590. * flags parameter is OR value of all flags that must match
  591. */
  592. sr31_cmd_export_t* find_mod_export_record(char* mod, char* name,
  593. int param_no, int flags,
  594. unsigned* mod_if_ver)
  595. {
  596. struct sr_module* t;
  597. sr31_cmd_export_t* cmd;
  598. for(t=modules;t;t=t->next){
  599. if (mod!=0 && (strcmp(t->exports.name, mod) !=0))
  600. continue;
  601. if (t->exports.cmds)
  602. for(cmd=&t->exports.cmds[0]; cmd->name; cmd++) {
  603. if((strcmp(name, cmd->name) == 0) &&
  604. ((cmd->param_no == param_no) ||
  605. (cmd->param_no==VAR_PARAM_NO)) &&
  606. ((cmd->flags & flags) == flags)
  607. ){
  608. LM_DBG("find_export_record: found <%s> in module %s [%s]\n",
  609. name, t->exports.name, t->path);
  610. *mod_if_ver=t->orig_mod_interface_ver;
  611. return cmd;
  612. }
  613. }
  614. }
  615. LM_DBG("find_export_record: <%s> not found \n", name);
  616. return 0;
  617. }
  618. /* searches the module list for function name and returns
  619. * a pointer to the "name" function record union or 0 if not found
  620. * sets also *mod_if_ver to the module interface version (needed to know
  621. * which member of the union should be accessed v0 or v1)
  622. * mod==0 is a wildcard matching all modules
  623. * flags parameter is OR value of all flags that must match
  624. */
  625. sr31_cmd_export_t* find_export_record(char* name,
  626. int param_no, int flags,
  627. unsigned* mod_if_ver)
  628. {
  629. return find_mod_export_record(0, name, param_no, flags, mod_if_ver);
  630. }
  631. cmd_function find_export(char* name, int param_no, int flags)
  632. {
  633. sr31_cmd_export_t* cmd;
  634. unsigned mver;
  635. cmd = find_export_record(name, param_no, flags, &mver);
  636. return cmd?cmd->function:0;
  637. }
  638. rpc_export_t* find_rpc_export(char* name, int flags)
  639. {
  640. return rpc_lookup((char*)name, strlen(name));
  641. }
  642. /*
  643. * searches the module list and returns pointer to "name" function in module
  644. * "mod"
  645. * 0 if not found
  646. * flags parameter is OR value of all flags that must match
  647. */
  648. cmd_function find_mod_export(char* mod, char* name, int param_no, int flags)
  649. {
  650. sr31_cmd_export_t* cmd;
  651. unsigned mver;
  652. cmd=find_mod_export_record(mod, name, param_no, flags, &mver);
  653. if (cmd)
  654. return cmd->function;
  655. LM_DBG("<%s> in module <%s> not found\n", name, mod);
  656. return 0;
  657. }
  658. struct sr_module* find_module_by_name(char* mod) {
  659. struct sr_module* t;
  660. for(t = modules; t; t = t->next) {
  661. if (strcmp(mod, t->exports.name) == 0) {
  662. return t;
  663. }
  664. }
  665. LM_DBG("module <%s> not found\n", mod);
  666. return 0;
  667. }
  668. /*!
  669. * \brief Find a parameter with given type
  670. * \param mod module
  671. * \param name parameter name
  672. * \param type_mask parameter mask
  673. * \param param_type parameter type
  674. * \return parameter address in memory, if there is no such parameter, NULL is returned
  675. */
  676. void* find_param_export(struct sr_module* mod, char* name,
  677. modparam_t type_mask, modparam_t *param_type)
  678. {
  679. param_export_t* param;
  680. if (!mod)
  681. return 0;
  682. for(param = mod->exports.params ;param && param->name ; param++) {
  683. if ((strcmp(name, param->name) == 0) &&
  684. ((param->type & PARAM_TYPE_MASK(type_mask)) != 0)) {
  685. LM_DBG("found <%s> in module %s [%s]\n",
  686. name, mod->exports.name, mod->path);
  687. *param_type = param->type;
  688. return param->param_pointer;
  689. }
  690. }
  691. LM_DBG("parameter <%s> not found in module <%s>\n",
  692. name, mod->exports.name);
  693. return 0;
  694. }
  695. void destroy_modules()
  696. {
  697. struct sr_module* t, *foo;
  698. /* call first destroy function from each module */
  699. t=modules;
  700. while(t) {
  701. foo=t->next;
  702. if (t->exports.destroy_f){
  703. t->exports.destroy_f();
  704. }
  705. t=foo;
  706. }
  707. /* free module exports structures */
  708. t=modules;
  709. while(t) {
  710. foo=t->next;
  711. pkg_free(t);
  712. t=foo;
  713. }
  714. modules=0;
  715. if (mod_response_cbks){
  716. pkg_free(mod_response_cbks);
  717. mod_response_cbks=0;
  718. }
  719. }
  720. #ifdef NO_REVERSE_INIT
  721. /*
  722. * Initialize all loaded modules, the initialization
  723. * is done *AFTER* the configuration file is parsed
  724. */
  725. int init_modules(void)
  726. {
  727. struct sr_module* t;
  728. if(async_task_init()<0)
  729. return -1;
  730. for(t = modules; t; t = t->next) {
  731. if (t->exports.init_f) {
  732. if (t->exports.init_f() != 0) {
  733. LM_ERR("Error while initializing module %s\n", t->exports.name);
  734. return -1;
  735. }
  736. /* delay next module init, if configured */
  737. if(unlikely(modinit_delay>0))
  738. sleep_us(modinit_delay);
  739. }
  740. if (t->exports.response_f)
  741. mod_response_cbk_no++;
  742. }
  743. mod_response_cbks=pkg_malloc(mod_response_cbk_no *
  744. sizeof(response_function));
  745. if (mod_response_cbks==0){
  746. LM_ERR("memory allocation failure for %d response_f callbacks\n",
  747. mod_response_cbk_no);
  748. return -1;
  749. }
  750. for (t=modules, i=0; t && (i<mod_response_cbk_no); t=t->next) {
  751. if (t->exports.response_f) {
  752. mod_response_cbks[i]=t->exports.response_f;
  753. i++;
  754. }
  755. }
  756. return 0;
  757. }
  758. /*
  759. * per-child initialization
  760. */
  761. int init_child(int rank)
  762. {
  763. struct sr_module* t;
  764. char* type;
  765. switch(rank) {
  766. case PROC_MAIN: type = "PROC_MAIN"; break;
  767. case PROC_TIMER: type = "PROC_TIMER"; break;
  768. case PROC_FIFO: type = "PROC_FIFO"; break;
  769. case PROC_TCP_MAIN: type = "PROC_TCP_MAIN"; break;
  770. default: type = "CHILD"; break;
  771. }
  772. LM_DBG("initializing %s with rank %d\n", type, rank);
  773. if(async_task_child_init(rank)<0)
  774. return -1;
  775. for(t = modules; t; t = t->next) {
  776. if (t->exports.init_child_f) {
  777. if ((t->exports.init_child_f(rank)) < 0) {
  778. LM_ERR("Initialization of child %d failed\n", rank);
  779. return -1;
  780. }
  781. }
  782. }
  783. return 0;
  784. }
  785. #else
  786. /* recursive module child initialization; (recursion is used to
  787. process the module linear list in the same order in
  788. which modules are loaded in config file
  789. */
  790. static int init_mod_child( struct sr_module* m, int rank )
  791. {
  792. if (m) {
  793. /* iterate through the list; if error occurs,
  794. propagate it up the stack
  795. */
  796. if (init_mod_child(m->next, rank)!=0) return -1;
  797. if (m->exports.init_child_f) {
  798. LM_DBG("rank %d: %s\n", rank, m->exports.name);
  799. if (m->exports.init_child_f(rank)<0) {
  800. LM_ERR("Error while initializing module %s (%s)\n",
  801. m->exports.name, m->path);
  802. return -1;
  803. } else {
  804. /* module correctly initialized */
  805. return 0;
  806. }
  807. }
  808. /* no init function -- proceed with success */
  809. return 0;
  810. } else {
  811. /* end of list */
  812. return 0;
  813. }
  814. }
  815. /*
  816. * per-child initialization
  817. */
  818. int init_child(int rank)
  819. {
  820. if(async_task_child_init(rank)<0)
  821. return -1;
  822. return init_mod_child(modules, rank);
  823. }
  824. /* recursive module initialization; (recursion is used to
  825. process the module linear list in the same order in
  826. which modules are loaded in config file
  827. */
  828. static int init_mod( struct sr_module* m )
  829. {
  830. if (m) {
  831. /* iterate through the list; if error occurs,
  832. propagate it up the stack
  833. */
  834. if (init_mod(m->next)!=0) return -1;
  835. if (m->exports.init_f) {
  836. LM_DBG("%s\n", m->exports.name);
  837. if (m->exports.init_f()!=0) {
  838. LM_ERR("Error while initializing module %s (%s)\n",
  839. m->exports.name, m->path);
  840. return -1;
  841. } else {
  842. /* module correctly initialized */
  843. return 0;
  844. }
  845. }
  846. /* no init function -- proceed with success */
  847. return 0;
  848. } else {
  849. /* end of list */
  850. return 0;
  851. }
  852. }
  853. /*
  854. * Initialize all loaded modules, the initialization
  855. * is done *AFTER* the configuration file is parsed
  856. */
  857. int init_modules(void)
  858. {
  859. struct sr_module* t;
  860. int i;
  861. if(async_task_init()<0)
  862. return -1;
  863. i = init_mod(modules);
  864. if(i!=0)
  865. return i;
  866. for(t = modules; t; t = t->next)
  867. if (t->exports.response_f)
  868. mod_response_cbk_no++;
  869. mod_response_cbks=pkg_malloc(mod_response_cbk_no *
  870. sizeof(response_function));
  871. if (mod_response_cbks==0){
  872. LM_ERR("memory allocation failure for %d response_f callbacks\n", mod_response_cbk_no);
  873. return -1;
  874. }
  875. for (t=modules, i=0; t && (i<mod_response_cbk_no); t=t->next)
  876. if (t->exports.response_f) {
  877. mod_response_cbks[i]=t->exports.response_f;
  878. i++;
  879. }
  880. return 0;
  881. }
  882. #endif
  883. action_u_t *fixup_get_param(void **cur_param, int cur_param_no,
  884. int required_param_no)
  885. {
  886. action_u_t *a;
  887. /* cur_param points to a->u.string, get pointer to a */
  888. a = (void*) ((char *)cur_param - offsetof(action_u_t, u.string));
  889. return a + required_param_no - cur_param_no;
  890. }
  891. int fixup_get_param_count(void **cur_param, int cur_param_no)
  892. {
  893. action_u_t *a;
  894. a = fixup_get_param(cur_param, cur_param_no, 0);
  895. if (a)
  896. return a->u.number;
  897. else
  898. return -1;
  899. }
  900. /** get a pointer to a parameter internal type.
  901. * @param param
  902. * @return pointer to the parameter internal type.
  903. */
  904. action_param_type* fixup_get_param_ptype(void** param)
  905. {
  906. action_u_t* a;
  907. a = (void*)((char*)param - offsetof(action_u_t, u.string));
  908. return &a->type;
  909. }
  910. /** get a parameter internal type.
  911. * @see fixup_get_param_ptype().
  912. * @return paramter internal type.
  913. */
  914. action_param_type fixup_get_param_type(void** param)
  915. {
  916. return *fixup_get_param_ptype(param);
  917. }
  918. /* fixes flag params (resolves possible named flags)
  919. * use PARAM_USE_FUNC|PARAM_STRING as a param. type and create
  920. * a wrapper function that does just:
  921. * return fix_flag(type, val, "my_module", "my_param", &flag_var)
  922. * see also param_func_t.
  923. */
  924. int fix_flag( modparam_t type, void* val,
  925. char* mod_name, char* param_name, int* flag)
  926. {
  927. int num;
  928. int err;
  929. int f, len;
  930. char* s;
  931. char *p;
  932. if ((type & PARAM_STRING)==0){
  933. LM_CRIT("%s: fix_flag(%s): bad parameter type\n",
  934. mod_name, param_name);
  935. return -1;
  936. }
  937. s=(char*)val;
  938. len=strlen(s);
  939. f=-1;
  940. /* try to see if it's a number */
  941. num = str2s(s, len, &err);
  942. if (err != 0) {
  943. /* see if it's in the name:<no> format */
  944. p=strchr(s, ':');
  945. if (p){
  946. f= str2s(p+1, strlen(p+1), &err);
  947. if (err!=0){
  948. LM_ERR("%s: invalid %s format: \"%s\"",
  949. mod_name, param_name, s);
  950. return -1;
  951. }
  952. *p=0;
  953. }
  954. if ((num=get_flag_no(s, len))<0){
  955. /* not declared yet, declare it */
  956. num=register_flag(s, f);
  957. }
  958. if (num<0){
  959. LM_ERR("%s: bad %s %s\n", mod_name, param_name, s);
  960. return -1;
  961. } else if ((f>0) && (num!=f)){
  962. LM_ERR("%s: flag %s already defined"
  963. " as %d (and not %d), using %s:%d\n",
  964. mod_name, s, num, f, s, num);
  965. }
  966. }
  967. *flag=num;
  968. return 0;
  969. }
  970. /*
  971. * Common function parameter fixups
  972. */
  973. /** Generic parameter fixup function.
  974. * Creates a fparam_t structure.
  975. * @param type contains allowed parameter types
  976. * @param param is the parameter that will be fixed-up
  977. *
  978. * @return
  979. * 0 on success,
  980. * 1 if the param doesn't match the specified type
  981. * <0 on failure
  982. */
  983. int fix_param(int type, void** param)
  984. {
  985. fparam_t* p;
  986. str name, s;
  987. int num;
  988. int err;
  989. p = (fparam_t*)pkg_malloc(sizeof(fparam_t));
  990. if (!p) {
  991. LM_ERR("No memory left\n");
  992. return E_OUT_OF_MEM;
  993. }
  994. memset(p, 0, sizeof(fparam_t));
  995. p->orig = *param;
  996. switch(type) {
  997. case FPARAM_UNSPEC:
  998. LM_ERR("Invalid type value\n");
  999. goto error;
  1000. case FPARAM_STRING:
  1001. p->v.asciiz = *param;
  1002. /* no break */
  1003. case FPARAM_STR:
  1004. p->v.str.s = (char*)*param;
  1005. p->v.str.len = strlen(p->v.str.s);
  1006. p->fixed = &p->v;
  1007. break;
  1008. case FPARAM_INT:
  1009. s.s = (char*)*param;
  1010. s.len = strlen(s.s);
  1011. err = str2sint(&s, &num);
  1012. if (err == 0) {
  1013. p->v.i = (int)num;
  1014. } else {
  1015. /* Not a number */
  1016. pkg_free(p);
  1017. return 1;
  1018. }
  1019. p->fixed = (void*)(long)num;
  1020. break;
  1021. case FPARAM_REGEX:
  1022. if ((p->v.regex = pkg_malloc(sizeof(regex_t))) == 0) {
  1023. LM_ERR("No memory left\n");
  1024. goto error;
  1025. }
  1026. if (regcomp(p->v.regex, *param,
  1027. REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
  1028. pkg_free(p->v.regex);
  1029. p->v.regex=0;
  1030. /* not a valid regex */
  1031. goto no_match;
  1032. }
  1033. p->fixed = p->v.regex;
  1034. break;
  1035. case FPARAM_AVP:
  1036. name.s = (char*)*param;
  1037. name.len = strlen(name.s);
  1038. trim(&name);
  1039. if (!name.len || name.s[0] != '$') {
  1040. /* Not an AVP identifier */
  1041. goto no_match;
  1042. }
  1043. name.s++;
  1044. name.len--;
  1045. if (parse_avp_ident(&name, &p->v.avp) < 0) {
  1046. /* invalid avp identifier (=> no match) */
  1047. goto no_match;
  1048. }
  1049. p->fixed = &p->v;
  1050. break;
  1051. case FPARAM_SELECT:
  1052. name.s = (char*)*param;
  1053. name.len = strlen(name.s);
  1054. trim(&name);
  1055. if (!name.len || name.s[0] != '@') {
  1056. /* Not a select identifier */
  1057. goto no_match;
  1058. }
  1059. if (parse_select(&name.s, &p->v.select) < 0) {
  1060. LM_ERR("Error while parsing select identifier\n");
  1061. goto error;
  1062. }
  1063. p->fixed = &p->v;
  1064. break;
  1065. case FPARAM_SUBST:
  1066. s.s = *param;
  1067. s.len = strlen(s.s);
  1068. p->v.subst = subst_parser(&s);
  1069. if (!p->v.subst) {
  1070. LM_ERR("Error while parsing regex substitution\n");
  1071. goto error;
  1072. }
  1073. p->fixed = &p->v;
  1074. break;
  1075. case FPARAM_PVS:
  1076. name.s = (char*)*param;
  1077. name.len = strlen(name.s);
  1078. trim(&name);
  1079. if (!name.len || name.s[0] != '$'){
  1080. /* not a pvs identifier */
  1081. goto no_match;
  1082. }
  1083. p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
  1084. if (p->v.pvs==0){
  1085. LM_ERR("out of memory while parsing pv_spec_t\n");
  1086. goto error;
  1087. }
  1088. if (pv_parse_spec2(&name, p->v.pvs, 1)==0){
  1089. /* not a valid pvs identifier (but it might be an avp) */
  1090. pkg_free(p->v.pvs);
  1091. p->v.pvs=0;
  1092. goto no_match;
  1093. }
  1094. p->fixed = p->v.pvs;
  1095. break;
  1096. case FPARAM_PVE:
  1097. name.s = (char*)*param;
  1098. name.len = strlen(name.s);
  1099. if (pv_parse_format(&name, &p->v.pve)<0){
  1100. LM_ERR("bad PVE format: \"%.*s\"\n", name.len, name.s);
  1101. goto error;
  1102. }
  1103. p->fixed = &p->v;
  1104. break;
  1105. }
  1106. p->type = type;
  1107. *param = (void*)p;
  1108. return 0;
  1109. no_match:
  1110. pkg_free(p);
  1111. return 1;
  1112. error:
  1113. pkg_free(p);
  1114. return E_UNSPEC;
  1115. }
  1116. /** fparam_t free function.
  1117. * Frees the "content" of a fparam, but not the fparam itself.
  1118. * Note: it doesn't free fp->orig!
  1119. * Assumes pkg_malloc'ed content.
  1120. * @param fp - fparam to be freed
  1121. *
  1122. */
  1123. void fparam_free_contents(fparam_t* fp)
  1124. {
  1125. if (fp==0)
  1126. return;
  1127. switch(fp->type) {
  1128. case FPARAM_UNSPEC:
  1129. case FPARAM_STRING: /* asciiz string, not str */
  1130. case FPARAM_INT:
  1131. case FPARAM_STR:
  1132. /* nothing to do */
  1133. break;
  1134. case FPARAM_REGEX:
  1135. if (fp->v.regex){
  1136. regfree(fp->v.regex);
  1137. pkg_free(fp->v.regex);
  1138. fp->v.regex=0;
  1139. }
  1140. break;
  1141. case FPARAM_AVP:
  1142. free_avp_name(&fp->v.avp.flags, &fp->v.avp.name);
  1143. break;
  1144. case FPARAM_SELECT:
  1145. if (fp->v.select){
  1146. free_select(fp->v.select);
  1147. fp->v.select=0;
  1148. }
  1149. break;
  1150. case FPARAM_SUBST:
  1151. if (fp->v.subst){
  1152. subst_expr_free(fp->v.subst);
  1153. fp->v.subst=0;
  1154. }
  1155. break;
  1156. case FPARAM_PVS:
  1157. if (fp->v.pvs){
  1158. pv_spec_free(fp->v.pvs);
  1159. fp->v.pvs=0;
  1160. }
  1161. break;
  1162. case FPARAM_PVE:
  1163. if (fp->v.pve){
  1164. pv_elem_free_all(fp->v.pve);
  1165. fp->v.pve=0;
  1166. }
  1167. break;
  1168. }
  1169. }
  1170. /**
  1171. * @brief Generic free fixup type function for a fixed fparam
  1172. *
  1173. * Generic free fixup type function for a fixed fparam. It will free whatever
  1174. * was allocated during the initial fparam fixup and restore the original param
  1175. * value.
  1176. * @param param freed parameters
  1177. */
  1178. void fparam_free_restore(void** param)
  1179. {
  1180. fparam_t *fp;
  1181. void *orig;
  1182. fp = *param;
  1183. orig = fp->orig;
  1184. fp->orig = 0;
  1185. fparam_free_contents(fp);
  1186. pkg_free(fp);
  1187. *param = orig;
  1188. }
  1189. /** fix a param to one of the given types (mask).
  1190. *
  1191. * @param types - bitmap of the allowed types (e.g. FPARAM_INT|FPARAM_STR)
  1192. * @param param - value/result
  1193. * @return - 0 on success, -1 on error, 1 if param doesn't
  1194. * match any of the types
  1195. */
  1196. int fix_param_types(int types, void** param)
  1197. {
  1198. int ret;
  1199. int t;
  1200. if (fixup_get_param_type(param) == STRING_RVE_ST &&
  1201. (types & (FPARAM_INT|FPARAM_STR|FPARAM_STRING))) {
  1202. /* if called with a RVE already converted to string =>
  1203. don't try AVP, PVAR or SELECT (to avoid double
  1204. deref., e.g.: $foo="$bar"; f($foo) ) */
  1205. types &= ~ (FPARAM_AVP|FPARAM_PVS|FPARAM_SELECT|FPARAM_PVE);
  1206. }
  1207. for (t=types & ~(types-1); types; types&=(types-1), t=types & ~(types-1)){
  1208. if ((ret=fix_param(t, param))<=0) return ret;
  1209. }
  1210. return E_UNSPEC;
  1211. }
  1212. /*
  1213. * Fixup variable string, the parameter can be
  1214. * AVP, SELECT, or ordinary string. AVP and select
  1215. * identifiers will be resolved to their values during
  1216. * runtime
  1217. *
  1218. * The parameter value will be converted to fparam structure
  1219. * This function returns -1 on an error
  1220. */
  1221. int fixup_var_str_12(void** param, int param_no)
  1222. {
  1223. int ret;
  1224. if (fixup_get_param_type(param) != STRING_RVE_ST) {
  1225. /* if called with a RVE already converted to string =>
  1226. don't try AVP, PVAR or SELECT (to avoid double
  1227. deref., e.g.: $foo="$bar"; f($foo) ) */
  1228. if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
  1229. if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
  1230. if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
  1231. }
  1232. if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
  1233. LM_ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
  1234. " failed\n");
  1235. return -1;
  1236. }
  1237. /* Same as fixup_var_str_12 but applies to the 1st parameter only */
  1238. int fixup_var_str_1(void** param, int param_no)
  1239. {
  1240. if (param_no == 1) return fixup_var_str_12(param, param_no);
  1241. else return 0;
  1242. }
  1243. /* Same as fixup_var_str_12 but applies to the 2nd parameter only */
  1244. int fixup_var_str_2(void** param, int param_no)
  1245. {
  1246. if (param_no == 2) return fixup_var_str_12(param, param_no);
  1247. else return 0;
  1248. }
  1249. /** fixup variable-pve-only-string.
  1250. * The parameter can be a PVE (pv based format string)
  1251. * or string.
  1252. * non-static PVEs identifiers will be resolved to
  1253. * their values during runtime.
  1254. * The parameter value will be converted to fparam structure
  1255. * @param param - double pointer to param, as for normal fixup functions.
  1256. * @param param_no - parameter number, ignored.
  1257. * @return -1 on an error, 0 on success.
  1258. */
  1259. int fixup_var_pve_12(void** param, int param_no)
  1260. {
  1261. int ret;
  1262. fparam_t* fp;
  1263. if (fixup_get_param_type(param) != STRING_RVE_ST) {
  1264. /* if called with a RVE already converted to string =>
  1265. don't try PVE again (to avoid double
  1266. deref., e.g.: $foo="$bar"; f($foo) ) */
  1267. if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
  1268. if (ret < 0)
  1269. return ret;
  1270. /* check if it resolved to a dynamic or "static" PVE.
  1271. If the resulting PVE is static (normal string), discard
  1272. it and use the normal string fixup (faster at runtime) */
  1273. fp = (fparam_t*)*param;
  1274. if (fp->v.pve->spec == 0 || fp->v.pve->spec->getf == 0)
  1275. fparam_free_restore(param); /* fallback to STR below */
  1276. else
  1277. return ret; /* dynamic PVE => return */
  1278. }
  1279. }
  1280. if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
  1281. LM_ERR("Error while fixing parameter - PVE or str conversions failed\n");
  1282. return -1;
  1283. }
  1284. /** fixup variable-pve-string.
  1285. * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
  1286. * or string.
  1287. * PVAR, AVP and select and non-static PVEs identifiers will be resolved to
  1288. * their values during runtime.
  1289. * The parameter value will be converted to fparam structure
  1290. * @param param - double pointer to param, as for normal fixup functions.
  1291. * @param param_no - parameter number, ignored.
  1292. * @return -1 on an error, 0 on success.
  1293. */
  1294. int fixup_var_pve_str_12(void** param, int param_no)
  1295. {
  1296. int ret;
  1297. fparam_t* fp;
  1298. if (fixup_get_param_type(param) != STRING_RVE_ST) {
  1299. /* if called with a RVE already converted to string =>
  1300. don't try AVP, PVAR, SELECT or PVE again (to avoid double
  1301. deref., e.g.: $foo="$bar"; f($foo) ) */
  1302. if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
  1303. if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
  1304. if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
  1305. if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
  1306. if (ret < 0)
  1307. return ret;
  1308. /* check if it resolved to a dynamic or "static" PVE.
  1309. If the resulting PVE is static (normal string), discard
  1310. it and use the normal string fixup (faster at runtime) */
  1311. fp = (fparam_t*)*param;
  1312. if (fp->v.pve->spec == 0 || fp->v.pve->spec->getf == 0)
  1313. fparam_free_restore(param); /* fallback to STR below */
  1314. else
  1315. return ret; /* dynamic PVE => return */
  1316. }
  1317. }
  1318. if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
  1319. LM_ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
  1320. " failed\n");
  1321. return -1;
  1322. }
  1323. /* Same as fixup_var_pve_str_12 but applies to the 1st parameter only */
  1324. int fixup_var_pve_str_1(void** param, int param_no)
  1325. {
  1326. if (param_no == 1) return fixup_var_pve_str_12(param, param_no);
  1327. else return 0;
  1328. }
  1329. /* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
  1330. int fixup_var_pve_str_2(void** param, int param_no)
  1331. {
  1332. if (param_no == 2) return fixup_var_pve_str_12(param, param_no);
  1333. else return 0;
  1334. }
  1335. /*
  1336. * Fixup variable integer, the parameter can be
  1337. * AVP, SELECT, or ordinary integer. AVP and select
  1338. * identifiers will be resolved to their values and
  1339. * converted to int if necessary during runtime
  1340. *
  1341. * The parameter value will be converted to fparam structure
  1342. * This function returns -1 on an error
  1343. */
  1344. int fixup_var_int_12(void** param, int param_no)
  1345. {
  1346. int ret;
  1347. if (fixup_get_param_type(param) != STRING_RVE_ST) {
  1348. /* if called with a RVE already converted to string =>
  1349. don't try AVP, PVAR or SELECT (to avoid double
  1350. deref., e.g.: $foo="$bar"; f($foo) ) */
  1351. if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
  1352. if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
  1353. if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
  1354. }
  1355. if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret;
  1356. LM_ERR("Error while fixing parameter, PV, AVP, SELECT, and int conversions"
  1357. " failed\n");
  1358. return -1;
  1359. }
  1360. /* Same as fixup_var_int_12 but applies to the 1st parameter only */
  1361. int fixup_var_int_1(void** param, int param_no)
  1362. {
  1363. if (param_no == 1) return fixup_var_int_12(param, param_no);
  1364. else return 0;
  1365. }
  1366. /* Same as fixup_var_int_12 but applies to the 2nd parameter only */
  1367. int fixup_var_int_2(void** param, int param_no)
  1368. {
  1369. if (param_no == 2) return fixup_var_int_12(param, param_no);
  1370. else return 0;
  1371. }
  1372. /*
  1373. * The parameter must be a regular expression which must compile, the
  1374. * parameter will be converted to compiled regex
  1375. */
  1376. int fixup_regex_12(void** param, int param_no)
  1377. {
  1378. int ret;
  1379. if ((ret = fix_param(FPARAM_REGEX, param)) <= 0) return ret;
  1380. LM_ERR("Error while compiling regex in function parameter\n");
  1381. return -1;
  1382. }
  1383. /* Same as fixup_regex_12 but applies to the 1st parameter only */
  1384. int fixup_regex_1(void** param, int param_no)
  1385. {
  1386. if (param_no == 1) return fixup_regex_12(param, param_no);
  1387. else return 0;
  1388. }
  1389. /* Same as fixup_regex_12 but applies to the 2nd parameter only */
  1390. int fixup_regex_2(void** param, int param_no)
  1391. {
  1392. if (param_no == 2) return fixup_regex_12(param, param_no);
  1393. else return 0;
  1394. }
  1395. /*
  1396. * The string parameter will be converted to integer
  1397. */
  1398. int fixup_int_12(void** param, int param_no)
  1399. {
  1400. int ret;
  1401. if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret;
  1402. LM_ERR("Cannot function parameter to integer\n");
  1403. return -1;
  1404. }
  1405. /* Same as fixup_int_12 but applies to the 1st parameter only */
  1406. int fixup_int_1(void** param, int param_no)
  1407. {
  1408. if (param_no == 1) return fixup_int_12(param, param_no);
  1409. else return 0;
  1410. }
  1411. /* Same as fixup_int_12 but applies to the 2nd parameter only */
  1412. int fixup_int_2(void** param, int param_no)
  1413. {
  1414. if (param_no == 2) return fixup_int_12(param, param_no);
  1415. else return 0;
  1416. }
  1417. /*
  1418. * Parse the parameter as static string, do not resolve
  1419. * AVPs or selects, convert the parameter to str structure
  1420. */
  1421. int fixup_str_12(void** param, int param_no)
  1422. {
  1423. int ret;
  1424. if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
  1425. LM_ERR("Cannot function parameter to string\n");
  1426. return -1;
  1427. }
  1428. /* Same as fixup_str_12 but applies to the 1st parameter only */
  1429. int fixup_str_1(void** param, int param_no)
  1430. {
  1431. if (param_no == 1) return fixup_str_12(param, param_no);
  1432. else return 0;
  1433. }
  1434. /* Same as fixup_str_12 but applies to the 2nd parameter only */
  1435. int fixup_str_2(void** param, int param_no)
  1436. {
  1437. if (param_no == 2) return fixup_str_12(param, param_no);
  1438. else return 0;
  1439. }
  1440. /** Get the function parameter value as string.
  1441. * @return 0 - Success
  1442. * -1 - Cannot get value
  1443. */
  1444. int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
  1445. {
  1446. int_str val;
  1447. int ret;
  1448. avp_t* avp;
  1449. pv_value_t pv_val;
  1450. switch(param->type) {
  1451. case FPARAM_REGEX:
  1452. case FPARAM_UNSPEC:
  1453. case FPARAM_INT:
  1454. return -1;
  1455. case FPARAM_STRING:
  1456. dst->s = param->v.asciiz;
  1457. dst->len = strlen(param->v.asciiz);
  1458. break;
  1459. case FPARAM_STR:
  1460. *dst = param->v.str;
  1461. break;
  1462. case FPARAM_AVP:
  1463. avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
  1464. &val, 0);
  1465. if (unlikely(!avp)) {
  1466. LM_DBG("Could not find AVP from function parameter '%s'\n",
  1467. param->orig);
  1468. return -1;
  1469. }
  1470. if (likely(avp->flags & AVP_VAL_STR)) {
  1471. *dst = val.s;
  1472. } else {
  1473. /* The caller does not know of what type the AVP will be so
  1474. * convert int AVPs into string here
  1475. */
  1476. dst->s = int2str(val.n, &dst->len);
  1477. }
  1478. break;
  1479. case FPARAM_SELECT:
  1480. ret = run_select(dst, param->v.select, msg);
  1481. if (unlikely(ret < 0 || ret > 0)) return -1;
  1482. break;
  1483. case FPARAM_PVS:
  1484. if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
  1485. ((pv_val.flags&(PV_VAL_NULL|PV_VAL_STR))==PV_VAL_STR))){
  1486. *dst=pv_val.rs;
  1487. }else{
  1488. LM_ERR("Could not convert PV to str\n");
  1489. return -1;
  1490. }
  1491. break;
  1492. case FPARAM_PVE:
  1493. dst->s=pv_get_buffer();
  1494. dst->len=pv_get_buffer_size();
  1495. if (unlikely(pv_printf(msg, param->v.pve, dst->s, &dst->len)!=0)){
  1496. LM_ERR("Could not convert the PV-formated string to str\n");
  1497. dst->len=0;
  1498. return -1;
  1499. };
  1500. break;
  1501. }
  1502. return 0;
  1503. }
  1504. /** Get the function parameter value as integer.
  1505. * @return 0 - Success
  1506. * -1 - Cannot get value
  1507. */
  1508. int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
  1509. {
  1510. int_str val;
  1511. int ret;
  1512. avp_t* avp;
  1513. str tmp;
  1514. pv_value_t pv_val;
  1515. switch(param->type) {
  1516. case FPARAM_INT:
  1517. *dst = param->v.i;
  1518. return 0;
  1519. case FPARAM_REGEX:
  1520. case FPARAM_UNSPEC:
  1521. case FPARAM_STRING:
  1522. case FPARAM_STR:
  1523. return -1;
  1524. case FPARAM_AVP:
  1525. avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
  1526. &val, 0);
  1527. if (unlikely(!avp)) {
  1528. LM_DBG("Could not find AVP from function parameter '%s'\n",
  1529. param->orig);
  1530. return -1;
  1531. }
  1532. if (avp->flags & AVP_VAL_STR) {
  1533. if (str2int(&val.s, (unsigned int*)dst) < 0) {
  1534. LM_ERR("Could not convert AVP string value to int\n");
  1535. return -1;
  1536. }
  1537. } else {
  1538. *dst = val.n;
  1539. }
  1540. break;
  1541. case FPARAM_SELECT:
  1542. ret = run_select(&tmp, param->v.select, msg);
  1543. if (unlikely(ret < 0 || ret > 0)) return -1;
  1544. if (unlikely(str2int(&tmp, (unsigned int*)dst) < 0)) {
  1545. LM_ERR("Could not convert select result to int\n");
  1546. return -1;
  1547. }
  1548. break;
  1549. case FPARAM_PVS:
  1550. if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
  1551. ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT))){
  1552. *dst=pv_val.ri;
  1553. }else{
  1554. LM_ERR("Could not convert PV to int\n");
  1555. return -1;
  1556. }
  1557. break;
  1558. case FPARAM_PVE:
  1559. return -1;
  1560. }
  1561. return 0;
  1562. }
  1563. /** Get the function parameter value as string or/and integer (if possible).
  1564. * @return 0 - Success
  1565. * -1 - Cannot get value
  1566. */
  1567. int get_is_fparam(int* i_dst, str* s_dst, struct sip_msg* msg, fparam_t* param, unsigned int *flags)
  1568. {
  1569. int_str val;
  1570. int ret;
  1571. avp_t* avp;
  1572. str tmp;
  1573. pv_value_t pv_val;
  1574. *flags = 0;
  1575. switch(param->type) {
  1576. case FPARAM_INT:
  1577. *i_dst = param->v.i;
  1578. *flags |= PARAM_INT;
  1579. return 0;
  1580. case FPARAM_REGEX:
  1581. case FPARAM_UNSPEC:
  1582. case FPARAM_STRING:
  1583. s_dst->s = param->v.asciiz;
  1584. s_dst->len = strlen(param->v.asciiz);
  1585. *flags |= PARAM_STR;
  1586. break;
  1587. case FPARAM_STR:
  1588. *s_dst = param->v.str;
  1589. *flags |= PARAM_STR;
  1590. break;
  1591. case FPARAM_AVP:
  1592. avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
  1593. &val, 0);
  1594. if (unlikely(!avp)) {
  1595. LM_DBG("Could not find AVP from function parameter '%s'\n",
  1596. param->orig);
  1597. return -1;
  1598. }
  1599. if (avp->flags & AVP_VAL_STR) {
  1600. *s_dst = val.s;
  1601. *flags |= PARAM_STR;
  1602. if (str2int(&val.s, (unsigned int*)i_dst) < 0) {
  1603. LM_ERR("Could not convert AVP string value to int\n");
  1604. return -1;
  1605. }
  1606. } else {
  1607. *i_dst = val.n;
  1608. *flags |= PARAM_INT;
  1609. }
  1610. break;
  1611. case FPARAM_SELECT:
  1612. ret = run_select(&tmp, param->v.select, msg);
  1613. if (unlikely(ret < 0 || ret > 0)) return -1;
  1614. if (unlikely(str2int(&tmp, (unsigned int*)i_dst) < 0)) {
  1615. LM_ERR("Could not convert select result to int\n");
  1616. return -1;
  1617. }
  1618. *flags |= PARAM_INT;
  1619. break;
  1620. case FPARAM_PVS:
  1621. if (likely(pv_get_spec_value(msg, param->v.pvs, &pv_val)==0)) {
  1622. if ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT){
  1623. *i_dst=pv_val.ri;
  1624. *flags |= PARAM_INT;
  1625. }
  1626. if ((pv_val.flags&(PV_VAL_NULL|PV_VAL_STR))==PV_VAL_STR){
  1627. *s_dst=pv_val.rs;
  1628. *flags |= PARAM_STR;
  1629. }
  1630. }else{
  1631. LM_ERR("Could not get PV\n");
  1632. return -1;
  1633. }
  1634. break;
  1635. case FPARAM_PVE:
  1636. s_dst->s=pv_get_buffer();
  1637. s_dst->len=pv_get_buffer_size();
  1638. if (unlikely(pv_printf(msg, param->v.pve, s_dst->s, &s_dst->len)!=0)){
  1639. LM_ERR("Could not convert the PV-formated string to str\n");
  1640. s_dst->len=0;
  1641. return -1;
  1642. }
  1643. *flags |= PARAM_STR;
  1644. break;
  1645. }
  1646. /* Let's convert to int, if possible */
  1647. if (!(*flags & PARAM_INT) && (*flags & PARAM_STR) && str2sint(s_dst, i_dst) == 0)
  1648. *flags |= PARAM_INT;
  1649. if (!*flags) return -1;
  1650. return 0;
  1651. }
  1652. /**
  1653. * Retrieve the compiled RegExp.
  1654. * @return: 0 for success, negative on error.
  1655. */
  1656. int get_regex_fparam(regex_t *dst, struct sip_msg* msg, fparam_t* param)
  1657. {
  1658. switch (param->type) {
  1659. case FPARAM_REGEX:
  1660. *dst = *param->v.regex;
  1661. return 0;
  1662. default:
  1663. LM_ERR("unexpected parameter type (%d), instead of regexp.\n",
  1664. param->type);
  1665. }
  1666. return -1;
  1667. }
  1668. /** generic free fixup function for "pure" fparam type fixups.
  1669. * @param param - double pointer to param, as for normal fixup functions.
  1670. * @param param_no - parameter number, ignored.
  1671. * @return 0 on success (always).
  1672. */
  1673. int fixup_free_fparam_all(void** param, int param_no)
  1674. {
  1675. fparam_free_restore(param);
  1676. return 0;
  1677. }
  1678. /** generic free fixup function for "pure" first parameter fparam type fixups.
  1679. * @param param - double pointer to param, as for normal fixup functions.
  1680. * @param param_no - parameter number: the function will work only for
  1681. * param_no == 1 (first parameter).
  1682. * @return 0 on success (always).
  1683. */
  1684. int fixup_free_fparam_1(void** param, int param_no)
  1685. {
  1686. if (param_no == 1)
  1687. fparam_free_restore(param);
  1688. return 0;
  1689. }
  1690. /** generic free fixup function for "pure" 2nd parameter fparam type fixups.
  1691. * @param param - double pointer to param, as for normal fixup functions.
  1692. * @param param_no - parameter number: the function will work only for
  1693. * param_no == 2 (2nd parameter).
  1694. * @return 0 on success (always).
  1695. */
  1696. int fixup_free_fparam_2(void** param, int param_no)
  1697. {
  1698. if (param_no == 2)
  1699. fparam_free_restore(param);
  1700. return 0;
  1701. }
  1702. /** returns true if a fixup is a fparam_t* one.
  1703. * Used to automatically detect "pure" fparam fixups that can be used with non
  1704. * contant RVEs.
  1705. * @param f - function pointer
  1706. * @return 1 for fparam fixups, 0 for others.
  1707. */
  1708. int is_fparam_rve_fixup(fixup_function f)
  1709. {
  1710. if (f == fixup_var_str_12 ||
  1711. f == fixup_var_str_1 ||
  1712. f == fixup_var_str_2 ||
  1713. f == fixup_var_pve_str_12 ||
  1714. f == fixup_var_pve_str_1 ||
  1715. f == fixup_var_pve_str_2 ||
  1716. f == fixup_var_int_12 ||
  1717. f == fixup_var_int_1 ||
  1718. f == fixup_var_int_2 ||
  1719. f == fixup_int_12 ||
  1720. f == fixup_int_1 ||
  1721. f == fixup_int_2 ||
  1722. f == fixup_str_12 ||
  1723. f == fixup_str_1 ||
  1724. f == fixup_str_2 ||
  1725. f == fixup_regex_12 ||
  1726. f == fixup_regex_1 ||
  1727. f == fixup_regex_2
  1728. )
  1729. return 1;
  1730. return 0;
  1731. }
  1732. /**
  1733. * @brief returns the corresponding fixup_free* for various known fixup types
  1734. *
  1735. * Returns the corresponding fixup_free* for various known fixup types.
  1736. * Used to automatically fill in free_fixup* functions.
  1737. * @param f fixup function pointer
  1738. * @return free fixup function pointer on success, 0 on failure (unknown
  1739. * fixup or no free fixup function).
  1740. */
  1741. free_fixup_function get_fixup_free(fixup_function f)
  1742. {
  1743. free_fixup_function ret;
  1744. /* "pure" fparam, all parameters */
  1745. if (f == fixup_var_str_12 ||
  1746. f == fixup_var_pve_str_12 ||
  1747. f == fixup_var_int_12 ||
  1748. f == fixup_int_12 ||
  1749. f == fixup_str_12 ||
  1750. f == fixup_regex_12)
  1751. return fixup_free_fparam_all;
  1752. /* "pure" fparam, 1st parameter */
  1753. if (f == fixup_var_str_1 ||
  1754. f == fixup_var_pve_str_1 ||
  1755. f == fixup_var_int_1 ||
  1756. f == fixup_int_1 ||
  1757. f == fixup_str_1 ||
  1758. f == fixup_regex_1)
  1759. return fixup_free_fparam_1;
  1760. /* "pure" fparam, 2nd parameters */
  1761. if (f == fixup_var_str_2 ||
  1762. f == fixup_var_pve_str_2 ||
  1763. f == fixup_var_int_2 ||
  1764. f == fixup_int_2 ||
  1765. f == fixup_str_2 ||
  1766. f == fixup_regex_2)
  1767. return fixup_free_fparam_2;
  1768. /* mod_fix.h kamailio style fixups */
  1769. if ((ret = mod_fix_get_fixup_free(f)) != 0)
  1770. return ret;
  1771. /* unknown */
  1772. return 0;
  1773. }