Voip adds Chinese display name

For terminals interacting with voip, what you expect to see is not numbers or English names, but Chinese display names. For sip interactions, rfc3261 supports UTF-8 encoding in the from and to fields, adding display names: The sample code is as follows:

Code to call exosip:

#include <osip2/osip.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
    osip_init();

    // 创建SIP消息结构体
    osip_message_t* invite = NULL;
    int status = osip_message_init(&invite);
    if (status != 0) {
        printf("Failed to initialize SIP message.\n");
        return -1;
    }

    // 设置From头
    osip_from_t* from = NULL;
    status = osip_from_init(&from);
    if (status != 0) {
        printf("Failed to initialize From header.\n");
        osip_free(invite);
        return -1;
    }
    status = osip_from_set_displayname(from, "中国");
    if (status != 0) {
        printf("Failed to set display name in From header.\n");
        osip_free(invite);
        return -1;
    }

    osip_uri_t* from_uri = NULL;
    status = osip_uri_init(&from_uri);
    if (status != 0) {
        printf("Failed to initialize From URI.\n");
        osip_free(invite);
        return -1;
    }
    
    status = osip_uri_parse(from_uri, "sip:[email protected]");
    if (status != 0) {
        printf("Failed to parse URL in From URI.\n");
        osip_uri_free(from_uri);
        osip_free(invite);
        return -1;
    }

    status = osip_from_set_url(from, from_uri);
    if (status != 0) {
        printf("Failed to set URL in From header.\n");
        osip_uri_free(from_uri);
        osip_free(invite);
        return -1;
    }
    invite->from = from;

    // 设置To头,发送SIP消息等其他操作...

    osip_free(invite);
    osip_quit();
    return 0;
}

In this case, the corresponding Chinese name can be displayed in the interaction

Sample package captured:

INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/TCP 192.168.43.51:51444;branch=z9hG4bK.lDh2aCdHv;rport
From: "中国" <sip:[email protected]>;tag=KaLU8kGOz
To: "人民" <sip:[email protected]>
CSeq: 20 INVITE
Call-ID: v0-K3~FDj-
Max-Forwards: 70
Supported: replaces, outbound, gruu, path, record-aware
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK, UPDATE
Content-Type: application/sdp
Content-Length: 575
Contact: <sip:[email protected]:2763;transport=tcp>;expires=3600;received="sip:124.190.49.82:2763;transport=tcp";+sip.instance="<urn:uuid:fa7401d9-8473-0077-a27c-c4ab00607c92>";+org.linphone.specs="lime"
User-Agent: Linphone-Desktop/5.0.18 (DESKTOP-5REGCE3) windows/10 Qt/5.15.2 LinphoneSDK/5.2.75

v=0
o=1001 909 1598 IN IP4 192.168.43.51
s=Talk
c=IN IP4 192.168.43.51
t=0 0
a=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics
a=record:off
m=audio 7078 RTP/AVP 0 8 3 9 96 18 97 98 10 11
a=rtpmap:96 iLBC/8000
a=fmtp:96 mode=30
a=fmtp:18 annexb=yes
a=rtpmap:97 speex/32000
a=fmtp:97 vbr=on
a=rtpmap:98 BV16/8000
a=rtcp-fb:* trr-int 1000
a=rtcp-fb:* ccm tmmbr
m=video 9078 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42801F
a=rtcp-fb:* trr-int 1000
a=rtcp-fb:* ccm tmmbr
a=rtcp-fb:96 nack pli
a=rtcp-fb:96 ccm fir

Guess you like

Origin blog.csdn.net/huapeng_guo/article/details/131422805
Recommended