Changeset 1222
- Timestamp:
- Apr 29, 2007 6:30:58 AM (18 years ago)
- Location:
- pjproject/branches/pjproject-0.5-stable/pjsip/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/pjproject-0.5-stable/pjsip/src/pjsip/sip_parser.c
r1219 r1222 139 139 pj_pool_t *pool, 140 140 pj_str_t *pname, 141 pj_str_t *pvalue); 141 pj_str_t *pvalue, 142 unsigned option); 142 143 static void int_parse_uri_param( pj_scanner *scanner, 143 144 pj_pool_t *pool, … … 1118 1119 /* Parse parameter (";" pname ["=" pvalue]) in header. */ 1119 1120 static void int_parse_param( pj_scanner *scanner, pj_pool_t *pool, 1120 pj_str_t *pname, pj_str_t *pvalue) 1121 pj_str_t *pname, pj_str_t *pvalue, 1122 unsigned option) 1121 1123 { 1122 1124 /* Get ';' character */ … … 1124 1126 1125 1127 /* Get pname and optionally pvalue */ 1126 pjsip_parse_param_imp(scanner, pool, pname, pvalue, 1127 PJSIP_PARSE_REMOVE_QUOTE); 1128 pjsip_parse_param_imp(scanner, pool, pname, pvalue, option); 1128 1129 } 1129 1130 … … 1536 1537 * Accept, Allow, Supported 1537 1538 */ 1538 if (*scanner->curptr == '\r' || *scanner->curptr == '\n') { 1539 if (pj_scan_is_eof(scanner) || 1540 *scanner->curptr == '\r' || *scanner->curptr == '\n') 1541 { 1539 1542 goto end; 1540 1543 } … … 1548 1551 &hdr->values[hdr->count]); 1549 1552 hdr->count++; 1553 1554 if (hdr->count >= PJSIP_GENERIC_ARRAY_MAX_COUNT) 1555 break; 1550 1556 } 1551 1557 … … 1614 1620 pj_str_t pname, pvalue; 1615 1621 1616 int_parse_param( scanner, pool, &pname, &pvalue );1622 int_parse_param( scanner, pool, &pname, &pvalue, 0); 1617 1623 if (!parser_stricmp(pname, pjsip_Q_STR) && pvalue.slen) { 1618 1624 char *dot_pos = pj_memchr(pvalue.ptr, '.', pvalue.slen); … … 1707 1713 while (*scanner->curptr == ';') { 1708 1714 pj_str_t pname, pvalue; 1709 int_parse_param(scanner, ctx->pool, &pname, &pvalue );1715 int_parse_param(scanner, ctx->pool, &pname, &pvalue, 0); 1710 1716 concat_param(&hdr->media.param, ctx->pool, &pname, &pvalue); 1711 1717 } … … 1760 1766 pj_str_t pname, pvalue; 1761 1767 1762 int_parse_param( scanner, pool, &pname, &pvalue );1768 int_parse_param( scanner, pool, &pname, &pvalue, 0); 1763 1769 1764 1770 if (!parser_stricmp(pname, pjsip_TAG_STR)) { … … 1844 1850 pj_str_t pname, pvalue; 1845 1851 1846 int_parse_param( scanner, pool, &pname, &pvalue );1852 int_parse_param( scanner, pool, &pname, &pvalue, 0); 1847 1853 1848 1854 if (!parser_stricmp(pname, pjsip_BRANCH_STR) && pvalue.slen) { … … 1905 1911 while (*scanner->curptr == ';') { 1906 1912 pjsip_param *p = pj_pool_alloc(pool, sizeof(pjsip_param)); 1907 int_parse_param(scanner, pool, &p->name, &p->value );1913 int_parse_param(scanner, pool, &p->name, &p->value, 0); 1908 1914 pj_list_insert_before(&hdr->other_param, p); 1909 1915 } -
pjproject/branches/pjproject-0.5-stable/pjsip/src/pjsip/sip_uri.c
r974 r1222 111 111 if (p->value.slen) { 112 112 *buf++ = '='; 113 copy_advance_escape(buf, p->value, (*pvalue_spec)); 113 if (*p->value.ptr == '"') 114 copy_advance(buf, p->value); 115 else 116 copy_advance_escape(buf, p->value, (*pvalue_spec)); 114 117 } 115 118 p = p->next; -
pjproject/branches/pjproject-0.5-stable/pjsip/src/test-pjsip/msg_test.c
r1219 r1222 778 778 779 779 /*****************************************************************************/ 780 /* Test various header parsing and production */ 781 static int hdr_test_success(pjsip_hdr *h); 782 static int hdr_test_accept0(pjsip_hdr *h); 783 static int hdr_test_accept1(pjsip_hdr *h); 784 static int hdr_test_accept2(pjsip_hdr *h); 785 static int hdr_test_allow0(pjsip_hdr *h); 786 static int hdr_test_authorization(pjsip_hdr *h); 787 static int hdr_test_cid(pjsip_hdr *h); 788 static int hdr_test_contact0(pjsip_hdr *h); 789 static int hdr_test_contact1(pjsip_hdr *h); 790 static int hdr_test_content_length(pjsip_hdr *h); 791 static int hdr_test_content_type(pjsip_hdr *h); 792 static int hdr_test_from(pjsip_hdr *h); 793 static int hdr_test_proxy_authenticate(pjsip_hdr *h); 794 static int hdr_test_record_route(pjsip_hdr *h); 795 static int hdr_test_supported(pjsip_hdr *h); 796 static int hdr_test_to(pjsip_hdr *h); 797 static int hdr_test_via(pjsip_hdr *h); 798 799 800 801 #define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3" 802 #define GENERIC_PARAM_PARSED "p0=a;p1=\"ab:;cd\";p2=ab:cd;p3" 803 #define PARAM_CHAR "[]/:&+$" 804 #define SIMPLE_ADDR_SPEC "sip:host" 805 #define ADDR_SPEC SIMPLE_ADDR_SPEC ";" PARAM_CHAR "=" PARAM_CHAR 806 #define NAME_ADDR "<" ADDR_SPEC ">" 807 808 #define HDR_FLAG_PARSE_FAIL 1 809 #define HDR_FLAG_DONT_PRINT 2 810 811 struct hdr_test_t 812 { 813 char *hname; 814 char *hshort_name; 815 char *hcontent; 816 int (*test)(pjsip_hdr*); 817 unsigned flags; 818 } hdr_test_data[] = 819 { 820 { 821 /* Empty Accept */ 822 "Accept", NULL, 823 "", 824 &hdr_test_accept0 825 }, 826 827 { 828 /* Overflowing generic string header */ 829 "Accept", NULL, 830 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 831 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 832 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 833 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 834 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 835 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 836 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ 837 "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a", 838 &hdr_test_success, 839 HDR_FLAG_PARSE_FAIL 840 }, 841 842 { 843 /* Normal Accept */ 844 "Accept", NULL, 845 "application/*, text/plain", 846 &hdr_test_accept1 847 }, 848 849 { 850 /* Accept with params */ 851 "Accept", NULL, 852 "application/*;p1=v1, text/plain", 853 &hdr_test_accept2 854 }, 855 856 { 857 /* Empty Allow */ 858 "Allow", NULL, 859 "", 860 &hdr_test_allow0, 861 }, 862 863 { 864 /* Authorization, testing which params should be quoted */ 865 "Authorization", NULL, 866 "Digest username=\"username\", realm=\"realm\", nonce=\"nonce\", " \ 867 "uri=\"sip:domain\", response=\"RESPONSE\", algorithm=MD5, " \ 868 "cnonce=\"CNONCE\", opaque=\"OPAQUE\", qop=auth, nc=00000001", 869 &hdr_test_authorization 870 }, 871 872 { 873 /* Call ID */ 874 "Call-ID", "i", 875 "-.!%*_+`'~()<>:\\\"/[]?{}", 876 &hdr_test_cid, 877 }, 878 879 { 880 /* Parameter belong to hparam */ 881 "Contact", "m", 882 SIMPLE_ADDR_SPEC ";p1=v1", 883 &hdr_test_contact0, 884 HDR_FLAG_DONT_PRINT 885 }, 886 887 { 888 /* generic-param in Contact header */ 889 "Contact", "m", 890 NAME_ADDR ";" GENERIC_PARAM, 891 &hdr_test_contact1 892 }, 893 894 { 895 /* Content-Length */ 896 "Content-Length", "l", 897 "10", 898 &hdr_test_content_length 899 }, 900 901 { 902 /* Content-Type, with generic-param */ 903 "Content-Type", "c", 904 "application/sdp" ";" GENERIC_PARAM, 905 &hdr_test_content_type, 906 HDR_FLAG_DONT_PRINT 907 }, 908 909 { 910 /* From, testing parameters and generic-param */ 911 "From", "f", 912 NAME_ADDR ";" GENERIC_PARAM, 913 &hdr_test_from 914 }, 915 916 { 917 /* Proxy-Authenticate, testing which params should be quoted */ 918 "Proxy-Authenticate", NULL, 919 "Digest realm=\"realm\",domain=\"sip:domain\",nonce=\"nonce\"," \ 920 "opaque=\"opaque\",stale=true,algorithm=MD5,qop=\"auth\"", 921 &hdr_test_proxy_authenticate 922 }, 923 924 { 925 /* Record-Route, param belong to header */ 926 "Record-Route", NULL, 927 NAME_ADDR ";" GENERIC_PARAM, 928 &hdr_test_record_route 929 }, 930 931 { 932 /* Empty Supported */ 933 "Supported", "k", 934 "", 935 &hdr_test_supported, 936 }, 937 938 { 939 /* To */ 940 "To", "t", 941 NAME_ADDR ";" GENERIC_PARAM, 942 &hdr_test_to 943 }, 944 945 { 946 /* Via */ 947 "Via", "v", 948 "SIP/2.0/XYZ host" ";" GENERIC_PARAM, 949 &hdr_test_via 950 } 951 }; 952 953 static int hdr_test_success(pjsip_hdr *h) 954 { 955 PJ_UNUSED_ARG(h); 956 return 0; 957 } 958 959 /* "" */ 960 static int hdr_test_accept0(pjsip_hdr *h) 961 { 962 pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; 963 964 if (h->type != PJSIP_H_ACCEPT) 965 return -1010; 966 967 if (hdr->count != 0) 968 return -1020; 969 970 return 0; 971 } 972 973 /* "application/*, text/plain\r\n" */ 974 static int hdr_test_accept1(pjsip_hdr *h) 975 { 976 pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; 977 978 if (h->type != PJSIP_H_ACCEPT) 979 return -1110; 980 981 if (hdr->count != 2) 982 return -1120; 983 984 if (pj_strcmp2(&hdr->values[0], "application/*")) 985 return -1130; 986 987 if (pj_strcmp2(&hdr->values[1], "text/plain")) 988 return -1140; 989 990 return 0; 991 } 992 993 /* "application/*;p1=v1, text/plain\r\n" */ 994 static int hdr_test_accept2(pjsip_hdr *h) 995 { 996 pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; 997 998 if (h->type != PJSIP_H_ACCEPT) 999 return -1210; 1000 1001 if (hdr->count != 2) 1002 return -1220; 1003 1004 if (pj_strcmp2(&hdr->values[0], "application/*;p1=v1")) 1005 return -1230; 1006 1007 if (pj_strcmp2(&hdr->values[1], "text/plain")) 1008 return -1240; 1009 1010 return 0; 1011 } 1012 1013 /* "" */ 1014 static int hdr_test_allow0(pjsip_hdr *h) 1015 { 1016 pjsip_allow_hdr *hdr = (pjsip_allow_hdr*)h; 1017 1018 if (h->type != PJSIP_H_ALLOW) 1019 return -1310; 1020 1021 if (hdr->count != 0) 1022 return -1320; 1023 1024 return 0; 1025 1026 } 1027 1028 1029 /* 1030 "Digest username=\"username\", realm=\"realm\", nonce=\"nonce\", " \ 1031 "uri=\"sip:domain\", response=\"RESPONSE\", algorithm=MD5, " \ 1032 "cnonce=\"CNONCE\", opaque=\"OPAQUE\", qop=auth, nc=00000001", 1033 */ 1034 static int hdr_test_authorization(pjsip_hdr *h) 1035 { 1036 pjsip_authorization_hdr *hdr = (pjsip_authorization_hdr*)h; 1037 1038 if (h->type != PJSIP_H_AUTHORIZATION) 1039 return -1410; 1040 1041 if (pj_strcmp2(&hdr->scheme, "Digest")) 1042 return -1420; 1043 1044 if (pj_strcmp2(&hdr->credential.digest.username, "username")) 1045 return -1421; 1046 1047 if (pj_strcmp2(&hdr->credential.digest.realm, "realm")) 1048 return -1422; 1049 1050 if (pj_strcmp2(&hdr->credential.digest.nonce, "nonce")) 1051 return -1423; 1052 1053 if (pj_strcmp2(&hdr->credential.digest.uri, "sip:domain")) 1054 return -1424; 1055 1056 if (pj_strcmp2(&hdr->credential.digest.response, "RESPONSE")) 1057 return -1425; 1058 1059 if (pj_strcmp2(&hdr->credential.digest.algorithm, "MD5")) 1060 return -1426; 1061 1062 if (pj_strcmp2(&hdr->credential.digest.cnonce, "CNONCE")) 1063 return -1427; 1064 1065 if (pj_strcmp2(&hdr->credential.digest.opaque, "OPAQUE")) 1066 return -1428; 1067 1068 if (pj_strcmp2(&hdr->credential.digest.qop, "auth")) 1069 return -1429; 1070 1071 if (pj_strcmp2(&hdr->credential.digest.nc, "00000001")) 1072 return -1430; 1073 1074 return 0; 1075 } 1076 1077 1078 /* 1079 "-.!%*_+`'~()<>:\\\"/[]?{}\r\n" 1080 */ 1081 static int hdr_test_cid(pjsip_hdr *h) 1082 { 1083 pjsip_cid_hdr *hdr = (pjsip_cid_hdr*)h; 1084 1085 if (h->type != PJSIP_H_CALL_ID) 1086 return -1510; 1087 1088 if (pj_strcmp2(&hdr->id, "-.!%*_+`'~()<>:\\\"/[]?{}\r\n")) 1089 return -1520; 1090 1091 return 0; 1092 } 1093 1094 /* 1095 #define SIMPLE_ADDR_SPEC "sip:host" 1096 */ 1097 static int test_simple_addr_spec(pjsip_uri *uri) 1098 { 1099 pjsip_sip_uri *sip_uri = (pjsip_sip_uri *)pjsip_uri_get_uri(uri); 1100 1101 if (!PJSIP_URI_SCHEME_IS_SIP(uri)) 1102 return -900; 1103 1104 if (pj_strcmp2(&sip_uri->host, "host")) 1105 return -910; 1106 1107 if (sip_uri->port != 0) 1108 return -920; 1109 1110 return 0; 1111 } 1112 1113 /* 1114 #define PARAM_CHAR "[]/:&+$" 1115 #define SIMPLE_ADDR_SPEC "sip:host" 1116 #define ADDR_SPEC SIMPLE_ADDR_SPEC ";" PARAM_CHAR "=" PARAM_CHAR 1117 #define NAME_ADDR "<" ADDR_SPEC ">" 1118 */ 1119 static int nameaddr_test(pjsip_uri *uri) 1120 { 1121 pjsip_sip_uri *sip_uri = (pjsip_sip_uri *)pjsip_uri_get_uri(uri); 1122 pjsip_param *param; 1123 int rc; 1124 1125 if (!PJSIP_URI_SCHEME_IS_SIP(uri)) 1126 return -930; 1127 1128 rc = test_simple_addr_spec((pjsip_uri*)sip_uri); 1129 if (rc != 0) 1130 return rc; 1131 1132 if (pj_list_size(&sip_uri->other_param) != 1) 1133 return -940; 1134 1135 param = sip_uri->other_param.next; 1136 1137 if (pj_strcmp2(¶m->name, PARAM_CHAR)) 1138 return -942; 1139 1140 if (pj_strcmp2(¶m->value, PARAM_CHAR)) 1141 return -943; 1142 1143 return 0; 1144 } 1145 1146 /* 1147 #define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3" 1148 */ 1149 static int generic_param_test(pjsip_param *param_head) 1150 { 1151 pjsip_param *param; 1152 1153 if (pj_list_size(param_head) != 4) 1154 return -950; 1155 1156 param = param_head->next; 1157 1158 if (pj_strcmp2(¶m->name, "p0")) 1159 return -952; 1160 if (pj_strcmp2(¶m->value, "a")) 1161 return -953; 1162 1163 param = param->next; 1164 if (pj_strcmp2(¶m->name, "p1")) 1165 return -954; 1166 if (pj_strcmp2(¶m->value, "\"ab:;cd\"")) 1167 return -955; 1168 1169 param = param->next; 1170 if (pj_strcmp2(¶m->name, "p2")) 1171 return -956; 1172 if (pj_strcmp2(¶m->value, "ab:cd")) 1173 return -957; 1174 1175 param = param->next; 1176 if (pj_strcmp2(¶m->name, "p3")) 1177 return -958; 1178 if (pj_strcmp2(¶m->value, "")) 1179 return -959; 1180 1181 return 0; 1182 } 1183 1184 1185 1186 /* 1187 SIMPLE_ADDR_SPEC ";p1=v1\r\n" 1188 */ 1189 static int hdr_test_contact0(pjsip_hdr *h) 1190 { 1191 pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 1192 pjsip_param *param; 1193 int rc; 1194 1195 if (h->type != PJSIP_H_CONTACT) 1196 return -1610; 1197 1198 rc = test_simple_addr_spec(hdr->uri); 1199 if (rc != 0) 1200 return rc; 1201 1202 if (pj_list_size(&hdr->other_param) != 1) 1203 return -1620; 1204 1205 param = hdr->other_param.next; 1206 1207 if (pj_strcmp2(¶m->name, "p1")) 1208 return -1630; 1209 1210 if (pj_strcmp2(¶m->value, "v1")) 1211 return -1640; 1212 1213 return 0; 1214 } 1215 1216 /* 1217 NAME_ADDR GENERIC_PARAM "\r\n", 1218 */ 1219 static int hdr_test_contact1(pjsip_hdr *h) 1220 { 1221 pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 1222 int rc; 1223 1224 if (h->type != PJSIP_H_CONTACT) 1225 return -1710; 1226 1227 rc = nameaddr_test(hdr->uri); 1228 if (rc != 0) 1229 return rc; 1230 1231 rc = generic_param_test(&hdr->other_param); 1232 if (rc != 0) 1233 return rc; 1234 1235 return 0; 1236 } 1237 1238 /* 1239 "10" 1240 */ 1241 static int hdr_test_content_length(pjsip_hdr *h) 1242 { 1243 pjsip_clen_hdr *hdr = (pjsip_clen_hdr*)h; 1244 1245 if (h->type != PJSIP_H_CONTENT_LENGTH) 1246 return -1810; 1247 1248 if (hdr->len != 10) 1249 return -1820; 1250 1251 return 0; 1252 } 1253 1254 /* 1255 "application/sdp" GENERIC_PARAM, 1256 */ 1257 static int hdr_test_content_type(pjsip_hdr *h) 1258 { 1259 pjsip_ctype_hdr *hdr = (pjsip_ctype_hdr*)h; 1260 1261 if (h->type != PJSIP_H_CONTENT_TYPE) 1262 return -1910; 1263 1264 if (pj_strcmp2(&hdr->media.type, "application")) 1265 return -1920; 1266 1267 if (pj_strcmp2(&hdr->media.subtype, "sdp")) 1268 return -1930; 1269 1270 /* Currently, if the media parameter contains escaped characters, 1271 * pjsip will print the parameter unescaped. 1272 */ 1273 PJ_TODO(FIX_PARAMETER_IN_MEDIA_TYPE); 1274 1275 if (pj_strcmp2(&hdr->media.param, ";" GENERIC_PARAM_PARSED)) 1276 return -1940; 1277 1278 return 0; 1279 } 1280 1281 /* 1282 NAME_ADDR GENERIC_PARAM, 1283 */ 1284 static int hdr_test_from(pjsip_hdr *h) 1285 { 1286 pjsip_from_hdr *hdr = (pjsip_from_hdr*)h; 1287 int rc; 1288 1289 if (h->type != PJSIP_H_FROM) 1290 return -2010; 1291 1292 rc = nameaddr_test(hdr->uri); 1293 if (rc != 0) 1294 return rc; 1295 1296 rc = generic_param_test(&hdr->other_param); 1297 if (rc != 0) 1298 return rc; 1299 1300 return 0; 1301 } 1302 1303 /* 1304 "Digest realm=\"realm\", domain=\"sip:domain\", nonce=\"nonce\", " \ 1305 "opaque=\"opaque\", stale=true, algorithm=MD5, qop=\"auth\"", 1306 */ 1307 static int hdr_test_proxy_authenticate(pjsip_hdr *h) 1308 { 1309 pjsip_proxy_authenticate_hdr *hdr = (pjsip_proxy_authenticate_hdr*)h; 1310 1311 if (h->type != PJSIP_H_PROXY_AUTHENTICATE) 1312 return -2110; 1313 1314 if (pj_strcmp2(&hdr->scheme, "Digest")) 1315 return -2120; 1316 1317 if (pj_strcmp2(&hdr->challenge.digest.realm, "realm")) 1318 return -2130; 1319 1320 if (pj_strcmp2(&hdr->challenge.digest.domain, "sip:domain")) 1321 return -2140; 1322 1323 if (pj_strcmp2(&hdr->challenge.digest.nonce, "nonce")) 1324 return -2150; 1325 1326 if (pj_strcmp2(&hdr->challenge.digest.opaque, "opaque")) 1327 return -2160; 1328 1329 if (hdr->challenge.digest.stale != 1) 1330 return -2170; 1331 1332 if (pj_strcmp2(&hdr->challenge.digest.algorithm, "MD5")) 1333 return -2180; 1334 1335 if (pj_strcmp2(&hdr->challenge.digest.qop, "auth")) 1336 return -2190; 1337 1338 return 0; 1339 } 1340 1341 /* 1342 NAME_ADDR GENERIC_PARAM, 1343 */ 1344 static int hdr_test_record_route(pjsip_hdr *h) 1345 { 1346 pjsip_rr_hdr *hdr = (pjsip_rr_hdr*)h; 1347 int rc; 1348 1349 if (h->type != PJSIP_H_RECORD_ROUTE) 1350 return -2210; 1351 1352 rc = nameaddr_test((pjsip_uri*)&hdr->name_addr); 1353 if (rc != 0) 1354 return rc; 1355 1356 rc = generic_param_test(&hdr->other_param); 1357 if (rc != 0) 1358 return rc; 1359 1360 return 0; 1361 1362 } 1363 1364 /* 1365 " \r\n" 1366 */ 1367 static int hdr_test_supported(pjsip_hdr *h) 1368 { 1369 pjsip_supported_hdr *hdr = (pjsip_supported_hdr*)h; 1370 1371 if (h->type != PJSIP_H_SUPPORTED) 1372 return -2310; 1373 1374 if (hdr->count != 0) 1375 return -2320; 1376 1377 return 0; 1378 } 1379 1380 /* 1381 NAME_ADDR GENERIC_PARAM, 1382 */ 1383 static int hdr_test_to(pjsip_hdr *h) 1384 { 1385 pjsip_to_hdr *hdr = (pjsip_to_hdr*)h; 1386 int rc; 1387 1388 if (h->type != PJSIP_H_TO) 1389 return -2410; 1390 1391 rc = nameaddr_test(hdr->uri); 1392 if (rc != 0) 1393 return rc; 1394 1395 rc = generic_param_test(&hdr->other_param); 1396 if (rc != 0) 1397 return rc; 1398 1399 return 0; 1400 } 1401 1402 /* 1403 "SIP/2.0 host" GENERIC_PARAM 1404 */ 1405 static int hdr_test_via(pjsip_hdr *h) 1406 { 1407 pjsip_via_hdr *hdr = (pjsip_via_hdr*)h; 1408 int rc; 1409 1410 if (h->type != PJSIP_H_VIA) 1411 return -2510; 1412 1413 if (pj_strcmp2(&hdr->transport, "XYZ")) 1414 return -2515; 1415 1416 if (pj_strcmp2(&hdr->sent_by.host, "host")) 1417 return -2520; 1418 1419 if (hdr->sent_by.port != 0) 1420 return -2530; 1421 1422 rc = generic_param_test(&hdr->other_param); 1423 if (rc != 0) 1424 return rc; 1425 1426 return 0; 1427 } 1428 1429 1430 static int hdr_test(void) 1431 { 1432 unsigned i; 1433 1434 PJ_LOG(3,(THIS_FILE, " testing header parsing..")); 1435 1436 for (i=0; i<PJ_ARRAY_SIZE(hdr_test_data); ++i) { 1437 struct hdr_test_t *test = &hdr_test_data[i]; 1438 pj_str_t hname; 1439 int len, parsed_len; 1440 pj_pool_t *pool; 1441 pjsip_hdr *parsed_hdr1=NULL, *parsed_hdr2=NULL; 1442 char *input, *output; 1443 int rc; 1444 1445 pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE); 1446 1447 /* Parse the header */ 1448 hname = pj_str(test->hname); 1449 len = strlen(test->hcontent); 1450 parsed_hdr1 = pjsip_parse_hdr(pool, &hname, test->hcontent, len, &parsed_len); 1451 if (parsed_hdr1 == NULL) { 1452 if (test->flags & HDR_FLAG_PARSE_FAIL) { 1453 pj_pool_release(pool); 1454 continue; 1455 } 1456 PJ_LOG(3,(THIS_FILE, " error parsing header %s: %s", test->hname, test->hcontent)); 1457 return -500; 1458 } 1459 1460 /* Test the parsing result */ 1461 if (test->test && (rc=test->test(parsed_hdr1)) != 0) { 1462 PJ_LOG(3,(THIS_FILE, " validation failed for header %s: %s", test->hname, test->hcontent)); 1463 PJ_LOG(3,(THIS_FILE, " error code is %d", rc)); 1464 return -502; 1465 } 1466 1467 #if 0 1468 /* Parse with hshortname, if present */ 1469 if (test->hshort_name) { 1470 hname = pj_str(test->hshort_name); 1471 len = strlen(test->hcontent); 1472 parsed_hdr2 = pjsip_parse_hdr(pool, &hname, test->hcontent, len, &parsed_len); 1473 if (parsed_hdr2 == NULL) { 1474 PJ_LOG(3,(THIS_FILE, " error parsing header %s: %s", test->hshort_name, test->hcontent)); 1475 return -510; 1476 } 1477 } 1478 #endif 1479 1480 if (test->flags & HDR_FLAG_DONT_PRINT) { 1481 pj_pool_release(pool); 1482 continue; 1483 } 1484 1485 /* Print the original header */ 1486 input = pj_pool_alloc(pool, 1024); 1487 len = pj_ansi_snprintf(input, 1024, "%s: %s", test->hname, test->hcontent); 1488 if (len < 1 || len >= 1024) 1489 return -520; 1490 1491 /* Print the parsed header*/ 1492 output = pj_pool_alloc(pool, 1024); 1493 len = pjsip_hdr_print_on(parsed_hdr1, output, 1024); 1494 if (len < 1 || len >= 1024) { 1495 PJ_LOG(3,(THIS_FILE, " header too long: %s: %s", test->hname, test->hcontent)); 1496 return -530; 1497 } 1498 output[len] = 0; 1499 1500 if (strcmp(input, output) != 0) { 1501 PJ_LOG(3,(THIS_FILE, " header character by character comparison failed.")); 1502 PJ_LOG(3,(THIS_FILE, " original header=|%s|", input)); 1503 PJ_LOG(3,(THIS_FILE, " parsed header =|%s|", output)); 1504 return -540; 1505 } 1506 1507 pj_pool_release(pool); 1508 } 1509 1510 return 0; 1511 } 1512 1513 1514 /*****************************************************************************/ 780 1515 781 1516 int msg_test(void) … … 795 1530 return status; 796 1531 1532 status = hdr_test(); 1533 if (status != 0) 1534 return status; 1535 797 1536 for (i=0; i<COUNT; ++i) { 798 1537 PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)..", i+1, COUNT)); … … 866 1605 } 867 1606 1607 1608 1609
Note: See TracChangeset
for help on using the changeset viewer.