[kernel] nefilter: fix chaostables on 2.6.24
[openwrt.git] / package / busybox / patches / 500-ipkg.patch
1 Index: busybox-1.8.1/archival/Config.in
2 ===================================================================
3 --- busybox-1.8.1.orig/archival/Config.in 2007-11-10 17:39:21.063504932 +0100
4 +++ busybox-1.8.1/archival/Config.in 2007-11-10 17:40:53.320762376 +0100
5 @@ -131,6 +131,15 @@
6 gzip is used to compress files.
7 It's probably the most widely used UNIX compression program.
8
9 +config IPKG
10 + bool "ipkg"
11 + default n
12 + select MD5SUM
13 + select WGET
14 + select DIFF
15 + help
16 + ipkg is the itsy package management system.
17 +
18 config RPM2CPIO
19 bool "rpm2cpio"
20 default n
21 Index: busybox-1.8.1/archival/dpkg.c
22 ===================================================================
23 --- busybox-1.8.1.orig/archival/dpkg.c 2007-11-10 17:39:21.071505389 +0100
24 +++ busybox-1.8.1/archival/dpkg.c 2007-11-10 17:40:53.320762376 +0100
25 @@ -1455,6 +1455,10 @@
26 return ar_handle->sub_archive->buffer;
27 }
28
29 +/*
30 +
31 +// moved to data_extract_all.c
32 +
33 static void data_extract_all_prefix(archive_handle_t *archive_handle)
34 {
35 char *name_ptr = archive_handle->file_header->name;
36 @@ -1466,6 +1470,8 @@
37 }
38 }
39
40 +*/
41 +
42 static void unpack_package(deb_file_t *deb_file)
43 {
44 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
45 Index: busybox-1.8.1/archival/ipkg.c
46 ===================================================================
47 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
48 +++ busybox-1.8.1/archival/ipkg.c 2007-11-10 17:41:16.866104145 +0100
49 @@ -0,0 +1,27 @@
50 +/* ipkg.c - the itsy package management system
51 +
52 + Florina Boor
53 +
54 + Copyright (C) 2003 kernel concepts
55 +
56 + This program is free software; you can redistribute it and/or
57 + modify it under the terms of the GNU General Public License as
58 + published by the Free Software Foundation; either version 2, or (at
59 + your option) any later version.
60 +
61 + This program is distributed in the hope that it will be useful, but
62 + WITHOUT ANY WARRANTY; without even the implied warranty of
63 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64 + General Public License for more details.
65 +
66 + ipkg command line frontend using libipkg
67 +
68 +*/
69 +#include "libipkg/libipkg.h"
70 +#include "busybox.h"
71 +
72 +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
73 +int ipkg_main(int argc, char **argv)
74 +{
75 + return ipkg_op(argc, argv);
76 +}
77 Index: busybox-1.8.1/archival/Kbuild
78 ===================================================================
79 --- busybox-1.8.1.orig/archival/Kbuild 2007-11-10 17:39:21.083506071 +0100
80 +++ busybox-1.8.1/archival/Kbuild 2007-11-10 17:40:53.332763058 +0100
81 @@ -16,6 +16,7 @@
82 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
83 lib-$(CONFIG_GUNZIP) += bbunzip.o
84 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
85 +lib-$(CONFIG_IPKG) += ipkg.o
86 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
87 lib-$(CONFIG_RPM) += rpm.o
88 lib-$(CONFIG_TAR) += tar.o
89 Index: busybox-1.8.1/archival/libipkg/args.c
90 ===================================================================
91 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
92 +++ busybox-1.8.1/archival/libipkg/args.c 2007-11-10 17:40:53.336763287 +0100
93 @@ -0,0 +1,242 @@
94 +/* args.c - parse command-line args
95 +
96 + Carl D. Worth
97 +
98 + Copyright 2001 University of Southern California
99 +
100 + This program is free software; you can redistribute it and/or modify
101 + it under the terms of the GNU General Public License as published by
102 + the Free Software Foundation; either version 2, or (at your option)
103 + any later version.
104 +
105 + This program is distributed in the hope that it will be useful,
106 + but WITHOUT ANY WARRANTY; without even the implied warranty of
107 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108 + GNU General Public License for more details.
109 + */
110 +
111 +#include <getopt.h>
112 +#include <stdlib.h>
113 +#include <string.h>
114 +#include <unistd.h>
115 +
116 +#include "ipkg.h"
117 +#include "ipkg_message.h"
118 +
119 +#include "args.h"
120 +#include "sprintf_alloc.h"
121 +
122 +#include "libbb.h"
123 +
124 +
125 +static void print_version(void);
126 +
127 +enum long_args_opt
128 +{
129 + ARGS_OPT_FORCE_DEFAULTS = 129,
130 + ARGS_OPT_FORCE_DEPENDS,
131 + ARGS_OPT_FORCE_OVERWRITE,
132 + ARGS_OPT_FORCE_DOWNGRADE,
133 + ARGS_OPT_FORCE_REINSTALL,
134 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
135 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
136 + ARGS_OPT_FORCE_SPACE,
137 + ARGS_OPT_NOACTION,
138 + ARGS_OPT_NODEPS,
139 + ARGS_OPT_VERBOSE_WGET,
140 + ARGS_OPT_VERBOSITY,
141 + ARGS_OPT_MULTIPLE_PROVIDERS
142 +};
143 +
144 +int args_init(args_t *args)
145 +{
146 + char *conf_file_dir;
147 +
148 + memset(args, 0, sizeof(args_t));
149 +
150 + args->dest = ARGS_DEFAULT_DEST;
151 +
152 + conf_file_dir = getenv("IPKG_CONF_DIR");
153 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
154 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
155 + }
156 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
157 + ARGS_DEFAULT_CONF_FILE_NAME);
158 +
159 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
160 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
161 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
162 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
163 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
164 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
165 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
166 + args->noaction = ARGS_DEFAULT_NOACTION;
167 + args->nodeps = ARGS_DEFAULT_NODEPS;
168 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
169 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
170 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
171 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
172 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
173 + args->multiple_providers = 0;
174 + args->nocheckfordirorfile = 0;
175 + args->noreadfeedsfile = 0;
176 +
177 + return 1;
178 +}
179 +
180 +void args_deinit(args_t *args)
181 +{
182 + free(args->conf_file);
183 + args->conf_file = NULL;
184 +}
185 +
186 +int args_parse(args_t *args, int argc, char *argv[])
187 +{
188 + int c;
189 + int option_index = 0;
190 + int parse_err = 0;
191 + static struct option long_options[] = {
192 + {"query-all", 0, 0, 'A'},
193 + {"conf-file", 1, 0, 'f'},
194 + {"conf", 1, 0, 'f'},
195 + {"dest", 1, 0, 'd'},
196 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
197 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
198 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
199 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
200 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
201 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
202 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
203 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
204 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
205 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
206 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
207 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
208 + {"recursive", 0, 0,
209 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
210 + {"force-removal-of-dependent-packages", 0, 0,
211 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
212 + {"force_removal_of_dependent_packages", 0, 0,
213 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
214 + {"force-removal-of-essential-packages", 0, 0,
215 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
216 + {"force_removal_of_essential_packages", 0, 0,
217 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
218 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
219 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
220 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
221 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
222 + {"offline", 1, 0, 'o'},
223 + {"offline-root", 1, 0, 'o'},
224 + {"test", 0, 0, ARGS_OPT_NOACTION},
225 + {"tmp-dir", 1, 0, 't'},
226 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
227 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
228 + {"verbosity", 2, 0, 'V'},
229 + {"version", 0, 0, 'v'},
230 + {0, 0, 0, 0}
231 + };
232 +
233 + while (1) {
234 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
235 + if (c == -1)
236 + break;
237 +
238 + switch (c) {
239 + case 'A':
240 + args->query_all = 1;
241 + break;
242 + case 'd':
243 + args->dest = optarg;
244 + break;
245 + case 'f':
246 + free(args->conf_file);
247 + args->conf_file = strdup(optarg);
248 + break;
249 + case 'o':
250 + args->offline_root = optarg;
251 + break;
252 + case 'n':
253 + args->noaction = 1;
254 + break;
255 + case 't':
256 + args->tmp_dir = strdup(optarg);
257 + break;
258 + case 'v':
259 + print_version();
260 + exit(0);
261 + case 'V':
262 + case ARGS_OPT_VERBOSITY:
263 + if (optarg)
264 + args->verbosity = atoi(optarg);
265 + else
266 + args->verbosity += 1;
267 + break;
268 + case ARGS_OPT_FORCE_DEFAULTS:
269 + args->force_defaults = 1;
270 + break;
271 + case ARGS_OPT_FORCE_DEPENDS:
272 + args->force_depends = 1;
273 + break;
274 + case ARGS_OPT_FORCE_OVERWRITE:
275 + args->force_overwrite = 1;
276 + break;
277 + case ARGS_OPT_FORCE_DOWNGRADE:
278 + args->force_downgrade = 1;
279 + break;
280 + case ARGS_OPT_FORCE_REINSTALL:
281 + args->force_reinstall = 1;
282 + break;
283 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
284 + args->force_removal_of_essential_packages = 1;
285 + break;
286 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
287 + args->force_removal_of_dependent_packages = 1;
288 + break;
289 + case ARGS_OPT_FORCE_SPACE:
290 + args->force_space = 1;
291 + break;
292 + case ARGS_OPT_VERBOSE_WGET:
293 + args->verbose_wget = 1;
294 + break;
295 + case ARGS_OPT_MULTIPLE_PROVIDERS:
296 + args->multiple_providers = 1;
297 + break;
298 + case ARGS_OPT_NODEPS:
299 + args->nodeps = 1;
300 + break;
301 + case ARGS_OPT_NOACTION:
302 + args->noaction = 1;
303 + break;
304 + case ':':
305 + parse_err++;
306 + break;
307 + case '?':
308 + parse_err++;
309 + break;
310 + default:
311 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
312 + }
313 + }
314 +
315 + if (parse_err) {
316 + return -parse_err;
317 + } else {
318 + return optind;
319 + }
320 +}
321 +
322 +void args_usage(char *complaint)
323 +{
324 + if (complaint) {
325 + bb_error_msg("%s\n", complaint);
326 + }
327 + print_version();
328 + bb_show_usage();
329 + exit(1);
330 +}
331 +
332 +static void print_version(void)
333 +{
334 + bb_error_msg("version %s\n", IPKG_VERSION);
335 +}
336 Index: busybox-1.8.1/archival/libipkg/args.h
337 ===================================================================
338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
339 +++ busybox-1.8.1/archival/libipkg/args.h 2007-11-10 17:40:53.340763516 +0100
340 @@ -0,0 +1,72 @@
341 +/* args.h - parse command-line args
342 +
343 + Carl D. Worth
344 +
345 + Copyright 2001 University of Southern California
346 +
347 + This program is free software; you can redistribute it and/or modify
348 + it under the terms of the GNU General Public License as published by
349 + the Free Software Foundation; either version 2, or (at your option)
350 + any later version.
351 +
352 + This program is distributed in the hope that it will be useful,
353 + but WITHOUT ANY WARRANTY; without even the implied warranty of
354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355 + GNU General Public License for more details.
356 +*/
357 +
358 +#ifndef ARGS_H
359 +#define ARGS_H
360 +
361 +struct args
362 +{
363 + char *conf_file;
364 + char *dest;
365 + char *tmp_dir;
366 + int force_defaults;
367 + int force_depends;
368 + int force_overwrite;
369 + int force_downgrade;
370 + int force_reinstall;
371 + int force_removal_of_essential_packages;
372 + int force_removal_of_dependent_packages;
373 + int force_space;
374 + int noaction;
375 + int nodeps;
376 + int multiple_providers;
377 + int query_all;
378 + int verbose_wget;
379 + int verbosity;
380 + int nocheckfordirorfile;
381 + int noreadfeedsfile;
382 + char *offline_root;
383 + char *offline_root_pre_script_cmd;
384 + char *offline_root_post_script_cmd;
385 +};
386 +typedef struct args args_t;
387 +
388 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
389 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
390 +#define ARGS_DEFAULT_DEST NULL
391 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
392 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
393 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
394 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
395 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
396 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
397 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
398 +#define ARGS_DEFAULT_FORCE_SPACE 0
399 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
400 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
401 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
402 +#define ARGS_DEFAULT_NOACTION 0
403 +#define ARGS_DEFAULT_NODEPS 0
404 +#define ARGS_DEFAULT_VERBOSE_WGET 0
405 +#define ARGS_DEFAULT_VERBOSITY 1
406 +
407 +int args_init(args_t *args);
408 +void args_deinit(args_t *args);
409 +int args_parse(args_t *args, int argc, char *argv[]);
410 +void args_usage(char *complaint);
411 +
412 +#endif
413 Index: busybox-1.8.1/archival/libipkg/conffile.c
414 ===================================================================
415 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
416 +++ busybox-1.8.1/archival/libipkg/conffile.c 2007-11-10 17:40:53.340763516 +0100
417 @@ -0,0 +1,64 @@
418 +/* conffile.c - the itsy package management system
419 +
420 + Carl D. Worth
421 +
422 + Copyright (C) 2001 University of Southern California
423 +
424 + This program is free software; you can redistribute it and/or
425 + modify it under the terms of the GNU General Public License as
426 + published by the Free Software Foundation; either version 2, or (at
427 + your option) any later version.
428 +
429 + This program is distributed in the hope that it will be useful, but
430 + WITHOUT ANY WARRANTY; without even the implied warranty of
431 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
432 + General Public License for more details.
433 +*/
434 +
435 +#include <string.h>
436 +#include <stdlib.h>
437 +
438 +#include "ipkg.h"
439 +#include "ipkg_message.h"
440 +
441 +#include "conffile.h"
442 +#include "file_util.h"
443 +#include "sprintf_alloc.h"
444 +
445 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
446 +{
447 + return nv_pair_init(conffile, file_name, md5sum);
448 +}
449 +
450 +void conffile_deinit(conffile_t *conffile)
451 +{
452 + nv_pair_deinit(conffile);
453 +}
454 +
455 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
456 +{
457 + char *md5sum;
458 + char *filename = conffile->name;
459 + char *root_filename;
460 + int ret;
461 +
462 + if (conffile->value == NULL) {
463 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
464 + return 1;
465 + }
466 +
467 + root_filename = root_filename_alloc(conf, filename);
468 +
469 + md5sum = file_md5sum_alloc(root_filename);
470 +
471 + ret = strcmp(md5sum, conffile->value);
472 + if (ret) {
473 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
474 + conffile->name, md5sum, conffile->value);
475 + }
476 +
477 + free(root_filename);
478 + free(md5sum);
479 +
480 + return ret;
481 +}
482 Index: busybox-1.8.1/archival/libipkg/conffile.h
483 ===================================================================
484 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
485 +++ busybox-1.8.1/archival/libipkg/conffile.h 2007-11-10 17:40:53.340763516 +0100
486 @@ -0,0 +1,30 @@
487 +/* conffile.h - the itsy package management system
488 +
489 + Carl D. Worth
490 +
491 + Copyright (C) 2001 University of Southern California
492 +
493 + This program is free software; you can redistribute it and/or
494 + modify it under the terms of the GNU General Public License as
495 + published by the Free Software Foundation; either version 2, or (at
496 + your option) any later version.
497 +
498 + This program is distributed in the hope that it will be useful, but
499 + WITHOUT ANY WARRANTY; without even the implied warranty of
500 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
501 + General Public License for more details.
502 +*/
503 +
504 +#ifndef CONFFILE_H
505 +#define CONFFILE_H
506 +
507 +#include "nv_pair.h"
508 +
509 +typedef struct nv_pair conffile_t;
510 +
511 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
512 +void conffile_deinit(conffile_t *conffile);
513 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
514 +
515 +#endif
516 +
517 Index: busybox-1.8.1/archival/libipkg/conffile_list.c
518 ===================================================================
519 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
520 +++ busybox-1.8.1/archival/libipkg/conffile_list.c 2007-11-10 17:40:53.340763516 +0100
521 @@ -0,0 +1,47 @@
522 +/* conffile_list.c - the itsy package management system
523 +
524 + Carl D. Worth
525 +
526 + Copyright (C) 2001 University of Southern California
527 +
528 + This program is free software; you can redistribute it and/or
529 + modify it under the terms of the GNU General Public License as
530 + published by the Free Software Foundation; either version 2, or (at
531 + your option) any later version.
532 +
533 + This program is distributed in the hope that it will be useful, but
534 + WITHOUT ANY WARRANTY; without even the implied warranty of
535 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
536 + General Public License for more details.
537 +*/
538 +
539 +#include "ipkg.h"
540 +
541 +#include "conffile_list.h"
542 +
543 +int conffile_list_init(conffile_list_t *list)
544 +{
545 + return nv_pair_list_init(list);
546 +}
547 +
548 +void conffile_list_deinit(conffile_list_t *list)
549 +{
550 + nv_pair_list_deinit(list);
551 +}
552 +
553 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
554 + const char *md5sum)
555 +{
556 + return nv_pair_list_append(list, file_name, md5sum);
557 +}
558 +
559 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
560 +{
561 + return nv_pair_list_push(list, data);
562 +}
563 +
564 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
565 +{
566 + return nv_pair_list_pop(list);
567 +}
568 +
569 Index: busybox-1.8.1/archival/libipkg/conffile_list.h
570 ===================================================================
571 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
572 +++ busybox-1.8.1/archival/libipkg/conffile_list.h 2007-11-10 17:40:53.340763516 +0100
573 @@ -0,0 +1,36 @@
574 +/* conffile_list.h - the itsy package management system
575 +
576 + Carl D. Worth
577 +
578 + Copyright (C) 2001 University of Southern California
579 +
580 + This program is free software; you can redistribute it and/or
581 + modify it under the terms of the GNU General Public License as
582 + published by the Free Software Foundation; either version 2, or (at
583 + your option) any later version.
584 +
585 + This program is distributed in the hope that it will be useful, but
586 + WITHOUT ANY WARRANTY; without even the implied warranty of
587 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
588 + General Public License for more details.
589 +*/
590 +
591 +#ifndef CONFFILE_LIST_H
592 +#define CONFFILE_LIST_H
593 +
594 +#include "conffile.h"
595 +#include "nv_pair_list.h"
596 +
597 +typedef struct nv_pair_list_elt conffile_list_elt_t;
598 +typedef struct nv_pair_list conffile_list_t;
599 +
600 +int conffile_list_init(conffile_list_t *list);
601 +void conffile_list_deinit(conffile_list_t *list);
602 +
603 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
604 + const char *root_dir);
605 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
606 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
607 +
608 +#endif
609 +
610 Index: busybox-1.8.1/archival/libipkg/file_util.c
611 ===================================================================
612 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
613 +++ busybox-1.8.1/archival/libipkg/file_util.c 2007-11-10 17:40:53.340763516 +0100
614 @@ -0,0 +1,132 @@
615 +/* file_util.c - convenience routines for common stat operations
616 +
617 + Carl D. Worth
618 +
619 + Copyright (C) 2001 University of Southern California
620 +
621 + This program is free software; you can redistribute it and/or
622 + modify it under the terms of the GNU General Public License as
623 + published by the Free Software Foundation; either version 2, or (at
624 + your option) any later version.
625 +
626 + This program is distributed in the hope that it will be useful, but
627 + WITHOUT ANY WARRANTY; without even the implied warranty of
628 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
629 + General Public License for more details.
630 +*/
631 +
632 +#include "ipkg.h"
633 +#include <sys/types.h>
634 +#include <sys/stat.h>
635 +
636 +#include "sprintf_alloc.h"
637 +#include "file_util.h"
638 +#include "libbb.h"
639 +#undef strlen
640 +
641 +int file_exists(const char *file_name)
642 +{
643 + int err;
644 + struct stat stat_buf;
645 +
646 + err = stat(file_name, &stat_buf);
647 + if (err == 0) {
648 + return 1;
649 + } else {
650 + return 0;
651 + }
652 +}
653 +
654 +int file_is_dir(const char *file_name)
655 +{
656 + int err;
657 + struct stat stat_buf;
658 +
659 + err = stat(file_name, &stat_buf);
660 + if (err) {
661 + return 0;
662 + }
663 +
664 + return S_ISDIR(stat_buf.st_mode);
665 +}
666 +
667 +/* read a single line from a file, stopping at a newline or EOF.
668 + If a newline is read, it will appear in the resulting string.
669 + Return value is a malloc'ed char * which should be freed at
670 + some point by the caller.
671 +
672 + Return value is NULL if the file is at EOF when called.
673 +*/
674 +#define FILE_READ_LINE_BUF_SIZE 1024
675 +char *file_read_line_alloc(FILE *file)
676 +{
677 + char buf[FILE_READ_LINE_BUF_SIZE];
678 + int buf_len;
679 + char *line = NULL;
680 + int line_size = 0;
681 +
682 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
683 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
684 + buf_len = strlen(buf);
685 + if (line) {
686 + line_size += buf_len;
687 + line = realloc(line, line_size);
688 + if (line == NULL) {
689 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
690 + break;
691 + }
692 + strcat(line, buf);
693 + } else {
694 + line_size = buf_len + 1;
695 + line = strdup(buf);
696 + }
697 + if (buf[buf_len - 1] == '\n') {
698 + break;
699 + }
700 + }
701 +
702 + return line;
703 +}
704 +
705 +int file_move(const char *src, const char *dest)
706 +{
707 + int err;
708 +
709 + err = rename(src, dest);
710 +
711 + if (err && errno == EXDEV) {
712 + err = file_copy(src, dest);
713 + unlink(src);
714 + } else if (err) {
715 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
716 + __FUNCTION__, src, dest, strerror(errno));
717 + }
718 +
719 + return err;
720 +}
721 +
722 +/* I put these here to keep libbb dependencies from creeping all over
723 + the ipkg code */
724 +int file_copy(const char *src, const char *dest)
725 +{
726 + int err;
727 +
728 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
729 + if (err) {
730 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
731 + __FUNCTION__, src, dest);
732 + }
733 +
734 + return err;
735 +}
736 +
737 +int file_mkdir_hier(const char *path, long mode)
738 +{
739 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
740 +}
741 +
742 +char *file_md5sum_alloc(const char *file_name)
743 +{
744 + return hash_file(file_name, HASH_MD5);
745 +}
746 +
747 Index: busybox-1.8.1/archival/libipkg/file_util.h
748 ===================================================================
749 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
750 +++ busybox-1.8.1/archival/libipkg/file_util.h 2007-11-10 17:40:53.344763742 +0100
751 @@ -0,0 +1,29 @@
752 +/* file_util.h - convenience routines for common file operations
753 +
754 + Carl D. Worth
755 +
756 + Copyright (C) 2001 University of Southern California
757 +
758 + This program is free software; you can redistribute it and/or
759 + modify it under the terms of the GNU General Public License as
760 + published by the Free Software Foundation; either version 2, or (at
761 + your option) any later version.
762 +
763 + This program is distributed in the hope that it will be useful, but
764 + WITHOUT ANY WARRANTY; without even the implied warranty of
765 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
766 + General Public License for more details.
767 +*/
768 +
769 +#ifndef FILE_UTIL_H
770 +#define FILE_UTIL_H
771 +
772 +int file_exists(const char *file_name);
773 +int file_is_dir(const char *file_name);
774 +char *file_read_line_alloc(FILE *file);
775 +int file_move(const char *src, const char *dest);
776 +int file_copy(const char *src, const char *dest);
777 +int file_mkdir_hier(const char *path, long mode);
778 +char *file_md5sum_alloc(const char *file_name);
779 +
780 +#endif
781 Index: busybox-1.8.1/archival/libipkg/hash_table.c
782 ===================================================================
783 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
784 +++ busybox-1.8.1/archival/libipkg/hash_table.c 2007-11-10 17:40:53.344763742 +0100
785 @@ -0,0 +1,155 @@
786 +/* hash.c - hash tables for ipkg
787 +
788 + Steven M. Ayer, Jamey Hicks
789 +
790 + Copyright (C) 2002 Compaq Computer Corporation
791 +
792 + This program is free software; you can redistribute it and/or
793 + modify it under the terms of the GNU General Public License as
794 + published by the Free Software Foundation; either version 2, or (at
795 + your option) any later version.
796 +
797 + This program is distributed in the hope that it will be useful, but
798 + WITHOUT ANY WARRANTY; without even the implied warranty of
799 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
800 + General Public License for more details.
801 +*/
802 +
803 +#include <errno.h>
804 +#include <stdio.h>
805 +#include <stdlib.h>
806 +#include <string.h>
807 +#include "hash_table.h"
808 +#include "ipkg_message.h"
809 +
810 +
811 +static int hash_index(hash_table_t *hash, const char *pkg_name);
812 +static int rotating(const char *key, int len, int prime);
813 +
814 +static int hash_index(hash_table_t *hash, const char *pkg_name)
815 +{
816 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
817 +}
818 +
819 +static int rotating(const char *key, int len, int prime)
820 +{
821 + unsigned int hash, i;
822 + for (hash=len, i=0; i<len; ++i)
823 + hash = (hash<<4)^(hash>>28)^key[i];
824 + return (hash % prime);
825 +}
826 +
827 +
828 +/*
829 + * this is an open table keyed by strings
830 + */
831 +int hash_table_init(const char *name, hash_table_t *hash, int len)
832 +{
833 + static int primes_table[] = {
834 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
835 + 19471, 23143, 33961, 46499, 49727, 99529, 0
836 + };
837 + int *picker;
838 +
839 + if (hash->entries != NULL) {
840 + /* we have been here already */
841 + return 0;
842 + }
843 +
844 + hash->name = name;
845 + hash->entries = NULL;
846 + hash->n_entries = 0;
847 + hash->hash_entry_key = NULL;
848 +
849 + picker = primes_table;
850 + while(*picker && (*picker++ < len));
851 + if(!*picker)
852 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
853 + --picker;
854 +
855 + hash->n_entries = *picker;
856 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
857 + if (hash->entries == NULL) {
858 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
859 + return ENOMEM;
860 + }
861 + return 0;
862 +}
863 +
864 +void hash_table_deinit(hash_table_t *hash)
865 +{
866 + free(hash->entries);
867 + hash->entries = NULL;
868 + hash->n_entries = 0;
869 +}
870 +
871 +void *hash_table_get(hash_table_t *hash, const char *key)
872 +{
873 + int ndx= hash_index(hash, key);
874 + hash_entry_t *hash_entry = hash->entries + ndx;
875 + while (hash_entry)
876 + {
877 + if (hash_entry->key)
878 + {
879 + if (strcmp(key, hash_entry->key) == 0) {
880 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
881 + return hash_entry->data;
882 + }
883 + }
884 + hash_entry = hash_entry->next;
885 + }
886 + return NULL;
887 +}
888 +
889 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
890 +{
891 + int ndx= hash_index(hash, key);
892 + hash_entry_t *hash_entry = hash->entries + ndx;
893 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
894 + if (hash_entry->key) {
895 + if (strcmp(hash_entry->key, key) == 0) {
896 + /* alread in table, update the value */
897 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
898 + hash_entry->data = value;
899 + return 0;
900 + } else {
901 + /*
902 + * if this is a collision, we have to go to the end of the ll,
903 + * then add a new entry
904 + * before we can hook up the value
905 + */
906 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
907 + while (hash_entry->next)
908 + hash_entry = hash_entry->next;
909 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
910 + if (!hash_entry->next) {
911 + return -ENOMEM;
912 + }
913 + hash_entry = hash_entry->next;
914 + hash_entry->next = NULL;
915 + }
916 + }
917 + hash->n_elements++;
918 + hash_entry->key = strdup(key);
919 + hash_entry->data = value;
920 +
921 + return 0;
922 +}
923 +
924 +
925 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
926 +{
927 + int i;
928 + if (!hash || !f)
929 + return;
930 +
931 + for (i = 0; i < hash->n_entries; i++) {
932 + hash_entry_t *hash_entry = (hash->entries + i);
933 + do {
934 + if(hash_entry->key) {
935 + f(hash_entry->key, hash_entry->data, data);
936 + }
937 + } while((hash_entry = hash_entry->next));
938 + }
939 +}
940 +
941 Index: busybox-1.8.1/archival/libipkg/hash_table.h
942 ===================================================================
943 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
944 +++ busybox-1.8.1/archival/libipkg/hash_table.h 2007-11-10 17:40:53.344763742 +0100
945 @@ -0,0 +1,44 @@
946 +/* hash.h - hash tables for ipkg
947 +
948 + Steven M. Ayer, Jamey Hicks
949 +
950 + Copyright (C) 2002 Compaq Computer Corporation
951 +
952 + This program is free software; you can redistribute it and/or
953 + modify it under the terms of the GNU General Public License as
954 + published by the Free Software Foundation; either version 2, or (at
955 + your option) any later version.
956 +
957 + This program is distributed in the hope that it will be useful, but
958 + WITHOUT ANY WARRANTY; without even the implied warranty of
959 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
960 + General Public License for more details.
961 +*/
962 +
963 +#ifndef _HASH_TABLE_H_
964 +#define _HASH_TABLE_H_
965 +
966 +typedef struct hash_entry hash_entry_t;
967 +typedef struct hash_table hash_table_t;
968 +
969 +struct hash_entry {
970 + const char * key;
971 + void * data;
972 + struct hash_entry * next;
973 +};
974 +
975 +struct hash_table {
976 + const char *name;
977 + hash_entry_t * entries;
978 + int n_entries; /* number of buckets */
979 + int n_elements;
980 + const char * (*hash_entry_key)(void * data);
981 +};
982 +
983 +int hash_table_init(const char *name, hash_table_t *hash, int len);
984 +void hash_table_deinit(hash_table_t *hash);
985 +void *hash_table_get(hash_table_t *hash, const char *key);
986 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
987 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
988 +
989 +#endif /* _HASH_TABLE_H_ */
990 Index: busybox-1.8.1/archival/libipkg/ipkg_cmd.c
991 ===================================================================
992 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
993 +++ busybox-1.8.1/archival/libipkg/ipkg_cmd.c 2007-11-10 17:40:53.344763742 +0100
994 @@ -0,0 +1,1431 @@
995 +/* ipkg_cmd.c - the itsy package management system
996 +
997 + Carl D. Worth
998 +
999 + Copyright (C) 2001 University of Southern California
1000 +
1001 + This program is free software; you can redistribute it and/or
1002 + modify it under the terms of the GNU General Public License as
1003 + published by the Free Software Foundation; either version 2, or (at
1004 + your option) any later version.
1005 +
1006 + This program is distributed in the hope that it will be useful, but
1007 + WITHOUT ANY WARRANTY; without even the implied warranty of
1008 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1009 + General Public License for more details.
1010 +*/
1011 +
1012 +#include <string.h>
1013 +
1014 +#include "ipkg.h"
1015 +#include <libgen.h>
1016 +#include <glob.h>
1017 +#include <errno.h>
1018 +#include <stdlib.h>
1019 +#include <unistd.h>
1020 +#include <signal.h>
1021 +#include <stdio.h>
1022 +#include <dirent.h>
1023 +
1024 +#include "ipkg_conf.h"
1025 +#include "ipkg_cmd.h"
1026 +#include "ipkg_message.h"
1027 +#include "pkg.h"
1028 +#include "pkg_dest.h"
1029 +#include "pkg_parse.h"
1030 +#include "sprintf_alloc.h"
1031 +#include "pkg.h"
1032 +#include "file_util.h"
1033 +#include "str_util.h"
1034 +#include "libbb.h"
1035 +#include "unarchive.h"
1036 +
1037 +#include <fnmatch.h>
1038 +
1039 +
1040 +#include "ipkg_download.h"
1041 +#include "ipkg_install.h"
1042 +#include "ipkg_upgrade.h"
1043 +#include "ipkg_remove.h"
1044 +#include "ipkg_configure.h"
1045 +#include "ipkg_message.h"
1046 +
1047 +#ifdef IPKG_LIB
1048 +#include "libipkg.h"
1049 +static void *p_userdata = NULL;
1050 +#endif
1051 +
1052 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1076 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1077 +
1078 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1079 + array for easier maintenance */
1080 +static ipkg_cmd_t cmds[] = {
1081 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1082 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1083 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1084 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1085 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1086 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1087 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1088 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1089 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1090 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1091 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1092 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1093 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1094 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1095 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1096 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1097 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1098 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1101 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1102 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1103 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1104 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1105 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1106 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1107 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1108 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1109 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1110 +};
1111 +
1112 +int ipkg_state_changed;
1113 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1114 +{
1115 + if (ipkg_state_changed && !conf->noaction) {
1116 + ipkg_message(conf, IPKG_INFO,
1117 + " writing status file\n");
1118 + ipkg_conf_write_status_files(conf);
1119 + pkg_write_changed_filelists(conf);
1120 + } else {
1121 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1122 + }
1123 +}
1124 +
1125 +
1126 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1127 +
1128 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1129 +{
1130 + int i;
1131 + ipkg_cmd_t *cmd;
1132 +
1133 + for (i=0; i < num_cmds; i++) {
1134 + cmd = &cmds[i];
1135 + if (strcmp(name, cmd->name) == 0) {
1136 + return cmd;
1137 + }
1138 + }
1139 +
1140 + return NULL;
1141 +}
1142 +
1143 +#ifdef IPKG_LIB
1144 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1145 +{
1146 + int result;
1147 + p_userdata = userdata;
1148 +
1149 +
1150 + result = (cmd->fun)(conf, argc, argv);
1151 + if ( result == 0 ) {
1152 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1153 + } else {
1154 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1155 +
1156 + }
1157 + if ( error_list ) {
1158 + reverse_error_list(&error_list);
1159 +
1160 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1161 + /* Here we print the errors collected and free the list */
1162 + while (error_list != NULL) {
1163 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1164 + error_list = error_list->next;
1165 +
1166 + }
1167 + free_error_list(&error_list);
1168 +
1169 + }
1170 +
1171 + p_userdata = NULL;
1172 + return result;
1173 +}
1174 +#else
1175 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1176 +{
1177 + return (cmd->fun)(conf, argc, argv);
1178 +}
1179 +#endif
1180 +
1181 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1182 +{
1183 + int err;
1184 + int failures;
1185 + char *lists_dir;
1186 + pkg_src_list_elt_t *iter;
1187 + pkg_src_t *src;
1188 +
1189 +
1190 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1191 +
1192 + if (! file_is_dir(lists_dir)) {
1193 + if (file_exists(lists_dir)) {
1194 + ipkg_message(conf, IPKG_ERROR,
1195 + "%s: ERROR: %s exists, but is not a directory\n",
1196 + __FUNCTION__, lists_dir);
1197 + free(lists_dir);
1198 + return EINVAL;
1199 + }
1200 + err = file_mkdir_hier(lists_dir, 0755);
1201 + if (err) {
1202 + ipkg_message(conf, IPKG_ERROR,
1203 + "%s: ERROR: failed to make directory %s: %s\n",
1204 + __FUNCTION__, lists_dir, strerror(errno));
1205 + free(lists_dir);
1206 + return EINVAL;
1207 + }
1208 + }
1209 +
1210 + failures = 0;
1211 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1212 + char *url, *list_file_name;
1213 +
1214 + src = iter->data;
1215 +
1216 + if (src->extra_data) /* debian style? */
1217 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1218 + src->gzip ? "Packages.gz" : "Packages");
1219 + else
1220 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1221 +
1222 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1223 + if (src->gzip) {
1224 + char *tmp;
1225 + char *tmp_file_name;
1226 + FILE *in, *out;
1227 +
1228 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1229 +
1230 + if (mkdtemp (tmp) == NULL) {
1231 + perror ("mkdtemp");
1232 + failures++;
1233 + continue;
1234 + }
1235 +
1236 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1237 + err = ipkg_download(conf, url, tmp_file_name);
1238 + if (err == 0) {
1239 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1240 + in = fopen (tmp_file_name, "r");
1241 + out = fopen (list_file_name, "w");
1242 + if (in && out) {
1243 + inflate_unzip_result res;
1244 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1245 + } else
1246 + err = 1;
1247 + if (in)
1248 + fclose (in);
1249 + if (out)
1250 + fclose (out);
1251 + unlink (tmp_file_name);
1252 + rmdir (tmp);
1253 + free (tmp);
1254 + }
1255 + } else
1256 + err = ipkg_download(conf, url, list_file_name);
1257 + if (err) {
1258 + failures++;
1259 + } else {
1260 + ipkg_message(conf, IPKG_NOTICE,
1261 + "Updated list of available packages in %s\n",
1262 + list_file_name);
1263 + }
1264 + free(url);
1265 + free(list_file_name);
1266 + }
1267 + free(lists_dir);
1268 +
1269 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1270 +#warning here
1271 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1272 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1273 + * -Jamey 3/1/03
1274 + */
1275 + {
1276 + int i;
1277 + int changed = 0;
1278 + pkg_vec_t *available = pkg_vec_alloc();
1279 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1280 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1281 + for (i = 0; i < available->len; i++) {
1282 + pkg_t *pkg = available->pkgs[i];
1283 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1284 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1285 + pkg->state_want = SW_UNKNOWN;
1286 + changed = 1;
1287 + }
1288 + }
1289 + pkg_vec_free(available);
1290 + if (changed) {
1291 + write_status_files_if_changed(conf);
1292 + }
1293 + }
1294 +#endif
1295 +
1296 + return failures;
1297 +}
1298 +
1299 +
1300 +/* scan the args passed and cache the local filenames of the packages */
1301 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1302 +{
1303 + int i;
1304 + int err;
1305 +
1306 + /*
1307 + * First scan through package names/urls
1308 + * For any urls, download the packages and install in database.
1309 + * For any files, install package info in database.
1310 + */
1311 + for (i = 0; i < argc; i ++) {
1312 + char *filename = argv [i];
1313 + //char *tmp = basename (tmp);
1314 + //int tmplen = strlen (tmp);
1315 +
1316 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1317 + // continue;
1318 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1319 + // continue;
1320 +
1321 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1322 +
1323 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1324 + if (err)
1325 + return err;
1326 + }
1327 + return 0;
1328 +}
1329 +
1330 +struct ipkg_intercept
1331 +{
1332 + char *oldpath;
1333 + char *statedir;
1334 +};
1335 +
1336 +typedef struct ipkg_intercept *ipkg_intercept_t;
1337 +
1338 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1339 +{
1340 + ipkg_intercept_t ctx;
1341 + char *newpath;
1342 + int gen;
1343 +
1344 + ctx = malloc (sizeof (*ctx));
1345 + ctx->oldpath = strdup (getenv ("PATH"));
1346 +
1347 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1348 + setenv ("PATH", newpath, 1);
1349 + free (newpath);
1350 +
1351 + gen = 0;
1352 + retry:
1353 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1354 + if (mkdir (ctx->statedir, 0770) < 0) {
1355 + if (errno == EEXIST) {
1356 + free (ctx->statedir);
1357 + gen++;
1358 + goto retry;
1359 + }
1360 + perror (ctx->statedir);
1361 + return NULL;
1362 + }
1363 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1364 + return ctx;
1365 +}
1366 +
1367 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1368 +{
1369 + char *cmd;
1370 + DIR *dir;
1371 + int err = 0;
1372 +
1373 + setenv ("PATH", ctx->oldpath, 1);
1374 + free (ctx->oldpath);
1375 +
1376 + dir = opendir (ctx->statedir);
1377 + if (dir) {
1378 + struct dirent *de;
1379 + while (de = readdir (dir), de != NULL) {
1380 + char *path;
1381 +
1382 + if (de->d_name[0] == '.')
1383 + continue;
1384 +
1385 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1386 + if (access (path, X_OK) == 0) {
1387 + if (system (path)) {
1388 + err = errno;
1389 + perror (de->d_name);
1390 + }
1391 + }
1392 + free (path);
1393 + }
1394 + } else
1395 + perror (ctx->statedir);
1396 +
1397 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1398 + system (cmd);
1399 + free (cmd);
1400 +
1401 + free (ctx->statedir);
1402 + free (ctx);
1403 +
1404 + return err;
1405 +}
1406 +
1407 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1408 +{
1409 + pkg_vec_t *all;
1410 + int i;
1411 + pkg_t *pkg;
1412 + ipkg_intercept_t ic;
1413 + int r, err = 0;
1414 +
1415 + ipkg_message(conf, IPKG_INFO,
1416 + "Configuring unpacked packages\n");
1417 + fflush( stdout );
1418 +
1419 + all = pkg_vec_alloc();
1420 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1421 +
1422 + ic = ipkg_prep_intercepts (conf);
1423 +
1424 + for(i = 0; i < all->len; i++) {
1425 + pkg = all->pkgs[i];
1426 +
1427 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1428 + continue;
1429 +
1430 + if (pkg->state_status == SS_UNPACKED) {
1431 + ipkg_message(conf, IPKG_NOTICE,
1432 + "Configuring %s\n", pkg->name);
1433 + fflush( stdout );
1434 + r = ipkg_configure(conf, pkg);
1435 + if (r == 0) {
1436 + pkg->state_status = SS_INSTALLED;
1437 + pkg->parent->state_status = SS_INSTALLED;
1438 + pkg->state_flag &= ~SF_PREFER;
1439 + } else {
1440 + if (!err)
1441 + err = r;
1442 + }
1443 + }
1444 + }
1445 +
1446 + r = ipkg_finalize_intercepts (ic);
1447 + if (r && !err)
1448 + err = r;
1449 +
1450 + pkg_vec_free(all);
1451 + return err;
1452 +}
1453 +
1454 +static void sigint_handler(int sig)
1455 +{
1456 + signal(sig, SIG_DFL);
1457 + ipkg_message(NULL, IPKG_NOTICE,
1458 + "ipkg: interrupted. writing out status database\n");
1459 + write_status_files_if_changed(global_conf);
1460 + exit(128 + sig);
1461 +}
1462 +
1463 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1464 +{
1465 + int i;
1466 + char *arg;
1467 + int err=0;
1468 +
1469 + global_conf = conf;
1470 + signal(SIGINT, sigint_handler);
1471 +
1472 + /*
1473 + * Now scan through package names and install
1474 + */
1475 + for (i=0; i < argc; i++) {
1476 + arg = argv[i];
1477 +
1478 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1479 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1480 + if (err != EINVAL && err != 0)
1481 + return err;
1482 + }
1483 + pkg_info_preinstall_check(conf);
1484 +
1485 + for (i=0; i < argc; i++) {
1486 + arg = argv[i];
1487 + if (conf->multiple_providers)
1488 + err = ipkg_install_multi_by_name(conf, arg);
1489 + else{
1490 + err = ipkg_install_by_name(conf, arg);
1491 + }
1492 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1493 + ipkg_message(conf, IPKG_ERROR,
1494 + "Cannot find package %s.\n"
1495 + "Check the spelling or perhaps run 'ipkg update'\n",
1496 + arg);
1497 + }
1498 + }
1499 +
1500 + /* recheck to verify that all dependences are satisfied */
1501 + if (0) ipkg_satisfy_all_dependences(conf);
1502 +
1503 + ipkg_configure_packages(conf, NULL);
1504 +
1505 + write_status_files_if_changed(conf);
1506 +
1507 + return err;
1508 +}
1509 +
1510 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1511 +{
1512 + int i;
1513 + pkg_t *pkg;
1514 + int err;
1515 +
1516 + global_conf = conf;
1517 + signal(SIGINT, sigint_handler);
1518 +
1519 + if (argc) {
1520 + for (i=0; i < argc; i++) {
1521 + char *arg = argv[i];
1522 +
1523 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1524 + if (err != EINVAL && err != 0)
1525 + return err;
1526 + }
1527 + pkg_info_preinstall_check(conf);
1528 +
1529 + for (i=0; i < argc; i++) {
1530 + char *arg = argv[i];
1531 + if (conf->restrict_to_default_dest) {
1532 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1533 + argv[i],
1534 + conf->default_dest);
1535 + if (pkg == NULL) {
1536 + ipkg_message(conf, IPKG_NOTICE,
1537 + "Package %s not installed in %s\n",
1538 + argv[i], conf->default_dest->name);
1539 + continue;
1540 + }
1541 + } else {
1542 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1543 + argv[i]);
1544 + }
1545 + if (pkg)
1546 + ipkg_upgrade_pkg(conf, pkg);
1547 + else {
1548 + ipkg_install_by_name(conf, arg);
1549 + }
1550 + }
1551 + } else {
1552 + pkg_vec_t *installed = pkg_vec_alloc();
1553 +
1554 + pkg_info_preinstall_check(conf);
1555 +
1556 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1557 + for (i = 0; i < installed->len; i++) {
1558 + pkg = installed->pkgs[i];
1559 + ipkg_upgrade_pkg(conf, pkg);
1560 + }
1561 + pkg_vec_free(installed);
1562 + }
1563 +
1564 + /* recheck to verify that all dependences are satisfied */
1565 + if (0) ipkg_satisfy_all_dependences(conf);
1566 +
1567 + ipkg_configure_packages(conf, NULL);
1568 +
1569 + write_status_files_if_changed(conf);
1570 +
1571 + return 0;
1572 +}
1573 +
1574 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1575 +{
1576 + int i, err;
1577 + char *arg;
1578 + pkg_t *pkg;
1579 +
1580 + pkg_info_preinstall_check(conf);
1581 + for (i = 0; i < argc; i++) {
1582 + arg = argv[i];
1583 +
1584 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1585 + if (pkg == NULL) {
1586 + ipkg_message(conf, IPKG_ERROR,
1587 + "Cannot find package %s.\n"
1588 + "Check the spelling or perhaps run 'ipkg update'\n",
1589 + arg);
1590 + continue;
1591 + }
1592 +
1593 + err = ipkg_download_pkg(conf, pkg, ".");
1594 +
1595 + if (err) {
1596 + ipkg_message(conf, IPKG_ERROR,
1597 + "Failed to download %s\n", pkg->name);
1598 + } else {
1599 + ipkg_message(conf, IPKG_NOTICE,
1600 + "Downloaded %s as %s\n",
1601 + pkg->name, pkg->local_filename);
1602 + }
1603 + }
1604 +
1605 + return 0;
1606 +}
1607 +
1608 +
1609 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1610 +{
1611 + int i ;
1612 + pkg_vec_t *available;
1613 + pkg_t *pkg;
1614 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1615 + char *newline;
1616 + char *pkg_name = NULL;
1617 + char *version_str;
1618 +
1619 + if (argc > 0) {
1620 + pkg_name = argv[0];
1621 + }
1622 + available = pkg_vec_alloc();
1623 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1624 + for (i=0; i < available->len; i++) {
1625 + pkg = available->pkgs[i];
1626 + /* if we have package name or pattern and pkg does not match, then skip it */
1627 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1628 + continue;
1629 + if (pkg->description) {
1630 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1631 + } else {
1632 + desc_short[0] = '\0';
1633 + }
1634 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1635 + newline = strchr(desc_short, '\n');
1636 + if (newline) {
1637 + *newline = '\0';
1638 + }
1639 +#ifndef IPKG_LIB
1640 + printf("%s - %s\n", pkg->name, desc_short);
1641 +#else
1642 + if (ipkg_cb_list) {
1643 + version_str = pkg_version_str_alloc(pkg);
1644 + ipkg_cb_list(pkg->name,desc_short,
1645 + version_str,
1646 + pkg->state_status,
1647 + p_userdata);
1648 + free(version_str);
1649 + }
1650 +#endif
1651 + }
1652 + pkg_vec_free(available);
1653 +
1654 + return 0;
1655 +}
1656 +
1657 +
1658 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1659 +{
1660 + int i ;
1661 + pkg_vec_t *available;
1662 + pkg_t *pkg;
1663 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1664 + char *newline;
1665 + char *pkg_name = NULL;
1666 + char *version_str;
1667 +
1668 + if (argc > 0) {
1669 + pkg_name = argv[0];
1670 + }
1671 + available = pkg_vec_alloc();
1672 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1673 + for (i=0; i < available->len; i++) {
1674 + pkg = available->pkgs[i];
1675 + /* if we have package name or pattern and pkg does not match, then skip it */
1676 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1677 + continue;
1678 + if (pkg->description) {
1679 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1680 + } else {
1681 + desc_short[0] = '\0';
1682 + }
1683 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1684 + newline = strchr(desc_short, '\n');
1685 + if (newline) {
1686 + *newline = '\0';
1687 + }
1688 +#ifndef IPKG_LIB
1689 + printf("%s - %s\n", pkg->name, desc_short);
1690 +#else
1691 + if (ipkg_cb_list) {
1692 + version_str = pkg_version_str_alloc(pkg);
1693 + ipkg_cb_list(pkg->name,desc_short,
1694 + version_str,
1695 + pkg->state_status,
1696 + p_userdata);
1697 + free(version_str);
1698 + }
1699 +#endif
1700 + }
1701 +
1702 + return 0;
1703 +}
1704 +
1705 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1706 +{
1707 + int i;
1708 + pkg_vec_t *available;
1709 + pkg_t *pkg;
1710 + char *pkg_name = NULL;
1711 + char **pkg_fields = NULL;
1712 + int n_fields = 0;
1713 + char *buff ; // = (char *)malloc(1);
1714 +
1715 + if (argc > 0) {
1716 + pkg_name = argv[0];
1717 + }
1718 + if (argc > 1) {
1719 + pkg_fields = &argv[1];
1720 + n_fields = argc - 1;
1721 + }
1722 +
1723 + available = pkg_vec_alloc();
1724 + if (installed_only)
1725 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1726 + else
1727 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1728 + for (i=0; i < available->len; i++) {
1729 + pkg = available->pkgs[i];
1730 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1731 + continue;
1732 + }
1733 +#ifndef IPKG_LIB
1734 + if (n_fields) {
1735 + for (j = 0; j < n_fields; j++)
1736 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1737 + } else {
1738 + pkg_print_info(pkg, stdout);
1739 + }
1740 +#else
1741 +
1742 + buff = pkg_formatted_info(pkg);
1743 + if ( buff ) {
1744 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1745 + pkg->state_status,
1746 + buff,
1747 + p_userdata);
1748 +/*
1749 + We should not forget that actually the pointer is allocated.
1750 + We need to free it :) ( Thanks florian for seeing the error )
1751 +*/
1752 + free(buff);
1753 + }
1754 +#endif
1755 + if (conf->verbosity > 1) {
1756 + conffile_list_elt_t *iter;
1757 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1758 + conffile_t *cf = iter->data;
1759 + int modified = conffile_has_been_modified(conf, cf);
1760 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1761 + cf->name, cf->value, modified);
1762 + }
1763 + }
1764 + }
1765 +#ifndef IPKG_LIB
1766 + if (buff)
1767 + free(buff);
1768 +#endif
1769 + pkg_vec_free(available);
1770 +
1771 + return 0;
1772 +}
1773 +
1774 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1775 +{
1776 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1777 +}
1778 +
1779 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1780 +{
1781 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1782 +}
1783 +
1784 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1785 +{
1786 +
1787 + int err;
1788 + if (argc > 0) {
1789 + char *pkg_name = NULL;
1790 +
1791 + pkg_name = argv[0];
1792 +
1793 + err = ipkg_configure_packages (conf, pkg_name);
1794 +
1795 + } else {
1796 + err = ipkg_configure_packages (conf, NULL);
1797 + }
1798 +
1799 + write_status_files_if_changed(conf);
1800 +
1801 + return err;
1802 +}
1803 +
1804 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1805 +{
1806 + int i, err;
1807 + char *globpattern;
1808 + glob_t globbuf;
1809 +
1810 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1811 + err = glob(globpattern, 0, NULL, &globbuf);
1812 + free(globpattern);
1813 + if (err) {
1814 + return 0;
1815 + }
1816 +
1817 + ipkg_message(conf, IPKG_NOTICE,
1818 + "The following packages in %s will now be installed.\n",
1819 + conf->pending_dir);
1820 + for (i = 0; i < globbuf.gl_pathc; i++) {
1821 + ipkg_message(conf, IPKG_NOTICE,
1822 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1823 + }
1824 + ipkg_message(conf, IPKG_NOTICE, "\n");
1825 + for (i = 0; i < globbuf.gl_pathc; i++) {
1826 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1827 + if (err == 0) {
1828 + err = unlink(globbuf.gl_pathv[i]);
1829 + if (err) {
1830 + ipkg_message(conf, IPKG_ERROR,
1831 + "%s: ERROR: failed to unlink %s: %s\n",
1832 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1833 + return err;
1834 + }
1835 + }
1836 + }
1837 + globfree(&globbuf);
1838 +
1839 + return err;
1840 +}
1841 +
1842 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1843 +{
1844 + int i,a,done;
1845 + pkg_t *pkg;
1846 + pkg_t *pkg_to_remove;
1847 + pkg_vec_t *available;
1848 + char *pkg_name = NULL;
1849 + global_conf = conf;
1850 + signal(SIGINT, sigint_handler);
1851 +
1852 +// ENH: Add the "no pkg removed" just in case.
1853 +
1854 + done = 0;
1855 +
1856 + available = pkg_vec_alloc();
1857 + pkg_info_preinstall_check(conf);
1858 + if ( argc > 0 ) {
1859 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1860 + for (i=0; i < argc; i++) {
1861 + pkg_name = malloc(strlen(argv[i])+2);
1862 + strcpy(pkg_name,argv[i]);
1863 + for (a=0; a < available->len; a++) {
1864 + pkg = available->pkgs[a];
1865 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1866 + continue;
1867 + }
1868 + if (conf->restrict_to_default_dest) {
1869 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1870 + pkg->name,
1871 + conf->default_dest);
1872 + } else {
1873 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1874 + }
1875 +
1876 + if (pkg == NULL) {
1877 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1878 + continue;
1879 + }
1880 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1881 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1882 + continue;
1883 + }
1884 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1885 + done = 1;
1886 + }
1887 + free (pkg_name);
1888 + }
1889 + pkg_vec_free(available);
1890 + } else {
1891 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1892 + int flagged_pkg_count = 0;
1893 + int removed;
1894 +
1895 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1896 +
1897 + for (i = 0; i < installed_pkgs->len; i++) {
1898 + pkg = installed_pkgs->pkgs[i];
1899 + if (pkg->state_flag & SF_USER) {
1900 + flagged_pkg_count++;
1901 + } else {
1902 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1903 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1904 + }
1905 + }
1906 + if (!flagged_pkg_count) {
1907 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1908 + "so refusing to uninstall unflagged non-leaf packages\n");
1909 + return 0;
1910 + }
1911 +
1912 + /* find packages not flagged SF_USER (i.e., installed to
1913 + * satisfy a dependence) and not having any dependents, and
1914 + * remove them */
1915 + do {
1916 + removed = 0;
1917 + for (i = 0; i < installed_pkgs->len; i++) {
1918 + pkg = installed_pkgs->pkgs[i];
1919 + if (!(pkg->state_flag & SF_USER)
1920 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1921 + removed++;
1922 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1923 + ipkg_remove_pkg(conf, pkg,0);
1924 + done = 1;
1925 + }
1926 + }
1927 + } while (removed);
1928 + pkg_vec_free(installed_pkgs);
1929 + }
1930 +
1931 + if ( done == 0 )
1932 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1933 +
1934 + write_status_files_if_changed(conf);
1935 + return 0;
1936 +}
1937 +
1938 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1939 +{
1940 + int i;
1941 + pkg_t *pkg;
1942 +
1943 + global_conf = conf;
1944 + signal(SIGINT, sigint_handler);
1945 +
1946 + pkg_info_preinstall_check(conf);
1947 +
1948 + for (i=0; i < argc; i++) {
1949 + if (conf->restrict_to_default_dest) {
1950 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1951 + argv[i],
1952 + conf->default_dest);
1953 + } else {
1954 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1955 + }
1956 +
1957 + if (pkg == NULL) {
1958 + ipkg_message(conf, IPKG_ERROR,
1959 + "Package %s is not installed.\n", argv[i]);
1960 + continue;
1961 + }
1962 + ipkg_purge_pkg(conf, pkg);
1963 + }
1964 +
1965 + write_status_files_if_changed(conf);
1966 + return 0;
1967 +}
1968 +
1969 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1970 +{
1971 + int i;
1972 + pkg_t *pkg;
1973 + char *flags = argv[0];
1974 +
1975 + global_conf = conf;
1976 + signal(SIGINT, sigint_handler);
1977 +
1978 + for (i=1; i < argc; i++) {
1979 + if (conf->restrict_to_default_dest) {
1980 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1981 + argv[i],
1982 + conf->default_dest);
1983 + } else {
1984 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1985 + }
1986 +
1987 + if (pkg == NULL) {
1988 + ipkg_message(conf, IPKG_ERROR,
1989 + "Package %s is not installed.\n", argv[i]);
1990 + continue;
1991 + }
1992 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1993 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1994 + pkg->state_flag = pkg_state_flag_from_str(flags);
1995 + }
1996 +/* pb_ asked this feature 03292004 */
1997 +/* Actually I will use only this two, but this is an open for various status */
1998 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1999 + pkg->state_status = pkg_state_status_from_str(flags);
2000 + }
2001 + ipkg_state_changed++;
2002 + ipkg_message(conf, IPKG_NOTICE,
2003 + "Setting flags for package %s to %s\n",
2004 + pkg->name, flags);
2005 + }
2006 +
2007 + write_status_files_if_changed(conf);
2008 + return 0;
2009 +}
2010 +
2011 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2012 +{
2013 + pkg_t *pkg;
2014 + str_list_t *installed_files;
2015 + str_list_elt_t *iter;
2016 + char *pkg_version;
2017 + size_t buff_len = 8192;
2018 + size_t used_len;
2019 + char *buff ;
2020 +
2021 + buff = (char *)malloc(buff_len);
2022 + if ( buff == NULL ) {
2023 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2024 + return ENOMEM;
2025 + }
2026 +
2027 + if (argc < 1) {
2028 + return EINVAL;
2029 + }
2030 +
2031 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2032 + argv[0]);
2033 + if (pkg == NULL) {
2034 + ipkg_message(conf, IPKG_ERROR,
2035 + "Package %s not installed.\n", argv[0]);
2036 + return 0;
2037 + }
2038 +
2039 + installed_files = pkg_get_installed_files(pkg);
2040 + pkg_version = pkg_version_str_alloc(pkg);
2041 +
2042 +#ifndef IPKG_LIB
2043 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2044 + pkg->name, pkg_version, pkg->dest->name);
2045 + for (iter = installed_files->head; iter; iter = iter->next) {
2046 + puts(iter->data);
2047 + }
2048 +#else
2049 + if (buff) {
2050 + try_again:
2051 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2052 + pkg->name, pkg_version, pkg->dest->name) + 1;
2053 + if (used_len > buff_len) {
2054 + buff_len *= 2;
2055 + buff = realloc (buff, buff_len);
2056 + goto try_again;
2057 + }
2058 + for (iter = installed_files->head; iter; iter = iter->next) {
2059 + used_len += strlen (iter->data) + 1;
2060 + while (buff_len <= used_len) {
2061 + buff_len *= 2;
2062 + buff = realloc (buff, buff_len);
2063 + }
2064 + strncat(buff, iter->data, buff_len);
2065 + strncat(buff, "\n", buff_len);
2066 + }
2067 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2068 + buff,
2069 + pkg_version_str_alloc(pkg),
2070 + pkg->state_status,
2071 + p_userdata);
2072 + free(buff);
2073 + }
2074 +#endif
2075 +
2076 + free(pkg_version);
2077 + pkg_free_installed_files(pkg);
2078 +
2079 + return 0;
2080 +}
2081 +
2082 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2083 +{
2084 +
2085 + if (argc > 0) {
2086 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2087 + const char *rel_str = "depends on";
2088 + int i;
2089 +
2090 + pkg_info_preinstall_check(conf);
2091 +
2092 + if (conf->query_all)
2093 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2094 + else
2095 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2096 + for (i = 0; i < argc; i++) {
2097 + const char *target = argv[i];
2098 + int j;
2099 +
2100 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2101 +
2102 + for (j = 0; j < available_pkgs->len; j++) {
2103 + pkg_t *pkg = available_pkgs->pkgs[j];
2104 + if (fnmatch(target, pkg->name, 0) == 0) {
2105 + int k;
2106 + int count = pkg->depends_count + pkg->pre_depends_count;
2107 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2108 + target, pkg->architecture, rel_str);
2109 + for (k = 0; k < count; k++) {
2110 + compound_depend_t *cdepend = &pkg->depends[k];
2111 + int l;
2112 + for (l = 0; l < cdepend->possibility_count; l++) {
2113 + depend_t *possibility = cdepend->possibilities[l];
2114 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2115 + if (conf->verbosity > 0) {
2116 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2117 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2118 + if (possibility->version) {
2119 + char *typestr = NULL;
2120 + switch (possibility->constraint) {
2121 + case NONE: typestr = "none"; break;
2122 + case EARLIER: typestr = "<"; break;
2123 + case EARLIER_EQUAL: typestr = "<="; break;
2124 + case EQUAL: typestr = "="; break;
2125 + case LATER_EQUAL: typestr = ">="; break;
2126 + case LATER: typestr = ">"; break;
2127 + }
2128 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2129 + }
2130 + // free(ver);
2131 + }
2132 + ipkg_message(conf, IPKG_ERROR, "\n");
2133 + }
2134 + }
2135 + }
2136 + }
2137 + }
2138 + pkg_vec_free(available_pkgs);
2139 + }
2140 + return 0;
2141 +}
2142 +
2143 +enum what_field_type {
2144 + WHATDEPENDS,
2145 + WHATCONFLICTS,
2146 + WHATPROVIDES,
2147 + WHATREPLACES,
2148 + WHATRECOMMENDS,
2149 + WHATSUGGESTS
2150 +};
2151 +
2152 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2153 +{
2154 +
2155 + if (argc > 0) {
2156 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2157 + const char *rel_str = NULL;
2158 + int i;
2159 + int changed;
2160 +
2161 + switch (what_field_type) {
2162 + case WHATDEPENDS: rel_str = "depends on"; break;
2163 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2164 + case WHATSUGGESTS: rel_str = "suggests"; break;
2165 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2166 + case WHATPROVIDES: rel_str = "provides"; break;
2167 + case WHATREPLACES: rel_str = "replaces"; break;
2168 + }
2169 +
2170 + if (conf->query_all)
2171 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2172 + else
2173 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2174 +
2175 + /* mark the root set */
2176 + pkg_vec_clear_marks(available_pkgs);
2177 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2178 + for (i = 0; i < argc; i++) {
2179 + const char *dependee_pattern = argv[i];
2180 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2181 + }
2182 + for (i = 0; i < available_pkgs->len; i++) {
2183 + pkg_t *pkg = available_pkgs->pkgs[i];
2184 + if (pkg->state_flag & SF_MARKED) {
2185 + /* mark the parent (abstract) package */
2186 + pkg_mark_provides(pkg);
2187 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2188 + }
2189 + }
2190 +
2191 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2192 + do {
2193 + int j;
2194 + changed = 0;
2195 +
2196 + for (j = 0; j < available_pkgs->len; j++) {
2197 + pkg_t *pkg = available_pkgs->pkgs[j];
2198 + int k;
2199 + int count = ((what_field_type == WHATCONFLICTS)
2200 + ? pkg->conflicts_count
2201 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2202 + /* skip this package if it is already marked */
2203 + if (pkg->parent->state_flag & SF_MARKED) {
2204 + continue;
2205 + }
2206 + for (k = 0; k < count; k++) {
2207 + compound_depend_t *cdepend =
2208 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2209 + int l;
2210 + for (l = 0; l < cdepend->possibility_count; l++) {
2211 + depend_t *possibility = cdepend->possibilities[l];
2212 + if (possibility->pkg->state_flag & SF_MARKED) {
2213 + /* mark the depending package so we won't visit it again */
2214 + pkg->state_flag |= SF_MARKED;
2215 + pkg_mark_provides(pkg);
2216 + changed++;
2217 +
2218 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2219 + if (conf->verbosity > 0) {
2220 + char *ver = pkg_version_str_alloc(pkg);
2221 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2222 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2223 + if (possibility->version) {
2224 + char *typestr = NULL;
2225 + switch (possibility->constraint) {
2226 + case NONE: typestr = "none"; break;
2227 + case EARLIER: typestr = "<"; break;
2228 + case EARLIER_EQUAL: typestr = "<="; break;
2229 + case EQUAL: typestr = "="; break;
2230 + case LATER_EQUAL: typestr = ">="; break;
2231 + case LATER: typestr = ">"; break;
2232 + }
2233 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2234 + }
2235 + free(ver);
2236 + if (!pkg_dependence_satisfiable(conf, possibility))
2237 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2238 + }
2239 + ipkg_message(conf, IPKG_NOTICE, "\n");
2240 + goto next_package;
2241 + }
2242 + }
2243 + }
2244 + next_package:
2245 + ;
2246 + }
2247 + } while (changed && recursive);
2248 + pkg_vec_free(available_pkgs);
2249 + }
2250 +
2251 + return 0;
2252 +}
2253 +
2254 +int pkg_mark_provides(pkg_t *pkg)
2255 +{
2256 + int provides_count = pkg->provides_count;
2257 + abstract_pkg_t **provides = pkg->provides;
2258 + int i;
2259 + pkg->parent->state_flag |= SF_MARKED;
2260 + for (i = 0; i < provides_count; i++) {
2261 + provides[i]->state_flag |= SF_MARKED;
2262 + }
2263 + return 0;
2264 +}
2265 +
2266 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2267 +{
2268 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2269 +}
2270 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2271 +{
2272 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2273 +}
2274 +
2275 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2276 +{
2277 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2278 +}
2279 +
2280 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2281 +{
2282 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2283 +}
2284 +
2285 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2286 +{
2287 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2288 +}
2289 +
2290 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2291 +{
2292 +
2293 + if (argc > 0) {
2294 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2295 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2296 + int i;
2297 +
2298 + pkg_info_preinstall_check(conf);
2299 +
2300 + if (conf->query_all)
2301 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2302 + else
2303 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2304 + for (i = 0; i < argc; i++) {
2305 + const char *target = argv[i];
2306 + int j;
2307 +
2308 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2309 + rel_str, target);
2310 + for (j = 0; j < available_pkgs->len; j++) {
2311 + pkg_t *pkg = available_pkgs->pkgs[j];
2312 + int k;
2313 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2314 + for (k = 0; k < count; k++) {
2315 + abstract_pkg_t *apkg =
2316 + ((what_field_type == WHATPROVIDES)
2317 + ? pkg->provides[k]
2318 + : pkg->replaces[k]);
2319 + if (fnmatch(target, apkg->name, 0) == 0) {
2320 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2321 + if (strcmp(target, apkg->name) != 0)
2322 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2323 + ipkg_message(conf, IPKG_ERROR, "\n");
2324 + }
2325 + }
2326 + }
2327 + }
2328 + pkg_vec_free(available_pkgs);
2329 + }
2330 + return 0;
2331 +}
2332 +
2333 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2334 +{
2335 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2336 +}
2337 +
2338 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2339 +{
2340 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2341 +}
2342 +
2343 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2344 +{
2345 + int i;
2346 +
2347 + pkg_vec_t *installed;
2348 + pkg_t *pkg;
2349 + str_list_t *installed_files;
2350 + str_list_elt_t *iter;
2351 + char *installed_file;
2352 +
2353 + if (argc < 1) {
2354 + return EINVAL;
2355 + }
2356 +
2357 + installed = pkg_vec_alloc();
2358 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2359 +
2360 + for (i=0; i < installed->len; i++) {
2361 + pkg = installed->pkgs[i];
2362 +
2363 + installed_files = pkg_get_installed_files(pkg);
2364 +
2365 + for (iter = installed_files->head; iter; iter = iter->next) {
2366 + installed_file = iter->data;
2367 + if (fnmatch(argv[0], installed_file, 0)==0) {
2368 +#ifndef IPKG_LIB
2369 + printf("%s: %s\n", pkg->name, installed_file);
2370 +#else
2371 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2372 + installed_file,
2373 + pkg_version_str_alloc(pkg),
2374 + pkg->state_status, p_userdata);
2375 +#endif
2376 + }
2377 + }
2378 +
2379 + pkg_free_installed_files(pkg);
2380 + }
2381 +
2382 + /* XXX: CLEANUP: It's not obvious from the name of
2383 + pkg_hash_fetch_all_installed that we need to call
2384 + pkg_vec_free to avoid a memory leak. */
2385 + pkg_vec_free(installed);
2386 +
2387 + return 0;
2388 +}
2389 +
2390 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2391 +{
2392 + if (argc == 3) {
2393 + /* this is a bit gross */
2394 + struct pkg p1, p2;
2395 + parseVersion(&p1, argv[0]);
2396 + parseVersion(&p2, argv[2]);
2397 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2398 + } else {
2399 + ipkg_message(conf, IPKG_ERROR,
2400 + "ipkg compare_versions <v1> <op> <v2>\n"
2401 + "<op> is one of <= >= << >> =\n");
2402 + return -1;
2403 + }
2404 +}
2405 +
2406 +#ifndef HOST_CPU_STR
2407 +#define HOST_CPU_STR__(X) #X
2408 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2409 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2410 +#endif
2411 +
2412 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2413 +{
2414 + nv_pair_list_elt_t *l;
2415 +
2416 + l = conf->arch_list.head;
2417 + while (l) {
2418 + nv_pair_t *nv = l->data;
2419 + printf("arch %s %s\n", nv->name, nv->value);
2420 + l = l->next;
2421 + }
2422 + return 0;
2423 +}
2424 +
2425 +
2426 Index: busybox-1.8.1/archival/libipkg/ipkg_cmd.h
2427 ===================================================================
2428 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2429 +++ busybox-1.8.1/archival/libipkg/ipkg_cmd.h 2007-11-10 17:40:53.348763971 +0100
2430 @@ -0,0 +1,46 @@
2431 +/* ipkg_cmd.h - the itsy package management system
2432 +
2433 + Carl D. Worth
2434 +
2435 + Copyright (C) 2001 University of Southern California
2436 +
2437 + This program is free software; you can redistribute it and/or
2438 + modify it under the terms of the GNU General Public License as
2439 + published by the Free Software Foundation; either version 2, or (at
2440 + your option) any later version.
2441 +
2442 + This program is distributed in the hope that it will be useful, but
2443 + WITHOUT ANY WARRANTY; without even the implied warranty of
2444 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2445 + General Public License for more details.
2446 +*/
2447 +
2448 +#ifndef IPKG_CMD_H
2449 +#define IPKG_CMD_H
2450 +
2451 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2452 +
2453 +struct ipkg_cmd
2454 +{
2455 + char *name;
2456 + int requires_args;
2457 + ipkg_cmd_fun_t fun;
2458 +};
2459 +typedef struct ipkg_cmd ipkg_cmd_t;
2460 +
2461 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2462 +#ifdef IPKG_LIB
2463 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2464 + const char **argv, void *userdata);
2465 +#else
2466 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2467 +#endif
2468 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2469 +/* install any packges with state_want == SW_INSTALL */
2470 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2471 +/* ensure that all dependences are satisfied */
2472 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2473 +
2474 +int pkg_mark_provides(pkg_t *pkg);
2475 +
2476 +#endif
2477 Index: busybox-1.8.1/archival/libipkg/ipkg_conf.c
2478 ===================================================================
2479 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2480 +++ busybox-1.8.1/archival/libipkg/ipkg_conf.c 2007-11-10 17:40:53.348763971 +0100
2481 @@ -0,0 +1,711 @@
2482 +/* ipkg_conf.c - the itsy package management system
2483 +
2484 + Carl D. Worth
2485 +
2486 + Copyright (C) 2001 University of Southern California
2487 +
2488 + This program is free software; you can redistribute it and/or
2489 + modify it under the terms of the GNU General Public License as
2490 + published by the Free Software Foundation; either version 2, or (at
2491 + your option) any later version.
2492 +
2493 + This program is distributed in the hope that it will be useful, but
2494 + WITHOUT ANY WARRANTY; without even the implied warranty of
2495 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2496 + General Public License for more details.
2497 +*/
2498 +
2499 +#include <glob.h>
2500 +
2501 +#include "ipkg.h"
2502 +#include "ipkg_conf.h"
2503 +
2504 +#include "xregex.h"
2505 +#include "sprintf_alloc.h"
2506 +#include "ipkg_conf.h"
2507 +#include "ipkg_message.h"
2508 +#include "file_util.h"
2509 +#include "str_util.h"
2510 +#include "xsystem.h"
2511 +
2512 +
2513 +ipkg_conf_t *global_conf;
2514 +
2515 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2516 + pkg_src_list_t *pkg_src_list,
2517 + nv_pair_list_t *tmp_dest_nv_pair_list,
2518 + char **tmp_lists_dir);
2519 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2520 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2521 + const char *name, const char *value);
2522 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2523 + const char *default_dest_name);
2524 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2525 + pkg_src_list_t *nv_pair_list);
2526 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2527 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2528 +
2529 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2530 +{
2531 + ipkg_option_t tmp[] = {
2532 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2533 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2534 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2535 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2536 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2537 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2538 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2539 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2540 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2541 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2542 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2543 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2544 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2545 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2546 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2547 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2548 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2549 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2550 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2551 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2552 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2553 + { NULL }
2554 + };
2555 +
2556 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2557 + if ( options == NULL ){
2558 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2559 + return -1;
2560 + }
2561 +
2562 + memcpy(*options, tmp, sizeof(tmp));
2563 + return 0;
2564 +};
2565 +
2566 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2567 +{
2568 + if (arg_str) {
2569 + if (*conf_str) {
2570 + free(*conf_str);
2571 + }
2572 + *conf_str = strdup(arg_str);
2573 + }
2574 +}
2575 +
2576 +static void ipkg_conf_free_string(char **conf_str)
2577 +{
2578 + if (*conf_str) {
2579 + free(*conf_str);
2580 + *conf_str = NULL;
2581 + }
2582 +}
2583 +
2584 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2585 +{
2586 + int err;
2587 + char *tmp_dir_base;
2588 + nv_pair_list_t tmp_dest_nv_pair_list;
2589 + char * lists_dir =NULL;
2590 + glob_t globbuf;
2591 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2592 + char *pending_dir =NULL;
2593 +
2594 + memset(conf, 0, sizeof(ipkg_conf_t));
2595 +
2596 + pkg_src_list_init(&conf->pkg_src_list);
2597 +
2598 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2599 + pkg_dest_list_init(&conf->pkg_dest_list);
2600 +
2601 + nv_pair_list_init(&conf->arch_list);
2602 +
2603 + conf->restrict_to_default_dest = 0;
2604 + conf->default_dest = NULL;
2605 +
2606 +
2607 + if (args->tmp_dir)
2608 + tmp_dir_base = args->tmp_dir;
2609 + else
2610 + tmp_dir_base = getenv("TMPDIR");
2611 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2612 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2613 + IPKG_CONF_TMP_DIR_SUFFIX);
2614 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2615 + if (conf->tmp_dir == NULL) {
2616 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2617 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2618 + return errno;
2619 + }
2620 +
2621 + conf->force_depends = 0;
2622 + conf->force_defaults = 0;
2623 + conf->force_overwrite = 0;
2624 + conf->force_downgrade = 0;
2625 + conf->force_reinstall = 0;
2626 + conf->force_space = 0;
2627 + conf->force_removal_of_essential_packages = 0;
2628 + conf->force_removal_of_dependent_packages = 0;
2629 + conf->nodeps = 0;
2630 + conf->verbose_wget = 0;
2631 + conf->offline_root = NULL;
2632 + conf->offline_root_pre_script_cmd = NULL;
2633 + conf->offline_root_post_script_cmd = NULL;
2634 + conf->multiple_providers = 0;
2635 + conf->verbosity = 1;
2636 + conf->noaction = 0;
2637 +
2638 + conf->http_proxy = NULL;
2639 + conf->ftp_proxy = NULL;
2640 + conf->no_proxy = NULL;
2641 + conf->proxy_user = NULL;
2642 + conf->proxy_passwd = NULL;
2643 +
2644 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2646 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2647 + lists_dir=(char *)malloc(1);
2648 + lists_dir[0]='\0';
2649 + if (args->conf_file) {
2650 + struct stat stat_buf;
2651 + err = stat(args->conf_file, &stat_buf);
2652 + if (err == 0)
2653 + if (ipkg_conf_parse_file(conf, args->conf_file,
2654 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2655 + /* Memory leakage from ipkg_conf_parse-file */
2656 + return -1;
2657 + }
2658 +
2659 + }
2660 +
2661 + /* if (!lists_dir ){*/
2662 + if (strlen(lists_dir)<=1 ){
2663 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2664 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2665 + }
2666 +
2667 + if (args->offline_root) {
2668 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2669 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2670 + free(lists_dir);
2671 + lists_dir = tmp;
2672 + }
2673 +
2674 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2675 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2676 +
2677 + conf->lists_dir = strdup(lists_dir);
2678 + conf->pending_dir = strdup(pending_dir);
2679 +
2680 + if (args->offline_root)
2681 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2682 + memset(&globbuf, 0, sizeof(globbuf));
2683 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2684 + if (!err) {
2685 + int i;
2686 + for (i = 0; i < globbuf.gl_pathc; i++) {
2687 + if (globbuf.gl_pathv[i])
2688 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2689 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2690 + /* Memory leakage from ipkg_conf_parse-file */
2691 + return -1;
2692 + }
2693 + }
2694 + }
2695 + globfree(&globbuf);
2696 +
2697 + /* if no architectures were defined, then default all, noarch, and host architecture */
2698 + if (nv_pair_list_empty(&conf->arch_list)) {
2699 + nv_pair_list_append(&conf->arch_list, "all", "1");
2700 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2701 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2702 + }
2703 +
2704 + /* Even if there is no conf file, we'll need at least one dest. */
2705 + if (tmp_dest_nv_pair_list.head == NULL) {
2706 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2707 + IPKG_CONF_DEFAULT_DEST_NAME,
2708 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2709 + }
2710 +
2711 + /* After parsing the file, set options from command-line, (so that
2712 + command-line arguments take precedence) */
2713 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2714 + really needs to be cleaned up. There is so much duplication
2715 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2716 + a pointer to args_t (which could then not be freed), rather
2717 + than duplicating every field here? */
2718 + if (args->force_depends) {
2719 + conf->force_depends = 1;
2720 + }
2721 + if (args->force_defaults) {
2722 + conf->force_defaults = 1;
2723 + }
2724 + if (args->force_overwrite) {
2725 + conf->force_overwrite = 1;
2726 + }
2727 + if (args->force_downgrade) {
2728 + conf->force_downgrade = 1;
2729 + }
2730 + if (args->force_reinstall) {
2731 + conf->force_reinstall = 1;
2732 + }
2733 + if (args->force_removal_of_dependent_packages) {
2734 + conf->force_removal_of_dependent_packages = 1;
2735 + }
2736 + if (args->force_removal_of_essential_packages) {
2737 + conf->force_removal_of_essential_packages = 1;
2738 + }
2739 + if (args->nodeps) {
2740 + conf->nodeps = 1;
2741 + }
2742 + if (args->noaction) {
2743 + conf->noaction = 1;
2744 + }
2745 + if (args->query_all) {
2746 + conf->query_all = 1;
2747 + }
2748 + if (args->verbose_wget) {
2749 + conf->verbose_wget = 1;
2750 + }
2751 + if (args->multiple_providers) {
2752 + conf->multiple_providers = 1;
2753 + }
2754 + if (args->verbosity != conf->verbosity) {
2755 + conf->verbosity = args->verbosity;
2756 + }
2757 +
2758 + ipkg_conf_override_string(&conf->offline_root,
2759 + args->offline_root);
2760 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2761 + args->offline_root_pre_script_cmd);
2762 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2763 + args->offline_root_post_script_cmd);
2764 +
2765 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2766 + read anything from there.
2767 +*/
2768 + if ( !(args->nocheckfordirorfile)){
2769 + /* need to run load the source list before dest list -Jamey */
2770 + if ( !(args->noreadfeedsfile))
2771 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2772 +
2773 + /* Now that we have resolved conf->offline_root, we can commit to
2774 + the directory names for the dests and load in all the package
2775 + lists. */
2776 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2777 +
2778 + if (args->dest) {
2779 + err = ipkg_conf_set_default_dest(conf, args->dest);
2780 + if (err) {
2781 + return err;
2782 + }
2783 + }
2784 + }
2785 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2786 + free(lists_dir);
2787 + free(pending_dir);
2788 +
2789 + return 0;
2790 +}
2791 +
2792 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2793 +{
2794 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2795 +#error
2796 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2797 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2798 + __FUNCTION__, conf->tmp_dir);
2799 +#else
2800 + int err;
2801 +
2802 + err = rmdir(conf->tmp_dir);
2803 + if (err) {
2804 + if (errno == ENOTEMPTY) {
2805 + char *cmd;
2806 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2807 + err = xsystem(cmd);
2808 + free(cmd);
2809 + }
2810 + if (err)
2811 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2812 + }
2813 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2814 +
2815 + free(conf->tmp_dir); /*XXX*/
2816 +
2817 + pkg_src_list_deinit(&conf->pkg_src_list);
2818 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2819 + nv_pair_list_deinit(&conf->arch_list);
2820 + if (&conf->pkg_hash)
2821 + pkg_hash_deinit(&conf->pkg_hash);
2822 + if (&conf->file_hash)
2823 + hash_table_deinit(&conf->file_hash);
2824 + if (&conf->obs_file_hash)
2825 + hash_table_deinit(&conf->obs_file_hash);
2826 +
2827 + ipkg_conf_free_string(&conf->offline_root);
2828 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2829 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2830 +
2831 + if (conf->verbosity > 1) {
2832 + int i;
2833 + hash_table_t *hashes[] = {
2834 + &conf->pkg_hash,
2835 + &conf->file_hash,
2836 + &conf->obs_file_hash };
2837 + for (i = 0; i < 3; i++) {
2838 + hash_table_t *hash = hashes[i];
2839 + int c = 0;
2840 + int n_conflicts = 0;
2841 + int j;
2842 + for (j = 0; j < hash->n_entries; j++) {
2843 + int len = 0;
2844 + hash_entry_t *e = &hash->entries[j];
2845 + if (e->next)
2846 + n_conflicts++;
2847 + while (e && e->key) {
2848 + len++;
2849 + e = e->next;
2850 + }
2851 + if (len > c)
2852 + c = len;
2853 + }
2854 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2855 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2856 + hash_table_deinit(hash);
2857 + }
2858 + }
2859 +}
2860 +
2861 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2862 + const char *default_dest_name)
2863 +{
2864 + pkg_dest_list_elt_t *iter;
2865 + pkg_dest_t *dest;
2866 +
2867 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2868 + dest = iter->data;
2869 + if (strcmp(dest->name, default_dest_name) == 0) {
2870 + conf->default_dest = dest;
2871 + conf->restrict_to_default_dest = 1;
2872 + return 0;
2873 + }
2874 + }
2875 +
2876 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2877 +
2878 + return 1;
2879 +}
2880 +
2881 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2882 +{
2883 + pkg_src_list_elt_t *iter;
2884 + pkg_src_t *src;
2885 + char *list_file;
2886 +
2887 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2888 + src = iter->data;
2889 + if (src == NULL) {
2890 + continue;
2891 + }
2892 +
2893 + sprintf_alloc(&list_file, "%s/%s",
2894 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2895 + src->name);
2896 +
2897 + if (file_exists(list_file)) {
2898 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2899 + }
2900 + free(list_file);
2901 + }
2902 +
2903 + return 0;
2904 +}
2905 +
2906 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2907 +{
2908 + nv_pair_list_elt_t *iter;
2909 + nv_pair_t *nv_pair;
2910 + pkg_dest_t *dest;
2911 + char *root_dir;
2912 +
2913 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2914 + nv_pair = iter->data;
2915 +
2916 + if (conf->offline_root) {
2917 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2918 + } else {
2919 + root_dir = strdup(nv_pair->value);
2920 + }
2921 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2922 + free(root_dir);
2923 + if (dest == NULL) {
2924 + continue;
2925 + }
2926 + if (conf->default_dest == NULL) {
2927 + conf->default_dest = dest;
2928 + }
2929 + if (file_exists(dest->status_file_name)) {
2930 + pkg_hash_add_from_file(conf, dest->status_file_name,
2931 + NULL, dest, 1);
2932 + }
2933 + }
2934 +
2935 + return 0;
2936 +}
2937 +
2938 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2939 + pkg_src_list_t *pkg_src_list,
2940 + nv_pair_list_t *tmp_dest_nv_pair_list,
2941 + char **lists_dir)
2942 +{
2943 + ipkg_option_t * options;
2944 + FILE *file = fopen(filename, "r");
2945 + regex_t valid_line_re, comment_re;
2946 +#define regmatch_size 12
2947 + regmatch_t regmatch[regmatch_size];
2948 +
2949 + if (ipkg_init_options_array(conf, &options)<0)
2950 + return ENOMEM;
2951 +
2952 + if (file == NULL) {
2953 + fprintf(stderr, "%s: failed to open %s: %s\n",
2954 + __FUNCTION__, filename, strerror(errno));
2955 + free(options);
2956 + return errno;
2957 + }
2958 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2959 +
2960 + xregcomp(&comment_re,
2961 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2962 + REG_EXTENDED);
2963 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2964 +
2965 + while(1) {
2966 + int line_num = 0;
2967 + char *line;
2968 + char *type, *name, *value, *extra;
2969 +
2970 + line = file_read_line_alloc(file);
2971 + line_num++;
2972 + if (line == NULL) {
2973 + break;
2974 + }
2975 +
2976 + str_chomp(line);
2977 +
2978 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2979 + goto NEXT_LINE;
2980 + }
2981 +
2982 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2983 + str_chomp(line);
2984 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2985 + filename, line_num, line);
2986 + goto NEXT_LINE;
2987 + }
2988 +
2989 + /* This has to be so ugly to deal with optional quotation marks */
2990 + if (regmatch[2].rm_so > 0) {
2991 + type = strndup(line + regmatch[2].rm_so,
2992 + regmatch[2].rm_eo - regmatch[2].rm_so);
2993 + } else {
2994 + type = strndup(line + regmatch[3].rm_so,
2995 + regmatch[3].rm_eo - regmatch[3].rm_so);
2996 + }
2997 + if (regmatch[5].rm_so > 0) {
2998 + name = strndup(line + regmatch[5].rm_so,
2999 + regmatch[5].rm_eo - regmatch[5].rm_so);
3000 + } else {
3001 + name = strndup(line + regmatch[6].rm_so,
3002 + regmatch[6].rm_eo - regmatch[6].rm_so);
3003 + }
3004 + if (regmatch[8].rm_so > 0) {
3005 + value = strndup(line + regmatch[8].rm_so,
3006 + regmatch[8].rm_eo - regmatch[8].rm_so);
3007 + } else {
3008 + value = strndup(line + regmatch[9].rm_so,
3009 + regmatch[9].rm_eo - regmatch[9].rm_so);
3010 + }
3011 + extra = NULL;
3012 + if (regmatch[11].rm_so > 0) {
3013 + extra = strndup (line + regmatch[11].rm_so,
3014 + regmatch[11].rm_eo - regmatch[11].rm_so);
3015 + }
3016 +
3017 + /* We use the tmp_dest_nv_pair_list below instead of
3018 + conf->pkg_dest_list because we might encounter an
3019 + offline_root option later and that would invalidate the
3020 + directories we would have computed in
3021 + pkg_dest_list_init. (We do a similar thing with
3022 + tmp_src_nv_pair_list for sake of symmetry.) */
3023 + if (strcmp(type, "option") == 0) {
3024 + ipkg_conf_set_option(options, name, value);
3025 + } else if (strcmp(type, "src") == 0) {
3026 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3027 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3028 + } else {
3029 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3030 + name, value);
3031 + }
3032 + } else if (strcmp(type, "src/gz") == 0) {
3033 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3034 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3035 + } else {
3036 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3037 + name, value);
3038 + }
3039 + } else if (strcmp(type, "dest") == 0) {
3040 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3041 + } else if (strcmp(type, "lists_dir") == 0) {
3042 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3043 + if (*lists_dir == NULL) {
3044 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3045 + free(options);
3046 + return EINVAL;
3047 + }
3048 + sprintf (*lists_dir,"%s",value);
3049 + } else if (strcmp(type, "arch") == 0) {
3050 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3051 + if (!value) {
3052 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3053 + value = strdup("10");
3054 + }
3055 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3056 + } else {
3057 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3058 + "parameter: %s %s %s\n", type, name, value);
3059 + free(options);
3060 + return EINVAL;
3061 + }
3062 +
3063 + free(type);
3064 + free(name);
3065 + free(value);
3066 + if (extra)
3067 + free (extra);
3068 +
3069 + NEXT_LINE:
3070 + free(line);
3071 + }
3072 +
3073 + free(options);
3074 + regfree(&comment_re);
3075 + regfree(&valid_line_re);
3076 + fclose(file);
3077 +
3078 + return 0;
3079 +}
3080 +
3081 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3082 + const char *name, const char *value)
3083 +{
3084 + int i = 0;
3085 + while (options[i].name) {
3086 + if (strcmp(options[i].name, name) == 0) {
3087 + switch (options[i].type) {
3088 + case IPKG_OPT_TYPE_BOOL:
3089 + *((int *)options[i].value) = 1;
3090 + return 0;
3091 + case IPKG_OPT_TYPE_INT:
3092 + if (value) {
3093 + *((int *)options[i].value) = atoi(value);
3094 + return 0;
3095 + } else {
3096 + printf("%s: Option %s need an argument\n",
3097 + __FUNCTION__, name);
3098 + return EINVAL;
3099 + }
3100 + case IPKG_OPT_TYPE_STRING:
3101 + if (value) {
3102 + *((char **)options[i].value) = strdup(value);
3103 + return 0;
3104 + } else {
3105 + printf("%s: Option %s need an argument\n",
3106 + __FUNCTION__, name);
3107 + return EINVAL;
3108 + }
3109 + }
3110 + }
3111 + i++;
3112 + }
3113 +
3114 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3115 + __FUNCTION__, name, value);
3116 + return EINVAL;
3117 +}
3118 +
3119 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3120 +{
3121 + pkg_dest_list_elt_t *iter;
3122 + pkg_dest_t *dest;
3123 + pkg_vec_t *all;
3124 + pkg_t *pkg;
3125 + register int i;
3126 + int err;
3127 +
3128 + if (conf->noaction)
3129 + return 0;
3130 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3131 + dest = iter->data;
3132 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3133 + if (dest->status_file == NULL) {
3134 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3135 + __FUNCTION__, dest->status_file_name, strerror(errno));
3136 + }
3137 + }
3138 +
3139 + all = pkg_vec_alloc();
3140 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3141 +
3142 + for(i = 0; i < all->len; i++) {
3143 + pkg = all->pkgs[i];
3144 + /* We don't need most uninstalled packages in the status file */
3145 + if (pkg->state_status == SS_NOT_INSTALLED
3146 + && (pkg->state_want == SW_UNKNOWN
3147 + || pkg->state_want == SW_DEINSTALL
3148 + || pkg->state_want == SW_PURGE)) {
3149 + continue;
3150 + }
3151 + if (!pkg) {
3152 + fprintf(stderr, "Null package\n");
3153 + }
3154 + if (pkg->dest == NULL) {
3155 + fprintf(stderr, "%s: ERROR: Can't write status for "
3156 + "package %s since it has a NULL dest\n",
3157 + __FUNCTION__, pkg->name);
3158 + continue;
3159 + }
3160 + if (pkg->dest->status_file) {
3161 + pkg_print_status(pkg, pkg->dest->status_file);
3162 + }
3163 + }
3164 +
3165 + pkg_vec_free(all);
3166 +
3167 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3168 + dest = iter->data;
3169 + if (dest->status_file) {
3170 + err = ferror(dest->status_file);
3171 + fclose(dest->status_file);
3172 + dest->status_file = NULL;
3173 + if (!err) {
3174 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3175 + } else {
3176 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3177 + "retaining old %s\n", __FUNCTION__,
3178 + dest->status_file_tmp_name, dest->status_file_name);
3179 + }
3180 + }
3181 + }
3182 +
3183 + return 0;
3184 +}
3185 +
3186 +
3187 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3188 +{
3189 + char *root_filename;
3190 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3191 + return root_filename;
3192 +}
3193 Index: busybox-1.8.1/archival/libipkg/ipkg_conf.h
3194 ===================================================================
3195 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3196 +++ busybox-1.8.1/archival/libipkg/ipkg_conf.h 2007-11-10 17:40:53.348763971 +0100
3197 @@ -0,0 +1,107 @@
3198 +/* ipkg_conf.h - the itsy package management system
3199 +
3200 + Carl D. Worth
3201 +
3202 + Copyright (C) 2001 University of Southern California
3203 +
3204 + This program is free software; you can redistribute it and/or
3205 + modify it under the terms of the GNU General Public License as
3206 + published by the Free Software Foundation; either version 2, or (at
3207 + your option) any later version.
3208 +
3209 + This program is distributed in the hope that it will be useful, but
3210 + WITHOUT ANY WARRANTY; without even the implied warranty of
3211 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3212 + General Public License for more details.
3213 +*/
3214 +
3215 +#ifndef IPKG_CONF_H
3216 +#define IPKG_CONF_H
3217 +
3218 +typedef struct ipkg_conf ipkg_conf_t;
3219 +
3220 +#include "hash_table.h"
3221 +#include "ipkg.h"
3222 +#include "args.h"
3223 +#include "pkg.h"
3224 +#include "pkg_hash.h"
3225 +#include "pkg_src_list.h"
3226 +#include "pkg_dest_list.h"
3227 +#include "nv_pair_list.h"
3228 +
3229 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3230 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3231 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3232 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3233 +
3234 +/* In case the config file defines no dest */
3235 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3236 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3237 +
3238 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3239 +
3240 +struct ipkg_conf
3241 +{
3242 + pkg_src_list_t pkg_src_list;
3243 + pkg_dest_list_t pkg_dest_list;
3244 + nv_pair_list_t arch_list;
3245 +
3246 + int restrict_to_default_dest;
3247 + pkg_dest_t *default_dest;
3248 +
3249 + char *tmp_dir;
3250 + const char *lists_dir;
3251 + const char *pending_dir;
3252 +
3253 + /* options */
3254 + int force_depends;
3255 + int force_defaults;
3256 + int force_overwrite;
3257 + int force_downgrade;
3258 + int force_reinstall;
3259 + int force_space;
3260 + int force_removal_of_dependent_packages;
3261 + int force_removal_of_essential_packages;
3262 + int nodeps; /* do not follow dependences */
3263 + int verbose_wget;
3264 + int multiple_providers;
3265 + char *offline_root;
3266 + char *offline_root_pre_script_cmd;
3267 + char *offline_root_post_script_cmd;
3268 + int query_all;
3269 + int verbosity;
3270 + int noaction;
3271 +
3272 + /* proxy options */
3273 + char *http_proxy;
3274 + char *ftp_proxy;
3275 + char *no_proxy;
3276 + char *proxy_user;
3277 + char *proxy_passwd;
3278 +
3279 + hash_table_t pkg_hash;
3280 + hash_table_t file_hash;
3281 + hash_table_t obs_file_hash;
3282 +};
3283 +
3284 +enum ipkg_option_type {
3285 + IPKG_OPT_TYPE_BOOL,
3286 + IPKG_OPT_TYPE_INT,
3287 + IPKG_OPT_TYPE_STRING
3288 +};
3289 +typedef enum ipkg_option_type ipkg_option_type_t;
3290 +
3291 +typedef struct ipkg_option ipkg_option_t;
3292 +struct ipkg_option {
3293 + const char *name;
3294 + const ipkg_option_type_t type;
3295 + const void *value;
3296 +};
3297 +
3298 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3299 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3300 +
3301 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3302 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3303 +
3304 +#endif
3305 Index: busybox-1.8.1/archival/libipkg/ipkg_configure.c
3306 ===================================================================
3307 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3308 +++ busybox-1.8.1/archival/libipkg/ipkg_configure.c 2007-11-10 17:40:53.348763971 +0100
3309 @@ -0,0 +1,40 @@
3310 +/* ipkg_configure.c - the itsy package management system
3311 +
3312 + Carl D. Worth
3313 +
3314 + Copyright (C) 2001 University of Southern California
3315 +
3316 + This program is free software; you can redistribute it and/or
3317 + modify it under the terms of the GNU General Public License as
3318 + published by the Free Software Foundation; either version 2, or (at
3319 + your option) any later version.
3320 +
3321 + This program is distributed in the hope that it will be useful, but
3322 + WITHOUT ANY WARRANTY; without even the implied warranty of
3323 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3324 + General Public License for more details.
3325 +*/
3326 +
3327 +#include "ipkg.h"
3328 +
3329 +#include "ipkg_configure.h"
3330 +
3331 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3332 +{
3333 + int err;
3334 +
3335 + /* DPKG_INCOMPATIBILITY:
3336 + dpkg actually does some conffile handling here, rather than at the
3337 + end of ipkg_install(). Do we care? */
3338 + /* DPKG_INCOMPATIBILITY:
3339 + dpkg actually includes a version number to this script call */
3340 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3341 + if (err) {
3342 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3343 + return err;
3344 + }
3345 +
3346 + ipkg_state_changed++;
3347 + return 0;
3348 +}
3349 +
3350 Index: busybox-1.8.1/archival/libipkg/ipkg_configure.h
3351 ===================================================================
3352 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3353 +++ busybox-1.8.1/archival/libipkg/ipkg_configure.h 2007-11-10 17:40:53.348763971 +0100
3354 @@ -0,0 +1,25 @@
3355 +/* ipkg_configure.h - the itsy package management system
3356 +
3357 + Carl D. Worth
3358 +
3359 + Copyright (C) 2001 University of Southern California
3360 +
3361 + This program is free software; you can redistribute it and/or
3362 + modify it under the terms of the GNU General Public License as
3363 + published by the Free Software Foundation; either version 2, or (at
3364 + your option) any later version.
3365 +
3366 + This program is distributed in the hope that it will be useful, but
3367 + WITHOUT ANY WARRANTY; without even the implied warranty of
3368 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3369 + General Public License for more details.
3370 +*/
3371 +
3372 +#ifndef IPKG_CONFIGURE_H
3373 +#define IPKG_CONFIGURE_H
3374 +
3375 +#include "ipkg_conf.h"
3376 +
3377 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3378 +
3379 +#endif
3380 Index: busybox-1.8.1/archival/libipkg/ipkg_download.c
3381 ===================================================================
3382 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3383 +++ busybox-1.8.1/archival/libipkg/ipkg_download.c 2007-11-10 17:40:53.352764197 +0100
3384 @@ -0,0 +1,195 @@
3385 +/* ipkg_download.c - the itsy package management system
3386 +
3387 + Carl D. Worth
3388 +
3389 + Copyright (C) 2001 University of Southern California
3390 +
3391 + This program is free software; you can redistribute it and/or
3392 + modify it under the terms of the GNU General Public License as
3393 + published by the Free Software Foundation; either version 2, or (at
3394 + your option) any later version.
3395 +
3396 + This program is distributed in the hope that it will be useful, but
3397 + WITHOUT ANY WARRANTY; without even the implied warranty of
3398 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3399 + General Public License for more details.
3400 +*/
3401 +
3402 +#include "ipkg.h"
3403 +#include "ipkg_download.h"
3404 +#include "ipkg_message.h"
3405 +
3406 +#include "sprintf_alloc.h"
3407 +#include "xsystem.h"
3408 +#include "file_util.h"
3409 +#include "str_util.h"
3410 +
3411 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3412 +{
3413 + int err = 0;
3414 +
3415 + char *src_basec = strdup(src);
3416 + char *src_base = basename(src_basec);
3417 + char *tmp_file_location;
3418 + char *cmd;
3419 +
3420 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3421 +
3422 + fflush(stdout);
3423 +
3424 + if (str_starts_with(src, "file:")) {
3425 + int ret;
3426 + const char *file_src = src + 5;
3427 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3428 + ret = file_copy(src + 5, dest_file_name);
3429 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3430 + return ret;
3431 + }
3432 +
3433 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3434 + err = unlink(tmp_file_location);
3435 + if (err && errno != ENOENT) {
3436 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3437 + __FUNCTION__, tmp_file_location, strerror(errno));
3438 + free(tmp_file_location);
3439 + return errno;
3440 + }
3441 +
3442 + if (conf->http_proxy) {
3443 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3444 + setenv("http_proxy", conf->http_proxy, 1);
3445 + }
3446 + if (conf->ftp_proxy) {
3447 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3448 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3449 + }
3450 + if (conf->no_proxy) {
3451 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3452 + setenv("no_proxy", conf->no_proxy, 1);
3453 + }
3454 +
3455 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3456 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3457 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3458 + conf->proxy_user ? "--proxy-user=" : "",
3459 + conf->proxy_user ? conf->proxy_user : "",
3460 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3461 + conf->proxy_passwd ? conf->proxy_passwd : "",
3462 + conf->verbose_wget ? "" : "-q",
3463 + conf->tmp_dir,
3464 + src);
3465 + err = xsystem(cmd);
3466 + if (err) {
3467 + if (err != -1) {
3468 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3469 + __FUNCTION__, err, cmd);
3470 + }
3471 + unlink(tmp_file_location);
3472 + free(tmp_file_location);
3473 + free(src_basec);
3474 + free(cmd);
3475 + return EINVAL;
3476 + }
3477 + free(cmd);
3478 +
3479 + err = file_move(tmp_file_location, dest_file_name);
3480 +
3481 + free(tmp_file_location);
3482 + free(src_basec);
3483 +
3484 + if (err) {
3485 + return err;
3486 + }
3487 +
3488 + return 0;
3489 +}
3490 +
3491 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3492 +{
3493 + int err;
3494 + char *url;
3495 +
3496 + if (pkg->src == NULL) {
3497 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3498 + pkg->name, pkg->parent->name);
3499 + return -1;
3500 + }
3501 +
3502 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3503 +
3504 + /* XXX: BUG: The pkg->filename might be something like
3505 + "../../foo.ipk". While this is correct, and exactly what we
3506 + want to use to construct url above, here we actually need to
3507 + use just the filename part, without any directory. */
3508 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3509 +
3510 + err = ipkg_download(conf, url, pkg->local_filename);
3511 + free(url);
3512 +
3513 + return err;
3514 +}
3515 +
3516 +/*
3517 + * Downloads file from url, installs in package database, return package name.
3518 + */
3519 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3520 +{
3521 + int err = 0;
3522 + pkg_t *pkg;
3523 + pkg = pkg_new();
3524 + if (pkg == NULL)
3525 + return ENOMEM;
3526 +
3527 + if (str_starts_with(url, "http://")
3528 + || str_starts_with(url, "ftp://")) {
3529 + char *tmp_file;
3530 + char *file_basec = strdup(url);
3531 + char *file_base = basename(file_basec);
3532 +
3533 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3534 + err = ipkg_download(conf, url, tmp_file);
3535 + if (err)
3536 + return err;
3537 +
3538 + err = pkg_init_from_file(pkg, tmp_file);
3539 + if (err)
3540 + return err;
3541 + pkg->local_filename = strdup(tmp_file);
3542 +
3543 + free(tmp_file);
3544 + free(file_basec);
3545 +
3546 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3547 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3548 +
3549 + err = pkg_init_from_file(pkg, url);
3550 + if (err)
3551 + return err;
3552 + pkg->local_filename = strdup(url);
3553 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3554 + pkg->provided_by_hand = 1;
3555 +
3556 + } else {
3557 + pkg_deinit(pkg);
3558 + free(pkg);
3559 + return 0;
3560 + }
3561 +
3562 + if (!pkg->architecture) {
3563 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3564 + return -EINVAL;
3565 + }
3566 +
3567 + pkg->dest = conf->default_dest;
3568 + pkg->state_want = SW_INSTALL;
3569 + pkg->state_flag |= SF_PREFER;
3570 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3571 + if ( pkg == NULL ){
3572 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3573 + return 0;
3574 + }
3575 + if (namep) {
3576 + *namep = strdup(pkg->name);
3577 + }
3578 + return 0;
3579 +}
3580 Index: busybox-1.8.1/archival/libipkg/ipkg_download.h
3581 ===================================================================
3582 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3583 +++ busybox-1.8.1/archival/libipkg/ipkg_download.h 2007-11-10 17:40:53.352764197 +0100
3584 @@ -0,0 +1,30 @@
3585 +/* ipkg_download.h - the itsy package management system
3586 +
3587 + Carl D. Worth
3588 +
3589 + Copyright (C) 2001 University of Southern California
3590 +
3591 + This program is free software; you can redistribute it and/or
3592 + modify it under the terms of the GNU General Public License as
3593 + published by the Free Software Foundation; either version 2, or (at
3594 + your option) any later version.
3595 +
3596 + This program is distributed in the hope that it will be useful, but
3597 + WITHOUT ANY WARRANTY; without even the implied warranty of
3598 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3599 + General Public License for more details.
3600 +*/
3601 +
3602 +#ifndef IPKG_DOWNLOAD_H
3603 +#define IPKG_DOWNLOAD_H
3604 +
3605 +#include "ipkg_conf.h"
3606 +
3607 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3608 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3609 +/*
3610 + * Downloads file from url, installs in package database, return package name.
3611 + */
3612 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3613 +
3614 +#endif
3615 Index: busybox-1.8.1/archival/libipkg/ipkg.h
3616 ===================================================================
3617 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3618 +++ busybox-1.8.1/archival/libipkg/ipkg.h 2007-11-10 17:40:53.352764197 +0100
3619 @@ -0,0 +1,74 @@
3620 +/* ipkg.h - the itsy package management system
3621 +
3622 + Carl D. Worth
3623 +
3624 + Copyright (C) 2001 University of Southern California
3625 +
3626 + This program is free software; you can redistribute it and/or
3627 + modify it under the terms of the GNU General Public License as
3628 + published by the Free Software Foundation; either version 2, or (at
3629 + your option) any later version.
3630 +
3631 + This program is distributed in the hope that it will be useful, but
3632 + WITHOUT ANY WARRANTY; without even the implied warranty of
3633 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3634 + General Public License for more details.
3635 +*/
3636 +
3637 +#ifndef IPKG_H
3638 +#define IPKG_H
3639 +
3640 +/*
3641 +#ifdef HAVE_CONFIG_H
3642 +#include "config.h"
3643 +#endif
3644 +*/
3645 +
3646 +#if 0
3647 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3648 +#endif
3649 +
3650 +#include "ipkg_includes.h"
3651 +#include "ipkg_conf.h"
3652 +#include "ipkg_message.h"
3653 +
3654 +#define IPKG_PKG_EXTENSION ".ipk"
3655 +#define DPKG_PKG_EXTENSION ".deb"
3656 +
3657 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3658 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3659 +
3660 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3661 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3662 +#define IPKG_INFO_DIR_SUFFIX "info"
3663 +#define IPKG_STATUS_FILE_SUFFIX "status"
3664 +
3665 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3666 +
3667 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3668 +
3669 +#define IPKG_VERSION "0.99.162"
3670 +
3671 +
3672 +enum ipkg_error {
3673 + IPKG_SUCCESS = 0,
3674 + IPKG_PKG_DEPS_UNSATISFIED,
3675 + IPKG_PKG_IS_ESSENTIAL,
3676 + IPKG_PKG_HAS_DEPENDENTS,
3677 + IPKG_PKG_HAS_NO_CANDIDATE
3678 +};
3679 +typedef enum ipkg_error ipkg_error_t;
3680 +
3681 +extern int ipkg_state_changed;
3682 +
3683 +
3684 +struct errlist {
3685 + char * errmsg;
3686 + struct errlist * next;
3687 +} ;
3688 +
3689 +extern struct errlist* error_list;
3690 +
3691 +extern ipkg_conf_t *global_conf;
3692 +
3693 +#endif
3694 Index: busybox-1.8.1/archival/libipkg/ipkg_includes.h
3695 ===================================================================
3696 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3697 +++ busybox-1.8.1/archival/libipkg/ipkg_includes.h 2007-11-10 17:40:53.352764197 +0100
3698 @@ -0,0 +1,79 @@
3699 +#ifndef IPKG_INCLUDES_H
3700 +#define IPKG_INCLUDES_H
3701 +
3702 +/* Define to 1 if you have the <memory.h> header file. */
3703 +#define HAVE_MEMORY_H 1
3704 +
3705 +/* Define to 1 if you have the <regex.h> header file. */
3706 +#define HAVE_REGEX_H 1
3707 +
3708 +/* Define to 1 if you have the <stdlib.h> header file. */
3709 +#define HAVE_STDLIB_H 1
3710 +
3711 +/* Define to 1 if you have the <strings.h> header file. */
3712 +#define HAVE_STRINGS_H 1
3713 +
3714 +/* Define to 1 if you have the <string.h> header file. */
3715 +#define HAVE_STRING_H 1
3716 +
3717 +/* Define to 1 if you have the <sys/stat.h> header file. */
3718 +#define HAVE_SYS_STAT_H 1
3719 +
3720 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3721 +#define HAVE_SYS_WAIT_H 1
3722 +
3723 +/* Define to 1 if you have the <unistd.h> header file. */
3724 +#define HAVE_UNISTD_H 1
3725 +
3726 +/* Define to 1 if you have the ANSI C header files. */
3727 +#define STDC_HEADERS 1
3728 +
3729 +
3730 +#include <stdio.h>
3731 +
3732 +#if STDC_HEADERS
3733 +# include <stdlib.h>
3734 +# include <stdarg.h>
3735 +# include <stddef.h>
3736 +# include <ctype.h>
3737 +# include <errno.h>
3738 +#else
3739 +# if HAVE_STDLIB_H
3740 +# include <stdlib.h>
3741 +# endif
3742 +#endif
3743 +
3744 +#if HAVE_REGEX_H
3745 +# include <regex.h>
3746 +#endif
3747 +
3748 +#if HAVE_STRING_H
3749 +# if !STDC_HEADERS && HAVE_MEMORY_H
3750 +# include <memory.h>
3751 +# endif
3752 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3753 +# if __GNUC__
3754 +# define __USE_GNU 1
3755 +# endif
3756 +# include <string.h>
3757 +# undef __USE_GNU
3758 +#endif
3759 +
3760 +#if HAVE_STRINGS_H
3761 +# include <strings.h>
3762 +#endif
3763 +
3764 +#if HAVE_SYS_STAT_H
3765 +# include <sys/stat.h>
3766 +#endif
3767 +
3768 +#if HAVE_SYS_WAIT_H
3769 +# include <sys/wait.h>
3770 +#endif
3771 +
3772 +#if HAVE_UNISTD_H
3773 +# include <sys/types.h>
3774 +# include <unistd.h>
3775 +#endif
3776 +
3777 +#endif /* IPKG_INCLUDES_H */
3778 Index: busybox-1.8.1/archival/libipkg/ipkg_install.c
3779 ===================================================================
3780 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3781 +++ busybox-1.8.1/archival/libipkg/ipkg_install.c 2007-11-10 17:40:53.356764426 +0100
3782 @@ -0,0 +1,1942 @@
3783 +/* ipkg_install.c - the itsy package management system
3784 +
3785 + Carl D. Worth
3786 +
3787 + Copyright (C) 2001 University of Southern California
3788 +
3789 + This program is free software; you can redistribute it and/or
3790 + modify it under the terms of the GNU General Public License as
3791 + published by the Free Software Foundation; either version 2, or (at
3792 + your option) any later version.
3793 +
3794 + This program is distributed in the hope that it will be useful, but
3795 + WITHOUT ANY WARRANTY; without even the implied warranty of
3796 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3797 + General Public License for more details.
3798 +*/
3799 +
3800 +#include "ipkg.h"
3801 +#include <errno.h>
3802 +#include <dirent.h>
3803 +#include <glob.h>
3804 +#include <time.h>
3805 +#include <signal.h>
3806 +typedef void (*sighandler_t)(int);
3807 +
3808 +#include "pkg.h"
3809 +#include "pkg_hash.h"
3810 +#include "pkg_extract.h"
3811 +
3812 +#include "ipkg_install.h"
3813 +#include "ipkg_configure.h"
3814 +#include "ipkg_download.h"
3815 +#include "ipkg_remove.h"
3816 +
3817 +#include "ipkg_utils.h"
3818 +#include "ipkg_message.h"
3819 +
3820 +#include "sprintf_alloc.h"
3821 +#include "file_util.h"
3822 +#include "str_util.h"
3823 +#include "xsystem.h"
3824 +#include "user.h"
3825 +
3826 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3827 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3828 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3829 +
3830 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3831 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3832 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3833 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3834 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3842 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3843 +
3844 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3847 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3848 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3849 +
3850 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3851 +
3852 +static int user_prefers_old_conffile(const char *file, const char *backup);
3853 +
3854 +static char *backup_filename_alloc(const char *file_name);
3855 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3856 +static int backup_exists_for(const char *file_name);
3857 +static int backup_remove(const char *file_name);
3858 +
3859 +
3860 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3861 +{
3862 + int err, cmp;
3863 + pkg_t *pkg, *old;
3864 + char *old_version, *new_version;
3865 +
3866 + pkg = pkg_new();
3867 + if (pkg == NULL) {
3868 + return ENOMEM;
3869 + }
3870 +
3871 + err = pkg_init_from_file(pkg, filename);
3872 + if (err) {
3873 + return err;
3874 + }
3875 +
3876 + if (!pkg->architecture) {
3877 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3878 + return -EINVAL;
3879 + }
3880 +
3881 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3882 + freeing the pkg that we pass in. It might be nice to clean this up
3883 + if possible. */
3884 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3885 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3886 +
3887 + pkg->local_filename = strdup(filename);
3888 +
3889 + if (old) {
3890 + old_version = pkg_version_str_alloc(old);
3891 + new_version = pkg_version_str_alloc(pkg);
3892 +
3893 + cmp = pkg_compare_versions(old, pkg);
3894 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3895 + cmp = -1 ; /* then we force ipkg to downgrade */
3896 + /* We need to use a value < 0 because in the 0 case we are asking to */
3897 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3898 + }
3899 + if (cmp > 0) {
3900 + ipkg_message(conf, IPKG_NOTICE,
3901 + "Not downgrading package %s on %s from %s to %s.\n",
3902 + old->name, old->dest->name, old_version, new_version);
3903 + pkg->state_want = SW_DEINSTALL;
3904 + pkg->state_flag |= SF_OBSOLETE;
3905 + free(old_version);
3906 + free(new_version);
3907 + return 0;
3908 + } else {
3909 + free(old_version);
3910 + free(new_version);
3911 + }
3912 + }
3913 +
3914 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3915 + return ipkg_install_pkg(conf, pkg,0);
3916 +}
3917 +
3918 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3919 +{
3920 + int cmp;
3921 + pkg_t *old, *new;
3922 + char *old_version, *new_version;
3923 +
3924 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3925 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3926 + if ( old )
3927 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3928 +
3929 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3930 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3931 + if ( new )
3932 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3933 +
3934 +/* Pigi Basically here is broken the version stuff.
3935 + What's happening is that nothing provide the version to differents
3936 + functions, so the returned struct is always the latest.
3937 + That's why the install by name don't work.
3938 +*/
3939 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3940 +
3941 + if ( old )
3942 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3943 + if ( new )
3944 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3945 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3946 +
3947 + if (new == NULL) {
3948 + return IPKG_PKG_HAS_NO_CANDIDATE;
3949 + }
3950 +
3951 + new->state_flag |= SF_USER;
3952 + if (old) {
3953 + old_version = pkg_version_str_alloc(old);
3954 + new_version = pkg_version_str_alloc(new);
3955 +
3956 + cmp = pkg_compare_versions(old, new);
3957 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3958 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3959 + cmp = -1 ; /* then we force ipkg to downgrade */
3960 + /* We need to use a value < 0 because in the 0 case we are asking to */
3961 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3962 + }
3963 + ipkg_message(conf, IPKG_DEBUG,
3964 + "Comparing visible versions of pkg %s:"
3965 + "\n\t%s is installed "
3966 + "\n\t%s is available "
3967 + "\n\t%d was comparison result\n",
3968 + pkg_name, old_version, new_version, cmp);
3969 + if (cmp == 0 && !conf->force_reinstall) {
3970 + ipkg_message(conf, IPKG_NOTICE,
3971 + "Package %s (%s) installed in %s is up to date.\n",
3972 + old->name, old_version, old->dest->name);
3973 + free(old_version);
3974 + free(new_version);
3975 + return 0;
3976 + } else if (cmp > 0) {
3977 + ipkg_message(conf, IPKG_NOTICE,
3978 + "Not downgrading package %s on %s from %s to %s.\n",
3979 + old->name, old->dest->name, old_version, new_version);
3980 + free(old_version);
3981 + free(new_version);
3982 + return 0;
3983 + } else if (cmp < 0) {
3984 + new->dest = old->dest;
3985 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3986 + }
3987 + }
3988 +
3989 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3990 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3991 + return any kind of integer, (might be errno from a syscall,
3992 + etc.). This is a real mess and will need to be cleaned up if
3993 + anyone ever wants to make a nice libipkg. */
3994 +
3995 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3996 + return ipkg_install_pkg(conf, new,0);
3997 +}
3998 +
3999 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4000 +{
4001 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4002 + int i;
4003 + ipkg_error_t err;
4004 + abstract_pkg_t *ppkg ;
4005 +
4006 + if (providers == NULL)
4007 + return IPKG_PKG_HAS_NO_CANDIDATE;
4008 +
4009 + for (i = 0; i < providers->len; i++) {
4010 + ppkg = abstract_pkg_vec_get(providers, i);
4011 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4012 + err = ipkg_install_by_name(conf, ppkg->name);
4013 + if (err)
4014 + return err;
4015 +/* XXX Maybe ppkg should be freed ? */
4016 + }
4017 + return 0;
4018 +}
4019 +
4020 +/*
4021 + * Walk dependence graph starting with pkg, collect packages to be
4022 + * installed into pkgs_needed, in dependence order.
4023 + */
4024 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4025 +{
4026 + int i, err;
4027 + pkg_vec_t *depends = pkg_vec_alloc();
4028 + char **unresolved = NULL;
4029 + int ndepends;
4030 +
4031 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4032 + pkg, depends,
4033 + &unresolved);
4034 +
4035 + if (unresolved) {
4036 + ipkg_message(conf, IPKG_ERROR,
4037 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4038 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4039 + while (*unresolved) {
4040 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4041 + unresolved++;
4042 + }
4043 + ipkg_message(conf, IPKG_ERROR, "\n");
4044 + if (! conf->force_depends) {
4045 + ipkg_message(conf, IPKG_INFO,
4046 + "This could mean that your package list is out of date or that the packages\n"
4047 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4048 + "of this problem try again with the '-force-depends' option.\n");
4049 + pkg_vec_free(depends);
4050 + return IPKG_PKG_DEPS_UNSATISFIED;
4051 + }
4052 + }
4053 +
4054 + if (ndepends <= 0) {
4055 + pkg_vec_free(depends);
4056 + return 0;
4057 + }
4058 +
4059 + for (i = 0; i < depends->len; i++) {
4060 + pkg_t *dep = depends->pkgs[i];
4061 + /* The package was uninstalled when we started, but another
4062 + dep earlier in this loop may have depended on it and pulled
4063 + it in, so check first. */
4064 + if ((dep->state_status != SS_INSTALLED)
4065 + && (dep->state_status != SS_UNPACKED)
4066 + && (dep->state_want != SW_INSTALL)) {
4067 +
4068 + /* Mark packages as to-be-installed */
4069 + dep->state_want = SW_INSTALL;
4070 +
4071 + /* Dependencies should be installed the same place as pkg */
4072 + if (dep->dest == NULL) {
4073 + dep->dest = pkg->dest;
4074 + }
4075 +
4076 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4077 + if (err) {
4078 + pkg_vec_free(depends);
4079 + return err;
4080 + }
4081 + }
4082 + }
4083 + if (pkgs_needed)
4084 + pkg_vec_insert(pkgs_needed, pkg);
4085 +
4086 + pkg_vec_free(depends);
4087 +
4088 + return 0;
4089 +}
4090 +
4091 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4092 +{
4093 + int cmp;
4094 + pkg_t *old, *new;
4095 + char *old_version, *new_version;
4096 +
4097 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4098 +
4099 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4100 + if (new == NULL) {
4101 + return IPKG_PKG_HAS_NO_CANDIDATE;
4102 + }
4103 + if (old) {
4104 + old_version = pkg_version_str_alloc(old);
4105 + new_version = pkg_version_str_alloc(new);
4106 +
4107 + cmp = pkg_compare_versions(old, new);
4108 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4109 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4110 + cmp = -1 ; /* then we force ipkg to downgrade */
4111 + /* We need to use a value < 0 because in the 0 case we are asking to */
4112 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4113 + }
4114 + ipkg_message(conf, IPKG_DEBUG,
4115 + "comparing visible versions of pkg %s:"
4116 + "\n\t%s is installed "
4117 + "\n\t%s is available "
4118 + "\n\t%d was comparison result\n",
4119 + pkg_name, old_version, new_version, cmp);
4120 + if (cmp == 0 && !conf->force_reinstall) {
4121 + ipkg_message(conf, IPKG_NOTICE,
4122 + "Package %s (%s) installed in %s is up to date.\n",
4123 + old->name, old_version, old->dest->name);
4124 + free(old_version);
4125 + free(new_version);
4126 + return 0;
4127 + } else if (cmp > 0) {
4128 + ipkg_message(conf, IPKG_NOTICE,
4129 + "Not downgrading package %s on %s from %s to %s.\n",
4130 + old->name, old->dest->name, old_version, new_version);
4131 + free(old_version);
4132 + free(new_version);
4133 + return 0;
4134 + } else if (cmp < 0) {
4135 + new->dest = old->dest;
4136 + old->state_want = SW_DEINSTALL;
4137 + old->state_flag |= SF_OBSOLETE;
4138 + }
4139 + }
4140 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4141 +}
4142 +
4143 +\f
4144 +
4145 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4146 +{
4147 + int i, err;
4148 + pkg_vec_t *depends = pkg_vec_alloc();
4149 + pkg_t *dep;
4150 + char **unresolved = NULL;
4151 + int ndepends;
4152 +
4153 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4154 + pkg, depends,
4155 + &unresolved);
4156 +
4157 + if (unresolved) {
4158 + ipkg_message(conf, IPKG_ERROR,
4159 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4160 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4161 + while (*unresolved) {
4162 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4163 + unresolved++;
4164 + }
4165 + ipkg_message(conf, IPKG_ERROR, "\n");
4166 + if (! conf->force_depends) {
4167 + ipkg_message(conf, IPKG_INFO,
4168 + "This could mean that your package list is out of date or that the packages\n"
4169 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4170 + "of this problem try again with the '-force-depends' option.\n");
4171 + pkg_vec_free(depends);
4172 + return IPKG_PKG_DEPS_UNSATISFIED;
4173 + }
4174 + }
4175 +
4176 + if (ndepends <= 0) {
4177 + return 0;
4178 + }
4179 +
4180 + /* Mark packages as to-be-installed */
4181 + for (i=0; i < depends->len; i++) {
4182 + /* Dependencies should be installed the same place as pkg */
4183 + if (depends->pkgs[i]->dest == NULL) {
4184 + depends->pkgs[i]->dest = pkg->dest;
4185 + }
4186 + depends->pkgs[i]->state_want = SW_INSTALL;
4187 + }
4188 +
4189 + for (i = 0; i < depends->len; i++) {
4190 + dep = depends->pkgs[i];
4191 + /* The package was uninstalled when we started, but another
4192 + dep earlier in this loop may have depended on it and pulled
4193 + it in, so check first. */
4194 + if ((dep->state_status != SS_INSTALLED)
4195 + && (dep->state_status != SS_UNPACKED)) {
4196 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4197 + err = ipkg_install_pkg(conf, dep,0);
4198 + if (err) {
4199 + pkg_vec_free(depends);
4200 + return err;
4201 + }
4202 + }
4203 + }
4204 +
4205 + pkg_vec_free(depends);
4206 +
4207 + return 0;
4208 +}
4209 +
4210 +
4211 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4212 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4213 +{
4214 + if (conf->nodeps == 0) {
4215 + int i;
4216 + pkg_vec_t *installed = pkg_vec_alloc();
4217 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4218 + for (i = 0; i < installed->len; i++) {
4219 + pkg_t *pkg = installed->pkgs[i];
4220 + satisfy_dependencies_for(conf, pkg);
4221 + }
4222 + pkg_vec_free(installed);
4223 + }
4224 + return 0;
4225 +}
4226 +
4227 +\f
4228 +
4229 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4230 +{
4231 + int i;
4232 + pkg_vec_t *conflicts = NULL;
4233 + int level;
4234 + const char *prefix;
4235 + if (conf->force_depends) {
4236 + level = IPKG_NOTICE;
4237 + prefix = "Warning";
4238 + } else {
4239 + level = IPKG_ERROR;
4240 + prefix = "ERROR";
4241 + }
4242 +
4243 + if (!conf->force_depends)
4244 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4245 +
4246 + if (conflicts) {
4247 + ipkg_message(conf, level,
4248 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4249 + i = 0;
4250 + while (i < conflicts->len)
4251 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4252 + ipkg_message(conf, level, "\n");
4253 + pkg_vec_free(conflicts);
4254 + return IPKG_PKG_DEPS_UNSATISFIED;
4255 + }
4256 + return 0;
4257 +}
4258 +
4259 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4260 +{
4261 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4262 + str_list_elt_t *iter;
4263 +
4264 + for (iter = new_list->head; iter; iter = iter->next) {
4265 + char *new_file = iter->data;
4266 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4267 + if (!new_file)
4268 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4269 + if (!owner || (owner == old_pkg))
4270 + file_hash_set_file_owner(conf, new_file, new_pkg);
4271 + }
4272 + if (old_pkg) {
4273 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4274 + for (iter = old_list->head; iter; iter = iter->next) {
4275 + char *old_file = iter->data;
4276 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4277 + if (owner == old_pkg) {
4278 + /* obsolete */
4279 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4280 + }
4281 + }
4282 + }
4283 + return 0;
4284 +}
4285 +
4286 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4287 +{
4288 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4289 +
4290 + /* sma 6.20.02: yup; here's the first bit */
4291 + /*
4292 + * XXX: BUG easy for cworth
4293 + * 1) please point the call below to the correct current root destination
4294 + * 2) we need to resolve how to check the required space for a pending pkg,
4295 + * my diddling with the .ipk file size below isn't going to cut it.
4296 + * 3) return a proper error code instead of 1
4297 + */
4298 + int comp_size, blocks_available;
4299 +
4300 + if (!conf->force_space && pkg->installed_size != NULL) {
4301 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4302 +
4303 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4304 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4305 + comp_size = (int)((comp_size + 1023) / 1024);
4306 +
4307 + if (comp_size >= blocks_available) {
4308 + ipkg_message(conf, IPKG_ERROR,
4309 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4310 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4311 + return ENOSPC;
4312 + }
4313 + }
4314 + return 0;
4315 +}
4316 +
4317 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4318 +{
4319 + int err;
4320 + char *conffiles_file_name;
4321 + char *root_dir;
4322 + FILE *conffiles_file;
4323 +
4324 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4325 +
4326 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4327 + if (pkg->tmp_unpack_dir == NULL) {
4328 + ipkg_message(conf, IPKG_ERROR,
4329 + "%s: Failed to create temporary directory '%s': %s\n",
4330 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4331 + return errno;
4332 + }
4333 +
4334 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4335 + if (err) {
4336 + return err;
4337 + }
4338 +
4339 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4340 + conffiles. Seems like I should be able to get everything to go
4341 + through pkg_init_from_file. If so, maybe it would make sense to
4342 + move all of unpack_pkg_control_files to that function. */
4343 +
4344 + /* Don't need to re-read conffiles if we already have it */
4345 + if (pkg->conffiles.head) {
4346 + return 0;
4347 + }
4348 +
4349 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4350 + if (! file_exists(conffiles_file_name)) {
4351 + free(conffiles_file_name);
4352 + return 0;
4353 + }
4354 +
4355 + conffiles_file = fopen(conffiles_file_name, "r");
4356 + if (conffiles_file == NULL) {
4357 + fprintf(stderr, "%s: failed to open %s: %s\n",
4358 + __FUNCTION__, conffiles_file_name, strerror(errno));
4359 + free(conffiles_file_name);
4360 + return errno;
4361 + }
4362 + free(conffiles_file_name);
4363 +
4364 + while (1) {
4365 + char *cf_name;
4366 + char *cf_name_in_dest;
4367 +
4368 + cf_name = file_read_line_alloc(conffiles_file);
4369 + if (cf_name == NULL) {
4370 + break;
4371 + }
4372 + str_chomp(cf_name);
4373 + if (cf_name[0] == '\0') {
4374 + continue;
4375 + }
4376 +
4377 + /* Prepend dest->root_dir to conffile name.
4378 + Take pains to avoid multiple slashes. */
4379 + root_dir = pkg->dest->root_dir;
4380 + if (conf->offline_root)
4381 + /* skip the offline_root prefix */
4382 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4383 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4384 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4385 +
4386 + /* Can't get an md5sum now, (file isn't extracted yet).
4387 + We'll wait until resolve_conffiles */
4388 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4389 +
4390 + free(cf_name);
4391 + free(cf_name_in_dest);
4392 + }
4393 +
4394 + fclose(conffiles_file);
4395 +
4396 + return 0;
4397 +}
4398 +
4399 +/* returns number of installed replacees */
4400 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4401 +{
4402 + abstract_pkg_t **replaces = pkg->replaces;
4403 + int replaces_count = pkg->replaces_count;
4404 + int i, j;
4405 + for (i = 0; i < replaces_count; i++) {
4406 + abstract_pkg_t *ab_pkg = replaces[i];
4407 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4408 + if (pkg_vec) {
4409 + for (j = 0; j < pkg_vec->len; j++) {
4410 + pkg_t *replacee = pkg_vec->pkgs[j];
4411 + if (!pkg_conflicts(pkg, replacee))
4412 + continue;
4413 + if (replacee->state_status == SS_INSTALLED) {
4414 + pkg_vec_insert(installed_replacees, replacee);
4415 + }
4416 + }
4417 + }
4418 + }
4419 + return installed_replacees->len;
4420 +}
4421 +
4422 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4423 +{
4424 + int i;
4425 + int replaces_count = replacees->len;
4426 + for (i = 0; i < replaces_count; i++) {
4427 + pkg_t *replacee = replacees->pkgs[i];
4428 + int err;
4429 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4430 + err = ipkg_remove_pkg(conf, replacee,0);
4431 + if (err)
4432 + return err;
4433 + }
4434 + return 0;
4435 +}
4436 +
4437 +/* to unwind the removal: make sure they are installed */
4438 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4439 +{
4440 + int i, err;
4441 + int replaces_count = replacees->len;
4442 + for (i = 0; i < replaces_count; i++) {
4443 + pkg_t *replacee = replacees->pkgs[i];
4444 + if (replacee->state_status != SS_INSTALLED) {
4445 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4446 + err = ipkg_install_pkg(conf, replacee,0);
4447 + if (err)
4448 + return err;
4449 + }
4450 + }
4451 + return 0;
4452 +}
4453 +
4454 +int caught_sigint = 0;
4455 +static void ipkg_install_pkg_sigint_handler(int sig)
4456 +{
4457 + caught_sigint = sig;
4458 +}
4459 +
4460 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4461 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4462 +{
4463 + if (old_pkg) {
4464 + char message_out[15];
4465 + char *old_version = pkg_version_str_alloc(old_pkg);
4466 + char *new_version = pkg_version_str_alloc(pkg);
4467 + int cmp = pkg_compare_versions(old_pkg, pkg);
4468 + int rc = 0;
4469 +
4470 + memset(message_out,'\x0',15);
4471 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4472 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4473 + cmp = -1 ; /* then we force ipkg to downgrade */
4474 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4475 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4476 + }
4477 +
4478 + if (cmp > 0) {
4479 + ipkg_message(conf, IPKG_NOTICE,
4480 + "Not downgrading package %s on %s from %s to %s.\n",
4481 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4482 + rc = 1;
4483 + } else if (cmp < 0) {
4484 + ipkg_message(conf, IPKG_NOTICE,
4485 + "%s%s on %s from %s to %s...\n",
4486 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4487 + pkg->dest = old_pkg->dest;
4488 + rc = 0;
4489 + } else /* cmp == 0 */ {
4490 + if (conf->force_reinstall) {
4491 + ipkg_message(conf, IPKG_NOTICE,
4492 + "Reinstalling %s (%s) on %s...\n",
4493 + pkg->name, new_version, old_pkg->dest->name);
4494 + pkg->dest = old_pkg->dest;
4495 + rc = 0;
4496 + } else {
4497 + ipkg_message(conf, IPKG_NOTICE,
4498 + "Not installing %s (%s) on %s -- already installed.\n",
4499 + pkg->name, new_version, old_pkg->dest->name);
4500 + rc = 1;
4501 + }
4502 + }
4503 + free(old_version);
4504 + free(new_version);
4505 + return rc;
4506 + } else {
4507 + char message_out[15], *version ;
4508 + memset(message_out,'\x0',15);
4509 + if ( message )
4510 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4511 + else
4512 + strncpy( message_out,"Installing ",strlen("Installing ") );
4513 + version = pkg_version_str_alloc(pkg);
4514 +
4515 + ipkg_message(conf, IPKG_NOTICE,
4516 + "%s%s (%s) to %s...\n", message_out,
4517 + pkg->name, version, pkg->dest->name);
4518 + free(version);
4519 + return 0;
4520 + }
4521 +}
4522 +
4523 +/* and now the meat... */
4524 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4525 +{
4526 + int err = 0;
4527 + int message = 0;
4528 + pkg_t *old_pkg = NULL;
4529 + pkg_vec_t *replacees;
4530 + abstract_pkg_t *ab_pkg = NULL;
4531 + int old_state_flag;
4532 + char* file_md5;
4533 +
4534 +
4535 + if ( from_upgrade )
4536 + message = 1; /* Coming from an upgrade, and should change the output message */
4537 +
4538 + if (!pkg) {
4539 + ipkg_message(conf, IPKG_ERROR,
4540 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4541 + return -EINVAL;
4542 + }
4543 +
4544 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4545 +
4546 + if (!pkg_arch_supported(conf, pkg)) {
4547 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4548 + pkg->architecture, pkg->name);
4549 + return -EINVAL;
4550 + }
4551 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4552 + err = satisfy_dependencies_for(conf, pkg);
4553 + if (err) { return err; }
4554 +
4555 + ipkg_message(conf, IPKG_NOTICE,
4556 + "Package %s is already installed in %s.\n",
4557 + pkg->name, pkg->dest->name);
4558 + return 0;
4559 + }
4560 +
4561 + if (pkg->dest == NULL) {
4562 + pkg->dest = conf->default_dest;
4563 + }
4564 +
4565 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4566 +
4567 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4568 + if (err) { return err; }
4569 +
4570 + pkg->state_want = SW_INSTALL;
4571 + if (old_pkg){
4572 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4573 + }
4574 +
4575 +
4576 + /* Abhaya: conflicts check */
4577 + err = check_conflicts_for(conf, pkg);
4578 + if (err) { return err; }
4579 +
4580 + /* this setup is to remove the upgrade scenario in the end when
4581 + installing pkg A, A deps B & B deps on A. So both B and A are
4582 + installed. Then A's installation is started resulting in an
4583 + uncecessary upgrade */
4584 + if (pkg->state_status == SS_INSTALLED
4585 + && conf->force_reinstall == 0) return 0;
4586 +
4587 + err = verify_pkg_installable(conf, pkg);
4588 + if (err) { return err; }
4589 +
4590 + if (pkg->local_filename == NULL) {
4591 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4592 + if (err) {
4593 + ipkg_message(conf, IPKG_ERROR,
4594 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4595 + pkg->name);
4596 + return err;
4597 + }
4598 + }
4599 +
4600 +/* Check for md5 values */
4601 + if (pkg->md5sum)
4602 + {
4603 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4604 + if (strcmp(file_md5, pkg->md5sum))
4605 + {
4606 + ipkg_message(conf, IPKG_ERROR,
4607 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4608 + pkg->name);
4609 + free(file_md5);
4610 + return err;
4611 + }
4612 + free(file_md5);
4613 + }
4614 +
4615 + if (pkg->tmp_unpack_dir == NULL) {
4616 + unpack_pkg_control_files(conf, pkg);
4617 + }
4618 +
4619 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4620 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4621 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4622 + err = update_file_ownership(conf, pkg, old_pkg);
4623 + if (err) { return err; }
4624 +
4625 + if (conf->nodeps == 0) {
4626 + err = satisfy_dependencies_for(conf, pkg);
4627 + if (err) { return err; }
4628 + }
4629 +
4630 + replacees = pkg_vec_alloc();
4631 + pkg_get_installed_replacees(conf, pkg, replacees);
4632 +
4633 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4634 + {
4635 + sigset_t newset, oldset;
4636 + sighandler_t old_handler = NULL;
4637 + int use_signal = 0;
4638 + caught_sigint = 0;
4639 + if (use_signal) {
4640 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4641 + } else {
4642 + sigemptyset(&newset);
4643 + sigaddset(&newset, SIGINT);
4644 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4645 + }
4646 +
4647 + ipkg_state_changed++;
4648 + pkg->state_flag |= SF_FILELIST_CHANGED;
4649 +
4650 + /* XXX: BUG: we really should treat replacement more like an upgrade
4651 + * Instead, we're going to remove the replacees
4652 + */
4653 + err = pkg_remove_installed_replacees(conf, replacees);
4654 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4655 +
4656 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4657 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4658 +
4659 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4660 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4661 +
4662 + err = preinst_configure(conf, pkg, old_pkg);
4663 + if (err) goto UNWIND_PREINST_CONFIGURE;
4664 +
4665 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4666 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4667 +
4668 + err = check_data_file_clashes(conf, pkg, old_pkg);
4669 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4670 +
4671 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4672 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4673 +
4674 + if (conf->noaction) return 0;
4675 +
4676 + /* point of no return: no unwinding after this */
4677 + if (old_pkg && !conf->force_reinstall) {
4678 + old_pkg->state_want = SW_DEINSTALL;
4679 +
4680 + if (old_pkg->state_flag & SF_NOPRUNE) {
4681 + ipkg_message(conf, IPKG_INFO,
4682 + " not removing obsolesced files because package marked noprune\n");
4683 + } else {
4684 + ipkg_message(conf, IPKG_INFO,
4685 + " removing obsolesced files\n");
4686 + remove_obsolesced_files(conf, pkg, old_pkg);
4687 + }
4688 + /* removing files from old package, to avoid ghost files */
4689 + remove_data_files_and_list(conf, old_pkg);
4690 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4691 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4692 + remove_postrm(conf, old_pkg);
4693 +/* Pigi */
4694 +
4695 + }
4696 +
4697 +
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " installing maintainer scripts\n");
4700 + install_maintainer_scripts(conf, pkg, old_pkg);
4701 +
4702 + /* the following just returns 0 */
4703 + remove_disappeared(conf, pkg);
4704 +
4705 + ipkg_message(conf, IPKG_INFO,
4706 + " installing data files\n");
4707 + install_data_files(conf, pkg);
4708 +
4709 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4710 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4711 +
4712 + ipkg_message(conf, IPKG_INFO,
4713 + " resolving conf files\n");
4714 + resolve_conffiles(conf, pkg);
4715 +
4716 + pkg->state_status = SS_UNPACKED;
4717 + old_state_flag = pkg->state_flag;
4718 + pkg->state_flag &= ~SF_PREFER;
4719 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4720 +
4721 + if (old_pkg && !conf->force_reinstall) {
4722 + old_pkg->state_status = SS_NOT_INSTALLED;
4723 + }
4724 +
4725 + time(&pkg->installed_time);
4726 +
4727 + ipkg_message(conf, IPKG_INFO,
4728 + " cleanup temp files\n");
4729 + cleanup_temporary_files(conf, pkg);
4730 +
4731 + ab_pkg = pkg->parent;
4732 + if (ab_pkg)
4733 + ab_pkg->state_status = pkg->state_status;
4734 +
4735 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4736 +
4737 + if (use_signal)
4738 + signal(SIGINT, old_handler);
4739 + else
4740 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4741 +
4742 + return 0;
4743 +
4744 +
4745 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4746 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4747 + UNWIND_CHECK_DATA_FILE_CLASHES:
4748 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4749 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4750 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4751 + UNWIND_PREINST_CONFIGURE:
4752 + preinst_configure_unwind(conf, pkg, old_pkg);
4753 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4754 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4755 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4756 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4757 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4758 + pkg_remove_installed_replacees_unwind(conf, replacees);
4759 +
4760 + ipkg_message(conf, IPKG_INFO,
4761 + " cleanup temp files\n");
4762 + cleanup_temporary_files(conf, pkg);
4763 +
4764 + ipkg_message(conf, IPKG_INFO,
4765 + "Failed.\n");
4766 + if (use_signal)
4767 + signal(SIGINT, old_handler);
4768 + else
4769 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4770 +
4771 + return err;
4772 + }
4773 +}
4774 +
4775 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4776 +{
4777 + /* DPKG_INCOMPATIBILITY:
4778 + dpkg does some things here that we don't do yet. Do we care?
4779 +
4780 + 1. If a version of the package is already installed, call
4781 + old-prerm upgrade new-version
4782 + 2. If the script runs but exits with a non-zero exit status
4783 + new-prerm failed-upgrade old-version
4784 + Error unwind, for both the above cases:
4785 + old-postinst abort-upgrade new-version
4786 + */
4787 + return 0;
4788 +}
4789 +
4790 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4791 +{
4792 + /* DPKG_INCOMPATIBILITY:
4793 + dpkg does some things here that we don't do yet. Do we care?
4794 + (See prerm_upgrade_old_package for details)
4795 + */
4796 + return 0;
4797 +}
4798 +
4799 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4800 +{
4801 + /* DPKG_INCOMPATIBILITY:
4802 + dpkg does some things here that we don't do yet. Do we care?
4803 + 2. If a 'conflicting' package is being removed at the same time:
4804 + 1. If any packages depended on that conflicting package and
4805 + --auto-deconfigure is specified, call, for each such package:
4806 + deconfigured's-prerm deconfigure \
4807 + in-favour package-being-installed version \
4808 + removing conflicting-package version
4809 + Error unwind:
4810 + deconfigured's-postinst abort-deconfigure \
4811 + in-favour package-being-installed-but-failed version \
4812 + removing conflicting-package version
4813 +
4814 + The deconfigured packages are marked as requiring
4815 + configuration, so that if --install is used they will be
4816 + configured again if possible.
4817 + 2. To prepare for removal of the conflicting package, call:
4818 + conflictor's-prerm remove in-favour package new-version
4819 + Error unwind:
4820 + conflictor's-postinst abort-remove in-favour package new-version
4821 + */
4822 + return 0;
4823 +}
4824 +
4825 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4826 +{
4827 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4828 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4829 + details) */
4830 + return 0;
4831 +}
4832 +
4833 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4834 +{
4835 + int err;
4836 + char *preinst_args;
4837 +
4838 + if (old_pkg) {
4839 + char *old_version = pkg_version_str_alloc(old_pkg);
4840 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4841 + free(old_version);
4842 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4843 + char *pkg_version = pkg_version_str_alloc(pkg);
4844 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4845 + free(pkg_version);
4846 + } else {
4847 + preinst_args = strdup("install");
4848 + }
4849 +
4850 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4851 + if (err) {
4852 + ipkg_message(conf, IPKG_ERROR,
4853 + "Aborting installation of %s\n", pkg->name);
4854 + return 1;
4855 + }
4856 +
4857 + free(preinst_args);
4858 +
4859 + return 0;
4860 +}
4861 +
4862 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4863 +{
4864 + /* DPKG_INCOMPATIBILITY:
4865 + dpkg does the following error unwind, should we?
4866 + pkg->postrm abort-upgrade old-version
4867 + OR pkg->postrm abort-install old-version
4868 + OR pkg->postrm abort-install
4869 + */
4870 + return 0;
4871 +}
4872 +
4873 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4874 +{
4875 + int err;
4876 + conffile_list_elt_t *iter;
4877 + conffile_t *cf;
4878 +
4879 + if (conf->noaction) return 0;
4880 +
4881 + /* Backup all modified conffiles */
4882 + if (old_pkg) {
4883 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4884 + char *cf_name;
4885 +
4886 + cf = iter->data;
4887 + cf_name = root_filename_alloc(conf, cf->name);
4888 +
4889 + /* Don't worry if the conffile is just plain gone */
4890 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4891 + err = backup_make_backup(conf, cf_name);
4892 + if (err) {
4893 + return err;
4894 + }
4895 + }
4896 + free(cf_name);
4897 + }
4898 + }
4899 +
4900 + /* Backup all conffiles that were not conffiles in old_pkg */
4901 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4902 + char *cf_name;
4903 + cf = iter->data;
4904 + cf_name = root_filename_alloc(conf, cf->name);
4905 + /* Ignore if this was a conffile in old_pkg as well */
4906 + if (pkg_get_conffile(old_pkg, cf->name)) {
4907 + continue;
4908 + }
4909 +
4910 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4911 + err = backup_make_backup(conf, cf_name);
4912 + if (err) {
4913 + return err;
4914 + }
4915 + }
4916 + free(cf_name);
4917 + }
4918 +
4919 + return 0;
4920 +}
4921 +
4922 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4923 +{
4924 + conffile_list_elt_t *iter;
4925 +
4926 + if (old_pkg) {
4927 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4928 + backup_remove(iter->data->name);
4929 + }
4930 + }
4931 +
4932 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4933 + backup_remove(iter->data->name);
4934 + }
4935 +
4936 + return 0;
4937 +}
4938 +
4939 +
4940 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4941 +{
4942 + /* DPKG_INCOMPATIBILITY:
4943 + ipkg takes a slightly different approach than dpkg at this
4944 + point. dpkg installs each file in the new package while
4945 + creating a backup for any file that is replaced, (so that it
4946 + can unwind if necessary). To avoid complexity and redundant
4947 + storage, ipkg doesn't do any installation until later, (at the
4948 + point at which dpkg removes the backups.
4949 +
4950 + But, we do have to check for data file clashes, since after
4951 + installing a package with a file clash, removing either of the
4952 + packages involved in the clash has the potential to break the
4953 + other package.
4954 + */
4955 + str_list_t *files_list;
4956 + str_list_elt_t *iter;
4957 +
4958 + int clashes = 0;
4959 +
4960 + files_list = pkg_get_installed_files(pkg);
4961 + for (iter = files_list->head; iter; iter = iter->next) {
4962 + char *root_filename;
4963 + char *filename = iter->data;
4964 + root_filename = root_filename_alloc(conf, filename);
4965 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4966 + pkg_t *owner;
4967 + pkg_t *obs;
4968 + /* Pre-existing conffiles are OK */
4969 + /* @@@@ should have way to check that it is a conffile -Jamey */
4970 + if (backup_exists_for(root_filename)) {
4971 + continue;
4972 + }
4973 +
4974 + /* Pre-existing files are OK if force-overwrite was asserted. */
4975 + if (conf->force_overwrite) {
4976 + /* but we need to change who owns this file */
4977 + file_hash_set_file_owner(conf, filename, pkg);
4978 + continue;
4979 + }
4980 +
4981 + owner = file_hash_get_file_owner(conf, filename);
4982 +
4983 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4984 + if (owner && old_pkg) {
4985 + if (strcmp(owner->name, old_pkg->name) == 0) {
4986 + continue;
4987 + }
4988 + }
4989 +
4990 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4991 + if (owner) {
4992 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4993 + if (pkg_replaces(pkg, owner)) {
4994 + continue;
4995 + }
4996 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4997 + then it's ok to overwrite. */
4998 + if (strcmp(owner->name,pkg->name)==0){
4999 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5000 + continue;
5001 + }
5002 + }
5003 +
5004 + /* Pre-existing files are OK if they are obsolete */
5005 + obs = hash_table_get(&conf->obs_file_hash, filename);
5006 + if (obs) {
5007 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5008 + continue;
5009 + }
5010 +
5011 + /* We have found a clash. */
5012 + ipkg_message(conf, IPKG_ERROR,
5013 + "Package %s wants to install file %s\n"
5014 + "\tBut that file is already provided by package ",
5015 + pkg->name, filename);
5016 + if (owner) {
5017 + ipkg_message(conf, IPKG_ERROR,
5018 + "%s\n", owner->name);
5019 + } else {
5020 + ipkg_message(conf, IPKG_ERROR,
5021 + "<no package>\nPlease move this file out of the way and try again.\n");
5022 + }
5023 + clashes++;
5024 + }
5025 + free(root_filename);
5026 + }
5027 + pkg_free_installed_files(pkg);
5028 +
5029 + return clashes;
5030 +}
5031 +
5032 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5033 +{
5034 + /* Basically that's the worst hack I could do to be able to change ownership of
5035 + file list, but, being that we have no way to unwind the mods, due to structure
5036 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5037 + What we do here is change the ownership of file in hash if a replace ( or similar events
5038 + happens )
5039 + Only the action that are needed to change name should be considered.
5040 + @@@ To change after 1.0 release.
5041 + */
5042 + str_list_t *files_list;
5043 + str_list_elt_t *iter;
5044 +
5045 + int clashes = 0;
5046 +
5047 + files_list = pkg_get_installed_files(pkg);
5048 + for (iter = files_list->head; iter; iter = iter->next) {
5049 + char *root_filename;
5050 + char *filename = iter->data;
5051 + root_filename = root_filename_alloc(conf, filename);
5052 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5053 + pkg_t *owner;
5054 +
5055 + if (conf->force_overwrite) {
5056 + /* but we need to change who owns this file */
5057 + file_hash_set_file_owner(conf, filename, pkg);
5058 + continue;
5059 + }
5060 +
5061 + owner = file_hash_get_file_owner(conf, filename);
5062 +
5063 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5064 + if (owner) {
5065 + if (pkg_replaces(pkg, owner)) {
5066 +/* It's now time to change the owner of that file.
5067 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5068 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5069 + file_hash_set_file_owner(conf, filename, pkg);
5070 + continue;
5071 + }
5072 + }
5073 +
5074 + }
5075 + free(root_filename);
5076 + }
5077 + pkg_free_installed_files(pkg);
5078 +
5079 + return clashes;
5080 +}
5081 +
5082 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5083 +{
5084 + /* Nothing to do since check_data_file_clashes doesn't change state */
5085 + return 0;
5086 +}
5087 +
5088 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5089 +{
5090 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5091 + 1. If the package is being upgraded, call
5092 + old-postrm upgrade new-version
5093 + 2. If this fails, attempt:
5094 + new-postrm failed-upgrade old-version
5095 + Error unwind, for both cases:
5096 + old-preinst abort-upgrade new-version */
5097 + return 0;
5098 +}
5099 +
5100 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5101 +{
5102 + /* DPKG_INCOMPATIBILITY:
5103 + dpkg does some things here that we don't do yet. Do we care?
5104 + (See postrm_upgrade_old_pkg for details)
5105 + */
5106 + return 0;
5107 +}
5108 +
5109 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5110 +{
5111 + int err;
5112 + str_list_t *old_files;
5113 + str_list_elt_t *of;
5114 + str_list_t *new_files;
5115 + str_list_elt_t *nf;
5116 +
5117 + if (old_pkg == NULL) {
5118 + return 0;
5119 + }
5120 +
5121 + old_files = pkg_get_installed_files(old_pkg);
5122 + new_files = pkg_get_installed_files(pkg);
5123 +
5124 + for (of = old_files->head; of; of = of->next) {
5125 + pkg_t *owner;
5126 + char *old, *new;
5127 + old = of->data;
5128 + for (nf = new_files->head; nf; nf = nf->next) {
5129 + new = nf->data;
5130 + if (strcmp(old, new) == 0) {
5131 + goto NOT_OBSOLETE;
5132 + }
5133 + }
5134 + if (file_is_dir(old)) {
5135 + continue;
5136 + }
5137 + owner = file_hash_get_file_owner(conf, old);
5138 + if (owner != old_pkg) {
5139 + /* in case obsolete file no longer belongs to old_pkg */
5140 + continue;
5141 + }
5142 +
5143 + /* old file is obsolete */
5144 + ipkg_message(conf, IPKG_INFO,
5145 + " removing obsolete file %s\n", old);
5146 + if (!conf->noaction) {
5147 + err = unlink(old);
5148 + if (err) {
5149 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5150 + strerror(errno));
5151 + }
5152 + }
5153 +
5154 + NOT_OBSOLETE:
5155 + ;
5156 + }
5157 +
5158 + pkg_free_installed_files(old_pkg);
5159 + pkg_free_installed_files(pkg);
5160 +
5161 + return 0;
5162 +}
5163 +
5164 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5165 +{
5166 + int i;
5167 + int err = 0;
5168 + char *globpattern;
5169 + glob_t globbuf;
5170 + if (0) {
5171 + if (!pkg->dest) {
5172 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5173 + return -1;
5174 + }
5175 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5176 + err = glob(globpattern, 0, NULL, &globbuf);
5177 + free(globpattern);
5178 + if (err) {
5179 + return err;
5180 + }
5181 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5182 + for (i = 0; i < globbuf.gl_pathc; i++) {
5183 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5184 + globbuf.gl_pathv[i], old_pkg->name);
5185 + if (!conf->noaction)
5186 + unlink(globbuf.gl_pathv[i]);
5187 + }
5188 + globfree(&globbuf);
5189 + }
5190 + return err;
5191 +}
5192 +
5193 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5194 +{
5195 + int ret;
5196 + char *prefix;
5197 +
5198 + if (old_pkg)
5199 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5200 + sprintf_alloc(&prefix, "%s.", pkg->name);
5201 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5202 + pkg->dest->info_dir,
5203 + prefix);
5204 + free(prefix);
5205 + return ret;
5206 +}
5207 +
5208 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5209 +{
5210 + /* DPKG_INCOMPATIBILITY:
5211 + This is a fairly sophisticated dpkg operation. Shall we
5212 + skip it? */
5213 +
5214 + /* Any packages all of whose files have been overwritten during the
5215 + installation, and which aren't required for dependencies, are
5216 + considered to have been removed. For each such package
5217 + 1. disappearer's-postrm disappear overwriter overwriter-version
5218 + 2. The package's maintainer scripts are removed
5219 + 3. It is noted in the status database as being in a sane state,
5220 + namely not installed (any conffiles it may have are ignored,
5221 + rather than being removed by dpkg). Note that disappearing
5222 + packages do not have their prerm called, because dpkg doesn't
5223 + know in advance that the package is going to vanish.
5224 + */
5225 + return 0;
5226 +}
5227 +
5228 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5229 +{
5230 + int err;
5231 +
5232 + /* ipkg takes a slightly different approach to data file backups
5233 + than dpkg. Rather than removing backups at this point, we
5234 + actually do the data file installation now. See comments in
5235 + check_data_file_clashes() for more details. */
5236 +
5237 + ipkg_message(conf, IPKG_INFO,
5238 + " extracting data files to %s\n", pkg->dest->root_dir);
5239 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5240 + if (err) {
5241 + return err;
5242 + }
5243 +
5244 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5245 + so we can't save ourself from removing important packages
5246 + At this point we (should) have extracted the .control file, so it
5247 + would be a good idea to reload the data in it, and set the Essential
5248 + state in *pkg. From now on the Essential is back in status file and
5249 + we can protect again.
5250 + We should operate this way:
5251 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5252 + check for "Essential" in it
5253 + set the value in pkg->essential.
5254 + This new routine could be useful also for every other flag
5255 + Pigi: 16/03/2004 */
5256 + set_flags_from_control(conf, pkg) ;
5257 +
5258 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5259 + err = pkg_write_filelist(conf, pkg);
5260 + if (err)
5261 + return err;
5262 +
5263 + /* XXX: FEATURE: ipkg should identify any files which existed
5264 + before installation and which were overwritten, (see
5265 + check_data_file_clashes()). What it must do is remove any such
5266 + files from the filelist of the old package which provided the
5267 + file. Otherwise, if the old package were removed at some point
5268 + it would break the new package. Removing the new package will
5269 + also break the old one, but this cannot be helped since the old
5270 + package's file has already been deleted. This is the importance
5271 + of check_data_file_clashes(), and only allowing ipkg to install
5272 + a clashing package with a user force. */
5273 +
5274 + return 0;
5275 +}
5276 +
5277 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5278 +{
5279 + conffile_list_elt_t *iter;
5280 + conffile_t *cf;
5281 + char *cf_backup;
5282 +
5283 + char *md5sum;
5284 +
5285 +
5286 + if (conf->noaction) return 0;
5287 +
5288 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5289 + char *root_filename;
5290 + cf = iter->data;
5291 + root_filename = root_filename_alloc(conf, cf->name);
5292 +
5293 + /* Might need to initialize the md5sum for each conffile */
5294 + if (cf->value == NULL) {
5295 + cf->value = file_md5sum_alloc(root_filename);
5296 + }
5297 +
5298 + if (!file_exists(root_filename)) {
5299 + free(root_filename);
5300 + continue;
5301 + }
5302 +
5303 + cf_backup = backup_filename_alloc(root_filename);
5304 +
5305 +
5306 + if (file_exists(cf_backup)) {
5307 + /* Let's compute md5 to test if files are changed */
5308 + md5sum = file_md5sum_alloc(cf_backup);
5309 + if (strcmp( cf->value,md5sum) != 0 ) {
5310 + if (conf->force_defaults
5311 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5312 + rename(cf_backup, root_filename);
5313 + }
5314 + }
5315 + unlink(cf_backup);
5316 + free(md5sum);
5317 + }
5318 +
5319 + free(cf_backup);
5320 + free(root_filename);
5321 + }
5322 +
5323 + return 0;
5324 +}
5325 +
5326 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5327 +{
5328 + char *response;
5329 + const char *short_file_name;
5330 +
5331 + short_file_name = strrchr(file_name, '/');
5332 + if (short_file_name) {
5333 + short_file_name++;
5334 + } else {
5335 + short_file_name = file_name;
5336 + }
5337 +
5338 + while (1) {
5339 + response = get_user_response(" Configuration file '%s'\n"
5340 + " ==> File on system created by you or by a script.\n"
5341 + " ==> File also in package provided by package maintainer.\n"
5342 + " What would you like to do about it ? Your options are:\n"
5343 + " Y or I : install the package maintainer's version\n"
5344 + " N or O : keep your currently-installed version\n"
5345 + " D : show the differences between the versions (if diff is installed)\n"
5346 + " The default action is to keep your current version.\n"
5347 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5348 + if (strcmp(response, "y") == 0
5349 + || strcmp(response, "i") == 0
5350 + || strcmp(response, "yes") == 0) {
5351 + free(response);
5352 + return 0;
5353 + }
5354 +
5355 + if (strcmp(response, "d") == 0) {
5356 + char *cmd;
5357 +
5358 + free(response);
5359 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5360 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5361 + xsystem(cmd);
5362 + free(cmd);
5363 + printf(" [Press ENTER to continue]\n");
5364 + response = file_read_line_alloc(stdin);
5365 + free(response);
5366 + continue;
5367 + }
5368 +
5369 + free(response);
5370 + return 1;
5371 + }
5372 +}
5373 +
5374 +/* XXX: CLEANUP: I'd like to move all of the code for
5375 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5376 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5377 + pkg_deinit for example). */
5378 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5379 +{
5380 + DIR *tmp_dir;
5381 + struct dirent *dirent;
5382 + char *tmp_file;
5383 +
5384 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5385 +#error
5386 + ipkg_message(conf, IPKG_DEBUG,
5387 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5388 + __FUNCTION__, pkg->tmp_unpack_dir);
5389 + return 0;
5390 +#endif
5391 +
5392 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5393 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5394 + if (tmp_dir) {
5395 + while (1) {
5396 + dirent = readdir(tmp_dir);
5397 + if (dirent == NULL) {
5398 + break;
5399 + }
5400 + sprintf_alloc(&tmp_file, "%s/%s",
5401 + pkg->tmp_unpack_dir, dirent->d_name);
5402 + if (! file_is_dir(tmp_file)) {
5403 + unlink(tmp_file);
5404 + }
5405 + free(tmp_file);
5406 + }
5407 + closedir(tmp_dir);
5408 + rmdir(pkg->tmp_unpack_dir);
5409 + free(pkg->tmp_unpack_dir);
5410 + pkg->tmp_unpack_dir = NULL;
5411 + }
5412 + }
5413 +
5414 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5415 + pkg->name, pkg->local_filename, conf->tmp_dir);
5416 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5417 + unlink(pkg->local_filename);
5418 + free(pkg->local_filename);
5419 + pkg->local_filename = NULL;
5420 + }
5421 +
5422 + return 0;
5423 +}
5424 +
5425 +static char *backup_filename_alloc(const char *file_name)
5426 +{
5427 + char *backup;
5428 +
5429 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5430 +
5431 + return backup;
5432 +}
5433 +
5434 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5435 +{
5436 + int err;
5437 + char *backup;
5438 +
5439 + backup = backup_filename_alloc(file_name);
5440 + err = file_copy(file_name, backup);
5441 + if (err) {
5442 + ipkg_message(conf, IPKG_ERROR,
5443 + "%s: Failed to copy %s to %s\n",
5444 + __FUNCTION__, file_name, backup);
5445 + }
5446 +
5447 + free(backup);
5448 +
5449 + return err;
5450 +}
5451 +
5452 +static int backup_exists_for(const char *file_name)
5453 +{
5454 + int ret;
5455 + char *backup;
5456 +
5457 + backup = backup_filename_alloc(file_name);
5458 +
5459 + ret = file_exists(backup);
5460 +
5461 + free(backup);
5462 +
5463 + return ret;
5464 +}
5465 +
5466 +static int backup_remove(const char *file_name)
5467 +{
5468 + char *backup;
5469 +
5470 + backup = backup_filename_alloc(file_name);
5471 + unlink(backup);
5472 + free(backup);
5473 +
5474 + return 0;
5475 +}
5476 +
5477 +\f
5478 +
5479 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5480 +
5481 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5482 +{
5483 + /* first, remove the packages that need removing */
5484 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5485 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5486 + err = ipkg_remove_pkg(conf, pkg,0);
5487 + if (err) return err;
5488 + }
5489 + return 0;
5490 +}
5491 +
5492 +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)
5493 +{
5494 + int i;
5495 + /* now one more pass checking on the ones that need to be installed */
5496 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5497 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5498 + if (pkg->dest == NULL)
5499 + pkg->dest = conf->default_dest;
5500 +
5501 + pkg->state_want = SW_INSTALL;
5502 +
5503 + /* Abhaya: conflicts check */
5504 + err = check_conflicts_for(conf, pkg);
5505 + if (err) { return err; }
5506 + }
5507 + return 0;
5508 +}
5509 +
5510 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5511 +{
5512 + int i;
5513 + /* now one more pass checking on the ones that need to be installed */
5514 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5515 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5516 +
5517 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5518 + pkg_vec_t *replacees = pkg_vec_alloc();
5519 + pkg_get_installed_replacees(conf, pkg, replacees);
5520 +
5521 + /* XXX: BUG: we really should treat replacement more like an upgrade
5522 + * Instead, we're going to remove the replacees
5523 + */
5524 + err = pkg_remove_installed_replacees(conf, replacees);
5525 + if (err) return err;
5526 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5527 + }
5528 + return 0;
5529 +}
5530 +
5531 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5532 +{
5533 + int i;
5534 + /* now one more pass checking on the ones that need to be installed */
5535 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5536 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5537 + if (pkg->local_filename == NULL) {
5538 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5539 + if (err) {
5540 + ipkg_message(conf, IPKG_ERROR,
5541 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5542 + pkg->name);
5543 + return err;
5544 + }
5545 + }
5546 + if (pkg->tmp_unpack_dir == NULL) {
5547 + err = unpack_pkg_control_files(conf, pkg);
5548 + if (err) return err;
5549 + }
5550 + }
5551 + return 0;
5552 +}
5553 +
5554 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5555 +{
5556 + int i;
5557 + /* now one more pass checking on the ones that need to be installed */
5558 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5559 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5560 + pkg_t *old_pkg = pkg->old_pkg;
5561 +
5562 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5563 + if (err) return err;
5564 +
5565 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5566 + if (err) return err;
5567 +
5568 + err = preinst_configure(conf, pkg, old_pkg);
5569 + if (err) return err;
5570 +
5571 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5572 + if (err) return err;
5573 +
5574 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5575 + if (err) return err;
5576 + }
5577 + return 0;
5578 +}
5579 +
5580 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5581 +{
5582 + int i;
5583 + /* now one more pass checking on the ones that need to be installed */
5584 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5585 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5586 + pkg_t *old_pkg = pkg->old_pkg;
5587 +
5588 + if (old_pkg) {
5589 + old_pkg->state_want = SW_DEINSTALL;
5590 +
5591 + if (old_pkg->state_flag & SF_NOPRUNE) {
5592 + ipkg_message(conf, IPKG_INFO,
5593 + " not removing obsolesced files because package marked noprune\n");
5594 + } else {
5595 + ipkg_message(conf, IPKG_INFO,
5596 + " removing obsolesced files\n");
5597 + remove_obsolesced_files(conf, pkg, old_pkg);
5598 + }
5599 + }
5600 +
5601 + ipkg_message(conf, IPKG_INFO,
5602 + " installing maintainer scripts\n");
5603 + install_maintainer_scripts(conf, pkg, old_pkg);
5604 +
5605 + /* the following just returns 0 */
5606 + remove_disappeared(conf, pkg);
5607 +
5608 + ipkg_message(conf, IPKG_INFO,
5609 + " installing data files\n");
5610 + install_data_files(conf, pkg);
5611 +
5612 + ipkg_message(conf, IPKG_INFO,
5613 + " resolving conf files\n");
5614 + resolve_conffiles(conf, pkg);
5615 +
5616 + pkg->state_status = SS_UNPACKED;
5617 +
5618 + if (old_pkg) {
5619 + old_pkg->state_status = SS_NOT_INSTALLED;
5620 + }
5621 +
5622 + time(&pkg->installed_time);
5623 +
5624 + ipkg_message(conf, IPKG_INFO,
5625 + " cleanup temp files\n");
5626 + cleanup_temporary_files(conf, pkg);
5627 +
5628 + if (pkg->parent)
5629 + pkg->parent->state_status = pkg->state_status;
5630 + }
5631 + return 0;
5632 +}
5633 +
5634 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5635 +{
5636 + int i;
5637 + /* now one more pass checking on the ones that need to be installed */
5638 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5639 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5640 + pkg_t *old_pkg = pkg->old_pkg;
5641 +
5642 + if (old_pkg) {
5643 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5644 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5645 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5646 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5647 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5648 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5649 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5650 + preinst_configure_unwind(conf, pkg, old_pkg);
5651 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5652 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5653 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5654 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5655 +
5656 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5657 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5658 +
5659 + }
5660 + }
5661 + return 0;
5662 +}
5663 +
5664 +/*
5665 + * Perform all the actions.
5666 + *
5667 + * pkgs_to_remove are packages marked for removal.
5668 + * pkgs_superseded are the old packages being replaced by upgrades.
5669 + *
5670 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5671 + */
5672 +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)
5673 +{
5674 + int err;
5675 + int i;
5676 +
5677 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5678 + if (err) return err;
5679 +
5680 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5681 + if (err) return err;
5682 +
5683 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5684 + if (err) goto UNWIND;
5685 +
5686 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5687 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5688 + if (err) goto UNWIND;
5689 +
5690 + /*
5691 + * Now that we have the packages unpacked, we can look for data
5692 + * file clashes. First, we mark the files from the superseded
5693 + * packages as obsolete. Then we scan the files in
5694 + * pkgs_to_install, and only complain about clashes with
5695 + * non-obsolete files.
5696 + */
5697 +
5698 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5699 + if (err) goto UNWIND;
5700 +
5701 + /* this was before checking data file clashes */
5702 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5703 + if (err) goto UNWIND;
5704 +
5705 + /* point of no return: no unwinding after this */
5706 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5707 + if (err) return err;
5708 +
5709 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5710 + return 0;
5711 +
5712 + UNWIND:
5713 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5714 +
5715 + ipkg_message(conf, IPKG_INFO,
5716 + " cleanup temp files\n");
5717 + cleanup_temporary_files(conf, pkg);
5718 +
5719 + ipkg_message(conf, IPKG_INFO,
5720 + "Failed.\n");
5721 + return err;
5722 +}
5723 +
5724 +#endif
5725 Index: busybox-1.8.1/archival/libipkg/ipkg_install.h
5726 ===================================================================
5727 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5728 +++ busybox-1.8.1/archival/libipkg/ipkg_install.h 2007-11-10 17:40:53.356764426 +0100
5729 @@ -0,0 +1,35 @@
5730 +/* ipkg_install.h - the itsy package management system
5731 +
5732 + Carl D. Worth
5733 +
5734 + Copyright (C) 2001 University of Southern California
5735 +
5736 + This program is free software; you can redistribute it and/or
5737 + modify it under the terms of the GNU General Public License as
5738 + published by the Free Software Foundation; either version 2, or (at
5739 + your option) any later version.
5740 +
5741 + This program is distributed in the hope that it will be useful, but
5742 + WITHOUT ANY WARRANTY; without even the implied warranty of
5743 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5744 + General Public License for more details.
5745 +*/
5746 +
5747 +#ifndef IPKG_INSTALL_H
5748 +#define IPKG_INSTALL_H
5749 +
5750 +#include "pkg.h"
5751 +#include "ipkg_conf.h"
5752 +
5753 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5754 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5755 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5756 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5757 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5758 +
5759 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5760 +
5761 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5762 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5763 +
5764 +#endif
5765 Index: busybox-1.8.1/archival/libipkg/ipkg_message.c
5766 ===================================================================
5767 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5768 +++ busybox-1.8.1/archival/libipkg/ipkg_message.c 2007-11-10 17:40:53.356764426 +0100
5769 @@ -0,0 +1,61 @@
5770 +/* ipkg_message.c - the itsy package management system
5771 +
5772 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5773 +
5774 + This program is free software; you can redistribute it and/or
5775 + modify it under the terms of the GNU General Public License as
5776 + published by the Free Software Foundation; either version 2, or (at
5777 + your option) any later version.
5778 +
5779 + This program is distributed in the hope that it will be useful, but
5780 + WITHOUT ANY WARRANTY; without even the implied warranty of
5781 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5782 + General Public License for more details.
5783 +*/
5784 +
5785 +
5786 +#include "ipkg.h"
5787 +#include "ipkg_conf.h"
5788 +#include "ipkg_message.h"
5789 +
5790 +#ifndef IPKG_LIB
5791 +
5792 +void
5793 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5794 +{
5795 + va_list ap;
5796 +
5797 + if (conf && (conf->verbosity < level))
5798 + {
5799 + return;
5800 + }
5801 + else
5802 + {
5803 +
5804 + va_start (ap, fmt);
5805 + vprintf (fmt, ap);
5806 + va_end (ap);
5807 + }
5808 +}
5809 +
5810 +#else
5811 +
5812 +#include "libipkg.h"
5813 +
5814 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5815 +
5816 +void
5817 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5818 +{
5819 + va_list ap;
5820 + char ts[256];
5821 +
5822 + if (ipkg_cb_message)
5823 + {
5824 + va_start (ap, fmt);
5825 + vsnprintf (ts,256,fmt, ap);
5826 + va_end (ap);
5827 + ipkg_cb_message(conf,level,ts);
5828 + }
5829 +}
5830 +#endif
5831 Index: busybox-1.8.1/archival/libipkg/ipkg_message.h
5832 ===================================================================
5833 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5834 +++ busybox-1.8.1/archival/libipkg/ipkg_message.h 2007-11-10 17:40:53.356764426 +0100
5835 @@ -0,0 +1,32 @@
5836 +/* ipkg_message.h - the itsy package management system
5837 +
5838 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5839 +
5840 + This program is free software; you can redistribute it and/or
5841 + modify it under the terms of the GNU General Public License as
5842 + published by the Free Software Foundation; either version 2, or (at
5843 + your option) any later version.
5844 +
5845 + This program is distributed in the hope that it will be useful, but
5846 + WITHOUT ANY WARRANTY; without even the implied warranty of
5847 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5848 + General Public License for more details.
5849 +*/
5850 +
5851 +#ifndef _IPKG_MESSAGE_H_
5852 +#define _IPKG_MESSAGE_H_
5853 +
5854 +#include "ipkg.h"
5855 +#include "ipkg_conf.h"
5856 +
5857 +typedef enum {
5858 + IPKG_ERROR, /* error conditions */
5859 + IPKG_NOTICE, /* normal but significant condition */
5860 + IPKG_INFO, /* informational message */
5861 + IPKG_DEBUG, /* debug level message */
5862 + IPKG_DEBUG2, /* more debug level message */
5863 +} message_level_t;
5864 +
5865 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
5866 +
5867 +#endif /* _IPKG_MESSAGE_H_ */
5868 Index: busybox-1.8.1/archival/libipkg/ipkg_remove.c
5869 ===================================================================
5870 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5871 +++ busybox-1.8.1/archival/libipkg/ipkg_remove.c 2007-11-10 17:40:53.360764656 +0100
5872 @@ -0,0 +1,383 @@
5873 +/* ipkg_remove.c - the itsy package management system
5874 +
5875 + Carl D. Worth
5876 +
5877 + Copyright (C) 2001 University of Southern California
5878 +
5879 + This program is free software; you can redistribute it and/or
5880 + modify it under the terms of the GNU General Public License as
5881 + published by the Free Software Foundation; either version 2, or (at
5882 + your option) any later version.
5883 +
5884 + This program is distributed in the hope that it will be useful, but
5885 + WITHOUT ANY WARRANTY; without even the implied warranty of
5886 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5887 + General Public License for more details.
5888 +*/
5889 +
5890 +#include "ipkg.h"
5891 +#include "ipkg_message.h"
5892 +
5893 +#include <glob.h>
5894 +
5895 +#include "ipkg_remove.h"
5896 +
5897 +#include "file_util.h"
5898 +#include "sprintf_alloc.h"
5899 +#include "str_util.h"
5900 +
5901 +#include "ipkg_cmd.h"
5902 +
5903 +/*
5904 + * Returns number of the number of packages depending on the packages provided by this package.
5905 + * Every package implicitly provides itself.
5906 + */
5907 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5908 +{
5909 + int nprovides = pkg->provides_count;
5910 + abstract_pkg_t **provides = pkg->provides;
5911 + int n_installed_dependents = 0;
5912 + int i;
5913 + for (i = 0; i <= nprovides; i++) {
5914 + abstract_pkg_t *providee = provides[i];
5915 + abstract_pkg_t **dependers = providee->depended_upon_by;
5916 + abstract_pkg_t *dep_ab_pkg;
5917 + if (dependers == NULL)
5918 + continue;
5919 + while ((dep_ab_pkg = *dependers++) != NULL) {
5920 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5921 + n_installed_dependents++;
5922 + }
5923 + }
5924 +
5925 + }
5926 + /* if caller requested the set of installed dependents */
5927 + if (pdependents) {
5928 + int p = 0;
5929 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5930 +
5931 + if ( dependents == NULL ){
5932 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5933 + return -1;
5934 + }
5935 +
5936 + *pdependents = dependents;
5937 + for (i = 0; i <= nprovides; i++) {
5938 + abstract_pkg_t *providee = provides[i];
5939 + abstract_pkg_t **dependers = providee->depended_upon_by;
5940 + abstract_pkg_t *dep_ab_pkg;
5941 + if (dependers == NULL)
5942 + continue;
5943 + while ((dep_ab_pkg = *dependers++) != NULL) {
5944 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5945 + dependents[p++] = dep_ab_pkg;
5946 + dep_ab_pkg->state_flag |= SF_MARKED;
5947 + }
5948 + }
5949 + }
5950 + dependents[p] = NULL;
5951 + /* now clear the marks */
5952 + for (i = 0; i < p; i++) {
5953 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5954 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5955 + }
5956 + }
5957 + return n_installed_dependents;
5958 +}
5959 +
5960 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5961 +{
5962 + int i;
5963 + int a;
5964 + int count;
5965 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5966 + abstract_pkg_t * ab_pkg;
5967 +
5968 + if((ab_pkg = pkg->parent) == NULL){
5969 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5970 + __FUNCTION__, pkg->name);
5971 + return 0;
5972 + }
5973 +
5974 + if (dependents == NULL)
5975 + return 0;
5976 +
5977 + // here i am using the dependencies_checked
5978 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5979 + return 0; // has already been encountered in the process
5980 + // of marking packages for removal - Karthik
5981 + ab_pkg->dependencies_checked = 2;
5982 +
5983 + i = 0;
5984 + count = 1;
5985 + while (dependents [i] != NULL) {
5986 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5987 +
5988 + if (dep_ab_pkg->dependencies_checked == 2){
5989 + i++;
5990 + continue;
5991 + }
5992 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5993 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5994 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5995 + if (dep_pkg->state_status == SS_INSTALLED) {
5996 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5997 + count++;
5998 + }
5999 + }
6000 + }
6001 + i++;
6002 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6003 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6004 + }
6005 +
6006 + if (count == 1)
6007 + return 0;
6008 +
6009 +
6010 + for (i = 0; i < dependent_pkgs->len; i++) {
6011 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6012 + if (err)
6013 + return err;
6014 + }
6015 + return 0;
6016 +}
6017 +
6018 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6019 +{
6020 + abstract_pkg_t *dep_ab_pkg;
6021 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6022 + while ((dep_ab_pkg = *dependents++) != NULL) {
6023 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6024 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6025 + }
6026 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6027 + ipkg_message(conf, IPKG_ERROR, "");
6028 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6029 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6030 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6031 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6032 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6033 + return 0;
6034 +}
6035 +
6036 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6037 +{
6038 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6039 + thus I wan't check for essential, as I'm upgrading.
6040 + I hope it won't break anything :)
6041 +*/
6042 + int err;
6043 + abstract_pkg_t *parent_pkg = NULL;
6044 +
6045 + if (pkg->essential && !message) {
6046 + if (conf->force_removal_of_essential_packages) {
6047 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6048 + "\tIf your system breaks, you get to keep both pieces\n",
6049 + pkg->name);
6050 + } else {
6051 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6052 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6053 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6054 + "\tits will with the option: -force-removal-of-essential-packages\n",
6055 + pkg->name);
6056 + return IPKG_PKG_IS_ESSENTIAL;
6057 + }
6058 + }
6059 +
6060 + if ((parent_pkg = pkg->parent) == NULL)
6061 + return 0;
6062 +
6063 + /* only attempt to remove dependent installed packages if
6064 + * force_depends is not specified or the package is being
6065 + * replaced.
6066 + */
6067 + if (!conf->force_depends
6068 + && !(pkg->state_flag & SF_REPLACE)) {
6069 + abstract_pkg_t **dependents;
6070 + int has_installed_dependents =
6071 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6072 +
6073 + if (has_installed_dependents) {
6074 + /*
6075 + * if this package is depended up by others, then either we should
6076 + * not remove it or we should remove it and all of its dependents
6077 + */
6078 +
6079 + if (!conf->force_removal_of_dependent_packages
6080 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6081 + return IPKG_PKG_HAS_DEPENDENTS;
6082 + }
6083 +
6084 + /* remove packages depending on this package - Karthik */
6085 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6086 + free(dependents);
6087 + if (err) return err;
6088 + }
6089 + }
6090 +
6091 + if ( message==0 ){
6092 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6093 + fflush(stdout);
6094 + }
6095 + pkg->state_flag |= SF_FILELIST_CHANGED;
6096 +
6097 + pkg->state_want = SW_DEINSTALL;
6098 + ipkg_state_changed++;
6099 +
6100 + pkg_run_script(conf, pkg, "prerm", "remove");
6101 +
6102 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6103 + maintains an empty filelist rather than deleting it. That seems
6104 + like a big pain, and I don't see that that should make a big
6105 + difference, but for anyone who wants tighter compatibility,
6106 + feel free to fix this. */
6107 + remove_data_files_and_list(conf, pkg);
6108 +
6109 + pkg_run_script(conf, pkg, "postrm", "remove");
6110 +
6111 + remove_maintainer_scripts_except_postrm(conf, pkg);
6112 +
6113 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6114 + * space, it doesn't make sense to leave extra configurations, files,
6115 + * and maintainer scripts left around. So, we make remove like purge,
6116 + * and take out all the crap :) */
6117 +
6118 + remove_postrm(conf, pkg);
6119 + pkg->state_status = SS_NOT_INSTALLED;
6120 +
6121 + if (parent_pkg)
6122 + parent_pkg->state_status = SS_NOT_INSTALLED;
6123 +
6124 + return 0;
6125 +}
6126 +
6127 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6128 +{
6129 + ipkg_remove_pkg(conf, pkg,0);
6130 + return 0;
6131 +}
6132 +
6133 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6134 +{
6135 + str_list_t installed_dirs;
6136 + str_list_t *installed_files;
6137 + str_list_elt_t *iter;
6138 + char *file_name;
6139 + conffile_t *conffile;
6140 + int removed_a_dir;
6141 + pkg_t *owner;
6142 +
6143 + str_list_init(&installed_dirs);
6144 + installed_files = pkg_get_installed_files(pkg);
6145 +
6146 + for (iter = installed_files->head; iter; iter = iter->next) {
6147 + file_name = iter->data;
6148 +
6149 + if (file_is_dir(file_name)) {
6150 + str_list_append(&installed_dirs, strdup(file_name));
6151 + continue;
6152 + }
6153 +
6154 + conffile = pkg_get_conffile(pkg, file_name);
6155 + if (conffile) {
6156 + /* XXX: QUESTION: Is this right? I figure we only need to
6157 + save the conffile if it has been modified. Is that what
6158 + dpkg does? Or does dpkg preserve all conffiles? If so,
6159 + this seems like a better thing to do to conserve
6160 + space. */
6161 + if (conffile_has_been_modified(conf, conffile)) {
6162 + printf(" not deleting modified conffile %s\n", file_name);
6163 + fflush(stdout);
6164 + continue;
6165 + }
6166 + }
6167 +
6168 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6169 + if (!conf->noaction)
6170 + unlink(file_name);
6171 + }
6172 +
6173 + if (!conf->noaction) {
6174 + do {
6175 + removed_a_dir = 0;
6176 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6177 + file_name = iter->data;
6178 +
6179 + if (rmdir(file_name) == 0) {
6180 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6181 + removed_a_dir = 1;
6182 + str_list_remove(&installed_dirs, &iter);
6183 + }
6184 + }
6185 + } while (removed_a_dir);
6186 + }
6187 +
6188 + pkg_free_installed_files(pkg);
6189 + /* We have to remove the file list now, so that
6190 + find_pkg_owning_file does not always just report this package */
6191 + pkg_remove_installed_files_list(conf, pkg);
6192 +
6193 + /* Don't print warning for dirs that are provided by other packages */
6194 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6195 + file_name = iter->data;
6196 +
6197 + owner = file_hash_get_file_owner(conf, file_name);
6198 + if (owner) {
6199 + free(iter->data);
6200 + iter->data = NULL;
6201 + str_list_remove(&installed_dirs, &iter);
6202 + }
6203 + }
6204 +
6205 + /* cleanup */
6206 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6207 + free(iter->data);
6208 + iter->data = NULL;
6209 + }
6210 + str_list_deinit(&installed_dirs);
6211 +
6212 + return 0;
6213 +}
6214 +
6215 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6216 +{
6217 + int i, err;
6218 + char *globpattern;
6219 + glob_t globbuf;
6220 +
6221 + if (conf->noaction) return 0;
6222 +
6223 + sprintf_alloc(&globpattern, "%s/%s.*",
6224 + pkg->dest->info_dir, pkg->name);
6225 + err = glob(globpattern, 0, NULL, &globbuf);
6226 + free(globpattern);
6227 + if (err) {
6228 + return 0;
6229 + }
6230 +
6231 + for (i = 0; i < globbuf.gl_pathc; i++) {
6232 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6233 + continue;
6234 + }
6235 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6236 + unlink(globbuf.gl_pathv[i]);
6237 + }
6238 + globfree(&globbuf);
6239 +
6240 + return 0;
6241 +}
6242 +
6243 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6244 +{
6245 + char *postrm_file_name;
6246 +
6247 + if (conf->noaction) return 0;
6248 +
6249 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6250 + pkg->dest->info_dir, pkg->name);
6251 + unlink(postrm_file_name);
6252 + free(postrm_file_name);
6253 +
6254 + return 0;
6255 +}
6256 Index: busybox-1.8.1/archival/libipkg/ipkg_remove.h
6257 ===================================================================
6258 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6259 +++ busybox-1.8.1/archival/libipkg/ipkg_remove.h 2007-11-10 17:40:53.360764656 +0100
6260 @@ -0,0 +1,33 @@
6261 +/* ipkg_remove.h - the itsy package management system
6262 +
6263 + Carl D. Worth
6264 +
6265 + Copyright (C) 2001 University of Southern California
6266 +
6267 + This program is free software; you can redistribute it and/or
6268 + modify it under the terms of the GNU General Public License as
6269 + published by the Free Software Foundation; either version 2, or (at
6270 + your option) any later version.
6271 +
6272 + This program is distributed in the hope that it will be useful, but
6273 + WITHOUT ANY WARRANTY; without even the implied warranty of
6274 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6275 + General Public License for more details.
6276 +*/
6277 +
6278 +#ifndef IPKG_REMOVE_H
6279 +#define IPKG_REMOVE_H
6280 +
6281 +#include "pkg.h"
6282 +#include "ipkg_conf.h"
6283 +
6284 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6285 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6286 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6287 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6288 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6289 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6290 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6291 +
6292 +
6293 +#endif
6294 Index: busybox-1.8.1/archival/libipkg/ipkg_upgrade.c
6295 ===================================================================
6296 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6297 +++ busybox-1.8.1/archival/libipkg/ipkg_upgrade.c 2007-11-10 17:40:53.360764656 +0100
6298 @@ -0,0 +1,77 @@
6299 +/* ipkg_upgrade.c - the itsy package management system
6300 +
6301 + Carl D. Worth
6302 + Copyright (C) 2001 University of Southern California
6303 +
6304 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6305 +
6306 + This program is free software; you can redistribute it and/or
6307 + modify it under the terms of the GNU General Public License as
6308 + published by the Free Software Foundation; either version 2, or (at
6309 + your option) any later version.
6310 +
6311 + This program is distributed in the hope that it will be useful, but
6312 + WITHOUT ANY WARRANTY; without even the implied warranty of
6313 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6314 + General Public License for more details.
6315 +*/
6316 +
6317 +#include "ipkg.h"
6318 +#include "ipkg_install.h"
6319 +#include "ipkg_message.h"
6320 +
6321 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6322 +{
6323 + pkg_t *new;
6324 + int cmp;
6325 + char *old_version, *new_version;
6326 +
6327 + if (old->state_flag & SF_HOLD) {
6328 + ipkg_message(conf, IPKG_NOTICE,
6329 + "Not upgrading package %s which is marked "
6330 + "hold (flags=%#x)\n", old->name, old->state_flag);
6331 + return 0;
6332 + }
6333 +
6334 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6335 + if (new == NULL) {
6336 + old_version = pkg_version_str_alloc(old);
6337 + ipkg_message(conf, IPKG_NOTICE,
6338 + "Assuming locally installed package %s (%s) "
6339 + "is up to date.\n", old->name, old_version);
6340 + free(old_version);
6341 + return 0;
6342 + }
6343 +
6344 + old_version = pkg_version_str_alloc(old);
6345 + new_version = pkg_version_str_alloc(new);
6346 +
6347 + cmp = pkg_compare_versions(old, new);
6348 + ipkg_message(conf, IPKG_DEBUG,
6349 + "comparing visible versions of pkg %s:"
6350 + "\n\t%s is installed "
6351 + "\n\t%s is available "
6352 + "\n\t%d was comparison result\n",
6353 + old->name, old_version, new_version, cmp);
6354 + if (cmp == 0) {
6355 + ipkg_message(conf, IPKG_INFO,
6356 + "Package %s (%s) installed in %s is up to date.\n",
6357 + old->name, old_version, old->dest->name);
6358 + free(old_version);
6359 + free(new_version);
6360 + return 0;
6361 + } else if (cmp > 0) {
6362 + ipkg_message(conf, IPKG_NOTICE,
6363 + "Not downgrading package %s on %s from %s to %s.\n",
6364 + old->name, old->dest->name, old_version, new_version);
6365 + free(old_version);
6366 + free(new_version);
6367 + return 0;
6368 + } else if (cmp < 0) {
6369 + new->dest = old->dest;
6370 + old->state_want = SW_DEINSTALL;
6371 + }
6372 +
6373 + new->state_flag |= SF_USER;
6374 + return ipkg_install_pkg(conf, new,1);
6375 +}
6376 Index: busybox-1.8.1/archival/libipkg/ipkg_upgrade.h
6377 ===================================================================
6378 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6379 +++ busybox-1.8.1/archival/libipkg/ipkg_upgrade.h 2007-11-10 17:40:53.360764656 +0100
6380 @@ -0,0 +1,18 @@
6381 +/* ipkg_upgrade.c - the itsy package management system
6382 +
6383 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6384 +
6385 + This program is free software; you can redistribute it and/or
6386 + modify it under the terms of the GNU General Public License as
6387 + published by the Free Software Foundation; either version 2, or (at
6388 + your option) any later version.
6389 +
6390 + This program is distributed in the hope that it will be useful, but
6391 + WITHOUT ANY WARRANTY; without even the implied warranty of
6392 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6393 + General Public License for more details.
6394 +*/
6395 +
6396 +#include "ipkg.h"
6397 +
6398 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6399 Index: busybox-1.8.1/archival/libipkg/ipkg_utils.c
6400 ===================================================================
6401 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6402 +++ busybox-1.8.1/archival/libipkg/ipkg_utils.c 2007-11-10 17:40:53.360764656 +0100
6403 @@ -0,0 +1,181 @@
6404 +/* ipkg_utils.c - the itsy package management system
6405 +
6406 + Steven M. Ayer
6407 +
6408 + Copyright (C) 2002 Compaq Computer Corporation
6409 +
6410 + This program is free software; you can redistribute it and/or
6411 + modify it under the terms of the GNU General Public License as
6412 + published by the Free Software Foundation; either version 2, or (at
6413 + your option) any later version.
6414 +
6415 + This program is distributed in the hope that it will be useful, but
6416 + WITHOUT ANY WARRANTY; without even the implied warranty of
6417 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6418 + General Public License for more details.
6419 +*/
6420 +
6421 +#include "ipkg.h"
6422 +#include <errno.h>
6423 +#include <ctype.h>
6424 +#include <sys/vfs.h>
6425 +
6426 +#include "ipkg_utils.h"
6427 +#include "pkg.h"
6428 +#include "pkg_hash.h"
6429 +
6430 +struct errlist* error_list;
6431 +
6432 +int get_available_blocks(char * filesystem)
6433 +{
6434 + struct statfs sfs;
6435 +
6436 + if(statfs(filesystem, &sfs)){
6437 + fprintf(stderr, "bad statfs\n");
6438 + return 0;
6439 + }
6440 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6441 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6442 +}
6443 +
6444 +char **read_raw_pkgs_from_file(const char *file_name)
6445 +{
6446 + FILE *fp;
6447 + char **ret;
6448 +
6449 + if(!(fp = fopen(file_name, "r"))){
6450 + fprintf(stderr, "can't get %s open for read\n", file_name);
6451 + return NULL;
6452 + }
6453 +
6454 + ret = read_raw_pkgs_from_stream(fp);
6455 +
6456 + fclose(fp);
6457 +
6458 + return ret;
6459 +}
6460 +
6461 +char **read_raw_pkgs_from_stream(FILE *fp)
6462 +{
6463 + char **raw = NULL, *buf, *scout;
6464 + int count = 0;
6465 + size_t size = 512;
6466 +
6467 + buf = malloc (size);
6468 +
6469 + while (fgets(buf, size, fp)) {
6470 + while (strlen (buf) == (size - 1)
6471 + && buf[size-2] != '\n') {
6472 + size_t o = size - 1;
6473 + size *= 2;
6474 + buf = realloc (buf, size);
6475 + if (fgets (buf + o, size - o, fp) == NULL)
6476 + break;
6477 + }
6478 +
6479 + if(!(count % 50))
6480 + raw = realloc(raw, (count + 50) * sizeof(char *));
6481 +
6482 + if((scout = strchr(buf, '\n')))
6483 + *scout = '\0';
6484 +
6485 + raw[count++] = strdup(buf);
6486 + }
6487 +
6488 + raw = realloc(raw, (count + 1) * sizeof(char *));
6489 + raw[count] = NULL;
6490 +
6491 + free (buf);
6492 +
6493 + return raw;
6494 +}
6495 +
6496 +/* something to remove whitespace, a hash pooper */
6497 +char *trim_alloc(char *line)
6498 +{
6499 + char *new;
6500 + char *dest, *src, *end;
6501 +
6502 + new = malloc(strlen(line) + 1);
6503 + if ( new == NULL ){
6504 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6505 + return NULL;
6506 + }
6507 + dest = new, src = line, end = line + (strlen(line) - 1);
6508 +
6509 + /* remove it from the front */
6510 + while(src &&
6511 + isspace(*src) &&
6512 + *src)
6513 + src++;
6514 + /* and now from the back */
6515 + while((end > src) &&
6516 + isspace(*end))
6517 + end--;
6518 + end++;
6519 + *end = '\0';
6520 + strcpy(new, src);
6521 + /* this does from the first space
6522 + * blasting away any versions stuff in depends
6523 + while(src &&
6524 + !isspace(*src) &&
6525 + *src)
6526 + *dest++ = *src++;
6527 + *dest = '\0';
6528 + */
6529 +
6530 + return new;
6531 +}
6532 +
6533 +int line_is_blank(const char *line)
6534 +{
6535 + const char *s;
6536 +
6537 + for (s = line; *s; s++) {
6538 + if (!isspace(*s))
6539 + return 0;
6540 + }
6541 + return 1;
6542 +}
6543 +
6544 +void push_error_list(struct errlist ** errors, char * msg){
6545 + struct errlist *err_lst_tmp;
6546 +
6547 +
6548 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6549 + err_lst_tmp->errmsg=strdup(msg) ;
6550 + err_lst_tmp->next = *errors;
6551 + *errors = err_lst_tmp;
6552 +}
6553 +
6554 +
6555 +void reverse_error_list(struct errlist **errors){
6556 + struct errlist *result=NULL;
6557 + struct errlist *current= *errors;
6558 + struct errlist *next;
6559 +
6560 + while ( current != NULL ) {
6561 + next = current->next;
6562 + current->next=result;
6563 + result=current;
6564 + current=next;
6565 + }
6566 + *errors=result;
6567 +
6568 +}
6569 +
6570 +
6571 +void free_error_list(struct errlist **errors){
6572 + struct errlist *current = *errors;
6573 +
6574 + while (current != NULL) {
6575 + free(current->errmsg);
6576 + current = (*errors)->next;
6577 + free(*errors);
6578 + *errors = current;
6579 + }
6580 +
6581 +
6582 +}
6583 +
6584 +
6585 Index: busybox-1.8.1/archival/libipkg/ipkg_utils.h
6586 ===================================================================
6587 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6588 +++ busybox-1.8.1/archival/libipkg/ipkg_utils.h 2007-11-10 17:40:53.360764656 +0100
6589 @@ -0,0 +1,29 @@
6590 +/* ipkg_utils.h - the itsy package management system
6591 +
6592 + Steven M. Ayer
6593 +
6594 + Copyright (C) 2002 Compaq Computer Corporation
6595 +
6596 + This program is free software; you can redistribute it and/or
6597 + modify it under the terms of the GNU General Public License as
6598 + published by the Free Software Foundation; either version 2, or (at
6599 + your option) any later version.
6600 +
6601 + This program is distributed in the hope that it will be useful, but
6602 + WITHOUT ANY WARRANTY; without even the implied warranty of
6603 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6604 + General Public License for more details.
6605 +*/
6606 +
6607 +#ifndef IPKG_UTILS_H
6608 +#define IPKG_UTILS_H
6609 +
6610 +#include "pkg.h"
6611 +
6612 +int get_available_blocks(char * filesystem);
6613 +char **read_raw_pkgs_from_file(const char *file_name);
6614 +char **read_raw_pkgs_from_stream(FILE *fp);
6615 +char *trim_alloc(char * line);
6616 +int line_is_blank(const char *line);
6617 +
6618 +#endif
6619 Index: busybox-1.8.1/archival/libipkg/Kbuild
6620 ===================================================================
6621 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6622 +++ busybox-1.8.1/archival/libipkg/Kbuild 2007-11-10 17:40:53.364764882 +0100
6623 @@ -0,0 +1,60 @@
6624 +# Makefile for busybox
6625 +#
6626 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6627 +# Copyright (C) 2006 OpenWrt.org
6628 +#
6629 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6630 +
6631 +LIBIPKG_CORE_OBJS:= \
6632 + args.o \
6633 + libipkg.o \
6634 + user.o \
6635 +
6636 +LIBIPKG_CMD_OBJS:= \
6637 + ipkg_cmd.o \
6638 + ipkg_configure.o \
6639 + ipkg_download.o \
6640 + ipkg_install.o \
6641 + ipkg_remove.o \
6642 + ipkg_upgrade.o \
6643 +
6644 +LIBIPKG_DB_OBJS:= \
6645 + hash_table.o \
6646 + ipkg_conf.o \
6647 + ipkg_utils.o \
6648 + pkg.o \
6649 + pkg_depends.o \
6650 + pkg_extract.o \
6651 + pkg_hash.o \
6652 + pkg_parse.o \
6653 + pkg_vec.o \
6654 +
6655 +LIBIPKG_LIST_OBJS:= \
6656 + conffile.o \
6657 + conffile_list.o \
6658 + nv_pair.o \
6659 + nv_pair_list.o \
6660 + pkg_dest.o \
6661 + pkg_dest_list.o \
6662 + pkg_src.o \
6663 + pkg_src_list.o \
6664 + str_list.o \
6665 + void_list.o \
6666 +
6667 +LIBIPKG_UTIL_OBJS:= \
6668 + file_util.o \
6669 + ipkg_message.o \
6670 + str_util.o \
6671 + xsystem.o \
6672 +
6673 +lib-y :=
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6677 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6678 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6679 +
6680 +ifeq ($(strip $(IPKG_ARCH)),)
6681 +IPKG_ARCH:=$(TARGET_ARCH)
6682 +endif
6683 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6684 Index: busybox-1.8.1/archival/libipkg/libipkg.c
6685 ===================================================================
6686 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6687 +++ busybox-1.8.1/archival/libipkg/libipkg.c 2007-11-10 17:40:53.364764882 +0100
6688 @@ -0,0 +1,527 @@
6689 +/* ipkglib.c - the itsy package management system
6690 +
6691 + Florina Boor
6692 +
6693 + Copyright (C) 2003 kernel concepts
6694 +
6695 + This program is free software; you can redistribute it and/or
6696 + modify it under the terms of the GNU General Public License as
6697 + published by the Free Software Foundation; either version 2, or (at
6698 + your option) any later version.
6699 +
6700 + This program is distributed in the hope that it will be useful, but
6701 + WITHOUT ANY WARRANTY; without even the implied warranty of
6702 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6703 + General Public License for more details.
6704 +*/
6705 +
6706 +#ifdef IPKG_LIB
6707 +
6708 +#include "ipkg.h"
6709 +#include "ipkg_includes.h"
6710 +#include "libipkg.h"
6711 +
6712 +#include "args.h"
6713 +#include "ipkg_conf.h"
6714 +#include "ipkg_cmd.h"
6715 +#include "file_util.h"
6716 +
6717 +
6718 +
6719 +ipkg_message_callback ipkg_cb_message = NULL;
6720 +ipkg_response_callback ipkg_cb_response = NULL;
6721 +ipkg_status_callback ipkg_cb_status = NULL;
6722 +ipkg_list_callback ipkg_cb_list = NULL;
6723 +
6724 +
6725 +int
6726 +ipkg_init (ipkg_message_callback mcall,
6727 + ipkg_response_callback rcall,
6728 + args_t * args)
6729 +{
6730 + ipkg_cb_message = mcall;
6731 + ipkg_cb_response = rcall;
6732 +
6733 + args_init (args);
6734 +
6735 + return 0;
6736 +}
6737 +
6738 +
6739 +int
6740 +ipkg_deinit (args_t * args)
6741 +{
6742 + args_deinit (args);
6743 + ipkg_cb_message = NULL;
6744 + ipkg_cb_response = NULL;
6745 +
6746 + /* place other cleanup stuff here */
6747 +
6748 + return 0;
6749 +}
6750 +
6751 +
6752 +int
6753 +ipkg_packages_list(args_t *args,
6754 + const char *packages,
6755 + ipkg_list_callback cblist,
6756 + void *userdata)
6757 +{
6758 + ipkg_cmd_t *cmd;
6759 + ipkg_conf_t ipkg_conf;
6760 + int err;
6761 +
6762 + err = ipkg_conf_init (&ipkg_conf, args);
6763 + if (err)
6764 + {
6765 + return err;
6766 + }
6767 +
6768 + ipkg_cb_list = cblist;
6769 + /* we need to do this because of static declarations,
6770 + * maybe a good idea to change */
6771 + cmd = ipkg_cmd_find ("list");
6772 + if (packages)
6773 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6774 + else
6775 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6776 + ipkg_cb_list = NULL;
6777 + ipkg_conf_deinit (&ipkg_conf);
6778 + return (err);
6779 +}
6780 +
6781 +
6782 +int
6783 +ipkg_packages_status(args_t *args,
6784 + const char *packages,
6785 + ipkg_status_callback cbstatus,
6786 + void *userdata)
6787 +{
6788 + ipkg_cmd_t *cmd;
6789 + ipkg_conf_t ipkg_conf;
6790 + int err;
6791 +
6792 + err = ipkg_conf_init (&ipkg_conf, args);
6793 + if (err)
6794 + {
6795 + return err;
6796 + }
6797 +
6798 + ipkg_cb_status = cbstatus;
6799 +
6800 + /* we need to do this because of static declarations,
6801 + * maybe a good idea to change */
6802 + cmd = ipkg_cmd_find ("status");
6803 + if (packages)
6804 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6805 + else
6806 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6807 +
6808 + ipkg_cb_status = NULL;
6809 + ipkg_conf_deinit (&ipkg_conf);
6810 + return (err);
6811 +}
6812 +
6813 +
6814 +int
6815 +ipkg_packages_info(args_t *args,
6816 + const char *packages,
6817 + ipkg_status_callback cbstatus,
6818 + void *userdata)
6819 +{
6820 + ipkg_cmd_t *cmd;
6821 + ipkg_conf_t ipkg_conf;
6822 + int err;
6823 +
6824 + err = ipkg_conf_init (&ipkg_conf, args);
6825 + if (err)
6826 + {
6827 + return err;
6828 + }
6829 +
6830 + ipkg_cb_status = cbstatus;
6831 +
6832 + /* we need to do this because of static declarations,
6833 + * maybe a good idea to change */
6834 + cmd = ipkg_cmd_find ("info");
6835 + if (packages)
6836 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6837 + else
6838 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6839 +
6840 + ipkg_cb_status = NULL;
6841 + ipkg_conf_deinit (&ipkg_conf);
6842 + return (err);
6843 +}
6844 +
6845 +
6846 +int
6847 +ipkg_packages_install (args_t * args, const char *name)
6848 +{
6849 + ipkg_cmd_t *cmd;
6850 + ipkg_conf_t ipkg_conf;
6851 + int err;
6852 +
6853 + /* this error should be handled in application */
6854 + if (!name || !strlen (name))
6855 + return (-1);
6856 +
6857 + err = ipkg_conf_init (&ipkg_conf, args);
6858 + if (err)
6859 + {
6860 + return err;
6861 + }
6862 +
6863 + /* we need to do this because of static declarations,
6864 + * maybe a good idea to change */
6865 + cmd = ipkg_cmd_find ("install");
6866 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6867 +
6868 + ipkg_conf_deinit(&ipkg_conf);
6869 + return (err);
6870 +}
6871 +
6872 +
6873 +int
6874 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6875 +{
6876 + ipkg_cmd_t *cmd;
6877 + ipkg_conf_t ipkg_conf;
6878 + int err;
6879 +
6880 + /* this error should be handled in application */
6881 + if (!name || !strlen (name))
6882 + return (-1);
6883 +
6884 + err = ipkg_conf_init (&ipkg_conf, args);
6885 + if (err)
6886 + {
6887 + return err;
6888 + }
6889 +
6890 + /* we need to do this because of static declarations,
6891 + * maybe a good idea to change */
6892 + if (purge)
6893 + cmd = ipkg_cmd_find ("purge");
6894 + else
6895 + cmd = ipkg_cmd_find ("remove");
6896 +
6897 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6898 +
6899 + ipkg_conf_deinit(&ipkg_conf);
6900 + return (err);
6901 +}
6902 +
6903 +
6904 +int
6905 +ipkg_lists_update(args_t *args)
6906 +{
6907 + ipkg_cmd_t *cmd;
6908 + ipkg_conf_t ipkg_conf;
6909 + int err;
6910 +
6911 + err = ipkg_conf_init (&ipkg_conf, args);
6912 + if (err)
6913 + {
6914 + return err;
6915 + }
6916 +
6917 + /* we need to do this because of static declarations,
6918 + * maybe a good idea to change */
6919 + cmd = ipkg_cmd_find ("update");
6920 +
6921 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6922 +
6923 + ipkg_conf_deinit(&ipkg_conf);
6924 + return (err);
6925 +}
6926 +
6927 +
6928 +int
6929 +ipkg_packages_upgrade(args_t *args)
6930 +{
6931 + ipkg_cmd_t *cmd;
6932 + ipkg_conf_t ipkg_conf;
6933 + int err;
6934 +
6935 + err = ipkg_conf_init (&ipkg_conf, args);
6936 + if (err)
6937 + {
6938 + return err;
6939 + }
6940 +
6941 + /* we need to do this because of static declarations,
6942 + * maybe a good idea to change */
6943 + cmd = ipkg_cmd_find ("upgrade");
6944 +
6945 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6946 +
6947 + ipkg_conf_deinit(&ipkg_conf);
6948 + return (err);
6949 +}
6950 +
6951 +
6952 +int
6953 +ipkg_packages_download (args_t * args, const char *name)
6954 +{
6955 + ipkg_cmd_t *cmd;
6956 + ipkg_conf_t ipkg_conf;
6957 + int err;
6958 +
6959 + /* this error should be handled in application */
6960 + if (!name || !strlen (name))
6961 + return (-1);
6962 +
6963 + err = ipkg_conf_init (&ipkg_conf, args);
6964 + if (err)
6965 + {
6966 + return err;
6967 + }
6968 +
6969 + /* we need to do this because of static declarations,
6970 + * maybe a good idea to change */
6971 + cmd = ipkg_cmd_find ("download");
6972 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6973 +
6974 + ipkg_conf_deinit(&ipkg_conf);
6975 + return (err);
6976 +}
6977 +
6978 +
6979 +int
6980 +ipkg_package_files(args_t *args,
6981 + const char *name,
6982 + ipkg_list_callback cblist,
6983 + void *userdata)
6984 +{
6985 + ipkg_cmd_t *cmd;
6986 + ipkg_conf_t ipkg_conf;
6987 + int err;
6988 +
6989 + /* this error should be handled in application */
6990 + if (!name || !strlen (name))
6991 + return (-1);
6992 +
6993 + err = ipkg_conf_init (&ipkg_conf, args);
6994 + if (err)
6995 + {
6996 + return err;
6997 + }
6998 +
6999 + ipkg_cb_list = cblist;
7000 +
7001 + /* we need to do this because of static declarations,
7002 + * maybe a good idea to change */
7003 + cmd = ipkg_cmd_find ("files");
7004 +
7005 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7006 +
7007 + ipkg_cb_list = NULL;
7008 + ipkg_conf_deinit(&ipkg_conf);
7009 + return (err);
7010 +}
7011 +
7012 +
7013 +int
7014 +ipkg_file_search(args_t *args,
7015 + const char *file,
7016 + ipkg_list_callback cblist,
7017 + void *userdata)
7018 +{
7019 + ipkg_cmd_t *cmd;
7020 + ipkg_conf_t ipkg_conf;
7021 + int err;
7022 +
7023 + /* this error should be handled in application */
7024 + if (!file || !strlen (file))
7025 + return (-1);
7026 +
7027 + err = ipkg_conf_init (&ipkg_conf, args);
7028 + if (err)
7029 + {
7030 + return err;
7031 + }
7032 +
7033 + ipkg_cb_list = cblist;
7034 +
7035 + /* we need to do this because of static declarations,
7036 + * maybe a good idea to change */
7037 + cmd = ipkg_cmd_find ("search");
7038 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7039 +
7040 + ipkg_cb_list = NULL;
7041 + ipkg_conf_deinit(&ipkg_conf);
7042 + return(err);
7043 +}
7044 +
7045 +
7046 +int
7047 +ipkg_file_what(args_t *args, const char *file, const char* command)
7048 +{
7049 + ipkg_cmd_t *cmd;
7050 + ipkg_conf_t ipkg_conf;
7051 + int err;
7052 +
7053 + /* this error should be handled in application */
7054 + if (!file || !strlen (file))
7055 + return (-1);
7056 +
7057 + err = ipkg_conf_init (&ipkg_conf, args);
7058 + if (err)
7059 + {
7060 + return err;
7061 + }
7062 +
7063 + /* we need to do this because of static declarations,
7064 + * maybe a good idea to change */
7065 + cmd = ipkg_cmd_find (command);
7066 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7067 +
7068 + ipkg_conf_deinit(&ipkg_conf);
7069 + return(err);
7070 +}
7071 +
7072 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7073 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7074 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7075 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7076 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7077 +
7078 +
7079 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7080 + char *msg)
7081 +{
7082 + if (conf && (conf->verbosity < level)) {
7083 + return 0;
7084 + } else {
7085 +#ifdef IPKG_LIB
7086 + if ( level == IPKG_ERROR ){
7087 + push_error_list(&error_list, msg);
7088 +// printf(msg);
7089 + } else
7090 +#endif
7091 + printf(msg);
7092 + }
7093 + return 0;
7094 +}
7095 +
7096 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7097 + pkg_state_status_t status, void *userdata)
7098 +{
7099 + if (desc)
7100 + printf("%s - %s - %s\n", name, version, desc);
7101 + else
7102 + printf("%s - %s\n", name, version);
7103 + return 0;
7104 +}
7105 +
7106 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7107 + pkg_state_status_t status, void *userdata)
7108 +{
7109 + if (desc)
7110 + printf("%s\n", desc);
7111 + return 0;
7112 +}
7113 +
7114 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7115 + void *userdata)
7116 +{
7117 + printf("%s\n", desc);
7118 + return 0;
7119 +}
7120 +
7121 +char* default_ipkg_response_callback(char *question)
7122 +{
7123 + char *response = NULL;
7124 + printf(question);
7125 + fflush(stdout);
7126 + do {
7127 + response = (char *)file_read_line_alloc(stdin);
7128 + } while (response == NULL);
7129 + return response;
7130 +}
7131 +
7132 +/* This is used for backward compatibility */
7133 +int
7134 +ipkg_op (int argc, char *argv[])
7135 +{
7136 + int err, opt_index;
7137 + args_t args;
7138 + char *cmd_name;
7139 + ipkg_cmd_t *cmd;
7140 + ipkg_conf_t ipkg_conf;
7141 +
7142 + args_init (&args);
7143 +
7144 + opt_index = args_parse (&args, argc, argv);
7145 + if (opt_index == argc || opt_index < 0)
7146 + {
7147 + args_usage ("ipkg must have one sub-command argument");
7148 + }
7149 +
7150 + cmd_name = argv[opt_index++];
7151 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7152 + read anything from there.
7153 +*/
7154 + if ( !strcmp(cmd_name,"print-architecture") ||
7155 + !strcmp(cmd_name,"print_architecture") ||
7156 + !strcmp(cmd_name,"print-installation-architecture") ||
7157 + !strcmp(cmd_name,"print_installation_architecture") )
7158 + args.nocheckfordirorfile = 1;
7159 +
7160 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7161 + read anything from there.
7162 +*/
7163 + if ( !strcmp(cmd_name,"flag") ||
7164 + !strcmp(cmd_name,"configure") ||
7165 + !strcmp(cmd_name,"remove") ||
7166 + !strcmp(cmd_name,"files") ||
7167 + !strcmp(cmd_name,"search") ||
7168 + !strcmp(cmd_name,"compare_versions") ||
7169 + !strcmp(cmd_name,"compare-versions") ||
7170 + !strcmp(cmd_name,"list_installed") ||
7171 + !strcmp(cmd_name,"list-installed") ||
7172 + !strcmp(cmd_name,"status") )
7173 + args.noreadfeedsfile = 1;
7174 +
7175 +
7176 + err = ipkg_conf_init (&ipkg_conf, &args);
7177 + if (err)
7178 + {
7179 + return err;
7180 + }
7181 +
7182 + args_deinit (&args);
7183 +
7184 + ipkg_cb_message = default_ipkg_message_callback;
7185 + ipkg_cb_response = default_ipkg_response_callback;
7186 + ipkg_cb_status = default_ipkg_status_callback;
7187 + if ( strcmp(cmd_name, "files")==0)
7188 + ipkg_cb_list = default_ipkg_files_callback;
7189 + else
7190 + ipkg_cb_list = default_ipkg_list_callback;
7191 +
7192 + cmd = ipkg_cmd_find (cmd_name);
7193 + if (cmd == NULL)
7194 + {
7195 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7196 + cmd_name);
7197 + args_usage (NULL);
7198 + }
7199 +
7200 + if (cmd->requires_args && opt_index == argc)
7201 + {
7202 + fprintf (stderr,
7203 + "%s: the ``%s'' command requires at least one argument\n",
7204 + __FUNCTION__, cmd_name);
7205 + args_usage (NULL);
7206 + }
7207 +
7208 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7209 +
7210 + ipkg_conf_deinit (&ipkg_conf);
7211 +
7212 + return err;
7213 +}
7214 +
7215 +#endif /* IPKG_LIB */
7216 Index: busybox-1.8.1/archival/libipkg/libipkg.h
7217 ===================================================================
7218 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7219 +++ busybox-1.8.1/archival/libipkg/libipkg.h 2007-11-10 17:40:53.364764882 +0100
7220 @@ -0,0 +1,88 @@
7221 +/* ipkglib.h - the itsy package management system
7222 +
7223 + Florian Boor <florian.boor@kernelconcepts.de>
7224 +
7225 + This program is free software; you can redistribute it and/or
7226 + modify it under the terms of the GNU General Public License as
7227 + published by the Free Software Foundation; either version 2, or (at
7228 + your option) any later version.
7229 +
7230 + This program is distributed in the hope that it will be useful, but
7231 + WITHOUT ANY WARRANTY; without even the implied warranty of
7232 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7233 + General Public License for more details.
7234 +*/
7235 +
7236 +#ifndef IPKGLIB_H
7237 +#define IPKGLIB_H
7238 +
7239 +#ifdef IPKG_LIB
7240 +
7241 +#include "ipkg_conf.h"
7242 +#include "ipkg_message.h"
7243 +
7244 +#include "libbb.h"
7245 +#include "args.h"
7246 +#include "pkg.h"
7247 +
7248 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7249 + char *msg);
7250 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7251 + pkg_state_status_t status, void *userdata);
7252 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7253 + void *userdata);
7254 +typedef char* (*ipkg_response_callback)(char *question);
7255 +
7256 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7257 +extern int ipkg_init (ipkg_message_callback mcall,
7258 + ipkg_response_callback rcall,
7259 + args_t * args);
7260 +
7261 +extern int ipkg_deinit (args_t *args);
7262 +extern int ipkg_packages_list(args_t *args,
7263 + const char *packages,
7264 + ipkg_list_callback cblist,
7265 + void *userdata);
7266 +extern int ipkg_packages_status(args_t *args,
7267 + const char *packages,
7268 + ipkg_status_callback cbstatus,
7269 + void *userdata);
7270 +extern int ipkg_packages_info(args_t *args,
7271 + const char *packages,
7272 + ipkg_status_callback cbstatus,
7273 + void *userdata);
7274 +extern int ipkg_packages_install(args_t *args, const char *name);
7275 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7276 +extern int ipkg_lists_update(args_t *args);
7277 +extern int ipkg_packages_upgrade(args_t *args);
7278 +extern int ipkg_packages_download(args_t *args, const char *name);
7279 +extern int ipkg_package_files(args_t *args,
7280 + const char *name,
7281 + ipkg_list_callback cblist,
7282 + void *userdata);
7283 +extern int ipkg_file_search(args_t *args,
7284 + const char *file,
7285 + ipkg_list_callback cblist,
7286 + void *userdata);
7287 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7288 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7289 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7290 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7291 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7292 +
7293 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7294 +extern ipkg_response_callback ipkg_cb_response;
7295 +extern ipkg_status_callback ipkg_cb_status;
7296 +extern ipkg_list_callback ipkg_cb_list;
7297 +extern void push_error_list(struct errlist **errors,char * msg);
7298 +extern void reverse_error_list(struct errlist **errors);
7299 +extern void free_error_list(struct errlist **errors);
7300 +
7301 +#else
7302 +
7303 +extern int ipkg_op(int argc, char *argv[]);
7304 +
7305 +#endif
7306 +
7307 +
7308 +#endif
7309 Index: busybox-1.8.1/archival/libipkg/nv_pair.c
7310 ===================================================================
7311 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7312 +++ busybox-1.8.1/archival/libipkg/nv_pair.c 2007-11-10 17:40:53.364764882 +0100
7313 @@ -0,0 +1,40 @@
7314 +/* nv_pair.c - the itsy package management system
7315 +
7316 + Carl D. Worth
7317 +
7318 + Copyright (C) 2001 University of Southern California
7319 +
7320 + This program is free software; you can redistribute it and/or
7321 + modify it under the terms of the GNU General Public License as
7322 + published by the Free Software Foundation; either version 2, or (at
7323 + your option) any later version.
7324 +
7325 + This program is distributed in the hope that it will be useful, but
7326 + WITHOUT ANY WARRANTY; without even the implied warranty of
7327 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7328 + General Public License for more details.
7329 +*/
7330 +
7331 +#include "ipkg.h"
7332 +
7333 +#include "nv_pair.h"
7334 +#include "str_util.h"
7335 +
7336 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7337 +{
7338 + nv_pair->name = str_dup_safe(name);
7339 + nv_pair->value = str_dup_safe(value);
7340 +
7341 + return 0;
7342 +}
7343 +
7344 +void nv_pair_deinit(nv_pair_t *nv_pair)
7345 +{
7346 + free(nv_pair->name);
7347 + nv_pair->name = NULL;
7348 +
7349 + free(nv_pair->value);
7350 + nv_pair->value = NULL;
7351 +}
7352 +
7353 +
7354 Index: busybox-1.8.1/archival/libipkg/nv_pair.h
7355 ===================================================================
7356 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7357 +++ busybox-1.8.1/archival/libipkg/nv_pair.h 2007-11-10 17:40:53.372765337 +0100
7358 @@ -0,0 +1,32 @@
7359 +/* nv_pair.h - the itsy package management system
7360 +
7361 + Carl D. Worth
7362 +
7363 + Copyright (C) 2001 University of Southern California
7364 +
7365 + This program is free software; you can redistribute it and/or
7366 + modify it under the terms of the GNU General Public License as
7367 + published by the Free Software Foundation; either version 2, or (at
7368 + your option) any later version.
7369 +
7370 + This program is distributed in the hope that it will be useful, but
7371 + WITHOUT ANY WARRANTY; without even the implied warranty of
7372 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7373 + General Public License for more details.
7374 +*/
7375 +
7376 +#ifndef NV_PAIR_H
7377 +#define NV_PAIR_H
7378 +
7379 +typedef struct nv_pair nv_pair_t;
7380 +struct nv_pair
7381 +{
7382 + char *name;
7383 + char *value;
7384 +};
7385 +
7386 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7387 +void nv_pair_deinit(nv_pair_t *nv_pair);
7388 +
7389 +#endif
7390 +
7391 Index: busybox-1.8.1/archival/libipkg/nv_pair_list.c
7392 ===================================================================
7393 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7394 +++ busybox-1.8.1/archival/libipkg/nv_pair_list.c 2007-11-10 17:40:53.372765337 +0100
7395 @@ -0,0 +1,98 @@
7396 +/* nv_pair_list.c - the itsy package management system
7397 +
7398 + Carl D. Worth
7399 +
7400 + Copyright (C) 2001 University of Southern California
7401 +
7402 + This program is free software; you can redistribute it and/or
7403 + modify it under the terms of the GNU General Public License as
7404 + published by the Free Software Foundation; either version 2, or (at
7405 + your option) any later version.
7406 +
7407 + This program is distributed in the hope that it will be useful, but
7408 + WITHOUT ANY WARRANTY; without even the implied warranty of
7409 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7410 + General Public License for more details.
7411 +*/
7412 +
7413 +#include "ipkg.h"
7414 +
7415 +#include "nv_pair.h"
7416 +#include "void_list.h"
7417 +#include "nv_pair_list.h"
7418 +
7419 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7420 +{
7421 + return void_list_elt_init((void_list_elt_t *) elt, data);
7422 +}
7423 +
7424 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7425 +{
7426 + void_list_elt_deinit((void_list_elt_t *) elt);
7427 +}
7428 +
7429 +int nv_pair_list_init(nv_pair_list_t *list)
7430 +{
7431 + return void_list_init((void_list_t *) list);
7432 +}
7433 +
7434 +void nv_pair_list_deinit(nv_pair_list_t *list)
7435 +{
7436 + nv_pair_list_elt_t *iter;
7437 + nv_pair_t *nv_pair;
7438 +
7439 + for (iter = list->head; iter; iter = iter->next) {
7440 + nv_pair = iter->data;
7441 + nv_pair_deinit(nv_pair);
7442 +
7443 + /* malloced in nv_pair_list_append */
7444 + free(nv_pair);
7445 + iter->data = NULL;
7446 + }
7447 + void_list_deinit((void_list_t *) list);
7448 +}
7449 +
7450 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7451 +{
7452 + int err;
7453 +
7454 + /* freed in nv_pair_list_deinit */
7455 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7456 +
7457 + if (nv_pair == NULL) {
7458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7459 + return NULL;
7460 + }
7461 + nv_pair_init(nv_pair, name, value);
7462 +
7463 + err = void_list_append((void_list_t *) list, nv_pair);
7464 + if (err) {
7465 + return NULL;
7466 + }
7467 +
7468 + return nv_pair;
7469 +}
7470 +
7471 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7472 +{
7473 + return void_list_push((void_list_t *) list, data);
7474 +}
7475 +
7476 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7477 +{
7478 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7479 +}
7480 +
7481 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7482 +{
7483 + nv_pair_list_elt_t *iter;
7484 + nv_pair_t *nv_pair;
7485 +
7486 + for (iter = list->head; iter; iter = iter->next) {
7487 + nv_pair = iter->data;
7488 + if (strcmp(nv_pair->name, name) == 0) {
7489 + return nv_pair->value;
7490 + }
7491 + }
7492 + return NULL;
7493 +}
7494 Index: busybox-1.8.1/archival/libipkg/nv_pair_list.h
7495 ===================================================================
7496 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7497 +++ busybox-1.8.1/archival/libipkg/nv_pair_list.h 2007-11-10 17:40:53.372765337 +0100
7498 @@ -0,0 +1,60 @@
7499 +/* nv_pair_list.h - the itsy package management system
7500 +
7501 + Carl D. Worth
7502 +
7503 + Copyright (C) 2001 University of Southern California
7504 +
7505 + This program is free software; you can redistribute it and/or
7506 + modify it under the terms of the GNU General Public License as
7507 + published by the Free Software Foundation; either version 2, or (at
7508 + your option) any later version.
7509 +
7510 + This program is distributed in the hope that it will be useful, but
7511 + WITHOUT ANY WARRANTY; without even the implied warranty of
7512 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7513 + General Public License for more details.
7514 +*/
7515 +
7516 +#ifndef NV_PAIR_LIST_H
7517 +#define NV_PAIR_LIST_H
7518 +
7519 +#include "nv_pair.h"
7520 +#include "void_list.h"
7521 +
7522 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7523 +struct nv_pair_list_elt
7524 +{
7525 + nv_pair_list_elt_t *next;
7526 + nv_pair_t *data;
7527 +};
7528 +
7529 +typedef struct nv_pair_list nv_pair_list_t;
7530 +struct nv_pair_list
7531 +{
7532 + nv_pair_list_elt_t pre_head;
7533 + nv_pair_list_elt_t *head;
7534 + nv_pair_list_elt_t *tail;
7535 +};
7536 +
7537 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7538 +{
7539 + if (list->head == NULL)
7540 + return 1;
7541 + else
7542 + return 0;
7543 +}
7544 +
7545 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7546 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7547 +
7548 +int nv_pair_list_init(nv_pair_list_t *list);
7549 +void nv_pair_list_deinit(nv_pair_list_t *list);
7550 +
7551 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7552 + const char *name, const char *value);
7553 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7554 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7555 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7556 +
7557 +#endif
7558 +
7559 Index: busybox-1.8.1/archival/libipkg/pkg.c
7560 ===================================================================
7561 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7562 +++ busybox-1.8.1/archival/libipkg/pkg.c 2007-11-10 17:40:53.376765566 +0100
7563 @@ -0,0 +1,1747 @@
7564 +/* pkg.c - the itsy package management system
7565 +
7566 + Carl D. Worth
7567 +
7568 + Copyright (C) 2001 University of Southern California
7569 +
7570 + This program is free software; you can redistribute it and/or
7571 + modify it under the terms of the GNU General Public License as
7572 + published by the Free Software Foundation; either version 2, or (at
7573 + your option) any later version.
7574 +
7575 + This program is distributed in the hope that it will be useful, but
7576 + WITHOUT ANY WARRANTY; without even the implied warranty of
7577 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7578 + General Public License for more details.
7579 +*/
7580 +
7581 +#include "ipkg.h"
7582 +#include <ctype.h>
7583 +#include <string.h>
7584 +#include <errno.h>
7585 +
7586 +#include "pkg.h"
7587 +
7588 +#include "pkg_parse.h"
7589 +#include "pkg_extract.h"
7590 +#include "ipkg_message.h"
7591 +#include "ipkg_utils.h"
7592 +
7593 +#include "sprintf_alloc.h"
7594 +#include "file_util.h"
7595 +#include "str_util.h"
7596 +#include "xsystem.h"
7597 +#include "ipkg_conf.h"
7598 +
7599 +typedef struct enum_map enum_map_t;
7600 +struct enum_map
7601 +{
7602 + int value;
7603 + char *str;
7604 +};
7605 +
7606 +static const enum_map_t pkg_state_want_map[] = {
7607 + { SW_UNKNOWN, "unknown"},
7608 + { SW_INSTALL, "install"},
7609 + { SW_DEINSTALL, "deinstall"},
7610 + { SW_PURGE, "purge"}
7611 +};
7612 +
7613 +static const enum_map_t pkg_state_flag_map[] = {
7614 + { SF_OK, "ok"},
7615 + { SF_REINSTREQ, "reinstreq"},
7616 + { SF_HOLD, "hold"},
7617 + { SF_REPLACE, "replace"},
7618 + { SF_NOPRUNE, "noprune"},
7619 + { SF_PREFER, "prefer"},
7620 + { SF_OBSOLETE, "obsolete"},
7621 + { SF_USER, "user"},
7622 +};
7623 +
7624 +static const enum_map_t pkg_state_status_map[] = {
7625 + { SS_NOT_INSTALLED, "not-installed" },
7626 + { SS_UNPACKED, "unpacked" },
7627 + { SS_HALF_CONFIGURED, "half-configured" },
7628 + { SS_INSTALLED, "installed" },
7629 + { SS_HALF_INSTALLED, "half-installed" },
7630 + { SS_CONFIG_FILES, "config-files" },
7631 + { SS_POST_INST_FAILED, "post-inst-failed" },
7632 + { SS_REMOVAL_FAILED, "removal-failed" }
7633 +};
7634 +
7635 +static int verrevcmp(const char *val, const char *ref);
7636 +
7637 +
7638 +pkg_t *pkg_new(void)
7639 +{
7640 + pkg_t *pkg;
7641 +
7642 + pkg = malloc(sizeof(pkg_t));
7643 + if (pkg == NULL) {
7644 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7645 + return NULL;
7646 + }
7647 +
7648 + pkg_init(pkg);
7649 +
7650 + return pkg;
7651 +}
7652 +
7653 +int pkg_init(pkg_t *pkg)
7654 +{
7655 + memset(pkg, 0, sizeof(pkg_t));
7656 + pkg->name = NULL;
7657 + pkg->epoch = 0;
7658 + pkg->version = NULL;
7659 + pkg->revision = NULL;
7660 + pkg->familiar_revision = NULL;
7661 + pkg->dest = NULL;
7662 + pkg->src = NULL;
7663 + pkg->architecture = NULL;
7664 + pkg->maintainer = NULL;
7665 + pkg->section = NULL;
7666 + pkg->description = NULL;
7667 + pkg->state_want = SW_UNKNOWN;
7668 + pkg->state_flag = SF_OK;
7669 + pkg->state_status = SS_NOT_INSTALLED;
7670 + pkg->depends_str = NULL;
7671 + pkg->provides_str = NULL;
7672 + pkg->depends_count = 0;
7673 + pkg->depends = NULL;
7674 + pkg->suggests_str = NULL;
7675 + pkg->recommends_str = NULL;
7676 + pkg->suggests_count = 0;
7677 + pkg->recommends_count = 0;
7678 +
7679 + /* Abhaya: added init for conflicts fields */
7680 + pkg->conflicts = NULL;
7681 + pkg->conflicts_count = 0;
7682 +
7683 + /* added for replaces. Jamey 7/23/2002 */
7684 + pkg->replaces = NULL;
7685 + pkg->replaces_count = 0;
7686 +
7687 + pkg->pre_depends_count = 0;
7688 + pkg->pre_depends_str = NULL;
7689 + pkg->provides_count = 0;
7690 + pkg->provides = NULL;
7691 + pkg->filename = NULL;
7692 + pkg->local_filename = NULL;
7693 + pkg->tmp_unpack_dir = NULL;
7694 + pkg->md5sum = NULL;
7695 + pkg->size = NULL;
7696 + pkg->installed_size = NULL;
7697 + pkg->priority = NULL;
7698 + pkg->source = NULL;
7699 + conffile_list_init(&pkg->conffiles);
7700 + pkg->installed_files = NULL;
7701 + pkg->installed_files_ref_cnt = 0;
7702 + pkg->essential = 0;
7703 + pkg->provided_by_hand = 0;
7704 +
7705 + return 0;
7706 +}
7707 +
7708 +void pkg_deinit(pkg_t *pkg)
7709 +{
7710 + free(pkg->name);
7711 + pkg->name = NULL;
7712 + pkg->epoch = 0;
7713 + free(pkg->version);
7714 + pkg->version = NULL;
7715 + /* revision and familiar_revision share storage with version, so
7716 + don't free */
7717 + pkg->revision = NULL;
7718 + pkg->familiar_revision = NULL;
7719 + /* owned by ipkg_conf_t */
7720 + pkg->dest = NULL;
7721 + /* owned by ipkg_conf_t */
7722 + pkg->src = NULL;
7723 + free(pkg->architecture);
7724 + pkg->architecture = NULL;
7725 + free(pkg->maintainer);
7726 + pkg->maintainer = NULL;
7727 + free(pkg->section);
7728 + pkg->section = NULL;
7729 + free(pkg->description);
7730 + pkg->description = NULL;
7731 + pkg->state_want = SW_UNKNOWN;
7732 + pkg->state_flag = SF_OK;
7733 + pkg->state_status = SS_NOT_INSTALLED;
7734 + free(pkg->depends_str);
7735 + pkg->depends_str = NULL;
7736 + free(pkg->provides_str);
7737 + pkg->provides_str = NULL;
7738 + pkg->depends_count = 0;
7739 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7740 + pkg->pre_depends_count = 0;
7741 + free(pkg->pre_depends_str);
7742 + pkg->pre_depends_str = NULL;
7743 + pkg->provides_count = 0;
7744 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7745 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7746 + free(pkg->filename);
7747 + pkg->filename = NULL;
7748 + free(pkg->local_filename);
7749 + pkg->local_filename = NULL;
7750 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7751 + ipkg_install.c here. See comment in
7752 + ipkg_install.c:cleanup_temporary_files */
7753 + free(pkg->tmp_unpack_dir);
7754 + pkg->tmp_unpack_dir = NULL;
7755 + free(pkg->md5sum);
7756 + pkg->md5sum = NULL;
7757 + free(pkg->size);
7758 + pkg->size = NULL;
7759 + free(pkg->installed_size);
7760 + pkg->installed_size = NULL;
7761 + free(pkg->priority);
7762 + pkg->priority = NULL;
7763 + free(pkg->source);
7764 + pkg->source = NULL;
7765 + conffile_list_deinit(&pkg->conffiles);
7766 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7767 + since if they are calling deinit, they should know. Maybe do an
7768 + assertion here instead? */
7769 + pkg->installed_files_ref_cnt = 1;
7770 + pkg_free_installed_files(pkg);
7771 + pkg->essential = 0;
7772 +}
7773 +
7774 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7775 +{
7776 + int err;
7777 + char **raw;
7778 + FILE *control_file;
7779 +
7780 + err = pkg_init(pkg);
7781 + if (err) { return err; }
7782 +
7783 + pkg->local_filename = strdup(filename);
7784 +
7785 + control_file = tmpfile();
7786 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7787 + if (err) { return err; }
7788 +
7789 + rewind(control_file);
7790 + raw = read_raw_pkgs_from_stream(control_file);
7791 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7792 +
7793 + fclose(control_file);
7794 +
7795 + return 0;
7796 +}
7797 +
7798 +/* Merge any new information in newpkg into oldpkg */
7799 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7800 + newpkg, but should leave it usable. This rework is so that
7801 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7802 +/*
7803 + * uh, i thought that i had originally written this so that it took
7804 + * two pkgs and returned a new one? we can do that again... -sma
7805 + */
7806 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7807 +{
7808 + if (oldpkg == newpkg) {
7809 + return 0;
7810 + }
7811 +
7812 + if (!oldpkg->src)
7813 + oldpkg->src = newpkg->src;
7814 + if (!oldpkg->dest)
7815 + oldpkg->dest = newpkg->dest;
7816 + if (!oldpkg->architecture)
7817 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7818 + if (!oldpkg->arch_priority)
7819 + oldpkg->arch_priority = newpkg->arch_priority;
7820 + if (!oldpkg->section)
7821 + oldpkg->section = str_dup_safe(newpkg->section);
7822 + if(!oldpkg->maintainer)
7823 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7824 + if(!oldpkg->description)
7825 + oldpkg->description = str_dup_safe(newpkg->description);
7826 + if (set_status) {
7827 + /* merge the state_flags from the new package */
7828 + oldpkg->state_want = newpkg->state_want;
7829 + oldpkg->state_status = newpkg->state_status;
7830 + oldpkg->state_flag = newpkg->state_flag;
7831 + } else {
7832 + if (oldpkg->state_want == SW_UNKNOWN)
7833 + oldpkg->state_want = newpkg->state_want;
7834 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7835 + oldpkg->state_status = newpkg->state_status;
7836 + oldpkg->state_flag |= newpkg->state_flag;
7837 + }
7838 +
7839 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7840 + oldpkg->depends_str = newpkg->depends_str;
7841 + newpkg->depends_str = NULL;
7842 + oldpkg->depends_count = newpkg->depends_count;
7843 + newpkg->depends_count = 0;
7844 +
7845 + oldpkg->depends = newpkg->depends;
7846 + newpkg->depends = NULL;
7847 +
7848 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7849 + newpkg->pre_depends_str = NULL;
7850 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7851 + newpkg->pre_depends_count = 0;
7852 +
7853 + oldpkg->recommends_str = newpkg->recommends_str;
7854 + newpkg->recommends_str = NULL;
7855 + oldpkg->recommends_count = newpkg->recommends_count;
7856 + newpkg->recommends_count = 0;
7857 +
7858 + oldpkg->suggests_str = newpkg->suggests_str;
7859 + newpkg->suggests_str = NULL;
7860 + oldpkg->suggests_count = newpkg->suggests_count;
7861 + newpkg->suggests_count = 0;
7862 + }
7863 +
7864 + if (!oldpkg->provides_str) {
7865 + oldpkg->provides_str = newpkg->provides_str;
7866 + newpkg->provides_str = NULL;
7867 + oldpkg->provides_count = newpkg->provides_count;
7868 + newpkg->provides_count = 0;
7869 +
7870 + oldpkg->provides = newpkg->provides;
7871 + newpkg->provides = NULL;
7872 + }
7873 +
7874 + if (!oldpkg->conflicts_str) {
7875 + oldpkg->conflicts_str = newpkg->conflicts_str;
7876 + newpkg->conflicts_str = NULL;
7877 + oldpkg->conflicts_count = newpkg->conflicts_count;
7878 + newpkg->conflicts_count = 0;
7879 +
7880 + oldpkg->conflicts = newpkg->conflicts;
7881 + newpkg->conflicts = NULL;
7882 + }
7883 +
7884 + if (!oldpkg->replaces_str) {
7885 + oldpkg->replaces_str = newpkg->replaces_str;
7886 + newpkg->replaces_str = NULL;
7887 + oldpkg->replaces_count = newpkg->replaces_count;
7888 + newpkg->replaces_count = 0;
7889 +
7890 + oldpkg->replaces = newpkg->replaces;
7891 + newpkg->replaces = NULL;
7892 + }
7893 +
7894 + if (!oldpkg->filename)
7895 + oldpkg->filename = str_dup_safe(newpkg->filename);
7896 + if (0)
7897 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7898 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7899 + if (!oldpkg->local_filename)
7900 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7901 + if (!oldpkg->tmp_unpack_dir)
7902 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7903 + if (!oldpkg->md5sum)
7904 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7905 + if (!oldpkg->size)
7906 + oldpkg->size = str_dup_safe(newpkg->size);
7907 + if (!oldpkg->installed_size)
7908 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7909 + if (!oldpkg->priority)
7910 + oldpkg->priority = str_dup_safe(newpkg->priority);
7911 + if (!oldpkg->source)
7912 + oldpkg->source = str_dup_safe(newpkg->source);
7913 + if (oldpkg->conffiles.head == NULL){
7914 + oldpkg->conffiles = newpkg->conffiles;
7915 + conffile_list_init(&newpkg->conffiles);
7916 + }
7917 + if (!oldpkg->installed_files){
7918 + oldpkg->installed_files = newpkg->installed_files;
7919 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7920 + newpkg->installed_files = NULL;
7921 + }
7922 + if (!oldpkg->essential)
7923 + oldpkg->essential = newpkg->essential;
7924 +
7925 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7926 +
7927 + return 0;
7928 +}
7929 +
7930 +abstract_pkg_t *abstract_pkg_new(void)
7931 +{
7932 + abstract_pkg_t * ab_pkg;
7933 +
7934 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7935 +
7936 + if (ab_pkg == NULL) {
7937 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7938 + return NULL;
7939 + }
7940 +
7941 + if ( abstract_pkg_init(ab_pkg) < 0 )
7942 + return NULL;
7943 +
7944 + return ab_pkg;
7945 +}
7946 +
7947 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7948 +{
7949 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7950 +
7951 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7952 + if (ab_pkg->provided_by==NULL){
7953 + return -1;
7954 + }
7955 + ab_pkg->dependencies_checked = 0;
7956 + ab_pkg->state_status = SS_NOT_INSTALLED;
7957 +
7958 + return 0;
7959 +}
7960 +
7961 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7962 + char * temp_str;
7963 + char **raw =NULL;
7964 + char **raw_start=NULL;
7965 +
7966 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7967 + if (temp_str == NULL ){
7968 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7969 + return;
7970 + }
7971 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7972 +
7973 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7974 + if (raw == NULL ){
7975 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7976 + return;
7977 + }
7978 +
7979 + while(*raw){
7980 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7981 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7982 + }
7983 + }
7984 + raw = raw_start;
7985 + while (*raw) {
7986 + if (raw!=NULL)
7987 + free(*raw++);
7988 + }
7989 +
7990 + free(raw_start);
7991 + free(temp_str);
7992 +
7993 + return ;
7994 +
7995 +}
7996 +
7997 +char * pkg_formatted_info(pkg_t *pkg )
7998 +{
7999 + char *line;
8000 + char * buff;
8001 +
8002 + buff = malloc(8192);
8003 + if (buff == NULL) {
8004 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8005 + return NULL;
8006 + }
8007 +
8008 + buff[0] = '\0';
8009 +
8010 + line = pkg_formatted_field(pkg, "Package");
8011 + strncat(buff ,line, strlen(line));
8012 + free(line);
8013 +
8014 + line = pkg_formatted_field(pkg, "Version");
8015 + strncat(buff ,line, strlen(line));
8016 + free(line);
8017 +
8018 + line = pkg_formatted_field(pkg, "Depends");
8019 + strncat(buff ,line, strlen(line));
8020 + free(line);
8021 +
8022 + line = pkg_formatted_field(pkg, "Recommends");
8023 + strncat(buff ,line, strlen(line));
8024 + free(line);
8025 +
8026 + line = pkg_formatted_field(pkg, "Suggests");
8027 + strncat(buff ,line, strlen(line));
8028 + free(line);
8029 +
8030 + line = pkg_formatted_field(pkg, "Provides");
8031 + strncat(buff ,line, strlen(line));
8032 + free(line);
8033 +
8034 + line = pkg_formatted_field(pkg, "Replaces");
8035 + strncat(buff ,line, strlen(line));
8036 + free(line);
8037 +
8038 + line = pkg_formatted_field(pkg, "Conflicts");
8039 + strncat(buff ,line, strlen(line));
8040 + free(line);
8041 +
8042 + line = pkg_formatted_field(pkg, "Status");
8043 + strncat(buff ,line, strlen(line));
8044 + free(line);
8045 +
8046 + line = pkg_formatted_field(pkg, "Section");
8047 + strncat(buff ,line, strlen(line));
8048 + free(line);
8049 +
8050 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8051 + strncat(buff ,line, strlen(line));
8052 + free(line);
8053 +
8054 + line = pkg_formatted_field(pkg, "Architecture");
8055 + strncat(buff ,line, strlen(line));
8056 + free(line);
8057 +
8058 + line = pkg_formatted_field(pkg, "Maintainer");
8059 + strncat(buff ,line, strlen(line));
8060 + free(line);
8061 +
8062 + line = pkg_formatted_field(pkg, "MD5sum");
8063 + strncat(buff ,line, strlen(line));
8064 + free(line);
8065 +
8066 + line = pkg_formatted_field(pkg, "Size");
8067 + strncat(buff ,line, strlen(line));
8068 + free(line);
8069 +
8070 + line = pkg_formatted_field(pkg, "Filename");
8071 + strncat(buff ,line, strlen(line));
8072 + free(line);
8073 +
8074 + line = pkg_formatted_field(pkg, "Conffiles");
8075 + strncat(buff ,line, strlen(line));
8076 + free(line);
8077 +
8078 + line = pkg_formatted_field(pkg, "Source");
8079 + strncat(buff ,line, strlen(line));
8080 + free(line);
8081 +
8082 + line = pkg_formatted_field(pkg, "Description");
8083 + strncat(buff ,line, strlen(line));
8084 + free(line);
8085 +
8086 + line = pkg_formatted_field(pkg, "Installed-Time");
8087 + strncat(buff ,line, strlen(line));
8088 + free(line);
8089 +
8090 + return buff;
8091 +}
8092 +
8093 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8094 +{
8095 + static size_t LINE_LEN = 128;
8096 + char line_str[LINE_LEN];
8097 + char * temp = (char *)malloc(1);
8098 + int len = 0;
8099 + int flag_provide_false = 0;
8100 +
8101 +/*
8102 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8103 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8104 +*/
8105 +
8106 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8107 + goto UNKNOWN_FMT_FIELD;
8108 + }
8109 +
8110 + temp[0]='\0';
8111 +
8112 + switch (field[0])
8113 + {
8114 + case 'a':
8115 + case 'A':
8116 + if (strcasecmp(field, "Architecture") == 0) {
8117 + /* Architecture */
8118 + if (pkg->architecture) {
8119 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8120 + if ( temp == NULL ){
8121 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8122 + return NULL;
8123 + }
8124 + temp[0]='\0';
8125 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8126 + }
8127 + } else {
8128 + goto UNKNOWN_FMT_FIELD;
8129 + }
8130 + break;
8131 + case 'c':
8132 + case 'C':
8133 + if (strcasecmp(field, "Conffiles") == 0) {
8134 + /* Conffiles */
8135 + conffile_list_elt_t *iter;
8136 +
8137 + if (pkg->conffiles.head == NULL) {
8138 + return temp;
8139 + }
8140 +
8141 + len = 14 ;
8142 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8143 + if (iter->data->name && iter->data->value) {
8144 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8145 + }
8146 + }
8147 + temp = (char *)realloc(temp,len);
8148 + if ( temp == NULL ){
8149 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8150 + return NULL;
8151 + }
8152 + temp[0]='\0';
8153 + strncpy(temp, "Conffiles:\n", 12);
8154 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8155 + if (iter->data->name && iter->data->value) {
8156 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8157 + strncat(temp, line_str, strlen(line_str));
8158 + }
8159 + }
8160 + } else if (strcasecmp(field, "Conflicts") == 0) {
8161 + int i;
8162 +
8163 + if (pkg->conflicts_count) {
8164 + len = 14 ;
8165 + for(i = 0; i < pkg->conflicts_count; i++) {
8166 + len = len + (strlen(pkg->conflicts_str[i])+5);
8167 + }
8168 + temp = (char *)realloc(temp,len);
8169 + if ( temp == NULL ){
8170 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8171 + return NULL;
8172 + }
8173 + temp[0]='\0';
8174 + strncpy(temp, "Conflicts:", 11);
8175 + for(i = 0; i < pkg->conflicts_count; i++) {
8176 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8177 + strncat(temp, line_str, strlen(line_str));
8178 + }
8179 + strncat(temp, "\n", strlen("\n"));
8180 + }
8181 + } else {
8182 + goto UNKNOWN_FMT_FIELD;
8183 + }
8184 + break;
8185 + case 'd':
8186 + case 'D':
8187 + if (strcasecmp(field, "Depends") == 0) {
8188 + /* Depends */
8189 + int i;
8190 +
8191 + if (pkg->depends_count) {
8192 + len = 14 ;
8193 + for(i = 0; i < pkg->depends_count; i++) {
8194 + len = len + (strlen(pkg->depends_str[i])+4);
8195 + }
8196 + temp = (char *)realloc(temp,len);
8197 + if ( temp == NULL ){
8198 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8199 + return NULL;
8200 + }
8201 + temp[0]='\0';
8202 + strncpy(temp, "Depends:", 10);
8203 + for(i = 0; i < pkg->depends_count; i++) {
8204 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8205 + strncat(temp, line_str, strlen(line_str));
8206 + }
8207 + strncat(temp, "\n", strlen("\n"));
8208 + }
8209 + } else if (strcasecmp(field, "Description") == 0) {
8210 + /* Description */
8211 + if (pkg->description) {
8212 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8213 + if ( temp == NULL ){
8214 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8215 + return NULL;
8216 + }
8217 + temp[0]='\0';
8218 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8219 + }
8220 + } else {
8221 + goto UNKNOWN_FMT_FIELD;
8222 + }
8223 + break;
8224 + case 'e':
8225 + case 'E': {
8226 + /* Essential */
8227 + if (pkg->essential) {
8228 + temp = (char *)realloc(temp,16);
8229 + if ( temp == NULL ){
8230 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8231 + return NULL;
8232 + }
8233 + temp[0]='\0';
8234 + snprintf(temp, (16), "Essential: yes\n");
8235 + }
8236 + }
8237 + break;
8238 + case 'f':
8239 + case 'F': {
8240 + /* Filename */
8241 + if (pkg->filename) {
8242 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8243 + if ( temp == NULL ){
8244 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8245 + return NULL;
8246 + }
8247 + temp[0]='\0';
8248 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8249 + }
8250 + }
8251 + break;
8252 + case 'i':
8253 + case 'I': {
8254 + if (strcasecmp(field, "Installed-Size") == 0) {
8255 + /* Installed-Size */
8256 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8257 + if ( temp == NULL ){
8258 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8259 + return NULL;
8260 + }
8261 + temp[0]='\0';
8262 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8263 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8264 + temp = (char *)realloc(temp,29);
8265 + if ( temp == NULL ){
8266 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8267 + return NULL;
8268 + }
8269 + temp[0]='\0';
8270 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8271 + }
8272 + }
8273 + break;
8274 + case 'm':
8275 + case 'M': {
8276 + /* Maintainer | MD5sum */
8277 + if (strcasecmp(field, "Maintainer") == 0) {
8278 + /* Maintainer */
8279 + if (pkg->maintainer) {
8280 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8281 + if ( temp == NULL ){
8282 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8283 + return NULL;
8284 + }
8285 + temp[0]='\0';
8286 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8287 + }
8288 + } else if (strcasecmp(field, "MD5sum") == 0) {
8289 + /* MD5sum */
8290 + if (pkg->md5sum) {
8291 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8292 + if ( temp == NULL ){
8293 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8294 + return NULL;
8295 + }
8296 + temp[0]='\0';
8297 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8298 + }
8299 + } else {
8300 + goto UNKNOWN_FMT_FIELD;
8301 + }
8302 + }
8303 + break;
8304 + case 'p':
8305 + case 'P': {
8306 + if (strcasecmp(field, "Package") == 0) {
8307 + /* Package */
8308 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8309 + if ( temp == NULL ){
8310 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8311 + return NULL;
8312 + }
8313 + temp[0]='\0';
8314 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8315 + } else if (strcasecmp(field, "Priority") == 0) {
8316 + /* Priority */
8317 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8318 + if ( temp == NULL ){
8319 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8320 + return NULL;
8321 + }
8322 + temp[0]='\0';
8323 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8324 + } else if (strcasecmp(field, "Provides") == 0) {
8325 + /* Provides */
8326 + int i;
8327 +
8328 + if (pkg->provides_count) {
8329 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8330 + for ( i=0; i < pkg->provides_count; i++ ){
8331 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8332 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8333 + flag_provide_false = 1;
8334 + }
8335 + }
8336 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8337 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8338 + char provstr[LINE_LEN];
8339 + len = 15;
8340 + for(i = 0; i < pkg->provides_count; i++) {
8341 + len = len + (strlen(pkg->provides_str[i])+5);
8342 + }
8343 + temp = (char *)realloc(temp,len);
8344 + if ( temp == NULL ){
8345 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8346 + return NULL;
8347 + }
8348 + temp[0]='\0';
8349 + strncpy(temp, "Provides:", 12);
8350 + for(i = 0; i < pkg->provides_count; i++) {
8351 + if (strlen(pkg->provides_str[i])>0){;
8352 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8353 + strncat(temp, provstr, strlen(provstr));
8354 + }
8355 + }
8356 + strncat(temp, "\n", strlen("\n"));
8357 + }
8358 + }
8359 + } else {
8360 + goto UNKNOWN_FMT_FIELD;
8361 + }
8362 + }
8363 + break;
8364 + case 'r':
8365 + case 'R': {
8366 + int i;
8367 + /* Replaces | Recommends*/
8368 + if (strcasecmp (field, "Replaces") == 0) {
8369 + if (pkg->replaces_count) {
8370 + len = 14;
8371 + for (i = 0; i < pkg->replaces_count; i++) {
8372 + len = len + (strlen(pkg->replaces_str[i])+5);
8373 + }
8374 + temp = (char *)realloc(temp,len);
8375 + if ( temp == NULL ){
8376 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8377 + return NULL;
8378 + }
8379 + temp[0]='\0';
8380 + strncpy(temp, "Replaces:", 12);
8381 + for (i = 0; i < pkg->replaces_count; i++) {
8382 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8383 + strncat(temp, line_str, strlen(line_str));
8384 + }
8385 + strncat(temp, "\n", strlen("\n"));
8386 + }
8387 + } else if (strcasecmp (field, "Recommends") == 0) {
8388 + if (pkg->recommends_count) {
8389 + len = 15;
8390 + for(i = 0; i < pkg->recommends_count; i++) {
8391 + len = len + (strlen( pkg->recommends_str[i])+5);
8392 + }
8393 + temp = (char *)realloc(temp,len);
8394 + if ( temp == NULL ){
8395 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8396 + return NULL;
8397 + }
8398 + temp[0]='\0';
8399 + strncpy(temp, "Recommends:", 13);
8400 + for(i = 0; i < pkg->recommends_count; i++) {
8401 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8402 + strncat(temp, line_str, strlen(line_str));
8403 + }
8404 + strncat(temp, "\n", strlen("\n"));
8405 + }
8406 + } else {
8407 + goto UNKNOWN_FMT_FIELD;
8408 + }
8409 + }
8410 + break;
8411 + case 's':
8412 + case 'S': {
8413 + /* Section | Size | Source | Status | Suggests */
8414 + if (strcasecmp(field, "Section") == 0) {
8415 + /* Section */
8416 + if (pkg->section) {
8417 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8418 + if ( temp == NULL ){
8419 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8420 + return NULL;
8421 + }
8422 + temp[0]='\0';
8423 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8424 + }
8425 + } else if (strcasecmp(field, "Size") == 0) {
8426 + /* Size */
8427 + if (pkg->size) {
8428 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8429 + if ( temp == NULL ){
8430 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8431 + return NULL;
8432 + }
8433 + temp[0]='\0';
8434 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8435 + }
8436 + } else if (strcasecmp(field, "Source") == 0) {
8437 + /* Source */
8438 + if (pkg->source) {
8439 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8440 + if ( temp == NULL ){
8441 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8442 + return NULL;
8443 + }
8444 + temp[0]='\0';
8445 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8446 + }
8447 + } else if (strcasecmp(field, "Status") == 0) {
8448 + /* Status */
8449 + /* Benjamin Pineau note: we should avoid direct usage of
8450 + * strlen(arg) without keeping "arg" for later free()
8451 + */
8452 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8453 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8454 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8455 +
8456 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8457 + temp = (char *)realloc(temp,sum_of_sizes);
8458 + if ( temp == NULL ){
8459 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8460 + return NULL;
8461 + }
8462 + temp[0]='\0';
8463 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8464 + free(pflag);
8465 + free(pwant);
8466 + if(pstat) /* pfstat can be NULL if ENOMEM */
8467 + free(pstat);
8468 + } else if (strcasecmp(field, "Suggests") == 0) {
8469 + if (pkg->suggests_count) {
8470 + int i;
8471 + len = 13;
8472 + for(i = 0; i < pkg->suggests_count; i++) {
8473 + len = len + (strlen(pkg->suggests_str[i])+5);
8474 + }
8475 + temp = (char *)realloc(temp,len);
8476 + if ( temp == NULL ){
8477 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8478 + return NULL;
8479 + }
8480 + temp[0]='\0';
8481 + strncpy(temp, "Suggests:", 10);
8482 + for(i = 0; i < pkg->suggests_count; i++) {
8483 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8484 + strncat(temp, line_str, strlen(line_str));
8485 + }
8486 + strncat(temp, "\n", strlen("\n"));
8487 + }
8488 + } else {
8489 + goto UNKNOWN_FMT_FIELD;
8490 + }
8491 + }
8492 + break;
8493 + case 'v':
8494 + case 'V': {
8495 + /* Version */
8496 + char *version = pkg_version_str_alloc(pkg);
8497 + temp = (char *)realloc(temp,strlen(version)+14);
8498 + if ( temp == NULL ){
8499 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8500 + return NULL;
8501 + }
8502 + temp[0]='\0';
8503 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8504 + free(version);
8505 + }
8506 + break;
8507 + default:
8508 + goto UNKNOWN_FMT_FIELD;
8509 + }
8510 +
8511 + if ( strlen(temp)<2 ) {
8512 + temp[0]='\0';
8513 + }
8514 + return temp;
8515 +
8516 + UNKNOWN_FMT_FIELD:
8517 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8518 + if ( strlen(temp)<2 ) {
8519 + temp[0]='\0';
8520 + }
8521 +
8522 + return temp;
8523 +}
8524 +
8525 +void pkg_print_info(pkg_t *pkg, FILE *file)
8526 +{
8527 + char * buff;
8528 + if (pkg == NULL) {
8529 + return;
8530 + }
8531 +
8532 + buff = pkg_formatted_info(pkg);
8533 + if ( buff == NULL )
8534 + return;
8535 + if (strlen(buff)>2){
8536 + fwrite(buff, 1, strlen(buff), file);
8537 + }
8538 + free(buff);
8539 +}
8540 +
8541 +void pkg_print_status(pkg_t * pkg, FILE * file)
8542 +{
8543 + if (pkg == NULL) {
8544 + return;
8545 + }
8546 +
8547 + /* XXX: QUESTION: Do we actually want more fields here? The
8548 + original idea was to save space by installing only what was
8549 + needed for actual computation, (package, version, status,
8550 + essential, conffiles). The assumption is that all other fields
8551 + can be found in th available file.
8552 +
8553 + But, someone proposed the idea to make it possible to
8554 + reconstruct a .ipk from an installed package, (ie. for beaming
8555 + from one handheld to another). So, maybe we actually want a few
8556 + more fields here, (depends, suggests, etc.), so that that would
8557 + be guaranteed to work even in the absence of more information
8558 + from the available file.
8559 +
8560 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8561 + the essential info needs to be here for all installed packages
8562 + because they may not appear in the Packages files on various
8563 + feeds. Furthermore, one should be able to install from URL or
8564 + local storage without requiring a Packages file from any feed.
8565 + -Jamey
8566 + */
8567 + pkg_print_field(pkg, file, "Package");
8568 + pkg_print_field(pkg, file, "Version");
8569 + pkg_print_field(pkg, file, "Depends");
8570 + pkg_print_field(pkg, file, "Recommends");
8571 + pkg_print_field(pkg, file, "Suggests");
8572 + pkg_print_field(pkg, file, "Provides");
8573 + pkg_print_field(pkg, file, "Replaces");
8574 + pkg_print_field(pkg, file, "Conflicts");
8575 + pkg_print_field(pkg, file, "Status");
8576 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8577 + pkg_print_field(pkg, file, "Architecture");
8578 + pkg_print_field(pkg, file, "Conffiles");
8579 + pkg_print_field(pkg, file, "Installed-Time");
8580 + fputs("\n", file);
8581 +}
8582 +
8583 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8584 +{
8585 + char *buff;
8586 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8587 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8588 + __FUNCTION__, field);
8589 + }
8590 + buff = pkg_formatted_field(pkg, field);
8591 + if (strlen(buff)>2) {
8592 + fprintf(file, "%s", buff);
8593 + fflush(file);
8594 + }
8595 + free(buff);
8596 + return;
8597 +}
8598 +
8599 +/*
8600 + * libdpkg - Debian packaging suite library routines
8601 + * vercmp.c - comparison of version numbers
8602 + *
8603 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8604 + */
8605 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8606 +{
8607 + int r;
8608 +
8609 + if (pkg->epoch > ref_pkg->epoch) {
8610 + return 1;
8611 + }
8612 +
8613 + if (pkg->epoch < ref_pkg->epoch) {
8614 + return -1;
8615 + }
8616 +
8617 + r = verrevcmp(pkg->version, ref_pkg->version);
8618 + if (r) {
8619 + return r;
8620 + }
8621 +
8622 +#ifdef USE_DEBVERSION
8623 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8624 + if (r) {
8625 + return r;
8626 + }
8627 +
8628 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8629 +#endif
8630 +
8631 + return r;
8632 +}
8633 +
8634 +int verrevcmp(const char *val, const char *ref)
8635 +{
8636 + int vc, rc;
8637 + long vl, rl;
8638 + const char *vp, *rp;
8639 + const char *vsep, *rsep;
8640 +
8641 + if (!val) val= "";
8642 + if (!ref) ref= "";
8643 + for (;;) {
8644 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8645 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8646 + for (;;) {
8647 + vc= (val == vp) ? 0 : *val++;
8648 + rc= (ref == rp) ? 0 : *ref++;
8649 + if (!rc && !vc) break;
8650 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8651 + if (rc && !isalpha(rc)) rc += 256;
8652 + if (vc != rc) return vc - rc;
8653 + }
8654 + val= vp;
8655 + ref= rp;
8656 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8657 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8658 + if (vl != rl) return vl - rl;
8659 +
8660 + vc = *val;
8661 + rc = *ref;
8662 + vsep = strchr(".-", vc);
8663 + rsep = strchr(".-", rc);
8664 + if (vsep && !rsep) return -1;
8665 + if (!vsep && rsep) return +1;
8666 +
8667 + if (!*val && !*ref) return 0;
8668 + if (!*val) return -1;
8669 + if (!*ref) return +1;
8670 + }
8671 +}
8672 +
8673 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8674 +{
8675 + int r;
8676 +
8677 + r = pkg_compare_versions(it, ref);
8678 +
8679 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8680 + return r <= 0;
8681 + }
8682 +
8683 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8684 + return r >= 0;
8685 + }
8686 +
8687 + if (strcmp(op, "<<") == 0) {
8688 + return r < 0;
8689 + }
8690 +
8691 + if (strcmp(op, ">>") == 0) {
8692 + return r > 0;
8693 + }
8694 +
8695 + if (strcmp(op, "=") == 0) {
8696 + return r == 0;
8697 + }
8698 +
8699 + fprintf(stderr, "unknown operator: %s", op);
8700 + return 0;
8701 +}
8702 +
8703 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8704 +{
8705 + int namecmp;
8706 + int vercmp;
8707 + if (!a->name || !b->name) {
8708 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8709 + a, a->name, b, b->name);
8710 + return 0;
8711 + }
8712 +
8713 + namecmp = strcmp(a->name, b->name);
8714 + if (namecmp)
8715 + return namecmp;
8716 + vercmp = pkg_compare_versions(a, b);
8717 + if (vercmp)
8718 + return vercmp;
8719 + if (!a->arch_priority || !b->arch_priority) {
8720 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8721 + a, a->arch_priority, b, b->arch_priority);
8722 + return 0;
8723 + }
8724 + if (a->arch_priority > b->arch_priority)
8725 + return 1;
8726 + if (a->arch_priority < b->arch_priority)
8727 + return -1;
8728 + return 0;
8729 +}
8730 +
8731 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8732 +{
8733 + if (!a->name || !b->name) {
8734 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8735 + a, a->name, b, b->name);
8736 + return 0;
8737 + }
8738 + return strcmp(a->name, b->name);
8739 +}
8740 +
8741 +
8742 +char *pkg_version_str_alloc(pkg_t *pkg)
8743 +{
8744 + char *complete_version;
8745 + char *epoch_str;
8746 +#ifdef USE_DEBVERSION
8747 + char *revision_str;
8748 + char *familiar_revision_str;
8749 +#endif
8750 +
8751 + if (pkg->epoch) {
8752 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8753 + } else {
8754 + epoch_str = strdup("");
8755 + }
8756 +
8757 +#ifdef USE_DEBVERSION
8758 + if (pkg->revision && strlen(pkg->revision)) {
8759 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8760 + } else {
8761 + revision_str = strdup("");
8762 + }
8763 +
8764 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8765 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8766 + } else {
8767 + familiar_revision_str = strdup("");
8768 + }
8769 +#endif
8770 +
8771 +#ifdef USE_DEBVERSION
8772 + sprintf_alloc(&complete_version, "%s%s%s%s",
8773 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8774 +#else
8775 + sprintf_alloc(&complete_version, "%s%s",
8776 + epoch_str, pkg->version);
8777 +#endif
8778 +
8779 + free(epoch_str);
8780 +#ifdef USE_DEBVERSION
8781 + free(revision_str);
8782 + free(familiar_revision_str);
8783 +#endif
8784 +
8785 + return complete_version;
8786 +}
8787 +
8788 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8789 +{
8790 + int err;
8791 + char *list_file_name = NULL;
8792 + FILE *list_file = NULL;
8793 + char *line;
8794 + char *installed_file_name;
8795 + int rootdirlen;
8796 +
8797 + pkg->installed_files_ref_cnt++;
8798 +
8799 + if (pkg->installed_files) {
8800 + return pkg->installed_files;
8801 + }
8802 +
8803 + pkg->installed_files = str_list_alloc();
8804 + if (pkg->installed_files == NULL) {
8805 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8806 + return NULL;
8807 + }
8808 +
8809 + /* For uninstalled packages, get the file list firectly from the package.
8810 + For installed packages, look at the package.list file in the database.
8811 + */
8812 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8813 + if (pkg->local_filename == NULL) {
8814 + return pkg->installed_files;
8815 + }
8816 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8817 + file. In other words, change deb_extract so that it can
8818 + simply return the file list as a char *[] rather than
8819 + insisting on writing in to a FILE * as it does now. */
8820 + list_file = tmpfile();
8821 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8822 + if (err) {
8823 + fclose(list_file);
8824 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8825 + __FUNCTION__, pkg->local_filename, strerror(err));
8826 + return pkg->installed_files;
8827 + }
8828 + rewind(list_file);
8829 + } else {
8830 + sprintf_alloc(&list_file_name, "%s/%s.list",
8831 + pkg->dest->info_dir, pkg->name);
8832 + if (! file_exists(list_file_name)) {
8833 + free(list_file_name);
8834 + return pkg->installed_files;
8835 + }
8836 +
8837 + list_file = fopen(list_file_name, "r");
8838 + if (list_file == NULL) {
8839 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8840 + list_file_name, strerror(errno));
8841 + free(list_file_name);
8842 + return pkg->installed_files;
8843 + }
8844 + free(list_file_name);
8845 + }
8846 +
8847 + rootdirlen = strlen( pkg->dest->root_dir );
8848 + while (1) {
8849 + char *file_name;
8850 +
8851 + line = file_read_line_alloc(list_file);
8852 + if (line == NULL) {
8853 + break;
8854 + }
8855 + str_chomp(line);
8856 + file_name = line;
8857 +
8858 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8859 + if( strncmp( pkg->dest->root_dir,
8860 + file_name,
8861 + rootdirlen ) ) {
8862 + if (*file_name == '.') {
8863 + file_name++;
8864 + }
8865 + if (*file_name == '/') {
8866 + file_name++;
8867 + }
8868 +
8869 + /* Freed in pkg_free_installed_files */
8870 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8871 + } else {
8872 + // already contains root_dir as header -> ABSOLUTE
8873 + sprintf_alloc(&installed_file_name, "%s", file_name);
8874 + }
8875 + str_list_append(pkg->installed_files, installed_file_name);
8876 + free(line);
8877 + }
8878 +
8879 + fclose(list_file);
8880 +
8881 + return pkg->installed_files;
8882 +}
8883 +
8884 +/* XXX: CLEANUP: This function and it's counterpart,
8885 + (pkg_get_installed_files), do not match our init/deinit naming
8886 + convention. Nor the alloc/free convention. But, then again, neither
8887 + of these conventions currrently fit the way these two functions
8888 + work. */
8889 +int pkg_free_installed_files(pkg_t *pkg)
8890 +{
8891 + str_list_elt_t *iter;
8892 +
8893 + pkg->installed_files_ref_cnt--;
8894 + if (pkg->installed_files_ref_cnt > 0) {
8895 + return 0;
8896 + }
8897 +
8898 + if (pkg->installed_files) {
8899 +
8900 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8901 + /* malloced in pkg_get_installed_files */
8902 + free (iter->data);
8903 + iter->data = NULL;
8904 + }
8905 +
8906 + str_list_deinit(pkg->installed_files);
8907 + }
8908 +
8909 + pkg->installed_files = NULL;
8910 +
8911 + return 0;
8912 +}
8913 +
8914 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8915 +{
8916 + int err;
8917 + char *list_file_name;
8918 +
8919 + //I don't think pkg_free_installed_files should be called here. Jamey
8920 + //pkg_free_installed_files(pkg);
8921 +
8922 + sprintf_alloc(&list_file_name, "%s/%s.list",
8923 + pkg->dest->info_dir, pkg->name);
8924 + if (!conf->noaction) {
8925 + err = unlink(list_file_name);
8926 + free(list_file_name);
8927 +
8928 + if (err) {
8929 + return errno;
8930 + }
8931 + }
8932 + return 0;
8933 +}
8934 +
8935 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8936 +{
8937 + conffile_list_elt_t *iter;
8938 + conffile_t *conffile;
8939 +
8940 + if (pkg == NULL) {
8941 + return NULL;
8942 + }
8943 +
8944 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8945 + conffile = iter->data;
8946 +
8947 + if (strcmp(conffile->name, file_name) == 0) {
8948 + return conffile;
8949 + }
8950 + }
8951 +
8952 + return NULL;
8953 +}
8954 +
8955 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8956 + const char *script, const char *args)
8957 +{
8958 + int err;
8959 + char *path;
8960 + char *cmd;
8961 +
8962 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8963 + maintainer script within a chroot environment. */
8964 +
8965 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8966 + have scripts in pkg->tmp_unpack_dir. */
8967 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8968 + if (pkg->dest == NULL) {
8969 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8970 + __FUNCTION__, pkg->name);
8971 + return EINVAL;
8972 + }
8973 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8974 + } else {
8975 + if (pkg->tmp_unpack_dir == NULL) {
8976 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8977 + __FUNCTION__, pkg->name);
8978 + return EINVAL;
8979 + }
8980 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8981 + }
8982 +
8983 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8984 + if (conf->noaction) return 0;
8985 +
8986 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8987 + scripts when running with offline_root mode and/or a dest other
8988 + than '/'. I've been playing around with some clever chroot
8989 + tricks and I might come up with something workable. */
8990 + if (conf->offline_root) {
8991 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8992 + }
8993 +
8994 + setenv("PKG_ROOT",
8995 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8996 +
8997 + if (! file_exists(path)) {
8998 + free(path);
8999 + return 0;
9000 + }
9001 +
9002 + if (conf->offline_root) {
9003 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9004 + free(path);
9005 + return 0;
9006 + }
9007 +
9008 + sprintf_alloc(&cmd, "%s %s", path, args);
9009 + free(path);
9010 +
9011 + err = xsystem(cmd);
9012 + free(cmd);
9013 +
9014 + if (err) {
9015 + fprintf(stderr, "%s script returned status %d\n", script, err);
9016 + return err;
9017 + }
9018 +
9019 + return 0;
9020 +}
9021 +
9022 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9023 +{
9024 + int i;
9025 +
9026 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9027 + if (pkg_state_want_map[i].value == sw) {
9028 + return strdup(pkg_state_want_map[i].str);
9029 + }
9030 + }
9031 +
9032 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9033 + __FUNCTION__, sw);
9034 + return strdup("<STATE_WANT_UNKNOWN>");
9035 +}
9036 +
9037 +pkg_state_want_t pkg_state_want_from_str(char *str)
9038 +{
9039 + int i;
9040 +
9041 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9042 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9043 + return pkg_state_want_map[i].value;
9044 + }
9045 + }
9046 +
9047 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9048 + __FUNCTION__, str);
9049 + return SW_UNKNOWN;
9050 +}
9051 +
9052 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9053 +{
9054 + int i;
9055 + int len = 3; /* ok\000 is minimum */
9056 + char *str = NULL;
9057 +
9058 + /* clear the temporary flags before converting to string */
9059 + sf &= SF_NONVOLATILE_FLAGS;
9060 +
9061 + if (sf == 0) {
9062 + return strdup("ok");
9063 + } else {
9064 +
9065 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9066 + if (sf & pkg_state_flag_map[i].value) {
9067 + len += strlen(pkg_state_flag_map[i].str) + 1;
9068 + }
9069 + }
9070 + str = malloc(len);
9071 + if ( str == NULL ) {
9072 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9073 + return NULL;
9074 + }
9075 + str[0] = 0;
9076 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9077 + if (sf & pkg_state_flag_map[i].value) {
9078 + strcat(str, pkg_state_flag_map[i].str);
9079 + strcat(str, ",");
9080 + }
9081 + }
9082 + len = strlen(str);
9083 + str[len-1] = 0; /* squash last comma */
9084 + return str;
9085 + }
9086 +}
9087 +
9088 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9089 +{
9090 + int i;
9091 + int sf = SF_OK;
9092 +
9093 + if (strcmp(str, "ok") == 0) {
9094 + return SF_OK;
9095 + }
9096 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9097 + const char *sfname = pkg_state_flag_map[i].str;
9098 + int sfname_len = strlen(sfname);
9099 + if (strncmp(str, sfname, sfname_len) == 0) {
9100 + sf |= pkg_state_flag_map[i].value;
9101 + str += sfname_len;
9102 + if (str[0] == ',') {
9103 + str++;
9104 + } else {
9105 + break;
9106 + }
9107 + }
9108 + }
9109 +
9110 + return sf;
9111 +}
9112 +
9113 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9114 +{
9115 + int i;
9116 +
9117 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9118 + if (pkg_state_status_map[i].value == ss) {
9119 + return strdup(pkg_state_status_map[i].str);
9120 + }
9121 + }
9122 +
9123 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9124 + __FUNCTION__, ss);
9125 + return strdup("<STATE_STATUS_UNKNOWN>");
9126 +}
9127 +
9128 +pkg_state_status_t pkg_state_status_from_str(char *str)
9129 +{
9130 + int i;
9131 +
9132 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9133 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9134 + return pkg_state_status_map[i].value;
9135 + }
9136 + }
9137 +
9138 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9139 + __FUNCTION__, str);
9140 + return SS_NOT_INSTALLED;
9141 +}
9142 +
9143 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9144 +{
9145 + nv_pair_list_elt_t *l;
9146 +
9147 + if (!pkg->architecture)
9148 + return 1;
9149 +
9150 + l = conf->arch_list.head;
9151 +
9152 + while (l) {
9153 + nv_pair_t *nv = l->data;
9154 + if (strcmp(nv->name, pkg->architecture) == 0) {
9155 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9156 + return 1;
9157 + }
9158 + l = l->next;
9159 + }
9160 +
9161 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9162 + return 0;
9163 +}
9164 +
9165 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9166 +{
9167 + nv_pair_list_elt_t *l;
9168 +
9169 + l = conf->arch_list.head;
9170 +
9171 + while (l) {
9172 + nv_pair_t *nv = l->data;
9173 + if (strcmp(nv->name, archname) == 0) {
9174 + int priority = strtol(nv->value, NULL, 0);
9175 + return priority;
9176 + }
9177 + l = l->next;
9178 + }
9179 + return 0;
9180 +}
9181 +
9182 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9183 +{
9184 + int i;
9185 + hash_table_t *pkg_hash = &conf->pkg_hash;
9186 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9187 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9188 +
9189 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9190 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9191 + /* update arch_priority for each package */
9192 + for (i = 0; i < available_pkgs->len; i++) {
9193 + pkg_t *pkg = available_pkgs->pkgs[i];
9194 + int arch_priority = 1;
9195 + if (!pkg)
9196 + continue;
9197 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9198 + if (pkg->architecture)
9199 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9200 + else
9201 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9202 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9203 + pkg->arch_priority = arch_priority;
9204 + }
9205 +
9206 + for (i = 0; i < available_pkgs->len; i++) {
9207 + pkg_t *pkg = available_pkgs->pkgs[i];
9208 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9209 + /* clear flags and want for any uninstallable package */
9210 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9211 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9212 + pkg->state_want = SW_UNKNOWN;
9213 + pkg->state_flag = 0;
9214 + }
9215 + }
9216 + pkg_vec_free(available_pkgs);
9217 +
9218 + /* update the file owner data structure */
9219 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9220 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9221 + for (i = 0; i < installed_pkgs->len; i++) {
9222 + pkg_t *pkg = installed_pkgs->pkgs[i];
9223 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9224 + str_list_elt_t *iter;
9225 + if (installed_files == NULL) {
9226 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9227 + break;
9228 + }
9229 + for (iter = installed_files->head; iter; iter = iter->next) {
9230 + char *installed_file = iter->data;
9231 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9232 + file_hash_set_file_owner(conf, installed_file, pkg);
9233 + }
9234 + }
9235 + pkg_vec_free(installed_pkgs);
9236 +
9237 + return 0;
9238 +}
9239 +
9240 +struct pkg_write_filelist_data {
9241 + ipkg_conf_t *conf;
9242 + pkg_t *pkg;
9243 + FILE *stream;
9244 +};
9245 +
9246 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9247 +{
9248 + struct pkg_write_filelist_data *data = data_;
9249 + pkg_t *entry = entry_;
9250 + if (entry == data->pkg) {
9251 + fprintf(data->stream, "%s\n", key);
9252 + }
9253 +}
9254 +
9255 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9256 +{
9257 + struct pkg_write_filelist_data data;
9258 + char *list_file_name = NULL;
9259 + int err = 0;
9260 +
9261 + if (!pkg) {
9262 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9263 + return -EINVAL;
9264 + }
9265 + ipkg_message(conf, IPKG_INFO,
9266 + " creating %s.list file\n", pkg->name);
9267 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9268 + if (!list_file_name) {
9269 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9270 + return -ENOMEM;
9271 + }
9272 + ipkg_message(conf, IPKG_INFO,
9273 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9274 + data.stream = fopen(list_file_name, "w");
9275 + if (!data.stream) {
9276 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9277 + list_file_name, strerror(errno));
9278 + return errno;
9279 + }
9280 + data.pkg = pkg;
9281 + data.conf = conf;
9282 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9283 + fclose(data.stream);
9284 + free(list_file_name);
9285 +
9286 + return err;
9287 +}
9288 +
9289 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9290 +{
9291 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9292 + hash_table_t *pkg_hash = &conf->pkg_hash;
9293 + int i;
9294 + int err;
9295 + if (conf->noaction)
9296 + return 0;
9297 +
9298 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9299 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9300 + for (i = 0; i < installed_pkgs->len; i++) {
9301 + pkg_t *pkg = installed_pkgs->pkgs[i];
9302 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9303 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9304 + err = pkg_write_filelist(conf, pkg);
9305 + if (err)
9306 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9307 + }
9308 + }
9309 + return 0;
9310 +}
9311 Index: busybox-1.8.1/archival/libipkg/pkg_depends.c
9312 ===================================================================
9313 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9314 +++ busybox-1.8.1/archival/libipkg/pkg_depends.c 2007-11-10 17:40:53.376765566 +0100
9315 @@ -0,0 +1,1031 @@
9316 +/* pkg_depends.c - the itsy package management system
9317 +
9318 + Steven M. Ayer
9319 +
9320 + Copyright (C) 2002 Compaq Computer Corporation
9321 +
9322 + This program is free software; you can redistribute it and/or
9323 + modify it under the terms of the GNU General Public License as
9324 + published by the Free Software Foundation; either version 2, or (at
9325 + your option) any later version.
9326 +
9327 + This program is distributed in the hope that it will be useful, but
9328 + WITHOUT ANY WARRANTY; without even the implied warranty of
9329 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9330 + General Public License for more details.
9331 +*/
9332 +
9333 +#include "ipkg.h"
9334 +#include <errno.h>
9335 +#include <ctype.h>
9336 +
9337 +#include "pkg.h"
9338 +#include "ipkg_utils.h"
9339 +#include "pkg_hash.h"
9340 +#include "ipkg_message.h"
9341 +#include "pkg_parse.h"
9342 +#include "hash_table.h"
9343 +
9344 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9345 +static depend_t * depend_init(void);
9346 +static void depend_deinit(depend_t *d);
9347 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9348 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9349 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9350 +
9351 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9352 +{
9353 + depend_t *depend = (depend_t *)cdata;
9354 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9355 + return 1;
9356 + else
9357 + return 0;
9358 +}
9359 +
9360 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9361 +{
9362 + depend_t *depend = (depend_t *)cdata;
9363 +#if 0
9364 + pkg_t * temp = pkg_new();
9365 + int comparison;
9366 + parseVersion(temp, depend->version);
9367 + comparison = pkg_compare_versions(pkg, temp);
9368 + free(temp);
9369 +
9370 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9371 + __FUNCTION__, pkg->name, pkg->version,
9372 + depend, depend->constraint, depend->version,
9373 + comparison, version_constraints_satisfied(depend, pkg));
9374 +#endif
9375 + if (version_constraints_satisfied(depend, pkg))
9376 + return 1;
9377 + else
9378 + return 0;
9379 +}
9380 +
9381 +/* returns ndependences or negative error value */
9382 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9383 + pkg_vec_t *unsatisfied, char *** unresolved)
9384 +{
9385 + pkg_t * satisfier_entry_pkg;
9386 + register int i, j, k, l;
9387 + int count, found;
9388 + char ** the_lost;
9389 + abstract_pkg_t * ab_pkg;
9390 +
9391 + /*
9392 + * this is a setup to check for redundant/cyclic dependency checks,
9393 + * which are marked at the abstract_pkg level
9394 + */
9395 + if (!(ab_pkg = pkg->parent)) {
9396 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9397 + *unresolved = NULL;
9398 + return 0;
9399 + }
9400 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9401 + *unresolved = NULL;
9402 + return 0;
9403 + } else {
9404 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9405 + }
9406 + /**/
9407 +
9408 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9409 + if (!count){
9410 + *unresolved = NULL;
9411 + return 0;
9412 + }
9413 +
9414 + the_lost = NULL;
9415 +
9416 + /* foreach dependency */
9417 + for (i = 0; i < count; i++) {
9418 + compound_depend_t * compound_depend = &pkg->depends[i];
9419 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9420 + found = 0;
9421 + satisfier_entry_pkg = NULL;
9422 +
9423 + if (compound_depend->type == GREEDY_DEPEND) {
9424 + /* foreach possible satisfier */
9425 + for (j = 0; j < compound_depend->possibility_count; j++) {
9426 + /* foreach provided_by, which includes the abstract_pkg itself */
9427 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9428 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9429 + int nposs = ab_provider_vec->len;
9430 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9431 + for (l = 0; l < nposs; l++) {
9432 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9433 + /* if no depends on this one, try the first package that Provides this one */
9434 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9435 + continue;
9436 + }
9437 +
9438 + /* cruise this possiblity's pkg_vec looking for an installed version */
9439 + for (k = 0; k < test_vec->len; k++) {
9440 + pkg_t *pkg_scout = test_vec->pkgs[k];
9441 + /* not installed, and not already known about? */
9442 + if ((pkg_scout->state_want != SW_INSTALL)
9443 + && !pkg_scout->parent->dependencies_checked
9444 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9445 + char ** newstuff = NULL;
9446 + int rc;
9447 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9448 + /* check for not-already-installed dependencies */
9449 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9450 + pkg_scout,
9451 + tmp_vec,
9452 + &newstuff);
9453 + if (newstuff == NULL) {
9454 + int ok = 1;
9455 + for (l = 0; l < rc; l++) {
9456 + pkg_t *p = tmp_vec->pkgs[l];
9457 + if (p->state_want == SW_INSTALL)
9458 + continue;
9459 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9460 + ok = 0;
9461 + break;
9462 + }
9463 + pkg_vec_free (tmp_vec);
9464 + if (ok) {
9465 + /* mark this one for installation */
9466 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9467 + pkg_vec_insert(unsatisfied, pkg_scout);
9468 + }
9469 + } else {
9470 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9471 + free (newstuff);
9472 + }
9473 + }
9474 + }
9475 + }
9476 + }
9477 +
9478 + continue;
9479 + }
9480 +
9481 + /* foreach possible satisfier, look for installed package */
9482 + for (j = 0; j < compound_depend->possibility_count; j++) {
9483 + /* foreach provided_by, which includes the abstract_pkg itself */
9484 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9485 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9486 + pkg_t *satisfying_pkg =
9487 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9488 + pkg_installed_and_constraint_satisfied,
9489 + dependence_to_satisfy, 1);
9490 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9491 + if (satisfying_pkg != NULL) {
9492 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9493 + satisfying_pkg = NULL;
9494 + }
9495 + }
9496 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9497 + if (satisfying_pkg != NULL) {
9498 + found = 1;
9499 + break;
9500 + }
9501 +
9502 + }
9503 + /* if nothing installed matches, then look for uninstalled satisfier */
9504 + if (!found) {
9505 + /* foreach possible satisfier, look for installed package */
9506 + for (j = 0; j < compound_depend->possibility_count; j++) {
9507 + /* foreach provided_by, which includes the abstract_pkg itself */
9508 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9509 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9510 + pkg_t *satisfying_pkg =
9511 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9512 + pkg_constraint_satisfied,
9513 + dependence_to_satisfy, 1);
9514 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9515 + if (satisfying_pkg != NULL) {
9516 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9517 + satisfying_pkg = NULL;
9518 + }
9519 + }
9520 +
9521 + /* user request overrides package recommendation */
9522 + if (satisfying_pkg != NULL
9523 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9524 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9525 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9526 + pkg->name, satisfying_pkg->name);
9527 + continue;
9528 + }
9529 +
9530 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9531 + if (satisfying_pkg != NULL) {
9532 + satisfier_entry_pkg = satisfying_pkg;
9533 + break;
9534 + }
9535 + }
9536 + }
9537 +
9538 + /* we didn't find one, add something to the unsatisfied vector */
9539 + if (!found) {
9540 + if (!satisfier_entry_pkg) {
9541 + /* failure to meet recommendations is not an error */
9542 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9543 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9544 + else
9545 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9546 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9547 + }
9548 + else {
9549 + if (compound_depend->type == SUGGEST) {
9550 + /* just mention it politely */
9551 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9552 + pkg->name, satisfier_entry_pkg->name);
9553 + } else {
9554 + char ** newstuff = NULL;
9555 +
9556 + if (satisfier_entry_pkg != pkg &&
9557 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9558 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9559 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9560 + satisfier_entry_pkg,
9561 + unsatisfied,
9562 + &newstuff);
9563 + the_lost = merge_unresolved(the_lost, newstuff);
9564 + }
9565 + }
9566 + }
9567 + }
9568 + }
9569 + *unresolved = the_lost;
9570 +
9571 + return unsatisfied->len;
9572 +}
9573 +
9574 +/*checking for conflicts !in replaces
9575 + If a packages conflicts with another but is also replacing it, I should not consider it a
9576 + really conflicts
9577 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9578 +*/
9579 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9580 +{
9581 + int i ;
9582 + int replaces_count = pkg->replaces_count;
9583 + abstract_pkg_t **replaces;
9584 +
9585 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9586 + return 0;
9587 +
9588 + replaces = pkg->replaces;
9589 +
9590 + for (i = 0; i < replaces_count; i++) {
9591 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9592 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9593 + return 1;
9594 + }
9595 + }
9596 + return 0;
9597 +
9598 +}
9599 +
9600 +
9601 +/* Abhaya: added support for conflicts */
9602 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9603 +{
9604 + pkg_vec_t * installed_conflicts, * test_vec;
9605 + compound_depend_t * conflicts;
9606 + depend_t ** possible_satisfiers;
9607 + depend_t * possible_satisfier;
9608 + register int i, j, k;
9609 + int count;
9610 + abstract_pkg_t * ab_pkg;
9611 + pkg_t **pkg_scouts;
9612 + pkg_t *pkg_scout;
9613 +
9614 + /*
9615 + * this is a setup to check for redundant/cyclic dependency checks,
9616 + * which are marked at the abstract_pkg level
9617 + */
9618 + if(!(ab_pkg = pkg->parent)){
9619 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9620 + return (pkg_vec_t *)NULL;
9621 + }
9622 +
9623 + conflicts = pkg->conflicts;
9624 + if(!conflicts){
9625 + return (pkg_vec_t *)NULL;
9626 + }
9627 + installed_conflicts = pkg_vec_alloc();
9628 +
9629 + count = pkg->conflicts_count;
9630 +
9631 +
9632 +
9633 + /* foreach conflict */
9634 + for(i = 0; i < pkg->conflicts_count; i++){
9635 +
9636 + possible_satisfiers = conflicts->possibilities;
9637 +
9638 + /* foreach possible satisfier */
9639 + for(j = 0; j < conflicts->possibility_count; j++){
9640 + possible_satisfier = possible_satisfiers[j];
9641 + if (!possible_satisfier)
9642 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9643 + if (!possible_satisfier->pkg)
9644 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9645 + test_vec = possible_satisfier->pkg->pkgs;
9646 + if (test_vec) {
9647 + /* pkg_vec found, it is an actual package conflict
9648 + * cruise this possiblity's pkg_vec looking for an installed version */
9649 + pkg_scouts = test_vec->pkgs;
9650 + for(k = 0; k < test_vec->len; k++){
9651 + pkg_scout = pkg_scouts[k];
9652 + if (!pkg_scout) {
9653 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9654 + continue;
9655 + }
9656 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9657 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9658 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9659 + pkg_vec_insert(installed_conflicts, pkg_scout);
9660 + }
9661 + }
9662 + }
9663 + }
9664 + }
9665 + conflicts++;
9666 + }
9667 +
9668 + if (installed_conflicts->len)
9669 + return installed_conflicts;
9670 + pkg_vec_free(installed_conflicts);
9671 + return (pkg_vec_t *)NULL;
9672 +}
9673 +
9674 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9675 +{
9676 + pkg_t * temp;
9677 + int comparison;
9678 +
9679 + if(depends->constraint == NONE)
9680 + return 1;
9681 +
9682 + temp = pkg_new();
9683 +
9684 + parseVersion(temp, depends->version);
9685 +
9686 + comparison = pkg_compare_versions(pkg, temp);
9687 +
9688 + free(temp);
9689 +
9690 + if((depends->constraint == EARLIER) &&
9691 + (comparison < 0))
9692 + return 1;
9693 + else if((depends->constraint == LATER) &&
9694 + (comparison > 0))
9695 + return 1;
9696 + else if(comparison == 0)
9697 + return 1;
9698 + else if((depends->constraint == LATER_EQUAL) &&
9699 + (comparison >= 0))
9700 + return 1;
9701 + else if((depends->constraint == EARLIER_EQUAL) &&
9702 + (comparison <= 0))
9703 + return 1;
9704 +
9705 + return 0;
9706 +}
9707 +
9708 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9709 +{
9710 + abstract_pkg_t *apkg = depend->pkg;
9711 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9712 + int n_providers = provider_apkgs->len;
9713 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9714 + pkg_vec_t *pkg_vec;
9715 + int n_pkgs ;
9716 + int i;
9717 + int j;
9718 +
9719 + for (i = 0; i < n_providers; i++) {
9720 + abstract_pkg_t *papkg = apkgs[i];
9721 + pkg_vec = papkg->pkgs;
9722 + if (pkg_vec) {
9723 + n_pkgs = pkg_vec->len;
9724 + for (j = 0; j < n_pkgs; j++) {
9725 + pkg_t *pkg = pkg_vec->pkgs[j];
9726 + if (version_constraints_satisfied(depend, pkg)) {
9727 + return 1;
9728 + }
9729 + }
9730 + }
9731 + }
9732 + return 0;
9733 +}
9734 +
9735 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9736 +{
9737 + abstract_pkg_t *apkg = depend->pkg;
9738 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9739 + int n_providers = provider_apkgs->len;
9740 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9741 + int i;
9742 + int n_pkgs;
9743 + int j;
9744 +
9745 + for (i = 0; i < n_providers; i++) {
9746 + abstract_pkg_t *papkg = apkgs[i];
9747 + pkg_vec_t *pkg_vec = papkg->pkgs;
9748 + if (pkg_vec) {
9749 + n_pkgs = pkg_vec->len;
9750 + for (j = 0; j < n_pkgs; j++) {
9751 + pkg_t *pkg = pkg_vec->pkgs[j];
9752 + if (version_constraints_satisfied(depend, pkg)) {
9753 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9754 + return 1;
9755 + }
9756 + }
9757 + }
9758 + }
9759 + return 0;
9760 +}
9761 +
9762 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9763 +{
9764 + register int i;
9765 + pkg_t ** pkgs = vec->pkgs;
9766 +
9767 + for(i = 0; i < vec->len; i++)
9768 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9769 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9770 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9771 + return 1;
9772 + return 0;
9773 +}
9774 +
9775 +
9776 +#ifdef DeadCode
9777 +/**
9778 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9779 + * the same abstract package and 0 otherwise.
9780 + */
9781 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9782 +{
9783 + abstract_pkg_t **provides = pkg->provides;
9784 + int provides_count = pkg->provides_count;
9785 + abstract_pkg_t **replacee_provides = replacee->provides;
9786 + int replacee_provides_count = replacee->provides_count;
9787 + int i, j;
9788 + for (i = 0; i < provides_count; i++) {
9789 + abstract_pkg_t *apkg = provides[i];
9790 + for (j = 0; j < replacee_provides_count; j++) {
9791 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9792 + if (apkg == replacee_apkg)
9793 + return 1;
9794 + }
9795 + }
9796 + return 0;
9797 +}
9798 +#endif
9799 +
9800 +/**
9801 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9802 + * and 0 otherwise.
9803 + */
9804 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9805 +{
9806 + abstract_pkg_t **provides = pkg->provides;
9807 + int provides_count = pkg->provides_count;
9808 + int i;
9809 + for (i = 0; i < provides_count; i++) {
9810 + if (provides[i] == providee)
9811 + return 1;
9812 + }
9813 + return 0;
9814 +}
9815 +
9816 +/**
9817 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9818 + * otherwise.
9819 + */
9820 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9821 +{
9822 + abstract_pkg_t **replaces = pkg->replaces;
9823 + int replaces_count = pkg->replaces_count;
9824 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9825 + int replacee_provides_count = pkg->provides_count; */
9826 + int i, j;
9827 + for (i = 0; i < replaces_count; i++) {
9828 + abstract_pkg_t *abstract_replacee = replaces[i];
9829 + for (j = 0; j < replaces_count; j++) {
9830 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9831 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9832 + if (replacee->provides[j] == abstract_replacee)
9833 + return 1;
9834 + }
9835 + }
9836 + return 0;
9837 +}
9838 +
9839 +
9840 +/**
9841 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9842 + * otherwise.
9843 + */
9844 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9845 +{
9846 + compound_depend_t *conflicts = pkg->conflicts;
9847 + int conflicts_count = pkg->conflicts_count;
9848 + int i, j;
9849 + for (i = 0; i < conflicts_count; i++) {
9850 + int possibility_count = conflicts[i].possibility_count;
9851 + struct depend **possibilities = conflicts[i].possibilities;
9852 + for (j = 0; j < possibility_count; j++) {
9853 + if (possibilities[j]->pkg == conflictee) {
9854 + return 1;
9855 + }
9856 + }
9857 + }
9858 + return 0;
9859 +}
9860 +
9861 +/**
9862 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9863 + * conflictee's provides and 0 otherwise.
9864 + */
9865 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9866 +{
9867 + compound_depend_t *conflicts = pkg->conflicts;
9868 + int conflicts_count = pkg->conflicts_count;
9869 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9870 + int conflictee_provides_count = conflictee->provides_count;
9871 + int i, j, k;
9872 + int possibility_count;
9873 + struct depend **possibilities;
9874 + abstract_pkg_t *possibility ;
9875 +
9876 + for (i = 0; i < conflicts_count; i++) {
9877 + possibility_count = conflicts[i].possibility_count;
9878 + possibilities = conflicts[i].possibilities;
9879 + for (j = 0; j < possibility_count; j++) {
9880 + possibility = possibilities[j]->pkg;
9881 + for (k = 0; k < conflictee_provides_count; k++) {
9882 + if (possibility == conflictee_provides[k]) {
9883 + return 1;
9884 + }
9885 + }
9886 + }
9887 + }
9888 + return 0;
9889 +}
9890 +
9891 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9892 +{
9893 + int oldlen = 0, newlen = 0;
9894 + char ** result;
9895 + register int i, j;
9896 +
9897 + if(!newstuff)
9898 + return oldstuff;
9899 +
9900 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9901 + while(newstuff && newstuff[newlen]) newlen++;
9902 +
9903 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9904 + if (result == NULL) {
9905 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9906 + return NULL;
9907 + }
9908 +
9909 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9910 + *(result + i) = *(newstuff + j);
9911 +
9912 + *(result + i) = NULL;
9913 +
9914 + return result;
9915 +}
9916 +
9917 +/*
9918 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9919 + * this is null terminated, no count is carried around
9920 + */
9921 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9922 +{
9923 + int count;
9924 + char ** resized;
9925 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9926 +
9927 + count = 0;
9928 + while(the_lost && the_lost[count]) count++;
9929 +
9930 + count++; /* need one to hold the null */
9931 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9932 + if (resized == NULL) {
9933 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9934 + return NULL;
9935 + }
9936 + resized[count - 1] = strdup(depend_str);
9937 + resized[count] = NULL;
9938 +
9939 + return resized;
9940 +}
9941 +
9942 +void printDepends(pkg_t * pkg)
9943 +{
9944 + register int i, j;
9945 + compound_depend_t * depend;
9946 + int count;
9947 +
9948 + count = pkg->pre_depends_count + pkg->depends_count;
9949 +
9950 + depend = pkg->depends;
9951 + if(!depend){
9952 + fprintf(stderr, "Depends pointer is NULL\n");
9953 + return;
9954 + }
9955 + for(i = 0; i < count; i++){
9956 + fprintf(stderr, "%s has %d possibilities:\n",
9957 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9958 + depend->possibility_count);
9959 + for(j = 0; j < depend->possibility_count; j++)
9960 + fprintf(stderr, "\t%s version %s (%d)\n",
9961 + depend->possibilities[j]->pkg->name,
9962 + depend->possibilities[j]->version,
9963 + depend->possibilities[j]->constraint);
9964 + depend++;
9965 + }
9966 +}
9967 +
9968 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9969 +{
9970 + register int i, j;
9971 +
9972 + /* every pkg provides itself */
9973 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9974 +
9975 + if (!pkg->provides_count)
9976 + return 0;
9977 +
9978 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9979 + if (pkg->provides == NULL) {
9980 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9981 + return -1 ;
9982 + }
9983 + pkg->provides[0] = ab_pkg;
9984 +
9985 + // if (strcmp(ab_pkg->name, pkg->name))
9986 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9987 +
9988 + for(i = 0; i < pkg->provides_count; i++){
9989 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9990 +
9991 + pkg->provides[i+1] = provided_abpkg;
9992 +
9993 + j = 0;
9994 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9995 + }
9996 + return 0;
9997 +}
9998 +
9999 +/* Abhaya: added conflicts support */
10000 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10001 +{
10002 + register int i;
10003 + compound_depend_t * conflicts;
10004 +
10005 + if (!pkg->conflicts_count)
10006 + return 0;
10007 +
10008 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10009 + pkg->conflicts_count);
10010 + if (conflicts == NULL) {
10011 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10012 + return -1;
10013 + }
10014 + for (i = 0; i < pkg->conflicts_count; i++) {
10015 + conflicts->type = CONFLICTS;
10016 + parseDepends(conflicts, hash,
10017 + pkg->conflicts_str[i]);
10018 +#if 0
10019 + for (j = 0; j < conflicts->possibility_count; j++) {
10020 + depend_t *possibility = conflicts->possibilities[j];
10021 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10022 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10023 + }
10024 +#endif
10025 + conflicts++;
10026 + }
10027 + return 0;
10028 +}
10029 +
10030 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10031 +{
10032 + register int i, j;
10033 +
10034 + if (!pkg->replaces_count)
10035 + return 0;
10036 +
10037 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10038 + if (pkg->replaces == NULL) {
10039 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10040 + return -1;
10041 + }
10042 +
10043 + // if (strcmp(ab_pkg->name, pkg->name))
10044 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10045 +
10046 + for(i = 0; i < pkg->replaces_count; i++){
10047 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10048 +
10049 + pkg->replaces[i] = old_abpkg;
10050 +
10051 + j = 0;
10052 + if (!old_abpkg->replaced_by)
10053 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10054 + if ( old_abpkg->replaced_by == NULL ){
10055 + return -1;
10056 + }
10057 + /* if a package pkg both replaces and conflicts old_abpkg,
10058 + * then add it to the replaced_by vector so that old_abpkg
10059 + * will be upgraded to ab_pkg automatically */
10060 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10061 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10062 + }
10063 + return 0;
10064 +}
10065 +
10066 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10067 +{
10068 + int count;
10069 + register int i;
10070 + compound_depend_t * depends;
10071 +
10072 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10073 + return 0;
10074 +
10075 + if (0 && pkg->pre_depends_count)
10076 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10077 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10078 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10079 + if (depends == NULL) {
10080 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10081 + return -1;
10082 + }
10083 +
10084 +
10085 + for(i = 0; i < pkg->pre_depends_count; i++){
10086 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10087 + if (0 && pkg->pre_depends_count)
10088 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10089 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10090 + depends->type = PREDEPEND;
10091 + depends++;
10092 + }
10093 +
10094 + for(i = 0; i < pkg->recommends_count; i++){
10095 + parseDepends(depends, hash, pkg->recommends_str[i]);
10096 + if (0 && pkg->recommends_count)
10097 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10098 + pkg->recommends_str[i], depends, depends->possibility_count);
10099 + depends->type = RECOMMEND;
10100 + depends++;
10101 + }
10102 +
10103 + for(i = 0; i < pkg->suggests_count; i++){
10104 + parseDepends(depends, hash, pkg->suggests_str[i]);
10105 + if (0 && pkg->suggests_count)
10106 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10107 + pkg->suggests_str[i], depends, depends->possibility_count);
10108 + depends->type = SUGGEST;
10109 + depends++;
10110 + }
10111 +
10112 + for(i = 0; i < pkg->depends_count; i++){
10113 + parseDepends(depends, hash, pkg->depends_str[i]);
10114 + if (0 && pkg->depends_count)
10115 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10116 + pkg->depends_str[i], depends, depends->possibility_count);
10117 + depends++;
10118 + }
10119 + return 0;
10120 +}
10121 +
10122 +/*
10123 + * pkg_depend_string: returns the depends string specified by index.
10124 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10125 + * [0,npredepends) -> returns pre_depends_str[index]
10126 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10127 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10128 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10129 + */
10130 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10131 +{
10132 + if (pkg_index < pkg->pre_depends_count) {
10133 + return pkg->pre_depends_str[pkg_index];
10134 + }
10135 + pkg_index -= pkg->pre_depends_count;
10136 +
10137 + if (pkg_index < pkg->recommends_count) {
10138 + return pkg->recommends_str[pkg_index];
10139 + }
10140 + pkg_index -= pkg->recommends_count;
10141 +
10142 + if (pkg_index < pkg->suggests_count) {
10143 + return pkg->suggests_str[pkg_index];
10144 + }
10145 + pkg_index -= pkg->suggests_count;
10146 +
10147 + if (pkg_index < pkg->depends_count) {
10148 + return pkg->depends_str[pkg_index];
10149 + }
10150 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10151 + return NULL;
10152 +}
10153 +
10154 +void freeDepends(pkg_t *pkg)
10155 +{
10156 + int i;
10157 +
10158 + if (pkg == NULL || pkg->depends == NULL) {
10159 + return;
10160 + }
10161 +
10162 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10163 + for (i=0; i < pkg->depends->possibility_count; i++) {
10164 + depend_deinit(pkg->depends->possibilities[i]);
10165 + }
10166 + free(pkg->depends->possibilities);
10167 + free(pkg->depends);
10168 + pkg->depends = NULL;
10169 +}
10170 +
10171 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10172 +{
10173 + compound_depend_t * depends;
10174 + int count, othercount;
10175 + register int i, j;
10176 + abstract_pkg_t * ab_depend;
10177 + abstract_pkg_t ** temp;
10178 +
10179 + count = pkg->pre_depends_count + pkg->depends_count;
10180 + depends = pkg->depends;
10181 +
10182 + if (0 && pkg->pre_depends_count)
10183 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10184 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10185 + for (i = 0; i < count; i++) {
10186 + if (0 && pkg->pre_depends_count)
10187 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10188 + for (j = 0; j < depends->possibility_count; j++){
10189 + ab_depend = depends->possibilities[j]->pkg;
10190 + if(!ab_depend->depended_upon_by)
10191 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10192 +
10193 + temp = ab_depend->depended_upon_by;
10194 + othercount = 1;
10195 + while(*temp){
10196 + temp++;
10197 + othercount++;
10198 + }
10199 + *temp = ab_pkg;
10200 +
10201 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10202 + (othercount + 1) * sizeof(abstract_pkg_t *));
10203 + /* the array may have moved */
10204 + temp = ab_depend->depended_upon_by + othercount;
10205 + *temp = NULL;
10206 + }
10207 + depends++;
10208 + }
10209 +}
10210 +
10211 +static depend_t * depend_init(void)
10212 +{
10213 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10214 + if ( d==NULL ){
10215 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10216 + return NULL;
10217 + }
10218 + d->constraint = NONE;
10219 + d->version = NULL;
10220 + d->pkg = NULL;
10221 +
10222 + return d;
10223 +}
10224 +
10225 +static void depend_deinit(depend_t *d)
10226 +{
10227 + free(d);
10228 +}
10229 +
10230 +static int parseDepends(compound_depend_t *compound_depend,
10231 + hash_table_t * hash, char * depend_str)
10232 +{
10233 + char * pkg_name, buffer[2048];
10234 + int num_of_ors = 0;
10235 + register int i;
10236 + register char * src, * dest;
10237 + depend_t ** possibilities;
10238 +
10239 + /* first count the number of ored possibilities for satisfying dependency */
10240 + src = depend_str;
10241 + while(*src)
10242 + if(*src++ == '|')
10243 + num_of_ors++;
10244 +
10245 + compound_depend->type = DEPEND;
10246 +
10247 + compound_depend->possibility_count = num_of_ors + 1;
10248 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10249 + if (!possibilities)
10250 + return -ENOMEM;
10251 + compound_depend->possibilities = possibilities;
10252 +
10253 + src = depend_str;
10254 + for(i = 0; i < num_of_ors + 1; i++){
10255 + possibilities[i] = depend_init();
10256 + if (!possibilities[i])
10257 + return -ENOMEM;
10258 + /* gobble up just the name first */
10259 + dest = buffer;
10260 + while(*src &&
10261 + !isspace(*src) &&
10262 + (*src != '(') &&
10263 + (*src != '*') &&
10264 + (*src != '|'))
10265 + *dest++ = *src++;
10266 + *dest = '\0';
10267 + pkg_name = trim_alloc(buffer);
10268 + if (pkg_name == NULL )
10269 + return -ENOMEM;
10270 +
10271 + /* now look at possible version info */
10272 +
10273 + /* skip to next chars */
10274 + if(isspace(*src))
10275 + while(*src && isspace(*src)) src++;
10276 +
10277 + /* extract constraint and version */
10278 + if(*src == '('){
10279 + src++;
10280 + if(!strncmp(src, "<<", 2)){
10281 + possibilities[i]->constraint = EARLIER;
10282 + src += 2;
10283 + }
10284 + else if(!strncmp(src, "<=", 2)){
10285 + possibilities[i]->constraint = EARLIER_EQUAL;
10286 + src += 2;
10287 + }
10288 + else if(!strncmp(src, ">=", 2)){
10289 + possibilities[i]->constraint = LATER_EQUAL;
10290 + src += 2;
10291 + }
10292 + else if(!strncmp(src, ">>", 2)){
10293 + possibilities[i]->constraint = LATER;
10294 + src += 2;
10295 + }
10296 + else if(!strncmp(src, "=", 1)){
10297 + possibilities[i]->constraint = EQUAL;
10298 + src++;
10299 + }
10300 + /* should these be here to support deprecated designations; dpkg does */
10301 + else if(!strncmp(src, "<", 1)){
10302 + possibilities[i]->constraint = EARLIER_EQUAL;
10303 + src++;
10304 + }
10305 + else if(!strncmp(src, ">", 1)){
10306 + possibilities[i]->constraint = LATER_EQUAL;
10307 + src++;
10308 + }
10309 +
10310 + /* now we have any constraint, pass space to version string */
10311 + while(isspace(*src)) src++;
10312 +
10313 + /* this would be the version string */
10314 + dest = buffer;
10315 + while(*src && *src != ')')
10316 + *dest++ = *src++;
10317 + *dest = '\0';
10318 +
10319 + possibilities[i]->version = trim_alloc(buffer);
10320 + /* fprintf(stderr, "let's print the depends version string:");
10321 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10322 + if (possibilities[i]->version == NULL )
10323 + return -ENOMEM;
10324 +
10325 +
10326 + }
10327 + /* hook up the dependency to its abstract pkg */
10328 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10329 +
10330 + free(pkg_name);
10331 +
10332 + /* now get past the ) and any possible | chars */
10333 + while(*src &&
10334 + (isspace(*src) ||
10335 + (*src == ')') ||
10336 + (*src == '|')))
10337 + src++;
10338 + if (*src == '*')
10339 + {
10340 + compound_depend->type = GREEDY_DEPEND;
10341 + src++;
10342 + }
10343 + }
10344 +
10345 + return 0;
10346 +}
10347 Index: busybox-1.8.1/archival/libipkg/pkg_depends.h
10348 ===================================================================
10349 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10350 +++ busybox-1.8.1/archival/libipkg/pkg_depends.h 2007-11-10 17:40:53.376765566 +0100
10351 @@ -0,0 +1,105 @@
10352 +/* pkg_depends.h - the itsy package management system
10353 +
10354 + Steven M. Ayer
10355 +
10356 + Copyright (C) 2002 Compaq Computer Corporation
10357 +
10358 + This program is free software; you can redistribute it and/or
10359 + modify it under the terms of the GNU General Public License as
10360 + published by the Free Software Foundation; either version 2, or (at
10361 + your option) any later version.
10362 +
10363 + This program is distributed in the hope that it will be useful, but
10364 + WITHOUT ANY WARRANTY; without even the implied warranty of
10365 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10366 + General Public License for more details.
10367 +*/
10368 +
10369 +#ifndef PKG_DEPENDS_H
10370 +#define PKG_DEPENDS_H
10371 +
10372 +#include "pkg.h"
10373 +#include "pkg_hash.h"
10374 +
10375 +enum depend_type {
10376 + PREDEPEND,
10377 + DEPEND,
10378 + CONFLICTS,
10379 + GREEDY_DEPEND,
10380 + RECOMMEND,
10381 + SUGGEST
10382 +};
10383 +typedef enum depend_type depend_type_t;
10384 +
10385 +enum version_constraint {
10386 + NONE,
10387 + EARLIER,
10388 + EARLIER_EQUAL,
10389 + EQUAL,
10390 + LATER_EQUAL,
10391 + LATER
10392 +};
10393 +typedef enum version_constraint version_constraint_t;
10394 +
10395 +struct depend{
10396 + version_constraint_t constraint;
10397 + char * version;
10398 + abstract_pkg_t * pkg;
10399 +};
10400 +typedef struct depend depend_t;
10401 +
10402 +struct compound_depend{
10403 + depend_type_t type;
10404 + int possibility_count;
10405 + struct depend ** possibilities;
10406 +};
10407 +typedef struct compound_depend compound_depend_t;
10408 +
10409 +#include "hash_table.h"
10410 +
10411 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10412 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10413 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10414 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10415 +
10416 +/**
10417 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10418 + * the same abstract package and 0 otherwise.
10419 + */
10420 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10421 +
10422 +/**
10423 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10424 + * otherwise.
10425 + */
10426 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10427 +
10428 +/**
10429 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10430 + * otherwise.
10431 + */
10432 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10433 +
10434 +/**
10435 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10436 + * otherwise.
10437 + */
10438 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10439 +
10440 +/**
10441 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10442 + * otherwise.
10443 + */
10444 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10445 +
10446 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10447 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10448 +void freeDepends(pkg_t *pkg);
10449 +void printDepends(pkg_t * pkg);
10450 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10451 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10452 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10453 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10454 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10455 +
10456 +#endif
10457 Index: busybox-1.8.1/archival/libipkg/pkg_dest.c
10458 ===================================================================
10459 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10460 +++ busybox-1.8.1/archival/libipkg/pkg_dest.c 2007-11-10 17:40:53.376765566 +0100
10461 @@ -0,0 +1,92 @@
10462 +/* pkg_dest.c - the itsy package management system
10463 +
10464 + Carl D. Worth
10465 +
10466 + Copyright (C) 2001 University of Southern California
10467 +
10468 + This program is free software; you can redistribute it and/or
10469 + modify it under the terms of the GNU General Public License as
10470 + published by the Free Software Foundation; either version 2, or (at
10471 + your option) any later version.
10472 +
10473 + This program is distributed in the hope that it will be useful, but
10474 + WITHOUT ANY WARRANTY; without even the implied warranty of
10475 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10476 + General Public License for more details.
10477 +*/
10478 +
10479 +#include "ipkg.h"
10480 +
10481 +#include "pkg_dest.h"
10482 +#include "file_util.h"
10483 +#include "str_util.h"
10484 +#include "sprintf_alloc.h"
10485 +
10486 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10487 +{
10488 + dest->name = strdup(name);
10489 +
10490 + /* Guarantee that dest->root_dir ends with a '/' */
10491 + if (str_ends_with(root_dir, "/")) {
10492 + dest->root_dir = strdup(root_dir);
10493 + } else {
10494 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10495 + }
10496 + file_mkdir_hier(dest->root_dir, 0755);
10497 +
10498 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10499 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10500 + file_mkdir_hier(dest->ipkg_dir, 0755);
10501 +
10502 + if (str_starts_with (lists_dir, "/"))
10503 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10504 + else
10505 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10506 +
10507 + file_mkdir_hier(dest->lists_dir, 0755);
10508 +
10509 + sprintf_alloc(&dest->info_dir, "%s/%s",
10510 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10511 + file_mkdir_hier(dest->info_dir, 0755);
10512 +
10513 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10514 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10515 +
10516 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10517 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10518 +
10519 + dest->status_file = NULL;
10520 +
10521 + return 0;
10522 +}
10523 +
10524 +void pkg_dest_deinit(pkg_dest_t *dest)
10525 +{
10526 + free(dest->name);
10527 + dest->name = NULL;
10528 +
10529 + free(dest->root_dir);
10530 + dest->root_dir = NULL;
10531 +
10532 + free(dest->ipkg_dir);
10533 + dest->ipkg_dir = NULL;
10534 +
10535 + free(dest->lists_dir);
10536 + dest->lists_dir = NULL;
10537 +
10538 + free(dest->info_dir);
10539 + dest->info_dir = NULL;
10540 +
10541 + free(dest->status_file_name);
10542 + dest->status_file_name = NULL;
10543 +
10544 + free(dest->status_file_tmp_name);
10545 + dest->status_file_tmp_name = NULL;
10546 +
10547 + if (dest->status_file) {
10548 + fclose(dest->status_file);
10549 + }
10550 + dest->status_file = NULL;
10551 +
10552 + dest->root_dir = NULL;
10553 +}
10554 Index: busybox-1.8.1/archival/libipkg/pkg_dest.h
10555 ===================================================================
10556 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10557 +++ busybox-1.8.1/archival/libipkg/pkg_dest.h 2007-11-10 17:40:53.380765796 +0100
10558 @@ -0,0 +1,38 @@
10559 +/* pkg_dest.h - the itsy package management system
10560 +
10561 + Carl D. Worth
10562 +
10563 + Copyright (C) 2001 University of Southern California
10564 +
10565 + This program is free software; you can redistribute it and/or
10566 + modify it under the terms of the GNU General Public License as
10567 + published by the Free Software Foundation; either version 2, or (at
10568 + your option) any later version.
10569 +
10570 + This program is distributed in the hope that it will be useful, but
10571 + WITHOUT ANY WARRANTY; without even the implied warranty of
10572 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10573 + General Public License for more details.
10574 +*/
10575 +
10576 +#ifndef PKG_DEST_H
10577 +#define PKG_DEST_H
10578 +
10579 +typedef struct pkg_dest pkg_dest_t;
10580 +struct pkg_dest
10581 +{
10582 + char *name;
10583 + char *root_dir;
10584 + char *ipkg_dir;
10585 + char *lists_dir;
10586 + char *info_dir;
10587 + char *status_file_name;
10588 + char *status_file_tmp_name;
10589 + FILE *status_file;
10590 +};
10591 +
10592 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10593 +void pkg_dest_deinit(pkg_dest_t *dest);
10594 +
10595 +#endif
10596 +
10597 Index: busybox-1.8.1/archival/libipkg/pkg_dest_list.c
10598 ===================================================================
10599 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10600 +++ busybox-1.8.1/archival/libipkg/pkg_dest_list.c 2007-11-10 17:40:53.380765796 +0100
10601 @@ -0,0 +1,85 @@
10602 +/* pkg_dest_list.c - the itsy package management system
10603 +
10604 + Carl D. Worth
10605 +
10606 + Copyright (C) 2001 University of Southern California
10607 +
10608 + This program is free software; you can redistribute it and/or
10609 + modify it under the terms of the GNU General Public License as
10610 + published by the Free Software Foundation; either version 2, or (at
10611 + your option) any later version.
10612 +
10613 + This program is distributed in the hope that it will be useful, but
10614 + WITHOUT ANY WARRANTY; without even the implied warranty of
10615 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10616 + General Public License for more details.
10617 +*/
10618 +
10619 +#include "ipkg.h"
10620 +
10621 +#include "pkg_dest.h"
10622 +#include "void_list.h"
10623 +#include "pkg_dest_list.h"
10624 +
10625 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10626 +{
10627 + return void_list_elt_init((void_list_elt_t *) elt, data);
10628 +}
10629 +
10630 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10631 +{
10632 + void_list_elt_deinit((void_list_elt_t *) elt);
10633 +}
10634 +
10635 +int pkg_dest_list_init(pkg_dest_list_t *list)
10636 +{
10637 + return void_list_init((void_list_t *) list);
10638 +}
10639 +
10640 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10641 +{
10642 + pkg_dest_list_elt_t *iter;
10643 + pkg_dest_t *pkg_dest;
10644 +
10645 + for (iter = list->head; iter; iter = iter->next) {
10646 + pkg_dest = iter->data;
10647 + pkg_dest_deinit(pkg_dest);
10648 +
10649 + /* malloced in pkg_dest_list_append */
10650 + free(pkg_dest);
10651 + iter->data = NULL;
10652 + }
10653 + void_list_deinit((void_list_t *) list);
10654 +}
10655 +
10656 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10657 + const char *root_dir,const char *lists_dir)
10658 +{
10659 + int err;
10660 + pkg_dest_t *pkg_dest;
10661 +
10662 + /* freed in plg_dest_list_deinit */
10663 + pkg_dest = malloc(sizeof(pkg_dest_t));
10664 + if (pkg_dest == NULL) {
10665 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10666 + return NULL;
10667 + }
10668 +
10669 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10670 + err = void_list_append((void_list_t *) list, pkg_dest);
10671 + if (err) {
10672 + return NULL;
10673 + }
10674 +
10675 + return pkg_dest;
10676 +}
10677 +
10678 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10679 +{
10680 + return void_list_push((void_list_t *) list, data);
10681 +}
10682 +
10683 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10684 +{
10685 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10686 +}
10687 Index: busybox-1.8.1/archival/libipkg/pkg_dest_list.h
10688 ===================================================================
10689 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10690 +++ busybox-1.8.1/archival/libipkg/pkg_dest_list.h 2007-11-10 17:40:53.380765796 +0100
10691 @@ -0,0 +1,50 @@
10692 +/* pkg_dest_list.h - the itsy package management system
10693 +
10694 + Carl D. Worth
10695 +
10696 + Copyright (C) 2001 University of Southern California
10697 +
10698 + This program is free software; you can redistribute it and/or
10699 + modify it under the terms of the GNU General Public License as
10700 + published by the Free Software Foundation; either version 2, or (at
10701 + your option) any later version.
10702 +
10703 + This program is distributed in the hope that it will be useful, but
10704 + WITHOUT ANY WARRANTY; without even the implied warranty of
10705 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10706 + General Public License for more details.
10707 +*/
10708 +
10709 +#ifndef PKG_DEST_LIST_H
10710 +#define PKG_DEST_LIST_H
10711 +
10712 +#include "pkg_dest.h"
10713 +
10714 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10715 +struct pkg_dest_list_elt
10716 +{
10717 + pkg_dest_list_elt_t *next;
10718 + pkg_dest_t *data;
10719 +};
10720 +
10721 +typedef struct pkg_dest_list pkg_dest_list_t;
10722 +struct pkg_dest_list
10723 +{
10724 + pkg_dest_list_elt_t pre_head;
10725 + pkg_dest_list_elt_t *head;
10726 + pkg_dest_list_elt_t *tail;
10727 +};
10728 +
10729 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10730 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10731 +
10732 +int pkg_dest_list_init(pkg_dest_list_t *list);
10733 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10734 +
10735 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10736 + const char *root_dir,const char* lists_dir);
10737 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10738 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10739 +
10740 +#endif
10741 +
10742 Index: busybox-1.8.1/archival/libipkg/pkg_extract.c
10743 ===================================================================
10744 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10745 +++ busybox-1.8.1/archival/libipkg/pkg_extract.c 2007-11-10 17:40:53.380765796 +0100
10746 @@ -0,0 +1,224 @@
10747 +/* pkg_extract.c - the itsy package management system
10748 +
10749 + Carl D. Worth
10750 +
10751 + Copyright (C) 2001 University of Southern California
10752 +
10753 + This program is free software; you can redistribute it and/or
10754 + modify it under the terms of the GNU General Public License as
10755 + published by the Free Software Foundation; either version 2, or (at
10756 + your option) any later version.
10757 +
10758 + This program is distributed in the hope that it will be useful, but
10759 + WITHOUT ANY WARRANTY; without even the implied warranty of
10760 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10761 + General Public License for more details.
10762 +*/
10763 +
10764 +#include "ipkg.h"
10765 +#include <errno.h>
10766 +#include <fcntl.h>
10767 +#include <stdio.h>
10768 +
10769 +#include "pkg_extract.h"
10770 +
10771 +#include "libbb.h"
10772 +#include "file_util.h"
10773 +#include "sprintf_alloc.h"
10774 +#include "unarchive.h"
10775 +
10776 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10777 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10778 +#define IPKG_CONTROL_FILE "control"
10779 +
10780 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10781 +{
10782 + archive_handle_t *archive;
10783 + char *path;
10784 +
10785 + sprintf_alloc(&path, "%s/", dir);
10786 + archive = init_handle();
10787 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10788 + archive->filter = filter_accept_list;
10789 + llist_add_to(&(archive->accept), (char *)filename);
10790 + archive->buffer = path;
10791 + archive->action_data = data_extract_all_prefix;
10792 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10793 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10794 + close(archive->src_fd);
10795 + free(archive->accept);
10796 + free(archive);
10797 + free(path);
10798 +}
10799 +
10800 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10801 +{
10802 + unsigned int size = strlen(archive->file_header->name) + 2;
10803 +
10804 + if (archive->buffer == NULL) {
10805 + archive->buffer = xmalloc(size);
10806 + strcpy(archive->buffer, archive->file_header->name);
10807 + } else {
10808 + size += strlen(archive->buffer);
10809 + archive->buffer = xrealloc(archive->buffer, size);
10810 + strcat(archive->buffer, archive->file_header->name);
10811 + }
10812 + strcat(archive->buffer, "\n");
10813 + data_skip(archive);
10814 +}
10815 +
10816 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10817 +{
10818 + archive_handle_t *archive;
10819 + char *name;
10820 +
10821 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10822 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10823 + archive = init_handle();
10824 + archive->src_fd = xopen(name, O_RDONLY);
10825 + archive->filter = filter_accept_list;
10826 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10827 + archive->action_data = data_extract_to_buffer;
10828 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10829 + close(archive->src_fd);
10830 + fputs(archive->buffer, stream);
10831 + free(archive->buffer);
10832 + free(archive->accept);
10833 + free(archive);
10834 + free(name);
10835 +
10836 + return 0;
10837 +}
10838 +
10839 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10840 +{
10841 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10842 +}
10843 +
10844 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10845 +{
10846 + archive_handle_t *archive;
10847 + char *name;
10848 + char *path;
10849 +
10850 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10851 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10852 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10853 + archive = init_handle();
10854 + archive->src_fd = xopen(name, O_RDONLY);
10855 + archive->filter = filter_accept_all;
10856 + archive->buffer = path;
10857 + archive->action_data = data_extract_all_prefix;
10858 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10859 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10860 + close(archive->src_fd);
10861 + free(archive);
10862 + free(path);
10863 + free(name);
10864 +
10865 + return 0;
10866 +}
10867 +
10868 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10869 +{
10870 + archive_handle_t *archive;
10871 + char *name;
10872 + char *path;
10873 +
10874 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10875 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10876 + sprintf_alloc(&path, "%s/", dir);
10877 + archive = init_handle();
10878 + archive->src_fd = xopen(name, O_RDONLY);
10879 + archive->filter = filter_accept_all;
10880 + archive->buffer = path;
10881 + archive->action_data = data_extract_all_prefix;
10882 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10883 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10884 + close(archive->src_fd);
10885 + free(archive);
10886 + free(path);
10887 + free(name);
10888 +
10889 + return 0;
10890 +}
10891 +
10892 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10893 +{
10894 + int err=0;
10895 + char *line, *data_file;
10896 + FILE *file;
10897 + FILE *tmp;
10898 +
10899 + file = fopen(file_name, "w");
10900 + if (file == NULL) {
10901 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10902 + __FUNCTION__, file_name);
10903 + return EINVAL;
10904 + }
10905 +
10906 + tmp = tmpfile();
10907 + if (pkg->installed_files) {
10908 + str_list_elt_t *elt;
10909 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10910 + fprintf(file, "%s\n", elt->data);
10911 + }
10912 + } else {
10913 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10914 + if (err) {
10915 + fclose(file);
10916 + fclose(tmp);
10917 + return err;
10918 + }
10919 +
10920 + /* Fixup data file names by removing the initial '.' */
10921 + rewind(tmp);
10922 + while (1) {
10923 + line = file_read_line_alloc(tmp);
10924 + if (line == NULL) {
10925 + break;
10926 + }
10927 +
10928 + data_file = line;
10929 + if (*data_file == '.') {
10930 + data_file++;
10931 + }
10932 +
10933 + if (*data_file != '/') {
10934 + fputs("/", file);
10935 + }
10936 +
10937 + /* I have no idea why, but this is what dpkg does */
10938 + if (strcmp(data_file, "/\n") == 0) {
10939 + fputs("/.\n", file);
10940 + } else {
10941 + fputs(data_file, file);
10942 + }
10943 + }
10944 + }
10945 + fclose(tmp);
10946 + fclose(file);
10947 +
10948 + return err;
10949 +}
10950 +
10951 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10952 +{
10953 + archive_handle_t *archive;
10954 + char *name;
10955 +
10956 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10957 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10958 + archive = init_handle();
10959 + archive->src_fd = xopen(name, O_RDONLY);
10960 + archive->filter = filter_accept_all;
10961 + archive->action_data = data_extract_file_name_to_buffer;
10962 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10963 + close(archive->src_fd);
10964 + fputs(archive->buffer, file);
10965 + free(archive->buffer);
10966 + free(archive);
10967 + free(name);
10968 +
10969 + return 0;
10970 +}
10971 Index: busybox-1.8.1/archival/libipkg/pkg_extract.h
10972 ===================================================================
10973 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10974 +++ busybox-1.8.1/archival/libipkg/pkg_extract.h 2007-11-10 17:40:53.380765796 +0100
10975 @@ -0,0 +1,32 @@
10976 +/* pkg_extract.c - the itsy package management system
10977 +
10978 + Carl D. Worth
10979 +
10980 + Copyright (C) 2001 University of Southern California
10981 +
10982 + This program is free software; you can redistribute it and/or
10983 + modify it under the terms of the GNU General Public License as
10984 + published by the Free Software Foundation; either version 2, or (at
10985 + your option) any later version.
10986 +
10987 + This program is distributed in the hope that it will be useful, but
10988 + WITHOUT ANY WARRANTY; without even the implied warranty of
10989 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10990 + General Public License for more details.
10991 +*/
10992 +
10993 +#ifndef PKG_EXTRACT_H
10994 +#define PKG_EXTRACT_H
10995 +
10996 +#include "pkg.h"
10997 +
10998 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10999 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11000 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11001 + const char *dir,
11002 + const char *prefix);
11003 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11004 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11005 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11006 +
11007 +#endif
11008 Index: busybox-1.8.1/archival/libipkg/pkg.h
11009 ===================================================================
11010 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11011 +++ busybox-1.8.1/archival/libipkg/pkg.h 2007-11-10 17:40:53.384766022 +0100
11012 @@ -0,0 +1,229 @@
11013 +/* pkg.h - the itsy package management system
11014 +
11015 + Carl D. Worth
11016 +
11017 + Copyright (C) 2001 University of Southern California
11018 +
11019 + This program is free software; you can redistribute it and/or
11020 + modify it under the terms of the GNU General Public License as
11021 + published by the Free Software Foundation; either version 2, or (at
11022 + your option) any later version.
11023 +
11024 + This program is distributed in the hope that it will be useful, but
11025 + WITHOUT ANY WARRANTY; without even the implied warranty of
11026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11027 + General Public License for more details.
11028 +*/
11029 +
11030 +#ifndef PKG_H
11031 +#define PKG_H
11032 +
11033 +#include <sys/types.h>
11034 +#include <sys/stat.h>
11035 +#include <unistd.h>
11036 +
11037 +#include "pkg_vec.h"
11038 +#include "str_list.h"
11039 +#include "pkg_src.h"
11040 +#include "pkg_dest.h"
11041 +#include "ipkg_conf.h"
11042 +#include "conffile_list.h"
11043 +
11044 +struct ipkg_conf;
11045 +
11046 +/* I think "Size" is currently the shortest field name */
11047 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11048 +
11049 +enum pkg_state_want
11050 +{
11051 + SW_UNKNOWN = 1,
11052 + SW_INSTALL,
11053 + SW_DEINSTALL,
11054 + SW_PURGE,
11055 + SW_LAST_STATE_WANT
11056 +};
11057 +typedef enum pkg_state_want pkg_state_want_t;
11058 +
11059 +enum pkg_state_flag
11060 +{
11061 + SF_OK = 0,
11062 + SF_REINSTREQ = 1,
11063 + SF_HOLD = 2, /* do not upgrade version */
11064 + SF_REPLACE = 4, /* replace this package */
11065 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11066 + SF_PREFER = 16, /* prefer this version */
11067 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11068 + SF_MARKED = 64, /* temporary mark */
11069 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11070 + SF_USER = 256,
11071 + SF_LAST_STATE_FLAG
11072 +};
11073 +typedef enum pkg_state_flag pkg_state_flag_t;
11074 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11075 +
11076 +enum pkg_state_status
11077 +{
11078 + SS_NOT_INSTALLED = 1,
11079 + SS_UNPACKED,
11080 + SS_HALF_CONFIGURED,
11081 + SS_INSTALLED,
11082 + SS_HALF_INSTALLED,
11083 + SS_CONFIG_FILES,
11084 + SS_POST_INST_FAILED,
11085 + SS_REMOVAL_FAILED,
11086 + SS_LAST_STATE_STATUS
11087 +};
11088 +typedef enum pkg_state_status pkg_state_status_t;
11089 +
11090 +struct abstract_pkg{
11091 + char * name;
11092 + int dependencies_checked;
11093 + pkg_vec_t * pkgs;
11094 + pkg_state_status_t state_status;
11095 + pkg_state_flag_t state_flag;
11096 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11097 + abstract_pkg_vec_t * provided_by;
11098 + abstract_pkg_vec_t * replaced_by;
11099 +};
11100 +
11101 +#include "pkg_depends.h"
11102 +
11103 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11104 +
11105 + The 3 version fields should go into a single version struct. (This
11106 + is especially important since, currently, pkg->version can easily
11107 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11108 + distinct. This has been the source of multiple bugs.
11109 +
11110 + The 3 state fields could possibly also go into their own struct.
11111 +
11112 + All fields which deal with lists of packages, (Depends,
11113 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11114 + be handled by a single struct in pkg_t
11115 +
11116 + All string fields for which there is a small set of possible
11117 + values, (section, maintainer, architecture, maybe version?), that
11118 + are reused among different packages -- for all such packages we
11119 + should move from "char *"s to some atom datatype to share data
11120 + storage and use less memory. We might even do reference counting,
11121 + but probably not since most often we only create new pkg_t structs,
11122 + we don't often free them. */
11123 +struct pkg
11124 +{
11125 + char *name;
11126 + unsigned long epoch;
11127 + char *version;
11128 + char *revision;
11129 + char *familiar_revision;
11130 + pkg_src_t *src;
11131 + pkg_dest_t *dest;
11132 + char *architecture;
11133 + char *section;
11134 + char *maintainer;
11135 + char *description;
11136 + pkg_state_want_t state_want;
11137 + pkg_state_flag_t state_flag;
11138 + pkg_state_status_t state_status;
11139 + char **depends_str;
11140 + int depends_count;
11141 + char **pre_depends_str;
11142 + int pre_depends_count;
11143 + char **recommends_str;
11144 + int recommends_count;
11145 + char **suggests_str;
11146 + int suggests_count;
11147 + compound_depend_t * depends;
11148 +
11149 + /* Abhaya: new conflicts */
11150 + char **conflicts_str;
11151 + compound_depend_t * conflicts;
11152 + int conflicts_count;
11153 +
11154 + char **replaces_str;
11155 + int replaces_count;
11156 + abstract_pkg_t ** replaces;
11157 +
11158 + char **provides_str;
11159 + int provides_count;
11160 + abstract_pkg_t ** provides;
11161 +
11162 + abstract_pkg_t *parent;
11163 +
11164 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11165 +
11166 + char *filename;
11167 + char *local_filename;
11168 + char *url;
11169 + char *tmp_unpack_dir;
11170 + char *md5sum;
11171 + char *size;
11172 + char *installed_size;
11173 + char *priority;
11174 + char *source;
11175 + conffile_list_t conffiles;
11176 + time_t installed_time;
11177 + /* As pointer for lazy evaluation */
11178 + str_list_t *installed_files;
11179 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11180 + mechanism to avoid the problem here, (which is that the
11181 + installed_files list was being freed from an inner loop while
11182 + still being used within an outer loop. */
11183 + int installed_files_ref_cnt;
11184 + int essential;
11185 + int arch_priority;
11186 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11187 + int provided_by_hand;
11188 +};
11189 +
11190 +pkg_t *pkg_new(void);
11191 +int pkg_init(pkg_t *pkg);
11192 +void pkg_deinit(pkg_t *pkg);
11193 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11194 +abstract_pkg_t *abstract_pkg_new(void);
11195 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11196 +
11197 +/*
11198 + * merges fields from newpkg into oldpkg.
11199 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11200 + */
11201 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11202 +
11203 +char *pkg_version_str_alloc(pkg_t *pkg);
11204 +
11205 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11206 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11207 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11208 +
11209 +char * pkg_formatted_info(pkg_t *pkg );
11210 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11211 +
11212 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11213 +
11214 +void pkg_print_info(pkg_t *pkg, FILE *file);
11215 +void pkg_print_status(pkg_t * pkg, FILE * file);
11216 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11217 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11218 +int pkg_free_installed_files(pkg_t *pkg);
11219 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11220 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11221 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11222 + const char *script, const char *args);
11223 +
11224 +/* enum mappings */
11225 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11226 +pkg_state_want_t pkg_state_want_from_str(char *str);
11227 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11228 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11229 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11230 +pkg_state_status_t pkg_state_status_from_str(char *str);
11231 +
11232 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11233 +
11234 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11235 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11236 +int pkg_free_installed_files(pkg_t *pkg);
11237 +
11238 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11239 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11240 +
11241 +#endif
11242 Index: busybox-1.8.1/archival/libipkg/pkg_hash.c
11243 ===================================================================
11244 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11245 +++ busybox-1.8.1/archival/libipkg/pkg_hash.c 2007-11-10 17:40:53.388766251 +0100
11246 @@ -0,0 +1,616 @@
11247 +/* ipkg_hash.c - the itsy package management system
11248 +
11249 + Steven M. Ayer
11250 +
11251 + Copyright (C) 2002 Compaq Computer Corporation
11252 +
11253 + This program is free software; you can redistribute it and/or
11254 + modify it under the terms of the GNU General Public License as
11255 + published by the Free Software Foundation; either version 2, or (at
11256 + your option) any later version.
11257 +
11258 + This program is distributed in the hope that it will be useful, but
11259 + WITHOUT ANY WARRANTY; without even the implied warranty of
11260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11261 + General Public License for more details.
11262 +*/
11263 +
11264 +#include "ipkg.h"
11265 +#include <errno.h>
11266 +#include <ctype.h>
11267 +#include <stdlib.h>
11268 +#include <string.h>
11269 +
11270 +#include "hash_table.h"
11271 +#include "pkg.h"
11272 +#include "ipkg_message.h"
11273 +#include "pkg_vec.h"
11274 +#include "pkg_hash.h"
11275 +#include "pkg_parse.h"
11276 +#include "ipkg_utils.h"
11277 +
11278 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11279 +
11280 +/*
11281 + * this will talk to both feeds-lists files and installed status files
11282 + * example api:
11283 + *
11284 + * hash_table_t hash;
11285 + * pkg_hash_init(name, &hash, 1000);
11286 + * pkg_hash_add_from_file(<feed filename>);
11287 + *
11288 + * the query function is just there as a shell to prove to me that this
11289 + * sort of works, but isn't far from doing something useful
11290 + *
11291 + * -sma, 12/21/01
11292 + * modified: CDW 3 Jan. 2002
11293 + */
11294 +
11295 +
11296 +\f
11297 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11298 +{
11299 + return hash_table_init(name, hash, len);
11300 +}
11301 +
11302 +void pkg_hash_deinit(hash_table_t *hash)
11303 +{
11304 + hash_table_deinit(hash);
11305 +}
11306 +
11307 +
11308 +/* Find the default arch for a given package status file if none is given. */
11309 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11310 +{
11311 + nv_pair_list_elt_t *l;
11312 + char *def_arch = HOST_CPU_STR; /* Default arch */
11313 + int def_prio = 0; /* Other archs override this */
11314 +
11315 + l = conf->arch_list.head;
11316 +
11317 + while (l) {
11318 + nv_pair_t *nv = l->data;
11319 + int priority = strtol(nv->value, NULL, 0);
11320 +
11321 + /* Check if this arch has higher priority, and is valid */
11322 + if ((priority > def_prio) &&
11323 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11324 + /* Our new default */
11325 + def_prio = priority;
11326 + def_arch = nv->name;
11327 + }
11328 + l = l->next;
11329 + }
11330 +
11331 + return strdup(def_arch);
11332 +}
11333 +
11334 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11335 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11336 +{
11337 + hash_table_t *hash = &conf->pkg_hash;
11338 + char **raw;
11339 + char **raw_start;
11340 + pkg_t *pkg;
11341 +
11342 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11343 + if (!raw)
11344 + return -ENOMEM;
11345 +
11346 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11347 + pkg = pkg_new();
11348 + if (!pkg)
11349 + return -ENOMEM;
11350 +
11351 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11352 + if (!pkg->architecture) {
11353 + char *version_str = pkg_version_str_alloc(pkg);
11354 + pkg->architecture = pkg_get_default_arch(conf);
11355 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11356 + pkg->name, version_str, pkg->architecture);
11357 + free(version_str);
11358 + }
11359 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11360 + } else {
11361 + free(pkg);
11362 + }
11363 + }
11364 +
11365 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11366 + memory after read_raw_pkgs_from_file */
11367 + raw = raw_start;
11368 + while (*raw) {
11369 + free(*raw++);
11370 + }
11371 + free(raw_start);
11372 + return 0;
11373 +}
11374 +
11375 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11376 +{
11377 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11378 +}
11379 +
11380 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11381 +{
11382 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11383 + if (apkg)
11384 + return NULL;
11385 + return apkg->provided_by;
11386 +}
11387 +
11388 +
11389 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11390 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11391 +{
11392 + int i, j;
11393 + int nprovides = 0;
11394 + int nmatching = 0;
11395 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11396 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11397 + abstract_pkg_vec_t *provided_apkg_vec;
11398 + abstract_pkg_t **provided_apkgs;
11399 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11400 + pkg_t *latest_installed_parent = NULL;
11401 + pkg_t *latest_matching = NULL;
11402 + pkg_t *held_pkg = NULL;
11403 + pkg_t *good_pkg_by_name = NULL;
11404 +
11405 + if (matching_apkgs == NULL || providers == NULL ||
11406 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11407 + return NULL;
11408 +
11409 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11410 +
11411 + provided_apkg_vec = apkg->provided_by;
11412 + nprovides = provided_apkg_vec->len;
11413 + provided_apkgs = provided_apkg_vec->pkgs;
11414 + if (nprovides > 1)
11415 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11416 +
11417 + /* accumulate all the providers */
11418 + for (i = 0; i < nprovides; i++) {
11419 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11420 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11421 + abstract_pkg_vec_insert(providers, provider_apkg);
11422 + }
11423 + nprovides = providers->len;
11424 +
11425 + for (i = 0; i < nprovides; i++) {
11426 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11427 + abstract_pkg_t *replacement_apkg = NULL;
11428 + pkg_vec_t *vec;
11429 +
11430 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11431 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11432 + if (provider_apkg->replaced_by->len > 1) {
11433 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11434 + provider_apkg->name, replacement_apkg->name);
11435 + }
11436 + }
11437 +
11438 + if (replacement_apkg)
11439 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11440 + replacement_apkg->name, provider_apkg->name);
11441 +
11442 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11443 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11444 + continue;
11445 + else
11446 + provider_apkg = replacement_apkg;
11447 + }
11448 +
11449 + if (!(vec = provider_apkg->pkgs)) {
11450 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11451 + continue;
11452 + }
11453 +
11454 +
11455 + /* now check for supported architecture */
11456 + {
11457 + int max_count = 0;
11458 +
11459 + /* count packages matching max arch priority and keep track of last one */
11460 + for (j = 0; j < vec->len; j++) {
11461 + pkg_t *maybe = vec->pkgs[j];
11462 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11463 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11464 + if (maybe->arch_priority > 0) {
11465 + max_count++;
11466 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11467 + pkg_vec_insert(matching_pkgs, maybe);
11468 + }
11469 + }
11470 + }
11471 + }
11472 +
11473 + if (matching_pkgs->len > 1)
11474 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11475 + if (matching_apkgs->len > 1)
11476 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11477 +
11478 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11479 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11480 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11481 + Until now I always got the latest, but that breaks the downgrade option.
11482 + If I stop at the first one, I would probably miss the new ones
11483 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11484 + or from a Packages feed.
11485 + 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*/
11486 +/*Pigi*/
11487 +
11488 + for (i = 0; i < matching_pkgs->len; i++) {
11489 + pkg_t *matching = matching_pkgs->pkgs[i];
11490 + if (constraint_fcn(matching, cdata)) { /* We found it */
11491 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11492 + good_pkg_by_name = matching;
11493 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11494 + break;
11495 + }
11496 + }
11497 +
11498 +
11499 + for (i = 0; i < matching_pkgs->len; i++) {
11500 + pkg_t *matching = matching_pkgs->pkgs[i];
11501 + latest_matching = matching;
11502 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11503 + latest_installed_parent = matching;
11504 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11505 + if (held_pkg)
11506 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11507 + held_pkg->name, matching->name);
11508 + held_pkg = matching;
11509 + }
11510 + }
11511 +
11512 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11513 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11514 + apkg->name, matching_apkgs->len);
11515 + for (i = 0; i < matching_apkgs->len; i++) {
11516 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11517 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11518 + }
11519 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11520 + }
11521 +
11522 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11523 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11524 + __FUNCTION__, apkg->name, matching_pkgs->len);
11525 + for (i = 0; i < matching_pkgs->len; i++) {
11526 + pkg_t *matching = matching_pkgs->pkgs[i];
11527 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11528 + matching->name, matching->version, matching->architecture);
11529 + }
11530 + }
11531 +
11532 + nmatching = matching_apkgs->len;
11533 +
11534 + pkg_vec_free(matching_pkgs);
11535 + abstract_pkg_vec_free(matching_apkgs);
11536 + abstract_pkg_vec_free(providers);
11537 +
11538 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11539 + return good_pkg_by_name;
11540 + }
11541 + if (held_pkg) {
11542 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11543 + return held_pkg;
11544 + }
11545 + if (latest_installed_parent) {
11546 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11547 + return latest_installed_parent;
11548 + }
11549 + if (nmatching > 1) {
11550 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11551 + return NULL;
11552 + }
11553 + if (latest_matching) {
11554 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11555 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11556 + return latest_matching;
11557 + }
11558 + return NULL;
11559 +}
11560 +
11561 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11562 +{
11563 + const char *name = (const char *)cdata;
11564 + if (strcmp(pkg->name, name) == 0)
11565 + return 1;
11566 + else
11567 + return 0;
11568 +}
11569 +
11570 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11571 +{
11572 + hash_table_t *hash = &conf->pkg_hash;
11573 + abstract_pkg_t *apkg = NULL;
11574 +
11575 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11576 + return NULL;
11577 +
11578 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11579 +}
11580 +
11581 +
11582 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11583 + const char *pkg_name,
11584 + const char * version)
11585 +{
11586 + pkg_vec_t * vec;
11587 + register int i;
11588 + char *version_str = NULL;
11589 +
11590 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11591 + return NULL;
11592 +
11593 + for(i = 0; i < vec->len; i++) {
11594 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11595 + if(!strcmp(version_str, version)) {
11596 + free(version_str);
11597 + break;
11598 + }
11599 + free(version_str);
11600 + }
11601 +
11602 + if(i == vec->len)
11603 + return NULL;
11604 +
11605 + return vec->pkgs[i];
11606 +}
11607 +
11608 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11609 + const char *pkg_name,
11610 + pkg_dest_t *dest)
11611 +{
11612 + pkg_vec_t * vec;
11613 + register int i;
11614 +
11615 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11616 + return NULL;
11617 + }
11618 +
11619 + for(i = 0; i < vec->len; i++)
11620 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11621 + return vec->pkgs[i];
11622 + }
11623 + return NULL;
11624 +}
11625 +
11626 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11627 + const char *pkg_name)
11628 +{
11629 + pkg_vec_t * vec;
11630 + register int i;
11631 +
11632 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11633 + return NULL;
11634 + }
11635 +
11636 + for(i = 0; i < vec->len; i++)
11637 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11638 + return vec->pkgs[i];
11639 + }
11640 +
11641 + return NULL;
11642 +}
11643 +
11644 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11645 +{
11646 + abstract_pkg_t * ab_pkg;
11647 +
11648 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11649 + return NULL;
11650 + }
11651 +
11652 + if (ab_pkg->pkgs) {
11653 + return ab_pkg->pkgs;
11654 + } else if (ab_pkg->provided_by) {
11655 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11656 + if (abpkg != NULL){
11657 + return abpkg->pkgs;
11658 + } else {
11659 + return ab_pkg->pkgs;
11660 + }
11661 + } else {
11662 + return NULL;
11663 + }
11664 +}
11665 +
11666 +static int pkg_compare_names(const void *p1, const void *p2)
11667 +{
11668 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11669 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11670 + if (pkg1->name == NULL)
11671 + return 1;
11672 + if (pkg2->name == NULL)
11673 + return -1;
11674 + return(strcmp(pkg1->name, pkg2->name));
11675 +}
11676 +
11677 +
11678 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11679 +{
11680 + int j;
11681 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11682 + pkg_vec_t *all = (pkg_vec_t *)data;
11683 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11684 + if (pkg_vec) {
11685 + for (j = 0; j < pkg_vec->len; j++) {
11686 + pkg_t *pkg = pkg_vec->pkgs[j];
11687 + pkg_vec_insert(all, pkg);
11688 + }
11689 + }
11690 +}
11691 +
11692 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11693 +{
11694 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11695 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11696 +}
11697 +
11698 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11699 +{
11700 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11701 + pkg_vec_t *all = (pkg_vec_t *)data;
11702 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11703 + int j;
11704 + if (pkg_vec) {
11705 + for (j = 0; j < pkg_vec->len; j++) {
11706 + pkg_t *pkg = pkg_vec->pkgs[j];
11707 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11708 + pkg_vec_insert(all, pkg);
11709 + }
11710 + }
11711 + }
11712 +}
11713 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11714 +{
11715 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11716 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11717 +}
11718 +
11719 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11720 +{
11721 + int i;
11722 + pkg_t *pkg;
11723 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11724 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11725 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11726 + fprintf(stdout, "%s\n", ab_pkg->name);
11727 + i = 0;
11728 + if (dependents != NULL)
11729 + while (dependents [i] != NULL)
11730 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11731 + dependents = ab_pkg->provided_by->pkgs;
11732 + i = 0;
11733 + if (dependents != NULL)
11734 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11735 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11736 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11737 + if (pkg) {
11738 + i = 0;
11739 + while (i < pkg->depends_count)
11740 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11741 + }
11742 +}
11743 +void pkg_hash_dump(hash_table_t *hash, void *data)
11744 +{
11745 +
11746 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11747 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11748 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11749 +}
11750 +
11751 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11752 +{
11753 + abstract_pkg_t * ab_pkg;
11754 +
11755 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11756 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11757 +
11758 + return ab_pkg;
11759 +}
11760 +
11761 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11762 +{
11763 + abstract_pkg_t * ab_pkg;
11764 + int arch_priority;
11765 +
11766 + if(!pkg)
11767 + return pkg;
11768 +
11769 + arch_priority = pkg->arch_priority;
11770 +
11771 + if (buildDepends(hash, pkg)<0){
11772 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11773 + return NULL;
11774 + }
11775 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11776 +
11777 + if (set_status) {
11778 + if (pkg->state_status == SS_INSTALLED) {
11779 + ab_pkg->state_status = SS_INSTALLED;
11780 + } else if (pkg->state_status == SS_UNPACKED) {
11781 + ab_pkg->state_status = SS_UNPACKED;
11782 + }
11783 + }
11784 +
11785 + if(!ab_pkg->pkgs)
11786 + ab_pkg->pkgs = pkg_vec_alloc();
11787 +
11788 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11789 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11790 + pkg->parent = ab_pkg;
11791 +
11792 + if (buildProvides(hash, ab_pkg, pkg)<0){
11793 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11794 + return NULL;
11795 + }
11796 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11797 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11798 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11799 + return NULL;
11800 + }
11801 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11802 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11803 + return NULL;
11804 + }
11805 +
11806 + buildDependedUponBy(pkg, ab_pkg);
11807 + return pkg;
11808 +}
11809 +
11810 +/*
11811 + * this will assume that we've already determined that
11812 + * the abstract pkg doesn't exist, 'cause we should know these things...
11813 + */
11814 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11815 +{
11816 + abstract_pkg_t * ab_pkg;
11817 +
11818 + ab_pkg = abstract_pkg_new();
11819 + if (ab_pkg == NULL) { return NULL; }
11820 +
11821 + ab_pkg->name = strdup(pkg_name);
11822 + hash_table_insert(hash, pkg_name, ab_pkg);
11823 +
11824 + return ab_pkg;
11825 +}
11826 +
11827 +
11828 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11829 +{
11830 + hash_table_t *file_hash = &conf->file_hash;
11831 +
11832 + return hash_table_get(file_hash, file_name);
11833 +}
11834 +
11835 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11836 +{
11837 + hash_table_t *file_hash = &conf->file_hash;
11838 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11839 + int file_name_len = strlen(file_name);
11840 +
11841 + if (file_name[file_name_len -1] == '/')
11842 + return 0;
11843 +
11844 + if (conf->offline_root) {
11845 + int len = strlen(conf->offline_root);
11846 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11847 + file_name += len;
11848 + }
11849 + }
11850 +
11851 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11852 + hash_table_insert(file_hash, file_name, owning_pkg);
11853 + if (old_owning_pkg) {
11854 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11855 + /* mark this package to have its filelist written */
11856 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11857 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11858 + }
11859 + return 0;
11860 +}
11861 +
11862 +
11863 Index: busybox-1.8.1/archival/libipkg/pkg_hash.h
11864 ===================================================================
11865 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11866 +++ busybox-1.8.1/archival/libipkg/pkg_hash.h 2007-11-10 17:40:53.388766251 +0100
11867 @@ -0,0 +1,61 @@
11868 +/* pkg_hash.h - the itsy package management system
11869 +
11870 + Steven M. Ayer
11871 +
11872 + Copyright (C) 2002 Compaq Computer Corporation
11873 +
11874 + This program is free software; you can redistribute it and/or
11875 + modify it under the terms of the GNU General Public License as
11876 + published by the Free Software Foundation; either version 2, or (at
11877 + your option) any later version.
11878 +
11879 + This program is distributed in the hope that it will be useful, but
11880 + WITHOUT ANY WARRANTY; without even the implied warranty of
11881 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11882 + General Public License for more details.
11883 +*/
11884 +
11885 +#ifndef PKG_HASH_H
11886 +#define PKG_HASH_H
11887 +
11888 +#include "pkg.h"
11889 +#include "pkg_vec.h"
11890 +#include "hash_table.h"
11891 +
11892 +
11893 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11894 +void pkg_hash_deinit(hash_table_t *hash);
11895 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11896 +
11897 +void pkg_hash_dump(hash_table_t *hash, void *data);
11898 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11899 +
11900 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11901 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11902 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11903 +
11904 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11905 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11906 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11907 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11908 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11909 + const char *pkg_name,
11910 + const char * version);
11911 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11912 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11913 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11914 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11915 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11916 + const char *pkg_name);
11917 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11918 + const char *pkg_name,
11919 + pkg_dest_t *dest);
11920 +
11921 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11922 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11923 +
11924 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11925 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11926 +
11927 +#endif
11928 +
11929 Index: busybox-1.8.1/archival/libipkg/pkg_parse.c
11930 ===================================================================
11931 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11932 +++ busybox-1.8.1/archival/libipkg/pkg_parse.c 2007-11-10 17:40:53.388766251 +0100
11933 @@ -0,0 +1,366 @@
11934 +/* pkg_parse.c - the itsy package management system
11935 +
11936 + Steven M. Ayer
11937 +
11938 + Copyright (C) 2002 Compaq Computer Corporation
11939 +
11940 + This program is free software; you can redistribute it and/or
11941 + modify it under the terms of the GNU General Public License as
11942 + published by the Free Software Foundation; either version 2, or (at
11943 + your option) any later version.
11944 +
11945 + This program is distributed in the hope that it will be useful, but
11946 + WITHOUT ANY WARRANTY; without even the implied warranty of
11947 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11948 + General Public License for more details.
11949 +*/
11950 +
11951 +#include "ipkg.h"
11952 +#include <errno.h>
11953 +#include <ctype.h>
11954 +
11955 +#include "pkg.h"
11956 +#include "ipkg_utils.h"
11957 +#include "pkg_parse.h"
11958 +
11959 +int isGenericFieldType(char * type, char * line)
11960 +{
11961 + if(!strncmp(line, type, strlen(type)))
11962 + return 1;
11963 + return 0;
11964 +}
11965 +
11966 +char * parseGenericFieldType(char * type, char * raw)
11967 +{
11968 + char * field_value = raw + (strlen(type) + 1);
11969 + return trim_alloc(field_value);
11970 +}
11971 +
11972 +void parseStatus(pkg_t *pkg, char * raw)
11973 +{
11974 + char sw_str[64], sf_str[64], ss_str[64];
11975 +
11976 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11977 + pkg->state_want = pkg_state_want_from_str(sw_str);
11978 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11979 + pkg->state_status = pkg_state_status_from_str(ss_str);
11980 +}
11981 +
11982 +char ** parseDependsString(char * raw, int * depends_count)
11983 +{
11984 + char ** depends = NULL;
11985 + int line_count = 0;
11986 + char buff[2048], * dest;
11987 +
11988 + while(raw && *raw && !isspace(*raw)) {
11989 + raw++;
11990 + }
11991 +
11992 + if(line_is_blank(raw)){
11993 + *depends_count = line_count;
11994 + return NULL;
11995 + }
11996 + while(raw && *raw){
11997 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11998 +
11999 + while(isspace(*raw)) raw++;
12000 +
12001 + dest = buff;
12002 + while((*raw != ',') && *raw)
12003 + *dest++ = *raw++;
12004 +
12005 + *dest = '\0';
12006 + depends[line_count] = trim_alloc(buff);
12007 + if(depends[line_count] ==NULL)
12008 + return NULL;
12009 + line_count++;
12010 + if(*raw == ',')
12011 + raw++;
12012 + }
12013 + *depends_count = line_count;
12014 + return depends;
12015 +}
12016 +
12017 +void parseConffiles(pkg_t * pkg, char * raw)
12018 +{
12019 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12020 +
12021 + if(!strncmp(raw, "Conffiles:", 10))
12022 + raw += strlen("Conffiles:");
12023 +
12024 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12025 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12026 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12027 + while (*raw && isspace(*raw)) {
12028 + raw++;
12029 + }
12030 + raw += strlen(file_name);
12031 + while (*raw && isspace(*raw)) {
12032 + raw++;
12033 + }
12034 + raw += strlen(md5sum);
12035 + }
12036 +}
12037 +
12038 +int parseVersion(pkg_t *pkg, char *raw)
12039 +{
12040 + char *colon, *eepochcolon;
12041 +#ifdef USE_DEBVERSION
12042 + char *hyphen;
12043 +#endif
12044 + unsigned long epoch;
12045 +
12046 + if (!*raw) {
12047 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12048 + return EINVAL;
12049 + }
12050 +
12051 + if (strncmp(raw, "Version:", 8) == 0) {
12052 + raw += 8;
12053 + }
12054 + while (*raw && isspace(*raw)) {
12055 + raw++;
12056 + }
12057 +
12058 + colon= strchr(raw,':');
12059 + if (colon) {
12060 + epoch= strtoul(raw,&eepochcolon,10);
12061 + if (colon != eepochcolon) {
12062 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12063 + return EINVAL;
12064 + }
12065 + if (!*++colon) {
12066 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12067 + return EINVAL;
12068 + }
12069 + raw= colon;
12070 + pkg->epoch= epoch;
12071 + } else {
12072 + pkg->epoch= 0;
12073 + }
12074 +
12075 + pkg->revision = "";
12076 + pkg->familiar_revision = "";
12077 +
12078 + pkg->version= malloc(strlen(raw)+1);
12079 + if ( pkg->version == NULL ) {
12080 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12081 + return ENOMEM;
12082 + }
12083 + strcpy(pkg->version, raw);
12084 +
12085 +#ifdef USE_DEBVERSION
12086 + hyphen= strrchr(pkg->version,'-');
12087 +
12088 + if (hyphen) {
12089 + *hyphen++= 0;
12090 + if (strncmp("fam", hyphen, 3) == 0) {
12091 + pkg->familiar_revision=hyphen+3;
12092 + hyphen= strrchr(pkg->version,'-');
12093 + if (hyphen) {
12094 + *hyphen++= 0;
12095 + pkg->revision = hyphen;
12096 + }
12097 + } else {
12098 + pkg->revision = hyphen;
12099 + }
12100 + }
12101 +#endif
12102 +
12103 +/*
12104 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12105 + pkg->epoch,
12106 + pkg->version,
12107 + pkg->revision,
12108 + pkg->familiar_revision);
12109 +*/
12110 +
12111 + return 0;
12112 +}
12113 +
12114 +
12115 +/* This code is needed to insert in first position the keyword for the aligning bug */
12116 +
12117 +int alterProvidesLine(char *raw, char *temp)
12118 +{
12119 +
12120 +
12121 + if (!*raw) {
12122 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12123 + return -EINVAL;
12124 + }
12125 +
12126 + if ( temp == NULL ) {
12127 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12128 + return -ENOMEM;
12129 + }
12130 +
12131 + if (strncmp(raw, "Provides:", 9) == 0) {
12132 + raw += 9;
12133 + }
12134 + while (*raw && isspace(*raw)) {
12135 + raw++;
12136 + }
12137 +
12138 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12139 + while (*raw) {
12140 + strncat( temp, raw++, 1);
12141 + }
12142 + return 0;
12143 +
12144 +}
12145 +
12146 +/* Some random thoughts from Carl:
12147 +
12148 + This function could be considerably simplified if we just kept
12149 + an array of all the generic string-valued field names, and looped
12150 + through those looking for a match. Also, these fields could perhaps
12151 + be stored in the package as an array as well, (or, probably better,
12152 + as an nv_pair_list_t).
12153 +
12154 + Fields which require special parsing or storage, (such as Depends:
12155 + and Status:) could be handled as they are now.
12156 +*/
12157 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12158 + to a dependency list. And, since we already have
12159 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12160 + Enhances, perhaps we could generalize all of these and save some
12161 + code duplication.
12162 +*/
12163 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12164 +{
12165 + int reading_conffiles, reading_description;
12166 + int pkg_false_provides=1;
12167 + char ** lines;
12168 + char * provide=NULL;
12169 +
12170 + pkg->src = src;
12171 + pkg->dest = dest;
12172 +
12173 + reading_conffiles = reading_description = 0;
12174 +
12175 + for (lines = *raw; *lines; lines++) {
12176 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12177 + if(isGenericFieldType("Package:", *lines))
12178 + pkg->name = parseGenericFieldType("Package", *lines);
12179 + else if(isGenericFieldType("Architecture:", *lines))
12180 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12181 + else if(isGenericFieldType("Filename:", *lines))
12182 + pkg->filename = parseGenericFieldType("Filename", *lines);
12183 + else if(isGenericFieldType("Section:", *lines))
12184 + pkg->section = parseGenericFieldType("Section", *lines);
12185 + else if(isGenericFieldType("MD5sum:", *lines))
12186 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12187 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12188 + let's parse it either way */
12189 + else if(isGenericFieldType("MD5Sum:", *lines))
12190 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12191 + else if(isGenericFieldType("Size:", *lines))
12192 + pkg->size = parseGenericFieldType("Size", *lines);
12193 + else if(isGenericFieldType("Source:", *lines))
12194 + pkg->source = parseGenericFieldType("Source", *lines);
12195 + else if(isGenericFieldType("Installed-Size:", *lines))
12196 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12197 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12198 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12199 + pkg->installed_time = strtoul(time_str, NULL, 0);
12200 + } else if(isGenericFieldType("Priority:", *lines))
12201 + pkg->priority = parseGenericFieldType("Priority", *lines);
12202 + else if(isGenericFieldType("Essential:", *lines)) {
12203 + char *essential_value;
12204 + essential_value = parseGenericFieldType("Essential", *lines);
12205 + if (strcmp(essential_value, "yes") == 0) {
12206 + pkg->essential = 1;
12207 + }
12208 + free(essential_value);
12209 + }
12210 + else if(isGenericFieldType("Status", *lines))
12211 + parseStatus(pkg, *lines);
12212 + else if(isGenericFieldType("Version", *lines))
12213 + parseVersion(pkg, *lines);
12214 + else if(isGenericFieldType("Maintainer", *lines))
12215 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12216 + else if(isGenericFieldType("Conffiles", *lines)){
12217 + parseConffiles(pkg, *lines);
12218 + reading_conffiles = 1;
12219 + }
12220 + else if(isGenericFieldType("Description", *lines)) {
12221 + pkg->description = parseGenericFieldType("Description", *lines);
12222 + reading_conffiles = 0;
12223 + reading_description = 1;
12224 + }
12225 +
12226 + else if(isGenericFieldType("Provides", *lines)){
12227 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12228 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12229 + if ( alterProvidesLine(*lines,provide) ){
12230 + return EINVAL;
12231 + }
12232 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12233 +/* Let's try to hack a bit here.
12234 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12235 + in alot of other places. We will remove it before writing down the status database */
12236 + pkg_false_provides=0;
12237 + free(provide);
12238 + }
12239 +
12240 + else if(isGenericFieldType("Depends", *lines))
12241 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12242 + else if(isGenericFieldType("Pre-Depends", *lines))
12243 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12244 + else if(isGenericFieldType("Recommends", *lines))
12245 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12246 + else if(isGenericFieldType("Suggests", *lines))
12247 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12248 + /* Abhaya: support for conflicts */
12249 + else if(isGenericFieldType("Conflicts", *lines))
12250 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12251 + else if(isGenericFieldType("Replaces", *lines))
12252 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12253 + else if(line_is_blank(*lines)) {
12254 + lines++;
12255 + break;
12256 + }
12257 + else if(**lines == ' '){
12258 + if(reading_description) {
12259 + /* we already know it's not blank, so the rest of description */
12260 + pkg->description = realloc(pkg->description,
12261 + strlen(pkg->description)
12262 + + 1 + strlen(*lines) + 1);
12263 + strcat(pkg->description, "\n");
12264 + strcat(pkg->description, (*lines));
12265 + }
12266 + else if(reading_conffiles)
12267 + parseConffiles(pkg, *lines);
12268 + }
12269 + }
12270 + *raw = lines;
12271 +/* If the ipk has not a Provides line, we insert our false line */
12272 + if ( pkg_false_provides==1)
12273 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12274 +
12275 + if (pkg->name) {
12276 + return 0;
12277 + } else {
12278 + return EINVAL;
12279 + }
12280 +}
12281 +
12282 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12283 +{
12284 + char ** lines;
12285 +
12286 + for (lines = *raw; *lines; lines++) {
12287 + if(isGenericFieldType("Essential:", *lines)) {
12288 + char *essential_value;
12289 + essential_value = parseGenericFieldType("Essential", *lines);
12290 + if (strcmp(essential_value, "yes") == 0) {
12291 + pkg->essential = 1;
12292 + }
12293 + free(essential_value);
12294 + }
12295 + }
12296 + *raw = lines;
12297 +
12298 + return 0;
12299 +}
12300 Index: busybox-1.8.1/archival/libipkg/pkg_parse.h
12301 ===================================================================
12302 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12303 +++ busybox-1.8.1/archival/libipkg/pkg_parse.h 2007-11-10 17:40:53.392766477 +0100
12304 @@ -0,0 +1,31 @@
12305 +/* pkg_parse.h - the itsy package management system
12306 +
12307 + Steven M. Ayer
12308 +
12309 + Copyright (C) 2002 Compaq Computer Corporation
12310 +
12311 + This program is free software; you can redistribute it and/or
12312 + modify it under the terms of the GNU General Public License as
12313 + published by the Free Software Foundation; either version 2, or (at
12314 + your option) any later version.
12315 +
12316 + This program is distributed in the hope that it will be useful, but
12317 + WITHOUT ANY WARRANTY; without even the implied warranty of
12318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12319 + General Public License for more details.
12320 +*/
12321 +
12322 +#ifndef PKG_PARSE_H
12323 +#define PKG_PARSE_H
12324 +
12325 +int isGenericFieldType(char * type, char * line);
12326 +char * parseGenericFieldType(char * type, char * raw);
12327 +void parseStatus(pkg_t *pkg, char * raw);
12328 +int parseVersion(pkg_t *pkg, char *raw);
12329 +char ** parseDependsString(char * raw, int * depends_count);
12330 +int parseVersion(pkg_t *pkg, char *raw);
12331 +void parseConffiles(pkg_t * pkg, char * raw);
12332 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12333 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12334 +
12335 +#endif
12336 Index: busybox-1.8.1/archival/libipkg/pkg_src.c
12337 ===================================================================
12338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12339 +++ busybox-1.8.1/archival/libipkg/pkg_src.c 2007-11-10 17:40:53.392766477 +0100
12340 @@ -0,0 +1,43 @@
12341 +/* pkg_src.c - the itsy package management system
12342 +
12343 + Carl D. Worth
12344 +
12345 + Copyright (C) 2001 University of Southern California
12346 +
12347 + This program is free software; you can redistribute it and/or
12348 + modify it under the terms of the GNU General Public License as
12349 + published by the Free Software Foundation; either version 2, or (at
12350 + your option) any later version.
12351 +
12352 + This program is distributed in the hope that it will be useful, but
12353 + WITHOUT ANY WARRANTY; without even the implied warranty of
12354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12355 + General Public License for more details.
12356 +*/
12357 +
12358 +#include "ipkg.h"
12359 +
12360 +#include "pkg_src.h"
12361 +#include "str_util.h"
12362 +
12363 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12364 +{
12365 + src->gzip = gzip;
12366 + src->name = str_dup_safe (name);
12367 + src->value = str_dup_safe (base_url);
12368 + if (extra_data)
12369 + src->extra_data = str_dup_safe (extra_data);
12370 + else
12371 + src->extra_data = NULL;
12372 + return 0;
12373 +}
12374 +
12375 +void pkg_src_deinit(pkg_src_t *src)
12376 +{
12377 + free (src->name);
12378 + free (src->value);
12379 + if (src->extra_data)
12380 + free (src->extra_data);
12381 +}
12382 +
12383 +
12384 Index: busybox-1.8.1/archival/libipkg/pkg_src.h
12385 ===================================================================
12386 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12387 +++ busybox-1.8.1/archival/libipkg/pkg_src.h 2007-11-10 17:40:53.392766477 +0100
12388 @@ -0,0 +1,34 @@
12389 +/* pkg_src.h - the itsy package management system
12390 +
12391 + Carl D. Worth
12392 +
12393 + Copyright (C) 2001 University of Southern California
12394 +
12395 + This program is free software; you can redistribute it and/or
12396 + modify it under the terms of the GNU General Public License as
12397 + published by the Free Software Foundation; either version 2, or (at
12398 + your option) any later version.
12399 +
12400 + This program is distributed in the hope that it will be useful, but
12401 + WITHOUT ANY WARRANTY; without even the implied warranty of
12402 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12403 + General Public License for more details.
12404 +*/
12405 +
12406 +#ifndef PKG_SRC_H
12407 +#define PKG_SRC_H
12408 +
12409 +#include "nv_pair.h"
12410 +
12411 +typedef struct
12412 +{
12413 + char *name;
12414 + char *value;
12415 + char *extra_data;
12416 + int gzip;
12417 +} pkg_src_t;
12418 +
12419 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12420 +void pkg_src_deinit(pkg_src_t *src);
12421 +
12422 +#endif
12423 Index: busybox-1.8.1/archival/libipkg/pkg_src_list.c
12424 ===================================================================
12425 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12426 +++ busybox-1.8.1/archival/libipkg/pkg_src_list.c 2007-11-10 17:40:53.392766477 +0100
12427 @@ -0,0 +1,75 @@
12428 +/* pkg_src_list.c - the itsy package management system
12429 +
12430 + Carl D. Worth
12431 +
12432 + Copyright (C) 2001 University of Southern California
12433 +
12434 + This program is free software; you can redistribute it and/or
12435 + modify it under the terms of the GNU General Public License as
12436 + published by the Free Software Foundation; either version 2, or (at
12437 + your option) any later version.
12438 +
12439 + This program is distributed in the hope that it will be useful, but
12440 + WITHOUT ANY WARRANTY; without even the implied warranty of
12441 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12442 + General Public License for more details.
12443 +*/
12444 +
12445 +#include "ipkg.h"
12446 +
12447 +#include "pkg_src_list.h"
12448 +#include "void_list.h"
12449 +
12450 +int pkg_src_list_init(pkg_src_list_t *list)
12451 +{
12452 + return void_list_init((void_list_t *) list);
12453 +}
12454 +
12455 +void pkg_src_list_deinit(pkg_src_list_t *list)
12456 +{
12457 + pkg_src_list_elt_t *iter;
12458 + pkg_src_t *pkg_src;
12459 +
12460 + for (iter = list->head; iter; iter = iter->next) {
12461 + pkg_src = iter->data;
12462 + pkg_src_deinit(pkg_src);
12463 +
12464 + /* malloced in pkg_src_list_append */
12465 + free(pkg_src);
12466 + iter->data = NULL;
12467 + }
12468 + void_list_deinit((void_list_t *) list);
12469 +}
12470 +
12471 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12472 + const char *name, const char *base_url, const char *extra_data,
12473 + int gzip)
12474 +{
12475 + int err;
12476 +
12477 + /* freed in pkg_src_list_deinit */
12478 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12479 +
12480 + if (pkg_src == NULL) {
12481 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12482 + return NULL;
12483 + }
12484 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12485 +
12486 + err = void_list_append((void_list_t *) list, pkg_src);
12487 + if (err) {
12488 + return NULL;
12489 + }
12490 +
12491 + return pkg_src;
12492 +}
12493 +
12494 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12495 +{
12496 + return void_list_push((void_list_t *) list, data);
12497 +}
12498 +
12499 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12500 +{
12501 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12502 +}
12503 Index: busybox-1.8.1/archival/libipkg/pkg_src_list.h
12504 ===================================================================
12505 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12506 +++ busybox-1.8.1/archival/libipkg/pkg_src_list.h 2007-11-10 17:40:53.396766706 +0100
12507 @@ -0,0 +1,57 @@
12508 +/* pkg_src_list.h - the itsy package management system
12509 +
12510 + Carl D. Worth
12511 +
12512 + Copyright (C) 2001 University of Southern California
12513 +
12514 + This program is free software; you can redistribute it and/or
12515 + modify it under the terms of the GNU General Public License as
12516 + published by the Free Software Foundation; either version 2, or (at
12517 + your option) any later version.
12518 +
12519 + This program is distributed in the hope that it will be useful, but
12520 + WITHOUT ANY WARRANTY; without even the implied warranty of
12521 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12522 + General Public License for more details.
12523 +*/
12524 +
12525 +#ifndef PKG_SRC_LIST_H
12526 +#define PKG_SRC_LIST_H
12527 +
12528 +#include "pkg_src.h"
12529 +
12530 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12531 +struct pkg_src_list_elt
12532 +{
12533 + pkg_src_list_elt_t *next;
12534 + pkg_src_t *data;
12535 +};
12536 +
12537 +typedef struct pkg_src_list pkg_src_list_t;
12538 +struct pkg_src_list
12539 +{
12540 + pkg_src_list_elt_t pre_head;
12541 + pkg_src_list_elt_t *head;
12542 + pkg_src_list_elt_t *tail;
12543 +};
12544 +
12545 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12546 +{
12547 + if (list->head == NULL)
12548 + return 1;
12549 + else
12550 + return 0;
12551 +}
12552 +
12553 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12554 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12555 +
12556 +int pkg_src_list_init(pkg_src_list_t *list);
12557 +void pkg_src_list_deinit(pkg_src_list_t *list);
12558 +
12559 +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);
12560 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12561 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12562 +
12563 +#endif
12564 +
12565 Index: busybox-1.8.1/archival/libipkg/pkg_vec.c
12566 ===================================================================
12567 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12568 +++ busybox-1.8.1/archival/libipkg/pkg_vec.c 2007-11-10 17:40:53.396766706 +0100
12569 @@ -0,0 +1,230 @@
12570 +/* pkg_vec.c - the itsy package management system
12571 +
12572 + Steven M. Ayer
12573 +
12574 + Copyright (C) 2002 Compaq Computer Corporation
12575 +
12576 + This program is free software; you can redistribute it and/or
12577 + modify it under the terms of the GNU General Public License as
12578 + published by the Free Software Foundation; either version 2, or (at
12579 + your option) any later version.
12580 +
12581 + This program is distributed in the hope that it will be useful, but
12582 + WITHOUT ANY WARRANTY; without even the implied warranty of
12583 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12584 + General Public License for more details.
12585 +*/
12586 +
12587 +#include <stdlib.h>
12588 +#include <fnmatch.h>
12589 +#include "xregex.h"
12590 +#include "ipkg.h"
12591 +#include "pkg.h"
12592 +
12593 +pkg_vec_t * pkg_vec_alloc(void)
12594 +{
12595 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12596 + if (!vec) {
12597 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12598 + return NULL;
12599 + }
12600 + vec->pkgs = NULL;
12601 + vec->len = 0;
12602 +
12603 + return vec;
12604 +}
12605 +
12606 +void pkg_vec_free(pkg_vec_t *vec)
12607 +{
12608 + free(vec->pkgs);
12609 + free(vec);
12610 +}
12611 +
12612 +/*
12613 + * assumption: all names in a vector are identical
12614 + * assumption: all version strings are trimmed,
12615 + * so identical versions have identical version strings,
12616 + * implying identical packages; let's marry these
12617 + */
12618 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12619 +{
12620 + int i;
12621 + int found = 0;
12622 +
12623 + /* look for a duplicate pkg by name, version, and architecture */
12624 + for (i = 0; i < vec->len; i++){
12625 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12626 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12627 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12628 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12629 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12630 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12631 + found = 1;
12632 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12633 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12634 + break;
12635 + }
12636 + }
12637 +
12638 + /* we didn't find one, add it */
12639 + if (!found){
12640 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12641 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12642 +
12643 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12644 + vec->pkgs[vec->len] = pkg;
12645 + vec->len++;
12646 + return pkg;
12647 + }
12648 + /* update the one that we have */
12649 + else {
12650 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12651 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12652 + if (set_status) {
12653 + /* this is from the status file, so need to merge with existing database */
12654 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12655 + pkg_merge(vec->pkgs[i], pkg, set_status);
12656 + /* XXX: CLEANUP: It's not so polite to free something here
12657 + that was passed in from above. */
12658 + pkg_deinit(pkg);
12659 + free(pkg);
12660 + } else {
12661 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12662 + /* just overwrite the old one */
12663 + pkg_deinit(vec->pkgs[i]);
12664 + free(vec->pkgs[i]);
12665 + vec->pkgs[i] = pkg;
12666 + }
12667 + return vec->pkgs[i];
12668 + }
12669 +}
12670 +
12671 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12672 +{
12673 + int i;
12674 + int found = 0;
12675 +
12676 + /* look for a duplicate pkg by name, version, and architecture */
12677 + for (i = 0; i < vec->len; i++)
12678 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12679 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12680 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12681 + found = 1;
12682 + break;
12683 + }
12684 +
12685 + /* we didn't find one, add it */
12686 + if(!found){
12687 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12688 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12689 + vec->len++;
12690 + }
12691 +}
12692 +
12693 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12694 +{
12695 + int i;
12696 + for (i = 0; i < vec->len; i++)
12697 + if (vec->pkgs[i] == apkg)
12698 + return 1;
12699 + return 0;
12700 +}
12701 +
12702 +typedef int (*compare_fcn_t)(const void *, const void *);
12703 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12704 +{
12705 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12706 +}
12707 +
12708 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12709 +{
12710 + int npkgs = vec->len;
12711 + int i;
12712 + for (i = 0; i < npkgs; i++) {
12713 + pkg_t *pkg = vec->pkgs[i];
12714 + pkg->state_flag &= ~SF_MARKED;
12715 + }
12716 + return 0;
12717 +}
12718 +
12719 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12720 +{
12721 + int matching_count = 0;
12722 + pkg_t **pkgs = vec->pkgs;
12723 + int npkgs = vec->len;
12724 + int i;
12725 + for (i = 0; i < npkgs; i++) {
12726 + pkg_t *pkg = pkgs[i];
12727 + if (fnmatch(pattern, pkg->name, 0)==0) {
12728 + pkg->state_flag |= SF_MARKED;
12729 + matching_count++;
12730 + }
12731 + }
12732 + return matching_count;
12733 +}
12734 +
12735 +
12736 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12737 +{
12738 + abstract_pkg_vec_t * vec ;
12739 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12740 + if (!vec) {
12741 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12742 + return NULL;
12743 + }
12744 + vec->pkgs = NULL;
12745 + vec->len = 0;
12746 +
12747 + return vec;
12748 +}
12749 +
12750 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12751 +{
12752 + free(vec->pkgs);
12753 + free(vec);
12754 +}
12755 +
12756 +/*
12757 + * assumption: all names in a vector are unique
12758 + */
12759 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12760 +{
12761 + int i;
12762 +
12763 + /* look for a duplicate pkg by name */
12764 + for(i = 0; i < vec->len; i++)
12765 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12766 + break;
12767 +
12768 + /* we didn't find one, add it */
12769 + if(i == vec->len){
12770 + vec->pkgs =
12771 + (abstract_pkg_t **)
12772 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12773 + vec->pkgs[vec->len] = pkg;
12774 + vec->len++;
12775 + }
12776 +}
12777 +
12778 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12779 +{
12780 + if (vec->len > i)
12781 + return vec->pkgs[i];
12782 + else
12783 + return NULL;
12784 +}
12785 +
12786 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12787 +{
12788 + int i;
12789 + for (i = 0; i < vec->len; i++)
12790 + if (vec->pkgs[i] == apkg)
12791 + return 1;
12792 + return 0;
12793 +}
12794 +
12795 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12796 +{
12797 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12798 +}
12799 +
12800 Index: busybox-1.8.1/archival/libipkg/pkg_vec.h
12801 ===================================================================
12802 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12803 +++ busybox-1.8.1/archival/libipkg/pkg_vec.h 2007-11-10 17:40:53.396766706 +0100
12804 @@ -0,0 +1,64 @@
12805 +/* pkg_vec.h - the itsy package management system
12806 +
12807 + Steven M. Ayer
12808 +
12809 + Copyright (C) 2002 Compaq Computer Corporation
12810 +
12811 + This program is free software; you can redistribute it and/or
12812 + modify it under the terms of the GNU General Public License as
12813 + published by the Free Software Foundation; either version 2, or (at
12814 + your option) any later version.
12815 +
12816 + This program is distributed in the hope that it will be useful, but
12817 + WITHOUT ANY WARRANTY; without even the implied warranty of
12818 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12819 + General Public License for more details.
12820 +*/
12821 +
12822 +#ifndef PKG_VEC_H
12823 +#define PKG_VEC_H
12824 +
12825 +typedef struct pkg pkg_t;
12826 +typedef struct abstract_pkg abstract_pkg_t;
12827 +
12828 +struct pkg_vec
12829 +{
12830 + pkg_t **pkgs;
12831 + int len;
12832 +};
12833 +typedef struct pkg_vec pkg_vec_t;
12834 +
12835 +struct abstract_pkg_vec
12836 +{
12837 + abstract_pkg_t **pkgs;
12838 + int len;
12839 +};
12840 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12841 +
12842 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12843 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12844 +
12845 +pkg_vec_t * pkg_vec_alloc(void);
12846 +void pkg_vec_free(pkg_vec_t *vec);
12847 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12848 +
12849 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12850 +/* pkg_vec_insert_merge: might munge pkg.
12851 +* returns the pkg that is in the pkg graph */
12852 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12853 +/* this one never munges pkg */
12854 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12855 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12856 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12857 +
12858 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12859 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12860 +
12861 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12862 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12863 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12864 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12865 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12866 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12867 +#endif
12868 +
12869 Index: busybox-1.8.1/archival/libipkg/sprintf_alloc.h
12870 ===================================================================
12871 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12872 +++ busybox-1.8.1/archival/libipkg/sprintf_alloc.h 2007-11-10 17:40:53.396766706 +0100
12873 @@ -0,0 +1,25 @@
12874 +/* sprintf_alloca.c -- like sprintf with memory allocation
12875 +
12876 + Carl D. Worth
12877 +
12878 + Copyright (C) 2001 University of Southern California
12879 +
12880 + This program is free software; you can redistribute it and/or modify
12881 + it under the terms of the GNU General Public License as published by
12882 + the Free Software Foundation; either version 2, or (at your option)
12883 + any later version.
12884 +
12885 + This program is distributed in the hope that it will be useful,
12886 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12887 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12888 + GNU General Public License for more details.
12889 +*/
12890 +
12891 +#ifndef SPRINTF_ALLOC_H
12892 +#define SPRINTF_ALLOC_H
12893 +
12894 +#include "libbb.h"
12895 +
12896 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12897 +
12898 +#endif
12899 Index: busybox-1.8.1/archival/libipkg/str_list.c
12900 ===================================================================
12901 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12902 +++ busybox-1.8.1/archival/libipkg/str_list.c 2007-11-10 17:40:53.396766706 +0100
12903 @@ -0,0 +1,76 @@
12904 +/* str_list.c - the itsy package management system
12905 +
12906 + Carl D. Worth
12907 +
12908 + Copyright (C) 2001 University of Southern California
12909 +
12910 + This program is free software; you can redistribute it and/or
12911 + modify it under the terms of the GNU General Public License as
12912 + published by the Free Software Foundation; either version 2, or (at
12913 + your option) any later version.
12914 +
12915 + This program is distributed in the hope that it will be useful, but
12916 + WITHOUT ANY WARRANTY; without even the implied warranty of
12917 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12918 + General Public License for more details.
12919 +*/
12920 +
12921 +#include "ipkg.h"
12922 +
12923 +#include "str_list.h"
12924 +
12925 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12926 +{
12927 + return void_list_elt_init((void_list_elt_t *) elt, data);
12928 +}
12929 +
12930 +void str_list_elt_deinit(str_list_elt_t *elt)
12931 +{
12932 + void_list_elt_deinit((void_list_elt_t *) elt);
12933 +}
12934 +
12935 +str_list_t *str_list_alloc()
12936 +{
12937 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12938 + if (list)
12939 + str_list_init(list);
12940 + return list;
12941 +}
12942 +
12943 +int str_list_init(str_list_t *list)
12944 +{
12945 + return void_list_init((void_list_t *) list);
12946 +}
12947 +
12948 +void str_list_deinit(str_list_t *list)
12949 +{
12950 + void_list_deinit((void_list_t *) list);
12951 +}
12952 +
12953 +int str_list_append(str_list_t *list, char *data)
12954 +{
12955 + return void_list_append((void_list_t *) list, data);
12956 +}
12957 +
12958 +int str_list_push(str_list_t *list, char *data)
12959 +{
12960 + return void_list_push((void_list_t *) list, data);
12961 +}
12962 +
12963 +str_list_elt_t *str_list_pop(str_list_t *list)
12964 +{
12965 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12966 +}
12967 +
12968 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12969 +{
12970 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12971 + (void_list_elt_t **) iter);
12972 +}
12973 +
12974 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12975 +{
12976 + return (char *)void_list_remove_elt((void_list_t *) list,
12977 + (void *)target_str,
12978 + (void_list_cmp_t)strcmp);
12979 +}
12980 Index: busybox-1.8.1/archival/libipkg/str_list.h
12981 ===================================================================
12982 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12983 +++ busybox-1.8.1/archival/libipkg/str_list.h 2007-11-10 17:40:53.400766935 +0100
12984 @@ -0,0 +1,51 @@
12985 +/* str_list.h - the itsy package management system
12986 +
12987 + Carl D. Worth
12988 +
12989 + Copyright (C) 2001 University of Southern California
12990 +
12991 + This program is free software; you can redistribute it and/or
12992 + modify it under the terms of the GNU General Public License as
12993 + published by the Free Software Foundation; either version 2, or (at
12994 + your option) any later version.
12995 +
12996 + This program is distributed in the hope that it will be useful, but
12997 + WITHOUT ANY WARRANTY; without even the implied warranty of
12998 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12999 + General Public License for more details.
13000 +*/
13001 +
13002 +#ifndef STR_LIST_H
13003 +#define STR_LIST_H
13004 +
13005 +#include "void_list.h"
13006 +
13007 +typedef struct str_list_elt str_list_elt_t;
13008 +struct str_list_elt
13009 +{
13010 + str_list_elt_t *next;
13011 + char *data;
13012 +};
13013 +
13014 +typedef struct xstr_list str_list_t;
13015 +struct xstr_list
13016 +{
13017 + str_list_elt_t pre_head;
13018 + str_list_elt_t *head;
13019 + str_list_elt_t *tail;
13020 +};
13021 +
13022 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13023 +void str_list_elt_deinit(str_list_elt_t *elt);
13024 +
13025 +str_list_t *str_list_alloc(void);
13026 +int str_list_init(str_list_t *list);
13027 +void str_list_deinit(str_list_t *list);
13028 +
13029 +int str_list_append(str_list_t *list, char *data);
13030 +int str_list_push(str_list_t *list, char *data);
13031 +str_list_elt_t *str_list_pop(str_list_t *list);
13032 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13033 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13034 +
13035 +#endif
13036 Index: busybox-1.8.1/archival/libipkg/str_util.c
13037 ===================================================================
13038 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13039 +++ busybox-1.8.1/archival/libipkg/str_util.c 2007-11-10 17:40:53.400766935 +0100
13040 @@ -0,0 +1,63 @@
13041 +/* str_utils.c - the itsy package management system
13042 +
13043 + Carl D. Worth
13044 +
13045 + Copyright (C) 2001 University of Southern California
13046 +
13047 + This program is free software; you can redistribute it and/or
13048 + modify it under the terms of the GNU General Public License as
13049 + published by the Free Software Foundation; either version 2, or (at
13050 + your option) any later version.
13051 +
13052 + This program is distributed in the hope that it will be useful, but
13053 + WITHOUT ANY WARRANTY; without even the implied warranty of
13054 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13055 + General Public License for more details.
13056 +*/
13057 +
13058 +#include "ipkg.h"
13059 +
13060 +int str_starts_with(const char *str, const char *prefix)
13061 +{
13062 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13063 +}
13064 +
13065 +int str_ends_with(const char *str, const char *suffix)
13066 +{
13067 + int suffix_len;
13068 + int str_len;
13069 +
13070 + str_len = strlen(str);
13071 + suffix_len = strlen(suffix);
13072 +
13073 + if (str_len < suffix_len) {
13074 + return 0;
13075 + }
13076 +
13077 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13078 +}
13079 +
13080 +int str_chomp(char *str)
13081 +{
13082 + if (str[strlen(str) - 1] == '\n') {
13083 + str[strlen(str) - 1] = '\0';
13084 + return 1;
13085 + }
13086 + return 0;
13087 +}
13088 +
13089 +int str_toupper(char *str)
13090 +{
13091 + while (*str) {
13092 + *str = toupper(*str);
13093 + str++;
13094 + }
13095 +
13096 + return 0;
13097 +}
13098 +
13099 +char *str_dup_safe(const char *str)
13100 +{
13101 + return str ? strdup(str) : NULL;
13102 +}
13103 +
13104 Index: busybox-1.8.1/archival/libipkg/str_util.h
13105 ===================================================================
13106 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13107 +++ busybox-1.8.1/archival/libipkg/str_util.h 2007-11-10 17:40:53.400766935 +0100
13108 @@ -0,0 +1,27 @@
13109 +/* str_utils.h - the itsy package management system
13110 +
13111 + Carl D. Worth
13112 +
13113 + Copyright (C) 2001 University of Southern California
13114 +
13115 + This program is free software; you can redistribute it and/or
13116 + modify it under the terms of the GNU General Public License as
13117 + published by the Free Software Foundation; either version 2, or (at
13118 + your option) any later version.
13119 +
13120 + This program is distributed in the hope that it will be useful, but
13121 + WITHOUT ANY WARRANTY; without even the implied warranty of
13122 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13123 + General Public License for more details.
13124 +*/
13125 +
13126 +#ifndef STR_UTILS_H
13127 +#define STR_UTILS_H
13128 +
13129 +int str_starts_with(const char *str, const char *prefix);
13130 +int str_ends_with(const char *str, const char *suffix);
13131 +int str_chomp(char *str);
13132 +int str_toupper(char *str);
13133 +char *str_dup_safe(const char *str);
13134 +
13135 +#endif
13136 Index: busybox-1.8.1/archival/libipkg/user.c
13137 ===================================================================
13138 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13139 +++ busybox-1.8.1/archival/libipkg/user.c 2007-11-10 17:40:53.400766935 +0100
13140 @@ -0,0 +1,58 @@
13141 +/* user.c - the itsy package management system
13142 +
13143 + Jamey Hicks
13144 +
13145 + Copyright (C) 2002 Hewlett Packard Company
13146 + Copyright (C) 2001 University of Southern California
13147 +
13148 + This program is free software; you can redistribute it and/or
13149 + modify it under the terms of the GNU General Public License as
13150 + published by the Free Software Foundation; either version 2, or (at
13151 + your option) any later version.
13152 +
13153 + This program is distributed in the hope that it will be useful, but
13154 + WITHOUT ANY WARRANTY; without even the implied warranty of
13155 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13156 + General Public License for more details.
13157 +*/
13158 +
13159 +#include <stdio.h>
13160 +#include <stdarg.h>
13161 +#include "file_util.h"
13162 +#include "str_util.h"
13163 +#ifdef IPKG_LIB
13164 +#include "libipkg.h"
13165 +#endif
13166 +
13167 +
13168 +#ifdef IPKG_LIB
13169 +static char *question = NULL;
13170 +static int question_len = 255;
13171 +#endif
13172 +char *get_user_response(const char *format, ...)
13173 +{
13174 + int len = question_len;
13175 + va_list ap;
13176 + char *response;
13177 + va_start(ap, format);
13178 +
13179 +#ifndef IPKG_LIB
13180 + vprintf(format, ap);
13181 + do {
13182 + response = file_read_line_alloc(stdin);
13183 + } while (response == NULL);
13184 +#else
13185 + do {
13186 + if (question == NULL || len > question_len) {
13187 + question = realloc(question, len + 1);
13188 + question_len = len;
13189 + }
13190 + len = vsnprintf(question,question_len,format,ap);
13191 + } while (len > question_len);
13192 + response = strdup(ipkg_cb_response(question));
13193 +#endif
13194 + str_chomp(response);
13195 + str_tolower(response);
13196 +
13197 + return response;
13198 +}
13199 Index: busybox-1.8.1/archival/libipkg/user.h
13200 ===================================================================
13201 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13202 +++ busybox-1.8.1/archival/libipkg/user.h 2007-11-10 17:40:53.400766935 +0100
13203 @@ -0,0 +1,23 @@
13204 +/* user.c - the itsy package management system
13205 +
13206 + Jamey Hicks
13207 +
13208 + Copyright (C) 2002 Hewlett Packard Company
13209 + Copyright (C) 2001 University of Southern California
13210 +
13211 + This program is free software; you can redistribute it and/or
13212 + modify it under the terms of the GNU General Public License as
13213 + published by the Free Software Foundation; either version 2, or (at
13214 + your option) any later version.
13215 +
13216 + This program is distributed in the hope that it will be useful, but
13217 + WITHOUT ANY WARRANTY; without even the implied warranty of
13218 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13219 + General Public License for more details.
13220 +*/
13221 +
13222 +#include <stdio.h>
13223 +#include <stdarg.h>
13224 +
13225 +char *get_user_response(const char *format, ...);
13226 +
13227 Index: busybox-1.8.1/archival/libipkg/void_list.c
13228 ===================================================================
13229 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13230 +++ busybox-1.8.1/archival/libipkg/void_list.c 2007-11-10 17:40:53.404767161 +0100
13231 @@ -0,0 +1,194 @@
13232 +/* void_list.c - the itsy package management system
13233 +
13234 + Carl D. Worth
13235 +
13236 + Copyright (C) 2001 University of Southern California
13237 +
13238 + This program is free software; you can redistribute it and/or
13239 + modify it under the terms of the GNU General Public License as
13240 + published by the Free Software Foundation; either version 2, or (at
13241 + your option) any later version.
13242 +
13243 + This program is distributed in the hope that it will be useful, but
13244 + WITHOUT ANY WARRANTY; without even the implied warranty of
13245 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13246 + General Public License for more details.
13247 +*/
13248 +
13249 +#include "ipkg.h"
13250 +#include <errno.h>
13251 +
13252 +#include "void_list.h"
13253 +
13254 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13255 +{
13256 + elt->next = NULL;
13257 + elt->data = data;
13258 +
13259 + return 0;
13260 +}
13261 +
13262 +void void_list_elt_deinit(void_list_elt_t *elt)
13263 +{
13264 + void_list_elt_init(elt, NULL);
13265 +}
13266 +
13267 +int void_list_init(void_list_t *list)
13268 +{
13269 + void_list_elt_init(&list->pre_head, NULL);
13270 + list->head = NULL;
13271 + list->pre_head.next = list->head;
13272 + list->tail = NULL;
13273 +
13274 + return 0;
13275 +}
13276 +
13277 +void void_list_deinit(void_list_t *list)
13278 +{
13279 + void_list_elt_t *elt;
13280 +
13281 + while (list->head) {
13282 + elt = void_list_pop(list);
13283 + void_list_elt_deinit(elt);
13284 + /* malloced in void_list_append */
13285 + free(elt);
13286 + }
13287 +}
13288 +
13289 +int void_list_append(void_list_t *list, void *data)
13290 +{
13291 + void_list_elt_t *elt;
13292 +
13293 + /* freed in void_list_deinit */
13294 + elt = malloc(sizeof(void_list_elt_t));
13295 + if (elt == NULL) {
13296 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13297 + return ENOMEM;
13298 + }
13299 +
13300 + void_list_elt_init(elt, data);
13301 +
13302 + if (list->tail) {
13303 + list->tail->next = elt;
13304 + list->tail = elt;
13305 + } else {
13306 + list->head = elt;
13307 + list->pre_head.next = list->head;
13308 + list->tail = elt;
13309 + }
13310 +
13311 + return 0;
13312 +}
13313 +
13314 +int void_list_push(void_list_t *list, void *data)
13315 +{
13316 + void_list_elt_t *elt;
13317 +
13318 + elt = malloc(sizeof(void_list_elt_t));
13319 + if (elt == NULL) {
13320 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13321 + return ENOMEM;
13322 + }
13323 +
13324 + void_list_elt_init(elt, data);
13325 +
13326 + elt->next = list->head;
13327 + list->head->next = elt;
13328 + if (list->tail == NULL) {
13329 + list->tail = list->head;
13330 + }
13331 +
13332 + return 0;
13333 +}
13334 +
13335 +void_list_elt_t *void_list_pop(void_list_t *list)
13336 +{
13337 + void_list_elt_t *elt;
13338 +
13339 + elt = list->head;
13340 +
13341 + if (list->head) {
13342 + list->head = list->head->next;
13343 + list->pre_head.next = list->head;
13344 + if (list->head == NULL) {
13345 + list->tail = NULL;
13346 + }
13347 + }
13348 +
13349 + return elt;
13350 +}
13351 +
13352 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13353 +{
13354 + void_list_elt_t *prior;
13355 + void_list_elt_t *old_elt;
13356 + void *old_data;
13357 +
13358 + old_elt = *iter;
13359 + old_data = old_elt->data;
13360 +
13361 + if (old_elt == list->head) {
13362 + prior = &list->pre_head;
13363 + void_list_pop(list);
13364 + } else {
13365 + for (prior = list->head; prior; prior = prior->next) {
13366 + if (prior->next == old_elt) {
13367 + break;
13368 + }
13369 + }
13370 + if (prior == NULL || prior->next != old_elt) {
13371 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13372 + return NULL;
13373 + }
13374 + prior->next = old_elt->next;
13375 +
13376 + if (old_elt == list->tail) {
13377 + list->tail = prior;
13378 + }
13379 + }
13380 +
13381 + void_list_elt_deinit(old_elt);
13382 + *iter = prior;
13383 +
13384 + return old_data;
13385 +}
13386 +
13387 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13388 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13389 +{
13390 + void_list_elt_t *prior;
13391 + void_list_elt_t *old_elt = NULL;
13392 + void *old_data = NULL;
13393 +
13394 + /* first element */
13395 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13396 + old_elt = list->head;
13397 + old_data = list->head->data;
13398 + void_list_pop(list);
13399 + } else {
13400 + int found = 0;
13401 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13402 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13403 + old_elt = prior->next;
13404 + old_data = old_elt->data;
13405 + found = 1;
13406 + break;
13407 + }
13408 + }
13409 + if (!found) {
13410 + return NULL;
13411 + }
13412 + prior->next = old_elt->next;
13413 +
13414 + if (old_elt == list->tail) {
13415 + list->tail = prior;
13416 + }
13417 + }
13418 + if (old_elt)
13419 + void_list_elt_deinit(old_elt);
13420 +
13421 + if (old_data)
13422 + return old_data;
13423 + else
13424 + return NULL;
13425 +}
13426 Index: busybox-1.8.1/archival/libipkg/void_list.h
13427 ===================================================================
13428 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13429 +++ busybox-1.8.1/archival/libipkg/void_list.h 2007-11-10 17:40:53.404767161 +0100
13430 @@ -0,0 +1,59 @@
13431 +/* void_list.h - the itsy package management system
13432 +
13433 + Carl D. Worth
13434 +
13435 + Copyright (C) 2001 University of Southern California
13436 +
13437 + This program is free software; you can redistribute it and/or
13438 + modify it under the terms of the GNU General Public License as
13439 + published by the Free Software Foundation; either version 2, or (at
13440 + your option) any later version.
13441 +
13442 + This program is distributed in the hope that it will be useful, but
13443 + WITHOUT ANY WARRANTY; without even the implied warranty of
13444 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13445 + General Public License for more details.
13446 +*/
13447 +
13448 +#ifndef VOID_LIST_H
13449 +#define VOID_LIST_H
13450 +
13451 +typedef struct void_list_elt void_list_elt_t;
13452 +struct void_list_elt
13453 +{
13454 + void_list_elt_t *next;
13455 + void *data;
13456 +};
13457 +
13458 +typedef struct void_list void_list_t;
13459 +struct void_list
13460 +{
13461 + void_list_elt_t pre_head;
13462 + void_list_elt_t *head;
13463 + void_list_elt_t *tail;
13464 +};
13465 +
13466 +static inline int void_list_empty(void_list_t *list)
13467 +{
13468 + if (list->head == NULL)
13469 + return 1;
13470 + else
13471 + return 0;
13472 +}
13473 +
13474 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13475 +void void_list_elt_deinit(void_list_elt_t *elt);
13476 +
13477 +int void_list_init(void_list_t *list);
13478 +void void_list_deinit(void_list_t *list);
13479 +
13480 +int void_list_append(void_list_t *list, void *data);
13481 +int void_list_push(void_list_t *list, void *data);
13482 +void_list_elt_t *void_list_pop(void_list_t *list);
13483 +
13484 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13485 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13486 +typedef int (*void_list_cmp_t)(const void *, const void *);
13487 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13488 +
13489 +#endif
13490 Index: busybox-1.8.1/archival/libipkg/xsystem.c
13491 ===================================================================
13492 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13493 +++ busybox-1.8.1/archival/libipkg/xsystem.c 2007-11-10 17:40:53.404767161 +0100
13494 @@ -0,0 +1,64 @@
13495 +/* xsystem.c - system(3) with error messages
13496 +
13497 + Carl D. Worth
13498 +
13499 + Copyright (C) 2001 University of Southern California
13500 +
13501 + This program is free software; you can redistribute it and/or
13502 + modify it under the terms of the GNU General Public License as
13503 + published by the Free Software Foundation; either version 2, or (at
13504 + your option) any later version.
13505 +
13506 + This program is distributed in the hope that it will be useful, but
13507 + WITHOUT ANY WARRANTY; without even the implied warranty of
13508 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13509 + General Public License for more details.
13510 +*/
13511 +
13512 +#include "ipkg.h"
13513 +#include <sys/wait.h>
13514 +
13515 +#include "xsystem.h"
13516 +
13517 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13518 + really need the /bin/sh invocation which takes resources and
13519 + introduces security problems. I should switch all of this to a sort
13520 + of execl() or execv() interface/implementation.
13521 +*/
13522 +
13523 +/* Like system(3), but with error messages printed if the fork fails
13524 + or if the child process dies due to an uncaught signal. Also, the
13525 + return value is a bit simpler:
13526 +
13527 + -1 if there was any problem
13528 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13529 + as defined in <sys/wait.h>.
13530 +*/
13531 +int xsystem(const char *cmd)
13532 +{
13533 + int err;
13534 +
13535 + err = system(cmd);
13536 +
13537 + if (err == -1) {
13538 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13539 + __FUNCTION__, cmd);
13540 + return -1;
13541 + }
13542 +
13543 + if (WIFSIGNALED(err)) {
13544 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13545 + __FUNCTION__, WTERMSIG(err), cmd);
13546 + return -1;
13547 + }
13548 +
13549 + if (WIFEXITED(err)) {
13550 + /* Normal child exit */
13551 + return WEXITSTATUS(err);
13552 + }
13553 +
13554 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13555 + __FUNCTION__, err);
13556 + return -1;
13557 +}
13558 +
13559 Index: busybox-1.8.1/archival/libipkg/xsystem.h
13560 ===================================================================
13561 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13562 +++ busybox-1.8.1/archival/libipkg/xsystem.h 2007-11-10 17:40:53.404767161 +0100
13563 @@ -0,0 +1,34 @@
13564 +/* xsystem.h - system(3) with error messages
13565 +
13566 + Carl D. Worth
13567 +
13568 + Copyright (C) 2001 University of Southern California
13569 +
13570 + This program is free software; you can redistribute it and/or
13571 + modify it under the terms of the GNU General Public License as
13572 + published by the Free Software Foundation; either version 2, or (at
13573 + your option) any later version.
13574 +
13575 + This program is distributed in the hope that it will be useful, but
13576 + WITHOUT ANY WARRANTY; without even the implied warranty of
13577 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13578 + General Public License for more details.
13579 +*/
13580 +
13581 +#ifndef XSYSTEM_H
13582 +#define XSYSTEM_H
13583 +
13584 +#include <stdlib.h>
13585 +
13586 +/* Like system(3), but with error messages printed if the fork fails
13587 + or if the child process dies due to an uncaught signal. Also, the
13588 + return value is a bit simpler:
13589 +
13590 + -1 if there was any problem
13591 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13592 + as defined in <sys/wait.h>.
13593 +*/
13594 +int xsystem(const char *cmd);
13595 +
13596 +#endif
13597 +
13598 Index: busybox-1.8.1/archival/libunarchive/data_extract_all.c
13599 ===================================================================
13600 --- busybox-1.8.1.orig/archival/libunarchive/data_extract_all.c 2007-11-10 17:39:21.471528185 +0100
13601 +++ busybox-1.8.1/archival/libunarchive/data_extract_all.c 2007-11-10 17:40:53.404767161 +0100
13602 @@ -129,3 +129,17 @@
13603 }
13604 }
13605 }
13606 +
13607 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13608 +{
13609 + char *name_ptr = archive_handle->file_header->name;
13610 +
13611 + name_ptr += strspn(name_ptr, "./");
13612 + if (name_ptr[0] != '\0') {
13613 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13614 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13615 + strcat(archive_handle->file_header->name, name_ptr);
13616 + data_extract_all(archive_handle);
13617 + }
13618 +}
13619 +
13620 Index: busybox-1.8.1/archival/libunarchive/Kbuild
13621 ===================================================================
13622 --- busybox-1.8.1.orig/archival/libunarchive/Kbuild 2007-11-10 17:39:21.479528641 +0100
13623 +++ busybox-1.8.1/archival/libunarchive/Kbuild 2007-11-10 17:40:53.408767391 +0100
13624 @@ -54,6 +54,7 @@
13625 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13626 lib-$(CONFIG_GUNZIP) += decompress_unzip.o
13627 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13628 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13629 lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
13630 lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
13631 lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
13632 Index: busybox-1.8.1/include/applets.h
13633 ===================================================================
13634 --- busybox-1.8.1.orig/include/applets.h 2007-11-10 17:39:21.487529096 +0100
13635 +++ busybox-1.8.1/include/applets.h 2007-11-10 17:40:53.408767391 +0100
13636 @@ -198,6 +198,7 @@
13637 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13638 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13639 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13640 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13641 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13642 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13643 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13644 Index: busybox-1.8.1/include/unarchive.h
13645 ===================================================================
13646 --- busybox-1.8.1.orig/include/unarchive.h 2007-11-10 17:39:21.495529554 +0100
13647 +++ busybox-1.8.1/include/unarchive.h 2007-11-10 17:40:53.408767391 +0100
13648 @@ -74,6 +74,7 @@
13649
13650 extern void data_skip(archive_handle_t *archive_handle);
13651 extern void data_extract_all(archive_handle_t *archive_handle);
13652 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13653 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13654 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13655
13656 Index: busybox-1.8.1/include/usage.h
13657 ===================================================================
13658 --- busybox-1.8.1.orig/include/usage.h 2007-11-10 17:40:53.208755993 +0100
13659 +++ busybox-1.8.1/include/usage.h 2007-11-10 17:40:53.412767617 +0100
13660 @@ -1294,6 +1294,82 @@
13661 "$ ls -la /tmp/busybox*\n" \
13662 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13663
13664 +#define ipkg_trivial_usage \
13665 + "[options]... sub-command [arguments]..."
13666 +#define ipkg_full_usage \
13667 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13668 + "\n" \
13669 + "Sub-commands:\n" \
13670 + "\nPackage Manipulation:\n" \
13671 + "\tupdate Update list of available packages\n" \
13672 + "\tupgrade Upgrade all installed packages to latest version\n" \
13673 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13674 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13675 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13676 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13677 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13678 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13679 + "\n" \
13680 + "Informational Commands:\n" \
13681 + "\tlist List available packages and descriptions\n" \
13682 + "\tlist_installed List all and only the installed packages and description \n" \
13683 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13684 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13685 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13686 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13687 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13688 + "\tcompare_versions <v1> <op> <v2>\n" \
13689 + "\t compare versions using <= < > >= = << >>\n" \
13690 + "\tprint_architecture prints the architecture.\n" \
13691 + "\tprint_installation_architecture\n" \
13692 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13693 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13694 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13695 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13696 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13697 + "\t prints the installation architecture.\n" \
13698 + "\n" \
13699 + "\nOptions:\n" \
13700 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13701 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13702 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13703 + "\t 0 errors only\n" \
13704 + "\t 1 normal messages (default)\n" \
13705 + "\t 2 informative messages\n" \
13706 + "\t 3 debug output\n" \
13707 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13708 + "\t-conf <conf_file> Default configuration file location\n" \
13709 + " is /etc/ipkg.conf\n" \
13710 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13711 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13712 + " <dest_name> should be a defined dest name from\n" \
13713 + " the configuration file, (but can also be a\n" \
13714 + " directory name in a pinch).\n" \
13715 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13716 + "\t-offline <offline_root> offline installation of packages.\n" \
13717 + "\t-verbose_wget more wget messages\n" \
13718 + "\n" \
13719 + "Force Options (use when ipkg is too smart for its own good):\n" \
13720 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13721 + "\t Install/remove package in spite of failed dependences\n" \
13722 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13723 + " (no prompts). Note that this will not prevent\n" \
13724 + " package installation scripts from prompting.\n" \
13725 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13726 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13727 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13728 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13729 + "\t-noaction No action -- test only\n" \
13730 + "\t-nodeps Do not follow dependences\n" \
13731 + "\t-force-removal-of-dependent-packages\n" \
13732 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13733 + "\t-test No action -- test only\n" \
13734 + "\t-t Specify tmp-dir.\n" \
13735 + "\t--tmp-dir Specify tmp-dir.\n" \
13736 + "\n" \
13737 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13738 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13739 +
13740 #define halt_trivial_usage \
13741 "[-d delay] [-n] [-f]"
13742 #define halt_full_usage \
13743 Index: busybox-1.8.1/Makefile
13744 ===================================================================
13745 --- busybox-1.8.1.orig/Makefile 2007-11-10 17:39:21.511530465 +0100
13746 +++ busybox-1.8.1/Makefile 2007-11-10 17:40:53.412767617 +0100
13747 @@ -428,6 +428,7 @@
13748
13749 libs-y := \
13750 archival/ \
13751 + archival/libipkg/ \
13752 archival/libunarchive/ \
13753 console-tools/ \
13754 coreutils/ \
This page took 0.637107 seconds and 5 git commands to generate.