Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips 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 | | * opensips 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | * |
20 | | * |
21 | | * History: |
22 | | * -------- |
23 | | * 2003-04-04 phrase length corrected not to include trailer 0 (jiri) |
24 | | * 2006-12-18 error phrases updates (norman) |
25 | | */ |
26 | | |
27 | | /*! |
28 | | * \file error.c |
29 | | * \brief OpenSIPS Error handling functions |
30 | | * |
31 | | * \note For a list of error codes in SIP, please check |
32 | | * http://www.iana.org/assignments/sip-parameters |
33 | | */ |
34 | | |
35 | | |
36 | | #include <stdio.h> |
37 | | #include "error.h" |
38 | | #include "str.h" |
39 | | #include "parser/msg_parser.h" |
40 | | #include "mem/mem.h" |
41 | | |
42 | | /*! current function's error; */ |
43 | | int ser_error=-1; |
44 | | /*! previous error */ |
45 | | int prev_ser_error=-1; |
46 | | |
47 | | int err2reason_phrase( |
48 | | int error, /*!< current internal ser error */ |
49 | | int *sip_error, /*!< the sip error code to which ser error will be turned */ |
50 | | char *phrase, /*!< resulting error text */ |
51 | | int etl, /*!< error text buffer length */ |
52 | | char *signature ) /*!< extra text to be appended */ |
53 | 0 | { |
54 | |
|
55 | 0 | char *error_txt; |
56 | |
|
57 | 0 | switch( error ) { |
58 | 0 | case E_IP_BLOCKED: |
59 | 0 | error_txt="Filtered destination"; |
60 | 0 | *sip_error=-error; |
61 | 0 | break; |
62 | 0 | case E_SEND: |
63 | 0 | error_txt="Send failed"; |
64 | 0 | *sip_error=-error; |
65 | 0 | break; |
66 | 0 | case E_BAD_ADDRESS: |
67 | 0 | error_txt="Unresolvable destination"; |
68 | 0 | *sip_error=-error; |
69 | 0 | break; |
70 | 0 | case E_BAD_REQ: |
71 | 0 | error_txt="Bad Request"; |
72 | 0 | *sip_error=-error; |
73 | 0 | break; |
74 | 0 | case E_BAD_URI: |
75 | 0 | error_txt="Bad URI"; |
76 | 0 | *sip_error=-error; |
77 | 0 | break; |
78 | 0 | case E_BAD_TUPEL: |
79 | 0 | error_txt="Transaction tuple incomplete"; |
80 | 0 | *sip_error=-E_BAD_REQ; |
81 | 0 | break; |
82 | 0 | case E_BAD_TO: |
83 | 0 | error_txt="Bad To"; |
84 | 0 | *sip_error=-E_BAD_REQ; |
85 | 0 | break; |
86 | 0 | case E_EXEC: |
87 | 0 | error_txt="Error in external logic"; |
88 | 0 | *sip_error=-E_BAD_SERVER; |
89 | 0 | break; |
90 | 0 | case E_TOO_MANY_BRANCHES: |
91 | 0 | error_txt="Forking capacity exceeded"; |
92 | 0 | *sip_error=-E_BAD_SERVER; |
93 | 0 | break; |
94 | 0 | case E_Q_INV_CHAR: |
95 | 0 | error_txt="Invalid character in q parameter"; |
96 | 0 | *sip_error=-E_BAD_REQ; |
97 | 0 | break; |
98 | 0 | case E_Q_EMPTY: |
99 | 0 | error_txt="Empty q parameter"; |
100 | 0 | *sip_error=-E_BAD_REQ; |
101 | 0 | break;; |
102 | 0 | case E_Q_TOO_BIG: |
103 | 0 | error_txt="q parameter too big"; |
104 | 0 | *sip_error=-E_BAD_REQ; |
105 | 0 | break; |
106 | 0 | case E_NO_DESTINATION: |
107 | 0 | error_txt="No destination available"; |
108 | 0 | *sip_error=-E_BAD_SERVER; |
109 | 0 | break; |
110 | 0 | case E_OUT_OF_MEM: |
111 | | /* don't disclose lack of mem in release mode */ |
112 | | #ifdef DEBUG |
113 | | error_txt="Excuse me I ran out of memory"; |
114 | | *sip_error=-E_BAD_SERVER; |
115 | | break; |
116 | | #endif |
117 | 0 | default: |
118 | 0 | error_txt="Server error occurred"; |
119 | 0 | *sip_error=-E_BAD_SERVER; |
120 | 0 | break; |
121 | 0 | } |
122 | 0 | return snprintf( phrase, etl, "%s (%d/%s)", error_txt, |
123 | 0 | -error, signature ); |
124 | 0 | } |
125 | | |
126 | | char *error_text( int code ) |
127 | 0 | { |
128 | 0 | switch(code) { |
129 | | |
130 | 0 | case 100: return "Trying"; |
131 | 0 | case 180: return "Ringing"; |
132 | 0 | case 181: return "Call is Being Forwarded"; |
133 | 0 | case 182: return "Queued"; |
134 | 0 | case 183: return "Session Progress"; |
135 | | |
136 | 0 | case 200: return "OK"; |
137 | 0 | case 202: return "Accepted"; |
138 | | |
139 | 0 | case 300: return "Multiple Choices"; |
140 | 0 | case 301: return "Moved Permanently"; |
141 | 0 | case 302: return "Moved Temporarily"; |
142 | 0 | case 305: return "Use Proxy"; |
143 | 0 | case 380: return "Alternative Service"; |
144 | | |
145 | 0 | case 400: return "Bad Request"; |
146 | 0 | case 401: return "Unauthorized"; |
147 | 0 | case 402: return "Payment Required"; |
148 | 0 | case 403: return "Forbidden"; |
149 | 0 | case 404: return "Not Found"; |
150 | 0 | case 405: return "Method not Allowed"; |
151 | 0 | case 406: return "Not Acceptable"; |
152 | 0 | case 407: return "Proxy Authentication Required"; |
153 | 0 | case 408: return "Request Timeout"; |
154 | 0 | case 409: return "Conflict"; |
155 | 0 | case 410: return "Gone"; |
156 | 0 | case 411: return "Length Required"; |
157 | 0 | case 412: return "Conditional Request Failed"; |
158 | 0 | case 413: return "Request Entity Too Large"; |
159 | 0 | case 414: return "Request-URI Too Long"; |
160 | 0 | case 415: return "Unsupported Media Type"; |
161 | 0 | case 416: return "Unsupported URI Scheme"; |
162 | 0 | case 417: return "Unknown Resource-Priority"; |
163 | 0 | case 420: return "Bad Extension"; |
164 | 0 | case 421: return "Extension Required"; |
165 | 0 | case 422: return "Session Interval Too Small"; |
166 | 0 | case 423: return "Interval Too Brief"; |
167 | 0 | case 428: return "Use Identity Header"; |
168 | 0 | case 429: return "Provide Referrer Identity"; |
169 | 0 | case 436: return "Bad Identity-Info"; |
170 | 0 | case 437: return "Unsupported Certificate"; |
171 | 0 | case 438: return "Invalid Identity Header"; |
172 | 0 | case 480: return "Temporarily Unavailable"; |
173 | 0 | case 481: return "Call/Transaction Does not Exist"; |
174 | 0 | case 482: return "Loop Detected"; |
175 | 0 | case 483: return "Too Many Hops"; |
176 | 0 | case 484: return "Address Incomplete"; |
177 | 0 | case 485: return "Ambiguous"; |
178 | 0 | case 486: return "Busy Here"; |
179 | 0 | case 487: return "Request Terminated"; |
180 | 0 | case 488: return "Not Acceptable Here"; |
181 | 0 | case 489: return "Bad Event"; |
182 | 0 | case 491: return "Request Pending"; |
183 | 0 | case 493: return "Undecipherable"; |
184 | 0 | case 494: return "Security Agreement Required"; |
185 | | |
186 | 0 | case 500: return "Server Internal Error"; |
187 | 0 | case 501: return "Not Implemented"; |
188 | 0 | case 502: return "Bad Gateway"; |
189 | 0 | case 503: return "Service Unavailable"; |
190 | 0 | case 504: return "Server Time-out"; |
191 | 0 | case 505: return "Version Not Supported"; |
192 | 0 | case 513: return "Message Too Large"; |
193 | 0 | case 555: return "Push Notification Service Not Supported"; |
194 | 0 | case 580: return "Precondition Failure"; |
195 | | |
196 | 0 | case 600: return "Busy Everywhere"; |
197 | 0 | case 603: return "Decline"; |
198 | 0 | case 604: return "Does not Exist Anywhere"; |
199 | 0 | case 606: return "Not Acceptable"; |
200 | |
|
201 | 0 | } |
202 | | |
203 | 0 | if (code>=600) return "Global Failure"; |
204 | 0 | else if (code>=500) return "Server Failure"; |
205 | 0 | else if (code>=400) return "Request Failure"; |
206 | 0 | else if (code>=300) return "Redirection"; |
207 | 0 | else if (code>=200) return "Successful"; |
208 | 0 | else if (code>=100) return "Provisional"; |
209 | 0 | else return "Unspecified"; |
210 | 0 | } |
211 | | |
212 | | void get_reply_status( str *status, struct sip_msg *reply, int code ) |
213 | 0 | { |
214 | 0 | str phrase; |
215 | |
|
216 | 0 | status->s=0; |
217 | |
|
218 | 0 | if (reply==0) { |
219 | 0 | LM_CRIT("called with 0 msg\n"); |
220 | 0 | return; |
221 | 0 | } |
222 | | |
223 | 0 | if (reply==FAKED_REPLY) { |
224 | 0 | phrase.s=error_text(code); |
225 | 0 | phrase.len=strlen(phrase.s); |
226 | 0 | } else { |
227 | 0 | phrase=reply->first_line.u.reply.reason; |
228 | 0 | } |
229 | 0 | status->len=phrase.len+3/*code*/+1/*space*/; |
230 | 0 | status->s=pkg_malloc(status->len+1/*ZT */); |
231 | 0 | if (!status->s) { |
232 | 0 | LM_ERR("no pkg mem\n"); |
233 | 0 | return; |
234 | 0 | } |
235 | 0 | status->s[3]=' '; |
236 | 0 | status->s[2]='0'+code % 10; code=code/10; |
237 | 0 | status->s[1]='0'+code% 10; code=code/10; |
238 | 0 | status->s[0]='0'+code % 10; |
239 | 0 | memcpy(&status->s[4], phrase.s, phrase.len); |
240 | 0 | status->s[status->len]=0; |
241 | 0 | } |