Skip to content

Commit

Permalink
presence_xml: use presence api via structure instead of declaring loc…
Browse files Browse the repository at this point in the history
…al function variables

- simpler overall and clearer when function is local in module or imported via
api, given that same prefix was used
  • Loading branch information
miconda committed Apr 15, 2020
1 parent 498d764 commit 3b2a84e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 70 deletions.
8 changes: 4 additions & 4 deletions src/modules/presence_xml/add_events.c
Expand Up @@ -68,7 +68,7 @@ int xml_add_events(void)
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) {
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event presence\n");
return -1;
}
Expand All @@ -87,7 +87,7 @@ int xml_add_events(void)
event.free_body = free_xml_body;
event.default_expires = 3600;

if(pres_add_event(&event) < 0) {
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event presence.winfo\n");
return -1;
}
Expand All @@ -107,7 +107,7 @@ int xml_add_events(void)
event.type = PUBL_TYPE;
event.free_body = free_xml_body;
event.default_expires = 3600;
if(pres_add_event(&event) < 0) {
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event dialog;sla\n");
return -1;
}
Expand All @@ -125,7 +125,7 @@ int xml_add_events(void)

event.type = PUBL_TYPE;
event.default_expires = 3600;
if(pres_add_event(&event) < 0) {
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event xcap-diff\n");
return -1;
}
Expand Down
14 changes: 9 additions & 5 deletions src/modules/presence_xml/notify_body.c
@@ -1,5 +1,5 @@
/*
* presence_xml module -
* presence_xml module
*
* Copyright (C) 2006 Voice Sistem S.R.L.
*
Expand All @@ -15,8 +15,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand Down Expand Up @@ -62,14 +62,18 @@ void free_xml_body(char *body)

#define PRESENCE_EMPTY_BODY \
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" xmlns:c=\"urn:ietf:params:xml:ns:pidf:cipid\" entity=\"%.*s\"> \
<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\
xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\"\
xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\"\
xmlns:c=\"urn:ietf:params:xml:ns:pidf:cipid\" entity=\"%.*s\"> \
<tuple xmlns=\"urn:ietf:params:xml:ns:pidf\" id=\"615293b33c62dec073e05d9421e9f48b\">\
<status>\
<basic>open</basic>\
</status>\
</tuple>\
<note xmlns=\"urn:ietf:params:xml:ns:pidf\">Available</note>\
<dm:person xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" id=\"1\">\
<dm:person xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\"\
xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" id=\"1\">\
<rpid:activities/>\
<dm:note>Available</dm:note>\
</dm:person>\
Expand Down
4 changes: 2 additions & 2 deletions src/modules/presence_xml/pidf.c
Expand Up @@ -15,8 +15,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand Down
21 changes: 11 additions & 10 deletions src/modules/presence_xml/pres_check.c
Expand Up @@ -13,21 +13,22 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


#include <stdio.h>
#include <libxml/parser.h>

#include "pres_check.h"
#include "pidf.h"
#include "../../core/parser/msg_parser.h"
#include "../../core/parser/parse_uri.h"
#include "../../core/str.h"
#include "../presence/event_list.h"
#include "pres_check.h"
#include "pidf.h"
#include "presence_xml.h"

int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
{
Expand All @@ -45,13 +46,13 @@ int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
return -1;
}

ev = pres_contains_event(&event, NULL);
ev = psapi.contains_event(&event, NULL);
if(ev == NULL) {
LM_ERR("event presence is not registered\n");
return -1;
}

presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
presentity = psapi.get_presentity(presentity_uri, ev, NULL, NULL);

if(presentity == NULL || presentity->len <= 0 || presentity->s == NULL) {
LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len,
Expand Down Expand Up @@ -92,7 +93,7 @@ int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
error:
if(xmlDoc != NULL)
xmlFreeDoc(xmlDoc);
pres_free_presentity(presentity, ev);
psapi.free_presentity(presentity, ev);
return retval;
}

Expand All @@ -113,7 +114,7 @@ int presxml_check_activities(
return -1;
}

ev = pres_contains_event(&event, NULL);
ev = psapi.contains_event(&event, NULL);
if(ev == NULL) {
LM_ERR("event presence is not registered\n");
return -1;
Expand All @@ -126,7 +127,7 @@ int presxml_check_activities(
memcpy(nodeName, activity.s, activity.len);
nodeName[activity.len] = '\0';

presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
presentity = psapi.get_presentity(presentity_uri, ev, NULL, NULL);

if(presentity == NULL || presentity->len <= 0 || presentity->s == NULL) {
LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len,
Expand Down Expand Up @@ -179,6 +180,6 @@ int presxml_check_activities(
if(xmlDoc != NULL)
xmlFreeDoc(xmlDoc);
if(presentity != NULL)
pres_free_presentity(presentity, ev);
psapi.free_presentity(presentity, ev);
return retval;
}
10 changes: 3 additions & 7 deletions src/modules/presence_xml/pres_check.h
Expand Up @@ -22,16 +22,12 @@
#ifndef _PRES_CHECK_H_
#define _PRES_CHECK_H_


#include <stdio.h>
#include "../../core/parser/msg_parser.h"
#include "../presence/bind_presence.h"
#include "../presence/event_list.h"

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);
extern contains_event_t pres_contains_event;
extern pres_get_presentity_t pres_get_presentity;
extern pres_free_presentity_t pres_free_presentity;
int presxml_check_basic(sip_msg_t *msg, str presentity_uri, str status);
int presxml_check_activities(sip_msg_t *msg, str presentity_uri, str activity);

#endif
38 changes: 10 additions & 28 deletions src/modules/presence_xml/presence_xml.c
Expand Up @@ -26,7 +26,8 @@
*/

/*!
* \defgroup presence_xml Presence_xml :: This module implements a range of XML-based SIP event packages for presence
* \defgroup presence_xml Presence_xml :: This module implements a range
* of XML-based SIP event packages for presence
*/


Expand Down Expand Up @@ -76,13 +77,7 @@ static int w_presxml_check_activities(
sip_msg_t *msg, char *presentity_uri, char *activities);

/** module variables ***/
add_event_t pres_add_event;
update_watchers_t pres_update_watchers;
pres_get_sphere_t pres_get_sphere;

contains_event_t pres_contains_event;
pres_get_presentity_t pres_get_presentity;
pres_free_presentity_t pres_free_presentity;
presence_api_t psapi = {0};

/* Module parameter variables */
str xcap_table = str_init("xcap");
Expand Down Expand Up @@ -167,11 +162,9 @@ struct module_exports exports= {
*/
static int mod_init(void)
{
bind_presence_t bind_presence;
presence_api_t pres;

if(passive_mode == 1)
if(passive_mode == 1) {
return 0;
}

LM_DBG("db_url=%s (len=%d addr=%p)\n", ZSW(presxml_db_url.s),
presxml_db_url.len, presxml_db_url.s);
Expand All @@ -182,24 +175,13 @@ static int mod_init(void)
return -1;
}

bind_presence = (bind_presence_t)find_export("bind_presence", 1, 0);
if(!bind_presence) {
LM_ERR("Can't bind presence\n");
return -1;
}
if(bind_presence(&pres) < 0) {
LM_ERR("Can't bind to presence module\n");
if(presence_load_api(&psapi) != 0) {
LM_ERR("cannot bind to presence api\n");
return -1;
}

pres_get_sphere = pres.get_sphere;
pres_add_event = pres.add_event;
pres_update_watchers = pres.update_watchers_status;
pres_contains_event = pres.contains_event;
pres_get_presentity = pres.get_presentity;
pres_free_presentity = pres.free_presentity;
if(pres_add_event == NULL || pres_update_watchers == NULL) {
LM_ERR("Can't import add_event\n");
if(psapi.add_event == NULL || psapi.update_watchers_status == NULL) {
LM_ERR("requited presence api not available\n");
return -1;
}
if(xml_add_events() < 0) {
Expand Down Expand Up @@ -448,7 +430,7 @@ static int xcap_doc_updated(int doc_type, str xid, char *doc)
rules_doc.s = doc;
rules_doc.len = strlen(doc);

if(pres_update_watchers(&xid, &ev, &rules_doc) < 0) {
if(psapi.update_watchers_status(&xid, &ev, &rules_doc) < 0) {
LM_ERR("updating watchers in presence\n");
return -1;
}
Expand Down
10 changes: 4 additions & 6 deletions src/modules/presence_xml/presence_xml.h
Expand Up @@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand All @@ -31,8 +31,7 @@

#include "../../lib/srdb1/db.h"
#include "../../modules/sl/sl.h"
#include "../presence/event_list.h"
#include "../presence/presentity.h"
#include "../presence/bind_presence.h"
#include "../xcap_client/xcap_functions.h"

typedef struct xcap_serv
Expand All @@ -43,16 +42,15 @@ typedef struct xcap_serv
} xcap_serv_t;

extern sl_api_t slb;
extern presence_api_t psapi;

extern str xcap_table;
extern add_event_t pres_add_event;
extern db1_con_t *pxml_db;
extern db_func_t pxml_dbf;
extern int force_active;
extern int pidf_manipulation;
extern int integrated_xcap_server;
extern xcap_serv_t *xs_list;
extern xcapGetNewDoc_t xcap_GetNewDoc;
extern pres_get_sphere_t pres_get_sphere;

#endif
10 changes: 5 additions & 5 deletions src/modules/presence_xml/xcap_auth.c
@@ -1,5 +1,5 @@
/*
* presence_xml module -
* presence_xml module
*
* Copyright (C) 2007 Voice Sistem S.R.L.
*
Expand All @@ -15,8 +15,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand Down Expand Up @@ -240,7 +240,7 @@ xmlNodePtr get_rule_node(subs_t *subs, xmlDocPtr xcap_tree)
/* check to see if matches presentity current sphere */
/* ask presence for sphere information */

char *sphere = pres_get_sphere(&subs->pres_uri);
char *sphere = psapi.get_sphere(&subs->pres_uri);
if(sphere) {
char *attr = (char *)xmlNodeGetContent(sphere_node);
if(xmlStrcasecmp((unsigned char *)attr, (unsigned char *)sphere)
Expand All @@ -254,7 +254,7 @@ xmlNodePtr get_rule_node(subs_t *subs, xmlDocPtr xcap_tree)
xmlFree(attr);
}

/* if the user has not define a sphere ->
/* if the user has not define a sphere ->
* consider the condition true*/
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/presence_xml/xcap_auth.h
@@ -1,5 +1,5 @@
/*
* presence_xml module -
* presence_xml module
*
* Copyright (C) 2006 Voice Sistem S.R.L.
*
Expand All @@ -15,8 +15,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand Down

0 comments on commit 3b2a84e

Please sign in to comment.