Changeset 1101


Ignore:
Timestamp:
Mar 24, 2007 1:00:30 PM (17 years ago)
Author:
bennylp
Message:

ICE (work in progress): implement error codes

Location:
pjproject/trunk
Files:
14 edited

Legend:

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

    r1099 r1101  
    198198 
    199199    /* Add all candidates (to media level) */ 
    200     cand_cnt = pj_ice_get_cand_cnt(tp_ice->ice_st->ice); 
     200    cand_cnt = tp_ice->ice_st->ice->lcand_cnt; 
    201201    for (i=0; i<cand_cnt; ++i) { 
    202202        pj_ice_cand *cand; 
     
    204204        int len; 
    205205 
    206         pj_ice_get_cand(tp_ice->ice_st->ice, i, &cand); 
     206        cand = &tp_ice->ice_st->ice->lcand[i]; 
    207207 
    208208        len = pj_ansi_snprintf( buffer, MAXLEN, 
     
    266266    char *token, *host; 
    267267    pj_str_t s; 
    268     pj_status_t status = PJ_EICEINCANDSDP; 
     268    pj_status_t status = PJNATH_EICEINCANDSDP; 
    269269 
    270270    pj_bzero(cand, sizeof(*cand)); 
     
    342342on_return: 
    343343    return status; 
     344} 
     345 
     346static void set_no_ice(struct transport_ice *tp_ice) 
     347{ 
     348    PJ_LOG(4,(tp_ice->ice_st->obj_name,  
     349              "Remote does not support ICE, disabling local ICE")); 
     350    pjmedia_ice_stop_ice(&tp_ice->base); 
    344351} 
    345352 
     
    359366    attr = pjmedia_sdp_attr_find2(rem_sdp->attr_count, rem_sdp->attr, 
    360367                                  "ice-ufrag", NULL); 
    361     if (attr == NULL) 
    362         return PJ_EICEMISSINGSDP; 
     368    if (attr == NULL) { 
     369        set_no_ice(tp_ice); 
     370        return PJ_SUCCESS; 
     371    } 
    363372    uname = attr->value; 
    364373 
     
    366375    attr = pjmedia_sdp_attr_find2(rem_sdp->attr_count, rem_sdp->attr, 
    367376                                  "ice-pwd", NULL); 
    368     if (attr == NULL) 
    369         return PJ_EICEMISSINGSDP; 
     377    if (attr == NULL) { 
     378        set_no_ice(tp_ice); 
     379        return PJ_SUCCESS; 
     380    } 
    370381    pass = attr->value; 
    371382 
     
    547558    PJ_TIME_VAL_SUB(end_ice, tp_ice->start_ice); 
    548559 
    549     check = &ice_st->ice->clist.checks[ice_st->ice->valid_list[0]]; 
     560    check = &ice_st->ice->valid_list.checks[0]; 
    550561     
    551562    lcand = check->lcand; 
  • pjproject/trunk/pjnath/build/pjnath.dsp

    r1096 r1101  
    4242# PROP Target_Dir "" 
    4343# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    44 # ADD CPP /nologo /MD /W4 /GX /Zi /O2 /Ob2 /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /c 
    45 # SUBTRACT CPP /YX 
     44# ADD CPP /nologo /MD /W4 /GX /O1 /Ob2 /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /c 
     45# SUBTRACT CPP /Z<none> /YX 
    4646# ADD BASE RSC /l 0x409 /d "NDEBUG" 
    4747# ADD RSC /l 0x409 /d "NDEBUG" 
  • pjproject/trunk/pjnath/include/pjnath.h

    r1096 r1101  
    2828#include <pjnath/stun_transaction.h> 
    2929#include <pjnath/types.h> 
     30 
  • pjproject/trunk/pjnath/include/pjnath/errno.h

    r1099 r1101  
    2424 
    2525/** 
    26  * @defgroup PJNATH_ERROR NAT Helper Error Codes 
     26 * @defgroup PJNATH_ERROR NAT Helper Library Error Codes 
    2727 * @ingroup PJNATH 
    2828 * @{ 
     
    3636 
    3737 
     38/************************************************************ 
     39 * STUN MESSAGING ERRORS 
     40 ***********************************************************/ 
    3841 
    39 /************************************************************ 
    40  * NEW STUN ERROR 
    41  ***********************************************************/ 
    42 /* Messaging errors */ 
    43 #define PJNATH_ESTUNINATTRLEN       -1 
    44 #define PJNATH_ESTUNINMSGLEN        -1 
    45 #define PJNATH_ESTUNINMSGTYPE       -1 
    46 #define PJNATH_ESTUNFINGERPRINT     -1 
    47 #define PJNATH_ESTUNNOTRESPOND      -1 
    48 #define PJNATH_ESTUNNOXORMAP        -1 
     42/** 
     43 * Map STUN error code (300-699) into pj_status_t error space. 
     44 */ 
     45#define PJ_STATUS_FROM_STUN_CODE(code)  (PJNATH_ERRNO_START+code) 
     46 
     47/** 
     48 * @hideinitializer 
     49 * Invalid STUN message length. 
     50 */ 
     51#define PJNATH_EINSTUNMSGLEN        (PJNATH_ERRNO_START+1)  /* 370001 */ 
     52/** 
     53 * @hideinitializer 
     54 * Invalid or unexpected STUN message type 
     55 */ 
     56#define PJNATH_EINSTUNMSGTYPE       (PJNATH_ERRNO_START+2)  /* 370002 */ 
     57/** 
     58 * @hideinitializer 
     59 * STUN transaction has timed out 
     60 */ 
     61#define PJNATH_ESTUNTIMEDOUT        (PJNATH_ERRNO_START+3)  /* 370003 */ 
     62 
     63 
    4964 
    5065/** 
     
    5267 * Too many STUN attributes. 
    5368 */ 
    54 #define PJNATH_ESTUNTOOMANYATTR     (PJNATH_ERRNO_START+110)/* 370110 */ 
     69#define PJNATH_ESTUNTOOMANYATTR     (PJNATH_ERRNO_START+21) /* 370021 */ 
    5570/** 
    5671 * @hideinitializer 
    57  * Unknown STUN attribute. This error happens when the decoder encounters 
    58  * mandatory attribute type which it doesn't understand. 
     72 * Invalid STUN attribute length. 
    5973 */ 
    60 #define PJNATH_ESTUNUNKNOWNATTR     (PJNATH_ERRNO_START+111)/* 370111 */ 
     74#define PJNATH_ESTUNINATTRLEN       (PJNATH_ERRNO_START+22) /* 370022 */ 
    6175/** 
    6276 * @hideinitializer 
    63  * Invalid STUN socket address length. 
     77 * Found duplicate STUN attribute. 
    6478 */ 
    65 #define PJNATH_ESTUNINADDRLEN       (PJNATH_ERRNO_START+112)/* 370112 */ 
     79#define PJNATH_ESTUNDUPATTR         (PJNATH_ERRNO_START+23) /* 370023 */ 
     80 
     81/** 
     82 * @hideinitializer 
     83 * STUN FINGERPRINT verification failed 
     84 */ 
     85#define PJNATH_ESTUNFINGERPRINT     (PJNATH_ERRNO_START+30) /* 370030 */ 
     86/** 
     87 * @hideinitializer 
     88 * Invalid STUN attribute after MESSAGE-INTEGRITY. 
     89 */ 
     90#define PJNATH_ESTUNMSGINTPOS       (PJNATH_ERRNO_START+31) /* 370031 */ 
     91/** 
     92 * @hideinitializer 
     93 * Invalid STUN attribute after FINGERPRINT. 
     94 */ 
     95#define PJNATH_ESTUNFINGERPOS       (PJNATH_ERRNO_START+33) /* 370033 */ 
     96 
     97 
     98/** 
     99 * @hideinitializer 
     100 * STUN (XOR-)MAPPED-ADDRESS attribute not found 
     101 */ 
     102#define PJNATH_ESTUNNOMAPPEDADDR    (PJNATH_ERRNO_START+40) /* 370040 */ 
    66103/** 
    67104 * @hideinitializer 
    68105 * STUN IPv6 attribute not supported 
    69106 */ 
    70 #define PJNATH_ESTUNIPV6NOTSUPP     (PJNATH_ERRNO_START+113)/* 370113 */ 
    71 /** 
    72  * @hideinitializer 
    73  * Expecting STUN response message. 
    74  */ 
    75 #define PJNATH_ESTUNNOTRESPONSE     (PJNATH_ERRNO_START+114)/* 370114 */ 
    76 /** 
    77  * @hideinitializer 
    78  * STUN transaction ID mismatch. 
    79  */ 
    80 #define PJNATH_ESTUNINVALIDID       (PJNATH_ERRNO_START+115)/* 370115 */ 
    81 /** 
    82  * @hideinitializer 
    83  * Unable to find handler for the request. 
    84  */ 
    85 #define PJNATH_ESTUNNOHANDLER       (PJNATH_ERRNO_START+116)/* 370116 */ 
    86 /** 
    87  * @hideinitializer 
    88  * Found non-FINGERPRINT attribute after MESSAGE-INTEGRITY. This is not 
    89  * valid since MESSAGE-INTEGRITY MUST be the last attribute or the 
    90  * attribute right before FINGERPRINT before the message. 
    91  */ 
    92 #define PJNATH_ESTUNMSGINTPOS       (PJNATH_ERRNO_START+118)/* 370118 */ 
    93 /** 
    94  * @hideinitializer 
    95  * Found attribute after FINGERPRINT. This is not valid since FINGERPRINT 
    96  * MUST be the last attribute in the message. 
    97  */ 
    98 #define PJNATH_ESTUNFINGERPOS       (PJNATH_ERRNO_START+119)/* 370119 */ 
    99 /** 
    100  * @hideinitializer 
    101  * Missing STUN USERNAME attribute. 
    102  * When credential is included in the STUN message (MESSAGE-INTEGRITY is 
    103  * present), the USERNAME attribute must be present in the message. 
    104  */ 
    105 #define PJNATH_ESTUNNOUSERNAME      (PJNATH_ERRNO_START+120)/* 370120 */ 
    106 /** 
    107  * @hideinitializer 
    108  * Unknown STUN username/credential. 
    109  */ 
    110 #define PJNATH_ESTUNUSERNAME        (PJNATH_ERRNO_START+121)/* 370121 */ 
    111 /** 
    112  * @hideinitializer 
    113  * Missing/invalidSTUN MESSAGE-INTEGRITY attribute. 
    114  */ 
    115 #define PJNATH_ESTUNMSGINT          (PJNATH_ERRNO_START+122)/* 370122 */ 
    116 /** 
    117  * @hideinitializer 
    118  * Found duplicate STUN attribute. 
    119  */ 
    120 #define PJNATH_ESTUNDUPATTR         (PJNATH_ERRNO_START+123)/* 370123 */ 
    121 /** 
    122  * @hideinitializer 
    123  * Missing STUN REALM attribute. 
    124  */ 
    125 #define PJNATH_ESTUNNOREALM         (PJNATH_ERRNO_START+124)/* 370124 */ 
    126 /** 
    127  * @hideinitializer 
    128  * Missing/stale STUN NONCE attribute value. 
    129  */ 
    130 #define PJNATH_ESTUNNONCE           (PJNATH_ERRNO_START+125)/* 370125 */ 
    131 /** 
    132  * @hideinitializer 
    133  * STUN transaction terminates with failure. 
    134  */ 
    135 #define PJNATH_ESTUNTSXFAILED       (PJNATH_ERRNO_START+126)/* 370126 */ 
    136 /** 
    137  * @hideinitializer 
    138  * STUN mapped address attribute not found 
    139  */ 
    140 #define PJNATH_ESTUNNOMAPPEDADDR    (PJNATH_ERRNO_START+127)/* 370127 */ 
     107#define PJNATH_ESTUNIPV6NOTSUPP     (PJNATH_ERRNO_START+41) /* 370041 */ 
    141108 
    142109 
    143 //#define PJ_STATUS_FROM_STUN_CODE(code)        (PJNATH_ERRNO_START+code) 
    144110 
     111 
     112/************************************************************ 
     113 * ICE ERROR CODES 
     114 ***********************************************************/ 
    145115 
    146116/** 
    147117 * @hideinitializer 
    148  * No ICE checklist is formed. 
     118 * ICE session not available 
    149119 */ 
    150 #define PJ_EICENOCHECKLIST          -1 
     120#define PJNATH_ENOICE               (PJNATH_ERRNO_START+80) /* 370080 */ 
    151121/** 
    152122 * @hideinitializer 
    153  * No suitable default ICE candidate for the component. 
     123 * ICE check is in progress 
    154124 */ 
    155 #define PJ_EICENOCAND               -1 
     125#define PJNATH_EICEINPROGRESS       (PJNATH_ERRNO_START+81) /* 370081 */ 
     126/** 
     127 * @hideinitializer 
     128 * All ICE checklists failed 
     129 */ 
     130#define PJNATH_EICEFAILED           (PJNATH_ERRNO_START+82) /* 370082 */ 
    156131/** 
    157132 * @hideinitializer 
    158133 * Invalid ICE component ID 
    159134 */ 
    160 #define PJ_EICEINCOMPID             -1 
     135#define PJNATH_EICEINCOMPID         (PJNATH_ERRNO_START+86) /* 370086 */ 
    161136/** 
    162137 * @hideinitializer 
    163138 * Invalid ICE candidate ID 
    164139 */ 
    165 #define PJ_EICEINCANDID             -1 
    166 /** 
    167  * @hideinitializer 
    168  * ICE session not available 
    169  */ 
    170 #define PJ_ENOICE                   -1 
    171 /** 
    172  * @hideinitializer 
    173  * ICE check is in progress 
    174  */ 
    175 #define PJ_EICEINPROGRESS           -1 
     140#define PJNATH_EICEINCANDID         (PJNATH_ERRNO_START+87) /* 370087 */ 
    176141/** 
    177142 * @hideinitializer 
    178143 * Missing ICE SDP attribute 
    179144 */ 
    180 #define PJ_EICEMISSINGSDP           -1 
     145#define PJNATH_EICEMISSINGSDP       (PJNATH_ERRNO_START+90) /* 370090 */ 
    181146/** 
    182147 * @hideinitializer 
    183148 * Invalid SDP "candidate" attribute 
    184149 */ 
    185 #define PJ_EICEINCANDSDP            -1 
     150#define PJNATH_EICEINCANDSDP        (PJNATH_ERRNO_START+91) /* 370091 */ 
    186151 
    187152 
  • pjproject/trunk/pjnath/include/pjnath/ice.h

    r1096 r1101  
    9797    pj_sockaddr          addr; 
    9898    pj_sockaddr          base_addr; 
    99     pj_sockaddr          srv_addr; 
     99    pj_sockaddr          rel_addr; 
    100100    pj_stun_session     *stun_sess; 
    101101} pj_ice_cand; 
     
    205205     
    206206    /* Valid list */ 
    207     unsigned             valid_cnt; 
    208     unsigned             valid_list[PJ_ICE_MAX_CHECKS]; 
     207    pj_ice_checklist     valid_list; 
    209208}; 
    210209 
     
    213212                                   const char *name, 
    214213                                   pj_ice_role role, 
     214                                   unsigned comp_cnt, 
    215215                                   const pj_ice_cb *cb, 
    216216                                   const pj_str_t *local_ufrag, 
     
    218218                                   pj_ice **p_ice); 
    219219PJ_DECL(pj_status_t) pj_ice_destroy(pj_ice *ice); 
    220 PJ_DECL(pj_status_t) pj_ice_add_comp(pj_ice *ice, unsigned comp_id); 
    221220PJ_DECL(pj_status_t) pj_ice_add_cand(pj_ice *ice, 
    222221                                     unsigned comp_id, 
     
    226225                                     const pj_sockaddr_t *addr, 
    227226                                     const pj_sockaddr_t *base_addr, 
    228                                      const pj_sockaddr_t *srv_addr, 
     227                                     const pj_sockaddr_t *rel_addr, 
    229228                                     int addr_len, 
    230229                                     unsigned *cand_id); 
    231230 
    232 PJ_DECL(unsigned) pj_ice_get_cand_cnt(pj_ice *ice); 
    233 PJ_DECL(pj_status_t) pj_ice_enum_cands(pj_ice *ice, 
    234                                        unsigned *p_count, 
    235                                        unsigned cand_ids[]); 
    236 PJ_DECL(pj_status_t) pj_ice_get_default_cand(pj_ice *ice, 
    237                                              unsigned comp_id, 
    238                                              int *cand_id); 
    239 PJ_DECL(pj_status_t) pj_ice_get_cand(pj_ice *ice, 
    240                                      unsigned cand_id, 
    241                                      pj_ice_cand **p_cand); 
     231PJ_DECL(pj_status_t) pj_ice_find_default_cand(pj_ice *ice, 
     232                                              unsigned comp_id, 
     233                                              int *cand_id); 
    242234 
    243235PJ_DECL(pj_status_t) pj_ice_create_check_list(pj_ice *ice, 
  • pjproject/trunk/pjnath/include/pjnath/stun_msg.h

    r1085 r1101  
    384384    PJ_STUN_SC_STALE_NONCE              = 438,  /**< Stale Nonce            */ 
    385385    PJ_STUN_SC_TRANSITIONING            = 439,  /**< Transitioning.         */ 
    386     PJ_STUN_SC_WRONG_USERNAME           = 441,  /**< Wrong Username.        */ 
    387386    PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO   = 442,  /**< Unsupported Transport or 
    388387                                                     Protocol */ 
  • pjproject/trunk/pjnath/include/pjnath/types.h

    r1080 r1101  
    3030/** 
    3131 * @defgroup PJNATH NAT Helper Library 
     32 * @{ 
    3233 */ 
     34 
     35PJ_BEGIN_DECL 
     36 
     37/** 
     38 * Initialize pjnath library. 
     39 * 
     40 * @return  Initialization status. 
     41 */ 
     42PJ_DECL(pj_status_t) pjnath_init(void); 
     43 
     44 
     45PJ_END_DECL 
     46 
     47/** 
     48 * @} 
     49 */ 
     50 
     51/* Doxygen documentation below: */ 
    3352 
    3453/** 
     
    4463 * of modules. 
    4564 * 
    46  * 
    47  * \n 
    48  * \n 
    49  * \n 
    50  * \n 
    51  * \n 
    52  * \n 
    53  * \n 
    54  * \n 
    55  * \n 
    56  * \n 
    57  * \n 
    58  * \n 
    59  * \n 
    6065 */ 
    6166 
  • pjproject/trunk/pjnath/src/pjnath/errno.c

    r1080 r1101  
    1818 */ 
    1919#include <pjnath/errno.h> 
     20#include <pjnath/stun_msg.h> 
    2021#include <pj/string.h> 
    2122 
     
    3334} err_str[] =  
    3435{ 
    35     /* STUN */ 
     36    /* STUN related error codes */ 
     37    PJ_BUILD_ERR( PJNATH_EINSTUNMSGLEN,     "Invalid STUN message length"), 
     38    PJ_BUILD_ERR( PJNATH_EINSTUNMSGTYPE,    "Invalid or unexpected STUN message type"), 
     39    PJ_BUILD_ERR( PJNATH_ESTUNTIMEDOUT,     "STUN transaction has timed out"), 
     40 
    3641    PJ_BUILD_ERR( PJNATH_ESTUNTOOMANYATTR,  "Too many STUN attributes"), 
    37     PJ_BUILD_ERR( PJNATH_ESTUNUNKNOWNATTR,  "Unknown STUN attribute"), 
    38     PJ_BUILD_ERR( PJNATH_ESTUNINADDRLEN,    "Invalid STUN socket address length"), 
     42    PJ_BUILD_ERR( PJNATH_ESTUNINATTRLEN,    "Invalid STUN attribute length"), 
     43    PJ_BUILD_ERR( PJNATH_ESTUNDUPATTR,      "Found duplicate STUN attribute"), 
     44 
     45    PJ_BUILD_ERR( PJNATH_ESTUNFINGERPRINT,  "STUN FINGERPRINT verification failed"), 
     46    PJ_BUILD_ERR( PJNATH_ESTUNMSGINTPOS,    "Invalid STUN attribute after MESSAGE-INTEGRITY"), 
     47    PJ_BUILD_ERR( PJNATH_ESTUNFINGERPOS,    "Invalid STUN attribute after FINGERPRINT"), 
     48 
     49    PJ_BUILD_ERR( PJNATH_ESTUNNOMAPPEDADDR, "STUN (XOR-)MAPPED-ADDRESS attribute not found"), 
    3950    PJ_BUILD_ERR( PJNATH_ESTUNIPV6NOTSUPP,  "STUN IPv6 attribute not supported"), 
    40     PJ_BUILD_ERR( PJNATH_ESTUNNOTRESPONSE,  "Expecting STUN response message"), 
    41     PJ_BUILD_ERR( PJNATH_ESTUNINVALIDID,    "STUN transaction ID mismatch"), 
    42     PJ_BUILD_ERR( PJNATH_ESTUNNOHANDLER,    "Unable to find STUN handler for the request"), 
    43     PJ_BUILD_ERR( PJNATH_ESTUNMSGINTPOS,    "Found non-FINGERPRINT attr. after MESSAGE-INTEGRITY"), 
    44     PJ_BUILD_ERR( PJNATH_ESTUNFINGERPOS,    "Found STUN attribute after FINGERPRINT"), 
    45     PJ_BUILD_ERR( PJNATH_ESTUNNOUSERNAME,   "Missing STUN USERNAME attribute"), 
    46     PJ_BUILD_ERR( PJNATH_ESTUNMSGINT,       "Missing/invalid STUN MESSAGE-INTEGRITY attribute"), 
    47     PJ_BUILD_ERR( PJNATH_ESTUNDUPATTR,      "Found duplicate STUN attribute"), 
    48     PJ_BUILD_ERR( PJNATH_ESTUNNOREALM,      "Missing STUN REALM attribute"), 
    49     PJ_BUILD_ERR( PJNATH_ESTUNNONCE,        "Missing/stale STUN NONCE attribute value"), 
    50     PJ_BUILD_ERR( PJNATH_ESTUNTSXFAILED,    "STUN transaction terminates with failure"), 
     51 
     52    /* ICE related errors */ 
     53    PJ_BUILD_ERR( PJNATH_ENOICE,            "ICE session not available"), 
     54    PJ_BUILD_ERR( PJNATH_EICEINPROGRESS,    "ICE check is in progress"), 
     55    PJ_BUILD_ERR( PJNATH_EICEFAILED,        "All ICE checklists failed"), 
     56    PJ_BUILD_ERR( PJNATH_EICEINCOMPID,      "Invalid ICE component ID"), 
     57    PJ_BUILD_ERR( PJNATH_EICEINCANDID,      "Invalid ICE candidate ID"), 
     58    PJ_BUILD_ERR( PJNATH_EICEMISSINGSDP,    "Missing ICE SDP attribute"), 
     59    PJ_BUILD_ERR( PJNATH_EICEINCANDSDP,     "Invalid SDP \"candidate\" attribute"), 
     60 
    5161}; 
    5262#endif  /* PJ_HAS_ERROR_STRING */ 
     
    5666 * pjnath_strerror() 
    5767 */ 
    58 PJ_DEF(pj_str_t) pjnath_strerror( pj_status_t statcode,  
    59                                   char *buf, pj_size_t bufsize ) 
     68static pj_str_t pjnath_strerror(pj_status_t statcode,  
     69                                char *buf, pj_size_t bufsize ) 
    6070{ 
    6171    pj_str_t errstr; 
     
    107117    errstr.ptr = buf; 
    108118    errstr.slen = pj_ansi_snprintf(buf, bufsize,  
    109                                    "Unknown pjlib-util error %d", 
     119                                   "Unknown pjnath error %d", 
    110120                                   statcode); 
     121    if (errstr.slen < 0) errstr.slen = 0; 
     122    else if (errstr.slen > (int)bufsize) errstr.slen = bufsize; 
     123 
     124    return errstr; 
     125} 
     126 
     127 
     128static pj_str_t pjnath_strerror2(pj_status_t statcode,  
     129                                 char *buf, pj_size_t bufsize ) 
     130{ 
     131    int stun_code = statcode - PJ_STATUS_FROM_STUN_CODE(0); 
     132    const pj_str_t cmsg = pj_stun_get_err_reason(stun_code); 
     133    pj_str_t errstr; 
     134 
     135    if (cmsg.slen == 0) { 
     136        /* Not found */ 
     137        errstr.ptr = buf; 
     138        errstr.slen = pj_ansi_snprintf(buf, bufsize,  
     139                                       "Unknown STUN err-code %d", 
     140                                       stun_code); 
     141    } else { 
     142        errstr.ptr = buf; 
     143        pj_strncpy(&errstr, &cmsg, bufsize); 
     144    } 
     145 
     146    if (errstr.slen < 0) errstr.slen = 0; 
     147    else if (errstr.slen > (int)bufsize) errstr.slen = bufsize; 
    111148 
    112149    return errstr; 
     
    116153PJ_DEF(pj_status_t) pjnath_init(void) 
    117154{ 
    118     return pj_register_strerror(PJNATH_ERRNO_START,  
    119                                 PJ_ERRNO_SPACE_SIZE,  
    120                                 &pjnath_strerror); 
     155    pj_status_t status; 
     156 
     157    status = pj_register_strerror(PJNATH_ERRNO_START, 299,  
     158                                  &pjnath_strerror); 
     159    if (status != PJ_SUCCESS) 
     160        return status; 
     161 
     162    status = pj_register_strerror(PJ_STATUS_FROM_STUN_CODE(300),  
     163                                  699 - 300,  
     164                                  &pjnath_strerror2); 
     165    return status; 
    121166} 
     167 
  • pjproject/trunk/pjnath/src/pjnath/ice.c

    r1099 r1101  
    5858 
    5959#define CHECK_NAME_LEN      128 
    60 #define LOG(expr)           PJ_LOG(4,expr) 
     60#define LOG4(expr)          PJ_LOG(4,expr) 
     61#define LOG5(expr)          PJ_LOG(4,expr) 
    6162#define GET_LCAND_ID(cand)  (cand - ice->lcand) 
    6263#define GET_CHECK_ID(chk)   (chk - ice->clist.checks) 
     
    136137                                  const char *name, 
    137138                                  pj_ice_role role, 
     139                                  unsigned comp_cnt, 
    138140                                  const pj_ice_cb *cb, 
    139141                                  const pj_str_t *local_ufrag, 
     
    171173    pj_memcpy(&ice->stun_cfg, stun_cfg, sizeof(*stun_cfg)); 
    172174 
    173     for (i=0; i<PJ_ICE_MAX_COMP; ++i) { 
    174         ice->comp[i].nominated_check_id = -1; 
     175    ice->comp_cnt = comp_cnt; 
     176    for (i=0; i<comp_cnt; ++i) { 
     177        pj_ice_comp *comp; 
     178        comp = &ice->comp[i]; 
     179        comp->comp_id = i+1; 
     180        comp->nominated_check_id = -1; 
    175181    } 
    176182 
     
    193199    *p_ice = ice; 
    194200 
    195     LOG((ice->obj_name, "ICE stream session created, role is %s agent", 
    196         (ice->role==PJ_ICE_ROLE_CONTROLLING ? "controlling" : "controlled"))); 
     201    LOG4((ice->obj_name, "ICE stream session created, role is %s agent", 
     202         (ice->role==PJ_ICE_ROLE_CONTROLLING ? "controlling" : "controlled"))); 
    197203 
    198204    return PJ_SUCCESS; 
     
    209215 
    210216    if (reason == PJ_SUCCESS) { 
    211         LOG((ice->obj_name, "Destroying ICE session")); 
    212     } 
    213  
    214     for (i=0; i<ice->comp_cnt; ++i) { 
    215         /* Nothing to do */ 
     217        LOG4((ice->obj_name, "Destroying ICE session")); 
    216218    } 
    217219 
     
    251253static pj_ice_comp *find_comp(const pj_ice *ice, unsigned comp_id) 
    252254{ 
    253     unsigned i; 
    254     for (i=0; i<ice->comp_cnt; ++i) { 
    255         if (ice->comp[i].comp_id == comp_id) 
    256             return (pj_ice_comp *) &ice->comp[i]; 
    257     } 
    258  
    259     return NULL; 
    260 } 
    261  
    262  
    263 /* Add a new component */ 
    264 PJ_DEF(pj_status_t) pj_ice_add_comp(pj_ice *ice, unsigned comp_id) 
    265 { 
    266     pj_ice_comp *comp; 
    267  
    268     PJ_ASSERT_RETURN(ice && comp_id, PJ_EINVAL); 
    269     PJ_ASSERT_RETURN(ice->comp_cnt < PJ_ARRAY_SIZE(ice->comp), PJ_ETOOMANY); 
    270     PJ_ASSERT_RETURN(comp_id==ice->comp_cnt+1, PJ_EICEINCOMPID); 
    271     PJ_ASSERT_RETURN(find_comp(ice, comp_id) == NULL, PJ_EEXISTS); 
    272  
    273     pj_mutex_lock(ice->mutex); 
    274  
    275     comp = &ice->comp[ice->comp_cnt]; 
    276     comp->comp_id = comp_id; 
    277     comp->nominated_check_id = -1; 
    278  
    279     /* Done */ 
    280     ice->comp_cnt++; 
    281     pj_mutex_unlock(ice->mutex); 
    282  
    283     return PJ_SUCCESS; 
    284 } 
     255    pj_assert(comp_id > 0 && comp_id <= ice->comp_cnt); 
     256    return (pj_ice_comp*) &ice->comp[comp_id-1]; 
     257} 
     258 
    285259 
    286260static pj_status_t stun_auth_get_auth(void *user_data, 
     
    357331        /* Verify username */ 
    358332        if (pj_strcmp(username, &ice->tx_uname) != 0) 
    359             return -1; 
     333            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_USERNAME); 
    360334        *data_type = 0; 
    361335        *data = ice->tx_pass; 
     
    408382    }; 
    409383 
    410     return ((1 << 24) * type_pref[type]) +  
    411            ((1 << 8) * local_pref) + 
    412            (256 - comp_id); 
     384    return ((type_pref[type] & 0xFF) << 24) +  
     385           ((local_pref & 0xFFFF)    << 8) + 
     386           (((256 - comp_id) & 0xFF) << 0); 
    413387} 
    414388 
     
    424398                                    const pj_sockaddr_t *addr, 
    425399                                    const pj_sockaddr_t *base_addr, 
    426                                     const pj_sockaddr_t *srv_addr, 
     400                                    const pj_sockaddr_t *rel_addr, 
    427401                                    int addr_len, 
    428402                                    unsigned *p_cand_id) 
     
    453427    pj_memcpy(&lcand->addr, addr, addr_len); 
    454428    pj_memcpy(&lcand->base_addr, base_addr, addr_len); 
    455     if (srv_addr) 
    456         pj_memcpy(&lcand->srv_addr, srv_addr, addr_len); 
     429    if (rel_addr) 
     430        pj_memcpy(&lcand->rel_addr, rel_addr, addr_len); 
    457431    else 
    458         pj_bzero(&lcand->srv_addr, sizeof(lcand->srv_addr)); 
     432        pj_bzero(&lcand->rel_addr, sizeof(lcand->rel_addr)); 
    459433 
    460434    /* Init STUN callbacks */ 
     
    493467 
    494468    pj_ansi_strcpy(tmp, pj_inet_ntoa(lcand->addr.ipv4.sin_addr)); 
    495     LOG((ice->obj_name,  
     469    LOG4((ice->obj_name,  
    496470         "Candidate %d added: comp_id=%d, type=%s, foundation=%.*s, " 
    497471         "addr=%s:%d, base=%s:%d, prio=0x%x (%u)", 
     
    518492 
    519493 
    520 PJ_DEF(unsigned) pj_ice_get_cand_cnt(pj_ice *ice) 
    521 { 
    522     return ice->lcand_cnt; 
    523 } 
    524  
    525  
    526 PJ_DEF(pj_status_t) pj_ice_enum_cands(pj_ice *ice, 
    527                                       unsigned *p_count, 
    528                                       unsigned cand_ids[]) 
    529 { 
    530     unsigned i, count; 
    531  
    532     PJ_ASSERT_RETURN(ice && p_count && *p_count && cand_ids, PJ_EINVAL); 
     494PJ_DEF(pj_status_t) pj_ice_find_default_cand(pj_ice *ice, 
     495                                             unsigned comp_id, 
     496                                             int *cand_id) 
     497{ 
     498    unsigned i; 
     499 
     500    PJ_ASSERT_RETURN(ice && comp_id && cand_id, PJ_EINVAL); 
     501 
     502    *cand_id = -1; 
    533503 
    534504    pj_mutex_lock(ice->mutex); 
    535505 
    536     count = (*p_count < ice->lcand_cnt) ? *p_count : ice->lcand_cnt; 
    537     for (i=0; i<count; ++i) 
    538         cand_ids[i] = i; 
    539  
    540     *p_count = count; 
    541     pj_mutex_unlock(ice->mutex); 
    542  
    543     return PJ_SUCCESS; 
    544 } 
    545  
    546  
    547 PJ_DEF(pj_status_t) pj_ice_get_default_cand(pj_ice *ice, 
    548                                             unsigned comp_id, 
    549                                             int *cand_id) 
    550 { 
    551     unsigned i; 
    552  
    553     PJ_ASSERT_RETURN(ice && comp_id && cand_id, PJ_EINVAL); 
    554  
    555     *cand_id = -1; 
    556  
    557     pj_mutex_lock(ice->mutex); 
    558  
    559506    /* First find in valid list if we have nominated pair */ 
    560     for (i=0; i<ice->valid_cnt; ++i) { 
    561         pj_ice_cand *lcand; 
     507    for (i=0; i<ice->valid_list.count; ++i) { 
     508        pj_ice_check *check = &ice->valid_list.checks[i]; 
    562509         
    563         lcand = ice->clist.checks[ice->valid_list[i]].lcand; 
    564         if (lcand->comp_id==comp_id) { 
    565             *cand_id = GET_LCAND_ID(lcand); 
     510        if (check->lcand->comp_id == comp_id) { 
     511            *cand_id = GET_LCAND_ID(check->lcand); 
    566512            pj_mutex_unlock(ice->mutex); 
    567513            return PJ_SUCCESS; 
     
    609555 
    610556    pj_assert(!"Should have a candidate by now"); 
    611     return PJ_EICENOCAND; 
    612 } 
    613  
    614  
    615 PJ_DEF(pj_status_t) pj_ice_get_cand(pj_ice *ice, 
    616                                     unsigned cand_id, 
    617                                     pj_ice_cand **p_cand) 
    618 { 
    619     PJ_ASSERT_RETURN(ice && p_cand, PJ_EINVAL); 
    620     PJ_ASSERT_RETURN(cand_id <= ice->lcand_cnt, PJ_EINVAL); 
    621  
    622     *p_cand = &ice->lcand[cand_id]; 
    623  
    624     return PJ_SUCCESS; 
    625 } 
     557    return PJ_EBUG; 
     558} 
     559 
    626560 
    627561#ifndef MIN 
     
    690624    char buffer[CHECK_NAME_LEN]; 
    691625 
    692     LOG((ice->obj_name, "%s", title)); 
     626    LOG4((ice->obj_name, "%s", title)); 
    693627    for (i=0; i<clist->count; ++i) { 
    694628        const pj_ice_check *c = &clist->checks[i]; 
    695         LOG((ice->obj_name, " %s (%s, state=%s)", 
     629        LOG4((ice->obj_name, " %s (%s, state=%s)", 
    696630             dump_check(buffer, sizeof(buffer), ice, c), 
    697631             (c->nominated ? "nominated" : "not nominated"),  
     
    700634} 
    701635 
    702 static void dump_valid_list(const char *title, const pj_ice *ice) 
    703 { 
    704     unsigned i; 
    705     char buffer[CHECK_NAME_LEN]; 
    706  
    707     LOG((ice->obj_name, "%s", title)); 
    708     for (i=0; i<ice->valid_cnt; ++i) { 
    709         const pj_ice_check *c = &ice->clist.checks[ice->valid_list[i]]; 
    710         LOG((ice->obj_name, " %s (%s, state=%s)", 
    711              dump_check(buffer, sizeof(buffer), ice, c), 
    712              (c->nominated ? "nominated" : "not nominated"),  
    713              check_state_name[c->state])); 
    714     } 
    715 } 
    716  
    717636#else 
    718637#define dump_checklist(ice, clist) 
     
    727646    pj_assert(check->state < PJ_ICE_CHECK_STATE_SUCCEEDED); 
    728647 
    729     LOG((ice->obj_name, "Check %s: state changed from %s to %s", 
     648    LOG5((ice->obj_name, "Check %s: state changed from %s to %s", 
    730649         dump_check(buf, sizeof(buf), ice, check), 
    731650         check_state_name[check->state], 
     
    739658{ 
    740659    if (clist->state != st) { 
    741         LOG((ice->obj_name, "Checklist: state changed from %s to %s", 
     660        LOG5((ice->obj_name, "Checklist: state changed from %s to %s", 
    742661             clist_state_name[clist->state], 
    743662             clist_state_name[st])); 
     
    769688    } 
    770689} 
    771  
    772 /* Sort valid list based on priority */ 
    773 static void sort_valid_list(pj_ice *ice) 
    774 { 
    775     unsigned i; 
    776  
    777     for (i=0; i<ice->valid_cnt-1; ++i) { 
    778         unsigned j, highest = i; 
    779         pj_ice_check *ci = &ice->clist.checks[ice->valid_list[i]]; 
    780  
    781         for (j=i+1; j<ice->valid_cnt; ++j) { 
    782             pj_ice_check *cj = &ice->clist.checks[ice->valid_list[j]]; 
    783  
    784             if (cj->prio > ci->prio) { 
    785                 highest = j; 
    786             } 
    787         } 
    788  
    789         if (highest != i) { 
    790             unsigned tmp = ice->valid_list[i]; 
    791             ice->valid_list[i] = ice->valid_list[j]; 
    792             ice->valid_list[j] = tmp; 
    793         } 
    794     } 
    795 } 
    796  
    797690 
    798691enum  
     
    866759                char buf[CHECK_NAME_LEN]; 
    867760 
    868                 LOG((ice->obj_name, "Check %s pruned", 
     761                LOG5((ice->obj_name, "Check %s pruned", 
    869762                    dump_check(buf, sizeof(buf), ice, &clist->checks[j]))); 
    870763 
     
    890783     
    891784        /* Log message */ 
    892         LOG((ice->obj_name, "ICE process complete, status=%s",  
     785        LOG4((ice->obj_name, "ICE process complete, status=%s",  
    893786             pj_strerror(status, errmsg, sizeof(errmsg)).ptr)); 
    894787 
    895         dump_checklist("Dumping checklist", ice, &ice->clist); 
    896         dump_valid_list("Dumping valid list", ice); 
     788        dump_checklist("Valid list", ice, &ice->valid_list); 
    897789 
    898790        /* Call callback */ 
     
    922814        pj_ice_comp *comp; 
    923815 
    924         LOG((ice->obj_name, "Check %d is successful and nominated", 
     816        LOG5((ice->obj_name, "Check %d is successful and nominated", 
    925817             GET_CHECK_ID(check))); 
    926818 
     
    931823                 c->state==PJ_ICE_CHECK_STATE_WAITING)) 
    932824            { 
    933                 LOG((ice->obj_name,  
     825                LOG5((ice->obj_name,  
    934826                     "Check %d to be failed because state is %s", 
    935827                     i, check_state_name[c->state])); 
     
    982874 
    983875 
    984 #if 0 
    985     /* For now, just see if we have a valid pair in component 1 and 
    986      * just terminate ICE. 
    987      */ 
    988     for (i=0; i<ice->valid_cnt; ++i) { 
    989         pj_ice_check *c = &ice->clist.checks[ice->valid_list[i]]; 
    990         if (c->lcand->comp_id == 1) 
    991             break; 
    992     } 
    993  
    994     if (i != ice->valid_cnt) { 
    995         /* ICE succeeded */ 
    996         on_ice_complete(ice, PJ_SUCCESS); 
    997         return PJ_TRUE; 
    998     } 
    999 #else 
    1000876    /* See if all components have nominated pair. If they do, then mark 
    1001877     * ICE processing as success, otherwise wait. 
     
    1010886        return PJ_TRUE; 
    1011887    } 
    1012 #endif 
    1013888 
    1014889    /*  
     
    1025900    if (i == ice->clist.count) { 
    1026901        /* All checks have completed */ 
    1027         on_ice_complete(ice, -1); 
     902        on_ice_complete(ice, PJNATH_EICEFAILED); 
    1028903        return PJ_TRUE; 
    1029904    } 
     
    11671042    comp = find_comp(ice, lcand->comp_id); 
    11681043 
    1169     LOG((ice->obj_name,  
     1044    LOG5((ice->obj_name,  
    11701045         "Sending connectivity check for check %s",  
    11711046         dump_check(buffer, sizeof(buffer), ice, check))); 
     
    12391114    clist_set_state(ice, clist, PJ_ICE_CHECKLIST_ST_RUNNING); 
    12401115 
    1241     LOG((ice->obj_name, "Starting checklist periodic check")); 
     1116    LOG5((ice->obj_name, "Starting checklist periodic check")); 
    12421117 
    12431118    /* Send STUN Binding request for check with highest priority on 
     
    13071182 
    13081183    PJ_ASSERT_RETURN(ice, PJ_EINVAL); 
    1309  
    1310     LOG((ice->obj_name, "Starting ICE check..")); 
     1184    /* Checklist must be created */ 
     1185    PJ_ASSERT_RETURN(ice->clist.count > 0, PJ_EINVALIDOP); 
     1186 
     1187    LOG4((ice->obj_name, "Starting ICE check..")); 
    13111188 
    13121189    clist = &ice->clist; 
    1313  
    1314     if (clist->count == 0) 
    1315         return PJ_EICENOCHECKLIST; 
    13161190 
    13171191    /* Pickup the first pair and set the state to Waiting */ 
     
    13631237    struct req_data *rd = (struct req_data*) tdata->user_data; 
    13641238    pj_ice *ice; 
    1365     pj_ice_check *check; 
    1366     const pj_ice_cand *lcand; 
    1367     const pj_ice_cand *rcand; 
     1239    pj_ice_check *check, *new_check; 
     1240    pj_ice_cand *lcand; 
    13681241    pj_ice_checklist *clist; 
    13691242    pj_stun_xor_mapped_addr_attr *xaddr; 
     
    13791252    pj_mutex_lock(ice->mutex); 
    13801253 
    1381     lcand = check->lcand; 
    1382     rcand = check->rcand; 
    1383  
    1384     LOG((ice->obj_name,  
     1254    /* Init lcand to NULL. lcand will be found from the mapped address 
     1255     * found in the response. 
     1256     */ 
     1257    lcand = NULL; 
     1258 
     1259    LOG4((ice->obj_name,  
    13851260         "Check %s%s: connectivity check %s", 
    13861261         dump_check(buffer, sizeof(buffer), ice, check), 
     
    14031278    PJ_TODO(ICE_CHECK_RESPONSE_SOURCE_ADDRESS); 
    14041279 
    1405     /* Get the STUN MAPPED-ADDRESS attribute. */ 
     1280    /* Get the STUN XOR-MAPPED-ADDRESS attribute. */ 
    14061281    xaddr = (pj_stun_xor_mapped_addr_attr*) 
    14071282            pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR,0); 
    14081283    if (!xaddr) { 
    14091284        check_set_state(ice, check, PJ_ICE_CHECK_STATE_FAILED,  
    1410                         PJNATH_ESTUNNOXORMAP); 
     1285                        PJNATH_ESTUNNOMAPPEDADDR); 
    14111286        on_check_complete(ice, check); 
    14121287        pj_mutex_unlock(ice->mutex); 
     
    14141289    } 
    14151290 
     1291    /* Find local candidate that matches the XOR-MAPPED-ADDRESS */ 
     1292    pj_assert(lcand == NULL); 
     1293    for (i=0; i<ice->lcand_cnt; ++i) { 
     1294        if (sockaddr_cmp(&xaddr->sockaddr, &ice->lcand[i].addr) == 0) { 
     1295            /* Match */ 
     1296            lcand = &ice->lcand[i]; 
     1297            break; 
     1298        } 
     1299    } 
     1300 
    14161301    /* If the transport address returned in XOR-MAPPED-ADDRESS does not match 
    14171302     * any of the local candidates that the agent knows about, the mapped  
    14181303     * address represents a new candidate - a peer reflexive candidate. 
    14191304     */ 
    1420     for (i=0; i<ice->lcand_cnt; ++i) { 
    1421         if (sockaddr_cmp(&xaddr->sockaddr, &ice->lcand[i].addr) == 0) { 
    1422             /* Match */ 
    1423             break; 
    1424         } 
    1425     } 
    1426  
    1427     if (i == ice->lcand_cnt) { 
     1305    if (lcand == NULL) { 
    14281306        unsigned cand_id; 
    14291307        char buf[32]; 
     
    14511329    } 
    14521330 
    1453     /* Sets the state of the pair that generated the check to succeeded. */ 
     1331    /* Add pair to valid list */ 
     1332    new_check = &ice->valid_list.checks[ice->valid_list.count++]; 
     1333    new_check->lcand = lcand; 
     1334    new_check->rcand = check->rcand; 
     1335    new_check->prio = CALC_CHECK_PRIO(ice, lcand, check->rcand); 
     1336    new_check->state = PJ_ICE_CHECK_STATE_SUCCEEDED; 
     1337    new_check->nominated = check->nominated; 
     1338    new_check->err_code = PJ_SUCCESS; 
     1339 
     1340    /* Sort valid_list */ 
     1341    sort_checklist(&ice->valid_list); 
     1342 
     1343 
     1344    /* Sets the state of the original pair that generated the check to  
     1345     * succeeded.  
     1346     */ 
    14541347    check_set_state(ice, check, PJ_ICE_CHECK_STATE_SUCCEEDED, PJ_SUCCESS); 
    1455  
    1456     /* This is a valid pair, so add this to the valid list */ 
    1457     ice->valid_list[ice->valid_cnt++] = rd->ckid; 
    1458  
    1459     /* Sort valid_list */ 
    1460     sort_valid_list(ice); 
    14611348 
    14621349    /* Inform about check completion. 
     
    15161403} 
    15171404 
    1518  
     1405/* This callback is called by the STUN session associated with a candidate 
     1406 * when it receives incoming request. 
     1407 */ 
    15191408static pj_status_t on_stun_rx_request(pj_stun_session *sess, 
    15201409                                      const pj_uint8_t *pkt, 
     
    15411430    /* Reject any requests except Binding request */ 
    15421431    if (msg->hdr.type != PJ_STUN_BINDING_REQUEST) { 
    1543         pj_str_t err_msg = pj_str("Expecting Binding Request only"); 
    15441432        status = pj_stun_session_create_response(sess, msg,  
    15451433                                                 PJ_STUN_SC_BAD_REQUEST, 
    1546                                                  &err_msg, &tdata); 
    1547         if (status != PJ_SUCCESS) { 
     1434                                                 NULL, &tdata); 
     1435        if (status != PJ_SUCCESS) 
    15481436            return status; 
    1549         } 
    1550  
    1551         status = pj_stun_session_send_msg(sess, PJ_TRUE,  
    1552                                           src_addr, src_addr_len, tdata); 
    1553  
    1554         return status; 
     1437 
     1438        return pj_stun_session_send_msg(sess, PJ_TRUE,  
     1439                                        src_addr, src_addr_len, tdata); 
    15551440    } 
    15561441 
     
    15671452         pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_PRIORITY, 0); 
    15681453    if (ap == 0) { 
    1569         LOG((ice->obj_name, "Received Binding request with no PRIORITY")); 
     1454        LOG5((ice->obj_name, "Received Binding request with no PRIORITY")); 
    15701455        pj_mutex_unlock(ice->mutex); 
    15711456        return PJ_SUCCESS; 
     
    16271512                                                  rcand->foundation.ptr); 
    16281513 
    1629         LOG((ice->obj_name,  
     1514        LOG4((ice->obj_name,  
    16301515             "Added new remote candidate from the request: %s:%d", 
    16311516             pj_inet_ntoa(rcand->addr.ipv4.sin_addr), 
     
    16791564            c->state == PJ_ICE_CHECK_STATE_WAITING) 
    16801565        { 
    1681             LOG((ice->obj_name, "Performing triggered check for check %d",i)); 
     1566            LOG5((ice->obj_name, "Performing triggered check for check %d",i)); 
    16821567            perform_check(ice, &ice->clist, i); 
    16831568 
     
    16861571             * TODO 
    16871572             */ 
    1688             LOG((ice->obj_name, "Triggered check for check %d not performed " 
     1573            LOG5((ice->obj_name, "Triggered check for check %d not performed " 
    16891574                                "because it's in progress", i)); 
    16901575        } else if (c->state == PJ_ICE_CHECK_STATE_SUCCEEDED) { 
     
    16941579            pj_bool_t complete; 
    16951580 
    1696             LOG((ice->obj_name, "Triggered check for check %d not performed " 
     1581            LOG5((ice->obj_name, "Triggered check for check %d not performed " 
    16971582                                "because it's completed", i)); 
    16981583 
     
    17221607        c->err_code = PJ_SUCCESS; 
    17231608 
    1724         LOG((ice->obj_name, "New triggered check added: %d",  
     1609        LOG4((ice->obj_name, "New triggered check added: %d",  
    17251610             ice->clist.count)); 
    17261611        perform_check(ice, &ice->clist, ice->clist.count++); 
    17271612 
    17281613    } else { 
    1729         LOG((ice->obj_name, "Error: unable to perform triggered check: " 
     1614        LOG4((ice->obj_name, "Error: unable to perform triggered check: " 
    17301615             "TOO MANY CHECKS IN CHECKLIST!")); 
    17311616    } 
     
    17721657    comp = find_comp(ice, comp_id); 
    17731658    if (comp == NULL) { 
    1774         status = PJ_EICEINCOMPID; 
     1659        status = PJNATH_EICEINCOMPID; 
    17751660        goto on_return; 
    17761661    } 
    17771662 
    17781663    if (comp->nominated_check_id == -1) { 
    1779         status = PJ_EICEINPROGRESS; 
     1664        status = PJNATH_EICEINPROGRESS; 
    17801665        goto on_return; 
    17811666    } 
     
    18131698    comp = find_comp(ice, comp_id); 
    18141699    if (comp == NULL) { 
    1815         status = PJ_EICEINCOMPID; 
     1700        status = PJNATH_EICEINCOMPID; 
    18161701        goto on_return; 
    18171702    } 
  • pjproject/trunk/pjnath/src/pjnath/ice_stream_transport.c

    r1099 r1101  
    365365 
    366366    /* Component ID must be valid */ 
    367     PJ_ASSERT_RETURN(comp_id <= PJ_ICE_MAX_COMP, PJ_EICEINCOMPID); 
     367    PJ_ASSERT_RETURN(comp_id <= PJ_ICE_MAX_COMP, PJNATH_EICEINCOMPID); 
    368368 
    369369    /* First component ID must be 1, second must be 2, etc., and  
     
    371371     */ 
    372372    PJ_ASSERT_RETURN(ice_st->comps[comp_id-1] == ice_st->comp_cnt,  
    373                      PJ_EICEINCOMPID); 
     373                     PJNATH_EICEINCOMPID); 
    374374 
    375375    /* All in order, add the component. */ 
     
    408408 
    409409    /* Check that component ID present */ 
    410     PJ_ASSERT_RETURN(comp_id <= ice_st->comp_cnt, PJ_EICEINCOMPID); 
     410    PJ_ASSERT_RETURN(comp_id <= ice_st->comp_cnt, PJNATH_EICEINCOMPID); 
    411411 
    412412    /* Can't add new interface while ICE is running */ 
     
    579579    /* Create! */ 
    580580    status = pj_ice_create(&ice_st->stun_cfg, ice_st->obj_name, role,  
    581                            &ice_cb, local_ufrag, local_passwd, &ice_st->ice); 
     581                           ice_st->comp_cnt, &ice_cb,  
     582                           local_ufrag, local_passwd, &ice_st->ice); 
    582583    if (status != PJ_SUCCESS) 
    583584        return status; 
     
    585586    /* Associate user data */ 
    586587    ice_st->ice->user_data = (void*)ice_st; 
    587  
    588     /* Add components */ 
    589     for (i=0; i<ice_st->comp_cnt; ++i) { 
    590         status = pj_ice_add_comp(ice_st->ice, ice_st->comps[i]); 
    591         if (status != PJ_SUCCESS) 
    592             goto on_error; 
    593     } 
    594588 
    595589    /* Add candidates */ 
     
    627621    unsigned i, cnt; 
    628622    pj_ice_cand *pcand; 
    629     pj_status_t status; 
    630623 
    631624    PJ_ASSERT_RETURN(ice_st && count && cand, PJ_EINVAL); 
    632625    PJ_ASSERT_RETURN(ice_st->ice, PJ_EINVALIDOP); 
    633626 
    634     cnt = pj_ice_get_cand_cnt(ice_st->ice); 
     627    cnt = ice_st->ice->lcand_cnt; 
    635628    cnt = (cnt > *count) ? *count : cnt; 
    636629    *count = 0; 
    637630 
    638631    for (i=0; i<cnt; ++i) { 
    639         status = pj_ice_get_cand(ice_st->ice, i, &pcand); 
    640         if (status != PJ_SUCCESS) 
    641             return status; 
    642  
     632        pcand = &ice_st->ice->lcand[i]; 
    643633        pj_memcpy(&cand[i], pcand, sizeof(pj_ice_cand)); 
    644634    } 
     
    689679{ 
    690680    if (!ice_st->ice) 
    691         return PJ_ENOICE; 
     681        return PJNATH_ENOICE; 
    692682 
    693683    return pj_ice_send_data(ice_st->ice, comp_id, data, data_len); 
     
    753743    } 
    754744    if (is == NULL) { 
    755         return PJ_EICEINCANDID; 
     745        return PJNATH_EICEINCANDID; 
    756746    } 
    757747 
  • pjproject/trunk/pjnath/src/pjnath/stun_auth.c

    r1089 r1101  
    160160                             &realm, &nonce, p_response); 
    161161        } 
    162         return PJNATH_ESTUNMSGINT; 
     162        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_INTEGRITY_CHECK_FAILURE); 
    163163    } 
    164164 
     
    171171                             &realm, &nonce, p_response); 
    172172        } 
    173         return PJNATH_ESTUNNOUSERNAME; 
     173        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_USERNAME); 
    174174    } 
    175175 
     
    203203                             &realm, &nonce, p_response); 
    204204        } 
    205         return PJNATH_ESTUNUSERNAME; 
     205        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_USERNAME); 
    206206    } 
    207207 
     
    218218                             &realm, &nonce, p_response); 
    219219        } 
    220         return PJNATH_ESTUNNOREALM; 
     220        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_REALM); 
    221221 
    222222    } else if (realm.slen != 0 && arealm != NULL) { 
     
    229229                                 NULL, &realm, &nonce, p_response); 
    230230            } 
    231             return PJNATH_ESTUNNONCE; 
     231            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 
    232232        } 
    233233 
     
    239239                                 NULL, &realm, &nonce, p_response); 
    240240            } 
    241             return PJNATH_ESTUNNOREALM; 
     241            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_REALM); 
    242242        } 
    243243 
     
    262262                                 NULL, &realm, &nonce, p_response); 
    263263            } 
    264             return PJNATH_ESTUNNONCE; 
     264            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 
    265265        } 
    266266    } 
     
    289289                                 NULL, &realm, &nonce, p_response); 
    290290            } 
    291             return PJNATH_ESTUNNONCE; 
     291            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 
    292292        } 
    293293    } 
     
    334334                             NULL, &realm, &nonce, p_response); 
    335335        } 
    336         return PJNATH_ESTUNMSGINT; 
     336        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_INTEGRITY_CHECK_FAILURE); 
    337337    } 
    338338 
  • pjproject/trunk/pjnath/src/pjnath/stun_msg.c

    r1094 r1101  
    6565    { PJ_STUN_SC_STALE_NONCE,               "Stale Nonce"}, 
    6666    { PJ_STUN_SC_TRANSITIONING,             "Active Destination Already Set"}, 
    67     { PJ_STUN_SC_WRONG_USERNAME,            "Wrong Username"}, 
    6867    { PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO,    "Unsupported Transport Protocol"}, 
    6968    { PJ_STUN_SC_INVALID_IP_ADDR,           "Invalid IP Address"}, 
     
    514513PJ_DEF(pj_str_t) pj_stun_get_err_reason(int err_code) 
    515514{ 
     515#if 0 
     516    /* Find error using linear search */ 
    516517    unsigned i; 
    517518 
     
    521522    } 
    522523    return pj_str(NULL); 
     524#else 
     525    /* Find error message using binary search */ 
     526    int first = 0; 
     527    int n = PJ_ARRAY_SIZE(stun_err_msg_map); 
     528 
     529    while (n > 0) { 
     530        int half = n/2; 
     531        int mid = first + half; 
     532 
     533        if (stun_err_msg_map[mid].err_code < err_code) { 
     534            first = mid+1; 
     535            n -= (half+1); 
     536        } else if (stun_err_msg_map[mid].err_code > err_code) { 
     537            n = half; 
     538        } else { 
     539            first = mid; 
     540            break; 
     541        } 
     542    } 
     543 
     544 
     545    if (stun_err_msg_map[first].err_code == err_code) { 
     546        return pj_str((char*)stun_err_msg_map[first].err_msg); 
     547    } else { 
     548        return pj_str(NULL); 
     549    } 
     550#endif 
    523551} 
    524552 
     
    15801608 
    15811609    if (pdu_len < sizeof(pj_stun_msg_hdr)) 
    1582         return PJNATH_ESTUNINMSGLEN; 
     1610        return PJNATH_EINSTUNMSGLEN; 
    15831611 
    15841612    /* First byte of STUN message is always 0x00 or 0x01. */ 
    15851613    if (*pdu != 0x00 && *pdu != 0x01) 
    1586         return PJNATH_ESTUNINMSGTYPE; 
     1614        return PJNATH_EINSTUNMSGTYPE; 
    15871615 
    15881616    /* Check the PDU length */ 
     
    15911619        ((options & PJ_STUN_IS_DATAGRAM) && msg_len + 20 != pdu_len)) 
    15921620    { 
    1593         return PJNATH_ESTUNINMSGLEN; 
     1621        return PJNATH_EINSTUNMSGLEN; 
    15941622    } 
    15951623 
     
    16351663 
    16361664    PJ_ASSERT_RETURN(PJ_STUN_IS_REQUEST(msg_type),  
    1637                      PJNATH_ESTUNINMSGTYPE); 
     1665                     PJNATH_EINSTUNMSGTYPE); 
    16381666 
    16391667    /* Create response or error response */ 
     
    17741802                } 
    17751803 
    1776                 return PJNATH_ESTUNUNKNOWNATTR; 
     1804                return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_ATTRIBUTE); 
    17771805            } 
    17781806 
     
    21032131            /* Should not happen for message generated by us */ 
    21042132            pj_assert(PJ_FALSE); 
    2105             return PJNATH_ESTUNNOUSERNAME; 
     2133            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_USERNAME); 
    21062134        } 
    21072135 
  • pjproject/trunk/pjnath/src/pjnath/stun_transaction.c

    r1080 r1101  
    236236        tsx->complete = PJ_TRUE; 
    237237        if (tsx->cb.on_complete) { 
    238             tsx->cb.on_complete(tsx, PJNATH_ESTUNNOTRESPOND, NULL); 
     238            tsx->cb.on_complete(tsx, PJNATH_ESTUNTIMEDOUT, NULL); 
    239239        } 
    240240        return; 
     
    269269        PJ_LOG(4,(tsx->obj_name,  
    270270                  "STUN rx_msg() error: not response message")); 
    271         return PJNATH_ESTUNNOTRESPONSE; 
     271        return PJNATH_EINSTUNMSGTYPE; 
    272272    } 
    273273 
     
    301301        status = PJ_SUCCESS; 
    302302    } else { 
    303         status = PJNATH_ESTUNTSXFAILED; 
     303        status = PJ_STATUS_FROM_STUN_CODE(err_attr->err_class * 100 +  
     304                                          err_attr->number); 
    304305    } 
    305306 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r1099 r1101  
    400400    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    401401 
     402    /* Init PJNATH */ 
     403    status = pjnath_init(); 
     404    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    402405 
    403406    /* Set default sound device ID */ 
Note: See TracChangeset for help on using the changeset viewer.