blob: 4248fdaf7ef2d09eae0e6fee2a9e42ee72d60d18 [file] [log] [blame]
Benny Prijonof80b1bf2006-02-19 02:24:27 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijonof80b1bf2006-02-19 02:24:27 +00004 *
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 Prijono26ff9062006-02-21 23:47:00 +000020#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 Prijono3ba816e2006-03-18 12:26:55 +000026
27#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
28
Benny Prijono26ff9062006-02-21 23:47:00 +000029static const struct
30{
31 int code;
32 const char *msg;
33} err_str[] =
34{
Benny Prijonob0808372006-03-02 21:18:58 +000035 /* Event errors */
Benny Prijono26ff9062006-02-21 23:47:00 +000036 { PJSIP_SIMPLE_ENOPKG, "No SIP event package with the specified name" },
37 { PJSIP_SIMPLE_EPKGEXISTS, "SIP event package already exist" },
38
Benny Prijonob0808372006-03-02 21:18:58 +000039 /* Presence errors */
Benny Prijono26ff9062006-02-21 23:47:00 +000040 { 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 Prijono4461c7d2007-08-25 13:36:15 +000046 { PJSIP_SIMPLE_EBADRPID, "Invalid or bad RPID document"},
Benny Prijonob0808372006-03-02 21:18:58 +000047
48 /* isComposing errors. */
49 { PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" },
Benny Prijono26ff9062006-02-21 23:47:00 +000050};
51
52
Benny Prijono3ba816e2006-03-18 12:26:55 +000053#endif /* PJ_HAS_ERROR_STRING */
54
Benny Prijono26ff9062006-02-21 23:47:00 +000055
56/*
57 * pjsipsimple_strerror()
58 */
59PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode,
60 char *buf, pj_size_t bufsize )
61{
62 pj_str_t errstr;
63
Benny Prijono3ba816e2006-03-18 12:26:55 +000064#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
65
Benny Prijono26ff9062006-02-21 23:47:00 +000066 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
Benny Prijono3ba816e2006-03-18 12:26:55 +0000104#endif /* PJ_HAS_ERROR_STRING */
105
106
Benny Prijono26ff9062006-02-21 23:47:00 +0000107 /* Error not found. */
108 errstr.ptr = buf;
Benny Prijonoed811d72006-03-10 12:57:12 +0000109 errstr.slen = pj_ansi_snprintf(buf, bufsize,
Benny Prijono3ba816e2006-03-18 12:26:55 +0000110 "Unknown pjsip-simple error %d",
Benny Prijonoed811d72006-03-10 12:57:12 +0000111 statcode);
Benny Prijono26ff9062006-02-21 23:47:00 +0000112
113 return errstr;
114}
Benny Prijonof80b1bf2006-02-19 02:24:27 +0000115