update ipkg patch for 1.1.1, expose an hash_fd function again removed in 1.1.1
[openwrt/svn-archive/archive.git] / openwrt / package / busybox / patches / 911-ipkg.patch
1 diff -ruN busybox-1.1.1-old/Makefile busybox-1.1.1-new/Makefile
2 --- busybox-1.1.1-old/Makefile 2006-03-22 22:16:26.000000000 +0100
3 +++ busybox-1.1.1-new/Makefile 2006-03-30 00:39:48.000000000 +0200
4 @@ -25,7 +25,7 @@
5 export srctree=$(top_srcdir)
6 vpath %/Config.in $(srctree)
7
8 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
9 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
10 debianutils editors findutils init miscutils modutils networking \
11 networking/libiproute networking/udhcp procps loginutils shell \
12 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
13 diff -ruN busybox-1.1.1-old/archival/Config.in busybox-1.1.1-new/archival/Config.in
14 --- busybox-1.1.1-old/archival/Config.in 2006-03-22 22:16:20.000000000 +0100
15 +++ busybox-1.1.1-new/archival/Config.in 2006-03-30 00:39:48.000000000 +0200
16 @@ -121,6 +121,14 @@
17 gzip is used to compress files.
18 It's probably the most widely used UNIX compression program.
19
20 +config CONFIG_IPKG
21 + bool "ipkg"
22 + default n
23 + select CONFIG_MD5SUM
24 + select CONFIG_WGET
25 + help
26 + ipkg is the itsy package management system.
27 +
28 config CONFIG_RPM2CPIO
29 bool "rpm2cpio"
30 default n
31 diff -ruN busybox-1.1.1-old/archival/Makefile.in busybox-1.1.1-new/archival/Makefile.in
32 --- busybox-1.1.1-old/archival/Makefile.in 2006-03-22 22:16:20.000000000 +0100
33 +++ busybox-1.1.1-new/archival/Makefile.in 2006-03-30 00:39:48.000000000 +0200
34 @@ -20,6 +20,7 @@
35 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
36 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
37 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
38 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
39 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
40 ARCHIVAL-$(CONFIG_RPM) += rpm.o
41 ARCHIVAL-$(CONFIG_TAR) += tar.o
42 diff -ruN busybox-1.1.1-old/archival/dpkg.c busybox-1.1.1-new/archival/dpkg.c
43 --- busybox-1.1.1-old/archival/dpkg.c 2006-03-22 22:16:20.000000000 +0100
44 +++ busybox-1.1.1-new/archival/dpkg.c 2006-03-30 00:39:48.000000000 +0200
45 @@ -1530,6 +1530,10 @@
46 return(ar_handle->sub_archive->buffer);
47 }
48
49 +/*
50 +
51 +// moved to data_extract_all.c
52 +
53 static void data_extract_all_prefix(archive_handle_t *archive_handle)
54 {
55 char *name_ptr = archive_handle->file_header->name;
56 @@ -1544,6 +1548,8 @@
57 return;
58 }
59
60 +*/
61 +
62 static void unpack_package(deb_file_t *deb_file)
63 {
64 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
65 diff -ruN busybox-1.1.1-old/archival/ipkg.c busybox-1.1.1-new/archival/ipkg.c
66 --- busybox-1.1.1-old/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
67 +++ busybox-1.1.1-new/archival/ipkg.c 2006-03-30 00:39:48.000000000 +0200
68 @@ -0,0 +1,26 @@
69 +/* ipkg.c - the itsy package management system
70 +
71 + Florina Boor
72 +
73 + Copyright (C) 2003 kernel concepts
74 +
75 + This program is free software; you can redistribute it and/or
76 + modify it under the terms of the GNU General Public License as
77 + published by the Free Software Foundation; either version 2, or (at
78 + your option) any later version.
79 +
80 + This program is distributed in the hope that it will be useful, but
81 + WITHOUT ANY WARRANTY; without even the implied warranty of
82 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83 + General Public License for more details.
84 +
85 + ipkg command line frontend using libipkg
86 +
87 +*/
88 +
89 +#include "libipkg/libipkg.h"
90 +
91 +int ipkg_main(int argc, char **argv)
92 +{
93 + return ipkg_op(argc, argv);
94 +}
95 diff -ruN busybox-1.1.1-old/archival/libipkg/Makefile busybox-1.1.1-new/archival/libipkg/Makefile
96 --- busybox-1.1.1-old/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
97 +++ busybox-1.1.1-new/archival/libipkg/Makefile 2006-03-30 00:39:48.000000000 +0200
98 @@ -0,0 +1,32 @@
99 +# Makefile for busybox
100 +#
101 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
102 +#
103 +# This program is free software; you can redistribute it and/or modify
104 +# it under the terms of the GNU General Public License as published by
105 +# the Free Software Foundation; either version 2 of the License, or
106 +# (at your option) any later version.
107 +#
108 +# This program is distributed in the hope that it will be useful,
109 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
110 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
111 +# General Public License for more details.
112 +#
113 +# You should have received a copy of the GNU General Public License
114 +# along with this program; if not, write to the Free Software
115 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
116 +#
117 +
118 +top_srcdir=../..
119 +top_builddir=../..
120 +srcdir=$(top_srcdir)/archival/libipkg
121 +LIBIPKG_DIR:=./
122 +include $(top_builddir)/Rules.mak
123 +include $(top_builddir)/.config
124 +include $(srcdir)/Makefile.in
125 +all: $(libraries-y)
126 +-include $(top_builddir)/.depend
127 +
128 +clean:
129 + rm -f *.o *.a $(AR_TARGET)
130 +
131 diff -ruN busybox-1.1.1-old/archival/libipkg/Makefile.in busybox-1.1.1-new/archival/libipkg/Makefile.in
132 --- busybox-1.1.1-old/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
133 +++ busybox-1.1.1-new/archival/libipkg/Makefile.in 2006-03-30 01:14:50.000000000 +0200
134 @@ -0,0 +1,85 @@
135 +# Makefile for busybox
136 +#
137 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
138 +#
139 +# This program is free software; you can redistribute it and/or modify
140 +# it under the terms of the GNU General Public License as published by
141 +# the Free Software Foundation; either version 2 of the License, or
142 +# (at your option) any later version.
143 +#
144 +# This program is distributed in the hope that it will be useful,
145 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
146 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
147 +# General Public License for more details.
148 +#
149 +# You should have received a copy of the GNU General Public License
150 +# along with this program; if not, write to the Free Software
151 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
152 +#
153 +
154 +LIBIPKG_AR:=libipkg.a
155 +ifndef $(LIBIPKG_DIR)
156 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
157 +endif
158 +srcdir=$(top_srcdir)/archival/libipkg
159 +
160 +LIBIPKG_CORE_SOURCES:= \
161 + args.c \
162 + libipkg.c \
163 + user.c \
164 +
165 +LIBIPKG_CMD_SOURCES:= \
166 + ipkg_cmd.c \
167 + ipkg_configure.c \
168 + ipkg_download.c \
169 + ipkg_install.c \
170 + ipkg_remove.c \
171 + ipkg_upgrade.c \
172 +
173 +LIBIPKG_DB_SOURCES:= \
174 + hash_table.c \
175 + ipkg_conf.c \
176 + ipkg_utils.c \
177 + pkg.c \
178 + pkg_depends.c \
179 + pkg_extract.c \
180 + pkg_hash.c \
181 + pkg_parse.c \
182 + pkg_vec.c \
183 +
184 +LIBIPKG_LIST_SOURCES:= \
185 + conffile.c \
186 + conffile_list.c \
187 + nv_pair.c \
188 + nv_pair_list.c \
189 + pkg_dest.c \
190 + pkg_dest_list.c \
191 + pkg_src.c \
192 + pkg_src_list.c \
193 + str_list.c \
194 + void_list.c \
195 +
196 +LIBIPKG_UTIL_SOURCES:= \
197 + file_util.c \
198 + ipkg_message.c \
199 + md5.c \
200 + str_util.c \
201 + xsystem.c \
202 +
203 +LIBIPKG-y += $(LIBIPKG_CORE_SOURCES)
204 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
205 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
206 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_UTIL_SOURCES)
208 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
209 +
210 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
211 +
212 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
213 +
214 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
215 + $(do_ar)
216 +
217 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
218 + $(compile.c)
219 +
220 diff -ruN busybox-1.1.1-old/archival/libipkg/args.c busybox-1.1.1-new/archival/libipkg/args.c
221 --- busybox-1.1.1-old/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
222 +++ busybox-1.1.1-new/archival/libipkg/args.c 2006-03-30 00:39:48.000000000 +0200
223 @@ -0,0 +1,241 @@
224 +/* args.c - parse command-line args
225 +
226 + Carl D. Worth
227 +
228 + Copyright 2001 University of Southern California
229 +
230 + This program is free software; you can redistribute it and/or modify
231 + it under the terms of the GNU General Public License as published by
232 + the Free Software Foundation; either version 2, or (at your option)
233 + any later version.
234 +
235 + This program is distributed in the hope that it will be useful,
236 + but WITHOUT ANY WARRANTY; without even the implied warranty of
237 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238 + GNU General Public License for more details.
239 + */
240 +
241 +#include <getopt.h>
242 +#include <stdlib.h>
243 +#include <string.h>
244 +#include <unistd.h>
245 +
246 +#include "ipkg.h"
247 +#include "ipkg_message.h"
248 +
249 +#include "args.h"
250 +#include "sprintf_alloc.h"
251 +
252 +#include "libbb.h"
253 +
254 +
255 +static void print_version(void);
256 +
257 +enum long_args_opt
258 +{
259 + ARGS_OPT_FORCE_DEFAULTS = 129,
260 + ARGS_OPT_FORCE_DEPENDS,
261 + ARGS_OPT_FORCE_OVERWRITE,
262 + ARGS_OPT_FORCE_DOWNGRADE,
263 + ARGS_OPT_FORCE_REINSTALL,
264 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
265 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
266 + ARGS_OPT_FORCE_SPACE,
267 + ARGS_OPT_NOACTION,
268 + ARGS_OPT_NODEPS,
269 + ARGS_OPT_VERBOSE_WGET,
270 + ARGS_OPT_VERBOSITY,
271 + ARGS_OPT_MULTIPLE_PROVIDERS
272 +};
273 +
274 +int args_init(args_t *args)
275 +{
276 + char *conf_file_dir;
277 +
278 + memset(args, 0, sizeof(args_t));
279 +
280 + args->dest = ARGS_DEFAULT_DEST;
281 +
282 + conf_file_dir = getenv("IPKG_CONF_DIR");
283 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
284 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
285 + }
286 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
287 + ARGS_DEFAULT_CONF_FILE_NAME);
288 +
289 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
290 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
291 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
292 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
293 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
294 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
295 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
296 + args->noaction = ARGS_DEFAULT_NOACTION;
297 + args->nodeps = ARGS_DEFAULT_NODEPS;
298 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
299 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
300 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
301 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
302 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
303 + args->multiple_providers = 0;
304 + args->nocheckfordirorfile = 0;
305 +
306 + return 1;
307 +}
308 +
309 +void args_deinit(args_t *args)
310 +{
311 + free(args->conf_file);
312 + args->conf_file = NULL;
313 +}
314 +
315 +int args_parse(args_t *args, int argc, char *argv[])
316 +{
317 + int c;
318 + int option_index = 0;
319 + int parse_err = 0;
320 + static struct option long_options[] = {
321 + {"query-all", 0, 0, 'A'},
322 + {"conf-file", 1, 0, 'f'},
323 + {"conf", 1, 0, 'f'},
324 + {"dest", 1, 0, 'd'},
325 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
326 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
327 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
328 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
329 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
330 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
331 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
332 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
333 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
334 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
335 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
336 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
337 + {"recursive", 0, 0,
338 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
339 + {"force-removal-of-dependent-packages", 0, 0,
340 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
341 + {"force_removal_of_dependent_packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
343 + {"force-removal-of-essential-packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"force_removal_of_essential_packages", 0, 0,
346 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
347 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
348 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
349 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
350 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
351 + {"offline", 1, 0, 'o'},
352 + {"offline-root", 1, 0, 'o'},
353 + {"test", 0, 0, ARGS_OPT_NOACTION},
354 + {"tmp-dir", 1, 0, 't'},
355 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
356 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
357 + {"verbosity", 2, 0, 'V'},
358 + {"version", 0, 0, 'v'},
359 + {0, 0, 0, 0}
360 + };
361 +
362 + while (1) {
363 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
364 + if (c == -1)
365 + break;
366 +
367 + switch (c) {
368 + case 'A':
369 + args->query_all = 1;
370 + break;
371 + case 'd':
372 + args->dest = optarg;
373 + break;
374 + case 'f':
375 + free(args->conf_file);
376 + args->conf_file = strdup(optarg);
377 + break;
378 + case 'o':
379 + args->offline_root = optarg;
380 + break;
381 + case 'n':
382 + args->noaction = 1;
383 + break;
384 + case 't':
385 + args->tmp_dir = strdup(optarg);
386 + break;
387 + case 'v':
388 + print_version();
389 + exit(0);
390 + case 'V':
391 + case ARGS_OPT_VERBOSITY:
392 + if (optarg)
393 + args->verbosity = atoi(optarg);
394 + else
395 + args->verbosity += 1;
396 + break;
397 + case ARGS_OPT_FORCE_DEFAULTS:
398 + args->force_defaults = 1;
399 + break;
400 + case ARGS_OPT_FORCE_DEPENDS:
401 + args->force_depends = 1;
402 + break;
403 + case ARGS_OPT_FORCE_OVERWRITE:
404 + args->force_overwrite = 1;
405 + break;
406 + case ARGS_OPT_FORCE_DOWNGRADE:
407 + args->force_downgrade = 1;
408 + break;
409 + case ARGS_OPT_FORCE_REINSTALL:
410 + args->force_reinstall = 1;
411 + break;
412 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
413 + args->force_removal_of_essential_packages = 1;
414 + break;
415 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
416 + args->force_removal_of_dependent_packages = 1;
417 + break;
418 + case ARGS_OPT_FORCE_SPACE:
419 + args->force_space = 1;
420 + break;
421 + case ARGS_OPT_VERBOSE_WGET:
422 + args->verbose_wget = 1;
423 + break;
424 + case ARGS_OPT_MULTIPLE_PROVIDERS:
425 + args->multiple_providers = 1;
426 + break;
427 + case ARGS_OPT_NODEPS:
428 + args->nodeps = 1;
429 + break;
430 + case ARGS_OPT_NOACTION:
431 + args->noaction = 1;
432 + break;
433 + case ':':
434 + parse_err++;
435 + break;
436 + case '?':
437 + parse_err++;
438 + break;
439 + default:
440 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
441 + }
442 + }
443 +
444 + if (parse_err) {
445 + return -parse_err;
446 + } else {
447 + return optind;
448 + }
449 +}
450 +
451 +void args_usage(char *complaint)
452 +{
453 + if (complaint) {
454 + bb_error_msg("%s\n", complaint);
455 + }
456 + print_version();
457 + bb_show_usage();
458 + exit(1);
459 +}
460 +
461 +static void print_version(void)
462 +{
463 + bb_error_msg("version %s\n", IPKG_VERSION);
464 +}
465 diff -ruN busybox-1.1.1-old/archival/libipkg/args.h busybox-1.1.1-new/archival/libipkg/args.h
466 --- busybox-1.1.1-old/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
467 +++ busybox-1.1.1-new/archival/libipkg/args.h 2006-03-30 00:39:48.000000000 +0200
468 @@ -0,0 +1,71 @@
469 +/* args.h - parse command-line args
470 +
471 + Carl D. Worth
472 +
473 + Copyright 2001 University of Southern California
474 +
475 + This program is free software; you can redistribute it and/or modify
476 + it under the terms of the GNU General Public License as published by
477 + the Free Software Foundation; either version 2, or (at your option)
478 + any later version.
479 +
480 + This program is distributed in the hope that it will be useful,
481 + but WITHOUT ANY WARRANTY; without even the implied warranty of
482 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
483 + GNU General Public License for more details.
484 +*/
485 +
486 +#ifndef ARGS_H
487 +#define ARGS_H
488 +
489 +struct args
490 +{
491 + char *conf_file;
492 + char *dest;
493 + char *tmp_dir;
494 + int force_defaults;
495 + int force_depends;
496 + int force_overwrite;
497 + int force_downgrade;
498 + int force_reinstall;
499 + int force_removal_of_essential_packages;
500 + int force_removal_of_dependent_packages;
501 + int force_space;
502 + int noaction;
503 + int nodeps;
504 + int multiple_providers;
505 + int query_all;
506 + int verbose_wget;
507 + int verbosity;
508 + int nocheckfordirorfile;
509 + char *offline_root;
510 + char *offline_root_pre_script_cmd;
511 + char *offline_root_post_script_cmd;
512 +};
513 +typedef struct args args_t;
514 +
515 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
516 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
517 +#define ARGS_DEFAULT_DEST NULL
518 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
519 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
520 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
521 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
522 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
523 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
524 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
525 +#define ARGS_DEFAULT_FORCE_SPACE 0
526 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
527 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
528 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
529 +#define ARGS_DEFAULT_NOACTION 0
530 +#define ARGS_DEFAULT_NODEPS 0
531 +#define ARGS_DEFAULT_VERBOSE_WGET 0
532 +#define ARGS_DEFAULT_VERBOSITY 1
533 +
534 +int args_init(args_t *args);
535 +void args_deinit(args_t *args);
536 +int args_parse(args_t *args, int argc, char *argv[]);
537 +void args_usage(char *complaint);
538 +
539 +#endif
540 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.c busybox-1.1.1-new/archival/libipkg/conffile.c
541 --- busybox-1.1.1-old/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
542 +++ busybox-1.1.1-new/archival/libipkg/conffile.c 2006-03-30 00:39:48.000000000 +0200
543 @@ -0,0 +1,64 @@
544 +/* conffile.c - the itsy package management system
545 +
546 + Carl D. Worth
547 +
548 + Copyright (C) 2001 University of Southern California
549 +
550 + This program is free software; you can redistribute it and/or
551 + modify it under the terms of the GNU General Public License as
552 + published by the Free Software Foundation; either version 2, or (at
553 + your option) any later version.
554 +
555 + This program is distributed in the hope that it will be useful, but
556 + WITHOUT ANY WARRANTY; without even the implied warranty of
557 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
558 + General Public License for more details.
559 +*/
560 +
561 +#include <string.h>
562 +#include <stdlib.h>
563 +
564 +#include "ipkg.h"
565 +#include "ipkg_message.h"
566 +
567 +#include "conffile.h"
568 +#include "file_util.h"
569 +#include "sprintf_alloc.h"
570 +
571 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
572 +{
573 + return nv_pair_init(conffile, file_name, md5sum);
574 +}
575 +
576 +void conffile_deinit(conffile_t *conffile)
577 +{
578 + nv_pair_deinit(conffile);
579 +}
580 +
581 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
582 +{
583 + char *md5sum;
584 + char *filename = conffile->name;
585 + char *root_filename;
586 + int ret;
587 +
588 + if (conffile->value == NULL) {
589 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
590 + return 1;
591 + }
592 +
593 + root_filename = root_filename_alloc(conf, filename);
594 +
595 + md5sum = file_md5sum_alloc(root_filename);
596 +
597 + ret = strcmp(md5sum, conffile->value);
598 + if (ret) {
599 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
600 + conffile->name, md5sum, conffile->value);
601 + }
602 +
603 + free(root_filename);
604 + free(md5sum);
605 +
606 + return ret;
607 +}
608 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.h busybox-1.1.1-new/archival/libipkg/conffile.h
609 --- busybox-1.1.1-old/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
610 +++ busybox-1.1.1-new/archival/libipkg/conffile.h 2006-03-30 00:39:48.000000000 +0200
611 @@ -0,0 +1,30 @@
612 +/* conffile.h - the itsy package management system
613 +
614 + Carl D. Worth
615 +
616 + Copyright (C) 2001 University of Southern California
617 +
618 + This program is free software; you can redistribute it and/or
619 + modify it under the terms of the GNU General Public License as
620 + published by the Free Software Foundation; either version 2, or (at
621 + your option) any later version.
622 +
623 + This program is distributed in the hope that it will be useful, but
624 + WITHOUT ANY WARRANTY; without even the implied warranty of
625 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
626 + General Public License for more details.
627 +*/
628 +
629 +#ifndef CONFFILE_H
630 +#define CONFFILE_H
631 +
632 +#include "nv_pair.h"
633 +
634 +typedef struct nv_pair conffile_t;
635 +
636 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
637 +void conffile_deinit(conffile_t *conffile);
638 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
639 +
640 +#endif
641 +
642 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.c busybox-1.1.1-new/archival/libipkg/conffile_list.c
643 --- busybox-1.1.1-old/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
644 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.c 2006-03-30 00:39:48.000000000 +0200
645 @@ -0,0 +1,47 @@
646 +/* conffile_list.c - the itsy package management system
647 +
648 + Carl D. Worth
649 +
650 + Copyright (C) 2001 University of Southern California
651 +
652 + This program is free software; you can redistribute it and/or
653 + modify it under the terms of the GNU General Public License as
654 + published by the Free Software Foundation; either version 2, or (at
655 + your option) any later version.
656 +
657 + This program is distributed in the hope that it will be useful, but
658 + WITHOUT ANY WARRANTY; without even the implied warranty of
659 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
660 + General Public License for more details.
661 +*/
662 +
663 +#include "ipkg.h"
664 +
665 +#include "conffile_list.h"
666 +
667 +int conffile_list_init(conffile_list_t *list)
668 +{
669 + return nv_pair_list_init(list);
670 +}
671 +
672 +void conffile_list_deinit(conffile_list_t *list)
673 +{
674 + nv_pair_list_deinit(list);
675 +}
676 +
677 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
678 + const char *md5sum)
679 +{
680 + return nv_pair_list_append(list, file_name, md5sum);
681 +}
682 +
683 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
684 +{
685 + return nv_pair_list_push(list, data);
686 +}
687 +
688 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
689 +{
690 + return nv_pair_list_pop(list);
691 +}
692 +
693 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.h busybox-1.1.1-new/archival/libipkg/conffile_list.h
694 --- busybox-1.1.1-old/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
695 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.h 2006-03-30 00:39:48.000000000 +0200
696 @@ -0,0 +1,36 @@
697 +/* conffile_list.h - the itsy package management system
698 +
699 + Carl D. Worth
700 +
701 + Copyright (C) 2001 University of Southern California
702 +
703 + This program is free software; you can redistribute it and/or
704 + modify it under the terms of the GNU General Public License as
705 + published by the Free Software Foundation; either version 2, or (at
706 + your option) any later version.
707 +
708 + This program is distributed in the hope that it will be useful, but
709 + WITHOUT ANY WARRANTY; without even the implied warranty of
710 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
711 + General Public License for more details.
712 +*/
713 +
714 +#ifndef CONFFILE_LIST_H
715 +#define CONFFILE_LIST_H
716 +
717 +#include "conffile.h"
718 +#include "nv_pair_list.h"
719 +
720 +typedef struct nv_pair_list_elt conffile_list_elt_t;
721 +typedef struct nv_pair_list conffile_list_t;
722 +
723 +int conffile_list_init(conffile_list_t *list);
724 +void conffile_list_deinit(conffile_list_t *list);
725 +
726 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
727 + const char *root_dir);
728 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
729 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
730 +
731 +#endif
732 +
733 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.c busybox-1.1.1-new/archival/libipkg/file_util.c
734 --- busybox-1.1.1-old/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
735 +++ busybox-1.1.1-new/archival/libipkg/file_util.c 2006-03-30 00:39:48.000000000 +0200
736 @@ -0,0 +1,177 @@
737 +/* file_util.c - convenience routines for common stat operations
738 +
739 + Carl D. Worth
740 +
741 + Copyright (C) 2001 University of Southern California
742 +
743 + This program is free software; you can redistribute it and/or
744 + modify it under the terms of the GNU General Public License as
745 + published by the Free Software Foundation; either version 2, or (at
746 + your option) any later version.
747 +
748 + This program is distributed in the hope that it will be useful, but
749 + WITHOUT ANY WARRANTY; without even the implied warranty of
750 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
751 + General Public License for more details.
752 +*/
753 +
754 +#include "ipkg.h"
755 +#include <sys/types.h>
756 +#include <sys/stat.h>
757 +
758 +#include "sprintf_alloc.h"
759 +#include "file_util.h"
760 +#include "md5.h"
761 +#include "libbb.h"
762 +#undef strlen
763 +
764 +int file_exists(const char *file_name)
765 +{
766 + int err;
767 + struct stat stat_buf;
768 +
769 + err = stat(file_name, &stat_buf);
770 + if (err == 0) {
771 + return 1;
772 + } else {
773 + return 0;
774 + }
775 +}
776 +
777 +int file_is_dir(const char *file_name)
778 +{
779 + int err;
780 + struct stat stat_buf;
781 +
782 + err = stat(file_name, &stat_buf);
783 + if (err) {
784 + return 0;
785 + }
786 +
787 + return S_ISDIR(stat_buf.st_mode);
788 +}
789 +
790 +/* read a single line from a file, stopping at a newline or EOF.
791 + If a newline is read, it will appear in the resulting string.
792 + Return value is a malloc'ed char * which should be freed at
793 + some point by the caller.
794 +
795 + Return value is NULL if the file is at EOF when called.
796 +*/
797 +#define FILE_READ_LINE_BUF_SIZE 1024
798 +char *file_read_line_alloc(FILE *file)
799 +{
800 + char buf[FILE_READ_LINE_BUF_SIZE];
801 + int buf_len;
802 + char *line = NULL;
803 + int line_size = 0;
804 +
805 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
806 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
807 + buf_len = strlen(buf);
808 + if (line) {
809 + line_size += buf_len;
810 + line = realloc(line, line_size);
811 + if (line == NULL) {
812 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
813 + break;
814 + }
815 + strcat(line, buf);
816 + } else {
817 + line_size = buf_len + 1;
818 + line = strdup(buf);
819 + }
820 + if (buf[buf_len - 1] == '\n') {
821 + break;
822 + }
823 + }
824 +
825 + return line;
826 +}
827 +
828 +int file_move(const char *src, const char *dest)
829 +{
830 + int err;
831 +
832 + err = rename(src, dest);
833 +
834 + if (err && errno == EXDEV) {
835 + err = file_copy(src, dest);
836 + unlink(src);
837 + } else if (err) {
838 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
839 + __FUNCTION__, src, dest, strerror(errno));
840 + }
841 +
842 + return err;
843 +}
844 +
845 +/* I put these here to keep libbb dependencies from creeping all over
846 + the ipkg code */
847 +int file_copy(const char *src, const char *dest)
848 +{
849 + int err;
850 +
851 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
852 + if (err) {
853 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
854 + __FUNCTION__, src, dest);
855 + }
856 +
857 + return err;
858 +}
859 +
860 +int file_mkdir_hier(const char *path, long mode)
861 +{
862 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
863 +}
864 +
865 +char *file_md5sum_alloc(const char *file_name)
866 +{
867 + static const int md5sum_bin_len = 16;
868 + static const int md5sum_hex_len = 32;
869 +
870 + static const unsigned char bin2hex[16] = {
871 + '0', '1', '2', '3',
872 + '4', '5', '6', '7',
873 + '8', '9', 'a', 'b',
874 + 'c', 'd', 'e', 'f'
875 + };
876 +
877 + int i, err;
878 + FILE *file;
879 + unsigned char *md5sum_hex;
880 + unsigned char md5sum_bin[md5sum_bin_len];
881 +
882 + md5sum_hex = malloc(md5sum_hex_len + 1);
883 + if (md5sum_hex == NULL) {
884 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
885 + return strdup("");
886 + }
887 +
888 + file = fopen(file_name, "r");
889 + if (file == NULL) {
890 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
891 + __FUNCTION__, file_name, strerror(errno));
892 + return strdup("");
893 + }
894 +
895 + err = md5_stream(file, md5sum_bin);
896 + if (err) {
897 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
898 + __FUNCTION__, file_name, strerror(err));
899 + return strdup("");
900 + }
901 +
902 + fclose(file);
903 +
904 + for (i=0; i < md5sum_bin_len; i++) {
905 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
906 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
907 + }
908 +
909 + md5sum_hex[md5sum_hex_len] = '\0';
910 +
911 + return md5sum_hex;
912 +}
913 +
914 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.h busybox-1.1.1-new/archival/libipkg/file_util.h
915 --- busybox-1.1.1-old/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
916 +++ busybox-1.1.1-new/archival/libipkg/file_util.h 2006-03-30 00:39:48.000000000 +0200
917 @@ -0,0 +1,29 @@
918 +/* file_util.h - convenience routines for common file operations
919 +
920 + Carl D. Worth
921 +
922 + Copyright (C) 2001 University of Southern California
923 +
924 + This program is free software; you can redistribute it and/or
925 + modify it under the terms of the GNU General Public License as
926 + published by the Free Software Foundation; either version 2, or (at
927 + your option) any later version.
928 +
929 + This program is distributed in the hope that it will be useful, but
930 + WITHOUT ANY WARRANTY; without even the implied warranty of
931 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
932 + General Public License for more details.
933 +*/
934 +
935 +#ifndef FILE_UTIL_H
936 +#define FILE_UTIL_H
937 +
938 +int file_exists(const char *file_name);
939 +int file_is_dir(const char *file_name);
940 +char *file_read_line_alloc(FILE *file);
941 +int file_move(const char *src, const char *dest);
942 +int file_copy(const char *src, const char *dest);
943 +int file_mkdir_hier(const char *path, long mode);
944 +char *file_md5sum_alloc(const char *file_name);
945 +
946 +#endif
947 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.c busybox-1.1.1-new/archival/libipkg/hash_table.c
948 --- busybox-1.1.1-old/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
949 +++ busybox-1.1.1-new/archival/libipkg/hash_table.c 2006-03-30 00:39:48.000000000 +0200
950 @@ -0,0 +1,155 @@
951 +/* hash.c - hash tables for ipkg
952 +
953 + Steven M. Ayer, Jamey Hicks
954 +
955 + Copyright (C) 2002 Compaq Computer Corporation
956 +
957 + This program is free software; you can redistribute it and/or
958 + modify it under the terms of the GNU General Public License as
959 + published by the Free Software Foundation; either version 2, or (at
960 + your option) any later version.
961 +
962 + This program is distributed in the hope that it will be useful, but
963 + WITHOUT ANY WARRANTY; without even the implied warranty of
964 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
965 + General Public License for more details.
966 +*/
967 +
968 +#include <errno.h>
969 +#include <stdio.h>
970 +#include <stdlib.h>
971 +#include <string.h>
972 +#include "hash_table.h"
973 +#include "ipkg_message.h"
974 +
975 +
976 +static int hash_index(hash_table_t *hash, const char *pkg_name);
977 +static int rotating(const char *key, int len, int prime);
978 +
979 +static int hash_index(hash_table_t *hash, const char *pkg_name)
980 +{
981 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
982 +}
983 +
984 +static int rotating(const char *key, int len, int prime)
985 +{
986 + unsigned int hash, i;
987 + for (hash=len, i=0; i<len; ++i)
988 + hash = (hash<<4)^(hash>>28)^key[i];
989 + return (hash % prime);
990 +}
991 +
992 +
993 +/*
994 + * this is an open table keyed by strings
995 + */
996 +int hash_table_init(const char *name, hash_table_t *hash, int len)
997 +{
998 + static int primes_table[] = {
999 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
1000 + 19471, 23143, 33961, 46499, 49727, 99529, 0
1001 + };
1002 + int *picker;
1003 +
1004 + if (hash->entries != NULL) {
1005 + /* we have been here already */
1006 + return 0;
1007 + }
1008 +
1009 + hash->name = name;
1010 + hash->entries = NULL;
1011 + hash->n_entries = 0;
1012 + hash->hash_entry_key = NULL;
1013 +
1014 + picker = primes_table;
1015 + while(*picker && (*picker++ < len));
1016 + if(!*picker)
1017 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1018 + --picker;
1019 +
1020 + hash->n_entries = *picker;
1021 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1022 + if (hash->entries == NULL) {
1023 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1024 + return ENOMEM;
1025 + }
1026 + return 0;
1027 +}
1028 +
1029 +void hash_table_deinit(hash_table_t *hash)
1030 +{
1031 + free(hash->entries);
1032 + hash->entries = NULL;
1033 + hash->n_entries = 0;
1034 +}
1035 +
1036 +void *hash_table_get(hash_table_t *hash, const char *key)
1037 +{
1038 + int ndx= hash_index(hash, key);
1039 + hash_entry_t *hash_entry = hash->entries + ndx;
1040 + while (hash_entry)
1041 + {
1042 + if (hash_entry->key)
1043 + {
1044 + if (strcmp(key, hash_entry->key) == 0) {
1045 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1046 + return hash_entry->data;
1047 + }
1048 + }
1049 + hash_entry = hash_entry->next;
1050 + }
1051 + return NULL;
1052 +}
1053 +
1054 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1055 +{
1056 + int ndx= hash_index(hash, key);
1057 + hash_entry_t *hash_entry = hash->entries + ndx;
1058 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1059 + if (hash_entry->key) {
1060 + if (strcmp(hash_entry->key, key) == 0) {
1061 + /* alread in table, update the value */
1062 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1063 + hash_entry->data = value;
1064 + return 0;
1065 + } else {
1066 + /*
1067 + * if this is a collision, we have to go to the end of the ll,
1068 + * then add a new entry
1069 + * before we can hook up the value
1070 + */
1071 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1072 + while (hash_entry->next)
1073 + hash_entry = hash_entry->next;
1074 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1075 + if (!hash_entry->next) {
1076 + return -ENOMEM;
1077 + }
1078 + hash_entry = hash_entry->next;
1079 + hash_entry->next = NULL;
1080 + }
1081 + }
1082 + hash->n_elements++;
1083 + hash_entry->key = strdup(key);
1084 + hash_entry->data = value;
1085 +
1086 + return 0;
1087 +}
1088 +
1089 +
1090 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1091 +{
1092 + int i;
1093 + if (!hash || !f)
1094 + return;
1095 +
1096 + for (i = 0; i < hash->n_entries; i++) {
1097 + hash_entry_t *hash_entry = (hash->entries + i);
1098 + do {
1099 + if(hash_entry->key) {
1100 + f(hash_entry->key, hash_entry->data, data);
1101 + }
1102 + } while((hash_entry = hash_entry->next));
1103 + }
1104 +}
1105 +
1106 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.h busybox-1.1.1-new/archival/libipkg/hash_table.h
1107 --- busybox-1.1.1-old/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1108 +++ busybox-1.1.1-new/archival/libipkg/hash_table.h 2006-03-30 00:39:48.000000000 +0200
1109 @@ -0,0 +1,44 @@
1110 +/* hash.h - hash tables for ipkg
1111 +
1112 + Steven M. Ayer, Jamey Hicks
1113 +
1114 + Copyright (C) 2002 Compaq Computer Corporation
1115 +
1116 + This program is free software; you can redistribute it and/or
1117 + modify it under the terms of the GNU General Public License as
1118 + published by the Free Software Foundation; either version 2, or (at
1119 + your option) any later version.
1120 +
1121 + This program is distributed in the hope that it will be useful, but
1122 + WITHOUT ANY WARRANTY; without even the implied warranty of
1123 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1124 + General Public License for more details.
1125 +*/
1126 +
1127 +#ifndef _HASH_TABLE_H_
1128 +#define _HASH_TABLE_H_
1129 +
1130 +typedef struct hash_entry hash_entry_t;
1131 +typedef struct hash_table hash_table_t;
1132 +
1133 +struct hash_entry {
1134 + const char * key;
1135 + void * data;
1136 + struct hash_entry * next;
1137 +};
1138 +
1139 +struct hash_table {
1140 + const char *name;
1141 + hash_entry_t * entries;
1142 + int n_entries; /* number of buckets */
1143 + int n_elements;
1144 + const char * (*hash_entry_key)(void * data);
1145 +};
1146 +
1147 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1148 +void hash_table_deinit(hash_table_t *hash);
1149 +void *hash_table_get(hash_table_t *hash, const char *key);
1150 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1151 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1152 +
1153 +#endif /* _HASH_TABLE_H_ */
1154 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg.h busybox-1.1.1-new/archival/libipkg/ipkg.h
1155 --- busybox-1.1.1-old/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1156 +++ busybox-1.1.1-new/archival/libipkg/ipkg.h 2006-03-30 00:39:48.000000000 +0200
1157 @@ -0,0 +1,74 @@
1158 +/* ipkg.h - the itsy package management system
1159 +
1160 + Carl D. Worth
1161 +
1162 + Copyright (C) 2001 University of Southern California
1163 +
1164 + This program is free software; you can redistribute it and/or
1165 + modify it under the terms of the GNU General Public License as
1166 + published by the Free Software Foundation; either version 2, or (at
1167 + your option) any later version.
1168 +
1169 + This program is distributed in the hope that it will be useful, but
1170 + WITHOUT ANY WARRANTY; without even the implied warranty of
1171 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1172 + General Public License for more details.
1173 +*/
1174 +
1175 +#ifndef IPKG_H
1176 +#define IPKG_H
1177 +
1178 +/*
1179 +#ifdef HAVE_CONFIG_H
1180 +#include "config.h"
1181 +#endif
1182 +*/
1183 +
1184 +#if 0
1185 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1186 +#endif
1187 +
1188 +#include "ipkg_includes.h"
1189 +#include "ipkg_conf.h"
1190 +#include "ipkg_message.h"
1191 +
1192 +#define IPKG_PKG_EXTENSION ".ipk"
1193 +#define DPKG_PKG_EXTENSION ".deb"
1194 +
1195 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1196 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1197 +
1198 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1199 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1200 +#define IPKG_INFO_DIR_SUFFIX "info"
1201 +#define IPKG_STATUS_FILE_SUFFIX "status"
1202 +
1203 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1204 +
1205 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1206 +
1207 +#define IPKG_VERSION "0.99.154"
1208 +
1209 +
1210 +enum ipkg_error {
1211 + IPKG_SUCCESS = 0,
1212 + IPKG_PKG_DEPS_UNSATISFIED,
1213 + IPKG_PKG_IS_ESSENTIAL,
1214 + IPKG_PKG_HAS_DEPENDENTS,
1215 + IPKG_PKG_HAS_NO_CANDIDATE
1216 +};
1217 +typedef enum ipkg_error ipkg_error_t;
1218 +
1219 +extern int ipkg_state_changed;
1220 +
1221 +
1222 +struct errlist {
1223 + char * errmsg;
1224 + struct errlist * next;
1225 +} ;
1226 +
1227 +extern struct errlist* error_list;
1228 +
1229 +extern ipkg_conf_t *global_conf;
1230 +
1231 +#endif
1232 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c
1233 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1234 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c 2006-03-30 00:39:48.000000000 +0200
1235 @@ -0,0 +1,1344 @@
1236 +/* ipkg_cmd.c - the itsy package management system
1237 +
1238 + Carl D. Worth
1239 +
1240 + Copyright (C) 2001 University of Southern California
1241 +
1242 + This program is free software; you can redistribute it and/or
1243 + modify it under the terms of the GNU General Public License as
1244 + published by the Free Software Foundation; either version 2, or (at
1245 + your option) any later version.
1246 +
1247 + This program is distributed in the hope that it will be useful, but
1248 + WITHOUT ANY WARRANTY; without even the implied warranty of
1249 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1250 + General Public License for more details.
1251 +*/
1252 +
1253 +#include <string.h>
1254 +
1255 +#include "ipkg.h"
1256 +#include <libgen.h>
1257 +#include <glob.h>
1258 +#include <errno.h>
1259 +#include <stdlib.h>
1260 +#include <unistd.h>
1261 +#include <signal.h>
1262 +#include <stdio.h>
1263 +
1264 +#include "ipkg_conf.h"
1265 +#include "ipkg_cmd.h"
1266 +#include "ipkg_message.h"
1267 +#include "pkg.h"
1268 +#include "pkg_dest.h"
1269 +#include "pkg_parse.h"
1270 +#include "sprintf_alloc.h"
1271 +#include "pkg.h"
1272 +#include "file_util.h"
1273 +#include "str_util.h"
1274 +#include "libbb.h"
1275 +#include "unarchive.h"
1276 +
1277 +#include <fnmatch.h>
1278 +
1279 +
1280 +#include "ipkg_download.h"
1281 +#include "ipkg_install.h"
1282 +#include "ipkg_upgrade.h"
1283 +#include "ipkg_remove.h"
1284 +#include "ipkg_configure.h"
1285 +#include "ipkg_message.h"
1286 +
1287 +#ifdef IPKG_LIB
1288 +#include "libipkg.h"
1289 +static void *p_userdata = NULL;
1290 +#endif
1291 +
1292 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1316 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1317 +
1318 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1319 + array for easier maintenance */
1320 +static ipkg_cmd_t cmds[] = {
1321 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1322 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1323 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1324 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1325 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1326 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1327 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1328 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1329 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1330 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1331 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1332 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1333 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1334 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1335 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1336 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1337 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1338 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1341 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1342 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1343 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1344 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1345 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1346 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1347 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1348 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1349 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1350 +};
1351 +
1352 +int ipkg_state_changed;
1353 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1354 +{
1355 + if (ipkg_state_changed && !conf->noaction) {
1356 + ipkg_message(conf, IPKG_INFO,
1357 + " writing status file\n");
1358 + ipkg_conf_write_status_files(conf);
1359 + pkg_write_changed_filelists(conf);
1360 + } else {
1361 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1362 + }
1363 +}
1364 +
1365 +
1366 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1367 +
1368 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1369 +{
1370 + int i;
1371 + ipkg_cmd_t *cmd;
1372 +
1373 + for (i=0; i < num_cmds; i++) {
1374 + cmd = &cmds[i];
1375 + if (strcmp(name, cmd->name) == 0) {
1376 + return cmd;
1377 + }
1378 + }
1379 +
1380 + return NULL;
1381 +}
1382 +
1383 +#ifdef IPKG_LIB
1384 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1385 +{
1386 + int result;
1387 + p_userdata = userdata;
1388 +
1389 +
1390 + result = (cmd->fun)(conf, argc, argv);
1391 + if ( result == 0 ) {
1392 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1393 + } else {
1394 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1395 +
1396 + }
1397 + if ( error_list ) {
1398 + reverse_error_list(&error_list);
1399 +
1400 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1401 + /* Here we print the errors collected and free the list */
1402 + while (error_list != NULL) {
1403 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1404 + error_list = error_list->next;
1405 +
1406 + }
1407 + free_error_list(&error_list);
1408 +
1409 + }
1410 +
1411 + p_userdata = NULL;
1412 + return result;
1413 +}
1414 +#else
1415 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1416 +{
1417 + return (cmd->fun)(conf, argc, argv);
1418 +}
1419 +#endif
1420 +
1421 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1422 +{
1423 + int err;
1424 + int failures;
1425 + char *lists_dir;
1426 + pkg_src_list_elt_t *iter;
1427 + pkg_src_t *src;
1428 +
1429 +
1430 + if (conf->offline_root) {
1431 + sprintf_alloc(&lists_dir, "%s/%s",
1432 + conf->offline_root,
1433 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1434 + } else {
1435 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1436 + }
1437 +
1438 + if (! file_is_dir(lists_dir)) {
1439 + if (file_exists(lists_dir)) {
1440 + ipkg_message(conf, IPKG_ERROR,
1441 + "%s: ERROR: %s exists, but is not a directory\n",
1442 + __FUNCTION__, lists_dir);
1443 + free(lists_dir);
1444 + return EINVAL;
1445 + }
1446 + err = file_mkdir_hier(lists_dir, 0755);
1447 + if (err) {
1448 + ipkg_message(conf, IPKG_ERROR,
1449 + "%s: ERROR: failed to make directory %s: %s\n",
1450 + __FUNCTION__, lists_dir, strerror(errno));
1451 + free(lists_dir);
1452 + return EINVAL;
1453 + }
1454 + }
1455 +
1456 + failures = 0;
1457 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1458 + char *url, *list_file_name;
1459 +
1460 + src = iter->data;
1461 +
1462 + if (src->extra_data) /* debian style? */
1463 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1464 + src->gzip ? "Packages.gz" : "Packages");
1465 + else
1466 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1467 +
1468 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1469 + if (src->gzip) {
1470 + char *tmp;
1471 + char *tmp_file_name;
1472 + FILE *in, *out;
1473 +
1474 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1475 +
1476 + if (mkdtemp (tmp) == NULL) {
1477 + perror ("mkdtemp");
1478 + failures++;
1479 + continue;
1480 + }
1481 +
1482 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1483 + err = ipkg_download(conf, url, tmp_file_name);
1484 + if (err == 0) {
1485 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1486 + in = fopen (tmp_file_name, "r");
1487 + out = fopen (list_file_name, "w");
1488 + if (in && out)
1489 + inflate_unzip (in, out);
1490 + else
1491 + err = 1;
1492 + if (in)
1493 + fclose (in);
1494 + if (out)
1495 + fclose (out);
1496 + unlink (tmp_file_name);
1497 + rmdir (tmp);
1498 + free (tmp);
1499 + }
1500 + } else
1501 + err = ipkg_download(conf, url, list_file_name);
1502 + if (err) {
1503 + failures++;
1504 + } else {
1505 + ipkg_message(conf, IPKG_NOTICE,
1506 + "Updated list of available packages in %s\n",
1507 + list_file_name);
1508 + }
1509 + free(url);
1510 + free(list_file_name);
1511 + }
1512 + free(lists_dir);
1513 +
1514 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1515 +#warning here
1516 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1517 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1518 + * -Jamey 3/1/03
1519 + */
1520 + {
1521 + int i;
1522 + int changed = 0;
1523 + pkg_vec_t *available = pkg_vec_alloc();
1524 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1525 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1526 + for (i = 0; i < available->len; i++) {
1527 + pkg_t *pkg = available->pkgs[i];
1528 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1529 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1530 + pkg->state_want = SW_UNKNOWN;
1531 + changed = 1;
1532 + }
1533 + }
1534 + pkg_vec_free(available);
1535 + if (changed) {
1536 + write_status_files_if_changed(conf);
1537 + }
1538 + }
1539 +#endif
1540 +
1541 + return failures;
1542 +}
1543 +
1544 +
1545 +/* scan the args passed and cache the local filenames of the packages */
1546 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1547 +{
1548 + int i;
1549 + int err;
1550 +
1551 + /*
1552 + * First scan through package names/urls
1553 + * For any urls, download the packages and install in database.
1554 + * For any files, install package info in database.
1555 + */
1556 + for (i = 0; i < argc; i ++) {
1557 + char *filename = argv [i];
1558 + //char *tmp = basename (tmp);
1559 + //int tmplen = strlen (tmp);
1560 +
1561 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1562 + // continue;
1563 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1564 + // continue;
1565 +
1566 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1567 + if (err)
1568 + return err;
1569 + }
1570 + return 0;
1571 +}
1572 +
1573 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1574 +{
1575 + pkg_vec_t *all;
1576 + int i;
1577 + pkg_t *pkg;
1578 +
1579 + ipkg_message(conf, IPKG_INFO,
1580 + "Configuring unpacked packages\n");
1581 + fflush( stdout );
1582 +
1583 + all = pkg_vec_alloc();
1584 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1585 +
1586 + for(i = 0; i < all->len; i++) {
1587 + pkg = all->pkgs[i];
1588 +
1589 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1590 + continue;
1591 +
1592 + if (pkg->state_status == SS_UNPACKED) {
1593 + ipkg_message(conf, IPKG_NOTICE,
1594 + "Configuring %s\n", pkg->name);
1595 + fflush( stdout );
1596 + if (ipkg_configure(conf, pkg) == 0) {
1597 + pkg->state_status = SS_INSTALLED;
1598 + pkg->parent->state_status = SS_INSTALLED;
1599 + pkg->state_flag &= ~SF_PREFER;
1600 + }
1601 + }
1602 + }
1603 +
1604 + pkg_vec_free(all);
1605 + return 0;
1606 +}
1607 +
1608 +static void sigint_handler(int sig)
1609 +{
1610 + signal(sig, SIG_DFL);
1611 + ipkg_message(NULL, IPKG_NOTICE,
1612 + "ipkg: interrupted. writing out status database\n");
1613 + write_status_files_if_changed(global_conf);
1614 + exit(128 + sig);
1615 +}
1616 +
1617 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1618 +{
1619 + int i;
1620 + char *arg;
1621 + int err=0;
1622 +
1623 + global_conf = conf;
1624 + signal(SIGINT, sigint_handler);
1625 +
1626 + /*
1627 + * Now scan through package names and install
1628 + */
1629 + for (i=0; i < argc; i++) {
1630 + arg = argv[i];
1631 +
1632 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1633 + if (err != EINVAL && err != 0)
1634 + return err;
1635 + }
1636 + pkg_info_preinstall_check(conf);
1637 +
1638 + for (i=0; i < argc; i++) {
1639 + arg = argv[i];
1640 + if (conf->multiple_providers)
1641 + err = ipkg_install_multi_by_name(conf, arg);
1642 + else{
1643 + err = ipkg_install_by_name(conf, arg);
1644 + }
1645 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1646 + ipkg_message(conf, IPKG_ERROR,
1647 + "Cannot find package %s.\n"
1648 + "Check the spelling or perhaps run 'ipkg update'\n",
1649 + arg);
1650 + }
1651 + }
1652 +
1653 + /* recheck to verify that all dependences are satisfied */
1654 + if (0) ipkg_satisfy_all_dependences(conf);
1655 +
1656 + ipkg_configure_packages(conf, NULL);
1657 +
1658 + write_status_files_if_changed(conf);
1659 +
1660 + return err;
1661 +}
1662 +
1663 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1664 +{
1665 + int i;
1666 + pkg_t *pkg;
1667 + int err;
1668 +
1669 + global_conf = conf;
1670 + signal(SIGINT, sigint_handler);
1671 +
1672 + if (argc) {
1673 + for (i=0; i < argc; i++) {
1674 + char *arg = argv[i];
1675 +
1676 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1677 + if (err != EINVAL && err != 0)
1678 + return err;
1679 + }
1680 + pkg_info_preinstall_check(conf);
1681 +
1682 + for (i=0; i < argc; i++) {
1683 + char *arg = argv[i];
1684 + if (conf->restrict_to_default_dest) {
1685 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1686 + argv[i],
1687 + conf->default_dest);
1688 + if (pkg == NULL) {
1689 + ipkg_message(conf, IPKG_NOTICE,
1690 + "Package %s not installed in %s\n",
1691 + argv[i], conf->default_dest->name);
1692 + continue;
1693 + }
1694 + } else {
1695 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1696 + argv[i]);
1697 + }
1698 + if (pkg)
1699 + ipkg_upgrade_pkg(conf, pkg);
1700 + else {
1701 + ipkg_install_by_name(conf, arg);
1702 + }
1703 + }
1704 + } else {
1705 + pkg_vec_t *installed = pkg_vec_alloc();
1706 +
1707 + pkg_info_preinstall_check(conf);
1708 +
1709 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1710 + for (i = 0; i < installed->len; i++) {
1711 + pkg = installed->pkgs[i];
1712 + ipkg_upgrade_pkg(conf, pkg);
1713 + }
1714 + pkg_vec_free(installed);
1715 + }
1716 +
1717 + /* recheck to verify that all dependences are satisfied */
1718 + if (0) ipkg_satisfy_all_dependences(conf);
1719 +
1720 + ipkg_configure_packages(conf, NULL);
1721 +
1722 + write_status_files_if_changed(conf);
1723 +
1724 + return 0;
1725 +}
1726 +
1727 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1728 +{
1729 + int i, err;
1730 + char *arg;
1731 + pkg_t *pkg;
1732 +
1733 + pkg_info_preinstall_check(conf);
1734 + for (i = 0; i < argc; i++) {
1735 + arg = argv[i];
1736 +
1737 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1738 + if (pkg == NULL) {
1739 + ipkg_message(conf, IPKG_ERROR,
1740 + "Cannot find package %s.\n"
1741 + "Check the spelling or perhaps run 'ipkg update'\n",
1742 + arg);
1743 + continue;
1744 + }
1745 +
1746 + err = ipkg_download_pkg(conf, pkg, ".");
1747 +
1748 + if (err) {
1749 + ipkg_message(conf, IPKG_ERROR,
1750 + "Failed to download %s\n", pkg->name);
1751 + } else {
1752 + ipkg_message(conf, IPKG_NOTICE,
1753 + "Downloaded %s as %s\n",
1754 + pkg->name, pkg->local_filename);
1755 + }
1756 + }
1757 +
1758 + return 0;
1759 +}
1760 +
1761 +
1762 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1763 +{
1764 + int i ;
1765 + pkg_vec_t *available;
1766 + pkg_t *pkg;
1767 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1768 + char *newline;
1769 + char *pkg_name = NULL;
1770 + char *version_str;
1771 +
1772 + if (argc > 0) {
1773 + pkg_name = argv[0];
1774 + }
1775 + available = pkg_vec_alloc();
1776 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1777 + for (i=0; i < available->len; i++) {
1778 + pkg = available->pkgs[i];
1779 + /* if we have package name or pattern and pkg does not match, then skip it */
1780 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1781 + continue;
1782 + if (pkg->description) {
1783 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1784 + } else {
1785 + desc_short[0] = '\0';
1786 + }
1787 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1788 + newline = strchr(desc_short, '\n');
1789 + if (newline) {
1790 + *newline = '\0';
1791 + }
1792 +#ifndef IPKG_LIB
1793 + printf("%s - %s\n", pkg->name, desc_short);
1794 +#else
1795 + if (ipkg_cb_list) {
1796 + version_str = pkg_version_str_alloc(pkg);
1797 + ipkg_cb_list(pkg->name,desc_short,
1798 + version_str,
1799 + pkg->state_status,
1800 + p_userdata);
1801 + free(version_str);
1802 + }
1803 +#endif
1804 + }
1805 + pkg_vec_free(available);
1806 +
1807 + return 0;
1808 +}
1809 +
1810 +
1811 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1812 +{
1813 + int i ;
1814 + pkg_vec_t *available;
1815 + pkg_t *pkg;
1816 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1817 + char *newline;
1818 + char *pkg_name = NULL;
1819 + char *version_str;
1820 +
1821 + if (argc > 0) {
1822 + pkg_name = argv[0];
1823 + }
1824 + available = pkg_vec_alloc();
1825 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1826 + for (i=0; i < available->len; i++) {
1827 + pkg = available->pkgs[i];
1828 + /* if we have package name or pattern and pkg does not match, then skip it */
1829 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1830 + continue;
1831 + if (pkg->description) {
1832 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1833 + } else {
1834 + desc_short[0] = '\0';
1835 + }
1836 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1837 + newline = strchr(desc_short, '\n');
1838 + if (newline) {
1839 + *newline = '\0';
1840 + }
1841 +#ifndef IPKG_LIB
1842 + printf("%s - %s\n", pkg->name, desc_short);
1843 +#else
1844 + if (ipkg_cb_list) {
1845 + version_str = pkg_version_str_alloc(pkg);
1846 + ipkg_cb_list(pkg->name,desc_short,
1847 + version_str,
1848 + pkg->state_status,
1849 + p_userdata);
1850 + free(version_str);
1851 + }
1852 +#endif
1853 + }
1854 +
1855 + return 0;
1856 +}
1857 +
1858 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1859 +{
1860 + int i;
1861 + pkg_vec_t *available;
1862 + pkg_t *pkg;
1863 + char *pkg_name = NULL;
1864 + char **pkg_fields = NULL;
1865 + int n_fields = 0;
1866 + char *buff ; // = (char *)malloc(1);
1867 +
1868 + if (argc > 0) {
1869 + pkg_name = argv[0];
1870 + }
1871 + if (argc > 1) {
1872 + pkg_fields = &argv[1];
1873 + n_fields = argc - 1;
1874 + }
1875 +
1876 + available = pkg_vec_alloc();
1877 + if (installed_only)
1878 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1879 + else
1880 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1881 + for (i=0; i < available->len; i++) {
1882 + pkg = available->pkgs[i];
1883 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1884 + continue;
1885 + }
1886 +#ifndef IPKG_LIB
1887 + if (n_fields) {
1888 + for (j = 0; j < n_fields; j++)
1889 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1890 + } else {
1891 + pkg_print_info(pkg, stdout);
1892 + }
1893 +#else
1894 +
1895 + buff = pkg_formatted_info(pkg);
1896 + if ( buff ) {
1897 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1898 + pkg->state_status,
1899 + buff,
1900 + p_userdata);
1901 +/*
1902 + We should not forget that actually the pointer is allocated.
1903 + We need to free it :) ( Thanks florian for seeing the error )
1904 +*/
1905 + free(buff);
1906 + }
1907 +#endif
1908 + if (conf->verbosity > 1) {
1909 + conffile_list_elt_t *iter;
1910 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1911 + conffile_t *cf = iter->data;
1912 + int modified = conffile_has_been_modified(conf, cf);
1913 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1914 + cf->name, cf->value, modified);
1915 + }
1916 + }
1917 + }
1918 +#ifndef IPKG_LIB
1919 + if (buff)
1920 + free(buff);
1921 +#endif
1922 + pkg_vec_free(available);
1923 +
1924 + return 0;
1925 +}
1926 +
1927 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1928 +{
1929 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1930 +}
1931 +
1932 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1933 +{
1934 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1935 +}
1936 +
1937 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1938 +{
1939 +
1940 + int err;
1941 + if (argc > 0) {
1942 + char *pkg_name = NULL;
1943 +
1944 + pkg_name = argv[0];
1945 +
1946 + err = ipkg_configure_packages (conf, pkg_name);
1947 +
1948 + } else {
1949 + err = ipkg_configure_packages (conf, NULL);
1950 + }
1951 +
1952 + write_status_files_if_changed(conf);
1953 +
1954 + return err;
1955 +}
1956 +
1957 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1958 +{
1959 + int i, err;
1960 + char *globpattern;
1961 + glob_t globbuf;
1962 +
1963 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1964 + err = glob(globpattern, 0, NULL, &globbuf);
1965 + free(globpattern);
1966 + if (err) {
1967 + return 0;
1968 + }
1969 +
1970 + ipkg_message(conf, IPKG_NOTICE,
1971 + "The following packages in %s will now be installed.\n",
1972 + conf->pending_dir);
1973 + for (i = 0; i < globbuf.gl_pathc; i++) {
1974 + ipkg_message(conf, IPKG_NOTICE,
1975 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1976 + }
1977 + ipkg_message(conf, IPKG_NOTICE, "\n");
1978 + for (i = 0; i < globbuf.gl_pathc; i++) {
1979 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1980 + if (err == 0) {
1981 + err = unlink(globbuf.gl_pathv[i]);
1982 + if (err) {
1983 + ipkg_message(conf, IPKG_ERROR,
1984 + "%s: ERROR: failed to unlink %s: %s\n",
1985 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1986 + return err;
1987 + }
1988 + }
1989 + }
1990 + globfree(&globbuf);
1991 +
1992 + return err;
1993 +}
1994 +
1995 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1996 +{
1997 + int i,a,done;
1998 + pkg_t *pkg;
1999 + pkg_t *pkg_to_remove;
2000 + pkg_vec_t *available;
2001 + char *pkg_name = NULL;
2002 + global_conf = conf;
2003 + signal(SIGINT, sigint_handler);
2004 +
2005 +// ENH: Add the "no pkg removed" just in case.
2006 +
2007 + done = 0;
2008 +
2009 + available = pkg_vec_alloc();
2010 + pkg_info_preinstall_check(conf);
2011 + if ( argc > 0 ) {
2012 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2013 + for (i=0; i < argc; i++) {
2014 + pkg_name = malloc(strlen(argv[i])+2);
2015 + strcpy(pkg_name,argv[i]);
2016 + for (a=0; a < available->len; a++) {
2017 + pkg = available->pkgs[a];
2018 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2019 + continue;
2020 + }
2021 + if (conf->restrict_to_default_dest) {
2022 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2023 + pkg->name,
2024 + conf->default_dest);
2025 + } else {
2026 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2027 + }
2028 +
2029 + if (pkg == NULL) {
2030 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2031 + continue;
2032 + }
2033 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2034 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2035 + continue;
2036 + }
2037 + ipkg_remove_pkg(conf, pkg_to_remove);
2038 + done = 1;
2039 + }
2040 + free (pkg_name);
2041 + }
2042 + pkg_vec_free(available);
2043 + } else {
2044 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2045 + int i;
2046 + int flagged_pkg_count = 0;
2047 + int removed;
2048 +
2049 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2050 +
2051 + for (i = 0; i < installed_pkgs->len; i++) {
2052 + pkg_t *pkg = installed_pkgs->pkgs[i];
2053 + if (pkg->state_flag & SF_USER) {
2054 + flagged_pkg_count++;
2055 + } else {
2056 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2057 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2058 + }
2059 + }
2060 + if (!flagged_pkg_count) {
2061 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2062 + "so refusing to uninstall unflagged non-leaf packages\n");
2063 + return 0;
2064 + }
2065 +
2066 + /* find packages not flagged SF_USER (i.e., installed to
2067 + * satisfy a dependence) and not having any dependents, and
2068 + * remove them */
2069 + do {
2070 + removed = 0;
2071 + for (i = 0; i < installed_pkgs->len; i++) {
2072 + pkg_t *pkg = installed_pkgs->pkgs[i];
2073 + if (!(pkg->state_flag & SF_USER)
2074 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2075 + removed++;
2076 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2077 + ipkg_remove_pkg(conf, pkg);
2078 + done = 1;
2079 + }
2080 + }
2081 + } while (removed);
2082 + pkg_vec_free(installed_pkgs);
2083 + }
2084 +
2085 + if ( done == 0 )
2086 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2087 +
2088 + write_status_files_if_changed(conf);
2089 + return 0;
2090 +}
2091 +
2092 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2093 +{
2094 + int i;
2095 + pkg_t *pkg;
2096 +
2097 + global_conf = conf;
2098 + signal(SIGINT, sigint_handler);
2099 +
2100 + pkg_info_preinstall_check(conf);
2101 +
2102 + for (i=0; i < argc; i++) {
2103 + if (conf->restrict_to_default_dest) {
2104 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2105 + argv[i],
2106 + conf->default_dest);
2107 + } else {
2108 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2109 + }
2110 +
2111 + if (pkg == NULL) {
2112 + ipkg_message(conf, IPKG_ERROR,
2113 + "Package %s is not installed.\n", argv[i]);
2114 + continue;
2115 + }
2116 + ipkg_purge_pkg(conf, pkg);
2117 + }
2118 +
2119 + write_status_files_if_changed(conf);
2120 + return 0;
2121 +}
2122 +
2123 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2124 +{
2125 + int i;
2126 + pkg_t *pkg;
2127 + const char *flags = argv[0];
2128 +
2129 + global_conf = conf;
2130 + signal(SIGINT, sigint_handler);
2131 +
2132 + for (i=1; i < argc; i++) {
2133 + if (conf->restrict_to_default_dest) {
2134 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2135 + argv[i],
2136 + conf->default_dest);
2137 + } else {
2138 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2139 + }
2140 +
2141 + if (pkg == NULL) {
2142 + ipkg_message(conf, IPKG_ERROR,
2143 + "Package %s is not installed.\n", argv[i]);
2144 + continue;
2145 + }
2146 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2147 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2148 + pkg->state_flag = pkg_state_flag_from_str(flags);
2149 + }
2150 +/* pb_ asked this feature 03292004 */
2151 +/* Actually I will use only this two, but this is an open for various status */
2152 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2153 + pkg->state_status = pkg_state_status_from_str(flags);
2154 + }
2155 + ipkg_state_changed++;
2156 + ipkg_message(conf, IPKG_NOTICE,
2157 + "Setting flags for package %s to %s\n",
2158 + pkg->name, flags);
2159 + }
2160 +
2161 + write_status_files_if_changed(conf);
2162 + return 0;
2163 +}
2164 +
2165 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2166 +{
2167 + pkg_t *pkg;
2168 + str_list_t *installed_files;
2169 + str_list_elt_t *iter;
2170 + char *pkg_version;
2171 + size_t buff_len = 8192;
2172 + size_t used_len;
2173 + char *buff ;
2174 +
2175 + buff = (char *)malloc(buff_len);
2176 + if ( buff == NULL ) {
2177 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2178 + return ENOMEM;
2179 + }
2180 +
2181 + if (argc < 1) {
2182 + return EINVAL;
2183 + }
2184 +
2185 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2186 + argv[0]);
2187 + if (pkg == NULL) {
2188 + ipkg_message(conf, IPKG_ERROR,
2189 + "Package %s not installed.\n", argv[0]);
2190 + return 0;
2191 + }
2192 +
2193 + installed_files = pkg_get_installed_files(pkg);
2194 + pkg_version = pkg_version_str_alloc(pkg);
2195 +
2196 +#ifndef IPKG_LIB
2197 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2198 + pkg->name, pkg_version, pkg->dest->name);
2199 + for (iter = installed_files->head; iter; iter = iter->next) {
2200 + puts(iter->data);
2201 + }
2202 +#else
2203 + if (buff) {
2204 + try_again:
2205 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2206 + pkg->name, pkg_version, pkg->dest->name) + 1;
2207 + if (used_len > buff_len) {
2208 + buff_len *= 2;
2209 + buff = realloc (buff, buff_len);
2210 + goto try_again;
2211 + }
2212 + for (iter = installed_files->head; iter; iter = iter->next) {
2213 + used_len += strlen (iter->data) + 1;
2214 + while (buff_len <= used_len) {
2215 + buff_len *= 2;
2216 + buff = realloc (buff, buff_len);
2217 + }
2218 + strncat(buff, iter->data, buff_len);
2219 + strncat(buff, "\n", buff_len);
2220 + }
2221 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2222 + buff,
2223 + pkg_version_str_alloc(pkg),
2224 + pkg->state_status,
2225 + p_userdata);
2226 + free(buff);
2227 + }
2228 +#endif
2229 +
2230 + free(pkg_version);
2231 + pkg_free_installed_files(pkg);
2232 +
2233 + return 0;
2234 +}
2235 +
2236 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2237 +{
2238 +
2239 + if (argc > 0) {
2240 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2241 + const char *rel_str = "depends on";
2242 + int i;
2243 +
2244 + pkg_info_preinstall_check(conf);
2245 +
2246 + if (conf->query_all)
2247 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2248 + else
2249 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2250 + for (i = 0; i < argc; i++) {
2251 + const char *target = argv[i];
2252 + int j;
2253 +
2254 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2255 +
2256 + for (j = 0; j < available_pkgs->len; j++) {
2257 + pkg_t *pkg = available_pkgs->pkgs[j];
2258 + if (fnmatch(target, pkg->name, 0) == 0) {
2259 + int k;
2260 + int count = pkg->depends_count + pkg->pre_depends_count;
2261 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2262 + target, pkg->architecture, rel_str);
2263 + for (k = 0; k < count; k++) {
2264 + compound_depend_t *cdepend = &pkg->depends[k];
2265 + int l;
2266 + for (l = 0; l < cdepend->possibility_count; l++) {
2267 + depend_t *possibility = cdepend->possibilities[l];
2268 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2269 + if (conf->verbosity > 0) {
2270 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2271 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2272 + if (possibility->version) {
2273 + char *typestr = NULL;
2274 + switch (possibility->constraint) {
2275 + case NONE: typestr = "none"; break;
2276 + case EARLIER: typestr = "<"; break;
2277 + case EARLIER_EQUAL: typestr = "<="; break;
2278 + case EQUAL: typestr = "="; break;
2279 + case LATER_EQUAL: typestr = ">="; break;
2280 + case LATER: typestr = ">"; break;
2281 + }
2282 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2283 + }
2284 + // free(ver);
2285 + }
2286 + ipkg_message(conf, IPKG_ERROR, "\n");
2287 + }
2288 + }
2289 + }
2290 + }
2291 + }
2292 + pkg_vec_free(available_pkgs);
2293 + }
2294 + return 0;
2295 +}
2296 +
2297 +enum what_field_type {
2298 + WHATDEPENDS,
2299 + WHATCONFLICTS,
2300 + WHATPROVIDES,
2301 + WHATREPLACES,
2302 + WHATRECOMMENDS,
2303 + WHATSUGGESTS
2304 +};
2305 +
2306 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2307 +{
2308 +
2309 + if (argc > 0) {
2310 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2311 + const char *rel_str = NULL;
2312 + int i;
2313 + int changed;
2314 +
2315 + switch (what_field_type) {
2316 + case WHATDEPENDS: rel_str = "depends on"; break;
2317 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2318 + case WHATSUGGESTS: rel_str = "suggests"; break;
2319 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2320 + case WHATPROVIDES: rel_str = "provides"; break;
2321 + case WHATREPLACES: rel_str = "replaces"; break;
2322 + }
2323 +
2324 + if (conf->query_all)
2325 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2326 + else
2327 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2328 +
2329 + /* mark the root set */
2330 + pkg_vec_clear_marks(available_pkgs);
2331 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2332 + for (i = 0; i < argc; i++) {
2333 + const char *dependee_pattern = argv[i];
2334 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2335 + }
2336 + for (i = 0; i < available_pkgs->len; i++) {
2337 + pkg_t *pkg = available_pkgs->pkgs[i];
2338 + if (pkg->state_flag & SF_MARKED) {
2339 + /* mark the parent (abstract) package */
2340 + pkg_mark_provides(pkg);
2341 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2342 + }
2343 + }
2344 +
2345 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2346 + do {
2347 + int j;
2348 + changed = 0;
2349 +
2350 + for (j = 0; j < available_pkgs->len; j++) {
2351 + pkg_t *pkg = available_pkgs->pkgs[j];
2352 + int k;
2353 + int count = ((what_field_type == WHATCONFLICTS)
2354 + ? pkg->conflicts_count
2355 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2356 + /* skip this package if it is already marked */
2357 + if (pkg->parent->state_flag & SF_MARKED) {
2358 + continue;
2359 + }
2360 + for (k = 0; k < count; k++) {
2361 + compound_depend_t *cdepend =
2362 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2363 + int l;
2364 + for (l = 0; l < cdepend->possibility_count; l++) {
2365 + depend_t *possibility = cdepend->possibilities[l];
2366 + if (possibility->pkg->state_flag & SF_MARKED) {
2367 + /* mark the depending package so we won't visit it again */
2368 + pkg->state_flag |= SF_MARKED;
2369 + pkg_mark_provides(pkg);
2370 + changed++;
2371 +
2372 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2373 + if (conf->verbosity > 0) {
2374 + char *ver = pkg_version_str_alloc(pkg);
2375 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2376 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2377 + if (possibility->version) {
2378 + char *typestr = NULL;
2379 + switch (possibility->constraint) {
2380 + case NONE: typestr = "none"; break;
2381 + case EARLIER: typestr = "<"; break;
2382 + case EARLIER_EQUAL: typestr = "<="; break;
2383 + case EQUAL: typestr = "="; break;
2384 + case LATER_EQUAL: typestr = ">="; break;
2385 + case LATER: typestr = ">"; break;
2386 + }
2387 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2388 + }
2389 + free(ver);
2390 + if (!pkg_dependence_satisfiable(conf, possibility))
2391 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2392 + }
2393 + ipkg_message(conf, IPKG_NOTICE, "\n");
2394 + goto next_package;
2395 + }
2396 + }
2397 + }
2398 + next_package:
2399 + ;
2400 + }
2401 + } while (changed && recursive);
2402 + pkg_vec_free(available_pkgs);
2403 + }
2404 +
2405 + return 0;
2406 +}
2407 +
2408 +int pkg_mark_provides(pkg_t *pkg)
2409 +{
2410 + int provides_count = pkg->provides_count;
2411 + abstract_pkg_t **provides = pkg->provides;
2412 + int i;
2413 + pkg->parent->state_flag |= SF_MARKED;
2414 + for (i = 0; i < provides_count; i++) {
2415 + provides[i]->state_flag |= SF_MARKED;
2416 + }
2417 + return 0;
2418 +}
2419 +
2420 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2421 +{
2422 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2423 +}
2424 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2425 +{
2426 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2427 +}
2428 +
2429 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2430 +{
2431 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2432 +}
2433 +
2434 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2435 +{
2436 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2437 +}
2438 +
2439 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2440 +{
2441 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2442 +}
2443 +
2444 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2445 +{
2446 +
2447 + if (argc > 0) {
2448 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2449 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2450 + int i;
2451 +
2452 + pkg_info_preinstall_check(conf);
2453 +
2454 + if (conf->query_all)
2455 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2456 + else
2457 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2458 + for (i = 0; i < argc; i++) {
2459 + const char *target = argv[i];
2460 + int j;
2461 +
2462 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2463 + rel_str, target);
2464 + for (j = 0; j < available_pkgs->len; j++) {
2465 + pkg_t *pkg = available_pkgs->pkgs[j];
2466 + int k;
2467 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2468 + for (k = 0; k < count; k++) {
2469 + abstract_pkg_t *apkg =
2470 + ((what_field_type == WHATPROVIDES)
2471 + ? pkg->provides[k]
2472 + : pkg->replaces[k]);
2473 + if (fnmatch(target, apkg->name, 0) == 0) {
2474 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2475 + if (strcmp(target, apkg->name) != 0)
2476 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2477 + ipkg_message(conf, IPKG_ERROR, "\n");
2478 + }
2479 + }
2480 + }
2481 + }
2482 + pkg_vec_free(available_pkgs);
2483 + }
2484 + return 0;
2485 +}
2486 +
2487 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2488 +{
2489 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2490 +}
2491 +
2492 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2493 +{
2494 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2495 +}
2496 +
2497 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2498 +{
2499 + int i;
2500 +
2501 + pkg_vec_t *installed;
2502 + pkg_t *pkg;
2503 + str_list_t *installed_files;
2504 + str_list_elt_t *iter;
2505 + char *installed_file;
2506 +
2507 + if (argc < 1) {
2508 + return EINVAL;
2509 + }
2510 +
2511 + installed = pkg_vec_alloc();
2512 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2513 +
2514 + for (i=0; i < installed->len; i++) {
2515 + pkg = installed->pkgs[i];
2516 +
2517 + installed_files = pkg_get_installed_files(pkg);
2518 +
2519 + for (iter = installed_files->head; iter; iter = iter->next) {
2520 + installed_file = iter->data;
2521 + if (fnmatch(argv[0], installed_file, 0)==0) {
2522 +#ifndef IPKG_LIB
2523 + printf("%s: %s\n", pkg->name, installed_file);
2524 +#else
2525 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2526 + installed_file,
2527 + pkg_version_str_alloc(pkg),
2528 + pkg->state_status, p_userdata);
2529 +#endif
2530 + }
2531 + }
2532 +
2533 + pkg_free_installed_files(pkg);
2534 + }
2535 +
2536 + /* XXX: CLEANUP: It's not obvious from the name of
2537 + pkg_hash_fetch_all_installed that we need to call
2538 + pkg_vec_free to avoid a memory leak. */
2539 + pkg_vec_free(installed);
2540 +
2541 + return 0;
2542 +}
2543 +
2544 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2545 +{
2546 + if (argc == 3) {
2547 + /* this is a bit gross */
2548 + struct pkg p1, p2;
2549 + parseVersion(&p1, argv[0]);
2550 + parseVersion(&p2, argv[2]);
2551 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2552 + } else {
2553 + ipkg_message(conf, IPKG_ERROR,
2554 + "ipkg compare_versions <v1> <op> <v2>\n"
2555 + "<op> is one of <= >= << >> =\n");
2556 + return -1;
2557 + }
2558 +}
2559 +
2560 +#ifndef HOST_CPU_STR
2561 +#define HOST_CPU_STR__(X) #X
2562 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2563 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2564 +#endif
2565 +
2566 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2567 +{
2568 + nv_pair_list_elt_t *l;
2569 +
2570 + l = conf->arch_list.head;
2571 + while (l) {
2572 + nv_pair_t *nv = l->data;
2573 + printf("arch %s %s\n", nv->name, nv->value);
2574 + l = l->next;
2575 + }
2576 + return 0;
2577 +}
2578 +
2579 +
2580 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h
2581 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2582 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h 2006-03-30 00:39:48.000000000 +0200
2583 @@ -0,0 +1,46 @@
2584 +/* ipkg_cmd.h - the itsy package management system
2585 +
2586 + Carl D. Worth
2587 +
2588 + Copyright (C) 2001 University of Southern California
2589 +
2590 + This program is free software; you can redistribute it and/or
2591 + modify it under the terms of the GNU General Public License as
2592 + published by the Free Software Foundation; either version 2, or (at
2593 + your option) any later version.
2594 +
2595 + This program is distributed in the hope that it will be useful, but
2596 + WITHOUT ANY WARRANTY; without even the implied warranty of
2597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2598 + General Public License for more details.
2599 +*/
2600 +
2601 +#ifndef IPKG_CMD_H
2602 +#define IPKG_CMD_H
2603 +
2604 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2605 +
2606 +struct ipkg_cmd
2607 +{
2608 + char *name;
2609 + int requires_args;
2610 + ipkg_cmd_fun_t fun;
2611 +};
2612 +typedef struct ipkg_cmd ipkg_cmd_t;
2613 +
2614 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2615 +#ifdef IPKG_LIB
2616 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2617 + const char **argv, void *userdata);
2618 +#else
2619 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2620 +#endif
2621 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2622 +/* install any packges with state_want == SW_INSTALL */
2623 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2624 +/* ensure that all dependences are satisfied */
2625 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2626 +
2627 +int pkg_mark_provides(pkg_t *pkg);
2628 +
2629 +#endif
2630 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.c busybox-1.1.1-new/archival/libipkg/ipkg_conf.c
2631 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2632 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.c 2006-03-30 00:39:48.000000000 +0200
2633 @@ -0,0 +1,709 @@
2634 +/* ipkg_conf.c - the itsy package management system
2635 +
2636 + Carl D. Worth
2637 +
2638 + Copyright (C) 2001 University of Southern California
2639 +
2640 + This program is free software; you can redistribute it and/or
2641 + modify it under the terms of the GNU General Public License as
2642 + published by the Free Software Foundation; either version 2, or (at
2643 + your option) any later version.
2644 +
2645 + This program is distributed in the hope that it will be useful, but
2646 + WITHOUT ANY WARRANTY; without even the implied warranty of
2647 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2648 + General Public License for more details.
2649 +*/
2650 +
2651 +#include <glob.h>
2652 +
2653 +#include "ipkg.h"
2654 +#include "ipkg_conf.h"
2655 +
2656 +#include "xregex.h"
2657 +#include "sprintf_alloc.h"
2658 +#include "ipkg_conf.h"
2659 +#include "ipkg_message.h"
2660 +#include "file_util.h"
2661 +#include "str_util.h"
2662 +#include "xsystem.h"
2663 +
2664 +
2665 +ipkg_conf_t *global_conf;
2666 +
2667 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2668 + pkg_src_list_t *pkg_src_list,
2669 + nv_pair_list_t *tmp_dest_nv_pair_list,
2670 + char **tmp_lists_dir);
2671 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2672 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2673 + const char *name, const char *value);
2674 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2675 + const char *default_dest_name);
2676 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2677 + pkg_src_list_t *nv_pair_list);
2678 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2679 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2680 +
2681 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2682 +{
2683 + ipkg_option_t tmp[] = {
2684 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2685 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2686 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2687 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2688 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2689 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2690 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2691 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2692 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2693 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2694 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2695 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2696 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2697 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2698 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2699 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2700 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2701 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2702 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2703 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2704 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2705 + { NULL }
2706 + };
2707 +
2708 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2709 + if ( options == NULL ){
2710 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2711 + return -1;
2712 + }
2713 +
2714 + memcpy(*options, tmp, sizeof(tmp));
2715 + return 0;
2716 +};
2717 +
2718 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2719 +{
2720 + if (arg_str) {
2721 + if (*conf_str) {
2722 + free(*conf_str);
2723 + }
2724 + *conf_str = strdup(arg_str);
2725 + }
2726 +}
2727 +
2728 +static void ipkg_conf_free_string(char **conf_str)
2729 +{
2730 + if (*conf_str) {
2731 + free(*conf_str);
2732 + *conf_str = NULL;
2733 + }
2734 +}
2735 +
2736 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2737 +{
2738 + int err;
2739 + char *tmp_dir_base;
2740 + nv_pair_list_t tmp_dest_nv_pair_list;
2741 + char * lists_dir =NULL;
2742 + glob_t globbuf;
2743 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2744 + char *pending_dir =NULL;
2745 +
2746 + memset(conf, 0, sizeof(ipkg_conf_t));
2747 +
2748 + pkg_src_list_init(&conf->pkg_src_list);
2749 +
2750 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2751 + pkg_dest_list_init(&conf->pkg_dest_list);
2752 +
2753 + nv_pair_list_init(&conf->arch_list);
2754 +
2755 + conf->restrict_to_default_dest = 0;
2756 + conf->default_dest = NULL;
2757 +
2758 +
2759 + if (args->tmp_dir)
2760 + tmp_dir_base = args->tmp_dir;
2761 + else
2762 + tmp_dir_base = getenv("TMPDIR");
2763 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2764 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2765 + IPKG_CONF_TMP_DIR_SUFFIX);
2766 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2767 + if (conf->tmp_dir == NULL) {
2768 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2769 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2770 + return errno;
2771 + }
2772 +
2773 + conf->force_depends = 0;
2774 + conf->force_defaults = 0;
2775 + conf->force_overwrite = 0;
2776 + conf->force_downgrade = 0;
2777 + conf->force_reinstall = 0;
2778 + conf->force_space = 0;
2779 + conf->force_removal_of_essential_packages = 0;
2780 + conf->force_removal_of_dependent_packages = 0;
2781 + conf->nodeps = 0;
2782 + conf->verbose_wget = 0;
2783 + conf->offline_root = NULL;
2784 + conf->offline_root_pre_script_cmd = NULL;
2785 + conf->offline_root_post_script_cmd = NULL;
2786 + conf->multiple_providers = 0;
2787 + conf->verbosity = 1;
2788 + conf->noaction = 0;
2789 +
2790 + conf->http_proxy = NULL;
2791 + conf->ftp_proxy = NULL;
2792 + conf->no_proxy = NULL;
2793 + conf->proxy_user = NULL;
2794 + conf->proxy_passwd = NULL;
2795 +
2796 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2798 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2799 + lists_dir=(char *)malloc(1);
2800 + lists_dir[0]='\0';
2801 + if (args->conf_file) {
2802 + struct stat stat_buf;
2803 + err = stat(args->conf_file, &stat_buf);
2804 + if (err == 0)
2805 + if (ipkg_conf_parse_file(conf, args->conf_file,
2806 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2807 + /* Memory leakage from ipkg_conf_parse-file */
2808 + return -1;
2809 + }
2810 +
2811 + }
2812 +
2813 + /* if (!lists_dir ){*/
2814 + if (strlen(lists_dir)<=1 ){
2815 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2816 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2817 + }
2818 +
2819 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2820 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2821 +
2822 + conf->lists_dir = strdup(lists_dir);
2823 + conf->pending_dir = strdup(pending_dir);
2824 +
2825 + if (args->offline_root)
2826 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2827 + memset(&globbuf, 0, sizeof(globbuf));
2828 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2829 + if (!err) {
2830 + int i;
2831 + for (i = 0; i < globbuf.gl_pathc; i++) {
2832 + if (globbuf.gl_pathv[i])
2833 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2834 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2835 + /* Memory leakage from ipkg_conf_parse-file */
2836 + return -1;
2837 + }
2838 + }
2839 + }
2840 + globfree(&globbuf);
2841 +
2842 + /* if no architectures were defined, then default all, noarch, and host architecture */
2843 + if (nv_pair_list_empty(&conf->arch_list)) {
2844 + nv_pair_list_append(&conf->arch_list, "all", "1");
2845 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2846 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2847 + }
2848 +
2849 + /* Even if there is no conf file, we'll need at least one dest. */
2850 + if (tmp_dest_nv_pair_list.head == NULL) {
2851 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2852 + IPKG_CONF_DEFAULT_DEST_NAME,
2853 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2854 + }
2855 +
2856 + /* After parsing the file, set options from command-line, (so that
2857 + command-line arguments take precedence) */
2858 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2859 + really needs to be cleaned up. There is so much duplication
2860 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2861 + a pointer to args_t (which could then not be freed), rather
2862 + than duplicating every field here? */
2863 + if (args->force_depends) {
2864 + conf->force_depends = 1;
2865 + }
2866 + if (args->force_defaults) {
2867 + conf->force_defaults = 1;
2868 + }
2869 + if (args->force_overwrite) {
2870 + conf->force_overwrite = 1;
2871 + }
2872 + if (args->force_downgrade) {
2873 + conf->force_downgrade = 1;
2874 + }
2875 + if (args->force_reinstall) {
2876 + conf->force_reinstall = 1;
2877 + }
2878 + if (args->force_removal_of_dependent_packages) {
2879 + conf->force_removal_of_dependent_packages = 1;
2880 + }
2881 + if (args->force_removal_of_essential_packages) {
2882 + conf->force_removal_of_essential_packages = 1;
2883 + }
2884 + if (args->nodeps) {
2885 + conf->nodeps = 1;
2886 + }
2887 + if (args->noaction) {
2888 + conf->noaction = 1;
2889 + }
2890 + if (args->query_all) {
2891 + conf->query_all = 1;
2892 + }
2893 + if (args->verbose_wget) {
2894 + conf->verbose_wget = 1;
2895 + }
2896 + if (args->multiple_providers) {
2897 + conf->multiple_providers = 1;
2898 + }
2899 + if (args->verbosity != conf->verbosity) {
2900 + conf->verbosity = args->verbosity;
2901 + }
2902 +
2903 + ipkg_conf_override_string(&conf->offline_root,
2904 + args->offline_root);
2905 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2906 + args->offline_root_pre_script_cmd);
2907 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2908 + args->offline_root_post_script_cmd);
2909 +
2910 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2911 + read anything from there.
2912 +*/
2913 + if ( !(args->nocheckfordirorfile)){
2914 + /* need to run load the source list before dest list -Jamey */
2915 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2916 +
2917 + /* Now that we have resolved conf->offline_root, we can commit to
2918 + the directory names for the dests and load in all the package
2919 + lists. */
2920 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2921 +
2922 + if (args->dest) {
2923 + err = ipkg_conf_set_default_dest(conf, args->dest);
2924 + if (err) {
2925 + return err;
2926 + }
2927 + }
2928 + }
2929 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2930 + free(lists_dir);
2931 + free(pending_dir);
2932 +
2933 + return 0;
2934 +}
2935 +
2936 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2937 +{
2938 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2939 +#error
2940 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2941 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2942 + __FUNCTION__, conf->tmp_dir);
2943 +#else
2944 + int err;
2945 +
2946 + err = rmdir(conf->tmp_dir);
2947 + if (err) {
2948 + if (errno == ENOTEMPTY) {
2949 + char *cmd;
2950 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2951 + err = xsystem(cmd);
2952 + free(cmd);
2953 + }
2954 + if (err)
2955 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2956 + }
2957 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2958 +
2959 + free(conf->tmp_dir); /*XXX*/
2960 +
2961 + pkg_src_list_deinit(&conf->pkg_src_list);
2962 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2963 + nv_pair_list_deinit(&conf->arch_list);
2964 + if (&conf->pkg_hash)
2965 + pkg_hash_deinit(&conf->pkg_hash);
2966 + if (&conf->file_hash)
2967 + hash_table_deinit(&conf->file_hash);
2968 + if (&conf->obs_file_hash)
2969 + hash_table_deinit(&conf->obs_file_hash);
2970 +
2971 + ipkg_conf_free_string(&conf->offline_root);
2972 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2973 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2974 +
2975 + if (conf->verbosity > 1) {
2976 + int i;
2977 + hash_table_t *hashes[] = {
2978 + &conf->pkg_hash,
2979 + &conf->file_hash,
2980 + &conf->obs_file_hash };
2981 + for (i = 0; i < 3; i++) {
2982 + hash_table_t *hash = hashes[i];
2983 + int c = 0;
2984 + int n_conflicts = 0;
2985 + int j;
2986 + for (j = 0; j < hash->n_entries; j++) {
2987 + int len = 0;
2988 + hash_entry_t *e = &hash->entries[j];
2989 + if (e->next)
2990 + n_conflicts++;
2991 + while (e && e->key) {
2992 + len++;
2993 + e = e->next;
2994 + }
2995 + if (len > c)
2996 + c = len;
2997 + }
2998 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2999 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
3000 + hash_table_deinit(hash);
3001 + }
3002 + }
3003 +}
3004 +
3005 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3006 + const char *default_dest_name)
3007 +{
3008 + pkg_dest_list_elt_t *iter;
3009 + pkg_dest_t *dest;
3010 +
3011 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3012 + dest = iter->data;
3013 + if (strcmp(dest->name, default_dest_name) == 0) {
3014 + conf->default_dest = dest;
3015 + conf->restrict_to_default_dest = 1;
3016 + return 0;
3017 + }
3018 + }
3019 +
3020 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3021 +
3022 + return 1;
3023 +}
3024 +
3025 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3026 +{
3027 + pkg_src_list_elt_t *iter;
3028 + pkg_src_t *src;
3029 + char *list_file;
3030 +
3031 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3032 + src = iter->data;
3033 + if (src == NULL) {
3034 + continue;
3035 + }
3036 + if (conf->offline_root) {
3037 + sprintf_alloc(&list_file, "%s/%s/%s",
3038 + conf->offline_root,
3039 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3040 + src->name);
3041 + } else {
3042 + sprintf_alloc(&list_file, "%s/%s",
3043 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3044 + src->name);
3045 + }
3046 +
3047 + if (file_exists(list_file)) {
3048 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3049 + }
3050 + free(list_file);
3051 + }
3052 +
3053 + return 0;
3054 +}
3055 +
3056 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3057 +{
3058 + nv_pair_list_elt_t *iter;
3059 + nv_pair_t *nv_pair;
3060 + pkg_dest_t *dest;
3061 + char *root_dir;
3062 +
3063 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3064 + nv_pair = iter->data;
3065 +
3066 + if (conf->offline_root) {
3067 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3068 + } else {
3069 + root_dir = strdup(nv_pair->value);
3070 + }
3071 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3072 + free(root_dir);
3073 + if (dest == NULL) {
3074 + continue;
3075 + }
3076 + if (conf->default_dest == NULL) {
3077 + conf->default_dest = dest;
3078 + }
3079 + if (file_exists(dest->status_file_name)) {
3080 + pkg_hash_add_from_file(conf, dest->status_file_name,
3081 + NULL, dest, 1);
3082 + }
3083 + }
3084 +
3085 + return 0;
3086 +}
3087 +
3088 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3089 + pkg_src_list_t *pkg_src_list,
3090 + nv_pair_list_t *tmp_dest_nv_pair_list,
3091 + char **lists_dir)
3092 +{
3093 + ipkg_option_t * options;
3094 + FILE *file = fopen(filename, "r");
3095 + regex_t valid_line_re, comment_re;
3096 +#define regmatch_size 12
3097 + regmatch_t regmatch[regmatch_size];
3098 +
3099 + if (ipkg_init_options_array(conf, &options)<0)
3100 + return ENOMEM;
3101 +
3102 + if (file == NULL) {
3103 + fprintf(stderr, "%s: failed to open %s: %s\n",
3104 + __FUNCTION__, filename, strerror(errno));
3105 + free(options);
3106 + return errno;
3107 + }
3108 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3109 +
3110 + xregcomp(&comment_re,
3111 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3112 + REG_EXTENDED);
3113 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3114 +
3115 + while(1) {
3116 + int line_num = 0;
3117 + char *line;
3118 + char *type, *name, *value, *extra;
3119 +
3120 + line = file_read_line_alloc(file);
3121 + line_num++;
3122 + if (line == NULL) {
3123 + break;
3124 + }
3125 +
3126 + str_chomp(line);
3127 +
3128 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3129 + goto NEXT_LINE;
3130 + }
3131 +
3132 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3133 + str_chomp(line);
3134 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3135 + filename, line_num, line);
3136 + goto NEXT_LINE;
3137 + }
3138 +
3139 + /* This has to be so ugly to deal with optional quotation marks */
3140 + if (regmatch[2].rm_so > 0) {
3141 + type = strndup(line + regmatch[2].rm_so,
3142 + regmatch[2].rm_eo - regmatch[2].rm_so);
3143 + } else {
3144 + type = strndup(line + regmatch[3].rm_so,
3145 + regmatch[3].rm_eo - regmatch[3].rm_so);
3146 + }
3147 + if (regmatch[5].rm_so > 0) {
3148 + name = strndup(line + regmatch[5].rm_so,
3149 + regmatch[5].rm_eo - regmatch[5].rm_so);
3150 + } else {
3151 + name = strndup(line + regmatch[6].rm_so,
3152 + regmatch[6].rm_eo - regmatch[6].rm_so);
3153 + }
3154 + if (regmatch[8].rm_so > 0) {
3155 + value = strndup(line + regmatch[8].rm_so,
3156 + regmatch[8].rm_eo - regmatch[8].rm_so);
3157 + } else {
3158 + value = strndup(line + regmatch[9].rm_so,
3159 + regmatch[9].rm_eo - regmatch[9].rm_so);
3160 + }
3161 + extra = NULL;
3162 + if (regmatch[11].rm_so > 0) {
3163 + extra = strndup (line + regmatch[11].rm_so,
3164 + regmatch[11].rm_eo - regmatch[11].rm_so);
3165 + }
3166 +
3167 + /* We use the tmp_dest_nv_pair_list below instead of
3168 + conf->pkg_dest_list because we might encounter an
3169 + offline_root option later and that would invalidate the
3170 + directories we would have computed in
3171 + pkg_dest_list_init. (We do a similar thing with
3172 + tmp_src_nv_pair_list for sake of symmetry.) */
3173 + if (strcmp(type, "option") == 0) {
3174 + ipkg_conf_set_option(options, name, value);
3175 + } else if (strcmp(type, "src") == 0) {
3176 + if (!nv_pair_list_find(pkg_src_list, name)) {
3177 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3178 + } else {
3179 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3180 + name, value);
3181 + }
3182 + } else if (strcmp(type, "src/gz") == 0) {
3183 + if (!nv_pair_list_find(pkg_src_list, name)) {
3184 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3185 + } else {
3186 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3187 + name, value);
3188 + }
3189 + } else if (strcmp(type, "dest") == 0) {
3190 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3191 + } else if (strcmp(type, "lists_dir") == 0) {
3192 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3193 + if (*lists_dir == NULL) {
3194 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3195 + free(options);
3196 + return EINVAL;
3197 + }
3198 + sprintf (*lists_dir,"%s",value);
3199 + } else if (strcmp(type, "arch") == 0) {
3200 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3201 + if (!value) {
3202 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3203 + value = strdup("10");
3204 + }
3205 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3206 + } else {
3207 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3208 + "parameter: %s %s %s\n", type, name, value);
3209 + free(options);
3210 + return EINVAL;
3211 + }
3212 +
3213 + free(type);
3214 + free(name);
3215 + free(value);
3216 + if (extra)
3217 + free (extra);
3218 +
3219 + NEXT_LINE:
3220 + free(line);
3221 + }
3222 +
3223 + free(options);
3224 + regfree(&comment_re);
3225 + regfree(&valid_line_re);
3226 + fclose(file);
3227 +
3228 + return 0;
3229 +}
3230 +
3231 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3232 + const char *name, const char *value)
3233 +{
3234 + int i = 0;
3235 + while (options[i].name) {
3236 + if (strcmp(options[i].name, name) == 0) {
3237 + switch (options[i].type) {
3238 + case IPKG_OPT_TYPE_BOOL:
3239 + *((int *)options[i].value) = 1;
3240 + return 0;
3241 + case IPKG_OPT_TYPE_INT:
3242 + if (value) {
3243 + *((int *)options[i].value) = atoi(value);
3244 + return 0;
3245 + } else {
3246 + printf("%s: Option %s need an argument\n",
3247 + __FUNCTION__, name);
3248 + return EINVAL;
3249 + }
3250 + case IPKG_OPT_TYPE_STRING:
3251 + if (value) {
3252 + *((char **)options[i].value) = strdup(value);
3253 + return 0;
3254 + } else {
3255 + printf("%s: Option %s need an argument\n",
3256 + __FUNCTION__, name);
3257 + return EINVAL;
3258 + }
3259 + }
3260 + }
3261 + i++;
3262 + }
3263 +
3264 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3265 + __FUNCTION__, name, value);
3266 + return EINVAL;
3267 +}
3268 +
3269 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3270 +{
3271 + pkg_dest_list_elt_t *iter;
3272 + pkg_dest_t *dest;
3273 + pkg_vec_t *all;
3274 + pkg_t *pkg;
3275 + register int i;
3276 + int err;
3277 +
3278 + if (conf->noaction)
3279 + return 0;
3280 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3281 + dest = iter->data;
3282 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3283 + if (dest->status_file == NULL) {
3284 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3285 + __FUNCTION__, dest->status_file_name, strerror(errno));
3286 + }
3287 + }
3288 +
3289 + all = pkg_vec_alloc();
3290 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3291 +
3292 + for(i = 0; i < all->len; i++) {
3293 + pkg = all->pkgs[i];
3294 + /* We don't need most uninstalled packages in the status file */
3295 + if (pkg->state_status == SS_NOT_INSTALLED
3296 + && (pkg->state_want == SW_UNKNOWN
3297 + || pkg->state_want == SW_DEINSTALL
3298 + || pkg->state_want == SW_PURGE)) {
3299 + continue;
3300 + }
3301 + if (!pkg) {
3302 + fprintf(stderr, "Null package\n");
3303 + }
3304 + if (pkg->dest == NULL) {
3305 + fprintf(stderr, "%s: ERROR: Can't write status for "
3306 + "package %s since it has a NULL dest\n",
3307 + __FUNCTION__, pkg->name);
3308 + continue;
3309 + }
3310 + if (pkg->dest->status_file) {
3311 + pkg_print_status(pkg, pkg->dest->status_file);
3312 + }
3313 + }
3314 +
3315 + pkg_vec_free(all);
3316 +
3317 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3318 + dest = iter->data;
3319 + if (dest->status_file) {
3320 + err = ferror(dest->status_file);
3321 + fclose(dest->status_file);
3322 + dest->status_file = NULL;
3323 + if (!err) {
3324 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3325 + } else {
3326 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3327 + "retaining old %s\n", __FUNCTION__,
3328 + dest->status_file_tmp_name, dest->status_file_name);
3329 + }
3330 + }
3331 + }
3332 +
3333 + return 0;
3334 +}
3335 +
3336 +
3337 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3338 +{
3339 + char *root_filename;
3340 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3341 + return root_filename;
3342 +}
3343 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.h busybox-1.1.1-new/archival/libipkg/ipkg_conf.h
3344 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3345 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.h 2006-03-30 00:39:48.000000000 +0200
3346 @@ -0,0 +1,107 @@
3347 +/* ipkg_conf.h - the itsy package management system
3348 +
3349 + Carl D. Worth
3350 +
3351 + Copyright (C) 2001 University of Southern California
3352 +
3353 + This program is free software; you can redistribute it and/or
3354 + modify it under the terms of the GNU General Public License as
3355 + published by the Free Software Foundation; either version 2, or (at
3356 + your option) any later version.
3357 +
3358 + This program is distributed in the hope that it will be useful, but
3359 + WITHOUT ANY WARRANTY; without even the implied warranty of
3360 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3361 + General Public License for more details.
3362 +*/
3363 +
3364 +#ifndef IPKG_CONF_H
3365 +#define IPKG_CONF_H
3366 +
3367 +typedef struct ipkg_conf ipkg_conf_t;
3368 +
3369 +#include "hash_table.h"
3370 +#include "ipkg.h"
3371 +#include "args.h"
3372 +#include "pkg.h"
3373 +#include "pkg_hash.h"
3374 +#include "pkg_src_list.h"
3375 +#include "pkg_dest_list.h"
3376 +#include "nv_pair_list.h"
3377 +
3378 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3379 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3380 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3381 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3382 +
3383 +/* In case the config file defines no dest */
3384 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3385 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3386 +
3387 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3388 +
3389 +struct ipkg_conf
3390 +{
3391 + pkg_src_list_t pkg_src_list;
3392 + pkg_dest_list_t pkg_dest_list;
3393 + nv_pair_list_t arch_list;
3394 +
3395 + int restrict_to_default_dest;
3396 + pkg_dest_t *default_dest;
3397 +
3398 + char *tmp_dir;
3399 + const char *lists_dir;
3400 + const char *pending_dir;
3401 +
3402 + /* options */
3403 + int force_depends;
3404 + int force_defaults;
3405 + int force_overwrite;
3406 + int force_downgrade;
3407 + int force_reinstall;
3408 + int force_space;
3409 + int force_removal_of_dependent_packages;
3410 + int force_removal_of_essential_packages;
3411 + int nodeps; /* do not follow dependences */
3412 + int verbose_wget;
3413 + int multiple_providers;
3414 + char *offline_root;
3415 + char *offline_root_pre_script_cmd;
3416 + char *offline_root_post_script_cmd;
3417 + int query_all;
3418 + int verbosity;
3419 + int noaction;
3420 +
3421 + /* proxy options */
3422 + char *http_proxy;
3423 + char *ftp_proxy;
3424 + char *no_proxy;
3425 + char *proxy_user;
3426 + char *proxy_passwd;
3427 +
3428 + hash_table_t pkg_hash;
3429 + hash_table_t file_hash;
3430 + hash_table_t obs_file_hash;
3431 +};
3432 +
3433 +enum ipkg_option_type {
3434 + IPKG_OPT_TYPE_BOOL,
3435 + IPKG_OPT_TYPE_INT,
3436 + IPKG_OPT_TYPE_STRING
3437 +};
3438 +typedef enum ipkg_option_type ipkg_option_type_t;
3439 +
3440 +typedef struct ipkg_option ipkg_option_t;
3441 +struct ipkg_option {
3442 + const char *name;
3443 + const ipkg_option_type_t type;
3444 + const void *value;
3445 +};
3446 +
3447 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3448 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3449 +
3450 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3451 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3452 +
3453 +#endif
3454 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.c busybox-1.1.1-new/archival/libipkg/ipkg_configure.c
3455 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3456 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.c 2006-03-30 00:39:48.000000000 +0200
3457 @@ -0,0 +1,40 @@
3458 +/* ipkg_configure.c - the itsy package management system
3459 +
3460 + Carl D. Worth
3461 +
3462 + Copyright (C) 2001 University of Southern California
3463 +
3464 + This program is free software; you can redistribute it and/or
3465 + modify it under the terms of the GNU General Public License as
3466 + published by the Free Software Foundation; either version 2, or (at
3467 + your option) any later version.
3468 +
3469 + This program is distributed in the hope that it will be useful, but
3470 + WITHOUT ANY WARRANTY; without even the implied warranty of
3471 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3472 + General Public License for more details.
3473 +*/
3474 +
3475 +#include "ipkg.h"
3476 +
3477 +#include "ipkg_configure.h"
3478 +
3479 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3480 +{
3481 + int err;
3482 +
3483 + /* DPKG_INCOMPATIBILITY:
3484 + dpkg actually does some conffile handling here, rather than at the
3485 + end of ipkg_install(). Do we care? */
3486 + /* DPKG_INCOMPATIBILITY:
3487 + dpkg actually includes a version number to this script call */
3488 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3489 + if (err) {
3490 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3491 + return err;
3492 + }
3493 +
3494 + ipkg_state_changed++;
3495 + return 0;
3496 +}
3497 +
3498 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.h busybox-1.1.1-new/archival/libipkg/ipkg_configure.h
3499 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3500 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.h 2006-03-30 00:39:48.000000000 +0200
3501 @@ -0,0 +1,25 @@
3502 +/* ipkg_configure.h - the itsy package management system
3503 +
3504 + Carl D. Worth
3505 +
3506 + Copyright (C) 2001 University of Southern California
3507 +
3508 + This program is free software; you can redistribute it and/or
3509 + modify it under the terms of the GNU General Public License as
3510 + published by the Free Software Foundation; either version 2, or (at
3511 + your option) any later version.
3512 +
3513 + This program is distributed in the hope that it will be useful, but
3514 + WITHOUT ANY WARRANTY; without even the implied warranty of
3515 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3516 + General Public License for more details.
3517 +*/
3518 +
3519 +#ifndef IPKG_CONFIGURE_H
3520 +#define IPKG_CONFIGURE_H
3521 +
3522 +#include "ipkg_conf.h"
3523 +
3524 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3525 +
3526 +#endif
3527 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.c busybox-1.1.1-new/archival/libipkg/ipkg_download.c
3528 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3529 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.c 2006-03-30 00:39:48.000000000 +0200
3530 @@ -0,0 +1,191 @@
3531 +/* ipkg_download.c - the itsy package management system
3532 +
3533 + Carl D. Worth
3534 +
3535 + Copyright (C) 2001 University of Southern California
3536 +
3537 + This program is free software; you can redistribute it and/or
3538 + modify it under the terms of the GNU General Public License as
3539 + published by the Free Software Foundation; either version 2, or (at
3540 + your option) any later version.
3541 +
3542 + This program is distributed in the hope that it will be useful, but
3543 + WITHOUT ANY WARRANTY; without even the implied warranty of
3544 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3545 + General Public License for more details.
3546 +*/
3547 +
3548 +#include "ipkg.h"
3549 +#include "ipkg_download.h"
3550 +#include "ipkg_message.h"
3551 +
3552 +#include "sprintf_alloc.h"
3553 +#include "xsystem.h"
3554 +#include "file_util.h"
3555 +#include "str_util.h"
3556 +
3557 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3558 +{
3559 + int err = 0;
3560 +
3561 + char *src_basec = strdup(src);
3562 + char *src_base = basename(src_basec);
3563 + char *tmp_file_location;
3564 + char *cmd;
3565 +
3566 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3567 +
3568 + fflush(stdout);
3569 +
3570 + if (str_starts_with(src, "file:")) {
3571 + int ret;
3572 + const char *file_src = src + 5;
3573 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3574 + ret = file_copy(src + 5, dest_file_name);
3575 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3576 + return ret;
3577 + }
3578 +
3579 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3580 + err = unlink(tmp_file_location);
3581 + if (err && errno != ENOENT) {
3582 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3583 + __FUNCTION__, tmp_file_location, strerror(errno));
3584 + free(tmp_file_location);
3585 + return errno;
3586 + }
3587 +
3588 + if (conf->http_proxy) {
3589 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3590 + setenv("http_proxy", conf->http_proxy, 1);
3591 + }
3592 + if (conf->ftp_proxy) {
3593 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3594 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3595 + }
3596 + if (conf->no_proxy) {
3597 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3598 + setenv("no_proxy", conf->no_proxy, 1);
3599 + }
3600 +
3601 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3602 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3603 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3604 + conf->proxy_user ? "--proxy-user=" : "",
3605 + conf->proxy_user ? conf->proxy_user : "",
3606 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3607 + conf->proxy_passwd ? conf->proxy_passwd : "",
3608 + conf->verbose_wget ? "" : "-q",
3609 + conf->tmp_dir,
3610 + src);
3611 + err = xsystem(cmd);
3612 + if (err) {
3613 + if (err != -1) {
3614 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3615 + __FUNCTION__, err, cmd);
3616 + }
3617 + unlink(tmp_file_location);
3618 + free(tmp_file_location);
3619 + free(src_basec);
3620 + free(cmd);
3621 + return EINVAL;
3622 + }
3623 + free(cmd);
3624 +
3625 + err = file_move(tmp_file_location, dest_file_name);
3626 +
3627 + free(tmp_file_location);
3628 + free(src_basec);
3629 +
3630 + if (err) {
3631 + return err;
3632 + }
3633 +
3634 + return 0;
3635 +}
3636 +
3637 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3638 +{
3639 + int err;
3640 + char *url;
3641 +
3642 + if (pkg->src == NULL) {
3643 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3644 + pkg->name, pkg->parent->name);
3645 + return -1;
3646 + }
3647 +
3648 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3649 +
3650 + /* XXX: BUG: The pkg->filename might be something like
3651 + "../../foo.ipk". While this is correct, and exactly what we
3652 + want to use to construct url above, here we actually need to
3653 + use just the filename part, without any directory. */
3654 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3655 +
3656 + err = ipkg_download(conf, url, pkg->local_filename);
3657 + free(url);
3658 +
3659 + return err;
3660 +}
3661 +
3662 +/*
3663 + * Downloads file from url, installs in package database, return package name.
3664 + */
3665 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3666 +{
3667 + int err = 0;
3668 + pkg_t *pkg;
3669 + pkg = pkg_new();
3670 + if (pkg == NULL)
3671 + return ENOMEM;
3672 +
3673 + if (str_starts_with(url, "http://")
3674 + || str_starts_with(url, "ftp://")) {
3675 + char *tmp_file;
3676 + char *file_basec = strdup(url);
3677 + char *file_base = basename(file_basec);
3678 +
3679 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3680 + err = ipkg_download(conf, url, tmp_file);
3681 + if (err)
3682 + return err;
3683 +
3684 + err = pkg_init_from_file(pkg, tmp_file);
3685 + if (err)
3686 + return err;
3687 + pkg->local_filename = strdup(tmp_file);
3688 +
3689 + free(tmp_file);
3690 + free(file_basec);
3691 +
3692 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3693 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3694 +
3695 + err = pkg_init_from_file(pkg, url);
3696 + if (err)
3697 + return err;
3698 + pkg->local_filename = strdup(url);
3699 +
3700 + } else {
3701 + return 0;
3702 + }
3703 +
3704 + if (!pkg->architecture) {
3705 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3706 + return -EINVAL;
3707 + }
3708 +
3709 + pkg->dest = conf->default_dest;
3710 + pkg->state_want = SW_INSTALL;
3711 + pkg->state_flag |= SF_PREFER;
3712 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3713 + if ( pkg == NULL ){
3714 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3715 + return 0;
3716 + }
3717 + if (namep) {
3718 + *namep = pkg->name;
3719 + }
3720 + return 0;
3721 +}
3722 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.h busybox-1.1.1-new/archival/libipkg/ipkg_download.h
3723 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3724 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.h 2006-03-30 00:39:48.000000000 +0200
3725 @@ -0,0 +1,30 @@
3726 +/* ipkg_download.h - the itsy package management system
3727 +
3728 + Carl D. Worth
3729 +
3730 + Copyright (C) 2001 University of Southern California
3731 +
3732 + This program is free software; you can redistribute it and/or
3733 + modify it under the terms of the GNU General Public License as
3734 + published by the Free Software Foundation; either version 2, or (at
3735 + your option) any later version.
3736 +
3737 + This program is distributed in the hope that it will be useful, but
3738 + WITHOUT ANY WARRANTY; without even the implied warranty of
3739 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3740 + General Public License for more details.
3741 +*/
3742 +
3743 +#ifndef IPKG_DOWNLOAD_H
3744 +#define IPKG_DOWNLOAD_H
3745 +
3746 +#include "ipkg_conf.h"
3747 +
3748 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3749 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3750 +/*
3751 + * Downloads file from url, installs in package database, return package name.
3752 + */
3753 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3754 +
3755 +#endif
3756 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_includes.h busybox-1.1.1-new/archival/libipkg/ipkg_includes.h
3757 --- busybox-1.1.1-old/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3758 +++ busybox-1.1.1-new/archival/libipkg/ipkg_includes.h 2006-03-30 00:39:48.000000000 +0200
3759 @@ -0,0 +1,79 @@
3760 +#ifndef IPKG_INCLUDES_H
3761 +#define IPKG_INCLUDES_H
3762 +
3763 +/* Define to 1 if you have the <memory.h> header file. */
3764 +#define HAVE_MEMORY_H 1
3765 +
3766 +/* Define to 1 if you have the <regex.h> header file. */
3767 +#define HAVE_REGEX_H 1
3768 +
3769 +/* Define to 1 if you have the <stdlib.h> header file. */
3770 +#define HAVE_STDLIB_H 1
3771 +
3772 +/* Define to 1 if you have the <strings.h> header file. */
3773 +#define HAVE_STRINGS_H 1
3774 +
3775 +/* Define to 1 if you have the <string.h> header file. */
3776 +#define HAVE_STRING_H 1
3777 +
3778 +/* Define to 1 if you have the <sys/stat.h> header file. */
3779 +#define HAVE_SYS_STAT_H 1
3780 +
3781 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3782 +#define HAVE_SYS_WAIT_H 1
3783 +
3784 +/* Define to 1 if you have the <unistd.h> header file. */
3785 +#define HAVE_UNISTD_H 1
3786 +
3787 +/* Define to 1 if you have the ANSI C header files. */
3788 +#define STDC_HEADERS 1
3789 +
3790 +
3791 +#include <stdio.h>
3792 +
3793 +#if STDC_HEADERS
3794 +# include <stdlib.h>
3795 +# include <stdarg.h>
3796 +# include <stddef.h>
3797 +# include <ctype.h>
3798 +# include <errno.h>
3799 +#else
3800 +# if HAVE_STDLIB_H
3801 +# include <stdlib.h>
3802 +# endif
3803 +#endif
3804 +
3805 +#if HAVE_REGEX_H
3806 +# include <regex.h>
3807 +#endif
3808 +
3809 +#if HAVE_STRING_H
3810 +# if !STDC_HEADERS && HAVE_MEMORY_H
3811 +# include <memory.h>
3812 +# endif
3813 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3814 +# if __GNUC__
3815 +# define __USE_GNU 1
3816 +# endif
3817 +# include <string.h>
3818 +# undef __USE_GNU
3819 +#endif
3820 +
3821 +#if HAVE_STRINGS_H
3822 +# include <strings.h>
3823 +#endif
3824 +
3825 +#if HAVE_SYS_STAT_H
3826 +# include <sys/stat.h>
3827 +#endif
3828 +
3829 +#if HAVE_SYS_WAIT_H
3830 +# include <sys/wait.h>
3831 +#endif
3832 +
3833 +#if HAVE_UNISTD_H
3834 +# include <sys/types.h>
3835 +# include <unistd.h>
3836 +#endif
3837 +
3838 +#endif /* IPKG_INCLUDES_H */
3839 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_install.c busybox-1.1.1-new/archival/libipkg/ipkg_install.c
3840 --- busybox-1.1.1-old/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3841 +++ busybox-1.1.1-new/archival/libipkg/ipkg_install.c 2006-03-30 00:39:48.000000000 +0200
3842 @@ -0,0 +1,1823 @@
3843 +/* ipkg_install.c - the itsy package management system
3844 +
3845 + Carl D. Worth
3846 +
3847 + Copyright (C) 2001 University of Southern California
3848 +
3849 + This program is free software; you can redistribute it and/or
3850 + modify it under the terms of the GNU General Public License as
3851 + published by the Free Software Foundation; either version 2, or (at
3852 + your option) any later version.
3853 +
3854 + This program is distributed in the hope that it will be useful, but
3855 + WITHOUT ANY WARRANTY; without even the implied warranty of
3856 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3857 + General Public License for more details.
3858 +*/
3859 +
3860 +#include "ipkg.h"
3861 +#include <errno.h>
3862 +#include <dirent.h>
3863 +#include <glob.h>
3864 +#include <time.h>
3865 +#include <signal.h>
3866 +typedef void (*sighandler_t)(int);
3867 +
3868 +#include "pkg.h"
3869 +#include "pkg_hash.h"
3870 +#include "pkg_extract.h"
3871 +
3872 +#include "ipkg_install.h"
3873 +#include "ipkg_configure.h"
3874 +#include "ipkg_download.h"
3875 +#include "ipkg_remove.h"
3876 +
3877 +#include "ipkg_utils.h"
3878 +#include "ipkg_message.h"
3879 +
3880 +#include "sprintf_alloc.h"
3881 +#include "file_util.h"
3882 +#include "str_util.h"
3883 +#include "xsystem.h"
3884 +#include "user.h"
3885 +
3886 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3887 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3888 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3889 +
3890 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3891 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3892 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3893 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3894 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3900 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3901 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3902 +
3903 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3904 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3905 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3906 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3907 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3908 +
3909 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3910 +
3911 +static int user_prefers_old_conffile(const char *file, const char *backup);
3912 +
3913 +static char *backup_filename_alloc(const char *file_name);
3914 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3915 +static int backup_exists_for(const char *file_name);
3916 +static int backup_remove(const char *file_name);
3917 +
3918 +
3919 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3920 +{
3921 + int err, cmp;
3922 + pkg_t *pkg, *old;
3923 + char *old_version, *new_version;
3924 +
3925 + pkg = pkg_new();
3926 + if (pkg == NULL) {
3927 + return ENOMEM;
3928 + }
3929 +
3930 + err = pkg_init_from_file(pkg, filename);
3931 + if (err) {
3932 + return err;
3933 + }
3934 +
3935 + if (!pkg->architecture) {
3936 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3937 + return -EINVAL;
3938 + }
3939 +
3940 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3941 + freeing the pkg that we pass in. It might be nice to clean this up
3942 + if possible. */
3943 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3944 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3945 +
3946 + pkg->local_filename = strdup(filename);
3947 +
3948 + if (old) {
3949 + old_version = pkg_version_str_alloc(old);
3950 + new_version = pkg_version_str_alloc(pkg);
3951 +
3952 + cmp = pkg_compare_versions(old, pkg);
3953 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3954 + cmp = -1 ; /* then we force ipkg to downgrade */
3955 + /* We need to use a value < 0 because in the 0 case we are asking to */
3956 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3957 + }
3958 + if (cmp > 0) {
3959 + ipkg_message(conf, IPKG_NOTICE,
3960 + "Not downgrading package %s on %s from %s to %s.\n",
3961 + old->name, old->dest->name, old_version, new_version);
3962 + pkg->state_want = SW_DEINSTALL;
3963 + pkg->state_flag |= SF_OBSOLETE;
3964 + free(old_version);
3965 + free(new_version);
3966 + return 0;
3967 + } else {
3968 + free(old_version);
3969 + free(new_version);
3970 + }
3971 + }
3972 +
3973 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3974 + return ipkg_install_pkg(conf, pkg);
3975 +}
3976 +
3977 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3978 +{
3979 + int cmp;
3980 + pkg_t *old, *new;
3981 + char *old_version, *new_version;
3982 +
3983 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3984 +
3985 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3986 + if (new == NULL) {
3987 + return IPKG_PKG_HAS_NO_CANDIDATE;
3988 + }
3989 +
3990 + new->state_flag |= SF_USER;
3991 + if (old) {
3992 + old_version = pkg_version_str_alloc(old);
3993 + new_version = pkg_version_str_alloc(new);
3994 +
3995 + cmp = pkg_compare_versions(old, new);
3996 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3997 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3998 + cmp = -1 ; /* then we force ipkg to downgrade */
3999 + /* We need to use a value < 0 because in the 0 case we are asking to */
4000 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4001 + }
4002 + ipkg_message(conf, IPKG_DEBUG,
4003 + "comparing visible versions of pkg %s:"
4004 + "\n\t%s is installed "
4005 + "\n\t%s is available "
4006 + "\n\t%d was comparison result\n",
4007 + pkg_name, old_version, new_version, cmp);
4008 + if (cmp == 0 && !conf->force_reinstall) {
4009 + ipkg_message(conf, IPKG_NOTICE,
4010 + "Package %s (%s) installed in %s is up to date.\n",
4011 + old->name, old_version, old->dest->name);
4012 + free(old_version);
4013 + free(new_version);
4014 + return 0;
4015 + } else if (cmp > 0) {
4016 + ipkg_message(conf, IPKG_NOTICE,
4017 + "Not downgrading package %s on %s from %s to %s.\n",
4018 + old->name, old->dest->name, old_version, new_version);
4019 + free(old_version);
4020 + free(new_version);
4021 + return 0;
4022 + } else if (cmp < 0) {
4023 + new->dest = old->dest;
4024 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4025 + }
4026 + }
4027 +
4028 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4029 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4030 + return any kind of integer, (might be errno from a syscall,
4031 + etc.). This is a real mess and will need to be cleaned up if
4032 + anyone ever wants to make a nice libipkg. */
4033 +
4034 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4035 + return ipkg_install_pkg(conf, new);
4036 +}
4037 +
4038 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4039 +{
4040 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4041 + int i;
4042 + ipkg_error_t err;
4043 + abstract_pkg_t *ppkg ;
4044 +
4045 + if (providers == NULL)
4046 + return IPKG_PKG_HAS_NO_CANDIDATE;
4047 +
4048 + for (i = 0; i < providers->len; i++) {
4049 + ppkg = abstract_pkg_vec_get(providers, i);
4050 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4051 + err = ipkg_install_by_name(conf, ppkg->name);
4052 + if (err)
4053 + return err;
4054 +/* XXX Maybe ppkg should be freed ? */
4055 + }
4056 + return 0;
4057 +}
4058 +
4059 +/*
4060 + * Walk dependence graph starting with pkg, collect packages to be
4061 + * installed into pkgs_needed, in dependence order.
4062 + */
4063 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4064 +{
4065 + int i, err;
4066 + pkg_vec_t *depends = pkg_vec_alloc();
4067 + char **unresolved = NULL;
4068 + int ndepends;
4069 +
4070 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4071 + pkg, depends,
4072 + &unresolved);
4073 +
4074 + if (unresolved) {
4075 + ipkg_message(conf, IPKG_ERROR,
4076 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4077 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4078 + while (*unresolved) {
4079 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4080 + unresolved++;
4081 + }
4082 + ipkg_message(conf, IPKG_ERROR, "\n");
4083 + if (! conf->force_depends) {
4084 + ipkg_message(conf, IPKG_INFO,
4085 + "This could mean that your package list is out of date or that the packages\n"
4086 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4087 + "of this problem try again with the '-force-depends' option.\n");
4088 + pkg_vec_free(depends);
4089 + return IPKG_PKG_DEPS_UNSATISFIED;
4090 + }
4091 + }
4092 +
4093 + if (ndepends <= 0) {
4094 + pkg_vec_free(depends);
4095 + return 0;
4096 + }
4097 +
4098 + for (i = 0; i < depends->len; i++) {
4099 + pkg_t *dep = depends->pkgs[i];
4100 + /* The package was uninstalled when we started, but another
4101 + dep earlier in this loop may have depended on it and pulled
4102 + it in, so check first. */
4103 + if ((dep->state_status != SS_INSTALLED)
4104 + && (dep->state_status != SS_UNPACKED)
4105 + && (dep->state_want != SW_INSTALL)) {
4106 +
4107 + /* Mark packages as to-be-installed */
4108 + dep->state_want = SW_INSTALL;
4109 +
4110 + /* Dependencies should be installed the same place as pkg */
4111 + if (dep->dest == NULL) {
4112 + dep->dest = pkg->dest;
4113 + }
4114 +
4115 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4116 + if (err) {
4117 + pkg_vec_free(depends);
4118 + return err;
4119 + }
4120 + }
4121 + }
4122 + if (pkgs_needed)
4123 + pkg_vec_insert(pkgs_needed, pkg);
4124 +
4125 + pkg_vec_free(depends);
4126 +
4127 + return 0;
4128 +}
4129 +
4130 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4131 +{
4132 + int cmp;
4133 + pkg_t *old, *new;
4134 + char *old_version, *new_version;
4135 +
4136 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4137 +
4138 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4139 + if (new == NULL) {
4140 + return IPKG_PKG_HAS_NO_CANDIDATE;
4141 + }
4142 + if (old) {
4143 + old_version = pkg_version_str_alloc(old);
4144 + new_version = pkg_version_str_alloc(new);
4145 +
4146 + cmp = pkg_compare_versions(old, new);
4147 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4148 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4149 + cmp = -1 ; /* then we force ipkg to downgrade */
4150 + /* We need to use a value < 0 because in the 0 case we are asking to */
4151 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4152 + }
4153 + ipkg_message(conf, IPKG_DEBUG,
4154 + "comparing visible versions of pkg %s:"
4155 + "\n\t%s is installed "
4156 + "\n\t%s is available "
4157 + "\n\t%d was comparison result\n",
4158 + pkg_name, old_version, new_version, cmp);
4159 + if (cmp == 0 && !conf->force_reinstall) {
4160 + ipkg_message(conf, IPKG_NOTICE,
4161 + "Package %s (%s) installed in %s is up to date.\n",
4162 + old->name, old_version, old->dest->name);
4163 + free(old_version);
4164 + free(new_version);
4165 + return 0;
4166 + } else if (cmp > 0) {
4167 + ipkg_message(conf, IPKG_NOTICE,
4168 + "Not downgrading package %s on %s from %s to %s.\n",
4169 + old->name, old->dest->name, old_version, new_version);
4170 + free(old_version);
4171 + free(new_version);
4172 + return 0;
4173 + } else if (cmp < 0) {
4174 + new->dest = old->dest;
4175 + old->state_want = SW_DEINSTALL;
4176 + old->state_flag |= SF_OBSOLETE;
4177 + }
4178 + }
4179 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4180 +}
4181 +
4182 +\f
4183 +
4184 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4185 +{
4186 + int i, err;
4187 + pkg_vec_t *depends = pkg_vec_alloc();
4188 + pkg_t *dep;
4189 + char **unresolved = NULL;
4190 + int ndepends;
4191 +
4192 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4193 + pkg, depends,
4194 + &unresolved);
4195 +
4196 + if (unresolved) {
4197 + ipkg_message(conf, IPKG_ERROR,
4198 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4199 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4200 + while (*unresolved) {
4201 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4202 + unresolved++;
4203 + }
4204 + ipkg_message(conf, IPKG_ERROR, "\n");
4205 + if (! conf->force_depends) {
4206 + ipkg_message(conf, IPKG_INFO,
4207 + "This could mean that your package list is out of date or that the packages\n"
4208 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4209 + "of this problem try again with the '-force-depends' option.\n");
4210 + pkg_vec_free(depends);
4211 + return IPKG_PKG_DEPS_UNSATISFIED;
4212 + }
4213 + }
4214 +
4215 + if (ndepends <= 0) {
4216 + return 0;
4217 + }
4218 +
4219 + /* Mark packages as to-be-installed */
4220 + for (i=0; i < depends->len; i++) {
4221 + /* Dependencies should be installed the same place as pkg */
4222 + if (depends->pkgs[i]->dest == NULL) {
4223 + depends->pkgs[i]->dest = pkg->dest;
4224 + }
4225 + depends->pkgs[i]->state_want = SW_INSTALL;
4226 + }
4227 +
4228 + for (i = 0; i < depends->len; i++) {
4229 + dep = depends->pkgs[i];
4230 + /* The package was uninstalled when we started, but another
4231 + dep earlier in this loop may have depended on it and pulled
4232 + it in, so check first. */
4233 + if ((dep->state_status != SS_INSTALLED)
4234 + && (dep->state_status != SS_UNPACKED)) {
4235 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4236 + err = ipkg_install_pkg(conf, dep);
4237 + if (err) {
4238 + pkg_vec_free(depends);
4239 + return err;
4240 + }
4241 + }
4242 + }
4243 +
4244 + pkg_vec_free(depends);
4245 +
4246 + return 0;