@@ -79,46 +79,57 @@ return(retval); } static int lc_process_conf_apache_file(const char *configfile, const char *pathprefix) { - FILE *configfp = NULL; + LC_FILE *configfp = NULL; + const char *local_lc_errfile; char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL, *tmp_ptr = NULL; char *lastsection = NULL; char qualifbuf[LC_LINEBUF_LEN] = {0}; char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL; char *fgetsret = NULL; int lcpvret = -1, lpcafret = -1; int invalid_section = 0, ignore_section = 0; + int local_lc_errline; int retval = 0; lc_err_t save_lc_errno = LC_ERR_NONE; if (pathprefix != NULL) { /* Copy the prefix, if specified. */ strncpy(qualifbuf, pathprefix, sizeof(qualifbuf) - 1); } + + local_lc_errfile = configfile; + local_lc_errline = 0; if (configfile == NULL) { + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_INVDATA; return(-1); } configfp = lc_fopen(configfile, "r"); if (configfp == NULL) { + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_CANTOPEN; return(-1); } while (1) { - fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp); + fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp); if (fgetsret == NULL) { break; } - if (feof(configfp)) { + if (lc_feof(configfp)) { break; } + + local_lc_errline++; /* Remove trailing crap (but not spaces). */ linebuf_ptr = &linebuf[strlen(linebuf) - 1]; while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) { *linebuf_ptr = '\0'; @@ -162,10 +173,12 @@ #ifdef DEBUG fprintf(stderr, "Section closing does not match last opened section.\n"); fprintf(stderr, "Last opened = \"%s\", Closing = \"%s\"\n", lastsection, cmd); #endif retval = -1; + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_BADFORMAT; /* For this error, we abort immediately. */ break; } @@ -230,10 +243,12 @@ if (lcpvret < 0) { #ifdef DEBUG fprintf(stderr, "Invalid section: \"%s\"\n", qualifbuf); #endif invalid_section = 1; + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_INVSECTION; retval = -1; } if (lcpvret == LC_CBRET_IGNORESECTION) { ignore_section = 1; @@ -286,10 +301,12 @@ cmd = linebuf_ptr; /* Handle special commands. */ if (strcasecmp(cmd, "include") == 0) { if (value == NULL) { + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_BADFORMAT; retval = -1; #ifdef DEBUG fprintf(stderr, "Invalid include command.\n"); #endif @@ -325,10 +342,12 @@ } else { #ifdef DEBUG fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n"); #endif } + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; retval = -1; } else { lc_errno = save_lc_errno; } @@ -338,13 +357,13 @@ tmp_ptr = qualifbuf; } *tmp_ptr = '\0'; } - fclose(configfp); + lc_fclose(configfp); return(retval); } int lc_process_conf_apache(const char *appname, const char *configfile) { return(lc_process_conf_apache_file(configfile, NULL)); }