X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=libatalk%2Finiparser%2Finiparser.c;h=343a6d063b5cbd5028934f05e5b63c9f7f567d9c;hp=8e58de6d3174742b2a9f82956971998611cb121b;hb=d7e5521f69859b3df89da09bf50621945f119d97;hpb=36672cafcc5582cd15ece6077b1a9fa74f59755f diff --git a/libatalk/iniparser/iniparser.c b/libatalk/iniparser/iniparser.c index 8e58de6d..343a6d06 100644 --- a/libatalk/iniparser/iniparser.c +++ b/libatalk/iniparser/iniparser.c @@ -1,4 +1,3 @@ - /*-------------------------------------------------------------------------*/ /** @file iniparser.c @@ -9,6 +8,10 @@ */ /*---------------------------- Includes ------------------------------------*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + #include #include @@ -35,9 +38,9 @@ typedef enum _line_status_ { /*-------------------------------------------------------------------------*/ /** - @brief Remove blanks at the beginning and the end of a string. - @param s String to parse. - @return ptr to statically allocated string. + @brief Remove blanks at the beginning and the end of a string. + @param s String to parse. + @return ptr to statically allocated string. This function returns a pointer to a statically allocated string, which is identical to the input string, except that all blank @@ -50,21 +53,21 @@ typedef enum _line_status_ { static char * strstrip(char * s) { static char l[ASCIILINESZ+1]; - char * last ; - + char * last ; + if (s==NULL) return NULL ; - - while (isspace((int)*s) && *s) s++; - memset(l, 0, ASCIILINESZ+1); - strcpy(l, s); - last = l + strlen(l); - while (last > l) { - if (!isspace((int)*(last-1))) - break ; - last -- ; - } - *last = (char)0; - return (char*)l ; + + while (isspace((int)*s) && *s) s++; + memset(l, 0, ASCIILINESZ+1); + strcpy(l, s); + last = l + strlen(l); + while (last > l) { + if (!isspace((int)*(last-1))) + break ; + last -- ; + } + *last = (char)0; + return (char*)l ; } /*-------------------------------------------------------------------------*/ @@ -85,7 +88,7 @@ static char * strstrip(char * s) This function returns -1 in case of error. */ /*--------------------------------------------------------------------------*/ -int iniparser_getnsec(const dictionary * d) +int atalk_iniparser_getnsec(const dictionary * d) { int i ; int nsec ; @@ -116,7 +119,7 @@ int iniparser_getnsec(const dictionary * d) This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ -const char * iniparser_getsecname(const dictionary * d, int n) +const char * atalk_iniparser_getsecname(const dictionary * d, int n) { int i ; int foundsec ; @@ -151,7 +154,7 @@ const char * iniparser_getsecname(const dictionary * d, int n) purposes mostly. */ /*--------------------------------------------------------------------------*/ -void iniparser_dump(const dictionary * d, FILE * f) +void atalk_iniparser_dump(const dictionary * d, FILE * f) { int i ; @@ -179,7 +182,7 @@ void iniparser_dump(const dictionary * d, FILE * f) It is Ok to specify @c stderr or @c stdout as output files. */ /*--------------------------------------------------------------------------*/ -void iniparser_dump_ini(const dictionary * d, FILE * f) +void atalk_iniparser_dump_ini(const dictionary * d, FILE * f) { int i, j ; char keym[ASCIILINESZ+1]; @@ -189,7 +192,7 @@ void iniparser_dump_ini(const dictionary * d, FILE * f) if (d==NULL || f==NULL) return ; - nsec = iniparser_getnsec(d); + nsec = atalk_iniparser_getnsec(d); if (nsec<1) { /* No section in file: dump all keys as they are */ for (i=0 ; isize ; i++) { @@ -200,7 +203,7 @@ void iniparser_dump_ini(const dictionary * d, FILE * f) return ; } for (i=0 ; i=0) && ((line[len]=='\n') || (isspace(line[len])))) { @@ -594,26 +587,32 @@ dictionary * iniparser_load(const char * ininame) } else { last=0 ; } - switch (iniparser_line(line, section, key, val)) { + switch (atalk_iniparser_line(line, section, key, val)) { case LINE_EMPTY: case LINE_COMMENT: break ; case LINE_SECTION: - errs = dictionary_set(dict, section, NULL, NULL); + if (strchr(section, ':') != NULL) + LOG(log_error, logtype_default, "iniparser: syntax error \"%s\" section name must not contain \":\".", section); + errs = atalkdict_set(dict, section, NULL, NULL); break ; case LINE_VALUE: if (strcmp(key, "include") == 0) { + errs = atalkdict_set(dict, section, key, val); + if (errs < 0) { + LOG(log_error, logtype_default, "iniparser: memory allocation failure"); + } if ((include = fopen(val, "r")) == NULL) { - LOG(logtype_default, log_error, "iniparser: cannot open \"%s\"", val); + LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", val); continue; } in = include; continue; } - errs = dictionary_set(dict, section, key, val) ; + errs = atalkdict_set(dict, section, key, val) ; break ; case LINE_ERROR: - LOG(logtype_default, log_error, "iniparser: syntax error in %s (lineno: %d): %s", + LOG(log_error, logtype_default, "iniparser: syntax error in %s (lineno: %d): %s", ininame, lineno, line); errs++ ; break; @@ -623,12 +622,12 @@ dictionary * iniparser_load(const char * ininame) memset(line, 0, ASCIILINESZ); last=0; if (errs<0) { - LOG(logtype_default, log_error, "iniparser: memory allocation failure"); + LOG(log_error, logtype_default, "iniparser: memory allocation failure"); break ; } } if (errs) { - dictionary_del(dict); + atalkdict_del(dict); dict = NULL ; } fclose(in); @@ -646,8 +645,8 @@ dictionary * iniparser_load(const char * ininame) gets out of the current context. */ /*--------------------------------------------------------------------------*/ -void iniparser_freedict(dictionary * d) +void atalk_iniparser_freedict(dictionary * d) { - dictionary_del(d); + atalkdict_del(d); }