add fix for tar command line (thx matled)
[openwrt.git] / openwrt / package / busybox / patches / busybox-1.00+ipkg-0.99.152-pre2.patch
1 diff -ruN busybox-1.00-orig/Makefile busybox-1.00+ipkg-0.99.152-pre2/Makefile
2 --- busybox-1.00-orig/Makefile 2004-10-08 07:45:08.000000000 +0000
3 +++ busybox-1.00+ipkg-0.99.152-pre2/Makefile 2005-07-20 13:24:00.000000000 +0000
4 @@ -39,7 +39,7 @@
5
6 include $(top_builddir)/Rules.mak
7
8 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
9 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
10 debianutils editors findutils init miscutils modutils networking \
11 networking/libiproute networking/udhcp procps loginutils shell \
12 sysklogd util-linux libpwdgrp coreutils/libcoreutils libbb
13 diff -ruN busybox-1.00-orig/archival/Config.in busybox-1.00+ipkg-0.99.152-pre2/archival/Config.in
14 --- busybox-1.00-orig/archival/Config.in 2004-03-15 08:28:16.000000000 +0000
15 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/Config.in 2005-07-20 16:53:48.805813848 +0000
16 @@ -121,6 +121,14 @@
17 gzip is used to compress files.
18 It's probably the most widely used UNIX compression program.
19
20 +config CONFIG_IPKG
21 + bool "ipkg"
22 + default n
23 + select CONFIG_MD5SUM
24 + select CONFIG_WGET
25 + help
26 + ipkg is the itsy package management system.
27 +
28 config CONFIG_RPM2CPIO
29 bool "rpm2cpio"
30 default n
31 diff -ruN busybox-1.00-orig/archival/Makefile.in busybox-1.00+ipkg-0.99.152-pre2/archival/Makefile.in
32 --- busybox-1.00-orig/archival/Makefile.in 2004-10-08 07:45:09.000000000 +0000
33 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/Makefile.in 2005-07-18 11:40:31.000000000 +0000
34 @@ -32,6 +32,7 @@
35 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
36 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
37 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
38 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
39 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
40 ARCHIVAL-$(CONFIG_RPM) += rpm.o
41 ARCHIVAL-$(CONFIG_TAR) += tar.o
42 diff -ruN busybox-1.00-orig/archival/dpkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/dpkg.c
43 --- busybox-1.00-orig/archival/dpkg.c 2004-04-14 17:51:08.000000000 +0000
44 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/dpkg.c 2005-07-20 13:15:04.000000000 +0000
45 @@ -1527,6 +1527,10 @@
46 return(ar_handle->sub_archive->buffer);
47 }
48
49 +/*
50 +
51 +// moved to data_extract_all.c
52 +
53 static void data_extract_all_prefix(archive_handle_t *archive_handle)
54 {
55 char *name_ptr = archive_handle->file_header->name;
56 @@ -1541,6 +1545,8 @@
57 return;
58 }
59
60 +*/
61 +
62 static void unpack_package(deb_file_t *deb_file)
63 {
64 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
65 diff -ruN busybox-1.00-orig/archival/ipkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/ipkg.c
66 --- busybox-1.00-orig/archival/ipkg.c 1970-01-01 00:00:00.000000000 +0000
67 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/ipkg.c 2005-07-20 13:16:47.000000000 +0000
68 @@ -0,0 +1,26 @@
69 +/* ipkg.c - the itsy package management system
70 +
71 + Florina Boor
72 +
73 + Copyright (C) 2003 kernel concepts
74 +
75 + This program is free software; you can redistribute it and/or
76 + modify it under the terms of the GNU General Public License as
77 + published by the Free Software Foundation; either version 2, or (at
78 + your option) any later version.
79 +
80 + This program is distributed in the hope that it will be useful, but
81 + WITHOUT ANY WARRANTY; without even the implied warranty of
82 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83 + General Public License for more details.
84 +
85 + ipkg command line frontend using libipkg
86 +
87 +*/
88 +
89 +#include "libipkg/libipkg.h"
90 +
91 +int ipkg_main(int argc, char **argv)
92 +{
93 + return ipkg_op(argc, argv);
94 +}
95 diff -ruN busybox-1.00-orig/archival/libipkg/Makefile busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile
96 --- busybox-1.00-orig/archival/libipkg/Makefile 1970-01-01 00:00:00.000000000 +0000
97 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile 2005-07-17 16:10:23.000000000 +0000
98 @@ -0,0 +1,32 @@
99 +# Makefile for busybox
100 +#
101 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
102 +#
103 +# This program is free software; you can redistribute it and/or modify
104 +# it under the terms of the GNU General Public License as published by
105 +# the Free Software Foundation; either version 2 of the License, or
106 +# (at your option) any later version.
107 +#
108 +# This program is distributed in the hope that it will be useful,
109 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
110 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
111 +# General Public License for more details.
112 +#
113 +# You should have received a copy of the GNU General Public License
114 +# along with this program; if not, write to the Free Software
115 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
116 +#
117 +
118 +top_srcdir=../..
119 +top_builddir=../..
120 +srcdir=$(top_srcdir)/archival/libipkg
121 +LIBIPKG_DIR:=./
122 +include $(top_builddir)/Rules.mak
123 +include $(top_builddir)/.config
124 +include $(srcdir)/Makefile.in
125 +all: $(libraries-y)
126 +-include $(top_builddir)/.depend
127 +
128 +clean:
129 + rm -f *.o *.a $(AR_TARGET)
130 +
131 diff -ruN busybox-1.00-orig/archival/libipkg/Makefile.in busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile.in
132 --- busybox-1.00-orig/archival/libipkg/Makefile.in 1970-01-01 00:00:00.000000000 +0000
133 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile.in 2005-07-20 17:24:44.092767360 +0000
134 @@ -0,0 +1,83 @@
135 +# Makefile for busybox
136 +#
137 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
138 +#
139 +# This program is free software; you can redistribute it and/or modify
140 +# it under the terms of the GNU General Public License as published by
141 +# the Free Software Foundation; either version 2 of the License, or
142 +# (at your option) any later version.
143 +#
144 +# This program is distributed in the hope that it will be useful,
145 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
146 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
147 +# General Public License for more details.
148 +#
149 +# You should have received a copy of the GNU General Public License
150 +# along with this program; if not, write to the Free Software
151 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
152 +#
153 +
154 +LIBIPKG_AR:=libipkg.a
155 +ifndef $(LIBIPKG_DIR)
156 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
157 +endif
158 +srcdir=$(top_srcdir)/archival/libipkg
159 +
160 +LIBIPKG_CORE_SOURCES:= \
161 + args.c \
162 + libipkg.c \
163 + user.c \
164 +
165 +LIBIPKG_CMD_SOURCES:= \
166 + ipkg_cmd.c \
167 + ipkg_configure.c \
168 + ipkg_download.c \
169 + ipkg_install.c \
170 + ipkg_remove.c \
171 + ipkg_upgrade.c \
172 +
173 +LIBIPKG_DB_SOURCES:= \
174 + hash_table.c \
175 + ipkg_conf.c \
176 + ipkg_utils.c \
177 + pkg.c \
178 + pkg_depends.c \
179 + pkg_extract.c \
180 + pkg_hash.c \
181 + pkg_parse.c \
182 + pkg_vec.c \
183 +
184 +LIBIPKG_LIST_SOURCES:= \
185 + conffile.c \
186 + conffile_list.c \
187 + nv_pair.c \
188 + nv_pair_list.c \
189 + pkg_dest.c \
190 + pkg_dest_list.c \
191 + pkg_src.c \
192 + pkg_src_list.c \
193 + str_list.c \
194 + void_list.c \
195 +
196 +LIBIPKG_UTIL_SOURCES:= \
197 + file_util.c \
198 + ipkg_message.c \
199 + md5.c \
200 + str_util.c \
201 + xsystem.c \
202 +
203 +LIBIPKG-y += $(LIBIPKG_CORE_SOURCES)
204 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
205 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
206 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_UTIL_SOURCES)
208 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
209 +
210 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
211 +
212 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
213 + $(AR) -ro $@ $^
214 +
215 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
216 + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(ARCH)\"" -c -o $@ $<
217 +
218 diff -ruN busybox-1.00-orig/archival/libipkg/args.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.c
219 --- busybox-1.00-orig/archival/libipkg/args.c 1970-01-01 00:00:00.000000000 +0000
220 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.c 2005-07-20 10:38:34.000000000 +0000
221 @@ -0,0 +1,241 @@
222 +/* args.c - parse command-line args
223 +
224 + Carl D. Worth
225 +
226 + Copyright 2001 University of Southern California
227 +
228 + This program is free software; you can redistribute it and/or modify
229 + it under the terms of the GNU General Public License as published by
230 + the Free Software Foundation; either version 2, or (at your option)
231 + any later version.
232 +
233 + This program is distributed in the hope that it will be useful,
234 + but WITHOUT ANY WARRANTY; without even the implied warranty of
235 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236 + GNU General Public License for more details.
237 + */
238 +
239 +#include <getopt.h>
240 +#include <stdlib.h>
241 +#include <string.h>
242 +#include <unistd.h>
243 +
244 +#include "ipkg.h"
245 +#include "ipkg_message.h"
246 +
247 +#include "args.h"
248 +#include "sprintf_alloc.h"
249 +
250 +#include "libbb.h"
251 +
252 +
253 +static void print_version(void);
254 +
255 +enum long_args_opt
256 +{
257 + ARGS_OPT_FORCE_DEFAULTS = 129,
258 + ARGS_OPT_FORCE_DEPENDS,
259 + ARGS_OPT_FORCE_OVERWRITE,
260 + ARGS_OPT_FORCE_DOWNGRADE,
261 + ARGS_OPT_FORCE_REINSTALL,
262 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
263 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
264 + ARGS_OPT_FORCE_SPACE,
265 + ARGS_OPT_NOACTION,
266 + ARGS_OPT_NODEPS,
267 + ARGS_OPT_VERBOSE_WGET,
268 + ARGS_OPT_VERBOSITY,
269 + ARGS_OPT_MULTIPLE_PROVIDERS
270 +};
271 +
272 +int args_init(args_t *args)
273 +{
274 + char *conf_file_dir;
275 +
276 + memset(args, 0, sizeof(args_t));
277 +
278 + args->dest = ARGS_DEFAULT_DEST;
279 +
280 + conf_file_dir = getenv("IPKG_CONF_DIR");
281 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
282 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
283 + }
284 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
285 + ARGS_DEFAULT_CONF_FILE_NAME);
286 +
287 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
288 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
289 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
290 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
291 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
292 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
293 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
294 + args->noaction = ARGS_DEFAULT_NOACTION;
295 + args->nodeps = ARGS_DEFAULT_NODEPS;
296 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
297 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
298 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
299 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
300 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
301 + args->multiple_providers = 0;
302 + args->nocheckfordirorfile = 0;
303 +
304 + return 1;
305 +}
306 +
307 +void args_deinit(args_t *args)
308 +{
309 + free(args->conf_file);
310 + args->conf_file = NULL;
311 +}
312 +
313 +int args_parse(args_t *args, int argc, char *argv[])
314 +{
315 + int c;
316 + int option_index = 0;
317 + int parse_err = 0;
318 + static struct option long_options[] = {
319 + {"query-all", 0, 0, 'A'},
320 + {"conf-file", 1, 0, 'f'},
321 + {"conf", 1, 0, 'f'},
322 + {"dest", 1, 0, 'd'},
323 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
324 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
325 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
326 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
327 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
328 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
329 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
330 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
331 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
332 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
333 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
334 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
335 + {"recursive", 0, 0,
336 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
337 + {"force-removal-of-dependent-packages", 0, 0,
338 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
339 + {"force_removal_of_dependent_packages", 0, 0,
340 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
341 + {"force-removal-of-essential-packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
343 + {"force_removal_of_essential_packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
346 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
347 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
348 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
349 + {"offline", 1, 0, 'o'},
350 + {"offline-root", 1, 0, 'o'},
351 + {"test", 0, 0, ARGS_OPT_NOACTION},
352 + {"tmp-dir", 1, 0, 't'},
353 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
354 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
355 + {"verbosity", 2, 0, 'V'},
356 + {"version", 0, 0, 'v'},
357 + {0, 0, 0, 0}
358 + };
359 +
360 + while (1) {
361 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
362 + if (c == -1)
363 + break;
364 +
365 + switch (c) {
366 + case 'A':
367 + args->query_all = 1;
368 + break;
369 + case 'd':
370 + args->dest = optarg;
371 + break;
372 + case 'f':
373 + free(args->conf_file);
374 + args->conf_file = strdup(optarg);
375 + break;
376 + case 'o':
377 + args->offline_root = optarg;
378 + break;
379 + case 'n':
380 + args->noaction = 1;
381 + break;
382 + case 't':
383 + args->tmp_dir = strdup(optarg);
384 + break;
385 + case 'v':
386 + print_version();
387 + exit(0);
388 + case 'V':
389 + case ARGS_OPT_VERBOSITY:
390 + if (optarg)
391 + args->verbosity = atoi(optarg);
392 + else
393 + args->verbosity += 1;
394 + break;
395 + case ARGS_OPT_FORCE_DEFAULTS:
396 + args->force_defaults = 1;
397 + break;
398 + case ARGS_OPT_FORCE_DEPENDS:
399 + args->force_depends = 1;
400 + break;
401 + case ARGS_OPT_FORCE_OVERWRITE:
402 + args->force_overwrite = 1;
403 + break;
404 + case ARGS_OPT_FORCE_DOWNGRADE:
405 + args->force_downgrade = 1;
406 + break;
407 + case ARGS_OPT_FORCE_REINSTALL:
408 + args->force_reinstall = 1;
409 + break;
410 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
411 + args->force_removal_of_essential_packages = 1;
412 + break;
413 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
414 + args->force_removal_of_dependent_packages = 1;
415 + break;
416 + case ARGS_OPT_FORCE_SPACE:
417 + args->force_space = 1;
418 + break;
419 + case ARGS_OPT_VERBOSE_WGET:
420 + args->verbose_wget = 1;
421 + break;
422 + case ARGS_OPT_MULTIPLE_PROVIDERS:
423 + args->multiple_providers = 1;
424 + break;
425 + case ARGS_OPT_NODEPS:
426 + args->nodeps = 1;
427 + break;
428 + case ARGS_OPT_NOACTION:
429 + args->noaction = 1;
430 + break;
431 + case ':':
432 + parse_err++;
433 + break;
434 + case '?':
435 + parse_err++;
436 + break;
437 + default:
438 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
439 + }
440 + }
441 +
442 + if (parse_err) {
443 + return -parse_err;
444 + } else {
445 + return optind;
446 + }
447 +}
448 +
449 +void args_usage(char *complaint)
450 +{
451 + if (complaint) {
452 + bb_error_msg("%s\n", complaint);
453 + }
454 + print_version();
455 + bb_show_usage();
456 + exit(1);
457 +}
458 +
459 +static void print_version(void)
460 +{
461 + bb_error_msg("version %s\n", IPKG_VERSION);
462 +}
463 diff -ruN busybox-1.00-orig/archival/libipkg/args.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.h
464 --- busybox-1.00-orig/archival/libipkg/args.h 1970-01-01 00:00:00.000000000 +0000
465 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.h 2005-07-19 00:46:01.000000000 +0000
466 @@ -0,0 +1,71 @@
467 +/* args.h - parse command-line args
468 +
469 + Carl D. Worth
470 +
471 + Copyright 2001 University of Southern California
472 +
473 + This program is free software; you can redistribute it and/or modify
474 + it under the terms of the GNU General Public License as published by
475 + the Free Software Foundation; either version 2, or (at your option)
476 + any later version.
477 +
478 + This program is distributed in the hope that it will be useful,
479 + but WITHOUT ANY WARRANTY; without even the implied warranty of
480 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
481 + GNU General Public License for more details.
482 +*/
483 +
484 +#ifndef ARGS_H
485 +#define ARGS_H
486 +
487 +struct args
488 +{
489 + char *conf_file;
490 + char *dest;
491 + char *tmp_dir;
492 + int force_defaults;
493 + int force_depends;
494 + int force_overwrite;
495 + int force_downgrade;
496 + int force_reinstall;
497 + int force_removal_of_essential_packages;
498 + int force_removal_of_dependent_packages;
499 + int force_space;
500 + int noaction;
501 + int nodeps;
502 + int multiple_providers;
503 + int query_all;
504 + int verbose_wget;
505 + int verbosity;
506 + int nocheckfordirorfile;
507 + char *offline_root;
508 + char *offline_root_pre_script_cmd;
509 + char *offline_root_post_script_cmd;
510 +};
511 +typedef struct args args_t;
512 +
513 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
514 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
515 +#define ARGS_DEFAULT_DEST NULL
516 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
517 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
518 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
519 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
520 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
521 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
522 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
523 +#define ARGS_DEFAULT_FORCE_SPACE 0
524 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
525 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
526 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
527 +#define ARGS_DEFAULT_NOACTION 0
528 +#define ARGS_DEFAULT_NODEPS 0
529 +#define ARGS_DEFAULT_VERBOSE_WGET 0
530 +#define ARGS_DEFAULT_VERBOSITY 1
531 +
532 +int args_init(args_t *args);
533 +void args_deinit(args_t *args);
534 +int args_parse(args_t *args, int argc, char *argv[]);
535 +void args_usage(char *complaint);
536 +
537 +#endif
538 diff -ruN busybox-1.00-orig/archival/libipkg/conffile.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.c
539 --- busybox-1.00-orig/archival/libipkg/conffile.c 1970-01-01 00:00:00.000000000 +0000
540 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.c 2005-07-17 16:10:23.000000000 +0000
541 @@ -0,0 +1,64 @@
542 +/* conffile.c - the itsy package management system
543 +
544 + Carl D. Worth
545 +
546 + Copyright (C) 2001 University of Southern California
547 +
548 + This program is free software; you can redistribute it and/or
549 + modify it under the terms of the GNU General Public License as
550 + published by the Free Software Foundation; either version 2, or (at
551 + your option) any later version.
552 +
553 + This program is distributed in the hope that it will be useful, but
554 + WITHOUT ANY WARRANTY; without even the implied warranty of
555 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
556 + General Public License for more details.
557 +*/
558 +
559 +#include <string.h>
560 +#include <stdlib.h>
561 +
562 +#include "ipkg.h"
563 +#include "ipkg_message.h"
564 +
565 +#include "conffile.h"
566 +#include "file_util.h"
567 +#include "sprintf_alloc.h"
568 +
569 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
570 +{
571 + return nv_pair_init(conffile, file_name, md5sum);
572 +}
573 +
574 +void conffile_deinit(conffile_t *conffile)
575 +{
576 + nv_pair_deinit(conffile);
577 +}
578 +
579 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
580 +{
581 + char *md5sum;
582 + char *filename = conffile->name;
583 + char *root_filename;
584 + int ret;
585 +
586 + if (conffile->value == NULL) {
587 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
588 + return 1;
589 + }
590 +
591 + root_filename = root_filename_alloc(conf, filename);
592 +
593 + md5sum = file_md5sum_alloc(root_filename);
594 +
595 + ret = strcmp(md5sum, conffile->value);
596 + if (ret) {
597 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
598 + conffile->name, md5sum, conffile->value);
599 + }
600 +
601 + free(root_filename);
602 + free(md5sum);
603 +
604 + return ret;
605 +}
606 diff -ruN busybox-1.00-orig/archival/libipkg/conffile.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.h
607 --- busybox-1.00-orig/archival/libipkg/conffile.h 1970-01-01 00:00:00.000000000 +0000
608 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.h 2005-07-17 16:10:23.000000000 +0000
609 @@ -0,0 +1,30 @@
610 +/* conffile.h - the itsy package management system
611 +
612 + Carl D. Worth
613 +
614 + Copyright (C) 2001 University of Southern California
615 +
616 + This program is free software; you can redistribute it and/or
617 + modify it under the terms of the GNU General Public License as
618 + published by the Free Software Foundation; either version 2, or (at
619 + your option) any later version.
620 +
621 + This program is distributed in the hope that it will be useful, but
622 + WITHOUT ANY WARRANTY; without even the implied warranty of
623 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
624 + General Public License for more details.
625 +*/
626 +
627 +#ifndef CONFFILE_H
628 +#define CONFFILE_H
629 +
630 +#include "nv_pair.h"
631 +
632 +typedef struct nv_pair conffile_t;
633 +
634 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
635 +void conffile_deinit(conffile_t *conffile);
636 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
637 +
638 +#endif
639 +
640 diff -ruN busybox-1.00-orig/archival/libipkg/conffile_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.c
641 --- busybox-1.00-orig/archival/libipkg/conffile_list.c 1970-01-01 00:00:00.000000000 +0000
642 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.c 2005-07-17 16:10:23.000000000 +0000
643 @@ -0,0 +1,47 @@
644 +/* conffile_list.c - the itsy package management system
645 +
646 + Carl D. Worth
647 +
648 + Copyright (C) 2001 University of Southern California
649 +
650 + This program is free software; you can redistribute it and/or
651 + modify it under the terms of the GNU General Public License as
652 + published by the Free Software Foundation; either version 2, or (at
653 + your option) any later version.
654 +
655 + This program is distributed in the hope that it will be useful, but
656 + WITHOUT ANY WARRANTY; without even the implied warranty of
657 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
658 + General Public License for more details.
659 +*/
660 +
661 +#include "ipkg.h"
662 +
663 +#include "conffile_list.h"
664 +
665 +int conffile_list_init(conffile_list_t *list)
666 +{
667 + return nv_pair_list_init(list);
668 +}
669 +
670 +void conffile_list_deinit(conffile_list_t *list)
671 +{
672 + nv_pair_list_deinit(list);
673 +}
674 +
675 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
676 + const char *md5sum)
677 +{
678 + return nv_pair_list_append(list, file_name, md5sum);
679 +}
680 +
681 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
682 +{
683 + return nv_pair_list_push(list, data);
684 +}
685 +
686 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
687 +{
688 + return nv_pair_list_pop(list);
689 +}
690 +
691 diff -ruN busybox-1.00-orig/archival/libipkg/conffile_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.h
692 --- busybox-1.00-orig/archival/libipkg/conffile_list.h 1970-01-01 00:00:00.000000000 +0000
693 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.h 2005-07-17 16:10:23.000000000 +0000
694 @@ -0,0 +1,36 @@
695 +/* conffile_list.h - the itsy package management system
696 +
697 + Carl D. Worth
698 +
699 + Copyright (C) 2001 University of Southern California
700 +
701 + This program is free software; you can redistribute it and/or
702 + modify it under the terms of the GNU General Public License as
703 + published by the Free Software Foundation; either version 2, or (at
704 + your option) any later version.
705 +
706 + This program is distributed in the hope that it will be useful, but
707 + WITHOUT ANY WARRANTY; without even the implied warranty of
708 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
709 + General Public License for more details.
710 +*/
711 +
712 +#ifndef CONFFILE_LIST_H
713 +#define CONFFILE_LIST_H
714 +
715 +#include "conffile.h"
716 +#include "nv_pair_list.h"
717 +
718 +typedef struct nv_pair_list_elt conffile_list_elt_t;
719 +typedef struct nv_pair_list conffile_list_t;
720 +
721 +int conffile_list_init(conffile_list_t *list);
722 +void conffile_list_deinit(conffile_list_t *list);
723 +
724 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
725 + const char *root_dir);
726 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
727 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
728 +
729 +#endif
730 +
731 diff -ruN busybox-1.00-orig/archival/libipkg/file_util.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.c
732 --- busybox-1.00-orig/archival/libipkg/file_util.c 1970-01-01 00:00:00.000000000 +0000
733 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.c 2005-07-18 12:02:26.000000000 +0000
734 @@ -0,0 +1,177 @@
735 +/* file_util.c - convenience routines for common stat operations
736 +
737 + Carl D. Worth
738 +
739 + Copyright (C) 2001 University of Southern California
740 +
741 + This program is free software; you can redistribute it and/or
742 + modify it under the terms of the GNU General Public License as
743 + published by the Free Software Foundation; either version 2, or (at
744 + your option) any later version.
745 +
746 + This program is distributed in the hope that it will be useful, but
747 + WITHOUT ANY WARRANTY; without even the implied warranty of
748 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
749 + General Public License for more details.
750 +*/
751 +
752 +#include "ipkg.h"
753 +#include <sys/types.h>
754 +#include <sys/stat.h>
755 +
756 +#include "sprintf_alloc.h"
757 +#include "file_util.h"
758 +#include "md5.h"
759 +#include "libbb.h"
760 +#undef strlen
761 +
762 +int file_exists(const char *file_name)
763 +{
764 + int err;
765 + struct stat stat_buf;
766 +
767 + err = stat(file_name, &stat_buf);
768 + if (err == 0) {
769 + return 1;
770 + } else {
771 + return 0;
772 + }
773 +}
774 +
775 +int file_is_dir(const char *file_name)
776 +{
777 + int err;
778 + struct stat stat_buf;
779 +
780 + err = stat(file_name, &stat_buf);
781 + if (err) {
782 + return 0;
783 + }
784 +
785 + return S_ISDIR(stat_buf.st_mode);
786 +}
787 +
788 +/* read a single line from a file, stopping at a newline or EOF.
789 + If a newline is read, it will appear in the resulting string.
790 + Return value is a malloc'ed char * which should be freed at
791 + some point by the caller.
792 +
793 + Return value is NULL if the file is at EOF when called.
794 +*/
795 +#define FILE_READ_LINE_BUF_SIZE 1024
796 +char *file_read_line_alloc(FILE *file)
797 +{
798 + char buf[FILE_READ_LINE_BUF_SIZE];
799 + int buf_len;
800 + char *line = NULL;
801 + int line_size = 0;
802 +
803 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
804 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
805 + buf_len = strlen(buf);
806 + if (line) {
807 + line_size += buf_len;
808 + line = realloc(line, line_size);
809 + if (line == NULL) {
810 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
811 + break;
812 + }
813 + strcat(line, buf);
814 + } else {
815 + line_size = buf_len + 1;
816 + line = strdup(buf);
817 + }
818 + if (buf[buf_len - 1] == '\n') {
819 + break;
820 + }
821 + }
822 +
823 + return line;
824 +}
825 +
826 +int file_move(const char *src, const char *dest)
827 +{
828 + int err;
829 +
830 + err = rename(src, dest);
831 +
832 + if (err && errno == EXDEV) {
833 + err = file_copy(src, dest);
834 + unlink(src);
835 + } else if (err) {
836 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
837 + __FUNCTION__, src, dest, strerror(errno));
838 + }
839 +
840 + return err;
841 +}
842 +
843 +/* I put these here to keep libbb dependencies from creeping all over
844 + the ipkg code */
845 +int file_copy(const char *src, const char *dest)
846 +{
847 + int err;
848 +
849 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
850 + if (err) {
851 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
852 + __FUNCTION__, src, dest);
853 + }
854 +
855 + return err;
856 +}
857 +
858 +int file_mkdir_hier(const char *path, long mode)
859 +{
860 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
861 +}
862 +
863 +char *file_md5sum_alloc(const char *file_name)
864 +{
865 + static const int md5sum_bin_len = 16;
866 + static const int md5sum_hex_len = 32;
867 +
868 + static const unsigned char bin2hex[16] = {
869 + '0', '1', '2', '3',
870 + '4', '5', '6', '7',
871 + '8', '9', 'a', 'b',
872 + 'c', 'd', 'e', 'f'
873 + };
874 +
875 + int i, err;
876 + FILE *file;
877 + unsigned char *md5sum_hex;
878 + unsigned char md5sum_bin[md5sum_bin_len];
879 +
880 + md5sum_hex = malloc(md5sum_hex_len + 1);
881 + if (md5sum_hex == NULL) {
882 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
883 + return strdup("");
884 + }
885 +
886 + file = fopen(file_name, "r");
887 + if (file == NULL) {
888 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
889 + __FUNCTION__, file_name, strerror(errno));
890 + return strdup("");
891 + }
892 +
893 + err = md5_stream(file, md5sum_bin);
894 + if (err) {
895 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
896 + __FUNCTION__, file_name, strerror(err));
897 + return strdup("");
898 + }
899 +
900 + fclose(file);
901 +
902 + for (i=0; i < md5sum_bin_len; i++) {
903 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
904 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
905 + }
906 +
907 + md5sum_hex[md5sum_hex_len] = '\0';
908 +
909 + return md5sum_hex;
910 +}
911 +
912 diff -ruN busybox-1.00-orig/archival/libipkg/file_util.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.h
913 --- busybox-1.00-orig/archival/libipkg/file_util.h 1970-01-01 00:00:00.000000000 +0000
914 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.h 2005-07-17 16:10:23.000000000 +0000
915 @@ -0,0 +1,29 @@
916 +/* file_util.h - convenience routines for common file operations
917 +
918 + Carl D. Worth
919 +
920 + Copyright (C) 2001 University of Southern California
921 +
922 + This program is free software; you can redistribute it and/or
923 + modify it under the terms of the GNU General Public License as
924 + published by the Free Software Foundation; either version 2, or (at
925 + your option) any later version.
926 +
927 + This program is distributed in the hope that it will be useful, but
928 + WITHOUT ANY WARRANTY; without even the implied warranty of
929 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
930 + General Public License for more details.
931 +*/
932 +
933 +#ifndef FILE_UTIL_H
934 +#define FILE_UTIL_H
935 +
936 +int file_exists(const char *file_name);
937 +int file_is_dir(const char *file_name);
938 +char *file_read_line_alloc(FILE *file);
939 +int file_move(const char *src, const char *dest);
940 +int file_copy(const char *src, const char *dest);
941 +int file_mkdir_hier(const char *path, long mode);
942 +char *file_md5sum_alloc(const char *file_name);
943 +
944 +#endif
945 diff -ruN busybox-1.00-orig/archival/libipkg/hash_table.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.c
946 --- busybox-1.00-orig/archival/libipkg/hash_table.c 1970-01-01 00:00:00.000000000 +0000
947 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.c 2005-07-20 09:45:35.000000000 +0000
948 @@ -0,0 +1,155 @@
949 +/* hash.c - hash tables for ipkg
950 +
951 + Steven M. Ayer, Jamey Hicks
952 +
953 + Copyright (C) 2002 Compaq Computer Corporation
954 +
955 + This program is free software; you can redistribute it and/or
956 + modify it under the terms of the GNU General Public License as
957 + published by the Free Software Foundation; either version 2, or (at
958 + your option) any later version.
959 +
960 + This program is distributed in the hope that it will be useful, but
961 + WITHOUT ANY WARRANTY; without even the implied warranty of
962 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
963 + General Public License for more details.
964 +*/
965 +
966 +#include <errno.h>
967 +#include <stdio.h>
968 +#include <stdlib.h>
969 +#include <string.h>
970 +#include "hash_table.h"
971 +#include "ipkg_message.h"
972 +
973 +
974 +static int hash_index(hash_table_t *hash, const char *pkg_name);
975 +static int rotating(const char *key, int len, int prime);
976 +
977 +static int hash_index(hash_table_t *hash, const char *pkg_name)
978 +{
979 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
980 +}
981 +
982 +static int rotating(const char *key, int len, int prime)
983 +{
984 + unsigned int hash, i;
985 + for (hash=len, i=0; i<len; ++i)
986 + hash = (hash<<4)^(hash>>28)^key[i];
987 + return (hash % prime);
988 +}
989 +
990 +
991 +/*
992 + * this is an open table keyed by strings
993 + */
994 +int hash_table_init(const char *name, hash_table_t *hash, int len)
995 +{
996 + static int primes_table[] = {
997 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
998 + 19471, 23143, 33961, 46499, 49727, 99529, 0
999 + };
1000 + int *picker;
1001 +
1002 + if (hash->entries != NULL) {
1003 + /* we have been here already */
1004 + return 0;
1005 + }
1006 +
1007 + hash->name = name;
1008 + hash->entries = NULL;
1009 + hash->n_entries = 0;
1010 + hash->hash_entry_key = NULL;
1011 +
1012 + picker = primes_table;
1013 + while(*picker && (*picker++ < len));
1014 + if(!*picker)
1015 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1016 + --picker;
1017 +
1018 + hash->n_entries = *picker;
1019 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1020 + if (hash->entries == NULL) {
1021 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1022 + return ENOMEM;
1023 + }
1024 + return 0;
1025 +}
1026 +
1027 +void hash_table_deinit(hash_table_t *hash)
1028 +{
1029 + free(hash->entries);
1030 + hash->entries = NULL;
1031 + hash->n_entries = 0;
1032 +}
1033 +
1034 +void *hash_table_get(hash_table_t *hash, const char *key)
1035 +{
1036 + int ndx= hash_index(hash, key);
1037 + hash_entry_t *hash_entry = hash->entries + ndx;
1038 + while (hash_entry)
1039 + {
1040 + if (hash_entry->key)
1041 + {
1042 + if (strcmp(key, hash_entry->key) == 0) {
1043 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1044 + return hash_entry->data;
1045 + }
1046 + }
1047 + hash_entry = hash_entry->next;
1048 + }
1049 + return NULL;
1050 +}
1051 +
1052 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1053 +{
1054 + int ndx= hash_index(hash, key);
1055 + hash_entry_t *hash_entry = hash->entries + ndx;
1056 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1057 + if (hash_entry->key) {
1058 + if (strcmp(hash_entry->key, key) == 0) {
1059 + /* alread in table, update the value */
1060 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1061 + hash_entry->data = value;
1062 + return 0;
1063 + } else {
1064 + /*
1065 + * if this is a collision, we have to go to the end of the ll,
1066 + * then add a new entry
1067 + * before we can hook up the value
1068 + */
1069 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1070 + while (hash_entry->next)
1071 + hash_entry = hash_entry->next;
1072 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1073 + if (!hash_entry->next) {
1074 + return -ENOMEM;
1075 + }
1076 + hash_entry = hash_entry->next;
1077 + hash_entry->next = NULL;
1078 + }
1079 + }
1080 + hash->n_elements++;
1081 + hash_entry->key = strdup(key);
1082 + hash_entry->data = value;
1083 +
1084 + return 0;
1085 +}
1086 +
1087 +
1088 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1089 +{
1090 + int i;
1091 + if (!hash || !f)
1092 + return;
1093 +
1094 + for (i = 0; i < hash->n_entries; i++) {
1095 + hash_entry_t *hash_entry = (hash->entries + i);
1096 + do {
1097 + if(hash_entry->key) {
1098 + f(hash_entry->key, hash_entry->data, data);
1099 + }
1100 + } while((hash_entry = hash_entry->next));
1101 + }
1102 +}
1103 +
1104 diff -ruN busybox-1.00-orig/archival/libipkg/hash_table.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.h
1105 --- busybox-1.00-orig/archival/libipkg/hash_table.h 1970-01-01 00:00:00.000000000 +0000
1106 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.h 2005-07-17 16:10:23.000000000 +0000
1107 @@ -0,0 +1,44 @@
1108 +/* hash.h - hash tables for ipkg
1109 +
1110 + Steven M. Ayer, Jamey Hicks
1111 +
1112 + Copyright (C) 2002 Compaq Computer Corporation
1113 +
1114 + This program is free software; you can redistribute it and/or
1115 + modify it under the terms of the GNU General Public License as
1116 + published by the Free Software Foundation; either version 2, or (at
1117 + your option) any later version.
1118 +
1119 + This program is distributed in the hope that it will be useful, but
1120 + WITHOUT ANY WARRANTY; without even the implied warranty of
1121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1122 + General Public License for more details.
1123 +*/
1124 +
1125 +#ifndef _HASH_TABLE_H_
1126 +#define _HASH_TABLE_H_
1127 +
1128 +typedef struct hash_entry hash_entry_t;
1129 +typedef struct hash_table hash_table_t;
1130 +
1131 +struct hash_entry {
1132 + const char * key;
1133 + void * data;
1134 + struct hash_entry * next;
1135 +};
1136 +
1137 +struct hash_table {
1138 + const char *name;
1139 + hash_entry_t * entries;
1140 + int n_entries; /* number of buckets */
1141 + int n_elements;
1142 + const char * (*hash_entry_key)(void * data);
1143 +};
1144 +
1145 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1146 +void hash_table_deinit(hash_table_t *hash);
1147 +void *hash_table_get(hash_table_t *hash, const char *key);
1148 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1149 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1150 +
1151 +#endif /* _HASH_TABLE_H_ */
1152 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg.h
1153 --- busybox-1.00-orig/archival/libipkg/ipkg.h 1970-01-01 00:00:00.000000000 +0000
1154 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg.h 2005-07-20 14:12:10.000000000 +0000
1155 @@ -0,0 +1,74 @@
1156 +/* ipkg.h - the itsy package management system
1157 +
1158 + Carl D. Worth
1159 +
1160 + Copyright (C) 2001 University of Southern California
1161 +
1162 + This program is free software; you can redistribute it and/or
1163 + modify it under the terms of the GNU General Public License as
1164 + published by the Free Software Foundation; either version 2, or (at
1165 + your option) any later version.
1166 +
1167 + This program is distributed in the hope that it will be useful, but
1168 + WITHOUT ANY WARRANTY; without even the implied warranty of
1169 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1170 + General Public License for more details.
1171 +*/
1172 +
1173 +#ifndef IPKG_H
1174 +#define IPKG_H
1175 +
1176 +/*
1177 +#ifdef HAVE_CONFIG_H
1178 +#include "config.h"
1179 +#endif
1180 +*/
1181 +
1182 +#if 0
1183 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1184 +#endif
1185 +
1186 +#include "ipkg_includes.h"
1187 +#include "ipkg_conf.h"
1188 +#include "ipkg_message.h"
1189 +
1190 +#define IPKG_PKG_EXTENSION ".ipk"
1191 +#define DPKG_PKG_EXTENSION ".deb"
1192 +
1193 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1194 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1195 +
1196 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1197 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1198 +#define IPKG_INFO_DIR_SUFFIX "info"
1199 +#define IPKG_STATUS_FILE_SUFFIX "status"
1200 +
1201 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1202 +
1203 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1204 +
1205 +#define IPKG_VERSION "0.99.152"
1206 +
1207 +
1208 +enum ipkg_error {
1209 + IPKG_SUCCESS = 0,
1210 + IPKG_PKG_DEPS_UNSATISFIED,
1211 + IPKG_PKG_IS_ESSENTIAL,
1212 + IPKG_PKG_HAS_DEPENDENTS,
1213 + IPKG_PKG_HAS_NO_CANDIDATE
1214 +};
1215 +typedef enum ipkg_error ipkg_error_t;
1216 +
1217 +extern int ipkg_state_changed;
1218 +
1219 +
1220 +struct errlist {
1221 + char * errmsg;
1222 + struct errlist * next;
1223 +} ;
1224 +
1225 +extern struct errlist* error_list;
1226 +
1227 +extern ipkg_conf_t *global_conf;
1228 +
1229 +#endif
1230 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_cmd.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.c
1231 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 00:00:00.000000000 +0000
1232 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.c 2005-07-20 10:42:05.000000000 +0000
1233 @@ -0,0 +1,1344 @@
1234 +/* ipkg_cmd.c - the itsy package management system
1235 +
1236 + Carl D. Worth
1237 +
1238 + Copyright (C) 2001 University of Southern California
1239 +
1240 + This program is free software; you can redistribute it and/or
1241 + modify it under the terms of the GNU General Public License as
1242 + published by the Free Software Foundation; either version 2, or (at
1243 + your option) any later version.
1244 +
1245 + This program is distributed in the hope that it will be useful, but
1246 + WITHOUT ANY WARRANTY; without even the implied warranty of
1247 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1248 + General Public License for more details.
1249 +*/
1250 +
1251 +#include <string.h>
1252 +
1253 +#include "ipkg.h"
1254 +#include <libgen.h>
1255 +#include <glob.h>
1256 +#include <errno.h>
1257 +#include <stdlib.h>
1258 +#include <unistd.h>
1259 +#include <signal.h>
1260 +#include <stdio.h>
1261 +
1262 +#include "ipkg_conf.h"
1263 +#include "ipkg_cmd.h"
1264 +#include "ipkg_message.h"
1265 +#include "pkg.h"
1266 +#include "pkg_dest.h"
1267 +#include "pkg_parse.h"
1268 +#include "sprintf_alloc.h"
1269 +#include "pkg.h"
1270 +#include "file_util.h"
1271 +#include "str_util.h"
1272 +#include "libbb.h"
1273 +#include "unarchive.h"
1274 +
1275 +#include <fnmatch.h>
1276 +
1277 +
1278 +#include "ipkg_download.h"
1279 +#include "ipkg_install.h"
1280 +#include "ipkg_upgrade.h"
1281 +#include "ipkg_remove.h"
1282 +#include "ipkg_configure.h"
1283 +#include "ipkg_message.h"
1284 +
1285 +#ifdef IPKG_LIB
1286 +#include "libipkg.h"
1287 +static void *p_userdata = NULL;
1288 +#endif
1289 +
1290 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1291 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1292 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +
1316 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1317 + array for easier maintenance */
1318 +static ipkg_cmd_t cmds[] = {
1319 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1320 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1321 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1322 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1323 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1324 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1325 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1326 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1327 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1328 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1329 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1330 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1331 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1332 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1333 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1334 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1335 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1336 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1337 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1338 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1341 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1342 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1343 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1344 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1345 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1346 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1347 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1348 +};
1349 +
1350 +int ipkg_state_changed;
1351 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1352 +{
1353 + if (ipkg_state_changed && !conf->noaction) {
1354 + ipkg_message(conf, IPKG_INFO,
1355 + " writing status file\n");
1356 + ipkg_conf_write_status_files(conf);
1357 + pkg_write_changed_filelists(conf);
1358 + } else {
1359 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1360 + }
1361 +}
1362 +
1363 +
1364 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1365 +
1366 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1367 +{
1368 + int i;
1369 + ipkg_cmd_t *cmd;
1370 +
1371 + for (i=0; i < num_cmds; i++) {
1372 + cmd = &cmds[i];
1373 + if (strcmp(name, cmd->name) == 0) {
1374 + return cmd;
1375 + }
1376 + }
1377 +
1378 + return NULL;
1379 +}
1380 +
1381 +#ifdef IPKG_LIB
1382 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1383 +{
1384 + int result;
1385 + p_userdata = userdata;
1386 +
1387 +
1388 + result = (cmd->fun)(conf, argc, argv);
1389 + if ( result == 0 ) {
1390 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1391 + } else {
1392 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1393 +
1394 + }
1395 + if ( error_list ) {
1396 + reverse_error_list(&error_list);
1397 +
1398 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1399 + /* Here we print the errors collected and free the list */
1400 + while (error_list != NULL) {
1401 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1402 + error_list = error_list->next;
1403 +
1404 + }
1405 + free_error_list(&error_list);
1406 +
1407 + }
1408 +
1409 + p_userdata = NULL;
1410 + return result;
1411 +}
1412 +#else
1413 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1414 +{
1415 + return (cmd->fun)(conf, argc, argv);
1416 +}
1417 +#endif
1418 +
1419 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1420 +{
1421 + int err;
1422 + int failures;
1423 + char *lists_dir;
1424 + pkg_src_list_elt_t *iter;
1425 + pkg_src_t *src;
1426 +
1427 +
1428 + if (conf->offline_root) {
1429 + sprintf_alloc(&lists_dir, "%s/%s",
1430 + conf->offline_root,
1431 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1432 + } else {
1433 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1434 + }
1435 +
1436 + if (! file_is_dir(lists_dir)) {
1437 + if (file_exists(lists_dir)) {
1438 + ipkg_message(conf, IPKG_ERROR,
1439 + "%s: ERROR: %s exists, but is not a directory\n",
1440 + __FUNCTION__, lists_dir);
1441 + free(lists_dir);
1442 + return EINVAL;
1443 + }
1444 + err = file_mkdir_hier(lists_dir, 0755);
1445 + if (err) {
1446 + ipkg_message(conf, IPKG_ERROR,
1447 + "%s: ERROR: failed to make directory %s: %s\n",
1448 + __FUNCTION__, lists_dir, strerror(errno));
1449 + free(lists_dir);
1450 + return EINVAL;
1451 + }
1452 + }
1453 +
1454 + failures = 0;
1455 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1456 + char *url, *list_file_name;
1457 +
1458 + src = iter->data;
1459 +
1460 + if (src->extra_data) /* debian style? */
1461 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1462 + src->gzip ? "Packages.gz" : "Packages");
1463 + else
1464 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1465 +
1466 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1467 + if (src->gzip) {
1468 + char *tmp;
1469 + char *tmp_file_name;
1470 + FILE *in, *out;
1471 +
1472 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1473 +
1474 + if (mkdtemp (tmp) == NULL) {
1475 + perror ("mkdtemp");
1476 + failures++;
1477 + continue;
1478 + }
1479 +
1480 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1481 + err = ipkg_download(conf, url, tmp_file_name);
1482 + if (err == 0) {
1483 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1484 + in = fopen (tmp_file_name, "r");
1485 + out = fopen (list_file_name, "w");
1486 + if (in && out)
1487 + inflate_unzip (in, out);
1488 + else
1489 + err = 1;
1490 + if (in)
1491 + fclose (in);
1492 + if (out)
1493 + fclose (out);
1494 + unlink (tmp_file_name);
1495 + rmdir (tmp);
1496 + free (tmp);
1497 + }
1498 + } else
1499 + err = ipkg_download(conf, url, list_file_name);
1500 + if (err) {
1501 + failures++;
1502 + } else {
1503 + ipkg_message(conf, IPKG_NOTICE,
1504 + "Updated list of available packages in %s\n",
1505 + list_file_name);
1506 + }
1507 + free(url);
1508 + free(list_file_name);
1509 + }
1510 + free(lists_dir);
1511 +
1512 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1513 +#warning here
1514 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1515 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1516 + * -Jamey 3/1/03
1517 + */
1518 + {
1519 + int i;
1520 + int changed = 0;
1521 + pkg_vec_t *available = pkg_vec_alloc();
1522 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1523 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1524 + for (i = 0; i < available->len; i++) {
1525 + pkg_t *pkg = available->pkgs[i];
1526 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1527 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1528 + pkg->state_want = SW_UNKNOWN;
1529 + changed = 1;
1530 + }
1531 + }
1532 + pkg_vec_free(available);
1533 + if (changed) {
1534 + write_status_files_if_changed(conf);
1535 + }
1536 + }
1537 +#endif
1538 +
1539 + return failures;
1540 +}
1541 +
1542 +
1543 +/* scan the args passed and cache the local filenames of the packages */
1544 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1545 +{
1546 + int i;
1547 + int err;
1548 +
1549 + /*
1550 + * First scan through package names/urls
1551 + * For any urls, download the packages and install in database.
1552 + * For any files, install package info in database.
1553 + */
1554 + for (i = 0; i < argc; i ++) {
1555 + char *filename = argv [i];
1556 + //char *tmp = basename (tmp);
1557 + //int tmplen = strlen (tmp);
1558 +
1559 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1560 + // continue;
1561 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1562 + // continue;
1563 +
1564 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1565 + if (err)
1566 + return err;
1567 + }
1568 + return 0;
1569 +}
1570 +
1571 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1572 +{
1573 + pkg_vec_t *all;
1574 + int i;
1575 + pkg_t *pkg;
1576 +
1577 + ipkg_message(conf, IPKG_INFO,
1578 + "Configuring unpacked packages\n");
1579 + fflush( stdout );
1580 +
1581 + all = pkg_vec_alloc();
1582 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1583 +
1584 + for(i = 0; i < all->len; i++) {
1585 + pkg = all->pkgs[i];
1586 +
1587 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1588 + continue;
1589 +
1590 + if (pkg->state_status == SS_UNPACKED) {
1591 + ipkg_message(conf, IPKG_NOTICE,
1592 + "Configuring %s\n", pkg->name);
1593 + fflush( stdout );
1594 + if (ipkg_configure(conf, pkg) == 0) {
1595 + pkg->state_status = SS_INSTALLED;
1596 + pkg->parent->state_status = SS_INSTALLED;
1597 + pkg->state_flag &= ~SF_PREFER;
1598 + }
1599 + }
1600 + }
1601 +
1602 + pkg_vec_free(all);
1603 + return 0;
1604 +}
1605 +
1606 +static void sigint_handler(int sig)
1607 +{
1608 + signal(sig, SIG_DFL);
1609 + ipkg_message(NULL, IPKG_NOTICE,
1610 + "ipkg: interrupted. writing out status database\n");
1611 + write_status_files_if_changed(global_conf);
1612 + exit(128 + sig);
1613 +}
1614 +
1615 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1616 +{
1617 + int i;
1618 + char *arg;
1619 + int err=0;
1620 +
1621 + global_conf = conf;
1622 + signal(SIGINT, sigint_handler);
1623 +
1624 + /*
1625 + * Now scan through package names and install
1626 + */
1627 + for (i=0; i < argc; i++) {
1628 + arg = argv[i];
1629 +
1630 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1631 + if (err != EINVAL && err != 0)
1632 + return err;
1633 + }
1634 + pkg_info_preinstall_check(conf);
1635 +
1636 + for (i=0; i < argc; i++) {
1637 + arg = argv[i];
1638 + if (conf->multiple_providers)
1639 + err = ipkg_install_multi_by_name(conf, arg);
1640 + else{
1641 + err = ipkg_install_by_name(conf, arg);
1642 + }
1643 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1644 + ipkg_message(conf, IPKG_ERROR,
1645 + "Cannot find package %s.\n"
1646 + "Check the spelling or perhaps run 'ipkg update'\n",
1647 + arg);
1648 + }
1649 + }
1650 +
1651 + /* recheck to verify that all dependences are satisfied */
1652 + if (0) ipkg_satisfy_all_dependences(conf);
1653 +
1654 + ipkg_configure_packages(conf, NULL);
1655 +
1656 + write_status_files_if_changed(conf);
1657 +
1658 + return err;
1659 +}
1660 +
1661 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1662 +{
1663 + int i;
1664 + pkg_t *pkg;
1665 + int err;
1666 +
1667 + global_conf = conf;
1668 + signal(SIGINT, sigint_handler);
1669 +
1670 + if (argc) {
1671 + for (i=0; i < argc; i++) {
1672 + char *arg = argv[i];
1673 +
1674 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1675 + if (err != EINVAL && err != 0)
1676 + return err;
1677 + }
1678 + pkg_info_preinstall_check(conf);
1679 +
1680 + for (i=0; i < argc; i++) {
1681 + char *arg = argv[i];
1682 + if (conf->restrict_to_default_dest) {
1683 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1684 + argv[i],
1685 + conf->default_dest);
1686 + if (pkg == NULL) {
1687 + ipkg_message(conf, IPKG_NOTICE,
1688 + "Package %s not installed in %s\n",
1689 + argv[i], conf->default_dest->name);
1690 + continue;
1691 + }
1692 + } else {
1693 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1694 + argv[i]);
1695 + }
1696 + if (pkg)
1697 + ipkg_upgrade_pkg(conf, pkg);
1698 + else {
1699 + ipkg_install_by_name(conf, arg);
1700 + }
1701 + }
1702 + } else {
1703 + pkg_vec_t *installed = pkg_vec_alloc();
1704 +
1705 + pkg_info_preinstall_check(conf);
1706 +
1707 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1708 + for (i = 0; i < installed->len; i++) {
1709 + pkg = installed->pkgs[i];
1710 + ipkg_upgrade_pkg(conf, pkg);
1711 + }
1712 + pkg_vec_free(installed);
1713 + }
1714 +
1715 + /* recheck to verify that all dependences are satisfied */
1716 + if (0) ipkg_satisfy_all_dependences(conf);
1717 +
1718 + ipkg_configure_packages(conf, NULL);
1719 +
1720 + write_status_files_if_changed(conf);
1721 +
1722 + return 0;
1723 +}
1724 +
1725 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1726 +{
1727 + int i, err;
1728 + char *arg;
1729 + pkg_t *pkg;
1730 +
1731 + pkg_info_preinstall_check(conf);
1732 + for (i = 0; i < argc; i++) {
1733 + arg = argv[i];
1734 +
1735 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1736 + if (pkg == NULL) {
1737 + ipkg_message(conf, IPKG_ERROR,
1738 + "Cannot find package %s.\n"
1739 + "Check the spelling or perhaps run 'ipkg update'\n",
1740 + arg);
1741 + continue;
1742 + }
1743 +
1744 + err = ipkg_download_pkg(conf, pkg, ".");
1745 +
1746 + if (err) {
1747 + ipkg_message(conf, IPKG_ERROR,
1748 + "Failed to download %s\n", pkg->name);
1749 + } else {
1750 + ipkg_message(conf, IPKG_NOTICE,
1751 + "Downloaded %s as %s\n",
1752 + pkg->name, pkg->local_filename);
1753 + }
1754 + }
1755 +
1756 + return 0;
1757 +}
1758 +
1759 +
1760 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1761 +{
1762 + int i ;
1763 + pkg_vec_t *available;
1764 + pkg_t *pkg;
1765 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1766 + char *newline;
1767 + char *pkg_name = NULL;
1768 + char *version_str;
1769 +
1770 + if (argc > 0) {
1771 + pkg_name = argv[0];
1772 + }
1773 + available = pkg_vec_alloc();
1774 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1775 + for (i=0; i < available->len; i++) {
1776 + pkg = available->pkgs[i];
1777 + /* if we have package name or pattern and pkg does not match, then skip it */
1778 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1779 + continue;
1780 + if (pkg->description) {
1781 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1782 + } else {
1783 + desc_short[0] = '\0';
1784 + }
1785 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1786 + newline = strchr(desc_short, '\n');
1787 + if (newline) {
1788 + *newline = '\0';
1789 + }
1790 +#ifndef IPKG_LIB
1791 + printf("%s - %s\n", pkg->name, desc_short);
1792 +#else
1793 + if (ipkg_cb_list) {
1794 + version_str = pkg_version_str_alloc(pkg);
1795 + ipkg_cb_list(pkg->name,desc_short,
1796 + version_str,
1797 + pkg->state_status,
1798 + p_userdata);
1799 + free(version_str);
1800 + }
1801 +#endif
1802 + }
1803 + pkg_vec_free(available);
1804 +
1805 + return 0;
1806 +}
1807 +
1808 +
1809 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1810 +{
1811 + int i ;
1812 + pkg_vec_t *available;
1813 + pkg_t *pkg;
1814 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1815 + char *newline;
1816 + char *pkg_name = NULL;
1817 + char *version_str;
1818 +
1819 + if (argc > 0) {
1820 + pkg_name = argv[0];
1821 + }
1822 + available = pkg_vec_alloc();
1823 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1824 + for (i=0; i < available->len; i++) {
1825 + pkg = available->pkgs[i];
1826 + /* if we have package name or pattern and pkg does not match, then skip it */
1827 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1828 + continue;
1829 + if (pkg->description) {
1830 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1831 + } else {
1832 + desc_short[0] = '\0';
1833 + }
1834 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1835 + newline = strchr(desc_short, '\n');
1836 + if (newline) {
1837 + *newline = '\0';
1838 + }
1839 +#ifndef IPKG_LIB
1840 + printf("%s - %s\n", pkg->name, desc_short);
1841 +#else
1842 + if (ipkg_cb_list) {
1843 + version_str = pkg_version_str_alloc(pkg);
1844 + ipkg_cb_list(pkg->name,desc_short,
1845 + version_str,
1846 + pkg->state_status,
1847 + p_userdata);
1848 + free(version_str);
1849 + }
1850 +#endif
1851 + }
1852 +
1853 + return 0;
1854 +}
1855 +
1856 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1857 +{
1858 + int i;
1859 + pkg_vec_t *available;
1860 + pkg_t *pkg;
1861 + char *pkg_name = NULL;
1862 + char **pkg_fields = NULL;
1863 + int n_fields = 0;
1864 + char *buff ; // = (char *)malloc(1);
1865 +
1866 + if (argc > 0) {
1867 + pkg_name = argv[0];
1868 + }
1869 + if (argc > 1) {
1870 + pkg_fields = &argv[1];
1871 + n_fields = argc - 1;
1872 + }
1873 +
1874 + available = pkg_vec_alloc();
1875 + if (installed_only)
1876 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1877 + else
1878 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1879 + for (i=0; i < available->len; i++) {
1880 + pkg = available->pkgs[i];
1881 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1882 + continue;
1883 + }
1884 +#ifndef IPKG_LIB
1885 + if (n_fields) {
1886 + for (j = 0; j < n_fields; j++)
1887 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1888 + } else {
1889 + pkg_print_info(pkg, stdout);
1890 + }
1891 +#else
1892 +
1893 + buff = pkg_formatted_info(pkg);
1894 + if ( buff ) {
1895 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1896 + pkg->state_status,
1897 + buff,
1898 + p_userdata);
1899 +/*
1900 + We should not forget that actually the pointer is allocated.
1901 + We need to free it :) ( Thanks florian for seeing the error )
1902 +*/
1903 + free(buff);
1904 + }
1905 +#endif
1906 + if (conf->verbosity > 1) {
1907 + conffile_list_elt_t *iter;
1908 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1909 + conffile_t *cf = iter->data;
1910 + int modified = conffile_has_been_modified(conf, cf);
1911 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1912 + cf->name, cf->value, modified);
1913 + }
1914 + }
1915 + }
1916 +#ifndef IPKG_LIB
1917 + if (buff)
1918 + free(buff);
1919 +#endif
1920 + pkg_vec_free(available);
1921 +
1922 + return 0;
1923 +}
1924 +
1925 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1926 +{
1927 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1928 +}
1929 +
1930 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1931 +{
1932 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1933 +}
1934 +
1935 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1936 +{
1937 +
1938 + int err;
1939 + if (argc > 0) {
1940 + char *pkg_name = NULL;
1941 +
1942 + pkg_name = argv[0];
1943 +
1944 + err = ipkg_configure_packages (conf, pkg_name);
1945 +
1946 + } else {
1947 + err = ipkg_configure_packages (conf, NULL);
1948 + }
1949 +
1950 + write_status_files_if_changed(conf);
1951 +
1952 + return err;
1953 +}
1954 +
1955 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1956 +{
1957 + int i, err;
1958 + char *globpattern;
1959 + glob_t globbuf;
1960 +
1961 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1962 + err = glob(globpattern, 0, NULL, &globbuf);
1963 + free(globpattern);
1964 + if (err) {
1965 + return 0;
1966 + }
1967 +
1968 + ipkg_message(conf, IPKG_NOTICE,
1969 + "The following packages in %s will now be installed.\n",
1970 + conf->pending_dir);
1971 + for (i = 0; i < globbuf.gl_pathc; i++) {
1972 + ipkg_message(conf, IPKG_NOTICE,
1973 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1974 + }
1975 + ipkg_message(conf, IPKG_NOTICE, "\n");
1976 + for (i = 0; i < globbuf.gl_pathc; i++) {
1977 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1978 + if (err == 0) {
1979 + err = unlink(globbuf.gl_pathv[i]);
1980 + if (err) {
1981 + ipkg_message(conf, IPKG_ERROR,
1982 + "%s: ERROR: failed to unlink %s: %s\n",
1983 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1984 + return err;
1985 + }
1986 + }
1987 + }
1988 + globfree(&globbuf);
1989 +
1990 + return err;
1991 +}
1992 +
1993 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1994 +{
1995 + int i,a,done;
1996 + pkg_t *pkg;
1997 + pkg_t *pkg_to_remove;
1998 + pkg_vec_t *available;
1999 + char *pkg_name = NULL;
2000 + global_conf = conf;
2001 + signal(SIGINT, sigint_handler);
2002 +
2003 +// ENH: Add the "no pkg removed" just in case.
2004 +
2005 + done = 0;
2006 +
2007 + available = pkg_vec_alloc();
2008 + pkg_info_preinstall_check(conf);
2009 + if ( argc > 0 ) {
2010 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2011 + for (i=0; i < argc; i++) {
2012 + pkg_name = malloc(strlen(argv[i])+2);
2013 + strcpy(pkg_name,argv[i]);
2014 + for (a=0; a < available->len; a++) {
2015 + pkg = available->pkgs[a];
2016 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2017 + continue;
2018 + }
2019 + if (conf->restrict_to_default_dest) {
2020 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2021 + pkg->name,
2022 + conf->default_dest);
2023 + } else {
2024 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2025 + }
2026 +
2027 + if (pkg == NULL) {
2028 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2029 + continue;
2030 + }
2031 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2032 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2033 + continue;
2034 + }
2035 + ipkg_remove_pkg(conf, pkg_to_remove);
2036 + done = 1;
2037 + }
2038 + free (pkg_name);
2039 + }
2040 + pkg_vec_free(available);
2041 + } else {
2042 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2043 + int i;
2044 + int flagged_pkg_count = 0;
2045 + int removed;
2046 +
2047 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2048 +
2049 + for (i = 0; i < installed_pkgs->len; i++) {
2050 + pkg_t *pkg = installed_pkgs->pkgs[i];
2051 + if (pkg->state_flag & SF_USER) {
2052 + flagged_pkg_count++;
2053 + } else {
2054 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2055 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2056 + }
2057 + }
2058 + if (!flagged_pkg_count) {
2059 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2060 + "so refusing to uninstall unflagged non-leaf packages\n");
2061 + return 0;
2062 + }
2063 +
2064 + /* find packages not flagged SF_USER (i.e., installed to
2065 + * satisfy a dependence) and not having any dependents, and
2066 + * remove them */
2067 + do {
2068 + removed = 0;
2069 + for (i = 0; i < installed_pkgs->len; i++) {
2070 + pkg_t *pkg = installed_pkgs->pkgs[i];
2071 + if (!(pkg->state_flag & SF_USER)
2072 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2073 + removed++;
2074 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2075 + ipkg_remove_pkg(conf, pkg);
2076 + done = 1;
2077 + }
2078 + }
2079 + } while (removed);
2080 + pkg_vec_free(installed_pkgs);
2081 + }
2082 +
2083 + if ( done == 0 )
2084 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2085 +
2086 + write_status_files_if_changed(conf);
2087 + return 0;
2088 +}
2089 +
2090 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2091 +{
2092 + int i;
2093 + pkg_t *pkg;
2094 +
2095 + global_conf = conf;
2096 + signal(SIGINT, sigint_handler);
2097 +
2098 + pkg_info_preinstall_check(conf);
2099 +
2100 + for (i=0; i < argc; i++) {
2101 + if (conf->restrict_to_default_dest) {
2102 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2103 + argv[i],
2104 + conf->default_dest);
2105 + } else {
2106 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2107 + }
2108 +
2109 + if (pkg == NULL) {
2110 + ipkg_message(conf, IPKG_ERROR,
2111 + "Package %s is not installed.\n", argv[i]);
2112 + continue;
2113 + }
2114 + ipkg_purge_pkg(conf, pkg);
2115 + }
2116 +
2117 + write_status_files_if_changed(conf);
2118 + return 0;
2119 +}
2120 +
2121 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2122 +{
2123 + int i;
2124 + pkg_t *pkg;
2125 + const char *flags = argv[0];
2126 +
2127 + global_conf = conf;
2128 + signal(SIGINT, sigint_handler);
2129 +
2130 + for (i=1; i < argc; i++) {
2131 + if (conf->restrict_to_default_dest) {
2132 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2133 + argv[i],
2134 + conf->default_dest);
2135 + } else {
2136 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2137 + }
2138 +
2139 + if (pkg == NULL) {
2140 + ipkg_message(conf, IPKG_ERROR,
2141 + "Package %s is not installed.\n", argv[i]);
2142 + continue;
2143 + }
2144 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2145 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2146 + pkg->state_flag = pkg_state_flag_from_str(flags);
2147 + }
2148 +/* pb_ asked this feature 03292004 */
2149 +/* Actually I will use only this two, but this is an open for various status */
2150 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2151 + pkg->state_status = pkg_state_status_from_str(flags);
2152 + }
2153 + ipkg_state_changed++;
2154 + ipkg_message(conf, IPKG_NOTICE,
2155 + "Setting flags for package %s to %s\n",
2156 + pkg->name, flags);
2157 + }
2158 +
2159 + write_status_files_if_changed(conf);
2160 + return 0;
2161 +}
2162 +
2163 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2164 +{
2165 + pkg_t *pkg;
2166 + str_list_t *installed_files;
2167 + str_list_elt_t *iter;
2168 + char *pkg_version;
2169 + size_t buff_len = 8192;
2170 + size_t used_len;
2171 + char *buff ;
2172 +
2173 + buff = (char *)malloc(buff_len);
2174 + if ( buff == NULL ) {
2175 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2176 + return ENOMEM;
2177 + }
2178 +
2179 + if (argc < 1) {
2180 + return EINVAL;
2181 + }
2182 +
2183 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2184 + argv[0]);
2185 + if (pkg == NULL) {
2186 + ipkg_message(conf, IPKG_ERROR,
2187 + "Package %s not installed.\n", argv[0]);
2188 + return 0;
2189 + }
2190 +
2191 + installed_files = pkg_get_installed_files(pkg);
2192 + pkg_version = pkg_version_str_alloc(pkg);
2193 +
2194 +#ifndef IPKG_LIB
2195 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2196 + pkg->name, pkg_version, pkg->dest->name);
2197 + for (iter = installed_files->head; iter; iter = iter->next) {
2198 + puts(iter->data);
2199 + }
2200 +#else
2201 + if (buff) {
2202 + try_again:
2203 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2204 + pkg->name, pkg_version, pkg->dest->name) + 1;
2205 + if (used_len > buff_len) {
2206 + buff_len *= 2;
2207 + buff = realloc (buff, buff_len);
2208 + goto try_again;
2209 + }
2210 + for (iter = installed_files->head; iter; iter = iter->next) {
2211 + used_len += strlen (iter->data) + 1;
2212 + while (buff_len <= used_len) {
2213 + buff_len *= 2;
2214 + buff = realloc (buff, buff_len);
2215 + }
2216 + strncat(buff, iter->data, buff_len);
2217 + strncat(buff, "\n", buff_len);
2218 + }
2219 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2220 + buff,
2221 + pkg_version_str_alloc(pkg),
2222 + pkg->state_status,
2223 + p_userdata);
2224 + free(buff);
2225 + }
2226 +#endif
2227 +
2228 + free(pkg_version);
2229 + pkg_free_installed_files(pkg);
2230 +
2231 + return 0;
2232 +}
2233 +
2234 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2235 +{
2236 +
2237 + if (argc > 0) {
2238 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2239 + const char *rel_str = "depends on";
2240 + int i;
2241 +
2242 + pkg_info_preinstall_check(conf);
2243 +
2244 + if (conf->query_all)
2245 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2246 + else
2247 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2248 + for (i = 0; i < argc; i++) {
2249 + const char *target = argv[i];
2250 + int j;
2251 +
2252 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2253 +
2254 + for (j = 0; j < available_pkgs->len; j++) {
2255 + pkg_t *pkg = available_pkgs->pkgs[j];
2256 + if (fnmatch(target, pkg->name, 0) == 0) {
2257 + int k;
2258 + int count = pkg->depends_count + pkg->pre_depends_count;
2259 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2260 + target, pkg->architecture, rel_str);
2261 + for (k = 0; k < count; k++) {
2262 + compound_depend_t *cdepend = &pkg->depends[k];
2263 + int l;
2264 + for (l = 0; l < cdepend->possibility_count; l++) {
2265 + depend_t *possibility = cdepend->possibilities[l];
2266 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2267 + if (conf->verbosity > 0) {
2268 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2269 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2270 + if (possibility->version) {
2271 + char *typestr = NULL;
2272 + switch (possibility->constraint) {
2273 + case NONE: typestr = "none"; break;
2274 + case EARLIER: typestr = "<"; break;
2275 + case EARLIER_EQUAL: typestr = "<="; break;
2276 + case EQUAL: typestr = "="; break;
2277 + case LATER_EQUAL: typestr = ">="; break;
2278 + case LATER: typestr = ">"; break;
2279 + }
2280 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2281 + }
2282 + // free(ver);
2283 + }
2284 + ipkg_message(conf, IPKG_ERROR, "\n");
2285 + }
2286 + }
2287 + }
2288 + }
2289 + }
2290 + pkg_vec_free(available_pkgs);
2291 + }
2292 + return 0;
2293 +}
2294 +
2295 +enum what_field_type {
2296 + WHATDEPENDS,
2297 + WHATCONFLICTS,
2298 + WHATPROVIDES,
2299 + WHATREPLACES,
2300 + WHATRECOMMENDS,
2301 + WHATSUGGESTS
2302 +};
2303 +
2304 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2305 +{
2306 +
2307 + if (argc > 0) {
2308 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2309 + const char *rel_str = NULL;
2310 + int i;
2311 + int changed;
2312 +
2313 + switch (what_field_type) {
2314 + case WHATDEPENDS: rel_str = "depends on"; break;
2315 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2316 + case WHATSUGGESTS: rel_str = "suggests"; break;
2317 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2318 + case WHATPROVIDES: rel_str = "provides"; break;
2319 + case WHATREPLACES: rel_str = "replaces"; break;
2320 + }
2321 +
2322 + if (conf->query_all)
2323 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2324 + else
2325 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2326 +
2327 + /* mark the root set */
2328 + pkg_vec_clear_marks(available_pkgs);
2329 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2330 + for (i = 0; i < argc; i++) {
2331 + const char *dependee_pattern = argv[i];
2332 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2333 + }
2334 + for (i = 0; i < available_pkgs->len; i++) {
2335 + pkg_t *pkg = available_pkgs->pkgs[i];
2336 + if (pkg->state_flag & SF_MARKED) {
2337 + /* mark the parent (abstract) package */
2338 + pkg_mark_provides(pkg);
2339 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2340 + }
2341 + }
2342 +
2343 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2344 + do {
2345 + int j;
2346 + changed = 0;
2347 +
2348 + for (j = 0; j < available_pkgs->len; j++) {
2349 + pkg_t *pkg = available_pkgs->pkgs[j];
2350 + int k;
2351 + int count = ((what_field_type == WHATCONFLICTS)
2352 + ? pkg->conflicts_count
2353 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2354 + /* skip this package if it is already marked */
2355 + if (pkg->parent->state_flag & SF_MARKED) {
2356 + continue;
2357 + }
2358 + for (k = 0; k < count; k++) {
2359 + compound_depend_t *cdepend =
2360 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2361 + int l;
2362 + for (l = 0; l < cdepend->possibility_count; l++) {
2363 + depend_t *possibility = cdepend->possibilities[l];
2364 + if (possibility->pkg->state_flag & SF_MARKED) {
2365 + /* mark the depending package so we won't visit it again */
2366 + pkg->state_flag |= SF_MARKED;
2367 + pkg_mark_provides(pkg);
2368 + changed++;
2369 +
2370 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2371 + if (conf->verbosity > 0) {
2372 + char *ver = pkg_version_str_alloc(pkg);
2373 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2374 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2375 + if (possibility->version) {
2376 + char *typestr = NULL;
2377 + switch (possibility->constraint) {
2378 + case NONE: typestr = "none"; break;
2379 + case EARLIER: typestr = "<"; break;
2380 + case EARLIER_EQUAL: typestr = "<="; break;
2381 + case EQUAL: typestr = "="; break;
2382 + case LATER_EQUAL: typestr = ">="; break;
2383 + case LATER: typestr = ">"; break;
2384 + }
2385 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2386 + }
2387 + free(ver);
2388 + if (!pkg_dependence_satisfiable(conf, possibility))
2389 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2390 + }
2391 + ipkg_message(conf, IPKG_NOTICE, "\n");
2392 + goto next_package;
2393 + }
2394 + }
2395 + }
2396 + next_package:
2397 + ;
2398 + }
2399 + } while (changed && recursive);
2400 + pkg_vec_free(available_pkgs);
2401 + }
2402 +
2403 + return 0;
2404 +}
2405 +
2406 +int pkg_mark_provides(pkg_t *pkg)
2407 +{
2408 + int provides_count = pkg->provides_count;
2409 + abstract_pkg_t **provides = pkg->provides;
2410 + int i;
2411 + pkg->parent->state_flag |= SF_MARKED;
2412 + for (i = 0; i < provides_count; i++) {
2413 + provides[i]->state_flag |= SF_MARKED;
2414 + }
2415 + return 0;
2416 +}
2417 +
2418 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2419 +{
2420 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2421 +}
2422 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2423 +{
2424 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2425 +}
2426 +
2427 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2428 +{
2429 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2430 +}
2431 +
2432 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2433 +{
2434 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2435 +}
2436 +
2437 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2438 +{
2439 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2440 +}
2441 +
2442 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2443 +{
2444 +
2445 + if (argc > 0) {
2446 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2447 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2448 + int i;
2449 +
2450 + pkg_info_preinstall_check(conf);
2451 +
2452 + if (conf->query_all)
2453 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2454 + else
2455 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2456 + for (i = 0; i < argc; i++) {
2457 + const char *target = argv[i];
2458 + int j;
2459 +
2460 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2461 + rel_str, target);
2462 + for (j = 0; j < available_pkgs->len; j++) {
2463 + pkg_t *pkg = available_pkgs->pkgs[j];
2464 + int k;
2465 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2466 + for (k = 0; k < count; k++) {
2467 + abstract_pkg_t *apkg =
2468 + ((what_field_type == WHATPROVIDES)
2469 + ? pkg->provides[k]
2470 + : pkg->replaces[k]);
2471 + if (fnmatch(target, apkg->name, 0) == 0) {
2472 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2473 + if (strcmp(target, apkg->name) != 0)
2474 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2475 + ipkg_message(conf, IPKG_ERROR, "\n");
2476 + }
2477 + }
2478 + }
2479 + }
2480 + pkg_vec_free(available_pkgs);
2481 + }
2482 + return 0;
2483 +}
2484 +
2485 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2486 +{
2487 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2488 +}
2489 +
2490 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2491 +{
2492 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2493 +}
2494 +
2495 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2496 +{
2497 + int i;
2498 +
2499 + pkg_vec_t *installed;
2500 + pkg_t *pkg;
2501 + str_list_t *installed_files;
2502 + str_list_elt_t *iter;
2503 + char *installed_file;
2504 +
2505 + if (argc < 1) {
2506 + return EINVAL;
2507 + }
2508 +
2509 + installed = pkg_vec_alloc();
2510 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2511 +
2512 + for (i=0; i < installed->len; i++) {
2513 + pkg = installed->pkgs[i];
2514 +
2515 + installed_files = pkg_get_installed_files(pkg);
2516 +
2517 + for (iter = installed_files->head; iter; iter = iter->next) {
2518 + installed_file = iter->data;
2519 + if (fnmatch(argv[0], installed_file, 0)==0) {
2520 +#ifndef IPKG_LIB
2521 + printf("%s: %s\n", pkg->name, installed_file);
2522 +#else
2523 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2524 + installed_file,
2525 + pkg_version_str_alloc(pkg),
2526 + pkg->state_status, p_userdata);
2527 +#endif
2528 + }
2529 + }
2530 +
2531 + pkg_free_installed_files(pkg);
2532 + }
2533 +
2534 + /* XXX: CLEANUP: It's not obvious from the name of
2535 + pkg_hash_fetch_all_installed that we need to call
2536 + pkg_vec_free to avoid a memory leak. */
2537 + pkg_vec_free(installed);
2538 +
2539 + return 0;
2540 +}
2541 +
2542 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2543 +{
2544 + if (argc == 3) {
2545 + /* this is a bit gross */
2546 + struct pkg p1, p2;
2547 + parseVersion(&p1, argv[0]);
2548 + parseVersion(&p2, argv[2]);
2549 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2550 + } else {
2551 + ipkg_message(conf, IPKG_ERROR,
2552 + "ipkg compare_versions <v1> <op> <v2>\n"
2553 + "<op> is one of <= >= << >> =\n");
2554 + return -1;
2555 + }
2556 +}
2557 +
2558 +#ifndef HOST_CPU_STR
2559 +#define HOST_CPU_STR__(X) #X
2560 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2561 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2562 +#endif
2563 +
2564 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2565 +{
2566 + nv_pair_list_elt_t *l;
2567 +
2568 + l = conf->arch_list.head;
2569 + while (l) {
2570 + nv_pair_t *nv = l->data;
2571 + printf("arch %s %s\n", nv->name, nv->value);
2572 + l = l->next;
2573 + }
2574 + return 0;
2575 +}
2576 +
2577 +
2578 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_cmd.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.h
2579 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 00:00:00.000000000 +0000
2580 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.h 2005-07-17 16:10:23.000000000 +0000
2581 @@ -0,0 +1,46 @@
2582 +/* ipkg_cmd.h - the itsy package management system
2583 +
2584 + Carl D. Worth
2585 +
2586 + Copyright (C) 2001 University of Southern California
2587 +
2588 + This program is free software; you can redistribute it and/or
2589 + modify it under the terms of the GNU General Public License as
2590 + published by the Free Software Foundation; either version 2, or (at
2591 + your option) any later version.
2592 +
2593 + This program is distributed in the hope that it will be useful, but
2594 + WITHOUT ANY WARRANTY; without even the implied warranty of
2595 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2596 + General Public License for more details.
2597 +*/
2598 +
2599 +#ifndef IPKG_CMD_H
2600 +#define IPKG_CMD_H
2601 +
2602 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2603 +
2604 +struct ipkg_cmd
2605 +{
2606 + char *name;
2607 + int requires_args;
2608 + ipkg_cmd_fun_t fun;
2609 +};
2610 +typedef struct ipkg_cmd ipkg_cmd_t;
2611 +
2612 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2613 +#ifdef IPKG_LIB
2614 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2615 + const char **argv, void *userdata);
2616 +#else
2617 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2618 +#endif
2619 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2620 +/* install any packges with state_want == SW_INSTALL */
2621 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2622 +/* ensure that all dependences are satisfied */
2623 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2624 +
2625 +int pkg_mark_provides(pkg_t *pkg);
2626 +
2627 +#endif
2628 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_conf.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.c
2629 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.c 1970-01-01 00:00:00.000000000 +0000
2630 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.c 2005-07-20 17:31:15.430275016 +0000
2631 @@ -0,0 +1,709 @@
2632 +/* ipkg_conf.c - the itsy package management system
2633 +
2634 + Carl D. Worth
2635 +
2636 + Copyright (C) 2001 University of Southern California
2637 +
2638 + This program is free software; you can redistribute it and/or
2639 + modify it under the terms of the GNU General Public License as
2640 + published by the Free Software Foundation; either version 2, or (at
2641 + your option) any later version.
2642 +
2643 + This program is distributed in the hope that it will be useful, but
2644 + WITHOUT ANY WARRANTY; without even the implied warranty of
2645 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2646 + General Public License for more details.
2647 +*/
2648 +
2649 +#include <glob.h>
2650 +
2651 +#include "ipkg.h"
2652 +#include "ipkg_conf.h"
2653 +
2654 +#include "xregex.h"
2655 +#include "sprintf_alloc.h"
2656 +#include "ipkg_conf.h"
2657 +#include "ipkg_message.h"
2658 +#include "file_util.h"
2659 +#include "str_util.h"
2660 +#include "xsystem.h"
2661 +
2662 +
2663 +ipkg_conf_t *global_conf;
2664 +
2665 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2666 + pkg_src_list_t *pkg_src_list,
2667 + nv_pair_list_t *tmp_dest_nv_pair_list,
2668 + char **tmp_lists_dir);
2669 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2670 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2671 + const char *name, const char *value);
2672 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2673 + const char *default_dest_name);
2674 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2675 + pkg_src_list_t *nv_pair_list);
2676 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2677 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2678 +
2679 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2680 +{
2681 + ipkg_option_t tmp[] = {
2682 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2683 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2684 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2685 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2686 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2687 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2688 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2689 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2690 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2691 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2692 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2693 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2694 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2695 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2696 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2697 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2698 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2699 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2700 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2701 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2702 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2703 + { NULL }
2704 + };
2705 +
2706 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2707 + if ( options == NULL ){
2708 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2709 + return -1;
2710 + }
2711 +
2712 + memcpy(*options, tmp, sizeof(tmp));
2713 + return 0;
2714 +};
2715 +
2716 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2717 +{
2718 + if (arg_str) {
2719 + if (*conf_str) {
2720 + free(*conf_str);
2721 + }
2722 + *conf_str = strdup(arg_str);
2723 + }
2724 +}
2725 +
2726 +static void ipkg_conf_free_string(char **conf_str)
2727 +{
2728 + if (*conf_str) {
2729 + free(*conf_str);
2730 + *conf_str = NULL;
2731 + }
2732 +}
2733 +
2734 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2735 +{
2736 + int err;
2737 + char *tmp_dir_base;
2738 + nv_pair_list_t tmp_dest_nv_pair_list;
2739 + char * lists_dir =NULL;
2740 + glob_t globbuf;
2741 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2742 + char *pending_dir =NULL;
2743 +
2744 + memset(conf, 0, sizeof(ipkg_conf_t));
2745 +
2746 + pkg_src_list_init(&conf->pkg_src_list);
2747 +
2748 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2749 + pkg_dest_list_init(&conf->pkg_dest_list);
2750 +
2751 + nv_pair_list_init(&conf->arch_list);
2752 +
2753 + conf->restrict_to_default_dest = 0;
2754 + conf->default_dest = NULL;
2755 +
2756 +
2757 + if (args->tmp_dir)
2758 + tmp_dir_base = args->tmp_dir;
2759 + else
2760 + tmp_dir_base = getenv("TMPDIR");
2761 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2762 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2763 + IPKG_CONF_TMP_DIR_SUFFIX);
2764 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2765 + if (conf->tmp_dir == NULL) {
2766 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2767 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2768 + return errno;
2769 + }
2770 +
2771 + conf->force_depends = 0;
2772 + conf->force_defaults = 0;
2773 + conf->force_overwrite = 0;
2774 + conf->force_downgrade = 0;
2775 + conf->force_reinstall = 0;
2776 + conf->force_space = 0;
2777 + conf->force_removal_of_essential_packages = 0;
2778 + conf->force_removal_of_dependent_packages = 0;
2779 + conf->nodeps = 0;
2780 + conf->verbose_wget = 0;
2781 + conf->offline_root = NULL;
2782 + conf->offline_root_pre_script_cmd = NULL;
2783 + conf->offline_root_post_script_cmd = NULL;
2784 + conf->multiple_providers = 0;
2785 + conf->verbosity = 1;
2786 + conf->noaction = 0;
2787 +
2788 + conf->http_proxy = NULL;
2789 + conf->ftp_proxy = NULL;
2790 + conf->no_proxy = NULL;
2791 + conf->proxy_user = NULL;
2792 + conf->proxy_passwd = NULL;
2793 +
2794 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2795 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2796 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + lists_dir=(char *)malloc(1);
2798 + lists_dir[0]='\0';
2799 + if (args->conf_file) {
2800 + struct stat stat_buf;
2801 + err = stat(args->conf_file, &stat_buf);
2802 + if (err == 0)
2803 + if (ipkg_conf_parse_file(conf, args->conf_file,
2804 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2805 + /* Memory leakage from ipkg_conf_parse-file */
2806 + return -1;
2807 + }
2808 +
2809 + }
2810 +
2811 + /* if (!lists_dir ){*/
2812 + if (strlen(lists_dir)<=1 ){
2813 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2814 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2815 + }
2816 +
2817 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2818 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2819 +
2820 + conf->lists_dir = strdup(lists_dir);
2821 + conf->pending_dir = strdup(pending_dir);
2822 +
2823 + if (args->offline_root)
2824 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2825 + memset(&globbuf, 0, sizeof(globbuf));
2826 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2827 + if (!err) {
2828 + int i;
2829 + for (i = 0; i < globbuf.gl_pathc; i++) {
2830 + if (globbuf.gl_pathv[i])
2831 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2832 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2833 + /* Memory leakage from ipkg_conf_parse-file */
2834 + return -1;
2835 + }
2836 + }
2837 + }
2838 + globfree(&globbuf);
2839 +
2840 + /* if no architectures were defined, then default all, noarch, and host architecture */
2841 + if (nv_pair_list_empty(&conf->arch_list)) {
2842 + nv_pair_list_append(&conf->arch_list, "all", "1");
2843 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2844 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2845 + }
2846 +
2847 + /* Even if there is no conf file, we'll need at least one dest. */
2848 + if (tmp_dest_nv_pair_list.head == NULL) {
2849 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2850 + IPKG_CONF_DEFAULT_DEST_NAME,
2851 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2852 + }
2853 +
2854 + /* After parsing the file, set options from command-line, (so that
2855 + command-line arguments take precedence) */
2856 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2857 + really needs to be cleaned up. There is so much duplication
2858 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2859 + a pointer to args_t (which could then not be freed), rather
2860 + than duplicating every field here? */
2861 + if (args->force_depends) {
2862 + conf->force_depends = 1;
2863 + }
2864 + if (args->force_defaults) {
2865 + conf->force_defaults = 1;
2866 + }
2867 + if (args->force_overwrite) {
2868 + conf->force_overwrite = 1;
2869 + }
2870 + if (args->force_downgrade) {
2871 + conf->force_downgrade = 1;
2872 + }
2873 + if (args->force_reinstall) {
2874 + conf->force_reinstall = 1;
2875 + }
2876 + if (args->force_removal_of_dependent_packages) {
2877 + conf->force_removal_of_dependent_packages = 1;
2878 + }
2879 + if (args->force_removal_of_essential_packages) {
2880 + conf->force_removal_of_essential_packages = 1;
2881 + }
2882 + if (args->nodeps) {
2883 + conf->nodeps = 1;
2884 + }
2885 + if (args->noaction) {
2886 + conf->noaction = 1;
2887 + }
2888 + if (args->query_all) {
2889 + conf->query_all = 1;
2890 + }
2891 + if (args->verbose_wget) {
2892 + conf->verbose_wget = 1;
2893 + }
2894 + if (args->multiple_providers) {
2895 + conf->multiple_providers = 1;
2896 + }
2897 + if (args->verbosity != conf->verbosity) {
2898 + conf->verbosity = args->verbosity;
2899 + }
2900 +
2901 + ipkg_conf_override_string(&conf->offline_root,
2902 + args->offline_root);
2903 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2904 + args->offline_root_pre_script_cmd);
2905 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2906 + args->offline_root_post_script_cmd);
2907 +
2908 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2909 + read anything from there.
2910 +*/
2911 + if ( !(args->nocheckfordirorfile)){
2912 + /* need to run load the source list before dest list -Jamey */
2913 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2914 +
2915 + /* Now that we have resolved conf->offline_root, we can commit to
2916 + the directory names for the dests and load in all the package
2917 + lists. */
2918 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2919 +
2920 + if (args->dest) {
2921 + err = ipkg_conf_set_default_dest(conf, args->dest);
2922 + if (err) {
2923 + return err;
2924 + }
2925 + }
2926 + }
2927 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2928 + free(lists_dir);
2929 + free(pending_dir);
2930 +
2931 + return 0;
2932 +}
2933 +
2934 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2935 +{
2936 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2937 +#error
2938 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2939 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2940 + __FUNCTION__, conf->tmp_dir);
2941 +#else
2942 + int err;
2943 +
2944 + err = rmdir(conf->tmp_dir);
2945 + if (err) {
2946 + if (errno == ENOTEMPTY) {
2947 + char *cmd;
2948 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2949 + err = xsystem(cmd);
2950 + free(cmd);
2951 + }
2952 + if (err)
2953 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2954 + }
2955 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2956 +
2957 + free(conf->tmp_dir); /*XXX*/
2958 +
2959 + pkg_src_list_deinit(&conf->pkg_src_list);
2960 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2961 + nv_pair_list_deinit(&conf->arch_list);
2962 + if (&conf->pkg_hash)
2963 + pkg_hash_deinit(&conf->pkg_hash);
2964 + if (&conf->file_hash)
2965 + hash_table_deinit(&conf->file_hash);
2966 + if (&conf->obs_file_hash)
2967 + hash_table_deinit(&conf->obs_file_hash);
2968 +
2969 + ipkg_conf_free_string(&conf->offline_root);
2970 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2971 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2972 +
2973 + if (conf->verbosity > 1) {
2974 + int i;
2975 + hash_table_t *hashes[] = {
2976 + &conf->pkg_hash,
2977 + &conf->file_hash,
2978 + &conf->obs_file_hash };
2979 + for (i = 0; i < 3; i++) {
2980 + hash_table_t *hash = hashes[i];
2981 + int c = 0;
2982 + int n_conflicts = 0;
2983 + int j;
2984 + for (j = 0; j < hash->n_entries; j++) {
2985 + int len = 0;
2986 + hash_entry_t *e = &hash->entries[j];
2987 + if (e->next)
2988 + n_conflicts++;
2989 + while (e && e->key) {
2990 + len++;
2991 + e = e->next;
2992 + }
2993 + if (len > c)
2994 + c = len;
2995 + }
2996 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2997 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2998 + hash_table_deinit(hash);
2999 + }
3000 + }
3001 +}
3002 +
3003 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3004 + const char *default_dest_name)
3005 +{
3006 + pkg_dest_list_elt_t *iter;
3007 + pkg_dest_t *dest;
3008 +
3009 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3010 + dest = iter->data;
3011 + if (strcmp(dest->name, default_dest_name) == 0) {
3012 + conf->default_dest = dest;
3013 + conf->restrict_to_default_dest = 1;
3014 + return 0;
3015 + }
3016 + }
3017 +
3018 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3019 +
3020 + return 1;
3021 +}
3022 +
3023 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3024 +{
3025 + pkg_src_list_elt_t *iter;
3026 + pkg_src_t *src;
3027 + char *list_file;
3028 +
3029 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3030 + src = iter->data;
3031 + if (src == NULL) {
3032 + continue;
3033 + }
3034 + if (conf->offline_root) {
3035 + sprintf_alloc(&list_file, "%s/%s/%s",
3036 + conf->offline_root,
3037 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3038 + src->name);
3039 + } else {
3040 + sprintf_alloc(&list_file, "%s/%s",
3041 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3042 + src->name);
3043 + }
3044 +
3045 + if (file_exists(list_file)) {
3046 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3047 + }
3048 + free(list_file);
3049 + }
3050 +
3051 + return 0;
3052 +}
3053 +
3054 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3055 +{
3056 + nv_pair_list_elt_t *iter;
3057 + nv_pair_t *nv_pair;
3058 + pkg_dest_t *dest;
3059 + char *root_dir;
3060 +
3061 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3062 + nv_pair = iter->data;
3063 +
3064 + if (conf->offline_root) {
3065 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3066 + } else {
3067 + root_dir = strdup(nv_pair->value);
3068 + }
3069 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3070 + free(root_dir);
3071 + if (dest == NULL) {
3072 + continue;
3073 + }
3074 + if (conf->default_dest == NULL) {
3075 + conf->default_dest = dest;
3076 + }
3077 + if (file_exists(dest->status_file_name)) {
3078 + pkg_hash_add_from_file(conf, dest->status_file_name,
3079 + NULL, dest, 1);
3080 + }
3081 + }
3082 +
3083 + return 0;
3084 +}
3085 +
3086 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3087 + pkg_src_list_t *pkg_src_list,
3088 + nv_pair_list_t *tmp_dest_nv_pair_list,
3089 + char **lists_dir)
3090 +{
3091 + ipkg_option_t * options;
3092 + FILE *file = fopen(filename, "r");
3093 + regex_t valid_line_re, comment_re;
3094 +#define regmatch_size 12
3095 + regmatch_t regmatch[regmatch_size];
3096 +
3097 + if (ipkg_init_options_array(conf, &options)<0)
3098 + return ENOMEM;
3099 +
3100 + if (file == NULL) {
3101 + fprintf(stderr, "%s: failed to open %s: %s\n",
3102 + __FUNCTION__, filename, strerror(errno));
3103 + free(options);
3104 + return errno;
3105 + }
3106 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3107 +
3108 + xregcomp(&comment_re,
3109 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3110 + REG_EXTENDED);
3111 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3112 +
3113 + while(1) {
3114 + int line_num = 0;
3115 + char *line;
3116 + char *type, *name, *value, *extra;
3117 +
3118 + line = file_read_line_alloc(file);
3119 + line_num++;
3120 + if (line == NULL) {
3121 + break;
3122 + }
3123 +
3124 + str_chomp(line);
3125 +
3126 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3127 + goto NEXT_LINE;
3128 + }
3129 +
3130 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3131 + str_chomp(line);
3132 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3133 + filename, line_num, line);
3134 + goto NEXT_LINE;
3135 + }
3136 +
3137 + /* This has to be so ugly to deal with optional quotation marks */
3138 + if (regmatch[2].rm_so > 0) {
3139 + type = strndup(line + regmatch[2].rm_so,
3140 + regmatch[2].rm_eo - regmatch[2].rm_so);
3141 + } else {
3142 + type = strndup(line + regmatch[3].rm_so,
3143 + regmatch[3].rm_eo - regmatch[3].rm_so);
3144 + }
3145 + if (regmatch[5].rm_so > 0) {
3146 + name = strndup(line + regmatch[5].rm_so,
3147 + regmatch[5].rm_eo - regmatch[5].rm_so);
3148 + } else {
3149 + name = strndup(line + regmatch[6].rm_so,
3150 + regmatch[6].rm_eo - regmatch[6].rm_so);
3151 + }
3152 + if (regmatch[8].rm_so > 0) {
3153 + value = strndup(line + regmatch[8].rm_so,
3154 + regmatch[8].rm_eo - regmatch[8].rm_so);
3155 + } else {
3156 + value = strndup(line + regmatch[9].rm_so,
3157 + regmatch[9].rm_eo - regmatch[9].rm_so);
3158 + }
3159 + extra = NULL;
3160 + if (regmatch[11].rm_so > 0) {
3161 + extra = strndup (line + regmatch[11].rm_so,
3162 + regmatch[11].rm_eo - regmatch[11].rm_so);
3163 + }
3164 +
3165 + /* We use the tmp_dest_nv_pair_list below instead of
3166 + conf->pkg_dest_list because we might encounter an
3167 + offline_root option later and that would invalidate the
3168 + directories we would have computed in
3169 + pkg_dest_list_init. (We do a similar thing with
3170 + tmp_src_nv_pair_list for sake of symmetry.) */
3171 + if (strcmp(type, "option") == 0) {
3172 + ipkg_conf_set_option(options, name, value);
3173 + } else if (strcmp(type, "src") == 0) {
3174 + if (!nv_pair_list_find(pkg_src_list, name)) {
3175 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3176 + } else {
3177 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3178 + name, value);
3179 + }
3180 + } else if (strcmp(type, "src/gz") == 0) {
3181 + if (!nv_pair_list_find(pkg_src_list, name)) {
3182 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3183 + } else {
3184 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3185 + name, value);
3186 + }
3187 + } else if (strcmp(type, "dest") == 0) {
3188 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3189 + } else if (strcmp(type, "lists_dir") == 0) {
3190 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3191 + if (*lists_dir == NULL) {
3192 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3193 + free(options);
3194 + return EINVAL;
3195 + }
3196 + sprintf (*lists_dir,"%s",value);
3197 + } else if (strcmp(type, "arch") == 0) {
3198 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3199 + if (!value) {
3200 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3201 + value = strdup("10");
3202 + }
3203 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3204 + } else {
3205 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3206 + "parameter: %s %s %s\n", type, name, value);
3207 + free(options);
3208 + return EINVAL;
3209 + }
3210 +
3211 + free(type);
3212 + free(name);
3213 + free(value);
3214 + if (extra)
3215 + free (extra);
3216 +
3217 + NEXT_LINE:
3218 + free(line);
3219 + }
3220 +
3221 + free(options);
3222 + regfree(&comment_re);
3223 + regfree(&valid_line_re);
3224 + fclose(file);
3225 +
3226 + return 0;
3227 +}
3228 +
3229 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3230 + const char *name, const char *value)
3231 +{
3232 + int i = 0;
3233 + while (options[i].name) {
3234 + if (strcmp(options[i].name, name) == 0) {
3235 + switch (options[i].type) {
3236 + case IPKG_OPT_TYPE_BOOL:
3237 + *((int *)options[i].value) = 1;
3238 + return 0;
3239 + case IPKG_OPT_TYPE_INT:
3240 + if (value) {
3241 + *((int *)options[i].value) = atoi(value);
3242 + return 0;
3243 + } else {
3244 + printf("%s: Option %s need an argument\n",
3245 + __FUNCTION__, name);
3246 + return EINVAL;
3247 + }
3248 + case IPKG_OPT_TYPE_STRING:
3249 + if (value) {
3250 + *((char **)options[i].value) = strdup(value);
3251 + return 0;
3252 + } else {
3253 + printf("%s: Option %s need an argument\n",
3254 + __FUNCTION__, name);
3255 + return EINVAL;
3256 + }
3257 + }
3258 + }
3259 + i++;
3260 + }
3261 +
3262 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3263 + __FUNCTION__, name, value);
3264 + return EINVAL;
3265 +}
3266 +
3267 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3268 +{
3269 + pkg_dest_list_elt_t *iter;
3270 + pkg_dest_t *dest;
3271 + pkg_vec_t *all;
3272 + pkg_t *pkg;
3273 + register int i;
3274 + int err;
3275 +
3276 + if (conf->noaction)
3277 + return 0;
3278 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3279 + dest = iter->data;
3280 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3281 + if (dest->status_file == NULL) {
3282 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3283 + __FUNCTION__, dest->status_file_name, strerror(errno));
3284 + }
3285 + }
3286 +
3287 + all = pkg_vec_alloc();
3288 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3289 +
3290 + for(i = 0; i < all->len; i++) {
3291 + pkg = all->pkgs[i];
3292 + /* We don't need most uninstalled packages in the status file */
3293 + if (pkg->state_status == SS_NOT_INSTALLED
3294 + && (pkg->state_want == SW_UNKNOWN
3295 + || pkg->state_want == SW_DEINSTALL
3296 + || pkg->state_want == SW_PURGE)) {
3297 + continue;
3298 + }
3299 + if (!pkg) {
3300 + fprintf(stderr, "Null package\n");
3301 + }
3302 + if (pkg->dest == NULL) {
3303 + fprintf(stderr, "%s: ERROR: Can't write status for "
3304 + "package %s since it has a NULL dest\n",
3305 + __FUNCTION__, pkg->name);
3306 + continue;
3307 + }
3308 + if (pkg->dest->status_file) {
3309 + pkg_print_status(pkg, pkg->dest->status_file);
3310 + }
3311 + }
3312 +
3313 + pkg_vec_free(all);
3314 +
3315 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3316 + dest = iter->data;
3317 + if (dest->status_file) {
3318 + err = ferror(dest->status_file);
3319 + fclose(dest->status_file);
3320 + dest->status_file = NULL;
3321 + if (!err) {
3322 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3323 + } else {
3324 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3325 + "retaining old %s\n", __FUNCTION__,
3326 + dest->status_file_tmp_name, dest->status_file_name);
3327 + }
3328 + }
3329 + }
3330 +
3331 + return 0;
3332 +}
3333 +
3334 +
3335 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3336 +{
3337 + char *root_filename;
3338 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3339 + return root_filename;
3340 +}
3341 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_conf.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.h
3342 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.h 1970-01-01 00:00:00.000000000 +0000
3343 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.h 2005-07-19 00:48:24.000000000 +0000
3344 @@ -0,0 +1,107 @@
3345 +/* ipkg_conf.h - the itsy package management system
3346 +
3347 + Carl D. Worth
3348 +
3349 + Copyright (C) 2001 University of Southern California
3350 +
3351 + This program is free software; you can redistribute it and/or
3352 + modify it under the terms of the GNU General Public License as
3353 + published by the Free Software Foundation; either version 2, or (at
3354 + your option) any later version.
3355 +
3356 + This program is distributed in the hope that it will be useful, but
3357 + WITHOUT ANY WARRANTY; without even the implied warranty of
3358 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3359 + General Public License for more details.
3360 +*/
3361 +
3362 +#ifndef IPKG_CONF_H
3363 +#define IPKG_CONF_H
3364 +
3365 +typedef struct ipkg_conf ipkg_conf_t;
3366 +
3367 +#include "hash_table.h"
3368 +#include "ipkg.h"
3369 +#include "args.h"
3370 +#include "pkg.h"
3371 +#include "pkg_hash.h"
3372 +#include "pkg_src_list.h"
3373 +#include "pkg_dest_list.h"
3374 +#include "nv_pair_list.h"
3375 +
3376 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3377 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3378 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3379 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3380 +
3381 +/* In case the config file defines no dest */
3382 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3383 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3384 +
3385 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3386 +
3387 +struct ipkg_conf
3388 +{
3389 + pkg_src_list_t pkg_src_list;
3390 + pkg_dest_list_t pkg_dest_list;
3391 + nv_pair_list_t arch_list;
3392 +
3393 + int restrict_to_default_dest;
3394 + pkg_dest_t *default_dest;
3395 +
3396 + char *tmp_dir;
3397 + const char *lists_dir;
3398 + const char *pending_dir;
3399 +
3400 + /* options */
3401 + int force_depends;
3402 + int force_defaults;
3403 + int force_overwrite;
3404 + int force_downgrade;
3405 + int force_reinstall;
3406 + int force_space;
3407 + int force_removal_of_dependent_packages;
3408 + int force_removal_of_essential_packages;
3409 + int nodeps; /* do not follow dependences */
3410 + int verbose_wget;
3411 + int multiple_providers;
3412 + char *offline_root;
3413 + char *offline_root_pre_script_cmd;
3414 + char *offline_root_post_script_cmd;
3415 + int query_all;
3416 + int verbosity;
3417 + int noaction;
3418 +
3419 + /* proxy options */
3420 + char *http_proxy;
3421 + char *ftp_proxy;
3422 + char *no_proxy;
3423 + char *proxy_user;
3424 + char *proxy_passwd;
3425 +
3426 + hash_table_t pkg_hash;
3427 + hash_table_t file_hash;
3428 + hash_table_t obs_file_hash;
3429 +};
3430 +
3431 +enum ipkg_option_type {
3432 + IPKG_OPT_TYPE_BOOL,
3433 + IPKG_OPT_TYPE_INT,
3434 + IPKG_OPT_TYPE_STRING
3435 +};
3436 +typedef enum ipkg_option_type ipkg_option_type_t;
3437 +
3438 +typedef struct ipkg_option ipkg_option_t;
3439 +struct ipkg_option {
3440 + const char *name;
3441 + const ipkg_option_type_t type;
3442 + const void *value;
3443 +};
3444 +
3445 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3446 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3447 +
3448 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3449 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3450 +
3451 +#endif
3452 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_configure.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.c
3453 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.c 1970-01-01 00:00:00.000000000 +0000
3454 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.c 2005-07-17 16:10:23.000000000 +0000
3455 @@ -0,0 +1,40 @@
3456 +/* ipkg_configure.c - the itsy package management system
3457 +
3458 + Carl D. Worth
3459 +
3460 + Copyright (C) 2001 University of Southern California
3461 +
3462 + This program is free software; you can redistribute it and/or
3463 + modify it under the terms of the GNU General Public License as
3464 + published by the Free Software Foundation; either version 2, or (at
3465 + your option) any later version.
3466 +
3467 + This program is distributed in the hope that it will be useful, but
3468 + WITHOUT ANY WARRANTY; without even the implied warranty of
3469 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3470 + General Public License for more details.
3471 +*/
3472 +
3473 +#include "ipkg.h"
3474 +
3475 +#include "ipkg_configure.h"
3476 +
3477 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3478 +{
3479 + int err;
3480 +
3481 + /* DPKG_INCOMPATIBILITY:
3482 + dpkg actually does some conffile handling here, rather than at the
3483 + end of ipkg_install(). Do we care? */
3484 + /* DPKG_INCOMPATIBILITY:
3485 + dpkg actually includes a version number to this script call */
3486 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3487 + if (err) {
3488 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3489 + return err;
3490 + }
3491 +
3492 + ipkg_state_changed++;
3493 + return 0;
3494 +}
3495 +
3496 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_configure.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.h
3497 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.h 1970-01-01 00:00:00.000000000 +0000
3498 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.h 2005-07-17 16:10:23.000000000 +0000
3499 @@ -0,0 +1,25 @@
3500 +/* ipkg_configure.h - the itsy package management system
3501 +
3502 + Carl D. Worth
3503 +
3504 + Copyright (C) 2001 University of Southern California
3505 +
3506 + This program is free software; you can redistribute it and/or
3507 + modify it under the terms of the GNU General Public License as
3508 + published by the Free Software Foundation; either version 2, or (at
3509 + your option) any later version.
3510 +
3511 + This program is distributed in the hope that it will be useful, but
3512 + WITHOUT ANY WARRANTY; without even the implied warranty of
3513 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3514 + General Public License for more details.
3515 +*/
3516 +
3517 +#ifndef IPKG_CONFIGURE_H
3518 +#define IPKG_CONFIGURE_H
3519 +
3520 +#include "ipkg_conf.h"
3521 +
3522 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3523 +
3524 +#endif
3525 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_download.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.c
3526 --- busybox-1.00-orig/archival/libipkg/ipkg_download.c 1970-01-01 00:00:00.000000000 +0000
3527 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.c 2005-07-20 00:13:02.000000000 +0000
3528 @@ -0,0 +1,191 @@
3529 +/* ipkg_download.c - the itsy package management system
3530 +
3531 + Carl D. Worth
3532 +
3533 + Copyright (C) 2001 University of Southern California
3534 +
3535 + This program is free software; you can redistribute it and/or
3536 + modify it under the terms of the GNU General Public License as
3537 + published by the Free Software Foundation; either version 2, or (at
3538 + your option) any later version.
3539 +
3540 + This program is distributed in the hope that it will be useful, but
3541 + WITHOUT ANY WARRANTY; without even the implied warranty of
3542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3543 + General Public License for more details.
3544 +*/
3545 +
3546 +#include "ipkg.h"
3547 +#include "ipkg_download.h"
3548 +#include "ipkg_message.h"
3549 +
3550 +#include "sprintf_alloc.h"
3551 +#include "xsystem.h"
3552 +#include "file_util.h"
3553 +#include "str_util.h"
3554 +
3555 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3556 +{
3557 + int err = 0;
3558 +
3559 + char *src_basec = strdup(src);
3560 + char *src_base = basename(src_basec);
3561 + char *tmp_file_location;
3562 + char *cmd;
3563 +
3564 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3565 +
3566 + fflush(stdout);
3567 +
3568 + if (str_starts_with(src, "file:")) {
3569 + int ret;
3570 + const char *file_src = src + 5;
3571 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3572 + ret = file_copy(src + 5, dest_file_name);
3573 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3574 + return ret;
3575 + }
3576 +
3577 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3578 + err = unlink(tmp_file_location);
3579 + if (err && errno != ENOENT) {
3580 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3581 + __FUNCTION__, tmp_file_location, strerror(errno));
3582 + free(tmp_file_location);
3583 + return errno;
3584 + }
3585 +
3586 + if (conf->http_proxy) {
3587 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3588 + setenv("http_proxy", conf->http_proxy, 1);
3589 + }
3590 + if (conf->ftp_proxy) {
3591 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3592 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3593 + }
3594 + if (conf->no_proxy) {
3595 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3596 + setenv("no_proxy", conf->no_proxy, 1);
3597 + }
3598 +
3599 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3600 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3601 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3602 + conf->proxy_user ? "--proxy-user=" : "",
3603 + conf->proxy_user ? conf->proxy_user : "",
3604 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3605 + conf->proxy_passwd ? conf->proxy_passwd : "",
3606 + conf->verbose_wget ? "" : "-q",
3607 + conf->tmp_dir,
3608 + src);
3609 + err = xsystem(cmd);
3610 + if (err) {
3611 + if (err != -1) {
3612 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3613 + __FUNCTION__, err, cmd);
3614 + }
3615 + unlink(tmp_file_location);
3616 + free(tmp_file_location);
3617 + free(src_basec);
3618 + free(cmd);
3619 + return EINVAL;
3620 + }
3621 + free(cmd);
3622 +
3623 + err = file_move(tmp_file_location, dest_file_name);
3624 +
3625 + free(tmp_file_location);
3626 + free(src_basec);
3627 +
3628 + if (err) {
3629 + return err;
3630 + }
3631 +
3632 + return 0;
3633 +}
3634 +
3635 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3636 +{
3637 + int err;
3638 + char *url;
3639 +
3640 + if (pkg->src == NULL) {
3641 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3642 + pkg->name, pkg->parent->name);
3643 + return -1;
3644 + }
3645 +
3646 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3647 +
3648 + /* XXX: BUG: The pkg->filename might be something like
3649 + "../../foo.ipk". While this is correct, and exactly what we
3650 + want to use to construct url above, here we actually need to
3651 + use just the filename part, without any directory. */
3652 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3653 +
3654 + err = ipkg_download(conf, url, pkg->local_filename);
3655 + free(url);
3656 +
3657 + return err;
3658 +}
3659 +
3660 +/*
3661 + * Downloads file from url, installs in package database, return package name.
3662 + */
3663 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3664 +{
3665 + int err = 0;
3666 + pkg_t *pkg;
3667 + pkg = pkg_new();
3668 + if (pkg == NULL)
3669 + return ENOMEM;
3670 +
3671 + if (str_starts_with(url, "http://")
3672 + || str_starts_with(url, "ftp://")) {
3673 + char *tmp_file;
3674 + char *file_basec = strdup(url);
3675 + char *file_base = basename(file_basec);
3676 +
3677 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3678 + err = ipkg_download(conf, url, tmp_file);
3679 + if (err)
3680 + return err;
3681 +
3682 + err = pkg_init_from_file(pkg, tmp_file);
3683 + if (err)
3684 + return err;
3685 + pkg->local_filename = strdup(tmp_file);
3686 +
3687 + free(tmp_file);
3688 + free(file_basec);
3689 +
3690 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3691 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3692 +
3693 + err = pkg_init_from_file(pkg, url);
3694 + if (err)
3695 + return err;
3696 + pkg->local_filename = strdup(url);
3697 +
3698 + } else {
3699 + return 0;
3700 + }
3701 +
3702 + if (!pkg->architecture) {
3703 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3704 + return -EINVAL;
3705 + }
3706 +
3707 + pkg->dest = conf->default_dest;
3708 + pkg->state_want = SW_INSTALL;
3709 + pkg->state_flag |= SF_PREFER;
3710 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3711 + if ( pkg == NULL ){
3712 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3713 + return 0;
3714 + }
3715 + if (namep) {
3716 + *namep = pkg->name;
3717 + }
3718 + return 0;
3719 +}
3720 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_download.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.h
3721 --- busybox-1.00-orig/archival/libipkg/ipkg_download.h 1970-01-01 00:00:00.000000000 +0000
3722 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.h 2005-07-17 16:10:23.000000000 +0000
3723 @@ -0,0 +1,30 @@
3724 +/* ipkg_download.h - the itsy package management system
3725 +
3726 + Carl D. Worth
3727 +
3728 + Copyright (C) 2001 University of Southern California
3729 +
3730 + This program is free software; you can redistribute it and/or
3731 + modify it under the terms of the GNU General Public License as
3732 + published by the Free Software Foundation; either version 2, or (at
3733 + your option) any later version.
3734 +
3735 + This program is distributed in the hope that it will be useful, but
3736 + WITHOUT ANY WARRANTY; without even the implied warranty of
3737 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3738 + General Public License for more details.
3739 +*/
3740 +
3741 +#ifndef IPKG_DOWNLOAD_H
3742 +#define IPKG_DOWNLOAD_H
3743 +
3744 +#include "ipkg_conf.h"
3745 +
3746 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3747 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3748 +/*
3749 + * Downloads file from url, installs in package database, return package name.
3750 + */
3751 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3752 +
3753 +#endif
3754 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_includes.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_includes.h
3755 --- busybox-1.00-orig/archival/libipkg/ipkg_includes.h 1970-01-01 00:00:00.000000000 +0000
3756 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_includes.h 2005-07-20 09:16:48.000000000 +0000
3757 @@ -0,0 +1,79 @@
3758 +#ifndef IPKG_INCLUDES_H
3759 +#define IPKG_INCLUDES_H
3760 +
3761 +/* Define to 1 if you have the <memory.h> header file. */
3762 +#define HAVE_MEMORY_H 1
3763 +
3764 +/* Define to 1 if you have the <regex.h> header file. */
3765 +#define HAVE_REGEX_H 1
3766 +
3767 +/* Define to 1 if you have the <stdlib.h> header file. */
3768 +#define HAVE_STDLIB_H 1
3769 +
3770 +/* Define to 1 if you have the <strings.h> header file. */
3771 +#define HAVE_STRINGS_H 1
3772 +
3773 +/* Define to 1 if you have the <string.h> header file. */
3774 +#define HAVE_STRING_H 1
3775 +
3776 +/* Define to 1 if you have the <sys/stat.h> header file. */
3777 +#define HAVE_SYS_STAT_H 1
3778 +
3779 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3780 +#define HAVE_SYS_WAIT_H 1
3781 +
3782 +/* Define to 1 if you have the <unistd.h> header file. */
3783 +#define HAVE_UNISTD_H 1
3784 +
3785 +/* Define to 1 if you have the ANSI C header files. */
3786 +#define STDC_HEADERS 1
3787 +
3788 +
3789 +#include <stdio.h>
3790 +
3791 +#if STDC_HEADERS
3792 +# include <stdlib.h>
3793 +# include <stdarg.h>
3794 +# include <stddef.h>
3795 +# include <ctype.h>
3796 +# include <errno.h>
3797 +#else
3798 +# if HAVE_STDLIB_H
3799 +# include <stdlib.h>
3800 +# endif
3801 +#endif
3802 +
3803 +#if HAVE_REGEX_H
3804 +# include <regex.h>
3805 +#endif
3806 +
3807 +#if HAVE_STRING_H
3808 +# if !STDC_HEADERS && HAVE_MEMORY_H
3809 +# include <memory.h>
3810 +# endif
3811 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3812 +# if __GNUC__
3813 +# define __USE_GNU 1
3814 +# endif
3815 +# include <string.h>
3816 +# undef __USE_GNU
3817 +#endif
3818 +
3819 +#if HAVE_STRINGS_H
3820 +# include <strings.h>
3821 +#endif
3822 +
3823 +#if HAVE_SYS_STAT_H
3824 +# include <sys/stat.h>
3825 +#endif
3826 +
3827 +#if HAVE_SYS_WAIT_H
3828 +# include <sys/wait.h>
3829 +#endif
3830 +
3831 +#if HAVE_UNISTD_H
3832 +# include <sys/types.h>
3833 +# include <unistd.h>
3834 +#endif
3835 +
3836 +#endif /* IPKG_INCLUDES_H */
3837 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_install.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.c
3838 --- busybox-1.00-orig/archival/libipkg/ipkg_install.c 1970-01-01 00:00:00.000000000 +0000
3839 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.c 2005-07-20 10:12:33.000000000 +0000
3840 @@ -0,0 +1,1823 @@
3841 +/* ipkg_install.c - the itsy package management system
3842 +
3843 + Carl D. Worth
3844 +
3845 + Copyright (C) 2001 University of Southern California
3846 +
3847 + This program is free software; you can redistribute it and/or
3848 + modify it under the terms of the GNU General Public License as
3849 + published by the Free Software Foundation; either version 2, or (at
3850 + your option) any later version.
3851 +
3852 + This program is distributed in the hope that it will be useful, but
3853 + WITHOUT ANY WARRANTY; without even the implied warranty of
3854 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3855 + General Public License for more details.
3856 +*/
3857 +
3858 +#include "ipkg.h"
3859 +#include <errno.h>
3860 +#include <dirent.h>
3861 +#include <glob.h>
3862 +#include <time.h>
3863 +#include <signal.h>
3864 +typedef void (*sighandler_t)(int);
3865 +
3866 +#include "pkg.h"
3867 +#include "pkg_hash.h"
3868 +#include "pkg_extract.h"
3869 +
3870 +#include "ipkg_install.h"
3871 +#include "ipkg_configure.h"
3872 +#include "ipkg_download.h"
3873 +#include "ipkg_remove.h"
3874 +
3875 +#include "ipkg_utils.h"
3876 +#include "ipkg_message.h"
3877 +
3878 +#include "sprintf_alloc.h"
3879 +#include "file_util.h"
3880 +#include "str_util.h"
3881 +#include "xsystem.h"
3882 +#include "user.h"
3883 +
3884 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3885 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3886 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3887 +
3888 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3889 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3890 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3891 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3892 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3893 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3894 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3900 +
3901 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3902 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3903 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3904 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3905 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3906 +
3907 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3908 +
3909 +static int user_prefers_old_conffile(const char *file, const char *backup);
3910 +
3911 +static char *backup_filename_alloc(const char *file_name);
3912 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3913 +static int backup_exists_for(const char *file_name);
3914 +static int backup_remove(const char *file_name);
3915 +
3916 +
3917 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3918 +{
3919 + int err, cmp;
3920 + pkg_t *pkg, *old;
3921 + char *old_version, *new_version;
3922 +
3923 + pkg = pkg_new();
3924 + if (pkg == NULL) {
3925 + return ENOMEM;
3926 + }
3927 +
3928 + err = pkg_init_from_file(pkg, filename);
3929 + if (err) {
3930 + return err;
3931 + }
3932 +
3933 + if (!pkg->architecture) {
3934 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3935 + return -EINVAL;
3936 + }
3937 +
3938 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3939 + freeing the pkg that we pass in. It might be nice to clean this up
3940 + if possible. */
3941 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3942 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3943 +
3944 + pkg->local_filename = strdup(filename);
3945 +
3946 + if (old) {
3947 + old_version = pkg_version_str_alloc(old);
3948 + new_version = pkg_version_str_alloc(pkg);
3949 +
3950 + cmp = pkg_compare_versions(old, pkg);
3951 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3952 + cmp = -1 ; /* then we force ipkg to downgrade */
3953 + /* We need to use a value < 0 because in the 0 case we are asking to */
3954 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3955 + }
3956 + if (cmp > 0) {
3957 + ipkg_message(conf, IPKG_NOTICE,
3958 + "Not downgrading package %s on %s from %s to %s.\n",
3959 + old->name, old->dest->name, old_version, new_version);
3960 + pkg->state_want = SW_DEINSTALL;
3961 + pkg->state_flag |= SF_OBSOLETE;
3962 + free(old_version);
3963 + free(new_version);
3964 + return 0;
3965 + } else {
3966 + free(old_version);
3967 + free(new_version);
3968 + }
3969 + }
3970 +
3971 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3972 + return ipkg_install_pkg(conf, pkg);
3973 +}
3974 +
3975 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3976 +{
3977 + int cmp;
3978 + pkg_t *old, *new;
3979 + char *old_version, *new_version;
3980 +
3981 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3982 +
3983 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3984 + if (new == NULL) {
3985 + return IPKG_PKG_HAS_NO_CANDIDATE;
3986 + }
3987 +
3988 + new->state_flag |= SF_USER;
3989 + if (old) {
3990 + old_version = pkg_version_str_alloc(old);
3991 + new_version = pkg_version_str_alloc(new);
3992 +
3993 + cmp = pkg_compare_versions(old, new);
3994 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3995 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3996 + cmp = -1 ; /* then we force ipkg to downgrade */
3997 + /* We need to use a value < 0 because in the 0 case we are asking to */
3998 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3999 + }
4000 + ipkg_message(conf, IPKG_DEBUG,
4001 + "comparing visible versions of pkg %s:"
4002 + "\n\t%s is installed "
4003 + "\n\t%s is available "
4004 + "\n\t%d was comparison result\n",
4005 + pkg_name, old_version, new_version, cmp);
4006 + if (cmp == 0 && !conf->force_reinstall) {
4007 + ipkg_message(conf, IPKG_NOTICE,
4008 + "Package %s (%s) installed in %s is up to date.\n",
4009 + old->name, old_version, old->dest->name);
4010 + free(old_version);
4011 + free(new_version);
4012 + return 0;
4013 + } else if (cmp > 0) {
4014 + ipkg_message(conf, IPKG_NOTICE,
4015 + "Not downgrading package %s on %s from %s to %s.\n",
4016 + old->name, old->dest->name, old_version, new_version);
4017 + free(old_version);
4018 + free(new_version);
4019 + return 0;
4020 + } else if (cmp < 0) {
4021 + new->dest = old->dest;
4022 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4023 + }
4024 + }
4025 +
4026 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4027 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4028 + return any kind of integer, (might be errno from a syscall,
4029 + etc.). This is a real mess and will need to be cleaned up if
4030 + anyone ever wants to make a nice libipkg. */
4031 +
4032 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4033 + return ipkg_install_pkg(conf, new);
4034 +}
4035 +
4036 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4037 +{
4038 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4039 + int i;
4040 + ipkg_error_t err;
4041 + abstract_pkg_t *ppkg ;
4042 +
4043 + if (providers == NULL)
4044 + return IPKG_PKG_HAS_NO_CANDIDATE;
4045 +
4046 + for (i = 0; i < providers->len; i++) {
4047 + ppkg = abstract_pkg_vec_get(providers, i);
4048 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4049 + err = ipkg_install_by_name(conf, ppkg->name);
4050 + if (err)
4051 + return err;
4052 +/* XXX Maybe ppkg should be freed ? */
4053 + }
4054 + return 0;
4055 +}
4056 +
4057 +/*
4058 + * Walk dependence graph starting with pkg, collect packages to be
4059 + * installed into pkgs_needed, in dependence order.
4060 + */
4061 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4062 +{
4063 + int i, err;
4064 + pkg_vec_t *depends = pkg_vec_alloc();
4065 + char **unresolved = NULL;
4066 + int ndepends;
4067 +
4068 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4069 + pkg, depends,
4070 + &unresolved);
4071 +
4072 + if (unresolved) {
4073 + ipkg_message(conf, IPKG_ERROR,
4074 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4075 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4076 + while (*unresolved) {
4077 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4078 + unresolved++;
4079 + }
4080 + ipkg_message(conf, IPKG_ERROR, "\n");
4081 + if (! conf->force_depends) {
4082 + ipkg_message(conf, IPKG_INFO,
4083 + "This could mean that your package list is out of date or that the packages\n"
4084 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4085 + "of this problem try again with the '-force-depends' option.\n");
4086 + pkg_vec_free(depends);
4087 + return IPKG_PKG_DEPS_UNSATISFIED;
4088 + }
4089 + }
4090 +
4091 + if (ndepends <= 0) {
4092 + pkg_vec_free(depends);
4093 + return 0;
4094 + }
4095 +
4096 + for (i = 0; i < depends->len; i++) {
4097 + pkg_t *dep = depends->pkgs[i];
4098 + /* The package was uninstalled when we started, but another
4099 + dep earlier in this loop may have depended on it and pulled
4100 + it in, so check first. */
4101 + if ((dep->state_status != SS_INSTALLED)
4102 + && (dep->state_status != SS_UNPACKED)
4103 + && (dep->state_want != SW_INSTALL)) {
4104 +
4105 + /* Mark packages as to-be-installed */
4106 + dep->state_want = SW_INSTALL;
4107 +
4108 + /* Dependencies should be installed the same place as pkg */
4109 + if (dep->dest == NULL) {
4110 + dep->dest = pkg->dest;
4111 + }
4112 +
4113 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4114 + if (err) {
4115 + pkg_vec_free(depends);
4116 + return err;
4117 + }
4118 + }
4119 + }
4120 + if (pkgs_needed)
4121 + pkg_vec_insert(pkgs_needed, pkg);
4122 +
4123 + pkg_vec_free(depends);
4124 +
4125 + return 0;
4126 +}
4127 +
4128 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4129 +{
4130 + int cmp;
4131 + pkg_t *old, *new;
4132 + char *old_version, *new_version;
4133 +
4134 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4135 +
4136 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4137 + if (new == NULL) {
4138 + return IPKG_PKG_HAS_NO_CANDIDATE;
4139 + }
4140 + if (old) {
4141 + old_version = pkg_version_str_alloc(old);
4142 + new_version = pkg_version_str_alloc(new);
4143 +
4144 + cmp = pkg_compare_versions(old, new);
4145 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4146 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4147 + cmp = -1 ; /* then we force ipkg to downgrade */
4148 + /* We need to use a value < 0 because in the 0 case we are asking to */
4149 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4150 + }
4151 + ipkg_message(conf, IPKG_DEBUG,
4152 + "comparing visible versions of pkg %s:"
4153 + "\n\t%s is installed "
4154 + "\n\t%s is available "
4155 + "\n\t%d was comparison result\n",
4156 + pkg_name, old_version, new_version, cmp);
4157 + if (cmp == 0 && !conf->force_reinstall) {
4158 + ipkg_message(conf, IPKG_NOTICE,
4159 + "Package %s (%s) installed in %s is up to date.\n",
4160 + old->name, old_version, old->dest->name);
4161 + free(old_version);
4162 + free(new_version);
4163 + return 0;
4164 + } else if (cmp > 0) {
4165 + ipkg_message(conf, IPKG_NOTICE,
4166 + "Not downgrading package %s on %s from %s to %s.\n",
4167 + old->name, old->dest->name, old_version, new_version);
4168 + free(old_version);
4169 + free(new_version);
4170 + return 0;
4171 + } else if (cmp < 0) {
4172 + new->dest = old->dest;
4173 + old->state_want = SW_DEINSTALL;
4174 + old->state_flag |= SF_OBSOLETE;
4175 + }
4176 + }
4177 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4178 +}
4179 +
4180 +\f
4181 +
4182 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4183 +{
4184 + int i, err;
4185 + pkg_vec_t *depends = pkg_vec_alloc();
4186 + pkg_t *dep;
4187 + char **unresolved = NULL;
4188 + int ndepends;
4189 +
4190 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4191 + pkg, depends,
4192 + &unresolved);
4193 +
4194 + if (unresolved) {
4195 + ipkg_message(conf, IPKG_ERROR,
4196 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4197 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4198 + while (*unresolved) {
4199 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4200 + unresolved++;
4201 + }
4202 + ipkg_message(conf, IPKG_ERROR, "\n");
4203 + if (! conf->force_depends) {
4204 + ipkg_message(conf, IPKG_INFO,
4205 + "This could mean that your package list is out of date or that the packages\n"
4206 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4207 + "of this problem try again with the '-force-depends' option.\n");
4208 + pkg_vec_free(depends);
4209 + return IPKG_PKG_DEPS_UNSATISFIED;
4210 + }
4211 + }
4212 +
4213 + if (ndepends <= 0) {
4214 + return 0;
4215 + }
4216 +
4217 + /* Mark packages as to-be-installed */
4218 + for (i=0; i < depends->len; i++) {
4219 + /* Dependencies should be installed the same place as pkg */
4220 + if (depends->pkgs[i]->dest == NULL) {
4221 + depends->pkgs[i]->dest = pkg->dest;
4222 + }
4223 + depends->pkgs[i]->state_want = SW_INSTALL;
4224 + }
4225 +
4226 + for (i = 0; i < depends->len; i++) {
4227 + dep = depends->pkgs[i];
4228 + /* The package was uninstalled when we started, but another
4229 + dep earlier in this loop may have depended on it and pulled
4230 + it in, so check first. */
4231 + if ((dep->state_status != SS_INSTALLED)
4232 + && (dep->state_status != SS_UNPACKED)) {
4233 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4234 + err = ipkg_install_pkg(conf, dep);
4235 + if (err) {
4236 + pkg_vec_free(depends);
4237 + return err;
4238 + }
4239 + }
4240 + }
4241 +
4242 + pkg_vec_free(depends);
4243 +
4244 + return 0;
4245 +}
4246 +
4247 +
4248 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4249 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4250 +{
4251 + if (conf->nodeps == 0) {
4252 + int i;
4253 + pkg_vec_t *installed = pkg_vec_alloc();
4254 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4255 + for (i = 0; i < installed->len; i++) {
4256 + pkg_t *pkg = installed->pkgs[i];
4257 + satisfy_dependencies_for(conf, pkg);
4258 + }
4259 + pkg_vec_free(installed);
4260 + }
4261 + return 0;
4262 +}
4263 +
4264 +\f
4265 +
4266 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4267 +{
4268 + int i;
4269 + pkg_vec_t *conflicts = NULL;
4270 + int level;
4271 + const char *prefix;
4272 + if (conf->force_depends) {
4273 + level = IPKG_NOTICE;
4274 + prefix = "Warning";
4275 + } else {
4276 + level = IPKG_ERROR;
4277 + prefix = "ERROR";
4278 + }
4279 +
4280 + if (!conf->force_depends)
4281 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4282 +
4283 + if (conflicts) {
4284 + ipkg_message(conf, level,
4285 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4286 + i = 0;
4287 + while (i < conflicts->len)
4288 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4289 + ipkg_message(conf, level, "\n");
4290 + pkg_vec_free(conflicts);
4291 + return IPKG_PKG_DEPS_UNSATISFIED;
4292 + }
4293 + return 0;
4294 +}
4295 +
4296 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4297 +{
4298 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4299 + str_list_elt_t *iter;
4300 +
4301 + for (iter = new_list->head; iter; iter = iter->next) {
4302 + char *new_file = iter->data;
4303 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4304 + if (!new_file)
4305 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4306 + if (!owner || (owner == old_pkg))
4307 + file_hash_set_file_owner(conf, new_file, new_pkg);
4308 + }
4309 + if (old_pkg) {
4310 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4311 + for (iter = old_list->head; iter; iter = iter->next) {
4312 + char *old_file = iter->data;
4313 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4314 + if (owner == old_pkg) {
4315 + /* obsolete */
4316 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4317 + }
4318 + }
4319 + }
4320 + return 0;
4321 +}
4322 +
4323 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4324 +{
4325 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4326 +
4327 + /* sma 6.20.02: yup; here's the first bit */
4328 + /*
4329 + * XXX: BUG easy for cworth
4330 + * 1) please point the call below to the correct current root destination
4331 + * 2) we need to resolve how to check the required space for a pending pkg,
4332 + * my diddling with the .ipk file size below isn't going to cut it.
4333 + * 3) return a proper error code instead of 1
4334 + */
4335 + int comp_size, blocks_available;
4336 +
4337 + if (!conf->force_space && pkg->installed_size != NULL) {
4338 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4339 +
4340 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4341 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4342 + comp_size = (int)((comp_size + 1023) / 1024);
4343 +
4344 + if (comp_size >= blocks_available) {
4345 + ipkg_message(conf, IPKG_ERROR,
4346 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4347 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4348 + return ENOSPC;
4349 + }
4350 + }
4351 + return 0;
4352 +}
4353 +
4354 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4355 +{
4356 + int err;
4357 + char *conffiles_file_name;
4358 + char *root_dir;
4359 + FILE *conffiles_file;
4360 +
4361 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4362 +
4363 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4364 + if (pkg->tmp_unpack_dir == NULL) {
4365 + ipkg_message(conf, IPKG_ERROR,
4366 + "%s: Failed to create temporary directory '%s': %s\n",
4367 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4368 + return errno;
4369 + }
4370 +
4371 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4372 + if (err) {
4373 + return err;
4374 + }
4375 +
4376 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4377 + conffiles. Seems like I should be able to get everything to go
4378 + through pkg_init_from_file. If so, maybe it would make sense to
4379 + move all of unpack_pkg_control_files to that function. */
4380 +
4381 + /* Don't need to re-read conffiles if we already have it */
4382 + if (pkg->conffiles.head) {
4383 + return 0;
4384 + }
4385 +
4386 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4387 + if (! file_exists(conffiles_file_name)) {
4388 + free(conffiles_file_name);
4389 + return 0;
4390 + }
4391 +
4392 + conffiles_file = fopen(conffiles_file_name, "r");
4393 + if (conffiles_file == NULL) {
4394 + fprintf(stderr, "%s: failed to open %s: %s\n",
4395 + __FUNCTION__, conffiles_file_name, strerror(errno));
4396 + free(conffiles_file_name);
4397 + return errno;
4398 + }
4399 + free(conffiles_file_name);
4400 +
4401 + while (1) {
4402 + char *cf_name;
4403 + char *cf_name_in_dest;
4404 +
4405 + cf_name = file_read_line_alloc(conffiles_file);
4406 + if (cf_name == NULL) {
4407 + break;
4408 + }
4409 + str_chomp(cf_name);
4410 + if (cf_name[0] == '\0') {
4411 + continue;
4412 + }
4413 +
4414 + /* Prepend dest->root_dir to conffile name.
4415 + Take pains to avoid multiple slashes. */
4416 + root_dir = pkg->dest->root_dir;
4417 + if (conf->offline_root)
4418 + /* skip the offline_root prefix */
4419 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4420 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4421 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4422 +
4423 + /* Can't get an md5sum now, (file isn't extracted yet).
4424 + We'll wait until resolve_conffiles */
4425 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4426 +
4427 + free(cf_name);
4428 + free(cf_name_in_dest);
4429 + }
4430 +
4431 + fclose(conffiles_file);
4432 +
4433 + return 0;
4434 +}
4435 +
4436 +/* returns number of installed replacees */
4437 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4438 +{
4439 + abstract_pkg_t **replaces = pkg->replaces;
4440 + int replaces_count = pkg->replaces_count;
4441 + int i, j;
4442 + for (i = 0; i < replaces_count; i++) {
4443 + abstract_pkg_t *ab_pkg = replaces[i];
4444 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4445 + if (pkg_vec) {
4446 + for (j = 0; j < pkg_vec->len; j++) {
4447 + pkg_t *replacee = pkg_vec->pkgs[j];
4448 + if (!pkg_conflicts(pkg, replacee))
4449 + continue;
4450 + if (replacee->state_status == SS_INSTALLED) {
4451 + pkg_vec_insert(installed_replacees, replacee);
4452 + }
4453 + }
4454 + }
4455 + }
4456 + return installed_replacees->len;
4457 +}
4458 +
4459 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4460 +{
4461 + int i;
4462 + int replaces_count = replacees->len;
4463 + for (i = 0; i < replaces_count; i++) {
4464 + pkg_t *replacee = replacees->pkgs[i];
4465 + int err;
4466 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4467 + err = ipkg_remove_pkg(conf, replacee);
4468 + if (err)
4469 + return err;
4470 + }
4471 + return 0;
4472 +}
4473 +
4474 +/* to unwind the removal: make sure they are installed */
4475 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4476 +{
4477 + int i, err;
4478 + int replaces_count = replacees->len;
4479 + for (i = 0; i < replaces_count; i++) {
4480 + pkg_t *replacee = replacees->pkgs[i];
4481 + if (replacee->state_status != SS_INSTALLED) {
4482 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4483 + err = ipkg_install_pkg(conf, replacee);
4484 + if (err)
4485 + return err;
4486 + }
4487 + }
4488 + return 0;
4489 +}
4490 +
4491 +int caught_sigint = 0;
4492 +static void ipkg_install_pkg_sigint_handler(int sig)
4493 +{
4494 + caught_sigint = sig;
4495 +}
4496 +
4497 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4498 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4499 +{
4500 + if (old_pkg) {
4501 + char message_out[15];
4502 + char *old_version = pkg_version_str_alloc(old_pkg);
4503 + char *new_version = pkg_version_str_alloc(pkg);
4504 + int cmp = pkg_compare_versions(old_pkg, pkg);
4505 + int rc = 0;
4506 +
4507 + strncpy (message_out,"Upgrading ",13);
4508 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4509 + cmp = -1 ; /* then we force ipkg to downgrade */
4510 + strncpy (message_out,"Downgrading ",13); /* We need to use a value < 0 because in the 0 case we are asking to */
4511 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4512 + }
4513 +
4514 + if (cmp > 0) {
4515 + ipkg_message(conf, IPKG_NOTICE,
4516 + "Not downgrading package %s on %s from %s to %s.\n",
4517 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4518 + rc = 1;
4519 + } else if (cmp < 0) {
4520 + ipkg_message(conf, IPKG_NOTICE,
4521 + "%s %s on %s from %s to %s...\n",
4522 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4523 + pkg->dest = old_pkg->dest;
4524 + rc = 0;
4525 + } else /* cmp == 0 */ {
4526 + if (conf->force_reinstall) {
4527 + ipkg_message(conf, IPKG_NOTICE,
4528 + "Reinstalling %s (%s) on %s...\n",
4529 + pkg->name, new_version, old_pkg->dest->name);
4530 + pkg->dest = old_pkg->dest;
4531 + rc = 0;
4532 + } else {
4533 + ipkg_message(conf, IPKG_NOTICE,
4534 + "Not installing %s (%s) on %s -- already installed.\n",
4535 + pkg->name, new_version, old_pkg->dest->name);
4536 + rc = 1;
4537 + }
4538 + }
4539 + free(old_version);
4540 + free(new_version);
4541 + return rc;
4542 + } else {
4543 + char *version = pkg_version_str_alloc(pkg);
4544 + ipkg_message(conf, IPKG_NOTICE,
4545 + "Installing %s (%s) to %s...\n",
4546 + pkg->name, version, pkg->dest->name);
4547 + free(version);
4548 + return 0;
4549 + }
4550 +}
4551 +
4552 +/* and now the meat... */
4553 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg)
4554 +{
4555 + int err = 0;
4556 + pkg_t *old_pkg = NULL;
4557 + pkg_vec_t *replacees;
4558 + abstract_pkg_t *ab_pkg = NULL;
4559 + int old_state_flag;
4560 +
4561 + if (!pkg) {
4562 + ipkg_message(conf, IPKG_ERROR,
4563 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4564 + return -EINVAL;
4565 + }
4566 +
4567 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4568 +
4569 + if (!pkg_arch_supported(conf, pkg)) {
4570 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4571 + pkg->architecture, pkg->name);
4572 + return -EINVAL;
4573 + }
4574 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4575 + err = satisfy_dependencies_for(conf, pkg);
4576 + if (err) { return err; }
4577 +
4578 + ipkg_message(conf, IPKG_NOTICE,
4579 + "Package %s is already installed in %s.\n",
4580 + pkg->name, pkg->dest->name);
4581 + return 0;
4582 + }
4583 +
4584 + if (pkg->dest == NULL) {
4585 + pkg->dest = conf->default_dest;
4586 + }
4587 +
4588 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4589 +
4590 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg);
4591 + if (err) { return err; }
4592 +
4593 + pkg->state_want = SW_INSTALL;
4594 + if (old_pkg) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4595 +
4596 + /* Abhaya: conflicts check */
4597 + err = check_conflicts_for(conf, pkg);
4598 + if (err) { return err; }
4599 +
4600 + /* this setup is to remove the upgrade scenario in the end when
4601 + installing pkg A, A deps B & B deps on A. So both B and A are
4602 + installed. Then A's installation is started resulting in an
4603 + uncecessary upgrade */
4604 + if (pkg->state_status == SS_INSTALLED
4605 + && conf->force_reinstall == 0) return 0;
4606 +
4607 + err = verify_pkg_installable(conf, pkg);
4608 + if (err) { return err; }
4609 +
4610 + if (pkg->local_filename == NULL) {
4611 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4612 + if (err) {
4613 + ipkg_message(conf, IPKG_ERROR,
4614 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4615 + pkg->name);
4616 + return err;
4617 + }
4618 + }
4619 + if (pkg->tmp_unpack_dir == NULL) {
4620 + unpack_pkg_control_files(conf, pkg);
4621 + }
4622 +
4623 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4624 + err = update_file_ownership(conf, pkg, old_pkg);
4625 + if (err) { return err; }
4626 +
4627 + if (conf->nodeps == 0) {
4628 + err = satisfy_dependencies_for(conf, pkg);
4629 + if (err) { return err; }
4630 + }
4631 +
4632 + replacees = pkg_vec_alloc();
4633 + pkg_get_installed_replacees(conf, pkg, replacees);
4634 +
4635 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4636 + {
4637 + sigset_t newset, oldset;
4638 + sighandler_t old_handler = NULL;
4639 + int use_signal = 0;
4640 + caught_sigint = 0;
4641 + if (use_signal) {
4642 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4643 + } else {
4644 + sigemptyset(&newset);
4645 + sigaddset(&newset, SIGINT);
4646 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4647 + }
4648 +
4649 + ipkg_state_changed++;
4650 + pkg->state_flag |= SF_FILELIST_CHANGED;
4651 +
4652 + /* XXX: BUG: we really should treat replacement more like an upgrade
4653 + * Instead, we're going to remove the replacees
4654 + */
4655 + err = pkg_remove_installed_replacees(conf, replacees);
4656 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4657 +
4658 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4659 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4660 +
4661 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4662 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4663 +
4664 + err = preinst_configure(conf, pkg, old_pkg);
4665 + if (err) goto UNWIND_PREINST_CONFIGURE;
4666 +
4667 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4668 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4669 +
4670 + err = check_data_file_clashes(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4672 +
4673 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4674 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4675 +
4676 + if (conf->noaction) return 0;
4677 +
4678 + /* point of no return: no unwinding after this */
4679 + if (old_pkg && !conf->force_reinstall) {
4680 + old_pkg->state_want = SW_DEINSTALL;
4681 +
4682 + if (old_pkg->state_flag & SF_NOPRUNE) {
4683 + ipkg_message(conf, IPKG_INFO,
4684 + " not removing obsolesced files because package marked noprune\n");
4685 + } else {
4686 + ipkg_message(conf, IPKG_INFO,
4687 + " removing obsolesced files\n");
4688 + remove_obsolesced_files(conf, pkg, old_pkg);
4689 + }
4690 + }
4691 + ipkg_message(conf, IPKG_INFO,
4692 + " installing maintainer scripts\n");
4693 + install_maintainer_scripts(conf, pkg, old_pkg);
4694 +
4695 + /* the following just returns 0 */
4696 + remove_disappeared(conf, pkg);
4697 +
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " installing data files\n");
4700 + install_data_files(conf, pkg);
4701 +
4702 + ipkg_message(conf, IPKG_INFO,
4703 + " resolving conf files\n");
4704 + resolve_conffiles(conf, pkg);
4705 +
4706 + pkg->state_status = SS_UNPACKED;
4707 + old_state_flag = pkg->state_flag;
4708 + pkg->state_flag &= ~SF_PREFER;
4709 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4710 +
4711 + if (old_pkg && !conf->force_reinstall) {
4712 + old_pkg->state_status = SS_NOT_INSTALLED;
4713 + }
4714 +
4715 + time(&pkg->installed_time);
4716 +
4717 + ipkg_message(conf, IPKG_INFO,
4718 + " cleanup temp files\n");
4719 + cleanup_temporary_files(conf, pkg);
4720 +
4721 + ab_pkg = pkg->parent;
4722 + if (ab_pkg)
4723 + ab_pkg->state_status = pkg->state_status;
4724 +
4725 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4726 +
4727 + if (use_signal)
4728 + signal(SIGINT, old_handler);
4729 + else
4730 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4731 +
4732 + return 0;
4733 +
4734 +
4735 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4736 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4737 + UNWIND_CHECK_DATA_FILE_CLASHES:
4738 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4739 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4740 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4741 + UNWIND_PREINST_CONFIGURE:
4742 + preinst_configure_unwind(conf, pkg, old_pkg);
4743 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4744 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4745 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4746 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4747 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4748 + pkg_remove_installed_replacees_unwind(conf, replacees);
4749 +
4750 + ipkg_message(conf, IPKG_INFO,
4751 + " cleanup temp files\n");
4752 + cleanup_temporary_files(conf, pkg);
4753 +
4754 + ipkg_message(conf, IPKG_INFO,
4755 + "Failed.\n");
4756 + if (use_signal)
4757 + signal(SIGINT, old_handler);
4758 + else
4759 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4760 +
4761 + return err;
4762 + }
4763 +}
4764 +
4765 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4766 +{
4767 + /* DPKG_INCOMPATIBILITY:
4768 + dpkg does some things here that we don't do yet. Do we care?
4769 +
4770 + 1. If a version of the package is already installed, call
4771 + old-prerm upgrade new-version
4772 + 2. If the script runs but exits with a non-zero exit status
4773 + new-prerm failed-upgrade old-version
4774 + Error unwind, for both the above cases:
4775 + old-postinst abort-upgrade new-version
4776 + */
4777 + return 0;
4778 +}
4779 +
4780 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4781 +{
4782 + /* DPKG_INCOMPATIBILITY:
4783 + dpkg does some things here that we don't do yet. Do we care?
4784 + (See prerm_upgrade_old_package for details)
4785 + */
4786 + return 0;
4787 +}
4788 +
4789 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4790 +{
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4793 + 2. If a 'conflicting' package is being removed at the same time:
4794 + 1. If any packages depended on that conflicting package and
4795 + --auto-deconfigure is specified, call, for each such package:
4796 + deconfigured's-prerm deconfigure \
4797 + in-favour package-being-installed version \
4798 + removing conflicting-package version
4799 + Error unwind:
4800 + deconfigured's-postinst abort-deconfigure \
4801 + in-favour package-being-installed-but-failed version \
4802 + removing conflicting-package version
4803 +
4804 + The deconfigured packages are marked as requiring
4805 + configuration, so that if --install is used they will be
4806 + configured again if possible.
4807 + 2. To prepare for removal of the conflicting package, call:
4808 + conflictor's-prerm remove in-favour package new-version
4809 + Error unwind:
4810 + conflictor's-postinst abort-remove in-favour package new-version
4811 + */
4812 + return 0;
4813 +}
4814 +
4815 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4816 +{
4817 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4818 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4819 + details) */
4820 + return 0;
4821 +}
4822 +
4823 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4824 +{
4825 + int err;
4826 + char *preinst_args;
4827 +
4828 + if (old_pkg) {
4829 + char *old_version = pkg_version_str_alloc(old_pkg);
4830 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4831 + free(old_version);
4832 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4833 + char *pkg_version = pkg_version_str_alloc(pkg);
4834 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4835 + free(pkg_version);
4836 + } else {
4837 + preinst_args = strdup("install");
4838 + }
4839 +
4840 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4841 + if (err) {
4842 + ipkg_message(conf, IPKG_ERROR,
4843 + "Aborting installation of %s\n", pkg->name);
4844 + return 1;
4845 + }
4846 +
4847 + free(preinst_args);
4848 +
4849 + return 0;
4850 +}
4851 +
4852 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4853 +{
4854 + /* DPKG_INCOMPATIBILITY:
4855 + dpkg does the following error unwind, should we?
4856 + pkg->postrm abort-upgrade old-version
4857 + OR pkg->postrm abort-install old-version
4858 + OR pkg->postrm abort-install
4859 + */
4860 + return 0;
4861 +}
4862 +
4863 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4864 +{
4865 + int err;
4866 + conffile_list_elt_t *iter;
4867 + conffile_t *cf;
4868 +
4869 + if (conf->noaction) return 0;
4870 +
4871 + /* Backup all modified conffiles */
4872 + if (old_pkg) {
4873 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4874 + char *cf_name;
4875 +
4876 + cf = iter->data;
4877 + cf_name = root_filename_alloc(conf, cf->name);
4878 +
4879 + /* Don't worry if the conffile is just plain gone */
4880 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4881 + err = backup_make_backup(conf, cf_name);
4882 + if (err) {
4883 + return err;
4884 + }
4885 + }
4886 + free(cf_name);
4887 + }
4888 + }
4889 +
4890 + /* Backup all conffiles that were not conffiles in old_pkg */
4891 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4892 + char *cf_name;
4893 + cf = iter->data;
4894 + cf_name = root_filename_alloc(conf, cf->name);
4895 + /* Ignore if this was a conffile in old_pkg as well */
4896 + if (pkg_get_conffile(old_pkg, cf->name)) {
4897 + continue;
4898 + }
4899 +
4900 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4901 + err = backup_make_backup(conf, cf_name);
4902 + if (err) {
4903 + return err;
4904 + }
4905 + }
4906 + free(cf_name);
4907 + }
4908 +
4909 + return 0;
4910 +}
4911 +
4912 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4913 +{
4914 + conffile_list_elt_t *iter;
4915 +
4916 + if (old_pkg) {
4917 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4918 + backup_remove(iter->data->name);
4919 + }
4920 + }
4921 +
4922 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4923 + backup_remove(iter->data->name);
4924 + }
4925 +
4926 + return 0;
4927 +}
4928 +
4929 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4930 +{
4931 + /* DPKG_INCOMPATIBILITY:
4932 + ipkg takes a slightly different approach than dpkg at this
4933 + point. dpkg installs each file in the new package while
4934 + creating a backup for any file that is replaced, (so that it
4935 + can unwind if necessary). To avoid complexity and redundant
4936 + storage, ipkg doesn't do any installation until later, (at the
4937 + point at which dpkg removes the backups.
4938 +
4939 + But, we do have to check for data file clashes, since after
4940 + installing a package with a file clash, removing either of the
4941 + packages involved in the clash has the potential to break the
4942 + other package.
4943 + */
4944 + str_list_t *files_list;
4945 + str_list_elt_t *iter;
4946 +
4947 + int clashes = 0;
4948 +
4949 + files_list = pkg_get_installed_files(pkg);
4950 + for (iter = files_list->head; iter; iter = iter->next) {
4951 + char *root_filename;
4952 + char *filename = iter->data;
4953 + root_filename = root_filename_alloc(conf, filename);
4954 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4955 + pkg_t *owner;
4956 + pkg_t *obs;
4957 + /* Pre-existing conffiles are OK */
4958 + /* @@@@ should have way to check that it is a conffile -Jamey */
4959 + if (backup_exists_for(root_filename)) {
4960 + continue;
4961 + }
4962 +
4963 + /* Pre-existing files are OK if force-overwrite was asserted. */
4964 + if (conf->force_overwrite) {
4965 + /* but we need to change who owns this file */
4966 + file_hash_set_file_owner(conf, filename, pkg);
4967 + continue;
4968 + }
4969 +
4970 + owner = file_hash_get_file_owner(conf, filename);
4971 +
4972 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4973 + if (owner && old_pkg) {
4974 + if (strcmp(owner->name, old_pkg->name) == 0) {
4975 + continue;
4976 + }
4977 + }
4978 +
4979 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4980 + if (owner) {
4981 + if (pkg_replaces(pkg, owner)) {
4982 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4983 + continue;
4984 + }
4985 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4986 + then it's ok to overwrite. */
4987 + if (strcmp(owner->name,pkg->name)==0){
4988 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4989 + continue;
4990 + }
4991 + }
4992 +
4993 + /* Pre-existing files are OK if they are obsolete */
4994 + obs = hash_table_get(&conf->obs_file_hash, filename);
4995 + if (obs) {
4996 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
4997 + continue;
4998 + }
4999 +
5000 + /* We have found a clash. */
5001 + ipkg_message(conf, IPKG_ERROR,
5002 + "Package %s wants to install file %s\n"
5003 + "\tBut that file is already provided by package ",
5004 + pkg->name, filename);
5005 + if (owner) {
5006 + ipkg_message(conf, IPKG_ERROR,
5007 + "%s\n", owner->name);
5008 + } else {
5009 + ipkg_message(conf, IPKG_ERROR,
5010 + "<no package>\nPlease move this file out of the way and try again.\n");
5011 + }
5012 + clashes++;
5013 + }
5014 + free(root_filename);
5015 + }
5016 + pkg_free_installed_files(pkg);
5017 +
5018 + return clashes;
5019 +}
5020 +
5021 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5022 +{
5023 + /* Nothing to do since check_data_file_clashes doesn't change state */
5024 + return 0;
5025 +}
5026 +
5027 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5028 +{
5029 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5030 + 1. If the package is being upgraded, call
5031 + old-postrm upgrade new-version
5032 + 2. If this fails, attempt:
5033 + new-postrm failed-upgrade old-version
5034 + Error unwind, for both cases:
5035 + old-preinst abort-upgrade new-version */
5036 + return 0;
5037 +}
5038 +
5039 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5040 +{
5041 + /* DPKG_INCOMPATIBILITY:
5042 + dpkg does some things here that we don't do yet. Do we care?
5043 + (See postrm_upgrade_old_pkg for details)
5044 + */
5045 + return 0;
5046 +}
5047 +
5048 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5049 +{
5050 + int err;
5051 + str_list_t *old_files;
5052 + str_list_elt_t *of;
5053 + str_list_t *new_files;
5054 + str_list_elt_t *nf;
5055 +
5056 + if (old_pkg == NULL) {
5057 + return 0;
5058 + }
5059 +
5060 + old_files = pkg_get_installed_files(old_pkg);
5061 + new_files = pkg_get_installed_files(pkg);
5062 +
5063 + for (of = old_files->head; of; of = of->next) {
5064 + pkg_t *owner;
5065 + char *old, *new;
5066 + old = of->data;
5067 + for (nf = new_files->head; nf; nf = nf->next) {
5068 + new = nf->data;
5069 + if (strcmp(old, new) == 0) {
5070 + goto NOT_OBSOLETE;
5071 + }
5072 + }
5073 + if (file_is_dir(old)) {
5074 + continue;
5075 + }
5076 + owner = file_hash_get_file_owner(conf, old);
5077 + if (owner != old_pkg) {
5078 + /* in case obsolete file no longer belongs to old_pkg */
5079 + continue;
5080 + }
5081 +
5082 + /* old file is obsolete */
5083 + ipkg_message(conf, IPKG_INFO,
5084 + " removing obsolete file %s\n", old);
5085 + if (!conf->noaction) {
5086 + err = unlink(old);
5087 + if (err) {
5088 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5089 + strerror(errno));
5090 + }
5091 + }
5092 +
5093 + NOT_OBSOLETE:
5094 + ;
5095 + }
5096 +
5097 + pkg_free_installed_files(old_pkg);
5098 + pkg_free_installed_files(pkg);
5099 +
5100 + return 0;
5101 +}
5102 +
5103 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5104 +{
5105 + int i;
5106 + int err = 0;
5107 + char *globpattern;
5108 + glob_t globbuf;
5109 + if (0) {
5110 + if (!pkg->dest) {
5111 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5112 + return -1;
5113 + }
5114 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5115 + err = glob(globpattern, 0, NULL, &globbuf);
5116 + free(globpattern);
5117 + if (err) {
5118 + return err;
5119 + }
5120 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5121 + for (i = 0; i < globbuf.gl_pathc; i++) {
5122 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5123 + globbuf.gl_pathv[i], old_pkg->name);
5124 + if (!conf->noaction)
5125 + unlink(globbuf.gl_pathv[i]);
5126 + }
5127 + globfree(&globbuf);
5128 + }
5129 + return err;
5130 +}
5131 +
5132 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5133 +{
5134 + int ret;
5135 + char *prefix;
5136 +
5137 + if (old_pkg)
5138 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5139 + sprintf_alloc(&prefix, "%s.", pkg->name);
5140 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5141 + pkg->dest->info_dir,
5142 + prefix);
5143 + free(prefix);
5144 + return ret;
5145 +}
5146 +
5147 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5148 +{
5149 + /* DPKG_INCOMPATIBILITY:
5150 + This is a fairly sophisticated dpkg operation. Shall we
5151 + skip it? */
5152 +
5153 + /* Any packages all of whose files have been overwritten during the
5154 + installation, and which aren't required for dependencies, are
5155 + considered to have been removed. For each such package
5156 + 1. disappearer's-postrm disappear overwriter overwriter-version
5157 + 2. The package's maintainer scripts are removed
5158 + 3. It is noted in the status database as being in a sane state,
5159 + namely not installed (any conffiles it may have are ignored,
5160 + rather than being removed by dpkg). Note that disappearing
5161 + packages do not have their prerm called, because dpkg doesn't
5162 + know in advance that the package is going to vanish.
5163 + */
5164 + return 0;
5165 +}
5166 +
5167 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5168 +{
5169 + int err;
5170 +
5171 + /* ipkg takes a slightly different approach to data file backups
5172 + than dpkg. Rather than removing backups at this point, we
5173 + actually do the data file installation now. See comments in
5174 + check_data_file_clashes() for more details. */
5175 +
5176 + ipkg_message(conf, IPKG_INFO,
5177 + " extracting data files to %s\n", pkg->dest->root_dir);
5178 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5179 + if (err) {
5180 + return err;
5181 + }
5182 +
5183 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5184 + so we can't save ourself from removing important packages
5185 + At this point we (should) have extracted the .control file, so it
5186 + would be a good idea to reload the data in it, and set the Essential
5187 + state in *pkg. From now on the Essential is back in status file and
5188 + we can protect again.
5189 + We should operate this way:
5190 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5191 + check for "Essential" in it
5192 + set the value in pkg->essential.
5193 + This new routine could be useful also for every other flag
5194 + Pigi: 16/03/2004 */
5195 + set_flags_from_control(conf, pkg) ;
5196 +
5197 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5198 + err = pkg_write_filelist(conf, pkg);
5199 + if (err)
5200 + return err;
5201 +
5202 + /* XXX: FEATURE: ipkg should identify any files which existed
5203 + before installation and which were overwritten, (see
5204 + check_data_file_clashes()). What it must do is remove any such
5205 + files from the filelist of the old package which provided the
5206 + file. Otherwise, if the old package were removed at some point
5207 + it would break the new package. Removing the new package will
5208 + also break the old one, but this cannot be helped since the old
5209 + package's file has already been deleted. This is the importance
5210 + of check_data_file_clashes(), and only allowing ipkg to install
5211 + a clashing package with a user force. */
5212 +
5213 + return 0;
5214 +}
5215 +
5216 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5217 +{
5218 + conffile_list_elt_t *iter;
5219 + conffile_t *cf;
5220 + char *cf_backup;
5221 +
5222 + char *md5sum;
5223 +
5224 +
5225 + if (conf->noaction) return 0;
5226 +
5227 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5228 + char *root_filename;
5229 + cf = iter->data;
5230 + root_filename = root_filename_alloc(conf, cf->name);
5231 +
5232 + /* Might need to initialize the md5sum for each conffile */
5233 + if (cf->value == NULL) {
5234 + cf->value = file_md5sum_alloc(root_filename);
5235 + }
5236 +
5237 + if (!file_exists(root_filename)) {
5238 + free(root_filename);
5239 + continue;
5240 + }
5241 +
5242 + cf_backup = backup_filename_alloc(root_filename);
5243 +
5244 +
5245 + if (file_exists(cf_backup)) {
5246 + /* Let's compute md5 to test if files are changed */
5247 + md5sum = file_md5sum_alloc(cf_backup);
5248 + if (strcmp( cf->value,md5sum) != 0 ) {
5249 + if (conf->force_defaults
5250 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5251 + rename(cf_backup, root_filename);
5252 + }
5253 + }
5254 + unlink(cf_backup);
5255 + free(md5sum);
5256 + }
5257 +
5258 + free(cf_backup);
5259 + free(root_filename);
5260 + }
5261 +
5262 + return 0;
5263 +}
5264 +
5265 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5266 +{
5267 + char *response;
5268 + const char *short_file_name;
5269 +
5270 + short_file_name = strrchr(file_name, '/');
5271 + if (short_file_name) {
5272 + short_file_name++;
5273 + } else {
5274 + short_file_name = file_name;
5275 + }
5276 +
5277 + while (1) {
5278 + response = get_user_response(" Configuration file '%s'\n"
5279 + " ==> File on system created by you or by a script.\n"
5280 + " ==> File also in package provided by package maintainer.\n"
5281 + " What would you like to do about it ? Your options are:\n"
5282 + " Y or I : install the package maintainer's version\n"
5283 + " N or O : keep your currently-installed version\n"
5284 + " D : show the differences between the versions (if diff is installed)\n"
5285 + " The default action is to keep your current version.\n"
5286 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5287 + if (strcmp(response, "y") == 0
5288 + || strcmp(response, "i") == 0
5289 + || strcmp(response, "yes") == 0) {
5290 + free(response);
5291 + return 0;
5292 + }
5293 +
5294 + if (strcmp(response, "d") == 0) {
5295 + char *cmd;
5296 +
5297 + free(response);
5298 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5299 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5300 + xsystem(cmd);
5301 + free(cmd);
5302 + printf(" [Press ENTER to continue]\n");
5303 + response = file_read_line_alloc(stdin);
5304 + free(response);
5305 + continue;
5306 + }
5307 +
5308 + free(response);
5309 + return 1;
5310 + }
5311 +}
5312 +
5313 +/* XXX: CLEANUP: I'd like to move all of the code for
5314 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5315 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5316 + pkg_deinit for example). */
5317 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5318 +{
5319 + DIR *tmp_dir;
5320 + struct dirent *dirent;
5321 + char *tmp_file;
5322 +
5323 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5324 +#error
5325 + ipkg_message(conf, IPKG_DEBUG,
5326 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5327 + __FUNCTION__, pkg->tmp_unpack_dir);
5328 + return 0;
5329 +#endif
5330 +
5331 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5332 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5333 + if (tmp_dir) {
5334 + while (1) {
5335 + dirent = readdir(tmp_dir);
5336 + if (dirent == NULL) {
5337 + break;
5338 + }
5339 + sprintf_alloc(&tmp_file, "%s/%s",
5340 + pkg->tmp_unpack_dir, dirent->d_name);
5341 + if (! file_is_dir(tmp_file)) {
5342 + unlink(tmp_file);
5343 + }
5344 + free(tmp_file);
5345 + }
5346 + closedir(tmp_dir);
5347 + rmdir(pkg->tmp_unpack_dir);
5348 + free(pkg->tmp_unpack_dir);
5349 + pkg->tmp_unpack_dir = NULL;
5350 + }
5351 + }
5352 +
5353 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5354 + pkg->name, pkg->local_filename, conf->tmp_dir);
5355 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5356 + unlink(pkg->local_filename);
5357 + free(pkg->local_filename);
5358 + pkg->local_filename = NULL;
5359 + }
5360 +
5361 + return 0;
5362 +}
5363 +
5364 +static char *backup_filename_alloc(const char *file_name)
5365 +{
5366 + char *backup;
5367 +
5368 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5369 +
5370 + return backup;
5371 +}
5372 +
5373 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5374 +{
5375 + int err;
5376 + char *backup;
5377 +
5378 + backup = backup_filename_alloc(file_name);
5379 + err = file_copy(file_name, backup);
5380 + if (err) {
5381 + ipkg_message(conf, IPKG_ERROR,
5382 + "%s: Failed to copy %s to %s\n",
5383 + __FUNCTION__, file_name, backup);
5384 + }
5385 +
5386 + free(backup);
5387 +
5388 + return err;
5389 +}
5390 +
5391 +static int backup_exists_for(const char *file_name)
5392 +{
5393 + int ret;
5394 + char *backup;
5395 +
5396 + backup = backup_filename_alloc(file_name);
5397 +
5398 + ret = file_exists(backup);
5399 +
5400 + free(backup);
5401 +
5402 + return ret;
5403 +}
5404 +
5405 +static int backup_remove(const char *file_name)
5406 +{
5407 + char *backup;
5408 +
5409 + backup = backup_filename_alloc(file_name);
5410 + unlink(backup);
5411 + free(backup);
5412 +
5413 + return 0;
5414 +}
5415 +
5416 +\f
5417 +
5418 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5419 +
5420 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5421 +{
5422 + /* first, remove the packages that need removing */
5423 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5424 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5425 + err = ipkg_remove_pkg(conf, pkg);
5426 + if (err) return err;
5427 + }
5428 + return 0;
5429 +}
5430 +
5431 +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5432 +{
5433 + int i;
5434 + /* now one more pass checking on the ones that need to be installed */
5435 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5436 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5437 + if (pkg->dest == NULL)
5438 + pkg->dest = conf->default_dest;
5439 +
5440 + pkg->state_want = SW_INSTALL;
5441 +
5442 + /* Abhaya: conflicts check */
5443 + err = check_conflicts_for(conf, pkg);
5444 + if (err) { return err; }
5445 + }
5446 + return 0;
5447 +}
5448 +
5449 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5450 +{
5451 + int i;
5452 + /* now one more pass checking on the ones that need to be installed */
5453 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5454 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5455 +
5456 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5457 + pkg_vec_t *replacees = pkg_vec_alloc();
5458 + pkg_get_installed_replacees(conf, pkg, replacees);
5459 +
5460 + /* XXX: BUG: we really should treat replacement more like an upgrade
5461 + * Instead, we're going to remove the replacees
5462 + */
5463 + err = pkg_remove_installed_replacees(conf, replacees);
5464 + if (err) return err;
5465 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5466 + }
5467 + return 0;
5468 +}
5469 +
5470 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5471 +{
5472 + int i;
5473 + /* now one more pass checking on the ones that need to be installed */
5474 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5475 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5476 + if (pkg->local_filename == NULL) {
5477 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5478 + if (err) {
5479 + ipkg_message(conf, IPKG_ERROR,
5480 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5481 + pkg->name);
5482 + return err;
5483 + }
5484 + }
5485 + if (pkg->tmp_unpack_dir == NULL) {
5486 + err = unpack_pkg_control_files(conf, pkg);
5487 + if (err) return err;
5488 + }
5489 + }
5490 + return 0;
5491 +}
5492 +
5493 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5494 +{
5495 + int i;
5496 + /* now one more pass checking on the ones that need to be installed */
5497 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5498 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5499 + pkg_t *old_pkg = pkg->old_pkg;
5500 +
5501 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5502 + if (err) return err;
5503 +
5504 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5505 + if (err) return err;
5506 +
5507 + err = preinst_configure(conf, pkg, old_pkg);
5508 + if (err) return err;
5509 +
5510 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5511 + if (err) return err;
5512 +
5513 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5514 + if (err) return err;
5515 + }
5516 + return 0;
5517 +}
5518 +
5519 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5520 +{
5521 + int i;
5522 + /* now one more pass checking on the ones that need to be installed */
5523 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5524 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5525 + pkg_t *old_pkg = pkg->old_pkg;
5526 +
5527 + if (old_pkg) {
5528 + old_pkg->state_want = SW_DEINSTALL;
5529 +
5530 + if (old_pkg->state_flag & SF_NOPRUNE) {
5531 + ipkg_message(conf, IPKG_INFO,
5532 + " not removing obsolesced files because package marked noprune\n");
5533 + } else {
5534 + ipkg_message(conf, IPKG_INFO,
5535 + " removing obsolesced files\n");
5536 + remove_obsolesced_files(conf, pkg, old_pkg);
5537 + }
5538 + }
5539 +
5540 + ipkg_message(conf, IPKG_INFO,
5541 + " installing maintainer scripts\n");
5542 + install_maintainer_scripts(conf, pkg, old_pkg);
5543 +
5544 + /* the following just returns 0 */
5545 + remove_disappeared(conf, pkg);
5546 +
5547 + ipkg_message(conf, IPKG_INFO,
5548 + " installing data files\n");
5549 + install_data_files(conf, pkg);
5550 +
5551 + ipkg_message(conf, IPKG_INFO,
5552 + " resolving conf files\n");
5553 + resolve_conffiles(conf, pkg);
5554 +
5555 + pkg->state_status = SS_UNPACKED;
5556 +
5557 + if (old_pkg) {
5558 + old_pkg->state_status = SS_NOT_INSTALLED;
5559 + }
5560 +
5561 + time(&pkg->installed_time);
5562 +
5563 + ipkg_message(conf, IPKG_INFO,
5564 + " cleanup temp files\n");
5565 + cleanup_temporary_files(conf, pkg);
5566 +
5567 + if (pkg->parent)
5568 + pkg->parent->state_status = pkg->state_status;
5569 + }
5570 + return 0;
5571 +}
5572 +
5573 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5574 +{
5575 + int i;
5576 + /* now one more pass checking on the ones that need to be installed */
5577 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5578 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5579 + pkg_t *old_pkg = pkg->old_pkg;
5580 +
5581 + if (old_pkg) {
5582 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5583 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5584 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5585 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5586 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5587 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5588 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5589 + preinst_configure_unwind(conf, pkg, old_pkg);
5590 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5591 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5592 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5593 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5594 +
5595 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5596 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5597 +
5598 + }
5599 + }
5600 + return 0;
5601 +}
5602 +
5603 +/*
5604 + * Perform all the actions.
5605 + *
5606 + * pkgs_to_remove are packages marked for removal.
5607 + * pkgs_superseded are the old packages being replaced by upgrades.
5608 + *
5609 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5610 + */
5611 +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5612 +{
5613 + int err;
5614 + int i;
5615 +
5616 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5617 + if (err) return err;
5618 +
5619 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5620 + if (err) return err;
5621 +
5622 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5623 + if (err) goto UNWIND;
5624 +
5625 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5626 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5627 + if (err) goto UNWIND;
5628 +
5629 + /*
5630 + * Now that we have the packages unpacked, we can look for data
5631 + * file clashes. First, we mark the files from the superseded
5632 + * packages as obsolete. Then we scan the files in
5633 + * pkgs_to_install, and only complain about clashes with
5634 + * non-obsolete files.
5635 + */
5636 +
5637 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5638 + if (err) goto UNWIND;
5639 +
5640 + /* this was before checking data file clashes */
5641 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5642 + if (err) goto UNWIND;
5643 +
5644 + /* point of no return: no unwinding after this */
5645 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5646 + if (err) return err;
5647 +
5648 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5649 + return 0;
5650 +
5651 + UNWIND:
5652 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5653 +
5654 + ipkg_message(conf, IPKG_INFO,
5655 + " cleanup temp files\n");
5656 + cleanup_temporary_files(conf, pkg);
5657 +
5658 + ipkg_message(conf, IPKG_INFO,
5659 + "Failed.\n");
5660 + return err;
5661 +}
5662 +
5663 +#endif
5664 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_install.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.h
5665 --- busybox-1.00-orig/archival/libipkg/ipkg_install.h 1970-01-01 00:00:00.000000000 +0000
5666 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.h 2005-07-17 16:10:23.000000000 +0000
5667 @@ -0,0 +1,35 @@
5668 +/* ipkg_install.h - the itsy package management system
5669 +
5670 + Carl D. Worth
5671 +
5672 + Copyright (C) 2001 University of Southern California
5673 +
5674 + This program is free software; you can redistribute it and/or
5675 + modify it under the terms of the GNU General Public License as
5676 + published by the Free Software Foundation; either version 2, or (at
5677 + your option) any later version.
5678 +
5679 + This program is distributed in the hope that it will be useful, but
5680 + WITHOUT ANY WARRANTY; without even the implied warranty of
5681 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5682 + General Public License for more details.
5683 +*/
5684 +
5685 +#ifndef IPKG_INSTALL_H
5686 +#define IPKG_INSTALL_H
5687 +
5688 +#include "pkg.h"
5689 +#include "ipkg_conf.h"
5690 +
5691 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5692 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5693 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5694 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg);
5695 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5696 +
5697 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5698 +
5699 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5700 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5701 +
5702 +#endif
5703 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_message.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.c
5704 --- busybox-1.00-orig/archival/libipkg/ipkg_message.c 1970-01-01 00:00:00.000000000 +0000
5705 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.c 2005-07-20 10:36:45.000000000 +0000
5706 @@ -0,0 +1,61 @@
5707 +/* ipkg_message.c - the itsy package management system
5708 +
5709 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5710 +
5711 + This program is free software; you can redistribute it and/or
5712 + modify it under the terms of the GNU General Public License as
5713 + published by the Free Software Foundation; either version 2, or (at
5714 + your option) any later version.
5715 +
5716 + This program is distributed in the hope that it will be useful, but
5717 + WITHOUT ANY WARRANTY; without even the implied warranty of
5718 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5719 + General Public License for more details.
5720 +*/
5721 +
5722 +
5723 +#include "ipkg.h"
5724 +#include "ipkg_conf.h"
5725 +#include "ipkg_message.h"
5726 +
5727 +#ifndef IPKG_LIB
5728 +
5729 +void
5730 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5731 +{
5732 + va_list ap;
5733 +
5734 + if (conf && (conf->verbosity < level))
5735 + {
5736 + return;
5737 + }
5738 + else
5739 + {
5740 +
5741 + va_start (ap, fmt);
5742 + vprintf (fmt, ap);
5743 + va_end (ap);
5744 + }
5745 +}
5746 +
5747 +#else
5748 +
5749 +#include "libipkg.h"
5750 +
5751 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5752 +
5753 +void
5754 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5755 +{
5756 + va_list ap;
5757 + char ts[256];
5758 +
5759 + if (ipkg_cb_message)
5760 + {
5761 + va_start (ap, fmt);
5762 + vsnprintf (ts,256,fmt, ap);
5763 + va_end (ap);
5764 + ipkg_cb_message(conf,level,ts);
5765 + }
5766 +}
5767 +#endif
5768 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_message.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.h
5769 --- busybox-1.00-orig/archival/libipkg/ipkg_message.h 1970-01-01 00:00:00.000000000 +0000
5770 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.h 2005-07-20 10:37:22.000000000 +0000
5771 @@ -0,0 +1,32 @@
5772 +/* ipkg_message.h - the itsy package management system
5773 +
5774 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5775 +
5776 + This program is free software; you can redistribute it and/or
5777 + modify it under the terms of the GNU General Public License as
5778 + published by the Free Software Foundation; either version 2, or (at
5779 + your option) any later version.
5780 +
5781 + This program is distributed in the hope that it will be useful, but
5782 + WITHOUT ANY WARRANTY; without even the implied warranty of
5783 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5784 + General Public License for more details.
5785 +*/
5786 +
5787 +#ifndef _IPKG_MESSAGE_H_
5788 +#define _IPKG_MESSAGE_H_
5789 +
5790 +#include "ipkg.h"
5791 +#include "ipkg_conf.h"
5792 +
5793 +typedef enum {
5794 + IPKG_ERROR, /* error conditions */
5795 + IPKG_NOTICE, /* normal but significant condition */
5796 + IPKG_INFO, /* informational message */
5797 + IPKG_DEBUG, /* debug level message */
5798 + IPKG_DEBUG2, /* more debug level message */
5799 +} message_level_t;
5800 +
5801 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5802 +
5803 +#endif /* _IPKG_MESSAGE_H_ */
5804 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_remove.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.c
5805 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.c 1970-01-01 00:00:00.000000000 +0000
5806 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.c 2005-07-17 16:10:24.000000000 +0000
5807 @@ -0,0 +1,379 @@
5808 +/* ipkg_remove.c - the itsy package management system
5809 +
5810 + Carl D. Worth
5811 +
5812 + Copyright (C) 2001 University of Southern California
5813 +
5814 + This program is free software; you can redistribute it and/or
5815 + modify it under the terms of the GNU General Public License as
5816 + published by the Free Software Foundation; either version 2, or (at
5817 + your option) any later version.
5818 +
5819 + This program is distributed in the hope that it will be useful, but
5820 + WITHOUT ANY WARRANTY; without even the implied warranty of
5821 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5822 + General Public License for more details.
5823 +*/
5824 +
5825 +#include "ipkg.h"
5826 +#include "ipkg_message.h"
5827 +
5828 +#include <glob.h>
5829 +
5830 +#include "ipkg_remove.h"
5831 +
5832 +#include "file_util.h"
5833 +#include "sprintf_alloc.h"
5834 +#include "str_util.h"
5835 +
5836 +#include "ipkg_cmd.h"
5837 +
5838 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
5839 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5840 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5841 +
5842 +/*
5843 + * Returns number of the number of packages depending on the packages provided by this package.
5844 + * Every package implicitly provides itself.
5845 + */
5846 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5847 +{
5848 + int nprovides = pkg->provides_count;
5849 + abstract_pkg_t **provides = pkg->provides;
5850 + int n_installed_dependents = 0;
5851 + int i;
5852 + for (i = 0; i < nprovides; i++) {
5853 + abstract_pkg_t *providee = provides[i];
5854 + abstract_pkg_t **dependers = providee->depended_upon_by;
5855 + abstract_pkg_t *dep_ab_pkg;
5856 + if (dependers == NULL)
5857 + continue;
5858 + while ((dep_ab_pkg = *dependers++) != NULL) {
5859 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5860 + n_installed_dependents++;
5861 + }
5862 + }
5863 + /* if caller requested the set of installed dependents */
5864 + if (pdependents) {
5865 + int p = 0;
5866 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5867 +
5868 + if ( dependents == NULL ){
5869 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5870 + return -1;
5871 + }
5872 +
5873 + *pdependents = dependents;
5874 + for (i = 0; i < nprovides; i++) {
5875 + abstract_pkg_t *providee = provides[i];
5876 + abstract_pkg_t **dependers = providee->depended_upon_by;
5877 + abstract_pkg_t *dep_ab_pkg;
5878 + if (dependers == NULL)
5879 + continue;
5880 + while ((dep_ab_pkg = *dependers++) != NULL) {
5881 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5882 + dependents[p++] = dep_ab_pkg;
5883 + dep_ab_pkg->state_flag |= SF_MARKED;
5884 + }
5885 + }
5886 + }
5887 + dependents[p] = NULL;
5888 + /* now clear the marks */
5889 + for (i = 0; i < p; i++) {
5890 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5891 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5892 + }
5893 + }
5894 + return n_installed_dependents;
5895 +}
5896 +
5897 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5898 +{
5899 + int i;
5900 + int a;
5901 + int count;
5902 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5903 + abstract_pkg_t * ab_pkg;
5904 +
5905 + if((ab_pkg = pkg->parent) == NULL){
5906 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5907 + __FUNCTION__, pkg->name);
5908 + return 0;
5909 + }
5910 +
5911 + if (dependents == NULL)
5912 + return 0;
5913 +
5914 + // here i am using the dependencies_checked
5915 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5916 + return 0; // has already been encountered in the process
5917 + // of marking packages for removal - Karthik
5918 + ab_pkg->dependencies_checked = 2;
5919 +
5920 + i = 0;
5921 + count = 1;
5922 + while (dependents [i] != NULL) {
5923 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5924 +
5925 + if (dep_ab_pkg->dependencies_checked == 2){
5926 + i++;
5927 + continue;
5928 + }
5929 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5930 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5931 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5932 + if (dep_pkg->state_status == SS_INSTALLED) {
5933 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5934 + count++;
5935 + }
5936 + }
5937 + }
5938 + i++;
5939 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5940 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5941 + }
5942 +
5943 + if (count == 1)
5944 + return 0;
5945 +
5946 +
5947 + for (i = 0; i < dependent_pkgs->len; i++) {
5948 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5949 + if (err)
5950 + return err;
5951 + }
5952 + return 0;
5953 +}
5954 +
5955 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5956 +{
5957 + abstract_pkg_t *dep_ab_pkg;
5958 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5959 + while ((dep_ab_pkg = *dependents++) != NULL) {
5960 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5961 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5962 + }
5963 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5964 + ipkg_message(conf, IPKG_ERROR, "");
5965 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5966 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5967 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5968 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5969 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5970 + return 0;
5971 +}
5972 +
5973 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5974 +{
5975 + int err;
5976 + abstract_pkg_t *parent_pkg = NULL;
5977 +
5978 + if (pkg->essential) {
5979 + if (conf->force_removal_of_essential_packages) {
5980 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5981 + "\tIf your system breaks, you get to keep both pieces\n",
5982 + pkg->name);
5983 + } else {
5984 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5985 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5986 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5987 + "\tits will with the option: -force-removal-of-essential-packages\n",
5988 + pkg->name);
5989 + return IPKG_PKG_IS_ESSENTIAL;
5990 + }
5991 + }
5992 +
5993 + if ((parent_pkg = pkg->parent) == NULL)
5994 + return 0;
5995 +
5996 + /* only attempt to remove dependent installed packages if
5997 + * force_depends is not specified or the package is being
5998 + * replaced.
5999 + */
6000 + if (!conf->force_depends
6001 + && !(pkg->state_flag & SF_REPLACE)) {
6002 + abstract_pkg_t **dependents;
6003 + int has_installed_dependents =
6004 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6005 +
6006 + if (has_installed_dependents) {
6007 + /*
6008 + * if this package is depended up by others, then either we should
6009 + * not remove it or we should remove it and all of its dependents
6010 + */
6011 +
6012 + if (!conf->force_removal_of_dependent_packages
6013 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6014 + return IPKG_PKG_HAS_DEPENDENTS;
6015 + }
6016 +
6017 + /* remove packages depending on this package - Karthik */
6018 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6019 + free(dependents);
6020 + if (err) return err;
6021 + }
6022 + }
6023 +
6024 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6025 + fflush(stdout);
6026 +
6027 + pkg->state_flag |= SF_FILELIST_CHANGED;
6028 +
6029 + pkg->state_want = SW_DEINSTALL;
6030 + ipkg_state_changed++;
6031 +
6032 + pkg_run_script(conf, pkg, "prerm", "remove");
6033 +
6034 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6035 + maintains an empty filelist rather than deleting it. That seems
6036 + like a big pain, and I don't see that that should make a big
6037 + difference, but for anyone who wants tighter compatibility,
6038 + feel free to fix this. */
6039 + remove_data_files_and_list(conf, pkg);
6040 +
6041 + pkg_run_script(conf, pkg, "postrm", "remove");
6042 +
6043 + remove_maintainer_scripts_except_postrm(conf, pkg);
6044 +
6045 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6046 + * space, it doesn't make sense to leave extra configurations, files,
6047 + * and maintainer scripts left around. So, we make remove like purge,
6048 + * and take out all the crap :) */
6049 +
6050 + remove_postrm(conf, pkg);
6051 + pkg->state_status = SS_NOT_INSTALLED;
6052 +
6053 + if (parent_pkg)
6054 + parent_pkg->state_status = SS_NOT_INSTALLED;
6055 +
6056 + return 0;
6057 +}
6058 +
6059 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6060 +{
6061 + ipkg_remove_pkg(conf, pkg);
6062 + return 0;
6063 +}
6064 +
6065 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6066 +{
6067 + str_list_t installed_dirs;
6068 + str_list_t *installed_files;
6069 + str_list_elt_t *iter;
6070 + char *file_name;
6071 + conffile_t *conffile;
6072 + int removed_a_dir;
6073 + pkg_t *owner;
6074 +
6075 + str_list_init(&installed_dirs);
6076 + installed_files = pkg_get_installed_files(pkg);
6077 +
6078 + for (iter = installed_files->head; iter; iter = iter->next) {
6079 + file_name = iter->data;
6080 +
6081 + if (file_is_dir(file_name)) {
6082 + str_list_append(&installed_dirs, strdup(file_name));
6083 + continue;
6084 + }
6085 +
6086 + conffile = pkg_get_conffile(pkg, file_name);
6087 + if (conffile) {
6088 + /* XXX: QUESTION: Is this right? I figure we only need to
6089 + save the conffile if it has been modified. Is that what
6090 + dpkg does? Or does dpkg preserve all conffiles? If so,
6091 + this seems like a better thing to do to conserve
6092 + space. */
6093 + if (conffile_has_been_modified(conf, conffile)) {
6094 + printf(" not deleting modified conffile %s\n", file_name);
6095 + fflush(stdout);
6096 + continue;
6097 + }
6098 + }
6099 +
6100 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6101 + if (!conf->noaction)
6102 + unlink(file_name);
6103 + }
6104 +
6105 + if (!conf->noaction) {
6106 + do {
6107 + removed_a_dir = 0;
6108 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6109 + file_name = iter->data;
6110 +
6111 + if (rmdir(file_name) == 0) {
6112 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6113 + removed_a_dir = 1;
6114 + str_list_remove(&installed_dirs, &iter);
6115 + }
6116 + }
6117 + } while (removed_a_dir);
6118 + }
6119 +
6120 + pkg_free_installed_files(pkg);
6121 + /* We have to remove the file list now, so that
6122 + find_pkg_owning_file does not always just report this package */
6123 + pkg_remove_installed_files_list(conf, pkg);
6124 +
6125 + /* Don't print warning for dirs that are provided by other packages */
6126 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6127 + file_name = iter->data;
6128 +
6129 + owner = file_hash_get_file_owner(conf, file_name);
6130 + if (owner) {
6131 + free(iter->data);
6132 + iter->data = NULL;
6133 + str_list_remove(&installed_dirs, &iter);
6134 + }
6135 + }
6136 +
6137 + /* cleanup */
6138 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6139 + free(iter->data);
6140 + iter->data = NULL;
6141 + }
6142 + str_list_deinit(&installed_dirs);
6143 +
6144 + return 0;
6145 +}
6146 +
6147 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6148 +{
6149 + int i, err;
6150 + char *globpattern;
6151 + glob_t globbuf;
6152 +
6153 + if (conf->noaction) return 0;
6154 +
6155 + sprintf_alloc(&globpattern, "%s/%s.*",
6156 + pkg->dest->info_dir, pkg->name);
6157 + err = glob(globpattern, 0, NULL, &globbuf);
6158 + free(globpattern);
6159 + if (err) {
6160 + return 0;
6161 + }
6162 +
6163 + for (i = 0; i < globbuf.gl_pathc; i++) {
6164 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6165 + continue;
6166 + }
6167 + unlink(globbuf.gl_pathv[i]);
6168 + }
6169 + globfree(&globbuf);
6170 +
6171 + return 0;
6172 +}
6173 +
6174 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6175 +{
6176 + char *postrm_file_name;
6177 +
6178 + if (conf->noaction) return 0;
6179 +
6180 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6181 + pkg->dest->info_dir, pkg->name);
6182 + unlink(postrm_file_name);
6183 + free(postrm_file_name);
6184 +
6185 + return 0;
6186 +}
6187 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_remove.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.h
6188 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.h 1970-01-01 00:00:00.000000000 +0000
6189 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.h 2005-07-17 16:10:24.000000000 +0000
6190 @@ -0,0 +1,29 @@
6191 +/* ipkg_remove.h - the itsy package management system
6192 +
6193 + Carl D. Worth
6194 +
6195 + Copyright (C) 2001 University of Southern California
6196 +
6197 + This program is free software; you can redistribute it and/or
6198 + modify it under the terms of the GNU General Public License as
6199 + published by the Free Software Foundation; either version 2, or (at
6200 + your option) any later version.
6201 +
6202 + This program is distributed in the hope that it will be useful, but
6203 + WITHOUT ANY WARRANTY; without even the implied warranty of
6204 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6205 + General Public License for more details.
6206 +*/
6207 +
6208 +#ifndef IPKG_REMOVE_H
6209 +#define IPKG_REMOVE_H
6210 +
6211 +#include "pkg.h"
6212 +#include "ipkg_conf.h"
6213 +
6214 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6215 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6216 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6217 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6218 +
6219 +#endif
6220 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.c
6221 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 00:00:00.000000000 +0000
6222 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.c 2005-07-17 16:10:24.000000000 +0000
6223 @@ -0,0 +1,77 @@
6224 +/* ipkg_upgrade.c - the itsy package management system
6225 +
6226 + Carl D. Worth
6227 + Copyright (C) 2001 University of Southern California
6228 +
6229 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6230 +
6231 + This program is free software; you can redistribute it and/or
6232 + modify it under the terms of the GNU General Public License as
6233 + published by the Free Software Foundation; either version 2, or (at
6234 + your option) any later version.
6235 +
6236 + This program is distributed in the hope that it will be useful, but
6237 + WITHOUT ANY WARRANTY; without even the implied warranty of
6238 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6239 + General Public License for more details.
6240 +*/
6241 +
6242 +#include "ipkg.h"
6243 +#include "ipkg_install.h"
6244 +#include "ipkg_message.h"
6245 +
6246 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6247 +{
6248 + pkg_t *new;
6249 + int cmp;
6250 + char *old_version, *new_version;
6251 +
6252 + if (old->state_flag & SF_HOLD) {
6253 + ipkg_message(conf, IPKG_NOTICE,
6254 + "Not upgrading package %s which is marked "
6255 + "hold (flags=%#x)\n", old->name, old->state_flag);
6256 + return 0;
6257 + }
6258 +
6259 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6260 + if (new == NULL) {
6261 + old_version = pkg_version_str_alloc(old);
6262 + ipkg_message(conf, IPKG_NOTICE,
6263 + "Assuming locally installed package %s (%s) "
6264 + "is up to date.\n", old->name, old_version);
6265 + free(old_version);
6266 + return 0;
6267 + }
6268 +
6269 + old_version = pkg_version_str_alloc(old);
6270 + new_version = pkg_version_str_alloc(new);
6271 +
6272 + cmp = pkg_compare_versions(old, new);
6273 + ipkg_message(conf, IPKG_DEBUG,
6274 + "comparing visible versions of pkg %s:"
6275 + "\n\t%s is installed "
6276 + "\n\t%s is available "
6277 + "\n\t%d was comparison result\n",
6278 + old->name, old_version, new_version, cmp);
6279 + if (cmp == 0) {
6280 + ipkg_message(conf, IPKG_INFO,
6281 + "Package %s (%s) installed in %s is up to date.\n",
6282 + old->name, old_version, old->dest->name);
6283 + free(old_version);
6284 + free(new_version);
6285 + return 0;
6286 + } else if (cmp > 0) {
6287 + ipkg_message(conf, IPKG_NOTICE,
6288 + "Not downgrading package %s on %s from %s to %s.\n",
6289 + old->name, old->dest->name, old_version, new_version);
6290 + free(old_version);
6291 + free(new_version);
6292 + return 0;
6293 + } else if (cmp < 0) {
6294 + new->dest = old->dest;
6295 + old->state_want = SW_DEINSTALL;
6296 + }
6297 +
6298 + new->state_flag |= SF_USER;
6299 + return ipkg_install_pkg(conf, new);
6300 +}
6301 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.h
6302 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 00:00:00.000000000 +0000
6303 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.h 2005-07-17 16:10:24.000000000 +0000
6304 @@ -0,0 +1,18 @@
6305 +/* ipkg_upgrade.c - the itsy package management system
6306 +
6307 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6308 +
6309 + This program is free software; you can redistribute it and/or
6310 + modify it under the terms of the GNU General Public License as
6311 + published by the Free Software Foundation; either version 2, or (at
6312 + your option) any later version.
6313 +
6314 + This program is distributed in the hope that it will be useful, but
6315 + WITHOUT ANY WARRANTY; without even the implied warranty of
6316 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6317 + General Public License for more details.
6318 +*/
6319 +
6320 +#include "ipkg.h"
6321 +
6322 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6323 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.c
6324 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.c 1970-01-01 00:00:00.000000000 +0000
6325 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.c 2005-07-20 10:16:42.000000000 +0000
6326 @@ -0,0 +1,181 @@
6327 +/* ipkg_utils.c - the itsy package management system
6328 +
6329 + Steven M. Ayer
6330 +
6331 + Copyright (C) 2002 Compaq Computer Corporation
6332 +
6333 + This program is free software; you can redistribute it and/or
6334 + modify it under the terms of the GNU General Public License as
6335 + published by the Free Software Foundation; either version 2, or (at
6336 + your option) any later version.
6337 +
6338 + This program is distributed in the hope that it will be useful, but
6339 + WITHOUT ANY WARRANTY; without even the implied warranty of
6340 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6341 + General Public License for more details.
6342 +*/
6343 +
6344 +#include "ipkg.h"
6345 +#include <errno.h>
6346 +#include <ctype.h>
6347 +#include <sys/vfs.h>
6348 +
6349 +#include "ipkg_utils.h"
6350 +#include "pkg.h"
6351 +#include "pkg_hash.h"
6352 +
6353 +struct errlist* error_list;
6354 +
6355 +int get_available_blocks(char * filesystem)
6356 +{
6357 + struct statfs sfs;
6358 +
6359 + if(statfs(filesystem, &sfs)){
6360 + fprintf(stderr, "bad statfs\n");
6361 + return 0;
6362 + }
6363 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6364 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6365 +}
6366 +
6367 +char **read_raw_pkgs_from_file(const char *file_name)
6368 +{
6369 + FILE *fp;
6370 + char **ret;
6371 +
6372 + if(!(fp = fopen(file_name, "r"))){
6373 + fprintf(stderr, "can't get %s open for read\n", file_name);
6374 + return NULL;
6375 + }
6376 +
6377 + ret = read_raw_pkgs_from_stream(fp);
6378 +
6379 + fclose(fp);
6380 +
6381 + return ret;
6382 +}
6383 +
6384 +char **read_raw_pkgs_from_stream(FILE *fp)
6385 +{
6386 + char **raw = NULL, *buf, *scout;
6387 + int count = 0;
6388 + size_t size = 512;
6389 +
6390 + buf = malloc (size);
6391 +
6392 + while (fgets(buf, size, fp)) {
6393 + while (strlen (buf) == (size - 1)
6394 + && buf[size-2] != '\n') {
6395 + size_t o = size - 1;
6396 + size *= 2;
6397 + buf = realloc (buf, size);
6398 + if (fgets (buf + o, size - o, fp) == NULL)
6399 + break;
6400 + }
6401 +
6402 + if(!(count % 50))
6403 + raw = realloc(raw, (count + 50) * sizeof(char *));
6404 +
6405 + if((scout = strchr(buf, '\n')))
6406 + *scout = '\0';
6407 +
6408 + raw[count++] = strdup(buf);
6409 + }
6410 +
6411 + raw = realloc(raw, (count + 1) * sizeof(char *));
6412 + raw[count] = NULL;
6413 +
6414 + free (buf);
6415 +
6416 + return raw;
6417 +}
6418 +
6419 +/* something to remove whitespace, a hash pooper */
6420 +char *trim_alloc(char *line)
6421 +{
6422 + char *new;
6423 + char *dest, *src, *end;
6424 +
6425 + new = malloc(strlen(line) + 1);
6426 + if ( new == NULL ){
6427 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6428 + return NULL;
6429 + }
6430 + dest = new, src = line, end = line + (strlen(line) - 1);
6431 +
6432 + /* remove it from the front */
6433 + while(src &&
6434 + isspace(*src) &&
6435 + *src)
6436 + src++;
6437 + /* and now from the back */
6438 + while((end > src) &&
6439 + isspace(*end))
6440 + end--;
6441 + end++;
6442 + *end = '\0';
6443 + strcpy(new, src);
6444 + /* this does from the first space
6445 + * blasting away any versions stuff in depends
6446 + while(src &&
6447 + !isspace(*src) &&
6448 + *src)
6449 + *dest++ = *src++;
6450 + *dest = '\0';
6451 + */
6452 +
6453 + return new;
6454 +}
6455 +
6456 +int line_is_blank(const char *line)
6457 +{
6458 + const char *s;
6459 +
6460 + for (s = line; *s; s++) {
6461 + if (!isspace(*s))
6462 + return 0;
6463 + }
6464 + return 1;
6465 +}
6466 +
6467 +void push_error_list(struct errlist ** errors, char * msg){
6468 + struct errlist *err_lst_tmp;
6469 +
6470 +
6471 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6472 + err_lst_tmp->errmsg=strdup(msg) ;
6473 + err_lst_tmp->next = *errors;
6474 + *errors = err_lst_tmp;
6475 +}
6476 +
6477 +
6478 +void reverse_error_list(struct errlist **errors){
6479 + struct errlist *result=NULL;
6480 + struct errlist *current= *errors;
6481 + struct errlist *next;
6482 +
6483 + while ( current != NULL ) {
6484 + next = current->next;
6485 + current->next=result;
6486 + result=current;
6487 + current=next;
6488 + }
6489 + *errors=result;
6490 +
6491 +}
6492 +
6493 +
6494 +void free_error_list(struct errlist **errors){
6495 + struct errlist *current = *errors;
6496 +
6497 + while (current != NULL) {
6498 + free(current->errmsg);
6499 + current = (*errors)->next;
6500 + free(*errors);
6501 + *errors = current;
6502 + }
6503 +
6504 +
6505 +}
6506 +
6507 +
6508 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.h
6509 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.h 1970-01-01 00:00:00.000000000 +0000
6510 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.h 2005-07-17 16:10:24.000000000 +0000
6511 @@ -0,0 +1,29 @@
6512 +/* ipkg_utils.h - the itsy package management system
6513 +
6514 + Steven M. Ayer
6515 +
6516 + Copyright (C) 2002 Compaq Computer Corporation
6517 +
6518 + This program is free software; you can redistribute it and/or
6519 + modify it under the terms of the GNU General Public License as
6520 + published by the Free Software Foundation; either version 2, or (at
6521 + your option) any later version.
6522 +
6523 + This program is distributed in the hope that it will be useful, but
6524 + WITHOUT ANY WARRANTY; without even the implied warranty of
6525 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6526 + General Public License for more details.
6527 +*/
6528 +
6529 +#ifndef IPKG_UTILS_H
6530 +#define IPKG_UTILS_H
6531 +
6532 +#include "pkg.h"
6533 +
6534 +int get_available_blocks(char * filesystem);
6535 +char **read_raw_pkgs_from_file(const char *file_name);
6536 +char **read_raw_pkgs_from_stream(FILE *fp);
6537 +char *trim_alloc(char * line);
6538 +int line_is_blank(const char *line);
6539 +
6540 +#endif
6541 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.c
6542 --- busybox-1.00-orig/archival/libipkg/libipkg.c 1970-01-01 00:00:00.000000000 +0000
6543 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.c 2005-07-20 10:22:50.000000000 +0000
6544 @@ -0,0 +1,512 @@
6545 +/* ipkglib.c - the itsy package management system
6546 +
6547 + Florina Boor
6548 +
6549 + Copyright (C) 2003 kernel concepts
6550 +
6551 + This program is free software; you can redistribute it and/or
6552 + modify it under the terms of the GNU General Public License as
6553 + published by the Free Software Foundation; either version 2, or (at
6554 + your option) any later version.
6555 +
6556 + This program is distributed in the hope that it will be useful, but
6557 + WITHOUT ANY WARRANTY; without even the implied warranty of
6558 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6559 + General Public License for more details.
6560 +*/
6561 +
6562 +#ifdef IPKG_LIB
6563 +
6564 +#include "ipkg.h"
6565 +#include "ipkg_includes.h"
6566 +#include "libipkg.h"
6567 +
6568 +#include "args.h"
6569 +#include "ipkg_conf.h"
6570 +#include "ipkg_cmd.h"
6571 +#include "file_util.h"
6572 +
6573 +
6574 +
6575 +ipkg_message_callback ipkg_cb_message = NULL;
6576 +ipkg_response_callback ipkg_cb_response = NULL;
6577 +ipkg_status_callback ipkg_cb_status = NULL;
6578 +ipkg_list_callback ipkg_cb_list = NULL;
6579 +
6580 +
6581 +int
6582 +ipkg_init (ipkg_message_callback mcall,
6583 + ipkg_response_callback rcall,
6584 + args_t * args)
6585 +{
6586 + ipkg_cb_message = mcall;
6587 + ipkg_cb_response = rcall;
6588 +
6589 + args_init (args);
6590 +
6591 + return 0;
6592 +}
6593 +
6594 +
6595 +int
6596 +ipkg_deinit (args_t * args)
6597 +{
6598 + args_deinit (args);
6599 + ipkg_cb_message = NULL;
6600 + ipkg_cb_response = NULL;
6601 +
6602 + /* place other cleanup stuff here */
6603 +
6604 + return 0;
6605 +}
6606 +
6607 +
6608 +int
6609 +ipkg_packages_list(args_t *args,
6610 + const char *packages,
6611 + ipkg_list_callback cblist,
6612 + void *userdata)
6613 +{
6614 + ipkg_cmd_t *cmd;
6615 + ipkg_conf_t ipkg_conf;
6616 + int err;
6617 +
6618 + err = ipkg_conf_init (&ipkg_conf, args);
6619 + if (err)
6620 + {
6621 + return err;
6622 + }
6623 +
6624 + ipkg_cb_list = cblist;
6625 + /* we need to do this because of static declarations,
6626 + * maybe a good idea to change */
6627 + cmd = ipkg_cmd_find ("list");
6628 + if (packages)
6629 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6630 + else
6631 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6632 + ipkg_cb_list = NULL;
6633 + ipkg_conf_deinit (&ipkg_conf);
6634 + return (err);
6635 +}
6636 +
6637 +
6638 +int
6639 +ipkg_packages_status(args_t *args,
6640 + const char *packages,
6641 + ipkg_status_callback cbstatus,
6642 + void *userdata)
6643 +{
6644 + ipkg_cmd_t *cmd;
6645 + ipkg_conf_t ipkg_conf;
6646 + int err;
6647 +
6648 + err = ipkg_conf_init (&ipkg_conf, args);
6649 + if (err)
6650 + {
6651 + return err;
6652 + }
6653 +
6654 + ipkg_cb_status = cbstatus;
6655 +
6656 + /* we need to do this because of static declarations,
6657 + * maybe a good idea to change */
6658 + cmd = ipkg_cmd_find ("status");
6659 + if (packages)
6660 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6661 + else
6662 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6663 +
6664 + ipkg_cb_status = NULL;
6665 + ipkg_conf_deinit (&ipkg_conf);
6666 + return (err);
6667 +}
6668 +
6669 +
6670 +int
6671 +ipkg_packages_info(args_t *args,
6672 + const char *packages,
6673 + ipkg_status_callback cbstatus,
6674 + void *userdata)
6675 +{
6676 + ipkg_cmd_t *cmd;
6677 + ipkg_conf_t ipkg_conf;
6678 + int err;
6679 +
6680 + err = ipkg_conf_init (&ipkg_conf, args);
6681 + if (err)
6682 + {
6683 + return err;
6684 + }
6685 +
6686 + ipkg_cb_status = cbstatus;
6687 +
6688 + /* we need to do this because of static declarations,
6689 + * maybe a good idea to change */
6690 + cmd = ipkg_cmd_find ("info");
6691 + if (packages)
6692 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6693 + else
6694 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6695 +
6696 + ipkg_cb_status = NULL;
6697 + ipkg_conf_deinit (&ipkg_conf);
6698 + return (err);
6699 +}
6700 +
6701 +
6702 +int
6703 +ipkg_packages_install (args_t * args, const char *name)
6704 +{
6705 + ipkg_cmd_t *cmd;
6706 + ipkg_conf_t ipkg_conf;
6707 + int err;
6708 +
6709 + /* this error should be handled in application */
6710 + if (!name || !strlen (name))
6711 + return (-1);
6712 +
6713 + err = ipkg_conf_init (&ipkg_conf, args);
6714 + if (err)
6715 + {
6716 + return err;
6717 + }
6718 +
6719 + /* we need to do this because of static declarations,
6720 + * maybe a good idea to change */
6721 + cmd = ipkg_cmd_find ("install");
6722 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6723 +
6724 + ipkg_conf_deinit(&ipkg_conf);
6725 + return (err);
6726 +}
6727 +
6728 +
6729 +int
6730 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6731 +{
6732 + ipkg_cmd_t *cmd;
6733 + ipkg_conf_t ipkg_conf;
6734 + int err;
6735 +
6736 + /* this error should be handled in application */
6737 + if (!name || !strlen (name))
6738 + return (-1);
6739 +
6740 + err = ipkg_conf_init (&ipkg_conf, args);
6741 + if (err)
6742 + {
6743 + return err;
6744 + }
6745 +
6746 + /* we need to do this because of static declarations,
6747 + * maybe a good idea to change */
6748 + if (purge)
6749 + cmd = ipkg_cmd_find ("purge");
6750 + else
6751 + cmd = ipkg_cmd_find ("remove");
6752 +
6753 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6754 +
6755 + ipkg_conf_deinit(&ipkg_conf);
6756 + return (err);
6757 +}
6758 +
6759 +
6760 +int
6761 +ipkg_lists_update(args_t *args)
6762 +{
6763 + ipkg_cmd_t *cmd;
6764 + ipkg_conf_t ipkg_conf;
6765 + int err;
6766 +
6767 + err = ipkg_conf_init (&ipkg_conf, args);
6768 + if (err)
6769 + {
6770 + return err;
6771 + }
6772 +
6773 + /* we need to do this because of static declarations,
6774 + * maybe a good idea to change */
6775 + cmd = ipkg_cmd_find ("update");
6776 +
6777 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6778 +
6779 + ipkg_conf_deinit(&ipkg_conf);
6780 + return (err);
6781 +}
6782 +
6783 +
6784 +int
6785 +ipkg_packages_upgrade(args_t *args)
6786 +{
6787 + ipkg_cmd_t *cmd;
6788 + ipkg_conf_t ipkg_conf;
6789 + int err;
6790 +
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6792 + if (err)
6793 + {
6794 + return err;
6795 + }
6796 +
6797 + /* we need to do this because of static declarations,
6798 + * maybe a good idea to change */
6799 + cmd = ipkg_cmd_find ("upgrade");
6800 +
6801 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6802 +
6803 + ipkg_conf_deinit(&ipkg_conf);
6804 + return (err);
6805 +}
6806 +
6807 +
6808 +int
6809 +ipkg_packages_download (args_t * args, const char *name)
6810 +{
6811 + ipkg_cmd_t *cmd;
6812 + ipkg_conf_t ipkg_conf;
6813 + int err;
6814 +
6815 + /* this error should be handled in application */
6816 + if (!name || !strlen (name))
6817 + return (-1);
6818 +
6819 + err = ipkg_conf_init (&ipkg_conf, args);
6820 + if (err)
6821 + {
6822 + return err;
6823 + }
6824 +
6825 + /* we need to do this because of static declarations,
6826 + * maybe a good idea to change */
6827 + cmd = ipkg_cmd_find ("download");
6828 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6829 +
6830 + ipkg_conf_deinit(&ipkg_conf);
6831 + return (err);
6832 +}
6833 +
6834 +
6835 +int
6836 +ipkg_package_files(args_t *args,
6837 + const char *name,
6838 + ipkg_list_callback cblist,
6839 + void *userdata)
6840 +{
6841 + ipkg_cmd_t *cmd;
6842 + ipkg_conf_t ipkg_conf;
6843 + int err;
6844 +
6845 + /* this error should be handled in application */
6846 + if (!name || !strlen (name))
6847 + return (-1);
6848 +
6849 + err = ipkg_conf_init (&ipkg_conf, args);
6850 + if (err)
6851 + {
6852 + return err;
6853 + }
6854 +
6855 + ipkg_cb_list = cblist;
6856 +
6857 + /* we need to do this because of static declarations,
6858 + * maybe a good idea to change */
6859 + cmd = ipkg_cmd_find ("files");
6860 +
6861 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6862 +
6863 + ipkg_cb_list = NULL;
6864 + ipkg_conf_deinit(&ipkg_conf);
6865 + return (err);
6866 +}
6867 +
6868 +
6869 +int
6870 +ipkg_file_search(args_t *args,
6871 + const char *file,
6872 + ipkg_list_callback cblist,
6873 + void *userdata)
6874 +{
6875 + ipkg_cmd_t *cmd;
6876 + ipkg_conf_t ipkg_conf;
6877 + int err;
6878 +
6879 + /* this error should be handled in application */
6880 + if (!file || !strlen (file))
6881 + return (-1);
6882 +
6883 + err = ipkg_conf_init (&ipkg_conf, args);
6884 + if (err)
6885 + {
6886 + return err;
6887 + }
6888 +
6889 + ipkg_cb_list = cblist;
6890 +
6891 + /* we need to do this because of static declarations,
6892 + * maybe a good idea to change */
6893 + cmd = ipkg_cmd_find ("search");
6894 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6895 +
6896 + ipkg_cb_list = NULL;
6897 + ipkg_conf_deinit(&ipkg_conf);
6898 + return(err);
6899 +}
6900 +
6901 +
6902 +int
6903 +ipkg_file_what(args_t *args, const char *file, const char* command)
6904 +{
6905 + ipkg_cmd_t *cmd;
6906 + ipkg_conf_t ipkg_conf;
6907 + int err;
6908 +
6909 + /* this error should be handled in application */
6910 + if (!file || !strlen (file))
6911 + return (-1);
6912 +
6913 + err = ipkg_conf_init (&ipkg_conf, args);
6914 + if (err)
6915 + {
6916 + return err;
6917 + }
6918 +
6919 + /* we need to do this because of static declarations,
6920 + * maybe a good idea to change */
6921 + cmd = ipkg_cmd_find (command);
6922 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6923 +
6924 + ipkg_conf_deinit(&ipkg_conf);
6925 + return(err);
6926 +}
6927 +
6928 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6929 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6930 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6931 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6932 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6933 +
6934 +
6935 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6936 + char *msg)
6937 +{
6938 + if (conf && (conf->verbosity < level)) {
6939 + return 0;
6940 + } else {
6941 +#ifdef IPKG_LIB
6942 + if ( level == IPKG_ERROR ){
6943 + push_error_list(&error_list, msg);
6944 +// printf(msg);
6945 + } else
6946 +#endif
6947 + printf(msg);
6948 + }
6949 + return 0;
6950 +}
6951 +
6952 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6953 + pkg_state_status_t status, void *userdata)
6954 +{
6955 + if (desc)
6956 + printf("%s - %s - %s\n", name, version, desc);
6957 + else
6958 + printf("%s - %s\n", name, version);
6959 + return 0;
6960 +}
6961 +
6962 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6963 + pkg_state_status_t status, void *userdata)
6964 +{
6965 + if (desc)
6966 + printf("%s\n", desc);
6967 + return 0;
6968 +}
6969 +
6970 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6971 + void *userdata)
6972 +{
6973 + printf("%s\n", desc);
6974 + return 0;
6975 +}
6976 +
6977 +char* default_ipkg_response_callback(char *question)
6978 +{
6979 + char *response = NULL;
6980 + printf(question);
6981 + fflush(stdout);
6982 + do {
6983 + response = (char *)file_read_line_alloc(stdin);
6984 + } while (response == NULL);
6985 + return response;
6986 +}
6987 +
6988 +/* This is used for backward compatibility */
6989 +int
6990 +ipkg_op (int argc, char *argv[])
6991 +{
6992 + int err, optind;
6993 + args_t args;
6994 + char *cmd_name;
6995 + ipkg_cmd_t *cmd;
6996 + ipkg_conf_t ipkg_conf;
6997 +
6998 + args_init (&args);
6999 +
7000 + optind = args_parse (&args, argc, argv);
7001 + if (optind == argc || optind < 0)
7002 + {
7003 + args_usage ("ipkg must have one sub-command argument");
7004 + }
7005 +
7006 + cmd_name = argv[optind++];
7007 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7008 + read anything from there.
7009 +*/
7010 + if ( !strcmp(cmd_name,"print-architecture") ||
7011 + !strcmp(cmd_name,"print_architecture") ||
7012 + !strcmp(cmd_name,"print-installation-architecture") ||
7013 + !strcmp(cmd_name,"print_installation_architecture") )
7014 + args.nocheckfordirorfile = 1;
7015 +
7016 +
7017 + err = ipkg_conf_init (&ipkg_conf, &args);
7018 + if (err)
7019 + {
7020 + return err;
7021 + }
7022 +
7023 + args_deinit (&args);
7024 +
7025 + ipkg_cb_message = default_ipkg_message_callback;
7026 + ipkg_cb_response = default_ipkg_response_callback;
7027 + ipkg_cb_status = default_ipkg_status_callback;
7028 + if ( strcmp(cmd_name, "files")==0)
7029 + ipkg_cb_list = default_ipkg_files_callback;
7030 + else
7031 + ipkg_cb_list = default_ipkg_list_callback;
7032 +
7033 + cmd = ipkg_cmd_find (cmd_name);
7034 + if (cmd == NULL)
7035 + {
7036 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7037 + cmd_name);
7038 + args_usage (NULL);
7039 + }
7040 +
7041 + if (cmd->requires_args && optind == argc)
7042 + {
7043 + fprintf (stderr,
7044 + "%s: the ``%s'' command requires at least one argument\n",
7045 + __FUNCTION__, cmd_name);
7046 + args_usage (NULL);
7047 + }
7048 +
7049 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7050 +
7051 + ipkg_conf_deinit (&ipkg_conf);
7052 +
7053 + return err;
7054 +}
7055 +
7056 +#endif /* IPKG_LIB */
7057 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.h
7058 --- busybox-1.00-orig/archival/libipkg/libipkg.h 1970-01-01 00:00:00.000000000 +0000
7059 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.h 2005-07-20 10:21:59.000000000 +0000
7060 @@ -0,0 +1,87 @@
7061 +/* ipkglib.h - the itsy package management system
7062 +
7063 + Florian Boor <florian.boor@kernelconcepts.de>
7064 +
7065 + This program is free software; you can redistribute it and/or
7066 + modify it under the terms of the GNU General Public License as
7067 + published by the Free Software Foundation; either version 2, or (at
7068 + your option) any later version.
7069 +
7070 + This program is distributed in the hope that it will be useful, but
7071 + WITHOUT ANY WARRANTY; without even the implied warranty of
7072 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7073 + General Public License for more details.
7074 +*/
7075 +
7076 +#ifndef IPKGLIB_H
7077 +#define IPKGLIB_H
7078 +
7079 +#ifdef IPKG_LIB
7080 +
7081 +#include "ipkg_conf.h"
7082 +#include "ipkg_message.h"
7083 +
7084 +#include "args.h"
7085 +#include "pkg.h"
7086 +
7087 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7088 + char *msg);
7089 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7090 + pkg_state_status_t status, void *userdata);
7091 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7092 + void *userdata);
7093 +typedef char* (*ipkg_response_callback)(char *question);
7094 +
7095 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7096 +extern int ipkg_init (ipkg_message_callback mcall,
7097 + ipkg_response_callback rcall,
7098 + args_t * args);
7099 +
7100 +extern int ipkg_deinit (args_t *args);
7101 +extern int ipkg_packages_list(args_t *args,
7102 + const char *packages,
7103 + ipkg_list_callback cblist,
7104 + void *userdata);
7105 +extern int ipkg_packages_status(args_t *args,
7106 + const char *packages,
7107 + ipkg_status_callback cbstatus,
7108 + void *userdata);
7109 +extern int ipkg_packages_info(args_t *args,
7110 + const char *packages,
7111 + ipkg_status_callback cbstatus,
7112 + void *userdata);
7113 +extern int ipkg_packages_install(args_t *args, const char *name);
7114 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7115 +extern int ipkg_lists_update(args_t *args);
7116 +extern int ipkg_packages_upgrade(args_t *args);
7117 +extern int ipkg_packages_download(args_t *args, const char *name);
7118 +extern int ipkg_package_files(args_t *args,
7119 + const char *name,
7120 + ipkg_list_callback cblist,
7121 + void *userdata);
7122 +extern int ipkg_file_search(args_t *args,
7123 + const char *file,
7124 + ipkg_list_callback cblist,
7125 + void *userdata);
7126 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7127 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7128 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7129 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7130 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7131 +
7132 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7133 +extern ipkg_response_callback ipkg_cb_response;
7134 +extern ipkg_status_callback ipkg_cb_status;
7135 +extern ipkg_list_callback ipkg_cb_list;
7136 +extern void push_error_list(struct errlist **errors,char * msg);
7137 +extern void reverse_error_list(struct errlist **errors);
7138 +extern void free_error_list(struct errlist **errors);
7139 +
7140 +#else
7141 +
7142 +extern int ipkg_op(int argc, char *argv[]);
7143 +
7144 +#endif
7145 +
7146 +
7147 +#endif
7148 diff -ruN busybox-1.00-orig/archival/libipkg/md5.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.c
7149 --- busybox-1.00-orig/archival/libipkg/md5.c 1970-01-01 00:00:00.000000000 +0000
7150 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.c 2005-07-20 16:54:34.905805584 +0000
7151 @@ -0,0 +1,48 @@
7152 +/* md5.c - wrappers to busybox md5 functions
7153 + *
7154 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7155 + *
7156 + * This program is free software; you can redistribute it and/or modify
7157 + * it under the terms of the GNU General Public License as published by
7158 + * the Free Software Foundation; either version 2, or (at your option)
7159 + * any later version.
7160 + *
7161 + * This program is distributed in the hope that it will be useful,
7162 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7163 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7164 + * GNU General Public License for more details.
7165 + *
7166 + * You should have received a copy of the GNU General Public License
7167 + * along with this program; if not, write to the Free Software Foundation,
7168 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7169 + */
7170 +
7171 +#include <stdio.h>
7172 +#include "libbb.h"
7173 +
7174 +#include "md5.h"
7175 +
7176 +int md5_stream(FILE *stream, void *resblock)
7177 +{
7178 + int fd;
7179 + int sum;
7180 +
7181 + if( (fd = fileno(stream)) == -1 ) {
7182 + bb_error_msg("bad file descriptor");
7183 + return 1;
7184 + }
7185 +
7186 + hash_fd(fd, -1, HASH_MD5, (uint8_t *)resblock);
7187 +
7188 + return 0;
7189 +}
7190 +
7191 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7192 +{
7193 + struct md5_ctx_t md5_cx;
7194 +
7195 + md5_begin(&md5_cx);
7196 + md5_hash(buffer, len, &md5_cx);
7197 + return md5_end(resblock, &md5_cx);
7198 +}
7199 +
7200 diff -ruN busybox-1.00-orig/archival/libipkg/md5.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.h
7201 --- busybox-1.00-orig/archival/libipkg/md5.h 1970-01-01 00:00:00.000000000 +0000
7202 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.h 2005-07-17 16:10:24.000000000 +0000
7203 @@ -0,0 +1,35 @@
7204 +/* md5.h - Compute MD5 checksum of files or strings according to the
7205 + * definition of MD5 in RFC 1321 from April 1992.
7206 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7207 + *
7208 + * This program is free software; you can redistribute it and/or modify
7209 + * it under the terms of the GNU General Public License as published by
7210 + * the Free Software Foundation; either version 2, or (at your option)
7211 + * any later version.
7212 + *
7213 + * This program is distributed in the hope that it will be useful,
7214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7216 + * GNU General Public License for more details.
7217 + *
7218 + * You should have received a copy of the GNU General Public License
7219 + * along with this program; if not, write to the Free Software Foundation,
7220 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7221 + */
7222 +
7223 +#ifndef MD5_H
7224 +#define MD5_H
7225 +
7226 +/* Compute MD5 message digest for bytes read from STREAM. The
7227 + resulting message digest number will be written into the 16 bytes
7228 + beginning at RESBLOCK. */
7229 +int md5_stream(FILE *stream, void *resblock);
7230 +
7231 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7232 + result is always in little endian byte order, so that a byte-wise
7233 + output yields to the wanted ASCII representation of the message
7234 + digest. */
7235 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7236 +
7237 +#endif
7238 +
7239 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.c
7240 --- busybox-1.00-orig/archival/libipkg/nv_pair.c 1970-01-01 00:00:00.000000000 +0000
7241 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.c 2005-07-17 16:10:24.000000000 +0000
7242 @@ -0,0 +1,40 @@
7243 +/* nv_pair.c - the itsy package management system
7244 +
7245 + Carl D. Worth
7246 +
7247 + Copyright (C) 2001 University of Southern California
7248 +
7249 + This program is free software; you can redistribute it and/or
7250 + modify it under the terms of the GNU General Public License as
7251 + published by the Free Software Foundation; either version 2, or (at
7252 + your option) any later version.
7253 +
7254 + This program is distributed in the hope that it will be useful, but
7255 + WITHOUT ANY WARRANTY; without even the implied warranty of
7256 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7257 + General Public License for more details.
7258 +*/
7259 +
7260 +#include "ipkg.h"
7261 +
7262 +#include "nv_pair.h"
7263 +#include "str_util.h"
7264 +
7265 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7266 +{
7267 + nv_pair->name = str_dup_safe(name);
7268 + nv_pair->value = str_dup_safe(value);
7269 +
7270 + return 0;
7271 +}
7272 +
7273 +void nv_pair_deinit(nv_pair_t *nv_pair)
7274 +{
7275 + free(nv_pair->name);
7276 + nv_pair->name = NULL;
7277 +
7278 + free(nv_pair->value);
7279 + nv_pair->value = NULL;
7280 +}
7281 +
7282 +
7283 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.h
7284 --- busybox-1.00-orig/archival/libipkg/nv_pair.h 1970-01-01 00:00:00.000000000 +0000
7285 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.h 2005-07-17 16:10:24.000000000 +0000
7286 @@ -0,0 +1,32 @@
7287 +/* nv_pair.h - the itsy package management system
7288 +
7289 + Carl D. Worth
7290 +
7291 + Copyright (C) 2001 University of Southern California
7292 +
7293 + This program is free software; you can redistribute it and/or
7294 + modify it under the terms of the GNU General Public License as
7295 + published by the Free Software Foundation; either version 2, or (at
7296 + your option) any later version.
7297 +
7298 + This program is distributed in the hope that it will be useful, but
7299 + WITHOUT ANY WARRANTY; without even the implied warranty of
7300 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7301 + General Public License for more details.
7302 +*/
7303 +
7304 +#ifndef NV_PAIR_H
7305 +#define NV_PAIR_H
7306 +
7307 +typedef struct nv_pair nv_pair_t;
7308 +struct nv_pair
7309 +{
7310 + char *name;
7311 + char *value;
7312 +};
7313 +
7314 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7315 +void nv_pair_deinit(nv_pair_t *nv_pair);
7316 +
7317 +#endif
7318 +
7319 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.c
7320 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.c 1970-01-01 00:00:00.000000000 +0000
7321 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.c 2005-07-17 16:10:24.000000000 +0000
7322 @@ -0,0 +1,98 @@
7323 +/* nv_pair_list.c - the itsy package management system
7324 +
7325 + Carl D. Worth
7326 +
7327 + Copyright (C) 2001 University of Southern California
7328 +
7329 + This program is free software; you can redistribute it and/or
7330 + modify it under the terms of the GNU General Public License as
7331 + published by the Free Software Foundation; either version 2, or (at
7332 + your option) any later version.
7333 +
7334 + This program is distributed in the hope that it will be useful, but
7335 + WITHOUT ANY WARRANTY; without even the implied warranty of
7336 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7337 + General Public License for more details.
7338 +*/
7339 +
7340 +#include "ipkg.h"
7341 +
7342 +#include "nv_pair.h"
7343 +#include "void_list.h"
7344 +#include "nv_pair_list.h"
7345 +
7346 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7347 +{
7348 + return void_list_elt_init((void_list_elt_t *) elt, data);
7349 +}
7350 +
7351 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7352 +{
7353 + void_list_elt_deinit((void_list_elt_t *) elt);
7354 +}
7355 +
7356 +int nv_pair_list_init(nv_pair_list_t *list)
7357 +{
7358 + return void_list_init((void_list_t *) list);
7359 +}
7360 +
7361 +void nv_pair_list_deinit(nv_pair_list_t *list)
7362 +{
7363 + nv_pair_list_elt_t *iter;
7364 + nv_pair_t *nv_pair;
7365 +
7366 + for (iter = list->head; iter; iter = iter->next) {
7367 + nv_pair = iter->data;
7368 + nv_pair_deinit(nv_pair);
7369 +
7370 + /* malloced in nv_pair_list_append */
7371 + free(nv_pair);
7372 + iter->data = NULL;
7373 + }
7374 + void_list_deinit((void_list_t *) list);
7375 +}
7376 +
7377 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7378 +{
7379 + int err;
7380 +
7381 + /* freed in nv_pair_list_deinit */
7382 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7383 +
7384 + if (nv_pair == NULL) {
7385 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7386 + return NULL;
7387 + }
7388 + nv_pair_init(nv_pair, name, value);
7389 +
7390 + err = void_list_append((void_list_t *) list, nv_pair);
7391 + if (err) {
7392 + return NULL;
7393 + }
7394 +
7395 + return nv_pair;
7396 +}
7397 +
7398 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7399 +{
7400 + return void_list_push((void_list_t *) list, data);
7401 +}
7402 +
7403 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7404 +{
7405 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7406 +}
7407 +
7408 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7409 +{
7410 + nv_pair_list_elt_t *iter;
7411 + nv_pair_t *nv_pair;
7412 +
7413 + for (iter = list->head; iter; iter = iter->next) {
7414 + nv_pair = iter->data;
7415 + if (strcmp(nv_pair->name, name) == 0) {
7416 + return nv_pair->value;
7417 + }
7418 + }
7419 + return NULL;
7420 +}
7421 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.h
7422 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.h 1970-01-01 00:00:00.000000000 +0000
7423 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.h 2005-07-17 16:10:24.000000000 +0000
7424 @@ -0,0 +1,60 @@
7425 +/* nv_pair_list.h - the itsy package management system
7426 +
7427 + Carl D. Worth
7428 +
7429 + Copyright (C) 2001 University of Southern California
7430 +
7431 + This program is free software; you can redistribute it and/or
7432 + modify it under the terms of the GNU General Public License as
7433 + published by the Free Software Foundation; either version 2, or (at
7434 + your option) any later version.
7435 +
7436 + This program is distributed in the hope that it will be useful, but
7437 + WITHOUT ANY WARRANTY; without even the implied warranty of
7438 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7439 + General Public License for more details.
7440 +*/
7441 +
7442 +#ifndef NV_PAIR_LIST_H
7443 +#define NV_PAIR_LIST_H
7444 +
7445 +#include "nv_pair.h"
7446 +#include "void_list.h"
7447 +
7448 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7449 +struct nv_pair_list_elt
7450 +{
7451 + nv_pair_list_elt_t *next;
7452 + nv_pair_t *data;
7453 +};
7454 +
7455 +typedef struct nv_pair_list nv_pair_list_t;
7456 +struct nv_pair_list
7457 +{
7458 + nv_pair_list_elt_t pre_head;
7459 + nv_pair_list_elt_t *head;
7460 + nv_pair_list_elt_t *tail;
7461 +};
7462 +
7463 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7464 +{
7465 + if (list->head == NULL)
7466 + return 1;
7467 + else
7468 + return 0;
7469 +}
7470 +
7471 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7472 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7473 +
7474 +int nv_pair_list_init(nv_pair_list_t *list);
7475 +void nv_pair_list_deinit(nv_pair_list_t *list);
7476 +
7477 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7478 + const char *name, const char *value);
7479 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7480 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7481 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7482 +
7483 +#endif
7484 +
7485 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.c
7486 --- busybox-1.00-orig/archival/libipkg/pkg.c 1970-01-01 00:00:00.000000000 +0000
7487 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.c 2005-07-17 16:10:24.000000000 +0000
7488 @@ -0,0 +1,1753 @@
7489 +/* pkg.c - the itsy package management system
7490 +
7491 + Carl D. Worth
7492 +
7493 + Copyright (C) 2001 University of Southern California
7494 +
7495 + This program is free software; you can redistribute it and/or
7496 + modify it under the terms of the GNU General Public License as
7497 + published by the Free Software Foundation; either version 2, or (at
7498 + your option) any later version.
7499 +
7500 + This program is distributed in the hope that it will be useful, but
7501 + WITHOUT ANY WARRANTY; without even the implied warranty of
7502 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7503 + General Public License for more details.
7504 +*/
7505 +
7506 +#include "ipkg.h"
7507 +#include <ctype.h>
7508 +#include <string.h>
7509 +#include <errno.h>
7510 +
7511 +#include "pkg.h"
7512 +
7513 +#include "pkg_parse.h"
7514 +#include "pkg_extract.h"
7515 +#include "ipkg_message.h"
7516 +#include "ipkg_utils.h"
7517 +
7518 +#include "sprintf_alloc.h"
7519 +#include "file_util.h"
7520 +#include "str_util.h"
7521 +#include "xsystem.h"
7522 +#include "ipkg_conf.h"
7523 +
7524 +typedef struct enum_map enum_map_t;
7525 +struct enum_map
7526 +{
7527 + int value;
7528 + char *str;
7529 +};
7530 +
7531 +static const enum_map_t pkg_state_want_map[] = {
7532 + { SW_UNKNOWN, "unknown"},
7533 + { SW_INSTALL, "install"},
7534 + { SW_DEINSTALL, "deinstall"},
7535 + { SW_PURGE, "purge"}
7536 +};
7537 +
7538 +static const enum_map_t pkg_state_flag_map[] = {
7539 + { SF_OK, "ok"},
7540 + { SF_REINSTREQ, "reinstreq"},
7541 + { SF_HOLD, "hold"},
7542 + { SF_REPLACE, "replace"},
7543 + { SF_NOPRUNE, "noprune"},
7544 + { SF_PREFER, "prefer"},
7545 + { SF_OBSOLETE, "obsolete"},
7546 + { SF_USER, "user"},
7547 +};
7548 +
7549 +static const enum_map_t pkg_state_status_map[] = {
7550 + { SS_NOT_INSTALLED, "not-installed" },
7551 + { SS_UNPACKED, "unpacked" },
7552 + { SS_HALF_CONFIGURED, "half-configured" },
7553 + { SS_INSTALLED, "installed" },
7554 + { SS_HALF_INSTALLED, "half-installed" },
7555 + { SS_CONFIG_FILES, "config-files" },
7556 + { SS_POST_INST_FAILED, "post-inst-failed" },
7557 + { SS_REMOVAL_FAILED, "removal-failed" }
7558 +};
7559 +
7560 +static int verrevcmp(const char *val, const char *ref);
7561 +
7562 +
7563 +pkg_t *pkg_new(void)
7564 +{
7565 + pkg_t *pkg;
7566 +
7567 + pkg = malloc(sizeof(pkg_t));
7568 + if (pkg == NULL) {
7569 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7570 + return NULL;
7571 + }
7572 +
7573 + pkg_init(pkg);
7574 +
7575 + return pkg;
7576 +}
7577 +
7578 +int pkg_init(pkg_t *pkg)
7579 +{
7580 + memset(pkg, 0, sizeof(pkg_t));
7581 + pkg->name = NULL;
7582 + pkg->epoch = 0;
7583 + pkg->version = NULL;
7584 + pkg->revision = NULL;
7585 + pkg->familiar_revision = NULL;
7586 + pkg->dest = NULL;
7587 + pkg->src = NULL;
7588 + pkg->architecture = NULL;
7589 + pkg->maintainer = NULL;
7590 + pkg->section = NULL;
7591 + pkg->description = NULL;
7592 + pkg->state_want = SW_UNKNOWN;
7593 + pkg->state_flag = SF_OK;
7594 + pkg->state_status = SS_NOT_INSTALLED;
7595 + pkg->depends_str = NULL;
7596 + pkg->provides_str = NULL;
7597 + pkg->depends_count = 0;
7598 + pkg->depends = NULL;
7599 + pkg->suggests_str = NULL;
7600 + pkg->recommends_str = NULL;
7601 + pkg->suggests_count = 0;
7602 + pkg->recommends_count = 0;
7603 +
7604 + /* Abhaya: added init for conflicts fields */
7605 + pkg->conflicts = NULL;
7606 + pkg->conflicts_count = 0;
7607 +
7608 + /* added for replaces. Jamey 7/23/2002 */
7609 + pkg->replaces = NULL;
7610 + pkg->replaces_count = 0;
7611 +
7612 + pkg->pre_depends_count = 0;
7613 + pkg->pre_depends_str = NULL;
7614 + pkg->provides_count = 0;
7615 + pkg->provides = NULL;
7616 + pkg->filename = NULL;
7617 + pkg->local_filename = NULL;
7618 + pkg->tmp_unpack_dir = NULL;
7619 + pkg->md5sum = NULL;
7620 + pkg->size = NULL;
7621 + pkg->installed_size = NULL;
7622 + pkg->priority = NULL;
7623 + pkg->source = NULL;
7624 + conffile_list_init(&pkg->conffiles);
7625 + pkg->installed_files = NULL;
7626 + pkg->installed_files_ref_cnt = 0;
7627 + pkg->essential = 0;
7628 +
7629 + return 0;
7630 +}
7631 +
7632 +void pkg_deinit(pkg_t *pkg)
7633 +{
7634 + free(pkg->name);
7635 + pkg->name = NULL;
7636 + pkg->epoch = 0;
7637 + free(pkg->version);
7638 + pkg->version = NULL;
7639 + /* revision and familiar_revision share storage with version, so
7640 + don't free */
7641 + pkg->revision = NULL;
7642 + pkg->familiar_revision = NULL;
7643 + /* owned by ipkg_conf_t */
7644 + pkg->dest = NULL;
7645 + /* owned by ipkg_conf_t */
7646 + pkg->src = NULL;
7647 + free(pkg->architecture);
7648 + pkg->architecture = NULL;
7649 + free(pkg->maintainer);
7650 + pkg->maintainer = NULL;
7651 + free(pkg->section);
7652 + pkg->section = NULL;
7653 + free(pkg->description);
7654 + pkg->description = NULL;
7655 + pkg->state_want = SW_UNKNOWN;
7656 + pkg->state_flag = SF_OK;
7657 + pkg->state_status = SS_NOT_INSTALLED;
7658 + free(pkg->depends_str);
7659 + pkg->depends_str = NULL;
7660 + free(pkg->provides_str);
7661 + pkg->provides_str = NULL;
7662 + pkg->depends_count = 0;
7663 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7664 + pkg->pre_depends_count = 0;
7665 + free(pkg->pre_depends_str);
7666 + pkg->pre_depends_str = NULL;
7667 + pkg->provides_count = 0;
7668 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7669 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7670 + free(pkg->filename);
7671 + pkg->filename = NULL;
7672 + free(pkg->local_filename);
7673 + pkg->local_filename = NULL;
7674 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7675 + ipkg_install.c here. See comment in
7676 + ipkg_install.c:cleanup_temporary_files */
7677 + free(pkg->tmp_unpack_dir);
7678 + pkg->tmp_unpack_dir = NULL;
7679 + free(pkg->md5sum);
7680 + pkg->md5sum = NULL;
7681 + free(pkg->size);
7682 + pkg->size = NULL;
7683 + free(pkg->installed_size);
7684 + pkg->installed_size = NULL;
7685 + free(pkg->priority);
7686 + pkg->priority = NULL;
7687 + free(pkg->source);
7688 + pkg->source = NULL;
7689 + conffile_list_deinit(&pkg->conffiles);
7690 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7691 + since if they are calling deinit, they should know. Maybe do an
7692 + assertion here instead? */
7693 + pkg->installed_files_ref_cnt = 1;
7694 + pkg_free_installed_files(pkg);
7695 + pkg->essential = 0;
7696 +}
7697 +
7698 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7699 +{
7700 + int err;
7701 + char **raw;
7702 + FILE *control_file;
7703 +
7704 + err = pkg_init(pkg);
7705 + if (err) { return err; }
7706 +
7707 + pkg->local_filename = strdup(filename);
7708 +
7709 + control_file = tmpfile();
7710 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7711 + if (err) { return err; }
7712 +
7713 + rewind(control_file);
7714 + raw = read_raw_pkgs_from_stream(control_file);
7715 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7716 +
7717 + fclose(control_file);
7718 +
7719 + return 0;
7720 +}
7721 +
7722 +/* Merge any new information in newpkg into oldpkg */
7723 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7724 + newpkg, but should leave it usable. This rework is so that
7725 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7726 +/*
7727 + * uh, i thought that i had originally written this so that it took
7728 + * two pkgs and returned a new one? we can do that again... -sma
7729 + */
7730 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7731 +{
7732 + if (oldpkg == newpkg) {
7733 + return 0;
7734 + }
7735 +
7736 + if (!oldpkg->src)
7737 + oldpkg->src = newpkg->src;
7738 + if (!oldpkg->dest)
7739 + oldpkg->dest = newpkg->dest;
7740 + if (!oldpkg->architecture)
7741 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7742 + if (!oldpkg->arch_priority)
7743 + oldpkg->arch_priority = newpkg->arch_priority;
7744 + if (!oldpkg->section)
7745 + oldpkg->section = str_dup_safe(newpkg->section);
7746 + if(!oldpkg->maintainer)
7747 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7748 + if(!oldpkg->description)
7749 + oldpkg->description = str_dup_safe(newpkg->description);
7750 + if (set_status) {
7751 + /* merge the state_flags from the new package */
7752 + oldpkg->state_want = newpkg->state_want;
7753 + oldpkg->state_status = newpkg->state_status;
7754 + oldpkg->state_flag = newpkg->state_flag;
7755 + } else {
7756 + if (oldpkg->state_want == SW_UNKNOWN)
7757 + oldpkg->state_want = newpkg->state_want;
7758 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7759 + oldpkg->state_status = newpkg->state_status;
7760 + oldpkg->state_flag |= newpkg->state_flag;
7761 + }
7762 +
7763 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7764 + oldpkg->depends_str = newpkg->depends_str;
7765 + newpkg->depends_str = NULL;
7766 + oldpkg->depends_count = newpkg->depends_count;
7767 + newpkg->depends_count = 0;
7768 +
7769 + oldpkg->depends = newpkg->depends;
7770 + newpkg->depends = NULL;
7771 +
7772 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7773 + newpkg->pre_depends_str = NULL;
7774 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7775 + newpkg->pre_depends_count = 0;
7776 +
7777 + oldpkg->recommends_str = newpkg->recommends_str;
7778 + newpkg->recommends_str = NULL;
7779 + oldpkg->recommends_count = newpkg->recommends_count;
7780 + newpkg->recommends_count = 0;
7781 +
7782 + oldpkg->suggests_str = newpkg->suggests_str;
7783 + newpkg->suggests_str = NULL;
7784 + oldpkg->suggests_count = newpkg->suggests_count;
7785 + newpkg->suggests_count = 0;
7786 + }
7787 +
7788 + if (!oldpkg->provides_str) {
7789 + oldpkg->provides_str = newpkg->provides_str;
7790 + newpkg->provides_str = NULL;
7791 + oldpkg->provides_count = newpkg->provides_count;
7792 + newpkg->provides_count = 0;
7793 +
7794 + oldpkg->provides = newpkg->provides;
7795 + newpkg->provides = NULL;
7796 + }
7797 +
7798 + if (!oldpkg->conflicts_str) {
7799 + oldpkg->conflicts_str = newpkg->conflicts_str;
7800 + newpkg->conflicts_str = NULL;
7801 + oldpkg->conflicts_count = newpkg->conflicts_count;
7802 + newpkg->conflicts_count = 0;
7803 +
7804 + oldpkg->conflicts = newpkg->conflicts;
7805 + newpkg->conflicts = NULL;
7806 + }
7807 +
7808 + if (!oldpkg->replaces_str) {
7809 + oldpkg->replaces_str = newpkg->replaces_str;
7810 + newpkg->replaces_str = NULL;
7811 + oldpkg->replaces_count = newpkg->replaces_count;
7812 + newpkg->replaces_count = 0;
7813 +
7814 + oldpkg->replaces = newpkg->replaces;
7815 + newpkg->replaces = NULL;
7816 + }
7817 +
7818 + if (!oldpkg->filename)
7819 + oldpkg->filename = str_dup_safe(newpkg->filename);
7820 + if (0)
7821 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7822 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7823 + if (!oldpkg->local_filename)
7824 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7825 + if (!oldpkg->tmp_unpack_dir)
7826 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7827 + if (!oldpkg->md5sum)
7828 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7829 + if (!oldpkg->size)
7830 + oldpkg->size = str_dup_safe(newpkg->size);
7831 + if (!oldpkg->installed_size)
7832 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7833 + if (!oldpkg->priority)
7834 + oldpkg->priority = str_dup_safe(newpkg->priority);
7835 + if (!oldpkg->source)
7836 + oldpkg->source = str_dup_safe(newpkg->source);
7837 + if (oldpkg->conffiles.head == NULL){
7838 + oldpkg->conffiles = newpkg->conffiles;
7839 + conffile_list_init(&newpkg->conffiles);
7840 + }
7841 + if (!oldpkg->installed_files){
7842 + oldpkg->installed_files = newpkg->installed_files;
7843 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7844 + newpkg->installed_files = NULL;
7845 + }
7846 + if (!oldpkg->essential)
7847 + oldpkg->essential = newpkg->essential;
7848 +
7849 + return 0;
7850 +}
7851 +
7852 +abstract_pkg_t *abstract_pkg_new(void)
7853 +{
7854 + abstract_pkg_t * ab_pkg;
7855 +
7856 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7857 +
7858 + if (ab_pkg == NULL) {
7859 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7860 + return NULL;
7861 + }
7862 +
7863 + if ( abstract_pkg_init(ab_pkg) < 0 )
7864 + return NULL;
7865 +
7866 + return ab_pkg;
7867 +}
7868 +
7869 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7870 +{
7871 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7872 +
7873 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7874 + if (ab_pkg->provided_by==NULL){
7875 + return -1;
7876 + }
7877 + ab_pkg->dependencies_checked = 0;
7878 + ab_pkg->state_status = SS_NOT_INSTALLED;
7879 +
7880 + return 0;
7881 +}
7882 +
7883 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7884 + char * temp_str;
7885 + char **raw =NULL;
7886 + char **raw_start=NULL;
7887 +
7888 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7889 + if (temp_str == NULL ){
7890 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7891 + return;
7892 + }
7893 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7894 +
7895 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7896 + if (raw == NULL ){
7897 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7898 + return;
7899 + }
7900 +
7901 + while(*raw){
7902 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7903 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7904 + }
7905 + }
7906 + raw = raw_start;
7907 + while (*raw) {
7908 + if (raw!=NULL)
7909 + free(*raw++);
7910 + }
7911 +
7912 + free(raw_start);
7913 + free(temp_str);
7914 +
7915 + return ;
7916 +
7917 +}
7918 +
7919 +char * pkg_formatted_info(pkg_t *pkg )
7920 +{
7921 + char *line;
7922 + char * buff;
7923 +
7924 + buff = malloc(8192);
7925 + if (buff == NULL) {
7926 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7927 + return NULL;
7928 + }
7929 +
7930 + buff[0] = '\0';
7931 +
7932 + line = pkg_formatted_field(pkg, "Package");
7933 + strncat(buff ,line, strlen(line));
7934 + free(line);
7935 +
7936 + line = pkg_formatted_field(pkg, "Version");
7937 + strncat(buff ,line, strlen(line));
7938 + free(line);
7939 +
7940 + line = pkg_formatted_field(pkg, "Depends");
7941 + strncat(buff ,line, strlen(line));
7942 + free(line);
7943 +
7944 + line = pkg_formatted_field(pkg, "Recommends");
7945 + strncat(buff ,line, strlen(line));
7946 + free(line);
7947 +
7948 + line = pkg_formatted_field(pkg, "Suggests");
7949 + strncat(buff ,line, strlen(line));
7950 + free(line);
7951 +
7952 + line = pkg_formatted_field(pkg, "Provides");
7953 + strncat(buff ,line, strlen(line));
7954 + free(line);
7955 +
7956 + line = pkg_formatted_field(pkg, "Replaces");
7957 + strncat(buff ,line, strlen(line));
7958 + free(line);
7959 +
7960 + line = pkg_formatted_field(pkg, "Conflicts");
7961 + strncat(buff ,line, strlen(line));
7962 + free(line);
7963 +
7964 + line = pkg_formatted_field(pkg, "Status");
7965 + strncat(buff ,line, strlen(line));
7966 + free(line);
7967 +
7968 + line = pkg_formatted_field(pkg, "Section");
7969 + strncat(buff ,line, strlen(line));
7970 + free(line);
7971 +
7972 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7973 + strncat(buff ,line, strlen(line));
7974 + free(line);
7975 +
7976 + line = pkg_formatted_field(pkg, "Architecture");
7977 + strncat(buff ,line, strlen(line));
7978 + free(line);
7979 +
7980 + line = pkg_formatted_field(pkg, "Maintainer");
7981 + strncat(buff ,line, strlen(line));
7982 + free(line);
7983 +
7984 + line = pkg_formatted_field(pkg, "MD5sum");
7985 + strncat(buff ,line, strlen(line));
7986 + free(line);
7987 +
7988 + line = pkg_formatted_field(pkg, "Size");
7989 + strncat(buff ,line, strlen(line));
7990 + free(line);
7991 +
7992 + line = pkg_formatted_field(pkg, "Filename");
7993 + strncat(buff ,line, strlen(line));
7994 + free(line);
7995 +
7996 + line = pkg_formatted_field(pkg, "Conffiles");
7997 + strncat(buff ,line, strlen(line));
7998 + free(line);
7999 +
8000 + line = pkg_formatted_field(pkg, "Source");
8001 + strncat(buff ,line, strlen(line));
8002 + free(line);
8003 +
8004 + line = pkg_formatted_field(pkg, "Description");
8005 + strncat(buff ,line, strlen(line));
8006 + free(line);
8007 +
8008 + line = pkg_formatted_field(pkg, "Installed-Time");
8009 + strncat(buff ,line, strlen(line));
8010 + free(line);
8011 +
8012 + return buff;
8013 +}
8014 +
8015 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8016 +{
8017 + static size_t LINE_LEN = 128;
8018 + char * temp = (char *)malloc(1);
8019 + int len = 0;
8020 + int flag_provide_false = 0;
8021 +
8022 +/*
8023 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8024 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8025 +*/
8026 +
8027 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8028 + goto UNKNOWN_FMT_FIELD;
8029 + }
8030 +
8031 + temp[0]='\0';
8032 +
8033 + switch (field[0])
8034 + {
8035 + case 'a':
8036 + case 'A':
8037 + if (strcasecmp(field, "Architecture") == 0) {
8038 + /* Architecture */
8039 + if (pkg->architecture) {
8040 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8041 + if ( temp == NULL ){
8042 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8043 + return NULL;
8044 + }
8045 + temp[0]='\0';
8046 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8047 + }
8048 + } else {
8049 + goto UNKNOWN_FMT_FIELD;
8050 + }
8051 + break;
8052 + case 'c':
8053 + case 'C':
8054 + if (strcasecmp(field, "Conffiles") == 0) {
8055 + /* Conffiles */
8056 + conffile_list_elt_t *iter;
8057 + char confstr[LINE_LEN];
8058 +
8059 + if (pkg->conffiles.head == NULL) {
8060 + return temp;
8061 + }
8062 +
8063 + len = 14 ;
8064 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8065 + if (iter->data->name && iter->data->value) {
8066 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8067 + }
8068 + }
8069 + temp = (char *)realloc(temp,len);
8070 + if ( temp == NULL ){
8071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8072 + return NULL;
8073 + }
8074 + temp[0]='\0';
8075 + strncpy(temp, "Conffiles:\n", 12);
8076 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8077 + if (iter->data->name && iter->data->value) {
8078 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8079 + strncat(temp, confstr, strlen(confstr));
8080 + }
8081 + }
8082 + } else if (strcasecmp(field, "Conflicts") == 0) {
8083 + int i;
8084 +
8085 + if (pkg->conflicts_count) {
8086 + char conflictstr[LINE_LEN];
8087 + len = 14 ;
8088 + for(i = 0; i < pkg->conflicts_count; i++) {
8089 + len = len + (strlen(pkg->conflicts_str[i])+5);
8090 + }
8091 + temp = (char *)realloc(temp,len);
8092 + if ( temp == NULL ){
8093 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8094 + return NULL;
8095 + }
8096 + temp[0]='\0';
8097 + strncpy(temp, "Conflicts:", 11);
8098 + for(i = 0; i < pkg->conflicts_count; i++) {
8099 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8100 + strncat(temp, conflictstr, strlen(conflictstr));
8101 + }
8102 + strncat(temp, "\n", strlen("\n"));
8103 + }
8104 + } else {
8105 + goto UNKNOWN_FMT_FIELD;
8106 + }
8107 + break;
8108 + case 'd':
8109 + case 'D':
8110 + if (strcasecmp(field, "Depends") == 0) {
8111 + /* Depends */
8112 + int i;
8113 +
8114 + if (pkg->depends_count) {
8115 + char depstr[LINE_LEN];
8116 + len = 14 ;
8117 + for(i = 0; i < pkg->depends_count; i++) {
8118 + len = len + (strlen(pkg->depends_str[i])+4);
8119 + }
8120 + temp = (char *)realloc(temp,len);
8121 + if ( temp == NULL ){
8122 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8123 + return NULL;
8124 + }
8125 + temp[0]='\0';
8126 + strncpy(temp, "Depends:", 10);
8127 + for(i = 0; i < pkg->depends_count; i++) {
8128 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8129 + strncat(temp, depstr, strlen(depstr));
8130 + }
8131 + strncat(temp, "\n", strlen("\n"));
8132 + }
8133 + } else if (strcasecmp(field, "Description") == 0) {
8134 + /* Description */
8135 + if (pkg->description) {
8136 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8137 + if ( temp == NULL ){
8138 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8139 + return NULL;
8140 + }
8141 + temp[0]='\0';
8142 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8143 + }
8144 + } else {
8145 + goto UNKNOWN_FMT_FIELD;
8146 + }
8147 + break;
8148 + case 'e':
8149 + case 'E': {
8150 + /* Essential */
8151 + if (pkg->essential) {
8152 + temp = (char *)realloc(temp,16);
8153 + if ( temp == NULL ){
8154 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8155 + return NULL;
8156 + }
8157 + temp[0]='\0';
8158 + snprintf(temp, (16), "Essential: yes\n");
8159 + }
8160 + }
8161 + break;
8162 + case 'f':
8163 + case 'F': {
8164 + /* Filename */
8165 + if (pkg->filename) {
8166 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8167 + if ( temp == NULL ){
8168 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8169 + return NULL;
8170 + }
8171 + temp[0]='\0';
8172 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8173 + }
8174 + }
8175 + break;
8176 + case 'i':
8177 + case 'I': {
8178 + if (strcasecmp(field, "Installed-Size") == 0) {
8179 + /* Installed-Size */
8180 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8181 + if ( temp == NULL ){
8182 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8183 + return NULL;
8184 + }
8185 + temp[0]='\0';
8186 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8187 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8188 + temp = (char *)realloc(temp,29);
8189 + if ( temp == NULL ){
8190 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8191 + return NULL;
8192 + }
8193 + temp[0]='\0';
8194 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8195 + }
8196 + }
8197 + break;
8198 + case 'm':
8199 + case 'M': {
8200 + /* Maintainer | MD5sum */
8201 + if (strcasecmp(field, "Maintainer") == 0) {
8202 + /* Maintainer */
8203 + if (pkg->maintainer) {
8204 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8205 + if ( temp == NULL ){
8206 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8207 + return NULL;
8208 + }
8209 + temp[0]='\0';
8210 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8211 + }
8212 + } else if (strcasecmp(field, "MD5sum") == 0) {
8213 + /* MD5sum */
8214 + if (pkg->md5sum) {
8215 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8216 + if ( temp == NULL ){
8217 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8218 + return NULL;
8219 + }
8220 + temp[0]='\0';
8221 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8222 + }
8223 + } else {
8224 + goto UNKNOWN_FMT_FIELD;
8225 + }
8226 + }
8227 + break;
8228 + case 'p':
8229 + case 'P': {
8230 + if (strcasecmp(field, "Package") == 0) {
8231 + /* Package */
8232 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8233 + if ( temp == NULL ){
8234 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8235 + return NULL;
8236 + }
8237 + temp[0]='\0';
8238 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8239 + } else if (strcasecmp(field, "Priority") == 0) {
8240 + /* Priority */
8241 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8242 + if ( temp == NULL ){
8243 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8244 + return NULL;
8245 + }
8246 + temp[0]='\0';
8247 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8248 + } else if (strcasecmp(field, "Provides") == 0) {
8249 + /* Provides */
8250 + int i;
8251 +
8252 + if (pkg->provides_count) {
8253 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8254 + for ( i=0; i < pkg->provides_count; i++ ){
8255 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8256 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8257 + flag_provide_false = 1;
8258 + }
8259 + }
8260 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8261 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8262 + char provstr[LINE_LEN];
8263 + len = 15;
8264 + for(i = 0; i < pkg->provides_count; i++) {
8265 + len = len + (strlen(pkg->provides_str[i])+5);
8266 + }
8267 + temp = (char *)realloc(temp,len);
8268 + if ( temp == NULL ){
8269 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8270 + return NULL;
8271 + }
8272 + temp[0]='\0';
8273 + strncpy(temp, "Provides:", 12);
8274 + for(i = 0; i < pkg->provides_count; i++) {
8275 + if (strlen(pkg->provides_str[i])>0){;
8276 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8277 + strncat(temp, provstr, strlen(provstr));
8278 + }
8279 + }
8280 + strncat(temp, "\n", strlen("\n"));
8281 + }
8282 + }
8283 + } else {
8284 + goto UNKNOWN_FMT_FIELD;
8285 + }
8286 + }
8287 + break;
8288 + case 'r':
8289 + case 'R': {
8290 + int i;
8291 + /* Replaces | Recommends*/
8292 + if (strcasecmp (field, "Replaces") == 0) {
8293 + if (pkg->replaces_count) {
8294 + char replstr[LINE_LEN];
8295 + len = 14;
8296 + for (i = 0; i < pkg->replaces_count; i++) {
8297 + len = len + (strlen(pkg->replaces_str[i])+5);
8298 + }
8299 + temp = (char *)realloc(temp,len);
8300 + if ( temp == NULL ){
8301 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8302 + return NULL;
8303 + }
8304 + temp[0]='\0';
8305 + strncpy(temp, "Replaces:", 12);
8306 + for (i = 0; i < pkg->replaces_count; i++) {
8307 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8308 + strncat(temp, replstr, strlen(replstr));
8309 + }
8310 + strncat(temp, "\n", strlen("\n"));
8311 + }
8312 + } else if (strcasecmp (field, "Recommends") == 0) {
8313 + if (pkg->recommends_count) {
8314 + char recstr[LINE_LEN];
8315 + len = 15;
8316 + for(i = 0; i < pkg->recommends_count; i++) {
8317 + len = len + (strlen( pkg->recommends_str[i])+5);
8318 + }
8319 + temp = (char *)realloc(temp,len);
8320 + if ( temp == NULL ){
8321 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8322 + return NULL;
8323 + }
8324 + temp[0]='\0';
8325 + strncpy(temp, "Recommends:", 13);
8326 + for(i = 0; i < pkg->recommends_count; i++) {
8327 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8328 + strncat(temp, recstr, strlen(recstr));
8329 + }
8330 + strncat(temp, "\n", strlen("\n"));
8331 + }
8332 + } else {
8333 + goto UNKNOWN_FMT_FIELD;
8334 + }
8335 + }
8336 + break;
8337 + case 's':
8338 + case 'S': {
8339 + /* Section | Size | Source | Status | Suggests */
8340 + if (strcasecmp(field, "Section") == 0) {
8341 + /* Section */
8342 + if (pkg->section) {
8343 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8344 + if ( temp == NULL ){
8345 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8346 + return NULL;
8347 + }
8348 + temp[0]='\0';
8349 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8350 + }
8351 + } else if (strcasecmp(field, "Size") == 0) {
8352 + /* Size */
8353 + if (pkg->size) {
8354 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8355 + if ( temp == NULL ){
8356 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8357 + return NULL;
8358 + }
8359 + temp[0]='\0';
8360 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8361 + }
8362 + } else if (strcasecmp(field, "Source") == 0) {
8363 + /* Source */
8364 + if (pkg->source) {
8365 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8366 + if ( temp == NULL ){
8367 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8368 + return NULL;
8369 + }
8370 + temp[0]='\0';
8371 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8372 + }
8373 + } else if (strcasecmp(field, "Status") == 0) {
8374 + /* Status */
8375 + /* Benjamin Pineau note: we should avoid direct usage of
8376 + * strlen(arg) without keeping "arg" for later free()
8377 + */
8378 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8379 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8380 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8381 +
8382 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8383 + temp = (char *)realloc(temp,sum_of_sizes);
8384 + if ( temp == NULL ){
8385 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8386 + return NULL;
8387 + }
8388 + temp[0]='\0';
8389 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8390 + free(pflag);
8391 + free(pwant);
8392 + if(pstat) /* pfstat can be NULL if ENOMEM */
8393 + free(pstat);
8394 + } else if (strcasecmp(field, "Suggests") == 0) {
8395 + if (pkg->suggests_count) {
8396 + int i;
8397 + char sugstr[LINE_LEN];
8398 + len = 13;
8399 + for(i = 0; i < pkg->suggests_count; i++) {
8400 + len = len + (strlen(pkg->suggests_str[i])+5);
8401 + }
8402 + temp = (char *)realloc(temp,len);
8403 + if ( temp == NULL ){
8404 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8405 + return NULL;
8406 + }
8407 + temp[0]='\0';
8408 + strncpy(temp, "Suggests:", 10);
8409 + for(i = 0; i < pkg->suggests_count; i++) {
8410 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8411 + strncat(temp, sugstr, strlen(sugstr));
8412 + }
8413 + strncat(temp, "\n", strlen("\n"));
8414 + }
8415 + } else {
8416 + goto UNKNOWN_FMT_FIELD;
8417 + }
8418 + }
8419 + break;
8420 + case 'v':
8421 + case 'V': {
8422 + /* Version */
8423 + char *version = pkg_version_str_alloc(pkg);
8424 + temp = (char *)realloc(temp,strlen(version)+14);
8425 + if ( temp == NULL ){
8426 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8427 + return NULL;
8428 + }
8429 + temp[0]='\0';
8430 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8431 + free(version);
8432 + }
8433 + break;
8434 + default:
8435 + goto UNKNOWN_FMT_FIELD;
8436 + }
8437 +
8438 + if ( strlen(temp)<2 ) {
8439 + temp[0]='\0';
8440 + }
8441 + return temp;
8442 +
8443 + UNKNOWN_FMT_FIELD:
8444 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8445 + if ( strlen(temp)<2 ) {
8446 + temp[0]='\0';
8447 + }
8448 +
8449 + return temp;
8450 +}
8451 +
8452 +void pkg_print_info(pkg_t *pkg, FILE *file)
8453 +{
8454 + char * buff;
8455 + if (pkg == NULL) {
8456 + return;
8457 + }
8458 +
8459 + buff = pkg_formatted_info(pkg);
8460 + if ( buff == NULL )
8461 + return;
8462 + if (strlen(buff)>2){
8463 + fwrite(buff, 1, strlen(buff), file);
8464 + }
8465 + free(buff);
8466 +}
8467 +
8468 +void pkg_print_status(pkg_t * pkg, FILE * file)
8469 +{
8470 + if (pkg == NULL) {
8471 + return;
8472 + }
8473 +
8474 + /* XXX: QUESTION: Do we actually want more fields here? The
8475 + original idea was to save space by installing only what was
8476 + needed for actual computation, (package, version, status,
8477 + essential, conffiles). The assumption is that all other fields
8478 + can be found in th available file.
8479 +
8480 + But, someone proposed the idea to make it possible to
8481 + reconstruct a .ipk from an installed package, (ie. for beaming
8482 + from one handheld to another). So, maybe we actually want a few
8483 + more fields here, (depends, suggests, etc.), so that that would
8484 + be guaranteed to work even in the absence of more information
8485 + from the available file.
8486 +
8487 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8488 + the essential info needs to be here for all installed packages
8489 + because they may not appear in the Packages files on various
8490 + feeds. Furthermore, one should be able to install from URL or
8491 + local storage without requiring a Packages file from any feed.
8492 + -Jamey
8493 + */
8494 + pkg_print_field(pkg, file, "Package");
8495 + pkg_print_field(pkg, file, "Version");
8496 + pkg_print_field(pkg, file, "Depends");
8497 + pkg_print_field(pkg, file, "Recommends");
8498 + pkg_print_field(pkg, file, "Suggests");
8499 + pkg_print_field(pkg, file, "Provides");
8500 + pkg_print_field(pkg, file, "Replaces");
8501 + pkg_print_field(pkg, file, "Conflicts");
8502 + pkg_print_field(pkg, file, "Status");
8503 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8504 + pkg_print_field(pkg, file, "Architecture");
8505 + pkg_print_field(pkg, file, "Conffiles");
8506 + pkg_print_field(pkg, file, "Installed-Time");
8507 + fputs("\n", file);
8508 +}
8509 +
8510 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8511 +{
8512 + char *buff;
8513 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8514 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8515 + __FUNCTION__, field);
8516 + }
8517 + buff = pkg_formatted_field(pkg, field);
8518 + if (strlen(buff)>2) {
8519 + fprintf(file, "%s", buff);
8520 + fflush(file);
8521 + }
8522 + free(buff);
8523 + return;
8524 +}
8525 +
8526 +/*
8527 + * libdpkg - Debian packaging suite library routines
8528 + * vercmp.c - comparison of version numbers
8529 + *
8530 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8531 + */
8532 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8533 +{
8534 + int r;
8535 +
8536 + if (pkg->epoch > ref_pkg->epoch) {
8537 + return 1;
8538 + }
8539 +
8540 + if (pkg->epoch < ref_pkg->epoch) {
8541 + return -1;
8542 + }
8543 +
8544 + r = verrevcmp(pkg->version, ref_pkg->version);
8545 + if (r) {
8546 + return r;
8547 + }
8548 +
8549 +#ifdef USE_DEBVERSION
8550 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8551 + if (r) {
8552 + return r;
8553 + }
8554 +
8555 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8556 +#endif
8557 +
8558 + return r;
8559 +}
8560 +
8561 +int verrevcmp(const char *val, const char *ref)
8562 +{
8563 + int vc, rc;
8564 + long vl, rl;
8565 + const char *vp, *rp;
8566 + const char *vsep, *rsep;
8567 +
8568 + if (!val) val= "";
8569 + if (!ref) ref= "";
8570 + for (;;) {
8571 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8572 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8573 + for (;;) {
8574 + vc= (val == vp) ? 0 : *val++;
8575 + rc= (ref == rp) ? 0 : *ref++;
8576 + if (!rc && !vc) break;
8577 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8578 + if (rc && !isalpha(rc)) rc += 256;
8579 + if (vc != rc) return vc - rc;
8580 + }
8581 + val= vp;
8582 + ref= rp;
8583 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8584 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8585 + if (vl != rl) return vl - rl;
8586 +
8587 + vc = *val;
8588 + rc = *ref;
8589 + vsep = strchr(".-", vc);
8590 + rsep = strchr(".-", rc);
8591 + if (vsep && !rsep) return -1;
8592 + if (!vsep && rsep) return +1;
8593 +
8594 + if (!*val && !*ref) return 0;
8595 + if (!*val) return -1;
8596 + if (!*ref) return +1;
8597 + }
8598 +}
8599 +
8600 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8601 +{
8602 + int r;
8603 +
8604 + r = pkg_compare_versions(it, ref);
8605 +
8606 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8607 + return r <= 0;
8608 + }
8609 +
8610 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8611 + return r >= 0;
8612 + }
8613 +
8614 + if (strcmp(op, "<<") == 0) {
8615 + return r < 0;
8616 + }
8617 +
8618 + if (strcmp(op, ">>") == 0) {
8619 + return r > 0;
8620 + }
8621 +
8622 + if (strcmp(op, "=") == 0) {
8623 + return r == 0;
8624 + }
8625 +
8626 + fprintf(stderr, "unknown operator: %s", op);
8627 + return 0;
8628 +}
8629 +
8630 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8631 +{
8632 + const pkg_t *a = *(const pkg_t **)p1;
8633 + const pkg_t *b = *(const pkg_t **)p2;
8634 + int namecmp;
8635 + int vercmp;
8636 + if (!a->name || !b->name) {
8637 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8638 + a, a->name, b, b->name);
8639 + return 0;
8640 + }
8641 +
8642 + namecmp = strcmp(a->name, b->name);
8643 + if (namecmp)
8644 + return namecmp;
8645 + vercmp = pkg_compare_versions(a, b);
8646 + if (vercmp)
8647 + return vercmp;
8648 + if (!a->arch_priority || !b->arch_priority) {
8649 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8650 + a, a->arch_priority, b, b->arch_priority);
8651 + return 0;
8652 + }
8653 + if (a->arch_priority > b->arch_priority)
8654 + return 1;
8655 + if (a->arch_priority < b->arch_priority)
8656 + return -1;
8657 + return 0;
8658 +}
8659 +
8660 +int abstract_pkg_name_compare(void *p1, void *p2)
8661 +{
8662 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8663 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8664 + if (!a->name || !b->name) {
8665 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8666 + a, a->name, b, b->name);
8667 + return 0;
8668 + }
8669 + return strcmp(a->name, b->name);
8670 +}
8671 +
8672 +
8673 +char *pkg_version_str_alloc(pkg_t *pkg)
8674 +{
8675 + char *complete_version;
8676 + char *epoch_str;
8677 +#ifdef USE_DEBVERSION
8678 + char *revision_str;
8679 + char *familiar_revision_str;
8680 +#endif
8681 +
8682 + if (pkg->epoch) {
8683 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8684 + } else {
8685 + epoch_str = strdup("");
8686 + }
8687 +
8688 +#ifdef USE_DEBVERSION
8689 + if (pkg->revision && strlen(pkg->revision)) {
8690 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8691 + } else {
8692 + revision_str = strdup("");
8693 + }
8694 +
8695 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8696 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8697 + } else {
8698 + familiar_revision_str = strdup("");
8699 + }
8700 +#endif
8701 +
8702 +#ifdef USE_DEBVERSION
8703 + sprintf_alloc(&complete_version, "%s%s%s%s",
8704 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8705 +#else
8706 + sprintf_alloc(&complete_version, "%s%s",
8707 + epoch_str, pkg->version);
8708 +#endif
8709 +
8710 + free(epoch_str);
8711 +#ifdef USE_DEBVERSION
8712 + free(revision_str);
8713 + free(familiar_revision_str);
8714 +#endif
8715 +
8716 + return complete_version;
8717 +}
8718 +
8719 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8720 +{
8721 + int err;
8722 + char *list_file_name = NULL;
8723 + FILE *list_file = NULL;
8724 + char *line;
8725 + char *installed_file_name;
8726 + int rootdirlen;
8727 +
8728 + pkg->installed_files_ref_cnt++;
8729 +
8730 + if (pkg->installed_files) {
8731 + return pkg->installed_files;
8732 + }
8733 +
8734 + pkg->installed_files = str_list_alloc();
8735 + if (pkg->installed_files == NULL) {
8736 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8737 + return NULL;
8738 + }
8739 +
8740 + /* For uninstalled packages, get the file list firectly from the package.
8741 + For installed packages, look at the package.list file in the database.
8742 + */
8743 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8744 + if (pkg->local_filename == NULL) {
8745 + return pkg->installed_files;
8746 + }
8747 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8748 + file. In other words, change deb_extract so that it can
8749 + simply return the file list as a char *[] rather than
8750 + insisting on writing in to a FILE * as it does now. */
8751 + list_file = tmpfile();
8752 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8753 + if (err) {
8754 + fclose(list_file);
8755 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8756 + __FUNCTION__, pkg->local_filename, strerror(err));
8757 + return pkg->installed_files;
8758 + }
8759 + rewind(list_file);
8760 + } else {
8761 + sprintf_alloc(&list_file_name, "%s/%s.list",
8762 + pkg->dest->info_dir, pkg->name);
8763 + if (! file_exists(list_file_name)) {
8764 + free(list_file_name);
8765 + return pkg->installed_files;
8766 + }
8767 +
8768 + list_file = fopen(list_file_name, "r");
8769 + if (list_file == NULL) {
8770 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8771 + list_file_name, strerror(errno));
8772 + free(list_file_name);
8773 + return pkg->installed_files;
8774 + }
8775 + free(list_file_name);
8776 + }
8777 +
8778 + rootdirlen = strlen( pkg->dest->root_dir );
8779 + while (1) {
8780 + char *file_name;
8781 +
8782 + line = file_read_line_alloc(list_file);
8783 + if (line == NULL) {
8784 + break;
8785 + }
8786 + str_chomp(line);
8787 + file_name = line;
8788 +
8789 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8790 + if( strncmp( pkg->dest->root_dir,
8791 + file_name,
8792 + rootdirlen ) ) {
8793 + if (*file_name == '.') {
8794 + file_name++;
8795 + }
8796 + if (*file_name == '/') {
8797 + file_name++;
8798 + }
8799 +
8800 + /* Freed in pkg_free_installed_files */
8801 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8802 + } else {
8803 + // already contains root_dir as header -> ABSOLUTE
8804 + sprintf_alloc(&installed_file_name, "%s", file_name);
8805 + }
8806 + str_list_append(pkg->installed_files, installed_file_name);
8807 + free(line);
8808 + }
8809 +
8810 + fclose(list_file);
8811 +
8812 + return pkg->installed_files;
8813 +}
8814 +
8815 +/* XXX: CLEANUP: This function and it's counterpart,
8816 + (pkg_get_installed_files), do not match our init/deinit naming
8817 + convention. Nor the alloc/free convention. But, then again, neither
8818 + of these conventions currrently fit the way these two functions
8819 + work. */
8820 +int pkg_free_installed_files(pkg_t *pkg)
8821 +{
8822 + str_list_elt_t *iter;
8823 +
8824 + pkg->installed_files_ref_cnt--;
8825 + if (pkg->installed_files_ref_cnt > 0) {
8826 + return 0;
8827 + }
8828 +
8829 + if (pkg->installed_files) {
8830 +
8831 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8832 + /* malloced in pkg_get_installed_files */
8833 + free (iter->data);
8834 + iter->data = NULL;
8835 + }
8836 +
8837 + str_list_deinit(pkg->installed_files);
8838 + }
8839 +
8840 + pkg->installed_files = NULL;
8841 +
8842 + return 0;
8843 +}
8844 +
8845 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8846 +{
8847 + int err;
8848 + char *list_file_name;
8849 +
8850 + //I don't think pkg_free_installed_files should be called here. Jamey
8851 + //pkg_free_installed_files(pkg);
8852 +
8853 + sprintf_alloc(&list_file_name, "%s/%s.list",
8854 + pkg->dest->info_dir, pkg->name);
8855 + if (!conf->noaction) {
8856 + err = unlink(list_file_name);
8857 + free(list_file_name);
8858 +
8859 + if (err) {
8860 + return errno;
8861 + }
8862 + }
8863 + return 0;
8864 +}
8865 +
8866 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8867 +{
8868 + conffile_list_elt_t *iter;
8869 + conffile_t *conffile;
8870 +
8871 + if (pkg == NULL) {
8872 + return NULL;
8873 + }
8874 +
8875 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8876 + conffile = iter->data;
8877 +
8878 + if (strcmp(conffile->name, file_name) == 0) {
8879 + return conffile;
8880 + }
8881 + }
8882 +
8883 + return NULL;
8884 +}
8885 +
8886 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8887 + const char *script, const char *args)
8888 +{
8889 + int err;
8890 + char *path;
8891 + char *cmd;
8892 +
8893 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8894 + maintainer script within a chroot environment. */
8895 +
8896 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8897 + have scripts in pkg->tmp_unpack_dir. */
8898 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8899 + if (pkg->dest == NULL) {
8900 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8901 + __FUNCTION__, pkg->name);
8902 + return EINVAL;
8903 + }
8904 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8905 + } else {
8906 + if (pkg->tmp_unpack_dir == NULL) {
8907 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8908 + __FUNCTION__, pkg->name);
8909 + return EINVAL;
8910 + }
8911 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8912 + }
8913 +
8914 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8915 + if (conf->noaction) return 0;
8916 +
8917 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8918 + scripts when running with offline_root mode and/or a dest other
8919 + than '/'. I've been playing around with some clever chroot
8920 + tricks and I might come up with something workable. */
8921 + if (conf->offline_root) {
8922 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8923 + }
8924 +
8925 + setenv("PKG_ROOT",
8926 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8927 +
8928 + if (! file_exists(path)) {
8929 + free(path);
8930 + return 0;
8931 + }
8932 +
8933 + if (conf->offline_root) {
8934 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8935 + free(path);
8936 + return 0;
8937 + }
8938 +
8939 + sprintf_alloc(&cmd, "%s %s", path, args);
8940 + free(path);
8941 +
8942 + err = xsystem(cmd);
8943 + free(cmd);
8944 +
8945 + if (err) {
8946 + fprintf(stderr, "%s script returned status %d\n", script, err);
8947 + return err;
8948 + }
8949 +
8950 + return 0;
8951 +}
8952 +
8953 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8954 +{
8955 + int i;
8956 +
8957 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8958 + if (pkg_state_want_map[i].value == sw) {
8959 + return strdup(pkg_state_want_map[i].str);
8960 + }
8961 + }
8962 +
8963 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8964 + __FUNCTION__, sw);
8965 + return strdup("<STATE_WANT_UNKNOWN>");
8966 +}
8967 +
8968 +pkg_state_want_t pkg_state_want_from_str(char *str)
8969 +{
8970 + int i;
8971 +
8972 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8973 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8974 + return pkg_state_want_map[i].value;
8975 + }
8976 + }
8977 +
8978 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8979 + __FUNCTION__, str);
8980 + return SW_UNKNOWN;
8981 +}
8982 +
8983 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8984 +{
8985 + int i;
8986 + int len = 3; /* ok\000 is minimum */
8987 + char *str = NULL;
8988 +
8989 + /* clear the temporary flags before converting to string */
8990 + sf &= SF_NONVOLATILE_FLAGS;
8991 +
8992 + if (sf == 0) {
8993 + return strdup("ok");
8994 + } else {
8995 +
8996 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8997 + if (sf & pkg_state_flag_map[i].value) {
8998 + len += strlen(pkg_state_flag_map[i].str) + 1;
8999 + }
9000 + }
9001 + str = malloc(len);
9002 + if ( str == NULL ) {
9003 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9004 + return NULL;
9005 + }
9006 + str[0] = 0;
9007 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9008 + if (sf & pkg_state_flag_map[i].value) {
9009 + strcat(str, pkg_state_flag_map[i].str);
9010 + strcat(str, ",");
9011 + }
9012 + }
9013 + len = strlen(str);
9014 + str[len-1] = 0; /* squash last comma */
9015 + return str;
9016 + }
9017 +}
9018 +
9019 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9020 +{
9021 + int i;
9022 + int sf = SF_OK;
9023 +
9024 + if (strcmp(str, "ok") == 0) {
9025 + return SF_OK;
9026 + }
9027 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9028 + const char *sfname = pkg_state_flag_map[i].str;
9029 + int sfname_len = strlen(sfname);
9030 + if (strncmp(str, sfname, sfname_len) == 0) {
9031 + sf |= pkg_state_flag_map[i].value;
9032 + str += sfname_len;
9033 + if (str[0] == ',') {
9034 + str++;
9035 + } else {
9036 + break;
9037 + }
9038 + }
9039 + }
9040 +
9041 + return sf;
9042 +}
9043 +
9044 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9045 +{
9046 + int i;
9047 +
9048 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9049 + if (pkg_state_status_map[i].value == ss) {
9050 + return strdup(pkg_state_status_map[i].str);
9051 + }
9052 + }
9053 +
9054 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9055 + __FUNCTION__, ss);
9056 + return strdup("<STATE_STATUS_UNKNOWN>");
9057 +}
9058 +
9059 +pkg_state_status_t pkg_state_status_from_str(char *str)
9060 +{
9061 + int i;
9062 +
9063 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9064 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9065 + return pkg_state_status_map[i].value;
9066 + }
9067 + }
9068 +
9069 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9070 + __FUNCTION__, str);
9071 + return SS_NOT_INSTALLED;
9072 +}
9073 +
9074 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9075 +{
9076 + nv_pair_list_elt_t *l;
9077 +
9078 + if (!pkg->architecture)
9079 + return 1;
9080 +
9081 + l = conf->arch_list.head;
9082 +
9083 + while (l) {
9084 + nv_pair_t *nv = l->data;
9085 + if (strcmp(nv->name, pkg->architecture) == 0) {
9086 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9087 + return 1;
9088 + }
9089 + l = l->next;
9090 + }
9091 +
9092 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9093 + return 0;
9094 +}
9095 +
9096 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9097 +{
9098 + nv_pair_list_elt_t *l;
9099 +
9100 + l = conf->arch_list.head;
9101 +
9102 + while (l) {
9103 + nv_pair_t *nv = l->data;
9104 + if (strcmp(nv->name, archname) == 0) {
9105 + int priority = strtol(nv->value, NULL, 0);
9106 + return priority;
9107 + }
9108 + l = l->next;
9109 + }
9110 + return 0;
9111 +}
9112 +
9113 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9114 +{
9115 + int i;
9116 + hash_table_t *pkg_hash = &conf->pkg_hash;
9117 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9118 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9119 +
9120 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9121 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9122 + /* update arch_priority for each package */
9123 + for (i = 0; i < available_pkgs->len; i++) {
9124 + pkg_t *pkg = available_pkgs->pkgs[i];
9125 + int arch_priority = 1;
9126 + if (!pkg)
9127 + continue;
9128 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9129 + if (pkg->architecture)
9130 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9131 + else
9132 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9133 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9134 + pkg->arch_priority = arch_priority;
9135 + }
9136 +
9137 + for (i = 0; i < available_pkgs->len; i++) {
9138 + pkg_t *pkg = available_pkgs->pkgs[i];
9139 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9140 + /* clear flags and want for any uninstallable package */
9141 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9142 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9143 + pkg->state_want = SW_UNKNOWN;
9144 + pkg->state_flag = 0;
9145 + }
9146 + }
9147 + pkg_vec_free(available_pkgs);
9148 +
9149 + /* update the file owner data structure */
9150 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9151 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9152 + for (i = 0; i < installed_pkgs->len; i++) {
9153 + pkg_t *pkg = installed_pkgs->pkgs[i];
9154 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9155 + str_list_elt_t *iter;
9156 + if (installed_files == NULL) {
9157 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9158 + break;
9159 + }
9160 + for (iter = installed_files->head; iter; iter = iter->next) {
9161 + char *installed_file = iter->data;
9162 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9163 + file_hash_set_file_owner(conf, installed_file, pkg);
9164 + }
9165 + }
9166 + pkg_vec_free(installed_pkgs);
9167 +
9168 + return 0;
9169 +}
9170 +
9171 +struct pkg_write_filelist_data {
9172 + ipkg_conf_t *conf;
9173 + pkg_t *pkg;
9174 + FILE *stream;
9175 +};
9176 +
9177 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9178 +{
9179 + struct pkg_write_filelist_data *data = data_;
9180 + pkg_t *entry = entry_;
9181 + if (entry == data->pkg) {
9182 + fprintf(data->stream, "%s\n", key);
9183 + }
9184 +}
9185 +
9186 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9187 +{
9188 + struct pkg_write_filelist_data data;
9189 + char *list_file_name = NULL;
9190 + int err = 0;
9191 +
9192 + if (!pkg) {
9193 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9194 + return -EINVAL;
9195 + }
9196 + ipkg_message(conf, IPKG_INFO,
9197 + " creating %s.list file\n", pkg->name);
9198 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9199 + if (!list_file_name) {
9200 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9201 + return -ENOMEM;
9202 + }
9203 + ipkg_message(conf, IPKG_INFO,
9204 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9205 + data.stream = fopen(list_file_name, "w");
9206 + if (!data.stream) {
9207 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9208 + list_file_name, strerror(errno));
9209 + return errno;
9210 + }
9211 + data.pkg = pkg;
9212 + data.conf = conf;
9213 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9214 + fclose(data.stream);
9215 + free(list_file_name);
9216 +
9217 + return err;
9218 +}
9219 +
9220 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9221 +{
9222 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9223 + hash_table_t *pkg_hash = &conf->pkg_hash;
9224 + int i;
9225 + int err;
9226 + if (conf->noaction)
9227 + return 0;
9228 +
9229 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9230 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9231 + for (i = 0; i < installed_pkgs->len; i++) {
9232 + pkg_t *pkg = installed_pkgs->pkgs[i];
9233 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9234 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9235 + err = pkg_write_filelist(conf, pkg);
9236 + if (err)
9237 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9238 + }
9239 + }
9240 + return 0;
9241 +}
9242 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.h
9243 --- busybox-1.00-orig/archival/libipkg/pkg.h 1970-01-01 00:00:00.000000000 +0000
9244 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.h 2005-07-17 16:10:24.000000000 +0000
9245 @@ -0,0 +1,230 @@
9246 +/* pkg.h - the itsy package management system
9247 +
9248 + Carl D. Worth
9249 +
9250 + Copyright (C) 2001 University of Southern California
9251 +
9252 + This program is free software; you can redistribute it and/or
9253 + modify it under the terms of the GNU General Public License as
9254 + published by the Free Software Foundation; either version 2, or (at
9255 + your option) any later version.
9256 +
9257 + This program is distributed in the hope that it will be useful, but
9258 + WITHOUT ANY WARRANTY; without even the implied warranty of
9259 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9260 + General Public License for more details.
9261 +*/
9262 +
9263 +#ifndef PKG_H
9264 +#define PKG_H
9265 +
9266 +#include <sys/types.h>
9267 +#include <sys/stat.h>
9268 +#include <unistd.h>
9269 +
9270 +#include "pkg_vec.h"
9271 +#include "str_list.h"
9272 +#include "pkg_src.h"
9273 +#include "pkg_dest.h"
9274 +#include "ipkg_conf.h"
9275 +#include "conffile_list.h"
9276 +
9277 +struct ipkg_conf;
9278 +
9279 +
9280 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9281 +
9282 +/* I think "Size" is currently the shortest field name */
9283 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9284 +
9285 +enum pkg_state_want
9286 +{
9287 + SW_UNKNOWN = 1,
9288 + SW_INSTALL,
9289 + SW_DEINSTALL,
9290 + SW_PURGE,
9291 + SW_LAST_STATE_WANT
9292 +};
9293 +typedef enum pkg_state_want pkg_state_want_t;
9294 +
9295 +enum pkg_state_flag
9296 +{
9297 + SF_OK = 0,
9298 + SF_REINSTREQ = 1,
9299 + SF_HOLD = 2, /* do not upgrade version */
9300 + SF_REPLACE = 4, /* replace this package */
9301 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9302 + SF_PREFER = 16, /* prefer this version */
9303 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9304 + SF_MARKED = 64, /* temporary mark */
9305 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9306 + SF_USER = 256,
9307 + SF_LAST_STATE_FLAG
9308 +};
9309 +typedef enum pkg_state_flag pkg_state_flag_t;
9310 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9311 +
9312 +enum pkg_state_status
9313 +{
9314 + SS_NOT_INSTALLED = 1,
9315 + SS_UNPACKED,
9316 + SS_HALF_CONFIGURED,
9317 + SS_INSTALLED,
9318 + SS_HALF_INSTALLED,
9319 + SS_CONFIG_FILES,
9320 + SS_POST_INST_FAILED,
9321 + SS_REMOVAL_FAILED,
9322 + SS_LAST_STATE_STATUS
9323 +};
9324 +typedef enum pkg_state_status pkg_state_status_t;
9325 +
9326 +struct abstract_pkg{
9327 + char * name;
9328 + int dependencies_checked;
9329 + pkg_vec_t * pkgs;
9330 + pkg_state_status_t state_status;
9331 + pkg_state_flag_t state_flag;
9332 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9333 + abstract_pkg_vec_t * provided_by;
9334 + abstract_pkg_vec_t * replaced_by;
9335 +};
9336 +
9337 +#include "pkg_depends.h"
9338 +
9339 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9340 +
9341 + The 3 version fields should go into a single version struct. (This
9342 + is especially important since, currently, pkg->version can easily
9343 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9344 + distinct. This has been the source of multiple bugs.
9345 +
9346 + The 3 state fields could possibly also go into their own struct.
9347 +
9348 + All fields which deal with lists of packages, (Depends,
9349 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9350 + be handled by a single struct in pkg_t
9351 +
9352 + All string fields for which there is a small set of possible
9353 + values, (section, maintainer, architecture, maybe version?), that
9354 + are reused among different packages -- for all such packages we
9355 + should move from "char *"s to some atom datatype to share data
9356 + storage and use less memory. We might even do reference counting,
9357 + but probably not since most often we only create new pkg_t structs,
9358 + we don't often free them. */
9359 +struct pkg
9360 +{
9361 + char *name;
9362 + unsigned long epoch;
9363 + char *version;
9364 + char *revision;
9365 + char *familiar_revision;
9366 + pkg_src_t *src;
9367 + pkg_dest_t *dest;
9368 + char *architecture;
9369 + char *section;
9370 + char *maintainer;
9371 + char *description;
9372 + pkg_state_want_t state_want;
9373 + pkg_state_flag_t state_flag;
9374 + pkg_state_status_t state_status;
9375 + char **depends_str;
9376 + int depends_count;
9377 + char **pre_depends_str;
9378 + int pre_depends_count;
9379 + char **recommends_str;
9380 + int recommends_count;
9381 + char **suggests_str;
9382 + int suggests_count;
9383 + compound_depend_t * depends;
9384 +
9385 + /* Abhaya: new conflicts */
9386 + char **conflicts_str;
9387 + compound_depend_t * conflicts;
9388 + int conflicts_count;
9389 +
9390 + char **replaces_str;
9391 + int replaces_count;
9392 + abstract_pkg_t ** replaces;
9393 +
9394 + char **provides_str;
9395 + int provides_count;
9396 + abstract_pkg_t ** provides;
9397 +
9398 + abstract_pkg_t *parent;
9399 +
9400 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9401 +
9402 + char *filename;
9403 + char *local_filename;
9404 + char *url;
9405 + char *tmp_unpack_dir;
9406 + char *md5sum;
9407 + char *size;
9408 + char *installed_size;
9409 + char *priority;
9410 + char *source;
9411 + conffile_list_t conffiles;
9412 + time_t installed_time;
9413 + /* As pointer for lazy evaluation */
9414 + str_list_t *installed_files;
9415 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9416 + mechanism to avoid the problem here, (which is that the
9417 + installed_files list was being freed from an inner loop while
9418 + still being used within an outer loop. */
9419 + int installed_files_ref_cnt;
9420 + int essential;
9421 + int arch_priority;
9422 +};
9423 +
9424 +pkg_t *pkg_new(void);
9425 +int pkg_init(pkg_t *pkg);
9426 +void pkg_deinit(pkg_t *pkg);
9427 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9428 +abstract_pkg_t *abstract_pkg_new(void);
9429 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9430 +
9431 +/*
9432 + * merges fields from newpkg into oldpkg.
9433 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9434 + */
9435 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9436 +
9437 +char *pkg_version_str_alloc(pkg_t *pkg);
9438 +
9439 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9440 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9441 +int abstract_pkg_name_compare(void *a, void *b);
9442 +
9443 +char * pkg_formatted_info(pkg_t *pkg );
9444 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9445 +
9446 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9447 +
9448 +void pkg_print_info(pkg_t *pkg, FILE *file);
9449 +void pkg_print_status(pkg_t * pkg, FILE * file);
9450 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9451 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9452 +int pkg_free_installed_files(pkg_t *pkg);
9453 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9454 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9455 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9456 + const char *script, const char *args);
9457 +
9458 +/* enum mappings */
9459 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9460 +pkg_state_want_t pkg_state_want_from_str(char *str);
9461 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9462 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9463 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9464 +pkg_state_status_t pkg_state_status_from_str(char *str);
9465 +
9466 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9467 +
9468 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9469 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9470 +int pkg_free_installed_files(pkg_t *pkg);
9471 +
9472 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9473 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9474 +
9475 +#endif
9476 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.c
9477 --- busybox-1.00-orig/archival/libipkg/pkg_depends.c 1970-01-01 00:00:00.000000000 +0000
9478 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.c 2005-07-20 10:19:23.000000000 +0000
9479 @@ -0,0 +1,1017 @@
9480 +/* pkg_depends.c - the itsy package management system
9481 +
9482 + Steven M. Ayer
9483 +
9484 + Copyright (C) 2002 Compaq Computer Corporation
9485 +
9486 + This program is free software; you can redistribute it and/or
9487 + modify it under the terms of the GNU General Public License as
9488 + published by the Free Software Foundation; either version 2, or (at
9489 + your option) any later version.
9490 +
9491 + This program is distributed in the hope that it will be useful, but
9492 + WITHOUT ANY WARRANTY; without even the implied warranty of
9493 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9494 + General Public License for more details.
9495 +*/
9496 +
9497 +#include "ipkg.h"
9498 +#include <errno.h>
9499 +#include <ctype.h>
9500 +
9501 +#include "pkg.h"
9502 +#include "ipkg_utils.h"
9503 +#include "pkg_hash.h"
9504 +#include "ipkg_message.h"
9505 +#include "pkg_parse.h"
9506 +#include "hash_table.h"
9507 +
9508 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9509 +static depend_t * depend_init(void);
9510 +static void depend_deinit(depend_t *d);
9511 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9512 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9513 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9514 +
9515 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9516 +{
9517 + depend_t *depend = (depend_t *)cdata;
9518 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9519 + return 1;
9520 + else
9521 + return 0;
9522 +}
9523 +
9524 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9525 +{
9526 + depend_t *depend = (depend_t *)cdata;
9527 +#if 0
9528 + pkg_t * temp = pkg_new();
9529 + int comparison;
9530 + parseVersion(temp, depend->version);
9531 + comparison = pkg_compare_versions(pkg, temp);
9532 + free(temp);
9533 +
9534 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9535 + __FUNCTION__, pkg->name, pkg->version,
9536 + depend, depend->constraint, depend->version,
9537 + comparison, version_constraints_satisfied(depend, pkg));
9538 +#endif
9539 + if (version_constraints_satisfied(depend, pkg))
9540 + return 1;
9541 + else
9542 + return 0;
9543 +}
9544 +
9545 +/* returns ndependences or negative error value */
9546 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9547 + pkg_vec_t *unsatisfied, char *** unresolved)
9548 +{
9549 + pkg_t * satisfier_entry_pkg;
9550 + register int i, j, k;
9551 + int count, found;
9552 + char ** the_lost;
9553 + abstract_pkg_t * ab_pkg;
9554 +
9555 + /*
9556 + * this is a setup to check for redundant/cyclic dependency checks,
9557 + * which are marked at the abstract_pkg level
9558 + */
9559 + if (!(ab_pkg = pkg->parent)) {
9560 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9561 + *unresolved = NULL;
9562 + return 0;
9563 + }
9564 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9565 + *unresolved = NULL;
9566 + return 0;
9567 + } else {
9568 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9569 + }
9570 + /**/
9571 +
9572 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9573 + if (!count){
9574 + *unresolved = NULL;
9575 + return 0;
9576 + }
9577 +
9578 + the_lost = NULL;
9579 +
9580 + /* foreach dependency */
9581 + for (i = 0; i < count; i++) {
9582 + compound_depend_t * compound_depend = &pkg->depends[i];
9583 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9584 + found = 0;
9585 + satisfier_entry_pkg = NULL;
9586 +
9587 + if (compound_depend->type == GREEDY_DEPEND) {
9588 + /* foreach possible satisfier */
9589 + for (j = 0; j < compound_depend->possibility_count; j++) {
9590 + /* foreach provided_by, which includes the abstract_pkg itself */
9591 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9592 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9593 + int nposs = ab_provider_vec->len;
9594 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9595 + int l;
9596 + for (l = 0; l < nposs; l++) {
9597 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9598 + /* if no depends on this one, try the first package that Provides this one */
9599 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9600 + continue;
9601 + }
9602 +
9603 + /* cruise this possiblity's pkg_vec looking for an installed version */
9604 + for (k = 0; k < test_vec->len; k++) {
9605 + pkg_t *pkg_scout = test_vec->pkgs[k];
9606 + /* not installed, and not already known about? */
9607 + if ((pkg_scout->state_want != SW_INSTALL)
9608 + && !pkg_scout->parent->dependencies_checked
9609 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9610 + char ** newstuff = NULL;
9611 + int rc;
9612 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9613 + /* check for not-already-installed dependencies */
9614 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9615 + pkg_scout,
9616 + tmp_vec,
9617 + &newstuff);
9618 + if (newstuff == NULL) {
9619 + int i;
9620 + int ok = 1;
9621 + for (i = 0; i < rc; i++) {
9622 + pkg_t *p = tmp_vec->pkgs[i];
9623 + if (p->state_want == SW_INSTALL)
9624 + continue;
9625 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9626 + ok = 0;
9627 + break;
9628 + }
9629 + pkg_vec_free (tmp_vec);
9630 + if (ok) {
9631 + /* mark this one for installation */
9632 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9633 + pkg_vec_insert(unsatisfied, pkg_scout);
9634 + }
9635 + } else {
9636 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9637 + free (newstuff);
9638 + }
9639 + }
9640 + }
9641 + }
9642 + }
9643 +
9644 + continue;
9645 + }
9646 +
9647 + /* foreach possible satisfier, look for installed package */
9648 + for (j = 0; j < compound_depend->possibility_count; j++) {
9649 + /* foreach provided_by, which includes the abstract_pkg itself */
9650 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9651 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9652 + pkg_t *satisfying_pkg =
9653 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9654 + pkg_installed_and_constraint_satisfied,
9655 + dependence_to_satisfy, 1);
9656 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9657 + if (satisfying_pkg != NULL) {
9658 + found = 1;
9659 + break;
9660 + }
9661 +
9662 + }
9663 + /* if nothing installed matches, then look for uninstalled satisfier */
9664 + if (!found) {
9665 + /* foreach possible satisfier, look for installed package */
9666 + for (j = 0; j < compound_depend->possibility_count; j++) {
9667 + /* foreach provided_by, which includes the abstract_pkg itself */
9668 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9669 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9670 + pkg_t *satisfying_pkg =
9671 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9672 + pkg_constraint_satisfied,
9673 + dependence_to_satisfy, 1);
9674 +
9675 + /* user request overrides package recommendation */
9676 + if (satisfying_pkg != NULL
9677 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9678 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9679 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9680 + pkg->name, satisfying_pkg->name);
9681 + continue;
9682 + }
9683 +
9684 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9685 + if (satisfying_pkg != NULL) {
9686 + satisfier_entry_pkg = satisfying_pkg;
9687 + break;
9688 + }
9689 + }
9690 + }
9691 +
9692 + /* we didn't find one, add something to the unsatisfied vector */
9693 + if (!found) {
9694 + if (!satisfier_entry_pkg) {
9695 + /* failure to meet recommendations is not an error */
9696 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9697 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9698 + else
9699 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9700 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9701 + }
9702 + else {
9703 + if (compound_depend->type == SUGGEST) {
9704 + /* just mention it politely */
9705 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9706 + pkg->name, satisfier_entry_pkg->name);
9707 + } else {
9708 + char ** newstuff = NULL;
9709 +
9710 + if (satisfier_entry_pkg != pkg &&
9711 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9712 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9713 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9714 + satisfier_entry_pkg,
9715 + unsatisfied,
9716 + &newstuff);
9717 + the_lost = merge_unresolved(the_lost, newstuff);
9718 + }
9719 + }
9720 + }
9721 + }
9722 + }
9723 + *unresolved = the_lost;
9724 +
9725 + return unsatisfied->len;
9726 +}
9727 +
9728 +/*checking for conflicts !in replaces
9729 + If a packages conflicts with another but is also replacing it, I should not consider it a
9730 + really conflicts
9731 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9732 +*/
9733 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9734 +{
9735 + int i ;
9736 + int replaces_count = pkg->replaces_count;
9737 + abstract_pkg_t **replaces;
9738 +
9739 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9740 + return 0;
9741 +
9742 + replaces = pkg->replaces;
9743 +
9744 + for (i = 0; i < replaces_count; i++) {
9745 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9746 + return 1;
9747 + }
9748 + return 0;
9749 +
9750 +}
9751 +
9752 +
9753 +/* Abhaya: added support for conflicts */
9754 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9755 +{
9756 + pkg_vec_t * installed_conflicts, * test_vec;
9757 + compound_depend_t * conflicts;
9758 + depend_t ** possible_satisfiers;
9759 + depend_t * possible_satisfier;
9760 + register int i, j, k;
9761 + int count;
9762 + abstract_pkg_t * ab_pkg;
9763 + pkg_t **pkg_scouts;
9764 + pkg_t *pkg_scout;
9765 +
9766 + /*
9767 + * this is a setup to check for redundant/cyclic dependency checks,
9768 + * which are marked at the abstract_pkg level
9769 + */
9770 + if(!(ab_pkg = pkg->parent)){
9771 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9772 + return (pkg_vec_t *)NULL;
9773 + }
9774 +
9775 + conflicts = pkg->conflicts;
9776 + if(!conflicts){
9777 + return (pkg_vec_t *)NULL;
9778 + }
9779 + installed_conflicts = pkg_vec_alloc();
9780 +
9781 + count = pkg->conflicts_count;
9782 +
9783 +
9784 +
9785 + /* foreach conflict */
9786 + for(i = 0; i < pkg->conflicts_count; i++){
9787 +
9788 + possible_satisfiers = conflicts->possibilities;
9789 +
9790 + /* foreach possible satisfier */
9791 + for(j = 0; j < conflicts->possibility_count; j++){
9792 + possible_satisfier = possible_satisfiers[j];
9793 + if (!possible_satisfier)
9794 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9795 + if (!possible_satisfier->pkg)
9796 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9797 + test_vec = possible_satisfier->pkg->pkgs;
9798 + if (test_vec) {
9799 + /* pkg_vec found, it is an actual package conflict
9800 + * cruise this possiblity's pkg_vec looking for an installed version */
9801 + pkg_scouts = test_vec->pkgs;
9802 + for(k = 0; k < test_vec->len; k++){
9803 + pkg_scout = pkg_scouts[k];
9804 + if (!pkg_scout) {
9805 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9806 + continue;
9807 + }
9808 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9809 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9810 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9811 + pkg_vec_insert(installed_conflicts, pkg_scout);
9812 + }
9813 + }
9814 + }
9815 + }
9816 + }
9817 + conflicts++;
9818 + }
9819 +
9820 + if (installed_conflicts->len)
9821 + return installed_conflicts;
9822 + pkg_vec_free(installed_conflicts);
9823 + return (pkg_vec_t *)NULL;
9824 +}
9825 +
9826 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9827 +{
9828 + pkg_t * temp;
9829 + int comparison;
9830 +
9831 + if(depends->constraint == NONE)
9832 + return 1;
9833 +
9834 + temp = pkg_new();
9835 +
9836 + parseVersion(temp, depends->version);
9837 +
9838 + comparison = pkg_compare_versions(pkg, temp);
9839 +
9840 + free(temp);
9841 +
9842 + if((depends->constraint == EARLIER) &&
9843 + (comparison < 0))
9844 + return 1;
9845 + else if((depends->constraint == LATER) &&
9846 + (comparison > 0))
9847 + return 1;
9848 + else if(comparison == 0)
9849 + return 1;
9850 + else if((depends->constraint == LATER_EQUAL) &&
9851 + (comparison >= 0))
9852 + return 1;
9853 + else if((depends->constraint == EARLIER_EQUAL) &&
9854 + (comparison <= 0))
9855 + return 1;
9856 +
9857 + return 0;
9858 +}
9859 +
9860 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9861 +{
9862 + abstract_pkg_t *apkg = depend->pkg;
9863 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9864 + int n_providers = provider_apkgs->len;
9865 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9866 + pkg_vec_t *pkg_vec;
9867 + int n_pkgs ;
9868 + int i;
9869 + int j;
9870 +
9871 + for (i = 0; i < n_providers; i++) {
9872 + abstract_pkg_t *papkg = apkgs[i];
9873 + pkg_vec = papkg->pkgs;
9874 + if (pkg_vec) {
9875 + n_pkgs = pkg_vec->len;
9876 + for (j = 0; j < n_pkgs; j++) {
9877 + pkg_t *pkg = pkg_vec->pkgs[j];
9878 + if (version_constraints_satisfied(depend, pkg)) {
9879 + return 1;
9880 + }
9881 + }
9882 + }
9883 + }
9884 + return 0;
9885 +}
9886 +
9887 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9888 +{
9889 + abstract_pkg_t *apkg = depend->pkg;
9890 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9891 + int n_providers = provider_apkgs->len;
9892 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9893 + int i;
9894 + int n_pkgs;
9895 + int j;
9896 +
9897 + for (i = 0; i < n_providers; i++) {
9898 + abstract_pkg_t *papkg = apkgs[i];
9899 + pkg_vec_t *pkg_vec = papkg->pkgs;
9900 + if (pkg_vec) {
9901 + n_pkgs = pkg_vec->len;
9902 + for (j = 0; j < n_pkgs; j++) {
9903 + pkg_t *pkg = pkg_vec->pkgs[j];
9904 + if (version_constraints_satisfied(depend, pkg)) {
9905 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9906 + return 1;
9907 + }
9908 + }
9909 + }
9910 + }
9911 + return 0;
9912 +}
9913 +
9914 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9915 +{
9916 + register int i;
9917 + pkg_t ** pkgs = vec->pkgs;
9918 +
9919 + for(i = 0; i < vec->len; i++)
9920 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9921 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9922 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9923 + return 1;
9924 + return 0;
9925 +}
9926 +
9927 +
9928 +#ifdef DeadCode
9929 +/**
9930 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9931 + * the same abstract package and 0 otherwise.
9932 + */
9933 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9934 +{
9935 + abstract_pkg_t **provides = pkg->provides;
9936 + int provides_count = pkg->provides_count;
9937 + abstract_pkg_t **replacee_provides = replacee->provides;
9938 + int replacee_provides_count = replacee->provides_count;
9939 + int i, j;
9940 + for (i = 0; i < provides_count; i++) {
9941 + abstract_pkg_t *apkg = provides[i];
9942 + for (j = 0; j < replacee_provides_count; j++) {
9943 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9944 + if (apkg == replacee_apkg)
9945 + return 1;
9946 + }
9947 + }
9948 + return 0;
9949 +}
9950 +#endif
9951 +
9952 +/**
9953 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9954 + * and 0 otherwise.
9955 + */
9956 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9957 +{
9958 + abstract_pkg_t **provides = pkg->provides;
9959 + int provides_count = pkg->provides_count;
9960 + int i;
9961 + for (i = 0; i < provides_count; i++) {
9962 + if (provides[i] == providee)
9963 + return 1;
9964 + }
9965 + return 0;
9966 +}
9967 +
9968 +/**
9969 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9970 + * otherwise.
9971 + */
9972 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9973 +{
9974 + abstract_pkg_t **replaces = pkg->replaces;
9975 + int replaces_count = pkg->replaces_count;
9976 + abstract_pkg_t **replacee_provides = pkg->provides;
9977 + int replacee_provides_count = pkg->provides_count;
9978 + int i, j;
9979 + for (i = 0; i < replaces_count; i++) {
9980 + abstract_pkg_t *abstract_replacee = replaces[i];
9981 + for (j = 0; j < replacee_provides_count; j++) {
9982 + if (replacee_provides[j] == abstract_replacee)
9983 + return 1;
9984 + }
9985 + }
9986 + return 0;
9987 +}
9988 +
9989 +
9990 +/**
9991 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9992 + * otherwise.
9993 + */
9994 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9995 +{
9996 + compound_depend_t *conflicts = pkg->conflicts;
9997 + int conflicts_count = pkg->conflicts_count;
9998 + int i, j;
9999 + for (i = 0; i < conflicts_count; i++) {
10000 + int possibility_count = conflicts[i].possibility_count;
10001 + struct depend **possibilities = conflicts[i].possibilities;
10002 + for (j = 0; j < possibility_count; j++) {
10003 + if (possibilities[j]->pkg == conflictee) {
10004 + return 1;
10005 + }
10006 + }
10007 + }
10008 + return 0;
10009 +}
10010 +
10011 +/**
10012 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10013 + * conflictee's provides and 0 otherwise.
10014 + */
10015 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10016 +{
10017 + compound_depend_t *conflicts = pkg->conflicts;
10018 + int conflicts_count = pkg->conflicts_count;
10019 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10020 + int conflictee_provides_count = conflictee->provides_count;
10021 + int i, j, k;
10022 + int possibility_count;
10023 + struct depend **possibilities;
10024 + abstract_pkg_t *possibility ;
10025 +
10026 + for (i = 0; i < conflicts_count; i++) {
10027 + possibility_count = conflicts[i].possibility_count;
10028 + possibilities = conflicts[i].possibilities;
10029 + for (j = 0; j < possibility_count; j++) {
10030 + possibility = possibilities[j]->pkg;
10031 + for (k = 0; k < conflictee_provides_count; k++) {
10032 + if (possibility == conflictee_provides[k]) {
10033 + return 1;
10034 + }
10035 + }
10036 + }
10037 + }
10038 + return 0;
10039 +}
10040 +
10041 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10042 +{
10043 + int oldlen = 0, newlen = 0;
10044 + char ** result;
10045 + register int i, j;
10046 +
10047 + if(!newstuff)
10048 + return oldstuff;
10049 +
10050 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10051 + while(newstuff && newstuff[newlen]) newlen++;
10052 +
10053 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10054 + if (result == NULL) {
10055 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10056 + return NULL;
10057 + }
10058 +
10059 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10060 + *(result + i) = *(newstuff + j);
10061 +
10062 + *(result + i) = NULL;
10063 +
10064 + return result;
10065 +}
10066 +
10067 +/*
10068 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10069 + * this is null terminated, no count is carried around
10070 + */
10071 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10072 +{
10073 + int count;
10074 + char ** resized;
10075 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10076 +
10077 + count = 0;
10078 + while(the_lost && the_lost[count]) count++;
10079 +
10080 + count++; /* need one to hold the null */
10081 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10082 + if (resized == NULL) {
10083 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10084 + return NULL;
10085 + }
10086 + resized[count - 1] = strdup(depend_str);
10087 + resized[count] = NULL;
10088 +
10089 + return resized;
10090 +}
10091 +
10092 +void printDepends(pkg_t * pkg)
10093 +{
10094 + register int i, j;
10095 + compound_depend_t * depend;
10096 + int count;
10097 +
10098 + count = pkg->pre_depends_count + pkg->depends_count;
10099 +
10100 + depend = pkg->depends;
10101 + if(!depend){
10102 + fprintf(stderr, "Depends pointer is NULL\n");
10103 + return;
10104 + }
10105 + for(i = 0; i < count; i++){
10106 + fprintf(stderr, "%s has %d possibilities:\n",
10107 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10108 + depend->possibility_count);
10109 + for(j = 0; j < depend->possibility_count; j++)
10110 + fprintf(stderr, "\t%s version %s (%d)\n",
10111 + depend->possibilities[j]->pkg->name,
10112 + depend->possibilities[j]->version,
10113 + depend->possibilities[j]->constraint);
10114 + depend++;
10115 + }
10116 +}
10117 +
10118 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10119 +{
10120 + register int i, j;
10121 +
10122 + /* every pkg provides itself */
10123 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10124 +
10125 + if (!pkg->provides_count)
10126 + return 0;
10127 +
10128 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10129 + if (pkg->provides == NULL) {
10130 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10131 + return -1 ;
10132 + }
10133 + pkg->provides[0] = ab_pkg;
10134 +
10135 + // if (strcmp(ab_pkg->name, pkg->name))
10136 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10137 +
10138 + for(i = 0; i < pkg->provides_count; i++){
10139 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10140 +
10141 + pkg->provides[i+1] = provided_abpkg;
10142 +
10143 + j = 0;
10144 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10145 + }
10146 + return 0;
10147 +}
10148 +
10149 +/* Abhaya: added conflicts support */
10150 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10151 +{
10152 + register int i;
10153 + compound_depend_t * conflicts;
10154 +
10155 + if (!pkg->conflicts_count)
10156 + return 0;
10157 +
10158 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10159 + pkg->conflicts_count);
10160 + if (conflicts == NULL) {
10161 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10162 + return -1;
10163 + }
10164 + for (i = 0; i < pkg->conflicts_count; i++) {
10165 + conflicts->type = CONFLICTS;
10166 + parseDepends(conflicts, hash,
10167 + pkg->conflicts_str[i]);
10168 +#if 0
10169 + for (j = 0; j < conflicts->possibility_count; j++) {
10170 + depend_t *possibility = conflicts->possibilities[j];
10171 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10172 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10173 + }
10174 +#endif
10175 + conflicts++;
10176 + }
10177 + return 0;
10178 +}
10179 +
10180 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10181 +{
10182 + register int i, j;
10183 +
10184 + if (!pkg->replaces_count)
10185 + return 0;
10186 +
10187 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10188 + if (pkg->replaces == NULL) {
10189 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10190 + return -1;
10191 + }
10192 +
10193 + // if (strcmp(ab_pkg->name, pkg->name))
10194 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10195 +
10196 + for(i = 0; i < pkg->replaces_count; i++){
10197 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10198 +
10199 + pkg->replaces[i] = old_abpkg;
10200 +
10201 + j = 0;
10202 + if (!old_abpkg->replaced_by)
10203 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10204 + if ( old_abpkg->replaced_by == NULL ){
10205 + return -1;
10206 + }
10207 + /* if a package pkg both replaces and conflicts old_abpkg,
10208 + * then add it to the replaced_by vector so that old_abpkg
10209 + * will be upgraded to ab_pkg automatically */
10210 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10211 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10212 + }
10213 + return 0;
10214 +}
10215 +
10216 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10217 +{
10218 + int count;
10219 + register int i;
10220 + compound_depend_t * depends;
10221 +
10222 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10223 + return 0;
10224 +
10225 + if (0 && pkg->pre_depends_count)
10226 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10227 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10228 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10229 + if (depends == NULL) {
10230 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10231 + return -1;
10232 + }
10233 +
10234 +
10235 + for(i = 0; i < pkg->pre_depends_count; i++){
10236 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10237 + if (0 && pkg->pre_depends_count)
10238 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10239 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10240 + depends->type = PREDEPEND;
10241 + depends++;
10242 + }
10243 +
10244 + for(i = 0; i < pkg->recommends_count; i++){
10245 + parseDepends(depends, hash, pkg->recommends_str[i]);
10246 + if (0 && pkg->recommends_count)
10247 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10248 + pkg->recommends_str[i], depends, depends->possibility_count);
10249 + depends->type = RECOMMEND;
10250 + depends++;
10251 + }
10252 +
10253 + for(i = 0; i < pkg->suggests_count; i++){
10254 + parseDepends(depends, hash, pkg->suggests_str[i]);
10255 + if (0 && pkg->suggests_count)
10256 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10257 + pkg->suggests_str[i], depends, depends->possibility_count);
10258 + depends->type = SUGGEST;
10259 + depends++;
10260 + }
10261 +
10262 + for(i = 0; i < pkg->depends_count; i++){
10263 + parseDepends(depends, hash, pkg->depends_str[i]);
10264 + if (0 && pkg->depends_count)
10265 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10266 + pkg->depends_str[i], depends, depends->possibility_count);
10267 + depends++;
10268 + }
10269 + return 0;
10270 +}
10271 +
10272 +/*
10273 + * pkg_depend_string: returns the depends string specified by index.
10274 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10275 + * [0,npredepends) -> returns pre_depends_str[index]
10276 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10277 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10278 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10279 + */
10280 +char *pkg_depend_str(pkg_t *pkg, int index)
10281 +{
10282 + if (index < pkg->pre_depends_count) {
10283 + return pkg->pre_depends_str[index];
10284 + }
10285 + index -= pkg->pre_depends_count;
10286 +
10287 + if (index < pkg->recommends_count) {
10288 + return pkg->recommends_str[index];
10289 + }
10290 + index -= pkg->recommends_count;
10291 +
10292 + if (index < pkg->suggests_count) {
10293 + return pkg->suggests_str[index];
10294 + }
10295 + index -= pkg->suggests_count;
10296 +
10297 + if (index < pkg->depends_count) {
10298 + return pkg->depends_str[index];
10299 + }
10300 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10301 + return NULL;
10302 +}
10303 +
10304 +void freeDepends(pkg_t *pkg)
10305 +{
10306 + int i;
10307 +
10308 + if (pkg == NULL || pkg->depends == NULL) {
10309 + return;
10310 + }
10311 +
10312 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10313 + for (i=0; i < pkg->depends->possibility_count; i++) {
10314 + depend_deinit(pkg->depends->possibilities[i]);
10315 + }
10316 + free(pkg->depends->possibilities);
10317 + free(pkg->depends);
10318 + pkg->depends = NULL;
10319 +}
10320 +
10321 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10322 +{
10323 + compound_depend_t * depends;
10324 + int count, othercount;
10325 + register int i, j;
10326 + abstract_pkg_t * ab_depend;
10327 + abstract_pkg_t ** temp;
10328 +
10329 + count = pkg->pre_depends_count + pkg->depends_count;
10330 + depends = pkg->depends;
10331 +
10332 + if (0 && pkg->pre_depends_count)
10333 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10334 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10335 + for (i = 0; i < count; i++) {
10336 + if (0 && pkg->pre_depends_count)
10337 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10338 + for (j = 0; j < depends->possibility_count; j++){
10339 + ab_depend = depends->possibilities[j]->pkg;
10340 + if(!ab_depend->depended_upon_by)
10341 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10342 +
10343 + temp = ab_depend->depended_upon_by;
10344 + othercount = 1;
10345 + while(*temp){
10346 + temp++;
10347 + othercount++;
10348 + }
10349 + *temp = ab_pkg;
10350 +
10351 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10352 + (othercount + 1) * sizeof(abstract_pkg_t *));
10353 + /* the array may have moved */
10354 + temp = ab_depend->depended_upon_by + othercount;
10355 + *temp = NULL;
10356 + }
10357 + depends++;
10358 + }
10359 +}
10360 +
10361 +static depend_t * depend_init(void)
10362 +{
10363 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10364 + if ( d==NULL ){
10365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10366 + return NULL;
10367 + }
10368 + d->constraint = NONE;
10369 + d->version = NULL;
10370 + d->pkg = NULL;
10371 +
10372 + return d;
10373 +}
10374 +
10375 +static void depend_deinit(depend_t *d)
10376 +{
10377 + free(d);
10378 +}
10379 +
10380 +static int parseDepends(compound_depend_t *compound_depend,
10381 + hash_table_t * hash, char * depend_str)
10382 +{
10383 + char * pkg_name, buffer[2048];
10384 + int num_of_ors = 0;
10385 + register int i;
10386 + register char * src, * dest;
10387 + depend_t ** possibilities;
10388 +
10389 + /* first count the number of ored possibilities for satisfying dependency */
10390 + src = depend_str;
10391 + while(*src)
10392 + if(*src++ == '|')
10393 + num_of_ors++;
10394 +
10395 + compound_depend->type = DEPEND;
10396 +
10397 + compound_depend->possibility_count = num_of_ors + 1;
10398 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10399 + if (!possibilities)
10400 + return -ENOMEM;
10401 + compound_depend->possibilities = possibilities;
10402 +
10403 + src = depend_str;
10404 + for(i = 0; i < num_of_ors + 1; i++){
10405 + possibilities[i] = depend_init();
10406 + if (!possibilities[i])
10407 + return -ENOMEM;
10408 + /* gobble up just the name first */
10409 + dest = buffer;
10410 + while(*src &&
10411 + !isspace(*src) &&
10412 + (*src != '(') &&
10413 + (*src != '*') &&
10414 + (*src != '|'))
10415 + *dest++ = *src++;
10416 + *dest = '\0';
10417 + pkg_name = trim_alloc(buffer);
10418 + if (pkg_name == NULL )
10419 + return -ENOMEM;
10420 +
10421 + /* now look at possible version info */
10422 +
10423 + /* skip to next chars */
10424 + if(isspace(*src))
10425 + while(*src && isspace(*src)) src++;
10426 +
10427 + /* extract constraint and version */
10428 + if(*src == '('){
10429 + src++;
10430 + if(!strncmp(src, "<<", 2)){
10431 + possibilities[i]->constraint = EARLIER;
10432 + src += 2;
10433 + }
10434 + else if(!strncmp(src, "<=", 2)){
10435 + possibilities[i]->constraint = EARLIER_EQUAL;
10436 + src += 2;
10437 + }
10438 + else if(!strncmp(src, ">=", 2)){
10439 + possibilities[i]->constraint = LATER_EQUAL;
10440 + src += 2;
10441 + }
10442 + else if(!strncmp(src, ">>", 2)){
10443 + possibilities[i]->constraint = LATER;
10444 + src += 2;
10445 + }
10446 + else if(!strncmp(src, "=", 1)){
10447 + possibilities[i]->constraint = EQUAL;
10448 + src++;
10449 + }
10450 + /* should these be here to support deprecated designations; dpkg does */
10451 + else if(!strncmp(src, "<", 1)){
10452 + possibilities[i]->constraint = EARLIER_EQUAL;
10453 + src++;
10454 + }
10455 + else if(!strncmp(src, ">", 1)){
10456 + possibilities[i]->constraint = LATER_EQUAL;
10457 + src++;
10458 + }
10459 +
10460 + /* now we have any constraint, pass space to version string */
10461 + while(isspace(*src)) src++;
10462 +
10463 + /* this would be the version string */
10464 + dest = buffer;
10465 + while(*src && *src != ')')
10466 + *dest++ = *src++;
10467 + *dest = '\0';
10468 +
10469 + possibilities[i]->version = trim_alloc(buffer);
10470 + /* fprintf(stderr, "let's print the depends version string:");
10471 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10472 + if (possibilities[i]->version == NULL )
10473 + return -ENOMEM;
10474 +
10475 +
10476 + }
10477 + /* hook up the dependency to its abstract pkg */
10478 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10479 +
10480 + free(pkg_name);
10481 +
10482 + /* now get past the ) and any possible | chars */
10483 + while(*src &&
10484 + (isspace(*src) ||
10485 + (*src == ')') ||
10486 + (*src == '|')))
10487 + src++;
10488 + if (*src == '*')
10489 + {
10490 + compound_depend->type = GREEDY_DEPEND;
10491 + src++;
10492 + }
10493 + }
10494 +
10495 + return 0;
10496 +}
10497 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.h
10498 --- busybox-1.00-orig/archival/libipkg/pkg_depends.h 1970-01-01 00:00:00.000000000 +0000
10499 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.h 2005-07-20 10:19:05.000000000 +0000
10500 @@ -0,0 +1,105 @@
10501 +/* pkg_depends.h - the itsy package management system
10502 +
10503 + Steven M. Ayer
10504 +
10505 + Copyright (C) 2002 Compaq Computer Corporation
10506 +
10507 + This program is free software; you can redistribute it and/or
10508 + modify it under the terms of the GNU General Public License as
10509 + published by the Free Software Foundation; either version 2, or (at
10510 + your option) any later version.
10511 +
10512 + This program is distributed in the hope that it will be useful, but
10513 + WITHOUT ANY WARRANTY; without even the implied warranty of
10514 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10515 + General Public License for more details.
10516 +*/
10517 +
10518 +#ifndef PKG_DEPENDS_H
10519 +#define PKG_DEPENDS_H
10520 +
10521 +#include "pkg.h"
10522 +#include "pkg_hash.h"
10523 +
10524 +enum depend_type {
10525 + PREDEPEND,
10526 + DEPEND,
10527 + CONFLICTS,
10528 + GREEDY_DEPEND,
10529 + RECOMMEND,
10530 + SUGGEST
10531 +};
10532 +typedef enum depend_type depend_type_t;
10533 +
10534 +enum version_constraint {
10535 + NONE,
10536 + EARLIER,
10537 + EARLIER_EQUAL,
10538 + EQUAL,
10539 + LATER_EQUAL,
10540 + LATER
10541 +};
10542 +typedef enum version_constraint version_constraint_t;
10543 +
10544 +struct depend{
10545 + version_constraint_t constraint;
10546 + char * version;
10547 + abstract_pkg_t * pkg;
10548 +};
10549 +typedef struct depend depend_t;
10550 +
10551 +struct compound_depend{
10552 + depend_type_t type;
10553 + int possibility_count;
10554 + struct depend ** possibilities;
10555 +};
10556 +typedef struct compound_depend compound_depend_t;
10557 +
10558 +#include "hash_table.h"
10559 +
10560 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10561 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10562 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10563 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10564 +
10565 +/**
10566 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10567 + * the same abstract package and 0 otherwise.
10568 + */
10569 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10570 +
10571 +/**
10572 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10573 + * otherwise.
10574 + */
10575 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10576 +
10577 +/**
10578 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10579 + * otherwise.
10580 + */
10581 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10582 +
10583 +/**
10584 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10585 + * otherwise.
10586 + */
10587 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10588 +
10589 +/**
10590 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10591 + * otherwise.
10592 + */
10593 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10594 +
10595 +char *pkg_depend_str(pkg_t *pkg, int index);
10596 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10597 +void freeDepends(pkg_t *pkg);
10598 +void printDepends(pkg_t * pkg);
10599 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10600 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10601 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10602 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10603 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10604 +
10605 +#endif
10606 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.c
10607 --- busybox-1.00-orig/archival/libipkg/pkg_dest.c 1970-01-01 00:00:00.000000000 +0000
10608 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.c 2005-07-17 16:10:25.000000000 +0000
10609 @@ -0,0 +1,92 @@
10610 +/* pkg_dest.c - the itsy package management system
10611 +
10612 + Carl D. Worth
10613 +
10614 + Copyright (C) 2001 University of Southern California
10615 +
10616 + This program is free software; you can redistribute it and/or
10617 + modify it under the terms of the GNU General Public License as
10618 + published by the Free Software Foundation; either version 2, or (at
10619 + your option) any later version.
10620 +
10621 + This program is distributed in the hope that it will be useful, but
10622 + WITHOUT ANY WARRANTY; without even the implied warranty of
10623 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10624 + General Public License for more details.
10625 +*/
10626 +
10627 +#include "ipkg.h"
10628 +
10629 +#include "pkg_dest.h"
10630 +#include "file_util.h"
10631 +#include "str_util.h"
10632 +#include "sprintf_alloc.h"
10633 +
10634 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10635 +{
10636 + dest->name = strdup(name);
10637 +
10638 + /* Guarantee that dest->root_dir ends with a '/' */
10639 + if (str_ends_with(root_dir, "/")) {
10640 + dest->root_dir = strdup(root_dir);
10641 + } else {
10642 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10643 + }
10644 + file_mkdir_hier(dest->root_dir, 0755);
10645 +
10646 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10647 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10648 + file_mkdir_hier(dest->ipkg_dir, 0755);
10649 +
10650 + if (str_starts_with (lists_dir, "/"))
10651 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10652 + else
10653 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10654 +
10655 + file_mkdir_hier(dest->lists_dir, 0755);
10656 +
10657 + sprintf_alloc(&dest->info_dir, "%s/%s",
10658 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10659 + file_mkdir_hier(dest->info_dir, 0755);
10660 +
10661 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10662 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10663 +
10664 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10665 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10666 +
10667 + dest->status_file = NULL;
10668 +
10669 + return 0;
10670 +}
10671 +
10672 +void pkg_dest_deinit(pkg_dest_t *dest)
10673 +{
10674 + free(dest->name);
10675 + dest->name = NULL;
10676 +
10677 + free(dest->root_dir);
10678 + dest->root_dir = NULL;
10679 +
10680 + free(dest->ipkg_dir);
10681 + dest->ipkg_dir = NULL;
10682 +
10683 + free(dest->lists_dir);
10684 + dest->lists_dir = NULL;
10685 +
10686 + free(dest->info_dir);
10687 + dest->info_dir = NULL;
10688 +
10689 + free(dest->status_file_name);
10690 + dest->status_file_name = NULL;
10691 +
10692 + free(dest->status_file_tmp_name);
10693 + dest->status_file_tmp_name = NULL;
10694 +
10695 + if (dest->status_file) {
10696 + fclose(dest->status_file);
10697 + }
10698 + dest->status_file = NULL;
10699 +
10700 + dest->root_dir = NULL;
10701 +}
10702 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.h
10703 --- busybox-1.00-orig/archival/libipkg/pkg_dest.h 1970-01-01 00:00:00.000000000 +0000
10704 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.h 2005-07-17 16:10:25.000000000 +0000
10705 @@ -0,0 +1,38 @@
10706 +/* pkg_dest.h - the itsy package management system
10707 +
10708 + Carl D. Worth
10709 +
10710 + Copyright (C) 2001 University of Southern California
10711 +
10712 + This program is free software; you can redistribute it and/or
10713 + modify it under the terms of the GNU General Public License as
10714 + published by the Free Software Foundation; either version 2, or (at
10715 + your option) any later version.
10716 +
10717 + This program is distributed in the hope that it will be useful, but
10718 + WITHOUT ANY WARRANTY; without even the implied warranty of
10719 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10720 + General Public License for more details.
10721 +*/
10722 +
10723 +#ifndef PKG_DEST_H
10724 +#define PKG_DEST_H
10725 +
10726 +typedef struct pkg_dest pkg_dest_t;
10727 +struct pkg_dest
10728 +{
10729 + char *name;
10730 + char *root_dir;
10731 + char *ipkg_dir;
10732 + char *lists_dir;
10733 + char *info_dir;
10734 + char *status_file_name;
10735 + char *status_file_tmp_name;
10736 + FILE *status_file;
10737 +};
10738 +
10739 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10740 +void pkg_dest_deinit(pkg_dest_t *dest);
10741 +
10742 +#endif
10743 +
10744 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.c
10745 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 00:00:00.000000000 +0000
10746 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.c 2005-07-17 16:10:25.000000000 +0000
10747 @@ -0,0 +1,85 @@
10748 +/* pkg_dest_list.c - the itsy package management system
10749 +
10750 + Carl D. Worth
10751 +
10752 + Copyright (C) 2001 University of Southern California
10753 +
10754 + This program is free software; you can redistribute it and/or
10755 + modify it under the terms of the GNU General Public License as
10756 + published by the Free Software Foundation; either version 2, or (at
10757 + your option) any later version.
10758 +
10759 + This program is distributed in the hope that it will be useful, but
10760 + WITHOUT ANY WARRANTY; without even the implied warranty of
10761 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10762 + General Public License for more details.
10763 +*/
10764 +
10765 +#include "ipkg.h"
10766 +
10767 +#include "pkg_dest.h"
10768 +#include "void_list.h"
10769 +#include "pkg_dest_list.h"
10770 +
10771 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10772 +{
10773 + return void_list_elt_init((void_list_elt_t *) elt, data);
10774 +}
10775 +
10776 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10777 +{
10778 + void_list_elt_deinit((void_list_elt_t *) elt);
10779 +}
10780 +
10781 +int pkg_dest_list_init(pkg_dest_list_t *list)
10782 +{
10783 + return void_list_init((void_list_t *) list);
10784 +}
10785 +
10786 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10787 +{
10788 + pkg_dest_list_elt_t *iter;
10789 + pkg_dest_t *pkg_dest;
10790 +
10791 + for (iter = list->head; iter; iter = iter->next) {
10792 + pkg_dest = iter->data;
10793 + pkg_dest_deinit(pkg_dest);
10794 +
10795 + /* malloced in pkg_dest_list_append */
10796 + free(pkg_dest);
10797 + iter->data = NULL;
10798 + }
10799 + void_list_deinit((void_list_t *) list);
10800 +}
10801 +
10802 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10803 + const char *root_dir,const char *lists_dir)
10804 +{
10805 + int err;
10806 + pkg_dest_t *pkg_dest;
10807 +
10808 + /* freed in plg_dest_list_deinit */
10809 + pkg_dest = malloc(sizeof(pkg_dest_t));
10810 + if (pkg_dest == NULL) {
10811 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10812 + return NULL;
10813 + }
10814 +
10815 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10816 + err = void_list_append((void_list_t *) list, pkg_dest);
10817 + if (err) {
10818 + return NULL;
10819 + }
10820 +
10821 + return pkg_dest;
10822 +}
10823 +
10824 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10825 +{
10826 + return void_list_push((void_list_t *) list, data);
10827 +}
10828 +
10829 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10830 +{
10831 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10832 +}
10833 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.h
10834 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 00:00:00.000000000 +0000
10835 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.h 2005-07-17 16:10:25.000000000 +0000
10836 @@ -0,0 +1,50 @@
10837 +/* pkg_dest_list.h - the itsy package management system
10838 +
10839 + Carl D. Worth
10840 +
10841 + Copyright (C) 2001 University of Southern California
10842 +
10843 + This program is free software; you can redistribute it and/or
10844 + modify it under the terms of the GNU General Public License as
10845 + published by the Free Software Foundation; either version 2, or (at
10846 + your option) any later version.
10847 +
10848 + This program is distributed in the hope that it will be useful, but
10849 + WITHOUT ANY WARRANTY; without even the implied warranty of
10850 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10851 + General Public License for more details.
10852 +*/
10853 +
10854 +#ifndef PKG_DEST_LIST_H
10855 +#define PKG_DEST_LIST_H
10856 +
10857 +#include "pkg_dest.h"
10858 +
10859 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10860 +struct pkg_dest_list_elt
10861 +{
10862 + pkg_dest_list_elt_t *next;
10863 + pkg_dest_t *data;
10864 +};
10865 +
10866 +typedef struct pkg_dest_list pkg_dest_list_t;
10867 +struct pkg_dest_list
10868 +{
10869 + pkg_dest_list_elt_t pre_head;
10870 + pkg_dest_list_elt_t *head;
10871 + pkg_dest_list_elt_t *tail;
10872 +};
10873 +
10874 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10875 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10876 +
10877 +int pkg_dest_list_init(pkg_dest_list_t *list);
10878 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10879 +
10880 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10881 + const char *root_dir,const char* lists_dir);
10882 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10883 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10884 +
10885 +#endif
10886 +
10887 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.c
10888 --- busybox-1.00-orig/archival/libipkg/pkg_extract.c 1970-01-01 00:00:00.000000000 +0000
10889 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.c 2005-07-20 08:43:49.000000000 +0000
10890 @@ -0,0 +1,224 @@
10891 +/* pkg_extract.c - the itsy package management system
10892 +
10893 + Carl D. Worth
10894 +
10895 + Copyright (C) 2001 University of Southern California
10896 +
10897 + This program is free software; you can redistribute it and/or
10898 + modify it under the terms of the GNU General Public License as
10899 + published by the Free Software Foundation; either version 2, or (at
10900 + your option) any later version.
10901 +
10902 + This program is distributed in the hope that it will be useful, but
10903 + WITHOUT ANY WARRANTY; without even the implied warranty of
10904 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10905 + General Public License for more details.
10906 +*/
10907 +
10908 +#include "ipkg.h"
10909 +#include <errno.h>
10910 +#include <fcntl.h>
10911 +#include <stdio.h>
10912 +
10913 +#include "pkg_extract.h"
10914 +
10915 +#include "libbb.h"
10916 +#include "file_util.h"
10917 +#include "sprintf_alloc.h"
10918 +#include "unarchive.h"
10919 +
10920 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10921 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10922 +#define IPKG_CONTROL_FILE "control"
10923 +
10924 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10925 +{
10926 + archive_handle_t *archive;
10927 + char *path;
10928 +
10929 + sprintf_alloc(&path, "%s/", dir);
10930 + archive = init_handle();
10931 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10932 + archive->filter = filter_accept_list;
10933 + archive->accept = llist_add_to(NULL, (char *)filename);
10934 + archive->buffer = path;
10935 + archive->action_data = data_extract_all_prefix;
10936 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10937 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10938 + close(archive->src_fd);
10939 + free(archive->accept);
10940 + free(archive);
10941 + free(path);
10942 +}
10943 +
10944 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10945 +{
10946 + unsigned int size = strlen(archive->file_header->name) + 2;
10947 +
10948 + if (archive->buffer == NULL) {
10949 + archive->buffer = xmalloc(size);
10950 + strcpy(archive->buffer, archive->file_header->name);
10951 + } else {
10952 + size += strlen(archive->buffer);
10953 + archive->buffer = xrealloc(archive->buffer, size);
10954 + strcat(archive->buffer, archive->file_header->name);
10955 + }
10956 + strcat(archive->buffer, "\n");
10957 + data_skip(archive);
10958 +}
10959 +
10960 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10961 +{
10962 + archive_handle_t *archive;
10963 + char *name;
10964 +
10965 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10966 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10967 + archive = init_handle();
10968 + archive->src_fd = bb_xopen(name, O_RDONLY);
10969 + archive->filter = filter_accept_list;
10970 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10971 + archive->action_data = data_extract_to_buffer;
10972 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10973 + close(archive->src_fd);
10974 + fputs(archive->buffer, stream);
10975 + free(archive->buffer);
10976 + free(archive->accept);
10977 + free(archive);
10978 + free(name);
10979 +
10980 + return 0;
10981 +}
10982 +
10983 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10984 +{
10985 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10986 +}
10987 +
10988 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10989 +{
10990 + archive_handle_t *archive;
10991 + char *name;
10992 + char *path;
10993 +
10994 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10995 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10996 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10997 + archive = init_handle();
10998 + archive->src_fd = bb_xopen(name, O_RDONLY);
10999 + archive->filter = filter_accept_all;
11000 + archive->buffer = path;
11001 + archive->action_data = data_extract_all_prefix;
11002 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11003 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11004 + close(archive->src_fd);
11005 + free(archive);
11006 + free(path);
11007 + free(name);
11008 +
11009 + return 0;
11010 +}
11011 +
11012 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11013 +{
11014 + archive_handle_t *archive;
11015 + char *name;
11016 + char *path;
11017 +
11018 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11019 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11020 + sprintf_alloc(&path, "%s/", dir);
11021 + archive = init_handle();
11022 + archive->src_fd = bb_xopen(name, O_RDONLY);
11023 + archive->filter = filter_accept_all;
11024 + archive->buffer = path;
11025 + archive->action_data = data_extract_all_prefix;
11026 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11027 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11028 + close(archive->src_fd);
11029 + free(archive);
11030 + free(path);
11031 + free(name);
11032 +
11033 + return 0;
11034 +}
11035 +
11036 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11037 +{
11038 + int err=0;
11039 + char *line, *data_file;
11040 + FILE *file;
11041 + FILE *tmp;
11042 +
11043 + file = fopen(file_name, "w");
11044 + if (file == NULL) {
11045 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11046 + __FUNCTION__, file_name);
11047 + return EINVAL;
11048 + }
11049 +
11050 + tmp = tmpfile();
11051 + if (pkg->installed_files) {
11052 + str_list_elt_t *elt;
11053 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11054 + fprintf(file, "%s\n", elt->data);
11055 + }
11056 + } else {
11057 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11058 + if (err) {
11059 + fclose(file);
11060 + fclose(tmp);
11061 + return err;
11062 + }
11063 +
11064 + /* Fixup data file names by removing the initial '.' */
11065 + rewind(tmp);
11066 + while (1) {
11067 + line = file_read_line_alloc(tmp);
11068 + if (line == NULL) {
11069 + break;
11070 + }
11071 +
11072 + data_file = line;
11073 + if (*data_file == '.') {
11074 + data_file++;
11075 + }
11076 +
11077 + if (*data_file != '/') {
11078 + fputs("/", file);
11079 + }
11080 +
11081 + /* I have no idea why, but this is what dpkg does */
11082 + if (strcmp(data_file, "/\n") == 0) {
11083 + fputs("/.\n", file);
11084 + } else {
11085 + fputs(data_file, file);
11086 + }
11087 + }
11088 + }
11089 + fclose(tmp);
11090 + fclose(file);
11091 +
11092 + return err;
11093 +}
11094 +
11095 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11096 +{
11097 + archive_handle_t *archive;
11098 + char *name;
11099 +
11100 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11101 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11102 + archive = init_handle();
11103 + archive->src_fd = bb_xopen(name, O_RDONLY);
11104 + archive->filter = filter_accept_all;
11105 + archive->action_data = data_extract_file_name_to_buffer;
11106 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11107 + close(archive->src_fd);
11108 + fputs(archive->buffer, file);
11109 + free(archive->buffer);
11110 + free(archive);
11111 + free(name);
11112 +
11113 + return 0;
11114 +}
11115 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.h
11116 --- busybox-1.00-orig/archival/libipkg/pkg_extract.h 1970-01-01 00:00:00.000000000 +0000
11117 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.h 2005-07-17 16:10:25.000000000 +0000
11118 @@ -0,0 +1,32 @@
11119 +/* pkg_extract.c - the itsy package management system
11120 +
11121 + Carl D. Worth
11122 +
11123 + Copyright (C) 2001 University of Southern California
11124 +
11125 + This program is free software; you can redistribute it and/or
11126 + modify it under the terms of the GNU General Public License as
11127 + published by the Free Software Foundation; either version 2, or (at
11128 + your option) any later version.
11129 +
11130 + This program is distributed in the hope that it will be useful, but
11131 + WITHOUT ANY WARRANTY; without even the implied warranty of
11132 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11133 + General Public License for more details.
11134 +*/
11135 +
11136 +#ifndef PKG_EXTRACT_H
11137 +#define PKG_EXTRACT_H
11138 +
11139 +#include "pkg.h"
11140 +
11141 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11142 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11143 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11144 + const char *dir,
11145 + const char *prefix);
11146 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11147 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11148 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11149 +
11150 +#endif
11151 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.c
11152 --- busybox-1.00-orig/archival/libipkg/pkg_hash.c 1970-01-01 00:00:00.000000000 +0000
11153 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.c 2005-07-20 10:18:39.000000000 +0000
11154 @@ -0,0 +1,600 @@
11155 +/* ipkg_hash.c - the itsy package management system
11156 +
11157 + Steven M. Ayer
11158 +
11159 + Copyright (C) 2002 Compaq Computer Corporation
11160 +
11161 + This program is free software; you can redistribute it and/or
11162 + modify it under the terms of the GNU General Public License as
11163 + published by the Free Software Foundation; either version 2, or (at
11164 + your option) any later version.
11165 +
11166 + This program is distributed in the hope that it will be useful, but
11167 + WITHOUT ANY WARRANTY; without even the implied warranty of
11168 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11169 + General Public License for more details.
11170 +*/
11171 +
11172 +#include "ipkg.h"
11173 +#include <errno.h>
11174 +#include <ctype.h>
11175 +#include <stdlib.h>
11176 +#include <string.h>
11177 +
11178 +#include "hash_table.h"
11179 +#include "pkg.h"
11180 +#include "ipkg_message.h"
11181 +#include "pkg_vec.h"
11182 +#include "pkg_hash.h"
11183 +#include "pkg_parse.h"
11184 +#include "ipkg_utils.h"
11185 +
11186 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11187 +
11188 +/*
11189 + * this will talk to both feeds-lists files and installed status files
11190 + * example api:
11191 + *
11192 + * hash_table_t hash;
11193 + * pkg_hash_init(name, &hash, 1000);
11194 + * pkg_hash_add_from_file(<feed filename>);
11195 + *
11196 + * the query function is just there as a shell to prove to me that this
11197 + * sort of works, but isn't far from doing something useful
11198 + *
11199 + * -sma, 12/21/01
11200 + * modified: CDW 3 Jan. 2002
11201 + */
11202 +
11203 +
11204 +\f
11205 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11206 +{
11207 + return hash_table_init(name, hash, len);
11208 +}
11209 +
11210 +void pkg_hash_deinit(hash_table_t *hash)
11211 +{
11212 + hash_table_deinit(hash);
11213 +}
11214 +
11215 +
11216 +/* Find the default arch for a given package status file if none is given. */
11217 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11218 +{
11219 + nv_pair_list_elt_t *l;
11220 + char *def_arch = HOST_CPU_STR; /* Default arch */
11221 + int def_prio = 0; /* Other archs override this */
11222 +
11223 + l = conf->arch_list.head;
11224 +
11225 + while (l) {
11226 + nv_pair_t *nv = l->data;
11227 + int priority = strtol(nv->value, NULL, 0);
11228 +
11229 + /* Check if this arch has higher priority, and is valid */
11230 + if ((priority > def_prio) &&
11231 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11232 + /* Our new default */
11233 + def_prio = priority;
11234 + def_arch = nv->name;
11235 + }
11236 + l = l->next;
11237 + }
11238 +
11239 + return strdup(def_arch);
11240 +}
11241 +
11242 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11243 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11244 +{
11245 + hash_table_t *hash = &conf->pkg_hash;
11246 + char **raw;
11247 + char **raw_start;
11248 + pkg_t *pkg;
11249 +
11250 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11251 + if (!raw)
11252 + return -ENOMEM;
11253 +
11254 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11255 + pkg = pkg_new();
11256 + if (!pkg)
11257 + return -ENOMEM;
11258 +
11259 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11260 + if (!pkg->architecture) {
11261 + char *version_str = pkg_version_str_alloc(pkg);
11262 + pkg->architecture = pkg_get_default_arch(conf);
11263 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11264 + pkg->name, version_str, pkg->architecture);
11265 + free(version_str);
11266 + }
11267 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11268 + } else {
11269 + free(pkg);
11270 + }
11271 + }
11272 +
11273 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11274 + memory after read_raw_pkgs_from_file */
11275 + raw = raw_start;
11276 + while (*raw) {
11277 + free(*raw++);
11278 + }
11279 + free(raw_start);
11280 + return 0;
11281 +}
11282 +
11283 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11284 +{
11285 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11286 +}
11287 +
11288 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11289 +{
11290 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11291 + if (apkg)
11292 + return NULL;
11293 + return apkg->provided_by;
11294 +}
11295 +
11296 +
11297 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11298 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11299 +{
11300 + int i;
11301 + int nprovides = 0;
11302 + int nmatching = 0;
11303 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11304 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11305 + abstract_pkg_vec_t *provided_apkg_vec;
11306 + abstract_pkg_t **provided_apkgs;
11307 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11308 + pkg_t *latest_installed_parent = NULL;
11309 + pkg_t *latest_matching = NULL;
11310 + pkg_t *held_pkg = NULL;
11311 +
11312 + if (matching_apkgs == NULL || providers == NULL ||
11313 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11314 + return NULL;
11315 +
11316 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11317 +
11318 + provided_apkg_vec = apkg->provided_by;
11319 + nprovides = provided_apkg_vec->len;
11320 + provided_apkgs = provided_apkg_vec->pkgs;
11321 + if (nprovides > 1)
11322 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11323 +
11324 + /* accumulate all the providers */
11325 + for (i = 0; i < nprovides; i++) {
11326 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11327 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11328 + abstract_pkg_vec_insert(providers, provider_apkg);
11329 + }
11330 + nprovides = providers->len;
11331 +
11332 + for (i = 0; i < nprovides; i++) {
11333 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11334 + abstract_pkg_t *replacement_apkg = NULL;
11335 + pkg_vec_t *vec;
11336 +
11337 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11338 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11339 + if (provider_apkg->replaced_by->len > 1) {
11340 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11341 + provider_apkg->name, replacement_apkg->name);
11342 + }
11343 + }
11344 +
11345 + if (replacement_apkg)
11346 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11347 + replacement_apkg->name, provider_apkg->name);
11348 +
11349 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11350 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11351 + continue;
11352 + else
11353 + provider_apkg = replacement_apkg;
11354 + }
11355 +
11356 + if (!(vec = provider_apkg->pkgs)) {
11357 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11358 + continue;
11359 + }
11360 +
11361 +
11362 +/* Could a package provide more than a package ? */
11363 + /* now check for supported architecture and satisfaction of constraint_fcn */
11364 + {
11365 + int max_count = 0;
11366 + int i;
11367 +
11368 + /* count packages matching max arch priority and keep track of last one */
11369 + for (i = 0; i < vec->len; i++) {
11370 + pkg_t *maybe = vec->pkgs[i];
11371 + /* only consider the ones that satisfy the constraint */
11372 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d constraint=%d \n",
11373 + maybe->name, maybe->architecture,
11374 + maybe->arch_priority,
11375 + ((constraint_fcn == NULL) || constraint_fcn(maybe, cdata)));
11376 + if ((maybe->arch_priority > 0)
11377 + && ((constraint_fcn == NULL) || constraint_fcn(maybe, cdata))) {
11378 + max_count++;
11379 +
11380 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11381 + pkg_vec_insert(matching_pkgs, maybe);
11382 + }
11383 + }
11384 + }
11385 + }
11386 +
11387 + if (matching_pkgs->len > 1)
11388 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11389 + if (matching_apkgs->len > 1)
11390 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11391 +
11392 + for (i = 0; i < matching_pkgs->len; i++) {
11393 + pkg_t *matching = matching_pkgs->pkgs[i];
11394 + latest_matching = matching;
11395 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11396 + latest_installed_parent = matching;
11397 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11398 + if (held_pkg)
11399 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11400 + held_pkg->name, matching->name);
11401 + held_pkg = matching;
11402 + }
11403 + }
11404 +
11405 + if (!held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11406 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11407 + apkg->name, matching_apkgs->len);
11408 + if (conf->verbosity > 1) {
11409 + for (i = 0; i < matching_apkgs->len; i++) {
11410 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11411 + ipkg_message(conf, IPKG_NOTICE, " %s\n", matching->name);
11412 + }
11413 + }
11414 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11415 + }
11416 +
11417 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11418 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11419 + __FUNCTION__, apkg->name, matching_pkgs->len);
11420 + for (i = 0; i < matching_pkgs->len; i++) {
11421 + pkg_t *matching = matching_pkgs->pkgs[i];
11422 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11423 + matching->name, matching->version, matching->architecture);
11424 + }
11425 + }
11426 +
11427 + nmatching = matching_apkgs->len;
11428 +
11429 + pkg_vec_free(matching_pkgs);
11430 + abstract_pkg_vec_free(matching_apkgs);
11431 + abstract_pkg_vec_free(providers);
11432 +
11433 + if (held_pkg) {
11434 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11435 + return held_pkg;
11436 + }
11437 + if (latest_installed_parent) {
11438 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11439 + return latest_installed_parent;
11440 + }
11441 + if (nmatching > 1) {
11442 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11443 + return NULL;
11444 + }
11445 + if (latest_matching) {
11446 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11447 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11448 + return latest_matching;
11449 + }
11450 + return NULL;
11451 +}
11452 +
11453 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11454 +{
11455 + const char *name = (const char *)cdata;
11456 + if (strcmp(pkg->name, name) == 0)
11457 + return 1;
11458 + else
11459 + return 0;
11460 +}
11461 +
11462 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11463 +{
11464 + hash_table_t *hash = &conf->pkg_hash;
11465 + abstract_pkg_t *apkg = NULL;
11466 +
11467 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11468 + return NULL;
11469 +
11470 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11471 +}
11472 +
11473 +
11474 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11475 + const char *pkg_name,
11476 + const char * version)
11477 +{
11478 + pkg_vec_t * vec;
11479 + register int i;
11480 + char *version_str = NULL;
11481 +
11482 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11483 + return NULL;
11484 +
11485 + for(i = 0; i < vec->len; i++) {
11486 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11487 + if(!strcmp(version_str, version)) {
11488 + free(version_str);
11489 + break;
11490 + }
11491 + free(version_str);
11492 + }
11493 +
11494 + if(i == vec->len)
11495 + return NULL;
11496 +
11497 + return vec->pkgs[i];
11498 +}
11499 +
11500 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11501 + const char *pkg_name,
11502 + pkg_dest_t *dest)
11503 +{
11504 + pkg_vec_t * vec;
11505 + register int i;
11506 +
11507 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11508 + return NULL;
11509 + }
11510 +
11511 + for(i = 0; i < vec->len; i++)
11512 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11513 + return vec->pkgs[i];
11514 + }
11515 + return NULL;
11516 +}
11517 +
11518 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11519 + const char *pkg_name)
11520 +{
11521 + pkg_vec_t * vec;
11522 + register int i;
11523 +
11524 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11525 + return NULL;
11526 + }
11527 +
11528 + for(i = 0; i < vec->len; i++)
11529 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11530 + return vec->pkgs[i];
11531 + }
11532 +
11533 + return NULL;
11534 +}
11535 +
11536 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11537 +{
11538 + abstract_pkg_t * ab_pkg;
11539 +
11540 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11541 + return NULL;
11542 + }
11543 +
11544 + if (ab_pkg->pkgs) {
11545 + return ab_pkg->pkgs;
11546 + } else if (ab_pkg->provided_by) {
11547 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11548 + if (abpkg != NULL){
11549 + return abpkg->pkgs;
11550 + } else {
11551 + return ab_pkg->pkgs;
11552 + }
11553 + } else {
11554 + return NULL;
11555 + }
11556 +}
11557 +
11558 +static int pkg_compare_names(const void *p1, const void *p2)
11559 +{
11560 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11561 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11562 + if (pkg1->name == NULL)
11563 + return 1;
11564 + if (pkg2->name == NULL)
11565 + return -1;
11566 + return(strcmp(pkg1->name, pkg2->name));
11567 +}
11568 +
11569 +
11570 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11571 +{
11572 + int j;
11573 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11574 + pkg_vec_t *all = (pkg_vec_t *)data;
11575 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11576 + if (pkg_vec) {
11577 + for (j = 0; j < pkg_vec->len; j++) {
11578 + pkg_t *pkg = pkg_vec->pkgs[j];
11579 + pkg_vec_insert(all, pkg);
11580 + }
11581 + }
11582 +}
11583 +
11584 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11585 +{
11586 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11587 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11588 +}
11589 +
11590 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11591 +{
11592 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11593 + pkg_vec_t *all = (pkg_vec_t *)data;
11594 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11595 + int j;
11596 + if (pkg_vec) {
11597 + for (j = 0; j < pkg_vec->len; j++) {
11598 + pkg_t *pkg = pkg_vec->pkgs[j];
11599 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11600 + pkg_vec_insert(all, pkg);
11601 + }
11602 + }
11603 + }
11604 +}
11605 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11606 +{
11607 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11608 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11609 +}
11610 +
11611 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11612 +{
11613 + int i;
11614 + pkg_t *pkg;
11615 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11616 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11617 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11618 + fprintf(stdout, "%s\n", ab_pkg->name);
11619 + i = 0;
11620 + if (dependents != NULL)
11621 + while (dependents [i] != NULL)
11622 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11623 + dependents = ab_pkg->provided_by->pkgs;
11624 + i = 0;
11625 + if (dependents != NULL)
11626 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11627 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11628 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11629 + if (pkg) {
11630 + i = 0;
11631 + while (i < pkg->depends_count)
11632 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11633 + }
11634 +}
11635 +void pkg_hash_dump(hash_table_t *hash, void *data)
11636 +{
11637 +
11638 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11639 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11640 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11641 +}
11642 +
11643 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11644 +{
11645 + abstract_pkg_t * ab_pkg;
11646 +
11647 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11648 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11649 +
11650 + return ab_pkg;
11651 +}
11652 +
11653 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11654 +{
11655 + abstract_pkg_t * ab_pkg;
11656 + int arch_priority;
11657 +
11658 + if(!pkg)
11659 + return pkg;
11660 +
11661 + arch_priority = pkg->arch_priority;
11662 +
11663 + if (buildDepends(hash, pkg)<0){
11664 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11665 + return NULL;
11666 + }
11667 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11668 +
11669 + if (set_status) {
11670 + if (pkg->state_status == SS_INSTALLED) {
11671 + ab_pkg->state_status = SS_INSTALLED;
11672 + } else if (pkg->state_status == SS_UNPACKED) {
11673 + ab_pkg->state_status = SS_UNPACKED;
11674 + }
11675 + }
11676 +
11677 + if(!ab_pkg->pkgs)
11678 + ab_pkg->pkgs = pkg_vec_alloc();
11679 +
11680 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11681 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11682 + pkg->parent = ab_pkg;
11683 +
11684 + if (buildProvides(hash, ab_pkg, pkg)<0){
11685 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11686 + return NULL;
11687 + }
11688 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11689 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11690 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11691 + return NULL;
11692 + }
11693 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11694 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11695 + return NULL;
11696 + }
11697 +
11698 + buildDependedUponBy(pkg, ab_pkg);
11699 + return pkg;
11700 +}
11701 +
11702 +/*
11703 + * this will assume that we've already determined that
11704 + * the abstract pkg doesn't exist, 'cause we should know these things...
11705 + */
11706 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11707 +{
11708 + abstract_pkg_t * ab_pkg;
11709 +
11710 + ab_pkg = abstract_pkg_new();
11711 + if (ab_pkg == NULL) { return NULL; }
11712 +
11713 + ab_pkg->name = strdup(pkg_name);
11714 + hash_table_insert(hash, pkg_name, ab_pkg);
11715 +
11716 + return ab_pkg;
11717 +}
11718 +
11719 +
11720 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11721 +{
11722 + hash_table_t *file_hash = &conf->file_hash;
11723 +
11724 + return hash_table_get(file_hash, file_name);
11725 +}
11726 +
11727 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11728 +{
11729 + hash_table_t *file_hash = &conf->file_hash;
11730 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11731 + int file_name_len = strlen(file_name);
11732 +
11733 + if (file_name[file_name_len -1] == '/')
11734 + return 0;
11735 +
11736 + if (conf->offline_root) {
11737 + int len = strlen(conf->offline_root);
11738 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11739 + file_name += len;
11740 + }
11741 + }
11742 +
11743 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11744 + hash_table_insert(file_hash, file_name, owning_pkg);
11745 + if (old_owning_pkg) {
11746 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11747 + /* mark this package to have its filelist written */
11748 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11749 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11750 + }
11751 + return 0;
11752 +}
11753 +
11754 +
11755 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.h
11756 --- busybox-1.00-orig/archival/libipkg/pkg_hash.h 1970-01-01 00:00:00.000000000 +0000
11757 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.h 2005-07-17 16:10:25.000000000 +0000
11758 @@ -0,0 +1,61 @@
11759 +/* pkg_hash.h - the itsy package management system
11760 +
11761 + Steven M. Ayer
11762 +
11763 + Copyright (C) 2002 Compaq Computer Corporation
11764 +
11765 + This program is free software; you can redistribute it and/or
11766 + modify it under the terms of the GNU General Public License as
11767 + published by the Free Software Foundation; either version 2, or (at
11768 + your option) any later version.
11769 +
11770 + This program is distributed in the hope that it will be useful, but
11771 + WITHOUT ANY WARRANTY; without even the implied warranty of
11772 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11773 + General Public License for more details.
11774 +*/
11775 +
11776 +#ifndef PKG_HASH_H
11777 +#define PKG_HASH_H
11778 +
11779 +#include "pkg.h"
11780 +#include "pkg_vec.h"
11781 +#include "hash_table.h"
11782 +
11783 +
11784 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11785 +void pkg_hash_deinit(hash_table_t *hash);
11786 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11787 +
11788 +void pkg_hash_dump(hash_table_t *hash, void *data);
11789 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11790 +
11791 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11792 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11793 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11794 +
11795 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11796 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11797 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11798 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11799 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11800 + const char *pkg_name,
11801 + const char * version);
11802 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11803 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11804 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11805 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11806 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11807 + const char *pkg_name);
11808 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11809 + const char *pkg_name,
11810 + pkg_dest_t *dest);
11811 +
11812 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11813 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11814 +
11815 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11816 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11817 +
11818 +#endif
11819 +
11820 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.c
11821 --- busybox-1.00-orig/archival/libipkg/pkg_parse.c 1970-01-01 00:00:00.000000000 +0000
11822 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.c 2005-07-17 16:10:25.000000000 +0000
11823 @@ -0,0 +1,366 @@
11824 +/* pkg_parse.c - the itsy package management system
11825 +
11826 + Steven M. Ayer
11827 +
11828 + Copyright (C) 2002 Compaq Computer Corporation
11829 +
11830 + This program is free software; you can redistribute it and/or
11831 + modify it under the terms of the GNU General Public License as
11832 + published by the Free Software Foundation; either version 2, or (at
11833 + your option) any later version.
11834 +
11835 + This program is distributed in the hope that it will be useful, but
11836 + WITHOUT ANY WARRANTY; without even the implied warranty of
11837 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11838 + General Public License for more details.
11839 +*/
11840 +
11841 +#include "ipkg.h"
11842 +#include <errno.h>
11843 +#include <ctype.h>
11844 +
11845 +#include "pkg.h"
11846 +#include "ipkg_utils.h"
11847 +#include "pkg_parse.h"
11848 +
11849 +int isGenericFieldType(char * type, char * line)
11850 +{
11851 + if(!strncmp(line, type, strlen(type)))
11852 + return 1;
11853 + return 0;
11854 +}
11855 +
11856 +char * parseGenericFieldType(char * type, char * raw)
11857 +{
11858 + char * field_value = raw + (strlen(type) + 1);
11859 + return trim_alloc(field_value);
11860 +}
11861 +
11862 +void parseStatus(pkg_t *pkg, char * raw)
11863 +{
11864 + char sw_str[64], sf_str[64], ss_str[64];
11865 +
11866 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11867 + pkg->state_want = pkg_state_want_from_str(sw_str);
11868 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11869 + pkg->state_status = pkg_state_status_from_str(ss_str);
11870 +}
11871 +
11872 +char ** parseDependsString(char * raw, int * depends_count)
11873 +{
11874 + char ** depends = NULL;
11875 + int line_count = 0;
11876 + char buff[2048], * dest;
11877 +
11878 + while(raw && *raw && !isspace(*raw)) {
11879 + raw++;
11880 + }
11881 +
11882 + if(line_is_blank(raw)){
11883 + *depends_count = line_count;
11884 + return NULL;
11885 + }
11886 + while(raw && *raw){
11887 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11888 +
11889 + while(isspace(*raw)) raw++;
11890 +
11891 + dest = buff;
11892 + while((*raw != ',') && *raw)
11893 + *dest++ = *raw++;
11894 +
11895 + *dest = '\0';
11896 + depends[line_count] = trim_alloc(buff);
11897 + if(depends[line_count] ==NULL)
11898 + return NULL;
11899 + line_count++;
11900 + if(*raw == ',')
11901 + raw++;
11902 + }
11903 + *depends_count = line_count;
11904 + return depends;
11905 +}
11906 +
11907 +void parseConffiles(pkg_t * pkg, char * raw)
11908 +{
11909 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11910 +
11911 + if(!strncmp(raw, "Conffiles:", 10))
11912 + raw += strlen("Conffiles:");
11913 +
11914 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11915 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11916 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11917 + while (*raw && isspace(*raw)) {
11918 + raw++;
11919 + }
11920 + raw += strlen(file_name);
11921 + while (*raw && isspace(*raw)) {
11922 + raw++;
11923 + }
11924 + raw += strlen(md5sum);
11925 + }
11926 +}
11927 +
11928 +int parseVersion(pkg_t *pkg, char *raw)
11929 +{
11930 + char *colon, *eepochcolon;
11931 +#ifdef USE_DEBVERSION
11932 + char *hyphen;
11933 +#endif
11934 + unsigned long epoch;
11935 +
11936 + if (!*raw) {
11937 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11938 + return EINVAL;
11939 + }
11940 +
11941 + if (strncmp(raw, "Version:", 8) == 0) {
11942 + raw += 8;
11943 + }
11944 + while (*raw && isspace(*raw)) {
11945 + raw++;
11946 + }
11947 +
11948 + colon= strchr(raw,':');
11949 + if (colon) {
11950 + epoch= strtoul(raw,&eepochcolon,10);
11951 + if (colon != eepochcolon) {
11952 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11953 + return EINVAL;
11954 + }
11955 + if (!*++colon) {
11956 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11957 + return EINVAL;
11958 + }
11959 + raw= colon;
11960 + pkg->epoch= epoch;
11961 + } else {
11962 + pkg->epoch= 0;
11963 + }
11964 +
11965 + pkg->revision = "";
11966 + pkg->familiar_revision = "";
11967 +
11968 + pkg->version= malloc(strlen(raw)+1);
11969 + if ( pkg->version == NULL ) {
11970 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11971 + return ENOMEM;
11972 + }
11973 + strcpy(pkg->version, raw);
11974 +
11975 +#ifdef USE_DEBVERSION
11976 + hyphen= strrchr(pkg->version,'-');
11977 +
11978 + if (hyphen) {
11979 + *hyphen++= 0;
11980 + if (strncmp("fam", hyphen, 3) == 0) {
11981 + pkg->familiar_revision=hyphen+3;
11982 + hyphen= strrchr(pkg->version,'-');
11983 + if (hyphen) {
11984 + *hyphen++= 0;
11985 + pkg->revision = hyphen;
11986 + }
11987 + } else {
11988 + pkg->revision = hyphen;
11989 + }
11990 + }
11991 +#endif
11992 +
11993 +/*
11994 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
11995 + pkg->epoch,
11996 + pkg->version,
11997 + pkg->revision,
11998 + pkg->familiar_revision);
11999 +*/
12000 +
12001 + return 0;
12002 +}
12003 +
12004 +
12005 +/* This code is needed to insert in first position the keyword for the aligning bug */
12006 +
12007 +int alterProvidesLine(char *raw, char *temp)
12008 +{
12009 +
12010 +
12011 + if (!*raw) {
12012 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12013 + return -EINVAL;
12014 + }
12015 +
12016 + if ( temp == NULL ) {
12017 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12018 + return -ENOMEM;
12019 + }
12020 +
12021 + if (strncmp(raw, "Provides:", 9) == 0) {
12022 + raw += 9;
12023 + }
12024 + while (*raw && isspace(*raw)) {
12025 + raw++;
12026 + }
12027 +
12028 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12029 + while (*raw) {
12030 + strncat( temp, raw++, 1);
12031 + }
12032 + return 0;
12033 +
12034 +}
12035 +
12036 +/* Some random thoughts from Carl:
12037 +
12038 + This function could be considerably simplified if we just kept
12039 + an array of all the generic string-valued field names, and looped
12040 + through those looking for a match. Also, these fields could perhaps
12041 + be stored in the package as an array as well, (or, probably better,
12042 + as an nv_pair_list_t).
12043 +
12044 + Fields which require special parsing or storage, (such as Depends:
12045 + and Status:) could be handled as they are now.
12046 +*/
12047 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12048 + to a dependency list. And, since we already have
12049 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12050 + Enhances, perhaps we could generalize all of these and save some
12051 + code duplication.
12052 +*/
12053 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12054 +{
12055 + int reading_conffiles, reading_description;
12056 + int pkg_false_provides=1;
12057 + char ** lines;
12058 + char * provide=NULL;
12059 +
12060 + pkg->src = src;
12061 + pkg->dest = dest;
12062 +
12063 + reading_conffiles = reading_description = 0;
12064 +
12065 + for (lines = *raw; *lines; lines++) {
12066 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12067 + if(isGenericFieldType("Package:", *lines))
12068 + pkg->name = parseGenericFieldType("Package", *lines);
12069 + else if(isGenericFieldType("Architecture:", *lines))
12070 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12071 + else if(isGenericFieldType("Filename:", *lines))
12072 + pkg->filename = parseGenericFieldType("Filename", *lines);
12073 + else if(isGenericFieldType("Section:", *lines))
12074 + pkg->section = parseGenericFieldType("Section", *lines);
12075 + else if(isGenericFieldType("MD5sum:", *lines))
12076 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12077 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12078 + let's parse it either way */
12079 + else if(isGenericFieldType("MD5Sum:", *lines))
12080 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12081 + else if(isGenericFieldType("Size:", *lines))
12082 + pkg->size = parseGenericFieldType("Size", *lines);
12083 + else if(isGenericFieldType("Source:", *lines))
12084 + pkg->source = parseGenericFieldType("Source", *lines);
12085 + else if(isGenericFieldType("Installed-Size:", *lines))
12086 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12087 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12088 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12089 + pkg->installed_time = strtoul(time_str, NULL, 0);
12090 + } else if(isGenericFieldType("Priority:", *lines))
12091 + pkg->priority = parseGenericFieldType("Priority", *lines);
12092 + else if(isGenericFieldType("Essential:", *lines)) {
12093 + char *essential_value;
12094 + essential_value = parseGenericFieldType("Essential", *lines);
12095 + if (strcmp(essential_value, "yes") == 0) {
12096 + pkg->essential = 1;
12097 + }
12098 + free(essential_value);
12099 + }
12100 + else if(isGenericFieldType("Status", *lines))
12101 + parseStatus(pkg, *lines);
12102 + else if(isGenericFieldType("Version", *lines))
12103 + parseVersion(pkg, *lines);
12104 + else if(isGenericFieldType("Maintainer", *lines))
12105 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12106 + else if(isGenericFieldType("Conffiles", *lines)){
12107 + parseConffiles(pkg, *lines);
12108 + reading_conffiles = 1;
12109 + }
12110 + else if(isGenericFieldType("Description", *lines)) {
12111 + pkg->description = parseGenericFieldType("Description", *lines);
12112 + reading_conffiles = 0;
12113 + reading_description = 1;
12114 + }
12115 +
12116 + else if(isGenericFieldType("Provides", *lines)){
12117 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12118 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12119 + if ( alterProvidesLine(*lines,provide) ){
12120 + return EINVAL;
12121 + }
12122 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12123 +/* Let's try to hack a bit here.
12124 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12125 + in alot of other places. We will remove it before writing down the status database */
12126 + pkg_false_provides=0;
12127 + free(provide);
12128 + }
12129 +
12130 + else if(isGenericFieldType("Depends", *lines))
12131 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12132 + else if(isGenericFieldType("Pre-Depends", *lines))
12133 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12134 + else if(isGenericFieldType("Recommends", *lines))
12135 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12136 + else if(isGenericFieldType("Suggests", *lines))
12137 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12138 + /* Abhaya: support for conflicts */
12139 + else if(isGenericFieldType("Conflicts", *lines))
12140 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12141 + else if(isGenericFieldType("Replaces", *lines))
12142 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12143 + else if(line_is_blank(*lines)) {
12144 + lines++;
12145 + break;
12146 + }
12147 + else if(**lines == ' '){
12148 + if(reading_description) {
12149 + /* we already know it's not blank, so the rest of description */
12150 + pkg->description = realloc(pkg->description,
12151 + strlen(pkg->description)
12152 + + 1 + strlen(*lines) + 1);
12153 + strcat(pkg->description, "\n");
12154 + strcat(pkg->description, (*lines));
12155 + }
12156 + else if(reading_conffiles)
12157 + parseConffiles(pkg, *lines);
12158 + }
12159 + }
12160 + *raw = lines;
12161 +/* If the ipk has not a Provides line, we insert our false line */
12162 + if ( pkg_false_provides==1)
12163 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12164 +
12165 + if (pkg->name) {
12166 + return 0;
12167 + } else {
12168 + return EINVAL;
12169 + }
12170 +}
12171 +
12172 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12173 +{
12174 + char ** lines;
12175 +
12176 + for (lines = *raw; *lines; lines++) {
12177 + if(isGenericFieldType("Essential:", *lines)) {
12178 + char *essential_value;
12179 + essential_value = parseGenericFieldType("Essential", *lines);
12180 + if (strcmp(essential_value, "yes") == 0) {
12181 + pkg->essential = 1;
12182 + }
12183 + free(essential_value);
12184 + }
12185 + }
12186 + *raw = lines;
12187 +
12188 + return 0;
12189 +}
12190 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.h
12191 --- busybox-1.00-orig/archival/libipkg/pkg_parse.h 1970-01-01 00:00:00.000000000 +0000
12192 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.h 2005-07-17 16:10:25.000000000 +0000
12193 @@ -0,0 +1,31 @@
12194 +/* pkg_parse.h - the itsy package management system
12195 +
12196 + Steven M. Ayer
12197 +
12198 + Copyright (C) 2002 Compaq Computer Corporation
12199 +
12200 + This program is free software; you can redistribute it and/or
12201 + modify it under the terms of the GNU General Public License as
12202 + published by the Free Software Foundation; either version 2, or (at
12203 + your option) any later version.
12204 +
12205 + This program is distributed in the hope that it will be useful, but
12206 + WITHOUT ANY WARRANTY; without even the implied warranty of
12207 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12208 + General Public License for more details.
12209 +*/
12210 +
12211 +#ifndef PKG_PARSE_H
12212 +#define PKG_PARSE_H
12213 +
12214 +int isGenericFieldType(char * type, char * line);
12215 +char * parseGenericFieldType(char * type, char * raw);
12216 +void parseStatus(pkg_t *pkg, char * raw);
12217 +int parseVersion(pkg_t *pkg, char *raw);
12218 +char ** parseDependsString(char * raw, int * depends_count);
12219 +int parseVersion(pkg_t *pkg, char *raw);
12220 +void parseConffiles(pkg_t * pkg, char * raw);
12221 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12222 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12223 +
12224 +#endif
12225 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.c
12226 --- busybox-1.00-orig/archival/libipkg/pkg_src.c 1970-01-01 00:00:00.000000000 +0000
12227 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.c 2005-07-17 16:10:25.000000000 +0000
12228 @@ -0,0 +1,43 @@
12229 +/* pkg_src.c - the itsy package management system
12230 +
12231 + Carl D. Worth
12232 +
12233 + Copyright (C) 2001 University of Southern California
12234 +
12235 + This program is free software; you can redistribute it and/or
12236 + modify it under the terms of the GNU General Public License as
12237 + published by the Free Software Foundation; either version 2, or (at
12238 + your option) any later version.
12239 +
12240 + This program is distributed in the hope that it will be useful, but
12241 + WITHOUT ANY WARRANTY; without even the implied warranty of
12242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12243 + General Public License for more details.
12244 +*/
12245 +
12246 +#include "ipkg.h"
12247 +
12248 +#include "pkg_src.h"
12249 +#include "str_util.h"
12250 +
12251 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12252 +{
12253 + src->gzip = gzip;
12254 + src->name = str_dup_safe (name);
12255 + src->value = str_dup_safe (base_url);
12256 + if (extra_data)
12257 + src->extra_data = str_dup_safe (extra_data);
12258 + else
12259 + src->extra_data = NULL;
12260 + return 0;
12261 +}
12262 +
12263 +void pkg_src_deinit(pkg_src_t *src)
12264 +{
12265 + free (src->name);
12266 + free (src->value);
12267 + if (src->extra_data)
12268 + free (src->extra_data);
12269 +}
12270 +
12271 +
12272 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.h
12273 --- busybox-1.00-orig/archival/libipkg/pkg_src.h 1970-01-01 00:00:00.000000000 +0000
12274 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.h 2005-07-17 16:10:25.000000000 +0000
12275 @@ -0,0 +1,34 @@
12276 +/* pkg_src.h - the itsy package management system
12277 +
12278 + Carl D. Worth
12279 +
12280 + Copyright (C) 2001 University of Southern California
12281 +
12282 + This program is free software; you can redistribute it and/or
12283 + modify it under the terms of the GNU General Public License as
12284 + published by the Free Software Foundation; either version 2, or (at
12285 + your option) any later version.
12286 +
12287 + This program is distributed in the hope that it will be useful, but
12288 + WITHOUT ANY WARRANTY; without even the implied warranty of
12289 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12290 + General Public License for more details.
12291 +*/
12292 +
12293 +#ifndef PKG_SRC_H
12294 +#define PKG_SRC_H
12295 +
12296 +#include "nv_pair.h"
12297 +
12298 +typedef struct
12299 +{
12300 + char *name;
12301 + char *value;
12302 + char *extra_data;
12303 + int gzip;
12304 +} pkg_src_t;
12305 +
12306 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12307 +void pkg_src_deinit(pkg_src_t *src);
12308 +
12309 +#endif
12310 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.c
12311 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.c 1970-01-01 00:00:00.000000000 +0000
12312 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.c 2005-07-17 16:10:25.000000000 +0000
12313 @@ -0,0 +1,75 @@
12314 +/* pkg_src_list.c - the itsy package management system
12315 +
12316 + Carl D. Worth
12317 +
12318 + Copyright (C) 2001 University of Southern California
12319 +
12320 + This program is free software; you can redistribute it and/or
12321 + modify it under the terms of the GNU General Public License as
12322 + published by the Free Software Foundation; either version 2, or (at
12323 + your option) any later version.
12324 +
12325 + This program is distributed in the hope that it will be useful, but
12326 + WITHOUT ANY WARRANTY; without even the implied warranty of
12327 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12328 + General Public License for more details.
12329 +*/
12330 +
12331 +#include "ipkg.h"
12332 +
12333 +#include "pkg_src_list.h"
12334 +#include "void_list.h"
12335 +
12336 +int pkg_src_list_init(pkg_src_list_t *list)
12337 +{
12338 + return void_list_init((void_list_t *) list);
12339 +}
12340 +
12341 +void pkg_src_list_deinit(pkg_src_list_t *list)
12342 +{
12343 + pkg_src_list_elt_t *iter;
12344 + pkg_src_t *pkg_src;
12345 +
12346 + for (iter = list->head; iter; iter = iter->next) {
12347 + pkg_src = iter->data;
12348 + pkg_src_deinit(pkg_src);
12349 +
12350 + /* malloced in pkg_src_list_append */
12351 + free(pkg_src);
12352 + iter->data = NULL;
12353 + }
12354 + void_list_deinit((void_list_t *) list);
12355 +}
12356 +
12357 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12358 + const char *name, const char *base_url, const char *extra_data,
12359 + int gzip)
12360 +{
12361 + int err;
12362 +
12363 + /* freed in pkg_src_list_deinit */
12364 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12365 +
12366 + if (pkg_src == NULL) {
12367 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12368 + return NULL;
12369 + }
12370 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12371 +
12372 + err = void_list_append((void_list_t *) list, pkg_src);
12373 + if (err) {
12374 + return NULL;
12375 + }
12376 +
12377 + return pkg_src;
12378 +}
12379 +
12380 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12381 +{
12382 + return void_list_push((void_list_t *) list, data);
12383 +}
12384 +
12385 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12386 +{
12387 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12388 +}
12389 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.h
12390 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.h 1970-01-01 00:00:00.000000000 +0000
12391 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.h 2005-07-17 16:10:25.000000000 +0000
12392 @@ -0,0 +1,57 @@
12393 +/* pkg_src_list.h - the itsy package management system
12394 +
12395 + Carl D. Worth
12396 +
12397 + Copyright (C) 2001 University of Southern California
12398 +
12399 + This program is free software; you can redistribute it and/or
12400 + modify it under the terms of the GNU General Public License as
12401 + published by the Free Software Foundation; either version 2, or (at
12402 + your option) any later version.
12403 +
12404 + This program is distributed in the hope that it will be useful, but
12405 + WITHOUT ANY WARRANTY; without even the implied warranty of
12406 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12407 + General Public License for more details.
12408 +*/
12409 +
12410 +#ifndef PKG_SRC_LIST_H
12411 +#define PKG_SRC_LIST_H
12412 +
12413 +#include "pkg_src.h"
12414 +
12415 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12416 +struct pkg_src_list_elt
12417 +{
12418 + pkg_src_list_elt_t *next;
12419 + pkg_src_t *data;
12420 +};
12421 +
12422 +typedef struct pkg_src_list pkg_src_list_t;
12423 +struct pkg_src_list
12424 +{
12425 + pkg_src_list_elt_t pre_head;
12426 + pkg_src_list_elt_t *head;
12427 + pkg_src_list_elt_t *tail;
12428 +};
12429 +
12430 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12431 +{
12432 + if (list->head == NULL)
12433 + return 1;
12434 + else
12435 + return 0;
12436 +}
12437 +
12438 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12439 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12440 +
12441 +int pkg_src_list_init(pkg_src_list_t *list);
12442 +void pkg_src_list_deinit(pkg_src_list_t *list);
12443 +
12444 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
12445 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12446 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12447 +
12448 +#endif
12449 +
12450 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.c
12451 --- busybox-1.00-orig/archival/libipkg/pkg_vec.c 1970-01-01 00:00:00.000000000 +0000
12452 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.c 2005-07-17 16:10:25.000000000 +0000
12453 @@ -0,0 +1,226 @@
12454 +/* pkg_vec.c - the itsy package management system
12455 +
12456 + Steven M. Ayer
12457 +
12458 + Copyright (C) 2002 Compaq Computer Corporation
12459 +
12460 + This program is free software; you can redistribute it and/or
12461 + modify it under the terms of the GNU General Public License as
12462 + published by the Free Software Foundation; either version 2, or (at
12463 + your option) any later version.
12464 +
12465 + This program is distributed in the hope that it will be useful, but
12466 + WITHOUT ANY WARRANTY; without even the implied warranty of
12467 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12468 + General Public License for more details.
12469 +*/
12470 +
12471 +#include <stdlib.h>
12472 +#include <fnmatch.h>
12473 +#include "xregex.h"
12474 +#include "ipkg.h"
12475 +#include "pkg.h"
12476 +
12477 +pkg_vec_t * pkg_vec_alloc(void)
12478 +{
12479 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12480 + if (!vec) {
12481 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12482 + return NULL;
12483 + }
12484 + vec->pkgs = NULL;
12485 + vec->len = 0;
12486 +
12487 + return vec;
12488 +}
12489 +
12490 +void pkg_vec_free(pkg_vec_t *vec)
12491 +{
12492 + free(vec->pkgs);
12493 + free(vec);
12494 +}
12495 +
12496 +/*
12497 + * assumption: all names in a vector are identical
12498 + * assumption: all version strings are trimmed,
12499 + * so identical versions have identical version strings,
12500 + * implying identical packages; let's marry these
12501 + */
12502 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12503 +{
12504 + int i;
12505 + int found = 0;
12506 +
12507 + /* look for a duplicate pkg by name, version, and architecture */
12508 + for (i = 0; i < vec->len; i++)
12509 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12510 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12511 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12512 + found = 1;
12513 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12514 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12515 + break;
12516 + }
12517 +
12518 + /* we didn't find one, add it */
12519 + if (!found){
12520 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12521 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12522 +
12523 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12524 + vec->pkgs[vec->len] = pkg;
12525 + vec->len++;
12526 + return pkg;
12527 + }
12528 + /* update the one that we have */
12529 + else {
12530 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12531 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12532 + if (set_status) {
12533 + /* this is from the status file, so need to merge with existing database */
12534 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12535 + pkg_merge(vec->pkgs[i], pkg, set_status);
12536 + /* XXX: CLEANUP: It's not so polite to free something here
12537 + that was passed in from above. */
12538 + pkg_deinit(pkg);
12539 + free(pkg);
12540 + } else {
12541 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12542 + /* just overwrite the old one */
12543 + pkg_deinit(vec->pkgs[i]);
12544 + free(vec->pkgs[i]);
12545 + vec->pkgs[i] = pkg;
12546 + }
12547 + return vec->pkgs[i];
12548 + }
12549 +}
12550 +
12551 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12552 +{
12553 + int i;
12554 + int found = 0;
12555 +
12556 + /* look for a duplicate pkg by name, version, and architecture */
12557 + for (i = 0; i < vec->len; i++)
12558 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12559 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12560 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12561 + found = 1;
12562 + break;
12563 + }
12564 +
12565 + /* we didn't find one, add it */
12566 + if(!found){
12567 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12568 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12569 + vec->len++;
12570 + }
12571 +}
12572 +
12573 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12574 +{
12575 + int i;
12576 + for (i = 0; i < vec->len; i++)
12577 + if (vec->pkgs[i] == apkg)
12578 + return 1;
12579 + return 0;
12580 +}
12581 +
12582 +typedef int (*compare_fcn_t)(const void *, const void *);
12583 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12584 +{
12585 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12586 +}
12587 +
12588 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12589 +{
12590 + int npkgs = vec->len;
12591 + int i;
12592 + for (i = 0; i < npkgs; i++) {
12593 + pkg_t *pkg = vec->pkgs[i];
12594 + pkg->state_flag &= ~SF_MARKED;
12595 + }
12596 + return 0;
12597 +}
12598 +
12599 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12600 +{
12601 + int matching_count = 0;
12602 + pkg_t **pkgs = vec->pkgs;
12603 + int npkgs = vec->len;
12604 + int i;
12605 + for (i = 0; i < npkgs; i++) {
12606 + pkg_t *pkg = pkgs[i];
12607 + if (fnmatch(pattern, pkg->name, 0)==0) {
12608 + pkg->state_flag |= SF_MARKED;
12609 + matching_count++;
12610 + }
12611 + }
12612 + return matching_count;
12613 +}
12614 +
12615 +
12616 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12617 +{
12618 + abstract_pkg_vec_t * vec ;
12619 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12620 + if (!vec) {
12621 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12622 + return NULL;
12623 + }
12624 + vec->pkgs = NULL;
12625 + vec->len = 0;
12626 +
12627 + return vec;
12628 +}
12629 +
12630 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12631 +{
12632 + free(vec->pkgs);
12633 + free(vec);
12634 +}
12635 +
12636 +/*
12637 + * assumption: all names in a vector are unique
12638 + */
12639 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12640 +{
12641 + int i;
12642 +
12643 + /* look for a duplicate pkg by name */
12644 + for(i = 0; i < vec->len; i++)
12645 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12646 + break;
12647 +
12648 + /* we didn't find one, add it */
12649 + if(i == vec->len){
12650 + vec->pkgs =
12651 + (abstract_pkg_t **)
12652 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12653 + vec->pkgs[vec->len] = pkg;
12654 + vec->len++;
12655 + }
12656 +}
12657 +
12658 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12659 +{
12660 + if (vec->len > i)
12661 + return vec->pkgs[i];
12662 + else
12663 + return NULL;
12664 +}
12665 +
12666 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12667 +{
12668 + int i;
12669 + for (i = 0; i < vec->len; i++)
12670 + if (vec->pkgs[i] == apkg)
12671 + return 1;
12672 + return 0;
12673 +}
12674 +
12675 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12676 +{
12677 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12678 +}
12679 +
12680 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.h
12681 --- busybox-1.00-orig/archival/libipkg/pkg_vec.h 1970-01-01 00:00:00.000000000 +0000
12682 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.h 2005-07-17 16:10:25.000000000 +0000
12683 @@ -0,0 +1,62 @@
12684 +/* pkg_vec.h - the itsy package management system
12685 +
12686 + Steven M. Ayer
12687 +
12688 + Copyright (C) 2002 Compaq Computer Corporation
12689 +
12690 + This program is free software; you can redistribute it and/or
12691 + modify it under the terms of the GNU General Public License as
12692 + published by the Free Software Foundation; either version 2, or (at
12693 + your option) any later version.
12694 +
12695 + This program is distributed in the hope that it will be useful, but
12696 + WITHOUT ANY WARRANTY; without even the implied warranty of
12697 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12698 + General Public License for more details.
12699 +*/
12700 +
12701 +#ifndef PKG_VEC_H
12702 +#define PKG_VEC_H
12703 +
12704 +typedef struct pkg pkg_t;
12705 +typedef struct abstract_pkg abstract_pkg_t;
12706 +
12707 +struct pkg_vec
12708 +{
12709 + pkg_t **pkgs;
12710 + int len;
12711 +};
12712 +typedef struct pkg_vec pkg_vec_t;
12713 +
12714 +struct abstract_pkg_vec
12715 +{
12716 + abstract_pkg_t **pkgs;
12717 + int len;
12718 +};
12719 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12720 +
12721 +
12722 +pkg_vec_t * pkg_vec_alloc(void);
12723 +void pkg_vec_free(pkg_vec_t *vec);
12724 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12725 +
12726 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12727 +/* pkg_vec_insert_merge: might munge pkg.
12728 +* returns the pkg that is in the pkg graph */
12729 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12730 +/* this one never munges pkg */
12731 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12732 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12733 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12734 +
12735 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12736 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12737 +
12738 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12739 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12740 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12741 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12742 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12743 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12744 +#endif
12745 +
12746 diff -ruN busybox-1.00-orig/archival/libipkg/sprintf_alloc.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/sprintf_alloc.h
12747 --- busybox-1.00-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 00:00:00.000000000 +0000
12748 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/sprintf_alloc.h 2005-07-20 17:16:41.554124384 +0000
12749 @@ -0,0 +1,25 @@
12750 +/* sprintf_alloca.c -- like sprintf with memory allocation
12751 +
12752 + Carl D. Worth
12753 +
12754 + Copyright (C) 2001 University of Southern California
12755 +
12756 + This program is free software; you can redistribute it and/or modify
12757 + it under the terms of the GNU General Public License as published by
12758 + the Free Software Foundation; either version 2, or (at your option)
12759 + any later version.
12760 +
12761 + This program is distributed in the hope that it will be useful,
12762 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12764 + GNU General Public License for more details.
12765 +*/
12766 +
12767 +#ifndef SPRINTF_ALLOC_H
12768 +#define SPRINTF_ALLOC_H
12769 +
12770 +#include "libbb.h"
12771 +
12772 +#define sprintf_alloc bb_xasprintf
12773 +
12774 +#endif
12775 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.c
12776 --- busybox-1.00-orig/archival/libipkg/str_list.c 1970-01-01 00:00:00.000000000 +0000
12777 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.c 2005-07-17 16:10:25.000000000 +0000
12778 @@ -0,0 +1,76 @@
12779 +/* str_list.c - the itsy package management system
12780 +
12781 + Carl D. Worth
12782 +
12783 + Copyright (C) 2001 University of Southern California
12784 +
12785 + This program is free software; you can redistribute it and/or
12786 + modify it under the terms of the GNU General Public License as
12787 + published by the Free Software Foundation; either version 2, or (at
12788 + your option) any later version.
12789 +
12790 + This program is distributed in the hope that it will be useful, but
12791 + WITHOUT ANY WARRANTY; without even the implied warranty of
12792 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12793 + General Public License for more details.
12794 +*/
12795 +
12796 +#include "ipkg.h"
12797 +
12798 +#include "str_list.h"
12799 +
12800 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12801 +{
12802 + return void_list_elt_init((void_list_elt_t *) elt, data);
12803 +}
12804 +
12805 +void str_list_elt_deinit(str_list_elt_t *elt)
12806 +{
12807 + void_list_elt_deinit((void_list_elt_t *) elt);
12808 +}
12809 +
12810 +str_list_t *str_list_alloc()
12811 +{
12812 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12813 + if (list)
12814 + str_list_init(list);
12815 + return list;
12816 +}
12817 +
12818 +int str_list_init(str_list_t *list)
12819 +{
12820 + return void_list_init((void_list_t *) list);
12821 +}
12822 +
12823 +void str_list_deinit(str_list_t *list)
12824 +{
12825 + void_list_deinit((void_list_t *) list);
12826 +}
12827 +
12828 +int str_list_append(str_list_t *list, char *data)
12829 +{
12830 + return void_list_append((void_list_t *) list, data);
12831 +}
12832 +
12833 +int str_list_push(str_list_t *list, char *data)
12834 +{
12835 + return void_list_push((void_list_t *) list, data);
12836 +}
12837 +
12838 +str_list_elt_t *str_list_pop(str_list_t *list)
12839 +{
12840 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12841 +}
12842 +
12843 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12844 +{
12845 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12846 + (void_list_elt_t **) iter);
12847 +}
12848 +
12849 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12850 +{
12851 + return (char *)void_list_remove_elt((void_list_t *) list,
12852 + (void *)target_str,
12853 + (void_list_cmp_t)strcmp);
12854 +}
12855 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.h
12856 --- busybox-1.00-orig/archival/libipkg/str_list.h 1970-01-01 00:00:00.000000000 +0000
12857 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.h 2005-07-17 16:10:25.000000000 +0000
12858 @@ -0,0 +1,51 @@
12859 +/* str_list.h - the itsy package management system
12860 +
12861 + Carl D. Worth
12862 +
12863 + Copyright (C) 2001 University of Southern California
12864 +
12865 + This program is free software; you can redistribute it and/or
12866 + modify it under the terms of the GNU General Public License as
12867 + published by the Free Software Foundation; either version 2, or (at
12868 + your option) any later version.
12869 +
12870 + This program is distributed in the hope that it will be useful, but
12871 + WITHOUT ANY WARRANTY; without even the implied warranty of
12872 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12873 + General Public License for more details.
12874 +*/
12875 +
12876 +#ifndef STR_LIST_H
12877 +#define STR_LIST_H
12878 +
12879 +#include "void_list.h"
12880 +
12881 +typedef struct str_list_elt str_list_elt_t;
12882 +struct str_list_elt
12883 +{
12884 + str_list_elt_t *next;
12885 + char *data;
12886 +};
12887 +
12888 +typedef struct xstr_list str_list_t;
12889 +struct xstr_list
12890 +{
12891 + str_list_elt_t pre_head;
12892 + str_list_elt_t *head;
12893 + str_list_elt_t *tail;
12894 +};
12895 +
12896 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12897 +void str_list_elt_deinit(str_list_elt_t *elt);
12898 +
12899 +str_list_t *str_list_alloc(void);
12900 +int str_list_init(str_list_t *list);
12901 +void str_list_deinit(str_list_t *list);
12902 +
12903 +int str_list_append(str_list_t *list, char *data);
12904 +int str_list_push(str_list_t *list, char *data);
12905 +str_list_elt_t *str_list_pop(str_list_t *list);
12906 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12907 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12908 +
12909 +#endif
12910 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.c
12911 --- busybox-1.00-orig/archival/libipkg/str_util.c 1970-01-01 00:00:00.000000000 +0000
12912 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.c 2005-07-17 16:10:25.000000000 +0000
12913 @@ -0,0 +1,73 @@
12914 +/* str_utils.c - the itsy package management system
12915 +
12916 + Carl D. Worth
12917 +
12918 + Copyright (C) 2001 University of Southern California
12919 +
12920 + This program is free software; you can redistribute it and/or
12921 + modify it under the terms of the GNU General Public License as
12922 + published by the Free Software Foundation; either version 2, or (at
12923 + your option) any later version.
12924 +
12925 + This program is distributed in the hope that it will be useful, but
12926 + WITHOUT ANY WARRANTY; without even the implied warranty of
12927 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12928 + General Public License for more details.
12929 +*/
12930 +
12931 +#include "ipkg.h"
12932 +
12933 +int str_starts_with(const char *str, const char *prefix)
12934 +{
12935 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12936 +}
12937 +
12938 +int str_ends_with(const char *str, const char *suffix)
12939 +{
12940 + int suffix_len;
12941 + int str_len;
12942 +
12943 + str_len = strlen(str);
12944 + suffix_len = strlen(suffix);
12945 +
12946 + if (str_len < suffix_len) {
12947 + return 0;
12948 + }
12949 +
12950 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12951 +}
12952 +
12953 +int str_chomp(char *str)
12954 +{
12955 + if (str[strlen(str) - 1] == '\n') {
12956 + str[strlen(str) - 1] = '\0';
12957 + return 1;
12958 + }
12959 + return 0;
12960 +}
12961 +
12962 +int str_tolower(char *str)
12963 +{
12964 + while (*str) {
12965 + *str = tolower(*str);
12966 + str++;
12967 + }
12968 +
12969 + return 0;
12970 +}
12971 +
12972 +int str_toupper(char *str)
12973 +{
12974 + while (*str) {
12975 + *str = toupper(*str);
12976 + str++;
12977 + }
12978 +
12979 + return 0;
12980 +}
12981 +
12982 +char *str_dup_safe(const char *str)
12983 +{
12984 + return str ? strdup(str) : NULL;
12985 +}
12986 +
12987 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.h
12988 --- busybox-1.00-orig/archival/libipkg/str_util.h 1970-01-01 00:00:00.000000000 +0000
12989 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.h 2005-07-17 16:10:25.000000000 +0000
12990 @@ -0,0 +1,28 @@
12991 +/* str_utils.h - the itsy package management system
12992 +
12993 + Carl D. Worth
12994 +
12995 + Copyright (C) 2001 University of Southern California
12996 +
12997 + This program is free software; you can redistribute it and/or
12998 + modify it under the terms of the GNU General Public License as
12999 + published by the Free Software Foundation; either version 2, or (at
13000 + your option) any later version.
13001 +
13002 + This program is distributed in the hope that it will be useful, but
13003 + WITHOUT ANY WARRANTY; without even the implied warranty of
13004 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13005 + General Public License for more details.
13006 +*/
13007 +
13008 +#ifndef STR_UTILS_H
13009 +#define STR_UTILS_H
13010 +
13011 +int str_starts_with(const char *str, const char *prefix);
13012 +int str_ends_with(const char *str, const char *suffix);
13013 +int str_chomp(char *str);
13014 +int str_tolower(char *str);
13015 +int str_toupper(char *str);
13016 +char *str_dup_safe(const char *str);
13017 +
13018 +#endif
13019 diff -ruN busybox-1.00-orig/archival/libipkg/user.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.c
13020 --- busybox-1.00-orig/archival/libipkg/user.c 1970-01-01 00:00:00.000000000 +0000
13021 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.c 2005-07-17 16:10:26.000000000 +0000
13022 @@ -0,0 +1,58 @@
13023 +/* user.c - the itsy package management system
13024 +
13025 + Jamey Hicks
13026 +
13027 + Copyright (C) 2002 Hewlett Packard Company
13028 + Copyright (C) 2001 University of Southern California
13029 +
13030 + This program is free software; you can redistribute it and/or
13031 + modify it under the terms of the GNU General Public License as
13032 + published by the Free Software Foundation; either version 2, or (at
13033 + your option) any later version.
13034 +
13035 + This program is distributed in the hope that it will be useful, but
13036 + WITHOUT ANY WARRANTY; without even the implied warranty of
13037 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13038 + General Public License for more details.
13039 +*/
13040 +
13041 +#include <stdio.h>
13042 +#include <stdarg.h>
13043 +#include "file_util.h"
13044 +#include "str_util.h"
13045 +#ifdef IPKG_LIB
13046 +#include "libipkg.h"
13047 +#endif
13048 +
13049 +
13050 +#ifdef IPKG_LIB
13051 +static char *question = NULL;
13052 +static int question_len = 255;
13053 +#endif
13054 +char *get_user_response(const char *format, ...)
13055 +{
13056 + int len = question_len;
13057 + va_list ap;
13058 + char *response;
13059 + va_start(ap, format);
13060 +
13061 +#ifndef IPKG_LIB
13062 + vprintf(format, ap);
13063 + do {
13064 + response = file_read_line_alloc(stdin);
13065 + } while (response == NULL);
13066 +#else
13067 + do {
13068 + if (question == NULL || len > question_len) {
13069 + question = realloc(question, len + 1);
13070 + question_len = len;
13071 + }
13072 + len = vsnprintf(question,question_len,format,ap);
13073 + } while (len > question_len);
13074 + response = strdup(ipkg_cb_response(question));
13075 +#endif
13076 + str_chomp(response);
13077 + str_tolower(response);
13078 +
13079 + return response;
13080 +}
13081 diff -ruN busybox-1.00-orig/archival/libipkg/user.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.h
13082 --- busybox-1.00-orig/archival/libipkg/user.h 1970-01-01 00:00:00.000000000 +0000
13083 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.h 2005-07-17 16:10:26.000000000 +0000
13084 @@ -0,0 +1,23 @@
13085 +/* user.c - the itsy package management system
13086 +
13087 + Jamey Hicks
13088 +
13089 + Copyright (C) 2002 Hewlett Packard Company
13090 + Copyright (C) 2001 University of Southern California
13091 +
13092 + This program is free software; you can redistribute it and/or
13093 + modify it under the terms of the GNU General Public License as
13094 + published by the Free Software Foundation; either version 2, or (at
13095 + your option) any later version.
13096 +
13097 + This program is distributed in the hope that it will be useful, but
13098 + WITHOUT ANY WARRANTY; without even the implied warranty of
13099 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13100 + General Public License for more details.
13101 +*/
13102 +
13103 +#include <stdio.h>
13104 +#include <stdarg.h>
13105 +
13106 +char *get_user_response(const char *format, ...);
13107 +
13108 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.c
13109 --- busybox-1.00-orig/archival/libipkg/void_list.c 1970-01-01 00:00:00.000000000 +0000
13110 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.c 2005-07-17 16:10:26.000000000 +0000
13111 @@ -0,0 +1,194 @@
13112 +/* void_list.c - the itsy package management system
13113 +
13114 + Carl D. Worth
13115 +
13116 + Copyright (C) 2001 University of Southern California
13117 +
13118 + This program is free software; you can redistribute it and/or
13119 + modify it under the terms of the GNU General Public License as
13120 + published by the Free Software Foundation; either version 2, or (at
13121 + your option) any later version.
13122 +
13123 + This program is distributed in the hope that it will be useful, but
13124 + WITHOUT ANY WARRANTY; without even the implied warranty of
13125 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13126 + General Public License for more details.
13127 +*/
13128 +
13129 +#include "ipkg.h"
13130 +#include <errno.h>
13131 +
13132 +#include "void_list.h"
13133 +
13134 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13135 +{
13136 + elt->next = NULL;
13137 + elt->data = data;
13138 +
13139 + return 0;
13140 +}
13141 +
13142 +void void_list_elt_deinit(void_list_elt_t *elt)
13143 +{
13144 + void_list_elt_init(elt, NULL);
13145 +}
13146 +
13147 +int void_list_init(void_list_t *list)
13148 +{
13149 + void_list_elt_init(&list->pre_head, NULL);
13150 + list->head = NULL;
13151 + list->pre_head.next = list->head;
13152 + list->tail = NULL;
13153 +
13154 + return 0;
13155 +}
13156 +
13157 +void void_list_deinit(void_list_t *list)
13158 +{
13159 + void_list_elt_t *elt;
13160 +
13161 + while (list->head) {
13162 + elt = void_list_pop(list);
13163 + void_list_elt_deinit(elt);
13164 + /* malloced in void_list_append */
13165 + free(elt);
13166 + }
13167 +}
13168 +
13169 +int void_list_append(void_list_t *list, void *data)
13170 +{
13171 + void_list_elt_t *elt;
13172 +
13173 + /* freed in void_list_deinit */
13174 + elt = malloc(sizeof(void_list_elt_t));
13175 + if (elt == NULL) {
13176 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13177 + return ENOMEM;
13178 + }
13179 +
13180 + void_list_elt_init(elt, data);
13181 +
13182 + if (list->tail) {
13183 + list->tail->next = elt;
13184 + list->tail = elt;
13185 + } else {
13186 + list->head = elt;
13187 + list->pre_head.next = list->head;
13188 + list->tail = elt;
13189 + }
13190 +
13191 + return 0;
13192 +}
13193 +
13194 +int void_list_push(void_list_t *list, void *data)
13195 +{
13196 + void_list_elt_t *elt;
13197 +
13198 + elt = malloc(sizeof(void_list_elt_t));
13199 + if (elt == NULL) {
13200 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13201 + return ENOMEM;
13202 + }
13203 +
13204 + void_list_elt_init(elt, data);
13205 +
13206 + elt->next = list->head;
13207 + list->head->next = elt;
13208 + if (list->tail == NULL) {
13209 + list->tail = list->head;
13210 + }
13211 +
13212 + return 0;
13213 +}
13214 +
13215 +void_list_elt_t *void_list_pop(void_list_t *list)
13216 +{
13217 + void_list_elt_t *elt;
13218 +
13219 + elt = list->head;
13220 +
13221 + if (list->head) {
13222 + list->head = list->head->next;
13223 + list->pre_head.next = list->head;
13224 + if (list->head == NULL) {
13225 + list->tail = NULL;
13226 + }
13227 + }
13228 +
13229 + return elt;
13230 +}
13231 +
13232 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13233 +{
13234 + void_list_elt_t *prior;
13235 + void_list_elt_t *old_elt;
13236 + void *old_data;
13237 +
13238 + old_elt = *iter;
13239 + old_data = old_elt->data;
13240 +
13241 + if (old_elt == list->head) {
13242 + prior = &list->pre_head;
13243 + void_list_pop(list);
13244 + } else {
13245 + for (prior = list->head; prior; prior = prior->next) {
13246 + if (prior->next == old_elt) {
13247 + break;
13248 + }
13249 + }
13250 + if (prior == NULL || prior->next != old_elt) {
13251 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13252 + return NULL;
13253 + }
13254 + prior->next = old_elt->next;
13255 +
13256 + if (old_elt == list->tail) {
13257 + list->tail = prior;
13258 + }
13259 + }
13260 +
13261 + void_list_elt_deinit(old_elt);
13262 + *iter = prior;
13263 +
13264 + return old_data;
13265 +}
13266 +
13267 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13268 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13269 +{
13270 + void_list_elt_t *prior;
13271 + void_list_elt_t *old_elt = NULL;
13272 + void *old_data = NULL;
13273 +
13274 + /* first element */
13275 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13276 + old_elt = list->head;
13277 + old_data = list->head->data;
13278 + void_list_pop(list);
13279 + } else {
13280 + int found = 0;
13281 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13282 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13283 + old_elt = prior->next;
13284 + old_data = old_elt->data;
13285 + found = 1;
13286 + break;
13287 + }
13288 + }
13289 + if (!found) {
13290 + return NULL;
13291 + }
13292 + prior->next = old_elt->next;
13293 +
13294 + if (old_elt == list->tail) {
13295 + list->tail = prior;
13296 + }
13297 + }
13298 + if (old_elt)
13299 + void_list_elt_deinit(old_elt);
13300 +
13301 + if (old_data)
13302 + return old_data;
13303 + else
13304 + return NULL;
13305 +}
13306 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.h
13307 --- busybox-1.00-orig/archival/libipkg/void_list.h 1970-01-01 00:00:00.000000000 +0000
13308 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.h 2005-07-17 16:10:26.000000000 +0000
13309 @@ -0,0 +1,59 @@
13310 +/* void_list.h - the itsy package management system
13311 +
13312 + Carl D. Worth
13313 +
13314 + Copyright (C) 2001 University of Southern California
13315 +
13316 + This program is free software; you can redistribute it and/or
13317 + modify it under the terms of the GNU General Public License as
13318 + published by the Free Software Foundation; either version 2, or (at
13319 + your option) any later version.
13320 +
13321 + This program is distributed in the hope that it will be useful, but
13322 + WITHOUT ANY WARRANTY; without even the implied warranty of
13323 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13324 + General Public License for more details.
13325 +*/
13326 +
13327 +#ifndef VOID_LIST_H
13328 +#define VOID_LIST_H
13329 +
13330 +typedef struct void_list_elt void_list_elt_t;
13331 +struct void_list_elt
13332 +{
13333 + void_list_elt_t *next;
13334 + void *data;
13335 +};
13336 +
13337 +typedef struct void_list void_list_t;
13338 +struct void_list
13339 +{
13340 + void_list_elt_t pre_head;
13341 + void_list_elt_t *head;
13342 + void_list_elt_t *tail;
13343 +};
13344 +
13345 +static inline int void_list_empty(void_list_t *list)
13346 +{
13347 + if (list->head == NULL)
13348 + return 1;
13349 + else
13350 + return 0;
13351 +}
13352 +
13353 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13354 +void void_list_elt_deinit(void_list_elt_t *elt);
13355 +
13356 +int void_list_init(void_list_t *list);
13357 +void void_list_deinit(void_list_t *list);
13358 +
13359 +int void_list_append(void_list_t *list, void *data);
13360 +int void_list_push(void_list_t *list, void *data);
13361 +void_list_elt_t *void_list_pop(void_list_t *list);
13362 +
13363 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13364 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13365 +typedef int (*void_list_cmp_t)(const void *, const void *);
13366 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13367 +
13368 +#endif
13369 diff -ruN busybox-1.00-orig/archival/libipkg/xregex.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xregex.h
13370 --- busybox-1.00-orig/archival/libipkg/xregex.h 1970-01-01 00:00:00.000000000 +0000
13371 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xregex.h 2005-07-20 17:28:42.773482376 +0000
13372 @@ -0,0 +1,29 @@
13373 +/* xregex.h - regex functions with error messages
13374 +
13375 + Carl D. Worth
13376 +
13377 + Copyright (C) 2001 University of Southern California
13378 +
13379 + This program is free software; you can redistribute it and/or modify
13380 + it under the terms of the GNU General Public License as published by
13381 + the Free Software Foundation; either version 2, or (at your option)
13382 + any later version.
13383 +
13384 + This program is distributed in the hope that it will be useful,
13385 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13386 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13387 + GNU General Public License for more details.
13388 +*/
13389 +
13390 +#ifndef XREGEX_H
13391 +#define XREGEX_H
13392 +
13393 +#include "libbb.h"
13394 +
13395 +static inline void xregfree(regex_t *preg)
13396 +{
13397 + regfree(preg);
13398 +}
13399 +
13400 +
13401 +#endif
13402 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.c
13403 --- busybox-1.00-orig/archival/libipkg/xsystem.c 1970-01-01 00:00:00.000000000 +0000
13404 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.c 2005-07-17 16:10:26.000000000 +0000
13405 @@ -0,0 +1,64 @@
13406 +/* xsystem.c - system(3) with error messages
13407 +
13408 + Carl D. Worth
13409 +
13410 + Copyright (C) 2001 University of Southern California
13411 +
13412 + This program is free software; you can redistribute it and/or
13413 + modify it under the terms of the GNU General Public License as
13414 + published by the Free Software Foundation; either version 2, or (at
13415 + your option) any later version.
13416 +
13417 + This program is distributed in the hope that it will be useful, but
13418 + WITHOUT ANY WARRANTY; without even the implied warranty of
13419 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13420 + General Public License for more details.
13421 +*/
13422 +
13423 +#include "ipkg.h"
13424 +#include <sys/wait.h>
13425 +
13426 +#include "xsystem.h"
13427 +
13428 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13429 + really need the /bin/sh invocation which takes resources and
13430 + introduces security problems. I should switch all of this to a sort
13431 + of execl() or execv() interface/implementation.
13432 +*/
13433 +
13434 +/* Like system(3), but with error messages printed if the fork fails
13435 + or if the child process dies due to an uncaught signal. Also, the
13436 + return value is a bit simpler:
13437 +
13438 + -1 if there was any problem
13439 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13440 + as defined in <sys/wait.h>.
13441 +*/
13442 +int xsystem(const char *cmd)
13443 +{
13444 + int err;
13445 +
13446 + err = system(cmd);
13447 +
13448 + if (err == -1) {
13449 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13450 + __FUNCTION__, cmd);
13451 + return -1;
13452 + }
13453 +
13454 + if (WIFSIGNALED(err)) {
13455 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13456 + __FUNCTION__, WTERMSIG(err), cmd);
13457 + return -1;
13458 + }
13459 +
13460 + if (WIFEXITED(err)) {
13461 + /* Normal child exit */
13462 + return WEXITSTATUS(err);
13463 + }
13464 +
13465 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13466 + __FUNCTION__, err);
13467 + return -1;
13468 +}
13469 +
13470 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.h
13471 --- busybox-1.00-orig/archival/libipkg/xsystem.h 1970-01-01 00:00:00.000000000 +0000
13472 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.h 2005-07-17 16:10:26.000000000 +0000
13473 @@ -0,0 +1,34 @@
13474 +/* xsystem.h - system(3) with error messages
13475 +
13476 + Carl D. Worth
13477 +
13478 + Copyright (C) 2001 University of Southern California
13479 +
13480 + This program is free software; you can redistribute it and/or
13481 + modify it under the terms of the GNU General Public License as
13482 + published by the Free Software Foundation; either version 2, or (at
13483 + your option) any later version.
13484 +
13485 + This program is distributed in the hope that it will be useful, but
13486 + WITHOUT ANY WARRANTY; without even the implied warranty of
13487 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13488 + General Public License for more details.
13489 +*/
13490 +
13491 +#ifndef XSYSTEM_H
13492 +#define XSYSTEM_H
13493 +
13494 +#include <stdlib.h>
13495 +
13496 +/* Like system(3), but with error messages printed if the fork fails
13497 + or if the child process dies due to an uncaught signal. Also, the
13498 + return value is a bit simpler:
13499 +
13500 + -1 if there was any problem
13501 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13502 + as defined in <sys/wait.h>.
13503 +*/
13504 +int xsystem(const char *cmd);
13505 +
13506 +#endif
13507 +
13508 diff -ruN busybox-1.00-orig/archival/libunarchive/data_extract_all.c busybox-1.00+ipkg-0.99.152-pre2/archival/libunarchive/data_extract_all.c
13509 --- busybox-1.00-orig/archival/libunarchive/data_extract_all.c 2004-10-13 06:25:51.000000000 +0000
13510 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libunarchive/data_extract_all.c 2005-07-20 00:02:41.000000000 +0000
13511 @@ -122,3 +122,17 @@
13512 utime(file_header->name, &t);
13513 }
13514 }
13515 +
13516 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13517 +{
13518 + char *name_ptr = archive_handle->file_header->name;
13519 +
13520 + name_ptr += strspn(name_ptr, "./");
13521 + if (name_ptr[0] != '\0') {
13522 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13523 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13524 + strcat(archive_handle->file_header->name, name_ptr);
13525 + data_extract_all(archive_handle);
13526 + }
13527 +}
13528 +
13529 diff -ruN busybox-1.00-orig/include/applets.h busybox-1.00+ipkg-0.99.152-pre2/include/applets.h
13530 --- busybox-1.00-orig/include/applets.h 2005-07-20 13:09:57.000000000 +0000
13531 +++ busybox-1.00+ipkg-0.99.152-pre2/include/applets.h 2005-07-17 16:29:18.000000000 +0000
13532 @@ -298,6 +298,9 @@
13533 #ifdef CONFIG_IPCALC
13534 APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13535 #endif
13536 +#ifdef CONFIG_IPKG
13537 + APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
13538 +#endif
13539 #ifdef CONFIG_IPLINK
13540 APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13541 #endif
13542 diff -ruN busybox-1.00-orig/include/libbb.h busybox-1.00+ipkg-0.99.152-pre2/include/libbb.h
13543 --- busybox-1.00-orig/include/libbb.h 2004-09-15 03:04:07.000000000 +0000
13544 +++ busybox-1.00+ipkg-0.99.152-pre2/include/libbb.h 2005-07-20 17:13:46.442745360 +0000
13545 @@ -484,4 +484,17 @@
13546 #define HASH_MD5 2
13547 extern int hash_fd(int fd, const size_t size, const uint8_t hash_algo, uint8_t *hashval);
13548
13549 +struct md5_ctx_t {
13550 + uint32_t A;
13551 + uint32_t B;
13552 + uint32_t C;
13553 + uint32_t D;
13554 + uint32_t total[2];
13555 + uint32_t buflen;
13556 + char buffer[128];
13557 +};
13558 +extern void md5_begin(struct md5_ctx_t *ctx);
13559 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx);
13560 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
13561 +
13562 #endif /* __LIBCONFIG_H__ */
13563 diff -ruN busybox-1.00-orig/include/unarchive.h busybox-1.00+ipkg-0.99.152-pre2/include/unarchive.h
13564 --- busybox-1.00-orig/include/unarchive.h 2004-03-15 08:28:38.000000000 +0000
13565 +++ busybox-1.00+ipkg-0.99.152-pre2/include/unarchive.h 2005-07-19 16:40:11.000000000 +0000
13566 @@ -72,6 +72,7 @@
13567
13568 extern void data_skip(archive_handle_t *archive_handle);
13569 extern void data_extract_all(archive_handle_t *archive_handle);
13570 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13571 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13572 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13573
13574 diff -ruN busybox-1.00-orig/include/usage.h busybox-1.00+ipkg-0.99.152-pre2/include/usage.h
13575 --- busybox-1.00-orig/include/usage.h 2005-07-20 13:09:58.000000000 +0000
13576 +++ busybox-1.00+ipkg-0.99.152-pre2/include/usage.h 2005-07-20 09:33:45.367746000 +0000
13577 @@ -836,6 +836,82 @@
13578 "$ ls -la /tmp/busybox*\n" \
13579 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13580
13581 +#define ipkg_trivial_usage \
13582 + "[options...] sub-command [arguments...]"
13583 +#define ipkg_full_usage \
13584 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13585 + "\n" \
13586 + "Sub-commands:\n" \
13587 + "\nPackage Manipulation:\n" \
13588 + "\tupdate Update list of available packages\n" \
13589 + "\tupgrade Upgrade all installed packages to latest version\n" \
13590 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13591 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13592 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13593 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13594 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13595 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13596 + "\n" \
13597 + "Informational Commands:\n" \
13598 + "\tlist List available packages and descriptions\n" \
13599 + "\tlist_installed List all and only the installed packages and description \n" \
13600 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13601 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13602 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13603 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13604 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13605 + "\tcompare_versions <v1> <op> <v2>\n" \
13606 + "\t compare versions using <= < > >= = << >>\n" \
13607 + "\tprint_architecture prints the architecture.\n" \
13608 + "\tprint_installation_architecture\n" \
13609 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13610 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13611 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13612 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13613 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13614 + "\t prints the installation architecture.\n" \
13615 + "\n" \
13616 + "\nOptions:\n" \
13617 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13618 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13619 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13620 + "\t 0 errors only\n" \
13621 + "\t 1 normal messages (default)\n" \
13622 + "\t 2 informative messages\n" \
13623 + "\t 3 debug output\n" \
13624 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13625 + "\t-conf <conf_file> Default configuration file location\n" \
13626 + " is /etc/ipkg.conf\n" \
13627 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13628 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13629 + " <dest_name> should be a defined dest name from\n" \
13630 + " the configuration file, (but can also be a\n" \
13631 + " directory name in a pinch).\n" \
13632 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13633 + "\t-offline <offline_root> offline installation of packages.\n" \
13634 + "\t-verbose_wget more wget messages\n" \
13635 + "\n" \
13636 + "Force Options (use when ipkg is too smart for its own good):\n" \
13637 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13638 + "\t Install/remove package in spite of failed dependences\n" \
13639 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13640 + " (no prompts). Note that this will not prevent\n" \
13641 + " package installation scripts from prompting.\n" \
13642 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13643 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13644 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13645 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13646 + "\t-noaction No action -- test only\n" \
13647 + "\t-nodeps Do not follow dependences\n" \
13648 + "\t-force-removal-of-dependent-packages\n" \
13649 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13650 + "\t-test No action -- test only\n" \
13651 + "\t-t Specify tmp-dir.\n" \
13652 + "\t--tmp-dir Specify tmp-dir.\n" \
13653 + "\n" \
13654 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13655 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13656 +
13657 #define halt_trivial_usage \
13658 "[-d<delay>]"
13659 #define halt_full_usage \
13660 diff -ruN busybox-1.00-orig/libbb/hash_fd.c busybox-1.00+ipkg-0.99.152-pre2/libbb/hash_fd.c
13661 --- busybox-1.00-orig/libbb/hash_fd.c 2004-03-15 08:28:42.000000000 +0000
13662 +++ busybox-1.00+ipkg-0.99.152-pre2/libbb/hash_fd.c 2005-07-20 17:13:48.129488936 +0000
13663 @@ -288,21 +288,10 @@
13664 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
13665 # endif /* MD5SUM_SIZE_VS_SPEED == 0 */
13666
13667 -/* Structure to save state of computation between the single steps. */
13668 -struct md5_ctx_t {
13669 - uint32_t A;
13670 - uint32_t B;
13671 - uint32_t C;
13672 - uint32_t D;
13673 - uint32_t total[2];
13674 - uint32_t buflen;
13675 - char buffer[128];
13676 -};
13677 -
13678 /* Initialize structure containing state of computation.
13679 * (RFC 1321, 3.3: Step 3)
13680 */
13681 -static void md5_begin(struct md5_ctx_t *ctx)
13682 +extern void md5_begin(struct md5_ctx_t *ctx)
13683 {
13684 ctx->A = 0x67452301;
13685 ctx->B = 0xefcdab89;
13686 @@ -706,7 +695,7 @@
13687 }
13688 }
13689
13690 -static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13691 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13692 {
13693 if (length % 64 == 0) {
13694 md5_hash_block(buffer, length, md5_ctx);
13695 @@ -723,7 +712,7 @@
13696 * IMPORTANT: On some systems it is required that RESBUF is correctly
13697 * aligned for a 32 bits value.
13698 */
13699 -static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13700 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13701 {
13702 /* Take yet unprocessed bytes into account. */
13703 uint32_t bytes = ctx->buflen;
This page took 0.745622 seconds and 5 git commands to generate.