blob: 03d7ead63476ec773080d9b59bad3357b405803b [file] [log] [blame]
Benny Prijonof80b1bf2006-02-19 02:24:27 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijonof80b1bf2006-02-19 02:24:27 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <pjsip-simple/errno.h>
Benny Prijono26ff9062006-02-21 23:47:00 +000021#include <pj/string.h>
22
23/* PJSIP-SIMPLE's own error codes/messages
24 * MUST KEEP THIS ARRAY SORTED!!
25 * Message must be limited to 64 chars!
26 */
Benny Prijono3ba816e2006-03-18 12:26:55 +000027
28#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
29
Benny Prijono26ff9062006-02-21 23:47:00 +000030static const struct
31{
32 int code;
33 const char *msg;
34} err_str[] =
35{
Benny Prijonob0808372006-03-02 21:18:58 +000036 /* Event errors */
Benny Prijono26ff9062006-02-21 23:47:00 +000037 { PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" },
38 { PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" },
39
Benny Prijonob0808372006-03-02 21:18:58 +000040 /* Presence errors */
Benny Prijono26ff9062006-02-21 23:47:00 +000041 { PJSIP_SIMPLE_ENOTSUBSCRIBE, "Expecting SUBSCRIBE request" },
42 { PJSIP_SIMPLE_ENOPRESENCE, "No presence associated with the subscription" },
43 { PJSIP_SIMPLE_ENOPRESENCEINFO, "No presence info in the server subscription" },
44 { PJSIP_SIMPLE_EBADCONTENT, "Bad Content-Type for presence" },
45 { PJSIP_SIMPLE_EBADPIDF, "Bad PIDF content for presence" },
46 { PJSIP_SIMPLE_EBADXPIDF, "Bad XPIDF content for presence" },
Benny Prijono4461c7d2007-08-25 13:36:15 +000047 { PJSIP_SIMPLE_EBADRPID, "Invalid or bad RPID document"},
Benny Prijonob0808372006-03-02 21:18:58 +000048
49 /* isComposing errors. */
50 { PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" },
Benny Prijono26ff9062006-02-21 23:47:00 +000051};
52
53
Benny Prijono3ba816e2006-03-18 12:26:55 +000054#endif /* PJ_HAS_ERROR_STRING */
55
Benny Prijono26ff9062006-02-21 23:47:00 +000056
57/*
58 * pjsipsimple_strerror()
59 */
60PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode,
61 char *buf, pj_size_t bufsize )
62{
63 pj_str_t errstr;
64
Benny Prijono3ba816e2006-03-18 12:26:55 +000065#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
66
Benny Prijono26ff9062006-02-21 23:47:00 +000067 if (statcode >= PJSIP_SIMPLE_ERRNO_START &&
68 statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
69 {
70 /* Find the error in the table.
71 * Use binary search!
72 */
73 int first = 0;
74 int n = PJ_ARRAY_SIZE(err_str);
75
76 while (n > 0) {
77 int half = n/2;
78 int mid = first + half;
79
80 if (err_str[mid].code < statcode) {
81 first = mid+1;
82 n -= (half+1);
83 } else if (err_str[mid].code > statcode) {
84 n = half;
85 } else {
86 first = mid;
87 break;
88 }
89 }
90
91
92 if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
93 pj_str_t msg;
94
95 msg.ptr = (char*)err_str[first].msg;
96 msg.slen = pj_ansi_strlen(err_str[first].msg);
97
98 errstr.ptr = buf;
99 pj_strncpy_with_null(&errstr, &msg, bufsize);
100 return errstr;
101
102 }
103 }
104
Benny Prijono3ba816e2006-03-18 12:26:55 +0000105#endif /* PJ_HAS_ERROR_STRING */
106
107
Benny Prijono26ff9062006-02-21 23:47:00 +0000108 /* Error not found. */
109 errstr.ptr = buf;
Benny Prijonoed811d72006-03-10 12:57:12 +0000110 errstr.slen = pj_ansi_snprintf(buf, bufsize,
Benny Prijono3ba816e2006-03-18 12:26:55 +0000111 "Unknown pjsip-simple error %d",
Benny Prijonoed811d72006-03-10 12:57:12 +0000112 statcode);
Benny Prijono26ff9062006-02-21 23:47:00 +0000113
114 return errstr;
115}
Benny Prijonof80b1bf2006-02-19 02:24:27 +0000116