1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,478 +0,0 @@ |
1 |
-/* $Id$ |
|
2 |
- * |
|
3 |
- * Copyright (C) 2006-2007 VozTelecom Sistemas S.L |
|
4 |
- * |
|
5 |
- * This file is part of Kamailio, a free SIP server. |
|
6 |
- * |
|
7 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
8 |
- * it under the terms of the GNU General Public License as published by |
|
9 |
- * the Free Software Foundation; either version 2 of the License, or |
|
10 |
- * (at your option) any later version |
|
11 |
- * |
|
12 |
- * Kamailio is distributed in the hope that it will be useful, |
|
13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
- * GNU General Public License for more details. |
|
16 |
- * |
|
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
19 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
20 |
- */ |
|
21 |
- |
|
22 |
-/* |
|
23 |
- * ===================================================================================== |
|
24 |
- * |
|
25 |
- * Filename: main.c |
|
26 |
- * |
|
27 |
- * Description: functions to encode a message |
|
28 |
- * |
|
29 |
- * Version: 1.0 |
|
30 |
- * Created: 14/11/05 13:42:53 CET |
|
31 |
- * Revision: none |
|
32 |
- * Compiler: gcc |
|
33 |
- * |
|
34 |
- * Author: Elias Baixas (EB), elias@conillera.net |
|
35 |
- * Company: VozTele.com |
|
36 |
- * |
|
37 |
- * ===================================================================================== |
|
38 |
- */ |
|
39 |
- |
|
40 |
-#define _GNU_SOURCE |
|
41 |
-#include <stdio.h> |
|
42 |
-#include <sys/types.h> |
|
43 |
-#include <sys/stat.h> |
|
44 |
-#include <fcntl.h> |
|
45 |
-#include <unistd.h> |
|
46 |
-#include <stdlib.h> |
|
47 |
-#include <string.h> |
|
48 |
-#include <stddef.h> |
|
49 |
- |
|
50 |
-#include "../../parser/msg_parser.h" |
|
51 |
-#include "../../parser/parse_via.h" |
|
52 |
-#include "../../parser/parse_uri.h" |
|
53 |
-#include "../../parser/parse_from.h" |
|
54 |
-#include "../../mem/mem.h" |
|
55 |
-#include "../../dprint.h" |
|
56 |
-#include "encode_header.h" |
|
57 |
-#include "encode_uri.h" |
|
58 |
-#include "encode_msg.h" |
|
59 |
-#include "xaddress.h" |
|
60 |
- |
|
61 |
-unsigned int theSignal = 0xAA55AA55;/*which is: 10101010-01010101-10101010-01010101*/ |
|
62 |
- |
|
63 |
-char get_header_code(struct hdr_field *hf) |
|
64 |
-{ |
|
65 |
- switch(hf->type){ |
|
66 |
- case HDR_CALLID_T: |
|
67 |
- return 'i'; |
|
68 |
- case HDR_CONTACT_T: |
|
69 |
- return 'm'; |
|
70 |
- case HDR_CONTENTLENGTH_T: |
|
71 |
- return 'l'; |
|
72 |
- case HDR_CONTENTTYPE_T: |
|
73 |
- return 'c'; |
|
74 |
- case HDR_FROM_T: |
|
75 |
- return 'f'; |
|
76 |
- case HDR_SUBJECT_T: |
|
77 |
- return 's'; |
|
78 |
- case HDR_SUPPORTED_T: |
|
79 |
- return 'k'; |
|
80 |
- case HDR_TO_T: |
|
81 |
- return 't'; |
|
82 |
- case HDR_VIA_T: |
|
83 |
- return 'v'; |
|
84 |
- case HDR_ROUTE_T: |
|
85 |
- return 'r'; |
|
86 |
- case HDR_RECORDROUTE_T: |
|
87 |
- return 'R'; |
|
88 |
- case HDR_ALLOW_T: |
|
89 |
- return 'a'; |
|
90 |
- case HDR_ACCEPT_T: |
|
91 |
- return 'A'; |
|
92 |
- case HDR_CSEQ_T: |
|
93 |
- return 'S'; |
|
94 |
- case HDR_REFER_TO_T: |
|
95 |
- return 'o'; |
|
96 |
- case HDR_RPID_T: |
|
97 |
- return 'p'; |
|
98 |
- case HDR_EXPIRES_T: |
|
99 |
- return 'P'; |
|
100 |
- case HDR_AUTHORIZATION_T: |
|
101 |
- return 'H'; |
|
102 |
- case HDR_PROXYAUTH_T: |
|
103 |
- return 'z'; |
|
104 |
- default: |
|
105 |
- return 'x'; |
|
106 |
- } |
|
107 |
- return 'x'; |
|
108 |
-} |
|
109 |
- |
|
110 |
-/* This function extracts meta-info from the sip_msg structure and |
|
111 |
- * formats it so that it can be used to rapidly access the message structured |
|
112 |
- * parts. |
|
113 |
- * |
|
114 |
- * RETURNS: LENGTH of structure on success, <0 if failure |
|
115 |
- * if there was failure, you dont need to pkg_free the payload (it is done inside). |
|
116 |
- * if there was success, you __NEED_TO_PKG_FREE_THE_PAYLOAD__ from the calling function. |
|
117 |
- * |
|
118 |
- * The encoded meta-info is composed by 3 sections: |
|
119 |
- * |
|
120 |
- * MSG_META_INFO: |
|
121 |
- * 2: short int in network-byte-order, if <100, the msg is a REQUEST and the int |
|
122 |
- * is the code of the METHOD. if >100, it is a RESPONSE and the int is the code |
|
123 |
- * of the response. |
|
124 |
- * 2: short int in NBO: payload-start based pointer (index) to where the SIP MSG starts. |
|
125 |
- * 2: short int in NBO: the sip-message length |
|
126 |
- * 2: METHOD or CODE string SIP-START-based pointer and length |
|
127 |
- * 2: R-URI or REASON PHRASE string SIP-START-based pointer and length |
|
128 |
- * 2: VERSION string SIP-START-based pointer and length |
|
129 |
- * 2: short int in NBO: start of the content of the SIP message |
|
130 |
- * [1+N]: in case this is a request, the length of the encoded-uri and the encoded-uri |
|
131 |
- * 1: how many present headers have been found. |
|
132 |
- * |
|
133 |
- * MSG_HEADERS_INDEX: |
|
134 |
- * N*3: groups of 3 bytes, each one describing a header struct: the first byte |
|
135 |
- * is a letter that corresponds to a header type, the second and third bytes are a NBO |
|
136 |
- * inidex to where this struct begins within the HEADERS_META_INFO section. |
|
137 |
- * |
|
138 |
- * HEADERS_META_INFO: |
|
139 |
- * M: all the codified headers meta info structs one after another |
|
140 |
- * |
|
141 |
- * SIP_MSG: |
|
142 |
- * the SIP message as it has been received. |
|
143 |
- * |
|
144 |
- * The length of the structure, will be ((short*)payload)[1] + ((short*)payload)[2] |
|
145 |
- * |
|
146 |
- * TODO: msg->parsed_uri msg->parsed_orig_uri_ok, msg->first_line->u.request.uri |
|
147 |
- * buggy and little bit fuzzy |
|
148 |
- */ |
|
149 |
-int encode_msg(struct sip_msg *msg,char *payload,int len) |
|
150 |
-{ |
|
151 |
- int i,j,k,u,request; |
|
152 |
- unsigned short int h; |
|
153 |
- struct hdr_field* hf; |
|
154 |
- struct msg_start* ms; |
|
155 |
- struct sip_uri miuri; |
|
156 |
- char *myerror=NULL; |
|
157 |
- ptrdiff_t diff; |
|
158 |
- |
|
159 |
- if(len < MAX_ENCODED_MSG + MAX_MESSAGE_LEN) |
|
160 |
- return -1; |
|
161 |
- if(parse_headers(msg,HDR_EOH_F,0)<0){ |
|
162 |
- myerror="in parse_headers"; |
|
163 |
- goto error; |
|
164 |
- } |
|
165 |
- memset(payload,0,len); |
|
166 |
- ms=&msg->first_line; |
|
167 |
- if(ms->type == SIP_REQUEST) |
|
168 |
- request=1; |
|
169 |
- else if(ms->type == SIP_REPLY) |
|
170 |
- request=0; |
|
171 |
- else{ |
|
172 |
- myerror="message is neither request nor response"; |
|
173 |
- goto error; |
|
174 |
- } |
|
175 |
- if(request) { |
|
176 |
- for(h=0;h<32;j=(0x01<<h),h++) |
|
177 |
- if(j & ms->u.request.method_value) |
|
178 |
- break; |
|
179 |
- } else { |
|
180 |
- h=(unsigned short)(ms->u.reply.statuscode); |
|
181 |
- } |
|
182 |
- if(h==32){/*statuscode wont be 32...*/ |
|
183 |
- myerror="unknown message type\n"; |
|
184 |
- goto error; |
|
185 |
- } |
|
186 |
- h=htons(h); |
|
187 |
- /*first goes the message code type*/ |
|
188 |
- memcpy(payload,&h,2); |
|
189 |
- h=htons((unsigned short int)msg->len); |
|
190 |
- /*then goes the message start idx, but we'll put it later*/ |
|
191 |
- /*then goes the message length (we hope it to be less than 65535 bytes...)*/ |
|
192 |
- memcpy(&payload[MSG_LEN_IDX],&h,2); |
|
193 |
- /*then goes the content start index (starting from SIP MSG START)*/ |
|
194 |
- if(0>(diff=(get_body(msg)-(msg->buf)))){ |
|
195 |
- myerror="body starts before the message (uh ?)"; |
|
196 |
- goto error; |
|
197 |
- }else |
|
198 |
- h=htons((unsigned short int)diff); |
|
199 |
- memcpy(payload+CONTENT_IDX,&h,2); |
|
200 |
- payload[METHOD_CODE_IDX]=(unsigned char)(request? |
|
201 |
- (ms->u.request.method.s-msg->buf): |
|
202 |
- (ms->u.reply.status.s-msg->buf)); |
|
203 |
- payload[METHOD_CODE_IDX+1]=(unsigned char)(request? |
|
204 |
- (ms->u.request.method.len): |
|
205 |
- (ms->u.reply.status.len)); |
|
206 |
- payload[URI_REASON_IDX]=(unsigned char)(request? |
|
207 |
- (ms->u.request.uri.s-msg->buf): |
|
208 |
- (ms->u.reply.reason.s-msg->buf)); |
|
209 |
- payload[URI_REASON_IDX+1]=(unsigned char)(request? |
|
210 |
- (ms->u.request.uri.len): |
|
211 |
- (ms->u.reply.reason.len)); |
|
212 |
- payload[VERSION_IDX]=(unsigned char)(request? |
|
213 |
- (ms->u.request.version.s-msg->buf): |
|
214 |
- (ms->u.reply.version.s-msg->buf)); |
|
215 |
- if(request){ |
|
216 |
- if (parse_uri(ms->u.request.uri.s,ms->u.request.uri.len, &miuri)<0){ |
|
217 |
- LM_ERR("<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
218 |
- myerror="while parsing the R-URI"; |
|
219 |
- goto error; |
|
220 |
- } |
|
221 |
- if(0>(j=encode_uri2(msg->buf, |
|
222 |
- ms->u.request.method.s-msg->buf+ms->len, |
|
223 |
- ms->u.request.uri,&miuri, |
|
224 |
- (unsigned char*)&payload[REQUEST_URI_IDX+1]))) |
|
225 |
- { |
|
226 |
- myerror="ENCODE_MSG: ERROR while encoding the R-URI"; |
|
227 |
- goto error; |
|
228 |
- } |
|
229 |
- payload[REQUEST_URI_IDX]=(unsigned char)j; |
|
230 |
- k=REQUEST_URI_IDX+1+j; |
|
231 |
- }else |
|
232 |
- k=REQUEST_URI_IDX; |
|
233 |
- u=k; |
|
234 |
- k++; |
|
235 |
- for(i=0,hf=msg->headers;hf;hf=hf->next,i++); |
|
236 |
- i++;/*we do as if there was an extra header, that marks the end of |
|
237 |
- the previous header in the headers hashtable(read below)*/ |
|
238 |
- j=k+3*i; |
|
239 |
- for(i=0,hf=msg->headers;hf;hf=hf->next,k+=3){ |
|
240 |
- payload[k]=(unsigned char)(hf->type & 0xFF); |
|
241 |
- h=htons(j); |
|
242 |
- /*now goes a payload-based-ptr to where the header-code starts*/ |
|
243 |
- memcpy(&payload[k+1],&h,2); |
|
244 |
- /*TODO fix this... fixed with k-=3?*/ |
|
245 |
- if(0>(i=encode_header(msg,hf,(unsigned char*)(payload+j),MAX_ENCODED_MSG+MAX_MESSAGE_LEN-j))){ |
|
246 |
- LM_ERR("encoding header %.*s\n",hf->name.len,hf->name.s); |
|
247 |
- goto error; |
|
248 |
- k-=3; |
|
249 |
- continue; |
|
250 |
- } |
|
251 |
- j+=(unsigned short int)i; |
|
252 |
- } |
|
253 |
- /*now goes the number of headers that have been found, right after the meta-msg-section*/ |
|
254 |
- payload[u]=(unsigned char)((k-u-1)/3); |
|
255 |
- j=htons(j); |
|
256 |
- /*now copy the number of bytes that the headers-meta-section has occupied,right afther |
|
257 |
- * headers-meta-section(the array with ['v',[2:where],'r',[2:where],'R',[2:where],...] |
|
258 |
- * this is to know where the LAST header ends, since the length of each header-struct |
|
259 |
- * is calculated substracting the nextHeaderStart - presentHeaderStart |
|
260 |
- * the k+1 is because payload[k] is usually the letter*/ |
|
261 |
- memcpy(&payload[k+1],&j,2); |
|
262 |
- k+=3; |
|
263 |
- j=ntohs(j); |
|
264 |
- /*now we copy the headers-meta-section after the msg-headers-meta-section*/ |
|
265 |
- /*memcpy(&payload[k],payload2,j);*/ |
|
266 |
- /*j+=k;*/ |
|
267 |
- /*pkg_free(payload2);*/ |
|
268 |
- /*now we copy the actual message after the headers-meta-section*/ |
|
269 |
- memcpy(&payload[j],msg->buf,msg->len); |
|
270 |
- LM_DBG("msglen = %d,msg starts at %d\n",msg->len,j); |
|
271 |
- j=htons(j); |
|
272 |
- /*now we copy at the beginning, the index to where the actual message starts*/ |
|
273 |
- memcpy(&payload[MSG_START_IDX],&j,2); |
|
274 |
- return GET_PAY_SIZE( payload ); |
|
275 |
-error: |
|
276 |
- LM_ERR("%s\n",myerror); |
|
277 |
- return -1; |
|
278 |
-} |
|
279 |
- |
|
280 |
-int decode_msg(struct sip_msg *msg,char *code, unsigned int len) |
|
281 |
-{ |
|
282 |
- unsigned short int h; |
|
283 |
- char *myerror=NULL; |
|
284 |
- |
|
285 |
- memcpy(&h,&code[2],2); |
|
286 |
- h=ntohs(h); |
|
287 |
- /*TODO use shorcuts in meta-info header.*/ |
|
288 |
- |
|
289 |
- msg->buf=&code[h]; |
|
290 |
- memcpy(&h,&code[4],2); |
|
291 |
- h=ntohs(h); |
|
292 |
- msg->len=h; |
|
293 |
- if(parse_headers(msg,HDR_EOH_F,0)<0){ |
|
294 |
- myerror="in parse_headers"; |
|
295 |
- goto error; |
|
296 |
- } |
|
297 |
-error: |
|
298 |
- LM_ERR("(%s)\n",myerror); |
|
299 |
- return -1; |
|
300 |
-} |
|
301 |
- |
|
302 |
-int print_encoded_msg(FILE* fd,char *code,char *prefix) |
|
303 |
-{ |
|
304 |
- unsigned short int i,j,k,l,m,msglen; |
|
305 |
- char r,*msg; |
|
306 |
- unsigned char *payload; |
|
307 |
- |
|
308 |
- payload=(unsigned char*)code; |
|
309 |
- memcpy(&i,code,2); |
|
310 |
- memcpy(&j,&code[MSG_START_IDX],2); |
|
311 |
- memcpy(&msglen,&code[MSG_LEN_IDX],2); |
|
312 |
- i=ntohs(i); |
|
313 |
- j=ntohs(j); |
|
314 |
- msglen=ntohs(msglen); |
|
315 |
- for(k=0;k<j;k++) |
|
316 |
- fprintf(fd,"%s%d%s",k==0?"ENCODED-MSG:[":":",payload[k],k==j-1?"]\n":""); |
|
317 |
- msg=(char*)&payload[j]; |
|
318 |
- fprintf(fd,"MESSAGE:\n[%.*s]\n",msglen,msg); |
|
319 |
- r=(i<100)?1:0; |
|
320 |
- if(r){ |
|
321 |
- fprintf(fd,"%sREQUEST CODE=%d==%.*s,URI=%.*s,VERSION=%*.s\n",prefix,i, |
|
322 |
- payload[METHOD_CODE_IDX+1],&msg[payload[METHOD_CODE_IDX]], |
|
323 |
- payload[URI_REASON_IDX+1],&msg[payload[URI_REASON_IDX]], |
|
324 |
- payload[VERSION_IDX+1],&msg[payload[VERSION_IDX]]); |
|
325 |
- print_encoded_uri(fd,&payload[REQUEST_URI_IDX+1],payload[REQUEST_URI_IDX],msg,50,strcat(prefix," ")); |
|
326 |
- prefix[strlen(prefix)-2]=0; |
|
327 |
- i=REQUEST_URI_IDX+1+payload[REQUEST_URI_IDX]; |
|
328 |
- }else{ |
|
329 |
- fprintf(fd,"%sRESPONSE CODE=%d==%.*s,REASON=%.*s,VERSION=%.*s\n",prefix,i, |
|
330 |
- payload[METHOD_CODE_IDX+1],&msg[payload[METHOD_CODE_IDX]], |
|
331 |
- payload[URI_REASON_IDX+1],&msg[payload[URI_REASON_IDX]], |
|
332 |
- payload[VERSION_IDX+1],&msg[payload[VERSION_IDX]]); |
|
333 |
- i=REQUEST_URI_IDX; |
|
334 |
- } |
|
335 |
- k=((payload[CONTENT_IDX]<<8)|payload[CONTENT_IDX+1]); |
|
336 |
- j=msglen-k; |
|
337 |
- fprintf(fd,"%sMESSAGE CONTENT:%.*s\n",prefix,j,&msg[k]); |
|
338 |
- j=payload[i]; |
|
339 |
- fprintf(fd,"%sHEADERS PRESENT(%d):",prefix,j); |
|
340 |
- i++; |
|
341 |
- for(k=i;k<i+(j*3);k+=3) |
|
342 |
- fprintf(fd,"%c%d%c",k==i?'[':',',payload[k],k==(i+3*j-3)?']':' '); |
|
343 |
- fprintf(fd,"\n"); |
|
344 |
- for(k=i;k<i+(j*3);k+=3){ |
|
345 |
- memcpy(&l,&payload[k+1],2); |
|
346 |
- memcpy(&m,&payload[k+4],2); |
|
347 |
- l=ntohs(l); |
|
348 |
- m=ntohs(m); |
|
349 |
- print_encoded_header(fd,msg,msglen,&payload[l],m-l,payload[k],prefix); |
|
350 |
- } |
|
351 |
- return 1; |
|
352 |
-} |
|
353 |
- |
|
354 |
-/* |
|
355 |
- * Function to generate testing file, where we dump entire encoded-messages |
|
356 |
- * preceded by a network-byte-order short int that says how long is the message, |
|
357 |
- * or just encoded-headers. The last integer, is a flag set of which headers |
|
358 |
- * must be dumped |
|
359 |
- */ |
|
360 |
- |
|
361 |
-int dump_msg_test(char *code,FILE* fd,char header,char segregationLevel) |
|
362 |
-{ |
|
363 |
- unsigned short int i,j,l,m,msglen; |
|
364 |
- int k; |
|
365 |
- char r,*msg; |
|
366 |
- unsigned char *payload; |
|
367 |
- payload=(unsigned char*)code; |
|
368 |
- memcpy(&i,code,2);/*the CODE of the request/response*/ |
|
369 |
- memcpy(&j,&code[MSG_START_IDX],2);/*where the MSG starts*/ |
|
370 |
- memcpy(&msglen,&code[MSG_LEN_IDX],2);/*how long the MSG is*/ |
|
371 |
- i=ntohs(i); |
|
372 |
- j=ntohs(j); |
|
373 |
- msglen=ntohs(msglen); |
|
374 |
- if(header==0){ |
|
375 |
- fwrite(code,1,j+msglen,fd); |
|
376 |
- fwrite(&theSignal,1,4,fd); |
|
377 |
- return 0; |
|
378 |
- } |
|
379 |
- msg=(char*)&payload[j]; |
|
380 |
- r=(i<100)?1:0; |
|
381 |
- if(r){ |
|
382 |
- if(segregationLevel & ALSO_RURI){ |
|
383 |
- if(!(segregationLevel & JUNIT)){ |
|
384 |
- |
|
385 |
- k=htonl(payload[REQUEST_URI_IDX+1]+payload[REQUEST_URI_IDX+2]); |
|
386 |
- fwrite(&k,1,4,fd); |
|
387 |
- fwrite(msg,1,ntohl(k),fd); |
|
388 |
- k=htonl((long)payload[REQUEST_URI_IDX]); |
|
389 |
- fwrite(&k,1,4,fd); |
|
390 |
- fwrite(&payload[REQUEST_URI_IDX+1],1,payload[REQUEST_URI_IDX],fd); |
|
391 |
- fwrite(&theSignal,1,4,fd); |
|
392 |
- }else |
|
393 |
- print_uri_junit_tests(msg,payload[REQUEST_URI_IDX+1]+payload[REQUEST_URI_IDX+2] |
|
394 |
- ,&payload[REQUEST_URI_IDX+1],payload[REQUEST_URI_IDX],fd,1,""); |
|
395 |
- } |
|
396 |
- i=REQUEST_URI_IDX+1+payload[REQUEST_URI_IDX]; |
|
397 |
- }else{ |
|
398 |
- i=REQUEST_URI_IDX; |
|
399 |
- } |
|
400 |
- j=payload[i]; |
|
401 |
- i++; |
|
402 |
- for(k=i;k<i+(j*3);k+=3){ |
|
403 |
- memcpy(&l,&payload[k+1],2); |
|
404 |
- memcpy(&m,&payload[k+4],2); |
|
405 |
- l=ntohs(l); |
|
406 |
- m=ntohs(m); |
|
407 |
- if(header==(char)payload[k] || |
|
408 |
- (header=='U' && |
|
409 |
- (payload[k]=='f' || |
|
410 |
- payload[k]=='t' || |
|
411 |
- payload[k]=='m' || |
|
412 |
- payload[k]=='o' || |
|
413 |
- payload[k]=='p'))) |
|
414 |
- dump_headers_test(msg,msglen,&payload[i+(j*3)+l+3],m-l,payload[k],fd,segregationLevel); |
|
415 |
- } |
|
416 |
- return 1; |
|
417 |
-} |
|
418 |
- |
|
419 |
- |
|
420 |
-/* |
|
421 |
- * Function to generate testing file, where we dump entire encoded-messages |
|
422 |
- * preceded by a network-byte-order short int that says how long is the message, |
|
423 |
- * or just encoded-headers. The last integer, is a flag set of which headers |
|
424 |
- * must be dumped |
|
425 |
- */ |
|
426 |
- |
|
427 |
-int print_msg_junit_test(char *code,FILE* fd,char header,char segregationLevel) |
|
428 |
-{ |
|
429 |
- unsigned short int i,j,l,m,msglen; |
|
430 |
- int k; |
|
431 |
- char r,*msg; |
|
432 |
- unsigned char *payload; |
|
433 |
- payload=(unsigned char*)code; |
|
434 |
- memcpy(&i,code,2);/*the CODE of the request/response*/ |
|
435 |
- memcpy(&j,&code[MSG_START_IDX],2);/*where the MSG starts*/ |
|
436 |
- memcpy(&msglen,&code[MSG_LEN_IDX],2);/*how long the MSG is*/ |
|
437 |
- i=ntohs(i); |
|
438 |
- j=ntohs(j); |
|
439 |
- msglen=ntohs(msglen); |
|
440 |
- if(header==0){ |
|
441 |
- fwrite(code,1,j+msglen,fd); |
|
442 |
- fwrite(&theSignal,1,4,fd); |
|
443 |
- return 0; |
|
444 |
- } |
|
445 |
- msg=(char*)&payload[j]; |
|
446 |
- r=(i<100)?1:0; |
|
447 |
- if(r){ |
|
448 |
- if(segregationLevel & ALSO_RURI){ |
|
449 |
- k=htonl(50); |
|
450 |
- fwrite(&k,1,4,fd); |
|
451 |
- fwrite(msg,1,50,fd); |
|
452 |
- k=htonl((long)payload[REQUEST_URI_IDX]); |
|
453 |
- fwrite(&k,1,4,fd); |
|
454 |
- fwrite(&payload[REQUEST_URI_IDX+1],1,payload[REQUEST_URI_IDX],fd); |
|
455 |
- fwrite(&theSignal,1,4,fd); |
|
456 |
- } |
|
457 |
- i=REQUEST_URI_IDX+1+payload[REQUEST_URI_IDX]; |
|
458 |
- }else{ |
|
459 |
- i=REQUEST_URI_IDX; |
|
460 |
- } |
|
461 |
- j=payload[i]; |
|
462 |
- i++; |
|
463 |
- for(k=i;k<i+(j*3);k+=3){ |
|
464 |
- memcpy(&l,&payload[k+1],2); |
|
465 |
- memcpy(&m,&payload[k+4],2); |
|
466 |
- l=ntohs(l); |
|
467 |
- m=ntohs(m); |
|
468 |
- if(header==(char)payload[k] || |
|
469 |
- (header=='U' && |
|
470 |
- (payload[k]=='f' || |
|
471 |
- payload[k]=='t' || |
|
472 |
- payload[k]=='m' || |
|
473 |
- payload[k]=='o' || |
|
474 |
- payload[k]=='p'))) |
|
475 |
- dump_headers_test(msg,msglen,&payload[i+(j*3)+l+3],m-l,payload[k],fd,segregationLevel); |
|
476 |
- } |
|
477 |
- return 1; |
|
478 |
-} |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5192 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -299,7 +299,7 @@ error: |
299 | 299 |
return -1; |
300 | 300 |
} |
301 | 301 |
|
302 |
-int print_encoded_msg(int fd,char *code,char *prefix) |
|
302 |
+int print_encoded_msg(FILE* fd,char *code,char *prefix) |
|
303 | 303 |
{ |
304 | 304 |
unsigned short int i,j,k,l,m,msglen; |
305 | 305 |
char r,*msg; |
... | ... |
@@ -313,12 +313,12 @@ int print_encoded_msg(int fd,char *code,char *prefix) |
313 | 313 |
j=ntohs(j); |
314 | 314 |
msglen=ntohs(msglen); |
315 | 315 |
for(k=0;k<j;k++) |
316 |
- dprintf(fd,"%s%d%s",k==0?"ENCODED-MSG:[":":",payload[k],k==j-1?"]\n":""); |
|
316 |
+ fprintf(fd,"%s%d%s",k==0?"ENCODED-MSG:[":":",payload[k],k==j-1?"]\n":""); |
|
317 | 317 |
msg=(char*)&payload[j]; |
318 |
- dprintf(fd,"MESSAGE:\n[%.*s]\n",msglen,msg); |
|
318 |
+ fprintf(fd,"MESSAGE:\n[%.*s]\n",msglen,msg); |
|
319 | 319 |
r=(i<100)?1:0; |
320 | 320 |
if(r){ |
321 |
- dprintf(fd,"%sREQUEST CODE=%d==%.*s,URI=%.*s,VERSION=%*.s\n",prefix,i, |
|
321 |
+ fprintf(fd,"%sREQUEST CODE=%d==%.*s,URI=%.*s,VERSION=%*.s\n",prefix,i, |
|
322 | 322 |
payload[METHOD_CODE_IDX+1],&msg[payload[METHOD_CODE_IDX]], |
323 | 323 |
payload[URI_REASON_IDX+1],&msg[payload[URI_REASON_IDX]], |
324 | 324 |
payload[VERSION_IDX+1],&msg[payload[VERSION_IDX]]); |
... | ... |
@@ -326,7 +326,7 @@ int print_encoded_msg(int fd,char *code,char *prefix) |
326 | 326 |
prefix[strlen(prefix)-2]=0; |
327 | 327 |
i=REQUEST_URI_IDX+1+payload[REQUEST_URI_IDX]; |
328 | 328 |
}else{ |
329 |
- dprintf(fd,"%sRESPONSE CODE=%d==%.*s,REASON=%.*s,VERSION=%.*s\n",prefix,i, |
|
329 |
+ fprintf(fd,"%sRESPONSE CODE=%d==%.*s,REASON=%.*s,VERSION=%.*s\n",prefix,i, |
|
330 | 330 |
payload[METHOD_CODE_IDX+1],&msg[payload[METHOD_CODE_IDX]], |
331 | 331 |
payload[URI_REASON_IDX+1],&msg[payload[URI_REASON_IDX]], |
332 | 332 |
payload[VERSION_IDX+1],&msg[payload[VERSION_IDX]]); |
... | ... |
@@ -334,13 +334,13 @@ int print_encoded_msg(int fd,char *code,char *prefix) |
334 | 334 |
} |
335 | 335 |
k=((payload[CONTENT_IDX]<<8)|payload[CONTENT_IDX+1]); |
336 | 336 |
j=msglen-k; |
337 |
- dprintf(fd,"%sMESSAGE CONTENT:%.*s\n",prefix,j,&msg[k]); |
|
337 |
+ fprintf(fd,"%sMESSAGE CONTENT:%.*s\n",prefix,j,&msg[k]); |
|
338 | 338 |
j=payload[i]; |
339 |
- dprintf(fd,"%sHEADERS PRESENT(%d):",prefix,j); |
|
339 |
+ fprintf(fd,"%sHEADERS PRESENT(%d):",prefix,j); |
|
340 | 340 |
i++; |
341 | 341 |
for(k=i;k<i+(j*3);k+=3) |
342 |
- dprintf(fd,"%c%d%c",k==i?'[':',',payload[k],k==(i+3*j-3)?']':' '); |
|
343 |
- dprintf(fd,"\n"); |
|
342 |
+ fprintf(fd,"%c%d%c",k==i?'[':',',payload[k],k==(i+3*j-3)?']':' '); |
|
343 |
+ fprintf(fd,"\n"); |
|
344 | 344 |
for(k=i;k<i+(j*3);k+=3){ |
345 | 345 |
memcpy(&l,&payload[k+1],2); |
346 | 346 |
memcpy(&m,&payload[k+4],2); |
... | ... |
@@ -358,7 +358,7 @@ int print_encoded_msg(int fd,char *code,char *prefix) |
358 | 358 |
* must be dumped |
359 | 359 |
*/ |
360 | 360 |
|
361 |
-int dump_msg_test(char *code,int fd,char header,char segregationLevel) |
|
361 |
+int dump_msg_test(char *code,FILE* fd,char header,char segregationLevel) |
|
362 | 362 |
{ |
363 | 363 |
unsigned short int i,j,l,m,msglen; |
364 | 364 |
int k; |
... | ... |
@@ -372,8 +372,8 @@ int dump_msg_test(char *code,int fd,char header,char segregationLevel) |
372 | 372 |
j=ntohs(j); |
373 | 373 |
msglen=ntohs(msglen); |
374 | 374 |
if(header==0){ |
375 |
- write(fd,code,j+msglen); |
|
376 |
- write(fd,&theSignal,4); |
|
375 |
+ fwrite(code,1,j+msglen,fd); |
|
376 |
+ fwrite(&theSignal,1,4,fd); |
|
377 | 377 |
return 0; |
378 | 378 |
} |
379 | 379 |
msg=(char*)&payload[j]; |
... | ... |
@@ -383,12 +383,12 @@ int dump_msg_test(char *code,int fd,char header,char segregationLevel) |
383 | 383 |
if(!(segregationLevel & JUNIT)){ |
384 | 384 |
|
385 | 385 |
k=htonl(payload[REQUEST_URI_IDX+1]+payload[REQUEST_URI_IDX+2]); |
386 |
- write(fd,&k,4); |
|
387 |
- write(fd,msg,ntohl(k)); |
|
386 |
+ fwrite(&k,1,4,fd); |
|
387 |
+ fwrite(msg,1,ntohl(k),fd); |
|
388 | 388 |
k=htonl((long)payload[REQUEST_URI_IDX]); |
389 |
- write(fd,&k,4); |
|
390 |
- write(fd,&payload[REQUEST_URI_IDX+1],payload[REQUEST_URI_IDX]); |
|
391 |
- write(fd,&theSignal,4); |
|
389 |
+ fwrite(&k,1,4,fd); |
|
390 |
+ fwrite(&payload[REQUEST_URI_IDX+1],1,payload[REQUEST_URI_IDX],fd); |
|
391 |
+ fwrite(&theSignal,1,4,fd); |
|
392 | 392 |
}else |
393 | 393 |
print_uri_junit_tests(msg,payload[REQUEST_URI_IDX+1]+payload[REQUEST_URI_IDX+2] |
394 | 394 |
,&payload[REQUEST_URI_IDX+1],payload[REQUEST_URI_IDX],fd,1,""); |
... | ... |
@@ -424,7 +424,7 @@ int dump_msg_test(char *code,int fd,char header,char segregationLevel) |
424 | 424 |
* must be dumped |
425 | 425 |
*/ |
426 | 426 |
|
427 |
-int print_msg_junit_test(char *code,int fd,char header,char segregationLevel) |
|
427 |
+int print_msg_junit_test(char *code,FILE* fd,char header,char segregationLevel) |
|
428 | 428 |
{ |
429 | 429 |
unsigned short int i,j,l,m,msglen; |
430 | 430 |
int k; |
... | ... |
@@ -438,8 +438,8 @@ int print_msg_junit_test(char *code,int fd,char header,char segregationLevel) |
438 | 438 |
j=ntohs(j); |
439 | 439 |
msglen=ntohs(msglen); |
440 | 440 |
if(header==0){ |
441 |
- write(fd,code,j+msglen); |
|
442 |
- write(fd,&theSignal,4); |
|
441 |
+ fwrite(code,1,j+msglen,fd); |
|
442 |
+ fwrite(&theSignal,1,4,fd); |
|
443 | 443 |
return 0; |
444 | 444 |
} |
445 | 445 |
msg=(char*)&payload[j]; |
... | ... |
@@ -447,12 +447,12 @@ int print_msg_junit_test(char *code,int fd,char header,char segregationLevel) |
447 | 447 |
if(r){ |
448 | 448 |
if(segregationLevel & ALSO_RURI){ |
449 | 449 |
k=htonl(50); |
450 |
- write(fd,&k,4); |
|
451 |
- write(fd,msg,50); |
|
450 |
+ fwrite(&k,1,4,fd); |
|
451 |
+ fwrite(msg,1,50,fd); |
|
452 | 452 |
k=htonl((long)payload[REQUEST_URI_IDX]); |
453 |
- write(fd,&k,4); |
|
454 |
- write(fd,&payload[REQUEST_URI_IDX+1],payload[REQUEST_URI_IDX]); |
|
455 |
- write(fd,&theSignal,4); |
|
453 |
+ fwrite(&k,1,4,fd); |
|
454 |
+ fwrite(&payload[REQUEST_URI_IDX+1],1,payload[REQUEST_URI_IDX],fd); |
|
455 |
+ fwrite(&theSignal,1,4,fd); |
|
456 | 456 |
} |
457 | 457 |
i=REQUEST_URI_IDX+1+payload[REQUEST_URI_IDX]; |
458 | 458 |
}else{ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -2,14 +2,14 @@ |
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2006-2007 VozTelecom Sistemas S.L |
4 | 4 |
* |
5 |
- * This file is part of openser, a free SIP server. |
|
5 |
+ * This file is part of Kamailio, a free SIP server. |
|
6 | 6 |
* |
7 |
- * openser is free software; you can redistribute it and/or modify |
|
7 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
8 | 8 |
* it under the terms of the GNU General Public License as published by |
9 | 9 |
* the Free Software Foundation; either version 2 of the License, or |
10 | 10 |
* (at your option) any later version |
11 | 11 |
* |
12 |
- * openser is distributed in the hope that it will be useful, |
|
12 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
13 | 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3318 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -164,21 +164,21 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
164 | 164 |
} |
165 | 165 |
memset(payload,0,len); |
166 | 166 |
ms=&msg->first_line; |
167 |
- if(ms->type == SIP_REQUEST) |
|
168 |
- request=1; |
|
169 |
- else |
|
170 |
- if(ms->type == SIP_REPLY) |
|
171 |
- request=0; |
|
172 |
- else{ |
|
173 |
- myerror="message is neither request nor response"; |
|
174 |
- goto error; |
|
175 |
- } |
|
176 |
- if(request) |
|
177 |
- for(h=0;h<32;j=(0x01<<h),h++) |
|
178 |
- if(j & ms->u.request.method_value) |
|
179 |
- break; |
|
180 |
- else |
|
181 |
- h=(unsigned short)(ms->u.reply.statuscode); |
|
167 |
+ if(ms->type == SIP_REQUEST) |
|
168 |
+ request=1; |
|
169 |
+ else if(ms->type == SIP_REPLY) |
|
170 |
+ request=0; |
|
171 |
+ else{ |
|
172 |
+ myerror="message is neither request nor response"; |
|
173 |
+ goto error; |
|
174 |
+ } |
|
175 |
+ if(request) { |
|
176 |
+ for(h=0;h<32;j=(0x01<<h),h++) |
|
177 |
+ if(j & ms->u.request.method_value) |
|
178 |
+ break; |
|
179 |
+ } else { |
|
180 |
+ h=(unsigned short)(ms->u.reply.statuscode); |
|
181 |
+ } |
|
182 | 182 |
if(h==32){/*statuscode wont be 32...*/ |
183 | 183 |
myerror="unknown message type\n"; |
184 | 184 |
goto error; |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2943 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -214,7 +214,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
214 | 214 |
(ms->u.reply.version.s-msg->buf)); |
215 | 215 |
if(request){ |
216 | 216 |
if (parse_uri(ms->u.request.uri.s,ms->u.request.uri.len, &miuri)<0){ |
217 |
- LOG(L_ERR, "<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
217 |
+ LM_ERR("<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
218 | 218 |
myerror="while parsing the R-URI"; |
219 | 219 |
goto error; |
220 | 220 |
} |
... | ... |
@@ -243,7 +243,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
243 | 243 |
memcpy(&payload[k+1],&h,2); |
244 | 244 |
/*TODO fix this... fixed with k-=3?*/ |
245 | 245 |
if(0>(i=encode_header(msg,hf,(unsigned char*)(payload+j),MAX_ENCODED_MSG+MAX_MESSAGE_LEN-j))){ |
246 |
- LOG(L_ERR,"encoding header %.*s\n",hf->name.len,hf->name.s); |
|
246 |
+ LM_ERR("encoding header %.*s\n",hf->name.len,hf->name.s); |
|
247 | 247 |
goto error; |
248 | 248 |
k-=3; |
249 | 249 |
continue; |
... | ... |
@@ -267,13 +267,13 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
267 | 267 |
/*pkg_free(payload2);*/ |
268 | 268 |
/*now we copy the actual message after the headers-meta-section*/ |
269 | 269 |
memcpy(&payload[j],msg->buf,msg->len); |
270 |
- LOG(L_DBG,"msglen = %d,msg starts at %d\n",msg->len,j); |
|
270 |
+ LM_DBG("msglen = %d,msg starts at %d\n",msg->len,j); |
|
271 | 271 |
j=htons(j); |
272 | 272 |
/*now we copy at the beginning, the index to where the actual message starts*/ |
273 | 273 |
memcpy(&payload[MSG_START_IDX],&j,2); |
274 | 274 |
return GET_PAY_SIZE( payload ); |
275 | 275 |
error: |
276 |
- LOG(L_ERR,"%s\n",myerror); |
|
276 |
+ LM_ERR("%s\n",myerror); |
|
277 | 277 |
return -1; |
278 | 278 |
} |
279 | 279 |
|
... | ... |
@@ -295,7 +295,7 @@ int decode_msg(struct sip_msg *msg,char *code, unsigned int len) |
295 | 295 |
goto error; |
296 | 296 |
} |
297 | 297 |
error: |
298 |
- LOG(L_ERR,"(%s)\n",myerror); |
|
298 |
+ LM_ERR("(%s)\n",myerror); |
|
299 | 299 |
return -1; |
300 | 300 |
} |
301 | 301 |
|
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2188 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -177,7 +177,6 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
177 | 177 |
for(h=0;h<32;j=(0x01<<h),h++) |
178 | 178 |
if(j & ms->u.request.method_value) |
179 | 179 |
break; |
180 |
- else; |
|
181 | 180 |
else |
182 | 181 |
h=(unsigned short)(ms->u.reply.statuscode); |
183 | 182 |
if(h==32){/*statuscode wont be 32...*/ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1819 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -1,4 +1,24 @@ |
1 |
-/* $Id$ */ |
|
1 |
+/* $Id$ |
|
2 |
+ * |
|
3 |
+ * Copyright (C) 2006-2007 VozTelecom Sistemas S.L |
|
4 |
+ * |
|
5 |
+ * This file is part of openser, a free SIP server. |
|
6 |
+ * |
|
7 |
+ * openser is free software; you can redistribute it and/or modify |
|
8 |
+ * it under the terms of the GNU General Public License as published by |
|
9 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
10 |
+ * (at your option) any later version |
|
11 |
+ * |
|
12 |
+ * openser is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
+ * GNU General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
20 |
+ */ |
|
21 |
+ |
|
2 | 22 |
/* |
3 | 23 |
* ===================================================================================== |
4 | 24 |
* |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1767 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -195,7 +195,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
195 | 195 |
(ms->u.reply.version.s-msg->buf)); |
196 | 196 |
if(request){ |
197 | 197 |
if (parse_uri(ms->u.request.uri.s,ms->u.request.uri.len, &miuri)<0){ |
198 |
- SLOG(L_ERR, "<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
198 |
+ LOG(L_ERR, "<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
199 | 199 |
myerror="while parsing the R-URI"; |
200 | 200 |
goto error; |
201 | 201 |
} |
... | ... |
@@ -224,7 +224,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
224 | 224 |
memcpy(&payload[k+1],&h,2); |
225 | 225 |
/*TODO fix this... fixed with k-=3?*/ |
226 | 226 |
if(0>(i=encode_header(msg,hf,(unsigned char*)(payload+j),MAX_ENCODED_MSG+MAX_MESSAGE_LEN-j))){ |
227 |
- SLOG(L_ERR,"encoding header %.*s\n",hf->name.len,hf->name.s); |
|
227 |
+ LOG(L_ERR,"encoding header %.*s\n",hf->name.len,hf->name.s); |
|
228 | 228 |
goto error; |
229 | 229 |
k-=3; |
230 | 230 |
continue; |
... | ... |
@@ -248,13 +248,13 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
248 | 248 |
/*pkg_free(payload2);*/ |
249 | 249 |
/*now we copy the actual message after the headers-meta-section*/ |
250 | 250 |
memcpy(&payload[j],msg->buf,msg->len); |
251 |
- SLOG(L_DBG,"msglen = %d,msg starts at %d\n",msg->len,j); |
|
251 |
+ LOG(L_DBG,"msglen = %d,msg starts at %d\n",msg->len,j); |
|
252 | 252 |
j=htons(j); |
253 | 253 |
/*now we copy at the beginning, the index to where the actual message starts*/ |
254 | 254 |
memcpy(&payload[MSG_START_IDX],&j,2); |
255 | 255 |
return GET_PAY_SIZE( payload ); |
256 | 256 |
error: |
257 |
- SLOG(L_ERR,"%s\n",myerror); |
|
257 |
+ LOG(L_ERR,"%s\n",myerror); |
|
258 | 258 |
return -1; |
259 | 259 |
} |
260 | 260 |
|
... | ... |
@@ -276,7 +276,7 @@ int decode_msg(struct sip_msg *msg,char *code, unsigned int len) |
276 | 276 |
goto error; |
277 | 277 |
} |
278 | 278 |
error: |
279 |
- SLOG(L_ERR,"(%s)\n",myerror); |
|
279 |
+ LOG(L_ERR,"(%s)\n",myerror); |
|
280 | 280 |
return -1; |
281 | 281 |
} |
282 | 282 |
|
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1725 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -133,7 +133,6 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
133 | 133 |
struct hdr_field* hf; |
134 | 134 |
struct msg_start* ms; |
135 | 135 |
struct sip_uri miuri; |
136 |
- unsigned char index[3*MAX_HEADERS]; |
|
137 | 136 |
char *myerror=NULL; |
138 | 137 |
ptrdiff_t diff; |
139 | 138 |
|
... | ... |
@@ -144,7 +143,6 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
144 | 143 |
goto error; |
145 | 144 |
} |
146 | 145 |
memset(payload,0,len); |
147 |
- memset(index,0,sizeof(index)); |
|
148 | 146 |
ms=&msg->first_line; |
149 | 147 |
if(ms->type == SIP_REQUEST) |
150 | 148 |
request=1; |
... | ... |
@@ -163,7 +161,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
163 | 161 |
else |
164 | 162 |
h=(unsigned short)(ms->u.reply.statuscode); |
165 | 163 |
if(h==32){/*statuscode wont be 32...*/ |
166 |
- myerror="ERROR:encode_msg: unknown message type\n"; |
|
164 |
+ myerror="unknown message type\n"; |
|
167 | 165 |
goto error; |
168 | 166 |
} |
169 | 167 |
h=htons(h); |
... | ... |
@@ -175,7 +173,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
175 | 173 |
memcpy(&payload[MSG_LEN_IDX],&h,2); |
176 | 174 |
/*then goes the content start index (starting from SIP MSG START)*/ |
177 | 175 |
if(0>(diff=(get_body(msg)-(msg->buf)))){ |
178 |
- myerror="ERROR: body starts before the message (uh ?)"; |
|
176 |
+ myerror="body starts before the message (uh ?)"; |
|
179 | 177 |
goto error; |
180 | 178 |
}else |
181 | 179 |
h=htons((unsigned short int)diff); |
... | ... |
@@ -197,7 +195,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
197 | 195 |
(ms->u.reply.version.s-msg->buf)); |
198 | 196 |
if(request){ |
199 | 197 |
if (parse_uri(ms->u.request.uri.s,ms->u.request.uri.len, &miuri)<0){ |
200 |
- LOG(L_ERR, "ERROR:encode_msg:<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
198 |
+ SLOG(L_ERR, "<%.*s>\n",ms->u.request.uri.len,ms->u.request.uri.s); |
|
201 | 199 |
myerror="while parsing the R-URI"; |
202 | 200 |
goto error; |
203 | 201 |
} |
... | ... |
@@ -225,8 +223,8 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
225 | 223 |
/*now goes a payload-based-ptr to where the header-code starts*/ |
226 | 224 |
memcpy(&payload[k+1],&h,2); |
227 | 225 |
/*TODO fix this... fixed with k-=3?*/ |
228 |
- if((i=encode_header(msg,hf,(unsigned char*)(payload+j),MAX_ENCODED_MSG+MAX_MESSAGE_LEN-j))<0){ |
|
229 |
- LOG(L_ERR,"ERROR: encode_msg: encoding header %.*s\n",hf->name.len,hf->name.s); |
|
226 |
+ if(0>(i=encode_header(msg,hf,(unsigned char*)(payload+j),MAX_ENCODED_MSG+MAX_MESSAGE_LEN-j))){ |
|
227 |
+ SLOG(L_ERR,"encoding header %.*s\n",hf->name.len,hf->name.s); |
|
230 | 228 |
goto error; |
231 | 229 |
k-=3; |
232 | 230 |
continue; |
... | ... |
@@ -250,13 +248,13 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
250 | 248 |
/*pkg_free(payload2);*/ |
251 | 249 |
/*now we copy the actual message after the headers-meta-section*/ |
252 | 250 |
memcpy(&payload[j],msg->buf,msg->len); |
253 |
- LOG(L_DBG,"msglen = %d,msg starts at %d\n",msg->len,j); |
|
251 |
+ SLOG(L_DBG,"msglen = %d,msg starts at %d\n",msg->len,j); |
|
254 | 252 |
j=htons(j); |
255 | 253 |
/*now we copy at the beginning, the index to where the actual message starts*/ |
256 | 254 |
memcpy(&payload[MSG_START_IDX],&j,2); |
257 | 255 |
return GET_PAY_SIZE( payload ); |
258 | 256 |
error: |
259 |
- LOG(L_ERR,"ERROR: encode_msg: %s\n",myerror); |
|
257 |
+ SLOG(L_ERR,"%s\n",myerror); |
|
260 | 258 |
return -1; |
261 | 259 |
} |
262 | 260 |
|
... | ... |
@@ -278,7 +276,7 @@ int decode_msg(struct sip_msg *msg,char *code, unsigned int len) |
278 | 276 |
goto error; |
279 | 277 |
} |
280 | 278 |
error: |
281 |
- LOG(L_ERR,"ERROR:decode_msg:(%s)\n",myerror); |
|
279 |
+ SLOG(L_ERR,"(%s)\n",myerror); |
|
282 | 280 |
return -1; |
283 | 281 |
} |
284 | 282 |
|
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1492 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -25,6 +25,7 @@ |
25 | 25 |
#include <unistd.h> |
26 | 26 |
#include <stdlib.h> |
27 | 27 |
#include <string.h> |
28 |
+#include <stddef.h> |
|
28 | 29 |
|
29 | 30 |
#include "../../parser/msg_parser.h" |
30 | 31 |
#include "../../parser/parse_via.h" |
... | ... |
@@ -127,13 +128,14 @@ char get_header_code(struct hdr_field *hf) |
127 | 128 |
*/ |
128 | 129 |
int encode_msg(struct sip_msg *msg,char *payload,int len) |
129 | 130 |
{ |
130 |
- int i,k,u; |
|
131 |
+ int i,j,k,u,request; |
|
131 | 132 |
unsigned short int h; |
132 |
- short int j; |
|
133 | 133 |
struct hdr_field* hf; |
134 | 134 |
struct msg_start* ms; |
135 |
+ struct sip_uri miuri; |
|
135 | 136 |
unsigned char index[3*MAX_HEADERS]; |
136 |
- char request,*myerror=NULL; |
|
137 |
+ char *myerror=NULL; |
|
138 |
+ ptrdiff_t diff; |
|
137 | 139 |
|
138 | 140 |
if(len < MAX_ENCODED_MSG + MAX_MESSAGE_LEN) |
139 | 141 |
return -1; |
... | ... |
@@ -142,7 +144,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
142 | 144 |
goto error; |
143 | 145 |
} |
144 | 146 |
memset(payload,0,len); |
145 |
- memset(index,0,3*MAX_HEADERS); |
|
147 |
+ memset(index,0,sizeof(index)); |
|
146 | 148 |
ms=&msg->first_line; |
147 | 149 |
if(ms->type == SIP_REQUEST) |
148 | 150 |
request=1; |
... | ... |
@@ -160,7 +162,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len) |
160 | 162 |
else; |
161 | 163 |
else |
162 |