unsigned long insert_htable(ua_pres_t* presentity) { unsigned int hash_code; str* s1; unsigned long pres_id; ua_pres_t* p; if(presentity->to_uri.s) s1 = &presentity->to_uri; else s1 = presentity->pres_uri; LM_DBG("to_uri= %.*s, watcher_uri= %.*s\n", s1->len, s1->s, (presentity->watcher_uri?presentity->watcher_uri->len:0), (presentity->watcher_uri?presentity->watcher_uri->s:0)); hash_code= core_hash(s1, presentity->watcher_uri, HASH_SIZE); presentity->hash_index = hash_code; LM_DBG("hash_code = %d\n", hash_code); lock_get(&HashT->p_records[hash_code].lock); p= HashT->p_records[hash_code].entity; presentity->db_flag= INSERTDB_FLAG; presentity->next= p->next; if(p->next) { presentity->local_index = p->next->local_index + 1; } else presentity->local_index = 0; p->next= presentity; pres_id = PRES_HASH_ID(presentity); lock_release(&HashT->p_records[hash_code].lock); return pres_id; }
int send_publish_int(ua_pres_t* presentity, publ_info_t* publ, pua_event_t* ev, int hash_index) { unsigned long pres_id= 0; int ret = ERR_PUBLISH_GENERIC; char etag_buf[256]; char tuple_buf[128]; str tuple_id= {0, 0}; str etag= {0, 0}; int ver= 0; str* body= NULL; str* str_hdr = NULL; str met = {"PUBLISH", 7}; LM_DBG("start\n"); if(presentity) { LM_DBG("presentity exists\n"); pres_id = PRES_HASH_ID(presentity); ver= ++presentity->version; /* copy etag */ if(presentity->etag.s) { etag.s = etag_buf; memcpy(etag.s, presentity->etag.s, presentity->etag.len); etag.len = presentity->etag.len; } /* tuple id */ if(presentity->tuple_id.s) { tuple_id.s = tuple_buf; memcpy(tuple_id.s, presentity->tuple_id.s, presentity->tuple_id.len); tuple_id.len = presentity->tuple_id.len; } presentity->desired_expires= publ->expires + (int)time(NULL); presentity->waiting_reply = 1; presentity->cb_param = publ->cb_param; if(publ->expires== 0) { LM_DBG("expires= 0- delete from hash table\n"); delete_htable_safe(presentity, hash_index); } } lock_release(&HashT->p_records[hash_index].lock); /* handle body */ if(publ->body && publ->body->s) { if(ev->process_body) { if(ev->process_body(publ, &body, ver, &tuple_id)< 0 || body== NULL) { LM_ERR("while processing body\n"); goto error; } } else body = publ->body; LM_DBG("Handled body [%.*s]\n", body->len, body->s); } if(publ->expires!= 0 && publ->expires< min_expires) publ->expires = min_expires; if(presentity== NULL) { if(publ->expires== 0) { LM_DBG("request for a publish with expires 0 and" " no record found\n"); ret = ERR_PUBLISH_NO_RECORD; goto error; } if(publ->body== NULL) { if (ev->content_type.s && ev->content_type.len) { LM_ERR("New '%.*s' PUBLISH and no body found - invalid request\n", ev->name.len, ev->name.s); ret = ERR_PUBLISH_NO_BODY; goto error; } } pres_id = new_publ_record(publ, ev, &tuple_id); } str_hdr = publ_build_hdr(((publ->expires< 0)?3600:publ->expires), ev, &publ->content_type, (etag.s?&etag:NULL), publ->extra_headers, ((body)?1:0)); 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 ) LM_DBG("body:\n%.*s\n ", body->len, body->s); LM_DBG("cback param = %ld\n", pres_id); tmb.t_request(&met, /* Type of the message */ publ->pres_uri, /* Request-URI */ publ->pres_uri, /* To */ publ->pres_uri, /* From */ str_hdr, /* Optional headers */ body, /* Message body */ ((publ->outbound_proxy.s)?&publ->outbound_proxy:0),/*Outbound proxy*/ publ->expires?publ_cback_func:0, /* Callback function */ (void*)pres_id, /* Callback parameter */ 0 ); pkg_free(str_hdr); if(body && ev->process_body) { if(body->s) xmlFree(body->s); pkg_free(body); } return ERR_PUBLISH_NO_ERROR; error: if(body && ev->process_body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(str_hdr) pkg_free(str_hdr); return ret; }