/** * Creates a new s_dialog structure. * Does not add the structure to the list * @param call_id - call_id of the dialog * @param aor - aor of the user * @param dir - the direction * @returns the new s_dialog* or NULL s_dialog */ s_dialog* new_s_dialog(str call_id,str aor, enum s_dialog_direction dir) { s_dialog *d; if (!s_dialog_count_increment()) return 0; d = shm_malloc(sizeof(s_dialog)); if (!d) { LOG(L_ERR,"ERR:"M_NAME":new_s_dialog(): Unable to alloc %d bytes\n", sizeof(s_dialog)); goto error; } memset(d,0,sizeof(s_dialog)); d->hash = get_s_dialog_hash(call_id); STR_SHM_DUP(d->call_id,call_id,"shm"); STR_SHM_DUP(d->aor,aor,"shm"); d->direction = dir; d->is_releasing = 0; return d; error: out_of_memory: if (d){ shm_free(d); } s_dialog_count_decrement(); return 0; }
/** * Decode a dialog userdata from a binary data structure * @param x - binary data to decode from * @returns the s_dialog* where the data has been decoded */ s_dialog* bin_decode_s_dialog(bin_data *x) { s_dialog *d=0; int len; str s; char ch; len = sizeof(s_dialog); d = (s_dialog*) shm_malloc(len); if (!d) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_s_dialog: Error allocating %d bytes.\n",len); goto error; } memset(d,0,len); if (!bin_decode_str(x,&s)||!str_shm_dup(&(d->call_id),&s)) goto error; if (!bin_decode_char(x, &ch)) goto error; d->direction = ch; if (!bin_decode_str(x,&s)||!str_shm_dup(&(d->aor),&s)) goto error; if (!bin_decode_char(x, &ch)) goto error; d->method = ch; if (!bin_decode_str(x,&s)||!str_shm_dup(&(d->method_str),&s)) goto error; if (!bin_decode_int(x, &d->first_cseq)) goto error; if (!bin_decode_int(x, &d->last_cseq)) goto error; if (!bin_decode_char(x, &ch)) goto error; d->state = ch; if (!bin_decode_time_t(x, &d->expires)) goto error; if (!bin_decode_time_t(x, &d->lr_session_expires)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(d->refresher),&s)) goto error; if (!bin_decode_uchar(x,&d->uac_supp_timer)) goto error; if (!bin_decode_uchar(x, &d->is_releasing)) goto error; if (!bin_decode_dlg_t(x,&(d->dialog_c))) goto error; if (!bin_decode_dlg_t(x,&(d->dialog_s))) goto error; d->hash = get_s_dialog_hash(d->call_id); return d; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_s_dialog: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (d) { if (d->call_id.s) shm_free(d->call_id.s); if (d->aor.s) shm_free(d->aor.s); if (d->method_str.s) shm_free(d->method_str.s); if (d->refresher.s) shm_free(d->refresher.s); shm_free(d); } return 0; }
/** * Finds and returns a dialog from the hash table. * \note the table should be locked already for the call_id in the parameter * @param call_id - call_id of the dialog * @param dir - the direction * @returns the s_dialog* or NULL if not found */ s_dialog* get_s_dialog_dir_nolock(str call_id,enum s_dialog_direction dir) { s_dialog *d=0; unsigned int hash = get_s_dialog_hash(call_id); d = s_dialogs[hash].head; while(d){ if (d->direction == dir && d->call_id.len == call_id.len && strncasecmp(d->call_id.s,call_id.s,call_id.len)==0) { return d; } d = d->next; } return 0; }
/** * Finds and returns a dialog from the hash table. * \note Locks the hash slot if ok! Call d_unlock(s_dialog->hash) when you are finished) * @param call_id - call_id of the dialog * @param aor - aor of the user * @returns the s_dialog* or NULL if not found */ s_dialog* get_s_dialog(str call_id,str aor) { s_dialog *d=0; unsigned int hash = get_s_dialog_hash(call_id); d_lock(hash); d = s_dialogs[hash].head; while(d){ if (d->aor.len == aor.len && d->call_id.len == call_id.len && strncasecmp(d->aor.s,aor.s,aor.len)==0 && strncasecmp(d->call_id.s,call_id.s,call_id.len)==0) { return d; } d = d->next; } d_unlock(hash); return 0; }