瀏覽代碼

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

Bogdan-Andrei Iancu 22 年之前
父節點
當前提交
ed7856ed2b
共有 4 個文件被更改,包括 36 次插入11 次删除
  1. 2 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 30 11
      db/db_fifo.c
  4. 1 0
      globals.h

+ 2 - 0
cfg.lex

@@ -165,6 +165,7 @@ MEMLOG		"memlog"|"mem_log"
 SIP_WARNING sip_warning
 FIFO fifo
 FIFO_DIR  fifo_dir
+FIFO_DB_URL fifo_db_url
 FIFO_MODE fifo_mode
 SERVER_SIGNATURE server_signature
 REPLY_TO_VIA reply_to_via
@@ -335,6 +336,7 @@ EAT_ABLE	[\ \t\b\r]
 										return TLS_CA_LIST; }
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
 <INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
+<INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }

+ 3 - 0
cfg.y

@@ -190,6 +190,7 @@ static struct id_list* mk_listen_id(char*, int, int);
 %token FIFO
 %token FIFO_DIR
 %token FIFO_MODE
+%token FIFO_DB_URL
 %token SERVER_SIGNATURE
 %token REPLY_TO_VIA
 %token LOADMODULE
@@ -384,6 +385,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
+		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
+		| FIFO_DB_URL EQUAL error { yyerror("string value expected"); }
 		| USER EQUAL STRING     { user=$3; }
 		| USER EQUAL ID         { user=$3; }
 		| USER EQUAL error      { yyerror("string value expected"); }

+ 30 - 11
db/db_fifo.c

@@ -149,18 +149,22 @@ error:
 }
 
 
-
+/* returns : -1 bad key list
+ *           -2 server error
+ *            1 success */
 int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
 {
 	str line;
 	char *key;
+	int ret;
 
 	*nr = 0;
+	ret = -1;
 
 	while(1) {
 		/* read a new line */
 		line.s = buf;
-		if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
+		if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || !line.len) {
 			LOG(L_ERR,"ERROR:get_keys: cannot read key name\n");
 			goto error;
 		}
@@ -175,6 +179,7 @@ int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
 			key = (char*)pkg_malloc(line.len+1);
 			if (key==0) {
 				LOG(L_ERR,"ERROR:get_key: no more pkg memory\n");
+				ret = -2;
 				goto error;
 			}
 			memcpy( key, line.s, line.len);
@@ -189,7 +194,7 @@ int get_keys( FILE *fifo , db_key_t *keys, int *nr, int max_nr)
 error:
 	for(;*nr;*nr--)
 		pkg_free( (void*)keys[*nr] );
-	return -1;
+	return ret;
 }
 
 
@@ -197,8 +202,8 @@ error:
 int db_fifo( FILE *fifo, char *response_file )
 {
 	static db_key_t keys1[MAX_ARRAY];
-	static db_op_t  ops1[MAX_ARRAY];
-	static db_val_t vals1[MAX_ARRAY];
+	//static db_op_t  ops1[MAX_ARRAY];
+	//static db_val_t vals1[MAX_ARRAY];
 	static db_key_t keys2[MAX_ARRAY];
 	static db_op_t  ops2[MAX_ARRAY];
 	static db_val_t vals2[MAX_ARRAY];
@@ -206,6 +211,7 @@ int db_fifo( FILE *fifo, char *response_file )
 	str   line;
 	int   db_cmd;
 	int   nr1, nr2;
+	int   ret;
 
 	/* first check the response file */
 	rpl = open_reply_pipe( response_file );
@@ -214,7 +220,8 @@ int db_fifo( FILE *fifo, char *response_file )
 
 	/* first name must be the real name of the DB operation */
 	line.s = buf;
-	if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
+	if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || line.len==0) {
+		fprintf( rpl, "DB command name expected\n");
 		LOG(L_ERR,"ERROR:db_fifo: cannot read fifo cmd name\n");
 		goto error;
 	}
@@ -234,6 +241,7 @@ int db_fifo( FILE *fifo, char *response_file )
 	&& !strncasecmp( line.s, UPDATE_STR, line.len)) {
 		db_cmd = UPDATE_CMD;
 	} else {
+		fprintf( rpl, "unknown DB command \"%.*s\"\n",line.len,line.s);
 		LOG(L_ERR,"ERROR:db_fifo: unknown command \"%.*s\"\n",
 			line.len,line.s);
 		goto error;
@@ -242,9 +250,18 @@ int db_fifo( FILE *fifo, char *response_file )
 
 	if (db_cmd==SELECT_CMD) {
 		/* read the colums to be fetched */
-		if ( get_keys( fifo, keys1, &nr1, MAX_ARRAY)==-1 )
+		ret = get_keys( fifo, keys1, &nr1, MAX_ARRAY);
+		if (ret==-1) {
+			fprintf( rpl, "Bad key list in SELECT DB command "
+				"(missing '.' at the end?)\n");
+			LOG(L_ERR,"ERROR:db_fifo: bad key list termination in SELECT cmd"
+				"(missing '.' at the end?)\n");
 			goto error;
-		if (nr1==0) {
+		} else if (ret==-2) {
+			fprintf( rpl, "Internal Server error\n");
+			goto error;
+		} else if (nr1==0) {
+			fprintf( rpl, "Empty key list found in SELECT DB command\n");
 			LOG(L_ERR,"ERROR:db_fifo: no keys specified in SELECT cmd\n");
 			goto error;
 		}
@@ -254,21 +271,23 @@ int db_fifo( FILE *fifo, char *response_file )
 
 	/* read the table name */
 	line.s = buf;
-	if (read_line( line.s, MAX_SIZE_LINE, fifo, &line.len)!=1) {
+	if (!read_line( line.s, MAX_SIZE_LINE, fifo, &line.len) || !line.len) {
+		fprintf( rpl, "Table name expected\n");
 		LOG(L_ERR,"ERROR:db_fifo: cannot read table name\n");
 		goto error;
 	}
 	trim_spaces(line);
 
 	/*read 'where' avps */
-	if (get_avps( fifo , keys1, ops1, vals1, &nr2, MAX_ARRAY)==-1)
-		goto error;
+	//if (get_avps( fifo , keys2, ops2, vals2, &nr2, MAX_ARRAY)==-1)
+	//	goto error;
 
 
 	if (db_cmd==SELECT_CMD) {
 		 
 	}
 
+	fclose(rpl);
 	return 0;
 error:
 	if (rpl) fclose(rpl);

+ 1 - 0
globals.h

@@ -102,6 +102,7 @@ extern unsigned int shm_mem_size;
 char extern *fifo; /* FIFO name */
 extern int fifo_mode;
 char extern *fifo_dir; /* dir. where  reply fifos are allowed */
+extern char *fifo_db_url;  /* db url used by db_fifo interface */
 
 /* moved to pt.h
 extern int *pids;