Browse code

Error reasons will be reported in Error-Info, not in reason phrase.

Jan Janak authored on 21/01/2003 20:48:54
Showing 2 changed files
... ...
@@ -29,17 +29,16 @@
29 29
  * History:
30 30
  * --------
31 31
  * 2003-01-18: buffer overflow patch committed (Jan on behalf of Maxim)
32
+ * 2003-01-21: Errors reported via Error-Info header field - janakj
32 33
  */
33 34
 
34
-
35
-#include "reply.h"
36 35
 #include <stdio.h>
37 36
 #include "../../parser/msg_parser.h"
38 37
 #include "../../data_lump_rpl.h"
39 38
 #include "rerrno.h"
40 39
 #include "reg_mod.h"
41 40
 #include "regtime.h"
42
-
41
+#include "reply.h"
43 42
 
44 43
 #define MAX_CONTACT_BUFFER 1024
45 44
 
... ...
@@ -47,11 +46,6 @@ static char b[MAX_CONTACT_BUFFER];
47 47
 static int l;
48 48
 
49 49
 
50
-#define MSG_200 "OK"
51
-#define MSG_400 "Bad Request"
52
-#define MSG_500 "Internal Server Error"
53
-
54
-
55 50
 /*
56 51
  * Build Contact HF for reply
57 52
  */
... ...
@@ -59,7 +53,7 @@ void build_contact(ucontact_t* _c)
59 59
 {
60 60
 	char *lastgoodend;
61 61
 	int nummissed;
62
-
62
+	
63 63
 	l = 0;
64 64
 	lastgoodend = b;
65 65
 	while(_c) {
... ...
@@ -112,38 +106,91 @@ void build_contact(ucontact_t* _c)
112 112
 }
113 113
 
114 114
 
115
-/*
116
- * Convert rerrno to code and message
117
- */
118
-static inline void rerrno2msg(int* _c, char** _m)
119
-{
120
-	switch(rerrno) {
121
-	case R_FINE:         *_c = 200; *_m = MSG_200;                                     break;
122
-	case R_UL_DEL_R:   *_c = 500; *_m = MSG_500 " - Usrloc_record_delete failed";      break;
123
-	case R_UL_GET_R:   *_c = 500; *_m = MSG_500 " - Usrloc_record_get failed";         break;
124
-	case R_UL_NEW_R:   *_c = 500; *_m = MSG_500 " - Usrloc_record_new failed";         break;
125
-	case R_INV_CSEQ:   *_c = 400; *_m = MSG_400 " - Invalid CSeq number";              break;
126
-	case R_UL_INS_C:   *_c = 500; *_m = MSG_500 " - Usrloc_contact_insert failed";     break;
127
-	case R_UL_INS_R:   *_c = 500; *_m = MSG_500 " - Usrloc_record_insert failed ";     break;
128
-	case R_UL_DEL_C:   *_c = 500; *_m = MSG_500 " - Usrloc_contact_delete failed";     break;			
129
-	case R_UL_UPD_C:   *_c = 500; *_m = MSG_500 " - Usrloc_contact_update failed";     break;
130
-	case R_TO_USER:    *_c = 400; *_m = MSG_400 " - No username in To URI";            break;
131
-	case R_AOR_LEN:    *_c = 500; *_m = MSG_500 " - Address Of Record too long";       break;
132
-	case R_AOR_PARSE:  *_c = 400; *_m = MSG_400 " - Error while parsing AOR";          break;
133
-	case R_INV_EXP:    *_c = 400; *_m = MSG_400 " - Invalid expires param in contact"; break;
134
-	case R_INV_Q:      *_c = 400; *_m = MSG_400 " - Invalid q param in contact";       break;
135
-	case R_PARSE:      *_c = 400; *_m = MSG_400 " - Message parse error";              break;
136
-	case R_TO_MISS:    *_c = 400; *_m = MSG_400 " - To header not found";              break;
137
-	case R_CID_MISS:   *_c = 400; *_m = MSG_400 " - Call-ID header not found";         break;
138
-	case R_CS_MISS:    *_c = 400; *_m = MSG_400 " - CSeq header not found";            break;
139
-	case R_PARSE_EXP:  *_c = 400; *_m = MSG_400 " - Expires parse error";              break;
140
-	case R_PARSE_CONT: *_c = 400; *_m = MSG_400 " - Contact parse error";              break;
141
-	case R_STAR_EXP:   *_c = 400; *_m = MSG_400 " - star and expires not zero";        break;
142
-	case R_STAR_CONT:  *_c = 400; *_m = MSG_400 " - star and more contacts";           break;
143
-	case R_OOO:        *_c = 200; *_m = MSG_200 " - Out Of Order";                     break;
144
-	case R_RETRANS:    *_c = 200; *_m = MSG_200 " - Retransmission";                   break;
145
-	}
146
-}
115
+
116
+#define MSG_200 "OK"
117
+#define MSG_400 "Bad Request"
118
+#define MSG_500 "Internal Server Error"
119
+
120
+#define EI_R_FINE       "No problem"                                /* R_FINE */
121
+#define EI_R_UL_DEL_R   "usrloc_record_delete failed"               /* R_UL_DEL_R */
122
+#define	EI_R_UL_GET_R   "usrloc_record_get failed"                  /* R_UL_GET */
123
+#define	EI_R_UL_NEW_R   "usrloc_record_new failed"                  /* R_UL_NEW_R */
124
+#define	EI_R_INV_CSEQ   "Invalid CSeq number"                       /* R_INV_CSEQ */
125
+#define	EI_R_UL_INS_C   "usrloc_contact_insert failed"              /* R_UL_INS_C */
126
+#define	EI_R_UL_INS_R   "usrloc_record_insert failed"               /* R_UL_INS_R */
127
+#define	EI_R_UL_DEL_C   "usrloc_contact_delete failed"              /* R_UL_DEL_C */
128
+#define	EI_R_UL_UPD_C   "usrloc_contact_update failed"              /* R_UL_UPD_C */
129
+#define	EI_R_TO_USER    "No username in To URI"                     /* R_TO_USER */
130
+#define	EI_R_AOR_LEN    "Address Of Record too long"                /* R_AOR_LEN */
131
+#define	EI_R_AOR_PARSE  "Error while parsing AOR"                   /* R_AOR_PARSE */
132
+#define	EI_R_INV_EXP    "Invalid expires param in contact"          /* R_INV_EXP */
133
+#define	EI_R_INV_Q      "Invalid q param in contact"                /* R_INV_Q */
134
+#define	EI_R_PARSE      "Message parse error"                       /* R_PARSE */
135
+#define	EI_R_TO_MISS    "To header not found"                       /* R_TO_MISS */
136
+#define	EI_R_CID_MISS   "Call-ID header not found"                  /* R_CID_MISS */
137
+#define	EI_R_CS_MISS    "CSeq header not found"                     /* R_CS_MISS */ 
138
+#define	EI_R_PARSE_EXP	"Expires parse error"                       /* R_PARSE_EXP */
139
+#define	EI_R_PARSE_CONT	"Contact parse error"                       /* R_PARSE_CONT */
140
+#define	EI_R_STAR_EXP	"* used in contact and expires != 0"        /* R_STAR__EXP */
141
+#define	EI_R_STAR_CONT	"* used in contact and no. of contacts > 1" /* R_STAR_CONT */
142
+#define	EI_R_OOO	"Out of order request"                      /* R_OOO */
143
+#define	EI_R_RETRANS	"Retransmission"                            /* R_RETRANS */
144
+
145
+
146
+str error_info[] = {
147
+	{EI_R_FINE,       sizeof(EI_R_FINE) - 1},
148
+	{EI_R_UL_DEL_R,   sizeof(EI_R_UL_DEL_R) - 1},
149
+	{EI_R_UL_GET_R,   sizeof(EI_R_UL_GET_R) - 1},
150
+	{EI_R_UL_NEW_R,   sizeof(EI_R_UL_NEW_R) - 1},
151
+	{EI_R_INV_CSEQ,   sizeof(EI_R_INV_CSEQ) - 1},
152
+	{EI_R_UL_INS_C,   sizeof(EI_R_UL_INS_C) - 1},
153
+	{EI_R_UL_INS_R,   sizeof(EI_R_UL_INS_R) - 1},
154
+	{EI_R_UL_DEL_C,   sizeof(EI_R_UL_DEL_C) - 1},
155
+	{EI_R_UL_UPD_C,   sizeof(EI_R_UL_UPD_C) - 1},
156
+	{EI_R_TO_USER,    sizeof(EI_R_TO_USER) - 1},
157
+	{EI_R_AOR_LEN,    sizeof(EI_R_AOR_LEN) - 1},
158
+	{EI_R_AOR_PARSE,  sizeof(EI_R_AOR_PARSE) - 1},
159
+	{EI_R_INV_EXP,    sizeof(EI_R_INV_EXP) - 1},
160
+	{EI_R_INV_Q,      sizeof(EI_R_INV_Q) - 1},
161
+	{EI_R_PARSE,      sizeof(EI_R_PARSE) - 1},
162
+	{EI_R_TO_MISS,    sizeof(EI_R_TO_MISS) - 1},
163
+	{EI_R_CID_MISS,   sizeof(EI_R_CID_MISS) - 1},
164
+	{EI_R_CS_MISS,    sizeof(EI_R_CS_MISS) - 1},
165
+	{EI_R_PARSE_EXP,  sizeof(EI_R_PARSE_EXP) - 1},
166
+	{EI_R_PARSE_CONT, sizeof(EI_R_PARSE_CONT) - 1},
167
+	{EI_R_STAR_EXP,   sizeof(EI_R_STAR_EXP) - 1},
168
+	{EI_R_STAR_CONT,  sizeof(EI_R_STAR_CONT) - 1},
169
+	{EI_R_OOO,        sizeof(EI_R_OOO) - 1},
170
+	{EI_R_RETRANS,    sizeof(EI_R_RETRANS) - 1}
171
+};
172
+
173
+int codes[] = {
174
+	200, /* R_FINE */
175
+     	500, /* R_UL_DEL_R */
176
+	500, /* R_UL_GET */
177
+	500, /* R_UL_NEW_R */
178
+	400, /* R_INV_CSEQ */
179
+	500, /* R_UL_INS_C */
180
+	500, /* R_UL_INS_R */
181
+	500, /* R_UL_DEL_C */
182
+	500, /* R_UL_UPD_C */
183
+	400, /* R_TO_USER */
184
+	500, /* R_AOR_LEN */
185
+	400, /* R_AOR_PARSE */
186
+	400, /* R_INV_EXP */
187
+	400, /* R_INV_Q */
188
+	400, /* R_PARSE */
189
+	400, /* R_TO_MISS */
190
+	400, /* R_CID_MISS */
191
+	400, /* R_CS_MISS */
192
+	400, /* R_PARSE_EXP */
193
+	400, /* R_PARSE_CONT */
194
+	400, /* R_STAR_EXP */
195
+	400, /* R_STAR_CONT */
196
+	200, /* R_OOO */
197
+	200  /* R_RETRANS */
198
+};
199
+
147 200
 
148 201
 
149 202
 /*
... ...
@@ -152,9 +199,9 @@ static inline void rerrno2msg(int* _c, char** _m)
152 152
 int send_reply(struct sip_msg* _m)
153 153
 {
154 154
 	int code;
155
-	char* msg;
155
+	char* msg = MSG_200; /* makes gcc shut up */
156 156
 
157
-	struct lump_rpl* p;
157
+	struct lump_rpl* p, *ei;
158 158
 
159 159
 	if (l > 0) {
160 160
 		p = build_lump_rpl(b, l);
... ...
@@ -162,8 +209,18 @@ int send_reply(struct sip_msg* _m)
162 162
 		l = 0;
163 163
 	}
164 164
 
165
-	rerrno2msg(&code, &msg);
165
+	code = codes[rerrno];
166
+	switch(code) {
167
+	case 200: msg = MSG_200; break;
168
+	case 400: msg = MSG_400; break;
169
+	case 500: msg = MSG_500; break;
170
+	}
166 171
 	
172
+	if (code != 200) {
173
+		ei = build_lump_rpl(error_info[rerrno].s, error_info[rerrno].len);
174
+		add_lump_rpl(_m, ei);
175
+	}
176
+
167 177
 	if (sl_reply(_m, (char*)code, msg) == -1) {
168 178
 		LOG(L_ERR, "send_reply(): Error while sending %d %s\n", code, msg);
169 179
 		return -1;
... ...
@@ -54,9 +54,11 @@ static inline int get_expires_hf(struct sip_msg* _m)
54 54
 	
55 55
 	if (_m->expires) {
56 56
 		p = (exp_body_t*)_m->expires->parsed;
57
-		if (p->val != 0) {
58
-			return p->val + act_time;
59
-		} else return 0;
57
+		if (p->valid) {
58
+			if (p->val != 0) {
59
+				return p->val + act_time;
60
+			} else return 0;
61
+		} else return act_time + default_expires;
60 62
 	} else {
61 63
 		return act_time + default_expires;
62 64
 	}