event_t *shm_copy_event(event_t *e) { event_t *ev = NULL; param_t *p1, *p2; int size; ev = (event_t *)shm_malloc(sizeof(event_t)); if(ev == NULL) { ERR_MEM(SHARE_MEM); } memset(ev, 0, sizeof(event_t)); ev->name.s = (char *)shm_malloc(e->name.len * sizeof(char)); if(ev->name.s == NULL) { ERR_MEM(SHARE_MEM); } memcpy(ev->name.s, e->name.s, e->name.len); ev->name.len = e->name.len; p1 = e->params.list; while(p1) { size = sizeof(param_t) + (p1->name.len + p1->body.len) * sizeof(char); p2 = (param_t *)shm_malloc(size); if(p2 == NULL) { ERR_MEM(SHARE_MEM); } memset(p2, 0, size); size = sizeof(param_t); CONT_COPY(p2, p2->name, p1->name); if(p1->body.s && p1->body.len) CONT_COPY(p2, p2->body, p1->body); p2->next = ev->params.list; ev->params.list = p2; /* Update parameter hooks in the shmmem copy, this is needed so that * we can test for the presence of the sla parameter even in the * shared copy of the event */ if(e->params.hooks.event_dialog.call_id == p1) ev->params.hooks.event_dialog.call_id = p2; if(e->params.hooks.event_dialog.from_tag == p1) ev->params.hooks.event_dialog.from_tag = p2; if(e->params.hooks.event_dialog.to_tag == p1) ev->params.hooks.event_dialog.to_tag = p2; if(e->params.hooks.event_dialog.include_session_description == p1) ev->params.hooks.event_dialog.include_session_description = p2; if(e->params.hooks.event_dialog.sla == p1) ev->params.hooks.event_dialog.sla = p2; p1 = p1->next; } ev->type = e->type; return ev; error: shm_free_event(ev); return NULL; }
event_t* shm_copy_event(event_t* e) { event_t* ev= NULL; param_t* p1, *p2; int size; ev= (event_t*)shm_malloc(sizeof(event_t)); if(ev== NULL) { ERR_MEM(SHARE_MEM); } memset(ev, 0, sizeof(event_t)); ev->text.s= (char*)shm_malloc(e->text.len); if(ev->text.s== NULL) { ERR_MEM(SHARE_MEM); } memcpy(ev->text.s, e->text.s, e->text.len); ev->text.len= e->text.len; p1= e->params; while(p1) { size= sizeof(param_t)+ p1->name.len+ p1->body.len; p2= (param_t*)shm_malloc(size); if(p2== NULL) { ERR_MEM(SHARE_MEM); } memset(p2, 0, size); size= sizeof(param_t); CONT_COPY(p2, p2->name, p1->name); if(p1->body.s && p1->body.len) CONT_COPY(p2, p2->body, p1->body); p2->next= ev->params; ev->params= p2; p1= p1->next; } ev->parsed= e->parsed; return ev; error: shm_free_event(ev); return NULL; }
publ_t* build_pending_publ(publ_info_t* publ) { publ_t* p; int size; size = sizeof(publ_t) + ((publ->body)?publ->body->len:0) + publ->content_type.len + ((publ->extra_headers)?publ->extra_headers->len:0); p = (publ_t*)shm_malloc(size); if(p == NULL) { LM_ERR("No more share memory\n"); return 0; } memset(p, 0, size); size = sizeof(publ_t); if(publ->body && publ->body->s) { p->body.s = (char*)p + size; memcpy(p->body.s, publ->body->s, publ->body->len); p->body.len = publ->body->len; size+= publ->body->len; } if(publ->extra_headers && publ->extra_headers->s) { p->extra_headers.s = (char*)p + size; memcpy(p->extra_headers.s, publ->extra_headers->s, publ->extra_headers->len); p->extra_headers.len = publ->extra_headers->len; size+= publ->extra_headers->len; LM_DBG("saved [%.*s]\n", p->extra_headers.len, p->extra_headers.s); } CONT_COPY(p, p->content_type, publ->content_type); p->expires = publ->expires; p->cb_param = publ->cb_param; return p; }
ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag) { 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; 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; if(subs->remote_contact.s) size+= subs->remote_contact.len; hentity= (ua_pres_t*)shm_malloc(size); if(hentity== NULL) { LM_ERR("No more share memory\n"); 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; 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->id.s) { CONT_COPY(hentity, hentity->id, subs->id) } 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; 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; } /* copy dialog information */ CONT_COPY(hentity, hentity->to_tag, subs->to_tag) 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; else 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; return hentity; }
ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag) { 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); 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); hentity= (ua_pres_t*)shm_malloc(size); if(hentity== NULL) { LM_ERR("No more share memory\n"); 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) { 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; else hentity->desired_expires=subs->expires+ (int)time(NULL); if(subs->id.s) { CONT_COPY(hentity, hentity->id, subs->id) } if(subs->extra_headers) { 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->flag= subs->source_flag; hentity->event= subs->event; hentity->ua_flag= ua_flag; hentity->cb_param= subs->cb_param; return hentity; }
str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, b2b_add_dlginfo_t add_dlginfo, str* param) { int result; b2b_dlg_t* dlg; unsigned int hash_index; str* callid = NULL; int size; str ehdr = {0, 0}; str* b2b_key_shm = NULL; dlg_t td; str from_tag; str random_info = {0, 0}; if(ci == NULL || b2b_cback == NULL || param== NULL) { LM_ERR("Wrong parameters.\n"); return NULL; } if(param && param->len > B2BL_MAX_KEY_LEN) { LM_ERR("parameter too long, received [%d], maximum [%d]\n", param->len, B2BL_MAX_KEY_LEN); return 0; } hash_index = core_hash(&ci->from_uri, &ci->to_uri, client_hsize); if(ci->from_tag) from_tag = *ci->from_tag; else generate_tag(&from_tag, &ci->from_uri, ci->extra_headers); /* create a dummy b2b dialog structure to be inserted in the hash table*/ size = sizeof(b2b_dlg_t) + ci->to_uri.len + ci->from_uri.len + ci->from_dname.len + ci->to_dname.len + from_tag.len + ci->local_contact.len + B2B_MAX_KEY_SIZE + B2BL_MAX_KEY_LEN; /* create record in hash table */ dlg = (b2b_dlg_t*)shm_malloc(size); if(dlg == NULL) { LM_ERR("No more shared memory\n"); return 0; } memset(dlg, 0, size); size = sizeof(b2b_dlg_t); CONT_COPY(dlg, dlg->from_uri, ci->from_uri); CONT_COPY(dlg, dlg->to_uri, ci->to_uri); if(ci->to_dname.s) CONT_COPY(dlg, dlg->to_dname, ci->to_dname); if(ci->from_dname.s) CONT_COPY(dlg, dlg->from_dname, ci->from_dname); CONT_COPY(dlg, dlg->tag[CALLER_LEG], from_tag); CONT_COPY(dlg, dlg->contact[CALLER_LEG], ci->local_contact); if(param && param->s) { dlg->param.s = (char*)dlg + size; memcpy(dlg->param.s, param->s, param->len); dlg->param.len = param->len; size+= B2BL_MAX_KEY_LEN; } dlg->b2b_cback = b2b_cback; dlg->add_dlginfo = add_dlginfo; if(parse_method(ci->method.s, ci->method.s+ci->method.len, &dlg->last_method)< 0) { LM_ERR("wrong method %.*s\n", ci->method.len, ci->method.s); shm_free(dlg); goto error; } dlg->state = B2B_NEW; dlg->cseq[CALLER_LEG] =(ci->cseq?ci->cseq:1); dlg->send_sock = ci->send_sock; /* if the callid should be the same in more instances running at the same time (replication)*/ if(!replication_mode) { srand(get_uticks()); random_info.s = int2str(rand(), &random_info.len); } dlg->send_sock = ci->send_sock; dlg->id = core_hash(&from_tag, random_info.s?&random_info:0, HASH_SIZE); /* callid must have the special format */ dlg->db_flag = NO_UPDATEDB_FLAG; callid = b2b_htable_insert(client_htable, dlg, hash_index, B2B_CLIENT, 0); if(callid == NULL) { LM_ERR("Inserting new record in hash table failed\n"); shm_free(dlg); goto error; } if(b2breq_complete_ehdr(ci->extra_headers, &ehdr, ci->body, &ci->local_contact)< 0) { LM_ERR("Failed to complete extra headers\n"); goto error; } /* copy the key in shared memory to transmit it as a parameter to the tm callback */ b2b_key_shm = b2b_key_copy_shm(callid); if(b2b_key_shm== NULL) { LM_ERR("no more shared memory\n"); goto error; } CONT_COPY(dlg, dlg->callid, (*callid)); /* create the tm dialog structure with the a costum callid */ memset(&td, 0, sizeof(dlg_t)); td.loc_seq.value = dlg->cseq[CALLER_LEG]; dlg->last_invite_cseq = dlg->cseq[CALLER_LEG]; td.loc_seq.is_set = 1; td.id.call_id = *callid; td.id.loc_tag = from_tag; td.id.rem_tag.s = 0; td.id.rem_tag.len = 0; td.rem_uri = ci->to_uri; if(ci->req_uri.s) td.rem_target = ci->req_uri; else td.rem_target = ci->to_uri; if(td.rem_target.s[0] == '<') { td.rem_target.s++; td.rem_target.len-=2; } td.rem_dname = ci->to_dname; td.loc_uri = ci->from_uri; td.loc_dname = ci->from_dname; td.state= DLG_CONFIRMED; td.T_flags=T_NO_AUTOACK_FLAG|T_PASS_PROVISIONAL_FLAG ; td.send_sock = ci->send_sock; if(ci->dst_uri.len) td.obp = ci->dst_uri; td.avps = ci->avps; tmb.setlocalTholder(&dlg->uac_tran); /* send request */ result= tmb.t_request_within (&ci->method, /* method*/ &ehdr, /* extra headers*/ ci->body, /* body*/ &td, /* dialog structure*/ b2b_client_tm_cback, /* callback function*/ b2b_key_shm, shm_free_param); /* function to release the parameter*/ if(td.route_set) pkg_free(td.route_set); if(result< 0) { LM_ERR("while sending request with t_request\n"); pkg_free(callid); shm_free(b2b_key_shm); return NULL; } tmb.setlocalTholder(NULL); LM_DBG("new client entity [%p] callid=[%.*s] tag=[%.*s] param=[%.*s]" " last method=[%d] dlg->uac_tran=[%p]\n", dlg, callid->len, callid->s, dlg->tag[CALLER_LEG].len, dlg->tag[CALLER_LEG].s, dlg->param.len, dlg->param.s, dlg->last_method, dlg->uac_tran); return callid; error: if(callid) pkg_free(callid); return NULL; }
ua_pres_t* new_ua_pres(publ_info_t* publ, str* tuple_id) { unsigned int size; ua_pres_t* presentity; size= sizeof(ua_pres_t) + sizeof(str)+ publ->pres_uri->len+ publ->id.len; if(publ->outbound_proxy.s) size+= sizeof(str)+ publ->outbound_proxy.len; if(tuple_id->s) size+= tuple_id->len; presentity= (ua_pres_t*)shm_malloc(size); if(presentity== NULL) { LM_ERR("no more share memory\n"); goto error; } memset(presentity, 0, size); size= sizeof(ua_pres_t); presentity->pres_uri= (str*)((char*)presentity+ size); size+= sizeof(str); presentity->pres_uri->s= (char*)presentity+ size; memcpy(presentity->pres_uri->s, publ->pres_uri->s, publ->pres_uri->len); presentity->pres_uri->len= publ->pres_uri->len; size+= publ->pres_uri->len; // presentity->id.s=(char*)presentity+ size; CONT_COPY(presentity, presentity->id, publ->id); if(publ->extra_headers && publ->extra_headers->s && publ->extra_headers->len) { presentity->extra_headers.s = (char*)shm_malloc(publ->extra_headers->len); if(presentity->extra_headers.s == NULL) { LM_ERR("No more shared memory\n"); goto error; } memcpy(presentity->extra_headers.s, publ->extra_headers->s, publ->extra_headers->len); presentity->extra_headers.len = publ->extra_headers->len; } if(publ->outbound_proxy.s) { presentity->outbound_proxy= (str*)((char*)presentity+ size); size+= sizeof(str); presentity->outbound_proxy->s= (char*)presentity+ size; memcpy(presentity->outbound_proxy->s, publ->outbound_proxy.s, publ->outbound_proxy.len); presentity->outbound_proxy->len= publ->outbound_proxy.len; size+= publ->outbound_proxy.len; } presentity->desired_expires= publ->expires + (int)time(NULL); presentity->flag = publ->source_flag; presentity->event = publ->event; presentity->cb_param = publ->cb_param; presentity->waiting_reply = 1; return presentity; error: if (presentity) shm_free(presentity); return NULL; }
NODE* mem_copy_call_noc(ESCT* s){ int size; NODE* dest = NULL; NODE* dest_atr; int size_esgwri; int size_esgw; int size_esqk; int size_callid; int size_ert_srid; int size_datetimestamp; int size_lro; int size_disposition; int size_result; int size_source_organizationname; int size_source_hostname; int size_source_nenaid; int size_source_contact; int size_source_certuri; int size_vpc_organizationname; int size_vpc_hostname; int size_vpc_nenaid; int size_vpc_contact; int size_vpc_certuri; int size_call_id; int size_local_tag; int size_rem_tag; char *p; size_esgwri = s->esgwri? strlen(s->esgwri)+1:1; size_esgw = s->esgw?strlen(s->esgw)+1:1; size_esqk = s->esqk? strlen(s->esqk)+1:1; size_callid = s->callid? strlen(s->callid)+1:1; size_ert_srid = s->ert_srid? strlen(s->ert_srid)+1:1; size_datetimestamp = s->datetimestamp? strlen(s->datetimestamp)+1:1; size_lro = s->lro? strlen(s->lro)+1:1; size_disposition = s->disposition? strlen(s->disposition)+1:1; size_result = s->result? strlen(s->result)+1:1; size_source_organizationname = s->source->organizationname? strlen(s->source->organizationname)+1:1; size_source_hostname = s->source->hostname? strlen(s->source->hostname)+1:1; size_source_nenaid = s->source->nenaid? strlen(s->source->nenaid)+1:1; size_source_contact = s->source->contact? strlen(s->source->contact)+1:1; size_source_certuri = s->source->certuri? strlen(s->source->certuri)+1:1; size_vpc_organizationname = s->vpc->organizationname? strlen(s->vpc->organizationname)+1:1; size_vpc_hostname = s->vpc->hostname? strlen(s->vpc->hostname)+1:1; size_vpc_nenaid = s->vpc->nenaid? strlen(s->vpc->nenaid)+1:1; size_vpc_contact = s->vpc->contact? strlen(s->vpc->contact)+1:1; size_vpc_certuri = s->vpc->certuri? strlen(s->vpc->certuri)+1:1; size_call_id = s->eme_dlg_id->call_id? strlen(s->eme_dlg_id->call_id)+1:1; size_local_tag = s->eme_dlg_id->local_tag? strlen(s->eme_dlg_id->local_tag)+1:1; size_rem_tag = s->eme_dlg_id->rem_tag? strlen(s->eme_dlg_id->rem_tag)+1:1; size= sizeof(NODE)+ sizeof(ESCT)+ (2 * sizeof(NENA)) + sizeof(struct dialog_set) + size_esgwri + size_esgw + size_esqk+ size_callid + size_ert_srid + size_datetimestamp + size_lro + size_disposition + size_result + size_call_id + size_local_tag + size_rem_tag + size_source_organizationname + size_source_hostname + size_source_nenaid + size_source_contact + size_source_certuri + size_vpc_organizationname + size_vpc_hostname + size_vpc_nenaid + size_vpc_contact + size_vpc_certuri; p= (char*)shm_malloc(size); if(p== NULL){ //ERR_MEM(SHARE_MEM); goto error; } memset(p, 0, size); dest = (NODE*)p; p = p + sizeof(NODE); dest->esct = (ESCT*)p; p = p + sizeof(ESCT); dest->esct->eme_dlg_id = (struct dialog_set*)p; size= sizeof(struct dialog_set ); CONT_COPY(dest->esct->eme_dlg_id, dest->esct->eme_dlg_id->call_id, s->eme_dlg_id->call_id); CONT_COPY(dest->esct->eme_dlg_id, dest->esct->eme_dlg_id->local_tag, s->eme_dlg_id->local_tag); CONT_COPY(dest->esct->eme_dlg_id, dest->esct->eme_dlg_id->rem_tag, s->eme_dlg_id->rem_tag); p = p + size; dest->esct->source = (NENA*)p; size= sizeof(NENA); CONT_COPY(dest->esct->source, dest->esct->source->organizationname, s->source->organizationname); CONT_COPY(dest->esct->source, dest->esct->source->hostname, s->source->hostname); CONT_COPY(dest->esct->source, dest->esct->source->nenaid, s->source->nenaid); CONT_COPY(dest->esct->source, dest->esct->source->contact, s->source->contact); CONT_COPY(dest->esct->source, dest->esct->source->certuri, s->source->certuri); p = p + size; dest->esct->vpc = (NENA*)p; size= sizeof(NENA); CONT_COPY(dest->esct->vpc, dest->esct->vpc->organizationname, s->vpc->organizationname); CONT_COPY(dest->esct->vpc, dest->esct->vpc->hostname, s->vpc->hostname); CONT_COPY(dest->esct->vpc, dest->esct->vpc->nenaid, s->vpc->nenaid); CONT_COPY(dest->esct->vpc, dest->esct->vpc->contact, s->vpc->contact); CONT_COPY(dest->esct->vpc, dest->esct->vpc->certuri, s->vpc->certuri); p = p + size; dest_atr = (NODE*)p; size = 0; CONT_COPY(dest_atr, dest->esct->esgwri, s->esgwri); CONT_COPY(dest_atr, dest->esct->esgw, s->esgw); CONT_COPY(dest_atr, dest->esct->esqk, s->esqk); CONT_COPY(dest_atr, dest->esct->callid, s->callid); CONT_COPY(dest_atr, dest->esct->ert_srid, s->ert_srid); CONT_COPY(dest_atr, dest->esct->datetimestamp, s->datetimestamp); CONT_COPY(dest_atr, dest->esct->lro, s->lro); CONT_COPY(dest_atr, dest->esct->disposition, s->disposition); CONT_COPY(dest_atr, dest->esct->result, s->result); LM_DBG(" ---INSERT HASH %s \n\n", dest->esct->esgwri); LM_DBG(" ---INSERT ESGWRI %s \n\n", s->esgwri); dest->esct->ert_resn= s->ert_resn; dest->esct->ert_npa= s->ert_npa; dest->esct->timeout= s->timeout; return dest; error: if(dest) shm_free(dest); return NULL; }
static int db_restore(void) { ua_pres_t* p= NULL; db_key_t result_cols[20]; db_res_t *res= NULL; db_row_t *row = NULL; db_val_t *row_vals= NULL; str pres_uri, pres_id, to_uri; 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,touri_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; int no_rows = 10; result_cols[puri_col=n_result_cols++] = &str_pres_uri_col; result_cols[touri_col=n_result_cols++] = &str_to_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) { LM_ERR("in use table\n"); return -1; } if (DB_CAPABILITY(pua_dbf, DB_CAP_FETCH)) { if(pua_dbf.query(pua_db,0, 0, 0, result_cols,0, n_result_cols, 0,0)< 0) { LM_ERR("while querying table\n"); return -1; } no_rows = estimate_available_rows( 128+128+8+8+4+32+64+64+128+ 128+64+64+16+64, n_result_cols); if (no_rows==0) no_rows = 10; if(pua_dbf.fetch_result(pua_db, &res, no_rows)<0) { LM_ERR("Error fetching rows\n"); return -1; } } else { if(pua_dbf.query(pua_db,0, 0, 0,result_cols,0,n_result_cols,0,&res)< 0) { LM_ERR("while querrying table\n"); if(res) { pua_dbf.free_result(pua_db, res); res = NULL; } return -1; } } if(res== NULL) return -1; if(res->n<=0) { LM_INFO("the query returned no result\n"); pua_dbf.free_result(pua_db, res); res = NULL; return 0; } LM_DBG("found %d db entries\n", res->n); do { for(i =0 ; i< res->n ; i++) { row = &res->rows[i]; row_vals = ROW_VALUES(row); if(row_vals[expires_col].val.int_val < time(NULL)) continue; 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(&to_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; etag.len = strlen(etag.s); 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; watcher_uri.len = strlen(watcher_uri.s); to_uri.s= (char*)row_vals[touri_col].val.string_val; if(to_uri.s == NULL) to_uri = pres_uri; else to_uri.len = strlen(to_uri.s); LM_DBG("to_uri= %.*s\n", to_uri.len, to_uri.s); 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.len = strlen(to_tag.s); 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); } 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; if(remote_contact.s) remote_contact.len = strlen(remote_contact.s); } extra_headers.s= (char*)row_vals[extra_headers_col].val.string_val; if(extra_headers.s) extra_headers.len= strlen(extra_headers.s); else extra_headers.len= 0; size= sizeof(ua_pres_t)+ sizeof(str)+ (pres_uri.len+ pres_id.len+ tuple_id.len)* sizeof(char); if(watcher_uri.s) size+= sizeof(str)+ to_uri.len + watcher_uri.len+ call_id.len+ to_tag.len+ from_tag.len+ record_route.len+ contact.len; p= (ua_pres_t*)shm_malloc(size); if(p== NULL) { LM_ERR("no more shared memmory"); goto error; } memset(p, 0, size); size= sizeof(ua_pres_t); 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; if(pres_id.s) { CONT_COPY(p, p->id, pres_id); } if(watcher_uri.s && watcher_uri.len) { p->watcher_uri= (str*)((char*)p+ size); size+= sizeof(str); 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; CONT_COPY(p, p->to_uri, to_uri); CONT_COPY(p, p->to_tag, to_tag); CONT_COPY(p, p->from_tag, from_tag); CONT_COPY(p, p->call_id, call_id); if(record_route.s && record_route.len) { CONT_COPY(p, p->record_route, record_route); } CONT_COPY(p, p->contact, contact); p->cseq= row_vals[cseq_col].val.int_val; p->remote_contact.s= (char*)shm_malloc(remote_contact.len); if(p->remote_contact.s== NULL) { LM_ERR("No more shared memory\n"); goto error; } 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; } 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; memset(&p->etag, 0, sizeof(str)); if(etag.s && etag.len) { /* alloc separately */ p->etag.s= (char*)shm_malloc(etag.len); if(p->etag.s== NULL) { LM_ERR("no more share memory\n"); goto error; } memcpy(p->etag.s, etag.s, etag.len); p->etag.len= etag.len; } memset(&p->extra_headers, 0, sizeof(str)); if(extra_headers.s && extra_headers.len) { /* alloc separately */ p->extra_headers.s= (char*)shm_malloc(extra_headers.len); if(p->extra_headers.s== NULL) { LM_ERR("no more share memory\n"); goto error; } memcpy(p->extra_headers.s, extra_headers.s, extra_headers.len); p->extra_headers.len= extra_headers.len; } print_ua_pres(p); insert_htable(p); } /* end for(all rows)*/ if (DB_CAPABILITY(pua_dbf, DB_CAP_FETCH)) { if(pua_dbf.fetch_result(pua_db, &res, no_rows)<0) { LM_ERR( "fetching rows (1)\n"); goto error; } } else { break; } } while(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) { LM_ERR("while deleting information from db\n"); goto error; } return 0; error: if(res) pua_dbf.free_result(pua_db, res); if(p) { if(p->remote_contact.s) shm_free(p->remote_contact.s); if(p->extra_headers.s) shm_free(p->extra_headers.s); if(p->etag.s) shm_free(p->etag.s); shm_free(p); } return -1; }
subs_t* mem_copy_subs_noc(subs_t* s) { int size; subs_t* dest; size= sizeof(subs_t)+ s->pres_uri.len+ s->to_user.len + s->to_domain.len+ s->from_user.len+ s->from_domain.len+ s->callid.len + s->to_tag.len+ s->from_tag.len+s->event_id.len + s->local_contact.len + s->record_route.len+ + s->reason.len+ 1; dest= (subs_t*)shm_malloc(size); if(dest== NULL) { ERR_MEM(SHARE_MEM); } memset(dest, 0, size); size= sizeof(subs_t); CONT_COPY(dest, dest->pres_uri, s->pres_uri); CONT_COPY(dest, dest->to_user, s->to_user); CONT_COPY(dest, dest->to_domain, s->to_domain); CONT_COPY(dest, dest->from_user, s->from_user); CONT_COPY(dest, dest->from_domain, s->from_domain); CONT_COPY(dest, dest->to_tag, s->to_tag); CONT_COPY(dest, dest->from_tag, s->from_tag); CONT_COPY(dest, dest->callid, s->callid); CONT_COPY(dest, dest->local_contact, s->local_contact); CONT_COPY(dest, dest->record_route, s->record_route); if(s->event_id.s) CONT_COPY(dest, dest->event_id, s->event_id); if(s->reason.s) CONT_COPY(dest, dest->reason, s->reason); dest->event= s->event; dest->local_cseq= s->local_cseq; dest->remote_cseq= s->remote_cseq; dest->status= s->status; dest->version= s->version; dest->expires= s->expires; dest->db_flag= s->db_flag; dest->sockinfo = s->sockinfo; dest->contact.s= (char*)shm_malloc(s->contact.len); if(dest->contact.s== NULL) { ERR_MEM(SHARE_MEM); } memcpy(dest->contact.s, s->contact.s, s->contact.len); dest->contact.len= s->contact.len; return dest; error: if(dest) shm_free(dest); return NULL; }
subs_t* mem_copy_subs(subs_t* s, int mem_type) { int size; subs_t* dest; size= sizeof(subs_t)+ s->pres_uri.len+ s->to_user.len + s->to_domain.len+ s->from_user.len+ s->from_domain.len+ s->callid.len + s->to_tag.len+ s->from_tag.len+s->event_id.len + s->local_contact.len+ s->contact.len+ s->record_route.len+ + s->reason.len+ 1; if(mem_type == PKG_MEM_TYPE) dest= (subs_t*)pkg_malloc(size); else dest= (subs_t*)shm_malloc(size); if(dest== NULL) { ERR_MEM((mem_type==PKG_MEM_TYPE)?PKG_MEM_STR:SHARE_MEM); } memset(dest, 0, size); size= sizeof(subs_t); CONT_COPY(dest, dest->pres_uri, s->pres_uri); CONT_COPY(dest, dest->to_user, s->to_user); CONT_COPY(dest, dest->to_domain, s->to_domain); CONT_COPY(dest, dest->from_user, s->from_user); CONT_COPY(dest, dest->from_domain, s->from_domain); CONT_COPY(dest, dest->to_tag, s->to_tag); CONT_COPY(dest, dest->from_tag, s->from_tag); CONT_COPY(dest, dest->callid, s->callid); CONT_COPY(dest, dest->local_contact, s->local_contact); CONT_COPY(dest, dest->contact, s->contact); CONT_COPY(dest, dest->record_route, s->record_route); if(s->event_id.s) CONT_COPY(dest, dest->event_id, s->event_id); if(s->reason.s) CONT_COPY(dest, dest->reason, s->reason); dest->event= s->event; dest->local_cseq= s->local_cseq; dest->remote_cseq= s->remote_cseq; dest->status= s->status; dest->version= s->version; dest->expires= s->expires; dest->db_flag= s->db_flag; dest->sockinfo= s->sockinfo; return dest; error: if(dest) { if(mem_type == PKG_MEM_TYPE) pkg_free(dest); else shm_free(dest); } return NULL; }