bin_scscf.c File Reference


Detailed Description

Binary codec operations for the S-CSCF.

Author:
Dragos Vingarzan vingarzan -at- fokus dot fraunhofer dot de

Definition in file bin_scscf.c.

#include "bin_scscf.h"

Go to the source code of this file.

Functions

static int str_shm_dup (str *dest, str *src)
static int bin_encode_public_identity (bin_data *x, ims_public_identity *pi)
 Encode and append a Public Indentity.
static int bin_decode_public_identity (bin_data *x, ims_public_identity *pi)
 Decode a binary string from a binary data structure.
static int bin_encode_spt (bin_data *x, ims_spt *spt)
 Encode and append a SPT.
static int bin_decode_spt (bin_data *x, ims_spt *spt)
 Decode an SPT.
static int bin_encode_filter_criteria (bin_data *x, ims_filter_criteria *fc)
 Encode and Append a Filter Criteria.
static int bin_decode_filter_criteria (bin_data *x, ims_filter_criteria *fc)
 Decode a Filter Criteria.
static int bin_encode_service_profile (bin_data *x, ims_service_profile *sp)
 Encode and append a Service Profile.
static int bin_decode_service_profile (bin_data *x, ims_service_profile *sp)
 Decode a service profile.
int bin_encode_ims_subscription (bin_data *x, ims_subscription *s)
 Encode the entire user profile and append it to the binary data.
ims_subscriptionbin_decode_ims_subscription (bin_data *x)
 Decode a binary string from a binary data structure.
int bin_encode_r_contact (bin_data *x, r_contact *c)
 Encode a r_contact into a binary form.
r_contactbin_decode_r_contact (bin_data *x)
 Decode a r_contact from a binary data structure.
int bin_encode_r_subscriber (bin_data *x, r_subscriber *s)
 Encode a r_subscriber into a binary form.
r_subscriberbin_decode_r_subscriber (bin_data *x)
 Decode a subscriber from a binary data structure.
int bin_encode_r_public (bin_data *x, r_public *p)
 Encode a r_public into a binary form.
r_publicbin_decode_r_public (bin_data *x)
 Decode a r_public from a binary data structure.
int bin_encode_auth_vector (bin_data *x, auth_vector *v)
 Encode an authentication vector into a binary form.
auth_vectorbin_decode_auth_vector (bin_data *x)
 Decode an authentication vector from a binary data structure.
int bin_encode_auth_userdata (bin_data *x, auth_userdata *u)
 Encode an authentication userdata into a binary form.
auth_userdatabin_decode_auth_userdata (bin_data *x)
 Decode an authentication userdata from a binary data structure.
int bin_encode_s_dialog (bin_data *x, s_dialog *d)
 Encode a dialog into a binary form.
s_dialogbin_decode_s_dialog (bin_data *x)
 Decode a dialog userdata from a binary data structure.

Variables

tm_binds tmb
 Structure with pointers to tm funcs.
int r_hash_size
 Size of S-CSCF registrar hash table.


Function Documentation

static int str_shm_dup ( str *  dest,
str *  src 
) [inline, static]

Definition at line 62 of file bin_scscf.c.

References M_NAME.

00063 {
00064     dest->s = shm_malloc(src->len);
00065     if (!dest->s){
00066         LOG(L_ERR,"ERR:"M_NAME":str_shm_dup: Error allocating %d bytes\n",src->len);
00067         dest->len=0;
00068         return 0;
00069     }
00070     dest->len = src->len;
00071     memcpy(dest->s,src->s,src->len);
00072     return 1;
00073 }

static int bin_encode_public_identity ( bin_data x,
ims_public_identity pi 
) [static]

Encode and append a Public Indentity.

Parameters:
x - binary data to append to
pi - the public identity to encode
Returns:
1 on succcess or 0 on error

Definition at line 81 of file bin_scscf.c.

References ims_public_identity::barring, bin_encode_char(), bin_encode_str(), M_NAME, and ims_public_identity::public_identity.

Referenced by bin_encode_service_profile().

00082 {
00083     if (!bin_encode_char(x,pi->barring)) goto error;
00084     if (!bin_encode_str(x,&(pi->public_identity))) goto error;  
00085     return 1;
00086 error:
00087     LOG(L_ERR,"ERR:"M_NAME":bin_encode_public_identity: Error while encoding.\n");
00088     return 0;       
00089 }

static int bin_decode_public_identity ( bin_data x,
ims_public_identity pi 
) [static]

Decode a binary string from a binary data structure.

Parameters:
x - binary data to decode from
pi - the public identity to decode into
Returns:
1 on succcess or 0 on error

Definition at line 97 of file bin_scscf.c.

References ims_public_identity::barring, bin_decode_char(), bin_decode_str(), M_NAME, _bin_data::max, ims_public_identity::public_identity, and str_shm_dup().

Referenced by bin_decode_service_profile().

00098 {
00099     str s;
00100     if (!bin_decode_char(x, &(pi->barring))) goto error;
00101     if (!bin_decode_str(x,&s)||!str_shm_dup(&(pi->public_identity),&s)) goto error;
00102     
00103     return 1;
00104 error:
00105     LOG(L_ERR,"ERR:"M_NAME":bin_decode_public_identity: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00106     if (pi) {
00107         if (pi->public_identity.s) shm_free(pi->public_identity.s);
00108     }
00109     return 0;
00110 }

static int bin_encode_spt ( bin_data x,
ims_spt spt 
) [static]

Encode and append a SPT.

Parameters:
x - binary data to append to
spt - the service point trigger to encode
Returns:
1 on succcess or 0 on error

Definition at line 123 of file bin_scscf.c.

References bin_encode_char(), bin_encode_int(), bin_encode_short(), bin_encode_str(), bin_encode_uchar(), _ims_spt::condition_negated, _ims_session_desc::content, _ims_sip_header::content, _ims_spt::group, _ims_sip_header::header, _ims_session_desc::line, M_NAME, _ims_spt::method, _ims_spt::registration_type, _ims_spt::request_uri, _ims_spt::session_case, _ims_spt::session_desc, _ims_spt::sip_header, _ims_sip_header::type, and _ims_spt::type.

Referenced by bin_encode_filter_criteria().

00124 {
00125     unsigned char c = spt->condition_negated<<7 | spt->registration_type<<4 | spt->type;
00126     // cond negated, reg type, spt type
00127     if (!bin_encode_uchar(x,c)) goto error;
00128 
00129     //group
00130     if (!bin_encode_int(x,spt->group)) goto error;
00131 
00132     //spt
00133     switch(spt->type){
00134         case 1:
00135             if (!bin_encode_str(x,&(spt->request_uri))) goto error; 
00136             break;
00137         case 2:
00138             if (!bin_encode_str(x,&(spt->method))) goto error; 
00139             break;
00140         case 3:
00141             if (!bin_encode_short(x,spt->sip_header.type)) goto error;
00142             if (!bin_encode_str(x,&(spt->sip_header.header))) goto error; 
00143             if (!bin_encode_str(x,&(spt->sip_header.content))) goto error; 
00144             break;
00145         case 4:
00146             if (!bin_encode_char(x,spt->session_case)) goto error;
00147             break;
00148         case 5:
00149             if (!bin_encode_str(x,&(spt->session_desc.line))) goto error; 
00150             if (!bin_encode_str(x,&(spt->session_desc.content))) goto error; 
00151             break;
00152     }
00153     return 1;
00154 error:
00155     LOG(L_ERR,"ERR:"M_NAME":bin_encode_spt: Error while encoding.\n");
00156     return 0;       
00157 }

static int bin_decode_spt ( bin_data x,
ims_spt spt 
) [static]

Decode an SPT.

Parameters:
x - binary data to decode from
spt - the service point trigger to decode into
Returns:
1 on succcess or 0 on error

Definition at line 166 of file bin_scscf.c.

References bin_decode_char(), bin_decode_int(), bin_decode_short(), bin_decode_str(), bin_decode_uchar(), _ims_spt::condition_negated, _ims_session_desc::content, _ims_sip_header::content, _ims_spt::group, _ims_sip_header::header, _ims_session_desc::line, M_NAME, _bin_data::max, _ims_spt::method, _ims_spt::registration_type, _ims_spt::request_uri, _ims_spt::session_case, _ims_spt::session_desc, _ims_spt::sip_header, str_shm_dup(), _ims_sip_header::type, and _ims_spt::type.

Referenced by bin_decode_filter_criteria().

00167 {
00168     unsigned char k;
00169     str s;
00170     
00171     if (!bin_decode_uchar(x,&k)) goto error;
00172     
00173     spt->type = k & 0x0F;
00174     spt->condition_negated = ((k & 0x80)!=0);
00175     spt->registration_type = ((k & 0x70)>>4);
00176     
00177     if (!bin_decode_int(x,&(spt->group))) goto error;
00178 
00179     switch (spt->type){
00180         case 1:
00181             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->request_uri),&s)) goto error;
00182             break;
00183         case 2:
00184             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->method),&s)) goto error;
00185             break;
00186         case 3:
00187             if (!bin_decode_short(x,&(spt->sip_header.type))) goto error;
00188             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->sip_header.header),&s)) goto error;
00189             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->sip_header.content),&s)) goto error;
00190             break;
00191         case 4:
00192             if (!bin_decode_char(x,&(spt->session_case))) goto error;
00193             break;
00194         case 5:
00195             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->session_desc.line),&s)) goto error;
00196             if (!bin_decode_str(x,&s)||!str_shm_dup(&(spt->session_desc.content),&s)) goto error;
00197             break;
00198 
00199     }
00200     return 1;
00201     
00202 error:
00203     LOG(L_ERR,"ERR:"M_NAME":bin_decode_spt: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00204     if (spt){
00205         switch (spt->type){
00206             case 1:
00207                 if (spt->request_uri.s) shm_free(spt->request_uri.s);
00208                 break;
00209             case 2:
00210                 if (spt->method.s) shm_free(spt->method.s);
00211                 break;
00212             case 3:
00213                 if (spt->sip_header.header.s) shm_free(spt->sip_header.header.s);
00214                 if (spt->sip_header.header.s) shm_free(spt->sip_header.content.s);
00215                 break;
00216             case 4:
00217                 break;
00218             case 5:
00219                 if (spt->sip_header.header.s) shm_free(spt->session_desc.line.s);
00220                 if (spt->sip_header.header.s) shm_free(spt->session_desc.content.s);
00221                 break;
00222         }
00223     }
00224     return 0;
00225 }   

static int bin_encode_filter_criteria ( bin_data x,
ims_filter_criteria fc 
) [static]

Encode and Append a Filter Criteria.

Parameters:
x - binary data to append to
spt - the service point trigger to encode
Returns:
1 on succcess or 0 on error

Definition at line 235 of file bin_scscf.c.

References _ims_filter_criteria::application_server, bin_encode_char(), bin_encode_int(), bin_encode_spt(), bin_encode_str(), bin_encode_ushort(), _ims_trigger_point::condition_type_cnf, _ims_application_server::default_handling, if, M_NAME, _ims_filter_criteria::priority, _ims_filter_criteria::profile_part_indicator, _ims_application_server::server_name, _ims_application_server::service_info, _ims_trigger_point::spt, _ims_trigger_point::spt_cnt, and _ims_filter_criteria::trigger_point.

Referenced by bin_encode_service_profile().

00236 {
00237     int i;
00238     char ppindicator;
00239 
00240     //priority
00241     if (!bin_encode_int(x,fc->priority)) goto error;
00242     
00243     //profile part indicator
00244     if (fc->profile_part_indicator) ppindicator = (*fc->profile_part_indicator)+1;
00245     else ppindicator = 0;
00246     if (!bin_encode_char(x,ppindicator)) goto error;
00247             
00248     // trigger point 
00249     if (fc->trigger_point) {
00250         if (!bin_encode_char(x,fc->trigger_point->condition_type_cnf)) goto error;
00251         
00252         if (!bin_encode_ushort(x,fc->trigger_point->spt_cnt)) goto error;
00253         
00254         for(i=0;i<fc->trigger_point->spt_cnt;i++)
00255             if (!bin_encode_spt(x,fc->trigger_point->spt+i)) goto error;
00256     } else {
00257         if (!bin_encode_char(x,100)) goto error;
00258     }
00259     
00260     //app server
00261     if (!bin_encode_str(x,&(fc->application_server.server_name))) goto error;
00262     if (!bin_encode_char(x,fc->application_server.default_handling)) goto error;
00263     if (!bin_encode_str(x,&(fc->application_server.service_info))) goto error;
00264     
00265     return 1;
00266 error:
00267     LOG(L_ERR,"ERR:"M_NAME":bin_encode_filter_criteria: Error while encoding.\n");
00268     return 0;       
00269 }

static int bin_decode_filter_criteria ( bin_data x,
ims_filter_criteria fc 
) [static]

Decode a Filter Criteria.

Parameters:
x - binary data to decode from
fc - filter criteria to decode into
Returns:
1 on succcess or 0 on error

Definition at line 278 of file bin_scscf.c.

References _ims_filter_criteria::application_server, bin_decode_char(), bin_decode_int(), bin_decode_spt(), bin_decode_str(), bin_decode_ushort(), _ims_trigger_point::condition_type_cnf, _ims_application_server::default_handling, if, M_NAME, _bin_data::max, NULL, _ims_filter_criteria::priority, _ims_filter_criteria::profile_part_indicator, _ims_application_server::server_name, _ims_application_server::service_info, _ims_trigger_point::spt, _ims_trigger_point::spt_cnt, str_shm_dup(), and _ims_filter_criteria::trigger_point.

00279 {
00280     int i,len;
00281     str s;
00282     char ppindicator,cnf;
00283     
00284     //priority
00285     if (!bin_decode_int(x,&(fc->priority))) goto error;
00286     
00287     // profile part indicator
00288     if (!bin_decode_char(x,&ppindicator)) goto error;
00289     if (!ppindicator){
00290         fc->profile_part_indicator = 0;
00291     }
00292     else {
00293         fc->profile_part_indicator = (char*)shm_malloc(sizeof(char));
00294         if (!fc->profile_part_indicator) {
00295             LOG(L_ERR,"ERR:"M_NAME":bin_decode_filter_criteria: Error allocating %d bytes.\n",sizeof(int));
00296             goto error;
00297         }
00298         *(fc->profile_part_indicator) = ppindicator-1;
00299     }
00300     
00301     //cnf 
00302     if (!bin_decode_char(x,&cnf)) goto error;
00303 
00304     if (cnf==100)
00305         fc->trigger_point=NULL;
00306     else {
00307         ims_trigger_point *tp=0;
00308         //trigger point
00309         len = sizeof(ims_trigger_point);
00310         tp = (ims_trigger_point*)shm_malloc(len);
00311         fc->trigger_point = tp;
00312         if (!tp) {
00313             LOG(L_ERR,"ERR:"M_NAME":bin_decode_filter_criteria: Error allocating %d bytes.\n",len);
00314             goto error;
00315         }
00316         memset(tp,0,len);
00317         tp->condition_type_cnf=cnf;
00318         
00319         if (!bin_decode_ushort(x,&tp->spt_cnt)) goto error;
00320         len = sizeof(ims_spt)*tp->spt_cnt;
00321         tp->spt = (ims_spt*)shm_malloc(len);
00322         if (!tp->spt) {
00323             LOG(L_ERR,"ERR:"M_NAME":bin_decode_filter_criteria: Error allocating %d bytes.\n",len);
00324             goto error;
00325         }
00326         memset(tp->spt,0,len);
00327         for(i=0;i<tp->spt_cnt;i++)
00328             if (!bin_decode_spt(x,tp->spt+i)) goto error;
00329     }
00330     //app server uri
00331     if (!bin_decode_str(x,&s)||!str_shm_dup(&(fc->application_server.server_name),&s)) goto error;
00332     // app server default handling
00333     if (!bin_decode_char(x,&(fc->application_server.default_handling)))goto error;
00334     // app server service info
00335     if (!bin_decode_str(x,&s)||!str_shm_dup(&(fc->application_server.service_info),&s)) goto error;
00336 
00337     return 1;
00338 error:
00339     LOG(L_ERR,"ERR:"M_NAME":bin_decode_filter_criteria: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00340     if (fc){
00341         if (fc->trigger_point){
00342             if (fc->trigger_point){
00343                 if (fc->trigger_point->spt) shm_free(fc->trigger_point->spt);
00344             }
00345             shm_free(fc->trigger_point);
00346         }
00347         if (fc->application_server.server_name.s) shm_free(fc->application_server.server_name.s);
00348         if (fc->application_server.service_info.s) shm_free(fc->application_server.service_info.s);
00349     }
00350     return 0;       
00351 }

static int bin_encode_service_profile ( bin_data x,
ims_service_profile sp 
) [static]

Encode and append a Service Profile.

Parameters:
x - binary data to append to
sp - the service profile to encode
Returns:
1 on succcess or 0 on error

Definition at line 364 of file bin_scscf.c.

References bin_encode_filter_criteria(), bin_encode_int(), bin_encode_public_identity(), bin_encode_ushort(), ims_service_profile::cn_service_auth, ims_service_profile::filter_criteria, ims_service_profile::filter_criteria_cnt, if, M_NAME, ims_service_profile::public_identities, ims_service_profile::public_identities_cnt, ims_service_profile::shared_ifc_set, ims_service_profile::shared_ifc_set_cnt, and _ims_cn_service_auth::subscribed_media_profile_id.

Referenced by bin_encode_ims_subscription().

00365 {
00366     int i;
00367         
00368     //public identity
00369     if (!bin_encode_ushort(x,sp->public_identities_cnt)) return 0;
00370     for(i=0;i<sp->public_identities_cnt;i++)
00371         if (!bin_encode_public_identity(x,sp->public_identities+i)) goto error;
00372     
00373     //filter criteria
00374     if (!bin_encode_ushort(x,sp->filter_criteria_cnt)) return 0;
00375     for(i=0;i<sp->filter_criteria_cnt;i++)
00376         if (!bin_encode_filter_criteria(x,sp->filter_criteria+i)) goto error;
00377         
00378     //cn service_auth
00379     if (sp->cn_service_auth)
00380         i = sp->cn_service_auth->subscribed_media_profile_id;
00381     else i = 0xFFFFFFFF;
00382     if (!bin_encode_int(x,i)) goto error;
00383 
00384     //shared_ifc
00385     if (!bin_encode_ushort(x,sp->shared_ifc_set_cnt)) return 0;
00386     for(i=0;i<sp->shared_ifc_set_cnt;i++)
00387         if (!bin_encode_int(x,sp->shared_ifc_set[i])) goto error;
00388 
00389     return 1;
00390 error:
00391     LOG(L_ERR,"ERR:"M_NAME":bin_encode_service_profile: Error while encoding.\n");
00392     return 0;       
00393 }

static int bin_decode_service_profile ( bin_data x,
ims_service_profile sp 
) [static]

Decode a service profile.

Parameters:
x - binary data to decode from
sp - service profile to decode into
Returns:
1 on succcess or 0 on error

Definition at line 402 of file bin_scscf.c.

References bin_decode_public_identity(), bin_decode_ushort(), ims_service_profile::filter_criteria, ims_service_profile::filter_criteria_cnt, if, M_NAME, ims_service_profile::public_identities, and ims_service_profile::public_identities_cnt.

Referenced by bin_decode_ims_subscription().

00403 {
00404     int i,len;
00405 
00406     //public identities
00407     if (!bin_decode_ushort(x,&(sp->public_identities_cnt))) goto error;
00408     len = sizeof(ims_public_identity)*sp->public_identities_cnt;
00409     sp->public_identities = (ims_public_identity*)shm_malloc(len);
00410     if (!sp->public_identities) {
00411         LOG(L_ERR,"ERR:"M_NAME":bin_decode_service_profile: Error allocating %d bytes.\n",len);
00412         goto error;
00413     }
00414     memset(sp->public_identities,0,len);
00415     for(i=0;i<sp->public_identities_cnt;i++)
00416         if (!bin_decode_public_identity(x,sp->public_identities+i)) goto error;
00417     
00418     // filter criteria
00419     if (!bin_decode_ushort(x,&(sp->filter_criteria_cnt))) goto error;   
00420     len = sizeof(ims_filter_criteria)*sp->filter_criteria_cnt;
00421     sp->filter_criteria = (ims_filter_criteria*)shm_malloc(len);
00422     if (!sp->filter_criteria) {
00423         LOG(L_ERR,"ERR:"M_NAME":bin_decode_service_profile: Error allocating %d bytes.\n",len);
00424         goto error;
00425     }
00426     memset(sp->filter_criteria,0,len);
00427     for(i=0;i<sp->filter_criteria_cnt;i++)
00428         if (!bin_decode_filter_criteria(x,sp->filter_criteria+i)) goto error;
00429 
00430     // cn service auth
00431     if (!bin_decode_int(x,&i)) goto error;
00432     if (i==0xFFFFFFFF)
00433         sp->cn_service_auth = 0;
00434     else {
00435         len = sizeof(ims_cn_service_auth);
00436         sp->cn_service_auth = (ims_cn_service_auth*)shm_malloc(len);
00437         if (!sp->cn_service_auth) {
00438             LOG(L_ERR,"ERR:"M_NAME":bin_decode_service_profile: Error allocating %d bytes.\n",len);
00439             goto error;
00440         }
00441         sp->cn_service_auth->subscribed_media_profile_id=i;
00442     }
00443     
00444     //shared ifc
00445     if (!bin_decode_ushort(x,&(sp->shared_ifc_set_cnt))) goto error;    
00446     len = sizeof(int)*sp->shared_ifc_set_cnt;
00447     sp->shared_ifc_set = (int*)shm_malloc(len);
00448     if (!sp->shared_ifc_set) {
00449         LOG(L_ERR,"ERR:"M_NAME":bin_decode_service_profile: Error allocating %d bytes.\n",len);
00450         goto error;
00451     }
00452     memset(sp->shared_ifc_set,0,len);
00453     for(i=0;i<sp->shared_ifc_set_cnt;i++)
00454         if (!bin_decode_int(x,sp->shared_ifc_set+i)) goto error;
00455 
00456     return 1;
00457 error:
00458     LOG(L_ERR,"ERR:"M_NAME":bin_decode_service_profile: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00459     if (sp) {
00460         if (sp->public_identities) shm_free(sp->public_identities);
00461         if (sp->filter_criteria) shm_free(sp->filter_criteria);
00462         if (sp->cn_service_auth) shm_free(sp->cn_service_auth);
00463         if (sp->shared_ifc_set) shm_free(sp->shared_ifc_set);
00464     }
00465     return 0;
00466 }

int bin_encode_ims_subscription ( bin_data x,
ims_subscription s 
)

Encode the entire user profile and append it to the binary data.

Parameters:
x - binary data to append to
s - the ims subscription to encode
Returns:
1 on succcess or 0 on error

Definition at line 486 of file bin_scscf.c.

References bin_encode_service_profile(), bin_encode_str(), bin_encode_ushort(), M_NAME, ims_subscription::private_identity, ims_subscription::service_profiles, and ims_subscription::service_profiles_cnt.

Referenced by bin_encode_r_public().

00487 {
00488     int i;
00489     if (!bin_encode_str(x,&(s->private_identity))) goto error;
00490     if (!bin_encode_ushort(x,s->service_profiles_cnt)) goto error;
00491 
00492     for(i=0;i<s->service_profiles_cnt;i++)
00493         if (!bin_encode_service_profile(x,s->service_profiles+i)) goto error;
00494     
00495     return 1;
00496 error:
00497     LOG(L_ERR,"ERR:"M_NAME":bin_encode_ims_subscription: Error while encoding.\n");
00498     return 0;   
00499 }

ims_subscription* bin_decode_ims_subscription ( bin_data x  ) 

Decode a binary string from a binary data structure.

Parameters:
x - binary data to decode from
Returns:
the ims_subscription* where the data has been decoded

Definition at line 507 of file bin_scscf.c.

References bin_decode_service_profile(), bin_decode_str(), bin_decode_ushort(), ims_subscription::lock, M_NAME, _bin_data::max, ims_subscription::private_identity, ims_subscription::ref_count, ims_subscription::service_profiles, ims_subscription::service_profiles_cnt, and str_shm_dup().

Referenced by bin_decode_r_public().

00508 {
00509     ims_subscription *imss=0;
00510     int i,len;
00511     str s;
00512     
00513     imss = (ims_subscription*) shm_malloc(sizeof(ims_subscription));
00514     if (!imss) {
00515         LOG(L_ERR,"ERR:"M_NAME":bin_decode_ims_subscription: Error allocating %d bytes.\n",sizeof(ims_subscription));
00516         goto error;
00517     }
00518     memset(imss,0,sizeof(ims_subscription));
00519     
00520     if (!bin_decode_str(x,&s)||!str_shm_dup(&(imss->private_identity),&s)) goto error;
00521     if (!bin_decode_ushort(x,   &(imss->service_profiles_cnt))) goto error;
00522     
00523     len = sizeof(ims_service_profile)*imss->service_profiles_cnt;
00524     imss->service_profiles = (ims_service_profile*)shm_malloc(len);
00525     if (!imss->service_profiles) {
00526         LOG(L_ERR,"ERR:"M_NAME":bin_decode_ims_subscription: Error allocating %d bytes.\n",len);
00527         goto error;
00528     }
00529     memset(imss->service_profiles,0,len);
00530 
00531     for(i=0;i<imss->service_profiles_cnt;i++)
00532         if (!bin_decode_service_profile(x,imss->service_profiles+i)) goto error;
00533 
00534     imss->lock = lock_alloc();
00535     imss->lock = lock_init(imss->lock);
00536     imss->ref_count = 1;
00537 
00538     return imss;
00539 error:
00540     LOG(L_ERR,"ERR:"M_NAME":bin_decode_ims_subscription: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00541     if (imss) {
00542         if (imss->private_identity.s) shm_free(imss->private_identity.s);
00543         if (imss->service_profiles) shm_free(imss->service_profiles);
00544         shm_free(imss);
00545     }
00546     return 0;
00547 }

int bin_encode_r_contact ( bin_data x,
r_contact c 
)

Encode a r_contact into a binary form.

Parameters:
x - binary data to append to
c - the r_contact to encode
Returns:
1 on succcess or 0 on error

Definition at line 559 of file bin_scscf.c.

References bin_encode_char(), bin_encode_pinhole(), bin_encode_r_public(), bin_encode_r_security(), bin_encode_str(), bin_encode_time_t(), bin_encode_ushort(), _r_contact::expires, _r_contact::head, _r_contact::host, if, M_NAME, _r_public::next, _r_contact::path, _r_contact::pinhole, _r_contact::port, _r_contact::reg_state, _r_contact::security, _r_contact::security_temp, _r_contact::service_route, _r_contact::service_route_cnt, _r_contact::transport, _r_contact::ua, and _r_contact::uri.

00560 {
00561     if (!bin_encode_str(x,&(c->uri))) goto error;
00562     if (!bin_encode_time_t(x,c->expires)) goto error;
00563     if (!bin_encode_str(x,&(c->ua))) goto error;
00564     if (!bin_encode_str(x,&(c->path))) goto error;
00565 
00566     return 1;
00567 error:
00568     LOG(L_ERR,"ERR:"M_NAME":bin_encode_r_contact: Error while encoding.\n");
00569     return 0;       
00570 }

r_contact* bin_decode_r_contact ( bin_data x  ) 

Decode a r_contact from a binary data structure.

Parameters:
x - binary data to decode from
Returns:
the r_contact* where the data has been decoded

Definition at line 577 of file bin_scscf.c.

References bin_decode_char(), bin_decode_pinhole(), bin_decode_r_public(), bin_decode_r_security(), bin_decode_str(), bin_decode_time_t(), bin_decode_ushort(), _r_contact::expires, free_r_public(), free_r_security(), get_contact_hash(), _r_contact::hash, _r_contact::head, _r_contact::host, if, M_NAME, _bin_data::max, _r_public::next, _r_contact::path, _r_contact::pinhole, _r_contact::port, _r_public::prev, r_hash_size, _r_contact::reg_state, _r_contact::security, _r_contact::security_temp, _r_contact::service_route, _r_contact::service_route_cnt, str_shm_dup(), _r_contact::tail, _r_contact::transport, _r_contact::ua, and _r_contact::uri.

00578 {
00579     r_contact *c=0;
00580     int len;
00581     str s;
00582     
00583     len = sizeof(r_contact);
00584     c = (r_contact*) shm_malloc(len);
00585     if (!c) {
00586         LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error allocating %d bytes.\n",len);
00587         goto error;
00588     }
00589     memset(c,0,len);
00590     
00591     if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->uri),&s)) goto error;
00592     if (!bin_decode_time_t(x,&c->expires)) goto error;
00593     if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->ua),&s)) goto error;
00594     if (!bin_decode_str(x,&s)||!str_shm_dup(&(c->path),&s)) goto error;
00595     
00596     return c;
00597 error:
00598     LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_contact: Error while decoding (at %d (%04x)).\n",x->max,x->max);
00599     if (c) {
00600         if (c->uri.s) shm_free(c->uri.s);
00601         if (c->ua.s) shm_free(c->ua.s);
00602         if (c->path.s) shm_free(c->path.s);
00603         
00604         shm_free(c);
00605     }
00606     return 0;
00607 }

int bin_encode_r_subscriber ( bin_data x,
r_subscriber s 
)

Encode a r_subscriber into a binary form.

Parameters:<