Skip to content

Commit

Permalink
pua: convert to PKG/SHM memory logging helper functions
Browse files Browse the repository at this point in the history
* remove trailing spaces
  • Loading branch information
linuxmaniac committed Jul 29, 2020
1 parent 7e5cc3a commit c91e852
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 327 deletions.
62 changes: 31 additions & 31 deletions src/modules/pua/add_events.c
Original file line number Diff line number Diff line change
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 All @@ -35,7 +35,7 @@ extern int dlginfo_increase_version;
int pua_add_events(void)
{
/* add presence */
if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml",
if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml",
pres_process_body)< 0)
{
LM_ERR("while adding event presence\n");
Expand Down Expand Up @@ -68,20 +68,20 @@ int pua_add_events(void)
}

/* add message-summary*/
if(add_pua_event(MSGSUM_EVENT, "message-summary",
if(add_pua_event(MSGSUM_EVENT, "message-summary",
"application/simple-message-summary", mwi_process_body)< 0)
{
LM_ERR("while adding event message-summary\n");
return -1;
}

/* add presence;winfo */
if(add_pua_event(PWINFO_EVENT, "presence.winfo", NULL, NULL)< 0)
{
LM_ERR("while adding event presence.winfo\n");
return -1;
}

/* add application/reginfo+xml */
if (dlginfo_increase_version) {
if(add_pua_event(REGINFO_EVENT, "reg", "application/reginfo+xml", reginfo_process_body)< 0) {
Expand All @@ -94,7 +94,7 @@ int pua_add_events(void)
return -1;
}
}

/* add xcap-diff */
if(add_pua_event(XCAPDIFF_EVENT, "xcap-diff",
"application/xcap-diff+xml", 0)< 0)
Expand All @@ -105,7 +105,7 @@ int pua_add_events(void)

return 0;

}
}

int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_param)
{
Expand Down Expand Up @@ -142,19 +142,19 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
{
tuple_id= buf;
tuple_id_len= sprintf(tuple_id, "%p", publ);
tuple_id[tuple_id_len]= '\0';
tuple_id[tuple_id_len]= '\0';

tuple=(str*)pkg_malloc(sizeof(str));
if(tuple== NULL)
{
LM_ERR("No more memory\n");
PKG_MEM_ERROR;
goto error;
}
alloc_tuple = 1;
tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char));
if(tuple->s== NULL)
{
LM_ERR("NO more memory\n");
PKG_MEM_ERROR;
goto error;
}
memcpy(tuple->s, tuple_id, tuple_id_len);
Expand Down Expand Up @@ -191,18 +191,18 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
xmlFree(tuple_id);
tuple_id= buf;
tuple_id_len= strlen(tuple_id);

tuple=(str*)pkg_malloc(sizeof(str));
if(tuple== NULL)
{
LM_ERR("No more memory\n");
PKG_MEM_ERROR;
goto error;
}
alloc_tuple= 1;
tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char));
if(tuple->s== NULL)
{
LM_ERR("NO more memory\n");
PKG_MEM_ERROR;
goto error;
}
memcpy(tuple->s, tuple_id, tuple_id_len);
Expand All @@ -217,7 +217,7 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
LM_DBG("found person node\n");
person_id= xmlNodeGetAttrContentByName(node, "id");
if(person_id== NULL)
{
{
if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
{
LM_ERR("while extracting xml"
Expand All @@ -229,23 +229,23 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
{
xmlFree(person_id);
}
}
}
body= (str*)pkg_malloc(sizeof(str));
if(body== NULL)
{
LM_ERR("NO more memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(body, 0, sizeof(str));
xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);
xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);
if(body->s== NULL || body->len== 0)
{
LM_ERR("while dumping xml format\n");
goto error;
}
}
xmlFreeDoc(doc);
doc= NULL;

*fin_body= body;
xmlMemoryDump();
xmlCleanupParser();
Expand All @@ -263,7 +263,7 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
}
return -1;

}
}

int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
{
Expand Down Expand Up @@ -295,20 +295,20 @@ int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL)
{
LM_ERR("while setting version attribute\n");
goto error;
goto error;
}
body= (str*)pkg_malloc(sizeof(str));
if(body== NULL)
{
LM_ERR("NO more memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(body, 0, sizeof(str));
xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);
xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);

xmlFreeDoc(doc);
doc= NULL;
*fin_body= body;
*fin_body= body;
if(*fin_body== NULL)
LM_DBG("NULL fin_body\n");

Expand All @@ -322,7 +322,7 @@ int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
xmlFreeDoc(doc);
if(body)
pkg_free(body);

xmlMemoryDump();
xmlCleanupParser();
return -1;
Expand Down Expand Up @@ -355,19 +355,19 @@ int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple

if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL) {
LM_ERR("while setting version attribute\n");
goto error;
goto error;
}
body= (str*)pkg_malloc(sizeof(str));
if(body== NULL) {
LM_ERR("NO more memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(body, 0, sizeof(str));
xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);
xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);

xmlFreeDoc(doc);
doc= NULL;
*fin_body= body;
*fin_body= body;
if(*fin_body== NULL)
LM_DBG("NULL fin_body\n");

Expand All @@ -381,7 +381,7 @@ int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple
xmlFreeDoc(doc);
if(body)
pkg_free(body);

xmlMemoryDump();
xmlCleanupParser();
return -1;
Expand Down
40 changes: 20 additions & 20 deletions src/modules/pua/event_list.c
Original file line number Diff line number Diff line change
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 All @@ -36,24 +36,24 @@ pua_event_t* init_pua_evlist(void)
list= (pua_event_t*)shm_malloc(sizeof(pua_event_t));
if(list== NULL)
{
LM_ERR("no more share memory\n");
SHM_MEM_ERROR;
return NULL;
}
list->next= NULL;

return list;

}

int add_pua_event(int ev_flag, char* name, char* content_type,
evs_process_body_t* process_body)
{

pua_event_t* event= NULL;
int size;
int name_len;
int ctype_len= 0;
str str_name;
str str_name;

name_len= strlen(name);
str_name.s= name;
Expand All @@ -72,23 +72,23 @@ int add_pua_event(int ev_flag, char* name, char* content_type,
event= (pua_event_t*)shm_malloc(size);
if(event== NULL)
{
LM_ERR("No more share memory\n");
SHM_MEM_ERROR;
return -1;
}
}
memset(event, 0, size);
size= sizeof(pua_event_t);

event->name.s= (char*)event+ size;
memcpy(event->name.s, name, name_len);
event->name.len= name_len;
size+= name_len;

if(content_type)
{
event->content_type.s= (char*)event+ size;
memcpy(event->content_type.s, content_type, ctype_len);
event->content_type.len= ctype_len;
size+= ctype_len;
size+= ctype_len;
}

event->process_body= process_body;
Expand All @@ -98,7 +98,7 @@ int add_pua_event(int ev_flag, char* name, char* content_type,
pua_evlist->next= event;

return 0;
}
}

pua_event_t* contains_pua_event(str* name)
{
Expand All @@ -110,12 +110,12 @@ pua_event_t* contains_pua_event(str* name)
if(event->name.len== name->len &&
strncmp(event->name.s, name->s, name->len)== 0)
{
return event;
return event;
}
event= event->next;
}
}

return NULL;
return NULL;
}

pua_event_t* get_event(int ev_flag)
Expand All @@ -127,11 +127,11 @@ pua_event_t* get_event(int ev_flag)
{
if(event->ev_flag== ev_flag)
{
return event;
return event;
}
event= event->next;
}
return NULL;
}
return NULL;
}


Expand All @@ -147,8 +147,8 @@ void destroy_pua_evlist(void)
e2= e1->next;
shm_free(e1);
e1= e2;
}
}
shm_free(pua_evlist);
}
}

}
}
Loading

0 comments on commit c91e852

Please sign in to comment.