Ignore:
Timestamp:
Jan 11, 2017 4:38:29 AM (7 years ago)
Author:
riza
Message:

Re 1989: Implement pj_strtok()/pj_strtok() as a replacement to strtok().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c

    r5500 r5520  
    12171217                                     int *tag) 
    12181218{ 
    1219     pj_str_t input; 
    1220     char *token; 
    1221     pj_str_t tmp; 
     1219    pj_str_t token, delim; 
    12221220    pj_status_t status; 
    1223     int itmp, token_len; 
     1221    int itmp, found_idx; 
    12241222 
    12251223    pj_bzero(crypto, sizeof(*crypto)); 
    1226     pj_strdup_with_null(pool, &input, &attr->value); 
    12271224 
    12281225    /* 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) { 
    12311229        PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting tag")); 
    12321230        return PJMEDIA_SDP_EINATTR; 
    12331231    } 
    1234     token_len = pj_ansi_strlen(token); 
    12351232 
    12361233    /* Tag must not use leading zeroes. */ 
    1237     if (token_len > 1 && *token == '0') 
     1234    if (token.slen > 1 && *token.ptr == '0') 
    12381235        return PJMEDIA_SDP_EINATTR; 
    12391236 
    12401237    /* 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])) 
    12431240            return PJMEDIA_SDP_EINATTR; 
    12441241 
    12451242    /* Get tag value. */ 
    1246     *tag = atoi(token); 
     1243    *tag = pj_strtoul(&token); 
    12471244 
    12481245    /* 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) { 
    12511248        PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting crypto suite")); 
    12521249        return PJMEDIA_SDP_EINATTR; 
    12531250    } 
    1254     crypto->name = pj_str(token); 
     1251    crypto->name = token; 
    12551252 
    12561253    /* 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) { 
    12591257        PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key method")); 
    12601258        return PJMEDIA_SDP_EINATTR; 
    12611259    } 
    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)); 
    12651263        return PJMEDIA_SDP_EINATTR; 
    12661264    } 
    12671265 
    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) { 
    12711270        PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key")); 
    12721271        return PJMEDIA_SDP_EINATTR; 
    12731272    } 
    1274     tmp = pj_str(token); 
    1275     if (PJ_BASE64_TO_BASE256_LEN(tmp.slen) > MAX_KEY_LEN) { 
     1273     
     1274    if (PJ_BASE64_TO_BASE256_LEN(token.slen) > MAX_KEY_LEN) { 
    12761275        PJ_LOG(4,(THIS_FILE, "Key too long")); 
    12771276        return PJMEDIA_SRTP_EINKEYLEN; 
     
    12811280    crypto->key.ptr = (char*) pj_pool_zalloc(pool, MAX_KEY_LEN); 
    12821281    itmp = MAX_KEY_LEN; 
    1283     status = pj_base64_decode(&tmp, (pj_uint8_t*)crypto->key.ptr, 
     1282    status = pj_base64_decode(&token, (pj_uint8_t*)crypto->key.ptr, 
    12841283                              &itmp); 
    12851284    if (status != PJ_SUCCESS) { 
Note: See TracChangeset for help on using the changeset viewer.