Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

presence_xml: add optional param force_dummy_presence #387

Merged
merged 1 commit into from
Nov 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions modules/presence_xml/README
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Anca-Maria Vamanu
3.8. xcap_server (str)
3.9. passive_mode(int)
3.10. xcapauth_userdel_reason(str)
3.11. force_dummy_presence(int)

4. Functions

Expand All @@ -56,8 +57,9 @@ Anca-Maria Vamanu
1.8. Set xcap_server parameter
1.9. Set passive_mode parameter
1.10. Set xcapauth_userdel_reason parameter
1.11. pres_check_basic usage
1.12. pres_check_activities usage
1.11. Set force_dummy_presence parameter
1.12. pres_check_basic usage
1.13. pres_check_activities usage

Chapter 1. Admin Guide

Expand All @@ -81,6 +83,7 @@ Chapter 1. Admin Guide
3.8. xcap_server (str)
3.9. passive_mode(int)
3.10. xcapauth_userdel_reason(str)
3.11. force_dummy_presence(int)

4. Functions

Expand Down Expand Up @@ -139,6 +142,7 @@ Chapter 1. Admin Guide
3.8. xcap_server (str)
3.9. passive_mode(int)
3.10. xcapauth_userdel_reason(str)
3.11. force_dummy_presence(int)

3.1. db_url(str)

Expand Down Expand Up @@ -284,12 +288,24 @@ modparam("presence_xml", "xcapauth_userdel_reason", "probation;retry-after=30")
modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
...

3.11. force_dummy_presence(int)

Set this parameter to enable simple body notify with status 'open' when
presentity info is not available.

Default value: "0".

Example 1.11. Set force_dummy_presence parameter
...
modparam("presence_xml", "force_dummy_presence", 1)
...

4. Functions

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.
Expand All @@ -300,7 +316,7 @@ modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
* 1 - if a match is found.
* -1 - if a match is not found.

Example 1.11. pres_check_basic usage
Example 1.12. pres_check_basic usage
...
if (pres_check_basic("$ru", "open")) {
...
Expand All @@ -312,7 +328,7 @@ modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
}
...

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.
Expand All @@ -324,7 +340,7 @@ modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
* -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.13. pres_check_activities usage
...
if (pres_check_basic("$ru", "open")) {
pres_check_activities("$ru", "unknown");
Expand Down
18 changes: 18 additions & 0 deletions modules/presence_xml/doc/presence_xml_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
</programlisting>
</example>
</section>
<section>
<title><varname>force_dummy_presence</varname>(int)</title>
<para>
Set this parameter to enable simple body notify with status 'open' when presentity info is not available.
</para>
<para>
<emphasis>Default value: <quote>0</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>force_dummy_presence</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence_xml", "force_dummy_presence", 1)
...
</programlisting>
</example>
</section>
</section>


Expand Down
51 changes: 50 additions & 1 deletion modules/presence_xml/notify_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "notify_body.h"
#include "presence_xml.h"

extern int force_dummy_presence;

str* offline_nbody(str* body);
str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n);
str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node);
Expand All @@ -56,15 +58,62 @@ void free_xml_body(char* body)
body= NULL;
}

#define PRESENCE_EMPTY_BODY_SIZE 512

#define PRESENCE_EMPTY_BODY "<presence> \
<tuple id=\"615293b33c62dec073e05d9421e9f48b\">\
<status>\
<basic>open</basic>\
</status>\
</tuple>\
<note xmlns=\"urn:ietf:params:xml:ns:pidf\">Available</note>\
</presence>"

str* pres_agg_nbody_empty(str* pres_user, str* pres_domain)
{
str* n_body= NULL;

LM_DBG("creating empty presence for [pres_user]=%.*s [pres_domain]= %.*s\n",
pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);

str* body_array = (str*)pkg_malloc(sizeof(str));
char* body = (char*)pkg_malloc(PRESENCE_EMPTY_BODY_SIZE);
sprintf(body, PRESENCE_EMPTY_BODY);
body_array->s = body;
body_array->len = strlen(body);


n_body= agregate_xmls(pres_user, pres_domain, &body_array, 1);
LM_DBG("[n_body]=%p\n", n_body);
if(n_body) {
LM_DBG("[*n_body]=%.*s\n",n_body->len, n_body->s);
}
if(n_body== NULL)
{
LM_ERR("while aggregating body\n");
}

pkg_free(body);
pkg_free(body_array);


xmlCleanupParser();
xmlMemoryDump();

return n_body;
}

str* pres_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, int off_index)
{
str* n_body= NULL;
str* body= NULL;

if(body_array== NULL)
if(body_array== NULL && (!force_dummy_presence))
return NULL;

if(body_array== NULL)
return pres_agg_nbody_empty(pres_user, pres_domain);

if(off_index>= 0)
{
body= body_array[off_index];
Expand Down
2 changes: 2 additions & 0 deletions modules/presence_xml/presence_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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 force_dummy_presence = 0;
int integrated_xcap_server= 0;
xcap_serv_t* xs_list= NULL;
int disable_presence = 0;
Expand Down Expand Up @@ -130,6 +131,7 @@ static param_export_t params[]={
{ "disable_xcapdiff", INT_PARAM, &disable_xcapdiff },
{ "passive_mode", INT_PARAM, &passive_mode },
{ "xcapauth_userdel_reason", PARAM_STR, &xcapauth_userdel_reason},
{ "force_dummy_presence", INT_PARAM, &force_dummy_presence },
{ 0, 0, 0}
};

Expand Down