Remove autodection of hesiod since it will be enabled by default if present on host...
[openwrt.git] / package / busybox / patches / 911-ipkg.patch
1 diff -ruN busybox-1.1.1-old/Makefile busybox-1.1.1-new/Makefile
2 --- busybox-1.1.1-old/Makefile 2006-03-22 22:16:26.000000000 +0100
3 +++ busybox-1.1.1-new/Makefile 2006-03-30 00:39:48.000000000 +0200
4 @@ -25,7 +25,7 @@
5 export srctree=$(top_srcdir)
6 vpath %/Config.in $(srctree)
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 e2fsprogs libpwdgrp coreutils/libcoreutils libbb
13 diff -ruN busybox-1.1.1-old/archival/Config.in busybox-1.1.1-new/archival/Config.in
14 --- busybox-1.1.1-old/archival/Config.in 2006-03-22 22:16:20.000000000 +0100
15 +++ busybox-1.1.1-new/archival/Config.in 2006-03-30 00:39:48.000000000 +0200
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.1.1-old/archival/Makefile.in busybox-1.1.1-new/archival/Makefile.in
32 --- busybox-1.1.1-old/archival/Makefile.in 2006-03-22 22:16:20.000000000 +0100
33 +++ busybox-1.1.1-new/archival/Makefile.in 2006-03-30 00:39:48.000000000 +0200
34 @@ -20,6 +20,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.1.1-old/archival/dpkg.c busybox-1.1.1-new/archival/dpkg.c
43 --- busybox-1.1.1-old/archival/dpkg.c 2006-03-22 22:16:20.000000000 +0100
44 +++ busybox-1.1.1-new/archival/dpkg.c 2006-03-30 00:39:48.000000000 +0200
45 @@ -1530,6 +1530,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 @@ -1544,6 +1548,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.1.1-old/archival/ipkg.c busybox-1.1.1-new/archival/ipkg.c
66 --- busybox-1.1.1-old/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
67 +++ busybox-1.1.1-new/archival/ipkg.c 2006-03-30 00:39:48.000000000 +0200
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.1.1-old/archival/libipkg/Makefile busybox-1.1.1-new/archival/libipkg/Makefile
96 --- busybox-1.1.1-old/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
97 +++ busybox-1.1.1-new/archival/libipkg/Makefile 2006-03-30 00:39:48.000000000 +0200
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.1.1-old/archival/libipkg/Makefile.in busybox-1.1.1-new/archival/libipkg/Makefile.in
132 --- busybox-1.1.1-old/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
133 +++ busybox-1.1.1-new/archival/libipkg/Makefile.in 2006-03-30 01:14:50.000000000 +0200
134 @@ -0,0 +1,85 @@
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 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
211 +
212 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
213 +
214 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
215 + $(do_ar)
216 +
217 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
218 + $(compile.c)
219 +
220 diff -ruN busybox-1.1.1-old/archival/libipkg/args.c busybox-1.1.1-new/archival/libipkg/args.c
221 --- busybox-1.1.1-old/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
222 +++ busybox-1.1.1-new/archival/libipkg/args.c 2006-03-30 00:39:48.000000000 +0200
223 @@ -0,0 +1,241 @@
224 +/* args.c - parse command-line args
225 +
226 + Carl D. Worth
227 +
228 + Copyright 2001 University of Southern California
229 +
230 + This program is free software; you can redistribute it and/or modify
231 + it under the terms of the GNU General Public License as published by
232 + the Free Software Foundation; either version 2, or (at your option)
233 + any later version.
234 +
235 + This program is distributed in the hope that it will be useful,
236 + but WITHOUT ANY WARRANTY; without even the implied warranty of
237 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238 + GNU General Public License for more details.
239 + */
240 +
241 +#include <getopt.h>
242 +#include <stdlib.h>
243 +#include <string.h>
244 +#include <unistd.h>
245 +
246 +#include "ipkg.h"
247 +#include "ipkg_message.h"
248 +
249 +#include "args.h"
250 +#include "sprintf_alloc.h"
251 +
252 +#include "libbb.h"
253 +
254 +
255 +static void print_version(void);
256 +
257 +enum long_args_opt
258 +{
259 + ARGS_OPT_FORCE_DEFAULTS = 129,
260 + ARGS_OPT_FORCE_DEPENDS,
261 + ARGS_OPT_FORCE_OVERWRITE,
262 + ARGS_OPT_FORCE_DOWNGRADE,
263 + ARGS_OPT_FORCE_REINSTALL,
264 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
265 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
266 + ARGS_OPT_FORCE_SPACE,
267 + ARGS_OPT_NOACTION,
268 + ARGS_OPT_NODEPS,
269 + ARGS_OPT_VERBOSE_WGET,
270 + ARGS_OPT_VERBOSITY,
271 + ARGS_OPT_MULTIPLE_PROVIDERS
272 +};
273 +
274 +int args_init(args_t *args)
275 +{
276 + char *conf_file_dir;
277 +
278 + memset(args, 0, sizeof(args_t));
279 +
280 + args->dest = ARGS_DEFAULT_DEST;
281 +
282 + conf_file_dir = getenv("IPKG_CONF_DIR");
283 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
284 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
285 + }
286 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
287 + ARGS_DEFAULT_CONF_FILE_NAME);
288 +
289 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
290 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
291 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
292 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
293 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
294 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
295 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
296 + args->noaction = ARGS_DEFAULT_NOACTION;
297 + args->nodeps = ARGS_DEFAULT_NODEPS;
298 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
299 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
300 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
301 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
302 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
303 + args->multiple_providers = 0;
304 + args->nocheckfordirorfile = 0;
305 +
306 + return 1;
307 +}
308 +
309 +void args_deinit(args_t *args)
310 +{
311 + free(args->conf_file);
312 + args->conf_file = NULL;
313 +}
314 +
315 +int args_parse(args_t *args, int argc, char *argv[])
316 +{
317 + int c;
318 + int option_index = 0;
319 + int parse_err = 0;
320 + static struct option long_options[] = {
321 + {"query-all", 0, 0, 'A'},
322 + {"conf-file", 1, 0, 'f'},
323 + {"conf", 1, 0, 'f'},
324 + {"dest", 1, 0, 'd'},
325 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
326 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
327 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
328 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
329 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
330 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
331 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
332 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
333 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
334 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
335 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
336 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
337 + {"recursive", 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_dependent_packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
343 + {"force-removal-of-essential-packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"force_removal_of_essential_packages", 0, 0,
346 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
347 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
348 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
349 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
350 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
351 + {"offline", 1, 0, 'o'},
352 + {"offline-root", 1, 0, 'o'},
353 + {"test", 0, 0, ARGS_OPT_NOACTION},
354 + {"tmp-dir", 1, 0, 't'},
355 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
356 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
357 + {"verbosity", 2, 0, 'V'},
358 + {"version", 0, 0, 'v'},
359 + {0, 0, 0, 0}
360 + };
361 +
362 + while (1) {
363 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
364 + if (c == -1)
365 + break;
366 +
367 + switch (c) {
368 + case 'A':
369 + args->query_all = 1;
370 + break;
371 + case 'd':
372 + args->dest = optarg;
373 + break;
374 + case 'f':
375 + free(args->conf_file);
376 + args->conf_file = strdup(optarg);
377 + break;
378 + case 'o':
379 + args->offline_root = optarg;
380 + break;
381 + case 'n':
382 + args->noaction = 1;
383 + break;
384 + case 't':
385 + args->tmp_dir = strdup(optarg);
386 + break;
387 + case 'v':
388 + print_version();
389 + exit(0);
390 + case 'V':
391 + case ARGS_OPT_VERBOSITY:
392 + if (optarg)
393 + args->verbosity = atoi(optarg);
394 + else
395 + args->verbosity += 1;
396 + break;
397 + case ARGS_OPT_FORCE_DEFAULTS:
398 + args->force_defaults = 1;
399 + break;
400 + case ARGS_OPT_FORCE_DEPENDS:
401 + args->force_depends = 1;
402 + break;
403 + case ARGS_OPT_FORCE_OVERWRITE:
404 + args->force_overwrite = 1;
405 + break;
406 + case ARGS_OPT_FORCE_DOWNGRADE:
407 + args->force_downgrade = 1;
408 + break;
409 + case ARGS_OPT_FORCE_REINSTALL:
410 + args->force_reinstall = 1;
411 + break;
412 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
413 + args->force_removal_of_essential_packages = 1;
414 + break;
415 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
416 + args->force_removal_of_dependent_packages = 1;
417 + break;
418 + case ARGS_OPT_FORCE_SPACE:
419 + args->force_space = 1;
420 + break;
421 + case ARGS_OPT_VERBOSE_WGET:
422 + args->verbose_wget = 1;
423 + break;
424 + case ARGS_OPT_MULTIPLE_PROVIDERS:
425 + args->multiple_providers = 1;
426 + break;
427 + case ARGS_OPT_NODEPS:
428 + args->nodeps = 1;
429 + break;
430 + case ARGS_OPT_NOACTION:
431 + args->noaction = 1;
432 + break;
433 + case ':':
434 + parse_err++;
435 + break;
436 + case '?':
437 + parse_err++;
438 + break;
439 + default:
440 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
441 + }
442 + }
443 +
444 + if (parse_err) {
445 + return -parse_err;
446 + } else {
447 + return optind;
448 + }
449 +}
450 +
451 +void args_usage(char *complaint)
452 +{
453 + if (complaint) {
454 + bb_error_msg("%s\n", complaint);
455 + }
456 + print_version();
457 + bb_show_usage();
458 + exit(1);
459 +}
460 +
461 +static void print_version(void)
462 +{
463 + bb_error_msg("version %s\n", IPKG_VERSION);
464 +}
465 diff -ruN busybox-1.1.1-old/archival/libipkg/args.h busybox-1.1.1-new/archival/libipkg/args.h
466 --- busybox-1.1.1-old/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
467 +++ busybox-1.1.1-new/archival/libipkg/args.h 2006-03-30 00:39:48.000000000 +0200
468 @@ -0,0 +1,71 @@
469 +/* args.h - parse command-line args
470 +
471 + Carl D. Worth
472 +
473 + Copyright 2001 University of Southern California
474 +
475 + This program is free software; you can redistribute it and/or modify
476 + it under the terms of the GNU General Public License as published by
477 + the Free Software Foundation; either version 2, or (at your option)
478 + any later version.
479 +
480 + This program is distributed in the hope that it will be useful,
481 + but WITHOUT ANY WARRANTY; without even the implied warranty of
482 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
483 + GNU General Public License for more details.
484 +*/
485 +
486 +#ifndef ARGS_H
487 +#define ARGS_H
488 +
489 +struct args
490 +{
491 + char *conf_file;
492 + char *dest;
493 + char *tmp_dir;
494 + int force_defaults;
495 + int force_depends;
496 + int force_overwrite;
497 + int force_downgrade;
498 + int force_reinstall;
499 + int force_removal_of_essential_packages;
500 + int force_removal_of_dependent_packages;
501 + int force_space;
502 + int noaction;
503 + int nodeps;
504 + int multiple_providers;
505 + int query_all;
506 + int verbose_wget;
507 + int verbosity;
508 + int nocheckfordirorfile;
509 + char *offline_root;
510 + char *offline_root_pre_script_cmd;
511 + char *offline_root_post_script_cmd;
512 +};
513 +typedef struct args args_t;
514 +
515 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
516 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
517 +#define ARGS_DEFAULT_DEST NULL
518 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
519 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
520 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
521 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
522 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
523 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
524 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
525 +#define ARGS_DEFAULT_FORCE_SPACE 0
526 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
527 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
528 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
529 +#define ARGS_DEFAULT_NOACTION 0
530 +#define ARGS_DEFAULT_NODEPS 0
531 +#define ARGS_DEFAULT_VERBOSE_WGET 0
532 +#define ARGS_DEFAULT_VERBOSITY 1
533 +
534 +int args_init(args_t *args);
535 +void args_deinit(args_t *args);
536 +int args_parse(args_t *args, int argc, char *argv[]);
537 +void args_usage(char *complaint);
538 +
539 +#endif
540 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.c busybox-1.1.1-new/archival/libipkg/conffile.c
541 --- busybox-1.1.1-old/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
542 +++ busybox-1.1.1-new/archival/libipkg/conffile.c 2006-03-30 00:39:48.000000000 +0200
543 @@ -0,0 +1,64 @@
544 +/* conffile.c - the itsy package management system
545 +
546 + Carl D. Worth
547 +
548 + Copyright (C) 2001 University of Southern California
549 +
550 + This program is free software; you can redistribute it and/or
551 + modify it under the terms of the GNU General Public License as
552 + published by the Free Software Foundation; either version 2, or (at
553 + your option) any later version.
554 +
555 + This program is distributed in the hope that it will be useful, but
556 + WITHOUT ANY WARRANTY; without even the implied warranty of
557 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
558 + General Public License for more details.
559 +*/
560 +
561 +#include <string.h>
562 +#include <stdlib.h>
563 +
564 +#include "ipkg.h"
565 +#include "ipkg_message.h"
566 +
567 +#include "conffile.h"
568 +#include "file_util.h"
569 +#include "sprintf_alloc.h"
570 +
571 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
572 +{
573 + return nv_pair_init(conffile, file_name, md5sum);
574 +}
575 +
576 +void conffile_deinit(conffile_t *conffile)
577 +{
578 + nv_pair_deinit(conffile);
579 +}
580 +
581 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
582 +{
583 + char *md5sum;
584 + char *filename = conffile->name;
585 + char *root_filename;
586 + int ret;
587 +
588 + if (conffile->value == NULL) {
589 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
590 + return 1;
591 + }
592 +
593 + root_filename = root_filename_alloc(conf, filename);
594 +
595 + md5sum = file_md5sum_alloc(root_filename);
596 +
597 + ret = strcmp(md5sum, conffile->value);
598 + if (ret) {
599 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
600 + conffile->name, md5sum, conffile->value);
601 + }
602 +
603 + free(root_filename);
604 + free(md5sum);
605 +
606 + return ret;
607 +}
608 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.h busybox-1.1.1-new/archival/libipkg/conffile.h
609 --- busybox-1.1.1-old/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
610 +++ busybox-1.1.1-new/archival/libipkg/conffile.h 2006-03-30 00:39:48.000000000 +0200
611 @@ -0,0 +1,30 @@
612 +/* conffile.h - the itsy package management system
613 +
614 + Carl D. Worth
615 +
616 + Copyright (C) 2001 University of Southern California
617 +
618 + This program is free software; you can redistribute it and/or
619 + modify it under the terms of the GNU General Public License as
620 + published by the Free Software Foundation; either version 2, or (at
621 + your option) any later version.
622 +
623 + This program is distributed in the hope that it will be useful, but
624 + WITHOUT ANY WARRANTY; without even the implied warranty of
625 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
626 + General Public License for more details.
627 +*/
628 +
629 +#ifndef CONFFILE_H
630 +#define CONFFILE_H
631 +
632 +#include "nv_pair.h"
633 +
634 +typedef struct nv_pair conffile_t;
635 +
636 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
637 +void conffile_deinit(conffile_t *conffile);
638 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
639 +
640 +#endif
641 +
642 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.c busybox-1.1.1-new/archival/libipkg/conffile_list.c
643 --- busybox-1.1.1-old/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
644 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.c 2006-03-30 00:39:48.000000000 +0200
645 @@ -0,0 +1,47 @@
646 +/* conffile_list.c - the itsy package management system
647 +
648 + Carl D. Worth
649 +
650 + Copyright (C) 2001 University of Southern California
651 +
652 + This program is free software; you can redistribute it and/or
653 + modify it under the terms of the GNU General Public License as
654 + published by the Free Software Foundation; either version 2, or (at
655 + your option) any later version.
656 +
657 + This program is distributed in the hope that it will be useful, but
658 + WITHOUT ANY WARRANTY; without even the implied warranty of
659 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
660 + General Public License for more details.
661 +*/
662 +
663 +#include "ipkg.h"
664 +
665 +#include "conffile_list.h"
666 +
667 +int conffile_list_init(conffile_list_t *list)
668 +{
669 + return nv_pair_list_init(list);
670 +}
671 +
672 +void conffile_list_deinit(conffile_list_t *list)
673 +{
674 + nv_pair_list_deinit(list);
675 +}
676 +
677 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
678 + const char *md5sum)
679 +{
680 + return nv_pair_list_append(list, file_name, md5sum);
681 +}
682 +
683 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
684 +{
685 + return nv_pair_list_push(list, data);
686 +}
687 +
688 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
689 +{
690 + return nv_pair_list_pop(list);
691 +}
692 +
693 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.h busybox-1.1.1-new/archival/libipkg/conffile_list.h
694 --- busybox-1.1.1-old/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
695 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.h 2006-03-30 00:39:48.000000000 +0200
696 @@ -0,0 +1,36 @@
697 +/* conffile_list.h - the itsy package management system
698 +
699 + Carl D. Worth
700 +
701 + Copyright (C) 2001 University of Southern California
702 +
703 + This program is free software; you can redistribute it and/or
704 + modify it under the terms of the GNU General Public License as
705 + published by the Free Software Foundation; either version 2, or (at
706 + your option) any later version.
707 +
708 + This program is distributed in the hope that it will be useful, but
709 + WITHOUT ANY WARRANTY; without even the implied warranty of
710 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
711 + General Public License for more details.
712 +*/
713 +
714 +#ifndef CONFFILE_LIST_H
715 +#define CONFFILE_LIST_H
716 +
717 +#include "conffile.h"
718 +#include "nv_pair_list.h"
719 +
720 +typedef struct nv_pair_list_elt conffile_list_elt_t;
721 +typedef struct nv_pair_list conffile_list_t;
722 +
723 +int conffile_list_init(conffile_list_t *list);
724 +void conffile_list_deinit(conffile_list_t *list);
725 +
726 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
727 + const char *root_dir);
728 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
729 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
730 +
731 +#endif
732 +
733 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.c busybox-1.1.1-new/archival/libipkg/file_util.c
734 --- busybox-1.1.1-old/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
735 +++ busybox-1.1.1-new/archival/libipkg/file_util.c 2006-03-30 00:39:48.000000000 +0200
736 @@ -0,0 +1,177 @@
737 +/* file_util.c - convenience routines for common stat operations
738 +
739 + Carl D. Worth
740 +
741 + Copyright (C) 2001 University of Southern California
742 +
743 + This program is free software; you can redistribute it and/or
744 + modify it under the terms of the GNU General Public License as
745 + published by the Free Software Foundation; either version 2, or (at
746 + your option) any later version.
747 +
748 + This program is distributed in the hope that it will be useful, but
749 + WITHOUT ANY WARRANTY; without even the implied warranty of
750 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
751 + General Public License for more details.
752 +*/
753 +
754 +#include "ipkg.h"
755 +#include <sys/types.h>
756 +#include <sys/stat.h>
757 +
758 +#include "sprintf_alloc.h"
759 +#include "file_util.h"
760 +#include "md5.h"
761 +#include "libbb.h"
762 +#undef strlen
763 +
764 +int file_exists(const char *file_name)
765 +{
766 + int err;
767 + struct stat stat_buf;
768 +
769 + err = stat(file_name, &stat_buf);
770 + if (err == 0) {
771 + return 1;
772 + } else {
773 + return 0;
774 + }
775 +}
776 +
777 +int file_is_dir(const char *file_name)
778 +{
779 + int err;
780 + struct stat stat_buf;
781 +
782 + err = stat(file_name, &stat_buf);
783 + if (err) {
784 + return 0;
785 + }
786 +
787 + return S_ISDIR(stat_buf.st_mode);
788 +}
789 +
790 +/* read a single line from a file, stopping at a newline or EOF.
791 + If a newline is read, it will appear in the resulting string.
792 + Return value is a malloc'ed char * which should be freed at
793 + some point by the caller.
794 +
795 + Return value is NULL if the file is at EOF when called.
796 +*/
797 +#define FILE_READ_LINE_BUF_SIZE 1024
798 +char *file_read_line_alloc(FILE *file)
799 +{
800 + char buf[FILE_READ_LINE_BUF_SIZE];
801 + int buf_len;
802 + char *line = NULL;
803 + int line_size = 0;
804 +
805 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
806 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
807 + buf_len = strlen(buf);
808 + if (line) {
809 + line_size += buf_len;
810 + line = realloc(line, line_size);
811 + if (line == NULL) {
812 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
813 + break;
814 + }
815 + strcat(line, buf);
816 + } else {
817 + line_size = buf_len + 1;
818 + line = strdup(buf);
819 + }
820 + if (buf[buf_len - 1] == '\n') {
821 + break;
822 + }
823 + }
824 +
825 + return line;
826 +}
827 +
828 +int file_move(const char *src, const char *dest)
829 +{
830 + int err;
831 +
832 + err = rename(src, dest);
833 +
834 + if (err && errno == EXDEV) {
835 + err = file_copy(src, dest);
836 + unlink(src);
837 + } else if (err) {
838 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
839 + __FUNCTION__, src, dest, strerror(errno));
840 + }
841 +
842 + return err;
843 +}
844 +
845 +/* I put these here to keep libbb dependencies from creeping all over
846 + the ipkg code */
847 +int file_copy(const char *src, const char *dest)
848 +{
849 + int err;
850 +
851 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
852 + if (err) {
853 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
854 + __FUNCTION__, src, dest);
855 + }
856 +
857 + return err;
858 +}
859 +
860 +int file_mkdir_hier(const char *path, long mode)
861 +{
862 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
863 +}
864 +
865 +char *file_md5sum_alloc(const char *file_name)
866 +{
867 + static const int md5sum_bin_len = 16;
868 + static const int md5sum_hex_len = 32;
869 +
870 + static const unsigned char bin2hex[16] = {
871 + '0', '1', '2', '3',
872 + '4', '5', '6', '7',
873 + '8', '9', 'a', 'b',
874 + 'c', 'd', 'e', 'f'
875 + };
876 +
877 + int i, err;
878 + FILE *file;
879 + unsigned char *md5sum_hex;
880 + unsigned char md5sum_bin[md5sum_bin_len];
881 +
882 + md5sum_hex = malloc(md5sum_hex_len + 1);
883 + if (md5sum_hex == NULL) {
884 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
885 + return strdup("");
886 + }
887 +
888 + file = fopen(file_name, "r");
889 + if (file == NULL) {
890 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
891 + __FUNCTION__, file_name, strerror(errno));
892 + return strdup("");
893 + }
894 +
895 + err = md5_stream(file, md5sum_bin);
896 + if (err) {
897 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
898 + __FUNCTION__, file_name, strerror(err));
899 + return strdup("");
900 + }
901 +
902 + fclose(file);
903 +
904 + for (i=0; i < md5sum_bin_len; i++) {
905 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
906 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
907 + }
908 +
909 + md5sum_hex[md5sum_hex_len] = '\0';
910 +
911 + return md5sum_hex;
912 +}
913 +
914 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.h busybox-1.1.1-new/archival/libipkg/file_util.h
915 --- busybox-1.1.1-old/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
916 +++ busybox-1.1.1-new/archival/libipkg/file_util.h 2006-03-30 00:39:48.000000000 +0200
917 @@ -0,0 +1,29 @@
918 +/* file_util.h - convenience routines for common file operations
919 +
920 + Carl D. Worth
921 +
922 + Copyright (C) 2001 University of Southern California
923 +
924 + This program is free software; you can redistribute it and/or
925 + modify it under the terms of the GNU General Public License as
926 + published by the Free Software Foundation; either version 2, or (at
927 + your option) any later version.
928 +
929 + This program is distributed in the hope that it will be useful, but
930 + WITHOUT ANY WARRANTY; without even the implied warranty of
931 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
932 + General Public License for more details.
933 +*/
934 +
935 +#ifndef FILE_UTIL_H
936 +#define FILE_UTIL_H
937 +
938 +int file_exists(const char *file_name);
939 +int file_is_dir(const char *file_name);
940 +char *file_read_line_alloc(FILE *file);
941 +int file_move(const char *src, const char *dest);
942 +int file_copy(const char *src, const char *dest);
943 +int file_mkdir_hier(const char *path, long mode);
944 +char *file_md5sum_alloc(const char *file_name);
945 +
946 +#endif
947 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.c busybox-1.1.1-new/archival/libipkg/hash_table.c
948 --- busybox-1.1.1-old/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
949 +++ busybox-1.1.1-new/archival/libipkg/hash_table.c 2006-03-30 00:39:48.000000000 +0200
950 @@ -0,0 +1,155 @@
951 +/* hash.c - hash tables for ipkg
952 +
953 + Steven M. Ayer, Jamey Hicks
954 +
955 + Copyright (C) 2002 Compaq Computer Corporation
956 +
957 + This program is free software; you can redistribute it and/or
958 + modify it under the terms of the GNU General Public License as
959 + published by the Free Software Foundation; either version 2, or (at
960 + your option) any later version.
961 +
962 + This program is distributed in the hope that it will be useful, but
963 + WITHOUT ANY WARRANTY; without even the implied warranty of
964 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
965 + General Public License for more details.
966 +*/
967 +
968 +#include <errno.h>
969 +#include <stdio.h>
970 +#include <stdlib.h>
971 +#include <string.h>
972 +#include "hash_table.h"
973 +#include "ipkg_message.h"
974 +
975 +
976 +static int hash_index(hash_table_t *hash, const char *pkg_name);
977 +static int rotating(const char *key, int len, int prime);
978 +
979 +static int hash_index(hash_table_t *hash, const char *pkg_name)
980 +{
981 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
982 +}
983 +
984 +static int rotating(const char *key, int len, int prime)
985 +{
986 + unsigned int hash, i;
987 + for (hash=len, i=0; i<len; ++i)
988 + hash = (hash<<4)^(hash>>28)^key[i];
989 + return (hash % prime);
990 +}
991 +
992 +
993 +/*
994 + * this is an open table keyed by strings
995 + */
996 +int hash_table_init(const char *name, hash_table_t *hash, int len)
997 +{
998 + static int primes_table[] = {
999 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
1000 + 19471, 23143, 33961, 46499, 49727, 99529, 0
1001 + };
1002 + int *picker;
1003 +
1004 + if (hash->entries != NULL) {
1005 + /* we have been here already */
1006 + return 0;
1007 + }
1008 +
1009 + hash->name = name;
1010 + hash->entries = NULL;
1011 + hash->n_entries = 0;
1012 + hash->hash_entry_key = NULL;
1013 +
1014 + picker = primes_table;
1015 + while(*picker && (*picker++ < len));
1016 + if(!*picker)
1017 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1018 + --picker;
1019 +
1020 + hash->n_entries = *picker;
1021 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1022 + if (hash->entries == NULL) {
1023 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1024 + return ENOMEM;
1025 + }
1026 + return 0;
1027 +}
1028 +
1029 +void hash_table_deinit(hash_table_t *hash)
1030 +{
1031 + free(hash->entries);
1032 + hash->entries = NULL;
1033 + hash->n_entries = 0;
1034 +}
1035 +
1036 +void *hash_table_get(hash_table_t *hash, const char *key)
1037 +{
1038 + int ndx= hash_index(hash, key);
1039 + hash_entry_t *hash_entry = hash->entries + ndx;
1040 + while (hash_entry)
1041 + {
1042 + if (hash_entry->key)
1043 + {
1044 + if (strcmp(key, hash_entry->key) == 0) {
1045 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1046 + return hash_entry->data;
1047 + }
1048 + }
1049 + hash_entry = hash_entry->next;
1050 + }
1051 + return NULL;
1052 +}
1053 +
1054 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1055 +{
1056 + int ndx= hash_index(hash, key);
1057 + hash_entry_t *hash_entry = hash->entries + ndx;
1058 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1059 + if (hash_entry->key) {
1060 + if (strcmp(hash_entry->key, key) == 0) {
1061 + /* alread in table, update the value */
1062 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1063 + hash_entry->data = value;
1064 + return 0;
1065 + } else {
1066 + /*
1067 + * if this is a collision, we have to go to the end of the ll,
1068 + * then add a new entry
1069 + * before we can hook up the value
1070 + */
1071 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1072 + while (hash_entry->next)
1073 + hash_entry = hash_entry->next;
1074 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1075 + if (!hash_entry->next) {
1076 + return -ENOMEM;
1077 + }
1078 + hash_entry = hash_entry->next;
1079 + hash_entry->next = NULL;
1080 + }
1081 + }
1082 + hash->n_elements++;
1083 + hash_entry->key = strdup(key);
1084 + hash_entry->data = value;
1085 +
1086 + return 0;
1087 +}
1088 +
1089 +
1090 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1091 +{
1092 + int i;
1093 + if (!hash || !f)
1094 + return;
1095 +
1096 + for (i = 0; i < hash->n_entries; i++) {
1097 + hash_entry_t *hash_entry = (hash->entries + i);
1098 + do {
1099 + if(hash_entry->key) {
1100 + f(hash_entry->key, hash_entry->data, data);
1101 + }
1102 + } while((hash_entry = hash_entry->next));
1103 + }
1104 +}
1105 +
1106 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.h busybox-1.1.1-new/archival/libipkg/hash_table.h
1107 --- busybox-1.1.1-old/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1108 +++ busybox-1.1.1-new/archival/libipkg/hash_table.h 2006-03-30 00:39:48.000000000 +0200
1109 @@ -0,0 +1,44 @@
1110 +/* hash.h - hash tables for ipkg
1111 +
1112 + Steven M. Ayer, Jamey Hicks
1113 +
1114 + Copyright (C) 2002 Compaq Computer Corporation
1115 +
1116 + This program is free software; you can redistribute it and/or
1117 + modify it under the terms of the GNU General Public License as
1118 + published by the Free Software Foundation; either version 2, or (at
1119 + your option) any later version.
1120 +
1121 + This program is distributed in the hope that it will be useful, but
1122 + WITHOUT ANY WARRANTY; without even the implied warranty of
1123 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1124 + General Public License for more details.
1125 +*/
1126 +
1127 +#ifndef _HASH_TABLE_H_
1128 +#define _HASH_TABLE_H_
1129 +
1130 +typedef struct hash_entry hash_entry_t;
1131 +typedef struct hash_table hash_table_t;
1132 +
1133 +struct hash_entry {
1134 + const char * key;
1135 + void * data;
1136 + struct hash_entry * next;
1137 +};
1138 +
1139 +struct hash_table {
1140 + const char *name;
1141 + hash_entry_t * entries;
1142 + int n_entries; /* number of buckets */
1143 + int n_elements;
1144 + const char * (*hash_entry_key)(void * data);
1145 +};
1146 +
1147 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1148 +void hash_table_deinit(hash_table_t *hash);
1149 +void *hash_table_get(hash_table_t *hash, const char *key);
1150 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1151 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1152 +
1153 +#endif /* _HASH_TABLE_H_ */
1154 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg.h busybox-1.1.1-new/archival/libipkg/ipkg.h
1155 --- busybox-1.1.1-old/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1156 +++ busybox-1.1.1-new/archival/libipkg/ipkg.h 2006-03-30 00:39:48.000000000 +0200
1157 @@ -0,0 +1,74 @@
1158 +/* ipkg.h - the itsy package management system
1159 +
1160 + Carl D. Worth
1161 +
1162 + Copyright (C) 2001 University of Southern California
1163 +
1164 + This program is free software; you can redistribute it and/or
1165 + modify it under the terms of the GNU General Public License as
1166 + published by the Free Software Foundation; either version 2, or (at
1167 + your option) any later version.
1168 +
1169 + This program is distributed in the hope that it will be useful, but
1170 + WITHOUT ANY WARRANTY; without even the implied warranty of
1171 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1172 + General Public License for more details.
1173 +*/
1174 +
1175 +#ifndef IPKG_H
1176 +#define IPKG_H
1177 +
1178 +/*
1179 +#ifdef HAVE_CONFIG_H
1180 +#include "config.h"
1181 +#endif
1182 +*/
1183 +
1184 +#if 0
1185 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1186 +#endif
1187 +
1188 +#include "ipkg_includes.h"
1189 +#include "ipkg_conf.h"
1190 +#include "ipkg_message.h"
1191 +
1192 +#define IPKG_PKG_EXTENSION ".ipk"
1193 +#define DPKG_PKG_EXTENSION ".deb"
1194 +
1195 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1196 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1197 +
1198 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1199 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1200 +#define IPKG_INFO_DIR_SUFFIX "info"
1201 +#define IPKG_STATUS_FILE_SUFFIX "status"
1202 +
1203 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1204 +
1205 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1206 +
1207 +#define IPKG_VERSION "0.99.154"
1208 +
1209 +
1210 +enum ipkg_error {
1211 + IPKG_SUCCESS = 0,
1212 + IPKG_PKG_DEPS_UNSATISFIED,
1213 + IPKG_PKG_IS_ESSENTIAL,
1214 + IPKG_PKG_HAS_DEPENDENTS,
1215 + IPKG_PKG_HAS_NO_CANDIDATE
1216 +};
1217 +typedef enum ipkg_error ipkg_error_t;
1218 +
1219 +extern int ipkg_state_changed;
1220 +
1221 +
1222 +struct errlist {
1223 + char * errmsg;
1224 + struct errlist * next;
1225 +} ;
1226 +
1227 +extern struct errlist* error_list;
1228 +
1229 +extern ipkg_conf_t *global_conf;
1230 +
1231 +#endif
1232 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c
1233 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1234 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c 2006-03-30 00:39:48.000000000 +0200
1235 @@ -0,0 +1,1344 @@
1236 +/* ipkg_cmd.c - the itsy package management system
1237 +
1238 + Carl D. Worth
1239 +
1240 + Copyright (C) 2001 University of Southern California
1241 +
1242 + This program is free software; you can redistribute it and/or
1243 + modify it under the terms of the GNU General Public License as
1244 + published by the Free Software Foundation; either version 2, or (at
1245 + your option) any later version.
1246 +
1247 + This program is distributed in the hope that it will be useful, but
1248 + WITHOUT ANY WARRANTY; without even the implied warranty of
1249 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1250 + General Public License for more details.
1251 +*/
1252 +
1253 +#include <string.h>
1254 +
1255 +#include "ipkg.h"
1256 +#include <libgen.h>
1257 +#include <glob.h>
1258 +#include <errno.h>
1259 +#include <stdlib.h>
1260 +#include <unistd.h>
1261 +#include <signal.h>
1262 +#include <stdio.h>
1263 +
1264 +#include "ipkg_conf.h"
1265 +#include "ipkg_cmd.h"
1266 +#include "ipkg_message.h"
1267 +#include "pkg.h"
1268 +#include "pkg_dest.h"
1269 +#include "pkg_parse.h"
1270 +#include "sprintf_alloc.h"
1271 +#include "pkg.h"
1272 +#include "file_util.h"
1273 +#include "str_util.h"
1274 +#include "libbb.h"
1275 +#include "unarchive.h"
1276 +
1277 +#include <fnmatch.h>
1278 +
1279 +
1280 +#include "ipkg_download.h"
1281 +#include "ipkg_install.h"
1282 +#include "ipkg_upgrade.h"
1283 +#include "ipkg_remove.h"
1284 +#include "ipkg_configure.h"
1285 +#include "ipkg_message.h"
1286 +
1287 +#ifdef IPKG_LIB
1288 +#include "libipkg.h"
1289 +static void *p_userdata = NULL;
1290 +#endif
1291 +
1292 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1316 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1317 +
1318 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1319 + array for easier maintenance */
1320 +static ipkg_cmd_t cmds[] = {
1321 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1322 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1323 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1324 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1325 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1326 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1327 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1328 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1329 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1330 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1331 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1332 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1333 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1334 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1335 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1336 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1337 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1338 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1341 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1342 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1343 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1344 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1345 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1346 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1347 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1348 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1349 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1350 +};
1351 +
1352 +int ipkg_state_changed;
1353 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1354 +{
1355 + if (ipkg_state_changed && !conf->noaction) {
1356 + ipkg_message(conf, IPKG_INFO,
1357 + " writing status file\n");
1358 + ipkg_conf_write_status_files(conf);
1359 + pkg_write_changed_filelists(conf);
1360 + } else {
1361 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1362 + }
1363 +}
1364 +
1365 +
1366 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1367 +
1368 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1369 +{
1370 + int i;
1371 + ipkg_cmd_t *cmd;
1372 +
1373 + for (i=0; i < num_cmds; i++) {
1374 + cmd = &cmds[i];
1375 + if (strcmp(name, cmd->name) == 0) {
1376 + return cmd;
1377 + }
1378 + }
1379 +
1380 + return NULL;
1381 +}
1382 +
1383 +#ifdef IPKG_LIB
1384 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1385 +{
1386 + int result;
1387 + p_userdata = userdata;
1388 +
1389 +
1390 + result = (cmd->fun)(conf, argc, argv);
1391 + if ( result == 0 ) {
1392 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1393 + } else {
1394 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1395 +
1396 + }
1397 + if ( error_list ) {
1398 + reverse_error_list(&error_list);
1399 +
1400 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1401 + /* Here we print the errors collected and free the list */
1402 + while (error_list != NULL) {
1403 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1404 + error_list = error_list->next;
1405 +
1406 + }
1407 + free_error_list(&error_list);
1408 +
1409 + }
1410 +
1411 + p_userdata = NULL;
1412 + return result;
1413 +}
1414 +#else
1415 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1416 +{
1417 + return (cmd->fun)(conf, argc, argv);
1418 +}
1419 +#endif
1420 +
1421 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1422 +{
1423 + int err;
1424 + int failures;
1425 + char *lists_dir;
1426 + pkg_src_list_elt_t *iter;
1427 + pkg_src_t *src;
1428 +
1429 +
1430 + if (conf->offline_root) {
1431 + sprintf_alloc(&lists_dir, "%s/%s",
1432 + conf->offline_root,
1433 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1434 + } else {
1435 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1436 + }
1437 +
1438 + if (! file_is_dir(lists_dir)) {
1439 + if (file_exists(lists_dir)) {
1440 + ipkg_message(conf, IPKG_ERROR,
1441 + "%s: ERROR: %s exists, but is not a directory\n",
1442 + __FUNCTION__, lists_dir);
1443 + free(lists_dir);
1444 + return EINVAL;
1445 + }
1446 + err = file_mkdir_hier(lists_dir, 0755);
1447 + if (err) {
1448 + ipkg_message(conf, IPKG_ERROR,
1449 + "%s: ERROR: failed to make directory %s: %s\n",
1450 + __FUNCTION__, lists_dir, strerror(errno));
1451 + free(lists_dir);
1452 + return EINVAL;
1453 + }
1454 + }
1455 +
1456 + failures = 0;
1457 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1458 + char *url, *list_file_name;
1459 +
1460 + src = iter->data;
1461 +
1462 + if (src->extra_data) /* debian style? */
1463 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1464 + src->gzip ? "Packages.gz" : "Packages");
1465 + else
1466 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1467 +
1468 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1469 + if (src->gzip) {
1470 + char *tmp;
1471 + char *tmp_file_name;
1472 + FILE *in, *out;
1473 +
1474 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1475 +
1476 + if (mkdtemp (tmp) == NULL) {
1477 + perror ("mkdtemp");
1478 + failures++;
1479 + continue;
1480 + }
1481 +
1482 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1483 + err = ipkg_download(conf, url, tmp_file_name);
1484 + if (err == 0) {
1485 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1486 + in = fopen (tmp_file_name, "r");
1487 + out = fopen (list_file_name, "w");
1488 + if (in && out)
1489 + inflate_unzip (in, out);
1490 + else
1491 + err = 1;
1492 + if (in)
1493 + fclose (in);
1494 + if (out)
1495 + fclose (out);
1496 + unlink (tmp_file_name);
1497 + rmdir (tmp);
1498 + free (tmp);
1499 + }
1500 + } else
1501 + err = ipkg_download(conf, url, list_file_name);
1502 + if (err) {
1503 + failures++;
1504 + } else {
1505 + ipkg_message(conf, IPKG_NOTICE,
1506 + "Updated list of available packages in %s\n",
1507 + list_file_name);
1508 + }
1509 + free(url);
1510 + free(list_file_name);
1511 + }
1512 + free(lists_dir);
1513 +
1514 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1515 +#warning here
1516 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1517 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1518 + * -Jamey 3/1/03
1519 + */
1520 + {
1521 + int i;
1522 + int changed = 0;
1523 + pkg_vec_t *available = pkg_vec_alloc();
1524 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1525 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1526 + for (i = 0; i < available->len; i++) {
1527 + pkg_t *pkg = available->pkgs[i];
1528 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1529 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1530 + pkg->state_want = SW_UNKNOWN;
1531 + changed = 1;
1532 + }
1533 + }
1534 + pkg_vec_free(available);
1535 + if (changed) {
1536 + write_status_files_if_changed(conf);
1537 + }
1538 + }
1539 +#endif
1540 +
1541 + return failures;
1542 +}
1543 +
1544 +
1545 +/* scan the args passed and cache the local filenames of the packages */
1546 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1547 +{
1548 + int i;
1549 + int err;
1550 +
1551 + /*
1552 + * First scan through package names/urls
1553 + * For any urls, download the packages and install in database.
1554 + * For any files, install package info in database.
1555 + */
1556 + for (i = 0; i < argc; i ++) {
1557 + char *filename = argv [i];
1558 + //char *tmp = basename (tmp);
1559 + //int tmplen = strlen (tmp);
1560 +
1561 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1562 + // continue;
1563 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1564 + // continue;
1565 +
1566 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1567 + if (err)
1568 + return err;
1569 + }
1570 + return 0;
1571 +}
1572 +
1573 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1574 +{
1575 + pkg_vec_t *all;
1576 + int i;
1577 + pkg_t *pkg;
1578 +
1579 + ipkg_message(conf, IPKG_INFO,
1580 + "Configuring unpacked packages\n");
1581 + fflush( stdout );
1582 +
1583 + all = pkg_vec_alloc();
1584 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1585 +
1586 + for(i = 0; i < all->len; i++) {
1587 + pkg = all->pkgs[i];
1588 +
1589 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1590 + continue;
1591 +
1592 + if (pkg->state_status == SS_UNPACKED) {
1593 + ipkg_message(conf, IPKG_NOTICE,
1594 + "Configuring %s\n", pkg->name);
1595 + fflush( stdout );
1596 + if (ipkg_configure(conf, pkg) == 0) {
1597 + pkg->state_status = SS_INSTALLED;
1598 + pkg->parent->state_status = SS_INSTALLED;
1599 + pkg->state_flag &= ~SF_PREFER;
1600 + }
1601 + }
1602 + }
1603 +
1604 + pkg_vec_free(all);
1605 + return 0;
1606 +}
1607 +
1608 +static void sigint_handler(int sig)
1609 +{
1610 + signal(sig, SIG_DFL);
1611 + ipkg_message(NULL, IPKG_NOTICE,
1612 + "ipkg: interrupted. writing out status database\n");
1613 + write_status_files_if_changed(global_conf);
1614 + exit(128 + sig);
1615 +}
1616 +
1617 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1618 +{
1619 + int i;
1620 + char *arg;
1621 + int err=0;
1622 +
1623 + global_conf = conf;
1624 + signal(SIGINT, sigint_handler);
1625 +
1626 + /*
1627 + * Now scan through package names and install
1628 + */
1629 + for (i=0; i < argc; i++) {
1630 + arg = argv[i];
1631 +
1632 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1633 + if (err != EINVAL && err != 0)
1634 + return err;
1635 + }
1636 + pkg_info_preinstall_check(conf);
1637 +
1638 + for (i=0; i < argc; i++) {
1639 + arg = argv[i];
1640 + if (conf->multiple_providers)
1641 + err = ipkg_install_multi_by_name(conf, arg);
1642 + else{
1643 + err = ipkg_install_by_name(conf, arg);
1644 + }
1645 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1646 + ipkg_message(conf, IPKG_ERROR,
1647 + "Cannot find package %s.\n"
1648 + "Check the spelling or perhaps run 'ipkg update'\n",
1649 + arg);
1650 + }
1651 + }
1652 +
1653 + /* recheck to verify that all dependences are satisfied */
1654 + if (0) ipkg_satisfy_all_dependences(conf);
1655 +
1656 + ipkg_configure_packages(conf, NULL);
1657 +
1658 + write_status_files_if_changed(conf);
1659 +
1660 + return err;
1661 +}
1662 +
1663 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1664 +{
1665 + int i;
1666 + pkg_t *pkg;
1667 + int err;
1668 +
1669 + global_conf = conf;
1670 + signal(SIGINT, sigint_handler);
1671 +
1672 + if (argc) {
1673 + for (i=0; i < argc; i++) {
1674 + char *arg = argv[i];
1675 +
1676 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1677 + if (err != EINVAL && err != 0)
1678 + return err;
1679 + }
1680 + pkg_info_preinstall_check(conf);
1681 +
1682 + for (i=0; i < argc; i++) {
1683 + char *arg = argv[i];
1684 + if (conf->restrict_to_default_dest) {
1685 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1686 + argv[i],
1687 + conf->default_dest);
1688 + if (pkg == NULL) {
1689 + ipkg_message(conf, IPKG_NOTICE,
1690 + "Package %s not installed in %s\n",
1691 + argv[i], conf->default_dest->name);
1692 + continue;
1693 + }
1694 + } else {
1695 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1696 + argv[i]);
1697 + }
1698 + if (pkg)
1699 + ipkg_upgrade_pkg(conf, pkg);
1700 + else {
1701 + ipkg_install_by_name(conf, arg);
1702 + }
1703 + }
1704 + } else {
1705 + pkg_vec_t *installed = pkg_vec_alloc();
1706 +
1707 + pkg_info_preinstall_check(conf);
1708 +
1709 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1710 + for (i = 0; i < installed->len; i++) {
1711 + pkg = installed->pkgs[i];
1712 + ipkg_upgrade_pkg(conf, pkg);
1713 + }
1714 + pkg_vec_free(installed);
1715 + }
1716 +
1717 + /* recheck to verify that all dependences are satisfied */
1718 + if (0) ipkg_satisfy_all_dependences(conf);
1719 +
1720 + ipkg_configure_packages(conf, NULL);
1721 +
1722 + write_status_files_if_changed(conf);
1723 +
1724 + return 0;
1725 +}
1726 +
1727 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1728 +{
1729 + int i, err;
1730 + char *arg;
1731 + pkg_t *pkg;
1732 +
1733 + pkg_info_preinstall_check(conf);
1734 + for (i = 0; i < argc; i++) {
1735 + arg = argv[i];
1736 +
1737 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1738 + if (pkg == NULL) {
1739 + ipkg_message(conf, IPKG_ERROR,
1740 + "Cannot find package %s.\n"
1741 + "Check the spelling or perhaps run 'ipkg update'\n",
1742 + arg);
1743 + continue;
1744 + }
1745 +
1746 + err = ipkg_download_pkg(conf, pkg, ".");
1747 +
1748 + if (err) {
1749 + ipkg_message(conf, IPKG_ERROR,
1750 + "Failed to download %s\n", pkg->name);
1751 + } else {
1752 + ipkg_message(conf, IPKG_NOTICE,
1753 + "Downloaded %s as %s\n",
1754 + pkg->name, pkg->local_filename);
1755 + }
1756 + }
1757 +
1758 + return 0;
1759 +}
1760 +
1761 +
1762 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1763 +{
1764 + int i ;
1765 + pkg_vec_t *available;
1766 + pkg_t *pkg;
1767 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1768 + char *newline;
1769 + char *pkg_name = NULL;
1770 + char *version_str;
1771 +
1772 + if (argc > 0) {
1773 + pkg_name = argv[0];
1774 + }
1775 + available = pkg_vec_alloc();
1776 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1777 + for (i=0; i < available->len; i++) {
1778 + pkg = available->pkgs[i];
1779 + /* if we have package name or pattern and pkg does not match, then skip it */
1780 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1781 + continue;
1782 + if (pkg->description) {
1783 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1784 + } else {
1785 + desc_short[0] = '\0';
1786 + }
1787 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1788 + newline = strchr(desc_short, '\n');
1789 + if (newline) {
1790 + *newline = '\0';
1791 + }
1792 +#ifndef IPKG_LIB
1793 + printf("%s - %s\n", pkg->name, desc_short);
1794 +#else
1795 + if (ipkg_cb_list) {
1796 + version_str = pkg_version_str_alloc(pkg);
1797 + ipkg_cb_list(pkg->name,desc_short,
1798 + version_str,
1799 + pkg->state_status,
1800 + p_userdata);
1801 + free(version_str);
1802 + }
1803 +#endif
1804 + }
1805 + pkg_vec_free(available);
1806 +
1807 + return 0;
1808 +}
1809 +
1810 +
1811 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1812 +{
1813 + int i ;
1814 + pkg_vec_t *available;
1815 + pkg_t *pkg;
1816 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1817 + char *newline;
1818 + char *pkg_name = NULL;
1819 + char *version_str;
1820 +
1821 + if (argc > 0) {
1822 + pkg_name = argv[0];
1823 + }
1824 + available = pkg_vec_alloc();
1825 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1826 + for (i=0; i < available->len; i++) {
1827 + pkg = available->pkgs[i];
1828 + /* if we have package name or pattern and pkg does not match, then skip it */
1829 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1830 + continue;
1831 + if (pkg->description) {
1832 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1833 + } else {
1834 + desc_short[0] = '\0';
1835 + }
1836 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1837 + newline = strchr(desc_short, '\n');
1838 + if (newline) {
1839 + *newline = '\0';
1840 + }
1841 +#ifndef IPKG_LIB
1842 + printf("%s - %s\n", pkg->name, desc_short);
1843 +#else
1844 + if (ipkg_cb_list) {
1845 + version_str = pkg_version_str_alloc(pkg);
1846 + ipkg_cb_list(pkg->name,desc_short,
1847 + version_str,
1848 + pkg->state_status,
1849 + p_userdata);
1850 + free(version_str);
1851 + }
1852 +#endif
1853 + }
1854 +
1855 + return 0;
1856 +}
1857 +
1858 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1859 +{
1860 + int i;
1861 + pkg_vec_t *available;
1862 + pkg_t *pkg;
1863 + char *pkg_name = NULL;
1864 + char **pkg_fields = NULL;
1865 + int n_fields = 0;
1866 + char *buff ; // = (char *)malloc(1);
1867 +
1868 + if (argc > 0) {
1869 + pkg_name = argv[0];
1870 + }
1871 + if (argc > 1) {
1872 + pkg_fields = &argv[1];
1873 + n_fields = argc - 1;
1874 + }
1875 +
1876 + available = pkg_vec_alloc();
1877 + if (installed_only)
1878 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1879 + else
1880 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1881 + for (i=0; i < available->len; i++) {
1882 + pkg = available->pkgs[i];
1883 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1884 + continue;
1885 + }
1886 +#ifndef IPKG_LIB
1887 + if (n_fields) {
1888 + for (j = 0; j < n_fields; j++)
1889 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1890 + } else {
1891 + pkg_print_info(pkg, stdout);
1892 + }
1893 +#else
1894 +
1895 + buff = pkg_formatted_info(pkg);
1896 + if ( buff ) {
1897 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1898 + pkg->state_status,
1899 + buff,
1900 + p_userdata);
1901 +/*
1902 + We should not forget that actually the pointer is allocated.
1903 + We need to free it :) ( Thanks florian for seeing the error )
1904 +*/
1905 + free(buff);
1906 + }
1907 +#endif
1908 + if (conf->verbosity > 1) {
1909 + conffile_list_elt_t *iter;
1910 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1911 + conffile_t *cf = iter->data;
1912 + int modified = conffile_has_been_modified(conf, cf);
1913 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1914 + cf->name, cf->value, modified);
1915 + }
1916 + }
1917 + }
1918 +#ifndef IPKG_LIB
1919 + if (buff)
1920 + free(buff);
1921 +#endif
1922 + pkg_vec_free(available);
1923 +
1924 + return 0;
1925 +}
1926 +
1927 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1928 +{
1929 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1930 +}
1931 +
1932 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1933 +{
1934 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1935 +}
1936 +
1937 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1938 +{
1939 +
1940 + int err;
1941 + if (argc > 0) {
1942 + char *pkg_name = NULL;
1943 +
1944 + pkg_name = argv[0];
1945 +
1946 + err = ipkg_configure_packages (conf, pkg_name);
1947 +
1948 + } else {
1949 + err = ipkg_configure_packages (conf, NULL);
1950 + }
1951 +
1952 + write_status_files_if_changed(conf);
1953 +
1954 + return err;
1955 +}
1956 +
1957 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1958 +{
1959 + int i, err;
1960 + char *globpattern;
1961 + glob_t globbuf;
1962 +
1963 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1964 + err = glob(globpattern, 0, NULL, &globbuf);
1965 + free(globpattern);
1966 + if (err) {
1967 + return 0;
1968 + }
1969 +
1970 + ipkg_message(conf, IPKG_NOTICE,
1971 + "The following packages in %s will now be installed.\n",
1972 + conf->pending_dir);
1973 + for (i = 0; i < globbuf.gl_pathc; i++) {
1974 + ipkg_message(conf, IPKG_NOTICE,
1975 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1976 + }
1977 + ipkg_message(conf, IPKG_NOTICE, "\n");
1978 + for (i = 0; i < globbuf.gl_pathc; i++) {
1979 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1980 + if (err == 0) {
1981 + err = unlink(globbuf.gl_pathv[i]);
1982 + if (err) {
1983 + ipkg_message(conf, IPKG_ERROR,
1984 + "%s: ERROR: failed to unlink %s: %s\n",
1985 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1986 + return err;
1987 + }
1988 + }
1989 + }
1990 + globfree(&globbuf);
1991 +
1992 + return err;
1993 +}
1994 +
1995 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1996 +{
1997 + int i,a,done;
1998 + pkg_t *pkg;
1999 + pkg_t *pkg_to_remove;
2000 + pkg_vec_t *available;
2001 + char *pkg_name = NULL;
2002 + global_conf = conf;
2003 + signal(SIGINT, sigint_handler);
2004 +
2005 +// ENH: Add the "no pkg removed" just in case.
2006 +
2007 + done = 0;
2008 +
2009 + available = pkg_vec_alloc();
2010 + pkg_info_preinstall_check(conf);
2011 + if ( argc > 0 ) {
2012 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2013 + for (i=0; i < argc; i++) {
2014 + pkg_name = malloc(strlen(argv[i])+2);
2015 + strcpy(pkg_name,argv[i]);
2016 + for (a=0; a < available->len; a++) {
2017 + pkg = available->pkgs[a];
2018 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2019 + continue;
2020 + }
2021 + if (conf->restrict_to_default_dest) {
2022 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2023 + pkg->name,
2024 + conf->default_dest);
2025 + } else {
2026 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2027 + }
2028 +
2029 + if (pkg == NULL) {
2030 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2031 + continue;
2032 + }
2033 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2034 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2035 + continue;
2036 + }
2037 + ipkg_remove_pkg(conf, pkg_to_remove);
2038 + done = 1;
2039 + }
2040 + free (pkg_name);
2041 + }
2042 + pkg_vec_free(available);
2043 + } else {
2044 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2045 + int i;
2046 + int flagged_pkg_count = 0;
2047 + int removed;
2048 +
2049 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2050 +
2051 + for (i = 0; i < installed_pkgs->len; i++) {
2052 + pkg_t *pkg = installed_pkgs->pkgs[i];
2053 + if (pkg->state_flag & SF_USER) {
2054 + flagged_pkg_count++;
2055 + } else {
2056 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2057 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2058 + }
2059 + }
2060 + if (!flagged_pkg_count) {
2061 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2062 + "so refusing to uninstall unflagged non-leaf packages\n");
2063 + return 0;
2064 + }
2065 +
2066 + /* find packages not flagged SF_USER (i.e., installed to
2067 + * satisfy a dependence) and not having any dependents, and
2068 + * remove them */
2069 + do {
2070 + removed = 0;
2071 + for (i = 0; i < installed_pkgs->len; i++) {
2072 + pkg_t *pkg = installed_pkgs->pkgs[i];
2073 + if (!(pkg->state_flag & SF_USER)
2074 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2075 + removed++;
2076 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2077 + ipkg_remove_pkg(conf, pkg);
2078 + done = 1;
2079 + }
2080 + }
2081 + } while (removed);
2082 + pkg_vec_free(installed_pkgs);
2083 + }
2084 +
2085 + if ( done == 0 )
2086 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2087 +
2088 + write_status_files_if_changed(conf);
2089 + return 0;
2090 +}
2091 +
2092 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2093 +{
2094 + int i;
2095 + pkg_t *pkg;
2096 +
2097 + global_conf = conf;
2098 + signal(SIGINT, sigint_handler);
2099 +
2100 + pkg_info_preinstall_check(conf);
2101 +
2102 + for (i=0; i < argc; i++) {
2103 + if (conf->restrict_to_default_dest) {
2104 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2105 + argv[i],
2106 + conf->default_dest);
2107 + } else {
2108 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2109 + }
2110 +
2111 + if (pkg == NULL) {
2112 + ipkg_message(conf, IPKG_ERROR,
2113 + "Package %s is not installed.\n", argv[i]);
2114 + continue;
2115 + }
2116 + ipkg_purge_pkg(conf, pkg);
2117 + }
2118 +
2119 + write_status_files_if_changed(conf);
2120 + return 0;
2121 +}
2122 +
2123 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2124 +{
2125 + int i;
2126 + pkg_t *pkg;
2127 + const char *flags = argv[0];
2128 +
2129 + global_conf = conf;
2130 + signal(SIGINT, sigint_handler);
2131 +
2132 + for (i=1; i < argc; i++) {
2133 + if (conf->restrict_to_default_dest) {
2134 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2135 + argv[i],
2136 + conf->default_dest);
2137 + } else {
2138 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2139 + }
2140 +
2141 + if (pkg == NULL) {
2142 + ipkg_message(conf, IPKG_ERROR,
2143 + "Package %s is not installed.\n", argv[i]);
2144 + continue;
2145 + }
2146 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2147 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2148 + pkg->state_flag = pkg_state_flag_from_str(flags);
2149 + }
2150 +/* pb_ asked this feature 03292004 */
2151 +/* Actually I will use only this two, but this is an open for various status */
2152 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2153 + pkg->state_status = pkg_state_status_from_str(flags);
2154 + }
2155 + ipkg_state_changed++;
2156 + ipkg_message(conf, IPKG_NOTICE,
2157 + "Setting flags for package %s to %s\n",
2158 + pkg->name, flags);
2159 + }
2160 +
2161 + write_status_files_if_changed(conf);
2162 + return 0;
2163 +}
2164 +
2165 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2166 +{
2167 + pkg_t *pkg;
2168 + str_list_t *installed_files;
2169 + str_list_elt_t *iter;
2170 + char *pkg_version;
2171 + size_t buff_len = 8192;
2172 + size_t used_len;
2173 + char *buff ;
2174 +
2175 + buff = (char *)malloc(buff_len);
2176 + if ( buff == NULL ) {
2177 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2178 + return ENOMEM;
2179 + }
2180 +
2181 + if (argc < 1) {
2182 + return EINVAL;
2183 + }
2184 +
2185 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2186 + argv[0]);
2187 + if (pkg == NULL) {
2188 + ipkg_message(conf, IPKG_ERROR,
2189 + "Package %s not installed.\n", argv[0]);
2190 + return 0;
2191 + }
2192 +
2193 + installed_files = pkg_get_installed_files(pkg);
2194 + pkg_version = pkg_version_str_alloc(pkg);
2195 +
2196 +#ifndef IPKG_LIB
2197 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2198 + pkg->name, pkg_version, pkg->dest->name);
2199 + for (iter = installed_files->head; iter; iter = iter->next) {
2200 + puts(iter->data);
2201 + }
2202 +#else
2203 + if (buff) {
2204 + try_again:
2205 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2206 + pkg->name, pkg_version, pkg->dest->name) + 1;
2207 + if (used_len > buff_len) {
2208 + buff_len *= 2;
2209 + buff = realloc (buff, buff_len);
2210 + goto try_again;
2211 + }
2212 + for (iter = installed_files->head; iter; iter = iter->next) {
2213 + used_len += strlen (iter->data) + 1;
2214 + while (buff_len <= used_len) {
2215 + buff_len *= 2;
2216 + buff = realloc (buff, buff_len);
2217 + }
2218 + strncat(buff, iter->data, buff_len);
2219 + strncat(buff, "\n", buff_len);
2220 + }
2221 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2222 + buff,
2223 + pkg_version_str_alloc(pkg),
2224 + pkg->state_status,
2225 + p_userdata);
2226 + free(buff);
2227 + }
2228 +#endif
2229 +
2230 + free(pkg_version);
2231 + pkg_free_installed_files(pkg);
2232 +
2233 + return 0;
2234 +}
2235 +
2236 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2237 +{
2238 +
2239 + if (argc > 0) {
2240 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2241 + const char *rel_str = "depends on";
2242 + int i;
2243 +
2244 + pkg_info_preinstall_check(conf);
2245 +
2246 + if (conf->query_all)
2247 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2248 + else
2249 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2250 + for (i = 0; i < argc; i++) {
2251 + const char *target = argv[i];
2252 + int j;
2253 +
2254 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2255 +
2256 + for (j = 0; j < available_pkgs->len; j++) {
2257 + pkg_t *pkg = available_pkgs->pkgs[j];
2258 + if (fnmatch(target, pkg->name, 0) == 0) {
2259 + int k;
2260 + int count = pkg->depends_count + pkg->pre_depends_count;
2261 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2262 + target, pkg->architecture, rel_str);
2263 + for (k = 0; k < count; k++) {
2264 + compound_depend_t *cdepend = &pkg->depends[k];
2265 + int l;
2266 + for (l = 0; l < cdepend->possibility_count; l++) {
2267 + depend_t *possibility = cdepend->possibilities[l];
2268 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2269 + if (conf->verbosity > 0) {
2270 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2271 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2272 + if (possibility->version) {
2273 + char *typestr = NULL;
2274 + switch (possibility->constraint) {
2275 + case NONE: typestr = "none"; break;
2276 + case EARLIER: typestr = "<"; break;
2277 + case EARLIER_EQUAL: typestr = "<="; break;
2278 + case EQUAL: typestr = "="; break;
2279 + case LATER_EQUAL: typestr = ">="; break;
2280 + case LATER: typestr = ">"; break;
2281 + }
2282 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2283 + }
2284 + // free(ver);
2285 + }
2286 + ipkg_message(conf, IPKG_ERROR, "\n");
2287 + }
2288 + }
2289 + }
2290 + }
2291 + }
2292 + pkg_vec_free(available_pkgs);
2293 + }
2294 + return 0;
2295 +}
2296 +
2297 +enum what_field_type {
2298 + WHATDEPENDS,
2299 + WHATCONFLICTS,
2300 + WHATPROVIDES,
2301 + WHATREPLACES,
2302 + WHATRECOMMENDS,
2303 + WHATSUGGESTS
2304 +};
2305 +
2306 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2307 +{
2308 +
2309 + if (argc > 0) {
2310 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2311 + const char *rel_str = NULL;
2312 + int i;
2313 + int changed;
2314 +
2315 + switch (what_field_type) {
2316 + case WHATDEPENDS: rel_str = "depends on"; break;
2317 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2318 + case WHATSUGGESTS: rel_str = "suggests"; break;
2319 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2320 + case WHATPROVIDES: rel_str = "provides"; break;
2321 + case WHATREPLACES: rel_str = "replaces"; break;
2322 + }
2323 +
2324 + if (conf->query_all)
2325 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2326 + else
2327 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2328 +
2329 + /* mark the root set */
2330 + pkg_vec_clear_marks(available_pkgs);
2331 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2332 + for (i = 0; i < argc; i++) {
2333 + const char *dependee_pattern = argv[i];
2334 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2335 + }
2336 + for (i = 0; i < available_pkgs->len; i++) {
2337 + pkg_t *pkg = available_pkgs->pkgs[i];
2338 + if (pkg->state_flag & SF_MARKED) {
2339 + /* mark the parent (abstract) package */
2340 + pkg_mark_provides(pkg);
2341 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2342 + }
2343 + }
2344 +
2345 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2346 + do {
2347 + int j;
2348 + changed = 0;
2349 +
2350 + for (j = 0; j < available_pkgs->len; j++) {
2351 + pkg_t *pkg = available_pkgs->pkgs[j];
2352 + int k;
2353 + int count = ((what_field_type == WHATCONFLICTS)
2354 + ? pkg->conflicts_count
2355 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2356 + /* skip this package if it is already marked */
2357 + if (pkg->parent->state_flag & SF_MARKED) {
2358 + continue;
2359 + }
2360 + for (k = 0; k < count; k++) {
2361 + compound_depend_t *cdepend =
2362 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2363 + int l;
2364 + for (l = 0; l < cdepend->possibility_count; l++) {
2365 + depend_t *possibility = cdepend->possibilities[l];
2366 + if (possibility->pkg->state_flag & SF_MARKED) {
2367 + /* mark the depending package so we won't visit it again */
2368 + pkg->state_flag |= SF_MARKED;
2369 + pkg_mark_provides(pkg);
2370 + changed++;
2371 +
2372 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2373 + if (conf->verbosity > 0) {
2374 + char *ver = pkg_version_str_alloc(pkg);
2375 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2376 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2377 + if (possibility->version) {
2378 + char *typestr = NULL;
2379 + switch (possibility->constraint) {
2380 + case NONE: typestr = "none"; break;
2381 + case EARLIER: typestr = "<"; break;
2382 + case EARLIER_EQUAL: typestr = "<="; break;
2383 + case EQUAL: typestr = "="; break;
2384 + case LATER_EQUAL: typestr = ">="; break;
2385 + case LATER: typestr = ">"; break;
2386 + }
2387 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2388 + }
2389 + free(ver);
2390 + if (!pkg_dependence_satisfiable(conf, possibility))
2391 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2392 + }
2393 + ipkg_message(conf, IPKG_NOTICE, "\n");
2394 + goto next_package;
2395 + }
2396 + }
2397 + }
2398 + next_package:
2399 + ;
2400 + }
2401 + } while (changed && recursive);
2402 + pkg_vec_free(available_pkgs);
2403 + }
2404 +
2405 + return 0;
2406 +}
2407 +
2408 +int pkg_mark_provides(pkg_t *pkg)
2409 +{
2410 + int provides_count = pkg->provides_count;
2411 + abstract_pkg_t **provides = pkg->provides;
2412 + int i;
2413 + pkg->parent->state_flag |= SF_MARKED;
2414 + for (i = 0; i < provides_count; i++) {
2415 + provides[i]->state_flag |= SF_MARKED;
2416 + }
2417 + return 0;
2418 +}
2419 +
2420 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2421 +{
2422 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2423 +}
2424 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2425 +{
2426 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2427 +}
2428 +
2429 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2430 +{
2431 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2432 +}
2433 +
2434 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2435 +{
2436 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2437 +}
2438 +
2439 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2440 +{
2441 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2442 +}
2443 +
2444 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2445 +{
2446 +
2447 + if (argc > 0) {
2448 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2449 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2450 + int i;
2451 +
2452 + pkg_info_preinstall_check(conf);
2453 +
2454 + if (conf->query_all)
2455 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2456 + else
2457 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2458 + for (i = 0; i < argc; i++) {
2459 + const char *target = argv[i];
2460 + int j;
2461 +
2462 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2463 + rel_str, target);
2464 + for (j = 0; j < available_pkgs->len; j++) {
2465 + pkg_t *pkg = available_pkgs->pkgs[j];
2466 + int k;
2467 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2468 + for (k = 0; k < count; k++) {
2469 + abstract_pkg_t *apkg =
2470 + ((what_field_type == WHATPROVIDES)
2471 + ? pkg->provides[k]
2472 + : pkg->replaces[k]);
2473 + if (fnmatch(target, apkg->name, 0) == 0) {
2474 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2475 + if (strcmp(target, apkg->name) != 0)
2476 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2477 + ipkg_message(conf, IPKG_ERROR, "\n");
2478 + }
2479 + }
2480 + }
2481 + }
2482 + pkg_vec_free(available_pkgs);
2483 + }
2484 + return 0;
2485 +}
2486 +
2487 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2488 +{
2489 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2490 +}
2491 +
2492 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2493 +{
2494 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2495 +}
2496 +
2497 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2498 +{
2499 + int i;
2500 +
2501 + pkg_vec_t *installed;
2502 + pkg_t *pkg;
2503 + str_list_t *installed_files;
2504 + str_list_elt_t *iter;
2505 + char *installed_file;
2506 +
2507 + if (argc < 1) {
2508 + return EINVAL;
2509 + }
2510 +
2511 + installed = pkg_vec_alloc();
2512 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2513 +
2514 + for (i=0; i < installed->len; i++) {
2515 + pkg = installed->pkgs[i];
2516 +
2517 + installed_files = pkg_get_installed_files(pkg);
2518 +
2519 + for (iter = installed_files->head; iter; iter = iter->next) {
2520 + installed_file = iter->data;
2521 + if (fnmatch(argv[0], installed_file, 0)==0) {
2522 +#ifndef IPKG_LIB
2523 + printf("%s: %s\n", pkg->name, installed_file);
2524 +#else
2525 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2526 + installed_file,
2527 + pkg_version_str_alloc(pkg),
2528 + pkg->state_status, p_userdata);
2529 +#endif
2530 + }
2531 + }
2532 +
2533 + pkg_free_installed_files(pkg);
2534 + }
2535 +
2536 + /* XXX: CLEANUP: It's not obvious from the name of
2537 + pkg_hash_fetch_all_installed that we need to call
2538 + pkg_vec_free to avoid a memory leak. */
2539 + pkg_vec_free(installed);
2540 +
2541 + return 0;
2542 +}
2543 +
2544 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2545 +{
2546 + if (argc == 3) {
2547 + /* this is a bit gross */
2548 + struct pkg p1, p2;
2549 + parseVersion(&p1, argv[0]);
2550 + parseVersion(&p2, argv[2]);
2551 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2552 + } else {
2553 + ipkg_message(conf, IPKG_ERROR,
2554 + "ipkg compare_versions <v1> <op> <v2>\n"
2555 + "<op> is one of <= >= << >> =\n");
2556 + return -1;
2557 + }
2558 +}
2559 +
2560 +#ifndef HOST_CPU_STR
2561 +#define HOST_CPU_STR__(X) #X
2562 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2563 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2564 +#endif
2565 +
2566 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2567 +{
2568 + nv_pair_list_elt_t *l;
2569 +
2570 + l = conf->arch_list.head;
2571 + while (l) {
2572 + nv_pair_t *nv = l->data;
2573 + printf("arch %s %s\n", nv->name, nv->value);
2574 + l = l->next;
2575 + }
2576 + return 0;
2577 +}
2578 +
2579 +
2580 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h
2581 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2582 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h 2006-03-30 00:39:48.000000000 +0200
2583 @@ -0,0 +1,46 @@
2584 +/* ipkg_cmd.h - the itsy package management system
2585 +
2586 + Carl D. Worth
2587 +
2588 + Copyright (C) 2001 University of Southern California
2589 +
2590 + This program is free software; you can redistribute it and/or
2591 + modify it under the terms of the GNU General Public License as
2592 + published by the Free Software Foundation; either version 2, or (at
2593 + your option) any later version.
2594 +
2595 + This program is distributed in the hope that it will be useful, but
2596 + WITHOUT ANY WARRANTY; without even the implied warranty of
2597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2598 + General Public License for more details.
2599 +*/
2600 +
2601 +#ifndef IPKG_CMD_H
2602 +#define IPKG_CMD_H
2603 +
2604 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2605 +
2606 +struct ipkg_cmd
2607 +{
2608 + char *name;
2609 + int requires_args;
2610 + ipkg_cmd_fun_t fun;
2611 +};
2612 +typedef struct ipkg_cmd ipkg_cmd_t;
2613 +
2614 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2615 +#ifdef IPKG_LIB
2616 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2617 + const char **argv, void *userdata);
2618 +#else
2619 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2620 +#endif
2621 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2622 +/* install any packges with state_want == SW_INSTALL */
2623 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2624 +/* ensure that all dependences are satisfied */
2625 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2626 +
2627 +int pkg_mark_provides(pkg_t *pkg);
2628 +
2629 +#endif
2630 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.c busybox-1.1.1-new/archival/libipkg/ipkg_conf.c
2631 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2632 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.c 2006-03-30 00:39:48.000000000 +0200
2633 @@ -0,0 +1,709 @@
2634 +/* ipkg_conf.c - the itsy package management system
2635 +
2636 + Carl D. Worth
2637 +
2638 + Copyright (C) 2001 University of Southern California
2639 +
2640 + This program is free software; you can redistribute it and/or
2641 + modify it under the terms of the GNU General Public License as
2642 + published by the Free Software Foundation; either version 2, or (at
2643 + your option) any later version.
2644 +
2645 + This program is distributed in the hope that it will be useful, but
2646 + WITHOUT ANY WARRANTY; without even the implied warranty of
2647 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2648 + General Public License for more details.
2649 +*/
2650 +
2651 +#include <glob.h>
2652 +
2653 +#include "ipkg.h"
2654 +#include "ipkg_conf.h"
2655 +
2656 +#include "xregex.h"
2657 +#include "sprintf_alloc.h"
2658 +#include "ipkg_conf.h"
2659 +#include "ipkg_message.h"
2660 +#include "file_util.h"
2661 +#include "str_util.h"
2662 +#include "xsystem.h"
2663 +
2664 +
2665 +ipkg_conf_t *global_conf;
2666 +
2667 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2668 + pkg_src_list_t *pkg_src_list,
2669 + nv_pair_list_t *tmp_dest_nv_pair_list,
2670 + char **tmp_lists_dir);
2671 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2672 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2673 + const char *name, const char *value);
2674 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2675 + const char *default_dest_name);
2676 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2677 + pkg_src_list_t *nv_pair_list);
2678 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2679 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2680 +
2681 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2682 +{
2683 + ipkg_option_t tmp[] = {
2684 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2685 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2686 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2687 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2688 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2689 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2690 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2691 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2692 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2693 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2694 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2695 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2696 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2697 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2698 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2699 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2700 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2701 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2702 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2703 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2704 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2705 + { NULL }
2706 + };
2707 +
2708 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2709 + if ( options == NULL ){
2710 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2711 + return -1;
2712 + }
2713 +
2714 + memcpy(*options, tmp, sizeof(tmp));
2715 + return 0;
2716 +};
2717 +
2718 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2719 +{
2720 + if (arg_str) {
2721 + if (*conf_str) {
2722 + free(*conf_str);
2723 + }
2724 + *conf_str = strdup(arg_str);
2725 + }
2726 +}
2727 +
2728 +static void ipkg_conf_free_string(char **conf_str)
2729 +{
2730 + if (*conf_str) {
2731 + free(*conf_str);
2732 + *conf_str = NULL;
2733 + }
2734 +}
2735 +
2736 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2737 +{
2738 + int err;
2739 + char *tmp_dir_base;
2740 + nv_pair_list_t tmp_dest_nv_pair_list;
2741 + char * lists_dir =NULL;
2742 + glob_t globbuf;
2743 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2744 + char *pending_dir =NULL;
2745 +
2746 + memset(conf, 0, sizeof(ipkg_conf_t));
2747 +
2748 + pkg_src_list_init(&conf->pkg_src_list);
2749 +
2750 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2751 + pkg_dest_list_init(&conf->pkg_dest_list);
2752 +
2753 + nv_pair_list_init(&conf->arch_list);
2754 +
2755 + conf->restrict_to_default_dest = 0;
2756 + conf->default_dest = NULL;
2757 +
2758 +
2759 + if (args->tmp_dir)
2760 + tmp_dir_base = args->tmp_dir;
2761 + else
2762 + tmp_dir_base = getenv("TMPDIR");
2763 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2764 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2765 + IPKG_CONF_TMP_DIR_SUFFIX);
2766 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2767 + if (conf->tmp_dir == NULL) {
2768 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2769 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2770 + return errno;
2771 + }
2772 +
2773 + conf->force_depends = 0;
2774 + conf->force_defaults = 0;
2775 + conf->force_overwrite = 0;
2776 + conf->force_downgrade = 0;
2777 + conf->force_reinstall = 0;
2778 + conf->force_space = 0;
2779 + conf->force_removal_of_essential_packages = 0;
2780 + conf->force_removal_of_dependent_packages = 0;
2781 + conf->nodeps = 0;
2782 + conf->verbose_wget = 0;
2783 + conf->offline_root = NULL;
2784 + conf->offline_root_pre_script_cmd = NULL;
2785 + conf->offline_root_post_script_cmd = NULL;
2786 + conf->multiple_providers = 0;
2787 + conf->verbosity = 1;
2788 + conf->noaction = 0;
2789 +
2790 + conf->http_proxy = NULL;
2791 + conf->ftp_proxy = NULL;
2792 + conf->no_proxy = NULL;
2793 + conf->proxy_user = NULL;
2794 + conf->proxy_passwd = NULL;
2795 +
2796 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2798 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2799 + lists_dir=(char *)malloc(1);
2800 + lists_dir[0]='\0';
2801 + if (args->conf_file) {
2802 + struct stat stat_buf;
2803 + err = stat(args->conf_file, &stat_buf);
2804 + if (err == 0)
2805 + if (ipkg_conf_parse_file(conf, args->conf_file,
2806 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2807 + /* Memory leakage from ipkg_conf_parse-file */
2808 + return -1;
2809 + }
2810 +
2811 + }
2812 +
2813 + /* if (!lists_dir ){*/
2814 + if (strlen(lists_dir)<=1 ){
2815 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2816 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2817 + }
2818 +
2819 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2820 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2821 +
2822 + conf->lists_dir = strdup(lists_dir);
2823 + conf->pending_dir = strdup(pending_dir);
2824 +
2825 + if (args->offline_root)
2826 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2827 + memset(&globbuf, 0, sizeof(globbuf));
2828 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2829 + if (!err) {
2830 + int i;
2831 + for (i = 0; i < globbuf.gl_pathc; i++) {
2832 + if (globbuf.gl_pathv[i])
2833 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2834 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2835 + /* Memory leakage from ipkg_conf_parse-file */
2836 + return -1;
2837 + }
2838 + }
2839 + }
2840 + globfree(&globbuf);
2841 +
2842 + /* if no architectures were defined, then default all, noarch, and host architecture */
2843 + if (nv_pair_list_empty(&conf->arch_list)) {
2844 + nv_pair_list_append(&conf->arch_list, "all", "1");
2845 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2846 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2847 + }
2848 +
2849 + /* Even if there is no conf file, we'll need at least one dest. */
2850 + if (tmp_dest_nv_pair_list.head == NULL) {
2851 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2852 + IPKG_CONF_DEFAULT_DEST_NAME,
2853 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2854 + }
2855 +
2856 + /* After parsing the file, set options from command-line, (so that
2857 + command-line arguments take precedence) */
2858 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2859 + really needs to be cleaned up. There is so much duplication
2860 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2861 + a pointer to args_t (which could then not be freed), rather
2862 + than duplicating every field here? */
2863 + if (args->force_depends) {
2864 + conf->force_depends = 1;
2865 + }
2866 + if (args->force_defaults) {
2867 + conf->force_defaults = 1;
2868 + }
2869 + if (args->force_overwrite) {
2870 + conf->force_overwrite = 1;
2871 + }
2872 + if (args->force_downgrade) {
2873 + conf->force_downgrade = 1;
2874 + }
2875 + if (args->force_reinstall) {
2876 + conf->force_reinstall = 1;
2877 + }
2878 + if (args->force_removal_of_dependent_packages) {
2879 + conf->force_removal_of_dependent_packages = 1;
2880 + }
2881 + if (args->force_removal_of_essential_packages) {
2882 + conf->force_removal_of_essential_packages = 1;
2883 + }
2884 + if (args->nodeps) {
2885 + conf->nodeps = 1;
2886 + }
2887 + if (args->noaction) {
2888 + conf->noaction = 1;
2889 + }
2890 + if (args->query_all) {
2891 + conf->query_all = 1;
2892 + }
2893 + if (args->verbose_wget) {
2894 + conf->verbose_wget = 1;
2895 + }
2896 + if (args->multiple_providers) {
2897 + conf->multiple_providers = 1;
2898 + }
2899 + if (args->verbosity != conf->verbosity) {
2900 + conf->verbosity = args->verbosity;
2901 + }
2902 +
2903 + ipkg_conf_override_string(&conf->offline_root,
2904 + args->offline_root);
2905 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2906 + args->offline_root_pre_script_cmd);
2907 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2908 + args->offline_root_post_script_cmd);
2909 +
2910 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2911 + read anything from there.
2912 +*/
2913 + if ( !(args->nocheckfordirorfile)){
2914 + /* need to run load the source list before dest list -Jamey */
2915 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2916 +
2917 + /* Now that we have resolved conf->offline_root, we can commit to
2918 + the directory names for the dests and load in all the package
2919 + lists. */
2920 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2921 +
2922 + if (args->dest) {
2923 + err = ipkg_conf_set_default_dest(conf, args->dest);
2924 + if (err) {
2925 + return err;
2926 + }
2927 + }
2928 + }
2929 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2930 + free(lists_dir);
2931 + free(pending_dir);
2932 +
2933 + return 0;
2934 +}
2935 +
2936 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2937 +{
2938 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2939 +#error
2940 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2941 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2942 + __FUNCTION__, conf->tmp_dir);
2943 +#else
2944 + int err;
2945 +
2946 + err = rmdir(conf->tmp_dir);
2947 + if (err) {
2948 + if (errno == ENOTEMPTY) {
2949 + char *cmd;
2950 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2951 + err = xsystem(cmd);
2952 + free(cmd);
2953 + }
2954 + if (err)
2955 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2956 + }
2957 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2958 +
2959 + free(conf->tmp_dir); /*XXX*/
2960 +
2961 + pkg_src_list_deinit(&conf->pkg_src_list);
2962 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2963 + nv_pair_list_deinit(&conf->arch_list);
2964 + if (&conf->pkg_hash)
2965 + pkg_hash_deinit(&conf->pkg_hash);
2966 + if (&conf->file_hash)
2967 + hash_table_deinit(&conf->file_hash);
2968 + if (&conf->obs_file_hash)
2969 + hash_table_deinit(&conf->obs_file_hash);
2970 +
2971 + ipkg_conf_free_string(&conf->offline_root);
2972 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2973 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2974 +
2975 + if (conf->verbosity > 1) {
2976 + int i;
2977 + hash_table_t *hashes[] = {
2978 + &conf->pkg_hash,
2979 + &conf->file_hash,
2980 + &conf->obs_file_hash };
2981 + for (i = 0; i < 3; i++) {
2982 + hash_table_t *hash = hashes[i];
2983 + int c = 0;
2984 + int n_conflicts = 0;
2985 + int j;
2986 + for (j = 0; j < hash->n_entries; j++) {
2987 + int len = 0;
2988 + hash_entry_t *e = &hash->entries[j];
2989 + if (e->next)
2990 + n_conflicts++;
2991 + while (e && e->key) {
2992 + len++;
2993 + e = e->next;
2994 + }
2995 + if (len > c)
2996 + c = len;
2997 + }
2998 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2999 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
3000 + hash_table_deinit(hash);
3001 + }
3002 + }
3003 +}
3004 +
3005 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3006 + const char *default_dest_name)
3007 +{
3008 + pkg_dest_list_elt_t *iter;
3009 + pkg_dest_t *dest;
3010 +
3011 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3012 + dest = iter->data;
3013 + if (strcmp(dest->name, default_dest_name) == 0) {
3014 + conf->default_dest = dest;
3015 + conf->restrict_to_default_dest = 1;
3016 + return 0;
3017 + }
3018 + }
3019 +
3020 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3021 +
3022 + return 1;
3023 +}
3024 +
3025 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3026 +{
3027 + pkg_src_list_elt_t *iter;
3028 + pkg_src_t *src;
3029 + char *list_file;
3030 +
3031 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3032 + src = iter->data;
3033 + if (src == NULL) {
3034 + continue;
3035 + }
3036 + if (conf->offline_root) {
3037 + sprintf_alloc(&list_file, "%s/%s/%s",
3038 + conf->offline_root,
3039 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3040 + src->name);
3041 + } else {
3042 + sprintf_alloc(&list_file, "%s/%s",
3043 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3044 + src->name);
3045 + }
3046 +
3047 + if (file_exists(list_file)) {
3048 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3049 + }
3050 + free(list_file);
3051 + }
3052 +
3053 + return 0;
3054 +}
3055 +
3056 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3057 +{
3058 + nv_pair_list_elt_t *iter;
3059 + nv_pair_t *nv_pair;
3060 + pkg_dest_t *dest;
3061 + char *root_dir;
3062 +
3063 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3064 + nv_pair = iter->data;
3065 +
3066 + if (conf->offline_root) {
3067 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3068 + } else {
3069 + root_dir = strdup(nv_pair->value);
3070 + }
3071 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3072 + free(root_dir);
3073 + if (dest == NULL) {
3074 + continue;
3075 + }
3076 + if (conf->default_dest == NULL) {
3077 + conf->default_dest = dest;
3078 + }
3079 + if (file_exists(dest->status_file_name)) {
3080 + pkg_hash_add_from_file(conf, dest->status_file_name,
3081 + NULL, dest, 1);
3082 + }
3083 + }
3084 +
3085 + return 0;
3086 +}
3087 +
3088 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3089 + pkg_src_list_t *pkg_src_list,
3090 + nv_pair_list_t *tmp_dest_nv_pair_list,
3091 + char **lists_dir)
3092 +{
3093 + ipkg_option_t * options;
3094 + FILE *file = fopen(filename, "r");
3095 + regex_t valid_line_re, comment_re;
3096 +#define regmatch_size 12
3097 + regmatch_t regmatch[regmatch_size];
3098 +
3099 + if (ipkg_init_options_array(conf, &options)<0)
3100 + return ENOMEM;
3101 +
3102 + if (file == NULL) {
3103 + fprintf(stderr, "%s: failed to open %s: %s\n",
3104 + __FUNCTION__, filename, strerror(errno));
3105 + free(options);
3106 + return errno;
3107 + }
3108 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3109 +
3110 + xregcomp(&comment_re,
3111 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3112 + REG_EXTENDED);
3113 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3114 +
3115 + while(1) {
3116 + int line_num = 0;
3117 + char *line;
3118 + char *type, *name, *value, *extra;
3119 +
3120 + line = file_read_line_alloc(file);
3121 + line_num++;
3122 + if (line == NULL) {
3123 + break;
3124 + }
3125 +
3126 + str_chomp(line);
3127 +
3128 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3129 + goto NEXT_LINE;
3130 + }
3131 +
3132 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3133 + str_chomp(line);
3134 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3135 + filename, line_num, line);
3136 + goto NEXT_LINE;
3137 + }
3138 +
3139 + /* This has to be so ugly to deal with optional quotation marks */
3140 + if (regmatch[2].rm_so > 0) {
3141 + type = strndup(line + regmatch[2].rm_so,
3142 + regmatch[2].rm_eo - regmatch[2].rm_so);
3143 + } else {
3144 + type = strndup(line + regmatch[3].rm_so,
3145 + regmatch[3].rm_eo - regmatch[3].rm_so);
3146 + }
3147 + if (regmatch[5].rm_so > 0) {
3148 + name = strndup(line + regmatch[5].rm_so,
3149 + regmatch[5].rm_eo - regmatch[5].rm_so);
3150 + } else {
3151 + name = strndup(line + regmatch[6].rm_so,
3152 + regmatch[6].rm_eo - regmatch[6].rm_so);
3153 + }
3154 + if (regmatch[8].rm_so > 0) {
3155 + value = strndup(line + regmatch[8].rm_so,
3156 + regmatch[8].rm_eo - regmatch[8].rm_so);
3157 + } else {
3158 + value = strndup(line + regmatch[9].rm_so,
3159 + regmatch[9].rm_eo - regmatch[9].rm_so);
3160 + }
3161 + extra = NULL;
3162 + if (regmatch[11].rm_so > 0) {
3163 + extra = strndup (line + regmatch[11].rm_so,
3164 + regmatch[11].rm_eo - regmatch[11].rm_so);
3165 + }
3166 +
3167 + /* We use the tmp_dest_nv_pair_list below instead of
3168 + conf->pkg_dest_list because we might encounter an
3169 + offline_root option later and that would invalidate the
3170 + directories we would have computed in
3171 + pkg_dest_list_init. (We do a similar thing with
3172 + tmp_src_nv_pair_list for sake of symmetry.) */
3173 + if (strcmp(type, "option") == 0) {
3174 + ipkg_conf_set_option(options, name, value);
3175 + } else if (strcmp(type, "src") == 0) {
3176 + if (!nv_pair_list_find(pkg_src_list, name)) {
3177 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3178 + } else {
3179 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3180 + name, value);
3181 + }
3182 + } else if (strcmp(type, "src/gz") == 0) {
3183 + if (!nv_pair_list_find(pkg_src_list, name)) {
3184 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3185 + } else {
3186 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3187 + name, value);
3188 + }
3189 + } else if (strcmp(type, "dest") == 0) {
3190 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3191 + } else if (strcmp(type, "lists_dir") == 0) {
3192 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3193 + if (*lists_dir == NULL) {
3194 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3195 + free(options);
3196 + return EINVAL;
3197 + }
3198 + sprintf (*lists_dir,"%s",value);
3199 + } else if (strcmp(type, "arch") == 0) {
3200 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3201 + if (!value) {
3202 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3203 + value = strdup("10");
3204 + }
3205 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3206 + } else {
3207 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3208 + "parameter: %s %s %s\n", type, name, value);
3209 + free(options);
3210 + return EINVAL;
3211 + }
3212 +
3213 + free(type);
3214 + free(name);
3215 + free(value);
3216 + if (extra)
3217 + free (extra);
3218 +
3219 + NEXT_LINE:
3220 + free(line);
3221 + }
3222 +
3223 + free(options);
3224 + regfree(&comment_re);
3225 + regfree(&valid_line_re);
3226 + fclose(file);
3227 +
3228 + return 0;
3229 +}
3230 +
3231 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3232 + const char *name, const char *value)
3233 +{
3234 + int i = 0;
3235 + while (options[i].name) {
3236 + if (strcmp(options[i].name, name) == 0) {
3237 + switch (options[i].type) {
3238 + case IPKG_OPT_TYPE_BOOL:
3239 + *((int *)options[i].value) = 1;
3240 + return 0;
3241 + case IPKG_OPT_TYPE_INT:
3242 + if (value) {
3243 + *((int *)options[i].value) = atoi(value);
3244 + return 0;
3245 + } else {
3246 + printf("%s: Option %s need an argument\n",
3247 + __FUNCTION__, name);
3248 + return EINVAL;
3249 + }
3250 + case IPKG_OPT_TYPE_STRING:
3251 + if (value) {
3252 + *((char **)options[i].value) = strdup(value);
3253 + return 0;
3254 + } else {
3255 + printf("%s: Option %s need an argument\n",
3256 + __FUNCTION__, name);
3257 + return EINVAL;
3258 + }
3259 + }
3260 + }
3261 + i++;
3262 + }
3263 +
3264 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3265 + __FUNCTION__, name, value);
3266 + return EINVAL;
3267 +}
3268 +
3269 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3270 +{
3271 + pkg_dest_list_elt_t *iter;
3272 + pkg_dest_t *dest;
3273 + pkg_vec_t *all;
3274 + pkg_t *pkg;
3275 + register int i;
3276 + int err;
3277 +
3278 + if (conf->noaction)
3279 + return 0;
3280 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3281 + dest = iter->data;
3282 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3283 + if (dest->status_file == NULL) {
3284 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3285 + __FUNCTION__, dest->status_file_name, strerror(errno));
3286 + }
3287 + }
3288 +
3289 + all = pkg_vec_alloc();
3290 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3291 +
3292 + for(i = 0; i < all->len; i++) {
3293 + pkg = all->pkgs[i];
3294 + /* We don't need most uninstalled packages in the status file */
3295 + if (pkg->state_status == SS_NOT_INSTALLED
3296 + && (pkg->state_want == SW_UNKNOWN
3297 + || pkg->state_want == SW_DEINSTALL
3298 + || pkg->state_want == SW_PURGE)) {
3299 + continue;
3300 + }
3301 + if (!pkg) {
3302 + fprintf(stderr, "Null package\n");
3303 + }
3304 + if (pkg->dest == NULL) {
3305 + fprintf(stderr, "%s: ERROR: Can't write status for "
3306 + "package %s since it has a NULL dest\n",
3307 + __FUNCTION__, pkg->name);
3308 + continue;
3309 + }
3310 + if (pkg->dest->status_file) {
3311 + pkg_print_status(pkg, pkg->dest->status_file);
3312 + }
3313 + }
3314 +
3315 + pkg_vec_free(all);
3316 +
3317 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3318 + dest = iter->data;
3319 + if (dest->status_file) {
3320 + err = ferror(dest->status_file);
3321 + fclose(dest->status_file);
3322 + dest->status_file = NULL;
3323 + if (!err) {
3324 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3325 + } else {
3326 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3327 + "retaining old %s\n", __FUNCTION__,
3328 + dest->status_file_tmp_name, dest->status_file_name);
3329 + }
3330 + }
3331 + }
3332 +
3333 + return 0;
3334 +}
3335 +
3336 +
3337 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3338 +{
3339 + char *root_filename;
3340 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3341 + return root_filename;
3342 +}
3343 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.h busybox-1.1.1-new/archival/libipkg/ipkg_conf.h
3344 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3345 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.h 2006-03-30 00:39:48.000000000 +0200
3346 @@ -0,0 +1,107 @@
3347 +/* ipkg_conf.h - the itsy package management system
3348 +
3349 + Carl D. Worth
3350 +
3351 + Copyright (C) 2001 University of Southern California
3352 +
3353 + This program is free software; you can redistribute it and/or
3354 + modify it under the terms of the GNU General Public License as
3355 + published by the Free Software Foundation; either version 2, or (at
3356 + your option) any later version.
3357 +
3358 + This program is distributed in the hope that it will be useful, but
3359 + WITHOUT ANY WARRANTY; without even the implied warranty of
3360 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3361 + General Public License for more details.
3362 +*/
3363 +
3364 +#ifndef IPKG_CONF_H
3365 +#define IPKG_CONF_H
3366 +
3367 +typedef struct ipkg_conf ipkg_conf_t;
3368 +
3369 +#include "hash_table.h"
3370 +#include "ipkg.h"
3371 +#include "args.h"
3372 +#include "pkg.h"
3373 +#include "pkg_hash.h"
3374 +#include "pkg_src_list.h"
3375 +#include "pkg_dest_list.h"
3376 +#include "nv_pair_list.h"
3377 +
3378 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3379 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3380 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3381 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3382 +
3383 +/* In case the config file defines no dest */
3384 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3385 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3386 +
3387 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3388 +
3389 +struct ipkg_conf
3390 +{
3391 + pkg_src_list_t pkg_src_list;
3392 + pkg_dest_list_t pkg_dest_list;
3393 + nv_pair_list_t arch_list;
3394 +
3395 + int restrict_to_default_dest;
3396 + pkg_dest_t *default_dest;
3397 +
3398 + char *tmp_dir;
3399 + const char *lists_dir;
3400 + const char *pending_dir;
3401 +
3402 + /* options */
3403 + int force_depends;
3404 + int force_defaults;
3405 + int force_overwrite;
3406 + int force_downgrade;
3407 + int force_reinstall;
3408 + int force_space;
3409 + int force_removal_of_dependent_packages;
3410 + int force_removal_of_essential_packages;
3411 + int nodeps; /* do not follow dependences */
3412 + int verbose_wget;
3413 + int multiple_providers;
3414 + char *offline_root;
3415 + char *offline_root_pre_script_cmd;
3416 + char *offline_root_post_script_cmd;
3417 + int query_all;
3418 + int verbosity;
3419 + int noaction;
3420 +
3421 + /* proxy options */
3422 + char *http_proxy;
3423 + char *ftp_proxy;
3424 + char *no_proxy;
3425 + char *proxy_user;
3426 + char *proxy_passwd;
3427 +
3428 + hash_table_t pkg_hash;
3429 + hash_table_t file_hash;
3430 + hash_table_t obs_file_hash;
3431 +};
3432 +
3433 +enum ipkg_option_type {
3434 + IPKG_OPT_TYPE_BOOL,
3435 + IPKG_OPT_TYPE_INT,
3436 + IPKG_OPT_TYPE_STRING
3437 +};
3438 +typedef enum ipkg_option_type ipkg_option_type_t;
3439 +
3440 +typedef struct ipkg_option ipkg_option_t;
3441 +struct ipkg_option {
3442 + const char *name;
3443 + const ipkg_option_type_t type;
3444 + const void *value;
3445 +};
3446 +
3447 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3448 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3449 +
3450 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3451 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3452 +
3453 +#endif
3454 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.c busybox-1.1.1-new/archival/libipkg/ipkg_configure.c
3455 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3456 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.c 2006-03-30 00:39:48.000000000 +0200
3457 @@ -0,0 +1,40 @@
3458 +/* ipkg_configure.c - the itsy package management system
3459 +
3460 + Carl D. Worth
3461 +
3462 + Copyright (C) 2001 University of Southern California
3463 +
3464 + This program is free software; you can redistribute it and/or
3465 + modify it under the terms of the GNU General Public License as
3466 + published by the Free Software Foundation; either version 2, or (at
3467 + your option) any later version.
3468 +
3469 + This program is distributed in the hope that it will be useful, but
3470 + WITHOUT ANY WARRANTY; without even the implied warranty of
3471 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3472 + General Public License for more details.
3473 +*/
3474 +
3475 +#include "ipkg.h"
3476 +
3477 +#include "ipkg_configure.h"
3478 +
3479 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3480 +{
3481 + int err;
3482 +
3483 + /* DPKG_INCOMPATIBILITY:
3484 + dpkg actually does some conffile handling here, rather than at the
3485 + end of ipkg_install(). Do we care? */
3486 + /* DPKG_INCOMPATIBILITY:
3487 + dpkg actually includes a version number to this script call */
3488 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3489 + if (err) {
3490 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3491 + return err;
3492 + }
3493 +
3494 + ipkg_state_changed++;
3495 + return 0;
3496 +}
3497 +
3498 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.h busybox-1.1.1-new/archival/libipkg/ipkg_configure.h
3499 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3500 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.h 2006-03-30 00:39:48.000000000 +0200
3501 @@ -0,0 +1,25 @@
3502 +/* ipkg_configure.h - the itsy package management system
3503 +
3504 + Carl D. Worth
3505 +
3506 + Copyright (C) 2001 University of Southern California
3507 +
3508 + This program is free software; you can redistribute it and/or
3509 + modify it under the terms of the GNU General Public License as
3510 + published by the Free Software Foundation; either version 2, or (at
3511 + your option) any later version.
3512 +
3513 + This program is distributed in the hope that it will be useful, but
3514 + WITHOUT ANY WARRANTY; without even the implied warranty of
3515 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3516 + General Public License for more details.
3517 +*/
3518 +
3519 +#ifndef IPKG_CONFIGURE_H
3520 +#define IPKG_CONFIGURE_H
3521 +
3522 +#include "ipkg_conf.h"
3523 +
3524 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3525 +
3526 +#endif
3527 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.c busybox-1.1.1-new/archival/libipkg/ipkg_download.c
3528 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3529 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.c 2006-03-30 00:39:48.000000000 +0200
3530 @@ -0,0 +1,191 @@
3531 +/* ipkg_download.c - the itsy package management system
3532 +
3533 + Carl D. Worth
3534 +
3535 + Copyright (C) 2001 University of Southern California
3536 +
3537 + This program is free software; you can redistribute it and/or
3538 + modify it under the terms of the GNU General Public License as
3539 + published by the Free Software Foundation; either version 2, or (at
3540 + your option) any later version.
3541 +
3542 + This program is distributed in the hope that it will be useful, but
3543 + WITHOUT ANY WARRANTY; without even the implied warranty of
3544 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3545 + General Public License for more details.
3546 +*/
3547 +
3548 +#include "ipkg.h"
3549 +#include "ipkg_download.h"
3550 +#include "ipkg_message.h"
3551 +
3552 +#include "sprintf_alloc.h"
3553 +#include "xsystem.h"
3554 +#include "file_util.h"
3555 +#include "str_util.h"
3556 +
3557 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3558 +{
3559 + int err = 0;
3560 +
3561 + char *src_basec = strdup(src);
3562 + char *src_base = basename(src_basec);
3563 + char *tmp_file_location;
3564 + char *cmd;
3565 +
3566 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3567 +
3568 + fflush(stdout);
3569 +
3570 + if (str_starts_with(src, "file:")) {
3571 + int ret;
3572 + const char *file_src = src + 5;
3573 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3574 + ret = file_copy(src + 5, dest_file_name);
3575 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3576 + return ret;
3577 + }
3578 +
3579 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3580 + err = unlink(tmp_file_location);
3581 + if (err && errno != ENOENT) {
3582 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3583 + __FUNCTION__, tmp_file_location, strerror(errno));
3584 + free(tmp_file_location);
3585 + return errno;
3586 + }
3587 +
3588 + if (conf->http_proxy) {
3589 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3590 + setenv("http_proxy", conf->http_proxy, 1);
3591 + }
3592 + if (conf->ftp_proxy) {
3593 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3594 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3595 + }
3596 + if (conf->no_proxy) {
3597 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3598 + setenv("no_proxy", conf->no_proxy, 1);
3599 + }
3600 +
3601 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3602 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3603 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3604 + conf->proxy_user ? "--proxy-user=" : "",
3605 + conf->proxy_user ? conf->proxy_user : "",
3606 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3607 + conf->proxy_passwd ? conf->proxy_passwd : "",
3608 + conf->verbose_wget ? "" : "-q",
3609 + conf->tmp_dir,
3610 + src);
3611 + err = xsystem(cmd);
3612 + if (err) {
3613 + if (err != -1) {
3614 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3615 + __FUNCTION__, err, cmd);
3616 + }
3617 + unlink(tmp_file_location);
3618 + free(tmp_file_location);
3619 + free(src_basec);
3620 + free(cmd);
3621 + return EINVAL;
3622 + }
3623 + free(cmd);
3624 +
3625 + err = file_move(tmp_file_location, dest_file_name);
3626 +
3627 + free(tmp_file_location);
3628 + free(src_basec);
3629 +
3630 + if (err) {
3631 + return err;
3632 + }
3633 +
3634 + return 0;
3635 +}
3636 +
3637 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3638 +{
3639 + int err;
3640 + char *url;
3641 +
3642 + if (pkg->src == NULL) {
3643 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3644 + pkg->name, pkg->parent->name);
3645 + return -1;
3646 + }
3647 +
3648 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3649 +
3650 + /* XXX: BUG: The pkg->filename might be something like
3651 + "../../foo.ipk". While this is correct, and exactly what we
3652 + want to use to construct url above, here we actually need to
3653 + use just the filename part, without any directory. */
3654 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3655 +
3656 + err = ipkg_download(conf, url, pkg->local_filename);
3657 + free(url);
3658 +
3659 + return err;
3660 +}
3661 +
3662 +/*
3663 + * Downloads file from url, installs in package database, return package name.
3664 + */
3665 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3666 +{
3667 + int err = 0;
3668 + pkg_t *pkg;
3669 + pkg = pkg_new();
3670 + if (pkg == NULL)
3671 + return ENOMEM;
3672 +
3673 + if (str_starts_with(url, "http://")
3674 + || str_starts_with(url, "ftp://")) {
3675 + char *tmp_file;
3676 + char *file_basec = strdup(url);
3677 + char *file_base = basename(file_basec);
3678 +
3679 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3680 + err = ipkg_download(conf, url, tmp_file);
3681 + if (err)
3682 + return err;
3683 +
3684 + err = pkg_init_from_file(pkg, tmp_file);
3685 + if (err)
3686 + return err;
3687 + pkg->local_filename = strdup(tmp_file);
3688 +
3689 + free(tmp_file);
3690 + free(file_basec);
3691 +
3692 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3693 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3694 +
3695 + err = pkg_init_from_file(pkg, url);
3696 + if (err)
3697 + return err;
3698 + pkg->local_filename = strdup(url);
3699 +
3700 + } else {
3701 + return 0;
3702 + }
3703 +
3704 + if (!pkg->architecture) {
3705 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3706 + return -EINVAL;
3707 + }
3708 +
3709 + pkg->dest = conf->default_dest;
3710 + pkg->state_want = SW_INSTALL;
3711 + pkg->state_flag |= SF_PREFER;
3712 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3713 + if ( pkg == NULL ){
3714 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3715 + return 0;
3716 + }
3717 + if (namep) {
3718 + *namep = pkg->name;
3719 + }
3720 + return 0;
3721 +}
3722 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.h busybox-1.1.1-new/archival/libipkg/ipkg_download.h
3723 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3724 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.h 2006-03-30 00:39:48.000000000 +0200
3725 @@ -0,0 +1,30 @@
3726 +/* ipkg_download.h - the itsy package management system
3727 +
3728 + Carl D. Worth
3729 +
3730 + Copyright (C) 2001 University of Southern California
3731 +
3732 + This program is free software; you can redistribute it and/or
3733 + modify it under the terms of the GNU General Public License as
3734 + published by the Free Software Foundation; either version 2, or (at
3735 + your option) any later version.
3736 +
3737 + This program is distributed in the hope that it will be useful, but
3738 + WITHOUT ANY WARRANTY; without even the implied warranty of
3739 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3740 + General Public License for more details.
3741 +*/
3742 +
3743 +#ifndef IPKG_DOWNLOAD_H
3744 +#define IPKG_DOWNLOAD_H
3745 +
3746 +#include "ipkg_conf.h"
3747 +
3748 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3749 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3750 +/*
3751 + * Downloads file from url, installs in package database, return package name.
3752 + */
3753 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3754 +
3755 +#endif
3756 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_includes.h busybox-1.1.1-new/archival/libipkg/ipkg_includes.h
3757 --- busybox-1.1.1-old/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3758 +++ busybox-1.1.1-new/archival/libipkg/ipkg_includes.h 2006-03-30 00:39:48.000000000 +0200
3759 @@ -0,0 +1,79 @@
3760 +#ifndef IPKG_INCLUDES_H
3761 +#define IPKG_INCLUDES_H
3762 +
3763 +/* Define to 1 if you have the <memory.h> header file. */
3764 +#define HAVE_MEMORY_H 1
3765 +
3766 +/* Define to 1 if you have the <regex.h> header file. */
3767 +#define HAVE_REGEX_H 1
3768 +
3769 +/* Define to 1 if you have the <stdlib.h> header file. */
3770 +#define HAVE_STDLIB_H 1
3771 +
3772 +/* Define to 1 if you have the <strings.h> header file. */
3773 +#define HAVE_STRINGS_H 1
3774 +
3775 +/* Define to 1 if you have the <string.h> header file. */
3776 +#define HAVE_STRING_H 1
3777 +
3778 +/* Define to 1 if you have the <sys/stat.h> header file. */
3779 +#define HAVE_SYS_STAT_H 1
3780 +
3781 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3782 +#define HAVE_SYS_WAIT_H 1
3783 +
3784 +/* Define to 1 if you have the <unistd.h> header file. */
3785 +#define HAVE_UNISTD_H 1
3786 +
3787 +/* Define to 1 if you have the ANSI C header files. */
3788 +#define STDC_HEADERS 1
3789 +
3790 +
3791 +#include <stdio.h>
3792 +
3793 +#if STDC_HEADERS
3794 +# include <stdlib.h>
3795 +# include <stdarg.h>
3796 +# include <stddef.h>
3797 +# include <ctype.h>
3798 +# include <errno.h>
3799 +#else
3800 +# if HAVE_STDLIB_H
3801 +# include <stdlib.h>
3802 +# endif
3803 +#endif
3804 +
3805 +#if HAVE_REGEX_H
3806 +# include <regex.h>
3807 +#endif
3808 +
3809 +#if HAVE_STRING_H
3810 +# if !STDC_HEADERS && HAVE_MEMORY_H
3811 +# include <memory.h>
3812 +# endif
3813 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3814 +# if __GNUC__
3815 +# define __USE_GNU 1
3816 +# endif
3817 +# include <string.h>
3818 +# undef __USE_GNU
3819 +#endif
3820 +
3821 +#if HAVE_STRINGS_H
3822 +# include <strings.h>
3823 +#endif
3824 +
3825 +#if HAVE_SYS_STAT_H
3826 +# include <sys/stat.h>
3827 +#endif
3828 +
3829 +#if HAVE_SYS_WAIT_H
3830 +# include <sys/wait.h>
3831 +#endif
3832 +
3833 +#if HAVE_UNISTD_H
3834 +# include <sys/types.h>
3835 +# include <unistd.h>
3836 +#endif
3837 +
3838 +#endif /* IPKG_INCLUDES_H */
3839 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_install.c busybox-1.1.1-new/archival/libipkg/ipkg_install.c
3840 --- busybox-1.1.1-old/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3841 +++ busybox-1.1.1-new/archival/libipkg/ipkg_install.c 2006-03-30 00:39:48.000000000 +0200
3842 @@ -0,0 +1,1823 @@
3843 +/* ipkg_install.c - the itsy package management system
3844 +
3845 + Carl D. Worth
3846 +
3847 + Copyright (C) 2001 University of Southern California
3848 +
3849 + This program is free software; you can redistribute it and/or
3850 + modify it under the terms of the GNU General Public License as
3851 + published by the Free Software Foundation; either version 2, or (at
3852 + your option) any later version.
3853 +
3854 + This program is distributed in the hope that it will be useful, but
3855 + WITHOUT ANY WARRANTY; without even the implied warranty of
3856 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3857 + General Public License for more details.
3858 +*/
3859 +
3860 +#include "ipkg.h"
3861 +#include <errno.h>
3862 +#include <dirent.h>
3863 +#include <glob.h>
3864 +#include <time.h>
3865 +#include <signal.h>
3866 +typedef void (*sighandler_t)(int);
3867 +
3868 +#include "pkg.h"
3869 +#include "pkg_hash.h"
3870 +#include "pkg_extract.h"
3871 +
3872 +#include "ipkg_install.h"
3873 +#include "ipkg_configure.h"
3874 +#include "ipkg_download.h"
3875 +#include "ipkg_remove.h"
3876 +
3877 +#include "ipkg_utils.h"
3878 +#include "ipkg_message.h"
3879 +
3880 +#include "sprintf_alloc.h"
3881 +#include "file_util.h"
3882 +#include "str_util.h"
3883 +#include "xsystem.h"
3884 +#include "user.h"
3885 +
3886 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3887 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3888 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3889 +
3890 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3891 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3892 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3893 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3894 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3900 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3901 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3902 +
3903 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3904 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3905 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3906 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3907 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3908 +
3909 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3910 +
3911 +static int user_prefers_old_conffile(const char *file, const char *backup);
3912 +
3913 +static char *backup_filename_alloc(const char *file_name);
3914 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3915 +static int backup_exists_for(const char *file_name);
3916 +static int backup_remove(const char *file_name);
3917 +
3918 +
3919 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3920 +{
3921 + int err, cmp;
3922 + pkg_t *pkg, *old;
3923 + char *old_version, *new_version;
3924 +
3925 + pkg = pkg_new();
3926 + if (pkg == NULL) {
3927 + return ENOMEM;
3928 + }
3929 +
3930 + err = pkg_init_from_file(pkg, filename);
3931 + if (err) {
3932 + return err;
3933 + }
3934 +
3935 + if (!pkg->architecture) {
3936 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3937 + return -EINVAL;
3938 + }
3939 +
3940 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3941 + freeing the pkg that we pass in. It might be nice to clean this up
3942 + if possible. */
3943 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3944 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3945 +
3946 + pkg->local_filename = strdup(filename);
3947 +
3948 + if (old) {
3949 + old_version = pkg_version_str_alloc(old);
3950 + new_version = pkg_version_str_alloc(pkg);
3951 +
3952 + cmp = pkg_compare_versions(old, pkg);
3953 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3954 + cmp = -1 ; /* then we force ipkg to downgrade */
3955 + /* We need to use a value < 0 because in the 0 case we are asking to */
3956 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3957 + }
3958 + if (cmp > 0) {
3959 + ipkg_message(conf, IPKG_NOTICE,
3960 + "Not downgrading package %s on %s from %s to %s.\n",
3961 + old->name, old->dest->name, old_version, new_version);
3962 + pkg->state_want = SW_DEINSTALL;
3963 + pkg->state_flag |= SF_OBSOLETE;
3964 + free(old_version);
3965 + free(new_version);
3966 + return 0;
3967 + } else {
3968 + free(old_version);
3969 + free(new_version);
3970 + }
3971 + }
3972 +
3973 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3974 + return ipkg_install_pkg(conf, pkg);
3975 +}
3976 +
3977 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3978 +{
3979 + int cmp;
3980 + pkg_t *old, *new;
3981 + char *old_version, *new_version;
3982 +
3983 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3984 +
3985 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3986 + if (new == NULL) {
3987 + return IPKG_PKG_HAS_NO_CANDIDATE;
3988 + }
3989 +
3990 + new->state_flag |= SF_USER;
3991 + if (old) {
3992 + old_version = pkg_version_str_alloc(old);
3993 + new_version = pkg_version_str_alloc(new);
3994 +
3995 + cmp = pkg_compare_versions(old, new);
3996 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3997 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3998 + cmp = -1 ; /* then we force ipkg to downgrade */
3999 + /* We need to use a value < 0 because in the 0 case we are asking to */
4000 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4001 + }
4002 + ipkg_message(conf, IPKG_DEBUG,
4003 + "comparing visible versions of pkg %s:"
4004 + "\n\t%s is installed "
4005 + "\n\t%s is available "
4006 + "\n\t%d was comparison result\n",
4007 + pkg_name, old_version, new_version, cmp);
4008 + if (cmp == 0 && !conf->force_reinstall) {
4009 + ipkg_message(conf, IPKG_NOTICE,
4010 + "Package %s (%s) installed in %s is up to date.\n",
4011 + old->name, old_version, old->dest->name);
4012 + free(old_version);
4013 + free(new_version);
4014 + return 0;
4015 + } else if (cmp > 0) {
4016 + ipkg_message(conf, IPKG_NOTICE,
4017 + "Not downgrading package %s on %s from %s to %s.\n",
4018 + old->name, old->dest->name, old_version, new_version);
4019 + free(old_version);
4020 + free(new_version);
4021 + return 0;
4022 + } else if (cmp < 0) {
4023 + new->dest = old->dest;
4024 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4025 + }
4026 + }
4027 +
4028 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4029 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4030 + return any kind of integer, (might be errno from a syscall,
4031 + etc.). This is a real mess and will need to be cleaned up if
4032 + anyone ever wants to make a nice libipkg. */
4033 +
4034 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4035 + return ipkg_install_pkg(conf, new);
4036 +}
4037 +
4038 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4039 +{
4040 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4041 + int i;
4042 + ipkg_error_t err;
4043 + abstract_pkg_t *ppkg ;
4044 +
4045 + if (providers == NULL)
4046 + return IPKG_PKG_HAS_NO_CANDIDATE;
4047 +
4048 + for (i = 0; i < providers->len; i++) {
4049 + ppkg = abstract_pkg_vec_get(providers, i);
4050 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4051 + err = ipkg_install_by_name(conf, ppkg->name);
4052 + if (err)
4053 + return err;
4054 +/* XXX Maybe ppkg should be freed ? */
4055 + }
4056 + return 0;
4057 +}
4058 +
4059 +/*
4060 + * Walk dependence graph starting with pkg, collect packages to be
4061 + * installed into pkgs_needed, in dependence order.
4062 + */
4063 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4064 +{
4065 + int i, err;
4066 + pkg_vec_t *depends = pkg_vec_alloc();
4067 + char **unresolved = NULL;
4068 + int ndepends;
4069 +
4070 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4071 + pkg, depends,
4072 + &unresolved);
4073 +
4074 + if (unresolved) {
4075 + ipkg_message(conf, IPKG_ERROR,
4076 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4077 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4078 + while (*unresolved) {
4079 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4080 + unresolved++;
4081 + }
4082 + ipkg_message(conf, IPKG_ERROR, "\n");
4083 + if (! conf->force_depends) {
4084 + ipkg_message(conf, IPKG_INFO,
4085 + "This could mean that your package list is out of date or that the packages\n"
4086 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4087 + "of this problem try again with the '-force-depends' option.\n");
4088 + pkg_vec_free(depends);
4089 + return IPKG_PKG_DEPS_UNSATISFIED;
4090 + }
4091 + }
4092 +
4093 + if (ndepends <= 0) {
4094 + pkg_vec_free(depends);
4095 + return 0;
4096 + }
4097 +
4098 + for (i = 0; i < depends->len; i++) {
4099 + pkg_t *dep = depends->pkgs[i];
4100 + /* The package was uninstalled when we started, but another
4101 + dep earlier in this loop may have depended on it and pulled
4102 + it in, so check first. */
4103 + if ((dep->state_status != SS_INSTALLED)
4104 + && (dep->state_status != SS_UNPACKED)
4105 + && (dep->state_want != SW_INSTALL)) {
4106 +
4107 + /* Mark packages as to-be-installed */
4108 + dep->state_want = SW_INSTALL;
4109 +
4110 + /* Dependencies should be installed the same place as pkg */
4111 + if (dep->dest == NULL) {
4112 + dep->dest = pkg->dest;
4113 + }
4114 +
4115 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4116 + if (err) {
4117 + pkg_vec_free(depends);
4118 + return err;
4119 + }
4120 + }
4121 + }
4122 + if (pkgs_needed)
4123 + pkg_vec_insert(pkgs_needed, pkg);
4124 +
4125 + pkg_vec_free(depends);
4126 +
4127 + return 0;
4128 +}
4129 +
4130 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4131 +{
4132 + int cmp;
4133 + pkg_t *old, *new;
4134 + char *old_version, *new_version;
4135 +
4136 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4137 +
4138 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4139 + if (new == NULL) {
4140 + return IPKG_PKG_HAS_NO_CANDIDATE;
4141 + }
4142 + if (old) {
4143 + old_version = pkg_version_str_alloc(old);
4144 + new_version = pkg_version_str_alloc(new);
4145 +
4146 + cmp = pkg_compare_versions(old, new);
4147 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4148 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4149 + cmp = -1 ; /* then we force ipkg to downgrade */
4150 + /* We need to use a value < 0 because in the 0 case we are asking to */
4151 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4152 + }
4153 + ipkg_message(conf, IPKG_DEBUG,
4154 + "comparing visible versions of pkg %s:"
4155 + "\n\t%s is installed "
4156 + "\n\t%s is available "
4157 + "\n\t%d was comparison result\n",
4158 + pkg_name, old_version, new_version, cmp);
4159 + if (cmp == 0 && !conf->force_reinstall) {
4160 + ipkg_message(conf, IPKG_NOTICE,
4161 + "Package %s (%s) installed in %s is up to date.\n",
4162 + old->name, old_version, old->dest->name);
4163 + free(old_version);
4164 + free(new_version);
4165 + return 0;
4166 + } else if (cmp > 0) {
4167 + ipkg_message(conf, IPKG_NOTICE,
4168 + "Not downgrading package %s on %s from %s to %s.\n",
4169 + old->name, old->dest->name, old_version, new_version);
4170 + free(old_version);
4171 + free(new_version);
4172 + return 0;
4173 + } else if (cmp < 0) {
4174 + new->dest = old->dest;
4175 + old->state_want = SW_DEINSTALL;
4176 + old->state_flag |= SF_OBSOLETE;
4177 + }
4178 + }
4179 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4180 +}
4181 +
4182 +\f
4183 +
4184 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4185 +{
4186 + int i, err;
4187 + pkg_vec_t *depends = pkg_vec_alloc();
4188 + pkg_t *dep;
4189 + char **unresolved = NULL;
4190 + int ndepends;
4191 +
4192 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4193 + pkg, depends,
4194 + &unresolved);
4195 +
4196 + if (unresolved) {
4197 + ipkg_message(conf, IPKG_ERROR,
4198 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4199 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4200 + while (*unresolved) {
4201 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4202 + unresolved++;
4203 + }
4204 + ipkg_message(conf, IPKG_ERROR, "\n");
4205 + if (! conf->force_depends) {
4206 + ipkg_message(conf, IPKG_INFO,
4207 + "This could mean that your package list is out of date or that the packages\n"
4208 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4209 + "of this problem try again with the '-force-depends' option.\n");
4210 + pkg_vec_free(depends);
4211 + return IPKG_PKG_DEPS_UNSATISFIED;
4212 + }
4213 + }
4214 +
4215 + if (ndepends <= 0) {
4216 + return 0;
4217 + }
4218 +
4219 + /* Mark packages as to-be-installed */
4220 + for (i=0; i < depends->len; i++) {
4221 + /* Dependencies should be installed the same place as pkg */
4222 + if (depends->pkgs[i]->dest == NULL) {
4223 + depends->pkgs[i]->dest = pkg->dest;
4224 + }
4225 + depends->pkgs[i]->state_want = SW_INSTALL;
4226 + }
4227 +
4228 + for (i = 0; i < depends->len; i++) {
4229 + dep = depends->pkgs[i];
4230 + /* The package was uninstalled when we started, but another
4231 + dep earlier in this loop may have depended on it and pulled
4232 + it in, so check first. */
4233 + if ((dep->state_status != SS_INSTALLED)
4234 + && (dep->state_status != SS_UNPACKED)) {
4235 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4236 + err = ipkg_install_pkg(conf, dep);
4237 + if (err) {
4238 + pkg_vec_free(depends);
4239 + return err;
4240 + }
4241 + }
4242 + }
4243 +
4244 + pkg_vec_free(depends);
4245 +
4246 + return 0;
4247 +}
4248 +
4249 +
4250 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4251 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4252 +{
4253 + if (conf->nodeps == 0) {
4254 + int i;
4255 + pkg_vec_t *installed = pkg_vec_alloc();
4256 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4257 + for (i = 0; i < installed->len; i++) {
4258 + pkg_t *pkg = installed->pkgs[i];
4259 + satisfy_dependencies_for(conf, pkg);
4260 + }
4261 + pkg_vec_free(installed);
4262 + }
4263 + return 0;
4264 +}
4265 +
4266 +\f
4267 +
4268 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4269 +{
4270 + int i;
4271 + pkg_vec_t *conflicts = NULL;
4272 + int level;
4273 + const char *prefix;
4274 + if (conf->force_depends) {
4275 + level = IPKG_NOTICE;
4276 + prefix = "Warning";
4277 + } else {
4278 + level = IPKG_ERROR;
4279 + prefix = "ERROR";
4280 + }
4281 +
4282 + if (!conf->force_depends)
4283 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4284 +
4285 + if (conflicts) {
4286 + ipkg_message(conf, level,
4287 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4288 + i = 0;
4289 + while (i < conflicts->len)
4290 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4291 + ipkg_message(conf, level, "\n");
4292 + pkg_vec_free(conflicts);
4293 + return IPKG_PKG_DEPS_UNSATISFIED;
4294 + }
4295 + return 0;
4296 +}
4297 +
4298 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4299 +{
4300 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4301 + str_list_elt_t *iter;
4302 +
4303 + for (iter = new_list->head; iter; iter = iter->next) {
4304 + char *new_file = iter->data;
4305 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4306 + if (!new_file)
4307 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4308 + if (!owner || (owner == old_pkg))
4309 + file_hash_set_file_owner(conf, new_file, new_pkg);
4310 + }
4311 + if (old_pkg) {
4312 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4313 + for (iter = old_list->head; iter; iter = iter->next) {
4314 + char *old_file = iter->data;
4315 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4316 + if (owner == old_pkg) {
4317 + /* obsolete */
4318 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4319 + }
4320 + }
4321 + }
4322 + return 0;
4323 +}
4324 +
4325 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4326 +{
4327 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4328 +
4329 + /* sma 6.20.02: yup; here's the first bit */
4330 + /*
4331 + * XXX: BUG easy for cworth
4332 + * 1) please point the call below to the correct current root destination
4333 + * 2) we need to resolve how to check the required space for a pending pkg,
4334 + * my diddling with the .ipk file size below isn't going to cut it.
4335 + * 3) return a proper error code instead of 1
4336 + */
4337 + int comp_size, blocks_available;
4338 +
4339 + if (!conf->force_space && pkg->installed_size != NULL) {
4340 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4341 +
4342 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4343 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4344 + comp_size = (int)((comp_size + 1023) / 1024);
4345 +
4346 + if (comp_size >= blocks_available) {
4347 + ipkg_message(conf, IPKG_ERROR,
4348 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4349 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4350 + return ENOSPC;
4351 + }
4352 + }
4353 + return 0;
4354 +}
4355 +
4356 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4357 +{
4358 + int err;
4359 + char *conffiles_file_name;
4360 + char *root_dir;
4361 + FILE *conffiles_file;
4362 +
4363 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4364 +
4365 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4366 + if (pkg->tmp_unpack_dir == NULL) {
4367 + ipkg_message(conf, IPKG_ERROR,
4368 + "%s: Failed to create temporary directory '%s': %s\n",
4369 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4370 + return errno;
4371 + }
4372 +
4373 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4374 + if (err) {
4375 + return err;
4376 + }
4377 +
4378 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4379 + conffiles. Seems like I should be able to get everything to go
4380 + through pkg_init_from_file. If so, maybe it would make sense to
4381 + move all of unpack_pkg_control_files to that function. */
4382 +
4383 + /* Don't need to re-read conffiles if we already have it */
4384 + if (pkg->conffiles.head) {
4385 + return 0;
4386 + }
4387 +
4388 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4389 + if (! file_exists(conffiles_file_name)) {
4390 + free(conffiles_file_name);
4391 + return 0;
4392 + }
4393 +
4394 + conffiles_file = fopen(conffiles_file_name, "r");
4395 + if (conffiles_file == NULL) {
4396 + fprintf(stderr, "%s: failed to open %s: %s\n",
4397 + __FUNCTION__, conffiles_file_name, strerror(errno));
4398 + free(conffiles_file_name);
4399 + return errno;
4400 + }
4401 + free(conffiles_file_name);
4402 +
4403 + while (1) {
4404 + char *cf_name;
4405 + char *cf_name_in_dest;
4406 +
4407 + cf_name = file_read_line_alloc(conffiles_file);
4408 + if (cf_name == NULL) {
4409 + break;
4410 + }
4411 + str_chomp(cf_name);
4412 + if (cf_name[0] == '\0') {
4413 + continue;
4414 + }
4415 +
4416 + /* Prepend dest->root_dir to conffile name.
4417 + Take pains to avoid multiple slashes. */
4418 + root_dir = pkg->dest->root_dir;
4419 + if (conf->offline_root)
4420 + /* skip the offline_root prefix */
4421 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4422 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4423 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4424 +
4425 + /* Can't get an md5sum now, (file isn't extracted yet).
4426 + We'll wait until resolve_conffiles */
4427 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4428 +
4429 + free(cf_name);
4430 + free(cf_name_in_dest);
4431 + }
4432 +
4433 + fclose(conffiles_file);
4434 +
4435 + return 0;
4436 +}
4437 +
4438 +/* returns number of installed replacees */
4439 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4440 +{
4441 + abstract_pkg_t **replaces = pkg->replaces;
4442 + int replaces_count = pkg->replaces_count;
4443 + int i, j;
4444 + for (i = 0; i < replaces_count; i++) {
4445 + abstract_pkg_t *ab_pkg = replaces[i];
4446 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4447 + if (pkg_vec) {
4448 + for (j = 0; j < pkg_vec->len; j++) {
4449 + pkg_t *replacee = pkg_vec->pkgs[j];
4450 + if (!pkg_conflicts(pkg, replacee))
4451 + continue;
4452 + if (replacee->state_status == SS_INSTALLED) {
4453 + pkg_vec_insert(installed_replacees, replacee);
4454 + }
4455 + }
4456 + }
4457 + }
4458 + return installed_replacees->len;
4459 +}
4460 +
4461 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4462 +{
4463 + int i;
4464 + int replaces_count = replacees->len;
4465 + for (i = 0; i < replaces_count; i++) {
4466 + pkg_t *replacee = replacees->pkgs[i];
4467 + int err;
4468 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4469 + err = ipkg_remove_pkg(conf, replacee);
4470 + if (err)
4471 + return err;
4472 + }
4473 + return 0;
4474 +}
4475 +
4476 +/* to unwind the removal: make sure they are installed */
4477 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4478 +{
4479 + int i, err;
4480 + int replaces_count = replacees->len;
4481 + for (i = 0; i < replaces_count; i++) {
4482 + pkg_t *replacee = replacees->pkgs[i];
4483 + if (replacee->state_status != SS_INSTALLED) {
4484 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4485 + err = ipkg_install_pkg(conf, replacee);
4486 + if (err)
4487 + return err;
4488 + }
4489 + }
4490 + return 0;
4491 +}
4492 +
4493 +int caught_sigint = 0;
4494 +static void ipkg_install_pkg_sigint_handler(int sig)
4495 +{
4496 + caught_sigint = sig;
4497 +}
4498 +
4499 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4500 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4501 +{
4502 + if (old_pkg) {
4503 + char message_out[15];
4504 + char *old_version = pkg_version_str_alloc(old_pkg);
4505 + char *new_version = pkg_version_str_alloc(pkg);
4506 + int cmp = pkg_compare_versions(old_pkg, pkg);
4507 + int rc = 0;
4508 +
4509 + strncpy (message_out,"Upgrading ",13);
4510 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4511 + cmp = -1 ; /* then we force ipkg to downgrade */
4512 + strncpy (message_out,"Downgrading ",13); /* We need to use a value < 0 because in the 0 case we are asking to */
4513 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4514 + }
4515 +
4516 + if (cmp > 0) {
4517 + ipkg_message(conf, IPKG_NOTICE,
4518 + "Not downgrading package %s on %s from %s to %s.\n",
4519 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4520 + rc = 1;
4521 + } else if (cmp < 0) {
4522 + ipkg_message(conf, IPKG_NOTICE,
4523 + "%s %s on %s from %s to %s...\n",
4524 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4525 + pkg->dest = old_pkg->dest;
4526 + rc = 0;
4527 + } else /* cmp == 0 */ {
4528 + if (conf->force_reinstall) {
4529 + ipkg_message(conf, IPKG_NOTICE,
4530 + "Reinstalling %s (%s) on %s...\n",
4531 + pkg->name, new_version, old_pkg->dest->name);
4532 + pkg->dest = old_pkg->dest;
4533 + rc = 0;
4534 + } else {
4535 + ipkg_message(conf, IPKG_NOTICE,
4536 + "Not installing %s (%s) on %s -- already installed.\n",
4537 + pkg->name, new_version, old_pkg->dest->name);
4538 + rc = 1;
4539 + }
4540 + }
4541 + free(old_version);
4542 + free(new_version);
4543 + return rc;
4544 + } else {
4545 + char *version = pkg_version_str_alloc(pkg);
4546 + ipkg_message(conf, IPKG_NOTICE,
4547 + "Installing %s (%s) to %s...\n",
4548 + pkg->name, version, pkg->dest->name);
4549 + free(version);
4550 + return 0;
4551 + }
4552 +}
4553 +
4554 +/* and now the meat... */
4555 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg)
4556 +{
4557 + int err = 0;
4558 + pkg_t *old_pkg = NULL;
4559 + pkg_vec_t *replacees;
4560 + abstract_pkg_t *ab_pkg = NULL;
4561 + int old_state_flag;
4562 +
4563 + if (!pkg) {
4564 + ipkg_message(conf, IPKG_ERROR,
4565 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4566 + return -EINVAL;
4567 + }
4568 +
4569 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4570 +
4571 + if (!pkg_arch_supported(conf, pkg)) {
4572 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4573 + pkg->architecture, pkg->name);
4574 + return -EINVAL;
4575 + }
4576 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4577 + err = satisfy_dependencies_for(conf, pkg);
4578 + if (err) { return err; }
4579 +
4580 + ipkg_message(conf, IPKG_NOTICE,
4581 + "Package %s is already installed in %s.\n",
4582 + pkg->name, pkg->dest->name);
4583 + return 0;
4584 + }
4585 +
4586 + if (pkg->dest == NULL) {
4587 + pkg->dest = conf->default_dest;
4588 + }
4589 +
4590 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4591 +
4592 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg);
4593 + if (err) { return err; }
4594 +
4595 + pkg->state_want = SW_INSTALL;
4596 + if (old_pkg) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4597 +
4598 + /* Abhaya: conflicts check */
4599 + err = check_conflicts_for(conf, pkg);
4600 + if (err) { return err; }
4601 +
4602 + /* this setup is to remove the upgrade scenario in the end when
4603 + installing pkg A, A deps B & B deps on A. So both B and A are
4604 + installed. Then A's installation is started resulting in an
4605 + uncecessary upgrade */
4606 + if (pkg->state_status == SS_INSTALLED
4607 + && conf->force_reinstall == 0) return 0;
4608 +
4609 + err = verify_pkg_installable(conf, pkg);
4610 + if (err) { return err; }
4611 +
4612 + if (pkg->local_filename == NULL) {
4613 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4614 + if (err) {
4615 + ipkg_message(conf, IPKG_ERROR,
4616 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4617 + pkg->name);
4618 + return err;
4619 + }
4620 + }
4621 + if (pkg->tmp_unpack_dir == NULL) {
4622 + unpack_pkg_control_files(conf, pkg);
4623 + }
4624 +
4625 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4626 + err = update_file_ownership(conf, pkg, old_pkg);
4627 + if (err) { return err; }
4628 +
4629 + if (conf->nodeps == 0) {
4630 + err = satisfy_dependencies_for(conf, pkg);
4631 + if (err) { return err; }
4632 + }
4633 +
4634 + replacees = pkg_vec_alloc();
4635 + pkg_get_installed_replacees(conf, pkg, replacees);
4636 +
4637 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4638 + {
4639 + sigset_t newset, oldset;
4640 + sighandler_t old_handler = NULL;
4641 + int use_signal = 0;
4642 + caught_sigint = 0;
4643 + if (use_signal) {
4644 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4645 + } else {
4646 + sigemptyset(&newset);
4647 + sigaddset(&newset, SIGINT);
4648 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4649 + }
4650 +
4651 + ipkg_state_changed++;
4652 + pkg->state_flag |= SF_FILELIST_CHANGED;
4653 +
4654 + /* XXX: BUG: we really should treat replacement more like an upgrade
4655 + * Instead, we're going to remove the replacees
4656 + */
4657 + err = pkg_remove_installed_replacees(conf, replacees);
4658 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4659 +
4660 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4661 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4662 +
4663 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4664 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4665 +
4666 + err = preinst_configure(conf, pkg, old_pkg);
4667 + if (err) goto UNWIND_PREINST_CONFIGURE;
4668 +
4669 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4670 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4671 +
4672 + err = check_data_file_clashes(conf, pkg, old_pkg);
4673 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4674 +
4675 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4676 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4677 +
4678 + if (conf->noaction) return 0;
4679 +
4680 + /* point of no return: no unwinding after this */
4681 + if (old_pkg && !conf->force_reinstall) {
4682 + old_pkg->state_want = SW_DEINSTALL;
4683 +
4684 + if (old_pkg->state_flag & SF_NOPRUNE) {
4685 + ipkg_message(conf, IPKG_INFO,
4686 + " not removing obsolesced files because package marked noprune\n");
4687 + } else {
4688 + ipkg_message(conf, IPKG_INFO,
4689 + " removing obsolesced files\n");
4690 + remove_obsolesced_files(conf, pkg, old_pkg);
4691 + }
4692 + }
4693 + ipkg_message(conf, IPKG_INFO,
4694 + " installing maintainer scripts\n");
4695 + install_maintainer_scripts(conf, pkg, old_pkg);
4696 +
4697 + /* the following just returns 0 */
4698 + remove_disappeared(conf, pkg);
4699 +
4700 + ipkg_message(conf, IPKG_INFO,
4701 + " installing data files\n");
4702 + install_data_files(conf, pkg);
4703 +
4704 + ipkg_message(conf, IPKG_INFO,
4705 + " resolving conf files\n");
4706 + resolve_conffiles(conf, pkg);
4707 +
4708 + pkg->state_status = SS_UNPACKED;
4709 + old_state_flag = pkg->state_flag;
4710 + pkg->state_flag &= ~SF_PREFER;
4711 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4712 +
4713 + if (old_pkg && !conf->force_reinstall) {
4714 + old_pkg->state_status = SS_NOT_INSTALLED;
4715 + }
4716 +
4717 + time(&pkg->installed_time);
4718 +
4719 + ipkg_message(conf, IPKG_INFO,
4720 + " cleanup temp files\n");
4721 + cleanup_temporary_files(conf, pkg);
4722 +
4723 + ab_pkg = pkg->parent;
4724 + if (ab_pkg)
4725 + ab_pkg->state_status = pkg->state_status;
4726 +
4727 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4728 +
4729 + if (use_signal)
4730 + signal(SIGINT, old_handler);
4731 + else
4732 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4733 +
4734 + return 0;
4735 +
4736 +
4737 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4738 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4739 + UNWIND_CHECK_DATA_FILE_CLASHES:
4740 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4741 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4742 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4743 + UNWIND_PREINST_CONFIGURE:
4744 + preinst_configure_unwind(conf, pkg, old_pkg);
4745 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4746 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4747 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4748 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4749 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4750 + pkg_remove_installed_replacees_unwind(conf, replacees);
4751 +
4752 + ipkg_message(conf, IPKG_INFO,
4753 + " cleanup temp files\n");
4754 + cleanup_temporary_files(conf, pkg);
4755 +
4756 + ipkg_message(conf, IPKG_INFO,
4757 + "Failed.\n");
4758 + if (use_signal)
4759 + signal(SIGINT, old_handler);
4760 + else
4761 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4762 +
4763 + return err;
4764 + }
4765 +}
4766 +
4767 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4768 +{
4769 + /* DPKG_INCOMPATIBILITY:
4770 + dpkg does some things here that we don't do yet. Do we care?
4771 +
4772 + 1. If a version of the package is already installed, call
4773 + old-prerm upgrade new-version
4774 + 2. If the script runs but exits with a non-zero exit status
4775 + new-prerm failed-upgrade old-version
4776 + Error unwind, for both the above cases:
4777 + old-postinst abort-upgrade new-version
4778 + */
4779 + return 0;
4780 +}
4781 +
4782 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4783 +{
4784 + /* DPKG_INCOMPATIBILITY:
4785 + dpkg does some things here that we don't do yet. Do we care?
4786 + (See prerm_upgrade_old_package for details)
4787 + */
4788 + return 0;
4789 +}
4790 +
4791 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4792 +{
4793 + /* DPKG_INCOMPATIBILITY:
4794 + dpkg does some things here that we don't do yet. Do we care?
4795 + 2. If a 'conflicting' package is being removed at the same time:
4796 + 1. If any packages depended on that conflicting package and
4797 + --auto-deconfigure is specified, call, for each such package:
4798 + deconfigured's-prerm deconfigure \
4799 + in-favour package-being-installed version \
4800 + removing conflicting-package version
4801 + Error unwind:
4802 + deconfigured's-postinst abort-deconfigure \
4803 + in-favour package-being-installed-but-failed version \
4804 + removing conflicting-package version
4805 +
4806 + The deconfigured packages are marked as requiring
4807 + configuration, so that if --install is used they will be
4808 + configured again if possible.
4809 + 2. To prepare for removal of the conflicting package, call:
4810 + conflictor's-prerm remove in-favour package new-version
4811 + Error unwind:
4812 + conflictor's-postinst abort-remove in-favour package new-version
4813 + */
4814 + return 0;
4815 +}
4816 +
4817 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4818 +{
4819 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4820 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4821 + details) */
4822 + return 0;
4823 +}
4824 +
4825 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4826 +{
4827 + int err;
4828 + char *preinst_args;
4829 +
4830 + if (old_pkg) {
4831 + char *old_version = pkg_version_str_alloc(old_pkg);
4832 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4833 + free(old_version);
4834 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4835 + char *pkg_version = pkg_version_str_alloc(pkg);
4836 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4837 + free(pkg_version);
4838 + } else {
4839 + preinst_args = strdup("install");
4840 + }
4841 +
4842 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4843 + if (err) {
4844 + ipkg_message(conf, IPKG_ERROR,
4845 + "Aborting installation of %s\n", pkg->name);
4846 + return 1;
4847 + }
4848 +
4849 + free(preinst_args);
4850 +
4851 + return 0;
4852 +}
4853 +
4854 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4855 +{
4856 + /* DPKG_INCOMPATIBILITY:
4857 + dpkg does the following error unwind, should we?
4858 + pkg->postrm abort-upgrade old-version
4859 + OR pkg->postrm abort-install old-version
4860 + OR pkg->postrm abort-install
4861 + */
4862 + return 0;
4863 +}
4864 +
4865 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4866 +{
4867 + int err;
4868 + conffile_list_elt_t *iter;
4869 + conffile_t *cf;
4870 +
4871 + if (conf->noaction) return 0;
4872 +
4873 + /* Backup all modified conffiles */
4874 + if (old_pkg) {
4875 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4876 + char *cf_name;
4877 +
4878 + cf = iter->data;
4879 + cf_name = root_filename_alloc(conf, cf->name);
4880 +
4881 + /* Don't worry if the conffile is just plain gone */
4882 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4883 + err = backup_make_backup(conf, cf_name);
4884 + if (err) {
4885 + return err;
4886 + }
4887 + }
4888 + free(cf_name);
4889 + }
4890 + }
4891 +
4892 + /* Backup all conffiles that were not conffiles in old_pkg */
4893 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4894 + char *cf_name;
4895 + cf = iter->data;
4896 + cf_name = root_filename_alloc(conf, cf->name);
4897 + /* Ignore if this was a conffile in old_pkg as well */
4898 + if (pkg_get_conffile(old_pkg, cf->name)) {
4899 + continue;
4900 + }
4901 +
4902 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4903 + err = backup_make_backup(conf, cf_name);
4904 + if (err) {
4905 + return err;
4906 + }
4907 + }
4908 + free(cf_name);
4909 + }
4910 +
4911 + return 0;
4912 +}
4913 +
4914 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4915 +{
4916 + conffile_list_elt_t *iter;
4917 +
4918 + if (old_pkg) {
4919 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4920 + backup_remove(iter->data->name);
4921 + }
4922 + }
4923 +
4924 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4925 + backup_remove(iter->data->name);
4926 + }
4927 +
4928 + return 0;
4929 +}
4930 +
4931 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4932 +{
4933 + /* DPKG_INCOMPATIBILITY:
4934 + ipkg takes a slightly different approach than dpkg at this
4935 + point. dpkg installs each file in the new package while
4936 + creating a backup for any file that is replaced, (so that it
4937 + can unwind if necessary). To avoid complexity and redundant
4938 + storage, ipkg doesn't do any installation until later, (at the
4939 + point at which dpkg removes the backups.
4940 +
4941 + But, we do have to check for data file clashes, since after
4942 + installing a package with a file clash, removing either of the
4943 + packages involved in the clash has the potential to break the
4944 + other package.
4945 + */
4946 + str_list_t *files_list;
4947 + str_list_elt_t *iter;
4948 +
4949 + int clashes = 0;
4950 +
4951 + files_list = pkg_get_installed_files(pkg);
4952 + for (iter = files_list->head; iter; iter = iter->next) {
4953 + char *root_filename;
4954 + char *filename = iter->data;
4955 + root_filename = root_filename_alloc(conf, filename);
4956 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4957 + pkg_t *owner;
4958 + pkg_t *obs;
4959 + /* Pre-existing conffiles are OK */
4960 + /* @@@@ should have way to check that it is a conffile -Jamey */
4961 + if (backup_exists_for(root_filename)) {
4962 + continue;
4963 + }
4964 +
4965 + /* Pre-existing files are OK if force-overwrite was asserted. */
4966 + if (conf->force_overwrite) {
4967 + /* but we need to change who owns this file */
4968 + file_hash_set_file_owner(conf, filename, pkg);
4969 + continue;
4970 + }
4971 +
4972 + owner = file_hash_get_file_owner(conf, filename);
4973 +
4974 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4975 + if (owner && old_pkg) {
4976 + if (strcmp(owner->name, old_pkg->name) == 0) {
4977 + continue;
4978 + }
4979 + }
4980 +
4981 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4982 + if (owner) {
4983 + if (pkg_replaces(pkg, owner)) {
4984 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4985 + continue;
4986 + }
4987 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4988 + then it's ok to overwrite. */
4989 + if (strcmp(owner->name,pkg->name)==0){
4990 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4991 + continue;
4992 + }
4993 + }
4994 +
4995 + /* Pre-existing files are OK if they are obsolete */
4996 + obs = hash_table_get(&conf->obs_file_hash, filename);
4997 + if (obs) {
4998 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
4999 + continue;
5000 + }
5001 +
5002 + /* We have found a clash. */
5003 + ipkg_message(conf, IPKG_ERROR,
5004 + "Package %s wants to install file %s\n"
5005 + "\tBut that file is already provided by package ",
5006 + pkg->name, filename);
5007 + if (owner) {
5008 + ipkg_message(conf, IPKG_ERROR,
5009 + "%s\n", owner->name);
5010 + } else {
5011 + ipkg_message(conf, IPKG_ERROR,
5012 + "<no package>\nPlease move this file out of the way and try again.\n");
5013 + }
5014 + clashes++;
5015 + }
5016 + free(root_filename);
5017 + }
5018 + pkg_free_installed_files(pkg);
5019 +
5020 + return clashes;
5021 +}
5022 +
5023 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5024 +{
5025 + /* Nothing to do since check_data_file_clashes doesn't change state */
5026 + return 0;
5027 +}
5028 +
5029 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5030 +{
5031 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5032 + 1. If the package is being upgraded, call
5033 + old-postrm upgrade new-version
5034 + 2. If this fails, attempt:
5035 + new-postrm failed-upgrade old-version
5036 + Error unwind, for both cases:
5037 + old-preinst abort-upgrade new-version */
5038 + return 0;
5039 +}
5040 +
5041 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5042 +{
5043 + /* DPKG_INCOMPATIBILITY:
5044 + dpkg does some things here that we don't do yet. Do we care?
5045 + (See postrm_upgrade_old_pkg for details)
5046 + */
5047 + return 0;
5048 +}
5049 +
5050 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5051 +{
5052 + int err;
5053 + str_list_t *old_files;
5054 + str_list_elt_t *of;
5055 + str_list_t *new_files;
5056 + str_list_elt_t *nf;
5057 +
5058 + if (old_pkg == NULL) {
5059 + return 0;
5060 + }
5061 +
5062 + old_files = pkg_get_installed_files(old_pkg);
5063 + new_files = pkg_get_installed_files(pkg);
5064 +
5065 + for (of = old_files->head; of; of = of->next) {
5066 + pkg_t *owner;
5067 + char *old, *new;
5068 + old = of->data;
5069 + for (nf = new_files->head; nf; nf = nf->next) {
5070 + new = nf->data;
5071 + if (strcmp(old, new) == 0) {
5072 + goto NOT_OBSOLETE;
5073 + }
5074 + }
5075 + if (file_is_dir(old)) {
5076 + continue;
5077 + }
5078 + owner = file_hash_get_file_owner(conf, old);
5079 + if (owner != old_pkg) {
5080 + /* in case obsolete file no longer belongs to old_pkg */
5081 + continue;
5082 + }
5083 +
5084 + /* old file is obsolete */
5085 + ipkg_message(conf, IPKG_INFO,
5086 + " removing obsolete file %s\n", old);
5087 + if (!conf->noaction) {
5088 + err = unlink(old);
5089 + if (err) {
5090 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5091 + strerror(errno));
5092 + }
5093 + }
5094 +
5095 + NOT_OBSOLETE:
5096 + ;
5097 + }
5098 +
5099 + pkg_free_installed_files(old_pkg);
5100 + pkg_free_installed_files(pkg);
5101 +
5102 + return 0;
5103 +}
5104 +
5105 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5106 +{
5107 + int i;
5108 + int err = 0;
5109 + char *globpattern;
5110 + glob_t globbuf;
5111 + if (0) {
5112 + if (!pkg->dest) {
5113 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5114 + return -1;
5115 + }
5116 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5117 + err = glob(globpattern, 0, NULL, &globbuf);
5118 + free(globpattern);
5119 + if (err) {
5120 + return err;
5121 + }
5122 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5123 + for (i = 0; i < globbuf.gl_pathc; i++) {
5124 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5125 + globbuf.gl_pathv[i], old_pkg->name);
5126 + if (!conf->noaction)
5127 + unlink(globbuf.gl_pathv[i]);
5128 + }
5129 + globfree(&globbuf);
5130 + }
5131 + return err;
5132 +}
5133 +
5134 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5135 +{
5136 + int ret;
5137 + char *prefix;
5138 +
5139 + if (old_pkg)
5140 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5141 + sprintf_alloc(&prefix, "%s.", pkg->name);
5142 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5143 + pkg->dest->info_dir,
5144 + prefix);
5145 + free(prefix);
5146 + return ret;
5147 +}
5148 +
5149 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5150 +{
5151 + /* DPKG_INCOMPATIBILITY:
5152 + This is a fairly sophisticated dpkg operation. Shall we
5153 + skip it? */
5154 +
5155 + /* Any packages all of whose files have been overwritten during the
5156 + installation, and which aren't required for dependencies, are
5157 + considered to have been removed. For each such package
5158 + 1. disappearer's-postrm disappear overwriter overwriter-version
5159 + 2. The package's maintainer scripts are removed
5160 + 3. It is noted in the status database as being in a sane state,
5161 + namely not installed (any conffiles it may have are ignored,
5162 + rather than being removed by dpkg). Note that disappearing
5163 + packages do not have their prerm called, because dpkg doesn't
5164 + know in advance that the package is going to vanish.
5165 + */
5166 + return 0;
5167 +}
5168 +
5169 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5170 +{
5171 + int err;
5172 +
5173 + /* ipkg takes a slightly different approach to data file backups
5174 + than dpkg. Rather than removing backups at this point, we
5175 + actually do the data file installation now. See comments in
5176 + check_data_file_clashes() for more details. */
5177 +
5178 + ipkg_message(conf, IPKG_INFO,
5179 + " extracting data files to %s\n", pkg->dest->root_dir);
5180 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5181 + if (err) {
5182 + return err;
5183 + }
5184 +
5185 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5186 + so we can't save ourself from removing important packages
5187 + At this point we (should) have extracted the .control file, so it
5188 + would be a good idea to reload the data in it, and set the Essential
5189 + state in *pkg. From now on the Essential is back in status file and
5190 + we can protect again.
5191 + We should operate this way:
5192 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5193 + check for "Essential" in it
5194 + set the value in pkg->essential.
5195 + This new routine could be useful also for every other flag
5196 + Pigi: 16/03/2004 */
5197 + set_flags_from_control(conf, pkg) ;
5198 +
5199 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5200 + err = pkg_write_filelist(conf, pkg);
5201 + if (err)
5202 + return err;
5203 +
5204 + /* XXX: FEATURE: ipkg should identify any files which existed
5205 + before installation and which were overwritten, (see
5206 + check_data_file_clashes()). What it must do is remove any such
5207 + files from the filelist of the old package which provided the
5208 + file. Otherwise, if the old package were removed at some point
5209 + it would break the new package. Removing the new package will
5210 + also break the old one, but this cannot be helped since the old
5211 + package's file has already been deleted. This is the importance
5212 + of check_data_file_clashes(), and only allowing ipkg to install
5213 + a clashing package with a user force. */
5214 +
5215 + return 0;
5216 +}
5217 +
5218 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5219 +{
5220 + conffile_list_elt_t *iter;
5221 + conffile_t *cf;
5222 + char *cf_backup;
5223 +
5224 + char *md5sum;
5225 +
5226 +
5227 + if (conf->noaction) return 0;
5228 +
5229 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5230 + char *root_filename;
5231 + cf = iter->data;
5232 + root_filename = root_filename_alloc(conf, cf->name);
5233 +
5234 + /* Might need to initialize the md5sum for each conffile */
5235 + if (cf->value == NULL) {
5236 + cf->value = file_md5sum_alloc(root_filename);
5237 + }
5238 +
5239 + if (!file_exists(root_filename)) {
5240 + free(root_filename);
5241 + continue;
5242 + }
5243 +
5244 + cf_backup = backup_filename_alloc(root_filename);
5245 +
5246 +
5247 + if (file_exists(cf_backup)) {
5248 + /* Let's compute md5 to test if files are changed */
5249 + md5sum = file_md5sum_alloc(cf_backup);
5250 + if (strcmp( cf->value,md5sum) != 0 ) {
5251 + if (conf->force_defaults
5252 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5253 + rename(cf_backup, root_filename);
5254 + }
5255 + }
5256 + unlink(cf_backup);
5257 + free(md5sum);
5258 + }
5259 +
5260 + free(cf_backup);
5261 + free(root_filename);
5262 + }
5263 +
5264 + return 0;
5265 +}
5266 +
5267 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5268 +{
5269 + char *response;
5270 + const char *short_file_name;
5271 +
5272 + short_file_name = strrchr(file_name, '/');
5273 + if (short_file_name) {
5274 + short_file_name++;
5275 + } else {
5276 + short_file_name = file_name;
5277 + }
5278 +
5279 + while (1) {
5280 + response = get_user_response(" Configuration file '%s'\n"
5281 + " ==> File on system created by you or by a script.\n"
5282 + " ==> File also in package provided by package maintainer.\n"
5283 + " What would you like to do about it ? Your options are:\n"
5284 + " Y or I : install the package maintainer's version\n"
5285 + " N or O : keep your currently-installed version\n"
5286 + " D : show the differences between the versions (if diff is installed)\n"
5287 + " The default action is to keep your current version.\n"
5288 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5289 + if (strcmp(response, "y") == 0
5290 + || strcmp(response, "i") == 0
5291 + || strcmp(response, "yes") == 0) {
5292 + free(response);
5293 + return 0;
5294 + }
5295 +
5296 + if (strcmp(response, "d") == 0) {
5297 + char *cmd;
5298 +
5299 + free(response);
5300 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5301 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5302 + xsystem(cmd);
5303 + free(cmd);
5304 + printf(" [Press ENTER to continue]\n");
5305 + response = file_read_line_alloc(stdin);
5306 + free(response);
5307 + continue;
5308 + }
5309 +
5310 + free(response);
5311 + return 1;
5312 + }
5313 +}
5314 +
5315 +/* XXX: CLEANUP: I'd like to move all of the code for
5316 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5317 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5318 + pkg_deinit for example). */
5319 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5320 +{
5321 + DIR *tmp_dir;
5322 + struct dirent *dirent;
5323 + char *tmp_file;
5324 +
5325 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5326 +#error
5327 + ipkg_message(conf, IPKG_DEBUG,
5328 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5329 + __FUNCTION__, pkg->tmp_unpack_dir);
5330 + return 0;
5331 +#endif
5332 +
5333 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5334 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5335 + if (tmp_dir) {
5336 + while (1) {
5337 + dirent = readdir(tmp_dir);
5338 + if (dirent == NULL) {
5339 + break;
5340 + }
5341 + sprintf_alloc(&tmp_file, "%s/%s",
5342 + pkg->tmp_unpack_dir, dirent->d_name);
5343 + if (! file_is_dir(tmp_file)) {
5344 + unlink(tmp_file);
5345 + }
5346 + free(tmp_file);
5347 + }
5348 + closedir(tmp_dir);
5349 + rmdir(pkg->tmp_unpack_dir);
5350 + free(pkg->tmp_unpack_dir);
5351 + pkg->tmp_unpack_dir = NULL;
5352 + }
5353 + }
5354 +
5355 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5356 + pkg->name, pkg->local_filename, conf->tmp_dir);
5357 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5358 + unlink(pkg->local_filename);
5359 + free(pkg->local_filename);
5360 + pkg->local_filename = NULL;
5361 + }
5362 +
5363 + return 0;
5364 +}
5365 +
5366 +static char *backup_filename_alloc(const char *file_name)
5367 +{
5368 + char *backup;
5369 +
5370 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5371 +
5372 + return backup;
5373 +}
5374 +
5375 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5376 +{
5377 + int err;
5378 + char *backup;
5379 +
5380 + backup = backup_filename_alloc(file_name);
5381 + err = file_copy(file_name, backup);
5382 + if (err) {
5383 + ipkg_message(conf, IPKG_ERROR,
5384 + "%s: Failed to copy %s to %s\n",
5385 + __FUNCTION__, file_name, backup);
5386 + }
5387 +
5388 + free(backup);
5389 +
5390 + return err;
5391 +}
5392 +
5393 +static int backup_exists_for(const char *file_name)
5394 +{
5395 + int ret;
5396 + char *backup;
5397 +
5398 + backup = backup_filename_alloc(file_name);
5399 +
5400 + ret = file_exists(backup);
5401 +
5402 + free(backup);
5403 +
5404 + return ret;
5405 +}
5406 +
5407 +static int backup_remove(const char *file_name)
5408 +{
5409 + char *backup;
5410 +
5411 + backup = backup_filename_alloc(file_name);
5412 + unlink(backup);
5413 + free(backup);
5414 +
5415 + return 0;
5416 +}
5417 +
5418 +\f
5419 +
5420 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5421 +
5422 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5423 +{
5424 + /* first, remove the packages that need removing */
5425 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5426 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5427 + err = ipkg_remove_pkg(conf, pkg);
5428 + if (err) return err;
5429 + }
5430 + return 0;
5431 +}
5432 +
5433 +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)
5434 +{
5435 + int i;
5436 + /* now one more pass checking on the ones that need to be installed */
5437 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5438 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5439 + if (pkg->dest == NULL)
5440 + pkg->dest = conf->default_dest;
5441 +
5442 + pkg->state_want = SW_INSTALL;
5443 +
5444 + /* Abhaya: conflicts check */
5445 + err = check_conflicts_for(conf, pkg);
5446 + if (err) { return err; }
5447 + }
5448 + return 0;
5449 +}
5450 +
5451 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5452 +{
5453 + int i;
5454 + /* now one more pass checking on the ones that need to be installed */
5455 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5456 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5457 +
5458 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5459 + pkg_vec_t *replacees = pkg_vec_alloc();
5460 + pkg_get_installed_replacees(conf, pkg, replacees);
5461 +
5462 + /* XXX: BUG: we really should treat replacement more like an upgrade
5463 + * Instead, we're going to remove the replacees
5464 + */
5465 + err = pkg_remove_installed_replacees(conf, replacees);
5466 + if (err) return err;
5467 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5468 + }
5469 + return 0;
5470 +}
5471 +
5472 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5473 +{
5474 + int i;
5475 + /* now one more pass checking on the ones that need to be installed */
5476 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5477 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5478 + if (pkg->local_filename == NULL) {
5479 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5480 + if (err) {
5481 + ipkg_message(conf, IPKG_ERROR,
5482 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5483 + pkg->name);
5484 + return err;
5485 + }
5486 + }
5487 + if (pkg->tmp_unpack_dir == NULL) {
5488 + err = unpack_pkg_control_files(conf, pkg);
5489 + if (err) return err;
5490 + }
5491 + }
5492 + return 0;
5493 +}
5494 +
5495 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5496 +{
5497 + int i;
5498 + /* now one more pass checking on the ones that need to be installed */
5499 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5500 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5501 + pkg_t *old_pkg = pkg->old_pkg;
5502 +
5503 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5504 + if (err) return err;
5505 +
5506 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5507 + if (err) return err;
5508 +
5509 + err = preinst_configure(conf, pkg, old_pkg);
5510 + if (err) return err;
5511 +
5512 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5513 + if (err) return err;
5514 +
5515 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5516 + if (err) return err;
5517 + }
5518 + return 0;
5519 +}
5520 +
5521 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5522 +{
5523 + int i;
5524 + /* now one more pass checking on the ones that need to be installed */
5525 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5526 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5527 + pkg_t *old_pkg = pkg->old_pkg;
5528 +
5529 + if (old_pkg) {
5530 + old_pkg->state_want = SW_DEINSTALL;
5531 +
5532 + if (old_pkg->state_flag & SF_NOPRUNE) {
5533 + ipkg_message(conf, IPKG_INFO,
5534 + " not removing obsolesced files because package marked noprune\n");
5535 + } else {
5536 + ipkg_message(conf, IPKG_INFO,
5537 + " removing obsolesced files\n");
5538 + remove_obsolesced_files(conf, pkg, old_pkg);
5539 + }
5540 + }
5541 +
5542 + ipkg_message(conf, IPKG_INFO,
5543 + " installing maintainer scripts\n");
5544 + install_maintainer_scripts(conf, pkg, old_pkg);
5545 +
5546 + /* the following just returns 0 */
5547 + remove_disappeared(conf, pkg);
5548 +
5549 + ipkg_message(conf, IPKG_INFO,
5550 + " installing data files\n");
5551 + install_data_files(conf, pkg);
5552 +
5553 + ipkg_message(conf, IPKG_INFO,
5554 + " resolving conf files\n");
5555 + resolve_conffiles(conf, pkg);
5556 +
5557 + pkg->state_status = SS_UNPACKED;
5558 +
5559 + if (old_pkg) {
5560 + old_pkg->state_status = SS_NOT_INSTALLED;
5561 + }
5562 +
5563 + time(&pkg->installed_time);
5564 +
5565 + ipkg_message(conf, IPKG_INFO,
5566 + " cleanup temp files\n");
5567 + cleanup_temporary_files(conf, pkg);
5568 +
5569 + if (pkg->parent)
5570 + pkg->parent->state_status = pkg->state_status;
5571 + }
5572 + return 0;
5573 +}
5574 +
5575 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5576 +{
5577 + int i;
5578 + /* now one more pass checking on the ones that need to be installed */
5579 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5580 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5581 + pkg_t *old_pkg = pkg->old_pkg;
5582 +
5583 + if (old_pkg) {
5584 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5585 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5586 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5587 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5588 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5589 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5590 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5591 + preinst_configure_unwind(conf, pkg, old_pkg);
5592 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5593 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5594 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5595 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5596 +
5597 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5598 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5599 +
5600 + }
5601 + }
5602 + return 0;
5603 +}
5604 +
5605 +/*
5606 + * Perform all the actions.
5607 + *
5608 + * pkgs_to_remove are packages marked for removal.
5609 + * pkgs_superseded are the old packages being replaced by upgrades.
5610 + *
5611 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5612 + */
5613 +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)
5614 +{
5615 + int err;
5616 + int i;
5617 +
5618 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5619 + if (err) return err;
5620 +
5621 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5622 + if (err) return err;
5623 +
5624 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5625 + if (err) goto UNWIND;
5626 +
5627 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5628 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5629 + if (err) goto UNWIND;
5630 +
5631 + /*
5632 + * Now that we have the packages unpacked, we can look for data
5633 + * file clashes. First, we mark the files from the superseded
5634 + * packages as obsolete. Then we scan the files in
5635 + * pkgs_to_install, and only complain about clashes with
5636 + * non-obsolete files.
5637 + */
5638 +
5639 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5640 + if (err) goto UNWIND;
5641 +
5642 + /* this was before checking data file clashes */
5643 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5644 + if (err) goto UNWIND;
5645 +
5646 + /* point of no return: no unwinding after this */
5647 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5648 + if (err) return err;
5649 +
5650 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5651 + return 0;
5652 +
5653 + UNWIND:
5654 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5655 +
5656 + ipkg_message(conf, IPKG_INFO,
5657 + " cleanup temp files\n");
5658 + cleanup_temporary_files(conf, pkg);
5659 +
5660 + ipkg_message(conf, IPKG_INFO,
5661 + "Failed.\n");
5662 + return err;
5663 +}
5664 +
5665 +#endif
5666 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_install.h busybox-1.1.1-new/archival/libipkg/ipkg_install.h
5667 --- busybox-1.1.1-old/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5668 +++ busybox-1.1.1-new/archival/libipkg/ipkg_install.h 2006-03-30 00:39:48.000000000 +0200
5669 @@ -0,0 +1,35 @@
5670 +/* ipkg_install.h - the itsy package management system
5671 +
5672 + Carl D. Worth
5673 +
5674 + Copyright (C) 2001 University of Southern California
5675 +
5676 + This program is free software; you can redistribute it and/or
5677 + modify it under the terms of the GNU General Public License as
5678 + published by the Free Software Foundation; either version 2, or (at
5679 + your option) any later version.
5680 +
5681 + This program is distributed in the hope that it will be useful, but
5682 + WITHOUT ANY WARRANTY; without even the implied warranty of
5683 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5684 + General Public License for more details.
5685 +*/
5686 +
5687 +#ifndef IPKG_INSTALL_H
5688 +#define IPKG_INSTALL_H
5689 +
5690 +#include "pkg.h"
5691 +#include "ipkg_conf.h"
5692 +
5693 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5694 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5695 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5696 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg);
5697 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5698 +
5699 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5700 +
5701 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5702 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5703 +
5704 +#endif
5705 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_message.c busybox-1.1.1-new/archival/libipkg/ipkg_message.c
5706 --- busybox-1.1.1-old/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5707 +++ busybox-1.1.1-new/archival/libipkg/ipkg_message.c 2006-03-30 00:39:48.000000000 +0200
5708 @@ -0,0 +1,61 @@
5709 +/* ipkg_message.c - the itsy package management system
5710 +
5711 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5712 +
5713 + This program is free software; you can redistribute it and/or
5714 + modify it under the terms of the GNU General Public License as
5715 + published by the Free Software Foundation; either version 2, or (at
5716 + your option) any later version.
5717 +
5718 + This program is distributed in the hope that it will be useful, but
5719 + WITHOUT ANY WARRANTY; without even the implied warranty of
5720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5721 + General Public License for more details.
5722 +*/
5723 +
5724 +
5725 +#include "ipkg.h"
5726 +#include "ipkg_conf.h"
5727 +#include "ipkg_message.h"
5728 +
5729 +#ifndef IPKG_LIB
5730 +
5731 +void
5732 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5733 +{
5734 + va_list ap;
5735 +
5736 + if (conf && (conf->verbosity < level))
5737 + {
5738 + return;
5739 + }
5740 + else
5741 + {
5742 +
5743 + va_start (ap, fmt);
5744 + vprintf (fmt, ap);
5745 + va_end (ap);
5746 + }
5747 +}
5748 +
5749 +#else
5750 +
5751 +#include "libipkg.h"
5752 +
5753 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5754 +
5755 +void
5756 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5757 +{
5758 + va_list ap;
5759 + char ts[256];
5760 +
5761 + if (ipkg_cb_message)
5762 + {
5763 + va_start (ap, fmt);
5764 + vsnprintf (ts,256,fmt, ap);
5765 + va_end (ap);
5766 + ipkg_cb_message(conf,level,ts);
5767 + }
5768 +}
5769 +#endif
5770 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_message.h busybox-1.1.1-new/archival/libipkg/ipkg_message.h
5771 --- busybox-1.1.1-old/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5772 +++ busybox-1.1.1-new/archival/libipkg/ipkg_message.h 2006-03-30 00:39:48.000000000 +0200
5773 @@ -0,0 +1,32 @@
5774 +/* ipkg_message.h - the itsy package management system
5775 +
5776 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5777 +
5778 + This program is free software; you can redistribute it and/or
5779 + modify it under the terms of the GNU General Public License as
5780 + published by the Free Software Foundation; either version 2, or (at
5781 + your option) any later version.
5782 +
5783 + This program is distributed in the hope that it will be useful, but
5784 + WITHOUT ANY WARRANTY; without even the implied warranty of
5785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5786 + General Public License for more details.
5787 +*/
5788 +
5789 +#ifndef _IPKG_MESSAGE_H_
5790 +#define _IPKG_MESSAGE_H_
5791 +
5792 +#include "ipkg.h"
5793 +#include "ipkg_conf.h"
5794 +
5795 +typedef enum {
5796 + IPKG_ERROR, /* error conditions */
5797 + IPKG_NOTICE, /* normal but significant condition */
5798 + IPKG_INFO, /* informational message */
5799 + IPKG_DEBUG, /* debug level message */
5800 + IPKG_DEBUG2, /* more debug level message */
5801 +} message_level_t;
5802 +
5803 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5804 +
5805 +#endif /* _IPKG_MESSAGE_H_ */
5806 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_remove.c busybox-1.1.1-new/archival/libipkg/ipkg_remove.c
5807 --- busybox-1.1.1-old/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5808 +++ busybox-1.1.1-new/archival/libipkg/ipkg_remove.c 2006-03-30 00:39:48.000000000 +0200
5809 @@ -0,0 +1,381 @@
5810 +/* ipkg_remove.c - the itsy package management system
5811 +
5812 + Carl D. Worth
5813 +
5814 + Copyright (C) 2001 University of Southern California
5815 +
5816 + This program is free software; you can redistribute it and/or
5817 + modify it under the terms of the GNU General Public License as
5818 + published by the Free Software Foundation; either version 2, or (at
5819 + your option) any later version.
5820 +
5821 + This program is distributed in the hope that it will be useful, but
5822 + WITHOUT ANY WARRANTY; without even the implied warranty of
5823 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5824 + General Public License for more details.
5825 +*/
5826 +
5827 +#include "ipkg.h"
5828 +#include "ipkg_message.h"
5829 +
5830 +#include <glob.h>
5831 +
5832 +#include "ipkg_remove.h"
5833 +
5834 +#include "file_util.h"
5835 +#include "sprintf_alloc.h"
5836 +#include "str_util.h"
5837 +
5838 +#include "ipkg_cmd.h"
5839 +
5840 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
5841 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5842 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5843 +
5844 +/*
5845 + * Returns number of the number of packages depending on the packages provided by this package.
5846 + * Every package implicitly provides itself.
5847 + */
5848 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5849 +{
5850 + int nprovides = pkg->provides_count;
5851 + abstract_pkg_t **provides = pkg->provides;
5852 + int n_installed_dependents = 0;
5853 + int i;
5854 + for (i = 0; i <= nprovides; i++) {
5855 + abstract_pkg_t *providee = provides[i];
5856 + abstract_pkg_t **dependers = providee->depended_upon_by;
5857 + abstract_pkg_t *dep_ab_pkg;
5858 + if (dependers == NULL)
5859 + continue;
5860 + while ((dep_ab_pkg = *dependers++) != NULL) {
5861 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5862 + n_installed_dependents++;
5863 + }
5864 + }
5865 +
5866 + }
5867 + /* if caller requested the set of installed dependents */
5868 + if (pdependents) {
5869 + int p = 0;
5870 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5871 +
5872 + if ( dependents == NULL ){
5873 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5874 + return -1;
5875 + }
5876 +
5877 + *pdependents = dependents;
5878 + for (i = 0; i <= nprovides; i++) {
5879 + abstract_pkg_t *providee = provides[i];
5880 + abstract_pkg_t **dependers = providee->depended_upon_by;
5881 + abstract_pkg_t *dep_ab_pkg;
5882 + if (dependers == NULL)
5883 + continue;
5884 + while ((dep_ab_pkg = *dependers++) != NULL) {
5885 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5886 + dependents[p++] = dep_ab_pkg;
5887 + dep_ab_pkg->state_flag |= SF_MARKED;
5888 + }
5889 + }
5890 + }
5891 + dependents[p] = NULL;
5892 + /* now clear the marks */
5893 + for (i = 0; i < p; i++) {
5894 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5895 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5896 + }
5897 + }
5898 + return n_installed_dependents;
5899 +}
5900 +
5901 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5902 +{
5903 + int i;
5904 + int a;
5905 + int count;
5906 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5907 + abstract_pkg_t * ab_pkg;
5908 +
5909 + if((ab_pkg = pkg->parent) == NULL){
5910 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5911 + __FUNCTION__, pkg->name);
5912 + return 0;
5913 + }
5914 +
5915 + if (dependents == NULL)
5916 + return 0;
5917 +
5918 + // here i am using the dependencies_checked
5919 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5920 + return 0; // has already been encountered in the process
5921 + // of marking packages for removal - Karthik
5922 + ab_pkg->dependencies_checked = 2;
5923 +
5924 + i = 0;
5925 + count = 1;
5926 + while (dependents [i] != NULL) {
5927 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5928 +
5929 + if (dep_ab_pkg->dependencies_checked == 2){
5930 + i++;
5931 + continue;
5932 + }
5933 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5934 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5935 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5936 + if (dep_pkg->state_status == SS_INSTALLED) {
5937 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5938 + count++;
5939 + }
5940 + }
5941 + }
5942 + i++;
5943 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5944 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5945 + }
5946 +
5947 + if (count == 1)
5948 + return 0;
5949 +
5950 +
5951 + for (i = 0; i < dependent_pkgs->len; i++) {
5952 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5953 + if (err)
5954 + return err;
5955 + }
5956 + return 0;
5957 +}
5958 +
5959 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5960 +{
5961 + abstract_pkg_t *dep_ab_pkg;
5962 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5963 + while ((dep_ab_pkg = *dependents++) != NULL) {
5964 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5965 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5966 + }
5967 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5968 + ipkg_message(conf, IPKG_ERROR, "");
5969 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5970 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5971 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5972 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5973 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5974 + return 0;
5975 +}
5976 +
5977 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5978 +{
5979 + int err;
5980 + abstract_pkg_t *parent_pkg = NULL;
5981 +
5982 + if (pkg->essential) {
5983 + if (conf->force_removal_of_essential_packages) {
5984 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5985 + "\tIf your system breaks, you get to keep both pieces\n",
5986 + pkg->name);
5987 + } else {
5988 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5989 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5990 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5991 + "\tits will with the option: -force-removal-of-essential-packages\n",
5992 + pkg->name);
5993 + return IPKG_PKG_IS_ESSENTIAL;
5994 + }
5995 + }
5996 +
5997 + if ((parent_pkg = pkg->parent) == NULL)
5998 + return 0;
5999 +
6000 + /* only attempt to remove dependent installed packages if
6001 + * force_depends is not specified or the package is being
6002 + * replaced.
6003 + */
6004 + if (!conf->force_depends
6005 + && !(pkg->state_flag & SF_REPLACE)) {
6006 + abstract_pkg_t **dependents;
6007 + int has_installed_dependents =
6008 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6009 +
6010 + if (has_installed_dependents) {
6011 + /*
6012 + * if this package is depended up by others, then either we should
6013 + * not remove it or we should remove it and all of its dependents
6014 + */
6015 +
6016 + if (!conf->force_removal_of_dependent_packages
6017 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6018 + return IPKG_PKG_HAS_DEPENDENTS;
6019 + }
6020 +
6021 + /* remove packages depending on this package - Karthik */
6022 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6023 + free(dependents);
6024 + if (err) return err;
6025 + }
6026 + }
6027 +
6028 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6029 + fflush(stdout);
6030 +
6031 + pkg->state_flag |= SF_FILELIST_CHANGED;
6032 +
6033 + pkg->state_want = SW_DEINSTALL;
6034 + ipkg_state_changed++;
6035 +
6036 + pkg_run_script(conf, pkg, "prerm", "remove");
6037 +
6038 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6039 + maintains an empty filelist rather than deleting it. That seems
6040 + like a big pain, and I don't see that that should make a big
6041 + difference, but for anyone who wants tighter compatibility,
6042 + feel free to fix this. */
6043 + remove_data_files_and_list(conf, pkg);
6044 +
6045 + pkg_run_script(conf, pkg, "postrm", "remove");
6046 +
6047 + remove_maintainer_scripts_except_postrm(conf, pkg);
6048 +
6049 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6050 + * space, it doesn't make sense to leave extra configurations, files,
6051 + * and maintainer scripts left around. So, we make remove like purge,
6052 + * and take out all the crap :) */
6053 +
6054 + remove_postrm(conf, pkg);
6055 + pkg->state_status = SS_NOT_INSTALLED;
6056 +
6057 + if (parent_pkg)
6058 + parent_pkg->state_status = SS_NOT_INSTALLED;
6059 +
6060 + return 0;
6061 +}
6062 +
6063 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6064 +{
6065 + ipkg_remove_pkg(conf, pkg);
6066 + return 0;
6067 +}
6068 +
6069 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6070 +{
6071 + str_list_t installed_dirs;
6072 + str_list_t *installed_files;
6073 + str_list_elt_t *iter;
6074 + char *file_name;
6075 + conffile_t *conffile;
6076 + int removed_a_dir;
6077 + pkg_t *owner;
6078 +
6079 + str_list_init(&installed_dirs);
6080 + installed_files = pkg_get_installed_files(pkg);
6081 +
6082 + for (iter = installed_files->head; iter; iter = iter->next) {
6083 + file_name = iter->data;
6084 +
6085 + if (file_is_dir(file_name)) {
6086 + str_list_append(&installed_dirs, strdup(file_name));
6087 + continue;
6088 + }
6089 +
6090 + conffile = pkg_get_conffile(pkg, file_name);
6091 + if (conffile) {
6092 + /* XXX: QUESTION: Is this right? I figure we only need to
6093 + save the conffile if it has been modified. Is that what
6094 + dpkg does? Or does dpkg preserve all conffiles? If so,
6095 + this seems like a better thing to do to conserve
6096 + space. */
6097 + if (conffile_has_been_modified(conf, conffile)) {
6098 + printf(" not deleting modified conffile %s\n", file_name);
6099 + fflush(stdout);
6100 + continue;
6101 + }
6102 + }
6103 +
6104 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6105 + if (!conf->noaction)
6106 + unlink(file_name);
6107 + }
6108 +
6109 + if (!conf->noaction) {
6110 + do {
6111 + removed_a_dir = 0;
6112 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6113 + file_name = iter->data;
6114 +
6115 + if (rmdir(file_name) == 0) {
6116 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6117 + removed_a_dir = 1;
6118 + str_list_remove(&installed_dirs, &iter);
6119 + }
6120 + }
6121 + } while (removed_a_dir);
6122 + }
6123 +
6124 + pkg_free_installed_files(pkg);
6125 + /* We have to remove the file list now, so that
6126 + find_pkg_owning_file does not always just report this package */
6127 + pkg_remove_installed_files_list(conf, pkg);
6128 +
6129 + /* Don't print warning for dirs that are provided by other packages */
6130 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6131 + file_name = iter->data;
6132 +
6133 + owner = file_hash_get_file_owner(conf, file_name);
6134 + if (owner) {
6135 + free(iter->data);
6136 + iter->data = NULL;
6137 + str_list_remove(&installed_dirs, &iter);
6138 + }
6139 + }
6140 +
6141 + /* cleanup */
6142 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6143 + free(iter->data);
6144 + iter->data = NULL;
6145 + }
6146 + str_list_deinit(&installed_dirs);
6147 +
6148 + return 0;
6149 +}
6150 +
6151 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6152 +{
6153 + int i, err;
6154 + char *globpattern;
6155 + glob_t globbuf;
6156 +
6157 + if (conf->noaction) return 0;
6158 +
6159 + sprintf_alloc(&globpattern, "%s/%s.*",
6160 + pkg->dest->info_dir, pkg->name);
6161 + err = glob(globpattern, 0, NULL, &globbuf);
6162 + free(globpattern);
6163 + if (err) {
6164 + return 0;
6165 + }
6166 +
6167 + for (i = 0; i < globbuf.gl_pathc; i++) {
6168 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6169 + continue;
6170 + }
6171 + unlink(globbuf.gl_pathv[i]);
6172 + }
6173 + globfree(&globbuf);
6174 +
6175 + return 0;
6176 +}
6177 +
6178 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6179 +{
6180 + char *postrm_file_name;
6181 +
6182 + if (conf->noaction) return 0;
6183 +
6184 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6185 + pkg->dest->info_dir, pkg->name);
6186 + unlink(postrm_file_name);
6187 + free(postrm_file_name);
6188 +
6189 + return 0;
6190 +}
6191 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_remove.h busybox-1.1.1-new/archival/libipkg/ipkg_remove.h
6192 --- busybox-1.1.1-old/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6193 +++ busybox-1.1.1-new/archival/libipkg/ipkg_remove.h 2006-03-30 00:39:48.000000000 +0200
6194 @@ -0,0 +1,29 @@
6195 +/* ipkg_remove.h - the itsy package management system
6196 +
6197 + Carl D. Worth
6198 +
6199 + Copyright (C) 2001 University of Southern California
6200 +
6201 + This program is free software; you can redistribute it and/or
6202 + modify it under the terms of the GNU General Public License as
6203 + published by the Free Software Foundation; either version 2, or (at
6204 + your option) any later version.
6205 +
6206 + This program is distributed in the hope that it will be useful, but
6207 + WITHOUT ANY WARRANTY; without even the implied warranty of
6208 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6209 + General Public License for more details.
6210 +*/
6211 +
6212 +#ifndef IPKG_REMOVE_H
6213 +#define IPKG_REMOVE_H
6214 +
6215 +#include "pkg.h"
6216 +#include "ipkg_conf.h"
6217 +
6218 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6219 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6220 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6221 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6222 +
6223 +#endif
6224 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.c busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.c
6225 --- busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6226 +++ busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.c 2006-03-30 00:39:48.000000000 +0200
6227 @@ -0,0 +1,77 @@
6228 +/* ipkg_upgrade.c - the itsy package management system
6229 +
6230 + Carl D. Worth
6231 + Copyright (C) 2001 University of Southern California
6232 +
6233 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6234 +
6235 + This program is free software; you can redistribute it and/or
6236 + modify it under the terms of the GNU General Public License as
6237 + published by the Free Software Foundation; either version 2, or (at
6238 + your option) any later version.
6239 +
6240 + This program is distributed in the hope that it will be useful, but
6241 + WITHOUT ANY WARRANTY; without even the implied warranty of
6242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6243 + General Public License for more details.
6244 +*/
6245 +
6246 +#include "ipkg.h"
6247 +#include "ipkg_install.h"
6248 +#include "ipkg_message.h"
6249 +
6250 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6251 +{
6252 + pkg_t *new;
6253 + int cmp;
6254 + char *old_version, *new_version;
6255 +
6256 + if (old->state_flag & SF_HOLD) {
6257 + ipkg_message(conf, IPKG_NOTICE,
6258 + "Not upgrading package %s which is marked "
6259 + "hold (flags=%#x)\n", old->name, old->state_flag);
6260 + return 0;
6261 + }
6262 +
6263 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6264 + if (new == NULL) {
6265 + old_version = pkg_version_str_alloc(old);
6266 + ipkg_message(conf, IPKG_NOTICE,
6267 + "Assuming locally installed package %s (%s) "
6268 + "is up to date.\n", old->name, old_version);
6269 + free(old_version);
6270 + return 0;
6271 + }
6272 +
6273 + old_version = pkg_version_str_alloc(old);
6274 + new_version = pkg_version_str_alloc(new);
6275 +
6276 + cmp = pkg_compare_versions(old, new);
6277 + ipkg_message(conf, IPKG_DEBUG,
6278 + "comparing visible versions of pkg %s:"
6279 + "\n\t%s is installed "
6280 + "\n\t%s is available "
6281 + "\n\t%d was comparison result\n",
6282 + old->name, old_version, new_version, cmp);
6283 + if (cmp == 0) {
6284 + ipkg_message(conf, IPKG_INFO,
6285 + "Package %s (%s) installed in %s is up to date.\n",
6286 + old->name, old_version, old->dest->name);
6287 + free(old_version);
6288 + free(new_version);
6289 + return 0;
6290 + } else if (cmp > 0) {
6291 + ipkg_message(conf, IPKG_NOTICE,
6292 + "Not downgrading package %s on %s from %s to %s.\n",
6293 + old->name, old->dest->name, old_version, new_version);
6294 + free(old_version);
6295 + free(new_version);
6296 + return 0;
6297 + } else if (cmp < 0) {
6298 + new->dest = old->dest;
6299 + old->state_want = SW_DEINSTALL;
6300 + }
6301 +
6302 + new->state_flag |= SF_USER;
6303 + return ipkg_install_pkg(conf, new);
6304 +}
6305 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.h busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.h
6306 --- busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6307 +++ busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.h 2006-03-30 00:39:48.000000000 +0200
6308 @@ -0,0 +1,18 @@
6309 +/* ipkg_upgrade.c - the itsy package management system
6310 +
6311 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6312 +
6313 + This program is free software; you can redistribute it and/or
6314 + modify it under the terms of the GNU General Public License as
6315 + published by the Free Software Foundation; either version 2, or (at
6316 + your option) any later version.
6317 +
6318 + This program is distributed in the hope that it will be useful, but
6319 + WITHOUT ANY WARRANTY; without even the implied warranty of
6320 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6321 + General Public License for more details.
6322 +*/
6323 +
6324 +#include "ipkg.h"
6325 +
6326 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6327 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_utils.c busybox-1.1.1-new/archival/libipkg/ipkg_utils.c
6328 --- busybox-1.1.1-old/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6329 +++ busybox-1.1.1-new/archival/libipkg/ipkg_utils.c 2006-03-30 00:39:48.000000000 +0200
6330 @@ -0,0 +1,181 @@
6331 +/* ipkg_utils.c - the itsy package management system
6332 +
6333 + Steven M. Ayer
6334 +
6335 + Copyright (C) 2002 Compaq Computer Corporation
6336 +
6337 + This program is free software; you can redistribute it and/or
6338 + modify it under the terms of the GNU General Public License as
6339 + published by the Free Software Foundation; either version 2, or (at
6340 + your option) any later version.
6341 +
6342 + This program is distributed in the hope that it will be useful, but
6343 + WITHOUT ANY WARRANTY; without even the implied warranty of
6344 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6345 + General Public License for more details.
6346 +*/
6347 +
6348 +#include "ipkg.h"
6349 +#include <errno.h>
6350 +#include <ctype.h>
6351 +#include <sys/vfs.h>
6352 +
6353 +#include "ipkg_utils.h"
6354 +#include "pkg.h"
6355 +#include "pkg_hash.h"
6356 +
6357 +struct errlist* error_list;
6358 +
6359 +int get_available_blocks(char * filesystem)
6360 +{
6361 + struct statfs sfs;
6362 +
6363 + if(statfs(filesystem, &sfs)){
6364 + fprintf(stderr, "bad statfs\n");
6365 + return 0;
6366 + }
6367 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6368 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6369 +}
6370 +
6371 +char **read_raw_pkgs_from_file(const char *file_name)
6372 +{
6373 + FILE *fp;
6374 + char **ret;
6375 +
6376 + if(!(fp = fopen(file_name, "r"))){
6377 + fprintf(stderr, "can't get %s open for read\n", file_name);
6378 + return NULL;
6379 + }
6380 +
6381 + ret = read_raw_pkgs_from_stream(fp);
6382 +
6383 + fclose(fp);
6384 +
6385 + return ret;
6386 +}
6387 +
6388 +char **read_raw_pkgs_from_stream(FILE *fp)
6389 +{
6390 + char **raw = NULL, *buf, *scout;
6391 + int count = 0;
6392 + size_t size = 512;
6393 +
6394 + buf = malloc (size);
6395 +
6396 + while (fgets(buf, size, fp)) {
6397 + while (strlen (buf) == (size - 1)
6398 + && buf[size-2] != '\n') {
6399 + size_t o = size - 1;
6400 + size *= 2;
6401 + buf = realloc (buf, size);
6402 + if (fgets (buf + o, size - o, fp) == NULL)
6403 + break;
6404 + }
6405 +
6406 + if(!(count % 50))
6407 + raw = realloc(raw, (count + 50) * sizeof(char *));
6408 +
6409 + if((scout = strchr(buf, '\n')))
6410 + *scout = '\0';
6411 +
6412 + raw[count++] = strdup(buf);
6413 + }
6414 +
6415 + raw = realloc(raw, (count + 1) * sizeof(char *));
6416 + raw[count] = NULL;
6417 +
6418 + free (buf);
6419 +
6420 + return raw;
6421 +}
6422 +
6423 +/* something to remove whitespace, a hash pooper */
6424 +char *trim_alloc(char *line)
6425 +{
6426 + char *new;
6427 + char *dest, *src, *end;
6428 +
6429 + new = malloc(strlen(line) + 1);
6430 + if ( new == NULL ){
6431 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6432 + return NULL;
6433 + }
6434 + dest = new, src = line, end = line + (strlen(line) - 1);
6435 +
6436 + /* remove it from the front */
6437 + while(src &&
6438 + isspace(*src) &&
6439 + *src)
6440 + src++;
6441 + /* and now from the back */
6442 + while((end > src) &&
6443 + isspace(*end))
6444 + end--;
6445 + end++;
6446 + *end = '\0';
6447 + strcpy(new, src);
6448 + /* this does from the first space
6449 + * blasting away any versions stuff in depends
6450 + while(src &&
6451 + !isspace(*src) &&
6452 + *src)
6453 + *dest++ = *src++;
6454 + *dest = '\0';
6455 + */
6456 +
6457 + return new;
6458 +}
6459 +
6460 +int line_is_blank(const char *line)
6461 +{
6462 + const char *s;
6463 +
6464 + for (s = line; *s; s++) {
6465 + if (!isspace(*s))
6466 + return 0;
6467 + }
6468 + return 1;
6469 +}
6470 +
6471 +void push_error_list(struct errlist ** errors, char * msg){
6472 + struct errlist *err_lst_tmp;
6473 +
6474 +
6475 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6476 + err_lst_tmp->errmsg=strdup(msg) ;
6477 + err_lst_tmp->next = *errors;
6478 + *errors = err_lst_tmp;
6479 +}
6480 +
6481 +
6482 +void reverse_error_list(struct errlist **errors){
6483 + struct errlist *result=NULL;
6484 + struct errlist *current= *errors;
6485 + struct errlist *next;
6486 +
6487 + while ( current != NULL ) {
6488 + next = current->next;
6489 + current->next=result;
6490 + result=current;
6491 + current=next;
6492 + }
6493 + *errors=result;
6494 +
6495 +}
6496 +
6497 +
6498 +void free_error_list(struct errlist **errors){
6499 + struct errlist *current = *errors;
6500 +
6501 + while (current != NULL) {
6502 + free(current->errmsg);
6503 + current = (*errors)->next;
6504 + free(*errors);
6505 + *errors = current;
6506 + }
6507 +
6508 +
6509 +}
6510 +
6511 +
6512 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_utils.h busybox-1.1.1-new/archival/libipkg/ipkg_utils.h
6513 --- busybox-1.1.1-old/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6514 +++ busybox-1.1.1-new/archival/libipkg/ipkg_utils.h 2006-03-30 00:39:48.000000000 +0200
6515 @@ -0,0 +1,29 @@
6516 +/* ipkg_utils.h - the itsy package management system
6517 +
6518 + Steven M. Ayer
6519 +
6520 + Copyright (C) 2002 Compaq Computer Corporation
6521 +
6522 + This program is free software; you can redistribute it and/or
6523 + modify it under the terms of the GNU General Public License as
6524 + published by the Free Software Foundation; either version 2, or (at
6525 + your option) any later version.
6526 +
6527 + This program is distributed in the hope that it will be useful, but
6528 + WITHOUT ANY WARRANTY; without even the implied warranty of
6529 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6530 + General Public License for more details.
6531 +*/
6532 +
6533 +#ifndef IPKG_UTILS_H
6534 +#define IPKG_UTILS_H
6535 +
6536 +#include "pkg.h"
6537 +
6538 +int get_available_blocks(char * filesystem);
6539 +char **read_raw_pkgs_from_file(const char *file_name);
6540 +char **read_raw_pkgs_from_stream(FILE *fp);
6541 +char *trim_alloc(char * line);
6542 +int line_is_blank(const char *line);
6543 +
6544 +#endif
6545 diff -ruN busybox-1.1.1-old/archival/libipkg/libipkg.c busybox-1.1.1-new/archival/libipkg/libipkg.c
6546 --- busybox-1.1.1-old/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6547 +++ busybox-1.1.1-new/archival/libipkg/libipkg.c 2006-03-30 00:39:48.000000000 +0200
6548 @@ -0,0 +1,512 @@
6549 +/* ipkglib.c - the itsy package management system
6550 +
6551 + Florina Boor
6552 +
6553 + Copyright (C) 2003 kernel concepts
6554 +
6555 + This program is free software; you can redistribute it and/or
6556 + modify it under the terms of the GNU General Public License as
6557 + published by the Free Software Foundation; either version 2, or (at
6558 + your option) any later version.
6559 +
6560 + This program is distributed in the hope that it will be useful, but
6561 + WITHOUT ANY WARRANTY; without even the implied warranty of
6562 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6563 + General Public License for more details.
6564 +*/
6565 +
6566 +#ifdef IPKG_LIB
6567 +
6568 +#include "ipkg.h"
6569 +#include "ipkg_includes.h"
6570 +#include "libipkg.h"
6571 +
6572 +#include "args.h"
6573 +#include "ipkg_conf.h"
6574 +#include "ipkg_cmd.h"
6575 +#include "file_util.h"
6576 +
6577 +
6578 +
6579 +ipkg_message_callback ipkg_cb_message = NULL;
6580 +ipkg_response_callback ipkg_cb_response = NULL;
6581 +ipkg_status_callback ipkg_cb_status = NULL;
6582 +ipkg_list_callback ipkg_cb_list = NULL;
6583 +
6584 +
6585 +int
6586 +ipkg_init (ipkg_message_callback mcall,
6587 + ipkg_response_callback rcall,
6588 + args_t * args)
6589 +{
6590 + ipkg_cb_message = mcall;
6591 + ipkg_cb_response = rcall;
6592 +
6593 + args_init (args);
6594 +
6595 + return 0;
6596 +}
6597 +
6598 +
6599 +int
6600 +ipkg_deinit (args_t * args)
6601 +{
6602 + args_deinit (args);
6603 + ipkg_cb_message = NULL;
6604 + ipkg_cb_response = NULL;
6605 +
6606 + /* place other cleanup stuff here */
6607 +
6608 + return 0;
6609 +}
6610 +
6611 +
6612 +int
6613 +ipkg_packages_list(args_t *args,
6614 + const char *packages,
6615 + ipkg_list_callback cblist,
6616 + void *userdata)
6617 +{
6618 + ipkg_cmd_t *cmd;
6619 + ipkg_conf_t ipkg_conf;
6620 + int err;
6621 +
6622 + err = ipkg_conf_init (&ipkg_conf, args);
6623 + if (err)
6624 + {
6625 + return err;
6626 + }
6627 +
6628 + ipkg_cb_list = cblist;
6629 + /* we need to do this because of static declarations,
6630 + * maybe a good idea to change */
6631 + cmd = ipkg_cmd_find ("list");
6632 + if (packages)
6633 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6634 + else
6635 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6636 + ipkg_cb_list = NULL;
6637 + ipkg_conf_deinit (&ipkg_conf);
6638 + return (err);
6639 +}
6640 +
6641 +
6642 +int
6643 +ipkg_packages_status(args_t *args,
6644 + const char *packages,
6645 + ipkg_status_callback cbstatus,
6646 + void *userdata)
6647 +{
6648 + ipkg_cmd_t *cmd;
6649 + ipkg_conf_t ipkg_conf;
6650 + int err;
6651 +
6652 + err = ipkg_conf_init (&ipkg_conf, args);
6653 + if (err)
6654 + {
6655 + return err;
6656 + }
6657 +
6658 + ipkg_cb_status = cbstatus;
6659 +
6660 + /* we need to do this because of static declarations,
6661 + * maybe a good idea to change */
6662 + cmd = ipkg_cmd_find ("status");
6663 + if (packages)
6664 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6665 + else
6666 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6667 +
6668 + ipkg_cb_status = NULL;
6669 + ipkg_conf_deinit (&ipkg_conf);
6670 + return (err);
6671 +}
6672 +
6673 +
6674 +int
6675 +ipkg_packages_info(args_t *args,
6676 + const char *packages,
6677 + ipkg_status_callback cbstatus,
6678 + void *userdata)
6679 +{
6680 + ipkg_cmd_t *cmd;
6681 + ipkg_conf_t ipkg_conf;
6682 + int err;
6683 +
6684 + err = ipkg_conf_init (&ipkg_conf, args);
6685 + if (err)
6686 + {
6687 + return err;
6688 + }
6689 +
6690 + ipkg_cb_status = cbstatus;
6691 +
6692 + /* we need to do this because of static declarations,
6693 + * maybe a good idea to change */
6694 + cmd = ipkg_cmd_find ("info");
6695 + if (packages)
6696 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6697 + else
6698 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6699 +
6700 + ipkg_cb_status = NULL;
6701 + ipkg_conf_deinit (&ipkg_conf);
6702 + return (err);
6703 +}
6704 +
6705 +
6706 +int
6707 +ipkg_packages_install (args_t * args, const char *name)
6708 +{
6709 + ipkg_cmd_t *cmd;
6710 + ipkg_conf_t ipkg_conf;
6711 + int err;
6712 +
6713 + /* this error should be handled in application */
6714 + if (!name || !strlen (name))
6715 + return (-1);
6716 +
6717 + err = ipkg_conf_init (&ipkg_conf, args);
6718 + if (err)
6719 + {
6720 + return err;
6721 + }
6722 +
6723 + /* we need to do this because of static declarations,
6724 + * maybe a good idea to change */
6725 + cmd = ipkg_cmd_find ("install");
6726 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6727 +
6728 + ipkg_conf_deinit(&ipkg_conf);
6729 + return (err);
6730 +}
6731 +
6732 +
6733 +int
6734 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6735 +{
6736 + ipkg_cmd_t *cmd;
6737 + ipkg_conf_t ipkg_conf;
6738 + int err;
6739 +
6740 + /* this error should be handled in application */
6741 + if (!name || !strlen (name))
6742 + return (-1);
6743 +
6744 + err = ipkg_conf_init (&ipkg_conf, args);
6745 + if (err)
6746 + {
6747 + return err;
6748 + }
6749 +
6750 + /* we need to do this because of static declarations,
6751 + * maybe a good idea to change */
6752 + if (purge)
6753 + cmd = ipkg_cmd_find ("purge");
6754 + else
6755 + cmd = ipkg_cmd_find ("remove");
6756 +
6757 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6758 +
6759 + ipkg_conf_deinit(&ipkg_conf);
6760 + return (err);
6761 +}
6762 +
6763 +
6764 +int
6765 +ipkg_lists_update(args_t *args)
6766 +{
6767 + ipkg_cmd_t *cmd;
6768 + ipkg_conf_t ipkg_conf;
6769 + int err;
6770 +
6771 + err = ipkg_conf_init (&ipkg_conf, args);
6772 + if (err)
6773 + {
6774 + return err;
6775 + }
6776 +
6777 + /* we need to do this because of static declarations,
6778 + * maybe a good idea to change */
6779 + cmd = ipkg_cmd_find ("update");
6780 +
6781 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6782 +
6783 + ipkg_conf_deinit(&ipkg_conf);
6784 + return (err);
6785 +}
6786 +
6787 +
6788 +int
6789 +ipkg_packages_upgrade(args_t *args)
6790 +{
6791 + ipkg_cmd_t *cmd;
6792 + ipkg_conf_t ipkg_conf;
6793 + int err;
6794 +
6795 + err = ipkg_conf_init (&ipkg_conf, args);
6796 + if (err)
6797 + {
6798 + return err;
6799 + }
6800 +
6801 + /* we need to do this because of static declarations,
6802 + * maybe a good idea to change */
6803 + cmd = ipkg_cmd_find ("upgrade");
6804 +
6805 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6806 +
6807 + ipkg_conf_deinit(&ipkg_conf);
6808 + return (err);
6809 +}
6810 +
6811 +
6812 +int
6813 +ipkg_packages_download (args_t * args, const char *name)
6814 +{
6815 + ipkg_cmd_t *cmd;
6816 + ipkg_conf_t ipkg_conf;
6817 + int err;
6818 +
6819 + /* this error should be handled in application */
6820 + if (!name || !strlen (name))
6821 + return (-1);
6822 +
6823 + err = ipkg_conf_init (&ipkg_conf, args);
6824 + if (err)
6825 + {
6826 + return err;
6827 + }
6828 +
6829 + /* we need to do this because of static declarations,
6830 + * maybe a good idea to change */
6831 + cmd = ipkg_cmd_find ("download");
6832 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6833 +
6834 + ipkg_conf_deinit(&ipkg_conf);
6835 + return (err);
6836 +}
6837 +
6838 +
6839 +int
6840 +ipkg_package_files(args_t *args,
6841 + const char *name,
6842 + ipkg_list_callback cblist,
6843 + void *userdata)
6844 +{
6845 + ipkg_cmd_t *cmd;
6846 + ipkg_conf_t ipkg_conf;
6847 + int err;
6848 +
6849 + /* this error should be handled in application */
6850 + if (!name || !strlen (name))
6851 + return (-1);
6852 +
6853 + err = ipkg_conf_init (&ipkg_conf, args);
6854 + if (err)
6855 + {
6856 + return err;
6857 + }
6858 +
6859 + ipkg_cb_list = cblist;
6860 +
6861 + /* we need to do this because of static declarations,
6862 + * maybe a good idea to change */
6863 + cmd = ipkg_cmd_find ("files");
6864 +
6865 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6866 +
6867 + ipkg_cb_list = NULL;
6868 + ipkg_conf_deinit(&ipkg_conf);
6869 + return (err);
6870 +}
6871 +
6872 +
6873 +int
6874 +ipkg_file_search(args_t *args,
6875 + const char *file,
6876 + ipkg_list_callback cblist,
6877 + void *userdata)
6878 +{
6879 + ipkg_cmd_t *cmd;
6880 + ipkg_conf_t ipkg_conf;
6881 + int err;
6882 +
6883 + /* this error should be handled in application */
6884 + if (!file || !strlen (file))
6885 + return (-1);
6886 +
6887 + err = ipkg_conf_init (&ipkg_conf, args);
6888 + if (err)
6889 + {
6890 + return err;
6891 + }
6892 +
6893 + ipkg_cb_list = cblist;
6894 +
6895 + /* we need to do this because of static declarations,
6896 + * maybe a good idea to change */
6897 + cmd = ipkg_cmd_find ("search");
6898 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6899 +
6900 + ipkg_cb_list = NULL;
6901 + ipkg_conf_deinit(&ipkg_conf);
6902 + return(err);
6903 +}
6904 +
6905 +
6906 +int
6907 +ipkg_file_what(args_t *args, const char *file, const char* command)
6908 +{
6909 + ipkg_cmd_t *cmd;
6910 + ipkg_conf_t ipkg_conf;
6911 + int err;
6912 +
6913 + /* this error should be handled in application */
6914 + if (!file || !strlen (file))
6915 + return (-1);
6916 +
6917 + err = ipkg_conf_init (&ipkg_conf, args);
6918 + if (err)
6919 + {
6920 + return err;
6921 + }
6922 +
6923 + /* we need to do this because of static declarations,
6924 + * maybe a good idea to change */
6925 + cmd = ipkg_cmd_find (command);
6926 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6927 +
6928 + ipkg_conf_deinit(&ipkg_conf);
6929 + return(err);
6930 +}
6931 +
6932 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6933 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6934 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6935 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6936 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6937 +
6938 +
6939 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6940 + char *msg)
6941 +{
6942 + if (conf && (conf->verbosity < level)) {
6943 + return 0;
6944 + } else {
6945 +#ifdef IPKG_LIB
6946 + if ( level == IPKG_ERROR ){
6947 + push_error_list(&error_list, msg);
6948 +// printf(msg);
6949 + } else
6950 +#endif
6951 + printf(msg);
6952 + }
6953 + return 0;
6954 +}
6955 +
6956 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6957 + pkg_state_status_t status, void *userdata)
6958 +{
6959 + if (desc)
6960 + printf("%s - %s - %s\n", name, version, desc);
6961 + else
6962 + printf("%s - %s\n", name, version);
6963 + return 0;
6964 +}
6965 +
6966 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6967 + pkg_state_status_t status, void *userdata)
6968 +{
6969 + if (desc)
6970 + printf("%s\n", desc);
6971 + return 0;
6972 +}
6973 +
6974 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6975 + void *userdata)
6976 +{
6977 + printf("%s\n", desc);
6978 + return 0;
6979 +}
6980 +
6981 +char* default_ipkg_response_callback(char *question)
6982 +{
6983 + char *response = NULL;
6984 + printf(question);
6985 + fflush(stdout);
6986 + do {
6987 + response = (char *)file_read_line_alloc(stdin);
6988 + } while (response == NULL);
6989 + return response;
6990 +}
6991 +
6992 +/* This is used for backward compatibility */
6993 +int
6994 +ipkg_op (int argc, char *argv[])
6995 +{
6996 + int err, optind;
6997 + args_t args;
6998 + char *cmd_name;
6999 + ipkg_cmd_t *cmd;
7000 + ipkg_conf_t ipkg_conf;
7001 +
7002 + args_init (&args);
7003 +
7004 + optind = args_parse (&args, argc, argv);
7005 + if (optind == argc || optind < 0)
7006 + {
7007 + args_usage ("ipkg must have one sub-command argument");
7008 + }
7009 +
7010 + cmd_name = argv[optind++];
7011 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7012 + read anything from there.
7013 +*/
7014 + if ( !strcmp(cmd_name,"print-architecture") ||
7015 + !strcmp(cmd_name,"print_architecture") ||
7016 + !strcmp(cmd_name,"print-installation-architecture") ||
7017 + !strcmp(cmd_name,"print_installation_architecture") )
7018 + args.nocheckfordirorfile = 1;
7019 +
7020 +
7021 + err = ipkg_conf_init (&ipkg_conf, &args);
7022 + if (err)
7023 + {
7024 + return err;
7025 + }
7026 +
7027 + args_deinit (&args);
7028 +
7029 + ipkg_cb_message = default_ipkg_message_callback;
7030 + ipkg_cb_response = default_ipkg_response_callback;
7031 + ipkg_cb_status = default_ipkg_status_callback;
7032 + if ( strcmp(cmd_name, "files")==0)
7033 + ipkg_cb_list = default_ipkg_files_callback;
7034 + else
7035 + ipkg_cb_list = default_ipkg_list_callback;
7036 +
7037 + cmd = ipkg_cmd_find (cmd_name);
7038 + if (cmd == NULL)
7039 + {
7040 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7041 + cmd_name);
7042 + args_usage (NULL);
7043 + }
7044 +
7045 + if (cmd->requires_args && optind == argc)
7046 + {
7047 + fprintf (stderr,
7048 + "%s: the ``%s'' command requires at least one argument\n",
7049 + __FUNCTION__, cmd_name);
7050 + args_usage (NULL);
7051 + }
7052 +
7053 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7054 +
7055 + ipkg_conf_deinit (&ipkg_conf);
7056 +
7057 + return err;
7058 +}
7059 +
7060 +#endif /* IPKG_LIB */
7061 diff -ruN busybox-1.1.1-old/archival/libipkg/libipkg.h busybox-1.1.1-new/archival/libipkg/libipkg.h
7062 --- busybox-1.1.1-old/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7063 +++ busybox-1.1.1-new/archival/libipkg/libipkg.h 2006-03-30 00:39:48.000000000 +0200
7064 @@ -0,0 +1,87 @@
7065 +/* ipkglib.h - the itsy package management system
7066 +
7067 + Florian Boor <florian.boor@kernelconcepts.de>
7068 +
7069 + This program is free software; you can redistribute it and/or
7070 + modify it under the terms of the GNU General Public License as
7071 + published by the Free Software Foundation; either version 2, or (at
7072 + your option) any later version.
7073 +
7074 + This program is distributed in the hope that it will be useful, but
7075 + WITHOUT ANY WARRANTY; without even the implied warranty of
7076 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7077 + General Public License for more details.
7078 +*/
7079 +
7080 +#ifndef IPKGLIB_H
7081 +#define IPKGLIB_H
7082 +
7083 +#ifdef IPKG_LIB
7084 +
7085 +#include "ipkg_conf.h"
7086 +#include "ipkg_message.h"
7087 +
7088 +#include "args.h"
7089 +#include "pkg.h"
7090 +
7091 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7092 + char *msg);
7093 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7094 + pkg_state_status_t status, void *userdata);
7095 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7096 + void *userdata);
7097 +typedef char* (*ipkg_response_callback)(char *question);
7098 +
7099 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7100 +extern int ipkg_init (ipkg_message_callback mcall,
7101 + ipkg_response_callback rcall,
7102 + args_t * args);
7103 +
7104 +extern int ipkg_deinit (args_t *args);
7105 +extern int ipkg_packages_list(args_t *args,
7106 + const char *packages,
7107 + ipkg_list_callback cblist,
7108 + void *userdata);
7109 +extern int ipkg_packages_status(args_t *args,
7110 + const char *packages,
7111 + ipkg_status_callback cbstatus,
7112 + void *userdata);
7113 +extern int ipkg_packages_info(args_t *args,
7114 + const char *packages,
7115 + ipkg_status_callback cbstatus,
7116 + void *userdata);
7117 +extern int ipkg_packages_install(args_t *args, const char *name);
7118 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7119 +extern int ipkg_lists_update(args_t *args);
7120 +extern int ipkg_packages_upgrade(args_t *args);
7121 +extern int ipkg_packages_download(args_t *args, const char *name);
7122 +extern int ipkg_package_files(args_t *args,
7123 + const char *name,
7124 + ipkg_list_callback cblist,
7125 + void *userdata);
7126 +extern int ipkg_file_search(args_t *args,
7127 + const char *file,
7128 + ipkg_list_callback cblist,
7129 + void *userdata);
7130 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7131 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7132 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7133 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7134 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7135 +
7136 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7137 +extern ipkg_response_callback ipkg_cb_response;
7138 +extern ipkg_status_callback ipkg_cb_status;
7139 +extern ipkg_list_callback ipkg_cb_list;
7140 +extern void push_error_list(struct errlist **errors,char * msg);
7141 +extern void reverse_error_list(struct errlist **errors);
7142 +extern void free_error_list(struct errlist **errors);
7143 +
7144 +#else
7145 +
7146 +extern int ipkg_op(int argc, char *argv[]);
7147 +
7148 +#endif
7149 +
7150 +
7151 +#endif
7152 diff -ruN busybox-1.1.1-old/archival/libipkg/md5.c busybox-1.1.1-new/archival/libipkg/md5.c
7153 --- busybox-1.1.1-old/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7154 +++ busybox-1.1.1-new/archival/libipkg/md5.c 2006-03-30 01:24:25.000000000 +0200
7155 @@ -0,0 +1,48 @@
7156 +/* md5.c - wrappers to busybox md5 functions
7157 + *
7158 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7159 + *
7160 + * This program is free software; you can redistribute it and/or modify
7161 + * it under the terms of the GNU General Public License as published by
7162 + * the Free Software Foundation; either version 2, or (at your option)
7163 + * any later version.
7164 + *
7165 + * This program is distributed in the hope that it will be useful,
7166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7168 + * GNU General Public License for more details.
7169 + *
7170 + * You should have received a copy of the GNU General Public License
7171 + * along with this program; if not, write to the Free Software Foundation,
7172 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7173 + */
7174 +
7175 +#include <stdio.h>
7176 +#include "libbb.h"
7177 +
7178 +#include "md5.h"
7179 +
7180 +int md5_stream(FILE *stream, void *resblock)
7181 +{
7182 + int fd;
7183 + int sum;
7184 +
7185 + if( (fd = fileno(stream)) == -1 ) {
7186 + bb_error_msg("bad file descriptor");
7187 + return 1;
7188 + }
7189 +
7190 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7191 +
7192 + return 0;
7193 +}
7194 +
7195 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7196 +{
7197 + md5_ctx_t md5_cx;
7198 +
7199 + md5_begin(&md5_cx);
7200 + md5_hash(buffer, len, &md5_cx);
7201 + return md5_end(resblock, &md5_cx);
7202 +}
7203 +
7204 diff -ruN busybox-1.1.1-old/archival/libipkg/md5.h busybox-1.1.1-new/archival/libipkg/md5.h
7205 --- busybox-1.1.1-old/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7206 +++ busybox-1.1.1-new/archival/libipkg/md5.h 2006-03-30 00:39:48.000000000 +0200
7207 @@ -0,0 +1,35 @@
7208 +/* md5.h - Compute MD5 checksum of files or strings according to the
7209 + * definition of MD5 in RFC 1321 from April 1992.
7210 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7211 + *
7212 + * This program is free software; you can redistribute it and/or modify
7213 + * it under the terms of the GNU General Public License as published by
7214 + * the Free Software Foundation; either version 2, or (at your option)
7215 + * any later version.
7216 + *
7217 + * This program is distributed in the hope that it will be useful,
7218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7220 + * GNU General Public License for more details.
7221 + *
7222 + * You should have received a copy of the GNU General Public License
7223 + * along with this program; if not, write to the Free Software Foundation,
7224 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7225 + */
7226 +
7227 +#ifndef MD5_H
7228 +#define MD5_H
7229 +
7230 +/* Compute MD5 message digest for bytes read from STREAM. The
7231 + resulting message digest number will be written into the 16 bytes
7232 + beginning at RESBLOCK. */
7233 +int md5_stream(FILE *stream, void *resblock);
7234 +
7235 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7236 + result is always in little endian byte order, so that a byte-wise
7237 + output yields to the wanted ASCII representation of the message
7238 + digest. */
7239 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7240 +
7241 +#endif
7242 +
7243 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair.c busybox-1.1.1-new/archival/libipkg/nv_pair.c
7244 --- busybox-1.1.1-old/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7245 +++ busybox-1.1.1-new/archival/libipkg/nv_pair.c 2006-03-30 00:39:48.000000000 +0200
7246 @@ -0,0 +1,40 @@
7247 +/* nv_pair.c - the itsy package management system
7248 +
7249 + Carl D. Worth
7250 +
7251 + Copyright (C) 2001 University of Southern California
7252 +
7253 + This program is free software; you can redistribute it and/or
7254 + modify it under the terms of the GNU General Public License as
7255 + published by the Free Software Foundation; either version 2, or (at
7256 + your option) any later version.
7257 +
7258 + This program is distributed in the hope that it will be useful, but
7259 + WITHOUT ANY WARRANTY; without even the implied warranty of
7260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7261 + General Public License for more details.
7262 +*/
7263 +
7264 +#include "ipkg.h"
7265 +
7266 +#include "nv_pair.h"
7267 +#include "str_util.h"
7268 +
7269 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7270 +{
7271 + nv_pair->name = str_dup_safe(name);
7272 + nv_pair->value = str_dup_safe(value);
7273 +
7274 + return 0;
7275 +}
7276 +
7277 +void nv_pair_deinit(nv_pair_t *nv_pair)
7278 +{
7279 + free(nv_pair->name);
7280 + nv_pair->name = NULL;
7281 +
7282 + free(nv_pair->value);
7283 + nv_pair->value = NULL;
7284 +}
7285 +
7286 +
7287 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair.h busybox-1.1.1-new/archival/libipkg/nv_pair.h
7288 --- busybox-1.1.1-old/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7289 +++ busybox-1.1.1-new/archival/libipkg/nv_pair.h 2006-03-30 00:39:48.000000000 +0200
7290 @@ -0,0 +1,32 @@
7291 +/* nv_pair.h - the itsy package management system
7292 +
7293 + Carl D. Worth
7294 +
7295 + Copyright (C) 2001 University of Southern California
7296 +
7297 + This program is free software; you can redistribute it and/or
7298 + modify it under the terms of the GNU General Public License as
7299 + published by the Free Software Foundation; either version 2, or (at
7300 + your option) any later version.
7301 +
7302 + This program is distributed in the hope that it will be useful, but
7303 + WITHOUT ANY WARRANTY; without even the implied warranty of
7304 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7305 + General Public License for more details.
7306 +*/
7307 +
7308 +#ifndef NV_PAIR_H
7309 +#define NV_PAIR_H
7310 +
7311 +typedef struct nv_pair nv_pair_t;
7312 +struct nv_pair
7313 +{
7314 + char *name;
7315 + char *value;
7316 +};
7317 +
7318 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7319 +void nv_pair_deinit(nv_pair_t *nv_pair);
7320 +
7321 +#endif
7322 +
7323 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair_list.c busybox-1.1.1-new/archival/libipkg/nv_pair_list.c
7324 --- busybox-1.1.1-old/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7325 +++ busybox-1.1.1-new/archival/libipkg/nv_pair_list.c 2006-03-30 00:39:48.000000000 +0200
7326 @@ -0,0 +1,98 @@
7327 +/* nv_pair_list.c - the itsy package management system
7328 +
7329 + Carl D. Worth
7330 +
7331 + Copyright (C) 2001 University of Southern California
7332 +
7333 + This program is free software; you can redistribute it and/or
7334 + modify it under the terms of the GNU General Public License as
7335 + published by the Free Software Foundation; either version 2, or (at
7336 + your option) any later version.
7337 +
7338 + This program is distributed in the hope that it will be useful, but
7339 + WITHOUT ANY WARRANTY; without even the implied warranty of
7340 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7341 + General Public License for more details.
7342 +*/
7343 +
7344 +#include "ipkg.h"
7345 +
7346 +#include "nv_pair.h"
7347 +#include "void_list.h"
7348 +#include "nv_pair_list.h"
7349 +
7350 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7351 +{
7352 + return void_list_elt_init((void_list_elt_t *) elt, data);
7353 +}
7354 +
7355 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7356 +{
7357 + void_list_elt_deinit((void_list_elt_t *) elt);
7358 +}
7359 +
7360 +int nv_pair_list_init(nv_pair_list_t *list)
7361 +{
7362 + return void_list_init((void_list_t *) list);
7363 +}
7364 +
7365 +void nv_pair_list_deinit(nv_pair_list_t *list)
7366 +{
7367 + nv_pair_list_elt_t *iter;
7368 + nv_pair_t *nv_pair;
7369 +
7370 + for (iter = list->head; iter; iter = iter->next) {
7371 + nv_pair = iter->data;
7372 + nv_pair_deinit(nv_pair);
7373 +
7374 + /* malloced in nv_pair_list_append */
7375 + free(nv_pair);
7376 + iter->data = NULL;
7377 + }
7378 + void_list_deinit((void_list_t *) list);
7379 +}
7380 +
7381 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7382 +{
7383 + int err;
7384 +
7385 + /* freed in nv_pair_list_deinit */
7386 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7387 +
7388 + if (nv_pair == NULL) {
7389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7390 + return NULL;
7391 + }
7392 + nv_pair_init(nv_pair, name, value);
7393 +
7394 + err = void_list_append((void_list_t *) list, nv_pair);
7395 + if (err) {
7396 + return NULL;
7397 + }
7398 +
7399 + return nv_pair;
7400 +}
7401 +
7402 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7403 +{
7404 + return void_list_push((void_list_t *) list, data);
7405 +}
7406 +
7407 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7408 +{
7409 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7410 +}
7411 +
7412 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7413 +{
7414 + nv_pair_list_elt_t *iter;
7415 + nv_pair_t *nv_pair;
7416 +
7417 + for (iter = list->head; iter; iter = iter->next) {
7418 + nv_pair = iter->data;
7419 + if (strcmp(nv_pair->name, name) == 0) {
7420 + return nv_pair->value;
7421 + }
7422 + }
7423 + return NULL;
7424 +}
7425 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair_list.h busybox-1.1.1-new/archival/libipkg/nv_pair_list.h
7426 --- busybox-1.1.1-old/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7427 +++ busybox-1.1.1-new/archival/libipkg/nv_pair_list.h 2006-03-30 00:39:48.000000000 +0200
7428 @@ -0,0 +1,60 @@
7429 +/* nv_pair_list.h - the itsy package management system
7430 +
7431 + Carl D. Worth
7432 +
7433 + Copyright (C) 2001 University of Southern California
7434 +
7435 + This program is free software; you can redistribute it and/or
7436 + modify it under the terms of the GNU General Public License as
7437 + published by the Free Software Foundation; either version 2, or (at
7438 + your option) any later version.
7439 +
7440 + This program is distributed in the hope that it will be useful, but
7441 + WITHOUT ANY WARRANTY; without even the implied warranty of
7442 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7443 + General Public License for more details.
7444 +*/
7445 +
7446 +#ifndef NV_PAIR_LIST_H
7447 +#define NV_PAIR_LIST_H
7448 +
7449 +#include "nv_pair.h"
7450 +#include "void_list.h"
7451 +
7452 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7453 +struct nv_pair_list_elt
7454 +{
7455 + nv_pair_list_elt_t *next;
7456 + nv_pair_t *data;
7457 +};
7458 +
7459 +typedef struct nv_pair_list nv_pair_list_t;
7460 +struct nv_pair_list
7461 +{
7462 + nv_pair_list_elt_t pre_head;
7463 + nv_pair_list_elt_t *head;
7464 + nv_pair_list_elt_t *tail;
7465 +};
7466 +
7467 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7468 +{
7469 + if (list->head == NULL)
7470 + return 1;
7471 + else
7472 + return 0;
7473 +}
7474 +
7475 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7476 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7477 +
7478 +int nv_pair_list_init(nv_pair_list_t *list);
7479 +void nv_pair_list_deinit(nv_pair_list_t *list);
7480 +
7481 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7482 + const char *name, const char *value);
7483 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7484 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7485 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7486 +
7487 +#endif
7488 +
7489 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg.c busybox-1.1.1-new/archival/libipkg/pkg.c
7490 --- busybox-1.1.1-old/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7491 +++ busybox-1.1.1-new/archival/libipkg/pkg.c 2006-03-30 00:39:48.000000000 +0200
7492 @@ -0,0 +1,1753 @@
7493 +/* pkg.c - the itsy package management system
7494 +
7495 + Carl D. Worth
7496 +
7497 + Copyright (C) 2001 University of Southern California
7498 +
7499 + This program is free software; you can redistribute it and/or
7500 + modify it under the terms of the GNU General Public License as
7501 + published by the Free Software Foundation; either version 2, or (at
7502 + your option) any later version.
7503 +
7504 + This program is distributed in the hope that it will be useful, but
7505 + WITHOUT ANY WARRANTY; without even the implied warranty of
7506 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7507 + General Public License for more details.
7508 +*/
7509 +
7510 +#include "ipkg.h"
7511 +#include <ctype.h>
7512 +#include <string.h>
7513 +#include <errno.h>
7514 +
7515 +#include "pkg.h"
7516 +
7517 +#include "pkg_parse.h"
7518 +#include "pkg_extract.h"
7519 +#include "ipkg_message.h"
7520 +#include "ipkg_utils.h"
7521 +
7522 +#include "sprintf_alloc.h"
7523 +#include "file_util.h"
7524 +#include "str_util.h"
7525 +#include "xsystem.h"
7526 +#include "ipkg_conf.h"
7527 +
7528 +typedef struct enum_map enum_map_t;
7529 +struct enum_map
7530 +{
7531 + int value;
7532 + char *str;
7533 +};
7534 +
7535 +static const enum_map_t pkg_state_want_map[] = {
7536 + { SW_UNKNOWN, "unknown"},
7537 + { SW_INSTALL, "install"},
7538 + { SW_DEINSTALL, "deinstall"},
7539 + { SW_PURGE, "purge"}
7540 +};
7541 +
7542 +static const enum_map_t pkg_state_flag_map[] = {
7543 + { SF_OK, "ok"},
7544 + { SF_REINSTREQ, "reinstreq"},
7545 + { SF_HOLD, "hold"},
7546 + { SF_REPLACE, "replace"},
7547 + { SF_NOPRUNE, "noprune"},
7548 + { SF_PREFER, "prefer"},
7549 + { SF_OBSOLETE, "obsolete"},
7550 + { SF_USER, "user"},
7551 +};
7552 +
7553 +static const enum_map_t pkg_state_status_map[] = {
7554 + { SS_NOT_INSTALLED, "not-installed" },
7555 + { SS_UNPACKED, "unpacked" },
7556 + { SS_HALF_CONFIGURED, "half-configured" },
7557 + { SS_INSTALLED, "installed" },
7558 + { SS_HALF_INSTALLED, "half-installed" },
7559 + { SS_CONFIG_FILES, "config-files" },
7560 + { SS_POST_INST_FAILED, "post-inst-failed" },
7561 + { SS_REMOVAL_FAILED, "removal-failed" }
7562 +};
7563 +
7564 +static int verrevcmp(const char *val, const char *ref);
7565 +
7566 +
7567 +pkg_t *pkg_new(void)
7568 +{
7569 + pkg_t *pkg;
7570 +
7571 + pkg = malloc(sizeof(pkg_t));
7572 + if (pkg == NULL) {
7573 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7574 + return NULL;
7575 + }
7576 +
7577 + pkg_init(pkg);
7578 +
7579 + return pkg;
7580 +}
7581 +
7582 +int pkg_init(pkg_t *pkg)
7583 +{
7584 + memset(pkg, 0, sizeof(pkg_t));
7585 + pkg->name = NULL;
7586 + pkg->epoch = 0;
7587 + pkg->version = NULL;
7588 + pkg->revision = NULL;
7589 + pkg->familiar_revision = NULL;
7590 + pkg->dest = NULL;
7591 + pkg->src = NULL;
7592 + pkg->architecture = NULL;
7593 + pkg->maintainer = NULL;
7594 + pkg->section = NULL;
7595 + pkg->description = NULL;
7596 + pkg->state_want = SW_UNKNOWN;
7597 + pkg->state_flag = SF_OK;
7598 + pkg->state_status = SS_NOT_INSTALLED;
7599 + pkg->depends_str = NULL;
7600 + pkg->provides_str = NULL;
7601 + pkg->depends_count = 0;
7602 + pkg->depends = NULL;
7603 + pkg->suggests_str = NULL;
7604 + pkg->recommends_str = NULL;
7605 + pkg->suggests_count = 0;
7606 + pkg->recommends_count = 0;
7607 +
7608 + /* Abhaya: added init for conflicts fields */
7609 + pkg->conflicts = NULL;
7610 + pkg->conflicts_count = 0;
7611 +
7612 + /* added for replaces. Jamey 7/23/2002 */
7613 + pkg->replaces = NULL;
7614 + pkg->replaces_count = 0;
7615 +
7616 + pkg->pre_depends_count = 0;
7617 + pkg->pre_depends_str = NULL;
7618 + pkg->provides_count = 0;
7619 + pkg->provides = NULL;
7620 + pkg->filename = NULL;
7621 + pkg->local_filename = NULL;
7622 + pkg->tmp_unpack_dir = NULL;
7623 + pkg->md5sum = NULL;
7624 + pkg->size = NULL;
7625 + pkg->installed_size = NULL;
7626 + pkg->priority = NULL;
7627 + pkg->source = NULL;
7628 + conffile_list_init(&pkg->conffiles);
7629 + pkg->installed_files = NULL;
7630 + pkg->installed_files_ref_cnt = 0;
7631 + pkg->essential = 0;
7632 +
7633 + return 0;
7634 +}
7635 +
7636 +void pkg_deinit(pkg_t *pkg)
7637 +{
7638 + free(pkg->name);
7639 + pkg->name = NULL;
7640 + pkg->epoch = 0;
7641 + free(pkg->version);
7642 + pkg->version = NULL;
7643 + /* revision and familiar_revision share storage with version, so
7644 + don't free */
7645 + pkg->revision = NULL;
7646 + pkg->familiar_revision = NULL;
7647 + /* owned by ipkg_conf_t */
7648 + pkg->dest = NULL;
7649 + /* owned by ipkg_conf_t */
7650 + pkg->src = NULL;
7651 + free(pkg->architecture);
7652 + pkg->architecture = NULL;
7653 + free(pkg->maintainer);
7654 + pkg->maintainer = NULL;
7655 + free(pkg->section);
7656 + pkg->section = NULL;
7657 + free(pkg->description);
7658 + pkg->description = NULL;
7659 + pkg->state_want = SW_UNKNOWN;
7660 + pkg->state_flag = SF_OK;
7661 + pkg->state_status = SS_NOT_INSTALLED;
7662 + free(pkg->depends_str);
7663 + pkg->depends_str = NULL;
7664 + free(pkg->provides_str);
7665 + pkg->provides_str = NULL;
7666 + pkg->depends_count = 0;
7667 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7668 + pkg->pre_depends_count = 0;
7669 + free(pkg->pre_depends_str);
7670 + pkg->pre_depends_str = NULL;
7671 + pkg->provides_count = 0;
7672 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7673 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7674 + free(pkg->filename);
7675 + pkg->filename = NULL;
7676 + free(pkg->local_filename);
7677 + pkg->local_filename = NULL;
7678 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7679 + ipkg_install.c here. See comment in
7680 + ipkg_install.c:cleanup_temporary_files */
7681 + free(pkg->tmp_unpack_dir);
7682 + pkg->tmp_unpack_dir = NULL;
7683 + free(pkg->md5sum);
7684 + pkg->md5sum = NULL;
7685 + free(pkg->size);
7686 + pkg->size = NULL;
7687 + free(pkg->installed_size);
7688 + pkg->installed_size = NULL;
7689 + free(pkg->priority);
7690 + pkg->priority = NULL;
7691 + free(pkg->source);
7692 + pkg->source = NULL;
7693 + conffile_list_deinit(&pkg->conffiles);
7694 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7695 + since if they are calling deinit, they should know. Maybe do an
7696 + assertion here instead? */
7697 + pkg->installed_files_ref_cnt = 1;
7698 + pkg_free_installed_files(pkg);
7699 + pkg->essential = 0;
7700 +}
7701 +
7702 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7703 +{
7704 + int err;
7705 + char **raw;
7706 + FILE *control_file;
7707 +
7708 + err = pkg_init(pkg);
7709 + if (err) { return err; }
7710 +
7711 + pkg->local_filename = strdup(filename);
7712 +
7713 + control_file = tmpfile();
7714 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7715 + if (err) { return err; }
7716 +
7717 + rewind(control_file);
7718 + raw = read_raw_pkgs_from_stream(control_file);
7719 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7720 +
7721 + fclose(control_file);
7722 +
7723 + return 0;
7724 +}
7725 +
7726 +/* Merge any new information in newpkg into oldpkg */
7727 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7728 + newpkg, but should leave it usable. This rework is so that
7729 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7730 +/*
7731 + * uh, i thought that i had originally written this so that it took
7732 + * two pkgs and returned a new one? we can do that again... -sma
7733 + */
7734 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7735 +{
7736 + if (oldpkg == newpkg) {
7737 + return 0;
7738 + }
7739 +
7740 + if (!oldpkg->src)
7741 + oldpkg->src = newpkg->src;
7742 + if (!oldpkg->dest)
7743 + oldpkg->dest = newpkg->dest;
7744 + if (!oldpkg->architecture)
7745 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7746 + if (!oldpkg->arch_priority)
7747 + oldpkg->arch_priority = newpkg->arch_priority;
7748 + if (!oldpkg->section)
7749 + oldpkg->section = str_dup_safe(newpkg->section);
7750 + if(!oldpkg->maintainer)
7751 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7752 + if(!oldpkg->description)
7753 + oldpkg->description = str_dup_safe(newpkg->description);
7754 + if (set_status) {
7755 + /* merge the state_flags from the new package */
7756 + oldpkg->state_want = newpkg->state_want;
7757 + oldpkg->state_status = newpkg->state_status;
7758 + oldpkg->state_flag = newpkg->state_flag;
7759 + } else {
7760 + if (oldpkg->state_want == SW_UNKNOWN)
7761 + oldpkg->state_want = newpkg->state_want;
7762 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7763 + oldpkg->state_status = newpkg->state_status;
7764 + oldpkg->state_flag |= newpkg->state_flag;
7765 + }
7766 +
7767 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7768 + oldpkg->depends_str = newpkg->depends_str;
7769 + newpkg->depends_str = NULL;
7770 + oldpkg->depends_count = newpkg->depends_count;
7771 + newpkg->depends_count = 0;
7772 +
7773 + oldpkg->depends = newpkg->depends;
7774 + newpkg->depends = NULL;
7775 +
7776 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7777 + newpkg->pre_depends_str = NULL;
7778 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7779 + newpkg->pre_depends_count = 0;
7780 +
7781 + oldpkg->recommends_str = newpkg->recommends_str;
7782 + newpkg->recommends_str = NULL;
7783 + oldpkg->recommends_count = newpkg->recommends_count;
7784 + newpkg->recommends_count = 0;
7785 +
7786 + oldpkg->suggests_str = newpkg->suggests_str;
7787 + newpkg->suggests_str = NULL;
7788 + oldpkg->suggests_count = newpkg->suggests_count;
7789 + newpkg->suggests_count = 0;
7790 + }
7791 +
7792 + if (!oldpkg->provides_str) {
7793 + oldpkg->provides_str = newpkg->provides_str;
7794 + newpkg->provides_str = NULL;
7795 + oldpkg->provides_count = newpkg->provides_count;
7796 + newpkg->provides_count = 0;
7797 +
7798 + oldpkg->provides = newpkg->provides;
7799 + newpkg->provides = NULL;
7800 + }
7801 +
7802 + if (!oldpkg->conflicts_str) {
7803 + oldpkg->conflicts_str = newpkg->conflicts_str;
7804 + newpkg->conflicts_str = NULL;
7805 + oldpkg->conflicts_count = newpkg->conflicts_count;
7806 + newpkg->conflicts_count = 0;
7807 +
7808 + oldpkg->conflicts = newpkg->conflicts;
7809 + newpkg->conflicts = NULL;
7810 + }
7811 +
7812 + if (!oldpkg->replaces_str) {
7813 + oldpkg->replaces_str = newpkg->replaces_str;
7814 + newpkg->replaces_str = NULL;
7815 + oldpkg->replaces_count = newpkg->replaces_count;
7816 + newpkg->replaces_count = 0;
7817 +
7818 + oldpkg->replaces = newpkg->replaces;
7819 + newpkg->replaces = NULL;
7820 + }
7821 +
7822 + if (!oldpkg->filename)
7823 + oldpkg->filename = str_dup_safe(newpkg->filename);
7824 + if (0)
7825 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7826 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7827 + if (!oldpkg->local_filename)
7828 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7829 + if (!oldpkg->tmp_unpack_dir)
7830 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7831 + if (!oldpkg->md5sum)
7832 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7833 + if (!oldpkg->size)
7834 + oldpkg->size = str_dup_safe(newpkg->size);
7835 + if (!oldpkg->installed_size)
7836 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7837 + if (!oldpkg->priority)
7838 + oldpkg->priority = str_dup_safe(newpkg->priority);
7839 + if (!oldpkg->source)
7840 + oldpkg->source = str_dup_safe(newpkg->source);
7841 + if (oldpkg->conffiles.head == NULL){
7842 + oldpkg->conffiles = newpkg->conffiles;
7843 + conffile_list_init(&newpkg->conffiles);
7844 + }
7845 + if (!oldpkg->installed_files){
7846 + oldpkg->installed_files = newpkg->installed_files;
7847 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7848 + newpkg->installed_files = NULL;
7849 + }
7850 + if (!oldpkg->essential)
7851 + oldpkg->essential = newpkg->essential;
7852 +
7853 + return 0;
7854 +}
7855 +
7856 +abstract_pkg_t *abstract_pkg_new(void)
7857 +{
7858 + abstract_pkg_t * ab_pkg;
7859 +
7860 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7861 +
7862 + if (ab_pkg == NULL) {
7863 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7864 + return NULL;
7865 + }
7866 +
7867 + if ( abstract_pkg_init(ab_pkg) < 0 )
7868 + return NULL;
7869 +
7870 + return ab_pkg;
7871 +}
7872 +
7873 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7874 +{
7875 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7876 +
7877 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7878 + if (ab_pkg->provided_by==NULL){
7879 + return -1;
7880 + }
7881 + ab_pkg->dependencies_checked = 0;
7882 + ab_pkg->state_status = SS_NOT_INSTALLED;
7883 +
7884 + return 0;
7885 +}
7886 +
7887 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7888 + char * temp_str;
7889 + char **raw =NULL;
7890 + char **raw_start=NULL;
7891 +
7892 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7893 + if (temp_str == NULL ){
7894 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7895 + return;
7896 + }
7897 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7898 +
7899 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7900 + if (raw == NULL ){
7901 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7902 + return;
7903 + }
7904 +
7905 + while(*raw){
7906 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7907 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7908 + }
7909 + }
7910 + raw = raw_start;
7911 + while (*raw) {
7912 + if (raw!=NULL)
7913 + free(*raw++);
7914 + }
7915 +
7916 + free(raw_start);
7917 + free(temp_str);
7918 +
7919 + return ;
7920 +
7921 +}
7922 +
7923 +char * pkg_formatted_info(pkg_t *pkg )
7924 +{
7925 + char *line;
7926 + char * buff;
7927 +
7928 + buff = malloc(8192);
7929 + if (buff == NULL) {
7930 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7931 + return NULL;
7932 + }
7933 +
7934 + buff[0] = '\0';
7935 +
7936 + line = pkg_formatted_field(pkg, "Package");
7937 + strncat(buff ,line, strlen(line));
7938 + free(line);
7939 +
7940 + line = pkg_formatted_field(pkg, "Version");
7941 + strncat(buff ,line, strlen(line));
7942 + free(line);
7943 +
7944 + line = pkg_formatted_field(pkg, "Depends");
7945 + strncat(buff ,line, strlen(line));
7946 + free(line);
7947 +
7948 + line = pkg_formatted_field(pkg, "Recommends");
7949 + strncat(buff ,line, strlen(line));
7950 + free(line);
7951 +
7952 + line = pkg_formatted_field(pkg, "Suggests");
7953 + strncat(buff ,line, strlen(line));
7954 + free(line);
7955 +
7956 + line = pkg_formatted_field(pkg, "Provides");
7957 + strncat(buff ,line, strlen(line));
7958 + free(line);
7959 +
7960 + line = pkg_formatted_field(pkg, "Replaces");
7961 + strncat(buff ,line, strlen(line));
7962 + free(line);
7963 +
7964 + line = pkg_formatted_field(pkg, "Conflicts");
7965 + strncat(buff ,line, strlen(line));
7966 + free(line);
7967 +
7968 + line = pkg_formatted_field(pkg, "Status");
7969 + strncat(buff ,line, strlen(line));
7970 + free(line);
7971 +
7972 + line = pkg_formatted_field(pkg, "Section");
7973 + strncat(buff ,line, strlen(line));
7974 + free(line);
7975 +
7976 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7977 + strncat(buff ,line, strlen(line));
7978 + free(line);
7979 +
7980 + line = pkg_formatted_field(pkg, "Architecture");
7981 + strncat(buff ,line, strlen(line));
7982 + free(line);
7983 +
7984 + line = pkg_formatted_field(pkg, "Maintainer");
7985 + strncat(buff ,line, strlen(line));
7986 + free(line);
7987 +
7988 + line = pkg_formatted_field(pkg, "MD5sum");
7989 + strncat(buff ,line, strlen(line));
7990 + free(line);
7991 +
7992 + line = pkg_formatted_field(pkg, "Size");
7993 + strncat(buff ,line, strlen(line));
7994 + free(line);
7995 +
7996 + line = pkg_formatted_field(pkg, "Filename");
7997 + strncat(buff ,line, strlen(line));
7998 + free(line);
7999 +
8000 + line = pkg_formatted_field(pkg, "Conffiles");
8001 + strncat(buff ,line, strlen(line));
8002 + free(line);
8003 +
8004 + line = pkg_formatted_field(pkg, "Source");
8005 + strncat(buff ,line, strlen(line));
8006 + free(line);
8007 +
8008 + line = pkg_formatted_field(pkg, "Description");
8009 + strncat(buff ,line, strlen(line));
8010 + free(line);
8011 +
8012 + line = pkg_formatted_field(pkg, "Installed-Time");
8013 + strncat(buff ,line, strlen(line));
8014 + free(line);
8015 +
8016 + return buff;
8017 +}
8018 +
8019 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8020 +{
8021 + static size_t LINE_LEN = 128;
8022 + char * temp = (char *)malloc(1);
8023 + int len = 0;
8024 + int flag_provide_false = 0;
8025 +
8026 +/*
8027 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8028 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8029 +*/
8030 +
8031 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8032 + goto UNKNOWN_FMT_FIELD;
8033 + }
8034 +
8035 + temp[0]='\0';
8036 +
8037 + switch (field[0])
8038 + {
8039 + case 'a':
8040 + case 'A':
8041 + if (strcasecmp(field, "Architecture") == 0) {
8042 + /* Architecture */
8043 + if (pkg->architecture) {
8044 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8045 + if ( temp == NULL ){
8046 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8047 + return NULL;
8048 + }
8049 + temp[0]='\0';
8050 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8051 + }
8052 + } else {
8053 + goto UNKNOWN_FMT_FIELD;
8054 + }
8055 + break;
8056 + case 'c':
8057 + case 'C':
8058 + if (strcasecmp(field, "Conffiles") == 0) {
8059 + /* Conffiles */
8060 + conffile_list_elt_t *iter;
8061 + char confstr[LINE_LEN];
8062 +
8063 + if (pkg->conffiles.head == NULL) {
8064 + return temp;
8065 + }
8066 +
8067 + len = 14 ;
8068 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8069 + if (iter->data->name && iter->data->value) {
8070 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8071 + }
8072 + }
8073 + temp = (char *)realloc(temp,len);
8074 + if ( temp == NULL ){
8075 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8076 + return NULL;
8077 + }
8078 + temp[0]='\0';
8079 + strncpy(temp, "Conffiles:\n", 12);
8080 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8081 + if (iter->data->name && iter->data->value) {
8082 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8083 + strncat(temp, confstr, strlen(confstr));
8084 + }
8085 + }
8086 + } else if (strcasecmp(field, "Conflicts") == 0) {
8087 + int i;
8088 +
8089 + if (pkg->conflicts_count) {
8090 + char conflictstr[LINE_LEN];
8091 + len = 14 ;
8092 + for(i = 0; i < pkg->conflicts_count; i++) {
8093 + len = len + (strlen(pkg->conflicts_str[i])+5);
8094 + }
8095 + temp = (char *)realloc(temp,len);
8096 + if ( temp == NULL ){
8097 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8098 + return NULL;
8099 + }
8100 + temp[0]='\0';
8101 + strncpy(temp, "Conflicts:", 11);
8102 + for(i = 0; i < pkg->conflicts_count; i++) {
8103 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8104 + strncat(temp, conflictstr, strlen(conflictstr));
8105 + }
8106 + strncat(temp, "\n", strlen("\n"));
8107 + }
8108 + } else {
8109 + goto UNKNOWN_FMT_FIELD;
8110 + }
8111 + break;
8112 + case 'd':
8113 + case 'D':
8114 + if (strcasecmp(field, "Depends") == 0) {
8115 + /* Depends */
8116 + int i;
8117 +
8118 + if (pkg->depends_count) {
8119 + char depstr[LINE_LEN];
8120 + len = 14 ;
8121 + for(i = 0; i < pkg->depends_count; i++) {
8122 + len = len + (strlen(pkg->depends_str[i])+4);
8123 + }
8124 + temp = (char *)realloc(temp,len);
8125 + if ( temp == NULL ){
8126 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8127 + return NULL;
8128 + }
8129 + temp[0]='\0';
8130 + strncpy(temp, "Depends:", 10);
8131 + for(i = 0; i < pkg->depends_count; i++) {
8132 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8133 + strncat(temp, depstr, strlen(depstr));
8134 + }
8135 + strncat(temp, "\n", strlen("\n"));
8136 + }
8137 + } else if (strcasecmp(field, "Description") == 0) {
8138 + /* Description */
8139 + if (pkg->description) {
8140 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8141 + if ( temp == NULL ){
8142 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8143 + return NULL;
8144 + }
8145 + temp[0]='\0';
8146 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8147 + }
8148 + } else {
8149 + goto UNKNOWN_FMT_FIELD;
8150 + }
8151 + break;
8152 + case 'e':
8153 + case 'E': {
8154 + /* Essential */
8155 + if (pkg->essential) {
8156 + temp = (char *)realloc(temp,16);
8157 + if ( temp == NULL ){
8158 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8159 + return NULL;
8160 + }
8161 + temp[0]='\0';
8162 + snprintf(temp, (16), "Essential: yes\n");
8163 + }
8164 + }
8165 + break;
8166 + case 'f':
8167 + case 'F': {
8168 + /* Filename */
8169 + if (pkg->filename) {
8170 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8171 + if ( temp == NULL ){
8172 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8173 + return NULL;
8174 + }
8175 + temp[0]='\0';
8176 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8177 + }
8178 + }
8179 + break;
8180 + case 'i':
8181 + case 'I': {
8182 + if (strcasecmp(field, "Installed-Size") == 0) {
8183 + /* Installed-Size */
8184 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8185 + if ( temp == NULL ){
8186 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8187 + return NULL;
8188 + }
8189 + temp[0]='\0';
8190 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8191 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8192 + temp = (char *)realloc(temp,29);
8193 + if ( temp == NULL ){
8194 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8195 + return NULL;
8196 + }
8197 + temp[0]='\0';
8198 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8199 + }
8200 + }
8201 + break;
8202 + case 'm':
8203 + case 'M': {
8204 + /* Maintainer | MD5sum */
8205 + if (strcasecmp(field, "Maintainer") == 0) {
8206 + /* Maintainer */
8207 + if (pkg->maintainer) {
8208 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8209 + if ( temp == NULL ){
8210 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8211 + return NULL;
8212 + }
8213 + temp[0]='\0';
8214 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8215 + }
8216 + } else if (strcasecmp(field, "MD5sum") == 0) {
8217 + /* MD5sum */
8218 + if (pkg->md5sum) {
8219 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8220 + if ( temp == NULL ){
8221 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8222 + return NULL;
8223 + }
8224 + temp[0]='\0';
8225 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8226 + }
8227 + } else {
8228 + goto UNKNOWN_FMT_FIELD;
8229 + }
8230 + }
8231 + break;
8232 + case 'p':
8233 + case 'P': {
8234 + if (strcasecmp(field, "Package") == 0) {
8235 + /* Package */
8236 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8237 + if ( temp == NULL ){
8238 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8239 + return NULL;
8240 + }
8241 + temp[0]='\0';
8242 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8243 + } else if (strcasecmp(field, "Priority") == 0) {
8244 + /* Priority */
8245 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8246 + if ( temp == NULL ){
8247 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8248 + return NULL;
8249 + }
8250 + temp[0]='\0';
8251 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8252 + } else if (strcasecmp(field, "Provides") == 0) {
8253 + /* Provides */
8254 + int i;
8255 +
8256 + if (pkg->provides_count) {
8257 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8258 + for ( i=0; i < pkg->provides_count; i++ ){
8259 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8260 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8261 + flag_provide_false = 1;
8262 + }
8263 + }
8264 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8265 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8266 + char provstr[LINE_LEN];
8267 + len = 15;
8268 + for(i = 0; i < pkg->provides_count; i++) {
8269 + len = len + (strlen(pkg->provides_str[i])+5);
8270 + }
8271 + temp = (char *)realloc(temp,len);
8272 + if ( temp == NULL ){
8273 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8274 + return NULL;
8275 + }
8276 + temp[0]='\0';
8277 + strncpy(temp, "Provides:", 12);
8278 + for(i = 0; i < pkg->provides_count; i++) {
8279 + if (strlen(pkg->provides_str[i])>0){;
8280 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8281 + strncat(temp, provstr, strlen(provstr));
8282 + }
8283 + }
8284 + strncat(temp, "\n", strlen("\n"));
8285 + }
8286 + }
8287 + } else {
8288 + goto UNKNOWN_FMT_FIELD;
8289 + }
8290 + }
8291 + break;
8292 + case 'r':
8293 + case 'R': {
8294 + int i;
8295 + /* Replaces | Recommends*/
8296 + if (strcasecmp (field, "Replaces") == 0) {
8297 + if (pkg->replaces_count) {
8298 + char replstr[LINE_LEN];
8299 + len = 14;
8300 + for (i = 0; i < pkg->replaces_count; i++) {
8301 + len = len + (strlen(pkg->replaces_str[i])+5);
8302 + }
8303 + temp = (char *)realloc(temp,len);
8304 + if ( temp == NULL ){
8305 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8306 + return NULL;
8307 + }
8308 + temp[0]='\0';
8309 + strncpy(temp, "Replaces:", 12);
8310 + for (i = 0; i < pkg->replaces_count; i++) {
8311 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8312 + strncat(temp, replstr, strlen(replstr));
8313 + }
8314 + strncat(temp, "\n", strlen("\n"));
8315 + }
8316 + } else if (strcasecmp (field, "Recommends") == 0) {
8317 + if (pkg->recommends_count) {
8318 + char recstr[LINE_LEN];
8319 + len = 15;
8320 + for(i = 0; i < pkg->recommends_count; i++) {
8321 + len = len + (strlen( pkg->recommends_str[i])+5);
8322 + }
8323 + temp = (char *)realloc(temp,len);
8324 + if ( temp == NULL ){
8325 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8326 + return NULL;
8327 + }
8328 + temp[0]='\0';
8329 + strncpy(temp, "Recommends:", 13);
8330 + for(i = 0; i < pkg->recommends_count; i++) {
8331 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8332 + strncat(temp, recstr, strlen(recstr));
8333 + }
8334 + strncat(temp, "\n", strlen("\n"));
8335 + }
8336 + } else {
8337 + goto UNKNOWN_FMT_FIELD;
8338 + }
8339 + }
8340 + break;
8341 + case 's':
8342 + case 'S': {
8343 + /* Section | Size | Source | Status | Suggests */
8344 + if (strcasecmp(field, "Section") == 0) {
8345 + /* Section */
8346 + if (pkg->section) {
8347 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8348 + if ( temp == NULL ){
8349 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8350 + return NULL;
8351 + }
8352 + temp[0]='\0';
8353 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8354 + }
8355 + } else if (strcasecmp(field, "Size") == 0) {
8356 + /* Size */
8357 + if (pkg->size) {
8358 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8359 + if ( temp == NULL ){
8360 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8361 + return NULL;
8362 + }
8363 + temp[0]='\0';
8364 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8365 + }
8366 + } else if (strcasecmp(field, "Source") == 0) {
8367 + /* Source */
8368 + if (pkg->source) {
8369 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8370 + if ( temp == NULL ){
8371 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8372 + return NULL;
8373 + }
8374 + temp[0]='\0';
8375 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8376 + }
8377 + } else if (strcasecmp(field, "Status") == 0) {
8378 + /* Status */
8379 + /* Benjamin Pineau note: we should avoid direct usage of
8380 + * strlen(arg) without keeping "arg" for later free()
8381 + */
8382 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8383 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8384 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8385 +
8386 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8387 + temp = (char *)realloc(temp,sum_of_sizes);
8388 + if ( temp == NULL ){
8389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8390 + return NULL;
8391 + }
8392 + temp[0]='\0';
8393 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8394 + free(pflag);
8395 + free(pwant);
8396 + if(pstat) /* pfstat can be NULL if ENOMEM */
8397 + free(pstat);
8398 + } else if (strcasecmp(field, "Suggests") == 0) {
8399 + if (pkg->suggests_count) {
8400 + int i;
8401 + char sugstr[LINE_LEN];
8402 + len = 13;
8403 + for(i = 0; i < pkg->suggests_count; i++) {
8404 + len = len + (strlen(pkg->suggests_str[i])+5);
8405 + }
8406 + temp = (char *)realloc(temp,len);
8407 + if ( temp == NULL ){
8408 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8409 + return NULL;
8410 + }
8411 + temp[0]='\0';
8412 + strncpy(temp, "Suggests:", 10);
8413 + for(i = 0; i < pkg->suggests_count; i++) {
8414 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8415 + strncat(temp, sugstr, strlen(sugstr));
8416 + }
8417 + strncat(temp, "\n", strlen("\n"));
8418 + }
8419 + } else {
8420 + goto UNKNOWN_FMT_FIELD;
8421 + }
8422 + }
8423 + break;
8424 + case 'v':
8425 + case 'V': {
8426 + /* Version */
8427 + char *version = pkg_version_str_alloc(pkg);
8428 + temp = (char *)realloc(temp,strlen(version)+14);
8429 + if ( temp == NULL ){
8430 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8431 + return NULL;
8432 + }
8433 + temp[0]='\0';
8434 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8435 + free(version);
8436 + }
8437 + break;
8438 + default:
8439 + goto UNKNOWN_FMT_FIELD;
8440 + }
8441 +
8442 + if ( strlen(temp)<2 ) {
8443 + temp[0]='\0';
8444 + }
8445 + return temp;
8446 +
8447 + UNKNOWN_FMT_FIELD:
8448 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8449 + if ( strlen(temp)<2 ) {
8450 + temp[0]='\0';
8451 + }
8452 +
8453 + return temp;
8454 +}
8455 +
8456 +void pkg_print_info(pkg_t *pkg, FILE *file)
8457 +{
8458 + char * buff;
8459 + if (pkg == NULL) {
8460 + return;
8461 + }
8462 +
8463 + buff = pkg_formatted_info(pkg);
8464 + if ( buff == NULL )
8465 + return;
8466 + if (strlen(buff)>2){
8467 + fwrite(buff, 1, strlen(buff), file);
8468 + }
8469 + free(buff);
8470 +}
8471 +
8472 +void pkg_print_status(pkg_t * pkg, FILE * file)
8473 +{
8474 + if (pkg == NULL) {
8475 + return;
8476 + }
8477 +
8478 + /* XXX: QUESTION: Do we actually want more fields here? The
8479 + original idea was to save space by installing only what was
8480 + needed for actual computation, (package, version, status,
8481 + essential, conffiles). The assumption is that all other fields
8482 + can be found in th available file.
8483 +
8484 + But, someone proposed the idea to make it possible to
8485 + reconstruct a .ipk from an installed package, (ie. for beaming
8486 + from one handheld to another). So, maybe we actually want a few
8487 + more fields here, (depends, suggests, etc.), so that that would
8488 + be guaranteed to work even in the absence of more information
8489 + from the available file.
8490 +
8491 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8492 + the essential info needs to be here for all installed packages
8493 + because they may not appear in the Packages files on various
8494 + feeds. Furthermore, one should be able to install from URL or
8495 + local storage without requiring a Packages file from any feed.
8496 + -Jamey
8497 + */
8498 + pkg_print_field(pkg, file, "Package");
8499 + pkg_print_field(pkg, file, "Version");
8500 + pkg_print_field(pkg, file, "Depends");
8501 + pkg_print_field(pkg, file, "Recommends");
8502 + pkg_print_field(pkg, file, "Suggests");
8503 + pkg_print_field(pkg, file, "Provides");
8504 + pkg_print_field(pkg, file, "Replaces");
8505 + pkg_print_field(pkg, file, "Conflicts");
8506 + pkg_print_field(pkg, file, "Status");
8507 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8508 + pkg_print_field(pkg, file, "Architecture");
8509 + pkg_print_field(pkg, file, "Conffiles");
8510 + pkg_print_field(pkg, file, "Installed-Time");
8511 + fputs("\n", file);
8512 +}
8513 +
8514 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8515 +{
8516 + char *buff;
8517 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8518 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8519 + __FUNCTION__, field);
8520 + }
8521 + buff = pkg_formatted_field(pkg, field);
8522 + if (strlen(buff)>2) {
8523 + fprintf(file, "%s", buff);
8524 + fflush(file);
8525 + }
8526 + free(buff);
8527 + return;
8528 +}
8529 +
8530 +/*
8531 + * libdpkg - Debian packaging suite library routines
8532 + * vercmp.c - comparison of version numbers
8533 + *
8534 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8535 + */
8536 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8537 +{
8538 + int r;
8539 +
8540 + if (pkg->epoch > ref_pkg->epoch) {
8541 + return 1;
8542 + }
8543 +
8544 + if (pkg->epoch < ref_pkg->epoch) {
8545 + return -1;
8546 + }
8547 +
8548 + r = verrevcmp(pkg->version, ref_pkg->version);
8549 + if (r) {
8550 + return r;
8551 + }
8552 +
8553 +#ifdef USE_DEBVERSION
8554 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8555 + if (r) {
8556 + return r;
8557 + }
8558 +
8559 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8560 +#endif
8561 +
8562 + return r;
8563 +}
8564 +
8565 +int verrevcmp(const char *val, const char *ref)
8566 +{
8567 + int vc, rc;
8568 + long vl, rl;
8569 + const char *vp, *rp;
8570 + const char *vsep, *rsep;
8571 +
8572 + if (!val) val= "";
8573 + if (!ref) ref= "";
8574 + for (;;) {
8575 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8576 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8577 + for (;;) {
8578 + vc= (val == vp) ? 0 : *val++;
8579 + rc= (ref == rp) ? 0 : *ref++;
8580 + if (!rc && !vc) break;
8581 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8582 + if (rc && !isalpha(rc)) rc += 256;
8583 + if (vc != rc) return vc - rc;
8584 + }
8585 + val= vp;
8586 + ref= rp;
8587 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8588 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8589 + if (vl != rl) return vl - rl;
8590 +
8591 + vc = *val;
8592 + rc = *ref;
8593 + vsep = strchr(".-", vc);
8594 + rsep = strchr(".-", rc);
8595 + if (vsep && !rsep) return -1;
8596 + if (!vsep && rsep) return +1;
8597 +
8598 + if (!*val && !*ref) return 0;
8599 + if (!*val) return -1;
8600 + if (!*ref) return +1;
8601 + }
8602 +}
8603 +
8604 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8605 +{
8606 + int r;
8607 +
8608 + r = pkg_compare_versions(it, ref);
8609 +
8610 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8611 + return r <= 0;
8612 + }
8613 +
8614 + if (strcmp(op, ">=") == 0 || 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 + if (strcmp(op, "=") == 0) {
8627 + return r == 0;
8628 + }
8629 +
8630 + fprintf(stderr, "unknown operator: %s", op);
8631 + return 0;
8632 +}
8633 +
8634 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8635 +{
8636 + const pkg_t *a = *(const pkg_t **)p1;
8637 + const pkg_t *b = *(const pkg_t **)p2;
8638 + int namecmp;
8639 + int vercmp;
8640 + if (!a->name || !b->name) {
8641 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8642 + a, a->name, b, b->name);
8643 + return 0;
8644 + }
8645 +
8646 + namecmp = strcmp(a->name, b->name);
8647 + if (namecmp)
8648 + return namecmp;
8649 + vercmp = pkg_compare_versions(a, b);
8650 + if (vercmp)
8651 + return vercmp;
8652 + if (!a->arch_priority || !b->arch_priority) {
8653 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8654 + a, a->arch_priority, b, b->arch_priority);
8655 + return 0;
8656 + }
8657 + if (a->arch_priority > b->arch_priority)
8658 + return 1;
8659 + if (a->arch_priority < b->arch_priority)
8660 + return -1;
8661 + return 0;
8662 +}
8663 +
8664 +int abstract_pkg_name_compare(void *p1, void *p2)
8665 +{
8666 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8667 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8668 + if (!a->name || !b->name) {
8669 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8670 + a, a->name, b, b->name);
8671 + return 0;
8672 + }
8673 + return strcmp(a->name, b->name);
8674 +}
8675 +
8676 +
8677 +char *pkg_version_str_alloc(pkg_t *pkg)
8678 +{
8679 + char *complete_version;
8680 + char *epoch_str;
8681 +#ifdef USE_DEBVERSION
8682 + char *revision_str;
8683 + char *familiar_revision_str;
8684 +#endif
8685 +
8686 + if (pkg->epoch) {
8687 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8688 + } else {
8689 + epoch_str = strdup("");
8690 + }
8691 +
8692 +#ifdef USE_DEBVERSION
8693 + if (pkg->revision && strlen(pkg->revision)) {
8694 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8695 + } else {
8696 + revision_str = strdup("");
8697 + }
8698 +
8699 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8700 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8701 + } else {
8702 + familiar_revision_str = strdup("");
8703 + }
8704 +#endif
8705 +
8706 +#ifdef USE_DEBVERSION
8707 + sprintf_alloc(&complete_version, "%s%s%s%s",
8708 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8709 +#else
8710 + sprintf_alloc(&complete_version, "%s%s",
8711 + epoch_str, pkg->version);
8712 +#endif
8713 +
8714 + free(epoch_str);
8715 +#ifdef USE_DEBVERSION
8716 + free(revision_str);
8717 + free(familiar_revision_str);
8718 +#endif
8719 +
8720 + return complete_version;
8721 +}
8722 +
8723 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8724 +{
8725 + int err;
8726 + char *list_file_name = NULL;
8727 + FILE *list_file = NULL;
8728 + char *line;
8729 + char *installed_file_name;
8730 + int rootdirlen;
8731 +
8732 + pkg->installed_files_ref_cnt++;
8733 +
8734 + if (pkg->installed_files) {
8735 + return pkg->installed_files;
8736 + }
8737 +
8738 + pkg->installed_files = str_list_alloc();
8739 + if (pkg->installed_files == NULL) {
8740 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8741 + return NULL;
8742 + }
8743 +
8744 + /* For uninstalled packages, get the file list firectly from the package.
8745 + For installed packages, look at the package.list file in the database.
8746 + */
8747 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8748 + if (pkg->local_filename == NULL) {
8749 + return pkg->installed_files;
8750 + }
8751 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8752 + file. In other words, change deb_extract so that it can
8753 + simply return the file list as a char *[] rather than
8754 + insisting on writing in to a FILE * as it does now. */
8755 + list_file = tmpfile();
8756 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8757 + if (err) {
8758 + fclose(list_file);
8759 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8760 + __FUNCTION__, pkg->local_filename, strerror(err));
8761 + return pkg->installed_files;
8762 + }
8763 + rewind(list_file);
8764 + } else {
8765 + sprintf_alloc(&list_file_name, "%s/%s.list",
8766 + pkg->dest->info_dir, pkg->name);
8767 + if (! file_exists(list_file_name)) {
8768 + free(list_file_name);
8769 + return pkg->installed_files;
8770 + }
8771 +
8772 + list_file = fopen(list_file_name, "r");
8773 + if (list_file == NULL) {
8774 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8775 + list_file_name, strerror(errno));
8776 + free(list_file_name);
8777 + return pkg->installed_files;
8778 + }
8779 + free(list_file_name);
8780 + }
8781 +
8782 + rootdirlen = strlen( pkg->dest->root_dir );
8783 + while (1) {
8784 + char *file_name;
8785 +
8786 + line = file_read_line_alloc(list_file);
8787 + if (line == NULL) {
8788 + break;
8789 + }
8790 + str_chomp(line);
8791 + file_name = line;
8792 +
8793 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8794 + if( strncmp( pkg->dest->root_dir,
8795 + file_name,
8796 + rootdirlen ) ) {
8797 + if (*file_name == '.') {
8798 + file_name++;
8799 + }
8800 + if (*file_name == '/') {
8801 + file_name++;
8802 + }
8803 +
8804 + /* Freed in pkg_free_installed_files */
8805 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8806 + } else {
8807 + // already contains root_dir as header -> ABSOLUTE
8808 + sprintf_alloc(&installed_file_name, "%s", file_name);
8809 + }
8810 + str_list_append(pkg->installed_files, installed_file_name);
8811 + free(line);
8812 + }
8813 +
8814 + fclose(list_file);
8815 +
8816 + return pkg->installed_files;
8817 +}
8818 +
8819 +/* XXX: CLEANUP: This function and it's counterpart,
8820 + (pkg_get_installed_files), do not match our init/deinit naming
8821 + convention. Nor the alloc/free convention. But, then again, neither
8822 + of these conventions currrently fit the way these two functions
8823 + work. */
8824 +int pkg_free_installed_files(pkg_t *pkg)
8825 +{
8826 + str_list_elt_t *iter;
8827 +
8828 + pkg->installed_files_ref_cnt--;
8829 + if (pkg->installed_files_ref_cnt > 0) {
8830 + return 0;
8831 + }
8832 +
8833 + if (pkg->installed_files) {
8834 +
8835 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8836 + /* malloced in pkg_get_installed_files */
8837 + free (iter->data);
8838 + iter->data = NULL;
8839 + }
8840 +
8841 + str_list_deinit(pkg->installed_files);
8842 + }
8843 +
8844 + pkg->installed_files = NULL;
8845 +
8846 + return 0;
8847 +}
8848 +
8849 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8850 +{
8851 + int err;
8852 + char *list_file_name;
8853 +
8854 + //I don't think pkg_free_installed_files should be called here. Jamey
8855 + //pkg_free_installed_files(pkg);
8856 +
8857 + sprintf_alloc(&list_file_name, "%s/%s.list",
8858 + pkg->dest->info_dir, pkg->name);
8859 + if (!conf->noaction) {
8860 + err = unlink(list_file_name);
8861 + free(list_file_name);
8862 +
8863 + if (err) {
8864 + return errno;
8865 + }
8866 + }
8867 + return 0;
8868 +}
8869 +
8870 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8871 +{
8872 + conffile_list_elt_t *iter;
8873 + conffile_t *conffile;
8874 +
8875 + if (pkg == NULL) {
8876 + return NULL;
8877 + }
8878 +
8879 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8880 + conffile = iter->data;
8881 +
8882 + if (strcmp(conffile->name, file_name) == 0) {
8883 + return conffile;
8884 + }
8885 + }
8886 +
8887 + return NULL;
8888 +}
8889 +
8890 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8891 + const char *script, const char *args)
8892 +{
8893 + int err;
8894 + char *path;
8895 + char *cmd;
8896 +
8897 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8898 + maintainer script within a chroot environment. */
8899 +
8900 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8901 + have scripts in pkg->tmp_unpack_dir. */
8902 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8903 + if (pkg->dest == NULL) {
8904 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8905 + __FUNCTION__, pkg->name);
8906 + return EINVAL;
8907 + }
8908 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8909 + } else {
8910 + if (pkg->tmp_unpack_dir == NULL) {
8911 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8912 + __FUNCTION__, pkg->name);
8913 + return EINVAL;
8914 + }
8915 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8916 + }
8917 +
8918 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8919 + if (conf->noaction) return 0;
8920 +
8921 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8922 + scripts when running with offline_root mode and/or a dest other
8923 + than '/'. I've been playing around with some clever chroot
8924 + tricks and I might come up with something workable. */
8925 + if (conf->offline_root) {
8926 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8927 + }
8928 +
8929 + setenv("PKG_ROOT",
8930 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8931 +
8932 + if (! file_exists(path)) {
8933 + free(path);
8934 + return 0;
8935 + }
8936 +
8937 + if (conf->offline_root) {
8938 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8939 + free(path);
8940 + return 0;
8941 + }
8942 +
8943 + sprintf_alloc(&cmd, "%s %s", path, args);
8944 + free(path);
8945 +
8946 + err = xsystem(cmd);
8947 + free(cmd);
8948 +
8949 + if (err) {
8950 + fprintf(stderr, "%s script returned status %d\n", script, err);
8951 + return err;
8952 + }
8953 +
8954 + return 0;
8955 +}
8956 +
8957 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8958 +{
8959 + int i;
8960 +
8961 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8962 + if (pkg_state_want_map[i].value == sw) {
8963 + return strdup(pkg_state_want_map[i].str);
8964 + }
8965 + }
8966 +
8967 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8968 + __FUNCTION__, sw);
8969 + return strdup("<STATE_WANT_UNKNOWN>");
8970 +}
8971 +
8972 +pkg_state_want_t pkg_state_want_from_str(char *str)
8973 +{
8974 + int i;
8975 +
8976 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8977 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8978 + return pkg_state_want_map[i].value;
8979 + }
8980 + }
8981 +
8982 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8983 + __FUNCTION__, str);
8984 + return SW_UNKNOWN;
8985 +}
8986 +
8987 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8988 +{
8989 + int i;
8990 + int len = 3; /* ok\000 is minimum */
8991 + char *str = NULL;
8992 +
8993 + /* clear the temporary flags before converting to string */
8994 + sf &= SF_NONVOLATILE_FLAGS;
8995 +
8996 + if (sf == 0) {
8997 + return strdup("ok");
8998 + } else {
8999 +
9000 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9001 + if (sf & pkg_state_flag_map[i].value) {
9002 + len += strlen(pkg_state_flag_map[i].str) + 1;
9003 + }
9004 + }
9005 + str = malloc(len);
9006 + if ( str == NULL ) {
9007 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9008 + return NULL;
9009 + }
9010 + str[0] = 0;
9011 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9012 + if (sf & pkg_state_flag_map[i].value) {
9013 + strcat(str, pkg_state_flag_map[i].str);
9014 + strcat(str, ",");
9015 + }
9016 + }
9017 + len = strlen(str);
9018 + str[len-1] = 0; /* squash last comma */
9019 + return str;
9020 + }
9021 +}
9022 +
9023 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9024 +{
9025 + int i;
9026 + int sf = SF_OK;
9027 +
9028 + if (strcmp(str, "ok") == 0) {
9029 + return SF_OK;
9030 + }
9031 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9032 + const char *sfname = pkg_state_flag_map[i].str;
9033 + int sfname_len = strlen(sfname);
9034 + if (strncmp(str, sfname, sfname_len) == 0) {
9035 + sf |= pkg_state_flag_map[i].value;
9036 + str += sfname_len;
9037 + if (str[0] == ',') {
9038 + str++;
9039 + } else {
9040 + break;
9041 + }
9042 + }
9043 + }
9044 +
9045 + return sf;
9046 +}
9047 +
9048 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9049 +{
9050 + int i;
9051 +
9052 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9053 + if (pkg_state_status_map[i].value == ss) {
9054 + return strdup(pkg_state_status_map[i].str);
9055 + }
9056 + }
9057 +
9058 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9059 + __FUNCTION__, ss);
9060 + return strdup("<STATE_STATUS_UNKNOWN>");
9061 +}
9062 +
9063 +pkg_state_status_t pkg_state_status_from_str(char *str)
9064 +{
9065 + int i;
9066 +
9067 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9068 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9069 + return pkg_state_status_map[i].value;
9070 + }
9071 + }
9072 +
9073 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9074 + __FUNCTION__, str);
9075 + return SS_NOT_INSTALLED;
9076 +}
9077 +
9078 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9079 +{
9080 + nv_pair_list_elt_t *l;
9081 +
9082 + if (!pkg->architecture)
9083 + return 1;
9084 +
9085 + l = conf->arch_list.head;
9086 +
9087 + while (l) {
9088 + nv_pair_t *nv = l->data;
9089 + if (strcmp(nv->name, pkg->architecture) == 0) {
9090 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9091 + return 1;
9092 + }
9093 + l = l->next;
9094 + }
9095 +
9096 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9097 + return 0;
9098 +}
9099 +
9100 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9101 +{
9102 + nv_pair_list_elt_t *l;
9103 +
9104 + l = conf->arch_list.head;
9105 +
9106 + while (l) {
9107 + nv_pair_t *nv = l->data;
9108 + if (strcmp(nv->name, archname) == 0) {
9109 + int priority = strtol(nv->value, NULL, 0);
9110 + return priority;
9111 + }
9112 + l = l->next;
9113 + }
9114 + return 0;
9115 +}
9116 +
9117 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9118 +{
9119 + int i;
9120 + hash_table_t *pkg_hash = &conf->pkg_hash;
9121 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9122 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9123 +
9124 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9125 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9126 + /* update arch_priority for each package */
9127 + for (i = 0; i < available_pkgs->len; i++) {
9128 + pkg_t *pkg = available_pkgs->pkgs[i];
9129 + int arch_priority = 1;
9130 + if (!pkg)
9131 + continue;
9132 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9133 + if (pkg->architecture)
9134 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9135 + else
9136 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9137 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9138 + pkg->arch_priority = arch_priority;
9139 + }
9140 +
9141 + for (i = 0; i < available_pkgs->len; i++) {
9142 + pkg_t *pkg = available_pkgs->pkgs[i];
9143 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9144 + /* clear flags and want for any uninstallable package */
9145 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9146 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9147 + pkg->state_want = SW_UNKNOWN;
9148 + pkg->state_flag = 0;
9149 + }
9150 + }
9151 + pkg_vec_free(available_pkgs);
9152 +
9153 + /* update the file owner data structure */
9154 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9155 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9156 + for (i = 0; i < installed_pkgs->len; i++) {
9157 + pkg_t *pkg = installed_pkgs->pkgs[i];
9158 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9159 + str_list_elt_t *iter;
9160 + if (installed_files == NULL) {
9161 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9162 + break;
9163 + }
9164 + for (iter = installed_files->head; iter; iter = iter->next) {
9165 + char *installed_file = iter->data;
9166 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9167 + file_hash_set_file_owner(conf, installed_file, pkg);
9168 + }
9169 + }
9170 + pkg_vec_free(installed_pkgs);
9171 +
9172 + return 0;
9173 +}
9174 +
9175 +struct pkg_write_filelist_data {
9176 + ipkg_conf_t *conf;
9177 + pkg_t *pkg;
9178 + FILE *stream;
9179 +};
9180 +
9181 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9182 +{
9183 + struct pkg_write_filelist_data *data = data_;
9184 + pkg_t *entry = entry_;
9185 + if (entry == data->pkg) {
9186 + fprintf(data->stream, "%s\n", key);
9187 + }
9188 +}
9189 +
9190 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9191 +{
9192 + struct pkg_write_filelist_data data;
9193 + char *list_file_name = NULL;
9194 + int err = 0;
9195 +
9196 + if (!pkg) {
9197 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9198 + return -EINVAL;
9199 + }
9200 + ipkg_message(conf, IPKG_INFO,
9201 + " creating %s.list file\n", pkg->name);
9202 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9203 + if (!list_file_name) {
9204 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9205 + return -ENOMEM;
9206 + }
9207 + ipkg_message(conf, IPKG_INFO,
9208 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9209 + data.stream = fopen(list_file_name, "w");
9210 + if (!data.stream) {
9211 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9212 + list_file_name, strerror(errno));
9213 + return errno;
9214 + }
9215 + data.pkg = pkg;
9216 + data.conf = conf;
9217 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9218 + fclose(data.stream);
9219 + free(list_file_name);
9220 +
9221 + return err;
9222 +}
9223 +
9224 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9225 +{
9226 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9227 + hash_table_t *pkg_hash = &conf->pkg_hash;
9228 + int i;
9229 + int err;
9230 + if (conf->noaction)
9231 + return 0;
9232 +
9233 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9234 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9235 + for (i = 0; i < installed_pkgs->len; i++) {
9236 + pkg_t *pkg = installed_pkgs->pkgs[i];
9237 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9238 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9239 + err = pkg_write_filelist(conf, pkg);
9240 + if (err)
9241 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9242 + }
9243 + }
9244 + return 0;
9245 +}
9246 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg.h busybox-1.1.1-new/archival/libipkg/pkg.h
9247 --- busybox-1.1.1-old/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9248 +++ busybox-1.1.1-new/archival/libipkg/pkg.h 2006-03-30 00:39:48.000000000 +0200
9249 @@ -0,0 +1,230 @@
9250 +/* pkg.h - the itsy package management system
9251 +
9252 + Carl D. Worth
9253 +
9254 + Copyright (C) 2001 University of Southern California
9255 +
9256 + This program is free software; you can redistribute it and/or
9257 + modify it under the terms of the GNU General Public License as
9258 + published by the Free Software Foundation; either version 2, or (at
9259 + your option) any later version.
9260 +
9261 + This program is distributed in the hope that it will be useful, but
9262 + WITHOUT ANY WARRANTY; without even the implied warranty of
9263 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9264 + General Public License for more details.
9265 +*/
9266 +
9267 +#ifndef PKG_H
9268 +#define PKG_H
9269 +
9270 +#include <sys/types.h>
9271 +#include <sys/stat.h>
9272 +#include <unistd.h>
9273 +
9274 +#include "pkg_vec.h"
9275 +#include "str_list.h"
9276 +#include "pkg_src.h"
9277 +#include "pkg_dest.h"
9278 +#include "ipkg_conf.h"
9279 +#include "conffile_list.h"
9280 +
9281 +struct ipkg_conf;
9282 +
9283 +
9284 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9285 +
9286 +/* I think "Size" is currently the shortest field name */
9287 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9288 +
9289 +enum pkg_state_want
9290 +{
9291 + SW_UNKNOWN = 1,
9292 + SW_INSTALL,
9293 + SW_DEINSTALL,
9294 + SW_PURGE,
9295 + SW_LAST_STATE_WANT
9296 +};
9297 +typedef enum pkg_state_want pkg_state_want_t;
9298 +
9299 +enum pkg_state_flag
9300 +{
9301 + SF_OK = 0,
9302 + SF_REINSTREQ = 1,
9303 + SF_HOLD = 2, /* do not upgrade version */
9304 + SF_REPLACE = 4, /* replace this package */
9305 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9306 + SF_PREFER = 16, /* prefer this version */
9307 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9308 + SF_MARKED = 64, /* temporary mark */
9309 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9310 + SF_USER = 256,
9311 + SF_LAST_STATE_FLAG
9312 +};
9313 +typedef enum pkg_state_flag pkg_state_flag_t;
9314 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9315 +
9316 +enum pkg_state_status
9317 +{
9318 + SS_NOT_INSTALLED = 1,
9319 + SS_UNPACKED,
9320 + SS_HALF_CONFIGURED,
9321 + SS_INSTALLED,
9322 + SS_HALF_INSTALLED,
9323 + SS_CONFIG_FILES,
9324 + SS_POST_INST_FAILED,
9325 + SS_REMOVAL_FAILED,
9326 + SS_LAST_STATE_STATUS
9327 +};
9328 +typedef enum pkg_state_status pkg_state_status_t;
9329 +
9330 +struct abstract_pkg{
9331 + char * name;
9332 + int dependencies_checked;
9333 + pkg_vec_t * pkgs;
9334 + pkg_state_status_t state_status;
9335 + pkg_state_flag_t state_flag;
9336 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9337 + abstract_pkg_vec_t * provided_by;
9338 + abstract_pkg_vec_t * replaced_by;
9339 +};
9340 +
9341 +#include "pkg_depends.h"
9342 +
9343 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9344 +
9345 + The 3 version fields should go into a single version struct. (This
9346 + is especially important since, currently, pkg->version can easily
9347 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9348 + distinct. This has been the source of multiple bugs.
9349 +
9350 + The 3 state fields could possibly also go into their own struct.
9351 +
9352 + All fields which deal with lists of packages, (Depends,
9353 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9354 + be handled by a single struct in pkg_t
9355 +
9356 + All string fields for which there is a small set of possible
9357 + values, (section, maintainer, architecture, maybe version?), that
9358 + are reused among different packages -- for all such packages we
9359 + should move from "char *"s to some atom datatype to share data
9360 + storage and use less memory. We might even do reference counting,
9361 + but probably not since most often we only create new pkg_t structs,
9362 + we don't often free them. */
9363 +struct pkg
9364 +{
9365 + char *name;
9366 + unsigned long epoch;
9367 + char *version;
9368 + char *revision;
9369 + char *familiar_revision;
9370 + pkg_src_t *src;
9371 + pkg_dest_t *dest;
9372 + char *architecture;
9373 + char *section;
9374 + char *maintainer;
9375 + char *description;
9376 + pkg_state_want_t state_want;
9377 + pkg_state_flag_t state_flag;
9378 + pkg_state_status_t state_status;
9379 + char **depends_str;
9380 + int depends_count;
9381 + char **pre_depends_str;
9382 + int pre_depends_count;
9383 + char **recommends_str;
9384 + int recommends_count;
9385 + char **suggests_str;
9386 + int suggests_count;
9387 + compound_depend_t * depends;
9388 +
9389 + /* Abhaya: new conflicts */
9390 + char **conflicts_str;
9391 + compound_depend_t * conflicts;
9392 + int conflicts_count;
9393 +
9394 + char **replaces_str;
9395 + int replaces_count;
9396 + abstract_pkg_t ** replaces;
9397 +
9398 + char **provides_str;
9399 + int provides_count;
9400 + abstract_pkg_t ** provides;
9401 +
9402 + abstract_pkg_t *parent;
9403 +
9404 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9405 +
9406 + char *filename;
9407 + char *local_filename;
9408 + char *url;
9409 + char *tmp_unpack_dir;
9410 + char *md5sum;
9411 + char *size;
9412 + char *installed_size;
9413 + char *priority;
9414 + char *source;
9415 + conffile_list_t conffiles;
9416 + time_t installed_time;
9417 + /* As pointer for lazy evaluation */
9418 + str_list_t *installed_files;
9419 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9420 + mechanism to avoid the problem here, (which is that the
9421 + installed_files list was being freed from an inner loop while
9422 + still being used within an outer loop. */
9423 + int installed_files_ref_cnt;
9424 + int essential;
9425 + int arch_priority;
9426 +};
9427 +
9428 +pkg_t *pkg_new(void);
9429 +int pkg_init(pkg_t *pkg);
9430 +void pkg_deinit(pkg_t *pkg);
9431 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9432 +abstract_pkg_t *abstract_pkg_new(void);
9433 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9434 +
9435 +/*
9436 + * merges fields from newpkg into oldpkg.
9437 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9438 + */
9439 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9440 +
9441 +char *pkg_version_str_alloc(pkg_t *pkg);
9442 +
9443 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9444 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9445 +int abstract_pkg_name_compare(void *a, void *b);
9446 +
9447 +char * pkg_formatted_info(pkg_t *pkg );
9448 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9449 +
9450 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9451 +
9452 +void pkg_print_info(pkg_t *pkg, FILE *file);
9453 +void pkg_print_status(pkg_t * pkg, FILE * file);
9454 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9455 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9456 +int pkg_free_installed_files(pkg_t *pkg);
9457 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9458 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9459 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9460 + const char *script, const char *args);
9461 +
9462 +/* enum mappings */
9463 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9464 +pkg_state_want_t pkg_state_want_from_str(char *str);
9465 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9466 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9467 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9468 +pkg_state_status_t pkg_state_status_from_str(char *str);
9469 +
9470 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9471 +
9472 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9473 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9474 +int pkg_free_installed_files(pkg_t *pkg);
9475 +
9476 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9477 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9478 +
9479 +#endif
9480 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_depends.c busybox-1.1.1-new/archival/libipkg/pkg_depends.c
9481 --- busybox-1.1.1-old/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9482 +++ busybox-1.1.1-new/archival/libipkg/pkg_depends.c 2006-03-30 00:39:48.000000000 +0200
9483 @@ -0,0 +1,1029 @@
9484 +/* pkg_depends.c - the itsy package management system
9485 +
9486 + Steven M. Ayer
9487 +
9488 + Copyright (C) 2002 Compaq Computer Corporation
9489 +
9490 + This program is free software; you can redistribute it and/or
9491 + modify it under the terms of the GNU General Public License as
9492 + published by the Free Software Foundation; either version 2, or (at
9493 + your option) any later version.
9494 +
9495 + This program is distributed in the hope that it will be useful, but
9496 + WITHOUT ANY WARRANTY; without even the implied warranty of
9497 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9498 + General Public License for more details.
9499 +*/
9500 +
9501 +#include "ipkg.h"
9502 +#include <errno.h>
9503 +#include <ctype.h>
9504 +
9505 +#include "pkg.h"
9506 +#include "ipkg_utils.h"
9507 +#include "pkg_hash.h"
9508 +#include "ipkg_message.h"
9509 +#include "pkg_parse.h"
9510 +#include "hash_table.h"
9511 +
9512 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9513 +static depend_t * depend_init(void);
9514 +static void depend_deinit(depend_t *d);
9515 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9516 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9517 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9518 +
9519 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9520 +{
9521 + depend_t *depend = (depend_t *)cdata;
9522 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9523 + return 1;
9524 + else
9525 + return 0;
9526 +}
9527 +
9528 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9529 +{
9530 + depend_t *depend = (depend_t *)cdata;
9531 +#if 0
9532 + pkg_t * temp = pkg_new();
9533 + int comparison;
9534 + parseVersion(temp, depend->version);
9535 + comparison = pkg_compare_versions(pkg, temp);
9536 + free(temp);
9537 +
9538 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9539 + __FUNCTION__, pkg->name, pkg->version,
9540 + depend, depend->constraint, depend->version,
9541 + comparison, version_constraints_satisfied(depend, pkg));
9542 +#endif
9543 + if (version_constraints_satisfied(depend, pkg))
9544 + return 1;
9545 + else
9546 + return 0;
9547 +}
9548 +
9549 +/* returns ndependences or negative error value */
9550 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9551 + pkg_vec_t *unsatisfied, char *** unresolved)
9552 +{
9553 + pkg_t * satisfier_entry_pkg;
9554 + register int i, j, k;
9555 + int count, found;
9556 + char ** the_lost;
9557 + abstract_pkg_t * ab_pkg;
9558 +
9559 + /*
9560 + * this is a setup to check for redundant/cyclic dependency checks,
9561 + * which are marked at the abstract_pkg level
9562 + */
9563 + if (!(ab_pkg = pkg->parent)) {
9564 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9565 + *unresolved = NULL;
9566 + return 0;
9567 + }
9568 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9569 + *unresolved = NULL;
9570 + return 0;
9571 + } else {
9572 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9573 + }
9574 + /**/
9575 +
9576 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9577 + if (!count){
9578 + *unresolved = NULL;
9579 + return 0;
9580 + }
9581 +
9582 + the_lost = NULL;
9583 +
9584 + /* foreach dependency */
9585 + for (i = 0; i < count; i++) {
9586 + compound_depend_t * compound_depend = &pkg->depends[i];
9587 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9588 + found = 0;
9589 + satisfier_entry_pkg = NULL;
9590 +
9591 + if (compound_depend->type == GREEDY_DEPEND) {
9592 + /* foreach possible satisfier */
9593 + for (j = 0; j < compound_depend->possibility_count; j++) {
9594 + /* foreach provided_by, which includes the abstract_pkg itself */
9595 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9596 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9597 + int nposs = ab_provider_vec->len;
9598 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9599 + int l;
9600 + for (l = 0; l < nposs; l++) {
9601 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9602 + /* if no depends on this one, try the first package that Provides this one */
9603 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9604 + continue;
9605 + }
9606 +
9607 + /* cruise this possiblity's pkg_vec looking for an installed version */
9608 + for (k = 0; k < test_vec->len; k++) {
9609 + pkg_t *pkg_scout = test_vec->pkgs[k];
9610 + /* not installed, and not already known about? */
9611 + if ((pkg_scout->state_want != SW_INSTALL)
9612 + && !pkg_scout->parent->dependencies_checked
9613 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9614 + char ** newstuff = NULL;
9615 + int rc;
9616 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9617 + /* check for not-already-installed dependencies */
9618 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9619 + pkg_scout,
9620 + tmp_vec,
9621 + &newstuff);
9622 + if (newstuff == NULL) {
9623 + int i;
9624 + int ok = 1;
9625 + for (i = 0; i < rc; i++) {
9626 + pkg_t *p = tmp_vec->pkgs[i];
9627 + if (p->state_want == SW_INSTALL)
9628 + continue;
9629 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9630 + ok = 0;
9631 + break;
9632 + }
9633 + pkg_vec_free (tmp_vec);
9634 + if (ok) {
9635 + /* mark this one for installation */
9636 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9637 + pkg_vec_insert(unsatisfied, pkg_scout);
9638 + }
9639 + } else {
9640 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9641 + free (newstuff);
9642 + }
9643 + }
9644 + }
9645 + }
9646 + }
9647 +
9648 + continue;
9649 + }
9650 +
9651 + /* foreach possible satisfier, look for installed package */
9652 + for (j = 0; j < compound_depend->possibility_count; j++) {
9653 + /* foreach provided_by, which includes the abstract_pkg itself */
9654 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9655 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9656 + pkg_t *satisfying_pkg =
9657 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9658 + pkg_installed_and_constraint_satisfied,
9659 + dependence_to_satisfy, 1);
9660 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9661 + if (satisfying_pkg != NULL) {
9662 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9663 + satisfying_pkg = NULL;
9664 + }
9665 + }
9666 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9667 + if (satisfying_pkg != NULL) {
9668 + found = 1;
9669 + break;
9670 + }
9671 +
9672 + }
9673 + /* if nothing installed matches, then look for uninstalled satisfier */
9674 + if (!found) {
9675 + /* foreach possible satisfier, look for installed package */
9676 + for (j = 0; j < compound_depend->possibility_count; j++) {
9677 + /* foreach provided_by, which includes the abstract_pkg itself */
9678 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9679 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9680 + pkg_t *satisfying_pkg =
9681 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9682 + pkg_constraint_satisfied,
9683 + dependence_to_satisfy, 1);
9684 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9685 + if (satisfying_pkg != NULL) {
9686 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9687 + satisfying_pkg = NULL;
9688 + }
9689 + }
9690 +
9691 + /* user request overrides package recommendation */
9692 + if (satisfying_pkg != NULL
9693 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9694 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9695 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9696 + pkg->name, satisfying_pkg->name);
9697 + continue;
9698 + }
9699 +
9700 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9701 + if (satisfying_pkg != NULL) {
9702 + satisfier_entry_pkg = satisfying_pkg;
9703 + break;
9704 + }
9705 + }
9706 + }
9707 +
9708 + /* we didn't find one, add something to the unsatisfied vector */
9709 + if (!found) {
9710 + if (!satisfier_entry_pkg) {
9711 + /* failure to meet recommendations is not an error */
9712 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9713 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9714 + else
9715 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9716 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9717 + }
9718 + else {
9719 + if (compound_depend->type == SUGGEST) {
9720 + /* just mention it politely */
9721 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9722 + pkg->name, satisfier_entry_pkg->name);
9723 + } else {
9724 + char ** newstuff = NULL;
9725 +
9726 + if (satisfier_entry_pkg != pkg &&
9727 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9728 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9729 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9730 + satisfier_entry_pkg,
9731 + unsatisfied,
9732 + &newstuff);
9733 + the_lost = merge_unresolved(the_lost, newstuff);
9734 + }
9735 + }
9736 + }
9737 + }
9738 + }
9739 + *unresolved = the_lost;
9740 +
9741 + return unsatisfied->len;
9742 +}
9743 +
9744 +/*checking for conflicts !in replaces
9745 + If a packages conflicts with another but is also replacing it, I should not consider it a
9746 + really conflicts
9747 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9748 +*/
9749 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9750 +{
9751 + int i ;
9752 + int replaces_count = pkg->replaces_count;
9753 + abstract_pkg_t **replaces;
9754 +
9755 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9756 + return 0;
9757 +
9758 + replaces = pkg->replaces;
9759 +
9760 + for (i = 0; i < replaces_count; i++) {
9761 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9762 + return 1;
9763 + }
9764 + return 0;
9765 +
9766 +}
9767 +
9768 +
9769 +/* Abhaya: added support for conflicts */
9770 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9771 +{
9772 + pkg_vec_t * installed_conflicts, * test_vec;
9773 + compound_depend_t * conflicts;
9774 + depend_t ** possible_satisfiers;
9775 + depend_t * possible_satisfier;
9776 + register int i, j, k;
9777 + int count;
9778 + abstract_pkg_t * ab_pkg;
9779 + pkg_t **pkg_scouts;
9780 + pkg_t *pkg_scout;
9781 +
9782 + /*
9783 + * this is a setup to check for redundant/cyclic dependency checks,
9784 + * which are marked at the abstract_pkg level
9785 + */
9786 + if(!(ab_pkg = pkg->parent)){
9787 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9788 + return (pkg_vec_t *)NULL;
9789 + }
9790 +
9791 + conflicts = pkg->conflicts;
9792 + if(!conflicts){
9793 + return (pkg_vec_t *)NULL;
9794 + }
9795 + installed_conflicts = pkg_vec_alloc();
9796 +
9797 + count = pkg->conflicts_count;
9798 +
9799 +
9800 +
9801 + /* foreach conflict */
9802 + for(i = 0; i < pkg->conflicts_count; i++){
9803 +
9804 + possible_satisfiers = conflicts->possibilities;
9805 +
9806 + /* foreach possible satisfier */
9807 + for(j = 0; j < conflicts->possibility_count; j++){
9808 + possible_satisfier = possible_satisfiers[j];
9809 + if (!possible_satisfier)
9810 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9811 + if (!possible_satisfier->pkg)
9812 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9813 + test_vec = possible_satisfier->pkg->pkgs;
9814 + if (test_vec) {
9815 + /* pkg_vec found, it is an actual package conflict
9816 + * cruise this possiblity's pkg_vec looking for an installed version */
9817 + pkg_scouts = test_vec->pkgs;
9818 + for(k = 0; k < test_vec->len; k++){
9819 + pkg_scout = pkg_scouts[k];
9820 + if (!pkg_scout) {
9821 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9822 + continue;
9823 + }
9824 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9825 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9826 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9827 + pkg_vec_insert(installed_conflicts, pkg_scout);
9828 + }
9829 + }
9830 + }
9831 + }
9832 + }
9833 + conflicts++;
9834 + }
9835 +
9836 + if (installed_conflicts->len)
9837 + return installed_conflicts;
9838 + pkg_vec_free(installed_conflicts);
9839 + return (pkg_vec_t *)NULL;
9840 +}
9841 +
9842 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9843 +{
9844 + pkg_t * temp;
9845 + int comparison;
9846 +
9847 + if(depends->constraint == NONE)
9848 + return 1;
9849 +
9850 + temp = pkg_new();
9851 +
9852 + parseVersion(temp, depends->version);
9853 +
9854 + comparison = pkg_compare_versions(pkg, temp);
9855 +
9856 + free(temp);
9857 +
9858 + if((depends->constraint == EARLIER) &&
9859 + (comparison < 0))
9860 + return 1;
9861 + else if((depends->constraint == LATER) &&
9862 + (comparison > 0))
9863 + return 1;
9864 + else if(comparison == 0)
9865 + return 1;
9866 + else if((depends->constraint == LATER_EQUAL) &&
9867 + (comparison >= 0))
9868 + return 1;
9869 + else if((depends->constraint == EARLIER_EQUAL) &&
9870 + (comparison <= 0))
9871 + return 1;
9872 +
9873 + return 0;
9874 +}
9875 +
9876 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9877 +{
9878 + abstract_pkg_t *apkg = depend->pkg;
9879 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9880 + int n_providers = provider_apkgs->len;
9881 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9882 + pkg_vec_t *pkg_vec;
9883 + int n_pkgs ;
9884 + int i;
9885 + int j;
9886 +
9887 + for (i = 0; i < n_providers; i++) {
9888 + abstract_pkg_t *papkg = apkgs[i];
9889 + pkg_vec = papkg->pkgs;
9890 + if (pkg_vec) {
9891 + n_pkgs = pkg_vec->len;
9892 + for (j = 0; j < n_pkgs; j++) {
9893 + pkg_t *pkg = pkg_vec->pkgs[j];
9894 + if (version_constraints_satisfied(depend, pkg)) {
9895 + return 1;
9896 + }
9897 + }
9898 + }
9899 + }
9900 + return 0;
9901 +}
9902 +
9903 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9904 +{
9905 + abstract_pkg_t *apkg = depend->pkg;
9906 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9907 + int n_providers = provider_apkgs->len;
9908 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9909 + int i;
9910 + int n_pkgs;
9911 + int j;
9912 +
9913 + for (i = 0; i < n_providers; i++) {
9914 + abstract_pkg_t *papkg = apkgs[i];
9915 + pkg_vec_t *pkg_vec = papkg->pkgs;
9916 + if (pkg_vec) {
9917 + n_pkgs = pkg_vec->len;
9918 + for (j = 0; j < n_pkgs; j++) {
9919 + pkg_t *pkg = pkg_vec->pkgs[j];
9920 + if (version_constraints_satisfied(depend, pkg)) {
9921 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9922 + return 1;
9923 + }
9924 + }
9925 + }
9926 + }
9927 + return 0;
9928 +}
9929 +
9930 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9931 +{
9932 + register int i;
9933 + pkg_t ** pkgs = vec->pkgs;
9934 +
9935 + for(i = 0; i < vec->len; i++)
9936 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9937 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9938 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9939 + return 1;
9940 + return 0;
9941 +}
9942 +
9943 +
9944 +#ifdef DeadCode
9945 +/**
9946 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9947 + * the same abstract package and 0 otherwise.
9948 + */
9949 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9950 +{
9951 + abstract_pkg_t **provides = pkg->provides;
9952 + int provides_count = pkg->provides_count;
9953 + abstract_pkg_t **replacee_provides = replacee->provides;
9954 + int replacee_provides_count = replacee->provides_count;
9955 + int i, j;
9956 + for (i = 0; i < provides_count; i++) {
9957 + abstract_pkg_t *apkg = provides[i];
9958 + for (j = 0; j < replacee_provides_count; j++) {
9959 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9960 + if (apkg == replacee_apkg)
9961 + return 1;
9962 + }
9963 + }
9964 + return 0;
9965 +}
9966 +#endif
9967 +
9968 +/**
9969 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9970 + * and 0 otherwise.
9971 + */
9972 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9973 +{
9974 + abstract_pkg_t **provides = pkg->provides;
9975 + int provides_count = pkg->provides_count;
9976 + int i;
9977 + for (i = 0; i < provides_count; i++) {
9978 + if (provides[i] == providee)
9979 + return 1;
9980 + }
9981 + return 0;
9982 +}
9983 +
9984 +/**
9985 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9986 + * otherwise.
9987 + */
9988 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9989 +{
9990 + abstract_pkg_t **replaces = pkg->replaces;
9991 + int replaces_count = pkg->replaces_count;
9992 + abstract_pkg_t **replacee_provides = pkg->provides;
9993 + int replacee_provides_count = pkg->provides_count;
9994 + int i, j;
9995 + for (i = 0; i < replaces_count; i++) {
9996 + abstract_pkg_t *abstract_replacee = replaces[i];
9997 + for (j = 0; j < replacee_provides_count; j++) {
9998 + if (replacee_provides[j] == abstract_replacee)
9999 + return 1;
10000 + }
10001 + }
10002 + return 0;
10003 +}
10004 +
10005 +
10006 +/**
10007 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10008 + * otherwise.
10009 + */
10010 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10011 +{
10012 + compound_depend_t *conflicts = pkg->conflicts;
10013 + int conflicts_count = pkg->conflicts_count;
10014 + int i, j;
10015 + for (i = 0; i < conflicts_count; i++) {
10016 + int possibility_count = conflicts[i].possibility_count;
10017 + struct depend **possibilities = conflicts[i].possibilities;
10018 + for (j = 0; j < possibility_count; j++) {
10019 + if (possibilities[j]->pkg == conflictee) {
10020 + return 1;
10021 + }
10022 + }
10023 + }
10024 + return 0;
10025 +}
10026 +
10027 +/**
10028 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10029 + * conflictee's provides and 0 otherwise.
10030 + */
10031 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10032 +{
10033 + compound_depend_t *conflicts = pkg->conflicts;
10034 + int conflicts_count = pkg->conflicts_count;
10035 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10036 + int conflictee_provides_count = conflictee->provides_count;
10037 + int i, j, k;
10038 + int possibility_count;
10039 + struct depend **possibilities;
10040 + abstract_pkg_t *possibility ;
10041 +
10042 + for (i = 0; i < conflicts_count; i++) {
10043 + possibility_count = conflicts[i].possibility_count;
10044 + possibilities = conflicts[i].possibilities;
10045 + for (j = 0; j < possibility_count; j++) {
10046 + possibility = possibilities[j]->pkg;
10047 + for (k = 0; k < conflictee_provides_count; k++) {
10048 + if (possibility == conflictee_provides[k]) {
10049 + return 1;
10050 + }
10051 + }
10052 + }
10053 + }
10054 + return 0;
10055 +}
10056 +
10057 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10058 +{
10059 + int oldlen = 0, newlen = 0;
10060 + char ** result;
10061 + register int i, j;
10062 +
10063 + if(!newstuff)
10064 + return oldstuff;
10065 +
10066 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10067 + while(newstuff && newstuff[newlen]) newlen++;
10068 +
10069 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10070 + if (result == NULL) {
10071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10072 + return NULL;
10073 + }
10074 +
10075 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10076 + *(result + i) = *(newstuff + j);
10077 +
10078 + *(result + i) = NULL;
10079 +
10080 + return result;
10081 +}
10082 +
10083 +/*
10084 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10085 + * this is null terminated, no count is carried around
10086 + */
10087 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10088 +{
10089 + int count;
10090 + char ** resized;
10091 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10092 +
10093 + count = 0;
10094 + while(the_lost && the_lost[count]) count++;
10095 +
10096 + count++; /* need one to hold the null */
10097 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10098 + if (resized == NULL) {
10099 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10100 + return NULL;
10101 + }
10102 + resized[count - 1] = strdup(depend_str);
10103 + resized[count] = NULL;
10104 +
10105 + return resized;
10106 +}
10107 +
10108 +void printDepends(pkg_t * pkg)
10109 +{
10110 + register int i, j;
10111 + compound_depend_t * depend;
10112 + int count;
10113 +
10114 + count = pkg->pre_depends_count + pkg->depends_count;
10115 +
10116 + depend = pkg->depends;
10117 + if(!depend){
10118 + fprintf(stderr, "Depends pointer is NULL\n");
10119 + return;
10120 + }
10121 + for(i = 0; i < count; i++){
10122 + fprintf(stderr, "%s has %d possibilities:\n",
10123 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10124 + depend->possibility_count);
10125 + for(j = 0; j < depend->possibility_count; j++)
10126 + fprintf(stderr, "\t%s version %s (%d)\n",
10127 + depend->possibilities[j]->pkg->name,
10128 + depend->possibilities[j]->version,
10129 + depend->possibilities[j]->constraint);
10130 + depend++;
10131 + }
10132 +}
10133 +
10134 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10135 +{
10136 + register int i, j;
10137 +
10138 + /* every pkg provides itself */
10139 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10140 +
10141 + if (!pkg->provides_count)
10142 + return 0;
10143 +
10144 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10145 + if (pkg->provides == NULL) {
10146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10147 + return -1 ;
10148 + }
10149 + pkg->provides[0] = ab_pkg;
10150 +
10151 + // if (strcmp(ab_pkg->name, pkg->name))
10152 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10153 +
10154 + for(i = 0; i < pkg->provides_count; i++){
10155 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10156 +
10157 + pkg->provides[i+1] = provided_abpkg;
10158 +
10159 + j = 0;
10160 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10161 + }
10162 + return 0;
10163 +}
10164 +
10165 +/* Abhaya: added conflicts support */
10166 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10167 +{
10168 + register int i;
10169 + compound_depend_t * conflicts;
10170 +
10171 + if (!pkg->conflicts_count)
10172 + return 0;
10173 +
10174 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10175 + pkg->conflicts_count);
10176 + if (conflicts == NULL) {
10177 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10178 + return -1;
10179 + }
10180 + for (i = 0; i < pkg->conflicts_count; i++) {
10181 + conflicts->type = CONFLICTS;
10182 + parseDepends(conflicts, hash,
10183 + pkg->conflicts_str[i]);
10184 +#if 0
10185 + for (j = 0; j < conflicts->possibility_count; j++) {
10186 + depend_t *possibility = conflicts->possibilities[j];
10187 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10188 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10189 + }
10190 +#endif
10191 + conflicts++;
10192 + }
10193 + return 0;
10194 +}
10195 +
10196 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10197 +{
10198 + register int i, j;
10199 +
10200 + if (!pkg->replaces_count)
10201 + return 0;
10202 +
10203 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10204 + if (pkg->replaces == NULL) {
10205 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10206 + return -1;
10207 + }
10208 +
10209 + // if (strcmp(ab_pkg->name, pkg->name))
10210 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10211 +
10212 + for(i = 0; i < pkg->replaces_count; i++){
10213 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10214 +
10215 + pkg->replaces[i] = old_abpkg;
10216 +
10217 + j = 0;
10218 + if (!old_abpkg->replaced_by)
10219 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10220 + if ( old_abpkg->replaced_by == NULL ){
10221 + return -1;
10222 + }
10223 + /* if a package pkg both replaces and conflicts old_abpkg,
10224 + * then add it to the replaced_by vector so that old_abpkg
10225 + * will be upgraded to ab_pkg automatically */
10226 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10227 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10228 + }
10229 + return 0;
10230 +}
10231 +
10232 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10233 +{
10234 + int count;
10235 + register int i;
10236 + compound_depend_t * depends;
10237 +
10238 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10239 + return 0;
10240 +
10241 + if (0 && pkg->pre_depends_count)
10242 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10243 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10244 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10245 + if (depends == NULL) {
10246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10247 + return -1;
10248 + }
10249 +
10250 +
10251 + for(i = 0; i < pkg->pre_depends_count; i++){
10252 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10253 + if (0 && pkg->pre_depends_count)
10254 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10255 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10256 + depends->type = PREDEPEND;
10257 + depends++;
10258 + }
10259 +
10260 + for(i = 0; i < pkg->recommends_count; i++){
10261 + parseDepends(depends, hash, pkg->recommends_str[i]);
10262 + if (0 && pkg->recommends_count)
10263 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10264 + pkg->recommends_str[i], depends, depends->possibility_count);
10265 + depends->type = RECOMMEND;
10266 + depends++;
10267 + }
10268 +
10269 + for(i = 0; i < pkg->suggests_count; i++){
10270 + parseDepends(depends, hash, pkg->suggests_str[i]);
10271 + if (0 && pkg->suggests_count)
10272 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10273 + pkg->suggests_str[i], depends, depends->possibility_count);
10274 + depends->type = SUGGEST;
10275 + depends++;
10276 + }
10277 +
10278 + for(i = 0; i < pkg->depends_count; i++){
10279 + parseDepends(depends, hash, pkg->depends_str[i]);
10280 + if (0 && pkg->depends_count)
10281 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10282 + pkg->depends_str[i], depends, depends->possibility_count);
10283 + depends++;
10284 + }
10285 + return 0;
10286 +}
10287 +
10288 +/*
10289 + * pkg_depend_string: returns the depends string specified by index.
10290 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10291 + * [0,npredepends) -> returns pre_depends_str[index]
10292 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10293 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10294 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10295 + */
10296 +char *pkg_depend_str(pkg_t *pkg, int index)
10297 +{
10298 + if (index < pkg->pre_depends_count) {
10299 + return pkg->pre_depends_str[index];
10300 + }
10301 + index -= pkg->pre_depends_count;
10302 +
10303 + if (index < pkg->recommends_count) {
10304 + return pkg->recommends_str[index];
10305 + }
10306 + index -= pkg->recommends_count;
10307 +
10308 + if (index < pkg->suggests_count) {
10309 + return pkg->suggests_str[index];
10310 + }
10311 + index -= pkg->suggests_count;
10312 +
10313 + if (index < pkg->depends_count) {
10314 + return pkg->depends_str[index];
10315 + }
10316 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10317 + return NULL;
10318 +}
10319 +
10320 +void freeDepends(pkg_t *pkg)
10321 +{
10322 + int i;
10323 +
10324 + if (pkg == NULL || pkg->depends == NULL) {
10325 + return;
10326 + }
10327 +
10328 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10329 + for (i=0; i < pkg->depends->possibility_count; i++) {
10330 + depend_deinit(pkg->depends->possibilities[i]);
10331 + }
10332 + free(pkg->depends->possibilities);
10333 + free(pkg->depends);
10334 + pkg->depends = NULL;
10335 +}
10336 +
10337 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10338 +{
10339 + compound_depend_t * depends;
10340 + int count, othercount;
10341 + register int i, j;
10342 + abstract_pkg_t * ab_depend;
10343 + abstract_pkg_t ** temp;
10344 +
10345 + count = pkg->pre_depends_count + pkg->depends_count;
10346 + depends = pkg->depends;
10347 +
10348 + if (0 && pkg->pre_depends_count)
10349 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10350 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10351 + for (i = 0; i < count; i++) {
10352 + if (0 && pkg->pre_depends_count)
10353 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10354 + for (j = 0; j < depends->possibility_count; j++){
10355 + ab_depend = depends->possibilities[j]->pkg;
10356 + if(!ab_depend->depended_upon_by)
10357 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10358 +
10359 + temp = ab_depend->depended_upon_by;
10360 + othercount = 1;
10361 + while(*temp){
10362 + temp++;
10363 + othercount++;
10364 + }
10365 + *temp = ab_pkg;
10366 +
10367 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10368 + (othercount + 1) * sizeof(abstract_pkg_t *));
10369 + /* the array may have moved */
10370 + temp = ab_depend->depended_upon_by + othercount;
10371 + *temp = NULL;
10372 + }
10373 + depends++;
10374 + }
10375 +}
10376 +
10377 +static depend_t * depend_init(void)
10378 +{
10379 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10380 + if ( d==NULL ){
10381 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10382 + return NULL;
10383 + }
10384 + d->constraint = NONE;
10385 + d->version = NULL;
10386 + d->pkg = NULL;
10387 +
10388 + return d;
10389 +}
10390 +
10391 +static void depend_deinit(depend_t *d)
10392 +{
10393 + free(d);
10394 +}
10395 +
10396 +static int parseDepends(compound_depend_t *compound_depend,
10397 + hash_table_t * hash, char * depend_str)
10398 +{
10399 + char * pkg_name, buffer[2048];
10400 + int num_of_ors = 0;
10401 + register int i;
10402 + register char * src, * dest;
10403 + depend_t ** possibilities;
10404 +
10405 + /* first count the number of ored possibilities for satisfying dependency */
10406 + src = depend_str;
10407 + while(*src)
10408 + if(*src++ == '|')
10409 + num_of_ors++;
10410 +
10411 + compound_depend->type = DEPEND;
10412 +
10413 + compound_depend->possibility_count = num_of_ors + 1;
10414 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10415 + if (!possibilities)
10416 + return -ENOMEM;
10417 + compound_depend->possibilities = possibilities;
10418 +
10419 + src = depend_str;
10420 + for(i = 0; i < num_of_ors + 1; i++){
10421 + possibilities[i] = depend_init();
10422 + if (!possibilities[i])
10423 + return -ENOMEM;
10424 + /* gobble up just the name first */
10425 + dest = buffer;
10426 + while(*src &&
10427 + !isspace(*src) &&
10428 + (*src != '(') &&
10429 + (*src != '*') &&
10430 + (*src != '|'))
10431 + *dest++ = *src++;
10432 + *dest = '\0';
10433 + pkg_name = trim_alloc(buffer);
10434 + if (pkg_name == NULL )
10435 + return -ENOMEM;
10436 +
10437 + /* now look at possible version info */
10438 +
10439 + /* skip to next chars */
10440 + if(isspace(*src))
10441 + while(*src && isspace(*src)) src++;
10442 +
10443 + /* extract constraint and version */
10444 + if(*src == '('){
10445 + src++;
10446 + if(!strncmp(src, "<<", 2)){
10447 + possibilities[i]->constraint = EARLIER;
10448 + src += 2;
10449 + }
10450 + else if(!strncmp(src, "<=", 2)){
10451 + possibilities[i]->constraint = EARLIER_EQUAL;
10452 + src += 2;
10453 + }
10454 + else if(!strncmp(src, ">=", 2)){
10455 + possibilities[i]->constraint = LATER_EQUAL;
10456 + src += 2;
10457 + }
10458 + else if(!strncmp(src, ">>", 2)){
10459 + possibilities[i]->constraint = LATER;
10460 + src += 2;
10461 + }
10462 + else if(!strncmp(src, "=", 1)){
10463 + possibilities[i]->constraint = EQUAL;
10464 + src++;
10465 + }
10466 + /* should these be here to support deprecated designations; dpkg does */
10467 + else if(!strncmp(src, "<", 1)){
10468 + possibilities[i]->constraint = EARLIER_EQUAL;
10469 + src++;
10470 + }
10471 + else if(!strncmp(src, ">", 1)){
10472 + possibilities[i]->constraint = LATER_EQUAL;
10473 + src++;
10474 + }
10475 +
10476 + /* now we have any constraint, pass space to version string */
10477 + while(isspace(*src)) src++;
10478 +
10479 + /* this would be the version string */
10480 + dest = buffer;
10481 + while(*src && *src != ')')
10482 + *dest++ = *src++;
10483 + *dest = '\0';
10484 +
10485 + possibilities[i]->version = trim_alloc(buffer);
10486 + /* fprintf(stderr, "let's print the depends version string:");
10487 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10488 + if (possibilities[i]->version == NULL )
10489 + return -ENOMEM;
10490 +
10491 +
10492 + }
10493 + /* hook up the dependency to its abstract pkg */
10494 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10495 +
10496 + free(pkg_name);
10497 +
10498 + /* now get past the ) and any possible | chars */
10499 + while(*src &&
10500 + (isspace(*src) ||
10501 + (*src == ')') ||
10502 + (*src == '|')))
10503 + src++;
10504 + if (*src == '*')
10505 + {
10506 + compound_depend->type = GREEDY_DEPEND;
10507 + src++;
10508 + }
10509 + }
10510 +
10511 + return 0;
10512 +}
10513 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_depends.h busybox-1.1.1-new/archival/libipkg/pkg_depends.h
10514 --- busybox-1.1.1-old/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10515 +++ busybox-1.1.1-new/archival/libipkg/pkg_depends.h 2006-03-30 00:39:48.000000000 +0200
10516 @@ -0,0 +1,105 @@
10517 +/* pkg_depends.h - the itsy package management system
10518 +
10519 + Steven M. Ayer
10520 +
10521 + Copyright (C) 2002 Compaq Computer Corporation
10522 +
10523 + This program is free software; you can redistribute it and/or
10524 + modify it under the terms of the GNU General Public License as
10525 + published by the Free Software Foundation; either version 2, or (at
10526 + your option) any later version.
10527 +
10528 + This program is distributed in the hope that it will be useful, but
10529 + WITHOUT ANY WARRANTY; without even the implied warranty of
10530 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10531 + General Public License for more details.
10532 +*/
10533 +
10534 +#ifndef PKG_DEPENDS_H
10535 +#define PKG_DEPENDS_H
10536 +
10537 +#include "pkg.h"
10538 +#include "pkg_hash.h"
10539 +
10540 +enum depend_type {
10541 + PREDEPEND,
10542 + DEPEND,
10543 + CONFLICTS,
10544 + GREEDY_DEPEND,
10545 + RECOMMEND,
10546 + SUGGEST
10547 +};
10548 +typedef enum depend_type depend_type_t;
10549 +
10550 +enum version_constraint {
10551 + NONE,
10552 + EARLIER,
10553 + EARLIER_EQUAL,
10554 + EQUAL,
10555 + LATER_EQUAL,
10556 + LATER
10557 +};
10558 +typedef enum version_constraint version_constraint_t;
10559 +
10560 +struct depend{
10561 + version_constraint_t constraint;
10562 + char * version;
10563 + abstract_pkg_t * pkg;
10564 +};
10565 +typedef struct depend depend_t;
10566 +
10567 +struct compound_depend{
10568 + depend_type_t type;
10569 + int possibility_count;
10570 + struct depend ** possibilities;
10571 +};
10572 +typedef struct compound_depend compound_depend_t;
10573 +
10574 +#include "hash_table.h"
10575 +
10576 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10577 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10578 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10579 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10580 +
10581 +/**
10582 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10583 + * the same abstract package and 0 otherwise.
10584 + */
10585 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10586 +
10587 +/**
10588 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10589 + * otherwise.
10590 + */
10591 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10592 +
10593 +/**
10594 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10595 + * otherwise.
10596 + */
10597 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10598 +
10599 +/**
10600 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10601 + * otherwise.
10602 + */
10603 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10604 +
10605 +/**
10606 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10607 + * otherwise.
10608 + */
10609 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10610 +
10611 +char *pkg_depend_str(pkg_t *pkg, int index);
10612 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10613 +void freeDepends(pkg_t *pkg);
10614 +void printDepends(pkg_t * pkg);
10615 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10616 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10617 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10618 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10619 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10620 +
10621 +#endif
10622 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest.c busybox-1.1.1-new/archival/libipkg/pkg_dest.c
10623 --- busybox-1.1.1-old/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10624 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest.c 2006-03-30 00:39:48.000000000 +0200
10625 @@ -0,0 +1,92 @@
10626 +/* pkg_dest.c - the itsy package management system
10627 +
10628 + Carl D. Worth
10629 +
10630 + Copyright (C) 2001 University of Southern California
10631 +
10632 + This program is free software; you can redistribute it and/or
10633 + modify it under the terms of the GNU General Public License as
10634 + published by the Free Software Foundation; either version 2, or (at
10635 + your option) any later version.
10636 +
10637 + This program is distributed in the hope that it will be useful, but
10638 + WITHOUT ANY WARRANTY; without even the implied warranty of
10639 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10640 + General Public License for more details.
10641 +*/
10642 +
10643 +#include "ipkg.h"
10644 +
10645 +#include "pkg_dest.h"
10646 +#include "file_util.h"
10647 +#include "str_util.h"
10648 +#include "sprintf_alloc.h"
10649 +
10650 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10651 +{
10652 + dest->name = strdup(name);
10653 +
10654 + /* Guarantee that dest->root_dir ends with a '/' */
10655 + if (str_ends_with(root_dir, "/")) {
10656 + dest->root_dir = strdup(root_dir);
10657 + } else {
10658 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10659 + }
10660 + file_mkdir_hier(dest->root_dir, 0755);
10661 +
10662 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10663 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10664 + file_mkdir_hier(dest->ipkg_dir, 0755);
10665 +
10666 + if (str_starts_with (lists_dir, "/"))
10667 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10668 + else
10669 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10670 +
10671 + file_mkdir_hier(dest->lists_dir, 0755);
10672 +
10673 + sprintf_alloc(&dest->info_dir, "%s/%s",
10674 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10675 + file_mkdir_hier(dest->info_dir, 0755);
10676 +
10677 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10678 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10679 +
10680 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10681 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10682 +
10683 + dest->status_file = NULL;
10684 +
10685 + return 0;
10686 +}
10687 +
10688 +void pkg_dest_deinit(pkg_dest_t *dest)
10689 +{
10690 + free(dest->name);
10691 + dest->name = NULL;
10692 +
10693 + free(dest->root_dir);
10694 + dest->root_dir = NULL;
10695 +
10696 + free(dest->ipkg_dir);
10697 + dest->ipkg_dir = NULL;
10698 +
10699 + free(dest->lists_dir);
10700 + dest->lists_dir = NULL;
10701 +
10702 + free(dest->info_dir);
10703 + dest->info_dir = NULL;
10704 +
10705 + free(dest->status_file_name);
10706 + dest->status_file_name = NULL;
10707 +
10708 + free(dest->status_file_tmp_name);
10709 + dest->status_file_tmp_name = NULL;
10710 +
10711 + if (dest->status_file) {
10712 + fclose(dest->status_file);
10713 + }
10714 + dest->status_file = NULL;
10715 +
10716 + dest->root_dir = NULL;
10717 +}
10718 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest.h busybox-1.1.1-new/archival/libipkg/pkg_dest.h
10719 --- busybox-1.1.1-old/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10720 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest.h 2006-03-30 00:39:48.000000000 +0200
10721 @@ -0,0 +1,38 @@
10722 +/* pkg_dest.h - the itsy package management system
10723 +
10724 + Carl D. Worth
10725 +
10726 + Copyright (C) 2001 University of Southern California
10727 +
10728 + This program is free software; you can redistribute it and/or
10729 + modify it under the terms of the GNU General Public License as
10730 + published by the Free Software Foundation; either version 2, or (at
10731 + your option) any later version.
10732 +
10733 + This program is distributed in the hope that it will be useful, but
10734 + WITHOUT ANY WARRANTY; without even the implied warranty of
10735 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10736 + General Public License for more details.
10737 +*/
10738 +
10739 +#ifndef PKG_DEST_H
10740 +#define PKG_DEST_H
10741 +
10742 +typedef struct pkg_dest pkg_dest_t;
10743 +struct pkg_dest
10744 +{
10745 + char *name;
10746 + char *root_dir;
10747 + char *ipkg_dir;
10748 + char *lists_dir;
10749 + char *info_dir;
10750 + char *status_file_name;
10751 + char *status_file_tmp_name;
10752 + FILE *status_file;
10753 +};
10754 +
10755 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10756 +void pkg_dest_deinit(pkg_dest_t *dest);
10757 +
10758 +#endif
10759 +
10760 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest_list.c busybox-1.1.1-new/archival/libipkg/pkg_dest_list.c
10761 --- busybox-1.1.1-old/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10762 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest_list.c 2006-03-30 00:39:48.000000000 +0200
10763 @@ -0,0 +1,85 @@
10764 +/* pkg_dest_list.c - the itsy package management system
10765 +
10766 + Carl D. Worth
10767 +
10768 + Copyright (C) 2001 University of Southern California
10769 +
10770 + This program is free software; you can redistribute it and/or
10771 + modify it under the terms of the GNU General Public License as
10772 + published by the Free Software Foundation; either version 2, or (at
10773 + your option) any later version.
10774 +
10775 + This program is distributed in the hope that it will be useful, but
10776 + WITHOUT ANY WARRANTY; without even the implied warranty of
10777 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10778 + General Public License for more details.
10779 +*/
10780 +
10781 +#include "ipkg.h"
10782 +
10783 +#include "pkg_dest.h"
10784 +#include "void_list.h"
10785 +#include "pkg_dest_list.h"
10786 +
10787 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10788 +{
10789 + return void_list_elt_init((void_list_elt_t *) elt, data);
10790 +}
10791 +
10792 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10793 +{
10794 + void_list_elt_deinit((void_list_elt_t *) elt);
10795 +}
10796 +
10797 +int pkg_dest_list_init(pkg_dest_list_t *list)
10798 +{
10799 + return void_list_init((void_list_t *) list);
10800 +}
10801 +
10802 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10803 +{
10804 + pkg_dest_list_elt_t *iter;
10805 + pkg_dest_t *pkg_dest;
10806 +
10807 + for (iter = list->head; iter; iter = iter->next) {
10808 + pkg_dest = iter->data;
10809 + pkg_dest_deinit(pkg_dest);
10810 +
10811 + /* malloced in pkg_dest_list_append */
10812 + free(pkg_dest);
10813 + iter->data = NULL;
10814 + }
10815 + void_list_deinit((void_list_t *) list);
10816 +}
10817 +
10818 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10819 + const char *root_dir,const char *lists_dir)
10820 +{
10821 + int err;
10822 + pkg_dest_t *pkg_dest;
10823 +
10824 + /* freed in plg_dest_list_deinit */
10825 + pkg_dest = malloc(sizeof(pkg_dest_t));
10826 + if (pkg_dest == NULL) {
10827 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10828 + return NULL;
10829 + }
10830 +
10831 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10832 + err = void_list_append((void_list_t *) list, pkg_dest);
10833 + if (err) {
10834 + return NULL;
10835 + }
10836 +
10837 + return pkg_dest;
10838 +}
10839 +
10840 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10841 +{
10842 + return void_list_push((void_list_t *) list, data);
10843 +}
10844 +
10845 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10846 +{
10847 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10848 +}
10849 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest_list.h busybox-1.1.1-new/archival/libipkg/pkg_dest_list.h
10850 --- busybox-1.1.1-old/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10851 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest_list.h 2006-03-30 00:39:48.000000000 +0200
10852 @@ -0,0 +1,50 @@
10853 +/* pkg_dest_list.h - the itsy package management system
10854 +
10855 + Carl D. Worth
10856 +
10857 + Copyright (C) 2001 University of Southern California
10858 +
10859 + This program is free software; you can redistribute it and/or
10860 + modify it under the terms of the GNU General Public License as
10861 + published by the Free Software Foundation; either version 2, or (at
10862 + your option) any later version.
10863 +
10864 + This program is distributed in the hope that it will be useful, but
10865 + WITHOUT ANY WARRANTY; without even the implied warranty of
10866 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10867 + General Public License for more details.
10868 +*/
10869 +
10870 +#ifndef PKG_DEST_LIST_H
10871 +#define PKG_DEST_LIST_H
10872 +
10873 +#include "pkg_dest.h"
10874 +
10875 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10876 +struct pkg_dest_list_elt
10877 +{
10878 + pkg_dest_list_elt_t *next;
10879 + pkg_dest_t *data;
10880 +};
10881 +
10882 +typedef struct pkg_dest_list pkg_dest_list_t;
10883 +struct pkg_dest_list
10884 +{
10885 + pkg_dest_list_elt_t pre_head;
10886 + pkg_dest_list_elt_t *head;
10887 + pkg_dest_list_elt_t *tail;
10888 +};
10889 +
10890 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10891 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10892 +
10893 +int pkg_dest_list_init(pkg_dest_list_t *list);
10894 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10895 +
10896 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10897 + const char *root_dir,const char* lists_dir);
10898 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10899 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10900 +
10901 +#endif
10902 +
10903 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_extract.c busybox-1.1.1-new/archival/libipkg/pkg_extract.c
10904 --- busybox-1.1.1-old/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10905 +++ busybox-1.1.1-new/archival/libipkg/pkg_extract.c 2006-03-30 00:39:48.000000000 +0200
10906 @@ -0,0 +1,224 @@
10907 +/* pkg_extract.c - the itsy package management system
10908 +
10909 + Carl D. Worth
10910 +
10911 + Copyright (C) 2001 University of Southern California
10912 +
10913 + This program is free software; you can redistribute it and/or
10914 + modify it under the terms of the GNU General Public License as
10915 + published by the Free Software Foundation; either version 2, or (at
10916 + your option) any later version.
10917 +
10918 + This program is distributed in the hope that it will be useful, but
10919 + WITHOUT ANY WARRANTY; without even the implied warranty of
10920 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10921 + General Public License for more details.
10922 +*/
10923 +
10924 +#include "ipkg.h"
10925 +#include <errno.h>
10926 +#include <fcntl.h>
10927 +#include <stdio.h>
10928 +
10929 +#include "pkg_extract.h"
10930 +
10931 +#include "libbb.h"
10932 +#include "file_util.h"
10933 +#include "sprintf_alloc.h"
10934 +#include "unarchive.h"
10935 +
10936 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10937 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10938 +#define IPKG_CONTROL_FILE "control"
10939 +
10940 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10941 +{
10942 + archive_handle_t *archive;
10943 + char *path;
10944 +
10945 + sprintf_alloc(&path, "%s/", dir);
10946 + archive = init_handle();
10947 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10948 + archive->filter = filter_accept_list;
10949 + archive->accept = llist_add_to(NULL, (char *)filename);
10950 + archive->buffer = path;
10951 + archive->action_data = data_extract_all_prefix;
10952 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10953 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10954 + close(archive->src_fd);
10955 + free(archive->accept);
10956 + free(archive);
10957 + free(path);
10958 +}
10959 +
10960 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10961 +{
10962 + unsigned int size = strlen(archive->file_header->name) + 2;
10963 +
10964 + if (archive->buffer == NULL) {
10965 + archive->buffer = xmalloc(size);
10966 + strcpy(archive->buffer, archive->file_header->name);
10967 + } else {
10968 + size += strlen(archive->buffer);
10969 + archive->buffer = xrealloc(archive->buffer, size);
10970 + strcat(archive->buffer, archive->file_header->name);
10971 + }
10972 + strcat(archive->buffer, "\n");
10973 + data_skip(archive);
10974 +}
10975 +
10976 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10977 +{
10978 + archive_handle_t *archive;
10979 + char *name;
10980 +
10981 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10982 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10983 + archive = init_handle();
10984 + archive->src_fd = bb_xopen(name, O_RDONLY);
10985 + archive->filter = filter_accept_list;
10986 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10987 + archive->action_data = data_extract_to_buffer;
10988 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10989 + close(archive->src_fd);
10990 + fputs(archive->buffer, stream);
10991 + free(archive->buffer);
10992 + free(archive->accept);
10993 + free(archive);
10994 + free(name);
10995 +
10996 + return 0;
10997 +}
10998 +
10999 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
11000 +{
11001 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11002 +}
11003 +
11004 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11005 +{
11006 + archive_handle_t *archive;
11007 + char *name;
11008 + char *path;
11009 +
11010 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11011 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11012 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11013 + archive = init_handle();
11014 + archive->src_fd = bb_xopen(name, O_RDONLY);
11015 + archive->filter = filter_accept_all;
11016 + archive->buffer = path;
11017 + archive->action_data = data_extract_all_prefix;
11018 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11019 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11020 + close(archive->src_fd);
11021 + free(archive);
11022 + free(path);
11023 + free(name);
11024 +
11025 + return 0;
11026 +}
11027 +
11028 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11029 +{
11030 + archive_handle_t *archive;
11031 + char *name;
11032 + char *path;
11033 +
11034 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11035 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11036 + sprintf_alloc(&path, "%s/", dir);
11037 + archive = init_handle();
11038 + archive->src_fd = bb_xopen(name, O_RDONLY);
11039 + archive->filter = filter_accept_all;
11040 + archive->buffer = path;
11041 + archive->action_data = data_extract_all_prefix;
11042 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11043 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11044 + close(archive->src_fd);
11045 + free(archive);
11046 + free(path);
11047 + free(name);
11048 +
11049 + return 0;
11050 +}
11051 +
11052 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11053 +{
11054 + int err=0;
11055 + char *line, *data_file;
11056 + FILE *file;
11057 + FILE *tmp;
11058 +
11059 + file = fopen(file_name, "w");
11060 + if (file == NULL) {
11061 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11062 + __FUNCTION__, file_name);
11063 + return EINVAL;
11064 + }
11065 +
11066 + tmp = tmpfile();
11067 + if (pkg->installed_files) {
11068 + str_list_elt_t *elt;
11069 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11070 + fprintf(file, "%s\n", elt->data);
11071 + }
11072 + } else {
11073 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11074 + if (err) {
11075 + fclose(file);
11076 + fclose(tmp);
11077 + return err;
11078 + }
11079 +
11080 + /* Fixup data file names by removing the initial '.' */
11081 + rewind(tmp);
11082 + while (1) {
11083 + line = file_read_line_alloc(tmp);
11084 + if (line == NULL) {
11085 + break;
11086 + }
11087 +
11088 + data_file = line;
11089 + if (*data_file == '.') {
11090 + data_file++;
11091 + }
11092 +
11093 + if (*data_file != '/') {
11094 + fputs("/", file);
11095 + }
11096 +
11097 + /* I have no idea why, but this is what dpkg does */
11098 + if (strcmp(data_file, "/\n") == 0) {
11099 + fputs("/.\n", file);
11100 + } else {
11101 + fputs(data_file, file);
11102 + }
11103 + }
11104 + }
11105 + fclose(tmp);
11106 + fclose(file);
11107 +
11108 + return err;
11109 +}
11110 +
11111 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11112 +{
11113 + archive_handle_t *archive;
11114 + char *name;
11115 +
11116 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11117 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11118 + archive = init_handle();
11119 + archive->src_fd = bb_xopen(name, O_RDONLY);
11120 + archive->filter = filter_accept_all;
11121 + archive->action_data = data_extract_file_name_to_buffer;
11122 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11123 + close(archive->src_fd);
11124 + fputs(archive->buffer, file);
11125 + free(archive->buffer);
11126 + free(archive);
11127 + free(name);
11128 +
11129 + return 0;
11130 +}
11131 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_extract.h busybox-1.1.1-new/archival/libipkg/pkg_extract.h
11132 --- busybox-1.1.1-old/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11133 +++ busybox-1.1.1-new/archival/libipkg/pkg_extract.h 2006-03-30 00:39:48.000000000 +0200
11134 @@ -0,0 +1,32 @@
11135 +/* pkg_extract.c - the itsy package management system
11136 +
11137 + Carl D. Worth
11138 +
11139 + Copyright (C) 2001 University of Southern California
11140 +
11141 + This program is free software; you can redistribute it and/or
11142 + modify it under the terms of the GNU General Public License as
11143 + published by the Free Software Foundation; either version 2, or (at
11144 + your option) any later version.
11145 +
11146 + This program is distributed in the hope that it will be useful, but
11147 + WITHOUT ANY WARRANTY; without even the implied warranty of
11148 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11149 + General Public License for more details.
11150 +*/
11151 +
11152 +#ifndef PKG_EXTRACT_H
11153 +#define PKG_EXTRACT_H
11154 +
11155 +#include "pkg.h"
11156 +
11157 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11158 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11159 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11160 + const char *dir,
11161 + const char *prefix);
11162 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11163 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11164 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11165 +
11166 +#endif
11167 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_hash.c busybox-1.1.1-new/archival/libipkg/pkg_hash.c
11168 --- busybox-1.1.1-old/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11169 +++ busybox-1.1.1-new/archival/libipkg/pkg_hash.c 2006-03-30 00:39:48.000000000 +0200
11170 @@ -0,0 +1,608 @@
11171 +/* ipkg_hash.c - the itsy package management system
11172 +
11173 + Steven M. Ayer
11174 +
11175 + Copyright (C) 2002 Compaq Computer Corporation
11176 +
11177 + This program is free software; you can redistribute it and/or
11178 + modify it under the terms of the GNU General Public License as
11179 + published by the Free Software Foundation; either version 2, or (at
11180 + your option) any later version.
11181 +
11182 + This program is distributed in the hope that it will be useful, but
11183 + WITHOUT ANY WARRANTY; without even the implied warranty of
11184 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11185 + General Public License for more details.
11186 +*/
11187 +
11188 +#include "ipkg.h"
11189 +#include <errno.h>
11190 +#include <ctype.h>
11191 +#include <stdlib.h>
11192 +#include <string.h>
11193 +
11194 +#include "hash_table.h"
11195 +#include "pkg.h"
11196 +#include "ipkg_message.h"
11197 +#include "pkg_vec.h"
11198 +#include "pkg_hash.h"
11199 +#include "pkg_parse.h"
11200 +#include "ipkg_utils.h"
11201 +
11202 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11203 +
11204 +/*
11205 + * this will talk to both feeds-lists files and installed status files
11206 + * example api:
11207 + *
11208 + * hash_table_t hash;
11209 + * pkg_hash_init(name, &hash, 1000);
11210 + * pkg_hash_add_from_file(<feed filename>);
11211 + *
11212 + * the query function is just there as a shell to prove to me that this
11213 + * sort of works, but isn't far from doing something useful
11214 + *
11215 + * -sma, 12/21/01
11216 + * modified: CDW 3 Jan. 2002
11217 + */
11218 +
11219 +
11220 +\f
11221 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11222 +{
11223 + return hash_table_init(name, hash, len);
11224 +}
11225 +
11226 +void pkg_hash_deinit(hash_table_t *hash)
11227 +{
11228 + hash_table_deinit(hash);
11229 +}
11230 +
11231 +
11232 +/* Find the default arch for a given package status file if none is given. */
11233 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11234 +{
11235 + nv_pair_list_elt_t *l;
11236 + char *def_arch = HOST_CPU_STR; /* Default arch */
11237 + int def_prio = 0; /* Other archs override this */
11238 +
11239 + l = conf->arch_list.head;
11240 +
11241 + while (l) {
11242 + nv_pair_t *nv = l->data;
11243 + int priority = strtol(nv->value, NULL, 0);
11244 +
11245 + /* Check if this arch has higher priority, and is valid */
11246 + if ((priority > def_prio) &&
11247 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11248 + /* Our new default */
11249 + def_prio = priority;
11250 + def_arch = nv->name;
11251 + }
11252 + l = l->next;
11253 + }
11254 +
11255 + return strdup(def_arch);
11256 +}
11257 +
11258 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11259 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11260 +{
11261 + hash_table_t *hash = &conf->pkg_hash;
11262 + char **raw;
11263 + char **raw_start;
11264 + pkg_t *pkg;
11265 +
11266 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11267 + if (!raw)
11268 + return -ENOMEM;
11269 +
11270 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11271 + pkg = pkg_new();
11272 + if (!pkg)
11273 + return -ENOMEM;
11274 +
11275 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11276 + if (!pkg->architecture) {
11277 + char *version_str = pkg_version_str_alloc(pkg);
11278 + pkg->architecture = pkg_get_default_arch(conf);
11279 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11280 + pkg->name, version_str, pkg->architecture);
11281 + free(version_str);
11282 + }
11283 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11284 + } else {
11285 + free(pkg);
11286 + }
11287 + }
11288 +
11289 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11290 + memory after read_raw_pkgs_from_file */
11291 + raw = raw_start;
11292 + while (*raw) {
11293 + free(*raw++);
11294 + }
11295 + free(raw_start);
11296 + return 0;
11297 +}
11298 +
11299 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11300 +{
11301 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11302 +}
11303 +
11304 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11305 +{
11306 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11307 + if (apkg)
11308 + return NULL;
11309 + return apkg->provided_by;
11310 +}
11311 +
11312 +
11313 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11314 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11315 +{
11316 + int i;
11317 + int nprovides = 0;
11318 + int nmatching = 0;
11319 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11320 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11321 + abstract_pkg_vec_t *provided_apkg_vec;
11322 + abstract_pkg_t **provided_apkgs;
11323 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11324 + pkg_t *latest_installed_parent = NULL;
11325 + pkg_t *latest_matching = NULL;
11326 + pkg_t *held_pkg = NULL;
11327 + pkg_t *good_pkg_by_name = NULL;
11328 +
11329 + if (matching_apkgs == NULL || providers == NULL ||
11330 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11331 + return NULL;
11332 +
11333 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11334 +
11335 + provided_apkg_vec = apkg->provided_by;
11336 + nprovides = provided_apkg_vec->len;
11337 + provided_apkgs = provided_apkg_vec->pkgs;
11338 + if (nprovides > 1)
11339 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11340 +
11341 + /* accumulate all the providers */
11342 + for (i = 0; i < nprovides; i++) {
11343 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11344 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11345 + abstract_pkg_vec_insert(providers, provider_apkg);
11346 + }
11347 + nprovides = providers->len;
11348 +
11349 + for (i = 0; i < nprovides; i++) {
11350 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11351 + abstract_pkg_t *replacement_apkg = NULL;
11352 + pkg_vec_t *vec;
11353 +
11354 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11355 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11356 + if (provider_apkg->replaced_by->len > 1) {
11357 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11358 + provider_apkg->name, replacement_apkg->name);
11359 + }
11360 + }
11361 +
11362 + if (replacement_apkg)
11363 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11364 + replacement_apkg->name, provider_apkg->name);
11365 +
11366 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11367 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11368 + continue;
11369 + else
11370 + provider_apkg = replacement_apkg;
11371 + }
11372 +
11373 + if (!(vec = provider_apkg->pkgs)) {
11374 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11375 + continue;
11376 + }
11377 +
11378 +
11379 + /* now check for supported architecture */
11380 + {
11381 + int max_count = 0;
11382 + int i;
11383 +
11384 + /* count packages matching max arch priority and keep track of last one */
11385 + for (i = 0; i < vec->len; i++) {
11386 + pkg_t *maybe = vec->pkgs[i];
11387 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d \n",
11388 + maybe->name, maybe->architecture, maybe->arch_priority);
11389 + if (maybe->arch_priority > 0) {
11390 + max_count++;
11391 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11392 + pkg_vec_insert(matching_pkgs, maybe);
11393 + }
11394 + }
11395 + }
11396 + }
11397 +
11398 + if (matching_pkgs->len > 1)
11399 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11400 + if (matching_apkgs->len > 1)
11401 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11402 +
11403 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11404 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11405 +
11406 + for (i = 0; i < matching_pkgs->len; i++) {
11407 + pkg_t *matching = matching_pkgs->pkgs[i];
11408 + if (constraint_fcn(matching, cdata)) { /* We found it */
11409 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s \n", matching->name) ;
11410 + good_pkg_by_name = matching;
11411 + }
11412 + }
11413 +
11414 +
11415 + for (i = 0; i < matching_pkgs->len; i++) {
11416 + pkg_t *matching = matching_pkgs->pkgs[i];
11417 + latest_matching = matching;
11418 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11419 + latest_installed_parent = matching;
11420 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11421 + if (held_pkg)
11422 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11423 + held_pkg->name, matching->name);
11424 + held_pkg = matching;
11425 + }
11426 + }
11427 +
11428 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11429 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11430 + apkg->name, matching_apkgs->len);
11431 + for (i = 0; i < matching_apkgs->len; i++) {
11432 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11433 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11434 + }
11435 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11436 + }
11437 +
11438 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11439 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11440 + __FUNCTION__, apkg->name, matching_pkgs->len);
11441 + for (i = 0; i < matching_pkgs->len; i++) {
11442 + pkg_t *matching = matching_pkgs->pkgs[i];
11443 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11444 + matching->name, matching->version, matching->architecture);
11445 + }
11446 + }
11447 +
11448 + nmatching = matching_apkgs->len;
11449 +
11450 + pkg_vec_free(matching_pkgs);
11451 + abstract_pkg_vec_free(matching_apkgs);
11452 + abstract_pkg_vec_free(providers);
11453 +
11454 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11455 + return good_pkg_by_name;
11456 + }
11457 + if (held_pkg) {
11458 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11459 + return held_pkg;
11460 + }
11461 + if (latest_installed_parent) {
11462 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11463 + return latest_installed_parent;
11464 + }
11465 + if (nmatching > 1) {
11466 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11467 + return NULL;
11468 + }
11469 + if (latest_matching) {
11470 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11471 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11472 + return latest_matching;
11473 + }
11474 + return NULL;
11475 +}
11476 +
11477 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11478 +{
11479 + const char *name = (const char *)cdata;
11480 + if (strcmp(pkg->name, name) == 0)
11481 + return 1;
11482 + else
11483 + return 0; /* Pigi */
11484 +}
11485 +
11486 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11487 +{
11488 + hash_table_t *hash = &conf->pkg_hash;
11489 + abstract_pkg_t *apkg = NULL;
11490 +
11491 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11492 + return NULL;
11493 +
11494 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11495 +}
11496 +
11497 +
11498 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11499 + const char *pkg_name,
11500 + const char * version)
11501 +{
11502 + pkg_vec_t * vec;
11503 + register int i;
11504 + char *version_str = NULL;
11505 +
11506 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11507 + return NULL;
11508 +
11509 + for(i = 0; i < vec->len; i++) {
11510 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11511 + if(!strcmp(version_str, version)) {
11512 + free(version_str);
11513 + break;
11514 + }
11515 + free(version_str);
11516 + }
11517 +
11518 + if(i == vec->len)
11519 + return NULL;
11520 +
11521 + return vec->pkgs[i];
11522 +}
11523 +
11524 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11525 + const char *pkg_name,
11526 + pkg_dest_t *dest)
11527 +{
11528 + pkg_vec_t * vec;
11529 + register int i;
11530 +
11531 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11532 + return NULL;
11533 + }
11534 +
11535 + for(i = 0; i < vec->len; i++)
11536 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11537 + return vec->pkgs[i];
11538 + }
11539 + return NULL;
11540 +}
11541 +
11542 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11543 + const char *pkg_name)
11544 +{
11545 + pkg_vec_t * vec;
11546 + register int i;
11547 +
11548 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11549 + return NULL;
11550 + }
11551 +
11552 + for(i = 0; i < vec->len; i++)
11553 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11554 + return vec->pkgs[i];
11555 + }
11556 +
11557 + return NULL;
11558 +}
11559 +
11560 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11561 +{
11562 + abstract_pkg_t * ab_pkg;
11563 +
11564 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11565 + return NULL;
11566 + }
11567 +
11568 + if (ab_pkg->pkgs) {
11569 + return ab_pkg->pkgs;
11570 + } else if (ab_pkg->provided_by) {
11571 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11572 + if (abpkg != NULL){
11573 + return abpkg->pkgs;
11574 + } else {
11575 + return ab_pkg->pkgs;
11576 + }
11577 + } else {
11578 + return NULL;
11579 + }
11580 +}
11581 +
11582 +static int pkg_compare_names(const void *p1, const void *p2)
11583 +{
11584 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11585 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11586 + if (pkg1->name == NULL)
11587 + return 1;
11588 + if (pkg2->name == NULL)
11589 + return -1;
11590 + return(strcmp(pkg1->name, pkg2->name));
11591 +}
11592 +
11593 +
11594 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11595 +{
11596 + int j;
11597 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11598 + pkg_vec_t *all = (pkg_vec_t *)data;
11599 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11600 + if (pkg_vec) {
11601 + for (j = 0; j < pkg_vec->len; j++) {
11602 + pkg_t *pkg = pkg_vec->pkgs[j];
11603 + pkg_vec_insert(all, pkg);
11604 + }
11605 + }
11606 +}
11607 +
11608 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11609 +{
11610 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11611 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11612 +}
11613 +
11614 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11615 +{
11616 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11617 + pkg_vec_t *all = (pkg_vec_t *)data;
11618 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11619 + int j;
11620 + if (pkg_vec) {
11621 + for (j = 0; j < pkg_vec->len; j++) {
11622 + pkg_t *pkg = pkg_vec->pkgs[j];
11623 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11624 + pkg_vec_insert(all, pkg);
11625 + }
11626 + }
11627 + }
11628 +}
11629 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11630 +{
11631 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11632 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11633 +}
11634 +
11635 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11636 +{
11637 + int i;
11638 + pkg_t *pkg;
11639 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11640 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11641 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11642 + fprintf(stdout, "%s\n", ab_pkg->name);
11643 + i = 0;
11644 + if (dependents != NULL)
11645 + while (dependents [i] != NULL)
11646 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11647 + dependents = ab_pkg->provided_by->pkgs;
11648 + i = 0;
11649 + if (dependents != NULL)
11650 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11651 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11652 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11653 + if (pkg) {
11654 + i = 0;
11655 + while (i < pkg->depends_count)
11656 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11657 + }
11658 +}
11659 +void pkg_hash_dump(hash_table_t *hash, void *data)
11660 +{
11661 +
11662 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11663 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11664 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11665 +}
11666 +
11667 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11668 +{
11669 + abstract_pkg_t * ab_pkg;
11670 +
11671 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11672 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11673 +
11674 + return ab_pkg;
11675 +}
11676 +
11677 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11678 +{
11679 + abstract_pkg_t * ab_pkg;
11680 + int arch_priority;
11681 +
11682 + if(!pkg)
11683 + return pkg;
11684 +
11685 + arch_priority = pkg->arch_priority;
11686 +
11687 + if (buildDepends(hash, pkg)<0){
11688 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11689 + return NULL;
11690 + }
11691 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11692 +
11693 + if (set_status) {
11694 + if (pkg->state_status == SS_INSTALLED) {
11695 + ab_pkg->state_status = SS_INSTALLED;
11696 + } else if (pkg->state_status == SS_UNPACKED) {
11697 + ab_pkg->state_status = SS_UNPACKED;
11698 + }
11699 + }
11700 +
11701 + if(!ab_pkg->pkgs)
11702 + ab_pkg->pkgs = pkg_vec_alloc();
11703 +
11704 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11705 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11706 + pkg->parent = ab_pkg;
11707 +
11708 + if (buildProvides(hash, ab_pkg, pkg)<0){
11709 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11710 + return NULL;
11711 + }
11712 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11713 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11714 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11715 + return NULL;
11716 + }
11717 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11718 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11719 + return NULL;
11720 + }
11721 +
11722 + buildDependedUponBy(pkg, ab_pkg);
11723 + return pkg;
11724 +}
11725 +
11726 +/*
11727 + * this will assume that we've already determined that
11728 + * the abstract pkg doesn't exist, 'cause we should know these things...
11729 + */
11730 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11731 +{
11732 + abstract_pkg_t * ab_pkg;
11733 +
11734 + ab_pkg = abstract_pkg_new();
11735 + if (ab_pkg == NULL) { return NULL; }
11736 +
11737 + ab_pkg->name = strdup(pkg_name);
11738 + hash_table_insert(hash, pkg_name, ab_pkg);
11739 +
11740 + return ab_pkg;
11741 +}
11742 +
11743 +
11744 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11745 +{
11746 + hash_table_t *file_hash = &conf->file_hash;
11747 +
11748 + return hash_table_get(file_hash, file_name);
11749 +}
11750 +
11751 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11752 +{
11753 + hash_table_t *file_hash = &conf->file_hash;
11754 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11755 + int file_name_len = strlen(file_name);
11756 +
11757 + if (file_name[file_name_len -1] == '/')
11758 + return 0;
11759 +
11760 + if (conf->offline_root) {
11761 + int len = strlen(conf->offline_root);
11762 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11763 + file_name += len;
11764 + }
11765 + }
11766 +
11767 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11768 + hash_table_insert(file_hash, file_name, owning_pkg);
11769 + if (old_owning_pkg) {
11770 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11771 + /* mark this package to have its filelist written */
11772 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11773 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11774 + }
11775 + return 0;
11776 +}
11777 +
11778 +
11779 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_hash.h busybox-1.1.1-new/archival/libipkg/pkg_hash.h
11780 --- busybox-1.1.1-old/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11781 +++ busybox-1.1.1-new/archival/libipkg/pkg_hash.h 2006-03-30 00:39:48.000000000 +0200
11782 @@ -0,0 +1,61 @@
11783 +/* pkg_hash.h - the itsy package management system
11784 +
11785 + Steven M. Ayer
11786 +
11787 + Copyright (C) 2002 Compaq Computer Corporation
11788 +
11789 + This program is free software; you can redistribute it and/or
11790 + modify it under the terms of the GNU General Public License as
11791 + published by the Free Software Foundation; either version 2, or (at
11792 + your option) any later version.
11793 +
11794 + This program is distributed in the hope that it will be useful, but
11795 + WITHOUT ANY WARRANTY; without even the implied warranty of
11796 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11797 + General Public License for more details.
11798 +*/
11799 +
11800 +#ifndef PKG_HASH_H
11801 +#define PKG_HASH_H
11802 +
11803 +#include "pkg.h"
11804 +#include "pkg_vec.h"
11805 +#include "hash_table.h"
11806 +
11807 +
11808 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11809 +void pkg_hash_deinit(hash_table_t *hash);
11810 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11811 +
11812 +void pkg_hash_dump(hash_table_t *hash, void *data);
11813 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11814 +
11815 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11816 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11817 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11818 +
11819 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11820 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11821 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11822 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11823 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11824 + const char *pkg_name,
11825 + const char * version);
11826 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11827 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11828 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11829 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11830 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11831 + const char *pkg_name);
11832 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11833 + const char *pkg_name,
11834 + pkg_dest_t *dest);
11835 +
11836 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11837 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11838 +
11839 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11840 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11841 +
11842 +#endif
11843 +
11844 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_parse.c busybox-1.1.1-new/archival/libipkg/pkg_parse.c
11845 --- busybox-1.1.1-old/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
11846 +++ busybox-1.1.1-new/archival/libipkg/pkg_parse.c 2006-03-30 00:39:48.000000000 +0200
11847 @@ -0,0 +1,366 @@
11848 +/* pkg_parse.c - the itsy package management system
11849 +
11850 + Steven M. Ayer
11851 +
11852 + Copyright (C) 2002 Compaq Computer Corporation
11853 +
11854 + This program is free software; you can redistribute it and/or
11855 + modify it under the terms of the GNU General Public License as
11856 + published by the Free Software Foundation; either version 2, or (at
11857 + your option) any later version.
11858 +
11859 + This program is distributed in the hope that it will be useful, but
11860 + WITHOUT ANY WARRANTY; without even the implied warranty of
11861 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11862 + General Public License for more details.
11863 +*/
11864 +
11865 +#include "ipkg.h"
11866 +#include <errno.h>
11867 +#include <ctype.h>
11868 +
11869 +#include "pkg.h"
11870 +#include "ipkg_utils.h"
11871 +#include "pkg_parse.h"
11872 +
11873 +int isGenericFieldType(char * type, char * line)
11874 +{
11875 + if(!strncmp(line, type, strlen(type)))
11876 + return 1;
11877 + return 0;
11878 +}
11879 +
11880 +char * parseGenericFieldType(char * type, char * raw)
11881 +{
11882 + char * field_value = raw + (strlen(type) + 1);
11883 + return trim_alloc(field_value);
11884 +}
11885 +
11886 +void parseStatus(pkg_t *pkg, char * raw)
11887 +{
11888 + char sw_str[64], sf_str[64], ss_str[64];
11889 +
11890 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11891 + pkg->state_want = pkg_state_want_from_str(sw_str);
11892 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11893 + pkg->state_status = pkg_state_status_from_str(ss_str);
11894 +}
11895 +
11896 +char ** parseDependsString(char * raw, int * depends_count)
11897 +{
11898 + char ** depends = NULL;
11899 + int line_count = 0;
11900 + char buff[2048], * dest;
11901 +
11902 + while(raw && *raw && !isspace(*raw)) {
11903 + raw++;
11904 + }
11905 +
11906 + if(line_is_blank(raw)){
11907 + *depends_count = line_count;
11908 + return NULL;
11909 + }
11910 + while(raw && *raw){
11911 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11912 +
11913 + while(isspace(*raw)) raw++;
11914 +
11915 + dest = buff;
11916 + while((*raw != ',') && *raw)
11917 + *dest++ = *raw++;
11918 +
11919 + *dest = '\0';
11920 + depends[line_count] = trim_alloc(buff);
11921 + if(depends[line_count] ==NULL)
11922 + return NULL;
11923 + line_count++;
11924 + if(*raw == ',')
11925 + raw++;
11926 + }
11927 + *depends_count = line_count;
11928 + return depends;
11929 +}
11930 +
11931 +void parseConffiles(pkg_t * pkg, char * raw)
11932 +{
11933 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11934 +
11935 + if(!strncmp(raw, "Conffiles:", 10))
11936 + raw += strlen("Conffiles:");
11937 +
11938 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11939 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11940 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11941 + while (*raw && isspace(*raw)) {
11942 + raw++;
11943 + }
11944 + raw += strlen(file_name);
11945 + while (*raw && isspace(*raw)) {
11946 + raw++;
11947 + }
11948 + raw += strlen(md5sum);
11949 + }
11950 +}
11951 +
11952 +int parseVersion(pkg_t *pkg, char *raw)
11953 +{
11954 + char *colon, *eepochcolon;
11955 +#ifdef USE_DEBVERSION
11956 + char *hyphen;
11957 +#endif
11958 + unsigned long epoch;
11959 +
11960 + if (!*raw) {
11961 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11962 + return EINVAL;
11963 + }
11964 +
11965 + if (strncmp(raw, "Version:", 8) == 0) {
11966 + raw += 8;
11967 + }
11968 + while (*raw && isspace(*raw)) {
11969 + raw++;
11970 + }
11971 +
11972 + colon= strchr(raw,':');
11973 + if (colon) {
11974 + epoch= strtoul(raw,&eepochcolon,10);
11975 + if (colon != eepochcolon) {
11976 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11977 + return EINVAL;
11978 + }
11979 + if (!*++colon) {
11980 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11981 + return EINVAL;
11982 + }
11983 + raw= colon;
11984 + pkg->epoch= epoch;
11985 + } else {
11986 + pkg->epoch= 0;
11987 + }
11988 +
11989 + pkg->revision = "";
11990 + pkg->familiar_revision = "";
11991 +
11992 + pkg->version= malloc(strlen(raw)+1);
11993 + if ( pkg->version == NULL ) {
11994 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11995 + return ENOMEM;
11996 + }
11997 + strcpy(pkg->version, raw);
11998 +
11999 +#ifdef USE_DEBVERSION
12000 + hyphen= strrchr(pkg->version,'-');
12001 +
12002 + if (hyphen) {
12003 + *hyphen++= 0;
12004 + if (strncmp("fam", hyphen, 3) == 0) {
12005 + pkg->familiar_revision=hyphen+3;
12006 + hyphen= strrchr(pkg->version,'-');
12007 + if (hyphen) {
12008 + *hyphen++= 0;
12009 + pkg->revision = hyphen;
12010 + }
12011 + } else {
12012 + pkg->revision = hyphen;
12013 + }
12014 + }
12015 +#endif
12016 +
12017 +/*
12018 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12019 + pkg->epoch,
12020 + pkg->version,
12021 + pkg->revision,
12022 + pkg->familiar_revision);
12023 +*/
12024 +
12025 + return 0;
12026 +}
12027 +
12028 +
12029 +/* This code is needed to insert in first position the keyword for the aligning bug */
12030 +
12031 +int alterProvidesLine(char *raw, char *temp)
12032 +{
12033 +
12034 +
12035 + if (!*raw) {
12036 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12037 + return -EINVAL;
12038 + }
12039 +
12040 + if ( temp == NULL ) {
12041 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12042 + return -ENOMEM;
12043 + }
12044 +
12045 + if (strncmp(raw, "Provides:", 9) == 0) {
12046 + raw += 9;
12047 + }
12048 + while (*raw && isspace(*raw)) {
12049 + raw++;
12050 + }
12051 +
12052 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12053 + while (*raw) {
12054 + strncat( temp, raw++, 1);
12055 + }
12056 + return 0;
12057 +
12058 +}
12059 +
12060 +/* Some random thoughts from Carl:
12061 +
12062 + This function could be considerably simplified if we just kept
12063 + an array of all the generic string-valued field names, and looped
12064 + through those looking for a match. Also, these fields could perhaps
12065 + be stored in the package as an array as well, (or, probably better,
12066 + as an nv_pair_list_t).
12067 +
12068 + Fields which require special parsing or storage, (such as Depends:
12069 + and Status:) could be handled as they are now.
12070 +*/
12071 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12072 + to a dependency list. And, since we already have
12073 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12074 + Enhances, perhaps we could generalize all of these and save some
12075 + code duplication.
12076 +*/
12077 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12078 +{
12079 + int reading_conffiles, reading_description;
12080 + int pkg_false_provides=1;
12081 + char ** lines;
12082 + char * provide=NULL;
12083 +
12084 + pkg->src = src;
12085 + pkg->dest = dest;
12086 +
12087 + reading_conffiles = reading_description = 0;
12088 +
12089 + for (lines = *raw; *lines; lines++) {
12090 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12091 + if(isGenericFieldType("Package:", *lines))
12092 + pkg->name = parseGenericFieldType("Package", *lines);
12093 + else if(isGenericFieldType("Architecture:", *lines))
12094 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12095 + else if(isGenericFieldType("Filename:", *lines))
12096 + pkg->filename = parseGenericFieldType("Filename", *lines);
12097 + else if(isGenericFieldType("Section:", *lines))
12098 + pkg->section = parseGenericFieldType("Section", *lines);
12099 + else if(isGenericFieldType("MD5sum:", *lines))
12100 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12101 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12102 + let's parse it either way */
12103 + else if(isGenericFieldType("MD5Sum:", *lines))
12104 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12105 + else if(isGenericFieldType("Size:", *lines))
12106 + pkg->size = parseGenericFieldType("Size", *lines);
12107 + else if(isGenericFieldType("Source:", *lines))
12108 + pkg->source = parseGenericFieldType("Source", *lines);
12109 + else if(isGenericFieldType("Installed-Size:", *lines))
12110 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12111 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12112 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12113 + pkg->installed_time = strtoul(time_str, NULL, 0);
12114 + } else if(isGenericFieldType("Priority:", *lines))
12115 + pkg->priority = parseGenericFieldType("Priority", *lines);
12116 + else if(isGenericFieldType("Essential:", *lines)) {
12117 + char *essential_value;
12118 + essential_value = parseGenericFieldType("Essential", *lines);
12119 + if (strcmp(essential_value, "yes") == 0) {
12120 + pkg->essential = 1;
12121 + }
12122 + free(essential_value);
12123 + }
12124 + else if(isGenericFieldType("Status", *lines))
12125 + parseStatus(pkg, *lines);
12126 + else if(isGenericFieldType("Version", *lines))
12127 + parseVersion(pkg, *lines);
12128 + else if(isGenericFieldType("Maintainer", *lines))
12129 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12130 + else if(isGenericFieldType("Conffiles", *lines)){
12131 + parseConffiles(pkg, *lines);
12132 + reading_conffiles = 1;
12133 + }
12134 + else if(isGenericFieldType("Description", *lines)) {
12135 + pkg->description = parseGenericFieldType("Description", *lines);
12136 + reading_conffiles = 0;
12137 + reading_description = 1;
12138 + }
12139 +
12140 + else if(isGenericFieldType("Provides", *lines)){
12141 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12142 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12143 + if ( alterProvidesLine(*lines,provide) ){
12144 + return EINVAL;
12145 + }
12146 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12147 +/* Let's try to hack a bit here.
12148 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12149 + in alot of other places. We will remove it before writing down the status database */
12150 + pkg_false_provides=0;
12151 + free(provide);
12152 + }
12153 +
12154 + else if(isGenericFieldType("Depends", *lines))
12155 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12156 + else if(isGenericFieldType("Pre-Depends", *lines))
12157 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12158 + else if(isGenericFieldType("Recommends", *lines))
12159 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12160 + else if(isGenericFieldType("Suggests", *lines))
12161 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12162 + /* Abhaya: support for conflicts */
12163 + else if(isGenericFieldType("Conflicts", *lines))
12164 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12165 + else if(isGenericFieldType("Replaces", *lines))
12166 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12167 + else if(line_is_blank(*lines)) {
12168 + lines++;
12169 + break;
12170 + }
12171 + else if(**lines == ' '){
12172 + if(reading_description) {
12173 + /* we already know it's not blank, so the rest of description */
12174 + pkg->description = realloc(pkg->description,
12175 + strlen(pkg->description)
12176 + + 1 + strlen(*lines) + 1);
12177 + strcat(pkg->description, "\n");
12178 + strcat(pkg->description, (*lines));
12179 + }
12180 + else if(reading_conffiles)
12181 + parseConffiles(pkg, *lines);
12182 + }
12183 + }
12184 + *raw = lines;
12185 +/* If the ipk has not a Provides line, we insert our false line */
12186 + if ( pkg_false_provides==1)
12187 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12188 +
12189 + if (pkg->name) {
12190 + return 0;
12191 + } else {
12192 + return EINVAL;
12193 + }
12194 +}
12195 +
12196 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12197 +{
12198 + char ** lines;
12199 +
12200 + for (lines = *raw; *lines; lines++) {
12201 + if(isGenericFieldType("Essential:", *lines)) {
12202 + char *essential_value;
12203 + essential_value = parseGenericFieldType("Essential", *lines);
12204 + if (strcmp(essential_value, "yes") == 0) {
12205 + pkg->essential = 1;
12206 + }
12207 + free(essential_value);
12208 + }
12209 + }
12210 + *raw = lines;
12211 +
12212 + return 0;
12213 +}
12214 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_parse.h busybox-1.1.1-new/archival/libipkg/pkg_parse.h
12215 --- busybox-1.1.1-old/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12216 +++ busybox-1.1.1-new/archival/libipkg/pkg_parse.h 2006-03-30 00:39:48.000000000 +0200
12217 @@ -0,0 +1,31 @@
12218 +/* pkg_parse.h - the itsy package management system
12219 +
12220 + Steven M. Ayer
12221 +
12222 + Copyright (C) 2002 Compaq Computer Corporation
12223 +
12224 + This program is free software; you can redistribute it and/or
12225 + modify it under the terms of the GNU General Public License as
12226 + published by the Free Software Foundation; either version 2, or (at
12227 + your option) any later version.
12228 +
12229 + This program is distributed in the hope that it will be useful, but
12230 + WITHOUT ANY WARRANTY; without even the implied warranty of
12231 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12232 + General Public License for more details.
12233 +*/
12234 +
12235 +#ifndef PKG_PARSE_H
12236 +#define PKG_PARSE_H
12237 +
12238 +int isGenericFieldType(char * type, char * line);
12239 +char * parseGenericFieldType(char * type, char * raw);
12240 +void parseStatus(pkg_t *pkg, char * raw);
12241 +int parseVersion(pkg_t *pkg, char *raw);
12242 +char ** parseDependsString(char * raw, int * depends_count);
12243 +int parseVersion(pkg_t *pkg, char *raw);
12244 +void parseConffiles(pkg_t * pkg, char * raw);
12245 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12246 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12247 +
12248 +#endif
12249 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src.c busybox-1.1.1-new/archival/libipkg/pkg_src.c
12250 --- busybox-1.1.1-old/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12251 +++ busybox-1.1.1-new/archival/libipkg/pkg_src.c 2006-03-30 00:39:48.000000000 +0200
12252 @@ -0,0 +1,43 @@
12253 +/* pkg_src.c - the itsy package management system
12254 +
12255 + Carl D. Worth
12256 +
12257 + Copyright (C) 2001 University of Southern California
12258 +
12259 + This program is free software; you can redistribute it and/or
12260 + modify it under the terms of the GNU General Public License as
12261 + published by the Free Software Foundation; either version 2, or (at
12262 + your option) any later version.
12263 +
12264 + This program is distributed in the hope that it will be useful, but
12265 + WITHOUT ANY WARRANTY; without even the implied warranty of
12266 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12267 + General Public License for more details.
12268 +*/
12269 +
12270 +#include "ipkg.h"
12271 +
12272 +#include "pkg_src.h"
12273 +#include "str_util.h"
12274 +
12275 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12276 +{
12277 + src->gzip = gzip;
12278 + src->name = str_dup_safe (name);
12279 + src->value = str_dup_safe (base_url);
12280 + if (extra_data)
12281 + src->extra_data = str_dup_safe (extra_data);
12282 + else
12283 + src->extra_data = NULL;
12284 + return 0;
12285 +}
12286 +
12287 +void pkg_src_deinit(pkg_src_t *src)
12288 +{
12289 + free (src->name);
12290 + free (src->value);
12291 + if (src->extra_data)
12292 + free (src->extra_data);
12293 +}
12294 +
12295 +
12296 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src.h busybox-1.1.1-new/archival/libipkg/pkg_src.h
12297 --- busybox-1.1.1-old/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12298 +++ busybox-1.1.1-new/archival/libipkg/pkg_src.h 2006-03-30 00:39:48.000000000 +0200
12299 @@ -0,0 +1,34 @@
12300 +/* pkg_src.h - the itsy package management system
12301 +
12302 + Carl D. Worth
12303 +
12304 + Copyright (C) 2001 University of Southern California
12305 +
12306 + This program is free software; you can redistribute it and/or
12307 + modify it under the terms of the GNU General Public License as
12308 + published by the Free Software Foundation; either version 2, or (at
12309 + your option) any later version.
12310 +
12311 + This program is distributed in the hope that it will be useful, but
12312 + WITHOUT ANY WARRANTY; without even the implied warranty of
12313 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12314 + General Public License for more details.
12315 +*/
12316 +
12317 +#ifndef PKG_SRC_H
12318 +#define PKG_SRC_H
12319 +
12320 +#include "nv_pair.h"
12321 +
12322 +typedef struct
12323 +{
12324 + char *name;
12325 + char *value;
12326 + char *extra_data;
12327 + int gzip;
12328 +} pkg_src_t;
12329 +
12330 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12331 +void pkg_src_deinit(pkg_src_t *src);
12332 +
12333 +#endif
12334 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src_list.c busybox-1.1.1-new/archival/libipkg/pkg_src_list.c
12335 --- busybox-1.1.1-old/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12336 +++ busybox-1.1.1-new/archival/libipkg/pkg_src_list.c 2006-03-30 00:39:48.000000000 +0200
12337 @@ -0,0 +1,75 @@
12338 +/* pkg_src_list.c - the itsy package management system
12339 +
12340 + Carl D. Worth
12341 +
12342 + Copyright (C) 2001 University of Southern California
12343 +
12344 + This program is free software; you can redistribute it and/or
12345 + modify it under the terms of the GNU General Public License as
12346 + published by the Free Software Foundation; either version 2, or (at
12347 + your option) any later version.
12348 +
12349 + This program is distributed in the hope that it will be useful, but
12350 + WITHOUT ANY WARRANTY; without even the implied warranty of
12351 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12352 + General Public License for more details.
12353 +*/
12354 +
12355 +#include "ipkg.h"
12356 +
12357 +#include "pkg_src_list.h"
12358 +#include "void_list.h"
12359 +
12360 +int pkg_src_list_init(pkg_src_list_t *list)
12361 +{
12362 + return void_list_init((void_list_t *) list);
12363 +}
12364 +
12365 +void pkg_src_list_deinit(pkg_src_list_t *list)
12366 +{
12367 + pkg_src_list_elt_t *iter;
12368 + pkg_src_t *pkg_src;
12369 +
12370 + for (iter = list->head; iter; iter = iter->next) {
12371 + pkg_src = iter->data;
12372 + pkg_src_deinit(pkg_src);
12373 +
12374 + /* malloced in pkg_src_list_append */
12375 + free(pkg_src);
12376 + iter->data = NULL;
12377 + }
12378 + void_list_deinit((void_list_t *) list);
12379 +}
12380 +
12381 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12382 + const char *name, const char *base_url, const char *extra_data,
12383 + int gzip)
12384 +{
12385 + int err;
12386 +
12387 + /* freed in pkg_src_list_deinit */
12388 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12389 +
12390 + if (pkg_src == NULL) {
12391 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12392 + return NULL;
12393 + }
12394 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12395 +
12396 + err = void_list_append((void_list_t *) list, pkg_src);
12397 + if (err) {
12398 + return NULL;
12399 + }
12400 +
12401 + return pkg_src;
12402 +}
12403 +
12404 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12405 +{
12406 + return void_list_push((void_list_t *) list, data);
12407 +}
12408 +
12409 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12410 +{
12411 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12412 +}
12413 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src_list.h busybox-1.1.1-new/archival/libipkg/pkg_src_list.h
12414 --- busybox-1.1.1-old/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12415 +++ busybox-1.1.1-new/archival/libipkg/pkg_src_list.h 2006-03-30 00:39:48.000000000 +0200
12416 @@ -0,0 +1,57 @@
12417 +/* pkg_src_list.h - the itsy package management system
12418 +
12419 + Carl D. Worth
12420 +
12421 + Copyright (C) 2001 University of Southern California
12422 +
12423 + This program is free software; you can redistribute it and/or
12424 + modify it under the terms of the GNU General Public License as
12425 + published by the Free Software Foundation; either version 2, or (at
12426 + your option) any later version.
12427 +
12428 + This program is distributed in the hope that it will be useful, but
12429 + WITHOUT ANY WARRANTY; without even the implied warranty of
12430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12431 + General Public License for more details.
12432 +*/
12433 +
12434 +#ifndef PKG_SRC_LIST_H
12435 +#define PKG_SRC_LIST_H
12436 +
12437 +#include "pkg_src.h"
12438 +
12439 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12440 +struct pkg_src_list_elt
12441 +{
12442 + pkg_src_list_elt_t *next;
12443 + pkg_src_t *data;
12444 +};
12445 +
12446 +typedef struct pkg_src_list pkg_src_list_t;
12447 +struct pkg_src_list
12448 +{
12449 + pkg_src_list_elt_t pre_head;
12450 + pkg_src_list_elt_t *head;
12451 + pkg_src_list_elt_t *tail;
12452 +};
12453 +
12454 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12455 +{
12456 + if (list->head == NULL)
12457 + return 1;
12458 + else
12459 + return 0;
12460 +}
12461 +
12462 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12463 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12464 +
12465 +int pkg_src_list_init(pkg_src_list_t *list);
12466 +void pkg_src_list_deinit(pkg_src_list_t *list);
12467 +
12468 +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);
12469 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12470 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12471 +
12472 +#endif
12473 +
12474 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_vec.c busybox-1.1.1-new/archival/libipkg/pkg_vec.c
12475 --- busybox-1.1.1-old/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12476 +++ busybox-1.1.1-new/archival/libipkg/pkg_vec.c 2006-03-30 00:39:48.000000000 +0200
12477 @@ -0,0 +1,226 @@
12478 +/* pkg_vec.c - the itsy package management system
12479 +
12480 + Steven M. Ayer
12481 +
12482 + Copyright (C) 2002 Compaq Computer Corporation
12483 +
12484 + This program is free software; you can redistribute it and/or
12485 + modify it under the terms of the GNU General Public License as
12486 + published by the Free Software Foundation; either version 2, or (at
12487 + your option) any later version.
12488 +
12489 + This program is distributed in the hope that it will be useful, but
12490 + WITHOUT ANY WARRANTY; without even the implied warranty of
12491 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12492 + General Public License for more details.
12493 +*/
12494 +
12495 +#include <stdlib.h>
12496 +#include <fnmatch.h>
12497 +#include "xregex.h"
12498 +#include "ipkg.h"
12499 +#include "pkg.h"
12500 +
12501 +pkg_vec_t * pkg_vec_alloc(void)
12502 +{
12503 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12504 + if (!vec) {
12505 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12506 + return NULL;
12507 + }
12508 + vec->pkgs = NULL;
12509 + vec->len = 0;
12510 +
12511 + return vec;
12512 +}
12513 +
12514 +void pkg_vec_free(pkg_vec_t *vec)
12515 +{
12516 + free(vec->pkgs);
12517 + free(vec);
12518 +}
12519 +
12520 +/*
12521 + * assumption: all names in a vector are identical
12522 + * assumption: all version strings are trimmed,
12523 + * so identical versions have identical version strings,
12524 + * implying identical packages; let's marry these
12525 + */
12526 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12527 +{
12528 + int i;
12529 + int found = 0;
12530 +
12531 + /* look for a duplicate pkg by name, version, and architecture */
12532 + for (i = 0; i < vec->len; i++)
12533 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12534 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12535 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12536 + found = 1;
12537 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12538 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12539 + break;
12540 + }
12541 +
12542 + /* we didn't find one, add it */
12543 + if (!found){
12544 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12545 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12546 +
12547 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12548 + vec->pkgs[vec->len] = pkg;
12549 + vec->len++;
12550 + return pkg;
12551 + }
12552 + /* update the one that we have */
12553 + else {
12554 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12555 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12556 + if (set_status) {
12557 + /* this is from the status file, so need to merge with existing database */
12558 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12559 + pkg_merge(vec->pkgs[i], pkg, set_status);
12560 + /* XXX: CLEANUP: It's not so polite to free something here
12561 + that was passed in from above. */
12562 + pkg_deinit(pkg);
12563 + free(pkg);
12564 + } else {
12565 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12566 + /* just overwrite the old one */
12567 + pkg_deinit(vec->pkgs[i]);
12568 + free(vec->pkgs[i]);
12569 + vec->pkgs[i] = pkg;
12570 + }
12571 + return vec->pkgs[i];
12572 + }
12573 +}
12574 +
12575 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12576 +{
12577 + int i;
12578 + int found = 0;
12579 +
12580 + /* look for a duplicate pkg by name, version, and architecture */
12581 + for (i = 0; i < vec->len; i++)
12582 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12583 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12584 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12585 + found = 1;
12586 + break;
12587 + }
12588 +
12589 + /* we didn't find one, add it */
12590 + if(!found){
12591 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12592 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12593 + vec->len++;
12594 + }
12595 +}
12596 +
12597 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12598 +{
12599 + int i;
12600 + for (i = 0; i < vec->len; i++)
12601 + if (vec->pkgs[i] == apkg)
12602 + return 1;
12603 + return 0;
12604 +}
12605 +
12606 +typedef int (*compare_fcn_t)(const void *, const void *);
12607 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12608 +{
12609 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12610 +}
12611 +
12612 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12613 +{
12614 + int npkgs = vec->len;
12615 + int i;
12616 + for (i = 0; i < npkgs; i++) {
12617 + pkg_t *pkg = vec->pkgs[i];
12618 + pkg->state_flag &= ~SF_MARKED;
12619 + }
12620 + return 0;
12621 +}
12622 +
12623 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12624 +{
12625 + int matching_count = 0;
12626 + pkg_t **pkgs = vec->pkgs;
12627 + int npkgs = vec->len;
12628 + int i;
12629 + for (i = 0; i < npkgs; i++) {
12630 + pkg_t *pkg = pkgs[i];
12631 + if (fnmatch(pattern, pkg->name, 0)==0) {
12632 + pkg->state_flag |= SF_MARKED;
12633 + matching_count++;
12634 + }
12635 + }
12636 + return matching_count;
12637 +}
12638 +
12639 +
12640 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12641 +{
12642 + abstract_pkg_vec_t * vec ;
12643 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12644 + if (!vec) {
12645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12646 + return NULL;
12647 + }
12648 + vec->pkgs = NULL;
12649 + vec->len = 0;
12650 +
12651 + return vec;
12652 +}
12653 +
12654 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12655 +{
12656 + free(vec->pkgs);
12657 + free(vec);
12658 +}
12659 +
12660 +/*
12661 + * assumption: all names in a vector are unique
12662 + */
12663 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12664 +{
12665 + int i;
12666 +
12667 + /* look for a duplicate pkg by name */
12668 + for(i = 0; i < vec->len; i++)
12669 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12670 + break;
12671 +
12672 + /* we didn't find one, add it */
12673 + if(i == vec->len){
12674 + vec->pkgs =
12675 + (abstract_pkg_t **)
12676 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12677 + vec->pkgs[vec->len] = pkg;
12678 + vec->len++;
12679 + }
12680 +}
12681 +
12682 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12683 +{
12684 + if (vec->len > i)
12685 + return vec->pkgs[i];
12686 + else
12687 + return NULL;
12688 +}
12689 +
12690 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12691 +{
12692 + int i;
12693 + for (i = 0; i < vec->len; i++)
12694 + if (vec->pkgs[i] == apkg)
12695 + return 1;
12696 + return 0;
12697 +}
12698 +
12699 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12700 +{
12701 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12702 +}
12703 +
12704 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_vec.h busybox-1.1.1-new/archival/libipkg/pkg_vec.h
12705 --- busybox-1.1.1-old/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12706 +++ busybox-1.1.1-new/archival/libipkg/pkg_vec.h 2006-03-30 00:39:48.000000000 +0200
12707 @@ -0,0 +1,62 @@
12708 +/* pkg_vec.h - the itsy package management system
12709 +
12710 + Steven M. Ayer
12711 +
12712 + Copyright (C) 2002 Compaq Computer Corporation
12713 +
12714 + This program is free software; you can redistribute it and/or
12715 + modify it under the terms of the GNU General Public License as
12716 + published by the Free Software Foundation; either version 2, or (at
12717 + your option) any later version.
12718 +
12719 + This program is distributed in the hope that it will be useful, but
12720 + WITHOUT ANY WARRANTY; without even the implied warranty of
12721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12722 + General Public License for more details.
12723 +*/
12724 +
12725 +#ifndef PKG_VEC_H
12726 +#define PKG_VEC_H
12727 +
12728 +typedef struct pkg pkg_t;
12729 +typedef struct abstract_pkg abstract_pkg_t;
12730 +
12731 +struct pkg_vec
12732 +{
12733 + pkg_t **pkgs;
12734 + int len;
12735 +};
12736 +typedef struct pkg_vec pkg_vec_t;
12737 +
12738 +struct abstract_pkg_vec
12739 +{
12740 + abstract_pkg_t **pkgs;
12741 + int len;
12742 +};
12743 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12744 +
12745 +
12746 +pkg_vec_t * pkg_vec_alloc(void);
12747 +void pkg_vec_free(pkg_vec_t *vec);
12748 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12749 +
12750 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12751 +/* pkg_vec_insert_merge: might munge pkg.
12752 +* returns the pkg that is in the pkg graph */
12753 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12754 +/* this one never munges pkg */
12755 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12756 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12757 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12758 +
12759 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12760 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12761 +
12762 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12763 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12764 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12765 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12766 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12767 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12768 +#endif
12769 +
12770 diff -ruN busybox-1.1.1-old/archival/libipkg/sprintf_alloc.h busybox-1.1.1-new/archival/libipkg/sprintf_alloc.h
12771 --- busybox-1.1.1-old/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12772 +++ busybox-1.1.1-new/archival/libipkg/sprintf_alloc.h 2006-03-31 02:19:07.000000000 +0200
12773 @@ -0,0 +1,25 @@
12774 +/* sprintf_alloca.c -- like sprintf with memory allocation
12775 +
12776 + Carl D. Worth
12777 +
12778 + Copyright (C) 2001 University of Southern California
12779 +
12780 + This program is free software; you can redistribute it and/or modify
12781 + it under the terms of the GNU General Public License as published by
12782 + the Free Software Foundation; either version 2, or (at your option)
12783 + any later version.
12784 +
12785 + This program is distributed in the hope that it will be useful,
12786 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12787 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12788 + GNU General Public License for more details.
12789 +*/
12790 +
12791 +#ifndef SPRINTF_ALLOC_H
12792 +#define SPRINTF_ALLOC_H
12793 +
12794 +#include "libbb.h"
12795 +
12796 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
12797 +
12798 +#endif
12799 diff -ruN busybox-1.1.1-old/archival/libipkg/str_list.c busybox-1.1.1-new/archival/libipkg/str_list.c
12800 --- busybox-1.1.1-old/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12801 +++ busybox-1.1.1-new/archival/libipkg/str_list.c 2006-03-30 00:39:48.000000000 +0200
12802 @@ -0,0 +1,76 @@
12803 +/* str_list.c - the itsy package management system
12804 +
12805 + Carl D. Worth
12806 +
12807 + Copyright (C) 2001 University of Southern California
12808 +
12809 + This program is free software; you can redistribute it and/or
12810 + modify it under the terms of the GNU General Public License as
12811 + published by the Free Software Foundation; either version 2, or (at
12812 + your option) any later version.
12813 +
12814 + This program is distributed in the hope that it will be useful, but
12815 + WITHOUT ANY WARRANTY; without even the implied warranty of
12816 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12817 + General Public License for more details.
12818 +*/
12819 +
12820 +#include "ipkg.h"
12821 +
12822 +#include "str_list.h"
12823 +
12824 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12825 +{
12826 + return void_list_elt_init((void_list_elt_t *) elt, data);
12827 +}
12828 +
12829 +void str_list_elt_deinit(str_list_elt_t *elt)
12830 +{
12831 + void_list_elt_deinit((void_list_elt_t *) elt);
12832 +}
12833 +
12834 +str_list_t *str_list_alloc()
12835 +{
12836 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12837 + if (list)
12838 + str_list_init(list);
12839 + return list;
12840 +}
12841 +
12842 +int str_list_init(str_list_t *list)
12843 +{
12844 + return void_list_init((void_list_t *) list);
12845 +}
12846 +
12847 +void str_list_deinit(str_list_t *list)
12848 +{
12849 + void_list_deinit((void_list_t *) list);
12850 +}
12851 +
12852 +int str_list_append(str_list_t *list, char *data)
12853 +{
12854 + return void_list_append((void_list_t *) list, data);
12855 +}
12856 +
12857 +int str_list_push(str_list_t *list, char *data)
12858 +{
12859 + return void_list_push((void_list_t *) list, data);
12860 +}
12861 +
12862 +str_list_elt_t *str_list_pop(str_list_t *list)
12863 +{
12864 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12865 +}
12866 +
12867 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12868 +{
12869 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12870 + (void_list_elt_t **) iter);
12871 +}
12872 +
12873 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12874 +{
12875 + return (char *)void_list_remove_elt((void_list_t *) list,
12876 + (void *)target_str,
12877 + (void_list_cmp_t)strcmp);
12878 +}
12879 diff -ruN busybox-1.1.1-old/archival/libipkg/str_list.h busybox-1.1.1-new/archival/libipkg/str_list.h
12880 --- busybox-1.1.1-old/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
12881 +++ busybox-1.1.1-new/archival/libipkg/str_list.h 2006-03-30 00:39:48.000000000 +0200
12882 @@ -0,0 +1,51 @@
12883 +/* str_list.h - the itsy package management system
12884 +
12885 + Carl D. Worth
12886 +
12887 + Copyright (C) 2001 University of Southern California
12888 +
12889 + This program is free software; you can redistribute it and/or
12890 + modify it under the terms of the GNU General Public License as
12891 + published by the Free Software Foundation; either version 2, or (at
12892 + your option) any later version.
12893 +
12894 + This program is distributed in the hope that it will be useful, but
12895 + WITHOUT ANY WARRANTY; without even the implied warranty of
12896 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12897 + General Public License for more details.
12898 +*/
12899 +
12900 +#ifndef STR_LIST_H
12901 +#define STR_LIST_H
12902 +
12903 +#include "void_list.h"
12904 +
12905 +typedef struct str_list_elt str_list_elt_t;
12906 +struct str_list_elt
12907 +{
12908 + str_list_elt_t *next;
12909 + char *data;
12910 +};
12911 +
12912 +typedef struct xstr_list str_list_t;
12913 +struct xstr_list
12914 +{
12915 + str_list_elt_t pre_head;
12916 + str_list_elt_t *head;
12917 + str_list_elt_t *tail;
12918 +};
12919 +
12920 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12921 +void str_list_elt_deinit(str_list_elt_t *elt);
12922 +
12923 +str_list_t *str_list_alloc(void);
12924 +int str_list_init(str_list_t *list);
12925 +void str_list_deinit(str_list_t *list);
12926 +
12927 +int str_list_append(str_list_t *list, char *data);
12928 +int str_list_push(str_list_t *list, char *data);
12929 +str_list_elt_t *str_list_pop(str_list_t *list);
12930 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12931 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12932 +
12933 +#endif
12934 diff -ruN busybox-1.1.1-old/archival/libipkg/str_util.c busybox-1.1.1-new/archival/libipkg/str_util.c
12935 --- busybox-1.1.1-old/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
12936 +++ busybox-1.1.1-new/archival/libipkg/str_util.c 2006-03-30 00:39:48.000000000 +0200
12937 @@ -0,0 +1,73 @@
12938 +/* str_utils.c - the itsy package management system
12939 +
12940 + Carl D. Worth
12941 +
12942 + Copyright (C) 2001 University of Southern California
12943 +
12944 + This program is free software; you can redistribute it and/or
12945 + modify it under the terms of the GNU General Public License as
12946 + published by the Free Software Foundation; either version 2, or (at
12947 + your option) any later version.
12948 +
12949 + This program is distributed in the hope that it will be useful, but
12950 + WITHOUT ANY WARRANTY; without even the implied warranty of
12951 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12952 + General Public License for more details.
12953 +*/
12954 +
12955 +#include "ipkg.h"
12956 +
12957 +int str_starts_with(const char *str, const char *prefix)
12958 +{
12959 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12960 +}
12961 +
12962 +int str_ends_with(const char *str, const char *suffix)
12963 +{
12964 + int suffix_len;
12965 + int str_len;
12966 +
12967 + str_len = strlen(str);
12968 + suffix_len = strlen(suffix);
12969 +
12970 + if (str_len < suffix_len) {
12971 + return 0;
12972 + }
12973 +
12974 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12975 +}
12976 +
12977 +int str_chomp(char *str)
12978 +{
12979 + if (str[strlen(str) - 1] == '\n') {
12980 + str[strlen(str) - 1] = '\0';
12981 + return 1;
12982 + }
12983 + return 0;
12984 +}
12985 +
12986 +int str_tolower(char *str)
12987 +{
12988 + while (*str) {
12989 + *str = tolower(*str);
12990 + str++;
12991 + }
12992 +
12993 + return 0;
12994 +}
12995 +
12996 +int str_toupper(char *str)
12997 +{
12998 + while (*str) {
12999 + *str = toupper(*str);
13000 + str++;
13001 + }
13002 +
13003 + return 0;
13004 +}
13005 +
13006 +char *str_dup_safe(const char *str)
13007 +{
13008 + return str ? strdup(str) : NULL;
13009 +}
13010 +
13011 diff -ruN busybox-1.1.1-old/archival/libipkg/str_util.h busybox-1.1.1-new/archival/libipkg/str_util.h
13012 --- busybox-1.1.1-old/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13013 +++ busybox-1.1.1-new/archival/libipkg/str_util.h 2006-03-30 00:39:48.000000000 +0200
13014 @@ -0,0 +1,28 @@
13015 +/* str_utils.h - the itsy package management system
13016 +
13017 + Carl D. Worth
13018 +
13019 + Copyright (C) 2001 University of Southern California
13020 +
13021 + This program is free software; you can redistribute it and/or
13022 + modify it under the terms of the GNU General Public License as
13023 + published by the Free Software Foundation; either version 2, or (at
13024 + your option) any later version.
13025 +
13026 + This program is distributed in the hope that it will be useful, but
13027 + WITHOUT ANY WARRANTY; without even the implied warranty of
13028 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13029 + General Public License for more details.
13030 +*/
13031 +
13032 +#ifndef STR_UTILS_H
13033 +#define STR_UTILS_H
13034 +
13035 +int str_starts_with(const char *str, const char *prefix);
13036 +int str_ends_with(const char *str, const char *suffix);
13037 +int str_chomp(char *str);
13038 +int str_tolower(char *str);
13039 +int str_toupper(char *str);
13040 +char *str_dup_safe(const char *str);
13041 +
13042 +#endif
13043 diff -ruN busybox-1.1.1-old/archival/libipkg/user.c busybox-1.1.1-new/archival/libipkg/user.c
13044 --- busybox-1.1.1-old/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13045 +++ busybox-1.1.1-new/archival/libipkg/user.c 2006-03-30 00:39:48.000000000 +0200
13046 @@ -0,0 +1,58 @@
13047 +/* user.c - the itsy package management system
13048 +
13049 + Jamey Hicks
13050 +
13051 + Copyright (C) 2002 Hewlett Packard Company
13052 + Copyright (C) 2001 University of Southern California
13053 +
13054 + This program is free software; you can redistribute it and/or
13055 + modify it under the terms of the GNU General Public License as
13056 + published by the Free Software Foundation; either version 2, or (at
13057 + your option) any later version.
13058 +
13059 + This program is distributed in the hope that it will be useful, but
13060 + WITHOUT ANY WARRANTY; without even the implied warranty of
13061 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13062 + General Public License for more details.
13063 +*/
13064 +
13065 +#include <stdio.h>
13066 +#include <stdarg.h>
13067 +#include "file_util.h"
13068 +#include "str_util.h"
13069 +#ifdef IPKG_LIB
13070 +#include "libipkg.h"
13071 +#endif
13072 +
13073 +
13074 +#ifdef IPKG_LIB
13075 +static char *question = NULL;
13076 +static int question_len = 255;
13077 +#endif
13078 +char *get_user_response(const char *format, ...)
13079 +{
13080 + int len = question_len;
13081 + va_list ap;
13082 + char *response;
13083 + va_start(ap, format);
13084 +
13085 +#ifndef IPKG_LIB
13086 + vprintf(format, ap);
13087 + do {
13088 + response = file_read_line_alloc(stdin);
13089 + } while (response == NULL);
13090 +#else
13091 + do {
13092 + if (question == NULL || len > question_len) {
13093 + question = realloc(question, len + 1);
13094 + question_len = len;
13095 + }
13096 + len = vsnprintf(question,question_len,format,ap);
13097 + } while (len > question_len);
13098 + response = strdup(ipkg_cb_response(question));
13099 +#endif
13100 + str_chomp(response);
13101 + str_tolower(response);
13102 +
13103 + return response;
13104 +}
13105 diff -ruN busybox-1.1.1-old/archival/libipkg/user.h busybox-1.1.1-new/archival/libipkg/user.h
13106 --- busybox-1.1.1-old/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13107 +++ busybox-1.1.1-new/archival/libipkg/user.h 2006-03-30 00:39:48.000000000 +0200
13108 @@ -0,0 +1,23 @@
13109 +/* user.c - the itsy package management system
13110 +
13111 + Jamey Hicks
13112 +
13113 + Copyright (C) 2002 Hewlett Packard Company
13114 + Copyright (C) 2001 University of Southern California
13115 +
13116 + This program is free software; you can redistribute it and/or
13117 + modify it under the terms of the GNU General Public License as
13118 + published by the Free Software Foundation; either version 2, or (at
13119 + your option) any later version.
13120 +
13121 + This program is distributed in the hope that it will be useful, but
13122 + WITHOUT ANY WARRANTY; without even the implied warranty of
13123 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13124 + General Public License for more details.
13125 +*/
13126 +
13127 +#include <stdio.h>
13128 +#include <stdarg.h>
13129 +
13130 +char *get_user_response(const char *format, ...);
13131 +
13132 diff -ruN busybox-1.1.1-old/archival/libipkg/void_list.c busybox-1.1.1-new/archival/libipkg/void_list.c
13133 --- busybox-1.1.1-old/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13134 +++ busybox-1.1.1-new/archival/libipkg/void_list.c 2006-03-30 00:39:48.000000000 +0200
13135 @@ -0,0 +1,194 @@
13136 +/* void_list.c - the itsy package management system
13137 +
13138 + Carl D. Worth
13139 +
13140 + Copyright (C) 2001 University of Southern California
13141 +
13142 + This program is free software; you can redistribute it and/or
13143 + modify it under the terms of the GNU General Public License as
13144 + published by the Free Software Foundation; either version 2, or (at
13145 + your option) any later version.
13146 +
13147 + This program is distributed in the hope that it will be useful, but
13148 + WITHOUT ANY WARRANTY; without even the implied warranty of
13149 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13150 + General Public License for more details.
13151 +*/
13152 +
13153 +#include "ipkg.h"
13154 +#include <errno.h>
13155 +
13156 +#include "void_list.h"
13157 +
13158 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13159 +{
13160 + elt->next = NULL;
13161 + elt->data = data;
13162 +
13163 + return 0;
13164 +}
13165 +
13166 +void void_list_elt_deinit(void_list_elt_t *elt)
13167 +{
13168 + void_list_elt_init(elt, NULL);
13169 +}
13170 +
13171 +int void_list_init(void_list_t *list)
13172 +{
13173 + void_list_elt_init(&list->pre_head, NULL);
13174 + list->head = NULL;
13175 + list->pre_head.next = list->head;
13176 + list->tail = NULL;
13177 +
13178 + return 0;
13179 +}
13180 +
13181 +void void_list_deinit(void_list_t *list)
13182 +{
13183 + void_list_elt_t *elt;
13184 +
13185 + while (list->head) {
13186 + elt = void_list_pop(list);
13187 + void_list_elt_deinit(elt);
13188 + /* malloced in void_list_append */
13189 + free(elt);
13190 + }
13191 +}
13192 +
13193 +int void_list_append(void_list_t *list, void *data)
13194 +{
13195 + void_list_elt_t *elt;
13196 +
13197 + /* freed in void_list_deinit */
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 + if (list->tail) {
13207 + list->tail->next = elt;
13208 + list->tail = elt;
13209 + } else {
13210 + list->head = elt;
13211 + list->pre_head.next = list->head;
13212 + list->tail = elt;
13213 + }
13214 +
13215 + return 0;
13216 +}
13217 +
13218 +int void_list_push(void_list_t *list, void *data)
13219 +{
13220 + void_list_elt_t *elt;
13221 +
13222 + elt = malloc(sizeof(void_list_elt_t));
13223 + if (elt == NULL) {
13224 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13225 + return ENOMEM;
13226 + }
13227 +
13228 + void_list_elt_init(elt, data);
13229 +
13230 + elt->next = list->head;
13231 + list->head->next = elt;
13232 + if (list->tail == NULL) {
13233 + list->tail = list->head;
13234 + }
13235 +
13236 + return 0;
13237 +}
13238 +
13239 +void_list_elt_t *void_list_pop(void_list_t *list)
13240 +{
13241 + void_list_elt_t *elt;
13242 +
13243 + elt = list->head;
13244 +
13245 + if (list->head) {
13246 + list->head = list->head->next;
13247 + list->pre_head.next = list->head;
13248 + if (list->head == NULL) {
13249 + list->tail = NULL;
13250 + }
13251 + }
13252 +
13253 + return elt;
13254 +}
13255 +
13256 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13257 +{
13258 + void_list_elt_t *prior;
13259 + void_list_elt_t *old_elt;
13260 + void *old_data;
13261 +
13262 + old_elt = *iter;
13263 + old_data = old_elt->data;
13264 +
13265 + if (old_elt == list->head) {
13266 + prior = &list->pre_head;
13267 + void_list_pop(list);
13268 + } else {
13269 + for (prior = list->head; prior; prior = prior->next) {
13270 + if (prior->next == old_elt) {
13271 + break;
13272 + }
13273 + }
13274 + if (prior == NULL || prior->next != old_elt) {
13275 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13276 + return NULL;
13277 + }
13278 + prior->next = old_elt->next;
13279 +
13280 + if (old_elt == list->tail) {
13281 + list->tail = prior;
13282 + }
13283 + }
13284 +
13285 + void_list_elt_deinit(old_elt);
13286 + *iter = prior;
13287 +
13288 + return old_data;
13289 +}
13290 +
13291 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13292 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13293 +{
13294 + void_list_elt_t *prior;
13295 + void_list_elt_t *old_elt = NULL;
13296 + void *old_data = NULL;
13297 +
13298 + /* first element */
13299 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13300 + old_elt = list->head;
13301 + old_data = list->head->data;
13302 + void_list_pop(list);
13303 + } else {
13304 + int found = 0;
13305 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13306 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13307 + old_elt = prior->next;
13308 + old_data = old_elt->data;
13309 + found = 1;
13310 + break;
13311 + }
13312 + }
13313 + if (!found) {
13314 + return NULL;
13315 + }
13316 + prior->next = old_elt->next;
13317 +
13318 + if (old_elt == list->tail) {
13319 + list->tail = prior;
13320 + }
13321 + }
13322 + if (old_elt)
13323 + void_list_elt_deinit(old_elt);
13324 +
13325 + if (old_data)
13326 + return old_data;
13327 + else
13328 + return NULL;
13329 +}
13330 diff -ruN busybox-1.1.1-old/archival/libipkg/void_list.h busybox-1.1.1-new/archival/libipkg/void_list.h
13331 --- busybox-1.1.1-old/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13332 +++ busybox-1.1.1-new/archival/libipkg/void_list.h 2006-03-30 00:39:48.000000000 +0200
13333 @@ -0,0 +1,59 @@
13334 +/* void_list.h - the itsy package management system
13335 +
13336 + Carl D. Worth
13337 +
13338 + Copyright (C) 2001 University of Southern California
13339 +
13340 + This program is free software; you can redistribute it and/or
13341 + modify it under the terms of the GNU General Public License as
13342 + published by the Free Software Foundation; either version 2, or (at
13343 + your option) any later version.
13344 +
13345 + This program is distributed in the hope that it will be useful, but
13346 + WITHOUT ANY WARRANTY; without even the implied warranty of
13347 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13348 + General Public License for more details.
13349 +*/
13350 +
13351 +#ifndef VOID_LIST_H
13352 +#define VOID_LIST_H
13353 +
13354 +typedef struct void_list_elt void_list_elt_t;
13355 +struct void_list_elt
13356 +{
13357 + void_list_elt_t *next;
13358 + void *data;
13359 +};
13360 +
13361 +typedef struct void_list void_list_t;
13362 +struct void_list
13363 +{
13364 + void_list_elt_t pre_head;
13365 + void_list_elt_t *head;
13366 + void_list_elt_t *tail;
13367 +};
13368 +
13369 +static inline int void_list_empty(void_list_t *list)
13370 +{
13371 + if (list->head == NULL)
13372 + return 1;
13373 + else
13374 + return 0;
13375 +}
13376 +
13377 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13378 +void void_list_elt_deinit(void_list_elt_t *elt);
13379 +
13380 +int void_list_init(void_list_t *list);
13381 +void void_list_deinit(void_list_t *list);
13382 +
13383 +int void_list_append(void_list_t *list, void *data);
13384 +int void_list_push(void_list_t *list, void *data);
13385 +void_list_elt_t *void_list_pop(void_list_t *list);
13386 +
13387 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13388 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13389 +typedef int (*void_list_cmp_t)(const void *, const void *);
13390 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13391 +
13392 +#endif
13393 diff -ruN busybox-1.1.1-old/archival/libipkg/xsystem.c busybox-1.1.1-new/archival/libipkg/xsystem.c
13394 --- busybox-1.1.1-old/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13395 +++ busybox-1.1.1-new/archival/libipkg/xsystem.c 2006-03-30 00:39:48.000000000 +0200
13396 @@ -0,0 +1,64 @@
13397 +/* xsystem.c - system(3) with error messages
13398 +
13399 + Carl D. Worth
13400 +
13401 + Copyright (C) 2001 University of Southern California
13402 +
13403 + This program is free software; you can redistribute it and/or
13404 + modify it under the terms of the GNU General Public License as
13405 + published by the Free Software Foundation; either version 2, or (at
13406 + your option) any later version.
13407 +
13408 + This program is distributed in the hope that it will be useful, but
13409 + WITHOUT ANY WARRANTY; without even the implied warranty of
13410 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13411 + General Public License for more details.
13412 +*/
13413 +
13414 +#include "ipkg.h"
13415 +#include <sys/wait.h>
13416 +
13417 +#include "xsystem.h"
13418 +
13419 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13420 + really need the /bin/sh invocation which takes resources and
13421 + introduces security problems. I should switch all of this to a sort
13422 + of execl() or execv() interface/implementation.
13423 +*/
13424 +
13425 +/* Like system(3), but with error messages printed if the fork fails
13426 + or if the child process dies due to an uncaught signal. Also, the
13427 + return value is a bit simpler:
13428 +
13429 + -1 if there was any problem
13430 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13431 + as defined in <sys/wait.h>.
13432 +*/
13433 +int xsystem(const char *cmd)
13434 +{
13435 + int err;
13436 +
13437 + err = system(cmd);
13438 +
13439 + if (err == -1) {
13440 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13441 + __FUNCTION__, cmd);
13442 + return -1;
13443 + }
13444 +
13445 + if (WIFSIGNALED(err)) {
13446 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13447 + __FUNCTION__, WTERMSIG(err), cmd);
13448 + return -1;
13449 + }
13450 +
13451 + if (WIFEXITED(err)) {
13452 + /* Normal child exit */
13453 + return WEXITSTATUS(err);
13454 + }
13455 +
13456 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13457 + __FUNCTION__, err);
13458 + return -1;
13459 +}
13460 +
13461 diff -ruN busybox-1.1.1-old/archival/libipkg/xsystem.h busybox-1.1.1-new/archival/libipkg/xsystem.h
13462 --- busybox-1.1.1-old/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13463 +++ busybox-1.1.1-new/archival/libipkg/xsystem.h 2006-03-30 00:39:48.000000000 +0200
13464 @@ -0,0 +1,34 @@
13465 +/* xsystem.h - system(3) with error messages
13466 +
13467 + Carl D. Worth
13468 +
13469 + Copyright (C) 2001 University of Southern California
13470 +
13471 + This program is free software; you can redistribute it and/or
13472 + modify it under the terms of the GNU General Public License as
13473 + published by the Free Software Foundation; either version 2, or (at
13474 + your option) any later version.
13475 +
13476 + This program is distributed in the hope that it will be useful, but
13477 + WITHOUT ANY WARRANTY; without even the implied warranty of
13478 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13479 + General Public License for more details.
13480 +*/
13481 +
13482 +#ifndef XSYSTEM_H
13483 +#define XSYSTEM_H
13484 +
13485 +#include <stdlib.h>
13486 +
13487 +/* Like system(3), but with error messages printed if the fork fails
13488 + or if the child process dies due to an uncaught signal. Also, the
13489 + return value is a bit simpler:
13490 +
13491 + -1 if there was any problem
13492 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13493 + as defined in <sys/wait.h>.
13494 +*/
13495 +int xsystem(const char *cmd);
13496 +
13497 +#endif
13498 +
13499 diff -ruN busybox-1.1.1-old/archival/libunarchive/Makefile.in busybox-1.1.1-new/archival/libunarchive/Makefile.in
13500 --- busybox-1.1.1-old/archival/libunarchive/Makefile.in 2006-03-22 22:16:20.000000000 +0100
13501 +++ busybox-1.1.1-new/archival/libunarchive/Makefile.in 2006-03-30 00:56:59.000000000 +0200
13502 @@ -58,6 +58,7 @@
13503 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13504 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13505 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13506 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13507 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13508 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13509 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13510 diff -ruN busybox-1.1.1-old/archival/libunarchive/data_extract_all.c busybox-1.1.1-new/archival/libunarchive/data_extract_all.c
13511 --- busybox-1.1.1-old/archival/libunarchive/data_extract_all.c 2006-03-22 22:16:20.000000000 +0100
13512 +++ busybox-1.1.1-new/archival/libunarchive/data_extract_all.c 2006-03-30 00:39:48.000000000 +0200
13513 @@ -126,3 +126,17 @@
13514 utime(file_header->name, &t);
13515 }
13516 }
13517 +
13518 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13519 +{
13520 + char *name_ptr = archive_handle->file_header->name;
13521 +
13522 + name_ptr += strspn(name_ptr, "./");
13523 + if (name_ptr[0] != '\0') {
13524 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13525 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13526 + strcat(archive_handle->file_header->name, name_ptr);
13527 + data_extract_all(archive_handle);
13528 + }
13529 +}
13530 +
13531 diff -ruN busybox-1.1.1-old/include/applets.h busybox-1.1.1-new/include/applets.h
13532 --- busybox-1.1.1-old/include/applets.h 2006-03-22 22:16:24.000000000 +0100
13533 +++ busybox-1.1.1-new/include/applets.h 2006-03-30 00:42:08.000000000 +0200
13534 @@ -149,6 +149,7 @@
13535 USE_IPCALC(APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13536 USE_IPCRM(APPLET(ipcrm, ipcrm_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13537 USE_IPCS(APPLET(ipcs, ipcs_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13538 +USE_IPKG(APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13539 USE_IPLINK(APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13540 USE_IPROUTE(APPLET(iproute, iproute_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13541 USE_IPTUNNEL(APPLET(iptunnel, iptunnel_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13542 diff -ruN busybox-1.1.1-old/include/unarchive.h busybox-1.1.1-new/include/unarchive.h
13543 --- busybox-1.1.1-old/include/unarchive.h 2006-03-22 22:16:24.000000000 +0100
13544 +++ busybox-1.1.1-new/include/unarchive.h 2006-03-30 00:39:48.000000000 +0200
13545 @@ -74,6 +74,7 @@
13546
13547 extern void data_skip(archive_handle_t *archive_handle);
13548 extern void data_extract_all(archive_handle_t *archive_handle);
13549 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13550 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13551 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13552
13553 diff -ruN busybox-1.1.1-old/include/usage.h busybox-1.1.1-new/include/usage.h
13554 --- busybox-1.1.1-old/include/usage.h 2006-03-22 22:16:24.000000000 +0100
13555 +++ busybox-1.1.1-new/include/usage.h 2006-03-30 00:42:53.000000000 +0200
13556 @@ -1013,6 +1013,82 @@
13557 "$ ls -la /tmp/busybox*\n" \
13558 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13559
13560 +#define ipkg_trivial_usage \
13561 + "[options]... sub-command [arguments]..."
13562 +#define ipkg_full_usage \
13563 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13564 + "\n" \
13565 + "Sub-commands:\n" \
13566 + "\nPackage Manipulation:\n" \
13567 + "\tupdate Update list of available packages\n" \
13568 + "\tupgrade Upgrade all installed packages to latest version\n" \
13569 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13570 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13571 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13572 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13573 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13574 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13575 + "\n" \
13576 + "Informational Commands:\n" \
13577 + "\tlist List available packages and descriptions\n" \
13578 + "\tlist_installed List all and only the installed packages and description \n" \
13579 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13580 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13581 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13582 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13583 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13584 + "\tcompare_versions <v1> <op> <v2>\n" \
13585 + "\t compare versions using <= < > >= = << >>\n" \
13586 + "\tprint_architecture prints the architecture.\n" \
13587 + "\tprint_installation_architecture\n" \
13588 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13589 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13590 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13591 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13592 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13593 + "\t prints the installation architecture.\n" \
13594 + "\n" \
13595 + "\nOptions:\n" \
13596 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13597 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13598 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13599 + "\t 0 errors only\n" \
13600 + "\t 1 normal messages (default)\n" \
13601 + "\t 2 informative messages\n" \
13602 + "\t 3 debug output\n" \
13603 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13604 + "\t-conf <conf_file> Default configuration file location\n" \
13605 + " is /etc/ipkg.conf\n" \
13606 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13607 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13608 + " <dest_name> should be a defined dest name from\n" \
13609 + " the configuration file, (but can also be a\n" \
13610 + " directory name in a pinch).\n" \
13611 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13612 + "\t-offline <offline_root> offline installation of packages.\n" \
13613 + "\t-verbose_wget more wget messages\n" \
13614 + "\n" \
13615 + "Force Options (use when ipkg is too smart for its own good):\n" \
13616 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13617 + "\t Install/remove package in spite of failed dependences\n" \
13618 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13619 + " (no prompts). Note that this will not prevent\n" \
13620 + " package installation scripts from prompting.\n" \
13621 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13622 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13623 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13624 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13625 + "\t-noaction No action -- test only\n" \
13626 + "\t-nodeps Do not follow dependences\n" \
13627 + "\t-force-removal-of-dependent-packages\n" \
13628 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13629 + "\t-test No action -- test only\n" \
13630 + "\t-t Specify tmp-dir.\n" \
13631 + "\t--tmp-dir Specify tmp-dir.\n" \
13632 + "\n" \
13633 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13634 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13635 +
13636 #define halt_trivial_usage \
13637 "[-d<delay>] [-n<nosync>] [-f<force>]"
13638 #define halt_full_usage \
This page took 0.98994 seconds and 5 git commands to generate.