blob: 3f5c2e6b732b68d0480389480f75759de4695fa7 [file] [log] [blame]
Benny Prijonof80b1bf2006-02-19 02:24:27 +00001/* $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 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 Prijonob0808372006-03-02 21:18:58 +000046
47 /* isComposing errors. */
48 { PJSIP_SIMPLE_EBADISCOMPOSE, "Bad isComposing indication/XML message" },
Benny Prijono26ff9062006-02-21 23:47:00 +000049};
50
51
Benny Prijono3ba816e2006-03-18 12:26:55 +000052#endif /* PJ_HAS_ERROR_STRING */
53
Benny Prijono26ff9062006-02-21 23:47:00 +000054
55/*
56 * pjsipsimple_strerror()
57 */
58PJ_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 Prijono3ba816e2006-03-18 12:26:55 +000063#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
64
Benny Prijono26ff9062006-02-21 23:47:00 +000065 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 Prijono3ba816e2006-03-18 12:26:55 +0000103#endif /* PJ_HAS_ERROR_STRING */
104
105
Benny Prijono26ff9062006-02-21 23:47:00 +0000106 /* Error not found. */
107 errstr.ptr = buf;
Benny Prijonoed811d72006-03-10 12:57:12 +0000108 errstr.slen = pj_ansi_snprintf(buf, bufsize,
Benny Prijono3ba816e2006-03-18 12:26:55 +0000109 "Unknown pjsip-simple error %d",
Benny Prijonoed811d72006-03-10 12:57:12 +0000110 statcode);
Benny Prijono26ff9062006-02-21 23:47:00 +0000111
112 return errstr;
113}
Benny Prijonof80b1bf2006-02-19 02:24:27 +0000114