Changeset 212 for pjproject/trunk/pjsip/src/pjsip-simple/errno.c
- Timestamp:
- Feb 21, 2006 11:47:00 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-simple/errno.c
r198 r212 18 18 */ 19 19 #include <pjsip-simple/errno.h> 20 #include <pj/string.h> 20 21 22 /* PJSIP-SIMPLE's own error codes/messages 23 * MUST KEEP THIS ARRAY SORTED!! 24 * Message must be limited to 64 chars! 25 */ 26 static const struct 27 { 28 int code; 29 const char *msg; 30 } err_str[] = 31 { 32 { PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" }, 33 { PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" }, 34 35 { PJSIP_SIMPLE_ENOTSUBSCRIBE, "Expecting SUBSCRIBE request" }, 36 { PJSIP_SIMPLE_ENOPRESENCE, "No presence associated with the subscription" }, 37 { PJSIP_SIMPLE_ENOPRESENCEINFO, "No presence info in the server subscription" }, 38 { PJSIP_SIMPLE_EBADCONTENT, "Bad Content-Type for presence" }, 39 { PJSIP_SIMPLE_EBADPIDF, "Bad PIDF content for presence" }, 40 { PJSIP_SIMPLE_EBADXPIDF, "Bad XPIDF content for presence" }, 41 }; 42 43 44 45 /* 46 * pjsipsimple_strerror() 47 */ 48 PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode, 49 char *buf, pj_size_t bufsize ) 50 { 51 pj_str_t errstr; 52 53 if (statcode >= PJSIP_SIMPLE_ERRNO_START && 54 statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE) 55 { 56 /* Find the error in the table. 57 * Use binary search! 58 */ 59 int first = 0; 60 int n = PJ_ARRAY_SIZE(err_str); 61 62 while (n > 0) { 63 int half = n/2; 64 int mid = first + half; 65 66 if (err_str[mid].code < statcode) { 67 first = mid+1; 68 n -= (half+1); 69 } else if (err_str[mid].code > statcode) { 70 n = half; 71 } else { 72 first = mid; 73 break; 74 } 75 } 76 77 78 if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) { 79 pj_str_t msg; 80 81 msg.ptr = (char*)err_str[first].msg; 82 msg.slen = pj_ansi_strlen(err_str[first].msg); 83 84 errstr.ptr = buf; 85 pj_strncpy_with_null(&errstr, &msg, bufsize); 86 return errstr; 87 88 } 89 } 90 91 /* Error not found. */ 92 errstr.ptr = buf; 93 errstr.slen = pj_snprintf(buf, bufsize, 94 "Unknown error %d", 95 statcode); 96 97 return errstr; 98 } 99
Note: See TracChangeset
for help on using the changeset viewer.