forked from cristeab/g729codec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
caller_id_pjsua2.6.patch
105 lines (102 loc) · 3.43 KB
/
caller_id_pjsua2.6.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
index dd26632..7cf64e9 100644
--- a/pjsip/src/pjsip-ua/sip_inv.c
+++ b/pjsip/src/pjsip-ua/sip_inv.c
@@ -3147,6 +3147,87 @@ PJ_DEF(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
return PJ_SUCCESS;
}
+/* BEGIN BC */
+static char *escape_quoted(const char *string, char *outbuf, int buflen)
+{
+ const char *ptr = string;
+ char *out = outbuf;
+ char *allow = "\t\v !"; /* allow LWS (minus \r and \n) and "!" */
+
+ while (*ptr && out - outbuf < buflen - 1) {
+ if (!(strchr(allow, *ptr))
+ && !(*ptr >= '#' && *ptr <= '[') /* %x23 - %x5b */
+ && !(*ptr >= ']' && *ptr <= '~') /* %x5d - %x7e */
+ && !((unsigned char) *ptr > 0x7f)) { /* UTF8-nonascii */
+
+ if (out - outbuf >= buflen - 2) {
+ break;
+ }
+ out += sprintf(out, "\\%c", (unsigned char) *ptr);
+ } else {
+ *out = *ptr;
+ out++;
+ }
+ ptr++;
+ }
+
+ if (buflen) {
+ *out = '\0';
+ }
+
+ return outbuf;
+}
+static void modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, const char *cid)
+{
+ pjsip_name_addr *id_name_addr;
+ pjsip_sip_uri *id_uri;
+
+ id_name_addr = (pjsip_name_addr *) id_hdr->uri;
+ id_uri = pjsip_uri_get_uri(id_name_addr->uri);
+
+ /* if (id->name.valid) { */
+ int name_buf_len = strlen(cid) * 2 + 1;
+ char *name_buf = __builtin_alloca(name_buf_len);
+ escape_quoted(cid, name_buf, name_buf_len);
+ pj_strdup2(pool, &id_name_addr->display, name_buf);
+
+ /* if (id->number.valid) { */
+ pj_strdup2(pool, &id_uri->user, cid);
+}
+static void caller_id_outgoing_request(pjsip_tx_data *tdata)
+{
+ static const pj_str_t STR_ASSERTED_ID = { "P-Asserted-Identity", 19 };
+ static const pj_size_t caller_id_len = 1024;
+ char caller_id[caller_id_len];
+
+ /* get P-Asserted-Identity header */
+ pjsip_generic_string_hdr *hdr = pjsip_msg_find_hdr_by_name(tdata->msg, &STR_ASSERTED_ID, tdata->msg->hdr.next);
+ if (NULL != hdr) {
+ pjsip_fromto_hdr *from = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_FROM, tdata->msg->hdr.next);
+ if (NULL != from) {
+ pj_size_t len = pj_strlen(&hdr->hvalue);
+ if (4 < len) {
+ /* set CID only if it is not empty. CID should have the format 'sip:<CID>@<domain>' */
+ int index = 0;
+ const char *str_buf = pj_strbuf(&hdr->hvalue);
+ while ((index < (caller_id_len-1)) && ('@' != str_buf[4+index]) && ((4+index) < len)) {
+ caller_id[index] = str_buf[4+index];
+ ++index;
+ }
+ caller_id[index] = '\0';
+ modify_id_header(tdata->pool, from, caller_id);
+ }
+ }
+ }
+}
+static void handle_outgoing(pjsip_tx_data *tdata)
+{
+ if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+ caller_id_outgoing_request(tdata);
+ }
+}
+/* END BC */
+
/*
* Send a request or response message.
*/
@@ -3161,7 +3242,11 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv,
pj_log_push_indent();
PJ_LOG(5,(inv->obj_name, "Sending %s",
- pjsip_tx_data_get_info(tdata)));
+ pjsip_tx_data_get_info(tdata)));
+
+ /* BEGIN BC */
+ handle_outgoing(tdata);
+ /* END BC */
if (tdata->msg->type == PJSIP_REQUEST_MSG) {
struct tsx_inv_data *tsx_inv_data;