diff --git a/mediachanger/castorrmc/common/getconfent.c b/mediachanger/castorrmc/common/getconfent.c index 7ba74ca0ab00ce9e28867db488caea57729a7de6..eb38dc6f95d48e2ecd38b3a5b23d709ebea8428d 100644 --- a/mediachanger/castorrmc/common/getconfent.c +++ b/mediachanger/castorrmc/common/getconfent.c @@ -1,142 +1,98 @@ -/* - * Copyright (C) 1991-1997 by CERN CN-PDP/CS - * All rights reserved - */ - -#ifndef lint -static char sccsid[] = "@(#)getconfent.c 1.11 08/19/97 CERN CN-PDP/CS F. Hemmer"; -#endif /* not lint */ - -/* getconfent.c - get configuration entry */ +#include <stdio.h> +#include <string.h> +#include <Cglobals.h> +#include <serrno.h> #ifndef PATH_CONFIG -#if !defined(vms) #if defined(_WIN32) #define PATH_CONFIG "%SystemRoot%\\system32\\drivers\\etc\\shift.conf" #else #define PATH_CONFIG "/etc/shift.conf" #endif -#else /* vms */ -#define PATH_CONFIG "SYS$MANAGER:shift.conf" -#endif /* vms */ #endif /* PATH_CONFIG */ -#include <stdio.h> /* Standard input/output */ -#include <ctype.h> /* Character manipulation */ -#include <string.h> /* String handling functions */ -#ifndef vms -#include <serrno.h> /* Special Error numbers */ -#else -#include "serrno.h" /* Special Error numbers */ -#endif /* vms */ - -#if defined(vms) && defined(__alpha) && defined(COMPILE_NOPREFIX) -#define fclose DECC$FCLOSE -#define fgets DECC$FGETS -#define fopen DECC$FOPEN -#define getenv DECC$GETENV -#define strcmp DECC$STRCMP -#define strcpy DECC$STRCPY -#define strtok DECC$STRTOK -#endif /* vms && __alpha && COMPILE_NOPREFIX */ - -static char in_line[BUFSIZ+1]; +const char char_set[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+|~`\\=-{}[]:;''\",./<>?"; -extern char* getenv(); -static char value[BUFSIZ]; - -char * -getconfent(category, name, flags) -char *category; -char *name; -int flags; -{ - char *filename=PATH_CONFIG; - FILE *fp; - char *p, *cp; - int found = 0; - char path_config[256]; - char *separator; +char *getconfent_r(char *category, char *name, int flags, + char *buffer, int bufsiz) { + char *filename=PATH_CONFIG; + FILE *fp; + char *p, *cp, *ep; + char *getenv(); + int found = 0; + char path_config[256]; + char *separator; if ((p = getenv("PATH_CONFIG")) != NULL) { filename=p; } #if defined(_WIN32) - if (strncmp (filename, "%SystemRoot%\\", 13) == 0 && - (p = getenv ("SystemRoot"))) - sprintf (path_config, "%s\\%s", p, strchr (filename, '\\')); - else + if (strncmp (filename, "%SystemRoot%\\", 13) == 0 && + (p = getenv ("SystemRoot"))) + sprintf (path_config, "%s\\%s", p, strchr (filename, '\\')); + else #endif - strcpy (path_config, filename); + strcpy (path_config, filename); -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent(%s,%s,%d)\n", - category, name, flags); - log(LOG_DEBUG ,"getconfent: opening %s\n",path_config); -#endif /* DEBUG */ if ((fp = fopen(path_config,"r")) == NULL) { - serrno = SENOCONFIG; + serrno = SENOCONFIG; return (NULL); } for (;;) { - p = fgets(in_line, BUFSIZ, fp); + p = fgets(buffer, bufsiz-1, fp); if (p == NULL) { break; } -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: read <%s>",p); -#endif /* DEBUG */ - if (*p == '#') continue; -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: processing <%s>",p); -#endif /* DEBUG */ - if ((cp = strtok(p," \t")) == NULL) continue; /* empty line */ - if (*cp == '#') continue; /* comment */ - if (strcmp(cp, category) == 0) { /* a category match */ -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: category <%s>\n", cp); -#endif /* DEBUG */ - if ((cp = strtok(NULL," \t")) == NULL) continue; - if (*cp == '#') continue; /* comment, invalid */ - if (strcmp(cp, name) == 0) { /* A match */ -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: category <%s>, processing<%s>\n", - category, cp); -#endif /* DEBUG */ - if (flags) { - /* Don't tokenize next arg */ - separator = "#\n"; - } else { - /* Don't tokenize next arg */ - separator = "#\t \n"; - } - if ((cp = strtok(NULL, separator)) == NULL) continue; /* invalid format */ - if (*cp == '#') continue; /* comment, invalid */ -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: category <%s>, got<%s>\n", - category, cp); -#endif /* DEBUG */ - found++; - strcpy(value,cp); - break; - } - else { - continue; - } - } - else { - continue; - } - } -#ifdef DEBUG - log(LOG_DEBUG ,"getconfent: closing %s\n",path_config); -#endif /* DEBUG */ - if (fclose(fp)) return (NULL); - if (!found) { - return(NULL); - } - else { - return(value); - } + if (*p == '#') continue; + if ((cp = strpbrk(p,char_set)) == NULL) continue; + if (*cp == '#') continue; + if ((ep = strpbrk(cp," \t")) == NULL) ep = &cp[strlen(cp)]; + if ( *ep == '\n' ) continue; + *ep = '\0'; + if (strcmp(cp,category) == 0) { + p = &ep[1]; + if ((cp = strpbrk(p,char_set)) == NULL ) continue; + if (*cp == '#') continue; + if ((ep = strpbrk(cp," \t")) == NULL) ep = &cp[strlen(cp)]; + if ( *ep == '\n' ) continue; + *ep = '\0'; + if ( strcmp(cp,name) == 0) { + + if (flags != 0) { + separator = "#\n"; + } else { + separator = "#\t \n"; + } + p = &ep[1]; + if ((cp = strpbrk(p,char_set)) == NULL) continue; + if (*cp == '#') continue; + if ((ep = strpbrk(cp,separator)) == NULL) ep = &cp[strlen(cp)]; + *ep = '\0'; + found++; + break; + } + else { + continue; + } + } else { + continue; + } + } + if (fclose(fp)) return(NULL); + if (found == 0) return(NULL); + else return(cp); +} + +static int value_key = -1; + +char *getconfent(char *category, char *name, int flags) { + char *value = NULL; + + Cglobals_get(&value_key,&value,BUFSIZ+1); + if ( value == NULL ) { + return(NULL); + } + + return(getconfent_r(category,name,flags,value,BUFSIZ+1)); }