int get_record_id(ua_pres_t* dialog, str** rec_id) { unsigned int hash_code; ua_pres_t* rec; str* id; if (dbmode==PUA_DB_ONLY) { return( get_record_id_puadb( dialog, rec_id ) ); } *rec_id= NULL; 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) { LM_DBG("Record not found - looking for temporary\n"); rec = get_temporary_dialog(dialog, hash_code); 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) { LM_ERR("No more memory\n"); lock_release(&HashT->p_records[hash_code].lock); return -1; } id->s= (char*)pkg_malloc(rec->id.len* sizeof(char)); if(id->s== NULL) { LM_ERR("No more memory\n"); 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; lock_release(&HashT->p_records[hash_code].lock); LM_DBG("rec did= %.*s\n", id->len, id->s); *rec_id= id; return 0; }
int get_record_id(ua_pres_t* dialog, str** rec_id) { unsigned int hash_code; ua_pres_t* rec; str* id; str* s1; if(dialog->to_uri.s) s1 = &dialog->to_uri; else s1 = dialog->pres_uri; *rec_id= NULL; LM_DBG("to_uri= %.*s, watcher_uri= %.*s\n", s1->len, s1->s, (dialog->watcher_uri?dialog->watcher_uri->len:0), (dialog->watcher_uri?dialog->watcher_uri->s:0)); hash_code= core_hash(s1, dialog->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); LM_DBG("hash_code = %d\n", hash_code); rec= get_dialog(dialog, hash_code); if(rec== NULL) { LM_DBG("Record not found\n"); lock_release(&HashT->p_records[hash_code].lock); return 0; } id= (str*)pkg_malloc(sizeof(str)); if(id== NULL) { LM_ERR("No more memory\n"); lock_release(&HashT->p_records[hash_code].lock); return -1; } id->s= (char*)pkg_malloc(rec->id.len); if(id->s== NULL) { LM_ERR("No more memory\n"); 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; lock_release(&HashT->p_records[hash_code].lock); LM_DBG("rec did= %.*s\n", id->len, id->s); *rec_id= id; return 0; }
DefaultDialog_t * make_default_dialog (const gchar *title) { DefaultDialog_t *data = g_new0 (DefaultDialog_t, 1); data->ok_cb = NULL; data->apply_cb = NULL; data->cancel_cb = NULL; data->dialog = gimp_dialog_new (title, PLUG_IN_ROLE, get_dialog(), 0, gimp_standard_help_func, PLUG_IN_PROC, NULL); data->apply = gtk_dialog_add_button (GTK_DIALOG (data->dialog), _("_Apply"), GTK_RESPONSE_APPLY); data->cancel = gtk_dialog_add_button (GTK_DIALOG (data->dialog), _("_Cancel"), GTK_RESPONSE_CANCEL); data->ok = gtk_dialog_add_button (GTK_DIALOG (data->dialog), _("_OK"), GTK_RESPONSE_OK); gimp_dialog_set_alternative_button_order (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_RESPONSE_APPLY, GTK_RESPONSE_CANCEL, -1); g_signal_connect (data->dialog, "response", G_CALLBACK (dialog_response), data); g_signal_connect (data->dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &data->dialog); data->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (data->vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), data->vbox, TRUE, TRUE, 0); gtk_widget_show (data->vbox); return data; }
/** * \brief Changes the id of a dialog. * \param old_dialog_id Old id of the dialog. * \param new_dialog_id New id to set. * \return \c true in case of success. * In case of failure, the old dialog is unchanged. */ bool DialogResources::set_dialog_id( const std::string& old_dialog_id, const std::string& new_dialog_id) { if (!has_dialog(old_dialog_id)) { // No dialog was found with the old id. return false; } if (has_dialog(new_dialog_id)) { // The new id is already used. return false; } DialogData dialog = get_dialog(old_dialog_id); remove_dialog(old_dialog_id); add_dialog(new_dialog_id, dialog); return true; }
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) { update_dialog_puadb(dialog, lexpire, contact); } else { lock_get(&HashT->p_records[hash_code].lock); 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); lock_release(&HashT->p_records[hash_code].lock); } }
int is_dialog(ua_pres_t* dialog) { int ret_code= 0; unsigned int hash_code; str* s1; if(dialog->to_uri.s) s1 = &dialog->to_uri; else s1 = dialog->pres_uri; hash_code= core_hash(s1, dialog->watcher_uri, HASH_SIZE); lock_get(&HashT->p_records[hash_code].lock); if(get_dialog(dialog, hash_code)== NULL) ret_code= -1; else ret_code= 0; lock_release(&HashT->p_records[hash_code].lock); return ret_code; }
int update_contact(struct sip_msg* msg, char* str1, char* str2) { ua_pres_t* p, hentity; str contact; struct to_body *pto= NULL, *pfrom = NULL; unsigned int hash_code; 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) { LM_ERR("cannot parse callid header\n"); return -1; } 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 ) { LM_ERR("cannot parse From header\n"); return -1; } } pfrom = (struct to_body*)msg->from->parsed; 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) { LM_ERR("cannot parse TO header\n"); return -1; } pto = get_to(msg); if (pto == NULL || pto->error != PARSE_OK) { LM_ERR("failed to parse TO header\n"); return -1; } if( pto->tag_value.s ==NULL || pto->tag_value.len == 0) { LM_ERR("no to tag value present\n"); return -1; } memset( &hentity, 0, sizeof(ua_pres_t)); /* as we have a NOTIFY, we are looking for any SUBSCRIBER-like entity in the hash (we do not know the exact type) - bogdan */ hentity.flag = BLA_SUBSCRIBE | XMPP_SUBSCRIBE | XMPP_INITIAL_SUBS | MI_SUBSCRIBE | RLS_SUBSCRIBE; hentity.watcher_uri= &pto->uri; hentity.to_uri= pfrom->uri; hentity.call_id= msg->callid->body; hentity.to_tag= pto->tag_value; hentity.from_tag= pfrom->tag_value; hash_code= core_hash(&hentity.to_uri,hentity.watcher_uri, HASH_SIZE); /* extract the contact */ if(msg->contact== NULL || msg->contact->body.s== NULL) { LM_ERR("no contact header found in 200 OK reply"); return -1; } contact= msg->contact->body; lock_get(&HashT->p_records[hash_code].lock); 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"); return -1; } shm_free(p->remote_contact.s); 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); if(p->remote_contact.s== NULL) { LM_ERR("no more shared memory\n"); lock_release(&HashT->p_records[hash_code].lock); return -1; } memcpy(p->remote_contact.s, contact.s, contact.len); p->remote_contact.len= contact.len; } lock_release(&HashT->p_records[hash_code].lock); return 1; }
int ki_pua_update_contact(struct sip_msg* msg) { 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 ) { LM_ERR("when parsing headers\n"); return -1; } /* find the record */ 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) { LM_ERR("cannot find 'from' header!\n"); return -1; } 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; 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) { 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) { LM_DBG("'To' header NOT parsed\n"); goto error; } pto = &TO; } 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; /* extract the contact */ 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; if (dbmode==PUA_DB_ONLY) { update_contact_puadb(&hentity, &contact ); free_to_params(&TO); return(1); } 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) { lock_release(&HashT->p_records[hash_code].lock); LM_ERR("no record for the dialog found in hash table\n"); goto error; } shm_free(p->remote_contact.s); 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) { LM_ERR("no more shared memory\n"); 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; } lock_release(&HashT->p_records[hash_code].lock); free_to_params(&TO); return 1; error: free_to_params(&TO); return -1; }