Send custom headers in invite

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

 



If you read the documentation *carefully* (and examine the code 
implementing pjsip_generic_string_hdr_init2() )
you'll find out, that this function only creates a reference to the 
key-value pair.
Thus, if you call the function a second time with the same string_hdr 
reference, you'll overwrite the previous reference.
What you're basically doing is adding the same header structure over and 
over again.

I know about this because I had the exact same problem.
My solution is to explicitly allocate a header structure for each header 
that I want to add:

SipHeaderMap::const_iterator hit( additional_header.begin() );
     for(; additional_header.end() != hit; ++hit )
     {
         PLOG_NOTICE( "adding additional SIP header: %s = %s",
                      hit->first.c_str(),
                      hit->second.c_str() );
         pj_str_t add_hdr_name;
         pj_str_t add_hdr_value;

         pj_cstr( &add_hdr_name, hit->first.c_str() );
         pj_cstr( &add_hdr_value, hit->second.c_str() );

         pjsip_generic_string_hdr* add_hdr = 
pjsip_generic_string_hdr_create( PeerRef.privatePool(), &add_hdr_name, 
&add_hdr_value );
         pj_list_push_back(&msg_data.hdr_list, add_hdr);
      }

Of course if you do it like that, you'll have to have a memory pool to 
allocate from.
In my case every call creates its own private pool, so the pool is 
released as soon as the call is gone.

Regards,
Andy


On 09/04/2013 05:09 PM, Rohit Singh wrote:
> sorry for bad format  ill post the code again
>
> pjsua_msg_data msg_data;
>      pjsip_generic_string_hdr subject;
>      pj_str_t hvalue, hname;
>
>
>   for( /*  all keys and value */){
>
>         pjsua_msg_data_init(&msg_data);
>         hname = // key
>         char * headerValue = //value
>         hvalue = pj_str(headerValue);
>         pjsip_generic_string_hdr_init2 (&subject, &hname, &hvalue);
>
>          pj_list_push_back(&msg_data.hdr_list, &subject);
>
>
>      }
> when i log i get all keys and values but in case of headers i only get the
> last one
>
>
>
>
>
> On Wed, Sep 4, 2013 at 8:27 PM, Rohit Singh <soulgamebits at gmail.com> wrote:
>
>> Hi guys,
>> i am developing an ios app using pjsip as sip stack
>> i am trying to send multiple custom headers in my invite, but the code
>> adds  only the last one
>>
>> i am looping this code
>> like
>>
>>
>>    pjsua_msg_data msg_data;
>>      pjsip_generic_string_hdr subject;
>>
>>      pj_str_t hvalue, hname;
>>
>>       for(NSString *key in [headers allKeys]){
>>
>>
>>
>>          NSLog(@"Call.m key value in call %@,%@",key,[headers
>> objectForKey:key] );
>>
>>          pjsua_msg_data_init(&msg_data);
>>
>>
>>
>>          hname = pj_str((char *)[key UTF8String]);
>>
>>
>>
>>          char * headerValue=(char *)[(NSString *)[headers objectForKey:key]
>> UTF8String];
>>
>>
>>
>>          hvalue = pj_str(headerValue);
>>
>>
>>
>> //        pjsip_generic_string_hdr_create(pool1, &hname, &hvalue);
>>
>>          pjsip_generic_string_hdr_init2 (&subject, &hname, &hvalue);
>>
>>
>>
>>          pj_list_push_back(&msg_data.hdr_list, &subject);
>>
>>
>>      }
>>
>
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org




[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