add aircrack-ng package (thanks to Gerd, closes: #572, #581).
[openwrt.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-y += $(LIBIPKG_CORE_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
208 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
209 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
210 +LIBIPKG-y += $(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-y += $(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 +0100
3623 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.c 2006-05-09 02:12:04.000000000 +0200
3624 @@ -0,0 +1,195 @@
3625 +/* ipkg_download.c - the itsy package management system
3626 +
3627 + Carl D. Worth
3628 +
3629 + Copyright (C) 2001 University of Southern California
3630 +
3631 + This program is free software; you can redistribute it and/or
3632 + modify it under the terms of the GNU General Public License as
3633 + published by the Free Software Foundation; either version 2, or (at
3634 + your option) any later version.
3635 +
3636 + This program is distributed in the hope that it will be useful, but
3637 + WITHOUT ANY WARRANTY; without even the implied warranty of
3638 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3639 + General Public License for more details.
3640 +*/
3641 +
3642 +#include "ipkg.h"
3643 +#include "ipkg_download.h"
3644 +#include "ipkg_message.h"
3645 +
3646 +#include "sprintf_alloc.h"
3647 +#include "xsystem.h"
3648 +#include "file_util.h"
3649 +#include "str_util.h"
3650 +
3651 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3652 +{
3653 + int err = 0;
3654 +
3655 + char *src_basec = strdup(src);
3656 + char *src_base = basename(src_basec);
3657 + char *tmp_file_location;
3658 + char *cmd;
3659 +
3660 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3661 +
3662 + fflush(stdout);
3663 +
3664 + if (str_starts_with(src, "file:")) {
3665 + int ret;
3666 + const char *file_src = src + 5;
3667 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3668 + ret = file_copy(src + 5, dest_file_name);
3669 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3670 + return ret;
3671 + }
3672 +
3673 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3674 + err = unlink(tmp_file_location);
3675 + if (err && errno != ENOENT) {
3676 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3677 + __FUNCTION__, tmp_file_location, strerror(errno));
3678 + free(tmp_file_location);
3679 + return errno;
3680 + }
3681 +
3682 + if (conf->http_proxy) {
3683 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3684 + setenv("http_proxy", conf->http_proxy, 1);
3685 + }
3686 + if (conf->ftp_proxy) {
3687 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3688 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3689 + }
3690 + if (conf->no_proxy) {
3691 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3692 + setenv("no_proxy", conf->no_proxy, 1);
3693 + }
3694 +
3695 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3696 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3697 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3698 + conf->proxy_user ? "--proxy-user=" : "",
3699 + conf->proxy_user ? conf->proxy_user : "",
3700 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3701 + conf->proxy_passwd ? conf->proxy_passwd : "",
3702 + conf->verbose_wget ? "" : "-q",
3703 + conf->tmp_dir,
3704 + src);
3705 + err = xsystem(cmd);
3706 + if (err) {
3707 + if (err != -1) {
3708 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3709 + __FUNCTION__, err, cmd);
3710 + }
3711 + unlink(tmp_file_location);
3712 + free(tmp_file_location);
3713 + free(src_basec);
3714 + free(cmd);
3715 + return EINVAL;
3716 + }
3717 + free(cmd);
3718 +
3719 + err = file_move(tmp_file_location, dest_file_name);
3720 +
3721 + free(tmp_file_location);
3722 + free(src_basec);
3723 +
3724 + if (err) {
3725 + return err;
3726 + }
3727 +
3728 + return 0;
3729 +}
3730 +
3731 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3732 +{
3733 + int err;
3734 + char *url;
3735 +
3736 + if (pkg->src == NULL) {
3737 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3738 + pkg->name, pkg->parent->name);
3739 + return -1;
3740 + }
3741 +
3742 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3743 +
3744 + /* XXX: BUG: The pkg->filename might be something like
3745 + "../../foo.ipk". While this is correct, and exactly what we
3746 + want to use to construct url above, here we actually need to
3747 + use just the filename part, without any directory. */
3748 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3749 +
3750 + err = ipkg_download(conf, url, pkg->local_filename);
3751 + free(url);
3752 +
3753 + return err;
3754 +}
3755 +
3756 +/*
3757 + * Downloads file from url, installs in package database, return package name.
3758 + */
3759 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3760 +{
3761 + int err = 0;
3762 + pkg_t *pkg;
3763 + pkg = pkg_new();
3764 + if (pkg == NULL)
3765 + return ENOMEM;
3766 +
3767 + if (str_starts_with(url, "http://")
3768 + || str_starts_with(url, "ftp://")) {
3769 + char *tmp_file;
3770 + char *file_basec = strdup(url);
3771 + char *file_base = basename(file_basec);
3772 +
3773 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3774 + err = ipkg_download(conf, url, tmp_file);
3775 + if (err)
3776 + return err;
3777 +
3778 + err = pkg_init_from_file(pkg, tmp_file);
3779 + if (err)
3780 + return err;
3781 + pkg->local_filename = strdup(tmp_file);
3782 +
3783 + free(tmp_file);
3784 + free(file_basec);
3785 +
3786 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3787 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3788 +
3789 + err = pkg_init_from_file(pkg, url);
3790 + if (err)
3791 + return err;
3792 + pkg->local_filename = strdup(url);
3793 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3794 + pkg->provided_by_hand = 1;
3795 +
3796 + } else {
3797 + pkg_deinit(pkg);
3798 + free(pkg);
3799 + return 0;
3800 + }
3801 +
3802 + if (!pkg->architecture) {
3803 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3804 + return -EINVAL;
3805 + }
3806 +
3807 + pkg->dest = conf->default_dest;
3808 + pkg->state_want = SW_INSTALL;
3809 + pkg->state_flag |= SF_PREFER;
3810 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3811 + if ( pkg == NULL ){
3812 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3813 + return 0;
3814 + }
3815 + if (namep) {
3816 + *namep = strdup(pkg->name);
3817 + }
3818 + return 0;
3819 +}
3820 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_download.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.h
3821 --- busybox-1.1.2-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3822 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-05-09 02:06:48.000000000 +0200
3823 @@ -0,0 +1,30 @@
3824 +/* ipkg_download.h - the itsy package management system
3825 +
3826 + Carl D. Worth
3827 +
3828 + Copyright (C) 2001 University of Southern California
3829 +
3830 + This program is free software; you can redistribute it and/or
3831 + modify it under the terms of the GNU General Public License as
3832 + published by the Free Software Foundation; either version 2, or (at
3833 + your option) any later version.
3834 +
3835 + This program is distributed in the hope that it will be useful, but
3836 + WITHOUT ANY WARRANTY; without even the implied warranty of
3837 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3838 + General Public License for more details.
3839 +*/
3840 +
3841 +#ifndef IPKG_DOWNLOAD_H
3842 +#define IPKG_DOWNLOAD_H
3843 +
3844 +#include "ipkg_conf.h"
3845 +
3846 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3847 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3848 +/*
3849 + * Downloads file from url, installs in package database, return package name.
3850 + */
3851 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3852 +
3853 +#endif
3854 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_includes.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_includes.h
3855 --- busybox-1.1.2-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3856 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-05-09 02:06:48.000000000 +0200
3857 @@ -0,0 +1,79 @@
3858 +#ifndef IPKG_INCLUDES_H
3859 +#define IPKG_INCLUDES_H
3860 +
3861 +/* Define to 1 if you have the <memory.h> header file. */
3862 +#define HAVE_MEMORY_H 1
3863 +
3864 +/* Define to 1 if you have the <regex.h> header file. */
3865 +#define HAVE_REGEX_H 1
3866 +
3867 +/* Define to 1 if you have the <stdlib.h> header file. */
3868 +#define HAVE_STDLIB_H 1
3869 +
3870 +/* Define to 1 if you have the <strings.h> header file. */
3871 +#define HAVE_STRINGS_H 1
3872 +
3873 +/* Define to 1 if you have the <string.h> header file. */
3874 +#define HAVE_STRING_H 1
3875 +
3876 +/* Define to 1 if you have the <sys/stat.h> header file. */
3877 +#define HAVE_SYS_STAT_H 1
3878 +
3879 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3880 +#define HAVE_SYS_WAIT_H 1
3881 +
3882 +/* Define to 1 if you have the <unistd.h> header file. */
3883 +#define HAVE_UNISTD_H 1
3884 +
3885 +/* Define to 1 if you have the ANSI C header files. */
3886 +#define STDC_HEADERS 1
3887 +
3888 +
3889 +#include <stdio.h>
3890 +
3891 +#if STDC_HEADERS
3892 +# include <stdlib.h>
3893 +# include <stdarg.h>
3894 +# include <stddef.h>
3895 +# include <ctype.h>
3896 +# include <errno.h>
3897 +#else
3898 +# if HAVE_STDLIB_H
3899 +# include <stdlib.h>
3900 +# endif
3901 +#endif
3902 +
3903 +#if HAVE_REGEX_H
3904 +# include <regex.h>
3905 +#endif
3906 +
3907 +#if HAVE_STRING_H
3908 +# if !STDC_HEADERS && HAVE_MEMORY_H
3909 +# include <memory.h>
3910 +# endif
3911 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3912 +# if __GNUC__
3913 +# define __USE_GNU 1
3914 +# endif
3915 +# include <string.h>
3916 +# undef __USE_GNU
3917 +#endif
3918 +
3919 +#if HAVE_STRINGS_H
3920 +# include <strings.h>
3921 +#endif
3922 +
3923 +#if HAVE_SYS_STAT_H
3924 +# include <sys/stat.h>
3925 +#endif
3926 +
3927 +#if HAVE_SYS_WAIT_H
3928 +# include <sys/wait.h>
3929 +#endif
3930 +
3931 +#if HAVE_UNISTD_H
3932 +# include <sys/types.h>
3933 +# include <unistd.h>
3934 +#endif
3935 +
3936 +#endif /* IPKG_INCLUDES_H */
3937 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_install.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.c
3938 --- busybox-1.1.2-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3939 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-05-09 02:12:04.000000000 +0200
3940 @@ -0,0 +1,1942 @@
3941 +/* ipkg_install.c - the itsy package management system
3942 +
3943 + Carl D. Worth
3944 +
3945 + Copyright (C) 2001 University of Southern California
3946 +
3947 + This program is free software; you can redistribute it and/or
3948 + modify it under the terms of the GNU General Public License as
3949 + published by the Free Software Foundation; either version 2, or (at
3950 + your option) any later version.
3951 +
3952 + This program is distributed in the hope that it will be useful, but
3953 + WITHOUT ANY WARRANTY; without even the implied warranty of
3954 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3955 + General Public License for more details.
3956 +*/
3957 +
3958 +#include "ipkg.h"
3959 +#include <errno.h>
3960 +#include <dirent.h>
3961 +#include <glob.h>
3962 +#include <time.h>
3963 +#include <signal.h>
3964 +typedef void (*sighandler_t)(int);
3965 +
3966 +#include "pkg.h"
3967 +#include "pkg_hash.h"
3968 +#include "pkg_extract.h"
3969 +
3970 +#include "ipkg_install.h"
3971 +#include "ipkg_configure.h"
3972 +#include "ipkg_download.h"
3973 +#include "ipkg_remove.h"
3974 +
3975 +#include "ipkg_utils.h"
3976 +#include "ipkg_message.h"
3977 +
3978 +#include "sprintf_alloc.h"
3979 +#include "file_util.h"
3980 +#include "str_util.h"
3981 +#include "xsystem.h"
3982 +#include "user.h"
3983 +
3984 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3985 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3986 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3987 +
3988 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3989 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3990 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3991 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3992 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3993 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3994 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3995 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3996 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3997 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3998 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3999 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4000 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4001 +
4002 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4003 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4004 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
4005 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
4006 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
4007 +
4008 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
4009 +
4010 +static int user_prefers_old_conffile(const char *file, const char *backup);
4011 +
4012 +static char *backup_filename_alloc(const char *file_name);
4013 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
4014 +static int backup_exists_for(const char *file_name);
4015 +static int backup_remove(const char *file_name);
4016 +
4017 +
4018 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
4019 +{
4020 + int err, cmp;
4021 + pkg_t *pkg, *old;
4022 + char *old_version, *new_version;
4023 +
4024 + pkg = pkg_new();
4025 + if (pkg == NULL) {
4026 + return ENOMEM;
4027 + }
4028 +
4029 + err = pkg_init_from_file(pkg, filename);
4030 + if (err) {
4031 + return err;
4032 + }
4033 +
4034 + if (!pkg->architecture) {
4035 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
4036 + return -EINVAL;
4037 + }
4038 +
4039 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
4040 + freeing the pkg that we pass in. It might be nice to clean this up
4041 + if possible. */
4042 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
4043 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4044 +
4045 + pkg->local_filename = strdup(filename);
4046 +
4047 + if (old) {
4048 + old_version = pkg_version_str_alloc(old);
4049 + new_version = pkg_version_str_alloc(pkg);
4050 +
4051 + cmp = pkg_compare_versions(old, pkg);
4052 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4053 + cmp = -1 ; /* then we force ipkg to downgrade */
4054 + /* We need to use a value < 0 because in the 0 case we are asking to */
4055 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4056 + }
4057 + if (cmp > 0) {
4058 + ipkg_message(conf, IPKG_NOTICE,
4059 + "Not downgrading package %s on %s from %s to %s.\n",
4060 + old->name, old->dest->name, old_version, new_version);
4061 + pkg->state_want = SW_DEINSTALL;
4062 + pkg->state_flag |= SF_OBSOLETE;
4063 + free(old_version);
4064 + free(new_version);
4065 + return 0;
4066 + } else {
4067 + free(old_version);
4068 + free(new_version);
4069 + }
4070 + }
4071 +
4072 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4073 + return ipkg_install_pkg(conf, pkg,0);
4074 +}
4075 +
4076 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
4077 +{
4078 + int cmp;
4079 + pkg_t *old, *new;
4080 + char *old_version, *new_version;
4081 +
4082 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
4083 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4084 + if ( old )
4085 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
4086 +
4087 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
4088 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4089 + if ( new )
4090 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
4091 +
4092 +/* Pigi Basically here is broken the version stuff.
4093 + What's happening is that nothing provide the version to differents
4094 + functions, so the returned struct is always the latest.
4095 + That's why the install by name don't work.
4096 +*/
4097 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
4098 +
4099 + if ( old )
4100 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
4101 + if ( new )
4102 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
4103 + ipkg_message(conf, IPKG_DEBUG2, " \n");
4104 +
4105 + if (new == NULL) {
4106 + return IPKG_PKG_HAS_NO_CANDIDATE;
4107 + }
4108 +
4109 + new->state_flag |= SF_USER;
4110 + if (old) {
4111 + old_version = pkg_version_str_alloc(old);
4112 + new_version = pkg_version_str_alloc(new);
4113 +
4114 + cmp = pkg_compare_versions(old, new);
4115 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4116 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
4117 + cmp = -1 ; /* then we force ipkg to downgrade */
4118 + /* We need to use a value < 0 because in the 0 case we are asking to */
4119 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4120 + }
4121 + ipkg_message(conf, IPKG_DEBUG,
4122 + "Comparing visible versions of pkg %s:"
4123 + "\n\t%s is installed "
4124 + "\n\t%s is available "
4125 + "\n\t%d was comparison result\n",
4126 + pkg_name, old_version, new_version, cmp);
4127 + if (cmp == 0 && !conf->force_reinstall) {
4128 + ipkg_message(conf, IPKG_NOTICE,
4129 + "Package %s (%s) installed in %s is up to date.\n",
4130 + old->name, old_version, old->dest->name);
4131 + free(old_version);
4132 + free(new_version);
4133 + return 0;
4134 + } else if (cmp > 0) {
4135 + ipkg_message(conf, IPKG_NOTICE,
4136 + "Not downgrading package %s on %s from %s to %s.\n",
4137 + old->name, old->dest->name, old_version, new_version);
4138 + free(old_version);
4139 + free(new_version);
4140 + return 0;
4141 + } else if (cmp < 0) {
4142 + new->dest = old->dest;
4143 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4144 + }
4145 + }
4146 +
4147 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4148 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4149 + return any kind of integer, (might be errno from a syscall,
4150 + etc.). This is a real mess and will need to be cleaned up if
4151 + anyone ever wants to make a nice libipkg. */
4152 +
4153 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4154 + return ipkg_install_pkg(conf, new,0);
4155 +}
4156 +
4157 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4158 +{
4159 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4160 + int i;
4161 + ipkg_error_t err;
4162 + abstract_pkg_t *ppkg ;
4163 +
4164 + if (providers == NULL)
4165 + return IPKG_PKG_HAS_NO_CANDIDATE;
4166 +
4167 + for (i = 0; i < providers->len; i++) {
4168 + ppkg = abstract_pkg_vec_get(providers, i);
4169 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4170 + err = ipkg_install_by_name(conf, ppkg->name);
4171 + if (err)
4172 + return err;
4173 +/* XXX Maybe ppkg should be freed ? */
4174 + }
4175 + return 0;
4176 +}
4177 +
4178 +/*
4179 + * Walk dependence graph starting with pkg, collect packages to be
4180 + * installed into pkgs_needed, in dependence order.
4181 + */
4182 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4183 +{
4184 + int i, err;
4185 + pkg_vec_t *depends = pkg_vec_alloc();
4186 + char **unresolved = NULL;
4187 + int ndepends;
4188 +
4189 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4190 + pkg, depends,
4191 + &unresolved);
4192 +
4193 + if (unresolved) {
4194 + ipkg_message(conf, IPKG_ERROR,
4195 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4196 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4197 + while (*unresolved) {
4198 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4199 + unresolved++;
4200 + }
4201 + ipkg_message(conf, IPKG_ERROR, "\n");
4202 + if (! conf->force_depends) {
4203 + ipkg_message(conf, IPKG_INFO,
4204 + "This could mean that your package list is out of date or that the packages\n"
4205 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4206 + "of this problem try again with the '-force-depends' option.\n");
4207 + pkg_vec_free(depends);
4208 + return IPKG_PKG_DEPS_UNSATISFIED;
4209 + }
4210 + }
4211 +
4212 + if (ndepends <= 0) {
4213 + pkg_vec_free(depends);
4214 + return 0;
4215 + }
4216 +
4217 + for (i = 0; i < depends->len; i++) {
4218 + pkg_t *dep = depends->pkgs[i];
4219 + /* The package was uninstalled when we started, but another
4220 + dep earlier in this loop may have depended on it and pulled
4221 + it in, so check first. */
4222 + if ((dep->state_status != SS_INSTALLED)
4223 + && (dep->state_status != SS_UNPACKED)
4224 + && (dep->state_want != SW_INSTALL)) {
4225 +
4226 + /* Mark packages as to-be-installed */
4227 + dep->state_want = SW_INSTALL;
4228 +
4229 + /* Dependencies should be installed the same place as pkg */
4230 + if (dep->dest == NULL) {
4231 + dep->dest = pkg->dest;
4232 + }
4233 +
4234 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4235 + if (err) {
4236 + pkg_vec_free(depends);
4237 + return err;
4238 + }
4239 + }
4240 + }
4241 + if (pkgs_needed)
4242 + pkg_vec_insert(pkgs_needed, pkg);
4243 +
4244 + pkg_vec_free(depends);
4245 +
4246 + return 0;
4247 +}
4248 +
4249 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4250 +{
4251 + int cmp;
4252 + pkg_t *old, *new;
4253 + char *old_version, *new_version;
4254 +
4255 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4256 +
4257 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4258 + if (new == NULL) {
4259 + return IPKG_PKG_HAS_NO_CANDIDATE;
4260 + }
4261 + if (old) {
4262 + old_version = pkg_version_str_alloc(old);
4263 + new_version = pkg_version_str_alloc(new);
4264 +
4265 + cmp = pkg_compare_versions(old, new);
4266 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4267 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4268 + cmp = -1 ; /* then we force ipkg to downgrade */
4269 + /* We need to use a value < 0 because in the 0 case we are asking to */
4270 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4271 + }
4272 + ipkg_message(conf, IPKG_DEBUG,
4273 + "comparing visible versions of pkg %s:"
4274 + "\n\t%s is installed "
4275 + "\n\t%s is available "
4276 + "\n\t%d was comparison result\n",
4277 + pkg_name, old_version, new_version, cmp);
4278 + if (cmp == 0 && !conf->force_reinstall) {
4279 + ipkg_message(conf, IPKG_NOTICE,
4280 + "Package %s (%s) installed in %s is up to date.\n",
4281 + old->name, old_version, old->dest->name);
4282 + free(old_version);
4283 + free(new_version);
4284 + return 0;
4285 + } else if (cmp > 0) {
4286 + ipkg_message(conf, IPKG_NOTICE,
4287 + "Not downgrading package %s on %s from %s to %s.\n",
4288 + old->name, old->dest->name, old_version, new_version);
4289 + free(old_version);
4290 + free(new_version);
4291 + return 0;
4292 + } else if (cmp < 0) {
4293 + new->dest = old->dest;
4294 + old->state_want = SW_DEINSTALL;
4295 + old->state_flag |= SF_OBSOLETE;
4296 + }
4297 + }
4298 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4299 +}
4300 +
4301 +\f
4302 +
4303 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4304 +{
4305 + int i, err;
4306 + pkg_vec_t *depends = pkg_vec_alloc();
4307 + pkg_t *dep;
4308 + char **unresolved = NULL;
4309 + int ndepends;
4310 +
4311 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4312 + pkg, depends,
4313 + &unresolved);
4314 +
4315 + if (unresolved) {
4316 + ipkg_message(conf, IPKG_ERROR,
4317 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4318 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4319 + while (*unresolved) {
4320 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4321 + unresolved++;
4322 + }
4323 + ipkg_message(conf, IPKG_ERROR, "\n");
4324 + if (! conf->force_depends) {
4325 + ipkg_message(conf, IPKG_INFO,
4326 + "This could mean that your package list is out of date or that the packages\n"
4327 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4328 + "of this problem try again with the '-force-depends' option.\n");
4329 + pkg_vec_free(depends);
4330 + return IPKG_PKG_DEPS_UNSATISFIED;
4331 + }
4332 + }
4333 +
4334 + if (ndepends <= 0) {
4335 + return 0;
4336 + }
4337 +
4338 + /* Mark packages as to-be-installed */
4339 + for (i=0; i < depends->len; i++) {
4340 + /* Dependencies should be installed the same place as pkg */
4341 + if (depends->pkgs[i]->dest == NULL) {
4342 + depends->pkgs[i]->dest = pkg->dest;
4343 + }
4344 + depends->pkgs[i]->state_want = SW_INSTALL;
4345 + }
4346 +
4347 + for (i = 0; i < depends->len; i++) {
4348 + dep = depends->pkgs[i];
4349 + /* The package was uninstalled when we started, but another
4350 + dep earlier in this loop may have depended on it and pulled
4351 + it in, so check first. */
4352 + if ((dep->state_status != SS_INSTALLED)
4353 + && (dep->state_status != SS_UNPACKED)) {
4354 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4355 + err = ipkg_install_pkg(conf, dep,0);
4356 + if (err) {
4357 + pkg_vec_free(depends);
4358 + return err;
4359 + }
4360 + }
4361 + }
4362 +
4363 + pkg_vec_free(depends);
4364 +
4365 + return 0;
4366 +}
4367 +
4368 +
4369 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4370 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4371 +{
4372 + if (conf->nodeps == 0) {
4373 + int i;
4374 + pkg_vec_t *installed = pkg_vec_alloc();
4375 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4376 + for (i = 0; i < installed->len; i++) {
4377 + pkg_t *pkg = installed->pkgs[i];
4378 + satisfy_dependencies_for(conf, pkg);
4379 + }
4380 + pkg_vec_free(installed);
4381 + }
4382 + return 0;
4383 +}
4384 +
4385 +\f
4386 +
4387 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4388 +{
4389 + int i;
4390 + pkg_vec_t *conflicts = NULL;
4391 + int level;
4392 + const char *prefix;
4393 + if (conf->force_depends) {
4394 + level = IPKG_NOTICE;
4395 + prefix = "Warning";
4396 + } else {
4397 + level = IPKG_ERROR;
4398 + prefix = "ERROR";
4399 + }
4400 +
4401 + if (!conf->force_depends)
4402 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4403 +
4404 + if (conflicts) {
4405 + ipkg_message(conf, level,
4406 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4407 + i = 0;
4408 + while (i < conflicts->len)
4409 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4410 + ipkg_message(conf, level, "\n");
4411 + pkg_vec_free(conflicts);
4412 + return IPKG_PKG_DEPS_UNSATISFIED;
4413 + }
4414 + return 0;
4415 +}
4416 +
4417 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4418 +{
4419 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4420 + str_list_elt_t *iter;
4421 +
4422 + for (iter = new_list->head; iter; iter = iter->next) {
4423 + char *new_file = iter->data;
4424 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4425 + if (!new_file)
4426 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4427 + if (!owner || (owner == old_pkg))
4428 + file_hash_set_file_owner(conf, new_file, new_pkg);
4429 + }
4430 + if (old_pkg) {
4431 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4432 + for (iter = old_list->head; iter; iter = iter->next) {
4433 + char *old_file = iter->data;
4434 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4435 + if (owner == old_pkg) {
4436 + /* obsolete */
4437 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4438 + }
4439 + }
4440 + }
4441 + return 0;
4442 +}
4443 +
4444 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4445 +{
4446 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4447 +
4448 + /* sma 6.20.02: yup; here's the first bit */
4449 + /*
4450 + * XXX: BUG easy for cworth
4451 + * 1) please point the call below to the correct current root destination
4452 + * 2) we need to resolve how to check the required space for a pending pkg,
4453 + * my diddling with the .ipk file size below isn't going to cut it.
4454 + * 3) return a proper error code instead of 1
4455 + */
4456 + int comp_size, blocks_available;
4457 +
4458 + if (!conf->force_space && pkg->installed_size != NULL) {
4459 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4460 +
4461 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4462 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4463 + comp_size = (int)((comp_size + 1023) / 1024);
4464 +
4465 + if (comp_size >= blocks_available) {
4466 + ipkg_message(conf, IPKG_ERROR,
4467 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4468 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4469 + return ENOSPC;
4470 + }
4471 + }
4472 + return 0;
4473 +}
4474 +
4475 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4476 +{
4477 + int err;
4478 + char *conffiles_file_name;
4479 + char *root_dir;
4480 + FILE *conffiles_file;
4481 +
4482 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4483 +
4484 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4485 + if (pkg->tmp_unpack_dir == NULL) {
4486 + ipkg_message(conf, IPKG_ERROR,
4487 + "%s: Failed to create temporary directory '%s': %s\n",
4488 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4489 + return errno;
4490 + }
4491 +
4492 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4493 + if (err) {
4494 + return err;
4495 + }
4496 +
4497 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4498 + conffiles. Seems like I should be able to get everything to go
4499 + through pkg_init_from_file. If so, maybe it would make sense to
4500 + move all of unpack_pkg_control_files to that function. */
4501 +
4502 + /* Don't need to re-read conffiles if we already have it */
4503 + if (pkg->conffiles.head) {
4504 + return 0;
4505 + }
4506 +
4507 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4508 + if (! file_exists(conffiles_file_name)) {
4509 + free(conffiles_file_name);
4510 + return 0;
4511 + }
4512 +
4513 + conffiles_file = fopen(conffiles_file_name, "r");
4514 + if (conffiles_file == NULL) {
4515 + fprintf(stderr, "%s: failed to open %s: %s\n",
4516 + __FUNCTION__, conffiles_file_name, strerror(errno));
4517 + free(conffiles_file_name);
4518 + return errno;
4519 + }
4520 + free(conffiles_file_name);
4521 +
4522 + while (1) {
4523 + char *cf_name;
4524 + char *cf_name_in_dest;
4525 +
4526 + cf_name = file_read_line_alloc(conffiles_file);
4527 + if (cf_name == NULL) {
4528 + break;
4529 + }
4530 + str_chomp(cf_name);
4531 + if (cf_name[0] == '\0') {
4532 + continue;
4533 + }
4534 +
4535 + /* Prepend dest->root_dir to conffile name.
4536 + Take pains to avoid multiple slashes. */
4537 + root_dir = pkg->dest->root_dir;
4538 + if (conf->offline_root)
4539 + /* skip the offline_root prefix */
4540 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4541 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4542 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4543 +
4544 + /* Can't get an md5sum now, (file isn't extracted yet).
4545 + We'll wait until resolve_conffiles */
4546 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4547 +
4548 + free(cf_name);
4549 + free(cf_name_in_dest);
4550 + }
4551 +
4552 + fclose(conffiles_file);
4553 +
4554 + return 0;
4555 +}
4556 +
4557 +/* returns number of installed replacees */
4558 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4559 +{
4560 + abstract_pkg_t **replaces = pkg->replaces;
4561 + int replaces_count = pkg->replaces_count;
4562 + int i, j;
4563 + for (i = 0; i < replaces_count; i++) {
4564 + abstract_pkg_t *ab_pkg = replaces[i];
4565 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4566 + if (pkg_vec) {
4567 + for (j = 0; j < pkg_vec->len; j++) {
4568 + pkg_t *replacee = pkg_vec->pkgs[j];
4569 + if (!pkg_conflicts(pkg, replacee))
4570 + continue;
4571 + if (replacee->state_status == SS_INSTALLED) {
4572 + pkg_vec_insert(installed_replacees, replacee);
4573 + }
4574 + }
4575 + }
4576 + }
4577 + return installed_replacees->len;
4578 +}
4579 +
4580 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4581 +{
4582 + int i;
4583 + int replaces_count = replacees->len;
4584 + for (i = 0; i < replaces_count; i++) {
4585 + pkg_t *replacee = replacees->pkgs[i];
4586 + int err;
4587 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4588 + err = ipkg_remove_pkg(conf, replacee,0);
4589 + if (err)
4590 + return err;
4591 + }
4592 + return 0;
4593 +}
4594 +
4595 +/* to unwind the removal: make sure they are installed */
4596 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4597 +{
4598 + int i, err;
4599 + int replaces_count = replacees->len;
4600 + for (i = 0; i < replaces_count; i++) {
4601 + pkg_t *replacee = replacees->pkgs[i];
4602 + if (replacee->state_status != SS_INSTALLED) {
4603 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4604 + err = ipkg_install_pkg(conf, replacee,0);
4605 + if (err)
4606 + return err;
4607 + }
4608 + }
4609 + return 0;
4610 +}
4611 +
4612 +int caught_sigint = 0;
4613 +static void ipkg_install_pkg_sigint_handler(int sig)
4614 +{
4615 + caught_sigint = sig;
4616 +}
4617 +
4618 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4619 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4620 +{
4621 + if (old_pkg) {
4622 + char message_out[15];
4623 + char *old_version = pkg_version_str_alloc(old_pkg);
4624 + char *new_version = pkg_version_str_alloc(pkg);
4625 + int cmp = pkg_compare_versions(old_pkg, pkg);
4626 + int rc = 0;
4627 +
4628 + memset(message_out,'\x0',15);
4629 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4630 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4631 + cmp = -1 ; /* then we force ipkg to downgrade */
4632 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4633 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4634 + }
4635 +
4636 + if (cmp > 0) {
4637 + ipkg_message(conf, IPKG_NOTICE,
4638 + "Not downgrading package %s on %s from %s to %s.\n",
4639 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4640 + rc = 1;
4641 + } else if (cmp < 0) {
4642 + ipkg_message(conf, IPKG_NOTICE,
4643 + "%s%s on %s from %s to %s...\n",
4644 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4645 + pkg->dest = old_pkg->dest;
4646 + rc = 0;
4647 + } else /* cmp == 0 */ {
4648 + if (conf->force_reinstall) {
4649 + ipkg_message(conf, IPKG_NOTICE,
4650 + "Reinstalling %s (%s) on %s...\n",
4651 + pkg->name, new_version, old_pkg->dest->name);
4652 + pkg->dest = old_pkg->dest;
4653 + rc = 0;
4654 + } else {
4655 + ipkg_message(conf, IPKG_NOTICE,
4656 + "Not installing %s (%s) on %s -- already installed.\n",
4657 + pkg->name, new_version, old_pkg->dest->name);
4658 + rc = 1;
4659 + }
4660 + }
4661 + free(old_version);
4662 + free(new_version);
4663 + return rc;
4664 + } else {
4665 + char message_out[15] ;
4666 + memset(message_out,'\x0',15);
4667 + if ( message )
4668 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4669 + else
4670 + strncpy( message_out,"Installing ",strlen("Installing ") );
4671 + char *version = pkg_version_str_alloc(pkg);
4672 +
4673 + ipkg_message(conf, IPKG_NOTICE,
4674 + "%s%s (%s) to %s...\n", message_out,
4675 + pkg->name, version, pkg->dest->name);
4676 + free(version);
4677 + return 0;
4678 + }
4679 +}
4680 +
4681 +/* and now the meat... */
4682 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4683 +{
4684 + int err = 0;
4685 + int message = 0;
4686 + pkg_t *old_pkg = NULL;
4687 + pkg_vec_t *replacees;
4688 + abstract_pkg_t *ab_pkg = NULL;
4689 + int old_state_flag;
4690 + char* file_md5;
4691 +
4692 +
4693 + if ( from_upgrade )
4694 + message = 1; /* Coming from an upgrade, and should change the output message */
4695 +
4696 + if (!pkg) {
4697 + ipkg_message(conf, IPKG_ERROR,
4698 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4699 + return -EINVAL;
4700 + }
4701 +
4702 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4703 +
4704 + if (!pkg_arch_supported(conf, pkg)) {
4705 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4706 + pkg->architecture, pkg->name);
4707 + return -EINVAL;
4708 + }
4709 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4710 + err = satisfy_dependencies_for(conf, pkg);
4711 + if (err) { return err; }
4712 +
4713 + ipkg_message(conf, IPKG_NOTICE,
4714 + "Package %s is already installed in %s.\n",
4715 + pkg->name, pkg->dest->name);
4716 + return 0;
4717 + }
4718 +
4719 + if (pkg->dest == NULL) {
4720 + pkg->dest = conf->default_dest;
4721 + }
4722 +
4723 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4724 +
4725 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4726 + if (err) { return err; }
4727 +
4728 + pkg->state_want = SW_INSTALL;
4729 + if (old_pkg){
4730 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4731 + }
4732 +
4733 +
4734 + /* Abhaya: conflicts check */
4735 + err = check_conflicts_for(conf, pkg);
4736 + if (err) { return err; }
4737 +
4738 + /* this setup is to remove the upgrade scenario in the end when
4739 + installing pkg A, A deps B & B deps on A. So both B and A are
4740 + installed. Then A's installation is started resulting in an
4741 + uncecessary upgrade */
4742 + if (pkg->state_status == SS_INSTALLED
4743 + && conf->force_reinstall == 0) return 0;
4744 +
4745 + err = verify_pkg_installable(conf, pkg);
4746 + if (err) { return err; }
4747 +
4748 + if (pkg->local_filename == NULL) {
4749 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4750 + if (err) {
4751 + ipkg_message(conf, IPKG_ERROR,
4752 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4753 + pkg->name);
4754 + return err;
4755 + }
4756 + }
4757 +
4758 +/* Check for md5 values */
4759 + if (pkg->md5sum)
4760 + {
4761 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4762 + if (strcmp(file_md5, pkg->md5sum))
4763 + {
4764 + ipkg_message(conf, IPKG_ERROR,
4765 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4766 + pkg->name);
4767 + free(file_md5);
4768 + return err;
4769 + }
4770 + free(file_md5);
4771 + }
4772 +
4773 + if (pkg->tmp_unpack_dir == NULL) {
4774 + unpack_pkg_control_files(conf, pkg);
4775 + }
4776 +
4777 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4778 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4779 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4780 + err = update_file_ownership(conf, pkg, old_pkg);
4781 + if (err) { return err; }
4782 +
4783 + if (conf->nodeps == 0) {
4784 + err = satisfy_dependencies_for(conf, pkg);
4785 + if (err) { return err; }
4786 + }
4787 +
4788 + replacees = pkg_vec_alloc();
4789 + pkg_get_installed_replacees(conf, pkg, replacees);
4790 +
4791 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4792 + {
4793 + sigset_t newset, oldset;
4794 + sighandler_t old_handler = NULL;
4795 + int use_signal = 0;
4796 + caught_sigint = 0;
4797 + if (use_signal) {
4798 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4799 + } else {
4800 + sigemptyset(&newset);
4801 + sigaddset(&newset, SIGINT);
4802 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4803 + }
4804 +
4805 + ipkg_state_changed++;
4806 + pkg->state_flag |= SF_FILELIST_CHANGED;
4807 +
4808 + /* XXX: BUG: we really should treat replacement more like an upgrade
4809 + * Instead, we're going to remove the replacees
4810 + */
4811 + err = pkg_remove_installed_replacees(conf, replacees);
4812 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4813 +
4814 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4815 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4816 +
4817 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4818 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4819 +
4820 + err = preinst_configure(conf, pkg, old_pkg);
4821 + if (err) goto UNWIND_PREINST_CONFIGURE;
4822 +
4823 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4824 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4825 +
4826 + err = check_data_file_clashes(conf, pkg, old_pkg);
4827 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4828 +
4829 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4830 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4831 +
4832 + if (conf->noaction) return 0;
4833 +
4834 + /* point of no return: no unwinding after this */
4835 + if (old_pkg && !conf->force_reinstall) {
4836 + old_pkg->state_want = SW_DEINSTALL;
4837 +
4838 + if (old_pkg->state_flag & SF_NOPRUNE) {
4839 + ipkg_message(conf, IPKG_INFO,
4840 + " not removing obsolesced files because package marked noprune\n");
4841 + } else {
4842 + ipkg_message(conf, IPKG_INFO,
4843 + " removing obsolesced files\n");
4844 + remove_obsolesced_files(conf, pkg, old_pkg);
4845 + }
4846 + /* removing files from old package, to avoid ghost files */
4847 + remove_data_files_and_list(conf, old_pkg);
4848 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4849 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4850 + remove_postrm(conf, old_pkg);
4851 +/* Pigi */
4852 +
4853 + }
4854 +
4855 +
4856 + ipkg_message(conf, IPKG_INFO,
4857 + " installing maintainer scripts\n");
4858 + install_maintainer_scripts(conf, pkg, old_pkg);
4859 +
4860 + /* the following just returns 0 */
4861 + remove_disappeared(conf, pkg);
4862 +
4863 + ipkg_message(conf, IPKG_INFO,
4864 + " installing data files\n");
4865 + install_data_files(conf, pkg);
4866 +
4867 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4868 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4869 +
4870 + ipkg_message(conf, IPKG_INFO,
4871 + " resolving conf files\n");
4872 + resolve_conffiles(conf, pkg);
4873 +
4874 + pkg->state_status = SS_UNPACKED;
4875 + old_state_flag = pkg->state_flag;
4876 + pkg->state_flag &= ~SF_PREFER;
4877 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4878 +
4879 + if (old_pkg && !conf->force_reinstall) {
4880 + old_pkg->state_status = SS_NOT_INSTALLED;
4881 + }
4882 +
4883 + time(&pkg->installed_time);
4884 +
4885 + ipkg_message(conf, IPKG_INFO,
4886 + " cleanup temp files\n");
4887 + cleanup_temporary_files(conf, pkg);
4888 +
4889 + ab_pkg = pkg->parent;
4890 + if (ab_pkg)
4891 + ab_pkg->state_status = pkg->state_status;
4892 +
4893 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4894 +
4895 + if (use_signal)
4896 + signal(SIGINT, old_handler);
4897 + else
4898 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4899 +
4900 + return 0;
4901 +
4902 +
4903 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4904 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4905 + UNWIND_CHECK_DATA_FILE_CLASHES:
4906 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4907 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4908 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4909 + UNWIND_PREINST_CONFIGURE:
4910 + preinst_configure_unwind(conf, pkg, old_pkg);
4911 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4912 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4913 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4914 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4915 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4916 + pkg_remove_installed_replacees_unwind(conf, replacees);
4917 +
4918 + ipkg_message(conf, IPKG_INFO,
4919 + " cleanup temp files\n");
4920 + cleanup_temporary_files(conf, pkg);
4921 +
4922 + ipkg_message(conf, IPKG_INFO,
4923 + "Failed.\n");
4924 + if (use_signal)
4925 + signal(SIGINT, old_handler);
4926 + else
4927 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4928 +
4929 + return err;
4930 + }
4931 +}
4932 +
4933 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4934 +{
4935 + /* DPKG_INCOMPATIBILITY:
4936 + dpkg does some things here that we don't do yet. Do we care?
4937 +
4938 + 1. If a version of the package is already installed, call
4939 + old-prerm upgrade new-version
4940 + 2. If the script runs but exits with a non-zero exit status
4941 + new-prerm failed-upgrade old-version
4942 + Error unwind, for both the above cases:
4943 + old-postinst abort-upgrade new-version
4944 + */
4945 + return 0;
4946 +}
4947 +
4948 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4949 +{
4950 + /* DPKG_INCOMPATIBILITY:
4951 + dpkg does some things here that we don't do yet. Do we care?
4952 + (See prerm_upgrade_old_package for details)
4953 + */
4954 + return 0;
4955 +}
4956 +
4957 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4958 +{
4959 + /* DPKG_INCOMPATIBILITY:
4960 + dpkg does some things here that we don't do yet. Do we care?
4961 + 2. If a 'conflicting' package is being removed at the same time:
4962 + 1. If any packages depended on that conflicting package and
4963 + --auto-deconfigure is specified, call, for each such package:
4964 + deconfigured's-prerm deconfigure \
4965 + in-favour package-being-installed version \
4966 + removing conflicting-package version
4967 + Error unwind:
4968 + deconfigured's-postinst abort-deconfigure \
4969 + in-favour package-being-installed-but-failed version \
4970 + removing conflicting-package version
4971 +
4972 + The deconfigured packages are marked as requiring
4973 + configuration, so that if --install is used they will be
4974 + configured again if possible.
4975 + 2. To prepare for removal of the conflicting package, call:
4976 + conflictor's-prerm remove in-favour package new-version
4977 + Error unwind:
4978 + conflictor's-postinst abort-remove in-favour package new-version
4979 + */
4980 + return 0;
4981 +}
4982 +
4983 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4984 +{
4985 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4986 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4987 + details) */
4988 + return 0;
4989 +}
4990 +
4991 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4992 +{
4993 + int err;
4994 + char *preinst_args;
4995 +
4996 + if (old_pkg) {
4997 + char *old_version = pkg_version_str_alloc(old_pkg);
4998 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4999 + free(old_version);
5000 + } else if (pkg->state_status == SS_CONFIG_FILES) {
5001 + char *pkg_version = pkg_version_str_alloc(pkg);
5002 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
5003 + free(pkg_version);
5004 + } else {
5005 + preinst_args = strdup("install");
5006 + }
5007 +
5008 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
5009 + if (err) {
5010 + ipkg_message(conf, IPKG_ERROR,
5011 + "Aborting installation of %s\n", pkg->name);
5012 + return 1;
5013 + }
5014 +
5015 + free(preinst_args);
5016 +
5017 + return 0;
5018 +}
5019 +
5020 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5021 +{
5022 + /* DPKG_INCOMPATIBILITY:
5023 + dpkg does the following error unwind, should we?
5024 + pkg->postrm abort-upgrade old-version
5025 + OR pkg->postrm abort-install old-version
5026 + OR pkg->postrm abort-install
5027 + */
5028 + return 0;
5029 +}
5030 +
5031 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5032 +{
5033 + int err;
5034 + conffile_list_elt_t *iter;
5035 + conffile_t *cf;
5036 +
5037 + if (conf->noaction) return 0;
5038 +
5039 + /* Backup all modified conffiles */
5040 + if (old_pkg) {
5041 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
5042 + char *cf_name;
5043 +
5044 + cf = iter->data;
5045 + cf_name = root_filename_alloc(conf, cf->name);
5046 +
5047 + /* Don't worry if the conffile is just plain gone */
5048 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
5049 + err = backup_make_backup(conf, cf_name);
5050 + if (err) {
5051 + return err;
5052 + }
5053 + }
5054 + free(cf_name);
5055 + }
5056 + }
5057 +
5058 + /* Backup all conffiles that were not conffiles in old_pkg */
5059 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5060 + char *cf_name;
5061 + cf = iter->data;
5062 + cf_name = root_filename_alloc(conf, cf->name);
5063 + /* Ignore if this was a conffile in old_pkg as well */
5064 + if (pkg_get_conffile(old_pkg, cf->name)) {
5065 + continue;
5066 + }
5067 +
5068 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
5069 + err = backup_make_backup(conf, cf_name);
5070 + if (err) {
5071 + return err;
5072 + }
5073 + }
5074 + free(cf_name);
5075 + }
5076 +
5077 + return 0;
5078 +}
5079 +
5080 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5081 +{
5082 + conffile_list_elt_t *iter;
5083 +
5084 + if (old_pkg) {
5085 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
5086 + backup_remove(iter->data->name);
5087 + }
5088 + }
5089 +
5090 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5091 + backup_remove(iter->data->name);
5092 + }
5093 +
5094 + return 0;
5095 +}
5096 +
5097 +
5098 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5099 +{
5100 + /* DPKG_INCOMPATIBILITY:
5101 + ipkg takes a slightly different approach than dpkg at this
5102 + point. dpkg installs each file in the new package while
5103 + creating a backup for any file that is replaced, (so that it
5104 + can unwind if necessary). To avoid complexity and redundant
5105 + storage, ipkg doesn't do any installation until later, (at the
5106 + point at which dpkg removes the backups.
5107 +
5108 + But, we do have to check for data file clashes, since after
5109 + installing a package with a file clash, removing either of the
5110 + packages involved in the clash has the potential to break the
5111 + other package.
5112 + */
5113 + str_list_t *files_list;
5114 + str_list_elt_t *iter;
5115 +
5116 + int clashes = 0;
5117 +
5118 + files_list = pkg_get_installed_files(pkg);
5119 + for (iter = files_list->head; iter; iter = iter->next) {
5120 + char *root_filename;
5121 + char *filename = iter->data;
5122 + root_filename = root_filename_alloc(conf, filename);
5123 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5124 + pkg_t *owner;
5125 + pkg_t *obs;
5126 + /* Pre-existing conffiles are OK */
5127 + /* @@@@ should have way to check that it is a conffile -Jamey */
5128 + if (backup_exists_for(root_filename)) {
5129 + continue;
5130 + }
5131 +
5132 + /* Pre-existing files are OK if force-overwrite was asserted. */
5133 + if (conf->force_overwrite) {
5134 + /* but we need to change who owns this file */
5135 + file_hash_set_file_owner(conf, filename, pkg);
5136 + continue;
5137 + }
5138 +
5139 + owner = file_hash_get_file_owner(conf, filename);
5140 +
5141 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
5142 + if (owner && old_pkg) {
5143 + if (strcmp(owner->name, old_pkg->name) == 0) {
5144 + continue;
5145 + }
5146 + }
5147 +
5148 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5149 + if (owner) {
5150 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5151 + if (pkg_replaces(pkg, owner)) {
5152 + continue;
5153 + }
5154 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5155 + then it's ok to overwrite. */
5156 + if (strcmp(owner->name,pkg->name)==0){
5157 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5158 + continue;
5159 + }
5160 + }
5161 +
5162 + /* Pre-existing files are OK if they are obsolete */
5163 + obs = hash_table_get(&conf->obs_file_hash, filename);
5164 + if (obs) {
5165 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5166 + continue;
5167 + }
5168 +
5169 + /* We have found a clash. */
5170 + ipkg_message(conf, IPKG_ERROR,
5171 + "Package %s wants to install file %s\n"
5172 + "\tBut that file is already provided by package ",
5173 + pkg->name, filename);
5174 + if (owner) {
5175 + ipkg_message(conf, IPKG_ERROR,
5176 + "%s\n", owner->name);
5177 + } else {
5178 + ipkg_message(conf, IPKG_ERROR,
5179 + "<no package>\nPlease move this file out of the way and try again.\n");
5180 + }
5181 + clashes++;
5182 + }
5183 + free(root_filename);
5184 + }
5185 + pkg_free_installed_files(pkg);
5186 +
5187 + return clashes;
5188 +}
5189 +
5190 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5191 +{
5192 + /* Basically that's the worst hack I could do to be able to change ownership of
5193 + file list, but, being that we have no way to unwind the mods, due to structure
5194 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5195 + What we do here is change the ownership of file in hash if a replace ( or similar events
5196 + happens )
5197 + Only the action that are needed to change name should be considered.
5198 + @@@ To change after 1.0 release.
5199 + */
5200 + str_list_t *files_list;
5201 + str_list_elt_t *iter;
5202 +
5203 + int clashes = 0;
5204 +
5205 + files_list = pkg_get_installed_files(pkg);
5206 + for (iter = files_list->head; iter; iter = iter->next) {
5207 + char *root_filename;
5208 + char *filename = iter->data;
5209 + root_filename = root_filename_alloc(conf, filename);
5210 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5211 + pkg_t *owner;
5212 +
5213 + if (conf->force_overwrite) {
5214 + /* but we need to change who owns this file */
5215 + file_hash_set_file_owner(conf, filename, pkg);
5216 + continue;
5217 + }
5218 +
5219 + owner = file_hash_get_file_owner(conf, filename);
5220 +
5221 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5222 + if (owner) {
5223 + if (pkg_replaces(pkg, owner)) {
5224 +/* It's now time to change the owner of that file.
5225 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5226 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5227 + file_hash_set_file_owner(conf, filename, pkg);
5228 + continue;
5229 + }
5230 + }
5231 +
5232 + }
5233 + free(root_filename);
5234 + }
5235 + pkg_free_installed_files(pkg);
5236 +
5237 + return clashes;
5238 +}
5239 +
5240 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5241 +{
5242 + /* Nothing to do since check_data_file_clashes doesn't change state */
5243 + return 0;
5244 +}
5245 +
5246 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5247 +{
5248 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5249 + 1. If the package is being upgraded, call
5250 + old-postrm upgrade new-version
5251 + 2. If this fails, attempt:
5252 + new-postrm failed-upgrade old-version
5253 + Error unwind, for both cases:
5254 + old-preinst abort-upgrade new-version */
5255 + return 0;
5256 +}
5257 +
5258 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5259 +{
5260 + /* DPKG_INCOMPATIBILITY:
5261 + dpkg does some things here that we don't do yet. Do we care?
5262 + (See postrm_upgrade_old_pkg for details)
5263 + */
5264 + return 0;
5265 +}
5266 +
5267 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5268 +{
5269 + int err;
5270 + str_list_t *old_files;
5271 + str_list_elt_t *of;
5272 + str_list_t *new_files;
5273 + str_list_elt_t *nf;
5274 +
5275 + if (old_pkg == NULL) {
5276 + return 0;
5277 + }
5278 +
5279 + old_files = pkg_get_installed_files(old_pkg);
5280 + new_files = pkg_get_installed_files(pkg);
5281 +
5282 + for (of = old_files->head; of; of = of->next) {
5283 + pkg_t *owner;
5284 + char *old, *new;
5285 + old = of->data;
5286 + for (nf = new_files->head; nf; nf = nf->next) {
5287 + new = nf->data;
5288 + if (strcmp(old, new) == 0) {
5289 + goto NOT_OBSOLETE;
5290 + }
5291 + }
5292 + if (file_is_dir(old)) {
5293 + continue;
5294 + }
5295 + owner = file_hash_get_file_owner(conf, old);
5296 + if (owner != old_pkg) {
5297 + /* in case obsolete file no longer belongs to old_pkg */
5298 + continue;
5299 + }
5300 +
5301 + /* old file is obsolete */
5302 + ipkg_message(conf, IPKG_INFO,
5303 + " removing obsolete file %s\n", old);
5304 + if (!conf->noaction) {
5305 + err = unlink(old);
5306 + if (err) {
5307 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5308 + strerror(errno));
5309 + }
5310 + }
5311 +
5312 + NOT_OBSOLETE:
5313 + ;
5314 + }
5315 +
5316 + pkg_free_installed_files(old_pkg);
5317 + pkg_free_installed_files(pkg);
5318 +
5319 + return 0;
5320 +}
5321 +
5322 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5323 +{
5324 + int i;
5325 + int err = 0;
5326 + char *globpattern;
5327 + glob_t globbuf;
5328 + if (0) {
5329 + if (!pkg->dest) {
5330 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5331 + return -1;
5332 + }
5333 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5334 + err = glob(globpattern, 0, NULL, &globbuf);
5335 + free(globpattern);
5336 + if (err) {
5337 + return err;
5338 + }
5339 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5340 + for (i = 0; i < globbuf.gl_pathc; i++) {
5341 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5342 + globbuf.gl_pathv[i], old_pkg->name);
5343 + if (!conf->noaction)
5344 + unlink(globbuf.gl_pathv[i]);
5345 + }
5346 + globfree(&globbuf);
5347 + }
5348 + return err;
5349 +}
5350 +
5351 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5352 +{
5353 + int ret;
5354 + char *prefix;
5355 +
5356 + if (old_pkg)
5357 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5358 + sprintf_alloc(&prefix, "%s.", pkg->name);
5359 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5360 + pkg->dest->info_dir,
5361 + prefix);
5362 + free(prefix);
5363 + return ret;
5364 +}
5365 +
5366 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5367 +{
5368 + /* DPKG_INCOMPATIBILITY:
5369 + This is a fairly sophisticated dpkg operation. Shall we
5370 + skip it? */
5371 +
5372 + /* Any packages all of whose files have been overwritten during the
5373 + installation, and which aren't required for dependencies, are
5374 + considered to have been removed. For each such package
5375 + 1. disappearer's-postrm disappear overwriter overwriter-version
5376 + 2. The package's maintainer scripts are removed
5377 + 3. It is noted in the status database as being in a sane state,
5378 + namely not installed (any conffiles it may have are ignored,
5379 + rather than being removed by dpkg). Note that disappearing
5380 + packages do not have their prerm called, because dpkg doesn't
5381 + know in advance that the package is going to vanish.
5382 + */
5383 + return 0;
5384 +}
5385 +
5386 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5387 +{
5388 + int err;
5389 +
5390 + /* ipkg takes a slightly different approach to data file backups
5391 + than dpkg. Rather than removing backups at this point, we
5392 + actually do the data file installation now. See comments in
5393 + check_data_file_clashes() for more details. */
5394 +
5395 + ipkg_message(conf, IPKG_INFO,
5396 + " extracting data files to %s\n", pkg->dest->root_dir);
5397 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5398 + if (err) {
5399 + return err;
5400 + }
5401 +
5402 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5403 + so we can't save ourself from removing important packages
5404 + At this point we (should) have extracted the .control file, so it
5405 + would be a good idea to reload the data in it, and set the Essential
5406 + state in *pkg. From now on the Essential is back in status file and
5407 + we can protect again.
5408 + We should operate this way:
5409 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5410 + check for "Essential" in it
5411 + set the value in pkg->essential.
5412 + This new routine could be useful also for every other flag
5413 + Pigi: 16/03/2004 */
5414 + set_flags_from_control(conf, pkg) ;
5415 +
5416 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5417 + err = pkg_write_filelist(conf, pkg);
5418 + if (err)
5419 + return err;
5420 +
5421 + /* XXX: FEATURE: ipkg should identify any files which existed
5422 + before installation and which were overwritten, (see
5423 + check_data_file_clashes()). What it must do is remove any such
5424 + files from the filelist of the old package which provided the
5425 + file. Otherwise, if the old package were removed at some point
5426 + it would break the new package. Removing the new package will
5427 + also break the old one, but this cannot be helped since the old
5428 + package's file has already been deleted. This is the importance
5429 + of check_data_file_clashes(), and only allowing ipkg to install
5430 + a clashing package with a user force. */
5431 +
5432 + return 0;
5433 +}
5434 +
5435 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5436 +{
5437 + conffile_list_elt_t *iter;
5438 + conffile_t *cf;
5439 + char *cf_backup;
5440 +
5441 + char *md5sum;
5442 +
5443 +
5444 + if (conf->noaction) return 0;
5445 +
5446 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5447 + char *root_filename;
5448 + cf = iter->data;
5449 + root_filename = root_filename_alloc(conf, cf->name);
5450 +
5451 + /* Might need to initialize the md5sum for each conffile */
5452 + if (cf->value == NULL) {
5453 + cf->value = file_md5sum_alloc(root_filename);
5454 + }
5455 +
5456 + if (!file_exists(root_filename)) {
5457 + free(root_filename);
5458 + continue;
5459 + }
5460 +
5461 + cf_backup = backup_filename_alloc(root_filename);
5462 +
5463 +
5464 + if (file_exists(cf_backup)) {
5465 + /* Let's compute md5 to test if files are changed */
5466 + md5sum = file_md5sum_alloc(cf_backup);
5467 + if (strcmp( cf->value,md5sum) != 0 ) {
5468 + if (conf->force_defaults
5469 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5470 + rename(cf_backup, root_filename);
5471 + }
5472 + }
5473 + unlink(cf_backup);
5474 + free(md5sum);
5475 + }
5476 +
5477 + free(cf_backup);
5478 + free(root_filename);
5479 + }
5480 +
5481 + return 0;
5482 +}
5483 +
5484 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5485 +{
5486 + char *response;
5487 + const char *short_file_name;
5488 +
5489 + short_file_name = strrchr(file_name, '/');
5490 + if (short_file_name) {
5491 + short_file_name++;
5492 + } else {
5493 + short_file_name = file_name;
5494 + }
5495 +
5496 + while (1) {
5497 + response = get_user_response(" Configuration file '%s'\n"
5498 + " ==> File on system created by you or by a script.\n"
5499 + " ==> File also in package provided by package maintainer.\n"
5500 + " What would you like to do about it ? Your options are:\n"
5501 + " Y or I : install the package maintainer's version\n"
5502 + " N or O : keep your currently-installed version\n"
5503 + " D : show the differences between the versions (if diff is installed)\n"
5504 + " The default action is to keep your current version.\n"
5505 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5506 + if (strcmp(response, "y") == 0
5507 + || strcmp(response, "i") == 0
5508 + || strcmp(response, "yes") == 0) {
5509 + free(response);
5510 + return 0;
5511 + }
5512 +
5513 + if (strcmp(response, "d") == 0) {
5514 + char *cmd;
5515 +
5516 + free(response);
5517 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5518 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5519 + xsystem(cmd);
5520 + free(cmd);
5521 + printf(" [Press ENTER to continue]\n");
5522 + response = file_read_line_alloc(stdin);
5523 + free(response);
5524 + continue;
5525 + }
5526 +
5527 + free(response);
5528 + return 1;
5529 + }
5530 +}
5531 +
5532 +/* XXX: CLEANUP: I'd like to move all of the code for
5533 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5534 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5535 + pkg_deinit for example). */
5536 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5537 +{
5538 + DIR *tmp_dir;
5539 + struct dirent *dirent;
5540 + char *tmp_file;
5541 +
5542 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5543 +#error
5544 + ipkg_message(conf, IPKG_DEBUG,
5545 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5546 + __FUNCTION__, pkg->tmp_unpack_dir);
5547 + return 0;
5548 +#endif
5549 +
5550 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5551 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5552 + if (tmp_dir) {
5553 + while (1) {
5554 + dirent = readdir(tmp_dir);
5555 + if (dirent == NULL) {
5556 + break;
5557 + }
5558 + sprintf_alloc(&tmp_file, "%s/%s",
5559 + pkg->tmp_unpack_dir, dirent->d_name);
5560 + if (! file_is_dir(tmp_file)) {
5561 + unlink(tmp_file);
5562 + }
5563 + free(tmp_file);
5564 + }
5565 + closedir(tmp_dir);
5566 + rmdir(pkg->tmp_unpack_dir);
5567 + free(pkg->tmp_unpack_dir);
5568 + pkg->tmp_unpack_dir = NULL;
5569 + }
5570 + }
5571 +
5572 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5573 + pkg->name, pkg->local_filename, conf->tmp_dir);
5574 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5575 + unlink(pkg->local_filename);
5576 + free(pkg->local_filename);
5577 + pkg->local_filename = NULL;
5578 + }
5579 +
5580 + return 0;
5581 +}
5582 +
5583 +static char *backup_filename_alloc(const char *file_name)
5584 +{
5585 + char *backup;
5586 +
5587 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5588 +
5589 + return backup;
5590 +}
5591 +
5592 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5593 +{
5594 + int err;
5595 + char *backup;
5596 +
5597 + backup = backup_filename_alloc(file_name);
5598 + err = file_copy(file_name, backup);
5599 + if (err) {
5600 + ipkg_message(conf, IPKG_ERROR,
5601 + "%s: Failed to copy %s to %s\n",
5602 + __FUNCTION__, file_name, backup);
5603 + }
5604 +
5605 + free(backup);
5606 +
5607 + return err;
5608 +}
5609 +
5610 +static int backup_exists_for(const char *file_name)
5611 +{
5612 + int ret;
5613 + char *backup;
5614 +
5615 + backup = backup_filename_alloc(file_name);
5616 +
5617 + ret = file_exists(backup);
5618 +
5619 + free(backup);
5620 +
5621 + return ret;
5622 +}
5623 +
5624 +static int backup_remove(const char *file_name)
5625 +{
5626 + char *backup;
5627 +
5628 + backup = backup_filename_alloc(file_name);
5629 + unlink(backup);
5630 + free(backup);
5631 +
5632 + return 0;
5633 +}
5634 +
5635 +\f
5636 +
5637 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5638 +
5639 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5640 +{
5641 + /* first, remove the packages that need removing */
5642 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5643 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5644 + err = ipkg_remove_pkg(conf, pkg,0);
5645 + if (err) return err;
5646 + }
5647 + return 0;
5648 +}
5649 +
5650 +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5651 +{
5652 + int i;
5653 + /* now one more pass checking on the ones that need to be installed */
5654 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5655 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5656 + if (pkg->dest == NULL)
5657 + pkg->dest = conf->default_dest;
5658 +
5659 + pkg->state_want = SW_INSTALL;
5660 +
5661 + /* Abhaya: conflicts check */
5662 + err = check_conflicts_for(conf, pkg);
5663 + if (err) { return err; }
5664 + }
5665 + return 0;
5666 +}
5667 +
5668 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5669 +{
5670 + int i;
5671 + /* now one more pass checking on the ones that need to be installed */
5672 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5673 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5674 +
5675 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5676 + pkg_vec_t *replacees = pkg_vec_alloc();
5677 + pkg_get_installed_replacees(conf, pkg, replacees);
5678 +
5679 + /* XXX: BUG: we really should treat replacement more like an upgrade
5680 + * Instead, we're going to remove the replacees
5681 + */
5682 + err = pkg_remove_installed_replacees(conf, replacees);
5683 + if (err) return err;
5684 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5685 + }
5686 + return 0;
5687 +}
5688 +
5689 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5690 +{
5691 + int i;
5692 + /* now one more pass checking on the ones that need to be installed */
5693 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5694 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5695 + if (pkg->local_filename == NULL) {
5696 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5697 + if (err) {
5698 + ipkg_message(conf, IPKG_ERROR,
5699 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5700 + pkg->name);
5701 + return err;
5702 + }
5703 + }
5704 + if (pkg->tmp_unpack_dir == NULL) {
5705 + err = unpack_pkg_control_files(conf, pkg);
5706 + if (err) return err;
5707 + }
5708 + }
5709 + return 0;
5710 +}
5711 +
5712 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5713 +{
5714 + int i;
5715 + /* now one more pass checking on the ones that need to be installed */
5716 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5717 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5718 + pkg_t *old_pkg = pkg->old_pkg;
5719 +
5720 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5721 + if (err) return err;
5722 +
5723 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5724 + if (err) return err;
5725 +
5726 + err = preinst_configure(conf, pkg, old_pkg);
5727 + if (err) return err;
5728 +
5729 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5730 + if (err) return err;
5731 +
5732 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5733 + if (err) return err;
5734 + }
5735 + return 0;
5736 +}
5737 +
5738 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5739 +{
5740 + int i;
5741 + /* now one more pass checking on the ones that need to be installed */
5742 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5743 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5744 + pkg_t *old_pkg = pkg->old_pkg;
5745 +
5746 + if (old_pkg) {
5747 + old_pkg->state_want = SW_DEINSTALL;
5748 +
5749 + if (old_pkg->state_flag & SF_NOPRUNE) {
5750 + ipkg_message(conf, IPKG_INFO,
5751 + " not removing obsolesced files because package marked noprune\n");
5752 + } else {
5753 + ipkg_message(conf, IPKG_INFO,
5754 + " removing obsolesced files\n");
5755 + remove_obsolesced_files(conf, pkg, old_pkg);
5756 + }
5757 + }
5758 +
5759 + ipkg_message(conf, IPKG_INFO,
5760 + " installing maintainer scripts\n");
5761 + install_maintainer_scripts(conf, pkg, old_pkg);
5762 +
5763 + /* the following just returns 0 */
5764 + remove_disappeared(conf, pkg);
5765 +
5766 + ipkg_message(conf, IPKG_INFO,
5767 + " installing data files\n");
5768 + install_data_files(conf, pkg);
5769 +
5770 + ipkg_message(conf, IPKG_INFO,
5771 + " resolving conf files\n");
5772 + resolve_conffiles(conf, pkg);
5773 +
5774 + pkg->state_status = SS_UNPACKED;
5775 +
5776 + if (old_pkg) {
5777 + old_pkg->state_status = SS_NOT_INSTALLED;
5778 + }
5779 +
5780 + time(&pkg->installed_time);
5781 +
5782 + ipkg_message(conf, IPKG_INFO,
5783 + " cleanup temp files\n");
5784 + cleanup_temporary_files(conf, pkg);
5785 +
5786 + if (pkg->parent)
5787 + pkg->parent->state_status = pkg->state_status;
5788 + }
5789 + return 0;
5790 +}
5791 +
5792 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5793 +{
5794 + int i;
5795 + /* now one more pass checking on the ones that need to be installed */
5796 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5797 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5798 + pkg_t *old_pkg = pkg->old_pkg;
5799 +
5800 + if (old_pkg) {
5801 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5802 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5803 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5804 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5805 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5806 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5807 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5808 + preinst_configure_unwind(conf, pkg, old_pkg);
5809 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5810 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5811 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5812 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5813 +
5814 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5815 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5816 +
5817 + }
5818 + }
5819 + return 0;
5820 +}
5821 +
5822 +/*
5823 + * Perform all the actions.
5824 + *
5825 + * pkgs_to_remove are packages marked for removal.
5826 + * pkgs_superseded are the old packages being replaced by upgrades.
5827 + *
5828 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5829 + */
5830 +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5831 +{
5832 + int err;
5833 + int i;
5834 +
5835 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5836 + if (err) return err;
5837 +
5838 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5839 + if (err) return err;
5840 +
5841 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5842 + if (err) goto UNWIND;
5843 +
5844 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5845 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5846 + if (err) goto UNWIND;
5847 +
5848 + /*
5849 + * Now that we have the packages unpacked, we can look for data
5850 + * file clashes. First, we mark the files from the superseded
5851 + * packages as obsolete. Then we scan the files in
5852 + * pkgs_to_install, and only complain about clashes with
5853 + * non-obsolete files.
5854 + */
5855 +
5856 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5857 + if (err) goto UNWIND;
5858 +
5859 + /* this was before checking data file clashes */
5860 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5861 + if (err) goto UNWIND;
5862 +
5863 + /* point of no return: no unwinding after this */
5864 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5865 + if (err) return err;
5866 +
5867 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5868 + return 0;
5869 +
5870 + UNWIND:
5871 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5872 +
5873 + ipkg_message(conf, IPKG_INFO,
5874 + " cleanup temp files\n");
5875 + cleanup_temporary_files(conf, pkg);
5876 +
5877 + ipkg_message(conf, IPKG_INFO,
5878 + "Failed.\n");
5879 + return err;
5880 +}
5881 +
5882 +#endif
5883 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_install.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.h
5884 --- busybox-1.1.2-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5885 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-05-09 02:12:04.000000000 +0200
5886 @@ -0,0 +1,35 @@
5887 +/* ipkg_install.h - the itsy package management system
5888 +
5889 + Carl D. Worth
5890 +
5891 + Copyright (C) 2001 University of Southern California
5892 +
5893 + This program is free software; you can redistribute it and/or
5894 + modify it under the terms of the GNU General Public License as
5895 + published by the Free Software Foundation; either version 2, or (at
5896 + your option) any later version.
5897 +
5898 + This program is distributed in the hope that it will be useful, but
5899 + WITHOUT ANY WARRANTY; without even the implied warranty of
5900 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5901 + General Public License for more details.
5902 +*/
5903 +
5904 +#ifndef IPKG_INSTALL_H
5905 +#define IPKG_INSTALL_H
5906 +
5907 +#include "pkg.h"
5908 +#include "ipkg_conf.h"
5909 +
5910 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5911 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5912 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5913 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5914 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5915 +
5916 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5917 +
5918 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5919 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5920 +
5921 +#endif
5922 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_message.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.c
5923 --- busybox-1.1.2-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5924 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-05-09 02:06:48.000000000 +0200
5925 @@ -0,0 +1,61 @@
5926 +/* ipkg_message.c - the itsy package management system
5927 +
5928 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5929 +
5930 + This program is free software; you can redistribute it and/or
5931 + modify it under the terms of the GNU General Public License as
5932 + published by the Free Software Foundation; either version 2, or (at
5933 + your option) any later version.
5934 +
5935 + This program is distributed in the hope that it will be useful, but
5936 + WITHOUT ANY WARRANTY; without even the implied warranty of
5937 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5938 + General Public License for more details.
5939 +*/
5940 +
5941 +
5942 +#include "ipkg.h"
5943 +#include "ipkg_conf.h"
5944 +#include "ipkg_message.h"
5945 +
5946 +#ifndef IPKG_LIB
5947 +
5948 +void
5949 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5950 +{
5951 + va_list ap;
5952 +
5953 + if (conf && (conf->verbosity < level))
5954 + {
5955 + return;
5956 + }
5957 + else
5958 + {
5959 +
5960 + va_start (ap, fmt);
5961 + vprintf (fmt, ap);
5962 + va_end (ap);
5963 + }
5964 +}
5965 +
5966 +#else
5967 +
5968 +#include "libipkg.h"
5969 +
5970 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5971 +
5972 +void
5973 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5974 +{
5975 + va_list ap;
5976 + char ts[256];
5977 +
5978 + if (ipkg_cb_message)
5979 + {
5980 + va_start (ap, fmt);
5981 + vsnprintf (ts,256,fmt, ap);
5982 + va_end (ap);
5983 + ipkg_cb_message(conf,level,ts);
5984 + }
5985 +}
5986 +#endif
5987 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_message.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.h
5988 --- busybox-1.1.2-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5989 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-05-09 02:06:48.000000000 +0200
5990 @@ -0,0 +1,32 @@
5991 +/* ipkg_message.h - the itsy package management system
5992 +
5993 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5994 +
5995 + This program is free software; you can redistribute it and/or
5996 + modify it under the terms of the GNU General Public License as
5997 + published by the Free Software Foundation; either version 2, or (at
5998 + your option) any later version.
5999 +
6000 + This program is distributed in the hope that it will be useful, but
6001 + WITHOUT ANY WARRANTY; without even the implied warranty of
6002 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6003 + General Public License for more details.
6004 +*/
6005 +
6006 +#ifndef _IPKG_MESSAGE_H_
6007 +#define _IPKG_MESSAGE_H_
6008 +
6009 +#include "ipkg.h"
6010 +#include "ipkg_conf.h"
6011 +
6012 +typedef enum {
6013 + IPKG_ERROR, /* error conditions */
6014 + IPKG_NOTICE, /* normal but significant condition */
6015 + IPKG_INFO, /* informational message */
6016 + IPKG_DEBUG, /* debug level message */
6017 + IPKG_DEBUG2, /* more debug level message */
6018 +} message_level_t;
6019 +
6020 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
6021 +
6022 +#endif /* _IPKG_MESSAGE_H_ */
6023 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_remove.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.c
6024 --- busybox-1.1.2-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
6025 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-05-09 02:12:04.000000000 +0200
6026 @@ -0,0 +1,383 @@
6027 +/* ipkg_remove.c - the itsy package management system
6028 +
6029 + Carl D. Worth
6030 +
6031 + Copyright (C) 2001 University of Southern California
6032 +
6033 + This program is free software; you can redistribute it and/or
6034 + modify it under the terms of the GNU General Public License as
6035 + published by the Free Software Foundation; either version 2, or (at
6036 + your option) any later version.
6037 +
6038 + This program is distributed in the hope that it will be useful, but
6039 + WITHOUT ANY WARRANTY; without even the implied warranty of
6040 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6041 + General Public License for more details.
6042 +*/
6043 +
6044 +#include "ipkg.h"
6045 +#include "ipkg_message.h"
6046 +
6047 +#include <glob.h>
6048 +
6049 +#include "ipkg_remove.h"
6050 +
6051 +#include "file_util.h"
6052 +#include "sprintf_alloc.h"
6053 +#include "str_util.h"
6054 +
6055 +#include "ipkg_cmd.h"
6056 +
6057 +/*
6058 + * Returns number of the number of packages depending on the packages provided by this package.
6059 + * Every package implicitly provides itself.
6060 + */
6061 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
6062 +{
6063 + int nprovides = pkg->provides_count;
6064 + abstract_pkg_t **provides = pkg->provides;
6065 + int n_installed_dependents = 0;
6066 + int i;
6067 + for (i = 0; i <= nprovides; i++) {
6068 + abstract_pkg_t *providee = provides[i];
6069 + abstract_pkg_t **dependers = providee->depended_upon_by;
6070 + abstract_pkg_t *dep_ab_pkg;
6071 + if (dependers == NULL)
6072 + continue;
6073 + while ((dep_ab_pkg = *dependers++) != NULL) {
6074 + if (dep_ab_pkg->state_status == SS_INSTALLED){
6075 + n_installed_dependents++;
6076 + }
6077 + }
6078 +
6079 + }
6080 + /* if caller requested the set of installed dependents */
6081 + if (pdependents) {
6082 + int p = 0;
6083 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
6084 +
6085 + if ( dependents == NULL ){
6086 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
6087 + return -1;
6088 + }
6089 +
6090 + *pdependents = dependents;
6091 + for (i = 0; i <= nprovides; i++) {
6092 + abstract_pkg_t *providee = provides[i];
6093 + abstract_pkg_t **dependers = providee->depended_upon_by;
6094 + abstract_pkg_t *dep_ab_pkg;
6095 + if (dependers == NULL)
6096 + continue;
6097 + while ((dep_ab_pkg = *dependers++) != NULL) {
6098 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
6099 + dependents[p++] = dep_ab_pkg;
6100 + dep_ab_pkg->state_flag |= SF_MARKED;
6101 + }
6102 + }
6103 + }
6104 + dependents[p] = NULL;
6105 + /* now clear the marks */
6106 + for (i = 0; i < p; i++) {
6107 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6108 + dep_ab_pkg->state_flag &= ~SF_MARKED;
6109 + }
6110 + }
6111 + return n_installed_dependents;
6112 +}
6113 +
6114 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
6115 +{
6116 + int i;
6117 + int a;
6118 + int count;
6119 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
6120 + abstract_pkg_t * ab_pkg;
6121 +
6122 + if((ab_pkg = pkg->parent) == NULL){
6123 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
6124 + __FUNCTION__, pkg->name);
6125 + return 0;
6126 + }
6127 +
6128 + if (dependents == NULL)
6129 + return 0;
6130 +
6131 + // here i am using the dependencies_checked
6132 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
6133 + return 0; // has already been encountered in the process
6134 + // of marking packages for removal - Karthik
6135 + ab_pkg->dependencies_checked = 2;
6136 +
6137 + i = 0;
6138 + count = 1;
6139 + while (dependents [i] != NULL) {
6140 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6141 +
6142 + if (dep_ab_pkg->dependencies_checked == 2){
6143 + i++;
6144 + continue;
6145 + }
6146 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
6147 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
6148 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6149 + if (dep_pkg->state_status == SS_INSTALLED) {
6150 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6151 + count++;
6152 + }
6153 + }
6154 + }
6155 + i++;
6156 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6157 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6158 + }
6159 +
6160 + if (count == 1)
6161 + return 0;
6162 +
6163 +
6164 + for (i = 0; i < dependent_pkgs->len; i++) {
6165 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6166 + if (err)
6167 + return err;
6168 + }
6169 + return 0;
6170 +}
6171 +
6172 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6173 +{
6174 + abstract_pkg_t *dep_ab_pkg;
6175 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6176 + while ((dep_ab_pkg = *dependents++) != NULL) {
6177 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6178 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6179 + }
6180 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6181 + ipkg_message(conf, IPKG_ERROR, "");
6182 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6183 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6184 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6185 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6186 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6187 + return 0;
6188 +}
6189 +
6190 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6191 +{
6192 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6193 + thus I wan't check for essential, as I'm upgrading.
6194 + I hope it won't break anything :)
6195 +*/
6196 + int err;
6197 + abstract_pkg_t *parent_pkg = NULL;
6198 +
6199 + if (pkg->essential && !message) {
6200 + if (conf->force_removal_of_essential_packages) {
6201 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6202 + "\tIf your system breaks, you get to keep both pieces\n",
6203 + pkg->name);
6204 + } else {
6205 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6206 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6207 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6208 + "\tits will with the option: -force-removal-of-essential-packages\n",
6209 + pkg->name);
6210 + return IPKG_PKG_IS_ESSENTIAL;
6211 + }
6212 + }
6213 +
6214 + if ((parent_pkg = pkg->parent) == NULL)
6215 + return 0;
6216 +
6217 + /* only attempt to remove dependent installed packages if
6218 + * force_depends is not specified or the package is being
6219 + * replaced.
6220 + */
6221 + if (!conf->force_depends
6222 + && !(pkg->state_flag & SF_REPLACE)) {
6223 + abstract_pkg_t **dependents;
6224 + int has_installed_dependents =
6225 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6226 +
6227 + if (has_installed_dependents) {
6228 + /*
6229 + * if this package is depended up by others, then either we should
6230 + * not remove it or we should remove it and all of its dependents
6231 + */
6232 +
6233 + if (!conf->force_removal_of_dependent_packages
6234 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6235 + return IPKG_PKG_HAS_DEPENDENTS;
6236 + }
6237 +
6238 + /* remove packages depending on this package - Karthik */
6239 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6240 + free(dependents);
6241 + if (err) return err;
6242 + }
6243 + }
6244 +
6245 + if ( message==0 ){
6246 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6247 + fflush(stdout);
6248 + }
6249 + pkg->state_flag |= SF_FILELIST_CHANGED;
6250 +
6251 + pkg->state_want = SW_DEINSTALL;
6252 + ipkg_state_changed++;
6253 +
6254 + pkg_run_script(conf, pkg, "prerm", "remove");
6255 +
6256 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6257 + maintains an empty filelist rather than deleting it. That seems
6258 + like a big pain, and I don't see that that should make a big
6259 + difference, but for anyone who wants tighter compatibility,
6260 + feel free to fix this. */
6261 + remove_data_files_and_list(conf, pkg);
6262 +
6263 + pkg_run_script(conf, pkg, "postrm", "remove");
6264 +
6265 + remove_maintainer_scripts_except_postrm(conf, pkg);
6266 +
6267 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6268 + * space, it doesn't make sense to leave extra configurations, files,
6269 + * and maintainer scripts left around. So, we make remove like purge,
6270 + * and take out all the crap :) */
6271 +
6272 + remove_postrm(conf, pkg);
6273 + pkg->state_status = SS_NOT_INSTALLED;
6274 +
6275 + if (parent_pkg)
6276 + parent_pkg->state_status = SS_NOT_INSTALLED;
6277 +
6278 + return 0;
6279 +}
6280 +
6281 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6282 +{
6283 + ipkg_remove_pkg(conf, pkg,0);
6284 + return 0;
6285 +}
6286 +
6287 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6288 +{
6289 + str_list_t installed_dirs;
6290 + str_list_t *installed_files;
6291 + str_list_elt_t *iter;
6292 + char *file_name;
6293 + conffile_t *conffile;
6294 + int removed_a_dir;
6295 + pkg_t *owner;
6296 +
6297 + str_list_init(&installed_dirs);
6298 + installed_files = pkg_get_installed_files(pkg);
6299 +
6300 + for (iter = installed_files->head; iter; iter = iter->next) {
6301 + file_name = iter->data;
6302 +
6303 + if (file_is_dir(file_name)) {
6304 + str_list_append(&installed_dirs, strdup(file_name));
6305 + continue;
6306 + }
6307 +
6308 + conffile = pkg_get_conffile(pkg, file_name);
6309 + if (conffile) {
6310 + /* XXX: QUESTION: Is this right? I figure we only need to
6311 + save the conffile if it has been modified. Is that what
6312 + dpkg does? Or does dpkg preserve all conffiles? If so,
6313 + this seems like a better thing to do to conserve
6314 + space. */
6315 + if (conffile_has_been_modified(conf, conffile)) {
6316 + printf(" not deleting modified conffile %s\n", file_name);
6317 + fflush(stdout);
6318 + continue;
6319 + }
6320 + }
6321 +
6322 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6323 + if (!conf->noaction)
6324 + unlink(file_name);
6325 + }
6326 +
6327 + if (!conf->noaction) {
6328 + do {
6329 + removed_a_dir = 0;
6330 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6331 + file_name = iter->data;
6332 +
6333 + if (rmdir(file_name) == 0) {
6334 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6335 + removed_a_dir = 1;
6336 + str_list_remove(&installed_dirs, &iter);
6337 + }
6338 + }
6339 + } while (removed_a_dir);
6340 + }
6341 +
6342 + pkg_free_installed_files(pkg);
6343 + /* We have to remove the file list now, so that
6344 + find_pkg_owning_file does not always just report this package */
6345 + pkg_remove_installed_files_list(conf, pkg);
6346 +
6347 + /* Don't print warning for dirs that are provided by other packages */
6348 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6349 + file_name = iter->data;
6350 +
6351 + owner = file_hash_get_file_owner(conf, file_name);
6352 + if (owner) {
6353 + free(iter->data);
6354 + iter->data = NULL;
6355 + str_list_remove(&installed_dirs, &iter);
6356 + }
6357 + }
6358 +
6359 + /* cleanup */
6360 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6361 + free(iter->data);
6362 + iter->data = NULL;
6363 + }
6364 + str_list_deinit(&installed_dirs);
6365 +
6366 + return 0;
6367 +}
6368 +
6369 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6370 +{
6371 + int i, err;
6372 + char *globpattern;
6373 + glob_t globbuf;
6374 +
6375 + if (conf->noaction) return 0;
6376 +
6377 + sprintf_alloc(&globpattern, "%s/%s.*",
6378 + pkg->dest->info_dir, pkg->name);
6379 + err = glob(globpattern, 0, NULL, &globbuf);
6380 + free(globpattern);
6381 + if (err) {
6382 + return 0;
6383 + }
6384 +
6385 + for (i = 0; i < globbuf.gl_pathc; i++) {
6386 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6387 + continue;
6388 + }
6389 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6390 + unlink(globbuf.gl_pathv[i]);
6391 + }
6392 + globfree(&globbuf);
6393 +
6394 + return 0;
6395 +}
6396 +
6397 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6398 +{
6399 + char *postrm_file_name;
6400 +
6401 + if (conf->noaction) return 0;
6402 +
6403 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6404 + pkg->dest->info_dir, pkg->name);
6405 + unlink(postrm_file_name);
6406 + free(postrm_file_name);
6407 +
6408 + return 0;
6409 +}
6410 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_remove.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.h
6411 --- busybox-1.1.2-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6412 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-05-09 02:12:04.000000000 +0200
6413 @@ -0,0 +1,33 @@
6414 +/* ipkg_remove.h - the itsy package management system
6415 +
6416 + Carl D. Worth
6417 +
6418 + Copyright (C) 2001 University of Southern California
6419 +
6420 + This program is free software; you can redistribute it and/or
6421 + modify it under the terms of the GNU General Public License as
6422 + published by the Free Software Foundation; either version 2, or (at
6423 + your option) any later version.
6424 +
6425 + This program is distributed in the hope that it will be useful, but
6426 + WITHOUT ANY WARRANTY; without even the implied warranty of
6427 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6428 + General Public License for more details.
6429 +*/
6430 +
6431 +#ifndef IPKG_REMOVE_H
6432 +#define IPKG_REMOVE_H
6433 +
6434 +#include "pkg.h"
6435 +#include "ipkg_conf.h"
6436 +
6437 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6438 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6439 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6440 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6441 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6442 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6443 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6444 +
6445 +
6446 +#endif
6447 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c
6448 --- busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6449 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-05-09 02:12:04.000000000 +0200
6450 @@ -0,0 +1,77 @@
6451 +/* ipkg_upgrade.c - the itsy package management system
6452 +
6453 + Carl D. Worth
6454 + Copyright (C) 2001 University of Southern California
6455 +
6456 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6457 +
6458 + This program is free software; you can redistribute it and/or
6459 + modify it under the terms of the GNU General Public License as
6460 + published by the Free Software Foundation; either version 2, or (at
6461 + your option) any later version.
6462 +
6463 + This program is distributed in the hope that it will be useful, but
6464 + WITHOUT ANY WARRANTY; without even the implied warranty of
6465 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6466 + General Public License for more details.
6467 +*/
6468 +
6469 +#include "ipkg.h"
6470 +#include "ipkg_install.h"
6471 +#include "ipkg_message.h"
6472 +
6473 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6474 +{
6475 + pkg_t *new;
6476 + int cmp;
6477 + char *old_version, *new_version;
6478 +
6479 + if (old->state_flag & SF_HOLD) {
6480 + ipkg_message(conf, IPKG_NOTICE,
6481 + "Not upgrading package %s which is marked "
6482 + "hold (flags=%#x)\n", old->name, old->state_flag);
6483 + return 0;
6484 + }
6485 +
6486 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6487 + if (new == NULL) {
6488 + old_version = pkg_version_str_alloc(old);
6489 + ipkg_message(conf, IPKG_NOTICE,
6490 + "Assuming locally installed package %s (%s) "
6491 + "is up to date.\n", old->name, old_version);
6492 + free(old_version);
6493 + return 0;
6494 + }
6495 +
6496 + old_version = pkg_version_str_alloc(old);
6497 + new_version = pkg_version_str_alloc(new);
6498 +
6499 + cmp = pkg_compare_versions(old, new);
6500 + ipkg_message(conf, IPKG_DEBUG,
6501 + "comparing visible versions of pkg %s:"
6502 + "\n\t%s is installed "
6503 + "\n\t%s is available "
6504 + "\n\t%d was comparison result\n",
6505 + old->name, old_version, new_version, cmp);
6506 + if (cmp == 0) {
6507 + ipkg_message(conf, IPKG_INFO,
6508 + "Package %s (%s) installed in %s is up to date.\n",
6509 + old->name, old_version, old->dest->name);
6510 + free(old_version);
6511 + free(new_version);
6512 + return 0;
6513 + } else if (cmp > 0) {
6514 + ipkg_message(conf, IPKG_NOTICE,
6515 + "Not downgrading package %s on %s from %s to %s.\n",
6516 + old->name, old->dest->name, old_version, new_version);
6517 + free(old_version);
6518 + free(new_version);
6519 + return 0;
6520 + } else if (cmp < 0) {
6521 + new->dest = old->dest;
6522 + old->state_want = SW_DEINSTALL;
6523 + }
6524 +
6525 + new->state_flag |= SF_USER;
6526 + return ipkg_install_pkg(conf, new,1);
6527 +}
6528 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h
6529 --- busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6530 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-05-09 02:06:48.000000000 +0200
6531 @@ -0,0 +1,18 @@
6532 +/* ipkg_upgrade.c - the itsy package management system
6533 +
6534 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6535 +
6536 + This program is free software; you can redistribute it and/or
6537 + modify it under the terms of the GNU General Public License as
6538 + published by the Free Software Foundation; either version 2, or (at
6539 + your option) any later version.
6540 +
6541 + This program is distributed in the hope that it will be useful, but
6542 + WITHOUT ANY WARRANTY; without even the implied warranty of
6543 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6544 + General Public License for more details.
6545 +*/
6546 +
6547 +#include "ipkg.h"
6548 +
6549 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6550 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_utils.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.c
6551 --- busybox-1.1.2-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6552 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-05-09 02:06:48.000000000 +0200
6553 @@ -0,0 +1,181 @@
6554 +/* ipkg_utils.c - the itsy package management system
6555 +
6556 + Steven M. Ayer
6557 +
6558 + Copyright (C) 2002 Compaq Computer Corporation
6559 +
6560 + This program is free software; you can redistribute it and/or
6561 + modify it under the terms of the GNU General Public License as
6562 + published by the Free Software Foundation; either version 2, or (at
6563 + your option) any later version.
6564 +
6565 + This program is distributed in the hope that it will be useful, but
6566 + WITHOUT ANY WARRANTY; without even the implied warranty of
6567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6568 + General Public License for more details.
6569 +*/
6570 +
6571 +#include "ipkg.h"
6572 +#include <errno.h>
6573 +#include <ctype.h>
6574 +#include <sys/vfs.h>
6575 +
6576 +#include "ipkg_utils.h"
6577 +#include "pkg.h"
6578 +#include "pkg_hash.h"
6579 +
6580 +struct errlist* error_list;
6581 +
6582 +int get_available_blocks(char * filesystem)
6583 +{
6584 + struct statfs sfs;
6585 +
6586 + if(statfs(filesystem, &sfs)){
6587 + fprintf(stderr, "bad statfs\n");
6588 + return 0;
6589 + }
6590 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6591 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6592 +}
6593 +
6594 +char **read_raw_pkgs_from_file(const char *file_name)
6595 +{
6596 + FILE *fp;
6597 + char **ret;
6598 +
6599 + if(!(fp = fopen(file_name, "r"))){
6600 + fprintf(stderr, "can't get %s open for read\n", file_name);
6601 + return NULL;
6602 + }
6603 +
6604 + ret = read_raw_pkgs_from_stream(fp);
6605 +
6606 + fclose(fp);
6607 +
6608 + return ret;
6609 +}
6610 +
6611 +char **read_raw_pkgs_from_stream(FILE *fp)
6612 +{
6613 + char **raw = NULL, *buf, *scout;
6614 + int count = 0;
6615 + size_t size = 512;
6616 +
6617 + buf = malloc (size);
6618 +
6619 + while (fgets(buf, size, fp)) {
6620 + while (strlen (buf) == (size - 1)
6621 + && buf[size-2] != '\n') {
6622 + size_t o = size - 1;
6623 + size *= 2;
6624 + buf = realloc (buf, size);
6625 + if (fgets (buf + o, size - o, fp) == NULL)
6626 + break;
6627 + }
6628 +
6629 + if(!(count % 50))
6630 + raw = realloc(raw, (count + 50) * sizeof(char *));
6631 +
6632 + if((scout = strchr(buf, '\n')))
6633 + *scout = '\0';
6634 +
6635 + raw[count++] = strdup(buf);
6636 + }
6637 +
6638 + raw = realloc(raw, (count + 1) * sizeof(char *));
6639 + raw[count] = NULL;
6640 +
6641 + free (buf);
6642 +
6643 + return raw;
6644 +}
6645 +
6646 +/* something to remove whitespace, a hash pooper */
6647 +char *trim_alloc(char *line)
6648 +{
6649 + char *new;
6650 + char *dest, *src, *end;
6651 +
6652 + new = malloc(strlen(line) + 1);
6653 + if ( new == NULL ){
6654 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6655 + return NULL;
6656 + }
6657 + dest = new, src = line, end = line + (strlen(line) - 1);
6658 +
6659 + /* remove it from the front */
6660 + while(src &&
6661 + isspace(*src) &&
6662 + *src)
6663 + src++;
6664 + /* and now from the back */
6665 + while((end > src) &&
6666 + isspace(*end))
6667 + end--;
6668 + end++;
6669 + *end = '\0';
6670 + strcpy(new, src);
6671 + /* this does from the first space
6672 + * blasting away any versions stuff in depends
6673 + while(src &&
6674 + !isspace(*src) &&
6675 + *src)
6676 + *dest++ = *src++;
6677 + *dest = '\0';
6678 + */
6679 +
6680 + return new;
6681 +}
6682 +
6683 +int line_is_blank(const char *line)
6684 +{
6685 + const char *s;
6686 +
6687 + for (s = line; *s; s++) {
6688 + if (!isspace(*s))
6689 + return 0;
6690 + }
6691 + return 1;
6692 +}
6693 +
6694 +void push_error_list(struct errlist ** errors, char * msg){
6695 + struct errlist *err_lst_tmp;
6696 +
6697 +
6698 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6699 + err_lst_tmp->errmsg=strdup(msg) ;
6700 + err_lst_tmp->next = *errors;
6701 + *errors = err_lst_tmp;
6702 +}
6703 +
6704 +
6705 +void reverse_error_list(struct errlist **errors){
6706 + struct errlist *result=NULL;
6707 + struct errlist *current= *errors;
6708 + struct errlist *next;
6709 +
6710 + while ( current != NULL ) {
6711 + next = current->next;
6712 + current->next=result;
6713 + result=current;
6714 + current=next;
6715 + }
6716 + *errors=result;
6717 +
6718 +}
6719 +
6720 +
6721 +void free_error_list(struct errlist **errors){
6722 + struct errlist *current = *errors;
6723 +
6724 + while (current != NULL) {
6725 + free(current->errmsg);
6726 + current = (*errors)->next;
6727 + free(*errors);
6728 + *errors = current;
6729 + }
6730 +
6731 +
6732 +}
6733 +
6734 +
6735 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_utils.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.h
6736 --- busybox-1.1.2-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6737 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-05-09 02:06:48.000000000 +0200
6738 @@ -0,0 +1,29 @@
6739 +/* ipkg_utils.h - the itsy package management system
6740 +
6741 + Steven M. Ayer
6742 +
6743 + Copyright (C) 2002 Compaq Computer Corporation
6744 +
6745 + This program is free software; you can redistribute it and/or
6746 + modify it under the terms of the GNU General Public License as
6747 + published by the Free Software Foundation; either version 2, or (at
6748 + your option) any later version.
6749 +
6750 + This program is distributed in the hope that it will be useful, but
6751 + WITHOUT ANY WARRANTY; without even the implied warranty of
6752 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6753 + General Public License for more details.
6754 +*/
6755 +
6756 +#ifndef IPKG_UTILS_H
6757 +#define IPKG_UTILS_H
6758 +
6759 +#include "pkg.h"
6760 +
6761 +int get_available_blocks(char * filesystem);
6762 +char **read_raw_pkgs_from_file(const char *file_name);
6763 +char **read_raw_pkgs_from_stream(FILE *fp);
6764 +char *trim_alloc(char * line);
6765 +int line_is_blank(const char *line);
6766 +
6767 +#endif
6768 diff -ruN busybox-1.1.2-orig/archival/libipkg/libipkg.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.c
6769 --- busybox-1.1.2-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6770 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-05-09 02:12:05.000000000 +0200
6771 @@ -0,0 +1,527 @@
6772 +/* ipkglib.c - the itsy package management system
6773 +
6774 + Florina Boor
6775 +
6776 + Copyright (C) 2003 kernel concepts
6777 +
6778 + This program is free software; you can redistribute it and/or
6779 + modify it under the terms of the GNU General Public License as
6780 + published by the Free Software Foundation; either version 2, or (at
6781 + your option) any later version.
6782 +
6783 + This program is distributed in the hope that it will be useful, but
6784 + WITHOUT ANY WARRANTY; without even the implied warranty of
6785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6786 + General Public License for more details.
6787 +*/
6788 +
6789 +#ifdef IPKG_LIB
6790 +
6791 +#include "ipkg.h"
6792 +#include "ipkg_includes.h"
6793 +#include "libipkg.h"
6794 +
6795 +#include "args.h"
6796 +#include "ipkg_conf.h"
6797 +#include "ipkg_cmd.h"
6798 +#include "file_util.h"
6799 +
6800 +
6801 +
6802 +ipkg_message_callback ipkg_cb_message = NULL;
6803 +ipkg_response_callback ipkg_cb_response = NULL;
6804 +ipkg_status_callback ipkg_cb_status = NULL;
6805 +ipkg_list_callback ipkg_cb_list = NULL;
6806 +
6807 +
6808 +int
6809 +ipkg_init (ipkg_message_callback mcall,
6810 + ipkg_response_callback rcall,
6811 + args_t * args)
6812 +{
6813 + ipkg_cb_message = mcall;
6814 + ipkg_cb_response = rcall;
6815 +
6816 + args_init (args);
6817 +
6818 + return 0;
6819 +}
6820 +
6821 +
6822 +int
6823 +ipkg_deinit (args_t * args)
6824 +{
6825 + args_deinit (args);
6826 + ipkg_cb_message = NULL;
6827 + ipkg_cb_response = NULL;
6828 +
6829 + /* place other cleanup stuff here */
6830 +
6831 + return 0;
6832 +}
6833 +
6834 +
6835 +int
6836 +ipkg_packages_list(args_t *args,
6837 + const char *packages,
6838 + ipkg_list_callback cblist,
6839 + void *userdata)
6840 +{
6841 + ipkg_cmd_t *cmd;
6842 + ipkg_conf_t ipkg_conf;
6843 + int err;
6844 +
6845 + err = ipkg_conf_init (&ipkg_conf, args);
6846 + if (err)
6847 + {
6848 + return err;
6849 + }
6850 +
6851 + ipkg_cb_list = cblist;
6852 + /* we need to do this because of static declarations,
6853 + * maybe a good idea to change */
6854 + cmd = ipkg_cmd_find ("list");
6855 + if (packages)
6856 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6857 + else
6858 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6859 + ipkg_cb_list = NULL;
6860 + ipkg_conf_deinit (&ipkg_conf);
6861 + return (err);
6862 +}
6863 +
6864 +
6865 +int
6866 +ipkg_packages_status(args_t *args,
6867 + const char *packages,
6868 + ipkg_status_callback cbstatus,
6869 + void *userdata)
6870 +{
6871 + ipkg_cmd_t *cmd;
6872 + ipkg_conf_t ipkg_conf;
6873 + int err;
6874 +
6875 + err = ipkg_conf_init (&ipkg_conf, args);
6876 + if (err)
6877 + {
6878 + return err;
6879 + }
6880 +
6881 + ipkg_cb_status = cbstatus;
6882 +
6883 + /* we need to do this because of static declarations,
6884 + * maybe a good idea to change */
6885 + cmd = ipkg_cmd_find ("status");
6886 + if (packages)
6887 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6888 + else
6889 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6890 +
6891 + ipkg_cb_status = NULL;
6892 + ipkg_conf_deinit (&ipkg_conf);
6893 + return (err);
6894 +}
6895 +
6896 +
6897 +int
6898 +ipkg_packages_info(args_t *args,
6899 + const char *packages,
6900 + ipkg_status_callback cbstatus,
6901 + void *userdata)
6902 +{
6903 + ipkg_cmd_t *cmd;
6904 + ipkg_conf_t ipkg_conf;
6905 + int err;
6906 +
6907 + err = ipkg_conf_init (&ipkg_conf, args);
6908 + if (err)
6909 + {
6910 + return err;
6911 + }
6912 +
6913 + ipkg_cb_status = cbstatus;
6914 +
6915 + /* we need to do this because of static declarations,
6916 + * maybe a good idea to change */
6917 + cmd = ipkg_cmd_find ("info");
6918 + if (packages)
6919 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6920 + else
6921 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6922 +
6923 + ipkg_cb_status = NULL;
6924 + ipkg_conf_deinit (&ipkg_conf);
6925 + return (err);
6926 +}
6927 +
6928 +
6929 +int
6930 +ipkg_packages_install (args_t * args, const char *name)
6931 +{
6932 + ipkg_cmd_t *cmd;
6933 + ipkg_conf_t ipkg_conf;
6934 + int err;
6935 +
6936 + /* this error should be handled in application */
6937 + if (!name || !strlen (name))
6938 + return (-1);
6939 +
6940 + err = ipkg_conf_init (&ipkg_conf, args);
6941 + if (err)
6942 + {
6943 + return err;
6944 + }
6945 +
6946 + /* we need to do this because of static declarations,
6947 + * maybe a good idea to change */
6948 + cmd = ipkg_cmd_find ("install");
6949 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6950 +
6951 + ipkg_conf_deinit(&ipkg_conf);
6952 + return (err);
6953 +}
6954 +
6955 +
6956 +int
6957 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6958 +{
6959 + ipkg_cmd_t *cmd;
6960 + ipkg_conf_t ipkg_conf;
6961 + int err;
6962 +
6963 + /* this error should be handled in application */
6964 + if (!name || !strlen (name))
6965 + return (-1);
6966 +
6967 + err = ipkg_conf_init (&ipkg_conf, args);
6968 + if (err)
6969 + {
6970 + return err;
6971 + }
6972 +
6973 + /* we need to do this because of static declarations,
6974 + * maybe a good idea to change */
6975 + if (purge)
6976 + cmd = ipkg_cmd_find ("purge");
6977 + else
6978 + cmd = ipkg_cmd_find ("remove");
6979 +
6980 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6981 +
6982 + ipkg_conf_deinit(&ipkg_conf);
6983 + return (err);
6984 +}
6985 +
6986 +
6987 +int
6988 +ipkg_lists_update(args_t *args)
6989 +{
6990 + ipkg_cmd_t *cmd;
6991 + ipkg_conf_t ipkg_conf;
6992 + int err;
6993 +
6994 + err = ipkg_conf_init (&ipkg_conf, args);
6995 + if (err)
6996 + {
6997 + return err;
6998 + }
6999 +
7000 + /* we need to do this because of static declarations,
7001 + * maybe a good idea to change */
7002 + cmd = ipkg_cmd_find ("update");
7003 +
7004 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
7005 +
7006 + ipkg_conf_deinit(&ipkg_conf);
7007 + return (err);
7008 +}
7009 +
7010 +
7011 +int
7012 +ipkg_packages_upgrade(args_t *args)
7013 +{
7014 + ipkg_cmd_t *cmd;
7015 + ipkg_conf_t ipkg_conf;
7016 + int err;
7017 +
7018 + err = ipkg_conf_init (&ipkg_conf, args);
7019 + if (err)
7020 + {
7021 + return err;
7022 + }
7023 +
7024 + /* we need to do this because of static declarations,
7025 + * maybe a good idea to change */
7026 + cmd = ipkg_cmd_find ("upgrade");
7027 +
7028 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
7029 +
7030 + ipkg_conf_deinit(&ipkg_conf);
7031 + return (err);
7032 +}
7033 +
7034 +
7035 +int
7036 +ipkg_packages_download (args_t * args, const char *name)
7037 +{
7038 + ipkg_cmd_t *cmd;
7039 + ipkg_conf_t ipkg_conf;
7040 + int err;
7041 +
7042 + /* this error should be handled in application */
7043 + if (!name || !strlen (name))
7044 + return (-1);
7045 +
7046 + err = ipkg_conf_init (&ipkg_conf, args);
7047 + if (err)
7048 + {
7049 + return err;
7050 + }
7051 +
7052 + /* we need to do this because of static declarations,
7053 + * maybe a good idea to change */
7054 + cmd = ipkg_cmd_find ("download");
7055 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
7056 +
7057 + ipkg_conf_deinit(&ipkg_conf);
7058 + return (err);
7059 +}
7060 +
7061 +
7062 +int
7063 +ipkg_package_files(args_t *args,
7064 + const char *name,
7065 + ipkg_list_callback cblist,
7066 + void *userdata)
7067 +{
7068 + ipkg_cmd_t *cmd;
7069 + ipkg_conf_t ipkg_conf;
7070 + int err;
7071 +
7072 + /* this error should be handled in application */
7073 + if (!name || !strlen (name))
7074 + return (-1);
7075 +
7076 + err = ipkg_conf_init (&ipkg_conf, args);
7077 + if (err)
7078 + {
7079 + return err;
7080 + }
7081 +
7082 + ipkg_cb_list = cblist;
7083 +
7084 + /* we need to do this because of static declarations,
7085 + * maybe a good idea to change */
7086 + cmd = ipkg_cmd_find ("files");
7087 +
7088 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7089 +
7090 + ipkg_cb_list = NULL;
7091 + ipkg_conf_deinit(&ipkg_conf);
7092 + return (err);
7093 +}
7094 +
7095 +
7096 +int
7097 +ipkg_file_search(args_t *args,
7098 + const char *file,
7099 + ipkg_list_callback cblist,
7100 + void *userdata)
7101 +{
7102 + ipkg_cmd_t *cmd;
7103 + ipkg_conf_t ipkg_conf;
7104 + int err;
7105 +
7106 + /* this error should be handled in application */
7107 + if (!file || !strlen (file))
7108 + return (-1);
7109 +
7110 + err = ipkg_conf_init (&ipkg_conf, args);
7111 + if (err)
7112 + {
7113 + return err;
7114 + }
7115 +
7116 + ipkg_cb_list = cblist;
7117 +
7118 + /* we need to do this because of static declarations,
7119 + * maybe a good idea to change */
7120 + cmd = ipkg_cmd_find ("search");
7121 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7122 +
7123 + ipkg_cb_list = NULL;
7124 + ipkg_conf_deinit(&ipkg_conf);
7125 + return(err);
7126 +}
7127 +
7128 +
7129 +int
7130 +ipkg_file_what(args_t *args, const char *file, const char* command)
7131 +{
7132 + ipkg_cmd_t *cmd;
7133 + ipkg_conf_t ipkg_conf;
7134 + int err;
7135 +
7136 + /* this error should be handled in application */
7137 + if (!file || !strlen (file))
7138 + return (-1);
7139 +
7140 + err = ipkg_conf_init (&ipkg_conf, args);
7141 + if (err)
7142 + {
7143 + return err;
7144 + }
7145 +
7146 + /* we need to do this because of static declarations,
7147 + * maybe a good idea to change */
7148 + cmd = ipkg_cmd_find (command);
7149 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7150 +
7151 + ipkg_conf_deinit(&ipkg_conf);
7152 + return(err);
7153 +}
7154 +
7155 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7156 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7157 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7158 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7159 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7160 +
7161 +
7162 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7163 + char *msg)
7164 +{
7165 + if (conf && (conf->verbosity < level)) {
7166 + return 0;
7167 + } else {
7168 +#ifdef IPKG_LIB
7169 + if ( level == IPKG_ERROR ){
7170 + push_error_list(&error_list, msg);
7171 +// printf(msg);
7172 + } else
7173 +#endif
7174 + printf(msg);
7175 + }
7176 + return 0;
7177 +}
7178 +
7179 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7180 + pkg_state_status_t status, void *userdata)
7181 +{
7182 + if (desc)
7183 + printf("%s - %s - %s\n", name, version, desc);
7184 + else
7185 + printf("%s - %s\n", name, version);
7186 + return 0;
7187 +}
7188 +
7189 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7190 + pkg_state_status_t status, void *userdata)
7191 +{
7192 + if (desc)
7193 + printf("%s\n", desc);
7194 + return 0;
7195 +}
7196 +
7197 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7198 + void *userdata)
7199 +{
7200 + printf("%s\n", desc);
7201 + return 0;
7202 +}
7203 +
7204 +char* default_ipkg_response_callback(char *question)
7205 +{
7206 + char *response = NULL;
7207 + printf(question);
7208 + fflush(stdout);
7209 + do {
7210 + response = (char *)file_read_line_alloc(stdin);
7211 + } while (response == NULL);
7212 + return response;
7213 +}
7214 +
7215 +/* This is used for backward compatibility */
7216 +int
7217 +ipkg_op (int argc, char *argv[])
7218 +{
7219 + int err, optind;
7220 + args_t args;
7221 + char *cmd_name;
7222 + ipkg_cmd_t *cmd;
7223 + ipkg_conf_t ipkg_conf;
7224 +
7225 + args_init (&args);
7226 +
7227 + optind = args_parse (&args, argc, argv);
7228 + if (optind == argc || optind < 0)
7229 + {
7230 + args_usage ("ipkg must have one sub-command argument");
7231 + }
7232 +
7233 + cmd_name = argv[optind++];
7234 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7235 + read anything from there.
7236 +*/
7237 + if ( !strcmp(cmd_name,"print-architecture") ||
7238 + !strcmp(cmd_name,"print_architecture") ||
7239 + !strcmp(cmd_name,"print-installation-architecture") ||
7240 + !strcmp(cmd_name,"print_installation_architecture") )
7241 + args.nocheckfordirorfile = 1;
7242 +
7243 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7244 + read anything from there.
7245 +*/
7246 + if ( !strcmp(cmd_name,"flag") ||
7247 + !strcmp(cmd_name,"configure") ||
7248 + !strcmp(cmd_name,"remove") ||
7249 + !strcmp(cmd_name,"files") ||
7250 + !strcmp(cmd_name,"search") ||
7251 + !strcmp(cmd_name,"compare_versions") ||
7252 + !strcmp(cmd_name,"compare-versions") ||
7253 + !strcmp(cmd_name,"list_installed") ||
7254 + !strcmp(cmd_name,"list-installed") ||
7255 + !strcmp(cmd_name,"status") )
7256 + args.noreadfeedsfile = 1;
7257 +
7258 +
7259 + err = ipkg_conf_init (&ipkg_conf, &args);
7260 + if (err)
7261 + {
7262 + return err;
7263 + }
7264 +
7265 + args_deinit (&args);
7266 +
7267 + ipkg_cb_message = default_ipkg_message_callback;
7268 + ipkg_cb_response = default_ipkg_response_callback;
7269 + ipkg_cb_status = default_ipkg_status_callback;
7270 + if ( strcmp(cmd_name, "files")==0)
7271 + ipkg_cb_list = default_ipkg_files_callback;
7272 + else
7273 + ipkg_cb_list = default_ipkg_list_callback;
7274 +
7275 + cmd = ipkg_cmd_find (cmd_name);
7276 + if (cmd == NULL)
7277 + {
7278 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7279 + cmd_name);
7280 + args_usage (NULL);
7281 + }
7282 +
7283 + if (cmd->requires_args && optind == argc)
7284 + {
7285 + fprintf (stderr,
7286 + "%s: the ``%s'' command requires at least one argument\n",
7287 + __FUNCTION__, cmd_name);
7288 + args_usage (NULL);
7289 + }
7290 +
7291 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7292 +
7293 + ipkg_conf_deinit (&ipkg_conf);
7294 +
7295 + return err;
7296 +}
7297 +
7298 +#endif /* IPKG_LIB */
7299 diff -ruN busybox-1.1.2-orig/archival/libipkg/libipkg.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.h
7300 --- busybox-1.1.2-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7301 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-05-09 02:06:48.000000000 +0200
7302 @@ -0,0 +1,87 @@
7303 +/* ipkglib.h - the itsy package management system
7304 +
7305 + Florian Boor <florian.boor@kernelconcepts.de>
7306 +
7307 + This program is free software; you can redistribute it and/or
7308 + modify it under the terms of the GNU General Public License as
7309 + published by the Free Software Foundation; either version 2, or (at
7310 + your option) any later version.
7311 +
7312 + This program is distributed in the hope that it will be useful, but
7313 + WITHOUT ANY WARRANTY; without even the implied warranty of
7314 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7315 + General Public License for more details.
7316 +*/
7317 +
7318 +#ifndef IPKGLIB_H
7319 +#define IPKGLIB_H
7320 +
7321 +#ifdef IPKG_LIB
7322 +
7323 +#include "ipkg_conf.h"
7324 +#include "ipkg_message.h"
7325 +
7326 +#include "args.h"
7327 +#include "pkg.h"
7328 +
7329 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7330 + char *msg);
7331 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7332 + pkg_state_status_t status, void *userdata);
7333 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7334 + void *userdata);
7335 +typedef char* (*ipkg_response_callback)(char *question);
7336 +
7337 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7338 +extern int ipkg_init (ipkg_message_callback mcall,
7339 + ipkg_response_callback rcall,
7340 + args_t * args);
7341 +
7342 +extern int ipkg_deinit (args_t *args);
7343 +extern int ipkg_packages_list(args_t *args,
7344 + const char *packages,
7345 + ipkg_list_callback cblist,
7346 + void *userdata);
7347 +extern int ipkg_packages_status(args_t *args,
7348 + const char *packages,
7349 + ipkg_status_callback cbstatus,
7350 + void *userdata);
7351 +extern int ipkg_packages_info(args_t *args,
7352 + const char *packages,
7353 + ipkg_status_callback cbstatus,
7354 + void *userdata);
7355 +extern int ipkg_packages_install(args_t *args, const char *name);
7356 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7357 +extern int ipkg_lists_update(args_t *args);
7358 +extern int ipkg_packages_upgrade(args_t *args);
7359 +extern int ipkg_packages_download(args_t *args, const char *name);
7360 +extern int ipkg_package_files(args_t *args,
7361 + const char *name,
7362 + ipkg_list_callback cblist,
7363 + void *userdata);
7364 +extern int ipkg_file_search(args_t *args,
7365 + const char *file,
7366 + ipkg_list_callback cblist,
7367 + void *userdata);
7368 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7369 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7370 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7371 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7372 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7373 +
7374 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7375 +extern ipkg_response_callback ipkg_cb_response;
7376 +extern ipkg_status_callback ipkg_cb_status;
7377 +extern ipkg_list_callback ipkg_cb_list;
7378 +extern void push_error_list(struct errlist **errors,char * msg);
7379 +extern void reverse_error_list(struct errlist **errors);
7380 +extern void free_error_list(struct errlist **errors);
7381 +
7382 +#else
7383 +
7384 +extern int ipkg_op(int argc, char *argv[]);
7385 +
7386 +#endif
7387 +
7388 +
7389 +#endif
7390 diff -ruN busybox-1.1.2-orig/archival/libipkg/md5.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.c
7391 --- busybox-1.1.2-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7392 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.c 2006-05-09 02:06:48.000000000 +0200
7393 @@ -0,0 +1,48 @@
7394 +/* md5.c - wrappers to busybox md5 functions
7395 + *
7396 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7397 + *
7398 + * This program is free software; you can redistribute it and/or modify
7399 + * it under the terms of the GNU General Public License as published by
7400 + * the Free Software Foundation; either version 2, or (at your option)
7401 + * any later version.
7402 + *
7403 + * This program is distributed in the hope that it will be useful,
7404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7406 + * GNU General Public License for more details.
7407 + *
7408 + * You should have received a copy of the GNU General Public License
7409 + * along with this program; if not, write to the Free Software Foundation,
7410 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7411 + */
7412 +
7413 +#include <stdio.h>
7414 +#include "libbb.h"
7415 +
7416 +#include "md5.h"
7417 +
7418 +int md5_stream(FILE *stream, void *resblock)
7419 +{
7420 + int fd;
7421 + int sum;
7422 +
7423 + if( (fd = fileno(stream)) == -1 ) {
7424 + bb_error_msg("bad file descriptor");
7425 + return 1;
7426 + }
7427 +
7428 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7429 +
7430 + return 0;
7431 +}
7432 +
7433 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7434 +{
7435 + md5_ctx_t md5_cx;
7436 +
7437 + md5_begin(&md5_cx);
7438 + md5_hash(buffer, len, &md5_cx);
7439 + return md5_end(resblock, &md5_cx);
7440 +}
7441 +
7442 diff -ruN busybox-1.1.2-orig/archival/libipkg/md5.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.h
7443 --- busybox-1.1.2-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7444 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.h 2006-05-09 02:06:48.000000000 +0200
7445 @@ -0,0 +1,35 @@
7446 +/* md5.h - Compute MD5 checksum of files or strings according to the
7447 + * definition of MD5 in RFC 1321 from April 1992.
7448 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7449 + *
7450 + * This program is free software; you can redistribute it and/or modify
7451 + * it under the terms of the GNU General Public License as published by
7452 + * the Free Software Foundation; either version 2, or (at your option)
7453 + * any later version.
7454 + *
7455 + * This program is distributed in the hope that it will be useful,
7456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7458 + * GNU General Public License for more details.
7459 + *
7460 + * You should have received a copy of the GNU General Public License
7461 + * along with this program; if not, write to the Free Software Foundation,
7462 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7463 + */
7464 +
7465 +#ifndef MD5_H
7466 +#define MD5_H
7467 +
7468 +/* Compute MD5 message digest for bytes read from STREAM. The
7469 + resulting message digest number will be written into the 16 bytes
7470 + beginning at RESBLOCK. */
7471 +int md5_stream(FILE *stream, void *resblock);
7472 +
7473 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7474 + result is always in little endian byte order, so that a byte-wise
7475 + output yields to the wanted ASCII representation of the message
7476 + digest. */
7477 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7478 +
7479 +#endif
7480 +
7481 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.c
7482 --- busybox-1.1.2-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7483 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-05-09 02:06:48.000000000 +0200
7484 @@ -0,0 +1,40 @@
7485 +/* nv_pair.c - the itsy package management system
7486 +
7487 + Carl D. Worth
7488 +
7489 + Copyright (C) 2001 University of Southern California
7490 +
7491 + This program is free software; you can redistribute it and/or
7492 + modify it under the terms of the GNU General Public License as
7493 + published by the Free Software Foundation; either version 2, or (at
7494 + your option) any later version.
7495 +
7496 + This program is distributed in the hope that it will be useful, but
7497 + WITHOUT ANY WARRANTY; without even the implied warranty of
7498 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7499 + General Public License for more details.
7500 +*/
7501 +
7502 +#include "ipkg.h"
7503 +
7504 +#include "nv_pair.h"
7505 +#include "str_util.h"
7506 +
7507 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7508 +{
7509 + nv_pair->name = str_dup_safe(name);
7510 + nv_pair->value = str_dup_safe(value);
7511 +
7512 + return 0;
7513 +}
7514 +
7515 +void nv_pair_deinit(nv_pair_t *nv_pair)
7516 +{
7517 + free(nv_pair->name);
7518 + nv_pair->name = NULL;
7519 +
7520 + free(nv_pair->value);
7521 + nv_pair->value = NULL;
7522 +}
7523 +
7524 +
7525 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.h
7526 --- busybox-1.1.2-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7527 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-05-09 02:06:48.000000000 +0200
7528 @@ -0,0 +1,32 @@
7529 +/* nv_pair.h - the itsy package management system
7530 +
7531 + Carl D. Worth
7532 +
7533 + Copyright (C) 2001 University of Southern California
7534 +
7535 + This program is free software; you can redistribute it and/or
7536 + modify it under the terms of the GNU General Public License as
7537 + published by the Free Software Foundation; either version 2, or (at
7538 + your option) any later version.
7539 +
7540 + This program is distributed in the hope that it will be useful, but
7541 + WITHOUT ANY WARRANTY; without even the implied warranty of
7542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7543 + General Public License for more details.
7544 +*/
7545 +
7546 +#ifndef NV_PAIR_H
7547 +#define NV_PAIR_H
7548 +
7549 +typedef struct nv_pair nv_pair_t;
7550 +struct nv_pair
7551 +{
7552 + char *name;
7553 + char *value;
7554 +};
7555 +
7556 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7557 +void nv_pair_deinit(nv_pair_t *nv_pair);
7558 +
7559 +#endif
7560 +
7561 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.c
7562 --- busybox-1.1.2-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7563 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-05-09 02:06:48.000000000 +0200
7564 @@ -0,0 +1,98 @@
7565 +/* nv_pair_list.c - the itsy package management system
7566 +
7567 + Carl D. Worth
7568 +
7569 + Copyright (C) 2001 University of Southern California
7570 +
7571 + This program is free software; you can redistribute it and/or
7572 + modify it under the terms of the GNU General Public License as
7573 + published by the Free Software Foundation; either version 2, or (at
7574 + your option) any later version.
7575 +
7576 + This program is distributed in the hope that it will be useful, but
7577 + WITHOUT ANY WARRANTY; without even the implied warranty of
7578 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7579 + General Public License for more details.
7580 +*/
7581 +
7582 +#include "ipkg.h"
7583 +
7584 +#include "nv_pair.h"
7585 +#include "void_list.h"
7586 +#include "nv_pair_list.h"
7587 +
7588 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7589 +{
7590 + return void_list_elt_init((void_list_elt_t *) elt, data);
7591 +}
7592 +
7593 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7594 +{
7595 + void_list_elt_deinit((void_list_elt_t *) elt);
7596 +}
7597 +
7598 +int nv_pair_list_init(nv_pair_list_t *list)
7599 +{
7600 + return void_list_init((void_list_t *) list);
7601 +}
7602 +
7603 +void nv_pair_list_deinit(nv_pair_list_t *list)
7604 +{
7605 + nv_pair_list_elt_t *iter;
7606 + nv_pair_t *nv_pair;
7607 +
7608 + for (iter = list->head; iter; iter = iter->next) {
7609 + nv_pair = iter->data;
7610 + nv_pair_deinit(nv_pair);
7611 +
7612 + /* malloced in nv_pair_list_append */
7613 + free(nv_pair);
7614 + iter->data = NULL;
7615 + }
7616 + void_list_deinit((void_list_t *) list);
7617 +}
7618 +
7619 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7620 +{
7621 + int err;
7622 +
7623 + /* freed in nv_pair_list_deinit */
7624 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7625 +
7626 + if (nv_pair == NULL) {
7627 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7628 + return NULL;
7629 + }
7630 + nv_pair_init(nv_pair, name, value);
7631 +
7632 + err = void_list_append((void_list_t *) list, nv_pair);
7633 + if (err) {
7634 + return NULL;
7635 + }
7636 +
7637 + return nv_pair;
7638 +}
7639 +
7640 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7641 +{
7642 + return void_list_push((void_list_t *) list, data);
7643 +}
7644 +
7645 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7646 +{
7647 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7648 +}
7649 +
7650 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7651 +{
7652 + nv_pair_list_elt_t *iter;
7653 + nv_pair_t *nv_pair;
7654 +
7655 + for (iter = list->head; iter; iter = iter->next) {
7656 + nv_pair = iter->data;
7657 + if (strcmp(nv_pair->name, name) == 0) {
7658 + return nv_pair->value;
7659 + }
7660 + }
7661 + return NULL;
7662 +}
7663 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.h
7664 --- busybox-1.1.2-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7665 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-05-09 02:06:48.000000000 +0200
7666 @@ -0,0 +1,60 @@
7667 +/* nv_pair_list.h - the itsy package management system
7668 +
7669 + Carl D. Worth
7670 +
7671 + Copyright (C) 2001 University of Southern California
7672 +
7673 + This program is free software; you can redistribute it and/or
7674 + modify it under the terms of the GNU General Public License as
7675 + published by the Free Software Foundation; either version 2, or (at
7676 + your option) any later version.
7677 +
7678 + This program is distributed in the hope that it will be useful, but
7679 + WITHOUT ANY WARRANTY; without even the implied warranty of
7680 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7681 + General Public License for more details.
7682 +*/
7683 +
7684 +#ifndef NV_PAIR_LIST_H
7685 +#define NV_PAIR_LIST_H
7686 +
7687 +#include "nv_pair.h"
7688 +#include "void_list.h"
7689 +
7690 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7691 +struct nv_pair_list_elt
7692 +{
7693 + nv_pair_list_elt_t *next;
7694 + nv_pair_t *data;
7695 +};
7696 +
7697 +typedef struct nv_pair_list nv_pair_list_t;
7698 +struct nv_pair_list
7699 +{
7700 + nv_pair_list_elt_t pre_head;
7701 + nv_pair_list_elt_t *head;
7702 + nv_pair_list_elt_t *tail;
7703 +};
7704 +
7705 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7706 +{
7707 + if (list->head == NULL)
7708 + return 1;
7709 + else
7710 + return 0;
7711 +}
7712 +
7713 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7714 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7715 +
7716 +int nv_pair_list_init(nv_pair_list_t *list);
7717 +void nv_pair_list_deinit(nv_pair_list_t *list);
7718 +
7719 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7720 + const char *name, const char *value);
7721 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7722 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7723 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7724 +
7725 +#endif
7726 +
7727 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.c
7728 --- busybox-1.1.2-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7729 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.c 2006-05-09 02:12:05.000000000 +0200
7730 @@ -0,0 +1,1754 @@
7731 +/* pkg.c - the itsy package management system
7732 +
7733 + Carl D. Worth
7734 +
7735 + Copyright (C) 2001 University of Southern California
7736 +
7737 + This program is free software; you can redistribute it and/or
7738 + modify it under the terms of the GNU General Public License as
7739 + published by the Free Software Foundation; either version 2, or (at
7740 + your option) any later version.
7741 +
7742 + This program is distributed in the hope that it will be useful, but
7743 + WITHOUT ANY WARRANTY; without even the implied warranty of
7744 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7745 + General Public License for more details.
7746 +*/
7747 +
7748 +#include "ipkg.h"
7749 +#include <ctype.h>
7750 +#include <string.h>
7751 +#include <errno.h>
7752 +
7753 +#include "pkg.h"
7754 +
7755 +#include "pkg_parse.h"
7756 +#include "pkg_extract.h"
7757 +#include "ipkg_message.h"
7758 +#include "ipkg_utils.h"
7759 +
7760 +#include "sprintf_alloc.h"
7761 +#include "file_util.h"
7762 +#include "str_util.h"
7763 +#include "xsystem.h"
7764 +#include "ipkg_conf.h"
7765 +
7766 +typedef struct enum_map enum_map_t;
7767 +struct enum_map
7768 +{
7769 + int value;
7770 + char *str;
7771 +};
7772 +
7773 +static const enum_map_t pkg_state_want_map[] = {
7774 + { SW_UNKNOWN, "unknown"},
7775 + { SW_INSTALL, "install"},
7776 + { SW_DEINSTALL, "deinstall"},
7777 + { SW_PURGE, "purge"}
7778 +};
7779 +
7780 +static const enum_map_t pkg_state_flag_map[] = {
7781 + { SF_OK, "ok"},
7782 + { SF_REINSTREQ, "reinstreq"},
7783 + { SF_HOLD, "hold"},
7784 + { SF_REPLACE, "replace"},
7785 + { SF_NOPRUNE, "noprune"},
7786 + { SF_PREFER, "prefer"},
7787 + { SF_OBSOLETE, "obsolete"},
7788 + { SF_USER, "user"},
7789 +};
7790 +
7791 +static const enum_map_t pkg_state_status_map[] = {
7792 + { SS_NOT_INSTALLED, "not-installed" },
7793 + { SS_UNPACKED, "unpacked" },
7794 + { SS_HALF_CONFIGURED, "half-configured" },
7795 + { SS_INSTALLED, "installed" },
7796 + { SS_HALF_INSTALLED, "half-installed" },
7797 + { SS_CONFIG_FILES, "config-files" },
7798 + { SS_POST_INST_FAILED, "post-inst-failed" },
7799 + { SS_REMOVAL_FAILED, "removal-failed" }
7800 +};
7801 +
7802 +static int verrevcmp(const char *val, const char *ref);
7803 +
7804 +
7805 +pkg_t *pkg_new(void)
7806 +{
7807 + pkg_t *pkg;
7808 +
7809 + pkg = malloc(sizeof(pkg_t));
7810 + if (pkg == NULL) {
7811 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7812 + return NULL;
7813 + }
7814 +
7815 + pkg_init(pkg);
7816 +
7817 + return pkg;
7818 +}
7819 +
7820 +int pkg_init(pkg_t *pkg)
7821 +{
7822 + memset(pkg, 0, sizeof(pkg_t));
7823 + pkg->name = NULL;
7824 + pkg->epoch = 0;
7825 + pkg->version = NULL;
7826 + pkg->revision = NULL;
7827 + pkg->familiar_revision = NULL;
7828 + pkg->dest = NULL;
7829 + pkg->src = NULL;
7830 + pkg->architecture = NULL;
7831 + pkg->maintainer = NULL;
7832 + pkg->section = NULL;
7833 + pkg->description = NULL;
7834 + pkg->state_want = SW_UNKNOWN;
7835 + pkg->state_flag = SF_OK;
7836 + pkg->state_status = SS_NOT_INSTALLED;
7837 + pkg->depends_str = NULL;
7838 + pkg->provides_str = NULL;
7839 + pkg->depends_count = 0;
7840 + pkg->depends = NULL;
7841 + pkg->suggests_str = NULL;
7842 + pkg->recommends_str = NULL;
7843 + pkg->suggests_count = 0;
7844 + pkg->recommends_count = 0;
7845 +
7846 + /* Abhaya: added init for conflicts fields */
7847 + pkg->conflicts = NULL;
7848 + pkg->conflicts_count = 0;
7849 +
7850 + /* added for replaces. Jamey 7/23/2002 */
7851 + pkg->replaces = NULL;
7852 + pkg->replaces_count = 0;
7853 +
7854 + pkg->pre_depends_count = 0;
7855 + pkg->pre_depends_str = NULL;
7856 + pkg->provides_count = 0;
7857 + pkg->provides = NULL;
7858 + pkg->filename = NULL;
7859 + pkg->local_filename = NULL;
7860 + pkg->tmp_unpack_dir = NULL;
7861 + pkg->md5sum = NULL;
7862 + pkg->size = NULL;
7863 + pkg->installed_size = NULL;
7864 + pkg->priority = NULL;
7865 + pkg->source = NULL;
7866 + conffile_list_init(&pkg->conffiles);
7867 + pkg->installed_files = NULL;
7868 + pkg->installed_files_ref_cnt = 0;
7869 + pkg->essential = 0;
7870 + pkg->provided_by_hand = 0;
7871 +
7872 + return 0;
7873 +}
7874 +
7875 +void pkg_deinit(pkg_t *pkg)
7876 +{
7877 + free(pkg->name);
7878 + pkg->name = NULL;
7879 + pkg->epoch = 0;
7880 + free(pkg->version);
7881 + pkg->version = NULL;
7882 + /* revision and familiar_revision share storage with version, so
7883 + don't free */
7884 + pkg->revision = NULL;
7885 + pkg->familiar_revision = NULL;
7886 + /* owned by ipkg_conf_t */
7887 + pkg->dest = NULL;
7888 + /* owned by ipkg_conf_t */
7889 + pkg->src = NULL;
7890 + free(pkg->architecture);
7891 + pkg->architecture = NULL;
7892 + free(pkg->maintainer);
7893 + pkg->maintainer = NULL;
7894 + free(pkg->section);
7895 + pkg->section = NULL;
7896 + free(pkg->description);
7897 + pkg->description = NULL;
7898 + pkg->state_want = SW_UNKNOWN;
7899 + pkg->state_flag = SF_OK;
7900 + pkg->state_status = SS_NOT_INSTALLED;
7901 + free(pkg->depends_str);
7902 + pkg->depends_str = NULL;
7903 + free(pkg->provides_str);
7904 + pkg->provides_str = NULL;
7905 + pkg->depends_count = 0;
7906 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7907 + pkg->pre_depends_count = 0;
7908 + free(pkg->pre_depends_str);
7909 + pkg->pre_depends_str = NULL;
7910 + pkg->provides_count = 0;
7911 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7912 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7913 + free(pkg->filename);
7914 + pkg->filename = NULL;
7915 + free(pkg->local_filename);
7916 + pkg->local_filename = NULL;
7917 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7918 + ipkg_install.c here. See comment in
7919 + ipkg_install.c:cleanup_temporary_files */
7920 + free(pkg->tmp_unpack_dir);
7921 + pkg->tmp_unpack_dir = NULL;
7922 + free(pkg->md5sum);
7923 + pkg->md5sum = NULL;
7924 + free(pkg->size);
7925 + pkg->size = NULL;
7926 + free(pkg->installed_size);
7927 + pkg->installed_size = NULL;
7928 + free(pkg->priority);
7929 + pkg->priority = NULL;
7930 + free(pkg->source);
7931 + pkg->source = NULL;
7932 + conffile_list_deinit(&pkg->conffiles);
7933 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7934 + since if they are calling deinit, they should know. Maybe do an
7935 + assertion here instead? */
7936 + pkg->installed_files_ref_cnt = 1;
7937 + pkg_free_installed_files(pkg);
7938 + pkg->essential = 0;
7939 +}
7940 +
7941 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7942 +{
7943 + int err;
7944 + char **raw;
7945 + FILE *control_file;
7946 +
7947 + err = pkg_init(pkg);
7948 + if (err) { return err; }
7949 +
7950 + pkg->local_filename = strdup(filename);
7951 +
7952 + control_file = tmpfile();
7953 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7954 + if (err) { return err; }
7955 +
7956 + rewind(control_file);
7957 + raw = read_raw_pkgs_from_stream(control_file);
7958 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7959 +
7960 + fclose(control_file);
7961 +
7962 + return 0;
7963 +}
7964 +
7965 +/* Merge any new information in newpkg into oldpkg */
7966 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7967 + newpkg, but should leave it usable. This rework is so that
7968 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7969 +/*
7970 + * uh, i thought that i had originally written this so that it took
7971 + * two pkgs and returned a new one? we can do that again... -sma
7972 + */
7973 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7974 +{
7975 + if (oldpkg == newpkg) {
7976 + return 0;
7977 + }
7978 +
7979 + if (!oldpkg->src)
7980 + oldpkg->src = newpkg->src;
7981 + if (!oldpkg->dest)
7982 + oldpkg->dest = newpkg->dest;
7983 + if (!oldpkg->architecture)
7984 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7985 + if (!oldpkg->arch_priority)
7986 + oldpkg->arch_priority = newpkg->arch_priority;
7987 + if (!oldpkg->section)
7988 + oldpkg->section = str_dup_safe(newpkg->section);
7989 + if(!oldpkg->maintainer)
7990 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7991 + if(!oldpkg->description)
7992 + oldpkg->description = str_dup_safe(newpkg->description);
7993 + if (set_status) {
7994 + /* merge the state_flags from the new package */
7995 + oldpkg->state_want = newpkg->state_want;
7996 + oldpkg->state_status = newpkg->state_status;
7997 + oldpkg->state_flag = newpkg->state_flag;
7998 + } else {
7999 + if (oldpkg->state_want == SW_UNKNOWN)
8000 + oldpkg->state_want = newpkg->state_want;
8001 + if (oldpkg->state_status == SS_NOT_INSTALLED)
8002 + oldpkg->state_status = newpkg->state_status;
8003 + oldpkg->state_flag |= newpkg->state_flag;
8004 + }
8005 +
8006 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
8007 + oldpkg->depends_str = newpkg->depends_str;
8008 + newpkg->depends_str = NULL;
8009 + oldpkg->depends_count = newpkg->depends_count;
8010 + newpkg->depends_count = 0;
8011 +
8012 + oldpkg->depends = newpkg->depends;
8013 + newpkg->depends = NULL;
8014 +
8015 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
8016 + newpkg->pre_depends_str = NULL;
8017 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
8018 + newpkg->pre_depends_count = 0;
8019 +
8020 + oldpkg->recommends_str = newpkg->recommends_str;
8021 + newpkg->recommends_str = NULL;
8022 + oldpkg->recommends_count = newpkg->recommends_count;
8023 + newpkg->recommends_count = 0;
8024 +
8025 + oldpkg->suggests_str = newpkg->suggests_str;
8026 + newpkg->suggests_str = NULL;
8027 + oldpkg->suggests_count = newpkg->suggests_count;
8028 + newpkg->suggests_count = 0;
8029 + }
8030 +
8031 + if (!oldpkg->provides_str) {
8032 + oldpkg->provides_str = newpkg->provides_str;
8033 + newpkg->provides_str = NULL;
8034 + oldpkg->provides_count = newpkg->provides_count;
8035 + newpkg->provides_count = 0;
8036 +
8037 + oldpkg->provides = newpkg->provides;
8038 + newpkg->provides = NULL;
8039 + }
8040 +
8041 + if (!oldpkg->conflicts_str) {
8042 + oldpkg->conflicts_str = newpkg->conflicts_str;
8043 + newpkg->conflicts_str = NULL;
8044 + oldpkg->conflicts_count = newpkg->conflicts_count;
8045 + newpkg->conflicts_count = 0;
8046 +
8047 + oldpkg->conflicts = newpkg->conflicts;
8048 + newpkg->conflicts = NULL;
8049 + }
8050 +
8051 + if (!oldpkg->replaces_str) {
8052 + oldpkg->replaces_str = newpkg->replaces_str;
8053 + newpkg->replaces_str = NULL;
8054 + oldpkg->replaces_count = newpkg->replaces_count;
8055 + newpkg->replaces_count = 0;
8056 +
8057 + oldpkg->replaces = newpkg->replaces;
8058 + newpkg->replaces = NULL;
8059 + }
8060 +
8061 + if (!oldpkg->filename)
8062 + oldpkg->filename = str_dup_safe(newpkg->filename);
8063 + if (0)
8064 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8065 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8066 + if (!oldpkg->local_filename)
8067 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8068 + if (!oldpkg->tmp_unpack_dir)
8069 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8070 + if (!oldpkg->md5sum)
8071 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8072 + if (!oldpkg->size)
8073 + oldpkg->size = str_dup_safe(newpkg->size);
8074 + if (!oldpkg->installed_size)
8075 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8076 + if (!oldpkg->priority)
8077 + oldpkg->priority = str_dup_safe(newpkg->priority);
8078 + if (!oldpkg->source)
8079 + oldpkg->source = str_dup_safe(newpkg->source);
8080 + if (oldpkg->conffiles.head == NULL){
8081 + oldpkg->conffiles = newpkg->conffiles;
8082 + conffile_list_init(&newpkg->conffiles);
8083 + }
8084 + if (!oldpkg->installed_files){
8085 + oldpkg->installed_files = newpkg->installed_files;
8086 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8087 + newpkg->installed_files = NULL;
8088 + }
8089 + if (!oldpkg->essential)
8090 + oldpkg->essential = newpkg->essential;
8091 +
8092 + return 0;
8093 +}
8094 +
8095 +abstract_pkg_t *abstract_pkg_new(void)
8096 +{
8097 + abstract_pkg_t * ab_pkg;
8098 +
8099 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8100 +
8101 + if (ab_pkg == NULL) {
8102 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8103 + return NULL;
8104 + }
8105 +
8106 + if ( abstract_pkg_init(ab_pkg) < 0 )
8107 + return NULL;
8108 +
8109 + return ab_pkg;
8110 +}
8111 +
8112 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8113 +{
8114 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8115 +
8116 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8117 + if (ab_pkg->provided_by==NULL){
8118 + return -1;
8119 + }
8120 + ab_pkg->dependencies_checked = 0;
8121 + ab_pkg->state_status = SS_NOT_INSTALLED;
8122 +
8123 + return 0;
8124 +}
8125 +
8126 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8127 + char * temp_str;
8128 + char **raw =NULL;
8129 + char **raw_start=NULL;
8130 +
8131 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8132 + if (temp_str == NULL ){
8133 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8134 + return;
8135 + }
8136 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8137 +
8138 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8139 + if (raw == NULL ){
8140 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8141 + return;
8142 + }
8143 +
8144 + while(*raw){
8145 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8146 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8147 + }
8148 + }
8149 + raw = raw_start;
8150 + while (*raw) {
8151 + if (raw!=NULL)
8152 + free(*raw++);
8153 + }
8154 +
8155 + free(raw_start);
8156 + free(temp_str);
8157 +
8158 + return ;
8159 +
8160 +}
8161 +
8162 +char * pkg_formatted_info(pkg_t *pkg )
8163 +{
8164 + char *line;
8165 + char * buff;
8166 +
8167 + buff = malloc(8192);
8168 + if (buff == NULL) {
8169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8170 + return NULL;
8171 + }
8172 +
8173 + buff[0] = '\0';
8174 +
8175 + line = pkg_formatted_field(pkg, "Package");
8176 + strncat(buff ,line, strlen(line));
8177 + free(line);
8178 +
8179 + line = pkg_formatted_field(pkg, "Version");
8180 + strncat(buff ,line, strlen(line));
8181 + free(line);
8182 +
8183 + line = pkg_formatted_field(pkg, "Depends");
8184 + strncat(buff ,line, strlen(line));
8185 + free(line);
8186 +
8187 + line = pkg_formatted_field(pkg, "Recommends");
8188 + strncat(buff ,line, strlen(line));
8189 + free(line);
8190 +
8191 + line = pkg_formatted_field(pkg, "Suggests");
8192 + strncat(buff ,line, strlen(line));
8193 + free(line);
8194 +
8195 + line = pkg_formatted_field(pkg, "Provides");
8196 + strncat(buff ,line, strlen(line));
8197 + free(line);
8198 +
8199 + line = pkg_formatted_field(pkg, "Replaces");
8200 + strncat(buff ,line, strlen(line));
8201 + free(line);
8202 +
8203 + line = pkg_formatted_field(pkg, "Conflicts");
8204 + strncat(buff ,line, strlen(line));
8205 + free(line);
8206 +
8207 + line = pkg_formatted_field(pkg, "Status");
8208 + strncat(buff ,line, strlen(line));
8209 + free(line);
8210 +
8211 + line = pkg_formatted_field(pkg, "Section");
8212 + strncat(buff ,line, strlen(line));
8213 + free(line);
8214 +
8215 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8216 + strncat(buff ,line, strlen(line));
8217 + free(line);
8218 +
8219 + line = pkg_formatted_field(pkg, "Architecture");
8220 + strncat(buff ,line, strlen(line));
8221 + free(line);
8222 +
8223 + line = pkg_formatted_field(pkg, "Maintainer");
8224 + strncat(buff ,line, strlen(line));
8225 + free(line);
8226 +
8227 + line = pkg_formatted_field(pkg, "MD5sum");
8228 + strncat(buff ,line, strlen(line));
8229 + free(line);
8230 +
8231 + line = pkg_formatted_field(pkg, "Size");
8232 + strncat(buff ,line, strlen(line));
8233 + free(line);
8234 +
8235 + line = pkg_formatted_field(pkg, "Filename");
8236 + strncat(buff ,line, strlen(line));
8237 + free(line);
8238 +
8239 + line = pkg_formatted_field(pkg, "Conffiles");
8240 + strncat(buff ,line, strlen(line));
8241 + free(line);
8242 +
8243 + line = pkg_formatted_field(pkg, "Source");
8244 + strncat(buff ,line, strlen(line));
8245 + free(line);
8246 +
8247 + line = pkg_formatted_field(pkg, "Description");
8248 + strncat(buff ,line, strlen(line));
8249 + free(line);
8250 +
8251 + line = pkg_formatted_field(pkg, "Installed-Time");
8252 + strncat(buff ,line, strlen(line));
8253 + free(line);
8254 +
8255 + return buff;
8256 +}
8257 +
8258 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8259 +{
8260 + static size_t LINE_LEN = 128;
8261 + char * temp = (char *)malloc(1);
8262 + int len = 0;
8263 + int flag_provide_false = 0;
8264 +
8265 +/*
8266 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8267 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8268 +*/
8269 +
8270 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8271 + goto UNKNOWN_FMT_FIELD;
8272 + }
8273 +
8274 + temp[0]='\0';
8275 +
8276 + switch (field[0])
8277 + {
8278 + case 'a':
8279 + case 'A':
8280 + if (strcasecmp(field, "Architecture") == 0) {
8281 + /* Architecture */
8282 + if (pkg->architecture) {
8283 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8284 + if ( temp == NULL ){
8285 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8286 + return NULL;
8287 + }
8288 + temp[0]='\0';
8289 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8290 + }
8291 + } else {
8292 + goto UNKNOWN_FMT_FIELD;
8293 + }
8294 + break;
8295 + case 'c':
8296 + case 'C':
8297 + if (strcasecmp(field, "Conffiles") == 0) {
8298 + /* Conffiles */
8299 + conffile_list_elt_t *iter;
8300 + char confstr[LINE_LEN];
8301 +
8302 + if (pkg->conffiles.head == NULL) {
8303 + return temp;
8304 + }
8305 +
8306 + len = 14 ;
8307 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8308 + if (iter->data->name && iter->data->value) {
8309 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8310 + }
8311 + }
8312 + temp = (char *)realloc(temp,len);
8313 + if ( temp == NULL ){
8314 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8315 + return NULL;
8316 + }
8317 + temp[0]='\0';
8318 + strncpy(temp, "Conffiles:\n", 12);
8319 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8320 + if (iter->data->name && iter->data->value) {
8321 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8322 + strncat(temp, confstr, strlen(confstr));
8323 + }
8324 + }
8325 + } else if (strcasecmp(field, "Conflicts") == 0) {
8326 + int i;
8327 +
8328 + if (pkg->conflicts_count) {
8329 + char conflictstr[LINE_LEN];
8330 + len = 14 ;
8331 + for(i = 0; i < pkg->conflicts_count; i++) {
8332 + len = len + (strlen(pkg->conflicts_str[i])+5);
8333 + }
8334 + temp = (char *)realloc(temp,len);
8335 + if ( temp == NULL ){
8336 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8337 + return NULL;
8338 + }
8339 + temp[0]='\0';
8340 + strncpy(temp, "Conflicts:", 11);
8341 + for(i = 0; i < pkg->conflicts_count; i++) {
8342 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8343 + strncat(temp, conflictstr, strlen(conflictstr));
8344 + }
8345 + strncat(temp, "\n", strlen("\n"));
8346 + }
8347 + } else {
8348 + goto UNKNOWN_FMT_FIELD;
8349 + }
8350 + break;
8351 + case 'd':
8352 + case 'D':
8353 + if (strcasecmp(field, "Depends") == 0) {
8354 + /* Depends */
8355 + int i;
8356 +
8357 + if (pkg->depends_count) {
8358 + char depstr[LINE_LEN];
8359 + len = 14 ;
8360 + for(i = 0; i < pkg->depends_count; i++) {
8361 + len = len + (strlen(pkg->depends_str[i])+4);
8362 + }
8363 + temp = (char *)realloc(temp,len);
8364 + if ( temp == NULL ){
8365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8366 + return NULL;
8367 + }
8368 + temp[0]='\0';
8369 + strncpy(temp, "Depends:", 10);
8370 + for(i = 0; i < pkg->depends_count; i++) {
8371 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8372 + strncat(temp, depstr, strlen(depstr));
8373 + }
8374 + strncat(temp, "\n", strlen("\n"));
8375 + }
8376 + } else if (strcasecmp(field, "Description") == 0) {
8377 + /* Description */
8378 + if (pkg->description) {
8379 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8380 + if ( temp == NULL ){
8381 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8382 + return NULL;
8383 + }
8384 + temp[0]='\0';
8385 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8386 + }
8387 + } else {
8388 + goto UNKNOWN_FMT_FIELD;
8389 + }
8390 + break;
8391 + case 'e':
8392 + case 'E': {
8393 + /* Essential */
8394 + if (pkg->essential) {
8395 + temp = (char *)realloc(temp,16);
8396 + if ( temp == NULL ){
8397 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8398 + return NULL;
8399 + }
8400 + temp[0]='\0';
8401 + snprintf(temp, (16), "Essential: yes\n");
8402 + }
8403 + }
8404 + break;
8405 + case 'f':
8406 + case 'F': {
8407 + /* Filename */
8408 + if (pkg->filename) {
8409 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8410 + if ( temp == NULL ){
8411 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8412 + return NULL;
8413 + }
8414 + temp[0]='\0';
8415 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8416 + }
8417 + }
8418 + break;
8419 + case 'i':
8420 + case 'I': {
8421 + if (strcasecmp(field, "Installed-Size") == 0) {
8422 + /* Installed-Size */
8423 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8424 + if ( temp == NULL ){
8425 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8426 + return NULL;
8427 + }
8428 + temp[0]='\0';
8429 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8430 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8431 + temp = (char *)realloc(temp,29);
8432 + if ( temp == NULL ){
8433 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8434 + return NULL;
8435 + }
8436 + temp[0]='\0';
8437 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8438 + }
8439 + }
8440 + break;
8441 + case 'm':
8442 + case 'M': {
8443 + /* Maintainer | MD5sum */
8444 + if (strcasecmp(field, "Maintainer") == 0) {
8445 + /* Maintainer */
8446 + if (pkg->maintainer) {
8447 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8448 + if ( temp == NULL ){
8449 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8450 + return NULL;
8451 + }
8452 + temp[0]='\0';
8453 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8454 + }
8455 + } else if (strcasecmp(field, "MD5sum") == 0) {
8456 + /* MD5sum */
8457 + if (pkg->md5sum) {
8458 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8459 + if ( temp == NULL ){
8460 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8461 + return NULL;
8462 + }
8463 + temp[0]='\0';
8464 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8465 + }
8466 + } else {
8467 + goto UNKNOWN_FMT_FIELD;
8468 + }
8469 + }
8470 + break;
8471 + case 'p':
8472 + case 'P': {
8473 + if (strcasecmp(field, "Package") == 0) {
8474 + /* Package */
8475 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8476 + if ( temp == NULL ){
8477 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8478 + return NULL;
8479 + }
8480 + temp[0]='\0';
8481 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8482 + } else if (strcasecmp(field, "Priority") == 0) {
8483 + /* Priority */
8484 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8485 + if ( temp == NULL ){
8486 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8487 + return NULL;
8488 + }
8489 + temp[0]='\0';
8490 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8491 + } else if (strcasecmp(field, "Provides") == 0) {
8492 + /* Provides */
8493 + int i;
8494 +
8495 + if (pkg->provides_count) {
8496 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8497 + for ( i=0; i < pkg->provides_count; i++ ){
8498 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8499 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8500 + flag_provide_false = 1;
8501 + }
8502 + }
8503 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8504 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8505 + char provstr[LINE_LEN];
8506 + len = 15;
8507 + for(i = 0; i < pkg->provides_count; i++) {
8508 + len = len + (strlen(pkg->provides_str[i])+5);
8509 + }
8510 + temp = (char *)realloc(temp,len);
8511 + if ( temp == NULL ){
8512 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8513 + return NULL;
8514 + }
8515 + temp[0]='\0';
8516 + strncpy(temp, "Provides:", 12);
8517 + for(i = 0; i < pkg->provides_count; i++) {
8518 + if (strlen(pkg->provides_str[i])>0){;
8519 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8520 + strncat(temp, provstr, strlen(provstr));
8521 + }
8522 + }
8523 + strncat(temp, "\n", strlen("\n"));
8524 + }
8525 + }
8526 + } else {
8527 + goto UNKNOWN_FMT_FIELD;
8528 + }
8529 + }
8530 + break;
8531 + case 'r':
8532 + case 'R': {
8533 + int i;
8534 + /* Replaces | Recommends*/
8535 + if (strcasecmp (field, "Replaces") == 0) {
8536 + if (pkg->replaces_count) {
8537 + char replstr[LINE_LEN];
8538 + len = 14;
8539 + for (i = 0; i < pkg->replaces_count; i++) {
8540 + len = len + (strlen(pkg->replaces_str[i])+5);
8541 + }
8542 + temp = (char *)realloc(temp,len);
8543 + if ( temp == NULL ){
8544 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8545 + return NULL;
8546 + }
8547 + temp[0]='\0';
8548 + strncpy(temp, "Replaces:", 12);
8549 + for (i = 0; i < pkg->replaces_count; i++) {
8550 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8551 + strncat(temp, replstr, strlen(replstr));
8552 + }
8553 + strncat(temp, "\n", strlen("\n"));
8554 + }
8555 + } else if (strcasecmp (field, "Recommends") == 0) {
8556 + if (pkg->recommends_count) {
8557 + char recstr[LINE_LEN];
8558 + len = 15;
8559 + for(i = 0; i < pkg->recommends_count; i++) {
8560 + len = len + (strlen( pkg->recommends_str[i])+5);
8561 + }
8562 + temp = (char *)realloc(temp,len);
8563 + if ( temp == NULL ){
8564 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8565 + return NULL;
8566 + }
8567 + temp[0]='\0';
8568 + strncpy(temp, "Recommends:", 13);
8569 + for(i = 0; i < pkg->recommends_count; i++) {
8570 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8571 + strncat(temp, recstr, strlen(recstr));
8572 + }
8573 + strncat(temp, "\n", strlen("\n"));
8574 + }
8575 + } else {
8576 + goto UNKNOWN_FMT_FIELD;
8577 + }
8578 + }
8579 + break;
8580 + case 's':
8581 + case 'S': {
8582 + /* Section | Size | Source | Status | Suggests */
8583 + if (strcasecmp(field, "Section") == 0) {
8584 + /* Section */
8585 + if (pkg->section) {
8586 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8587 + if ( temp == NULL ){
8588 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8589 + return NULL;
8590 + }
8591 + temp[0]='\0';
8592 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8593 + }
8594 + } else if (strcasecmp(field, "Size") == 0) {
8595 + /* Size */
8596 + if (pkg->size) {
8597 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8598 + if ( temp == NULL ){
8599 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8600 + return NULL;
8601 + }
8602 + temp[0]='\0';
8603 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8604 + }
8605 + } else if (strcasecmp(field, "Source") == 0) {
8606 + /* Source */
8607 + if (pkg->source) {
8608 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8609 + if ( temp == NULL ){
8610 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8611 + return NULL;
8612 + }
8613 + temp[0]='\0';
8614 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8615 + }
8616 + } else if (strcasecmp(field, "Status") == 0) {
8617 + /* Status */
8618 + /* Benjamin Pineau note: we should avoid direct usage of
8619 + * strlen(arg) without keeping "arg" for later free()
8620 + */
8621 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8622 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8623 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8624 +
8625 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8626 + temp = (char *)realloc(temp,sum_of_sizes);
8627 + if ( temp == NULL ){
8628 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8629 + return NULL;
8630 + }
8631 + temp[0]='\0';
8632 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8633 + free(pflag);
8634 + free(pwant);
8635 + if(pstat) /* pfstat can be NULL if ENOMEM */
8636 + free(pstat);
8637 + } else if (strcasecmp(field, "Suggests") == 0) {
8638 + if (pkg->suggests_count) {
8639 + int i;
8640 + char sugstr[LINE_LEN];
8641 + len = 13;
8642 + for(i = 0; i < pkg->suggests_count; i++) {
8643 + len = len + (strlen(pkg->suggests_str[i])+5);
8644 + }
8645 + temp = (char *)realloc(temp,len);
8646 + if ( temp == NULL ){
8647 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8648 + return NULL;
8649 + }
8650 + temp[0]='\0';
8651 + strncpy(temp, "Suggests:", 10);
8652 + for(i = 0; i < pkg->suggests_count; i++) {
8653 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8654 + strncat(temp, sugstr, strlen(sugstr));
8655 + }
8656 + strncat(temp, "\n", strlen("\n"));
8657 + }
8658 + } else {
8659 + goto UNKNOWN_FMT_FIELD;
8660 + }
8661 + }
8662 + break;
8663 + case 'v':
8664 + case 'V': {
8665 + /* Version */
8666 + char *version = pkg_version_str_alloc(pkg);
8667 + temp = (char *)realloc(temp,strlen(version)+14);
8668 + if ( temp == NULL ){
8669 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8670 + return NULL;
8671 + }
8672 + temp[0]='\0';
8673 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8674 + free(version);
8675 + }
8676 + break;
8677 + default:
8678 + goto UNKNOWN_FMT_FIELD;
8679 + }
8680 +
8681 + if ( strlen(temp)<2 ) {
8682 + temp[0]='\0';
8683 + }
8684 + return temp;
8685 +
8686 + UNKNOWN_FMT_FIELD:
8687 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8688 + if ( strlen(temp)<2 ) {
8689 + temp[0]='\0';
8690 + }
8691 +
8692 + return temp;
8693 +}
8694 +
8695 +void pkg_print_info(pkg_t *pkg, FILE *file)
8696 +{
8697 + char * buff;
8698 + if (pkg == NULL) {
8699 + return;
8700 + }
8701 +
8702 + buff = pkg_formatted_info(pkg);
8703 + if ( buff == NULL )
8704 + return;
8705 + if (strlen(buff)>2){
8706 + fwrite(buff, 1, strlen(buff), file);
8707 + }
8708 + free(buff);
8709 +}
8710 +
8711 +void pkg_print_status(pkg_t * pkg, FILE * file)
8712 +{
8713 + if (pkg == NULL) {
8714 + return;
8715 + }
8716 +
8717 + /* XXX: QUESTION: Do we actually want more fields here? The
8718 + original idea was to save space by installing only what was
8719 + needed for actual computation, (package, version, status,
8720 + essential, conffiles). The assumption is that all other fields
8721 + can be found in th available file.
8722 +
8723 + But, someone proposed the idea to make it possible to
8724 + reconstruct a .ipk from an installed package, (ie. for beaming
8725 + from one handheld to another). So, maybe we actually want a few
8726 + more fields here, (depends, suggests, etc.), so that that would
8727 + be guaranteed to work even in the absence of more information
8728 + from the available file.
8729 +
8730 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8731 + the essential info needs to be here for all installed packages
8732 + because they may not appear in the Packages files on various
8733 + feeds. Furthermore, one should be able to install from URL or
8734 + local storage without requiring a Packages file from any feed.
8735 + -Jamey
8736 + */
8737 + pkg_print_field(pkg, file, "Package");
8738 + pkg_print_field(pkg, file, "Version");
8739 + pkg_print_field(pkg, file, "Depends");
8740 + pkg_print_field(pkg, file, "Recommends");
8741 + pkg_print_field(pkg, file, "Suggests");
8742 + pkg_print_field(pkg, file, "Provides");
8743 + pkg_print_field(pkg, file, "Replaces");
8744 + pkg_print_field(pkg, file, "Conflicts");
8745 + pkg_print_field(pkg, file, "Status");
8746 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8747 + pkg_print_field(pkg, file, "Architecture");
8748 + pkg_print_field(pkg, file, "Conffiles");
8749 + pkg_print_field(pkg, file, "Installed-Time");
8750 + fputs("\n", file);
8751 +}
8752 +
8753 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8754 +{
8755 + char *buff;
8756 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8757 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8758 + __FUNCTION__, field);
8759 + }
8760 + buff = pkg_formatted_field(pkg, field);
8761 + if (strlen(buff)>2) {
8762 + fprintf(file, "%s", buff);
8763 + fflush(file);
8764 + }
8765 + free(buff);
8766 + return;
8767 +}
8768 +
8769 +/*
8770 + * libdpkg - Debian packaging suite library routines
8771 + * vercmp.c - comparison of version numbers
8772 + *
8773 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8774 + */
8775 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8776 +{
8777 + int r;
8778 +
8779 + if (pkg->epoch > ref_pkg->epoch) {
8780 + return 1;
8781 + }
8782 +
8783 + if (pkg->epoch < ref_pkg->epoch) {
8784 + return -1;
8785 + }
8786 +
8787 + r = verrevcmp(pkg->version, ref_pkg->version);
8788 + if (r) {
8789 + return r;
8790 + }
8791 +
8792 +#ifdef USE_DEBVERSION
8793 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8794 + if (r) {
8795 + return r;
8796 + }
8797 +
8798 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8799 +#endif
8800 +
8801 + return r;
8802 +}
8803 +
8804 +int verrevcmp(const char *val, const char *ref)
8805 +{
8806 + int vc, rc;
8807 + long vl, rl;
8808 + const char *vp, *rp;
8809 + const char *vsep, *rsep;
8810 +
8811 + if (!val) val= "";
8812 + if (!ref) ref= "";
8813 + for (;;) {
8814 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8815 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8816 + for (;;) {
8817 + vc= (val == vp) ? 0 : *val++;
8818 + rc= (ref == rp) ? 0 : *ref++;
8819 + if (!rc && !vc) break;
8820 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8821 + if (rc && !isalpha(rc)) rc += 256;
8822 + if (vc != rc) return vc - rc;
8823 + }
8824 + val= vp;
8825 + ref= rp;
8826 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8827 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8828 + if (vl != rl) return vl - rl;
8829 +
8830 + vc = *val;
8831 + rc = *ref;
8832 + vsep = strchr(".-", vc);
8833 + rsep = strchr(".-", rc);
8834 + if (vsep && !rsep) return -1;
8835 + if (!vsep && rsep) return +1;
8836 +
8837 + if (!*val && !*ref) return 0;
8838 + if (!*val) return -1;
8839 + if (!*ref) return +1;
8840 + }
8841 +}
8842 +
8843 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8844 +{
8845 + int r;
8846 +
8847 + r = pkg_compare_versions(it, ref);
8848 +
8849 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8850 + return r <= 0;
8851 + }
8852 +
8853 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8854 + return r >= 0;
8855 + }
8856 +
8857 + if (strcmp(op, "<<") == 0) {
8858 + return r < 0;
8859 + }
8860 +
8861 + if (strcmp(op, ">>") == 0) {
8862 + return r > 0;
8863 + }
8864 +
8865 + if (strcmp(op, "=") == 0) {
8866 + return r == 0;
8867 + }
8868 +
8869 + fprintf(stderr, "unknown operator: %s", op);
8870 + return 0;
8871 +}
8872 +
8873 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8874 +{
8875 + const pkg_t *a = *(const pkg_t **)p1;
8876 + const pkg_t *b = *(const pkg_t **)p2;
8877 + int namecmp;
8878 + int vercmp;
8879 + if (!a->name || !b->name) {
8880 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8881 + a, a->name, b, b->name);
8882 + return 0;
8883 + }
8884 +
8885 + namecmp = strcmp(a->name, b->name);
8886 + if (namecmp)
8887 + return namecmp;
8888 + vercmp = pkg_compare_versions(a, b);
8889 + if (vercmp)
8890 + return vercmp;
8891 + if (!a->arch_priority || !b->arch_priority) {
8892 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8893 + a, a->arch_priority, b, b->arch_priority);
8894 + return 0;
8895 + }
8896 + if (a->arch_priority > b->arch_priority)
8897 + return 1;
8898 + if (a->arch_priority < b->arch_priority)
8899 + return -1;
8900 + return 0;
8901 +}
8902 +
8903 +int abstract_pkg_name_compare(void *p1, void *p2)
8904 +{
8905 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8906 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8907 + if (!a->name || !b->name) {
8908 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8909 + a, a->name, b, b->name);
8910 + return 0;
8911 + }
8912 + return strcmp(a->name, b->name);
8913 +}
8914 +
8915 +
8916 +char *pkg_version_str_alloc(pkg_t *pkg)
8917 +{
8918 + char *complete_version;
8919 + char *epoch_str;
8920 +#ifdef USE_DEBVERSION
8921 + char *revision_str;
8922 + char *familiar_revision_str;
8923 +#endif
8924 +
8925 + if (pkg->epoch) {
8926 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8927 + } else {
8928 + epoch_str = strdup("");
8929 + }
8930 +
8931 +#ifdef USE_DEBVERSION
8932 + if (pkg->revision && strlen(pkg->revision)) {
8933 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8934 + } else {
8935 + revision_str = strdup("");
8936 + }
8937 +
8938 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8939 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8940 + } else {
8941 + familiar_revision_str = strdup("");
8942 + }
8943 +#endif
8944 +
8945 +#ifdef USE_DEBVERSION
8946 + sprintf_alloc(&complete_version, "%s%s%s%s",
8947 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8948 +#else
8949 + sprintf_alloc(&complete_version, "%s%s",
8950 + epoch_str, pkg->version);
8951 +#endif
8952 +
8953 + free(epoch_str);
8954 +#ifdef USE_DEBVERSION
8955 + free(revision_str);
8956 + free(familiar_revision_str);
8957 +#endif
8958 +
8959 + return complete_version;
8960 +}
8961 +
8962 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8963 +{
8964 + int err;
8965 + char *list_file_name = NULL;
8966 + FILE *list_file = NULL;
8967 + char *line;
8968 + char *installed_file_name;
8969 + int rootdirlen;
8970 +
8971 + pkg->installed_files_ref_cnt++;
8972 +
8973 + if (pkg->installed_files) {
8974 + return pkg->installed_files;
8975 + }
8976 +
8977 + pkg->installed_files = str_list_alloc();
8978 + if (pkg->installed_files == NULL) {
8979 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8980 + return NULL;
8981 + }
8982 +
8983 + /* For uninstalled packages, get the file list firectly from the package.
8984 + For installed packages, look at the package.list file in the database.
8985 + */
8986 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8987 + if (pkg->local_filename == NULL) {
8988 + return pkg->installed_files;
8989 + }
8990 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8991 + file. In other words, change deb_extract so that it can
8992 + simply return the file list as a char *[] rather than
8993 + insisting on writing in to a FILE * as it does now. */
8994 + list_file = tmpfile();
8995 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8996 + if (err) {
8997 + fclose(list_file);
8998 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8999 + __FUNCTION__, pkg->local_filename, strerror(err));
9000 + return pkg->installed_files;
9001 + }
9002 + rewind(list_file);
9003 + } else {
9004 + sprintf_alloc(&list_file_name, "%s/%s.list",
9005 + pkg->dest->info_dir, pkg->name);
9006 + if (! file_exists(list_file_name)) {
9007 + free(list_file_name);
9008 + return pkg->installed_files;
9009 + }
9010 +
9011 + list_file = fopen(list_file_name, "r");
9012 + if (list_file == NULL) {
9013 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
9014 + list_file_name, strerror(errno));
9015 + free(list_file_name);
9016 + return pkg->installed_files;
9017 + }
9018 + free(list_file_name);
9019 + }
9020 +
9021 + rootdirlen = strlen( pkg->dest->root_dir );
9022 + while (1) {
9023 + char *file_name;
9024 +
9025 + line = file_read_line_alloc(list_file);
9026 + if (line == NULL) {
9027 + break;
9028 + }
9029 + str_chomp(line);
9030 + file_name = line;
9031 +
9032 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9033 + if( strncmp( pkg->dest->root_dir,
9034 + file_name,
9035 + rootdirlen ) ) {
9036 + if (*file_name == '.') {
9037 + file_name++;
9038 + }
9039 + if (*file_name == '/') {
9040 + file_name++;
9041 + }
9042 +
9043 + /* Freed in pkg_free_installed_files */
9044 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9045 + } else {
9046 + // already contains root_dir as header -> ABSOLUTE
9047 + sprintf_alloc(&installed_file_name, "%s", file_name);
9048 + }
9049 + str_list_append(pkg->installed_files, installed_file_name);
9050 + free(line);
9051 + }
9052 +
9053 + fclose(list_file);
9054 +
9055 + return pkg->installed_files;
9056 +}
9057 +
9058 +/* XXX: CLEANUP: This function and it's counterpart,
9059 + (pkg_get_installed_files), do not match our init/deinit naming
9060 + convention. Nor the alloc/free convention. But, then again, neither
9061 + of these conventions currrently fit the way these two functions
9062 + work. */
9063 +int pkg_free_installed_files(pkg_t *pkg)
9064 +{
9065 + str_list_elt_t *iter;
9066 +
9067 + pkg->installed_files_ref_cnt--;
9068 + if (pkg->installed_files_ref_cnt > 0) {
9069 + return 0;
9070 + }
9071 +
9072 + if (pkg->installed_files) {
9073 +
9074 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9075 + /* malloced in pkg_get_installed_files */
9076 + free (iter->data);
9077 + iter->data = NULL;
9078 + }
9079 +
9080 + str_list_deinit(pkg->installed_files);
9081 + }
9082 +
9083 + pkg->installed_files = NULL;
9084 +
9085 + return 0;
9086 +}
9087 +
9088 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9089 +{
9090 + int err;
9091 + char *list_file_name;
9092 +
9093 + //I don't think pkg_free_installed_files should be called here. Jamey
9094 + //pkg_free_installed_files(pkg);
9095 +
9096 + sprintf_alloc(&list_file_name, "%s/%s.list",
9097 + pkg->dest->info_dir, pkg->name);
9098 + if (!conf->noaction) {
9099 + err = unlink(list_file_name);
9100 + free(list_file_name);
9101 +
9102 + if (err) {
9103 + return errno;
9104 + }
9105 + }
9106 + return 0;
9107 +}
9108 +
9109 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9110 +{
9111 + conffile_list_elt_t *iter;
9112 + conffile_t *conffile;
9113 +
9114 + if (pkg == NULL) {
9115 + return NULL;
9116 + }
9117 +
9118 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9119 + conffile = iter->data;
9120 +
9121 + if (strcmp(conffile->name, file_name) == 0) {
9122 + return conffile;
9123 + }
9124 + }
9125 +
9126 + return NULL;
9127 +}
9128 +
9129 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9130 + const char *script, const char *args)
9131 +{
9132 + int err;
9133 + char *path;
9134 + char *cmd;
9135 +
9136 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9137 + maintainer script within a chroot environment. */
9138 +
9139 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9140 + have scripts in pkg->tmp_unpack_dir. */
9141 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9142 + if (pkg->dest == NULL) {
9143 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9144 + __FUNCTION__, pkg->name);
9145 + return EINVAL;
9146 + }
9147 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9148 + } else {
9149 + if (pkg->tmp_unpack_dir == NULL) {
9150 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9151 + __FUNCTION__, pkg->name);
9152 + return EINVAL;
9153 + }
9154 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9155 + }
9156 +
9157 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9158 + if (conf->noaction) return 0;
9159 +
9160 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9161 + scripts when running with offline_root mode and/or a dest other
9162 + than '/'. I've been playing around with some clever chroot
9163 + tricks and I might come up with something workable. */
9164 + if (conf->offline_root) {
9165 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9166 + }
9167 +
9168 + setenv("PKG_ROOT",
9169 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9170 +
9171 + if (! file_exists(path)) {
9172 + free(path);
9173 + return 0;
9174 + }
9175 +
9176 + if (conf->offline_root) {
9177 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9178 + free(path);
9179 + return 0;
9180 + }
9181 +
9182 + sprintf_alloc(&cmd, "%s %s", path, args);
9183 + free(path);
9184 +
9185 + err = xsystem(cmd);
9186 + free(cmd);
9187 +
9188 + if (err) {
9189 + fprintf(stderr, "%s script returned status %d\n", script, err);
9190 + return err;
9191 + }
9192 +
9193 + return 0;
9194 +}
9195 +
9196 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9197 +{
9198 + int i;
9199 +
9200 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9201 + if (pkg_state_want_map[i].value == sw) {
9202 + return strdup(pkg_state_want_map[i].str);
9203 + }
9204 + }
9205 +
9206 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9207 + __FUNCTION__, sw);
9208 + return strdup("<STATE_WANT_UNKNOWN>");
9209 +}
9210 +
9211 +pkg_state_want_t pkg_state_want_from_str(char *str)
9212 +{
9213 + int i;
9214 +
9215 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9216 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9217 + return pkg_state_want_map[i].value;
9218 + }
9219 + }
9220 +
9221 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9222 + __FUNCTION__, str);
9223 + return SW_UNKNOWN;
9224 +}
9225 +
9226 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9227 +{
9228 + int i;
9229 + int len = 3; /* ok\000 is minimum */
9230 + char *str = NULL;
9231 +
9232 + /* clear the temporary flags before converting to string */
9233 + sf &= SF_NONVOLATILE_FLAGS;
9234 +
9235 + if (sf == 0) {
9236 + return strdup("ok");
9237 + } else {
9238 +
9239 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9240 + if (sf & pkg_state_flag_map[i].value) {
9241 + len += strlen(pkg_state_flag_map[i].str) + 1;
9242 + }
9243 + }
9244 + str = malloc(len);
9245 + if ( str == NULL ) {
9246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9247 + return NULL;
9248 + }
9249 + str[0] = 0;
9250 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9251 + if (sf & pkg_state_flag_map[i].value) {
9252 + strcat(str, pkg_state_flag_map[i].str);
9253 + strcat(str, ",");
9254 + }
9255 + }
9256 + len = strlen(str);
9257 + str[len-1] = 0; /* squash last comma */
9258 + return str;
9259 + }
9260 +}
9261 +
9262 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9263 +{
9264 + int i;
9265 + int sf = SF_OK;
9266 +
9267 + if (strcmp(str, "ok") == 0) {
9268 + return SF_OK;
9269 + }
9270 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9271 + const char *sfname = pkg_state_flag_map[i].str;
9272 + int sfname_len = strlen(sfname);
9273 + if (strncmp(str, sfname, sfname_len) == 0) {
9274 + sf |= pkg_state_flag_map[i].value;
9275 + str += sfname_len;
9276 + if (str[0] == ',') {
9277 + str++;
9278 + } else {
9279 + break;
9280 + }
9281 + }
9282 + }
9283 +
9284 + return sf;
9285 +}
9286 +
9287 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9288 +{
9289 + int i;
9290 +
9291 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9292 + if (pkg_state_status_map[i].value == ss) {
9293 + return strdup(pkg_state_status_map[i].str);
9294 + }
9295 + }
9296 +
9297 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9298 + __FUNCTION__, ss);
9299 + return strdup("<STATE_STATUS_UNKNOWN>");
9300 +}
9301 +
9302 +pkg_state_status_t pkg_state_status_from_str(char *str)
9303 +{
9304 + int i;
9305 +
9306 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9307 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9308 + return pkg_state_status_map[i].value;
9309 + }
9310 + }
9311 +
9312 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9313 + __FUNCTION__, str);
9314 + return SS_NOT_INSTALLED;
9315 +}
9316 +
9317 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9318 +{
9319 + nv_pair_list_elt_t *l;
9320 +
9321 + if (!pkg->architecture)
9322 + return 1;
9323 +
9324 + l = conf->arch_list.head;
9325 +
9326 + while (l) {
9327 + nv_pair_t *nv = l->data;
9328 + if (strcmp(nv->name, pkg->architecture) == 0) {
9329 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9330 + return 1;
9331 + }
9332 + l = l->next;
9333 + }
9334 +
9335 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9336 + return 0;
9337 +}
9338 +
9339 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9340 +{
9341 + nv_pair_list_elt_t *l;
9342 +
9343 + l = conf->arch_list.head;
9344 +
9345 + while (l) {
9346 + nv_pair_t *nv = l->data;
9347 + if (strcmp(nv->name, archname) == 0) {
9348 + int priority = strtol(nv->value, NULL, 0);
9349 + return priority;
9350 + }
9351 + l = l->next;
9352 + }
9353 + return 0;
9354 +}
9355 +
9356 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9357 +{
9358 + int i;
9359 + hash_table_t *pkg_hash = &conf->pkg_hash;
9360 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9361 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9362 +
9363 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9364 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9365 + /* update arch_priority for each package */
9366 + for (i = 0; i < available_pkgs->len; i++) {
9367 + pkg_t *pkg = available_pkgs->pkgs[i];
9368 + int arch_priority = 1;
9369 + if (!pkg)
9370 + continue;
9371 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9372 + if (pkg->architecture)
9373 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9374 + else
9375 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9376 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9377 + pkg->arch_priority = arch_priority;
9378 + }
9379 +
9380 + for (i = 0; i < available_pkgs->len; i++) {
9381 + pkg_t *pkg = available_pkgs->pkgs[i];
9382 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9383 + /* clear flags and want for any uninstallable package */
9384 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9385 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9386 + pkg->state_want = SW_UNKNOWN;
9387 + pkg->state_flag = 0;
9388 + }
9389 + }
9390 + pkg_vec_free(available_pkgs);
9391 +
9392 + /* update the file owner data structure */
9393 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9394 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9395 + for (i = 0; i < installed_pkgs->len; i++) {
9396 + pkg_t *pkg = installed_pkgs->pkgs[i];
9397 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9398 + str_list_elt_t *iter;
9399 + if (installed_files == NULL) {
9400 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9401 + break;
9402 + }
9403 + for (iter = installed_files->head; iter; iter = iter->next) {
9404 + char *installed_file = iter->data;
9405 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9406 + file_hash_set_file_owner(conf, installed_file, pkg);
9407 + }
9408 + }
9409 + pkg_vec_free(installed_pkgs);
9410 +
9411 + return 0;
9412 +}
9413 +
9414 +struct pkg_write_filelist_data {
9415 + ipkg_conf_t *conf;
9416 + pkg_t *pkg;
9417 + FILE *stream;
9418 +};
9419 +
9420 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9421 +{
9422 + struct pkg_write_filelist_data *data = data_;
9423 + pkg_t *entry = entry_;
9424 + if (entry == data->pkg) {
9425 + fprintf(data->stream, "%s\n", key);
9426 + }
9427 +}
9428 +
9429 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9430 +{
9431 + struct pkg_write_filelist_data data;
9432 + char *list_file_name = NULL;
9433 + int err = 0;
9434 +
9435 + if (!pkg) {
9436 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9437 + return -EINVAL;
9438 + }
9439 + ipkg_message(conf, IPKG_INFO,
9440 + " creating %s.list file\n", pkg->name);
9441 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9442 + if (!list_file_name) {
9443 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9444 + return -ENOMEM;
9445 + }
9446 + ipkg_message(conf, IPKG_INFO,
9447 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9448 + data.stream = fopen(list_file_name, "w");
9449 + if (!data.stream) {
9450 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9451 + list_file_name, strerror(errno));
9452 + return errno;
9453 + }
9454 + data.pkg = pkg;
9455 + data.conf = conf;
9456 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9457 + fclose(data.stream);
9458 + free(list_file_name);
9459 +
9460 + return err;
9461 +}
9462 +
9463 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9464 +{
9465 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9466 + hash_table_t *pkg_hash = &conf->pkg_hash;
9467 + int i;
9468 + int err;
9469 + if (conf->noaction)
9470 + return 0;
9471 +
9472 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9473 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9474 + for (i = 0; i < installed_pkgs->len; i++) {
9475 + pkg_t *pkg = installed_pkgs->pkgs[i];
9476 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9477 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9478 + err = pkg_write_filelist(conf, pkg);
9479 + if (err)
9480 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9481 + }
9482 + }
9483 + return 0;
9484 +}
9485 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.h
9486 --- busybox-1.1.2-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9487 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.h 2006-05-09 02:12:05.000000000 +0200
9488 @@ -0,0 +1,232 @@
9489 +/* pkg.h - the itsy package management system
9490 +
9491 + Carl D. Worth
9492 +
9493 + Copyright (C) 2001 University of Southern California
9494 +
9495 + This program is free software; you can redistribute it and/or
9496 + modify it under the terms of the GNU General Public License as
9497 + published by the Free Software Foundation; either version 2, or (at
9498 + your option) any later version.
9499 +
9500 + This program is distributed in the hope that it will be useful, but
9501 + WITHOUT ANY WARRANTY; without even the implied warranty of
9502 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9503 + General Public License for more details.
9504 +*/
9505 +
9506 +#ifndef PKG_H
9507 +#define PKG_H
9508 +
9509 +#include <sys/types.h>
9510 +#include <sys/stat.h>
9511 +#include <unistd.h>
9512 +
9513 +#include "pkg_vec.h"
9514 +#include "str_list.h"
9515 +#include "pkg_src.h"
9516 +#include "pkg_dest.h"
9517 +#include "ipkg_conf.h"
9518 +#include "conffile_list.h"
9519 +
9520 +struct ipkg_conf;
9521 +
9522 +
9523 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9524 +
9525 +/* I think "Size" is currently the shortest field name */
9526 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9527 +
9528 +enum pkg_state_want
9529 +{
9530 + SW_UNKNOWN = 1,
9531 + SW_INSTALL,
9532 + SW_DEINSTALL,
9533 + SW_PURGE,
9534 + SW_LAST_STATE_WANT
9535 +};
9536 +typedef enum pkg_state_want pkg_state_want_t;
9537 +
9538 +enum pkg_state_flag
9539 +{
9540 + SF_OK = 0,
9541 + SF_REINSTREQ = 1,
9542 + SF_HOLD = 2, /* do not upgrade version */
9543 + SF_REPLACE = 4, /* replace this package */
9544 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9545 + SF_PREFER = 16, /* prefer this version */
9546 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9547 + SF_MARKED = 64, /* temporary mark */
9548 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9549 + SF_USER = 256,
9550 + SF_LAST_STATE_FLAG
9551 +};
9552 +typedef enum pkg_state_flag pkg_state_flag_t;
9553 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9554 +
9555 +enum pkg_state_status
9556 +{
9557 + SS_NOT_INSTALLED = 1,
9558 + SS_UNPACKED,
9559 + SS_HALF_CONFIGURED,
9560 + SS_INSTALLED,
9561 + SS_HALF_INSTALLED,
9562 + SS_CONFIG_FILES,
9563 + SS_POST_INST_FAILED,
9564 + SS_REMOVAL_FAILED,
9565 + SS_LAST_STATE_STATUS
9566 +};
9567 +typedef enum pkg_state_status pkg_state_status_t;
9568 +
9569 +struct abstract_pkg{
9570 + char * name;
9571 + int dependencies_checked;
9572 + pkg_vec_t * pkgs;
9573 + pkg_state_status_t state_status;
9574 + pkg_state_flag_t state_flag;
9575 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9576 + abstract_pkg_vec_t * provided_by;
9577 + abstract_pkg_vec_t * replaced_by;
9578 +};
9579 +
9580 +#include "pkg_depends.h"
9581 +
9582 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9583 +
9584 + The 3 version fields should go into a single version struct. (This
9585 + is especially important since, currently, pkg->version can easily
9586 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9587 + distinct. This has been the source of multiple bugs.
9588 +
9589 + The 3 state fields could possibly also go into their own struct.
9590 +
9591 + All fields which deal with lists of packages, (Depends,
9592 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9593 + be handled by a single struct in pkg_t
9594 +
9595 + All string fields for which there is a small set of possible
9596 + values, (section, maintainer, architecture, maybe version?), that
9597 + are reused among different packages -- for all such packages we
9598 + should move from "char *"s to some atom datatype to share data
9599 + storage and use less memory. We might even do reference counting,
9600 + but probably not since most often we only create new pkg_t structs,
9601 + we don't often free them. */
9602 +struct pkg
9603 +{
9604 + char *name;
9605 + unsigned long epoch;
9606 + char *version;
9607 + char *revision;
9608 + char *familiar_revision;
9609 + pkg_src_t *src;
9610 + pkg_dest_t *dest;
9611 + char *architecture;
9612 + char *section;
9613 + char *maintainer;
9614 + char *description;
9615 + pkg_state_want_t state_want;
9616 + pkg_state_flag_t state_flag;
9617 + pkg_state_status_t state_status;
9618 + char **depends_str;
9619 + int depends_count;
9620 + char **pre_depends_str;
9621 + int pre_depends_count;
9622 + char **recommends_str;
9623 + int recommends_count;
9624 + char **suggests_str;
9625 + int suggests_count;
9626 + compound_depend_t * depends;
9627 +
9628 + /* Abhaya: new conflicts */
9629 + char **conflicts_str;
9630 + compound_depend_t * conflicts;
9631 + int conflicts_count;
9632 +
9633 + char **replaces_str;
9634 + int replaces_count;
9635 + abstract_pkg_t ** replaces;
9636 +
9637 + char **provides_str;
9638 + int provides_count;
9639 + abstract_pkg_t ** provides;
9640 +
9641 + abstract_pkg_t *parent;
9642 +
9643 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9644 +
9645 + char *filename;
9646 + char *local_filename;
9647 + char *url;
9648 + char *tmp_unpack_dir;
9649 + char *md5sum;
9650 + char *size;
9651 + char *installed_size;
9652 + char *priority;
9653 + char *source;
9654 + conffile_list_t conffiles;
9655 + time_t installed_time;
9656 + /* As pointer for lazy evaluation */
9657 + str_list_t *installed_files;
9658 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9659 + mechanism to avoid the problem here, (which is that the
9660 + installed_files list was being freed from an inner loop while
9661 + still being used within an outer loop. */
9662 + int installed_files_ref_cnt;
9663 + int essential;
9664 + int arch_priority;
9665 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
9666 + int provided_by_hand;
9667 +};
9668 +
9669 +pkg_t *pkg_new(void);
9670 +int pkg_init(pkg_t *pkg);
9671 +void pkg_deinit(pkg_t *pkg);
9672 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9673 +abstract_pkg_t *abstract_pkg_new(void);
9674 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9675 +
9676 +/*
9677 + * merges fields from newpkg into oldpkg.
9678 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9679 + */
9680 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9681 +
9682 +char *pkg_version_str_alloc(pkg_t *pkg);
9683 +
9684 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9685 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9686 +int abstract_pkg_name_compare(void *a, void *b);
9687 +
9688 +char * pkg_formatted_info(pkg_t *pkg );
9689 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9690 +
9691 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9692 +
9693 +void pkg_print_info(pkg_t *pkg, FILE *file);
9694 +void pkg_print_status(pkg_t * pkg, FILE * file);
9695 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9696 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9697 +int pkg_free_installed_files(pkg_t *pkg);
9698 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9699 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9700 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9701 + const char *script, const char *args);
9702 +
9703 +/* enum mappings */
9704 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9705 +pkg_state_want_t pkg_state_want_from_str(char *str);
9706 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9707 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9708 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9709 +pkg_state_status_t pkg_state_status_from_str(char *str);
9710 +
9711 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9712 +
9713 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9714 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9715 +int pkg_free_installed_files(pkg_t *pkg);
9716 +
9717 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9718 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9719 +
9720 +#endif
9721 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_depends.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.c
9722 --- busybox-1.1.2-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9723 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-05-09 02:12:05.000000000 +0200
9724 @@ -0,0 +1,1033 @@
9725 +/* pkg_depends.c - the itsy package management system
9726 +
9727 + Steven M. Ayer
9728 +
9729 + Copyright (C) 2002 Compaq Computer Corporation
9730 +
9731 + This program is free software; you can redistribute it and/or
9732 + modify it under the terms of the GNU General Public License as
9733 + published by the Free Software Foundation; either version 2, or (at
9734 + your option) any later version.
9735 +
9736 + This program is distributed in the hope that it will be useful, but
9737 + WITHOUT ANY WARRANTY; without even the implied warranty of
9738 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9739 + General Public License for more details.
9740 +*/
9741 +
9742 +#include "ipkg.h"
9743 +#include <errno.h>
9744 +#include <ctype.h>
9745 +
9746 +#include "pkg.h"
9747 +#include "ipkg_utils.h"
9748 +#include "pkg_hash.h"
9749 +#include "ipkg_message.h"
9750 +#include "pkg_parse.h"
9751 +#include "hash_table.h"
9752 +
9753 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9754 +static depend_t * depend_init(void);
9755 +static void depend_deinit(depend_t *d);
9756 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9757 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9758 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9759 +
9760 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9761 +{
9762 + depend_t *depend = (depend_t *)cdata;
9763 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9764 + return 1;
9765 + else
9766 + return 0;
9767 +}
9768 +
9769 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9770 +{
9771 + depend_t *depend = (depend_t *)cdata;
9772 +#if 0
9773 + pkg_t * temp = pkg_new();
9774 + int comparison;
9775 + parseVersion(temp, depend->version);
9776 + comparison = pkg_compare_versions(pkg, temp);
9777 + free(temp);
9778 +
9779 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9780 + __FUNCTION__, pkg->name, pkg->version,
9781 + depend, depend->constraint, depend->version,
9782 + comparison, version_constraints_satisfied(depend, pkg));
9783 +#endif
9784 + if (version_constraints_satisfied(depend, pkg))
9785 + return 1;
9786 + else
9787 + return 0;
9788 +}
9789 +
9790 +/* returns ndependences or negative error value */
9791 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9792 + pkg_vec_t *unsatisfied, char *** unresolved)
9793 +{
9794 + pkg_t * satisfier_entry_pkg;
9795 + register int i, j, k;
9796 + int count, found;
9797 + char ** the_lost;
9798 + abstract_pkg_t * ab_pkg;
9799 +
9800 + /*
9801 + * this is a setup to check for redundant/cyclic dependency checks,
9802 + * which are marked at the abstract_pkg level
9803 + */
9804 + if (!(ab_pkg = pkg->parent)) {
9805 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9806 + *unresolved = NULL;
9807 + return 0;
9808 + }
9809 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9810 + *unresolved = NULL;
9811 + return 0;
9812 + } else {
9813 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9814 + }
9815 + /**/
9816 +
9817 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9818 + if (!count){
9819 + *unresolved = NULL;
9820 + return 0;
9821 + }
9822 +
9823 + the_lost = NULL;
9824 +
9825 + /* foreach dependency */
9826 + for (i = 0; i < count; i++) {
9827 + compound_depend_t * compound_depend = &pkg->depends[i];
9828 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9829 + found = 0;
9830 + satisfier_entry_pkg = NULL;
9831 +
9832 + if (compound_depend->type == GREEDY_DEPEND) {
9833 + /* foreach possible satisfier */
9834 + for (j = 0; j < compound_depend->possibility_count; j++) {
9835 + /* foreach provided_by, which includes the abstract_pkg itself */
9836 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9837 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9838 + int nposs = ab_provider_vec->len;
9839 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9840 + int l;
9841 + for (l = 0; l < nposs; l++) {
9842 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9843 + /* if no depends on this one, try the first package that Provides this one */
9844 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9845 + continue;
9846 + }
9847 +
9848 + /* cruise this possiblity's pkg_vec looking for an installed version */
9849 + for (k = 0; k < test_vec->len; k++) {
9850 + pkg_t *pkg_scout = test_vec->pkgs[k];
9851 + /* not installed, and not already known about? */
9852 + if ((pkg_scout->state_want != SW_INSTALL)
9853 + && !pkg_scout->parent->dependencies_checked
9854 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9855 + char ** newstuff = NULL;
9856 + int rc;
9857 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9858 + /* check for not-already-installed dependencies */
9859 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9860 + pkg_scout,
9861 + tmp_vec,
9862 + &newstuff);
9863 + if (newstuff == NULL) {
9864 + int i;
9865 + int ok = 1;
9866 + for (i = 0; i < rc; i++) {
9867 + pkg_t *p = tmp_vec->pkgs[i];
9868 + if (p->state_want == SW_INSTALL)
9869 + continue;
9870 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9871 + ok = 0;
9872 + break;
9873 + }
9874 + pkg_vec_free (tmp_vec);
9875 + if (ok) {
9876 + /* mark this one for installation */
9877 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9878 + pkg_vec_insert(unsatisfied, pkg_scout);
9879 + }
9880 + } else {
9881 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9882 + free (newstuff);
9883 + }
9884 + }
9885 + }
9886 + }
9887 + }
9888 +
9889 + continue;
9890 + }
9891 +
9892 + /* foreach possible satisfier, look for installed package */
9893 + for (j = 0; j < compound_depend->possibility_count; j++) {
9894 + /* foreach provided_by, which includes the abstract_pkg itself */
9895 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9896 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9897 + pkg_t *satisfying_pkg =
9898 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9899 + pkg_installed_and_constraint_satisfied,
9900 + dependence_to_satisfy, 1);
9901 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9902 + if (satisfying_pkg != NULL) {
9903 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9904 + satisfying_pkg = NULL;
9905 + }
9906 + }
9907 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9908 + if (satisfying_pkg != NULL) {
9909 + found = 1;
9910 + break;
9911 + }
9912 +
9913 + }
9914 + /* if nothing installed matches, then look for uninstalled satisfier */
9915 + if (!found) {
9916 + /* foreach possible satisfier, look for installed package */
9917 + for (j = 0; j < compound_depend->possibility_count; j++) {
9918 + /* foreach provided_by, which includes the abstract_pkg itself */
9919 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9920 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9921 + pkg_t *satisfying_pkg =
9922 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9923 + pkg_constraint_satisfied,
9924 + dependence_to_satisfy, 1);
9925 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9926 + if (satisfying_pkg != NULL) {
9927 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9928 + satisfying_pkg = NULL;
9929 + }
9930 + }
9931 +
9932 + /* user request overrides package recommendation */
9933 + if (satisfying_pkg != NULL
9934 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9935 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9936 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9937 + pkg->name, satisfying_pkg->name);
9938 + continue;
9939 + }
9940 +
9941 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9942 + if (satisfying_pkg != NULL) {
9943 + satisfier_entry_pkg = satisfying_pkg;
9944 + break;
9945 + }
9946 + }
9947 + }
9948 +
9949 + /* we didn't find one, add something to the unsatisfied vector */
9950 + if (!found) {
9951 + if (!satisfier_entry_pkg) {
9952 + /* failure to meet recommendations is not an error */
9953 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9954 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9955 + else
9956 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9957 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9958 + }
9959 + else {
9960 + if (compound_depend->type == SUGGEST) {
9961 + /* just mention it politely */
9962 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9963 + pkg->name, satisfier_entry_pkg->name);
9964 + } else {
9965 + char ** newstuff = NULL;
9966 +
9967 + if (satisfier_entry_pkg != pkg &&
9968 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9969 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9970 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9971 + satisfier_entry_pkg,
9972 + unsatisfied,
9973 + &newstuff);
9974 + the_lost = merge_unresolved(the_lost, newstuff);
9975 + }
9976 + }
9977 + }
9978 + }
9979 + }
9980 + *unresolved = the_lost;
9981 +
9982 + return unsatisfied->len;
9983 +}
9984 +
9985 +/*checking for conflicts !in replaces
9986 + If a packages conflicts with another but is also replacing it, I should not consider it a
9987 + really conflicts
9988 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9989 +*/
9990 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9991 +{
9992 + int i ;
9993 + int replaces_count = pkg->replaces_count;
9994 + abstract_pkg_t **replaces;
9995 +
9996 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9997 + return 0;
9998 +
9999 + replaces = pkg->replaces;
10000 +
10001 + for (i = 0; i < replaces_count; i++) {
10002 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
10003 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
10004 + return 1;
10005 + }
10006 + }
10007 + return 0;
10008 +
10009 +}
10010 +
10011 +
10012 +/* Abhaya: added support for conflicts */
10013 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
10014 +{
10015 + pkg_vec_t * installed_conflicts, * test_vec;
10016 + compound_depend_t * conflicts;
10017 + depend_t ** possible_satisfiers;
10018 + depend_t * possible_satisfier;
10019 + register int i, j, k;
10020 + int count;
10021 + abstract_pkg_t * ab_pkg;
10022 + pkg_t **pkg_scouts;
10023 + pkg_t *pkg_scout;
10024 +
10025 + /*
10026 + * this is a setup to check for redundant/cyclic dependency checks,
10027 + * which are marked at the abstract_pkg level
10028 + */
10029 + if(!(ab_pkg = pkg->parent)){
10030 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
10031 + return (pkg_vec_t *)NULL;
10032 + }
10033 +
10034 + conflicts = pkg->conflicts;
10035 + if(!conflicts){
10036 + return (pkg_vec_t *)NULL;
10037 + }
10038 + installed_conflicts = pkg_vec_alloc();
10039 +
10040 + count = pkg->conflicts_count;
10041 +
10042 +
10043 +
10044 + /* foreach conflict */
10045 + for(i = 0; i < pkg->conflicts_count; i++){
10046 +
10047 + possible_satisfiers = conflicts->possibilities;
10048 +
10049 + /* foreach possible satisfier */
10050 + for(j = 0; j < conflicts->possibility_count; j++){
10051 + possible_satisfier = possible_satisfiers[j];
10052 + if (!possible_satisfier)
10053 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
10054 + if (!possible_satisfier->pkg)
10055 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
10056 + test_vec = possible_satisfier->pkg->pkgs;
10057 + if (test_vec) {
10058 + /* pkg_vec found, it is an actual package conflict
10059 + * cruise this possiblity's pkg_vec looking for an installed version */
10060 + pkg_scouts = test_vec->pkgs;
10061 + for(k = 0; k < test_vec->len; k++){
10062 + pkg_scout = pkg_scouts[k];
10063 + if (!pkg_scout) {
10064 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
10065 + continue;
10066 + }
10067 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
10068 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
10069 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
10070 + pkg_vec_insert(installed_conflicts, pkg_scout);
10071 + }
10072 + }
10073 + }
10074 + }
10075 + }
10076 + conflicts++;
10077 + }
10078 +
10079 + if (installed_conflicts->len)
10080 + return installed_conflicts;
10081 + pkg_vec_free(installed_conflicts);
10082 + return (pkg_vec_t *)NULL;
10083 +}
10084 +
10085 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
10086 +{
10087 + pkg_t * temp;
10088 + int comparison;
10089 +
10090 + if(depends->constraint == NONE)
10091 + return 1;
10092 +
10093 + temp = pkg_new();
10094 +
10095 + parseVersion(temp, depends->version);
10096 +
10097 + comparison = pkg_compare_versions(pkg, temp);
10098 +
10099 + free(temp);
10100 +
10101 + if((depends->constraint == EARLIER) &&
10102 + (comparison < 0))
10103 + return 1;
10104 + else if((depends->constraint == LATER) &&
10105 + (comparison > 0))
10106 + return 1;
10107 + else if(comparison == 0)
10108 + return 1;
10109 + else if((depends->constraint == LATER_EQUAL) &&
10110 + (comparison >= 0))
10111 + return 1;
10112 + else if((depends->constraint == EARLIER_EQUAL) &&
10113 + (comparison <= 0))
10114 + return 1;
10115 +
10116 + return 0;
10117 +}
10118 +
10119 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
10120 +{
10121 + abstract_pkg_t *apkg = depend->pkg;
10122 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
10123 + int n_providers = provider_apkgs->len;
10124 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
10125 + pkg_vec_t *pkg_vec;
10126 + int n_pkgs ;
10127 + int i;
10128 + int j;
10129 +
10130 + for (i = 0; i < n_providers; i++) {
10131 + abstract_pkg_t *papkg = apkgs[i];
10132 + pkg_vec = papkg->pkgs;
10133 + if (pkg_vec) {
10134 + n_pkgs = pkg_vec->len;
10135 + for (j = 0; j < n_pkgs; j++) {
10136 + pkg_t *pkg = pkg_vec->pkgs[j];
10137 + if (version_constraints_satisfied(depend, pkg)) {
10138 + return 1;
10139 + }
10140 + }
10141 + }
10142 + }
10143 + return 0;
10144 +}
10145 +
10146 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
10147 +{
10148 + abstract_pkg_t *apkg = depend->pkg;
10149 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
10150 + int n_providers = provider_apkgs->len;
10151 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
10152 + int i;
10153 + int n_pkgs;
10154 + int j;
10155 +
10156 + for (i = 0; i < n_providers; i++) {
10157 + abstract_pkg_t *papkg = apkgs[i];
10158 + pkg_vec_t *pkg_vec = papkg->pkgs;
10159 + if (pkg_vec) {
10160 + n_pkgs = pkg_vec->len;
10161 + for (j = 0; j < n_pkgs; j++) {
10162 + pkg_t *pkg = pkg_vec->pkgs[j];
10163 + if (version_constraints_satisfied(depend, pkg)) {
10164 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
10165 + return 1;
10166 + }
10167 + }
10168 + }
10169 + }
10170 + return 0;
10171 +}
10172 +
10173 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
10174 +{
10175 + register int i;
10176 + pkg_t ** pkgs = vec->pkgs;
10177 +
10178 + for(i = 0; i < vec->len; i++)
10179 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
10180 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
10181 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
10182 + return 1;
10183 + return 0;
10184 +}
10185 +
10186 +
10187 +#ifdef DeadCode
10188 +/**
10189 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10190 + * the same abstract package and 0 otherwise.
10191 + */
10192 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
10193 +{
10194 + abstract_pkg_t **provides = pkg->provides;
10195 + int provides_count = pkg->provides_count;
10196 + abstract_pkg_t **replacee_provides = replacee->provides;
10197 + int replacee_provides_count = replacee->provides_count;
10198 + int i, j;
10199 + for (i = 0; i < provides_count; i++) {
10200 + abstract_pkg_t *apkg = provides[i];
10201 + for (j = 0; j < replacee_provides_count; j++) {
10202 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
10203 + if (apkg == replacee_apkg)
10204 + return 1;
10205 + }
10206 + }
10207 + return 0;
10208 +}
10209 +#endif
10210 +
10211 +/**
10212 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
10213 + * and 0 otherwise.
10214 + */
10215 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
10216 +{
10217 + abstract_pkg_t **provides = pkg->provides;
10218 + int provides_count = pkg->provides_count;
10219 + int i;
10220 + for (i = 0; i < provides_count; i++) {
10221 + if (provides[i] == providee)
10222 + return 1;
10223 + }
10224 + return 0;
10225 +}
10226 +
10227 +/**
10228 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10229 + * otherwise.
10230 + */
10231 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
10232 +{
10233 + abstract_pkg_t **replaces = pkg->replaces;
10234 + int replaces_count = pkg->replaces_count;
10235 + /* abstract_pkg_t **replacee_provides = pkg->provides;
10236 + int replacee_provides_count = pkg->provides_count; */
10237 + int i, j;
10238 + for (i = 0; i < replaces_count; i++) {
10239 + abstract_pkg_t *abstract_replacee = replaces[i];
10240 + for (j = 0; j < replaces_count; j++) {
10241 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
10242 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
10243 + if (replacee->provides[j] == abstract_replacee)
10244 + return 1;
10245 + }
10246 + }
10247 + return 0;
10248 +}
10249 +
10250 +
10251 +/**
10252 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10253 + * otherwise.
10254 + */
10255 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10256 +{
10257 + compound_depend_t *conflicts = pkg->conflicts;
10258 + int conflicts_count = pkg->conflicts_count;
10259 + int i, j;
10260 + for (i = 0; i < conflicts_count; i++) {
10261 + int possibility_count = conflicts[i].possibility_count;
10262 + struct depend **possibilities = conflicts[i].possibilities;
10263 + for (j = 0; j < possibility_count; j++) {
10264 + if (possibilities[j]->pkg == conflictee) {
10265 + return 1;
10266 + }
10267 + }
10268 + }
10269 + return 0;
10270 +}
10271 +
10272 +/**
10273 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10274 + * conflictee's provides and 0 otherwise.
10275 + */
10276 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10277 +{
10278 + compound_depend_t *conflicts = pkg->conflicts;
10279 + int conflicts_count = pkg->conflicts_count;
10280 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10281 + int conflictee_provides_count = conflictee->provides_count;
10282 + int i, j, k;
10283 + int possibility_count;
10284 + struct depend **possibilities;
10285 + abstract_pkg_t *possibility ;
10286 +
10287 + for (i = 0; i < conflicts_count; i++) {
10288 + possibility_count = conflicts[i].possibility_count;
10289 + possibilities = conflicts[i].possibilities;
10290 + for (j = 0; j < possibility_count; j++) {
10291 + possibility = possibilities[j]->pkg;
10292 + for (k = 0; k < conflictee_provides_count; k++) {
10293 + if (possibility == conflictee_provides[k]) {
10294 + return 1;
10295 + }
10296 + }
10297 + }
10298 + }
10299 + return 0;
10300 +}
10301 +
10302 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10303 +{
10304 + int oldlen = 0, newlen = 0;
10305 + char ** result;
10306 + register int i, j;
10307 +
10308 + if(!newstuff)
10309 + return oldstuff;
10310 +
10311 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10312 + while(newstuff && newstuff[newlen]) newlen++;
10313 +
10314 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10315 + if (result == NULL) {
10316 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10317 + return NULL;
10318 + }
10319 +
10320 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10321 + *(result + i) = *(newstuff + j);
10322 +
10323 + *(result + i) = NULL;
10324 +
10325 + return result;
10326 +}
10327 +
10328 +/*
10329 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10330 + * this is null terminated, no count is carried around
10331 + */
10332 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10333 +{
10334 + int count;
10335 + char ** resized;
10336 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10337 +
10338 + count = 0;
10339 + while(the_lost && the_lost[count]) count++;
10340 +
10341 + count++; /* need one to hold the null */
10342 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10343 + if (resized == NULL) {
10344 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10345 + return NULL;
10346 + }
10347 + resized[count - 1] = strdup(depend_str);
10348 + resized[count] = NULL;
10349 +
10350 + return resized;
10351 +}
10352 +
10353 +void printDepends(pkg_t * pkg)
10354 +{
10355 + register int i, j;
10356 + compound_depend_t * depend;
10357 + int count;
10358 +
10359 + count = pkg->pre_depends_count + pkg->depends_count;
10360 +
10361 + depend = pkg->depends;
10362 + if(!depend){
10363 + fprintf(stderr, "Depends pointer is NULL\n");
10364 + return;
10365 + }
10366 + for(i = 0; i < count; i++){
10367 + fprintf(stderr, "%s has %d possibilities:\n",
10368 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10369 + depend->possibility_count);
10370 + for(j = 0; j < depend->possibility_count; j++)
10371 + fprintf(stderr, "\t%s version %s (%d)\n",
10372 + depend->possibilities[j]->pkg->name,
10373 + depend->possibilities[j]->version,
10374 + depend->possibilities[j]->constraint);
10375 + depend++;
10376 + }
10377 +}
10378 +
10379 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10380 +{
10381 + register int i, j;
10382 +
10383 + /* every pkg provides itself */
10384 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10385 +
10386 + if (!pkg->provides_count)
10387 + return 0;
10388 +
10389 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10390 + if (pkg->provides == NULL) {
10391 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10392 + return -1 ;
10393 + }
10394 + pkg->provides[0] = ab_pkg;
10395 +
10396 + // if (strcmp(ab_pkg->name, pkg->name))
10397 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10398 +
10399 + for(i = 0; i < pkg->provides_count; i++){
10400 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10401 +
10402 + pkg->provides[i+1] = provided_abpkg;
10403 +
10404 + j = 0;
10405 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10406 + }
10407 + return 0;
10408 +}
10409 +
10410 +/* Abhaya: added conflicts support */
10411 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10412 +{
10413 + register int i;
10414 + compound_depend_t * conflicts;
10415 +
10416 + if (!pkg->conflicts_count)
10417 + return 0;
10418 +
10419 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10420 + pkg->conflicts_count);
10421 + if (conflicts == NULL) {
10422 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10423 + return -1;
10424 + }
10425 + for (i = 0; i < pkg->conflicts_count; i++) {
10426 + conflicts->type = CONFLICTS;
10427 + parseDepends(conflicts, hash,
10428 + pkg->conflicts_str[i]);
10429 +#if 0
10430 + for (j = 0; j < conflicts->possibility_count; j++) {
10431 + depend_t *possibility = conflicts->possibilities[j];
10432 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10433 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10434 + }
10435 +#endif
10436 + conflicts++;
10437 + }
10438 + return 0;
10439 +}
10440 +
10441 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10442 +{
10443 + register int i, j;
10444 +
10445 + if (!pkg->replaces_count)
10446 + return 0;
10447 +
10448 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10449 + if (pkg->replaces == NULL) {
10450 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10451 + return -1;
10452 + }
10453 +
10454 + // if (strcmp(ab_pkg->name, pkg->name))
10455 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10456 +
10457 + for(i = 0; i < pkg->replaces_count; i++){
10458 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10459 +
10460 + pkg->replaces[i] = old_abpkg;
10461 +
10462 + j = 0;
10463 + if (!old_abpkg->replaced_by)
10464 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10465 + if ( old_abpkg->replaced_by == NULL ){
10466 + return -1;
10467 + }
10468 + /* if a package pkg both replaces and conflicts old_abpkg,
10469 + * then add it to the replaced_by vector so that old_abpkg
10470 + * will be upgraded to ab_pkg automatically */
10471 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10472 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10473 + }
10474 + return 0;
10475 +}
10476 +
10477 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10478 +{
10479 + int count;
10480 + register int i;
10481 + compound_depend_t * depends;
10482 +
10483 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10484 + return 0;
10485 +
10486 + if (0 && pkg->pre_depends_count)
10487 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10488 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10489 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10490 + if (depends == NULL) {
10491 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10492 + return -1;
10493 + }
10494 +
10495 +
10496 + for(i = 0; i < pkg->pre_depends_count; i++){
10497 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10498 + if (0 && pkg->pre_depends_count)
10499 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10500 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10501 + depends->type = PREDEPEND;
10502 + depends++;
10503 + }
10504 +
10505 + for(i = 0; i < pkg->recommends_count; i++){
10506 + parseDepends(depends, hash, pkg->recommends_str[i]);
10507 + if (0 && pkg->recommends_count)
10508 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10509 + pkg->recommends_str[i], depends, depends->possibility_count);
10510 + depends->type = RECOMMEND;
10511 + depends++;
10512 + }
10513 +
10514 + for(i = 0; i < pkg->suggests_count; i++){
10515 + parseDepends(depends, hash, pkg->suggests_str[i]);
10516 + if (0 && pkg->suggests_count)
10517 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10518 + pkg->suggests_str[i], depends, depends->possibility_count);
10519 + depends->type = SUGGEST;
10520 + depends++;
10521 + }
10522 +
10523 + for(i = 0; i < pkg->depends_count; i++){
10524 + parseDepends(depends, hash, pkg->depends_str[i]);
10525 + if (0 && pkg->depends_count)
10526 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10527 + pkg->depends_str[i], depends, depends->possibility_count);
10528 + depends++;
10529 + }
10530 + return 0;
10531 +}
10532 +
10533 +/*
10534 + * pkg_depend_string: returns the depends string specified by index.
10535 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10536 + * [0,npredepends) -> returns pre_depends_str[index]
10537 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10538 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10539 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10540 + */
10541 +char *pkg_depend_str(pkg_t *pkg, int index)
10542 +{
10543 + if (index < pkg->pre_depends_count) {
10544 + return pkg->pre_depends_str[index];
10545 + }
10546 + index -= pkg->pre_depends_count;
10547 +
10548 + if (index < pkg->recommends_count) {
10549 + return pkg->recommends_str[index];
10550 + }
10551 + index -= pkg->recommends_count;
10552 +
10553 + if (index < pkg->suggests_count) {
10554 + return pkg->suggests_str[index];
10555 + }
10556 + index -= pkg->suggests_count;
10557 +
10558 + if (index < pkg->depends_count) {
10559 + return pkg->depends_str[index];
10560 + }
10561 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10562 + return NULL;
10563 +}
10564 +
10565 +void freeDepends(pkg_t *pkg)
10566 +{
10567 + int i;
10568 +
10569 + if (pkg == NULL || pkg->depends == NULL) {
10570 + return;
10571 + }
10572 +
10573 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10574 + for (i=0; i < pkg->depends->possibility_count; i++) {
10575 + depend_deinit(pkg->depends->possibilities[i]);
10576 + }
10577 + free(pkg->depends->possibilities);
10578 + free(pkg->depends);
10579 + pkg->depends = NULL;
10580 +}
10581 +
10582 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10583 +{
10584 + compound_depend_t * depends;
10585 + int count, othercount;
10586 + register int i, j;
10587 + abstract_pkg_t * ab_depend;
10588 + abstract_pkg_t ** temp;
10589 +
10590 + count = pkg->pre_depends_count + pkg->depends_count;
10591 + depends = pkg->depends;
10592 +
10593 + if (0 && pkg->pre_depends_count)
10594 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10595 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10596 + for (i = 0; i < count; i++) {
10597 + if (0 && pkg->pre_depends_count)
10598 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10599 + for (j = 0; j < depends->possibility_count; j++){
10600 + ab_depend = depends->possibilities[j]->pkg;
10601 + if(!ab_depend->depended_upon_by)
10602 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10603 +
10604 + temp = ab_depend->depended_upon_by;
10605 + othercount = 1;
10606 + while(*temp){
10607 + temp++;
10608 + othercount++;
10609 + }
10610 + *temp = ab_pkg;
10611 +
10612 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10613 + (othercount + 1) * sizeof(abstract_pkg_t *));
10614 + /* the array may have moved */
10615 + temp = ab_depend->depended_upon_by + othercount;
10616 + *temp = NULL;
10617 + }
10618 + depends++;
10619 + }
10620 +}
10621 +
10622 +static depend_t * depend_init(void)
10623 +{
10624 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10625 + if ( d==NULL ){
10626 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10627 + return NULL;
10628 + }
10629 + d->constraint = NONE;
10630 + d->version = NULL;
10631 + d->pkg = NULL;
10632 +
10633 + return d;
10634 +}
10635 +
10636 +static void depend_deinit(depend_t *d)
10637 +{
10638 + free(d);
10639 +}
10640 +
10641 +static int parseDepends(compound_depend_t *compound_depend,
10642 + hash_table_t * hash, char * depend_str)
10643 +{
10644 + char * pkg_name, buffer[2048];
10645 + int num_of_ors = 0;
10646 + register int i;
10647 + register char * src, * dest;
10648 + depend_t ** possibilities;
10649 +
10650 + /* first count the number of ored possibilities for satisfying dependency */
10651 + src = depend_str;
10652 + while(*src)
10653 + if(*src++ == '|')
10654 + num_of_ors++;
10655 +
10656 + compound_depend->type = DEPEND;
10657 +
10658 + compound_depend->possibility_count = num_of_ors + 1;
10659 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10660 + if (!possibilities)
10661 + return -ENOMEM;
10662 + compound_depend->possibilities = possibilities;
10663 +
10664 + src = depend_str;
10665 + for(i = 0; i < num_of_ors + 1; i++){
10666 + possibilities[i] = depend_init();
10667 + if (!possibilities[i])
10668 + return -ENOMEM;
10669 + /* gobble up just the name first */
10670 + dest = buffer;
10671 + while(*src &&
10672 + !isspace(*src) &&
10673 + (*src != '(') &&
10674 + (*src != '*') &&
10675 + (*src != '|'))
10676 + *dest++ = *src++;
10677 + *dest = '\0';
10678 + pkg_name = trim_alloc(buffer);
10679 + if (pkg_name == NULL )
10680 + return -ENOMEM;
10681 +
10682 + /* now look at possible version info */
10683 +
10684 + /* skip to next chars */
10685 + if(isspace(*src))
10686 + while(*src && isspace(*src)) src++;
10687 +
10688 + /* extract constraint and version */
10689 + if(*src == '('){
10690 + src++;
10691 + if(!strncmp(src, "<<", 2)){
10692 + possibilities[i]->constraint = EARLIER;
10693 + src += 2;
10694 + }
10695 + else if(!strncmp(src, "<=", 2)){
10696 + possibilities[i]->constraint = EARLIER_EQUAL;
10697 + src += 2;
10698 + }
10699 + else if(!strncmp(src, ">=", 2)){
10700 + possibilities[i]->constraint = LATER_EQUAL;
10701 + src += 2;
10702 + }
10703 + else if(!strncmp(src, ">>", 2)){
10704 + possibilities[i]->constraint = LATER;
10705 + src += 2;
10706 + }
10707 + else if(!strncmp(src, "=", 1)){
10708 + possibilities[i]->constraint = EQUAL;
10709 + src++;
10710 + }
10711 + /* should these be here to support deprecated designations; dpkg does */
10712 + else if(!strncmp(src, "<", 1)){
10713 + possibilities[i]->constraint = EARLIER_EQUAL;
10714 + src++;
10715 + }
10716 + else if(!strncmp(src, ">", 1)){
10717 + possibilities[i]->constraint = LATER_EQUAL;
10718 + src++;
10719 + }
10720 +
10721 + /* now we have any constraint, pass space to version string */
10722 + while(isspace(*src)) src++;
10723 +
10724 + /* this would be the version string */
10725 + dest = buffer;
10726 + while(*src && *src != ')')
10727 + *dest++ = *src++;
10728 + *dest = '\0';
10729 +
10730 + possibilities[i]->version = trim_alloc(buffer);
10731 + /* fprintf(stderr, "let's print the depends version string:");
10732 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10733 + if (possibilities[i]->version == NULL )
10734 + return -ENOMEM;
10735 +
10736 +
10737 + }
10738 + /* hook up the dependency to its abstract pkg */
10739 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10740 +
10741 + free(pkg_name);
10742 +
10743 + /* now get past the ) and any possible | chars */
10744 + while(*src &&
10745 + (isspace(*src) ||
10746 + (*src == ')') ||
10747 + (*src == '|')))
10748 + src++;
10749 + if (*src == '*')
10750 + {
10751 + compound_depend->type = GREEDY_DEPEND;
10752 + src++;
10753 + }
10754 + }
10755 +
10756 + return 0;
10757 +}
10758 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_depends.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.h
10759 --- busybox-1.1.2-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10760 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-05-09 02:06:48.000000000 +0200
10761 @@ -0,0 +1,105 @@
10762 +/* pkg_depends.h - the itsy package management system
10763 +
10764 + Steven M. Ayer
10765 +
10766 + Copyright (C) 2002 Compaq Computer Corporation
10767 +
10768 + This program is free software; you can redistribute it and/or
10769 + modify it under the terms of the GNU General Public License as
10770 + published by the Free Software Foundation; either version 2, or (at
10771 + your option) any later version.
10772 +
10773 + This program is distributed in the hope that it will be useful, but
10774 + WITHOUT ANY WARRANTY; without even the implied warranty of
10775 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10776 + General Public License for more details.
10777 +*/
10778 +
10779 +#ifndef PKG_DEPENDS_H
10780 +#define PKG_DEPENDS_H
10781 +
10782 +#include "pkg.h"
10783 +#include "pkg_hash.h"
10784 +
10785 +enum depend_type {
10786 + PREDEPEND,
10787 + DEPEND,
10788 + CONFLICTS,
10789 + GREEDY_DEPEND,
10790 + RECOMMEND,
10791 + SUGGEST
10792 +};
10793 +typedef enum depend_type depend_type_t;
10794 +
10795 +enum version_constraint {
10796 + NONE,
10797 + EARLIER,
10798 + EARLIER_EQUAL,
10799 + EQUAL,
10800 + LATER_EQUAL,
10801 + LATER
10802 +};
10803 +typedef enum version_constraint version_constraint_t;
10804 +
10805 +struct depend{
10806 + version_constraint_t constraint;
10807 + char * version;
10808 + abstract_pkg_t * pkg;
10809 +};
10810 +typedef struct depend depend_t;
10811 +
10812 +struct compound_depend{
10813 + depend_type_t type;
10814 + int possibility_count;
10815 + struct depend ** possibilities;
10816 +};
10817 +typedef struct compound_depend compound_depend_t;
10818 +
10819 +#include "hash_table.h"
10820 +
10821 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10822 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10823 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10824 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10825 +
10826 +/**
10827 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10828 + * the same abstract package and 0 otherwise.
10829 + */
10830 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10831 +
10832 +/**
10833 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10834 + * otherwise.
10835 + */
10836 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10837 +
10838 +/**
10839 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10840 + * otherwise.
10841 + */
10842 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10843 +
10844 +/**
10845 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10846 + * otherwise.
10847 + */
10848 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10849 +
10850 +/**
10851 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10852 + * otherwise.
10853 + */
10854 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10855 +
10856 +char *pkg_depend_str(pkg_t *pkg, int index);
10857 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10858 +void freeDepends(pkg_t *pkg);
10859 +void printDepends(pkg_t * pkg);
10860 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10861 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10862 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10863 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10864 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10865 +
10866 +#endif
10867 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.c
10868 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10869 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-05-09 02:06:48.000000000 +0200
10870 @@ -0,0 +1,92 @@
10871 +/* pkg_dest.c - the itsy package management system
10872 +
10873 + Carl D. Worth
10874 +
10875 + Copyright (C) 2001 University of Southern California
10876 +
10877 + This program is free software; you can redistribute it and/or
10878 + modify it under the terms of the GNU General Public License as
10879 + published by the Free Software Foundation; either version 2, or (at
10880 + your option) any later version.
10881 +
10882 + This program is distributed in the hope that it will be useful, but
10883 + WITHOUT ANY WARRANTY; without even the implied warranty of
10884 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10885 + General Public License for more details.
10886 +*/
10887 +
10888 +#include "ipkg.h"
10889 +
10890 +#include "pkg_dest.h"
10891 +#include "file_util.h"
10892 +#include "str_util.h"
10893 +#include "sprintf_alloc.h"
10894 +
10895 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10896 +{
10897 + dest->name = strdup(name);
10898 +
10899 + /* Guarantee that dest->root_dir ends with a '/' */
10900 + if (str_ends_with(root_dir, "/")) {
10901 + dest->root_dir = strdup(root_dir);
10902 + } else {
10903 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10904 + }
10905 + file_mkdir_hier(dest->root_dir, 0755);
10906 +
10907 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10908 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10909 + file_mkdir_hier(dest->ipkg_dir, 0755);
10910 +
10911 + if (str_starts_with (lists_dir, "/"))
10912 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10913 + else
10914 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10915 +
10916 + file_mkdir_hier(dest->lists_dir, 0755);
10917 +
10918 + sprintf_alloc(&dest->info_dir, "%s/%s",
10919 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10920 + file_mkdir_hier(dest->info_dir, 0755);
10921 +
10922 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10923 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10924 +
10925 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10926 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10927 +
10928 + dest->status_file = NULL;
10929 +
10930 + return 0;
10931 +}
10932 +
10933 +void pkg_dest_deinit(pkg_dest_t *dest)
10934 +{
10935 + free(dest->name);
10936 + dest->name = NULL;
10937 +
10938 + free(dest->root_dir);
10939 + dest->root_dir = NULL;
10940 +
10941 + free(dest->ipkg_dir);
10942 + dest->ipkg_dir = NULL;
10943 +
10944 + free(dest->lists_dir);
10945 + dest->lists_dir = NULL;
10946 +
10947 + free(dest->info_dir);
10948 + dest->info_dir = NULL;
10949 +
10950 + free(dest->status_file_name);
10951 + dest->status_file_name = NULL;
10952 +
10953 + free(dest->status_file_tmp_name);
10954 + dest->status_file_tmp_name = NULL;
10955 +
10956 + if (dest->status_file) {
10957 + fclose(dest->status_file);
10958 + }
10959 + dest->status_file = NULL;
10960 +
10961 + dest->root_dir = NULL;
10962 +}
10963 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.h
10964 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10965 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-05-09 02:06:48.000000000 +0200
10966 @@ -0,0 +1,38 @@
10967 +/* pkg_dest.h - the itsy package management system
10968 +
10969 + Carl D. Worth
10970 +
10971 + Copyright (C) 2001 University of Southern California
10972 +
10973 + This program is free software; you can redistribute it and/or
10974 + modify it under the terms of the GNU General Public License as
10975 + published by the Free Software Foundation; either version 2, or (at
10976 + your option) any later version.
10977 +
10978 + This program is distributed in the hope that it will be useful, but
10979 + WITHOUT ANY WARRANTY; without even the implied warranty of
10980 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10981 + General Public License for more details.
10982 +*/
10983 +
10984 +#ifndef PKG_DEST_H
10985 +#define PKG_DEST_H
10986 +
10987 +typedef struct pkg_dest pkg_dest_t;
10988 +struct pkg_dest
10989 +{
10990 + char *name;
10991 + char *root_dir;
10992 + char *ipkg_dir;
10993 + char *lists_dir;
10994 + char *info_dir;
10995 + char *status_file_name;
10996 + char *status_file_tmp_name;
10997 + FILE *status_file;
10998 +};
10999 +
11000 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
11001 +void pkg_dest_deinit(pkg_dest_t *dest);
11002 +
11003 +#endif
11004 +
11005 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c
11006 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
11007 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-05-09 02:06:48.000000000 +0200
11008 @@ -0,0 +1,85 @@
11009 +/* pkg_dest_list.c - the itsy package management system
11010 +
11011 + Carl D. Worth
11012 +
11013 + Copyright (C) 2001 University of Southern California
11014 +
11015 + This program is free software; you can redistribute it and/or
11016 + modify it under the terms of the GNU General Public License as
11017 + published by the Free Software Foundation; either version 2, or (at
11018 + your option) any later version.
11019 +
11020 + This program is distributed in the hope that it will be useful, but
11021 + WITHOUT ANY WARRANTY; without even the implied warranty of
11022 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11023 + General Public License for more details.
11024 +*/
11025 +
11026 +#include "ipkg.h"
11027 +
11028 +#include "pkg_dest.h"
11029 +#include "void_list.h"
11030 +#include "pkg_dest_list.h"
11031 +
11032 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
11033 +{
11034 + return void_list_elt_init((void_list_elt_t *) elt, data);
11035 +}
11036 +
11037 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
11038 +{
11039 + void_list_elt_deinit((void_list_elt_t *) elt);
11040 +}
11041 +
11042 +int pkg_dest_list_init(pkg_dest_list_t *list)
11043 +{
11044 + return void_list_init((void_list_t *) list);
11045 +}
11046 +
11047 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
11048 +{
11049 + pkg_dest_list_elt_t *iter;
11050 + pkg_dest_t *pkg_dest;
11051 +
11052 + for (iter = list->head; iter; iter = iter->next) {
11053 + pkg_dest = iter->data;
11054 + pkg_dest_deinit(pkg_dest);
11055 +
11056 + /* malloced in pkg_dest_list_append */
11057 + free(pkg_dest);
11058 + iter->data = NULL;
11059 + }
11060 + void_list_deinit((void_list_t *) list);
11061 +}
11062 +
11063 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
11064 + const char *root_dir,const char *lists_dir)
11065 +{
11066 + int err;
11067 + pkg_dest_t *pkg_dest;
11068 +
11069 + /* freed in plg_dest_list_deinit */
11070 + pkg_dest = malloc(sizeof(pkg_dest_t));
11071 + if (pkg_dest == NULL) {
11072 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
11073 + return NULL;
11074 + }
11075 +
11076 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
11077 + err = void_list_append((void_list_t *) list, pkg_dest);
11078 + if (err) {
11079 + return NULL;
11080 + }
11081 +
11082 + return pkg_dest;
11083 +}
11084 +
11085 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
11086 +{
11087 + return void_list_push((void_list_t *) list, data);
11088 +}
11089 +
11090 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
11091 +{
11092 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
11093 +}
11094 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h
11095 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
11096 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-05-09 02:06:48.000000000 +0200
11097 @@ -0,0 +1,50 @@
11098 +/* pkg_dest_list.h - the itsy package management system
11099 +
11100 + Carl D. Worth
11101 +
11102 + Copyright (C) 2001 University of Southern California
11103 +
11104 + This program is free software; you can redistribute it and/or
11105 + modify it under the terms of the GNU General Public License as
11106 + published by the Free Software Foundation; either version 2, or (at
11107 + your option) any later version.
11108 +
11109 + This program is distributed in the hope that it will be useful, but
11110 + WITHOUT ANY WARRANTY; without even the implied warranty of
11111 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11112 + General Public License for more details.
11113 +*/
11114 +
11115 +#ifndef PKG_DEST_LIST_H
11116 +#define PKG_DEST_LIST_H
11117 +
11118 +#include "pkg_dest.h"
11119 +
11120 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
11121 +struct pkg_dest_list_elt
11122 +{
11123 + pkg_dest_list_elt_t *next;
11124 + pkg_dest_t *data;
11125 +};
11126 +
11127 +typedef struct pkg_dest_list pkg_dest_list_t;
11128 +struct pkg_dest_list
11129 +{
11130 + pkg_dest_list_elt_t pre_head;
11131 + pkg_dest_list_elt_t *head;
11132 + pkg_dest_list_elt_t *tail;
11133 +};
11134 +
11135 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
11136 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
11137 +
11138 +int pkg_dest_list_init(pkg_dest_list_t *list);
11139 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
11140 +
11141 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
11142 + const char *root_dir,const char* lists_dir);
11143 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
11144 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
11145 +
11146 +#endif
11147 +
11148 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_extract.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.c
11149 --- busybox-1.1.2-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
11150 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-05-09 02:06:48.000000000 +0200
11151 @@ -0,0 +1,224 @@
11152 +/* pkg_extract.c - the itsy package management system
11153 +
11154 + Carl D. Worth
11155 +
11156 + Copyright (C) 2001 University of Southern California
11157 +
11158 + This program is free software; you can redistribute it and/or
11159 + modify it under the terms of the GNU General Public License as
11160 + published by the Free Software Foundation; either version 2, or (at
11161 + your option) any later version.
11162 +
11163 + This program is distributed in the hope that it will be useful, but
11164 + WITHOUT ANY WARRANTY; without even the implied warranty of
11165 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11166 + General Public License for more details.
11167 +*/
11168 +
11169 +#include "ipkg.h"
11170 +#include <errno.h>
11171 +#include <fcntl.h>
11172 +#include <stdio.h>
11173 +
11174 +#include "pkg_extract.h"
11175 +
11176 +#include "libbb.h"
11177 +#include "file_util.h"
11178 +#include "sprintf_alloc.h"
11179 +#include "unarchive.h"
11180 +
11181 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
11182 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
11183 +#define IPKG_CONTROL_FILE "control"
11184 +
11185 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
11186 +{
11187 + archive_handle_t *archive;
11188 + char *path;
11189 +
11190 + sprintf_alloc(&path, "%s/", dir);
11191 + archive = init_handle();
11192 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
11193 + archive->filter = filter_accept_list;
11194 + archive->accept = llist_add_to(NULL, (char *)filename);
11195 + archive->buffer = path;
11196 + archive->action_data = data_extract_all_prefix;
11197 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
11198 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11199 + close(archive->src_fd);
11200 + free(archive->accept);
11201 + free(archive);
11202 + free(path);
11203 +}
11204 +
11205 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
11206 +{
11207 + unsigned int size = strlen(archive->file_header->name) + 2;
11208 +
11209 + if (archive->buffer == NULL) {
11210 + archive->buffer = xmalloc(size);
11211 + strcpy(archive->buffer, archive->file_header->name);
11212 + } else {
11213 + size += strlen(archive->buffer);
11214 + archive->buffer = xrealloc(archive->buffer, size);
11215 + strcat(archive->buffer, archive->file_header->name);
11216 + }
11217 + strcat(archive->buffer, "\n");
11218 + data_skip(archive);
11219 +}
11220 +
11221 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
11222 +{
11223 + archive_handle_t *archive;
11224 + char *name;
11225 +
11226 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11227 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11228 + archive = init_handle();
11229 + archive->src_fd = bb_xopen(name, O_RDONLY);
11230 + archive->filter = filter_accept_list;
11231 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
11232 + archive->action_data = data_extract_to_buffer;
11233 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11234 + close(archive->src_fd);
11235 + fputs(archive->buffer, stream);
11236 + free(archive->buffer);
11237 + free(archive->accept);
11238 + free(archive);
11239 + free(name);
11240 +
11241 + return 0;
11242 +}
11243 +
11244 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
11245 +{
11246 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11247 +}
11248 +
11249 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11250 +{
11251 + archive_handle_t *archive;
11252 + char *name;
11253 + char *path;
11254 +
11255 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11256 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11257 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11258 + archive = init_handle();
11259 + archive->src_fd = bb_xopen(name, O_RDONLY);
11260 + archive->filter = filter_accept_all;
11261 + archive->buffer = path;
11262 + archive->action_data = data_extract_all_prefix;
11263 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11264 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11265 + close(archive->src_fd);
11266 + free(archive);
11267 + free(path);
11268 + free(name);
11269 +
11270 + return 0;
11271 +}
11272 +
11273 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11274 +{
11275 + archive_handle_t *archive;
11276 + char *name;
11277 + char *path;
11278 +
11279 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11280 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11281 + sprintf_alloc(&path, "%s/", dir);
11282 + archive = init_handle();
11283 + archive->src_fd = bb_xopen(name, O_RDONLY);
11284 + archive->filter = filter_accept_all;
11285 + archive->buffer = path;
11286 + archive->action_data = data_extract_all_prefix;
11287 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11288 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11289 + close(archive->src_fd);
11290 + free(archive);
11291 + free(path);
11292 + free(name);
11293 +
11294 + return 0;
11295 +}
11296 +
11297 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11298 +{
11299 + int err=0;
11300 + char *line, *data_file;
11301 + FILE *file;
11302 + FILE *tmp;
11303 +
11304 + file = fopen(file_name, "w");
11305 + if (file == NULL) {
11306 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11307 + __FUNCTION__, file_name);
11308 + return EINVAL;
11309 + }
11310 +
11311 + tmp = tmpfile();
11312 + if (pkg->installed_files) {
11313 + str_list_elt_t *elt;
11314 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11315 + fprintf(file, "%s\n", elt->data);
11316 + }
11317 + } else {
11318 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11319 + if (err) {
11320 + fclose(file);
11321 + fclose(tmp);
11322 + return err;
11323 + }
11324 +
11325 + /* Fixup data file names by removing the initial '.' */
11326 + rewind(tmp);
11327 + while (1) {
11328 + line = file_read_line_alloc(tmp);
11329 + if (line == NULL) {
11330 + break;
11331 + }
11332 +
11333 + data_file = line;
11334 + if (*data_file == '.') {
11335 + data_file++;
11336 + }
11337 +
11338 + if (*data_file != '/') {
11339 + fputs("/", file);
11340 + }
11341 +
11342 + /* I have no idea why, but this is what dpkg does */
11343 + if (strcmp(data_file, "/\n") == 0) {
11344 + fputs("/.\n", file);
11345 + } else {
11346 + fputs(data_file, file);
11347 + }
11348 + }
11349 + }
11350 + fclose(tmp);
11351 + fclose(file);
11352 +
11353 + return err;
11354 +}
11355 +
11356 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11357 +{
11358 + archive_handle_t *archive;
11359 + char *name;
11360 +
11361 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11362 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11363 + archive = init_handle();
11364 + archive->src_fd = bb_xopen(name, O_RDONLY);
11365 + archive->filter = filter_accept_all;
11366 + archive->action_data = data_extract_file_name_to_buffer;
11367 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11368 + close(archive->src_fd);
11369 + fputs(archive->buffer, file);
11370 + free(archive->buffer);
11371 + free(archive);
11372 + free(name);
11373 +
11374 + return 0;
11375 +}
11376 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_extract.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.h
11377 --- busybox-1.1.2-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11378 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-05-09 02:06:48.000000000 +0200
11379 @@ -0,0 +1,32 @@
11380 +/* pkg_extract.c - the itsy package management system
11381 +
11382 + Carl D. Worth
11383 +
11384 + Copyright (C) 2001 University of Southern California
11385 +
11386 + This program is free software; you can redistribute it and/or
11387 + modify it under the terms of the GNU General Public License as
11388 + published by the Free Software Foundation; either version 2, or (at
11389 + your option) any later version.
11390 +
11391 + This program is distributed in the hope that it will be useful, but
11392 + WITHOUT ANY WARRANTY; without even the implied warranty of
11393 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11394 + General Public License for more details.
11395 +*/
11396 +
11397 +#ifndef PKG_EXTRACT_H
11398 +#define PKG_EXTRACT_H
11399 +
11400 +#include "pkg.h"
11401 +
11402 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11403 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11404 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11405 + const char *dir,
11406 + const char *prefix);
11407 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11408 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11409 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11410 +
11411 +#endif
11412 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_hash.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.c
11413 --- busybox-1.1.2-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11414 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-05-09 02:12:05.000000000 +0200
11415 @@ -0,0 +1,617 @@
11416 +/* ipkg_hash.c - the itsy package management system
11417 +
11418 + Steven M. Ayer
11419 +
11420 + Copyright (C) 2002 Compaq Computer Corporation
11421 +
11422 + This program is free software; you can redistribute it and/or
11423 + modify it under the terms of the GNU General Public License as
11424 + published by the Free Software Foundation; either version 2, or (at
11425 + your option) any later version.
11426 +
11427 + This program is distributed in the hope that it will be useful, but
11428 + WITHOUT ANY WARRANTY; without even the implied warranty of
11429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11430 + General Public License for more details.
11431 +*/
11432 +
11433 +#include "ipkg.h"
11434 +#include <errno.h>
11435 +#include <ctype.h>
11436 +#include <stdlib.h>
11437 +#include <string.h>
11438 +
11439 +#include "hash_table.h"
11440 +#include "pkg.h"
11441 +#include "ipkg_message.h"
11442 +#include "pkg_vec.h"
11443 +#include "pkg_hash.h"
11444 +#include "pkg_parse.h"
11445 +#include "ipkg_utils.h"
11446 +
11447 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11448 +
11449 +/*
11450 + * this will talk to both feeds-lists files and installed status files
11451 + * example api:
11452 + *
11453 + * hash_table_t hash;
11454 + * pkg_hash_init(name, &hash, 1000);
11455 + * pkg_hash_add_from_file(<feed filename>);
11456 + *
11457 + * the query function is just there as a shell to prove to me that this
11458 + * sort of works, but isn't far from doing something useful
11459 + *
11460 + * -sma, 12/21/01
11461 + * modified: CDW 3 Jan. 2002
11462 + */
11463 +
11464 +
11465 +\f
11466 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11467 +{
11468 + return hash_table_init(name, hash, len);
11469 +}
11470 +
11471 +void pkg_hash_deinit(hash_table_t *hash)
11472 +{
11473 + hash_table_deinit(hash);
11474 +}
11475 +
11476 +
11477 +/* Find the default arch for a given package status file if none is given. */
11478 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11479 +{
11480 + nv_pair_list_elt_t *l;
11481 + char *def_arch = HOST_CPU_STR; /* Default arch */
11482 + int def_prio = 0; /* Other archs override this */
11483 +
11484 + l = conf->arch_list.head;
11485 +
11486 + while (l) {
11487 + nv_pair_t *nv = l->data;
11488 + int priority = strtol(nv->value, NULL, 0);
11489 +
11490 + /* Check if this arch has higher priority, and is valid */
11491 + if ((priority > def_prio) &&
11492 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11493 + /* Our new default */
11494 + def_prio = priority;
11495 + def_arch = nv->name;
11496 + }
11497 + l = l->next;
11498 + }
11499 +
11500 + return strdup(def_arch);
11501 +}
11502 +
11503 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11504 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11505 +{
11506 + hash_table_t *hash = &conf->pkg_hash;
11507 + char **raw;
11508 + char **raw_start;
11509 + pkg_t *pkg;
11510 +
11511 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11512 + if (!raw)
11513 + return -ENOMEM;
11514 +
11515 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11516 + pkg = pkg_new();
11517 + if (!pkg)
11518 + return -ENOMEM;
11519 +
11520 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11521 + if (!pkg->architecture) {
11522 + char *version_str = pkg_version_str_alloc(pkg);
11523 + pkg->architecture = pkg_get_default_arch(conf);
11524 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11525 + pkg->name, version_str, pkg->architecture);
11526 + free(version_str);
11527 + }
11528 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11529 + } else {
11530 + free(pkg);
11531 + }
11532 + }
11533 +
11534 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11535 + memory after read_raw_pkgs_from_file */
11536 + raw = raw_start;
11537 + while (*raw) {
11538 + free(*raw++);
11539 + }
11540 + free(raw_start);
11541 + return 0;
11542 +}
11543 +
11544 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11545 +{
11546 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11547 +}
11548 +
11549 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11550 +{
11551 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11552 + if (apkg)
11553 + return NULL;
11554 + return apkg->provided_by;
11555 +}
11556 +
11557 +
11558 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11559 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11560 +{
11561 + int i;
11562 + int nprovides = 0;
11563 + int nmatching = 0;
11564 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11565 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11566 + abstract_pkg_vec_t *provided_apkg_vec;
11567 + abstract_pkg_t **provided_apkgs;
11568 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11569 + pkg_t *latest_installed_parent = NULL;
11570 + pkg_t *latest_matching = NULL;
11571 + pkg_t *held_pkg = NULL;
11572 + pkg_t *good_pkg_by_name = NULL;
11573 +
11574 + if (matching_apkgs == NULL || providers == NULL ||
11575 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11576 + return NULL;
11577 +
11578 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11579 +
11580 + provided_apkg_vec = apkg->provided_by;
11581 + nprovides = provided_apkg_vec->len;
11582 + provided_apkgs = provided_apkg_vec->pkgs;
11583 + if (nprovides > 1)
11584 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11585 +
11586 + /* accumulate all the providers */
11587 + for (i = 0; i < nprovides; i++) {
11588 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11589 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11590 + abstract_pkg_vec_insert(providers, provider_apkg);
11591 + }
11592 + nprovides = providers->len;
11593 +
11594 + for (i = 0; i < nprovides; i++) {
11595 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11596 + abstract_pkg_t *replacement_apkg = NULL;
11597 + pkg_vec_t *vec;
11598 +
11599 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11600 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11601 + if (provider_apkg->replaced_by->len > 1) {
11602 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11603 + provider_apkg->name, replacement_apkg->name);
11604 + }
11605 + }
11606 +
11607 + if (replacement_apkg)
11608 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11609 + replacement_apkg->name, provider_apkg->name);
11610 +
11611 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11612 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11613 + continue;
11614 + else
11615 + provider_apkg = replacement_apkg;
11616 + }
11617 +
11618 + if (!(vec = provider_apkg->pkgs)) {
11619 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11620 + continue;
11621 + }
11622 +
11623 +
11624 + /* now check for supported architecture */
11625 + {
11626 + int max_count = 0;
11627 + int i;
11628 +
11629 + /* count packages matching max arch priority and keep track of last one */
11630 + for (i = 0; i < vec->len; i++) {
11631 + pkg_t *maybe = vec->pkgs[i];
11632 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11633 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11634 + if (maybe->arch_priority > 0) {
11635 + max_count++;
11636 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11637 + pkg_vec_insert(matching_pkgs, maybe);
11638 + }
11639 + }
11640 + }
11641 + }
11642 +
11643 + if (matching_pkgs->len > 1)
11644 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11645 + if (matching_apkgs->len > 1)
11646 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11647 +
11648 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11649 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11650 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11651 + Until now I always got the latest, but that breaks the downgrade option.
11652 + If I stop at the first one, I would probably miss the new ones
11653 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11654 + or from a Packages feed.
11655 + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
11656 +/*Pigi*/
11657 +
11658 + for (i = 0; i < matching_pkgs->len; i++) {
11659 + pkg_t *matching = matching_pkgs->pkgs[i];
11660 + if (constraint_fcn(matching, cdata)) { /* We found it */
11661 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11662 + good_pkg_by_name = matching;
11663 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11664 + break;
11665 + }
11666 + }
11667 +
11668 +
11669 + for (i = 0; i < matching_pkgs->len; i++) {
11670 + pkg_t *matching = matching_pkgs->pkgs[i];
11671 + latest_matching = matching;
11672 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11673 + latest_installed_parent = matching;
11674 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11675 + if (held_pkg)
11676 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11677 + held_pkg->name, matching->name);
11678 + held_pkg = matching;
11679 + }
11680 + }
11681 +
11682 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11683 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11684 + apkg->name, matching_apkgs->len);
11685 + for (i = 0; i < matching_apkgs->len; i++) {
11686 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11687 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11688 + }
11689 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11690 + }
11691 +
11692 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11693 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11694 + __FUNCTION__, apkg->name, matching_pkgs->len);
11695 + for (i = 0; i < matching_pkgs->len; i++) {
11696 + pkg_t *matching = matching_pkgs->pkgs[i];
11697 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11698 + matching->name, matching->version, matching->architecture);
11699 + }
11700 + }
11701 +
11702 + nmatching = matching_apkgs->len;
11703 +
11704 + pkg_vec_free(matching_pkgs);
11705 + abstract_pkg_vec_free(matching_apkgs);
11706 + abstract_pkg_vec_free(providers);
11707 +
11708 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11709 + return good_pkg_by_name;
11710 + }
11711 + if (held_pkg) {
11712 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11713 + return held_pkg;
11714 + }
11715 + if (latest_installed_parent) {
11716 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11717 + return latest_installed_parent;
11718 + }
11719 + if (nmatching > 1) {
11720 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11721 + return NULL;
11722 + }
11723 + if (latest_matching) {
11724 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11725 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11726 + return latest_matching;
11727 + }
11728 + return NULL;
11729 +}
11730 +
11731 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11732 +{
11733 + const char *name = (const char *)cdata;
11734 + if (strcmp(pkg->name, name) == 0)
11735 + return 1;
11736 + else
11737 + return 0;
11738 +}
11739 +
11740 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11741 +{
11742 + hash_table_t *hash = &conf->pkg_hash;
11743 + abstract_pkg_t *apkg = NULL;
11744 +
11745 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11746 + return NULL;
11747 +
11748 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11749 +}
11750 +
11751 +
11752 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11753 + const char *pkg_name,
11754 + const char * version)
11755 +{
11756 + pkg_vec_t * vec;
11757 + register int i;
11758 + char *version_str = NULL;
11759 +
11760 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11761 + return NULL;
11762 +
11763 + for(i = 0; i < vec->len; i++) {
11764 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11765 + if(!strcmp(version_str, version)) {
11766 + free(version_str);
11767 + break;
11768 + }
11769 + free(version_str);
11770 + }
11771 +
11772 + if(i == vec->len)
11773 + return NULL;
11774 +
11775 + return vec->pkgs[i];
11776 +}
11777 +
11778 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11779 + const char *pkg_name,
11780 + pkg_dest_t *dest)
11781 +{
11782 + pkg_vec_t * vec;
11783 + register int i;
11784 +
11785 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11786 + return NULL;
11787 + }
11788 +
11789 + for(i = 0; i < vec->len; i++)
11790 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11791 + return vec->pkgs[i];
11792 + }
11793 + return NULL;
11794 +}
11795 +
11796 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11797 + const char *pkg_name)
11798 +{
11799 + pkg_vec_t * vec;
11800 + register int i;
11801 +
11802 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11803 + return NULL;
11804 + }
11805 +
11806 + for(i = 0; i < vec->len; i++)
11807 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11808 + return vec->pkgs[i];
11809 + }
11810 +
11811 + return NULL;
11812 +}
11813 +
11814 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11815 +{
11816 + abstract_pkg_t * ab_pkg;
11817 +
11818 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11819 + return NULL;
11820 + }
11821 +
11822 + if (ab_pkg->pkgs) {
11823 + return ab_pkg->pkgs;
11824 + } else if (ab_pkg->provided_by) {
11825 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11826 + if (abpkg != NULL){
11827 + return abpkg->pkgs;
11828 + } else {
11829 + return ab_pkg->pkgs;
11830 + }
11831 + } else {
11832 + return NULL;
11833 + }
11834 +}
11835 +
11836 +static int pkg_compare_names(const void *p1, const void *p2)
11837 +{
11838 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11839 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11840 + if (pkg1->name == NULL)
11841 + return 1;
11842 + if (pkg2->name == NULL)
11843 + return -1;
11844 + return(strcmp(pkg1->name, pkg2->name));
11845 +}
11846 +
11847 +
11848 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11849 +{
11850 + int j;
11851 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11852 + pkg_vec_t *all = (pkg_vec_t *)data;
11853 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11854 + if (pkg_vec) {
11855 + for (j = 0; j < pkg_vec->len; j++) {
11856 + pkg_t *pkg = pkg_vec->pkgs[j];
11857 + pkg_vec_insert(all, pkg);
11858 + }
11859 + }
11860 +}
11861 +
11862 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11863 +{
11864 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11865 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11866 +}
11867 +
11868 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11869 +{
11870 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11871 + pkg_vec_t *all = (pkg_vec_t *)data;
11872 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11873 + int j;
11874 + if (pkg_vec) {
11875 + for (j = 0; j < pkg_vec->len; j++) {
11876 + pkg_t *pkg = pkg_vec->pkgs[j];
11877 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11878 + pkg_vec_insert(all, pkg);
11879 + }
11880 + }
11881 + }
11882 +}
11883 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11884 +{
11885 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11886 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11887 +}
11888 +
11889 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11890 +{
11891 + int i;
11892 + pkg_t *pkg;
11893 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11894 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11895 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11896 + fprintf(stdout, "%s\n", ab_pkg->name);
11897 + i = 0;
11898 + if (dependents != NULL)
11899 + while (dependents [i] != NULL)
11900 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11901 + dependents = ab_pkg->provided_by->pkgs;
11902 + i = 0;
11903 + if (dependents != NULL)
11904 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11905 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11906 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11907 + if (pkg) {
11908 + i = 0;
11909 + while (i < pkg->depends_count)
11910 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11911 + }
11912 +}
11913 +void pkg_hash_dump(hash_table_t *hash, void *data)
11914 +{
11915 +
11916 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11917 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11918 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11919 +}
11920 +
11921 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11922 +{
11923 + abstract_pkg_t * ab_pkg;
11924 +
11925 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11926 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11927 +
11928 + return ab_pkg;
11929 +}
11930 +
11931 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11932 +{
11933 + abstract_pkg_t * ab_pkg;
11934 + int arch_priority;
11935 +
11936 + if(!pkg)
11937 + return pkg;
11938 +
11939 + arch_priority = pkg->arch_priority;
11940 +
11941 + if (buildDepends(hash, pkg)<0){
11942 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11943 + return NULL;
11944 + }
11945 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11946 +
11947 + if (set_status) {
11948 + if (pkg->state_status == SS_INSTALLED) {
11949 + ab_pkg->state_status = SS_INSTALLED;
11950 + } else if (pkg->state_status == SS_UNPACKED) {
11951 + ab_pkg->state_status = SS_UNPACKED;
11952 + }
11953 + }
11954 +
11955 + if(!ab_pkg->pkgs)
11956 + ab_pkg->pkgs = pkg_vec_alloc();
11957 +
11958 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11959 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11960 + pkg->parent = ab_pkg;
11961 +
11962 + if (buildProvides(hash, ab_pkg, pkg)<0){
11963 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11964 + return NULL;
11965 + }
11966 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11967 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11968 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11969 + return NULL;
11970 + }
11971 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11972 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11973 + return NULL;
11974 + }
11975 +
11976 + buildDependedUponBy(pkg, ab_pkg);
11977 + return pkg;
11978 +}
11979 +
11980 +/*
11981 + * this will assume that we've already determined that
11982 + * the abstract pkg doesn't exist, 'cause we should know these things...
11983 + */
11984 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11985 +{
11986 + abstract_pkg_t * ab_pkg;
11987 +
11988 + ab_pkg = abstract_pkg_new();
11989 + if (ab_pkg == NULL) { return NULL; }
11990 +
11991 + ab_pkg->name = strdup(pkg_name);
11992 + hash_table_insert(hash, pkg_name, ab_pkg);
11993 +
11994 + return ab_pkg;
11995 +}
11996 +
11997 +
11998 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11999 +{
12000 + hash_table_t *file_hash = &conf->file_hash;
12001 +
12002 + return hash_table_get(file_hash, file_name);
12003 +}
12004 +
12005 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
12006 +{
12007 + hash_table_t *file_hash = &conf->file_hash;
12008 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
12009 + int file_name_len = strlen(file_name);
12010 +
12011 + if (file_name[file_name_len -1] == '/')
12012 + return 0;
12013 +
12014 + if (conf->offline_root) {
12015 + int len = strlen(conf->offline_root);
12016 + if (strncmp(file_name, conf->offline_root, len) == 0) {
12017 + file_name += len;
12018 + }
12019 + }
12020 +
12021 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
12022 + hash_table_insert(file_hash, file_name, owning_pkg);
12023 + if (old_owning_pkg) {
12024 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12025 + /* mark this package to have its filelist written */
12026 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12027 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12028 + }
12029 + return 0;
12030 +}
12031 +
12032 +
12033 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_hash.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.h
12034 --- busybox-1.1.2-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12035 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-05-09 02:06:48.000000000 +0200
12036 @@ -0,0 +1,61 @@
12037 +/* pkg_hash.h - the itsy package management system
12038 +
12039 + Steven M. Ayer
12040 +
12041 + Copyright (C) 2002 Compaq Computer Corporation
12042 +
12043 + This program is free software; you can redistribute it and/or
12044 + modify it under the terms of the GNU General Public License as
12045 + published by the Free Software Foundation; either version 2, or (at
12046 + your option) any later version.
12047 +
12048 + This program is distributed in the hope that it will be useful, but
12049 + WITHOUT ANY WARRANTY; without even the implied warranty of
12050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12051 + General Public License for more details.
12052 +*/
12053 +
12054 +#ifndef PKG_HASH_H
12055 +#define PKG_HASH_H
12056 +
12057 +#include "pkg.h"
12058 +#include "pkg_vec.h"
12059 +#include "hash_table.h"
12060 +
12061 +
12062 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12063 +void pkg_hash_deinit(hash_table_t *hash);
12064 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12065 +
12066 +void pkg_hash_dump(hash_table_t *hash, void *data);
12067 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12068 +
12069 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12070 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12071 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12072 +
12073 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12074 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12075 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12076 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12077 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12078 + const char *pkg_name,
12079 + const char * version);
12080 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12081 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12082 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12083 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12084 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12085 + const char *pkg_name);
12086 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12087 + const char *pkg_name,
12088 + pkg_dest_t *dest);
12089 +
12090 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12091 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12092 +
12093 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12094 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12095 +
12096 +#endif
12097 +
12098 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_parse.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.c
12099 --- busybox-1.1.2-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12100 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-05-09 02:06:48.000000000 +0200
12101 @@ -0,0 +1,366 @@
12102 +/* pkg_parse.c - the itsy package management system
12103 +
12104 + Steven M. Ayer
12105 +
12106 + Copyright (C) 2002 Compaq Computer Corporation
12107 +
12108 + This program is free software; you can redistribute it and/or
12109 + modify it under the terms of the GNU General Public License as
12110 + published by the Free Software Foundation; either version 2, or (at
12111 + your option) any later version.
12112 +
12113 + This program is distributed in the hope that it will be useful, but
12114 + WITHOUT ANY WARRANTY; without even the implied warranty of
12115 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12116 + General Public License for more details.
12117 +*/
12118 +
12119 +#include "ipkg.h"
12120 +#include <errno.h>
12121 +#include <ctype.h>
12122 +
12123 +#include "pkg.h"
12124 +#include "ipkg_utils.h"
12125 +#include "pkg_parse.h"
12126 +
12127 +int isGenericFieldType(char * type, char * line)
12128 +{
12129 + if(!strncmp(line, type, strlen(type)))
12130 + return 1;
12131 + return 0;
12132 +}
12133 +
12134 +char * parseGenericFieldType(char * type, char * raw)
12135 +{
12136 + char * field_value = raw + (strlen(type) + 1);
12137 + return trim_alloc(field_value);
12138 +}
12139 +
12140 +void parseStatus(pkg_t *pkg, char * raw)
12141 +{
12142 + char sw_str[64], sf_str[64], ss_str[64];
12143 +
12144 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12145 + pkg->state_want = pkg_state_want_from_str(sw_str);
12146 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12147 + pkg->state_status = pkg_state_status_from_str(ss_str);
12148 +}
12149 +
12150 +char ** parseDependsString(char * raw, int * depends_count)
12151 +{
12152 + char ** depends = NULL;
12153 + int line_count = 0;
12154 + char buff[2048], * dest;
12155 +
12156 + while(raw && *raw && !isspace(*raw)) {
12157 + raw++;
12158 + }
12159 +
12160 + if(line_is_blank(raw)){
12161 + *depends_count = line_count;
12162 + return NULL;
12163 + }
12164 + while(raw && *raw){
12165 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12166 +
12167 + while(isspace(*raw)) raw++;
12168 +
12169 + dest = buff;
12170 + while((*raw != ',') && *raw)
12171 + *dest++ = *raw++;
12172 +
12173 + *dest = '\0';
12174 + depends[line_count] = trim_alloc(buff);
12175 + if(depends[line_count] ==NULL)
12176 + return NULL;
12177 + line_count++;
12178 + if(*raw == ',')
12179 + raw++;
12180 + }
12181 + *depends_count = line_count;
12182 + return depends;
12183 +}
12184 +
12185 +void parseConffiles(pkg_t * pkg, char * raw)
12186 +{
12187 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12188 +
12189 + if(!strncmp(raw, "Conffiles:", 10))
12190 + raw += strlen("Conffiles:");
12191 +
12192 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12193 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12194 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12195 + while (*raw && isspace(*raw)) {
12196 + raw++;
12197 + }
12198 + raw += strlen(file_name);
12199 + while (*raw && isspace(*raw)) {
12200 + raw++;
12201 + }
12202 + raw += strlen(md5sum);
12203 + }
12204 +}
12205 +
12206 +int parseVersion(pkg_t *pkg, char *raw)
12207 +{
12208 + char *colon, *eepochcolon;
12209 +#ifdef USE_DEBVERSION
12210 + char *hyphen;
12211 +#endif
12212 + unsigned long epoch;
12213 +
12214 + if (!*raw) {
12215 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12216 + return EINVAL;
12217 + }
12218 +
12219 + if (strncmp(raw, "Version:", 8) == 0) {
12220 + raw += 8;
12221 + }
12222 + while (*raw && isspace(*raw)) {
12223 + raw++;
12224 + }
12225 +
12226 + colon= strchr(raw,':');
12227 + if (colon) {
12228 + epoch= strtoul(raw,&eepochcolon,10);
12229 + if (colon != eepochcolon) {
12230 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12231 + return EINVAL;
12232 + }
12233 + if (!*++colon) {
12234 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12235 + return EINVAL;
12236 + }
12237 + raw= colon;
12238 + pkg->epoch= epoch;
12239 + } else {
12240 + pkg->epoch= 0;
12241 + }
12242 +
12243 + pkg->revision = "";
12244 + pkg->familiar_revision = "";
12245 +
12246 + pkg->version= malloc(strlen(raw)+1);
12247 + if ( pkg->version == NULL ) {
12248 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12249 + return ENOMEM;
12250 + }
12251 + strcpy(pkg->version, raw);
12252 +
12253 +#ifdef USE_DEBVERSION
12254 + hyphen= strrchr(pkg->version,'-');
12255 +
12256 + if (hyphen) {
12257 + *hyphen++= 0;
12258 + if (strncmp("fam", hyphen, 3) == 0) {
12259 + pkg->familiar_revision=hyphen+3;
12260 + hyphen= strrchr(pkg->version,'-');
12261 + if (hyphen) {
12262 + *hyphen++= 0;
12263 + pkg->revision = hyphen;
12264 + }
12265 + } else {
12266 + pkg->revision = hyphen;
12267 + }
12268 + }
12269 +#endif
12270 +
12271 +/*
12272 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12273 + pkg->epoch,
12274 + pkg->version,
12275 + pkg->revision,
12276 + pkg->familiar_revision);
12277 +*/
12278 +
12279 + return 0;
12280 +}
12281 +
12282 +
12283 +/* This code is needed to insert in first position the keyword for the aligning bug */
12284 +
12285 +int alterProvidesLine(char *raw, char *temp)
12286 +{
12287 +
12288 +
12289 + if (!*raw) {
12290 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12291 + return -EINVAL;
12292 + }
12293 +
12294 + if ( temp == NULL ) {
12295 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12296 + return -ENOMEM;
12297 + }
12298 +
12299 + if (strncmp(raw, "Provides:", 9) == 0) {
12300 + raw += 9;
12301 + }
12302 + while (*raw && isspace(*raw)) {
12303 + raw++;
12304 + }
12305 +
12306 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12307 + while (*raw) {
12308 + strncat( temp, raw++, 1);
12309 + }
12310 + return 0;
12311 +
12312 +}
12313 +
12314 +/* Some random thoughts from Carl:
12315 +
12316 + This function could be considerably simplified if we just kept
12317 + an array of all the generic string-valued field names, and looped
12318 + through those looking for a match. Also, these fields could perhaps
12319 + be stored in the package as an array as well, (or, probably better,
12320 + as an nv_pair_list_t).
12321 +
12322 + Fields which require special parsing or storage, (such as Depends:
12323 + and Status:) could be handled as they are now.
12324 +*/
12325 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12326 + to a dependency list. And, since we already have
12327 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12328 + Enhances, perhaps we could generalize all of these and save some
12329 + code duplication.
12330 +*/
12331 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12332 +{
12333 + int reading_conffiles, reading_description;
12334 + int pkg_false_provides=1;
12335 + char ** lines;
12336 + char * provide=NULL;
12337 +
12338 + pkg->src = src;
12339 + pkg->dest = dest;
12340 +
12341 + reading_conffiles = reading_description = 0;
12342 +
12343 + for (lines = *raw; *lines; lines++) {
12344 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12345 + if(isGenericFieldType("Package:", *lines))
12346 + pkg->name = parseGenericFieldType("Package", *lines);
12347 + else if(isGenericFieldType("Architecture:", *lines))
12348 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12349 + else if(isGenericFieldType("Filename:", *lines))
12350 + pkg->filename = parseGenericFieldType("Filename", *lines);
12351 + else if(isGenericFieldType("Section:", *lines))
12352 + pkg->section = parseGenericFieldType("Section", *lines);
12353 + else if(isGenericFieldType("MD5sum:", *lines))
12354 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12355 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12356 + let's parse it either way */
12357 + else if(isGenericFieldType("MD5Sum:", *lines))
12358 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12359 + else if(isGenericFieldType("Size:", *lines))
12360 + pkg->size = parseGenericFieldType("Size", *lines);
12361 + else if(isGenericFieldType("Source:", *lines))
12362 + pkg->source = parseGenericFieldType("Source", *lines);
12363 + else if(isGenericFieldType("Installed-Size:", *lines))
12364 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12365 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12366 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12367 + pkg->installed_time = strtoul(time_str, NULL, 0);
12368 + } else if(isGenericFieldType("Priority:", *lines))
12369 + pkg->priority = parseGenericFieldType("Priority", *lines);
12370 + else if(isGenericFieldType("Essential:", *lines)) {
12371 + char *essential_value;
12372 + essential_value = parseGenericFieldType("Essential", *lines);
12373 + if (strcmp(essential_value, "yes") == 0) {
12374 + pkg->essential = 1;
12375 + }
12376 + free(essential_value);
12377 + }
12378 + else if(isGenericFieldType("Status", *lines))
12379 + parseStatus(pkg, *lines);
12380 + else if(isGenericFieldType("Version", *lines))
12381 + parseVersion(pkg, *lines);
12382 + else if(isGenericFieldType("Maintainer", *lines))
12383 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12384 + else if(isGenericFieldType("Conffiles", *lines)){
12385 + parseConffiles(pkg, *lines);
12386 + reading_conffiles = 1;
12387 + }
12388 + else if(isGenericFieldType("Description", *lines)) {
12389 + pkg->description = parseGenericFieldType("Description", *lines);
12390 + reading_conffiles = 0;
12391 + reading_description = 1;
12392 + }
12393 +
12394 + else if(isGenericFieldType("Provides", *lines)){
12395 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12396 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12397 + if ( alterProvidesLine(*lines,provide) ){
12398 + return EINVAL;
12399 + }
12400 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12401 +/* Let's try to hack a bit here.
12402 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12403 + in alot of other places. We will remove it before writing down the status database */
12404 + pkg_false_provides=0;
12405 + free(provide);
12406 + }
12407 +
12408 + else if(isGenericFieldType("Depends", *lines))
12409 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12410 + else if(isGenericFieldType("Pre-Depends", *lines))
12411 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12412 + else if(isGenericFieldType("Recommends", *lines))
12413 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12414 + else if(isGenericFieldType("Suggests", *lines))
12415 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12416 + /* Abhaya: support for conflicts */
12417 + else if(isGenericFieldType("Conflicts", *lines))
12418 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12419 + else if(isGenericFieldType("Replaces", *lines))
12420 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12421 + else if(line_is_blank(*lines)) {
12422 + lines++;
12423 + break;
12424 + }
12425 + else if(**lines == ' '){
12426 + if(reading_description) {
12427 + /* we already know it's not blank, so the rest of description */
12428 + pkg->description = realloc(pkg->description,
12429 + strlen(pkg->description)
12430 + + 1 + strlen(*lines) + 1);
12431 + strcat(pkg->description, "\n");
12432 + strcat(pkg->description, (*lines));
12433 + }
12434 + else if(reading_conffiles)
12435 + parseConffiles(pkg, *lines);
12436 + }
12437 + }
12438 + *raw = lines;
12439 +/* If the ipk has not a Provides line, we insert our false line */
12440 + if ( pkg_false_provides==1)
12441 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12442 +
12443 + if (pkg->name) {
12444 + return 0;
12445 + } else {
12446 + return EINVAL;
12447 + }
12448 +}
12449 +
12450 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12451 +{
12452 + char ** lines;
12453 +
12454 + for (lines = *raw; *lines; lines++) {
12455 + if(isGenericFieldType("Essential:", *lines)) {
12456 + char *essential_value;
12457 + essential_value = parseGenericFieldType("Essential", *lines);
12458 + if (strcmp(essential_value, "yes") == 0) {
12459 + pkg->essential = 1;
12460 + }
12461 + free(essential_value);
12462 + }
12463 + }
12464 + *raw = lines;
12465 +
12466 + return 0;
12467 +}
12468 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_parse.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.h
12469 --- busybox-1.1.2-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12470 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-05-09 02:06:48.000000000 +0200
12471 @@ -0,0 +1,31 @@
12472 +/* pkg_parse.h - the itsy package management system
12473 +
12474 + Steven M. Ayer
12475 +
12476 + Copyright (C) 2002 Compaq Computer Corporation
12477 +
12478 + This program is free software; you can redistribute it and/or
12479 + modify it under the terms of the GNU General Public License as
12480 + published by the Free Software Foundation; either version 2, or (at
12481 + your option) any later version.
12482 +
12483 + This program is distributed in the hope that it will be useful, but
12484 + WITHOUT ANY WARRANTY; without even the implied warranty of
12485 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12486 + General Public License for more details.
12487 +*/
12488 +
12489 +#ifndef PKG_PARSE_H
12490 +#define PKG_PARSE_H
12491 +
12492 +int isGenericFieldType(char * type, char * line);
12493 +char * parseGenericFieldType(char * type, char * raw);
12494 +void parseStatus(pkg_t *pkg, char * raw);
12495 +int parseVersion(pkg_t *pkg, char *raw);
12496 +char ** parseDependsString(char * raw, int * depends_count);
12497 +int parseVersion(pkg_t *pkg, char *raw);
12498 +void parseConffiles(pkg_t * pkg, char * raw);
12499 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12500 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12501 +
12502 +#endif
12503 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.c
12504 --- busybox-1.1.2-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12505 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-05-09 02:06:48.000000000 +0200
12506 @@ -0,0 +1,43 @@
12507 +/* pkg_src.c - the itsy package management system
12508 +
12509 + Carl D. Worth
12510 +
12511 + Copyright (C) 2001 University of Southern California
12512 +
12513 + This program is free software; you can redistribute it and/or
12514 + modify it under the terms of the GNU General Public License as
12515 + published by the Free Software Foundation; either version 2, or (at
12516 + your option) any later version.
12517 +
12518 + This program is distributed in the hope that it will be useful, but
12519 + WITHOUT ANY WARRANTY; without even the implied warranty of
12520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12521 + General Public License for more details.
12522 +*/
12523 +
12524 +#include "ipkg.h"
12525 +
12526 +#include "pkg_src.h"
12527 +#include "str_util.h"
12528 +
12529 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12530 +{
12531 + src->gzip = gzip;
12532 + src->name = str_dup_safe (name);
12533 + src->value = str_dup_safe (base_url);
12534 + if (extra_data)
12535 + src->extra_data = str_dup_safe (extra_data);
12536 + else
12537 + src->extra_data = NULL;
12538 + return 0;
12539 +}
12540 +
12541 +void pkg_src_deinit(pkg_src_t *src)
12542 +{
12543 + free (src->name);
12544 + free (src->value);
12545 + if (src->extra_data)
12546 + free (src->extra_data);
12547 +}
12548 +
12549 +
12550 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.h
12551 --- busybox-1.1.2-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12552 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-05-09 02:06:48.000000000 +0200
12553 @@ -0,0 +1,34 @@
12554 +/* pkg_src.h - the itsy package management system
12555 +
12556 + Carl D. Worth
12557 +
12558 + Copyright (C) 2001 University of Southern California
12559 +
12560 + This program is free software; you can redistribute it and/or
12561 + modify it under the terms of the GNU General Public License as
12562 + published by the Free Software Foundation; either version 2, or (at
12563 + your option) any later version.
12564 +
12565 + This program is distributed in the hope that it will be useful, but
12566 + WITHOUT ANY WARRANTY; without even the implied warranty of
12567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12568 + General Public License for more details.
12569 +*/
12570 +
12571 +#ifndef PKG_SRC_H
12572 +#define PKG_SRC_H
12573 +
12574 +#include "nv_pair.h"
12575 +
12576 +typedef struct
12577 +{
12578 + char *name;
12579 + char *value;
12580 + char *extra_data;
12581 + int gzip;
12582 +} pkg_src_t;
12583 +
12584 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12585 +void pkg_src_deinit(pkg_src_t *src);
12586 +
12587 +#endif
12588 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.c
12589 --- busybox-1.1.2-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12590 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-05-09 02:06:48.000000000 +0200
12591 @@ -0,0 +1,75 @@
12592 +/* pkg_src_list.c - the itsy package management system
12593 +
12594 + Carl D. Worth
12595 +
12596 + Copyright (C) 2001 University of Southern California
12597 +
12598 + This program is free software; you can redistribute it and/or
12599 + modify it under the terms of the GNU General Public License as
12600 + published by the Free Software Foundation; either version 2, or (at
12601 + your option) any later version.
12602 +
12603 + This program is distributed in the hope that it will be useful, but
12604 + WITHOUT ANY WARRANTY; without even the implied warranty of
12605 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12606 + General Public License for more details.
12607 +*/
12608 +
12609 +#include "ipkg.h"
12610 +
12611 +#include "pkg_src_list.h"
12612 +#include "void_list.h"
12613 +
12614 +int pkg_src_list_init(pkg_src_list_t *list)
12615 +{
12616 + return void_list_init((void_list_t *) list);
12617 +}
12618 +
12619 +void pkg_src_list_deinit(pkg_src_list_t *list)
12620 +{
12621 + pkg_src_list_elt_t *iter;
12622 + pkg_src_t *pkg_src;
12623 +
12624 + for (iter = list->head; iter; iter = iter->next) {
12625 + pkg_src = iter->data;
12626 + pkg_src_deinit(pkg_src);
12627 +
12628 + /* malloced in pkg_src_list_append */
12629 + free(pkg_src);
12630 + iter->data = NULL;
12631 + }
12632 + void_list_deinit((void_list_t *) list);
12633 +}
12634 +
12635 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12636 + const char *name, const char *base_url, const char *extra_data,
12637 + int gzip)
12638 +{
12639 + int err;
12640 +
12641 + /* freed in pkg_src_list_deinit */
12642 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12643 +
12644 + if (pkg_src == NULL) {
12645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12646 + return NULL;
12647 + }
12648 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12649 +
12650 + err = void_list_append((void_list_t *) list, pkg_src);
12651 + if (err) {
12652 + return NULL;
12653 + }
12654 +
12655 + return pkg_src;
12656 +}
12657 +
12658 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12659 +{
12660 + return void_list_push((void_list_t *) list, data);
12661 +}
12662 +
12663 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12664 +{
12665 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12666 +}
12667 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.h
12668 --- busybox-1.1.2-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12669 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-05-09 02:06:48.000000000 +0200
12670 @@ -0,0 +1,57 @@
12671 +/* pkg_src_list.h - the itsy package management system
12672 +
12673 + Carl D. Worth
12674 +
12675 + Copyright (C) 2001 University of Southern California
12676 +
12677 + This program is free software; you can redistribute it and/or
12678 + modify it under the terms of the GNU General Public License as
12679 + published by the Free Software Foundation; either version 2, or (at
12680 + your option) any later version.
12681 +
12682 + This program is distributed in the hope that it will be useful, but
12683 + WITHOUT ANY WARRANTY; without even the implied warranty of
12684 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12685 + General Public License for more details.
12686 +*/
12687 +
12688 +#ifndef PKG_SRC_LIST_H
12689 +#define PKG_SRC_LIST_H
12690 +
12691 +#include "pkg_src.h"
12692 +
12693 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12694 +struct pkg_src_list_elt
12695 +{
12696 + pkg_src_list_elt_t *next;
12697 + pkg_src_t *data;
12698 +};
12699 +
12700 +typedef struct pkg_src_list pkg_src_list_t;
12701 +struct pkg_src_list
12702 +{
12703 + pkg_src_list_elt_t pre_head;
12704 + pkg_src_list_elt_t *head;
12705 + pkg_src_list_elt_t *tail;
12706 +};
12707 +
12708 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12709 +{
12710 + if (list->head == NULL)
12711 + return 1;
12712 + else
12713 + return 0;
12714 +}
12715 +
12716 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12717 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12718 +
12719 +int pkg_src_list_init(pkg_src_list_t *list);
12720 +void pkg_src_list_deinit(pkg_src_list_t *list);
12721 +
12722 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
12723 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12724 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12725 +
12726 +#endif
12727 +
12728 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_vec.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.c
12729 --- busybox-1.1.2-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12730 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-05-09 02:12:05.000000000 +0200
12731 @@ -0,0 +1,230 @@
12732 +/* pkg_vec.c - the itsy package management system
12733 +
12734 + Steven M. Ayer
12735 +
12736 + Copyright (C) 2002 Compaq Computer Corporation
12737 +
12738 + This program is free software; you can redistribute it and/or
12739 + modify it under the terms of the GNU General Public License as
12740 + published by the Free Software Foundation; either version 2, or (at
12741 + your option) any later version.
12742 +
12743 + This program is distributed in the hope that it will be useful, but
12744 + WITHOUT ANY WARRANTY; without even the implied warranty of
12745 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12746 + General Public License for more details.
12747 +*/
12748 +
12749 +#include <stdlib.h>
12750 +#include <fnmatch.h>
12751 +#include "xregex.h"
12752 +#include "ipkg.h"
12753 +#include "pkg.h"
12754 +
12755 +pkg_vec_t * pkg_vec_alloc(void)
12756 +{
12757 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12758 + if (!vec) {
12759 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12760 + return NULL;
12761 + }
12762 + vec->pkgs = NULL;
12763 + vec->len = 0;
12764 +
12765 + return vec;
12766 +}
12767 +
12768 +void pkg_vec_free(pkg_vec_t *vec)
12769 +{
12770 + free(vec->pkgs);
12771 + free(vec);
12772 +}
12773 +
12774 +/*
12775 + * assumption: all names in a vector are identical
12776 + * assumption: all version strings are trimmed,
12777 + * so identical versions have identical version strings,
12778 + * implying identical packages; let's marry these
12779 + */
12780 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12781 +{
12782 + int i;
12783 + int found = 0;
12784 +
12785 + /* look for a duplicate pkg by name, version, and architecture */
12786 + for (i = 0; i < vec->len; i++){
12787 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12788 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12789 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12790 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12791 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12792 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12793 + found = 1;
12794 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12795 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12796 + break;
12797 + }
12798 + }
12799 +
12800 + /* we didn't find one, add it */
12801 + if (!found){
12802 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12803 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12804 +
12805 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12806 + vec->pkgs[vec->len] = pkg;
12807 + vec->len++;
12808 + return pkg;
12809 + }
12810 + /* update the one that we have */
12811 + else {
12812 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12813 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12814 + if (set_status) {
12815 + /* this is from the status file, so need to merge with existing database */
12816 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12817 + pkg_merge(vec->pkgs[i], pkg, set_status);
12818 + /* XXX: CLEANUP: It's not so polite to free something here
12819 + that was passed in from above. */
12820 + pkg_deinit(pkg);
12821 + free(pkg);
12822 + } else {
12823 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12824 + /* just overwrite the old one */
12825 + pkg_deinit(vec->pkgs[i]);
12826 + free(vec->pkgs[i]);
12827 + vec->pkgs[i] = pkg;
12828 + }
12829 + return vec->pkgs[i];
12830 + }
12831 +}
12832 +
12833 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12834 +{
12835 + int i;
12836 + int found = 0;
12837 +
12838 + /* look for a duplicate pkg by name, version, and architecture */
12839 + for (i = 0; i < vec->len; i++)
12840 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12841 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12842 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12843 + found = 1;
12844 + break;
12845 + }
12846 +
12847 + /* we didn't find one, add it */
12848 + if(!found){
12849 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12850 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12851 + vec->len++;
12852 + }
12853 +}
12854 +
12855 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12856 +{
12857 + int i;
12858 + for (i = 0; i < vec->len; i++)
12859 + if (vec->pkgs[i] == apkg)
12860 + return 1;
12861 + return 0;
12862 +}
12863 +
12864 +typedef int (*compare_fcn_t)(const void *, const void *);
12865 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12866 +{
12867 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12868 +}
12869 +
12870 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12871 +{
12872 + int npkgs = vec->len;
12873 + int i;
12874 + for (i = 0; i < npkgs; i++) {
12875 + pkg_t *pkg = vec->pkgs[i];
12876 + pkg->state_flag &= ~SF_MARKED;
12877 + }
12878 + return 0;
12879 +}
12880 +
12881 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12882 +{
12883 + int matching_count = 0;
12884 + pkg_t **pkgs = vec->pkgs;
12885 + int npkgs = vec->len;
12886 + int i;
12887 + for (i = 0; i < npkgs; i++) {
12888 + pkg_t *pkg = pkgs[i];
12889 + if (fnmatch(pattern, pkg->name, 0)==0) {
12890 + pkg->state_flag |= SF_MARKED;
12891 + matching_count++;
12892 + }
12893 + }
12894 + return matching_count;
12895 +}
12896 +
12897 +
12898 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12899 +{
12900 + abstract_pkg_vec_t * vec ;
12901 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12902 + if (!vec) {
12903 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12904 + return NULL;
12905 + }
12906 + vec->pkgs = NULL;
12907 + vec->len = 0;
12908 +
12909 + return vec;
12910 +}
12911 +
12912 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12913 +{
12914 + free(vec->pkgs);
12915 + free(vec);
12916 +}
12917 +
12918 +/*
12919 + * assumption: all names in a vector are unique
12920 + */
12921 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12922 +{
12923 + int i;
12924 +
12925 + /* look for a duplicate pkg by name */
12926 + for(i = 0; i < vec->len; i++)
12927 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12928 + break;
12929 +
12930 + /* we didn't find one, add it */
12931 + if(i == vec->len){
12932 + vec->pkgs =
12933 + (abstract_pkg_t **)
12934 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12935 + vec->pkgs[vec->len] = pkg;
12936 + vec->len++;
12937 + }
12938 +}
12939 +
12940 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12941 +{
12942 + if (vec->len > i)
12943 + return vec->pkgs[i];
12944 + else
12945 + return NULL;
12946 +}
12947 +
12948 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12949 +{
12950 + int i;
12951 + for (i = 0; i < vec->len; i++)
12952 + if (vec->pkgs[i] == apkg)
12953 + return 1;
12954 + return 0;
12955 +}
12956 +
12957 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12958 +{
12959 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12960 +}
12961 +
12962 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_vec.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.h
12963 --- busybox-1.1.2-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12964 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-05-09 02:06:48.000000000 +0200
12965 @@ -0,0 +1,62 @@
12966 +/* pkg_vec.h - the itsy package management system
12967 +
12968 + Steven M. Ayer
12969 +
12970 + Copyright (C) 2002 Compaq Computer Corporation
12971 +
12972 + This program is free software; you can redistribute it and/or
12973 + modify it under the terms of the GNU General Public License as
12974 + published by the Free Software Foundation; either version 2, or (at
12975 + your option) any later version.
12976 +
12977 + This program is distributed in the hope that it will be useful, but
12978 + WITHOUT ANY WARRANTY; without even the implied warranty of
12979 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12980 + General Public License for more details.
12981 +*/
12982 +
12983 +#ifndef PKG_VEC_H
12984 +#define PKG_VEC_H
12985 +
12986 +typedef struct pkg pkg_t;
12987 +typedef struct abstract_pkg abstract_pkg_t;
12988 +
12989 +struct pkg_vec
12990 +{
12991 + pkg_t **pkgs;
12992 + int len;
12993 +};
12994 +typedef struct pkg_vec pkg_vec_t;
12995 +
12996 +struct abstract_pkg_vec
12997 +{
12998 + abstract_pkg_t **pkgs;
12999 + int len;
13000 +};
13001 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
13002 +
13003 +
13004 +pkg_vec_t * pkg_vec_alloc(void);
13005 +void pkg_vec_free(pkg_vec_t *vec);
13006 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
13007 +
13008 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
13009 +/* pkg_vec_insert_merge: might munge pkg.
13010 +* returns the pkg that is in the pkg graph */
13011 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
13012 +/* this one never munges pkg */
13013 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
13014 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
13015 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
13016 +
13017 +int pkg_vec_clear_marks(pkg_vec_t *vec);
13018 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
13019 +
13020 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
13021 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
13022 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
13023 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13024 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13025 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13026 +#endif
13027 +
13028 diff -ruN busybox-1.1.2-orig/archival/libipkg/sprintf_alloc.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h
13029 --- busybox-1.1.2-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13030 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-05-09 02:06:48.000000000 +0200
13031 @@ -0,0 +1,25 @@
13032 +/* sprintf_alloca.c -- like sprintf with memory allocation
13033 +
13034 + Carl D. Worth
13035 +
13036 + Copyright (C) 2001 University of Southern California
13037 +
13038 + This program is free software; you can redistribute it and/or modify
13039 + it under the terms of the GNU General Public License as published by
13040 + the Free Software Foundation; either version 2, or (at your option)
13041 + any later version.
13042 +
13043 + This program is distributed in the hope that it will be useful,
13044 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13045 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13046 + GNU General Public License for more details.
13047 +*/
13048 +
13049 +#ifndef SPRINTF_ALLOC_H
13050 +#define SPRINTF_ALLOC_H
13051 +
13052 +#include "libbb.h"
13053 +
13054 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13055 +
13056 +#endif
13057 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.c
13058 --- busybox-1.1.2-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13059 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.c 2006-05-09 02:06:48.000000000 +0200
13060 @@ -0,0 +1,76 @@
13061 +/* str_list.c - the itsy package management system
13062 +
13063 + Carl D. Worth
13064 +
13065 + Copyright (C) 2001 University of Southern California
13066 +
13067 + This program is free software; you can redistribute it and/or
13068 + modify it under the terms of the GNU General Public License as
13069 + published by the Free Software Foundation; either version 2, or (at
13070 + your option) any later version.
13071 +
13072 + This program is distributed in the hope that it will be useful, but
13073 + WITHOUT ANY WARRANTY; without even the implied warranty of
13074 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13075 + General Public License for more details.
13076 +*/
13077 +
13078 +#include "ipkg.h"
13079 +
13080 +#include "str_list.h"
13081 +
13082 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13083 +{
13084 + return void_list_elt_init((void_list_elt_t *) elt, data);
13085 +}
13086 +
13087 +void str_list_elt_deinit(str_list_elt_t *elt)
13088 +{
13089 + void_list_elt_deinit((void_list_elt_t *) elt);
13090 +}
13091 +
13092 +str_list_t *str_list_alloc()
13093 +{
13094 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13095 + if (list)
13096 + str_list_init(list);
13097 + return list;
13098 +}
13099 +
13100 +int str_list_init(str_list_t *list)
13101 +{
13102 + return void_list_init((void_list_t *) list);
13103 +}
13104 +
13105 +void str_list_deinit(str_list_t *list)
13106 +{
13107 + void_list_deinit((void_list_t *) list);
13108 +}
13109 +
13110 +int str_list_append(str_list_t *list, char *data)
13111 +{
13112 + return void_list_append((void_list_t *) list, data);
13113 +}
13114 +
13115 +int str_list_push(str_list_t *list, char *data)
13116 +{
13117 + return void_list_push((void_list_t *) list, data);
13118 +}
13119 +
13120 +str_list_elt_t *str_list_pop(str_list_t *list)
13121 +{
13122 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13123 +}
13124 +
13125 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13126 +{
13127 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13128 + (void_list_elt_t **) iter);
13129 +}
13130 +
13131 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13132 +{
13133 + return (char *)void_list_remove_elt((void_list_t *) list,
13134 + (void *)target_str,
13135 + (void_list_cmp_t)strcmp);
13136 +}
13137 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.h
13138 --- busybox-1.1.2-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13139 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.h 2006-05-09 02:06:48.000000000 +0200
13140 @@ -0,0 +1,51 @@
13141 +/* str_list.h - the itsy package management system
13142 +
13143 + Carl D. Worth
13144 +
13145 + Copyright (C) 2001 University of Southern California
13146 +
13147 + This program is free software; you can redistribute it and/or
13148 + modify it under the terms of the GNU General Public License as
13149 + published by the Free Software Foundation; either version 2, or (at
13150 + your option) any later version.
13151 +
13152 + This program is distributed in the hope that it will be useful, but
13153 + WITHOUT ANY WARRANTY; without even the implied warranty of
13154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13155 + General Public License for more details.
13156 +*/
13157 +
13158 +#ifndef STR_LIST_H
13159 +#define STR_LIST_H
13160 +
13161 +#include "void_list.h"
13162 +
13163 +typedef struct str_list_elt str_list_elt_t;
13164 +struct str_list_elt
13165 +{
13166 + str_list_elt_t *next;
13167 + char *data;
13168 +};
13169 +
13170 +typedef struct xstr_list str_list_t;
13171 +struct xstr_list
13172 +{
13173 + str_list_elt_t pre_head;
13174 + str_list_elt_t *head;
13175 + str_list_elt_t *tail;
13176 +};
13177 +
13178 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13179 +void str_list_elt_deinit(str_list_elt_t *elt);
13180 +
13181 +str_list_t *str_list_alloc(void);
13182 +int str_list_init(str_list_t *list);
13183 +void str_list_deinit(str_list_t *list);
13184 +
13185 +int str_list_append(str_list_t *list, char *data);
13186 +int str_list_push(str_list_t *list, char *data);
13187 +str_list_elt_t *str_list_pop(str_list_t *list);
13188 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13189 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13190 +
13191 +#endif
13192 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_util.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.c
13193 --- busybox-1.1.2-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13194 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.c 2006-05-09 02:06:48.000000000 +0200
13195 @@ -0,0 +1,73 @@
13196 +/* str_utils.c - the itsy package management system
13197 +
13198 + Carl D. Worth
13199 +
13200 + Copyright (C) 2001 University of Southern California
13201 +
13202 + This program is free software; you can redistribute it and/or
13203 + modify it under the terms of the GNU General Public License as
13204 + published by the Free Software Foundation; either version 2, or (at
13205 + your option) any later version.
13206 +
13207 + This program is distributed in the hope that it will be useful, but
13208 + WITHOUT ANY WARRANTY; without even the implied warranty of
13209 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13210 + General Public License for more details.
13211 +*/
13212 +
13213 +#include "ipkg.h"
13214 +
13215 +int str_starts_with(const char *str, const char *prefix)
13216 +{
13217 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13218 +}
13219 +
13220 +int str_ends_with(const char *str, const char *suffix)
13221 +{
13222 + int suffix_len;
13223 + int str_len;
13224 +
13225 + str_len = strlen(str);
13226 + suffix_len = strlen(suffix);
13227 +
13228 + if (str_len < suffix_len) {
13229 + return 0;
13230 + }
13231 +
13232 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13233 +}
13234 +
13235 +int str_chomp(char *str)
13236 +{
13237 + if (str[strlen(str) - 1] == '\n') {
13238 + str[strlen(str) - 1] = '\0';
13239 + return 1;
13240 + }
13241 + return 0;
13242 +}
13243 +
13244 +int str_tolower(char *str)
13245 +{
13246 + while (*str) {
13247 + *str = tolower(*str);
13248 + str++;
13249 + }
13250 +
13251 + return 0;
13252 +}
13253 +
13254 +int str_toupper(char *str)
13255 +{
13256 + while (*str) {
13257 + *str = toupper(*str);
13258 + str++;
13259 + }
13260 +
13261 + return 0;
13262 +}
13263 +
13264 +char *str_dup_safe(const char *str)
13265 +{
13266 + return str ? strdup(str) : NULL;
13267 +}
13268 +
13269 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_util.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.h
13270 --- busybox-1.1.2-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13271 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.h 2006-05-09 02:06:48.000000000 +0200
13272 @@ -0,0 +1,28 @@
13273 +/* str_utils.h - the itsy package management system
13274 +
13275 + Carl D. Worth
13276 +
13277 + Copyright (C) 2001 University of Southern California
13278 +
13279 + This program is free software; you can redistribute it and/or
13280 + modify it under the terms of the GNU General Public License as
13281 + published by the Free Software Foundation; either version 2, or (at
13282 + your option) any later version.
13283 +
13284 + This program is distributed in the hope that it will be useful, but
13285 + WITHOUT ANY WARRANTY; without even the implied warranty of
13286 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13287 + General Public License for more details.
13288 +*/
13289 +
13290 +#ifndef STR_UTILS_H
13291 +#define STR_UTILS_H
13292 +
13293 +int str_starts_with(const char *str, const char *prefix);
13294 +int str_ends_with(const char *str, const char *suffix);
13295 +int str_chomp(char *str);
13296 +int str_tolower(char *str);
13297 +int str_toupper(char *str);
13298 +char *str_dup_safe(const char *str);
13299 +
13300 +#endif
13301 diff -ruN busybox-1.1.2-orig/archival/libipkg/user.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.c
13302 --- busybox-1.1.2-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13303 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.c 2006-05-09 02:06:48.000000000 +0200
13304 @@ -0,0 +1,58 @@
13305 +/* user.c - the itsy package management system
13306 +
13307 + Jamey Hicks
13308 +
13309 + Copyright (C) 2002 Hewlett Packard Company
13310 + Copyright (C) 2001 University of Southern California
13311 +
13312 + This program is free software; you can redistribute it and/or
13313 + modify it under the terms of the GNU General Public License as
13314 + published by the Free Software Foundation; either version 2, or (at
13315 + your option) any later version.
13316 +
13317 + This program is distributed in the hope that it will be useful, but
13318 + WITHOUT ANY WARRANTY; without even the implied warranty of
13319 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13320 + General Public License for more details.
13321 +*/
13322 +
13323 +#include <stdio.h>
13324 +#include <stdarg.h>
13325 +#include "file_util.h"
13326 +#include "str_util.h"
13327 +#ifdef IPKG_LIB
13328 +#include "libipkg.h"
13329 +#endif
13330 +
13331 +
13332 +#ifdef IPKG_LIB
13333 +static char *question = NULL;
13334 +static int question_len = 255;
13335 +#endif
13336 +char *get_user_response(const char *format, ...)
13337 +{
13338 + int len = question_len;
13339 + va_list ap;
13340 + char *response;
13341 + va_start(ap, format);
13342 +
13343 +#ifndef IPKG_LIB
13344 + vprintf(format, ap);
13345 + do {
13346 + response = file_read_line_alloc(stdin);
13347 + } while (response == NULL);
13348 +#else
13349 + do {
13350 + if (question == NULL || len > question_len) {
13351 + question = realloc(question, len + 1);
13352 + question_len = len;
13353 + }
13354 + len = vsnprintf(question,question_len,format,ap);
13355 + } while (len > question_len);
13356 + response = strdup(ipkg_cb_response(question));
13357 +#endif
13358 + str_chomp(response);
13359 + str_tolower(response);
13360 +
13361 + return response;
13362 +}
13363 diff -ruN busybox-1.1.2-orig/archival/libipkg/user.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.h
13364 --- busybox-1.1.2-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13365 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.h 2006-05-09 02:06:48.000000000 +0200
13366 @@ -0,0 +1,23 @@
13367 +/* user.c - the itsy package management system
13368 +
13369 + Jamey Hicks
13370 +
13371 + Copyright (C) 2002 Hewlett Packard Company
13372 + Copyright (C) 2001 University of Southern California
13373 +
13374 + This program is free software; you can redistribute it and/or
13375 + modify it under the terms of the GNU General Public License as
13376 + published by the Free Software Foundation; either version 2, or (at
13377 + your option) any later version.
13378 +
13379 + This program is distributed in the hope that it will be useful, but
13380 + WITHOUT ANY WARRANTY; without even the implied warranty of
13381 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13382 + General Public License for more details.
13383 +*/
13384 +
13385 +#include <stdio.h>
13386 +#include <stdarg.h>
13387 +
13388 +char *get_user_response(const char *format, ...);
13389 +
13390 diff -ruN busybox-1.1.2-orig/archival/libipkg/void_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.c
13391 --- busybox-1.1.2-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13392 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.c 2006-05-09 02:06:48.000000000 +0200
13393 @@ -0,0 +1,194 @@
13394 +/* void_list.c - the itsy package management system
13395 +
13396 + Carl D. Worth
13397 +
13398 + Copyright (C) 2001 University of Southern California
13399 +
13400 + This program is free software; you can redistribute it and/or
13401 + modify it under the terms of the GNU General Public License as
13402 + published by the Free Software Foundation; either version 2, or (at
13403 + your option) any later version.
13404 +
13405 + This program is distributed in the hope that it will be useful, but
13406 + WITHOUT ANY WARRANTY; without even the implied warranty of
13407 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13408 + General Public License for more details.
13409 +*/
13410 +
13411 +#include "ipkg.h"
13412 +#include <errno.h>
13413 +
13414 +#include "void_list.h"
13415 +
13416 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13417 +{
13418 + elt->next = NULL;
13419 + elt->data = data;
13420 +
13421 + return 0;
13422 +}
13423 +
13424 +void void_list_elt_deinit(void_list_elt_t *elt)
13425 +{
13426 + void_list_elt_init(elt, NULL);
13427 +}
13428 +
13429 +int void_list_init(void_list_t *list)
13430 +{
13431 + void_list_elt_init(&list->pre_head, NULL);
13432 + list->head = NULL;
13433 + list->pre_head.next = list->head;
13434 + list->tail = NULL;
13435 +
13436 + return 0;
13437 +}
13438 +
13439 +void void_list_deinit(void_list_t *list)
13440 +{
13441 + void_list_elt_t *elt;
13442 +
13443 + while (list->head) {
13444 + elt = void_list_pop(list);
13445 + void_list_elt_deinit(elt);
13446 + /* malloced in void_list_append */
13447 + free(elt);
13448 + }
13449 +}
13450 +
13451 +int void_list_append(void_list_t *list, void *data)
13452 +{
13453 + void_list_elt_t *elt;
13454 +
13455 + /* freed in void_list_deinit */
13456 + elt = malloc(sizeof(void_list_elt_t));
13457 + if (elt == NULL) {
13458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13459 + return ENOMEM;
13460 + }
13461 +
13462 + void_list_elt_init(elt, data);
13463 +
13464 + if (list->tail) {
13465 + list->tail->next = elt;
13466 + list->tail = elt;
13467 + } else {
13468 + list->head = elt;
13469 + list->pre_head.next = list->head;
13470 + list->tail = elt;
13471 + }
13472 +
13473 + return 0;
13474 +}
13475 +
13476 +int void_list_push(void_list_t *list, void *data)
13477 +{
13478 + void_list_elt_t *elt;
13479 +
13480 + elt = malloc(sizeof(void_list_elt_t));
13481 + if (elt == NULL) {
13482 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13483 + return ENOMEM;
13484 + }
13485 +
13486 + void_list_elt_init(elt, data);
13487 +
13488 + elt->next = list->head;
13489 + list->head->next = elt;
13490 + if (list->tail == NULL) {
13491 + list->tail = list->head;
13492 + }
13493 +
13494 + return 0;
13495 +}
13496 +
13497 +void_list_elt_t *void_list_pop(void_list_t *list)
13498 +{
13499 + void_list_elt_t *elt;
13500 +
13501 + elt = list->head;
13502 +
13503 + if (list->head) {
13504 + list->head = list->head->next;
13505 + list->pre_head.next = list->head;
13506 + if (list->head == NULL) {
13507 + list->tail = NULL;
13508 + }
13509 + }
13510 +
13511 + return elt;
13512 +}
13513 +
13514 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13515 +{
13516 + void_list_elt_t *prior;
13517 + void_list_elt_t *old_elt;
13518 + void *old_data;
13519 +
13520 + old_elt = *iter;
13521 + old_data = old_elt->data;
13522 +
13523 + if (old_elt == list->head) {
13524 + prior = &list->pre_head;
13525 + void_list_pop(list);
13526 + } else {
13527 + for (prior = list->head; prior; prior = prior->next) {
13528 + if (prior->next == old_elt) {
13529 + break;
13530 + }
13531 + }
13532 + if (prior == NULL || prior->next != old_elt) {
13533 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13534 + return NULL;
13535 + }
13536 + prior->next = old_elt->next;
13537 +
13538 + if (old_elt == list->tail) {
13539 + list->tail = prior;
13540 + }
13541 + }
13542 +
13543 + void_list_elt_deinit(old_elt);
13544 + *iter = prior;
13545 +
13546 + return old_data;
13547 +}
13548 +
13549 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13550 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13551 +{
13552 + void_list_elt_t *prior;
13553 + void_list_elt_t *old_elt = NULL;
13554 + void *old_data = NULL;
13555 +
13556 + /* first element */
13557 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13558 + old_elt = list->head;
13559 + old_data = list->head->data;
13560 + void_list_pop(list);
13561 + } else {
13562 + int found = 0;
13563 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13564 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13565 + old_elt = prior->next;
13566 + old_data = old_elt->data;
13567 + found = 1;
13568 + break;
13569 + }
13570 + }
13571 + if (!found) {
13572 + return NULL;
13573 + }
13574 + prior->next = old_elt->next;
13575 +
13576 + if (old_elt == list->tail) {
13577 + list->tail = prior;
13578 + }
13579 + }
13580 + if (old_elt)
13581 + void_list_elt_deinit(old_elt);
13582 +
13583 + if (old_data)
13584 + return old_data;
13585 + else
13586 + return NULL;
13587 +}
13588 diff -ruN busybox-1.1.2-orig/archival/libipkg/void_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.h
13589 --- busybox-1.1.2-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13590 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.h 2006-05-09 02:06:48.000000000 +0200
13591 @@ -0,0 +1,59 @@
13592 +/* void_list.h - the itsy package management system
13593 +
13594 + Carl D. Worth
13595 +
13596 + Copyright (C) 2001 University of Southern California
13597 +
13598 + This program is free software; you can redistribute it and/or
13599 + modify it under the terms of the GNU General Public License as
13600 + published by the Free Software Foundation; either version 2, or (at
13601 + your option) any later version.
13602 +
13603 + This program is distributed in the hope that it will be useful, but
13604 + WITHOUT ANY WARRANTY; without even the implied warranty of
13605 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13606 + General Public License for more details.
13607 +*/
13608 +
13609 +#ifndef VOID_LIST_H
13610 +#define VOID_LIST_H
13611 +
13612 +typedef struct void_list_elt void_list_elt_t;
13613 +struct void_list_elt
13614 +{
13615 + void_list_elt_t *next;
13616 + void *data;
13617 +};
13618 +
13619 +typedef struct void_list void_list_t;
13620 +struct void_list
13621 +{
13622 + void_list_elt_t pre_head;
13623 + void_list_elt_t *head;
13624 + void_list_elt_t *tail;
13625 +};
13626 +
13627 +static inline int void_list_empty(void_list_t *list)
13628 +{
13629 + if (list->head == NULL)
13630 + return 1;
13631 + else
13632 + return 0;
13633 +}
13634 +
13635 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13636 +void void_list_elt_deinit(void_list_elt_t *elt);
13637 +
13638 +int void_list_init(void_list_t *list);
13639 +void void_list_deinit(void_list_t *list);
13640 +
13641 +int void_list_append(void_list_t *list, void *data);
13642 +int void_list_push(void_list_t *list, void *data);
13643 +void_list_elt_t *void_list_pop(void_list_t *list);
13644 +
13645 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13646 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13647 +typedef int (*void_list_cmp_t)(const void *, const void *);
13648 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13649 +
13650 +#endif
13651 diff -ruN busybox-1.1.2-orig/archival/libipkg/xsystem.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.c
13652 --- busybox-1.1.2-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13653 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-05-09 02:06:48.000000000 +0200
13654 @@ -0,0 +1,64 @@
13655 +/* xsystem.c - system(3) with error messages
13656 +
13657 + Carl D. Worth
13658 +
13659 + Copyright (C) 2001 University of Southern California
13660 +
13661 + This program is free software; you can redistribute it and/or
13662 + modify it under the terms of the GNU General Public License as
13663 + published by the Free Software Foundation; either version 2, or (at
13664 + your option) any later version.
13665 +
13666 + This program is distributed in the hope that it will be useful, but
13667 + WITHOUT ANY WARRANTY; without even the implied warranty of
13668 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13669 + General Public License for more details.
13670 +*/
13671 +
13672 +#include "ipkg.h"
13673 +#include <sys/wait.h>
13674 +
13675 +#include "xsystem.h"
13676 +
13677 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13678 + really need the /bin/sh invocation which takes resources and
13679 + introduces security problems. I should switch all of this to a sort
13680 + of execl() or execv() interface/implementation.
13681 +*/
13682 +
13683 +/* Like system(3), but with error messages printed if the fork fails
13684 + or if the child process dies due to an uncaught signal. Also, the
13685 + return value is a bit simpler:
13686 +
13687 + -1 if there was any problem
13688 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13689 + as defined in <sys/wait.h>.
13690 +*/
13691 +int xsystem(const char *cmd)
13692 +{
13693 + int err;
13694 +
13695 + err = system(cmd);
13696 +
13697 + if (err == -1) {
13698 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13699 + __FUNCTION__, cmd);
13700 + return -1;
13701 + }
13702 +
13703 + if (WIFSIGNALED(err)) {
13704 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13705 + __FUNCTION__, WTERMSIG(err), cmd);
13706 + return -1;
13707 + }
13708 +
13709 + if (WIFEXITED(err)) {
13710 + /* Normal child exit */
13711 + return WEXITSTATUS(err);
13712 + }
13713 +
13714 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13715 + __FUNCTION__, err);
13716 + return -1;
13717 +}
13718 +
13719 diff -ruN busybox-1.1.2-orig/archival/libipkg/xsystem.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.h
13720 --- busybox-1.1.2-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13721 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-05-09 02:06:48.000000000 +0200
13722 @@ -0,0 +1,34 @@
13723 +/* xsystem.h - system(3) with error messages
13724 +
13725 + Carl D. Worth
13726 +
13727 + Copyright (C) 2001 University of Southern California
13728 +
13729 + This program is free software; you can redistribute it and/or
13730 + modify it under the terms of the GNU General Public License as
13731 + published by the Free Software Foundation; either version 2, or (at
13732 + your option) any later version.
13733 +
13734 + This program is distributed in the hope that it will be useful, but
13735 + WITHOUT ANY WARRANTY; without even the implied warranty of
13736 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13737 + General Public License for more details.
13738 +*/
13739 +
13740 +#ifndef XSYSTEM_H
13741 +#define XSYSTEM_H
13742 +
13743 +#include <stdlib.h>
13744 +
13745 +/* Like system(3), but with error messages printed if the fork fails
13746 + or if the child process dies due to an uncaught signal. Also, the
13747 + return value is a bit simpler:
13748 +
13749 + -1 if there was any problem
13750 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13751 + as defined in <sys/wait.h>.
13752 +*/
13753 +int xsystem(const char *cmd);
13754 +
13755 +#endif
13756 +
13757 diff -ruN busybox-1.1.2-orig/archival/libunarchive/Makefile.in busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/Makefile.in
13758 --- busybox-1.1.2-orig/archival/libunarchive/Makefile.in 2006-03-22 22:16:20.000000000 +0100
13759 +++ busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-05-09 02:06:48.000000000 +0200
13760 @@ -58,6 +58,7 @@
13761 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13762 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13763 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13764 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13765 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13766 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13767 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13768 diff -ruN busybox-1.1.2-orig/archival/libunarchive/data_extract_all.c busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/data_extract_all.c
13769 --- busybox-1.1.2-orig/archival/libunarchive/data_extract_all.c 2006-03-22 22:16:20.000000000 +0100
13770 +++ busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-05-09 02:06:48.000000000 +0200
13771 @@ -126,3 +126,17 @@
13772 utime(file_header->name, &t);
13773 }
13774 }
13775 +
13776 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13777 +{
13778 + char *name_ptr = archive_handle->file_header->name;
13779 +
13780 + name_ptr += strspn(name_ptr, "./");
13781 + if (name_ptr[0] != '\0') {
13782 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13783 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13784 + strcat(archive_handle->file_header->name, name_ptr);
13785 + data_extract_all(archive_handle);
13786 + }
13787 +}
13788 +
13789 diff -ruN busybox-1.1.2-orig/include/applets.h busybox-1.1.2+ipkg-0.99.162/include/applets.h
13790 --- busybox-1.1.2-orig/include/applets.h 2006-03-22 22:16:24.000000000 +0100
13791 +++ busybox-1.1.2+ipkg-0.99.162/include/applets.h 2006-05-09 02:06:48.000000000 +0200
13792 @@ -149,6 +149,7 @@
13793 USE_IPCALC(APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13794 USE_IPCRM(APPLET(ipcrm, ipcrm_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13795 USE_IPCS(APPLET(ipcs, ipcs_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13796 +USE_IPKG(APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13797 USE_IPLINK(APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13798 USE_IPROUTE(APPLET(iproute, iproute_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13799 USE_IPTUNNEL(APPLET(iptunnel, iptunnel_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13800 diff -ruN busybox-1.1.2-orig/include/unarchive.h busybox-1.1.2+ipkg-0.99.162/include/unarchive.h
13801 --- busybox-1.1.2-orig/include/unarchive.h 2006-03-22 22:16:24.000000000 +0100
13802 +++ busybox-1.1.2+ipkg-0.99.162/include/unarchive.h 2006-05-09 02:06:48.000000000 +0200
13803 @@ -74,6 +74,7 @@
13804
13805 extern void data_skip(archive_handle_t *archive_handle);
13806 extern void data_extract_all(archive_handle_t *archive_handle);
13807 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13808 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13809 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13810
13811 diff -ruN busybox-1.1.2-orig/include/usage.h busybox-1.1.2+ipkg-0.99.162/include/usage.h
13812 --- busybox-1.1.2-orig/include/usage.h 2006-03-22 22:16:24.000000000 +0100
13813 +++ busybox-1.1.2+ipkg-0.99.162/include/usage.h 2006-05-09 02:06:48.000000000 +0200
13814 @@ -1013,6 +1013,82 @@
13815 "$ ls -la /tmp/busybox*\n" \
13816 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13817
13818 +#define ipkg_trivial_usage \
13819 + "[options]... sub-command [arguments]..."
13820 +#define ipkg_full_usage \
13821 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13822 + "\n" \
13823 + "Sub-commands:\n" \
13824 + "\nPackage Manipulation:\n" \
13825 + "\tupdate Update list of available packages\n" \
13826 + "\tupgrade Upgrade all installed packages to latest version\n" \
13827 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13828 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13829 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13830 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13831 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13832 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13833 + "\n" \
13834 + "Informational Commands:\n" \
13835 + "\tlist List available packages and descriptions\n" \
13836 + "\tlist_installed List all and only the installed packages and description \n" \
13837 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13838 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13839 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13840 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13841 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13842 + "\tcompare_versions <v1> <op> <v2>\n" \
13843 + "\t compare versions using <= < > >= = << >>\n" \
13844 + "\tprint_architecture prints the architecture.\n" \
13845 + "\tprint_installation_architecture\n" \
13846 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13847 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13848 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13849 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13850 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13851 + "\t prints the installation architecture.\n" \
13852 + "\n" \
13853 + "\nOptions:\n" \
13854 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13855 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13856 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13857 + "\t 0 errors only\n" \
13858 + "\t 1 normal messages (default)\n" \
13859 + "\t 2 informative messages\n" \
13860 + "\t 3 debug output\n" \
13861 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13862 + "\t-conf <conf_file> Default configuration file location\n" \
13863 + " is /etc/ipkg.conf\n" \
13864 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13865 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13866 + " <dest_name> should be a defined dest name from\n" \
13867 + " the configuration file, (but can also be a\n" \
13868 + " directory name in a pinch).\n" \
13869 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13870 + "\t-offline <offline_root> offline installation of packages.\n" \
13871 + "\t-verbose_wget more wget messages\n" \
13872 + "\n" \
13873 + "Force Options (use when ipkg is too smart for its own good):\n" \
13874 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13875 + "\t Install/remove package in spite of failed dependences\n" \
13876 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13877 + " (no prompts). Note that this will not prevent\n" \
13878 + " package installation scripts from prompting.\n" \
13879 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13880 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13881 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13882 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13883 + "\t-noaction No action -- test only\n" \
13884 + "\t-nodeps Do not follow dependences\n" \
13885 + "\t-force-removal-of-dependent-packages\n" \
13886 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13887 + "\t-test No action -- test only\n" \
13888 + "\t-t Specify tmp-dir.\n" \
13889 + "\t--tmp-dir Specify tmp-dir.\n" \
13890 + "\n" \
13891 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13892 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13893 +
13894 #define halt_trivial_usage \
13895 "[-d<delay>] [-n<nosync>] [-f<force>]"
13896 #define halt_full_usage \
This page took 0.578506 seconds and 5 git commands to generate.