PjSip Add multiple headers

混江龙づ霸主 提交于 2019-12-21 23:20:51

问题


I am developing a voip app for I-phone using pjsip as sip stack, and i want to add custom headers am able to add, but only one gets added, am stuck i dont under stand whats wrong, below is my code snippet

pj_status_t status = PJ_SUCCESS;
    pj_str_t pj_uri;

    pjsua_msg_data msg_data;
    pjsip_generic_string_hdr subject;
    pj_str_t hvalue, hname;

    pj_uri = pj_str((char *)uri);


    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_init2 (&subject, &hname, &hvalue);
        pj_list_push_back(&msg_data.hdr_list, &subject);

    }


    status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);

回答1:


Again I end up answering my won question.

Ill put up the code which wrks

pj_caching_pool cp;
  pj_pool_t *pool;
  pj_status_t status = PJ_SUCCESS;
  pj_str_t pj_uri;

  pjsua_msg_data msg_data;
  pjsua_msg_data_init(&msg_data);


  pj_uri = pj_str((char *)uri);


  pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
  pool= pj_pool_create(&cp.factory, "header", 1000, 1000, NULL);

  for(NSString *key in [headers allKeys]){

    NSLog(@"Call.m key value in call %@,%@",key,[headers objectForKey:key] );
    pj_str_t hname = pj_str((char *)[key UTF8String]);
    char * headerValue=(char *)[(NSString *)[headers objectForKey:key] UTF8String];
    pj_str_t hvalue = pj_str(headerValue);
    pjsip_generic_string_hdr* add_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
    pj_list_push_back(&msg_data.hdr_list, add_hdr);
  }
  status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);
  pj_pool_release(pool);



回答2:


Not an expert with objective-c. Some basics

Always initialize pjsua_msg_data_init(&msg_data); before for loop instead of in the loop

change pjsip_generic_string_hdr subject; to an array of object



来源:https://stackoverflow.com/questions/18309010/pjsip-add-multiple-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!