Ignore:
Timestamp:
Jan 11, 2017 4:38:29 AM (3 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_ice.c

    r5339 r5520  
    672672                              pj_ice_sess_cand *cand) 
    673673{ 
    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;     
    678676    pj_status_t status = PJNATH_EICEINCANDSDP; 
    679677 
    680678    pj_bzero(cand, sizeof(*cand)); 
    681     pj_strdup_with_null(pool, &input, orig_input); 
    682679 
    683680    PJ_UNUSED_ARG(obj_name); 
    684681 
    685682    /* 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) { 
    688686        TRACE__((obj_name, "Expecting ICE foundation in candidate")); 
    689687        goto on_return; 
    690688    } 
    691     pj_strdup2(pool, &cand->foundation, token); 
     689    pj_strdup(pool, &cand->foundation, &token); 
    692690 
    693691    /* 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) { 
    696694        TRACE__((obj_name, "Expecting ICE component ID in candidate")); 
    697695        goto on_return; 
    698696    } 
    699     cand->comp_id = (pj_uint8_t) atoi(token); 
     697    cand->comp_id = (pj_uint8_t)pj_strtoul(&token); 
    700698 
    701699    /* 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) { 
    704702        TRACE__((obj_name, "Expecting ICE transport in candidate")); 
    705703        goto on_return; 
    706704    } 
    707     if (pj_ansi_stricmp(token, "UDP") != 0) { 
     705    if (pj_stricmp2(&token, "UDP") != 0) { 
    708706        TRACE__((obj_name,  
    709707                 "Expecting ICE UDP transport only in candidate")); 
     
    712710 
    713711    /* 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) { 
    716714        TRACE__((obj_name, "Expecting ICE priority in candidate")); 
    717715        goto on_return; 
    718716    } 
    719     cand->prio = atoi(token); 
     717    cand->prio = pj_strtoul(&token); 
    720718 
    721719    /* 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) { 
    724722        TRACE__((obj_name, "Expecting ICE host in candidate")); 
    725723        goto on_return; 
    726724    } 
    727725    /* Detect address family */ 
    728     if (pj_ansi_strchr(host, ':')) 
     726    if (pj_strchr(&host, ':')) 
    729727        af = pj_AF_INET6(); 
    730728    else 
    731729        af = pj_AF_INET(); 
    732730    /* 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)) { 
    734732        TRACE__((obj_name, "Invalid ICE candidate address")); 
    735733        goto on_return; 
     
    737735 
    738736    /* 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) { 
    741739        TRACE__((obj_name, "Expecting ICE port number in candidate")); 
    742740        goto on_return; 
    743741    } 
    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)); 
    745743 
    746744    /* 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) { 
    749747        TRACE__((obj_name, "Expecting ICE \"typ\" in candidate")); 
    750748        goto on_return; 
    751749    } 
    752     if (pj_ansi_stricmp(token, "typ") != 0) { 
     750    if (pj_stricmp2(&token, "typ") != 0) { 
    753751        TRACE__((obj_name, "Expecting ICE \"typ\" in candidate")); 
    754752        goto on_return; 
     
    756754 
    757755    /* 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) { 
    760758        TRACE__((obj_name, "Expecting ICE candidate type in candidate")); 
    761759        goto on_return; 
    762760    } 
    763761 
    764     if (pj_ansi_stricmp(token, "host") == 0) { 
     762    if (pj_stricmp2(&token, "host") == 0) { 
    765763        cand->type = PJ_ICE_CAND_TYPE_HOST; 
    766764 
    767     } else if (pj_ansi_stricmp(token, "srflx") == 0) { 
     765    } else if (pj_stricmp2(&token, "srflx") == 0) { 
    768766        cand->type = PJ_ICE_CAND_TYPE_SRFLX; 
    769767 
    770     } else if (pj_ansi_stricmp(token, "relay") == 0) { 
     768    } else if (pj_stricmp2(&token, "relay") == 0) { 
    771769        cand->type = PJ_ICE_CAND_TYPE_RELAYED; 
    772770 
    773     } else if (pj_ansi_stricmp(token, "prflx") == 0) { 
     771    } else if (pj_stricmp2(&token, "prflx") == 0) { 
    774772        cand->type = PJ_ICE_CAND_TYPE_PRFLX; 
    775773 
    776774    } 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)); 
    779777        goto on_return; 
    780778    } 
Note: See TracChangeset for help on using the changeset viewer.