Changeset 1559


Ignore:
Timestamp:
Nov 8, 2007 9:13:34 AM (16 years ago)
Author:
bennylp
Message:

Parse ICE SDP attribute without case sensitivity, and ignore malformed candidate line for more robustness

File:
1 edited

Legend:

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

    r1557 r1559  
    2323#include <pj/rand.h> 
    2424 
     25#define THIS_FILE   "transport_ice.c" 
    2526 
    2627struct transport_ice 
     
    349350    /* Foundation */ 
    350351    token = strtok(input.ptr, " "); 
    351     if (!token) 
    352         goto on_return; 
     352    if (!token) { 
     353        PJ_LOG(5,(THIS_FILE, "Expecting ICE foundation in candidate")); 
     354        goto on_return; 
     355    } 
    353356    pj_strdup2(pool, &cand->foundation, token); 
    354357 
    355358    /* Component ID */ 
    356359    token = strtok(NULL, " "); 
    357     if (!token) 
    358         goto on_return; 
     360    if (!token) { 
     361        PJ_LOG(5,(THIS_FILE, "Expecting ICE component ID in candidate")); 
     362        goto on_return; 
     363    } 
    359364    cand->comp_id = atoi(token); 
    360365 
    361366    /* Transport */ 
    362367    token = strtok(NULL, " "); 
    363     if (!token) 
    364         goto on_return; 
    365     if (pj_ansi_stricmp(token, "UDP") != 0) 
    366         goto on_return; 
     368    if (!token) { 
     369        PJ_LOG(5,(THIS_FILE, "Expecting ICE transport in candidate")); 
     370        goto on_return; 
     371    } 
     372    if (pj_ansi_stricmp(token, "UDP") != 0) { 
     373        PJ_LOG(5,(THIS_FILE,  
     374                  "Expecting ICE UDP transport only in candidate")); 
     375        goto on_return; 
     376    } 
    367377 
    368378    /* Priority */ 
    369379    token = strtok(NULL, " "); 
    370     if (!token) 
    371         goto on_return; 
     380    if (!token) { 
     381        PJ_LOG(5,(THIS_FILE, "Expecting ICE priority in candidate")); 
     382        goto on_return; 
     383    } 
    372384    cand->prio = atoi(token); 
    373385 
    374386    /* Host */ 
    375387    host = strtok(NULL, " "); 
    376     if (!host) 
    377         goto on_return; 
    378     if (pj_sockaddr_in_init(&cand->addr.ipv4, pj_cstr(&s, host), 0)) 
    379         goto on_return; 
     388    if (!host) { 
     389        PJ_LOG(5,(THIS_FILE, "Expecting ICE host in candidate")); 
     390        goto on_return; 
     391    } 
     392    if (pj_sockaddr_in_init(&cand->addr.ipv4, pj_cstr(&s, host), 0)) { 
     393        PJ_LOG(5,(THIS_FILE,  
     394                  "Expecting ICE IPv4 transport address in candidate")); 
     395        goto on_return; 
     396    } 
    380397 
    381398    /* Port */ 
    382399    token = strtok(NULL, " "); 
    383     if (!token) 
    384         goto on_return; 
     400    if (!token) { 
     401        PJ_LOG(5,(THIS_FILE, "Expecting ICE port number in candidate")); 
     402        goto on_return; 
     403    } 
    385404    cand->addr.ipv4.sin_port = pj_htons((pj_uint16_t)atoi(token)); 
    386405 
    387406    /* typ */ 
    388407    token = strtok(NULL, " "); 
    389     if (!token) 
    390         goto on_return; 
    391     if (pj_ansi_stricmp(token, "typ") != 0) 
    392         goto on_return; 
     408    if (!token) { 
     409        PJ_LOG(5,(THIS_FILE, "Expecting ICE \"typ\" in candidate")); 
     410        goto on_return; 
     411    } 
     412    if (pj_ansi_stricmp(token, "typ") != 0) { 
     413        PJ_LOG(5,(THIS_FILE, "Expecting ICE \"typ\" in candidate")); 
     414        goto on_return; 
     415    } 
    393416 
    394417    /* candidate type */ 
    395418    token = strtok(NULL, " "); 
    396     if (!token) 
    397         goto on_return; 
     419    if (!token) { 
     420        PJ_LOG(5,(THIS_FILE, "Expecting ICE candidate type in candidate")); 
     421        goto on_return; 
     422    } 
    398423 
    399424    if (pj_ansi_stricmp(token, "host") == 0) { 
     
    410435 
    411436    } else { 
     437        PJ_LOG(5,(THIS_FILE, "Invalid ICE candidate type %s in candidate",  
     438                  token)); 
    412439        goto on_return; 
    413440    } 
     
    527554        /* Parse candidate */ 
    528555        status = parse_cand(pool, &attr->value, &cand[cand_cnt]); 
    529         if (status != PJ_SUCCESS) 
    530             return status; 
     556        if (status != PJ_SUCCESS) { 
     557            PJ_LOG(4,(THIS_FILE,  
     558                      "Error in parsing SDP candidate attribute, " 
     559                      "candidate is ignored")); 
     560            continue; 
     561        } 
    531562 
    532563        /* Check if this candidate is equal to the connection line */ 
Note: See TracChangeset for help on using the changeset viewer.