| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pjsip-simple/errno.h> |
| 20 |
#include <pj/string.h> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 28 |
|
| 29 |
static const struct |
| 30 |
{ |
| 31 |
int code; |
| 32 |
const char *msg; |
| 33 |
} err_str[] = |
| 34 |
{ |
| 35 |
|
| 36 |
{ PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" }, |
| 37 |
{ PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" }, |
| 38 |
|
| 39 |
|
| 40 |
{ PJSIP_SIMPLE_ENOTSUBSCRIBE, "Expecting SUBSCRIBE request" }, |
| 41 |
{ PJSIP_SIMPLE_ENOPRESENCE, "No presence associated with the subscription" }, |
| 42 |
{ PJSIP_SIMPLE_ENOPRESENCEINFO, "No presence info in the server subscription" }, |
| 43 |
{ PJSIP_SIMPLE_EBADCONTENT, "Bad Content-Type for presence" }, |
| 44 |
{ PJSIP_SIMPLE_EBADPIDF, "Bad PIDF content for presence" }, |
| 45 |
{ PJSIP_SIMPLE_EBADXPIDF, "Bad XPIDF content for presence" }, |
| 46 |
{ PJSIP_SIMPLE_EBADRPID, "Invalid or bad RPID document"}, |
| 47 |
|
| 48 |
|
| 49 |
{ PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" }, |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
#endif |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode, |
| 60 |
char *buf, pj_size_t bufsize ) |
| 61 |
{ |
| 62 |
pj_str_t errstr; |
| 63 |
|
| 64 |
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 65 |
|
| 66 |
if (statcode >= PJSIP_SIMPLE_ERRNO_START && |
| 67 |
statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE) |
| 68 |
{ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
int first = 0; |
| 73 |
int n = PJ_ARRAY_SIZE(err_str); |
| 74 |
|
| 75 |
while (n > 0) { |
| 76 |
int half = n/2; |
| 77 |
int mid = first + half; |
| 78 |
|
| 79 |
if (err_str[mid].code < statcode) { |
| 80 |
first = mid+1; |
| 81 |
n -= (half+1); |
| 82 |
} else if (err_str[mid].code > statcode) { |
| 83 |
n = half; |
| 84 |
} else { |
| 85 |
first = mid; |
| 86 |
break; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) { |
| 92 |
pj_str_t msg; |
| 93 |
|
| 94 |
msg.ptr = (char*)err_str[first].msg; |
| 95 |
msg.slen = pj_ansi_strlen(err_str[first].msg); |
| 96 |
|
| 97 |
errstr.ptr = buf; |
| 98 |
pj_strncpy_with_null(&errstr, &msg, bufsize); |
| 99 |
return errstr; |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
#endif |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
errstr.ptr = buf; |
| 109 |
errstr.slen = pj_ansi_snprintf(buf, bufsize, |
| 110 |
"Unknown pjsip-simple error %d", |
| 111 |
statcode); |
| 112 |
if (errstr.slen < 1 || errstr.slen >= (pj_ssize_t)bufsize) |
| 113 |
errstr.slen = bufsize - 1; |
| 114 |
return errstr; |
| 115 |
} |
| 116 |
|