diff --git a/src/modules/app_lua_sr/app_lua_sr_api.c b/src/modules/app_lua_sr/app_lua_sr_api.c index 7e9fc023656..47e0a920efa 100644 --- a/src/modules/app_lua_sr/app_lua_sr_api.c +++ b/src/modules/app_lua_sr/app_lua_sr_api.c @@ -54,7 +54,7 @@ extern app_lua_api_t _app_lua_api; * */ void ksr_luaL_openlib_mode(lua_State *L, const char *libname, - const luaL_Reg *lfuncs, int nup, int mode) + const luaL_Reg *lfuncs, int nup, int mode) { char modname[256]; char *submod = NULL; @@ -62,7 +62,7 @@ void ksr_luaL_openlib_mode(lua_State *L, const char *libname, if(mode) { /* support for registering 'module.submodule' functions * - 'module' functions must be registered first */ - if(strlen(libname)>254) { + if(strlen(libname) > 254) { LM_ERR("module name is too long [%s]\n", libname); return; } @@ -73,7 +73,7 @@ void ksr_luaL_openlib_mode(lua_State *L, const char *libname, submod++; } lua_getglobal(L, modname); - if (lua_isnil(L, -1)) { + if(lua_isnil(L, -1)) { if(submod != NULL) { LM_ERR("main module not registered yet [%s]\n", libname); return; @@ -98,8 +98,8 @@ void ksr_luaL_openlib_mode(lua_State *L, const char *libname, /** * */ -void ksr_luaL_openlib(lua_State *L, const char *libname, - const luaL_Reg *lfuncs, int nup) +void ksr_luaL_openlib( + lua_State *L, const char *libname, const luaL_Reg *lfuncs, int nup) { ksr_luaL_openlib_mode(L, libname, lfuncs, nup, 1); } @@ -128,7 +128,7 @@ int app_lua_return_error(lua_State *L) */ int app_lua_return_boolean(lua_State *L, int b) { - if(b==SRLUA_FALSE) + if(b == SRLUA_FALSE) lua_pushboolean(L, SRLUA_FALSE); else lua_pushboolean(L, SRLUA_TRUE); @@ -156,7 +156,7 @@ int app_lua_return_true(lua_State *L) /** * */ -static int lua_sr_probe (lua_State *L) +static int lua_sr_probe(lua_State *L) { LM_DBG("someone probing from lua\n"); return 0; @@ -165,11 +165,11 @@ static int lua_sr_probe (lua_State *L) /** * */ -static int lua_sr_dbg (lua_State *L) +static int lua_sr_dbg(lua_State *L) { char *txt; - txt = (char*)lua_tostring(L, -1); - if(txt!=NULL) + txt = (char *)lua_tostring(L, -1); + if(txt != NULL) LM_DBG("%s", txt); return 0; } @@ -177,11 +177,11 @@ static int lua_sr_dbg (lua_State *L) /** * */ -static int lua_sr_err (lua_State *L) +static int lua_sr_err(lua_State *L) { char *txt; - txt = (char*)lua_tostring(L, -1); - if(txt!=NULL) + txt = (char *)lua_tostring(L, -1); + if(txt != NULL) LM_ERR("%s", txt); return 0; } @@ -189,27 +189,25 @@ static int lua_sr_err (lua_State *L) /** * */ -static int lua_sr_log (lua_State *L) +static int lua_sr_log(lua_State *L) { char *txt; char *level; - level = (char*)lua_tostring(L, -2); - txt = (char*)lua_tostring(L, -1); - if(txt!=NULL) - { - if(level==NULL) - { + level = (char *)lua_tostring(L, -2); + txt = (char *)lua_tostring(L, -1); + if(txt != NULL) { + if(level == NULL) { LM_ERR("%s", txt); } else { - if(strcasecmp(level, "dbg")==0) { + if(strcasecmp(level, "dbg") == 0) { LM_DBG("%s", txt); - } else if(strcasecmp(level, "info")==0) { + } else if(strcasecmp(level, "info") == 0) { LM_INFO("%s", txt); - } else if(strcasecmp(level, "notice")==0) { + } else if(strcasecmp(level, "notice") == 0) { LM_NOTICE("%s", txt); - } else if(strcasecmp(level, "warn")==0) { + } else if(strcasecmp(level, "warn") == 0) { LM_WARN("%s", txt); - } else if(strcasecmp(level, "crit")==0) { + } else if(strcasecmp(level, "crit") == 0) { LM_CRIT("%s", txt); } else { LM_ERR("%s", txt); @@ -222,7 +220,7 @@ static int lua_sr_log (lua_State *L) /** * */ -static int lua_sr_modf (lua_State *L) +static int lua_sr_modf(lua_State *L) { int ret; char *luav[MAX_ACTIONS]; @@ -232,50 +230,43 @@ static int lua_sr_modf (lua_State *L) int mod_type; struct run_act_ctx ra_ctx; struct action *act; - ksr_cmd_export_t* expf; + ksr_cmd_export_t *expf; sr_lua_env_t *env_L; ret = 1; act = NULL; argc = 0; - memset(luav, 0, MAX_ACTIONS*sizeof(char*)); - memset(argv, 0, MAX_ACTIONS*sizeof(char*)); + memset(luav, 0, MAX_ACTIONS * sizeof(char *)); + memset(argv, 0, MAX_ACTIONS * sizeof(char *)); env_L = _app_lua_api.env_get_f(); - if(env_L->msg==NULL) + if(env_L->msg == NULL) goto error; #if 0 app_lua_dump_stack(L); #endif argc = lua_gettop(L); - if(argc==0) - { + if(argc == 0) { LM_ERR("name of module function not provided\n"); goto error; } - if(argc>=MAX_ACTIONS) - { + if(argc >= MAX_ACTIONS) { LM_ERR("too many parameters\n"); goto error; } /* first is function name, then parameters */ - for(i=1; i<=argc; i++) - { - if (!lua_isstring(L, i)) - { + for(i = 1; i <= argc; i++) { + if(!lua_isstring(L, i)) { LM_ERR("invalid parameter type (%d)\n", i); goto error; } - luav[i-1] = (char*)lua_tostring(L, i); + luav[i - 1] = (char *)lua_tostring(L, i); } /* pkg copy only parameters */ - for(i=1; ifixup!=NULL && expf->free_fixup==NULL) { + if(expf->fixup != NULL && expf->free_fixup == NULL) { LM_ERR("function '%s' has fixup - cannot be used\n", luav[0]); goto error; } @@ -324,40 +315,36 @@ static int lua_sr_modf (lua_State *L) goto error; } - act = mk_action(mod_type, argc+1 /* number of (type, value) pairs */, - MODEXP_ST, expf, /* function */ - NUMBER_ST, argc-1, /* parameter number */ - STRING_ST, argv[1], /* param. 1 */ - STRING_ST, argv[2], /* param. 2 */ - STRING_ST, argv[3], /* param. 3 */ - STRING_ST, argv[4], /* param. 4 */ - STRING_ST, argv[5], /* param. 5 */ - STRING_ST, argv[6] /* param. 6 */ - ); + act = mk_action(mod_type, argc + 1 /* number of (type, value) pairs */, + MODEXP_ST, expf, /* function */ + NUMBER_ST, argc - 1, /* parameter number */ + STRING_ST, argv[1], /* param. 1 */ + STRING_ST, argv[2], /* param. 2 */ + STRING_ST, argv[3], /* param. 3 */ + STRING_ST, argv[4], /* param. 4 */ + STRING_ST, argv[5], /* param. 5 */ + STRING_ST, argv[6] /* param. 6 */ + ); - if (act==NULL) { + if(act == NULL) { LM_ERR("action structure could not be created for '%s'\n", luav[0]); goto error; } /* handle fixups */ - if (expf->fixup) { - if(argc==1) - { /* no parameters */ - if(expf->fixup(0, 0)<0) - { + if(expf->fixup) { + if(argc == 1) { /* no parameters */ + if(expf->fixup(0, 0) < 0) { LM_ERR("Error in fixup (0) for '%s'\n", luav[0]); goto error; } } else { - for(i=1; ifixup(&(act->val[i+1].u.data), i)<0) - { + for(i = 1; i < argc; i++) { + if(expf->fixup(&(act->val[i + 1].u.data), i) < 0) { LM_ERR("Error in fixup (%d) for '%s'\n", i, luav[0]); goto error; } - act->val[i+1].type = MODFIXUP_ST; + act->val[i + 1].type = MODFIXUP_ST; } } } @@ -365,30 +352,29 @@ static int lua_sr_modf (lua_State *L) ret = do_action(&ra_ctx, act, env_L->msg); /* free fixups */ - if (expf->fixup) { - for(i=1; ival[i+1].type == MODFIXUP_ST) && (act->val[i+1].u.data)) - { - expf->free_fixup(&(act->val[i+1].u.data), i); + if(expf->fixup) { + for(i = 1; i < argc; i++) { + if((act->val[i + 1].type == MODFIXUP_ST) + && (act->val[i + 1].u.data)) { + expf->free_fixup(&(act->val[i + 1].u.data), i); } } } pkg_free(act); - for(i=0; i4 && (strncmp(uri.s, "sip:", 4)==0 - || strncmp(uri.s, "sips:", 5)==0)) - { - if(parse_uri(uri.s, uri.len, &puri)!=0) - { + if(uri.len > 4 + && (strncmp(uri.s, "sip:", 4) == 0 + || strncmp(uri.s, "sips:", 5) == 0)) { + if(parse_uri(uri.s, uri.len, &puri) != 0) { LM_ERR("failed to parse uri [%s]\n", uri.s); return app_lua_return_false(L); } - ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0, - (puri.transport_val.s)?puri.proto:0); + ret = check_self(&puri.host, (puri.port.s) ? puri.port_no : 0, + (puri.transport_val.s) ? puri.proto : 0); } else { ret = check_self(&uri, 0, 0); } - if(ret==1) + if(ret == 1) return app_lua_return_true(L); return app_lua_return_false(L); } @@ -433,7 +417,7 @@ static int lua_sr_is_myself (lua_State *L) /** * */ -static int lua_sr_setflag (lua_State *L) +static int lua_sr_setflag(lua_State *L) { int flag; sr_lua_env_t *env_L; @@ -441,14 +425,12 @@ static int lua_sr_setflag (lua_State *L) env_L = _app_lua_api.env_get_f(); flag = lua_tointeger(L, -1); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } @@ -460,7 +442,7 @@ static int lua_sr_setflag (lua_State *L) /** * */ -static int lua_sr_resetflag (lua_State *L) +static int lua_sr_resetflag(lua_State *L) { int flag; sr_lua_env_t *env_L; @@ -468,14 +450,12 @@ static int lua_sr_resetflag (lua_State *L) env_L = _app_lua_api.env_get_f(); flag = lua_tointeger(L, -1); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } @@ -487,7 +467,7 @@ static int lua_sr_resetflag (lua_State *L) /** * */ -static int lua_sr_isflagset (lua_State *L) +static int lua_sr_isflagset(lua_State *L) { int flag; int ret; @@ -496,20 +476,18 @@ static int lua_sr_isflagset (lua_State *L) env_L = _app_lua_api.env_get_f(); flag = lua_tointeger(L, -1); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } ret = isflagset(env_L->msg, flag); - if(ret>0) + if(ret > 0) return app_lua_return_true(L); return app_lua_return_false(L); } @@ -517,18 +495,17 @@ static int lua_sr_isflagset (lua_State *L) /** * */ -static int lua_sr_setbflag (lua_State *L) +static int lua_sr_setbflag(lua_State *L) { int flag; int branch; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { flag = lua_tointeger(L, -1); branch = 0; - } else if(lua_gettop(L)==2) { + } else if(lua_gettop(L) == 2) { flag = lua_tointeger(L, -2); branch = lua_tointeger(L, -1); } else { @@ -536,14 +513,12 @@ static int lua_sr_setbflag (lua_State *L) return app_lua_return_false(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } @@ -555,18 +530,17 @@ static int lua_sr_setbflag (lua_State *L) /** * */ -static int lua_sr_resetbflag (lua_State *L) +static int lua_sr_resetbflag(lua_State *L) { int flag; int branch; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { flag = lua_tointeger(L, -1); branch = 0; - } else if(lua_gettop(L)==2) { + } else if(lua_gettop(L) == 2) { flag = lua_tointeger(L, -2); branch = lua_tointeger(L, -1); } else { @@ -574,14 +548,12 @@ static int lua_sr_resetbflag (lua_State *L) return app_lua_return_false(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } @@ -593,7 +565,7 @@ static int lua_sr_resetbflag (lua_State *L) /** * */ -static int lua_sr_isbflagset (lua_State *L) +static int lua_sr_isbflagset(lua_State *L) { int flag; int branch; @@ -601,11 +573,10 @@ static int lua_sr_isbflagset (lua_State *L) sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { flag = lua_tointeger(L, -1); branch = 0; - } else if(lua_gettop(L)==2) { + } else if(lua_gettop(L) == 2) { flag = lua_tointeger(L, -2); branch = lua_tointeger(L, -1); } else { @@ -613,20 +584,18 @@ static int lua_sr_isbflagset (lua_State *L) return app_lua_return_false(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (!flag_in_range(flag)) - { + if(!flag_in_range(flag)) { LM_ERR("invalid flag parameter %d\n", flag); return app_lua_return_false(L); } ret = isbflagset(branch, flag); - if(ret>0) + if(ret > 0) return app_lua_return_true(L); return app_lua_return_false(L); } @@ -634,24 +603,22 @@ static int lua_sr_isbflagset (lua_State *L) /** * */ -static int lua_sr_seturi (lua_State *L) +static int lua_sr_seturi(lua_State *L) { - struct action act; + struct action act; struct run_act_ctx h; str uri; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - uri.s = (char*)lua_tostring(L, -1); - if(uri.s==NULL) - { + uri.s = (char *)lua_tostring(L, -1); + if(uri.s == NULL) { LM_ERR("invalid uri parameter\n"); return app_lua_return_false(L); } uri.len = strlen(uri.s); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } @@ -661,8 +628,7 @@ static int lua_sr_seturi (lua_State *L) act.val[0].u.string = uri.s; act.type = SET_URI_T; init_run_actions_ctx(&h); - if (do_action(&h, &act, env_L->msg)<0) - { + if(do_action(&h, &act, env_L->msg) < 0) { LM_ERR("do action failed\n"); return app_lua_return_false(L); } @@ -672,24 +638,22 @@ static int lua_sr_seturi (lua_State *L) /** * */ -static int lua_sr_setuser (lua_State *L) +static int lua_sr_setuser(lua_State *L) { - struct action act; + struct action act; struct run_act_ctx h; str uri; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - uri.s = (char*)lua_tostring(L, -1); - if(uri.s==NULL) - { + uri.s = (char *)lua_tostring(L, -1); + if(uri.s == NULL) { LM_ERR("invalid uri parameter\n"); return app_lua_return_false(L); } uri.len = strlen(uri.s); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } @@ -699,8 +663,7 @@ static int lua_sr_setuser (lua_State *L) act.val[0].u.string = uri.s; act.type = SET_USER_T; init_run_actions_ctx(&h); - if (do_action(&h, &act, env_L->msg)<0) - { + if(do_action(&h, &act, env_L->msg) < 0) { LM_ERR("do action failed\n"); return app_lua_return_false(L); } @@ -710,24 +673,22 @@ static int lua_sr_setuser (lua_State *L) /** * */ -static int lua_sr_sethost (lua_State *L) +static int lua_sr_sethost(lua_State *L) { - struct action act; + struct action act; struct run_act_ctx h; str uri; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - uri.s = (char*)lua_tostring(L, -1); - if(uri.s==NULL) - { + uri.s = (char *)lua_tostring(L, -1); + if(uri.s == NULL) { LM_ERR("invalid uri parameter\n"); return app_lua_return_false(L); } uri.len = strlen(uri.s); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } @@ -737,8 +698,7 @@ static int lua_sr_sethost (lua_State *L) act.val[0].u.string = uri.s; act.type = SET_HOST_T; init_run_actions_ctx(&h); - if (do_action(&h, &act, env_L->msg)<0) - { + if(do_action(&h, &act, env_L->msg) < 0) { LM_ERR("do action failed\n"); return app_lua_return_false(L); } @@ -748,28 +708,25 @@ static int lua_sr_sethost (lua_State *L) /** * */ -static int lua_sr_setdsturi (lua_State *L) +static int lua_sr_setdsturi(lua_State *L) { str uri; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - uri.s = (char*)lua_tostring(L, -1); - if(uri.s==NULL) - { + uri.s = (char *)lua_tostring(L, -1); + if(uri.s == NULL) { LM_ERR("invalid uri parameter\n"); return app_lua_return_false(L); } uri.len = strlen(uri.s); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } - if (set_dst_uri(env_L->msg, &uri)<0) - { + if(set_dst_uri(env_L->msg, &uri) < 0) { LM_ERR("setting dst uri failed\n"); return app_lua_return_false(L); } @@ -779,13 +736,12 @@ static int lua_sr_setdsturi (lua_State *L) /** * */ -static int lua_sr_resetdsturi (lua_State *L) +static int lua_sr_resetdsturi(lua_State *L) { sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_false(L); } @@ -798,33 +754,22 @@ static int lua_sr_resetdsturi (lua_State *L) /** * */ -static const luaL_Reg _sr_core_Map [] = { - {"probe", lua_sr_probe}, - {"dbg", lua_sr_dbg}, - {"err", lua_sr_err}, - {"log", lua_sr_log}, - {"modf", lua_sr_modf}, - {"is_myself", lua_sr_is_myself}, - {"setflag", lua_sr_setflag}, - {"resetflag", lua_sr_resetflag}, - {"isflagset", lua_sr_isflagset}, - {"setbflag", lua_sr_setbflag}, - {"resetbflag", lua_sr_resetbflag}, - {"isbflagset", lua_sr_isbflagset}, - {"seturi", lua_sr_seturi}, - {"setuser", lua_sr_setuser}, - {"sethost", lua_sr_sethost}, - {"setdsturi", lua_sr_setdsturi}, - {"resetdsturi", lua_sr_resetdsturi}, - {NULL, NULL} -}; +static const luaL_Reg _sr_core_Map[] = {{"probe", lua_sr_probe}, + {"dbg", lua_sr_dbg}, {"err", lua_sr_err}, {"log", lua_sr_log}, + {"modf", lua_sr_modf}, {"is_myself", lua_sr_is_myself}, + {"setflag", lua_sr_setflag}, {"resetflag", lua_sr_resetflag}, + {"isflagset", lua_sr_isflagset}, {"setbflag", lua_sr_setbflag}, + {"resetbflag", lua_sr_resetbflag}, {"isbflagset", lua_sr_isbflagset}, + {"seturi", lua_sr_seturi}, {"setuser", lua_sr_setuser}, + {"sethost", lua_sr_sethost}, {"setdsturi", lua_sr_setdsturi}, + {"resetdsturi", lua_sr_resetdsturi}, {NULL, NULL}}; /** * */ -static int lua_sr_hdr_append (lua_State *L) +static int lua_sr_hdr_append(lua_State *L) { - struct lump* anchor; + struct lump *anchor; struct hdr_field *hf; char *txt; int len; @@ -833,36 +778,32 @@ static int lua_sr_hdr_append (lua_State *L) env_L = _app_lua_api.env_get_f(); - txt = (char*)lua_tostring(L, -1); - if(txt==NULL || env_L->msg==NULL) + txt = (char *)lua_tostring(L, -1); + if(txt == NULL || env_L->msg == NULL) return 0; LM_DBG("append hf: %s\n", txt); - if (parse_headers(env_L->msg, HDR_EOH_F, 0) == -1) - { + if(parse_headers(env_L->msg, HDR_EOH_F, 0) == -1) { LM_ERR("error while parsing message\n"); return 0; } hf = env_L->msg->last_header; len = strlen(txt); - hdr = (char*)pkg_malloc(len+1); - if(hdr==NULL) - { + hdr = (char *)pkg_malloc(len + 1); + if(hdr == NULL) { PKG_MEM_ERROR; return 0; } memcpy(hdr, txt, len); - anchor = anchor_lump(env_L->msg, - hf->name.s + hf->len - env_L->msg->buf, 0, 0); - if(anchor==NULL) - { + anchor = anchor_lump( + env_L->msg, hf->name.s + hf->len - env_L->msg->buf, 0, 0); + if(anchor == NULL) { LM_ERR("unable to get the anchor\n"); pkg_free(hdr); return 0; } - if(insert_new_lump_before(anchor, hdr, len, 0) == 0) - { + if(insert_new_lump_before(anchor, hdr, len, 0) == 0) { LM_ERR("can't insert lump\n"); pkg_free(hdr); return 0; @@ -873,9 +814,9 @@ static int lua_sr_hdr_append (lua_State *L) /** * */ -static int lua_sr_hdr_remove (lua_State *L) +static int lua_sr_hdr_remove(lua_State *L) { - struct lump* anchor; + struct lump *anchor; struct hdr_field *hf; char *txt; str hname; @@ -883,26 +824,23 @@ static int lua_sr_hdr_remove (lua_State *L) env_L = _app_lua_api.env_get_f(); - txt = (char*)lua_tostring(L, -1); - if(txt==NULL || env_L->msg==NULL) + txt = (char *)lua_tostring(L, -1); + if(txt == NULL || env_L->msg == NULL) return 0; LM_DBG("remove hf: %s\n", txt); - if (parse_headers(env_L->msg, HDR_EOH_F, 0) == -1) { + if(parse_headers(env_L->msg, HDR_EOH_F, 0) == -1) { LM_ERR("error while parsing message\n"); return 0; } hname.s = txt; hname.len = strlen(txt); - for (hf=env_L->msg->headers; hf; hf=hf->next) - { - if (cmp_hdrname_str(&hf->name, &hname)==0) - { - anchor=del_lump(env_L->msg, - hf->name.s - env_L->msg->buf, hf->len, 0); - if (anchor==0) - { + for(hf = env_L->msg->headers; hf; hf = hf->next) { + if(cmp_hdrname_str(&hf->name, &hname) == 0) { + anchor = del_lump( + env_L->msg, hf->name.s - env_L->msg->buf, hf->len, 0); + if(anchor == 0) { LM_ERR("cannot remove hdr %s\n", txt); return 0; } @@ -914,9 +852,9 @@ static int lua_sr_hdr_remove (lua_State *L) /** * */ -static int lua_sr_hdr_insert (lua_State *L) +static int lua_sr_hdr_insert(lua_State *L) { - struct lump* anchor; + struct lump *anchor; struct hdr_field *hf; char *txt; int len; @@ -925,24 +863,22 @@ static int lua_sr_hdr_insert (lua_State *L) env_L = _app_lua_api.env_get_f(); - txt = (char*)lua_tostring(L, -1); - if(txt==NULL || env_L->msg==NULL) + txt = (char *)lua_tostring(L, -1); + if(txt == NULL || env_L->msg == NULL) return 0; LM_DBG("insert hf: %s\n", txt); hf = env_L->msg->headers; len = strlen(txt); - hdr = (char*)pkg_malloc(len+1); - if(hdr==NULL) - { + hdr = (char *)pkg_malloc(len + 1); + if(hdr == NULL) { PKG_MEM_ERROR; return 0; } memcpy(hdr, txt, len); - anchor = anchor_lump(env_L->msg, - hf->name.s + hf->len - env_L->msg->buf, 0, 0); - if((anchor==NULL) || (insert_new_lump_before(anchor, hdr, len, 0) == 0)) - { + anchor = anchor_lump( + env_L->msg, hf->name.s + hf->len - env_L->msg->buf, 0, 0); + if((anchor == NULL) || (insert_new_lump_before(anchor, hdr, len, 0) == 0)) { LM_ERR("can't insert lump\n"); pkg_free(hdr); return 0; @@ -953,7 +889,7 @@ static int lua_sr_hdr_insert (lua_State *L) /** * */ -static int lua_sr_hdr_append_to_reply (lua_State *L) +static int lua_sr_hdr_append_to_reply(lua_State *L) { char *txt; int len; @@ -961,15 +897,14 @@ static int lua_sr_hdr_append_to_reply (lua_State *L) env_L = _app_lua_api.env_get_f(); - txt = (char*)lua_tostring(L, -1); - if(txt==NULL || env_L->msg==NULL) + txt = (char *)lua_tostring(L, -1); + if(txt == NULL || env_L->msg == NULL) return 0; LM_DBG("append to reply: %s\n", txt); len = strlen(txt); - if(add_lump_rpl(env_L->msg, txt, len, LUMP_RPL_HDR)==0) - { + if(add_lump_rpl(env_L->msg, txt, len, LUMP_RPL_HDR) == 0) { LM_ERR("unable to add reply lump\n"); return 0; } @@ -981,23 +916,19 @@ static int lua_sr_hdr_append_to_reply (lua_State *L) /** * */ -static const luaL_Reg _sr_hdr_Map [] = { - {"append", lua_sr_hdr_append}, - {"remove", lua_sr_hdr_remove}, - {"insert", lua_sr_hdr_insert}, - {"append_to_reply", lua_sr_hdr_append_to_reply}, - {NULL, NULL} -}; +static const luaL_Reg _sr_hdr_Map[] = {{"append", lua_sr_hdr_append}, + {"remove", lua_sr_hdr_remove}, {"insert", lua_sr_hdr_insert}, + {"append_to_reply", lua_sr_hdr_append_to_reply}, {NULL, NULL}}; /** * */ -static int lua_sr_pv_push_val_null (lua_State *L, int rmode) +static int lua_sr_pv_push_val_null(lua_State *L, int rmode) { - if(rmode==1) { + if(rmode == 1) { lua_pushlstring(L, "<>", 8); - } else if(rmode==2) { + } else if(rmode == 2) { lua_pushlstring(L, "", 0); } else { lua_pushnil(L); @@ -1008,9 +939,9 @@ static int lua_sr_pv_push_val_null (lua_State *L, int rmode) /** * */ -static int lua_sr_pv_push_valx (lua_State *L, int rmode, int vi, str *vs) +static int lua_sr_pv_push_valx(lua_State *L, int rmode, int vi, str *vs) { - if(rmode==1) { + if(rmode == 1) { lua_pushinteger(L, vi); } else { lua_pushlstring(L, vs->s, vs->len); @@ -1021,7 +952,7 @@ static int lua_sr_pv_push_valx (lua_State *L, int rmode, int vi, str *vs) /** * */ -static int lua_sr_pv_get_val (lua_State *L, int rmode) +static int lua_sr_pv_get_val(lua_State *L, int rmode) { str pvn; pv_spec_t *pvs; @@ -1031,8 +962,8 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) env_L = _app_lua_api.env_get_f(); - pvn.s = (char*)lua_tostring(L, -1); - if(pvn.s==NULL || env_L->msg==NULL) { + pvn.s = (char *)lua_tostring(L, -1); + if(pvn.s == NULL || env_L->msg == NULL) { return lua_sr_pv_push_val_null(L, rmode); } @@ -1044,7 +975,7 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) return lua_sr_pv_push_val_null(L, rmode); } pvs = pv_cache_get(&pvn); - if(pvs==NULL) { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return lua_sr_pv_push_val_null(L, rmode); } @@ -1053,10 +984,10 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) LM_ERR("unable to get pv value for [%s]\n", pvn.s); return lua_sr_pv_push_val_null(L, rmode); } - if(val.flags&PV_VAL_NULL) { + if(val.flags & PV_VAL_NULL) { return lua_sr_pv_push_val_null(L, rmode); } - if(val.flags&PV_TYPE_INT) { + if(val.flags & PV_TYPE_INT) { lua_pushinteger(L, val.ri); return 1; } @@ -1067,7 +998,7 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) /** * */ -static int lua_sr_pv_get (lua_State *L) +static int lua_sr_pv_get(lua_State *L) { return lua_sr_pv_get_val(L, 0); } @@ -1075,7 +1006,7 @@ static int lua_sr_pv_get (lua_State *L) /** * */ -static int lua_sr_pv_getw (lua_State *L) +static int lua_sr_pv_getw(lua_State *L) { return lua_sr_pv_get_val(L, 1); } @@ -1083,7 +1014,7 @@ static int lua_sr_pv_getw (lua_State *L) /** * */ -static int lua_sr_pv_gete (lua_State *L) +static int lua_sr_pv_gete(lua_State *L) { return lua_sr_pv_get_val(L, 2); } @@ -1091,7 +1022,7 @@ static int lua_sr_pv_gete (lua_State *L) /** * */ -static int lua_sr_pv_get_valx (lua_State *L, int rmode) +static int lua_sr_pv_get_valx(lua_State *L, int rmode) { str pvn; pv_spec_t *pvs; @@ -1103,11 +1034,11 @@ static int lua_sr_pv_get_valx (lua_State *L, int rmode) env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)<2) { + if(lua_gettop(L) < 2) { LM_ERR("to few parameters [%d]\n", lua_gettop(L)); return lua_sr_pv_push_val_null(L, 0); } - if(rmode==1) { + if(rmode == 1) { if(!lua_isnumber(L, -1)) { LM_ERR("invalid int parameter\n"); return lua_sr_pv_push_val_null(L, 0); @@ -1118,12 +1049,12 @@ static int lua_sr_pv_get_valx (lua_State *L, int rmode) LM_ERR("invalid str parameter\n"); return lua_sr_pv_push_val_null(L, 0); } - xsval.s = (char*)lua_tostring(L, -1); + xsval.s = (char *)lua_tostring(L, -1); xsval.len = strlen(xsval.s); } - pvn.s = (char*)lua_tostring(L, -2); - if(pvn.s==NULL || env_L->msg==NULL) + pvn.s = (char *)lua_tostring(L, -2); + if(pvn.s == NULL || env_L->msg == NULL) return lua_sr_pv_push_valx(L, rmode, xival, &xsval); pvn.len = strlen(pvn.s); @@ -1134,7 +1065,7 @@ static int lua_sr_pv_get_valx (lua_State *L, int rmode) return lua_sr_pv_push_valx(L, rmode, xival, &xsval); } pvs = pv_cache_get(&pvn); - if(pvs==NULL) { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return lua_sr_pv_push_valx(L, rmode, xival, &xsval); } @@ -1144,10 +1075,10 @@ static int lua_sr_pv_get_valx (lua_State *L, int rmode) LM_ERR("unable to get pv value for [%s]\n", pvn.s); return lua_sr_pv_push_valx(L, rmode, xival, &xsval); } - if(val.flags&PV_VAL_NULL) { + if(val.flags & PV_VAL_NULL) { return lua_sr_pv_push_valx(L, rmode, xival, &xsval); } - if(val.flags&PV_TYPE_INT) { + if(val.flags & PV_TYPE_INT) { lua_pushinteger(L, val.ri); return 1; } @@ -1158,7 +1089,7 @@ static int lua_sr_pv_get_valx (lua_State *L, int rmode) /** * */ -static int lua_sr_pv_getvs (lua_State *L) +static int lua_sr_pv_getvs(lua_State *L) { return lua_sr_pv_get_valx(L, 0); } @@ -1166,7 +1097,7 @@ static int lua_sr_pv_getvs (lua_State *L) /** * */ -static int lua_sr_pv_getvn (lua_State *L) +static int lua_sr_pv_getvn(lua_State *L) { return lua_sr_pv_get_valx(L, 1); } @@ -1174,7 +1105,7 @@ static int lua_sr_pv_getvn (lua_State *L) /** * */ -static int lua_sr_pv_seti (lua_State *L) +static int lua_sr_pv_seti(lua_State *L) { str pvn; pv_spec_t *pvs; @@ -1184,40 +1115,35 @@ static int lua_sr_pv_seti (lua_State *L) env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)<2) - { + if(lua_gettop(L) < 2) { LM_ERR("to few parameters [%d]\n", lua_gettop(L)); return 0; } - if(!lua_isnumber(L, -1)) - { + if(!lua_isnumber(L, -1)) { LM_ERR("invalid int parameter\n"); return 0; } memset(&val, 0, sizeof(pv_value_t)); val.ri = lua_tointeger(L, -1); - val.flags |= PV_TYPE_INT|PV_VAL_INT; + val.flags |= PV_TYPE_INT | PV_VAL_INT; - pvn.s = (char*)lua_tostring(L, -2); - if(pvn.s==NULL || env_L->msg==NULL) + pvn.s = (char *)lua_tostring(L, -2); + if(pvn.s == NULL || env_L->msg == NULL) return 0; pvn.len = strlen(pvn.s); LM_DBG("pv set: %s\n", pvn.s); pl = pv_locate_name(&pvn); - if(pl != pvn.len) - { + if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); return 0; } pvs = pv_cache_get(&pvn); - if(pvs==NULL) - { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return 0; } - if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0) - { + if(pv_set_spec_value(env_L->msg, pvs, 0, &val) < 0) { LM_ERR("unable to set pv [%s]\n", pvn.s); return 0; } @@ -1228,7 +1154,7 @@ static int lua_sr_pv_seti (lua_State *L) /** * */ -static int lua_sr_pv_sets (lua_State *L) +static int lua_sr_pv_sets(lua_State *L) { str pvn; pv_spec_t *pvs; @@ -1238,44 +1164,40 @@ static int lua_sr_pv_sets (lua_State *L) env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)<2) - { - LM_ERR("to few parameters [%d]\n",lua_gettop(L)); + if(lua_gettop(L) < 2) { + LM_ERR("to few parameters [%d]\n", lua_gettop(L)); return 0; } - if(!lua_isstring(L, -1)) - { - LM_ERR("Cannot convert to a string when assigning value to variable: %s\n", + if(!lua_isstring(L, -1)) { + LM_ERR("Cannot convert to a string when assigning value to variable: " + "%s\n", lua_tostring(L, -2)); return 0; } memset(&val, 0, sizeof(pv_value_t)); - val.rs.s = (char*)lua_tostring(L, -1); + val.rs.s = (char *)lua_tostring(L, -1); val.rs.len = strlen(val.rs.s); val.flags |= PV_VAL_STR; - pvn.s = (char*)lua_tostring(L, -2); - if(pvn.s==NULL || env_L->msg==NULL) + pvn.s = (char *)lua_tostring(L, -2); + if(pvn.s == NULL || env_L->msg == NULL) return 0; pvn.len = strlen(pvn.s); LM_DBG("pv set: %s\n", pvn.s); pl = pv_locate_name(&pvn); - if(pl != pvn.len) - { + if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); return 0; } pvs = pv_cache_get(&pvn); - if(pvs==NULL) - { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return 0; } - if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0) - { + if(pv_set_spec_value(env_L->msg, pvs, 0, &val) < 0) { LM_ERR("unable to set pv [%s]\n", pvn.s); return 0; } @@ -1286,7 +1208,7 @@ static int lua_sr_pv_sets (lua_State *L) /** * */ -static int lua_sr_pv_unset (lua_State *L) +static int lua_sr_pv_unset(lua_State *L) { str pvn; pv_spec_t *pvs; @@ -1296,28 +1218,25 @@ static int lua_sr_pv_unset (lua_State *L) env_L = _app_lua_api.env_get_f(); - pvn.s = (char*)lua_tostring(L, -1); - if(pvn.s==NULL || env_L->msg==NULL) + pvn.s = (char *)lua_tostring(L, -1); + if(pvn.s == NULL || env_L->msg == NULL) return 0; pvn.len = strlen(pvn.s); LM_DBG("pv unset: %s\n", pvn.s); pl = pv_locate_name(&pvn); - if(pl != pvn.len) - { + if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); return 0; } pvs = pv_cache_get(&pvn); - if(pvs==NULL) - { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return 0; } memset(&val, 0, sizeof(pv_value_t)); val.flags |= PV_VAL_NULL; - if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0) - { + if(pv_set_spec_value(env_L->msg, pvs, 0, &val) < 0) { LM_ERR("unable to unset pv [%s]\n", pvn.s); return 0; } @@ -1328,7 +1247,7 @@ static int lua_sr_pv_unset (lua_State *L) /** * */ -static int lua_sr_pv_is_null (lua_State *L) +static int lua_sr_pv_is_null(lua_State *L) { str pvn; pv_spec_t *pvs; @@ -1338,33 +1257,29 @@ static int lua_sr_pv_is_null (lua_State *L) env_L = _app_lua_api.env_get_f(); - pvn.s = (char*)lua_tostring(L, -1); - if(pvn.s==NULL || env_L->msg==NULL) + pvn.s = (char *)lua_tostring(L, -1); + if(pvn.s == NULL || env_L->msg == NULL) return 0; pvn.len = strlen(pvn.s); LM_DBG("pv is null test: %s\n", pvn.s); pl = pv_locate_name(&pvn); - if(pl != pvn.len) - { + if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); return 0; } pvs = pv_cache_get(&pvn); - if(pvs==NULL) - { + if(pvs == NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); return 0; } memset(&val, 0, sizeof(pv_value_t)); - if(pv_get_spec_value(env_L->msg, pvs, &val) != 0) - { + if(pv_get_spec_value(env_L->msg, pvs, &val) != 0) { LM_NOTICE("unable to get pv value for [%s]\n", pvn.s); lua_pushboolean(L, 1); return 1; } - if(val.flags&PV_VAL_NULL) - { + if(val.flags & PV_VAL_NULL) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); @@ -1375,30 +1290,25 @@ static int lua_sr_pv_is_null (lua_State *L) /** * */ -static const luaL_Reg _sr_pv_Map [] = { - {"get", lua_sr_pv_get}, - {"getw", lua_sr_pv_getw}, - {"gete", lua_sr_pv_gete}, - {"getvn", lua_sr_pv_getvn}, - {"getvs", lua_sr_pv_getvs}, - {"seti", lua_sr_pv_seti}, - {"sets", lua_sr_pv_sets}, - {"unset", lua_sr_pv_unset}, - {"is_null", lua_sr_pv_is_null}, - {NULL, NULL} -}; +static const luaL_Reg _sr_pv_Map[] = {{"get", lua_sr_pv_get}, + {"getw", lua_sr_pv_getw}, {"gete", lua_sr_pv_gete}, + {"getvn", lua_sr_pv_getvn}, {"getvs", lua_sr_pv_getvs}, + {"seti", lua_sr_pv_seti}, {"sets", lua_sr_pv_sets}, + {"unset", lua_sr_pv_unset}, {"is_null", lua_sr_pv_is_null}, + {NULL, NULL}}; /** * creates and push a table to the lua stack with * the elements of the list */ -static int lua_sr_push_str_list_table(lua_State *L, struct str_list *list) { +static int lua_sr_push_str_list_table(lua_State *L, struct str_list *list) +{ lua_Number i = 1; struct str_list *k = list; lua_newtable(L); - while(k!=NULL){ + while(k != NULL) { lua_pushnumber(L, i); lua_pushlstring(L, k->s.s, k->s.len); lua_settable(L, -3); @@ -1408,82 +1318,85 @@ static int lua_sr_push_str_list_table(lua_State *L, struct str_list *list) { return 1; } -static int lua_sr_push_xavp_table(lua_State *L, sr_xavp_t *xavp, const int simple_flag); +static int lua_sr_push_xavp_table( + lua_State *L, sr_xavp_t *xavp, const int simple_flag); /** * creates and push a table for the key name in xavp * if simple_flag is != 0 it will return only the first value */ -static void lua_sr_push_xavp_name_table(lua_State *L, sr_xavp_t *xavp, - str name, const int simple_flag) +static void lua_sr_push_xavp_name_table( + lua_State *L, sr_xavp_t *xavp, str name, const int simple_flag) { lua_Number i = 1; lua_Number elem = 1; sr_xavp_t *avp = xavp; - while(avp!=NULL&&!STR_EQ(avp->name,name)) - { + while(avp != NULL && !STR_EQ(avp->name, name)) { avp = avp->next; } - if(simple_flag==0) lua_newtable(L); + if(simple_flag == 0) + lua_newtable(L); - while(avp!=NULL){ - if(simple_flag==0) lua_pushnumber(L, elem); + while(avp != NULL) { + if(simple_flag == 0) + lua_pushnumber(L, elem); switch(avp->val.type) { case SR_XTYPE_NULL: lua_pushnil(L); - break; + break; case SR_XTYPE_LONG: i = avp->val.v.l; lua_pushnumber(L, i); - break; + break; case SR_XTYPE_STR: lua_pushlstring(L, avp->val.v.s.s, avp->val.v.s.len); - break; + break; case SR_XTYPE_TIME: case SR_XTYPE_LLONG: case SR_XTYPE_DATA: lua_pushnil(L); LM_WARN("XAVP type:%d value not supported\n", avp->val.type); - break; + break; case SR_XTYPE_XAVP: - if(!lua_sr_push_xavp_table(L,avp->val.v.xavp, simple_flag)){ + if(!lua_sr_push_xavp_table(L, avp->val.v.xavp, simple_flag)) { LM_ERR("xavp:%.*s subtable error. Nil value added\n", - avp->name.len, avp->name.s); + avp->name.len, avp->name.s); lua_pushnil(L); } - break; + break; default: LM_ERR("xavp:%.*s unknown type: %d. Nil value added\n", - avp->name.len, avp->name.s, avp->val.type); + avp->name.len, avp->name.s, avp->val.type); lua_pushnil(L); - break; + break; } - if(simple_flag==0) - { + if(simple_flag == 0) { lua_rawset(L, -3); elem = elem + 1; avp = xavp_get_next(avp); - } - else { + } else { lua_setfield(L, -2, name.s); avp = NULL; } } - if(simple_flag==0) lua_setfield(L, -2, name.s); + if(simple_flag == 0) + lua_setfield(L, -2, name.s); } /** * creates and push a table to the lua stack with * the elements of the xavp */ -static int lua_sr_push_xavp_table(lua_State *L, sr_xavp_t *xavp, const int simple_flag) { +static int lua_sr_push_xavp_table( + lua_State *L, sr_xavp_t *xavp, const int simple_flag) +{ sr_xavp_t *avp = NULL; struct str_list *keys; struct str_list *k; - if(xavp->val.type!=SR_XTYPE_XAVP){ + if(xavp->val.type != SR_XTYPE_XAVP) { LM_ERR("%s not xavp?\n", xavp->name.s); return 0; } @@ -1491,15 +1404,13 @@ static int lua_sr_push_xavp_table(lua_State *L, sr_xavp_t *xavp, const int simpl keys = xavp_get_list_key_names(xavp); lua_newtable(L); - if(keys!=NULL) - { - do - { + if(keys != NULL) { + do { lua_sr_push_xavp_name_table(L, avp, keys->s, simple_flag); k = keys; keys = keys->next; pkg_free(k); - }while(keys!=NULL); + } while(keys != NULL); } return 1; @@ -1523,16 +1434,13 @@ static int lua_sr_xavp_get(lua_State *L) env_L = _app_lua_api.env_get_f(); num_param = lua_gettop(L); - if(num_param<2 || num_param>3) - { + if(num_param < 2 || num_param > 3) { LM_ERR("wrong number of parameters [%d]\n", num_param); return 0; } - if(num_param==3) - { - if(!lua_isnumber(L, param)) - { + if(num_param == 3) { + if(!lua_isnumber(L, param)) { LM_ERR("invalid int parameter\n"); return 0; } @@ -1540,40 +1448,32 @@ static int lua_sr_xavp_get(lua_State *L) param = param - 1; } - if(!lua_isnumber(L, param)) - { - if(lua_isnil(L, param)) - { + if(!lua_isnumber(L, param)) { + if(lua_isnil(L, param)) { all_flag = 1; - } - else - { + } else { LM_ERR("invalid parameter, must be int or nil\n"); return 0; } - } - else - { + } else { indx = lua_tointeger(L, param); } param = param - 1; - xavp_name.s = (char*)lua_tostring(L, param); - if(xavp_name.s==NULL || env_L->msg==NULL) - { + xavp_name.s = (char *)lua_tostring(L, param); + if(xavp_name.s == NULL || env_L->msg == NULL) { LM_ERR("No xavp name in %d param\n", param); return 0; } xavp_name.len = strlen(xavp_name.s); - if(all_flag>0) { + if(all_flag > 0) { indx = 0; lua_newtable(L); } xavp_size = xavp_count(&xavp_name, NULL); - if(indx<0) - { - if((indx*-1)>xavp_size) - { - LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, indx); + if(indx < 0) { + if((indx * -1) > xavp_size) { + LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, + indx); lua_pushnil(L); return 1; } @@ -1581,25 +1481,25 @@ static int lua_sr_xavp_get(lua_State *L) } avp = xavp_get_by_index(&xavp_name, indx, NULL); - do - { - if(avp==NULL){ - LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, indx); + do { + if(avp == NULL) { + LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, + indx); lua_pushnil(L); return 1; } - if(all_flag!=0) { + if(all_flag != 0) { lua_pushnumber(L, elem); elem = elem + 1; } lua_sr_push_xavp_table(L, avp, simple_flag); - if(all_flag!=0) { + if(all_flag != 0) { lua_rawset(L, -3); indx = indx + 1; avp = xavp_get_by_index(&xavp_name, indx, NULL); - } - else return 1; - }while(avp!=NULL); + } else + return 1; + } while(avp != NULL); return 1; } @@ -1607,7 +1507,7 @@ static int lua_sr_xavp_get(lua_State *L) /** * puts a table with the list of keys of the xavp */ -static int lua_sr_xavp_get_keys (lua_State *L) +static int lua_sr_xavp_get_keys(lua_State *L) { str xavp_name; int indx = 0; @@ -1617,34 +1517,33 @@ static int lua_sr_xavp_get_keys (lua_State *L) env_L = _app_lua_api.env_get_f(); - if(lua_gettop(L)<2) - { - LM_ERR("to few parameters [%d]\n",lua_gettop(L)); + if(lua_gettop(L) < 2) { + LM_ERR("to few parameters [%d]\n", lua_gettop(L)); return 0; } - if(!lua_isnumber(L, -1)) - { + if(!lua_isnumber(L, -1)) { LM_ERR("invalid int parameter\n"); return 0; } indx = lua_tointeger(L, -1); - xavp_name.s = (char*)lua_tostring(L, -2); - if(xavp_name.s==NULL || env_L->msg==NULL) + xavp_name.s = (char *)lua_tostring(L, -2); + if(xavp_name.s == NULL || env_L->msg == NULL) return 0; xavp_name.len = strlen(xavp_name.s); avp = xavp_get_by_index(&xavp_name, indx, NULL); - if(avp==NULL){ - LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, indx); + if(avp == NULL) { + LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, + indx); lua_pushnil(L); return 1; } keys = xavp_get_list_key_names(avp); lua_sr_push_str_list_table(L, keys); // free list - while(keys!=NULL){ + while(keys != NULL) { k = keys; keys = k->next; pkg_free(k); @@ -1655,11 +1554,8 @@ static int lua_sr_xavp_get_keys (lua_State *L) /** * */ -static const luaL_Reg _sr_xavp_Map [] = { - {"get", lua_sr_xavp_get}, - {"get_keys", lua_sr_xavp_get_keys}, - {NULL, NULL} -}; +static const luaL_Reg _sr_xavp_Map[] = {{"get", lua_sr_xavp_get}, + {"get_keys", lua_sr_xavp_get_keys}, {NULL, NULL}}; /** * @@ -1668,8 +1564,8 @@ void lua_sr_core_openlibs(lua_State *L) { LM_DBG("exporting sr core extensions\n"); - luaL_openlib(L, "sr", _sr_core_Map, 0); - luaL_openlib(L, "sr.hdr", _sr_hdr_Map, 0); - luaL_openlib(L, "sr.pv", _sr_pv_Map, 0); + luaL_openlib(L, "sr", _sr_core_Map, 0); + luaL_openlib(L, "sr.hdr", _sr_hdr_Map, 0); + luaL_openlib(L, "sr.pv", _sr_pv_Map, 0); luaL_openlib(L, "sr.xavp", _sr_xavp_Map, 0); } diff --git a/src/modules/app_lua_sr/app_lua_sr_api.h b/src/modules/app_lua_sr/app_lua_sr_api.h index f700fb2fdff..ddbffee09c4 100644 --- a/src/modules/app_lua_sr/app_lua_sr_api.h +++ b/src/modules/app_lua_sr/app_lua_sr_api.h @@ -33,13 +33,12 @@ int app_lua_return_true(lua_State *L); void lua_sr_core_openlibs(lua_State *L); void lua_sr_kemi_register_libs(lua_State *L); -int sr_kemi_lua_exec_func(lua_State* L, int eidx); +int sr_kemi_lua_exec_func(lua_State *L, int eidx); #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504 -void ksr_luaL_openlib(lua_State *L, const char *libname, - const luaL_Reg *lfuncs, int nup); +void ksr_luaL_openlib( + lua_State *L, const char *libname, const luaL_Reg *lfuncs, int nup); #define luaL_openlib ksr_luaL_openlib #endif #endif - diff --git a/src/modules/app_lua_sr/app_lua_sr_exp.c b/src/modules/app_lua_sr/app_lua_sr_exp.c index 3dab7884369..522f0cfb87a 100644 --- a/src/modules/app_lua_sr/app_lua_sr_exp.c +++ b/src/modules/app_lua_sr/app_lua_sr_exp.c @@ -59,31 +59,31 @@ #include "app_lua_sr_api.h" -#define SR_LUA_EXP_MOD_SL (1<<0) -#define SR_LUA_EXP_MOD_TM (1<<1) -#define SR_LUA_EXP_MOD_SQLOPS (1<<2) -#define SR_LUA_EXP_MOD_RR (1<<3) -#define SR_LUA_EXP_MOD_AUTH (1<<4) -#define SR_LUA_EXP_MOD_AUTH_DB (1<<5) -#define SR_LUA_EXP_MOD_MAXFWD (1<<6) -#define SR_LUA_EXP_MOD_REGISTRAR (1<<7) -#define SR_LUA_EXP_MOD_DISPATCHER (1<<8) -#define SR_LUA_EXP_MOD_XHTTP (1<<9) -#define SR_LUA_EXP_MOD_SDPOPS (1<<10) -#define SR_LUA_EXP_MOD_PRESENCE (1<<11) -#define SR_LUA_EXP_MOD_PRESENCE_XML (1<<12) -#define SR_LUA_EXP_MOD_TEXTOPS (1<<13) -#define SR_LUA_EXP_MOD_PUA_USRLOC (1<<14) -#define SR_LUA_EXP_MOD_SIPUTILS (1<<15) -#define SR_LUA_EXP_MOD_RLS (1<<16) -#define SR_LUA_EXP_MOD_ALIAS_DB (1<<17) -#define SR_LUA_EXP_MOD_MSILO (1<<18) -#define SR_LUA_EXP_MOD_UAC (1<<19) -#define SR_LUA_EXP_MOD_SANITY (1<<20) -#define SR_LUA_EXP_MOD_CFGUTILS (1<<21) -#define SR_LUA_EXP_MOD_TMX (1<<22) -#define SR_LUA_EXP_MOD_MQUEUE (1<<23) -#define SR_LUA_EXP_MOD_NDB_MONGODB (1<<24) +#define SR_LUA_EXP_MOD_SL (1 << 0) +#define SR_LUA_EXP_MOD_TM (1 << 1) +#define SR_LUA_EXP_MOD_SQLOPS (1 << 2) +#define SR_LUA_EXP_MOD_RR (1 << 3) +#define SR_LUA_EXP_MOD_AUTH (1 << 4) +#define SR_LUA_EXP_MOD_AUTH_DB (1 << 5) +#define SR_LUA_EXP_MOD_MAXFWD (1 << 6) +#define SR_LUA_EXP_MOD_REGISTRAR (1 << 7) +#define SR_LUA_EXP_MOD_DISPATCHER (1 << 8) +#define SR_LUA_EXP_MOD_XHTTP (1 << 9) +#define SR_LUA_EXP_MOD_SDPOPS (1 << 10) +#define SR_LUA_EXP_MOD_PRESENCE (1 << 11) +#define SR_LUA_EXP_MOD_PRESENCE_XML (1 << 12) +#define SR_LUA_EXP_MOD_TEXTOPS (1 << 13) +#define SR_LUA_EXP_MOD_PUA_USRLOC (1 << 14) +#define SR_LUA_EXP_MOD_SIPUTILS (1 << 15) +#define SR_LUA_EXP_MOD_RLS (1 << 16) +#define SR_LUA_EXP_MOD_ALIAS_DB (1 << 17) +#define SR_LUA_EXP_MOD_MSILO (1 << 18) +#define SR_LUA_EXP_MOD_UAC (1 << 19) +#define SR_LUA_EXP_MOD_SANITY (1 << 20) +#define SR_LUA_EXP_MOD_CFGUTILS (1 << 21) +#define SR_LUA_EXP_MOD_TMX (1 << 22) +#define SR_LUA_EXP_MOD_MQUEUE (1 << 23) +#define SR_LUA_EXP_MOD_NDB_MONGODB (1 << 24) extern app_lua_api_t _app_lua_api; @@ -135,7 +135,7 @@ static sl_api_t _lua_slb; /** * tm */ -static tm_api_t _lua_tmb; +static tm_api_t _lua_tmb; static tm_xapi_t _lua_xtmb; /** @@ -222,7 +222,7 @@ static ndb_mongodb_api_t _lua_ndb_mongodbb; /** * */ -static int lua_sr_sl_send_reply (lua_State *L) +static int lua_sr_sl_send_reply(lua_State *L) { str txt; int code; @@ -231,24 +231,22 @@ static int lua_sr_sl_send_reply (lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SL)) { LM_WARN("weird: sl function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } code = lua_tointeger(L, -2); - if(code<100 || code>=800) + if(code < 100 || code >= 800) return app_lua_return_error(L); - txt.s = (char*)lua_tostring(L, -1); - if(txt.s==NULL || env_L->msg==NULL) + txt.s = (char *)lua_tostring(L, -1); + if(txt.s == NULL || env_L->msg == NULL) return app_lua_return_error(L); txt.len = strlen(txt.s); @@ -259,7 +257,7 @@ static int lua_sr_sl_send_reply (lua_State *L) /** * */ -static int lua_sr_sl_get_reply_totag (lua_State *L) +static int lua_sr_sl_get_reply_totag(lua_State *L) { str txt; int ret; @@ -267,19 +265,16 @@ static int lua_sr_sl_get_reply_totag (lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SL)) { LM_WARN("weird: sl function executed but module not registered\n"); return app_lua_return_false(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } ret = _lua_slb.get_reply_totag(env_L->msg, &txt); - if(ret<0) - { + if(ret < 0) { LM_WARN("sl get_reply_totag returned false\n"); return app_lua_return_false(L); } @@ -290,11 +285,8 @@ static int lua_sr_sl_get_reply_totag (lua_State *L) /** * */ -static const luaL_Reg _sr_sl_Map [] = { - {"send_reply", lua_sr_sl_send_reply}, - {"get_reply_totag", lua_sr_sl_get_reply_totag}, - {NULL, NULL} -}; +static const luaL_Reg _sr_sl_Map[] = {{"send_reply", lua_sr_sl_send_reply}, + {"get_reply_totag", lua_sr_sl_get_reply_totag}, {NULL, NULL}}; /** * @@ -308,25 +300,22 @@ static int lua_sr_tm_t_reply(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } code = lua_tointeger(L, -2); - if(code<100 || code>=800) + if(code < 100 || code >= 800) return app_lua_return_error(L); - txt = (char*)lua_tostring(L, -1); - if(txt!=NULL && env_L->msg!=NULL) - { + txt = (char *)lua_tostring(L, -1); + if(txt != NULL && env_L->msg != NULL) { ret = _lua_tmb.t_reply(env_L->msg, code, txt); return app_lua_return_int(L, ret); } @@ -343,13 +332,11 @@ static int lua_sr_tm_t_relay(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -368,28 +355,24 @@ static int lua_sr_tm_t_on_failure(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - name = (char*)lua_tostring(L, -1); - if(name==NULL) - { + name = (char *)lua_tostring(L, -1); + if(name == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } i = route_get(&failure_rt, name); - if(failure_rt.rlist[i]==0) - { + if(failure_rt.rlist[i] == 0) { LM_WARN("no actions in failure_route[%s]\n", name); return app_lua_return_error(L); } @@ -409,28 +392,24 @@ static int lua_sr_tm_t_on_branch(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - name = (char*)lua_tostring(L, -1); - if(name==NULL) - { + name = (char *)lua_tostring(L, -1); + if(name == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } i = route_get(&branch_rt, name); - if(branch_rt.rlist[i]==0) - { + if(branch_rt.rlist[i] == 0) { LM_WARN("no actions in branch_route[%s]\n", name); return app_lua_return_error(L); } @@ -450,28 +429,24 @@ static int lua_sr_tm_t_on_reply(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - name = (char*)lua_tostring(L, -1); - if(name==NULL) - { + name = (char *)lua_tostring(L, -1); + if(name == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } i = route_get(&onreply_rt, name); - if(onreply_rt.rlist[i]==0) - { + if(onreply_rt.rlist[i] == 0) { LM_WARN("no actions in onreply_route[%s]\n", name); return app_lua_return_error(L); } @@ -490,13 +465,11 @@ static int lua_sr_tm_t_check_trans(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -515,13 +488,11 @@ static int lua_sr_tm_t_is_canceled(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -540,13 +511,11 @@ static int lua_sr_tm_t_newtran(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -565,13 +534,11 @@ static int lua_sr_tm_t_release(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -591,19 +558,16 @@ static int lua_sr_tm_t_replicate(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - suri.s = (char*)lua_tostring(L, -1); - if(suri.s == NULL) - { + suri.s = (char *)lua_tostring(L, -1); + if(suri.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -627,39 +591,34 @@ static int lua_sr_tm_t_on_branch_failure(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - name = (char*)lua_tostring(L, -1); - if(name==NULL) - { + name = (char *)lua_tostring(L, -1); + if(name == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } rt_name_len = strlen(BRANCH_FAILURE_ROUTE_PREFIX) + 1 + strlen(name); - if (rt_name_len > rt_name.len) - { - if ((rt_name.s = pkg_reallocxf(rt_name.s, rt_name_len+1)) == NULL) - { + if(rt_name_len > rt_name.len) { + if((rt_name.s = pkg_reallocxf(rt_name.s, rt_name_len + 1)) == NULL) { PKG_MEM_ERROR; return -1; } rt_name.len = rt_name_len; } - snprintf(rt_name.s, rt_name_len+1, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, name); + snprintf(rt_name.s, rt_name_len + 1, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, + name); i = route_get(&event_rt, rt_name.s); - if(i < 0 || event_rt.rlist[i]==0) - { + if(i < 0 || event_rt.rlist[i] == 0) { LM_WARN("no actions in branch_failure_route[%s]\n", name); return app_lua_return_error(L); } @@ -678,13 +637,11 @@ static int lua_sr_tm_t_load_contacts(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -703,13 +660,11 @@ static int lua_sr_tm_t_next_contacts(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM)) { LM_WARN("weird: tm function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -721,22 +676,18 @@ static int lua_sr_tm_t_next_contacts(lua_State *L) /** * */ -static const luaL_Reg _sr_tm_Map [] = { - {"t_reply", lua_sr_tm_t_reply}, - {"t_relay", lua_sr_tm_t_relay}, - {"t_on_failure", lua_sr_tm_t_on_failure}, - {"t_on_branch", lua_sr_tm_t_on_branch}, - {"t_on_reply", lua_sr_tm_t_on_reply}, - {"t_check_trans", lua_sr_tm_t_check_trans}, - {"t_is_canceled", lua_sr_tm_t_is_canceled}, - {"t_newtran", lua_sr_tm_t_newtran}, - {"t_release", lua_sr_tm_t_release}, - {"t_replicate", lua_sr_tm_t_replicate}, - {"t_on_branch_failure", lua_sr_tm_t_on_branch_failure}, - {"t_load_contacts", lua_sr_tm_t_load_contacts}, - {"t_next_contacts", lua_sr_tm_t_next_contacts}, - {NULL, NULL} -}; +static const luaL_Reg _sr_tm_Map[] = {{"t_reply", lua_sr_tm_t_reply}, + {"t_relay", lua_sr_tm_t_relay}, + {"t_on_failure", lua_sr_tm_t_on_failure}, + {"t_on_branch", lua_sr_tm_t_on_branch}, + {"t_on_reply", lua_sr_tm_t_on_reply}, + {"t_check_trans", lua_sr_tm_t_check_trans}, + {"t_is_canceled", lua_sr_tm_t_is_canceled}, + {"t_newtran", lua_sr_tm_t_newtran}, {"t_release", lua_sr_tm_t_release}, + {"t_replicate", lua_sr_tm_t_replicate}, + {"t_on_branch_failure", lua_sr_tm_t_on_branch_failure}, + {"t_load_contacts", lua_sr_tm_t_load_contacts}, + {"t_next_contacts", lua_sr_tm_t_next_contacts}, {NULL, NULL}}; /** @@ -749,17 +700,15 @@ static int lua_sr_sqlops_query(lua_State *L) str sres; int ret; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_error(L); } - scon.s = (char*)lua_tostring(L, -3); - squery.s = (char*)lua_tostring(L, -2); - sres.s = (char*)lua_tostring(L, -1); - if(scon.s == NULL || squery.s == NULL || sres.s == NULL) - { + scon.s = (char *)lua_tostring(L, -3); + squery.s = (char *)lua_tostring(L, -2); + sres.s = (char *)lua_tostring(L, -1); + if(scon.s == NULL || squery.s == NULL || sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -781,30 +730,26 @@ static int lua_sr_sqlops_value(lua_State *L) int row; sql_val_t *val; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -3); + sres.s = (char *)lua_tostring(L, -3); row = lua_tointeger(L, -2); col = lua_tointeger(L, -1); - if(row<0 || col<0 || sres.s==NULL) - { + if(row < 0 || col < 0 || sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } sres.len = strlen(sres.s); - if(_lua_sqlopsb.value(&sres, row, col, &val)<0) + if(_lua_sqlopsb.value(&sres, row, col, &val) < 0) return app_lua_return_false(L); - if(val->flags&PV_VAL_NULL) - { + if(val->flags & PV_VAL_NULL) { lua_pushinteger(L, 0); return 1; } - if(val->flags&PV_VAL_INT) - { + if(val->flags & PV_VAL_INT) { lua_pushinteger(L, val->value.n); return 1; } @@ -821,21 +766,19 @@ static int lua_sr_sqlops_is_null(lua_State *L) int col; int row; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -3); + sres.s = (char *)lua_tostring(L, -3); row = lua_tointeger(L, -2); col = lua_tointeger(L, -1); - if(row<0 || col<0 || sres.s==NULL) - { + if(row < 0 || col < 0 || sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } sres.len = strlen(sres.s); - if(_lua_sqlopsb.is_null(&sres, row, col)==1) + if(_lua_sqlopsb.is_null(&sres, row, col) == 1) return app_lua_return_true(L); return app_lua_return_false(L); } @@ -849,20 +792,18 @@ static int lua_sr_sqlops_column(lua_State *L) int col; str name = {0, 0}; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -2); + sres.s = (char *)lua_tostring(L, -2); col = lua_tointeger(L, -1); - if(col<0 || sres.s==NULL) - { + if(col < 0 || sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } sres.len = strlen(sres.s); - if(_lua_sqlopsb.column(&sres, col, &name)<0) + if(_lua_sqlopsb.column(&sres, col, &name) < 0) return app_lua_return_false(L); lua_pushlstring(L, name.s, name.len); return 1; @@ -876,20 +817,18 @@ static int lua_sr_sqlops_nrows(lua_State *L) str sres; int rows; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -1); - if(sres.s==NULL) - { + sres.s = (char *)lua_tostring(L, -1); + if(sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } sres.len = strlen(sres.s); rows = _lua_sqlopsb.nrows(&sres); - if(rows<0) + if(rows < 0) return app_lua_return_false(L); lua_pushinteger(L, rows); return 1; @@ -903,20 +842,18 @@ static int lua_sr_sqlops_ncols(lua_State *L) str sres; int cols; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -1); - if(sres.s==NULL) - { + sres.s = (char *)lua_tostring(L, -1); + if(sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } sres.len = strlen(sres.s); cols = _lua_sqlopsb.ncols(&sres); - if(cols<0) + if(cols < 0) return app_lua_return_false(L); lua_pushinteger(L, cols); return 1; @@ -929,14 +866,12 @@ static int lua_sr_sqlops_reset(lua_State *L) { str sres; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_false(L); } - sres.s = (char*)lua_tostring(L, -1); - if(sres.s==NULL) - { + sres.s = (char *)lua_tostring(L, -1); + if(sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_false(L); } @@ -958,23 +893,20 @@ static int lua_sr_sqlops_xquery(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS)) { LM_WARN("weird: sqlops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - scon.s = (char*)lua_tostring(L, -3); - squery.s = (char*)lua_tostring(L, -2); - sres.s = (char*)lua_tostring(L, -1); - if(scon.s == NULL || squery.s == NULL || sres.s == NULL) - { + scon.s = (char *)lua_tostring(L, -3); + squery.s = (char *)lua_tostring(L, -2); + sres.s = (char *)lua_tostring(L, -1); + if(scon.s == NULL || squery.s == NULL || sres.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -989,17 +921,11 @@ static int lua_sr_sqlops_xquery(lua_State *L) /** * */ -static const luaL_Reg _sr_sqlops_Map [] = { - {"query", lua_sr_sqlops_query}, - {"value", lua_sr_sqlops_value}, - {"is_null", lua_sr_sqlops_is_null}, - {"column", lua_sr_sqlops_column}, - {"nrows", lua_sr_sqlops_nrows}, - {"ncols", lua_sr_sqlops_ncols}, - {"reset", lua_sr_sqlops_reset}, - {"xquery", lua_sr_sqlops_xquery}, - {NULL, NULL} -}; +static const luaL_Reg _sr_sqlops_Map[] = {{"query", lua_sr_sqlops_query}, + {"value", lua_sr_sqlops_value}, {"is_null", lua_sr_sqlops_is_null}, + {"column", lua_sr_sqlops_column}, {"nrows", lua_sr_sqlops_nrows}, + {"ncols", lua_sr_sqlops_ncols}, {"reset", lua_sr_sqlops_reset}, + {"xquery", lua_sr_sqlops_xquery}, {NULL, NULL}}; /** @@ -1013,23 +939,20 @@ static int lua_sr_rr_record_route(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RR)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RR)) { LM_WARN("weird: rr function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==1) - { - sv.s = (char*)lua_tostring(L, -1); - if(sv.s!=NULL) + if(lua_gettop(L) == 1) { + sv.s = (char *)lua_tostring(L, -1); + if(sv.s != NULL) sv.len = strlen(sv.s); } - ret = _lua_rrb.record_route(env_L->msg, (sv.len>0)?&sv:NULL); + ret = _lua_rrb.record_route(env_L->msg, (sv.len > 0) ? &sv : NULL); return app_lua_return_int(L, ret); } @@ -1044,13 +967,11 @@ static int lua_sr_rr_loose_route(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RR)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RR)) { LM_WARN("weird: rr function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -1070,24 +991,21 @@ static int lua_sr_rr_add_rr_param(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RR)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RR)) { LM_WARN("weird: rr function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters\n"); return app_lua_return_error(L); } - param.s = (char*)lua_tostring(L, -1); - if(param.s!=NULL) + param.s = (char *)lua_tostring(L, -1); + if(param.s != NULL) param.len = strlen(param.s); ret = _lua_rrb.add_rr_param(env_L->msg, ¶m); @@ -1098,12 +1016,9 @@ static int lua_sr_rr_add_rr_param(lua_State *L) /** * */ -static const luaL_Reg _sr_rr_Map [] = { - {"record_route", lua_sr_rr_record_route}, - {"loose_route", lua_sr_rr_loose_route}, - {"add_rr_param", lua_sr_rr_add_rr_param}, - {NULL, NULL} -}; +static const luaL_Reg _sr_rr_Map[] = {{"record_route", lua_sr_rr_record_route}, + {"loose_route", lua_sr_rr_loose_route}, + {"add_rr_param", lua_sr_rr_add_rr_param}, {NULL, NULL}}; static int lua_sr_auth_challenge_hftype(lua_State *L, int hftype) @@ -1115,25 +1030,21 @@ static int lua_sr_auth_challenge_hftype(lua_State *L, int hftype) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH)) { LM_WARN("weird: auth function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - realm.s = (char*)lua_tostring(L, -2); - flags = lua_tointeger(L, -1); - if(flags<0 || realm.s==NULL) - { + realm.s = (char *)lua_tostring(L, -2); + flags = lua_tointeger(L, -1); + if(flags < 0 || realm.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -1165,40 +1076,36 @@ static int lua_sr_auth_proxy_challenge(lua_State *L) static int lua_sr_auth_pv_authenticate(lua_State *L, int hftype) { int ret; - str realm = {0, 0}; + str realm = {0, 0}; str passwd = {0, 0}; int flags; sr_lua_env_t *env_L; env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH)) { LM_WARN("weird: auth function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=3) - { + if(lua_gettop(L) != 3) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - realm.s = (char*)lua_tostring(L, -3); - passwd.s = (char*)lua_tostring(L, -2); - flags = lua_tointeger(L, -1); - if(flags<0 || realm.s==NULL || passwd.s==NULL) - { + realm.s = (char *)lua_tostring(L, -3); + passwd.s = (char *)lua_tostring(L, -2); + flags = lua_tointeger(L, -1); + if(flags < 0 || realm.s == NULL || passwd.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } realm.len = strlen(realm.s); passwd.len = strlen(passwd.s); - ret = _lua_authb.pv_authenticate(env_L->msg, &realm, &passwd, flags, - hftype, &env_L->msg->first_line.u.request.method); + ret = _lua_authb.pv_authenticate(env_L->msg, &realm, &passwd, flags, hftype, + &env_L->msg->first_line.u.request.method); return app_lua_return_int(L, ret); } @@ -1229,13 +1136,11 @@ static int lua_sr_auth_consume_credentials(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH)) { LM_WARN("weird: auth function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -1247,14 +1152,12 @@ static int lua_sr_auth_consume_credentials(lua_State *L) /** * */ -static const luaL_Reg _sr_auth_Map [] = { - {"www_challenge", lua_sr_auth_www_challenge}, - {"proxy_challenge", lua_sr_auth_proxy_challenge}, - {"pv_www_authenticate", lua_sr_auth_pv_www_authenticate}, - {"pv_proxy_authenticate", lua_sr_auth_pv_proxy_authenticate}, - {"consume_credentials", lua_sr_auth_consume_credentials}, - {NULL, NULL} -}; +static const luaL_Reg _sr_auth_Map[] = { + {"www_challenge", lua_sr_auth_www_challenge}, + {"proxy_challenge", lua_sr_auth_proxy_challenge}, + {"pv_www_authenticate", lua_sr_auth_pv_www_authenticate}, + {"pv_proxy_authenticate", lua_sr_auth_pv_proxy_authenticate}, + {"consume_credentials", lua_sr_auth_consume_credentials}, {NULL, NULL}}; /** @@ -1269,32 +1172,28 @@ static int lua_sr_auth_db_authenticate(lua_State *L, hdr_types_t hftype) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH_DB)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH_DB)) { LM_WARN("weird: auth function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - realm.s = (char*)lua_tostring(L, -2); - table.s = (char*)lua_tostring(L, -1); - if(realm.s==NULL || table.s==NULL) - { + realm.s = (char *)lua_tostring(L, -2); + table.s = (char *)lua_tostring(L, -1); + if(realm.s == NULL || table.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } realm.len = strlen(realm.s); table.len = strlen(table.s); - ret = _lua_auth_dbb.digest_authenticate(env_L->msg, &realm, &table, - hftype, &env_L->msg->first_line.u.request.method); + ret = _lua_auth_dbb.digest_authenticate(env_L->msg, &realm, &table, hftype, + &env_L->msg->first_line.u.request.method); return app_lua_return_int(L, ret); } @@ -1318,11 +1217,10 @@ static int lua_sr_auth_db_proxy_authenticate(lua_State *L) /** * */ -static const luaL_Reg _sr_auth_db_Map [] = { - {"www_authenticate", lua_sr_auth_db_www_authenticate}, - {"proxy_authenticate", lua_sr_auth_db_proxy_authenticate}, - {NULL, NULL} -}; +static const luaL_Reg _sr_auth_db_Map[] = { + {"www_authenticate", lua_sr_auth_db_www_authenticate}, + {"proxy_authenticate", lua_sr_auth_db_proxy_authenticate}, + {NULL, NULL}}; /** @@ -1336,24 +1234,20 @@ static int lua_sr_maxfwd_process_maxfwd(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MAXFWD)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MAXFWD)) { LM_WARN("weird: maxfwd function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } limit = lua_tointeger(L, -1); - if(limit<0) - { + if(limit < 0) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -1366,10 +1260,8 @@ static int lua_sr_maxfwd_process_maxfwd(lua_State *L) /** * */ -static const luaL_Reg _sr_maxfwd_Map [] = { - {"process_maxfwd", lua_sr_maxfwd_process_maxfwd}, - {NULL, NULL} -}; +static const luaL_Reg _sr_maxfwd_Map[] = { + {"process_maxfwd", lua_sr_maxfwd_process_maxfwd}, {NULL, NULL}}; /** @@ -1386,37 +1278,34 @@ static int lua_sr_registrar_save(lua_State *L) flags = 0; env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR)) - { - LM_WARN("weird: registrar function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR)) { + LM_WARN("weird: registrar function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==1) - { - table.s = (char*)lua_tostring(L, -1); - } else if(lua_gettop(L)==2) { - table.s = (char*)lua_tostring(L, -2); + if(lua_gettop(L) == 1) { + table.s = (char *)lua_tostring(L, -1); + } else if(lua_gettop(L) == 2) { + table.s = (char *)lua_tostring(L, -2); flags = lua_tointeger(L, -1); - } else if(lua_gettop(L)==3) { - table.s = (char*)lua_tostring(L, -3); + } else if(lua_gettop(L) == 3) { + table.s = (char *)lua_tostring(L, -3); flags = lua_tointeger(L, -2); - uri.s = (char*)lua_tostring(L, -1); + uri.s = (char *)lua_tostring(L, -1); uri.len = strlen(uri.s); } else { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - if(table.s==NULL || (table.len=strlen(table.s))==0) - { + if(table.s == NULL || (table.len = strlen(table.s)) == 0) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } - if (lua_gettop(L)==3) { + if(lua_gettop(L) == 3) { ret = _lua_registrarb.save_uri(env_L->msg, &table, flags, &uri); } else { ret = _lua_registrarb.save(env_L->msg, &table, flags); @@ -1437,37 +1326,30 @@ static int lua_sr_registrar_lookup(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR)) - { - LM_WARN("weird: registrar function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR)) { + LM_WARN("weird: registrar function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==1) - { - table.s = (char*)lua_tostring(L, -1); - } - else if (lua_gettop(L)==2) - { - table.s = (char*)lua_tostring(L, -2); - uri.s = (char*)lua_tostring(L, -1); + if(lua_gettop(L) == 1) { + table.s = (char *)lua_tostring(L, -1); + } else if(lua_gettop(L) == 2) { + table.s = (char *)lua_tostring(L, -2); + uri.s = (char *)lua_tostring(L, -1); uri.len = strlen(uri.s); - } else - { + } else { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - if(table.s==NULL || (table.len=strlen(table.s))==0) - { + if(table.s == NULL || (table.len = strlen(table.s)) == 0) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==2) - { + if(lua_gettop(L) == 2) { ret = _lua_registrarb.lookup_uri(env_L->msg, &table, &uri); } else { ret = _lua_registrarb.lookup(env_L->msg, &table); @@ -1488,37 +1370,30 @@ static int lua_sr_registrar_lookup_to_dset(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR)) - { - LM_WARN("weird: registrar function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR)) { + LM_WARN("weird: registrar function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==1) - { - table.s = (char*)lua_tostring(L, -1); - } - else if (lua_gettop(L)==2) - { - table.s = (char*)lua_tostring(L, -2); - uri.s = (char*)lua_tostring(L, -1); + if(lua_gettop(L) == 1) { + table.s = (char *)lua_tostring(L, -1); + } else if(lua_gettop(L) == 2) { + table.s = (char *)lua_tostring(L, -2); + uri.s = (char *)lua_tostring(L, -1); uri.len = strlen(uri.s); - } else - { + } else { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - if(table.s==NULL || (table.len=strlen(table.s))==0) - { + if(table.s == NULL || (table.len = strlen(table.s)) == 0) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==2) - { + if(lua_gettop(L) == 2) { ret = _lua_registrarb.lookup_to_dset(env_L->msg, &table, &uri); } else { ret = _lua_registrarb.lookup_to_dset(env_L->msg, &table, NULL); @@ -1538,24 +1413,21 @@ static int lua_sr_registrar_registered(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR)) - { - LM_WARN("weird: registrar function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR)) { + LM_WARN("weird: registrar function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - table.s = (char*)lua_tostring(L, -1); - if(table.s==NULL || (table.len=strlen(table.s))==0) - { + table.s = (char *)lua_tostring(L, -1); + if(table.s == NULL || (table.len = strlen(table.s)) == 0) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -1568,13 +1440,10 @@ static int lua_sr_registrar_registered(lua_State *L) /** * */ -static const luaL_Reg _sr_registrar_Map [] = { - {"save", lua_sr_registrar_save}, - {"lookup", lua_sr_registrar_lookup}, - {"lookup_to_dset",lua_sr_registrar_lookup_to_dset}, - {"registered",lua_sr_registrar_registered}, - {NULL, NULL} -}; +static const luaL_Reg _sr_registrar_Map[] = {{"save", lua_sr_registrar_save}, + {"lookup", lua_sr_registrar_lookup}, + {"lookup_to_dset", lua_sr_registrar_lookup_to_dset}, + {"registered", lua_sr_registrar_registered}, {NULL, NULL}}; /** @@ -1590,26 +1459,23 @@ static int lua_sr_dispatcher_select(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER)) { LM_WARN("weird: dispatcher function executed but module" " not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==3) - { + if(lua_gettop(L) == 3) { setid = lua_tointeger(L, -3); algid = lua_tointeger(L, -2); - mode = lua_tointeger(L, -1); - } else if(lua_gettop(L)==2) { + mode = lua_tointeger(L, -1); + } else if(lua_gettop(L) == 2) { setid = lua_tointeger(L, -2); algid = lua_tointeger(L, -1); - mode = 0; + mode = 0; } else { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); @@ -1630,22 +1496,19 @@ static int lua_sr_dispatcher_next(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER)) { LM_WARN("weird: dispatcher function executed but module" " not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } mode = 0; - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { /* mode given as parameter */ - mode = lua_tointeger(L, -1); + mode = lua_tointeger(L, -1); } ret = _lua_dispatcherb.next(env_L->msg, mode); @@ -1663,22 +1526,19 @@ static int lua_sr_dispatcher_mark(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER)) { LM_WARN("weird: dispatcher function executed but module" " not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } mode = 0; - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { /* mode given as parameter */ - mode = lua_tointeger(L, -1); + mode = lua_tointeger(L, -1); } ret = _lua_dispatcherb.mark(env_L->msg, mode); @@ -1696,22 +1556,19 @@ static int lua_sr_dispatcher_is_from(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER)) { LM_WARN("weird: dispatcher function executed but module" " not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } mode = -1; - if(lua_gettop(L)==1) - { + if(lua_gettop(L) == 1) { /* mode given as parameter */ - mode = lua_tointeger(L, -1); + mode = lua_tointeger(L, -1); } ret = _lua_dispatcherb.is_from(env_L->msg, mode); @@ -1721,13 +1578,10 @@ static int lua_sr_dispatcher_is_from(lua_State *L) /** * */ -static const luaL_Reg _sr_dispatcher_Map [] = { - {"select", lua_sr_dispatcher_select}, - {"next", lua_sr_dispatcher_next}, - {"mark", lua_sr_dispatcher_mark}, - {"is_from", lua_sr_dispatcher_is_from}, - {NULL, NULL} -}; +static const luaL_Reg _sr_dispatcher_Map[] = { + {"select", lua_sr_dispatcher_select}, {"next", lua_sr_dispatcher_next}, + {"mark", lua_sr_dispatcher_mark}, + {"is_from", lua_sr_dispatcher_is_from}, {NULL, NULL}}; /** @@ -1744,23 +1598,20 @@ static int lua_sr_xhttp_reply(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_XHTTP)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_XHTTP)) { LM_WARN("weird: xhttp function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } rcode = lua_tointeger(L, -4); - reason.s = (char*)lua_tostring(L, -3); - ctype.s = (char*)lua_tostring(L, -2); - mbody.s = (char*)lua_tostring(L, -1); - if(reason.s == NULL || ctype.s == NULL || mbody.s == NULL) - { + reason.s = (char *)lua_tostring(L, -3); + ctype.s = (char *)lua_tostring(L, -2); + mbody.s = (char *)lua_tostring(L, -1); + if(reason.s == NULL || ctype.s == NULL || mbody.s == NULL) { LM_WARN("invalid parameters from Lua\n"); return app_lua_return_error(L); } @@ -1776,10 +1627,8 @@ static int lua_sr_xhttp_reply(lua_State *L) /** * */ -static const luaL_Reg _sr_xhttp_Map [] = { - {"reply", lua_sr_xhttp_reply}, - {NULL, NULL} -}; +static const luaL_Reg _sr_xhttp_Map[] = { + {"reply", lua_sr_xhttp_reply}, {NULL, NULL}}; /** * @@ -1792,25 +1641,22 @@ static int lua_sr_sdpops_with_media(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - media.s = (char*)lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); ret = _lua_sdpopsb.sdp_with_media(env_L->msg, &media); @@ -1829,25 +1675,22 @@ static int lua_sr_sdpops_with_active_media(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - media.s = (char*)lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); ret = _lua_sdpopsb.sdp_with_active_media(env_L->msg, &media); @@ -1866,25 +1709,22 @@ static int lua_sr_sdpops_with_transport(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - transport.s = (char*)lua_tostring(L, -1); + transport.s = (char *)lua_tostring(L, -1); transport.len = strlen(transport.s); ret = _lua_sdpopsb.sdp_with_transport(env_L->msg, &transport, 0); @@ -1903,25 +1743,22 @@ static int lua_sr_sdpops_with_codecs_by_id(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -1); + codecs.s = (char *)lua_tostring(L, -1); codecs.len = strlen(codecs.s); ret = _lua_sdpopsb.sdp_with_codecs_by_id(env_L->msg, &codecs); @@ -1940,25 +1777,22 @@ static int lua_sr_sdpops_with_codecs_by_name(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -1); + codecs.s = (char *)lua_tostring(L, -1); codecs.len = strlen(codecs.s); ret = _lua_sdpopsb.sdp_with_codecs_by_name(env_L->msg, &codecs); @@ -1976,20 +1810,17 @@ static int lua_sr_sdpops_with_ice(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=0) - { + if(lua_gettop(L) != 0) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2011,28 +1842,25 @@ static int lua_sr_sdpops_keep_codecs_by_id(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -2); + codecs.s = (char *)lua_tostring(L, -2); codecs.len = strlen(codecs.s); - media.s = (char*)lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); ret = _lua_sdpopsb.sdp_keep_codecs_by_id(env_L->msg, &codecs, &media); @@ -2052,28 +1880,25 @@ static int lua_sr_sdpops_keep_codecs_by_name(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -2); + codecs.s = (char *)lua_tostring(L, -2); codecs.len = strlen(codecs.s); - media.s = (char*)lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); ret = _lua_sdpopsb.sdp_keep_codecs_by_name(env_L->msg, &codecs, &media); @@ -2092,25 +1917,22 @@ static int lua_sr_sdpops_remove_media(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - media.s = (char*)lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); ret = _lua_sdpopsb.sdp_remove_media(env_L->msg, &media); @@ -2129,25 +1951,22 @@ static int lua_sr_sdpops_remove_transport(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - transport.s = (char*)lua_tostring(L, -1); + transport.s = (char *)lua_tostring(L, -1); transport.len = strlen(transport.s); ret = _lua_sdpopsb.sdp_remove_transport(env_L->msg, &transport); @@ -2167,27 +1986,23 @@ static int lua_sr_sdpops_remove_line_by_prefix(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==1) - { - prefix.s = (char *) lua_tostring(L, -1); + if(lua_gettop(L) == 1) { + prefix.s = (char *)lua_tostring(L, -1); prefix.len = strlen(prefix.s); - } else if(lua_gettop(L)==2) - { - prefix.s = (char *) lua_tostring(L, -2); + } else if(lua_gettop(L) == 2) { + prefix.s = (char *)lua_tostring(L, -2); prefix.len = strlen(prefix.s); - media.s = (char *) lua_tostring(L, -1); + media.s = (char *)lua_tostring(L, -1); media.len = strlen(media.s); } else { LM_ERR("incorrect number of arguments\n"); @@ -2210,25 +2025,22 @@ static int lua_sr_sdpops_remove_codecs_by_id(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -1); + codecs.s = (char *)lua_tostring(L, -1); codecs.len = strlen(codecs.s); ret = _lua_sdpopsb.sdp_remove_codecs_by_id(env_L->msg, &codecs, NULL); @@ -2247,25 +2059,22 @@ static int lua_sr_sdpops_remove_codecs_by_name(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS)) { LM_WARN("weird: sdpops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - codecs.s = (char*)lua_tostring(L, -1); + codecs.s = (char *)lua_tostring(L, -1); codecs.len = strlen(codecs.s); ret = _lua_sdpopsb.sdp_remove_codecs_by_name(env_L->msg, &codecs, NULL); @@ -2276,22 +2085,21 @@ static int lua_sr_sdpops_remove_codecs_by_name(lua_State *L) /** * */ -static const luaL_Reg _sr_sdpops_Map [] = { - {"sdp_with_media", lua_sr_sdpops_with_media}, - {"sdp_with_active_media", lua_sr_sdpops_with_active_media}, - {"sdp_with_transport", lua_sr_sdpops_with_transport}, - {"sdp_with_codecs_by_id", lua_sr_sdpops_with_codecs_by_id}, - {"sdp_with_codecs_by_name", lua_sr_sdpops_with_codecs_by_name}, - {"sdp_with_ice", lua_sr_sdpops_with_ice}, - {"sdp_keep_codecs_by_id", lua_sr_sdpops_keep_codecs_by_id}, - {"sdp_keep_codecs_by_name", lua_sr_sdpops_keep_codecs_by_name}, - {"sdp_remove_media", lua_sr_sdpops_remove_media}, - {"sdp_remove_transport", lua_sr_sdpops_remove_transport}, - {"sdp_remove_line_by_prefix", lua_sr_sdpops_remove_line_by_prefix}, - {"sdp_remove_codecs_by_id", lua_sr_sdpops_remove_codecs_by_id}, - {"sdp_remove_codecs_by_name", lua_sr_sdpops_remove_codecs_by_name}, - {NULL, NULL} -}; +static const luaL_Reg _sr_sdpops_Map[] = { + {"sdp_with_media", lua_sr_sdpops_with_media}, + {"sdp_with_active_media", lua_sr_sdpops_with_active_media}, + {"sdp_with_transport", lua_sr_sdpops_with_transport}, + {"sdp_with_codecs_by_id", lua_sr_sdpops_with_codecs_by_id}, + {"sdp_with_codecs_by_name", lua_sr_sdpops_with_codecs_by_name}, + {"sdp_with_ice", lua_sr_sdpops_with_ice}, + {"sdp_keep_codecs_by_id", lua_sr_sdpops_keep_codecs_by_id}, + {"sdp_keep_codecs_by_name", lua_sr_sdpops_keep_codecs_by_name}, + {"sdp_remove_media", lua_sr_sdpops_remove_media}, + {"sdp_remove_transport", lua_sr_sdpops_remove_transport}, + {"sdp_remove_line_by_prefix", lua_sr_sdpops_remove_line_by_prefix}, + {"sdp_remove_codecs_by_id", lua_sr_sdpops_remove_codecs_by_id}, + {"sdp_remove_codecs_by_name", lua_sr_sdpops_remove_codecs_by_name}, + {NULL, NULL}}; /** * @@ -2304,27 +2112,25 @@ static int lua_sr_pres_auth_status(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE)) - { - LM_WARN("weird: presence function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE)) { + LM_WARN("weird: presence function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -2); + param[0].s = (char *)lua_tostring(L, -2); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -1); + param[1].s = (char *)lua_tostring(L, -1); param[1].len = strlen(param[1].s); ret = _lua_presenceb.pres_auth_status(env_L->msg, param[0], param[1]); @@ -2341,20 +2147,18 @@ static int lua_sr_pres_handle_publish(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE)) - { - LM_WARN("weird: presence function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE)) { + LM_WARN("weird: presence function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=0) - { + if(lua_gettop(L) != 0) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2373,36 +2177,32 @@ static int lua_sr_pres_handle_subscribe(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE)) - { - LM_WARN("weird: presence function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE)) { + LM_WARN("weird: presence function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==0) + if(lua_gettop(L) == 0) ret = _lua_presenceb.handle_subscribe0(env_L->msg); - else if (lua_gettop(L)==1) - { + else if(lua_gettop(L) == 1) { str wuri; struct sip_uri parsed_wuri; - wuri.s = (char *) lua_tostring(L, -1); + wuri.s = (char *)lua_tostring(L, -1); wuri.len = strlen(wuri.s); - if (parse_uri(wuri.s, wuri.len, &parsed_wuri)) - { + if(parse_uri(wuri.s, wuri.len, &parsed_wuri)) { LM_ERR("failed to parse watcher URI\n"); return app_lua_return_error(L); } - ret = _lua_presenceb.handle_subscribe(env_L->msg, parsed_wuri.user, parsed_wuri.host); - } - else - { + ret = _lua_presenceb.handle_subscribe( + env_L->msg, parsed_wuri.user, parsed_wuri.host); + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2413,12 +2213,10 @@ static int lua_sr_pres_handle_subscribe(lua_State *L) /** * */ -static const luaL_Reg _sr_presence_Map [] = { - {"pres_auth_status", lua_sr_pres_auth_status}, - {"handle_publish", lua_sr_pres_handle_publish}, - {"handle_subscribe", lua_sr_pres_handle_subscribe}, - {NULL, NULL} -}; +static const luaL_Reg _sr_presence_Map[] = { + {"pres_auth_status", lua_sr_pres_auth_status}, + {"handle_publish", lua_sr_pres_handle_publish}, + {"handle_subscribe", lua_sr_pres_handle_subscribe}, {NULL, NULL}}; /** * @@ -2431,27 +2229,25 @@ static int lua_sr_pres_check_basic(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE_XML)) - { - LM_WARN("weird: presence_xml function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE_XML)) { + LM_WARN("weird: presence_xml function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -2); + param[0].s = (char *)lua_tostring(L, -2); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -1); + param[1].s = (char *)lua_tostring(L, -1); param[1].len = strlen(param[1].s); ret = _lua_presence_xmlb.pres_check_basic(env_L->msg, param[0], param[1]); @@ -2469,41 +2265,38 @@ static int lua_sr_pres_check_activities(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE_XML)) - { - LM_WARN("weird: presence_xml function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE_XML)) { + LM_WARN("weird: presence_xml function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=2) - { + if(lua_gettop(L) != 2) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -2); + param[0].s = (char *)lua_tostring(L, -2); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -1); + param[1].s = (char *)lua_tostring(L, -1); param[1].len = strlen(param[1].s); - ret = _lua_presence_xmlb.pres_check_activities(env_L->msg, param[0], param[1]); + ret = _lua_presence_xmlb.pres_check_activities( + env_L->msg, param[0], param[1]); return app_lua_return_int(L, ret); } /** * */ -static const luaL_Reg _sr_presence_xml_Map [] = { - {"pres_check_basic", lua_sr_pres_check_basic}, - {"pres_check_activities", lua_sr_pres_check_activities}, - {NULL, NULL} -}; +static const luaL_Reg _sr_presence_xml_Map[] = { + {"pres_check_basic", lua_sr_pres_check_basic}, + {"pres_check_activities", lua_sr_pres_check_activities}, {NULL, NULL}}; /** * @@ -2516,25 +2309,22 @@ static int lua_sr_textops_is_privacy(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TEXTOPS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TEXTOPS)) { LM_WARN("weird: textops function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -1); + param[0].s = (char *)lua_tostring(L, -1); param[0].len = strlen(param[0].s); ret = _lua_textopsb.is_privacy(env_L->msg, ¶m[0]); @@ -2544,10 +2334,8 @@ static int lua_sr_textops_is_privacy(lua_State *L) /** * */ -static const luaL_Reg _sr_textops_Map [] = { - {"is_privacy", lua_sr_textops_is_privacy}, - {NULL, NULL} -}; +static const luaL_Reg _sr_textops_Map[] = { + {"is_privacy", lua_sr_textops_is_privacy}, {NULL, NULL}}; /** * @@ -2559,20 +2347,18 @@ static int lua_sr_pua_usrloc_set_publish(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PUA_USRLOC)) - { - LM_WARN("weird: pua_usrloc function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PUA_USRLOC)) { + LM_WARN("weird: pua_usrloc function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=0) - { + if(lua_gettop(L) != 0) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2584,10 +2370,8 @@ static int lua_sr_pua_usrloc_set_publish(lua_State *L) /** * */ -static const luaL_Reg _sr_pua_usrloc_Map [] = { - {"set_publish", lua_sr_pua_usrloc_set_publish}, - {NULL, NULL} -}; +static const luaL_Reg _sr_pua_usrloc_Map[] = { + {"set_publish", lua_sr_pua_usrloc_set_publish}, {NULL, NULL}}; /** * @@ -2599,20 +2383,18 @@ static int lua_sr_siputils_has_totag(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SIPUTILS)) - { - LM_WARN("weird: siputils function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SIPUTILS)) { + LM_WARN("weird: siputils function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=0) - { + if(lua_gettop(L) != 0) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2632,29 +2414,27 @@ static int lua_sr_siputils_is_uri_user_e164(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SIPUTILS)) - { - LM_WARN("weird: siputils function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SIPUTILS)) { + LM_WARN("weird: siputils function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -1); + param[0].s = (char *)lua_tostring(L, -1); param[0].len = strlen(param[0].s); ret = _lua_siputilsb.is_uri_user_e164(¶m[0]); - if (ret < 0) + if(ret < 0) return app_lua_return_false(L); return app_lua_return_true(L); @@ -2663,11 +2443,9 @@ static int lua_sr_siputils_is_uri_user_e164(lua_State *L) /** * */ -static const luaL_Reg _sr_siputils_Map [] = { - {"has_totag", lua_sr_siputils_has_totag}, - {"is_uri_user_e164", lua_sr_siputils_is_uri_user_e164}, - {NULL, NULL} -}; +static const luaL_Reg _sr_siputils_Map[] = { + {"has_totag", lua_sr_siputils_has_totag}, + {"is_uri_user_e164", lua_sr_siputils_is_uri_user_e164}, {NULL, NULL}}; /** * @@ -2679,36 +2457,31 @@ static int lua_sr_rls_handle_subscribe(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RLS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RLS)) { LM_WARN("weird: rls function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)==0) + if(lua_gettop(L) == 0) ret = _lua_rlsb.rls_handle_subscribe0(env_L->msg); - else if (lua_gettop(L)==1) - { + else if(lua_gettop(L) == 1) { str wuri; struct sip_uri parsed_wuri; - wuri.s = (char *) lua_tostring(L, -1); + wuri.s = (char *)lua_tostring(L, -1); wuri.len = strlen(wuri.s); - if (parse_uri(wuri.s, wuri.len, &parsed_wuri)) - { + if(parse_uri(wuri.s, wuri.len, &parsed_wuri)) { LM_ERR("failed to parse watcher URI\n"); return app_lua_return_error(L); } - ret = _lua_rlsb.rls_handle_subscribe(env_L->msg, parsed_wuri.user, parsed_wuri.host); - } - else - { + ret = _lua_rlsb.rls_handle_subscribe( + env_L->msg, parsed_wuri.user, parsed_wuri.host); + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2726,20 +2499,17 @@ static int lua_sr_rls_handle_notify(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RLS)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RLS)) { LM_WARN("weird: rls function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=0) - { + if(lua_gettop(L) != 0) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2751,11 +2521,9 @@ static int lua_sr_rls_handle_notify(lua_State *L) /** * */ -static const luaL_Reg _sr_rls_Map [] = { - {"handle_subscribe", lua_sr_rls_handle_subscribe}, - {"handle_notify", lua_sr_rls_handle_notify}, - {NULL, NULL} -}; +static const luaL_Reg _sr_rls_Map[] = { + {"handle_subscribe", lua_sr_rls_handle_subscribe}, + {"handle_notify", lua_sr_rls_handle_notify}, {NULL, NULL}}; /** * @@ -2768,25 +2536,23 @@ static int lua_sr_alias_db_lookup(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_ALIAS_DB)) - { - LM_WARN("weird: alias_db function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_ALIAS_DB)) { + LM_WARN("weird: alias_db function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -1); + param[0].s = (char *)lua_tostring(L, -1); param[0].len = strlen(param[0].s); ret = _lua_alias_dbb.alias_db_lookup(env_L->msg, param[0]); @@ -2796,10 +2562,8 @@ static int lua_sr_alias_db_lookup(lua_State *L) /** * */ -static const luaL_Reg _sr_alias_db_Map [] = { - {"lookup", lua_sr_alias_db_lookup}, - {NULL, NULL} -}; +static const luaL_Reg _sr_alias_db_Map[] = { + {"lookup", lua_sr_alias_db_lookup}, {NULL, NULL}}; /** * @@ -2811,35 +2575,27 @@ static int lua_sr_msilo_store(lua_State *L) env_L = _app_lua_api.env_get_f(); - if (!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO)) { LM_WARN("weird: msilo function executed but module not registered\n"); return app_lua_return_error(L); } - if (env_L->msg == NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if (lua_gettop(L) == 0) - { + if(lua_gettop(L) == 0) { ret = _lua_msilob.m_store(env_L->msg, NULL); - } - else if (lua_gettop(L) == 1) - { + } else if(lua_gettop(L) == 1) { str owner; - owner.s = (char*)lua_tostring(L, -1); - if (owner.s == NULL) - { + owner.s = (char *)lua_tostring(L, -1); + if(owner.s == NULL) { return app_lua_return_error(L); } owner.len = strlen(owner.s); ret = _lua_msilob.m_store(env_L->msg, &owner); - } - else - { + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2857,35 +2613,27 @@ static int lua_sr_msilo_dump(lua_State *L) env_L = _app_lua_api.env_get_f(); - if (!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO)) { LM_WARN("weird: msilo function executed but module not registered\n"); return app_lua_return_error(L); } - if (env_L->msg == NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if (lua_gettop(L) == 0) - { + if(lua_gettop(L) == 0) { ret = _lua_msilob.m_dump(env_L->msg, NULL); - } - else if (lua_gettop(L) == 1) - { + } else if(lua_gettop(L) == 1) { str owner; - owner.s = (char*)lua_tostring(L, -1); - if (owner.s == NULL) - { + owner.s = (char *)lua_tostring(L, -1); + if(owner.s == NULL) { return app_lua_return_error(L); } owner.len = strlen(owner.s); ret = _lua_msilob.m_dump(env_L->msg, &owner); - } - else - { + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } @@ -2896,11 +2644,8 @@ static int lua_sr_msilo_dump(lua_State *L) /** * */ -static const luaL_Reg _sr_msilo_Map [] = { - {"store", lua_sr_msilo_store}, - {"dump", lua_sr_msilo_dump}, - {NULL, NULL} -}; +static const luaL_Reg _sr_msilo_Map[] = {{"store", lua_sr_msilo_store}, + {"dump", lua_sr_msilo_dump}, {NULL, NULL}}; /** * @@ -2913,40 +2658,33 @@ static int lua_sr_uac_replace_x(lua_State *L, int htype) env_L = _app_lua_api.env_get_f(); - if (!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC)) { LM_WARN("weird:uac function executed but module not registered\n"); return app_lua_return_error(L); } - if (env_L->msg == NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } - if (lua_gettop(L) == 1) - { + if(lua_gettop(L) == 1) { param[0].s = ""; param[0].len = 0; - param[1].s = (char *) lua_tostring(L, -1); + param[1].s = (char *)lua_tostring(L, -1); param[1].len = strlen(param[1].s); - } - else if (lua_gettop(L) == 2) - { - param[0].s = (char *) lua_tostring(L, -2); + } else if(lua_gettop(L) == 2) { + param[0].s = (char *)lua_tostring(L, -2); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -1); + param[1].s = (char *)lua_tostring(L, -1); param[1].len = strlen(param[1].s); - } - else - { + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - if(htype==1) { + if(htype == 1) { ret = _lua_uacb.replace_to(env_L->msg, ¶m[0], ¶m[1]); } else { ret = _lua_uacb.replace_from(env_L->msg, ¶m[0], ¶m[1]); @@ -2980,14 +2718,12 @@ static int lua_sr_uac_req_send(lua_State *L) env_L = _app_lua_api.env_get_f(); - if (!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC)) { LM_WARN("weird:uac function executed but module not registered\n"); return app_lua_return_error(L); } - if (env_L->msg == NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -3000,12 +2736,10 @@ static int lua_sr_uac_req_send(lua_State *L) /** * */ -static const luaL_Reg _sr_uac_Map [] = { - {"replace_from",lua_sr_uac_replace_from}, - {"replace_to",lua_sr_uac_replace_to}, - {"uac_req_send",lua_sr_uac_req_send}, - {NULL, NULL} -}; +static const luaL_Reg _sr_uac_Map[] = { + {"replace_from", lua_sr_uac_replace_from}, + {"replace_to", lua_sr_uac_replace_to}, + {"uac_req_send", lua_sr_uac_req_send}, {NULL, NULL}}; /** @@ -3019,14 +2753,12 @@ static int lua_sr_sanity_check(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SANITY)) { LM_WARN("weird: sanity function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -3041,10 +2773,8 @@ static int lua_sr_sanity_check(lua_State *L) /** * */ -static const luaL_Reg _sr_sanity_Map [] = { - {"sanity_check", lua_sr_sanity_check}, - {NULL, NULL} -}; +static const luaL_Reg _sr_sanity_Map[] = { + {"sanity_check", lua_sr_sanity_check}, {NULL, NULL}}; /** @@ -3055,17 +2785,16 @@ static int lua_sr_cfgutils_lock(lua_State *L) int ret; str lkey; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS)) - { - LM_WARN("weird: cfgutils function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS)) { + LM_WARN("weird: cfgutils function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - lkey.s = (char*)lua_tostring(L, -1); + lkey.s = (char *)lua_tostring(L, -1); lkey.len = strlen(lkey.s); ret = _lua_cfgutilsb.mlock(&lkey); @@ -3081,17 +2810,16 @@ static int lua_sr_cfgutils_unlock(lua_State *L) int ret; str lkey; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS)) - { - LM_WARN("weird: cfgutils function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS)) { + LM_WARN("weird: cfgutils function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - lkey.s = (char*)lua_tostring(L, -1); + lkey.s = (char *)lua_tostring(L, -1); lkey.len = strlen(lkey.s); ret = _lua_cfgutilsb.munlock(&lkey); @@ -3102,11 +2830,8 @@ static int lua_sr_cfgutils_unlock(lua_State *L) /** * */ -static const luaL_Reg _sr_cfgutils_Map [] = { - {"lock", lua_sr_cfgutils_lock}, - {"unlock", lua_sr_cfgutils_unlock}, - {NULL, NULL} -}; +static const luaL_Reg _sr_cfgutils_Map[] = {{"lock", lua_sr_cfgutils_lock}, + {"unlock", lua_sr_cfgutils_unlock}, {NULL, NULL}}; /** * @@ -3118,13 +2843,11 @@ static int lua_sr_tmx_t_suspend(lua_State *L) env_L = _app_lua_api.env_get_f(); - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TMX)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TMX)) { LM_WARN("weird: tmx function executed but module not registered\n"); return app_lua_return_error(L); } - if(env_L->msg==NULL) - { + if(env_L->msg == NULL) { LM_WARN("invalid parameters from Lua env\n"); return app_lua_return_error(L); } @@ -3136,10 +2859,8 @@ static int lua_sr_tmx_t_suspend(lua_State *L) /** * */ -static const luaL_Reg _sr_tmx_Map [] = { - {"t_suspend", lua_sr_tmx_t_suspend}, - {NULL, NULL} -}; +static const luaL_Reg _sr_tmx_Map[] = { + {"t_suspend", lua_sr_tmx_t_suspend}, {NULL, NULL}}; /** * @@ -3149,22 +2870,20 @@ static int lua_sr_mq_add(lua_State *L) int ret; str param[3]; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MQUEUE)) - { + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MQUEUE)) { LM_WARN("weird: mqueue function executed but module not registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=3) - { + if(lua_gettop(L) != 3) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -3); + param[0].s = (char *)lua_tostring(L, -3); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -2); + param[1].s = (char *)lua_tostring(L, -2); param[1].len = strlen(param[1].s); - param[2].s = (char *) lua_tostring(L, -1); + param[2].s = (char *)lua_tostring(L, -1); param[2].len = strlen(param[2].s); ret = _lua_mqb.add(¶m[0], ¶m[1], ¶m[2]); @@ -3174,10 +2893,7 @@ static int lua_sr_mq_add(lua_State *L) /** * */ -static const luaL_Reg _sr_mqueue_Map [] = { - {"add", lua_sr_mq_add}, - {NULL, NULL} -}; +static const luaL_Reg _sr_mqueue_Map[] = {{"add", lua_sr_mq_add}, {NULL, NULL}}; /** * @@ -3187,36 +2903,39 @@ static int lua_sr_ndb_mongodb_cmd_x(lua_State *L, int ctype) int ret = 0; str param[6]; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB)) - { - LM_WARN("weird: ndb_mongodb function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_NDB_MONGODB)) { + LM_WARN("weird: ndb_mongodb function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=5) - { + if(lua_gettop(L) != 5) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -5); + param[0].s = (char *)lua_tostring(L, -5); param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -4); + param[1].s = (char *)lua_tostring(L, -4); param[1].len = strlen(param[1].s); - param[2].s = (char *) lua_tostring(L, -3); + param[2].s = (char *)lua_tostring(L, -3); param[2].len = strlen(param[2].s); - param[3].s = (char *) lua_tostring(L, -2); + param[3].s = (char *)lua_tostring(L, -2); param[3].len = strlen(param[3].s); - param[4].s = (char *) lua_tostring(L, -1); + param[4].s = (char *)lua_tostring(L, -1); param[4].len = strlen(param[4].s); - if(ctype==1) { - ret = _lua_ndb_mongodbb.cmd_simple(¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); - } else if(ctype==2) { - ret = _lua_ndb_mongodbb.find(¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); - } else if(ctype==3) { - ret = _lua_ndb_mongodbb.find_one(¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); + if(ctype == 1) { + ret = _lua_ndb_mongodbb.cmd_simple( + ¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); + } else if(ctype == 2) { + ret = _lua_ndb_mongodbb.find( + ¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); + } else if(ctype == 3) { + ret = _lua_ndb_mongodbb.find_one( + ¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); } else { - ret = _lua_ndb_mongodbb.cmd(¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); + ret = _lua_ndb_mongodbb.cmd( + ¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4]); } return app_lua_return_int(L, ret); } @@ -3261,18 +2980,17 @@ static int lua_sr_ndb_mongodb_next_reply(lua_State *L) int ret = 0; str param[1]; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB)) - { - LM_WARN("weird: ndb_mongodb function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_NDB_MONGODB)) { + LM_WARN("weird: ndb_mongodb function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -1); + param[0].s = (char *)lua_tostring(L, -1); param[0].len = strlen(param[0].s); ret = _lua_ndb_mongodbb.next_reply(¶m[0]); @@ -3288,18 +3006,17 @@ static int lua_sr_ndb_mongodb_free_reply(lua_State *L) int ret = 0; str param[1]; - if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB)) - { - LM_WARN("weird: ndb_mongodb function executed but module not registered\n"); + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_NDB_MONGODB)) { + LM_WARN("weird: ndb_mongodb function executed but module not " + "registered\n"); return app_lua_return_error(L); } - if(lua_gettop(L)!=1) - { + if(lua_gettop(L) != 1) { LM_WARN("invalid number of parameters from Lua\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -1); + param[0].s = (char *)lua_tostring(L, -1); param[0].len = strlen(param[0].s); ret = _lua_ndb_mongodbb.free_reply(¶m[0]); @@ -3310,272 +3027,219 @@ static int lua_sr_ndb_mongodb_free_reply(lua_State *L) /** * */ -static const luaL_Reg _sr_ndb_mongodb_Map [] = { - {"cmd", lua_sr_ndb_mongodb_cmd}, - {"cmd_simple", lua_sr_ndb_mongodb_cmd_simple}, - {"find", lua_sr_ndb_mongodb_find}, - {"find_one", lua_sr_ndb_mongodb_find_one}, - {"next_reply", lua_sr_ndb_mongodb_next_reply}, - {"free_reply", lua_sr_ndb_mongodb_free_reply}, - {NULL, NULL} -}; +static const luaL_Reg _sr_ndb_mongodb_Map[] = {{"cmd", lua_sr_ndb_mongodb_cmd}, + {"cmd_simple", lua_sr_ndb_mongodb_cmd_simple}, + {"find", lua_sr_ndb_mongodb_find}, + {"find_one", lua_sr_ndb_mongodb_find_one}, + {"next_reply", lua_sr_ndb_mongodb_next_reply}, + {"free_reply", lua_sr_ndb_mongodb_free_reply}, {NULL, NULL}}; /** * */ int lua_sr_exp_init_mod(void) { - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SL) { /* bind the SL API */ - if (sl_load_api(&_lua_slb) < 0) { + if(sl_load_api(&_lua_slb) < 0) { LM_ERR("cannot bind to SL API\n"); return -1; } LM_DBG("loaded sl api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM) { /* bind the TM API */ - if (tm_load_api(&_lua_tmb) < 0) - { + if(tm_load_api(&_lua_tmb) < 0) { LM_ERR("cannot bind to TM API\n"); return -1; } LM_DBG("loaded tm api\n"); /* bind the TM XAPI */ - if (tm_load_xapi(&_lua_xtmb) < 0) - { + if(tm_load_xapi(&_lua_xtmb) < 0) { LM_ERR("cannot bind to TM XAPI\n"); return -1; } LM_DBG("loaded tm xapi\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS) { /* bind the SQLOPS API */ - if (sqlops_load_api(&_lua_sqlopsb) < 0) - { + if(sqlops_load_api(&_lua_sqlopsb) < 0) { LM_ERR("cannot bind to SQLOPS API\n"); return -1; } LM_DBG("loaded sqlops api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RR) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RR) { /* bind the RR API */ - if (rr_load_api(&_lua_rrb) < 0) - { + if(rr_load_api(&_lua_rrb) < 0) { LM_ERR("cannot bind to RR API\n"); return -1; } LM_DBG("loaded rr api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH) { /* bind the AUTH API */ - if (auth_load_api(&_lua_authb) < 0) - { + if(auth_load_api(&_lua_authb) < 0) { LM_ERR("cannot bind to AUTH API\n"); return -1; } LM_DBG("loaded auth api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH_DB) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH_DB) { /* bind the AUTH_DB API */ - if (auth_db_load_api(&_lua_auth_dbb) < 0) - { + if(auth_db_load_api(&_lua_auth_dbb) < 0) { LM_ERR("cannot bind to AUTH_DB API\n"); return -1; } LM_DBG("loaded auth_db api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MAXFWD) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MAXFWD) { /* bind the MAXFWD API */ - if (maxfwd_load_api(&_lua_maxfwdb) < 0) - { + if(maxfwd_load_api(&_lua_maxfwdb) < 0) { LM_ERR("cannot bind to MAXFWD API\n"); return -1; } LM_DBG("loaded maxfwd api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR) { /* bind the REGISTRAR API */ - if (registrar_load_api(&_lua_registrarb) < 0) - { + if(registrar_load_api(&_lua_registrarb) < 0) { LM_ERR("cannot bind to REGISTRAR API\n"); return -1; } LM_DBG("loaded registrar api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER) { /* bind the DISPATCHER API */ - if (dispatcher_load_api(&_lua_dispatcherb) < 0) - { + if(dispatcher_load_api(&_lua_dispatcherb) < 0) { LM_ERR("cannot bind to DISPATCHER API\n"); return -1; } LM_DBG("loaded dispatcher api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_XHTTP) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_XHTTP) { /* bind the XHTTP API */ - if (xhttp_load_api(&_lua_xhttpb) < 0) - { + if(xhttp_load_api(&_lua_xhttpb) < 0) { LM_ERR("cannot bind to XHTTP API\n"); return -1; } LM_DBG("loaded xhttp api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS) { /* bind the SDPOPS API */ - if (sdpops_load_api(&_lua_sdpopsb) < 0) - { + if(sdpops_load_api(&_lua_sdpopsb) < 0) { LM_ERR("cannot bind to SDPOPS API\n"); return -1; } LM_DBG("loaded sdpops api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE) { /* bind the PRESENCE API */ - if (presence_load_api(&_lua_presenceb) < 0) - { + if(presence_load_api(&_lua_presenceb) < 0) { LM_ERR("cannot bind to PRESENCE API\n"); return -1; } LM_DBG("loaded presence api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE) { /* bind the PRESENCE_XML API */ - if (presence_xml_load_api(&_lua_presence_xmlb) < 0) - { + if(presence_xml_load_api(&_lua_presence_xmlb) < 0) { LM_ERR("cannot bind to PRESENCE_XML API\n"); return -1; } LM_DBG("loaded presence_xml api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TEXTOPS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TEXTOPS) { /* bind the TEXTOPS API */ - if (load_textops_api(&_lua_textopsb) < 0) - { + if(load_textops_api(&_lua_textopsb) < 0) { LM_ERR("cannot bind to TEXTOPS API\n"); return -1; } LM_DBG("loaded textops api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PUA_USRLOC) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PUA_USRLOC) { /* bind the PUA_USRLOC API */ - if (pua_usrloc_load_api(&_lua_pua_usrlocb) < 0) - { + if(pua_usrloc_load_api(&_lua_pua_usrlocb) < 0) { LM_ERR("cannot bind to PUA_USRLOC API\n"); return -1; } LM_DBG("loaded pua_usrloc api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SIPUTILS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SIPUTILS) { /* bind the SIPUTILS API */ - if (siputils_load_api(&_lua_siputilsb) < 0) - { + if(siputils_load_api(&_lua_siputilsb) < 0) { LM_ERR("cannot bind to SIPUTILS API\n"); return -1; } LM_DBG("loaded siputils api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RLS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RLS) { /* bind the RLS API */ - if (rls_load_api(&_lua_rlsb) < 0) - { + if(rls_load_api(&_lua_rlsb) < 0) { LM_ERR("cannot bind to RLS API\n"); return -1; } LM_DBG("loaded rls api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_ALIAS_DB) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_ALIAS_DB) { /* bind the ALIAS_DB API */ - if (alias_db_load_api(&_lua_alias_dbb) < 0) - { + if(alias_db_load_api(&_lua_alias_dbb) < 0) { LM_ERR("cannot bind to ALIAS_DB API\n"); return -1; } LM_DBG("loaded alias_db api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MSILO) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO) { /* bind the MSILO API */ - if (load_msilo_api(&_lua_msilob) < 0) - { + if(load_msilo_api(&_lua_msilob) < 0) { LM_ERR("cannot bind to MSILO API\n"); return -1; } LM_DBG("loaded msilo api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_UAC) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC) { /* bind the UAC API */ - if (load_uac_api(&_lua_uacb) < 0) - { + if(load_uac_api(&_lua_uacb) < 0) { LM_ERR("cannot bind to UAC API\n"); return -1; } LM_DBG("loaded uac api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SANITY) { /* bind the SANITY API */ - if (sanity_load_api(&_lua_sanityb) < 0) - { + if(sanity_load_api(&_lua_sanityb) < 0) { LM_ERR("cannot bind to SANITY API\n"); return -1; } LM_DBG("loaded sanity api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS) { /* bind the CFGUTILS API */ - if (cfgutils_load_api(&_lua_cfgutilsb) < 0) - { + if(cfgutils_load_api(&_lua_cfgutilsb) < 0) { LM_ERR("cannot bind to CFGUTILS API\n"); return -1; } LM_DBG("loaded cfgutils api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TMX) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TMX) { /* bind the TMX API */ - if (load_tmx_api(&_lua_tmxb) < 0) - { + if(load_tmx_api(&_lua_tmxb) < 0) { LM_ERR("cannot bind to TMX API\n"); return -1; } LM_DBG("loaded tmx api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MQUEUE) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MQUEUE) { /* bind the MQUEUE API */ - if (load_mq_api(&_lua_mqb) < 0) - { + if(load_mq_api(&_lua_mqb) < 0) { LM_ERR("cannot bind to MQUEUE API\n"); return -1; } LM_DBG("loaded mqueue api\n"); } - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB) - { + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_NDB_MONGODB) { /* bind the NDB_MONGODB API */ - if (ndb_mongodb_load_api(&_lua_ndb_mongodbb) < 0) - { + if(ndb_mongodb_load_api(&_lua_ndb_mongodbb) < 0) { LM_ERR("cannot bind to NDB_MONGODB API\n"); return -1; } @@ -3594,80 +3258,79 @@ int lua_sr_exp_register_mod(char *mname) len = strlen(mname); - if(len==2 && strcmp(mname, "sl")==0) - { + if(len == 2 && strcmp(mname, "sl") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SL; return 0; - } else if(len==2 && strcmp(mname, "tm")==0) { + } else if(len == 2 && strcmp(mname, "tm") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_TM; return 0; - } else if(len==6 && strcmp(mname, "sqlops")==0) { + } else if(len == 6 && strcmp(mname, "sqlops") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SQLOPS; return 0; - } else if(len==2 && strcmp(mname, "rr")==0) { + } else if(len == 2 && strcmp(mname, "rr") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_RR; return 0; - } else if(len==4 && strcmp(mname, "auth")==0) { + } else if(len == 4 && strcmp(mname, "auth") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_AUTH; return 0; - } else if(len==7 && strcmp(mname, "auth_db")==0) { + } else if(len == 7 && strcmp(mname, "auth_db") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_AUTH_DB; return 0; - } else if(len==6 && strcmp(mname, "maxfwd")==0) { + } else if(len == 6 && strcmp(mname, "maxfwd") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_MAXFWD; return 0; - } else if(len==9 && strcmp(mname, "registrar")==0) { + } else if(len == 9 && strcmp(mname, "registrar") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_REGISTRAR; return 0; - } else if(len==10 && strcmp(mname, "dispatcher")==0) { + } else if(len == 10 && strcmp(mname, "dispatcher") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_DISPATCHER; return 0; - } else if(len==5 && strcmp(mname, "xhttp")==0) { + } else if(len == 5 && strcmp(mname, "xhttp") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_XHTTP; return 0; - } else if(len==6 && strcmp(mname, "sdpops")==0) { + } else if(len == 6 && strcmp(mname, "sdpops") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SDPOPS; return 0; - } else if(len==8 && strcmp(mname, "presence")==0) { + } else if(len == 8 && strcmp(mname, "presence") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_PRESENCE; return 0; - } else if(len==12 && strcmp(mname, "presence_xml")==0) { + } else if(len == 12 && strcmp(mname, "presence_xml") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_PRESENCE_XML; return 0; - } else if(len==7 && strcmp(mname, "textops")==0) { + } else if(len == 7 && strcmp(mname, "textops") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_TEXTOPS; return 0; - } else if(len==10 && strcmp(mname, "pua_usrloc")==0) { + } else if(len == 10 && strcmp(mname, "pua_usrloc") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_PUA_USRLOC; return 0; - } else if(len==8 && strcmp(mname, "siputils")==0) { + } else if(len == 8 && strcmp(mname, "siputils") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SIPUTILS; return 0; - } else if(len==3 && strcmp(mname, "rls")==0) { + } else if(len == 3 && strcmp(mname, "rls") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_RLS; return 0; - } else if(len==8 && strcmp(mname, "alias_db")==0) { + } else if(len == 8 && strcmp(mname, "alias_db") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_ALIAS_DB; return 0; - } else if(len==5 && strcmp(mname, "msilo")==0) { + } else if(len == 5 && strcmp(mname, "msilo") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_MSILO; return 0; - } else if(len==3 && strcmp(mname, "uac")==0) { + } else if(len == 3 && strcmp(mname, "uac") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_UAC; return 0; - } else if(len==6 && strcmp(mname, "sanity")==0) { + } else if(len == 6 && strcmp(mname, "sanity") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SANITY; return 0; - } else if(len==8 && strcmp(mname, "cfgutils")==0) { + } else if(len == 8 && strcmp(mname, "cfgutils") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_CFGUTILS; return 0; - } else if(len==3 && strcmp(mname, "tmx")==0) { + } else if(len == 3 && strcmp(mname, "tmx") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_TMX; return 0; - } else if(len==6 && strcmp(mname, "mqueue")==0) { + } else if(len == 6 && strcmp(mname, "mqueue") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_MQUEUE; return 0; - } else if(len==11 && strcmp(mname, "ndb_mongodb")==0) { + } else if(len == 11 && strcmp(mname, "ndb_mongodb") == 0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_NDB_MONGODB; return 0; } @@ -3682,55 +3345,54 @@ void lua_sr_exp_openlibs(lua_State *L) { LM_DBG("exporting sr registered extensions\n"); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL) - luaL_openlib(L, "sr.sl", _sr_sl_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM) - luaL_openlib(L, "sr.tm", _sr_tm_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS) - luaL_openlib(L, "sr.sqlops", _sr_sqlops_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RR) - luaL_openlib(L, "sr.rr", _sr_rr_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH) - luaL_openlib(L, "sr.auth", _sr_auth_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_AUTH_DB) - luaL_openlib(L, "sr.auth_db", _sr_auth_db_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MAXFWD) - luaL_openlib(L, "sr.maxfwd", _sr_maxfwd_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_REGISTRAR) - luaL_openlib(L, "sr.registrar", _sr_registrar_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_DISPATCHER) - luaL_openlib(L, "sr.dispatcher", _sr_dispatcher_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_XHTTP) - luaL_openlib(L, "sr.xhttp", _sr_xhttp_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS) - luaL_openlib(L, "sr.sdpops", _sr_sdpops_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE) - luaL_openlib(L, "sr.presence", _sr_presence_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE_XML) + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SL) + luaL_openlib(L, "sr.sl", _sr_sl_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TM) + luaL_openlib(L, "sr.tm", _sr_tm_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SQLOPS) + luaL_openlib(L, "sr.sqlops", _sr_sqlops_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RR) + luaL_openlib(L, "sr.rr", _sr_rr_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH) + luaL_openlib(L, "sr.auth", _sr_auth_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_AUTH_DB) + luaL_openlib(L, "sr.auth_db", _sr_auth_db_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MAXFWD) + luaL_openlib(L, "sr.maxfwd", _sr_maxfwd_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_REGISTRAR) + luaL_openlib(L, "sr.registrar", _sr_registrar_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_DISPATCHER) + luaL_openlib(L, "sr.dispatcher", _sr_dispatcher_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_XHTTP) + luaL_openlib(L, "sr.xhttp", _sr_xhttp_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SDPOPS) + luaL_openlib(L, "sr.sdpops", _sr_sdpops_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE) + luaL_openlib(L, "sr.presence", _sr_presence_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PRESENCE_XML) luaL_openlib(L, "sr.presence_xml", _sr_presence_xml_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TEXTOPS) - luaL_openlib(L, "sr.textops", _sr_textops_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PUA_USRLOC) - luaL_openlib(L, "sr.pua_usrloc", _sr_pua_usrloc_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SIPUTILS) - luaL_openlib(L, "sr.siputils", _sr_siputils_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_RLS) - luaL_openlib(L, "sr.rls", _sr_rls_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_ALIAS_DB) - luaL_openlib(L, "sr.alias_db", _sr_alias_db_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MSILO) - luaL_openlib(L, "sr.msilo", _sr_msilo_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_UAC) - luaL_openlib(L, "sr.uac", _sr_uac_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY) - luaL_openlib(L, "sr.sanity", _sr_sanity_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS) - luaL_openlib(L, "sr.cfgutils", _sr_cfgutils_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TMX) - luaL_openlib(L, "sr.tmx", _sr_tmx_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MQUEUE) - luaL_openlib(L, "sr.mq", _sr_mqueue_Map, 0); - if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB) + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TEXTOPS) + luaL_openlib(L, "sr.textops", _sr_textops_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_PUA_USRLOC) + luaL_openlib(L, "sr.pua_usrloc", _sr_pua_usrloc_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SIPUTILS) + luaL_openlib(L, "sr.siputils", _sr_siputils_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_RLS) + luaL_openlib(L, "sr.rls", _sr_rls_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_ALIAS_DB) + luaL_openlib(L, "sr.alias_db", _sr_alias_db_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MSILO) + luaL_openlib(L, "sr.msilo", _sr_msilo_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC) + luaL_openlib(L, "sr.uac", _sr_uac_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_SANITY) + luaL_openlib(L, "sr.sanity", _sr_sanity_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS) + luaL_openlib(L, "sr.cfgutils", _sr_cfgutils_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_TMX) + luaL_openlib(L, "sr.tmx", _sr_tmx_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_MQUEUE) + luaL_openlib(L, "sr.mq", _sr_mqueue_Map, 0); + if(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_NDB_MONGODB) luaL_openlib(L, "sr.ndb_mongodb", _sr_ndb_mongodb_Map, 0); } - diff --git a/src/modules/app_lua_sr/app_lua_sr_exp.h b/src/modules/app_lua_sr/app_lua_sr_exp.h index a8830292c8c..413b9564be9 100644 --- a/src/modules/app_lua_sr/app_lua_sr_exp.h +++ b/src/modules/app_lua_sr/app_lua_sr_exp.h @@ -29,4 +29,3 @@ int lua_sr_exp_init_mod(void); void lua_sr_exp_openlibs(lua_State *L); #endif - diff --git a/src/modules/app_lua_sr/app_lua_sr_mod.c b/src/modules/app_lua_sr/app_lua_sr_mod.c index 96b1875d3c3..c96793cc6fe 100644 --- a/src/modules/app_lua_sr/app_lua_sr_mod.c +++ b/src/modules/app_lua_sr/app_lua_sr_mod.c @@ -46,23 +46,21 @@ int _ksr_app_lua_log_mode = 0; app_lua_api_t _app_lua_api = {0}; -static param_export_t params[]={ - {"register", PARAM_STRING|USE_FUNC_PARAM, (void*)app_lua_register_param}, - {0, 0, 0} -}; +static param_export_t params[] = {{"register", PARAM_STRING | USE_FUNC_PARAM, + (void *)app_lua_register_param}, + {0, 0, 0}}; struct module_exports exports = { - "app_lua_sr", - DEFAULT_DLFLAGS, /* dlopen flags */ - 0, /*·exported·functions·*/ - params, /*·exported·params·*/ - 0, /*·exported·RPC·methods·*/ - 0, /* exported pseudo-variables */ - 0, /*·response·function·*/ - mod_init, /* initialization module */ - 0, /* per child init function */ - 0 /* destroy function */ + "app_lua_sr", DEFAULT_DLFLAGS, /* dlopen flags */ + 0, /*·exported·functions·*/ + params, /*·exported·params·*/ + 0, /*·exported·RPC·methods·*/ + 0, /* exported pseudo-variables */ + 0, /*·response·function·*/ + mod_init, /* initialization module */ + 0, /* per child init function */ + 0 /* destroy function */ }; /** @@ -70,10 +68,10 @@ struct module_exports exports = { */ static int mod_init(void) { - if(app_lua_load_api(&_app_lua_api)<0) { + if(app_lua_load_api(&_app_lua_api) < 0) { return -1; } - if(lua_sr_exp_init_mod()<0) { + if(lua_sr_exp_init_mod() < 0) { return -1; } @@ -83,11 +81,11 @@ static int mod_init(void) static int app_lua_register_param(modparam_t type, void *val) { - if(val==NULL) { + if(val == NULL) { return -1; } - if(lua_sr_exp_register_mod((char*)val)==0) + if(lua_sr_exp_register_mod((char *)val) == 0) return 0; return -1; }