Browse code

more devel.

Bogdan-Andrei Iancu authored on 24/06/2003 14:28:32
Showing 12 changed files
... ...
@@ -40,22 +40,19 @@
40 40
 #include "../../str.h"
41 41
 #include "../../dprint.h"
42 42
 #include "../../error.h"
43
+#include "../../fifo_server.h"
43 44
 #include "../../parser/parse_uri.h"
44 45
 #include "../../parser/parse_from.h"
45 46
 #include "../../db/db.h"
46 47
 #include "cpl_run.h"
47 48
 #include "cpl_db.h"
49
+#include "cpl_loader.h"
48 50
 
49 51
 
50
-//char           *resp_buf;
51
-//char           *cpl_server = "127.0.0.1";
52
-//unsigned int   cpl_port = 18011;
53
-//unsigned int   resp_len;
54
-//unsigned int   resp_code;
55
-
56 52
 char *DB_URL       = 0;  /* database url */
57 53
 char *DB_TABLE     = 0;  /* */
58
-static db_con_t* db_hdl   = 0;
54
+char *dtd_file     = 0;
55
+db_con_t* db_hdl   = 0;   /* this should be static !!!!*/
59 56
 int  cache_timeout = 5;
60 57
 cmd_function sl_send_rpl = 0;
61 58
 
... ...
@@ -85,6 +82,7 @@ static cmd_export_t cmds[] = {
85 82
 static param_export_t params[] = {
86 83
 	{"cpl_db",        STR_PARAM, &DB_URL       },
87 84
 	{"cpl_table",     STR_PARAM, &DB_TABLE     },
85
+	{"cpl_dtd_file",  STR_PARAM, &dtd_file     },
88 86
 	{"cache_timeout", INT_PARAM, &cache_timeout},
89 87
 	{0, 0, 0}
90 88
 };
... ...
@@ -141,6 +139,11 @@ static int cpl_init(void)
141 139
 			"found empty\n");
142 140
 		goto error;
143 141
 	}
142
+	if (dtd_file==0) {
143
+		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_dtd_file\" "
144
+			"found empty\n");
145
+		goto error;
146
+	}
144 147
 
145 148
 	/* bind to the mysql module */
146 149
 	if (bind_dbmod()) {
... ...
@@ -152,11 +155,17 @@ static int cpl_init(void)
152 155
 	/* bind the sl_send_reply function */
153 156
 	sl_send_rpl = find_export("sl_send_reply", 2, REQUEST_ROUTE);
154 157
 	if (sl_send_rpl==0) {
155
-		LOG(L_CRIT,"ERROR:cpl_init: connot find \"sl_send_reply\" function! "
158
+		LOG(L_CRIT,"ERROR:cpl_init: cannot find \"sl_send_reply\" function! "
156 159
 			"Did you forget to load the sl module ?\n");
157 160
 		goto error;
158 161
 	}
159 162
 
163
+	/* register the fifo command */
164
+	if (register_fifo_cmd( cpl_loader, "LOAD_CPL", 0)!=1) {
165
+		LOG(L_CRIT,"ERROR:cpl_init: cannot register fifo command!\n");
166
+		goto error;
167
+	}
168
+
160 169
 	return 0;
161 170
 error:
162 171
 	return -1;
... ...
@@ -166,10 +175,9 @@ error:
166 175
 
167 176
 static int cpl_child_init(int rank)
168 177
 {
169
-	//int  i, foo;
170
-
171
-	/* only the child 1 will execut this
172
-	if (rank != 1) goto done; */
178
+	/* don't do anything for main process and TCP manager process */
179
+	if (rank==PROC_MAIN || rank==PROC_TCP_MAIN)
180
+		return 0;
173 181
 
174 182
 	if ( (db_hdl=db_init(DB_URL))==0 ) {
175 183
 		LOG(L_CRIT,"ERROR:cpl_child_init: cannot initialize database "
... ...
@@ -31,14 +31,10 @@
31 31
 #include "cpl_db.h"
32 32
 
33 33
 
34
-char *DB_URL;
35
-char *DB_TABLE;
36
-
37
-
38 34
 
39 35
 int get_user_script( db_con_t *db_hdl, str *user, str *script)
40 36
 {
41
-	db_key_t   keys_cmp[] = {"username"};
37
+	db_key_t   keys_cmp[] = {"user"};
42 38
 	db_key_t   keys_ret[] = {"cpl_bin"};
43 39
 	db_val_t   vals[1];
44 40
 	db_res_t   *res = 0 ;
... ...
@@ -95,29 +91,12 @@ error:
95 91
 
96 92
 
97 93
 
98
-
99
-
100
-int write_to_db( char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len)
94
+int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin)
101 95
 {
102
-#if 0
103
-	db_key_t   keys[] = {"username","cpl","status","cpl_bin"};
104
-	db_val_t   vals[4];
105
-	db_con_t   *db_con;
96
+	db_key_t   keys[] = {"user","cpl_xml","cpl_bin"};
97
+	db_val_t   vals[3];
106 98
 	db_res_t   *res;
107 99
 
108
-	/* open connexion to db */
109
-	db_con = db_init(DB_URL);
110
-	if (!db_con) {
111
-		LOG(L_ERR,"ERROR:cpl:write_to_db: cannot connect to mysql db.\n");
112
-		goto error;
113
-	}
114
-
115
-	/* set the table */
116
-	if (use_table(db_con, DB_TABLE)<0) {
117
-		LOG(L_ERR,"ERROR:cpl:write_to_db: db_use_table failed\n");
118
-		goto error;
119
-	}
120
-
121 100
 	/* lets see if the user is already in database */
122 101
 	vals[0].type = DB_STRING;
123 102
 	vals[0].nul  = 0;
... ...
@@ -139,36 +118,32 @@ int write_to_db( char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len)
139 118
 	/* cpl text */
140 119
 	vals[1].type = DB_BLOB;
141 120
 	vals[1].nul  = 0;
142
-	vals[1].val.blob_val.s = xml_s;
143
-	vals[1].val.blob_val.len = xml_len;
144
-	/* status */
145
-	vals[2].type = DB_INT;
146
-	vals[2].nul  = 0;
147
-	vals[2].val.int_val = 1;
121
+	vals[1].val.blob_val.s = xml->s;
122
+	vals[1].val.blob_val.len = xml->len;
148 123
 	/* cpl bin */
149
-	vals[3].type = DB_BLOB;
150
-	vals[3].nul  = 0;
151
-	vals[3].val.blob_val.s = bin_s;
152
-	vals[3].val.blob_val.len = bin_len;
124
+	vals[2].type = DB_BLOB;
125
+	vals[2].nul  = 0;
126
+	vals[2].val.blob_val.s = bin->s;
127
+	vals[2].val.blob_val.len = bin->len;
153 128
 	/* insert or update ? */
154 129
 	if (res->n==0) {
155 130
 		DBG("DEBUG:cpl:write_to_db:No user %s in CPL databse->insert\n",usr);
156
-		if (db_insert(db_con, keys, vals, 4) < 0) {
131
+		if (db_insert(db_con, keys, vals, 3) < 0) {
157 132
 			LOG(L_ERR,"ERROR:cpl:write_to_db: insert failed !\n");
158 133
 			goto error;
159 134
 		}
160 135
 	} else {
161 136
 		DBG("DEBUG:cpl:write_to_db:User %s already in CPL database ->"
162 137
 			" update\n",usr);
163
-		if (db_update(db_con, keys, 0, vals, keys+1, vals+1, 1, 3) < 0) {
138
+		if (db_update(db_con, keys, 0, vals, keys+1, vals+1, 1, 2) < 0) {
164 139
 			LOG(L_ERR,"ERROR:cpl:write_to_db: updare failed !\n");
165 140
 			goto error;
166 141
 		}
167 142
 	}
168 143
 
169
-	return 0;
144
+	return 1;
170 145
 error:
171
-#endif
172 146
 	return -1;
173 147
 }
174 148
 
149
+
... ...
@@ -28,8 +28,11 @@
28 28
 #ifndef _CPL_DB_H
29 29
 #define _CPL_DB_H
30 30
 
31
+#include "../../db/db.h"
31 32
 
32
-int write_to_db(char *usr, char *bin_s, int bin_len, char *xml_s, int xml_len);
33
+
34
+int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin);
33 35
 int get_user_script( db_con_t *db_hdl, str *user, str *script);
34 36
 
37
+
35 38
 #endif
36 39
new file mode 100644
... ...
@@ -0,0 +1,207 @@
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
+ * History:
29
+ * -------
30
+ * 2003-06-24: file created (bogdan)
31
+ */
32
+
33
+
34
+#include <stdio.h>
35
+#include <stdlib.h>
36
+#include <unistd.h>
37
+#include <sys/types.h>
38
+#include <sys/stat.h>
39
+#include <fcntl.h>
40
+#include <errno.h>
41
+#include <string.h>
42
+#include "../../str.h"
43
+#include "../../dprint.h"
44
+#include "../../fifo_server.h"
45
+#include "../../mem/mem.h"
46
+#include "cpl_db.h"
47
+#include "cpl_parser.h"
48
+#include "cpl_loader.h"
49
+
50
+
51
+#define MAX_STAIC_BUF 256
52
+
53
+extern char *dtd_file;
54
+extern db_con_t* db_hdl;
55
+
56
+int write_to_file(char *filename, str *buf)
57
+{
58
+	int fd;
59
+	int ret;
60
+
61
+	fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0644);
62
+	if (!fd) {
63
+		LOG(L_ERR,"ERROR:cpl-c:write_to_file: cannot open file : %s\n",
64
+			strerror(errno));
65
+		goto error;
66
+	}
67
+
68
+	while ( (ret=write( fd, buf->s, buf->len))!=buf->len) {
69
+		if ((ret==-1 && errno!=EINTR)|| ret!=-1) {
70
+			LOG(L_ERR,"ERROR:cpl-c:write_to_file:cannot write to file:"
71
+				"%s write_ret=%d\n",strerror(errno), ret );
72
+			goto error;
73
+		}
74
+	}
75
+	close(fd);
76
+
77
+	return 0;
78
+error:
79
+	return -1;
80
+}
81
+
82
+
83
+
84
+
85
+int load_file( char *filename, str *xml)
86
+{
87
+	int n;
88
+	int offset;
89
+	int fd;
90
+
91
+	xml->s = 0;
92
+	xml->len = 0;
93
+
94
+	/* open the file for reading */
95
+	fd = open(filename,O_RDONLY);
96
+	if (fd==-1) {
97
+		LOG(L_ERR,"ERROR:cpl-c:load_file: cannot open file for reading:"
98
+			" %s\n",strerror(errno));
99
+		goto error;
100
+	}
101
+
102
+	/* get the file length */
103
+	if ( (xml->len=lseek(fd,0,SEEK_END))==-1) {
104
+		LOG(L_ERR,"ERROR:cpl-c:load_file: cannot get file length (lseek):"
105
+			" %s\n", strerror(errno));
106
+		goto error;
107
+	}
108
+	DBG("DEBUG:cpl-c:load_file: file size = %d\n",xml->len);
109
+	if ( lseek(fd,0,SEEK_SET)==-1 ) {
110
+		LOG(L_ERR,"ERROR:cpl-c:load_file: cannot go to begining (lseek):"
111
+			" %s\n",strerror(errno));
112
+		goto error;
113
+	}
114
+
115
+	/* get some memory */
116
+	xml->s = (char*)pkg_malloc( xml->len);
117
+	if (!xml->s) {
118
+		LOG(L_ERR,"ERROR:cpl-c:load_file: no more free pkg memory\n");
119
+		goto error;
120
+	}
121
+
122
+	/*start reading */
123
+	offset = 0;
124
+	while ( offset<xml->len ) {
125
+		n=read( fd, xml->s+offset, xml->len-offset);
126
+		if (n==-1) {
127
+			if (errno!=EINTR) {
128
+				LOG(L_ERR,"ERROR:cpl-c:load_file: read failed:"
129
+					" %s\n", strerror(errno));
130
+				goto error;
131
+			}
132
+		} else {
133
+			if (n==0) break;
134
+			offset += n;
135
+		}
136
+	}
137
+	if (xml->len!=offset) {
138
+		LOG(L_ERR,"ERROR:cpl:load_file: couldn't read all file!\n");
139
+		goto error;
140
+	}
141
+
142
+	return 1;
143
+error:
144
+	if (xml->s) pkg_free( xml->s);
145
+	return -1;
146
+}
147
+
148
+
149
+
150
+
151
+
152
+
153
+int cpl_loader( FILE *fifo_stream, char *response_file )
154
+{
155
+	static char user[MAX_STAIC_BUF];
156
+	static char cpl_file[MAX_STAIC_BUF];
157
+	int user_len;
158
+	int cpl_file_len;
159
+	str xml;
160
+	str bin;
161
+
162
+	DBG("DEBUG:cpl_loader: FIFO commnad received!\n");
163
+
164
+	/* first line must be the username */
165
+	if (read_line( user, MAX_STAIC_BUF-1 , fifo_stream, &user_len )!=1 ||
166
+	user_len<=0) {
167
+		LOG(L_ERR,"ERROR:cpl:cpl_loader: unable to read username from "
168
+			"FIFO command\n");
169
+		goto error;
170
+	}
171
+	user[user_len] = 0;
172
+	DBG("DEBUG:cpl_loader: user=%.*s\n",user_len,user);
173
+
174
+	/* second line must be the cpl file */
175
+	if (read_line( cpl_file, MAX_STAIC_BUF-1, fifo_stream, &cpl_file_len)!=1 ||
176
+	cpl_file_len<=0) {
177
+		LOG(L_ERR,"ERROR:cpl:cpl_loader: unable to read cpl_file name from "
178
+			"FIFO command\n");
179
+		goto error;
180
+	}
181
+	cpl_file[cpl_file_len] = 0;
182
+	DBG("DEBUG:cpl_loader: cpl file=%.*s\n",cpl_file_len,cpl_file);
183
+
184
+	/* load the xml file */
185
+	if (load_file( cpl_file, &xml)!=1)
186
+		return -1;
187
+
188
+	/* get the binary coding for the XML file */
189
+	if ( encodeXML( &xml, dtd_file , &bin)!=1)
190
+		return -1;
191
+
192
+	/* write both the XML and binary formats into database */
193
+	if (write_to_db( db_hdl, user, &xml, &bin)!=1)
194
+		return -1;
195
+
196
+	/* free the memory used for storing the cpl script in XML format */
197
+	pkg_free( xml.s );
198
+
199
+	//write_to_file("cript.ccc", bin.s, bin.len);
200
+
201
+	return 1;
202
+error:
203
+	return -1;
204
+}
205
+
206
+#undef MAX_STATIC_BUF
207
+
0 208
new file mode 100644
... ...
@@ -0,0 +1,44 @@
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
+ * History:
29
+ * -------
30
+ * 2003-06-24: file created (bogdan)
31
+ */
32
+
33
+#ifndef _CPL_LOADER_H
34
+#define _CPL_LOADER_H
35
+
36
+
37
+int cpl_loader( FILE *fifo_stream, char *response_file );
38
+
39
+#endif
40
+
41
+
42
+
43
+
44
+
... ...
@@ -38,6 +38,7 @@
38 38
 #include "CPL_tree.h"
39 39
 #include "sub_list.h"
40 40
 #include "../../dprint.h"
41
+#include "../../str.h"
41 42
 
42 43
 
43 44
 
... ...
@@ -702,10 +703,9 @@ int encrypt_node( xmlNodePtr node, unsigned char *p)
702 703
 
703 704
 
704 705
 
705
-char* encryptXML( char* xml_s, int xml_len, char* DTD_filename, int *bin_len)
706
+int encodeXML( str *xml, char* DTD_filename, str *bin)
706 707
 {
707 708
 	static unsigned char buf[2048];
708
-	int  len;
709 709
 	xmlValidCtxt  cvp;
710 710
 	xmlDocPtr  doc;
711 711
 	xmlNodePtr cur;
... ...
@@ -716,8 +716,8 @@ char* encryptXML( char* xml_s, int xml_len, char* DTD_filename, int *bin_len)
716 716
 	dtd  = 0;
717 717
 
718 718
 	/* parse the xml */
719
-	xml_s[xml_len] = 0;
720
-	doc = xmlParseDoc( xml_s );
719
+	xml->s[xml->len] = 0;
720
+	doc = xmlParseDoc( xml->s );
721 721
 	if (!doc) {
722 722
 		LOG(L_ERR,"ERROR:cpl:encryptXML:CPL script not parsed successfully\n");
723 723
 		goto error;
... ...
@@ -746,8 +746,8 @@ char* encryptXML( char* xml_s, int xml_len, char* DTD_filename, int *bin_len)
746 746
 		goto error;
747 747
 	}
748 748
 
749
-	len = encrypt_node( cur, buf);
750
-	if (len<0) {
749
+	bin->len = encrypt_node( cur, buf);
750
+	if (bin->len<0) {
751 751
 		LOG(L_ERR,"ERROR:cpl:encryptXML: zero lenght return by encripting"
752 752
 			" function\n");
753 753
 		goto error;
... ...
@@ -756,8 +756,8 @@ char* encryptXML( char* xml_s, int xml_len, char* DTD_filename, int *bin_len)
756 756
 
757 757
 	if (doc) xmlFreeDoc(doc);
758 758
 	if (list) delete_list(list);
759
-	if (bin_len) *bin_len = len;
760
-	return buf;
759
+	bin->s = buf;
760
+	return 1;
761 761
 error:
762 762
 	if (doc) xmlFreeDoc(doc);
763 763
 	if (list) delete_list(list);
... ...
@@ -28,7 +28,9 @@
28 28
 #ifndef _CPL_PARSER_H
29 29
 #define _CPL_PARSER_H
30 30
 
31
-char* encryptXML(char* xml, int xml_len, char* DTD_filename, int *bin_len);
31
+#include "../../str.h"
32
+
33
+int encodeXML(str *xml, char* DTD_filename, str *bin);
32 34
 
33 35
 
34 36
 #endif
... ...
@@ -48,6 +48,19 @@
48 48
 #define HDR_NOT_FOUND        ((char*)0xffffffff)
49 49
 #define UNDEF_CHAR           (0xff)
50 50
 
51
+#define check_overflow_by_ptr(_ptr_,_intr_,_error_) \
52
+	do {\
53
+		if ( (char*)(_ptr_)>(_intr_)->script.len+(_intr_)->script.s ) \
54
+			goto _error_; \
55
+	}while(0)
56
+
57
+#define check_overflow_by_offset(_len_,_intr_,_error_) \
58
+	do {\
59
+		if ( (char*)((_intr_)->ip+(_len_)) > \
60
+		(_intr_)->script.len+(_intr_)->script.s ) \
61
+			goto _error_; \
62
+	}while(0)
63
+
51 64
 
52 65
 extern int (*sl_send_rpl)(struct sip_msg*, char*, char*);
53 66
 
... ...
@@ -65,7 +78,7 @@ struct cpl_interpreter* build_cpl_interpreter( struct sip_msg *msg,
65 78
 	}
66 79
 	memset( intr, 0, sizeof(struct cpl_interpreter));
67 80
 
68
-	/* unut the interpreter*/
81
+	/* init the interpreter*/
69 82
 	intr->script.s = script->s;
70 83
 	intr->script.len = script->len;
71 84
 	intr->recv_time = time(0);
... ...
@@ -575,6 +588,7 @@ error:
575 588
 int run_cpl_script( struct cpl_interpreter *intr )
576 589
 {
577 590
 	do {
591
+		check_overflow_by_offset( SIMPLE_NODE_SIZE(intr->ip), intr, error);
578 592
 		switch ( NODE_TYPE(intr->ip) ) {
579 593
 			case CPL_NODE:
580 594
 				DBG("DEBUG:run_cpl_script:processing CPL node \n");
581 595
deleted file mode 100644
... ...
@@ -1,23 +0,0 @@
1
-BIN=encrypt
2
-CC=gcc
3
-OPT=-Wall -O9 -I/usr/include/libxml2
4
-EXT_OBJ=../../mysql/mysql.so ../cpl_parser.o ../cpl_db.o ../sub_list.o
5
-LIBS=-lxml2
6
-
7
-
8
-
9
-
10
-all: $(BIN)
11
-
12
-$(BIN): encrypt.o wraper.o
13
-	$(CC) $(LIBS) $(EXT_OBJ) encrypt.o wraper.o -o $(BIN)
14
-
15
-encrypt.o: encrypt.c Makefile
16
-	$(CC) -c $(OPT) -o encrypt.o encrypt.c
17
-	
18
-wraper.o: wraper.c Makefile
19
-	$(CC) -c $(OPT) -o wraper.o wraper.c
20
-
21
-clean:
22
-	rm -f *.o
23
-	rm -f $(BIN)
24 0
deleted file mode 100644
... ...
@@ -1,117 +0,0 @@
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
-#include "stdio.h"
30
-#include "stdlib.h"
31
-#include <unistd.h>
32
-#include <sys/types.h>
33
-#include <sys/stat.h>
34
-#include <fcntl.h>
35
-#include <errno.h>
36
-#include <string.h>
37
-#include "../cpl_db.h"
38
-#include "../cpl_parser.h"
39
-
40
-char *DB_URL = "sql://cpl:47cpl11@fox.iptel.org/jcidb";
41
-char *DB_TABLE = "user";
42
-
43
-
44
-int write_to_file(char *filename, char *s, int len)
45
-{
46
-	int fd;
47
-
48
-	fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0644);
49
-	if (!fd) {
50
-		printf("ERROR: cannot open file : %s",strerror(errno));
51
-		goto error;
52
-	}
53
-
54
-	if (write( fd, s, len)!=len) {
55
-		printf("ERROR: cannot write to file : %s",strerror(errno));
56
-		goto error;
57
-	}
58
-	close(fd);
59
-
60
-	return 0;
61
-error:
62
-	return -1;
63
-}
64
-
65
-
66
-
67
-
68
-unsigned char* load_file( char *filename, unsigned int *l)
69
-{
70
-	static char buf[4096];
71
-	unsigned int len;
72
-	int n;
73
-	int fd;
74
-
75
-	fd = open(filename,O_RDONLY);
76
-	if (!fd) {
77
-		printf("ERROR: cannot open file for reading: %s",strerror(errno));
78
-		goto error;
79
-	}
80
-
81
-	len = 0;
82
-	while ( (n=read(fd, buf+len, 256))>0 )
83
-		len += n;
84
-
85
-	if (l) *l=len;
86
-	return buf;
87
-error:
88
-	return 0;
89
-}
90
-
91
-
92
-
93
-
94
-int main(int argc, char **argv)
95
-{
96
-	unsigned char *buf_txt;
97
-	unsigned int  len_txt;
98
-	unsigned char *buf_bin;
99
-	unsigned int  len_bin;
100
-
101
-	if (argc <= 3) {
102
-		printf("Usage: %s user_name cpl_file dtd_file\n", argv[0]);
103
-		return(0);
104
-	}
105
-
106
-	if ((buf_txt=load_file(argv[2], &len_txt))==0)
107
-		return -1;
108
-
109
-	if ((buf_bin=encryptXML(buf_txt, len_txt, argv[3], &len_bin))==0)
110
-		return -1;
111
-
112
-	if (write_to_db( argv[1], buf_bin, len_bin, buf_txt, len_txt)==-1)
113
-		return -1;
114
-	write_to_file("cript.ccc", buf_bin, len_bin);
115
-
116
-	return 0;
117
-}
118 0
deleted file mode 100644
... ...
@@ -1,24 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-
3
-<!DOCTYPE cpl PUBLIC '-//IETF//DTD RFCxxxx CPL 1.0//EN' 'cpl.dtd'>
4
-
5
-<cpl>
6
-  <incoming>
7
-    <address-switch field="origin" subfield="user">
8
-      <address is="sisalem">
9
-        <reject status="603" reason="I am very busy!"/>
10
-      </address>
11
-      <address is="P1111">
12
-        <location url="sip:sisalem@iptel.org" priority="1.0" clear="no">
13
-          <redirect permanent="no" />
14
-        </location>
15
-      </address>
16
-      <otherwise>	
17
-        <location url="sip:test@mail.iptel.org" priority="1.0" clear="no">
18
-          <redirect permanent="no" />
19
-        </location>
20
-      </otherwise>
21
-    </address-switch>
22
-  </incoming>
23
-</cpl>
24
-
25 0
deleted file mode 100644
... ...
@@ -1,97 +0,0 @@
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 <stdlib.h>
29
-#include <stdarg.h>
30
-#include <stdio.h>
31
-
32
-
33
-
34
-/**************************  VARIABLES ************************************/
35
-int   debug = 9;
36
-int   log_stderr = 1;
37
-char  *mem_block = 0;
38
-
39
-
40
-
41
-
42
-/**************************  MEMORY  ***********************************/
43
-struct fm_block{};
44
-struct qm_block{};
45
-
46
-#ifdef DBG_F_MALLOC
47
-void* fm_malloc(struct fm_block* bl,unsigned int size,char* file, char* func,
48
-					unsigned int line)
49
-{
50
-	return malloc(size);
51
-}
52
-#else
53
-void* fm_malloc(struct fm_block* bl, unsigned int size)
54
-{
55
-	return malloc(size);
56
-}
57
-#endif
58
-
59
-
60
-#ifdef DBG_F_MALLOC
61
-void  fm_free(struct fm_block *bl, void* p, char* file, char* func, 
62
-				unsigned int line)
63
-{
64
-	free(p);
65
-}
66
-#else
67
-void  fm_free(struct fm_block* bl, void* p)
68
-{
69
-	free(p);
70
-}
71
-#endif
72
-
73
-
74
-void* qm_malloc(struct qm_block* qm, unsigned int size)
75
-{
76
-	return malloc(size);
77
-}
78
-
79
-void qm_free(struct qm_block* qm, void* p)
80
-{
81
-	free(p);
82
-}
83
-
84
-
85
-/****************************  DEBUG  *************************************/
86
-
87
-void dprint(char * format, ...)
88
-{
89
-	va_list ap;
90
-
91
-	va_start(ap, format);
92
-	vfprintf(stderr,format,ap);
93
-	fflush(stderr);
94
-	va_end(ap);
95
-}
96
-
97
-