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