1
/* $Id: sip_errno.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#include <pjsip/sip_errno.h>
21
#include <pjsip/sip_msg.h>
22
#include <pj/string.h>
25
/* PJSIP's own error codes/messages
26
* MUST KEEP THIS ARRAY SORTED!!
29
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
37
/* Generic SIP errors */
38
PJ_BUILD_ERR( PJSIP_EBUSY, "Object is busy" ),
39
PJ_BUILD_ERR( PJSIP_ETYPEEXISTS , "Object with the same type exists" ),
40
PJ_BUILD_ERR( PJSIP_ESHUTDOWN, "SIP stack shutting down" ),
41
PJ_BUILD_ERR( PJSIP_ENOTINITIALIZED,"SIP object is not initialized." ),
42
PJ_BUILD_ERR( PJSIP_ENOROUTESET, "Missing route set (for tel: URI)" ),
44
/* Messaging errors */
45
PJ_BUILD_ERR( PJSIP_EINVALIDMSG, "Invalid message/syntax error" ),
46
PJ_BUILD_ERR( PJSIP_ENOTREQUESTMSG, "Expecting request message"),
47
PJ_BUILD_ERR( PJSIP_ENOTRESPONSEMSG,"Expecting response message"),
48
PJ_BUILD_ERR( PJSIP_EMSGTOOLONG, "Message too long" ),
49
PJ_BUILD_ERR( PJSIP_EPARTIALMSG, "Partial message" ),
51
PJ_BUILD_ERR( PJSIP_EINVALIDSTATUS, "Invalid/unexpected SIP status code"),
53
PJ_BUILD_ERR( PJSIP_EINVALIDURI, "Invalid URI" ),
54
PJ_BUILD_ERR( PJSIP_EINVALIDSCHEME, "Invalid URI scheme" ),
55
PJ_BUILD_ERR( PJSIP_EMISSINGREQURI, "Missing Request-URI" ),
56
PJ_BUILD_ERR( PJSIP_EINVALIDREQURI, "Invalid Request URI" ),
57
PJ_BUILD_ERR( PJSIP_EURITOOLONG, "URI is too long" ),
59
PJ_BUILD_ERR( PJSIP_EMISSINGHDR, "Missing required header(s)" ),
60
PJ_BUILD_ERR( PJSIP_EINVALIDHDR, "Invalid header field"),
61
PJ_BUILD_ERR( PJSIP_EINVALIDVIA, "Invalid Via header" ),
62
PJ_BUILD_ERR( PJSIP_EMULTIPLEVIA, "Multiple Via headers in response" ),
64
PJ_BUILD_ERR( PJSIP_EMISSINGBODY, "Missing message body" ),
65
PJ_BUILD_ERR( PJSIP_EINVALIDMETHOD, "Invalid/unexpected method" ),
67
/* Transport errors */
68
PJ_BUILD_ERR( PJSIP_EUNSUPTRANSPORT,"Unsupported transport"),
69
PJ_BUILD_ERR( PJSIP_EPENDINGTX, "Transmit buffer already pending"),
70
PJ_BUILD_ERR( PJSIP_ERXOVERFLOW, "Rx buffer overflow"),
71
PJ_BUILD_ERR( PJSIP_EBUFDESTROYED, "Buffer destroyed"),
72
PJ_BUILD_ERR( PJSIP_ETPNOTSUITABLE, "Unsuitable transport selected"),
73
PJ_BUILD_ERR( PJSIP_ETPNOTAVAIL, "Transport not available for use"),
75
/* Transaction errors */
76
PJ_BUILD_ERR( PJSIP_ETSXDESTROYED, "Transaction has been destroyed"),
77
PJ_BUILD_ERR( PJSIP_ENOTSX, "No transaction is associated with the object "
78
"(expecting stateful processing)" ),
80
/* URI comparison status */
81
PJ_BUILD_ERR( PJSIP_ECMPSCHEME, "URI scheme mismatch" ),
82
PJ_BUILD_ERR( PJSIP_ECMPUSER, "URI user part mismatch" ),
83
PJ_BUILD_ERR( PJSIP_ECMPPASSWD, "URI password part mismatch" ),
84
PJ_BUILD_ERR( PJSIP_ECMPHOST, "URI host part mismatch" ),
85
PJ_BUILD_ERR( PJSIP_ECMPPORT, "URI port mismatch" ),
86
PJ_BUILD_ERR( PJSIP_ECMPTRANSPORTPRM,"URI transport param mismatch" ),
87
PJ_BUILD_ERR( PJSIP_ECMPTTLPARAM, "URI ttl param mismatch" ),
88
PJ_BUILD_ERR( PJSIP_ECMPUSERPARAM, "URI user param mismatch" ),
89
PJ_BUILD_ERR( PJSIP_ECMPMETHODPARAM,"URI method param mismatch" ),
90
PJ_BUILD_ERR( PJSIP_ECMPMADDRPARAM, "URI maddr param mismatch" ),
91
PJ_BUILD_ERR( PJSIP_ECMPOTHERPARAM, "URI other param mismatch" ),
92
PJ_BUILD_ERR( PJSIP_ECMPHEADERPARAM,"URI header parameter mismatch" ),
95
PJ_BUILD_ERR( PJSIP_EFAILEDCREDENTIAL, "Credential failed to authenticate"),
96
PJ_BUILD_ERR( PJSIP_ENOCREDENTIAL, "No suitable credential"),
97
PJ_BUILD_ERR( PJSIP_EINVALIDALGORITHM, "Invalid/unsupported digest algorithm" ),
98
PJ_BUILD_ERR( PJSIP_EINVALIDQOP, "Invalid/unsupported digest qop" ),
99
PJ_BUILD_ERR( PJSIP_EINVALIDAUTHSCHEME,"Unsupported authentication scheme" ),
100
PJ_BUILD_ERR( PJSIP_EAUTHNOPREVCHAL, "No previous challenge" ),
101
PJ_BUILD_ERR( PJSIP_EAUTHNOAUTH, "No suitable authorization header" ),
102
PJ_BUILD_ERR( PJSIP_EAUTHACCNOTFOUND, "Account or credential not found" ),
103
PJ_BUILD_ERR( PJSIP_EAUTHACCDISABLED, "Account or credential is disabled" ),
104
PJ_BUILD_ERR( PJSIP_EAUTHINVALIDREALM, "Invalid authorization realm"),
105
PJ_BUILD_ERR( PJSIP_EAUTHINVALIDDIGEST,"Invalid authorization digest" ),
106
PJ_BUILD_ERR( PJSIP_EAUTHSTALECOUNT, "Maximum number of stale retries exceeded"),
107
PJ_BUILD_ERR( PJSIP_EAUTHINNONCE, "Invalid nonce value in authentication challenge"),
108
PJ_BUILD_ERR( PJSIP_EAUTHINAKACRED, "Invalid AKA credential"),
109
PJ_BUILD_ERR( PJSIP_EAUTHNOCHAL, "No challenge is found"),
111
/* UA/dialog layer. */
112
PJ_BUILD_ERR( PJSIP_EMISSINGTAG, "Missing From/To tag parameter" ),
113
PJ_BUILD_ERR( PJSIP_ENOTREFER, "Expecting REFER request") ,
114
PJ_BUILD_ERR( PJSIP_ENOREFERSESSION,"Not associated with REFER subscription"),
116
/* Invite session. */
117
PJ_BUILD_ERR( PJSIP_ESESSIONTERMINATED, "INVITE session already terminated" ),
118
PJ_BUILD_ERR( PJSIP_ESESSIONSTATE, "Invalid INVITE session state" ),
119
PJ_BUILD_ERR( PJSIP_ESESSIONINSECURE, "Require secure session/transport"),
122
PJ_BUILD_ERR( PJSIP_TLS_EUNKNOWN, "Unknown TLS error" ),
123
PJ_BUILD_ERR( PJSIP_TLS_EINVMETHOD, "Invalid SSL protocol method" ),
124
PJ_BUILD_ERR( PJSIP_TLS_ECACERT, "Error loading/verifying SSL CA list file"),
125
PJ_BUILD_ERR( PJSIP_TLS_ECERTFILE, "Error loading SSL certificate chain file"),
126
PJ_BUILD_ERR( PJSIP_TLS_EKEYFILE, "Error adding private key from SSL certificate file"),
127
PJ_BUILD_ERR( PJSIP_TLS_ECIPHER, "Error setting SSL cipher list"),
128
PJ_BUILD_ERR( PJSIP_TLS_ECTX, "Error creating SSL context"),
129
PJ_BUILD_ERR( PJSIP_TLS_ESSLCONN, "Error creating SSL connection object"),
130
PJ_BUILD_ERR( PJSIP_TLS_ECONNECT, "Unknown error when performing SSL connect()"),
131
PJ_BUILD_ERR( PJSIP_TLS_EACCEPT, "Unknown error when performing SSL accept()"),
132
PJ_BUILD_ERR( PJSIP_TLS_ESEND, "Unknown error when sending SSL data"),
133
PJ_BUILD_ERR( PJSIP_TLS_EREAD, "Unknown error when reading SSL data"),
134
PJ_BUILD_ERR( PJSIP_TLS_ETIMEDOUT, "SSL negotiation has timed out"),
135
PJ_BUILD_ERR( PJSIP_TLS_ECERTVERIF, "SSL certificate verification error"),
139
#endif /* PJ_HAS_ERROR_STRING */
145
PJ_DEF(pj_str_t) pjsip_strerror( pj_status_t statcode,
146
char *buf, pj_size_t bufsize )
150
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
152
if (statcode >= PJSIP_ERRNO_START && statcode < PJSIP_ERRNO_START+800)
155
const pj_str_t *status_text =
156
pjsip_get_status_text(PJSIP_ERRNO_TO_SIP_STATUS(statcode));
159
pj_strncpy_with_null(&errstr, status_text, bufsize);
162
else if (statcode >= PJSIP_ERRNO_START_PJSIP &&
163
statcode < PJSIP_ERRNO_START_PJSIP + 1000)
165
/* Find the error in the table.
169
int n = PJ_ARRAY_SIZE(err_str);
173
int mid = first + half;
175
if (err_str[mid].code < statcode) {
178
} else if (err_str[mid].code > statcode) {
187
if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
190
msg.ptr = (char*)err_str[first].msg;
191
msg.slen = pj_ansi_strlen(err_str[first].msg);
194
pj_strncpy_with_null(&errstr, &msg, bufsize);
200
#endif /* PJ_HAS_ERROR_STRING */
202
/* Error not found. */
204
errstr.slen = pj_ansi_snprintf(buf, bufsize,
205
"Unknown pjsip error %d",