[pjsip] Header initialization/validation in pjlib

Benny Prijono bennylp at pjsip.org
Tue Nov 13 10:52:20 EST 2007


Alexander Agranovsky wrote:
> Does core/dialog/invite layers contain methods for initializing and  
> validating a common header (To:/From:/Contact:) from a string?
> 
> E.g. if I just do (pseudocode):
> 
> 	                pHeader = (pjsip_hdr*)pjsip_generic_string_hdr_create 
> (pTxData->pool,
> 							            "Contact",
> 							            "notvalid");
>   	                pjsip_msg_add_hdr(pTxData->msg, pHeader);
> 
> The message goes out with:
> 
> Contact: notvalid
> 
> What's the best way, given a string, to assign it to a header, but  
> make sure is valid at the same time?

You can use the parsing function to create the appropriate instance 
of the header, e.g. (pseudocode):

   pjsip_contact_hdr *hdr;
   char *hvalue = "<sip:user at host>";

   hdr = pjsip_parse_hdr(tdata->pool, "Contact", hvalue,
                         strlen(hvalue), NULL);
   if (hdr == NULL)
       // not valid header value

Note that hvalue MUST be null terminated (i.e. the current doxygen 
comment/documentation is wrong as it doesn't mention this).

cheers,
  -benny


> Thanks,
> Alex





More information about the pjsip mailing list