Browse code

Added code files for SEAS module

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1448 689a6050-402a-0410-94f2-e92a70836424

Elias Baixas authored on 22/12/2006 17:07:44
Showing 49 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+# $Id$
2
+#
3
+# example module makefile
4
+#
5
+# 
6
+# WARNING: do not run this directly, it should be run by the master Makefile
7
+
8
+include ../../Makefile.defs
9
+auto_gen=
10
+NAME=seas.so
11
+LIBS=
12
+
13
+include ../../Makefile.modules
0 14
new file mode 100644
... ...
@@ -0,0 +1,54 @@
1
+
2
+Install
3
+-------
4
+
5
+make
6
+make modules=modules/tm modules
7
+make modules=modules/seas modules
8
+
9
+Run
10
+---
11
+
12
+./openser -w .
13
+
14
+Configuration
15
+-------------
16
+
17
+The Ip and Port where OpenSER is listening MUST be the same as the "addresses"
18
+parameter in <Connector> tag in server.xml for the JAVA program.
19
+The listen_sockets IP and Port parameter must be the same as present in
20
+SER_ADDRESS and SER_PORT properties in the server.xml.
21
+
22
+This is some configuration for the openser.cfg file:
23
+
24
+>>>>>>>>>>>>>>>>>>>>>>>>>>
25
+reply_to_via=1
26
+listen = tcp:127.0.0.1:5060
27
+listen = udp:127.0.0.1:5060
28
+
29
+loadmodule "modules/tm/tm.so"
30
+loadmodule "modules/seas/seas.so"
31
+
32
+modparam("seas", "listen_sockets","192.168.1.207:5080")
33
+modparam("seas", "stats_socket","192.168.1.207:5088")
34
+>>>>>>>>>>>>>>>>>>>>>>>>>>
35
+
36
+and this is the corresponding server.xml piece of configuration...
37
+
38
+>>>>>>>>>>>>>>>>>>>>>>>>>>
39
+	 <Connector className="com.voztele.sipservlet.connector.SipConnector"
40
+	 minProcessors="5" maxProcessors="75"
41
+	 enableLookups="true" acceptCount="10" debug="10"
42
+	 addresses="127.0.0.1:5060" pathName="com.voztele" >
43
+		<ExtraProperties>
44
+			<Property key="com.voztele.javax.sip.SER_ADDRESS" value="192.168.1.207" />
45
+			<Property key="com.voztele.javax.sip.SER_PORT" value="5080" />
46
+			<Property key="com.voztele.STATISTICS" value="true" />
47
+			<Property key="javax.sip.STACK_NAME" value="shootist" />
48
+			<Property key="javax.sip.THREAD_POOL_SIZE" value="10" />
49
+			<Property key="com.voztele.javax.sip.THREAD_POOL_SIZE" value="10" />
50
+			<Property key="com.voztele.javax.sip.REENTRANT_LISTENER" value="true" />
51
+			<Property key="javax.sip.AUTOMATIC_DIALOG_SUPPORT" value="false" /> 
52
+		</ExtraProperties>
53
+	</Connector>
54
+>>>>>>>>>>>>>>>>>>>>>>>>>>
0 55
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  as.c
6
+ * 
7
+ *     Description:  this file contains code to setup the things needed 
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  29/12/05 22:55:07 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+
0 21
new file mode 100644
... ...
@@ -0,0 +1,163 @@
1
+/* $Id$ */
2
+
3
+#include <string.h>
4
+
5
+#include "cluster.h"
6
+#include "seas.h"
7
+#include "../../dprint.h"
8
+#include "../../mem/mem.h"
9
+
10
+char *cluster_cfg;
11
+
12
+#define eat_spaces(_p) \
13
+	while( *(_p)==' ' || *(_p)=='\t' ){\
14
+	(_p)++;}
15
+
16
+
17
+/**
18
+ * Parses the PING configuration string. Its format is 
19
+ * "ping_period:pings_lost:ping_timeout"
20
+ * ping_period : time between pings
21
+ * pings_lost: number of lost pings before failure
22
+ * ping_timeout: time to consider a ping failed
23
+ *
24
+ * returns 
25
+ * 0 if no clusters present
26
+ * -1 if config is malformed (unable to parse);
27
+ *  1 if config is successfully set
28
+ */
29
+int parse_cluster_cfg()
30
+{
31
+   char *p,*start;
32
+   int n,k;
33
+   struct as_entry **entry,*tmp,*tmp2;
34
+
35
+   if((p=cluster_cfg)==0 || *cluster_cfg==0){
36
+      return 0;
37
+   }
38
+   entry=&as_list;
39
+
40
+   while (*p)
41
+   {
42
+      eat_spaces(p);
43
+      /*get cluster name*/
44
+      start = p;
45
+      while (*p!=' ' && *p!='\t' && *p!='[' && *p!=0)
46
+	 p++;
47
+      if ( p==start || *p==0 ){
48
+	 LOG(L_ERR,"ERROR: cluster names must only contain alphanumeric chars\n");
49
+	 goto error;
50
+      }
51
+      if (!((*entry)=(struct as_entry*)shm_malloc(sizeof(struct as_entry)))) {
52
+	 LOG(L_ERR,"Out of shm mem for as_entry\n");
53
+	 goto error;
54
+      }
55
+      memset(*entry,0,sizeof(struct as_entry));
56
+      if (!((*entry)->name.s=shm_malloc(p-start))) {
57
+	 LOG(L_ERR,"Out of shm malloc for cluster name\n");
58
+	 goto error;
59
+      }
60
+      memcpy((*entry)->name.s, start, p-start);
61
+      (*entry)->name.len=p-start;
62
+      (*entry)->connected=0;
63
+      (*entry)->type=CLUSTER_TYPE;
64
+      (*entry)->u.cs.name=(*entry)->name;
65
+      /*get as names*/
66
+      eat_spaces(p);
67
+      if (*p!='['){
68
+	 LOG(L_ERR,"Malformed cluster cfg string %s\n",cluster_cfg);
69
+	 goto error;
70
+      }
71
+      p++;
72
+      n=0;
73
+      while (*p!=']')
74
+      {
75
+	 eat_spaces(p);
76
+	 start = p;
77
+	 while(*p!=' ' && *p!='\t' && *p!=']' && *p!=',' && *p!=0)
78
+	    p++;
79
+	 if ( p==start || *p==0 )
80
+	    goto error;
81
+	 if (!((*entry)->u.cs.as_names[n].s=shm_malloc(p-start))) {
82
+	    LOG(L_ERR,"Out of shm_mem for AS name in cluster\n");
83
+	    goto error;
84
+	 }
85
+	 (*entry)->u.cs.as_names[n].len=p-start;
86
+	 memcpy((*entry)->u.cs.as_names[n].s,start,p-start);
87
+	 n++;
88
+	 if(n>=MAX_AS_PER_CLUSTER){
89
+	    LOG(L_ERR,"ERROR: too many AS per cluster\n");
90
+	    goto error;
91
+	 }
92
+	 eat_spaces(p);
93
+	 if (*p==',') {
94
+	    p++;
95
+	    eat_spaces(p);
96
+	 }
97
+      }
98
+      p++;
99
+      (*entry)->u.cs.num=n;
100
+      /* end of element */
101
+      eat_spaces(p);
102
+      if (*p==',')
103
+	 p++;
104
+      eat_spaces(p);
105
+      entry=&((*entry)->next);
106
+   }
107
+   for (tmp=as_list;tmp->next;tmp=tmp->next){
108
+      LOG(L_DBG,"%.*s\n",tmp->name.len,tmp->name.s);
109
+   }
110
+   LOG(L_DBG,"%.*s\n",tmp->name.len,tmp->name.s);
111
+   entry=&(tmp->next);
112
+   for(tmp=as_list;tmp;tmp=tmp->next){
113
+      if (tmp->type!=CLUSTER_TYPE) 
114
+	 continue;
115
+      LOG(L_DBG,"cluster:[%.*s]\n",tmp->name.len,tmp->name.s);
116
+      for(k=0;k<tmp->u.cs.num;k++){
117
+	 LOG(L_DBG,"\tAS:[%.*s]\n",tmp->u.cs.as_names[k].len,tmp->u.cs.as_names[k].s);
118
+	 for (tmp2=as_list;tmp2;tmp2=tmp2->next) {
119
+	    if (tmp2->type== AS_TYPE && tmp->u.cs.as_names[k].len == tmp2->name.len && 
120
+		  !memcmp(tmp->u.cs.as_names[k].s,tmp2->name.s,tmp2->name.len)) {
121
+	       tmp->u.cs.servers[k]=&tmp2->u.as;
122
+	       break;
123
+	    }
124
+	 }
125
+	 if(tmp2)
126
+	    continue;
127
+	 if (!((*entry)=shm_malloc(sizeof(struct as_entry)))) {
128
+	    LOG(L_ERR,"ERROR:Out of shm mem \n");
129
+	    goto error;
130
+	 }
131
+	 memset(*entry,0,sizeof(struct as_entry));
132
+	 (*entry)->type=AS_TYPE;
133
+	 if (!((*entry)->name.s=shm_malloc(tmp->u.cs.as_names[k].len))) {
134
+	    LOG(L_ERR,"ERROR:out of shm mem\n");
135
+	    goto error;
136
+	 }
137
+	 memcpy((*entry)->name.s,tmp->u.cs.as_names[k].s,tmp->u.cs.as_names[k].len);
138
+	 (*entry)->name.len=tmp->u.cs.as_names[k].len;
139
+	 (*entry)->u.as.name=(*entry)->name;
140
+	 tmp->u.cs.servers[k]=&(*entry)->u.as;
141
+	 entry=&((*entry)->next);
142
+      }
143
+   }
144
+   for(tmp=as_list;tmp;tmp=tmp->next){
145
+      LOG(L_DBG,"%.*s %s",tmp->name.len,tmp->name.s,tmp->next?"":"\n");
146
+   }
147
+   return 1;
148
+error:
149
+   tmp=as_list;
150
+   while(tmp){
151
+      for(k=0;k<tmp->u.cs.num;k++){
152
+	 if(tmp->u.cs.as_names[k].s)
153
+	    shm_free(tmp->u.cs.as_names[k].s);
154
+      }
155
+      if(tmp->name.s)
156
+	 shm_free(tmp->name.s);
157
+      tmp2=tmp;
158
+      tmp=tmp->next;
159
+      shm_free(tmp2);
160
+   }
161
+   as_list=(struct as_entry *)0;
162
+   return -1;
163
+}
0 164
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+/* $Id$ */
2
+
3
+#ifndef cluster_h
4
+#define cluster_h
5
+#include "../../str.h"
6
+#include "seas.h"
7
+
8
+#define MAX_CLUSTERS 10
9
+extern char *cluster_cfg;
10
+
11
+int parse_cluster_cfg();
12
+#endif
0 13
new file mode 100644
... ...
@@ -0,0 +1,59 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_allow.c
6
+ * 
7
+ *     Description:  [en|de]code allow header
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  21/11/05 20:40:25 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <netinet/in.h>
22
+#include <string.h>
23
+#include <stdio.h>
24
+#include "../../parser/parse_allow.h"
25
+#include "../../parser/msg_parser.h"
26
+#include "encode_allow.h"
27
+
28
+char *mismetodos[]={"UNDEF","INVITE","CANCEL","ACK","BYE","INFO","OPTIONS","UPDATE","REGISTER","MESSAGE","SUBSCRIBE","NOTIFY","PRACK","REFER","OTHER"};
29
+
30
+/**
31
+ * Encodes allow header.
32
+ *
33
+ * TODO: Does not support the UNDEFINED header type !!!
34
+ */
35
+int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where)
36
+{
37
+   unsigned int i;
38
+   memcpy(&i,bodi,4);
39
+   i=htonl(i);
40
+   memcpy(where,&i,4);
41
+   return 4;
42
+}
43
+
44
+int print_encoded_allow(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
45
+{
46
+   unsigned int i,j=0,body;
47
+
48
+   memcpy(&body,payload,4);
49
+   body=ntohl(body);
50
+   dprintf(fd,"%sMETHODS=",prefix);
51
+   if(body==0)
52
+      dprintf(fd,"UNKNOWN");
53
+   for(i=0;i<32;j=(0x01<<i),i++){
54
+      if(body & (j<15))
55
+	 dprintf(fd,",%s",mismetodos[i]);
56
+   }
57
+   dprintf(fd,"\n");
58
+   return 1;
59
+}
0 60
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+/* $Id$ */
2
+
3
+int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where);
4
+int print_encoded_allow(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
0 5
new file mode 100644
... ...
@@ -0,0 +1,297 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_contact.c
6
+ * 
7
+ *     Description:  functions to encode/decode/print the contact header
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  20/11/05 04:24:55 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <stdio.h>
22
+#include "../../parser/contact/parse_contact.h"
23
+#include "../../parser/contact/contact.h"
24
+#include "../../parser/parse_uri.h"
25
+#include "encode_contact.h"
26
+#include "encode_uri.h"
27
+#include "xaddress.h"
28
+#include "encode_header.h"
29
+#include "encode_parameters.h"
30
+
31
+#define HAS_NAME_F		0x01
32
+#define HAS_Q_F			0x02
33
+#define HAS_EXPIRES_F		0x04
34
+#define HAS_RECEIVED_F		0x08
35
+#define HAS_METHOD_F		0x10
36
+/*
37
+ * encodes a (maybe aggregated) contact header.
38
+ * encoding is:
39
+ * 1: flags
40
+ * 	0x01 this is a star contact (*)
41
+ *[ 
42
+ * 1: number of contacts present
43
+ * N: fore each contact present, the length of the contact structure
44
+ * N*M: the contact structures concatenated
45
+ *]
46
+ */
47
+int encode_contact_body(char *hdr,int hdrlen,contact_body_t *contact_parsed,unsigned char *where)
48
+{
49
+   int i=0,k,contact_offset;
50
+   unsigned char flags=0,tmp[500];
51
+   contact_t *mycontact;
52
+
53
+   if(contact_parsed->star){
54
+      flags|=STAR_F;
55
+      where[0]=flags;
56
+      return 1;
57
+   }
58
+   for(contact_offset=0,i=0,mycontact=contact_parsed->contacts;mycontact;mycontact=mycontact->next,i++){
59
+      if((k=encode_contact(hdr,hdrlen,mycontact,&tmp[contact_offset]))<0){
60
+	 LOG(L_ERR,"ERROR: encode_contact_header: parsing contact number %d\n",i);
61
+	 return -1;
62
+      }
63
+      where[2+i]=k;
64
+      contact_offset+=k;
65
+   }
66
+   where[1]=(unsigned char)i;
67
+   memcpy(&where[2+i],tmp,contact_offset);
68
+   return 2+i+contact_offset;
69
+}
70
+
71
+/* Encoder for contacts.
72
+ * Returns the length of the encoded structure in bytes
73
+ * FORMAT (byte meanings):
74
+ * 1: flags
75
+ * 	0x01 :	there is a Display Name
76
+ * 	0x02 :	there is a Q parameter
77
+ * 	0x04 :	there is an EXPIRES parameter
78
+ * 	0x08 :	there is a RECEIVED parameter
79
+ * 	0x10 :	there is a METHOD parameter
80
+ * 1: length of the XURI-encoded uri in bytes.
81
+ * [2]: optionally, 1 HDR-based ptr to the displayname + the length of the name
82
+ * [2]: optionally, 1 HDR-based ptr to the q + the length of the q
83
+ * [2]: optionally, 1 HDR-based ptr to the expires + the length of the expires
84
+ * [2]: optionally, 1 HDR-based ptr to the received param + the length of the param
85
+ * [2]: optionally, 1 HDR-based ptr to the method + the length of the method parameter
86
+ * N: the XURI-encoded URI.
87
+ * [N:] optionally, HDR-based pointers to the different header-parameters
88
+ *
89
+ */
90
+int encode_contact(char *hdrstart,int hdrlen,contact_t *body,unsigned char *where)
91
+{
92
+   int i=2,j=0;/* 1*flags + 1*URI_len*/
93
+   unsigned char flags=0;
94
+   struct sip_uri puri;
95
+
96
+   if(body->name.s && body->name.len){
97
+      flags|=HAS_NAME_F;
98
+      where[i++]=(unsigned char)(body->name.s-hdrstart);
99
+      where[i++]=(unsigned char)body->name.len;
100
+   }
101
+   if(body->q){
102
+      flags|=HAS_Q_F;
103
+      where[i++]=(unsigned char)(body->q->name.s-hdrstart);
104
+      where[i++]=(unsigned char)body->q->len;
105
+   }
106
+   if(body->expires){
107
+      flags|=HAS_EXPIRES_F;
108
+      where[i++]=(unsigned char)(body->expires->name.s-hdrstart);
109
+      where[i++]=(unsigned char)body->expires->len;
110
+   }
111
+   if(body->received){
112
+      flags|=HAS_RECEIVED_F;
113
+      where[i++]=(unsigned char)(body->received->name.s-hdrstart);
114
+      where[i++]=(unsigned char)body->received->len;
115
+   }
116
+   if(body->methods){
117
+      flags|=HAS_METHOD_F;
118
+      where[i++]=(unsigned char)(body->methods->name.s-hdrstart);
119
+      where[i++]=(unsigned char)body->methods->len;
120
+   }
121
+
122
+   if (parse_uri(body->uri.s, body->uri.len,&puri) < 0 ) {
123
+      LOG(L_ERR, "ERROR: encode_contact: Bad URI in address\n");
124
+      return -1;
125
+   }else{
126
+      if((j=encode_uri2(hdrstart,hdrlen,body->uri,&puri,&where[i]))<0){
127
+	 LOG(L_ERR, "ERROR: addr2xaddr: error codifying the URI\n");
128
+	 return -1;
129
+      }else{
130
+	 i+=j;
131
+      }
132
+   }
133
+   where[0]=flags;
134
+   where[1]=(unsigned char)j;
135
+   /*CAUTION the  parameters are in reversed order !!! */
136
+   /*TODO parameter encoding logic should be moved to a specific function...*/
137
+
138
+   i+=encode_parameters(&where[i],body->params,hdrstart,body,'n');
139
+   return i;
140
+}
141
+
142
+int print_encoded_contact_body(int fd,char *hdr,int hdrlen,unsigned char *payload,int paylen,char *prefix)
143
+{
144
+   unsigned char flags, numcontacts;
145
+   int i,offset;
146
+
147
+   flags=payload[0];
148
+   dprintf(fd,"%s",prefix);
149
+   for(i=0;i<paylen;i++)
150
+      dprintf(fd,"%s%d%s",i==0?"ENCODED CONTACT BODY:[":":",payload[i],i==paylen-1?"]\n":"");
151
+
152
+   if(flags & STAR_F){
153
+      dprintf(fd,"%sSTART CONTACT\n",prefix);
154
+      return 1;
155
+   }
156
+   numcontacts=payload[1];
157
+   if(numcontacts==0){
158
+      LOG(L_ERR,"ERROR: print_encoded_contact_body: no contacts present?\n");
159
+      return -1;
160
+   }
161
+   for(i=0,offset=2+numcontacts;i<numcontacts;i++){
162
+      print_encoded_contact(fd,hdr,hdrlen,&payload[offset],payload[2+i],strcat(prefix,"  "));
163
+      offset+=payload[2+i];
164
+      prefix[strlen(prefix)-2]=0;
165
+   }
166
+   return 1;
167
+}
168
+int print_encoded_contact(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
169
+{
170
+   int i=2;/* flags + urilength */
171
+   unsigned char flags=0;
172
+
173
+   flags=payload[0];
174
+   dprintf(fd,"%s",prefix);
175
+   for(i=0;i<paylen;i++)
176
+      dprintf(fd,"%s%d%s",i==0?"ENCODED CONTACT=[":":",payload[i],i==paylen-1?"]\n":"");
177
+   i=2;
178
+   if(flags & HAS_NAME_F){
179
+      dprintf(fd,"%sCONTACT NAME=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
180
+      i+=2;
181
+   }
182
+   if(flags & HAS_Q_F){
183
+      dprintf(fd,"%sCONTACT Q=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
184
+      i+=2;
185
+   }
186
+   if(flags & HAS_EXPIRES_F){
187
+      dprintf(fd,"%sCONTACT EXPIRES=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
188
+      i+=2;
189
+   }
190
+   if(flags & HAS_RECEIVED_F){
191
+      dprintf(fd,"%sCONTACT RECEIVED=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
192
+      i+=2;
193
+   }
194
+   if(flags & HAS_METHOD_F){
195
+      dprintf(fd,"%sCONTACT METHOD=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
196
+      i+=2;
197
+   }
198
+   if(print_encoded_uri(fd,&payload[i],payload[1],hdr,hdrlen,strcat(prefix,"  "))<0){
199
+      prefix[strlen(prefix)-2]=0;
200
+      dprintf(fd,"Error parsing URI\n");
201
+      return -1;
202
+   }
203
+   prefix[strlen(prefix)-2]=0;
204
+
205
+   print_encoded_parameters(fd,(unsigned char*)&payload[i+payload[1]],hdr,paylen-i-payload[1],prefix);
206
+   return 0;
207
+}
208
+
209
+
210
+/**
211
+ *
212
+ */
213
+int dump_contact_body_test(char *hdr,int hdrlen,unsigned char *payload,int paylen,int fd,char segregationLevel,char *prefix)
214
+{
215
+   unsigned char flags, numcontacts;
216
+   int i,offset;
217
+
218
+   flags=payload[0];
219
+
220
+   if(!segregationLevel){
221
+      return dump_standard_hdr_test(hdr,hdrlen,payload,paylen,fd);
222
+   }
223
+   if(flags & STAR_F){
224
+      return 1;
225
+   }
226
+   numcontacts=payload[1];
227
+   if(numcontacts==0){
228
+      LOG(L_ERR,"ERROR: dump_contact_body_test: no contacts present?\n");
229
+      return -1;
230
+   }
231
+   if(segregationLevel & (JUNIT|SEGREGATE|ONLY_URIS)){
232
+      for(i=0,offset=2+numcontacts;i<numcontacts;i++){
233
+	 dump_contact_test(hdr,hdrlen,&payload[offset],payload[2+i],fd,segregationLevel,prefix);
234
+	 offset+=payload[2+i];
235
+      }
236
+   }
237
+   return 1;
238
+}
239
+
240
+int dump_contact_test(char *hdr,int hdrlen,unsigned char* payload,int paylen,int fd,char segregationLevel,char *prefix)
241
+{
242
+   int i=2;/* flags + urilength */
243
+   unsigned char flags=0;
244
+
245
+   flags=payload[0];
246
+   if((segregationLevel & SEGREGATE)&& !(segregationLevel & ONLY_URIS))
247
+      return dump_standard_hdr_test(hdr,hdrlen,payload,paylen,fd);
248
+   i=2;
249
+   if(flags & HAS_NAME_F)
250
+      i+=2;
251
+   if(flags & HAS_Q_F)
252
+      i+=2;
253
+   if(flags & HAS_EXPIRES_F)
254
+      i+=2;
255
+   if(flags & HAS_RECEIVED_F)
256
+      i+=2;
257
+   if(flags & HAS_METHOD_F)
258
+      i+=2;
259
+   if(!(segregationLevel & JUNIT) && (segregationLevel & ONLY_URIS))
260
+      return dump_standard_hdr_test(hdr,hdrlen,(&payload[i]),(int)payload[1],fd);
261
+   if((segregationLevel & JUNIT) && (segregationLevel & ONLY_URIS))
262
+      return print_uri_junit_tests(hdr,hdrlen,&payload[i],payload[1],fd,1,"");
263
+   if((segregationLevel & JUNIT) && !(segregationLevel & ONLY_URIS)){
264
+      i=2;
265
+      dprintf(fd,"%sgetAddress.getDisplayName=(S)",prefix);
266
+      if(flags & HAS_NAME_F){
267
+	 dprintf(fd,"%.*s\n",payload[i+1],&hdr[payload[i]]);
268
+	 i+=2;
269
+      }else
270
+	 dprintf(fd,"(null)\n");
271
+      dprintf(fd,"%sgetQValue=(F)",prefix);
272
+      if(flags & HAS_Q_F){
273
+	 dprintf(fd,"%.*s\n",payload[i+1],&hdr[payload[i]]);
274
+	 i+=2;
275
+      }else
276
+	 dprintf(fd,"(null)\n");
277
+      dprintf(fd,"%sgetExpires=(I)",prefix);
278
+      if(flags & HAS_EXPIRES_F){
279
+	 dprintf(fd,"%.*s\n",payload[i+1],&hdr[payload[i]]);
280
+	 i+=2;
281
+      }else
282
+	 dprintf(fd,"(null)\n");
283
+      if(flags & HAS_RECEIVED_F){
284
+	 i+=2;
285
+      }
286
+      if(flags & HAS_METHOD_F){
287
+	 i+=2;
288
+      }
289
+      dprintf(fd,"%sgetParameter=(SAVP)",prefix);
290
+      for(i+=payload[1];i<paylen-1;i+=2){
291
+	 printf("%.*s=",payload[i+1]-payload[i]-1,&hdr[payload[i]]);
292
+	 printf("%.*s;",(payload[i+2]-payload[i+1])==0?0:(payload[i+2]-payload[i+1]-1),&hdr[payload[i+1]]);
293
+      }
294
+      dprintf(fd,"\n");
295
+   }
296
+   return 0;
297
+}
0 298
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+/* $Id$ */
2
+
3
+#define STAR_F 0x01
4
+param_t *reverseParameters(param_t *param);
5
+int encode_contact_body(char *hdr,int hdrlen,contact_body_t *contact_parsed,unsigned char *where);
6
+int encode_contact(char *hdr,int hdrlen,contact_t *mycontact,unsigned char *where);
7
+int print_encoded_contact_body(int fd,char *hdr,int hdrlen,unsigned char *payload,int paylen,char *prefix);
8
+int print_encoded_contact(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
9
+int dump_contact_test(char *hdr,int hdrlen,unsigned char* payload,int paylen,int fd,char segregationLevel,char *prefix);
10
+int dump_contact_body_test(char *hdr,int hdrlen,unsigned char *payload,int paylen,int fd,char segregationLevel,char *prefix);
0 11
new file mode 100644
... ...
@@ -0,0 +1,55 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_content_disposition.c
6
+ * 
7
+ *     Description:  [en|de]encodes content disposition
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  21/11/05 20:36:19 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <stdio.h>
22
+#include "../../parser/parse_disposition.h"
23
+#include "encode_parameters.h"
24
+
25
+/*
26
+struct disposition_param { str name; str body; int is_quoted; struct disposition_param *next; };
27
+struct disposition { str type; struct disposition_param *params; };
28
+*/
29
+
30
+int encode_content_disposition(char *hdrstart,int hdrlen,struct disposition *body,unsigned char *where)
31
+{
32
+   unsigned char i=3;
33
+
34
+   /*where[0] reserved flags for future use*/
35
+   where[1]=(unsigned char)(body->type.s-hdrstart);
36
+   where[2]=(unsigned char)body->type.len;
37
+   i+=encode_parameters(&where[3],(void *)body->params,hdrstart,body,'d');
38
+   return i;
39
+}
40
+
41
+int print_encoded_content_disposition(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
42
+{
43
+   int i=3;/* flags + urilength */
44
+   unsigned char flags=0;
45
+
46
+   flags=payload[0];
47
+   printf("%s",prefix);
48
+   for(i=0;i<paylen;i++)
49
+      printf("%s%d%s",i==0?"ENCODED CONTENT-DISPOSITION=[":":",payload[i],i==paylen-1?"]\n":"");
50
+   printf("%sCONTENT DISPOSITION:[%.*s]\n",prefix,payload[2],&hdr[payload[1]]);
51
+   print_encoded_parameters(fd,&payload[3],hdr,paylen-3,prefix);
52
+   return 0;
53
+}
54
+
55
+
0 56
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+/* $Id$ */
2
+
3
+int encode_content_disposition(char *hdrstart,int hdrlen,struct disposition *body,unsigned char *where);
4
+int print_encoded_content_disposition(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
0 5
new file mode 100644
... ...
@@ -0,0 +1,58 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_content_length.c
6
+ * 
7
+ *     Description:  Function to encode content-length headers.
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  21/11/05 02:02:58 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <stdio.h>
22
+#include <string.h>
23
+#include <netinet/in.h>
24
+
25
+/*
26
+ * Encodes a content-length header.
27
+ * encoding is as follows:
28
+ * 1: length of the payload.
29
+ * N: Network-Byte-Ordered(little endian) of the
30
+ * multibyte number represeting the length (now, it is
31
+ * a long integer)
32
+ */
33
+int encode_contentlength(char *hdr,int hdrlen,long int len,char *where)
34
+{
35
+   long int longint;
36
+
37
+   longint = htonl(len);
38
+   where[0]=sizeof(long int);
39
+   memcpy(&where[1],&longint,sizeof(long int));
40
+   return 1+sizeof(long int);
41
+
42
+}
43
+
44
+int print_encoded_contentlength(int fd,char *hdr,int hdrlen,unsigned char *payload,int paylen,char *prefix)
45
+{
46
+   long int content_length;
47
+   int i;
48
+
49
+   memcpy(&content_length,&payload[1],payload[0]);
50
+   content_length=ntohl(content_length);
51
+
52
+   dprintf(fd,"%s",prefix);
53
+   for(i=0;i<paylen;i++)
54
+      dprintf(fd,"%s%d%s",i==0?"ENCODED CONTENT LENGTH BODY:[":":",payload[i],i==paylen-1?"]\n":"");
55
+   dprintf(fd,"%s  CONTENT LENGTH=[%d]\n",prefix,(int)content_length);
56
+   return 1;
57
+}
58
+
0 59
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+/* $Id$ */
2
+
3
+int encode_contentlength(char *hdr,int hdrlen,long int len,char *where);
4
+int print_encoded_contentlength(int fd,char *hdr,int hdrlen,unsigned char *payload,int paylen,char *prefix);
0 5
new file mode 100644
... ...
@@ -0,0 +1,154 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_content_type.c
6
+ * 
7
+ *     Description:  [en|de]code content type
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  21/11/05 20:40:25 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <stdio.h>
22
+#include <netinet/in.h>
23
+#include <string.h>
24
+#include "../../parser/parse_content.h"
25
+#include "encode_content_type.h"
26
+
27
+int encode_content_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where)
28
+{
29
+   return encode_mime_type(hdrstart,hdrlen,bodi,where);
30
+}
31
+
32
+int print_encoded_content_type(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
33
+{
34
+   unsigned int type;
35
+   memcpy(&type,payload,sizeof(unsigned int));
36
+   return print_encoded_mime_type(fd,hdr,hdrlen,&type,paylen,prefix);
37
+}
38
+
39
+int encode_accept(char *hdrstart,int hdrlen,unsigned int *bodi,char *where)
40
+{
41
+   int i;
42
+
43
+   for(i=0;bodi[i]!=0;i++){
44
+      encode_mime_type(hdrstart,hdrlen,bodi[i],&where[1+i*sizeof(unsigned int)]);
45
+   }
46
+   where[0]=(unsigned char)i;
47
+
48
+   return 1+i*sizeof(unsigned int);
49
+}
50
+
51
+int print_encoded_accept(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
52
+{
53
+   int i;
54
+   unsigned int type;
55
+   for(i=0;i<payload[0];i++){
56
+      memcpy(&type,&payload[1+i*sizeof(unsigned int)],sizeof(unsigned int));
57
+      print_encoded_mime_type(fd,hdr,hdrlen,&type,4,prefix);
58
+   }
59
+   return 1;
60
+
61
+}
62
+
63
+int encode_mime_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where)
64
+{
65
+   unsigned int type;
66
+
67
+   type=htonl(bodi);
68
+   memcpy(where,&type,sizeof(unsigned int));
69
+
70
+   return sizeof(int);
71
+}
72
+
73
+int print_encoded_mime_type(int fd,char *hdr,int hdrlen,unsigned int* payload,int paylen,char *prefix)
74
+{
75
+   unsigned int type;
76
+   char *chtype,*chsubtype;
77
+
78
+   type=ntohl(*payload);
79
+
80
+   switch(type>>16){
81
+      case TYPE_TEXT:
82
+	 chtype="text";
83
+	 break;
84
+      case TYPE_MESSAGE:
85
+	 chtype="message";
86
+	 break;
87
+      case TYPE_APPLICATION:
88
+	 chtype="application";
89
+	 break;
90
+      case TYPE_MULTIPART:
91
+	 chtype="multipart";
92
+	 break;
93
+      case TYPE_ALL:
94
+	 chtype="all";
95
+	 break;
96
+      case TYPE_UNKNOWN:
97
+	 chtype="unknown";
98
+	 break;
99
+      default:
100
+	chtype="(didn't know this type existed)";
101
+	break;
102
+   }
103
+
104
+   switch(type&0xFF){
105
+      case SUBTYPE_PLAIN:
106
+	 chsubtype="SUBTYPE_PLAIN";
107
+	 break;
108
+      case SUBTYPE_CPIM:
109
+	 chsubtype="SUBTYPE_CPIM";
110
+	 break;
111
+      case SUBTYPE_SDP:
112
+	 chsubtype="SUBTYPE_SDP";
113
+	 break;
114
+      case SUBTYPE_CPLXML:
115
+	 chsubtype="SUBTYPE_CPLXML";
116
+	 break;
117
+      case SUBTYPE_PIDFXML:
118
+	 chsubtype="SUBTYPE_PIDFXML";
119
+	 break;
120
+      case SUBTYPE_RLMIXML:
121
+	 chsubtype="SUBTYPE_RLMIXML";
122
+	 break;
123
+      case SUBTYPE_RELATED:
124
+	 chsubtype="SUBTYPE_RELATED";
125
+	 break;
126
+      case SUBTYPE_LPIDFXML:
127
+	 chsubtype="SUBTYPE_LPIDFXML";
128
+	 break;
129
+      case SUBTYPE_XPIDFXML:
130
+	 chsubtype="SUBTYPE_XPIDFXML";
131
+	 break;
132
+      case SUBTYPE_WATCHERINFOXML:
133
+	 chsubtype="SUBTYPE_WATCHERINFOXML";
134
+	 break;
135
+      case SUBTYPE_EXTERNAL_BODY:
136
+	 chsubtype="SUBTYPE_EXTERNAL_BODY";
137
+	 break;
138
+      case SUBTYPE_XML_MSRTC_PIDF:
139
+	 chsubtype="SUBTYPE_XML_MSRTC_PIDF";
140
+	 break;
141
+      case SUBTYPE_ALL:
142
+	 chsubtype="SUBTYPE_ALL";
143
+	 break;
144
+      case SUBTYPE_UNKNOWN:
145
+	 chsubtype="SUBTYPE_UNKNOWN";
146
+	 break;
147
+      default:
148
+	 chsubtype="(didnt know this subtype existed)";
149
+   }
150
+
151
+   dprintf(fd,"%sTYPE:[%s]\n",prefix,chtype);
152
+   dprintf(fd,"%sSUBTYPE:[%s]\n",prefix,chsubtype);
153
+   return 0;
154
+}
0 155
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+/* $Id$ */
2
+
3
+int encode_content_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where);
4
+int encode_accept(char *hdrstart,int hdrlen,unsigned int *bodi,char *where);
5
+int encode_mime_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where);
6
+int print_encoded_mime_type(int fd,char *hdr,int hdrlen,unsigned int* payload,int paylen,char *prefix);
7
+int print_encoded_content_type(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
8
+int print_encoded_accept(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
0 9
new file mode 100644
... ...
@@ -0,0 +1,124 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  xaddress.c
6
+ * 
7
+ *     Description:  Address manipulation tools
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  17/11/05 02:09:44 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+#define _GNU_SOURCE
20
+#include <stdio.h>
21
+#include <string.h>
22
+#include <netinet/in.h>
23
+#include "../../mem/mem.h"
24
+#include "../../parser/parse_cseq.h"
25
+#include "../../dprint.h"
26
+#include "../../ut.h"
27
+
28
+/* Encoder for CSeq header
29
+ * Returns the length of the encoded structure in bytes
30
+ * FORMAT (byte meanings):
31
+ * 1: method_id
32
+ * 4: cseqnum in network byte order
33
+ * 2: HDR-based ptr to the method number + number length
34
+ * 2: HDR-based ptr to the method name + method length
35
+ *
36
+ */
37
+int encode_cseq(char *hdrstart,int hdrlen,struct cseq_body *body,unsigned char *where)
38
+{
39
+   unsigned int cseqnum;
40
+   unsigned char i;
41
+
42
+   /*which is the first bit set to 1 ? if i==0, the first bit, 
43
+    * if i==31, the last, if i==32, none*/
44
+   for(i=0;(!(body->method_id & (0x01<<i))) && i<32;i++);
45
+   if(i==32)
46
+      i=0;
47
+   else
48
+      i++;
49
+   where[0]=i;
50
+   if(str2int(&body->number,&cseqnum)<0){
51
+      LOG(L_ERR,"ERROR: encode_cseq: str2int(cseq number)\n");
52
+      return -1;
53
+   }
54
+   cseqnum=htonl(cseqnum);
55
+   memcpy(&where[1],&cseqnum,4);/*I use 4 because 3261 says CSEq num must be 32 bits long*/
56
+   where[5]=(unsigned char)(body->number.s-hdrstart);
57
+   where[6]=(unsigned char)(body->number.len);
58
+   where[7]=(unsigned char)(body->method.s-hdrstart);
59
+   where[8]=(unsigned char)(body->method.len);
60
+   return 9;
61
+}
62
+
63
+int print_encoded_cseq(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
64
+{
65
+   unsigned int cseqnum;
66
+   char *what;
67
+
68
+   memcpy(&cseqnum,&payload[1],4);
69
+   cseqnum=ntohl(cseqnum);
70
+   dprintf(fd,"%sCSEQ NUMBER=%d==%.*s\n",prefix,cseqnum,payload[6],&hdr[payload[5]]);
71
+   switch(payload[0]){
72
+      case 0:
73
+	 what="UNDEFINED";
74
+	 break;
75
+      case 1:
76
+	 what="INVITE";
77
+	 break;
78
+      case 2:
79
+	 what="CANCEL";
80
+	 break;
81
+      case 3:
82
+	 what="ACK";
83
+	 break;
84
+      case 4:
85
+	 what="BYE";
86
+	 break;
87
+      case 5:
88
+	 what="INFO";
89
+	 break;
90
+      case 6:
91
+	 what="OPTIONS";
92
+	 break;
93
+      case 7:
94
+	 what="UPDATE";
95
+	 break;
96
+      case 8:
97
+	 what="REGISTER";
98
+	 break;
99
+      case 9:
100
+	 what="MESSAGE";
101
+	 break;
102
+      case 10:
103
+	 what="SUBSCRIBE";
104
+	 break;
105
+      case 11:
106
+	 what="NOTIFY";
107
+	 break;
108
+      case 12:
109
+	 what="PRACK";
110
+	 break;
111
+      case 13:
112
+	 what="REFER";
113
+	 break;
114
+      case 14:
115
+	 what="OTHER";
116
+	 break;
117
+      default:
118
+	 what="UNKNOWN?";
119
+	 break;
120
+   }
121
+   dprintf(fd,"%sCSEQ METHOD=%s==%.*s\n",prefix,what,payload[8],&hdr[payload[7]]);
122
+   return 1;
123
+
124
+}
0 125
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+/* $Id$ */
2
+
3
+#include "../../str.h"
4
+#include "../../parser/msg_parser.h"
5
+int encode_cseq(char *hdrstart,int hdrlen,struct cseq_body *body,unsigned char *where);
6
+int print_encoded_cseq(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
0 7
new file mode 100644
... ...
@@ -0,0 +1,220 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_digest.c
6
+ * 
7
+ *     Description:  functions to encode/decode/print Digest headers ([proxy,www]-[authenticate,require])
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  20/11/05 04:24:55 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+#define _GNU_SOURCE
20
+#include <stdio.h>
21
+
22
+#include "../../parser/digest/digest_parser.h"
23
+#include "../../parser/parse_uri.h"
24
+#include "../../parser/digest/digest.h"
25
+#include "encode_digest.h"
26
+#include "xaddress.h"
27
+#include "encode_header.h"
28
+#include "encode_uri.h"
29
+
30
+#define HAS_NAME_F		0x01
31
+#define HAS_REALM_F		0x02
32
+#define HAS_NONCE_F		0x04
33
+#define HAS_URI_F		0x08
34
+#define HAS_RESPONSE_F		0x10
35
+#define HAS_ALG_F		0x20
36
+#define HAS_CNONCE_F		0x40
37
+#define HAS_OPAQUE_F		0x80
38
+#define HAS_QoP_F		0x01
39
+#define HAS_NC_F		0x02
40
+/*
41
+ * encodes a digest header body.
42
+ * encoding is:
43
+ * 1: flags
44
+ * HAS_NAME_F		0x01
45
+ * HAS_REALM_F		0x02
46
+ * HAS_NONCE_F		0x04
47
+ * HAS_URI_F		0x08
48
+ * HAS_RESPONSE_F	0x10
49
+ * HAS_ALG_F		0x20
50
+ * HAS_CNONCE_F		0x40
51
+ * HAS_OPAQUE_F		0x80
52
+ * 1: flags
53
+ * HAS_QoP_F		0x01
54
+ * HAS_NC_F		0x02
55
+ * 2: hdr-start based pointer to where the scheme starts + length of the scheme (must be Digest).
56
+ * 
57
+ * for each field present, there are 2 bytes, one pointing the place where it starts, 
58
+ * the next signaling how long this field is. The URI is a special case, and is composed of 1
59
+ * byte telling how long is the URI structure, and then the encoded URI structure.
60
+ */
61
+
62
+int encode_digest(char *hdrstart,int hdrlen,dig_cred_t *digest,unsigned char *where)
63
+{
64
+   int i=2,j=0;/* 2*flags */
65
+   unsigned char flags1=0,flags2=0;
66
+   struct sip_uri sipuri;
67
+
68
+   if(digest->username.whole.s && digest->username.whole.len){
69
+      flags1|=HAS_NAME_F;
70
+      where[i++]=(unsigned char)(digest->username.whole.s-hdrstart);
71
+      where[i++]=(unsigned char)digest->username.whole.len;
72
+   }
73
+   if(digest->realm.s && digest->realm.len){
74
+      flags1|=HAS_REALM_F;
75
+      where[i++]=(unsigned char)(digest->realm.s-hdrstart);
76
+      where[i++]=(unsigned char)digest->realm.len;
77
+   }
78
+   if(digest->nonce.s && digest->nonce.len){
79
+      flags1|=HAS_NONCE_F;
80
+      where[i++]=(unsigned char)(digest->nonce.s-hdrstart);
81
+      where[i++]=(unsigned char)digest->nonce.len;
82
+   }
83
+   if(digest->uri.s && digest->uri.len){
84
+      memset(&sipuri,0,sizeof(struct sip_uri));
85
+      flags1|=HAS_URI_F;
86
+      if (parse_uri(digest->uri.s, digest->uri.len,&sipuri) < 0 ) {
87
+	 LOG(L_ERR, "ERROR: encode_digest: Bad URI in address\n");
88
+	 return -1;
89
+      }else{
90
+	 if((j=encode_uri2(hdrstart,hdrlen,digest->uri,&sipuri,&where[i+1]))<0){
91
+	    LOG(L_ERR, "ERROR: encode_digest: error encoding the URI\n");
92
+	    return -1;
93
+	 }else{
94
+	    where[i]=(unsigned char)j;
95
+	    i+=(j+1);
96
+	 }
97
+      }
98
+   }
99
+   if(digest->response.s && digest->response.len){
100
+      flags1|=HAS_RESPONSE_F;
101
+      where[i++]=(unsigned char)(digest->response.s-hdrstart);
102
+      where[i++]=(unsigned char)digest->response.len;
103
+   }
104
+   if(digest->alg.alg_str.s && digest->alg.alg_str.len){
105
+      flags1|=HAS_ALG_F;
106
+      where[i++]=(unsigned char)(digest->alg.alg_str.s-hdrstart);
107
+      where[i++]=(unsigned char)digest->alg.alg_str.len;
108
+   }
109
+   if(digest->cnonce.s && digest->cnonce.len){
110
+      flags1|=HAS_CNONCE_F;
111
+      where[i++]=(unsigned char)(digest->cnonce.s-hdrstart);
112
+      where[i++]=(unsigned char)digest->cnonce.len;
113
+   }
114
+   if(digest->opaque.s && digest->opaque.len){
115
+      flags1|=HAS_OPAQUE_F;
116
+      where[i++]=(unsigned char)(digest->opaque.s-hdrstart);
117
+      where[i++]=(unsigned char)digest->opaque.len;
118
+   }
119
+   if(digest->qop.qop_str.s && digest->qop.qop_str.len){
120
+      flags2|=HAS_QoP_F;
121
+      where[i++]=(unsigned char)(digest->qop.qop_str.s-hdrstart);
122
+      where[i++]=(unsigned char)digest->qop.qop_str.len;
123
+   }
124
+   if(digest->nc.s && digest->nc.len){
125
+      flags2|=HAS_NC_F;
126
+      where[i++]=(unsigned char)(digest->nc.s-hdrstart);
127
+      where[i++]=(unsigned char)digest->nc.len;
128
+   }
129
+   where[0]=flags1;
130
+   where[1]=flags2;
131
+   return i;
132
+}
133
+
134
+
135
+int print_encoded_digest(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
136
+{
137
+   int i=2;/* flags + flags1 */
138
+   unsigned char flags1,flags2;
139
+
140
+   flags1=payload[0];
141
+   flags2=payload[1];
142
+   dprintf(fd,"%s",prefix);
143
+   for(i=0;i<paylen;i++)
144
+      dprintf(fd,"%s%d%s",i==0?"ENCODED DIGEST=[":":",payload[i],i==paylen-1?"]\n":"");
145
+   i=2;
146
+   if(flags1 & HAS_NAME_F){
147
+      dprintf(fd,"%sDIGEST NAME=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
148
+      i+=2;
149
+   }
150
+   if(flags1& HAS_REALM_F){
151
+      dprintf(fd,"%sDIGEST REALM=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
152
+      i+=2;
153
+   }
154
+   if(flags1& HAS_NONCE_F){
155
+      dprintf(fd,"%sDIGEST NONCE=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
156
+      i+=2;
157
+   }
158
+   if(flags1& HAS_URI_F){
159
+      if(print_encoded_uri(fd,&payload[i+1],payload[i],hdr,hdrlen,strcat(prefix,"  "))<0){
160
+	 prefix[strlen(prefix)-2]=0;
161
+	 dprintf(fd,"Error parsing encoded URI\n");
162
+	 return -1;
163
+      }
164
+      i+=payload[i]+1;
165
+   }
166
+   if(flags1& HAS_RESPONSE_F){
167
+      dprintf(fd,"%sDIGEST RESPONSE=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
168
+      i+=2;
169
+   }
170
+   if(flags1& HAS_ALG_F){
171
+      dprintf(fd,"%sDIGEST ALGORITHM=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
172
+      i+=2;
173
+   }
174
+   if(flags1& HAS_CNONCE_F){
175
+      dprintf(fd,"%sDIGEST CNONCE=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
176
+      i+=2;
177
+   }
178
+   if(flags1& HAS_OPAQUE_F){
179
+      dprintf(fd,"%sDIGEST OPAQUE=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
180
+      i+=2;
181
+   }
182
+   if(flags2& HAS_QoP_F){
183
+      dprintf(fd,"%sDIGEST QualityOfProtection=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
184
+      i+=2;
185
+   }
186
+   if(flags2& HAS_NC_F){
187
+      dprintf(fd,"%sDIGEST NonceCount=[%.*s]\n",prefix,payload[i+1],&hdr[payload[i]]);
188
+      i+=2;
189
+   }
190
+   return 0;
191
+}
192
+
193
+
194
+/**
195
+ *
196
+ */
197
+int dump_digest_test(char *hdr,int hdrlen,unsigned char* payload,int paylen,int fd,char segregationLevel)
198
+{
199
+   int i=2;/* 2*flags */
200
+   unsigned char flags1=0,flags2=0;
201
+
202
+   flags1=payload[0];
203
+   flags2=payload[1];
204
+   if(!(segregationLevel & ONLY_URIS))
205
+      return dump_standard_hdr_test(hdr,hdrlen,payload,paylen,fd);
206
+   i=2;
207
+   if(flags1 & HAS_NAME_F)
208
+      i+=2;
209
+   if(flags1 & HAS_REALM_F)
210
+      i+=2;
211
+   if(flags1 & HAS_NONCE_F)
212
+      i+=2;
213
+   if(flags1 & HAS_URI_F){
214
+      if(!(segregationLevel & JUNIT) && (segregationLevel & ONLY_URIS))
215
+	 return dump_standard_hdr_test(hdr,hdrlen,&payload[i+1],payload[i],fd);
216
+      if((segregationLevel & JUNIT) && (segregationLevel & ONLY_URIS))
217
+	 return print_uri_junit_tests(hdr,hdrlen,&payload[i+1],payload[i],fd,1,"");
218
+   }
219
+   return 0;
220
+}
0 221
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+/* $Id$ */
2
+
3
+int encode_digest(char *hdrstart,int hdrlen,dig_cred_t *digest,unsigned char *where);
4
+int print_encoded_digest(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
5
+int dump_digest_test(char *hdr,int hdrlen,unsigned char* payload,int paylen,int fd,char segregationLevel);
0 6
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  encode_expires.c
6
+ * 
7
+ *     Description:  functions to [en|de]code expires header
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  22/11/05 00:05:54 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+
20
+#define _GNU_SOURCE
21
+#include <stdio.h>
22
+#include <netinet/in.h>
23
+#include <string.h>
24
+#include "../../parser/parse_expires.h"
25
+
26
+/*
27
+ * Encodes expires headers (content = delta-seconds)
28
+ * 4: network-byte-order value
29
+ * 2: hdr-based pointer to begin of value string + value string length
30
+ */
31
+int encode_expires(char *hdrstart,int hdrlen,exp_body_t *body,unsigned char *where)
32
+{
33
+   int i;
34
+
35
+   i=htonl(body->val);
36
+   memcpy(where,&i,4);
37
+   where[4]=(unsigned char)(body->text.s-hdrstart);
38
+   where[5]=(unsigned char)(body->text.len);
39
+   return 6;
40
+}
41
+
42
+int print_encoded_expires(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
43
+{
44
+   int i;
45
+   memcpy(&i,payload,4);
46
+   i=ntohl(i);
47
+   dprintf(fd,"%sEXPIRES VALUE=%d==%.*s\n",prefix,i,payload[5],&hdr[payload[4]]);
48
+   return 1;
49
+}
50
+
51
+
0 52
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+/* $Id$ */
2
+
3
+int encode_expires(char *hdrstart,int hdrlen,exp_body_t *body,unsigned char *where);
4
+int print_encoded_expires(int fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
0 5
new file mode 100644
... ...
@@ -0,0 +1,472 @@
1
+/* $Id$ */
2
+/*
3
+ * =====================================================================================
4
+ * 
5
+ *        Filename:  xcontact.c
6
+ * 
7
+ *     Description:  Contact encoding functions
8
+ * 
9
+ *         Version:  1.0
10
+ *         Created:  19/11/05 14:33:38 CET
11
+ *        Revision:  none
12
+ *        Compiler:  gcc
13
+ * 
14
+ *          Author:  Elias Baixas (EB), elias@conillera.net
15
+ *         Company:  VozTele.com
16
+ * 
17
+ * =====================================================================================
18
+ */
19
+#define _GNU_SOURCE
20
+#include <string.h>
21
+#include <unistd.h>
22
+#include <netinet/in.h>
23
+#include "../../str.h"
24
+#include "../../parser/msg_parser.h"
25
+#include "../../parser/hf.h"
26
+#include "../../parser/contact/parse_contact.h"
27
+#include "../../parser/contact/contact.h"
28
+#include "../../parser/digest/digest.h"