Subversion Repositories SvarDOS

Rev

Rev 237 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 237 Rev 238
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of FDNPKG.
2
 * This file is part of pkginst (SvarDOS).
3
 *
3
 *
4
 * Loads the list of repositories from the config file specified in %FDNPKG%.
4
 * Loads the list of repositories from a config file.
5
 * Returns the amount of repositories found (and loaded) on success, or -1 on failure.
-
 
6
 *
5
 *
7
 * Copyright (C) 2012-2016 Mateusz Viste
6
 * Copyright (C) 2012-2021 Mateusz Viste
8
 */
7
 */
9
 
8
 
10
#include <stdio.h>  /* printf(), fclose(), fopen()... */
9
#include <stdio.h>  /* printf(), fclose(), fopen()... */
11
#include <string.h> /* strcasecmp() */
10
#include <string.h> /* strcasecmp() */
12
#include <stdlib.h> /* malloc(), free() */
11
#include <stdlib.h> /* malloc(), free() */
Line 14... Line 13...
14
#include "fdnpkg.h" /* PKGINST_SKIPLINKS... */
13
#include "fdnpkg.h" /* PKGINST_SKIPLINKS... */
15
#include "helpers.h" /* slash2backslash(), removeDoubleBackslashes()... */
14
#include "helpers.h" /* slash2backslash(), removeDoubleBackslashes()... */
16
#include "kprintf.h"
15
#include "kprintf.h"
17
#include "loadconf.h"
16
#include "loadconf.h"
18
#include "parsecmd.h"
17
#include "parsecmd.h"
19
#include "version.h"
-
 
20
 
18
 
21
 
19
 
22
void freeconf(struct customdirs **dirlist) {
20
void freeconf(struct customdirs **dirlist) {
23
  struct customdirs *curpos;
21
  struct customdirs *curpos;
24
  /* free the linked list of custom dirs */
22
  /* free the linked list of custom dirs */
25
  while (*dirlist != NULL) {
23
  while (*dirlist != NULL) {
26
    curpos = *dirlist;
24
    curpos = *dirlist;
27
    if (curpos->name != NULL) free(curpos->name);
-
 
28
    if (curpos->location != NULL) free(curpos->location);
-
 
29
    *dirlist = (*dirlist)->next;
25
    *dirlist = (*dirlist)->next;
30
    free(curpos);
26
    free(curpos);
31
  }
27
  }
32
  *dirlist = NULL;
-
 
33
}
28
}
34
 
29
 
35
 
30
 
36
static int checkfordoubledirlist(struct customdirs *dirlist) {
31
static int checkfordoubledirlist(const struct customdirs *dirlist) {
37
  struct customdirs *curpos;
32
  struct customdirs *curpos;
38
  for (; dirlist != NULL; dirlist = dirlist->next) {
33
  for (; dirlist != NULL; dirlist = dirlist->next) {
39
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
34
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
40
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
35
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
41
        kitten_printf(7, 0, "Error: custom dir '%s' is listed twice!", curpos->name);
36
        kitten_printf(7, 0, "Error: custom dir '%s' is listed twice!", curpos->name);
Line 47... Line 42...
47
  return(0);
42
  return(0);
48
}
43
}
49
 
44
 
50
 
45
 
51
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
46
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
52
static int validatedirlist(struct customdirs *dirlist) {
47
static int validatedirlist(const struct customdirs *dirlist) {
53
  for (; dirlist != NULL; dirlist = dirlist->next) {
48
  for (; dirlist != NULL; dirlist = dirlist->next) {
54
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
49
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
55
    if (strlen(dirlist->location) < 3) {
50
    if (strlen(dirlist->location) < 3) {
56
      kitten_printf(7, 15, "Error: custom dir '%s' is not a valid absolute path!", dirlist->name);
51
      kitten_printf(7, 15, "Error: custom dir '%s' is not a valid absolute path!", dirlist->name);
57
      puts("");
52
      puts("");
Line 81... Line 76...
81
}
76
}
82
 
77
 
83
 
78
 
84
/* add (and allocates) a new custom dir entry to dirlist. Returns 0 on success,
79
/* add (and allocates) a new custom dir entry to dirlist. Returns 0 on success,
85
   or non-zero on failure (failures happen on out of memory events). */
80
   or non-zero on failure (failures happen on out of memory events). */
86
static int addnewdir(struct customdirs **dirlist, char *name, char *location) {
81
static int addnewdir(struct customdirs **dirlist, const char *name, const char *location) {
87
  struct customdirs *newentry;
82
  struct customdirs *newentry;
-
 
83
  if (strlen(name) >= sizeof(newentry->name)) return(-2);
88
  newentry = malloc(sizeof(struct customdirs));
84
  newentry = malloc(sizeof(struct customdirs) + strlen(location) + 1);
89
  if (newentry == NULL) return(-1);
85
  if (newentry == NULL) return(-1);
90
  newentry->name = malloc(strlen(name) + 1);
-
 
91
  if (newentry->name == NULL) {
-
 
92
    free(newentry);
-
 
93
    return(-1);
-
 
94
  }
-
 
95
  newentry->location = malloc(strlen(location) + 1);
-
 
96
  if (newentry->location == NULL) {
-
 
97
    free(newentry->name);
-
 
98
    free(newentry);
-
 
99
    return(-1);
-
 
100
  }
-
 
101
  strcpy(newentry->name, name);
86
  strcpy(newentry->name, name);
102
  strcpy(newentry->location, location);
87
  strcpy(newentry->location, location);
103
  newentry->next = *dirlist;
88
  newentry->next = *dirlist;
104
  *dirlist = newentry;
89
  *dirlist = newentry;
105
  return(0);
90
  return(0);