sip.h File Reference


Detailed Description

P/I/S-CSCF Module - Main SIP Operations.

Author:
Dragos Vingarzan vingarzan -at- fokus dot fraunhofer dot de
Copyright (C) 2005 FhG Fokus

Definition in file sip.h.

#include "../../sr_module.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/digest/digest.h"
#include "../../parser/parse_rr.h"

Go to the source code of this file.

Functions

int cscf_add_header_first (struct sip_msg *msg, str *hdr, int type)
 Adds a header to the message as the first one in the message.
int cscf_add_header (struct sip_msg *msg, str *hdr, int type)
 Adds a header to the message.
int cscf_add_header_rpl (struct sip_msg *msg, str *hdr)
 Adds a header to the reply message.
int cscf_add_contact (struct sip_msg *msg, str uri, int expires)
str cscf_get_private_identity (struct sip_msg *msg, str realm)
 Returns the Private Identity extracted from the Authorization header.
str cscf_get_public_identity (struct sip_msg *msg)
 Returns the Public Identity extracted from the To header.
int cscf_get_expires_hdr (struct sip_msg *msg)
 Returns the expires value from the Expires header in the message.
int cscf_get_max_expires (struct sip_msg *msg)
 Returns the expires value from the message.
str cscf_get_public_identity_from_requri (struct sip_msg *msg)
 Get the Public Identity from the Request URI of the message.
sip_msg * cscf_get_request (unsigned int hash, unsigned int label)
 Retrieves the SIP request that generated a diameter transaction.
int cscf_get_integrity_protected (struct sip_msg *msg, str realm)
 Returns if the SIP message is integrity protected.
int cscf_get_transaction (struct sip_msg *msg, unsigned int *hash, unsigned int *label)
 Returns the tm transaction identifiers.
int cscf_reply_transactional (struct sip_msg *msg, int code, char *text)
 Transactional SIP response - tries to create a transaction if none found.
str cscf_get_auts (struct sip_msg *msg, str realm)
 Looks for the auts parameter in the Authorization header and returns its value.
str cscf_get_nonce (struct sip_msg *msg, str realm)
 Looks for the nonce parameter in the Authorization header and returns its value.
str cscf_get_algorithm (struct sip_msg *msg, str realm)
 Looks for the algorithm parameter in the Authorization header and returns its value.
str cscf_get_digest_uri (struct sip_msg *msg, str realm)
 Looks for the uri parameter in the Authorization header and returns its value.
int cscf_get_nonce_response (struct sip_msg *msg, str realm, str *nonce, str *response, enum qop_type *qop, str *qop_str, str *nc, str *cnonce, str *uri)
 Looks for the nonce and response parameters in the Authorization header and returns them.
str cscf_get_user_agent (struct sip_msg *msg)
 Looks for the User-Agent header and extracts its content.
contact_body_t * cscf_parse_contacts (struct sip_msg *msg)
 Parses all the contact headers.
str cscf_get_path (struct sip_msg *msg)
 Retrieve a list of concatenated contents of Path headers found in the message.
str cscf_get_event (struct sip_msg *msg)
 Looks for the Event header and extracts its content.
str cscf_get_asserted_identity (struct sip_msg *msg)
 Looks for the P-Asserted-Identity header and extracts its content.
str cscf_get_asserted_identity_domain (struct sip_msg *msg)
 Looks for the P-Asserted-Identity header and extracts the domain inside the uri.
str cscf_get_contact (struct sip_msg *msg)
 Looks for the Contact header and extracts its content.
str cscf_get_first_route (struct sip_msg *msg, struct hdr_field **hr)
 Looks for the First Route header.
int cscf_remove_first_route (struct sip_msg *msg, str value)
 Looks if the first entry in the first Route points is equal to the given value and deletes the old header.
int cscf_remove_own_route (struct sip_msg *msg, struct hdr_field **h)
 Looks if the first entry in the first Route points to myself and if positive, it removes it deletes the old header.
str cscf_get_record_routes (struct sip_msg *msg)
 Returns all the record routes, concatenated.
hdr_field * cscf_get_next_record_route (struct sip_msg *msg, struct hdr_field *start)
 Returns the next record route header.
hdr_field * cscf_get_next_via_hdr (struct sip_msg *msg, struct hdr_field *start)
 Returns the next via header.
str cscf_get_next_via_str (struct sip_msg *msg, struct hdr_field *h, int pos, struct hdr_field **h_out, int *pos_out)
 Returns the next via str.
int cscf_via_matching (struct via_body *req_via, struct via_body *rpl_via)
 cscf_via_matching
int cscf_str_via_matching (str *sreq_via, str *srpl_via)
 Checks if 2 via strings are equal.
str cscf_get_realm_from_ruri (struct sip_msg *msg)
 Delivers the Realm from request URI.
str cscf_get_identity_from_ruri (struct sip_msg *msg)
 Gets identity from the request URI.
str cscf_get_call_id (struct sip_msg *msg, struct hdr_field **hr)
 Looks for the Call-ID header.
int cscf_get_cseq (struct sip_msg *msg, struct hdr_field **hr)
 Looks for the Call-ID header.
str cscf_get_cseq_method (struct sip_msg *msg, struct hdr_field **hr)
 Looks for the Call-ID header.
sip_msg * cscf_get_request_from_reply (struct sip_msg *reply)
 Returns the corresponding request for a reply, using tm transactions.
str cscf_get_called_party_id (struct sip_msg *msg, struct hdr_field **hr)
 Looks for the P-Preferred-Identity header and extracts its content.
int cscf_get_subscription_state (struct sip_msg *msg)
 Looks for the Subscription-State header and extracts its content.
int cscf_replace_string (struct sip_msg *msg, str orig, str repl)
 Replace a string in a message with another one.
hdr_field * cscf_get_header (struct sip_msg *msg, str header_name)
 Returns the first header structure for a given header name.
hdr_field * cscf_get_next_header (struct sip_msg *msg, str header_name, struct hdr_field *last_header)
 Returns the next header structure for a given header name.
hdr_field * cscf_get_next_header_type (struct sip_msg *msg, hdr_types_t type, struct hdr_field *last_header)
 Returns the next header structure for a given hdr_types_t type.
str cscf_get_headers_content (struct sip_msg *msg, str header_name)
 Get the content of a certain header.
str cscf_get_body (struct sip_msg *msg)
 Returns the first header structure for a given header name.
str cscf_get_visited_network_id (struct sip_msg *msg, struct hdr_field **h)
 Return the P-Visited-Network-ID header.
str cscf_get_access_network_info (struct sip_msg *msg, struct hdr_field **h)
 Return the P-Access-Network-Info header.
str cscf_get_authorization (struct sip_msg *msg, struct hdr_field **h)
 Looks for the Authorization header and returns its body.
str cscf_get_authenticate (struct sip_msg *msg, struct hdr_field **h)
 Looks for the WWW-Authenticate header and returns its body.
str cscf_get_session_expires_body (struct sip_msg *msg, struct hdr_field **h)
 Looks for the Session-Expires header and returns its body.
time_t cscf_get_session_expires (str expHdr, str *refresher)
 get Session Expires Value .
str cscf_get_min_se (struct sip_msg *msg, struct hdr_field **h)
 Looks for the Min-SE header and returns its body.
int cscf_del_header (struct sip_msg *msg, struct hdr_field *h)
 Deletes the given header.
int cscf_del_all_headers (struct sip_msg *msg, int hdr_type)
 Deletes all the headers of a given type.
via_body * cscf_get_first_via (struct sip_msg *msg, struct hdr_field **h)
 Looks for the First Via header and returns its body.
via_body * cscf_get_last_via (struct sip_msg *msg)
 Looks for the Last Via header and returns it.
via_body * cscf_get_ue_via (struct sip_msg *msg)
 Looks for the UE Via in First Via header if its a request or in the last if its a response and returns its body.
str cscf_get_realm (struct sip_msg *msg)
 Looks for the realm parameter in the Authorization header and returns its value.
str cscf_get_realm_from_uri (str uri)
 Extracts the realm from a SIP/TEL URI.
int cscf_get_p_associated_uri (struct sip_msg *msg, str **public_id, int *public_id_cnt)
 Returns the content of the P-Associated-URI header Public_id is pkg_alloced and should be later freed.
int cscf_get_first_p_associated_uri (struct sip_msg *msg, str *public_id)
 Returns the first entry of the P-Associated-URI header.
name_addr_t cscf_get_preferred_identity (struct sip_msg *msg, struct hdr_field **h)
 Looks for the P-Preferred-Identity header and extracts its content.
hdr_field * cscf_get_next_route (struct sip_msg *msg, struct hdr_field *start)
 Returns the next route.
int cscf_is_myself (str uri)
 Returns if the uri is of myself.
str cscf_get_content_type (struct sip_msg *msg)
 Looks for the Content-Type header and extracts its content.
int cscf_get_content_len (struct sip_msg *msg)
 Looks for the Content-length header and extracts its content.
str * cscf_get_service_route (struct sip_msg *msg, int *size)
 Returns the content of the Service-Route header.
int cscf_get_originating_contact (struct sip_msg *msg, str *host, int *port, int *transport)
 Returns the originating contact.
int cscf_get_terminating_contact (struct sip_msg *msg, str *host, int *port, int *transport)
 Returns the terminating contact.
int cscf_get_terminating_identity (struct sip_msg *msg, str *uri)
 Returns the terminating contact.
int cscf_add_p_charging_vector (struct sip_msg *msg)
 Inserts the P-Charging-Vector header P-Charging-Vector:.
str cscf_get_last_via_sent_by (struct sip_msg *msg)
 Get the sent-by parameter of the last Via header in the message.
str cscf_get_last_via_received (struct sip_msg *msg)
 Get the received parameter of the last Via header in the message.
int cscf_get_from_tag (struct sip_msg *msg, str *tag)
 Get the from tag.
int cscf_get_to_tag (struct sip_msg *msg, str *tag)
 Get the to tag.
int cscf_get_from_uri (struct sip_msg *msg, str *local_uri)
 Get the local uri from the From header.
int cscf_get_to_uri (struct sip_msg *msg, str *local_uri)
 Get the local uri from the To header.


Function Documentation

int cscf_add_header_first ( struct sip_msg *  msg,
str *  hdr,
int  type 
)

Adds a header to the message as the first one in the message.

Parameters:
msg - the message to add a header to
content - the str containing the new header
Returns:
1 on succes, 0 on failure

Definition at line 128 of file sip.c.

00129 {
00130     struct hdr_field *first;
00131     struct lump* anchor,*l;
00132 
00133     first = msg->headers;
00134     anchor = anchor_lump(msg, first->name.s - msg->buf, 0 , 0 );
00135 
00136     if (anchor == NULL) {
00137         LOG(L_ERR, "ERR:"M_NAME":cscf_add_header_first: anchor_lump failed\n");
00138         return 0;
00139     }
00140 
00141     if (!(l=insert_new_lump_before(anchor, hdr->s,hdr->len,type))){
00142         LOG(L_ERR, "ERR:"M_NAME":cscf_add_header_first: error creating lump for header\n" );
00143         return 0;
00144     }   
00145     return 1;
00146 }

int cscf_add_header ( struct sip_msg *  msg,
str *  hdr,
int  type 
)

Adds a header to the message.

Parameters:
msg - the message to add a header to
content - the str containing the new header
Returns:
1 on succes, 0 on failure

Definition at line 154 of file sip.c.

00155 {
00156     struct hdr_field *last;
00157     struct lump* anchor;
00158     last = msg->headers;
00159     while(last->next) 
00160         last = last->next;
00161     anchor = anchor_lump(msg, last->name.s + last->len - msg->buf, 0 , 0);
00162     if (anchor == NULL) {
00163         LOG(L_ERR, "ERR:"M_NAME":cscf_add_header_first: anchor_lump failed\n");
00164         return 0;
00165     }
00166 
00167     if (!insert_new_lump_after(anchor, hdr->s,hdr->len,type)){
00168         LOG(L_ERR, "ERR:"M_NAME":cscf_add_header_first: error creting lump for header\n" );
00169         return 0;
00170     }   
00171     return 1;
00172 }

int cscf_add_header_rpl ( struct sip_msg *  msg,
str *  hdr 
)

Adds a header to the reply message.

Parameters:
msg - the request to add a header to its reply
content - the str containing the new header
Returns:
1 on succes, 0 on failure

Definition at line 180 of file sip.c.

00181 {
00182     if (add_lump_rpl( msg, hdr->s, hdr->len, LUMP_RPL_HDR)==0) {
00183         LOG(L_ERR, "ERR:"M_NAME":cscf_add_header_rpl: Can't add header <%.*s>\n",
00184             hdr->len,hdr->s);
00185         return 0;
00186     }
00187     return 1;
00188 }

int cscf_add_contact ( struct sip_msg *  msg,
str  uri,
int  expires 
)

str cscf_get_private_identity ( struct sip_msg *  msg,
str  realm 
)

Returns the Private Identity extracted from the Authorization header.

If none found there takes the SIP URI in To without the "sip:" prefix

Todo:
  • remove the fallback case to the To header
Parameters:
msg - the SIP message
realm - the realm to match in an Authorization header
Returns:
the str containing the private id, no mem dup

Definition at line 200 of file sip.c.

00201 {
00202     str pi={0,0};
00203     struct hdr_field* h=0;
00204     int ret,i;
00205 
00206     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00207         LOG(L_ERR,"ERR:"M_NAME":cscf_get_private_identity: Error parsing until header Authorization: \n");
00208         return pi;
00209     }
00210 
00211     if (!msg->authorization){
00212         LOG(L_ERR, "ERR:"M_NAME":cscf_get_private_identity: Message does not contain Authorization header.\n");
00213         goto fallback;
00214     }
00215 
00216     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00217     if (ret < 0) {
00218         LOG(L_ERR, "ERR:"M_NAME":cscf_get_private_identity: Error while looking for credentials.\n");
00219         goto fallback;
00220     } else 
00221         if (ret > 0) {
00222             LOG(L_ERR, "ERR:"M_NAME":cscf_get_private_identity: No credentials for this realm found.\n");
00223             goto fallback;
00224         }
00225     
00226     if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
00227 
00228     goto done;
00229         
00230 fallback:
00231     LOG(L_INFO,"INF:"M_NAME":cscf_get_private_identity: Falling back to private_id=stripped(public_id)\n"
00232         "-> Message did not contain a valid Authorization Header!!! This fallback is deprecated outside Early-IMS or NASS-Bundled!\n"); 
00233     pi = cscf_get_public_identity(msg);
00234     if (pi.len>4&&strncasecmp(pi.s,"sip:",4)==0) {pi.s+=4;pi.len-=4;}
00235     for(i=0;i<pi.len;i++)
00236         if (pi.s[i]==';') {
00237             pi.len=i;
00238             break;
00239         }
00240 done:   
00241     LOG(L_DBG,"DBG:"M_NAME":cscf_get_private_identity: <%.*s> \n",
00242         pi.len,pi.s);
00243     return pi;  
00244 }

str cscf_get_public_identity ( struct sip_msg *  msg  ) 

Returns the Public Identity extracted from the To header.

Parameters:
msg - the SIP message
Returns:
the str containing the public id, no mem dup

Definition at line 523 of file sip.c.

00524 {
00525     str pu={0,0};
00526     struct to_body *to;
00527     
00528     if (parse_headers(msg,HDR_TO_F,0)!=0) {
00529         LOG(L_ERR,"ERR:"M_NAME":cscf_get_public_identity: Error parsing until header To: \n");
00530         return pu;
00531     }
00532     
00533     if ( get_to(msg) == NULL ) {
00534         to = (struct to_body*) pkg_malloc(sizeof(struct to_body));
00535         parse_to( msg->to->body.s, msg->to->body.s + msg->to->body.len, to );
00536         msg->to->parsed = to;
00537     }
00538         else to=(struct to_body *) msg->to->parsed;
00539     
00540     pu = to->uri;
00541     
00542     LOG(L_DBG,"DBG:"M_NAME":cscf_get_public_identity: <%.*s> \n",
00543         pu.len,pu.s);
00544     return pu;
00545 }

int cscf_get_expires_hdr ( struct sip_msg *  msg  ) 

Returns the expires value from the Expires header in the message.

It searches into the Expires header and if not found returns -1

Parameters:
msg - the SIP message, if available
Returns:
the value of the expire or -1 if not found

Definition at line 389 of file sip.c.

00389                                               {
00390     exp_body_t *exp;
00391     int expires;
00392     if (!msg) return -1;
00393     /*first search in Expires header */         
00394     if (parse_headers(msg,HDR_EXPIRES_F,0)!=0) {
00395         LOG(L_ERR,"ERR:"M_NAME":cscf_get_expires_hdr: Error parsing until header EXPIRES: \n");
00396         return -1;
00397     }
00398     if (msg->expires){
00399         if (!msg->expires->parsed) {
00400                 parse_expires(msg->expires);
00401         }
00402         if (msg->expires->parsed) {
00403                 exp = (exp_body_t*) msg->expires->parsed;
00404                 if (exp->valid) {
00405                         expires = exp->val;
00406                         LOG(L_DBG,"DBG:"M_NAME":cscf_get_expires_hdr: <%d> \n",expires);
00407                         return expires;
00408                 }
00409         }
00410     }
00411     
00412     return -1;
00413 }

int cscf_get_max_expires ( struct sip_msg *  msg  ) 

Returns the expires value from the message.

First it searches into the Expires header and if not found it also looks into the expires parameter in the contact header

Parameters:
msg - the SIP message
Returns:
the value of the expire or the default 3600 if none found

Definition at line 421 of file sip.c.

00422 {
00423     unsigned int exp;
00424     int max_expires = -1;
00425     struct hdr_field *h;
00426     contact_t *c;
00427     /*first search in Expires header */
00428     max_expires = cscf_get_expires_hdr(msg);
00429     
00430     cscf_parse_contacts(msg);
00431     for(h=msg->contact;h;h=h->next){
00432         if (h->type==HDR_CONTACT_T && h->parsed) {
00433             for(c=((contact_body_t *) h->parsed)->contacts;c;c=c->next){
00434                 if(c->expires){
00435                     if (!str2int(&(c->expires->body), (unsigned int*)&exp) && (int)exp>max_expires) max_expires = exp;
00436                 }
00437             }
00438         }   
00439     }
00440     LOG(L_DBG,"DBG:"M_NAME":cscf_get_max_expires: <%d> \n",max_expires);
00441     return max_expires;
00442 }

str cscf_get_public_identity_from_requri ( struct sip_msg *  msg  ) 

Get the Public Identity from the Request URI of the message.

Parameters:
msg - the SIP message
Returns:
the public identity

Definition at line 272 of file sip.c.

00273 {
00274     str pu={0,0};
00275     int i;
00276     if (msg->first_line.type!=SIP_REQUEST) {
00277         LOG(L_INFO,"ERR:"M_NAME":cscf_get_public_identity_from_requri: This ain't a request \n");   
00278         return pu;
00279     }
00280     if (parse_sip_msg_uri(msg)<0){
00281         LOG(L_ERR,"ERR:"M_NAME":cscf_get_public_identity_from_requri: Error parsing requesturi \n");    
00282         return pu;
00283     }
00284     pu = msg->first_line.u.request.uri;
00285     for(i=0;i<pu.len&& pu.s[i]!=';'&&pu.s[i]!='?';i++);
00286     pu.len = i;
00287     
00288     LOG(L_DBG,"DBG:"M_NAME":cscf_get_public_identity_from_requri: <%.*s> \n",
00289         pu.len,pu.s);   
00290     return pu;
00291 }

struct sip_msg* cscf_get_request ( unsigned int  hash,
unsigned int  label 
) [read]

Retrieves the SIP request that generated a diameter transaction.

Parameters:
hash - the tm hash value for this request
label - the tm label value for this request
Returns:
the SIP request

Definition at line 392 of file sip.c.

00393 {
00394     struct cell *c;
00395     if (tmb.t_lookup_ident(&c,hash,label)<0){
00396         LOG(L_INFO,"INF:"M_NAME":Cx_UAA_timeout: No transaction found for %u %u\n",
00397             hash,label);
00398         return 0;
00399     }
00400     return c->uas.request;
00401 }

int cscf_get_integrity_protected ( struct sip_msg *  msg,
str  realm 
)

Returns if the SIP message is integrity protected.

Looks for the integrity-protected field in the in the Authorization header.

Todo:
  • optimize it by including the integrity protected parameter in the digest parsed structures - will change the core though...
Parameters:
msg - the SIP message
realm - the realm to match in the authorization
Returns:
1 if integrity protected is set to yes, 0 if it is not set to yes or is missing

Definition at line 414 of file sip.c.

00415 {
00416     struct hdr_field* h=0;
00417     int ret,i,j;
00418 
00419     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00420         LOG(L_ERR,"ERR:"M_NAME":cscf_get_integrity_protected: Error parsing until header Authorization: \n");
00421         return 0;
00422     }
00423 
00424     if (!msg->authorization){
00425         LOG(L_ERR, "ERR:"M_NAME":cscf_get_integrity_protected: Message does not contain Authorization header.\n");
00426         return 0;
00427     }
00428 
00429     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00430     if (ret < 0) {
00431         LOG(L_ERR, "ERR:"M_NAME":cscf_get_integrity_protected: Error while looking for credentials.\n");
00432         return 0;
00433     } else 
00434         if (ret > 0) {
00435             LOG(L_ERR, "ERR:"M_NAME":cscf_get_integrity_protected: No credentials for this realm found.\n");
00436             return 0;
00437         }
00438     
00439     if (h) {
00440         for(i=0;i<h->body.len-s_ip.len;i++)
00441             if (strncasecmp(h->body.s+i,s_ip.s,s_ip.len)==0)
00442                 for(j=i+s_ip.len;j<h->body.len;j++){
00443                     if (h->body.s[j]=='y' || h->body.s[j]=='Y') return 1;
00444                     if (h->body.s[j]==' ') return 0;
00445                 }           
00446     }
00447     
00448     return 0;
00449 }

int cscf_get_transaction ( struct sip_msg *  msg,
unsigned int *  hash,
unsigned int *  label 
)

Returns the tm transaction identifiers.

If no transaction, then creates one

Parameters:
msg - the SIP message
hash - where to write the hash
label - where to write the label
Returns:
1 on success and creation of a new transaction, 0 if transaction existed, -1 if failure

Definition at line 344 of file sip.c.

00345 {
00346     
00347     if (isc_tmb.t_get_trans_ident(msg,hash,label)<0){   
00348         LOG(L_DBG,"DBG:"M_NAME":cscf_get_transaction: SIP message without transaction. OK - first request\n");
00349         if (isc_tmb.t_newtran(msg)<0) 
00350             LOG(L_INFO,"INF:"M_NAME":cscf_get_transaction: Failed creating SIP transaction\n");
00351         if (isc_tmb.t_get_trans_ident(msg,hash,label)<0){   
00352             LOG(L_INFO,"INF:"M_NAME":cscf_get_transaction: SIP message still without transaction\n");
00353             return -1;
00354         }else {
00355             LOG(L_DBG,"DBG:"M_NAME":cscf_get_transaction: New SIP message transaction %u %u\n",
00356                 *hash,*label);
00357             return 1;
00358         }                       
00359     }else {
00360         LOG(L_INFO,"INF:"M_NAME":cscf_get_transaction: Transaction %u %u exists."
00361         "Retransmission?\n",*hash,*label);
00362         return 0;
00363     }
00364 }

int cscf_reply_transactional ( struct sip_msg *  msg,
int  code,
char *  text 
)

Transactional SIP response - tries to create a transaction if none found.

Parameters:
msg - message to reply to
code - the Status-code for the response
text - the Reason-Phrase for the response
Returns:
the tmb.t_repy() result

Definition at line 490 of file sip.c.

00491 {
00492     unsigned int hash,label;
00493     if (tmb.t_get_trans_ident(msg,&hash,&label)<0){ 
00494     
00495         if (tmb.t_newtran(msg)<0) 
00496             LOG(L_INFO,"INF:"M_NAME":cscf_get_transaction: Failed creating SIP transaction\n");
00497     }
00498     return tmb.t_reply(msg,code,text);
00499 }

str cscf_get_auts ( struct sip_msg *  msg,
str  realm 
)

Looks for the auts parameter in the Authorization header and returns its value.

Parameters:
msg - the SIP message
realm - realm to match the right Authorization header
Returns:
the auts value or an empty string if not found

Definition at line 507 of file sip.c.

00508 {
00509     str name={"auts=\"",6};
00510     struct hdr_field* h=0;
00511     int i,ret;
00512     str auts={0,0};
00513 
00514     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00515         LOG(L_ERR,"ERR:"M_NAME":cscf_get_auts: Error parsing until header Authorization: \n");
00516         return auts;
00517     }
00518 
00519     if (!msg->authorization){
00520         LOG(L_ERR, "ERR:"M_NAME":cscf_get_auts: Message does not contain Authorization header.\n");
00521         return auts;
00522     }
00523 
00524     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00525     if (ret < 0) {
00526         LOG(L_ERR, "ERR:"M_NAME":cscf_get_auts: Error while looking for credentials.\n");
00527         return auts;
00528     } else 
00529         if (ret > 0) {
00530             LOG(L_ERR, "ERR:"M_NAME":cscf_get_auts: No credentials for this realm found.\n");
00531             return auts;
00532         }
00533     
00534     if (h) {
00535         for(i=0;i<h->body.len-name.len;i++)
00536             if (strncasecmp(h->body.s+i,name.s,name.len)==0){
00537                 auts.s = h->body.s+i+name.len;
00538                 while(i+auts.len<h->body.len && auts.s[auts.len]!='\"')
00539                     auts.len++;
00540             }
00541     }
00542     
00543     return auts;    
00544 }

str cscf_get_nonce ( struct sip_msg *  msg,
str  realm 
)

Looks for the nonce parameter in the Authorization header and returns its value.

Parameters:
msg - the SIP message
realm - realm to match the right Authorization header
Returns:
the nonce or an empty string if none found

Definition at line 552 of file sip.c.

00553 {
00554     struct hdr_field* h=0;
00555     int ret;
00556     str nonce={0,0};
00557 
00558     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00559         LOG(L_ERR,"ERR:"M_NAME":cscf_get_nonce: Error parsing until header Authorization: \n");
00560         return nonce;
00561     }
00562 
00563     if (!msg->authorization){
00564         LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: Message does not contain Authorization header.\n");
00565         return nonce;
00566     }
00567 
00568     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00569     if (ret < 0) {
00570         LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: Error while looking for credentials.\n");
00571         return nonce;
00572     } else 
00573         if (ret > 0) {
00574             LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: No credentials for this realm found.\n");
00575             return nonce;
00576         }
00577     
00578     if (h&&h->parsed) {
00579         nonce = ((auth_body_t*)h->parsed)->digest.nonce;
00580     }
00581     
00582     return nonce;   
00583 }

str cscf_get_algorithm ( struct sip_msg *  msg,
str  realm 
)

Looks for the algorithm parameter in the Authorization header and returns its value.

Parameters:
msg - the SIP message
realm - realm to match the right Authorization header
Returns:
the algorithm or an empty string if not found

Definition at line 591 of file sip.c.

00592 {
00593     struct hdr_field* h=0;
00594     int ret;
00595     str alg={0,0};
00596 
00597     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00598         LOG(L_ERR,"ERR:"M_NAME":cscf_get_algorithm: Error parsing until header Authorization: \n");
00599         return alg;
00600     }
00601 
00602     if (!msg->authorization){
00603         LOG(L_ERR, "ERR:"M_NAME":cscf_get_algorithm: Message does not contain Authorization header.\n");
00604         return alg;
00605     }
00606 
00607     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00608     if (ret < 0) {
00609         LOG(L_ERR, "ERR:"M_NAME":cscf_get_algorithm: Error while looking for credentials.\n");
00610         return alg;
00611     } else 
00612         if (ret > 0) {
00613             LOG(L_ERR, "ERR:"M_NAME":cscf_get_algorithm: No credentials for this realm found.\n");
00614             return alg;
00615         }
00616     
00617     if (h&&h->parsed) {
00618         alg = ((auth_body_t*)h->parsed)->digest.alg.alg_str;
00619     }
00620     return alg; 
00621 }

str cscf_get_digest_uri ( struct sip_msg *  msg,
str  realm 
)

Looks for the uri parameter in the Authorization header and returns its value.

Parameters:
msg - the SIP message
realm - realm to match the right Authorization header
Returns:
the uri in the digest

Definition at line 629 of file sip.c.

00630 {
00631     struct hdr_field* h=0;
00632     int ret;
00633     str uri={0,0};
00634 
00635     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00636         LOG(L_ERR,"ERR:"M_NAME":cscf_get_digest_uri: Error parsing until header Authorization: \n");
00637         return uri;
00638     }
00639 
00640     if (!msg->authorization){
00641         LOG(L_ERR, "ERR:"M_NAME":cscf_get_digest_uri: Message does not contain Authorization header.\n");
00642         return uri;
00643     }
00644 
00645     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00646     if (ret < 0) {
00647         LOG(L_ERR, "ERR:"M_NAME":cscf_get_digest_uri: Error while looking for credentials.\n");
00648         return uri;
00649     } else 
00650         if (ret > 0) {
00651             LOG(L_ERR, "ERR:"M_NAME":cscf_get_digest_uri: No credentials for this realm found.\n");
00652             return uri;
00653         }
00654     
00655     if (h&&h->parsed) {
00656         uri = ((auth_body_t*)h->parsed)->digest.uri;
00657     }
00658     return uri; 
00659 }

int cscf_get_nonce_response ( struct sip_msg *  msg,
str  realm,
str *  nonce,
str *  response,
enum qop_type *  qop,
str *  qop_str,
str *  nc,
str *  cnonce,
str *  uri 
)

Looks for the nonce and response parameters in the Authorization header and returns them.

Parameters:
msg - the SIP message
realm - realm to match the right Authorization header
nonce - param to fill with the nonce found
response - param to fill with the response
Returns:
1 if found, 0 if not

Definition at line 669 of file sip.c.

00671 {
00672     struct hdr_field* h=0;
00673     int ret;
00674 
00675     if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
00676         LOG(L_ERR,"ERR:"M_NAME":cscf_get_nonce: Error parsing until header Authorization: \n");
00677         return 0;
00678     }
00679 
00680     if (!msg->authorization){
00681         LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: Message does not contain Authorization header.\n");
00682         return 0;
00683     }
00684 
00685     ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
00686     if (ret < 0) {
00687         LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: Error while looking for credentials.\n");
00688         return 0;
00689     } else 
00690         if (ret > 0) {
00691             LOG(L_ERR, "ERR:"M_NAME":cscf_get_nonce: No credentials for this realm found.\n");
00692             return 0;
00693         }
00694     
00695     if (h&&h->parsed) {
00696         if (nonce) *nonce = ((auth_body_t*)h->parsed)->digest.nonce;
00697         if (response) *response = ((auth_body_t*)h->parsed)->digest.response;
00698         if (qop) *qop = ((auth_body_t*)h->parsed)->digest.qop.qop_parsed;
00699         if (qop_str) *qop_str = ((auth_body_t*)h->parsed)->digest.qop.qop_str;
00700         if (nc) *nc = ((auth_body_t*)h->parsed)->digest.nc;
00701         if (cnonce) *cnonce = ((auth_body_t*)h->parsed)->digest.cnonce;
00702         if (uri) *uri = ((auth_body_t*)h->parsed)->digest.uri;
00703     }
00704     
00705     return 1;   
00706 }

str cscf_get_user_agent ( struct sip_msg *  msg  ) 

Looks for the User-Agent header and extracts its content.

Parameters:
msg - the sip message
Returns:
the user agent string, or ua_dummy if not found, or ua_nomsg if msg was NULL

Definition at line 716 of file sip.c.

00717 {
00718     str ua;
00719     if (!msg) return ua_nomsg;
00720     ua.len = 0;
00721     if (parse_headers(msg, HDR_USERAGENT_F, 0) != -1 && msg->user_agent &&
00722         msg->user_agent->body.len > 0) 
00723     {
00724         ua.len = msg->user_agent->body.len;
00725         ua.s = msg->user_agent->body.s;
00726     }
00727     if (ua.len == 0) ua=ua_dummy;
00728     return ua;
00729 }

contact_body_t* cscf_parse_contacts ( struct sip_msg *  msg  ) 

Parses all the contact headers.

Parameters:
msg - the SIP message
Returns:
the first contact_body

Definition at line 449 of file sip.c.

00450 {
00451     struct hdr_field* ptr;
00452     if (!msg) return 0;
00453     
00454     if (parse_headers(msg, HDR_EOH_F, 0)<0){
00455         LOG(L_ERR,"ERR:"M_NAME":cscf_parse_contacts: Error parsing headers \n");
00456         return 0;
00457     }
00458     if (msg->contact) {
00459         ptr = msg->contact;
00460         while(ptr) {
00461             if (ptr->type == HDR_CONTACT_T) {
00462                 if (msg->contact->parsed==0){                   
00463                     if (parse_contact(ptr)<0){
00464                         LOG(L_ERR,"ERR:"M_NAME":cscf_parse_contacts: error parsing contacts [%.*s]\n",
00465                             ptr->body.len,ptr->body.s); 
00466                     }
00467                 }
00468             }
00469             ptr = ptr->next;
00470         }
00471     }
00472     if (!msg->contact) return 0;
00473     return msg->contact->parsed;
00474 }

str cscf_get_path ( struct sip_msg *  msg  ) 

Retrieve a list of concatenated contents of Path headers found in the message.

Parameters:
msg - the SIP message containing the Path headers
Returns:
pkg mem allocated str with the headers values separated by ','

Definition at line 767 of file sip.c.

00768 {
00769     str path={0,0};
00770     struct hdr_field *h;
00771     if (!msg) return path;
00772     if (parse_headers(msg, HDR_EOH_F, 0)<0){
00773         LOG(L_ERR,"ERR:"M_NAME":cscf_get_path: error parsing headers\n");
00774         return path;
00775     }
00776     h = msg->headers;
00777     while(h){
00778         if (h->name.len==4 &&
00779             strncasecmp(h->name.s,"Path",4)==0){
00780                 path.len+=h->body.len+1;
00781             }
00782         h = h->next;
00783     }
00784     path.s = pkg_malloc(path.len);
00785     if (!path.s){
00786         LOG(L_ERR,"ERR:"M_NAME":cscf_get_path: error allocating %d bytes\n",
00787             path.len);
00788         path.len=0;
00789         return path;
00790     }
00791     h = msg->headers;
00792     path.len=0;
00793     while(h){
00794         if (h->name.len==4 &&
00795             strncasecmp(h->name.s,"Path",4)==0){
00796                 if (path.len) path.s[path.len++]=',';
00797                 memcpy(path.s+path.len,h->body.s,h->body.len);
00798                 path.len+=h->body.len;
00799             }
00800         h = h->next;
00801     }
00802 
00803     return path;
00804 }

str cscf_get_event ( struct sip_msg *  msg  ) 

Looks for the Event header and extracts its content.

Parameters:
msg - the sip message
Returns:
the string event value or an empty string if none found

Definition at line 811 of file sip.c.

00812 {
00813     str e={0,0};
00814     if (!msg) return e;
00815     if (parse_headers(msg, HDR_EVENT_F, 0) != -1 && msg->event &&
00816         msg->event->body.len > 0) 
00817     {
00818         e.len = msg->event->body.len;
00819         e.s = msg->event->body.s;
00820     }
00821     return e;
00822 }

str cscf_get_asserted_identity ( struct sip_msg *  msg  ) 

Looks for the P-Asserted-Identity header and extracts its content.

Parameters:
msg - the sip message
Returns:
the asserted identity

Definition at line 162 of file sip.c.

00163 {
00164     name_addr_t id;
00165     struct hdr_field *h;
00166     rr_t *r;
00167     memset(&id,0,sizeof(name_addr_t));
00168     if (!msg) return id.uri;
00169     if (parse_headers(msg, HDR_EOH_F, 0)<0) {
00170         return id.uri;
00171     }
00172     h = msg->headers;
00173     while(h)
00174     {
00175         if (h->name.len == s_asserted_identity.len  &&
00176             strncasecmp(h->name.s,s_asserted_identity.s,s_asserted_identity.len)==0)
00177         {
00178             if (parse_rr(h)<0){
00179                 //This might be an old client
00180                 LOG(L_CRIT,"WARN:"M_NAME":cscf_get_asserted_identity: P-Asserted-Identity header must contain a Nameaddr!!! Fix the client!\n");
00181                 id.name.s = h->body.s;
00182                 id.name.len = 0;
00183                 id.len = h->body.len;
00184                 id.uri = h->body;
00185                 while(id.uri.len && (id.uri.s[0]==' ' || id.uri.s[0]=='\t' || id.uri.s[0]=='<')){
00186                     id.uri.s = id.uri.s+1;
00187                     id.uri.len --;
00188                 }
00189                 while(id.uri.len && (id.uri.s[id.uri.len-1]==' ' || id.uri.s[id.uri.len-1]=='\t' || id.uri.s[id.uri.len-1]=='>')){
00190                     id.uri.len--;
00191                 }
00192                 return id.uri;  
00193             }
00194             r = (rr_t*) h->parsed;
00195             id = r->nameaddr;           
00196             free_rr(&r);
00197             h->parsed=r;
00198             //LOG(L_RIT,"%.*s",id.uri.len,id.uri.s);
00199             return id.uri;
00200         }
00201         h = h->next;
00202     }
00203     return id.uri;
00204 }

str cscf_get_asserted_identity_domain ( struct sip_msg *  msg  ) 

Looks for the P-Asserted-Identity header and extracts the domain inside the uri.

Parameters:
msg - the sip message
Returns:
the domain in the asserted identity

Definition at line 880 of file sip.c.

00881 {
00882     struct sip_uri puri;
00883     str uri = cscf_get_asserted_identity(msg);
00884     if (!uri.len) return uri;
00885     
00886     if (parse_uri(uri.s,uri.len,&puri)<0){
00887         LOG(L_ERR,"ERR:"M_NAME":cscf_get_asserted_identity_domain: error parsing uri <%.*s>\n",
00888             uri.len,uri.s);
00889         uri.len=0;uri.s=0;
00890         return uri;         
00891     }
00892     return puri.host;
00893 }

str cscf_get_contact ( struct sip_msg *  msg  ) 

Looks for the Contact header and extracts its con