diff --git a/src/modules/pua/add_events.c b/src/modules/pua/add_events.c index 5c0e73b70f5..e2fc78be3ee 100644 --- a/src/modules/pua/add_events.c +++ b/src/modules/pua/add_events.c @@ -36,24 +36,24 @@ int pua_add_events(void) { /* add presence */ if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml", - pres_process_body)< 0) - { + pres_process_body) + < 0) { LM_ERR("while adding event presence\n"); return -1; } /* add dialog */ - if (dlginfo_increase_version) { + if(dlginfo_increase_version) { if(add_pua_event(DIALOG_EVENT, "dialog", "application/dialog-info+xml", - bla_process_body)< 0) - { + bla_process_body) + < 0) { LM_ERR("while adding event dialog w/ dlginfo_increase_version\n"); return -1; } } else { if(add_pua_event(DIALOG_EVENT, "dialog", "application/dialog-info+xml", - dlg_process_body)< 0) - { + dlg_process_body) + < 0) { LM_ERR("while adding event dialog w/o dlginfo_increase_version\n"); return -1; } @@ -61,192 +61,176 @@ int pua_add_events(void) /* add dialog;sla */ if(add_pua_event(BLA_EVENT, "dialog;sla", "application/dialog-info+xml", - bla_process_body)< 0) - { + bla_process_body) + < 0) { LM_ERR("while adding event dialog;sla\n"); return -1; } /* add message-summary*/ if(add_pua_event(MSGSUM_EVENT, "message-summary", - "application/simple-message-summary", mwi_process_body)< 0) - { + "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) - { + 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) { - LM_ERR("while adding event application/reginfo+xml with version increase\n"); + if(dlginfo_increase_version) { + if(add_pua_event(REGINFO_EVENT, "reg", "application/reginfo+xml", + reginfo_process_body) + < 0) { + LM_ERR("while adding event application/reginfo+xml with version " + "increase\n"); return -1; } } else { - if(add_pua_event(REGINFO_EVENT, "reg", "application/reginfo+xml", dlg_process_body)< 0) { + if(add_pua_event(REGINFO_EVENT, "reg", "application/reginfo+xml", + dlg_process_body) + < 0) { LM_ERR("while adding event application/reginfo+xml\n"); return -1; } } /* add xcap-diff */ - if(add_pua_event(XCAPDIFF_EVENT, "xcap-diff", - "application/xcap-diff+xml", 0)< 0) - { + if(add_pua_event( + XCAPDIFF_EVENT, "xcap-diff", "application/xcap-diff+xml", 0) + < 0) { LM_ERR("while adding event xcap-diff\n"); return -1; } return 0; - } -int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_param) +int pres_process_body( + publ_info_t *publ, str **fin_body, int ver, str **tuple_param) { - xmlDocPtr doc= NULL; - xmlNodePtr node= NULL; - char* tuple_id= NULL, *person_id= NULL; - int tuple_id_len= 0; + xmlDocPtr doc = NULL; + xmlNodePtr node = NULL; + char *tuple_id = NULL, *person_id = NULL; + int tuple_id_len = 0; char buf[50]; - str* body= NULL; - int alloc_tuple= 0; - str* tuple= NULL; + str *body = NULL; + int alloc_tuple = 0; + str *tuple = NULL; - doc= xmlParseMemory(publ->body->s, publ->body->len ); - if(doc== NULL) - { + doc = xmlParseMemory(publ->body->s, publ->body->len); + if(doc == NULL) { LM_ERR("while parsing xml memory\n"); goto error; } - node= xmlDocGetNodeByName(doc, "tuple", NULL); - if(node == NULL) - { + node = xmlDocGetNodeByName(doc, "tuple", NULL); + if(node == NULL) { LM_ERR("while extracting tuple node\n"); goto error; } - tuple= *(tuple_param); + tuple = *(tuple_param); - tuple_id= xmlNodeGetAttrContentByName(node, "id"); - if(tuple_id== NULL) - { + tuple_id = xmlNodeGetAttrContentByName(node, "id"); + if(tuple_id == NULL) { - if(tuple== NULL) // generate a tuple_id + if(tuple == NULL) // generate a tuple_id { - tuple_id= buf; - tuple_id_len= sprintf(tuple_id, "%p", publ); - tuple_id[tuple_id_len]= '\0'; + tuple_id = buf; + tuple_id_len = sprintf(tuple_id, "%p", publ); + tuple_id[tuple_id_len] = '\0'; - tuple=(str*)pkg_malloc(sizeof(str)); - if(tuple== NULL) - { + tuple = (str *)pkg_malloc(sizeof(str)); + if(tuple == NULL) { PKG_MEM_ERROR; goto error; } alloc_tuple = 1; - tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char)); - if(tuple->s== NULL) - { + tuple->s = (char *)pkg_malloc(tuple_id_len * sizeof(char)); + if(tuple->s == NULL) { PKG_MEM_ERROR; goto error; } memcpy(tuple->s, tuple_id, tuple_id_len); - tuple->len= tuple_id_len; + tuple->len = tuple_id_len; - *tuple_param= tuple; + *tuple_param = tuple; LM_DBG("allocated tuple_id\n\n"); - } - else - { - tuple_id= buf; - tuple_id_len= tuple->len; + } else { + tuple_id = buf; + tuple_id_len = tuple->len; memcpy(tuple_id, tuple->s, tuple_id_len); - tuple_id[tuple_id_len]= '\0'; + tuple_id[tuple_id_len] = '\0'; } /* add tuple id */ - if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id)) - { + if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id)) { LM_ERR("while extracting xml" - " node\n"); + " node\n"); goto error; } - } - else - { - if(tuple== NULL) - { - if(strlen(tuple_id)>=50) { + } else { + if(tuple == NULL) { + if(strlen(tuple_id) >= 50) { LM_ERR("tuple id is too long: %s\n", tuple_id); goto error; } strcpy(buf, tuple_id); xmlFree(tuple_id); - tuple_id= buf; - tuple_id_len= strlen(tuple_id); + tuple_id = buf; + tuple_id_len = strlen(tuple_id); - tuple=(str*)pkg_malloc(sizeof(str)); - if(tuple== NULL) - { + tuple = (str *)pkg_malloc(sizeof(str)); + if(tuple == NULL) { PKG_MEM_ERROR; goto error; } - alloc_tuple= 1; - tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char)); - if(tuple->s== NULL) - { + alloc_tuple = 1; + tuple->s = (char *)pkg_malloc(tuple_id_len * sizeof(char)); + if(tuple->s == NULL) { PKG_MEM_ERROR; goto error; } memcpy(tuple->s, tuple_id, tuple_id_len); - tuple->len= tuple_id_len; - *tuple_param= tuple; + tuple->len = tuple_id_len; + *tuple_param = tuple; } } - node= xmlDocGetNodeByName(doc, "person", NULL); - if(node) - { + node = xmlDocGetNodeByName(doc, "person", NULL); + if(node) { 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)) - { + person_id = xmlNodeGetAttrContentByName(node, "id"); + if(person_id == NULL) { + if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id)) { LM_ERR("while extracting xml" - " node\n"); + " node\n"); goto error; } - } - else - { + } else { xmlFree(person_id); } } - body= (str*)pkg_malloc(sizeof(str)); - if(body== NULL) - { + body = (str *)pkg_malloc(sizeof(str)); + if(body == NULL) { PKG_MEM_ERROR; goto error; } memset(body, 0, sizeof(str)); - xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1); - if(body->s== NULL || body->len== 0) - { + 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; + doc = NULL; - *fin_body= body; + *fin_body = body; xmlMemoryDump(); xmlCleanupParser(); return 1; @@ -262,54 +246,50 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa pkg_free(tuple); } return -1; - } -int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple) +int bla_process_body(publ_info_t *publ, str **fin_body, int ver, str **tuple) { - xmlNodePtr node= NULL; - xmlDocPtr doc= NULL; - char* version; - str* body= NULL; + xmlNodePtr node = NULL; + xmlDocPtr doc = NULL; + char *version; + str *body = NULL; int len; - str* init_body; + str *init_body; - init_body= publ->body; + init_body = publ->body; - doc= xmlParseMemory(init_body->s, init_body->len ); - if(doc== NULL) - { + doc = xmlParseMemory(init_body->s, init_body->len); + if(doc == NULL) { LM_ERR("while parsing xml memory\n"); goto error; } /* change version and state*/ - node= xmlDocGetNodeByName(doc, "dialog-info", NULL); - if(node == NULL) - { + node = xmlDocGetNodeByName(doc, "dialog-info", NULL); + if(node == NULL) { LM_ERR("while extracting dialog-info node\n"); goto error; } - version= int2str(ver,&len); - version[len]= '\0'; + version = int2str(ver, &len); + version[len] = '\0'; - if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL) - { + if(xmlSetProp(node, (const xmlChar *)"version", (const xmlChar *)version) + == NULL) { LM_ERR("while setting version attribute\n"); goto error; } - body= (str*)pkg_malloc(sizeof(str)); - if(body== NULL) - { + body = (str *)pkg_malloc(sizeof(str)); + if(body == NULL) { 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; - if(*fin_body== NULL) + doc = NULL; + *fin_body = body; + if(*fin_body == NULL) LM_DBG("NULL fin_body\n"); xmlMemoryDump(); @@ -328,47 +308,49 @@ int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple) return -1; } -int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple) +int reginfo_process_body( + publ_info_t *publ, str **fin_body, int ver, str **tuple) { - xmlNodePtr node= NULL; - xmlDocPtr doc= NULL; - char* version; - str* body= NULL; + xmlNodePtr node = NULL; + xmlDocPtr doc = NULL; + char *version; + str *body = NULL; int len; - str* init_body; + str *init_body; - init_body= publ->body; + init_body = publ->body; - doc= xmlParseMemory(init_body->s, init_body->len ); - if(doc== NULL) { + doc = xmlParseMemory(init_body->s, init_body->len); + if(doc == NULL) { LM_ERR("while parsing xml memory\n"); goto error; } /* change version and state*/ - node= xmlDocGetNodeByName(doc, "reginfo", NULL); + node = xmlDocGetNodeByName(doc, "reginfo", NULL); if(node == NULL) { LM_ERR("while extracting dialog-info node\n"); goto error; } - version= int2str(ver,&len); - version[len]= '\0'; + version = int2str(ver, &len); + version[len] = '\0'; - if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL) { + if(xmlSetProp(node, (const xmlChar *)"version", (const xmlChar *)version) + == NULL) { LM_ERR("while setting version attribute\n"); goto error; } - body= (str*)pkg_malloc(sizeof(str)); - if(body== NULL) { + body = (str *)pkg_malloc(sizeof(str)); + if(body == NULL) { 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; - if(*fin_body== NULL) + doc = NULL; + *fin_body = body; + if(*fin_body == NULL) LM_DBG("NULL fin_body\n"); xmlMemoryDump(); @@ -387,15 +369,14 @@ int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple return -1; } -int mwi_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple) +int mwi_process_body(publ_info_t *publ, str **fin_body, int ver, str **tuple) { - *fin_body= publ->body; + *fin_body = publ->body; return 0; } -int dlg_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple) +int dlg_process_body(publ_info_t *publ, str **fin_body, int ver, str **tuple) { - *fin_body= publ->body; + *fin_body = publ->body; return 0; } - diff --git a/src/modules/pua/add_events.h b/src/modules/pua/add_events.h index 5dbf5e070fc..bc0bde3e39e 100644 --- a/src/modules/pua/add_events.h +++ b/src/modules/pua/add_events.h @@ -32,10 +32,15 @@ * */ int pua_add_events(void); -int pres_process_body(struct publ_info* publ, str** fin_body, int ver, str** tuple); -int bla_process_body (struct publ_info* publ, str** fin_body, int ver, str** tuple); -int mwi_process_body (struct publ_info* publ, str** fin_body, int ver, str** tuple); -int dlg_process_body (struct publ_info* publ, str** fin_body, int ver, str** tuple); -int reginfo_process_body (struct publ_info* publ, str** fin_body, int ver, str** tuple); +int pres_process_body( + struct publ_info *publ, str **fin_body, int ver, str **tuple); +int bla_process_body( + struct publ_info *publ, str **fin_body, int ver, str **tuple); +int mwi_process_body( + struct publ_info *publ, str **fin_body, int ver, str **tuple); +int dlg_process_body( + struct publ_info *publ, str **fin_body, int ver, str **tuple); +int reginfo_process_body( + struct publ_info *publ, str **fin_body, int ver, str **tuple); #endif diff --git a/src/modules/pua/event_list.c b/src/modules/pua/event_list.c index f9155f02259..dc5b838ab3b 100644 --- a/src/modules/pua/event_list.c +++ b/src/modules/pua/event_list.c @@ -29,107 +29,98 @@ #include "../../core/mem/shm_mem.h" #include "event_list.h" -pua_event_t* init_pua_evlist(void) +pua_event_t *init_pua_evlist(void) { - pua_event_t* list= NULL; + pua_event_t *list = NULL; - list= (pua_event_t*)shm_malloc(sizeof(pua_event_t)); - if(list== NULL) - { + list = (pua_event_t *)shm_malloc(sizeof(pua_event_t)); + if(list == NULL) { SHM_MEM_ERROR; return NULL; } - list->next= NULL; + list->next = NULL; return list; - } -int add_pua_event(int ev_flag, char* name, char* content_type, - evs_process_body_t* process_body) +int add_pua_event(int ev_flag, char *name, char *content_type, + evs_process_body_t *process_body) { - pua_event_t* event= NULL; + pua_event_t *event = NULL; int size; int name_len; - int ctype_len= 0; + int ctype_len = 0; str str_name; - name_len= strlen(name); - str_name.s= name; - str_name.len= name_len; + name_len = strlen(name); + str_name.s = name; + str_name.len = name_len; - if(contains_pua_event(&str_name)) - { + if(contains_pua_event(&str_name)) { LM_DBG("Event already exists\n"); return 0; } if(content_type) - ctype_len= strlen(content_type); + ctype_len = strlen(content_type); - size= sizeof(pua_event_t)+ (name_len+ ctype_len)* sizeof(char); + size = sizeof(pua_event_t) + (name_len + ctype_len) * sizeof(char); - event= (pua_event_t*)shm_malloc(size); - if(event== NULL) - { + event = (pua_event_t *)shm_malloc(size); + if(event == NULL) { SHM_MEM_ERROR; return -1; } memset(event, 0, size); - size= sizeof(pua_event_t); + size = sizeof(pua_event_t); - event->name.s= (char*)event+ size; + event->name.s = (char *)event + size; memcpy(event->name.s, name, name_len); - event->name.len= name_len; - size+= name_len; + event->name.len = name_len; + size += name_len; - if(content_type) - { - event->content_type.s= (char*)event+ size; + 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; + event->content_type.len = ctype_len; + size += ctype_len; } - event->process_body= process_body; - event->ev_flag= ev_flag; + event->process_body = process_body; + event->ev_flag = ev_flag; - event->next= pua_evlist->next; - pua_evlist->next= event; + event->next = pua_evlist->next; + pua_evlist->next = event; return 0; } -pua_event_t* contains_pua_event(str* name) +pua_event_t *contains_pua_event(str *name) { - pua_event_t* event; - event= pua_evlist->next; - - while(event) - { - if(event->name.len== name->len && - strncmp(event->name.s, name->s, name->len)== 0) - { + pua_event_t *event; + event = pua_evlist->next; + + while(event) { + if(event->name.len == name->len + && strncmp(event->name.s, name->s, name->len) == 0) { return event; } - event= event->next; + event = event->next; } return NULL; } -pua_event_t* get_event(int ev_flag) +pua_event_t *get_event(int ev_flag) { - pua_event_t* event; - event= pua_evlist->next; + pua_event_t *event; + event = pua_evlist->next; - while(event) - { - if(event->ev_flag== ev_flag) - { + while(event) { + if(event->ev_flag == ev_flag) { return event; } - event= event->next; + event = event->next; } return NULL; } @@ -137,18 +128,15 @@ pua_event_t* get_event(int ev_flag) void destroy_pua_evlist(void) { - pua_event_t* e1, *e2; - - if(pua_evlist) - { - e1= pua_evlist->next; - while(e1) - { - e2= e1->next; + pua_event_t *e1, *e2; + + if(pua_evlist) { + e1 = pua_evlist->next; + while(e1) { + e2 = e1->next; shm_free(e1); - e1= e2; + e1 = e2; } shm_free(pua_evlist); } - } diff --git a/src/modules/pua/event_list.h b/src/modules/pua/event_list.h index 6b767fb5494..7dbdd13c1e9 100644 --- a/src/modules/pua/event_list.h +++ b/src/modules/pua/event_list.h @@ -29,32 +29,32 @@ struct publ_info; -typedef int (evs_process_body_t)(struct publ_info* , str** final_body, - int ver, str** tuple); +typedef int(evs_process_body_t)( + struct publ_info *, str **final_body, int ver, str **tuple); typedef struct pua_event { - int ev_flag; + int ev_flag; str name; - str content_type; /* default content type for that event*/ - evs_process_body_t* process_body; - struct pua_event* next; + str content_type; /* default content type for that event*/ + evs_process_body_t *process_body; + struct pua_event *next; -}pua_event_t; +} pua_event_t; -extern pua_event_t* pua_evlist; +extern pua_event_t *pua_evlist; -pua_event_t* init_pua_evlist(void); +pua_event_t *init_pua_evlist(void); -int add_pua_event(int ev_flag, char* name, char* content_type, - evs_process_body_t* process_body); +int add_pua_event(int ev_flag, char *name, char *content_type, + evs_process_body_t *process_body); -typedef int (*add_pua_event_t)(int ev_flag, char* name, char* content_type, - evs_process_body_t* process_body); +typedef int (*add_pua_event_t)(int ev_flag, char *name, char *content_type, + evs_process_body_t *process_body); -pua_event_t* contains_pua_event(str* name); +pua_event_t *contains_pua_event(str *name); -pua_event_t* get_event(int ev_flag); +pua_event_t *get_event(int ev_flag); void destroy_pua_evlist(void); diff --git a/src/modules/pua/hash.c b/src/modules/pua/hash.c index 8bd4a442e6c..eceeb3109c7 100644 --- a/src/modules/pua/hash.c +++ b/src/modules/pua/hash.c @@ -36,141 +36,129 @@ #include "pua_db.h" #include "send_publish.h" -void print_ua_pres(ua_pres_t* p) +void print_ua_pres(ua_pres_t *p) { - LM_DBG("\tpres_uri= %.*s len= %d\n", p->pres_uri->len, p->pres_uri->s, p->pres_uri->len); - if(p->watcher_uri) - { - LM_DBG("\twatcher_uri= %.*s len= %d\n", p->watcher_uri->len, p->watcher_uri->s, p->watcher_uri->len); - LM_DBG("\tcall_id= %.*s len= %d\n", p->call_id.len, p->call_id.s, p->call_id.len); - LM_DBG("\tfrom_tag= %.*s len= %d\n", p->from_tag.len, p->from_tag.s, p->from_tag.len); - LM_DBG("\tto_tag= %.*s len= %d\n", p->to_tag.len, p->to_tag.s, p->to_tag.len); + LM_DBG("\tpres_uri= %.*s len= %d\n", p->pres_uri->len, p->pres_uri->s, + p->pres_uri->len); + if(p->watcher_uri) { + LM_DBG("\twatcher_uri= %.*s len= %d\n", p->watcher_uri->len, + p->watcher_uri->s, p->watcher_uri->len); + LM_DBG("\tcall_id= %.*s len= %d\n", p->call_id.len, p->call_id.s, + p->call_id.len); + LM_DBG("\tfrom_tag= %.*s len= %d\n", p->from_tag.len, p->from_tag.s, + p->from_tag.len); + LM_DBG("\tto_tag= %.*s len= %d\n", p->to_tag.len, p->to_tag.s, + p->to_tag.len); LM_DBG("\tflag= %d\n", p->flag); LM_DBG("\tevent= %d\n", p->event); - } - else - { + } else { LM_DBG("\tetag= %.*s - len= %d\n", p->etag.len, p->etag.s, p->etag.len); if(p->id.s) LM_DBG("\tid= %.*s\n", p->id.len, p->id.s); } - LM_DBG("\texpires= %d\n", p->expires- (int)time(NULL)); + LM_DBG("\texpires= %d\n", p->expires - (int)time(NULL)); } -htable_t* new_htable(void) +htable_t *new_htable(void) { - htable_t* H= NULL; - int i= 0, j; - H= (htable_t*)shm_malloc(sizeof(htable_t)); + htable_t *H = NULL; + int i = 0, j; + H = (htable_t *)shm_malloc(sizeof(htable_t)); - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "new_htable shouldn't be called in PUA_DB_ONLY mode\n" ); - return(NULL); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("new_htable shouldn't be called in PUA_DB_ONLY mode\n"); + return (NULL); } - if(H== NULL) - { + if(H == NULL) { SHM_MEM_ERROR; return NULL; } memset(H, 0, sizeof(htable_t)); - H->p_records= (hash_entry_t*)shm_malloc(HASH_SIZE* sizeof(hash_entry_t)); - if(H->p_records== NULL) - { + H->p_records = (hash_entry_t *)shm_malloc(HASH_SIZE * sizeof(hash_entry_t)); + if(H->p_records == NULL) { SHM_MEM_ERROR; goto error; } - for(i=0; ip_records[i].lock)== 0) - { + for(i = 0; i < HASH_SIZE; i++) { + if(lock_init(&H->p_records[i].lock) == 0) { LM_CRIT("initializing lock [%d]\n", i); goto error; } - H->p_records[i].entity= (ua_pres_t*)shm_malloc(sizeof(ua_pres_t)); - if(H->p_records[i].entity== NULL) - { + H->p_records[i].entity = (ua_pres_t *)shm_malloc(sizeof(ua_pres_t)); + if(H->p_records[i].entity == NULL) { SHM_MEM_ERROR; goto error; } - H->p_records[i].entity->next= NULL; + H->p_records[i].entity->next = NULL; } return H; error: - if(H->p_records) - { - for(j=0; j< i; j++) - { + if(H->p_records) { + for(j = 0; j < i; j++) { if(H->p_records[j].entity) shm_free(H->p_records[j].entity); lock_destroy(&H->p_records[j].lock); - } shm_free(H->p_records); } shm_free(H); return NULL; - } -ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code) +ua_pres_t *search_htable(ua_pres_t *pres, unsigned int hash_code) { - ua_pres_t* p= NULL,* L= NULL; - L= HashT->p_records[hash_code].entity; + ua_pres_t *p = NULL, *L = NULL; + L = HashT->p_records[hash_code].entity; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "search_htable shouldn't be called in PUA_DB_ONLY mode\n" ); - return(NULL); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("search_htable shouldn't be called in PUA_DB_ONLY mode\n"); + return (NULL); } LM_DBG("core_hash= %u\n", hash_code); - for(p= L->next; p; p=p->next) - { - if((p->flag & pres->flag) && (p->event & pres->event)) - { - if((p->pres_uri->len==pres->pres_uri->len) && - (strncmp(p->pres_uri->s, pres->pres_uri->s,pres->pres_uri->len)==0)) - { - if(pres->id.s && pres->id.len) - { - if(!(pres->id.len== p->id.len && - strncmp(p->id.s, pres->id.s,pres->id.len)==0)) - continue; + for(p = L->next; p; p = p->next) { + if((p->flag & pres->flag) && (p->event & pres->event)) { + if((p->pres_uri->len == pres->pres_uri->len) + && (strncmp(p->pres_uri->s, pres->pres_uri->s, + pres->pres_uri->len) + == 0)) { + if(pres->id.s && pres->id.len) { + if(!(pres->id.len == p->id.len + && strncmp(p->id.s, pres->id.s, pres->id.len) + == 0)) + continue; } - if(pres->watcher_uri) - { - if(p->watcher_uri->len==pres->watcher_uri->len && - (strncmp(p->watcher_uri->s, pres->watcher_uri->s, - pres->watcher_uri->len )==0)) - { - if (check_remote_contact == 0) + if(pres->watcher_uri) { + if(p->watcher_uri->len == pres->watcher_uri->len + && (strncmp(p->watcher_uri->s, pres->watcher_uri->s, + pres->watcher_uri->len) + == 0)) { + if(check_remote_contact == 0) break; if(pres->remote_contact.s) - if(pres->remote_contact.len== p->remote_contact.len && - strncmp(pres->remote_contact.s, p->remote_contact.s, - p->remote_contact.len)== 0) + if(pres->remote_contact.len == p->remote_contact.len + && strncmp(pres->remote_contact.s, + p->remote_contact.s, + p->remote_contact.len) + == 0) break; } - } - else - { - if(pres->etag.s) - { - if(pres->etag.len== p->etag.len && - strncmp(p->etag.s, pres->etag.s,pres->etag.len)==0) + } else { + if(pres->etag.s) { + if(pres->etag.len == p->etag.len + && strncmp(p->etag.s, pres->etag.s, + pres->etag.len) + == 0) break; - } - else - { + } else { LM_DBG("no etag restriction\n"); break; } @@ -187,47 +175,44 @@ ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code) return p; } -void update_htable(ua_pres_t* p, time_t desired_expires, int expires, - str* etag, unsigned int hash_code, str* contact) +void update_htable(ua_pres_t *p, time_t desired_expires, int expires, str *etag, + unsigned int hash_code, str *contact) { - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "update_htable shouldn't be called in PUA_DB_ONLY mode\n" ); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("update_htable shouldn't be called in PUA_DB_ONLY mode\n"); return; } - if(etag) - { + if(etag) { shm_free(p->etag.s); - p->etag.s= (char*)shm_malloc(etag->len); + p->etag.s = (char *)shm_malloc(etag->len); if(p->etag.s == NULL) { SHM_MEM_ERROR; return; } memcpy(p->etag.s, etag->s, etag->len); - p->etag.len= etag->len; + p->etag.len = etag->len; } - p->expires= expires+ (int)time(NULL); - p->desired_expires= desired_expires; + p->expires = expires + (int)time(NULL); + p->desired_expires = desired_expires; if(p->db_flag & NO_UPDATEDB_FLAG) - p->db_flag= UPDATEDB_FLAG; + p->db_flag = UPDATEDB_FLAG; if(p->watcher_uri) p->cseq++; - if(contact) - { - if(!(p->remote_contact.len== contact->len && - strncmp(p->remote_contact.s, contact->s, contact->len)==0)) - { + if(contact) { + if(!(p->remote_contact.len == contact->len + && strncmp(p->remote_contact.s, contact->s, contact->len) + == 0)) { /* update remote contact */ shm_free(p->remote_contact.s); - p->remote_contact.s= (char*)shm_malloc(contact->len* sizeof(char)); - if(p->remote_contact.s== NULL) - { + p->remote_contact.s = + (char *)shm_malloc(contact->len * sizeof(char)); + if(p->remote_contact.s == NULL) { SHM_MEM_ERROR; if(etag) { shm_free(p->etag.s); @@ -235,97 +220,89 @@ void update_htable(ua_pres_t* p, time_t desired_expires, int expires, return; } memcpy(p->remote_contact.s, contact->s, contact->len); - p->remote_contact.len= contact->len; + p->remote_contact.len = contact->len; } } } /* insert in front; so when searching the most recent result is returned*/ -void insert_htable(ua_pres_t* presentity, unsigned int hash_code) +void insert_htable(ua_pres_t *presentity, unsigned int hash_code) { - ua_pres_t* p= NULL; + ua_pres_t *p = NULL; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "insert_htable shouldn't be called in PUA_DB_ONLY mode\n" ); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("insert_htable shouldn't be called in PUA_DB_ONLY mode\n"); return; } - p= HashT->p_records[hash_code].entity; + p = HashT->p_records[hash_code].entity; - presentity->db_flag= INSERTDB_FLAG; - presentity->next= p->next; + presentity->db_flag = INSERTDB_FLAG; + presentity->next = p->next; - p->next= presentity; + p->next = presentity; } /* This function used to perform a search to find the hash table entry that matches the presentity it is passed. However, everywhere it is used it is passed a pointer to the correct hash table entry already... so let's just delete that */ -void delete_htable(ua_pres_t* presentity, unsigned int hash_code) +void delete_htable(ua_pres_t *presentity, unsigned int hash_code) { ua_pres_t *q = NULL; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "delete_htable shouldn't be called in PUA_DB_ONLY mode\n" ); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("delete_htable shouldn't be called in PUA_DB_ONLY mode\n"); return; } - if (presentity == NULL) + if(presentity == NULL) return; q = HashT->p_records[hash_code].entity; - while (q->next != presentity) + while(q->next != presentity) q = q->next; q->next = presentity->next; if(presentity->etag.s) shm_free(presentity->etag.s); - else - if(presentity->remote_contact.s) - shm_free(presentity->remote_contact.s); + else if(presentity->remote_contact.s) + shm_free(presentity->remote_contact.s); shm_free(presentity); presentity = NULL; - } void destroy_htable(void) { - ua_pres_t* p= NULL,*q= NULL; + ua_pres_t *p = NULL, *q = NULL; int i; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "destroy_htable shouldn't be called in PUA_DB_ONLY mode\n" ); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("destroy_htable shouldn't be called in PUA_DB_ONLY mode\n"); return; } - for(i=0; ip_records[i].lock); - p=HashT->p_records[i].entity; - while(p->next) - { - q=p->next; - p->next=q->next; + p = HashT->p_records[i].entity; + while(p->next) { + q = p->next; + p->next = q->next; if(q->etag.s) shm_free(q->etag.s); - else - if(q->remote_contact.s) - shm_free(q->remote_contact.s); + else if(q->remote_contact.s) + shm_free(q->remote_contact.s); shm_free(q); - q= NULL; + q = NULL; } shm_free(p); } - shm_free(HashT->p_records); + shm_free(HashT->p_records); shm_free(HashT); - return; + return; } int convert_temporary_dialog(ua_pres_t *dialog) @@ -333,11 +310,11 @@ int convert_temporary_dialog(ua_pres_t *dialog) ua_pres_t *temp_dialog; unsigned int hash_code; - hash_code= core_hash(dialog->pres_uri,dialog->watcher_uri, HASH_SIZE); + hash_code = core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); temp_dialog = get_temporary_dialog(dialog, hash_code); - if (temp_dialog) + if(temp_dialog) delete_htable(temp_dialog, hash_code); else { lock_release(&HashT->p_records[hash_code].lock); @@ -352,71 +329,69 @@ int convert_temporary_dialog(ua_pres_t *dialog) } /* must lock the record line before calling this function*/ -ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code) +ua_pres_t *get_dialog(ua_pres_t *dialog, unsigned int hash_code) { - ua_pres_t* p= NULL, *L; + ua_pres_t *p = NULL, *L; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "get_dialog shouldn't be called in PUA_DB_ONLY mode\n" ); - return(NULL); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("get_dialog shouldn't be called in PUA_DB_ONLY mode\n"); + return (NULL); } - if (dialog->to_tag.len == 0 || dialog->to_tag.s == NULL) - return(NULL); + if(dialog->to_tag.len == 0 || dialog->to_tag.s == NULL) + return (NULL); LM_DBG("core_hash= %u\n", hash_code); - L= HashT->p_records[hash_code].entity; - for(p= L->next; p; p=p->next) - { + L = HashT->p_records[hash_code].entity; + for(p = L->next; p; p = p->next) { - if(p->flag& dialog->flag) - { + if(p->flag & dialog->flag) { LM_DBG("pres_uri= %.*s\twatcher_uri=%.*s\n\t" - "callid= %.*s\tto_tag= %.*s\tfrom_tag= %.*s\n", - p->pres_uri->len, p->pres_uri->s, p->watcher_uri->len, - p->watcher_uri->s,p->call_id.len, p->call_id.s, - p->to_tag.len, p->to_tag.s, p->from_tag.len, p->from_tag.s); - - LM_DBG("searched to_tag= %.*s\tfrom_tag= %.*s\n", - p->to_tag.len, p->to_tag.s, p->from_tag.len, p->from_tag.s); - - if( (strncmp(p->call_id.s, dialog->call_id.s, p->call_id.len)== 0) && - p->to_tag.len > 0 && - (strncmp(p->to_tag.s, dialog->to_tag.s, p->to_tag.len)== 0) && - (strncmp(p->from_tag.s, dialog->from_tag.s, p->from_tag.len)== 0) ) - { - LM_DBG("FOUND dialog\n"); - break; - } + "callid= %.*s\tto_tag= %.*s\tfrom_tag= %.*s\n", + p->pres_uri->len, p->pres_uri->s, p->watcher_uri->len, + p->watcher_uri->s, p->call_id.len, p->call_id.s, + p->to_tag.len, p->to_tag.s, p->from_tag.len, p->from_tag.s); + + LM_DBG("searched to_tag= %.*s\tfrom_tag= %.*s\n", p->to_tag.len, + p->to_tag.s, p->from_tag.len, p->from_tag.s); + + if((strncmp(p->call_id.s, dialog->call_id.s, p->call_id.len) == 0) + && p->to_tag.len > 0 + && (strncmp(p->to_tag.s, dialog->to_tag.s, p->to_tag.len) + == 0) + && (strncmp(p->from_tag.s, dialog->from_tag.s, + p->from_tag.len) + == 0)) { + LM_DBG("FOUND dialog\n"); + break; + } } - } return p; } /* must lock the record line before calling this function*/ -ua_pres_t* get_temporary_dialog(ua_pres_t* dialog, unsigned int hash_code) +ua_pres_t *get_temporary_dialog(ua_pres_t *dialog, unsigned int hash_code) { - ua_pres_t* p= NULL, *L; + ua_pres_t *p = NULL, *L; LM_DBG("core_hash= %u\n", hash_code); - L= HashT->p_records[hash_code].entity; - for(p= L->next; p; p=p->next) - { + L = HashT->p_records[hash_code].entity; + for(p = L->next; p; p = p->next) { LM_DBG("pres_uri= %.*s\twatcher_uri=%.*s\n\t" - "callid= %.*s\tfrom_tag= %.*s\n", - p->pres_uri->len, p->pres_uri->s, p->watcher_uri->len, - p->watcher_uri->s,p->call_id.len, p->call_id.s, - p->from_tag.len, p->from_tag.s); - - if((p->call_id.len == dialog->call_id.len) && - (strncmp(p->call_id.s, dialog->call_id.s, p->call_id.len)== 0) && - (p->from_tag.len == dialog->from_tag.len) && - (strncmp(p->from_tag.s, dialog->from_tag.s, p->from_tag.len)== 0)) - { + "callid= %.*s\tfrom_tag= %.*s\n", + p->pres_uri->len, p->pres_uri->s, p->watcher_uri->len, + p->watcher_uri->s, p->call_id.len, p->call_id.s, + p->from_tag.len, p->from_tag.s); + + if((p->call_id.len == dialog->call_id.len) + && (strncmp(p->call_id.s, dialog->call_id.s, p->call_id.len) + == 0) + && (p->from_tag.len == dialog->from_tag.len) + && (strncmp(p->from_tag.s, dialog->from_tag.s, p->from_tag.len) + == 0)) { LM_DBG("FOUND temporary dialog\n"); break; } @@ -425,57 +400,52 @@ ua_pres_t* get_temporary_dialog(ua_pres_t* dialog, unsigned int hash_code) return p; } -int get_record_id(ua_pres_t* dialog, str** rec_id) +int get_record_id(ua_pres_t *dialog, str **rec_id) { unsigned int hash_code; - ua_pres_t* rec; - str* id; + ua_pres_t *rec; + str *id; - if (dbmode==PUA_DB_ONLY) - { - return( get_record_id_puadb( dialog, rec_id ) ); + if(dbmode == PUA_DB_ONLY) { + return (get_record_id_puadb(dialog, rec_id)); } - *rec_id= NULL; + *rec_id = NULL; - hash_code= core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE); + hash_code = core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); - rec= get_dialog(dialog, hash_code); - if(rec== NULL) - { + rec = get_dialog(dialog, hash_code); + if(rec == NULL) { LM_DBG("Record not found - looking for temporary\n"); rec = get_temporary_dialog(dialog, hash_code); - if (rec == NULL) - { + if(rec == NULL) { LM_DBG("Temporary record not found\n"); lock_release(&HashT->p_records[hash_code].lock); return 0; } } - id= (str*)pkg_malloc(sizeof(str)); - if(id== NULL) - { + id = (str *)pkg_malloc(sizeof(str)); + if(id == NULL) { PKG_MEM_ERROR; lock_release(&HashT->p_records[hash_code].lock); return -1; } - id->s= (char*)pkg_malloc(rec->id.len* sizeof(char)); - if(id->s== NULL) - { + id->s = (char *)pkg_malloc(rec->id.len * sizeof(char)); + if(id->s == NULL) { PKG_MEM_ERROR; pkg_free(id); lock_release(&HashT->p_records[hash_code].lock); return -1; } memcpy(id->s, rec->id.s, rec->id.len); - id->len= rec->id.len; + id->len = rec->id.len; lock_release(&HashT->p_records[hash_code].lock); LM_DBG("rec did= %.*s\n", id->len, id->s); - *rec_id= id; + *rec_id = id; return 0; } @@ -483,133 +453,114 @@ int get_record_id(ua_pres_t* dialog, str** rec_id) /** * return -1 on not found, 0 on established dialog, 1 on temporary dialog */ -int is_dialog(ua_pres_t* dialog) +int is_dialog(ua_pres_t *dialog) { - int ret_code= 0; + int ret_code = 0; unsigned int hash_code; - if (dbmode==PUA_DB_ONLY) - { - return( is_dialog_puadb(dialog) ); + if(dbmode == PUA_DB_ONLY) { + return (is_dialog_puadb(dialog)); } - hash_code= core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE); + hash_code = core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); - if(get_dialog(dialog, hash_code)==NULL) - { - if(get_temporary_dialog(dialog, hash_code)==NULL) - ret_code= -1; + if(get_dialog(dialog, hash_code) == NULL) { + if(get_temporary_dialog(dialog, hash_code) == NULL) + ret_code = -1; else - ret_code= 1; + ret_code = 1; } else { - ret_code= 0; + ret_code = 0; } lock_release(&HashT->p_records[hash_code].lock); return ret_code; - } -int ki_pua_update_contact(struct sip_msg* msg) +int ki_pua_update_contact(struct sip_msg *msg) { - ua_pres_t* p, hentity; + ua_pres_t *p, hentity; str contact; struct to_body *pto = NULL, TO = {0}, *pfrom = NULL; unsigned int hash_code; - if ( parse_headers(msg,HDR_EOH_F, 0)==-1 ) - { + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("when parsing headers\n"); return -1; } /* find the record */ - if( msg->callid==NULL || msg->callid->body.s==NULL) - { + if(msg->callid == NULL || msg->callid->body.s == NULL) { LM_ERR("cannot parse callid header\n"); return -1; } - if (!msg->from || !msg->from->body.s) - { + if(!msg->from || !msg->from->body.s) { LM_ERR("cannot find 'from' header!\n"); return -1; } - if (msg->from->parsed == NULL) - { - if ( parse_from_header( msg )<0 ) - { + if(msg->from->parsed == NULL) { + if(parse_from_header(msg) < 0) { LM_ERR("cannot parse From header\n"); return -1; } } - pfrom = (struct to_body*)msg->from->parsed; + pfrom = (struct to_body *)msg->from->parsed; - if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0) - { + if(pfrom->tag_value.s == NULL || pfrom->tag_value.len == 0) { LM_ERR("no from tag value present\n"); return -1; } - if( msg->to==NULL || msg->to->body.s==NULL) - { + if(msg->to == NULL || msg->to->body.s == NULL) { LM_ERR("cannot parse TO header\n"); return -1; } - if(msg->to->parsed != NULL) - { - pto = (struct to_body*)msg->to->parsed; - LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",pto->uri.len,pto->uri.s); - } - else - { - parse_to(msg->to->body.s,msg->to->body.s + - msg->to->body.len + 1, &TO); - if(TO.uri.len <= 0) - { + if(msg->to->parsed != NULL) { + pto = (struct to_body *)msg->to->parsed; + LM_DBG("'To' header ALREADY PARSED: <%.*s>\n", pto->uri.len, + pto->uri.s); + } else { + parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, &TO); + if(TO.uri.len <= 0) { LM_DBG("'To' header NOT parsed\n"); goto error; } pto = &TO; } - if( pto->tag_value.s ==NULL || pto->tag_value.len == 0) - { + if(pto->tag_value.s == NULL || pto->tag_value.len == 0) { LM_ERR("no from tag value present\n"); goto error; } - hentity.watcher_uri= &pto->uri; - hentity.pres_uri= &pfrom->uri; - hentity.call_id= msg->callid->body; - hentity.to_tag= pto->tag_value; - hentity.from_tag= pfrom->tag_value; + hentity.watcher_uri = &pto->uri; + hentity.pres_uri = &pfrom->uri; + hentity.call_id = msg->callid->body; + hentity.to_tag = pto->tag_value; + hentity.from_tag = pfrom->tag_value; /* extract the contact */ - if(msg->contact== NULL || msg->contact->body.s== NULL) - { + if(msg->contact == NULL || msg->contact->body.s == NULL) { LM_ERR("no contact header found in 200 OK reply"); goto error; } - contact= msg->contact->body; + contact = msg->contact->body; - if (dbmode==PUA_DB_ONLY) - { - update_contact_puadb(&hentity, &contact ); + if(dbmode == PUA_DB_ONLY) { + update_contact_puadb(&hentity, &contact); free_to_params(&TO); - return(1); + return (1); } - hash_code= core_hash(hentity.pres_uri,hentity.watcher_uri, - HASH_SIZE); + hash_code = core_hash(hentity.pres_uri, hentity.watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); - p= get_dialog(&hentity, hash_code); - if(p== NULL) - { + p = get_dialog(&hentity, hash_code); + if(p == NULL) { lock_release(&HashT->p_records[hash_code].lock); LM_ERR("no record for the dialog found in hash table\n"); goto error; @@ -617,20 +568,18 @@ int ki_pua_update_contact(struct sip_msg* msg) shm_free(p->remote_contact.s); - if(!(p->remote_contact.len== contact.len && - strncmp(p->remote_contact.s, contact.s, contact.len)==0)) - { + if(!(p->remote_contact.len == contact.len + && strncmp(p->remote_contact.s, contact.s, contact.len) == 0)) { /* update remote contact */ shm_free(p->remote_contact.s); - p->remote_contact.s= (char*)shm_malloc(contact.len* sizeof(char)); - if(p->remote_contact.s== NULL) - { + p->remote_contact.s = (char *)shm_malloc(contact.len * sizeof(char)); + if(p->remote_contact.s == NULL) { SHM_MEM_ERROR; lock_release(&HashT->p_records[hash_code].lock); goto error; } memcpy(p->remote_contact.s, contact.s, contact.len); - p->remote_contact.len= contact.len; + p->remote_contact.len = contact.len; } lock_release(&HashT->p_records[hash_code].lock); @@ -643,7 +592,7 @@ int ki_pua_update_contact(struct sip_msg* msg) return -1; } -int w_pua_update_contact(struct sip_msg* msg, char* str1, char* str2) +int w_pua_update_contact(struct sip_msg *msg, char *str1, char *str2) { return ki_pua_update_contact(msg); } @@ -654,30 +603,27 @@ list_entry_t *get_subs_list(str *did) str *tmp_str; list_entry_t *list = NULL; - if (dbmode==PUA_DB_ONLY) + if(dbmode == PUA_DB_ONLY) return get_subs_list_puadb(did); - for (i = 0; i < HASH_SIZE; i++) - { + for(i = 0; i < HASH_SIZE; i++) { ua_pres_t *dialog; lock_get(&HashT->p_records[i].lock); dialog = HashT->p_records[i].entity; - while (dialog != NULL) - { - if (dialog->id.s != NULL && dialog->id.len > 0 && - strncmp(dialog->id.s, did->s, did->len) == 0 && - dialog->pres_uri != NULL && dialog->pres_uri->s != NULL && - dialog->pres_uri->len > 0) - { - if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL) - { + while(dialog != NULL) { + if(dialog->id.s != NULL && dialog->id.len > 0 + && strncmp(dialog->id.s, did->s, did->len) == 0 + && dialog->pres_uri != NULL && dialog->pres_uri->s != NULL + && dialog->pres_uri->len > 0) { + if((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL) { PKG_MEM_ERROR; lock_release(&HashT->p_records[i].lock); goto done; } - if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * dialog->pres_uri->len + 1)) == NULL) - { + if((tmp_str->s = (char *)pkg_malloc( + sizeof(char) * dialog->pres_uri->len + 1)) + == NULL) { pkg_free(tmp_str); PKG_MEM_ERROR; lock_release(&HashT->p_records[i].lock); diff --git a/src/modules/pua/hash.h b/src/modules/pua/hash.h index 454e4bb8531..933d2466a41 100644 --- a/src/modules/pua/hash.h +++ b/src/modules/pua/hash.h @@ -33,152 +33,153 @@ #include "../../core/parser/msg_parser.h" #include "../rls/list.h" -#define PRESENCE_EVENT 1<<0 -#define PWINFO_EVENT 1<<1 -#define BLA_EVENT 1<<2 -#define MSGSUM_EVENT 1<<3 -#define CONFERENCE_EVENT 1<<4 -#define DIALOG_EVENT 1<<5 -#define REGINFO_EVENT 1<<6 -#define XCAPDIFF_EVENT 1<<7 - -#define UL_PUBLISH 1<<0 -#define BLA_PUBLISH 1<<1 -#define BLA_SUBSCRIBE 1<<2 -#define XMPP_PUBLISH 1<<3 -#define XMPP_SUBSCRIBE 1<<4 -#define XMPP_INITIAL_SUBS 1<<5 -#define RPC_PUBLISH 1<<6 -#define RPC_ASYN_PUBLISH 1<<7 -#define RPC_SUBSCRIBE 1<<8 -#define RLS_SUBSCRIBE 1<<9 -#define DIALOG_PUBLISH 1<<10 -#define PURPLE_PUBLISH 1<<11 -#define REGINFO_PUBLISH 1<<12 -#define REGINFO_SUBSCRIBE 1<<13 -#define XCAPDIFF_PUBLISH 1<<14 -#define XCAPDIFF_SUBSCRIBE 1<<15 - -#define NO_UPDATEDB_FLAG 1<<0 -#define UPDATEDB_FLAG 1<<1 -#define INSERTDB_FLAG 1<<2 -#define WTHROUGHDB_FLAG 1<<3 - -#define MAX_FORWARD 70 - -typedef struct ua_pres{ - - /* common*/ +#define PRESENCE_EVENT 1 << 0 +#define PWINFO_EVENT 1 << 1 +#define BLA_EVENT 1 << 2 +#define MSGSUM_EVENT 1 << 3 +#define CONFERENCE_EVENT 1 << 4 +#define DIALOG_EVENT 1 << 5 +#define REGINFO_EVENT 1 << 6 +#define XCAPDIFF_EVENT 1 << 7 + +#define UL_PUBLISH 1 << 0 +#define BLA_PUBLISH 1 << 1 +#define BLA_SUBSCRIBE 1 << 2 +#define XMPP_PUBLISH 1 << 3 +#define XMPP_SUBSCRIBE 1 << 4 +#define XMPP_INITIAL_SUBS 1 << 5 +#define RPC_PUBLISH 1 << 6 +#define RPC_ASYN_PUBLISH 1 << 7 +#define RPC_SUBSCRIBE 1 << 8 +#define RLS_SUBSCRIBE 1 << 9 +#define DIALOG_PUBLISH 1 << 10 +#define PURPLE_PUBLISH 1 << 11 +#define REGINFO_PUBLISH 1 << 12 +#define REGINFO_SUBSCRIBE 1 << 13 +#define XCAPDIFF_PUBLISH 1 << 14 +#define XCAPDIFF_SUBSCRIBE 1 << 15 + +#define NO_UPDATEDB_FLAG 1 << 0 +#define UPDATEDB_FLAG 1 << 1 +#define INSERTDB_FLAG 1 << 2 +#define WTHROUGHDB_FLAG 1 << 3 + +#define MAX_FORWARD 70 + +typedef struct ua_pres +{ + + /* common*/ str id; - str* pres_uri; + str *pres_uri; int event; unsigned int expires; unsigned int desired_expires; int flag; int db_flag; - void* cb_param; - struct ua_pres* next; + void *cb_param; + struct ua_pres *next; int ua_flag; - str* outbound_proxy; /* croc-not sored in db_only mode */ - + str *outbound_proxy; /* croc-not sored in db_only mode */ + /* publish */ str etag; str tuple_id; - str* body; /* croc-not stored in db_only mode */ + str *body; /* croc-not stored in db_only mode */ str content_type; /* croc-not stored in db_only mode */ /* subscribe */ - str* watcher_uri; + str *watcher_uri; str call_id; str to_tag; - str from_tag; + str from_tag; int cseq; int version; -/* int watcher_count; croc-nolonger used!! */ - str* extra_headers; + /* int watcher_count; croc-nolonger used!! */ + str *extra_headers; str record_route; str remote_contact; str contact; /*?? should this be long? */ -}ua_pres_t; +} ua_pres_t; typedef struct hash_entry { - ua_pres_t* entity; + ua_pres_t *entity; gen_lock_t lock; -}hash_entry_t; +} hash_entry_t; -typedef struct htable{ - hash_entry_t* p_records; -}htable_t; +typedef struct htable +{ + hash_entry_t *p_records; +} htable_t; -htable_t* new_htable(void); +htable_t *new_htable(void); -ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code); +ua_pres_t *search_htable(ua_pres_t *pres, unsigned int hash_code); -void insert_htable(ua_pres_t* presentity, unsigned int hash_code); +void insert_htable(ua_pres_t *presentity, unsigned int hash_code); -void update_htable(ua_pres_t* presentity,time_t desired_expires, - int expires, str* etag, unsigned int hash_code, str* contact); +void update_htable(ua_pres_t *presentity, time_t desired_expires, int expires, + str *etag, unsigned int hash_code, str *contact); -void delete_htable(ua_pres_t* presentity, unsigned int hash_code); +void delete_htable(ua_pres_t *presentity, unsigned int hash_code); void destroy_htable(void); -int is_dialog(ua_pres_t* dialog); +int is_dialog(ua_pres_t *dialog); -ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code); -ua_pres_t* get_temporary_dialog(ua_pres_t* dialog, unsigned int hash_code); +ua_pres_t *get_dialog(ua_pres_t *dialog, unsigned int hash_code); +ua_pres_t *get_temporary_dialog(ua_pres_t *dialog, unsigned int hash_code); int convert_temporary_dialog(ua_pres_t *dialog); -int get_record_id(ua_pres_t* dialog, str** rec_id); -typedef int (*get_record_id_t)(ua_pres_t* dialog, str** rec_id); +int get_record_id(ua_pres_t *dialog, str **rec_id); +typedef int (*get_record_id_t)(ua_pres_t *dialog, str **rec_id); list_entry_t *get_subs_list(str *did); -typedef list_entry_t * (*get_subs_list_t)(str *did); +typedef list_entry_t *(*get_subs_list_t)(str *did); /* for degug */ -void print_ua_pres(ua_pres_t* p); +void print_ua_pres(ua_pres_t *p); -typedef int (*query_dialog_t)(ua_pres_t* presentity); +typedef int (*query_dialog_t)(ua_pres_t *presentity); -static inline int get_event_flag(str* event) +static inline int get_event_flag(str *event) { - switch (event->len) - { - case 3: - if (strncmp(event->s, "reg", 3) == 0) - return REGINFO_EVENT; - break; - case 6: - if (strncmp(event->s, "dialog", 6) == 0) - return DIALOG_EVENT; - break; - case 8: - if (strncmp(event->s, "presence", 8) == 0) - return PRESENCE_EVENT; - break; - case 10: - if (strncmp(event->s, "dialog;sla", 10) == 0) - return BLA_EVENT; - if (strncmp(event->s, "conference", 10) == 0) - return CONFERENCE_EVENT; - break; - case 14: - if (strncmp(event->s, "presence.winfo", 14) == 0) - return PWINFO_EVENT; - break; - case 15: - if (strncmp(event->s, "message-summary", 15) == 0) - return MSGSUM_EVENT; - } - - LM_ERR("Unknown event string\n"); - return -1; + switch(event->len) { + case 3: + if(strncmp(event->s, "reg", 3) == 0) + return REGINFO_EVENT; + break; + case 6: + if(strncmp(event->s, "dialog", 6) == 0) + return DIALOG_EVENT; + break; + case 8: + if(strncmp(event->s, "presence", 8) == 0) + return PRESENCE_EVENT; + break; + case 10: + if(strncmp(event->s, "dialog;sla", 10) == 0) + return BLA_EVENT; + if(strncmp(event->s, "conference", 10) == 0) + return CONFERENCE_EVENT; + break; + case 14: + if(strncmp(event->s, "presence.winfo", 14) == 0) + return PWINFO_EVENT; + break; + case 15: + if(strncmp(event->s, "message-summary", 15) == 0) + return MSGSUM_EVENT; + } + + LM_ERR("Unknown event string\n"); + return -1; } -int w_pua_update_contact(struct sip_msg* msg, char* str1, char* str2); -int ki_pua_update_contact(struct sip_msg* msg); +int w_pua_update_contact(struct sip_msg *msg, char *str1, char *str2); +int ki_pua_update_contact(struct sip_msg *msg); #endif diff --git a/src/modules/pua/pidf.c b/src/modules/pua/pidf.c index f2b0fd3fd14..d445b0e3a25 100644 --- a/src/modules/pua/pidf.c +++ b/src/modules/pua/pidf.c @@ -32,8 +32,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; } @@ -43,8 +43,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; } @@ -52,39 +52,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; } @@ -95,28 +98,26 @@ 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; } -int bind_libxml_api(libxml_api_t* api) +int bind_libxml_api(libxml_api_t *api) { - if (!api) - { + if(!api) { LM_ERR("Invalid parameter value\n"); return -1; } - api->xmlDocGetNodeByName = xmlDocGetNodeByName; - api->xmlNodeGetNodeByName = xmlNodeGetNodeByName; - api->xmlNodeGetNodeContentByName = xmlNodeGetNodeContentByName; - api->xmlNodeGetAttrContentByName = xmlNodeGetAttrContentByName; - - return 0; -} + api->xmlDocGetNodeByName = xmlDocGetNodeByName; + api->xmlNodeGetNodeByName = xmlNodeGetNodeByName; + api->xmlNodeGetNodeContentByName = xmlNodeGetNodeContentByName; + api->xmlNodeGetAttrContentByName = xmlNodeGetAttrContentByName; + return 0; +} diff --git a/src/modules/pua/pidf.h b/src/modules/pua/pidf.h index 71ea173b4ef..801d913ef8d 100644 --- a/src/modules/pua/pidf.h +++ b/src/modules/pua/pidf.h @@ -27,14 +27,18 @@ #include "../../core/str.h" #include -typedef xmlNodePtr (*xmlDocGetNodeByName_t)(xmlDocPtr doc, const char *name, const char *ns); -typedef xmlNodePtr (*xmlNodeGetNodeByName_t)(xmlNodePtr node, const char *name, const char *ns); -typedef char* (*xmlNodeGetNodeContentByName_t)(xmlNodePtr root, const char *name, - const char *ns); -typedef char* (*xmlNodeGetAttrContentByName_t)(xmlNodePtr node, const char *name); -xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name, - const char *ns); -typedef struct libxml_api { +typedef xmlNodePtr (*xmlDocGetNodeByName_t)( + xmlDocPtr doc, const char *name, const char *ns); +typedef xmlNodePtr (*xmlNodeGetNodeByName_t)( + xmlNodePtr node, const char *name, const char *ns); +typedef char *(*xmlNodeGetNodeContentByName_t)( + xmlNodePtr root, const char *name, const char *ns); +typedef char *(*xmlNodeGetAttrContentByName_t)( + xmlNodePtr node, const char *name); +xmlNodePtr xmlNodeGetNodeByName( + xmlNodePtr node, const char *name, const char *ns); +typedef struct libxml_api +{ xmlDocGetNodeByName_t xmlDocGetNodeByName; xmlNodeGetNodeByName_t xmlNodeGetNodeByName; xmlNodeGetNodeContentByName_t xmlNodeGetNodeContentByName; @@ -44,12 +48,12 @@ typedef struct libxml_api { 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); -typedef int (*bind_libxml_t)(libxml_api_t* api); +typedef int (*bind_libxml_t)(libxml_api_t *api); -int bind_libxml_api(libxml_api_t* api); +int bind_libxml_api(libxml_api_t *api); #endif /* PUA_PIDF_H */ diff --git a/src/modules/pua/pua.c b/src/modules/pua/pua.c index 255d0fa1bf4..ef542e2d627 100644 --- a/src/modules/pua/pua.c +++ b/src/modules/pua/pua.c @@ -54,20 +54,20 @@ MODULE_VERSION #define PUA_TABLE_VERSION 7 struct tm_binds tmb; -htable_t* HashT= NULL; -int HASH_SIZE= -1; -extern int bind_pua(pua_api_t* api); -int min_expires= 0; -int pua_default_expires=3600; +htable_t *HashT = NULL; +int HASH_SIZE = -1; +extern int bind_pua(pua_api_t *api); +int min_expires = 0; +int pua_default_expires = 3600; static str db_url = str_init(DEFAULT_DB_URL); -str db_table= str_init("pua"); -int update_period= 100; +str db_table = str_init("pua"); +int update_period = 100; str outbound_proxy = {0, 0}; int check_remote_contact = 1; int startup_time = 0; int dlginfo_increase_version = 0; int reginfo_increase_version = 0; -pua_event_t* pua_evlist= NULL; +pua_event_t *pua_evlist = NULL; int dbmode = 0; int db_table_lock_write = 1; @@ -82,21 +82,21 @@ db_func_t pua_dbf; /* database columns */ static str str_pres_uri_col = str_init("pres_uri"); static str str_pres_id_col = str_init("pres_id"); -static str str_expires_col= str_init("expires"); -static str str_flag_col= str_init("flag"); -static str str_etag_col= str_init("etag"); -static str str_tuple_id_col= str_init("tuple_id"); -static str str_watcher_uri_col= str_init("watcher_uri"); -static str str_call_id_col= str_init("call_id"); -static str str_to_tag_col= str_init("to_tag"); -static str str_from_tag_col= str_init("from_tag"); -static str str_cseq_col= str_init("cseq"); -static str str_event_col= str_init("event"); -static str str_record_route_col= str_init("record_route"); -static str str_contact_col= str_init("contact"); -static str str_remote_contact_col= str_init("remote_contact"); -static str str_extra_headers_col= str_init("extra_headers"); -static str str_desired_expires_col= str_init("desired_expires"); +static str str_expires_col = str_init("expires"); +static str str_flag_col = str_init("flag"); +static str str_etag_col = str_init("etag"); +static str str_tuple_id_col = str_init("tuple_id"); +static str str_watcher_uri_col = str_init("watcher_uri"); +static str str_call_id_col = str_init("call_id"); +static str str_to_tag_col = str_init("to_tag"); +static str str_from_tag_col = str_init("from_tag"); +static str str_cseq_col = str_init("cseq"); +static str str_event_col = str_init("event"); +static str str_record_route_col = str_init("record_route"); +static str str_contact_col = str_init("contact"); +static str str_remote_contact_col = str_init("remote_contact"); +static str str_extra_headers_col = str_init("extra_headers"); +static str str_desired_expires_col = str_init("desired_expires"); static str str_version_col = str_init("version"); /* module functions */ @@ -105,51 +105,45 @@ static int mod_init(void); static int child_init(int); static void destroy(void); -static ua_pres_t* build_uppubl_cbparam(ua_pres_t* p); +static ua_pres_t *build_uppubl_cbparam(ua_pres_t *p); static int db_restore(void); -static void db_update(unsigned int ticks,void *param); -static void hashT_clean(unsigned int ticks,void *param); +static void db_update(unsigned int ticks, void *param); +static void hashT_clean(unsigned int ticks, void *param); static int pua_rpc_init(void); -static cmd_export_t cmds[]= -{ - {"pua_update_contact", (cmd_function)w_pua_update_contact, 0, 0, 0, REQUEST_ROUTE}, - {"bind_libxml_api", (cmd_function)bind_libxml_api, 1, 0, 0, 0}, - {"bind_pua", (cmd_function)bind_pua, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; - -static param_export_t params[]={ - {"hash_size", INT_PARAM, &HASH_SIZE}, - {"db_url", PARAM_STR, &db_url}, - {"db_table", PARAM_STR, &db_table}, - {"min_expires", INT_PARAM, &min_expires}, - {"default_expires", INT_PARAM, &pua_default_expires}, - {"update_period", INT_PARAM, &update_period}, - {"outbound_proxy", PARAM_STR, &outbound_proxy}, - {"dlginfo_increase_version", INT_PARAM, &dlginfo_increase_version}, - {"reginfo_increase_version", INT_PARAM, ®info_increase_version}, - {"check_remote_contact", INT_PARAM, &check_remote_contact}, - {"db_mode", INT_PARAM, &dbmode}, - {"fetch_rows", INT_PARAM, &pua_fetch_rows}, - {"db_table_lock_write", INT_PARAM, &db_table_lock_write}, - {0, 0, 0} -}; +static cmd_export_t cmds[] = { + {"pua_update_contact", (cmd_function)w_pua_update_contact, 0, 0, 0, + REQUEST_ROUTE}, + {"bind_libxml_api", (cmd_function)bind_libxml_api, 1, 0, 0, 0}, + {"bind_pua", (cmd_function)bind_pua, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}; + +static param_export_t params[] = {{"hash_size", INT_PARAM, &HASH_SIZE}, + {"db_url", PARAM_STR, &db_url}, {"db_table", PARAM_STR, &db_table}, + {"min_expires", INT_PARAM, &min_expires}, + {"default_expires", INT_PARAM, &pua_default_expires}, + {"update_period", INT_PARAM, &update_period}, + {"outbound_proxy", PARAM_STR, &outbound_proxy}, + {"dlginfo_increase_version", INT_PARAM, &dlginfo_increase_version}, + {"reginfo_increase_version", INT_PARAM, ®info_increase_version}, + {"check_remote_contact", INT_PARAM, &check_remote_contact}, + {"db_mode", INT_PARAM, &dbmode}, + {"fetch_rows", INT_PARAM, &pua_fetch_rows}, + {"db_table_lock_write", INT_PARAM, &db_table_lock_write}, {0, 0, 0}}; /** module exports */ -struct module_exports exports= { - "pua", /* 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 */ - child_init, /* per-child init function */ - destroy /* module destroy function */ +struct module_exports exports = { + "pua", /* 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 */ + child_init, /* per-child init function */ + destroy /* module destroy function */ }; /** @@ -159,19 +153,18 @@ static int mod_init(void) { LM_DBG("...\n"); - if(min_expires< 0) - min_expires= 0; + if(min_expires < 0) + min_expires = 0; - if(pua_default_expires< 600) - pua_default_expires= 3600; + if(pua_default_expires < 600) + pua_default_expires = 3600; - if(pua_rpc_init()<0) { + if(pua_rpc_init() < 0) { LM_ERR("failed to register RPC commands\n"); return -1; } /* load TM API */ - if(load_tm_api(&tmb)==-1) - { + if(load_tm_api(&tmb) == -1) { LM_ERR("can't load tm functions\n"); return -1; } @@ -179,102 +172,90 @@ static int mod_init(void) LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); /* binding to database module */ - if (db_bind_mod(&db_url, &pua_dbf)) - { + if(db_bind_mod(&db_url, &pua_dbf)) { LM_ERR("Database module not found\n"); return -1; } - if (!DB_CAPABILITY(pua_dbf, DB_CAP_ALL)) { + if(!DB_CAPABILITY(pua_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions needed" - " by the module\n"); + " by the module\n"); return -1; } pua_db = pua_dbf.init(&db_url); - if (!pua_db) - { + if(!pua_db) { LM_ERR("while connecting database\n"); return -1; } /* verify table version */ - if(db_check_table_version(&pua_dbf, pua_db, &db_table, PUA_TABLE_VERSION) < 0) { + if(db_check_table_version(&pua_dbf, pua_db, &db_table, PUA_TABLE_VERSION) + < 0) { DB_TABLE_VERSION_ERROR(db_table); pua_dbf.close(pua_db); pua_db = NULL; return -1; } - if (dbmode != PUA_DB_ONLY) - { - if(HASH_SIZE<=1) - HASH_SIZE= 512; + if(dbmode != PUA_DB_ONLY) { + if(HASH_SIZE <= 1) + HASH_SIZE = 512; else - HASH_SIZE = 1<1) - { + if(check_remote_contact < 0 || check_remote_contact > 1) { LM_ERR("bad value for check_remote_contact\n"); return -1; } - startup_time = (int) time(NULL); + startup_time = (int)time(NULL); - if (update_period > 5) - register_timer(hashT_clean, 0, update_period- 5); - else if (update_period != 0) - { + if(update_period > 5) + register_timer(hashT_clean, 0, update_period - 5); + else if(update_period != 0) { LM_ERR("update_period must be 0 or > 5\n"); return -1; } - if (dbmode != PUA_DB_ONLY) - { - if (update_period > 0) + if(dbmode != PUA_DB_ONLY) { + if(update_period > 0) register_timer(db_update, 0, update_period); } - if (db_table_lock_write != 1) + if(db_table_lock_write != 1) db_table_lock = DB_LOCKING_NONE; if(pua_db) @@ -286,27 +267,24 @@ static int mod_init(void) static int child_init(int rank) { - if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) + if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN) return 0; /* do nothing for the main process */ - if (pua_dbf.init==0) - { + if(pua_dbf.init == 0) { LM_CRIT("database not bound\n"); return -1; } /* In DB only mode do not pool the connections where possible. */ - if (dbmode == PUA_DB_ONLY && pua_dbf.init2) + if(dbmode == PUA_DB_ONLY && pua_dbf.init2) pua_db = pua_dbf.init2(&db_url, DB_POOLING_NONE); else pua_db = pua_dbf.init(&db_url); - if (!pua_db) - { + if(!pua_db) { LM_ERR("Child %d: connecting to database failed\n", rank); return -1; } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("child %d: Error in use_table pua\n", rank); return -1; } @@ -318,13 +296,13 @@ static int child_init(int rank) static void destroy(void) { - if (puacb_list) + if(puacb_list) destroy_puacb_list(); /* if dbmode is PUA_DB_ONLY, then HashT will be NULL * so db_update and destroy_htable won't get called */ if(pua_db && HashT) - db_update(0,0); + db_update(0, 0); if(HashT) destroy_htable(); @@ -334,82 +312,79 @@ static void destroy(void) if(pua_evlist) destroy_pua_evlist(); - return ; + return; } static int db_restore(void) { - ua_pres_t* p= NULL; + ua_pres_t *p = NULL; db_key_t result_cols[19]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_row_t *row = NULL; - db_val_t *row_vals= NULL; + db_val_t *row_vals = NULL; str pres_uri, pres_id; str etag, tuple_id; str watcher_uri, call_id; str to_tag, from_tag, remote_contact; str record_route, contact, extra_headers; - int size= 0, i; - int n_result_cols= 0; - int puri_col,pid_col,expires_col,flag_col,etag_col, desired_expires_col; - int watcher_col,callid_col,totag_col,fromtag_col,cseq_col,remote_contact_col; - int event_col,contact_col,tuple_col,record_route_col, extra_headers_col; + int size = 0, i; + int n_result_cols = 0; + int puri_col, pid_col, expires_col, flag_col, etag_col, desired_expires_col; + int watcher_col, callid_col, totag_col, fromtag_col, cseq_col, + remote_contact_col; + int event_col, contact_col, tuple_col, record_route_col, extra_headers_col; int version_col; unsigned int hash_code; - if (dbmode==PUA_DB_ONLY) - { - LM_ERR( "db_restore shouldn't be called in PUA_DB_ONLY mode\n" ); - return(-1); + if(dbmode == PUA_DB_ONLY) { + LM_ERR("db_restore shouldn't be called in PUA_DB_ONLY mode\n"); + return (-1); } - result_cols[puri_col=n_result_cols++] = &str_pres_uri_col; - result_cols[pid_col=n_result_cols++] = &str_pres_id_col; - result_cols[expires_col=n_result_cols++]= &str_expires_col; - result_cols[flag_col=n_result_cols++] = &str_flag_col; - result_cols[etag_col=n_result_cols++] = &str_etag_col; - result_cols[tuple_col=n_result_cols++] = &str_tuple_id_col; - result_cols[watcher_col=n_result_cols++]= &str_watcher_uri_col; - result_cols[callid_col=n_result_cols++] = &str_call_id_col; - result_cols[totag_col=n_result_cols++] = &str_to_tag_col; - result_cols[fromtag_col=n_result_cols++]= &str_from_tag_col; - result_cols[cseq_col= n_result_cols++] = &str_cseq_col; - result_cols[event_col= n_result_cols++] = &str_event_col; - result_cols[record_route_col= n_result_cols++] = &str_record_route_col; - result_cols[contact_col= n_result_cols++] = &str_contact_col; - result_cols[remote_contact_col= n_result_cols++] = &str_remote_contact_col; - result_cols[extra_headers_col= n_result_cols++] = &str_extra_headers_col; - result_cols[desired_expires_col= n_result_cols++] = &str_desired_expires_col; - result_cols[version_col= n_result_cols++] = &str_version_col; - - if(!pua_db) - { + result_cols[puri_col = n_result_cols++] = &str_pres_uri_col; + result_cols[pid_col = n_result_cols++] = &str_pres_id_col; + result_cols[expires_col = n_result_cols++] = &str_expires_col; + result_cols[flag_col = n_result_cols++] = &str_flag_col; + result_cols[etag_col = n_result_cols++] = &str_etag_col; + result_cols[tuple_col = n_result_cols++] = &str_tuple_id_col; + result_cols[watcher_col = n_result_cols++] = &str_watcher_uri_col; + result_cols[callid_col = n_result_cols++] = &str_call_id_col; + result_cols[totag_col = n_result_cols++] = &str_to_tag_col; + result_cols[fromtag_col = n_result_cols++] = &str_from_tag_col; + result_cols[cseq_col = n_result_cols++] = &str_cseq_col; + result_cols[event_col = n_result_cols++] = &str_event_col; + result_cols[record_route_col = n_result_cols++] = &str_record_route_col; + result_cols[contact_col = n_result_cols++] = &str_contact_col; + result_cols[remote_contact_col = n_result_cols++] = &str_remote_contact_col; + result_cols[extra_headers_col = n_result_cols++] = &str_extra_headers_col; + result_cols[desired_expires_col = n_result_cols++] = + &str_desired_expires_col; + result_cols[version_col = n_result_cols++] = &str_version_col; + + if(!pua_db) { LM_ERR("null database connection\n"); return -1; } - if(pua_dbf.use_table(pua_db, &db_table)< 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("in use table\n"); return -1; } - if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, 0, 0, 0, result_cols, - 0, n_result_cols, 0, &res)< 0) - { + if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, 0, 0, 0, result_cols, 0, + n_result_cols, 0, &res) + < 0) { LM_ERR("while querying table\n"); - if(res) - { + if(res) { pua_dbf.free_result(pua_db, res); res = NULL; } return -1; } - if(res==NULL) + if(res == NULL) return -1; - if(res->n<=0) - { + if(res->n <= 0) { LM_INFO("the query returned no result\n"); pua_dbf.free_result(pua_db, res); res = NULL; @@ -419,187 +394,182 @@ static int db_restore(void) do { LM_DBG("found %d db entries\n", res->n); - for(i =0 ; i< res->n ; i++) - { + for(i = 0; i < res->n; i++) { row = &res->rows[i]; row_vals = ROW_VALUES(row); - pres_uri.s= (char*)row_vals[puri_col].val.string_val; + pres_uri.s = (char *)row_vals[puri_col].val.string_val; pres_uri.len = strlen(pres_uri.s); LM_DBG("pres_uri= %.*s\n", pres_uri.len, pres_uri.s); - memset(&etag, 0, sizeof(str)); - memset(&tuple_id, 0, sizeof(str)); - memset(&watcher_uri, 0, sizeof(str)); - memset(&call_id, 0, sizeof(str)); - memset(&to_tag, 0, sizeof(str)); - memset(&from_tag, 0, sizeof(str)); - memset(&record_route, 0, sizeof(str)); - memset(&pres_id, 0, sizeof(str)); - memset(&contact, 0, sizeof(str)); - memset(&remote_contact, 0, sizeof(str)); - memset(&extra_headers, 0, sizeof(str)); - - pres_id.s= (char*)row_vals[pid_col].val.string_val; + memset(&etag, 0, sizeof(str)); + memset(&tuple_id, 0, sizeof(str)); + memset(&watcher_uri, 0, sizeof(str)); + memset(&call_id, 0, sizeof(str)); + memset(&to_tag, 0, sizeof(str)); + memset(&from_tag, 0, sizeof(str)); + memset(&record_route, 0, sizeof(str)); + memset(&pres_id, 0, sizeof(str)); + memset(&contact, 0, sizeof(str)); + memset(&remote_contact, 0, sizeof(str)); + memset(&extra_headers, 0, sizeof(str)); + + pres_id.s = (char *)row_vals[pid_col].val.string_val; if(pres_id.s) pres_id.len = strlen(pres_id.s); - if(row_vals[etag_col].val.string_val) - { - etag.s= (char*)row_vals[etag_col].val.string_val; + if(row_vals[etag_col].val.string_val) { + etag.s = (char *)row_vals[etag_col].val.string_val; etag.len = strlen(etag.s); - tuple_id.s= (char*)row_vals[tuple_col].val.string_val; + tuple_id.s = (char *)row_vals[tuple_col].val.string_val; tuple_id.len = strlen(tuple_id.s); } - if(row_vals[watcher_col].val.string_val) - { - watcher_uri.s= (char*)row_vals[watcher_col].val.string_val; + if(row_vals[watcher_col].val.string_val) { + watcher_uri.s = (char *)row_vals[watcher_col].val.string_val; watcher_uri.len = strlen(watcher_uri.s); - call_id.s= (char*)row_vals[callid_col].val.string_val; + call_id.s = (char *)row_vals[callid_col].val.string_val; call_id.len = strlen(call_id.s); - to_tag.s= (char*)row_vals[totag_col].val.string_val; + to_tag.s = (char *)row_vals[totag_col].val.string_val; to_tag.len = strlen(to_tag.s); - from_tag.s= (char*)row_vals[fromtag_col].val.string_val; + from_tag.s = (char *)row_vals[fromtag_col].val.string_val; from_tag.len = strlen(from_tag.s); - if(row_vals[record_route_col].val.string_val) - { - record_route.s= (char*)row_vals[record_route_col].val.string_val; - record_route.len= strlen(record_route.s); + if(row_vals[record_route_col].val.string_val) { + record_route.s = + (char *)row_vals[record_route_col].val.string_val; + record_route.len = strlen(record_route.s); } - contact.s= (char*)row_vals[contact_col].val.string_val; + contact.s = (char *)row_vals[contact_col].val.string_val; contact.len = strlen(contact.s); - remote_contact.s= (char*)row_vals[remote_contact_col].val.string_val; + remote_contact.s = + (char *)row_vals[remote_contact_col].val.string_val; remote_contact.len = strlen(remote_contact.s); } - extra_headers.s= (char*)row_vals[extra_headers_col].val.string_val; + extra_headers.s = + (char *)row_vals[extra_headers_col].val.string_val; if(extra_headers.s) - extra_headers.len= strlen(extra_headers.s); + extra_headers.len = strlen(extra_headers.s); else - extra_headers.len= 0; + extra_headers.len = 0; - size= sizeof(ua_pres_t)+ sizeof(str)+ (pres_uri.len+ pres_id.len+ - tuple_id.len)* sizeof(char); + size = sizeof(ua_pres_t) + sizeof(str) + + (pres_uri.len + pres_id.len + tuple_id.len) * sizeof(char); if(extra_headers.s) - size+= sizeof(str)+ extra_headers.len* sizeof(char); + size += sizeof(str) + extra_headers.len * sizeof(char); if(watcher_uri.s) - size+= sizeof(str)+ (watcher_uri.len+ call_id.len+ to_tag.len+ - from_tag.len+ record_route.len+ contact.len)* sizeof(char); - - p= (ua_pres_t*)shm_malloc(size); - if(p== NULL) - { + size += sizeof(str) + + (watcher_uri.len + call_id.len + to_tag.len + + from_tag.len + record_route.len + + contact.len) + * sizeof(char); + + p = (ua_pres_t *)shm_malloc(size); + if(p == NULL) { SHM_MEM_ERROR; goto error; } memset(p, 0, size); - size= sizeof(ua_pres_t); + size = sizeof(ua_pres_t); - p->pres_uri= (str*)((char*)p+ size); - size+= sizeof(str); - p->pres_uri->s= (char*)p + size; + p->pres_uri = (str *)((char *)p + size); + size += sizeof(str); + p->pres_uri->s = (char *)p + size; memcpy(p->pres_uri->s, pres_uri.s, pres_uri.len); - p->pres_uri->len= pres_uri.len; - size+= pres_uri.len; + p->pres_uri->len = pres_uri.len; + size += pres_uri.len; - if(pres_id.s) - { - p->id.s= (char*)p + size; + if(pres_id.s) { + p->id.s = (char *)p + size; memcpy(p->id.s, pres_id.s, pres_id.len); - p->id.len= pres_id.len; - size+= pres_id.len; + p->id.len = pres_id.len; + size += pres_id.len; } - if(tuple_id.s && tuple_id.len) - { - p->tuple_id.s= (char*)p + size; + if(tuple_id.s && tuple_id.len) { + p->tuple_id.s = (char *)p + size; memcpy(p->tuple_id.s, tuple_id.s, tuple_id.len); - p->tuple_id.len= tuple_id.len; - size+= tuple_id.len; + p->tuple_id.len = tuple_id.len; + size += tuple_id.len; } - if(watcher_uri.s && watcher_uri.len) - { - p->watcher_uri= (str*)((char*)p+ size); - size+= sizeof(str); + if(watcher_uri.s && watcher_uri.len) { + p->watcher_uri = (str *)((char *)p + size); + size += sizeof(str); - p->watcher_uri->s= (char*)p+ size; + p->watcher_uri->s = (char *)p + size; memcpy(p->watcher_uri->s, watcher_uri.s, watcher_uri.len); - p->watcher_uri->len= watcher_uri.len; - size+= watcher_uri.len; + p->watcher_uri->len = watcher_uri.len; + size += watcher_uri.len; - p->to_tag.s= (char*)p+ size; + p->to_tag.s = (char *)p + size; memcpy(p->to_tag.s, to_tag.s, to_tag.len); - p->to_tag.len= to_tag.len; - size+= to_tag.len; + p->to_tag.len = to_tag.len; + size += to_tag.len; - p->from_tag.s= (char*)p+ size; + p->from_tag.s = (char *)p + size; memcpy(p->from_tag.s, from_tag.s, from_tag.len); - p->from_tag.len= from_tag.len; - size+= from_tag.len; + p->from_tag.len = from_tag.len; + size += from_tag.len; - p->call_id.s= (char*)p + size; + p->call_id.s = (char *)p + size; memcpy(p->call_id.s, call_id.s, call_id.len); - p->call_id.len= call_id.len; - size+= call_id.len; + p->call_id.len = call_id.len; + size += call_id.len; - if(record_route.s && record_route.len) - { - p->record_route.s= (char*)p + size; + if(record_route.s && record_route.len) { + p->record_route.s = (char *)p + size; memcpy(p->record_route.s, record_route.s, record_route.len); - p->record_route.len= record_route.len; - size+= record_route.len; + p->record_route.len = record_route.len; + size += record_route.len; } - p->contact.s= (char*)p + size; + p->contact.s = (char *)p + size; memcpy(p->contact.s, contact.s, contact.len); - p->contact.len= contact.len; - size+= contact.len; + p->contact.len = contact.len; + size += contact.len; - p->cseq= row_vals[cseq_col].val.int_val; + p->cseq = row_vals[cseq_col].val.int_val; - p->remote_contact.s= (char*)shm_malloc(remote_contact.len* sizeof(char)); - if(p->remote_contact.s== NULL) - { + p->remote_contact.s = + (char *)shm_malloc(remote_contact.len * sizeof(char)); + if(p->remote_contact.s == NULL) { SHM_MEM_ERROR; goto error; } - memcpy(p->remote_contact.s, remote_contact.s, remote_contact.len); - p->remote_contact.len= remote_contact.len; + memcpy(p->remote_contact.s, remote_contact.s, + remote_contact.len); + p->remote_contact.len = remote_contact.len; - p->version= row_vals[version_col].val.int_val; + p->version = row_vals[version_col].val.int_val; } - if(extra_headers.s) - { - p->extra_headers= (str*)((char*)p+ size); - size+= sizeof(str); - p->extra_headers->s= (char*)p+ size; + if(extra_headers.s) { + p->extra_headers = (str *)((char *)p + size); + size += sizeof(str); + p->extra_headers->s = (char *)p + size; memcpy(p->extra_headers->s, extra_headers.s, extra_headers.len); - p->extra_headers->len= extra_headers.len; - size+= extra_headers.len; + p->extra_headers->len = extra_headers.len; + size += extra_headers.len; } LM_DBG("size= %d\n", size); - p->event= row_vals[event_col].val.int_val; - p->expires= row_vals[expires_col].val.int_val; - p->desired_expires= row_vals[desired_expires_col].val.int_val; - p->flag|= row_vals[flag_col].val.int_val; + p->event = row_vals[event_col].val.int_val; + p->expires = row_vals[expires_col].val.int_val; + p->desired_expires = row_vals[desired_expires_col].val.int_val; + p->flag |= row_vals[flag_col].val.int_val; memset(&p->etag, 0, sizeof(str)); - if(etag.s && etag.len) - { + if(etag.s && etag.len) { /* alloc separately */ - p->etag.s= (char*)shm_malloc(etag.len* sizeof(char)); - if(p->etag.s== NULL) - { + p->etag.s = (char *)shm_malloc(etag.len * sizeof(char)); + if(p->etag.s == NULL) { SHM_MEM_ERROR; if(watcher_uri.s && watcher_uri.len) { shm_free(p->remote_contact.s); @@ -607,25 +577,24 @@ static int db_restore(void) goto error; } memcpy(p->etag.s, etag.s, etag.len); - p->etag.len= etag.len; + p->etag.len = etag.len; } print_ua_pres(p); - hash_code= core_hash(p->pres_uri, p->watcher_uri, HASH_SIZE); + hash_code = core_hash(p->pres_uri, p->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); insert_htable(p, hash_code); lock_release(&HashT->p_records[hash_code].lock); } - } while((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res)==1) - && (RES_ROW_N(res)>0)); + } while((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res) == 1) + && (RES_ROW_N(res) > 0)); pua_dbf.free_result(pua_db, res); res = NULL; - if(pua_dbf.delete(pua_db, 0, 0 , 0, 0) < 0) - { + if(pua_dbf.delete(pua_db, 0, 0, 0, 0) < 0) { LM_ERR("while deleting information from db\n"); goto error; } @@ -641,148 +610,127 @@ static int db_restore(void) return -1; } -static void hashT_clean(unsigned int ticks,void *param) +static void hashT_clean(unsigned int ticks, void *param) { int i; time_t now; - ua_pres_t* p= NULL, *q= NULL; + ua_pres_t *p = NULL, *q = NULL; - if (dbmode==PUA_DB_ONLY) - { - clean_puadb(update_period, min_expires ); + if(dbmode == PUA_DB_ONLY) { + clean_puadb(update_period, min_expires); return; } now = time(NULL); - for(i= 0;i< HASH_SIZE; i++) - { + for(i = 0; i < HASH_SIZE; i++) { lock_get(&HashT->p_records[i].lock); - p= HashT->p_records[i].entity->next; - while(p) - { + p = HashT->p_records[i].entity->next; + while(p) { print_ua_pres(p); - if(p->expires- update_period < now ) - { - if((p->desired_expires> p->expires + min_expires) || - (p->desired_expires== 0 )) - { - if(update_pua(p)< 0) - { + if(p->expires - update_period < now) { + if((p->desired_expires > p->expires + min_expires) + || (p->desired_expires == 0)) { + if(update_pua(p) < 0) { LM_ERR("while updating record\n"); lock_release(&HashT->p_records[i].lock); return; } - p= p->next; + p = p->next; continue; } - if(p->expires < now - 10) - { - q= p->next; + if(p->expires < now - 10) { + q = p->next; LM_DBG("Found expired: uri= %.*s\n", p->pres_uri->len, p->pres_uri->s); delete_htable(p, i); - p= q; - } - else - p= p->next; - } - else - p= p->next; + p = q; + } else + p = p->next; + } else + p = p->next; } lock_release(&HashT->p_records[i].lock); } - - } -int update_pua(ua_pres_t* p) +int update_pua(ua_pres_t *p) { - str* str_hdr= NULL; + str *str_hdr = NULL; int expires; int result; uac_req_t uac_r; int ret_code = 0; - dlg_t* td = NULL; + dlg_t *td = NULL; - if(p->desired_expires== 0) - expires= pua_default_expires; + if(p->desired_expires == 0) + expires = pua_default_expires; else - expires= p->desired_expires- (int)time(NULL); + expires = p->desired_expires - (int)time(NULL); - if(p->watcher_uri == NULL || p->watcher_uri->len == 0) - { - str met= {"PUBLISH", 7}; - ua_pres_t* cb_param; + if(p->watcher_uri == NULL || p->watcher_uri->len == 0) { + str met = {"PUBLISH", 7}; + ua_pres_t *cb_param; - str_hdr = publ_build_hdr(expires, get_event(p->event), NULL, - &p->etag, p->extra_headers, 0); - if(str_hdr == NULL) - { + str_hdr = publ_build_hdr(expires, get_event(p->event), NULL, &p->etag, + p->extra_headers, 0); + if(str_hdr == NULL) { LM_ERR("while building extra_headers\n"); ret_code = -1; goto done; } LM_DBG("str_hdr:\n%.*s\n ", str_hdr->len, str_hdr->s); - cb_param= build_uppubl_cbparam(p); - if(cb_param== NULL) - { + cb_param = build_uppubl_cbparam(p); + if(cb_param == NULL) { LM_ERR("while constructing publ callback param\n"); ret_code = -1; goto done; } set_uac_req(&uac_r, &met, str_hdr, 0, 0, TMCB_LOCAL_COMPLETED, - publ_cback_func, (void*)cb_param); - result= tmb.t_request(&uac_r, - p->pres_uri, /* Request-URI */ - p->pres_uri, /* To */ - p->pres_uri, /* From */ - &outbound_proxy /* Outbound proxy*/ - ); - if(result< 0) - { + publ_cback_func, (void *)cb_param); + result = tmb.t_request(&uac_r, p->pres_uri, /* Request-URI */ + p->pres_uri, /* To */ + p->pres_uri, /* From */ + &outbound_proxy /* Outbound proxy*/ + ); + if(result < 0) { LM_ERR("in t_request function\n"); shm_free(cb_param); ret_code = -1; goto done; } - } - else - { - str met= {"SUBSCRIBE", 9}; - ua_pres_t* cb_param= NULL; + } else { + str met = {"SUBSCRIBE", 9}; + ua_pres_t *cb_param = NULL; - td= pua_build_dlg_t(p); - if(td== NULL) - { + td = pua_build_dlg_t(p); + if(td == NULL) { LM_ERR("while building tm dlg_t structure"); ret_code = -1; goto done; }; - str_hdr= subs_build_hdr(&p->contact, expires,p->event,p->extra_headers); - if(str_hdr== NULL || str_hdr->s== NULL) - { - if(p->event!=0) + str_hdr = subs_build_hdr( + &p->contact, expires, p->event, p->extra_headers); + if(str_hdr == NULL || str_hdr->s == NULL) { + if(p->event != 0) LM_ERR("while building extra headers\n"); ret_code = -1; goto done; } - cb_param= subs_cbparam_indlg(p, expires, REQ_ME); - if(cb_param== NULL) - { + cb_param = subs_cbparam_indlg(p, expires, REQ_ME); + if(cb_param == NULL) { LM_ERR("while constructing subs callback param\n"); ret_code = -1; goto done; } set_uac_req(&uac_r, &met, str_hdr, 0, td, TMCB_LOCAL_COMPLETED, - subs_cback_func, (void*)cb_param); + subs_cback_func, (void *)cb_param); - result= tmb.t_request_within(&uac_r); - if(result< 0) - { + result = tmb.t_request_within(&uac_r); + if(result < 0) { LM_ERR("in t_request function\n"); shm_free(cb_param); ret_code = -1; @@ -790,446 +738,416 @@ int update_pua(ua_pres_t* p) } } done: - if(td!=NULL) - { + if(td != NULL) { if(td->route_set) free_rr(&td->route_set); pkg_free(td); - td= NULL; + td = NULL; } if(str_hdr) pkg_free(str_hdr); return ret_code; - } -static void db_update(unsigned int ticks,void *param) +static void db_update(unsigned int ticks, void *param) { - ua_pres_t* p= NULL; + ua_pres_t *p = NULL; db_key_t q_cols[20], result_cols[1]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_key_t db_cols[5]; db_val_t q_vals[20], db_vals[5]; - db_op_t db_ops[1] ; - int n_query_cols= 0, n_query_update= 0; - int n_update_cols= 0; + db_op_t db_ops[1]; + int n_query_cols = 0, n_query_update = 0; + int n_update_cols = 0; int i; - int puri_col,pid_col,expires_col,flag_col,etag_col,tuple_col,event_col; - int watcher_col,callid_col,totag_col,fromtag_col,record_route_col,cseq_col; - int no_lock= 0, contact_col, desired_expires_col, extra_headers_col; + int puri_col, pid_col, expires_col, flag_col, etag_col, tuple_col, + event_col; + int watcher_col, callid_col, totag_col, fromtag_col, record_route_col, + cseq_col; + int no_lock = 0, contact_col, desired_expires_col, extra_headers_col; int remote_contact_col, version_col; - if (dbmode==PUA_DB_ONLY) return; + if(dbmode == PUA_DB_ONLY) + return; - if(ticks== 0 && param == NULL) - no_lock= 1; + if(ticks == 0 && param == NULL) + no_lock = 1; /* cols and values used for insert */ - q_cols[puri_col= n_query_cols] = &str_pres_uri_col; + q_cols[puri_col = n_query_cols] = &str_pres_uri_col; q_vals[puri_col].type = DB1_STR; q_vals[puri_col].nul = 0; n_query_cols++; - q_cols[pid_col= n_query_cols] = &str_pres_id_col; + q_cols[pid_col = n_query_cols] = &str_pres_id_col; q_vals[pid_col].type = DB1_STR; q_vals[pid_col].nul = 0; n_query_cols++; - q_cols[flag_col= n_query_cols] = &str_flag_col; + q_cols[flag_col = n_query_cols] = &str_flag_col; q_vals[flag_col].type = DB1_INT; q_vals[flag_col].nul = 0; n_query_cols++; - q_cols[event_col= n_query_cols] = &str_event_col; + q_cols[event_col = n_query_cols] = &str_event_col; q_vals[event_col].type = DB1_INT; q_vals[event_col].nul = 0; n_query_cols++; - q_cols[watcher_col= n_query_cols] = &str_watcher_uri_col; + q_cols[watcher_col = n_query_cols] = &str_watcher_uri_col; q_vals[watcher_col].type = DB1_STR; q_vals[watcher_col].nul = 0; n_query_cols++; - q_cols[callid_col= n_query_cols] = &str_call_id_col; + q_cols[callid_col = n_query_cols] = &str_call_id_col; q_vals[callid_col].type = DB1_STR; q_vals[callid_col].nul = 0; n_query_cols++; - q_cols[totag_col= n_query_cols] = &str_to_tag_col; + q_cols[totag_col = n_query_cols] = &str_to_tag_col; q_vals[totag_col].type = DB1_STR; q_vals[totag_col].nul = 0; n_query_cols++; - q_cols[fromtag_col= n_query_cols] = &str_from_tag_col; + q_cols[fromtag_col = n_query_cols] = &str_from_tag_col; q_vals[fromtag_col].type = DB1_STR; q_vals[fromtag_col].nul = 0; n_query_cols++; - q_cols[etag_col= n_query_cols] = &str_etag_col; + q_cols[etag_col = n_query_cols] = &str_etag_col; q_vals[etag_col].type = DB1_STR; q_vals[etag_col].nul = 0; n_query_cols++; - q_cols[tuple_col= n_query_cols] = &str_tuple_id_col; + q_cols[tuple_col = n_query_cols] = &str_tuple_id_col; q_vals[tuple_col].type = DB1_STR; q_vals[tuple_col].nul = 0; n_query_cols++; - q_cols[cseq_col= n_query_cols]= &str_cseq_col; + q_cols[cseq_col = n_query_cols] = &str_cseq_col; q_vals[cseq_col].type = DB1_INT; q_vals[cseq_col].nul = 0; n_query_cols++; - q_cols[expires_col= n_query_cols] = &str_expires_col; + q_cols[expires_col = n_query_cols] = &str_expires_col; q_vals[expires_col].type = DB1_INT; q_vals[expires_col].nul = 0; n_query_cols++; - q_cols[desired_expires_col= n_query_cols] = &str_desired_expires_col; + q_cols[desired_expires_col = n_query_cols] = &str_desired_expires_col; q_vals[desired_expires_col].type = DB1_INT; q_vals[desired_expires_col].nul = 0; n_query_cols++; - q_cols[record_route_col= n_query_cols] = &str_record_route_col; + q_cols[record_route_col = n_query_cols] = &str_record_route_col; q_vals[record_route_col].type = DB1_STR; q_vals[record_route_col].nul = 0; n_query_cols++; - q_cols[contact_col= n_query_cols] = &str_contact_col; + q_cols[contact_col = n_query_cols] = &str_contact_col; q_vals[contact_col].type = DB1_STR; q_vals[contact_col].nul = 0; n_query_cols++; - q_cols[remote_contact_col= n_query_cols] = &str_remote_contact_col; + q_cols[remote_contact_col = n_query_cols] = &str_remote_contact_col; q_vals[remote_contact_col].type = DB1_STR; q_vals[remote_contact_col].nul = 0; n_query_cols++; - q_cols[version_col= n_query_cols] = &str_version_col; + q_cols[version_col = n_query_cols] = &str_version_col; q_vals[version_col].type = DB1_INT; q_vals[version_col].nul = 0; n_query_cols++; /* must keep this the last column to be inserted */ - q_cols[extra_headers_col= n_query_cols] = &str_extra_headers_col; + q_cols[extra_headers_col = n_query_cols] = &str_extra_headers_col; q_vals[extra_headers_col].type = DB1_STR; q_vals[extra_headers_col].nul = 0; n_query_cols++; /* cols and values used for update */ - db_cols[0]= &str_expires_col; + db_cols[0] = &str_expires_col; db_vals[0].type = DB1_INT; db_vals[0].nul = 0; - db_cols[1]= &str_cseq_col; + db_cols[1] = &str_cseq_col; db_vals[1].type = DB1_INT; db_vals[1].nul = 0; - db_cols[2]= &str_etag_col; + db_cols[2] = &str_etag_col; db_vals[2].type = DB1_STR; db_vals[2].nul = 0; - db_cols[3]= &str_desired_expires_col; + db_cols[3] = &str_desired_expires_col; db_vals[3].type = DB1_INT; db_vals[3].nul = 0; - db_cols[4]= &str_version_col; + db_cols[4] = &str_version_col; db_vals[4].type = DB1_INT; db_vals[4].nul = 0; - result_cols[0]= &str_expires_col; + result_cols[0] = &str_expires_col; - if(pua_db== NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); return; } - if(pua_dbf.use_table(pua_db, &db_table)< 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("in use table\n"); - return ; + return; } - for(i=0; ip_records[i].lock); p = HashT->p_records[i].entity->next; - while(p) - { - if((int)p->expires - (int)time(NULL)< 0) - { - p= p->next; + while(p) { + if((int)p->expires - (int)time(NULL) < 0) { + p = p->next; continue; } - switch(p->db_flag) - { - case NO_UPDATEDB_FLAG: - { - LM_DBG("NO_UPDATEDB_FLAG\n"); - break; - } + switch(p->db_flag) { + case NO_UPDATEDB_FLAG: { + LM_DBG("NO_UPDATEDB_FLAG\n"); + break; + } - case UPDATEDB_FLAG: - { - LM_DBG("UPDATEDB_FLAG\n"); - n_update_cols= 0; - n_query_update= 0; + case UPDATEDB_FLAG: { + LM_DBG("UPDATEDB_FLAG\n"); + n_update_cols = 0; + n_query_update = 0; - q_vals[puri_col].val.str_val = *(p->pres_uri); - n_query_update++; + q_vals[puri_col].val.str_val = *(p->pres_uri); + n_query_update++; - q_vals[pid_col].val.str_val = p->id; - n_query_update++; + q_vals[pid_col].val.str_val = p->id; + n_query_update++; - q_vals[flag_col].val.int_val = p->flag; - n_query_update++; + q_vals[flag_col].val.int_val = p->flag; + n_query_update++; - q_vals[event_col].val.int_val = p->event; - n_query_update++; + q_vals[event_col].val.int_val = p->event; + n_query_update++; - if(p->watcher_uri) - { - q_vals[watcher_col].val.str_val = *(p->watcher_uri); - n_query_update++; + if(p->watcher_uri) { + q_vals[watcher_col].val.str_val = *(p->watcher_uri); + n_query_update++; - q_vals[callid_col].val.str_val = p->call_id; - n_query_update++; + q_vals[callid_col].val.str_val = p->call_id; + n_query_update++; - q_vals[totag_col].val.str_val = p->to_tag; - n_query_update++; + q_vals[totag_col].val.str_val = p->to_tag; + n_query_update++; - q_vals[fromtag_col].val.str_val = p->from_tag; - n_query_update++; - } + q_vals[fromtag_col].val.str_val = p->from_tag; + n_query_update++; + } - db_vals[0].val.int_val= p->expires; - n_update_cols++; + db_vals[0].val.int_val = p->expires; + n_update_cols++; - db_vals[1].val.int_val= p->cseq ; - n_update_cols++; + db_vals[1].val.int_val = p->cseq; + n_update_cols++; - db_vals[2].val.str_val= p->etag ; - n_update_cols++; + db_vals[2].val.str_val = p->etag; + n_update_cols++; - db_vals[3].val.int_val= p->desired_expires; - n_update_cols++; + db_vals[3].val.int_val = p->desired_expires; + n_update_cols++; - db_vals[4].val.int_val= p->version; - n_update_cols++; + db_vals[4].val.int_val = p->version; + n_update_cols++; - LM_DBG("Updating:n_query_update= %d\tn_update_cols= %d\n", - n_query_update, n_update_cols); + LM_DBG("Updating:n_query_update= %d\tn_update_cols= %d\n", + n_query_update, n_update_cols); - if(pua_dbf.query(pua_db, q_cols, 0, q_vals, - result_cols, n_query_update, 1, 0, &res)< 0) - { - LM_ERR("while querying db table pua\n"); + if(pua_dbf.query(pua_db, q_cols, 0, q_vals, result_cols, + n_query_update, 1, 0, &res) + < 0) { + LM_ERR("while querying db table pua\n"); + if(!no_lock) + lock_release(&HashT->p_records[i].lock); + if(res) + pua_dbf.free_result(pua_db, res); + return; + } + if(res && res->n > 0) { + if(pua_dbf.update(pua_db, q_cols, 0, q_vals, db_cols, + db_vals, n_query_update, n_update_cols) + < 0) { + LM_ERR("while updating in database\n"); if(!no_lock) lock_release(&HashT->p_records[i].lock); - if(res) - pua_dbf.free_result(pua_db, res); - return ; - } - if(res && res->n> 0) - { - if(pua_dbf.update(pua_db, q_cols, 0, q_vals, db_cols, - db_vals, n_query_update, n_update_cols)<0) - { - LM_ERR("while updating in database\n"); - if(!no_lock) - lock_release(&HashT->p_records[i].lock); - pua_dbf.free_result(pua_db, res); - res= NULL; - return ; - } pua_dbf.free_result(pua_db, res); - res= NULL; + res = NULL; + return; } - else - { - if(res) - { - pua_dbf.free_result(pua_db, res); - res= NULL; - } - LM_DBG("UPDATEDB_FLAG and no record found\n"); - // p->db_flag= INSERTDB_FLAG; + pua_dbf.free_result(pua_db, res); + res = NULL; + } else { + if(res) { + pua_dbf.free_result(pua_db, res); + res = NULL; } - break; + LM_DBG("UPDATEDB_FLAG and no record found\n"); + // p->db_flag= INSERTDB_FLAG; + } + break; + } + case INSERTDB_FLAG: { + LM_DBG("INSERTDB_FLAG\n"); + q_vals[puri_col].val.str_val = *(p->pres_uri); + q_vals[pid_col].val.str_val = p->id; + q_vals[flag_col].val.int_val = p->flag; + if(p->call_id.s) { + LM_DBG("p->callid = %.*s\n", p->call_id.len, + p->call_id.s); + q_vals[callid_col].val.str_val = p->call_id; + } else { + LM_DBG("p->callid is empty\n"); + q_vals[callid_col].val.str_val.s = ""; + q_vals[callid_col].val.str_val.len = 0; + } + if(p->from_tag.s) { + q_vals[fromtag_col].val.str_val = p->from_tag; + } else { + LM_DBG("p->from_tag is empty\n"); + q_vals[fromtag_col].val.str_val.s = ""; + q_vals[fromtag_col].val.str_val.len = 0; + } + q_vals[cseq_col].val.int_val = p->cseq; + q_vals[expires_col].val.int_val = p->expires; + q_vals[desired_expires_col].val.int_val = + p->desired_expires; + q_vals[event_col].val.int_val = p->event; + q_vals[version_col].val.int_val = p->version; + + if((p->watcher_uri)) + q_vals[watcher_col].val.str_val = *(p->watcher_uri); + else { + q_vals[watcher_col].val.str_val.s = ""; + q_vals[watcher_col].val.str_val.len = 0; } - case INSERTDB_FLAG: - { - LM_DBG("INSERTDB_FLAG\n"); - q_vals[puri_col].val.str_val = *(p->pres_uri); - q_vals[pid_col].val.str_val = p->id; - q_vals[flag_col].val.int_val = p->flag; - if(p->call_id.s) { - LM_DBG("p->callid = %.*s\n", p->call_id.len, p->call_id.s); - q_vals[callid_col].val.str_val = p->call_id; - } else { - LM_DBG("p->callid is empty\n"); - q_vals[callid_col].val.str_val.s = ""; - q_vals[callid_col].val.str_val.len = 0; - } - if( p->from_tag.s) { - q_vals[fromtag_col].val.str_val = p->from_tag; - } else { - LM_DBG("p->from_tag is empty\n"); - q_vals[fromtag_col].val.str_val.s = ""; - q_vals[fromtag_col].val.str_val.len = 0; - } - q_vals[cseq_col].val.int_val= p->cseq; - q_vals[expires_col].val.int_val = p->expires; - q_vals[desired_expires_col].val.int_val = p->desired_expires; - q_vals[event_col].val.int_val = p->event; - q_vals[version_col].val.int_val = p->version; - - if((p->watcher_uri)) - q_vals[watcher_col].val.str_val = *(p->watcher_uri); - else - { - q_vals[watcher_col].val.str_val.s = ""; - q_vals[watcher_col].val.str_val.len = 0; - } - - if(p->tuple_id.s == NULL) - { - q_vals[tuple_col].val.str_val.s=""; - q_vals[tuple_col].val.str_val.len=0; - } - else - q_vals[tuple_col].val.str_val = p->tuple_id; - - if(p->etag.s == NULL) - { - q_vals[etag_col].val.str_val.s=""; - q_vals[etag_col].val.str_val.len=0; - } - else - q_vals[etag_col].val.str_val = p->etag; - - if (p->to_tag.s == NULL) - { - q_vals[totag_col].val.str_val.s=""; - q_vals[totag_col].val.str_val.len=0; - } - else - q_vals[totag_col].val.str_val = p->to_tag; - - if(p->record_route.s== NULL) - { - q_vals[record_route_col].val.str_val.s= ""; - q_vals[record_route_col].val.str_val.len = 0; - } - else - q_vals[record_route_col].val.str_val = p->record_route; - - if(p->contact.s == NULL) - { - q_vals[contact_col].val.str_val.s = ""; - q_vals[contact_col].val.str_val.len = 0; - } - else - q_vals[contact_col].val.str_val = p->contact; - - if(p->remote_contact.s) - { - q_vals[remote_contact_col].val.str_val = p->remote_contact; - LM_DBG("p->remote_contact = %.*s\n", p->remote_contact.len, p->remote_contact.s); - } - else - { - q_vals[remote_contact_col].val.str_val.s = ""; - q_vals[remote_contact_col].val.str_val.len = 0; - } - if(p->extra_headers) - q_vals[extra_headers_col].val.str_val = *(p->extra_headers); - else - { - q_vals[extra_headers_col].val.str_val.s = ""; - q_vals[extra_headers_col].val.str_val.len = 0; - } + if(p->tuple_id.s == NULL) { + q_vals[tuple_col].val.str_val.s = ""; + q_vals[tuple_col].val.str_val.len = 0; + } else + q_vals[tuple_col].val.str_val = p->tuple_id; + + if(p->etag.s == NULL) { + q_vals[etag_col].val.str_val.s = ""; + q_vals[etag_col].val.str_val.len = 0; + } else + q_vals[etag_col].val.str_val = p->etag; + + if(p->to_tag.s == NULL) { + q_vals[totag_col].val.str_val.s = ""; + q_vals[totag_col].val.str_val.len = 0; + } else + q_vals[totag_col].val.str_val = p->to_tag; + + if(p->record_route.s == NULL) { + q_vals[record_route_col].val.str_val.s = ""; + q_vals[record_route_col].val.str_val.len = 0; + } else + q_vals[record_route_col].val.str_val = p->record_route; + + if(p->contact.s == NULL) { + q_vals[contact_col].val.str_val.s = ""; + q_vals[contact_col].val.str_val.len = 0; + } else + q_vals[contact_col].val.str_val = p->contact; + + if(p->remote_contact.s) { + q_vals[remote_contact_col].val.str_val = + p->remote_contact; + LM_DBG("p->remote_contact = %.*s\n", + p->remote_contact.len, p->remote_contact.s); + } else { + q_vals[remote_contact_col].val.str_val.s = ""; + q_vals[remote_contact_col].val.str_val.len = 0; + } - if(pua_dbf.insert(pua_db, q_cols, q_vals,n_query_cols )<0) - { - LM_ERR("while inserting in db table pua\n"); - if(!no_lock) - lock_release(&HashT->p_records[i].lock); - return ; - } - break; + if(p->extra_headers) + q_vals[extra_headers_col].val.str_val = + *(p->extra_headers); + else { + q_vals[extra_headers_col].val.str_val.s = ""; + q_vals[extra_headers_col].val.str_val.len = 0; } + if(pua_dbf.insert(pua_db, q_cols, q_vals, n_query_cols) + < 0) { + LM_ERR("while inserting in db table pua\n"); + if(!no_lock) + lock_release(&HashT->p_records[i].lock); + return; + } + break; + } } - p->db_flag= NO_UPDATEDB_FLAG; - p= p->next; + p->db_flag = NO_UPDATEDB_FLAG; + p = p->next; } if(!no_lock) lock_release(&HashT->p_records[i].lock); } - db_vals[0].val.int_val= (int)time(NULL)- 10; - db_ops[0]= OP_LT; - if(pua_dbf.delete(pua_db, db_cols, db_ops, db_vals, 1) < 0) - { + db_vals[0].val.int_val = (int)time(NULL) - 10; + db_ops[0] = OP_LT; + if(pua_dbf.delete(pua_db, db_cols, db_ops, db_vals, 1) < 0) { LM_ERR("while deleting from db table pua\n"); } - return ; + return; } -static ua_pres_t* build_uppubl_cbparam(ua_pres_t* p) +static ua_pres_t *build_uppubl_cbparam(ua_pres_t *p) { publ_info_t publ; - ua_pres_t* cb_param= NULL; + ua_pres_t *cb_param = NULL; memset(&publ, 0, sizeof(publ_info_t)); - publ.pres_uri= p->pres_uri; - publ.content_type= p->content_type; - publ.id= p->id; - publ.expires= (p->desired_expires== 0) ?-1:p->desired_expires- (int)time(NULL); - publ.flag= UPDATE_TYPE; - publ.source_flag= p->flag; - publ.event= p->event; - publ.etag= &p->etag; - publ.extra_headers= p->extra_headers; - - cb_param= publish_cbparam(&publ, NULL, &p->tuple_id, REQ_ME); - if(cb_param== NULL) - { + publ.pres_uri = p->pres_uri; + publ.content_type = p->content_type; + publ.id = p->id; + publ.expires = (p->desired_expires == 0) + ? -1 + : p->desired_expires - (int)time(NULL); + publ.flag = UPDATE_TYPE; + publ.source_flag = p->flag; + publ.event = p->event; + publ.etag = &p->etag; + publ.extra_headers = p->extra_headers; + + cb_param = publish_cbparam(&publ, NULL, &p->tuple_id, REQ_ME); + if(cb_param == NULL) { LM_ERR("constructing callback parameter\n"); return NULL; } return cb_param; } -static void pua_rpc_cleanup(rpc_t* rpc, void* ctx) +static void pua_rpc_cleanup(rpc_t *rpc, void *ctx) { LM_DBG("cleaning up\n"); - (void)hashT_clean(0,0); + (void)hashT_clean(0, 0); } -static const char* pua_rpc_cleanup_doc[2] = { - "Execute pua cleanup.", - 0 -}; +static const char *pua_rpc_cleanup_doc[2] = {"Execute pua cleanup.", 0}; rpc_export_t pua_rpc[] = { - {"pua.cleanup", pua_rpc_cleanup, pua_rpc_cleanup_doc, 0}, - {0, 0, 0, 0} -}; + {"pua.cleanup", pua_rpc_cleanup, pua_rpc_cleanup_doc, 0}, {0, 0, 0, 0}}; static int pua_rpc_init(void) { - if (rpc_register_array(pua_rpc)!=0) - { + if(rpc_register_array(pua_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } diff --git a/src/modules/pua/pua.h b/src/modules/pua/pua.h index 7d99c0f796c..54d1b5a27ba 100644 --- a/src/modules/pua/pua.h +++ b/src/modules/pua/pua.h @@ -27,11 +27,11 @@ #include "../../lib/srdb1/db.h" #include "hash.h" -#define INSERT_TYPE 1<<1 -#define UPDATE_TYPE 1<<2 +#define INSERT_TYPE 1 << 1 +#define UPDATE_TYPE 1 << 2 -#define REQ_OTHER 0 -#define REQ_ME 1 +#define REQ_OTHER 0 +#define REQ_ME 1 #define PUA_DB_DEFAULT 0 #define PUA_DB_MODE1_RESERVED 1 @@ -39,7 +39,7 @@ extern str default_domain; extern struct tm_binds tmb; -extern htable_t* HashT; +extern htable_t *HashT; extern int HASH_SIZE; extern int min_expires; extern int pua_ul_publish; @@ -50,8 +50,8 @@ extern int dbmode; extern int reginfo_increase_version; -extern int update_pua(ua_pres_t* p); -extern int clean_puadb( int update_period, int min_expires ); +extern int update_pua(ua_pres_t *p); +extern int clean_puadb(int update_period, int min_expires); extern db_func_t pua_dbf; extern db1_con_t *pua_db; diff --git a/src/modules/pua/pua_bind.c b/src/modules/pua/pua_bind.c index 65a42ee60fc..c795ee48501 100644 --- a/src/modules/pua/pua_bind.c +++ b/src/modules/pua/pua_bind.c @@ -25,21 +25,20 @@ #include "../../core/dprint.h" #include "hash.h" -int bind_pua(pua_api_t* api) +int bind_pua(pua_api_t *api) { - if (!api) { + if(!api) { LM_ERR("Invalid parameter value\n"); return -1; } - api->send_publish = send_publish; - api->send_subscribe = send_subscribe; - api->register_puacb = register_puacb; - api->is_dialog = is_dialog; - api->get_record_id = get_record_id; - api->add_event = add_pua_event; - api->get_subs_list = get_subs_list; + api->send_publish = send_publish; + api->send_subscribe = send_subscribe; + api->register_puacb = register_puacb; + api->is_dialog = is_dialog; + api->get_record_id = get_record_id; + api->add_event = add_pua_event; + api->get_subs_list = get_subs_list; return 0; } - diff --git a/src/modules/pua/pua_bind.h b/src/modules/pua/pua_bind.h index 35c208e05b5..824ee25b67a 100644 --- a/src/modules/pua/pua_bind.h +++ b/src/modules/pua/pua_bind.h @@ -28,7 +28,8 @@ #include "pua_callback.h" #include "hash.h" -typedef struct pua_api { +typedef struct pua_api +{ send_subscribe_t send_subscribe; send_publish_t send_publish; register_puacb_t register_puacb; @@ -38,6 +39,6 @@ typedef struct pua_api { get_subs_list_t get_subs_list; } pua_api_t; -typedef int (*bind_pua_t)(pua_api_t* api); +typedef int (*bind_pua_t)(pua_api_t *api); #endif diff --git a/src/modules/pua/pua_callback.c b/src/modules/pua/pua_callback.c index 2140998111d..9b83bb7d026 100644 --- a/src/modules/pua/pua_callback.c +++ b/src/modules/pua/pua_callback.c @@ -27,14 +27,13 @@ #include "pua_callback.h" -struct puacb_head_list* puacb_list = 0; +struct puacb_head_list *puacb_list = 0; int init_puacb_list(void) { - puacb_list = (struct puacb_head_list*)shm_malloc - ( sizeof(struct puacb_head_list) ); - if (puacb_list==0) - { + puacb_list = (struct puacb_head_list *)shm_malloc( + sizeof(struct puacb_head_list)); + if(puacb_list == 0) { SHM_MEM_ERROR; return -1; } @@ -48,44 +47,40 @@ void destroy_puacb_list(void) { struct pua_callback *cbp, *cbp_tmp; - if (!puacb_list) + if(!puacb_list) return; - for( cbp=puacb_list->first; cbp ; ) - { + for(cbp = puacb_list->first; cbp;) { cbp_tmp = cbp; cbp = cbp->next; - if (cbp_tmp->param) - shm_free( cbp_tmp->param ); - shm_free( cbp_tmp ); + if(cbp_tmp->param) + shm_free(cbp_tmp->param); + shm_free(cbp_tmp); } shm_free(puacb_list); } - /* register a callback function 'f' for 'types' mask of events; */ -int register_puacb( int types, pua_cb f, void* param ) +int register_puacb(int types, pua_cb f, void *param) { struct pua_callback *cbp; /* are the callback types valid?... */ - if ( types<0 || types>PUACB_MAX ) - { - LM_CRIT("invalid callback types: mask=%d\n",types); + if(types < 0 || types > PUACB_MAX) { + LM_CRIT("invalid callback types: mask=%d\n", types); return E_BUG; } /* we don't register null functions */ - if (f==0) - { + if(f == 0) { LM_CRIT("null callback function\n"); return E_BUG; } /* build a new callback structure */ - if (!(cbp=(struct pua_callback*)shm_malloc(sizeof( struct pua_callback)))) - { + if(!(cbp = (struct pua_callback *)shm_malloc( + sizeof(struct pua_callback)))) { SHM_MEM_ERROR; return E_OUT_OF_MEM; } @@ -96,13 +91,12 @@ int register_puacb( int types, pua_cb f, void* param ) puacb_list->reg_types |= types; cbp->callback = f; - cbp->param= param; + cbp->param = param; cbp->types = types; - if (cbp->next) - cbp->id = cbp->next->id+1; + if(cbp->next) + cbp->id = cbp->next->id + 1; else cbp->id = 0; return 1; } - diff --git a/src/modules/pua/pua_callback.h b/src/modules/pua/pua_callback.h index 3a57216c16c..b5f9c48ced3 100644 --- a/src/modules/pua/pua_callback.h +++ b/src/modules/pua/pua_callback.h @@ -26,29 +26,31 @@ #include "../../core/parser/parse_fline.h" #include "../pua/hash.h" -#define PUACB_MAX (1<<9) +#define PUACB_MAX (1 << 9) /* callback function prototype */ -typedef int (pua_cb)(ua_pres_t* hentity, struct sip_msg*); +typedef int(pua_cb)(ua_pres_t *hentity, struct sip_msg *); /* register callback function prototype */ -typedef int (*register_puacb_t)(int types, pua_cb f, void* param ); +typedef int (*register_puacb_t)(int types, pua_cb f, void *param); -struct pua_callback { - int id; /* id of this callback - useless */ - int types; /* types of events that trigger the callback*/ - pua_cb* callback; /* callback function */ - void* param; - struct pua_callback* next; +struct pua_callback +{ + int id; /* id of this callback - useless */ + int types; /* types of events that trigger the callback*/ + pua_cb *callback; /* callback function */ + void *param; + struct pua_callback *next; }; -struct puacb_head_list { +struct puacb_head_list +{ struct pua_callback *first; int reg_types; }; -extern struct puacb_head_list* puacb_list; +extern struct puacb_head_list *puacb_list; int init_puacb_list(void); @@ -56,16 +58,15 @@ void destroy_puacb_list(void); /* register a callback for several types of events */ -int register_puacb( int types, pua_cb f, void* param ); +int register_puacb(int types, pua_cb f, void *param); /* run all transaction callbacks for an event type */ -static inline void run_pua_callbacks(ua_pres_t* hentity, struct sip_msg* msg) +static inline void run_pua_callbacks(ua_pres_t *hentity, struct sip_msg *msg) { struct pua_callback *cbp; - for (cbp= puacb_list->first; cbp; cbp=cbp->next) { - if(cbp->types & hentity->flag) - { + for(cbp = puacb_list->first; cbp; cbp = cbp->next) { + if(cbp->types & hentity->flag) { LM_DBG("found callback\n"); cbp->callback(hentity, msg); } diff --git a/src/modules/pua/pua_db.c b/src/modules/pua/pua_db.c index efa9ad76d68..f66c3b210f7 100644 --- a/src/modules/pua/pua_db.c +++ b/src/modules/pua/pua_db.c @@ -36,34 +36,33 @@ #include "pua_db.h" /* database columns */ -static str str_id_col = str_init( "id" ); +static str str_id_col = str_init("id"); static str str_pres_uri_col = str_init("pres_uri"); static str str_pres_id_col = str_init("pres_id"); -static str str_expires_col= str_init("expires"); -static str str_flag_col= str_init("flag"); -static str str_etag_col= str_init("etag"); -static str str_tuple_id_col= str_init("tuple_id"); -static str str_watcher_uri_col= str_init("watcher_uri"); -static str str_call_id_col= str_init("call_id"); -static str str_to_tag_col= str_init("to_tag"); -static str str_from_tag_col= str_init("from_tag"); -static str str_cseq_col= str_init("cseq"); -static str str_event_col= str_init("event"); -static str str_record_route_col= str_init("record_route"); -static str str_contact_col= str_init("contact"); -static str str_remote_contact_col= str_init("remote_contact"); -static str str_extra_headers_col= str_init("extra_headers"); -static str str_desired_expires_col= str_init("desired_expires"); +static str str_expires_col = str_init("expires"); +static str str_flag_col = str_init("flag"); +static str str_etag_col = str_init("etag"); +static str str_tuple_id_col = str_init("tuple_id"); +static str str_watcher_uri_col = str_init("watcher_uri"); +static str str_call_id_col = str_init("call_id"); +static str str_to_tag_col = str_init("to_tag"); +static str str_from_tag_col = str_init("from_tag"); +static str str_cseq_col = str_init("cseq"); +static str str_event_col = str_init("event"); +static str str_record_route_col = str_init("record_route"); +static str str_contact_col = str_init("contact"); +static str str_remote_contact_col = str_init("remote_contact"); +static str str_extra_headers_col = str_init("extra_headers"); +static str str_desired_expires_col = str_init("desired_expires"); static str str_version_col = str_init("version"); /******************************************************************************/ -void free_results_puadb( db1_res_t *res ) +void free_results_puadb(db1_res_t *res) { - if (res) - { + if(res) { pua_dbf.free_result(pua_db, res); res = NULL; } @@ -71,86 +70,83 @@ void free_results_puadb( db1_res_t *res ) /******************************************************************************/ -static void extract_row( db_val_t *values, ua_pres_t *result ) +static void extract_row(db_val_t *values, ua_pres_t *result) { - if (result->pres_uri != NULL ) - { - result->pres_uri->s = (char *)VAL_STRING(values+1); - result->pres_uri->len = strlen(VAL_STRING(values+1)); + if(result->pres_uri != NULL) { + result->pres_uri->s = (char *)VAL_STRING(values + 1); + result->pres_uri->len = strlen(VAL_STRING(values + 1)); } - result->id.s = (char *)VAL_STRING(values+2); - result->id.len = strlen(VAL_STRING(values+2)); + result->id.s = (char *)VAL_STRING(values + 2); + result->id.len = strlen(VAL_STRING(values + 2)); - result->event = VAL_INT(values+3); + result->event = VAL_INT(values + 3); - result->expires = VAL_INT(values+4); + result->expires = VAL_INT(values + 4); - result->desired_expires = VAL_INT(values+5); + result->desired_expires = VAL_INT(values + 5); - result->flag = VAL_INT(values+6); + result->flag = VAL_INT(values + 6); /* publish */ - result->etag.s = (char *)VAL_STRING(values+7); - result->etag.len = strlen(VAL_STRING(values+7)); + result->etag.s = (char *)VAL_STRING(values + 7); + result->etag.len = strlen(VAL_STRING(values + 7)); - result->tuple_id.s = (char *)VAL_STRING(values+8); - result->tuple_id.len = strlen(VAL_STRING(values+8)); + result->tuple_id.s = (char *)VAL_STRING(values + 8); + result->tuple_id.len = strlen(VAL_STRING(values + 8)); /* subscribe */ - if (result->watcher_uri != NULL ) - { - result->watcher_uri->s = (char *)VAL_STRING(values+9); - result->watcher_uri->len = strlen(VAL_STRING(values+9)); + if(result->watcher_uri != NULL) { + result->watcher_uri->s = (char *)VAL_STRING(values + 9); + result->watcher_uri->len = strlen(VAL_STRING(values + 9)); } - result->call_id.s = (char *)VAL_STRING(values+10); - result->call_id.len = strlen(VAL_STRING(values+10)); + result->call_id.s = (char *)VAL_STRING(values + 10); + result->call_id.len = strlen(VAL_STRING(values + 10)); - result->to_tag.s = (char *)VAL_STRING(values+11); - result->to_tag.len = strlen(VAL_STRING(values+11)); + result->to_tag.s = (char *)VAL_STRING(values + 11); + result->to_tag.len = strlen(VAL_STRING(values + 11)); - result->from_tag.s = (char *)VAL_STRING(values+12); - result->from_tag.len = strlen(VAL_STRING(values+12)); + result->from_tag.s = (char *)VAL_STRING(values + 12); + result->from_tag.len = strlen(VAL_STRING(values + 12)); - result->cseq = VAL_INT(values+13); + result->cseq = VAL_INT(values + 13); - result->record_route.s = (char *)VAL_STRING(values+14); - result->record_route.len = strlen(VAL_STRING(values+14)); + result->record_route.s = (char *)VAL_STRING(values + 14); + result->record_route.len = strlen(VAL_STRING(values + 14)); - result->contact.s = (char *)VAL_STRING(values+15); - result->contact.len = strlen(VAL_STRING(values+15)); + result->contact.s = (char *)VAL_STRING(values + 15); + result->contact.len = strlen(VAL_STRING(values + 15)); - result->remote_contact.s = (char *)VAL_STRING(values+16); - result->remote_contact.len = strlen(VAL_STRING(values+16)); + result->remote_contact.s = (char *)VAL_STRING(values + 16); + result->remote_contact.len = strlen(VAL_STRING(values + 16)); - result->version = VAL_INT(values+17); + result->version = VAL_INT(values + 17); - if (result->extra_headers != NULL ) - { - result->extra_headers->s = (char *)VAL_STRING(values+18); - result->extra_headers->len = strlen(VAL_STRING(values+18)); + if(result->extra_headers != NULL) { + result->extra_headers->s = (char *)VAL_STRING(values + 18); + result->extra_headers->len = strlen(VAL_STRING(values + 18)); } } /******************************************************************************/ -int clean_puadb( int update_period, int min_expires ) +int clean_puadb(int update_period, int min_expires) { int i, nr_rows; db_row_t *rows; db_val_t *values; db_key_t q_cols[1]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_val_t q_vals[1]; - db_op_t q_ops[1]; + db_op_t q_ops[1]; int id; time_t now; ua_pres_t p; - str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0}; + str pres_uri = {0, 0}, watcher_uri = {0, 0}, extra_headers = {0, 0}; memset(&p, 0, sizeof(p)); p.pres_uri = &pres_uri; @@ -163,33 +159,31 @@ int clean_puadb( int update_period, int min_expires ) q_cols[0] = &str_expires_col; q_vals[0].type = DB1_INT; q_vals[0].nul = 0; - q_vals[0].val.int_val = now+update_period; + q_vals[0].val.int_val = now + update_period; q_ops[0] = OP_LT; - if (pua_dbf.use_table(pua_db, &db_table) < 0) { - LM_ERR("error in use_table pua\n"); - return(-1); + if(pua_dbf.use_table(pua_db, &db_table) < 0) { + LM_ERR("error in use_table pua\n"); + return (-1); } - if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, q_cols, q_ops, - q_vals, NULL, 1, 0, 0, &res) < 0) - { + if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, q_cols, q_ops, q_vals, + NULL, 1, 0, 0, &res) + < 0) { LM_ERR("DB query error\n"); - return(-1); + return (-1); } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); - return(-1); + return (-1); } - if (RES_ROW_N(res) == 0) - { + if(RES_ROW_N(res) == 0) { /* no match */ - LM_DBG( "No records matched for clean\n"); + LM_DBG("No records matched for clean\n"); pua_dbf.free_result(pua_db, res); - return(0); + return (0); } do { @@ -198,42 +192,38 @@ int clean_puadb( int update_period, int min_expires ) /* get the results and update matching entries */ rows = RES_ROWS(res); - for (i=0; i < nr_rows; i++) - { - values = ROW_VALUES(rows+i); + for(i = 0; i < nr_rows; i++) { + values = ROW_VALUES(rows + i); - extract_row( values, &p ); + extract_row(values, &p); id = VAL_INT(values); - if((p.desired_expires> p.expires + min_expires) || (p.desired_expires== 0 )) - { - if(update_pua(&p)< 0) - { + if((p.desired_expires > p.expires + min_expires) + || (p.desired_expires == 0)) { + if(update_pua(&p) < 0) { LM_ERR("update_pua failed\n"); } continue; } - if(p.expires < now - 10) - { - LM_DBG("Found expired: uri= %.*s\n", p.pres_uri->len, p.pres_uri->s); + if(p.expires < now - 10) { + LM_DBG("Found expired: uri= %.*s\n", p.pres_uri->len, + p.pres_uri->s); q_cols[0] = &str_id_col; q_vals[0].type = DB1_INT; q_vals[0].nul = 0; q_vals[0].val.int_val = id; - if ( pua_dbf.delete(pua_db, q_cols, 0, q_vals, 1) < 0 ) - { - LM_ERR( "Failed to delete from db\n" ); + if(pua_dbf.delete(pua_db, q_cols, 0, q_vals, 1) < 0) { + LM_ERR("Failed to delete from db\n"); } } - } - } while ((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res)==1) - && (RES_ROWS(res)>0)); + } while((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res) == 1) + && (RES_ROWS(res) > 0)); pua_dbf.free_result(pua_db, res); - return(0); + return (0); } /******************************************************************************/ @@ -243,14 +233,13 @@ int is_dialog_puadb(ua_pres_t *pres) { int nr_rows; db_key_t q_cols[3], res_cols[1]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_val_t q_vals[3]; - int n_query_cols= 0, n_res_cols=0; + int n_query_cols = 0, n_res_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } /* cols and values used for search query */ @@ -276,49 +265,44 @@ int is_dialog_puadb(ua_pres_t *pres) res_cols[n_res_cols] = &str_id_col; n_res_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if(pua_dbf.query(pua_db, q_cols, 0, q_vals, - res_cols,n_query_cols,n_res_cols,0,&res) < 0) - { + if(pua_dbf.query(pua_db, q_cols, 0, q_vals, res_cols, n_query_cols, + n_res_cols, 0, &res) + < 0) { LM_ERR("DB query error\n"); - return(-1); + return (-1); } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); - return(-1); + return (-1); } nr_rows = RES_ROW_N(res); pua_dbf.free_result(pua_db, res); - if (nr_rows == 0) - { + if(nr_rows == 0) { /* no match */ LM_DBG("No rows found.\n"); - return(-1); + return (-1); } - if (nr_rows != 1) - { + if(nr_rows != 1) { LM_WARN("Too many rows found (%d)\n", nr_rows); /* no need to return here - drop thro */ } /* established dialog */ - if(pres->to_tag.len>0) + if(pres->to_tag.len > 0) return 0; /* temporary dialog */ return 1; @@ -326,23 +310,22 @@ int is_dialog_puadb(ua_pres_t *pres) /******************************************************************************/ -int get_record_id_puadb(ua_pres_t *pres, str **rec_id ) +int get_record_id_puadb(ua_pres_t *pres, str **rec_id) { int nr_rows; db_row_t *rows; db_key_t q_cols[3], res_cols[2]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_val_t q_vals[3]; - int n_query_cols=0, n_res_cols=0; + int n_query_cols = 0, n_res_cols = 0; db_val_t *values; str *id; str to_tag; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } /* cols and values used for search query */ @@ -369,127 +352,120 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id ) *rec_id = NULL; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if(pua_dbf.query(pua_db, q_cols, 0, q_vals, - res_cols,n_query_cols,n_res_cols,0,&res) < 0) - { + if(pua_dbf.query(pua_db, q_cols, 0, q_vals, res_cols, n_query_cols, + n_res_cols, 0, &res) + < 0) { LM_ERR("DB query error\n"); - return(-1); + return (-1); } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); - return(-1); + return (-1); } nr_rows = RES_ROW_N(res); - switch (nr_rows) - { - case 1: - rows = RES_ROWS(res); - values = ROW_VALUES(rows); - break; - - case 0: - /* no match */ - LM_DBG("No rows found. Looking for temporary dialog\n"); - pua_dbf.free_result(pua_db, res); - - n_query_cols--; - - res_cols[n_res_cols] = &str_to_tag_col; - n_res_cols++; + switch(nr_rows) { + case 1: + rows = RES_ROWS(res); + values = ROW_VALUES(rows); + break; - if(pua_dbf.query(pua_db, q_cols, 0, q_vals, - res_cols,n_query_cols,n_res_cols,0,&res) < 0) - { - LM_ERR("DB query error\n"); - return(-1); - } + case 0: + /* no match */ + LM_DBG("No rows found. Looking for temporary dialog\n"); + pua_dbf.free_result(pua_db, res); - if (res == NULL) - { - LM_ERR("bad result\n"); - return(-1); - } + n_query_cols--; - nr_rows = RES_ROW_N(res); + res_cols[n_res_cols] = &str_to_tag_col; + n_res_cols++; - if (nr_rows == 1) - { - rows = RES_ROWS(res); - values = ROW_VALUES(rows); + if(pua_dbf.query(pua_db, q_cols, 0, q_vals, res_cols, n_query_cols, + n_res_cols, 0, &res) + < 0) { + LM_ERR("DB query error\n"); + return (-1); + } - to_tag.s = (char *) VAL_STRING(values + 1); - to_tag.len = strlen(to_tag.s); + if(res == NULL) { + LM_ERR("bad result\n"); + return (-1); + } - if (to_tag.len == 0 || - (to_tag.len > 0 - && strncmp(to_tag.s, pres->to_tag.s, pres->to_tag.len) == 0)) - { - LM_DBG( "Found a (possibly temporary) Dialog\n" ); - break; + nr_rows = RES_ROW_N(res); + + if(nr_rows == 1) { + rows = RES_ROWS(res); + values = ROW_VALUES(rows); + + to_tag.s = (char *)VAL_STRING(values + 1); + to_tag.len = strlen(to_tag.s); + + if(to_tag.len == 0 + || (to_tag.len > 0 + && strncmp(to_tag.s, pres->to_tag.s, + pres->to_tag.len) + == 0)) { + LM_DBG("Found a (possibly temporary) Dialog\n"); + break; + } else + LM_WARN("Failed to find temporary dialog for To-tag: %.*s, " + "found To-tag: %.*s\n", + pres->to_tag.len, pres->to_tag.s, to_tag.len, + to_tag.s); } - else - LM_WARN("Failed to find temporary dialog for To-tag: %.*s, found To-tag: %.*s\n", - pres->to_tag.len, pres->to_tag.s, to_tag.len, to_tag.s); - } - if (nr_rows <= 1) - { - LM_DBG("Dialog not found\n" ); - pua_dbf.free_result(pua_db, res); - return(0); - } + if(nr_rows <= 1) { + LM_DBG("Dialog not found\n"); + pua_dbf.free_result(pua_db, res); + return (0); + } - /* Fall-thru */ + /* Fall-thru */ - default: - LM_ERR("Too many rows found (%d)\n", nr_rows); - pua_dbf.free_result(pua_db, res); - return(-1); + default: + LM_ERR("Too many rows found (%d)\n", nr_rows); + pua_dbf.free_result(pua_db, res); + return (-1); } - id= (str*)pkg_malloc(sizeof(str)); + id = (str *)pkg_malloc(sizeof(str)); - if(id== NULL) - { + if(id == NULL) { PKG_MEM_ERROR; pua_dbf.free_result(pua_db, res); - return(-1); + return (-1); } - id->s= (char*)pkg_malloc( strlen(VAL_STRING(values)) * sizeof(char)); + id->s = (char *)pkg_malloc(strlen(VAL_STRING(values)) * sizeof(char)); - if(id->s== NULL) - { + if(id->s == NULL) { PKG_MEM_ERROR; pkg_free(id); pua_dbf.free_result(pua_db, res); - return(-1); + return (-1); } - memcpy(id->s, VAL_STRING(values), strlen(VAL_STRING(values)) ); - id->len= strlen(VAL_STRING(values)); + memcpy(id->s, VAL_STRING(values), strlen(VAL_STRING(values))); + id->len = strlen(VAL_STRING(values)); - *rec_id= id; + *rec_id = id; pua_dbf.free_result(pua_db, res); LM_DBG("Found id=%.*s\n", id->len, id->s); - return(0); + return (0); } /******************************************************************************/ @@ -499,18 +475,17 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres) db_val_t query_vals[18]; int n_query_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } /* The columns I need to query to find the temporary dialog */ - query_cols[n_query_cols] = &str_pres_id_col; - query_vals[n_query_cols].type = DB1_STR; - query_vals[n_query_cols].nul = 0; - query_vals[n_query_cols].val.str_val = pres->id; - n_query_cols++; + query_cols[n_query_cols] = &str_pres_id_col; + query_vals[n_query_cols].type = DB1_STR; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.str_val = pres->id; + n_query_cols++; query_cols[n_query_cols] = &str_pres_uri_col; query_vals[n_query_cols].type = DB1_STR; @@ -589,13 +564,10 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres) query_cols[n_query_cols] = &str_extra_headers_col; query_vals[n_query_cols].type = DB1_STR; query_vals[n_query_cols].nul = 0; - if (pres->extra_headers) - { + if(pres->extra_headers) { query_vals[n_query_cols].val.str_val.s = pres->extra_headers->s; query_vals[n_query_cols].val.str_val.len = pres->extra_headers->len; - } - else - { + } else { query_vals[n_query_cols].val.str_val.s = ""; query_vals[n_query_cols].val.str_val.len = 0; } @@ -628,35 +600,29 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres) query_vals[n_query_cols].val.str_val.len = 0; n_query_cols++; - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if (pua_dbf.replace != NULL) - { - if (pua_dbf.replace(pua_db, query_cols, query_vals, n_query_cols, - 4, 0) < 0) - { + if(pua_dbf.replace != NULL) { + if(pua_dbf.replace(pua_db, query_cols, query_vals, n_query_cols, 4, 0) + < 0) { LM_ERR("Failed replace db\n"); return -1; } - } - else - { - if (pua_dbf.update(pua_db, query_cols, 0, query_vals, - query_cols + 4, query_vals + 4, 4, n_query_cols - 4) < 0) - { + } else { + if(pua_dbf.update(pua_db, query_cols, 0, query_vals, query_cols + 4, + query_vals + 4, 4, n_query_cols - 4) + < 0) { LM_ERR("Failed update db\n"); return -1; } LM_DBG("affected_rows: %d\n", pua_dbf.affected_rows(pua_db)); - if (pua_dbf.affected_rows(pua_db) == 0) - { - if (pua_dbf.insert(pua_db, query_cols, query_vals, n_query_cols) < 0) - { + if(pua_dbf.affected_rows(pua_db) == 0) { + if(pua_dbf.insert(pua_db, query_cols, query_vals, n_query_cols) + < 0) { LM_ERR("Failed insert db\n"); return -1; } @@ -672,17 +638,16 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres) /******************************************************************************/ -int insert_record_puadb(ua_pres_t* pres) +int insert_record_puadb(ua_pres_t *pres) { db_key_t db_cols[18]; db_val_t db_vals[18]; - int n_cols= 0; + int n_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } db_cols[n_cols] = &str_pres_uri_col; @@ -801,43 +766,40 @@ int insert_record_puadb(ua_pres_t* pres) db_cols[n_cols] = &str_extra_headers_col; db_vals[n_cols].type = DB1_STR; db_vals[n_cols].nul = 0; - if (pres->extra_headers) - { + if(pres->extra_headers) { db_vals[n_cols].val.str_val.s = pres->extra_headers->s; db_vals[n_cols].val.str_val.len = pres->extra_headers->len; - } - else - { + } else { db_vals[n_cols].val.str_val.s = ""; db_vals[n_cols].val.str_val.len = 0; } n_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0) - { + if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0) { LM_ERR("DB insert failed\n"); - return(-1); + return (-1); } - return(0); + return (0); } /******************************************************************************/ -ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t **dbres) +ua_pres_t *get_record_puadb( + str pres_id, str *etag, ua_pres_t *result, db1_res_t **dbres) { db_key_t q_cols[2]; db_val_t q_vals[2], *values; db_row_t *rows; db1_res_t *res; int n_query_cols = 0, nr_rows; - db_query_f query_fn = pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query; + db_query_f query_fn = + pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query; q_cols[n_query_cols] = &str_pres_id_col; q_vals[n_query_cols].type = DB1_STR; @@ -845,8 +807,7 @@ ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t q_vals[n_query_cols].val.str_val = pres_id; n_query_cols++; - if (etag != NULL) - { + if(etag != NULL) { q_cols[n_query_cols] = &str_etag_col; q_vals[n_query_cols].type = DB1_STR; q_vals[n_query_cols].nul = 0; @@ -855,57 +816,51 @@ ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t n_query_cols++; } - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(NULL); + return (NULL); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(NULL); + return (NULL); } - if(query_fn(pua_db, q_cols, 0, q_vals, - NULL,n_query_cols,0,0,&res) < 0) - { + if(query_fn(pua_db, q_cols, 0, q_vals, NULL, n_query_cols, 0, 0, &res) + < 0) { LM_ERR("DB query error\n"); - return(NULL); + return (NULL); } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); - return(NULL); + return (NULL); } nr_rows = RES_ROW_N(res); - if (nr_rows == 0) - { + if(nr_rows == 0) { /* no match */ LM_DBG("No rows found\n"); pua_dbf.free_result(pua_db, res); - return(NULL); + return (NULL); } - if (nr_rows != 1) - { + if(nr_rows != 1) { LM_ERR("Too many rows found (%d)\n", nr_rows); pua_dbf.free_result(pua_db, res); - return(NULL); + return (NULL); } /* get the results and fill in return data structure */ rows = RES_ROWS(res); values = ROW_VALUES(rows); - extract_row( values, result ); + extract_row(values, result); *dbres = res; - return(result); + return (result); } /******************************************************************************/ @@ -916,10 +871,9 @@ int delete_record_puadb(ua_pres_t *pres) db_val_t q_vals[2]; int n_query_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } q_cols[n_query_cols] = &str_pres_id_col; @@ -928,8 +882,7 @@ int delete_record_puadb(ua_pres_t *pres) q_vals[n_query_cols].val.str_val = pres->id; n_query_cols++; - if (pres->etag.s) - { + if(pres->etag.s) { q_cols[n_query_cols] = &str_etag_col; q_vals[n_query_cols].type = DB1_STR; q_vals[n_query_cols].nul = 0; @@ -937,20 +890,17 @@ int delete_record_puadb(ua_pres_t *pres) n_query_cols++; } - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) - { + if(pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) { LM_ERR("deleting record\n"); return -1; } @@ -966,10 +916,9 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag) db_val_t q_vals[2], u_vals[3]; int n_query_cols = 0, n_update_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } q_cols[n_query_cols] = &str_pres_id_col; @@ -978,8 +927,7 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag) q_vals[n_query_cols].val.str_val = pres->id; n_query_cols++; - if (pres->etag.s) - { + if(pres->etag.s) { q_cols[n_query_cols] = &str_etag_col; q_vals[n_query_cols].type = DB1_STR; q_vals[n_query_cols].nul = 0; @@ -996,11 +944,10 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag) u_cols[n_update_cols] = &str_expires_col; u_vals[n_update_cols].type = DB1_INT; u_vals[n_update_cols].nul = 0; - u_vals[n_update_cols].val.int_val = expires + (int) time(NULL); + u_vals[n_update_cols].val.int_val = expires + (int)time(NULL); n_update_cols++; - if (etag) - { + if(etag) { u_cols[n_update_cols] = &str_etag_col; u_vals[n_update_cols].type = DB1_STR; u_vals[n_update_cols].nul = 0; @@ -1009,26 +956,24 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag) n_update_cols++; } - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if (pua_dbf.update(pua_db, q_cols, 0, q_vals, u_cols, u_vals, - n_query_cols, n_update_cols) < 0) - { + if(pua_dbf.update(pua_db, q_cols, 0, q_vals, u_cols, u_vals, n_query_cols, + n_update_cols) + < 0) { LM_ERR("updating dialog\n"); return -1; } - if (pua_dbf.affected_rows != NULL) + if(pua_dbf.affected_rows != NULL) return pua_dbf.affected_rows(pua_db); return 1; @@ -1036,17 +981,16 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag) /******************************************************************************/ -int insert_dialog_puadb(ua_pres_t* pres) +int insert_dialog_puadb(ua_pres_t *pres) { db_key_t db_cols[18]; db_val_t db_vals[18]; - int n_cols= 0; + int n_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } db_cols[n_cols] = &str_pres_uri_col; @@ -1165,48 +1109,45 @@ int insert_dialog_puadb(ua_pres_t* pres) db_cols[n_cols] = &str_extra_headers_col; db_vals[n_cols].type = DB1_STR; db_vals[n_cols].nul = 0; - if (pres->extra_headers) - { + if(pres->extra_headers) { db_vals[n_cols].val.str_val.s = pres->extra_headers->s; db_vals[n_cols].val.str_val.len = pres->extra_headers->len; - } - else - { + } else { db_vals[n_cols].val.str_val.s = ""; db_vals[n_cols].val.str_val.len = 0; } n_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0) - { + if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0) { LM_ERR("DB insert failed\n"); - return(-1); + return (-1); } - return(0); + return (0); } /******************************************************************************/ -ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_res_t **dbres) +ua_pres_t *get_dialog_puadb( + str pres_id, str *pres_uri, ua_pres_t *result, db1_res_t **dbres) { db_key_t q_cols[2]; db_val_t q_vals[2], *values; db_row_t *rows; db1_res_t *res; int n_query_cols = 0, nr_rows; - db_query_f query_fn = pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query; + db_query_f query_fn = + pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query; - if (pres_uri == NULL) - { - LM_ERR("Attempting to search for a dialog without specifying pres_uri\n"); - return(NULL); + if(pres_uri == NULL) { + LM_ERR("Attempting to search for a dialog without specifying " + "pres_uri\n"); + return (NULL); } q_cols[n_query_cols] = &str_pres_id_col; @@ -1222,61 +1163,54 @@ ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_r q_vals[n_query_cols].val.str_val.len = pres_uri->len; n_query_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(NULL); + return (NULL); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(NULL); + return (NULL); } - if(query_fn(pua_db, q_cols, 0, q_vals, - NULL,n_query_cols,0,0,&res) < 0) - { + if(query_fn(pua_db, q_cols, 0, q_vals, NULL, n_query_cols, 0, 0, &res) + < 0) { LM_ERR("DB query error\n"); - return(NULL); + return (NULL); } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); - return(NULL); + return (NULL); } nr_rows = RES_ROW_N(res); - if (nr_rows == 0) - { + if(nr_rows == 0) { /* no match */ LM_DBG("No rows found\n"); pua_dbf.free_result(pua_db, res); - return(NULL); - } - else if (nr_rows > 1) - { + return (NULL); + } else if(nr_rows > 1) { LM_ERR("Too many rows found (%d)... deleting\n", nr_rows); pua_dbf.free_result(pua_db, res); - if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) + if(pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) LM_ERR("deleting record(s)\n"); - return(NULL); + return (NULL); } /* get the results and fill in return data structure */ rows = RES_ROWS(res); values = ROW_VALUES(rows); - extract_row( values, result ); + extract_row(values, result); /*pua_dbf.free_result(pua_db, res);*/ *dbres = res; - return(result); + return (result); } /******************************************************************************/ @@ -1287,10 +1221,9 @@ int delete_dialog_puadb(ua_pres_t *pres) db_val_t q_vals[3]; int n_query_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } q_cols[n_query_cols] = &str_call_id_col; @@ -1305,8 +1238,7 @@ int delete_dialog_puadb(ua_pres_t *pres) q_vals[n_query_cols].val.str_val = pres->from_tag; n_query_cols++; - if (pres->to_tag.len > 0 && pres->to_tag.s != NULL) - { + if(pres->to_tag.len > 0 && pres->to_tag.s != NULL) { q_cols[n_query_cols] = &str_to_tag_col; q_vals[n_query_cols].type = DB1_STR; q_vals[n_query_cols].nul = 0; @@ -1314,20 +1246,17 @@ int delete_dialog_puadb(ua_pres_t *pres) n_query_cols++; } - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) - { + if(pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) { LM_ERR("deleting record\n"); return -1; } @@ -1343,10 +1272,9 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact) db_val_t q_vals[3], u_vals[4]; int n_query_cols = 0, n_update_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } q_cols[n_query_cols] = &str_call_id_col; @@ -1376,7 +1304,7 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact) u_cols[n_update_cols] = &str_expires_col; u_vals[n_update_cols].type = DB1_INT; u_vals[n_update_cols].nul = 0; - u_vals[n_update_cols].val.int_val = expires + (int) time(NULL); + u_vals[n_update_cols].val.int_val = expires + (int)time(NULL); n_update_cols++; u_cols[n_update_cols] = &str_cseq_col; @@ -1392,21 +1320,19 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact) u_vals[n_update_cols].val.str_val.len = contact->len; n_update_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if (pua_dbf.update(pua_db, q_cols, 0, q_vals, u_cols, u_vals, - n_query_cols, n_update_cols) < 0) - { + if(pua_dbf.update(pua_db, q_cols, 0, q_vals, u_cols, u_vals, n_query_cols, + n_update_cols) + < 0) { LM_ERR("updating dialog\n"); return -1; } @@ -1421,12 +1347,11 @@ int update_contact_puadb(ua_pres_t *pres, str *contact) { db_key_t q_cols[3], db_cols[1]; db_val_t q_vals[3], db_vals[1]; - int n_query_cols= 0, n_update_cols=0; + int n_query_cols = 0, n_update_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } /* cols and values used for search query */ @@ -1457,26 +1382,24 @@ int update_contact_puadb(ua_pres_t *pres, str *contact) n_update_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if(pua_dbf.update(pua_db, q_cols, 0, q_vals, - db_cols,db_vals,n_query_cols,n_update_cols) < 0) - { + if(pua_dbf.update(pua_db, q_cols, 0, q_vals, db_cols, db_vals, n_query_cols, + n_update_cols) + < 0) { LM_ERR("DB update failed\n"); - return(-1); + return (-1); } - return(0); + return (0); } @@ -1487,12 +1410,11 @@ int update_version_puadb(ua_pres_t *pres) { db_key_t q_cols[1], db_cols[1]; db_val_t q_vals[1], db_vals[1]; - int n_query_cols= 0, n_update_cols=0; + int n_query_cols = 0, n_update_cols = 0; - if (pres==NULL) - { + if(pres == NULL) { LM_ERR("called with NULL param\n"); - return(-1); + return (-1); } /* cols and values used for search query */ @@ -1509,27 +1431,26 @@ int update_version_puadb(ua_pres_t *pres) db_vals[n_update_cols].val.int_val = pres->version; n_update_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); - return(-1); + return (-1); } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(-1); + return (-1); } - if(pua_dbf.update(pua_db, q_cols, 0, q_vals, - db_cols,db_vals,n_query_cols,n_update_cols) < 0) + if(pua_dbf.update(pua_db, q_cols, 0, q_vals, db_cols, db_vals, n_query_cols, + n_update_cols) + < 0) { LM_ERR("DB update failed\n"); - return(-1); + return (-1); } - return(0); + return (0); } /******************************************************************************/ @@ -1538,9 +1459,9 @@ list_entry_t *get_subs_list_puadb(str *did) { list_entry_t *list = NULL; db_key_t q_cols[1], res_cols[1]; - db1_res_t *res= NULL; + db1_res_t *res = NULL; db_val_t q_vals[1]; - int n_query_cols= 0, n_res_cols = 0; + int n_query_cols = 0, n_res_cols = 0; /* cols and values used for search query */ q_cols[n_query_cols] = &str_pres_id_col; @@ -1553,34 +1474,30 @@ list_entry_t *get_subs_list_puadb(str *did) res_cols[n_res_cols] = &str_pres_uri_col; n_res_cols++; - if(pua_db == NULL) - { + if(pua_db == NULL) { LM_ERR("null database connection\n"); return list; } - if (pua_dbf.use_table(pua_db, &db_table) < 0) - { + if(pua_dbf.use_table(pua_db, &db_table) < 0) { LM_ERR("error in use_table pua\n"); - return(list); + return (list); } - if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, q_cols, 0, - q_vals, res_cols, n_query_cols, n_res_cols, 0, &res) < 0) - { + if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, q_cols, 0, q_vals, + res_cols, n_query_cols, n_res_cols, 0, &res) + < 0) { LM_ERR("DB query error\n"); return list; } - if (res == NULL) - { + if(res == NULL) { LM_ERR("bad result\n"); return list; } - if (RES_ROW_N(res) == 0) - { - LM_INFO( "No records found\n"); + if(RES_ROW_N(res) == 0) { + LM_INFO("No records found\n"); pua_dbf.free_result(pua_db, res); return list; } @@ -1591,20 +1508,18 @@ list_entry_t *get_subs_list_puadb(str *did) nr_rows = RES_ROW_N(res); rows = RES_ROWS(res); - for (i=0; i < nr_rows; i++) - { + for(i = 0; i < nr_rows; i++) { str strng, *tmp_str; - strng.s = (char *) VAL_STRING(ROW_VALUES(rows+i)); - strng.len = strlen(VAL_STRING(ROW_VALUES(rows+i))); + strng.s = (char *)VAL_STRING(ROW_VALUES(rows + i)); + strng.len = strlen(VAL_STRING(ROW_VALUES(rows + i))); - if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL) - { + if((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL) { PKG_MEM_ERROR; pua_dbf.free_result(pua_db, res); return list; } - if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * strng.len + 1)) == NULL) - { + if((tmp_str->s = (char *)pkg_malloc(sizeof(char) * strng.len + 1)) + == NULL) { pkg_free(tmp_str); PKG_MEM_ERROR; pua_dbf.free_result(pua_db, res); @@ -1616,8 +1531,8 @@ list_entry_t *get_subs_list_puadb(str *did) list = list_insert(tmp_str, list, NULL); } - } while ((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res)==1) - && (RES_ROWS(res)>0)); + } while((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res) == 1) + && (RES_ROWS(res) > 0)); pua_dbf.free_result(pua_db, res); diff --git a/src/modules/pua/pua_db.h b/src/modules/pua/pua_db.h index c5e7a0b383b..98fd0cb116c 100644 --- a/src/modules/pua/pua_db.h +++ b/src/modules/pua/pua_db.h @@ -26,38 +26,40 @@ #include "../../lib/srdb1/db.h" #include "../rls/list.h" -#define PUA_PRES_URI (1<<0) -#define PUA_PRES_ID (1<<1) -#define PUA_EVENT (1<<2) -#define PUA_EXPIRES (1<<3) -#define PUA_DESIRED_EXPIRES (1<<4) -#define PUA_FLAG (1<<5) -#define PUA_ETAG (1<<6) -#define PUA_TUPLE_ID (1<<7) -#define PUA_WATCHER_URI (1<<8) -#define PUA_CALL_ID (1<<9) -#define PUA_TO_TAG (1<<10) -#define PUA_FROM_TAG (1<<11) -#define PUA_CSEQ (1<<12) -#define PUA_RECORD_ROUTE (1<<13) -#define PUA_CONTACT (1<<14) -#define PUA_REMOTE_CONTACT (1<<15) -#define PUA_VERSION (1<<16) -#define PUA_EXTRA_HEADERS (1<<17) +#define PUA_PRES_URI (1 << 0) +#define PUA_PRES_ID (1 << 1) +#define PUA_EVENT (1 << 2) +#define PUA_EXPIRES (1 << 3) +#define PUA_DESIRED_EXPIRES (1 << 4) +#define PUA_FLAG (1 << 5) +#define PUA_ETAG (1 << 6) +#define PUA_TUPLE_ID (1 << 7) +#define PUA_WATCHER_URI (1 << 8) +#define PUA_CALL_ID (1 << 9) +#define PUA_TO_TAG (1 << 10) +#define PUA_FROM_TAG (1 << 11) +#define PUA_CSEQ (1 << 12) +#define PUA_RECORD_ROUTE (1 << 13) +#define PUA_CONTACT (1 << 14) +#define PUA_REMOTE_CONTACT (1 << 15) +#define PUA_VERSION (1 << 16) +#define PUA_EXTRA_HEADERS (1 << 17) -void free_results_puadb( db1_res_t *res ); +void free_results_puadb(db1_res_t *res); int is_dialog_puadb(ua_pres_t *pres); -int get_record_id_puadb(ua_pres_t *pres, str **rec_id ); +int get_record_id_puadb(ua_pres_t *pres, str **rec_id); int convert_temporary_dialog_puadb(ua_pres_t *pres); -int insert_dialog_puadb(ua_pres_t* pres); -ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_res_t **res); +int insert_dialog_puadb(ua_pres_t *pres); +ua_pres_t *get_dialog_puadb( + str pres_id, str *pres_uri, ua_pres_t *result, db1_res_t **res); int delete_dialog_puadb(ua_pres_t *pres); int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact); list_entry_t *get_subs_list_puadb(str *did); -int insert_record_puadb(ua_pres_t* pres); -ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t **res); +int insert_record_puadb(ua_pres_t *pres); +ua_pres_t *get_record_puadb( + str pres_id, str *etag, ua_pres_t *result, db1_res_t **res); int delete_record_puadb(ua_pres_t *pres); int update_record_puadb(ua_pres_t *pres, int expires, str *contact); int update_version_puadb(ua_pres_t *pres); diff --git a/src/modules/pua/send_publish.c b/src/modules/pua/send_publish.c index c19ff1b9651..48e92e9728b 100644 --- a/src/modules/pua/send_publish.c +++ b/src/modules/pua/send_publish.c @@ -45,116 +45,102 @@ extern db_locking_t db_table_lock; -str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag, - str* extra_headers, int is_body) +str *publ_build_hdr(int expires, pua_event_t *ev, str *content_type, str *etag, + str *extra_headers, int is_body) { static char buf[3000]; - str* str_hdr = NULL; - char* expires_s = NULL; + str *str_hdr = NULL; + char *expires_s = NULL; int len = 0; - int t= 0; + int t = 0; str ctype; - str_hdr =(str*)pkg_malloc(sizeof(str)); - if(str_hdr== NULL) - { + str_hdr = (str *)pkg_malloc(sizeof(str)); + if(str_hdr == NULL) { PKG_MEM_ERROR; return NULL; } - memset(str_hdr, 0 , sizeof(str)); + memset(str_hdr, 0, sizeof(str)); memset(buf, 0, 2999); str_hdr->s = buf; - str_hdr->len= 0; + str_hdr->len = 0; - memcpy(str_hdr->s ,"Max-Forwards: ", 14); + memcpy(str_hdr->s, "Max-Forwards: ", 14); str_hdr->len = 14; - str_hdr->len+= sprintf(str_hdr->s+ str_hdr->len,"%d", MAX_FORWARD); - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + str_hdr->len += sprintf(str_hdr->s + str_hdr->len, "%d", MAX_FORWARD); + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - memcpy(str_hdr->s+ str_hdr->len ,"Event: ", 7); - str_hdr->len+= 7; - memcpy(str_hdr->s+ str_hdr->len, ev->name.s, ev->name.len); - str_hdr->len+= ev->name.len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, "Event: ", 7); + str_hdr->len += 7; + memcpy(str_hdr->s + str_hdr->len, ev->name.s, ev->name.len); + str_hdr->len += ev->name.len; + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - memcpy(str_hdr->s+str_hdr->len ,"Expires: ", 9); + memcpy(str_hdr->s + str_hdr->len, "Expires: ", 9); str_hdr->len += 9; - t= expires; + t = expires; - if( t<=0 ) - { - t= min_expires; - } - else - { + if(t <= 0) { + t = min_expires; + } else { t++; } expires_s = int2str(t, &len); - memcpy(str_hdr->s+str_hdr->len, expires_s, len); - str_hdr->len+= len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, expires_s, len); + str_hdr->len += len; + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - if(etag) - { + if(etag) { LM_DBG("UPDATE_TYPE [etag]= %.*s\n", etag->len, etag->s); - memcpy(str_hdr->s+str_hdr->len,"SIP-If-Match: ", 14); + memcpy(str_hdr->s + str_hdr->len, "SIP-If-Match: ", 14); str_hdr->len += 14; - memcpy(str_hdr->s+str_hdr->len, etag->s, etag->len); + memcpy(str_hdr->s + str_hdr->len, etag->s, etag->len); str_hdr->len += etag->len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; } - if(is_body) - { - if(content_type== NULL || content_type->s== NULL || content_type->len== 0) - { - ctype= ev->content_type; /* use event default value */ - } - else - { - ctype.s= content_type->s; - ctype.len= content_type->len; + if(is_body) { + if(content_type == NULL || content_type->s == NULL + || content_type->len == 0) { + ctype = ev->content_type; /* use event default value */ + } else { + ctype.s = content_type->s; + ctype.len = content_type->len; } - memcpy(str_hdr->s+str_hdr->len,"Content-Type: ", 14); + memcpy(str_hdr->s + str_hdr->len, "Content-Type: ", 14); str_hdr->len += 14; - memcpy(str_hdr->s+str_hdr->len, ctype.s, ctype.len); + memcpy(str_hdr->s + str_hdr->len, ctype.s, ctype.len); str_hdr->len += ctype.len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; } - if(extra_headers && extra_headers->s && extra_headers->len) - { - memcpy(str_hdr->s+str_hdr->len,extra_headers->s , extra_headers->len); + if(extra_headers && extra_headers->s && extra_headers->len) { + memcpy(str_hdr->s + str_hdr->len, extra_headers->s, extra_headers->len); str_hdr->len += extra_headers->len; } str_hdr->s[str_hdr->len] = '\0'; return str_hdr; - } static void find_and_delete_record(ua_pres_t *dialog, int hash_code) { ua_pres_t *presentity; - if (dbmode == PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { delete_record_puadb(dialog); - } - else - { + } else { lock_get(&HashT->p_records[hash_code].lock); presentity = search_htable(dialog, hash_code); - if (presentity == NULL) - { + if(presentity == NULL) { LM_DBG("Record found in table and deleted\n"); lock_release(&HashT->p_records[hash_code].lock); return; @@ -164,25 +150,23 @@ static void find_and_delete_record(ua_pres_t *dialog, int hash_code) } } -static int find_and_update_record(ua_pres_t *dialog, int hash_code, int lexpire, str *etag) +static int find_and_update_record( + ua_pres_t *dialog, int hash_code, int lexpire, str *etag) { ua_pres_t *presentity; - if(dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { return update_record_puadb(dialog, lexpire, etag); - } - else - { + } else { lock_get(&HashT->p_records[hash_code].lock); presentity = search_htable(dialog, hash_code); - if (presentity == NULL) - { + if(presentity == NULL) { LM_DBG("Record found in table and deleted\n"); lock_release(&HashT->p_records[hash_code].lock); return 0; } - update_htable(presentity, dialog->desired_expires, lexpire, etag, hash_code, NULL); + update_htable(presentity, dialog->desired_expires, lexpire, etag, + hash_code, NULL); lock_release(&HashT->p_records[hash_code].lock); return 1; } @@ -190,19 +174,19 @@ static int find_and_update_record(ua_pres_t *dialog, int hash_code, int lexpire, void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) { - struct hdr_field* hdr= NULL; - struct sip_msg* msg= NULL; - ua_pres_t* presentity= NULL; - ua_pres_t* db_presentity= NULL; - ua_pres_t* hentity= NULL; + struct hdr_field *hdr = NULL; + struct sip_msg *msg = NULL; + ua_pres_t *presentity = NULL; + ua_pres_t *db_presentity = NULL; + ua_pres_t *hentity = NULL; int found = 0; - int size= 0; - unsigned int lexpire= 0; + int size = 0; + unsigned int lexpire = 0; str etag; unsigned int hash_code; - db1_res_t *res=NULL; + db1_res_t *res = NULL; ua_pres_t dbpres; - str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0}; + str pres_uri = {0, 0}, watcher_uri = {0, 0}, extra_headers = {0, 0}; int end_transaction = 1; memset(&dbpres, 0, sizeof(dbpres)); @@ -210,73 +194,63 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) dbpres.watcher_uri = &watcher_uri; dbpres.extra_headers = &extra_headers; - if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) - { - if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) { + if(pua_dbf.start_transaction(pua_db, db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } } - if(ps->param== NULL|| *ps->param== NULL) - { + if(ps->param == NULL || *ps->param == NULL) { LM_ERR("NULL callback parameter\n"); goto error; } - hentity= (ua_pres_t*)(*ps->param); + hentity = (ua_pres_t *)(*ps->param); - msg= ps->rpl; - if(msg == NULL) - { + msg = ps->rpl; + if(msg == NULL) { LM_ERR("no reply message found\n "); goto error; } - if(msg== FAKED_REPLY) - { + if(msg == FAKED_REPLY) { LM_DBG("FAKED_REPLY\n"); goto done; } - hash_code= core_hash(hentity->pres_uri, NULL, HASH_SIZE); + hash_code = core_hash(hentity->pres_uri, NULL, HASH_SIZE); - if( ps->code>= 300 ) - { + if(ps->code >= 300) { find_and_delete_record(hentity, hash_code); - if(ps->code== 412 && hentity->body && hentity->flag!= RPC_PUBLISH - && hentity->flag!= RPC_ASYN_PUBLISH) - { + if(ps->code == 412 && hentity->body && hentity->flag != RPC_PUBLISH + && hentity->flag != RPC_ASYN_PUBLISH) { /* sent a PUBLISH within a dialog that no longer exists * send again an initial PUBLISH */ LM_DBG("received a 412 reply- try again to send PUBLISH\n"); publ_info_t publ; memset(&publ, 0, sizeof(publ_info_t)); - publ.pres_uri= hentity->pres_uri; - publ.body= hentity->body; + publ.pres_uri = hentity->pres_uri; + publ.body = hentity->body; - if(hentity->desired_expires== 0) - publ.expires= -1; - else - if(hentity->desired_expires<= (int)time(NULL)) - publ.expires= 0; + if(hentity->desired_expires == 0) + publ.expires = -1; + else if(hentity->desired_expires <= (int)time(NULL)) + publ.expires = 0; else - publ.expires= hentity->desired_expires- (int)time(NULL)+ 3; + publ.expires = hentity->desired_expires - (int)time(NULL) + 3; - publ.source_flag|= hentity->flag; - publ.event|= hentity->event; - publ.content_type= hentity->content_type; - publ.id= hentity->id; - publ.extra_headers= hentity->extra_headers; + publ.source_flag |= hentity->flag; + publ.event |= hentity->event; + publ.content_type = hentity->content_type; + publ.id = hentity->id; + publ.extra_headers = hentity->extra_headers; publ.outbound_proxy = hentity->outbound_proxy; - publ.cb_param= hentity->cb_param; + publ.cb_param = hentity->cb_param; - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -284,8 +258,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) end_transaction = 0; - if(send_publish(&publ)< 0) - { + if(send_publish(&publ) < 0) { LM_ERR("when trying to send PUBLISH\n"); goto error; } @@ -293,134 +266,117 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) goto done; } /* code >= 300 */ - if( parse_headers(msg,HDR_EOH_F, 0)==-1 ) - { + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("parsing headers\n"); goto error; } - if(msg->expires== NULL || msg->expires->body.len<= 0) - { - LM_ERR("No Expires header found\n"); - goto error; + if(msg->expires == NULL || msg->expires->body.len <= 0) { + LM_ERR("No Expires header found\n"); + goto error; } - if (!msg->expires->parsed && (parse_expires(msg->expires) < 0)) - { + if(!msg->expires->parsed && (parse_expires(msg->expires) < 0)) { LM_ERR("cannot parse Expires header\n"); goto error; } - lexpire = ((exp_body_t*)msg->expires->parsed)->val; + lexpire = ((exp_body_t *)msg->expires->parsed)->val; LM_DBG("lexpire= %u\n", lexpire); hdr = msg->headers; - while (hdr!= NULL) - { - if(cmp_hdrname_strzn(&hdr->name, "SIP-ETag",8)==0 ) - { + while(hdr != NULL) { + if(cmp_hdrname_strzn(&hdr->name, "SIP-ETag", 8) == 0) { found = 1; break; } hdr = hdr->next; } - if(found== 0) /* must find SIP-Etag header field in 200 OK msg*/ + if(found == 0) /* must find SIP-Etag header field in 200 OK msg*/ { LM_ERR("no SIP-ETag header field found\n"); goto error; } - etag= hdr->body; + etag = hdr->body; - LM_DBG("completed with status %d [contact:%.*s]\n", - ps->code, hentity->pres_uri->len, hentity->pres_uri->s); + LM_DBG("completed with status %d [contact:%.*s]\n", ps->code, + hentity->pres_uri->len, hentity->pres_uri->s); - if (lexpire == 0) - { + if(lexpire == 0) { find_and_delete_record(hentity, hash_code); goto done; } - if (hentity->etag.s) { - if (pua_dbf.affected_rows != NULL || dbmode != PUA_DB_ONLY) { - if (find_and_update_record(hentity, hash_code, - lexpire, &etag) > 0) + if(hentity->etag.s) { + if(pua_dbf.affected_rows != NULL || dbmode != PUA_DB_ONLY) { + if(find_and_update_record(hentity, hash_code, lexpire, &etag) > 0) goto done; - } - else if ((db_presentity = - get_record_puadb(hentity->id, &hentity->etag, - &dbpres, &res)) != NULL) - { + } else if((db_presentity = get_record_puadb( + hentity->id, &hentity->etag, &dbpres, &res)) + != NULL) { update_record_puadb(hentity, lexpire, &etag); goto done; } } - size= sizeof(ua_pres_t)+ sizeof(str)+ - (hentity->pres_uri->len+ hentity->tuple_id.len + - hentity->id.len)* sizeof(char); + size = sizeof(ua_pres_t) + sizeof(str) + + (hentity->pres_uri->len + hentity->tuple_id.len + hentity->id.len) + * sizeof(char); if(hentity->extra_headers) - size+= sizeof(str)+ hentity->extra_headers->len* sizeof(char); + size += sizeof(str) + hentity->extra_headers->len * sizeof(char); - presentity= (ua_pres_t*)shm_malloc(size); - if(presentity== NULL) - { + presentity = (ua_pres_t *)shm_malloc(size); + if(presentity == NULL) { SHM_MEM_ERROR; goto error; } memset(presentity, 0, size); - size= sizeof(ua_pres_t); - presentity->pres_uri= (str*)((char*)presentity+ size); - size+= sizeof(str); + size = sizeof(ua_pres_t); + presentity->pres_uri = (str *)((char *)presentity + size); + size += sizeof(str); - presentity->pres_uri->s= (char*)presentity+ size; + presentity->pres_uri->s = (char *)presentity + size; memcpy(presentity->pres_uri->s, hentity->pres_uri->s, hentity->pres_uri->len); - presentity->pres_uri->len= hentity->pres_uri->len; - size+= hentity->pres_uri->len; + presentity->pres_uri->len = hentity->pres_uri->len; + size += hentity->pres_uri->len; - presentity->tuple_id.s= (char*)presentity+ size; - memcpy(presentity->tuple_id.s, hentity->tuple_id.s, - hentity->tuple_id.len); - presentity->tuple_id.len= hentity->tuple_id.len; - size+= presentity->tuple_id.len; + presentity->tuple_id.s = (char *)presentity + size; + memcpy(presentity->tuple_id.s, hentity->tuple_id.s, hentity->tuple_id.len); + presentity->tuple_id.len = hentity->tuple_id.len; + size += presentity->tuple_id.len; - presentity->id.s=(char*)presentity+ size; - memcpy(presentity->id.s, hentity->id.s, - hentity->id.len); - presentity->id.len= hentity->id.len; - size+= presentity->id.len; + presentity->id.s = (char *)presentity + size; + memcpy(presentity->id.s, hentity->id.s, hentity->id.len); + presentity->id.len = hentity->id.len; + size += presentity->id.len; - if(hentity->extra_headers) - { - presentity->extra_headers= (str*)((char*)presentity+ size); - size+= sizeof(str); - presentity->extra_headers->s= (char*)presentity+ size; + if(hentity->extra_headers) { + presentity->extra_headers = (str *)((char *)presentity + size); + size += sizeof(str); + presentity->extra_headers->s = (char *)presentity + size; memcpy(presentity->extra_headers->s, hentity->extra_headers->s, hentity->extra_headers->len); - presentity->extra_headers->len= hentity->extra_headers->len; - size+= hentity->extra_headers->len; + presentity->extra_headers->len = hentity->extra_headers->len; + size += hentity->extra_headers->len; } - presentity->desired_expires= hentity->desired_expires; - presentity->expires= lexpire+ (int)time(NULL); - presentity->flag|= hentity->flag; - presentity->event|= hentity->event; + presentity->desired_expires = hentity->desired_expires; + presentity->expires = lexpire + (int)time(NULL); + presentity->flag |= hentity->flag; + presentity->event |= hentity->event; - presentity->etag.s= (char*)shm_malloc(etag.len* sizeof(char)); - if(presentity->etag.s== NULL) - { + presentity->etag.s = (char *)shm_malloc(etag.len * sizeof(char)); + if(presentity->etag.s == NULL) { SHM_MEM_ERROR; shm_free(presentity); goto error; } memcpy(presentity->etag.s, etag.s, etag.len); - presentity->etag.len= etag.len; + presentity->etag.len = etag.len; - if (dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { insert_record_puadb(presentity); - } - else - { + } else { lock_get(&HashT->p_records[hash_code].lock); insert_htable(presentity, hash_code); lock_release(&HashT->p_records[hash_code].lock); @@ -428,27 +384,23 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) LM_DBG("Inserted record\n"); done: - if(hentity->ua_flag == REQ_OTHER) - { + if(hentity->ua_flag == REQ_OTHER) { run_pua_callbacks(hentity, msg); } - if(*ps->param) - { + if(*ps->param) { shm_free(*ps->param); - *ps->param= NULL; + *ps->param = NULL; } - if(dbmode==PUA_DB_ONLY && presentity) - { + if(dbmode == PUA_DB_ONLY && presentity) { shm_free(presentity->etag.s); shm_free(presentity); } - if (res) free_results_puadb(res); + if(res) + free_results_puadb(res); - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction && end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction && end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -457,73 +409,67 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps) return; error: - if(ps->param && *ps->param) - { + if(ps->param && *ps->param) { shm_free(*ps->param); - *ps->param= NULL; + *ps->param = NULL; } - if(presentity) shm_free(presentity); + if(presentity) + shm_free(presentity); - if (res) free_results_puadb(res); + if(res) + free_results_puadb(res); - if (dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) - { - if (pua_dbf.abort_transaction(pua_db) < 0) + if(dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) { + if(pua_dbf.abort_transaction(pua_db) < 0) LM_ERR("in abort_transaction\n"); } return; } -int send_publish( publ_info_t* publ ) +int send_publish(publ_info_t *publ) { str met = {"PUBLISH", 7}; - str* str_hdr = NULL; - ua_pres_t* presentity= NULL; - str* body= NULL; - str* tuple_id= NULL; - ua_pres_t* cb_param= NULL; - unsigned int hash_code=0; - str etag= {0, 0}; - int ver= 0; + str *str_hdr = NULL; + ua_pres_t *presentity = NULL; + str *body = NULL; + str *tuple_id = NULL; + ua_pres_t *cb_param = NULL; + unsigned int hash_code = 0; + str etag = {0, 0}; + int ver = 0; int result; - int ret_code= 0; - pua_event_t* ev= NULL; + int ret_code = 0; + pua_event_t *ev = NULL; uac_req_t uac_r; - db1_res_t *res=NULL; + db1_res_t *res = NULL; ua_pres_t dbpres; - str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0}; + str pres_uri = {0, 0}, watcher_uri = {0, 0}, extra_headers = {0, 0}; int ret = -1; - LM_DBG("pres_uri=%.*s\n", publ->pres_uri->len, publ->pres_uri->s ); + LM_DBG("pres_uri=%.*s\n", publ->pres_uri->len, publ->pres_uri->s); - if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) - { - if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) { + if(pua_dbf.start_transaction(pua_db, db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } } /* get event from list */ - ev= get_event(publ->event); - if(ev== NULL) - { + ev = get_event(publ->event); + if(ev == NULL) { LM_ERR("event not found in list\n"); goto error; } - if (dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { memset(&dbpres, 0, sizeof(dbpres)); dbpres.pres_uri = &pres_uri; dbpres.watcher_uri = &watcher_uri; dbpres.extra_headers = &extra_headers; presentity = get_record_puadb(publ->id, publ->etag, &dbpres, &res); - } - else - { + } else { ua_pres_t pres; memset(&pres, 0, sizeof(ua_pres_t)); @@ -534,124 +480,107 @@ int send_publish( publ_info_t* publ ) if(publ->etag) pres.etag = *publ->etag; - hash_code= core_hash(publ->pres_uri, NULL, HASH_SIZE); + hash_code = core_hash(publ->pres_uri, NULL, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); - presentity= search_htable(&pres, hash_code); + presentity = search_htable(&pres, hash_code); } - if(publ->etag && presentity== NULL) - { - if (dbmode!=PUA_DB_ONLY) + if(publ->etag && presentity == NULL) { + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); ret = 418; goto error; } - if(publ->flag & INSERT_TYPE) - { + if(publ->flag & INSERT_TYPE) { LM_DBG("Insert flag set\n"); goto insert; } - if(presentity== NULL) - { -insert: - if (dbmode!=PUA_DB_ONLY) + if(presentity == NULL) { + insert: + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); LM_DBG("insert type\n"); - if(publ->flag & UPDATE_TYPE ) - { + if(publ->flag & UPDATE_TYPE) { LM_DBG("UPDATE_TYPE and no record found \n"); - publ->flag= INSERT_TYPE; + publ->flag = INSERT_TYPE; } - if(publ->expires== 0) - { + if(publ->expires == 0) { LM_DBG("request for a publish with expires 0 and" - " no record found\n"); + " no record found\n"); goto done; - } - if(publ->body== NULL) - { + if(publ->body == NULL) { LM_ERR("New PUBLISH and no body found- invalid request\n"); ret = ERR_PUBLISH_NO_BODY; goto error; } - } - else - { + } else { LM_DBG("record found\n"); - publ->flag= UPDATE_TYPE; - etag.s= (char*)pkg_malloc(presentity->etag.len* sizeof(char)); - if(etag.s== NULL) - { + publ->flag = UPDATE_TYPE; + etag.s = (char *)pkg_malloc(presentity->etag.len * sizeof(char)); + if(etag.s == NULL) { PKG_MEM_ERROR; - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } memcpy(etag.s, presentity->etag.s, presentity->etag.len); - etag.len= presentity->etag.len; + etag.len = presentity->etag.len; - if(presentity->tuple_id.s && presentity->tuple_id.len) - { + if(presentity->tuple_id.s && presentity->tuple_id.len) { /* get tuple_id*/ - tuple_id=(str*)pkg_malloc(sizeof(str)); - if(tuple_id== NULL) - { + tuple_id = (str *)pkg_malloc(sizeof(str)); + if(tuple_id == NULL) { PKG_MEM_ERROR; - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } - tuple_id->s= (char*)pkg_malloc(presentity->tuple_id.len* sizeof(char)); - if(tuple_id->s== NULL) - { + tuple_id->s = + (char *)pkg_malloc(presentity->tuple_id.len * sizeof(char)); + if(tuple_id->s == NULL) { PKG_MEM_ERROR; - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } - memcpy(tuple_id->s, presentity->tuple_id.s, presentity->tuple_id.len); - tuple_id->len= presentity->tuple_id.len; + memcpy(tuple_id->s, presentity->tuple_id.s, + presentity->tuple_id.len); + tuple_id->len = presentity->tuple_id.len; } - if(publ->expires== 0) - { + if(publ->expires == 0) { LM_DBG("expires= 0- delete from hash table\n"); - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto send_publish; } presentity->version++; - ver= presentity->version; + ver = presentity->version; - if (dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { update_version_puadb(presentity); - } - else - { + } else { lock_release(&HashT->p_records[hash_code].lock); } } /* handle body */ - if(publ->body && publ->body->s) - { - ret_code= ev->process_body(publ, &body, ver, &tuple_id ); - if( ret_code< 0 || body== NULL) - { + if(publ->body && publ->body->s) { + ret_code = ev->process_body(publ, &body, ver, &tuple_id); + if(ret_code < 0 || body == NULL) { LM_ERR("while processing body\n"); - if(body== NULL) + if(body == NULL) LM_ERR("NULL body\n"); goto error; } } if(tuple_id) - LM_DBG("tuple_id= %.*s\n", tuple_id->len, tuple_id->s ); + LM_DBG("tuple_id= %.*s\n", tuple_id->len, tuple_id->s); send_publish: @@ -659,41 +588,39 @@ int send_publish( publ_info_t* publ ) if(etag.s && etag.len) publ->etag = &etag; - cb_param= publish_cbparam(publ, body, tuple_id, REQ_OTHER); - if(cb_param== NULL) - { + cb_param = publish_cbparam(publ, body, tuple_id, REQ_OTHER); + if(cb_param == NULL) { LM_ERR("constructing callback parameter\n"); goto error; } if(publ->flag & UPDATE_TYPE) LM_DBG("etag:%.*s\n", etag.len, etag.s); - str_hdr = publ_build_hdr((publ->expires< 0)?pua_default_expires:publ->expires, ev, &publ->content_type, - (publ->flag & UPDATE_TYPE)?&etag:NULL, publ->extra_headers, (body)?1:0); + str_hdr = publ_build_hdr( + (publ->expires < 0) ? pua_default_expires : publ->expires, ev, + &publ->content_type, (publ->flag & UPDATE_TYPE) ? &etag : NULL, + publ->extra_headers, (body) ? 1 : 0); - if(str_hdr == NULL) - { + if(str_hdr == NULL) { LM_ERR("while building extra_headers\n"); goto error; } LM_DBG("publ->pres_uri:\n%.*s\n ", publ->pres_uri->len, publ->pres_uri->s); LM_DBG("str_hdr:\n%.*s %d\n ", str_hdr->len, str_hdr->s, str_hdr->len); - if(body && body->len && body->s ) + if(body && body->len && body->s) LM_DBG("body:\n%.*s\n ", body->len, body->s); set_uac_req(&uac_r, &met, str_hdr, body, 0, TMCB_LOCAL_COMPLETED, - publ_cback_func, (void*)cb_param); - result= tmb.t_request(&uac_r, - publ->pres_uri, /*! Request-URI */ - publ->pres_uri, /*! To */ - publ->pres_uri, /*! From */ - publ->outbound_proxy? - publ->outbound_proxy:&outbound_proxy /*! Outbound proxy*/ - ); - - if(result< 0) - { + publ_cback_func, (void *)cb_param); + result = tmb.t_request(&uac_r, publ->pres_uri, /*! Request-URI */ + publ->pres_uri, /*! To */ + publ->pres_uri, /*! From */ + publ->outbound_proxy ? publ->outbound_proxy + : &outbound_proxy /*! Outbound proxy*/ + ); + + if(result < 0) { LM_ERR("in t_request tm module function\n"); goto error; } @@ -701,10 +628,8 @@ int send_publish( publ_info_t* publ ) done: ret = 0; - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -715,9 +640,8 @@ int send_publish( publ_info_t* publ ) if(cb_param) shm_free(cb_param); - if (dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) - { - if (pua_dbf.abort_transaction(pua_db) < 0) + if(dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) { + if(pua_dbf.abort_transaction(pua_db) < 0) LM_ERR("in abort_transaction\n"); } @@ -725,16 +649,14 @@ int send_publish( publ_info_t* publ ) if(etag.s) pkg_free(etag.s); - if(body && ret_code) - { + if(body && ret_code) { if(body->s) xmlFree(body->s); pkg_free(body); } if(str_hdr) pkg_free(str_hdr); - if(tuple_id) - { + if(tuple_id) { if(tuple_id->s) pkg_free(tuple_id->s); pkg_free(tuple_id); @@ -744,116 +666,107 @@ int send_publish( publ_info_t* publ ) return ret; } -ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id, - int ua_flag) +ua_pres_t *publish_cbparam( + publ_info_t *publ, str *body, str *tuple_id, int ua_flag) { int size; - ua_pres_t* cb_param= NULL; + ua_pres_t *cb_param = NULL; - size= sizeof(ua_pres_t)+ sizeof(str)+ (publ->pres_uri->len+ - + publ->content_type.len+ publ->id.len+ 1)*sizeof(char); + size = sizeof(ua_pres_t) + sizeof(str) + + (publ->pres_uri->len + +publ->content_type.len + publ->id.len + 1) + * sizeof(char); if(publ->outbound_proxy) - size+= sizeof(str)+ publ->outbound_proxy->len* sizeof(char); + size += sizeof(str) + publ->outbound_proxy->len * sizeof(char); if(body && body->s && body->len) - size+= sizeof(str)+ body->len* sizeof(char); + size += sizeof(str) + body->len * sizeof(char); if(publ->etag) - size+= publ->etag->len* sizeof(char); + size += publ->etag->len * sizeof(char); if(publ->extra_headers) - size+= sizeof(str)+ publ->extra_headers->len* sizeof(char); - if(tuple_id ) - size+= tuple_id->len* sizeof(char); + size += sizeof(str) + publ->extra_headers->len * sizeof(char); + if(tuple_id) + size += tuple_id->len * sizeof(char); - cb_param= (ua_pres_t*)shm_malloc(size); - if(cb_param== NULL) - { + cb_param = (ua_pres_t *)shm_malloc(size); + if(cb_param == NULL) { SHM_MEM_ERROR; return NULL; } memset(cb_param, 0, size); - size = sizeof(ua_pres_t); + size = sizeof(ua_pres_t); - cb_param->pres_uri = (str*)((char*)cb_param + size); - size+= sizeof(str); - cb_param->pres_uri->s = (char*)cb_param + size; - memcpy(cb_param->pres_uri->s, publ->pres_uri->s , - publ->pres_uri->len ) ; - cb_param->pres_uri->len= publ->pres_uri->len; - size+= publ->pres_uri->len; + cb_param->pres_uri = (str *)((char *)cb_param + size); + size += sizeof(str); + cb_param->pres_uri->s = (char *)cb_param + size; + memcpy(cb_param->pres_uri->s, publ->pres_uri->s, publ->pres_uri->len); + cb_param->pres_uri->len = publ->pres_uri->len; + size += publ->pres_uri->len; - if(publ->id.s && publ->id.len) - { - cb_param->id.s = ((char*)cb_param+ size); + if(publ->id.s && publ->id.len) { + cb_param->id.s = ((char *)cb_param + size); memcpy(cb_param->id.s, publ->id.s, publ->id.len); - cb_param->id.len= publ->id.len; - size+= publ->id.len; + cb_param->id.len = publ->id.len; + size += publ->id.len; } - if(body && body->s && body->len) - { - cb_param->body = (str*)((char*)cb_param + size); - size+= sizeof(str); + if(body && body->s && body->len) { + cb_param->body = (str *)((char *)cb_param + size); + size += sizeof(str); - cb_param->body->s = (char*)cb_param + size; - memcpy(cb_param->body->s, body->s , - body->len ) ; - cb_param->body->len= body->len; - size+= body->len; + cb_param->body->s = (char *)cb_param + size; + memcpy(cb_param->body->s, body->s, body->len); + cb_param->body->len = body->len; + size += body->len; } - if(publ->etag) - { - cb_param->etag.s = (char*)cb_param + size; - memcpy(cb_param->etag.s, publ->etag->s , - publ->etag->len ) ; - cb_param->etag.len= publ->etag->len; - size+= publ->etag->len; + if(publ->etag) { + cb_param->etag.s = (char *)cb_param + size; + memcpy(cb_param->etag.s, publ->etag->s, publ->etag->len); + cb_param->etag.len = publ->etag->len; + size += publ->etag->len; } - if(publ->extra_headers) - { - cb_param->extra_headers = (str*)((char*)cb_param + size); - size+= sizeof(str); - cb_param->extra_headers->s = (char*)cb_param + size; - memcpy(cb_param->extra_headers->s, publ->extra_headers->s , - publ->extra_headers->len ) ; - cb_param->extra_headers->len= publ->extra_headers->len; - size+= publ->extra_headers->len; - } - if(publ->outbound_proxy) - { - cb_param->outbound_proxy = (str*)((char*)cb_param + size); + if(publ->extra_headers) { + cb_param->extra_headers = (str *)((char *)cb_param + size); + size += sizeof(str); + cb_param->extra_headers->s = (char *)cb_param + size; + memcpy(cb_param->extra_headers->s, publ->extra_headers->s, + publ->extra_headers->len); + cb_param->extra_headers->len = publ->extra_headers->len; + size += publ->extra_headers->len; + } + if(publ->outbound_proxy) { + cb_param->outbound_proxy = (str *)((char *)cb_param + size); size += sizeof(str); - cb_param->outbound_proxy->s = (char*)cb_param + size; + cb_param->outbound_proxy->s = (char *)cb_param + size; memcpy(cb_param->outbound_proxy->s, publ->outbound_proxy->s, - publ->outbound_proxy->len); + publ->outbound_proxy->len); cb_param->outbound_proxy->len = publ->outbound_proxy->len; - size+= publ->outbound_proxy->len; + size += publ->outbound_proxy->len; } - if(publ->content_type.s && publ->content_type.len) - { - cb_param->content_type.s= (char*)cb_param + size; - memcpy(cb_param->content_type.s, publ->content_type.s, publ->content_type.len); - cb_param->content_type.len= publ->content_type.len; - size+= publ->content_type.len; + if(publ->content_type.s && publ->content_type.len) { + cb_param->content_type.s = (char *)cb_param + size; + memcpy(cb_param->content_type.s, publ->content_type.s, + publ->content_type.len); + cb_param->content_type.len = publ->content_type.len; + size += publ->content_type.len; } - if(tuple_id) - { - cb_param->tuple_id.s = (char*)cb_param+ size; - memcpy(cb_param->tuple_id.s, tuple_id->s ,tuple_id->len); - cb_param->tuple_id.len= tuple_id->len; - size+= tuple_id->len; + if(tuple_id) { + cb_param->tuple_id.s = (char *)cb_param + size; + memcpy(cb_param->tuple_id.s, tuple_id->s, tuple_id->len); + cb_param->tuple_id.len = tuple_id->len; + size += tuple_id->len; } - cb_param->event= publ->event; - cb_param->flag|= publ->source_flag; - cb_param->cb_param= publ->cb_param; - cb_param->ua_flag= ua_flag; + cb_param->event = publ->event; + cb_param->flag |= publ->source_flag; + cb_param->cb_param = publ->cb_param; + cb_param->ua_flag = ua_flag; - if(publ->expires< 0) - cb_param->desired_expires= 0; + if(publ->expires < 0) + cb_param->desired_expires = 0; else - cb_param->desired_expires=publ->expires+ (int)time(NULL); + cb_param->desired_expires = publ->expires + (int)time(NULL); return cb_param; } diff --git a/src/modules/pua/send_publish.h b/src/modules/pua/send_publish.h index 00f8f948cfd..e744ee70a12 100644 --- a/src/modules/pua/send_publish.h +++ b/src/modules/pua/send_publish.h @@ -33,30 +33,30 @@ typedef struct publ_info { str id; - str* pres_uri; - str* body; + str *pres_uri; + str *body; int expires; int flag; int source_flag; int event; - str content_type; /*! the content_type of the body if present(optional if the + str content_type; /*! the content_type of the body if present(optional if the same as the default value for that event) */ - str* etag; - str* outbound_proxy; - str* extra_headers; - void* cb_param; /*! the parameter for the function to be called on the callback + str *etag; + str *outbound_proxy; + str *extra_headers; + void *cb_param; /*! the parameter for the function to be called on the callback for the received reply; it must be allocated in share memory; a reference to it will be found in the cb_param filed of the ua_pres_structure received as a parameter for the registered function*/ -}publ_info_t; +} publ_info_t; -typedef int (*send_publish_t)(publ_info_t* publ); -int send_publish( publ_info_t* publ ); +typedef int (*send_publish_t)(publ_info_t *publ); +int send_publish(publ_info_t *publ); void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps); -str* publ_build_hdr(int expires, pua_event_t* event, str* content_type, str* etag, - str* extra_headers, int is_body); -ua_pres_t* publish_cbparam(publ_info_t* publ, str* body, str* tuple_id, - int ua_flag); +str *publ_build_hdr(int expires, pua_event_t *event, str *content_type, + str *etag, str *extra_headers, int is_body); +ua_pres_t *publish_cbparam( + publ_info_t *publ, str *body, str *tuple_id, int ua_flag); #endif diff --git a/src/modules/pua/send_subscribe.c b/src/modules/pua/send_subscribe.c index 1791e6cca2b..95b3be6f1d1 100644 --- a/src/modules/pua/send_subscribe.c +++ b/src/modules/pua/send_subscribe.c @@ -48,89 +48,82 @@ extern db_locking_t db_table_lock; -void print_subs(subs_info_t* subs) +void print_subs(subs_info_t *subs) { - LM_DBG("pres_uri= %.*s - len: %d\n", - subs->pres_uri->len, subs->pres_uri->s, subs->pres_uri->len ); - LM_DBG("watcher_uri= %.*s - len: %d\n", - subs->watcher_uri->len, subs->watcher_uri->s, - subs->watcher_uri->len); - + LM_DBG("pres_uri= %.*s - len: %d\n", subs->pres_uri->len, subs->pres_uri->s, + subs->pres_uri->len); + LM_DBG("watcher_uri= %.*s - len: %d\n", subs->watcher_uri->len, + subs->watcher_uri->s, subs->watcher_uri->len); } -str* subs_build_hdr(str* contact, int expires, int event, str* extra_headers) +str *subs_build_hdr(str *contact, int expires, int event, str *extra_headers) { - str* str_hdr= NULL; + str *str_hdr = NULL; static char buf[3000]; - char* subs_expires= NULL; - int len= 1; - pua_event_t* ev; + char *subs_expires = NULL; + int len = 1; + pua_event_t *ev; - str_hdr= (str*)pkg_malloc(sizeof(str)); - if(str_hdr== NULL) - { + str_hdr = (str *)pkg_malloc(sizeof(str)); + if(str_hdr == NULL) { PKG_MEM_ERROR; return NULL; } memset(str_hdr, 0, sizeof(str)); - str_hdr->s= buf; + str_hdr->s = buf; - ev= get_event(event); - if(ev== NULL) - { + ev = get_event(event); + if(ev == NULL) { LM_ERR("getting event from list\n"); goto error; } - memcpy(str_hdr->s ,"Max-Forwards: ", 14); + memcpy(str_hdr->s, "Max-Forwards: ", 14); str_hdr->len = 14; - str_hdr->len+= sprintf(str_hdr->s+ str_hdr->len,"%d", MAX_FORWARD); - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + str_hdr->len += sprintf(str_hdr->s + str_hdr->len, "%d", MAX_FORWARD); + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - memcpy(str_hdr->s+ str_hdr->len ,"Event: ", 7); - str_hdr->len+= 7; - memcpy(str_hdr->s+ str_hdr->len, ev->name.s, ev->name.len); - str_hdr->len+= ev->name.len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, "Event: ", 7); + str_hdr->len += 7; + memcpy(str_hdr->s + str_hdr->len, ev->name.s, ev->name.len); + str_hdr->len += ev->name.len; + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - memcpy(str_hdr->s+ str_hdr->len ,"Contact: <", 10); + memcpy(str_hdr->s + str_hdr->len, "Contact: <", 10); str_hdr->len += 10; - memcpy(str_hdr->s +str_hdr->len, contact->s, - contact->len); - str_hdr->len+= contact->len; - memcpy(str_hdr->s+ str_hdr->len, ">", 1); - str_hdr->len+= 1; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, contact->s, contact->len); + str_hdr->len += contact->len; + memcpy(str_hdr->s + str_hdr->len, ">", 1); + str_hdr->len += 1; + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - memcpy(str_hdr->s+ str_hdr->len ,"Expires: ", 9); + memcpy(str_hdr->s + str_hdr->len, "Expires: ", 9); str_hdr->len += 9; - if( expires<= min_expires) - subs_expires= int2str(min_expires, &len); + if(expires <= min_expires) + subs_expires = int2str(min_expires, &len); else - subs_expires= int2str(expires+ 10, &len); + subs_expires = int2str(expires + 10, &len); - if(subs_expires == NULL || len == 0) - { + if(subs_expires == NULL || len == 0) { LM_ERR("while converting int to str\n"); pkg_free(str_hdr); return NULL; } - memcpy(str_hdr->s+str_hdr->len, subs_expires, len); + memcpy(str_hdr->s + str_hdr->len, subs_expires, len); str_hdr->len += len; - memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN); + memcpy(str_hdr->s + str_hdr->len, CRLF, CRLF_LEN); str_hdr->len += CRLF_LEN; - if(extra_headers && extra_headers->len) - { - memcpy(str_hdr->s+str_hdr->len, extra_headers->s, extra_headers->len); + if(extra_headers && extra_headers->len) { + memcpy(str_hdr->s + str_hdr->len, extra_headers->s, extra_headers->len); str_hdr->len += extra_headers->len; } - str_hdr->s[str_hdr->len]= '\0'; + str_hdr->s[str_hdr->len] = '\0'; return str_hdr; @@ -140,61 +133,59 @@ str* subs_build_hdr(str* contact, int expires, int event, str* extra_headers) return NULL; } -dlg_t* pua_build_dlg_t(ua_pres_t* presentity) +dlg_t *pua_build_dlg_t(ua_pres_t *presentity) { - dlg_t* td =NULL; + dlg_t *td = NULL; int size; - size= sizeof(dlg_t)+ presentity->call_id.len+ presentity->to_tag.len+ - presentity->from_tag.len+ presentity->watcher_uri->len+ - presentity->pres_uri->len+ presentity->remote_contact.len; + size = sizeof(dlg_t) + presentity->call_id.len + presentity->to_tag.len + + presentity->from_tag.len + presentity->watcher_uri->len + + presentity->pres_uri->len + presentity->remote_contact.len; - td = (dlg_t*)pkg_malloc(size); - if(td == NULL) - { + td = (dlg_t *)pkg_malloc(size); + if(td == NULL) { PKG_MEM_ERROR; return NULL; } memset(td, 0, size); - size= sizeof(dlg_t); + size = sizeof(dlg_t); - td->id.call_id.s = (char*)td+ size; + td->id.call_id.s = (char *)td + size; memcpy(td->id.call_id.s, presentity->call_id.s, presentity->call_id.len); - td->id.call_id.len= presentity->call_id.len; - size+= presentity->call_id.len; + td->id.call_id.len = presentity->call_id.len; + size += presentity->call_id.len; - td->id.rem_tag.s = (char*)td+ size; + td->id.rem_tag.s = (char *)td + size; memcpy(td->id.rem_tag.s, presentity->to_tag.s, presentity->to_tag.len); td->id.rem_tag.len = presentity->to_tag.len; - size+= presentity->to_tag.len; + size += presentity->to_tag.len; - td->id.loc_tag.s = (char*)td+ size; + td->id.loc_tag.s = (char *)td + size; memcpy(td->id.loc_tag.s, presentity->from_tag.s, presentity->from_tag.len); - td->id.loc_tag.len =presentity->from_tag.len; - size+= presentity->from_tag.len; + td->id.loc_tag.len = presentity->from_tag.len; + size += presentity->from_tag.len; - td->loc_uri.s = (char*)td+ size; + td->loc_uri.s = (char *)td + size; memcpy(td->loc_uri.s, presentity->watcher_uri->s, - presentity->watcher_uri->len) ; + presentity->watcher_uri->len); td->loc_uri.len = presentity->watcher_uri->len; - size+= td->loc_uri.len; + size += td->loc_uri.len; - td->rem_uri.s = (char*)td+ size; - memcpy(td->rem_uri.s, presentity->pres_uri->s, presentity->pres_uri->len) ; + td->rem_uri.s = (char *)td + size; + memcpy(td->rem_uri.s, presentity->pres_uri->s, presentity->pres_uri->len); td->rem_uri.len = presentity->pres_uri->len; - size+= td->rem_uri.len; + size += td->rem_uri.len; - td->rem_target.s = (char*)td+ size; + td->rem_target.s = (char *)td + size; memcpy(td->rem_target.s, presentity->remote_contact.s, - presentity->remote_contact.len) ; + presentity->remote_contact.len); td->rem_target.len = presentity->remote_contact.len; - size+= td->rem_target.len; + size += td->rem_target.len; - if(presentity->record_route.s && presentity->record_route.len) - { - if(parse_rr_body(presentity->record_route.s, presentity->record_route.len, - &td->route_set)< 0) - { + if(presentity->record_route.s && presentity->record_route.len) { + if(parse_rr_body(presentity->record_route.s, + presentity->record_route.len, &td->route_set) + < 0) { LM_ERR("ERROR in function parse_rr_body\n"); pkg_free(td); return NULL; @@ -203,7 +194,7 @@ dlg_t* pua_build_dlg_t(ua_pres_t* presentity) td->loc_seq.value = presentity->cseq; td->loc_seq.is_set = 1; - td->state= DLG_CONFIRMED ; + td->state = DLG_CONFIRMED; LM_DBG("size = %d\n", size); @@ -215,8 +206,7 @@ dlg_t* pua_build_dlg_t(ua_pres_t* presentity) */ static int pua_free_tm_dlg(dlg_t *td) { - if(td) - { + if(td) { if(td->route_set) free_rr(&td->route_set); pkg_free(td); @@ -228,19 +218,14 @@ static void find_and_delete_dialog(ua_pres_t *dialog, int hash_code) { ua_pres_t *presentity; - if (dbmode == PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { delete_dialog_puadb(dialog); - } - else - { + } else { lock_get(&HashT->p_records[hash_code].lock); - presentity= get_dialog(dialog, hash_code); - if (presentity == NULL) - { + presentity = get_dialog(dialog, hash_code); + if(presentity == NULL) { presentity = get_temporary_dialog(dialog, hash_code); - if(presentity== NULL) - { + if(presentity == NULL) { LM_ERR("no record found\n"); lock_release(&HashT->p_records[hash_code].lock); return; @@ -252,103 +237,93 @@ static void find_and_delete_dialog(ua_pres_t *dialog, int hash_code) } } -static void find_and_update_dialog(ua_pres_t *dialog, int hash_code, int lexpire, str *contact) +static void find_and_update_dialog( + ua_pres_t *dialog, int hash_code, int lexpire, str *contact) { ua_pres_t *presentity; - if (dbmode == PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { update_dialog_puadb(dialog, lexpire, contact); - } - else - { + } else { lock_get(&HashT->p_records[hash_code].lock); - presentity= get_dialog(dialog, hash_code); - if (presentity == NULL) - { + presentity = get_dialog(dialog, hash_code); + if(presentity == NULL) { LM_ERR("no record found\n"); lock_release(&HashT->p_records[hash_code].lock); return; } - update_htable(presentity, dialog->desired_expires, lexpire, NULL, hash_code, contact); + update_htable(presentity, dialog->desired_expires, lexpire, NULL, + hash_code, contact); lock_release(&HashT->p_records[hash_code].lock); } } void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps) { - struct sip_msg* msg= NULL; - int lexpire= 0; + struct sip_msg *msg = NULL; + int lexpire = 0; unsigned int cseq; - ua_pres_t* presentity= NULL, *hentity= NULL; + ua_pres_t *presentity = NULL, *hentity = NULL; struct to_body *pto = NULL, TO = {0}, *pfrom = NULL; - int size= 0; + int size = 0; unsigned int hash_code; - int flag ; - str record_route= {0, 0}; + int flag; + str record_route = {0, 0}; int rt; str contact; int initial_request = 0; int end_transaction = 1; - if( ps->param== NULL || *ps->param== NULL ) - { + if(ps->param == NULL || *ps->param == NULL) { LM_ERR("null callback parameter\n"); return; } - if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) - { - if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) { + if(pua_dbf.start_transaction(pua_db, db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } } - LM_DBG("completed with status %d\n",ps->code) ; - hentity= (ua_pres_t*)(*ps->param); - hash_code= core_hash(hentity->pres_uri,hentity->watcher_uri, - HASH_SIZE); - flag= hentity->flag; + LM_DBG("completed with status %d\n", ps->code); + hentity = (ua_pres_t *)(*ps->param); + hash_code = core_hash(hentity->pres_uri, hentity->watcher_uri, HASH_SIZE); + flag = hentity->flag; if(hentity->flag & XMPP_INITIAL_SUBS) - hentity->flag= XMPP_SUBSCRIBE; + hentity->flag = XMPP_SUBSCRIBE; /* get dialog information from reply message: callid, to_tag, from_tag */ - msg= ps->rpl; - if(msg == NULL) - { + msg = ps->rpl; + if(msg == NULL) { LM_ERR("no reply message found\n "); goto error; } - if(msg== FAKED_REPLY) - { + if(msg == FAKED_REPLY) { struct hdr_field *callid = NULL, *from = NULL; struct to_body FROM = {0}; - callid = (struct hdr_field *) pkg_malloc(sizeof(struct hdr_field)); - if (callid == NULL) - { + callid = (struct hdr_field *)pkg_malloc(sizeof(struct hdr_field)); + if(callid == NULL) { PKG_MEM_ERROR; goto faked_error; } memset(callid, 0, sizeof(struct hdr_field)); - get_hdr_field(t->callid_hdr.s, t->callid_hdr.s + t->callid_hdr.len, callid); + get_hdr_field( + t->callid_hdr.s, t->callid_hdr.s + t->callid_hdr.len, callid); hentity->call_id = callid->body; - from = (struct hdr_field *) pkg_malloc(sizeof(struct hdr_field)); - if (from == NULL) - { + from = (struct hdr_field *)pkg_malloc(sizeof(struct hdr_field)); + if(from == NULL) { PKG_MEM_ERROR; goto faked_error; } memset(from, 0, sizeof(struct hdr_field)); get_hdr_field(t->from_hdr.s, t->from_hdr.s + t->from_hdr.len, from); parse_to(from->body.s, from->body.s + from->body.len + 1, &FROM); - if(FROM.uri.len <= 0) - { + if(FROM.uri.len <= 0) { LM_ERR("'From' header NOT parsed\n"); goto faked_error; } @@ -359,104 +334,91 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps) hentity->to_tag.len = 0; find_and_delete_dialog(hentity, hash_code); -faked_error: - if (callid) pkg_free(callid); + faked_error: + if(callid) + pkg_free(callid); free_to_params(&FROM); - if (from) pkg_free(from); + if(from) + pkg_free(from); goto done; } - if ( parse_headers(msg,HDR_EOH_F, 0)==-1 ) - { + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("when parsing headers\n"); goto error; } - if(ps->rpl->expires && msg->expires->body.len > 0) - { - if (!msg->expires->parsed && (parse_expires(msg->expires) < 0)) - { + if(ps->rpl->expires && msg->expires->body.len > 0) { + if(!msg->expires->parsed && (parse_expires(msg->expires) < 0)) { LM_ERR("cannot parse Expires header\n"); goto error; } - lexpire = ((exp_body_t*)msg->expires->parsed)->val; + lexpire = ((exp_body_t *)msg->expires->parsed)->val; LM_DBG("lexpire= %d\n", lexpire); } /*if initial request */ - if(hentity->call_id.s== NULL) - { + if(hentity->call_id.s == NULL) { initial_request = 1; - if( msg->callid==NULL || msg->callid->body.s==NULL) - { + if(msg->callid == NULL || msg->callid->body.s == NULL) { LM_ERR("cannot parse callid header\n"); goto error; } - if (!msg->from || !msg->from->body.s) - { + if(!msg->from || !msg->from->body.s) { LM_ERR("cannot find 'from' header!\n"); goto error; } - if (msg->from->parsed == NULL) - { - if ( parse_from_header( msg )<0 ) - { + if(msg->from->parsed == NULL) { + if(parse_from_header(msg) < 0) { LM_ERR("cannot parse From header\n"); goto error; } } - pfrom = (struct to_body*)msg->from->parsed; + pfrom = (struct to_body *)msg->from->parsed; - if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0) - { + if(pfrom->tag_value.s == NULL || pfrom->tag_value.len == 0) { LM_ERR("no from tag value present\n"); goto error; } - hentity->call_id= msg->callid->body; - hentity->from_tag= pfrom->tag_value; + hentity->call_id = msg->callid->body; + hentity->from_tag = pfrom->tag_value; - if(ps->code >= 300 || lexpire == 0) - { + if(ps->code >= 300 || lexpire == 0) { hentity->to_tag.s = NULL; hentity->to_tag.len = 0; find_and_delete_dialog(hentity, hash_code); goto done; } - if( msg->to==NULL || msg->to->body.s==NULL) - { + if(msg->to == NULL || msg->to->body.s == NULL) { LM_ERR("cannot parse TO header\n"); goto error; } - if(msg->to->parsed != NULL) - { - pto = (struct to_body*)msg->to->parsed; - LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",pto->uri.len,pto->uri.s); - } - else - { - parse_to(msg->to->body.s,msg->to->body.s + - msg->to->body.len + 1, &TO); - if(TO.uri.len <= 0) - { + if(msg->to->parsed != NULL) { + pto = (struct to_body *)msg->to->parsed; + LM_DBG("'To' header ALREADY PARSED: <%.*s>\n", pto->uri.len, + pto->uri.s); + } else { + parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, + &TO); + if(TO.uri.len <= 0) { LM_ERR("'To' header NOT parsed\n"); goto error; } pto = &TO; } - if( pto->tag_value.s ==NULL || pto->tag_value.len == 0) - { + if(pto->tag_value.s == NULL || pto->tag_value.len == 0) { LM_ERR("no to tag value present\n"); goto error; } - hentity->to_tag= pto->tag_value; + hentity->to_tag = pto->tag_value; } - if(ps->code >= 300 ) - { /* if an error code and a stored dialog delete it and try to send + if(ps->code + >= 300) { /* if an error code and a stored dialog delete it and try to send a subscription with type= INSERT_TYPE, else return*/ subs_info_t subs; @@ -465,10 +427,8 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps) hentity->to_tag.len = 0; find_and_delete_dialog(hentity, hash_code); - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -478,249 +438,219 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps) /* Redirect if the response 3XX */ memset(&subs, 0, sizeof(subs_info_t)); - subs.pres_uri= hentity->pres_uri; - subs.watcher_uri= hentity->watcher_uri; - subs.contact= &hentity->contact; + subs.pres_uri = hentity->pres_uri; + subs.watcher_uri = hentity->watcher_uri; + subs.contact = &hentity->contact; if(hentity->remote_contact.s) - subs.remote_target= &hentity->remote_contact; + subs.remote_target = &hentity->remote_contact; - if(hentity->desired_expires== 0) - subs.expires= -1; - else - if(hentity->desired_expires< (int)time(NULL)) - subs.expires= 0; + if(hentity->desired_expires == 0) + subs.expires = -1; + else if(hentity->desired_expires < (int)time(NULL)) + subs.expires = 0; else - subs.expires= hentity->desired_expires- (int)time(NULL)+ 3; - - subs.flag= INSERT_TYPE; - subs.source_flag= flag; - subs.event= hentity->event; - subs.id= hentity->id; - subs.outbound_proxy= hentity->outbound_proxy; - subs.extra_headers= hentity->extra_headers; - subs.cb_param= hentity->cb_param; - - if(send_subscribe(&subs)< 0) - { + subs.expires = hentity->desired_expires - (int)time(NULL) + 3; + + subs.flag = INSERT_TYPE; + subs.source_flag = flag; + subs.event = hentity->event; + subs.id = hentity->id; + subs.outbound_proxy = hentity->outbound_proxy; + subs.extra_headers = hentity->extra_headers; + subs.cb_param = hentity->cb_param; + + if(send_subscribe(&subs) < 0) { LM_ERR("when trying to send SUBSCRIBE\n"); goto error; } goto done; } - if(lexpire== 0 ) - { + if(lexpire == 0) { LM_DBG("lexpire= 0 Delete from hash table"); find_and_delete_dialog(hentity, hash_code); goto done; } /* extract the contact */ - if(msg->contact== NULL || msg->contact->body.s== NULL) - { + if(msg->contact == NULL || msg->contact->body.s == NULL) { LM_ERR("no contact header found"); goto error; } - if( parse_contact(msg->contact) <0 ) - { + if(parse_contact(msg->contact) < 0) { LM_ERR(" cannot parse contact header\n"); goto error; } - if(msg->contact->parsed == NULL) - { + if(msg->contact->parsed == NULL) { LM_ERR("cannot parse contact header\n"); goto error; } - contact = ((contact_body_t* )msg->contact->parsed)->contacts->uri; + contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri; - if( msg->cseq==NULL || msg->cseq->body.s==NULL) - { + if(msg->cseq == NULL || msg->cseq->body.s == NULL) { LM_ERR("cannot parse cseq header\n"); goto error; } - if( str2int( &(get_cseq(msg)->number), &cseq)< 0) - { + if(str2int(&(get_cseq(msg)->number), &cseq) < 0) { LM_ERR("while converting str to int\n"); goto error; } - if(initial_request == 0) - { + if(initial_request == 0) { hentity->cseq = cseq; find_and_update_dialog(hentity, hash_code, lexpire, &contact); goto done; } /*process record route and add it to a string*/ - if (msg->record_route!=NULL) - { + if(msg->record_route != NULL) { rt = print_rr_body(msg->record_route, &record_route, 1, 0); - if(rt != 0) - { + if(rt != 0) { LM_ERR("parsing record route [%d]\n", rt); - record_route.s=NULL; - record_route.len=0; + record_route.s = NULL; + record_route.len = 0; } } - size= sizeof(ua_pres_t)+ 2*sizeof(str)+( pto->uri.len+ - pfrom->uri.len+ pto->tag_value.len+ pfrom->tag_value.len - +msg->callid->body.len+ record_route.len+ hentity->contact.len+ - hentity->id.len )*sizeof(char); + size = sizeof(ua_pres_t) + 2 * sizeof(str) + + (pto->uri.len + pfrom->uri.len + pto->tag_value.len + + pfrom->tag_value.len + msg->callid->body.len + + record_route.len + hentity->contact.len + + hentity->id.len) + * sizeof(char); if(hentity->extra_headers) - size+= sizeof(str)+ hentity->extra_headers->len*sizeof(char); + size += sizeof(str) + hentity->extra_headers->len * sizeof(char); - presentity= (ua_pres_t*)shm_malloc(size); - if(presentity== NULL) - { + presentity = (ua_pres_t *)shm_malloc(size); + if(presentity == NULL) { SHM_MEM_ERROR; goto error; } memset(presentity, 0, size); - size= sizeof(ua_pres_t); + size = sizeof(ua_pres_t); - presentity->pres_uri= (str*)( (char*)presentity+ size); - size+= sizeof(str); - presentity->pres_uri->s= (char*)presentity+ size; + presentity->pres_uri = (str *)((char *)presentity + size); + size += sizeof(str); + presentity->pres_uri->s = (char *)presentity + size; memcpy(presentity->pres_uri->s, pto->uri.s, pto->uri.len); - presentity->pres_uri->len= pto->uri.len; - size+= pto->uri.len; + presentity->pres_uri->len = pto->uri.len; + size += pto->uri.len; - presentity->watcher_uri= (str*)( (char*)presentity+ size); - size+= sizeof(str); - presentity->watcher_uri->s= (char*)presentity+ size; + presentity->watcher_uri = (str *)((char *)presentity + size); + size += sizeof(str); + presentity->watcher_uri->s = (char *)presentity + size; memcpy(presentity->watcher_uri->s, pfrom->uri.s, pfrom->uri.len); - presentity->watcher_uri->len= pfrom->uri.len; - size+= pfrom->uri.len; - - presentity->call_id.s= (char*)presentity + size; - memcpy(presentity->call_id.s,msg->callid->body.s, - msg->callid->body.len); - presentity->call_id.len= msg->callid->body.len; - size+= presentity->call_id.len; - - presentity->to_tag.s= (char*)presentity + size; - memcpy(presentity->to_tag.s,pto->tag_value.s, - pto->tag_value.len); - presentity->to_tag.len= pto->tag_value.len; - size+= pto->tag_value.len; - - presentity->from_tag.s= (char*)presentity + size; - memcpy(presentity->from_tag.s,pfrom->tag_value.s, - pfrom->tag_value.len); - presentity->from_tag.len= pfrom->tag_value.len; - size+= pfrom->tag_value.len; - - if(record_route.len && record_route.s) - { - presentity->record_route.s= (char*)presentity + size; + presentity->watcher_uri->len = pfrom->uri.len; + size += pfrom->uri.len; + + presentity->call_id.s = (char *)presentity + size; + memcpy(presentity->call_id.s, msg->callid->body.s, msg->callid->body.len); + presentity->call_id.len = msg->callid->body.len; + size += presentity->call_id.len; + + presentity->to_tag.s = (char *)presentity + size; + memcpy(presentity->to_tag.s, pto->tag_value.s, pto->tag_value.len); + presentity->to_tag.len = pto->tag_value.len; + size += pto->tag_value.len; + + presentity->from_tag.s = (char *)presentity + size; + memcpy(presentity->from_tag.s, pfrom->tag_value.s, pfrom->tag_value.len); + presentity->from_tag.len = pfrom->tag_value.len; + size += pfrom->tag_value.len; + + if(record_route.len && record_route.s) { + presentity->record_route.s = (char *)presentity + size; memcpy(presentity->record_route.s, record_route.s, record_route.len); - presentity->record_route.len= record_route.len; - size+= record_route.len; + presentity->record_route.len = record_route.len; + size += record_route.len; pkg_free(record_route.s); record_route.s = NULL; } - presentity->contact.s= (char*)presentity + size; + presentity->contact.s = (char *)presentity + size; memcpy(presentity->contact.s, hentity->contact.s, hentity->contact.len); - presentity->contact.len= hentity->contact.len; - size+= hentity->contact.len; - - if(hentity->id.s) - { - presentity->id.s=(char*)presentity+ size; - memcpy(presentity->id.s, hentity->id.s, - hentity->id.len); - presentity->id.len= hentity->id.len; - size+= presentity->id.len; + presentity->contact.len = hentity->contact.len; + size += hentity->contact.len; + + if(hentity->id.s) { + presentity->id.s = (char *)presentity + size; + memcpy(presentity->id.s, hentity->id.s, hentity->id.len); + presentity->id.len = hentity->id.len; + size += presentity->id.len; } - if(hentity->extra_headers) - { - presentity->extra_headers= (str*)((char*)presentity+ size); - size+= sizeof(str); - presentity->extra_headers->s=(char*)presentity+ size; + if(hentity->extra_headers) { + presentity->extra_headers = (str *)((char *)presentity + size); + size += sizeof(str); + presentity->extra_headers->s = (char *)presentity + size; memcpy(presentity->extra_headers->s, hentity->extra_headers->s, - hentity->extra_headers->len); - presentity->extra_headers->len= hentity->extra_headers->len; - size+= hentity->extra_headers->len; + hentity->extra_headers->len); + presentity->extra_headers->len = hentity->extra_headers->len; + size += hentity->extra_headers->len; } /* write the remote contact filed */ - presentity->remote_contact.s= (char*)shm_malloc(contact.len* sizeof(char)); - if(presentity->remote_contact.s==NULL) - { + presentity->remote_contact.s = + (char *)shm_malloc(contact.len * sizeof(char)); + if(presentity->remote_contact.s == NULL) { SHM_MEM_ERROR; shm_free(presentity); return; } memcpy(presentity->remote_contact.s, contact.s, contact.len); - presentity->remote_contact.len= contact.len; - - presentity->event|= hentity->event; - presentity->flag= hentity->flag; - presentity->etag.s= NULL; - presentity->cseq= cseq; - presentity->desired_expires= hentity->desired_expires; - presentity->expires= lexpire+ (int)time(NULL); - if(BLA_SUBSCRIBE & presentity->flag) - { + presentity->remote_contact.len = contact.len; + + presentity->event |= hentity->event; + presentity->flag = hentity->flag; + presentity->etag.s = NULL; + presentity->cseq = cseq; + presentity->desired_expires = hentity->desired_expires; + presentity->expires = lexpire + (int)time(NULL); + if(BLA_SUBSCRIBE & presentity->flag) { LM_DBG("BLA_SUBSCRIBE FLAG inserted\n"); } LM_DBG("record for subscribe from %.*s to %.*s inserted in database\n", presentity->watcher_uri->len, presentity->watcher_uri->s, presentity->pres_uri->len, presentity->pres_uri->s); - if (dbmode==PUA_DB_ONLY) - { - if (pua_dbf.end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY) { + if(pua_dbf.end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } } - if (pua_dbf.start_transaction) - { - if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0) - { + if(pua_dbf.start_transaction) { + if(pua_dbf.start_transaction(pua_db, db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } } - if (convert_temporary_dialog_puadb(presentity) < 0) - { + if(convert_temporary_dialog_puadb(presentity) < 0) { LM_ERR("Could not convert temporary dialog into a dialog\n"); goto error; } - } - else - { - if (convert_temporary_dialog(presentity) < 0) - { + } else { + if(convert_temporary_dialog(presentity) < 0) { LM_ERR("Could not convert temporary dialog into a dialog\n"); goto error; } } done: - if(hentity->ua_flag == REQ_OTHER) - { - hentity->flag= flag; - run_pua_callbacks( hentity, msg); + if(hentity->ua_flag == REQ_OTHER) { + hentity->flag = flag; + run_pua_callbacks(hentity, msg); } - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction && end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction && end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -729,195 +659,186 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps) goto end; error: - if (presentity) - { - if (presentity->remote_contact.s) shm_free(presentity->remote_contact.s); - shm_free(presentity); + if(presentity) { + if(presentity->remote_contact.s) + shm_free(presentity->remote_contact.s); + shm_free(presentity); } if(record_route.s) pkg_free(record_route.s); - if (dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) - { - if (pua_dbf.abort_transaction(pua_db) < 0) + if(dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) { + if(pua_dbf.abort_transaction(pua_db) < 0) LM_ERR("in abort_transaction\n"); } end: - if(hentity) - { + if(hentity) { shm_free(hentity); - hentity= NULL; + hentity = NULL; } free_to_params(&TO); return; } -ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag) +ua_pres_t *subscribe_cbparam(subs_info_t *subs, int ua_flag) { - ua_pres_t* hentity= NULL; + ua_pres_t *hentity = NULL; int size; - size= sizeof(ua_pres_t)+ 2*sizeof(str)+(subs->pres_uri->len+ - subs->watcher_uri->len+ subs->contact->len+ subs->id.len+ 1)* - sizeof(char); + size = sizeof(ua_pres_t) + 2 * sizeof(str) + + (subs->pres_uri->len + subs->watcher_uri->len + subs->contact->len + + subs->id.len + 1) + * sizeof(char); - if(subs->outbound_proxy && subs->outbound_proxy->len && subs->outbound_proxy->s ) - size+= sizeof(str)+ subs->outbound_proxy->len* sizeof(char); + if(subs->outbound_proxy && subs->outbound_proxy->len + && subs->outbound_proxy->s) + size += sizeof(str) + subs->outbound_proxy->len * sizeof(char); if(subs->extra_headers && subs->extra_headers->s) - size+= sizeof(str)+ subs->extra_headers->len* sizeof(char); + size += sizeof(str) + subs->extra_headers->len * sizeof(char); - hentity= (ua_pres_t*)shm_malloc(size); - if(hentity== NULL) - { + hentity = (ua_pres_t *)shm_malloc(size); + if(hentity == NULL) { SHM_MEM_ERROR; return NULL; } memset(hentity, 0, size); - size= sizeof(ua_pres_t); - - hentity->pres_uri = (str*)((char*)hentity + size); - size+= sizeof(str); - - hentity->pres_uri->s = (char*)hentity+ size; - memcpy(hentity->pres_uri->s, subs->pres_uri->s , - subs->pres_uri->len ) ; - hentity->pres_uri->len= subs->pres_uri->len; - size+= subs->pres_uri->len; - - hentity->watcher_uri = (str*)((char*)hentity + size); - size+= sizeof(str); - - hentity->watcher_uri->s = (char*)hentity+ size; - memcpy(hentity->watcher_uri->s, subs->watcher_uri->s , - subs->watcher_uri->len ) ; - hentity->watcher_uri->len= subs->watcher_uri->len; - size+= subs->watcher_uri->len; - - hentity->contact.s = (char*)hentity+ size; - memcpy(hentity->contact.s, subs->contact->s , - subs->contact->len ); - hentity->contact.len= subs->contact->len; - size+= subs->contact->len; - - if(subs->outbound_proxy && subs->outbound_proxy->s) - { - hentity->outbound_proxy= (str*)((char*)hentity+ size); - size+= sizeof(str); - hentity->outbound_proxy->s= (char*)hentity+ size; - memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, subs->outbound_proxy->len); - hentity->outbound_proxy->len= subs->outbound_proxy->len; - size+= subs->outbound_proxy->len; + size = sizeof(ua_pres_t); + + hentity->pres_uri = (str *)((char *)hentity + size); + size += sizeof(str); + + hentity->pres_uri->s = (char *)hentity + size; + memcpy(hentity->pres_uri->s, subs->pres_uri->s, subs->pres_uri->len); + hentity->pres_uri->len = subs->pres_uri->len; + size += subs->pres_uri->len; + + hentity->watcher_uri = (str *)((char *)hentity + size); + size += sizeof(str); + + hentity->watcher_uri->s = (char *)hentity + size; + memcpy(hentity->watcher_uri->s, subs->watcher_uri->s, + subs->watcher_uri->len); + hentity->watcher_uri->len = subs->watcher_uri->len; + size += subs->watcher_uri->len; + + hentity->contact.s = (char *)hentity + size; + memcpy(hentity->contact.s, subs->contact->s, subs->contact->len); + hentity->contact.len = subs->contact->len; + size += subs->contact->len; + + if(subs->outbound_proxy && subs->outbound_proxy->s) { + hentity->outbound_proxy = (str *)((char *)hentity + size); + size += sizeof(str); + hentity->outbound_proxy->s = (char *)hentity + size; + memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, + subs->outbound_proxy->len); + hentity->outbound_proxy->len = subs->outbound_proxy->len; + size += subs->outbound_proxy->len; } - if(subs->expires< 0) - hentity->desired_expires= 0; + if(subs->expires < 0) + hentity->desired_expires = 0; else - hentity->desired_expires=subs->expires+ (int)time(NULL); + hentity->desired_expires = subs->expires + (int)time(NULL); - if(subs->id.s) - { + if(subs->id.s) { CONT_COPY(hentity, hentity->id, subs->id); } - if(subs->extra_headers && subs->extra_headers->s) - { - hentity->extra_headers= (str*)((char*)hentity+ size); - size+= sizeof(str); - hentity->extra_headers->s= (char*)hentity+ size; + if(subs->extra_headers && subs->extra_headers->s) { + hentity->extra_headers = (str *)((char *)hentity + size); + size += sizeof(str); + hentity->extra_headers->s = (char *)hentity + size; memcpy(hentity->extra_headers->s, subs->extra_headers->s, subs->extra_headers->len); - hentity->extra_headers->len= subs->extra_headers->len; - size+= subs->extra_headers->len; + hentity->extra_headers->len = subs->extra_headers->len; + size += subs->extra_headers->len; } - hentity->flag= subs->source_flag; - hentity->event= subs->event; - hentity->ua_flag= ua_flag; - hentity->cb_param= subs->cb_param; + hentity->flag = subs->source_flag; + hentity->event = subs->event; + hentity->ua_flag = ua_flag; + hentity->cb_param = subs->cb_param; return hentity; - } -ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag) +ua_pres_t *subs_cbparam_indlg(ua_pres_t *subs, int expires, int ua_flag) { - ua_pres_t* hentity= NULL; + ua_pres_t *hentity = NULL; int size; - size= sizeof(ua_pres_t)+ 2*sizeof(str)+subs->pres_uri->len+ - subs->watcher_uri->len+ subs->contact.len+ subs->id.len+ - subs->to_tag.len+ subs->call_id.len+ subs->from_tag.len+ 1; + size = sizeof(ua_pres_t) + 2 * sizeof(str) + subs->pres_uri->len + + subs->watcher_uri->len + subs->contact.len + subs->id.len + + subs->to_tag.len + subs->call_id.len + subs->from_tag.len + 1; - if(subs->outbound_proxy && subs->outbound_proxy->len && subs->outbound_proxy->s ) - size+= sizeof(str)+ subs->outbound_proxy->len; + if(subs->outbound_proxy && subs->outbound_proxy->len + && subs->outbound_proxy->s) + size += sizeof(str) + subs->outbound_proxy->len; if(subs->extra_headers && subs->extra_headers->s) - size+= sizeof(str)+ subs->extra_headers->len; + size += sizeof(str) + subs->extra_headers->len; if(subs->remote_contact.s) - size+= subs->remote_contact.len; + size += subs->remote_contact.len; - hentity= (ua_pres_t*)shm_malloc(size); - if(hentity== NULL) - { + hentity = (ua_pres_t *)shm_malloc(size); + if(hentity == NULL) { SHM_MEM_ERROR; return NULL; } memset(hentity, 0, size); - size= sizeof(ua_pres_t); + size = sizeof(ua_pres_t); - hentity->pres_uri = (str*)((char*)hentity + size); - size+= sizeof(str); + hentity->pres_uri = (str *)((char *)hentity + size); + size += sizeof(str); - hentity->pres_uri->s = (char*)hentity+ size; - memcpy(hentity->pres_uri->s, subs->pres_uri->s , - subs->pres_uri->len ) ; - hentity->pres_uri->len= subs->pres_uri->len; - size+= subs->pres_uri->len; + hentity->pres_uri->s = (char *)hentity + size; + memcpy(hentity->pres_uri->s, subs->pres_uri->s, subs->pres_uri->len); + hentity->pres_uri->len = subs->pres_uri->len; + size += subs->pres_uri->len; - hentity->watcher_uri = (str*)((char*)hentity + size); - size+= sizeof(str); + hentity->watcher_uri = (str *)((char *)hentity + size); + size += sizeof(str); - hentity->watcher_uri->s = (char*)hentity+ size; - memcpy(hentity->watcher_uri->s, subs->watcher_uri->s , - subs->watcher_uri->len ) ; - hentity->watcher_uri->len= subs->watcher_uri->len; - size+= subs->watcher_uri->len; + hentity->watcher_uri->s = (char *)hentity + size; + memcpy(hentity->watcher_uri->s, subs->watcher_uri->s, + subs->watcher_uri->len); + hentity->watcher_uri->len = subs->watcher_uri->len; + size += subs->watcher_uri->len; CONT_COPY(hentity, hentity->contact, subs->contact); - if(subs->outbound_proxy && subs->outbound_proxy->len && subs->outbound_proxy->s) - { - hentity->outbound_proxy= (str*)((char*)hentity+ size); - size+= sizeof(str); - hentity->outbound_proxy->s= (char*)hentity+ size; - memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, subs->outbound_proxy->len); - hentity->outbound_proxy->len= subs->outbound_proxy->len; - size+= subs->outbound_proxy->len; + if(subs->outbound_proxy && subs->outbound_proxy->len + && subs->outbound_proxy->s) { + hentity->outbound_proxy = (str *)((char *)hentity + size); + size += sizeof(str); + hentity->outbound_proxy->s = (char *)hentity + size; + memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, + subs->outbound_proxy->len); + hentity->outbound_proxy->len = subs->outbound_proxy->len; + size += subs->outbound_proxy->len; } - if(subs->id.s) - { + if(subs->id.s) { CONT_COPY(hentity, hentity->id, subs->id); } - if(subs->remote_contact.s) - { + if(subs->remote_contact.s) { CONT_COPY(hentity, hentity->remote_contact, subs->remote_contact); } - if(subs->extra_headers && subs->extra_headers->s) - { - hentity->extra_headers= (str*)((char*)hentity+ size); - size+= sizeof(str); - hentity->extra_headers->s= (char*)hentity+ size; + if(subs->extra_headers && subs->extra_headers->s) { + hentity->extra_headers = (str *)((char *)hentity + size); + size += sizeof(str); + hentity->extra_headers->s = (char *)hentity + size; memcpy(hentity->extra_headers->s, subs->extra_headers->s, subs->extra_headers->len); - hentity->extra_headers->len= subs->extra_headers->len; - size+= subs->extra_headers->len; + hentity->extra_headers->len = subs->extra_headers->len; + size += subs->extra_headers->len; } /* copy dialog information */ @@ -925,40 +846,39 @@ ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag) CONT_COPY(hentity, hentity->from_tag, subs->from_tag); CONT_COPY(hentity, hentity->call_id, subs->call_id); - if(expires< 0) - hentity->desired_expires= 0; + if(expires < 0) + hentity->desired_expires = 0; else - hentity->desired_expires=expires+ (int)time(NULL); + hentity->desired_expires = expires + (int)time(NULL); - hentity->flag= subs->flag; - hentity->event= subs->event; - hentity->ua_flag= ua_flag; - hentity->cb_param= subs->cb_param; + hentity->flag = subs->flag; + hentity->event = subs->event; + hentity->ua_flag = ua_flag; + hentity->cb_param = subs->cb_param; return hentity; - } /** * */ -int send_subscribe(subs_info_t* subs) +int send_subscribe(subs_info_t *subs) { - ua_pres_t* presentity= NULL; - str met= {"SUBSCRIBE", 9}; - str* str_hdr= NULL; - int ret= -1; - unsigned int hash_code=0; - ua_pres_t* hentity= NULL; + ua_pres_t *presentity = NULL; + str met = {"SUBSCRIBE", 9}; + str *str_hdr = NULL; + int ret = -1; + unsigned int hash_code = 0; + ua_pres_t *hentity = NULL; int expires; int flag; int result; uac_req_t uac_r; - db1_res_t *res=NULL; + db1_res_t *res = NULL; ua_pres_t dbpres; - str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0}; - dlg_t* td= NULL; + str pres_uri = {0, 0}, watcher_uri = {0, 0}, extra_headers = {0, 0}; + dlg_t *td = NULL; memset(&dbpres, 0, sizeof(dbpres)); @@ -968,28 +888,26 @@ int send_subscribe(subs_info_t* subs) print_subs(subs); - flag= subs->source_flag; + flag = subs->source_flag; if(subs->source_flag & XMPP_INITIAL_SUBS) - subs->source_flag= XMPP_SUBSCRIBE; + subs->source_flag = XMPP_SUBSCRIBE; - if(subs->expires< 0) - expires= pua_default_expires; + if(subs->expires < 0) + expires = pua_default_expires; else - expires= subs->expires; + expires = subs->expires; - str_hdr= subs_build_hdr(subs->contact, expires, subs->event, - subs->extra_headers); - if(str_hdr== NULL || str_hdr->s== NULL) - { + str_hdr = subs_build_hdr( + subs->contact, expires, subs->event, subs->extra_headers); + if(str_hdr == NULL || str_hdr->s == NULL) { LM_ERR("while building extra headers\n"); - if(str_hdr) pkg_free(str_hdr); + if(str_hdr) + pkg_free(str_hdr); return -1; } - if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) - { - if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.start_transaction) { + if(pua_dbf.start_transaction(pua_db, db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -997,12 +915,9 @@ int send_subscribe(subs_info_t* subs) /* generation of hash and getting lock moved from here to further down */ - if (dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { presentity = get_dialog_puadb(subs->id, subs->pres_uri, &dbpres, &res); - } - else - { + } else { ua_pres_t pres; memset(&pres, 0, sizeof(ua_pres_t)); @@ -1011,72 +926,65 @@ int send_subscribe(subs_info_t* subs) pres.flag = subs->source_flag; pres.id = subs->id; pres.event = subs->event; - if (subs->remote_target) + if(subs->remote_target) pres.remote_contact = *subs->remote_target; - hash_code=core_hash(subs->pres_uri, subs->watcher_uri, HASH_SIZE); + hash_code = core_hash(subs->pres_uri, subs->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); - presentity= search_htable(&pres, hash_code); + presentity = search_htable(&pres, hash_code); } /* if flag == INSERT_TYPE insert no matter what the search result is */ - if(subs->flag & INSERT_TYPE) - { + if(subs->flag & INSERT_TYPE) { LM_DBG("A subscription request with insert type\n"); goto insert; } - if(presentity== NULL ) - { + if(presentity == NULL) { int size; -insert: + insert: - if (subs->expires == 0) - { + if(subs->expires == 0) { /* Don't create a new dialog when expires == 0 */ - if (dbmode != PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto done; } - if(subs->flag & UPDATE_TYPE) - { + if(subs->flag & UPDATE_TYPE) { LM_DBG("request for a subscription with update type" - " and no record found\n"); - subs->flag= INSERT_TYPE; + " and no record found\n"); + subs->flag = INSERT_TYPE; } - hentity= subscribe_cbparam(subs, REQ_OTHER); - if(hentity== NULL) - { + hentity = subscribe_cbparam(subs, REQ_OTHER); + if(hentity == NULL) { LM_ERR("while building callback" - " param\n"); - if (dbmode != PUA_DB_ONLY) + " param\n"); + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } - hentity->flag= flag; + hentity->flag = flag; set_uac_req(&uac_r, &met, str_hdr, 0, 0, TMCB_LOCAL_COMPLETED, - subs_cback_func, (void*)hentity); - result= tmb.t_request_outside - (&uac_r, /* Type of the message */ - subs->remote_target?subs->remote_target:subs->pres_uri,/* Request-URI*/ - subs->pres_uri, /* To */ - subs->watcher_uri, /* From */ - subs->outbound_proxy /* Outbound_proxy */ - ); - if(result< 0) - { + subs_cback_func, (void *)hentity); + result = tmb.t_request_outside(&uac_r, /* Type of the message */ + subs->remote_target ? subs->remote_target + : subs->pres_uri, /* Request-URI*/ + subs->pres_uri, /* To */ + subs->watcher_uri, /* From */ + subs->outbound_proxy /* Outbound_proxy */ + ); + if(result < 0) { LM_ERR("while sending request with t_request\n"); - if (uac_r.dialog != NULL) - { + if(uac_r.dialog != NULL) { uac_r.dialog->rem_target.s = 0; uac_r.dialog->dst_uri.s = 0; tmb.free_dlg(uac_r.dialog); uac_r.dialog = 0; } shm_free(hentity); - if (dbmode != PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); /* Although this is an error must not return -1 as the @@ -1088,49 +996,50 @@ int send_subscribe(subs_info_t* subs) /* Now create a temporary hash table entry. This is needed to deal with the race-hazard when NOTIFYs arrive before the 2xx response to the SUBSCRIBE. */ - size = sizeof(ua_pres_t)+ 2 * sizeof(str) + ( - subs->pres_uri->len + - subs->watcher_uri->len + - uac_r.dialog->id.loc_tag.len + - uac_r.dialog->id.call_id.len + - subs->id.len) * sizeof(char); - - presentity= (ua_pres_t*)shm_malloc(size); - if(presentity== NULL) - { + size = sizeof(ua_pres_t) + 2 * sizeof(str) + + (subs->pres_uri->len + subs->watcher_uri->len + + uac_r.dialog->id.loc_tag.len + + uac_r.dialog->id.call_id.len + subs->id.len) + * sizeof(char); + + presentity = (ua_pres_t *)shm_malloc(size); + if(presentity == NULL) { SHM_MEM_ERROR; - if (dbmode != PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } memset(presentity, 0, size); - size= sizeof(ua_pres_t); + size = sizeof(ua_pres_t); - presentity->pres_uri = (str *) ((char *) presentity + size); + presentity->pres_uri = (str *)((char *)presentity + size); size += sizeof(str); - presentity->pres_uri->s= (char *) presentity + size; + presentity->pres_uri->s = (char *)presentity + size; memcpy(presentity->pres_uri->s, subs->pres_uri->s, subs->pres_uri->len); - presentity->pres_uri->len= subs->pres_uri->len; - size+= subs->pres_uri->len; + presentity->pres_uri->len = subs->pres_uri->len; + size += subs->pres_uri->len; - presentity->watcher_uri= (str *) ((char *) presentity + size); + presentity->watcher_uri = (str *)((char *)presentity + size); size += sizeof(str); - presentity->watcher_uri->s= (char *) presentity + size; - memcpy(presentity->watcher_uri->s, subs->watcher_uri->s, subs->watcher_uri->len); + presentity->watcher_uri->s = (char *)presentity + size; + memcpy(presentity->watcher_uri->s, subs->watcher_uri->s, + subs->watcher_uri->len); presentity->watcher_uri->len = subs->watcher_uri->len; size += subs->watcher_uri->len; - presentity->call_id.s = (char *) presentity + size; - memcpy(presentity->call_id.s, uac_r.dialog->id.call_id.s, uac_r.dialog->id.call_id.len); + presentity->call_id.s = (char *)presentity + size; + memcpy(presentity->call_id.s, uac_r.dialog->id.call_id.s, + uac_r.dialog->id.call_id.len); presentity->call_id.len = uac_r.dialog->id.call_id.len; size += uac_r.dialog->id.call_id.len; - presentity->from_tag.s = (char *) presentity + size; - memcpy(presentity->from_tag.s, uac_r.dialog->id.loc_tag.s, uac_r.dialog->id.loc_tag.len); - presentity->from_tag.len= uac_r.dialog->id.loc_tag.len; + presentity->from_tag.s = (char *)presentity + size; + memcpy(presentity->from_tag.s, uac_r.dialog->id.loc_tag.s, + uac_r.dialog->id.loc_tag.len); + presentity->from_tag.len = uac_r.dialog->id.loc_tag.len; size += uac_r.dialog->id.loc_tag.len; - presentity->id.s = (char *) presentity+ size; + presentity->id.s = (char *)presentity + size; memcpy(presentity->id.s, subs->id.s, subs->id.len); presentity->id.len = subs->id.len; size += subs->id.len; @@ -1140,16 +1049,13 @@ int send_subscribe(subs_info_t* subs) presentity->cseq = uac_r.dialog->loc_seq.value; /* Set the temporary record expiry for 2 * 64T1 seconds from now */ - presentity->expires= (int)time(NULL) + 64; - presentity->desired_expires= presentity->expires; + presentity->expires = (int)time(NULL) + 64; + presentity->desired_expires = presentity->expires; - if (dbmode==PUA_DB_ONLY) - { + if(dbmode == PUA_DB_ONLY) { insert_dialog_puadb(presentity); shm_free(presentity); - } - else - { + } else { insert_htable(presentity, hash_code); lock_release(&HashT->p_records[hash_code].lock); } @@ -1158,64 +1064,60 @@ int send_subscribe(subs_info_t* subs) uac_r.dialog->dst_uri.s = 0; tmb.free_dlg(uac_r.dialog); uac_r.dialog = 0; - } - else - { - if (subs->internal_update_flag == INTERNAL_UPDATE_TRUE) - { - LM_INFO("attempting to re-SUBSCRIBE on internal (rls_update_subs()) update - skipping\n"); - if (dbmode != PUA_DB_ONLY) + } else { + if(subs->internal_update_flag == INTERNAL_UPDATE_TRUE) { + LM_INFO("attempting to re-SUBSCRIBE on internal " + "(rls_update_subs()) update - skipping\n"); + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto done; } - if (presentity->to_tag.len == 0) - { - if (subs->expires > 0) - LM_WARN("attempting to re-SUBSCRIBE to a temporary (non-established) dialog - skipping\n"); - else - { - LM_WARN("attempting to un-SUBSCRIBE from a temporary (non-established) dialog - skipping and deleting dialog\n"); - if (dbmode==PUA_DB_ONLY) + if(presentity->to_tag.len == 0) { + if(subs->expires > 0) + LM_WARN("attempting to re-SUBSCRIBE to a temporary " + "(non-established) dialog - skipping\n"); + else { + LM_WARN("attempting to un-SUBSCRIBE from a temporary " + "(non-established) dialog - skipping and deleting " + "dialog\n"); + if(dbmode == PUA_DB_ONLY) delete_dialog_puadb(presentity); else delete_htable(presentity, hash_code); } - if (dbmode != PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto done; } - td= pua_build_dlg_t(presentity); - if(td== NULL) - { + td = pua_build_dlg_t(presentity); + if(td == NULL) { LM_ERR("while building tm dlg_t structure"); - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } - hentity= subs_cbparam_indlg(presentity, expires, REQ_OTHER); - if(hentity== NULL) - { + hentity = subs_cbparam_indlg(presentity, expires, REQ_OTHER); + if(hentity == NULL) { LM_ERR("while building callback param\n"); - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); goto error; } - if (dbmode!=PUA_DB_ONLY) + if(dbmode != PUA_DB_ONLY) lock_release(&HashT->p_records[hash_code].lock); LM_DBG("event parameter: %d\n", hentity->event); set_uac_req(&uac_r, &met, str_hdr, 0, td, TMCB_LOCAL_COMPLETED, - subs_cback_func, (void*)hentity); - result= tmb.t_request_within(&uac_r); - if(result< 0) - { + subs_cback_func, (void *)hentity); + result = tmb.t_request_within(&uac_r); + if(result < 0) { shm_free(hentity); - hentity= NULL; + hentity = NULL; LM_ERR("while sending request with t_request\n"); goto error; } @@ -1223,10 +1125,8 @@ int send_subscribe(subs_info_t* subs) done: - if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) - { - if (pua_dbf.end_transaction(pua_db) < 0) - { + if(dbmode == PUA_DB_ONLY && pua_dbf.end_transaction) { + if(pua_dbf.end_transaction(pua_db) < 0) { LM_ERR("in end_transaction\n"); goto error; } @@ -1239,9 +1139,8 @@ int send_subscribe(subs_info_t* subs) pkg_free(str_hdr); free_results_puadb(res); - if (dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) - { - if (pua_dbf.abort_transaction(pua_db) < 0) + if(dbmode == PUA_DB_ONLY && pua_dbf.abort_transaction) { + if(pua_dbf.abort_transaction(pua_db) < 0) LM_ERR("in abort_transaction\n"); } diff --git a/src/modules/pua/send_subscribe.h b/src/modules/pua/send_subscribe.h index abe95d6c9fb..71843a1adb5 100644 --- a/src/modules/pua/send_subscribe.h +++ b/src/modules/pua/send_subscribe.h @@ -33,30 +33,31 @@ typedef struct subs_info { str id; - str* pres_uri; - str* watcher_uri; - str* contact; - str* remote_target; - str* outbound_proxy; + str *pres_uri; + str *watcher_uri; + str *contact; + str *remote_target; + str *outbound_proxy; int event; - str* extra_headers; + str *extra_headers; int expires; int source_flag; - int flag; /* it can be : INSERT_TYPE or UPDATE_TYPE; not compulsory */ - void* cb_param; /* the parameter for the function to be called on the callback + int flag; /* it can be : INSERT_TYPE or UPDATE_TYPE; not compulsory */ + void *cb_param; /* the parameter for the function to be called on the callback for the received reply; it must be allocated in share memory; a reference to it will be found in the cb_param filed of the ua_pres_structure received as a parameter for the registered function*/ int internal_update_flag; -}subs_info_t; +} subs_info_t; -typedef int (*send_subscribe_t)(subs_info_t* subs); -int send_subscribe(subs_info_t* subs); +typedef int (*send_subscribe_t)(subs_info_t *subs); +int send_subscribe(subs_info_t *subs); void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps); -str* subs_build_hdr(str* watcher_uri, int expires, int event, str* extra_headers); -dlg_t* pua_build_dlg_t(ua_pres_t* presentity); -ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag); -ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag); +str *subs_build_hdr( + str *watcher_uri, int expires, int event, str *extra_headers); +dlg_t *pua_build_dlg_t(ua_pres_t *presentity); +ua_pres_t *subscribe_cbparam(subs_info_t *subs, int ua_flag); +ua_pres_t *subs_cbparam_indlg(ua_pres_t *subs, int expires, int ua_flag); #endif