1
0
Переглянути джерело

Attempt to support quoted params in konfd.

git-svn-id: https://klish.googlecode.com/svn/trunk@195 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 14 роки тому
батько
коміт
ef4b5bcd86
4 змінених файлів з 46 додано та 4 видалено
  1. 1 2
      bin/konfd.c
  2. 9 1
      clish/variable/variable_expand.c
  3. 20 1
      lub/argv/argv_new.c
  4. 16 0
      lub/argv/argv_nextword.c

+ 1 - 2
bin/konfd.c

@@ -203,8 +203,7 @@ static char * process_query(int sock, konf_tree_t * conf, char *str)
 #ifdef DEBUG
 	fprintf(stderr, "----------------------\n");
 	fprintf(stderr, "REQUEST: %s\n", str);
-/*	konf_query_dump(query);
-*/
+	konf_query_dump(query);
 #endif
 
 	/* Go through the pwd */

+ 9 - 1
clish/variable/variable_expand.c

@@ -299,13 +299,21 @@ char *clish_variable__get_params(const clish_command_t * cmd, clish_pargv_t * pa
 
 	cnt = clish_pargv__get_count(pargv);
 	for (i = 0; i < cnt; i++) {
+		const char *tmp;
+		char *space = NULL;
 		param = clish_pargv__get_param(pargv, i);
 		if (clish_param__get_hidden(param))
 			continue;
 		parg = clish_pargv__get_parg(pargv, i);
+		tmp = clish_parg__get_value(parg);
+		space = strchr(tmp, ' ');
 		if (NULL != line)
 			lub_string_cat(&line, " ");
-		lub_string_cat(&line, clish_parg__get_value(parg));
+		if (space)
+			lub_string_cat(&line, "\\\"");
+		lub_string_cat(&line, tmp);
+		if (space)
+			lub_string_cat(&line, "\\\"");
 	}
 
 	return line;

+ 20 - 1
lub/argv/argv_new.c

@@ -5,6 +5,23 @@
 #include "lub/string.h"
 
 #include <stdlib.h>
+#include <string.h>
+
+/*--------------------------------------------------------- */
+static char * unescape_special_chars(const char *str)
+{
+    char *res = NULL;
+    char *s = NULL;
+
+    for (s = strchr(str, '\\'); s; s = strchr(str, '\\')) {
+        lub_string_catn(&res, str, s - str);
+        str = s + 1;
+    }
+    lub_string_cat(&res, str);
+
+    return res;
+}
+
 /*--------------------------------------------------------- */
 static void
 lub_argv_init(lub_argv_t *this,
@@ -29,7 +46,9 @@ lub_argv_init(lub_argv_t *this,
             *word;
             word = lub_argv_nextword(word+len,&len,&offset,&quoted))
         {
-            (*arg).arg    = lub_string_dupn(word,len);
+            char * tmp = lub_string_dupn(word,len);
+            (*arg).arg = unescape_special_chars(tmp);
+            lub_string_free(tmp);
             (*arg).offset = offset;
             (*arg).quoted = quoted;
 

+ 16 - 0
lub/argv/argv_nextword.c

@@ -24,6 +24,12 @@ lub_argv_nextword(const char *string,
         string++;
         (*offset)++;
     }
+    if(*string == '\\')
+    {
+        string++;
+        if (*string)
+            string++;
+    }
     /* is this the start of a quoted string ? */
     if(*string == '"')
     {
@@ -36,6 +42,16 @@ lub_argv_nextword(const char *string,
     /* find the end of the word */
     while(*string)
     {
+        if(*string == '\\')
+        {
+            string++;
+            (*len)++;
+            if (*string) {
+                (*len)++;
+                string++;
+            }
+            continue;
+        }
         if((BOOL_FALSE == quote) && lub_ctype_isspace(*string))
         {
             /* end of word */