Changeset 5520
- Timestamp:
- Jan 11, 2017 4:38:29 AM (8 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/string.h
r5468 r5520 475 475 } 476 476 477 478 /** 479 * Find the first index of character, in a string, that does not belong to a 480 * set of characters. 481 * 482 * @param str The string. 483 * @param set_char The string containing the set of characters. 484 * 485 * @return the index of the first character in the str that doesn't belong to 486 * set_char. If str starts with a character not in set_char, return 0. 487 */ 488 PJ_DECL(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char); 489 490 491 /** 492 * Find the first index of character, in a string, that does not belong to a 493 * set of characters. 494 * 495 * @param str The string. 496 * @param set_char The string containing the set of characters. 497 * 498 * @return the index of the first character in the str that doesn't belong to 499 * set_char. If str starts with a character not in set_char, return 0. 500 */ 501 PJ_DECL(pj_ssize_t) pj_strspn2(const pj_str_t *str, const char *set_char); 502 503 504 /** 505 * Find the first index of character, in a string, that belong to a set of 506 * characters. 507 * 508 * @param str The string. 509 * @param set_char The string containing the set of characters. 510 * 511 * @return the index of the first character in the str that belong to 512 * set_char. If no match is found, return the length of str. 513 */ 514 PJ_DECL(pj_ssize_t) pj_strcspn(const pj_str_t *str, const pj_str_t *set_char); 515 516 517 /** 518 * Find the first index of character, in a string, that belong to a set of 519 * characters. 520 * 521 * @param str The string. 522 * @param set_char The string containing the set of characters. 523 * 524 * @return the index of the first character in the str that belong to 525 * set_char. If no match is found, return the length of str. 526 */ 527 PJ_DECL(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char); 528 529 530 /** 531 * Find tokens from a string using the delimiter. 532 * 533 * @param str The string. 534 * @param delim The string containing the delimiter. It might contain 535 * multiple character treated as unique set. If same character 536 * was found on the set, it will be skipped. 537 * @param tok The string containing the token. 538 * @param start_idx The search will start from this index. 539 * 540 * @return the index of token from the str, or the length of the str 541 * if the token is not found. 542 */ 543 PJ_DECL(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim, 544 pj_str_t *tok, pj_size_t start_idx); 545 546 547 /** 548 * Find tokens from a string using the delimiter. 549 * 550 * @param str The string. 551 * @param delim The string containing the delimiter. It might contain 552 * multiple character treated as unique set. If same character 553 * was found on the set, it will be skipped. 554 * @param tok The string containing the token. 555 * @param start_idx The search will start from this index. 556 * 557 * @return the index of token from the str, or the length of the str 558 * if the token is not found. 559 */ 560 PJ_DECL(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim, 561 pj_str_t *tok, pj_size_t start_idx); 562 563 477 564 /** 478 565 * Find the occurence of a substring substr in string str. -
pjproject/trunk/pjlib/src/pj/os_info.c
r4610 r5520 99 99 100 100 static pj_uint32_t parse_version(char *str) 101 { 102 char *tok; 103 int i, maxtok; 101 { 102 int i, maxtok, found_idx; 104 103 pj_uint32_t version = 0; 104 pj_str_t in_str = pj_str(str); 105 pj_str_t token, delim; 105 106 106 107 while (*str && !pj_isdigit(*str)) … … 108 109 109 110 maxtok = 4; 110 for (tok = strtok(str, ".-"), i=0; tok && i<maxtok; 111 ++i, tok=strtok(NULL, ".-")) 111 delim = pj_str(".-"); 112 for (found_idx = pj_strtok(&in_str, &delim, &token, 0), i=0; 113 found_idx != in_str.slen && i < maxtok; 114 ++i, found_idx = pj_strtok(&in_str, &delim, &token, 115 found_idx + token.slen)) 112 116 { 113 117 int n; 114 118 115 if (!pj_isdigit(*tok ))119 if (!pj_isdigit(*token.ptr)) 116 120 break; 117 121 118 n = atoi(tok );122 n = atoi(token.ptr); 119 123 version |= (n << ((3-i)*8)); 120 124 } -
pjproject/trunk/pjlib/src/pj/string.c
r4704 r5520 29 29 #endif 30 30 31 PJ_DEF(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char) 32 { 33 pj_ssize_t i, j, count = 0; 34 for (i = 0; i < str->slen; i++) { 35 if (count != i) 36 break; 37 38 for (j = 0; j < set_char->slen; j++) { 39 if (str->ptr[i] == set_char->ptr[j]) 40 count++; 41 } 42 } 43 return count; 44 } 45 46 47 PJ_DEF(pj_ssize_t) pj_strspn2(const pj_str_t *str, const char *set_char) 48 { 49 pj_ssize_t i, j, count = 0; 50 for (i = 0; i < str->slen; i++) { 51 if (count != i) 52 break; 53 54 for (j = 0; set_char[j] != 0; j++) { 55 if (str->ptr[i] == set_char[j]) 56 count++; 57 } 58 } 59 return count; 60 } 61 62 63 PJ_DEF(pj_ssize_t) pj_strcspn(const pj_str_t *str, const pj_str_t *set_char) 64 { 65 pj_ssize_t i, j; 66 for (i = 0; i < str->slen; i++) { 67 for (j = 0; j < set_char->slen; j++) { 68 if (str->ptr[i] == set_char->ptr[j]) 69 return i; 70 } 71 } 72 return i; 73 } 74 75 76 PJ_DECL(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char) 77 { 78 pj_ssize_t i, j; 79 for (i = 0; i < str->slen; i++) { 80 for (j = 0; set_char[j] != 0; j++) { 81 if (str->ptr[i] == set_char[j]) 82 return i; 83 } 84 } 85 return i; 86 } 87 88 89 PJ_DEF(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim, 90 pj_str_t *tok, pj_size_t start_idx) 91 { 92 pj_ssize_t str_idx; 93 94 tok->slen = 0; 95 if ((str->slen == 0) || ((pj_size_t)str->slen < start_idx)) { 96 return str->slen; 97 } 98 99 tok->ptr = str->ptr + start_idx; 100 tok->slen = str->slen - start_idx; 101 102 str_idx = pj_strspn(tok, delim); 103 if (start_idx+str_idx == (pj_size_t)str->slen) { 104 return str->slen; 105 } 106 tok->ptr += str_idx; 107 tok->slen -= str_idx; 108 109 tok->slen = pj_strcspn(tok, delim); 110 return start_idx + str_idx; 111 } 112 113 114 PJ_DECL(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim, 115 pj_str_t *tok, pj_size_t start_idx) 116 { 117 pj_ssize_t str_idx; 118 119 tok->slen = 0; 120 if ((str->slen == 0) || ((pj_size_t)str->slen < start_idx)) { 121 return str->slen; 122 } 123 124 tok->ptr = str->ptr + start_idx; 125 tok->slen = str->slen - start_idx; 126 127 str_idx = pj_strspn2(tok, delim); 128 if (start_idx + str_idx == (pj_size_t)str->slen) { 129 return str->slen; 130 } 131 tok->ptr += str_idx; 132 tok->slen -= str_idx; 133 134 tok->slen = pj_strcspn2(tok, delim); 135 return start_idx + str_idx; 136 } 137 31 138 32 139 PJ_DEF(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr) -
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r5339 r5520 672 672 pj_ice_sess_cand *cand) 673 673 { 674 pj_str_t input; 675 char *token, *host; 676 int af; 677 pj_str_t s; 674 pj_str_t token, delim, host; 675 int af, found_idx; 678 676 pj_status_t status = PJNATH_EICEINCANDSDP; 679 677 680 678 pj_bzero(cand, sizeof(*cand)); 681 pj_strdup_with_null(pool, &input, orig_input);682 679 683 680 PJ_UNUSED_ARG(obj_name); 684 681 685 682 /* Foundation */ 686 token = strtok(input.ptr, " "); 687 if (!token) { 683 delim = pj_str(" "); 684 found_idx = pj_strtok(orig_input, &delim, &token, 0); 685 if (found_idx == orig_input->slen) { 688 686 TRACE__((obj_name, "Expecting ICE foundation in candidate")); 689 687 goto on_return; 690 688 } 691 pj_strdup 2(pool, &cand->foundation,token);689 pj_strdup(pool, &cand->foundation, &token); 692 690 693 691 /* Component ID */ 694 token = strtok(NULL, " ");695 if ( !token) {692 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + token.slen); 693 if (found_idx == orig_input->slen) { 696 694 TRACE__((obj_name, "Expecting ICE component ID in candidate")); 697 695 goto on_return; 698 696 } 699 cand->comp_id = (pj_uint8_t) atoi(token);697 cand->comp_id = (pj_uint8_t)pj_strtoul(&token); 700 698 701 699 /* Transport */ 702 token = strtok(NULL, " ");703 if ( !token) {700 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + token.slen); 701 if (found_idx == orig_input->slen) { 704 702 TRACE__((obj_name, "Expecting ICE transport in candidate")); 705 703 goto on_return; 706 704 } 707 if (pj_ ansi_stricmp(token, "UDP") != 0) {705 if (pj_stricmp2(&token, "UDP") != 0) { 708 706 TRACE__((obj_name, 709 707 "Expecting ICE UDP transport only in candidate")); … … 712 710 713 711 /* Priority */ 714 token = strtok(NULL, " ");715 if ( !token) {712 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + token.slen); 713 if (found_idx == orig_input->slen) { 716 714 TRACE__((obj_name, "Expecting ICE priority in candidate")); 717 715 goto on_return; 718 716 } 719 cand->prio = atoi(token);717 cand->prio = pj_strtoul(&token); 720 718 721 719 /* Host */ 722 host = strtok(NULL, " ");723 if ( !host) {720 found_idx = pj_strtok(orig_input, &delim, &host, found_idx + token.slen); 721 if (found_idx == orig_input->slen) { 724 722 TRACE__((obj_name, "Expecting ICE host in candidate")); 725 723 goto on_return; 726 724 } 727 725 /* Detect address family */ 728 if (pj_ ansi_strchr(host, ':'))726 if (pj_strchr(&host, ':')) 729 727 af = pj_AF_INET6(); 730 728 else 731 729 af = pj_AF_INET(); 732 730 /* Assign address */ 733 if (pj_sockaddr_init(af, &cand->addr, pj_cstr(&s, host), 0)) {731 if (pj_sockaddr_init(af, &cand->addr, &host, 0)) { 734 732 TRACE__((obj_name, "Invalid ICE candidate address")); 735 733 goto on_return; … … 737 735 738 736 /* Port */ 739 token = strtok(NULL, " ");740 if ( !token) {737 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + host.slen); 738 if (found_idx == orig_input->slen) { 741 739 TRACE__((obj_name, "Expecting ICE port number in candidate")); 742 740 goto on_return; 743 741 } 744 pj_sockaddr_set_port(&cand->addr, (pj_uint16_t) atoi(token));742 pj_sockaddr_set_port(&cand->addr, (pj_uint16_t)pj_strtoul(&token)); 745 743 746 744 /* typ */ 747 token = strtok(NULL, " ");748 if ( !token) {745 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + token.slen); 746 if (found_idx == orig_input->slen) { 749 747 TRACE__((obj_name, "Expecting ICE \"typ\" in candidate")); 750 748 goto on_return; 751 749 } 752 if (pj_ ansi_stricmp(token, "typ") != 0) {750 if (pj_stricmp2(&token, "typ") != 0) { 753 751 TRACE__((obj_name, "Expecting ICE \"typ\" in candidate")); 754 752 goto on_return; … … 756 754 757 755 /* candidate type */ 758 token = strtok(NULL, " ");759 if ( !token) {756 found_idx = pj_strtok(orig_input, &delim, &token, found_idx + token.slen); 757 if (found_idx == orig_input->slen) { 760 758 TRACE__((obj_name, "Expecting ICE candidate type in candidate")); 761 759 goto on_return; 762 760 } 763 761 764 if (pj_ ansi_stricmp(token, "host") == 0) {762 if (pj_stricmp2(&token, "host") == 0) { 765 763 cand->type = PJ_ICE_CAND_TYPE_HOST; 766 764 767 } else if (pj_ ansi_stricmp(token, "srflx") == 0) {765 } else if (pj_stricmp2(&token, "srflx") == 0) { 768 766 cand->type = PJ_ICE_CAND_TYPE_SRFLX; 769 767 770 } else if (pj_ ansi_stricmp(token, "relay") == 0) {768 } else if (pj_stricmp2(&token, "relay") == 0) { 771 769 cand->type = PJ_ICE_CAND_TYPE_RELAYED; 772 770 773 } else if (pj_ ansi_stricmp(token, "prflx") == 0) {771 } else if (pj_stricmp2(&token, "prflx") == 0) { 774 772 cand->type = PJ_ICE_CAND_TYPE_PRFLX; 775 773 776 774 } else { 777 PJ_LOG(5,(obj_name, "Invalid ICE candidate type % s in candidate",778 token ));775 PJ_LOG(5,(obj_name, "Invalid ICE candidate type %.*s in candidate", 776 token.slen, token.ptr)); 779 777 goto on_return; 780 778 } -
pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c
r5500 r5520 1217 1217 int *tag) 1218 1218 { 1219 pj_str_t input; 1220 char *token; 1221 pj_str_t tmp; 1219 pj_str_t token, delim; 1222 1220 pj_status_t status; 1223 int itmp, token_len;1221 int itmp, found_idx; 1224 1222 1225 1223 pj_bzero(crypto, sizeof(*crypto)); 1226 pj_strdup_with_null(pool, &input, &attr->value);1227 1224 1228 1225 /* Tag */ 1229 token = strtok(input.ptr, " "); 1230 if (!token) { 1226 delim = pj_str(" "); 1227 found_idx = pj_strtok(&attr->value, &delim, &token, 0); 1228 if (found_idx == attr->value.slen) { 1231 1229 PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting tag")); 1232 1230 return PJMEDIA_SDP_EINATTR; 1233 1231 } 1234 token_len = pj_ansi_strlen(token);1235 1232 1236 1233 /* Tag must not use leading zeroes. */ 1237 if (token _len > 1 && *token== '0')1234 if (token.slen > 1 && *token.ptr == '0') 1238 1235 return PJMEDIA_SDP_EINATTR; 1239 1236 1240 1237 /* Tag must be decimal, i.e: contains only digit '0'-'9'. */ 1241 for (itmp = 0; itmp < token _len; ++itmp)1242 if (!pj_isdigit(token [itmp]))1238 for (itmp = 0; itmp < token.slen; ++itmp) 1239 if (!pj_isdigit(token.ptr[itmp])) 1243 1240 return PJMEDIA_SDP_EINATTR; 1244 1241 1245 1242 /* Get tag value. */ 1246 *tag = atoi(token);1243 *tag = pj_strtoul(&token); 1247 1244 1248 1245 /* Crypto-suite */ 1249 token = strtok(NULL, " ");1250 if ( !token) {1246 found_idx = pj_strtok(&attr->value, &delim, &token, found_idx+token.slen); 1247 if (found_idx == attr->value.slen) { 1251 1248 PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting crypto suite")); 1252 1249 return PJMEDIA_SDP_EINATTR; 1253 1250 } 1254 crypto->name = pj_str(token);1251 crypto->name = token; 1255 1252 1256 1253 /* Key method */ 1257 token = strtok(NULL, ":"); 1258 if (!token) { 1254 delim = pj_str(": "); 1255 found_idx = pj_strtok(&attr->value, &delim, &token, found_idx+token.slen); 1256 if (found_idx == attr->value.slen) { 1259 1257 PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key method")); 1260 1258 return PJMEDIA_SDP_EINATTR; 1261 1259 } 1262 if (pj_ ansi_stricmp(token, "inline")) {1263 PJ_LOG(4,(THIS_FILE, "Attribute crypto key method '% s' not supported!",1264 token));1260 if (pj_stricmp2(&token, "inline")) { 1261 PJ_LOG(4,(THIS_FILE, "Attribute crypto key method '%.*s' " 1262 "not supported!", token.slen, token.ptr)); 1265 1263 return PJMEDIA_SDP_EINATTR; 1266 1264 } 1267 1265 1268 /* Key */ 1269 token = strtok(NULL, "| "); 1270 if (!token) { 1266 /* Key */ 1267 delim = pj_str("| "); 1268 found_idx = pj_strtok(&attr->value, &delim, &token, found_idx+token.slen); 1269 if (found_idx == attr->value.slen) { 1271 1270 PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key")); 1272 1271 return PJMEDIA_SDP_EINATTR; 1273 1272 } 1274 tmp = pj_str(token);1275 if (PJ_BASE64_TO_BASE256_LEN(t mp.slen) > MAX_KEY_LEN) {1273 1274 if (PJ_BASE64_TO_BASE256_LEN(token.slen) > MAX_KEY_LEN) { 1276 1275 PJ_LOG(4,(THIS_FILE, "Key too long")); 1277 1276 return PJMEDIA_SRTP_EINKEYLEN; … … 1281 1280 crypto->key.ptr = (char*) pj_pool_zalloc(pool, MAX_KEY_LEN); 1282 1281 itmp = MAX_KEY_LEN; 1283 status = pj_base64_decode(&t mp, (pj_uint8_t*)crypto->key.ptr,1282 status = pj_base64_decode(&token, (pj_uint8_t*)crypto->key.ptr, 1284 1283 &itmp); 1285 1284 if (status != PJ_SUCCESS) {
Note: See TracChangeset
for help on using the changeset viewer.