diff --git a/src/modules/presence_conference/add_events.c b/src/modules/presence_conference/add_events.c index 09aa6abe4f8..fba07ba336d 100644 --- a/src/modules/presence_conference/add_events.c +++ b/src/modules/presence_conference/add_events.c @@ -33,32 +33,32 @@ int conference_add_events(void) { - pres_ev_t event; + pres_ev_t event; - /* constructing "conference" event and add it to the list of events packages supported */ - memset(&event, 0, sizeof(pres_ev_t)); - event.name.s = "conference"; - event.name.len = 10; + /* constructing "conference" event and add it to the list of events packages supported */ + memset(&event, 0, sizeof(pres_ev_t)); + event.name.s = "conference"; + event.name.len = 10; - event.content_type.s = "application/conference-info+xml"; - event.content_type.len = 31; + event.content_type.s = "application/conference-info+xml"; + event.content_type.len = 31; - event.default_expires = pres_conf_default_expires; - event.type = PUBL_TYPE; - event.req_auth = 0; - event.evs_publ_handl = 0; + event.default_expires = pres_conf_default_expires; + event.type = PUBL_TYPE; + event.req_auth = 0; + event.evs_publ_handl = 0; - /* aggregate XML body and free() function */ - event.agg_nbody = conf_agg_nbody; - event.free_body = free_xml_body; + /* aggregate XML body and free() function */ + event.agg_nbody = conf_agg_nbody; + event.free_body = free_xml_body; - /* modify XML body for each watcher to set the correct "version" */ - event.aux_body_processing = conf_body_setversion; + /* modify XML body for each watcher to set the correct "version" */ + event.aux_body_processing = conf_body_setversion; - if (pres_add_event(&event) < 0) { + if(pres_add_event(&event) < 0) { LM_ERR("failed to add event \"conference\"\n"); return -1; - } + } - return 0; + return 0; } diff --git a/src/modules/presence_conference/notify_body.c b/src/modules/presence_conference/notify_body.c index 594789a50e2..edc732ad926 100644 --- a/src/modules/presence_conference/notify_body.c +++ b/src/modules/presence_conference/notify_body.c @@ -42,89 +42,86 @@ #include "notify_body.h" #include "pidf.h" -str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, int off_index); +str *aggregate_xmls(str *pres_user, str *pres_domain, str **body_array, int n, + int off_index); -void free_xml_body(char* body) +void free_xml_body(char *body) { - if(body== NULL) + if(body == NULL) return; xmlFree(body); } -str* conf_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, int off_index) +str *conf_agg_nbody(str *pres_user, str *pres_domain, str **body_array, int n, + int off_index) { - str* n_body= NULL; + str *n_body = NULL; - LM_DBG("[pres_user]=%.*s [pres_domain]= %.*s, [n]=%d\n", - pres_user->len, pres_user->s, pres_domain->len, pres_domain->s, n); + LM_DBG("[pres_user]=%.*s [pres_domain]= %.*s, [n]=%d\n", pres_user->len, + pres_user->s, pres_domain->len, pres_domain->s, n); - if(body_array== NULL) + if(body_array == NULL) return NULL; n_body = aggregate_xmls(pres_user, pres_domain, body_array, n, off_index); LM_DBG("[n_body]=%p\n", n_body); if(n_body) { - LM_DBG("[*n_body]=%.*s\n", - n_body->len, n_body->s); + LM_DBG("[*n_body]=%.*s\n", n_body->len, n_body->s); } - if(n_body== NULL && n!= 0) - { + if(n_body == NULL && n != 0) { LM_ERR("while aggregating body\n"); } return n_body; } -str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, int off_index) +str *aggregate_xmls(str *pres_user, str *pres_domain, str **body_array, int n, + int off_index) { int i, j = 0; if(body_array == NULL || n == 0) return 0; - xmlDocPtr doc = NULL; + xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL; - xmlNsPtr namespace = NULL; + xmlNsPtr namespace = NULL; - xmlNodePtr p_root= NULL; - xmlDocPtr* xml_array = NULL ; + xmlNodePtr p_root = NULL; + xmlDocPtr *xml_array = NULL; xmlNodePtr node = NULL; - str *body= NULL; - char buf[MAX_URI_SIZE+1]; + str *body = NULL; + char buf[MAX_URI_SIZE + 1]; - LM_DBG("[pres_user]=%.*s [pres_domain]= %.*s, [n]=%d\n", - pres_user->len, pres_user->s, pres_domain->len, pres_domain->s, n); + LM_DBG("[pres_user]=%.*s [pres_domain]= %.*s, [n]=%d\n", pres_user->len, + pres_user->s, pres_domain->len, pres_domain->s, n); - xml_array = (xmlDocPtr*)pkg_malloc( n*sizeof(xmlDocPtr) ); - if(unlikely(xml_array == NULL)) - { + xml_array = (xmlDocPtr *)pkg_malloc(n * sizeof(xmlDocPtr)); + if(unlikely(xml_array == NULL)) { LM_ERR("while allocating memory"); return NULL; } - memset(xml_array, 0, n*sizeof(xmlDocPtr)) ; + memset(xml_array, 0, n * sizeof(xmlDocPtr)); /* parse all the XML documents */ - for(i=0; is, body_array[i]->len ); + xml_array[j] = xmlParseMemory(body_array[i]->s, body_array[i]->len); /* LM_DBG("parsing XML body: [n]=%d, [i]=%d, [j]=%d xml_array[j]=%p\n", n, i, j, xml_array[j] ); */ - if(unlikely(xml_array[j] == NULL)) - { + if(unlikely(xml_array[j] == NULL)) { LM_ERR("while parsing xml body message\n"); goto error; } j++; - } - if(j == 0) /* no body */ + if(j == 0) /* no body */ { pkg_free(xml_array); return NULL; @@ -136,14 +133,14 @@ str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, i /* LM_DBG("number of bodies in total [n]=%d, number of useful bodies [j]=%d\n", n, j ); */ /* create the new NOTIFY body */ - if ( (pres_user->len + pres_domain->len + 1) > MAX_URI_SIZE ) { + if((pres_user->len + pres_domain->len + 1) > MAX_URI_SIZE) { LM_ERR("entity URI too long, maximum=%d\n", MAX_URI_SIZE); goto error; } memcpy(buf, pres_user->s, pres_user->len); buf[pres_user->len] = '@'; memcpy(buf + pres_user->len + 1, pres_domain->s, pres_domain->len); - buf[pres_user->len + 1 + pres_domain->len]= '\0'; + buf[pres_user->len + 1 + pres_domain->len] = '\0'; doc = xmlNewDoc(BAD_CAST "1.0"); if(unlikely(doc == NULL)) @@ -154,8 +151,9 @@ str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, i goto error; xmlDocSetRootElement(doc, root_node); - namespace = xmlNewNs(root_node, BAD_CAST "urn:ietf:params:xml:ns:conference-info", NULL); - if (unlikely(namespace == NULL)) { + namespace = xmlNewNs( + root_node, BAD_CAST "urn:ietf:params:xml:ns:conference-info", NULL); + if(unlikely(namespace == NULL)) { LM_ERR("creating namespace failed\n"); goto error; } @@ -165,30 +163,29 @@ str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, i depending on the subscription for which the notify is being sent. */ xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "0"); - xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "full" ); + xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "full"); xmlNewProp(root_node, BAD_CAST "entity", BAD_CAST buf); /* loop over all bodies and create the aggregated body */ - for(i=0; iname, BAD_CAST "conference-info") != 0)) - { + if(unlikely(xmlStrcasecmp(p_root->name, BAD_CAST "conference-info") + != 0)) { LM_ERR("root element is not \"conference-info\"\n"); goto error; } /* the root "conference-info" element should always have children */ - if (p_root->children) { - for (node = p_root->children; node != NULL; node = node->next) { - if(xmlAddChild(root_node, xmlCopyNode(node, 1)) == NULL) { - LM_ERR("while adding child\n"); - goto error; - } + if(p_root->children) { + for(node = p_root->children; node != NULL; node = node->next) { + if(xmlAddChild(root_node, xmlCopyNode(node, 1)) == NULL) { + LM_ERR("while adding child\n"); + goto error; + } } } /* we only take the most recent subscription as @@ -198,33 +195,29 @@ str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, i break; } - body = (str*)pkg_malloc(sizeof(str)); + body = (str *)pkg_malloc(sizeof(str)); if(body == NULL) { ERR_MEM(PKG_MEM_STR); } - xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, - &body->len, 1); + xmlDocDumpFormatMemory(doc, (xmlChar **)(void *)&body->s, &body->len, 1); - for(i=0; iversion); - if (!body) { + if(!body) { return NULL; } @@ -253,8 +247,7 @@ str *conf_body_setversion(subs_t *subs, str *body) { if(!xmlSetProp(conf_info, BAD_CAST "version", BAD_CAST version_str)) { goto error; } - xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, - &body->len, 1); + xmlDocDumpFormatMemory(doc, (xmlChar **)(void *)&body->s, &body->len, 1); return NULL; error: LM_ERR("error in presence_conference conf_body_setversion\n"); diff --git a/src/modules/presence_conference/notify_body.h b/src/modules/presence_conference/notify_body.h index ca9d2adfadc..4926dbe7109 100644 --- a/src/modules/presence_conference/notify_body.h +++ b/src/modules/presence_conference/notify_body.h @@ -29,9 +29,9 @@ #ifndef _CONF_NBODY_H_ #define _CONF_NBODY_H_ -str* conf_agg_nbody(str* pres_user, str* pres_domain, str** body_array, - int n, int off_index); -str* conf_body_setversion(subs_t *subs, str* body); -void free_xml_body(char* body); +str *conf_agg_nbody(str *pres_user, str *pres_domain, str **body_array, int n, + int off_index); +str *conf_body_setversion(subs_t *subs, str *body); +void free_xml_body(char *body); #endif diff --git a/src/modules/presence_conference/pidf.c b/src/modules/presence_conference/pidf.c index ce4c39bc8fe..e22a31263e8 100644 --- a/src/modules/presence_conference/pidf.c +++ b/src/modules/presence_conference/pidf.c @@ -31,17 +31,18 @@ * use 600 for 'Single UNIX Specification, Version 3' */ #ifdef __OS_linux - #define _XOPEN_SOURCE 600 /* glibc2 on linux */ - #define _BSD_SOURCE 1 /* needed on linux to "fix" the effect +#define _XOPEN_SOURCE 600 /* glibc2 on linux */ +#define _BSD_SOURCE \ + 1 /* needed on linux to "fix" the effect of the above define on features.h/unistd.h syscall() */ - #define _DEFAULT_SOURCE 1 /* _BSD_SOURCE is deprecated */ +#define _DEFAULT_SOURCE 1 /* _BSD_SOURCE is deprecated */ #endif #ifdef __OS_darwin - #define _DARWIN_C_SOURCE 1 +#define _DARWIN_C_SOURCE 1 #endif #ifdef __OS_solaris - #define _XOPEN_SOURCE_EXTENDED 1 +#define _XOPEN_SOURCE_EXTENDED 1 #endif #include @@ -55,8 +56,8 @@ xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name) { xmlAttrPtr attr = node->properties; - while (attr) { - if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0) + while(attr) { + if(xmlStrcasecmp(attr->name, (unsigned char *)name) == 0) return attr; attr = attr->next; } @@ -66,8 +67,8 @@ xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name) char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name) { xmlAttrPtr attr = xmlNodeGetAttrByName(node, name); - if (attr) - return (char*)xmlNodeGetContent(attr->children); + if(attr) + return (char *)xmlNodeGetContent(attr->children); else return NULL; } @@ -75,38 +76,42 @@ char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name) xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name) { xmlNodePtr cur = node->children; - while (cur) { - if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) + while(cur) { + if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0) return cur; cur = cur->next; } return NULL; } -xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name, const char *ns) +xmlNodePtr xmlNodeGetNodeByName( + xmlNodePtr node, const char *name, const char *ns) { xmlNodePtr cur = node; - while (cur) { + while(cur) { xmlNodePtr match = NULL; - if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) { - if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix, - (unsigned char*)ns) == 0)) + if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0) { + if(!ns + || (cur->ns + && xmlStrcasecmp( + cur->ns->prefix, (unsigned char *)ns) + == 0)) return cur; } match = xmlNodeGetNodeByName(cur->children, name, ns); - if (match) + if(match) return match; cur = cur->next; } return NULL; } -char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name, - const char *ns) +char *xmlNodeGetNodeContentByName( + xmlNodePtr root, const char *name, const char *ns) { xmlNodePtr node = xmlNodeGetNodeByName(root, name, ns); - if (node) - return (char*)xmlNodeGetContent(node->children); + if(node) + return (char *)xmlNodeGetContent(node->children); else return NULL; } @@ -117,65 +122,60 @@ xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns) return xmlNodeGetNodeByName(cur, name, ns); } -char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name, - const char *ns) +char *xmlDocGetNodeContentByName( + xmlDocPtr doc, const char *name, const char *ns) { xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns); - if (node) - return (char*)xmlNodeGetContent(node->children); + if(node) + return (char *)xmlNodeGetContent(node->children); else return NULL; } -time_t xml_parse_dateTime(char* xml_time_str) +time_t xml_parse_dateTime(char *xml_time_str) { struct tm tm; - char * p; + char *p; int h, m; char h1, h2, m1, m2; - int sign= 1; - signed int timezone_diff= 0; + int sign = 1; + signed int timezone_diff = 0; - p= strptime(xml_time_str, "%F", &tm); - if(p== NULL) - { + p = strptime(xml_time_str, "%F", &tm); + if(p == NULL) { printf("error: failed to parse time\n"); return 0; } p++; - p= strptime(p, "%T", &tm); - if(p== NULL) - { + p = strptime(p, "%T", &tm); + if(p == NULL) { printf("error: failed to parse time\n"); return 0; } - if(*p== '\0') + if(*p == '\0') goto done; - if(*p== '.') - { + if(*p == '.') { p++; /* read the fractionar part of the seconds*/ - while(*p!= '\0' && *p>= '0' && *p<= '9') - { + while(*p != '\0' && *p >= '0' && *p <= '9') { p++; } } - if(*p== '\0') + if(*p == '\0') goto done; /* read time zone */ - if(*p== 'Z') - { + if(*p == 'Z') { goto done; } - if(*p== '+') - sign= -1; + if(*p == '+') + sign = -1; p++; @@ -184,13 +184,11 @@ time_t xml_parse_dateTime(char* xml_time_str) return 0; } - h= (h1- '0')*10+ h2- '0'; - m= (m1- '0')*10+ m2- '0'; + h = (h1 - '0') * 10 + h2 - '0'; + m = (m1 - '0') * 10 + m2 - '0'; - timezone_diff= sign* ((m+ h* 60)* 60); + timezone_diff = sign * ((m + h * 60) * 60); done: return (mktime(&tm) + timezone_diff); } - - diff --git a/src/modules/presence_conference/pidf.h b/src/modules/presence_conference/pidf.h index e555d90a4a7..aef810e919f 100644 --- a/src/modules/presence_conference/pidf.h +++ b/src/modules/presence_conference/pidf.h @@ -34,15 +34,15 @@ #include "../../core/str.h" #include -xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name, - const char *ns); +xmlNodePtr xmlNodeGetNodeByName( + xmlNodePtr node, const char *name, const char *ns); xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns); xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name); -char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name, - const char *ns); +char *xmlNodeGetNodeContentByName( + xmlNodePtr root, const char *name, const char *ns); char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name); -time_t xml_parse_dateTime(char* xml_time_str); +time_t xml_parse_dateTime(char *xml_time_str); -#endif +#endif diff --git a/src/modules/presence_conference/presence_conference.c b/src/modules/presence_conference/presence_conference.c index ea9d3c133cf..ebb6f115bac 100644 --- a/src/modules/presence_conference/presence_conference.c +++ b/src/modules/presence_conference/presence_conference.c @@ -52,33 +52,28 @@ int use_partial_states = 0; unsigned int pres_conf_default_expires = 3600; /* module exported commands */ -static cmd_export_t cmds[] = -{ - {0, 0, 0, 0, 0, 0} -}; +static cmd_export_t cmds[] = {{0, 0, 0, 0, 0, 0}}; /* module exported parameters */ static param_export_t params[] = { - { "use_partial_states", INT_PARAM, &use_partial_states }, - { "default_expires", INT_PARAM, &pres_conf_default_expires }, - {0, 0, 0} -}; + {"use_partial_states", INT_PARAM, &use_partial_states}, + {"default_expires", INT_PARAM, &pres_conf_default_expires}, {0, 0, 0}}; /* presence api bind structure */ presence_api_t pres; /* module exports */ -struct module_exports exports= { - "presence_conference", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* exported functions */ - params, /* exported parameters */ - 0, /* RPC method exports */ - 0, /* exported pseudo-variables */ - 0, /* response handling function */ - mod_init, /* module initialization function */ - 0, /* per-child init function */ - 0 /* module destroy function */ +struct module_exports exports = { + "presence_conference", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* exported functions */ + params, /* exported parameters */ + 0, /* RPC method exports */ + 0, /* exported pseudo-variables */ + 0, /* response handling function */ + mod_init, /* module initialization function */ + 0, /* per-child init function */ + 0 /* module destroy function */ }; /* @@ -88,18 +83,18 @@ static int mod_init(void) { bind_presence_t bind_presence; - bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); - if (!bind_presence) { + bind_presence = (bind_presence_t)find_export("bind_presence", 1, 0); + if(!bind_presence) { LM_ERR("cannot find bind_presence\n"); return -1; } - if (bind_presence(&pres) < 0) { + if(bind_presence(&pres) < 0) { LM_ERR("cannot bind to presence module\n"); return -1; } pres_add_event = pres.add_event; - if (pres_add_event == NULL) { + if(pres_add_event == NULL) { LM_ERR("could not import add_event function\n"); return -1; } @@ -108,5 +103,5 @@ static int mod_init(void) return -1; } - return 0; + return 0; }