Best way to iterate over headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/23/2016 06:46 PM, Mike Roberts wrote:
> I want to copy the headers I receive in an INVITE (or other message) into a
> key value store. Is there an easy way to iterate over the headers in a
> message? Or at least the headers that can be represented as a
> pjsip_generic_string_hdr? The best method I can find so far would be to
> loop over the body of the message and manually parse the headers myself.
>

I didn't test it, but...
In the on_incoming_call you can get the message object:

void on_incoming_call( ..., ..., pjsip_rx_data *rdata )
{
     pjsip_msg* msg = rdata->msg_info.msg;
     char value[ 512 ] = { 0 };
     const pjsip_hdr *hdr=(const pjsip_hdr*)msg->hdr.next, *end=&msg->hdr;

     for (; hdr!=end; hdr = hdr->next)
     {
         /* write header value to buffer */
         hdr->vptr->print_on( hdr, value, 512 );

         /* store header in database or whatever... */
         store_header( hdr->name, value );
     }
}

Like I said, I didn't test it but merely wrote this looking at the code 
in functions like pjsip_msg_find_hdr*
If somebody else has a better way of doing this, please share it here.

Regards,
Andreas




[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux