Changeset 1101 for pjproject/trunk/pjnath/src/pjnath/errno.c
- Timestamp:
- Mar 24, 2007 1:00:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.