/** * 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; }
/** * Decode a subscriber from a binary data structure * @param x - binary data to decode from * @returns the r_subscriber* where the data has been decoded */ r_subscriber* bin_decode_r_subscriber(bin_data *x) { r_subscriber *s=0; int len; str st; len = sizeof(r_subscriber); s = (r_subscriber*) shm_malloc(len); if (!s) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len); goto error; } memset(s,0,len); if (!bin_decode_str(x,&st)||!str_shm_dup(&(s->subscriber),&st)) goto error; if (!bin_decode_char(x,&(s->event))) goto error; if (!bin_decode_time_t(x,&(s->expires))) goto error; if (!bin_decode_dlg_t(x,&(s->dialog))) goto error; if (!bin_decode_int(x,&(s->version))) goto error; return s; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (s) { if (s->subscriber.s) shm_free(s->subscriber.s); if (s->dialog) tmb.free_dlg(s->dialog); shm_free(s); } return 0; }
/** * Decode a contact from a binary data structure * @param x - binary data to decode from * @returns the r_contact* where the data has been decoded */ r_contact* bin_decode_r_contact(bin_data *x) { r_contact *c=0; int len; str s; len = sizeof(r_contact); c = (r_contact*) shm_malloc(len); if (!c) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len); goto error; } memset(c,0,len); if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->uri),&s)) goto error; if (!bin_decode_time_t(x,&c->expires)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->ua),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->path),&s)) goto error; return c; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (c) { if (c->uri.s) shm_free(c->uri.s); if (c->ua.s) shm_free(c->ua.s); if (c->path.s) shm_free(c->path.s); shm_free(c); } return 0; }
/** * Decode a r_subscription from a binary data structure * @param x - binary data to decode from * @returns the r_subscription* where the data has been decoded */ r_subscription* bin_decode_r_subscription(bin_data *x) { r_subscription *s=0; int len; str st; char c; len = sizeof(r_subscription); s = (r_subscription*) shm_malloc(len); if (!s) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_subscription: Error allocating %d bytes.\n",len); goto error; } memset(s,0,len); if (!bin_decode_str(x,&st)||!str_shm_dup(&(s->req_uri),&st)) goto error; if (!bin_decode_int(x,&s->duration)) goto error; if (!bin_decode_time_t(x,&s->expires)) goto error; if (!bin_decode_char(x,&c)) goto error; s->attempts_left = c; if (!bin_decode_dlg_t(x,&(s->dialog))) goto error; s->hash = get_subscription_hash(s->req_uri); return s; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_subscription: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (s) { if (s->req_uri.s) shm_free(s->req_uri.s); if (s->dialog) tmb.free_dlg(s->dialog); shm_free(s); } return 0; }
/** * Decode an authentication userdata from a binary data structure * @param x - binary data to decode from * @returns the auth_userdata* where the data has been decoded */ auth_userdata* bin_decode_auth_userdata(bin_data *x) { auth_userdata *u=0; auth_vector *v=0,*vn=0; int i,len; unsigned short k; str s; len = sizeof(auth_userdata); u = (auth_userdata*) shm_malloc(len); if (!u) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_auth_userdata: Error allocating %d bytes.\n",len); goto error; } memset(u,0,len); if (!bin_decode_str(x,&s)||!str_shm_dup(&(u->private_identity),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(u->public_identity),&s)) goto error; u->hash = get_hash_auth(u->private_identity,u->public_identity); if (!bin_decode_time_t(x, &(u->expires))) goto error; if (!bin_decode_ushort(x, &k)) goto error; for(i=0;i<k;i++){ v = bin_decode_auth_vector(x); if (!v) goto error; v->prev = u->tail; v->next = 0; if (!u->head) u->head = v; if (u->tail) u->tail->next = v; u->tail = v; } return u; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_auth_userdata: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (u) { if (u->private_identity.s) shm_free(u->private_identity.s); if (u->public_identity.s) shm_free(u->public_identity.s); while(u->head){ v = u->head; vn = v->next; if (v->authenticate.s) shm_free(v->authenticate.s); if (v->authorization.s) shm_free(v->authorization.s); if (v->ck.s) shm_free(v->ck.s); if (v->ik.s) shm_free(v->ik.s); shm_free(v); u->head = v; } shm_free(u); } return 0; }
/** * Decode a contact from a binary data structure * @param x - binary data to decode from * @returns the r_contact* where the data has been decoded */ r_contact* bin_decode_r_contact(bin_data *x) { r_contact *c=0; unsigned short cpn=0; r_contact_param *cp; int len; str s,name,value; len = sizeof(r_contact); c = (r_contact*) shm_malloc(len); if (!c) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len); goto error; } memset(c,0,len); if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->uri),&s)) goto error; if (!bin_decode_time_t(x,&c->expires)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->ua),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->path),&s)) goto error; if (!bin_decode_ushort(x,&(cpn))) goto error; while(cpn){ if (!bin_decode_str(x,&name)) goto error; if (!bin_decode_str(x,&value)) goto error; if (!add_r_contact_param(c,name,value)) goto error; cpn--; } return c; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (c) { if (c->uri.s) shm_free(c->uri.s); if (c->ua.s) shm_free(c->ua.s); if (c->path.s) shm_free(c->path.s); while(c->parameters){ cp = c->parameters->next; free_r_contact_param(cp); c->parameters = cp; } shm_free(c); } return 0; }
/** * Decode an authentication vector from a binary data structure * @param x - binary data to decode from * @returns the auth_vector* where the data has been decoded */ auth_vector* bin_decode_auth_vector(bin_data *x) { auth_vector *v=0; int len; char ch; str s; len = sizeof(auth_vector); v = (auth_vector*) shm_malloc(len); if (!v) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_auth_vector: Error allocating %d bytes.\n",len); goto error; } memset(v,0,len); if (!bin_decode_int(x,&(v->item_number))) goto error; if (!bin_decode_uchar(x,&(v->type))) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(v->authenticate),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(v->authorization),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(v->ck),&s)) goto error; if (!bin_decode_str(x,&s)||!str_shm_dup(&(v->ik),&s)) goto error; if (!bin_decode_time_t(x, &(v->expires))) goto error; if (!bin_decode_char(x, &ch)) goto error; v->status=ch; return v; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_auth_vector: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (v) { if (v->authenticate.s) shm_free(v->authenticate.s); if (v->authorization.s) shm_free(v->authorization.s); if (v->ck.s) shm_free(v->ck.s); if (v->ik.s) shm_free(v->ik.s); shm_free(v); } return 0; }
/** * Decode a r_contact from a binary data structure * @param x - binary data to decode from * @returns the r_contact* where the data has been decoded */ r_contact* bin_decode_r_contact(bin_data *x) { r_contact *c=0; r_public *p=0,*pn=0; int len,i; char k; unsigned short us; str st; len = sizeof(r_contact); c = (r_contact*) shm_malloc(len); if (!c) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len); goto error; } memset(c,0,len); if (!bin_decode_str(x,&st)||!str_shm_dup(&(c->host),&st)) goto error; if (!bin_decode_ushort(x,&c->port)) goto error; if (!bin_decode_char(x,&c->transport)) goto error; c->hash = get_contact_hash(c->host,c->port,c->transport,r_hash_size); if (!bin_decode_r_security(x,&(c->security_temp))) goto error; if (!bin_decode_r_security(x,&(c->security))) goto error; if (!bin_decode_str(x,&st)||!str_shm_dup(&(c->uri),&st)) goto error; if (!bin_decode_char(x,&k)) goto error; c->reg_state = k; if (!bin_decode_time_t(x,&c->expires)) goto error; if (!bin_decode_ushort(x, &c->service_route_cnt)) goto error; len = sizeof(str)*c->service_route_cnt; c->service_route = (str*) shm_malloc(len); if (!c->service_route) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len); goto error; } memset(c->service_route,0,len); for(i=0;i<c->service_route_cnt;i++) if (!bin_decode_str(x,&st)||!str_shm_dup(c->service_route+i,&st)) goto error; if (!bin_decode_pinhole(x,&(c->pinhole ))) goto error; if (!bin_decode_char(x,&k)) goto error; c->sos_flag = k; if (!bin_decode_str(x,&st)||!str_shm_dup(&(c->pcc_session_id),&st)) goto error; if (!bin_decode_ushort(x,&us)) goto error; for(i=0;i<us;i++){ p = bin_decode_r_public(x); if (!p) goto error; p->prev = c->tail; p->next = 0; if (c->tail) c->tail->next = p; c->tail = p; if (!c->head) c->head = p; } return c; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error while decoding (at %d (%04x)).\n",x->max,x->max); if (c) { if (c->host.s) shm_free(c->host.s); if (c->security_temp) free_r_security(c->security_temp); if (c->security) free_r_security(c->security); if (c->uri.s) shm_free(c->uri.s); if (c->pinhole) shm_free(c->pinhole); while(c->head){ p = c->head; pn = p->next; free_r_public(p); c->head = pn; } shm_free(c); } return 0; }
/** * Decode a dialog from a binary data structure * @param x - binary data to decode from * @returns the p_dialog* where the data has been decoded */ p_dialog* bin_decode_p_dialog(bin_data *x) { p_dialog *d=0; int len,i; str s; char c; unsigned char uc; len = sizeof(p_dialog); d = (p_dialog*) shm_malloc(len); if (!d) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_p_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_uchar(x, &uc)) goto error; d->direction = uc; if (!bin_decode_str(x,&s)||!str_shm_dup(&(d->host),&s)) goto error; if (!bin_decode_ushort(x, &d->port)) goto error; if (!bin_decode_uchar(x, &uc)) goto error; d->transport = uc; if (!bin_decode_ushort(x, &d->routes_cnt)) goto error; len = sizeof(str)*d->routes_cnt; d->routes = (str*) shm_malloc(len); if (!d) { LOG(L_ERR,"ERR:"M_NAME":bin_decode_p_dialog: Error allocating %d bytes.\n",len); goto error; } memset(d->routes,0,len); for(i=0;i<d->routes_cnt;i++) if (!bin_decode_str(x,&s)||!str_shm_dup(d->routes+i,&s)) goto error; if (!bin_decode_char(x, &c)) goto error; d->method = c; 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, &c)) goto error; d->state = c; 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_str(x,&s)||!str_shm_dup(&(d->pcc_session_id),&s)) 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_p_dialog_hash(d->call_id); return d; error: LOG(L_ERR,"ERR:"M_NAME":bin_decode_p_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->host.s) shm_free(d->host.s); if (d->routes_cnt){ for(i=0;i<d->routes_cnt;i++) if (d->routes[i].s) shm_free(d->routes[i].s); shm_free(d->routes); } 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; }