/** * Encode a r_public into a binary form * @param x - binary data to append to * @param p - the r_public to encode * @returns 1 on succcess or 0 on error */ int bin_encode_r_public(bin_data *x,r_public *p) { unsigned short k; char ch; r_contact *c=0; r_subscriber *s=0; if (!bin_encode_str(x,&(p->aor))) goto error; if (!bin_encode_str(x,&(p->early_ims_ip))) goto error; ch = p->reg_state; if (!bin_encode_char(x,ch)) goto error; if (!bin_encode_ims_subscription(x,p->s)) goto error; k=0; for(c=p->head;c;c=c->next) k++; if (!bin_encode_ushort(x,k)) goto error; for(c=p->head;c;c=c->next) if (!bin_encode_r_contact(x,c)) goto error; k=0; for(s=p->shead;s;s=s->next) k++; if (!bin_encode_ushort(x,k)) goto error; for(s=p->shead;s;s=s->next) if (!bin_encode_r_subscriber(x,s)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_r_public: Error while encoding.\n"); return 0; }
/** * Encode and append a Service Profile * @param x - binary data to append to * @param sp - the service profile to encode * @returns 1 on succcess or 0 on error */ static int bin_encode_service_profile(bin_data *x,ims_service_profile *sp) { int i; //public identity if (!bin_encode_ushort(x,sp->public_identities_cnt)) return 0; for(i=0;i<sp->public_identities_cnt;i++) if (!bin_encode_public_identity(x,sp->public_identities+i)) goto error; //filter criteria if (!bin_encode_ushort(x,sp->filter_criteria_cnt)) return 0; for(i=0;i<sp->filter_criteria_cnt;i++) if (!bin_encode_filter_criteria(x,sp->filter_criteria+i)) goto error; //cn service_auth if (sp->cn_service_auth) i = sp->cn_service_auth->subscribed_media_profile_id; else i = 0xFFFFFFFF; if (!bin_encode_int(x,i)) goto error; //shared_ifc if (!bin_encode_ushort(x,sp->shared_ifc_set_cnt)) return 0; for(i=0;i<sp->shared_ifc_set_cnt;i++) if (!bin_encode_int(x,sp->shared_ifc_set[i])) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_service_profile: Error while encoding.\n"); return 0; }
/** * Encode an ipsec into a binary form * @param x - binary data to append to * @param ipsec - the r_ipsec to encode * @returns 1 on succcess or 0 on error */ int bin_encode_ipsec(bin_data *x,r_ipsec *ipsec) { if (!ipsec){ if (!bin_encode_char(x,0)) goto error; return 1; } if (!bin_encode_char(x,1)) goto error; if (!bin_encode_uint(x,ipsec->spi_uc)) goto error; if (!bin_encode_uint(x,ipsec->spi_us)) goto error; if (!bin_encode_uint(x,ipsec->spi_pc)) goto error; if (!bin_encode_uint(x,ipsec->spi_ps)) goto error; if (!bin_encode_ushort(x,ipsec->port_uc)) goto error; if (!bin_encode_ushort(x,ipsec->port_us)) goto error; if (!bin_encode_str(x,&(ipsec->ealg))) goto error; if (!bin_encode_str(x,&(ipsec->r_ealg))) goto error; if (!bin_encode_str(x,&(ipsec->ck))) goto error; if (!bin_encode_str(x,&(ipsec->alg))) goto error; if (!bin_encode_str(x,&(ipsec->r_alg))) goto error; if (!bin_encode_str(x,&(ipsec->ik))) goto error; if (!bin_encode_str(x,&(ipsec->prot))) goto error; if (!bin_encode_str(x,&(ipsec->mod))) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_ipsec: Error while encoding.\n"); return 0; }
/** * Encode and Append a Filter Criteria * @param x - binary data to append to * @param spt - the service point trigger to encode * @returns 1 on succcess or 0 on error */ static int bin_encode_filter_criteria(bin_data *x, ims_filter_criteria *fc) { int i; char ppindicator; //priority if (!bin_encode_int(x,fc->priority)) goto error; //profile part indicator if (fc->profile_part_indicator) ppindicator = (*fc->profile_part_indicator)+1; else ppindicator = 0; if (!bin_encode_char(x,ppindicator)) goto error; // trigger point if (fc->trigger_point) { if (!bin_encode_char(x,fc->trigger_point->condition_type_cnf)) goto error; if (!bin_encode_ushort(x,fc->trigger_point->spt_cnt)) goto error; for(i=0;i<fc->trigger_point->spt_cnt;i++) if (!bin_encode_spt(x,fc->trigger_point->spt+i)) goto error; } else { if (!bin_encode_char(x,100)) goto error; } //app server if (!bin_encode_str(x,&(fc->application_server.server_name))) goto error; if (!bin_encode_char(x,fc->application_server.default_handling)) goto error; if (!bin_encode_str(x,&(fc->application_server.service_info))) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_filter_criteria: Error while encoding.\n"); return 0; }
/** * Encode an dialog into a binary form * @param x - binary data to append to * @param u - the dialog to encode * @returns 1 on succcess or 0 on error */ int bin_encode_p_dialog(bin_data *x,p_dialog *d) { int i; char c; if (!bin_encode_str(x,&(d->call_id))) goto error; c = d->direction; if (!bin_encode_uchar(x,c)) goto error; if (!bin_encode_str(x,&(d->host))) goto error; if (!bin_encode_ushort(x,d->port)) goto error; c = d->transport; if (!bin_encode_uchar(x,c)) goto error; if (!bin_encode_ushort(x,d->routes_cnt)) goto error; for(i=0;i<d->routes_cnt;i++) if (!bin_encode_str(x,d->routes+i)) goto error; c = d->method; if (!bin_encode_uchar(x,c)) goto error; if (!bin_encode_str(x,&(d->method_str))) goto error; if (!bin_encode_int(x,d->first_cseq)) goto error; if (!bin_encode_int(x,d->last_cseq)) goto error; c = d->state; if (!bin_encode_uchar(x,c)) goto error; if (!bin_encode_time_t(x,d->expires)) goto error; if (!bin_encode_time_t(x,d->lr_session_expires)) goto error; if (!bin_encode_str(x,&(d->refresher))) goto error; if (!bin_encode_uchar(x,d->uac_supp_timer)) goto error; if (!bin_encode_uchar(x,d->is_releasing)) goto error; if (!bin_encode_str(x,&(d->pcc_session_id))) goto error; if (!bin_encode_dlg_t(x,d->dialog_c)) goto error; if (!bin_encode_dlg_t(x,d->dialog_s)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_p_dialog: Error while encoding.\n"); return 0; }
/** * Encode a r_contact into a binary form * @param x - binary data to append to * @param p - the r_contact to encode * @returns 1 on succcess or 0 on error */ int bin_encode_r_contact(bin_data *x,r_contact *c) { int i; char k; unsigned short us; r_public *p=0; if (!bin_encode_str(x,&(c->host))) goto error; if (!bin_encode_ushort(x,c->port)) goto error; if (!bin_encode_char(x,c->transport)) goto error; if (!bin_encode_r_security(x,c->security_temp)) goto error; if (!bin_encode_r_security(x,c->security)) goto error; if (!bin_encode_str(x,&(c->uri))) goto error; k = c->reg_state; if (!bin_encode_char(x,k)) goto error; if (!bin_encode_time_t(x,c->expires)) goto error; if (!bin_encode_ushort(x,c->service_route_cnt)) goto error; for(i=0;i<c->service_route_cnt;i++) if (!bin_encode_str(x,c->service_route+i)) goto error; if (!bin_encode_pinhole(x,c->pinhole)) goto error; k = c->sos_flag; if (!bin_encode_char(x,k)) goto error; if (!bin_encode_str(x,&(c->pcc_session_id))) goto error; us=0; for(p=c->head;p;p=p->next) us++; if (!bin_encode_ushort(x,us)) goto error; for(p=c->head;p;p=p->next) if (!bin_encode_r_public(x,p)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_r_contact: Error while encoding.\n"); return 0; }
/** * Encode the entire user profile and append it to the binary data * @param x - binary data to append to * @param s - the ims subscription to encode * @returns 1 on succcess or 0 on error */ int bin_encode_ims_subscription(bin_data *x, ims_subscription *s) { int i; if (!bin_encode_str(x,&(s->private_identity))) goto error; if (!bin_encode_ushort(x,s->service_profiles_cnt)) goto error; for(i=0;i<s->service_profiles_cnt;i++) if (!bin_encode_service_profile(x,s->service_profiles+i)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_ims_subscription: Error while encoding.\n"); return 0; }
/** * Encode an tls into a binary form * @param x - binary data to append to * @param tls - the r_tls to encode * @returns 1 on succcess or 0 on error */ int bin_encode_tls(bin_data *x,r_tls *tls) { if (!tls){ if (!bin_encode_char(x,0)) goto error; return 1; } if (!bin_encode_char(x,1)) goto error; if (!bin_encode_ushort(x,tls->port_tls)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_tls: Error while encoding.\n"); return 0; }
/** * Encode an authentication userdata into a binary form * @param x - binary data to append to * @param u - the authentication usedata to encode * @returns 1 on succcess or 0 on error */ int bin_encode_auth_userdata(bin_data *x,auth_userdata *u) { unsigned short k=0; auth_vector *v; if (!bin_encode_str(x,&(u->private_identity))) goto error; if (!bin_encode_str(x,&(u->public_identity))) goto error; if (!bin_encode_time_t(x,u->expires)) goto error; for(v=u->head;v;v=v->next) k++; if (!bin_encode_ushort(x,k)) goto error; for(v=u->head;v;v=v->next) if (!bin_encode_auth_vector(x,v)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_auth_vector: Error while encoding.\n"); return 0; }
/** * Encode a pinhole into a binary form * @param x - binary data to append to * @param u - the dialog to encode * @returns 1 on succcess or 0 on error */ int bin_encode_pinhole(bin_data *x,r_nat_dest *pinhole) { if (!pinhole){ if (!bin_encode_char(x,0)) goto error; return 1; } if (!bin_encode_char(x,1)) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.af)) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.len)) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.u.addr32[0])) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.u.addr32[1])) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.u.addr32[2])) goto error; if (!bin_encode_uint(x,pinhole->nat_addr.u.addr32[3])) goto error; if (!bin_encode_ushort(x,pinhole->nat_port)) goto error; return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_pinhole: Error while encoding.\n"); return 0; }
/** * Encode a r_public into a binary form * @param x - binary data to append to * @param c - the r_contact to encode * @returns 1 on succcess or 0 on error */ int bin_encode_r_contact(bin_data *x,r_contact *c) { unsigned short cpn=0; r_contact_param *cp; if (!bin_encode_str(x,&(c->uri))) goto error; if (!bin_encode_time_t(x,c->expires)) goto error; if (!bin_encode_str(x,&(c->ua))) goto error; if (!bin_encode_str(x,&(c->path))) goto error; for(cp=c->parameters;cp;cp=cp->next) cpn++; if (!bin_encode_ushort(x,cpn)) goto error; for(cp=c->parameters;cp;cp=cp->next){ if (!bin_encode_str(x,&(cp->name))) goto error; if (!bin_encode_str(x,&(cp->value))) goto error; } return 1; error: LOG(L_ERR,"ERR:"M_NAME":bin_encode_r_contact: Error while encoding.\n"); return 0; }