Changeset 1389
- Timestamp:
- Jun 26, 2007 12:25:11 AM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r1369 r1389 96 96 #endif 97 97 pj_status_t app_destroy(void); 98 99 extern pj_bool_t pjsip_use_compact_form; 98 100 99 101 /***************************************************************************** … … 2885 2887 pj_status_t status; 2886 2888 2889 //pjsip_use_compact_form = PJ_TRUE; 2890 2887 2891 /* Create pjsua */ 2888 2892 status = pjsua_create(); -
pjproject/trunk/pjsip/include/pjsip/print_util.h
r1240 r1389 102 102 typedef int (*pjsip_hdr_print_fptr)(void *hdr, char *buf, pj_size_t len); 103 103 104 extern const pj_str_t pjsip_hdr_names[]; 104 typedef struct pjsip_hdr_name_info_t 105 { 106 char *name; 107 unsigned name_len; 108 char *sname; 109 } pjsip_hdr_name_info_t; 110 111 extern const pjsip_hdr_name_info_t pjsip_hdr_names[]; 105 112 106 113 PJ_INLINE(void) init_hdr(void *hptr, pjsip_hdr_e htype, void *vptr) … … 108 115 pjsip_hdr *hdr = (pjsip_hdr*) hptr; 109 116 hdr->type = htype; 110 hdr->name = hdr->sname = pjsip_hdr_names[htype]; 117 hdr->name.ptr = pjsip_hdr_names[htype].name; 118 hdr->name.slen = pjsip_hdr_names[htype].name_len; 119 if (pjsip_hdr_names[htype].sname) { 120 hdr->sname.ptr = pjsip_hdr_names[htype].sname; 121 hdr->sname.slen = 1; 122 } else { 123 hdr->sname = hdr->name; 124 } 111 125 hdr->vptr = (pjsip_hdr_vptr*) vptr; 112 126 pj_list_init(hdr); -
pjproject/trunk/pjsip/include/pjsip/sip_config.h
r1244 r1389 130 130 131 131 /** 132 * Encode SIP headers in their short forms to reduce size. By default, 133 * SIP headers in outgoing messages will be encoded in their full names. 134 * If this option is enabled, then SIP headers for outgoing messages 135 * will be encoded in their short forms, to reduce message size. 136 * Note that this does not affect the ability of PJSIP to parse incoming 137 * SIP messages, as the parser always supports parsing both the long 138 * and short version of the headers. 139 * 140 * Note that there is also an undocumented variable defined in sip_msg.c 141 * to control whether compact form should be used for encoding SIP 142 * headers. The default value of this variable is PJSIP_ENCODE_SHORT_HNAME. 143 * To change PJSIP behavior during run-time, application can use the 144 * following construct: 145 * 146 \verbatim 147 extern pj_bool_t pjsip_use_compact_form; 148 149 // enable compact form 150 pjsip_use_compact_form = PJ_TRUE; 151 \endverbatim 152 * 153 * Default is 0 (no) 154 */ 155 #ifndef PJSIP_ENCODE_SHORT_HNAME 156 # define PJSIP_ENCODE_SHORT_HNAME 0 157 #endif 158 159 160 /** 132 161 * Allow SIP modules removal or insertions during operation? 133 162 * If yes, then locking will be employed when endpoint need to -
pjproject/trunk/pjsip/src/pjsip/sip_msg.c
r1266 r1389 43 43 }; 44 44 45 const pj _str_t pjsip_hdr_names[] =46 { 47 { "Accept", 6}, // PJSIP_H_ACCEPT,48 { "Accept-Encoding", 15 }, // PJSIP_H_ACCEPT_ENCODING,49 { "Accept-Language", 15 }, // PJSIP_H_ACCEPT_LANGUAGE,50 { "Alert-Info", 10 }, // PJSIP_H_ALERT_INFO,51 { "Allow", 5}, // PJSIP_H_ALLOW,52 { "Authentication-Info",19 }, // PJSIP_H_AUTHENTICATION_INFO,53 { "Authorization", 13 }, // PJSIP_H_AUTHORIZATION,54 { "Call-ID", 7 },// PJSIP_H_CALL_ID,55 { "Call-Info", 9}, // PJSIP_H_CALL_INFO,56 { "Contact", 7 },// PJSIP_H_CONTACT,57 { "Content-Disposition",19 }, // PJSIP_H_CONTENT_DISPOSITION,58 { "Content-Encoding", 16 },// PJSIP_H_CONTENT_ENCODING,59 { "Content-Language", 16 }, // PJSIP_H_CONTENT_LANGUAGE,60 { "Content-Length", 14 },// PJSIP_H_CONTENT_LENGTH,61 { "Content-Type", 12 },// PJSIP_H_CONTENT_TYPE,62 { "CSeq", 4 }, // PJSIP_H_CSEQ,63 { "Date", 4 }, // PJSIP_H_DATE,64 { "Error-Info", 10 }, // PJSIP_H_ERROR_INFO,65 { "Expires", 7 }, // PJSIP_H_EXPIRES,66 { "From", 4 },// PJSIP_H_FROM,67 { "In-Reply-To", 11 }, // PJSIP_H_IN_REPLY_TO,68 { "Max-Forwards", 12 }, // PJSIP_H_MAX_FORWARDS,69 { "MIME-Version", 12 }, // PJSIP_H_MIME_VERSION,70 { "Min-Expires", 11 }, // PJSIP_H_MIN_EXPIRES,71 { "Organization", 12 }, // PJSIP_H_ORGANIZATION,72 { "Priority", 8 }, // PJSIP_H_PRIORITY,73 { "Proxy-Authenticate", 18 }, // PJSIP_H_PROXY_AUTHENTICATE,74 { "Proxy-Authorization",19 }, // PJSIP_H_PROXY_AUTHORIZATION,75 { "Proxy-Require", 13 }, // PJSIP_H_PROXY_REQUIRE,76 { "Record-Route", 12 }, // PJSIP_H_RECORD_ROUTE,77 { "Reply-To", 8 }, // PJSIP_H_REPLY_TO,78 { "Require", 7 }, // PJSIP_H_REQUIRE,79 { "Retry-After", 11 }, // PJSIP_H_RETRY_AFTER,80 { "Route", 5 }, // PJSIP_H_ROUTE,81 { "Server", 6 }, // PJSIP_H_SERVER,82 { "Subject", 7 },// PJSIP_H_SUBJECT,83 { "Supported", 9 },// PJSIP_H_SUPPORTED,84 { "Timestamp", 9 }, // PJSIP_H_TIMESTAMP,85 { "To", 2 },// PJSIP_H_TO,86 { "Unsupported", 11 }, // PJSIP_H_UNSUPPORTED,87 { "User-Agent", 10 }, // PJSIP_H_USER_AGENT,88 { "Via", 3 },// PJSIP_H_VIA,89 { "Warning", 7 }, // PJSIP_H_WARNING,90 { "WWW-Authenticate", 16 }, // PJSIP_H_WWW_AUTHENTICATE,91 92 { "_Unknown-Header", 15 }, // PJSIP_H_OTHER,45 const pjsip_hdr_name_info_t pjsip_hdr_names[] = 46 { 47 { "Accept", 6, NULL }, // PJSIP_H_ACCEPT, 48 { "Accept-Encoding", 15, NULL }, // PJSIP_H_ACCEPT_ENCODING, 49 { "Accept-Language", 15, NULL }, // PJSIP_H_ACCEPT_LANGUAGE, 50 { "Alert-Info", 10, NULL }, // PJSIP_H_ALERT_INFO, 51 { "Allow", 5, NULL }, // PJSIP_H_ALLOW, 52 { "Authentication-Info",19, NULL }, // PJSIP_H_AUTHENTICATION_INFO, 53 { "Authorization", 13, NULL }, // PJSIP_H_AUTHORIZATION, 54 { "Call-ID", 7, "i" }, // PJSIP_H_CALL_ID, 55 { "Call-Info", 9, NULL }, // PJSIP_H_CALL_INFO, 56 { "Contact", 7, "m" }, // PJSIP_H_CONTACT, 57 { "Content-Disposition",19, NULL }, // PJSIP_H_CONTENT_DISPOSITION, 58 { "Content-Encoding", 16, "e" }, // PJSIP_H_CONTENT_ENCODING, 59 { "Content-Language", 16, NULL }, // PJSIP_H_CONTENT_LANGUAGE, 60 { "Content-Length", 14, "l" }, // PJSIP_H_CONTENT_LENGTH, 61 { "Content-Type", 12, "c" }, // PJSIP_H_CONTENT_TYPE, 62 { "CSeq", 4, NULL }, // PJSIP_H_CSEQ, 63 { "Date", 4, NULL }, // PJSIP_H_DATE, 64 { "Error-Info", 10, NULL }, // PJSIP_H_ERROR_INFO, 65 { "Expires", 7, NULL }, // PJSIP_H_EXPIRES, 66 { "From", 4, "f" }, // PJSIP_H_FROM, 67 { "In-Reply-To", 11, NULL }, // PJSIP_H_IN_REPLY_TO, 68 { "Max-Forwards", 12, NULL }, // PJSIP_H_MAX_FORWARDS, 69 { "MIME-Version", 12, NULL }, // PJSIP_H_MIME_VERSION, 70 { "Min-Expires", 11, NULL }, // PJSIP_H_MIN_EXPIRES, 71 { "Organization", 12, NULL }, // PJSIP_H_ORGANIZATION, 72 { "Priority", 8, NULL }, // PJSIP_H_PRIORITY, 73 { "Proxy-Authenticate", 18, NULL }, // PJSIP_H_PROXY_AUTHENTICATE, 74 { "Proxy-Authorization",19, NULL }, // PJSIP_H_PROXY_AUTHORIZATION, 75 { "Proxy-Require", 13, NULL }, // PJSIP_H_PROXY_REQUIRE, 76 { "Record-Route", 12, NULL }, // PJSIP_H_RECORD_ROUTE, 77 { "Reply-To", 8, NULL }, // PJSIP_H_REPLY_TO, 78 { "Require", 7, NULL }, // PJSIP_H_REQUIRE, 79 { "Retry-After", 11, NULL }, // PJSIP_H_RETRY_AFTER, 80 { "Route", 5, NULL }, // PJSIP_H_ROUTE, 81 { "Server", 6, NULL }, // PJSIP_H_SERVER, 82 { "Subject", 7, "s" }, // PJSIP_H_SUBJECT, 83 { "Supported", 9, "k" }, // PJSIP_H_SUPPORTED, 84 { "Timestamp", 9, NULL }, // PJSIP_H_TIMESTAMP, 85 { "To", 2, "t" }, // PJSIP_H_TO, 86 { "Unsupported", 11, NULL }, // PJSIP_H_UNSUPPORTED, 87 { "User-Agent", 10, NULL }, // PJSIP_H_USER_AGENT, 88 { "Via", 3, "v" }, // PJSIP_H_VIA, 89 { "Warning", 7, NULL }, // PJSIP_H_WARNING, 90 { "WWW-Authenticate", 16, NULL }, // PJSIP_H_WWW_AUTHENTICATE, 91 92 { "_Unknown-Header", 15, NULL }, // PJSIP_H_OTHER, 93 93 }; 94 95 pj_bool_t pjsip_use_compact_form = PJSIP_ENCODE_SHORT_HNAME; 94 96 95 97 static pj_str_t status_phrase[710]; … … 306 308 } 307 309 for (; hdr!=end; hdr = hdr->next) { 308 if (hdr->type < PJSIP_H_OTHER) { 309 if (pj_stricmp(&pjsip_hdr_names[hdr->type], name) == 0) 310 return (void*)hdr; 311 } else { 312 if (pj_stricmp(&hdr->name, name) == 0) 313 return (void*)hdr; 314 } 310 if (pj_stricmp(&hdr->name, name) == 0) 311 return (void*)hdr; 315 312 } 316 313 return NULL; … … 334 331 pjsip_hdr *hdr; 335 332 pj_str_t clen_hdr = { "Content-Length: ", 16}; 333 334 if (pjsip_use_compact_form) { 335 clen_hdr.ptr = "l: "; 336 clen_hdr.slen = 3; 337 } 336 338 337 339 /* Get a wild guess on how many bytes are typically needed. … … 410 412 pj_str_t ctype_hdr = { "Content-Type: ", 14}; 411 413 const pjsip_media_type *media = &msg->body->content_type; 414 415 if (pjsip_use_compact_form) { 416 ctype_hdr.ptr = "c: "; 417 ctype_hdr.slen = 3; 418 } 412 419 413 420 /* Add Content-Type header. */ … … 597 604 { 598 605 char *p = buf; 606 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 599 607 600 if ((pj_ssize_t)size < h dr->name.slen + hdr->hvalue.slen + 5)608 if ((pj_ssize_t)size < hname->slen + hdr->hvalue.slen + 5) 601 609 return -1; 602 610 603 pj_memcpy(p, h dr->name.ptr, hdr->name.slen);604 p += h dr->name.slen;611 pj_memcpy(p, hname->ptr, hname->slen); 612 p += hname->slen; 605 613 *p++ = ':'; 606 614 *p++ = ' '; … … 620 628 621 629 hdr->type = rhs->type; 622 hdr->sname = hdr->name;630 pj_strdup(pool, &hdr->sname, &rhs->sname); 623 631 return hdr; 624 632 } … … 679 687 { 680 688 char *p = buf; 681 682 if ((pj_ssize_t)size < hdr->name.slen + 15) 689 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 690 691 if ((pj_ssize_t)size < hname->slen + 15) 683 692 return -1; 684 693 685 pj_memcpy(p, h dr->name.ptr, hdr->name.slen);686 p += h dr->name.slen;694 pj_memcpy(p, hname->ptr, hname->slen); 695 p += hname->slen; 687 696 *p++ = ':'; 688 697 *p++ = ' '; … … 754 763 { 755 764 char *p = buf, *endbuf = buf+size; 756 757 copy_advance(p, hdr->name); 765 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 766 767 copy_advance(p, (*hname)); 758 768 *p++ = ':'; 759 769 *p++ = ' '; … … 902 912 char *p = buf; 903 913 int len; 904 905 if ((pj_ssize_t)size < hdr->name.slen + 14) 914 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 915 916 if ((pj_ssize_t)size < hname->slen + 14) 906 917 return -1; 907 918 908 pj_memcpy(p, h dr->name.ptr, hdr->name.slen);909 p += h dr->name.slen;919 pj_memcpy(p, hname->ptr, hname->slen); 920 p += hname->slen; 910 921 *p++ = ':'; 911 922 *p++ = ' '; … … 966 977 char *p = buf; 967 978 int len; 979 /* CSeq doesn't have compact form */ 968 980 969 981 if ((pj_ssize_t)size < hdr->name.slen + hdr->method.name.slen + 15) … … 1043 1055 pj_size_t size) 1044 1056 { 1057 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 1058 1045 1059 if (hdr->star) { 1046 1060 char *p = buf; 1047 if ((pj_ssize_t)size < h dr->name.slen + 6)1061 if ((pj_ssize_t)size < hname->slen + 6) 1048 1062 return -1; 1049 pj_memcpy(p, h dr->name.ptr, hdr->name.slen);1050 p += h dr->name.slen;1063 pj_memcpy(p, hname->ptr, hname->slen); 1064 p += hname->slen; 1051 1065 *p++ = ':'; 1052 1066 *p++ = ' '; … … 1059 1073 char *endbuf = buf + size; 1060 1074 1061 copy_advance(buf, hdr->name);1075 copy_advance(buf, (*hname)); 1062 1076 *buf++ = ':'; 1063 1077 *buf++ = ' '; … … 1191 1205 char *p = buf; 1192 1206 int len; 1193 1194 if ((pj_ssize_t)size < hdr->name.slen + 1207 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 1208 1209 if ((pj_ssize_t)size < hname->slen + 1195 1210 hdr->media.type.slen + hdr->media.subtype.slen + 1196 1211 hdr->media.param.slen + 8) … … 1199 1214 } 1200 1215 1201 pj_memcpy(p, h dr->name.ptr, hdr->name.slen);1202 p += h dr->name.slen;1216 pj_memcpy(p, hname->ptr, hname->slen); 1217 p += hname->slen; 1203 1218 *p++ = ':'; 1204 1219 *p++ = ' '; … … 1308 1323 { 1309 1324 hdr->type = PJSIP_H_FROM; 1310 hdr->name = hdr->sname = pjsip_hdr_names[PJSIP_H_FROM]; 1325 hdr->name.ptr = pjsip_hdr_names[PJSIP_H_FROM].name; 1326 hdr->name.slen = pjsip_hdr_names[PJSIP_H_FROM].name_len; 1327 hdr->sname.ptr = pjsip_hdr_names[PJSIP_H_FROM].sname; 1328 hdr->sname.slen = 1; 1311 1329 return hdr; 1312 1330 } … … 1315 1333 { 1316 1334 hdr->type = PJSIP_H_TO; 1317 hdr->name = hdr->sname = pjsip_hdr_names[PJSIP_H_TO]; 1335 hdr->name.ptr = pjsip_hdr_names[PJSIP_H_TO].name; 1336 hdr->name.slen = pjsip_hdr_names[PJSIP_H_TO].name_len; 1337 hdr->sname.ptr = pjsip_hdr_names[PJSIP_H_TO].sname; 1338 hdr->sname.slen = 1; 1318 1339 return hdr; 1319 1340 } … … 1325 1346 char *startbuf = buf; 1326 1347 char *endbuf = buf + size; 1327 1328 copy_advance(buf, hdr->name); 1348 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 1349 1350 copy_advance(buf, (*hname)); 1329 1351 *buf++ = ':'; 1330 1352 *buf++ = ' '; … … 1482 1504 { 1483 1505 hdr->type = PJSIP_H_RECORD_ROUTE; 1484 hdr->name = hdr->sname = pjsip_hdr_names[PJSIP_H_RECORD_ROUTE]; 1506 hdr->name.ptr = pjsip_hdr_names[PJSIP_H_RECORD_ROUTE].name; 1507 hdr->name.slen = pjsip_hdr_names[PJSIP_H_RECORD_ROUTE].name_len; 1508 hdr->sname = hdr->name; 1485 1509 return hdr; 1486 1510 } … … 1489 1513 { 1490 1514 hdr->type = PJSIP_H_ROUTE; 1491 hdr->name = hdr->sname = pjsip_hdr_names[PJSIP_H_ROUTE]; 1515 hdr->name.ptr = pjsip_hdr_names[PJSIP_H_ROUTE].name; 1516 hdr->name.slen = pjsip_hdr_names[PJSIP_H_ROUTE].name_len; 1517 hdr->sname = hdr->name; 1492 1518 return hdr; 1493 1519 } … … 1499 1525 char *startbuf = buf; 1500 1526 char *endbuf = buf + size; 1527 /* Route and Record-Route don't compact forms */ 1501 1528 1502 1529 copy_advance(buf, hdr->name); … … 1677 1704 char *endbuf = buf + size; 1678 1705 pj_str_t sip_ver = { "SIP/2.0/", 8 }; 1679 1680 if ((pj_ssize_t)size < hdr->name.slen + sip_ver.slen + 1706 const pj_str_t *hname = pjsip_use_compact_form? &hdr->sname : &hdr->name; 1707 1708 if ((pj_ssize_t)size < hname->slen + sip_ver.slen + 1681 1709 hdr->transport.slen + hdr->sent_by.host.slen + 12) 1682 1710 { … … 1685 1713 1686 1714 /* pjsip_hdr_names */ 1687 copy_advance(buf, hdr->name);1715 copy_advance(buf, (*hname)); 1688 1716 *buf++ = ':'; 1689 1717 *buf++ = ' ';
Note: See TracChangeset
for help on using the changeset viewer.