fix ipkg segfaults
[openwrt/svn-archive/archive.git] / openwrt / package / busybox / patches / 911-ipkg.patch
1 diff -ruN busybox-1.1.0-pre1-old/Makefile busybox-1.1.0-pre1-new/Makefile
2 --- busybox-1.1.0-pre1-old/Makefile 2005-11-01 00:55:40.000000000 +0100
3 +++ busybox-1.1.0-pre1-new/Makefile 2005-12-07 21:25:30.000000000 +0100
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.0-pre1-old/archival/Config.in busybox-1.1.0-pre1-new/archival/Config.in
14 --- busybox-1.1.0-pre1-old/archival/Config.in 2005-11-01 00:55:20.000000000 +0100
15 +++ busybox-1.1.0-pre1-new/archival/Config.in 2005-12-07 21:25:30.000000000 +0100
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.0-pre1-old/archival/Makefile.in busybox-1.1.0-pre1-new/archival/Makefile.in
32 --- busybox-1.1.0-pre1-old/archival/Makefile.in 2005-11-01 00:55:20.000000000 +0100
33 +++ busybox-1.1.0-pre1-new/archival/Makefile.in 2005-12-07 21:25:30.000000000 +0100
34 @@ -19,6 +19,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.0-pre1-old/archival/dpkg.c busybox-1.1.0-pre1-new/archival/dpkg.c
43 --- busybox-1.1.0-pre1-old/archival/dpkg.c 2005-11-01 00:55:20.000000000 +0100
44 +++ busybox-1.1.0-pre1-new/archival/dpkg.c 2005-12-07 21:25:30.000000000 +0100
45 @@ -1528,6 +1528,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 @@ -1542,6 +1546,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.0-pre1-old/archival/ipkg.c busybox-1.1.0-pre1-new/archival/ipkg.c
66 --- busybox-1.1.0-pre1-old/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
67 +++ busybox-1.1.0-pre1-new/archival/ipkg.c 2005-12-07 21:25:30.000000000 +0100
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.0-pre1-old/archival/libipkg/Makefile busybox-1.1.0-pre1-new/archival/libipkg/Makefile
96 --- busybox-1.1.0-pre1-old/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
97 +++ busybox-1.1.0-pre1-new/archival/libipkg/Makefile 2005-12-07 21:25:30.000000000 +0100
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.0-pre1-old/archival/libipkg/Makefile.in busybox-1.1.0-pre1-new/archival/libipkg/Makefile.in
132 --- busybox-1.1.0-pre1-old/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
133 +++ busybox-1.1.0-pre1-new/archival/libipkg/Makefile.in 2005-12-07 21:25:30.000000000 +0100
134 @@ -0,0 +1,83 @@
135 +# Makefile for busybox
136 +#
137 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
138 +#
139 +# This program is free software; you can redistribute it and/or modify
140 +# it under the terms of the GNU General Public License as published by
141 +# the Free Software Foundation; either version 2 of the License, or
142 +# (at your option) any later version.
143 +#
144 +# This program is distributed in the hope that it will be useful,
145 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
146 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
147 +# General Public License for more details.
148 +#
149 +# You should have received a copy of the GNU General Public License
150 +# along with this program; if not, write to the Free Software
151 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
152 +#
153 +
154 +LIBIPKG_AR:=libipkg.a
155 +ifndef $(LIBIPKG_DIR)
156 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
157 +endif
158 +srcdir=$(top_srcdir)/archival/libipkg
159 +
160 +LIBIPKG_CORE_SOURCES:= \
161 + args.c \
162 + libipkg.c \
163 + user.c \
164 +
165 +LIBIPKG_CMD_SOURCES:= \
166 + ipkg_cmd.c \
167 + ipkg_configure.c \
168 + ipkg_download.c \
169 + ipkg_install.c \
170 + ipkg_remove.c \
171 + ipkg_upgrade.c \
172 +
173 +LIBIPKG_DB_SOURCES:= \
174 + hash_table.c \
175 + ipkg_conf.c \
176 + ipkg_utils.c \
177 + pkg.c \
178 + pkg_depends.c \
179 + pkg_extract.c \
180 + pkg_hash.c \
181 + pkg_parse.c \
182 + pkg_vec.c \
183 +
184 +LIBIPKG_LIST_SOURCES:= \
185 + conffile.c \
186 + conffile_list.c \
187 + nv_pair.c \
188 + nv_pair_list.c \
189 + pkg_dest.c \
190 + pkg_dest_list.c \
191 + pkg_src.c \
192 + pkg_src_list.c \
193 + str_list.c \
194 + void_list.c \
195 +
196 +LIBIPKG_UTIL_SOURCES:= \
197 + file_util.c \
198 + ipkg_message.c \
199 + md5.c \
200 + str_util.c \
201 + xsystem.c \
202 +
203 +LIBIPKG-y += $(LIBIPKG_CORE_SOURCES)
204 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
205 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
206 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_UTIL_SOURCES)
208 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
209 +
210 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
211 +
212 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
213 + $(AR) -ro $@ $^
214 +
215 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
216 + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\"" -c -o $@ $<
217 +
218 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/args.c busybox-1.1.0-pre1-new/archival/libipkg/args.c
219 --- busybox-1.1.0-pre1-old/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
220 +++ busybox-1.1.0-pre1-new/archival/libipkg/args.c 2005-12-07 21:25:30.000000000 +0100
221 @@ -0,0 +1,241 @@
222 +/* args.c - parse command-line args
223 +
224 + Carl D. Worth
225 +
226 + Copyright 2001 University of Southern California
227 +
228 + This program is free software; you can redistribute it and/or modify
229 + it under the terms of the GNU General Public License as published by
230 + the Free Software Foundation; either version 2, or (at your option)
231 + any later version.
232 +
233 + This program is distributed in the hope that it will be useful,
234 + but WITHOUT ANY WARRANTY; without even the implied warranty of
235 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236 + GNU General Public License for more details.
237 + */
238 +
239 +#include <getopt.h>
240 +#include <stdlib.h>
241 +#include <string.h>
242 +#include <unistd.h>
243 +
244 +#include "ipkg.h"
245 +#include "ipkg_message.h"
246 +
247 +#include "args.h"
248 +#include "sprintf_alloc.h"
249 +
250 +#include "libbb.h"
251 +
252 +
253 +static void print_version(void);
254 +
255 +enum long_args_opt
256 +{
257 + ARGS_OPT_FORCE_DEFAULTS = 129,
258 + ARGS_OPT_FORCE_DEPENDS,
259 + ARGS_OPT_FORCE_OVERWRITE,
260 + ARGS_OPT_FORCE_DOWNGRADE,
261 + ARGS_OPT_FORCE_REINSTALL,
262 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
263 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
264 + ARGS_OPT_FORCE_SPACE,
265 + ARGS_OPT_NOACTION,
266 + ARGS_OPT_NODEPS,
267 + ARGS_OPT_VERBOSE_WGET,
268 + ARGS_OPT_VERBOSITY,
269 + ARGS_OPT_MULTIPLE_PROVIDERS
270 +};
271 +
272 +int args_init(args_t *args)
273 +{
274 + char *conf_file_dir;
275 +
276 + memset(args, 0, sizeof(args_t));
277 +
278 + args->dest = ARGS_DEFAULT_DEST;
279 +
280 + conf_file_dir = getenv("IPKG_CONF_DIR");
281 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
282 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
283 + }
284 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
285 + ARGS_DEFAULT_CONF_FILE_NAME);
286 +
287 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
288 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
289 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
290 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
291 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
292 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
293 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
294 + args->noaction = ARGS_DEFAULT_NOACTION;
295 + args->nodeps = ARGS_DEFAULT_NODEPS;
296 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
297 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
298 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
299 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
300 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
301 + args->multiple_providers = 0;
302 + args->nocheckfordirorfile = 0;
303 +
304 + return 1;
305 +}
306 +
307 +void args_deinit(args_t *args)
308 +{
309 + free(args->conf_file);
310 + args->conf_file = NULL;
311 +}
312 +
313 +int args_parse(args_t *args, int argc, char *argv[])
314 +{
315 + int c;
316 + int option_index = 0;
317 + int parse_err = 0;
318 + static struct option long_options[] = {
319 + {"query-all", 0, 0, 'A'},
320 + {"conf-file", 1, 0, 'f'},
321 + {"conf", 1, 0, 'f'},
322 + {"dest", 1, 0, 'd'},
323 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
324 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
325 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
326 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
327 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
328 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
329 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
330 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
331 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
332 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
333 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
334 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
335 + {"recursive", 0, 0,
336 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
337 + {"force-removal-of-dependent-packages", 0, 0,
338 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
339 + {"force_removal_of_dependent_packages", 0, 0,
340 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
341 + {"force-removal-of-essential-packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
343 + {"force_removal_of_essential_packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
346 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
347 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
348 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
349 + {"offline", 1, 0, 'o'},
350 + {"offline-root", 1, 0, 'o'},
351 + {"test", 0, 0, ARGS_OPT_NOACTION},
352 + {"tmp-dir", 1, 0, 't'},
353 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
354 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
355 + {"verbosity", 2, 0, 'V'},
356 + {"version", 0, 0, 'v'},
357 + {0, 0, 0, 0}
358 + };
359 +
360 + while (1) {
361 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
362 + if (c == -1)
363 + break;
364 +
365 + switch (c) {
366 + case 'A':
367 + args->query_all = 1;
368 + break;
369 + case 'd':
370 + args->dest = optarg;
371 + break;
372 + case 'f':
373 + free(args->conf_file);
374 + args->conf_file = strdup(optarg);
375 + break;
376 + case 'o':
377 + args->offline_root = optarg;
378 + break;
379 + case 'n':
380 + args->noaction = 1;
381 + break;
382 + case 't':
383 + args->tmp_dir = strdup(optarg);
384 + break;
385 + case 'v':
386 + print_version();
387 + exit(0);
388 + case 'V':
389 + case ARGS_OPT_VERBOSITY:
390 + if (optarg)
391 + args->verbosity = atoi(optarg);
392 + else
393 + args->verbosity += 1;
394 + break;
395 + case ARGS_OPT_FORCE_DEFAULTS:
396 + args->force_defaults = 1;
397 + break;
398 + case ARGS_OPT_FORCE_DEPENDS:
399 + args->force_depends = 1;
400 + break;
401 + case ARGS_OPT_FORCE_OVERWRITE:
402 + args->force_overwrite = 1;
403 + break;
404 + case ARGS_OPT_FORCE_DOWNGRADE:
405 + args->force_downgrade = 1;
406 + break;
407 + case ARGS_OPT_FORCE_REINSTALL:
408 + args->force_reinstall = 1;
409 + break;
410 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
411 + args->force_removal_of_essential_packages = 1;
412 + break;
413 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
414 + args->force_removal_of_dependent_packages = 1;
415 + break;
416 + case ARGS_OPT_FORCE_SPACE:
417 + args->force_space = 1;
418 + break;
419 + case ARGS_OPT_VERBOSE_WGET:
420 + args->verbose_wget = 1;
421 + break;
422 + case ARGS_OPT_MULTIPLE_PROVIDERS:
423 + args->multiple_providers = 1;
424 + break;
425 + case ARGS_OPT_NODEPS:
426 + args->nodeps = 1;
427 + break;
428 + case ARGS_OPT_NOACTION:
429 + args->noaction = 1;
430 + break;
431 + case ':':
432 + parse_err++;
433 + break;
434 + case '?':
435 + parse_err++;
436 + break;
437 + default:
438 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
439 + }
440 + }
441 +
442 + if (parse_err) {
443 + return -parse_err;
444 + } else {
445 + return optind;
446 + }
447 +}
448 +
449 +void args_usage(char *complaint)
450 +{
451 + if (complaint) {
452 + bb_error_msg("%s\n", complaint);
453 + }
454 + print_version();
455 + bb_show_usage();
456 + exit(1);
457 +}
458 +
459 +static void print_version(void)
460 +{
461 + bb_error_msg("version %s\n", IPKG_VERSION);
462 +}
463 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/args.h busybox-1.1.0-pre1-new/archival/libipkg/args.h
464 --- busybox-1.1.0-pre1-old/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
465 +++ busybox-1.1.0-pre1-new/archival/libipkg/args.h 2005-12-07 21:25:30.000000000 +0100
466 @@ -0,0 +1,71 @@
467 +/* args.h - parse command-line args
468 +
469 + Carl D. Worth
470 +
471 + Copyright 2001 University of Southern California
472 +
473 + This program is free software; you can redistribute it and/or modify
474 + it under the terms of the GNU General Public License as published by
475 + the Free Software Foundation; either version 2, or (at your option)
476 + any later version.
477 +
478 + This program is distributed in the hope that it will be useful,
479 + but WITHOUT ANY WARRANTY; without even the implied warranty of
480 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
481 + GNU General Public License for more details.
482 +*/
483 +
484 +#ifndef ARGS_H
485 +#define ARGS_H
486 +
487 +struct args
488 +{
489 + char *conf_file;
490 + char *dest;
491 + char *tmp_dir;
492 + int force_defaults;
493 + int force_depends;
494 + int force_overwrite;
495 + int force_downgrade;
496 + int force_reinstall;
497 + int force_removal_of_essential_packages;
498 + int force_removal_of_dependent_packages;
499 + int force_space;
500 + int noaction;
501 + int nodeps;
502 + int multiple_providers;
503 + int query_all;
504 + int verbose_wget;
505 + int verbosity;
506 + int nocheckfordirorfile;
507 + char *offline_root;
508 + char *offline_root_pre_script_cmd;
509 + char *offline_root_post_script_cmd;
510 +};
511 +typedef struct args args_t;
512 +
513 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
514 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
515 +#define ARGS_DEFAULT_DEST NULL
516 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
517 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
518 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
519 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
520 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
521 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
522 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
523 +#define ARGS_DEFAULT_FORCE_SPACE 0
524 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
525 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
526 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
527 +#define ARGS_DEFAULT_NOACTION 0
528 +#define ARGS_DEFAULT_NODEPS 0
529 +#define ARGS_DEFAULT_VERBOSE_WGET 0
530 +#define ARGS_DEFAULT_VERBOSITY 1
531 +
532 +int args_init(args_t *args);
533 +void args_deinit(args_t *args);
534 +int args_parse(args_t *args, int argc, char *argv[]);
535 +void args_usage(char *complaint);
536 +
537 +#endif
538 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/conffile.c busybox-1.1.0-pre1-new/archival/libipkg/conffile.c
539 --- busybox-1.1.0-pre1-old/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
540 +++ busybox-1.1.0-pre1-new/archival/libipkg/conffile.c 2005-12-07 21:25:30.000000000 +0100
541 @@ -0,0 +1,64 @@
542 +/* conffile.c - the itsy package management system
543 +
544 + Carl D. Worth
545 +
546 + Copyright (C) 2001 University of Southern California
547 +
548 + This program is free software; you can redistribute it and/or
549 + modify it under the terms of the GNU General Public License as
550 + published by the Free Software Foundation; either version 2, or (at
551 + your option) any later version.
552 +
553 + This program is distributed in the hope that it will be useful, but
554 + WITHOUT ANY WARRANTY; without even the implied warranty of
555 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
556 + General Public License for more details.
557 +*/
558 +
559 +#include <string.h>
560 +#include <stdlib.h>
561 +
562 +#include "ipkg.h"
563 +#include "ipkg_message.h"
564 +
565 +#include "conffile.h"
566 +#include "file_util.h"
567 +#include "sprintf_alloc.h"
568 +
569 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
570 +{
571 + return nv_pair_init(conffile, file_name, md5sum);
572 +}
573 +
574 +void conffile_deinit(conffile_t *conffile)
575 +{
576 + nv_pair_deinit(conffile);
577 +}
578 +
579 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
580 +{
581 + char *md5sum;
582 + char *filename = conffile->name;
583 + char *root_filename;
584 + int ret;
585 +
586 + if (conffile->value == NULL) {
587 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
588 + return 1;
589 + }
590 +
591 + root_filename = root_filename_alloc(conf, filename);
592 +
593 + md5sum = file_md5sum_alloc(root_filename);
594 +
595 + ret = strcmp(md5sum, conffile->value);
596 + if (ret) {
597 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
598 + conffile->name, md5sum, conffile->value);
599 + }
600 +
601 + free(root_filename);
602 + free(md5sum);
603 +
604 + return ret;
605 +}
606 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/conffile.h busybox-1.1.0-pre1-new/archival/libipkg/conffile.h
607 --- busybox-1.1.0-pre1-old/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
608 +++ busybox-1.1.0-pre1-new/archival/libipkg/conffile.h 2005-12-07 21:25:30.000000000 +0100
609 @@ -0,0 +1,30 @@
610 +/* conffile.h - the itsy package management system
611 +
612 + Carl D. Worth
613 +
614 + Copyright (C) 2001 University of Southern California
615 +
616 + This program is free software; you can redistribute it and/or
617 + modify it under the terms of the GNU General Public License as
618 + published by the Free Software Foundation; either version 2, or (at
619 + your option) any later version.
620 +
621 + This program is distributed in the hope that it will be useful, but
622 + WITHOUT ANY WARRANTY; without even the implied warranty of
623 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
624 + General Public License for more details.
625 +*/
626 +
627 +#ifndef CONFFILE_H
628 +#define CONFFILE_H
629 +
630 +#include "nv_pair.h"
631 +
632 +typedef struct nv_pair conffile_t;
633 +
634 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
635 +void conffile_deinit(conffile_t *conffile);
636 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
637 +
638 +#endif
639 +
640 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/conffile_list.c busybox-1.1.0-pre1-new/archival/libipkg/conffile_list.c
641 --- busybox-1.1.0-pre1-old/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
642 +++ busybox-1.1.0-pre1-new/archival/libipkg/conffile_list.c 2005-12-07 21:25:30.000000000 +0100
643 @@ -0,0 +1,47 @@
644 +/* conffile_list.c - the itsy package management system
645 +
646 + Carl D. Worth
647 +
648 + Copyright (C) 2001 University of Southern California
649 +
650 + This program is free software; you can redistribute it and/or
651 + modify it under the terms of the GNU General Public License as
652 + published by the Free Software Foundation; either version 2, or (at
653 + your option) any later version.
654 +
655 + This program is distributed in the hope that it will be useful, but
656 + WITHOUT ANY WARRANTY; without even the implied warranty of
657 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
658 + General Public License for more details.
659 +*/
660 +
661 +#include "ipkg.h"
662 +
663 +#include "conffile_list.h"
664 +
665 +int conffile_list_init(conffile_list_t *list)
666 +{
667 + return nv_pair_list_init(list);
668 +}
669 +
670 +void conffile_list_deinit(conffile_list_t *list)
671 +{
672 + nv_pair_list_deinit(list);
673 +}
674 +
675 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
676 + const char *md5sum)
677 +{
678 + return nv_pair_list_append(list, file_name, md5sum);
679 +}
680 +
681 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
682 +{
683 + return nv_pair_list_push(list, data);
684 +}
685 +
686 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
687 +{
688 + return nv_pair_list_pop(list);
689 +}
690 +
691 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/conffile_list.h busybox-1.1.0-pre1-new/archival/libipkg/conffile_list.h
692 --- busybox-1.1.0-pre1-old/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
693 +++ busybox-1.1.0-pre1-new/archival/libipkg/conffile_list.h 2005-12-07 21:25:30.000000000 +0100
694 @@ -0,0 +1,36 @@
695 +/* conffile_list.h - the itsy package management system
696 +
697 + Carl D. Worth
698 +
699 + Copyright (C) 2001 University of Southern California
700 +
701 + This program is free software; you can redistribute it and/or
702 + modify it under the terms of the GNU General Public License as
703 + published by the Free Software Foundation; either version 2, or (at
704 + your option) any later version.
705 +
706 + This program is distributed in the hope that it will be useful, but
707 + WITHOUT ANY WARRANTY; without even the implied warranty of
708 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
709 + General Public License for more details.
710 +*/
711 +
712 +#ifndef CONFFILE_LIST_H
713 +#define CONFFILE_LIST_H
714 +
715 +#include "conffile.h"
716 +#include "nv_pair_list.h"
717 +
718 +typedef struct nv_pair_list_elt conffile_list_elt_t;
719 +typedef struct nv_pair_list conffile_list_t;
720 +
721 +int conffile_list_init(conffile_list_t *list);
722 +void conffile_list_deinit(conffile_list_t *list);
723 +
724 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
725 + const char *root_dir);
726 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
727 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
728 +
729 +#endif
730 +
731 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/file_util.c busybox-1.1.0-pre1-new/archival/libipkg/file_util.c
732 --- busybox-1.1.0-pre1-old/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
733 +++ busybox-1.1.0-pre1-new/archival/libipkg/file_util.c 2005-12-07 21:25:30.000000000 +0100
734 @@ -0,0 +1,177 @@
735 +/* file_util.c - convenience routines for common stat operations
736 +
737 + Carl D. Worth
738 +
739 + Copyright (C) 2001 University of Southern California
740 +
741 + This program is free software; you can redistribute it and/or
742 + modify it under the terms of the GNU General Public License as
743 + published by the Free Software Foundation; either version 2, or (at
744 + your option) any later version.
745 +
746 + This program is distributed in the hope that it will be useful, but
747 + WITHOUT ANY WARRANTY; without even the implied warranty of
748 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
749 + General Public License for more details.
750 +*/
751 +
752 +#include "ipkg.h"
753 +#include <sys/types.h>
754 +#include <sys/stat.h>
755 +
756 +#include "sprintf_alloc.h"
757 +#include "file_util.h"
758 +#include "md5.h"
759 +#include "libbb.h"
760 +#undef strlen
761 +
762 +int file_exists(const char *file_name)
763 +{
764 + int err;
765 + struct stat stat_buf;
766 +
767 + err = stat(file_name, &stat_buf);
768 + if (err == 0) {
769 + return 1;
770 + } else {
771 + return 0;
772 + }
773 +}
774 +
775 +int file_is_dir(const char *file_name)
776 +{
777 + int err;
778 + struct stat stat_buf;
779 +
780 + err = stat(file_name, &stat_buf);
781 + if (err) {
782 + return 0;
783 + }
784 +
785 + return S_ISDIR(stat_buf.st_mode);
786 +}
787 +
788 +/* read a single line from a file, stopping at a newline or EOF.
789 + If a newline is read, it will appear in the resulting string.
790 + Return value is a malloc'ed char * which should be freed at
791 + some point by the caller.
792 +
793 + Return value is NULL if the file is at EOF when called.
794 +*/
795 +#define FILE_READ_LINE_BUF_SIZE 1024
796 +char *file_read_line_alloc(FILE *file)
797 +{
798 + char buf[FILE_READ_LINE_BUF_SIZE];
799 + int buf_len;
800 + char *line = NULL;
801 + int line_size = 0;
802 +
803 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
804 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
805 + buf_len = strlen(buf);
806 + if (line) {
807 + line_size += buf_len;
808 + line = realloc(line, line_size);
809 + if (line == NULL) {
810 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
811 + break;
812 + }
813 + strcat(line, buf);
814 + } else {
815 + line_size = buf_len + 1;
816 + line = strdup(buf);
817 + }
818 + if (buf[buf_len - 1] == '\n') {
819 + break;
820 + }
821 + }
822 +
823 + return line;
824 +}
825 +
826 +int file_move(const char *src, const char *dest)
827 +{
828 + int err;
829 +
830 + err = rename(src, dest);
831 +
832 + if (err && errno == EXDEV) {
833 + err = file_copy(src, dest);
834 + unlink(src);
835 + } else if (err) {
836 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
837 + __FUNCTION__, src, dest, strerror(errno));
838 + }
839 +
840 + return err;
841 +}
842 +
843 +/* I put these here to keep libbb dependencies from creeping all over
844 + the ipkg code */
845 +int file_copy(const char *src, const char *dest)
846 +{
847 + int err;
848 +
849 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
850 + if (err) {
851 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
852 + __FUNCTION__, src, dest);
853 + }
854 +
855 + return err;
856 +}
857 +
858 +int file_mkdir_hier(const char *path, long mode)
859 +{
860 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
861 +}
862 +
863 +char *file_md5sum_alloc(const char *file_name)
864 +{
865 + static const int md5sum_bin_len = 16;
866 + static const int md5sum_hex_len = 32;
867 +
868 + static const unsigned char bin2hex[16] = {
869 + '0', '1', '2', '3',
870 + '4', '5', '6', '7',
871 + '8', '9', 'a', 'b',
872 + 'c', 'd', 'e', 'f'
873 + };
874 +
875 + int i, err;
876 + FILE *file;
877 + unsigned char *md5sum_hex;
878 + unsigned char md5sum_bin[md5sum_bin_len];
879 +
880 + md5sum_hex = malloc(md5sum_hex_len + 1);
881 + if (md5sum_hex == NULL) {
882 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
883 + return strdup("");
884 + }
885 +
886 + file = fopen(file_name, "r");
887 + if (file == NULL) {
888 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
889 + __FUNCTION__, file_name, strerror(errno));
890 + return strdup("");
891 + }
892 +
893 + err = md5_stream(file, md5sum_bin);
894 + if (err) {
895 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
896 + __FUNCTION__, file_name, strerror(err));
897 + return strdup("");
898 + }
899 +
900 + fclose(file);
901 +
902 + for (i=0; i < md5sum_bin_len; i++) {
903 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
904 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
905 + }
906 +
907 + md5sum_hex[md5sum_hex_len] = '\0';
908 +
909 + return md5sum_hex;
910 +}
911 +
912 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/file_util.h busybox-1.1.0-pre1-new/archival/libipkg/file_util.h
913 --- busybox-1.1.0-pre1-old/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
914 +++ busybox-1.1.0-pre1-new/archival/libipkg/file_util.h 2005-12-07 21:25:30.000000000 +0100
915 @@ -0,0 +1,29 @@
916 +/* file_util.h - convenience routines for common file operations
917 +
918 + Carl D. Worth
919 +
920 + Copyright (C) 2001 University of Southern California
921 +
922 + This program is free software; you can redistribute it and/or
923 + modify it under the terms of the GNU General Public License as
924 + published by the Free Software Foundation; either version 2, or (at
925 + your option) any later version.
926 +
927 + This program is distributed in the hope that it will be useful, but
928 + WITHOUT ANY WARRANTY; without even the implied warranty of
929 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
930 + General Public License for more details.
931 +*/
932 +
933 +#ifndef FILE_UTIL_H
934 +#define FILE_UTIL_H
935 +
936 +int file_exists(const char *file_name);
937 +int file_is_dir(const char *file_name);
938 +char *file_read_line_alloc(FILE *file);
939 +int file_move(const char *src, const char *dest);
940 +int file_copy(const char *src, const char *dest);
941 +int file_mkdir_hier(const char *path, long mode);
942 +char *file_md5sum_alloc(const char *file_name);
943 +
944 +#endif
945 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/hash_table.c busybox-1.1.0-pre1-new/archival/libipkg/hash_table.c
946 --- busybox-1.1.0-pre1-old/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
947 +++ busybox-1.1.0-pre1-new/archival/libipkg/hash_table.c 2005-12-07 21:25:30.000000000 +0100
948 @@ -0,0 +1,155 @@
949 +/* hash.c - hash tables for ipkg
950 +
951 + Steven M. Ayer, Jamey Hicks
952 +
953 + Copyright (C) 2002 Compaq Computer Corporation
954 +
955 + This program is free software; you can redistribute it and/or
956 + modify it under the terms of the GNU General Public License as
957 + published by the Free Software Foundation; either version 2, or (at
958 + your option) any later version.
959 +
960 + This program is distributed in the hope that it will be useful, but
961 + WITHOUT ANY WARRANTY; without even the implied warranty of
962 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
963 + General Public License for more details.
964 +*/
965 +
966 +#include <errno.h>
967 +#include <stdio.h>
968 +#include <stdlib.h>
969 +#include <string.h>
970 +#include "hash_table.h"
971 +#include "ipkg_message.h"
972 +
973 +
974 +static int hash_index(hash_table_t *hash, const char *pkg_name);
975 +static int rotating(const char *key, int len, int prime);
976 +
977 +static int hash_index(hash_table_t *hash, const char *pkg_name)
978 +{
979 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
980 +}
981 +
982 +static int rotating(const char *key, int len, int prime)
983 +{
984 + unsigned int hash, i;
985 + for (hash=len, i=0; i<len; ++i)
986 + hash = (hash<<4)^(hash>>28)^key[i];
987 + return (hash % prime);
988 +}
989 +
990 +
991 +/*
992 + * this is an open table keyed by strings
993 + */
994 +int hash_table_init(const char *name, hash_table_t *hash, int len)
995 +{
996 + static int primes_table[] = {
997 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
998 + 19471, 23143, 33961, 46499, 49727, 99529, 0
999 + };
1000 + int *picker;
1001 +
1002 + if (hash->entries != NULL) {
1003 + /* we have been here already */
1004 + return 0;
1005 + }
1006 +
1007 + hash->name = name;
1008 + hash->entries = NULL;
1009 + hash->n_entries = 0;
1010 + hash->hash_entry_key = NULL;
1011 +
1012 + picker = primes_table;
1013 + while(*picker && (*picker++ < len));
1014 + if(!*picker)
1015 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1016 + --picker;
1017 +
1018 + hash->n_entries = *picker;
1019 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1020 + if (hash->entries == NULL) {
1021 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1022 + return ENOMEM;
1023 + }
1024 + return 0;
1025 +}
1026 +
1027 +void hash_table_deinit(hash_table_t *hash)
1028 +{
1029 + free(hash->entries);
1030 + hash->entries = NULL;
1031 + hash->n_entries = 0;
1032 +}
1033 +
1034 +void *hash_table_get(hash_table_t *hash, const char *key)
1035 +{
1036 + int ndx= hash_index(hash, key);
1037 + hash_entry_t *hash_entry = hash->entries + ndx;
1038 + while (hash_entry)
1039 + {
1040 + if (hash_entry->key)
1041 + {
1042 + if (strcmp(key, hash_entry->key) == 0) {
1043 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1044 + return hash_entry->data;
1045 + }
1046 + }
1047 + hash_entry = hash_entry->next;
1048 + }
1049 + return NULL;
1050 +}
1051 +
1052 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1053 +{
1054 + int ndx= hash_index(hash, key);
1055 + hash_entry_t *hash_entry = hash->entries + ndx;
1056 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1057 + if (hash_entry->key) {
1058 + if (strcmp(hash_entry->key, key) == 0) {
1059 + /* alread in table, update the value */
1060 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1061 + hash_entry->data = value;
1062 + return 0;
1063 + } else {
1064 + /*
1065 + * if this is a collision, we have to go to the end of the ll,
1066 + * then add a new entry
1067 + * before we can hook up the value
1068 + */
1069 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1070 + while (hash_entry->next)
1071 + hash_entry = hash_entry->next;
1072 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1073 + if (!hash_entry->next) {
1074 + return -ENOMEM;
1075 + }
1076 + hash_entry = hash_entry->next;
1077 + hash_entry->next = NULL;
1078 + }
1079 + }
1080 + hash->n_elements++;
1081 + hash_entry->key = strdup(key);
1082 + hash_entry->data = value;
1083 +
1084 + return 0;
1085 +}
1086 +
1087 +
1088 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1089 +{
1090 + int i;
1091 + if (!hash || !f)
1092 + return;
1093 +
1094 + for (i = 0; i < hash->n_entries; i++) {
1095 + hash_entry_t *hash_entry = (hash->entries + i);
1096 + do {
1097 + if(hash_entry->key) {
1098 + f(hash_entry->key, hash_entry->data, data);
1099 + }
1100 + } while((hash_entry = hash_entry->next));
1101 + }
1102 +}
1103 +
1104 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/hash_table.h busybox-1.1.0-pre1-new/archival/libipkg/hash_table.h
1105 --- busybox-1.1.0-pre1-old/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1106 +++ busybox-1.1.0-pre1-new/archival/libipkg/hash_table.h 2005-12-07 21:25:30.000000000 +0100
1107 @@ -0,0 +1,44 @@
1108 +/* hash.h - hash tables for ipkg
1109 +
1110 + Steven M. Ayer, Jamey Hicks
1111 +
1112 + Copyright (C) 2002 Compaq Computer Corporation
1113 +
1114 + This program is free software; you can redistribute it and/or
1115 + modify it under the terms of the GNU General Public License as
1116 + published by the Free Software Foundation; either version 2, or (at
1117 + your option) any later version.
1118 +
1119 + This program is distributed in the hope that it will be useful, but
1120 + WITHOUT ANY WARRANTY; without even the implied warranty of
1121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1122 + General Public License for more details.
1123 +*/
1124 +
1125 +#ifndef _HASH_TABLE_H_
1126 +#define _HASH_TABLE_H_
1127 +
1128 +typedef struct hash_entry hash_entry_t;
1129 +typedef struct hash_table hash_table_t;
1130 +
1131 +struct hash_entry {
1132 + const char * key;
1133 + void * data;
1134 + struct hash_entry * next;
1135 +};
1136 +
1137 +struct hash_table {
1138 + const char *name;
1139 + hash_entry_t * entries;
1140 + int n_entries; /* number of buckets */
1141 + int n_elements;
1142 + const char * (*hash_entry_key)(void * data);
1143 +};
1144 +
1145 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1146 +void hash_table_deinit(hash_table_t *hash);
1147 +void *hash_table_get(hash_table_t *hash, const char *key);
1148 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1149 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1150 +
1151 +#endif /* _HASH_TABLE_H_ */
1152 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg.h
1153 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1154 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg.h 2005-12-07 21:25:30.000000000 +0100
1155 @@ -0,0 +1,74 @@
1156 +/* ipkg.h - the itsy package management system
1157 +
1158 + Carl D. Worth
1159 +
1160 + Copyright (C) 2001 University of Southern California
1161 +
1162 + This program is free software; you can redistribute it and/or
1163 + modify it under the terms of the GNU General Public License as
1164 + published by the Free Software Foundation; either version 2, or (at
1165 + your option) any later version.
1166 +
1167 + This program is distributed in the hope that it will be useful, but
1168 + WITHOUT ANY WARRANTY; without even the implied warranty of
1169 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1170 + General Public License for more details.
1171 +*/
1172 +
1173 +#ifndef IPKG_H
1174 +#define IPKG_H
1175 +
1176 +/*
1177 +#ifdef HAVE_CONFIG_H
1178 +#include "config.h"
1179 +#endif
1180 +*/
1181 +
1182 +#if 0
1183 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1184 +#endif
1185 +
1186 +#include "ipkg_includes.h"
1187 +#include "ipkg_conf.h"
1188 +#include "ipkg_message.h"
1189 +
1190 +#define IPKG_PKG_EXTENSION ".ipk"
1191 +#define DPKG_PKG_EXTENSION ".deb"
1192 +
1193 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1194 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1195 +
1196 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1197 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1198 +#define IPKG_INFO_DIR_SUFFIX "info"
1199 +#define IPKG_STATUS_FILE_SUFFIX "status"
1200 +
1201 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1202 +
1203 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1204 +
1205 +#define IPKG_VERSION "0.99.154"
1206 +
1207 +
1208 +enum ipkg_error {
1209 + IPKG_SUCCESS = 0,
1210 + IPKG_PKG_DEPS_UNSATISFIED,
1211 + IPKG_PKG_IS_ESSENTIAL,
1212 + IPKG_PKG_HAS_DEPENDENTS,
1213 + IPKG_PKG_HAS_NO_CANDIDATE
1214 +};
1215 +typedef enum ipkg_error ipkg_error_t;
1216 +
1217 +extern int ipkg_state_changed;
1218 +
1219 +
1220 +struct errlist {
1221 + char * errmsg;
1222 + struct errlist * next;
1223 +} ;
1224 +
1225 +extern struct errlist* error_list;
1226 +
1227 +extern ipkg_conf_t *global_conf;
1228 +
1229 +#endif
1230 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_cmd.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_cmd.c
1231 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1232 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_cmd.c 2005-12-07 21:25:30.000000000 +0100
1233 @@ -0,0 +1,1344 @@
1234 +/* ipkg_cmd.c - the itsy package management system
1235 +
1236 + Carl D. Worth
1237 +
1238 + Copyright (C) 2001 University of Southern California
1239 +
1240 + This program is free software; you can redistribute it and/or
1241 + modify it under the terms of the GNU General Public License as
1242 + published by the Free Software Foundation; either version 2, or (at
1243 + your option) any later version.
1244 +
1245 + This program is distributed in the hope that it will be useful, but
1246 + WITHOUT ANY WARRANTY; without even the implied warranty of
1247 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1248 + General Public License for more details.
1249 +*/
1250 +
1251 +#include <string.h>
1252 +
1253 +#include "ipkg.h"
1254 +#include <libgen.h>
1255 +#include <glob.h>
1256 +#include <errno.h>
1257 +#include <stdlib.h>
1258 +#include <unistd.h>
1259 +#include <signal.h>
1260 +#include <stdio.h>
1261 +
1262 +#include "ipkg_conf.h"
1263 +#include "ipkg_cmd.h"
1264 +#include "ipkg_message.h"
1265 +#include "pkg.h"
1266 +#include "pkg_dest.h"
1267 +#include "pkg_parse.h"
1268 +#include "sprintf_alloc.h"
1269 +#include "pkg.h"
1270 +#include "file_util.h"
1271 +#include "str_util.h"
1272 +#include "libbb.h"
1273 +#include "unarchive.h"
1274 +
1275 +#include <fnmatch.h>
1276 +
1277 +
1278 +#include "ipkg_download.h"
1279 +#include "ipkg_install.h"
1280 +#include "ipkg_upgrade.h"
1281 +#include "ipkg_remove.h"
1282 +#include "ipkg_configure.h"
1283 +#include "ipkg_message.h"
1284 +
1285 +#ifdef IPKG_LIB
1286 +#include "libipkg.h"
1287 +static void *p_userdata = NULL;
1288 +#endif
1289 +
1290 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1291 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1292 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +
1316 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1317 + array for easier maintenance */
1318 +static ipkg_cmd_t cmds[] = {
1319 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1320 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1321 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1322 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1323 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1324 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1325 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1326 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1327 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1328 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1329 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1330 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1331 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1332 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1333 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1334 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1335 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1336 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1337 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1338 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1341 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1342 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1343 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1344 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1345 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1346 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1347 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1348 +};
1349 +
1350 +int ipkg_state_changed;
1351 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1352 +{
1353 + if (ipkg_state_changed && !conf->noaction) {
1354 + ipkg_message(conf, IPKG_INFO,
1355 + " writing status file\n");
1356 + ipkg_conf_write_status_files(conf);
1357 + pkg_write_changed_filelists(conf);
1358 + } else {
1359 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1360 + }
1361 +}
1362 +
1363 +
1364 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1365 +
1366 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1367 +{
1368 + int i;
1369 + ipkg_cmd_t *cmd;
1370 +
1371 + for (i=0; i < num_cmds; i++) {
1372 + cmd = &cmds[i];
1373 + if (strcmp(name, cmd->name) == 0) {
1374 + return cmd;
1375 + }
1376 + }
1377 +
1378 + return NULL;
1379 +}
1380 +
1381 +#ifdef IPKG_LIB
1382 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1383 +{
1384 + int result;
1385 + p_userdata = userdata;
1386 +
1387 +
1388 + result = (cmd->fun)(conf, argc, argv);
1389 + if ( result == 0 ) {
1390 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1391 + } else {
1392 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1393 +
1394 + }
1395 + if ( error_list ) {
1396 + reverse_error_list(&error_list);
1397 +
1398 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1399 + /* Here we print the errors collected and free the list */
1400 + while (error_list != NULL) {
1401 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1402 + error_list = error_list->next;
1403 +
1404 + }
1405 + free_error_list(&error_list);
1406 +
1407 + }
1408 +
1409 + p_userdata = NULL;
1410 + return result;
1411 +}
1412 +#else
1413 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1414 +{
1415 + return (cmd->fun)(conf, argc, argv);
1416 +}
1417 +#endif
1418 +
1419 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1420 +{
1421 + int err;
1422 + int failures;
1423 + char *lists_dir;
1424 + pkg_src_list_elt_t *iter;
1425 + pkg_src_t *src;
1426 +
1427 +
1428 + if (conf->offline_root) {
1429 + sprintf_alloc(&lists_dir, "%s/%s",
1430 + conf->offline_root,
1431 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1432 + } else {
1433 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1434 + }
1435 +
1436 + if (! file_is_dir(lists_dir)) {
1437 + if (file_exists(lists_dir)) {
1438 + ipkg_message(conf, IPKG_ERROR,
1439 + "%s: ERROR: %s exists, but is not a directory\n",
1440 + __FUNCTION__, lists_dir);
1441 + free(lists_dir);
1442 + return EINVAL;
1443 + }
1444 + err = file_mkdir_hier(lists_dir, 0755);
1445 + if (err) {
1446 + ipkg_message(conf, IPKG_ERROR,
1447 + "%s: ERROR: failed to make directory %s: %s\n",
1448 + __FUNCTION__, lists_dir, strerror(errno));
1449 + free(lists_dir);
1450 + return EINVAL;
1451 + }
1452 + }
1453 +
1454 + failures = 0;
1455 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1456 + char *url, *list_file_name;
1457 +
1458 + src = iter->data;
1459 +
1460 + if (src->extra_data) /* debian style? */
1461 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1462 + src->gzip ? "Packages.gz" : "Packages");
1463 + else
1464 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1465 +
1466 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1467 + if (src->gzip) {
1468 + char *tmp;
1469 + char *tmp_file_name;
1470 + FILE *in, *out;
1471 +
1472 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1473 +
1474 + if (mkdtemp (tmp) == NULL) {
1475 + perror ("mkdtemp");
1476 + failures++;
1477 + continue;
1478 + }
1479 +
1480 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1481 + err = ipkg_download(conf, url, tmp_file_name);
1482 + if (err == 0) {
1483 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1484 + in = fopen (tmp_file_name, "r");
1485 + out = fopen (list_file_name, "w");
1486 + if (in && out)
1487 + inflate_unzip (in, out);
1488 + else
1489 + err = 1;
1490 + if (in)
1491 + fclose (in);
1492 + if (out)
1493 + fclose (out);
1494 + unlink (tmp_file_name);
1495 + rmdir (tmp);
1496 + free (tmp);
1497 + }
1498 + } else
1499 + err = ipkg_download(conf, url, list_file_name);
1500 + if (err) {
1501 + failures++;
1502 + } else {
1503 + ipkg_message(conf, IPKG_NOTICE,
1504 + "Updated list of available packages in %s\n",
1505 + list_file_name);
1506 + }
1507 + free(url);
1508 + free(list_file_name);
1509 + }
1510 + free(lists_dir);
1511 +
1512 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1513 +#warning here
1514 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1515 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1516 + * -Jamey 3/1/03
1517 + */
1518 + {
1519 + int i;
1520 + int changed = 0;
1521 + pkg_vec_t *available = pkg_vec_alloc();
1522 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1523 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1524 + for (i = 0; i < available->len; i++) {
1525 + pkg_t *pkg = available->pkgs[i];
1526 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1527 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1528 + pkg->state_want = SW_UNKNOWN;
1529 + changed = 1;
1530 + }
1531 + }
1532 + pkg_vec_free(available);
1533 + if (changed) {
1534 + write_status_files_if_changed(conf);
1535 + }
1536 + }
1537 +#endif
1538 +
1539 + return failures;
1540 +}
1541 +
1542 +
1543 +/* scan the args passed and cache the local filenames of the packages */
1544 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1545 +{
1546 + int i;
1547 + int err;
1548 +
1549 + /*
1550 + * First scan through package names/urls
1551 + * For any urls, download the packages and install in database.
1552 + * For any files, install package info in database.
1553 + */
1554 + for (i = 0; i < argc; i ++) {
1555 + char *filename = argv [i];
1556 + //char *tmp = basename (tmp);
1557 + //int tmplen = strlen (tmp);
1558 +
1559 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1560 + // continue;
1561 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1562 + // continue;
1563 +
1564 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1565 + if (err)
1566 + return err;
1567 + }
1568 + return 0;
1569 +}
1570 +
1571 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1572 +{
1573 + pkg_vec_t *all;
1574 + int i;
1575 + pkg_t *pkg;
1576 +
1577 + ipkg_message(conf, IPKG_INFO,
1578 + "Configuring unpacked packages\n");
1579 + fflush( stdout );
1580 +
1581 + all = pkg_vec_alloc();
1582 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1583 +
1584 + for(i = 0; i < all->len; i++) {
1585 + pkg = all->pkgs[i];
1586 +
1587 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1588 + continue;
1589 +
1590 + if (pkg->state_status == SS_UNPACKED) {
1591 + ipkg_message(conf, IPKG_NOTICE,
1592 + "Configuring %s\n", pkg->name);
1593 + fflush( stdout );
1594 + if (ipkg_configure(conf, pkg) == 0) {
1595 + pkg->state_status = SS_INSTALLED;
1596 + pkg->parent->state_status = SS_INSTALLED;
1597 + pkg->state_flag &= ~SF_PREFER;
1598 + }
1599 + }
1600 + }
1601 +
1602 + pkg_vec_free(all);
1603 + return 0;
1604 +}
1605 +
1606 +static void sigint_handler(int sig)
1607 +{
1608 + signal(sig, SIG_DFL);
1609 + ipkg_message(NULL, IPKG_NOTICE,
1610 + "ipkg: interrupted. writing out status database\n");
1611 + write_status_files_if_changed(global_conf);
1612 + exit(128 + sig);
1613 +}
1614 +
1615 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1616 +{
1617 + int i;
1618 + char *arg;
1619 + int err=0;
1620 +
1621 + global_conf = conf;
1622 + signal(SIGINT, sigint_handler);
1623 +
1624 + /*
1625 + * Now scan through package names and install
1626 + */
1627 + for (i=0; i < argc; i++) {
1628 + arg = argv[i];
1629 +
1630 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1631 + if (err != EINVAL && err != 0)
1632 + return err;
1633 + }
1634 + pkg_info_preinstall_check(conf);
1635 +
1636 + for (i=0; i < argc; i++) {
1637 + arg = argv[i];
1638 + if (conf->multiple_providers)
1639 + err = ipkg_install_multi_by_name(conf, arg);
1640 + else{
1641 + err = ipkg_install_by_name(conf, arg);
1642 + }
1643 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1644 + ipkg_message(conf, IPKG_ERROR,
1645 + "Cannot find package %s.\n"
1646 + "Check the spelling or perhaps run 'ipkg update'\n",
1647 + arg);
1648 + }
1649 + }
1650 +
1651 + /* recheck to verify that all dependences are satisfied */
1652 + if (0) ipkg_satisfy_all_dependences(conf);
1653 +
1654 + ipkg_configure_packages(conf, NULL);
1655 +
1656 + write_status_files_if_changed(conf);
1657 +
1658 + return err;
1659 +}
1660 +
1661 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1662 +{
1663 + int i;
1664 + pkg_t *pkg;
1665 + int err;
1666 +
1667 + global_conf = conf;
1668 + signal(SIGINT, sigint_handler);
1669 +
1670 + if (argc) {
1671 + for (i=0; i < argc; i++) {
1672 + char *arg = argv[i];
1673 +
1674 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1675 + if (err != EINVAL && err != 0)
1676 + return err;
1677 + }
1678 + pkg_info_preinstall_check(conf);
1679 +
1680 + for (i=0; i < argc; i++) {
1681 + char *arg = argv[i];
1682 + if (conf->restrict_to_default_dest) {
1683 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1684 + argv[i],
1685 + conf->default_dest);
1686 + if (pkg == NULL) {
1687 + ipkg_message(conf, IPKG_NOTICE,
1688 + "Package %s not installed in %s\n",
1689 + argv[i], conf->default_dest->name);
1690 + continue;
1691 + }
1692 + } else {
1693 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1694 + argv[i]);
1695 + }
1696 + if (pkg)
1697 + ipkg_upgrade_pkg(conf, pkg);
1698 + else {
1699 + ipkg_install_by_name(conf, arg);
1700 + }
1701 + }
1702 + } else {
1703 + pkg_vec_t *installed = pkg_vec_alloc();
1704 +
1705 + pkg_info_preinstall_check(conf);
1706 +
1707 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1708 + for (i = 0; i < installed->len; i++) {
1709 + pkg = installed->pkgs[i];
1710 + ipkg_upgrade_pkg(conf, pkg);
1711 + }
1712 + pkg_vec_free(installed);
1713 + }
1714 +
1715 + /* recheck to verify that all dependences are satisfied */
1716 + if (0) ipkg_satisfy_all_dependences(conf);
1717 +
1718 + ipkg_configure_packages(conf, NULL);
1719 +
1720 + write_status_files_if_changed(conf);
1721 +
1722 + return 0;
1723 +}
1724 +
1725 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1726 +{
1727 + int i, err;
1728 + char *arg;
1729 + pkg_t *pkg;
1730 +
1731 + pkg_info_preinstall_check(conf);
1732 + for (i = 0; i < argc; i++) {
1733 + arg = argv[i];
1734 +
1735 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1736 + if (pkg == NULL) {
1737 + ipkg_message(conf, IPKG_ERROR,
1738 + "Cannot find package %s.\n"
1739 + "Check the spelling or perhaps run 'ipkg update'\n",
1740 + arg);
1741 + continue;
1742 + }
1743 +
1744 + err = ipkg_download_pkg(conf, pkg, ".");
1745 +
1746 + if (err) {
1747 + ipkg_message(conf, IPKG_ERROR,
1748 + "Failed to download %s\n", pkg->name);
1749 + } else {
1750 + ipkg_message(conf, IPKG_NOTICE,
1751 + "Downloaded %s as %s\n",
1752 + pkg->name, pkg->local_filename);
1753 + }
1754 + }
1755 +
1756 + return 0;
1757 +}
1758 +
1759 +
1760 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1761 +{
1762 + int i ;
1763 + pkg_vec_t *available;
1764 + pkg_t *pkg;
1765 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1766 + char *newline;
1767 + char *pkg_name = NULL;
1768 + char *version_str;
1769 +
1770 + if (argc > 0) {
1771 + pkg_name = argv[0];
1772 + }
1773 + available = pkg_vec_alloc();
1774 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1775 + for (i=0; i < available->len; i++) {
1776 + pkg = available->pkgs[i];
1777 + /* if we have package name or pattern and pkg does not match, then skip it */
1778 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1779 + continue;
1780 + if (pkg->description) {
1781 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1782 + } else {
1783 + desc_short[0] = '\0';
1784 + }
1785 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1786 + newline = strchr(desc_short, '\n');
1787 + if (newline) {
1788 + *newline = '\0';
1789 + }
1790 +#ifndef IPKG_LIB
1791 + printf("%s - %s\n", pkg->name, desc_short);
1792 +#else
1793 + if (ipkg_cb_list) {
1794 + version_str = pkg_version_str_alloc(pkg);
1795 + ipkg_cb_list(pkg->name,desc_short,
1796 + version_str,
1797 + pkg->state_status,
1798 + p_userdata);
1799 + free(version_str);
1800 + }
1801 +#endif
1802 + }
1803 + pkg_vec_free(available);
1804 +
1805 + return 0;
1806 +}
1807 +
1808 +
1809 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1810 +{
1811 + int i ;
1812 + pkg_vec_t *available;
1813 + pkg_t *pkg;
1814 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1815 + char *newline;
1816 + char *pkg_name = NULL;
1817 + char *version_str;
1818 +
1819 + if (argc > 0) {
1820 + pkg_name = argv[0];
1821 + }
1822 + available = pkg_vec_alloc();
1823 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1824 + for (i=0; i < available->len; i++) {
1825 + pkg = available->pkgs[i];
1826 + /* if we have package name or pattern and pkg does not match, then skip it */
1827 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1828 + continue;
1829 + if (pkg->description) {
1830 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1831 + } else {
1832 + desc_short[0] = '\0';
1833 + }
1834 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1835 + newline = strchr(desc_short, '\n');
1836 + if (newline) {
1837 + *newline = '\0';
1838 + }
1839 +#ifndef IPKG_LIB
1840 + printf("%s - %s\n", pkg->name, desc_short);
1841 +#else
1842 + if (ipkg_cb_list) {
1843 + version_str = pkg_version_str_alloc(pkg);
1844 + ipkg_cb_list(pkg->name,desc_short,
1845 + version_str,
1846 + pkg->state_status,
1847 + p_userdata);
1848 + free(version_str);
1849 + }
1850 +#endif
1851 + }
1852 +
1853 + return 0;
1854 +}
1855 +
1856 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1857 +{
1858 + int i;
1859 + pkg_vec_t *available;
1860 + pkg_t *pkg;
1861 + char *pkg_name = NULL;
1862 + char **pkg_fields = NULL;
1863 + int n_fields = 0;
1864 + char *buff ; // = (char *)malloc(1);
1865 +
1866 + if (argc > 0) {
1867 + pkg_name = argv[0];
1868 + }
1869 + if (argc > 1) {
1870 + pkg_fields = &argv[1];
1871 + n_fields = argc - 1;
1872 + }
1873 +
1874 + available = pkg_vec_alloc();
1875 + if (installed_only)
1876 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1877 + else
1878 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1879 + for (i=0; i < available->len; i++) {
1880 + pkg = available->pkgs[i];
1881 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1882 + continue;
1883 + }
1884 +#ifndef IPKG_LIB
1885 + if (n_fields) {
1886 + for (j = 0; j < n_fields; j++)
1887 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1888 + } else {
1889 + pkg_print_info(pkg, stdout);
1890 + }
1891 +#else
1892 +
1893 + buff = pkg_formatted_info(pkg);
1894 + if ( buff ) {
1895 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1896 + pkg->state_status,
1897 + buff,
1898 + p_userdata);
1899 +/*
1900 + We should not forget that actually the pointer is allocated.
1901 + We need to free it :) ( Thanks florian for seeing the error )
1902 +*/
1903 + free(buff);
1904 + }
1905 +#endif
1906 + if (conf->verbosity > 1) {
1907 + conffile_list_elt_t *iter;
1908 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1909 + conffile_t *cf = iter->data;
1910 + int modified = conffile_has_been_modified(conf, cf);
1911 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1912 + cf->name, cf->value, modified);
1913 + }
1914 + }
1915 + }
1916 +#ifndef IPKG_LIB
1917 + if (buff)
1918 + free(buff);
1919 +#endif
1920 + pkg_vec_free(available);
1921 +
1922 + return 0;
1923 +}
1924 +
1925 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1926 +{
1927 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1928 +}
1929 +
1930 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1931 +{
1932 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1933 +}
1934 +
1935 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1936 +{
1937 +
1938 + int err;
1939 + if (argc > 0) {
1940 + char *pkg_name = NULL;
1941 +
1942 + pkg_name = argv[0];
1943 +
1944 + err = ipkg_configure_packages (conf, pkg_name);
1945 +
1946 + } else {
1947 + err = ipkg_configure_packages (conf, NULL);
1948 + }
1949 +
1950 + write_status_files_if_changed(conf);
1951 +
1952 + return err;
1953 +}
1954 +
1955 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1956 +{
1957 + int i, err;
1958 + char *globpattern;
1959 + glob_t globbuf;
1960 +
1961 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1962 + err = glob(globpattern, 0, NULL, &globbuf);
1963 + free(globpattern);
1964 + if (err) {
1965 + return 0;
1966 + }
1967 +
1968 + ipkg_message(conf, IPKG_NOTICE,
1969 + "The following packages in %s will now be installed.\n",
1970 + conf->pending_dir);
1971 + for (i = 0; i < globbuf.gl_pathc; i++) {
1972 + ipkg_message(conf, IPKG_NOTICE,
1973 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1974 + }
1975 + ipkg_message(conf, IPKG_NOTICE, "\n");
1976 + for (i = 0; i < globbuf.gl_pathc; i++) {
1977 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1978 + if (err == 0) {
1979 + err = unlink(globbuf.gl_pathv[i]);
1980 + if (err) {
1981 + ipkg_message(conf, IPKG_ERROR,
1982 + "%s: ERROR: failed to unlink %s: %s\n",
1983 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1984 + return err;
1985 + }
1986 + }
1987 + }
1988 + globfree(&globbuf);
1989 +
1990 + return err;
1991 +}
1992 +
1993 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1994 +{
1995 + int i,a,done;
1996 + pkg_t *pkg;
1997 + pkg_t *pkg_to_remove;
1998 + pkg_vec_t *available;
1999 + char *pkg_name = NULL;
2000 + global_conf = conf;
2001 + signal(SIGINT, sigint_handler);
2002 +
2003 +// ENH: Add the "no pkg removed" just in case.
2004 +
2005 + done = 0;
2006 +
2007 + available = pkg_vec_alloc();
2008 + pkg_info_preinstall_check(conf);
2009 + if ( argc > 0 ) {
2010 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2011 + for (i=0; i < argc; i++) {
2012 + pkg_name = malloc(strlen(argv[i])+2);
2013 + strcpy(pkg_name,argv[i]);
2014 + for (a=0; a < available->len; a++) {
2015 + pkg = available->pkgs[a];
2016 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2017 + continue;
2018 + }
2019 + if (conf->restrict_to_default_dest) {
2020 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2021 + pkg->name,
2022 + conf->default_dest);
2023 + } else {
2024 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2025 + }
2026 +
2027 + if (pkg == NULL) {
2028 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2029 + continue;
2030 + }
2031 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2032 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2033 + continue;
2034 + }
2035 + ipkg_remove_pkg(conf, pkg_to_remove);
2036 + done = 1;
2037 + }
2038 + free (pkg_name);
2039 + }
2040 + pkg_vec_free(available);
2041 + } else {
2042 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2043 + int i;
2044 + int flagged_pkg_count = 0;
2045 + int removed;
2046 +
2047 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2048 +
2049 + for (i = 0; i < installed_pkgs->len; i++) {
2050 + pkg_t *pkg = installed_pkgs->pkgs[i];
2051 + if (pkg->state_flag & SF_USER) {
2052 + flagged_pkg_count++;
2053 + } else {
2054 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2055 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2056 + }
2057 + }
2058 + if (!flagged_pkg_count) {
2059 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2060 + "so refusing to uninstall unflagged non-leaf packages\n");
2061 + return 0;
2062 + }
2063 +
2064 + /* find packages not flagged SF_USER (i.e., installed to
2065 + * satisfy a dependence) and not having any dependents, and
2066 + * remove them */
2067 + do {
2068 + removed = 0;
2069 + for (i = 0; i < installed_pkgs->len; i++) {
2070 + pkg_t *pkg = installed_pkgs->pkgs[i];
2071 + if (!(pkg->state_flag & SF_USER)
2072 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2073 + removed++;
2074 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2075 + ipkg_remove_pkg(conf, pkg);
2076 + done = 1;
2077 + }
2078 + }
2079 + } while (removed);
2080 + pkg_vec_free(installed_pkgs);
2081 + }
2082 +
2083 + if ( done == 0 )
2084 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2085 +
2086 + write_status_files_if_changed(conf);
2087 + return 0;
2088 +}
2089 +
2090 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2091 +{
2092 + int i;
2093 + pkg_t *pkg;
2094 +
2095 + global_conf = conf;
2096 + signal(SIGINT, sigint_handler);
2097 +
2098 + pkg_info_preinstall_check(conf);
2099 +
2100 + for (i=0; i < argc; i++) {
2101 + if (conf->restrict_to_default_dest) {
2102 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2103 + argv[i],
2104 + conf->default_dest);
2105 + } else {
2106 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2107 + }
2108 +
2109 + if (pkg == NULL) {
2110 + ipkg_message(conf, IPKG_ERROR,
2111 + "Package %s is not installed.\n", argv[i]);
2112 + continue;
2113 + }
2114 + ipkg_purge_pkg(conf, pkg);
2115 + }
2116 +
2117 + write_status_files_if_changed(conf);
2118 + return 0;
2119 +}
2120 +
2121 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2122 +{
2123 + int i;
2124 + pkg_t *pkg;
2125 + const char *flags = argv[0];
2126 +
2127 + global_conf = conf;
2128 + signal(SIGINT, sigint_handler);
2129 +
2130 + for (i=1; i < argc; i++) {
2131 + if (conf->restrict_to_default_dest) {
2132 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2133 + argv[i],
2134 + conf->default_dest);
2135 + } else {
2136 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2137 + }
2138 +
2139 + if (pkg == NULL) {
2140 + ipkg_message(conf, IPKG_ERROR,
2141 + "Package %s is not installed.\n", argv[i]);
2142 + continue;
2143 + }
2144 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2145 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2146 + pkg->state_flag = pkg_state_flag_from_str(flags);
2147 + }
2148 +/* pb_ asked this feature 03292004 */
2149 +/* Actually I will use only this two, but this is an open for various status */
2150 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2151 + pkg->state_status = pkg_state_status_from_str(flags);
2152 + }
2153 + ipkg_state_changed++;
2154 + ipkg_message(conf, IPKG_NOTICE,
2155 + "Setting flags for package %s to %s\n",
2156 + pkg->name, flags);
2157 + }
2158 +
2159 + write_status_files_if_changed(conf);
2160 + return 0;
2161 +}
2162 +
2163 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2164 +{
2165 + pkg_t *pkg;
2166 + str_list_t *installed_files;
2167 + str_list_elt_t *iter;
2168 + char *pkg_version;
2169 + size_t buff_len = 8192;
2170 + size_t used_len;
2171 + char *buff ;
2172 +
2173 + buff = (char *)malloc(buff_len);
2174 + if ( buff == NULL ) {
2175 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2176 + return ENOMEM;
2177 + }
2178 +
2179 + if (argc < 1) {
2180 + return EINVAL;
2181 + }
2182 +
2183 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2184 + argv[0]);
2185 + if (pkg == NULL) {
2186 + ipkg_message(conf, IPKG_ERROR,
2187 + "Package %s not installed.\n", argv[0]);
2188 + return 0;
2189 + }
2190 +
2191 + installed_files = pkg_get_installed_files(pkg);
2192 + pkg_version = pkg_version_str_alloc(pkg);
2193 +
2194 +#ifndef IPKG_LIB
2195 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2196 + pkg->name, pkg_version, pkg->dest->name);
2197 + for (iter = installed_files->head; iter; iter = iter->next) {
2198 + puts(iter->data);
2199 + }
2200 +#else
2201 + if (buff) {
2202 + try_again:
2203 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2204 + pkg->name, pkg_version, pkg->dest->name) + 1;
2205 + if (used_len > buff_len) {
2206 + buff_len *= 2;
2207 + buff = realloc (buff, buff_len);
2208 + goto try_again;
2209 + }
2210 + for (iter = installed_files->head; iter; iter = iter->next) {
2211 + used_len += strlen (iter->data) + 1;
2212 + while (buff_len <= used_len) {
2213 + buff_len *= 2;
2214 + buff = realloc (buff, buff_len);
2215 + }
2216 + strncat(buff, iter->data, buff_len);
2217 + strncat(buff, "\n", buff_len);
2218 + }
2219 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2220 + buff,
2221 + pkg_version_str_alloc(pkg),
2222 + pkg->state_status,
2223 + p_userdata);
2224 + free(buff);
2225 + }
2226 +#endif
2227 +
2228 + free(pkg_version);
2229 + pkg_free_installed_files(pkg);
2230 +
2231 + return 0;
2232 +}
2233 +
2234 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2235 +{
2236 +
2237 + if (argc > 0) {
2238 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2239 + const char *rel_str = "depends on";
2240 + int i;
2241 +
2242 + pkg_info_preinstall_check(conf);
2243 +
2244 + if (conf->query_all)
2245 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2246 + else
2247 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2248 + for (i = 0; i < argc; i++) {
2249 + const char *target = argv[i];
2250 + int j;
2251 +
2252 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2253 +
2254 + for (j = 0; j < available_pkgs->len; j++) {
2255 + pkg_t *pkg = available_pkgs->pkgs[j];
2256 + if (fnmatch(target, pkg->name, 0) == 0) {
2257 + int k;
2258 + int count = pkg->depends_count + pkg->pre_depends_count;
2259 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2260 + target, pkg->architecture, rel_str);
2261 + for (k = 0; k < count; k++) {
2262 + compound_depend_t *cdepend = &pkg->depends[k];
2263 + int l;
2264 + for (l = 0; l < cdepend->possibility_count; l++) {
2265 + depend_t *possibility = cdepend->possibilities[l];
2266 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2267 + if (conf->verbosity > 0) {
2268 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2269 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2270 + if (possibility->version) {
2271 + char *typestr = NULL;
2272 + switch (possibility->constraint) {
2273 + case NONE: typestr = "none"; break;
2274 + case EARLIER: typestr = "<"; break;
2275 + case EARLIER_EQUAL: typestr = "<="; break;
2276 + case EQUAL: typestr = "="; break;
2277 + case LATER_EQUAL: typestr = ">="; break;
2278 + case LATER: typestr = ">"; break;
2279 + }
2280 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2281 + }
2282 + // free(ver);
2283 + }
2284 + ipkg_message(conf, IPKG_ERROR, "\n");
2285 + }
2286 + }
2287 + }
2288 + }
2289 + }
2290 + pkg_vec_free(available_pkgs);
2291 + }
2292 + return 0;
2293 +}
2294 +
2295 +enum what_field_type {
2296 + WHATDEPENDS,
2297 + WHATCONFLICTS,
2298 + WHATPROVIDES,
2299 + WHATREPLACES,
2300 + WHATRECOMMENDS,
2301 + WHATSUGGESTS
2302 +};
2303 +
2304 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2305 +{
2306 +
2307 + if (argc > 0) {
2308 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2309 + const char *rel_str = NULL;
2310 + int i;
2311 + int changed;
2312 +
2313 + switch (what_field_type) {
2314 + case WHATDEPENDS: rel_str = "depends on"; break;
2315 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2316 + case WHATSUGGESTS: rel_str = "suggests"; break;
2317 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2318 + case WHATPROVIDES: rel_str = "provides"; break;
2319 + case WHATREPLACES: rel_str = "replaces"; break;
2320 + }
2321 +
2322 + if (conf->query_all)
2323 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2324 + else
2325 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2326 +
2327 + /* mark the root set */
2328 + pkg_vec_clear_marks(available_pkgs);
2329 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2330 + for (i = 0; i < argc; i++) {
2331 + const char *dependee_pattern = argv[i];
2332 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2333 + }
2334 + for (i = 0; i < available_pkgs->len; i++) {
2335 + pkg_t *pkg = available_pkgs->pkgs[i];
2336 + if (pkg->state_flag & SF_MARKED) {
2337 + /* mark the parent (abstract) package */
2338 + pkg_mark_provides(pkg);
2339 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2340 + }
2341 + }
2342 +
2343 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2344 + do {
2345 + int j;
2346 + changed = 0;
2347 +
2348 + for (j = 0; j < available_pkgs->len; j++) {
2349 + pkg_t *pkg = available_pkgs->pkgs[j];
2350 + int k;
2351 + int count = ((what_field_type == WHATCONFLICTS)
2352 + ? pkg->conflicts_count
2353 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2354 + /* skip this package if it is already marked */
2355 + if (pkg->parent->state_flag & SF_MARKED) {
2356 + continue;
2357 + }
2358 + for (k = 0; k < count; k++) {
2359 + compound_depend_t *cdepend =
2360 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2361 + int l;
2362 + for (l = 0; l < cdepend->possibility_count; l++) {
2363 + depend_t *possibility = cdepend->possibilities[l];
2364 + if (possibility->pkg->state_flag & SF_MARKED) {
2365 + /* mark the depending package so we won't visit it again */
2366 + pkg->state_flag |= SF_MARKED;
2367 + pkg_mark_provides(pkg);
2368 + changed++;
2369 +
2370 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2371 + if (conf->verbosity > 0) {
2372 + char *ver = pkg_version_str_alloc(pkg);
2373 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2374 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2375 + if (possibility->version) {
2376 + char *typestr = NULL;
2377 + switch (possibility->constraint) {
2378 + case NONE: typestr = "none"; break;
2379 + case EARLIER: typestr = "<"; break;
2380 + case EARLIER_EQUAL: typestr = "<="; break;
2381 + case EQUAL: typestr = "="; break;
2382 + case LATER_EQUAL: typestr = ">="; break;
2383 + case LATER: typestr = ">"; break;
2384 + }
2385 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2386 + }
2387 + free(ver);
2388 + if (!pkg_dependence_satisfiable(conf, possibility))
2389 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2390 + }
2391 + ipkg_message(conf, IPKG_NOTICE, "\n");
2392 + goto next_package;
2393 + }
2394 + }
2395 + }
2396 + next_package:
2397 + ;
2398 + }
2399 + } while (changed && recursive);
2400 + pkg_vec_free(available_pkgs);
2401 + }
2402 +
2403 + return 0;
2404 +}
2405 +
2406 +int pkg_mark_provides(pkg_t *pkg)
2407 +{
2408 + int provides_count = pkg->provides_count;
2409 + abstract_pkg_t **provides = pkg->provides;
2410 + int i;
2411 + pkg->parent->state_flag |= SF_MARKED;
2412 + for (i = 0; i < provides_count; i++) {
2413 + provides[i]->state_flag |= SF_MARKED;
2414 + }
2415 + return 0;
2416 +}
2417 +
2418 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2419 +{
2420 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2421 +}
2422 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2423 +{
2424 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2425 +}
2426 +
2427 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2428 +{
2429 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2430 +}
2431 +
2432 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2433 +{
2434 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2435 +}
2436 +
2437 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2438 +{
2439 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2440 +}
2441 +
2442 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2443 +{
2444 +
2445 + if (argc > 0) {
2446 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2447 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2448 + int i;
2449 +
2450 + pkg_info_preinstall_check(conf);
2451 +
2452 + if (conf->query_all)
2453 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2454 + else
2455 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2456 + for (i = 0; i < argc; i++) {
2457 + const char *target = argv[i];
2458 + int j;
2459 +
2460 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2461 + rel_str, target);
2462 + for (j = 0; j < available_pkgs->len; j++) {
2463 + pkg_t *pkg = available_pkgs->pkgs[j];
2464 + int k;
2465 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2466 + for (k = 0; k < count; k++) {
2467 + abstract_pkg_t *apkg =
2468 + ((what_field_type == WHATPROVIDES)
2469 + ? pkg->provides[k]
2470 + : pkg->replaces[k]);
2471 + if (fnmatch(target, apkg->name, 0) == 0) {
2472 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2473 + if (strcmp(target, apkg->name) != 0)
2474 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2475 + ipkg_message(conf, IPKG_ERROR, "\n");
2476 + }
2477 + }
2478 + }
2479 + }
2480 + pkg_vec_free(available_pkgs);
2481 + }
2482 + return 0;
2483 +}
2484 +
2485 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2486 +{
2487 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2488 +}
2489 +
2490 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2491 +{
2492 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2493 +}
2494 +
2495 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2496 +{
2497 + int i;
2498 +
2499 + pkg_vec_t *installed;
2500 + pkg_t *pkg;
2501 + str_list_t *installed_files;
2502 + str_list_elt_t *iter;
2503 + char *installed_file;
2504 +
2505 + if (argc < 1) {
2506 + return EINVAL;
2507 + }
2508 +
2509 + installed = pkg_vec_alloc();
2510 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2511 +
2512 + for (i=0; i < installed->len; i++) {
2513 + pkg = installed->pkgs[i];
2514 +
2515 + installed_files = pkg_get_installed_files(pkg);
2516 +
2517 + for (iter = installed_files->head; iter; iter = iter->next) {
2518 + installed_file = iter->data;
2519 + if (fnmatch(argv[0], installed_file, 0)==0) {
2520 +#ifndef IPKG_LIB
2521 + printf("%s: %s\n", pkg->name, installed_file);
2522 +#else
2523 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2524 + installed_file,
2525 + pkg_version_str_alloc(pkg),
2526 + pkg->state_status, p_userdata);
2527 +#endif
2528 + }
2529 + }
2530 +
2531 + pkg_free_installed_files(pkg);
2532 + }
2533 +
2534 + /* XXX: CLEANUP: It's not obvious from the name of
2535 + pkg_hash_fetch_all_installed that we need to call
2536 + pkg_vec_free to avoid a memory leak. */
2537 + pkg_vec_free(installed);
2538 +
2539 + return 0;
2540 +}
2541 +
2542 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2543 +{
2544 + if (argc == 3) {
2545 + /* this is a bit gross */
2546 + struct pkg p1, p2;
2547 + parseVersion(&p1, argv[0]);
2548 + parseVersion(&p2, argv[2]);
2549 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2550 + } else {
2551 + ipkg_message(conf, IPKG_ERROR,
2552 + "ipkg compare_versions <v1> <op> <v2>\n"
2553 + "<op> is one of <= >= << >> =\n");
2554 + return -1;
2555 + }
2556 +}
2557 +
2558 +#ifndef HOST_CPU_STR
2559 +#define HOST_CPU_STR__(X) #X
2560 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2561 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2562 +#endif
2563 +
2564 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2565 +{
2566 + nv_pair_list_elt_t *l;
2567 +
2568 + l = conf->arch_list.head;
2569 + while (l) {
2570 + nv_pair_t *nv = l->data;
2571 + printf("arch %s %s\n", nv->name, nv->value);
2572 + l = l->next;
2573 + }
2574 + return 0;
2575 +}
2576 +
2577 +
2578 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_cmd.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_cmd.h
2579 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2580 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_cmd.h 2005-12-07 21:25:30.000000000 +0100
2581 @@ -0,0 +1,46 @@
2582 +/* ipkg_cmd.h - the itsy package management system
2583 +
2584 + Carl D. Worth
2585 +
2586 + Copyright (C) 2001 University of Southern California
2587 +
2588 + This program is free software; you can redistribute it and/or
2589 + modify it under the terms of the GNU General Public License as
2590 + published by the Free Software Foundation; either version 2, or (at
2591 + your option) any later version.
2592 +
2593 + This program is distributed in the hope that it will be useful, but
2594 + WITHOUT ANY WARRANTY; without even the implied warranty of
2595 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2596 + General Public License for more details.
2597 +*/
2598 +
2599 +#ifndef IPKG_CMD_H
2600 +#define IPKG_CMD_H
2601 +
2602 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2603 +
2604 +struct ipkg_cmd
2605 +{
2606 + char *name;
2607 + int requires_args;
2608 + ipkg_cmd_fun_t fun;
2609 +};
2610 +typedef struct ipkg_cmd ipkg_cmd_t;
2611 +
2612 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2613 +#ifdef IPKG_LIB
2614 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2615 + const char **argv, void *userdata);
2616 +#else
2617 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2618 +#endif
2619 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2620 +/* install any packges with state_want == SW_INSTALL */
2621 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2622 +/* ensure that all dependences are satisfied */
2623 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2624 +
2625 +int pkg_mark_provides(pkg_t *pkg);
2626 +
2627 +#endif
2628 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_conf.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_conf.c
2629 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2630 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_conf.c 2005-12-07 21:25:30.000000000 +0100
2631 @@ -0,0 +1,709 @@
2632 +/* ipkg_conf.c - the itsy package management system
2633 +
2634 + Carl D. Worth
2635 +
2636 + Copyright (C) 2001 University of Southern California
2637 +
2638 + This program is free software; you can redistribute it and/or
2639 + modify it under the terms of the GNU General Public License as
2640 + published by the Free Software Foundation; either version 2, or (at
2641 + your option) any later version.
2642 +
2643 + This program is distributed in the hope that it will be useful, but
2644 + WITHOUT ANY WARRANTY; without even the implied warranty of
2645 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2646 + General Public License for more details.
2647 +*/
2648 +
2649 +#include <glob.h>
2650 +
2651 +#include "ipkg.h"
2652 +#include "ipkg_conf.h"
2653 +
2654 +#include "xregex.h"
2655 +#include "sprintf_alloc.h"
2656 +#include "ipkg_conf.h"
2657 +#include "ipkg_message.h"
2658 +#include "file_util.h"
2659 +#include "str_util.h"
2660 +#include "xsystem.h"
2661 +
2662 +
2663 +ipkg_conf_t *global_conf;
2664 +
2665 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2666 + pkg_src_list_t *pkg_src_list,
2667 + nv_pair_list_t *tmp_dest_nv_pair_list,
2668 + char **tmp_lists_dir);
2669 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2670 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2671 + const char *name, const char *value);
2672 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2673 + const char *default_dest_name);
2674 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2675 + pkg_src_list_t *nv_pair_list);
2676 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2677 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2678 +
2679 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2680 +{
2681 + ipkg_option_t tmp[] = {
2682 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2683 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2684 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2685 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2686 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2687 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2688 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2689 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2690 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2691 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2692 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2693 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2694 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2695 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2696 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2697 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2698 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2699 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2700 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2701 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2702 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2703 + { NULL }
2704 + };
2705 +
2706 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2707 + if ( options == NULL ){
2708 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2709 + return -1;
2710 + }
2711 +
2712 + memcpy(*options, tmp, sizeof(tmp));
2713 + return 0;
2714 +};
2715 +
2716 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2717 +{
2718 + if (arg_str) {
2719 + if (*conf_str) {
2720 + free(*conf_str);
2721 + }
2722 + *conf_str = strdup(arg_str);
2723 + }
2724 +}
2725 +
2726 +static void ipkg_conf_free_string(char **conf_str)
2727 +{
2728 + if (*conf_str) {
2729 + free(*conf_str);
2730 + *conf_str = NULL;
2731 + }
2732 +}
2733 +
2734 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2735 +{
2736 + int err;
2737 + char *tmp_dir_base;
2738 + nv_pair_list_t tmp_dest_nv_pair_list;
2739 + char * lists_dir =NULL;
2740 + glob_t globbuf;
2741 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2742 + char *pending_dir =NULL;
2743 +
2744 + memset(conf, 0, sizeof(ipkg_conf_t));
2745 +
2746 + pkg_src_list_init(&conf->pkg_src_list);
2747 +
2748 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2749 + pkg_dest_list_init(&conf->pkg_dest_list);
2750 +
2751 + nv_pair_list_init(&conf->arch_list);
2752 +
2753 + conf->restrict_to_default_dest = 0;
2754 + conf->default_dest = NULL;
2755 +
2756 +
2757 + if (args->tmp_dir)
2758 + tmp_dir_base = args->tmp_dir;
2759 + else
2760 + tmp_dir_base = getenv("TMPDIR");
2761 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2762 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2763 + IPKG_CONF_TMP_DIR_SUFFIX);
2764 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2765 + if (conf->tmp_dir == NULL) {
2766 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2767 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2768 + return errno;
2769 + }
2770 +
2771 + conf->force_depends = 0;
2772 + conf->force_defaults = 0;
2773 + conf->force_overwrite = 0;
2774 + conf->force_downgrade = 0;
2775 + conf->force_reinstall = 0;
2776 + conf->force_space = 0;
2777 + conf->force_removal_of_essential_packages = 0;
2778 + conf->force_removal_of_dependent_packages = 0;
2779 + conf->nodeps = 0;
2780 + conf->verbose_wget = 0;
2781 + conf->offline_root = NULL;
2782 + conf->offline_root_pre_script_cmd = NULL;
2783 + conf->offline_root_post_script_cmd = NULL;
2784 + conf->multiple_providers = 0;
2785 + conf->verbosity = 1;
2786 + conf->noaction = 0;
2787 +
2788 + conf->http_proxy = NULL;
2789 + conf->ftp_proxy = NULL;
2790 + conf->no_proxy = NULL;
2791 + conf->proxy_user = NULL;
2792 + conf->proxy_passwd = NULL;
2793 +
2794 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2795 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2796 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + lists_dir=(char *)malloc(1);
2798 + lists_dir[0]='\0';
2799 + if (args->conf_file) {
2800 + struct stat stat_buf;
2801 + err = stat(args->conf_file, &stat_buf);
2802 + if (err == 0)
2803 + if (ipkg_conf_parse_file(conf, args->conf_file,
2804 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2805 + /* Memory leakage from ipkg_conf_parse-file */
2806 + return -1;
2807 + }
2808 +
2809 + }
2810 +
2811 + /* if (!lists_dir ){*/
2812 + if (strlen(lists_dir)<=1 ){
2813 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2814 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2815 + }
2816 +
2817 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2818 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2819 +
2820 + conf->lists_dir = strdup(lists_dir);
2821 + conf->pending_dir = strdup(pending_dir);
2822 +
2823 + if (args->offline_root)
2824 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2825 + memset(&globbuf, 0, sizeof(globbuf));
2826 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2827 + if (!err) {
2828 + int i;
2829 + for (i = 0; i < globbuf.gl_pathc; i++) {
2830 + if (globbuf.gl_pathv[i])
2831 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2832 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2833 + /* Memory leakage from ipkg_conf_parse-file */
2834 + return -1;
2835 + }
2836 + }
2837 + }
2838 + globfree(&globbuf);
2839 +
2840 + /* if no architectures were defined, then default all, noarch, and host architecture */
2841 + if (nv_pair_list_empty(&conf->arch_list)) {
2842 + nv_pair_list_append(&conf->arch_list, "all", "1");
2843 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2844 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2845 + }
2846 +
2847 + /* Even if there is no conf file, we'll need at least one dest. */
2848 + if (tmp_dest_nv_pair_list.head == NULL) {
2849 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2850 + IPKG_CONF_DEFAULT_DEST_NAME,
2851 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2852 + }
2853 +
2854 + /* After parsing the file, set options from command-line, (so that
2855 + command-line arguments take precedence) */
2856 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2857 + really needs to be cleaned up. There is so much duplication
2858 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2859 + a pointer to args_t (which could then not be freed), rather
2860 + than duplicating every field here? */
2861 + if (args->force_depends) {
2862 + conf->force_depends = 1;
2863 + }
2864 + if (args->force_defaults) {
2865 + conf->force_defaults = 1;
2866 + }
2867 + if (args->force_overwrite) {
2868 + conf->force_overwrite = 1;
2869 + }
2870 + if (args->force_downgrade) {
2871 + conf->force_downgrade = 1;
2872 + }
2873 + if (args->force_reinstall) {
2874 + conf->force_reinstall = 1;
2875 + }
2876 + if (args->force_removal_of_dependent_packages) {
2877 + conf->force_removal_of_dependent_packages = 1;
2878 + }
2879 + if (args->force_removal_of_essential_packages) {
2880 + conf->force_removal_of_essential_packages = 1;
2881 + }
2882 + if (args->nodeps) {
2883 + conf->nodeps = 1;
2884 + }
2885 + if (args->noaction) {
2886 + conf->noaction = 1;
2887 + }
2888 + if (args->query_all) {
2889 + conf->query_all = 1;
2890 + }
2891 + if (args->verbose_wget) {
2892 + conf->verbose_wget = 1;
2893 + }
2894 + if (args->multiple_providers) {
2895 + conf->multiple_providers = 1;
2896 + }
2897 + if (args->verbosity != conf->verbosity) {
2898 + conf->verbosity = args->verbosity;
2899 + }
2900 +
2901 + ipkg_conf_override_string(&conf->offline_root,
2902 + args->offline_root);
2903 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2904 + args->offline_root_pre_script_cmd);
2905 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2906 + args->offline_root_post_script_cmd);
2907 +
2908 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2909 + read anything from there.
2910 +*/
2911 + if ( !(args->nocheckfordirorfile)){
2912 + /* need to run load the source list before dest list -Jamey */
2913 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2914 +
2915 + /* Now that we have resolved conf->offline_root, we can commit to
2916 + the directory names for the dests and load in all the package
2917 + lists. */
2918 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2919 +
2920 + if (args->dest) {
2921 + err = ipkg_conf_set_default_dest(conf, args->dest);
2922 + if (err) {
2923 + return err;
2924 + }
2925 + }
2926 + }
2927 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2928 + free(lists_dir);
2929 + free(pending_dir);
2930 +
2931 + return 0;
2932 +}
2933 +
2934 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2935 +{
2936 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2937 +#error
2938 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2939 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2940 + __FUNCTION__, conf->tmp_dir);
2941 +#else
2942 + int err;
2943 +
2944 + err = rmdir(conf->tmp_dir);
2945 + if (err) {
2946 + if (errno == ENOTEMPTY) {
2947 + char *cmd;
2948 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2949 + err = xsystem(cmd);
2950 + free(cmd);
2951 + }
2952 + if (err)
2953 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2954 + }
2955 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2956 +
2957 + free(conf->tmp_dir); /*XXX*/
2958 +
2959 + pkg_src_list_deinit(&conf->pkg_src_list);
2960 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2961 + nv_pair_list_deinit(&conf->arch_list);
2962 + if (&conf->pkg_hash)
2963 + pkg_hash_deinit(&conf->pkg_hash);
2964 + if (&conf->file_hash)
2965 + hash_table_deinit(&conf->file_hash);
2966 + if (&conf->obs_file_hash)
2967 + hash_table_deinit(&conf->obs_file_hash);
2968 +
2969 + ipkg_conf_free_string(&conf->offline_root);
2970 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2971 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2972 +
2973 + if (conf->verbosity > 1) {
2974 + int i;
2975 + hash_table_t *hashes[] = {
2976 + &conf->pkg_hash,
2977 + &conf->file_hash,
2978 + &conf->obs_file_hash };
2979 + for (i = 0; i < 3; i++) {
2980 + hash_table_t *hash = hashes[i];
2981 + int c = 0;
2982 + int n_conflicts = 0;
2983 + int j;
2984 + for (j = 0; j < hash->n_entries; j++) {
2985 + int len = 0;
2986 + hash_entry_t *e = &hash->entries[j];
2987 + if (e->next)
2988 + n_conflicts++;
2989 + while (e && e->key) {
2990 + len++;
2991 + e = e->next;
2992 + }
2993 + if (len > c)
2994 + c = len;
2995 + }
2996 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2997 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2998 + hash_table_deinit(hash);
2999 + }
3000 + }
3001 +}
3002 +
3003 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3004 + const char *default_dest_name)
3005 +{
3006 + pkg_dest_list_elt_t *iter;
3007 + pkg_dest_t *dest;
3008 +
3009 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3010 + dest = iter->data;
3011 + if (strcmp(dest->name, default_dest_name) == 0) {
3012 + conf->default_dest = dest;
3013 + conf->restrict_to_default_dest = 1;
3014 + return 0;
3015 + }
3016 + }
3017 +
3018 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3019 +
3020 + return 1;
3021 +}
3022 +
3023 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3024 +{
3025 + pkg_src_list_elt_t *iter;
3026 + pkg_src_t *src;
3027 + char *list_file;
3028 +
3029 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3030 + src = iter->data;
3031 + if (src == NULL) {
3032 + continue;
3033 + }
3034 + if (conf->offline_root) {
3035 + sprintf_alloc(&list_file, "%s/%s/%s",
3036 + conf->offline_root,
3037 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3038 + src->name);
3039 + } else {
3040 + sprintf_alloc(&list_file, "%s/%s",
3041 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3042 + src->name);
3043 + }
3044 +
3045 + if (file_exists(list_file)) {
3046 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3047 + }
3048 + free(list_file);
3049 + }
3050 +
3051 + return 0;
3052 +}
3053 +
3054 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3055 +{
3056 + nv_pair_list_elt_t *iter;
3057 + nv_pair_t *nv_pair;
3058 + pkg_dest_t *dest;
3059 + char *root_dir;
3060 +
3061 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3062 + nv_pair = iter->data;
3063 +
3064 + if (conf->offline_root) {
3065 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3066 + } else {
3067 + root_dir = strdup(nv_pair->value);
3068 + }
3069 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3070 + free(root_dir);
3071 + if (dest == NULL) {
3072 + continue;
3073 + }
3074 + if (conf->default_dest == NULL) {
3075 + conf->default_dest = dest;
3076 + }
3077 + if (file_exists(dest->status_file_name)) {
3078 + pkg_hash_add_from_file(conf, dest->status_file_name,
3079 + NULL, dest, 1);
3080 + }
3081 + }
3082 +
3083 + return 0;
3084 +}
3085 +
3086 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3087 + pkg_src_list_t *pkg_src_list,
3088 + nv_pair_list_t *tmp_dest_nv_pair_list,
3089 + char **lists_dir)
3090 +{
3091 + ipkg_option_t * options;
3092 + FILE *file = fopen(filename, "r");
3093 + regex_t valid_line_re, comment_re;
3094 +#define regmatch_size 12
3095 + regmatch_t regmatch[regmatch_size];
3096 +
3097 + if (ipkg_init_options_array(conf, &options)<0)
3098 + return ENOMEM;
3099 +
3100 + if (file == NULL) {
3101 + fprintf(stderr, "%s: failed to open %s: %s\n",
3102 + __FUNCTION__, filename, strerror(errno));
3103 + free(options);
3104 + return errno;
3105 + }
3106 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3107 +
3108 + xregcomp(&comment_re,
3109 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3110 + REG_EXTENDED);
3111 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3112 +
3113 + while(1) {
3114 + int line_num = 0;
3115 + char *line;
3116 + char *type, *name, *value, *extra;
3117 +
3118 + line = file_read_line_alloc(file);
3119 + line_num++;
3120 + if (line == NULL) {
3121 + break;
3122 + }
3123 +
3124 + str_chomp(line);
3125 +
3126 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3127 + goto NEXT_LINE;
3128 + }
3129 +
3130 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3131 + str_chomp(line);
3132 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3133 + filename, line_num, line);
3134 + goto NEXT_LINE;
3135 + }
3136 +
3137 + /* This has to be so ugly to deal with optional quotation marks */
3138 + if (regmatch[2].rm_so > 0) {
3139 + type = strndup(line + regmatch[2].rm_so,
3140 + regmatch[2].rm_eo - regmatch[2].rm_so);
3141 + } else {
3142 + type = strndup(line + regmatch[3].rm_so,
3143 + regmatch[3].rm_eo - regmatch[3].rm_so);
3144 + }
3145 + if (regmatch[5].rm_so > 0) {
3146 + name = strndup(line + regmatch[5].rm_so,
3147 + regmatch[5].rm_eo - regmatch[5].rm_so);
3148 + } else {
3149 + name = strndup(line + regmatch[6].rm_so,
3150 + regmatch[6].rm_eo - regmatch[6].rm_so);
3151 + }
3152 + if (regmatch[8].rm_so > 0) {
3153 + value = strndup(line + regmatch[8].rm_so,
3154 + regmatch[8].rm_eo - regmatch[8].rm_so);
3155 + } else {
3156 + value = strndup(line + regmatch[9].rm_so,
3157 + regmatch[9].rm_eo - regmatch[9].rm_so);
3158 + }
3159 + extra = NULL;
3160 + if (regmatch[11].rm_so > 0) {
3161 + extra = strndup (line + regmatch[11].rm_so,
3162 + regmatch[11].rm_eo - regmatch[11].rm_so);
3163 + }
3164 +
3165 + /* We use the tmp_dest_nv_pair_list below instead of
3166 + conf->pkg_dest_list because we might encounter an
3167 + offline_root option later and that would invalidate the
3168 + directories we would have computed in
3169 + pkg_dest_list_init. (We do a similar thing with
3170 + tmp_src_nv_pair_list for sake of symmetry.) */
3171 + if (strcmp(type, "option") == 0) {
3172 + ipkg_conf_set_option(options, name, value);
3173 + } else if (strcmp(type, "src") == 0) {
3174 + if (!nv_pair_list_find(pkg_src_list, name)) {
3175 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3176 + } else {
3177 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3178 + name, value);
3179 + }
3180 + } else if (strcmp(type, "src/gz") == 0) {
3181 + if (!nv_pair_list_find(pkg_src_list, name)) {
3182 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3183 + } else {
3184 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3185 + name, value);
3186 + }
3187 + } else if (strcmp(type, "dest") == 0) {
3188 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3189 + } else if (strcmp(type, "lists_dir") == 0) {
3190 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3191 + if (*lists_dir == NULL) {
3192 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3193 + free(options);
3194 + return EINVAL;
3195 + }
3196 + sprintf (*lists_dir,"%s",value);
3197 + } else if (strcmp(type, "arch") == 0) {
3198 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3199 + if (!value) {
3200 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3201 + value = strdup("10");
3202 + }
3203 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3204 + } else {
3205 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3206 + "parameter: %s %s %s\n", type, name, value);
3207 + free(options);
3208 + return EINVAL;
3209 + }
3210 +
3211 + free(type);
3212 + free(name);
3213 + free(value);
3214 + if (extra)
3215 + free (extra);
3216 +
3217 + NEXT_LINE:
3218 + free(line);
3219 + }
3220 +
3221 + free(options);
3222 + regfree(&comment_re);
3223 + regfree(&valid_line_re);
3224 + fclose(file);
3225 +
3226 + return 0;
3227 +}
3228 +
3229 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3230 + const char *name, const char *value)
3231 +{
3232 + int i = 0;
3233 + while (options[i].name) {
3234 + if (strcmp(options[i].name, name) == 0) {
3235 + switch (options[i].type) {
3236 + case IPKG_OPT_TYPE_BOOL:
3237 + *((int *)options[i].value) = 1;
3238 + return 0;
3239 + case IPKG_OPT_TYPE_INT:
3240 + if (value) {
3241 + *((int *)options[i].value) = atoi(value);
3242 + return 0;
3243 + } else {
3244 + printf("%s: Option %s need an argument\n",
3245 + __FUNCTION__, name);
3246 + return EINVAL;
3247 + }
3248 + case IPKG_OPT_TYPE_STRING:
3249 + if (value) {
3250 + *((char **)options[i].value) = strdup(value);
3251 + return 0;
3252 + } else {
3253 + printf("%s: Option %s need an argument\n",
3254 + __FUNCTION__, name);
3255 + return EINVAL;
3256 + }
3257 + }
3258 + }
3259 + i++;
3260 + }
3261 +
3262 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3263 + __FUNCTION__, name, value);
3264 + return EINVAL;
3265 +}
3266 +
3267 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3268 +{
3269 + pkg_dest_list_elt_t *iter;
3270 + pkg_dest_t *dest;
3271 + pkg_vec_t *all;
3272 + pkg_t *pkg;
3273 + register int i;
3274 + int err;
3275 +
3276 + if (conf->noaction)
3277 + return 0;
3278 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3279 + dest = iter->data;
3280 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3281 + if (dest->status_file == NULL) {
3282 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3283 + __FUNCTION__, dest->status_file_name, strerror(errno));
3284 + }
3285 + }
3286 +
3287 + all = pkg_vec_alloc();
3288 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3289 +
3290 + for(i = 0; i < all->len; i++) {
3291 + pkg = all->pkgs[i];
3292 + /* We don't need most uninstalled packages in the status file */
3293 + if (pkg->state_status == SS_NOT_INSTALLED
3294 + && (pkg->state_want == SW_UNKNOWN
3295 + || pkg->state_want == SW_DEINSTALL
3296 + || pkg->state_want == SW_PURGE)) {
3297 + continue;
3298 + }
3299 + if (!pkg) {
3300 + fprintf(stderr, "Null package\n");
3301 + }
3302 + if (pkg->dest == NULL) {
3303 + fprintf(stderr, "%s: ERROR: Can't write status for "
3304 + "package %s since it has a NULL dest\n",
3305 + __FUNCTION__, pkg->name);
3306 + continue;
3307 + }
3308 + if (pkg->dest->status_file) {
3309 + pkg_print_status(pkg, pkg->dest->status_file);
3310 + }
3311 + }
3312 +
3313 + pkg_vec_free(all);
3314 +
3315 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3316 + dest = iter->data;
3317 + if (dest->status_file) {
3318 + err = ferror(dest->status_file);
3319 + fclose(dest->status_file);
3320 + dest->status_file = NULL;
3321 + if (!err) {
3322 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3323 + } else {
3324 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3325 + "retaining old %s\n", __FUNCTION__,
3326 + dest->status_file_tmp_name, dest->status_file_name);
3327 + }
3328 + }
3329 + }
3330 +
3331 + return 0;
3332 +}
3333 +
3334 +
3335 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3336 +{
3337 + char *root_filename;
3338 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3339 + return root_filename;
3340 +}
3341 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_conf.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_conf.h
3342 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3343 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_conf.h 2005-12-07 21:25:30.000000000 +0100
3344 @@ -0,0 +1,107 @@
3345 +/* ipkg_conf.h - the itsy package management system
3346 +
3347 + Carl D. Worth
3348 +
3349 + Copyright (C) 2001 University of Southern California
3350 +
3351 + This program is free software; you can redistribute it and/or
3352 + modify it under the terms of the GNU General Public License as
3353 + published by the Free Software Foundation; either version 2, or (at
3354 + your option) any later version.
3355 +
3356 + This program is distributed in the hope that it will be useful, but
3357 + WITHOUT ANY WARRANTY; without even the implied warranty of
3358 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3359 + General Public License for more details.
3360 +*/
3361 +
3362 +#ifndef IPKG_CONF_H
3363 +#define IPKG_CONF_H
3364 +
3365 +typedef struct ipkg_conf ipkg_conf_t;
3366 +
3367 +#include "hash_table.h"
3368 +#include "ipkg.h"
3369 +#include "args.h"
3370 +#include "pkg.h"
3371 +#include "pkg_hash.h"
3372 +#include "pkg_src_list.h"
3373 +#include "pkg_dest_list.h"
3374 +#include "nv_pair_list.h"
3375 +
3376 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3377 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3378 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3379 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3380 +
3381 +/* In case the config file defines no dest */
3382 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3383 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3384 +
3385 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3386 +
3387 +struct ipkg_conf
3388 +{
3389 + pkg_src_list_t pkg_src_list;
3390 + pkg_dest_list_t pkg_dest_list;
3391 + nv_pair_list_t arch_list;
3392 +
3393 + int restrict_to_default_dest;
3394 + pkg_dest_t *default_dest;
3395 +
3396 + char *tmp_dir;
3397 + const char *lists_dir;
3398 + const char *pending_dir;
3399 +
3400 + /* options */
3401 + int force_depends;
3402 + int force_defaults;
3403 + int force_overwrite;
3404 + int force_downgrade;
3405 + int force_reinstall;
3406 + int force_space;
3407 + int force_removal_of_dependent_packages;
3408 + int force_removal_of_essential_packages;
3409 + int nodeps; /* do not follow dependences */
3410 + int verbose_wget;
3411 + int multiple_providers;
3412 + char *offline_root;
3413 + char *offline_root_pre_script_cmd;
3414 + char *offline_root_post_script_cmd;
3415 + int query_all;
3416 + int verbosity;
3417 + int noaction;
3418 +
3419 + /* proxy options */
3420 + char *http_proxy;
3421 + char *ftp_proxy;
3422 + char *no_proxy;
3423 + char *proxy_user;
3424 + char *proxy_passwd;
3425 +
3426 + hash_table_t pkg_hash;
3427 + hash_table_t file_hash;
3428 + hash_table_t obs_file_hash;
3429 +};
3430 +
3431 +enum ipkg_option_type {
3432 + IPKG_OPT_TYPE_BOOL,
3433 + IPKG_OPT_TYPE_INT,
3434 + IPKG_OPT_TYPE_STRING
3435 +};
3436 +typedef enum ipkg_option_type ipkg_option_type_t;
3437 +
3438 +typedef struct ipkg_option ipkg_option_t;
3439 +struct ipkg_option {
3440 + const char *name;
3441 + const ipkg_option_type_t type;
3442 + const void *value;
3443 +};
3444 +
3445 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3446 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3447 +
3448 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3449 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3450 +
3451 +#endif
3452 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_configure.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_configure.c
3453 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3454 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_configure.c 2005-12-07 21:25:30.000000000 +0100
3455 @@ -0,0 +1,40 @@
3456 +/* ipkg_configure.c - the itsy package management system
3457 +
3458 + Carl D. Worth
3459 +
3460 + Copyright (C) 2001 University of Southern California
3461 +
3462 + This program is free software; you can redistribute it and/or
3463 + modify it under the terms of the GNU General Public License as
3464 + published by the Free Software Foundation; either version 2, or (at
3465 + your option) any later version.
3466 +
3467 + This program is distributed in the hope that it will be useful, but
3468 + WITHOUT ANY WARRANTY; without even the implied warranty of
3469 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3470 + General Public License for more details.
3471 +*/
3472 +
3473 +#include "ipkg.h"
3474 +
3475 +#include "ipkg_configure.h"
3476 +
3477 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3478 +{
3479 + int err;
3480 +
3481 + /* DPKG_INCOMPATIBILITY:
3482 + dpkg actually does some conffile handling here, rather than at the
3483 + end of ipkg_install(). Do we care? */
3484 + /* DPKG_INCOMPATIBILITY:
3485 + dpkg actually includes a version number to this script call */
3486 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3487 + if (err) {
3488 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3489 + return err;
3490 + }
3491 +
3492 + ipkg_state_changed++;
3493 + return 0;
3494 +}
3495 +
3496 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_configure.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_configure.h
3497 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3498 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_configure.h 2005-12-07 21:25:30.000000000 +0100
3499 @@ -0,0 +1,25 @@
3500 +/* ipkg_configure.h - the itsy package management system
3501 +
3502 + Carl D. Worth
3503 +
3504 + Copyright (C) 2001 University of Southern California
3505 +
3506 + This program is free software; you can redistribute it and/or
3507 + modify it under the terms of the GNU General Public License as
3508 + published by the Free Software Foundation; either version 2, or (at
3509 + your option) any later version.
3510 +
3511 + This program is distributed in the hope that it will be useful, but
3512 + WITHOUT ANY WARRANTY; without even the implied warranty of
3513 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3514 + General Public License for more details.
3515 +*/
3516 +
3517 +#ifndef IPKG_CONFIGURE_H
3518 +#define IPKG_CONFIGURE_H
3519 +
3520 +#include "ipkg_conf.h"
3521 +
3522 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3523 +
3524 +#endif
3525 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_download.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_download.c
3526 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3527 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_download.c 2005-12-07 21:25:30.000000000 +0100
3528 @@ -0,0 +1,191 @@
3529 +/* ipkg_download.c - the itsy package management system
3530 +
3531 + Carl D. Worth
3532 +
3533 + Copyright (C) 2001 University of Southern California
3534 +
3535 + This program is free software; you can redistribute it and/or
3536 + modify it under the terms of the GNU General Public License as
3537 + published by the Free Software Foundation; either version 2, or (at
3538 + your option) any later version.
3539 +
3540 + This program is distributed in the hope that it will be useful, but
3541 + WITHOUT ANY WARRANTY; without even the implied warranty of
3542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3543 + General Public License for more details.
3544 +*/
3545 +
3546 +#include "ipkg.h"
3547 +#include "ipkg_download.h"
3548 +#include "ipkg_message.h"
3549 +
3550 +#include "sprintf_alloc.h"
3551 +#include "xsystem.h"
3552 +#include "file_util.h"
3553 +#include "str_util.h"
3554 +
3555 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3556 +{
3557 + int err = 0;
3558 +
3559 + char *src_basec = strdup(src);
3560 + char *src_base = basename(src_basec);
3561 + char *tmp_file_location;
3562 + char *cmd;
3563 +
3564 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3565 +
3566 + fflush(stdout);
3567 +
3568 + if (str_starts_with(src, "file:")) {
3569 + int ret;
3570 + const char *file_src = src + 5;
3571 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3572 + ret = file_copy(src + 5, dest_file_name);
3573 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3574 + return ret;
3575 + }
3576 +
3577 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3578 + err = unlink(tmp_file_location);
3579 + if (err && errno != ENOENT) {
3580 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3581 + __FUNCTION__, tmp_file_location, strerror(errno));
3582 + free(tmp_file_location);
3583 + return errno;
3584 + }
3585 +
3586 + if (conf->http_proxy) {
3587 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3588 + setenv("http_proxy", conf->http_proxy, 1);
3589 + }
3590 + if (conf->ftp_proxy) {
3591 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3592 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3593 + }
3594 + if (conf->no_proxy) {
3595 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3596 + setenv("no_proxy", conf->no_proxy, 1);
3597 + }
3598 +
3599 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3600 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3601 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3602 + conf->proxy_user ? "--proxy-user=" : "",
3603 + conf->proxy_user ? conf->proxy_user : "",
3604 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3605 + conf->proxy_passwd ? conf->proxy_passwd : "",
3606 + conf->verbose_wget ? "" : "-q",
3607 + conf->tmp_dir,
3608 + src);
3609 + err = xsystem(cmd);
3610 + if (err) {
3611 + if (err != -1) {
3612 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3613 + __FUNCTION__, err, cmd);
3614 + }
3615 + unlink(tmp_file_location);
3616 + free(tmp_file_location);
3617 + free(src_basec);
3618 + free(cmd);
3619 + return EINVAL;
3620 + }
3621 + free(cmd);
3622 +
3623 + err = file_move(tmp_file_location, dest_file_name);
3624 +
3625 + free(tmp_file_location);
3626 + free(src_basec);
3627 +
3628 + if (err) {
3629 + return err;
3630 + }
3631 +
3632 + return 0;
3633 +}
3634 +
3635 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3636 +{
3637 + int err;
3638 + char *url;
3639 +
3640 + if (pkg->src == NULL) {
3641 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3642 + pkg->name, pkg->parent->name);
3643 + return -1;
3644 + }
3645 +
3646 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3647 +
3648 + /* XXX: BUG: The pkg->filename might be something like
3649 + "../../foo.ipk". While this is correct, and exactly what we
3650 + want to use to construct url above, here we actually need to
3651 + use just the filename part, without any directory. */
3652 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3653 +
3654 + err = ipkg_download(conf, url, pkg->local_filename);
3655 + free(url);
3656 +
3657 + return err;
3658 +}
3659 +
3660 +/*
3661 + * Downloads file from url, installs in package database, return package name.
3662 + */
3663 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3664 +{
3665 + int err = 0;
3666 + pkg_t *pkg;
3667 + pkg = pkg_new();
3668 + if (pkg == NULL)
3669 + return ENOMEM;
3670 +
3671 + if (str_starts_with(url, "http://")
3672 + || str_starts_with(url, "ftp://")) {
3673 + char *tmp_file;
3674 + char *file_basec = strdup(url);
3675 + char *file_base = basename(file_basec);
3676 +
3677 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3678 + err = ipkg_download(conf, url, tmp_file);
3679 + if (err)
3680 + return err;
3681 +
3682 + err = pkg_init_from_file(pkg, tmp_file);
3683 + if (err)
3684 + return err;
3685 + pkg->local_filename = strdup(tmp_file);
3686 +
3687 + free(tmp_file);
3688 + free(file_basec);
3689 +
3690 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3691 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3692 +
3693 + err = pkg_init_from_file(pkg, url);
3694 + if (err)
3695 + return err;
3696 + pkg->local_filename = strdup(url);
3697 +
3698 + } else {
3699 + return 0;
3700 + }
3701 +
3702 + if (!pkg->architecture) {
3703 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3704 + return -EINVAL;
3705 + }
3706 +
3707 + pkg->dest = conf->default_dest;
3708 + pkg->state_want = SW_INSTALL;
3709 + pkg->state_flag |= SF_PREFER;
3710 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3711 + if ( pkg == NULL ){
3712 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3713 + return 0;
3714 + }
3715 + if (namep) {
3716 + *namep = pkg->name;
3717 + }
3718 + return 0;
3719 +}
3720 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_download.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_download.h
3721 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3722 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_download.h 2005-12-07 21:25:30.000000000 +0100
3723 @@ -0,0 +1,30 @@
3724 +/* ipkg_download.h - the itsy package management system
3725 +
3726 + Carl D. Worth
3727 +
3728 + Copyright (C) 2001 University of Southern California
3729 +
3730 + This program is free software; you can redistribute it and/or
3731 + modify it under the terms of the GNU General Public License as
3732 + published by the Free Software Foundation; either version 2, or (at
3733 + your option) any later version.
3734 +
3735 + This program is distributed in the hope that it will be useful, but
3736 + WITHOUT ANY WARRANTY; without even the implied warranty of
3737 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3738 + General Public License for more details.
3739 +*/
3740 +
3741 +#ifndef IPKG_DOWNLOAD_H
3742 +#define IPKG_DOWNLOAD_H
3743 +
3744 +#include "ipkg_conf.h"
3745 +
3746 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3747 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3748 +/*
3749 + * Downloads file from url, installs in package database, return package name.
3750 + */
3751 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3752 +
3753 +#endif
3754 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_includes.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_includes.h
3755 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3756 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_includes.h 2005-12-07 21:25:30.000000000 +0100
3757 @@ -0,0 +1,79 @@
3758 +#ifndef IPKG_INCLUDES_H
3759 +#define IPKG_INCLUDES_H
3760 +
3761 +/* Define to 1 if you have the <memory.h> header file. */
3762 +#define HAVE_MEMORY_H 1
3763 +
3764 +/* Define to 1 if you have the <regex.h> header file. */
3765 +#define HAVE_REGEX_H 1
3766 +
3767 +/* Define to 1 if you have the <stdlib.h> header file. */
3768 +#define HAVE_STDLIB_H 1
3769 +
3770 +/* Define to 1 if you have the <strings.h> header file. */
3771 +#define HAVE_STRINGS_H 1
3772 +
3773 +/* Define to 1 if you have the <string.h> header file. */
3774 +#define HAVE_STRING_H 1
3775 +
3776 +/* Define to 1 if you have the <sys/stat.h> header file. */
3777 +#define HAVE_SYS_STAT_H 1
3778 +
3779 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3780 +#define HAVE_SYS_WAIT_H 1
3781 +
3782 +/* Define to 1 if you have the <unistd.h> header file. */
3783 +#define HAVE_UNISTD_H 1
3784 +
3785 +/* Define to 1 if you have the ANSI C header files. */
3786 +#define STDC_HEADERS 1
3787 +
3788 +
3789 +#include <stdio.h>
3790 +
3791 +#if STDC_HEADERS
3792 +# include <stdlib.h>
3793 +# include <stdarg.h>
3794 +# include <stddef.h>
3795 +# include <ctype.h>
3796 +# include <errno.h>
3797 +#else
3798 +# if HAVE_STDLIB_H
3799 +# include <stdlib.h>
3800 +# endif
3801 +#endif
3802 +
3803 +#if HAVE_REGEX_H
3804 +# include <regex.h>
3805 +#endif
3806 +
3807 +#if HAVE_STRING_H
3808 +# if !STDC_HEADERS && HAVE_MEMORY_H
3809 +# include <memory.h>
3810 +# endif
3811 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3812 +# if __GNUC__
3813 +# define __USE_GNU 1
3814 +# endif
3815 +# include <string.h>
3816 +# undef __USE_GNU
3817 +#endif
3818 +
3819 +#if HAVE_STRINGS_H
3820 +# include <strings.h>
3821 +#endif
3822 +
3823 +#if HAVE_SYS_STAT_H
3824 +# include <sys/stat.h>
3825 +#endif
3826 +
3827 +#if HAVE_SYS_WAIT_H
3828 +# include <sys/wait.h>
3829 +#endif
3830 +
3831 +#if HAVE_UNISTD_H
3832 +# include <sys/types.h>
3833 +# include <unistd.h>
3834 +#endif
3835 +
3836 +#endif /* IPKG_INCLUDES_H */
3837 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_install.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_install.c
3838 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3839 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_install.c 2005-12-07 21:25:30.000000000 +0100
3840 @@ -0,0 +1,1823 @@
3841 +/* ipkg_install.c - the itsy package management system
3842 +
3843 + Carl D. Worth
3844 +
3845 + Copyright (C) 2001 University of Southern California
3846 +
3847 + This program is free software; you can redistribute it and/or
3848 + modify it under the terms of the GNU General Public License as
3849 + published by the Free Software Foundation; either version 2, or (at
3850 + your option) any later version.
3851 +
3852 + This program is distributed in the hope that it will be useful, but
3853 + WITHOUT ANY WARRANTY; without even the implied warranty of
3854 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3855 + General Public License for more details.
3856 +*/
3857 +
3858 +#include "ipkg.h"
3859 +#include <errno.h>
3860 +#include <dirent.h>
3861 +#include <glob.h>
3862 +#include <time.h>
3863 +#include <signal.h>
3864 +typedef void (*sighandler_t)(int);
3865 +
3866 +#include "pkg.h"
3867 +#include "pkg_hash.h"
3868 +#include "pkg_extract.h"
3869 +
3870 +#include "ipkg_install.h"
3871 +#include "ipkg_configure.h"
3872 +#include "ipkg_download.h"
3873 +#include "ipkg_remove.h"
3874 +
3875 +#include "ipkg_utils.h"
3876 +#include "ipkg_message.h"
3877 +
3878 +#include "sprintf_alloc.h"
3879 +#include "file_util.h"
3880 +#include "str_util.h"
3881 +#include "xsystem.h"
3882 +#include "user.h"
3883 +
3884 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3885 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3886 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3887 +
3888 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3889 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3890 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3891 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3892 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3893 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3894 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3900 +
3901 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3902 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3903 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3904 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3905 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3906 +
3907 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3908 +
3909 +static int user_prefers_old_conffile(const char *file, const char *backup);
3910 +
3911 +static char *backup_filename_alloc(const char *file_name);
3912 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3913 +static int backup_exists_for(const char *file_name);
3914 +static int backup_remove(const char *file_name);
3915 +
3916 +
3917 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3918 +{
3919 + int err, cmp;
3920 + pkg_t *pkg, *old;
3921 + char *old_version, *new_version;
3922 +
3923 + pkg = pkg_new();
3924 + if (pkg == NULL) {
3925 + return ENOMEM;
3926 + }
3927 +
3928 + err = pkg_init_from_file(pkg, filename);
3929 + if (err) {
3930 + return err;
3931 + }
3932 +
3933 + if (!pkg->architecture) {
3934 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3935 + return -EINVAL;
3936 + }
3937 +
3938 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3939 + freeing the pkg that we pass in. It might be nice to clean this up
3940 + if possible. */
3941 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3942 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3943 +
3944 + pkg->local_filename = strdup(filename);
3945 +
3946 + if (old) {
3947 + old_version = pkg_version_str_alloc(old);
3948 + new_version = pkg_version_str_alloc(pkg);
3949 +
3950 + cmp = pkg_compare_versions(old, pkg);
3951 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3952 + cmp = -1 ; /* then we force ipkg to downgrade */
3953 + /* We need to use a value < 0 because in the 0 case we are asking to */
3954 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3955 + }
3956 + if (cmp > 0) {
3957 + ipkg_message(conf, IPKG_NOTICE,
3958 + "Not downgrading package %s on %s from %s to %s.\n",
3959 + old->name, old->dest->name, old_version, new_version);
3960 + pkg->state_want = SW_DEINSTALL;
3961 + pkg->state_flag |= SF_OBSOLETE;
3962 + free(old_version);
3963 + free(new_version);
3964 + return 0;
3965 + } else {
3966 + free(old_version);
3967 + free(new_version);
3968 + }
3969 + }
3970 +
3971 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3972 + return ipkg_install_pkg(conf, pkg);
3973 +}
3974 +
3975 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3976 +{
3977 + int cmp;
3978 + pkg_t *old, *new;
3979 + char *old_version, *new_version;
3980 +
3981 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3982 +
3983 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3984 + if (new == NULL) {
3985 + return IPKG_PKG_HAS_NO_CANDIDATE;
3986 + }
3987 +
3988 + new->state_flag |= SF_USER;
3989 + if (old) {
3990 + old_version = pkg_version_str_alloc(old);
3991 + new_version = pkg_version_str_alloc(new);
3992 +
3993 + cmp = pkg_compare_versions(old, new);
3994 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3995 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3996 + cmp = -1 ; /* then we force ipkg to downgrade */
3997 + /* We need to use a value < 0 because in the 0 case we are asking to */
3998 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3999 + }
4000 + ipkg_message(conf, IPKG_DEBUG,
4001 + "comparing visible versions of pkg %s:"
4002 + "\n\t%s is installed "
4003 + "\n\t%s is available "
4004 + "\n\t%d was comparison result\n",
4005 + pkg_name, old_version, new_version, cmp);
4006 + if (cmp == 0 && !conf->force_reinstall) {
4007 + ipkg_message(conf, IPKG_NOTICE,
4008 + "Package %s (%s) installed in %s is up to date.\n",
4009 + old->name, old_version, old->dest->name);
4010 + free(old_version);
4011 + free(new_version);
4012 + return 0;
4013 + } else if (cmp > 0) {
4014 + ipkg_message(conf, IPKG_NOTICE,
4015 + "Not downgrading package %s on %s from %s to %s.\n",
4016 + old->name, old->dest->name, old_version, new_version);
4017 + free(old_version);
4018 + free(new_version);
4019 + return 0;
4020 + } else if (cmp < 0) {
4021 + new->dest = old->dest;
4022 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4023 + }
4024 + }
4025 +
4026 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4027 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4028 + return any kind of integer, (might be errno from a syscall,
4029 + etc.). This is a real mess and will need to be cleaned up if
4030 + anyone ever wants to make a nice libipkg. */
4031 +
4032 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4033 + return ipkg_install_pkg(conf, new);
4034 +}
4035 +
4036 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4037 +{
4038 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4039 + int i;
4040 + ipkg_error_t err;
4041 + abstract_pkg_t *ppkg ;
4042 +
4043 + if (providers == NULL)
4044 + return IPKG_PKG_HAS_NO_CANDIDATE;
4045 +
4046 + for (i = 0; i < providers->len; i++) {
4047 + ppkg = abstract_pkg_vec_get(providers, i);
4048 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4049 + err = ipkg_install_by_name(conf, ppkg->name);
4050 + if (err)
4051 + return err;
4052 +/* XXX Maybe ppkg should be freed ? */
4053 + }
4054 + return 0;
4055 +}
4056 +
4057 +/*
4058 + * Walk dependence graph starting with pkg, collect packages to be
4059 + * installed into pkgs_needed, in dependence order.
4060 + */
4061 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4062 +{
4063 + int i, err;
4064 + pkg_vec_t *depends = pkg_vec_alloc();
4065 + char **unresolved = NULL;
4066 + int ndepends;
4067 +
4068 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4069 + pkg, depends,
4070 + &unresolved);
4071 +
4072 + if (unresolved) {
4073 + ipkg_message(conf, IPKG_ERROR,
4074 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4075 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4076 + while (*unresolved) {
4077 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4078 + unresolved++;
4079 + }
4080 + ipkg_message(conf, IPKG_ERROR, "\n");
4081 + if (! conf->force_depends) {
4082 + ipkg_message(conf, IPKG_INFO,
4083 + "This could mean that your package list is out of date or that the packages\n"
4084 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4085 + "of this problem try again with the '-force-depends' option.\n");
4086 + pkg_vec_free(depends);
4087 + return IPKG_PKG_DEPS_UNSATISFIED;
4088 + }
4089 + }
4090 +
4091 + if (ndepends <= 0) {
4092 + pkg_vec_free(depends);
4093 + return 0;
4094 + }
4095 +
4096 + for (i = 0; i < depends->len; i++) {
4097 + pkg_t *dep = depends->pkgs[i];
4098 + /* The package was uninstalled when we started, but another
4099 + dep earlier in this loop may have depended on it and pulled
4100 + it in, so check first. */
4101 + if ((dep->state_status != SS_INSTALLED)
4102 + && (dep->state_status != SS_UNPACKED)
4103 + && (dep->state_want != SW_INSTALL)) {
4104 +
4105 + /* Mark packages as to-be-installed */
4106 + dep->state_want = SW_INSTALL;
4107 +
4108 + /* Dependencies should be installed the same place as pkg */
4109 + if (dep->dest == NULL) {
4110 + dep->dest = pkg->dest;
4111 + }
4112 +
4113 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4114 + if (err) {
4115 + pkg_vec_free(depends);
4116 + return err;
4117 + }
4118 + }
4119 + }
4120 + if (pkgs_needed)
4121 + pkg_vec_insert(pkgs_needed, pkg);
4122 +
4123 + pkg_vec_free(depends);
4124 +
4125 + return 0;
4126 +}
4127 +
4128 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4129 +{
4130 + int cmp;
4131 + pkg_t *old, *new;
4132 + char *old_version, *new_version;
4133 +
4134 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4135 +
4136 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4137 + if (new == NULL) {
4138 + return IPKG_PKG_HAS_NO_CANDIDATE;
4139 + }
4140 + if (old) {
4141 + old_version = pkg_version_str_alloc(old);
4142 + new_version = pkg_version_str_alloc(new);
4143 +
4144 + cmp = pkg_compare_versions(old, new);
4145 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4146 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4147 + cmp = -1 ; /* then we force ipkg to downgrade */
4148 + /* We need to use a value < 0 because in the 0 case we are asking to */
4149 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4150 + }
4151 + ipkg_message(conf, IPKG_DEBUG,
4152 + "comparing visible versions of pkg %s:"
4153 + "\n\t%s is installed "
4154 + "\n\t%s is available "
4155 + "\n\t%d was comparison result\n",
4156 + pkg_name, old_version, new_version, cmp);
4157 + if (cmp == 0 && !conf->force_reinstall) {
4158 + ipkg_message(conf, IPKG_NOTICE,
4159 + "Package %s (%s) installed in %s is up to date.\n",
4160 + old->name, old_version, old->dest->name);
4161 + free(old_version);
4162 + free(new_version);
4163 + return 0;
4164 + } else if (cmp > 0) {
4165 + ipkg_message(conf, IPKG_NOTICE,
4166 + "Not downgrading package %s on %s from %s to %s.\n",
4167 + old->name, old->dest->name, old_version, new_version);
4168 + free(old_version);
4169 + free(new_version);
4170 + return 0;
4171 + } else if (cmp < 0) {
4172 + new->dest = old->dest;
4173 + old->state_want = SW_DEINSTALL;
4174 + old->state_flag |= SF_OBSOLETE;
4175 + }
4176 + }
4177 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4178 +}
4179 +
4180 +\f
4181 +
4182 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4183 +{
4184 + int i, err;
4185 + pkg_vec_t *depends = pkg_vec_alloc();
4186 + pkg_t *dep;
4187 + char **unresolved = NULL;
4188 + int ndepends;
4189 +
4190 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4191 + pkg, depends,
4192 + &unresolved);
4193 +
4194 + if (unresolved) {
4195 + ipkg_message(conf, IPKG_ERROR,
4196 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4197 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4198 + while (*unresolved) {
4199 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4200 + unresolved++;
4201 + }
4202 + ipkg_message(conf, IPKG_ERROR, "\n");
4203 + if (! conf->force_depends) {
4204 + ipkg_message(conf, IPKG_INFO,
4205 + "This could mean that your package list is out of date or that the packages\n"
4206 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4207 + "of this problem try again with the '-force-depends' option.\n");
4208 + pkg_vec_free(depends);
4209 + return IPKG_PKG_DEPS_UNSATISFIED;
4210 + }
4211 + }
4212 +
4213 + if (ndepends <= 0) {
4214 + return 0;
4215 + }
4216 +
4217 + /* Mark packages as to-be-installed */
4218 + for (i=0; i < depends->len; i++) {
4219 + /* Dependencies should be installed the same place as pkg */
4220 + if (depends->pkgs[i]->dest == NULL) {
4221 + depends->pkgs[i]->dest = pkg->dest;
4222 + }
4223 + depends->pkgs[i]->state_want = SW_INSTALL;
4224 + }
4225 +
4226 + for (i = 0; i < depends->len; i++) {
4227 + dep = depends->pkgs[i];
4228 + /* The package was uninstalled when we started, but another
4229 + dep earlier in this loop may have depended on it and pulled
4230 + it in, so check first. */
4231 + if ((dep->state_status != SS_INSTALLED)
4232 + && (dep->state_status != SS_UNPACKED)) {
4233 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4234 + err = ipkg_install_pkg(conf, dep);
4235 + if (err) {
4236 + pkg_vec_free(depends);
4237 + return err;
4238 + }
4239 + }
4240 + }
4241 +
4242 + pkg_vec_free(depends);
4243 +
4244 + return 0;
4245 +}
4246 +
4247 +
4248 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4249 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4250 +{
4251 + if (conf->nodeps == 0) {
4252 + int i;
4253 + pkg_vec_t *installed = pkg_vec_alloc();
4254 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4255 + for (i = 0; i < installed->len; i++) {
4256 + pkg_t *pkg = installed->pkgs[i];
4257 + satisfy_dependencies_for(conf, pkg);
4258 + }
4259 + pkg_vec_free(installed);
4260 + }
4261 + return 0;
4262 +}
4263 +
4264 +\f
4265 +
4266 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4267 +{
4268 + int i;
4269 + pkg_vec_t *conflicts = NULL;
4270 + int level;
4271 + const char *prefix;
4272 + if (conf->force_depends) {
4273 + level = IPKG_NOTICE;
4274 + prefix = "Warning";
4275 + } else {
4276 + level = IPKG_ERROR;
4277 + prefix = "ERROR";
4278 + }
4279 +
4280 + if (!conf->force_depends)
4281 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4282 +
4283 + if (conflicts) {
4284 + ipkg_message(conf, level,
4285 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4286 + i = 0;
4287 + while (i < conflicts->len)
4288 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4289 + ipkg_message(conf, level, "\n");
4290 + pkg_vec_free(conflicts);
4291 + return IPKG_PKG_DEPS_UNSATISFIED;
4292 + }
4293 + return 0;
4294 +}
4295 +
4296 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4297 +{
4298 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4299 + str_list_elt_t *iter;
4300 +
4301 + for (iter = new_list->head; iter; iter = iter->next) {
4302 + char *new_file = iter->data;
4303 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4304 + if (!new_file)
4305 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4306 + if (!owner || (owner == old_pkg))
4307 + file_hash_set_file_owner(conf, new_file, new_pkg);
4308 + }
4309 + if (old_pkg) {
4310 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4311 + for (iter = old_list->head; iter; iter = iter->next) {
4312 + char *old_file = iter->data;
4313 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4314 + if (owner == old_pkg) {
4315 + /* obsolete */
4316 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4317 + }
4318 + }
4319 + }
4320 + return 0;
4321 +}
4322 +
4323 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4324 +{
4325 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4326 +
4327 + /* sma 6.20.02: yup; here's the first bit */
4328 + /*
4329 + * XXX: BUG easy for cworth
4330 + * 1) please point the call below to the correct current root destination
4331 + * 2) we need to resolve how to check the required space for a pending pkg,
4332 + * my diddling with the .ipk file size below isn't going to cut it.
4333 + * 3) return a proper error code instead of 1
4334 + */
4335 + int comp_size, blocks_available;
4336 +
4337 + if (!conf->force_space && pkg->installed_size != NULL) {
4338 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4339 +
4340 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4341 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4342 + comp_size = (int)((comp_size + 1023) / 1024);
4343 +
4344 + if (comp_size >= blocks_available) {
4345 + ipkg_message(conf, IPKG_ERROR,
4346 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4347 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4348 + return ENOSPC;
4349 + }
4350 + }
4351 + return 0;
4352 +}
4353 +
4354 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4355 +{
4356 + int err;
4357 + char *conffiles_file_name;
4358 + char *root_dir;
4359 + FILE *conffiles_file;
4360 +
4361 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4362 +
4363 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4364 + if (pkg->tmp_unpack_dir == NULL) {
4365 + ipkg_message(conf, IPKG_ERROR,
4366 + "%s: Failed to create temporary directory '%s': %s\n",
4367 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4368 + return errno;
4369 + }
4370 +
4371 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4372 + if (err) {
4373 + return err;
4374 + }
4375 +
4376 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4377 + conffiles. Seems like I should be able to get everything to go
4378 + through pkg_init_from_file. If so, maybe it would make sense to
4379 + move all of unpack_pkg_control_files to that function. */
4380 +
4381 + /* Don't need to re-read conffiles if we already have it */
4382 + if (pkg->conffiles.head) {
4383 + return 0;
4384 + }
4385 +
4386 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4387 + if (! file_exists(conffiles_file_name)) {
4388 + free(conffiles_file_name);
4389 + return 0;
4390 + }
4391 +
4392 + conffiles_file = fopen(conffiles_file_name, "r");
4393 + if (conffiles_file == NULL) {
4394 + fprintf(stderr, "%s: failed to open %s: %s\n",
4395 + __FUNCTION__, conffiles_file_name, strerror(errno));
4396 + free(conffiles_file_name);
4397 + return errno;
4398 + }
4399 + free(conffiles_file_name);
4400 +
4401 + while (1) {
4402 + char *cf_name;
4403 + char *cf_name_in_dest;
4404 +
4405 + cf_name = file_read_line_alloc(conffiles_file);
4406 + if (cf_name == NULL) {
4407 + break;
4408 + }
4409 + str_chomp(cf_name);
4410 + if (cf_name[0] == '\0') {
4411 + continue;
4412 + }
4413 +
4414 + /* Prepend dest->root_dir to conffile name.
4415 + Take pains to avoid multiple slashes. */
4416 + root_dir = pkg->dest->root_dir;
4417 + if (conf->offline_root)
4418 + /* skip the offline_root prefix */
4419 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4420 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4421 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4422 +
4423 + /* Can't get an md5sum now, (file isn't extracted yet).
4424 + We'll wait until resolve_conffiles */
4425 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4426 +
4427 + free(cf_name);
4428 + free(cf_name_in_dest);
4429 + }
4430 +
4431 + fclose(conffiles_file);
4432 +
4433 + return 0;
4434 +}
4435 +
4436 +/* returns number of installed replacees */
4437 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4438 +{
4439 + abstract_pkg_t **replaces = pkg->replaces;
4440 + int replaces_count = pkg->replaces_count;
4441 + int i, j;
4442 + for (i = 0; i < replaces_count; i++) {
4443 + abstract_pkg_t *ab_pkg = replaces[i];
4444 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4445 + if (pkg_vec) {
4446 + for (j = 0; j < pkg_vec->len; j++) {
4447 + pkg_t *replacee = pkg_vec->pkgs[j];
4448 + if (!pkg_conflicts(pkg, replacee))
4449 + continue;
4450 + if (replacee->state_status == SS_INSTALLED) {
4451 + pkg_vec_insert(installed_replacees, replacee);
4452 + }
4453 + }
4454 + }
4455 + }
4456 + return installed_replacees->len;
4457 +}
4458 +
4459 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4460 +{
4461 + int i;
4462 + int replaces_count = replacees->len;
4463 + for (i = 0; i < replaces_count; i++) {
4464 + pkg_t *replacee = replacees->pkgs[i];
4465 + int err;
4466 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4467 + err = ipkg_remove_pkg(conf, replacee);
4468 + if (err)
4469 + return err;
4470 + }
4471 + return 0;
4472 +}
4473 +
4474 +/* to unwind the removal: make sure they are installed */
4475 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4476 +{
4477 + int i, err;
4478 + int replaces_count = replacees->len;
4479 + for (i = 0; i < replaces_count; i++) {
4480 + pkg_t *replacee = replacees->pkgs[i];
4481 + if (replacee->state_status != SS_INSTALLED) {
4482 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4483 + err = ipkg_install_pkg(conf, replacee);
4484 + if (err)
4485 + return err;
4486 + }
4487 + }
4488 + return 0;
4489 +}
4490 +
4491 +int caught_sigint = 0;
4492 +static void ipkg_install_pkg_sigint_handler(int sig)
4493 +{
4494 + caught_sigint = sig;
4495 +}
4496 +
4497 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4498 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4499 +{
4500 + if (old_pkg) {
4501 + char message_out[15];
4502 + char *old_version = pkg_version_str_alloc(old_pkg);
4503 + char *new_version = pkg_version_str_alloc(pkg);
4504 + int cmp = pkg_compare_versions(old_pkg, pkg);
4505 + int rc = 0;
4506 +
4507 + strncpy (message_out,"Upgrading ",13);
4508 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4509 + cmp = -1 ; /* then we force ipkg to downgrade */
4510 + strncpy (message_out,"Downgrading ",13); /* We need to use a value < 0 because in the 0 case we are asking to */
4511 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4512 + }
4513 +
4514 + if (cmp > 0) {
4515 + ipkg_message(conf, IPKG_NOTICE,
4516 + "Not downgrading package %s on %s from %s to %s.\n",
4517 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4518 + rc = 1;
4519 + } else if (cmp < 0) {
4520 + ipkg_message(conf, IPKG_NOTICE,
4521 + "%s %s on %s from %s to %s...\n",
4522 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4523 + pkg->dest = old_pkg->dest;
4524 + rc = 0;
4525 + } else /* cmp == 0 */ {
4526 + if (conf->force_reinstall) {
4527 + ipkg_message(conf, IPKG_NOTICE,
4528 + "Reinstalling %s (%s) on %s...\n",
4529 + pkg->name, new_version, old_pkg->dest->name);
4530 + pkg->dest = old_pkg->dest;
4531 + rc = 0;
4532 + } else {
4533 + ipkg_message(conf, IPKG_NOTICE,
4534 + "Not installing %s (%s) on %s -- already installed.\n",
4535 + pkg->name, new_version, old_pkg->dest->name);
4536 + rc = 1;
4537 + }
4538 + }
4539 + free(old_version);
4540 + free(new_version);
4541 + return rc;
4542 + } else {
4543 + char *version = pkg_version_str_alloc(pkg);
4544 + ipkg_message(conf, IPKG_NOTICE,
4545 + "Installing %s (%s) to %s...\n",
4546 + pkg->name, version, pkg->dest->name);
4547 + free(version);
4548 + return 0;
4549 + }
4550 +}
4551 +
4552 +/* and now the meat... */
4553 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg)
4554 +{
4555 + int err = 0;
4556 + pkg_t *old_pkg = NULL;
4557 + pkg_vec_t *replacees;
4558 + abstract_pkg_t *ab_pkg = NULL;
4559 + int old_state_flag;
4560 +
4561 + if (!pkg) {
4562 + ipkg_message(conf, IPKG_ERROR,
4563 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4564 + return -EINVAL;
4565 + }
4566 +
4567 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4568 +
4569 + if (!pkg_arch_supported(conf, pkg)) {
4570 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4571 + pkg->architecture, pkg->name);
4572 + return -EINVAL;
4573 + }
4574 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4575 + err = satisfy_dependencies_for(conf, pkg);
4576 + if (err) { return err; }
4577 +
4578 + ipkg_message(conf, IPKG_NOTICE,
4579 + "Package %s is already installed in %s.\n",
4580 + pkg->name, pkg->dest->name);
4581 + return 0;
4582 + }
4583 +
4584 + if (pkg->dest == NULL) {
4585 + pkg->dest = conf->default_dest;
4586 + }
4587 +
4588 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4589 +
4590 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg);
4591 + if (err) { return err; }
4592 +
4593 + pkg->state_want = SW_INSTALL;
4594 + if (old_pkg) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4595 +
4596 + /* Abhaya: conflicts check */
4597 + err = check_conflicts_for(conf, pkg);
4598 + if (err) { return err; }
4599 +
4600 + /* this setup is to remove the upgrade scenario in the end when
4601 + installing pkg A, A deps B & B deps on A. So both B and A are
4602 + installed. Then A's installation is started resulting in an
4603 + uncecessary upgrade */
4604 + if (pkg->state_status == SS_INSTALLED
4605 + && conf->force_reinstall == 0) return 0;
4606 +
4607 + err = verify_pkg_installable(conf, pkg);
4608 + if (err) { return err; }
4609 +
4610 + if (pkg->local_filename == NULL) {
4611 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4612 + if (err) {
4613 + ipkg_message(conf, IPKG_ERROR,
4614 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4615 + pkg->name);
4616 + return err;
4617 + }
4618 + }
4619 + if (pkg->tmp_unpack_dir == NULL) {
4620 + unpack_pkg_control_files(conf, pkg);
4621 + }
4622 +
4623 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4624 + err = update_file_ownership(conf, pkg, old_pkg);
4625 + if (err) { return err; }
4626 +
4627 + if (conf->nodeps == 0) {
4628 + err = satisfy_dependencies_for(conf, pkg);
4629 + if (err) { return err; }
4630 + }
4631 +
4632 + replacees = pkg_vec_alloc();
4633 + pkg_get_installed_replacees(conf, pkg, replacees);
4634 +
4635 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4636 + {
4637 + sigset_t newset, oldset;
4638 + sighandler_t old_handler = NULL;
4639 + int use_signal = 0;
4640 + caught_sigint = 0;
4641 + if (use_signal) {
4642 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4643 + } else {
4644 + sigemptyset(&newset);
4645 + sigaddset(&newset, SIGINT);
4646 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4647 + }
4648 +
4649 + ipkg_state_changed++;
4650 + pkg->state_flag |= SF_FILELIST_CHANGED;
4651 +
4652 + /* XXX: BUG: we really should treat replacement more like an upgrade
4653 + * Instead, we're going to remove the replacees
4654 + */
4655 + err = pkg_remove_installed_replacees(conf, replacees);
4656 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4657 +
4658 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4659 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4660 +
4661 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4662 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4663 +
4664 + err = preinst_configure(conf, pkg, old_pkg);
4665 + if (err) goto UNWIND_PREINST_CONFIGURE;
4666 +
4667 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4668 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4669 +
4670 + err = check_data_file_clashes(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4672 +
4673 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4674 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4675 +
4676 + if (conf->noaction) return 0;
4677 +
4678 + /* point of no return: no unwinding after this */
4679 + if (old_pkg && !conf->force_reinstall) {
4680 + old_pkg->state_want = SW_DEINSTALL;
4681 +
4682 + if (old_pkg->state_flag & SF_NOPRUNE) {
4683 + ipkg_message(conf, IPKG_INFO,
4684 + " not removing obsolesced files because package marked noprune\n");
4685 + } else {
4686 + ipkg_message(conf, IPKG_INFO,
4687 + " removing obsolesced files\n");
4688 + remove_obsolesced_files(conf, pkg, old_pkg);
4689 + }
4690 + }
4691 + ipkg_message(conf, IPKG_INFO,
4692 + " installing maintainer scripts\n");
4693 + install_maintainer_scripts(conf, pkg, old_pkg);
4694 +
4695 + /* the following just returns 0 */
4696 + remove_disappeared(conf, pkg);
4697 +
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " installing data files\n");
4700 + install_data_files(conf, pkg);
4701 +
4702 + ipkg_message(conf, IPKG_INFO,
4703 + " resolving conf files\n");
4704 + resolve_conffiles(conf, pkg);
4705 +
4706 + pkg->state_status = SS_UNPACKED;
4707 + old_state_flag = pkg->state_flag;
4708 + pkg->state_flag &= ~SF_PREFER;
4709 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4710 +
4711 + if (old_pkg && !conf->force_reinstall) {
4712 + old_pkg->state_status = SS_NOT_INSTALLED;
4713 + }
4714 +
4715 + time(&pkg->installed_time);
4716 +
4717 + ipkg_message(conf, IPKG_INFO,
4718 + " cleanup temp files\n");
4719 + cleanup_temporary_files(conf, pkg);
4720 +
4721 + ab_pkg = pkg->parent;
4722 + if (ab_pkg)
4723 + ab_pkg->state_status = pkg->state_status;
4724 +
4725 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4726 +
4727 + if (use_signal)
4728 + signal(SIGINT, old_handler);
4729 + else
4730 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4731 +
4732 + return 0;
4733 +
4734 +
4735 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4736 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4737 + UNWIND_CHECK_DATA_FILE_CLASHES:
4738 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4739 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4740 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4741 + UNWIND_PREINST_CONFIGURE:
4742 + preinst_configure_unwind(conf, pkg, old_pkg);
4743 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4744 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4745 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4746 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4747 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4748 + pkg_remove_installed_replacees_unwind(conf, replacees);
4749 +
4750 + ipkg_message(conf, IPKG_INFO,
4751 + " cleanup temp files\n");
4752 + cleanup_temporary_files(conf, pkg);
4753 +
4754 + ipkg_message(conf, IPKG_INFO,
4755 + "Failed.\n");
4756 + if (use_signal)
4757 + signal(SIGINT, old_handler);
4758 + else
4759 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4760 +
4761 + return err;
4762 + }
4763 +}
4764 +
4765 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4766 +{
4767 + /* DPKG_INCOMPATIBILITY:
4768 + dpkg does some things here that we don't do yet. Do we care?
4769 +
4770 + 1. If a version of the package is already installed, call
4771 + old-prerm upgrade new-version
4772 + 2. If the script runs but exits with a non-zero exit status
4773 + new-prerm failed-upgrade old-version
4774 + Error unwind, for both the above cases:
4775 + old-postinst abort-upgrade new-version
4776 + */
4777 + return 0;
4778 +}
4779 +
4780 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4781 +{
4782 + /* DPKG_INCOMPATIBILITY:
4783 + dpkg does some things here that we don't do yet. Do we care?
4784 + (See prerm_upgrade_old_package for details)
4785 + */
4786 + return 0;
4787 +}
4788 +
4789 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4790 +{
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4793 + 2. If a 'conflicting' package is being removed at the same time:
4794 + 1. If any packages depended on that conflicting package and
4795 + --auto-deconfigure is specified, call, for each such package:
4796 + deconfigured's-prerm deconfigure \
4797 + in-favour package-being-installed version \
4798 + removing conflicting-package version
4799 + Error unwind:
4800 + deconfigured's-postinst abort-deconfigure \
4801 + in-favour package-being-installed-but-failed version \
4802 + removing conflicting-package version
4803 +
4804 + The deconfigured packages are marked as requiring
4805 + configuration, so that if --install is used they will be
4806 + configured again if possible.
4807 + 2. To prepare for removal of the conflicting package, call:
4808 + conflictor's-prerm remove in-favour package new-version
4809 + Error unwind:
4810 + conflictor's-postinst abort-remove in-favour package new-version
4811 + */
4812 + return 0;
4813 +}
4814 +
4815 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4816 +{
4817 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4818 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4819 + details) */
4820 + return 0;
4821 +}
4822 +
4823 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4824 +{
4825 + int err;
4826 + char *preinst_args;
4827 +
4828 + if (old_pkg) {
4829 + char *old_version = pkg_version_str_alloc(old_pkg);
4830 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4831 + free(old_version);
4832 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4833 + char *pkg_version = pkg_version_str_alloc(pkg);
4834 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4835 + free(pkg_version);
4836 + } else {
4837 + preinst_args = strdup("install");
4838 + }
4839 +
4840 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4841 + if (err) {
4842 + ipkg_message(conf, IPKG_ERROR,
4843 + "Aborting installation of %s\n", pkg->name);
4844 + return 1;
4845 + }
4846 +
4847 + free(preinst_args);
4848 +
4849 + return 0;
4850 +}
4851 +
4852 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4853 +{
4854 + /* DPKG_INCOMPATIBILITY:
4855 + dpkg does the following error unwind, should we?
4856 + pkg->postrm abort-upgrade old-version
4857 + OR pkg->postrm abort-install old-version
4858 + OR pkg->postrm abort-install
4859 + */
4860 + return 0;
4861 +}
4862 +
4863 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4864 +{
4865 + int err;
4866 + conffile_list_elt_t *iter;
4867 + conffile_t *cf;
4868 +
4869 + if (conf->noaction) return 0;
4870 +
4871 + /* Backup all modified conffiles */
4872 + if (old_pkg) {
4873 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4874 + char *cf_name;
4875 +
4876 + cf = iter->data;
4877 + cf_name = root_filename_alloc(conf, cf->name);
4878 +
4879 + /* Don't worry if the conffile is just plain gone */
4880 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4881 + err = backup_make_backup(conf, cf_name);
4882 + if (err) {
4883 + return err;
4884 + }
4885 + }
4886 + free(cf_name);
4887 + }
4888 + }
4889 +
4890 + /* Backup all conffiles that were not conffiles in old_pkg */
4891 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4892 + char *cf_name;
4893 + cf = iter->data;
4894 + cf_name = root_filename_alloc(conf, cf->name);
4895 + /* Ignore if this was a conffile in old_pkg as well */
4896 + if (pkg_get_conffile(old_pkg, cf->name)) {
4897 + continue;
4898 + }
4899 +
4900 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4901 + err = backup_make_backup(conf, cf_name);
4902 + if (err) {
4903 + return err;
4904 + }
4905 + }
4906 + free(cf_name);
4907 + }
4908 +
4909 + return 0;
4910 +}
4911 +
4912 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4913 +{
4914 + conffile_list_elt_t *iter;
4915 +
4916 + if (old_pkg) {
4917 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4918 + backup_remove(iter->data->name);
4919 + }
4920 + }
4921 +
4922 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4923 + backup_remove(iter->data->name);
4924 + }
4925 +
4926 + return 0;
4927 +}
4928 +
4929 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4930 +{
4931 + /* DPKG_INCOMPATIBILITY:
4932 + ipkg takes a slightly different approach than dpkg at this
4933 + point. dpkg installs each file in the new package while
4934 + creating a backup for any file that is replaced, (so that it
4935 + can unwind if necessary). To avoid complexity and redundant
4936 + storage, ipkg doesn't do any installation until later, (at the
4937 + point at which dpkg removes the backups.
4938 +
4939 + But, we do have to check for data file clashes, since after
4940 + installing a package with a file clash, removing either of the
4941 + packages involved in the clash has the potential to break the
4942 + other package.
4943 + */
4944 + str_list_t *files_list;
4945 + str_list_elt_t *iter;
4946 +
4947 + int clashes = 0;
4948 +
4949 + files_list = pkg_get_installed_files(pkg);
4950 + for (iter = files_list->head; iter; iter = iter->next) {
4951 + char *root_filename;
4952 + char *filename = iter->data;
4953 + root_filename = root_filename_alloc(conf, filename);
4954 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4955 + pkg_t *owner;
4956 + pkg_t *obs;
4957 + /* Pre-existing conffiles are OK */
4958 + /* @@@@ should have way to check that it is a conffile -Jamey */
4959 + if (backup_exists_for(root_filename)) {
4960 + continue;
4961 + }
4962 +
4963 + /* Pre-existing files are OK if force-overwrite was asserted. */
4964 + if (conf->force_overwrite) {
4965 + /* but we need to change who owns this file */
4966 + file_hash_set_file_owner(conf, filename, pkg);
4967 + continue;
4968 + }
4969 +
4970 + owner = file_hash_get_file_owner(conf, filename);
4971 +
4972 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4973 + if (owner && old_pkg) {
4974 + if (strcmp(owner->name, old_pkg->name) == 0) {
4975 + continue;
4976 + }
4977 + }
4978 +
4979 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4980 + if (owner) {
4981 + if (pkg_replaces(pkg, owner)) {
4982 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4983 + continue;
4984 + }
4985 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4986 + then it's ok to overwrite. */
4987 + if (strcmp(owner->name,pkg->name)==0){
4988 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4989 + continue;
4990 + }
4991 + }
4992 +
4993 + /* Pre-existing files are OK if they are obsolete */
4994 + obs = hash_table_get(&conf->obs_file_hash, filename);
4995 + if (obs) {
4996 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
4997 + continue;
4998 + }
4999 +
5000 + /* We have found a clash. */
5001 + ipkg_message(conf, IPKG_ERROR,
5002 + "Package %s wants to install file %s\n"
5003 + "\tBut that file is already provided by package ",
5004 + pkg->name, filename);
5005 + if (owner) {
5006 + ipkg_message(conf, IPKG_ERROR,
5007 + "%s\n", owner->name);
5008 + } else {
5009 + ipkg_message(conf, IPKG_ERROR,
5010 + "<no package>\nPlease move this file out of the way and try again.\n");
5011 + }
5012 + clashes++;
5013 + }
5014 + free(root_filename);
5015 + }
5016 + pkg_free_installed_files(pkg);
5017 +
5018 + return clashes;
5019 +}
5020 +
5021 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5022 +{
5023 + /* Nothing to do since check_data_file_clashes doesn't change state */
5024 + return 0;
5025 +}
5026 +
5027 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5028 +{
5029 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5030 + 1. If the package is being upgraded, call
5031 + old-postrm upgrade new-version
5032 + 2. If this fails, attempt:
5033 + new-postrm failed-upgrade old-version
5034 + Error unwind, for both cases:
5035 + old-preinst abort-upgrade new-version */
5036 + return 0;
5037 +}
5038 +
5039 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5040 +{
5041 + /* DPKG_INCOMPATIBILITY:
5042 + dpkg does some things here that we don't do yet. Do we care?
5043 + (See postrm_upgrade_old_pkg for details)
5044 + */
5045 + return 0;
5046 +}
5047 +
5048 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5049 +{
5050 + int err;
5051 + str_list_t *old_files;
5052 + str_list_elt_t *of;
5053 + str_list_t *new_files;
5054 + str_list_elt_t *nf;
5055 +
5056 + if (old_pkg == NULL) {
5057 + return 0;
5058 + }
5059 +
5060 + old_files = pkg_get_installed_files(old_pkg);
5061 + new_files = pkg_get_installed_files(pkg);
5062 +
5063 + for (of = old_files->head; of; of = of->next) {
5064 + pkg_t *owner;
5065 + char *old, *new;
5066 + old = of->data;
5067 + for (nf = new_files->head; nf; nf = nf->next) {
5068 + new = nf->data;
5069 + if (strcmp(old, new) == 0) {
5070 + goto NOT_OBSOLETE;
5071 + }
5072 + }
5073 + if (file_is_dir(old)) {
5074 + continue;
5075 + }
5076 + owner = file_hash_get_file_owner(conf, old);
5077 + if (owner != old_pkg) {
5078 + /* in case obsolete file no longer belongs to old_pkg */
5079 + continue;
5080 + }
5081 +
5082 + /* old file is obsolete */
5083 + ipkg_message(conf, IPKG_INFO,
5084 + " removing obsolete file %s\n", old);
5085 + if (!conf->noaction) {
5086 + err = unlink(old);
5087 + if (err) {
5088 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5089 + strerror(errno));
5090 + }
5091 + }
5092 +
5093 + NOT_OBSOLETE:
5094 + ;
5095 + }
5096 +
5097 + pkg_free_installed_files(old_pkg);
5098 + pkg_free_installed_files(pkg);
5099 +
5100 + return 0;
5101 +}
5102 +
5103 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5104 +{
5105 + int i;
5106 + int err = 0;
5107 + char *globpattern;
5108 + glob_t globbuf;
5109 + if (0) {
5110 + if (!pkg->dest) {
5111 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5112 + return -1;
5113 + }
5114 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5115 + err = glob(globpattern, 0, NULL, &globbuf);
5116 + free(globpattern);
5117 + if (err) {
5118 + return err;
5119 + }
5120 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5121 + for (i = 0; i < globbuf.gl_pathc; i++) {
5122 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5123 + globbuf.gl_pathv[i], old_pkg->name);
5124 + if (!conf->noaction)
5125 + unlink(globbuf.gl_pathv[i]);
5126 + }
5127 + globfree(&globbuf);
5128 + }
5129 + return err;
5130 +}
5131 +
5132 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5133 +{
5134 + int ret;
5135 + char *prefix;
5136 +
5137 + if (old_pkg)
5138 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5139 + sprintf_alloc(&prefix, "%s.", pkg->name);
5140 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5141 + pkg->dest->info_dir,
5142 + prefix);
5143 + free(prefix);
5144 + return ret;
5145 +}
5146 +
5147 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5148 +{
5149 + /* DPKG_INCOMPATIBILITY:
5150 + This is a fairly sophisticated dpkg operation. Shall we
5151 + skip it? */
5152 +
5153 + /* Any packages all of whose files have been overwritten during the
5154 + installation, and which aren't required for dependencies, are
5155 + considered to have been removed. For each such package
5156 + 1. disappearer's-postrm disappear overwriter overwriter-version
5157 + 2. The package's maintainer scripts are removed
5158 + 3. It is noted in the status database as being in a sane state,
5159 + namely not installed (any conffiles it may have are ignored,
5160 + rather than being removed by dpkg). Note that disappearing
5161 + packages do not have their prerm called, because dpkg doesn't
5162 + know in advance that the package is going to vanish.
5163 + */
5164 + return 0;
5165 +}
5166 +
5167 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5168 +{
5169 + int err;
5170 +
5171 + /* ipkg takes a slightly different approach to data file backups
5172 + than dpkg. Rather than removing backups at this point, we
5173 + actually do the data file installation now. See comments in
5174 + check_data_file_clashes() for more details. */
5175 +
5176 + ipkg_message(conf, IPKG_INFO,
5177 + " extracting data files to %s\n", pkg->dest->root_dir);
5178 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5179 + if (err) {
5180 + return err;
5181 + }
5182 +
5183 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5184 + so we can't save ourself from removing important packages
5185 + At this point we (should) have extracted the .control file, so it
5186 + would be a good idea to reload the data in it, and set the Essential
5187 + state in *pkg. From now on the Essential is back in status file and
5188 + we can protect again.
5189 + We should operate this way:
5190 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5191 + check for "Essential" in it
5192 + set the value in pkg->essential.
5193 + This new routine could be useful also for every other flag
5194 + Pigi: 16/03/2004 */
5195 + set_flags_from_control(conf, pkg) ;
5196 +
5197 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5198 + err = pkg_write_filelist(conf, pkg);
5199 + if (err)
5200 + return err;
5201 +
5202 + /* XXX: FEATURE: ipkg should identify any files which existed
5203 + before installation and which were overwritten, (see
5204 + check_data_file_clashes()). What it must do is remove any such
5205 + files from the filelist of the old package which provided the
5206 + file. Otherwise, if the old package were removed at some point
5207 + it would break the new package. Removing the new package will
5208 + also break the old one, but this cannot be helped since the old
5209 + package's file has already been deleted. This is the importance
5210 + of check_data_file_clashes(), and only allowing ipkg to install
5211 + a clashing package with a user force. */
5212 +
5213 + return 0;
5214 +}
5215 +
5216 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5217 +{
5218 + conffile_list_elt_t *iter;
5219 + conffile_t *cf;
5220 + char *cf_backup;
5221 +
5222 + char *md5sum;
5223 +
5224 +
5225 + if (conf->noaction) return 0;
5226 +
5227 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5228 + char *root_filename;
5229 + cf = iter->data;
5230 + root_filename = root_filename_alloc(conf, cf->name);
5231 +
5232 + /* Might need to initialize the md5sum for each conffile */
5233 + if (cf->value == NULL) {
5234 + cf->value = file_md5sum_alloc(root_filename);
5235 + }
5236 +
5237 + if (!file_exists(root_filename)) {
5238 + free(root_filename);
5239 + continue;
5240 + }
5241 +
5242 + cf_backup = backup_filename_alloc(root_filename);
5243 +
5244 +
5245 + if (file_exists(cf_backup)) {
5246 + /* Let's compute md5 to test if files are changed */
5247 + md5sum = file_md5sum_alloc(cf_backup);
5248 + if (strcmp( cf->value,md5sum) != 0 ) {
5249 + if (conf->force_defaults
5250 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5251 + rename(cf_backup, root_filename);
5252 + }
5253 + }
5254 + unlink(cf_backup);
5255 + free(md5sum);
5256 + }
5257 +
5258 + free(cf_backup);
5259 + free(root_filename);
5260 + }
5261 +
5262 + return 0;
5263 +}
5264 +
5265 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5266 +{
5267 + char *response;
5268 + const char *short_file_name;
5269 +
5270 + short_file_name = strrchr(file_name, '/');
5271 + if (short_file_name) {
5272 + short_file_name++;
5273 + } else {
5274 + short_file_name = file_name;
5275 + }
5276 +
5277 + while (1) {
5278 + response = get_user_response(" Configuration file '%s'\n"
5279 + " ==> File on system created by you or by a script.\n"
5280 + " ==> File also in package provided by package maintainer.\n"
5281 + " What would you like to do about it ? Your options are:\n"
5282 + " Y or I : install the package maintainer's version\n"
5283 + " N or O : keep your currently-installed version\n"
5284 + " D : show the differences between the versions (if diff is installed)\n"
5285 + " The default action is to keep your current version.\n"
5286 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5287 + if (strcmp(response, "y") == 0
5288 + || strcmp(response, "i") == 0
5289 + || strcmp(response, "yes") == 0) {
5290 + free(response);
5291 + return 0;
5292 + }
5293 +
5294 + if (strcmp(response, "d") == 0) {
5295 + char *cmd;
5296 +
5297 + free(response);
5298 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5299 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5300 + xsystem(cmd);
5301 + free(cmd);
5302 + printf(" [Press ENTER to continue]\n");
5303 + response = file_read_line_alloc(stdin);
5304 + free(response);
5305 + continue;
5306 + }
5307 +
5308 + free(response);
5309 + return 1;
5310 + }
5311 +}
5312 +
5313 +/* XXX: CLEANUP: I'd like to move all of the code for
5314 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5315 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5316 + pkg_deinit for example). */
5317 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5318 +{
5319 + DIR *tmp_dir;
5320 + struct dirent *dirent;
5321 + char *tmp_file;
5322 +
5323 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5324 +#error
5325 + ipkg_message(conf, IPKG_DEBUG,
5326 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5327 + __FUNCTION__, pkg->tmp_unpack_dir);
5328 + return 0;
5329 +#endif
5330 +
5331 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5332 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5333 + if (tmp_dir) {
5334 + while (1) {
5335 + dirent = readdir(tmp_dir);
5336 + if (dirent == NULL) {
5337 + break;
5338 + }
5339 + sprintf_alloc(&tmp_file, "%s/%s",
5340 + pkg->tmp_unpack_dir, dirent->d_name);
5341 + if (! file_is_dir(tmp_file)) {
5342 + unlink(tmp_file);
5343 + }
5344 + free(tmp_file);
5345 + }
5346 + closedir(tmp_dir);
5347 + rmdir(pkg->tmp_unpack_dir);
5348 + free(pkg->tmp_unpack_dir);
5349 + pkg->tmp_unpack_dir = NULL;
5350 + }
5351 + }
5352 +
5353 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5354 + pkg->name, pkg->local_filename, conf->tmp_dir);
5355 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5356 + unlink(pkg->local_filename);
5357 + free(pkg->local_filename);
5358 + pkg->local_filename = NULL;
5359 + }
5360 +
5361 + return 0;
5362 +}
5363 +
5364 +static char *backup_filename_alloc(const char *file_name)
5365 +{
5366 + char *backup;
5367 +
5368 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5369 +
5370 + return backup;
5371 +}
5372 +
5373 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5374 +{
5375 + int err;
5376 + char *backup;
5377 +
5378 + backup = backup_filename_alloc(file_name);
5379 + err = file_copy(file_name, backup);
5380 + if (err) {
5381 + ipkg_message(conf, IPKG_ERROR,
5382 + "%s: Failed to copy %s to %s\n",
5383 + __FUNCTION__, file_name, backup);
5384 + }
5385 +
5386 + free(backup);
5387 +
5388 + return err;
5389 +}
5390 +
5391 +static int backup_exists_for(const char *file_name)
5392 +{
5393 + int ret;
5394 + char *backup;
5395 +
5396 + backup = backup_filename_alloc(file_name);
5397 +
5398 + ret = file_exists(backup);
5399 +
5400 + free(backup);
5401 +
5402 + return ret;
5403 +}
5404 +
5405 +static int backup_remove(const char *file_name)
5406 +{
5407 + char *backup;
5408 +
5409 + backup = backup_filename_alloc(file_name);
5410 + unlink(backup);
5411 + free(backup);
5412 +
5413 + return 0;
5414 +}
5415 +
5416 +\f
5417 +
5418 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5419 +
5420 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5421 +{
5422 + /* first, remove the packages that need removing */
5423 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5424 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5425 + err = ipkg_remove_pkg(conf, pkg);
5426 + if (err) return err;
5427 + }
5428 + return 0;
5429 +}
5430 +
5431 +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5432 +{
5433 + int i;
5434 + /* now one more pass checking on the ones that need to be installed */
5435 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5436 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5437 + if (pkg->dest == NULL)
5438 + pkg->dest = conf->default_dest;
5439 +
5440 + pkg->state_want = SW_INSTALL;
5441 +
5442 + /* Abhaya: conflicts check */
5443 + err = check_conflicts_for(conf, pkg);
5444 + if (err) { return err; }
5445 + }
5446 + return 0;
5447 +}
5448 +
5449 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5450 +{
5451 + int i;
5452 + /* now one more pass checking on the ones that need to be installed */
5453 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5454 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5455 +
5456 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5457 + pkg_vec_t *replacees = pkg_vec_alloc();
5458 + pkg_get_installed_replacees(conf, pkg, replacees);
5459 +
5460 + /* XXX: BUG: we really should treat replacement more like an upgrade
5461 + * Instead, we're going to remove the replacees
5462 + */
5463 + err = pkg_remove_installed_replacees(conf, replacees);
5464 + if (err) return err;
5465 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5466 + }
5467 + return 0;
5468 +}
5469 +
5470 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5471 +{
5472 + int i;
5473 + /* now one more pass checking on the ones that need to be installed */
5474 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5475 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5476 + if (pkg->local_filename == NULL) {
5477 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5478 + if (err) {
5479 + ipkg_message(conf, IPKG_ERROR,
5480 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5481 + pkg->name);
5482 + return err;
5483 + }
5484 + }
5485 + if (pkg->tmp_unpack_dir == NULL) {
5486 + err = unpack_pkg_control_files(conf, pkg);
5487 + if (err) return err;
5488 + }
5489 + }
5490 + return 0;
5491 +}
5492 +
5493 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5494 +{
5495 + int i;
5496 + /* now one more pass checking on the ones that need to be installed */
5497 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5498 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5499 + pkg_t *old_pkg = pkg->old_pkg;
5500 +
5501 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5502 + if (err) return err;
5503 +
5504 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5505 + if (err) return err;
5506 +
5507 + err = preinst_configure(conf, pkg, old_pkg);
5508 + if (err) return err;
5509 +
5510 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5511 + if (err) return err;
5512 +
5513 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5514 + if (err) return err;
5515 + }
5516 + return 0;
5517 +}
5518 +
5519 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5520 +{
5521 + int i;
5522 + /* now one more pass checking on the ones that need to be installed */
5523 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5524 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5525 + pkg_t *old_pkg = pkg->old_pkg;
5526 +
5527 + if (old_pkg) {
5528 + old_pkg->state_want = SW_DEINSTALL;
5529 +
5530 + if (old_pkg->state_flag & SF_NOPRUNE) {
5531 + ipkg_message(conf, IPKG_INFO,
5532 + " not removing obsolesced files because package marked noprune\n");
5533 + } else {
5534 + ipkg_message(conf, IPKG_INFO,
5535 + " removing obsolesced files\n");
5536 + remove_obsolesced_files(conf, pkg, old_pkg);
5537 + }
5538 + }
5539 +
5540 + ipkg_message(conf, IPKG_INFO,
5541 + " installing maintainer scripts\n");
5542 + install_maintainer_scripts(conf, pkg, old_pkg);
5543 +
5544 + /* the following just returns 0 */
5545 + remove_disappeared(conf, pkg);
5546 +
5547 + ipkg_message(conf, IPKG_INFO,
5548 + " installing data files\n");
5549 + install_data_files(conf, pkg);
5550 +
5551 + ipkg_message(conf, IPKG_INFO,
5552 + " resolving conf files\n");
5553 + resolve_conffiles(conf, pkg);
5554 +
5555 + pkg->state_status = SS_UNPACKED;
5556 +
5557 + if (old_pkg) {
5558 + old_pkg->state_status = SS_NOT_INSTALLED;
5559 + }
5560 +
5561 + time(&pkg->installed_time);
5562 +
5563 + ipkg_message(conf, IPKG_INFO,
5564 + " cleanup temp files\n");
5565 + cleanup_temporary_files(conf, pkg);
5566 +
5567 + if (pkg->parent)
5568 + pkg->parent->state_status = pkg->state_status;
5569 + }
5570 + return 0;
5571 +}
5572 +
5573 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5574 +{
5575 + int i;
5576 + /* now one more pass checking on the ones that need to be installed */
5577 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5578 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5579 + pkg_t *old_pkg = pkg->old_pkg;
5580 +
5581 + if (old_pkg) {
5582 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5583 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5584 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5585 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5586 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5587 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5588 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5589 + preinst_configure_unwind(conf, pkg, old_pkg);
5590 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5591 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5592 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5593 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5594 +
5595 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5596 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5597 +
5598 + }
5599 + }
5600 + return 0;
5601 +}
5602 +
5603 +/*
5604 + * Perform all the actions.
5605 + *
5606 + * pkgs_to_remove are packages marked for removal.
5607 + * pkgs_superseded are the old packages being replaced by upgrades.
5608 + *
5609 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5610 + */
5611 +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5612 +{
5613 + int err;
5614 + int i;
5615 +
5616 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5617 + if (err) return err;
5618 +
5619 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5620 + if (err) return err;
5621 +
5622 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5623 + if (err) goto UNWIND;
5624 +
5625 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5626 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5627 + if (err) goto UNWIND;
5628 +
5629 + /*
5630 + * Now that we have the packages unpacked, we can look for data
5631 + * file clashes. First, we mark the files from the superseded
5632 + * packages as obsolete. Then we scan the files in
5633 + * pkgs_to_install, and only complain about clashes with
5634 + * non-obsolete files.
5635 + */
5636 +
5637 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5638 + if (err) goto UNWIND;
5639 +
5640 + /* this was before checking data file clashes */
5641 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5642 + if (err) goto UNWIND;
5643 +
5644 + /* point of no return: no unwinding after this */
5645 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5646 + if (err) return err;
5647 +
5648 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5649 + return 0;
5650 +
5651 + UNWIND:
5652 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5653 +
5654 + ipkg_message(conf, IPKG_INFO,
5655 + " cleanup temp files\n");
5656 + cleanup_temporary_files(conf, pkg);
5657 +
5658 + ipkg_message(conf, IPKG_INFO,
5659 + "Failed.\n");
5660 + return err;
5661 +}
5662 +
5663 +#endif
5664 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_install.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_install.h
5665 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5666 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_install.h 2005-12-07 21:25:30.000000000 +0100
5667 @@ -0,0 +1,35 @@
5668 +/* ipkg_install.h - the itsy package management system
5669 +
5670 + Carl D. Worth
5671 +
5672 + Copyright (C) 2001 University of Southern California
5673 +
5674 + This program is free software; you can redistribute it and/or
5675 + modify it under the terms of the GNU General Public License as
5676 + published by the Free Software Foundation; either version 2, or (at
5677 + your option) any later version.
5678 +
5679 + This program is distributed in the hope that it will be useful, but
5680 + WITHOUT ANY WARRANTY; without even the implied warranty of
5681 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5682 + General Public License for more details.
5683 +*/
5684 +
5685 +#ifndef IPKG_INSTALL_H
5686 +#define IPKG_INSTALL_H
5687 +
5688 +#include "pkg.h"
5689 +#include "ipkg_conf.h"
5690 +
5691 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5692 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5693 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5694 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg);
5695 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5696 +
5697 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5698 +
5699 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5700 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5701 +
5702 +#endif
5703 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_message.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_message.c
5704 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5705 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_message.c 2005-12-07 21:25:30.000000000 +0100
5706 @@ -0,0 +1,61 @@
5707 +/* ipkg_message.c - the itsy package management system
5708 +
5709 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5710 +
5711 + This program is free software; you can redistribute it and/or
5712 + modify it under the terms of the GNU General Public License as
5713 + published by the Free Software Foundation; either version 2, or (at
5714 + your option) any later version.
5715 +
5716 + This program is distributed in the hope that it will be useful, but
5717 + WITHOUT ANY WARRANTY; without even the implied warranty of
5718 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5719 + General Public License for more details.
5720 +*/
5721 +
5722 +
5723 +#include "ipkg.h"
5724 +#include "ipkg_conf.h"
5725 +#include "ipkg_message.h"
5726 +
5727 +#ifndef IPKG_LIB
5728 +
5729 +void
5730 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5731 +{
5732 + va_list ap;
5733 +
5734 + if (conf && (conf->verbosity < level))
5735 + {
5736 + return;
5737 + }
5738 + else
5739 + {
5740 +
5741 + va_start (ap, fmt);
5742 + vprintf (fmt, ap);
5743 + va_end (ap);
5744 + }
5745 +}
5746 +
5747 +#else
5748 +
5749 +#include "libipkg.h"
5750 +
5751 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5752 +
5753 +void
5754 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5755 +{
5756 + va_list ap;
5757 + char ts[256];
5758 +
5759 + if (ipkg_cb_message)
5760 + {
5761 + va_start (ap, fmt);
5762 + vsnprintf (ts,256,fmt, ap);
5763 + va_end (ap);
5764 + ipkg_cb_message(conf,level,ts);
5765 + }
5766 +}
5767 +#endif
5768 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_message.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_message.h
5769 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5770 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_message.h 2005-12-07 21:25:30.000000000 +0100
5771 @@ -0,0 +1,32 @@
5772 +/* ipkg_message.h - the itsy package management system
5773 +
5774 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5775 +
5776 + This program is free software; you can redistribute it and/or
5777 + modify it under the terms of the GNU General Public License as
5778 + published by the Free Software Foundation; either version 2, or (at
5779 + your option) any later version.
5780 +
5781 + This program is distributed in the hope that it will be useful, but
5782 + WITHOUT ANY WARRANTY; without even the implied warranty of
5783 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5784 + General Public License for more details.
5785 +*/
5786 +
5787 +#ifndef _IPKG_MESSAGE_H_
5788 +#define _IPKG_MESSAGE_H_
5789 +
5790 +#include "ipkg.h"
5791 +#include "ipkg_conf.h"
5792 +
5793 +typedef enum {
5794 + IPKG_ERROR, /* error conditions */
5795 + IPKG_NOTICE, /* normal but significant condition */
5796 + IPKG_INFO, /* informational message */
5797 + IPKG_DEBUG, /* debug level message */
5798 + IPKG_DEBUG2, /* more debug level message */
5799 +} message_level_t;
5800 +
5801 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5802 +
5803 +#endif /* _IPKG_MESSAGE_H_ */
5804 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_remove.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_remove.c
5805 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5806 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_remove.c 2005-12-07 21:25:30.000000000 +0100
5807 @@ -0,0 +1,381 @@
5808 +/* ipkg_remove.c - the itsy package management system
5809 +
5810 + Carl D. Worth
5811 +
5812 + Copyright (C) 2001 University of Southern California
5813 +
5814 + This program is free software; you can redistribute it and/or
5815 + modify it under the terms of the GNU General Public License as
5816 + published by the Free Software Foundation; either version 2, or (at
5817 + your option) any later version.
5818 +
5819 + This program is distributed in the hope that it will be useful, but
5820 + WITHOUT ANY WARRANTY; without even the implied warranty of
5821 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5822 + General Public License for more details.
5823 +*/
5824 +
5825 +#include "ipkg.h"
5826 +#include "ipkg_message.h"
5827 +
5828 +#include <glob.h>
5829 +
5830 +#include "ipkg_remove.h"
5831 +
5832 +#include "file_util.h"
5833 +#include "sprintf_alloc.h"
5834 +#include "str_util.h"
5835 +
5836 +#include "ipkg_cmd.h"
5837 +
5838 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
5839 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5840 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5841 +
5842 +/*
5843 + * Returns number of the number of packages depending on the packages provided by this package.
5844 + * Every package implicitly provides itself.
5845 + */
5846 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5847 +{
5848 + int nprovides = pkg->provides_count;
5849 + abstract_pkg_t **provides = pkg->provides;
5850 + int n_installed_dependents = 0;
5851 + int i;
5852 + for (i = 0; i <= nprovides; i++) {
5853 + abstract_pkg_t *providee = provides[i];
5854 + abstract_pkg_t **dependers = providee->depended_upon_by;
5855 + abstract_pkg_t *dep_ab_pkg;
5856 + if (dependers == NULL)
5857 + continue;
5858 + while ((dep_ab_pkg = *dependers++) != NULL) {
5859 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5860 + n_installed_dependents++;
5861 + }
5862 + }
5863 +
5864 + }
5865 + /* if caller requested the set of installed dependents */
5866 + if (pdependents) {
5867 + int p = 0;
5868 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5869 +
5870 + if ( dependents == NULL ){
5871 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5872 + return -1;
5873 + }
5874 +
5875 + *pdependents = dependents;
5876 + for (i = 0; i <= nprovides; i++) {
5877 + abstract_pkg_t *providee = provides[i];
5878 + abstract_pkg_t **dependers = providee->depended_upon_by;
5879 + abstract_pkg_t *dep_ab_pkg;
5880 + if (dependers == NULL)
5881 + continue;
5882 + while ((dep_ab_pkg = *dependers++) != NULL) {
5883 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5884 + dependents[p++] = dep_ab_pkg;
5885 + dep_ab_pkg->state_flag |= SF_MARKED;
5886 + }
5887 + }
5888 + }
5889 + dependents[p] = NULL;
5890 + /* now clear the marks */
5891 + for (i = 0; i < p; i++) {
5892 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5893 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5894 + }
5895 + }
5896 + return n_installed_dependents;
5897 +}
5898 +
5899 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5900 +{
5901 + int i;
5902 + int a;
5903 + int count;
5904 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5905 + abstract_pkg_t * ab_pkg;
5906 +
5907 + if((ab_pkg = pkg->parent) == NULL){
5908 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5909 + __FUNCTION__, pkg->name);
5910 + return 0;
5911 + }
5912 +
5913 + if (dependents == NULL)
5914 + return 0;
5915 +
5916 + // here i am using the dependencies_checked
5917 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5918 + return 0; // has already been encountered in the process
5919 + // of marking packages for removal - Karthik
5920 + ab_pkg->dependencies_checked = 2;
5921 +
5922 + i = 0;
5923 + count = 1;
5924 + while (dependents [i] != NULL) {
5925 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5926 +
5927 + if (dep_ab_pkg->dependencies_checked == 2){
5928 + i++;
5929 + continue;
5930 + }
5931 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5932 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5933 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5934 + if (dep_pkg->state_status == SS_INSTALLED) {
5935 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5936 + count++;
5937 + }
5938 + }
5939 + }
5940 + i++;
5941 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5942 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5943 + }
5944 +
5945 + if (count == 1)
5946 + return 0;
5947 +
5948 +
5949 + for (i = 0; i < dependent_pkgs->len; i++) {
5950 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5951 + if (err)
5952 + return err;
5953 + }
5954 + return 0;
5955 +}
5956 +
5957 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5958 +{
5959 + abstract_pkg_t *dep_ab_pkg;
5960 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5961 + while ((dep_ab_pkg = *dependents++) != NULL) {
5962 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5963 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5964 + }
5965 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5966 + ipkg_message(conf, IPKG_ERROR, "");
5967 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5968 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5969 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5970 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5971 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5972 + return 0;
5973 +}
5974 +
5975 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5976 +{
5977 + int err;
5978 + abstract_pkg_t *parent_pkg = NULL;
5979 +
5980 + if (pkg->essential) {
5981 + if (conf->force_removal_of_essential_packages) {
5982 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5983 + "\tIf your system breaks, you get to keep both pieces\n",
5984 + pkg->name);
5985 + } else {
5986 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5987 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5988 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5989 + "\tits will with the option: -force-removal-of-essential-packages\n",
5990 + pkg->name);
5991 + return IPKG_PKG_IS_ESSENTIAL;
5992 + }
5993 + }
5994 +
5995 + if ((parent_pkg = pkg->parent) == NULL)
5996 + return 0;
5997 +
5998 + /* only attempt to remove dependent installed packages if
5999 + * force_depends is not specified or the package is being
6000 + * replaced.
6001 + */
6002 + if (!conf->force_depends
6003 + && !(pkg->state_flag & SF_REPLACE)) {
6004 + abstract_pkg_t **dependents;
6005 + int has_installed_dependents =
6006 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6007 +
6008 + if (has_installed_dependents) {
6009 + /*
6010 + * if this package is depended up by others, then either we should
6011 + * not remove it or we should remove it and all of its dependents
6012 + */
6013 +
6014 + if (!conf->force_removal_of_dependent_packages
6015 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6016 + return IPKG_PKG_HAS_DEPENDENTS;
6017 + }
6018 +
6019 + /* remove packages depending on this package - Karthik */
6020 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6021 + free(dependents);
6022 + if (err) return err;
6023 + }
6024 + }
6025 +
6026 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6027 + fflush(stdout);
6028 +
6029 + pkg->state_flag |= SF_FILELIST_CHANGED;
6030 +
6031 + pkg->state_want = SW_DEINSTALL;
6032 + ipkg_state_changed++;
6033 +
6034 + pkg_run_script(conf, pkg, "prerm", "remove");
6035 +
6036 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6037 + maintains an empty filelist rather than deleting it. That seems
6038 + like a big pain, and I don't see that that should make a big
6039 + difference, but for anyone who wants tighter compatibility,
6040 + feel free to fix this. */
6041 + remove_data_files_and_list(conf, pkg);
6042 +
6043 + pkg_run_script(conf, pkg, "postrm", "remove");
6044 +
6045 + remove_maintainer_scripts_except_postrm(conf, pkg);
6046 +
6047 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6048 + * space, it doesn't make sense to leave extra configurations, files,
6049 + * and maintainer scripts left around. So, we make remove like purge,
6050 + * and take out all the crap :) */
6051 +
6052 + remove_postrm(conf, pkg);
6053 + pkg->state_status = SS_NOT_INSTALLED;
6054 +
6055 + if (parent_pkg)
6056 + parent_pkg->state_status = SS_NOT_INSTALLED;
6057 +
6058 + return 0;
6059 +}
6060 +
6061 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6062 +{
6063 + ipkg_remove_pkg(conf, pkg);
6064 + return 0;
6065 +}
6066 +
6067 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6068 +{
6069 + str_list_t installed_dirs;
6070 + str_list_t *installed_files;
6071 + str_list_elt_t *iter;
6072 + char *file_name;
6073 + conffile_t *conffile;
6074 + int removed_a_dir;
6075 + pkg_t *owner;
6076 +
6077 + str_list_init(&installed_dirs);
6078 + installed_files = pkg_get_installed_files(pkg);
6079 +
6080 + for (iter = installed_files->head; iter; iter = iter->next) {
6081 + file_name = iter->data;
6082 +
6083 + if (file_is_dir(file_name)) {
6084 + str_list_append(&installed_dirs, strdup(file_name));
6085 + continue;
6086 + }
6087 +
6088 + conffile = pkg_get_conffile(pkg, file_name);
6089 + if (conffile) {
6090 + /* XXX: QUESTION: Is this right? I figure we only need to
6091 + save the conffile if it has been modified. Is that what
6092 + dpkg does? Or does dpkg preserve all conffiles? If so,
6093 + this seems like a better thing to do to conserve
6094 + space. */
6095 + if (conffile_has_been_modified(conf, conffile)) {
6096 + printf(" not deleting modified conffile %s\n", file_name);
6097 + fflush(stdout);
6098 + continue;
6099 + }
6100 + }
6101 +
6102 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6103 + if (!conf->noaction)
6104 + unlink(file_name);
6105 + }
6106 +
6107 + if (!conf->noaction) {
6108 + do {
6109 + removed_a_dir = 0;
6110 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6111 + file_name = iter->data;
6112 +
6113 + if (rmdir(file_name) == 0) {
6114 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6115 + removed_a_dir = 1;
6116 + str_list_remove(&installed_dirs, &iter);
6117 + }
6118 + }
6119 + } while (removed_a_dir);
6120 + }
6121 +
6122 + pkg_free_installed_files(pkg);
6123 + /* We have to remove the file list now, so that
6124 + find_pkg_owning_file does not always just report this package */
6125 + pkg_remove_installed_files_list(conf, pkg);
6126 +
6127 + /* Don't print warning for dirs that are provided by other packages */
6128 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6129 + file_name = iter->data;
6130 +
6131 + owner = file_hash_get_file_owner(conf, file_name);
6132 + if (owner) {
6133 + free(iter->data);
6134 + iter->data = NULL;
6135 + str_list_remove(&installed_dirs, &iter);
6136 + }
6137 + }
6138 +
6139 + /* cleanup */
6140 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6141 + free(iter->data);
6142 + iter->data = NULL;
6143 + }
6144 + str_list_deinit(&installed_dirs);
6145 +
6146 + return 0;
6147 +}
6148 +
6149 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6150 +{
6151 + int i, err;
6152 + char *globpattern;
6153 + glob_t globbuf;
6154 +
6155 + if (conf->noaction) return 0;
6156 +
6157 + sprintf_alloc(&globpattern, "%s/%s.*",
6158 + pkg->dest->info_dir, pkg->name);
6159 + err = glob(globpattern, 0, NULL, &globbuf);
6160 + free(globpattern);
6161 + if (err) {
6162 + return 0;
6163 + }
6164 +
6165 + for (i = 0; i < globbuf.gl_pathc; i++) {
6166 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6167 + continue;
6168 + }
6169 + unlink(globbuf.gl_pathv[i]);
6170 + }
6171 + globfree(&globbuf);
6172 +
6173 + return 0;
6174 +}
6175 +
6176 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6177 +{
6178 + char *postrm_file_name;
6179 +
6180 + if (conf->noaction) return 0;
6181 +
6182 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6183 + pkg->dest->info_dir, pkg->name);
6184 + unlink(postrm_file_name);
6185 + free(postrm_file_name);
6186 +
6187 + return 0;
6188 +}
6189 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_remove.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_remove.h
6190 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6191 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_remove.h 2005-12-07 21:25:30.000000000 +0100
6192 @@ -0,0 +1,29 @@
6193 +/* ipkg_remove.h - the itsy package management system
6194 +
6195 + Carl D. Worth
6196 +
6197 + Copyright (C) 2001 University of Southern California
6198 +
6199 + This program is free software; you can redistribute it and/or
6200 + modify it under the terms of the GNU General Public License as
6201 + published by the Free Software Foundation; either version 2, or (at
6202 + your option) any later version.
6203 +
6204 + This program is distributed in the hope that it will be useful, but
6205 + WITHOUT ANY WARRANTY; without even the implied warranty of
6206 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6207 + General Public License for more details.
6208 +*/
6209 +
6210 +#ifndef IPKG_REMOVE_H
6211 +#define IPKG_REMOVE_H
6212 +
6213 +#include "pkg.h"
6214 +#include "ipkg_conf.h"
6215 +
6216 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6217 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6218 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6219 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6220 +
6221 +#endif
6222 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_upgrade.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_upgrade.c
6223 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6224 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_upgrade.c 2005-12-07 21:25:30.000000000 +0100
6225 @@ -0,0 +1,77 @@
6226 +/* ipkg_upgrade.c - the itsy package management system
6227 +
6228 + Carl D. Worth
6229 + Copyright (C) 2001 University of Southern California
6230 +
6231 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6232 +
6233 + This program is free software; you can redistribute it and/or
6234 + modify it under the terms of the GNU General Public License as
6235 + published by the Free Software Foundation; either version 2, or (at
6236 + your option) any later version.
6237 +
6238 + This program is distributed in the hope that it will be useful, but
6239 + WITHOUT ANY WARRANTY; without even the implied warranty of
6240 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6241 + General Public License for more details.
6242 +*/
6243 +
6244 +#include "ipkg.h"
6245 +#include "ipkg_install.h"
6246 +#include "ipkg_message.h"
6247 +
6248 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6249 +{
6250 + pkg_t *new;
6251 + int cmp;
6252 + char *old_version, *new_version;
6253 +
6254 + if (old->state_flag & SF_HOLD) {
6255 + ipkg_message(conf, IPKG_NOTICE,
6256 + "Not upgrading package %s which is marked "
6257 + "hold (flags=%#x)\n", old->name, old->state_flag);
6258 + return 0;
6259 + }
6260 +
6261 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6262 + if (new == NULL) {
6263 + old_version = pkg_version_str_alloc(old);
6264 + ipkg_message(conf, IPKG_NOTICE,
6265 + "Assuming locally installed package %s (%s) "
6266 + "is up to date.\n", old->name, old_version);
6267 + free(old_version);
6268 + return 0;
6269 + }
6270 +
6271 + old_version = pkg_version_str_alloc(old);
6272 + new_version = pkg_version_str_alloc(new);
6273 +
6274 + cmp = pkg_compare_versions(old, new);
6275 + ipkg_message(conf, IPKG_DEBUG,
6276 + "comparing visible versions of pkg %s:"
6277 + "\n\t%s is installed "
6278 + "\n\t%s is available "
6279 + "\n\t%d was comparison result\n",
6280 + old->name, old_version, new_version, cmp);
6281 + if (cmp == 0) {
6282 + ipkg_message(conf, IPKG_INFO,
6283 + "Package %s (%s) installed in %s is up to date.\n",
6284 + old->name, old_version, old->dest->name);
6285 + free(old_version);
6286 + free(new_version);
6287 + return 0;
6288 + } else if (cmp > 0) {
6289 + ipkg_message(conf, IPKG_NOTICE,
6290 + "Not downgrading package %s on %s from %s to %s.\n",
6291 + old->name, old->dest->name, old_version, new_version);
6292 + free(old_version);
6293 + free(new_version);
6294 + return 0;
6295 + } else if (cmp < 0) {
6296 + new->dest = old->dest;
6297 + old->state_want = SW_DEINSTALL;
6298 + }
6299 +
6300 + new->state_flag |= SF_USER;
6301 + return ipkg_install_pkg(conf, new);
6302 +}
6303 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_upgrade.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_upgrade.h
6304 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6305 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_upgrade.h 2005-12-07 21:25:30.000000000 +0100
6306 @@ -0,0 +1,18 @@
6307 +/* ipkg_upgrade.c - the itsy package management system
6308 +
6309 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6310 +
6311 + This program is free software; you can redistribute it and/or
6312 + modify it under the terms of the GNU General Public License as
6313 + published by the Free Software Foundation; either version 2, or (at
6314 + your option) any later version.
6315 +
6316 + This program is distributed in the hope that it will be useful, but
6317 + WITHOUT ANY WARRANTY; without even the implied warranty of
6318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6319 + General Public License for more details.
6320 +*/
6321 +
6322 +#include "ipkg.h"
6323 +
6324 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6325 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_utils.c busybox-1.1.0-pre1-new/archival/libipkg/ipkg_utils.c
6326 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6327 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_utils.c 2005-12-07 21:25:30.000000000 +0100
6328 @@ -0,0 +1,181 @@
6329 +/* ipkg_utils.c - the itsy package management system
6330 +
6331 + Steven M. Ayer
6332 +
6333 + Copyright (C) 2002 Compaq Computer Corporation
6334 +
6335 + This program is free software; you can redistribute it and/or
6336 + modify it under the terms of the GNU General Public License as
6337 + published by the Free Software Foundation; either version 2, or (at
6338 + your option) any later version.
6339 +
6340 + This program is distributed in the hope that it will be useful, but
6341 + WITHOUT ANY WARRANTY; without even the implied warranty of
6342 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6343 + General Public License for more details.
6344 +*/
6345 +
6346 +#include "ipkg.h"
6347 +#include <errno.h>
6348 +#include <ctype.h>
6349 +#include <sys/vfs.h>
6350 +
6351 +#include "ipkg_utils.h"
6352 +#include "pkg.h"
6353 +#include "pkg_hash.h"
6354 +
6355 +struct errlist* error_list;
6356 +
6357 +int get_available_blocks(char * filesystem)
6358 +{
6359 + struct statfs sfs;
6360 +
6361 + if(statfs(filesystem, &sfs)){
6362 + fprintf(stderr, "bad statfs\n");
6363 + return 0;
6364 + }
6365 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6366 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6367 +}
6368 +
6369 +char **read_raw_pkgs_from_file(const char *file_name)
6370 +{
6371 + FILE *fp;
6372 + char **ret;
6373 +
6374 + if(!(fp = fopen(file_name, "r"))){
6375 + fprintf(stderr, "can't get %s open for read\n", file_name);
6376 + return NULL;
6377 + }
6378 +
6379 + ret = read_raw_pkgs_from_stream(fp);
6380 +
6381 + fclose(fp);
6382 +
6383 + return ret;
6384 +}
6385 +
6386 +char **read_raw_pkgs_from_stream(FILE *fp)
6387 +{
6388 + char **raw = NULL, *buf, *scout;
6389 + int count = 0;
6390 + size_t size = 512;
6391 +
6392 + buf = malloc (size);
6393 +
6394 + while (fgets(buf, size, fp)) {
6395 + while (strlen (buf) == (size - 1)
6396 + && buf[size-2] != '\n') {
6397 + size_t o = size - 1;
6398 + size *= 2;
6399 + buf = realloc (buf, size);
6400 + if (fgets (buf + o, size - o, fp) == NULL)
6401 + break;
6402 + }
6403 +
6404 + if(!(count % 50))
6405 + raw = realloc(raw, (count + 50) * sizeof(char *));
6406 +
6407 + if((scout = strchr(buf, '\n')))
6408 + *scout = '\0';
6409 +
6410 + raw[count++] = strdup(buf);
6411 + }
6412 +
6413 + raw = realloc(raw, (count + 1) * sizeof(char *));
6414 + raw[count] = NULL;
6415 +
6416 + free (buf);
6417 +
6418 + return raw;
6419 +}
6420 +
6421 +/* something to remove whitespace, a hash pooper */
6422 +char *trim_alloc(char *line)
6423 +{
6424 + char *new;
6425 + char *dest, *src, *end;
6426 +
6427 + new = malloc(strlen(line) + 1);
6428 + if ( new == NULL ){
6429 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6430 + return NULL;
6431 + }
6432 + dest = new, src = line, end = line + (strlen(line) - 1);
6433 +
6434 + /* remove it from the front */
6435 + while(src &&
6436 + isspace(*src) &&
6437 + *src)
6438 + src++;
6439 + /* and now from the back */
6440 + while((end > src) &&
6441 + isspace(*end))
6442 + end--;
6443 + end++;
6444 + *end = '\0';
6445 + strcpy(new, src);
6446 + /* this does from the first space
6447 + * blasting away any versions stuff in depends
6448 + while(src &&
6449 + !isspace(*src) &&
6450 + *src)
6451 + *dest++ = *src++;
6452 + *dest = '\0';
6453 + */
6454 +
6455 + return new;
6456 +}
6457 +
6458 +int line_is_blank(const char *line)
6459 +{
6460 + const char *s;
6461 +
6462 + for (s = line; *s; s++) {
6463 + if (!isspace(*s))
6464 + return 0;
6465 + }
6466 + return 1;
6467 +}
6468 +
6469 +void push_error_list(struct errlist ** errors, char * msg){
6470 + struct errlist *err_lst_tmp;
6471 +
6472 +
6473 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6474 + err_lst_tmp->errmsg=strdup(msg) ;
6475 + err_lst_tmp->next = *errors;
6476 + *errors = err_lst_tmp;
6477 +}
6478 +
6479 +
6480 +void reverse_error_list(struct errlist **errors){
6481 + struct errlist *result=NULL;
6482 + struct errlist *current= *errors;
6483 + struct errlist *next;
6484 +
6485 + while ( current != NULL ) {
6486 + next = current->next;
6487 + current->next=result;
6488 + result=current;
6489 + current=next;
6490 + }
6491 + *errors=result;
6492 +
6493 +}
6494 +
6495 +
6496 +void free_error_list(struct errlist **errors){
6497 + struct errlist *current = *errors;
6498 +
6499 + while (current != NULL) {
6500 + free(current->errmsg);
6501 + current = (*errors)->next;
6502 + free(*errors);
6503 + *errors = current;
6504 + }
6505 +
6506 +
6507 +}
6508 +
6509 +
6510 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/ipkg_utils.h busybox-1.1.0-pre1-new/archival/libipkg/ipkg_utils.h
6511 --- busybox-1.1.0-pre1-old/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6512 +++ busybox-1.1.0-pre1-new/archival/libipkg/ipkg_utils.h 2005-12-07 21:25:30.000000000 +0100
6513 @@ -0,0 +1,29 @@
6514 +/* ipkg_utils.h - the itsy package management system
6515 +
6516 + Steven M. Ayer
6517 +
6518 + Copyright (C) 2002 Compaq Computer Corporation
6519 +
6520 + This program is free software; you can redistribute it and/or
6521 + modify it under the terms of the GNU General Public License as
6522 + published by the Free Software Foundation; either version 2, or (at
6523 + your option) any later version.
6524 +
6525 + This program is distributed in the hope that it will be useful, but
6526 + WITHOUT ANY WARRANTY; without even the implied warranty of
6527 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6528 + General Public License for more details.
6529 +*/
6530 +
6531 +#ifndef IPKG_UTILS_H
6532 +#define IPKG_UTILS_H
6533 +
6534 +#include "pkg.h"
6535 +
6536 +int get_available_blocks(char * filesystem);
6537 +char **read_raw_pkgs_from_file(const char *file_name);
6538 +char **read_raw_pkgs_from_stream(FILE *fp);
6539 +char *trim_alloc(char * line);
6540 +int line_is_blank(const char *line);
6541 +
6542 +#endif
6543 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/libipkg.c busybox-1.1.0-pre1-new/archival/libipkg/libipkg.c
6544 --- busybox-1.1.0-pre1-old/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6545 +++ busybox-1.1.0-pre1-new/archival/libipkg/libipkg.c 2005-12-07 21:25:30.000000000 +0100
6546 @@ -0,0 +1,512 @@
6547 +/* ipkglib.c - the itsy package management system
6548 +
6549 + Florina Boor
6550 +
6551 + Copyright (C) 2003 kernel concepts
6552 +
6553 + This program is free software; you can redistribute it and/or
6554 + modify it under the terms of the GNU General Public License as
6555 + published by the Free Software Foundation; either version 2, or (at
6556 + your option) any later version.
6557 +
6558 + This program is distributed in the hope that it will be useful, but
6559 + WITHOUT ANY WARRANTY; without even the implied warranty of
6560 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6561 + General Public License for more details.
6562 +*/
6563 +
6564 +#ifdef IPKG_LIB
6565 +
6566 +#include "ipkg.h"
6567 +#include "ipkg_includes.h"
6568 +#include "libipkg.h"
6569 +
6570 +#include "args.h"
6571 +#include "ipkg_conf.h"
6572 +#include "ipkg_cmd.h"
6573 +#include "file_util.h"
6574 +
6575 +
6576 +
6577 +ipkg_message_callback ipkg_cb_message = NULL;
6578 +ipkg_response_callback ipkg_cb_response = NULL;
6579 +ipkg_status_callback ipkg_cb_status = NULL;
6580 +ipkg_list_callback ipkg_cb_list = NULL;
6581 +
6582 +
6583 +int
6584 +ipkg_init (ipkg_message_callback mcall,
6585 + ipkg_response_callback rcall,
6586 + args_t * args)
6587 +{
6588 + ipkg_cb_message = mcall;
6589 + ipkg_cb_response = rcall;
6590 +
6591 + args_init (args);
6592 +
6593 + return 0;
6594 +}
6595 +
6596 +
6597 +int
6598 +ipkg_deinit (args_t * args)
6599 +{
6600 + args_deinit (args);
6601 + ipkg_cb_message = NULL;
6602 + ipkg_cb_response = NULL;
6603 +
6604 + /* place other cleanup stuff here */
6605 +
6606 + return 0;
6607 +}
6608 +
6609 +
6610 +int
6611 +ipkg_packages_list(args_t *args,
6612 + const char *packages,
6613 + ipkg_list_callback cblist,
6614 + void *userdata)
6615 +{
6616 + ipkg_cmd_t *cmd;
6617 + ipkg_conf_t ipkg_conf;
6618 + int err;
6619 +
6620 + err = ipkg_conf_init (&ipkg_conf, args);
6621 + if (err)
6622 + {
6623 + return err;
6624 + }
6625 +
6626 + ipkg_cb_list = cblist;
6627 + /* we need to do this because of static declarations,
6628 + * maybe a good idea to change */
6629 + cmd = ipkg_cmd_find ("list");
6630 + if (packages)
6631 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6632 + else
6633 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6634 + ipkg_cb_list = NULL;
6635 + ipkg_conf_deinit (&ipkg_conf);
6636 + return (err);
6637 +}
6638 +
6639 +
6640 +int
6641 +ipkg_packages_status(args_t *args,
6642 + const char *packages,
6643 + ipkg_status_callback cbstatus,
6644 + void *userdata)
6645 +{
6646 + ipkg_cmd_t *cmd;
6647 + ipkg_conf_t ipkg_conf;
6648 + int err;
6649 +
6650 + err = ipkg_conf_init (&ipkg_conf, args);
6651 + if (err)
6652 + {
6653 + return err;
6654 + }
6655 +
6656 + ipkg_cb_status = cbstatus;
6657 +
6658 + /* we need to do this because of static declarations,
6659 + * maybe a good idea to change */
6660 + cmd = ipkg_cmd_find ("status");
6661 + if (packages)
6662 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6663 + else
6664 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6665 +
6666 + ipkg_cb_status = NULL;
6667 + ipkg_conf_deinit (&ipkg_conf);
6668 + return (err);
6669 +}
6670 +
6671 +
6672 +int
6673 +ipkg_packages_info(args_t *args,
6674 + const char *packages,
6675 + ipkg_status_callback cbstatus,
6676 + void *userdata)
6677 +{
6678 + ipkg_cmd_t *cmd;
6679 + ipkg_conf_t ipkg_conf;
6680 + int err;
6681 +
6682 + err = ipkg_conf_init (&ipkg_conf, args);
6683 + if (err)
6684 + {
6685 + return err;
6686 + }
6687 +
6688 + ipkg_cb_status = cbstatus;
6689 +
6690 + /* we need to do this because of static declarations,
6691 + * maybe a good idea to change */
6692 + cmd = ipkg_cmd_find ("info");
6693 + if (packages)
6694 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6695 + else
6696 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6697 +
6698 + ipkg_cb_status = NULL;
6699 + ipkg_conf_deinit (&ipkg_conf);
6700 + return (err);
6701 +}
6702 +
6703 +
6704 +int
6705 +ipkg_packages_install (args_t * args, const char *name)
6706 +{
6707 + ipkg_cmd_t *cmd;
6708 + ipkg_conf_t ipkg_conf;
6709 + int err;
6710 +
6711 + /* this error should be handled in application */
6712 + if (!name || !strlen (name))
6713 + return (-1);
6714 +
6715 + err = ipkg_conf_init (&ipkg_conf, args);
6716 + if (err)
6717 + {
6718 + return err;
6719 + }
6720 +
6721 + /* we need to do this because of static declarations,
6722 + * maybe a good idea to change */
6723 + cmd = ipkg_cmd_find ("install");
6724 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6725 +
6726 + ipkg_conf_deinit(&ipkg_conf);
6727 + return (err);
6728 +}
6729 +
6730 +
6731 +int
6732 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6733 +{
6734 + ipkg_cmd_t *cmd;
6735 + ipkg_conf_t ipkg_conf;
6736 + int err;
6737 +
6738 + /* this error should be handled in application */
6739 + if (!name || !strlen (name))
6740 + return (-1);
6741 +
6742 + err = ipkg_conf_init (&ipkg_conf, args);
6743 + if (err)
6744 + {
6745 + return err;
6746 + }
6747 +
6748 + /* we need to do this because of static declarations,
6749 + * maybe a good idea to change */
6750 + if (purge)
6751 + cmd = ipkg_cmd_find ("purge");
6752 + else
6753 + cmd = ipkg_cmd_find ("remove");
6754 +
6755 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6756 +
6757 + ipkg_conf_deinit(&ipkg_conf);
6758 + return (err);
6759 +}
6760 +
6761 +
6762 +int
6763 +ipkg_lists_update(args_t *args)
6764 +{
6765 + ipkg_cmd_t *cmd;
6766 + ipkg_conf_t ipkg_conf;
6767 + int err;
6768 +
6769 + err = ipkg_conf_init (&ipkg_conf, args);
6770 + if (err)
6771 + {
6772 + return err;
6773 + }
6774 +
6775 + /* we need to do this because of static declarations,
6776 + * maybe a good idea to change */
6777 + cmd = ipkg_cmd_find ("update");
6778 +
6779 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6780 +
6781 + ipkg_conf_deinit(&ipkg_conf);
6782 + return (err);
6783 +}
6784 +
6785 +
6786 +int
6787 +ipkg_packages_upgrade(args_t *args)
6788 +{
6789 + ipkg_cmd_t *cmd;
6790 + ipkg_conf_t ipkg_conf;
6791 + int err;
6792 +
6793 + err = ipkg_conf_init (&ipkg_conf, args);
6794 + if (err)
6795 + {
6796 + return err;
6797 + }
6798 +
6799 + /* we need to do this because of static declarations,
6800 + * maybe a good idea to change */
6801 + cmd = ipkg_cmd_find ("upgrade");
6802 +
6803 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6804 +
6805 + ipkg_conf_deinit(&ipkg_conf);
6806 + return (err);
6807 +}
6808 +
6809 +
6810 +int
6811 +ipkg_packages_download (args_t * args, const char *name)
6812 +{
6813 + ipkg_cmd_t *cmd;
6814 + ipkg_conf_t ipkg_conf;
6815 + int err;
6816 +
6817 + /* this error should be handled in application */
6818 + if (!name || !strlen (name))
6819 + return (-1);
6820 +
6821 + err = ipkg_conf_init (&ipkg_conf, args);
6822 + if (err)
6823 + {
6824 + return err;
6825 + }
6826 +
6827 + /* we need to do this because of static declarations,
6828 + * maybe a good idea to change */
6829 + cmd = ipkg_cmd_find ("download");
6830 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6831 +
6832 + ipkg_conf_deinit(&ipkg_conf);
6833 + return (err);
6834 +}
6835 +
6836 +
6837 +int
6838 +ipkg_package_files(args_t *args,
6839 + const char *name,
6840 + ipkg_list_callback cblist,
6841 + void *userdata)
6842 +{
6843 + ipkg_cmd_t *cmd;
6844 + ipkg_conf_t ipkg_conf;
6845 + int err;
6846 +
6847 + /* this error should be handled in application */
6848 + if (!name || !strlen (name))
6849 + return (-1);
6850 +
6851 + err = ipkg_conf_init (&ipkg_conf, args);
6852 + if (err)
6853 + {
6854 + return err;
6855 + }
6856 +
6857 + ipkg_cb_list = cblist;
6858 +
6859 + /* we need to do this because of static declarations,
6860 + * maybe a good idea to change */
6861 + cmd = ipkg_cmd_find ("files");
6862 +
6863 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6864 +
6865 + ipkg_cb_list = NULL;
6866 + ipkg_conf_deinit(&ipkg_conf);
6867 + return (err);
6868 +}
6869 +
6870 +
6871 +int
6872 +ipkg_file_search(args_t *args,
6873 + const char *file,
6874 + ipkg_list_callback cblist,
6875 + void *userdata)
6876 +{
6877 + ipkg_cmd_t *cmd;
6878 + ipkg_conf_t ipkg_conf;
6879 + int err;
6880 +
6881 + /* this error should be handled in application */
6882 + if (!file || !strlen (file))
6883 + return (-1);
6884 +
6885 + err = ipkg_conf_init (&ipkg_conf, args);
6886 + if (err)
6887 + {
6888 + return err;
6889 + }
6890 +
6891 + ipkg_cb_list = cblist;
6892 +
6893 + /* we need to do this because of static declarations,
6894 + * maybe a good idea to change */
6895 + cmd = ipkg_cmd_find ("search");
6896 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6897 +
6898 + ipkg_cb_list = NULL;
6899 + ipkg_conf_deinit(&ipkg_conf);
6900 + return(err);
6901 +}
6902 +
6903 +
6904 +int
6905 +ipkg_file_what(args_t *args, const char *file, const char* command)
6906 +{
6907 + ipkg_cmd_t *cmd;
6908 + ipkg_conf_t ipkg_conf;
6909 + int err;
6910 +
6911 + /* this error should be handled in application */
6912 + if (!file || !strlen (file))
6913 + return (-1);
6914 +
6915 + err = ipkg_conf_init (&ipkg_conf, args);
6916 + if (err)
6917 + {
6918 + return err;
6919 + }
6920 +
6921 + /* we need to do this because of static declarations,
6922 + * maybe a good idea to change */
6923 + cmd = ipkg_cmd_find (command);
6924 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6925 +
6926 + ipkg_conf_deinit(&ipkg_conf);
6927 + return(err);
6928 +}
6929 +
6930 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6931 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6932 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6933 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6934 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6935 +
6936 +
6937 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6938 + char *msg)
6939 +{
6940 + if (conf && (conf->verbosity < level)) {
6941 + return 0;
6942 + } else {
6943 +#ifdef IPKG_LIB
6944 + if ( level == IPKG_ERROR ){
6945 + push_error_list(&error_list, msg);
6946 +// printf(msg);
6947 + } else
6948 +#endif
6949 + printf(msg);
6950 + }
6951 + return 0;
6952 +}
6953 +
6954 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6955 + pkg_state_status_t status, void *userdata)
6956 +{
6957 + if (desc)
6958 + printf("%s - %s - %s\n", name, version, desc);
6959 + else
6960 + printf("%s - %s\n", name, version);
6961 + return 0;
6962 +}
6963 +
6964 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6965 + pkg_state_status_t status, void *userdata)
6966 +{
6967 + if (desc)
6968 + printf("%s\n", desc);
6969 + return 0;
6970 +}
6971 +
6972 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6973 + void *userdata)
6974 +{
6975 + printf("%s\n", desc);
6976 + return 0;
6977 +}
6978 +
6979 +char* default_ipkg_response_callback(char *question)
6980 +{
6981 + char *response = NULL;
6982 + printf(question);
6983 + fflush(stdout);
6984 + do {
6985 + response = (char *)file_read_line_alloc(stdin);
6986 + } while (response == NULL);
6987 + return response;
6988 +}
6989 +
6990 +/* This is used for backward compatibility */
6991 +int
6992 +ipkg_op (int argc, char *argv[])
6993 +{
6994 + int err, optind;
6995 + args_t args;
6996 + char *cmd_name;
6997 + ipkg_cmd_t *cmd;
6998 + ipkg_conf_t ipkg_conf;
6999 +
7000 + args_init (&args);
7001 +
7002 + optind = args_parse (&args, argc, argv);
7003 + if (optind == argc || optind < 0)
7004 + {
7005 + args_usage ("ipkg must have one sub-command argument");
7006 + }
7007 +
7008 + cmd_name = argv[optind++];
7009 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7010 + read anything from there.
7011 +*/
7012 + if ( !strcmp(cmd_name,"print-architecture") ||
7013 + !strcmp(cmd_name,"print_architecture") ||
7014 + !strcmp(cmd_name,"print-installation-architecture") ||
7015 + !strcmp(cmd_name,"print_installation_architecture") )
7016 + args.nocheckfordirorfile = 1;
7017 +
7018 +
7019 + err = ipkg_conf_init (&ipkg_conf, &args);
7020 + if (err)
7021 + {
7022 + return err;
7023 + }
7024 +
7025 + args_deinit (&args);
7026 +
7027 + ipkg_cb_message = default_ipkg_message_callback;
7028 + ipkg_cb_response = default_ipkg_response_callback;
7029 + ipkg_cb_status = default_ipkg_status_callback;
7030 + if ( strcmp(cmd_name, "files")==0)
7031 + ipkg_cb_list = default_ipkg_files_callback;
7032 + else
7033 + ipkg_cb_list = default_ipkg_list_callback;
7034 +
7035 + cmd = ipkg_cmd_find (cmd_name);
7036 + if (cmd == NULL)
7037 + {
7038 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7039 + cmd_name);
7040 + args_usage (NULL);
7041 + }
7042 +
7043 + if (cmd->requires_args && optind == argc)
7044 + {
7045 + fprintf (stderr,
7046 + "%s: the ``%s'' command requires at least one argument\n",
7047 + __FUNCTION__, cmd_name);
7048 + args_usage (NULL);
7049 + }
7050 +
7051 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7052 +
7053 + ipkg_conf_deinit (&ipkg_conf);
7054 +
7055 + return err;
7056 +}
7057 +
7058 +#endif /* IPKG_LIB */
7059 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/libipkg.h busybox-1.1.0-pre1-new/archival/libipkg/libipkg.h
7060 --- busybox-1.1.0-pre1-old/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7061 +++ busybox-1.1.0-pre1-new/archival/libipkg/libipkg.h 2005-12-07 21:25:30.000000000 +0100
7062 @@ -0,0 +1,87 @@
7063 +/* ipkglib.h - the itsy package management system
7064 +
7065 + Florian Boor <florian.boor@kernelconcepts.de>
7066 +
7067 + This program is free software; you can redistribute it and/or
7068 + modify it under the terms of the GNU General Public License as
7069 + published by the Free Software Foundation; either version 2, or (at
7070 + your option) any later version.
7071 +
7072 + This program is distributed in the hope that it will be useful, but
7073 + WITHOUT ANY WARRANTY; without even the implied warranty of
7074 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7075 + General Public License for more details.
7076 +*/
7077 +
7078 +#ifndef IPKGLIB_H
7079 +#define IPKGLIB_H
7080 +
7081 +#ifdef IPKG_LIB
7082 +
7083 +#include "ipkg_conf.h"
7084 +#include "ipkg_message.h"
7085 +
7086 +#include "args.h"
7087 +#include "pkg.h"
7088 +
7089 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7090 + char *msg);
7091 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7092 + pkg_state_status_t status, void *userdata);
7093 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7094 + void *userdata);
7095 +typedef char* (*ipkg_response_callback)(char *question);
7096 +
7097 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7098 +extern int ipkg_init (ipkg_message_callback mcall,
7099 + ipkg_response_callback rcall,
7100 + args_t * args);
7101 +
7102 +extern int ipkg_deinit (args_t *args);
7103 +extern int ipkg_packages_list(args_t *args,
7104 + const char *packages,
7105 + ipkg_list_callback cblist,
7106 + void *userdata);
7107 +extern int ipkg_packages_status(args_t *args,
7108 + const char *packages,
7109 + ipkg_status_callback cbstatus,
7110 + void *userdata);
7111 +extern int ipkg_packages_info(args_t *args,
7112 + const char *packages,
7113 + ipkg_status_callback cbstatus,
7114 + void *userdata);
7115 +extern int ipkg_packages_install(args_t *args, const char *name);
7116 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7117 +extern int ipkg_lists_update(args_t *args);
7118 +extern int ipkg_packages_upgrade(args_t *args);
7119 +extern int ipkg_packages_download(args_t *args, const char *name);
7120 +extern int ipkg_package_files(args_t *args,
7121 + const char *name,
7122 + ipkg_list_callback cblist,
7123 + void *userdata);
7124 +extern int ipkg_file_search(args_t *args,
7125 + const char *file,
7126 + ipkg_list_callback cblist,
7127 + void *userdata);
7128 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7129 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7130 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7131 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7132 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7133 +
7134 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7135 +extern ipkg_response_callback ipkg_cb_response;
7136 +extern ipkg_status_callback ipkg_cb_status;
7137 +extern ipkg_list_callback ipkg_cb_list;
7138 +extern void push_error_list(struct errlist **errors,char * msg);
7139 +extern void reverse_error_list(struct errlist **errors);
7140 +extern void free_error_list(struct errlist **errors);
7141 +
7142 +#else
7143 +
7144 +extern int ipkg_op(int argc, char *argv[]);
7145 +
7146 +#endif
7147 +
7148 +
7149 +#endif
7150 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/md5.c busybox-1.1.0-pre1-new/archival/libipkg/md5.c
7151 --- busybox-1.1.0-pre1-old/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7152 +++ busybox-1.1.0-pre1-new/archival/libipkg/md5.c 2005-12-07 21:25:30.000000000 +0100
7153 @@ -0,0 +1,48 @@
7154 +/* md5.c - wrappers to busybox md5 functions
7155 + *
7156 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7157 + *
7158 + * This program is free software; you can redistribute it and/or modify
7159 + * it under the terms of the GNU General Public License as published by
7160 + * the Free Software Foundation; either version 2, or (at your option)
7161 + * any later version.
7162 + *
7163 + * This program is distributed in the hope that it will be useful,
7164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7166 + * GNU General Public License for more details.
7167 + *
7168 + * You should have received a copy of the GNU General Public License
7169 + * along with this program; if not, write to the Free Software Foundation,
7170 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7171 + */
7172 +
7173 +#include <stdio.h>
7174 +#include "libbb.h"
7175 +
7176 +#include "md5.h"
7177 +
7178 +int md5_stream(FILE *stream, void *resblock)
7179 +{
7180 + int fd;
7181 + int sum;
7182 +
7183 + if( (fd = fileno(stream)) == -1 ) {
7184 + bb_error_msg("bad file descriptor");
7185 + return 1;
7186 + }
7187 +
7188 + hash_fd(fd, -1, HASH_MD5, (uint8_t *)resblock);
7189 +
7190 + return 0;
7191 +}
7192 +
7193 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7194 +{
7195 + struct md5_ctx_t md5_cx;
7196 +
7197 + md5_begin(&md5_cx);
7198 + md5_hash(buffer, len, &md5_cx);
7199 + return md5_end(resblock, &md5_cx);
7200 +}
7201 +
7202 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/md5.h busybox-1.1.0-pre1-new/archival/libipkg/md5.h
7203 --- busybox-1.1.0-pre1-old/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7204 +++ busybox-1.1.0-pre1-new/archival/libipkg/md5.h 2005-12-07 21:25:30.000000000 +0100
7205 @@ -0,0 +1,35 @@
7206 +/* md5.h - Compute MD5 checksum of files or strings according to the
7207 + * definition of MD5 in RFC 1321 from April 1992.
7208 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7209 + *
7210 + * This program is free software; you can redistribute it and/or modify
7211 + * it under the terms of the GNU General Public License as published by
7212 + * the Free Software Foundation; either version 2, or (at your option)
7213 + * any later version.
7214 + *
7215 + * This program is distributed in the hope that it will be useful,
7216 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7217 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7218 + * GNU General Public License for more details.
7219 + *
7220 + * You should have received a copy of the GNU General Public License
7221 + * along with this program; if not, write to the Free Software Foundation,
7222 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7223 + */
7224 +
7225 +#ifndef MD5_H
7226 +#define MD5_H
7227 +
7228 +/* Compute MD5 message digest for bytes read from STREAM. The
7229 + resulting message digest number will be written into the 16 bytes
7230 + beginning at RESBLOCK. */
7231 +int md5_stream(FILE *stream, void *resblock);
7232 +
7233 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7234 + result is always in little endian byte order, so that a byte-wise
7235 + output yields to the wanted ASCII representation of the message
7236 + digest. */
7237 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7238 +
7239 +#endif
7240 +
7241 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/nv_pair.c busybox-1.1.0-pre1-new/archival/libipkg/nv_pair.c
7242 --- busybox-1.1.0-pre1-old/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7243 +++ busybox-1.1.0-pre1-new/archival/libipkg/nv_pair.c 2005-12-07 21:25:30.000000000 +0100
7244 @@ -0,0 +1,40 @@
7245 +/* nv_pair.c - the itsy package management system
7246 +
7247 + Carl D. Worth
7248 +
7249 + Copyright (C) 2001 University of Southern California
7250 +
7251 + This program is free software; you can redistribute it and/or
7252 + modify it under the terms of the GNU General Public License as
7253 + published by the Free Software Foundation; either version 2, or (at
7254 + your option) any later version.
7255 +
7256 + This program is distributed in the hope that it will be useful, but
7257 + WITHOUT ANY WARRANTY; without even the implied warranty of
7258 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7259 + General Public License for more details.
7260 +*/
7261 +
7262 +#include "ipkg.h"
7263 +
7264 +#include "nv_pair.h"
7265 +#include "str_util.h"
7266 +
7267 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7268 +{
7269 + nv_pair->name = str_dup_safe(name);
7270 + nv_pair->value = str_dup_safe(value);
7271 +
7272 + return 0;
7273 +}
7274 +
7275 +void nv_pair_deinit(nv_pair_t *nv_pair)
7276 +{
7277 + free(nv_pair->name);
7278 + nv_pair->name = NULL;
7279 +
7280 + free(nv_pair->value);
7281 + nv_pair->value = NULL;
7282 +}
7283 +
7284 +
7285 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/nv_pair.h busybox-1.1.0-pre1-new/archival/libipkg/nv_pair.h
7286 --- busybox-1.1.0-pre1-old/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7287 +++ busybox-1.1.0-pre1-new/archival/libipkg/nv_pair.h 2005-12-07 21:25:30.000000000 +0100
7288 @@ -0,0 +1,32 @@
7289 +/* nv_pair.h - the itsy package management system
7290 +
7291 + Carl D. Worth
7292 +
7293 + Copyright (C) 2001 University of Southern California
7294 +
7295 + This program is free software; you can redistribute it and/or
7296 + modify it under the terms of the GNU General Public License as
7297 + published by the Free Software Foundation; either version 2, or (at
7298 + your option) any later version.
7299 +
7300 + This program is distributed in the hope that it will be useful, but
7301 + WITHOUT ANY WARRANTY; without even the implied warranty of
7302 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7303 + General Public License for more details.
7304 +*/
7305 +
7306 +#ifndef NV_PAIR_H
7307 +#define NV_PAIR_H
7308 +
7309 +typedef struct nv_pair nv_pair_t;
7310 +struct nv_pair
7311 +{
7312 + char *name;
7313 + char *value;
7314 +};
7315 +
7316 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7317 +void nv_pair_deinit(nv_pair_t *nv_pair);
7318 +
7319 +#endif
7320 +
7321 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/nv_pair_list.c busybox-1.1.0-pre1-new/archival/libipkg/nv_pair_list.c
7322 --- busybox-1.1.0-pre1-old/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7323 +++ busybox-1.1.0-pre1-new/archival/libipkg/nv_pair_list.c 2005-12-07 21:25:30.000000000 +0100
7324 @@ -0,0 +1,98 @@
7325 +/* nv_pair_list.c - the itsy package management system
7326 +
7327 + Carl D. Worth
7328 +
7329 + Copyright (C) 2001 University of Southern California
7330 +
7331 + This program is free software; you can redistribute it and/or
7332 + modify it under the terms of the GNU General Public License as
7333 + published by the Free Software Foundation; either version 2, or (at
7334 + your option) any later version.
7335 +
7336 + This program is distributed in the hope that it will be useful, but
7337 + WITHOUT ANY WARRANTY; without even the implied warranty of
7338 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7339 + General Public License for more details.
7340 +*/
7341 +
7342 +#include "ipkg.h"
7343 +
7344 +#include "nv_pair.h"
7345 +#include "void_list.h"
7346 +#include "nv_pair_list.h"
7347 +
7348 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7349 +{
7350 + return void_list_elt_init((void_list_elt_t *) elt, data);
7351 +}
7352 +
7353 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7354 +{
7355 + void_list_elt_deinit((void_list_elt_t *) elt);
7356 +}
7357 +
7358 +int nv_pair_list_init(nv_pair_list_t *list)
7359 +{
7360 + return void_list_init((void_list_t *) list);
7361 +}
7362 +
7363 +void nv_pair_list_deinit(nv_pair_list_t *list)
7364 +{
7365 + nv_pair_list_elt_t *iter;
7366 + nv_pair_t *nv_pair;
7367 +
7368 + for (iter = list->head; iter; iter = iter->next) {
7369 + nv_pair = iter->data;
7370 + nv_pair_deinit(nv_pair);
7371 +
7372 + /* malloced in nv_pair_list_append */
7373 + free(nv_pair);
7374 + iter->data = NULL;
7375 + }
7376 + void_list_deinit((void_list_t *) list);
7377 +}
7378 +
7379 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7380 +{
7381 + int err;
7382 +
7383 + /* freed in nv_pair_list_deinit */
7384 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7385 +
7386 + if (nv_pair == NULL) {
7387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7388 + return NULL;
7389 + }
7390 + nv_pair_init(nv_pair, name, value);
7391 +
7392 + err = void_list_append((void_list_t *) list, nv_pair);
7393 + if (err) {
7394 + return NULL;
7395 + }
7396 +
7397 + return nv_pair;
7398 +}
7399 +
7400 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7401 +{
7402 + return void_list_push((void_list_t *) list, data);
7403 +}
7404 +
7405 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7406 +{
7407 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7408 +}
7409 +
7410 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7411 +{
7412 + nv_pair_list_elt_t *iter;
7413 + nv_pair_t *nv_pair;
7414 +
7415 + for (iter = list->head; iter; iter = iter->next) {
7416 + nv_pair = iter->data;
7417 + if (strcmp(nv_pair->name, name) == 0) {
7418 + return nv_pair->value;
7419 + }
7420 + }
7421 + return NULL;
7422 +}
7423 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/nv_pair_list.h busybox-1.1.0-pre1-new/archival/libipkg/nv_pair_list.h
7424 --- busybox-1.1.0-pre1-old/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7425 +++ busybox-1.1.0-pre1-new/archival/libipkg/nv_pair_list.h 2005-12-07 21:25:30.000000000 +0100
7426 @@ -0,0 +1,60 @@
7427 +/* nv_pair_list.h - the itsy package management system
7428 +
7429 + Carl D. Worth
7430 +
7431 + Copyright (C) 2001 University of Southern California
7432 +
7433 + This program is free software; you can redistribute it and/or
7434 + modify it under the terms of the GNU General Public License as
7435 + published by the Free Software Foundation; either version 2, or (at
7436 + your option) any later version.
7437 +
7438 + This program is distributed in the hope that it will be useful, but
7439 + WITHOUT ANY WARRANTY; without even the implied warranty of
7440 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7441 + General Public License for more details.
7442 +*/
7443 +
7444 +#ifndef NV_PAIR_LIST_H
7445 +#define NV_PAIR_LIST_H
7446 +
7447 +#include "nv_pair.h"
7448 +#include "void_list.h"
7449 +
7450 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7451 +struct nv_pair_list_elt
7452 +{
7453 + nv_pair_list_elt_t *next;
7454 + nv_pair_t *data;
7455 +};
7456 +
7457 +typedef struct nv_pair_list nv_pair_list_t;
7458 +struct nv_pair_list
7459 +{
7460 + nv_pair_list_elt_t pre_head;
7461 + nv_pair_list_elt_t *head;
7462 + nv_pair_list_elt_t *tail;
7463 +};
7464 +
7465 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7466 +{
7467 + if (list->head == NULL)
7468 + return 1;
7469 + else
7470 + return 0;
7471 +}
7472 +
7473 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7474 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7475 +
7476 +int nv_pair_list_init(nv_pair_list_t *list);
7477 +void nv_pair_list_deinit(nv_pair_list_t *list);
7478 +
7479 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7480 + const char *name, const char *value);
7481 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7482 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7483 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7484 +
7485 +#endif
7486 +
7487 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg.c busybox-1.1.0-pre1-new/archival/libipkg/pkg.c
7488 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7489 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg.c 2005-12-07 21:25:30.000000000 +0100
7490 @@ -0,0 +1,1753 @@
7491 +/* pkg.c - the itsy package management system
7492 +
7493 + Carl D. Worth
7494 +
7495 + Copyright (C) 2001 University of Southern California
7496 +
7497 + This program is free software; you can redistribute it and/or
7498 + modify it under the terms of the GNU General Public License as
7499 + published by the Free Software Foundation; either version 2, or (at
7500 + your option) any later version.
7501 +
7502 + This program is distributed in the hope that it will be useful, but
7503 + WITHOUT ANY WARRANTY; without even the implied warranty of
7504 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7505 + General Public License for more details.
7506 +*/
7507 +
7508 +#include "ipkg.h"
7509 +#include <ctype.h>
7510 +#include <string.h>
7511 +#include <errno.h>
7512 +
7513 +#include "pkg.h"
7514 +
7515 +#include "pkg_parse.h"
7516 +#include "pkg_extract.h"
7517 +#include "ipkg_message.h"
7518 +#include "ipkg_utils.h"
7519 +
7520 +#include "sprintf_alloc.h"
7521 +#include "file_util.h"
7522 +#include "str_util.h"
7523 +#include "xsystem.h"
7524 +#include "ipkg_conf.h"
7525 +
7526 +typedef struct enum_map enum_map_t;
7527 +struct enum_map
7528 +{
7529 + int value;
7530 + char *str;
7531 +};
7532 +
7533 +static const enum_map_t pkg_state_want_map[] = {
7534 + { SW_UNKNOWN, "unknown"},
7535 + { SW_INSTALL, "install"},
7536 + { SW_DEINSTALL, "deinstall"},
7537 + { SW_PURGE, "purge"}
7538 +};
7539 +
7540 +static const enum_map_t pkg_state_flag_map[] = {
7541 + { SF_OK, "ok"},
7542 + { SF_REINSTREQ, "reinstreq"},
7543 + { SF_HOLD, "hold"},
7544 + { SF_REPLACE, "replace"},
7545 + { SF_NOPRUNE, "noprune"},
7546 + { SF_PREFER, "prefer"},
7547 + { SF_OBSOLETE, "obsolete"},
7548 + { SF_USER, "user"},
7549 +};
7550 +
7551 +static const enum_map_t pkg_state_status_map[] = {
7552 + { SS_NOT_INSTALLED, "not-installed" },
7553 + { SS_UNPACKED, "unpacked" },
7554 + { SS_HALF_CONFIGURED, "half-configured" },
7555 + { SS_INSTALLED, "installed" },
7556 + { SS_HALF_INSTALLED, "half-installed" },
7557 + { SS_CONFIG_FILES, "config-files" },
7558 + { SS_POST_INST_FAILED, "post-inst-failed" },
7559 + { SS_REMOVAL_FAILED, "removal-failed" }
7560 +};
7561 +
7562 +static int verrevcmp(const char *val, const char *ref);
7563 +
7564 +
7565 +pkg_t *pkg_new(void)
7566 +{
7567 + pkg_t *pkg;
7568 +
7569 + pkg = malloc(sizeof(pkg_t));
7570 + if (pkg == NULL) {
7571 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7572 + return NULL;
7573 + }
7574 +
7575 + pkg_init(pkg);
7576 +
7577 + return pkg;
7578 +}
7579 +
7580 +int pkg_init(pkg_t *pkg)
7581 +{
7582 + memset(pkg, 0, sizeof(pkg_t));
7583 + pkg->name = NULL;
7584 + pkg->epoch = 0;
7585 + pkg->version = NULL;
7586 + pkg->revision = NULL;
7587 + pkg->familiar_revision = NULL;
7588 + pkg->dest = NULL;
7589 + pkg->src = NULL;
7590 + pkg->architecture = NULL;
7591 + pkg->maintainer = NULL;
7592 + pkg->section = NULL;
7593 + pkg->description = NULL;
7594 + pkg->state_want = SW_UNKNOWN;
7595 + pkg->state_flag = SF_OK;
7596 + pkg->state_status = SS_NOT_INSTALLED;
7597 + pkg->depends_str = NULL;
7598 + pkg->provides_str = NULL;
7599 + pkg->depends_count = 0;
7600 + pkg->depends = NULL;
7601 + pkg->suggests_str = NULL;
7602 + pkg->recommends_str = NULL;
7603 + pkg->suggests_count = 0;
7604 + pkg->recommends_count = 0;
7605 +
7606 + /* Abhaya: added init for conflicts fields */
7607 + pkg->conflicts = NULL;
7608 + pkg->conflicts_count = 0;
7609 +
7610 + /* added for replaces. Jamey 7/23/2002 */
7611 + pkg->replaces = NULL;
7612 + pkg->replaces_count = 0;
7613 +
7614 + pkg->pre_depends_count = 0;
7615 + pkg->pre_depends_str = NULL;
7616 + pkg->provides_count = 0;
7617 + pkg->provides = NULL;
7618 + pkg->filename = NULL;
7619 + pkg->local_filename = NULL;
7620 + pkg->tmp_unpack_dir = NULL;
7621 + pkg->md5sum = NULL;
7622 + pkg->size = NULL;
7623 + pkg->installed_size = NULL;
7624 + pkg->priority = NULL;
7625 + pkg->source = NULL;
7626 + conffile_list_init(&pkg->conffiles);
7627 + pkg->installed_files = NULL;
7628 + pkg->installed_files_ref_cnt = 0;
7629 + pkg->essential = 0;
7630 +
7631 + return 0;
7632 +}
7633 +
7634 +void pkg_deinit(pkg_t *pkg)
7635 +{
7636 + free(pkg->name);
7637 + pkg->name = NULL;
7638 + pkg->epoch = 0;
7639 + free(pkg->version);
7640 + pkg->version = NULL;
7641 + /* revision and familiar_revision share storage with version, so
7642 + don't free */
7643 + pkg->revision = NULL;
7644 + pkg->familiar_revision = NULL;
7645 + /* owned by ipkg_conf_t */
7646 + pkg->dest = NULL;
7647 + /* owned by ipkg_conf_t */
7648 + pkg->src = NULL;
7649 + free(pkg->architecture);
7650 + pkg->architecture = NULL;
7651 + free(pkg->maintainer);
7652 + pkg->maintainer = NULL;
7653 + free(pkg->section);
7654 + pkg->section = NULL;
7655 + free(pkg->description);
7656 + pkg->description = NULL;
7657 + pkg->state_want = SW_UNKNOWN;
7658 + pkg->state_flag = SF_OK;
7659 + pkg->state_status = SS_NOT_INSTALLED;
7660 + free(pkg->depends_str);
7661 + pkg->depends_str = NULL;
7662 + free(pkg->provides_str);
7663 + pkg->provides_str = NULL;
7664 + pkg->depends_count = 0;
7665 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7666 + pkg->pre_depends_count = 0;
7667 + free(pkg->pre_depends_str);
7668 + pkg->pre_depends_str = NULL;
7669 + pkg->provides_count = 0;
7670 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7671 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7672 + free(pkg->filename);
7673 + pkg->filename = NULL;
7674 + free(pkg->local_filename);
7675 + pkg->local_filename = NULL;
7676 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7677 + ipkg_install.c here. See comment in
7678 + ipkg_install.c:cleanup_temporary_files */
7679 + free(pkg->tmp_unpack_dir);
7680 + pkg->tmp_unpack_dir = NULL;
7681 + free(pkg->md5sum);
7682 + pkg->md5sum = NULL;
7683 + free(pkg->size);
7684 + pkg->size = NULL;
7685 + free(pkg->installed_size);
7686 + pkg->installed_size = NULL;
7687 + free(pkg->priority);
7688 + pkg->priority = NULL;
7689 + free(pkg->source);
7690 + pkg->source = NULL;
7691 + conffile_list_deinit(&pkg->conffiles);
7692 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7693 + since if they are calling deinit, they should know. Maybe do an
7694 + assertion here instead? */
7695 + pkg->installed_files_ref_cnt = 1;
7696 + pkg_free_installed_files(pkg);
7697 + pkg->essential = 0;
7698 +}
7699 +
7700 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7701 +{
7702 + int err;
7703 + char **raw;
7704 + FILE *control_file;
7705 +
7706 + err = pkg_init(pkg);
7707 + if (err) { return err; }
7708 +
7709 + pkg->local_filename = strdup(filename);
7710 +
7711 + control_file = tmpfile();
7712 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7713 + if (err) { return err; }
7714 +
7715 + rewind(control_file);
7716 + raw = read_raw_pkgs_from_stream(control_file);
7717 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7718 +
7719 + fclose(control_file);
7720 +
7721 + return 0;
7722 +}
7723 +
7724 +/* Merge any new information in newpkg into oldpkg */
7725 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7726 + newpkg, but should leave it usable. This rework is so that
7727 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7728 +/*
7729 + * uh, i thought that i had originally written this so that it took
7730 + * two pkgs and returned a new one? we can do that again... -sma
7731 + */
7732 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7733 +{
7734 + if (oldpkg == newpkg) {
7735 + return 0;
7736 + }
7737 +
7738 + if (!oldpkg->src)
7739 + oldpkg->src = newpkg->src;
7740 + if (!oldpkg->dest)
7741 + oldpkg->dest = newpkg->dest;
7742 + if (!oldpkg->architecture)
7743 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7744 + if (!oldpkg->arch_priority)
7745 + oldpkg->arch_priority = newpkg->arch_priority;
7746 + if (!oldpkg->section)
7747 + oldpkg->section = str_dup_safe(newpkg->section);
7748 + if(!oldpkg->maintainer)
7749 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7750 + if(!oldpkg->description)
7751 + oldpkg->description = str_dup_safe(newpkg->description);
7752 + if (set_status) {
7753 + /* merge the state_flags from the new package */
7754 + oldpkg->state_want = newpkg->state_want;
7755 + oldpkg->state_status = newpkg->state_status;
7756 + oldpkg->state_flag = newpkg->state_flag;
7757 + } else {
7758 + if (oldpkg->state_want == SW_UNKNOWN)
7759 + oldpkg->state_want = newpkg->state_want;
7760 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7761 + oldpkg->state_status = newpkg->state_status;
7762 + oldpkg->state_flag |= newpkg->state_flag;
7763 + }
7764 +
7765 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7766 + oldpkg->depends_str = newpkg->depends_str;
7767 + newpkg->depends_str = NULL;
7768 + oldpkg->depends_count = newpkg->depends_count;
7769 + newpkg->depends_count = 0;
7770 +
7771 + oldpkg->depends = newpkg->depends;
7772 + newpkg->depends = NULL;
7773 +
7774 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7775 + newpkg->pre_depends_str = NULL;
7776 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7777 + newpkg->pre_depends_count = 0;
7778 +
7779 + oldpkg->recommends_str = newpkg->recommends_str;
7780 + newpkg->recommends_str = NULL;
7781 + oldpkg->recommends_count = newpkg->recommends_count;
7782 + newpkg->recommends_count = 0;
7783 +
7784 + oldpkg->suggests_str = newpkg->suggests_str;
7785 + newpkg->suggests_str = NULL;
7786 + oldpkg->suggests_count = newpkg->suggests_count;
7787 + newpkg->suggests_count = 0;
7788 + }
7789 +
7790 + if (!oldpkg->provides_str) {
7791 + oldpkg->provides_str = newpkg->provides_str;
7792 + newpkg->provides_str = NULL;
7793 + oldpkg->provides_count = newpkg->provides_count;
7794 + newpkg->provides_count = 0;
7795 +
7796 + oldpkg->provides = newpkg->provides;
7797 + newpkg->provides = NULL;
7798 + }
7799 +
7800 + if (!oldpkg->conflicts_str) {
7801 + oldpkg->conflicts_str = newpkg->conflicts_str;
7802 + newpkg->conflicts_str = NULL;
7803 + oldpkg->conflicts_count = newpkg->conflicts_count;
7804 + newpkg->conflicts_count = 0;
7805 +
7806 + oldpkg->conflicts = newpkg->conflicts;
7807 + newpkg->conflicts = NULL;
7808 + }
7809 +
7810 + if (!oldpkg->replaces_str) {
7811 + oldpkg->replaces_str = newpkg->replaces_str;
7812 + newpkg->replaces_str = NULL;
7813 + oldpkg->replaces_count = newpkg->replaces_count;
7814 + newpkg->replaces_count = 0;
7815 +
7816 + oldpkg->replaces = newpkg->replaces;
7817 + newpkg->replaces = NULL;
7818 + }
7819 +
7820 + if (!oldpkg->filename)
7821 + oldpkg->filename = str_dup_safe(newpkg->filename);
7822 + if (0)
7823 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7824 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7825 + if (!oldpkg->local_filename)
7826 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7827 + if (!oldpkg->tmp_unpack_dir)
7828 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7829 + if (!oldpkg->md5sum)
7830 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7831 + if (!oldpkg->size)
7832 + oldpkg->size = str_dup_safe(newpkg->size);
7833 + if (!oldpkg->installed_size)
7834 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7835 + if (!oldpkg->priority)
7836 + oldpkg->priority = str_dup_safe(newpkg->priority);
7837 + if (!oldpkg->source)
7838 + oldpkg->source = str_dup_safe(newpkg->source);
7839 + if (oldpkg->conffiles.head == NULL){
7840 + oldpkg->conffiles = newpkg->conffiles;
7841 + conffile_list_init(&newpkg->conffiles);
7842 + }
7843 + if (!oldpkg->installed_files){
7844 + oldpkg->installed_files = newpkg->installed_files;
7845 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7846 + newpkg->installed_files = NULL;
7847 + }
7848 + if (!oldpkg->essential)
7849 + oldpkg->essential = newpkg->essential;
7850 +
7851 + return 0;
7852 +}
7853 +
7854 +abstract_pkg_t *abstract_pkg_new(void)
7855 +{
7856 + abstract_pkg_t * ab_pkg;
7857 +
7858 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7859 +
7860 + if (ab_pkg == NULL) {
7861 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7862 + return NULL;
7863 + }
7864 +
7865 + if ( abstract_pkg_init(ab_pkg) < 0 )
7866 + return NULL;
7867 +
7868 + return ab_pkg;
7869 +}
7870 +
7871 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7872 +{
7873 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7874 +
7875 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7876 + if (ab_pkg->provided_by==NULL){
7877 + return -1;
7878 + }
7879 + ab_pkg->dependencies_checked = 0;
7880 + ab_pkg->state_status = SS_NOT_INSTALLED;
7881 +
7882 + return 0;
7883 +}
7884 +
7885 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7886 + char * temp_str;
7887 + char **raw =NULL;
7888 + char **raw_start=NULL;
7889 +
7890 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7891 + if (temp_str == NULL ){
7892 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7893 + return;
7894 + }
7895 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7896 +
7897 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7898 + if (raw == NULL ){
7899 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7900 + return;
7901 + }
7902 +
7903 + while(*raw){
7904 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7905 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7906 + }
7907 + }
7908 + raw = raw_start;
7909 + while (*raw) {
7910 + if (raw!=NULL)
7911 + free(*raw++);
7912 + }
7913 +
7914 + free(raw_start);
7915 + free(temp_str);
7916 +
7917 + return ;
7918 +
7919 +}
7920 +
7921 +char * pkg_formatted_info(pkg_t *pkg )
7922 +{
7923 + char *line;
7924 + char * buff;
7925 +
7926 + buff = malloc(8192);
7927 + if (buff == NULL) {
7928 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7929 + return NULL;
7930 + }
7931 +
7932 + buff[0] = '\0';
7933 +
7934 + line = pkg_formatted_field(pkg, "Package");
7935 + strncat(buff ,line, strlen(line));
7936 + free(line);
7937 +
7938 + line = pkg_formatted_field(pkg, "Version");
7939 + strncat(buff ,line, strlen(line));
7940 + free(line);
7941 +
7942 + line = pkg_formatted_field(pkg, "Depends");
7943 + strncat(buff ,line, strlen(line));
7944 + free(line);
7945 +
7946 + line = pkg_formatted_field(pkg, "Recommends");
7947 + strncat(buff ,line, strlen(line));
7948 + free(line);
7949 +
7950 + line = pkg_formatted_field(pkg, "Suggests");
7951 + strncat(buff ,line, strlen(line));
7952 + free(line);
7953 +
7954 + line = pkg_formatted_field(pkg, "Provides");
7955 + strncat(buff ,line, strlen(line));
7956 + free(line);
7957 +
7958 + line = pkg_formatted_field(pkg, "Replaces");
7959 + strncat(buff ,line, strlen(line));
7960 + free(line);
7961 +
7962 + line = pkg_formatted_field(pkg, "Conflicts");
7963 + strncat(buff ,line, strlen(line));
7964 + free(line);
7965 +
7966 + line = pkg_formatted_field(pkg, "Status");
7967 + strncat(buff ,line, strlen(line));
7968 + free(line);
7969 +
7970 + line = pkg_formatted_field(pkg, "Section");
7971 + strncat(buff ,line, strlen(line));
7972 + free(line);
7973 +
7974 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7975 + strncat(buff ,line, strlen(line));
7976 + free(line);
7977 +
7978 + line = pkg_formatted_field(pkg, "Architecture");
7979 + strncat(buff ,line, strlen(line));
7980 + free(line);
7981 +
7982 + line = pkg_formatted_field(pkg, "Maintainer");
7983 + strncat(buff ,line, strlen(line));
7984 + free(line);
7985 +
7986 + line = pkg_formatted_field(pkg, "MD5sum");
7987 + strncat(buff ,line, strlen(line));
7988 + free(line);
7989 +
7990 + line = pkg_formatted_field(pkg, "Size");
7991 + strncat(buff ,line, strlen(line));
7992 + free(line);
7993 +
7994 + line = pkg_formatted_field(pkg, "Filename");
7995 + strncat(buff ,line, strlen(line));
7996 + free(line);
7997 +
7998 + line = pkg_formatted_field(pkg, "Conffiles");
7999 + strncat(buff ,line, strlen(line));
8000 + free(line);
8001 +
8002 + line = pkg_formatted_field(pkg, "Source");
8003 + strncat(buff ,line, strlen(line));
8004 + free(line);
8005 +
8006 + line = pkg_formatted_field(pkg, "Description");
8007 + strncat(buff ,line, strlen(line));
8008 + free(line);
8009 +
8010 + line = pkg_formatted_field(pkg, "Installed-Time");
8011 + strncat(buff ,line, strlen(line));
8012 + free(line);
8013 +
8014 + return buff;
8015 +}
8016 +
8017 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8018 +{
8019 + static size_t LINE_LEN = 128;
8020 + char * temp = (char *)malloc(1);
8021 + int len = 0;
8022 + int flag_provide_false = 0;
8023 +
8024 +/*
8025 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8026 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8027 +*/
8028 +
8029 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8030 + goto UNKNOWN_FMT_FIELD;
8031 + }
8032 +
8033 + temp[0]='\0';
8034 +
8035 + switch (field[0])
8036 + {
8037 + case 'a':
8038 + case 'A':
8039 + if (strcasecmp(field, "Architecture") == 0) {
8040 + /* Architecture */
8041 + if (pkg->architecture) {
8042 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8043 + if ( temp == NULL ){
8044 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8045 + return NULL;
8046 + }
8047 + temp[0]='\0';
8048 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8049 + }
8050 + } else {
8051 + goto UNKNOWN_FMT_FIELD;
8052 + }
8053 + break;
8054 + case 'c':
8055 + case 'C':
8056 + if (strcasecmp(field, "Conffiles") == 0) {
8057 + /* Conffiles */
8058 + conffile_list_elt_t *iter;
8059 + char confstr[LINE_LEN];
8060 +
8061 + if (pkg->conffiles.head == NULL) {
8062 + return temp;
8063 + }
8064 +
8065 + len = 14 ;
8066 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8067 + if (iter->data->name && iter->data->value) {
8068 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8069 + }
8070 + }
8071 + temp = (char *)realloc(temp,len);
8072 + if ( temp == NULL ){
8073 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8074 + return NULL;
8075 + }
8076 + temp[0]='\0';
8077 + strncpy(temp, "Conffiles:\n", 12);
8078 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8079 + if (iter->data->name && iter->data->value) {
8080 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8081 + strncat(temp, confstr, strlen(confstr));
8082 + }
8083 + }
8084 + } else if (strcasecmp(field, "Conflicts") == 0) {
8085 + int i;
8086 +
8087 + if (pkg->conflicts_count) {
8088 + char conflictstr[LINE_LEN];
8089 + len = 14 ;
8090 + for(i = 0; i < pkg->conflicts_count; i++) {
8091 + len = len + (strlen(pkg->conflicts_str[i])+5);
8092 + }
8093 + temp = (char *)realloc(temp,len);
8094 + if ( temp == NULL ){
8095 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8096 + return NULL;
8097 + }
8098 + temp[0]='\0';
8099 + strncpy(temp, "Conflicts:", 11);
8100 + for(i = 0; i < pkg->conflicts_count; i++) {
8101 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8102 + strncat(temp, conflictstr, strlen(conflictstr));
8103 + }
8104 + strncat(temp, "\n", strlen("\n"));
8105 + }
8106 + } else {
8107 + goto UNKNOWN_FMT_FIELD;
8108 + }
8109 + break;
8110 + case 'd':
8111 + case 'D':
8112 + if (strcasecmp(field, "Depends") == 0) {
8113 + /* Depends */
8114 + int i;
8115 +
8116 + if (pkg->depends_count) {
8117 + char depstr[LINE_LEN];
8118 + len = 14 ;
8119 + for(i = 0; i < pkg->depends_count; i++) {
8120 + len = len + (strlen(pkg->depends_str[i])+4);
8121 + }
8122 + temp = (char *)realloc(temp,len);
8123 + if ( temp == NULL ){
8124 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8125 + return NULL;
8126 + }
8127 + temp[0]='\0';
8128 + strncpy(temp, "Depends:", 10);
8129 + for(i = 0; i < pkg->depends_count; i++) {
8130 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8131 + strncat(temp, depstr, strlen(depstr));
8132 + }
8133 + strncat(temp, "\n", strlen("\n"));
8134 + }
8135 + } else if (strcasecmp(field, "Description") == 0) {
8136 + /* Description */
8137 + if (pkg->description) {
8138 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8139 + if ( temp == NULL ){
8140 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8141 + return NULL;
8142 + }
8143 + temp[0]='\0';
8144 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8145 + }
8146 + } else {
8147 + goto UNKNOWN_FMT_FIELD;
8148 + }
8149 + break;
8150 + case 'e':
8151 + case 'E': {
8152 + /* Essential */
8153 + if (pkg->essential) {
8154 + temp = (char *)realloc(temp,16);
8155 + if ( temp == NULL ){
8156 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8157 + return NULL;
8158 + }
8159 + temp[0]='\0';
8160 + snprintf(temp, (16), "Essential: yes\n");
8161 + }
8162 + }
8163 + break;
8164 + case 'f':
8165 + case 'F': {
8166 + /* Filename */
8167 + if (pkg->filename) {
8168 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8169 + if ( temp == NULL ){
8170 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8171 + return NULL;
8172 + }
8173 + temp[0]='\0';
8174 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8175 + }
8176 + }
8177 + break;
8178 + case 'i':
8179 + case 'I': {
8180 + if (strcasecmp(field, "Installed-Size") == 0) {
8181 + /* Installed-Size */
8182 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8183 + if ( temp == NULL ){
8184 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8185 + return NULL;
8186 + }
8187 + temp[0]='\0';
8188 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8189 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8190 + temp = (char *)realloc(temp,29);
8191 + if ( temp == NULL ){
8192 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8193 + return NULL;
8194 + }
8195 + temp[0]='\0';
8196 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8197 + }
8198 + }
8199 + break;
8200 + case 'm':
8201 + case 'M': {
8202 + /* Maintainer | MD5sum */
8203 + if (strcasecmp(field, "Maintainer") == 0) {
8204 + /* Maintainer */
8205 + if (pkg->maintainer) {
8206 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8207 + if ( temp == NULL ){
8208 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8209 + return NULL;
8210 + }
8211 + temp[0]='\0';
8212 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8213 + }
8214 + } else if (strcasecmp(field, "MD5sum") == 0) {
8215 + /* MD5sum */
8216 + if (pkg->md5sum) {
8217 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8218 + if ( temp == NULL ){
8219 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8220 + return NULL;
8221 + }
8222 + temp[0]='\0';
8223 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8224 + }
8225 + } else {
8226 + goto UNKNOWN_FMT_FIELD;
8227 + }
8228 + }
8229 + break;
8230 + case 'p':
8231 + case 'P': {
8232 + if (strcasecmp(field, "Package") == 0) {
8233 + /* Package */
8234 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8235 + if ( temp == NULL ){
8236 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8237 + return NULL;
8238 + }
8239 + temp[0]='\0';
8240 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8241 + } else if (strcasecmp(field, "Priority") == 0) {
8242 + /* Priority */
8243 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8244 + if ( temp == NULL ){
8245 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8246 + return NULL;
8247 + }
8248 + temp[0]='\0';
8249 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8250 + } else if (strcasecmp(field, "Provides") == 0) {
8251 + /* Provides */
8252 + int i;
8253 +
8254 + if (pkg->provides_count) {
8255 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8256 + for ( i=0; i < pkg->provides_count; i++ ){
8257 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8258 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8259 + flag_provide_false = 1;
8260 + }
8261 + }
8262 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8263 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8264 + char provstr[LINE_LEN];
8265 + len = 15;
8266 + for(i = 0; i < pkg->provides_count; i++) {
8267 + len = len + (strlen(pkg->provides_str[i])+5);
8268 + }
8269 + temp = (char *)realloc(temp,len);
8270 + if ( temp == NULL ){
8271 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8272 + return NULL;
8273 + }
8274 + temp[0]='\0';
8275 + strncpy(temp, "Provides:", 12);
8276 + for(i = 0; i < pkg->provides_count; i++) {
8277 + if (strlen(pkg->provides_str[i])>0){;
8278 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8279 + strncat(temp, provstr, strlen(provstr));
8280 + }
8281 + }
8282 + strncat(temp, "\n", strlen("\n"));
8283 + }
8284 + }
8285 + } else {
8286 + goto UNKNOWN_FMT_FIELD;
8287 + }
8288 + }
8289 + break;
8290 + case 'r':
8291 + case 'R': {
8292 + int i;
8293 + /* Replaces | Recommends*/
8294 + if (strcasecmp (field, "Replaces") == 0) {
8295 + if (pkg->replaces_count) {
8296 + char replstr[LINE_LEN];
8297 + len = 14;
8298 + for (i = 0; i < pkg->replaces_count; i++) {
8299 + len = len + (strlen(pkg->replaces_str[i])+5);
8300 + }
8301 + temp = (char *)realloc(temp,len);
8302 + if ( temp == NULL ){
8303 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8304 + return NULL;
8305 + }
8306 + temp[0]='\0';
8307 + strncpy(temp, "Replaces:", 12);
8308 + for (i = 0; i < pkg->replaces_count; i++) {
8309 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8310 + strncat(temp, replstr, strlen(replstr));
8311 + }
8312 + strncat(temp, "\n", strlen("\n"));
8313 + }
8314 + } else if (strcasecmp (field, "Recommends") == 0) {
8315 + if (pkg->recommends_count) {
8316 + char recstr[LINE_LEN];
8317 + len = 15;
8318 + for(i = 0; i < pkg->recommends_count; i++) {
8319 + len = len + (strlen( pkg->recommends_str[i])+5);
8320 + }
8321 + temp = (char *)realloc(temp,len);
8322 + if ( temp == NULL ){
8323 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8324 + return NULL;
8325 + }
8326 + temp[0]='\0';
8327 + strncpy(temp, "Recommends:", 13);
8328 + for(i = 0; i < pkg->recommends_count; i++) {
8329 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8330 + strncat(temp, recstr, strlen(recstr));
8331 + }
8332 + strncat(temp, "\n", strlen("\n"));
8333 + }
8334 + } else {
8335 + goto UNKNOWN_FMT_FIELD;
8336 + }
8337 + }
8338 + break;
8339 + case 's':
8340 + case 'S': {
8341 + /* Section | Size | Source | Status | Suggests */
8342 + if (strcasecmp(field, "Section") == 0) {
8343 + /* Section */
8344 + if (pkg->section) {
8345 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8346 + if ( temp == NULL ){
8347 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8348 + return NULL;
8349 + }
8350 + temp[0]='\0';
8351 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8352 + }
8353 + } else if (strcasecmp(field, "Size") == 0) {
8354 + /* Size */
8355 + if (pkg->size) {
8356 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8357 + if ( temp == NULL ){
8358 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8359 + return NULL;
8360 + }
8361 + temp[0]='\0';
8362 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8363 + }
8364 + } else if (strcasecmp(field, "Source") == 0) {
8365 + /* Source */
8366 + if (pkg->source) {
8367 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8368 + if ( temp == NULL ){
8369 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8370 + return NULL;
8371 + }
8372 + temp[0]='\0';
8373 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8374 + }
8375 + } else if (strcasecmp(field, "Status") == 0) {
8376 + /* Status */
8377 + /* Benjamin Pineau note: we should avoid direct usage of
8378 + * strlen(arg) without keeping "arg" for later free()
8379 + */
8380 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8381 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8382 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8383 +
8384 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8385 + temp = (char *)realloc(temp,sum_of_sizes);
8386 + if ( temp == NULL ){
8387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8388 + return NULL;
8389 + }
8390 + temp[0]='\0';
8391 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8392 + free(pflag);
8393 + free(pwant);
8394 + if(pstat) /* pfstat can be NULL if ENOMEM */
8395 + free(pstat);
8396 + } else if (strcasecmp(field, "Suggests") == 0) {
8397 + if (pkg->suggests_count) {
8398 + int i;
8399 + char sugstr[LINE_LEN];
8400 + len = 13;
8401 + for(i = 0; i < pkg->suggests_count; i++) {
8402 + len = len + (strlen(pkg->suggests_str[i])+5);
8403 + }
8404 + temp = (char *)realloc(temp,len);
8405 + if ( temp == NULL ){
8406 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8407 + return NULL;
8408 + }
8409 + temp[0]='\0';
8410 + strncpy(temp, "Suggests:", 10);
8411 + for(i = 0; i < pkg->suggests_count; i++) {
8412 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8413 + strncat(temp, sugstr, strlen(sugstr));
8414 + }
8415 + strncat(temp, "\n", strlen("\n"));
8416 + }
8417 + } else {
8418 + goto UNKNOWN_FMT_FIELD;
8419 + }
8420 + }
8421 + break;
8422 + case 'v':
8423 + case 'V': {
8424 + /* Version */
8425 + char *version = pkg_version_str_alloc(pkg);
8426 + temp = (char *)realloc(temp,strlen(version)+14);
8427 + if ( temp == NULL ){
8428 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8429 + return NULL;
8430 + }
8431 + temp[0]='\0';
8432 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8433 + free(version);
8434 + }
8435 + break;
8436 + default:
8437 + goto UNKNOWN_FMT_FIELD;
8438 + }
8439 +
8440 + if ( strlen(temp)<2 ) {
8441 + temp[0]='\0';
8442 + }
8443 + return temp;
8444 +
8445 + UNKNOWN_FMT_FIELD:
8446 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8447 + if ( strlen(temp)<2 ) {
8448 + temp[0]='\0';
8449 + }
8450 +
8451 + return temp;
8452 +}
8453 +
8454 +void pkg_print_info(pkg_t *pkg, FILE *file)
8455 +{
8456 + char * buff;
8457 + if (pkg == NULL) {
8458 + return;
8459 + }
8460 +
8461 + buff = pkg_formatted_info(pkg);
8462 + if ( buff == NULL )
8463 + return;
8464 + if (strlen(buff)>2){
8465 + fwrite(buff, 1, strlen(buff), file);
8466 + }
8467 + free(buff);
8468 +}
8469 +
8470 +void pkg_print_status(pkg_t * pkg, FILE * file)
8471 +{
8472 + if (pkg == NULL) {
8473 + return;
8474 + }
8475 +
8476 + /* XXX: QUESTION: Do we actually want more fields here? The
8477 + original idea was to save space by installing only what was
8478 + needed for actual computation, (package, version, status,
8479 + essential, conffiles). The assumption is that all other fields
8480 + can be found in th available file.
8481 +
8482 + But, someone proposed the idea to make it possible to
8483 + reconstruct a .ipk from an installed package, (ie. for beaming
8484 + from one handheld to another). So, maybe we actually want a few
8485 + more fields here, (depends, suggests, etc.), so that that would
8486 + be guaranteed to work even in the absence of more information
8487 + from the available file.
8488 +
8489 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8490 + the essential info needs to be here for all installed packages
8491 + because they may not appear in the Packages files on various
8492 + feeds. Furthermore, one should be able to install from URL or
8493 + local storage without requiring a Packages file from any feed.
8494 + -Jamey
8495 + */
8496 + pkg_print_field(pkg, file, "Package");
8497 + pkg_print_field(pkg, file, "Version");
8498 + pkg_print_field(pkg, file, "Depends");
8499 + pkg_print_field(pkg, file, "Recommends");
8500 + pkg_print_field(pkg, file, "Suggests");
8501 + pkg_print_field(pkg, file, "Provides");
8502 + pkg_print_field(pkg, file, "Replaces");
8503 + pkg_print_field(pkg, file, "Conflicts");
8504 + pkg_print_field(pkg, file, "Status");
8505 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8506 + pkg_print_field(pkg, file, "Architecture");
8507 + pkg_print_field(pkg, file, "Conffiles");
8508 + pkg_print_field(pkg, file, "Installed-Time");
8509 + fputs("\n", file);
8510 +}
8511 +
8512 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8513 +{
8514 + char *buff;
8515 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8516 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8517 + __FUNCTION__, field);
8518 + }
8519 + buff = pkg_formatted_field(pkg, field);
8520 + if (strlen(buff)>2) {
8521 + fprintf(file, "%s", buff);
8522 + fflush(file);
8523 + }
8524 + free(buff);
8525 + return;
8526 +}
8527 +
8528 +/*
8529 + * libdpkg - Debian packaging suite library routines
8530 + * vercmp.c - comparison of version numbers
8531 + *
8532 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8533 + */
8534 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8535 +{
8536 + int r;
8537 +
8538 + if (pkg->epoch > ref_pkg->epoch) {
8539 + return 1;
8540 + }
8541 +
8542 + if (pkg->epoch < ref_pkg->epoch) {
8543 + return -1;
8544 + }
8545 +
8546 + r = verrevcmp(pkg->version, ref_pkg->version);
8547 + if (r) {
8548 + return r;
8549 + }
8550 +
8551 +#ifdef USE_DEBVERSION
8552 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8553 + if (r) {
8554 + return r;
8555 + }
8556 +
8557 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8558 +#endif
8559 +
8560 + return r;
8561 +}
8562 +
8563 +int verrevcmp(const char *val, const char *ref)
8564 +{
8565 + int vc, rc;
8566 + long vl, rl;
8567 + const char *vp, *rp;
8568 + const char *vsep, *rsep;
8569 +
8570 + if (!val) val= "";
8571 + if (!ref) ref= "";
8572 + for (;;) {
8573 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8574 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8575 + for (;;) {
8576 + vc= (val == vp) ? 0 : *val++;
8577 + rc= (ref == rp) ? 0 : *ref++;
8578 + if (!rc && !vc) break;
8579 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8580 + if (rc && !isalpha(rc)) rc += 256;
8581 + if (vc != rc) return vc - rc;
8582 + }
8583 + val= vp;
8584 + ref= rp;
8585 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8586 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8587 + if (vl != rl) return vl - rl;
8588 +
8589 + vc = *val;
8590 + rc = *ref;
8591 + vsep = strchr(".-", vc);
8592 + rsep = strchr(".-", rc);
8593 + if (vsep && !rsep) return -1;
8594 + if (!vsep && rsep) return +1;
8595 +
8596 + if (!*val && !*ref) return 0;
8597 + if (!*val) return -1;
8598 + if (!*ref) return +1;
8599 + }
8600 +}
8601 +
8602 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8603 +{
8604 + int r;
8605 +
8606 + r = pkg_compare_versions(it, ref);
8607 +
8608 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8609 + return r <= 0;
8610 + }
8611 +
8612 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8613 + return r >= 0;
8614 + }
8615 +
8616 + if (strcmp(op, "<<") == 0) {
8617 + return r < 0;
8618 + }
8619 +
8620 + if (strcmp(op, ">>") == 0) {
8621 + return r > 0;
8622 + }
8623 +
8624 + if (strcmp(op, "=") == 0) {
8625 + return r == 0;
8626 + }
8627 +
8628 + fprintf(stderr, "unknown operator: %s", op);
8629 + return 0;
8630 +}
8631 +
8632 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8633 +{
8634 + const pkg_t *a = *(const pkg_t **)p1;
8635 + const pkg_t *b = *(const pkg_t **)p2;
8636 + int namecmp;
8637 + int vercmp;
8638 + if (!a->name || !b->name) {
8639 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8640 + a, a->name, b, b->name);
8641 + return 0;
8642 + }
8643 +
8644 + namecmp = strcmp(a->name, b->name);
8645 + if (namecmp)
8646 + return namecmp;
8647 + vercmp = pkg_compare_versions(a, b);
8648 + if (vercmp)
8649 + return vercmp;
8650 + if (!a->arch_priority || !b->arch_priority) {
8651 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8652 + a, a->arch_priority, b, b->arch_priority);
8653 + return 0;
8654 + }
8655 + if (a->arch_priority > b->arch_priority)
8656 + return 1;
8657 + if (a->arch_priority < b->arch_priority)
8658 + return -1;
8659 + return 0;
8660 +}
8661 +
8662 +int abstract_pkg_name_compare(void *p1, void *p2)
8663 +{
8664 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8665 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8666 + if (!a->name || !b->name) {
8667 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8668 + a, a->name, b, b->name);
8669 + return 0;
8670 + }
8671 + return strcmp(a->name, b->name);
8672 +}
8673 +
8674 +
8675 +char *pkg_version_str_alloc(pkg_t *pkg)
8676 +{
8677 + char *complete_version;
8678 + char *epoch_str;
8679 +#ifdef USE_DEBVERSION
8680 + char *revision_str;
8681 + char *familiar_revision_str;
8682 +#endif
8683 +
8684 + if (pkg->epoch) {
8685 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8686 + } else {
8687 + epoch_str = strdup("");
8688 + }
8689 +
8690 +#ifdef USE_DEBVERSION
8691 + if (pkg->revision && strlen(pkg->revision)) {
8692 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8693 + } else {
8694 + revision_str = strdup("");
8695 + }
8696 +
8697 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8698 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8699 + } else {
8700 + familiar_revision_str = strdup("");
8701 + }
8702 +#endif
8703 +
8704 +#ifdef USE_DEBVERSION
8705 + sprintf_alloc(&complete_version, "%s%s%s%s",
8706 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8707 +#else
8708 + sprintf_alloc(&complete_version, "%s%s",
8709 + epoch_str, pkg->version);
8710 +#endif
8711 +
8712 + free(epoch_str);
8713 +#ifdef USE_DEBVERSION
8714 + free(revision_str);
8715 + free(familiar_revision_str);
8716 +#endif
8717 +
8718 + return complete_version;
8719 +}
8720 +
8721 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8722 +{
8723 + int err;
8724 + char *list_file_name = NULL;
8725 + FILE *list_file = NULL;
8726 + char *line;
8727 + char *installed_file_name;
8728 + int rootdirlen;
8729 +
8730 + pkg->installed_files_ref_cnt++;
8731 +
8732 + if (pkg->installed_files) {
8733 + return pkg->installed_files;
8734 + }
8735 +
8736 + pkg->installed_files = str_list_alloc();
8737 + if (pkg->installed_files == NULL) {
8738 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8739 + return NULL;
8740 + }
8741 +
8742 + /* For uninstalled packages, get the file list firectly from the package.
8743 + For installed packages, look at the package.list file in the database.
8744 + */
8745 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8746 + if (pkg->local_filename == NULL) {
8747 + return pkg->installed_files;
8748 + }
8749 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8750 + file. In other words, change deb_extract so that it can
8751 + simply return the file list as a char *[] rather than
8752 + insisting on writing in to a FILE * as it does now. */
8753 + list_file = tmpfile();
8754 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8755 + if (err) {
8756 + fclose(list_file);
8757 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8758 + __FUNCTION__, pkg->local_filename, strerror(err));
8759 + return pkg->installed_files;
8760 + }
8761 + rewind(list_file);
8762 + } else {
8763 + sprintf_alloc(&list_file_name, "%s/%s.list",
8764 + pkg->dest->info_dir, pkg->name);
8765 + if (! file_exists(list_file_name)) {
8766 + free(list_file_name);
8767 + return pkg->installed_files;
8768 + }
8769 +
8770 + list_file = fopen(list_file_name, "r");
8771 + if (list_file == NULL) {
8772 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8773 + list_file_name, strerror(errno));
8774 + free(list_file_name);
8775 + return pkg->installed_files;
8776 + }
8777 + free(list_file_name);
8778 + }
8779 +
8780 + rootdirlen = strlen( pkg->dest->root_dir );
8781 + while (1) {
8782 + char *file_name;
8783 +
8784 + line = file_read_line_alloc(list_file);
8785 + if (line == NULL) {
8786 + break;
8787 + }
8788 + str_chomp(line);
8789 + file_name = line;
8790 +
8791 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8792 + if( strncmp( pkg->dest->root_dir,
8793 + file_name,
8794 + rootdirlen ) ) {
8795 + if (*file_name == '.') {
8796 + file_name++;
8797 + }
8798 + if (*file_name == '/') {
8799 + file_name++;
8800 + }
8801 +
8802 + /* Freed in pkg_free_installed_files */
8803 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8804 + } else {
8805 + // already contains root_dir as header -> ABSOLUTE
8806 + sprintf_alloc(&installed_file_name, "%s", file_name);
8807 + }
8808 + str_list_append(pkg->installed_files, installed_file_name);
8809 + free(line);
8810 + }
8811 +
8812 + fclose(list_file);
8813 +
8814 + return pkg->installed_files;
8815 +}
8816 +
8817 +/* XXX: CLEANUP: This function and it's counterpart,
8818 + (pkg_get_installed_files), do not match our init/deinit naming
8819 + convention. Nor the alloc/free convention. But, then again, neither
8820 + of these conventions currrently fit the way these two functions
8821 + work. */
8822 +int pkg_free_installed_files(pkg_t *pkg)
8823 +{
8824 + str_list_elt_t *iter;
8825 +
8826 + pkg->installed_files_ref_cnt--;
8827 + if (pkg->installed_files_ref_cnt > 0) {
8828 + return 0;
8829 + }
8830 +
8831 + if (pkg->installed_files) {
8832 +
8833 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8834 + /* malloced in pkg_get_installed_files */
8835 + free (iter->data);
8836 + iter->data = NULL;
8837 + }
8838 +
8839 + str_list_deinit(pkg->installed_files);
8840 + }
8841 +
8842 + pkg->installed_files = NULL;
8843 +
8844 + return 0;
8845 +}
8846 +
8847 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8848 +{
8849 + int err;
8850 + char *list_file_name;
8851 +
8852 + //I don't think pkg_free_installed_files should be called here. Jamey
8853 + //pkg_free_installed_files(pkg);
8854 +
8855 + sprintf_alloc(&list_file_name, "%s/%s.list",
8856 + pkg->dest->info_dir, pkg->name);
8857 + if (!conf->noaction) {
8858 + err = unlink(list_file_name);
8859 + free(list_file_name);
8860 +
8861 + if (err) {
8862 + return errno;
8863 + }
8864 + }
8865 + return 0;
8866 +}
8867 +
8868 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8869 +{
8870 + conffile_list_elt_t *iter;
8871 + conffile_t *conffile;
8872 +
8873 + if (pkg == NULL) {
8874 + return NULL;
8875 + }
8876 +
8877 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8878 + conffile = iter->data;
8879 +
8880 + if (strcmp(conffile->name, file_name) == 0) {
8881 + return conffile;
8882 + }
8883 + }
8884 +
8885 + return NULL;
8886 +}
8887 +
8888 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8889 + const char *script, const char *args)
8890 +{
8891 + int err;
8892 + char *path;
8893 + char *cmd;
8894 +
8895 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8896 + maintainer script within a chroot environment. */
8897 +
8898 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8899 + have scripts in pkg->tmp_unpack_dir. */
8900 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8901 + if (pkg->dest == NULL) {
8902 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8903 + __FUNCTION__, pkg->name);
8904 + return EINVAL;
8905 + }
8906 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8907 + } else {
8908 + if (pkg->tmp_unpack_dir == NULL) {
8909 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8910 + __FUNCTION__, pkg->name);
8911 + return EINVAL;
8912 + }
8913 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8914 + }
8915 +
8916 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8917 + if (conf->noaction) return 0;
8918 +
8919 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8920 + scripts when running with offline_root mode and/or a dest other
8921 + than '/'. I've been playing around with some clever chroot
8922 + tricks and I might come up with something workable. */
8923 + if (conf->offline_root) {
8924 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8925 + }
8926 +
8927 + setenv("PKG_ROOT",
8928 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8929 +
8930 + if (! file_exists(path)) {
8931 + free(path);
8932 + return 0;
8933 + }
8934 +
8935 + if (conf->offline_root) {
8936 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8937 + free(path);
8938 + return 0;
8939 + }
8940 +
8941 + sprintf_alloc(&cmd, "%s %s", path, args);
8942 + free(path);
8943 +
8944 + err = xsystem(cmd);
8945 + free(cmd);
8946 +
8947 + if (err) {
8948 + fprintf(stderr, "%s script returned status %d\n", script, err);
8949 + return err;
8950 + }
8951 +
8952 + return 0;
8953 +}
8954 +
8955 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8956 +{
8957 + int i;
8958 +
8959 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8960 + if (pkg_state_want_map[i].value == sw) {
8961 + return strdup(pkg_state_want_map[i].str);
8962 + }
8963 + }
8964 +
8965 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8966 + __FUNCTION__, sw);
8967 + return strdup("<STATE_WANT_UNKNOWN>");
8968 +}
8969 +
8970 +pkg_state_want_t pkg_state_want_from_str(char *str)
8971 +{
8972 + int i;
8973 +
8974 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8975 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8976 + return pkg_state_want_map[i].value;
8977 + }
8978 + }
8979 +
8980 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8981 + __FUNCTION__, str);
8982 + return SW_UNKNOWN;
8983 +}
8984 +
8985 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8986 +{
8987 + int i;
8988 + int len = 3; /* ok\000 is minimum */
8989 + char *str = NULL;
8990 +
8991 + /* clear the temporary flags before converting to string */
8992 + sf &= SF_NONVOLATILE_FLAGS;
8993 +
8994 + if (sf == 0) {
8995 + return strdup("ok");
8996 + } else {
8997 +
8998 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8999 + if (sf & pkg_state_flag_map[i].value) {
9000 + len += strlen(pkg_state_flag_map[i].str) + 1;
9001 + }
9002 + }
9003 + str = malloc(len);
9004 + if ( str == NULL ) {
9005 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9006 + return NULL;
9007 + }
9008 + str[0] = 0;
9009 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9010 + if (sf & pkg_state_flag_map[i].value) {
9011 + strcat(str, pkg_state_flag_map[i].str);
9012 + strcat(str, ",");
9013 + }
9014 + }
9015 + len = strlen(str);
9016 + str[len-1] = 0; /* squash last comma */
9017 + return str;
9018 + }
9019 +}
9020 +
9021 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9022 +{
9023 + int i;
9024 + int sf = SF_OK;
9025 +
9026 + if (strcmp(str, "ok") == 0) {
9027 + return SF_OK;
9028 + }
9029 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9030 + const char *sfname = pkg_state_flag_map[i].str;
9031 + int sfname_len = strlen(sfname);
9032 + if (strncmp(str, sfname, sfname_len) == 0) {
9033 + sf |= pkg_state_flag_map[i].value;
9034 + str += sfname_len;
9035 + if (str[0] == ',') {
9036 + str++;
9037 + } else {
9038 + break;
9039 + }
9040 + }
9041 + }
9042 +
9043 + return sf;
9044 +}
9045 +
9046 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9047 +{
9048 + int i;
9049 +
9050 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9051 + if (pkg_state_status_map[i].value == ss) {
9052 + return strdup(pkg_state_status_map[i].str);
9053 + }
9054 + }
9055 +
9056 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9057 + __FUNCTION__, ss);
9058 + return strdup("<STATE_STATUS_UNKNOWN>");
9059 +}
9060 +
9061 +pkg_state_status_t pkg_state_status_from_str(char *str)
9062 +{
9063 + int i;
9064 +
9065 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9066 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9067 + return pkg_state_status_map[i].value;
9068 + }
9069 + }
9070 +
9071 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9072 + __FUNCTION__, str);
9073 + return SS_NOT_INSTALLED;
9074 +}
9075 +
9076 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9077 +{
9078 + nv_pair_list_elt_t *l;
9079 +
9080 + if (!pkg->architecture)
9081 + return 1;
9082 +
9083 + l = conf->arch_list.head;
9084 +
9085 + while (l) {
9086 + nv_pair_t *nv = l->data;
9087 + if (strcmp(nv->name, pkg->architecture) == 0) {
9088 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9089 + return 1;
9090 + }
9091 + l = l->next;
9092 + }
9093 +
9094 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9095 + return 0;
9096 +}
9097 +
9098 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9099 +{
9100 + nv_pair_list_elt_t *l;
9101 +
9102 + l = conf->arch_list.head;
9103 +
9104 + while (l) {
9105 + nv_pair_t *nv = l->data;
9106 + if (strcmp(nv->name, archname) == 0) {
9107 + int priority = strtol(nv->value, NULL, 0);
9108 + return priority;
9109 + }
9110 + l = l->next;
9111 + }
9112 + return 0;
9113 +}
9114 +
9115 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9116 +{
9117 + int i;
9118 + hash_table_t *pkg_hash = &conf->pkg_hash;
9119 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9120 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9121 +
9122 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9123 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9124 + /* update arch_priority for each package */
9125 + for (i = 0; i < available_pkgs->len; i++) {
9126 + pkg_t *pkg = available_pkgs->pkgs[i];
9127 + int arch_priority = 1;
9128 + if (!pkg)
9129 + continue;
9130 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9131 + if (pkg->architecture)
9132 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9133 + else
9134 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9135 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9136 + pkg->arch_priority = arch_priority;
9137 + }
9138 +
9139 + for (i = 0; i < available_pkgs->len; i++) {
9140 + pkg_t *pkg = available_pkgs->pkgs[i];
9141 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9142 + /* clear flags and want for any uninstallable package */
9143 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9144 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9145 + pkg->state_want = SW_UNKNOWN;
9146 + pkg->state_flag = 0;
9147 + }
9148 + }
9149 + pkg_vec_free(available_pkgs);
9150 +
9151 + /* update the file owner data structure */
9152 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9153 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9154 + for (i = 0; i < installed_pkgs->len; i++) {
9155 + pkg_t *pkg = installed_pkgs->pkgs[i];
9156 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9157 + str_list_elt_t *iter;
9158 + if (installed_files == NULL) {
9159 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9160 + break;
9161 + }
9162 + for (iter = installed_files->head; iter; iter = iter->next) {
9163 + char *installed_file = iter->data;
9164 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9165 + file_hash_set_file_owner(conf, installed_file, pkg);
9166 + }
9167 + }
9168 + pkg_vec_free(installed_pkgs);
9169 +
9170 + return 0;
9171 +}
9172 +
9173 +struct pkg_write_filelist_data {
9174 + ipkg_conf_t *conf;
9175 + pkg_t *pkg;
9176 + FILE *stream;
9177 +};
9178 +
9179 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9180 +{
9181 + struct pkg_write_filelist_data *data = data_;
9182 + pkg_t *entry = entry_;
9183 + if (entry == data->pkg) {
9184 + fprintf(data->stream, "%s\n", key);
9185 + }
9186 +}
9187 +
9188 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9189 +{
9190 + struct pkg_write_filelist_data data;
9191 + char *list_file_name = NULL;
9192 + int err = 0;
9193 +
9194 + if (!pkg) {
9195 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9196 + return -EINVAL;
9197 + }
9198 + ipkg_message(conf, IPKG_INFO,
9199 + " creating %s.list file\n", pkg->name);
9200 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9201 + if (!list_file_name) {
9202 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9203 + return -ENOMEM;
9204 + }
9205 + ipkg_message(conf, IPKG_INFO,
9206 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9207 + data.stream = fopen(list_file_name, "w");
9208 + if (!data.stream) {
9209 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9210 + list_file_name, strerror(errno));
9211 + return errno;
9212 + }
9213 + data.pkg = pkg;
9214 + data.conf = conf;
9215 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9216 + fclose(data.stream);
9217 + free(list_file_name);
9218 +
9219 + return err;
9220 +}
9221 +
9222 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9223 +{
9224 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9225 + hash_table_t *pkg_hash = &conf->pkg_hash;
9226 + int i;
9227 + int err;
9228 + if (conf->noaction)
9229 + return 0;
9230 +
9231 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9232 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9233 + for (i = 0; i < installed_pkgs->len; i++) {
9234 + pkg_t *pkg = installed_pkgs->pkgs[i];
9235 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9236 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9237 + err = pkg_write_filelist(conf, pkg);
9238 + if (err)
9239 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9240 + }
9241 + }
9242 + return 0;
9243 +}
9244 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg.h busybox-1.1.0-pre1-new/archival/libipkg/pkg.h
9245 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9246 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg.h 2005-12-07 21:25:30.000000000 +0100
9247 @@ -0,0 +1,230 @@
9248 +/* pkg.h - the itsy package management system
9249 +
9250 + Carl D. Worth
9251 +
9252 + Copyright (C) 2001 University of Southern California
9253 +
9254 + This program is free software; you can redistribute it and/or
9255 + modify it under the terms of the GNU General Public License as
9256 + published by the Free Software Foundation; either version 2, or (at
9257 + your option) any later version.
9258 +
9259 + This program is distributed in the hope that it will be useful, but
9260 + WITHOUT ANY WARRANTY; without even the implied warranty of
9261 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9262 + General Public License for more details.
9263 +*/
9264 +
9265 +#ifndef PKG_H
9266 +#define PKG_H
9267 +
9268 +#include <sys/types.h>
9269 +#include <sys/stat.h>
9270 +#include <unistd.h>
9271 +
9272 +#include "pkg_vec.h"
9273 +#include "str_list.h"
9274 +#include "pkg_src.h"
9275 +#include "pkg_dest.h"
9276 +#include "ipkg_conf.h"
9277 +#include "conffile_list.h"
9278 +
9279 +struct ipkg_conf;
9280 +
9281 +
9282 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9283 +
9284 +/* I think "Size" is currently the shortest field name */
9285 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9286 +
9287 +enum pkg_state_want
9288 +{
9289 + SW_UNKNOWN = 1,
9290 + SW_INSTALL,
9291 + SW_DEINSTALL,
9292 + SW_PURGE,
9293 + SW_LAST_STATE_WANT
9294 +};
9295 +typedef enum pkg_state_want pkg_state_want_t;
9296 +
9297 +enum pkg_state_flag
9298 +{
9299 + SF_OK = 0,
9300 + SF_REINSTREQ = 1,
9301 + SF_HOLD = 2, /* do not upgrade version */
9302 + SF_REPLACE = 4, /* replace this package */
9303 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9304 + SF_PREFER = 16, /* prefer this version */
9305 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9306 + SF_MARKED = 64, /* temporary mark */
9307 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9308 + SF_USER = 256,
9309 + SF_LAST_STATE_FLAG
9310 +};
9311 +typedef enum pkg_state_flag pkg_state_flag_t;
9312 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9313 +
9314 +enum pkg_state_status
9315 +{
9316 + SS_NOT_INSTALLED = 1,
9317 + SS_UNPACKED,
9318 + SS_HALF_CONFIGURED,
9319 + SS_INSTALLED,
9320 + SS_HALF_INSTALLED,
9321 + SS_CONFIG_FILES,
9322 + SS_POST_INST_FAILED,
9323 + SS_REMOVAL_FAILED,
9324 + SS_LAST_STATE_STATUS
9325 +};
9326 +typedef enum pkg_state_status pkg_state_status_t;
9327 +
9328 +struct abstract_pkg{
9329 + char * name;
9330 + int dependencies_checked;
9331 + pkg_vec_t * pkgs;
9332 + pkg_state_status_t state_status;
9333 + pkg_state_flag_t state_flag;
9334 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9335 + abstract_pkg_vec_t * provided_by;
9336 + abstract_pkg_vec_t * replaced_by;
9337 +};
9338 +
9339 +#include "pkg_depends.h"
9340 +
9341 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9342 +
9343 + The 3 version fields should go into a single version struct. (This
9344 + is especially important since, currently, pkg->version can easily
9345 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9346 + distinct. This has been the source of multiple bugs.
9347 +
9348 + The 3 state fields could possibly also go into their own struct.
9349 +
9350 + All fields which deal with lists of packages, (Depends,
9351 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9352 + be handled by a single struct in pkg_t
9353 +
9354 + All string fields for which there is a small set of possible
9355 + values, (section, maintainer, architecture, maybe version?), that
9356 + are reused among different packages -- for all such packages we
9357 + should move from "char *"s to some atom datatype to share data
9358 + storage and use less memory. We might even do reference counting,
9359 + but probably not since most often we only create new pkg_t structs,
9360 + we don't often free them. */
9361 +struct pkg
9362 +{
9363 + char *name;
9364 + unsigned long epoch;
9365 + char *version;
9366 + char *revision;
9367 + char *familiar_revision;
9368 + pkg_src_t *src;
9369 + pkg_dest_t *dest;
9370 + char *architecture;
9371 + char *section;
9372 + char *maintainer;
9373 + char *description;
9374 + pkg_state_want_t state_want;
9375 + pkg_state_flag_t state_flag;
9376 + pkg_state_status_t state_status;
9377 + char **depends_str;
9378 + int depends_count;
9379 + char **pre_depends_str;
9380 + int pre_depends_count;
9381 + char **recommends_str;
9382 + int recommends_count;
9383 + char **suggests_str;
9384 + int suggests_count;
9385 + compound_depend_t * depends;
9386 +
9387 + /* Abhaya: new conflicts */
9388 + char **conflicts_str;
9389 + compound_depend_t * conflicts;
9390 + int conflicts_count;
9391 +
9392 + char **replaces_str;
9393 + int replaces_count;
9394 + abstract_pkg_t ** replaces;
9395 +
9396 + char **provides_str;
9397 + int provides_count;
9398 + abstract_pkg_t ** provides;
9399 +
9400 + abstract_pkg_t *parent;
9401 +
9402 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9403 +
9404 + char *filename;
9405 + char *local_filename;
9406 + char *url;
9407 + char *tmp_unpack_dir;
9408 + char *md5sum;
9409 + char *size;
9410 + char *installed_size;
9411 + char *priority;
9412 + char *source;
9413 + conffile_list_t conffiles;
9414 + time_t installed_time;
9415 + /* As pointer for lazy evaluation */
9416 + str_list_t *installed_files;
9417 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9418 + mechanism to avoid the problem here, (which is that the
9419 + installed_files list was being freed from an inner loop while
9420 + still being used within an outer loop. */
9421 + int installed_files_ref_cnt;
9422 + int essential;
9423 + int arch_priority;
9424 +};
9425 +
9426 +pkg_t *pkg_new(void);
9427 +int pkg_init(pkg_t *pkg);
9428 +void pkg_deinit(pkg_t *pkg);
9429 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9430 +abstract_pkg_t *abstract_pkg_new(void);
9431 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9432 +
9433 +/*
9434 + * merges fields from newpkg into oldpkg.
9435 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9436 + */
9437 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9438 +
9439 +char *pkg_version_str_alloc(pkg_t *pkg);
9440 +
9441 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9442 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9443 +int abstract_pkg_name_compare(void *a, void *b);
9444 +
9445 +char * pkg_formatted_info(pkg_t *pkg );
9446 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9447 +
9448 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9449 +
9450 +void pkg_print_info(pkg_t *pkg, FILE *file);
9451 +void pkg_print_status(pkg_t * pkg, FILE * file);
9452 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9453 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9454 +int pkg_free_installed_files(pkg_t *pkg);
9455 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9456 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9457 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9458 + const char *script, const char *args);
9459 +
9460 +/* enum mappings */
9461 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9462 +pkg_state_want_t pkg_state_want_from_str(char *str);
9463 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9464 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9465 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9466 +pkg_state_status_t pkg_state_status_from_str(char *str);
9467 +
9468 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9469 +
9470 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9471 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9472 +int pkg_free_installed_files(pkg_t *pkg);
9473 +
9474 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9475 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9476 +
9477 +#endif
9478 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_depends.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_depends.c
9479 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9480 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_depends.c 2005-12-07 21:25:30.000000000 +0100
9481 @@ -0,0 +1,1029 @@
9482 +/* pkg_depends.c - the itsy package management system
9483 +
9484 + Steven M. Ayer
9485 +
9486 + Copyright (C) 2002 Compaq Computer Corporation
9487 +
9488 + This program is free software; you can redistribute it and/or
9489 + modify it under the terms of the GNU General Public License as
9490 + published by the Free Software Foundation; either version 2, or (at
9491 + your option) any later version.
9492 +
9493 + This program is distributed in the hope that it will be useful, but
9494 + WITHOUT ANY WARRANTY; without even the implied warranty of
9495 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9496 + General Public License for more details.
9497 +*/
9498 +
9499 +#include "ipkg.h"
9500 +#include <errno.h>
9501 +#include <ctype.h>
9502 +
9503 +#include "pkg.h"
9504 +#include "ipkg_utils.h"
9505 +#include "pkg_hash.h"
9506 +#include "ipkg_message.h"
9507 +#include "pkg_parse.h"
9508 +#include "hash_table.h"
9509 +
9510 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9511 +static depend_t * depend_init(void);
9512 +static void depend_deinit(depend_t *d);
9513 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9514 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9515 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9516 +
9517 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9518 +{
9519 + depend_t *depend = (depend_t *)cdata;
9520 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9521 + return 1;
9522 + else
9523 + return 0;
9524 +}
9525 +
9526 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9527 +{
9528 + depend_t *depend = (depend_t *)cdata;
9529 +#if 0
9530 + pkg_t * temp = pkg_new();
9531 + int comparison;
9532 + parseVersion(temp, depend->version);
9533 + comparison = pkg_compare_versions(pkg, temp);
9534 + free(temp);
9535 +
9536 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9537 + __FUNCTION__, pkg->name, pkg->version,
9538 + depend, depend->constraint, depend->version,
9539 + comparison, version_constraints_satisfied(depend, pkg));
9540 +#endif
9541 + if (version_constraints_satisfied(depend, pkg))
9542 + return 1;
9543 + else
9544 + return 0;
9545 +}
9546 +
9547 +/* returns ndependences or negative error value */
9548 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9549 + pkg_vec_t *unsatisfied, char *** unresolved)
9550 +{
9551 + pkg_t * satisfier_entry_pkg;
9552 + register int i, j, k;
9553 + int count, found;
9554 + char ** the_lost;
9555 + abstract_pkg_t * ab_pkg;
9556 +
9557 + /*
9558 + * this is a setup to check for redundant/cyclic dependency checks,
9559 + * which are marked at the abstract_pkg level
9560 + */
9561 + if (!(ab_pkg = pkg->parent)) {
9562 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9563 + *unresolved = NULL;
9564 + return 0;
9565 + }
9566 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9567 + *unresolved = NULL;
9568 + return 0;
9569 + } else {
9570 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9571 + }
9572 + /**/
9573 +
9574 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9575 + if (!count){
9576 + *unresolved = NULL;
9577 + return 0;
9578 + }
9579 +
9580 + the_lost = NULL;
9581 +
9582 + /* foreach dependency */
9583 + for (i = 0; i < count; i++) {
9584 + compound_depend_t * compound_depend = &pkg->depends[i];
9585 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9586 + found = 0;
9587 + satisfier_entry_pkg = NULL;
9588 +
9589 + if (compound_depend->type == GREEDY_DEPEND) {
9590 + /* foreach possible satisfier */
9591 + for (j = 0; j < compound_depend->possibility_count; j++) {
9592 + /* foreach provided_by, which includes the abstract_pkg itself */
9593 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9594 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9595 + int nposs = ab_provider_vec->len;
9596 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9597 + int l;
9598 + for (l = 0; l < nposs; l++) {
9599 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9600 + /* if no depends on this one, try the first package that Provides this one */
9601 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9602 + continue;
9603 + }
9604 +
9605 + /* cruise this possiblity's pkg_vec looking for an installed version */
9606 + for (k = 0; k < test_vec->len; k++) {
9607 + pkg_t *pkg_scout = test_vec->pkgs[k];
9608 + /* not installed, and not already known about? */
9609 + if ((pkg_scout->state_want != SW_INSTALL)
9610 + && !pkg_scout->parent->dependencies_checked
9611 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9612 + char ** newstuff = NULL;
9613 + int rc;
9614 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9615 + /* check for not-already-installed dependencies */
9616 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9617 + pkg_scout,
9618 + tmp_vec,
9619 + &newstuff);
9620 + if (newstuff == NULL) {
9621 + int i;
9622 + int ok = 1;
9623 + for (i = 0; i < rc; i++) {
9624 + pkg_t *p = tmp_vec->pkgs[i];
9625 + if (p->state_want == SW_INSTALL)
9626 + continue;
9627 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9628 + ok = 0;
9629 + break;
9630 + }
9631 + pkg_vec_free (tmp_vec);
9632 + if (ok) {
9633 + /* mark this one for installation */
9634 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9635 + pkg_vec_insert(unsatisfied, pkg_scout);
9636 + }
9637 + } else {
9638 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9639 + free (newstuff);
9640 + }
9641 + }
9642 + }
9643 + }
9644 + }
9645 +
9646 + continue;
9647 + }
9648 +
9649 + /* foreach possible satisfier, look for installed package */
9650 + for (j = 0; j < compound_depend->possibility_count; j++) {
9651 + /* foreach provided_by, which includes the abstract_pkg itself */
9652 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9653 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9654 + pkg_t *satisfying_pkg =
9655 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9656 + pkg_installed_and_constraint_satisfied,
9657 + dependence_to_satisfy, 1);
9658 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9659 + if (satisfying_pkg != NULL) {
9660 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9661 + satisfying_pkg = NULL;
9662 + }
9663 + }
9664 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9665 + if (satisfying_pkg != NULL) {
9666 + found = 1;
9667 + break;
9668 + }
9669 +
9670 + }
9671 + /* if nothing installed matches, then look for uninstalled satisfier */
9672 + if (!found) {
9673 + /* foreach possible satisfier, look for installed package */
9674 + for (j = 0; j < compound_depend->possibility_count; j++) {
9675 + /* foreach provided_by, which includes the abstract_pkg itself */
9676 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9677 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9678 + pkg_t *satisfying_pkg =
9679 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9680 + pkg_constraint_satisfied,
9681 + dependence_to_satisfy, 1);
9682 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9683 + if (satisfying_pkg != NULL) {
9684 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9685 + satisfying_pkg = NULL;
9686 + }
9687 + }
9688 +
9689 + /* user request overrides package recommendation */
9690 + if (satisfying_pkg != NULL
9691 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9692 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9693 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9694 + pkg->name, satisfying_pkg->name);
9695 + continue;
9696 + }
9697 +
9698 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9699 + if (satisfying_pkg != NULL) {
9700 + satisfier_entry_pkg = satisfying_pkg;
9701 + break;
9702 + }
9703 + }
9704 + }
9705 +
9706 + /* we didn't find one, add something to the unsatisfied vector */
9707 + if (!found) {
9708 + if (!satisfier_entry_pkg) {
9709 + /* failure to meet recommendations is not an error */
9710 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9711 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9712 + else
9713 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9714 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9715 + }
9716 + else {
9717 + if (compound_depend->type == SUGGEST) {
9718 + /* just mention it politely */
9719 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9720 + pkg->name, satisfier_entry_pkg->name);
9721 + } else {
9722 + char ** newstuff = NULL;
9723 +
9724 + if (satisfier_entry_pkg != pkg &&
9725 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9726 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9727 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9728 + satisfier_entry_pkg,
9729 + unsatisfied,
9730 + &newstuff);
9731 + the_lost = merge_unresolved(the_lost, newstuff);
9732 + }
9733 + }
9734 + }
9735 + }
9736 + }
9737 + *unresolved = the_lost;
9738 +
9739 + return unsatisfied->len;
9740 +}
9741 +
9742 +/*checking for conflicts !in replaces
9743 + If a packages conflicts with another but is also replacing it, I should not consider it a
9744 + really conflicts
9745 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9746 +*/
9747 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9748 +{
9749 + int i ;
9750 + int replaces_count = pkg->replaces_count;
9751 + abstract_pkg_t **replaces;
9752 +
9753 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9754 + return 0;
9755 +
9756 + replaces = pkg->replaces;
9757 +
9758 + for (i = 0; i < replaces_count; i++) {
9759 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9760 + return 1;
9761 + }
9762 + return 0;
9763 +
9764 +}
9765 +
9766 +
9767 +/* Abhaya: added support for conflicts */
9768 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9769 +{
9770 + pkg_vec_t * installed_conflicts, * test_vec;
9771 + compound_depend_t * conflicts;
9772 + depend_t ** possible_satisfiers;
9773 + depend_t * possible_satisfier;
9774 + register int i, j, k;
9775 + int count;
9776 + abstract_pkg_t * ab_pkg;
9777 + pkg_t **pkg_scouts;
9778 + pkg_t *pkg_scout;
9779 +
9780 + /*
9781 + * this is a setup to check for redundant/cyclic dependency checks,
9782 + * which are marked at the abstract_pkg level
9783 + */
9784 + if(!(ab_pkg = pkg->parent)){
9785 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9786 + return (pkg_vec_t *)NULL;
9787 + }
9788 +
9789 + conflicts = pkg->conflicts;
9790 + if(!conflicts){
9791 + return (pkg_vec_t *)NULL;
9792 + }
9793 + installed_conflicts = pkg_vec_alloc();
9794 +
9795 + count = pkg->conflicts_count;
9796 +
9797 +
9798 +
9799 + /* foreach conflict */
9800 + for(i = 0; i < pkg->conflicts_count; i++){
9801 +
9802 + possible_satisfiers = conflicts->possibilities;
9803 +
9804 + /* foreach possible satisfier */
9805 + for(j = 0; j < conflicts->possibility_count; j++){
9806 + possible_satisfier = possible_satisfiers[j];
9807 + if (!possible_satisfier)
9808 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9809 + if (!possible_satisfier->pkg)
9810 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9811 + test_vec = possible_satisfier->pkg->pkgs;
9812 + if (test_vec) {
9813 + /* pkg_vec found, it is an actual package conflict
9814 + * cruise this possiblity's pkg_vec looking for an installed version */
9815 + pkg_scouts = test_vec->pkgs;
9816 + for(k = 0; k < test_vec->len; k++){
9817 + pkg_scout = pkg_scouts[k];
9818 + if (!pkg_scout) {
9819 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9820 + continue;
9821 + }
9822 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9823 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9824 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9825 + pkg_vec_insert(installed_conflicts, pkg_scout);
9826 + }
9827 + }
9828 + }
9829 + }
9830 + }
9831 + conflicts++;
9832 + }
9833 +
9834 + if (installed_conflicts->len)
9835 + return installed_conflicts;
9836 + pkg_vec_free(installed_conflicts);
9837 + return (pkg_vec_t *)NULL;
9838 +}
9839 +
9840 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9841 +{
9842 + pkg_t * temp;
9843 + int comparison;
9844 +
9845 + if(depends->constraint == NONE)
9846 + return 1;
9847 +
9848 + temp = pkg_new();
9849 +
9850 + parseVersion(temp, depends->version);
9851 +
9852 + comparison = pkg_compare_versions(pkg, temp);
9853 +
9854 + free(temp);
9855 +
9856 + if((depends->constraint == EARLIER) &&
9857 + (comparison < 0))
9858 + return 1;
9859 + else if((depends->constraint == LATER) &&
9860 + (comparison > 0))
9861 + return 1;
9862 + else if(comparison == 0)
9863 + return 1;
9864 + else if((depends->constraint == LATER_EQUAL) &&
9865 + (comparison >= 0))
9866 + return 1;
9867 + else if((depends->constraint == EARLIER_EQUAL) &&
9868 + (comparison <= 0))
9869 + return 1;
9870 +
9871 + return 0;
9872 +}
9873 +
9874 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9875 +{
9876 + abstract_pkg_t *apkg = depend->pkg;
9877 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9878 + int n_providers = provider_apkgs->len;
9879 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9880 + pkg_vec_t *pkg_vec;
9881 + int n_pkgs ;
9882 + int i;
9883 + int j;
9884 +
9885 + for (i = 0; i < n_providers; i++) {
9886 + abstract_pkg_t *papkg = apkgs[i];
9887 + pkg_vec = papkg->pkgs;
9888 + if (pkg_vec) {
9889 + n_pkgs = pkg_vec->len;
9890 + for (j = 0; j < n_pkgs; j++) {
9891 + pkg_t *pkg = pkg_vec->pkgs[j];
9892 + if (version_constraints_satisfied(depend, pkg)) {
9893 + return 1;
9894 + }
9895 + }
9896 + }
9897 + }
9898 + return 0;
9899 +}
9900 +
9901 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9902 +{
9903 + abstract_pkg_t *apkg = depend->pkg;
9904 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9905 + int n_providers = provider_apkgs->len;
9906 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9907 + int i;
9908 + int n_pkgs;
9909 + int j;
9910 +
9911 + for (i = 0; i < n_providers; i++) {
9912 + abstract_pkg_t *papkg = apkgs[i];
9913 + pkg_vec_t *pkg_vec = papkg->pkgs;
9914 + if (pkg_vec) {
9915 + n_pkgs = pkg_vec->len;
9916 + for (j = 0; j < n_pkgs; j++) {
9917 + pkg_t *pkg = pkg_vec->pkgs[j];
9918 + if (version_constraints_satisfied(depend, pkg)) {
9919 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9920 + return 1;
9921 + }
9922 + }
9923 + }
9924 + }
9925 + return 0;
9926 +}
9927 +
9928 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9929 +{
9930 + register int i;
9931 + pkg_t ** pkgs = vec->pkgs;
9932 +
9933 + for(i = 0; i < vec->len; i++)
9934 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9935 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9936 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9937 + return 1;
9938 + return 0;
9939 +}
9940 +
9941 +
9942 +#ifdef DeadCode
9943 +/**
9944 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9945 + * the same abstract package and 0 otherwise.
9946 + */
9947 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9948 +{
9949 + abstract_pkg_t **provides = pkg->provides;
9950 + int provides_count = pkg->provides_count;
9951 + abstract_pkg_t **replacee_provides = replacee->provides;
9952 + int replacee_provides_count = replacee->provides_count;
9953 + int i, j;
9954 + for (i = 0; i < provides_count; i++) {
9955 + abstract_pkg_t *apkg = provides[i];
9956 + for (j = 0; j < replacee_provides_count; j++) {
9957 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9958 + if (apkg == replacee_apkg)
9959 + return 1;
9960 + }
9961 + }
9962 + return 0;
9963 +}
9964 +#endif
9965 +
9966 +/**
9967 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9968 + * and 0 otherwise.
9969 + */
9970 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9971 +{
9972 + abstract_pkg_t **provides = pkg->provides;
9973 + int provides_count = pkg->provides_count;
9974 + int i;
9975 + for (i = 0; i < provides_count; i++) {
9976 + if (provides[i] == providee)
9977 + return 1;
9978 + }
9979 + return 0;
9980 +}
9981 +
9982 +/**
9983 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9984 + * otherwise.
9985 + */
9986 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9987 +{
9988 + abstract_pkg_t **replaces = pkg->replaces;
9989 + int replaces_count = pkg->replaces_count;
9990 + abstract_pkg_t **replacee_provides = pkg->provides;
9991 + int replacee_provides_count = pkg->provides_count;
9992 + int i, j;
9993 + for (i = 0; i < replaces_count; i++) {
9994 + abstract_pkg_t *abstract_replacee = replaces[i];
9995 + for (j = 0; j < replacee_provides_count; j++) {
9996 + if (replacee_provides[j] == abstract_replacee)
9997 + return 1;
9998 + }
9999 + }
10000 + return 0;
10001 +}
10002 +
10003 +
10004 +/**
10005 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10006 + * otherwise.
10007 + */
10008 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10009 +{
10010 + compound_depend_t *conflicts = pkg->conflicts;
10011 + int conflicts_count = pkg->conflicts_count;
10012 + int i, j;
10013 + for (i = 0; i < conflicts_count; i++) {
10014 + int possibility_count = conflicts[i].possibility_count;
10015 + struct depend **possibilities = conflicts[i].possibilities;
10016 + for (j = 0; j < possibility_count; j++) {
10017 + if (possibilities[j]->pkg == conflictee) {
10018 + return 1;
10019 + }
10020 + }
10021 + }
10022 + return 0;
10023 +}
10024 +
10025 +/**
10026 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10027 + * conflictee's provides and 0 otherwise.
10028 + */
10029 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10030 +{
10031 + compound_depend_t *conflicts = pkg->conflicts;
10032 + int conflicts_count = pkg->conflicts_count;
10033 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10034 + int conflictee_provides_count = conflictee->provides_count;
10035 + int i, j, k;
10036 + int possibility_count;
10037 + struct depend **possibilities;
10038 + abstract_pkg_t *possibility ;
10039 +
10040 + for (i = 0; i < conflicts_count; i++) {
10041 + possibility_count = conflicts[i].possibility_count;
10042 + possibilities = conflicts[i].possibilities;
10043 + for (j = 0; j < possibility_count; j++) {
10044 + possibility = possibilities[j]->pkg;
10045 + for (k = 0; k < conflictee_provides_count; k++) {
10046 + if (possibility == conflictee_provides[k]) {
10047 + return 1;
10048 + }
10049 + }
10050 + }
10051 + }
10052 + return 0;
10053 +}
10054 +
10055 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10056 +{
10057 + int oldlen = 0, newlen = 0;
10058 + char ** result;
10059 + register int i, j;
10060 +
10061 + if(!newstuff)
10062 + return oldstuff;
10063 +
10064 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10065 + while(newstuff && newstuff[newlen]) newlen++;
10066 +
10067 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10068 + if (result == NULL) {
10069 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10070 + return NULL;
10071 + }
10072 +
10073 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10074 + *(result + i) = *(newstuff + j);
10075 +
10076 + *(result + i) = NULL;
10077 +
10078 + return result;
10079 +}
10080 +
10081 +/*
10082 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10083 + * this is null terminated, no count is carried around
10084 + */
10085 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10086 +{
10087 + int count;
10088 + char ** resized;
10089 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10090 +
10091 + count = 0;
10092 + while(the_lost && the_lost[count]) count++;
10093 +
10094 + count++; /* need one to hold the null */
10095 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10096 + if (resized == NULL) {
10097 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10098 + return NULL;
10099 + }
10100 + resized[count - 1] = strdup(depend_str);
10101 + resized[count] = NULL;
10102 +
10103 + return resized;
10104 +}
10105 +
10106 +void printDepends(pkg_t * pkg)
10107 +{
10108 + register int i, j;
10109 + compound_depend_t * depend;
10110 + int count;
10111 +
10112 + count = pkg->pre_depends_count + pkg->depends_count;
10113 +
10114 + depend = pkg->depends;
10115 + if(!depend){
10116 + fprintf(stderr, "Depends pointer is NULL\n");
10117 + return;
10118 + }
10119 + for(i = 0; i < count; i++){
10120 + fprintf(stderr, "%s has %d possibilities:\n",
10121 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10122 + depend->possibility_count);
10123 + for(j = 0; j < depend->possibility_count; j++)
10124 + fprintf(stderr, "\t%s version %s (%d)\n",
10125 + depend->possibilities[j]->pkg->name,
10126 + depend->possibilities[j]->version,
10127 + depend->possibilities[j]->constraint);
10128 + depend++;
10129 + }
10130 +}
10131 +
10132 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10133 +{
10134 + register int i, j;
10135 +
10136 + /* every pkg provides itself */
10137 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10138 +
10139 + if (!pkg->provides_count)
10140 + return 0;
10141 +
10142 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10143 + if (pkg->provides == NULL) {
10144 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10145 + return -1 ;
10146 + }
10147 + pkg->provides[0] = ab_pkg;
10148 +
10149 + // if (strcmp(ab_pkg->name, pkg->name))
10150 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10151 +
10152 + for(i = 0; i < pkg->provides_count; i++){
10153 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10154 +
10155 + pkg->provides[i+1] = provided_abpkg;
10156 +
10157 + j = 0;
10158 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10159 + }
10160 + return 0;
10161 +}
10162 +
10163 +/* Abhaya: added conflicts support */
10164 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10165 +{
10166 + register int i;
10167 + compound_depend_t * conflicts;
10168 +
10169 + if (!pkg->conflicts_count)
10170 + return 0;
10171 +
10172 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10173 + pkg->conflicts_count);
10174 + if (conflicts == NULL) {
10175 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10176 + return -1;
10177 + }
10178 + for (i = 0; i < pkg->conflicts_count; i++) {
10179 + conflicts->type = CONFLICTS;
10180 + parseDepends(conflicts, hash,
10181 + pkg->conflicts_str[i]);
10182 +#if 0
10183 + for (j = 0; j < conflicts->possibility_count; j++) {
10184 + depend_t *possibility = conflicts->possibilities[j];
10185 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10186 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10187 + }
10188 +#endif
10189 + conflicts++;
10190 + }
10191 + return 0;
10192 +}
10193 +
10194 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10195 +{
10196 + register int i, j;
10197 +
10198 + if (!pkg->replaces_count)
10199 + return 0;
10200 +
10201 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10202 + if (pkg->replaces == NULL) {
10203 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10204 + return -1;
10205 + }
10206 +
10207 + // if (strcmp(ab_pkg->name, pkg->name))
10208 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10209 +
10210 + for(i = 0; i < pkg->replaces_count; i++){
10211 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10212 +
10213 + pkg->replaces[i] = old_abpkg;
10214 +
10215 + j = 0;
10216 + if (!old_abpkg->replaced_by)
10217 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10218 + if ( old_abpkg->replaced_by == NULL ){
10219 + return -1;
10220 + }
10221 + /* if a package pkg both replaces and conflicts old_abpkg,
10222 + * then add it to the replaced_by vector so that old_abpkg
10223 + * will be upgraded to ab_pkg automatically */
10224 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10225 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10226 + }
10227 + return 0;
10228 +}
10229 +
10230 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10231 +{
10232 + int count;
10233 + register int i;
10234 + compound_depend_t * depends;
10235 +
10236 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10237 + return 0;
10238 +
10239 + if (0 && pkg->pre_depends_count)
10240 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10241 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10242 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10243 + if (depends == NULL) {
10244 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10245 + return -1;
10246 + }
10247 +
10248 +
10249 + for(i = 0; i < pkg->pre_depends_count; i++){
10250 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10251 + if (0 && pkg->pre_depends_count)
10252 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10253 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10254 + depends->type = PREDEPEND;
10255 + depends++;
10256 + }
10257 +
10258 + for(i = 0; i < pkg->recommends_count; i++){
10259 + parseDepends(depends, hash, pkg->recommends_str[i]);
10260 + if (0 && pkg->recommends_count)
10261 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10262 + pkg->recommends_str[i], depends, depends->possibility_count);
10263 + depends->type = RECOMMEND;
10264 + depends++;
10265 + }
10266 +
10267 + for(i = 0; i < pkg->suggests_count; i++){
10268 + parseDepends(depends, hash, pkg->suggests_str[i]);
10269 + if (0 && pkg->suggests_count)
10270 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10271 + pkg->suggests_str[i], depends, depends->possibility_count);
10272 + depends->type = SUGGEST;
10273 + depends++;
10274 + }
10275 +
10276 + for(i = 0; i < pkg->depends_count; i++){
10277 + parseDepends(depends, hash, pkg->depends_str[i]);
10278 + if (0 && pkg->depends_count)
10279 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10280 + pkg->depends_str[i], depends, depends->possibility_count);
10281 + depends++;
10282 + }
10283 + return 0;
10284 +}
10285 +
10286 +/*
10287 + * pkg_depend_string: returns the depends string specified by index.
10288 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10289 + * [0,npredepends) -> returns pre_depends_str[index]
10290 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10291 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10292 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10293 + */
10294 +char *pkg_depend_str(pkg_t *pkg, int index)
10295 +{
10296 + if (index < pkg->pre_depends_count) {
10297 + return pkg->pre_depends_str[index];
10298 + }
10299 + index -= pkg->pre_depends_count;
10300 +
10301 + if (index < pkg->recommends_count) {
10302 + return pkg->recommends_str[index];
10303 + }
10304 + index -= pkg->recommends_count;
10305 +
10306 + if (index < pkg->suggests_count) {
10307 + return pkg->suggests_str[index];
10308 + }
10309 + index -= pkg->suggests_count;
10310 +
10311 + if (index < pkg->depends_count) {
10312 + return pkg->depends_str[index];
10313 + }
10314 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10315 + return NULL;
10316 +}
10317 +
10318 +void freeDepends(pkg_t *pkg)
10319 +{
10320 + int i;
10321 +
10322 + if (pkg == NULL || pkg->depends == NULL) {
10323 + return;
10324 + }
10325 +
10326 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10327 + for (i=0; i < pkg->depends->possibility_count; i++) {
10328 + depend_deinit(pkg->depends->possibilities[i]);
10329 + }
10330 + free(pkg->depends->possibilities);
10331 + free(pkg->depends);
10332 + pkg->depends = NULL;
10333 +}
10334 +
10335 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10336 +{
10337 + compound_depend_t * depends;
10338 + int count, othercount;
10339 + register int i, j;
10340 + abstract_pkg_t * ab_depend;
10341 + abstract_pkg_t ** temp;
10342 +
10343 + count = pkg->pre_depends_count + pkg->depends_count;
10344 + depends = pkg->depends;
10345 +
10346 + if (0 && pkg->pre_depends_count)
10347 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10348 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10349 + for (i = 0; i < count; i++) {
10350 + if (0 && pkg->pre_depends_count)
10351 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10352 + for (j = 0; j < depends->possibility_count; j++){
10353 + ab_depend = depends->possibilities[j]->pkg;
10354 + if(!ab_depend->depended_upon_by)
10355 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10356 +
10357 + temp = ab_depend->depended_upon_by;
10358 + othercount = 1;
10359 + while(*temp){
10360 + temp++;
10361 + othercount++;
10362 + }
10363 + *temp = ab_pkg;
10364 +
10365 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10366 + (othercount + 1) * sizeof(abstract_pkg_t *));
10367 + /* the array may have moved */
10368 + temp = ab_depend->depended_upon_by + othercount;
10369 + *temp = NULL;
10370 + }
10371 + depends++;
10372 + }
10373 +}
10374 +
10375 +static depend_t * depend_init(void)
10376 +{
10377 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10378 + if ( d==NULL ){
10379 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10380 + return NULL;
10381 + }
10382 + d->constraint = NONE;
10383 + d->version = NULL;
10384 + d->pkg = NULL;
10385 +
10386 + return d;
10387 +}
10388 +
10389 +static void depend_deinit(depend_t *d)
10390 +{
10391 + free(d);
10392 +}
10393 +
10394 +static int parseDepends(compound_depend_t *compound_depend,
10395 + hash_table_t * hash, char * depend_str)
10396 +{
10397 + char * pkg_name, buffer[2048];
10398 + int num_of_ors = 0;
10399 + register int i;
10400 + register char * src, * dest;
10401 + depend_t ** possibilities;
10402 +
10403 + /* first count the number of ored possibilities for satisfying dependency */
10404 + src = depend_str;
10405 + while(*src)
10406 + if(*src++ == '|')
10407 + num_of_ors++;
10408 +
10409 + compound_depend->type = DEPEND;
10410 +
10411 + compound_depend->possibility_count = num_of_ors + 1;
10412 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10413 + if (!possibilities)
10414 + return -ENOMEM;
10415 + compound_depend->possibilities = possibilities;
10416 +
10417 + src = depend_str;
10418 + for(i = 0; i < num_of_ors + 1; i++){
10419 + possibilities[i] = depend_init();
10420 + if (!possibilities[i])
10421 + return -ENOMEM;
10422 + /* gobble up just the name first */
10423 + dest = buffer;
10424 + while(*src &&
10425 + !isspace(*src) &&
10426 + (*src != '(') &&
10427 + (*src != '*') &&
10428 + (*src != '|'))
10429 + *dest++ = *src++;
10430 + *dest = '\0';
10431 + pkg_name = trim_alloc(buffer);
10432 + if (pkg_name == NULL )
10433 + return -ENOMEM;
10434 +
10435 + /* now look at possible version info */
10436 +
10437 + /* skip to next chars */
10438 + if(isspace(*src))
10439 + while(*src && isspace(*src)) src++;
10440 +
10441 + /* extract constraint and version */
10442 + if(*src == '('){
10443 + src++;
10444 + if(!strncmp(src, "<<", 2)){
10445 + possibilities[i]->constraint = EARLIER;
10446 + src += 2;
10447 + }
10448 + else if(!strncmp(src, "<=", 2)){
10449 + possibilities[i]->constraint = EARLIER_EQUAL;
10450 + src += 2;
10451 + }
10452 + else if(!strncmp(src, ">=", 2)){
10453 + possibilities[i]->constraint = LATER_EQUAL;
10454 + src += 2;
10455 + }
10456 + else if(!strncmp(src, ">>", 2)){
10457 + possibilities[i]->constraint = LATER;
10458 + src += 2;
10459 + }
10460 + else if(!strncmp(src, "=", 1)){
10461 + possibilities[i]->constraint = EQUAL;
10462 + src++;
10463 + }
10464 + /* should these be here to support deprecated designations; dpkg does */
10465 + else if(!strncmp(src, "<", 1)){
10466 + possibilities[i]->constraint = EARLIER_EQUAL;
10467 + src++;
10468 + }
10469 + else if(!strncmp(src, ">", 1)){
10470 + possibilities[i]->constraint = LATER_EQUAL;
10471 + src++;
10472 + }
10473 +
10474 + /* now we have any constraint, pass space to version string */
10475 + while(isspace(*src)) src++;
10476 +
10477 + /* this would be the version string */
10478 + dest = buffer;
10479 + while(*src && *src != ')')
10480 + *dest++ = *src++;
10481 + *dest = '\0';
10482 +
10483 + possibilities[i]->version = trim_alloc(buffer);
10484 + /* fprintf(stderr, "let's print the depends version string:");
10485 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10486 + if (possibilities[i]->version == NULL )
10487 + return -ENOMEM;
10488 +
10489 +
10490 + }
10491 + /* hook up the dependency to its abstract pkg */
10492 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10493 +
10494 + free(pkg_name);
10495 +
10496 + /* now get past the ) and any possible | chars */
10497 + while(*src &&
10498 + (isspace(*src) ||
10499 + (*src == ')') ||
10500 + (*src == '|')))
10501 + src++;
10502 + if (*src == '*')
10503 + {
10504 + compound_depend->type = GREEDY_DEPEND;
10505 + src++;
10506 + }
10507 + }
10508 +
10509 + return 0;
10510 +}
10511 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_depends.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_depends.h
10512 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10513 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_depends.h 2005-12-07 21:25:30.000000000 +0100
10514 @@ -0,0 +1,105 @@
10515 +/* pkg_depends.h - the itsy package management system
10516 +
10517 + Steven M. Ayer
10518 +
10519 + Copyright (C) 2002 Compaq Computer Corporation
10520 +
10521 + This program is free software; you can redistribute it and/or
10522 + modify it under the terms of the GNU General Public License as
10523 + published by the Free Software Foundation; either version 2, or (at
10524 + your option) any later version.
10525 +
10526 + This program is distributed in the hope that it will be useful, but
10527 + WITHOUT ANY WARRANTY; without even the implied warranty of
10528 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10529 + General Public License for more details.
10530 +*/
10531 +
10532 +#ifndef PKG_DEPENDS_H
10533 +#define PKG_DEPENDS_H
10534 +
10535 +#include "pkg.h"
10536 +#include "pkg_hash.h"
10537 +
10538 +enum depend_type {
10539 + PREDEPEND,
10540 + DEPEND,
10541 + CONFLICTS,
10542 + GREEDY_DEPEND,
10543 + RECOMMEND,
10544 + SUGGEST
10545 +};
10546 +typedef enum depend_type depend_type_t;
10547 +
10548 +enum version_constraint {
10549 + NONE,
10550 + EARLIER,
10551 + EARLIER_EQUAL,
10552 + EQUAL,
10553 + LATER_EQUAL,
10554 + LATER
10555 +};
10556 +typedef enum version_constraint version_constraint_t;
10557 +
10558 +struct depend{
10559 + version_constraint_t constraint;
10560 + char * version;
10561 + abstract_pkg_t * pkg;
10562 +};
10563 +typedef struct depend depend_t;
10564 +
10565 +struct compound_depend{
10566 + depend_type_t type;
10567 + int possibility_count;
10568 + struct depend ** possibilities;
10569 +};
10570 +typedef struct compound_depend compound_depend_t;
10571 +
10572 +#include "hash_table.h"
10573 +
10574 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10575 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10576 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10577 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10578 +
10579 +/**
10580 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10581 + * the same abstract package and 0 otherwise.
10582 + */
10583 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10584 +
10585 +/**
10586 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10587 + * otherwise.
10588 + */
10589 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10590 +
10591 +/**
10592 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10593 + * otherwise.
10594 + */
10595 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10596 +
10597 +/**
10598 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10599 + * otherwise.
10600 + */
10601 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10602 +
10603 +/**
10604 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10605 + * otherwise.
10606 + */
10607 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10608 +
10609 +char *pkg_depend_str(pkg_t *pkg, int index);
10610 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10611 +void freeDepends(pkg_t *pkg);
10612 +void printDepends(pkg_t * pkg);
10613 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10614 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10615 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10616 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10617 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10618 +
10619 +#endif
10620 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest.c
10621 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10622 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest.c 2005-12-07 21:25:30.000000000 +0100
10623 @@ -0,0 +1,92 @@
10624 +/* pkg_dest.c - the itsy package management system
10625 +
10626 + Carl D. Worth
10627 +
10628 + Copyright (C) 2001 University of Southern California
10629 +
10630 + This program is free software; you can redistribute it and/or
10631 + modify it under the terms of the GNU General Public License as
10632 + published by the Free Software Foundation; either version 2, or (at
10633 + your option) any later version.
10634 +
10635 + This program is distributed in the hope that it will be useful, but
10636 + WITHOUT ANY WARRANTY; without even the implied warranty of
10637 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10638 + General Public License for more details.
10639 +*/
10640 +
10641 +#include "ipkg.h"
10642 +
10643 +#include "pkg_dest.h"
10644 +#include "file_util.h"
10645 +#include "str_util.h"
10646 +#include "sprintf_alloc.h"
10647 +
10648 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10649 +{
10650 + dest->name = strdup(name);
10651 +
10652 + /* Guarantee that dest->root_dir ends with a '/' */
10653 + if (str_ends_with(root_dir, "/")) {
10654 + dest->root_dir = strdup(root_dir);
10655 + } else {
10656 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10657 + }
10658 + file_mkdir_hier(dest->root_dir, 0755);
10659 +
10660 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10661 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10662 + file_mkdir_hier(dest->ipkg_dir, 0755);
10663 +
10664 + if (str_starts_with (lists_dir, "/"))
10665 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10666 + else
10667 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10668 +
10669 + file_mkdir_hier(dest->lists_dir, 0755);
10670 +
10671 + sprintf_alloc(&dest->info_dir, "%s/%s",
10672 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10673 + file_mkdir_hier(dest->info_dir, 0755);
10674 +
10675 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10676 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10677 +
10678 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10679 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10680 +
10681 + dest->status_file = NULL;
10682 +
10683 + return 0;
10684 +}
10685 +
10686 +void pkg_dest_deinit(pkg_dest_t *dest)
10687 +{
10688 + free(dest->name);
10689 + dest->name = NULL;
10690 +
10691 + free(dest->root_dir);
10692 + dest->root_dir = NULL;
10693 +
10694 + free(dest->ipkg_dir);
10695 + dest->ipkg_dir = NULL;
10696 +
10697 + free(dest->lists_dir);
10698 + dest->lists_dir = NULL;
10699 +
10700 + free(dest->info_dir);
10701 + dest->info_dir = NULL;
10702 +
10703 + free(dest->status_file_name);
10704 + dest->status_file_name = NULL;
10705 +
10706 + free(dest->status_file_tmp_name);
10707 + dest->status_file_tmp_name = NULL;
10708 +
10709 + if (dest->status_file) {
10710 + fclose(dest->status_file);
10711 + }
10712 + dest->status_file = NULL;
10713 +
10714 + dest->root_dir = NULL;
10715 +}
10716 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest.h
10717 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10718 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest.h 2005-12-07 21:25:30.000000000 +0100
10719 @@ -0,0 +1,38 @@
10720 +/* pkg_dest.h - the itsy package management system
10721 +
10722 + Carl D. Worth
10723 +
10724 + Copyright (C) 2001 University of Southern California
10725 +
10726 + This program is free software; you can redistribute it and/or
10727 + modify it under the terms of the GNU General Public License as
10728 + published by the Free Software Foundation; either version 2, or (at
10729 + your option) any later version.
10730 +
10731 + This program is distributed in the hope that it will be useful, but
10732 + WITHOUT ANY WARRANTY; without even the implied warranty of
10733 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10734 + General Public License for more details.
10735 +*/
10736 +
10737 +#ifndef PKG_DEST_H
10738 +#define PKG_DEST_H
10739 +
10740 +typedef struct pkg_dest pkg_dest_t;
10741 +struct pkg_dest
10742 +{
10743 + char *name;
10744 + char *root_dir;
10745 + char *ipkg_dir;
10746 + char *lists_dir;
10747 + char *info_dir;
10748 + char *status_file_name;
10749 + char *status_file_tmp_name;
10750 + FILE *status_file;
10751 +};
10752 +
10753 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10754 +void pkg_dest_deinit(pkg_dest_t *dest);
10755 +
10756 +#endif
10757 +
10758 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest_list.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest_list.c
10759 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10760 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest_list.c 2005-12-07 21:25:30.000000000 +0100
10761 @@ -0,0 +1,85 @@
10762 +/* pkg_dest_list.c - the itsy package management system
10763 +
10764 + Carl D. Worth
10765 +
10766 + Copyright (C) 2001 University of Southern California
10767 +
10768 + This program is free software; you can redistribute it and/or
10769 + modify it under the terms of the GNU General Public License as
10770 + published by the Free Software Foundation; either version 2, or (at
10771 + your option) any later version.
10772 +
10773 + This program is distributed in the hope that it will be useful, but
10774 + WITHOUT ANY WARRANTY; without even the implied warranty of
10775 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10776 + General Public License for more details.
10777 +*/
10778 +
10779 +#include "ipkg.h"
10780 +
10781 +#include "pkg_dest.h"
10782 +#include "void_list.h"
10783 +#include "pkg_dest_list.h"
10784 +
10785 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10786 +{
10787 + return void_list_elt_init((void_list_elt_t *) elt, data);
10788 +}
10789 +
10790 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10791 +{
10792 + void_list_elt_deinit((void_list_elt_t *) elt);
10793 +}
10794 +
10795 +int pkg_dest_list_init(pkg_dest_list_t *list)
10796 +{
10797 + return void_list_init((void_list_t *) list);
10798 +}
10799 +
10800 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10801 +{
10802 + pkg_dest_list_elt_t *iter;
10803 + pkg_dest_t *pkg_dest;
10804 +
10805 + for (iter = list->head; iter; iter = iter->next) {
10806 + pkg_dest = iter->data;
10807 + pkg_dest_deinit(pkg_dest);
10808 +
10809 + /* malloced in pkg_dest_list_append */
10810 + free(pkg_dest);
10811 + iter->data = NULL;
10812 + }
10813 + void_list_deinit((void_list_t *) list);
10814 +}
10815 +
10816 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10817 + const char *root_dir,const char *lists_dir)
10818 +{
10819 + int err;
10820 + pkg_dest_t *pkg_dest;
10821 +
10822 + /* freed in plg_dest_list_deinit */
10823 + pkg_dest = malloc(sizeof(pkg_dest_t));
10824 + if (pkg_dest == NULL) {
10825 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10826 + return NULL;
10827 + }
10828 +
10829 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10830 + err = void_list_append((void_list_t *) list, pkg_dest);
10831 + if (err) {
10832 + return NULL;
10833 + }
10834 +
10835 + return pkg_dest;
10836 +}
10837 +
10838 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10839 +{
10840 + return void_list_push((void_list_t *) list, data);
10841 +}
10842 +
10843 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10844 +{
10845 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10846 +}
10847 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest_list.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest_list.h
10848 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10849 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_dest_list.h 2005-12-07 21:25:30.000000000 +0100
10850 @@ -0,0 +1,50 @@
10851 +/* pkg_dest_list.h - the itsy package management system
10852 +
10853 + Carl D. Worth
10854 +
10855 + Copyright (C) 2001 University of Southern California
10856 +
10857 + This program is free software; you can redistribute it and/or
10858 + modify it under the terms of the GNU General Public License as
10859 + published by the Free Software Foundation; either version 2, or (at
10860 + your option) any later version.
10861 +
10862 + This program is distributed in the hope that it will be useful, but
10863 + WITHOUT ANY WARRANTY; without even the implied warranty of
10864 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10865 + General Public License for more details.
10866 +*/
10867 +
10868 +#ifndef PKG_DEST_LIST_H
10869 +#define PKG_DEST_LIST_H
10870 +
10871 +#include "pkg_dest.h"
10872 +
10873 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10874 +struct pkg_dest_list_elt
10875 +{
10876 + pkg_dest_list_elt_t *next;
10877 + pkg_dest_t *data;
10878 +};
10879 +
10880 +typedef struct pkg_dest_list pkg_dest_list_t;
10881 +struct pkg_dest_list
10882 +{
10883 + pkg_dest_list_elt_t pre_head;
10884 + pkg_dest_list_elt_t *head;
10885 + pkg_dest_list_elt_t *tail;
10886 +};
10887 +
10888 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10889 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10890 +
10891 +int pkg_dest_list_init(pkg_dest_list_t *list);
10892 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10893 +
10894 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10895 + const char *root_dir,const char* lists_dir);
10896 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10897 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10898 +
10899 +#endif
10900 +
10901 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_extract.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_extract.c
10902 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10903 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_extract.c 2005-12-07 21:25:30.000000000 +0100
10904 @@ -0,0 +1,224 @@
10905 +/* pkg_extract.c - the itsy package management system
10906 +
10907 + Carl D. Worth
10908 +
10909 + Copyright (C) 2001 University of Southern California
10910 +
10911 + This program is free software; you can redistribute it and/or
10912 + modify it under the terms of the GNU General Public License as
10913 + published by the Free Software Foundation; either version 2, or (at
10914 + your option) any later version.
10915 +
10916 + This program is distributed in the hope that it will be useful, but
10917 + WITHOUT ANY WARRANTY; without even the implied warranty of
10918 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10919 + General Public License for more details.
10920 +*/
10921 +
10922 +#include "ipkg.h"
10923 +#include <errno.h>
10924 +#include <fcntl.h>
10925 +#include <stdio.h>
10926 +
10927 +#include "pkg_extract.h"
10928 +
10929 +#include "libbb.h"
10930 +#include "file_util.h"
10931 +#include "sprintf_alloc.h"
10932 +#include "unarchive.h"
10933 +
10934 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10935 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10936 +#define IPKG_CONTROL_FILE "control"
10937 +
10938 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10939 +{
10940 + archive_handle_t *archive;
10941 + char *path;
10942 +
10943 + sprintf_alloc(&path, "%s/", dir);
10944 + archive = init_handle();
10945 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10946 + archive->filter = filter_accept_list;
10947 + archive->accept = llist_add_to(NULL, (char *)filename);
10948 + archive->buffer = path;
10949 + archive->action_data = data_extract_all_prefix;
10950 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10951 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10952 + close(archive->src_fd);
10953 + free(archive->accept);
10954 + free(archive);
10955 + free(path);
10956 +}
10957 +
10958 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10959 +{
10960 + unsigned int size = strlen(archive->file_header->name) + 2;
10961 +
10962 + if (archive->buffer == NULL) {
10963 + archive->buffer = xmalloc(size);
10964 + strcpy(archive->buffer, archive->file_header->name);
10965 + } else {
10966 + size += strlen(archive->buffer);
10967 + archive->buffer = xrealloc(archive->buffer, size);
10968 + strcat(archive->buffer, archive->file_header->name);
10969 + }
10970 + strcat(archive->buffer, "\n");
10971 + data_skip(archive);
10972 +}
10973 +
10974 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10975 +{
10976 + archive_handle_t *archive;
10977 + char *name;
10978 +
10979 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10980 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10981 + archive = init_handle();
10982 + archive->src_fd = bb_xopen(name, O_RDONLY);
10983 + archive->filter = filter_accept_list;
10984 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10985 + archive->action_data = data_extract_to_buffer;
10986 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10987 + close(archive->src_fd);
10988 + fputs(archive->buffer, stream);
10989 + free(archive->buffer);
10990 + free(archive->accept);
10991 + free(archive);
10992 + free(name);
10993 +
10994 + return 0;
10995 +}
10996 +
10997 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10998 +{
10999 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11000 +}
11001 +
11002 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11003 +{
11004 + archive_handle_t *archive;
11005 + char *name;
11006 + char *path;
11007 +
11008 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11009 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11010 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11011 + archive = init_handle();
11012 + archive->src_fd = bb_xopen(name, O_RDONLY);
11013 + archive->filter = filter_accept_all;
11014 + archive->buffer = path;
11015 + archive->action_data = data_extract_all_prefix;
11016 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11017 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11018 + close(archive->src_fd);
11019 + free(archive);
11020 + free(path);
11021 + free(name);
11022 +
11023 + return 0;
11024 +}
11025 +
11026 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11027 +{
11028 + archive_handle_t *archive;
11029 + char *name;
11030 + char *path;
11031 +
11032 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11033 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11034 + sprintf_alloc(&path, "%s/", dir);
11035 + archive = init_handle();
11036 + archive->src_fd = bb_xopen(name, O_RDONLY);
11037 + archive->filter = filter_accept_all;
11038 + archive->buffer = path;
11039 + archive->action_data = data_extract_all_prefix;
11040 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11041 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11042 + close(archive->src_fd);
11043 + free(archive);
11044 + free(path);
11045 + free(name);
11046 +
11047 + return 0;
11048 +}
11049 +
11050 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11051 +{
11052 + int err=0;
11053 + char *line, *data_file;
11054 + FILE *file;
11055 + FILE *tmp;
11056 +
11057 + file = fopen(file_name, "w");
11058 + if (file == NULL) {
11059 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11060 + __FUNCTION__, file_name);
11061 + return EINVAL;
11062 + }
11063 +
11064 + tmp = tmpfile();
11065 + if (pkg->installed_files) {
11066 + str_list_elt_t *elt;
11067 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11068 + fprintf(file, "%s\n", elt->data);
11069 + }
11070 + } else {
11071 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11072 + if (err) {
11073 + fclose(file);
11074 + fclose(tmp);
11075 + return err;
11076 + }
11077 +
11078 + /* Fixup data file names by removing the initial '.' */
11079 + rewind(tmp);
11080 + while (1) {
11081 + line = file_read_line_alloc(tmp);
11082 + if (line == NULL) {
11083 + break;
11084 + }
11085 +
11086 + data_file = line;
11087 + if (*data_file == '.') {
11088 + data_file++;
11089 + }
11090 +
11091 + if (*data_file != '/') {
11092 + fputs("/", file);
11093 + }
11094 +
11095 + /* I have no idea why, but this is what dpkg does */
11096 + if (strcmp(data_file, "/\n") == 0) {
11097 + fputs("/.\n", file);
11098 + } else {
11099 + fputs(data_file, file);
11100 + }
11101 + }
11102 + }
11103 + fclose(tmp);
11104 + fclose(file);
11105 +
11106 + return err;
11107 +}
11108 +
11109 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11110 +{
11111 + archive_handle_t *archive;
11112 + char *name;
11113 +
11114 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11115 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11116 + archive = init_handle();
11117 + archive->src_fd = bb_xopen(name, O_RDONLY);
11118 + archive->filter = filter_accept_all;
11119 + archive->action_data = data_extract_file_name_to_buffer;
11120 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11121 + close(archive->src_fd);
11122 + fputs(archive->buffer, file);
11123 + free(archive->buffer);
11124 + free(archive);
11125 + free(name);
11126 +
11127 + return 0;
11128 +}
11129 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_extract.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_extract.h
11130 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11131 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_extract.h 2005-12-07 21:25:30.000000000 +0100
11132 @@ -0,0 +1,32 @@
11133 +/* pkg_extract.c - the itsy package management system
11134 +
11135 + Carl D. Worth
11136 +
11137 + Copyright (C) 2001 University of Southern California
11138 +
11139 + This program is free software; you can redistribute it and/or
11140 + modify it under the terms of the GNU General Public License as
11141 + published by the Free Software Foundation; either version 2, or (at
11142 + your option) any later version.
11143 +
11144 + This program is distributed in the hope that it will be useful, but
11145 + WITHOUT ANY WARRANTY; without even the implied warranty of
11146 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11147 + General Public License for more details.
11148 +*/
11149 +
11150 +#ifndef PKG_EXTRACT_H
11151 +#define PKG_EXTRACT_H
11152 +
11153 +#include "pkg.h"
11154 +
11155 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11156 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11157 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11158 + const char *dir,
11159 + const char *prefix);
11160 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11161 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11162 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11163 +
11164 +#endif
11165 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_hash.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_hash.c
11166 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11167 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_hash.c 2005-12-07 21:25:30.000000000 +0100
11168 @@ -0,0 +1,608 @@
11169 +/* ipkg_hash.c - the itsy package management system
11170 +
11171 + Steven M. Ayer
11172 +
11173 + Copyright (C) 2002 Compaq Computer Corporation
11174 +
11175 + This program is free software; you can redistribute it and/or
11176 + modify it under the terms of the GNU General Public License as
11177 + published by the Free Software Foundation; either version 2, or (at
11178 + your option) any later version.
11179 +
11180 + This program is distributed in the hope that it will be useful, but
11181 + WITHOUT ANY WARRANTY; without even the implied warranty of
11182 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11183 + General Public License for more details.
11184 +*/
11185 +
11186 +#include "ipkg.h"
11187 +#include <errno.h>
11188 +#include <ctype.h>
11189 +#include <stdlib.h>
11190 +#include <string.h>
11191 +
11192 +#include "hash_table.h"
11193 +#include "pkg.h"
11194 +#include "ipkg_message.h"
11195 +#include "pkg_vec.h"
11196 +#include "pkg_hash.h"
11197 +#include "pkg_parse.h"
11198 +#include "ipkg_utils.h"
11199 +
11200 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11201 +
11202 +/*
11203 + * this will talk to both feeds-lists files and installed status files
11204 + * example api:
11205 + *
11206 + * hash_table_t hash;
11207 + * pkg_hash_init(name, &hash, 1000);
11208 + * pkg_hash_add_from_file(<feed filename>);
11209 + *
11210 + * the query function is just there as a shell to prove to me that this
11211 + * sort of works, but isn't far from doing something useful
11212 + *
11213 + * -sma, 12/21/01
11214 + * modified: CDW 3 Jan. 2002
11215 + */
11216 +
11217 +
11218 +\f
11219 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11220 +{
11221 + return hash_table_init(name, hash, len);
11222 +}
11223 +
11224 +void pkg_hash_deinit(hash_table_t *hash)
11225 +{
11226 + hash_table_deinit(hash);
11227 +}
11228 +
11229 +
11230 +/* Find the default arch for a given package status file if none is given. */
11231 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11232 +{
11233 + nv_pair_list_elt_t *l;
11234 + char *def_arch = HOST_CPU_STR; /* Default arch */
11235 + int def_prio = 0; /* Other archs override this */
11236 +
11237 + l = conf->arch_list.head;
11238 +
11239 + while (l) {
11240 + nv_pair_t *nv = l->data;
11241 + int priority = strtol(nv->value, NULL, 0);
11242 +
11243 + /* Check if this arch has higher priority, and is valid */
11244 + if ((priority > def_prio) &&
11245 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11246 + /* Our new default */
11247 + def_prio = priority;
11248 + def_arch = nv->name;
11249 + }
11250 + l = l->next;
11251 + }
11252 +
11253 + return strdup(def_arch);
11254 +}
11255 +
11256 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11257 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11258 +{
11259 + hash_table_t *hash = &conf->pkg_hash;
11260 + char **raw;
11261 + char **raw_start;
11262 + pkg_t *pkg;
11263 +
11264 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11265 + if (!raw)
11266 + return -ENOMEM;
11267 +
11268 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11269 + pkg = pkg_new();
11270 + if (!pkg)
11271 + return -ENOMEM;
11272 +
11273 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11274 + if (!pkg->architecture) {
11275 + char *version_str = pkg_version_str_alloc(pkg);
11276 + pkg->architecture = pkg_get_default_arch(conf);
11277 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11278 + pkg->name, version_str, pkg->architecture);
11279 + free(version_str);
11280 + }
11281 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11282 + } else {
11283 + free(pkg);
11284 + }
11285 + }
11286 +
11287 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11288 + memory after read_raw_pkgs_from_file */
11289 + raw = raw_start;
11290 + while (*raw) {
11291 + free(*raw++);
11292 + }
11293 + free(raw_start);
11294 + return 0;
11295 +}
11296 +
11297 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11298 +{
11299 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11300 +}
11301 +
11302 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11303 +{
11304 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11305 + if (apkg)
11306 + return NULL;
11307 + return apkg->provided_by;
11308 +}
11309 +
11310 +
11311 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11312 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11313 +{
11314 + int i;
11315 + int nprovides = 0;
11316 + int nmatching = 0;
11317 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11318 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11319 + abstract_pkg_vec_t *provided_apkg_vec;
11320 + abstract_pkg_t **provided_apkgs;
11321 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11322 + pkg_t *latest_installed_parent = NULL;
11323 + pkg_t *latest_matching = NULL;
11324 + pkg_t *held_pkg = NULL;
11325 + pkg_t *good_pkg_by_name = NULL;
11326 +
11327 + if (matching_apkgs == NULL || providers == NULL ||
11328 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11329 + return NULL;
11330 +
11331 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11332 +
11333 + provided_apkg_vec = apkg->provided_by;
11334 + nprovides = provided_apkg_vec->len;
11335 + provided_apkgs = provided_apkg_vec->pkgs;
11336 + if (nprovides > 1)
11337 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11338 +
11339 + /* accumulate all the providers */
11340 + for (i = 0; i < nprovides; i++) {
11341 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11342 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11343 + abstract_pkg_vec_insert(providers, provider_apkg);
11344 + }
11345 + nprovides = providers->len;
11346 +
11347 + for (i = 0; i < nprovides; i++) {
11348 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11349 + abstract_pkg_t *replacement_apkg = NULL;
11350 + pkg_vec_t *vec;
11351 +
11352 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11353 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11354 + if (provider_apkg->replaced_by->len > 1) {
11355 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11356 + provider_apkg->name, replacement_apkg->name);
11357 + }
11358 + }
11359 +
11360 + if (replacement_apkg)
11361 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11362 + replacement_apkg->name, provider_apkg->name);
11363 +
11364 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11365 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11366 + continue;
11367 + else
11368 + provider_apkg = replacement_apkg;
11369 + }
11370 +
11371 + if (!(vec = provider_apkg->pkgs)) {
11372 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11373 + continue;
11374 + }
11375 +
11376 +
11377 + /* now check for supported architecture */
11378 + {
11379 + int max_count = 0;
11380 + int i;
11381 +
11382 + /* count packages matching max arch priority and keep track of last one */
11383 + for (i = 0; i < vec->len; i++) {
11384 + pkg_t *maybe = vec->pkgs[i];
11385 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d \n",
11386 + maybe->name, maybe->architecture, maybe->arch_priority);
11387 + if (maybe->arch_priority > 0) {
11388 + max_count++;
11389 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11390 + pkg_vec_insert(matching_pkgs, maybe);
11391 + }
11392 + }
11393 + }
11394 + }
11395 +
11396 + if (matching_pkgs->len > 1)
11397 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11398 + if (matching_apkgs->len > 1)
11399 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11400 +
11401 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11402 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11403 +
11404 + for (i = 0; i < matching_pkgs->len; i++) {
11405 + pkg_t *matching = matching_pkgs->pkgs[i];
11406 + if (constraint_fcn(matching, cdata)) { /* We found it */
11407 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s \n", matching->name) ;
11408 + good_pkg_by_name = matching;
11409 + }
11410 + }
11411 +
11412 +
11413 + for (i = 0; i < matching_pkgs->len; i++) {
11414 + pkg_t *matching = matching_pkgs->pkgs[i];
11415 + latest_matching = matching;
11416 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11417 + latest_installed_parent = matching;
11418 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11419 + if (held_pkg)
11420 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11421 + held_pkg->name, matching->name);
11422 + held_pkg = matching;
11423 + }
11424 + }
11425 +
11426 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11427 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11428 + apkg->name, matching_apkgs->len);
11429 + for (i = 0; i < matching_apkgs->len; i++) {
11430 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11431 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11432 + }
11433 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11434 + }
11435 +
11436 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11437 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11438 + __FUNCTION__, apkg->name, matching_pkgs->len);
11439 + for (i = 0; i < matching_pkgs->len; i++) {
11440 + pkg_t *matching = matching_pkgs->pkgs[i];
11441 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11442 + matching->name, matching->version, matching->architecture);
11443 + }
11444 + }
11445 +
11446 + nmatching = matching_apkgs->len;
11447 +
11448 + pkg_vec_free(matching_pkgs);
11449 + abstract_pkg_vec_free(matching_apkgs);
11450 + abstract_pkg_vec_free(providers);
11451 +
11452 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11453 + return good_pkg_by_name;
11454 + }
11455 + if (held_pkg) {
11456 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11457 + return held_pkg;
11458 + }
11459 + if (latest_installed_parent) {
11460 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11461 + return latest_installed_parent;
11462 + }
11463 + if (nmatching > 1) {
11464 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11465 + return NULL;
11466 + }
11467 + if (latest_matching) {
11468 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11469 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11470 + return latest_matching;
11471 + }
11472 + return NULL;
11473 +}
11474 +
11475 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11476 +{
11477 + const char *name = (const char *)cdata;
11478 + if (strcmp(pkg->name, name) == 0)
11479 + return 1;
11480 + else
11481 + return 0; /* Pigi */
11482 +}
11483 +
11484 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11485 +{
11486 + hash_table_t *hash = &conf->pkg_hash;
11487 + abstract_pkg_t *apkg = NULL;
11488 +
11489 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11490 + return NULL;
11491 +
11492 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11493 +}
11494 +
11495 +
11496 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11497 + const char *pkg_name,
11498 + const char * version)
11499 +{
11500 + pkg_vec_t * vec;
11501 + register int i;
11502 + char *version_str = NULL;
11503 +
11504 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11505 + return NULL;
11506 +
11507 + for(i = 0; i < vec->len; i++) {
11508 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11509 + if(!strcmp(version_str, version)) {
11510 + free(version_str);
11511 + break;
11512 + }
11513 + free(version_str);
11514 + }
11515 +
11516 + if(i == vec->len)
11517 + return NULL;
11518 +
11519 + return vec->pkgs[i];
11520 +}
11521 +
11522 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11523 + const char *pkg_name,
11524 + pkg_dest_t *dest)
11525 +{
11526 + pkg_vec_t * vec;
11527 + register int i;
11528 +
11529 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11530 + return NULL;
11531 + }
11532 +
11533 + for(i = 0; i < vec->len; i++)
11534 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11535 + return vec->pkgs[i];
11536 + }
11537 + return NULL;
11538 +}
11539 +
11540 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11541 + const char *pkg_name)
11542 +{
11543 + pkg_vec_t * vec;
11544 + register int i;
11545 +
11546 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11547 + return NULL;
11548 + }
11549 +
11550 + for(i = 0; i < vec->len; i++)
11551 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11552 + return vec->pkgs[i];
11553 + }
11554 +
11555 + return NULL;
11556 +}
11557 +
11558 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11559 +{
11560 + abstract_pkg_t * ab_pkg;
11561 +
11562 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11563 + return NULL;
11564 + }
11565 +
11566 + if (ab_pkg->pkgs) {
11567 + return ab_pkg->pkgs;
11568 + } else if (ab_pkg->provided_by) {
11569 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11570 + if (abpkg != NULL){
11571 + return abpkg->pkgs;
11572 + } else {
11573 + return ab_pkg->pkgs;
11574 + }
11575 + } else {
11576 + return NULL;
11577 + }
11578 +}
11579 +
11580 +static int pkg_compare_names(const void *p1, const void *p2)
11581 +{
11582 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11583 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11584 + if (pkg1->name == NULL)
11585 + return 1;
11586 + if (pkg2->name == NULL)
11587 + return -1;
11588 + return(strcmp(pkg1->name, pkg2->name));
11589 +}
11590 +
11591 +
11592 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11593 +{
11594 + int j;
11595 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11596 + pkg_vec_t *all = (pkg_vec_t *)data;
11597 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11598 + if (pkg_vec) {
11599 + for (j = 0; j < pkg_vec->len; j++) {
11600 + pkg_t *pkg = pkg_vec->pkgs[j];
11601 + pkg_vec_insert(all, pkg);
11602 + }
11603 + }
11604 +}
11605 +
11606 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11607 +{
11608 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11609 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11610 +}
11611 +
11612 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11613 +{
11614 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11615 + pkg_vec_t *all = (pkg_vec_t *)data;
11616 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11617 + int j;
11618 + if (pkg_vec) {
11619 + for (j = 0; j < pkg_vec->len; j++) {
11620 + pkg_t *pkg = pkg_vec->pkgs[j];
11621 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11622 + pkg_vec_insert(all, pkg);
11623 + }
11624 + }
11625 + }
11626 +}
11627 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11628 +{
11629 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11630 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11631 +}
11632 +
11633 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11634 +{
11635 + int i;
11636 + pkg_t *pkg;
11637 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11638 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11639 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11640 + fprintf(stdout, "%s\n", ab_pkg->name);
11641 + i = 0;
11642 + if (dependents != NULL)
11643 + while (dependents [i] != NULL)
11644 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11645 + dependents = ab_pkg->provided_by->pkgs;
11646 + i = 0;
11647 + if (dependents != NULL)
11648 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11649 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11650 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11651 + if (pkg) {
11652 + i = 0;
11653 + while (i < pkg->depends_count)
11654 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11655 + }
11656 +}
11657 +void pkg_hash_dump(hash_table_t *hash, void *data)
11658 +{
11659 +
11660 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11661 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11662 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11663 +}
11664 +
11665 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11666 +{
11667 + abstract_pkg_t * ab_pkg;
11668 +
11669 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11670 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11671 +
11672 + return ab_pkg;
11673 +}
11674 +
11675 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11676 +{
11677 + abstract_pkg_t * ab_pkg;
11678 + int arch_priority;
11679 +
11680 + if(!pkg)
11681 + return pkg;
11682 +
11683 + arch_priority = pkg->arch_priority;
11684 +
11685 + if (buildDepends(hash, pkg)<0){
11686 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11687 + return NULL;
11688 + }
11689 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11690 +
11691 + if (set_status) {
11692 + if (pkg->state_status == SS_INSTALLED) {
11693 + ab_pkg->state_status = SS_INSTALLED;
11694 + } else if (pkg->state_status == SS_UNPACKED) {
11695 + ab_pkg->state_status = SS_UNPACKED;
11696 + }
11697 + }
11698 +
11699 + if(!ab_pkg->pkgs)
11700 + ab_pkg->pkgs = pkg_vec_alloc();
11701 +
11702 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11703 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11704 + pkg->parent = ab_pkg;
11705 +
11706 + if (buildProvides(hash, ab_pkg, pkg)<0){
11707 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11708 + return NULL;
11709 + }
11710 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11711 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11712 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11713 + return NULL;
11714 + }
11715 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11716 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11717 + return NULL;
11718 + }
11719 +
11720 + buildDependedUponBy(pkg, ab_pkg);
11721 + return pkg;
11722 +}
11723 +
11724 +/*
11725 + * this will assume that we've already determined that
11726 + * the abstract pkg doesn't exist, 'cause we should know these things...
11727 + */
11728 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11729 +{
11730 + abstract_pkg_t * ab_pkg;
11731 +
11732 + ab_pkg = abstract_pkg_new();
11733 + if (ab_pkg == NULL) { return NULL; }
11734 +
11735 + ab_pkg->name = strdup(pkg_name);
11736 + hash_table_insert(hash, pkg_name, ab_pkg);
11737 +
11738 + return ab_pkg;
11739 +}
11740 +
11741 +
11742 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11743 +{
11744 + hash_table_t *file_hash = &conf->file_hash;
11745 +
11746 + return hash_table_get(file_hash, file_name);
11747 +}
11748 +
11749 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11750 +{
11751 + hash_table_t *file_hash = &conf->file_hash;
11752 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11753 + int file_name_len = strlen(file_name);
11754 +
11755 + if (file_name[file_name_len -1] == '/')
11756 + return 0;
11757 +
11758 + if (conf->offline_root) {
11759 + int len = strlen(conf->offline_root);
11760 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11761 + file_name += len;
11762 + }
11763 + }
11764 +
11765 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11766 + hash_table_insert(file_hash, file_name, owning_pkg);
11767 + if (old_owning_pkg) {
11768 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11769 + /* mark this package to have its filelist written */
11770 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11771 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11772 + }
11773 + return 0;
11774 +}
11775 +
11776 +
11777 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_hash.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_hash.h
11778 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11779 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_hash.h 2005-12-07 21:25:30.000000000 +0100
11780 @@ -0,0 +1,61 @@
11781 +/* pkg_hash.h - the itsy package management system
11782 +
11783 + Steven M. Ayer
11784 +
11785 + Copyright (C) 2002 Compaq Computer Corporation
11786 +
11787 + This program is free software; you can redistribute it and/or
11788 + modify it under the terms of the GNU General Public License as
11789 + published by the Free Software Foundation; either version 2, or (at
11790 + your option) any later version.
11791 +
11792 + This program is distributed in the hope that it will be useful, but
11793 + WITHOUT ANY WARRANTY; without even the implied warranty of
11794 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11795 + General Public License for more details.
11796 +*/
11797 +
11798 +#ifndef PKG_HASH_H
11799 +#define PKG_HASH_H
11800 +
11801 +#include "pkg.h"
11802 +#include "pkg_vec.h"
11803 +#include "hash_table.h"
11804 +
11805 +
11806 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11807 +void pkg_hash_deinit(hash_table_t *hash);
11808 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11809 +
11810 +void pkg_hash_dump(hash_table_t *hash, void *data);
11811 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11812 +
11813 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11814 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11815 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11816 +
11817 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11818 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11819 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11820 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11821 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11822 + const char *pkg_name,
11823 + const char * version);
11824 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11825 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11826 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11827 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11828 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11829 + const char *pkg_name);
11830 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11831 + const char *pkg_name,
11832 + pkg_dest_t *dest);
11833 +
11834 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11835 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11836 +
11837 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11838 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11839 +
11840 +#endif
11841 +
11842 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_parse.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_parse.c
11843 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
11844 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_parse.c 2005-12-07 21:25:30.000000000 +0100
11845 @@ -0,0 +1,366 @@
11846 +/* pkg_parse.c - the itsy package management system
11847 +
11848 + Steven M. Ayer
11849 +
11850 + Copyright (C) 2002 Compaq Computer Corporation
11851 +
11852 + This program is free software; you can redistribute it and/or
11853 + modify it under the terms of the GNU General Public License as
11854 + published by the Free Software Foundation; either version 2, or (at
11855 + your option) any later version.
11856 +
11857 + This program is distributed in the hope that it will be useful, but
11858 + WITHOUT ANY WARRANTY; without even the implied warranty of
11859 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11860 + General Public License for more details.
11861 +*/
11862 +
11863 +#include "ipkg.h"
11864 +#include <errno.h>
11865 +#include <ctype.h>
11866 +
11867 +#include "pkg.h"
11868 +#include "ipkg_utils.h"
11869 +#include "pkg_parse.h"
11870 +
11871 +int isGenericFieldType(char * type, char * line)
11872 +{
11873 + if(!strncmp(line, type, strlen(type)))
11874 + return 1;
11875 + return 0;
11876 +}
11877 +
11878 +char * parseGenericFieldType(char * type, char * raw)
11879 +{
11880 + char * field_value = raw + (strlen(type) + 1);
11881 + return trim_alloc(field_value);
11882 +}
11883 +
11884 +void parseStatus(pkg_t *pkg, char * raw)
11885 +{
11886 + char sw_str[64], sf_str[64], ss_str[64];
11887 +
11888 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11889 + pkg->state_want = pkg_state_want_from_str(sw_str);
11890 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11891 + pkg->state_status = pkg_state_status_from_str(ss_str);
11892 +}
11893 +
11894 +char ** parseDependsString(char * raw, int * depends_count)
11895 +{
11896 + char ** depends = NULL;
11897 + int line_count = 0;
11898 + char buff[2048], * dest;
11899 +
11900 + while(raw && *raw && !isspace(*raw)) {
11901 + raw++;
11902 + }
11903 +
11904 + if(line_is_blank(raw)){
11905 + *depends_count = line_count;
11906 + return NULL;
11907 + }
11908 + while(raw && *raw){
11909 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11910 +
11911 + while(isspace(*raw)) raw++;
11912 +
11913 + dest = buff;
11914 + while((*raw != ',') && *raw)
11915 + *dest++ = *raw++;
11916 +
11917 + *dest = '\0';
11918 + depends[line_count] = trim_alloc(buff);
11919 + if(depends[line_count] ==NULL)
11920 + return NULL;
11921 + line_count++;
11922 + if(*raw == ',')
11923 + raw++;
11924 + }
11925 + *depends_count = line_count;
11926 + return depends;
11927 +}
11928 +
11929 +void parseConffiles(pkg_t * pkg, char * raw)
11930 +{
11931 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11932 +
11933 + if(!strncmp(raw, "Conffiles:", 10))
11934 + raw += strlen("Conffiles:");
11935 +
11936 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11937 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11938 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11939 + while (*raw && isspace(*raw)) {
11940 + raw++;
11941 + }
11942 + raw += strlen(file_name);
11943 + while (*raw && isspace(*raw)) {
11944 + raw++;
11945 + }
11946 + raw += strlen(md5sum);
11947 + }
11948 +}
11949 +
11950 +int parseVersion(pkg_t *pkg, char *raw)
11951 +{
11952 + char *colon, *eepochcolon;
11953 +#ifdef USE_DEBVERSION
11954 + char *hyphen;
11955 +#endif
11956 + unsigned long epoch;
11957 +
11958 + if (!*raw) {
11959 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11960 + return EINVAL;
11961 + }
11962 +
11963 + if (strncmp(raw, "Version:", 8) == 0) {
11964 + raw += 8;
11965 + }
11966 + while (*raw && isspace(*raw)) {
11967 + raw++;
11968 + }
11969 +
11970 + colon= strchr(raw,':');
11971 + if (colon) {
11972 + epoch= strtoul(raw,&eepochcolon,10);
11973 + if (colon != eepochcolon) {
11974 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11975 + return EINVAL;
11976 + }
11977 + if (!*++colon) {
11978 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11979 + return EINVAL;
11980 + }
11981 + raw= colon;
11982 + pkg->epoch= epoch;
11983 + } else {
11984 + pkg->epoch= 0;
11985 + }
11986 +
11987 + pkg->revision = "";
11988 + pkg->familiar_revision = "";
11989 +
11990 + pkg->version= malloc(strlen(raw)+1);
11991 + if ( pkg->version == NULL ) {
11992 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11993 + return ENOMEM;
11994 + }
11995 + strcpy(pkg->version, raw);
11996 +
11997 +#ifdef USE_DEBVERSION
11998 + hyphen= strrchr(pkg->version,'-');
11999 +
12000 + if (hyphen) {
12001 + *hyphen++= 0;
12002 + if (strncmp("fam", hyphen, 3) == 0) {
12003 + pkg->familiar_revision=hyphen+3;
12004 + hyphen= strrchr(pkg->version,'-');
12005 + if (hyphen) {
12006 + *hyphen++= 0;
12007 + pkg->revision = hyphen;
12008 + }
12009 + } else {
12010 + pkg->revision = hyphen;
12011 + }
12012 + }
12013 +#endif
12014 +
12015 +/*
12016 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12017 + pkg->epoch,
12018 + pkg->version,
12019 + pkg->revision,
12020 + pkg->familiar_revision);
12021 +*/
12022 +
12023 + return 0;
12024 +}
12025 +
12026 +
12027 +/* This code is needed to insert in first position the keyword for the aligning bug */
12028 +
12029 +int alterProvidesLine(char *raw, char *temp)
12030 +{
12031 +
12032 +
12033 + if (!*raw) {
12034 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12035 + return -EINVAL;
12036 + }
12037 +
12038 + if ( temp == NULL ) {
12039 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12040 + return -ENOMEM;
12041 + }
12042 +
12043 + if (strncmp(raw, "Provides:", 9) == 0) {
12044 + raw += 9;
12045 + }
12046 + while (*raw && isspace(*raw)) {
12047 + raw++;
12048 + }
12049 +
12050 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12051 + while (*raw) {
12052 + strncat( temp, raw++, 1);
12053 + }
12054 + return 0;
12055 +
12056 +}
12057 +
12058 +/* Some random thoughts from Carl:
12059 +
12060 + This function could be considerably simplified if we just kept
12061 + an array of all the generic string-valued field names, and looped
12062 + through those looking for a match. Also, these fields could perhaps
12063 + be stored in the package as an array as well, (or, probably better,
12064 + as an nv_pair_list_t).
12065 +
12066 + Fields which require special parsing or storage, (such as Depends:
12067 + and Status:) could be handled as they are now.
12068 +*/
12069 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12070 + to a dependency list. And, since we already have
12071 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12072 + Enhances, perhaps we could generalize all of these and save some
12073 + code duplication.
12074 +*/
12075 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12076 +{
12077 + int reading_conffiles, reading_description;
12078 + int pkg_false_provides=1;
12079 + char ** lines;
12080 + char * provide=NULL;
12081 +
12082 + pkg->src = src;
12083 + pkg->dest = dest;
12084 +
12085 + reading_conffiles = reading_description = 0;
12086 +
12087 + for (lines = *raw; *lines; lines++) {
12088 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12089 + if(isGenericFieldType("Package:", *lines))
12090 + pkg->name = parseGenericFieldType("Package", *lines);
12091 + else if(isGenericFieldType("Architecture:", *lines))
12092 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12093 + else if(isGenericFieldType("Filename:", *lines))
12094 + pkg->filename = parseGenericFieldType("Filename", *lines);
12095 + else if(isGenericFieldType("Section:", *lines))
12096 + pkg->section = parseGenericFieldType("Section", *lines);
12097 + else if(isGenericFieldType("MD5sum:", *lines))
12098 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12099 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12100 + let's parse it either way */
12101 + else if(isGenericFieldType("MD5Sum:", *lines))
12102 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12103 + else if(isGenericFieldType("Size:", *lines))
12104 + pkg->size = parseGenericFieldType("Size", *lines);
12105 + else if(isGenericFieldType("Source:", *lines))
12106 + pkg->source = parseGenericFieldType("Source", *lines);
12107 + else if(isGenericFieldType("Installed-Size:", *lines))
12108 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12109 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12110 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12111 + pkg->installed_time = strtoul(time_str, NULL, 0);
12112 + } else if(isGenericFieldType("Priority:", *lines))
12113 + pkg->priority = parseGenericFieldType("Priority", *lines);
12114 + else if(isGenericFieldType("Essential:", *lines)) {
12115 + char *essential_value;
12116 + essential_value = parseGenericFieldType("Essential", *lines);
12117 + if (strcmp(essential_value, "yes") == 0) {
12118 + pkg->essential = 1;
12119 + }
12120 + free(essential_value);
12121 + }
12122 + else if(isGenericFieldType("Status", *lines))
12123 + parseStatus(pkg, *lines);
12124 + else if(isGenericFieldType("Version", *lines))
12125 + parseVersion(pkg, *lines);
12126 + else if(isGenericFieldType("Maintainer", *lines))
12127 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12128 + else if(isGenericFieldType("Conffiles", *lines)){
12129 + parseConffiles(pkg, *lines);
12130 + reading_conffiles = 1;
12131 + }
12132 + else if(isGenericFieldType("Description", *lines)) {
12133 + pkg->description = parseGenericFieldType("Description", *lines);
12134 + reading_conffiles = 0;
12135 + reading_description = 1;
12136 + }
12137 +
12138 + else if(isGenericFieldType("Provides", *lines)){
12139 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12140 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12141 + if ( alterProvidesLine(*lines,provide) ){
12142 + return EINVAL;
12143 + }
12144 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12145 +/* Let's try to hack a bit here.
12146 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12147 + in alot of other places. We will remove it before writing down the status database */
12148 + pkg_false_provides=0;
12149 + free(provide);
12150 + }
12151 +
12152 + else if(isGenericFieldType("Depends", *lines))
12153 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12154 + else if(isGenericFieldType("Pre-Depends", *lines))
12155 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12156 + else if(isGenericFieldType("Recommends", *lines))
12157 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12158 + else if(isGenericFieldType("Suggests", *lines))
12159 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12160 + /* Abhaya: support for conflicts */
12161 + else if(isGenericFieldType("Conflicts", *lines))
12162 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12163 + else if(isGenericFieldType("Replaces", *lines))
12164 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12165 + else if(line_is_blank(*lines)) {
12166 + lines++;
12167 + break;
12168 + }
12169 + else if(**lines == ' '){
12170 + if(reading_description) {
12171 + /* we already know it's not blank, so the rest of description */
12172 + pkg->description = realloc(pkg->description,
12173 + strlen(pkg->description)
12174 + + 1 + strlen(*lines) + 1);
12175 + strcat(pkg->description, "\n");
12176 + strcat(pkg->description, (*lines));
12177 + }
12178 + else if(reading_conffiles)
12179 + parseConffiles(pkg, *lines);
12180 + }
12181 + }
12182 + *raw = lines;
12183 +/* If the ipk has not a Provides line, we insert our false line */
12184 + if ( pkg_false_provides==1)
12185 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12186 +
12187 + if (pkg->name) {
12188 + return 0;
12189 + } else {
12190 + return EINVAL;
12191 + }
12192 +}
12193 +
12194 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12195 +{
12196 + char ** lines;
12197 +
12198 + for (lines = *raw; *lines; lines++) {
12199 + if(isGenericFieldType("Essential:", *lines)) {
12200 + char *essential_value;
12201 + essential_value = parseGenericFieldType("Essential", *lines);
12202 + if (strcmp(essential_value, "yes") == 0) {
12203 + pkg->essential = 1;
12204 + }
12205 + free(essential_value);
12206 + }
12207 + }
12208 + *raw = lines;
12209 +
12210 + return 0;
12211 +}
12212 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_parse.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_parse.h
12213 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12214 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_parse.h 2005-12-07 21:25:30.000000000 +0100
12215 @@ -0,0 +1,31 @@
12216 +/* pkg_parse.h - the itsy package management system
12217 +
12218 + Steven M. Ayer
12219 +
12220 + Copyright (C) 2002 Compaq Computer Corporation
12221 +
12222 + This program is free software; you can redistribute it and/or
12223 + modify it under the terms of the GNU General Public License as
12224 + published by the Free Software Foundation; either version 2, or (at
12225 + your option) any later version.
12226 +
12227 + This program is distributed in the hope that it will be useful, but
12228 + WITHOUT ANY WARRANTY; without even the implied warranty of
12229 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12230 + General Public License for more details.
12231 +*/
12232 +
12233 +#ifndef PKG_PARSE_H
12234 +#define PKG_PARSE_H
12235 +
12236 +int isGenericFieldType(char * type, char * line);
12237 +char * parseGenericFieldType(char * type, char * raw);
12238 +void parseStatus(pkg_t *pkg, char * raw);
12239 +int parseVersion(pkg_t *pkg, char *raw);
12240 +char ** parseDependsString(char * raw, int * depends_count);
12241 +int parseVersion(pkg_t *pkg, char *raw);
12242 +void parseConffiles(pkg_t * pkg, char * raw);
12243 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12244 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12245 +
12246 +#endif
12247 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_src.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_src.c
12248 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12249 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_src.c 2005-12-07 21:25:30.000000000 +0100
12250 @@ -0,0 +1,43 @@
12251 +/* pkg_src.c - the itsy package management system
12252 +
12253 + Carl D. Worth
12254 +
12255 + Copyright (C) 2001 University of Southern California
12256 +
12257 + This program is free software; you can redistribute it and/or
12258 + modify it under the terms of the GNU General Public License as
12259 + published by the Free Software Foundation; either version 2, or (at
12260 + your option) any later version.
12261 +
12262 + This program is distributed in the hope that it will be useful, but
12263 + WITHOUT ANY WARRANTY; without even the implied warranty of
12264 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12265 + General Public License for more details.
12266 +*/
12267 +
12268 +#include "ipkg.h"
12269 +
12270 +#include "pkg_src.h"
12271 +#include "str_util.h"
12272 +
12273 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12274 +{
12275 + src->gzip = gzip;
12276 + src->name = str_dup_safe (name);
12277 + src->value = str_dup_safe (base_url);
12278 + if (extra_data)
12279 + src->extra_data = str_dup_safe (extra_data);
12280 + else
12281 + src->extra_data = NULL;
12282 + return 0;
12283 +}
12284 +
12285 +void pkg_src_deinit(pkg_src_t *src)
12286 +{
12287 + free (src->name);
12288 + free (src->value);
12289 + if (src->extra_data)
12290 + free (src->extra_data);
12291 +}
12292 +
12293 +
12294 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_src.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_src.h
12295 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12296 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_src.h 2005-12-07 21:25:30.000000000 +0100
12297 @@ -0,0 +1,34 @@
12298 +/* pkg_src.h - the itsy package management system
12299 +
12300 + Carl D. Worth
12301 +
12302 + Copyright (C) 2001 University of Southern California
12303 +
12304 + This program is free software; you can redistribute it and/or
12305 + modify it under the terms of the GNU General Public License as
12306 + published by the Free Software Foundation; either version 2, or (at
12307 + your option) any later version.
12308 +
12309 + This program is distributed in the hope that it will be useful, but
12310 + WITHOUT ANY WARRANTY; without even the implied warranty of
12311 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12312 + General Public License for more details.
12313 +*/
12314 +
12315 +#ifndef PKG_SRC_H
12316 +#define PKG_SRC_H
12317 +
12318 +#include "nv_pair.h"
12319 +
12320 +typedef struct
12321 +{
12322 + char *name;
12323 + char *value;
12324 + char *extra_data;
12325 + int gzip;
12326 +} pkg_src_t;
12327 +
12328 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12329 +void pkg_src_deinit(pkg_src_t *src);
12330 +
12331 +#endif
12332 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_src_list.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_src_list.c
12333 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12334 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_src_list.c 2005-12-07 21:25:30.000000000 +0100
12335 @@ -0,0 +1,75 @@
12336 +/* pkg_src_list.c - the itsy package management system
12337 +
12338 + Carl D. Worth
12339 +
12340 + Copyright (C) 2001 University of Southern California
12341 +
12342 + This program is free software; you can redistribute it and/or
12343 + modify it under the terms of the GNU General Public License as
12344 + published by the Free Software Foundation; either version 2, or (at
12345 + your option) any later version.
12346 +
12347 + This program is distributed in the hope that it will be useful, but
12348 + WITHOUT ANY WARRANTY; without even the implied warranty of
12349 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12350 + General Public License for more details.
12351 +*/
12352 +
12353 +#include "ipkg.h"
12354 +
12355 +#include "pkg_src_list.h"
12356 +#include "void_list.h"
12357 +
12358 +int pkg_src_list_init(pkg_src_list_t *list)
12359 +{
12360 + return void_list_init((void_list_t *) list);
12361 +}
12362 +
12363 +void pkg_src_list_deinit(pkg_src_list_t *list)
12364 +{
12365 + pkg_src_list_elt_t *iter;
12366 + pkg_src_t *pkg_src;
12367 +
12368 + for (iter = list->head; iter; iter = iter->next) {
12369 + pkg_src = iter->data;
12370 + pkg_src_deinit(pkg_src);
12371 +
12372 + /* malloced in pkg_src_list_append */
12373 + free(pkg_src);
12374 + iter->data = NULL;
12375 + }
12376 + void_list_deinit((void_list_t *) list);
12377 +}
12378 +
12379 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12380 + const char *name, const char *base_url, const char *extra_data,
12381 + int gzip)
12382 +{
12383 + int err;
12384 +
12385 + /* freed in pkg_src_list_deinit */
12386 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12387 +
12388 + if (pkg_src == NULL) {
12389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12390 + return NULL;
12391 + }
12392 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12393 +
12394 + err = void_list_append((void_list_t *) list, pkg_src);
12395 + if (err) {
12396 + return NULL;
12397 + }
12398 +
12399 + return pkg_src;
12400 +}
12401 +
12402 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12403 +{
12404 + return void_list_push((void_list_t *) list, data);
12405 +}
12406 +
12407 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12408 +{
12409 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12410 +}
12411 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_src_list.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_src_list.h
12412 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12413 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_src_list.h 2005-12-07 21:25:30.000000000 +0100
12414 @@ -0,0 +1,57 @@
12415 +/* pkg_src_list.h - the itsy package management system
12416 +
12417 + Carl D. Worth
12418 +
12419 + Copyright (C) 2001 University of Southern California
12420 +
12421 + This program is free software; you can redistribute it and/or
12422 + modify it under the terms of the GNU General Public License as
12423 + published by the Free Software Foundation; either version 2, or (at
12424 + your option) any later version.
12425 +
12426 + This program is distributed in the hope that it will be useful, but
12427 + WITHOUT ANY WARRANTY; without even the implied warranty of
12428 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12429 + General Public License for more details.
12430 +*/
12431 +
12432 +#ifndef PKG_SRC_LIST_H
12433 +#define PKG_SRC_LIST_H
12434 +
12435 +#include "pkg_src.h"
12436 +
12437 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12438 +struct pkg_src_list_elt
12439 +{
12440 + pkg_src_list_elt_t *next;
12441 + pkg_src_t *data;
12442 +};
12443 +
12444 +typedef struct pkg_src_list pkg_src_list_t;
12445 +struct pkg_src_list
12446 +{
12447 + pkg_src_list_elt_t pre_head;
12448 + pkg_src_list_elt_t *head;
12449 + pkg_src_list_elt_t *tail;
12450 +};
12451 +
12452 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12453 +{
12454 + if (list->head == NULL)
12455 + return 1;
12456 + else
12457 + return 0;
12458 +}
12459 +
12460 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12461 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12462 +
12463 +int pkg_src_list_init(pkg_src_list_t *list);
12464 +void pkg_src_list_deinit(pkg_src_list_t *list);
12465 +
12466 +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);
12467 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12468 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12469 +
12470 +#endif
12471 +
12472 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_vec.c busybox-1.1.0-pre1-new/archival/libipkg/pkg_vec.c
12473 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12474 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_vec.c 2005-12-07 21:25:30.000000000 +0100
12475 @@ -0,0 +1,226 @@
12476 +/* pkg_vec.c - the itsy package management system
12477 +
12478 + Steven M. Ayer
12479 +
12480 + Copyright (C) 2002 Compaq Computer Corporation
12481 +
12482 + This program is free software; you can redistribute it and/or
12483 + modify it under the terms of the GNU General Public License as
12484 + published by the Free Software Foundation; either version 2, or (at
12485 + your option) any later version.
12486 +
12487 + This program is distributed in the hope that it will be useful, but
12488 + WITHOUT ANY WARRANTY; without even the implied warranty of
12489 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12490 + General Public License for more details.
12491 +*/
12492 +
12493 +#include <stdlib.h>
12494 +#include <fnmatch.h>
12495 +#include "xregex.h"
12496 +#include "ipkg.h"
12497 +#include "pkg.h"
12498 +
12499 +pkg_vec_t * pkg_vec_alloc(void)
12500 +{
12501 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12502 + if (!vec) {
12503 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12504 + return NULL;
12505 + }
12506 + vec->pkgs = NULL;
12507 + vec->len = 0;
12508 +
12509 + return vec;
12510 +}
12511 +
12512 +void pkg_vec_free(pkg_vec_t *vec)
12513 +{
12514 + free(vec->pkgs);
12515 + free(vec);
12516 +}
12517 +
12518 +/*
12519 + * assumption: all names in a vector are identical
12520 + * assumption: all version strings are trimmed,
12521 + * so identical versions have identical version strings,
12522 + * implying identical packages; let's marry these
12523 + */
12524 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12525 +{
12526 + int i;
12527 + int found = 0;
12528 +
12529 + /* look for a duplicate pkg by name, version, and architecture */
12530 + for (i = 0; i < vec->len; i++)
12531 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12532 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12533 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12534 + found = 1;
12535 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12536 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12537 + break;
12538 + }
12539 +
12540 + /* we didn't find one, add it */
12541 + if (!found){
12542 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12543 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12544 +
12545 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12546 + vec->pkgs[vec->len] = pkg;
12547 + vec->len++;
12548 + return pkg;
12549 + }
12550 + /* update the one that we have */
12551 + else {
12552 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12553 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12554 + if (set_status) {
12555 + /* this is from the status file, so need to merge with existing database */
12556 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12557 + pkg_merge(vec->pkgs[i], pkg, set_status);
12558 + /* XXX: CLEANUP: It's not so polite to free something here
12559 + that was passed in from above. */
12560 + pkg_deinit(pkg);
12561 + free(pkg);
12562 + } else {
12563 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12564 + /* just overwrite the old one */
12565 + pkg_deinit(vec->pkgs[i]);
12566 + free(vec->pkgs[i]);
12567 + vec->pkgs[i] = pkg;
12568 + }
12569 + return vec->pkgs[i];
12570 + }
12571 +}
12572 +
12573 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12574 +{
12575 + int i;
12576 + int found = 0;
12577 +
12578 + /* look for a duplicate pkg by name, version, and architecture */
12579 + for (i = 0; i < vec->len; i++)
12580 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12581 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12582 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12583 + found = 1;
12584 + break;
12585 + }
12586 +
12587 + /* we didn't find one, add it */
12588 + if(!found){
12589 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12590 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12591 + vec->len++;
12592 + }
12593 +}
12594 +
12595 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12596 +{
12597 + int i;
12598 + for (i = 0; i < vec->len; i++)
12599 + if (vec->pkgs[i] == apkg)
12600 + return 1;
12601 + return 0;
12602 +}
12603 +
12604 +typedef int (*compare_fcn_t)(const void *, const void *);
12605 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12606 +{
12607 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12608 +}
12609 +
12610 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12611 +{
12612 + int npkgs = vec->len;
12613 + int i;
12614 + for (i = 0; i < npkgs; i++) {
12615 + pkg_t *pkg = vec->pkgs[i];
12616 + pkg->state_flag &= ~SF_MARKED;
12617 + }
12618 + return 0;
12619 +}
12620 +
12621 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12622 +{
12623 + int matching_count = 0;
12624 + pkg_t **pkgs = vec->pkgs;
12625 + int npkgs = vec->len;
12626 + int i;
12627 + for (i = 0; i < npkgs; i++) {
12628 + pkg_t *pkg = pkgs[i];
12629 + if (fnmatch(pattern, pkg->name, 0)==0) {
12630 + pkg->state_flag |= SF_MARKED;
12631 + matching_count++;
12632 + }
12633 + }
12634 + return matching_count;
12635 +}
12636 +
12637 +
12638 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12639 +{
12640 + abstract_pkg_vec_t * vec ;
12641 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12642 + if (!vec) {
12643 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12644 + return NULL;
12645 + }
12646 + vec->pkgs = NULL;
12647 + vec->len = 0;
12648 +
12649 + return vec;
12650 +}
12651 +
12652 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12653 +{
12654 + free(vec->pkgs);
12655 + free(vec);
12656 +}
12657 +
12658 +/*
12659 + * assumption: all names in a vector are unique
12660 + */
12661 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12662 +{
12663 + int i;
12664 +
12665 + /* look for a duplicate pkg by name */
12666 + for(i = 0; i < vec->len; i++)
12667 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12668 + break;
12669 +
12670 + /* we didn't find one, add it */
12671 + if(i == vec->len){
12672 + vec->pkgs =
12673 + (abstract_pkg_t **)
12674 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12675 + vec->pkgs[vec->len] = pkg;
12676 + vec->len++;
12677 + }
12678 +}
12679 +
12680 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12681 +{
12682 + if (vec->len > i)
12683 + return vec->pkgs[i];
12684 + else
12685 + return NULL;
12686 +}
12687 +
12688 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12689 +{
12690 + int i;
12691 + for (i = 0; i < vec->len; i++)
12692 + if (vec->pkgs[i] == apkg)
12693 + return 1;
12694 + return 0;
12695 +}
12696 +
12697 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12698 +{
12699 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12700 +}
12701 +
12702 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/pkg_vec.h busybox-1.1.0-pre1-new/archival/libipkg/pkg_vec.h
12703 --- busybox-1.1.0-pre1-old/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12704 +++ busybox-1.1.0-pre1-new/archival/libipkg/pkg_vec.h 2005-12-07 21:25:30.000000000 +0100
12705 @@ -0,0 +1,62 @@
12706 +/* pkg_vec.h - the itsy package management system
12707 +
12708 + Steven M. Ayer
12709 +
12710 + Copyright (C) 2002 Compaq Computer Corporation
12711 +
12712 + This program is free software; you can redistribute it and/or
12713 + modify it under the terms of the GNU General Public License as
12714 + published by the Free Software Foundation; either version 2, or (at
12715 + your option) any later version.
12716 +
12717 + This program is distributed in the hope that it will be useful, but
12718 + WITHOUT ANY WARRANTY; without even the implied warranty of
12719 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12720 + General Public License for more details.
12721 +*/
12722 +
12723 +#ifndef PKG_VEC_H
12724 +#define PKG_VEC_H
12725 +
12726 +typedef struct pkg pkg_t;
12727 +typedef struct abstract_pkg abstract_pkg_t;
12728 +
12729 +struct pkg_vec
12730 +{
12731 + pkg_t **pkgs;
12732 + int len;
12733 +};
12734 +typedef struct pkg_vec pkg_vec_t;
12735 +
12736 +struct abstract_pkg_vec
12737 +{
12738 + abstract_pkg_t **pkgs;
12739 + int len;
12740 +};
12741 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12742 +
12743 +
12744 +pkg_vec_t * pkg_vec_alloc(void);
12745 +void pkg_vec_free(pkg_vec_t *vec);
12746 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12747 +
12748 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12749 +/* pkg_vec_insert_merge: might munge pkg.
12750 +* returns the pkg that is in the pkg graph */
12751 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12752 +/* this one never munges pkg */
12753 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12754 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12755 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12756 +
12757 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12758 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12759 +
12760 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12761 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12762 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12763 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12764 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12765 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12766 +#endif
12767 +
12768 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/sprintf_alloc.h busybox-1.1.0-pre1-new/archival/libipkg/sprintf_alloc.h
12769 --- busybox-1.1.0-pre1-old/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12770 +++ busybox-1.1.0-pre1-new/archival/libipkg/sprintf_alloc.h 2005-12-07 21:25:30.000000000 +0100
12771 @@ -0,0 +1,25 @@
12772 +/* sprintf_alloca.c -- like sprintf with memory allocation
12773 +
12774 + Carl D. Worth
12775 +
12776 + Copyright (C) 2001 University of Southern California
12777 +
12778 + This program is free software; you can redistribute it and/or modify
12779 + it under the terms of the GNU General Public License as published by
12780 + the Free Software Foundation; either version 2, or (at your option)
12781 + any later version.
12782 +
12783 + This program is distributed in the hope that it will be useful,
12784 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12786 + GNU General Public License for more details.
12787 +*/
12788 +
12789 +#ifndef SPRINTF_ALLOC_H
12790 +#define SPRINTF_ALLOC_H
12791 +
12792 +#include "libbb.h"
12793 +
12794 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
12795 +
12796 +#endif
12797 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/str_list.c busybox-1.1.0-pre1-new/archival/libipkg/str_list.c
12798 --- busybox-1.1.0-pre1-old/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12799 +++ busybox-1.1.0-pre1-new/archival/libipkg/str_list.c 2005-12-07 21:25:30.000000000 +0100
12800 @@ -0,0 +1,76 @@
12801 +/* str_list.c - the itsy package management system
12802 +
12803 + Carl D. Worth
12804 +
12805 + Copyright (C) 2001 University of Southern California
12806 +
12807 + This program is free software; you can redistribute it and/or
12808 + modify it under the terms of the GNU General Public License as
12809 + published by the Free Software Foundation; either version 2, or (at
12810 + your option) any later version.
12811 +
12812 + This program is distributed in the hope that it will be useful, but
12813 + WITHOUT ANY WARRANTY; without even the implied warranty of
12814 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12815 + General Public License for more details.
12816 +*/
12817 +
12818 +#include "ipkg.h"
12819 +
12820 +#include "str_list.h"
12821 +
12822 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12823 +{
12824 + return void_list_elt_init((void_list_elt_t *) elt, data);
12825 +}
12826 +
12827 +void str_list_elt_deinit(str_list_elt_t *elt)
12828 +{
12829 + void_list_elt_deinit((void_list_elt_t *) elt);
12830 +}
12831 +
12832 +str_list_t *str_list_alloc()
12833 +{
12834 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12835 + if (list)
12836 + str_list_init(list);
12837 + return list;
12838 +}
12839 +
12840 +int str_list_init(str_list_t *list)
12841 +{
12842 + return void_list_init((void_list_t *) list);
12843 +}
12844 +
12845 +void str_list_deinit(str_list_t *list)
12846 +{
12847 + void_list_deinit((void_list_t *) list);
12848 +}
12849 +
12850 +int str_list_append(str_list_t *list, char *data)
12851 +{
12852 + return void_list_append((void_list_t *) list, data);
12853 +}
12854 +
12855 +int str_list_push(str_list_t *list, char *data)
12856 +{
12857 + return void_list_push((void_list_t *) list, data);
12858 +}
12859 +
12860 +str_list_elt_t *str_list_pop(str_list_t *list)
12861 +{
12862 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12863 +}
12864 +
12865 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12866 +{
12867 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12868 + (void_list_elt_t **) iter);
12869 +}
12870 +
12871 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12872 +{
12873 + return (char *)void_list_remove_elt((void_list_t *) list,
12874 + (void *)target_str,
12875 + (void_list_cmp_t)strcmp);
12876 +}
12877 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/str_list.h busybox-1.1.0-pre1-new/archival/libipkg/str_list.h
12878 --- busybox-1.1.0-pre1-old/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
12879 +++ busybox-1.1.0-pre1-new/archival/libipkg/str_list.h 2005-12-07 21:25:30.000000000 +0100
12880 @@ -0,0 +1,51 @@
12881 +/* str_list.h - the itsy package management system
12882 +
12883 + Carl D. Worth
12884 +
12885 + Copyright (C) 2001 University of Southern California
12886 +
12887 + This program is free software; you can redistribute it and/or
12888 + modify it under the terms of the GNU General Public License as
12889 + published by the Free Software Foundation; either version 2, or (at
12890 + your option) any later version.
12891 +
12892 + This program is distributed in the hope that it will be useful, but
12893 + WITHOUT ANY WARRANTY; without even the implied warranty of
12894 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12895 + General Public License for more details.
12896 +*/
12897 +
12898 +#ifndef STR_LIST_H
12899 +#define STR_LIST_H
12900 +
12901 +#include "void_list.h"
12902 +
12903 +typedef struct str_list_elt str_list_elt_t;
12904 +struct str_list_elt
12905 +{
12906 + str_list_elt_t *next;
12907 + char *data;
12908 +};
12909 +
12910 +typedef struct xstr_list str_list_t;
12911 +struct xstr_list
12912 +{
12913 + str_list_elt_t pre_head;
12914 + str_list_elt_t *head;
12915 + str_list_elt_t *tail;
12916 +};
12917 +
12918 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12919 +void str_list_elt_deinit(str_list_elt_t *elt);
12920 +
12921 +str_list_t *str_list_alloc(void);
12922 +int str_list_init(str_list_t *list);
12923 +void str_list_deinit(str_list_t *list);
12924 +
12925 +int str_list_append(str_list_t *list, char *data);
12926 +int str_list_push(str_list_t *list, char *data);
12927 +str_list_elt_t *str_list_pop(str_list_t *list);
12928 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12929 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12930 +
12931 +#endif
12932 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/str_util.c busybox-1.1.0-pre1-new/archival/libipkg/str_util.c
12933 --- busybox-1.1.0-pre1-old/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
12934 +++ busybox-1.1.0-pre1-new/archival/libipkg/str_util.c 2005-12-07 21:25:30.000000000 +0100
12935 @@ -0,0 +1,73 @@
12936 +/* str_utils.c - the itsy package management system
12937 +
12938 + Carl D. Worth
12939 +
12940 + Copyright (C) 2001 University of Southern California
12941 +
12942 + This program is free software; you can redistribute it and/or
12943 + modify it under the terms of the GNU General Public License as
12944 + published by the Free Software Foundation; either version 2, or (at
12945 + your option) any later version.
12946 +
12947 + This program is distributed in the hope that it will be useful, but
12948 + WITHOUT ANY WARRANTY; without even the implied warranty of
12949 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12950 + General Public License for more details.
12951 +*/
12952 +
12953 +#include "ipkg.h"
12954 +
12955 +int str_starts_with(const char *str, const char *prefix)
12956 +{
12957 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12958 +}
12959 +
12960 +int str_ends_with(const char *str, const char *suffix)
12961 +{
12962 + int suffix_len;
12963 + int str_len;
12964 +
12965 + str_len = strlen(str);
12966 + suffix_len = strlen(suffix);
12967 +
12968 + if (str_len < suffix_len) {
12969 + return 0;
12970 + }
12971 +
12972 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12973 +}
12974 +
12975 +int str_chomp(char *str)
12976 +{
12977 + if (str[strlen(str) - 1] == '\n') {
12978 + str[strlen(str) - 1] = '\0';
12979 + return 1;
12980 + }
12981 + return 0;
12982 +}
12983 +
12984 +int str_tolower(char *str)
12985 +{
12986 + while (*str) {
12987 + *str = tolower(*str);
12988 + str++;
12989 + }
12990 +
12991 + return 0;
12992 +}
12993 +
12994 +int str_toupper(char *str)
12995 +{
12996 + while (*str) {
12997 + *str = toupper(*str);
12998 + str++;
12999 + }
13000 +
13001 + return 0;
13002 +}
13003 +
13004 +char *str_dup_safe(const char *str)
13005 +{
13006 + return str ? strdup(str) : NULL;
13007 +}
13008 +
13009 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/str_util.h busybox-1.1.0-pre1-new/archival/libipkg/str_util.h
13010 --- busybox-1.1.0-pre1-old/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13011 +++ busybox-1.1.0-pre1-new/archival/libipkg/str_util.h 2005-12-07 21:25:30.000000000 +0100
13012 @@ -0,0 +1,28 @@
13013 +/* str_utils.h - the itsy package management system
13014 +
13015 + Carl D. Worth
13016 +
13017 + Copyright (C) 2001 University of Southern California
13018 +
13019 + This program is free software; you can redistribute it and/or
13020 + modify it under the terms of the GNU General Public License as
13021 + published by the Free Software Foundation; either version 2, or (at
13022 + your option) any later version.
13023 +
13024 + This program is distributed in the hope that it will be useful, but
13025 + WITHOUT ANY WARRANTY; without even the implied warranty of
13026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13027 + General Public License for more details.
13028 +*/
13029 +
13030 +#ifndef STR_UTILS_H
13031 +#define STR_UTILS_H
13032 +
13033 +int str_starts_with(const char *str, const char *prefix);
13034 +int str_ends_with(const char *str, const char *suffix);
13035 +int str_chomp(char *str);
13036 +int str_tolower(char *str);
13037 +int str_toupper(char *str);
13038 +char *str_dup_safe(const char *str);
13039 +
13040 +#endif
13041 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/user.c busybox-1.1.0-pre1-new/archival/libipkg/user.c
13042 --- busybox-1.1.0-pre1-old/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13043 +++ busybox-1.1.0-pre1-new/archival/libipkg/user.c 2005-12-07 21:25:30.000000000 +0100
13044 @@ -0,0 +1,58 @@
13045 +/* user.c - the itsy package management system
13046 +
13047 + Jamey Hicks
13048 +
13049 + Copyright (C) 2002 Hewlett Packard Company
13050 + Copyright (C) 2001 University of Southern California
13051 +
13052 + This program is free software; you can redistribute it and/or
13053 + modify it under the terms of the GNU General Public License as
13054 + published by the Free Software Foundation; either version 2, or (at
13055 + your option) any later version.
13056 +
13057 + This program is distributed in the hope that it will be useful, but
13058 + WITHOUT ANY WARRANTY; without even the implied warranty of
13059 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13060 + General Public License for more details.
13061 +*/
13062 +
13063 +#include <stdio.h>
13064 +#include <stdarg.h>
13065 +#include "file_util.h"
13066 +#include "str_util.h"
13067 +#ifdef IPKG_LIB
13068 +#include "libipkg.h"
13069 +#endif
13070 +
13071 +
13072 +#ifdef IPKG_LIB
13073 +static char *question = NULL;
13074 +static int question_len = 255;
13075 +#endif
13076 +char *get_user_response(const char *format, ...)
13077 +{
13078 + int len = question_len;
13079 + va_list ap;
13080 + char *response;
13081 + va_start(ap, format);
13082 +
13083 +#ifndef IPKG_LIB
13084 + vprintf(format, ap);
13085 + do {
13086 + response = file_read_line_alloc(stdin);
13087 + } while (response == NULL);
13088 +#else
13089 + do {
13090 + if (question == NULL || len > question_len) {
13091 + question = realloc(question, len + 1);
13092 + question_len = len;
13093 + }
13094 + len = vsnprintf(question,question_len,format,ap);
13095 + } while (len > question_len);
13096 + response = strdup(ipkg_cb_response(question));
13097 +#endif
13098 + str_chomp(response);
13099 + str_tolower(response);
13100 +
13101 + return response;
13102 +}
13103 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/user.h busybox-1.1.0-pre1-new/archival/libipkg/user.h
13104 --- busybox-1.1.0-pre1-old/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13105 +++ busybox-1.1.0-pre1-new/archival/libipkg/user.h 2005-12-07 21:25:30.000000000 +0100
13106 @@ -0,0 +1,23 @@
13107 +/* user.c - the itsy package management system
13108 +
13109 + Jamey Hicks
13110 +
13111 + Copyright (C) 2002 Hewlett Packard Company
13112 + Copyright (C) 2001 University of Southern California
13113 +
13114 + This program is free software; you can redistribute it and/or
13115 + modify it under the terms of the GNU General Public License as
13116 + published by the Free Software Foundation; either version 2, or (at
13117 + your option) any later version.
13118 +
13119 + This program is distributed in the hope that it will be useful, but
13120 + WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13122 + General Public License for more details.
13123 +*/
13124 +
13125 +#include <stdio.h>
13126 +#include <stdarg.h>
13127 +
13128 +char *get_user_response(const char *format, ...);
13129 +
13130 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/void_list.c busybox-1.1.0-pre1-new/archival/libipkg/void_list.c
13131 --- busybox-1.1.0-pre1-old/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13132 +++ busybox-1.1.0-pre1-new/archival/libipkg/void_list.c 2005-12-07 21:25:30.000000000 +0100
13133 @@ -0,0 +1,194 @@
13134 +/* void_list.c - the itsy package management system
13135 +
13136 + Carl D. Worth
13137 +
13138 + Copyright (C) 2001 University of Southern California
13139 +
13140 + This program is free software; you can redistribute it and/or
13141 + modify it under the terms of the GNU General Public License as
13142 + published by the Free Software Foundation; either version 2, or (at
13143 + your option) any later version.
13144 +
13145 + This program is distributed in the hope that it will be useful, but
13146 + WITHOUT ANY WARRANTY; without even the implied warranty of
13147 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13148 + General Public License for more details.
13149 +*/
13150 +
13151 +#include "ipkg.h"
13152 +#include <errno.h>
13153 +
13154 +#include "void_list.h"
13155 +
13156 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13157 +{
13158 + elt->next = NULL;
13159 + elt->data = data;
13160 +
13161 + return 0;
13162 +}
13163 +
13164 +void void_list_elt_deinit(void_list_elt_t *elt)
13165 +{
13166 + void_list_elt_init(elt, NULL);
13167 +}
13168 +
13169 +int void_list_init(void_list_t *list)
13170 +{
13171 + void_list_elt_init(&list->pre_head, NULL);
13172 + list->head = NULL;
13173 + list->pre_head.next = list->head;
13174 + list->tail = NULL;
13175 +
13176 + return 0;
13177 +}
13178 +
13179 +void void_list_deinit(void_list_t *list)
13180 +{
13181 + void_list_elt_t *elt;
13182 +
13183 + while (list->head) {
13184 + elt = void_list_pop(list);
13185 + void_list_elt_deinit(elt);
13186 + /* malloced in void_list_append */
13187 + free(elt);
13188 + }
13189 +}
13190 +
13191 +int void_list_append(void_list_t *list, void *data)
13192 +{
13193 + void_list_elt_t *elt;
13194 +
13195 + /* freed in void_list_deinit */
13196 + elt = malloc(sizeof(void_list_elt_t));
13197 + if (elt == NULL) {
13198 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13199 + return ENOMEM;
13200 + }
13201 +
13202 + void_list_elt_init(elt, data);
13203 +
13204 + if (list->tail) {
13205 + list->tail->next = elt;
13206 + list->tail = elt;
13207 + } else {
13208 + list->head = elt;
13209 + list->pre_head.next = list->head;
13210 + list->tail = elt;
13211 + }
13212 +
13213 + return 0;
13214 +}
13215 +
13216 +int void_list_push(void_list_t *list, void *data)
13217 +{
13218 + void_list_elt_t *elt;
13219 +
13220 + elt = malloc(sizeof(void_list_elt_t));
13221 + if (elt == NULL) {
13222 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13223 + return ENOMEM;
13224 + }
13225 +
13226 + void_list_elt_init(elt, data);
13227 +
13228 + elt->next = list->head;
13229 + list->head->next = elt;
13230 + if (list->tail == NULL) {
13231 + list->tail = list->head;
13232 + }
13233 +
13234 + return 0;
13235 +}
13236 +
13237 +void_list_elt_t *void_list_pop(void_list_t *list)
13238 +{
13239 + void_list_elt_t *elt;
13240 +
13241 + elt = list->head;
13242 +
13243 + if (list->head) {
13244 + list->head = list->head->next;
13245 + list->pre_head.next = list->head;
13246 + if (list->head == NULL) {
13247 + list->tail = NULL;
13248 + }
13249 + }
13250 +
13251 + return elt;
13252 +}
13253 +
13254 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13255 +{
13256 + void_list_elt_t *prior;
13257 + void_list_elt_t *old_elt;
13258 + void *old_data;
13259 +
13260 + old_elt = *iter;
13261 + old_data = old_elt->data;
13262 +
13263 + if (old_elt == list->head) {
13264 + prior = &list->pre_head;
13265 + void_list_pop(list);
13266 + } else {
13267 + for (prior = list->head; prior; prior = prior->next) {
13268 + if (prior->next == old_elt) {
13269 + break;
13270 + }
13271 + }
13272 + if (prior == NULL || prior->next != old_elt) {
13273 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13274 + return NULL;
13275 + }
13276 + prior->next = old_elt->next;
13277 +
13278 + if (old_elt == list->tail) {
13279 + list->tail = prior;
13280 + }
13281 + }
13282 +
13283 + void_list_elt_deinit(old_elt);
13284 + *iter = prior;
13285 +
13286 + return old_data;
13287 +}
13288 +
13289 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13290 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13291 +{
13292 + void_list_elt_t *prior;
13293 + void_list_elt_t *old_elt = NULL;
13294 + void *old_data = NULL;
13295 +
13296 + /* first element */
13297 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13298 + old_elt = list->head;
13299 + old_data = list->head->data;
13300 + void_list_pop(list);
13301 + } else {
13302 + int found = 0;
13303 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13304 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13305 + old_elt = prior->next;
13306 + old_data = old_elt->data;
13307 + found = 1;
13308 + break;
13309 + }
13310 + }
13311 + if (!found) {
13312 + return NULL;
13313 + }
13314 + prior->next = old_elt->next;
13315 +
13316 + if (old_elt == list->tail) {
13317 + list->tail = prior;
13318 + }
13319 + }
13320 + if (old_elt)
13321 + void_list_elt_deinit(old_elt);
13322 +
13323 + if (old_data)
13324 + return old_data;
13325 + else
13326 + return NULL;
13327 +}
13328 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/void_list.h busybox-1.1.0-pre1-new/archival/libipkg/void_list.h
13329 --- busybox-1.1.0-pre1-old/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13330 +++ busybox-1.1.0-pre1-new/archival/libipkg/void_list.h 2005-12-07 21:25:30.000000000 +0100
13331 @@ -0,0 +1,59 @@
13332 +/* void_list.h - the itsy package management system
13333 +
13334 + Carl D. Worth
13335 +
13336 + Copyright (C) 2001 University of Southern California
13337 +
13338 + This program is free software; you can redistribute it and/or
13339 + modify it under the terms of the GNU General Public License as
13340 + published by the Free Software Foundation; either version 2, or (at
13341 + your option) any later version.
13342 +
13343 + This program is distributed in the hope that it will be useful, but
13344 + WITHOUT ANY WARRANTY; without even the implied warranty of
13345 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13346 + General Public License for more details.
13347 +*/
13348 +
13349 +#ifndef VOID_LIST_H
13350 +#define VOID_LIST_H
13351 +
13352 +typedef struct void_list_elt void_list_elt_t;
13353 +struct void_list_elt
13354 +{
13355 + void_list_elt_t *next;
13356 + void *data;
13357 +};
13358 +
13359 +typedef struct void_list void_list_t;
13360 +struct void_list
13361 +{
13362 + void_list_elt_t pre_head;
13363 + void_list_elt_t *head;
13364 + void_list_elt_t *tail;
13365 +};
13366 +
13367 +static inline int void_list_empty(void_list_t *list)
13368 +{
13369 + if (list->head == NULL)
13370 + return 1;
13371 + else
13372 + return 0;
13373 +}
13374 +
13375 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13376 +void void_list_elt_deinit(void_list_elt_t *elt);
13377 +
13378 +int void_list_init(void_list_t *list);
13379 +void void_list_deinit(void_list_t *list);
13380 +
13381 +int void_list_append(void_list_t *list, void *data);
13382 +int void_list_push(void_list_t *list, void *data);
13383 +void_list_elt_t *void_list_pop(void_list_t *list);
13384 +
13385 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13386 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13387 +typedef int (*void_list_cmp_t)(const void *, const void *);
13388 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13389 +
13390 +#endif
13391 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/xsystem.c busybox-1.1.0-pre1-new/archival/libipkg/xsystem.c
13392 --- busybox-1.1.0-pre1-old/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13393 +++ busybox-1.1.0-pre1-new/archival/libipkg/xsystem.c 2005-12-07 21:25:30.000000000 +0100
13394 @@ -0,0 +1,64 @@
13395 +/* xsystem.c - system(3) with error messages
13396 +
13397 + Carl D. Worth
13398 +
13399 + Copyright (C) 2001 University of Southern California
13400 +
13401 + This program is free software; you can redistribute it and/or
13402 + modify it under the terms of the GNU General Public License as
13403 + published by the Free Software Foundation; either version 2, or (at
13404 + your option) any later version.
13405 +
13406 + This program is distributed in the hope that it will be useful, but
13407 + WITHOUT ANY WARRANTY; without even the implied warranty of
13408 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13409 + General Public License for more details.
13410 +*/
13411 +
13412 +#include "ipkg.h"
13413 +#include <sys/wait.h>
13414 +
13415 +#include "xsystem.h"
13416 +
13417 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13418 + really need the /bin/sh invocation which takes resources and
13419 + introduces security problems. I should switch all of this to a sort
13420 + of execl() or execv() interface/implementation.
13421 +*/
13422 +
13423 +/* Like system(3), but with error messages printed if the fork fails
13424 + or if the child process dies due to an uncaught signal. Also, the
13425 + return value is a bit simpler:
13426 +
13427 + -1 if there was any problem
13428 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13429 + as defined in <sys/wait.h>.
13430 +*/
13431 +int xsystem(const char *cmd)
13432 +{
13433 + int err;
13434 +
13435 + err = system(cmd);
13436 +
13437 + if (err == -1) {
13438 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13439 + __FUNCTION__, cmd);
13440 + return -1;
13441 + }
13442 +
13443 + if (WIFSIGNALED(err)) {
13444 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13445 + __FUNCTION__, WTERMSIG(err), cmd);
13446 + return -1;
13447 + }
13448 +
13449 + if (WIFEXITED(err)) {
13450 + /* Normal child exit */
13451 + return WEXITSTATUS(err);
13452 + }
13453 +
13454 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13455 + __FUNCTION__, err);
13456 + return -1;
13457 +}
13458 +
13459 diff -ruN busybox-1.1.0-pre1-old/archival/libipkg/xsystem.h busybox-1.1.0-pre1-new/archival/libipkg/xsystem.h
13460 --- busybox-1.1.0-pre1-old/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13461 +++ busybox-1.1.0-pre1-new/archival/libipkg/xsystem.h 2005-12-07 21:25:30.000000000 +0100
13462 @@ -0,0 +1,34 @@
13463 +/* xsystem.h - system(3) with error messages
13464 +
13465 + Carl D. Worth
13466 +
13467 + Copyright (C) 2001 University of Southern California
13468 +
13469 + This program is free software; you can redistribute it and/or
13470 + modify it under the terms of the GNU General Public License as
13471 + published by the Free Software Foundation; either version 2, or (at
13472 + your option) any later version.
13473 +
13474 + This program is distributed in the hope that it will be useful, but
13475 + WITHOUT ANY WARRANTY; without even the implied warranty of
13476 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13477 + General Public License for more details.
13478 +*/
13479 +
13480 +#ifndef XSYSTEM_H
13481 +#define XSYSTEM_H
13482 +
13483 +#include <stdlib.h>
13484 +
13485 +/* Like system(3), but with error messages printed if the fork fails
13486 + or if the child process dies due to an uncaught signal. Also, the
13487 + return value is a bit simpler:
13488 +
13489 + -1 if there was any problem
13490 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13491 + as defined in <sys/wait.h>.
13492 +*/
13493 +int xsystem(const char *cmd);
13494 +
13495 +#endif
13496 +
13497 diff -ruN busybox-1.1.0-pre1-old/archival/libunarchive/data_extract_all.c busybox-1.1.0-pre1-new/archival/libunarchive/data_extract_all.c
13498 --- busybox-1.1.0-pre1-old/archival/libunarchive/data_extract_all.c 2005-11-01 00:55:19.000000000 +0100
13499 +++ busybox-1.1.0-pre1-new/archival/libunarchive/data_extract_all.c 2005-12-07 21:25:30.000000000 +0100
13500 @@ -126,3 +126,17 @@
13501 utime(file_header->name, &t);
13502 }
13503 }
13504 +
13505 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13506 +{
13507 + char *name_ptr = archive_handle->file_header->name;
13508 +
13509 + name_ptr += strspn(name_ptr, "./");
13510 + if (name_ptr[0] != '\0') {
13511 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13512 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13513 + strcat(archive_handle->file_header->name, name_ptr);
13514 + data_extract_all(archive_handle);
13515 + }
13516 +}
13517 +
13518 diff -ruN busybox-1.1.0-pre1-old/include/applets.h busybox-1.1.0-pre1-new/include/applets.h
13519 --- busybox-1.1.0-pre1-old/include/applets.h 2005-11-01 00:55:34.000000000 +0100
13520 +++ busybox-1.1.0-pre1-new/include/applets.h 2005-12-07 21:25:30.000000000 +0100
13521 @@ -342,6 +342,9 @@
13522 #ifdef CONFIG_IPCS
13523 APPLET(ipcs, ipcs_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)
13524 #endif
13525 +#ifdef CONFIG_IPKG
13526 + APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
13527 +#endif
13528 #ifdef CONFIG_IPLINK
13529 APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13530 #endif
13531 diff -ruN busybox-1.1.0-pre1-old/include/libbb.h busybox-1.1.0-pre1-new/include/libbb.h
13532 --- busybox-1.1.0-pre1-old/include/libbb.h 2005-11-01 00:55:34.000000000 +0100
13533 +++ busybox-1.1.0-pre1-new/include/libbb.h 2005-12-07 21:25:30.000000000 +0100
13534 @@ -496,4 +496,17 @@
13535 #include <dmalloc.h>
13536 #endif
13537
13538 +struct md5_ctx_t {
13539 + uint32_t A;
13540 + uint32_t B;
13541 + uint32_t C;
13542 + uint32_t D;
13543 + uint32_t total[2];
13544 + uint32_t buflen;
13545 + char buffer[128];
13546 +};
13547 +extern void md5_begin(struct md5_ctx_t *ctx);
13548 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx);
13549 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
13550 +
13551 #endif /* __LIBCONFIG_H__ */
13552 diff -ruN busybox-1.1.0-pre1-old/include/unarchive.h busybox-1.1.0-pre1-new/include/unarchive.h
13553 --- busybox-1.1.0-pre1-old/include/unarchive.h 2005-11-01 00:55:34.000000000 +0100
13554 +++ busybox-1.1.0-pre1-new/include/unarchive.h 2005-12-07 21:25:30.000000000 +0100
13555 @@ -74,6 +74,7 @@
13556
13557 extern void data_skip(archive_handle_t *archive_handle);
13558 extern void data_extract_all(archive_handle_t *archive_handle);
13559 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13560 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13561 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13562
13563 diff -ruN busybox-1.1.0-pre1-old/include/usage.h busybox-1.1.0-pre1-new/include/usage.h
13564 --- busybox-1.1.0-pre1-old/include/usage.h 2005-11-01 00:55:34.000000000 +0100
13565 +++ busybox-1.1.0-pre1-new/include/usage.h 2005-12-07 21:25:30.000000000 +0100
13566 @@ -975,6 +975,82 @@
13567 "$ ls -la /tmp/busybox*\n" \
13568 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13569
13570 +#define ipkg_trivial_usage \
13571 + "[options...] sub-command [arguments...]"
13572 +#define ipkg_full_usage \
13573 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13574 + "\n" \
13575 + "Sub-commands:\n" \
13576 + "\nPackage Manipulation:\n" \
13577 + "\tupdate Update list of available packages\n" \
13578 + "\tupgrade Upgrade all installed packages to latest version\n" \
13579 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13580 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13581 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13582 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13583 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13584 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13585 + "\n" \
13586 + "Informational Commands:\n" \
13587 + "\tlist List available packages and descriptions\n" \
13588 + "\tlist_installed List all and only the installed packages and description \n" \
13589 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13590 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13591 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13592 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13593 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13594 + "\tcompare_versions <v1> <op> <v2>\n" \
13595 + "\t compare versions using <= < > >= = << >>\n" \
13596 + "\tprint_architecture prints the architecture.\n" \
13597 + "\tprint_installation_architecture\n" \
13598 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13599 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13600 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13601 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13602 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13603 + "\t prints the installation architecture.\n" \
13604 + "\n" \
13605 + "\nOptions:\n" \
13606 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13607 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13608 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13609 + "\t 0 errors only\n" \
13610 + "\t 1 normal messages (default)\n" \
13611 + "\t 2 informative messages\n" \
13612 + "\t 3 debug output\n" \
13613 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13614 + "\t-conf <conf_file> Default configuration file location\n" \
13615 + " is /etc/ipkg.conf\n" \
13616 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13617 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13618 + " <dest_name> should be a defined dest name from\n" \
13619 + " the configuration file, (but can also be a\n" \
13620 + " directory name in a pinch).\n" \
13621 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13622 + "\t-offline <offline_root> offline installation of packages.\n" \
13623 + "\t-verbose_wget more wget messages\n" \
13624 + "\n" \
13625 + "Force Options (use when ipkg is too smart for its own good):\n" \
13626 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13627 + "\t Install/remove package in spite of failed dependences\n" \
13628 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13629 + " (no prompts). Note that this will not prevent\n" \
13630 + " package installation scripts from prompting.\n" \
13631 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13632 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13633 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13634 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13635 + "\t-noaction No action -- test only\n" \
13636 + "\t-nodeps Do not follow dependences\n" \
13637 + "\t-force-removal-of-dependent-packages\n" \
13638 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13639 + "\t-test No action -- test only\n" \
13640 + "\t-t Specify tmp-dir.\n" \
13641 + "\t--tmp-dir Specify tmp-dir.\n" \
13642 + "\n" \
13643 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13644 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13645 +
13646 #define halt_trivial_usage \
13647 "[-d<delay>]"
13648 #define halt_full_usage \
13649 diff -ruN busybox-1.1.0-pre1-old/libbb/hash_fd.c busybox-1.1.0-pre1-new/libbb/hash_fd.c
13650 --- busybox-1.1.0-pre1-old/libbb/hash_fd.c 2005-11-01 00:55:29.000000000 +0100
13651 +++ busybox-1.1.0-pre1-new/libbb/hash_fd.c 2005-12-07 21:25:30.000000000 +0100
13652 @@ -288,21 +288,10 @@
13653 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
13654 # endif /* MD5SUM_SIZE_VS_SPEED == 0 */
13655
13656 -/* Structure to save state of computation between the single steps. */
13657 -struct md5_ctx_t {
13658 - uint32_t A;
13659 - uint32_t B;
13660 - uint32_t C;
13661 - uint32_t D;
13662 - uint32_t total[2];
13663 - uint32_t buflen;
13664 - char buffer[128];
13665 -};
13666 -
13667 /* Initialize structure containing state of computation.
13668 * (RFC 1321, 3.3: Step 3)
13669 */
13670 -static void md5_begin(struct md5_ctx_t *ctx)
13671 +extern void md5_begin(struct md5_ctx_t *ctx)
13672 {
13673 ctx->A = 0x67452301;
13674 ctx->B = 0xefcdab89;
13675 @@ -706,7 +695,7 @@
13676 }
13677 }
13678
13679 -static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13680 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13681 {
13682 if (length % 64 == 0) {
13683 md5_hash_block(buffer, length, md5_ctx);
13684 @@ -723,7 +712,7 @@
13685 * IMPORTANT: On some systems it is required that RESBUF is correctly
13686 * aligned for a 32 bits value.
13687 */
13688 -static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13689 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13690 {
13691 /* Take yet unprocessed bytes into account. */
13692 uint32_t bytes = ctx->buflen;