Browse code

some development

Bogdan-Andrei Iancu authored on 23/06/2003 15:38:48
Showing 11 changed files
... ...
@@ -66,32 +66,6 @@
66 66
 
67 67
 
68 68
 /* attributs and values fro ADDRESS-SWITCH node */
69
-/*
70
- *
71
- * Copyright (C) 2001-2003 Fhg Fokus
72
- *
73
- * This file is part of ser, a free SIP server.
74
- *
75
- * ser is free software; you can redistribute it and/or modify
76
- * it under the terms of the GNU General Public License as published by
77
- * the Free Software Foundation; either version 2 of the License, or
78
- * (at your option) any later version
79
- *
80
- * For a license to use the ser software under conditions
81
- * other than those described here, or to purchase support for this
82
- * software, please contact iptel.org by e-mail at the following addresses:
83
- *    info@iptel.org
84
- *
85
- * ser is distributed in the hope that it will be useful,
86
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
87
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
88
- * GNU General Public License for more details.
89
- *
90
- * You should have received a copy of the GNU General Public License 
91
- * along with this program; if not, write to the Free Software 
92
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
93
- */
94
-
95 69
 #define  FIELD_ATTR                  0       /*shared with STRING_SWITCH*/
96 70
 #define  SUBFIELD_ATTR               1
97 71
 #define  ORIGIN_VAL                  0
... ...
@@ -194,6 +168,7 @@
194 168
 #define      KID_OFFSET(_buf,_nr)   ( *((unsigned short*)((_buf)+2+2*(_nr))) )
195 169
 #define      ATTR_PTR(_buf)         ( (_buf)+2+2*NR_OF_KIDS(_buf)+1 )
196 170
 #define      NR_OF_ATTR(_buf)       ( *((_buf)+2+2*NR_OF_KIDS(_buf)) )
171
+#define      SIMPLE_NODE_SIZE(_buf) ( 2+2*NR_OF_KIDS(_buf) )
197 172
 
198 173
 
199 174
 #endif
... ...
@@ -8,6 +8,9 @@
8 8
 include ../../Makefile.defs
9 9
 auto_gen=
10 10
 NAME=cpl-c.so
11
+
12
+#DEFS +=-I/usr/include/libxml2
13
+
11 14
 LIBS= -L$(LOCALBASE)/lib -L/usr/pkg/lib -lxml
12 15
 
13 16
 include ../../Makefile.modules
... ...
@@ -34,15 +34,17 @@
34 34
 #include <stdio.h>
35 35
 #include <string.h>
36 36
 
37
+#include "../../mem/shm_mem.h"
38
+#include "../../mem/mem.h"
37 39
 #include "../../sr_module.h"
38 40
 #include "../../str.h"
39
-#include "../../msg_translator.h"
40
-#include "../../data_lump_rpl.h"
41 41
 #include "../../dprint.h"
42 42
 #include "../../error.h"
43
-#include "../../ut.h"
44
-#include "../../globals.h"
45
-#include "cpl_parser.h"
43
+#include "../../parser/parse_uri.h"
44
+#include "../../parser/parse_from.h"
45
+#include "../../db/db.h"
46
+#include "cpl_run.h"
47
+#include "cpl_db.h"
46 48
 
47 49
 
48 50
 //char           *resp_buf;
... ...
@@ -51,30 +53,28 @@
51 53
 //unsigned int   resp_len;
52 54
 //unsigned int   resp_code;
53 55
 
54
-char *DB_URL       = 0;
55
-char *DB_TABLE     = 0;
56
+char *DB_URL       = 0;  /* database url */
57
+char *DB_TABLE     = 0;  /* */
58
+static db_con_t* db_hdl   = 0;
56 59
 int  cache_timeout = 5;
60
+cmd_function sl_send_rpl = 0;
57 61
 
62
+MODULE_VERSION
58 63
 
59 64
 
60 65
 
61 66
 static int cpl_run_script(struct sip_msg* msg, char* str, char* str2);
62
-static int cpl_is_response_accept(struct sip_msg* msg, char* str, char* str2);
63
-static int cpl_is_response_reject(struct sip_msg* msg, char* str, char* str2);
64
-static int cpl_is_response_redirect(struct sip_msg* msg, char* str, char* str2);
65
-static int cpl_update_contact(struct sip_msg* msg, char* str, char* str2);
66
-static int mod_init(void);
67
+static int fixup_cpl_run_script(void** param, int param_no);
68
+static int cpl_init(void);
69
+static int cpl_child_init(int rank);
70
+static int cpl_exit(void);
67 71
 
68 72
 
69 73
 /*
70 74
  * Exported functions
71 75
  */
72 76
 static cmd_export_t cmds[] = {
73
-	{"cpl_run_script",           cpl_run_script,           0, 0, REQUEST_ROUTE},
74
-	{"cpl_is_response_accept",   cpl_is_response_accept,   0, 0, REQUEST_ROUTE},
75
-	{"cpl_is_response_reject",   cpl_is_response_reject,   0, 0, REQUEST_ROUTE},
76
-	{"cpl_is_response_redirect", cpl_is_response_redirect, 0, 0, REQUEST_ROUTE},
77
-	{"cpl_update_contact",       cpl_update_contact,       0, 0, REQUEST_ROUTE},
77
+	{"cpl_run_script", cpl_run_script, 1, fixup_cpl_run_script, REQUEST_ROUTE},
78 78
 	{0, 0, 0, 0, 0}
79 79
 };
80 80
 
... ...
@@ -91,104 +91,188 @@ static param_export_t params[] = {
91 91
 
92 92
 
93 93
 struct module_exports exports = {
94
-	"cpl_module",
94
+	"cpl_c",
95 95
 	cmds,     /* Exported functions */
96 96
 	params,   /* Exported parameters */
97
-	mod_init, /* Module initialization function */
97
+	cpl_init, /* Module initialization function */
98 98
 	(response_function) 0,
99
-	(destroy_function) 0,
99
+	(destroy_function) cpl_exit,
100 100
 	0,
101
-	0 /* per-child init function */
101
+	(child_init_function) cpl_child_init /* per-child init function */
102 102
 };
103 103
 
104 104
 
105
-static int mod_init(void)
105
+
106
+static int fixup_cpl_run_script(void** param, int param_no)
106 107
 {
107
-	fprintf(stderr, "cpl - initializing\n");
108
+	int type;
109
+
110
+	if (param_no==1) {
111
+		if (!strcasecmp( "incoming", *param))
112
+			type = CPL_INCOMING_TYPE;
113
+		else if (!strcasecmp( "outgoing", *param))
114
+			type = CPL_OUTGOING_TYPE;
115
+		else {
116
+			LOG(L_ERR,"ERROR:fixup_cpl_run_script: script directive \"%s\""
117
+				" unknown!\n",(char*)*param);
118
+			return E_UNSPEC;
119
+		}
120
+		pkg_free(*param);
121
+		*param=(void*)type;
122
+		return 0;
123
+	}
108 124
 	return 0;
109 125
 }
110 126
 
111 127
 
112
-static int cpl_run_script(struct sip_msg* msg, char* str1, char* str2)
128
+
129
+static int cpl_init(void)
113 130
 {
114
-	return 1;
115
-}
131
+	LOG(L_INFO,"CPL - initializing\n");
116 132
 
133
+	/* check the module params */
134
+	if (DB_URL==0) {
135
+		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"DB_URL\" "
136
+			"found empty\n");
137
+		goto error;
138
+	}
139
+	if (DB_TABLE==0) {
140
+		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"DB_TABLE\" "
141
+			"found empty\n");
142
+		goto error;
143
+	}
117 144
 
145
+	/* bind to the mysql module */
146
+	if (bind_dbmod()) {
147
+		LOG(L_CRIT,"ERROR:cpl_init: cannot bind to database module! "
148
+			"Did you forget to load a database module ?\n");
149
+		goto error;
150
+	}
118 151
 
119
-static int cpl_is_response_accept(struct sip_msg* msg, char* str1, char* str2)
120
-{
121
-	return 1;
152
+	/* bind the sl_send_reply function */
153
+	sl_send_rpl = find_export("sl_send_reply", 2, REQUEST_ROUTE);
154
+	if (sl_send_rpl==0) {
155
+		LOG(L_CRIT,"ERROR:cpl_init: connot find \"sl_send_reply\" function! "
156
+			"Did you forget to load the sl module ?\n");
157
+		goto error;
158
+	}
159
+
160
+	return 0;
161
+error:
162
+	return -1;
122 163
 }
123 164
 
124 165
 
125
-static int cpl_is_response_reject(struct sip_msg* msg, char* str1, char* str2)
166
+
167
+static int cpl_child_init(int rank)
126 168
 {
127
-	return 1;
169
+	//int  i, foo;
170
+
171
+	/* only the child 1 will execut this
172
+	if (rank != 1) goto done; */
173
+
174
+	if ( (db_hdl=db_init(DB_URL))==0 ) {
175
+		LOG(L_CRIT,"ERROR:cpl_child_init: cannot initialize database "
176
+			"connection\n");
177
+		goto error;
178
+	}
179
+	if (db_use_table( db_hdl, DB_TABLE) < 0) {
180
+		LOG(L_CRIT,"ERROR:cpl_child_init: cannot select table \"%s\"\n",
181
+			DB_TABLE);
182
+		goto error;
183
+	}
184
+
185
+	return 0;
186
+error:
187
+	if (db_hdl)
188
+		db_close(db_hdl);
189
+	return -1;
128 190
 }
129 191
 
130 192
 
131
-static int cpl_is_response_redirect(struct sip_msg* msg, char* str1,char* str2)
193
+
194
+static int cpl_exit(void)
132 195
 {
133
-	return 1;
196
+	return 0;
134 197
 }
135 198
 
136 199
 
137
-static int cpl_update_contact(struct sip_msg* msg, char* str1, char* str2)
200
+
201
+static int cpl_run_script(struct sip_msg* msg, char* str1, char* str2)
138 202
 {
139
-#ifdef cucu
140
-	TRedirectMessage  *redirect;
141
-	struct lump_rpl *lump;
142
-	char *buf, *p;
143
-	int len;
144
-	int i;
145
-
146
-	if (resp_code!=REDIRECT_CALL || !resp_buf || !resp_len)
147
-		return -1;
148
-
149
-	redirect = parseRedirectResponse( resp_buf , resp_len );
150
-	printRedirectMessage( redirect );
151
-
152
-	len = 9 /*"Contact: "*/;
153
-	/* locations*/
154
-	for( i=0 ; i<redirect->numberOfLocations; i++)
155
-		len += 2/*"<>"*/ + redirect->locations[i].urlLength;
156
-	len += redirect->numberOfLocations -1 /*","*/;
157
-	len += CRLF_LEN;
158
-
159
-	buf = pkg_malloc( len );
160
-	if(!buf)
161
-	{
162
-		LOG(L_ERR,"ERROR:cpl_update_contact: out of memory! \n");
163
-		return -1;
203
+	struct cpl_interpreter  *cpl_intr;
204
+	struct to_body          *from;
205
+	struct sip_uri          uri;
206
+	str                     script;
207
+
208
+	script.s = 0;
209
+	cpl_intr = 0;
210
+
211
+	/* get the user_name */
212
+	if ( (unsigned int)str1==CPL_INCOMING_TYPE ) {
213
+		/* if it's incoming -> get the user_name from new_uri/RURI/To */
214
+		DBG("DEBUG:cpl_run_script: tring to get user from new_uri\n");
215
+		if ( !msg->new_uri.s||parse_uri( msg->new_uri.s,msg->new_uri.len,&uri)
216
+		|| !uri.user.len )
217
+		{
218
+			DBG("DEBUG:cpl_run_script: tring to get user from R_uri\n");
219
+			if ( parse_uri( msg->first_line.u.request.uri.s,
220
+			msg->first_line.u.request.uri.len ,&uri)||!uri.user.len )
221
+			{
222
+				DBG("DEBUG:cpl_run_script: tring to get user from To\n");
223
+				if (!msg->to || !get_to(msg) ||
224
+				parse_uri( get_to(msg)->uri.s, get_to(msg)->uri.len, &uri)
225
+				||!uri.user.len)
226
+				{
227
+					LOG(L_ERR,"ERROR:cpl_run_script: unable to extract user"
228
+					" name from RURI or To header!\n");
229
+					goto error;
230
+				}
231
+			}
232
+		}
233
+	} else {
234
+		/* if it's outgoing -> get the user_name from From */
235
+		/* parsing from header */
236
+		if ( parse_from_header( msg )==-1 ) {
237
+			LOG(L_ERR,"ERROR:cpl_run_script: unable to extract URI "
238
+				"from FROM header\n");
239
+			goto error;
240
+		}
241
+		from = (struct to_body*)msg->from->parsed;
242
+		/* parse the extracted uri from From */
243
+		if (parse_uri( from->uri.s, from->uri.len, &uri)||!uri.user.len) {
244
+			LOG(L_ERR,"ERROR:cpl_run_script: unable to extract user name "
245
+				"from URI (From header)\n");
246
+			goto error;
247
+		}
164 248
 	}
165 249
 
166
-	p = buf;
167
-	memcpy( p , "Contact: " , 9);
168
-	p += 9;
169
-	for( i=0 ; i<redirect->numberOfLocations; i++)
170
-	{
171
-		if (i) *(p++)=',';
172
-		*(p++) = '<';
173
-		memcpy(p,redirect->locations[i].URL,redirect->locations[i].urlLength);
174
-		p += redirect->locations[i].urlLength;
175
-		*(p++) = '>';
176
-	}
177
-	memcpy(p,CRLF,CRLF_LEN);
178
-
179
-	lump = build_lump_rpl( buf , len );
180
-	if(!buf)
181
-	{
182
-		LOG(L_ERR,"ERROR:cpl_update_contact: unable to build lump_rpl! \n");
183
-		pkg_free( buf );
184
-		return -1;
250
+	/* get the script for this user */
251
+	if (get_user_script( db_hdl, &uri.user, &script)==-1)
252
+		goto error;
253
+
254
+	/* build a new script interpreter */
255
+	if ( (cpl_intr=build_cpl_interpreter(msg,&script,(unsigned int)str1))==0 )
256
+		goto error;
257
+
258
+	/* run the script */
259
+	switch (run_cpl_script( cpl_intr )) {
260
+		case SCRIPT_END:
261
+			free_cpl_interpreter( cpl_intr );
262
+		case SCRIPT_TO_BE_CONTINUED:
263
+			break;
264
+		case -1:
265
+			goto error;
185 266
 	}
186
-	add_lump_rpl( msg , lump );
187 267
 
188
-	freeRedirectMessage( redirect );
189
-	pkg_free(buf);
190
-#endif
191 268
 	return 1;
269
+error:
270
+	if (!cpl_intr && script.s)
271
+		shm_free(script.s);
272
+	if (cpl_intr)
273
+		free_cpl_interpreter( cpl_intr );
274
+	return -1;
192 275
 }
193 276
 
194 277
 
278
+
... ...
@@ -25,7 +25,8 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
-#include "../mysql/dbase.h"
28
+#include "../../mem/shm_mem.h"
29
+#include "../../db/db.h"
29 30
 #include "../../dprint.h"
30 31
 #include "cpl_db.h"
31 32
 
... ...
@@ -33,41 +34,78 @@
33 34
 char *DB_URL;
34 35
 char *DB_TABLE;
35 36
 
37
+
38
+
39
+int get_user_script( db_con_t *db_hdl, str *user, str *script)
40
+{
41
+	db_key_t   keys_cmp[] = {"username"};
42
+	db_key_t   keys_ret[] = {"cpl_bin"};
43
+	db_val_t   vals[1];
44
+	db_res_t   *res = 0 ;
45
+	char       tmp;
46
+
47
+	/* it shouldn't be aproblem verwriting a \0 at the end of user name; the
48
+	 * user name is part of the sip_msg struct received -  that is allocated in
49
+	 * process private mem - no sync problems; also there is all the time some
50
+	 * extra characters after the user name - at least the EOH */
51
+	tmp = user->s[user->len];
52
+	user->s[user->len] = 0;
53
+	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
54
+	vals[0].type = DB_STRING;
55
+	vals[0].nul  = 0;
56
+	vals[0].val.string_val = user->s;
57
+	if (db_query(db_hdl, keys_cmp, 0, vals, keys_ret, 1, 1, NULL, &res) < 0) {
58
+		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
59
+		goto error;
60
+	}
61
+	user->s[user->len] = tmp;
62
+
63
+	if (res->n==0) {
64
+		LOG(L_ERR,"ERROR:get_user_script: user <%.*s> not found in databse\n",
65
+			user->len, user->s);
66
+		goto error;
67
+	}
68
+
69
+	if (res->rows[0].values[0].nul) {
70
+		DBG("DEBUG:get_user_script: user <%.*s> has a NULL script\n",
71
+			user->len, user->s);
72
+		script->s = 0;
73
+		script->len = 0;
74
+	} else {
75
+		DBG("DEBUG:get_user_script: we got the script len=%d\n",
76
+			res->rows[0].values[0].val.blob_val.len);
77
+		script->len = res->rows[0].values[0].val.blob_val.len;
78
+		script->s = shm_malloc( script->len );
79
+		if (!script->s) {
80
+			LOG(L_ERR,"ERROR:cpl-c:get_user_script: no more free memory\n");
81
+			goto error;
82
+		}
83
+		memcpy(script->s,res->rows[0].values[0].val.blob_val.s,script->len);
84
+	}
85
+
86
+	db_free_query( db_hdl, res);
87
+	return 1;
88
+error:
89
+	if (res)
90
+		db_free_query( db_hdl, res);
91
+	script->s = 0;
92
+	script->len = 0;
93
+	return -1;
94
+}
95
+
96
+
97
+
98
+
99
+
36 100
 int write_to_db( char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len)
37 101
 {
102
+#if 0
38 103
 	db_key_t   keys[] = {"username","cpl","status","cpl_bin"};
39 104
 	db_val_t   vals[4];
40 105
 	db_con_t   *db_con;
41 106
 	db_res_t   *res;
42 107
 
43
-
44 108
 	/* open connexion to db */
45
-/*
46
- *
47
- * Copyright (C) 2001-2003 Fhg Fokus
48
- *
49
- * This file is part of ser, a free SIP server.
50
- *
51
- * ser is free software; you can redistribute it and/or modify
52
- * it under the terms of the GNU General Public License as published by
53
- * the Free Software Foundation; either version 2 of the License, or
54
- * (at your option) any later version
55
- *
56
- * For a license to use the ser software under conditions
57
- * other than those described here, or to purchase support for this
58
- * software, please contact iptel.org by e-mail at the following addresses:
59
- *    info@iptel.org
60
- *
61
- * ser is distributed in the hope that it will be useful,
62
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
63
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64
- * GNU General Public License for more details.
65
- *
66
- * You should have received a copy of the GNU General Public License 
67
- * along with this program; if not, write to the Free Software 
68
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
69
- */
70
-
71 109
 	db_con = db_init(DB_URL);
72 110
 	if (!db_con) {
73 111
 		LOG(L_ERR,"ERROR:cpl:write_to_db: cannot connect to mysql db.\n");
... ...
@@ -130,6 +168,7 @@ int write_to_db( char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len)
130 168
 
131 169
 	return 0;
132 170
 error:
171
+#endif
133 172
 	return -1;
134 173
 }
135 174
 
... ...
@@ -28,9 +28,8 @@
28 28
 #ifndef _CPL_DB_H
29 29
 #define _CPL_DB_H
30 30
 
31
-int write_to_db(char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len);
32 31
 
33
-extern char* DB_URL;
34
-extern char* DB_TABLE;
32
+int write_to_db(char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len);
33
+int get_user_script( db_con_t *db_hdl, str *user, str *script);
35 34
 
36 35
 #endif
... ...
@@ -33,8 +33,8 @@
33 33
 #include <fcntl.h>
34 34
 #include <errno.h>
35 35
 #include <unistd.h>
36
-#include <gnome-xml/libxml/xmlmemory.h>
37
-#include <gnome-xml/libxml/parser.h>
36
+#include <gnome-xml/xmlmemory.h>
37
+#include <gnome-xml/parser.h>
38 38
 #include "CPL_tree.h"
39 39
 #include "sub_list.h"
40 40
 #include "../../dprint.h"
... ...
@@ -192,8 +192,7 @@ int encript_node_attr( xmlNodePtr node, unsigned char *node_ptr,
192 192
 		case DEFAULT_NODE:
193 193
 		case ANCILLARY_NODE:
194 194
 			break;
195
-		/* enconding attributes and values fro ADDRESS-SWITCH node */
196
-
195
+		/* enconding attributes and values for ADDRESS-SWITCH node */
197 196
 		case ADDRESS_SWITCH_NODE:
198 197
 			FOR_ALL_ATTR(node,attr) {
199 198
 				nr_attr++;
... ...
@@ -231,7 +230,7 @@ int encript_node_attr( xmlNodePtr node, unsigned char *node_ptr,
231 230
 				}
232 231
 			}
233 232
 			break;
234
-		/* enconding attributes and values fro ADDRESS node */
233
+		/* enconding attributes and values for ADDRESS node */
235 234
 		case ADDRESS_NODE:
236 235
 			FOR_ALL_ATTR(node,attr) {
237 236
 				nr_attr++;
... ...
@@ -706,7 +705,7 @@ int encrypt_node( xmlNodePtr node, unsigned char *p)
706 705
 char* encryptXML( char* xml_s, int xml_len, char* DTD_filename, int *bin_len)
707 706
 {
708 707
 	static unsigned char buf[2048];
709
-	unsigned int  len;
708
+	int  len;
710 709
 	xmlValidCtxt  cvp;
711 710
 	xmlDocPtr  doc;
712 711
 	xmlNodePtr cur;
713 712
new file mode 100644
... ...
@@ -0,0 +1,617 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ */
27
+
28
+#include <stdio.h>
29
+#include <string.h>
30
+#include <time.h>
31
+#include <stdlib.h>
32
+
33
+#include "../../mem/mem.h"
34
+#include "../../mem/shm_mem.h"
35
+#include "../../str.h"
36
+#include "../../dprint.h"
37
+#include "../../parser/msg_parser.h"
38
+#include "../../parser/parse_from.h"
39
+#include "../../parser/parse_uri.c"
40
+#include "../../data_lump_rpl.h"
41
+#include "CPL_tree.h"
42
+#include "loc_set.h"
43
+#include "cpl_run.h"
44
+
45
+
46
+#define MAX_SIZE_STATIC_BUF  256
47
+#define EO_SCRIPT            ((unsigned char*)0xffffffff)
48
+#define HDR_NOT_FOUND        ((char*)0xffffffff)
49
+#define UNDEF_CHAR           (0xff)
50
+
51
+
52
+extern int (*sl_send_rpl)(struct sip_msg*, char*, char*);
53
+
54
+
55
+
56
+struct cpl_interpreter* build_cpl_interpreter( struct sip_msg *msg,
57
+											str *script, unsigned int type)
58
+{
59
+	struct cpl_interpreter *intr = 0;
60
+
61
+	intr = (struct cpl_interpreter*)shm_malloc(sizeof(struct cpl_interpreter));
62
+	if (!intr) {
63
+		LOG(L_ERR,"ERROR:build_cpl_interpreter: no more free memory!\n");
64
+		goto error;
65
+	}
66
+	memset( intr, 0, sizeof(struct cpl_interpreter));
67
+
68
+	/* unut the interpreter*/
69
+	intr->script.s = script->s;
70
+	intr->script.len = script->len;
71
+	intr->recv_time = time(0);
72
+	intr->ip = script->s;
73
+	intr->msg = msg;
74
+	intr->type = (type==CPL_INCOMING_TYPE)?INCOMING_NODE:OUTGOING_NODE;
75
+
76
+	/* check the begining of the script */
77
+	if ( NODE_TYPE(intr->ip)!=CPL_NODE ) {
78
+		LOG(L_ERR,"ERROR:build_cpl_interpreter: first node is not CPL!!\n");
79
+		goto error;
80
+	}
81
+
82
+	return intr;
83
+error:
84
+	return 0;
85
+}
86
+
87
+
88
+
89
+void free_cpl_interpreter(struct cpl_interpreter *intr)
90
+{
91
+	if (intr) {
92
+		if (intr->script.s)
93
+			shm_free( intr->script.s);
94
+		empty_location_set( &(intr->loc_set) );
95
+		shm_free(intr);
96
+	}
97
+}
98
+
99
+
100
+
101
+inline unsigned char *run_cpl_node( struct cpl_interpreter *intr )
102
+{
103
+	unsigned char *kid;
104
+	int i;
105
+
106
+	for(i=0;i<NR_OF_KIDS(intr->ip);i++) {
107
+		kid= intr->ip + KID_OFFSET(intr->ip,i);
108
+		if ( NODE_TYPE(kid)==intr->type ) {
109
+			return ((NR_OF_KIDS(kid)==0)?EO_SCRIPT:kid+KID_OFFSET(kid,0));
110
+		} else if (NODE_TYPE(kid)==SUBACTION_NODE ||
111
+		NODE_TYPE(kid)==ANCILLARY_NODE) {
112
+			continue;
113
+		} else {
114
+			LOG(L_ERR,"ERROR:run_cpl_node: unknown child type (%d) "
115
+				"for CPL node!!\n",NODE_TYPE(kid));
116
+			goto error;
117
+		}
118
+	}
119
+
120
+	LOG(L_ERR,"ERROR:run_cpl_node: bad CPL node - subnode %d not found",
121
+		intr->type);
122
+error:
123
+	return 0;
124
+}
125
+
126
+
127
+
128
+inline unsigned char *run_address_switch( struct cpl_interpreter *intr )
129
+{
130
+	unsigned char field, subfield;
131
+	unsigned char *p;
132
+	unsigned char *kid;
133
+	int i;
134
+	str cpl_val;
135
+	str *msg_val;
136
+	str *uri;
137
+	struct sip_uri parsed_uri;
138
+
139
+	field = subfield = UNDEF_CHAR;
140
+	msg_val = 0;
141
+
142
+	DBG(">>>> kids=%d\n",NR_OF_KIDS(intr->ip));
143
+	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
144
+		if (*p==FIELD_ATTR)
145
+			field = *(p+1);
146
+		else if (*p==SUBFIELD_ATTR)
147
+			subfield = *(p+1);
148
+		else {
149
+			LOG(L_ERR,"ERROR:run_address_switch: unknown param type (%d) for "
150
+				"ADDRESS_SWITCH node\n",*p);
151
+			goto error;
152
+		}
153
+		p += 2;
154
+	}
155
+
156
+	if (field==UNDEF_CHAR) {
157
+		LOG(L_ERR,"ERROR:run_address_switch: param FIELD no found\n");
158
+		goto error;
159
+	}
160
+
161
+	for( i=0 ; i<NR_OF_KIDS(intr->ip) ; i++ ) {
162
+		kid = intr->ip + KID_OFFSET(intr->ip,i);
163
+		switch ( NODE_TYPE(kid) ) {
164
+			case OTHERWISE_NODE :
165
+				DBG("DEBUG:run_address_switch: matching on OTHERWISE node\n");
166
+				return ((NR_OF_KIDS(kid)==0)?EO_SCRIPT:kid+KID_OFFSET(kid,0));
167
+			case ADDRESS_NODE :
168
+				if (NR_OF_ATTR(kid)!=1)
169
+					goto error;
170
+				p = ATTR_PTR(kid);
171
+				cpl_val.len = *((unsigned short*)(p+1));
172
+				cpl_val.s = ((cpl_val.len)?(p+3):0);
173
+				DBG("DEBUG:run_address_switch: testing ADDRESS branch "
174
+					"(%d)[%.*s](%d)..\n",*p,cpl_val.len,cpl_val.s,cpl_val.len);
175
+				if (!msg_val) {
176
+					switch (field) {
177
+						case ORIGIN_VAL: /* FROM */
178
+							if (!intr->from) {
179
+								/* get the header */
180
+								if (parse_from_header( intr->msg )==-1)
181
+									goto error;
182
+								intr->from = &(get_from(intr->msg)->uri);
183
+							}
184
+							uri = intr->from;
185
+						break;
186
+						case DESTINATION_VAL: /* RURI */
187
+							if (!intr->ruri) {
188
+								intr->ruri = GET_RURI( intr->msg );
189
+							}
190
+							uri = intr->ruri;
191
+							break;
192
+						case ORIGINAL_DESTINATION_VAL: /* TO */
193
+							if (!intr->to) {
194
+								/* get and parse the header */
195
+								if (!intr->msg->to &&
196
+								(parse_headers(intr->msg,HDR_TO,0)==-1 ||
197
+								!intr->msg->to)) {
198
+									LOG(L_ERR,"ERROR:run_address_switch: bad "
199
+										"msg or missing TO header\n");
200
+									goto error;
201
+								}
202
+								intr->to = &(get_to(intr->msg)->uri);
203
+							}
204
+							uri = intr->to;
205
+							break;
206
+						default:
207
+							LOG(L_ERR,"ERROR:run_address_switch: unknown "
208
+								"attribute (%d) in ADDRESS node\n",field);
209
+							goto error;
210
+					}
211
+					DBG("DEBUG:run_address_switch: extracted uri is <%.*s>\n",
212
+						uri->len, uri->s);
213
+					switch (subfield) {
214
+						case UNDEF_CHAR:
215
+							msg_val = uri;
216
+							break;
217
+						case USER_VAL:
218
+							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)
219
+								goto error;
220
+							msg_val = &(parsed_uri.user);
221
+							break;
222
+						case HOST_VAL:
223
+							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)
224
+								goto error;
225
+							msg_val = &(parsed_uri.host);
226
+							break;
227
+						case PORT_VAL:
228
+							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)
229
+								goto error;
230
+							msg_val = &(parsed_uri.port);
231
+							break;
232
+						case TEL_VAL:
233
+							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)
234
+								goto error;
235
+							if (parsed_uri.user_param.len==5 &&
236
+							memcmp(parsed_uri.user_param.s,"phone",5)==0)
237
+								msg_val = &(parsed_uri.user);
238
+							break;
239
+						case ADDRESS_TYPE_VAL:
240
+						case DISPLAY_VAL:
241
+						default:
242
+							LOG(L_ERR,"ERROR:run_address_switch: unsupported "
243
+								"value attribute (%d) in ADDRESS node\n",
244
+								subfield);
245
+							goto error;
246
+					}
247
+					DBG("DEBUG:run_address_switch: extracted val. is <%.*s>\n",
248
+						(msg_val->len==0)?0:msg_val->len, msg_val->s);
249
+				}
250
+				/* does the value from script match the one from message? */
251
+				switch (*p) {
252
+					case IS_ATTR:
253
+						if ( (!msg_val && !cpl_val.s) ||
254
+						(msg_val && msg_val->len==cpl_val.len &&
255
+						memcmp(msg_val->s,cpl_val.s,cpl_val.len)==0)) {
256
+							DBG("DEBUG:run_address_switch: matching on "
257
+								"ADDRESS node (IS)\n");
258
+							return ((NR_OF_KIDS(kid)==0)?EO_SCRIPT:
259
+								kid+KID_OFFSET(kid,0));
260
+						}
261
+						break;
262
+					case CONTAINS_ATTR:
263
+						if (subfield!=DISPLAY_VAL) {
264
+							LOG(L_WARN,"WARNING:run_addres_switch: operator "
265
+							"CONTAINS applys only to DISPLAY -> ignored\n");
266
+						} else {
267
+							/* not implemeted ;-) */
268
+						}
269
+						break;
270
+					case SUBDOMAIN_OF_ATTR:
271
+						if (subfield!=HOST_VAL && subfield!=TEL_VAL) {
272
+							LOG(L_WARN,"WARNING:run_addres_switch: operator "
273
+								"SUBDOMAIN_OF applys only to HOST or TEL ->"
274
+								" ignored\n");
275
+						} else {
276
+							if (msg_val && msg_val->len>=cpl_val.len &&
277
+							memcmp( cpl_val.s, msg_val->s+(msg_val->len-
278
+							cpl_val.len), cpl_val.len)==0 && msg_val->s[1+
279
+							msg_val->len-cpl_val.len]=='.') {
280
+								DBG("DEBUG:run_address_switch: matching on "
281
+									"ADDRESS node (SUBDOMAIN_OF)\n");
282
+								return ((NR_OF_KIDS(kid)==0)?EO_SCRIPT:
283
+									kid+KID_OFFSET(kid,0));
284
+							}
285
+						}
286
+						break;
287
+				}
288
+				break;
289
+			default:
290
+				LOG(L_ERR,"ERROR:run_address_switch: unknown output node type "
291
+					"(%d) for ADDRESS_SWITCH node\n",NODE_TYPE(kid));
292
+		}
293
+	}
294
+
295
+error:
296
+	return 0;
297
+}
298
+
299
+
300
+
301
+inline unsigned char *run_location( struct cpl_interpreter *intr )
302
+{
303
+	unsigned char n;
304
+	unsigned char *p;
305
+	unsigned char prio;
306
+	unsigned char clear;
307
+	str url;
308
+	int i;
309
+
310
+	clear = NO_VAL;
311
+	prio = 10;
312
+	url.s = (char*)UNDEF_CHAR;
313
+
314
+	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
315
+		switch (*p) {
316
+			case URL_ATTR:
317
+				url.len = *((unsigned short*)(p+1));
318
+				url.s = ((url.len)?(p+3):0);
319
+				p += 3+url.len;
320
+				break;
321
+			case PRIORITY_ATTR:
322
+				n = (unsigned char)(*(p+1));
323
+				if ( n>10)
324
+					LOG(L_WARN,"WARNING:run_location: invalid value (%u) found"
325
+						" for param. PRIORITY in LOCATION node -> using "
326
+						"default (%u)!\n",n,prio);
327
+				else
328
+					prio = n;
329
+				p += 2;
330
+				break;
331
+			case CLEAR_ATTR:
332
+				n = (unsigned char)(*(p+1));
333
+				if (n!=YES_VAL && n!=NO_VAL)
334
+					LOG(L_WARN,"WARNING:run_location: invalid value (%u) found"
335
+						" for param. CLEAR in LOCATION node -> using "
336
+						"default (%u)!\n",n,clear);
337
+				else
338
+					clear = n;
339
+				p += 2;
340
+				break;
341
+			default:
342
+				LOG(L_ERR,"ERROR:run_location: unknown attribute (%d) in"
343
+					"LOCATION node\n",*p);
344
+				goto error;
345
+		}
346
+	}
347
+
348
+	if (url.s==(char*)UNDEF_CHAR) {
349
+		LOG(L_ERR,"ERROR:run_location: param. URL missing in LOCATION node\n");
350
+		goto error;
351
+	}
352
+
353
+	if (clear)
354
+		empty_location_set( &(intr->loc_set) );
355
+	add_location( &(intr->loc_set), url.s, url.len, prio );
356
+
357
+	return ((NR_OF_KIDS(intr->ip)==0)?EO_SCRIPT:
358
+		(intr->ip+KID_OFFSET(intr->ip,0)));
359
+error:
360
+	return 0;
361
+}
362
+
363
+
364
+
365
+inline unsigned char *run_remove_location( struct cpl_interpreter *intr )
366
+{
367
+	unsigned char *p;
368
+	str url;
369
+	int i;
370
+
371
+	url.s = (char*)UNDEF_CHAR;
372
+
373
+	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
374
+		switch (*p) {
375
+			case LOCATION_ATTR:
376
+				url.len = *((unsigned short*)(p+1));
377
+				url.s = ((url.len)?(p+3):0);
378
+				p += 3+url.len;
379
+				break;
380
+			default:
381
+				LOG(L_WARN,"WARNING:run_remove_location: unknown attribute "
382
+					"(%d) in REMOVE_LOCATION node -> ignoring..\n",*p);
383
+				goto error;
384
+		}
385
+	}
386
+
387
+	if (url.s==(char*)UNDEF_CHAR || url.len==0) {
388
+		DBG("DEBUG:run_remove_location: remove al llocs from loc_set\n");
389
+		empty_location_set( &(intr->loc_set) );
390
+	} else {
391
+		remove_location( &(intr->loc_set), url.s, url.len );
392
+	}
393
+
394
+	return ((NR_OF_KIDS(intr->ip)==0)?EO_SCRIPT:
395
+		(intr->ip+KID_OFFSET(intr->ip,0)));
396
+error:
397
+	return 0;
398
+}
399
+
400
+
401
+
402
+inline unsigned char *run_reject( struct cpl_interpreter *intr )
403
+{
404
+	static char buffer[MAX_SIZE_STATIC_BUF];
405
+	unsigned char *p;
406
+	unsigned short status;
407
+	char *reason;
408
+	int reason_len;
409
+	int len;
410
+	int i;
411
+
412
+	reason = (char*)UNDEF_CHAR;
413
+	status = UNDEF_CHAR;
414
+
415
+	/* sanity check */
416
+	if (NR_OF_KIDS(intr->ip)!=0) {
417
+		LOG(L_ERR,"ERROR:run_reject: REJECT node doesn't suppose to have any "
418
+			"sub-nodes. Found %d!\n",NR_OF_KIDS(intr->ip));
419
+		goto error;
420
+	}
421
+
422
+	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
423
+		switch (*p) {
424
+			case STATUS_ATTR:
425
+				status = *((unsigned short*)(p+1));
426
+				p += 3;
427
+				break;
428
+			case REASON_ATTR:
429
+				len = *((unsigned short*)(p+1));
430
+				if (len) {
431
+					reason_len = (len>MAX_SIZE_STATIC_BUF-1)?
432
+						(MAX_SIZE_STATIC_BUF-1):(len);
433
+					memcpy( buffer, p+3, reason_len );
434
+					buffer[reason_len] = 0;
435
+					reason = buffer;
436
+				}
437
+				p += 3+len;
438
+				break;
439
+			default:
440
+				LOG(L_WARN,"WARNING:run_reject: unknown attribute "
441
+					"(%d) in REJECT node -> ignoring..\n",*p);
442
+				goto error;
443
+		}
444
+	}
445
+
446
+	if (reason==(char*)UNDEF_CHAR ) {
447
+		switch (status) {
448
+			case 486:
449
+				reason = "Busy Here";
450
+				break;
451
+			case 404:
452
+				reason = "Not Found";
453
+				break;
454
+			case 603:
455
+				reason = "Decline";
456
+				break;
457
+			case 500:
458
+				reason = "Internal Server Error";
459
+			default:
460
+				LOG(L_ERR,"ERROR:run_reject: unknown value (%d) for attribute"
461
+					" STATUS in reject node\n",status);
462
+				goto error;
463
+		}
464
+	}
465
+
466
+	if (sl_send_rpl( intr->msg, (char*)(int)status, reason )<0) {
467
+		LOG(L_ERR,"ERROR:run_reject: unable to send reject reply!\n");
468
+		goto error;
469
+	}
470
+
471
+	return EO_SCRIPT;
472
+error:
473
+	return 0;
474
+}
475
+
476
+
477
+
478
+inline unsigned char *run_redirect( struct cpl_interpreter *intr )
479
+{
480
+	struct location *loc;
481
+	struct lump_rpl *lump;
482
+	unsigned char *p;
483
+	unsigned char permanent;
484
+	str lump_str;
485
+	char *cp;
486
+	int i;
487
+
488
+	permanent = NO_VAL;
489
+
490
+	/* sanity check */
491
+	if (NR_OF_KIDS(intr->ip)!=0) {
492
+		LOG(L_ERR,"ERROR:run_redirect: REDIRECT node doesn't suppose to have "
493
+			"any sub-nodes. Found %d!\n",NR_OF_KIDS(intr->ip));
494
+		goto error;
495
+	}
496
+
497
+	/* read the attributes of the REDIRECT node*/
498
+	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
499
+		switch (*p) {
500
+			case PERMANENT_ATTR:
501
+				permanent = *(p+1);
502
+				if (permanent!=YES_VAL && permanent!=NO_VAL) {
503
+					LOG(L_ERR,"ERROR:run_redirect: unsupported value (%d) "
504
+						"in attribute PERMANENT for REDIRECT node",permanent);
505
+					goto error;
506
+				}
507
+				p += 2;
508
+				break;
509
+			default:
510
+				LOG(L_WARN,"WARNING:run_redirect: unknown attribute "
511
+					"(%d) in REDIRECT node -> ignoring..\n",*p);
512
+				goto error;
513
+		}
514
+	}
515
+
516
+	/* build the lump for Contact header */
517
+	lump_str.len = 9 /*"Contact: "*/;
518
+	for(loc=intr->loc_set;loc;loc=loc->next)
519
+		lump_str.len += 1/*"<"*/ + loc->addr.uri.len + 7/*">;q=x.x"*/ +
520
+			2*(loc->next!=0)/*" ,"*/;
521
+	lump_str.len += CRLF_LEN;
522
+
523
+	lump_str.s = pkg_malloc( lump_str.len );
524
+	if(!lump_str.s) {
525
+		LOG(L_ERR,"ERROR:cpl_redirect: out of pkg memory!\n");
526
+		goto error;
527
+	}
528
+	cp = lump_str.s;
529
+	memcpy( cp , "Contact: " , 9);
530
+	cp += 9;
531
+	for(loc=intr->loc_set;loc;loc=loc->next) {
532
+		*(cp++) = '<';
533
+		memcpy(cp,loc->addr.uri.s,loc->addr.uri.len);
534
+		cp += loc->addr.uri.len;
535
+		memcpy(cp,">;q=",4);
536
+		cp += 4;
537
+		*(cp++) = (loc->addr.priority!=10)?'0':'1';
538
+		*(cp++) = '.';
539
+		*(cp++) = '0'+(loc->addr.priority%10);
540
+		if (loc->next) {
541
+			*(cp++) = ' ';
542
+			*(cp++) = ',';
543
+		}
544
+	}
545
+	memcpy(cp,CRLF,CRLF_LEN);
546
+
547
+	/* add the lump to the reply */
548
+	lump = build_lump_rpl( lump_str.s , lump_str.len );
549
+	if(!lump) {
550
+		LOG(L_ERR,"ERROR:cpl_redirect: unable to build lump_rpl! \n");
551
+		pkg_free( lump_str.s );
552
+		goto error;
553
+	}
554
+	add_lump_rpl( intr->msg , lump );
555
+
556
+	/* send the reply */
557
+	if (permanent)
558
+		i = sl_send_rpl( intr->msg, (char*)301, "Moved permanently" );
559
+	else
560
+		i = sl_send_rpl( intr->msg, (char*)302, "Moved temporarily" );
561
+	if (i<0) {
562
+		LOG(L_ERR,"ERROR:run_redirect: unable to send redirect reply!\n");
563
+		goto error;
564
+	}
565
+
566
+	return EO_SCRIPT;
567
+error:
568
+	return 0;
569
+}
570
+
571
+
572
+
573
+
574
+
575
+int run_cpl_script( struct cpl_interpreter *intr )
576
+{
577
+	do {
578
+		switch ( NODE_TYPE(intr->ip) ) {
579
+			case CPL_NODE:
580
+				DBG("DEBUG:run_cpl_script:processing CPL node \n");
581
+				intr->ip = run_cpl_node( intr );
582
+				break;
583
+			case ADDRESS_SWITCH_NODE:
584
+				DBG("DEBUG:run_cpl_script:processing address-switch node\n");
585
+				intr->ip = run_address_switch( intr );
586
+				break;
587
+			case LOCATION_NODE:
588
+				DBG("DEBUG:run_cpl_script:processing location node\n");
589
+				intr->ip = run_location( intr );
590
+				break;
591
+			case REMOVE_LOCATION_NODE:
592
+				DBG("DEBUG:run_cpl_script:processing remove_location node\n");
593
+				intr->ip = run_remove_location( intr );
594
+				break;
595
+			case REJECT_NODE:
596
+				DBG("DEBUG:run_cpl_script:processing reject node\n");
597
+				intr->ip = run_reject( intr );
598
+				break;
599
+			case REDIRECT_NODE:
600
+				DBG("DEBUG:run_cpl_script:processing redirect node\n");
601
+				intr->ip = run_redirect( intr );
602
+				break;
603
+			default:
604
+				LOG(L_ERR,"ERROR:run_cpl_script: unknown type node (%d)\n",
605
+					NODE_TYPE(intr->ip));
606
+				goto error;
607
+		}
608
+		if (intr->ip==0)
609
+			goto error;
610
+	}while(intr->ip!=EO_SCRIPT);
611
+
612
+	DBG("DEBUG:run_cpl_script: script interpretation done!\n");
613
+	return SCRIPT_END;
614
+error:
615
+	LOG(L_ERR,"ERROR:run_cpl_script: generic error\n");
616
+	return -1;
617
+}
0 618
new file mode 100644
... ...
@@ -0,0 +1,68 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ */
27
+
28
+#ifndef _CPL_RUN_H
29
+#define _CPL_RUN_H
30
+
31
+#include "../../str.h"
32
+#include "../../parser/msg_parser.h"
33
+
34
+#define CPL_INCOMING_TYPE   1
35
+#define CPL_OUTGOING_TYPE   2
36
+
37
+#define SCRIPT_END               1
38
+#define SCRIPT_TO_BE_CONTINUED   2
39
+
40
+
41
+
42
+struct cpl_interpreter {
43
+	str script;            /* CPL script */
44
+	unsigned char *ip;     /* instruction pointer */
45
+	int recv_time;         /* receiving time stamp */
46
+	struct sip_msg *msg;
47
+	unsigned char  type;
48
+	struct location *loc_set;     /* location set */
49
+	str *ruri;
50
+	str *to;
51
+	str *from;
52
+	str *subject;
53
+	str *organization;
54
+	str *user_angent;
55
+	str *accepted_langs;
56
+	str *priority;
57
+};
58
+
59
+struct cpl_interpreter* build_cpl_interpreter( struct sip_msg *msg,
60
+											str *script, unsigned int type);
61
+
62
+void free_cpl_interpreter(struct cpl_interpreter *intr);
63
+
64
+int run_cpl_script( struct cpl_interpreter *cpl_intr );
65
+
66
+#endif
67
+
68
+
0 69
new file mode 100644
... ...
@@ -0,0 +1,122 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ */
27
+
28
+
29
+#ifndef _CPL_LOC_SET_H_
30
+#define _CPL_LOC_SET_H_
31
+
32
+#include <stdio.h>
33
+#include <string.h>
34
+#include <time.h>
35
+#include <stdlib.h>
36
+
37
+#include "../../mem/shm_mem.h"
38
+#include "../../str.h"
39
+#include "../../dprint.h"
40
+
41
+
42
+
43
+struct location {
44
+	struct address {
45
+		str uri;
46
+		unsigned int priority;
47
+	}addr;
48
+	struct location *next;
49
+};
50
+
51
+
52
+
53
+static inline int add_location(struct location **loc_set, char *uri_s,
54
+											int uri_len, unsigned int prio)
55
+{
56
+	struct location *loc;
57
+
58
+	loc = (struct location*)shm_malloc( sizeof(struct location) );
59
+	if (!loc) {
60
+		LOG(L_ERR,"ERROR:add_location: no more free memory!\n");
61
+		return -1;
62
+	}
63
+
64
+	loc->addr.uri.s = uri_s;
65
+	loc->addr.uri.len = uri_len;
66
+	loc->addr.priority = prio;
67
+
68
+	if (*loc_set==0)
69
+		loc->next = 0;
70
+	else
71
+		loc->next = *loc_set;
72
+	*loc_set = loc;
73
+
74
+	return 0;
75
+}
76
+
77
+
78
+
79
+static inline void remove_location(struct location **loc_set, char *uri_s,
80
+																int uri_len)
81
+{
82
+	struct location *loc = *loc_set;
83
+	struct location *prev_loc = 0;
84
+
85
+	for( ; loc ; prev_loc=loc,loc=loc->next ) {
86
+		if (loc->addr.uri.len==uri_len &&
87
+		!memcpy(loc->addr.uri.s,uri_s,uri_len) )
88
+			break;
89
+	}
90
+
91
+	if (loc) {
92
+		DBG("DEBUG:remove_location: removing from loc_set <%.*s>\n",
93
+			uri_len,uri_s);
94
+		if (prev_loc)
95
+			prev_loc->next=loc->next;
96
+		else
97
+			(*loc_set)=loc->next;
98
+		shm_free( loc );
99
+	} else {
100
+		DBG("DEBUG:remove_location: no matching in loc_set for <%.*s>\n",
101
+			uri_len,uri_s);
102
+	}
103
+}
104
+
105
+
106
+
107
+static inline void empty_location_set(struct location **loc_set)
108
+{
109
+	struct location *loc;
110
+
111
+	while (*loc_set) {
112
+		loc = (*loc_set)->next;
113
+		shm_free(*loc_set);
114
+		*loc_set = loc;
115
+	}
116
+	*loc_set = 0;
117
+}
118
+
119
+
120
+#endif
121
+
122
+
... ...
@@ -1,18 +1,18 @@
1 1
 BIN=encrypt
2 2
 CC=gcc
3
-OPT=-Wall -O9
3
+OPT=-Wall -O9 -I/usr/include/libxml2
4 4
 EXT_OBJ=../../mysql/mysql.so ../cpl_parser.o ../cpl_db.o ../sub_list.o
5
-LIBS=-lxml
5
+LIBS=-lxml2
6 6
 
7 7
 
8 8
 
9 9
 
10 10
 all: $(BIN)
11 11
 
12
-$(BIN): $(EXT_OBJ) encrypt.o wraper.o
12
+$(BIN): encrypt.o wraper.o
13 13
 	$(CC) $(LIBS) $(EXT_OBJ) encrypt.o wraper.o -o $(BIN)
14 14
 
15
-encrypt.o: encrypt.c ../cpl_db.h ../cpl_parser.h Makefile
15
+encrypt.o: encrypt.c Makefile
16 16
 	$(CC) -c $(OPT) -o encrypt.o encrypt.c
17 17
 	
18 18
 wraper.o: wraper.c Makefile
... ...
@@ -32,33 +32,6 @@
32 32
 
33 33
 
34 34
 /**************************  VARIABLES ************************************/
35
-/*
36
- *
37
- * Copyright (C) 2001-2003 Fhg Fokus
38
- *
39
- * This file is part of ser, a free SIP server.
40
- *
41
- * ser is free software; you can redistribute it and/or modify
42
- * it under the terms of the GNU General Public License as published by
43
- * the Free Software Foundation; either version 2 of the License, or
44
- * (at your option) any later version
45
- *
46
- * For a license to use the ser software under conditions
47
- * other than those described here, or to purchase support for this
48
- * software, please contact iptel.org by e-mail at the following addresses:
49
- *    info@iptel.org
50
- *
51
- * ser is distributed in the hope that it will be useful,
52
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54
- * GNU General Public License for more details.
55
- *
56
- * You should have received a copy of the GNU General Public License 
57
- * along with this program; if not, write to the Free Software 
58
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
59
- */
60
-
61
-
62 35
 int   debug = 9;
63 36
 int   log_stderr = 1;
64 37
 char  *mem_block = 0;
... ...
@@ -68,6 +41,7 @@ char  *mem_block = 0;
68 41
 
69 42
 /**************************  MEMORY  ***********************************/
70 43
 struct fm_block{};
44
+struct qm_block{};
71 45
 
72