Przeglądaj źródła

modules_k/presence_xml: pidf-manipulation now fetched using event->get_pidf_doc()

- Part of the fix to the way presence hard-state works.
- Removed the, now unused, pidf_manipulation modparam
Peter Dunkley 13 lat temu
rodzic
commit
c5f3bc49bc

+ 34 - 56
modules_k/presence_xml/README

@@ -8,7 +8,7 @@ Edited by
 
 Anca-Maria Vamanu
 
-   Copyright © 2007 Voice Sistem SRL
+   Copyright © 2007 Voice Sistem SRL
      __________________________________________________________________
 
    Table of Contents
@@ -29,10 +29,9 @@ Anca-Maria Vamanu
               3.4. disable_winfo(int)
               3.5. disable_bla(int)
               3.6. force_active (int)
-              3.7. pidf_manipulation (int)
-              3.8. integrated_xcap_server (int)
-              3.9. xcap_server (str)
-              3.10. passive_mode(int)
+              3.7. integrated_xcap_server (int)
+              3.8. xcap_server (str)
+              3.9. passive_mode(int)
 
         4. Functions
 
@@ -52,12 +51,11 @@ Anca-Maria Vamanu
    1.4. Set disable_winfo parameter
    1.5. Set disable_bla parameter
    1.6. Set force_active parameter
-   1.7. Set pidf_manipulation parameter
-   1.8. Set integrated_xcap_server parameter
-   1.9. Set xcap_server parameter
-   1.10. Set passive_mode parameter
-   1.11. pres_check_basic usage
-   1.12. pres_check_activities usage
+   1.7. Set integrated_xcap_server parameter
+   1.8. Set xcap_server parameter
+   1.9. Set passive_mode parameter
+   1.10. pres_check_basic usage
+   1.11. pres_check_activities usage
 
 Chapter 1. Admin Guide
 
@@ -77,10 +75,9 @@ Chapter 1. Admin Guide
         3.4. disable_winfo(int)
         3.5. disable_bla(int)
         3.6. force_active (int)
-        3.7. pidf_manipulation (int)
-        3.8. integrated_xcap_server (int)
-        3.9. xcap_server (str)
-        3.10. passive_mode(int)
+        3.7. integrated_xcap_server (int)
+        3.8. xcap_server (str)
+        3.9. passive_mode(int)
 
    4. Functions
 
@@ -135,16 +132,15 @@ Chapter 1. Admin Guide
    3.4. disable_winfo(int)
    3.5. disable_bla(int)
    3.6. force_active (int)
-   3.7. pidf_manipulation (int)
-   3.8. integrated_xcap_server (int)
-   3.9. xcap_server (str)
-   3.10. passive_mode(int)
+   3.7. integrated_xcap_server (int)
+   3.8. xcap_server (str)
+   3.9. passive_mode(int)
 
 3.1. db_url(str)
 
    The database URL.
 
-   Default value is "mysql://openser:openserrw@localhost/openser".
+   Default value is “mysql://openser:openserrw@localhost/openser�.
 
    Example 1.1. Set db_url parameter
 ...
@@ -155,7 +151,7 @@ modparam("presence_xml", "db_url", "dbdriver://username:password@dbhost/dbname")
 
    The name of the database table where XCAP documents are stored.
 
-   Default value is "xcap".
+   Default value is “xcap�.
 
    Example 1.2. Set xcap_table parameter
 ...
@@ -166,7 +162,7 @@ modparam("presence_xml", "xcap_table", "xcaps")
 
    Set this parameter to disable the handling of the "presence" event.
 
-   Default value: "0".
+   Default value: “0�.
 
    Example 1.3. Set disable_presence parameter
 ...
@@ -178,7 +174,7 @@ modparam("presence_xml", "disable_presence", 1)
    Set this parameter to disable the handling of the "presence.winfo"
    event.
 
-   Default value: "0".
+   Default value: “0�.
 
    Example 1.4. Set disable_winfo parameter
 ...
@@ -189,7 +185,7 @@ modparam("presence_xml", "disable_winfo", 1)
 
    Set this parameter to disable the handling of the "dialog;sla" event.
 
-   Default value: "1" (0 - enabled, 1 - disabled).
+   Default value: “1� (0 - enabled, 1 - disabled).
 
    Example 1.5. Set disable_bla parameter
 ...
@@ -209,32 +205,14 @@ modparam("presence_xml", "disable_bla", 1)
    Note: When switching from one value to another, the watchers table must
    be emptied.
 
-   Default value is "0".
+   Default value is “0�.
 
    Example 1.6. Set force_active parameter
 ...
 modparam("presence_xml", "force_active", 1)
 ...
 
-3.7. pidf_manipulation (int)
-
-   Setting this parameter to 1 enables the features described in RFC 4827.
-   It gives the possibility to have a permanent state notified to the
-   users even in the case in which the phone is not online. The presence
-   document is taken from the XCAP server and aggregated together with the
-   other presence information, if any exist, for each Notify that is sent
-   to the watchers. It is also possible to have information notified even
-   if not issuing any Publish (useful for services such as email, SMS,
-   MMS).
-
-   Default value is "0".
-
-   Example 1.7. Set pidf_manipulation parameter
-...
-modparam("presence_xml", "pidf_manipulation", 1)
-...
-
-3.8. integrated_xcap_server (int)
+3.7. integrated_xcap_server (int)
 
    This parameter is a flag for the type of XCAP servers used. If the XCAP
    server is integrated with Kamailio presence_xml module and access the
@@ -249,35 +227,35 @@ modparam("presence_xml", "pidf_manipulation", 1)
    Otherwise, it uses xcap_client module to fetch documents from the XCAP
    servers with HTTP requests. This mode is currently not supported.
 
-   Default value is "0".
+   Default value is “0�.
 
-   Example 1.8. Set integrated_xcap_server parameter
+   Example 1.7. Set integrated_xcap_server parameter
 ...
 modparam("presence_xml", "integrated_xcap_server", 1)
 ...
 
-3.9. xcap_server (str)
+3.8. xcap_server (str)
 
    The address of the xcap servers used for storage. This parameter is
    compulsory if the integrated_xcap_server parameter is not set. It can
    be set more that once, to construct an address list of trusted XCAP
    servers.
 
-   Example 1.9. Set xcap_server parameter
+   Example 1.8. Set xcap_server parameter
 ...
 modparam("presence_xml", "xcap_server", "xcap_server.example.org")
 modparam("presence_xml", "xcap_server", "xcap_server.ag.org")
 ...
 
-3.10. passive_mode(int)
+3.9. passive_mode(int)
 
    If set to 1, module acts in passive mode - no bind to presence module,
    no connection to database. Useful when needing only to use $xml(...)
    pseudoc-variable.
 
-   Default value: "0" (0 - active mode, 1 - passive mode).
+   Default value: “0� (0 - active mode, 1 - passive mode).
 
-   Example 1.10. Set passive_mode parameter
+   Example 1.9. Set passive_mode parameter
 ...
 modparam("presence_xml", "passive_mode", 1)
 ...
@@ -287,7 +265,7 @@ modparam("presence_xml", "passive_mode", 1)
    4.1. pres_check_basic(presentity_uri, status)
    4.2. pres_check_activities(presentity_uri, activity)
 
-4.1. pres_check_basic(presentity_uri, status)
+4.1.  pres_check_basic(presentity_uri, status)
 
    Checks the /presence/tuple/status/basic nodes in the presentity for
    presentity_uri against the value in status.
@@ -298,7 +276,7 @@ modparam("presence_xml", "passive_mode", 1)
      * 1 - if a match is found.
      * -1 - if a match is not found.
 
-   Example 1.11. pres_check_basic usage
+   Example 1.10. pres_check_basic usage
 ...
     if (pres_check_basic("$ru", "open")) {
         ...
@@ -310,7 +288,7 @@ modparam("presence_xml", "passive_mode", 1)
     }
 ...
 
-4.2. pres_check_activities(presentity_uri, activity)
+4.2.  pres_check_activities(presentity_uri, activity)
 
    Checks whether a /presence/person/activities/activity node exists in
    the presentity for presentity_uri.
@@ -322,7 +300,7 @@ modparam("presence_xml", "passive_mode", 1)
      * -1 - if a match is not found.
      * -2 - if /presence/person or /presence/person/activity do not exist.
 
-   Example 1.12. pres_check_activities usage
+   Example 1.11. pres_check_activities usage
 ...
     if (pres_check_basic("$ru", "open")) {
         pres_check_activities("$ru", "unknown");
@@ -337,7 +315,7 @@ modparam("presence_xml", "passive_mode", 1)
 
 5. Installation
 
-   The module requires one table in Kamailio database: "xcap". The SQL
+   The module requires one table in Kamailio database: “xcap�. The SQL
    syntax to create it can be found in presence-create.sql script in the
    database directories in the kamailio/scripts folder. You can also find
    the complete database documentation on the project webpage,

+ 1 - 0
modules_k/presence_xml/add_events.c

@@ -69,6 +69,7 @@ int xml_add_events(void)
 		event.free_body= free_xml_body;
 		event.default_expires= 3600;
 		event.get_rules_doc= pres_get_rules_doc;
+		event.get_pidf_doc= pres_get_pidf_doc;
 		if(pres_add_event(&event)< 0)
 		{
 			LM_ERR("while adding event presence\n");

+ 0 - 24
modules_k/presence_xml/doc/presence_xml_admin.xml

@@ -216,30 +216,6 @@ modparam("presence_xml", "disable_bla", 1)
 ...
 modparam("presence_xml", "force_active", 1)
 ...
-</programlisting>
-		</example>
-	</section>
-	<section>
-		<title><varname>pidf_manipulation</varname> (int)</title>
-		<para>
-		Setting this parameter to 1 enables the features described in RFC 4827.
-		It gives the possibility to have a permanent state notified to the users
-		even in the case in which the phone is not online. The presence document
-		is taken from the XCAP server and aggregated together with the other
-		presence information, if any exist, for each Notify that is sent to the
-		watchers. It is also possible to have information notified even if not 
-		issuing any Publish (useful for services such as email, SMS, MMS).
-		</para>
-		<para>
-		<emphasis>Default value is <quote>0</quote>.
-		</emphasis>
-		</para>
-		<example>
-		<title>Set <varname>pidf_manipulation</varname> parameter</title>
-		<programlisting format="linespecific">
-...
-modparam("presence_xml", "pidf_manipulation", 1)
-...
 </programlisting>
 		</example>
 	</section>

+ 1 - 35
modules_k/presence_xml/notify_body.c

@@ -62,7 +62,7 @@ str* pres_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, i
 	str* n_body= NULL;
 	str* body= NULL;
 
-	if(body_array== NULL && !pidf_manipulation)
+	if(body_array== NULL)
 		return NULL;
 
 	if(off_index>= 0)
@@ -458,8 +458,6 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
 	xmlNodePtr add_node = NULL ;
 	str *body= NULL;
 	char* id= NULL, *tuple_id = NULL;
-	xmlDocPtr pidf_manip_doc= NULL;
-	str* pidf_doc= NULL;
 
 	xml_array = (xmlDocPtr*)pkg_malloc( (n+2)*sizeof(xmlDocPtr));
 	if(xml_array== NULL)
@@ -470,38 +468,6 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
 	}
 	memset(xml_array, 0, (n+2)*sizeof(xmlDocPtr)) ;
 
-	/* if pidf_manipulation usage is configured */
-	if(pidf_manipulation)
-	{
-		if( get_rules_doc(pres_user, pres_domain, PIDF_MANIPULATION, &pidf_doc)< 0)
-		{
-			LM_ERR("while getting xcap tree for doc_type PIDF_MANIPULATION\n");
-			goto error;
-		}	
-		if(pidf_doc== NULL)
-		{
-			LM_DBG("No PIDF_MANIPULATION doc for [user]= %.*s [domain]= %.*s\n"
-			,pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);
-		}
-		else
-		{
-			pidf_manip_doc= xmlParseMemory(pidf_doc->s, pidf_doc->len);
-			pkg_free(pidf_doc->s);
-			pkg_free(pidf_doc);
-
-			if(pidf_manip_doc== NULL)
-			{
-				LM_ERR("parsing xml memory\n");
-				goto error;
-			}		
-			else
-			{	
-				xml_array[0]= pidf_manip_doc;
-				j++;
-			}
-		}
-	}
-	
 	for(i=0; i<n; i++)
 	{
 		if(body_array[i] == NULL )

+ 0 - 2
modules_k/presence_xml/presence_xml.c

@@ -88,7 +88,6 @@ pres_get_sphere_t pres_get_sphere;
 str xcap_table= str_init("xcap");
 str db_url = str_init(DEFAULT_DB_URL);
 int force_active= 0;
-int pidf_manipulation= 0;
 int integrated_xcap_server= 0;
 xcap_serv_t* xs_list= NULL;
 int disable_presence = 0;
@@ -121,7 +120,6 @@ static param_export_t params[]={
 	{ "db_url",		STR_PARAM, &db_url.s},
 	{ "xcap_table",		STR_PARAM, &xcap_table.s},
 	{ "force_active",	INT_PARAM, &force_active },
-	{ "pidf_manipulation",  INT_PARAM, &pidf_manipulation},
 	{ "integrated_xcap_server", INT_PARAM, &integrated_xcap_server},
 	{ "xcap_server",     	STR_PARAM|USE_FUNC_PARAM,(void*)pxml_add_xcap_server},
 	{ "disable_presence",	INT_PARAM, &disable_presence },

+ 52 - 24
modules_k/presence_xml/xcap_auth.c

@@ -425,14 +425,19 @@ error:
 int pres_get_rules_doc(str* user, str* domain, str** rules_doc)
 {
 	
-	return get_rules_doc(user, domain, PRES_RULES, rules_doc);
+	return get_rules_doc(user, domain, NULL, PRES_RULES, rules_doc);
 }
 
-int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
+int pres_get_pidf_doc(str *user, str *domain, str *file_uri, str **rules_doc)
 {
-	db_key_t query_cols[5];
-	db_val_t query_vals[5];
-	db_key_t result_cols[3];
+	return get_rules_doc(user, domain, file_uri, PIDF_MANIPULATION, rules_doc);
+}
+
+int get_rules_doc(str* user, str* domain, str *file_uri, int type, str** rules_doc)
+{
+	db_key_t query_cols[3];
+	db_val_t query_vals[3];
+	db_key_t result_cols[1];
 	int n_query_cols = 0;
 	db1_res_t *result = 0;
 	db_row_t *row;
@@ -440,10 +445,11 @@ int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
 	str body;
 	str* doc= NULL;
 	int n_result_cols= 0, xcap_doc_col;
-	static str tmp1 = str_init("username");
-	static str tmp2 = str_init("domain");
-	static str tmp3 = str_init("doc_type");
-	static str tmp4 = str_init("doc");
+	static str tmp1 = str_init("doc_type");
+	static str tmp2 = str_init("doc_uri");
+	static str tmp3 = str_init("username");
+	static str tmp4 = str_init("domain");
+	static str tmp5 = str_init("doc");
 
 	if(force_active)
 	{
@@ -452,26 +458,43 @@ int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
 	}
 	LM_DBG("[user]= %.*s\t[domain]= %.*s", 
 			user->len, user->s,	domain->len, domain->s);
+
 	/* first search in database */
 	query_cols[n_query_cols] = &tmp1;
-	query_vals[n_query_cols].type = DB1_STR;
-	query_vals[n_query_cols].nul = 0;
-	query_vals[n_query_cols].val.str_val = *user;
-	n_query_cols++;
-	
-	query_cols[n_query_cols] = &tmp2;
-	query_vals[n_query_cols].type = DB1_STR;
-	query_vals[n_query_cols].nul = 0;
-	query_vals[n_query_cols].val.str_val = *domain;
-	n_query_cols++;
-	
-	query_cols[n_query_cols] = &tmp3;
 	query_vals[n_query_cols].type = DB1_INT;
 	query_vals[n_query_cols].nul = 0;
 	query_vals[n_query_cols].val.int_val= type;
 	n_query_cols++;
 
-	result_cols[xcap_doc_col= n_result_cols++] = &tmp4;
+	if (file_uri != NULL)
+	{
+		query_cols[n_query_cols] = &tmp2;
+		query_vals[n_query_cols].type = DB1_STR;
+		query_vals[n_query_cols].nul = 0;
+		query_vals[n_query_cols].val.str_val = *file_uri;
+		n_query_cols++;
+	}
+	else if (user != NULL && domain != NULL)
+	{
+		query_cols[n_query_cols] = &tmp3;
+		query_vals[n_query_cols].type = DB1_STR;
+		query_vals[n_query_cols].nul = 0;
+		query_vals[n_query_cols].val.str_val = *user;
+		n_query_cols++;
+	
+		query_cols[n_query_cols] = &tmp4;
+		query_vals[n_query_cols].type = DB1_STR;
+		query_vals[n_query_cols].nul = 0;
+		query_vals[n_query_cols].val.str_val = *domain;
+		n_query_cols++;
+	}
+	else
+	{
+		LM_ERR("Need to specify file uri _OR_ username and domain\n");
+		return -1;
+	}
+	
+	result_cols[xcap_doc_col= n_result_cols++] = &tmp5;
 	
 	if (pxml_dbf.use_table(pxml_db, &xcap_table) < 0) 
 	{
@@ -497,7 +520,12 @@ int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
 			"\t[domain]= %.*s\t[doc_type]= %d\n",user->len, user->s,
 			domain->len, domain->s, type);
 		
-		if(!integrated_xcap_server)
+		if (!integrated_xcap_server && type != PRES_RULES)
+		{
+			LM_WARN("Cannot retrieve non pres-rules documents from"
+				"external XCAP server\n");
+		}
+		else if(!integrated_xcap_server)
 		{
 			if(http_get_rules_doc(*user, *domain, &body)< 0)
 			{
@@ -548,7 +576,7 @@ done:
 	if(result)
 		pxml_dbf.free_result(pxml_db, result);
 
-	return 0;
+	return 1;
 
 error:
 	if(result)

+ 2 - 1
modules_k/presence_xml/xcap_auth.h

@@ -43,7 +43,8 @@
 int pres_watcher_allowed(subs_t* subs);
 
 xmlNodePtr get_rule_node(subs_t* subs, xmlDocPtr xcap_tree );
-int get_rules_doc(str* user, str* domain, int type, str** rules_doc);
+int get_rules_doc(str* user, str* domain, str *file_uri, int type, str** rules_doc);
 int pres_get_rules_doc(str* user, str* domain, str** rules_doc);
+int pres_get_pidf_doc(str *user, str *domain, str *file_uri, str **rules_doc);
 
 #endif