20,11 → 20,8 |
#include "version.h" |
|
|
void freeconf(char **repolist, int repscount, struct customdirs **dirlist) { |
int x; |
void freeconf(struct customdirs **dirlist) { |
struct customdirs *curpos; |
/* free repolist */ |
for (x = 0; x < repscount; x++) free(repolist[x]); |
/* free the linked list of custom dirs */ |
while (*dirlist != NULL) { |
curpos = *dirlist; |
37,21 → 34,6 |
} |
|
|
static int checkfordoubledrepos(char **repolist, int repocount) { |
int x, y; |
for (x = 0; x < (repocount - 1); x++) { |
for (y = x + 1; y < repocount; y++) { |
if (strcmp(repolist[x], repolist[y]) == 0) { |
kitten_printf(7, 14, "Error: repository '%s' is listed twice!", repolist[x]); |
puts(""); |
return(-1); |
} |
} |
} |
return(0); |
} |
|
|
static int checkfordoubledirlist(struct customdirs *dirlist) { |
struct customdirs *curpos; |
for (; dirlist != NULL; dirlist = dirlist->next) { |
125,18 → 107,14 |
} |
|
|
int loadconf(char *cfgfile, char **repolist, int maxreps, unsigned long *crc32val, long *maxcachetime, struct customdirs **dirlist, int *flags, char **proxy, int *proxyport, char **mapdrv) { |
int loadconf(char *cfgfile, struct customdirs **dirlist, int *flags) { |
int bytebuff, parserstate = 0; |
FILE *fd; |
#define BUFFSIZE 1024 |
unsigned char *fbuff; |
#define maxtok 16 |
char token[maxtok]; |
#define maxval 1024 |
char value[maxval]; |
int curtok = 0, curval = 0, nline = 1; |
int repocount = 0; |
int buffread; |
|
fd = fopen(cfgfile, "r"); |
if (fd == NULL) { |
145,26 → 123,6 |
return(-1); |
} |
|
/* compute the CRC32 of the configuration file (if crc32val not NULL) */ |
if (crc32val != NULL) { |
fbuff = malloc(BUFFSIZE); |
if (fbuff == NULL) { |
fclose(fd); |
kitten_printf(2, 14, "Out of memory! (%s)", "fbuff malloc"); |
puts(""); |
puts(""); |
return(-1); |
} |
*crc32val = crc32_init(); |
while ((buffread = fread(fbuff, sizeof(char), BUFFSIZE, fd)) > 0) { |
if (buffread > 0) crc32_feed(crc32val, fbuff, buffread); |
} |
crc32_finish(crc32val); |
free(fbuff); |
} |
/* rewind the file, to start reading it again */ |
rewind(fd); |
|
/* read the config file line by line */ |
do { |
bytebuff = fgetc(fd); |
230,64 → 188,10 |
} |
/* Interpret the token/value pair now! */ |
/* printf("token='%s' ; value = '%s'\n", token, value); */ |
if (strcasecmp(token, "REPO") == 0) { /* Repository declaration */ |
if (maxreps == 0) { |
/* simply ignore if the app explicitely wishes to load no repositories */ |
} else if (repocount >= maxreps) { |
kitten_printf(7, 6, "Dropped a repository: too many configured (max=%d)", maxreps); |
puts(""); |
} else { |
char pathdelimchar; |
/* add a trailing path delimiter (slash or backslash) to the url if not there already */ |
if (detect_localpath(value) != 0) { |
pathdelimchar = '\\'; |
} else { |
pathdelimchar = '/'; |
} |
if ((value[curval - 1] != '/') && (value[curval - 1] != '\\')) { |
value[curval++] = pathdelimchar; |
value[curval] = 0; |
} |
/* copy the value into the repository list */ |
repolist[repocount] = strdup(value); |
if (repolist[repocount] == NULL) { |
kitten_printf(2, 14, "Out of memory! (%s)", "repolist malloc"); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
fclose(fd); |
return(-1); |
} |
repocount += 1; |
} |
} else if (strcasecmp(token, "MAPDRIVES") == 0) { |
*mapdrv = strdup(value); |
if ((*mapdrv != NULL) && strlen(*mapdrv) & 1) { |
free(*mapdrv); |
*mapdrv = NULL; |
} |
if (*mapdrv == NULL) *mapdrv = ""; |
} else if (strcasecmp(token, "MAXCACHETIME") == 0) { |
long tmpint = atol(value); |
if ((tmpint >= 0) && (tmpint < 1209600l)) { /* min 0s / max 2 weeks */ |
if (maxcachetime != NULL) *maxcachetime = tmpint; |
} else { |
kitten_printf(7, 10, "Warning: Ignored an illegal '%s' value at line #%d", "maxcachetime", nline); |
puts(""); |
} |
} else if (strcasecmp(token, "INSTALLSOURCES") == 0) { |
if (strcasecmp(token, "SKIPLINKS") == 0) { |
int tmpint = atoi(value); /* must be 0/1 */ |
if (tmpint == 0) { |
*flags |= PKGINST_NOSOURCE; |
} else if (tmpint == 1) { |
/* do nothing */ |
} else { |
kitten_printf(7, 10, "Warning: Ignored an illegal '%s' value at line #%d", "installsources", nline); |
puts(""); |
} |
} else if (strcasecmp(token, "SKIPLINKS") == 0) { |
int tmpint = atoi(value); /* must be 0/1 */ |
if (tmpint == 0) { |
/* do nothing */ |
} else if (tmpint == 1) { |
*flags |= PKGINST_SKIPLINKS; |
} else { |
294,21 → 198,6 |
kitten_printf(7, 10, "Warning: Ignored an illegal '%s' value at line #%d", "skiplinks", nline); |
puts(""); |
} |
} else if (strcasecmp(token, "HTTP_PROXY") == 0) { |
if (value[0] != 0) { |
if (proxy != NULL) *proxy = strdup(value); |
} else { |
kitten_printf(7, 10, "Warning: Ignored an illegal '%s' value at line #%d", "http_proxy", nline); |
puts(""); |
} |
} else if (strcasecmp(token, "HTTP_PROXYPORT") == 0) { |
int tmpint = atoi(value); |
if (tmpint != 0) { |
if (proxyport != NULL) *proxyport = tmpint; |
} else { |
kitten_printf(7, 10, "Warning: Ignored an illegal '%s' value at line #%d", "http_proxyport", nline); |
puts(""); |
} |
} else if (strcasecmp(token, "DIR") == 0) { /* custom repository entry */ |
char *argv[2], *evar, *evar_content, *realLocation; |
#define realLocation_len 512 |
321,7 → 210,7 |
if (realLocation == NULL) { |
kitten_printf(2, 14, "Out of memory! (%s)", "malloc realLocation"); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
freeconf(dirlist); |
fclose(fd); |
return(-1); |
} |
337,7 → 226,7 |
if (y + 1 > realLocation_len) { |
kitten_printf(7, 12, "Error: DIR path too long at line #%d", nline); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
freeconf(dirlist); |
free(realLocation); |
fclose(fd); |
return(-1); |
353,7 → 242,7 |
if (evar_content == NULL) { |
kitten_printf(7, 13, "Error: Found inexisting environnement variable '%s' at line #%d", evar, nline); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
freeconf(dirlist); |
free(realLocation); |
fclose(fd); |
return(-1); |
361,7 → 250,7 |
if (strlen(evar_content) + y + 1 > realLocation_len) { |
kitten_printf(7, 12, "Error: DIR path too long at line #%d", nline); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
freeconf(dirlist); |
free(realLocation); |
fclose(fd); |
return(-1); |
379,7 → 268,7 |
if (addnewdir(dirlist, argv[0], realLocation) != 0) { |
kitten_printf(2, 14, "Out of memory! (%s)", "addnewdir"); |
puts(""); |
freeconf(repolist, repocount, dirlist); |
freeconf(dirlist); |
free(realLocation); |
fclose(fd); |
return(-1); |
413,10 → 302,9 |
} while (bytebuff != EOF); |
fclose(fd); |
|
/* Look out for doubled repositories */ |
if (checkfordoubledrepos(repolist, repocount) != 0) return(-1); |
/* perform some validations */ |
if (checkfordoubledirlist(*dirlist) != 0) return(-1); |
if (validatedirlist(*dirlist) != 0) return(-1); |
|
return(repocount); |
return(0); |
} |