Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 224 → Rev 225

/pkginst/helpers.c
1,6 → 1,6
/*
* This file is part of fdnpkg
* Copyright (C) 2012-2017 Mateusz Viste
* This file is part of pkginst
* Copyright (C) 2012-2021 Mateusz Viste
*
* It contains a few helper function...
*/
193,37 → 193,6
}
 
 
/* remap drive, if needed (hack for situations where fdinst is used to
* install an OS to a drive that will change its letter post-install) */
void mapdrives(char *s, char *mapdrv) {
int i = 0;
if (mapdrv == NULL) return;
if ((s == NULL) || (s[0] == 0) || (s[1] != ':')) return;
while (mapdrv[i] != 0) {
if (toupper(mapdrv[i]) == toupper(s[0])) {
s[0] = toupper(mapdrv[i + 1]);
return;
}
i += 2;
}
}
 
 
/* */
void unmapdrives(char *s, char *mapdrv) {
int i = 0;
if (mapdrv == NULL) return;
if ((s == NULL) || (s[0] == 0) || (s[1] != ':')) return;
while (mapdrv[i] != 0) {
if (toupper(mapdrv[i + 1]) == toupper(s[0])) {
s[0] = toupper(mapdrv[i]);
return;
}
i += 2;
}
}
 
 
/* returns a pointer to the start of the filename, out of a path\to\file string, and
fills respath with the local folder where the file should be placed. */
char *computelocalpath(char *longfilename, char *respath, char *dosdir, struct customdirs *dirlist) {
/pkginst/helpers.h
1,6 → 1,6
/*
* This file is part of fdnpkg
* Copyright (C) 2012-2017 Mateusz Viste
* This file is part of pkginst
* Copyright (C) 2012-2021 Mateusz Viste
*
* It contains a few helper function...
*/
14,8 → 14,6
void strtolower(char *mystring);
char *fdnpkg_strcasestr(const char *s, const char *find);
void mkpath(char *dirs);
void mapdrives(char *s, char *mapdrv);
void unmapdrives(char *s, char *mapdrv);
char *computelocalpath(char *longfilename, char *respath, char *dosdir, struct customdirs *dirlist);
void removeDoubleBackslashes(char *str);
int detect_localpath(char *url);
/pkginst/loadconf.c
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);
}
/pkginst/loadconf.h
1,7 → 1,7
/*
* This file is part of FDNPKG.
* This file is part of pkginst.
*
* Copyright (C) 2012-2016 Mateusz Viste
* Copyright (C) 2012-2021 Mateusz Viste
*/
 
#ifndef loadrepolist_sentinel
13,11 → 13,11
struct customdirs *next;
};
 
/* Loads the list of repositories from the config file specified in %FDNPKG%.
* Returns the amount of repositories found (and loaded) on success, or -1 on failure. */
int loadconf(char *cfgfile, char **repolist, int maxreps, unsigned long *crc32val, long *maxcachetime, struct customdirs **dirlist, int *nosourceflag, char **proxy, int *proxyport, char **mapdrv);
/* Loads the list of custom directories from the config file specified in %FDNPKG%.
* Returns 0 on success, or -1 on failure. */
int loadconf(char *cfgfile, struct customdirs **dirlist, int *flags);
 
/* Free the memory allocated at configuration load. */
void freeconf(char **repolist, int repscount, struct customdirs **dirlist);
void freeconf(struct customdirs **dirlist);
 
#endif
/pkginst/main.c
85,7 → 85,7
}
 
 
static int pkginst(char *file, int flags, char *dosdir, char *tempdir, struct customdirs *dirlist, char *mapdrv) {
static int pkginst(char *file, int flags, char *dosdir, char *tempdir, struct customdirs *dirlist) {
char pkgname[32];
int t, lastpathdelim = -1, u = 0;
char *buffmem1k;
111,11 → 111,11
return(1);
}
/* prepare the zip file and install it */
zipfileidx = pkginstall_preparepackage(NULL, pkgname, tempdir, file, flags, NULL, &zipfilefd, NULL, 0, NULL, dosdir, dirlist, buffmem1k, mapdrv);
zipfileidx = pkginstall_preparepackage(pkgname, file, flags, &zipfilefd, dosdir, dirlist, buffmem1k);
free(buffmem1k);
if (zipfileidx != NULL) {
int res = 0;
if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd, mapdrv) != 0) res = 1;
if (pkginstall_installpackage(pkgname, dosdir, dirlist, zipfileidx, zipfilefd) != 0) res = 1;
fclose(zipfilefd);
return(res);
} else {
130,7 → 130,6
enum ACTIONTYPES action;
char *dosdir, *tempdir, *cfgfile;
struct customdirs *dirlist;
char *mapdrv = "";
 
action = parsearg(argc, argv);
if (action == ACTION_HELP) return(showhelp());
151,7 → 150,7
/* load configuration */
flags = 0;
dirlist = NULL;
if (loadconf(cfgfile, NULL, 0, NULL, NULL, &dirlist, &flags, NULL, NULL, &mapdrv) < 0) return(5);
if (loadconf(cfgfile, &dirlist, &flags) < 0) return(5);
 
/* free the cfgfile buffer, I won't need the config file's location any more */
free(cfgfile);
159,10 → 158,10
 
switch (action) {
case ACTION_INSTALL:
res = pkginst(argv[2], flags, dosdir, tempdir, dirlist, mapdrv);
res = pkginst(argv[2], flags, dosdir, tempdir, dirlist);
break;
case ACTION_REMOVE:
res = pkgrem(argv[2], dosdir, mapdrv);
res = pkgrem(argv[2], dosdir);
break;
default:
res = showhelp();
/pkginst/pkginst.c
137,10 → 137,9
 
 
/* returns 0 if pkgname is not installed, non-zero otherwise */
int is_package_installed(char *pkgname, char *dosdir, char *mapdrv) {
int is_package_installed(char *pkgname, char *dosdir) {
char fname[512];
sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
mapdrives(fname, mapdrv);
if (fileexists(fname) != 0) { /* file exists -> package is installed */
return(1);
} else {
150,8 → 149,8
 
 
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
int validate_package_not_installed(char *pkgname, char *dosdir, char *mapdrv) {
if (is_package_installed(pkgname, dosdir, mapdrv) != 0) {
int validate_package_not_installed(char *pkgname, char *dosdir) {
if (is_package_installed(pkgname, dosdir) != 0) {
kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
puts("");
return(-1);
172,7 → 171,7
 
/* prepare a package for installation. this is mandatory before actually installing it!
* returns a pointer to the zip file's index on success, NULL on failure. the *zipfile pointer is updated with a file descriptor to the open zip file to install. */
struct ziplist *pkginstall_preparepackage(struct pkgdb *pkgdb, char *pkgname, char *tempdir, char *localfile, int flags, char **repolist, FILE **zipfd, char *proxy, int proxyport, char *downloadingstring, char *dosdir, struct customdirs *dirlist, char *buffmem1k, char *mapdrv) {
struct ziplist *pkginstall_preparepackage(char *pkgname, char *localfile, int flags, FILE **zipfd, char *dosdir, struct customdirs *dirlist, char *buffmem1k) {
char *fname;
char *zipfile;
char *appinfofile;
190,7 → 189,7
 
/* check if not already installed, if already here, print a message "you might want to use update instead"
* of course this must not be done if we are in the process of upgrading said package */
if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir, mapdrv) != 0)) {
if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
return(NULL);
}
 
271,7 → 270,6
/* look out for collisions with already existing files (unless we are
* updating the package and the local file belongs to it */
shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
mapdrives(fname, mapdrv);
strcat(fname, shortfile);
if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
317,7 → 315,7
 
/* install a package that has been prepared already. returns 0 on success,
* or a negative value on error, or a positive value on warning */
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd, char *mapdrv) {
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
char *buff;
char *fulldestfilename;
char packageslst[64];
344,7 → 342,6
 
/* open the lst file */
sprintf(buff, "%s\\%s", dosdir, packageslst);
mapdrives(buff, mapdrv);
lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
if (lstfd == NULL) {
kitten_printf(3, 10, "Error: Could not create %s!", buff);
363,8 → 360,6
shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
/* log the filename to packages\pkg.lst (with original, unmapped drive) */
fprintf(lstfd, "%s%s\r\n", buff, shortfile);
/* remap drive letter, if needed (AFTER writing to lstfd) */
mapdrives(buff, mapdrv);
/* create the path, just in case it doesn't exist yet */
mkpath(buff);
sprintf(fulldestfilename, "%s%s", buff, shortfile);
380,7 → 375,6
}
/* if it's a LINK file, recompute a new content */
if (islinkfile(curzipnode->filename) != 0) {
unmapdrives(buff, mapdrv);
processlinkfile(fulldestfilename, dosdir, dirlist, buff);
}
}
/pkginst/pkginst.h
1,6 → 1,6
/*
* This file is part of FDNPKG
* Copyright (C) 2012-2017 Mateusz Viste
* This file is part of SvarDOS
* Copyright (C) 2012-2021 Mateusz Viste
*/
 
#ifndef pkginst_sentinel
8,9 → 8,9
 
#include "loadconf.h" /* required for struct customdirs */
 
int is_package_installed(char *pkgname, char *dosdir, char *mapdrv);
struct ziplist *pkginstall_preparepackage(struct pkgdb *pkgdb, char *pkgname, char *tempdir, char *localfile, int nosourceflag, char **repolist, FILE **zipfd, char *proxy, int proxyport, char *downloadingstring, char *dosdir, struct customdirs *dirlist, char *buffmem1k, char *mapdrv);
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd, char *mapdrv);
int validate_package_not_installed(char *pkgname, char *dosdir, char *mapdrv);
int is_package_installed(char *pkgname, char *dosdir);
struct ziplist *pkginstall_preparepackage(char *pkgname, char *localfile, int nosourceflag, FILE **zipfd, char *dosdir, struct customdirs *dirlist, char *buffmem1k);
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd);
int validate_package_not_installed(char *pkgname, char *dosdir);
 
#endif
/pkginst/pkgrem.c
69,7 → 69,7
 
 
/* removes a package from the system. Returns 0 on success, non-zero otherwise */
int pkgrem(char *pkgname, char *dosdir, char *mapdrv) {
int pkgrem(char *pkgname, char *dosdir) {
char fpath[512];
char shellcmd[512];
char *lineptr;
83,7 → 83,6
 
/* Check if the file %DOSDIR%\packages\pkgname.lst exists (if not, the package is not installed) */
sprintf(fpath, "%s\\packages\\%s.lst", dosdir, pkgname);
mapdrives(fpath, mapdrv);
if (fileexists(fpath) == 0) { /* file does not exist */
kitten_printf(4, 0, "Package %s is not installed, so not removed.", pkgname);
puts("");
114,8 → 113,6
free(lineptr); /* free the memory occupied by the line */
continue; /* skip empty lines */
}
/* remap drive */
mapdrives(lineptr, mapdrv);
/* remember the path part for removal later */
lastdirsep = -1;
for (x = 1; lineptr[x] != 0; x++) {
/pkginst/pkgrem.h
1,9 → 1,9
/*
* This file is part of the FDNPKG project.
* Copyright (C) Mateusz Viste 2012-2016. All rights reserved.
* This file is part of the SvarDOS project.
* Copyright (C) Mateusz Viste 2012-2021. All rights reserved.
*/
 
#ifndef pkgrem_sentinel
#define pkgrem_sentinel
int pkgrem(char *pkgname, char *dosdir, char *mapdrv);
int pkgrem(char *pkgname, char *dosdir);
#endif