Module: sip-router Branch: master Commit: abc175ad51767f8607b77b0478878149a1a39131 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=abc175ad...
Author: pd peter.dunkley@crocodile-rcs.com Committer: pd peter.dunkley@crocodile-rcs.com Date: Thu Aug 18 16:47:13 2011 +0100
modules/app_lua, modules_k/presence: Added support for the exported function pres_auth_status() to app_lua
---
modules/app_lua/app_lua_exp.c | 67 ++++++++++++++++++++++++++++++++++++ modules_k/presence/bind_presence.c | 1 + modules_k/presence/bind_presence.h | 14 +++++++ modules_k/presence/presence.c | 26 +++++++++----- modules_k/presence/presence.h | 1 + 5 files changed, 100 insertions(+), 9 deletions(-)
diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c index 3a69ff7..be8d22d 100644 --- a/modules/app_lua/app_lua_exp.c +++ b/modules/app_lua/app_lua_exp.c @@ -42,6 +42,7 @@ #include "../../modules_k/dispatcher/api.h" #include "../../modules/xhttp/api.h" #include "../../modules/sdpops/api.h" +#include "../../modules_k/presence/bind_presence.h"
#include "app_lua_api.h"
@@ -56,6 +57,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)
/** * @@ -119,6 +121,11 @@ static xhttp_api_t _lua_xhttpb; static sdpops_api_t _lua_sdpopsb;
/** + * presence + */ +static presence_api_t _lua_presenceb; + +/** * */ static int lua_sr_sl_send_reply (lua_State *L) @@ -1339,6 +1346,51 @@ static const luaL_reg _sr_sdpops_Map [] = { {NULL, NULL} };
+/** + * + */ +static int lua_sr_pres_auth_status(lua_State *L) +{ + str param[2]; + int ret; + sr_lua_env_t *env_L; + + env_L = sr_lua_env_get(); + + 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) + { + LM_WARN("invalid parameters from Lua env\n"); + return app_lua_return_error(L); + } + + 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].len = strlen(param[0].s); + 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]); + return app_lua_return_int(L, ret); +} + +/** + * + */ +static const luaL_reg _sr_presence_Map [] = { + {"pres_auth_status", lua_sr_pres_auth_status}, + {NULL, NULL} +};
/** * @@ -1461,6 +1513,16 @@ int lua_sr_exp_init_mod(void) } LM_DBG("loaded sdpops api\n"); } + if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_PRESENCE) + { + /* bind the PRESENCE API */ + if (presence_load_api(&_lua_presenceb) < 0) + { + LM_ERR("cannot bind to PRESENCE API\n"); + return -1; + } + LM_DBG("loaded presence api\n"); + } return 0; }
@@ -1507,6 +1569,9 @@ int lua_sr_exp_register_mod(char *mname) } 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) { + _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_PRESENCE; + return 0; }
return -1; @@ -1539,5 +1604,7 @@ void lua_sr_exp_openlibs(lua_State *L) 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); }
diff --git a/modules_k/presence/bind_presence.c b/modules_k/presence/bind_presence.c index 8a89d1e..f606d82 100644 --- a/modules_k/presence/bind_presence.c +++ b/modules_k/presence/bind_presence.c @@ -66,6 +66,7 @@ int bind_presence(presence_api_t* api) api->get_sphere= get_sphere; api->get_presentity= get_p_notify_body; api->free_presentity= free_notify_body; + api->pres_auth_status= pres_auth_status; return 0; }
diff --git a/modules_k/presence/bind_presence.h b/modules_k/presence/bind_presence.h index afc1a77..7f2ce4e 100644 --- a/modules_k/presence/bind_presence.h +++ b/modules_k/presence/bind_presence.h @@ -38,10 +38,12 @@ #include "event_list.h" #include "hash.h" #include "presentity.h" +#include "../../sr_module.h"
typedef int (*update_watchers_t)(str pres_uri, pres_ev_t* ev, str* rules_doc); typedef str* (*pres_get_presentity_t)(str pres_uri, pres_ev_t *ev, str *etag, str *contact); typedef void (*pres_free_presentity_t)(str *presentity, pres_ev_t *ev); +typedef int (*pres_auth_status_t)(struct sip_msg* msg, str watcher_uri, str presentity_uri);
typedef struct presence_api { add_event_t add_event; @@ -62,11 +64,23 @@ typedef struct presence_api { pres_get_sphere_t get_sphere; pres_get_presentity_t get_presentity; pres_free_presentity_t free_presentity; + pres_auth_status_t pres_auth_status; } presence_api_t;
int bind_presence(presence_api_t* api);
typedef int (*bind_presence_t)(presence_api_t* api);
+inline static int presence_load_api(presence_api_t *api) +{ + bind_presence_t bind_presence_exports; + if (!(bind_presence_exports = (bind_presence_t)find_export("bind_presence", 1, 0))) + { + LM_ERR("Failed to import bind_presence\n"); + return -1; + } + return bind_presence_exports(api); +} + #endif
diff --git a/modules_k/presence/presence.c b/modules_k/presence/presence.c index 8dd866c..1bb6c9b 100644 --- a/modules_k/presence/presence.c +++ b/modules_k/presence/presence.c @@ -116,7 +116,7 @@ static int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array); int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc); static int mi_child_init(void); -static int pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2); +static int w_pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2); static int w_pres_refresh_watchers(struct sip_msg *msg, char *puri, char *pevent, char *ptype); static int w_pres_update_watchers(struct sip_msg *msg, char *puri, @@ -150,7 +150,7 @@ static cmd_export_t cmds[]= fixup_presence, 0, REQUEST_ROUTE}, {"handle_subscribe", (cmd_function)handle_subscribe, 0, fixup_subscribe,0, REQUEST_ROUTE}, - {"pres_auth_status", (cmd_function)pres_auth_status, 2, + {"pres_auth_status", (cmd_function)w_pres_auth_status, 2, fixup_pvar_pvar, fixup_free_pvar_pvar, REQUEST_ROUTE}, {"pres_refresh_watchers", (cmd_function)w_pres_refresh_watchers, 3, fixup_refresh_watchers, 0, ANY_ROUTE}, @@ -1131,16 +1131,11 @@ static int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs return 0; }
-static int pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2) +static int w_pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2) { pv_spec_t *sp; pv_value_t pv_val; - str watcher_uri, presentity_uri, event; - struct sip_uri uri; - pres_ev_t* ev; - str* rules_doc = NULL; - subs_t subs; - int res; + str watcher_uri, presentity_uri;
sp = (pv_spec_t *)_sp1;
@@ -1178,6 +1173,19 @@ static int pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2) return -1; }
+ return pres_auth_status(_msg, watcher_uri, presentity_uri); +} + + +int pres_auth_status(struct sip_msg* msg, str watcher_uri, str presentity_uri) +{ + str event; + struct sip_uri uri; + pres_ev_t* ev; + str* rules_doc = NULL; + subs_t subs; + int res; + event.s = "presence"; event.len = 8;
diff --git a/modules_k/presence/presence.h b/modules_k/presence/presence.h index 16e5177..7d4ba08 100644 --- a/modules_k/presence/presence.h +++ b/modules_k/presence/presence.h @@ -83,5 +83,6 @@ extern int phtable_size; extern phtable_t* pres_htable;
int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc); +int pres_auth_status(struct sip_msg* msg, str watcher_uri, str presentity_uri);
#endif /* PA_MOD_H */