aboutsummaryrefslogtreecommitdiffstats
path: root/src/package.h
blob: e054ec2bb8ca0824949830be935d22a7a120960a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (C) 2003 Jason Woodward <woodwardj at jaos dot org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#define MAX_PKG_ENTRIES 1300
#define PKG_PARSE_REGEX "([a-zA-Z0-9._\\-\\/]+/)([a-zA-Z0-9\\+_\\-]+)-([a-zA-Z0-9._\\-]+).tgz$"
#define PKG_NAME_PATTERN "^PACKAGE NAME:[ ]+([a-zA-Z0-9\\+_\\-]+)-([a-zA-Z0-9._\\-]+).tgz$"
#define PKG_MIRROR_PATTERN "^PACKAGE MIRROR:[ ]+(.*)$"
#define PKG_LOCATION_PATTERN "^PACKAGE LOCATION:[ ]+(.*)$"
#define PKG_SIZEC_PATTERN "^PACKAGE SIZE [(]+compressed[)]+:[ ]+([0-9]+) K$"
#define PKG_SIZEU_PATTERN "^PACKAGE SIZE [(]+uncompressed[)]+:[ ]+([0-9]+) K$"
#define PKG_LOG_DIR "/var/log/packages"
#define PKG_LOG_PATTERN "^([a-zA-Z0-9\\+_\\-]+)-([a-zA-Z0-9._\\-]+)$"
#define MD5SUM_REGEX "([a-zA-Z0-9]+)[ ]+([a-zA-Z0-9._\\-\\/]+/)([a-zA-Z0-9\\+_\\-]+)-([a-zA-Z0-9._\\-]+).tgz$"

/*
 * VARIABLE DEFINITIONS
 */
struct _pkg_info {
	char name[50];
	char version[50];
	char mirror[200];
	char location[60];
	int size_c;
	int size_u;
	char description[1024];
};
typedef struct _pkg_info pkg_info_t;
struct pkg_list {
	pkg_info_t **pkgs;
	int pkg_count;
};
struct _pkg_upgrade {
	pkg_info_t *installed;
	pkg_info_t *upgrade;
};
typedef struct _pkg_upgrade pkg_upgrade_t;
struct pkg_upgrade_list {
	pkg_upgrade_t **pkgs;
	int pkg_count;
};

/*
 * FUNCTION DEFINITIONS
 */

/* parse the PACKAGES.TXT file */
struct pkg_list *parse_packages_txt(FILE *);
struct pkg_list *get_available_pkgs(void);

/* retrieve list of installed pkgs */
struct pkg_list *get_installed_pkgs(void);

/*
	This used to be used to parse the file list for updates,
	until I realized patches/PACKAGES.TXT existed
	Legacy, might be useful one day.
*/
struct pkg_list *parse_file_list(FILE *);

/* generate a short description */
char *gen_short_pkg_description(pkg_info_t *);

/* retrieve the newest pkg from pkg_info_t list */
pkg_info_t *get_newest_pkg(pkg_info_t **,const char *,int);

/* install pkg */
int install_pkg(const rc_config *,pkg_info_t *);

/* upgrade pkg */
int upgrade_pkg(const rc_config *,pkg_info_t *,pkg_info_t *);

/* remove pkg */
int remove_pkg(const rc_config *,pkg_info_t *);

/* initialize pkg_list structure */
void init_pkg_list(struct pkg_list *);
/* add pkg to pkg_list structure */
void add_pkg_to_list(struct pkg_list *, pkg_info_t *);
/* free memory allocated for pkg_list struct */
void free_pkg_list(struct pkg_list *);

/* exclude pkg based on pkg name */
int is_excluded(const rc_config *,const char *);

/* lookup md5sum of file */
void get_md5sum(const rc_config *,pkg_info_t *,char *);

/* compare package versions */
int cmp_pkg_versions(char *, char *);

/* analyze the pkg version hunk by hunk */
int break_down_pkg_version(int *,char *);

/* get available, installed, and update pkgs all in one */
/* write pkg data to disk */
void write_pkg_data(const char *,FILE *,struct pkg_list *);