Benny Prijono | f80b1bf | 2006-02-19 02:24:27 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #include <pjsip-simple/errno.h> |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 20 | #include <pj/string.h> |
| 21 | |
| 22 | /* PJSIP-SIMPLE's own error codes/messages |
| 23 | * MUST KEEP THIS ARRAY SORTED!! |
| 24 | * Message must be limited to 64 chars! |
| 25 | */ |
Benny Prijono | 3ba816e | 2006-03-18 12:26:55 +0000 | [diff] [blame] | 26 | |
| 27 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 28 | |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 29 | static const struct |
| 30 | { |
| 31 | int code; |
| 32 | const char *msg; |
| 33 | } err_str[] = |
| 34 | { |
Benny Prijono | b080837 | 2006-03-02 21:18:58 +0000 | [diff] [blame] | 35 | /* Event errors */ |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 36 | { PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" }, |
| 37 | { PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" }, |
| 38 | |
Benny Prijono | b080837 | 2006-03-02 21:18:58 +0000 | [diff] [blame] | 39 | /* Presence errors */ |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 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" }, |
Benny Prijono | b080837 | 2006-03-02 21:18:58 +0000 | [diff] [blame] | 46 | |
| 47 | /* isComposing errors. */ |
| 48 | { PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" }, |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | |
Benny Prijono | 3ba816e | 2006-03-18 12:26:55 +0000 | [diff] [blame] | 52 | #endif /* PJ_HAS_ERROR_STRING */ |
| 53 | |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * pjsipsimple_strerror() |
| 57 | */ |
| 58 | PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode, |
| 59 | char *buf, pj_size_t bufsize ) |
| 60 | { |
| 61 | pj_str_t errstr; |
| 62 | |
Benny Prijono | 3ba816e | 2006-03-18 12:26:55 +0000 | [diff] [blame] | 63 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 64 | |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 65 | if (statcode >= PJSIP_SIMPLE_ERRNO_START && |
| 66 | statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE) |
| 67 | { |
| 68 | /* Find the error in the table. |
| 69 | * Use binary search! |
| 70 | */ |
| 71 | int first = 0; |
| 72 | int n = PJ_ARRAY_SIZE(err_str); |
| 73 | |
| 74 | while (n > 0) { |
| 75 | int half = n/2; |
| 76 | int mid = first + half; |
| 77 | |
| 78 | if (err_str[mid].code < statcode) { |
| 79 | first = mid+1; |
| 80 | n -= (half+1); |
| 81 | } else if (err_str[mid].code > statcode) { |
| 82 | n = half; |
| 83 | } else { |
| 84 | first = mid; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | |
| 90 | if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) { |
| 91 | pj_str_t msg; |
| 92 | |
| 93 | msg.ptr = (char*)err_str[first].msg; |
| 94 | msg.slen = pj_ansi_strlen(err_str[first].msg); |
| 95 | |
| 96 | errstr.ptr = buf; |
| 97 | pj_strncpy_with_null(&errstr, &msg, bufsize); |
| 98 | return errstr; |
| 99 | |
| 100 | } |
| 101 | } |
| 102 | |
Benny Prijono | 3ba816e | 2006-03-18 12:26:55 +0000 | [diff] [blame] | 103 | #endif /* PJ_HAS_ERROR_STRING */ |
| 104 | |
| 105 | |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 106 | /* Error not found. */ |
| 107 | errstr.ptr = buf; |
Benny Prijono | ed811d7 | 2006-03-10 12:57:12 +0000 | [diff] [blame] | 108 | errstr.slen = pj_ansi_snprintf(buf, bufsize, |
Benny Prijono | 3ba816e | 2006-03-18 12:26:55 +0000 | [diff] [blame] | 109 | "Unknown pjsip-simple error %d", |
Benny Prijono | ed811d7 | 2006-03-10 12:57:12 +0000 | [diff] [blame] | 110 | statcode); |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 111 | |
| 112 | return errstr; |
| 113 | } |
Benny Prijono | f80b1bf | 2006-02-19 02:24:27 +0000 | [diff] [blame] | 114 | |