registrar_parser.h File Reference


Detailed Description

Serving-CSCF - Parser for the IMS User Subscription XML.

This XML is received in the Server-Assignment-Answer

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

Definition in file registrar_parser.h.

#include "registrar.h"
#include "../../sr_module.h"
#include "../../locking.h"
#include "ifc_datastruct.h"

Go to the source code of this file.

Functions

int parser_init (char *dtd_filename, char *xsd_filename)
 Initializes the libxml2 parser.
void parser_destroy ()
 Destroys the parser.
ims_subscriptionparse_user_data (str xml)
 Parses the user data XML and copies data into a new ims_subscription structure.
void print_user_data (int log_level, ims_subscription *s)
 Print the contents of an ims_subscription structure.
void free_user_data (ims_subscription *s)
 Deallocates memory used by a subscription.


Function Documentation

int parser_init ( char *  dtd_filename,
char *  xsd_filename 
)

Initializes the libxml2 parser.

Parameters:
dtd_filename - path to the DTD or NULL if none
xsd_filename - path to the XSD or NULL if none
Returns:
1 on success or 0 on error

Definition at line 89 of file registrar_parser.c.

References ctxtInit, dtd, dtdCtxt, M_NAME, NULL, xsd, and xsdCtxt.

00090 {
00091     if (dtd_filename){
00092         dtd = xmlParseDTD(NULL,(unsigned char*)dtd_filename);
00093         if (!dtd){
00094             LOG(L_ERR,"ERR:"M_NAME":parser_init: unsuccesful DTD parsing from file <%s>\n",
00095                 dtd_filename);
00096             return 0;
00097         }
00098         dtdCtxt = xmlNewValidCtxt();
00099         dtdCtxt->userData = (void*)stderr;
00100         dtdCtxt->error = (xmlValidityErrorFunc) fprintf;
00101         dtdCtxt->warning = (xmlValidityWarningFunc) fprintf;
00102     }
00103     if (xsd_filename){
00104         xmlSchemaParserCtxtPtr ctxt;
00105         ctxt = xmlSchemaNewParserCtxt(xsd_filename);
00106         if (!ctxt) {
00107             LOG(L_ERR,"ERR:"M_NAME":parser_init: unsuccesful XSD parsing from file <%s>\n",
00108                 xsd_filename);
00109             return 0;
00110         }
00111         xmlSchemaSetParserErrors(ctxt,(xmlValidityErrorFunc) fprintf,(xmlValidityWarningFunc) fprintf,stderr);
00112         xsd = xmlSchemaParse(ctxt);
00113         xmlSchemaFreeParserCtxt(ctxt);      
00114         
00115         xsdCtxt = xmlSchemaNewValidCtxt(xsd);
00116         xmlSchemaSetValidErrors(xsdCtxt,(xmlValidityErrorFunc) fprintf,(xmlValidityWarningFunc) fprintf,stderr);
00117     }
00118     ctxtInit=1;
00119     return 1;
00120 }

void parser_destroy (  ) 

Destroys the parser.

Definition at line 676 of file registrar_subscribe.c.

References dtdCtxt, and xsdCtxt.

00677 {
00678     xmlCleanupParser();
00679 }

ims_subscription* parse_user_data ( str  xml  ) 

Parses the user data XML and copies data into a new ims_subscription structure.

Parameters:
xml - the input xml
Returns:
the ims_subscription* on success or NULL on error

Definition at line 957 of file registrar_parser.c.

References ctxtInit, dtd, dtdCtxt, M_NAME, parse_ims_subscription(), parser_init(), scscf_user_data_dtd, scscf_user_data_xsd, and xsdCtxt.

Referenced by Cx_PPA(), and save_location().

00958 {
00959     xmlDocPtr doc=0;
00960     xmlNodePtr root=0;
00961     char c;
00962     ims_subscription *s;
00963     if (!ctxtInit) parser_init(scscf_user_data_dtd,scscf_user_data_xsd);    
00964     doc=0;
00965     c = xml.s[xml.len];
00966     xml.s[xml.len]=0;
00967     doc = xmlParseDoc((unsigned char *)xml.s);
00968     if (!doc){
00969         LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  This is not a valid XML <%.*s>\n",
00970             xml.len,xml.s);
00971         goto error;
00972     }
00973     if (dtdCtxt){
00974         if (xmlValidateDtd(dtdCtxt,doc,dtd)!=1){
00975             LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Verification of XML against DTD failed <%.*s>\n",
00976                 xml.len,xml.s);
00977             goto error;
00978         }
00979     }
00980     if (xsdCtxt){
00981         if (xmlSchemaValidateDoc(xsdCtxt,doc)!=0){
00982             LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Verification of XML against XSD failed <%.*s>\n",
00983                 xml.len,xml.s);
00984             goto error;
00985         }
00986     }
00987     root = xmlDocGetRootElement(doc);
00988     if (!root){
00989         LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Empty XML <%.*s>\n",
00990             xml.len,xml.s);
00991         goto error;
00992     }
00993     s = parse_ims_subscription(doc,root);
00994     if (!s){
00995         LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Error while loading into  ims subscription structure\n");
00996         goto error;     
00997     }
00998     xmlFreeDoc(doc);
00999 //  print_user_data(L_CRIT,s);
01000     return s;
01001 error:  
01002     if (doc) xmlFreeDoc(doc);
01003     xml.s[xml.len]=c;
01004     return 0;   
01005 }

void print_user_data ( int  log_level,
ims_subscription s 
)

Print the contents of an ims_subscription structure.

Parameters:
log_level - level to log on
s - the ims_subscription to be printed

Definition at line 1012 of file registrar_parser.c.

References ims_public_identity::barring, _ims_spt::condition_negated, _ims_trigger_point::condition_type_cnf, _ims_session_desc::content, _ims_sip_header::content, ims_service_profile::filter_criteria, ims_service_profile::filter_criteria_cnt, _ims_spt::group, _ims_sip_header::header, if, _ims_session_desc::line, ims_subscription::lock, M_NAME, _ims_spt::method, _ims_filter_criteria::priority, ims_subscription::private_identity, _ims_filter_criteria::profile_part_indicator, ims_service_profile::public_identities, ims_service_profile::public_identities_cnt, ims_public_identity::public_identity, _ims_spt::registration_type, _ims_spt::request_uri, ims_subscription::service_profiles, ims_subscription::service_profiles_cnt, _ims_spt::session_case, _ims_spt::session_desc, _ims_spt::sip_header, _ims_trigger_point::spt, _ims_filter_criteria::trigger_point, _ims_sip_header::type, and _ims_spt::type.

Referenced by Cx_PPA(), and save_location().

01013 {
01014     int i,j,k;
01015     if (debug<log_level) return; /* to avoid useless calls when nothing will be printed */
01016     LOG(log_level,"INF:"M_NAME":IMSSubscription:\n");
01017     if (!s) return;
01018     lock_get(s->lock);
01019     LOG(log_level,"INF:"M_NAME":\tPrivate Identity: <%.*s>\n",s->private_identity.len,s->private_identity.s);
01020     for(i=0;i<s->service_profiles_cnt;i++){
01021         LOG(log_level,"INF:"M_NAME":\tService Profile:\n");
01022         for(j=0;j<s->service_profiles[i].public_identities_cnt;j++){    
01023             LOG(log_level,"INF:"M_NAME":\t\tPublic Identity: Barring [%d] <%.*s> \n",
01024                 s->service_profiles[i].public_identities[j].barring,
01025                 s->service_profiles[i].public_identities[j].public_identity.len,
01026                 s->service_profiles[i].public_identities[j].public_identity.s);         
01027         }
01028         for(j=0;j<s->service_profiles[i].filter_criteria_cnt;j++){  
01029             LOG(log_level,"INF:"M_NAME":\t\tFilter Criteria: Priority [%d]ProfilePartInd [%d]\n",
01030                 s->service_profiles[i].filter_criteria[j].priority,
01031                 s->service_profiles[i].filter_criteria[j].profile_part_indicator?
01032                  *(s->service_profiles[i].filter_criteria[j].profile_part_indicator):-1 );              
01033             if (s->service_profiles[i].filter_criteria[j].trigger_point){
01034                 LOG(log_level,"INF:"M_NAME":\t\t\tTrigger Point: CNF [%c] %s\n",
01035                     s->service_profiles[i].filter_criteria[j].trigger_point->condition_type_cnf?'X':' ',
01036                     s->service_profiles[i].filter_criteria[j].trigger_point->condition_type_cnf?"(_|_)&(_|_)":"(_&_)|(_&_)"
01037                     );                                          
01038                 for(k=0;k<s->service_profiles[i].filter_criteria[j].trigger_point->spt_cnt;k++){    
01039                     LOG(log_level,"INF:"M_NAME":\t\t\t\tSPT: Grp[%d] NOT[%c] RegType[%d]\n",
01040                         s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].group,
01041                         s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].condition_negated?'X':' ',
01042                         s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].registration_type
01043                     );                                                              
01044                     switch(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].type){
01045                         case 1:
01046                             LOG(log_level,"INF:"M_NAME":\t\t\t\t\t Request-URI == <%.*s>\n",
01047                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].request_uri.len,
01048                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].request_uri.s);
01049                             break;
01050                         case 2:
01051                             LOG(log_level,"INF:"M_NAME":\t\t\t\t\t Method == <%.*s>\n",
01052                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].method.len,
01053                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].method.s);
01054                             break;
01055                         case 3:
01056                             LOG(log_level,"INF:"M_NAME":\t\t\t\t\t Hdr(%.*s(%d)) == <%.*s>\n",
01057                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.header.len,
01058                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.header.s,
01059                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.type,
01060                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.content.len,
01061                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.content.s);
01062                             break;
01063                         case 4:
01064                             LOG(log_level,"INF:"M_NAME":\t\t\t\t\t SessionCase [%d]\n",
01065                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_case);
01066                             break;
01067                         case 5:
01068                             LOG(log_level,"INF:"M_NAME":\t\t\t\t\t SDP(%.*s) == <%.*s>\n",
01069                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.line.len,
01070                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.line.s,
01071                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.content.len,
01072                                 s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.content.s);
01073                             break;                          
01074                     }
01075                 }                   
01076             }           
01077             LOG(log_level,"INF:"M_NAME":\t\t\tAS: <%.*s> Handling [%d] SrvInfo: <%.*s>\n",
01078                 s->service_profiles[i].filter_criteria[j].application_server.server_name.len,
01079                 s->service_profiles[i].filter_criteria[j].application_server.server_name.s,
01080                 s->service_profiles[i].filter_criteria[j].application_server.default_handling,
01081                 s->service_profiles[i].filter_criteria[j].application_server.service_info.len,              
01082                 s->service_profiles[i].filter_criteria[j].application_server.service_info.s);                           
01083         }
01084         if (s->service_profiles[i].cn_service_auth){
01085             LOG(log_level,"INF:"M_NAME":\t\tCN Serv Auth: Subs Media Profile ID [%d]\n",
01086                 s->service_profiles[i].cn_service_auth->subscribed_media_profile_id);           
01087         }       
01088         for(j=0;j<s->service_profiles[i].shared_ifc_set_cnt;j++){   
01089             LOG(log_level,"INF:"M_NAME":\t\tShared IFC Set: [%d]\n",
01090                 s->service_profiles[i].shared_ifc_set[j]);          
01091         }       
01092     }
01093     lock_release(s->lock);
01094 }

void free_user_data ( ims_subscription s  ) 

Deallocates memory used by a subscription.

Note:
Must be called with the lock got to avoid races
Parameters:
s - the ims_subscription to free

Definition at line 1101 of file registrar_parser.c.

References _ims_session_desc::content, _ims_sip_header::content, ims_service_profile::filter_criteria, _ims_sip_header::header, if, IFC_METHOD, IFC_REQUEST_URI, IFC_SESSION_CASE, IFC_SESSION_DESC, IFC_SIP_HEADER, _ims_session_desc::line, _ims_spt::method, ims_service_profile::public_identities, ims_service_profile::public_identities_cnt, ims_public_identity::public_identity, _ims_spt::request_uri, ims_subscription::service_profiles, ims_subscription::service_profiles_cnt, _ims_spt::session_desc, _ims_spt::sip_header, _ims_trigger_point::spt, _ims_filter_criteria::trigger_point, _ims_spt::type, and ims_public_identity::wildcarded_psi.

Referenced by free_r_public(), save_location(), update_r_public(), and update_r_public_previous_lock().

01102 {
01103     int i,j,k;
01104     if (!s) return;
01105 /*  lock_get(s->lock); - must be called with the lock got */
01106     for(i=0;i<s->service_profiles_cnt;i++){
01107         for(j=0;j<s->service_profiles[i].public_identities_cnt;j++){
01108             if (s->service_profiles[i].public_identities[j].public_identity.s)
01109                 shm_free(s->service_profiles[i].public_identities[j].public_identity.s);
01110             if (s->service_profiles[i].public_identities[j].wildcarded_psi.s)
01111                 shm_free(s->service_profiles[i].public_identities[j].wildcarded_psi.s);
01112                         
01113         }       
01114         if (s->service_profiles[i].public_identities) 
01115             shm_free(s->service_profiles[i].public_identities);
01116 
01117         for(j=0;j<s->service_profiles[i].filter_criteria_cnt;j++){
01118             if (s->service_profiles[i].filter_criteria[j].trigger_point){
01119                 for(k=0;k<s->service_profiles[i].filter_criteria[j].trigger_point->spt_cnt;k++){
01120                     switch(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].type){
01121                         case IFC_REQUEST_URI:
01122                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].request_uri.s)  
01123                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].request_uri.s);
01124                             break;
01125                         case IFC_METHOD:
01126                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].method.s)   
01127                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].method.s);
01128                             break;
01129                         case IFC_SIP_HEADER:
01130                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.header.s)    
01131                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.header.s);
01132                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.content.s)   
01133                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].sip_header.content.s);
01134                             break;
01135                         case IFC_SESSION_CASE:
01136                             break;
01137                         case IFC_SESSION_DESC:
01138                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.line.s)    
01139                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.line.s);
01140                             if (s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.content.s) 
01141                                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt[k].session_desc.content.s);
01142                             break;
01143                             
01144                     }                   
01145                 }                               
01146                 if (s->service_profiles[i].filter_criteria[j].trigger_point->spt)
01147                     shm_free(s->service_profiles[i].filter_criteria[j].trigger_point->spt);                     
01148                 shm_free(s->service_profiles[i].filter_criteria[j].trigger_point);
01149             }
01150             if (s->service_profiles[i].filter_criteria[j].application_server.server_name.s)
01151                 shm_free(s->service_profiles[i].filter_criteria[j].application_server.server_name.s);
01152             if (s->service_profiles[i].filter_criteria[j].application_server.service_info.s)
01153                 shm_free(s->service_profiles[i].filter_criteria[j].application_server.service_info.s);
01154             if (s->service_profiles[i].filter_criteria[j].profile_part_indicator)
01155                 shm_free(s->service_profiles[i].filter_criteria[j].profile_part_indicator);
01156         }
01157         if (s->service_profiles[i].filter_criteria) 
01158             shm_free(s->service_profiles[i].filter_criteria);       
01159             
01160         if (s->service_profiles[i].cn_service_auth) 
01161             shm_free(s->service_profiles[i].cn_service_auth);                   
01162 
01163         if (s->service_profiles[i].shared_ifc_set) 
01164             shm_free(s->service_profiles[i].shared_ifc_set);                    
01165     }
01166     if (s->service_profiles) shm_free(s->service_profiles);
01167     if (s->private_identity.s) shm_free(s->private_identity.s);
01168     lock_release(s->lock);
01169     lock_destroy(s->lock);
01170     lock_dealloc(s->lock);
01171     shm_free(s);
01172     
01173 }


Generated on Thu Oct 23 04:14:45 2008 for Open IMS Core CSCFs by  doxygen 1.5.2