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