Browse code

- param "fifo_db_url" added in script - db_fifo interface updated to DB interface modifications.

Bogdan-Andrei Iancu authored on 26/10/2003 19:17:43
Showing 4 changed files
... ...
@@ -165,6 +165,7 @@ MEMLOG		"memlog"|"mem_log"
165 165
 SIP_WARNING sip_warning
166 166
 FIFO fifo
167 167
 FIFO_DIR  fifo_dir
168
+FIFO_DB_URL fifo_db_url
168 169
 FIFO_MODE fifo_mode
169 170
 SERVER_SIGNATURE server_signature
170 171
 REPLY_TO_VIA reply_to_via
... ...
@@ -335,6 +336,7 @@ EAT_ABLE	[\ \t\b\r]
335 336
 										return TLS_CA_LIST; }
336 337
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
337 338
 <INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
339
+<INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
338 340
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
339 341
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
340 342
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
... ...
@@ -190,6 +190,7 @@ static struct id_list* mk_listen_id(char*, int, int);
190 190
 %token FIFO
191 191
 %token FIFO_DIR
192 192
 %token FIFO_MODE
193
+%token FIFO_DB_URL
193 194
 %token SERVER_SIGNATURE
194 195
 %token REPLY_TO_VIA
195 196
 %token LOADMODULE
... ...
@@ -384,6 +385,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
384 385
 		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
385 386
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
386 387
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
388
+		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
389
+		| FIFO_DB_URL EQUAL error { yyerror("string value expected"); }
387 390
 		| USER EQUAL STRING     { user=$3; }
388 391
 		| USER EQUAL ID         { user=$3; }
389 392
 		| USER EQUAL error      { yyerror("string value expected"); }
... ...
@@ -149,18 +149,22 @@ error:
149 149
 }
150 150
 
151 151
 
152
-
152
+/* returns : -1 bad key list
153
+ *           -2 server error
154
+ *            1 success */
153 155
 int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
154 156
 {
155 157
 	str line;
156 158
 	char *key;
159
+	int ret;
157 160
 
158 161
 	*nr = 0;
162
+	ret = -1;
159 163
 
160 164
 	while(1) {
161 165
 		/* read a new line */
162 166
 		line.s = buf;
163
-		if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
167
+		if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || !line.len) {
164 168
 			LOG(L_ERR,"ERROR:get_keys: cannot read key name\n");
165 169
 			goto error;
166 170
 		}
... ...
@@ -175,6 +179,7 @@ int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
175 179
 			key = (char*)pkg_malloc(line.len+1);
176 180
 			if (key==0) {
177 181
 				LOG(L_ERR,"ERROR:get_key: no more pkg memory\n");
182
+				ret = -2;
178 183
 				goto error;
179 184
 			}
180 185
 			memcpy( key, line.s, line.len);
... ...
@@ -189,7 +194,7 @@ int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
189 194
 error:
190 195
 	for(;*nr;*nr--)
191 196
 		pkg_free( (void*)keys[*nr] );
192
-	return -1;
197
+	return ret;
193 198
 }
194 199
 
195 200
 
... ...
@@ -197,8 +202,8 @@ error:
197 202
 int db_fifo( FILE *fifo, char *response_file )
198 203
 {
199 204
 	static db_key_t keys1[MAX_ARRAY];
200
-	static db_op_t  ops1[MAX_ARRAY];
201
-	static db_val_t vals1[MAX_ARRAY];
205
+	//static db_op_t  ops1[MAX_ARRAY];
206
+	//static db_val_t vals1[MAX_ARRAY];
202 207
 	static db_key_t keys2[MAX_ARRAY];
203 208
 	static db_op_t  ops2[MAX_ARRAY];
204 209
 	static db_val_t vals2[MAX_ARRAY];
... ...
@@ -206,6 +211,7 @@ int db_fifo( FILE *fifo, char *response_file )
206 211
 	str   line;
207 212
 	int   db_cmd;
208 213
 	int   nr1, nr2;
214
+	int   ret;
209 215
 
210 216
 	/* first check the response file */
211 217
 	rpl = open_reply_pipe( response_file );
... ...
@@ -214,7 +220,8 @@ int db_fifo( FILE *fifo, char *response_file )
214 220
 
215 221
 	/* first name must be the real name of the DB operation */
216 222
 	line.s = buf;
217
-	if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
223
+	if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || line.len==0) {
224
+		fprintf( rpl, "DB command name expected\n");
218 225
 		LOG(L_ERR,"ERROR:db_fifo: cannot read fifo cmd name\n");
219 226
 		goto error;
220 227
 	}
... ...
@@ -234,6 +241,7 @@ int db_fifo( FILE *fifo, char *response_file )
234 241
 	&& !strncasecmp( line.s, UPDATE_STR, line.len)) {
235 242
 		db_cmd = UPDATE_CMD;
236 243
 	} else {
244
+		fprintf( rpl, "unknown DB command \"%.*s\"\n",line.len,line.s);
237 245
 		LOG(L_ERR,"ERROR:db_fifo: unknown command \"%.*s\"\n",
238 246
 			line.len,line.s);
239 247
 		goto error;
... ...
@@ -242,9 +250,18 @@ int db_fifo( FILE *fifo, char *response_file )
242 250
 
243 251
 	if (db_cmd==SELECT_CMD) {
244 252
 		/* read the colums to be fetched */
245
-		if ( get_keys( fifo, keys1, &nr1, MAX_ARRAY)==-1 )
253
+		ret = get_keys( fifo, keys1, &nr1, MAX_ARRAY);
254
+		if (ret==-1) {
255
+			fprintf( rpl, "Bad key list in SELECT DB command "
256
+				"(missing '.' at the end?)\n");
257
+			LOG(L_ERR,"ERROR:db_fifo: bad key list termination in SELECT cmd"
258
+				"(missing '.' at the end?)\n");
246 259
 			goto error;
247
-		if (nr1==0) {
260
+		} else if (ret==-2) {
261
+			fprintf( rpl, "Internal Server error\n");
262
+			goto error;
263
+		} else if (nr1==0) {
264
+			fprintf( rpl, "Empty key list found in SELECT DB command\n");
248 265
 			LOG(L_ERR,"ERROR:db_fifo: no keys specified in SELECT cmd\n");
249 266
 			goto error;
250 267
 		}
... ...
@@ -254,21 +271,23 @@ int db_fifo( FILE *fifo, char *response_file )
254 271
 
255 272
 	/* read the table name */
256 273
 	line.s = buf;
257
-	if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
274
+	if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || !line.len) {
275
+		fprintf( rpl, "Table name expected\n");
258 276
 		LOG(L_ERR,"ERROR:db_fifo: cannot read table name\n");
259 277
 		goto error;
260 278
 	}
261 279
 	trim_spaces(line);
262 280
 
263 281
 	/*read 'where' avps */
264
-	if (get_avps( fifo , keys1, ops1, vals1, &nr2, MAX_ARRAY)==-1)
265
-		goto error;
282
+	//if (get_avps( fifo , keys2, ops2, vals2, &nr2, MAX_ARRAY)==-1)
283
+	//	goto error;
266 284
 
267 285
 
268 286
 	if (db_cmd==SELECT_CMD) {
269 287
 		 
270 288
 	}
271 289
 
290
+	fclose(rpl);
272 291
 	return 0;
273 292
 error:
274 293
 	if (rpl) fclose(rpl);
... ...
@@ -102,6 +102,7 @@ extern unsigned int shm_mem_size;
102 102
 char extern *fifo; /* FIFO name */
103 103
 extern int fifo_mode;
104 104
 char extern *fifo_dir; /* dir. where  reply fifos are allowed */
105
+extern char *fifo_db_url;  /* db url used by db_fifo interface */
105 106
 
106 107
 /* moved to pt.h
107 108
 extern int *pids;