Просмотр исходного кода

- Make equal-less parameters illegal
- parameters without argument after '=' are now assumed to be argument-less
- Add a testcase for space in stanza and various argument-less parameters


git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1948 f882894a-f735-0410-b71e-b25c423dba1c

Thomas Guyot-Sionnest 18 лет назад
Родитель
Сommit
1a0ed0d6bb
3 измененных файлов с 17 добавлено и 5 удалено
  1. 4 1
      lib/parse_ini.c
  2. 5 0
      lib/tests/plugin.ini
  3. 8 4
      lib/tests/test_ini.c

+ 4 - 1
lib/parse_ini.c

@@ -212,6 +212,7 @@ static int add_option(FILE *f, np_arg_list **optlst){
 		else optend=NULL;
 		else optend=NULL;
 	}
 	}
 	if(optend==NULL) optend=eqptr;
 	if(optend==NULL) optend=eqptr;
+//printf("o1: %c\n", *optptr[optend]);
 	--optend;
 	--optend;
 	/* ^[[:space:]]*=foo is a syntax error */
 	/* ^[[:space:]]*=foo is a syntax error */
 	if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n"));
 	if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n"));
@@ -242,6 +243,8 @@ static int add_option(FILE *f, np_arg_list **optlst){
 		equals=1;
 		equals=1;
 		cfg_len+=1;
 		cfg_len+=1;
 	}
 	}
+	/* A line with no equal sign isn't valid */
+	if(equals==0) die(STATE_UNKNOWN, _("Config file error\n"));
 
 
 	/* okay, now we have all the info we need, so we create a new np_arg_list
 	/* okay, now we have all the info we need, so we create a new np_arg_list
 	 * element and set the argument...
 	 * element and set the argument...
@@ -260,8 +263,8 @@ static int add_option(FILE *f, np_arg_list **optlst){
 		read_pos+=2;
 		read_pos+=2;
 	}
 	}
 	strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len;
 	strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len;
-	if(equals) optnew->arg[read_pos++]='=';
 	if(value) {
 	if(value) {
+		optnew->arg[read_pos++]='=';
 		strncpy(&optnew->arg[read_pos], valptr, val_len); read_pos+=val_len;
 		strncpy(&optnew->arg[read_pos], valptr, val_len); read_pos+=val_len;
 	}
 	}
 	optnew->arg[read_pos]='\0';
 	optnew->arg[read_pos]='\0';

+ 5 - 0
lib/tests/plugin.ini

@@ -7,4 +7,9 @@ password=secret		# Remember to change later
 u=admin
 u=admin
 p=secret
 p=secret
 
 
+[check space_and_flags]
+foo=bar
+a=
+b=
+bar=
 
 

+ 8 - 4
lib/tests/test_ini.c

@@ -52,18 +52,18 @@ main (int argc, char **argv)
 {
 {
 	char *optstr=NULL;
 	char *optstr=NULL;
 
 
-	plan_tests(9);
+	plan_tests(10);
 
 
 	optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
 	optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
-	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected");
+	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
 	my_free(optstr);
 	my_free(optstr);
 
 
 	optstr=list2str(np_get_defaults("@./config-tiny.ini", "section"));
 	optstr=list2str(np_get_defaults("@./config-tiny.ini", "section"));
-	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific");
+	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
 	my_free(optstr);
 	my_free(optstr);
 
 
 	optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
 	optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
-	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one");
+	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name over specified one");
 	my_free(optstr);
 	my_free(optstr);
 
 
 	optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
 	optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
@@ -90,6 +90,10 @@ main (int argc, char **argv)
 	ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
 	ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
 	my_free(optstr);
 	my_free(optstr);
 
 
+	optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk"));
+	ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
+	my_free(optstr);
+
 	return exit_status();
 	return exit_status();
 }
 }