Browse Source

modules/app_lua, modules_k/presence_xml: Added support for pres_check_basic() and pres_check_available() to app_lua

pd 14 years ago
parent
commit
604a8a95e0

+ 107 - 0
modules/app_lua/app_lua_exp.c

@@ -43,6 +43,7 @@
 #include "../../modules/xhttp/api.h"
 #include "../../modules/sdpops/api.h"
 #include "../../modules_k/presence/bind_presence.h"
+#include "../../modules_k/presence_xml/api.h"
 
 #include "app_lua_api.h"
 
@@ -58,6 +59,7 @@
 #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)
 
 /**
  *
@@ -125,6 +127,11 @@ static sdpops_api_t _lua_sdpopsb;
  */
 static presence_api_t _lua_presenceb;
 
+/**
+ * presence_xml
+ */
+static presence_xml_api_t _lua_presence_xmlb;
+
 /**
  *
  */
@@ -1392,6 +1399,91 @@ static const luaL_reg _sr_presence_Map [] = {
 	{NULL, NULL}
 };
 
+/**
+ *
+ */
+static int lua_sr_pres_check_basic(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_XML))
+	{
+		LM_WARN("weird: presence_xml 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_presence_xmlb.pres_check_basic(env_L->msg, param[0], param[1]);
+	return app_lua_return_int(L, ret);
+}
+
+/**
+ *
+ */
+static int lua_sr_pres_check_activities(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_XML))
+	{
+		LM_WARN("weird: presence_xml 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_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}
+};
+
 /**
  *
  */
@@ -1523,6 +1615,16 @@ int lua_sr_exp_init_mod(void)
 		}
 		LM_DBG("loaded presence api\n");
 	}
+	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)
+		{
+			LM_ERR("cannot bind to PRESENCE_XML API\n");
+			return -1;
+		}
+		LM_DBG("loaded presence_xml api\n");
+	}
 	return 0;
 }
 
@@ -1572,6 +1674,9 @@ int lua_sr_exp_register_mod(char *mname)
 	} 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) {
+		_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_PRESENCE_XML;
+		return 0;
 	}
 
 	return -1;
@@ -1606,5 +1711,7 @@ void lua_sr_exp_openlibs(lua_State *L)
 		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);
 }
 

+ 14 - 52
modules_k/presence_xml/pres_check.c

@@ -24,26 +24,13 @@
 
 #include "pres_check.h"
 #include "pidf.h"
-#include "../../mod_fix.h"
 #include "../../parser/msg_parser.h"
 #include "../../parser/parse_uri.h"
 #include "../../str.h"
 #include "../presence/event_list.h"
 
-int fixup_presxml_check(void **param, int param_no)
+int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
 {
-        if(param_no==1)
-        {
-                return fixup_spve_null(param, 1);
-        } else if(param_no==2) {
-                return fixup_spve_null(param, 1);
-        }
-        return 0;
-}
-
-int presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status)
-{
-	str uri, basic;
 	str *presentity = NULL;
 	struct sip_uri parsed_uri;
 	pres_ev_t *ev;
@@ -53,21 +40,9 @@ int presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status)
 	xmlNodePtr tuple = NULL, basicNode = NULL;
 	char *basicVal = NULL;
 
-	if (fixup_get_svalue(msg, (gparam_p)presentity_uri, &uri) != 0)
-	{
-		LM_ERR("invalid presentity uri parameter\n");
-		return -1;
-	}
-
-	if (fixup_get_svalue(msg, (gparam_p)status, &basic) != 0)
+	if (parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0)
 	{
-		LM_ERR("invalud status parameter\n");
-		return -1;
-	}
-
-	if (parse_uri(uri.s, uri.len, &parsed_uri) < 0)
-	{
-		LM_ERR("bad uri: %.*s\n", uri.len, uri.s);
+		LM_ERR("bad uri: %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 
@@ -78,11 +53,11 @@ int presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status)
 		return -1;
 	}
 
-	presentity = pres_get_presentity(uri, ev, NULL, NULL);
+	presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
 
 	if (presentity == NULL || presentity->len <= 0 || presentity->s == NULL)
 	{
-		LM_DBG("cannot get presentity for %.*s\n", uri.len, uri.s);
+		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 
@@ -114,7 +89,7 @@ int presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status)
 				goto error;
 			}
 
-			if (strncasecmp(basicVal, basic.s, basic.len) == 0)
+			if (strncasecmp(basicVal, status.s, status.len) == 0)
 				retval = 1;
 
 			xmlFree(basicVal);
@@ -128,9 +103,8 @@ error:
 	return retval;
 }
 
-int presxml_check_activities(struct sip_msg *msg, char *presentity_uri, char *activity)
+int presxml_check_activities(struct sip_msg *msg, str presentity_uri, str activity)
 {
-	str uri, act;
 	str *presentity = NULL;
 	struct sip_uri parsed_uri;
 	pres_ev_t *ev;
@@ -140,21 +114,9 @@ int presxml_check_activities(struct sip_msg *msg, char *presentity_uri, char *ac
 	xmlDocPtr xmlDoc = NULL;
 	xmlNodePtr person = NULL, activitiesNode = NULL, activityNode = NULL;
 
-	if (fixup_get_svalue(msg, (gparam_p)presentity_uri, &uri) != 0)
-	{
-		LM_ERR("invalid presentity uri parameter\n");
-		return -1;
-	}
-
-	if (fixup_get_svalue(msg, (gparam_p)activity, &act) != 0)
-	{
-		LM_ERR("invalid activity parameter\n");
-		return -1;
-	}
-
-	if (parse_uri(uri.s, uri.len, &parsed_uri) < 0)
+	if (parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0)
 	{
-		LM_ERR("bad uri: %.*s\n", uri.len, uri.s);
+		LM_ERR("bad uri: %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 
@@ -165,19 +127,19 @@ int presxml_check_activities(struct sip_msg *msg, char *presentity_uri, char *ac
 		return -1;
 	}
 
-	if ((nodeName = pkg_malloc(act.len + 1)) == NULL)
+	if ((nodeName = pkg_malloc(activity.len + 1)) == NULL)
 	{
 		LM_ERR("cannot pkg_malloc for nodeName\n");
 		return -1;		
 	}
-	memcpy(nodeName, act.s, act.len);
-	nodeName[act.len] = '\0';
+	memcpy(nodeName, activity.s, activity.len);
+	nodeName[activity.len] = '\0';
 
-	presentity = pres_get_presentity(uri, ev, NULL, NULL);
+	presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
 
 	if (presentity == NULL || presentity->len <= 0 || presentity->s == NULL)
 	{
-		LM_DBG("cannot get presentity for %.*s\n", uri.len, uri.s);
+		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 

+ 2 - 3
modules_k/presence_xml/pres_check.h

@@ -24,9 +24,8 @@
 #include "../presence/bind_presence.h"
 #include "../presence/event_list.h"
 
-int presxml_check_basic(struct sip_msg* msg, char *presentity_uri, char *status);
-int presxml_check_activities(struct sip_msg* msg, char *presentity_uri, char *activity);
-int fixup_presxml_check(void **param, int param_no);
+int presxml_check_basic(struct sip_msg* msg, str presentity_uri, str status);
+int presxml_check_activities(struct sip_msg* msg, str presentity_uri, str activity);
 contains_event_t pres_contains_event;
 pres_get_presentity_t pres_get_presentity;
 pres_free_presentity_t pres_free_presentity;

+ 72 - 2
modules_k/presence_xml/presence_xml.c

@@ -52,10 +52,12 @@
 #include "../xcap_client/xcap_functions.h"
 #include "../../modules/sl/sl.h"
 #include "../../lib/kmi/mi.h"
+#include "../../mod_fix.h"
 #include "pidf.h"
 #include "add_events.h"
 #include "presence_xml.h"
 #include "pres_check.h"
+#include "api.h"
 
 MODULE_VERSION
 #define S_TABLE_VERSION 4
@@ -72,6 +74,10 @@ static int xcap_doc_updated(int doc_type, str xid, char* doc);
 static int mi_child_init(void);
 static struct mi_root* dum(struct mi_root* cmd, void* param);
 
+static int fixup_presxml_check(void **param, int param_no);
+static int w_presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status);
+static int w_presxml_check_activities(struct sip_msg *msg, char *presentity_uri, char *activities);
+
 /** module variables ***/
 add_event_t pres_add_event;
 update_watchers_t pres_update_watchers;
@@ -102,10 +108,12 @@ db_func_t pxml_dbf;
 xcapGetNewDoc_t xcap_GetNewDoc;
 
 static cmd_export_t cmds[]={
-	{ "pres_check_basic",		(cmd_function)presxml_check_basic, 2,
+	{ "pres_check_basic",		(cmd_function)w_presxml_check_basic, 2,
 		fixup_presxml_check, 0, ANY_ROUTE},
-	{ "pres_check_activities",	(cmd_function)presxml_check_activities, 2,
+	{ "pres_check_activities",	(cmd_function)w_presxml_check_activities, 2,
 		fixup_presxml_check, 0, ANY_ROUTE},
+	{ "bind_presence_xml",		(cmd_function)bind_presence_xml, 1,
+		0, 0, 0},
 	{ 0, 0, 0, 0, 0, 0}
 };
 
@@ -498,3 +506,65 @@ static struct mi_root* dum(struct mi_root* cmd, void* param)
 {
 	return 0;
 }
+
+int bind_presence_xml(struct presence_xml_binds *pxb)
+{
+	if (pxb == NULL)
+	{
+		LM_WARN("bind_presence_xml: Cannot load presence_xml API into a NULL pointer\n");
+		return -1;
+	}
+
+	pxb->pres_check_basic = presxml_check_basic;
+	pxb->pres_check_activities = presxml_check_activities;
+	return 0;
+}
+
+static int fixup_presxml_check(void **param, int param_no)
+{
+        if(param_no==1)
+        {
+                return fixup_spve_null(param, 1);
+        } else if(param_no==2) {
+                return fixup_spve_null(param, 1);
+        }
+        return 0;
+}
+
+static int w_presxml_check_basic(struct sip_msg *msg, char *presentity_uri, char *status)
+{
+        str uri, basic;
+
+        if (fixup_get_svalue(msg, (gparam_p)presentity_uri, &uri) != 0)
+        {
+                LM_ERR("invalid presentity uri parameter\n");
+                return -1;
+        }
+
+        if (fixup_get_svalue(msg, (gparam_p)status, &basic) != 0)
+        {
+                LM_ERR("invalid status parameter\n");
+                return -1;
+        }
+
+	return presxml_check_basic(msg, uri, basic);
+}
+
+static int w_presxml_check_activities(struct sip_msg *msg, char *presentity_uri, char *activity)
+{
+        str uri, act;
+
+        if (fixup_get_svalue(msg, (gparam_p)presentity_uri, &uri) != 0)
+        {
+                LM_ERR("invalid presentity uri parameter\n");
+                return -1;
+        }
+
+        if (fixup_get_svalue(msg, (gparam_p)activity, &act) != 0)
+        {
+                LM_ERR("invalid activity parameter\n");
+                return -1;
+        }
+
+	return presxml_check_activities(msg, uri, act);
+}