Skip to content

Commit

Permalink
presence_conference: clang-format for coherent indentation and coding…
Browse files Browse the repository at this point in the history
… style
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 197f64f commit 33a2c8c
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 170 deletions.
38 changes: 19 additions & 19 deletions src/modules/presence_conference/add_events.c
Expand Up @@ -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;
}
127 changes: 60 additions & 67 deletions src/modules/presence_conference/notify_body.c
Expand Up @@ -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; i<n; i++)
{
if(body_array[i] == NULL )
for(i = 0; i < n; i++) {
if(body_array[i] == NULL)
continue;

xml_array[j] = xmlParseMemory( body_array[i]->s, 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;
Expand All @@ -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))
Expand All @@ -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;
}
Expand All @@ -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; i<j; i++)
{
p_root= xmlDocGetRootElement(xml_array[i]);
for(i = 0; i < j; i++) {
p_root = xmlDocGetRootElement(xml_array[i]);
if(unlikely(p_root == NULL)) {
LM_ERR("while getting the xml_tree root element\n");
goto error;
}
/* just checking that the root element is "conference-info" as it should RFC4575 */
if(unlikely(xmlStrcasecmp(p_root->name, 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
Expand All @@ -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; i<j; i++)
{
if(xml_array[i]!=NULL)
for(i = 0; i < j; i++) {
if(xml_array[i] != NULL)
xmlFreeDoc(xml_array[i]);
}
if (doc)
if(doc)
xmlFreeDoc(doc);
if(xml_array!=NULL)
if(xml_array != NULL)
pkg_free(xml_array);

return body;

error:
LM_ERR("error in presence_conference agg_nbody\n");
if(xml_array!=NULL)
{
for(i=0; i<j; i++)
{
if(xml_array[i]!=NULL)
if(xml_array != NULL) {
for(i = 0; i < j; i++) {
if(xml_array[i] != NULL)
xmlFreeDoc(xml_array[i]);
}
pkg_free(xml_array);
Expand All @@ -235,10 +228,11 @@ str* aggregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, i
return NULL;
}

str *conf_body_setversion(subs_t *subs, str *body) {
char version_str[MAX_INT_LEN + 2];//for the null terminating character \0
str *conf_body_setversion(subs_t *subs, str *body)
{
char version_str[MAX_INT_LEN + 2]; //for the null terminating character \0
snprintf(version_str, MAX_INT_LEN, "%d", subs->version);
if (!body) {
if(!body) {
return NULL;
}

Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/modules/presence_conference/notify_body.h
Expand Up @@ -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

0 comments on commit 33a2c8c

Please sign in to comment.