Changeset 1101 for pjproject/trunk
- Timestamp:
- Mar 24, 2007 1:00:30 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r1099 r1101 198 198 199 199 /* 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; 201 201 for (i=0; i<cand_cnt; ++i) { 202 202 pj_ice_cand *cand; … … 204 204 int len; 205 205 206 pj_ice_get_cand(tp_ice->ice_st->ice, i, &cand);206 cand = &tp_ice->ice_st->ice->lcand[i]; 207 207 208 208 len = pj_ansi_snprintf( buffer, MAXLEN, … … 266 266 char *token, *host; 267 267 pj_str_t s; 268 pj_status_t status = PJ _EICEINCANDSDP;268 pj_status_t status = PJNATH_EICEINCANDSDP; 269 269 270 270 pj_bzero(cand, sizeof(*cand)); … … 342 342 on_return: 343 343 return status; 344 } 345 346 static 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); 344 351 } 345 352 … … 359 366 attr = pjmedia_sdp_attr_find2(rem_sdp->attr_count, rem_sdp->attr, 360 367 "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 } 363 372 uname = attr->value; 364 373 … … 366 375 attr = pjmedia_sdp_attr_find2(rem_sdp->attr_count, rem_sdp->attr, 367 376 "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 } 370 381 pass = attr->value; 371 382 … … 547 558 PJ_TIME_VAL_SUB(end_ice, tp_ice->start_ice); 548 559 549 check = &ice_st->ice-> clist.checks[ice_st->ice->valid_list[0]];560 check = &ice_st->ice->valid_list.checks[0]; 550 561 551 562 lcand = check->lcand; -
pjproject/trunk/pjnath/build/pjnath.dsp
r1096 r1101 42 42 # PROP Target_Dir "" 43 43 # 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 /c45 # SUBTRACT CPP / YX44 # 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 46 46 # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 47 # ADD RSC /l 0x409 /d "NDEBUG" -
pjproject/trunk/pjnath/include/pjnath.h
r1096 r1101 28 28 #include <pjnath/stun_transaction.h> 29 29 #include <pjnath/types.h> 30 -
pjproject/trunk/pjnath/include/pjnath/errno.h
r1099 r1101 24 24 25 25 /** 26 * @defgroup PJNATH_ERROR NAT Helper Error Codes26 * @defgroup PJNATH_ERROR NAT Helper Library Error Codes 27 27 * @ingroup PJNATH 28 28 * @{ … … 36 36 37 37 38 /************************************************************ 39 * STUN MESSAGING ERRORS 40 ***********************************************************/ 38 41 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 49 64 50 65 /** … … 52 67 * Too many STUN attributes. 53 68 */ 54 #define PJNATH_ESTUNTOOMANYATTR (PJNATH_ERRNO_START+ 110)/* 370110*/69 #define PJNATH_ESTUNTOOMANYATTR (PJNATH_ERRNO_START+21) /* 370021 */ 55 70 /** 56 71 * @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. 59 73 */ 60 #define PJNATH_ESTUN UNKNOWNATTR (PJNATH_ERRNO_START+111)/* 370111*/74 #define PJNATH_ESTUNINATTRLEN (PJNATH_ERRNO_START+22) /* 370022 */ 61 75 /** 62 76 * @hideinitializer 63 * Invalid STUN socket address length.77 * Found duplicate STUN attribute. 64 78 */ 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 */ 66 103 /** 67 104 * @hideinitializer 68 105 * STUN IPv6 attribute not supported 69 106 */ 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 */ 141 108 142 109 143 //#define PJ_STATUS_FROM_STUN_CODE(code) (PJNATH_ERRNO_START+code)144 110 111 112 /************************************************************ 113 * ICE ERROR CODES 114 ***********************************************************/ 145 115 146 116 /** 147 117 * @hideinitializer 148 * No ICE checklist is formed.118 * ICE session not available 149 119 */ 150 #define PJ _EICENOCHECKLIST -1120 #define PJNATH_ENOICE (PJNATH_ERRNO_START+80) /* 370080 */ 151 121 /** 152 122 * @hideinitializer 153 * No suitable default ICE candidate for the component.123 * ICE check is in progress 154 124 */ 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 */ 156 131 /** 157 132 * @hideinitializer 158 133 * Invalid ICE component ID 159 134 */ 160 #define PJ _EICEINCOMPID -1135 #define PJNATH_EICEINCOMPID (PJNATH_ERRNO_START+86) /* 370086 */ 161 136 /** 162 137 * @hideinitializer 163 138 * Invalid ICE candidate ID 164 139 */ 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 */ 176 141 /** 177 142 * @hideinitializer 178 143 * Missing ICE SDP attribute 179 144 */ 180 #define PJ _EICEMISSINGSDP -1145 #define PJNATH_EICEMISSINGSDP (PJNATH_ERRNO_START+90) /* 370090 */ 181 146 /** 182 147 * @hideinitializer 183 148 * Invalid SDP "candidate" attribute 184 149 */ 185 #define PJ _EICEINCANDSDP -1150 #define PJNATH_EICEINCANDSDP (PJNATH_ERRNO_START+91) /* 370091 */ 186 151 187 152 -
pjproject/trunk/pjnath/include/pjnath/ice.h
r1096 r1101 97 97 pj_sockaddr addr; 98 98 pj_sockaddr base_addr; 99 pj_sockaddr srv_addr;99 pj_sockaddr rel_addr; 100 100 pj_stun_session *stun_sess; 101 101 } pj_ice_cand; … … 205 205 206 206 /* Valid list */ 207 unsigned valid_cnt; 208 unsigned valid_list[PJ_ICE_MAX_CHECKS]; 207 pj_ice_checklist valid_list; 209 208 }; 210 209 … … 213 212 const char *name, 214 213 pj_ice_role role, 214 unsigned comp_cnt, 215 215 const pj_ice_cb *cb, 216 216 const pj_str_t *local_ufrag, … … 218 218 pj_ice **p_ice); 219 219 PJ_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);221 220 PJ_DECL(pj_status_t) pj_ice_add_cand(pj_ice *ice, 222 221 unsigned comp_id, … … 226 225 const pj_sockaddr_t *addr, 227 226 const pj_sockaddr_t *base_addr, 228 const pj_sockaddr_t * srv_addr,227 const pj_sockaddr_t *rel_addr, 229 228 int addr_len, 230 229 unsigned *cand_id); 231 230 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); 231 PJ_DECL(pj_status_t) pj_ice_find_default_cand(pj_ice *ice, 232 unsigned comp_id, 233 int *cand_id); 242 234 243 235 PJ_DECL(pj_status_t) pj_ice_create_check_list(pj_ice *ice, -
pjproject/trunk/pjnath/include/pjnath/stun_msg.h
r1085 r1101 384 384 PJ_STUN_SC_STALE_NONCE = 438, /**< Stale Nonce */ 385 385 PJ_STUN_SC_TRANSITIONING = 439, /**< Transitioning. */ 386 PJ_STUN_SC_WRONG_USERNAME = 441, /**< Wrong Username. */387 386 PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO = 442, /**< Unsupported Transport or 388 387 Protocol */ -
pjproject/trunk/pjnath/include/pjnath/types.h
r1080 r1101 30 30 /** 31 31 * @defgroup PJNATH NAT Helper Library 32 * @{ 32 33 */ 34 35 PJ_BEGIN_DECL 36 37 /** 38 * Initialize pjnath library. 39 * 40 * @return Initialization status. 41 */ 42 PJ_DECL(pj_status_t) pjnath_init(void); 43 44 45 PJ_END_DECL 46 47 /** 48 * @} 49 */ 50 51 /* Doxygen documentation below: */ 33 52 34 53 /** … … 44 63 * of modules. 45 64 * 46 *47 * \n48 * \n49 * \n50 * \n51 * \n52 * \n53 * \n54 * \n55 * \n56 * \n57 * \n58 * \n59 * \n60 65 */ 61 66 -
pjproject/trunk/pjnath/src/pjnath/errno.c
r1080 r1101 18 18 */ 19 19 #include <pjnath/errno.h> 20 #include <pjnath/stun_msg.h> 20 21 #include <pj/string.h> 21 22 … … 33 34 } err_str[] = 34 35 { 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 36 41 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"), 39 50 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 51 61 }; 52 62 #endif /* PJ_HAS_ERROR_STRING */ … … 56 66 * pjnath_strerror() 57 67 */ 58 PJ_DEF(pj_str_t) pjnath_strerror(pj_status_t statcode,59 68 static pj_str_t pjnath_strerror(pj_status_t statcode, 69 char *buf, pj_size_t bufsize ) 60 70 { 61 71 pj_str_t errstr; … … 107 117 errstr.ptr = buf; 108 118 errstr.slen = pj_ansi_snprintf(buf, bufsize, 109 "Unknown pj lib-utilerror %d",119 "Unknown pjnath error %d", 110 120 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 128 static 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; 111 148 112 149 return errstr; … … 116 153 PJ_DEF(pj_status_t) pjnath_init(void) 117 154 { 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; 121 166 } 167 -
pjproject/trunk/pjnath/src/pjnath/ice.c
r1099 r1101 58 58 59 59 #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) 61 62 #define GET_LCAND_ID(cand) (cand - ice->lcand) 62 63 #define GET_CHECK_ID(chk) (chk - ice->clist.checks) … … 136 137 const char *name, 137 138 pj_ice_role role, 139 unsigned comp_cnt, 138 140 const pj_ice_cb *cb, 139 141 const pj_str_t *local_ufrag, … … 171 173 pj_memcpy(&ice->stun_cfg, stun_cfg, sizeof(*stun_cfg)); 172 174 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; 175 181 } 176 182 … … 193 199 *p_ice = ice; 194 200 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"))); 197 203 198 204 return PJ_SUCCESS; … … 209 215 210 216 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")); 216 218 } 217 219 … … 251 253 static pj_ice_comp *find_comp(const pj_ice *ice, unsigned comp_id) 252 254 { 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 285 259 286 260 static pj_status_t stun_auth_get_auth(void *user_data, … … 357 331 /* Verify username */ 358 332 if (pj_strcmp(username, &ice->tx_uname) != 0) 359 return -1;333 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_USERNAME); 360 334 *data_type = 0; 361 335 *data = ice->tx_pass; … … 408 382 }; 409 383 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); 413 387 } 414 388 … … 424 398 const pj_sockaddr_t *addr, 425 399 const pj_sockaddr_t *base_addr, 426 const pj_sockaddr_t * srv_addr,400 const pj_sockaddr_t *rel_addr, 427 401 int addr_len, 428 402 unsigned *p_cand_id) … … 453 427 pj_memcpy(&lcand->addr, addr, addr_len); 454 428 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); 457 431 else 458 pj_bzero(&lcand-> srv_addr, sizeof(lcand->srv_addr));432 pj_bzero(&lcand->rel_addr, sizeof(lcand->rel_addr)); 459 433 460 434 /* Init STUN callbacks */ … … 493 467 494 468 pj_ansi_strcpy(tmp, pj_inet_ntoa(lcand->addr.ipv4.sin_addr)); 495 LOG ((ice->obj_name,469 LOG4((ice->obj_name, 496 470 "Candidate %d added: comp_id=%d, type=%s, foundation=%.*s, " 497 471 "addr=%s:%d, base=%s:%d, prio=0x%x (%u)", … … 518 492 519 493 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); 494 PJ_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; 533 503 534 504 pj_mutex_lock(ice->mutex); 535 505 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 559 506 /* First find in valid list if we have nominated pair */ 560 for (i=0; i<ice->valid_ cnt; ++i) {561 pj_ice_c and *lcand;507 for (i=0; i<ice->valid_list.count; ++i) { 508 pj_ice_check *check = &ice->valid_list.checks[i]; 562 509 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); 566 512 pj_mutex_unlock(ice->mutex); 567 513 return PJ_SUCCESS; … … 609 555 610 556 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 626 560 627 561 #ifndef MIN … … 690 624 char buffer[CHECK_NAME_LEN]; 691 625 692 LOG ((ice->obj_name, "%s", title));626 LOG4((ice->obj_name, "%s", title)); 693 627 for (i=0; i<clist->count; ++i) { 694 628 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)", 696 630 dump_check(buffer, sizeof(buffer), ice, c), 697 631 (c->nominated ? "nominated" : "not nominated"), … … 700 634 } 701 635 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 717 636 #else 718 637 #define dump_checklist(ice, clist) … … 727 646 pj_assert(check->state < PJ_ICE_CHECK_STATE_SUCCEEDED); 728 647 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", 730 649 dump_check(buf, sizeof(buf), ice, check), 731 650 check_state_name[check->state], … … 739 658 { 740 659 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", 742 661 clist_state_name[clist->state], 743 662 clist_state_name[st])); … … 769 688 } 770 689 } 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 797 690 798 691 enum … … 866 759 char buf[CHECK_NAME_LEN]; 867 760 868 LOG ((ice->obj_name, "Check %s pruned",761 LOG5((ice->obj_name, "Check %s pruned", 869 762 dump_check(buf, sizeof(buf), ice, &clist->checks[j]))); 870 763 … … 890 783 891 784 /* Log message */ 892 LOG ((ice->obj_name, "ICE process complete, status=%s",785 LOG4((ice->obj_name, "ICE process complete, status=%s", 893 786 pj_strerror(status, errmsg, sizeof(errmsg)).ptr)); 894 787 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); 897 789 898 790 /* Call callback */ … … 922 814 pj_ice_comp *comp; 923 815 924 LOG ((ice->obj_name, "Check %d is successful and nominated",816 LOG5((ice->obj_name, "Check %d is successful and nominated", 925 817 GET_CHECK_ID(check))); 926 818 … … 931 823 c->state==PJ_ICE_CHECK_STATE_WAITING)) 932 824 { 933 LOG ((ice->obj_name,825 LOG5((ice->obj_name, 934 826 "Check %d to be failed because state is %s", 935 827 i, check_state_name[c->state])); … … 982 874 983 875 984 #if 0985 /* For now, just see if we have a valid pair in component 1 and986 * 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 #else1000 876 /* See if all components have nominated pair. If they do, then mark 1001 877 * ICE processing as success, otherwise wait. … … 1010 886 return PJ_TRUE; 1011 887 } 1012 #endif1013 888 1014 889 /* … … 1025 900 if (i == ice->clist.count) { 1026 901 /* All checks have completed */ 1027 on_ice_complete(ice, -1);902 on_ice_complete(ice, PJNATH_EICEFAILED); 1028 903 return PJ_TRUE; 1029 904 } … … 1167 1042 comp = find_comp(ice, lcand->comp_id); 1168 1043 1169 LOG ((ice->obj_name,1044 LOG5((ice->obj_name, 1170 1045 "Sending connectivity check for check %s", 1171 1046 dump_check(buffer, sizeof(buffer), ice, check))); … … 1239 1114 clist_set_state(ice, clist, PJ_ICE_CHECKLIST_ST_RUNNING); 1240 1115 1241 LOG ((ice->obj_name, "Starting checklist periodic check"));1116 LOG5((ice->obj_name, "Starting checklist periodic check")); 1242 1117 1243 1118 /* Send STUN Binding request for check with highest priority on … … 1307 1182 1308 1183 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..")); 1311 1188 1312 1189 clist = &ice->clist; 1313 1314 if (clist->count == 0)1315 return PJ_EICENOCHECKLIST;1316 1190 1317 1191 /* Pickup the first pair and set the state to Waiting */ … … 1363 1237 struct req_data *rd = (struct req_data*) tdata->user_data; 1364 1238 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; 1368 1241 pj_ice_checklist *clist; 1369 1242 pj_stun_xor_mapped_addr_attr *xaddr; … … 1379 1252 pj_mutex_lock(ice->mutex); 1380 1253 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, 1385 1260 "Check %s%s: connectivity check %s", 1386 1261 dump_check(buffer, sizeof(buffer), ice, check), … … 1403 1278 PJ_TODO(ICE_CHECK_RESPONSE_SOURCE_ADDRESS); 1404 1279 1405 /* Get the STUN MAPPED-ADDRESS attribute. */1280 /* Get the STUN XOR-MAPPED-ADDRESS attribute. */ 1406 1281 xaddr = (pj_stun_xor_mapped_addr_attr*) 1407 1282 pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR,0); 1408 1283 if (!xaddr) { 1409 1284 check_set_state(ice, check, PJ_ICE_CHECK_STATE_FAILED, 1410 PJNATH_ESTUNNO XORMAP);1285 PJNATH_ESTUNNOMAPPEDADDR); 1411 1286 on_check_complete(ice, check); 1412 1287 pj_mutex_unlock(ice->mutex); … … 1414 1289 } 1415 1290 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 1416 1301 /* If the transport address returned in XOR-MAPPED-ADDRESS does not match 1417 1302 * any of the local candidates that the agent knows about, the mapped 1418 1303 * address represents a new candidate - a peer reflexive candidate. 1419 1304 */ 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) { 1428 1306 unsigned cand_id; 1429 1307 char buf[32]; … … 1451 1329 } 1452 1330 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 */ 1454 1347 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);1461 1348 1462 1349 /* Inform about check completion. … … 1516 1403 } 1517 1404 1518 1405 /* This callback is called by the STUN session associated with a candidate 1406 * when it receives incoming request. 1407 */ 1519 1408 static pj_status_t on_stun_rx_request(pj_stun_session *sess, 1520 1409 const pj_uint8_t *pkt, … … 1541 1430 /* Reject any requests except Binding request */ 1542 1431 if (msg->hdr.type != PJ_STUN_BINDING_REQUEST) { 1543 pj_str_t err_msg = pj_str("Expecting Binding Request only");1544 1432 status = pj_stun_session_create_response(sess, msg, 1545 1433 PJ_STUN_SC_BAD_REQUEST, 1546 &err_msg, &tdata);1547 if (status != PJ_SUCCESS) {1434 NULL, &tdata); 1435 if (status != PJ_SUCCESS) 1548 1436 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); 1555 1440 } 1556 1441 … … 1567 1452 pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_PRIORITY, 0); 1568 1453 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")); 1570 1455 pj_mutex_unlock(ice->mutex); 1571 1456 return PJ_SUCCESS; … … 1627 1512 rcand->foundation.ptr); 1628 1513 1629 LOG ((ice->obj_name,1514 LOG4((ice->obj_name, 1630 1515 "Added new remote candidate from the request: %s:%d", 1631 1516 pj_inet_ntoa(rcand->addr.ipv4.sin_addr), … … 1679 1564 c->state == PJ_ICE_CHECK_STATE_WAITING) 1680 1565 { 1681 LOG ((ice->obj_name, "Performing triggered check for check %d",i));1566 LOG5((ice->obj_name, "Performing triggered check for check %d",i)); 1682 1567 perform_check(ice, &ice->clist, i); 1683 1568 … … 1686 1571 * TODO 1687 1572 */ 1688 LOG ((ice->obj_name, "Triggered check for check %d not performed "1573 LOG5((ice->obj_name, "Triggered check for check %d not performed " 1689 1574 "because it's in progress", i)); 1690 1575 } else if (c->state == PJ_ICE_CHECK_STATE_SUCCEEDED) { … … 1694 1579 pj_bool_t complete; 1695 1580 1696 LOG ((ice->obj_name, "Triggered check for check %d not performed "1581 LOG5((ice->obj_name, "Triggered check for check %d not performed " 1697 1582 "because it's completed", i)); 1698 1583 … … 1722 1607 c->err_code = PJ_SUCCESS; 1723 1608 1724 LOG ((ice->obj_name, "New triggered check added: %d",1609 LOG4((ice->obj_name, "New triggered check added: %d", 1725 1610 ice->clist.count)); 1726 1611 perform_check(ice, &ice->clist, ice->clist.count++); 1727 1612 1728 1613 } else { 1729 LOG ((ice->obj_name, "Error: unable to perform triggered check: "1614 LOG4((ice->obj_name, "Error: unable to perform triggered check: " 1730 1615 "TOO MANY CHECKS IN CHECKLIST!")); 1731 1616 } … … 1772 1657 comp = find_comp(ice, comp_id); 1773 1658 if (comp == NULL) { 1774 status = PJ _EICEINCOMPID;1659 status = PJNATH_EICEINCOMPID; 1775 1660 goto on_return; 1776 1661 } 1777 1662 1778 1663 if (comp->nominated_check_id == -1) { 1779 status = PJ _EICEINPROGRESS;1664 status = PJNATH_EICEINPROGRESS; 1780 1665 goto on_return; 1781 1666 } … … 1813 1698 comp = find_comp(ice, comp_id); 1814 1699 if (comp == NULL) { 1815 status = PJ _EICEINCOMPID;1700 status = PJNATH_EICEINCOMPID; 1816 1701 goto on_return; 1817 1702 } -
pjproject/trunk/pjnath/src/pjnath/ice_stream_transport.c
r1099 r1101 365 365 366 366 /* 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); 368 368 369 369 /* First component ID must be 1, second must be 2, etc., and … … 371 371 */ 372 372 PJ_ASSERT_RETURN(ice_st->comps[comp_id-1] == ice_st->comp_cnt, 373 PJ _EICEINCOMPID);373 PJNATH_EICEINCOMPID); 374 374 375 375 /* All in order, add the component. */ … … 408 408 409 409 /* 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); 411 411 412 412 /* Can't add new interface while ICE is running */ … … 579 579 /* Create! */ 580 580 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); 582 583 if (status != PJ_SUCCESS) 583 584 return status; … … 585 586 /* Associate user data */ 586 587 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 }594 588 595 589 /* Add candidates */ … … 627 621 unsigned i, cnt; 628 622 pj_ice_cand *pcand; 629 pj_status_t status;630 623 631 624 PJ_ASSERT_RETURN(ice_st && count && cand, PJ_EINVAL); 632 625 PJ_ASSERT_RETURN(ice_st->ice, PJ_EINVALIDOP); 633 626 634 cnt = pj_ice_get_cand_cnt(ice_st->ice);627 cnt = ice_st->ice->lcand_cnt; 635 628 cnt = (cnt > *count) ? *count : cnt; 636 629 *count = 0; 637 630 638 631 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]; 643 633 pj_memcpy(&cand[i], pcand, sizeof(pj_ice_cand)); 644 634 } … … 689 679 { 690 680 if (!ice_st->ice) 691 return PJ _ENOICE;681 return PJNATH_ENOICE; 692 682 693 683 return pj_ice_send_data(ice_st->ice, comp_id, data, data_len); … … 753 743 } 754 744 if (is == NULL) { 755 return PJ _EICEINCANDID;745 return PJNATH_EICEINCANDID; 756 746 } 757 747 -
pjproject/trunk/pjnath/src/pjnath/stun_auth.c
r1089 r1101 160 160 &realm, &nonce, p_response); 161 161 } 162 return PJ NATH_ESTUNMSGINT;162 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_INTEGRITY_CHECK_FAILURE); 163 163 } 164 164 … … 171 171 &realm, &nonce, p_response); 172 172 } 173 return PJ NATH_ESTUNNOUSERNAME;173 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_USERNAME); 174 174 } 175 175 … … 203 203 &realm, &nonce, p_response); 204 204 } 205 return PJ NATH_ESTUNUSERNAME;205 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_USERNAME); 206 206 } 207 207 … … 218 218 &realm, &nonce, p_response); 219 219 } 220 return PJ NATH_ESTUNNOREALM;220 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_REALM); 221 221 222 222 } else if (realm.slen != 0 && arealm != NULL) { … … 229 229 NULL, &realm, &nonce, p_response); 230 230 } 231 return PJ NATH_ESTUNNONCE;231 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 232 232 } 233 233 … … 239 239 NULL, &realm, &nonce, p_response); 240 240 } 241 return PJ NATH_ESTUNNOREALM;241 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_REALM); 242 242 } 243 243 … … 262 262 NULL, &realm, &nonce, p_response); 263 263 } 264 return PJ NATH_ESTUNNONCE;264 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 265 265 } 266 266 } … … 289 289 NULL, &realm, &nonce, p_response); 290 290 } 291 return PJ NATH_ESTUNNONCE;291 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_NONCE); 292 292 } 293 293 } … … 334 334 NULL, &realm, &nonce, p_response); 335 335 } 336 return PJ NATH_ESTUNMSGINT;336 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_INTEGRITY_CHECK_FAILURE); 337 337 } 338 338 -
pjproject/trunk/pjnath/src/pjnath/stun_msg.c
r1094 r1101 65 65 { PJ_STUN_SC_STALE_NONCE, "Stale Nonce"}, 66 66 { PJ_STUN_SC_TRANSITIONING, "Active Destination Already Set"}, 67 { PJ_STUN_SC_WRONG_USERNAME, "Wrong Username"},68 67 { PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO, "Unsupported Transport Protocol"}, 69 68 { PJ_STUN_SC_INVALID_IP_ADDR, "Invalid IP Address"}, … … 514 513 PJ_DEF(pj_str_t) pj_stun_get_err_reason(int err_code) 515 514 { 515 #if 0 516 /* Find error using linear search */ 516 517 unsigned i; 517 518 … … 521 522 } 522 523 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 523 551 } 524 552 … … 1580 1608 1581 1609 if (pdu_len < sizeof(pj_stun_msg_hdr)) 1582 return PJNATH_E STUNINMSGLEN;1610 return PJNATH_EINSTUNMSGLEN; 1583 1611 1584 1612 /* First byte of STUN message is always 0x00 or 0x01. */ 1585 1613 if (*pdu != 0x00 && *pdu != 0x01) 1586 return PJNATH_E STUNINMSGTYPE;1614 return PJNATH_EINSTUNMSGTYPE; 1587 1615 1588 1616 /* Check the PDU length */ … … 1591 1619 ((options & PJ_STUN_IS_DATAGRAM) && msg_len + 20 != pdu_len)) 1592 1620 { 1593 return PJNATH_E STUNINMSGLEN;1621 return PJNATH_EINSTUNMSGLEN; 1594 1622 } 1595 1623 … … 1635 1663 1636 1664 PJ_ASSERT_RETURN(PJ_STUN_IS_REQUEST(msg_type), 1637 PJNATH_E STUNINMSGTYPE);1665 PJNATH_EINSTUNMSGTYPE); 1638 1666 1639 1667 /* Create response or error response */ … … 1774 1802 } 1775 1803 1776 return PJ NATH_ESTUNUNKNOWNATTR;1804 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_ATTRIBUTE); 1777 1805 } 1778 1806 … … 2103 2131 /* Should not happen for message generated by us */ 2104 2132 pj_assert(PJ_FALSE); 2105 return PJ NATH_ESTUNNOUSERNAME;2133 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_MISSING_USERNAME); 2106 2134 } 2107 2135 -
pjproject/trunk/pjnath/src/pjnath/stun_transaction.c
r1080 r1101 236 236 tsx->complete = PJ_TRUE; 237 237 if (tsx->cb.on_complete) { 238 tsx->cb.on_complete(tsx, PJNATH_ESTUN NOTRESPOND, NULL);238 tsx->cb.on_complete(tsx, PJNATH_ESTUNTIMEDOUT, NULL); 239 239 } 240 240 return; … … 269 269 PJ_LOG(4,(tsx->obj_name, 270 270 "STUN rx_msg() error: not response message")); 271 return PJNATH_E STUNNOTRESPONSE;271 return PJNATH_EINSTUNMSGTYPE; 272 272 } 273 273 … … 301 301 status = PJ_SUCCESS; 302 302 } else { 303 status = PJNATH_ESTUNTSXFAILED; 303 status = PJ_STATUS_FROM_STUN_CODE(err_attr->err_class * 100 + 304 err_attr->number); 304 305 } 305 306 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r1099 r1101 400 400 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 401 401 402 /* Init PJNATH */ 403 status = pjnath_init(); 404 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 402 405 403 406 /* Set default sound device ID */
Note: See TracChangeset
for help on using the changeset viewer.