ladendirekt / pjsip4net

A wrapper library exposing the pjsip library to the .NET world in a OO-friendly way.
71 stars 42 forks source link

How to add header in msg_body #102

Closed ujavaid1985 closed 5 years ago

ujavaid1985 commented 5 years ago

Describe the bug I want to sending Call Redirection (3xx) Response in PJSUA-LIB. I have read the articles and its easy step; just use pjsua_call_hangup() and give the new targets in Contact header in msg_data parameter. I want to send msg_data from C# code but unable to send it right. I can send msg_body but can't send hdr_list right.

Sample Java Code Following is the code people used in java to send header

_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_hangup(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);

My Code I

        pjsua_msg_data msg = new pjsua_msg_data();
        pjsip_generic_string_hdr hdr = new pjsip_generic_string_hdr();

        hdr.type = pjsip_hdr_e.PJSIP_H_CONTACT;
        hdr.name = new pj_str_t("Contact");
        hdr.sname = hdr.name;
        hdr.hvalue = new pj_str_t("<sip:250@10.2.30.100:5059>;q=1.0");

        PJSUA_DLL.Calls.pjsua_msg_data_init(msg);

        msg.hdr_list.name = hdr.name;
        msg.hdr_list.next = hdr.next;             //I believe this is wrong as its giving 0x00000000
        msg.hdr_list.prev = hdr.prev;              //I believe this is wrong as its giving 0x00000000
        msg.hdr_list.sname = hdr.name;
        msg.hdr_list.type = hdr.type;
        msg.hdr_list.vptr = hdr.vptr;               //I believe this is wrong as its giving 0x00000000

       msg.msg_body = new pj_str_t("Hello World");            //I can see "Hello World" text in Wireshark, verifies that **msg_data** is passing
       msg.content_type = new pj_str_t("Text/Plain");

        var r = new pj_str_t("My Reason");
        Helper.GuardError(PJSUA_DLL.Calls.pjsua_call_hangup(callId, (uint)code, ref r, msg));

Help Needed I need a sample code which I can use to add correct header. I believe I am doing something wrong in this code which is not a proper way to pass. Can you please provide me right sample code to add header in it. Note: I will not send msg_body in the actual packet, I just passed to confirm body is changing but headers are not. picturemessage_lkkyiioa s15

siniypin commented 5 years ago

pjsip4net uses method pjsua_call_xfer under the hood: https://github.com/siniypin/pjsip4net/blob/master/pjsip.Interop/ApiProviders/CallApiProvider_1_4.cs#L87

Can you give it a try (example: https://gist.github.com/siniypin/7504504)?

siniypin commented 5 years ago

Is this what you're asking about: https://www.pjsip.org/docs/latest-1/pjsip/docs/html/structpjsua__msg__data.htm#a7f6eec84a1979de17f5f60125fc20c2a ?

Checkout this example: https://github.com/chakrit/pjsip/blob/master/pjsip-apps/src/pjsua/pjsua_app.c#L156

ujavaid1985 commented 5 years ago

Is this what you're asking about: https://www.pjsip.org/docs/latest-1/pjsip/docs/html/structpjsua__msg__data.htm#a7f6eec84a1979de17f5f60125fc20c2a ?

Checkout this example: https://github.com/chakrit/pjsip/blob/master/pjsip-apps/src/pjsua/pjsua_app.c#L156

Thanks for your reply. I have already tried transfer its working fine.

I want to send msg_data from C# code but unable to send it right. I can send msg_body but can't send hdr_list right. Can you please provide one C# example code, how can we do it. I have already posted the example above people doing it in Java and a piece of code I am trying.

C# sample code to pass msg_data information in pjsua_call_hangup will be highly appreciated.

Thanks, Usman