Debian Codegraph @

Xpjproject/pjsip/src/pjsip-simple/errno.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
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>
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 */
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 /* Event errors */
36 { PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" },
37 { PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" },
38
39 /* Presence errors */
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 /* isComposing errors. */
49 { PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" },
50 };
51
52
53 #endif /* PJ_HAS_ERROR_STRING */
54
55
56 /*
57 * pjsipsimple_strerror()
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 /* Find the error in the table.
70 * Use binary search!
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 /* PJ_HAS_ERROR_STRING */
105
106
107 /* Error not found. */
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