refresh busybox patches
[openwrt/svn-archive/archive.git] / package / busybox / patches / 500-ipkg.patch
1 Index: busybox-1.7.2/archival/Config.in
2 ===================================================================
3 --- busybox-1.7.2.orig/archival/Config.in 2007-10-30 15:34:59.000000000 -0500
4 +++ busybox-1.7.2/archival/Config.in 2007-10-30 15:35:05.000000000 -0500
5 @@ -121,6 +121,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.7.2/archival/dpkg.c
22 ===================================================================
23 --- busybox-1.7.2.orig/archival/dpkg.c 2007-10-30 15:34:59.000000000 -0500
24 +++ busybox-1.7.2/archival/dpkg.c 2007-10-30 15:35:05.000000000 -0500
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.7.2/archival/ipkg.c
46 ===================================================================
47 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
48 +++ busybox-1.7.2/archival/ipkg.c 2007-10-30 15:35:05.000000000 -0500
49 @@ -0,0 +1,26 @@
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 +
70 +#include "libipkg/libipkg.h"
71 +
72 +int ipkg_main(int argc, char **argv)
73 +{
74 + return ipkg_op(argc, argv);
75 +}
76 Index: busybox-1.7.2/archival/Kbuild
77 ===================================================================
78 --- busybox-1.7.2.orig/archival/Kbuild 2007-10-30 15:34:59.000000000 -0500
79 +++ busybox-1.7.2/archival/Kbuild 2007-10-30 15:35:05.000000000 -0500
80 @@ -15,6 +15,7 @@
81 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
82 lib-$(CONFIG_GUNZIP) += bbunzip.o
83 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
84 +lib-$(CONFIG_IPKG) += ipkg.o
85 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
86 lib-$(CONFIG_RPM) += rpm.o
87 lib-$(CONFIG_TAR) += tar.o
88 Index: busybox-1.7.2/archival/libipkg/args.c
89 ===================================================================
90 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
91 +++ busybox-1.7.2/archival/libipkg/args.c 2007-10-30 15:35:05.000000000 -0500
92 @@ -0,0 +1,242 @@
93 +/* args.c - parse command-line args
94 +
95 + Carl D. Worth
96 +
97 + Copyright 2001 University of Southern California
98 +
99 + This program is free software; you can redistribute it and/or modify
100 + it under the terms of the GNU General Public License as published by
101 + the Free Software Foundation; either version 2, or (at your option)
102 + any later version.
103 +
104 + This program is distributed in the hope that it will be useful,
105 + but WITHOUT ANY WARRANTY; without even the implied warranty of
106 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107 + GNU General Public License for more details.
108 + */
109 +
110 +#include <getopt.h>
111 +#include <stdlib.h>
112 +#include <string.h>
113 +#include <unistd.h>
114 +
115 +#include "ipkg.h"
116 +#include "ipkg_message.h"
117 +
118 +#include "args.h"
119 +#include "sprintf_alloc.h"
120 +
121 +#include "libbb.h"
122 +
123 +
124 +static void print_version(void);
125 +
126 +enum long_args_opt
127 +{
128 + ARGS_OPT_FORCE_DEFAULTS = 129,
129 + ARGS_OPT_FORCE_DEPENDS,
130 + ARGS_OPT_FORCE_OVERWRITE,
131 + ARGS_OPT_FORCE_DOWNGRADE,
132 + ARGS_OPT_FORCE_REINSTALL,
133 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
134 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
135 + ARGS_OPT_FORCE_SPACE,
136 + ARGS_OPT_NOACTION,
137 + ARGS_OPT_NODEPS,
138 + ARGS_OPT_VERBOSE_WGET,
139 + ARGS_OPT_VERBOSITY,
140 + ARGS_OPT_MULTIPLE_PROVIDERS
141 +};
142 +
143 +int args_init(args_t *args)
144 +{
145 + char *conf_file_dir;
146 +
147 + memset(args, 0, sizeof(args_t));
148 +
149 + args->dest = ARGS_DEFAULT_DEST;
150 +
151 + conf_file_dir = getenv("IPKG_CONF_DIR");
152 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
153 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
154 + }
155 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
156 + ARGS_DEFAULT_CONF_FILE_NAME);
157 +
158 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
159 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
160 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
161 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
162 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
163 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
164 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
165 + args->noaction = ARGS_DEFAULT_NOACTION;
166 + args->nodeps = ARGS_DEFAULT_NODEPS;
167 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
168 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
169 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
170 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
171 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
172 + args->multiple_providers = 0;
173 + args->nocheckfordirorfile = 0;
174 + args->noreadfeedsfile = 0;
175 +
176 + return 1;
177 +}
178 +
179 +void args_deinit(args_t *args)
180 +{
181 + free(args->conf_file);
182 + args->conf_file = NULL;
183 +}
184 +
185 +int args_parse(args_t *args, int argc, char *argv[])
186 +{
187 + int c;
188 + int option_index = 0;
189 + int parse_err = 0;
190 + static struct option long_options[] = {
191 + {"query-all", 0, 0, 'A'},
192 + {"conf-file", 1, 0, 'f'},
193 + {"conf", 1, 0, 'f'},
194 + {"dest", 1, 0, 'd'},
195 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
196 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
197 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
198 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
199 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
200 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
201 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
202 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
203 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
204 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
205 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
206 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
207 + {"recursive", 0, 0,
208 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
209 + {"force-removal-of-dependent-packages", 0, 0,
210 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
211 + {"force_removal_of_dependent_packages", 0, 0,
212 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
213 + {"force-removal-of-essential-packages", 0, 0,
214 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
215 + {"force_removal_of_essential_packages", 0, 0,
216 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
217 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
218 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
219 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
220 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
221 + {"offline", 1, 0, 'o'},
222 + {"offline-root", 1, 0, 'o'},
223 + {"test", 0, 0, ARGS_OPT_NOACTION},
224 + {"tmp-dir", 1, 0, 't'},
225 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
226 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
227 + {"verbosity", 2, 0, 'V'},
228 + {"version", 0, 0, 'v'},
229 + {0, 0, 0, 0}
230 + };
231 +
232 + while (1) {
233 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
234 + if (c == -1)
235 + break;
236 +
237 + switch (c) {
238 + case 'A':
239 + args->query_all = 1;
240 + break;
241 + case 'd':
242 + args->dest = optarg;
243 + break;
244 + case 'f':
245 + free(args->conf_file);
246 + args->conf_file = strdup(optarg);
247 + break;
248 + case 'o':
249 + args->offline_root = optarg;
250 + break;
251 + case 'n':
252 + args->noaction = 1;
253 + break;
254 + case 't':
255 + args->tmp_dir = strdup(optarg);
256 + break;
257 + case 'v':
258 + print_version();
259 + exit(0);
260 + case 'V':
261 + case ARGS_OPT_VERBOSITY:
262 + if (optarg)
263 + args->verbosity = atoi(optarg);
264 + else
265 + args->verbosity += 1;
266 + break;
267 + case ARGS_OPT_FORCE_DEFAULTS:
268 + args->force_defaults = 1;
269 + break;
270 + case ARGS_OPT_FORCE_DEPENDS:
271 + args->force_depends = 1;
272 + break;
273 + case ARGS_OPT_FORCE_OVERWRITE:
274 + args->force_overwrite = 1;
275 + break;
276 + case ARGS_OPT_FORCE_DOWNGRADE:
277 + args->force_downgrade = 1;
278 + break;
279 + case ARGS_OPT_FORCE_REINSTALL:
280 + args->force_reinstall = 1;
281 + break;
282 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
283 + args->force_removal_of_essential_packages = 1;
284 + break;
285 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
286 + args->force_removal_of_dependent_packages = 1;
287 + break;
288 + case ARGS_OPT_FORCE_SPACE:
289 + args->force_space = 1;
290 + break;
291 + case ARGS_OPT_VERBOSE_WGET:
292 + args->verbose_wget = 1;
293 + break;
294 + case ARGS_OPT_MULTIPLE_PROVIDERS:
295 + args->multiple_providers = 1;
296 + break;
297 + case ARGS_OPT_NODEPS:
298 + args->nodeps = 1;
299 + break;
300 + case ARGS_OPT_NOACTION:
301 + args->noaction = 1;
302 + break;
303 + case ':':
304 + parse_err++;
305 + break;
306 + case '?':
307 + parse_err++;
308 + break;
309 + default:
310 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
311 + }
312 + }
313 +
314 + if (parse_err) {
315 + return -parse_err;
316 + } else {
317 + return optind;
318 + }
319 +}
320 +
321 +void args_usage(char *complaint)
322 +{
323 + if (complaint) {
324 + bb_error_msg("%s\n", complaint);
325 + }
326 + print_version();
327 + bb_show_usage();
328 + exit(1);
329 +}
330 +
331 +static void print_version(void)
332 +{
333 + bb_error_msg("version %s\n", IPKG_VERSION);
334 +}
335 Index: busybox-1.7.2/archival/libipkg/args.h
336 ===================================================================
337 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
338 +++ busybox-1.7.2/archival/libipkg/args.h 2007-10-30 15:35:05.000000000 -0500
339 @@ -0,0 +1,72 @@
340 +/* args.h - parse command-line args
341 +
342 + Carl D. Worth
343 +
344 + Copyright 2001 University of Southern California
345 +
346 + This program is free software; you can redistribute it and/or modify
347 + it under the terms of the GNU General Public License as published by
348 + the Free Software Foundation; either version 2, or (at your option)
349 + any later version.
350 +
351 + This program is distributed in the hope that it will be useful,
352 + but WITHOUT ANY WARRANTY; without even the implied warranty of
353 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
354 + GNU General Public License for more details.
355 +*/
356 +
357 +#ifndef ARGS_H
358 +#define ARGS_H
359 +
360 +struct args
361 +{
362 + char *conf_file;
363 + char *dest;
364 + char *tmp_dir;
365 + int force_defaults;
366 + int force_depends;
367 + int force_overwrite;
368 + int force_downgrade;
369 + int force_reinstall;
370 + int force_removal_of_essential_packages;
371 + int force_removal_of_dependent_packages;
372 + int force_space;
373 + int noaction;
374 + int nodeps;
375 + int multiple_providers;
376 + int query_all;
377 + int verbose_wget;
378 + int verbosity;
379 + int nocheckfordirorfile;
380 + int noreadfeedsfile;
381 + char *offline_root;
382 + char *offline_root_pre_script_cmd;
383 + char *offline_root_post_script_cmd;
384 +};
385 +typedef struct args args_t;
386 +
387 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
388 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
389 +#define ARGS_DEFAULT_DEST NULL
390 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
391 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
392 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
393 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
394 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
395 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
396 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
397 +#define ARGS_DEFAULT_FORCE_SPACE 0
398 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
399 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
400 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
401 +#define ARGS_DEFAULT_NOACTION 0
402 +#define ARGS_DEFAULT_NODEPS 0
403 +#define ARGS_DEFAULT_VERBOSE_WGET 0
404 +#define ARGS_DEFAULT_VERBOSITY 1
405 +
406 +int args_init(args_t *args);
407 +void args_deinit(args_t *args);
408 +int args_parse(args_t *args, int argc, char *argv[]);
409 +void args_usage(char *complaint);
410 +
411 +#endif
412 Index: busybox-1.7.2/archival/libipkg/conffile.c
413 ===================================================================
414 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
415 +++ busybox-1.7.2/archival/libipkg/conffile.c 2007-10-30 15:35:05.000000000 -0500
416 @@ -0,0 +1,64 @@
417 +/* conffile.c - the itsy package management system
418 +
419 + Carl D. Worth
420 +
421 + Copyright (C) 2001 University of Southern California
422 +
423 + This program is free software; you can redistribute it and/or
424 + modify it under the terms of the GNU General Public License as
425 + published by the Free Software Foundation; either version 2, or (at
426 + your option) any later version.
427 +
428 + This program is distributed in the hope that it will be useful, but
429 + WITHOUT ANY WARRANTY; without even the implied warranty of
430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
431 + General Public License for more details.
432 +*/
433 +
434 +#include <string.h>
435 +#include <stdlib.h>
436 +
437 +#include "ipkg.h"
438 +#include "ipkg_message.h"
439 +
440 +#include "conffile.h"
441 +#include "file_util.h"
442 +#include "sprintf_alloc.h"
443 +
444 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
445 +{
446 + return nv_pair_init(conffile, file_name, md5sum);
447 +}
448 +
449 +void conffile_deinit(conffile_t *conffile)
450 +{
451 + nv_pair_deinit(conffile);
452 +}
453 +
454 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
455 +{
456 + char *md5sum;
457 + char *filename = conffile->name;
458 + char *root_filename;
459 + int ret;
460 +
461 + if (conffile->value == NULL) {
462 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
463 + return 1;
464 + }
465 +
466 + root_filename = root_filename_alloc(conf, filename);
467 +
468 + md5sum = file_md5sum_alloc(root_filename);
469 +
470 + ret = strcmp(md5sum, conffile->value);
471 + if (ret) {
472 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
473 + conffile->name, md5sum, conffile->value);
474 + }
475 +
476 + free(root_filename);
477 + free(md5sum);
478 +
479 + return ret;
480 +}
481 Index: busybox-1.7.2/archival/libipkg/conffile.h
482 ===================================================================
483 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
484 +++ busybox-1.7.2/archival/libipkg/conffile.h 2007-10-30 15:35:05.000000000 -0500
485 @@ -0,0 +1,30 @@
486 +/* conffile.h - the itsy package management system
487 +
488 + Carl D. Worth
489 +
490 + Copyright (C) 2001 University of Southern California
491 +
492 + This program is free software; you can redistribute it and/or
493 + modify it under the terms of the GNU General Public License as
494 + published by the Free Software Foundation; either version 2, or (at
495 + your option) any later version.
496 +
497 + This program is distributed in the hope that it will be useful, but
498 + WITHOUT ANY WARRANTY; without even the implied warranty of
499 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
500 + General Public License for more details.
501 +*/
502 +
503 +#ifndef CONFFILE_H
504 +#define CONFFILE_H
505 +
506 +#include "nv_pair.h"
507 +
508 +typedef struct nv_pair conffile_t;
509 +
510 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
511 +void conffile_deinit(conffile_t *conffile);
512 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
513 +
514 +#endif
515 +
516 Index: busybox-1.7.2/archival/libipkg/conffile_list.c
517 ===================================================================
518 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
519 +++ busybox-1.7.2/archival/libipkg/conffile_list.c 2007-10-30 15:35:05.000000000 -0500
520 @@ -0,0 +1,47 @@
521 +/* conffile_list.c - the itsy package management system
522 +
523 + Carl D. Worth
524 +
525 + Copyright (C) 2001 University of Southern California
526 +
527 + This program is free software; you can redistribute it and/or
528 + modify it under the terms of the GNU General Public License as
529 + published by the Free Software Foundation; either version 2, or (at
530 + your option) any later version.
531 +
532 + This program is distributed in the hope that it will be useful, but
533 + WITHOUT ANY WARRANTY; without even the implied warranty of
534 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
535 + General Public License for more details.
536 +*/
537 +
538 +#include "ipkg.h"
539 +
540 +#include "conffile_list.h"
541 +
542 +int conffile_list_init(conffile_list_t *list)
543 +{
544 + return nv_pair_list_init(list);
545 +}
546 +
547 +void conffile_list_deinit(conffile_list_t *list)
548 +{
549 + nv_pair_list_deinit(list);
550 +}
551 +
552 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
553 + const char *md5sum)
554 +{
555 + return nv_pair_list_append(list, file_name, md5sum);
556 +}
557 +
558 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
559 +{
560 + return nv_pair_list_push(list, data);
561 +}
562 +
563 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
564 +{
565 + return nv_pair_list_pop(list);
566 +}
567 +
568 Index: busybox-1.7.2/archival/libipkg/conffile_list.h
569 ===================================================================
570 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
571 +++ busybox-1.7.2/archival/libipkg/conffile_list.h 2007-10-30 15:35:05.000000000 -0500
572 @@ -0,0 +1,36 @@
573 +/* conffile_list.h - the itsy package management system
574 +
575 + Carl D. Worth
576 +
577 + Copyright (C) 2001 University of Southern California
578 +
579 + This program is free software; you can redistribute it and/or
580 + modify it under the terms of the GNU General Public License as
581 + published by the Free Software Foundation; either version 2, or (at
582 + your option) any later version.
583 +
584 + This program is distributed in the hope that it will be useful, but
585 + WITHOUT ANY WARRANTY; without even the implied warranty of
586 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
587 + General Public License for more details.
588 +*/
589 +
590 +#ifndef CONFFILE_LIST_H
591 +#define CONFFILE_LIST_H
592 +
593 +#include "conffile.h"
594 +#include "nv_pair_list.h"
595 +
596 +typedef struct nv_pair_list_elt conffile_list_elt_t;
597 +typedef struct nv_pair_list conffile_list_t;
598 +
599 +int conffile_list_init(conffile_list_t *list);
600 +void conffile_list_deinit(conffile_list_t *list);
601 +
602 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
603 + const char *root_dir);
604 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
605 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
606 +
607 +#endif
608 +
609 Index: busybox-1.7.2/archival/libipkg/file_util.c
610 ===================================================================
611 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
612 +++ busybox-1.7.2/archival/libipkg/file_util.c 2007-10-30 15:35:05.000000000 -0500
613 @@ -0,0 +1,132 @@
614 +/* file_util.c - convenience routines for common stat operations
615 +
616 + Carl D. Worth
617 +
618 + Copyright (C) 2001 University of Southern California
619 +
620 + This program is free software; you can redistribute it and/or
621 + modify it under the terms of the GNU General Public License as
622 + published by the Free Software Foundation; either version 2, or (at
623 + your option) any later version.
624 +
625 + This program is distributed in the hope that it will be useful, but
626 + WITHOUT ANY WARRANTY; without even the implied warranty of
627 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
628 + General Public License for more details.
629 +*/
630 +
631 +#include "ipkg.h"
632 +#include <sys/types.h>
633 +#include <sys/stat.h>
634 +
635 +#include "sprintf_alloc.h"
636 +#include "file_util.h"
637 +#include "libbb.h"
638 +#undef strlen
639 +
640 +int file_exists(const char *file_name)
641 +{
642 + int err;
643 + struct stat stat_buf;
644 +
645 + err = stat(file_name, &stat_buf);
646 + if (err == 0) {
647 + return 1;
648 + } else {
649 + return 0;
650 + }
651 +}
652 +
653 +int file_is_dir(const char *file_name)
654 +{
655 + int err;
656 + struct stat stat_buf;
657 +
658 + err = stat(file_name, &stat_buf);
659 + if (err) {
660 + return 0;
661 + }
662 +
663 + return S_ISDIR(stat_buf.st_mode);
664 +}
665 +
666 +/* read a single line from a file, stopping at a newline or EOF.
667 + If a newline is read, it will appear in the resulting string.
668 + Return value is a malloc'ed char * which should be freed at
669 + some point by the caller.
670 +
671 + Return value is NULL if the file is at EOF when called.
672 +*/
673 +#define FILE_READ_LINE_BUF_SIZE 1024
674 +char *file_read_line_alloc(FILE *file)
675 +{
676 + char buf[FILE_READ_LINE_BUF_SIZE];
677 + int buf_len;
678 + char *line = NULL;
679 + int line_size = 0;
680 +
681 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
682 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
683 + buf_len = strlen(buf);
684 + if (line) {
685 + line_size += buf_len;
686 + line = realloc(line, line_size);
687 + if (line == NULL) {
688 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
689 + break;
690 + }
691 + strcat(line, buf);
692 + } else {
693 + line_size = buf_len + 1;
694 + line = strdup(buf);
695 + }
696 + if (buf[buf_len - 1] == '\n') {
697 + break;
698 + }
699 + }
700 +
701 + return line;
702 +}
703 +
704 +int file_move(const char *src, const char *dest)
705 +{
706 + int err;
707 +
708 + err = rename(src, dest);
709 +
710 + if (err && errno == EXDEV) {
711 + err = file_copy(src, dest);
712 + unlink(src);
713 + } else if (err) {
714 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
715 + __FUNCTION__, src, dest, strerror(errno));
716 + }
717 +
718 + return err;
719 +}
720 +
721 +/* I put these here to keep libbb dependencies from creeping all over
722 + the ipkg code */
723 +int file_copy(const char *src, const char *dest)
724 +{
725 + int err;
726 +
727 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
728 + if (err) {
729 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
730 + __FUNCTION__, src, dest);
731 + }
732 +
733 + return err;
734 +}
735 +
736 +int file_mkdir_hier(const char *path, long mode)
737 +{
738 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
739 +}
740 +
741 +char *file_md5sum_alloc(const char *file_name)
742 +{
743 + return hash_file(file_name, HASH_MD5);
744 +}
745 +
746 Index: busybox-1.7.2/archival/libipkg/file_util.h
747 ===================================================================
748 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
749 +++ busybox-1.7.2/archival/libipkg/file_util.h 2007-10-30 15:35:05.000000000 -0500
750 @@ -0,0 +1,29 @@
751 +/* file_util.h - convenience routines for common file operations
752 +
753 + Carl D. Worth
754 +
755 + Copyright (C) 2001 University of Southern California
756 +
757 + This program is free software; you can redistribute it and/or
758 + modify it under the terms of the GNU General Public License as
759 + published by the Free Software Foundation; either version 2, or (at
760 + your option) any later version.
761 +
762 + This program is distributed in the hope that it will be useful, but
763 + WITHOUT ANY WARRANTY; without even the implied warranty of
764 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
765 + General Public License for more details.
766 +*/
767 +
768 +#ifndef FILE_UTIL_H
769 +#define FILE_UTIL_H
770 +
771 +int file_exists(const char *file_name);
772 +int file_is_dir(const char *file_name);
773 +char *file_read_line_alloc(FILE *file);
774 +int file_move(const char *src, const char *dest);
775 +int file_copy(const char *src, const char *dest);
776 +int file_mkdir_hier(const char *path, long mode);
777 +char *file_md5sum_alloc(const char *file_name);
778 +
779 +#endif
780 Index: busybox-1.7.2/archival/libipkg/hash_table.c
781 ===================================================================
782 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
783 +++ busybox-1.7.2/archival/libipkg/hash_table.c 2007-10-30 15:35:05.000000000 -0500
784 @@ -0,0 +1,155 @@
785 +/* hash.c - hash tables for ipkg
786 +
787 + Steven M. Ayer, Jamey Hicks
788 +
789 + Copyright (C) 2002 Compaq Computer Corporation
790 +
791 + This program is free software; you can redistribute it and/or
792 + modify it under the terms of the GNU General Public License as
793 + published by the Free Software Foundation; either version 2, or (at
794 + your option) any later version.
795 +
796 + This program is distributed in the hope that it will be useful, but
797 + WITHOUT ANY WARRANTY; without even the implied warranty of
798 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
799 + General Public License for more details.
800 +*/
801 +
802 +#include <errno.h>
803 +#include <stdio.h>
804 +#include <stdlib.h>
805 +#include <string.h>
806 +#include "hash_table.h"
807 +#include "ipkg_message.h"
808 +
809 +
810 +static int hash_index(hash_table_t *hash, const char *pkg_name);
811 +static int rotating(const char *key, int len, int prime);
812 +
813 +static int hash_index(hash_table_t *hash, const char *pkg_name)
814 +{
815 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
816 +}
817 +
818 +static int rotating(const char *key, int len, int prime)
819 +{
820 + unsigned int hash, i;
821 + for (hash=len, i=0; i<len; ++i)
822 + hash = (hash<<4)^(hash>>28)^key[i];
823 + return (hash % prime);
824 +}
825 +
826 +
827 +/*
828 + * this is an open table keyed by strings
829 + */
830 +int hash_table_init(const char *name, hash_table_t *hash, int len)
831 +{
832 + static int primes_table[] = {
833 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
834 + 19471, 23143, 33961, 46499, 49727, 99529, 0
835 + };
836 + int *picker;
837 +
838 + if (hash->entries != NULL) {
839 + /* we have been here already */
840 + return 0;
841 + }
842 +
843 + hash->name = name;
844 + hash->entries = NULL;
845 + hash->n_entries = 0;
846 + hash->hash_entry_key = NULL;
847 +
848 + picker = primes_table;
849 + while(*picker && (*picker++ < len));
850 + if(!*picker)
851 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
852 + --picker;
853 +
854 + hash->n_entries = *picker;
855 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
856 + if (hash->entries == NULL) {
857 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
858 + return ENOMEM;
859 + }
860 + return 0;
861 +}
862 +
863 +void hash_table_deinit(hash_table_t *hash)
864 +{
865 + free(hash->entries);
866 + hash->entries = NULL;
867 + hash->n_entries = 0;
868 +}
869 +
870 +void *hash_table_get(hash_table_t *hash, const char *key)
871 +{
872 + int ndx= hash_index(hash, key);
873 + hash_entry_t *hash_entry = hash->entries + ndx;
874 + while (hash_entry)
875 + {
876 + if (hash_entry->key)
877 + {
878 + if (strcmp(key, hash_entry->key) == 0) {
879 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
880 + return hash_entry->data;
881 + }
882 + }
883 + hash_entry = hash_entry->next;
884 + }
885 + return NULL;
886 +}
887 +
888 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
889 +{
890 + int ndx= hash_index(hash, key);
891 + hash_entry_t *hash_entry = hash->entries + ndx;
892 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
893 + if (hash_entry->key) {
894 + if (strcmp(hash_entry->key, key) == 0) {
895 + /* alread in table, update the value */
896 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
897 + hash_entry->data = value;
898 + return 0;
899 + } else {
900 + /*
901 + * if this is a collision, we have to go to the end of the ll,
902 + * then add a new entry
903 + * before we can hook up the value
904 + */
905 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
906 + while (hash_entry->next)
907 + hash_entry = hash_entry->next;
908 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
909 + if (!hash_entry->next) {
910 + return -ENOMEM;
911 + }
912 + hash_entry = hash_entry->next;
913 + hash_entry->next = NULL;
914 + }
915 + }
916 + hash->n_elements++;
917 + hash_entry->key = strdup(key);
918 + hash_entry->data = value;
919 +
920 + return 0;
921 +}
922 +
923 +
924 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
925 +{
926 + int i;
927 + if (!hash || !f)
928 + return;
929 +
930 + for (i = 0; i < hash->n_entries; i++) {
931 + hash_entry_t *hash_entry = (hash->entries + i);
932 + do {
933 + if(hash_entry->key) {
934 + f(hash_entry->key, hash_entry->data, data);
935 + }
936 + } while((hash_entry = hash_entry->next));
937 + }
938 +}
939 +
940 Index: busybox-1.7.2/archival/libipkg/hash_table.h
941 ===================================================================
942 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
943 +++ busybox-1.7.2/archival/libipkg/hash_table.h 2007-10-30 15:35:05.000000000 -0500
944 @@ -0,0 +1,44 @@
945 +/* hash.h - hash tables for ipkg
946 +
947 + Steven M. Ayer, Jamey Hicks
948 +
949 + Copyright (C) 2002 Compaq Computer Corporation
950 +
951 + This program is free software; you can redistribute it and/or
952 + modify it under the terms of the GNU General Public License as
953 + published by the Free Software Foundation; either version 2, or (at
954 + your option) any later version.
955 +
956 + This program is distributed in the hope that it will be useful, but
957 + WITHOUT ANY WARRANTY; without even the implied warranty of
958 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
959 + General Public License for more details.
960 +*/
961 +
962 +#ifndef _HASH_TABLE_H_
963 +#define _HASH_TABLE_H_
964 +
965 +typedef struct hash_entry hash_entry_t;
966 +typedef struct hash_table hash_table_t;
967 +
968 +struct hash_entry {
969 + const char * key;
970 + void * data;
971 + struct hash_entry * next;
972 +};
973 +
974 +struct hash_table {
975 + const char *name;
976 + hash_entry_t * entries;
977 + int n_entries; /* number of buckets */
978 + int n_elements;
979 + const char * (*hash_entry_key)(void * data);
980 +};
981 +
982 +int hash_table_init(const char *name, hash_table_t *hash, int len);
983 +void hash_table_deinit(hash_table_t *hash);
984 +void *hash_table_get(hash_table_t *hash, const char *key);
985 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
986 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
987 +
988 +#endif /* _HASH_TABLE_H_ */
989 Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.c
990 ===================================================================
991 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
992 +++ busybox-1.7.2/archival/libipkg/ipkg_cmd.c 2007-10-30 15:35:05.000000000 -0500
993 @@ -0,0 +1,1431 @@
994 +/* ipkg_cmd.c - the itsy package management system
995 +
996 + Carl D. Worth
997 +
998 + Copyright (C) 2001 University of Southern California
999 +
1000 + This program is free software; you can redistribute it and/or
1001 + modify it under the terms of the GNU General Public License as
1002 + published by the Free Software Foundation; either version 2, or (at
1003 + your option) any later version.
1004 +
1005 + This program is distributed in the hope that it will be useful, but
1006 + WITHOUT ANY WARRANTY; without even the implied warranty of
1007 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1008 + General Public License for more details.
1009 +*/
1010 +
1011 +#include <string.h>
1012 +
1013 +#include "ipkg.h"
1014 +#include <libgen.h>
1015 +#include <glob.h>
1016 +#include <errno.h>
1017 +#include <stdlib.h>
1018 +#include <unistd.h>
1019 +#include <signal.h>
1020 +#include <stdio.h>
1021 +#include <dirent.h>
1022 +
1023 +#include "ipkg_conf.h"
1024 +#include "ipkg_cmd.h"
1025 +#include "ipkg_message.h"
1026 +#include "pkg.h"
1027 +#include "pkg_dest.h"
1028 +#include "pkg_parse.h"
1029 +#include "sprintf_alloc.h"
1030 +#include "pkg.h"
1031 +#include "file_util.h"
1032 +#include "str_util.h"
1033 +#include "libbb.h"
1034 +#include "unarchive.h"
1035 +
1036 +#include <fnmatch.h>
1037 +
1038 +
1039 +#include "ipkg_download.h"
1040 +#include "ipkg_install.h"
1041 +#include "ipkg_upgrade.h"
1042 +#include "ipkg_remove.h"
1043 +#include "ipkg_configure.h"
1044 +#include "ipkg_message.h"
1045 +
1046 +#ifdef IPKG_LIB
1047 +#include "libipkg.h"
1048 +static void *p_userdata = NULL;
1049 +#endif
1050 +
1051 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1052 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1076 +
1077 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1078 + array for easier maintenance */
1079 +static ipkg_cmd_t cmds[] = {
1080 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1081 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1082 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1083 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1084 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1085 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1086 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1087 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1088 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1089 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1090 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1091 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1092 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1093 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1094 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1095 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1096 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1097 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1098 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1101 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1102 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1103 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1104 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1105 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1106 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1107 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1108 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1109 +};
1110 +
1111 +int ipkg_state_changed;
1112 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1113 +{
1114 + if (ipkg_state_changed && !conf->noaction) {
1115 + ipkg_message(conf, IPKG_INFO,
1116 + " writing status file\n");
1117 + ipkg_conf_write_status_files(conf);
1118 + pkg_write_changed_filelists(conf);
1119 + } else {
1120 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1121 + }
1122 +}
1123 +
1124 +
1125 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1126 +
1127 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1128 +{
1129 + int i;
1130 + ipkg_cmd_t *cmd;
1131 +
1132 + for (i=0; i < num_cmds; i++) {
1133 + cmd = &cmds[i];
1134 + if (strcmp(name, cmd->name) == 0) {
1135 + return cmd;
1136 + }
1137 + }
1138 +
1139 + return NULL;
1140 +}
1141 +
1142 +#ifdef IPKG_LIB
1143 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1144 +{
1145 + int result;
1146 + p_userdata = userdata;
1147 +
1148 +
1149 + result = (cmd->fun)(conf, argc, argv);
1150 + if ( result == 0 ) {
1151 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1152 + } else {
1153 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1154 +
1155 + }
1156 + if ( error_list ) {
1157 + reverse_error_list(&error_list);
1158 +
1159 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1160 + /* Here we print the errors collected and free the list */
1161 + while (error_list != NULL) {
1162 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1163 + error_list = error_list->next;
1164 +
1165 + }
1166 + free_error_list(&error_list);
1167 +
1168 + }
1169 +
1170 + p_userdata = NULL;
1171 + return result;
1172 +}
1173 +#else
1174 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1175 +{
1176 + return (cmd->fun)(conf, argc, argv);
1177 +}
1178 +#endif
1179 +
1180 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1181 +{
1182 + int err;
1183 + int failures;
1184 + char *lists_dir;
1185 + pkg_src_list_elt_t *iter;
1186 + pkg_src_t *src;
1187 +
1188 +
1189 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1190 +
1191 + if (! file_is_dir(lists_dir)) {
1192 + if (file_exists(lists_dir)) {
1193 + ipkg_message(conf, IPKG_ERROR,
1194 + "%s: ERROR: %s exists, but is not a directory\n",
1195 + __FUNCTION__, lists_dir);
1196 + free(lists_dir);
1197 + return EINVAL;
1198 + }
1199 + err = file_mkdir_hier(lists_dir, 0755);
1200 + if (err) {
1201 + ipkg_message(conf, IPKG_ERROR,
1202 + "%s: ERROR: failed to make directory %s: %s\n",
1203 + __FUNCTION__, lists_dir, strerror(errno));
1204 + free(lists_dir);
1205 + return EINVAL;
1206 + }
1207 + }
1208 +
1209 + failures = 0;
1210 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1211 + char *url, *list_file_name;
1212 +
1213 + src = iter->data;
1214 +
1215 + if (src->extra_data) /* debian style? */
1216 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1217 + src->gzip ? "Packages.gz" : "Packages");
1218 + else
1219 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1220 +
1221 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1222 + if (src->gzip) {
1223 + char *tmp;
1224 + char *tmp_file_name;
1225 + FILE *in, *out;
1226 +
1227 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1228 +
1229 + if (mkdtemp (tmp) == NULL) {
1230 + perror ("mkdtemp");
1231 + failures++;
1232 + continue;
1233 + }
1234 +
1235 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1236 + err = ipkg_download(conf, url, tmp_file_name);
1237 + if (err == 0) {
1238 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1239 + in = fopen (tmp_file_name, "r");
1240 + out = fopen (list_file_name, "w");
1241 + if (in && out) {
1242 + inflate_unzip_result res;
1243 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1244 + } else
1245 + err = 1;
1246 + if (in)
1247 + fclose (in);
1248 + if (out)
1249 + fclose (out);
1250 + unlink (tmp_file_name);
1251 + rmdir (tmp);
1252 + free (tmp);
1253 + }
1254 + } else
1255 + err = ipkg_download(conf, url, list_file_name);
1256 + if (err) {
1257 + failures++;
1258 + } else {
1259 + ipkg_message(conf, IPKG_NOTICE,
1260 + "Updated list of available packages in %s\n",
1261 + list_file_name);
1262 + }
1263 + free(url);
1264 + free(list_file_name);
1265 + }
1266 + free(lists_dir);
1267 +
1268 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1269 +#warning here
1270 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1271 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1272 + * -Jamey 3/1/03
1273 + */
1274 + {
1275 + int i;
1276 + int changed = 0;
1277 + pkg_vec_t *available = pkg_vec_alloc();
1278 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1279 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1280 + for (i = 0; i < available->len; i++) {
1281 + pkg_t *pkg = available->pkgs[i];
1282 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1283 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1284 + pkg->state_want = SW_UNKNOWN;
1285 + changed = 1;
1286 + }
1287 + }
1288 + pkg_vec_free(available);
1289 + if (changed) {
1290 + write_status_files_if_changed(conf);
1291 + }
1292 + }
1293 +#endif
1294 +
1295 + return failures;
1296 +}
1297 +
1298 +
1299 +/* scan the args passed and cache the local filenames of the packages */
1300 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1301 +{
1302 + int i;
1303 + int err;
1304 +
1305 + /*
1306 + * First scan through package names/urls
1307 + * For any urls, download the packages and install in database.
1308 + * For any files, install package info in database.
1309 + */
1310 + for (i = 0; i < argc; i ++) {
1311 + char *filename = argv [i];
1312 + //char *tmp = basename (tmp);
1313 + //int tmplen = strlen (tmp);
1314 +
1315 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1316 + // continue;
1317 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1318 + // continue;
1319 +
1320 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1321 +
1322 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1323 + if (err)
1324 + return err;
1325 + }
1326 + return 0;
1327 +}
1328 +
1329 +struct ipkg_intercept
1330 +{
1331 + char *oldpath;
1332 + char *statedir;
1333 +};
1334 +
1335 +typedef struct ipkg_intercept *ipkg_intercept_t;
1336 +
1337 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1338 +{
1339 + ipkg_intercept_t ctx;
1340 + char *newpath;
1341 + int gen;
1342 +
1343 + ctx = malloc (sizeof (*ctx));
1344 + ctx->oldpath = strdup (getenv ("PATH"));
1345 +
1346 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1347 + setenv ("PATH", newpath, 1);
1348 + free (newpath);
1349 +
1350 + gen = 0;
1351 + retry:
1352 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1353 + if (mkdir (ctx->statedir, 0770) < 0) {
1354 + if (errno == EEXIST) {
1355 + free (ctx->statedir);
1356 + gen++;
1357 + goto retry;
1358 + }
1359 + perror (ctx->statedir);
1360 + return NULL;
1361 + }
1362 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1363 + return ctx;
1364 +}
1365 +
1366 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1367 +{
1368 + char *cmd;
1369 + DIR *dir;
1370 + int err = 0;
1371 +
1372 + setenv ("PATH", ctx->oldpath, 1);
1373 + free (ctx->oldpath);
1374 +
1375 + dir = opendir (ctx->statedir);
1376 + if (dir) {
1377 + struct dirent *de;
1378 + while (de = readdir (dir), de != NULL) {
1379 + char *path;
1380 +
1381 + if (de->d_name[0] == '.')
1382 + continue;
1383 +
1384 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1385 + if (access (path, X_OK) == 0) {
1386 + if (system (path)) {
1387 + err = errno;
1388 + perror (de->d_name);
1389 + }
1390 + }
1391 + free (path);
1392 + }
1393 + } else
1394 + perror (ctx->statedir);
1395 +
1396 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1397 + system (cmd);
1398 + free (cmd);
1399 +
1400 + free (ctx->statedir);
1401 + free (ctx);
1402 +
1403 + return err;
1404 +}
1405 +
1406 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1407 +{
1408 + pkg_vec_t *all;
1409 + int i;
1410 + pkg_t *pkg;
1411 + ipkg_intercept_t ic;
1412 + int r, err = 0;
1413 +
1414 + ipkg_message(conf, IPKG_INFO,
1415 + "Configuring unpacked packages\n");
1416 + fflush( stdout );
1417 +
1418 + all = pkg_vec_alloc();
1419 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1420 +
1421 + ic = ipkg_prep_intercepts (conf);
1422 +
1423 + for(i = 0; i < all->len; i++) {
1424 + pkg = all->pkgs[i];
1425 +
1426 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1427 + continue;
1428 +
1429 + if (pkg->state_status == SS_UNPACKED) {
1430 + ipkg_message(conf, IPKG_NOTICE,
1431 + "Configuring %s\n", pkg->name);
1432 + fflush( stdout );
1433 + r = ipkg_configure(conf, pkg);
1434 + if (r == 0) {
1435 + pkg->state_status = SS_INSTALLED;
1436 + pkg->parent->state_status = SS_INSTALLED;
1437 + pkg->state_flag &= ~SF_PREFER;
1438 + } else {
1439 + if (!err)
1440 + err = r;
1441 + }
1442 + }
1443 + }
1444 +
1445 + r = ipkg_finalize_intercepts (ic);
1446 + if (r && !err)
1447 + err = r;
1448 +
1449 + pkg_vec_free(all);
1450 + return err;
1451 +}
1452 +
1453 +static void sigint_handler(int sig)
1454 +{
1455 + signal(sig, SIG_DFL);
1456 + ipkg_message(NULL, IPKG_NOTICE,
1457 + "ipkg: interrupted. writing out status database\n");
1458 + write_status_files_if_changed(global_conf);
1459 + exit(128 + sig);
1460 +}
1461 +
1462 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1463 +{
1464 + int i;
1465 + char *arg;
1466 + int err=0;
1467 +
1468 + global_conf = conf;
1469 + signal(SIGINT, sigint_handler);
1470 +
1471 + /*
1472 + * Now scan through package names and install
1473 + */
1474 + for (i=0; i < argc; i++) {
1475 + arg = argv[i];
1476 +
1477 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1478 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1479 + if (err != EINVAL && err != 0)
1480 + return err;
1481 + }
1482 + pkg_info_preinstall_check(conf);
1483 +
1484 + for (i=0; i < argc; i++) {
1485 + arg = argv[i];
1486 + if (conf->multiple_providers)
1487 + err = ipkg_install_multi_by_name(conf, arg);
1488 + else{
1489 + err = ipkg_install_by_name(conf, arg);
1490 + }
1491 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1492 + ipkg_message(conf, IPKG_ERROR,
1493 + "Cannot find package %s.\n"
1494 + "Check the spelling or perhaps run 'ipkg update'\n",
1495 + arg);
1496 + }
1497 + }
1498 +
1499 + /* recheck to verify that all dependences are satisfied */
1500 + if (0) ipkg_satisfy_all_dependences(conf);
1501 +
1502 + ipkg_configure_packages(conf, NULL);
1503 +
1504 + write_status_files_if_changed(conf);
1505 +
1506 + return err;
1507 +}
1508 +
1509 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1510 +{
1511 + int i;
1512 + pkg_t *pkg;
1513 + int err;
1514 +
1515 + global_conf = conf;
1516 + signal(SIGINT, sigint_handler);
1517 +
1518 + if (argc) {
1519 + for (i=0; i < argc; i++) {
1520 + char *arg = argv[i];
1521 +
1522 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1523 + if (err != EINVAL && err != 0)
1524 + return err;
1525 + }
1526 + pkg_info_preinstall_check(conf);
1527 +
1528 + for (i=0; i < argc; i++) {
1529 + char *arg = argv[i];
1530 + if (conf->restrict_to_default_dest) {
1531 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1532 + argv[i],
1533 + conf->default_dest);
1534 + if (pkg == NULL) {
1535 + ipkg_message(conf, IPKG_NOTICE,
1536 + "Package %s not installed in %s\n",
1537 + argv[i], conf->default_dest->name);
1538 + continue;
1539 + }
1540 + } else {
1541 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1542 + argv[i]);
1543 + }
1544 + if (pkg)
1545 + ipkg_upgrade_pkg(conf, pkg);
1546 + else {
1547 + ipkg_install_by_name(conf, arg);
1548 + }
1549 + }
1550 + } else {
1551 + pkg_vec_t *installed = pkg_vec_alloc();
1552 +
1553 + pkg_info_preinstall_check(conf);
1554 +
1555 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1556 + for (i = 0; i < installed->len; i++) {
1557 + pkg = installed->pkgs[i];
1558 + ipkg_upgrade_pkg(conf, pkg);
1559 + }
1560 + pkg_vec_free(installed);
1561 + }
1562 +
1563 + /* recheck to verify that all dependences are satisfied */
1564 + if (0) ipkg_satisfy_all_dependences(conf);
1565 +
1566 + ipkg_configure_packages(conf, NULL);
1567 +
1568 + write_status_files_if_changed(conf);
1569 +
1570 + return 0;
1571 +}
1572 +
1573 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1574 +{
1575 + int i, err;
1576 + char *arg;
1577 + pkg_t *pkg;
1578 +
1579 + pkg_info_preinstall_check(conf);
1580 + for (i = 0; i < argc; i++) {
1581 + arg = argv[i];
1582 +
1583 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1584 + if (pkg == NULL) {
1585 + ipkg_message(conf, IPKG_ERROR,
1586 + "Cannot find package %s.\n"
1587 + "Check the spelling or perhaps run 'ipkg update'\n",
1588 + arg);
1589 + continue;
1590 + }
1591 +
1592 + err = ipkg_download_pkg(conf, pkg, ".");
1593 +
1594 + if (err) {
1595 + ipkg_message(conf, IPKG_ERROR,
1596 + "Failed to download %s\n", pkg->name);
1597 + } else {
1598 + ipkg_message(conf, IPKG_NOTICE,
1599 + "Downloaded %s as %s\n",
1600 + pkg->name, pkg->local_filename);
1601 + }
1602 + }
1603 +
1604 + return 0;
1605 +}
1606 +
1607 +
1608 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1609 +{
1610 + int i ;
1611 + pkg_vec_t *available;
1612 + pkg_t *pkg;
1613 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1614 + char *newline;
1615 + char *pkg_name = NULL;
1616 + char *version_str;
1617 +
1618 + if (argc > 0) {
1619 + pkg_name = argv[0];
1620 + }
1621 + available = pkg_vec_alloc();
1622 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1623 + for (i=0; i < available->len; i++) {
1624 + pkg = available->pkgs[i];
1625 + /* if we have package name or pattern and pkg does not match, then skip it */
1626 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1627 + continue;
1628 + if (pkg->description) {
1629 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1630 + } else {
1631 + desc_short[0] = '\0';
1632 + }
1633 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1634 + newline = strchr(desc_short, '\n');
1635 + if (newline) {
1636 + *newline = '\0';
1637 + }
1638 +#ifndef IPKG_LIB
1639 + printf("%s - %s\n", pkg->name, desc_short);
1640 +#else
1641 + if (ipkg_cb_list) {
1642 + version_str = pkg_version_str_alloc(pkg);
1643 + ipkg_cb_list(pkg->name,desc_short,
1644 + version_str,
1645 + pkg->state_status,
1646 + p_userdata);
1647 + free(version_str);
1648 + }
1649 +#endif
1650 + }
1651 + pkg_vec_free(available);
1652 +
1653 + return 0;
1654 +}
1655 +
1656 +
1657 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1658 +{
1659 + int i ;
1660 + pkg_vec_t *available;
1661 + pkg_t *pkg;
1662 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1663 + char *newline;
1664 + char *pkg_name = NULL;
1665 + char *version_str;
1666 +
1667 + if (argc > 0) {
1668 + pkg_name = argv[0];
1669 + }
1670 + available = pkg_vec_alloc();
1671 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1672 + for (i=0; i < available->len; i++) {
1673 + pkg = available->pkgs[i];
1674 + /* if we have package name or pattern and pkg does not match, then skip it */
1675 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1676 + continue;
1677 + if (pkg->description) {
1678 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1679 + } else {
1680 + desc_short[0] = '\0';
1681 + }
1682 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1683 + newline = strchr(desc_short, '\n');
1684 + if (newline) {
1685 + *newline = '\0';
1686 + }
1687 +#ifndef IPKG_LIB
1688 + printf("%s - %s\n", pkg->name, desc_short);
1689 +#else
1690 + if (ipkg_cb_list) {
1691 + version_str = pkg_version_str_alloc(pkg);
1692 + ipkg_cb_list(pkg->name,desc_short,
1693 + version_str,
1694 + pkg->state_status,
1695 + p_userdata);
1696 + free(version_str);
1697 + }
1698 +#endif
1699 + }
1700 +
1701 + return 0;
1702 +}
1703 +
1704 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1705 +{
1706 + int i;
1707 + pkg_vec_t *available;
1708 + pkg_t *pkg;
1709 + char *pkg_name = NULL;
1710 + char **pkg_fields = NULL;
1711 + int n_fields = 0;
1712 + char *buff ; // = (char *)malloc(1);
1713 +
1714 + if (argc > 0) {
1715 + pkg_name = argv[0];
1716 + }
1717 + if (argc > 1) {
1718 + pkg_fields = &argv[1];
1719 + n_fields = argc - 1;
1720 + }
1721 +
1722 + available = pkg_vec_alloc();
1723 + if (installed_only)
1724 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1725 + else
1726 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1727 + for (i=0; i < available->len; i++) {
1728 + pkg = available->pkgs[i];
1729 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1730 + continue;
1731 + }
1732 +#ifndef IPKG_LIB
1733 + if (n_fields) {
1734 + for (j = 0; j < n_fields; j++)
1735 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1736 + } else {
1737 + pkg_print_info(pkg, stdout);
1738 + }
1739 +#else
1740 +
1741 + buff = pkg_formatted_info(pkg);
1742 + if ( buff ) {
1743 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1744 + pkg->state_status,
1745 + buff,
1746 + p_userdata);
1747 +/*
1748 + We should not forget that actually the pointer is allocated.
1749 + We need to free it :) ( Thanks florian for seeing the error )
1750 +*/
1751 + free(buff);
1752 + }
1753 +#endif
1754 + if (conf->verbosity > 1) {
1755 + conffile_list_elt_t *iter;
1756 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1757 + conffile_t *cf = iter->data;
1758 + int modified = conffile_has_been_modified(conf, cf);
1759 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1760 + cf->name, cf->value, modified);
1761 + }
1762 + }
1763 + }
1764 +#ifndef IPKG_LIB
1765 + if (buff)
1766 + free(buff);
1767 +#endif
1768 + pkg_vec_free(available);
1769 +
1770 + return 0;
1771 +}
1772 +
1773 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1774 +{
1775 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1776 +}
1777 +
1778 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1779 +{
1780 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1781 +}
1782 +
1783 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1784 +{
1785 +
1786 + int err;
1787 + if (argc > 0) {
1788 + char *pkg_name = NULL;
1789 +
1790 + pkg_name = argv[0];
1791 +
1792 + err = ipkg_configure_packages (conf, pkg_name);
1793 +
1794 + } else {
1795 + err = ipkg_configure_packages (conf, NULL);
1796 + }
1797 +
1798 + write_status_files_if_changed(conf);
1799 +
1800 + return err;
1801 +}
1802 +
1803 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1804 +{
1805 + int i, err;
1806 + char *globpattern;
1807 + glob_t globbuf;
1808 +
1809 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1810 + err = glob(globpattern, 0, NULL, &globbuf);
1811 + free(globpattern);
1812 + if (err) {
1813 + return 0;
1814 + }
1815 +
1816 + ipkg_message(conf, IPKG_NOTICE,
1817 + "The following packages in %s will now be installed.\n",
1818 + conf->pending_dir);
1819 + for (i = 0; i < globbuf.gl_pathc; i++) {
1820 + ipkg_message(conf, IPKG_NOTICE,
1821 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1822 + }
1823 + ipkg_message(conf, IPKG_NOTICE, "\n");
1824 + for (i = 0; i < globbuf.gl_pathc; i++) {
1825 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1826 + if (err == 0) {
1827 + err = unlink(globbuf.gl_pathv[i]);
1828 + if (err) {
1829 + ipkg_message(conf, IPKG_ERROR,
1830 + "%s: ERROR: failed to unlink %s: %s\n",
1831 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1832 + return err;
1833 + }
1834 + }
1835 + }
1836 + globfree(&globbuf);
1837 +
1838 + return err;
1839 +}
1840 +
1841 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1842 +{
1843 + int i,a,done;
1844 + pkg_t *pkg;
1845 + pkg_t *pkg_to_remove;
1846 + pkg_vec_t *available;
1847 + char *pkg_name = NULL;
1848 + global_conf = conf;
1849 + signal(SIGINT, sigint_handler);
1850 +
1851 +// ENH: Add the "no pkg removed" just in case.
1852 +
1853 + done = 0;
1854 +
1855 + available = pkg_vec_alloc();
1856 + pkg_info_preinstall_check(conf);
1857 + if ( argc > 0 ) {
1858 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1859 + for (i=0; i < argc; i++) {
1860 + pkg_name = malloc(strlen(argv[i])+2);
1861 + strcpy(pkg_name,argv[i]);
1862 + for (a=0; a < available->len; a++) {
1863 + pkg = available->pkgs[a];
1864 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1865 + continue;
1866 + }
1867 + if (conf->restrict_to_default_dest) {
1868 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1869 + pkg->name,
1870 + conf->default_dest);
1871 + } else {
1872 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1873 + }
1874 +
1875 + if (pkg == NULL) {
1876 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1877 + continue;
1878 + }
1879 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1880 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1881 + continue;
1882 + }
1883 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1884 + done = 1;
1885 + }
1886 + free (pkg_name);
1887 + }
1888 + pkg_vec_free(available);
1889 + } else {
1890 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1891 + int flagged_pkg_count = 0;
1892 + int removed;
1893 +
1894 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1895 +
1896 + for (i = 0; i < installed_pkgs->len; i++) {
1897 + pkg = installed_pkgs->pkgs[i];
1898 + if (pkg->state_flag & SF_USER) {
1899 + flagged_pkg_count++;
1900 + } else {
1901 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1902 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1903 + }
1904 + }
1905 + if (!flagged_pkg_count) {
1906 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1907 + "so refusing to uninstall unflagged non-leaf packages\n");
1908 + return 0;
1909 + }
1910 +
1911 + /* find packages not flagged SF_USER (i.e., installed to
1912 + * satisfy a dependence) and not having any dependents, and
1913 + * remove them */
1914 + do {
1915 + removed = 0;
1916 + for (i = 0; i < installed_pkgs->len; i++) {
1917 + pkg = installed_pkgs->pkgs[i];
1918 + if (!(pkg->state_flag & SF_USER)
1919 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1920 + removed++;
1921 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1922 + ipkg_remove_pkg(conf, pkg,0);
1923 + done = 1;
1924 + }
1925 + }
1926 + } while (removed);
1927 + pkg_vec_free(installed_pkgs);
1928 + }
1929 +
1930 + if ( done == 0 )
1931 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1932 +
1933 + write_status_files_if_changed(conf);
1934 + return 0;
1935 +}
1936 +
1937 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1938 +{
1939 + int i;
1940 + pkg_t *pkg;
1941 +
1942 + global_conf = conf;
1943 + signal(SIGINT, sigint_handler);
1944 +
1945 + pkg_info_preinstall_check(conf);
1946 +
1947 + for (i=0; i < argc; i++) {
1948 + if (conf->restrict_to_default_dest) {
1949 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1950 + argv[i],
1951 + conf->default_dest);
1952 + } else {
1953 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1954 + }
1955 +
1956 + if (pkg == NULL) {
1957 + ipkg_message(conf, IPKG_ERROR,
1958 + "Package %s is not installed.\n", argv[i]);
1959 + continue;
1960 + }
1961 + ipkg_purge_pkg(conf, pkg);
1962 + }
1963 +
1964 + write_status_files_if_changed(conf);
1965 + return 0;
1966 +}
1967 +
1968 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1969 +{
1970 + int i;
1971 + pkg_t *pkg;
1972 + char *flags = argv[0];
1973 +
1974 + global_conf = conf;
1975 + signal(SIGINT, sigint_handler);
1976 +
1977 + for (i=1; i < argc; i++) {
1978 + if (conf->restrict_to_default_dest) {
1979 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1980 + argv[i],
1981 + conf->default_dest);
1982 + } else {
1983 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1984 + }
1985 +
1986 + if (pkg == NULL) {
1987 + ipkg_message(conf, IPKG_ERROR,
1988 + "Package %s is not installed.\n", argv[i]);
1989 + continue;
1990 + }
1991 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1992 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1993 + pkg->state_flag = pkg_state_flag_from_str(flags);
1994 + }
1995 +/* pb_ asked this feature 03292004 */
1996 +/* Actually I will use only this two, but this is an open for various status */
1997 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1998 + pkg->state_status = pkg_state_status_from_str(flags);
1999 + }
2000 + ipkg_state_changed++;
2001 + ipkg_message(conf, IPKG_NOTICE,
2002 + "Setting flags for package %s to %s\n",
2003 + pkg->name, flags);
2004 + }
2005 +
2006 + write_status_files_if_changed(conf);
2007 + return 0;
2008 +}
2009 +
2010 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2011 +{
2012 + pkg_t *pkg;
2013 + str_list_t *installed_files;
2014 + str_list_elt_t *iter;
2015 + char *pkg_version;
2016 + size_t buff_len = 8192;
2017 + size_t used_len;
2018 + char *buff ;
2019 +
2020 + buff = (char *)malloc(buff_len);
2021 + if ( buff == NULL ) {
2022 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2023 + return ENOMEM;
2024 + }
2025 +
2026 + if (argc < 1) {
2027 + return EINVAL;
2028 + }
2029 +
2030 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2031 + argv[0]);
2032 + if (pkg == NULL) {
2033 + ipkg_message(conf, IPKG_ERROR,
2034 + "Package %s not installed.\n", argv[0]);
2035 + return 0;
2036 + }
2037 +
2038 + installed_files = pkg_get_installed_files(pkg);
2039 + pkg_version = pkg_version_str_alloc(pkg);
2040 +
2041 +#ifndef IPKG_LIB
2042 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2043 + pkg->name, pkg_version, pkg->dest->name);
2044 + for (iter = installed_files->head; iter; iter = iter->next) {
2045 + puts(iter->data);
2046 + }
2047 +#else
2048 + if (buff) {
2049 + try_again:
2050 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2051 + pkg->name, pkg_version, pkg->dest->name) + 1;
2052 + if (used_len > buff_len) {
2053 + buff_len *= 2;
2054 + buff = realloc (buff, buff_len);
2055 + goto try_again;
2056 + }
2057 + for (iter = installed_files->head; iter; iter = iter->next) {
2058 + used_len += strlen (iter->data) + 1;
2059 + while (buff_len <= used_len) {
2060 + buff_len *= 2;
2061 + buff = realloc (buff, buff_len);
2062 + }
2063 + strncat(buff, iter->data, buff_len);
2064 + strncat(buff, "\n", buff_len);
2065 + }
2066 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2067 + buff,
2068 + pkg_version_str_alloc(pkg),
2069 + pkg->state_status,
2070 + p_userdata);
2071 + free(buff);
2072 + }
2073 +#endif
2074 +
2075 + free(pkg_version);
2076 + pkg_free_installed_files(pkg);
2077 +
2078 + return 0;
2079 +}
2080 +
2081 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2082 +{
2083 +
2084 + if (argc > 0) {
2085 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2086 + const char *rel_str = "depends on";
2087 + int i;
2088 +
2089 + pkg_info_preinstall_check(conf);
2090 +
2091 + if (conf->query_all)
2092 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2093 + else
2094 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2095 + for (i = 0; i < argc; i++) {
2096 + const char *target = argv[i];
2097 + int j;
2098 +
2099 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2100 +
2101 + for (j = 0; j < available_pkgs->len; j++) {
2102 + pkg_t *pkg = available_pkgs->pkgs[j];
2103 + if (fnmatch(target, pkg->name, 0) == 0) {
2104 + int k;
2105 + int count = pkg->depends_count + pkg->pre_depends_count;
2106 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2107 + target, pkg->architecture, rel_str);
2108 + for (k = 0; k < count; k++) {
2109 + compound_depend_t *cdepend = &pkg->depends[k];
2110 + int l;
2111 + for (l = 0; l < cdepend->possibility_count; l++) {
2112 + depend_t *possibility = cdepend->possibilities[l];
2113 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2114 + if (conf->verbosity > 0) {
2115 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2116 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2117 + if (possibility->version) {
2118 + char *typestr = NULL;
2119 + switch (possibility->constraint) {
2120 + case NONE: typestr = "none"; break;
2121 + case EARLIER: typestr = "<"; break;
2122 + case EARLIER_EQUAL: typestr = "<="; break;
2123 + case EQUAL: typestr = "="; break;
2124 + case LATER_EQUAL: typestr = ">="; break;
2125 + case LATER: typestr = ">"; break;
2126 + }
2127 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2128 + }
2129 + // free(ver);
2130 + }
2131 + ipkg_message(conf, IPKG_ERROR, "\n");
2132 + }
2133 + }
2134 + }
2135 + }
2136 + }
2137 + pkg_vec_free(available_pkgs);
2138 + }
2139 + return 0;
2140 +}
2141 +
2142 +enum what_field_type {
2143 + WHATDEPENDS,
2144 + WHATCONFLICTS,
2145 + WHATPROVIDES,
2146 + WHATREPLACES,
2147 + WHATRECOMMENDS,
2148 + WHATSUGGESTS
2149 +};
2150 +
2151 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2152 +{
2153 +
2154 + if (argc > 0) {
2155 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2156 + const char *rel_str = NULL;
2157 + int i;
2158 + int changed;
2159 +
2160 + switch (what_field_type) {
2161 + case WHATDEPENDS: rel_str = "depends on"; break;
2162 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2163 + case WHATSUGGESTS: rel_str = "suggests"; break;
2164 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2165 + case WHATPROVIDES: rel_str = "provides"; break;
2166 + case WHATREPLACES: rel_str = "replaces"; break;
2167 + }
2168 +
2169 + if (conf->query_all)
2170 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2171 + else
2172 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2173 +
2174 + /* mark the root set */
2175 + pkg_vec_clear_marks(available_pkgs);
2176 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2177 + for (i = 0; i < argc; i++) {
2178 + const char *dependee_pattern = argv[i];
2179 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2180 + }
2181 + for (i = 0; i < available_pkgs->len; i++) {
2182 + pkg_t *pkg = available_pkgs->pkgs[i];
2183 + if (pkg->state_flag & SF_MARKED) {
2184 + /* mark the parent (abstract) package */
2185 + pkg_mark_provides(pkg);
2186 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2187 + }
2188 + }
2189 +
2190 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2191 + do {
2192 + int j;
2193 + changed = 0;
2194 +
2195 + for (j = 0; j < available_pkgs->len; j++) {
2196 + pkg_t *pkg = available_pkgs->pkgs[j];
2197 + int k;
2198 + int count = ((what_field_type == WHATCONFLICTS)
2199 + ? pkg->conflicts_count
2200 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2201 + /* skip this package if it is already marked */
2202 + if (pkg->parent->state_flag & SF_MARKED) {
2203 + continue;
2204 + }
2205 + for (k = 0; k < count; k++) {
2206 + compound_depend_t *cdepend =
2207 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2208 + int l;
2209 + for (l = 0; l < cdepend->possibility_count; l++) {
2210 + depend_t *possibility = cdepend->possibilities[l];
2211 + if (possibility->pkg->state_flag & SF_MARKED) {
2212 + /* mark the depending package so we won't visit it again */
2213 + pkg->state_flag |= SF_MARKED;
2214 + pkg_mark_provides(pkg);
2215 + changed++;
2216 +
2217 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2218 + if (conf->verbosity > 0) {
2219 + char *ver = pkg_version_str_alloc(pkg);
2220 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2221 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2222 + if (possibility->version) {
2223 + char *typestr = NULL;
2224 + switch (possibility->constraint) {
2225 + case NONE: typestr = "none"; break;
2226 + case EARLIER: typestr = "<"; break;
2227 + case EARLIER_EQUAL: typestr = "<="; break;
2228 + case EQUAL: typestr = "="; break;
2229 + case LATER_EQUAL: typestr = ">="; break;
2230 + case LATER: typestr = ">"; break;
2231 + }
2232 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2233 + }
2234 + free(ver);
2235 + if (!pkg_dependence_satisfiable(conf, possibility))
2236 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2237 + }
2238 + ipkg_message(conf, IPKG_NOTICE, "\n");
2239 + goto next_package;
2240 + }
2241 + }
2242 + }
2243 + next_package:
2244 + ;
2245 + }
2246 + } while (changed && recursive);
2247 + pkg_vec_free(available_pkgs);
2248 + }
2249 +
2250 + return 0;
2251 +}
2252 +
2253 +int pkg_mark_provides(pkg_t *pkg)
2254 +{
2255 + int provides_count = pkg->provides_count;
2256 + abstract_pkg_t **provides = pkg->provides;
2257 + int i;
2258 + pkg->parent->state_flag |= SF_MARKED;
2259 + for (i = 0; i < provides_count; i++) {
2260 + provides[i]->state_flag |= SF_MARKED;
2261 + }
2262 + return 0;
2263 +}
2264 +
2265 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2266 +{
2267 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2268 +}
2269 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2270 +{
2271 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2272 +}
2273 +
2274 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2275 +{
2276 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2277 +}
2278 +
2279 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2280 +{
2281 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2282 +}
2283 +
2284 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2285 +{
2286 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2287 +}
2288 +
2289 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2290 +{
2291 +
2292 + if (argc > 0) {
2293 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2294 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2295 + int i;
2296 +
2297 + pkg_info_preinstall_check(conf);
2298 +
2299 + if (conf->query_all)
2300 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2301 + else
2302 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2303 + for (i = 0; i < argc; i++) {
2304 + const char *target = argv[i];
2305 + int j;
2306 +
2307 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2308 + rel_str, target);
2309 + for (j = 0; j < available_pkgs->len; j++) {
2310 + pkg_t *pkg = available_pkgs->pkgs[j];
2311 + int k;
2312 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2313 + for (k = 0; k < count; k++) {
2314 + abstract_pkg_t *apkg =
2315 + ((what_field_type == WHATPROVIDES)
2316 + ? pkg->provides[k]
2317 + : pkg->replaces[k]);
2318 + if (fnmatch(target, apkg->name, 0) == 0) {
2319 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2320 + if (strcmp(target, apkg->name) != 0)
2321 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2322 + ipkg_message(conf, IPKG_ERROR, "\n");
2323 + }
2324 + }
2325 + }
2326 + }
2327 + pkg_vec_free(available_pkgs);
2328 + }
2329 + return 0;
2330 +}
2331 +
2332 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2333 +{
2334 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2335 +}
2336 +
2337 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2338 +{
2339 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2340 +}
2341 +
2342 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2343 +{
2344 + int i;
2345 +
2346 + pkg_vec_t *installed;
2347 + pkg_t *pkg;
2348 + str_list_t *installed_files;
2349 + str_list_elt_t *iter;
2350 + char *installed_file;
2351 +
2352 + if (argc < 1) {
2353 + return EINVAL;
2354 + }
2355 +
2356 + installed = pkg_vec_alloc();
2357 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2358 +
2359 + for (i=0; i < installed->len; i++) {
2360 + pkg = installed->pkgs[i];
2361 +
2362 + installed_files = pkg_get_installed_files(pkg);
2363 +
2364 + for (iter = installed_files->head; iter; iter = iter->next) {
2365 + installed_file = iter->data;
2366 + if (fnmatch(argv[0], installed_file, 0)==0) {
2367 +#ifndef IPKG_LIB
2368 + printf("%s: %s\n", pkg->name, installed_file);
2369 +#else
2370 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2371 + installed_file,
2372 + pkg_version_str_alloc(pkg),
2373 + pkg->state_status, p_userdata);
2374 +#endif
2375 + }
2376 + }
2377 +
2378 + pkg_free_installed_files(pkg);
2379 + }
2380 +
2381 + /* XXX: CLEANUP: It's not obvious from the name of
2382 + pkg_hash_fetch_all_installed that we need to call
2383 + pkg_vec_free to avoid a memory leak. */
2384 + pkg_vec_free(installed);
2385 +
2386 + return 0;
2387 +}
2388 +
2389 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2390 +{
2391 + if (argc == 3) {
2392 + /* this is a bit gross */
2393 + struct pkg p1, p2;
2394 + parseVersion(&p1, argv[0]);
2395 + parseVersion(&p2, argv[2]);
2396 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2397 + } else {
2398 + ipkg_message(conf, IPKG_ERROR,
2399 + "ipkg compare_versions <v1> <op> <v2>\n"
2400 + "<op> is one of <= >= << >> =\n");
2401 + return -1;
2402 + }
2403 +}
2404 +
2405 +#ifndef HOST_CPU_STR
2406 +#define HOST_CPU_STR__(X) #X
2407 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2408 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2409 +#endif
2410 +
2411 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2412 +{
2413 + nv_pair_list_elt_t *l;
2414 +
2415 + l = conf->arch_list.head;
2416 + while (l) {
2417 + nv_pair_t *nv = l->data;
2418 + printf("arch %s %s\n", nv->name, nv->value);
2419 + l = l->next;
2420 + }
2421 + return 0;
2422 +}
2423 +
2424 +
2425 Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.h
2426 ===================================================================
2427 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2428 +++ busybox-1.7.2/archival/libipkg/ipkg_cmd.h 2007-10-30 15:35:05.000000000 -0500
2429 @@ -0,0 +1,46 @@
2430 +/* ipkg_cmd.h - the itsy package management system
2431 +
2432 + Carl D. Worth
2433 +
2434 + Copyright (C) 2001 University of Southern California
2435 +
2436 + This program is free software; you can redistribute it and/or
2437 + modify it under the terms of the GNU General Public License as
2438 + published by the Free Software Foundation; either version 2, or (at
2439 + your option) any later version.
2440 +
2441 + This program is distributed in the hope that it will be useful, but
2442 + WITHOUT ANY WARRANTY; without even the implied warranty of
2443 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2444 + General Public License for more details.
2445 +*/
2446 +
2447 +#ifndef IPKG_CMD_H
2448 +#define IPKG_CMD_H
2449 +
2450 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2451 +
2452 +struct ipkg_cmd
2453 +{
2454 + char *name;
2455 + int requires_args;
2456 + ipkg_cmd_fun_t fun;
2457 +};
2458 +typedef struct ipkg_cmd ipkg_cmd_t;
2459 +
2460 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2461 +#ifdef IPKG_LIB
2462 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2463 + const char **argv, void *userdata);
2464 +#else
2465 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2466 +#endif
2467 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2468 +/* install any packges with state_want == SW_INSTALL */
2469 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2470 +/* ensure that all dependences are satisfied */
2471 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2472 +
2473 +int pkg_mark_provides(pkg_t *pkg);
2474 +
2475 +#endif
2476 Index: busybox-1.7.2/archival/libipkg/ipkg_conf.c
2477 ===================================================================
2478 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2479 +++ busybox-1.7.2/archival/libipkg/ipkg_conf.c 2007-10-30 15:35:05.000000000 -0500
2480 @@ -0,0 +1,711 @@
2481 +/* ipkg_conf.c - the itsy package management system
2482 +
2483 + Carl D. Worth
2484 +
2485 + Copyright (C) 2001 University of Southern California
2486 +
2487 + This program is free software; you can redistribute it and/or
2488 + modify it under the terms of the GNU General Public License as
2489 + published by the Free Software Foundation; either version 2, or (at
2490 + your option) any later version.
2491 +
2492 + This program is distributed in the hope that it will be useful, but
2493 + WITHOUT ANY WARRANTY; without even the implied warranty of
2494 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2495 + General Public License for more details.
2496 +*/
2497 +
2498 +#include <glob.h>
2499 +
2500 +#include "ipkg.h"
2501 +#include "ipkg_conf.h"
2502 +
2503 +#include "xregex.h"
2504 +#include "sprintf_alloc.h"
2505 +#include "ipkg_conf.h"
2506 +#include "ipkg_message.h"
2507 +#include "file_util.h"
2508 +#include "str_util.h"
2509 +#include "xsystem.h"
2510 +
2511 +
2512 +ipkg_conf_t *global_conf;
2513 +
2514 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2515 + pkg_src_list_t *pkg_src_list,
2516 + nv_pair_list_t *tmp_dest_nv_pair_list,
2517 + char **tmp_lists_dir);
2518 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2519 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2520 + const char *name, const char *value);
2521 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2522 + const char *default_dest_name);
2523 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2524 + pkg_src_list_t *nv_pair_list);
2525 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2526 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2527 +
2528 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2529 +{
2530 + ipkg_option_t tmp[] = {
2531 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2532 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2533 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2534 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2535 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2536 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2537 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2538 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2539 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2540 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2541 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2542 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2543 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2544 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2545 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2546 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2547 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2548 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2549 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2550 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2551 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2552 + { NULL }
2553 + };
2554 +
2555 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2556 + if ( options == NULL ){
2557 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2558 + return -1;
2559 + }
2560 +
2561 + memcpy(*options, tmp, sizeof(tmp));
2562 + return 0;
2563 +};
2564 +
2565 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2566 +{
2567 + if (arg_str) {
2568 + if (*conf_str) {
2569 + free(*conf_str);
2570 + }
2571 + *conf_str = strdup(arg_str);
2572 + }
2573 +}
2574 +
2575 +static void ipkg_conf_free_string(char **conf_str)
2576 +{
2577 + if (*conf_str) {
2578 + free(*conf_str);
2579 + *conf_str = NULL;
2580 + }
2581 +}
2582 +
2583 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2584 +{
2585 + int err;
2586 + char *tmp_dir_base;
2587 + nv_pair_list_t tmp_dest_nv_pair_list;
2588 + char * lists_dir =NULL;
2589 + glob_t globbuf;
2590 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2591 + char *pending_dir =NULL;
2592 +
2593 + memset(conf, 0, sizeof(ipkg_conf_t));
2594 +
2595 + pkg_src_list_init(&conf->pkg_src_list);
2596 +
2597 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2598 + pkg_dest_list_init(&conf->pkg_dest_list);
2599 +
2600 + nv_pair_list_init(&conf->arch_list);
2601 +
2602 + conf->restrict_to_default_dest = 0;
2603 + conf->default_dest = NULL;
2604 +
2605 +
2606 + if (args->tmp_dir)
2607 + tmp_dir_base = args->tmp_dir;
2608 + else
2609 + tmp_dir_base = getenv("TMPDIR");
2610 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2611 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2612 + IPKG_CONF_TMP_DIR_SUFFIX);
2613 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2614 + if (conf->tmp_dir == NULL) {
2615 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2616 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2617 + return errno;
2618 + }
2619 +
2620 + conf->force_depends = 0;
2621 + conf->force_defaults = 0;
2622 + conf->force_overwrite = 0;
2623 + conf->force_downgrade = 0;
2624 + conf->force_reinstall = 0;
2625 + conf->force_space = 0;
2626 + conf->force_removal_of_essential_packages = 0;
2627 + conf->force_removal_of_dependent_packages = 0;
2628 + conf->nodeps = 0;
2629 + conf->verbose_wget = 0;
2630 + conf->offline_root = NULL;
2631 + conf->offline_root_pre_script_cmd = NULL;
2632 + conf->offline_root_post_script_cmd = NULL;
2633 + conf->multiple_providers = 0;
2634 + conf->verbosity = 1;
2635 + conf->noaction = 0;
2636 +
2637 + conf->http_proxy = NULL;
2638 + conf->ftp_proxy = NULL;
2639 + conf->no_proxy = NULL;
2640 + conf->proxy_user = NULL;
2641 + conf->proxy_passwd = NULL;
2642 +
2643 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2644 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2646 + lists_dir=(char *)malloc(1);
2647 + lists_dir[0]='\0';
2648 + if (args->conf_file) {
2649 + struct stat stat_buf;
2650 + err = stat(args->conf_file, &stat_buf);
2651 + if (err == 0)
2652 + if (ipkg_conf_parse_file(conf, args->conf_file,
2653 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2654 + /* Memory leakage from ipkg_conf_parse-file */
2655 + return -1;
2656 + }
2657 +
2658 + }
2659 +
2660 + /* if (!lists_dir ){*/
2661 + if (strlen(lists_dir)<=1 ){
2662 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2663 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2664 + }
2665 +
2666 + if (args->offline_root) {
2667 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2668 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2669 + free(lists_dir);
2670 + lists_dir = tmp;
2671 + }
2672 +
2673 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2674 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2675 +
2676 + conf->lists_dir = strdup(lists_dir);
2677 + conf->pending_dir = strdup(pending_dir);
2678 +
2679 + if (args->offline_root)
2680 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2681 + memset(&globbuf, 0, sizeof(globbuf));
2682 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2683 + if (!err) {
2684 + int i;
2685 + for (i = 0; i < globbuf.gl_pathc; i++) {
2686 + if (globbuf.gl_pathv[i])
2687 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2688 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2689 + /* Memory leakage from ipkg_conf_parse-file */
2690 + return -1;
2691 + }
2692 + }
2693 + }
2694 + globfree(&globbuf);
2695 +
2696 + /* if no architectures were defined, then default all, noarch, and host architecture */
2697 + if (nv_pair_list_empty(&conf->arch_list)) {
2698 + nv_pair_list_append(&conf->arch_list, "all", "1");
2699 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2700 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2701 + }
2702 +
2703 + /* Even if there is no conf file, we'll need at least one dest. */
2704 + if (tmp_dest_nv_pair_list.head == NULL) {
2705 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2706 + IPKG_CONF_DEFAULT_DEST_NAME,
2707 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2708 + }
2709 +
2710 + /* After parsing the file, set options from command-line, (so that
2711 + command-line arguments take precedence) */
2712 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2713 + really needs to be cleaned up. There is so much duplication
2714 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2715 + a pointer to args_t (which could then not be freed), rather
2716 + than duplicating every field here? */
2717 + if (args->force_depends) {
2718 + conf->force_depends = 1;
2719 + }
2720 + if (args->force_defaults) {
2721 + conf->force_defaults = 1;
2722 + }
2723 + if (args->force_overwrite) {
2724 + conf->force_overwrite = 1;
2725 + }
2726 + if (args->force_downgrade) {
2727 + conf->force_downgrade = 1;
2728 + }
2729 + if (args->force_reinstall) {
2730 + conf->force_reinstall = 1;
2731 + }
2732 + if (args->force_removal_of_dependent_packages) {
2733 + conf->force_removal_of_dependent_packages = 1;
2734 + }
2735 + if (args->force_removal_of_essential_packages) {
2736 + conf->force_removal_of_essential_packages = 1;
2737 + }
2738 + if (args->nodeps) {
2739 + conf->nodeps = 1;
2740 + }
2741 + if (args->noaction) {
2742 + conf->noaction = 1;
2743 + }
2744 + if (args->query_all) {
2745 + conf->query_all = 1;
2746 + }
2747 + if (args->verbose_wget) {
2748 + conf->verbose_wget = 1;
2749 + }
2750 + if (args->multiple_providers) {
2751 + conf->multiple_providers = 1;
2752 + }
2753 + if (args->verbosity != conf->verbosity) {
2754 + conf->verbosity = args->verbosity;
2755 + }
2756 +
2757 + ipkg_conf_override_string(&conf->offline_root,
2758 + args->offline_root);
2759 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2760 + args->offline_root_pre_script_cmd);
2761 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2762 + args->offline_root_post_script_cmd);
2763 +
2764 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2765 + read anything from there.
2766 +*/
2767 + if ( !(args->nocheckfordirorfile)){
2768 + /* need to run load the source list before dest list -Jamey */
2769 + if ( !(args->noreadfeedsfile))
2770 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2771 +
2772 + /* Now that we have resolved conf->offline_root, we can commit to
2773 + the directory names for the dests and load in all the package
2774 + lists. */
2775 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2776 +
2777 + if (args->dest) {
2778 + err = ipkg_conf_set_default_dest(conf, args->dest);
2779 + if (err) {
2780 + return err;
2781 + }
2782 + }
2783 + }
2784 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2785 + free(lists_dir);
2786 + free(pending_dir);
2787 +
2788 + return 0;
2789 +}
2790 +
2791 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2792 +{
2793 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2794 +#error
2795 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2796 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2797 + __FUNCTION__, conf->tmp_dir);
2798 +#else
2799 + int err;
2800 +
2801 + err = rmdir(conf->tmp_dir);
2802 + if (err) {
2803 + if (errno == ENOTEMPTY) {
2804 + char *cmd;
2805 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2806 + err = xsystem(cmd);
2807 + free(cmd);
2808 + }
2809 + if (err)
2810 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2811 + }
2812 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2813 +
2814 + free(conf->tmp_dir); /*XXX*/
2815 +
2816 + pkg_src_list_deinit(&conf->pkg_src_list);
2817 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2818 + nv_pair_list_deinit(&conf->arch_list);
2819 + if (&conf->pkg_hash)
2820 + pkg_hash_deinit(&conf->pkg_hash);
2821 + if (&conf->file_hash)
2822 + hash_table_deinit(&conf->file_hash);
2823 + if (&conf->obs_file_hash)
2824 + hash_table_deinit(&conf->obs_file_hash);
2825 +
2826 + ipkg_conf_free_string(&conf->offline_root);
2827 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2828 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2829 +
2830 + if (conf->verbosity > 1) {
2831 + int i;
2832 + hash_table_t *hashes[] = {
2833 + &conf->pkg_hash,
2834 + &conf->file_hash,
2835 + &conf->obs_file_hash };
2836 + for (i = 0; i < 3; i++) {
2837 + hash_table_t *hash = hashes[i];
2838 + int c = 0;
2839 + int n_conflicts = 0;
2840 + int j;
2841 + for (j = 0; j < hash->n_entries; j++) {
2842 + int len = 0;
2843 + hash_entry_t *e = &hash->entries[j];
2844 + if (e->next)
2845 + n_conflicts++;
2846 + while (e && e->key) {
2847 + len++;
2848 + e = e->next;
2849 + }
2850 + if (len > c)
2851 + c = len;
2852 + }
2853 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2854 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2855 + hash_table_deinit(hash);
2856 + }
2857 + }
2858 +}
2859 +
2860 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2861 + const char *default_dest_name)
2862 +{
2863 + pkg_dest_list_elt_t *iter;
2864 + pkg_dest_t *dest;
2865 +
2866 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2867 + dest = iter->data;
2868 + if (strcmp(dest->name, default_dest_name) == 0) {
2869 + conf->default_dest = dest;
2870 + conf->restrict_to_default_dest = 1;
2871 + return 0;
2872 + }
2873 + }
2874 +
2875 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2876 +
2877 + return 1;
2878 +}
2879 +
2880 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2881 +{
2882 + pkg_src_list_elt_t *iter;
2883 + pkg_src_t *src;
2884 + char *list_file;
2885 +
2886 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2887 + src = iter->data;
2888 + if (src == NULL) {
2889 + continue;
2890 + }
2891 +
2892 + sprintf_alloc(&list_file, "%s/%s",
2893 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2894 + src->name);
2895 +
2896 + if (file_exists(list_file)) {
2897 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2898 + }
2899 + free(list_file);
2900 + }
2901 +
2902 + return 0;
2903 +}
2904 +
2905 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2906 +{
2907 + nv_pair_list_elt_t *iter;
2908 + nv_pair_t *nv_pair;
2909 + pkg_dest_t *dest;
2910 + char *root_dir;
2911 +
2912 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2913 + nv_pair = iter->data;
2914 +
2915 + if (conf->offline_root) {
2916 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2917 + } else {
2918 + root_dir = strdup(nv_pair->value);
2919 + }
2920 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2921 + free(root_dir);
2922 + if (dest == NULL) {
2923 + continue;
2924 + }
2925 + if (conf->default_dest == NULL) {
2926 + conf->default_dest = dest;
2927 + }
2928 + if (file_exists(dest->status_file_name)) {
2929 + pkg_hash_add_from_file(conf, dest->status_file_name,
2930 + NULL, dest, 1);
2931 + }
2932 + }
2933 +
2934 + return 0;
2935 +}
2936 +
2937 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2938 + pkg_src_list_t *pkg_src_list,
2939 + nv_pair_list_t *tmp_dest_nv_pair_list,
2940 + char **lists_dir)
2941 +{
2942 + ipkg_option_t * options;
2943 + FILE *file = fopen(filename, "r");
2944 + regex_t valid_line_re, comment_re;
2945 +#define regmatch_size 12
2946 + regmatch_t regmatch[regmatch_size];
2947 +
2948 + if (ipkg_init_options_array(conf, &options)<0)
2949 + return ENOMEM;
2950 +
2951 + if (file == NULL) {
2952 + fprintf(stderr, "%s: failed to open %s: %s\n",
2953 + __FUNCTION__, filename, strerror(errno));
2954 + free(options);
2955 + return errno;
2956 + }
2957 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2958 +
2959 + xregcomp(&comment_re,
2960 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2961 + REG_EXTENDED);
2962 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2963 +
2964 + while(1) {
2965 + int line_num = 0;
2966 + char *line;
2967 + char *type, *name, *value, *extra;
2968 +
2969 + line = file_read_line_alloc(file);
2970 + line_num++;
2971 + if (line == NULL) {
2972 + break;
2973 + }
2974 +
2975 + str_chomp(line);
2976 +
2977 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2978 + goto NEXT_LINE;
2979 + }
2980 +
2981 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2982 + str_chomp(line);
2983 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2984 + filename, line_num, line);
2985 + goto NEXT_LINE;
2986 + }
2987 +
2988 + /* This has to be so ugly to deal with optional quotation marks */
2989 + if (regmatch[2].rm_so > 0) {
2990 + type = strndup(line + regmatch[2].rm_so,
2991 + regmatch[2].rm_eo - regmatch[2].rm_so);
2992 + } else {
2993 + type = strndup(line + regmatch[3].rm_so,
2994 + regmatch[3].rm_eo - regmatch[3].rm_so);
2995 + }
2996 + if (regmatch[5].rm_so > 0) {
2997 + name = strndup(line + regmatch[5].rm_so,
2998 + regmatch[5].rm_eo - regmatch[5].rm_so);
2999 + } else {
3000 + name = strndup(line + regmatch[6].rm_so,
3001 + regmatch[6].rm_eo - regmatch[6].rm_so);
3002 + }
3003 + if (regmatch[8].rm_so > 0) {
3004 + value = strndup(line + regmatch[8].rm_so,
3005 + regmatch[8].rm_eo - regmatch[8].rm_so);
3006 + } else {
3007 + value = strndup(line + regmatch[9].rm_so,
3008 + regmatch[9].rm_eo - regmatch[9].rm_so);
3009 + }
3010 + extra = NULL;
3011 + if (regmatch[11].rm_so > 0) {
3012 + extra = strndup (line + regmatch[11].rm_so,
3013 + regmatch[11].rm_eo - regmatch[11].rm_so);
3014 + }
3015 +
3016 + /* We use the tmp_dest_nv_pair_list below instead of
3017 + conf->pkg_dest_list because we might encounter an
3018 + offline_root option later and that would invalidate the
3019 + directories we would have computed in
3020 + pkg_dest_list_init. (We do a similar thing with
3021 + tmp_src_nv_pair_list for sake of symmetry.) */
3022 + if (strcmp(type, "option") == 0) {
3023 + ipkg_conf_set_option(options, name, value);
3024 + } else if (strcmp(type, "src") == 0) {
3025 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3026 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3027 + } else {
3028 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3029 + name, value);
3030 + }
3031 + } else if (strcmp(type, "src/gz") == 0) {
3032 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3033 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3034 + } else {
3035 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3036 + name, value);
3037 + }
3038 + } else if (strcmp(type, "dest") == 0) {
3039 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3040 + } else if (strcmp(type, "lists_dir") == 0) {
3041 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3042 + if (*lists_dir == NULL) {
3043 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3044 + free(options);
3045 + return EINVAL;
3046 + }
3047 + sprintf (*lists_dir,"%s",value);
3048 + } else if (strcmp(type, "arch") == 0) {
3049 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3050 + if (!value) {
3051 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3052 + value = strdup("10");
3053 + }
3054 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3055 + } else {
3056 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3057 + "parameter: %s %s %s\n", type, name, value);
3058 + free(options);
3059 + return EINVAL;
3060 + }
3061 +
3062 + free(type);
3063 + free(name);
3064 + free(value);
3065 + if (extra)
3066 + free (extra);
3067 +
3068 + NEXT_LINE:
3069 + free(line);
3070 + }
3071 +
3072 + free(options);
3073 + regfree(&comment_re);
3074 + regfree(&valid_line_re);
3075 + fclose(file);
3076 +
3077 + return 0;
3078 +}
3079 +
3080 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3081 + const char *name, const char *value)
3082 +{
3083 + int i = 0;
3084 + while (options[i].name) {
3085 + if (strcmp(options[i].name, name) == 0) {
3086 + switch (options[i].type) {
3087 + case IPKG_OPT_TYPE_BOOL:
3088 + *((int *)options[i].value) = 1;
3089 + return 0;
3090 + case IPKG_OPT_TYPE_INT:
3091 + if (value) {
3092 + *((int *)options[i].value) = atoi(value);
3093 + return 0;
3094 + } else {
3095 + printf("%s: Option %s need an argument\n",
3096 + __FUNCTION__, name);
3097 + return EINVAL;
3098 + }
3099 + case IPKG_OPT_TYPE_STRING:
3100 + if (value) {
3101 + *((char **)options[i].value) = strdup(value);
3102 + return 0;
3103 + } else {
3104 + printf("%s: Option %s need an argument\n",
3105 + __FUNCTION__, name);
3106 + return EINVAL;
3107 + }
3108 + }
3109 + }
3110 + i++;
3111 + }
3112 +
3113 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3114 + __FUNCTION__, name, value);
3115 + return EINVAL;
3116 +}
3117 +
3118 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3119 +{
3120 + pkg_dest_list_elt_t *iter;
3121 + pkg_dest_t *dest;
3122 + pkg_vec_t *all;
3123 + pkg_t *pkg;
3124 + register int i;
3125 + int err;
3126 +
3127 + if (conf->noaction)
3128 + return 0;
3129 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3130 + dest = iter->data;
3131 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3132 + if (dest->status_file == NULL) {
3133 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3134 + __FUNCTION__, dest->status_file_name, strerror(errno));
3135 + }
3136 + }
3137 +
3138 + all = pkg_vec_alloc();
3139 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3140 +
3141 + for(i = 0; i < all->len; i++) {
3142 + pkg = all->pkgs[i];
3143 + /* We don't need most uninstalled packages in the status file */
3144 + if (pkg->state_status == SS_NOT_INSTALLED
3145 + && (pkg->state_want == SW_UNKNOWN
3146 + || pkg->state_want == SW_DEINSTALL
3147 + || pkg->state_want == SW_PURGE)) {
3148 + continue;
3149 + }
3150 + if (!pkg) {
3151 + fprintf(stderr, "Null package\n");
3152 + }
3153 + if (pkg->dest == NULL) {
3154 + fprintf(stderr, "%s: ERROR: Can't write status for "
3155 + "package %s since it has a NULL dest\n",
3156 + __FUNCTION__, pkg->name);
3157 + continue;
3158 + }
3159 + if (pkg->dest->status_file) {
3160 + pkg_print_status(pkg, pkg->dest->status_file);
3161 + }
3162 + }
3163 +
3164 + pkg_vec_free(all);
3165 +
3166 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3167 + dest = iter->data;
3168 + if (dest->status_file) {
3169 + err = ferror(dest->status_file);
3170 + fclose(dest->status_file);
3171 + dest->status_file = NULL;
3172 + if (!err) {
3173 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3174 + } else {
3175 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3176 + "retaining old %s\n", __FUNCTION__,
3177 + dest->status_file_tmp_name, dest->status_file_name);
3178 + }
3179 + }
3180 + }
3181 +
3182 + return 0;
3183 +}
3184 +
3185 +
3186 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3187 +{
3188 + char *root_filename;
3189 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3190 + return root_filename;
3191 +}
3192 Index: busybox-1.7.2/archival/libipkg/ipkg_conf.h
3193 ===================================================================
3194 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3195 +++ busybox-1.7.2/archival/libipkg/ipkg_conf.h 2007-10-30 15:35:05.000000000 -0500
3196 @@ -0,0 +1,107 @@
3197 +/* ipkg_conf.h - the itsy package management system
3198 +
3199 + Carl D. Worth
3200 +
3201 + Copyright (C) 2001 University of Southern California
3202 +
3203 + This program is free software; you can redistribute it and/or
3204 + modify it under the terms of the GNU General Public License as
3205 + published by the Free Software Foundation; either version 2, or (at
3206 + your option) any later version.
3207 +
3208 + This program is distributed in the hope that it will be useful, but
3209 + WITHOUT ANY WARRANTY; without even the implied warranty of
3210 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3211 + General Public License for more details.
3212 +*/
3213 +
3214 +#ifndef IPKG_CONF_H
3215 +#define IPKG_CONF_H
3216 +
3217 +typedef struct ipkg_conf ipkg_conf_t;
3218 +
3219 +#include "hash_table.h"
3220 +#include "ipkg.h"
3221 +#include "args.h"
3222 +#include "pkg.h"
3223 +#include "pkg_hash.h"
3224 +#include "pkg_src_list.h"
3225 +#include "pkg_dest_list.h"
3226 +#include "nv_pair_list.h"
3227 +
3228 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3229 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3230 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3231 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3232 +
3233 +/* In case the config file defines no dest */
3234 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3235 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3236 +
3237 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3238 +
3239 +struct ipkg_conf
3240 +{
3241 + pkg_src_list_t pkg_src_list;
3242 + pkg_dest_list_t pkg_dest_list;
3243 + nv_pair_list_t arch_list;
3244 +
3245 + int restrict_to_default_dest;
3246 + pkg_dest_t *default_dest;
3247 +
3248 + char *tmp_dir;
3249 + const char *lists_dir;
3250 + const char *pending_dir;
3251 +
3252 + /* options */
3253 + int force_depends;
3254 + int force_defaults;
3255 + int force_overwrite;
3256 + int force_downgrade;
3257 + int force_reinstall;
3258 + int force_space;
3259 + int force_removal_of_dependent_packages;
3260 + int force_removal_of_essential_packages;
3261 + int nodeps; /* do not follow dependences */
3262 + int verbose_wget;
3263 + int multiple_providers;
3264 + char *offline_root;
3265 + char *offline_root_pre_script_cmd;
3266 + char *offline_root_post_script_cmd;
3267 + int query_all;
3268 + int verbosity;
3269 + int noaction;
3270 +
3271 + /* proxy options */
3272 + char *http_proxy;
3273 + char *ftp_proxy;
3274 + char *no_proxy;
3275 + char *proxy_user;
3276 + char *proxy_passwd;
3277 +
3278 + hash_table_t pkg_hash;
3279 + hash_table_t file_hash;
3280 + hash_table_t obs_file_hash;
3281 +};
3282 +
3283 +enum ipkg_option_type {
3284 + IPKG_OPT_TYPE_BOOL,
3285 + IPKG_OPT_TYPE_INT,
3286 + IPKG_OPT_TYPE_STRING
3287 +};
3288 +typedef enum ipkg_option_type ipkg_option_type_t;
3289 +
3290 +typedef struct ipkg_option ipkg_option_t;
3291 +struct ipkg_option {
3292 + const char *name;
3293 + const ipkg_option_type_t type;
3294 + const void *value;
3295 +};
3296 +
3297 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3298 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3299 +
3300 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3301 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3302 +
3303 +#endif
3304 Index: busybox-1.7.2/archival/libipkg/ipkg_configure.c
3305 ===================================================================
3306 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3307 +++ busybox-1.7.2/archival/libipkg/ipkg_configure.c 2007-10-30 15:35:05.000000000 -0500
3308 @@ -0,0 +1,40 @@
3309 +/* ipkg_configure.c - the itsy package management system
3310 +
3311 + Carl D. Worth
3312 +
3313 + Copyright (C) 2001 University of Southern California
3314 +
3315 + This program is free software; you can redistribute it and/or
3316 + modify it under the terms of the GNU General Public License as
3317 + published by the Free Software Foundation; either version 2, or (at
3318 + your option) any later version.
3319 +
3320 + This program is distributed in the hope that it will be useful, but
3321 + WITHOUT ANY WARRANTY; without even the implied warranty of
3322 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3323 + General Public License for more details.
3324 +*/
3325 +
3326 +#include "ipkg.h"
3327 +
3328 +#include "ipkg_configure.h"
3329 +
3330 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3331 +{
3332 + int err;
3333 +
3334 + /* DPKG_INCOMPATIBILITY:
3335 + dpkg actually does some conffile handling here, rather than at the
3336 + end of ipkg_install(). Do we care? */
3337 + /* DPKG_INCOMPATIBILITY:
3338 + dpkg actually includes a version number to this script call */
3339 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3340 + if (err) {
3341 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3342 + return err;
3343 + }
3344 +
3345 + ipkg_state_changed++;
3346 + return 0;
3347 +}
3348 +
3349 Index: busybox-1.7.2/archival/libipkg/ipkg_configure.h
3350 ===================================================================
3351 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3352 +++ busybox-1.7.2/archival/libipkg/ipkg_configure.h 2007-10-30 15:35:05.000000000 -0500
3353 @@ -0,0 +1,25 @@
3354 +/* ipkg_configure.h - the itsy package management system
3355 +
3356 + Carl D. Worth
3357 +
3358 + Copyright (C) 2001 University of Southern California
3359 +
3360 + This program is free software; you can redistribute it and/or
3361 + modify it under the terms of the GNU General Public License as
3362 + published by the Free Software Foundation; either version 2, or (at
3363 + your option) any later version.
3364 +
3365 + This program is distributed in the hope that it will be useful, but
3366 + WITHOUT ANY WARRANTY; without even the implied warranty of
3367 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3368 + General Public License for more details.
3369 +*/
3370 +
3371 +#ifndef IPKG_CONFIGURE_H
3372 +#define IPKG_CONFIGURE_H
3373 +
3374 +#include "ipkg_conf.h"
3375 +
3376 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3377 +
3378 +#endif
3379 Index: busybox-1.7.2/archival/libipkg/ipkg_download.c
3380 ===================================================================
3381 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3382 +++ busybox-1.7.2/archival/libipkg/ipkg_download.c 2007-10-30 15:35:05.000000000 -0500
3383 @@ -0,0 +1,195 @@
3384 +/* ipkg_download.c - the itsy package management system
3385 +
3386 + Carl D. Worth
3387 +
3388 + Copyright (C) 2001 University of Southern California
3389 +
3390 + This program is free software; you can redistribute it and/or
3391 + modify it under the terms of the GNU General Public License as
3392 + published by the Free Software Foundation; either version 2, or (at
3393 + your option) any later version.
3394 +
3395 + This program is distributed in the hope that it will be useful, but
3396 + WITHOUT ANY WARRANTY; without even the implied warranty of
3397 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3398 + General Public License for more details.
3399 +*/
3400 +
3401 +#include "ipkg.h"
3402 +#include "ipkg_download.h"
3403 +#include "ipkg_message.h"
3404 +
3405 +#include "sprintf_alloc.h"
3406 +#include "xsystem.h"
3407 +#include "file_util.h"
3408 +#include "str_util.h"
3409 +
3410 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3411 +{
3412 + int err = 0;
3413 +
3414 + char *src_basec = strdup(src);
3415 + char *src_base = basename(src_basec);
3416 + char *tmp_file_location;
3417 + char *cmd;
3418 +
3419 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3420 +
3421 + fflush(stdout);
3422 +
3423 + if (str_starts_with(src, "file:")) {
3424 + int ret;
3425 + const char *file_src = src + 5;
3426 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3427 + ret = file_copy(src + 5, dest_file_name);
3428 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3429 + return ret;
3430 + }
3431 +
3432 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3433 + err = unlink(tmp_file_location);
3434 + if (err && errno != ENOENT) {
3435 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3436 + __FUNCTION__, tmp_file_location, strerror(errno));
3437 + free(tmp_file_location);
3438 + return errno;
3439 + }
3440 +
3441 + if (conf->http_proxy) {
3442 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3443 + setenv("http_proxy", conf->http_proxy, 1);
3444 + }
3445 + if (conf->ftp_proxy) {
3446 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3447 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3448 + }
3449 + if (conf->no_proxy) {
3450 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3451 + setenv("no_proxy", conf->no_proxy, 1);
3452 + }
3453 +
3454 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3455 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3456 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3457 + conf->proxy_user ? "--proxy-user=" : "",
3458 + conf->proxy_user ? conf->proxy_user : "",
3459 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3460 + conf->proxy_passwd ? conf->proxy_passwd : "",
3461 + conf->verbose_wget ? "" : "-q",
3462 + conf->tmp_dir,
3463 + src);
3464 + err = xsystem(cmd);
3465 + if (err) {
3466 + if (err != -1) {
3467 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3468 + __FUNCTION__, err, cmd);
3469 + }
3470 + unlink(tmp_file_location);
3471 + free(tmp_file_location);
3472 + free(src_basec);
3473 + free(cmd);
3474 + return EINVAL;
3475 + }
3476 + free(cmd);
3477 +
3478 + err = file_move(tmp_file_location, dest_file_name);
3479 +
3480 + free(tmp_file_location);
3481 + free(src_basec);
3482 +
3483 + if (err) {
3484 + return err;
3485 + }
3486 +
3487 + return 0;
3488 +}
3489 +
3490 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3491 +{
3492 + int err;
3493 + char *url;
3494 +
3495 + if (pkg->src == NULL) {
3496 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3497 + pkg->name, pkg->parent->name);
3498 + return -1;
3499 + }
3500 +
3501 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3502 +
3503 + /* XXX: BUG: The pkg->filename might be something like
3504 + "../../foo.ipk". While this is correct, and exactly what we
3505 + want to use to construct url above, here we actually need to
3506 + use just the filename part, without any directory. */
3507 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3508 +
3509 + err = ipkg_download(conf, url, pkg->local_filename);
3510 + free(url);
3511 +
3512 + return err;
3513 +}
3514 +
3515 +/*
3516 + * Downloads file from url, installs in package database, return package name.
3517 + */
3518 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3519 +{
3520 + int err = 0;
3521 + pkg_t *pkg;
3522 + pkg = pkg_new();
3523 + if (pkg == NULL)
3524 + return ENOMEM;
3525 +
3526 + if (str_starts_with(url, "http://")
3527 + || str_starts_with(url, "ftp://")) {
3528 + char *tmp_file;
3529 + char *file_basec = strdup(url);
3530 + char *file_base = basename(file_basec);
3531 +
3532 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3533 + err = ipkg_download(conf, url, tmp_file);
3534 + if (err)
3535 + return err;
3536 +
3537 + err = pkg_init_from_file(pkg, tmp_file);
3538 + if (err)
3539 + return err;
3540 + pkg->local_filename = strdup(tmp_file);
3541 +
3542 + free(tmp_file);
3543 + free(file_basec);
3544 +
3545 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3546 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3547 +
3548 + err = pkg_init_from_file(pkg, url);
3549 + if (err)
3550 + return err;
3551 + pkg->local_filename = strdup(url);
3552 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3553 + pkg->provided_by_hand = 1;
3554 +
3555 + } else {
3556 + pkg_deinit(pkg);
3557 + free(pkg);
3558 + return 0;
3559 + }
3560 +
3561 + if (!pkg->architecture) {
3562 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3563 + return -EINVAL;
3564 + }
3565 +
3566 + pkg->dest = conf->default_dest;
3567 + pkg->state_want = SW_INSTALL;
3568 + pkg->state_flag |= SF_PREFER;
3569 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3570 + if ( pkg == NULL ){
3571 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3572 + return 0;
3573 + }
3574 + if (namep) {
3575 + *namep = strdup(pkg->name);
3576 + }
3577 + return 0;
3578 +}
3579 Index: busybox-1.7.2/archival/libipkg/ipkg_download.h
3580 ===================================================================
3581 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3582 +++ busybox-1.7.2/archival/libipkg/ipkg_download.h 2007-10-30 15:35:05.000000000 -0500
3583 @@ -0,0 +1,30 @@
3584 +/* ipkg_download.h - the itsy package management system
3585 +
3586 + Carl D. Worth
3587 +
3588 + Copyright (C) 2001 University of Southern California
3589 +
3590 + This program is free software; you can redistribute it and/or
3591 + modify it under the terms of the GNU General Public License as
3592 + published by the Free Software Foundation; either version 2, or (at
3593 + your option) any later version.
3594 +
3595 + This program is distributed in the hope that it will be useful, but
3596 + WITHOUT ANY WARRANTY; without even the implied warranty of
3597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3598 + General Public License for more details.
3599 +*/
3600 +
3601 +#ifndef IPKG_DOWNLOAD_H
3602 +#define IPKG_DOWNLOAD_H
3603 +
3604 +#include "ipkg_conf.h"
3605 +
3606 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3607 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3608 +/*
3609 + * Downloads file from url, installs in package database, return package name.
3610 + */
3611 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3612 +
3613 +#endif
3614 Index: busybox-1.7.2/archival/libipkg/ipkg.h
3615 ===================================================================
3616 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3617 +++ busybox-1.7.2/archival/libipkg/ipkg.h 2007-10-30 15:35:05.000000000 -0500
3618 @@ -0,0 +1,74 @@
3619 +/* ipkg.h - the itsy package management system
3620 +
3621 + Carl D. Worth
3622 +
3623 + Copyright (C) 2001 University of Southern California
3624 +
3625 + This program is free software; you can redistribute it and/or
3626 + modify it under the terms of the GNU General Public License as
3627 + published by the Free Software Foundation; either version 2, or (at
3628 + your option) any later version.
3629 +
3630 + This program is distributed in the hope that it will be useful, but
3631 + WITHOUT ANY WARRANTY; without even the implied warranty of
3632 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3633 + General Public License for more details.
3634 +*/
3635 +
3636 +#ifndef IPKG_H
3637 +#define IPKG_H
3638 +
3639 +/*
3640 +#ifdef HAVE_CONFIG_H
3641 +#include "config.h"
3642 +#endif
3643 +*/
3644 +
3645 +#if 0
3646 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3647 +#endif
3648 +
3649 +#include "ipkg_includes.h"
3650 +#include "ipkg_conf.h"
3651 +#include "ipkg_message.h"
3652 +
3653 +#define IPKG_PKG_EXTENSION ".ipk"
3654 +#define DPKG_PKG_EXTENSION ".deb"
3655 +
3656 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3657 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3658 +
3659 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3660 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3661 +#define IPKG_INFO_DIR_SUFFIX "info"
3662 +#define IPKG_STATUS_FILE_SUFFIX "status"
3663 +
3664 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3665 +
3666 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3667 +
3668 +#define IPKG_VERSION "0.99.162"
3669 +
3670 +
3671 +enum ipkg_error {
3672 + IPKG_SUCCESS = 0,
3673 + IPKG_PKG_DEPS_UNSATISFIED,
3674 + IPKG_PKG_IS_ESSENTIAL,
3675 + IPKG_PKG_HAS_DEPENDENTS,
3676 + IPKG_PKG_HAS_NO_CANDIDATE
3677 +};
3678 +typedef enum ipkg_error ipkg_error_t;
3679 +
3680 +extern int ipkg_state_changed;
3681 +
3682 +
3683 +struct errlist {
3684 + char * errmsg;
3685 + struct errlist * next;
3686 +} ;
3687 +
3688 +extern struct errlist* error_list;
3689 +
3690 +extern ipkg_conf_t *global_conf;
3691 +
3692 +#endif
3693 Index: busybox-1.7.2/archival/libipkg/ipkg_includes.h
3694 ===================================================================
3695 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3696 +++ busybox-1.7.2/archival/libipkg/ipkg_includes.h 2007-10-30 15:35:05.000000000 -0500
3697 @@ -0,0 +1,79 @@
3698 +#ifndef IPKG_INCLUDES_H
3699 +#define IPKG_INCLUDES_H
3700 +
3701 +/* Define to 1 if you have the <memory.h> header file. */
3702 +#define HAVE_MEMORY_H 1
3703 +
3704 +/* Define to 1 if you have the <regex.h> header file. */
3705 +#define HAVE_REGEX_H 1
3706 +
3707 +/* Define to 1 if you have the <stdlib.h> header file. */
3708 +#define HAVE_STDLIB_H 1
3709 +
3710 +/* Define to 1 if you have the <strings.h> header file. */
3711 +#define HAVE_STRINGS_H 1
3712 +
3713 +/* Define to 1 if you have the <string.h> header file. */
3714 +#define HAVE_STRING_H 1
3715 +
3716 +/* Define to 1 if you have the <sys/stat.h> header file. */
3717 +#define HAVE_SYS_STAT_H 1
3718 +
3719 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3720 +#define HAVE_SYS_WAIT_H 1
3721 +
3722 +/* Define to 1 if you have the <unistd.h> header file. */
3723 +#define HAVE_UNISTD_H 1
3724 +
3725 +/* Define to 1 if you have the ANSI C header files. */
3726 +#define STDC_HEADERS 1
3727 +
3728 +
3729 +#include <stdio.h>
3730 +
3731 +#if STDC_HEADERS
3732 +# include <stdlib.h>
3733 +# include <stdarg.h>
3734 +# include <stddef.h>
3735 +# include <ctype.h>
3736 +# include <errno.h>
3737 +#else
3738 +# if HAVE_STDLIB_H
3739 +# include <stdlib.h>
3740 +# endif
3741 +#endif
3742 +
3743 +#if HAVE_REGEX_H
3744 +# include <regex.h>
3745 +#endif
3746 +
3747 +#if HAVE_STRING_H
3748 +# if !STDC_HEADERS && HAVE_MEMORY_H
3749 +# include <memory.h>
3750 +# endif
3751 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3752 +# if __GNUC__
3753 +# define __USE_GNU 1
3754 +# endif
3755 +# include <string.h>
3756 +# undef __USE_GNU
3757 +#endif
3758 +
3759 +#if HAVE_STRINGS_H
3760 +# include <strings.h>
3761 +#endif
3762 +
3763 +#if HAVE_SYS_STAT_H
3764 +# include <sys/stat.h>
3765 +#endif
3766 +
3767 +#if HAVE_SYS_WAIT_H
3768 +# include <sys/wait.h>
3769 +#endif
3770 +
3771 +#if HAVE_UNISTD_H
3772 +# include <sys/types.h>
3773 +# include <unistd.h>
3774 +#endif
3775 +
3776 +#endif /* IPKG_INCLUDES_H */
3777 Index: busybox-1.7.2/archival/libipkg/ipkg_install.c
3778 ===================================================================
3779 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3780 +++ busybox-1.7.2/archival/libipkg/ipkg_install.c 2007-10-30 15:35:05.000000000 -0500
3781 @@ -0,0 +1,1942 @@
3782 +/* ipkg_install.c - the itsy package management system
3783 +
3784 + Carl D. Worth
3785 +
3786 + Copyright (C) 2001 University of Southern California
3787 +
3788 + This program is free software; you can redistribute it and/or
3789 + modify it under the terms of the GNU General Public License as
3790 + published by the Free Software Foundation; either version 2, or (at
3791 + your option) any later version.
3792 +
3793 + This program is distributed in the hope that it will be useful, but
3794 + WITHOUT ANY WARRANTY; without even the implied warranty of
3795 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3796 + General Public License for more details.
3797 +*/
3798 +
3799 +#include "ipkg.h"
3800 +#include <errno.h>
3801 +#include <dirent.h>
3802 +#include <glob.h>
3803 +#include <time.h>
3804 +#include <signal.h>
3805 +typedef void (*sighandler_t)(int);
3806 +
3807 +#include "pkg.h"
3808 +#include "pkg_hash.h"
3809 +#include "pkg_extract.h"
3810 +
3811 +#include "ipkg_install.h"
3812 +#include "ipkg_configure.h"
3813 +#include "ipkg_download.h"
3814 +#include "ipkg_remove.h"
3815 +
3816 +#include "ipkg_utils.h"
3817 +#include "ipkg_message.h"
3818 +
3819 +#include "sprintf_alloc.h"
3820 +#include "file_util.h"
3821 +#include "str_util.h"
3822 +#include "xsystem.h"
3823 +#include "user.h"
3824 +
3825 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3826 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3827 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3828 +
3829 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3830 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3831 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3832 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3833 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3834 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3842 +
3843 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3846 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3847 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3848 +
3849 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3850 +
3851 +static int user_prefers_old_conffile(const char *file, const char *backup);
3852 +
3853 +static char *backup_filename_alloc(const char *file_name);
3854 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3855 +static int backup_exists_for(const char *file_name);
3856 +static int backup_remove(const char *file_name);
3857 +
3858 +
3859 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3860 +{
3861 + int err, cmp;
3862 + pkg_t *pkg, *old;
3863 + char *old_version, *new_version;
3864 +
3865 + pkg = pkg_new();
3866 + if (pkg == NULL) {
3867 + return ENOMEM;
3868 + }
3869 +
3870 + err = pkg_init_from_file(pkg, filename);
3871 + if (err) {
3872 + return err;
3873 + }
3874 +
3875 + if (!pkg->architecture) {
3876 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3877 + return -EINVAL;
3878 + }
3879 +
3880 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3881 + freeing the pkg that we pass in. It might be nice to clean this up
3882 + if possible. */
3883 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3884 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3885 +
3886 + pkg->local_filename = strdup(filename);
3887 +
3888 + if (old) {
3889 + old_version = pkg_version_str_alloc(old);
3890 + new_version = pkg_version_str_alloc(pkg);
3891 +
3892 + cmp = pkg_compare_versions(old, pkg);
3893 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3894 + cmp = -1 ; /* then we force ipkg to downgrade */
3895 + /* We need to use a value < 0 because in the 0 case we are asking to */
3896 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3897 + }
3898 + if (cmp > 0) {
3899 + ipkg_message(conf, IPKG_NOTICE,
3900 + "Not downgrading package %s on %s from %s to %s.\n",
3901 + old->name, old->dest->name, old_version, new_version);
3902 + pkg->state_want = SW_DEINSTALL;
3903 + pkg->state_flag |= SF_OBSOLETE;
3904 + free(old_version);
3905 + free(new_version);
3906 + return 0;
3907 + } else {
3908 + free(old_version);
3909 + free(new_version);
3910 + }
3911 + }
3912 +
3913 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3914 + return ipkg_install_pkg(conf, pkg,0);
3915 +}
3916 +
3917 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3918 +{
3919 + int cmp;
3920 + pkg_t *old, *new;
3921 + char *old_version, *new_version;
3922 +
3923 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3924 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3925 + if ( old )
3926 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3927 +
3928 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3929 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3930 + if ( new )
3931 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3932 +
3933 +/* Pigi Basically here is broken the version stuff.
3934 + What's happening is that nothing provide the version to differents
3935 + functions, so the returned struct is always the latest.
3936 + That's why the install by name don't work.
3937 +*/
3938 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3939 +
3940 + if ( old )
3941 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3942 + if ( new )
3943 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3944 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3945 +
3946 + if (new == NULL) {
3947 + return IPKG_PKG_HAS_NO_CANDIDATE;
3948 + }
3949 +
3950 + new->state_flag |= SF_USER;
3951 + if (old) {
3952 + old_version = pkg_version_str_alloc(old);
3953 + new_version = pkg_version_str_alloc(new);
3954 +
3955 + cmp = pkg_compare_versions(old, new);
3956 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3957 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3958 + cmp = -1 ; /* then we force ipkg to downgrade */
3959 + /* We need to use a value < 0 because in the 0 case we are asking to */
3960 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3961 + }
3962 + ipkg_message(conf, IPKG_DEBUG,
3963 + "Comparing visible versions of pkg %s:"
3964 + "\n\t%s is installed "
3965 + "\n\t%s is available "
3966 + "\n\t%d was comparison result\n",
3967 + pkg_name, old_version, new_version, cmp);
3968 + if (cmp == 0 && !conf->force_reinstall) {
3969 + ipkg_message(conf, IPKG_NOTICE,
3970 + "Package %s (%s) installed in %s is up to date.\n",
3971 + old->name, old_version, old->dest->name);
3972 + free(old_version);
3973 + free(new_version);
3974 + return 0;
3975 + } else if (cmp > 0) {
3976 + ipkg_message(conf, IPKG_NOTICE,
3977 + "Not downgrading package %s on %s from %s to %s.\n",
3978 + old->name, old->dest->name, old_version, new_version);
3979 + free(old_version);
3980 + free(new_version);
3981 + return 0;
3982 + } else if (cmp < 0) {
3983 + new->dest = old->dest;
3984 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3985 + }
3986 + }
3987 +
3988 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3989 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3990 + return any kind of integer, (might be errno from a syscall,
3991 + etc.). This is a real mess and will need to be cleaned up if
3992 + anyone ever wants to make a nice libipkg. */
3993 +
3994 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3995 + return ipkg_install_pkg(conf, new,0);
3996 +}
3997 +
3998 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
3999 +{
4000 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4001 + int i;
4002 + ipkg_error_t err;
4003 + abstract_pkg_t *ppkg ;
4004 +
4005 + if (providers == NULL)
4006 + return IPKG_PKG_HAS_NO_CANDIDATE;
4007 +
4008 + for (i = 0; i < providers->len; i++) {
4009 + ppkg = abstract_pkg_vec_get(providers, i);
4010 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4011 + err = ipkg_install_by_name(conf, ppkg->name);
4012 + if (err)
4013 + return err;
4014 +/* XXX Maybe ppkg should be freed ? */
4015 + }
4016 + return 0;
4017 +}
4018 +
4019 +/*
4020 + * Walk dependence graph starting with pkg, collect packages to be
4021 + * installed into pkgs_needed, in dependence order.
4022 + */
4023 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4024 +{
4025 + int i, err;
4026 + pkg_vec_t *depends = pkg_vec_alloc();
4027 + char **unresolved = NULL;
4028 + int ndepends;
4029 +
4030 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4031 + pkg, depends,
4032 + &unresolved);
4033 +
4034 + if (unresolved) {
4035 + ipkg_message(conf, IPKG_ERROR,
4036 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4037 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4038 + while (*unresolved) {
4039 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4040 + unresolved++;
4041 + }
4042 + ipkg_message(conf, IPKG_ERROR, "\n");
4043 + if (! conf->force_depends) {
4044 + ipkg_message(conf, IPKG_INFO,
4045 + "This could mean that your package list is out of date or that the packages\n"
4046 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4047 + "of this problem try again with the '-force-depends' option.\n");
4048 + pkg_vec_free(depends);
4049 + return IPKG_PKG_DEPS_UNSATISFIED;
4050 + }
4051 + }
4052 +
4053 + if (ndepends <= 0) {
4054 + pkg_vec_free(depends);
4055 + return 0;
4056 + }
4057 +
4058 + for (i = 0; i < depends->len; i++) {
4059 + pkg_t *dep = depends->pkgs[i];
4060 + /* The package was uninstalled when we started, but another
4061 + dep earlier in this loop may have depended on it and pulled
4062 + it in, so check first. */
4063 + if ((dep->state_status != SS_INSTALLED)
4064 + && (dep->state_status != SS_UNPACKED)
4065 + && (dep->state_want != SW_INSTALL)) {
4066 +
4067 + /* Mark packages as to-be-installed */
4068 + dep->state_want = SW_INSTALL;
4069 +
4070 + /* Dependencies should be installed the same place as pkg */
4071 + if (dep->dest == NULL) {
4072 + dep->dest = pkg->dest;
4073 + }
4074 +
4075 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4076 + if (err) {
4077 + pkg_vec_free(depends);
4078 + return err;
4079 + }
4080 + }
4081 + }
4082 + if (pkgs_needed)
4083 + pkg_vec_insert(pkgs_needed, pkg);
4084 +
4085 + pkg_vec_free(depends);
4086 +
4087 + return 0;
4088 +}
4089 +
4090 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4091 +{
4092 + int cmp;
4093 + pkg_t *old, *new;
4094 + char *old_version, *new_version;
4095 +
4096 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4097 +
4098 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4099 + if (new == NULL) {
4100 + return IPKG_PKG_HAS_NO_CANDIDATE;
4101 + }
4102 + if (old) {
4103 + old_version = pkg_version_str_alloc(old);
4104 + new_version = pkg_version_str_alloc(new);
4105 +
4106 + cmp = pkg_compare_versions(old, new);
4107 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4108 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4109 + cmp = -1 ; /* then we force ipkg to downgrade */
4110 + /* We need to use a value < 0 because in the 0 case we are asking to */
4111 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4112 + }
4113 + ipkg_message(conf, IPKG_DEBUG,
4114 + "comparing visible versions of pkg %s:"
4115 + "\n\t%s is installed "
4116 + "\n\t%s is available "
4117 + "\n\t%d was comparison result\n",
4118 + pkg_name, old_version, new_version, cmp);
4119 + if (cmp == 0 && !conf->force_reinstall) {
4120 + ipkg_message(conf, IPKG_NOTICE,
4121 + "Package %s (%s) installed in %s is up to date.\n",
4122 + old->name, old_version, old->dest->name);
4123 + free(old_version);
4124 + free(new_version);
4125 + return 0;
4126 + } else if (cmp > 0) {
4127 + ipkg_message(conf, IPKG_NOTICE,
4128 + "Not downgrading package %s on %s from %s to %s.\n",
4129 + old->name, old->dest->name, old_version, new_version);
4130 + free(old_version);
4131 + free(new_version);
4132 + return 0;
4133 + } else if (cmp < 0) {
4134 + new->dest = old->dest;
4135 + old->state_want = SW_DEINSTALL;
4136 + old->state_flag |= SF_OBSOLETE;
4137 + }
4138 + }
4139 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4140 +}
4141 +
4142 +\f
4143 +
4144 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4145 +{
4146 + int i, err;
4147 + pkg_vec_t *depends = pkg_vec_alloc();
4148 + pkg_t *dep;
4149 + char **unresolved = NULL;
4150 + int ndepends;
4151 +
4152 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4153 + pkg, depends,
4154 + &unresolved);
4155 +
4156 + if (unresolved) {
4157 + ipkg_message(conf, IPKG_ERROR,
4158 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4159 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4160 + while (*unresolved) {
4161 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4162 + unresolved++;
4163 + }
4164 + ipkg_message(conf, IPKG_ERROR, "\n");
4165 + if (! conf->force_depends) {
4166 + ipkg_message(conf, IPKG_INFO,
4167 + "This could mean that your package list is out of date or that the packages\n"
4168 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4169 + "of this problem try again with the '-force-depends' option.\n");
4170 + pkg_vec_free(depends);
4171 + return IPKG_PKG_DEPS_UNSATISFIED;
4172 + }
4173 + }
4174 +
4175 + if (ndepends <= 0) {
4176 + return 0;
4177 + }
4178 +
4179 + /* Mark packages as to-be-installed */
4180 + for (i=0; i < depends->len; i++) {
4181 + /* Dependencies should be installed the same place as pkg */
4182 + if (depends->pkgs[i]->dest == NULL) {
4183 + depends->pkgs[i]->dest = pkg->dest;
4184 + }
4185 + depends->pkgs[i]->state_want = SW_INSTALL;
4186 + }
4187 +
4188 + for (i = 0; i < depends->len; i++) {
4189 + dep = depends->pkgs[i];
4190 + /* The package was uninstalled when we started, but another
4191 + dep earlier in this loop may have depended on it and pulled
4192 + it in, so check first. */
4193 + if ((dep->state_status != SS_INSTALLED)
4194 + && (dep->state_status != SS_UNPACKED)) {
4195 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4196 + err = ipkg_install_pkg(conf, dep,0);
4197 + if (err) {
4198 + pkg_vec_free(depends);
4199 + return err;
4200 + }
4201 + }
4202 + }
4203 +
4204 + pkg_vec_free(depends);
4205 +
4206 + return 0;
4207 +}
4208 +
4209 +
4210 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4211 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4212 +{
4213 + if (conf->nodeps == 0) {
4214 + int i;
4215 + pkg_vec_t *installed = pkg_vec_alloc();
4216 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4217 + for (i = 0; i < installed->len; i++) {
4218 + pkg_t *pkg = installed->pkgs[i];
4219 + satisfy_dependencies_for(conf, pkg);
4220 + }
4221 + pkg_vec_free(installed);
4222 + }
4223 + return 0;
4224 +}
4225 +
4226 +\f
4227 +
4228 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4229 +{
4230 + int i;
4231 + pkg_vec_t *conflicts = NULL;
4232 + int level;
4233 + const char *prefix;
4234 + if (conf->force_depends) {
4235 + level = IPKG_NOTICE;
4236 + prefix = "Warning";
4237 + } else {
4238 + level = IPKG_ERROR;
4239 + prefix = "ERROR";
4240 + }
4241 +
4242 + if (!conf->force_depends)
4243 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4244 +
4245 + if (conflicts) {
4246 + ipkg_message(conf, level,
4247 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4248 + i = 0;
4249 + while (i < conflicts->len)
4250 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4251 + ipkg_message(conf, level, "\n");
4252 + pkg_vec_free(conflicts);
4253 + return IPKG_PKG_DEPS_UNSATISFIED;
4254 + }
4255 + return 0;
4256 +}
4257 +
4258 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4259 +{
4260 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4261 + str_list_elt_t *iter;
4262 +
4263 + for (iter = new_list->head; iter; iter = iter->next) {
4264 + char *new_file = iter->data;
4265 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4266 + if (!new_file)
4267 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4268 + if (!owner || (owner == old_pkg))
4269 + file_hash_set_file_owner(conf, new_file, new_pkg);
4270 + }
4271 + if (old_pkg) {
4272 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4273 + for (iter = old_list->head; iter; iter = iter->next) {
4274 + char *old_file = iter->data;
4275 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4276 + if (owner == old_pkg) {
4277 + /* obsolete */
4278 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4279 + }
4280 + }
4281 + }
4282 + return 0;
4283 +}
4284 +
4285 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4286 +{
4287 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4288 +
4289 + /* sma 6.20.02: yup; here's the first bit */
4290 + /*
4291 + * XXX: BUG easy for cworth
4292 + * 1) please point the call below to the correct current root destination
4293 + * 2) we need to resolve how to check the required space for a pending pkg,
4294 + * my diddling with the .ipk file size below isn't going to cut it.
4295 + * 3) return a proper error code instead of 1
4296 + */
4297 + int comp_size, blocks_available;
4298 +
4299 + if (!conf->force_space && pkg->installed_size != NULL) {
4300 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4301 +
4302 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4303 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4304 + comp_size = (int)((comp_size + 1023) / 1024);
4305 +
4306 + if (comp_size >= blocks_available) {
4307 + ipkg_message(conf, IPKG_ERROR,
4308 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4309 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4310 + return ENOSPC;
4311 + }
4312 + }
4313 + return 0;
4314 +}
4315 +
4316 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4317 +{
4318 + int err;
4319 + char *conffiles_file_name;
4320 + char *root_dir;
4321 + FILE *conffiles_file;
4322 +
4323 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4324 +
4325 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4326 + if (pkg->tmp_unpack_dir == NULL) {
4327 + ipkg_message(conf, IPKG_ERROR,
4328 + "%s: Failed to create temporary directory '%s': %s\n",
4329 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4330 + return errno;
4331 + }
4332 +
4333 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4334 + if (err) {
4335 + return err;
4336 + }
4337 +
4338 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4339 + conffiles. Seems like I should be able to get everything to go
4340 + through pkg_init_from_file. If so, maybe it would make sense to
4341 + move all of unpack_pkg_control_files to that function. */
4342 +
4343 + /* Don't need to re-read conffiles if we already have it */
4344 + if (pkg->conffiles.head) {
4345 + return 0;
4346 + }
4347 +
4348 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4349 + if (! file_exists(conffiles_file_name)) {
4350 + free(conffiles_file_name);
4351 + return 0;
4352 + }
4353 +
4354 + conffiles_file = fopen(conffiles_file_name, "r");
4355 + if (conffiles_file == NULL) {
4356 + fprintf(stderr, "%s: failed to open %s: %s\n",
4357 + __FUNCTION__, conffiles_file_name, strerror(errno));
4358 + free(conffiles_file_name);
4359 + return errno;
4360 + }
4361 + free(conffiles_file_name);
4362 +
4363 + while (1) {
4364 + char *cf_name;
4365 + char *cf_name_in_dest;
4366 +
4367 + cf_name = file_read_line_alloc(conffiles_file);
4368 + if (cf_name == NULL) {
4369 + break;
4370 + }
4371 + str_chomp(cf_name);
4372 + if (cf_name[0] == '\0') {
4373 + continue;
4374 + }
4375 +
4376 + /* Prepend dest->root_dir to conffile name.
4377 + Take pains to avoid multiple slashes. */
4378 + root_dir = pkg->dest->root_dir;
4379 + if (conf->offline_root)
4380 + /* skip the offline_root prefix */
4381 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4382 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4383 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4384 +
4385 + /* Can't get an md5sum now, (file isn't extracted yet).
4386 + We'll wait until resolve_conffiles */
4387 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4388 +
4389 + free(cf_name);
4390 + free(cf_name_in_dest);
4391 + }
4392 +
4393 + fclose(conffiles_file);
4394 +
4395 + return 0;
4396 +}
4397 +
4398 +/* returns number of installed replacees */
4399 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4400 +{
4401 + abstract_pkg_t **replaces = pkg->replaces;
4402 + int replaces_count = pkg->replaces_count;
4403 + int i, j;
4404 + for (i = 0; i < replaces_count; i++) {
4405 + abstract_pkg_t *ab_pkg = replaces[i];
4406 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4407 + if (pkg_vec) {
4408 + for (j = 0; j < pkg_vec->len; j++) {
4409 + pkg_t *replacee = pkg_vec->pkgs[j];
4410 + if (!pkg_conflicts(pkg, replacee))
4411 + continue;
4412 + if (replacee->state_status == SS_INSTALLED) {
4413 + pkg_vec_insert(installed_replacees, replacee);
4414 + }
4415 + }
4416 + }
4417 + }
4418 + return installed_replacees->len;
4419 +}
4420 +
4421 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4422 +{
4423 + int i;
4424 + int replaces_count = replacees->len;
4425 + for (i = 0; i < replaces_count; i++) {
4426 + pkg_t *replacee = replacees->pkgs[i];
4427 + int err;
4428 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4429 + err = ipkg_remove_pkg(conf, replacee,0);
4430 + if (err)
4431 + return err;
4432 + }
4433 + return 0;
4434 +}
4435 +
4436 +/* to unwind the removal: make sure they are installed */
4437 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4438 +{
4439 + int i, err;
4440 + int replaces_count = replacees->len;
4441 + for (i = 0; i < replaces_count; i++) {
4442 + pkg_t *replacee = replacees->pkgs[i];
4443 + if (replacee->state_status != SS_INSTALLED) {
4444 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4445 + err = ipkg_install_pkg(conf, replacee,0);
4446 + if (err)
4447 + return err;
4448 + }
4449 + }
4450 + return 0;
4451 +}
4452 +
4453 +int caught_sigint = 0;
4454 +static void ipkg_install_pkg_sigint_handler(int sig)
4455 +{
4456 + caught_sigint = sig;
4457 +}
4458 +
4459 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4460 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4461 +{
4462 + if (old_pkg) {
4463 + char message_out[15];
4464 + char *old_version = pkg_version_str_alloc(old_pkg);
4465 + char *new_version = pkg_version_str_alloc(pkg);
4466 + int cmp = pkg_compare_versions(old_pkg, pkg);
4467 + int rc = 0;
4468 +
4469 + memset(message_out,'\x0',15);
4470 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4471 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4472 + cmp = -1 ; /* then we force ipkg to downgrade */
4473 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4474 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4475 + }
4476 +
4477 + if (cmp > 0) {
4478 + ipkg_message(conf, IPKG_NOTICE,
4479 + "Not downgrading package %s on %s from %s to %s.\n",
4480 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4481 + rc = 1;
4482 + } else if (cmp < 0) {
4483 + ipkg_message(conf, IPKG_NOTICE,
4484 + "%s%s on %s from %s to %s...\n",
4485 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4486 + pkg->dest = old_pkg->dest;
4487 + rc = 0;
4488 + } else /* cmp == 0 */ {
4489 + if (conf->force_reinstall) {
4490 + ipkg_message(conf, IPKG_NOTICE,
4491 + "Reinstalling %s (%s) on %s...\n",
4492 + pkg->name, new_version, old_pkg->dest->name);
4493 + pkg->dest = old_pkg->dest;
4494 + rc = 0;
4495 + } else {
4496 + ipkg_message(conf, IPKG_NOTICE,
4497 + "Not installing %s (%s) on %s -- already installed.\n",
4498 + pkg->name, new_version, old_pkg->dest->name);
4499 + rc = 1;
4500 + }
4501 + }
4502 + free(old_version);
4503 + free(new_version);
4504 + return rc;
4505 + } else {
4506 + char message_out[15], *version ;
4507 + memset(message_out,'\x0',15);
4508 + if ( message )
4509 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4510 + else
4511 + strncpy( message_out,"Installing ",strlen("Installing ") );
4512 + version = pkg_version_str_alloc(pkg);
4513 +
4514 + ipkg_message(conf, IPKG_NOTICE,
4515 + "%s%s (%s) to %s...\n", message_out,
4516 + pkg->name, version, pkg->dest->name);
4517 + free(version);
4518 + return 0;
4519 + }
4520 +}
4521 +
4522 +/* and now the meat... */
4523 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4524 +{
4525 + int err = 0;
4526 + int message = 0;
4527 + pkg_t *old_pkg = NULL;
4528 + pkg_vec_t *replacees;
4529 + abstract_pkg_t *ab_pkg = NULL;
4530 + int old_state_flag;
4531 + char* file_md5;
4532 +
4533 +
4534 + if ( from_upgrade )
4535 + message = 1; /* Coming from an upgrade, and should change the output message */
4536 +
4537 + if (!pkg) {
4538 + ipkg_message(conf, IPKG_ERROR,
4539 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4540 + return -EINVAL;
4541 + }
4542 +
4543 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4544 +
4545 + if (!pkg_arch_supported(conf, pkg)) {
4546 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4547 + pkg->architecture, pkg->name);
4548 + return -EINVAL;
4549 + }
4550 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4551 + err = satisfy_dependencies_for(conf, pkg);
4552 + if (err) { return err; }
4553 +
4554 + ipkg_message(conf, IPKG_NOTICE,
4555 + "Package %s is already installed in %s.\n",
4556 + pkg->name, pkg->dest->name);
4557 + return 0;
4558 + }
4559 +
4560 + if (pkg->dest == NULL) {
4561 + pkg->dest = conf->default_dest;
4562 + }
4563 +
4564 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4565 +
4566 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4567 + if (err) { return err; }
4568 +
4569 + pkg->state_want = SW_INSTALL;
4570 + if (old_pkg){
4571 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4572 + }
4573 +
4574 +
4575 + /* Abhaya: conflicts check */
4576 + err = check_conflicts_for(conf, pkg);
4577 + if (err) { return err; }
4578 +
4579 + /* this setup is to remove the upgrade scenario in the end when
4580 + installing pkg A, A deps B & B deps on A. So both B and A are
4581 + installed. Then A's installation is started resulting in an
4582 + uncecessary upgrade */
4583 + if (pkg->state_status == SS_INSTALLED
4584 + && conf->force_reinstall == 0) return 0;
4585 +
4586 + err = verify_pkg_installable(conf, pkg);
4587 + if (err) { return err; }
4588 +
4589 + if (pkg->local_filename == NULL) {
4590 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4591 + if (err) {
4592 + ipkg_message(conf, IPKG_ERROR,
4593 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4594 + pkg->name);
4595 + return err;
4596 + }
4597 + }
4598 +
4599 +/* Check for md5 values */
4600 + if (pkg->md5sum)
4601 + {
4602 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4603 + if (strcmp(file_md5, pkg->md5sum))
4604 + {
4605 + ipkg_message(conf, IPKG_ERROR,
4606 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4607 + pkg->name);
4608 + free(file_md5);
4609 + return err;
4610 + }
4611 + free(file_md5);
4612 + }
4613 +
4614 + if (pkg->tmp_unpack_dir == NULL) {
4615 + unpack_pkg_control_files(conf, pkg);
4616 + }
4617 +
4618 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4619 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4620 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4621 + err = update_file_ownership(conf, pkg, old_pkg);
4622 + if (err) { return err; }
4623 +
4624 + if (conf->nodeps == 0) {
4625 + err = satisfy_dependencies_for(conf, pkg);
4626 + if (err) { return err; }
4627 + }
4628 +
4629 + replacees = pkg_vec_alloc();
4630 + pkg_get_installed_replacees(conf, pkg, replacees);
4631 +
4632 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4633 + {
4634 + sigset_t newset, oldset;
4635 + sighandler_t old_handler = NULL;
4636 + int use_signal = 0;
4637 + caught_sigint = 0;
4638 + if (use_signal) {
4639 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4640 + } else {
4641 + sigemptyset(&newset);
4642 + sigaddset(&newset, SIGINT);
4643 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4644 + }
4645 +
4646 + ipkg_state_changed++;
4647 + pkg->state_flag |= SF_FILELIST_CHANGED;
4648 +
4649 + /* XXX: BUG: we really should treat replacement more like an upgrade
4650 + * Instead, we're going to remove the replacees
4651 + */
4652 + err = pkg_remove_installed_replacees(conf, replacees);
4653 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4654 +
4655 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4656 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4657 +
4658 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4659 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4660 +
4661 + err = preinst_configure(conf, pkg, old_pkg);
4662 + if (err) goto UNWIND_PREINST_CONFIGURE;
4663 +
4664 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4665 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4666 +
4667 + err = check_data_file_clashes(conf, pkg, old_pkg);
4668 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4669 +
4670 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4672 +
4673 + if (conf->noaction) return 0;
4674 +
4675 + /* point of no return: no unwinding after this */
4676 + if (old_pkg && !conf->force_reinstall) {
4677 + old_pkg->state_want = SW_DEINSTALL;
4678 +
4679 + if (old_pkg->state_flag & SF_NOPRUNE) {
4680 + ipkg_message(conf, IPKG_INFO,
4681 + " not removing obsolesced files because package marked noprune\n");
4682 + } else {
4683 + ipkg_message(conf, IPKG_INFO,
4684 + " removing obsolesced files\n");
4685 + remove_obsolesced_files(conf, pkg, old_pkg);
4686 + }
4687 + /* removing files from old package, to avoid ghost files */
4688 + remove_data_files_and_list(conf, old_pkg);
4689 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4690 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4691 + remove_postrm(conf, old_pkg);
4692 +/* Pigi */
4693 +
4694 + }
4695 +
4696 +
4697 + ipkg_message(conf, IPKG_INFO,
4698 + " installing maintainer scripts\n");
4699 + install_maintainer_scripts(conf, pkg, old_pkg);
4700 +
4701 + /* the following just returns 0 */
4702 + remove_disappeared(conf, pkg);
4703 +
4704 + ipkg_message(conf, IPKG_INFO,
4705 + " installing data files\n");
4706 + install_data_files(conf, pkg);
4707 +
4708 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4709 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4710 +
4711 + ipkg_message(conf, IPKG_INFO,
4712 + " resolving conf files\n");
4713 + resolve_conffiles(conf, pkg);
4714 +
4715 + pkg->state_status = SS_UNPACKED;
4716 + old_state_flag = pkg->state_flag;
4717 + pkg->state_flag &= ~SF_PREFER;
4718 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4719 +
4720 + if (old_pkg && !conf->force_reinstall) {
4721 + old_pkg->state_status = SS_NOT_INSTALLED;
4722 + }
4723 +
4724 + time(&pkg->installed_time);
4725 +
4726 + ipkg_message(conf, IPKG_INFO,
4727 + " cleanup temp files\n");
4728 + cleanup_temporary_files(conf, pkg);
4729 +
4730 + ab_pkg = pkg->parent;
4731 + if (ab_pkg)
4732 + ab_pkg->state_status = pkg->state_status;
4733 +
4734 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4735 +
4736 + if (use_signal)
4737 + signal(SIGINT, old_handler);
4738 + else
4739 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4740 +
4741 + return 0;
4742 +
4743 +
4744 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4745 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4746 + UNWIND_CHECK_DATA_FILE_CLASHES:
4747 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4748 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4749 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4750 + UNWIND_PREINST_CONFIGURE:
4751 + preinst_configure_unwind(conf, pkg, old_pkg);
4752 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4753 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4754 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4755 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4756 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4757 + pkg_remove_installed_replacees_unwind(conf, replacees);
4758 +
4759 + ipkg_message(conf, IPKG_INFO,
4760 + " cleanup temp files\n");
4761 + cleanup_temporary_files(conf, pkg);
4762 +
4763 + ipkg_message(conf, IPKG_INFO,
4764 + "Failed.\n");
4765 + if (use_signal)
4766 + signal(SIGINT, old_handler);
4767 + else
4768 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4769 +
4770 + return err;
4771 + }
4772 +}
4773 +
4774 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4775 +{
4776 + /* DPKG_INCOMPATIBILITY:
4777 + dpkg does some things here that we don't do yet. Do we care?
4778 +
4779 + 1. If a version of the package is already installed, call
4780 + old-prerm upgrade new-version
4781 + 2. If the script runs but exits with a non-zero exit status
4782 + new-prerm failed-upgrade old-version
4783 + Error unwind, for both the above cases:
4784 + old-postinst abort-upgrade new-version
4785 + */
4786 + return 0;
4787 +}
4788 +
4789 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4790 +{
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4793 + (See prerm_upgrade_old_package for details)
4794 + */
4795 + return 0;
4796 +}
4797 +
4798 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4799 +{
4800 + /* DPKG_INCOMPATIBILITY:
4801 + dpkg does some things here that we don't do yet. Do we care?
4802 + 2. If a 'conflicting' package is being removed at the same time:
4803 + 1. If any packages depended on that conflicting package and
4804 + --auto-deconfigure is specified, call, for each such package:
4805 + deconfigured's-prerm deconfigure \
4806 + in-favour package-being-installed version \
4807 + removing conflicting-package version
4808 + Error unwind:
4809 + deconfigured's-postinst abort-deconfigure \
4810 + in-favour package-being-installed-but-failed version \
4811 + removing conflicting-package version
4812 +
4813 + The deconfigured packages are marked as requiring
4814 + configuration, so that if --install is used they will be
4815 + configured again if possible.
4816 + 2. To prepare for removal of the conflicting package, call:
4817 + conflictor's-prerm remove in-favour package new-version
4818 + Error unwind:
4819 + conflictor's-postinst abort-remove in-favour package new-version
4820 + */
4821 + return 0;
4822 +}
4823 +
4824 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4825 +{
4826 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4827 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4828 + details) */
4829 + return 0;
4830 +}
4831 +
4832 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4833 +{
4834 + int err;
4835 + char *preinst_args;
4836 +
4837 + if (old_pkg) {
4838 + char *old_version = pkg_version_str_alloc(old_pkg);
4839 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4840 + free(old_version);
4841 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4842 + char *pkg_version = pkg_version_str_alloc(pkg);
4843 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4844 + free(pkg_version);
4845 + } else {
4846 + preinst_args = strdup("install");
4847 + }
4848 +
4849 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4850 + if (err) {
4851 + ipkg_message(conf, IPKG_ERROR,
4852 + "Aborting installation of %s\n", pkg->name);
4853 + return 1;
4854 + }
4855 +
4856 + free(preinst_args);
4857 +
4858 + return 0;
4859 +}
4860 +
4861 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4862 +{
4863 + /* DPKG_INCOMPATIBILITY:
4864 + dpkg does the following error unwind, should we?
4865 + pkg->postrm abort-upgrade old-version
4866 + OR pkg->postrm abort-install old-version
4867 + OR pkg->postrm abort-install
4868 + */
4869 + return 0;
4870 +}
4871 +
4872 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4873 +{
4874 + int err;
4875 + conffile_list_elt_t *iter;
4876 + conffile_t *cf;
4877 +
4878 + if (conf->noaction) return 0;
4879 +
4880 + /* Backup all modified conffiles */
4881 + if (old_pkg) {
4882 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4883 + char *cf_name;
4884 +
4885 + cf = iter->data;
4886 + cf_name = root_filename_alloc(conf, cf->name);
4887 +
4888 + /* Don't worry if the conffile is just plain gone */
4889 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4890 + err = backup_make_backup(conf, cf_name);
4891 + if (err) {
4892 + return err;
4893 + }
4894 + }
4895 + free(cf_name);
4896 + }
4897 + }
4898 +
4899 + /* Backup all conffiles that were not conffiles in old_pkg */
4900 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4901 + char *cf_name;
4902 + cf = iter->data;
4903 + cf_name = root_filename_alloc(conf, cf->name);
4904 + /* Ignore if this was a conffile in old_pkg as well */
4905 + if (pkg_get_conffile(old_pkg, cf->name)) {
4906 + continue;
4907 + }
4908 +
4909 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4910 + err = backup_make_backup(conf, cf_name);
4911 + if (err) {
4912 + return err;
4913 + }
4914 + }
4915 + free(cf_name);
4916 + }
4917 +
4918 + return 0;
4919 +}
4920 +
4921 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4922 +{
4923 + conffile_list_elt_t *iter;
4924 +
4925 + if (old_pkg) {
4926 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4927 + backup_remove(iter->data->name);
4928 + }
4929 + }
4930 +
4931 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4932 + backup_remove(iter->data->name);
4933 + }
4934 +
4935 + return 0;
4936 +}
4937 +
4938 +
4939 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4940 +{
4941 + /* DPKG_INCOMPATIBILITY:
4942 + ipkg takes a slightly different approach than dpkg at this
4943 + point. dpkg installs each file in the new package while
4944 + creating a backup for any file that is replaced, (so that it
4945 + can unwind if necessary). To avoid complexity and redundant
4946 + storage, ipkg doesn't do any installation until later, (at the
4947 + point at which dpkg removes the backups.
4948 +
4949 + But, we do have to check for data file clashes, since after
4950 + installing a package with a file clash, removing either of the
4951 + packages involved in the clash has the potential to break the
4952 + other package.
4953 + */
4954 + str_list_t *files_list;
4955 + str_list_elt_t *iter;
4956 +
4957 + int clashes = 0;
4958 +
4959 + files_list = pkg_get_installed_files(pkg);
4960 + for (iter = files_list->head; iter; iter = iter->next) {
4961 + char *root_filename;
4962 + char *filename = iter->data;
4963 + root_filename = root_filename_alloc(conf, filename);
4964 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4965 + pkg_t *owner;
4966 + pkg_t *obs;
4967 + /* Pre-existing conffiles are OK */
4968 + /* @@@@ should have way to check that it is a conffile -Jamey */
4969 + if (backup_exists_for(root_filename)) {
4970 + continue;
4971 + }
4972 +
4973 + /* Pre-existing files are OK if force-overwrite was asserted. */
4974 + if (conf->force_overwrite) {
4975 + /* but we need to change who owns this file */
4976 + file_hash_set_file_owner(conf, filename, pkg);
4977 + continue;
4978 + }
4979 +
4980 + owner = file_hash_get_file_owner(conf, filename);
4981 +
4982 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4983 + if (owner && old_pkg) {
4984 + if (strcmp(owner->name, old_pkg->name) == 0) {
4985 + continue;
4986 + }
4987 + }
4988 +
4989 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4990 + if (owner) {
4991 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4992 + if (pkg_replaces(pkg, owner)) {
4993 + continue;
4994 + }
4995 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4996 + then it's ok to overwrite. */
4997 + if (strcmp(owner->name,pkg->name)==0){
4998 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4999 + continue;
5000 + }
5001 + }
5002 +
5003 + /* Pre-existing files are OK if they are obsolete */
5004 + obs = hash_table_get(&conf->obs_file_hash, filename);
5005 + if (obs) {
5006 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5007 + continue;
5008 + }
5009 +
5010 + /* We have found a clash. */
5011 + ipkg_message(conf, IPKG_ERROR,
5012 + "Package %s wants to install file %s\n"
5013 + "\tBut that file is already provided by package ",
5014 + pkg->name, filename);
5015 + if (owner) {
5016 + ipkg_message(conf, IPKG_ERROR,
5017 + "%s\n", owner->name);
5018 + } else {
5019 + ipkg_message(conf, IPKG_ERROR,
5020 + "<no package>\nPlease move this file out of the way and try again.\n");
5021 + }
5022 + clashes++;
5023 + }
5024 + free(root_filename);
5025 + }
5026 + pkg_free_installed_files(pkg);
5027 +
5028 + return clashes;
5029 +}
5030 +
5031 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5032 +{
5033 + /* Basically that's the worst hack I could do to be able to change ownership of
5034 + file list, but, being that we have no way to unwind the mods, due to structure
5035 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5036 + What we do here is change the ownership of file in hash if a replace ( or similar events
5037 + happens )
5038 + Only the action that are needed to change name should be considered.
5039 + @@@ To change after 1.0 release.
5040 + */
5041 + str_list_t *files_list;
5042 + str_list_elt_t *iter;
5043 +
5044 + int clashes = 0;
5045 +
5046 + files_list = pkg_get_installed_files(pkg);
5047 + for (iter = files_list->head; iter; iter = iter->next) {
5048 + char *root_filename;
5049 + char *filename = iter->data;
5050 + root_filename = root_filename_alloc(conf, filename);
5051 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5052 + pkg_t *owner;
5053 +
5054 + if (conf->force_overwrite) {
5055 + /* but we need to change who owns this file */
5056 + file_hash_set_file_owner(conf, filename, pkg);
5057 + continue;
5058 + }
5059 +
5060 + owner = file_hash_get_file_owner(conf, filename);
5061 +
5062 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5063 + if (owner) {
5064 + if (pkg_replaces(pkg, owner)) {
5065 +/* It's now time to change the owner of that file.
5066 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5067 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5068 + file_hash_set_file_owner(conf, filename, pkg);
5069 + continue;
5070 + }
5071 + }
5072 +
5073 + }
5074 + free(root_filename);
5075 + }
5076 + pkg_free_installed_files(pkg);
5077 +
5078 + return clashes;
5079 +}
5080 +
5081 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5082 +{
5083 + /* Nothing to do since check_data_file_clashes doesn't change state */
5084 + return 0;
5085 +}
5086 +
5087 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5088 +{
5089 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5090 + 1. If the package is being upgraded, call
5091 + old-postrm upgrade new-version
5092 + 2. If this fails, attempt:
5093 + new-postrm failed-upgrade old-version
5094 + Error unwind, for both cases:
5095 + old-preinst abort-upgrade new-version */
5096 + return 0;
5097 +}
5098 +
5099 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5100 +{
5101 + /* DPKG_INCOMPATIBILITY:
5102 + dpkg does some things here that we don't do yet. Do we care?
5103 + (See postrm_upgrade_old_pkg for details)
5104 + */
5105 + return 0;
5106 +}
5107 +
5108 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5109 +{
5110 + int err;
5111 + str_list_t *old_files;
5112 + str_list_elt_t *of;
5113 + str_list_t *new_files;
5114 + str_list_elt_t *nf;
5115 +
5116 + if (old_pkg == NULL) {
5117 + return 0;
5118 + }
5119 +
5120 + old_files = pkg_get_installed_files(old_pkg);
5121 + new_files = pkg_get_installed_files(pkg);
5122 +
5123 + for (of = old_files->head; of; of = of->next) {
5124 + pkg_t *owner;
5125 + char *old, *new;
5126 + old = of->data;
5127 + for (nf = new_files->head; nf; nf = nf->next) {
5128 + new = nf->data;
5129 + if (strcmp(old, new) == 0) {
5130 + goto NOT_OBSOLETE;
5131 + }
5132 + }
5133 + if (file_is_dir(old)) {
5134 + continue;
5135 + }
5136 + owner = file_hash_get_file_owner(conf, old);
5137 + if (owner != old_pkg) {
5138 + /* in case obsolete file no longer belongs to old_pkg */
5139 + continue;
5140 + }
5141 +
5142 + /* old file is obsolete */
5143 + ipkg_message(conf, IPKG_INFO,
5144 + " removing obsolete file %s\n", old);
5145 + if (!conf->noaction) {
5146 + err = unlink(old);
5147 + if (err) {
5148 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5149 + strerror(errno));
5150 + }
5151 + }
5152 +
5153 + NOT_OBSOLETE:
5154 + ;
5155 + }
5156 +
5157 + pkg_free_installed_files(old_pkg);
5158 + pkg_free_installed_files(pkg);
5159 +
5160 + return 0;
5161 +}
5162 +
5163 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5164 +{
5165 + int i;
5166 + int err = 0;
5167 + char *globpattern;
5168 + glob_t globbuf;
5169 + if (0) {
5170 + if (!pkg->dest) {
5171 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5172 + return -1;
5173 + }
5174 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5175 + err = glob(globpattern, 0, NULL, &globbuf);
5176 + free(globpattern);
5177 + if (err) {
5178 + return err;
5179 + }
5180 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5181 + for (i = 0; i < globbuf.gl_pathc; i++) {
5182 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5183 + globbuf.gl_pathv[i], old_pkg->name);
5184 + if (!conf->noaction)
5185 + unlink(globbuf.gl_pathv[i]);
5186 + }
5187 + globfree(&globbuf);
5188 + }
5189 + return err;
5190 +}
5191 +
5192 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5193 +{
5194 + int ret;
5195 + char *prefix;
5196 +
5197 + if (old_pkg)
5198 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5199 + sprintf_alloc(&prefix, "%s.", pkg->name);
5200 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5201 + pkg->dest->info_dir,
5202 + prefix);
5203 + free(prefix);
5204 + return ret;
5205 +}
5206 +
5207 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5208 +{
5209 + /* DPKG_INCOMPATIBILITY:
5210 + This is a fairly sophisticated dpkg operation. Shall we
5211 + skip it? */
5212 +
5213 + /* Any packages all of whose files have been overwritten during the
5214 + installation, and which aren't required for dependencies, are
5215 + considered to have been removed. For each such package
5216 + 1. disappearer's-postrm disappear overwriter overwriter-version
5217 + 2. The package's maintainer scripts are removed
5218 + 3. It is noted in the status database as being in a sane state,
5219 + namely not installed (any conffiles it may have are ignored,
5220 + rather than being removed by dpkg). Note that disappearing
5221 + packages do not have their prerm called, because dpkg doesn't
5222 + know in advance that the package is going to vanish.
5223 + */
5224 + return 0;
5225 +}
5226 +
5227 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5228 +{
5229 + int err;
5230 +
5231 + /* ipkg takes a slightly different approach to data file backups
5232 + than dpkg. Rather than removing backups at this point, we
5233 + actually do the data file installation now. See comments in
5234 + check_data_file_clashes() for more details. */
5235 +
5236 + ipkg_message(conf, IPKG_INFO,
5237 + " extracting data files to %s\n", pkg->dest->root_dir);
5238 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5239 + if (err) {
5240 + return err;
5241 + }
5242 +
5243 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5244 + so we can't save ourself from removing important packages
5245 + At this point we (should) have extracted the .control file, so it
5246 + would be a good idea to reload the data in it, and set the Essential
5247 + state in *pkg. From now on the Essential is back in status file and
5248 + we can protect again.
5249 + We should operate this way:
5250 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5251 + check for "Essential" in it
5252 + set the value in pkg->essential.
5253 + This new routine could be useful also for every other flag
5254 + Pigi: 16/03/2004 */
5255 + set_flags_from_control(conf, pkg) ;
5256 +
5257 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5258 + err = pkg_write_filelist(conf, pkg);
5259 + if (err)
5260 + return err;
5261 +
5262 + /* XXX: FEATURE: ipkg should identify any files which existed
5263 + before installation and which were overwritten, (see
5264 + check_data_file_clashes()). What it must do is remove any such
5265 + files from the filelist of the old package which provided the
5266 + file. Otherwise, if the old package were removed at some point
5267 + it would break the new package. Removing the new package will
5268 + also break the old one, but this cannot be helped since the old
5269 + package's file has already been deleted. This is the importance
5270 + of check_data_file_clashes(), and only allowing ipkg to install
5271 + a clashing package with a user force. */
5272 +
5273 + return 0;
5274 +}
5275 +
5276 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5277 +{
5278 + conffile_list_elt_t *iter;
5279 + conffile_t *cf;
5280 + char *cf_backup;
5281 +
5282 + char *md5sum;
5283 +
5284 +
5285 + if (conf->noaction) return 0;
5286 +
5287 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5288 + char *root_filename;
5289 + cf = iter->data;
5290 + root_filename = root_filename_alloc(conf, cf->name);
5291 +
5292 + /* Might need to initialize the md5sum for each conffile */
5293 + if (cf->value == NULL) {
5294 + cf->value = file_md5sum_alloc(root_filename);
5295 + }
5296 +
5297 + if (!file_exists(root_filename)) {
5298 + free(root_filename);
5299 + continue;
5300 + }
5301 +
5302 + cf_backup = backup_filename_alloc(root_filename);
5303 +
5304 +
5305 + if (file_exists(cf_backup)) {
5306 + /* Let's compute md5 to test if files are changed */
5307 + md5sum = file_md5sum_alloc(cf_backup);
5308 + if (strcmp( cf->value,md5sum) != 0 ) {
5309 + if (conf->force_defaults
5310 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5311 + rename(cf_backup, root_filename);
5312 + }
5313 + }
5314 + unlink(cf_backup);
5315 + free(md5sum);
5316 + }
5317 +
5318 + free(cf_backup);
5319 + free(root_filename);
5320 + }
5321 +
5322 + return 0;
5323 +}
5324 +
5325 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5326 +{
5327 + char *response;
5328 + const char *short_file_name;
5329 +
5330 + short_file_name = strrchr(file_name, '/');
5331 + if (short_file_name) {
5332 + short_file_name++;
5333 + } else {
5334 + short_file_name = file_name;
5335 + }
5336 +
5337 + while (1) {
5338 + response = get_user_response(" Configuration file '%s'\n"
5339 + " ==> File on system created by you or by a script.\n"
5340 + " ==> File also in package provided by package maintainer.\n"
5341 + " What would you like to do about it ? Your options are:\n"
5342 + " Y or I : install the package maintainer's version\n"
5343 + " N or O : keep your currently-installed version\n"
5344 + " D : show the differences between the versions (if diff is installed)\n"
5345 + " The default action is to keep your current version.\n"
5346 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5347 + if (strcmp(response, "y") == 0
5348 + || strcmp(response, "i") == 0
5349 + || strcmp(response, "yes") == 0) {
5350 + free(response);
5351 + return 0;
5352 + }
5353 +
5354 + if (strcmp(response, "d") == 0) {
5355 + char *cmd;
5356 +
5357 + free(response);
5358 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5359 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5360 + xsystem(cmd);
5361 + free(cmd);
5362 + printf(" [Press ENTER to continue]\n");
5363 + response = file_read_line_alloc(stdin);
5364 + free(response);
5365 + continue;
5366 + }
5367 +
5368 + free(response);
5369 + return 1;
5370 + }
5371 +}
5372 +
5373 +/* XXX: CLEANUP: I'd like to move all of the code for
5374 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5375 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5376 + pkg_deinit for example). */
5377 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5378 +{
5379 + DIR *tmp_dir;
5380 + struct dirent *dirent;
5381 + char *tmp_file;
5382 +
5383 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5384 +#error
5385 + ipkg_message(conf, IPKG_DEBUG,
5386 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5387 + __FUNCTION__, pkg->tmp_unpack_dir);
5388 + return 0;
5389 +#endif
5390 +
5391 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5392 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5393 + if (tmp_dir) {
5394 + while (1) {
5395 + dirent = readdir(tmp_dir);
5396 + if (dirent == NULL) {
5397 + break;
5398 + }
5399 + sprintf_alloc(&tmp_file, "%s/%s",
5400 + pkg->tmp_unpack_dir, dirent->d_name);
5401 + if (! file_is_dir(tmp_file)) {
5402 + unlink(tmp_file);
5403 + }
5404 + free(tmp_file);
5405 + }
5406 + closedir(tmp_dir);
5407 + rmdir(pkg->tmp_unpack_dir);
5408 + free(pkg->tmp_unpack_dir);
5409 + pkg->tmp_unpack_dir = NULL;
5410 + }
5411 + }
5412 +
5413 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5414 + pkg->name, pkg->local_filename, conf->tmp_dir);
5415 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5416 + unlink(pkg->local_filename);
5417 + free(pkg->local_filename);
5418 + pkg->local_filename = NULL;
5419 + }
5420 +
5421 + return 0;
5422 +}
5423 +
5424 +static char *backup_filename_alloc(const char *file_name)
5425 +{
5426 + char *backup;
5427 +
5428 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5429 +
5430 + return backup;
5431 +}
5432 +
5433 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5434 +{
5435 + int err;
5436 + char *backup;
5437 +
5438 + backup = backup_filename_alloc(file_name);
5439 + err = file_copy(file_name, backup);
5440 + if (err) {
5441 + ipkg_message(conf, IPKG_ERROR,
5442 + "%s: Failed to copy %s to %s\n",
5443 + __FUNCTION__, file_name, backup);
5444 + }
5445 +
5446 + free(backup);
5447 +
5448 + return err;
5449 +}
5450 +
5451 +static int backup_exists_for(const char *file_name)
5452 +{
5453 + int ret;
5454 + char *backup;
5455 +
5456 + backup = backup_filename_alloc(file_name);
5457 +
5458 + ret = file_exists(backup);
5459 +
5460 + free(backup);
5461 +
5462 + return ret;
5463 +}
5464 +
5465 +static int backup_remove(const char *file_name)
5466 +{
5467 + char *backup;
5468 +
5469 + backup = backup_filename_alloc(file_name);
5470 + unlink(backup);
5471 + free(backup);
5472 +
5473 + return 0;
5474 +}
5475 +
5476 +\f
5477 +
5478 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5479 +
5480 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5481 +{
5482 + /* first, remove the packages that need removing */
5483 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5484 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5485 + err = ipkg_remove_pkg(conf, pkg,0);
5486 + if (err) return err;
5487 + }
5488 + return 0;
5489 +}
5490 +
5491 +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)
5492 +{
5493 + int i;
5494 + /* now one more pass checking on the ones that need to be installed */
5495 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5496 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5497 + if (pkg->dest == NULL)
5498 + pkg->dest = conf->default_dest;
5499 +
5500 + pkg->state_want = SW_INSTALL;
5501 +
5502 + /* Abhaya: conflicts check */
5503 + err = check_conflicts_for(conf, pkg);
5504 + if (err) { return err; }
5505 + }
5506 + return 0;
5507 +}
5508 +
5509 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5510 +{
5511 + int i;
5512 + /* now one more pass checking on the ones that need to be installed */
5513 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5514 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5515 +
5516 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5517 + pkg_vec_t *replacees = pkg_vec_alloc();
5518 + pkg_get_installed_replacees(conf, pkg, replacees);
5519 +
5520 + /* XXX: BUG: we really should treat replacement more like an upgrade
5521 + * Instead, we're going to remove the replacees
5522 + */
5523 + err = pkg_remove_installed_replacees(conf, replacees);
5524 + if (err) return err;
5525 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5526 + }
5527 + return 0;
5528 +}
5529 +
5530 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5531 +{
5532 + int i;
5533 + /* now one more pass checking on the ones that need to be installed */
5534 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5535 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5536 + if (pkg->local_filename == NULL) {
5537 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5538 + if (err) {
5539 + ipkg_message(conf, IPKG_ERROR,
5540 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5541 + pkg->name);
5542 + return err;
5543 + }
5544 + }
5545 + if (pkg->tmp_unpack_dir == NULL) {
5546 + err = unpack_pkg_control_files(conf, pkg);
5547 + if (err) return err;
5548 + }
5549 + }
5550 + return 0;
5551 +}
5552 +
5553 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5554 +{
5555 + int i;
5556 + /* now one more pass checking on the ones that need to be installed */
5557 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5558 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5559 + pkg_t *old_pkg = pkg->old_pkg;
5560 +
5561 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5562 + if (err) return err;
5563 +
5564 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5565 + if (err) return err;
5566 +
5567 + err = preinst_configure(conf, pkg, old_pkg);
5568 + if (err) return err;
5569 +
5570 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5571 + if (err) return err;
5572 +
5573 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5574 + if (err) return err;
5575 + }
5576 + return 0;
5577 +}
5578 +
5579 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5580 +{
5581 + int i;
5582 + /* now one more pass checking on the ones that need to be installed */
5583 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5584 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5585 + pkg_t *old_pkg = pkg->old_pkg;
5586 +
5587 + if (old_pkg) {
5588 + old_pkg->state_want = SW_DEINSTALL;
5589 +
5590 + if (old_pkg->state_flag & SF_NOPRUNE) {
5591 + ipkg_message(conf, IPKG_INFO,
5592 + " not removing obsolesced files because package marked noprune\n");
5593 + } else {
5594 + ipkg_message(conf, IPKG_INFO,
5595 + " removing obsolesced files\n");
5596 + remove_obsolesced_files(conf, pkg, old_pkg);
5597 + }
5598 + }
5599 +
5600 + ipkg_message(conf, IPKG_INFO,
5601 + " installing maintainer scripts\n");
5602 + install_maintainer_scripts(conf, pkg, old_pkg);
5603 +
5604 + /* the following just returns 0 */
5605 + remove_disappeared(conf, pkg);
5606 +
5607 + ipkg_message(conf, IPKG_INFO,
5608 + " installing data files\n");
5609 + install_data_files(conf, pkg);
5610 +
5611 + ipkg_message(conf, IPKG_INFO,
5612 + " resolving conf files\n");
5613 + resolve_conffiles(conf, pkg);
5614 +
5615 + pkg->state_status = SS_UNPACKED;
5616 +
5617 + if (old_pkg) {
5618 + old_pkg->state_status = SS_NOT_INSTALLED;
5619 + }
5620 +
5621 + time(&pkg->installed_time);
5622 +
5623 + ipkg_message(conf, IPKG_INFO,
5624 + " cleanup temp files\n");
5625 + cleanup_temporary_files(conf, pkg);
5626 +
5627 + if (pkg->parent)
5628 + pkg->parent->state_status = pkg->state_status;
5629 + }
5630 + return 0;
5631 +}
5632 +
5633 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5634 +{
5635 + int i;
5636 + /* now one more pass checking on the ones that need to be installed */
5637 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5638 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5639 + pkg_t *old_pkg = pkg->old_pkg;
5640 +
5641 + if (old_pkg) {
5642 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5643 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5644 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5645 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5646 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5647 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5648 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5649 + preinst_configure_unwind(conf, pkg, old_pkg);
5650 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5651 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5652 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5653 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5654 +
5655 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5656 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5657 +
5658 + }
5659 + }
5660 + return 0;
5661 +}
5662 +
5663 +/*
5664 + * Perform all the actions.
5665 + *
5666 + * pkgs_to_remove are packages marked for removal.
5667 + * pkgs_superseded are the old packages being replaced by upgrades.
5668 + *
5669 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5670 + */
5671 +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)
5672 +{
5673 + int err;
5674 + int i;
5675 +
5676 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5677 + if (err) return err;
5678 +
5679 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5680 + if (err) return err;
5681 +
5682 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5683 + if (err) goto UNWIND;
5684 +
5685 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5686 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5687 + if (err) goto UNWIND;
5688 +
5689 + /*
5690 + * Now that we have the packages unpacked, we can look for data
5691 + * file clashes. First, we mark the files from the superseded
5692 + * packages as obsolete. Then we scan the files in
5693 + * pkgs_to_install, and only complain about clashes with
5694 + * non-obsolete files.
5695 + */
5696 +
5697 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5698 + if (err) goto UNWIND;
5699 +
5700 + /* this was before checking data file clashes */
5701 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5702 + if (err) goto UNWIND;
5703 +
5704 + /* point of no return: no unwinding after this */
5705 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5706 + if (err) return err;
5707 +
5708 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5709 + return 0;
5710 +
5711 + UNWIND:
5712 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5713 +
5714 + ipkg_message(conf, IPKG_INFO,
5715 + " cleanup temp files\n");
5716 + cleanup_temporary_files(conf, pkg);
5717 +
5718 + ipkg_message(conf, IPKG_INFO,
5719 + "Failed.\n");
5720 + return err;
5721 +}
5722 +
5723 +#endif
5724 Index: busybox-1.7.2/archival/libipkg/ipkg_install.h
5725 ===================================================================
5726 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5727 +++ busybox-1.7.2/archival/libipkg/ipkg_install.h 2007-10-30 15:35:05.000000000 -0500
5728 @@ -0,0 +1,35 @@
5729 +/* ipkg_install.h - the itsy package management system
5730 +
5731 + Carl D. Worth
5732 +
5733 + Copyright (C) 2001 University of Southern California
5734 +
5735 + This program is free software; you can redistribute it and/or
5736 + modify it under the terms of the GNU General Public License as
5737 + published by the Free Software Foundation; either version 2, or (at
5738 + your option) any later version.
5739 +
5740 + This program is distributed in the hope that it will be useful, but
5741 + WITHOUT ANY WARRANTY; without even the implied warranty of
5742 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5743 + General Public License for more details.
5744 +*/
5745 +
5746 +#ifndef IPKG_INSTALL_H
5747 +#define IPKG_INSTALL_H
5748 +
5749 +#include "pkg.h"
5750 +#include "ipkg_conf.h"
5751 +
5752 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5753 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5754 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5755 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5756 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5757 +
5758 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5759 +
5760 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5761 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5762 +
5763 +#endif
5764 Index: busybox-1.7.2/archival/libipkg/ipkg_message.c
5765 ===================================================================
5766 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5767 +++ busybox-1.7.2/archival/libipkg/ipkg_message.c 2007-10-30 15:35:05.000000000 -0500
5768 @@ -0,0 +1,61 @@
5769 +/* ipkg_message.c - the itsy package management system
5770 +
5771 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5772 +
5773 + This program is free software; you can redistribute it and/or
5774 + modify it under the terms of the GNU General Public License as
5775 + published by the Free Software Foundation; either version 2, or (at
5776 + your option) any later version.
5777 +
5778 + This program is distributed in the hope that it will be useful, but
5779 + WITHOUT ANY WARRANTY; without even the implied warranty of
5780 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5781 + General Public License for more details.
5782 +*/
5783 +
5784 +
5785 +#include "ipkg.h"
5786 +#include "ipkg_conf.h"
5787 +#include "ipkg_message.h"
5788 +
5789 +#ifndef IPKG_LIB
5790 +
5791 +void
5792 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5793 +{
5794 + va_list ap;
5795 +
5796 + if (conf && (conf->verbosity < level))
5797 + {
5798 + return;
5799 + }
5800 + else
5801 + {
5802 +
5803 + va_start (ap, fmt);
5804 + vprintf (fmt, ap);
5805 + va_end (ap);
5806 + }
5807 +}
5808 +
5809 +#else
5810 +
5811 +#include "libipkg.h"
5812 +
5813 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5814 +
5815 +void
5816 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5817 +{
5818 + va_list ap;
5819 + char ts[256];
5820 +
5821 + if (ipkg_cb_message)
5822 + {
5823 + va_start (ap, fmt);
5824 + vsnprintf (ts,256,fmt, ap);
5825 + va_end (ap);
5826 + ipkg_cb_message(conf,level,ts);
5827 + }
5828 +}
5829 +#endif
5830 Index: busybox-1.7.2/archival/libipkg/ipkg_message.h
5831 ===================================================================
5832 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5833 +++ busybox-1.7.2/archival/libipkg/ipkg_message.h 2007-10-30 15:35:05.000000000 -0500
5834 @@ -0,0 +1,32 @@
5835 +/* ipkg_message.h - the itsy package management system
5836 +
5837 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5838 +
5839 + This program is free software; you can redistribute it and/or
5840 + modify it under the terms of the GNU General Public License as
5841 + published by the Free Software Foundation; either version 2, or (at
5842 + your option) any later version.
5843 +
5844 + This program is distributed in the hope that it will be useful, but
5845 + WITHOUT ANY WARRANTY; without even the implied warranty of
5846 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5847 + General Public License for more details.
5848 +*/
5849 +
5850 +#ifndef _IPKG_MESSAGE_H_
5851 +#define _IPKG_MESSAGE_H_
5852 +
5853 +#include "ipkg.h"
5854 +#include "ipkg_conf.h"
5855 +
5856 +typedef enum {
5857 + IPKG_ERROR, /* error conditions */
5858 + IPKG_NOTICE, /* normal but significant condition */
5859 + IPKG_INFO, /* informational message */
5860 + IPKG_DEBUG, /* debug level message */
5861 + IPKG_DEBUG2, /* more debug level message */
5862 +} message_level_t;
5863 +
5864 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
5865 +
5866 +#endif /* _IPKG_MESSAGE_H_ */
5867 Index: busybox-1.7.2/archival/libipkg/ipkg_remove.c
5868 ===================================================================
5869 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5870 +++ busybox-1.7.2/archival/libipkg/ipkg_remove.c 2007-10-30 15:35:05.000000000 -0500
5871 @@ -0,0 +1,383 @@
5872 +/* ipkg_remove.c - the itsy package management system
5873 +
5874 + Carl D. Worth
5875 +
5876 + Copyright (C) 2001 University of Southern California
5877 +
5878 + This program is free software; you can redistribute it and/or
5879 + modify it under the terms of the GNU General Public License as
5880 + published by the Free Software Foundation; either version 2, or (at
5881 + your option) any later version.
5882 +
5883 + This program is distributed in the hope that it will be useful, but
5884 + WITHOUT ANY WARRANTY; without even the implied warranty of
5885 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5886 + General Public License for more details.
5887 +*/
5888 +
5889 +#include "ipkg.h"
5890 +#include "ipkg_message.h"
5891 +
5892 +#include <glob.h>
5893 +
5894 +#include "ipkg_remove.h"
5895 +
5896 +#include "file_util.h"
5897 +#include "sprintf_alloc.h"
5898 +#include "str_util.h"
5899 +
5900 +#include "ipkg_cmd.h"
5901 +
5902 +/*
5903 + * Returns number of the number of packages depending on the packages provided by this package.
5904 + * Every package implicitly provides itself.
5905 + */
5906 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5907 +{
5908 + int nprovides = pkg->provides_count;
5909 + abstract_pkg_t **provides = pkg->provides;
5910 + int n_installed_dependents = 0;
5911 + int i;
5912 + for (i = 0; i <= nprovides; i++) {
5913 + abstract_pkg_t *providee = provides[i];
5914 + abstract_pkg_t **dependers = providee->depended_upon_by;
5915 + abstract_pkg_t *dep_ab_pkg;
5916 + if (dependers == NULL)
5917 + continue;
5918 + while ((dep_ab_pkg = *dependers++) != NULL) {
5919 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5920 + n_installed_dependents++;
5921 + }
5922 + }
5923 +
5924 + }
5925 + /* if caller requested the set of installed dependents */
5926 + if (pdependents) {
5927 + int p = 0;
5928 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5929 +
5930 + if ( dependents == NULL ){
5931 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5932 + return -1;
5933 + }
5934 +
5935 + *pdependents = dependents;
5936 + for (i = 0; i <= nprovides; i++) {
5937 + abstract_pkg_t *providee = provides[i];
5938 + abstract_pkg_t **dependers = providee->depended_upon_by;
5939 + abstract_pkg_t *dep_ab_pkg;
5940 + if (dependers == NULL)
5941 + continue;
5942 + while ((dep_ab_pkg = *dependers++) != NULL) {
5943 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5944 + dependents[p++] = dep_ab_pkg;
5945 + dep_ab_pkg->state_flag |= SF_MARKED;
5946 + }
5947 + }
5948 + }
5949 + dependents[p] = NULL;
5950 + /* now clear the marks */
5951 + for (i = 0; i < p; i++) {
5952 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5953 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5954 + }
5955 + }
5956 + return n_installed_dependents;
5957 +}
5958 +
5959 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5960 +{
5961 + int i;
5962 + int a;
5963 + int count;
5964 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5965 + abstract_pkg_t * ab_pkg;
5966 +
5967 + if((ab_pkg = pkg->parent) == NULL){
5968 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5969 + __FUNCTION__, pkg->name);
5970 + return 0;
5971 + }
5972 +
5973 + if (dependents == NULL)
5974 + return 0;
5975 +
5976 + // here i am using the dependencies_checked
5977 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5978 + return 0; // has already been encountered in the process
5979 + // of marking packages for removal - Karthik
5980 + ab_pkg->dependencies_checked = 2;
5981 +
5982 + i = 0;
5983 + count = 1;
5984 + while (dependents [i] != NULL) {
5985 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5986 +
5987 + if (dep_ab_pkg->dependencies_checked == 2){
5988 + i++;
5989 + continue;
5990 + }
5991 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5992 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5993 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5994 + if (dep_pkg->state_status == SS_INSTALLED) {
5995 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5996 + count++;
5997 + }
5998 + }
5999 + }
6000 + i++;
6001 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6002 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6003 + }
6004 +
6005 + if (count == 1)
6006 + return 0;
6007 +
6008 +
6009 + for (i = 0; i < dependent_pkgs->len; i++) {
6010 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6011 + if (err)
6012 + return err;
6013 + }
6014 + return 0;
6015 +}
6016 +
6017 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6018 +{
6019 + abstract_pkg_t *dep_ab_pkg;
6020 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6021 + while ((dep_ab_pkg = *dependents++) != NULL) {
6022 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6023 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6024 + }
6025 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6026 + ipkg_message(conf, IPKG_ERROR, "");
6027 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6028 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6029 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6030 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6031 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6032 + return 0;
6033 +}
6034 +
6035 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6036 +{
6037 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6038 + thus I wan't check for essential, as I'm upgrading.
6039 + I hope it won't break anything :)
6040 +*/
6041 + int err;
6042 + abstract_pkg_t *parent_pkg = NULL;
6043 +
6044 + if (pkg->essential && !message) {
6045 + if (conf->force_removal_of_essential_packages) {
6046 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6047 + "\tIf your system breaks, you get to keep both pieces\n",
6048 + pkg->name);
6049 + } else {
6050 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6051 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6052 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6053 + "\tits will with the option: -force-removal-of-essential-packages\n",
6054 + pkg->name);
6055 + return IPKG_PKG_IS_ESSENTIAL;
6056 + }
6057 + }
6058 +
6059 + if ((parent_pkg = pkg->parent) == NULL)
6060 + return 0;
6061 +
6062 + /* only attempt to remove dependent installed packages if
6063 + * force_depends is not specified or the package is being
6064 + * replaced.
6065 + */
6066 + if (!conf->force_depends
6067 + && !(pkg->state_flag & SF_REPLACE)) {
6068 + abstract_pkg_t **dependents;
6069 + int has_installed_dependents =
6070 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6071 +
6072 + if (has_installed_dependents) {
6073 + /*
6074 + * if this package is depended up by others, then either we should
6075 + * not remove it or we should remove it and all of its dependents
6076 + */
6077 +
6078 + if (!conf->force_removal_of_dependent_packages
6079 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6080 + return IPKG_PKG_HAS_DEPENDENTS;
6081 + }
6082 +
6083 + /* remove packages depending on this package - Karthik */
6084 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6085 + free(dependents);
6086 + if (err) return err;
6087 + }
6088 + }
6089 +
6090 + if ( message==0 ){
6091 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6092 + fflush(stdout);
6093 + }
6094 + pkg->state_flag |= SF_FILELIST_CHANGED;
6095 +
6096 + pkg->state_want = SW_DEINSTALL;
6097 + ipkg_state_changed++;
6098 +
6099 + pkg_run_script(conf, pkg, "prerm", "remove");
6100 +
6101 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6102 + maintains an empty filelist rather than deleting it. That seems
6103 + like a big pain, and I don't see that that should make a big
6104 + difference, but for anyone who wants tighter compatibility,
6105 + feel free to fix this. */
6106 + remove_data_files_and_list(conf, pkg);
6107 +
6108 + pkg_run_script(conf, pkg, "postrm", "remove");
6109 +
6110 + remove_maintainer_scripts_except_postrm(conf, pkg);
6111 +
6112 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6113 + * space, it doesn't make sense to leave extra configurations, files,
6114 + * and maintainer scripts left around. So, we make remove like purge,
6115 + * and take out all the crap :) */
6116 +
6117 + remove_postrm(conf, pkg);
6118 + pkg->state_status = SS_NOT_INSTALLED;
6119 +
6120 + if (parent_pkg)
6121 + parent_pkg->state_status = SS_NOT_INSTALLED;
6122 +
6123 + return 0;
6124 +}
6125 +
6126 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6127 +{
6128 + ipkg_remove_pkg(conf, pkg,0);
6129 + return 0;
6130 +}
6131 +
6132 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6133 +{
6134 + str_list_t installed_dirs;
6135 + str_list_t *installed_files;
6136 + str_list_elt_t *iter;
6137 + char *file_name;
6138 + conffile_t *conffile;
6139 + int removed_a_dir;
6140 + pkg_t *owner;
6141 +
6142 + str_list_init(&installed_dirs);
6143 + installed_files = pkg_get_installed_files(pkg);
6144 +
6145 + for (iter = installed_files->head; iter; iter = iter->next) {
6146 + file_name = iter->data;
6147 +
6148 + if (file_is_dir(file_name)) {
6149 + str_list_append(&installed_dirs, strdup(file_name));
6150 + continue;
6151 + }
6152 +
6153 + conffile = pkg_get_conffile(pkg, file_name);
6154 + if (conffile) {
6155 + /* XXX: QUESTION: Is this right? I figure we only need to
6156 + save the conffile if it has been modified. Is that what
6157 + dpkg does? Or does dpkg preserve all conffiles? If so,
6158 + this seems like a better thing to do to conserve
6159 + space. */
6160 + if (conffile_has_been_modified(conf, conffile)) {
6161 + printf(" not deleting modified conffile %s\n", file_name);
6162 + fflush(stdout);
6163 + continue;
6164 + }
6165 + }
6166 +
6167 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6168 + if (!conf->noaction)
6169 + unlink(file_name);
6170 + }
6171 +
6172 + if (!conf->noaction) {
6173 + do {
6174 + removed_a_dir = 0;
6175 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6176 + file_name = iter->data;
6177 +
6178 + if (rmdir(file_name) == 0) {
6179 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6180 + removed_a_dir = 1;
6181 + str_list_remove(&installed_dirs, &iter);
6182 + }
6183 + }
6184 + } while (removed_a_dir);
6185 + }
6186 +
6187 + pkg_free_installed_files(pkg);
6188 + /* We have to remove the file list now, so that
6189 + find_pkg_owning_file does not always just report this package */
6190 + pkg_remove_installed_files_list(conf, pkg);
6191 +
6192 + /* Don't print warning for dirs that are provided by other packages */
6193 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6194 + file_name = iter->data;
6195 +
6196 + owner = file_hash_get_file_owner(conf, file_name);
6197 + if (owner) {
6198 + free(iter->data);
6199 + iter->data = NULL;
6200 + str_list_remove(&installed_dirs, &iter);
6201 + }
6202 + }
6203 +
6204 + /* cleanup */
6205 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6206 + free(iter->data);
6207 + iter->data = NULL;
6208 + }
6209 + str_list_deinit(&installed_dirs);
6210 +
6211 + return 0;
6212 +}
6213 +
6214 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6215 +{
6216 + int i, err;
6217 + char *globpattern;
6218 + glob_t globbuf;
6219 +
6220 + if (conf->noaction) return 0;
6221 +
6222 + sprintf_alloc(&globpattern, "%s/%s.*",
6223 + pkg->dest->info_dir, pkg->name);
6224 + err = glob(globpattern, 0, NULL, &globbuf);
6225 + free(globpattern);
6226 + if (err) {
6227 + return 0;
6228 + }
6229 +
6230 + for (i = 0; i < globbuf.gl_pathc; i++) {
6231 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6232 + continue;
6233 + }
6234 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6235 + unlink(globbuf.gl_pathv[i]);
6236 + }
6237 + globfree(&globbuf);
6238 +
6239 + return 0;
6240 +}
6241 +
6242 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6243 +{
6244 + char *postrm_file_name;
6245 +
6246 + if (conf->noaction) return 0;
6247 +
6248 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6249 + pkg->dest->info_dir, pkg->name);
6250 + unlink(postrm_file_name);
6251 + free(postrm_file_name);
6252 +
6253 + return 0;
6254 +}
6255 Index: busybox-1.7.2/archival/libipkg/ipkg_remove.h
6256 ===================================================================
6257 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6258 +++ busybox-1.7.2/archival/libipkg/ipkg_remove.h 2007-10-30 15:35:05.000000000 -0500
6259 @@ -0,0 +1,33 @@
6260 +/* ipkg_remove.h - the itsy package management system
6261 +
6262 + Carl D. Worth
6263 +
6264 + Copyright (C) 2001 University of Southern California
6265 +
6266 + This program is free software; you can redistribute it and/or
6267 + modify it under the terms of the GNU General Public License as
6268 + published by the Free Software Foundation; either version 2, or (at
6269 + your option) any later version.
6270 +
6271 + This program is distributed in the hope that it will be useful, but
6272 + WITHOUT ANY WARRANTY; without even the implied warranty of
6273 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6274 + General Public License for more details.
6275 +*/
6276 +
6277 +#ifndef IPKG_REMOVE_H
6278 +#define IPKG_REMOVE_H
6279 +
6280 +#include "pkg.h"
6281 +#include "ipkg_conf.h"
6282 +
6283 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6284 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6285 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6286 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6287 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6288 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6289 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6290 +
6291 +
6292 +#endif
6293 Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.c
6294 ===================================================================
6295 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6296 +++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.c 2007-10-30 15:35:05.000000000 -0500
6297 @@ -0,0 +1,77 @@
6298 +/* ipkg_upgrade.c - the itsy package management system
6299 +
6300 + Carl D. Worth
6301 + Copyright (C) 2001 University of Southern California
6302 +
6303 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6304 +
6305 + This program is free software; you can redistribute it and/or
6306 + modify it under the terms of the GNU General Public License as
6307 + published by the Free Software Foundation; either version 2, or (at
6308 + your option) any later version.
6309 +
6310 + This program is distributed in the hope that it will be useful, but
6311 + WITHOUT ANY WARRANTY; without even the implied warranty of
6312 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6313 + General Public License for more details.
6314 +*/
6315 +
6316 +#include "ipkg.h"
6317 +#include "ipkg_install.h"
6318 +#include "ipkg_message.h"
6319 +
6320 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6321 +{
6322 + pkg_t *new;
6323 + int cmp;
6324 + char *old_version, *new_version;
6325 +
6326 + if (old->state_flag & SF_HOLD) {
6327 + ipkg_message(conf, IPKG_NOTICE,
6328 + "Not upgrading package %s which is marked "
6329 + "hold (flags=%#x)\n", old->name, old->state_flag);
6330 + return 0;
6331 + }
6332 +
6333 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6334 + if (new == NULL) {
6335 + old_version = pkg_version_str_alloc(old);
6336 + ipkg_message(conf, IPKG_NOTICE,
6337 + "Assuming locally installed package %s (%s) "
6338 + "is up to date.\n", old->name, old_version);
6339 + free(old_version);
6340 + return 0;
6341 + }
6342 +
6343 + old_version = pkg_version_str_alloc(old);
6344 + new_version = pkg_version_str_alloc(new);
6345 +
6346 + cmp = pkg_compare_versions(old, new);
6347 + ipkg_message(conf, IPKG_DEBUG,
6348 + "comparing visible versions of pkg %s:"
6349 + "\n\t%s is installed "
6350 + "\n\t%s is available "
6351 + "\n\t%d was comparison result\n",
6352 + old->name, old_version, new_version, cmp);
6353 + if (cmp == 0) {
6354 + ipkg_message(conf, IPKG_INFO,
6355 + "Package %s (%s) installed in %s is up to date.\n",
6356 + old->name, old_version, old->dest->name);
6357 + free(old_version);
6358 + free(new_version);
6359 + return 0;
6360 + } else if (cmp > 0) {
6361 + ipkg_message(conf, IPKG_NOTICE,
6362 + "Not downgrading package %s on %s from %s to %s.\n",
6363 + old->name, old->dest->name, old_version, new_version);
6364 + free(old_version);
6365 + free(new_version);
6366 + return 0;
6367 + } else if (cmp < 0) {
6368 + new->dest = old->dest;
6369 + old->state_want = SW_DEINSTALL;
6370 + }
6371 +
6372 + new->state_flag |= SF_USER;
6373 + return ipkg_install_pkg(conf, new,1);
6374 +}
6375 Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.h
6376 ===================================================================
6377 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6378 +++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.h 2007-10-30 15:35:05.000000000 -0500
6379 @@ -0,0 +1,18 @@
6380 +/* ipkg_upgrade.c - the itsy package management system
6381 +
6382 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6383 +
6384 + This program is free software; you can redistribute it and/or
6385 + modify it under the terms of the GNU General Public License as
6386 + published by the Free Software Foundation; either version 2, or (at
6387 + your option) any later version.
6388 +
6389 + This program is distributed in the hope that it will be useful, but
6390 + WITHOUT ANY WARRANTY; without even the implied warranty of
6391 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6392 + General Public License for more details.
6393 +*/
6394 +
6395 +#include "ipkg.h"
6396 +
6397 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6398 Index: busybox-1.7.2/archival/libipkg/ipkg_utils.c
6399 ===================================================================
6400 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6401 +++ busybox-1.7.2/archival/libipkg/ipkg_utils.c 2007-10-30 15:35:05.000000000 -0500
6402 @@ -0,0 +1,181 @@
6403 +/* ipkg_utils.c - the itsy package management system
6404 +
6405 + Steven M. Ayer
6406 +
6407 + Copyright (C) 2002 Compaq Computer Corporation
6408 +
6409 + This program is free software; you can redistribute it and/or
6410 + modify it under the terms of the GNU General Public License as
6411 + published by the Free Software Foundation; either version 2, or (at
6412 + your option) any later version.
6413 +
6414 + This program is distributed in the hope that it will be useful, but
6415 + WITHOUT ANY WARRANTY; without even the implied warranty of
6416 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6417 + General Public License for more details.
6418 +*/
6419 +
6420 +#include "ipkg.h"
6421 +#include <errno.h>
6422 +#include <ctype.h>
6423 +#include <sys/vfs.h>
6424 +
6425 +#include "ipkg_utils.h"
6426 +#include "pkg.h"
6427 +#include "pkg_hash.h"
6428 +
6429 +struct errlist* error_list;
6430 +
6431 +int get_available_blocks(char * filesystem)
6432 +{
6433 + struct statfs sfs;
6434 +
6435 + if(statfs(filesystem, &sfs)){
6436 + fprintf(stderr, "bad statfs\n");
6437 + return 0;
6438 + }
6439 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6440 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6441 +}
6442 +
6443 +char **read_raw_pkgs_from_file(const char *file_name)
6444 +{
6445 + FILE *fp;
6446 + char **ret;
6447 +
6448 + if(!(fp = fopen(file_name, "r"))){
6449 + fprintf(stderr, "can't get %s open for read\n", file_name);
6450 + return NULL;
6451 + }
6452 +
6453 + ret = read_raw_pkgs_from_stream(fp);
6454 +
6455 + fclose(fp);
6456 +
6457 + return ret;
6458 +}
6459 +
6460 +char **read_raw_pkgs_from_stream(FILE *fp)
6461 +{
6462 + char **raw = NULL, *buf, *scout;
6463 + int count = 0;
6464 + size_t size = 512;
6465 +
6466 + buf = malloc (size);
6467 +
6468 + while (fgets(buf, size, fp)) {
6469 + while (strlen (buf) == (size - 1)
6470 + && buf[size-2] != '\n') {
6471 + size_t o = size - 1;
6472 + size *= 2;
6473 + buf = realloc (buf, size);
6474 + if (fgets (buf + o, size - o, fp) == NULL)
6475 + break;
6476 + }
6477 +
6478 + if(!(count % 50))
6479 + raw = realloc(raw, (count + 50) * sizeof(char *));
6480 +
6481 + if((scout = strchr(buf, '\n')))
6482 + *scout = '\0';
6483 +
6484 + raw[count++] = strdup(buf);
6485 + }
6486 +
6487 + raw = realloc(raw, (count + 1) * sizeof(char *));
6488 + raw[count] = NULL;
6489 +
6490 + free (buf);
6491 +
6492 + return raw;
6493 +}
6494 +
6495 +/* something to remove whitespace, a hash pooper */
6496 +char *trim_alloc(char *line)
6497 +{
6498 + char *new;
6499 + char *dest, *src, *end;
6500 +
6501 + new = malloc(strlen(line) + 1);
6502 + if ( new == NULL ){
6503 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6504 + return NULL;
6505 + }
6506 + dest = new, src = line, end = line + (strlen(line) - 1);
6507 +
6508 + /* remove it from the front */
6509 + while(src &&
6510 + isspace(*src) &&
6511 + *src)
6512 + src++;
6513 + /* and now from the back */
6514 + while((end > src) &&
6515 + isspace(*end))
6516 + end--;
6517 + end++;
6518 + *end = '\0';
6519 + strcpy(new, src);
6520 + /* this does from the first space
6521 + * blasting away any versions stuff in depends
6522 + while(src &&
6523 + !isspace(*src) &&
6524 + *src)
6525 + *dest++ = *src++;
6526 + *dest = '\0';
6527 + */
6528 +
6529 + return new;
6530 +}
6531 +
6532 +int line_is_blank(const char *line)
6533 +{
6534 + const char *s;
6535 +
6536 + for (s = line; *s; s++) {
6537 + if (!isspace(*s))
6538 + return 0;
6539 + }
6540 + return 1;
6541 +}
6542 +
6543 +void push_error_list(struct errlist ** errors, char * msg){
6544 + struct errlist *err_lst_tmp;
6545 +
6546 +
6547 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6548 + err_lst_tmp->errmsg=strdup(msg) ;
6549 + err_lst_tmp->next = *errors;
6550 + *errors = err_lst_tmp;
6551 +}
6552 +
6553 +
6554 +void reverse_error_list(struct errlist **errors){
6555 + struct errlist *result=NULL;
6556 + struct errlist *current= *errors;
6557 + struct errlist *next;
6558 +
6559 + while ( current != NULL ) {
6560 + next = current->next;
6561 + current->next=result;
6562 + result=current;
6563 + current=next;
6564 + }
6565 + *errors=result;
6566 +
6567 +}
6568 +
6569 +
6570 +void free_error_list(struct errlist **errors){
6571 + struct errlist *current = *errors;
6572 +
6573 + while (current != NULL) {
6574 + free(current->errmsg);
6575 + current = (*errors)->next;
6576 + free(*errors);
6577 + *errors = current;
6578 + }
6579 +
6580 +
6581 +}
6582 +
6583 +
6584 Index: busybox-1.7.2/archival/libipkg/ipkg_utils.h
6585 ===================================================================
6586 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6587 +++ busybox-1.7.2/archival/libipkg/ipkg_utils.h 2007-10-30 15:35:05.000000000 -0500
6588 @@ -0,0 +1,29 @@
6589 +/* ipkg_utils.h - the itsy package management system
6590 +
6591 + Steven M. Ayer
6592 +
6593 + Copyright (C) 2002 Compaq Computer Corporation
6594 +
6595 + This program is free software; you can redistribute it and/or
6596 + modify it under the terms of the GNU General Public License as
6597 + published by the Free Software Foundation; either version 2, or (at
6598 + your option) any later version.
6599 +
6600 + This program is distributed in the hope that it will be useful, but
6601 + WITHOUT ANY WARRANTY; without even the implied warranty of
6602 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6603 + General Public License for more details.
6604 +*/
6605 +
6606 +#ifndef IPKG_UTILS_H
6607 +#define IPKG_UTILS_H
6608 +
6609 +#include "pkg.h"
6610 +
6611 +int get_available_blocks(char * filesystem);
6612 +char **read_raw_pkgs_from_file(const char *file_name);
6613 +char **read_raw_pkgs_from_stream(FILE *fp);
6614 +char *trim_alloc(char * line);
6615 +int line_is_blank(const char *line);
6616 +
6617 +#endif
6618 Index: busybox-1.7.2/archival/libipkg/Kbuild
6619 ===================================================================
6620 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6621 +++ busybox-1.7.2/archival/libipkg/Kbuild 2007-10-30 15:35:05.000000000 -0500
6622 @@ -0,0 +1,60 @@
6623 +# Makefile for busybox
6624 +#
6625 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6626 +# Copyright (C) 2006 OpenWrt.org
6627 +#
6628 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6629 +
6630 +LIBIPKG_CORE_OBJS:= \
6631 + args.o \
6632 + libipkg.o \
6633 + user.o \
6634 +
6635 +LIBIPKG_CMD_OBJS:= \
6636 + ipkg_cmd.o \
6637 + ipkg_configure.o \
6638 + ipkg_download.o \
6639 + ipkg_install.o \
6640 + ipkg_remove.o \
6641 + ipkg_upgrade.o \
6642 +
6643 +LIBIPKG_DB_OBJS:= \
6644 + hash_table.o \
6645 + ipkg_conf.o \
6646 + ipkg_utils.o \
6647 + pkg.o \
6648 + pkg_depends.o \
6649 + pkg_extract.o \
6650 + pkg_hash.o \
6651 + pkg_parse.o \
6652 + pkg_vec.o \
6653 +
6654 +LIBIPKG_LIST_OBJS:= \
6655 + conffile.o \
6656 + conffile_list.o \
6657 + nv_pair.o \
6658 + nv_pair_list.o \
6659 + pkg_dest.o \
6660 + pkg_dest_list.o \
6661 + pkg_src.o \
6662 + pkg_src_list.o \
6663 + str_list.o \
6664 + void_list.o \
6665 +
6666 +LIBIPKG_UTIL_OBJS:= \
6667 + file_util.o \
6668 + ipkg_message.o \
6669 + str_util.o \
6670 + xsystem.o \
6671 +
6672 +lib-y :=
6673 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6677 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6678 +
6679 +ifeq ($(strip $(IPKG_ARCH)),)
6680 +IPKG_ARCH:=$(TARGET_ARCH)
6681 +endif
6682 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6683 Index: busybox-1.7.2/archival/libipkg/libipkg.c
6684 ===================================================================
6685 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6686 +++ busybox-1.7.2/archival/libipkg/libipkg.c 2007-10-30 15:35:05.000000000 -0500
6687 @@ -0,0 +1,527 @@
6688 +/* ipkglib.c - the itsy package management system
6689 +
6690 + Florina Boor
6691 +
6692 + Copyright (C) 2003 kernel concepts
6693 +
6694 + This program is free software; you can redistribute it and/or
6695 + modify it under the terms of the GNU General Public License as
6696 + published by the Free Software Foundation; either version 2, or (at
6697 + your option) any later version.
6698 +
6699 + This program is distributed in the hope that it will be useful, but
6700 + WITHOUT ANY WARRANTY; without even the implied warranty of
6701 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6702 + General Public License for more details.
6703 +*/
6704 +
6705 +#ifdef IPKG_LIB
6706 +
6707 +#include "ipkg.h"
6708 +#include "ipkg_includes.h"
6709 +#include "libipkg.h"
6710 +
6711 +#include "args.h"
6712 +#include "ipkg_conf.h"
6713 +#include "ipkg_cmd.h"
6714 +#include "file_util.h"
6715 +
6716 +
6717 +
6718 +ipkg_message_callback ipkg_cb_message = NULL;
6719 +ipkg_response_callback ipkg_cb_response = NULL;
6720 +ipkg_status_callback ipkg_cb_status = NULL;
6721 +ipkg_list_callback ipkg_cb_list = NULL;
6722 +
6723 +
6724 +int
6725 +ipkg_init (ipkg_message_callback mcall,
6726 + ipkg_response_callback rcall,
6727 + args_t * args)
6728 +{
6729 + ipkg_cb_message = mcall;
6730 + ipkg_cb_response = rcall;
6731 +
6732 + args_init (args);
6733 +
6734 + return 0;
6735 +}
6736 +
6737 +
6738 +int
6739 +ipkg_deinit (args_t * args)
6740 +{
6741 + args_deinit (args);
6742 + ipkg_cb_message = NULL;
6743 + ipkg_cb_response = NULL;
6744 +
6745 + /* place other cleanup stuff here */
6746 +
6747 + return 0;
6748 +}
6749 +
6750 +
6751 +int
6752 +ipkg_packages_list(args_t *args,
6753 + const char *packages,
6754 + ipkg_list_callback cblist,
6755 + void *userdata)
6756 +{
6757 + ipkg_cmd_t *cmd;
6758 + ipkg_conf_t ipkg_conf;
6759 + int err;
6760 +
6761 + err = ipkg_conf_init (&ipkg_conf, args);
6762 + if (err)
6763 + {
6764 + return err;
6765 + }
6766 +
6767 + ipkg_cb_list = cblist;
6768 + /* we need to do this because of static declarations,
6769 + * maybe a good idea to change */
6770 + cmd = ipkg_cmd_find ("list");
6771 + if (packages)
6772 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6773 + else
6774 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6775 + ipkg_cb_list = NULL;
6776 + ipkg_conf_deinit (&ipkg_conf);
6777 + return (err);
6778 +}
6779 +
6780 +
6781 +int
6782 +ipkg_packages_status(args_t *args,
6783 + const char *packages,
6784 + ipkg_status_callback cbstatus,
6785 + void *userdata)
6786 +{
6787 + ipkg_cmd_t *cmd;
6788 + ipkg_conf_t ipkg_conf;
6789 + int err;
6790 +
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6792 + if (err)
6793 + {
6794 + return err;
6795 + }
6796 +
6797 + ipkg_cb_status = cbstatus;
6798 +
6799 + /* we need to do this because of static declarations,
6800 + * maybe a good idea to change */
6801 + cmd = ipkg_cmd_find ("status");
6802 + if (packages)
6803 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6804 + else
6805 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6806 +
6807 + ipkg_cb_status = NULL;
6808 + ipkg_conf_deinit (&ipkg_conf);
6809 + return (err);
6810 +}
6811 +
6812 +
6813 +int
6814 +ipkg_packages_info(args_t *args,
6815 + const char *packages,
6816 + ipkg_status_callback cbstatus,
6817 + void *userdata)
6818 +{
6819 + ipkg_cmd_t *cmd;
6820 + ipkg_conf_t ipkg_conf;
6821 + int err;
6822 +
6823 + err = ipkg_conf_init (&ipkg_conf, args);
6824 + if (err)
6825 + {
6826 + return err;
6827 + }
6828 +
6829 + ipkg_cb_status = cbstatus;
6830 +
6831 + /* we need to do this because of static declarations,
6832 + * maybe a good idea to change */
6833 + cmd = ipkg_cmd_find ("info");
6834 + if (packages)
6835 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6836 + else
6837 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6838 +
6839 + ipkg_cb_status = NULL;
6840 + ipkg_conf_deinit (&ipkg_conf);
6841 + return (err);
6842 +}
6843 +
6844 +
6845 +int
6846 +ipkg_packages_install (args_t * args, const char *name)
6847 +{
6848 + ipkg_cmd_t *cmd;
6849 + ipkg_conf_t ipkg_conf;
6850 + int err;
6851 +
6852 + /* this error should be handled in application */
6853 + if (!name || !strlen (name))
6854 + return (-1);
6855 +
6856 + err = ipkg_conf_init (&ipkg_conf, args);
6857 + if (err)
6858 + {
6859 + return err;
6860 + }
6861 +
6862 + /* we need to do this because of static declarations,
6863 + * maybe a good idea to change */
6864 + cmd = ipkg_cmd_find ("install");
6865 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6866 +
6867 + ipkg_conf_deinit(&ipkg_conf);
6868 + return (err);
6869 +}
6870 +
6871 +
6872 +int
6873 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6874 +{
6875 + ipkg_cmd_t *cmd;
6876 + ipkg_conf_t ipkg_conf;
6877 + int err;
6878 +
6879 + /* this error should be handled in application */
6880 + if (!name || !strlen (name))
6881 + return (-1);
6882 +
6883 + err = ipkg_conf_init (&ipkg_conf, args);
6884 + if (err)
6885 + {
6886 + return err;
6887 + }
6888 +
6889 + /* we need to do this because of static declarations,
6890 + * maybe a good idea to change */
6891 + if (purge)
6892 + cmd = ipkg_cmd_find ("purge");
6893 + else
6894 + cmd = ipkg_cmd_find ("remove");
6895 +
6896 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6897 +
6898 + ipkg_conf_deinit(&ipkg_conf);
6899 + return (err);
6900 +}
6901 +
6902 +
6903 +int
6904 +ipkg_lists_update(args_t *args)
6905 +{
6906 + ipkg_cmd_t *cmd;
6907 + ipkg_conf_t ipkg_conf;
6908 + int err;
6909 +
6910 + err = ipkg_conf_init (&ipkg_conf, args);
6911 + if (err)
6912 + {
6913 + return err;
6914 + }
6915 +
6916 + /* we need to do this because of static declarations,
6917 + * maybe a good idea to change */
6918 + cmd = ipkg_cmd_find ("update");
6919 +
6920 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6921 +
6922 + ipkg_conf_deinit(&ipkg_conf);
6923 + return (err);
6924 +}
6925 +
6926 +
6927 +int
6928 +ipkg_packages_upgrade(args_t *args)
6929 +{
6930 + ipkg_cmd_t *cmd;
6931 + ipkg_conf_t ipkg_conf;
6932 + int err;
6933 +
6934 + err = ipkg_conf_init (&ipkg_conf, args);
6935 + if (err)
6936 + {
6937 + return err;
6938 + }
6939 +
6940 + /* we need to do this because of static declarations,
6941 + * maybe a good idea to change */
6942 + cmd = ipkg_cmd_find ("upgrade");
6943 +
6944 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6945 +
6946 + ipkg_conf_deinit(&ipkg_conf);
6947 + return (err);
6948 +}
6949 +
6950 +
6951 +int
6952 +ipkg_packages_download (args_t * args, const char *name)
6953 +{
6954 + ipkg_cmd_t *cmd;
6955 + ipkg_conf_t ipkg_conf;
6956 + int err;
6957 +
6958 + /* this error should be handled in application */
6959 + if (!name || !strlen (name))
6960 + return (-1);
6961 +
6962 + err = ipkg_conf_init (&ipkg_conf, args);
6963 + if (err)
6964 + {
6965 + return err;
6966 + }
6967 +
6968 + /* we need to do this because of static declarations,
6969 + * maybe a good idea to change */
6970 + cmd = ipkg_cmd_find ("download");
6971 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6972 +
6973 + ipkg_conf_deinit(&ipkg_conf);
6974 + return (err);
6975 +}
6976 +
6977 +
6978 +int
6979 +ipkg_package_files(args_t *args,
6980 + const char *name,
6981 + ipkg_list_callback cblist,
6982 + void *userdata)
6983 +{
6984 + ipkg_cmd_t *cmd;
6985 + ipkg_conf_t ipkg_conf;
6986 + int err;
6987 +
6988 + /* this error should be handled in application */
6989 + if (!name || !strlen (name))
6990 + return (-1);
6991 +
6992 + err = ipkg_conf_init (&ipkg_conf, args);
6993 + if (err)
6994 + {
6995 + return err;
6996 + }
6997 +
6998 + ipkg_cb_list = cblist;
6999 +
7000 + /* we need to do this because of static declarations,
7001 + * maybe a good idea to change */
7002 + cmd = ipkg_cmd_find ("files");
7003 +
7004 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7005 +
7006 + ipkg_cb_list = NULL;
7007 + ipkg_conf_deinit(&ipkg_conf);
7008 + return (err);
7009 +}
7010 +
7011 +
7012 +int
7013 +ipkg_file_search(args_t *args,
7014 + const char *file,
7015 + ipkg_list_callback cblist,
7016 + void *userdata)
7017 +{
7018 + ipkg_cmd_t *cmd;
7019 + ipkg_conf_t ipkg_conf;
7020 + int err;
7021 +
7022 + /* this error should be handled in application */
7023 + if (!file || !strlen (file))
7024 + return (-1);
7025 +
7026 + err = ipkg_conf_init (&ipkg_conf, args);
7027 + if (err)
7028 + {
7029 + return err;
7030 + }
7031 +
7032 + ipkg_cb_list = cblist;
7033 +
7034 + /* we need to do this because of static declarations,
7035 + * maybe a good idea to change */
7036 + cmd = ipkg_cmd_find ("search");
7037 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7038 +
7039 + ipkg_cb_list = NULL;
7040 + ipkg_conf_deinit(&ipkg_conf);
7041 + return(err);
7042 +}
7043 +
7044 +
7045 +int
7046 +ipkg_file_what(args_t *args, const char *file, const char* command)
7047 +{
7048 + ipkg_cmd_t *cmd;
7049 + ipkg_conf_t ipkg_conf;
7050 + int err;
7051 +
7052 + /* this error should be handled in application */
7053 + if (!file || !strlen (file))
7054 + return (-1);
7055 +
7056 + err = ipkg_conf_init (&ipkg_conf, args);
7057 + if (err)
7058 + {
7059 + return err;
7060 + }
7061 +
7062 + /* we need to do this because of static declarations,
7063 + * maybe a good idea to change */
7064 + cmd = ipkg_cmd_find (command);
7065 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7066 +
7067 + ipkg_conf_deinit(&ipkg_conf);
7068 + return(err);
7069 +}
7070 +
7071 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7072 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7073 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7074 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7075 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7076 +
7077 +
7078 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7079 + char *msg)
7080 +{
7081 + if (conf && (conf->verbosity < level)) {
7082 + return 0;
7083 + } else {
7084 +#ifdef IPKG_LIB
7085 + if ( level == IPKG_ERROR ){
7086 + push_error_list(&error_list, msg);
7087 +// printf(msg);
7088 + } else
7089 +#endif
7090 + printf(msg);
7091 + }
7092 + return 0;
7093 +}
7094 +
7095 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7096 + pkg_state_status_t status, void *userdata)
7097 +{
7098 + if (desc)
7099 + printf("%s - %s - %s\n", name, version, desc);
7100 + else
7101 + printf("%s - %s\n", name, version);
7102 + return 0;
7103 +}
7104 +
7105 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7106 + pkg_state_status_t status, void *userdata)
7107 +{
7108 + if (desc)
7109 + printf("%s\n", desc);
7110 + return 0;
7111 +}
7112 +
7113 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7114 + void *userdata)
7115 +{
7116 + printf("%s\n", desc);
7117 + return 0;
7118 +}
7119 +
7120 +char* default_ipkg_response_callback(char *question)
7121 +{
7122 + char *response = NULL;
7123 + printf(question);
7124 + fflush(stdout);
7125 + do {
7126 + response = (char *)file_read_line_alloc(stdin);
7127 + } while (response == NULL);
7128 + return response;
7129 +}
7130 +
7131 +/* This is used for backward compatibility */
7132 +int
7133 +ipkg_op (int argc, char *argv[])
7134 +{
7135 + int err, opt_index;
7136 + args_t args;
7137 + char *cmd_name;
7138 + ipkg_cmd_t *cmd;
7139 + ipkg_conf_t ipkg_conf;
7140 +
7141 + args_init (&args);
7142 +
7143 + opt_index = args_parse (&args, argc, argv);
7144 + if (opt_index == argc || opt_index < 0)
7145 + {
7146 + args_usage ("ipkg must have one sub-command argument");
7147 + }
7148 +
7149 + cmd_name = argv[opt_index++];
7150 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7151 + read anything from there.
7152 +*/
7153 + if ( !strcmp(cmd_name,"print-architecture") ||
7154 + !strcmp(cmd_name,"print_architecture") ||
7155 + !strcmp(cmd_name,"print-installation-architecture") ||
7156 + !strcmp(cmd_name,"print_installation_architecture") )
7157 + args.nocheckfordirorfile = 1;
7158 +
7159 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7160 + read anything from there.
7161 +*/
7162 + if ( !strcmp(cmd_name,"flag") ||
7163 + !strcmp(cmd_name,"configure") ||
7164 + !strcmp(cmd_name,"remove") ||
7165 + !strcmp(cmd_name,"files") ||
7166 + !strcmp(cmd_name,"search") ||
7167 + !strcmp(cmd_name,"compare_versions") ||
7168 + !strcmp(cmd_name,"compare-versions") ||
7169 + !strcmp(cmd_name,"list_installed") ||
7170 + !strcmp(cmd_name,"list-installed") ||
7171 + !strcmp(cmd_name,"status") )
7172 + args.noreadfeedsfile = 1;
7173 +
7174 +
7175 + err = ipkg_conf_init (&ipkg_conf, &args);
7176 + if (err)
7177 + {
7178 + return err;
7179 + }
7180 +
7181 + args_deinit (&args);
7182 +
7183 + ipkg_cb_message = default_ipkg_message_callback;
7184 + ipkg_cb_response = default_ipkg_response_callback;
7185 + ipkg_cb_status = default_ipkg_status_callback;
7186 + if ( strcmp(cmd_name, "files")==0)
7187 + ipkg_cb_list = default_ipkg_files_callback;
7188 + else
7189 + ipkg_cb_list = default_ipkg_list_callback;
7190 +
7191 + cmd = ipkg_cmd_find (cmd_name);
7192 + if (cmd == NULL)
7193 + {
7194 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7195 + cmd_name);
7196 + args_usage (NULL);
7197 + }
7198 +
7199 + if (cmd->requires_args && opt_index == argc)
7200 + {
7201 + fprintf (stderr,
7202 + "%s: the ``%s'' command requires at least one argument\n",
7203 + __FUNCTION__, cmd_name);
7204 + args_usage (NULL);
7205 + }
7206 +
7207 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7208 +
7209 + ipkg_conf_deinit (&ipkg_conf);
7210 +
7211 + return err;
7212 +}
7213 +
7214 +#endif /* IPKG_LIB */
7215 Index: busybox-1.7.2/archival/libipkg/libipkg.h
7216 ===================================================================
7217 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7218 +++ busybox-1.7.2/archival/libipkg/libipkg.h 2007-10-30 15:35:05.000000000 -0500
7219 @@ -0,0 +1,88 @@
7220 +/* ipkglib.h - the itsy package management system
7221 +
7222 + Florian Boor <florian.boor@kernelconcepts.de>
7223 +
7224 + This program is free software; you can redistribute it and/or
7225 + modify it under the terms of the GNU General Public License as
7226 + published by the Free Software Foundation; either version 2, or (at
7227 + your option) any later version.
7228 +
7229 + This program is distributed in the hope that it will be useful, but
7230 + WITHOUT ANY WARRANTY; without even the implied warranty of
7231 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7232 + General Public License for more details.
7233 +*/
7234 +
7235 +#ifndef IPKGLIB_H
7236 +#define IPKGLIB_H
7237 +
7238 +#ifdef IPKG_LIB
7239 +
7240 +#include "ipkg_conf.h"
7241 +#include "ipkg_message.h"
7242 +
7243 +#include "libbb.h"
7244 +#include "args.h"
7245 +#include "pkg.h"
7246 +
7247 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7248 + char *msg);
7249 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7250 + pkg_state_status_t status, void *userdata);
7251 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7252 + void *userdata);
7253 +typedef char* (*ipkg_response_callback)(char *question);
7254 +
7255 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7256 +extern int ipkg_init (ipkg_message_callback mcall,
7257 + ipkg_response_callback rcall,
7258 + args_t * args);
7259 +
7260 +extern int ipkg_deinit (args_t *args);
7261 +extern int ipkg_packages_list(args_t *args,
7262 + const char *packages,
7263 + ipkg_list_callback cblist,
7264 + void *userdata);
7265 +extern int ipkg_packages_status(args_t *args,
7266 + const char *packages,
7267 + ipkg_status_callback cbstatus,
7268 + void *userdata);
7269 +extern int ipkg_packages_info(args_t *args,
7270 + const char *packages,
7271 + ipkg_status_callback cbstatus,
7272 + void *userdata);
7273 +extern int ipkg_packages_install(args_t *args, const char *name);
7274 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7275 +extern int ipkg_lists_update(args_t *args);
7276 +extern int ipkg_packages_upgrade(args_t *args);
7277 +extern int ipkg_packages_download(args_t *args, const char *name);
7278 +extern int ipkg_package_files(args_t *args,
7279 + const char *name,
7280 + ipkg_list_callback cblist,
7281 + void *userdata);
7282 +extern int ipkg_file_search(args_t *args,
7283 + const char *file,
7284 + ipkg_list_callback cblist,
7285 + void *userdata);
7286 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7287 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7288 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7289 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7290 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7291 +
7292 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7293 +extern ipkg_response_callback ipkg_cb_response;
7294 +extern ipkg_status_callback ipkg_cb_status;
7295 +extern ipkg_list_callback ipkg_cb_list;
7296 +extern void push_error_list(struct errlist **errors,char * msg);
7297 +extern void reverse_error_list(struct errlist **errors);
7298 +extern void free_error_list(struct errlist **errors);
7299 +
7300 +#else
7301 +
7302 +extern int ipkg_op(int argc, char *argv[]);
7303 +
7304 +#endif
7305 +
7306 +
7307 +#endif
7308 Index: busybox-1.7.2/archival/libipkg/nv_pair.c
7309 ===================================================================
7310 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7311 +++ busybox-1.7.2/archival/libipkg/nv_pair.c 2007-10-30 15:35:05.000000000 -0500
7312 @@ -0,0 +1,40 @@
7313 +/* nv_pair.c - the itsy package management system
7314 +
7315 + Carl D. Worth
7316 +
7317 + Copyright (C) 2001 University of Southern California
7318 +
7319 + This program is free software; you can redistribute it and/or
7320 + modify it under the terms of the GNU General Public License as
7321 + published by the Free Software Foundation; either version 2, or (at
7322 + your option) any later version.
7323 +
7324 + This program is distributed in the hope that it will be useful, but
7325 + WITHOUT ANY WARRANTY; without even the implied warranty of
7326 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7327 + General Public License for more details.
7328 +*/
7329 +
7330 +#include "ipkg.h"
7331 +
7332 +#include "nv_pair.h"
7333 +#include "str_util.h"
7334 +
7335 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7336 +{
7337 + nv_pair->name = str_dup_safe(name);
7338 + nv_pair->value = str_dup_safe(value);
7339 +
7340 + return 0;
7341 +}
7342 +
7343 +void nv_pair_deinit(nv_pair_t *nv_pair)
7344 +{
7345 + free(nv_pair->name);
7346 + nv_pair->name = NULL;
7347 +
7348 + free(nv_pair->value);
7349 + nv_pair->value = NULL;
7350 +}
7351 +
7352 +
7353 Index: busybox-1.7.2/archival/libipkg/nv_pair.h
7354 ===================================================================
7355 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7356 +++ busybox-1.7.2/archival/libipkg/nv_pair.h 2007-10-30 15:35:05.000000000 -0500
7357 @@ -0,0 +1,32 @@
7358 +/* nv_pair.h - the itsy package management system
7359 +
7360 + Carl D. Worth
7361 +
7362 + Copyright (C) 2001 University of Southern California
7363 +
7364 + This program is free software; you can redistribute it and/or
7365 + modify it under the terms of the GNU General Public License as
7366 + published by the Free Software Foundation; either version 2, or (at
7367 + your option) any later version.
7368 +
7369 + This program is distributed in the hope that it will be useful, but
7370 + WITHOUT ANY WARRANTY; without even the implied warranty of
7371 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7372 + General Public License for more details.
7373 +*/
7374 +
7375 +#ifndef NV_PAIR_H
7376 +#define NV_PAIR_H
7377 +
7378 +typedef struct nv_pair nv_pair_t;
7379 +struct nv_pair
7380 +{
7381 + char *name;
7382 + char *value;
7383 +};
7384 +
7385 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7386 +void nv_pair_deinit(nv_pair_t *nv_pair);
7387 +
7388 +#endif
7389 +
7390 Index: busybox-1.7.2/archival/libipkg/nv_pair_list.c
7391 ===================================================================
7392 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7393 +++ busybox-1.7.2/archival/libipkg/nv_pair_list.c 2007-10-30 15:35:05.000000000 -0500
7394 @@ -0,0 +1,98 @@
7395 +/* nv_pair_list.c - the itsy package management system
7396 +
7397 + Carl D. Worth
7398 +
7399 + Copyright (C) 2001 University of Southern California
7400 +
7401 + This program is free software; you can redistribute it and/or
7402 + modify it under the terms of the GNU General Public License as
7403 + published by the Free Software Foundation; either version 2, or (at
7404 + your option) any later version.
7405 +
7406 + This program is distributed in the hope that it will be useful, but
7407 + WITHOUT ANY WARRANTY; without even the implied warranty of
7408 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7409 + General Public License for more details.
7410 +*/
7411 +
7412 +#include "ipkg.h"
7413 +
7414 +#include "nv_pair.h"
7415 +#include "void_list.h"
7416 +#include "nv_pair_list.h"
7417 +
7418 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7419 +{
7420 + return void_list_elt_init((void_list_elt_t *) elt, data);
7421 +}
7422 +
7423 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7424 +{
7425 + void_list_elt_deinit((void_list_elt_t *) elt);
7426 +}
7427 +
7428 +int nv_pair_list_init(nv_pair_list_t *list)
7429 +{
7430 + return void_list_init((void_list_t *) list);
7431 +}
7432 +
7433 +void nv_pair_list_deinit(nv_pair_list_t *list)
7434 +{
7435 + nv_pair_list_elt_t *iter;
7436 + nv_pair_t *nv_pair;
7437 +
7438 + for (iter = list->head; iter; iter = iter->next) {
7439 + nv_pair = iter->data;
7440 + nv_pair_deinit(nv_pair);
7441 +
7442 + /* malloced in nv_pair_list_append */
7443 + free(nv_pair);
7444 + iter->data = NULL;
7445 + }
7446 + void_list_deinit((void_list_t *) list);
7447 +}
7448 +
7449 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7450 +{
7451 + int err;
7452 +
7453 + /* freed in nv_pair_list_deinit */
7454 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7455 +
7456 + if (nv_pair == NULL) {
7457 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7458 + return NULL;
7459 + }
7460 + nv_pair_init(nv_pair, name, value);
7461 +
7462 + err = void_list_append((void_list_t *) list, nv_pair);
7463 + if (err) {
7464 + return NULL;
7465 + }
7466 +
7467 + return nv_pair;
7468 +}
7469 +
7470 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7471 +{
7472 + return void_list_push((void_list_t *) list, data);
7473 +}
7474 +
7475 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7476 +{
7477 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7478 +}
7479 +
7480 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7481 +{
7482 + nv_pair_list_elt_t *iter;
7483 + nv_pair_t *nv_pair;
7484 +
7485 + for (iter = list->head; iter; iter = iter->next) {
7486 + nv_pair = iter->data;
7487 + if (strcmp(nv_pair->name, name) == 0) {
7488 + return nv_pair->value;
7489 + }
7490 + }
7491 + return NULL;
7492 +}
7493 Index: busybox-1.7.2/archival/libipkg/nv_pair_list.h
7494 ===================================================================
7495 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7496 +++ busybox-1.7.2/archival/libipkg/nv_pair_list.h 2007-10-30 15:35:05.000000000 -0500
7497 @@ -0,0 +1,60 @@
7498 +/* nv_pair_list.h - the itsy package management system
7499 +
7500 + Carl D. Worth
7501 +
7502 + Copyright (C) 2001 University of Southern California
7503 +
7504 + This program is free software; you can redistribute it and/or
7505 + modify it under the terms of the GNU General Public License as
7506 + published by the Free Software Foundation; either version 2, or (at
7507 + your option) any later version.
7508 +
7509 + This program is distributed in the hope that it will be useful, but
7510 + WITHOUT ANY WARRANTY; without even the implied warranty of
7511 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7512 + General Public License for more details.
7513 +*/
7514 +
7515 +#ifndef NV_PAIR_LIST_H
7516 +#define NV_PAIR_LIST_H
7517 +
7518 +#include "nv_pair.h"
7519 +#include "void_list.h"
7520 +
7521 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7522 +struct nv_pair_list_elt
7523 +{
7524 + nv_pair_list_elt_t *next;
7525 + nv_pair_t *data;
7526 +};
7527 +
7528 +typedef struct nv_pair_list nv_pair_list_t;
7529 +struct nv_pair_list
7530 +{
7531 + nv_pair_list_elt_t pre_head;
7532 + nv_pair_list_elt_t *head;
7533 + nv_pair_list_elt_t *tail;
7534 +};
7535 +
7536 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7537 +{
7538 + if (list->head == NULL)
7539 + return 1;
7540 + else
7541 + return 0;
7542 +}
7543 +
7544 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7545 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7546 +
7547 +int nv_pair_list_init(nv_pair_list_t *list);
7548 +void nv_pair_list_deinit(nv_pair_list_t *list);
7549 +
7550 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7551 + const char *name, const char *value);
7552 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7553 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7554 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7555 +
7556 +#endif
7557 +
7558 Index: busybox-1.7.2/archival/libipkg/pkg.c
7559 ===================================================================
7560 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7561 +++ busybox-1.7.2/archival/libipkg/pkg.c 2007-10-30 15:35:05.000000000 -0500
7562 @@ -0,0 +1,1747 @@
7563 +/* pkg.c - the itsy package management system
7564 +
7565 + Carl D. Worth
7566 +
7567 + Copyright (C) 2001 University of Southern California
7568 +
7569 + This program is free software; you can redistribute it and/or
7570 + modify it under the terms of the GNU General Public License as
7571 + published by the Free Software Foundation; either version 2, or (at
7572 + your option) any later version.
7573 +
7574 + This program is distributed in the hope that it will be useful, but
7575 + WITHOUT ANY WARRANTY; without even the implied warranty of
7576 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7577 + General Public License for more details.
7578 +*/
7579 +
7580 +#include "ipkg.h"
7581 +#include <ctype.h>
7582 +#include <string.h>
7583 +#include <errno.h>
7584 +
7585 +#include "pkg.h"
7586 +
7587 +#include "pkg_parse.h"
7588 +#include "pkg_extract.h"
7589 +#include "ipkg_message.h"
7590 +#include "ipkg_utils.h"
7591 +
7592 +#include "sprintf_alloc.h"
7593 +#include "file_util.h"
7594 +#include "str_util.h"
7595 +#include "xsystem.h"
7596 +#include "ipkg_conf.h"
7597 +
7598 +typedef struct enum_map enum_map_t;
7599 +struct enum_map
7600 +{
7601 + int value;
7602 + char *str;
7603 +};
7604 +
7605 +static const enum_map_t pkg_state_want_map[] = {
7606 + { SW_UNKNOWN, "unknown"},
7607 + { SW_INSTALL, "install"},
7608 + { SW_DEINSTALL, "deinstall"},
7609 + { SW_PURGE, "purge"}
7610 +};
7611 +
7612 +static const enum_map_t pkg_state_flag_map[] = {
7613 + { SF_OK, "ok"},
7614 + { SF_REINSTREQ, "reinstreq"},
7615 + { SF_HOLD, "hold"},
7616 + { SF_REPLACE, "replace"},
7617 + { SF_NOPRUNE, "noprune"},
7618 + { SF_PREFER, "prefer"},
7619 + { SF_OBSOLETE, "obsolete"},
7620 + { SF_USER, "user"},
7621 +};
7622 +
7623 +static const enum_map_t pkg_state_status_map[] = {
7624 + { SS_NOT_INSTALLED, "not-installed" },
7625 + { SS_UNPACKED, "unpacked" },
7626 + { SS_HALF_CONFIGURED, "half-configured" },
7627 + { SS_INSTALLED, "installed" },
7628 + { SS_HALF_INSTALLED, "half-installed" },
7629 + { SS_CONFIG_FILES, "config-files" },
7630 + { SS_POST_INST_FAILED, "post-inst-failed" },
7631 + { SS_REMOVAL_FAILED, "removal-failed" }
7632 +};
7633 +
7634 +static int verrevcmp(const char *val, const char *ref);
7635 +
7636 +
7637 +pkg_t *pkg_new(void)
7638 +{
7639 + pkg_t *pkg;
7640 +
7641 + pkg = malloc(sizeof(pkg_t));
7642 + if (pkg == NULL) {
7643 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7644 + return NULL;
7645 + }
7646 +
7647 + pkg_init(pkg);
7648 +
7649 + return pkg;
7650 +}
7651 +
7652 +int pkg_init(pkg_t *pkg)
7653 +{
7654 + memset(pkg, 0, sizeof(pkg_t));
7655 + pkg->name = NULL;
7656 + pkg->epoch = 0;
7657 + pkg->version = NULL;
7658 + pkg->revision = NULL;
7659 + pkg->familiar_revision = NULL;
7660 + pkg->dest = NULL;
7661 + pkg->src = NULL;
7662 + pkg->architecture = NULL;
7663 + pkg->maintainer = NULL;
7664 + pkg->section = NULL;
7665 + pkg->description = NULL;
7666 + pkg->state_want = SW_UNKNOWN;
7667 + pkg->state_flag = SF_OK;
7668 + pkg->state_status = SS_NOT_INSTALLED;
7669 + pkg->depends_str = NULL;
7670 + pkg->provides_str = NULL;
7671 + pkg->depends_count = 0;
7672 + pkg->depends = NULL;
7673 + pkg->suggests_str = NULL;
7674 + pkg->recommends_str = NULL;
7675 + pkg->suggests_count = 0;
7676 + pkg->recommends_count = 0;
7677 +
7678 + /* Abhaya: added init for conflicts fields */
7679 + pkg->conflicts = NULL;
7680 + pkg->conflicts_count = 0;
7681 +
7682 + /* added for replaces. Jamey 7/23/2002 */
7683 + pkg->replaces = NULL;
7684 + pkg->replaces_count = 0;
7685 +
7686 + pkg->pre_depends_count = 0;
7687 + pkg->pre_depends_str = NULL;
7688 + pkg->provides_count = 0;
7689 + pkg->provides = NULL;
7690 + pkg->filename = NULL;
7691 + pkg->local_filename = NULL;
7692 + pkg->tmp_unpack_dir = NULL;
7693 + pkg->md5sum = NULL;
7694 + pkg->size = NULL;
7695 + pkg->installed_size = NULL;
7696 + pkg->priority = NULL;
7697 + pkg->source = NULL;
7698 + conffile_list_init(&pkg->conffiles);
7699 + pkg->installed_files = NULL;
7700 + pkg->installed_files_ref_cnt = 0;
7701 + pkg->essential = 0;
7702 + pkg->provided_by_hand = 0;
7703 +
7704 + return 0;
7705 +}
7706 +
7707 +void pkg_deinit(pkg_t *pkg)
7708 +{
7709 + free(pkg->name);
7710 + pkg->name = NULL;
7711 + pkg->epoch = 0;
7712 + free(pkg->version);
7713 + pkg->version = NULL;
7714 + /* revision and familiar_revision share storage with version, so
7715 + don't free */
7716 + pkg->revision = NULL;
7717 + pkg->familiar_revision = NULL;
7718 + /* owned by ipkg_conf_t */
7719 + pkg->dest = NULL;
7720 + /* owned by ipkg_conf_t */
7721 + pkg->src = NULL;
7722 + free(pkg->architecture);
7723 + pkg->architecture = NULL;
7724 + free(pkg->maintainer);
7725 + pkg->maintainer = NULL;
7726 + free(pkg->section);
7727 + pkg->section = NULL;
7728 + free(pkg->description);
7729 + pkg->description = NULL;
7730 + pkg->state_want = SW_UNKNOWN;
7731 + pkg->state_flag = SF_OK;
7732 + pkg->state_status = SS_NOT_INSTALLED;
7733 + free(pkg->depends_str);
7734 + pkg->depends_str = NULL;
7735 + free(pkg->provides_str);
7736 + pkg->provides_str = NULL;
7737 + pkg->depends_count = 0;
7738 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7739 + pkg->pre_depends_count = 0;
7740 + free(pkg->pre_depends_str);
7741 + pkg->pre_depends_str = NULL;
7742 + pkg->provides_count = 0;
7743 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7744 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7745 + free(pkg->filename);
7746 + pkg->filename = NULL;
7747 + free(pkg->local_filename);
7748 + pkg->local_filename = NULL;
7749 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7750 + ipkg_install.c here. See comment in
7751 + ipkg_install.c:cleanup_temporary_files */
7752 + free(pkg->tmp_unpack_dir);
7753 + pkg->tmp_unpack_dir = NULL;
7754 + free(pkg->md5sum);
7755 + pkg->md5sum = NULL;
7756 + free(pkg->size);
7757 + pkg->size = NULL;
7758 + free(pkg->installed_size);
7759 + pkg->installed_size = NULL;
7760 + free(pkg->priority);
7761 + pkg->priority = NULL;
7762 + free(pkg->source);
7763 + pkg->source = NULL;
7764 + conffile_list_deinit(&pkg->conffiles);
7765 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7766 + since if they are calling deinit, they should know. Maybe do an
7767 + assertion here instead? */
7768 + pkg->installed_files_ref_cnt = 1;
7769 + pkg_free_installed_files(pkg);
7770 + pkg->essential = 0;
7771 +}
7772 +
7773 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7774 +{
7775 + int err;
7776 + char **raw;
7777 + FILE *control_file;
7778 +
7779 + err = pkg_init(pkg);
7780 + if (err) { return err; }
7781 +
7782 + pkg->local_filename = strdup(filename);
7783 +
7784 + control_file = tmpfile();
7785 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7786 + if (err) { return err; }
7787 +
7788 + rewind(control_file);
7789 + raw = read_raw_pkgs_from_stream(control_file);
7790 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7791 +
7792 + fclose(control_file);
7793 +
7794 + return 0;
7795 +}
7796 +
7797 +/* Merge any new information in newpkg into oldpkg */
7798 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7799 + newpkg, but should leave it usable. This rework is so that
7800 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7801 +/*
7802 + * uh, i thought that i had originally written this so that it took
7803 + * two pkgs and returned a new one? we can do that again... -sma
7804 + */
7805 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7806 +{
7807 + if (oldpkg == newpkg) {
7808 + return 0;
7809 + }
7810 +
7811 + if (!oldpkg->src)
7812 + oldpkg->src = newpkg->src;
7813 + if (!oldpkg->dest)
7814 + oldpkg->dest = newpkg->dest;
7815 + if (!oldpkg->architecture)
7816 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7817 + if (!oldpkg->arch_priority)
7818 + oldpkg->arch_priority = newpkg->arch_priority;
7819 + if (!oldpkg->section)
7820 + oldpkg->section = str_dup_safe(newpkg->section);
7821 + if(!oldpkg->maintainer)
7822 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7823 + if(!oldpkg->description)
7824 + oldpkg->description = str_dup_safe(newpkg->description);
7825 + if (set_status) {
7826 + /* merge the state_flags from the new package */
7827 + oldpkg->state_want = newpkg->state_want;
7828 + oldpkg->state_status = newpkg->state_status;
7829 + oldpkg->state_flag = newpkg->state_flag;
7830 + } else {
7831 + if (oldpkg->state_want == SW_UNKNOWN)
7832 + oldpkg->state_want = newpkg->state_want;
7833 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7834 + oldpkg->state_status = newpkg->state_status;
7835 + oldpkg->state_flag |= newpkg->state_flag;
7836 + }
7837 +
7838 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7839 + oldpkg->depends_str = newpkg->depends_str;
7840 + newpkg->depends_str = NULL;
7841 + oldpkg->depends_count = newpkg->depends_count;
7842 + newpkg->depends_count = 0;
7843 +
7844 + oldpkg->depends = newpkg->depends;
7845 + newpkg->depends = NULL;
7846 +
7847 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7848 + newpkg->pre_depends_str = NULL;
7849 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7850 + newpkg->pre_depends_count = 0;
7851 +
7852 + oldpkg->recommends_str = newpkg->recommends_str;
7853 + newpkg->recommends_str = NULL;
7854 + oldpkg->recommends_count = newpkg->recommends_count;
7855 + newpkg->recommends_count = 0;
7856 +
7857 + oldpkg->suggests_str = newpkg->suggests_str;
7858 + newpkg->suggests_str = NULL;
7859 + oldpkg->suggests_count = newpkg->suggests_count;
7860 + newpkg->suggests_count = 0;
7861 + }
7862 +
7863 + if (!oldpkg->provides_str) {
7864 + oldpkg->provides_str = newpkg->provides_str;
7865 + newpkg->provides_str = NULL;
7866 + oldpkg->provides_count = newpkg->provides_count;
7867 + newpkg->provides_count = 0;
7868 +
7869 + oldpkg->provides = newpkg->provides;
7870 + newpkg->provides = NULL;
7871 + }
7872 +
7873 + if (!oldpkg->conflicts_str) {
7874 + oldpkg->conflicts_str = newpkg->conflicts_str;
7875 + newpkg->conflicts_str = NULL;
7876 + oldpkg->conflicts_count = newpkg->conflicts_count;
7877 + newpkg->conflicts_count = 0;
7878 +
7879 + oldpkg->conflicts = newpkg->conflicts;
7880 + newpkg->conflicts = NULL;
7881 + }
7882 +
7883 + if (!oldpkg->replaces_str) {
7884 + oldpkg->replaces_str = newpkg->replaces_str;
7885 + newpkg->replaces_str = NULL;
7886 + oldpkg->replaces_count = newpkg->replaces_count;
7887 + newpkg->replaces_count = 0;
7888 +
7889 + oldpkg->replaces = newpkg->replaces;
7890 + newpkg->replaces = NULL;
7891 + }
7892 +
7893 + if (!oldpkg->filename)
7894 + oldpkg->filename = str_dup_safe(newpkg->filename);
7895 + if (0)
7896 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7897 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7898 + if (!oldpkg->local_filename)
7899 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7900 + if (!oldpkg->tmp_unpack_dir)
7901 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7902 + if (!oldpkg->md5sum)
7903 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7904 + if (!oldpkg->size)
7905 + oldpkg->size = str_dup_safe(newpkg->size);
7906 + if (!oldpkg->installed_size)
7907 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7908 + if (!oldpkg->priority)
7909 + oldpkg->priority = str_dup_safe(newpkg->priority);
7910 + if (!oldpkg->source)
7911 + oldpkg->source = str_dup_safe(newpkg->source);
7912 + if (oldpkg->conffiles.head == NULL){
7913 + oldpkg->conffiles = newpkg->conffiles;
7914 + conffile_list_init(&newpkg->conffiles);
7915 + }
7916 + if (!oldpkg->installed_files){
7917 + oldpkg->installed_files = newpkg->installed_files;
7918 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7919 + newpkg->installed_files = NULL;
7920 + }
7921 + if (!oldpkg->essential)
7922 + oldpkg->essential = newpkg->essential;
7923 +
7924 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7925 +
7926 + return 0;
7927 +}
7928 +
7929 +abstract_pkg_t *abstract_pkg_new(void)
7930 +{
7931 + abstract_pkg_t * ab_pkg;
7932 +
7933 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7934 +
7935 + if (ab_pkg == NULL) {
7936 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7937 + return NULL;
7938 + }
7939 +
7940 + if ( abstract_pkg_init(ab_pkg) < 0 )
7941 + return NULL;
7942 +
7943 + return ab_pkg;
7944 +}
7945 +
7946 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7947 +{
7948 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7949 +
7950 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7951 + if (ab_pkg->provided_by==NULL){
7952 + return -1;
7953 + }
7954 + ab_pkg->dependencies_checked = 0;
7955 + ab_pkg->state_status = SS_NOT_INSTALLED;
7956 +
7957 + return 0;
7958 +}
7959 +
7960 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7961 + char * temp_str;
7962 + char **raw =NULL;
7963 + char **raw_start=NULL;
7964 +
7965 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7966 + if (temp_str == NULL ){
7967 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7968 + return;
7969 + }
7970 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7971 +
7972 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7973 + if (raw == NULL ){
7974 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7975 + return;
7976 + }
7977 +
7978 + while(*raw){
7979 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7980 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7981 + }
7982 + }
7983 + raw = raw_start;
7984 + while (*raw) {
7985 + if (raw!=NULL)
7986 + free(*raw++);
7987 + }
7988 +
7989 + free(raw_start);
7990 + free(temp_str);
7991 +
7992 + return ;
7993 +
7994 +}
7995 +
7996 +char * pkg_formatted_info(pkg_t *pkg )
7997 +{
7998 + char *line;
7999 + char * buff;
8000 +
8001 + buff = malloc(8192);
8002 + if (buff == NULL) {
8003 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8004 + return NULL;
8005 + }
8006 +
8007 + buff[0] = '\0';
8008 +
8009 + line = pkg_formatted_field(pkg, "Package");
8010 + strncat(buff ,line, strlen(line));
8011 + free(line);
8012 +
8013 + line = pkg_formatted_field(pkg, "Version");
8014 + strncat(buff ,line, strlen(line));
8015 + free(line);
8016 +
8017 + line = pkg_formatted_field(pkg, "Depends");
8018 + strncat(buff ,line, strlen(line));
8019 + free(line);
8020 +
8021 + line = pkg_formatted_field(pkg, "Recommends");
8022 + strncat(buff ,line, strlen(line));
8023 + free(line);
8024 +
8025 + line = pkg_formatted_field(pkg, "Suggests");
8026 + strncat(buff ,line, strlen(line));
8027 + free(line);
8028 +
8029 + line = pkg_formatted_field(pkg, "Provides");
8030 + strncat(buff ,line, strlen(line));
8031 + free(line);
8032 +
8033 + line = pkg_formatted_field(pkg, "Replaces");
8034 + strncat(buff ,line, strlen(line));
8035 + free(line);
8036 +
8037 + line = pkg_formatted_field(pkg, "Conflicts");
8038 + strncat(buff ,line, strlen(line));
8039 + free(line);
8040 +
8041 + line = pkg_formatted_field(pkg, "Status");
8042 + strncat(buff ,line, strlen(line));
8043 + free(line);
8044 +
8045 + line = pkg_formatted_field(pkg, "Section");
8046 + strncat(buff ,line, strlen(line));
8047 + free(line);
8048 +
8049 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8050 + strncat(buff ,line, strlen(line));
8051 + free(line);
8052 +
8053 + line = pkg_formatted_field(pkg, "Architecture");
8054 + strncat(buff ,line, strlen(line));
8055 + free(line);
8056 +
8057 + line = pkg_formatted_field(pkg, "Maintainer");
8058 + strncat(buff ,line, strlen(line));
8059 + free(line);
8060 +
8061 + line = pkg_formatted_field(pkg, "MD5sum");
8062 + strncat(buff ,line, strlen(line));
8063 + free(line);
8064 +
8065 + line = pkg_formatted_field(pkg, "Size");
8066 + strncat(buff ,line, strlen(line));
8067 + free(line);
8068 +
8069 + line = pkg_formatted_field(pkg, "Filename");
8070 + strncat(buff ,line, strlen(line));
8071 + free(line);
8072 +
8073 + line = pkg_formatted_field(pkg, "Conffiles");
8074 + strncat(buff ,line, strlen(line));
8075 + free(line);
8076 +
8077 + line = pkg_formatted_field(pkg, "Source");
8078 + strncat(buff ,line, strlen(line));
8079 + free(line);
8080 +
8081 + line = pkg_formatted_field(pkg, "Description");
8082 + strncat(buff ,line, strlen(line));
8083 + free(line);
8084 +
8085 + line = pkg_formatted_field(pkg, "Installed-Time");
8086 + strncat(buff ,line, strlen(line));
8087 + free(line);
8088 +
8089 + return buff;
8090 +}
8091 +
8092 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8093 +{
8094 + static size_t LINE_LEN = 128;
8095 + char line_str[LINE_LEN];
8096 + char * temp = (char *)malloc(1);
8097 + int len = 0;
8098 + int flag_provide_false = 0;
8099 +
8100 +/*
8101 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8102 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8103 +*/
8104 +
8105 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8106 + goto UNKNOWN_FMT_FIELD;
8107 + }
8108 +
8109 + temp[0]='\0';
8110 +
8111 + switch (field[0])
8112 + {
8113 + case 'a':
8114 + case 'A':
8115 + if (strcasecmp(field, "Architecture") == 0) {
8116 + /* Architecture */
8117 + if (pkg->architecture) {
8118 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8119 + if ( temp == NULL ){
8120 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8121 + return NULL;
8122 + }
8123 + temp[0]='\0';
8124 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8125 + }
8126 + } else {
8127 + goto UNKNOWN_FMT_FIELD;
8128 + }
8129 + break;
8130 + case 'c':
8131 + case 'C':
8132 + if (strcasecmp(field, "Conffiles") == 0) {
8133 + /* Conffiles */
8134 + conffile_list_elt_t *iter;
8135 +
8136 + if (pkg->conffiles.head == NULL) {
8137 + return temp;
8138 + }
8139 +
8140 + len = 14 ;
8141 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8142 + if (iter->data->name && iter->data->value) {
8143 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8144 + }
8145 + }
8146 + temp = (char *)realloc(temp,len);
8147 + if ( temp == NULL ){
8148 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8149 + return NULL;
8150 + }
8151 + temp[0]='\0';
8152 + strncpy(temp, "Conffiles:\n", 12);
8153 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8154 + if (iter->data->name && iter->data->value) {
8155 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8156 + strncat(temp, line_str, strlen(line_str));
8157 + }
8158 + }
8159 + } else if (strcasecmp(field, "Conflicts") == 0) {
8160 + int i;
8161 +
8162 + if (pkg->conflicts_count) {
8163 + len = 14 ;
8164 + for(i = 0; i < pkg->conflicts_count; i++) {
8165 + len = len + (strlen(pkg->conflicts_str[i])+5);
8166 + }
8167 + temp = (char *)realloc(temp,len);
8168 + if ( temp == NULL ){
8169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8170 + return NULL;
8171 + }
8172 + temp[0]='\0';
8173 + strncpy(temp, "Conflicts:", 11);
8174 + for(i = 0; i < pkg->conflicts_count; i++) {
8175 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8176 + strncat(temp, line_str, strlen(line_str));
8177 + }
8178 + strncat(temp, "\n", strlen("\n"));
8179 + }
8180 + } else {
8181 + goto UNKNOWN_FMT_FIELD;
8182 + }
8183 + break;
8184 + case 'd':
8185 + case 'D':
8186 + if (strcasecmp(field, "Depends") == 0) {
8187 + /* Depends */
8188 + int i;
8189 +
8190 + if (pkg->depends_count) {
8191 + len = 14 ;
8192 + for(i = 0; i < pkg->depends_count; i++) {
8193 + len = len + (strlen(pkg->depends_str[i])+4);
8194 + }
8195 + temp = (char *)realloc(temp,len);
8196 + if ( temp == NULL ){
8197 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8198 + return NULL;
8199 + }
8200 + temp[0]='\0';
8201 + strncpy(temp, "Depends:", 10);
8202 + for(i = 0; i < pkg->depends_count; i++) {
8203 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8204 + strncat(temp, line_str, strlen(line_str));
8205 + }
8206 + strncat(temp, "\n", strlen("\n"));
8207 + }
8208 + } else if (strcasecmp(field, "Description") == 0) {
8209 + /* Description */
8210 + if (pkg->description) {
8211 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8212 + if ( temp == NULL ){
8213 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8214 + return NULL;
8215 + }
8216 + temp[0]='\0';
8217 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8218 + }
8219 + } else {
8220 + goto UNKNOWN_FMT_FIELD;
8221 + }
8222 + break;
8223 + case 'e':
8224 + case 'E': {
8225 + /* Essential */
8226 + if (pkg->essential) {
8227 + temp = (char *)realloc(temp,16);
8228 + if ( temp == NULL ){
8229 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8230 + return NULL;
8231 + }
8232 + temp[0]='\0';
8233 + snprintf(temp, (16), "Essential: yes\n");
8234 + }
8235 + }
8236 + break;
8237 + case 'f':
8238 + case 'F': {
8239 + /* Filename */
8240 + if (pkg->filename) {
8241 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8242 + if ( temp == NULL ){
8243 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8244 + return NULL;
8245 + }
8246 + temp[0]='\0';
8247 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8248 + }
8249 + }
8250 + break;
8251 + case 'i':
8252 + case 'I': {
8253 + if (strcasecmp(field, "Installed-Size") == 0) {
8254 + /* Installed-Size */
8255 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8256 + if ( temp == NULL ){
8257 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8258 + return NULL;
8259 + }
8260 + temp[0]='\0';
8261 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8262 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8263 + temp = (char *)realloc(temp,29);
8264 + if ( temp == NULL ){
8265 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8266 + return NULL;
8267 + }
8268 + temp[0]='\0';
8269 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8270 + }
8271 + }
8272 + break;
8273 + case 'm':
8274 + case 'M': {
8275 + /* Maintainer | MD5sum */
8276 + if (strcasecmp(field, "Maintainer") == 0) {
8277 + /* Maintainer */
8278 + if (pkg->maintainer) {
8279 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8280 + if ( temp == NULL ){
8281 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8282 + return NULL;
8283 + }
8284 + temp[0]='\0';
8285 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8286 + }
8287 + } else if (strcasecmp(field, "MD5sum") == 0) {
8288 + /* MD5sum */
8289 + if (pkg->md5sum) {
8290 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8291 + if ( temp == NULL ){
8292 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8293 + return NULL;
8294 + }
8295 + temp[0]='\0';
8296 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8297 + }
8298 + } else {
8299 + goto UNKNOWN_FMT_FIELD;
8300 + }
8301 + }
8302 + break;
8303 + case 'p':
8304 + case 'P': {
8305 + if (strcasecmp(field, "Package") == 0) {
8306 + /* Package */
8307 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8308 + if ( temp == NULL ){
8309 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8310 + return NULL;
8311 + }
8312 + temp[0]='\0';
8313 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8314 + } else if (strcasecmp(field, "Priority") == 0) {
8315 + /* Priority */
8316 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8317 + if ( temp == NULL ){
8318 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8319 + return NULL;
8320 + }
8321 + temp[0]='\0';
8322 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8323 + } else if (strcasecmp(field, "Provides") == 0) {
8324 + /* Provides */
8325 + int i;
8326 +
8327 + if (pkg->provides_count) {
8328 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8329 + for ( i=0; i < pkg->provides_count; i++ ){
8330 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8331 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8332 + flag_provide_false = 1;
8333 + }
8334 + }
8335 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8336 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8337 + char provstr[LINE_LEN];
8338 + len = 15;
8339 + for(i = 0; i < pkg->provides_count; i++) {
8340 + len = len + (strlen(pkg->provides_str[i])+5);
8341 + }
8342 + temp = (char *)realloc(temp,len);
8343 + if ( temp == NULL ){
8344 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8345 + return NULL;
8346 + }
8347 + temp[0]='\0';
8348 + strncpy(temp, "Provides:", 12);
8349 + for(i = 0; i < pkg->provides_count; i++) {
8350 + if (strlen(pkg->provides_str[i])>0){;
8351 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8352 + strncat(temp, provstr, strlen(provstr));
8353 + }
8354 + }
8355 + strncat(temp, "\n", strlen("\n"));
8356 + }
8357 + }
8358 + } else {
8359 + goto UNKNOWN_FMT_FIELD;
8360 + }
8361 + }
8362 + break;
8363 + case 'r':
8364 + case 'R': {
8365 + int i;
8366 + /* Replaces | Recommends*/
8367 + if (strcasecmp (field, "Replaces") == 0) {
8368 + if (pkg->replaces_count) {
8369 + len = 14;
8370 + for (i = 0; i < pkg->replaces_count; i++) {
8371 + len = len + (strlen(pkg->replaces_str[i])+5);
8372 + }
8373 + temp = (char *)realloc(temp,len);
8374 + if ( temp == NULL ){
8375 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8376 + return NULL;
8377 + }
8378 + temp[0]='\0';
8379 + strncpy(temp, "Replaces:", 12);
8380 + for (i = 0; i < pkg->replaces_count; i++) {
8381 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8382 + strncat(temp, line_str, strlen(line_str));
8383 + }
8384 + strncat(temp, "\n", strlen("\n"));
8385 + }
8386 + } else if (strcasecmp (field, "Recommends") == 0) {
8387 + if (pkg->recommends_count) {
8388 + len = 15;
8389 + for(i = 0; i < pkg->recommends_count; i++) {
8390 + len = len + (strlen( pkg->recommends_str[i])+5);
8391 + }
8392 + temp = (char *)realloc(temp,len);
8393 + if ( temp == NULL ){
8394 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8395 + return NULL;
8396 + }
8397 + temp[0]='\0';
8398 + strncpy(temp, "Recommends:", 13);
8399 + for(i = 0; i < pkg->recommends_count; i++) {
8400 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8401 + strncat(temp, line_str, strlen(line_str));
8402 + }
8403 + strncat(temp, "\n", strlen("\n"));
8404 + }
8405 + } else {
8406 + goto UNKNOWN_FMT_FIELD;
8407 + }
8408 + }
8409 + break;
8410 + case 's':
8411 + case 'S': {
8412 + /* Section | Size | Source | Status | Suggests */
8413 + if (strcasecmp(field, "Section") == 0) {
8414 + /* Section */
8415 + if (pkg->section) {
8416 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8417 + if ( temp == NULL ){
8418 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8419 + return NULL;
8420 + }
8421 + temp[0]='\0';
8422 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8423 + }
8424 + } else if (strcasecmp(field, "Size") == 0) {
8425 + /* Size */
8426 + if (pkg->size) {
8427 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8428 + if ( temp == NULL ){
8429 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8430 + return NULL;
8431 + }
8432 + temp[0]='\0';
8433 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8434 + }
8435 + } else if (strcasecmp(field, "Source") == 0) {
8436 + /* Source */
8437 + if (pkg->source) {
8438 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8439 + if ( temp == NULL ){
8440 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8441 + return NULL;
8442 + }
8443 + temp[0]='\0';
8444 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8445 + }
8446 + } else if (strcasecmp(field, "Status") == 0) {
8447 + /* Status */
8448 + /* Benjamin Pineau note: we should avoid direct usage of
8449 + * strlen(arg) without keeping "arg" for later free()
8450 + */
8451 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8452 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8453 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8454 +
8455 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8456 + temp = (char *)realloc(temp,sum_of_sizes);
8457 + if ( temp == NULL ){
8458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8459 + return NULL;
8460 + }
8461 + temp[0]='\0';
8462 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8463 + free(pflag);
8464 + free(pwant);
8465 + if(pstat) /* pfstat can be NULL if ENOMEM */
8466 + free(pstat);
8467 + } else if (strcasecmp(field, "Suggests") == 0) {
8468 + if (pkg->suggests_count) {
8469 + int i;
8470 + len = 13;
8471 + for(i = 0; i < pkg->suggests_count; i++) {
8472 + len = len + (strlen(pkg->suggests_str[i])+5);
8473 + }
8474 + temp = (char *)realloc(temp,len);
8475 + if ( temp == NULL ){
8476 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8477 + return NULL;
8478 + }
8479 + temp[0]='\0';
8480 + strncpy(temp, "Suggests:", 10);
8481 + for(i = 0; i < pkg->suggests_count; i++) {
8482 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8483 + strncat(temp, line_str, strlen(line_str));
8484 + }
8485 + strncat(temp, "\n", strlen("\n"));
8486 + }
8487 + } else {
8488 + goto UNKNOWN_FMT_FIELD;
8489 + }
8490 + }
8491 + break;
8492 + case 'v':
8493 + case 'V': {
8494 + /* Version */
8495 + char *version = pkg_version_str_alloc(pkg);
8496 + temp = (char *)realloc(temp,strlen(version)+14);
8497 + if ( temp == NULL ){
8498 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8499 + return NULL;
8500 + }
8501 + temp[0]='\0';
8502 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8503 + free(version);
8504 + }
8505 + break;
8506 + default:
8507 + goto UNKNOWN_FMT_FIELD;
8508 + }
8509 +
8510 + if ( strlen(temp)<2 ) {
8511 + temp[0]='\0';
8512 + }
8513 + return temp;
8514 +
8515 + UNKNOWN_FMT_FIELD:
8516 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8517 + if ( strlen(temp)<2 ) {
8518 + temp[0]='\0';
8519 + }
8520 +
8521 + return temp;
8522 +}
8523 +
8524 +void pkg_print_info(pkg_t *pkg, FILE *file)
8525 +{
8526 + char * buff;
8527 + if (pkg == NULL) {
8528 + return;
8529 + }
8530 +
8531 + buff = pkg_formatted_info(pkg);
8532 + if ( buff == NULL )
8533 + return;
8534 + if (strlen(buff)>2){
8535 + fwrite(buff, 1, strlen(buff), file);
8536 + }
8537 + free(buff);
8538 +}
8539 +
8540 +void pkg_print_status(pkg_t * pkg, FILE * file)
8541 +{
8542 + if (pkg == NULL) {
8543 + return;
8544 + }
8545 +
8546 + /* XXX: QUESTION: Do we actually want more fields here? The
8547 + original idea was to save space by installing only what was
8548 + needed for actual computation, (package, version, status,
8549 + essential, conffiles). The assumption is that all other fields
8550 + can be found in th available file.
8551 +
8552 + But, someone proposed the idea to make it possible to
8553 + reconstruct a .ipk from an installed package, (ie. for beaming
8554 + from one handheld to another). So, maybe we actually want a few
8555 + more fields here, (depends, suggests, etc.), so that that would
8556 + be guaranteed to work even in the absence of more information
8557 + from the available file.
8558 +
8559 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8560 + the essential info needs to be here for all installed packages
8561 + because they may not appear in the Packages files on various
8562 + feeds. Furthermore, one should be able to install from URL or
8563 + local storage without requiring a Packages file from any feed.
8564 + -Jamey
8565 + */
8566 + pkg_print_field(pkg, file, "Package");
8567 + pkg_print_field(pkg, file, "Version");
8568 + pkg_print_field(pkg, file, "Depends");
8569 + pkg_print_field(pkg, file, "Recommends");
8570 + pkg_print_field(pkg, file, "Suggests");
8571 + pkg_print_field(pkg, file, "Provides");
8572 + pkg_print_field(pkg, file, "Replaces");
8573 + pkg_print_field(pkg, file, "Conflicts");
8574 + pkg_print_field(pkg, file, "Status");
8575 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8576 + pkg_print_field(pkg, file, "Architecture");
8577 + pkg_print_field(pkg, file, "Conffiles");
8578 + pkg_print_field(pkg, file, "Installed-Time");
8579 + fputs("\n", file);
8580 +}
8581 +
8582 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8583 +{
8584 + char *buff;
8585 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8586 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8587 + __FUNCTION__, field);
8588 + }
8589 + buff = pkg_formatted_field(pkg, field);
8590 + if (strlen(buff)>2) {
8591 + fprintf(file, "%s", buff);
8592 + fflush(file);
8593 + }
8594 + free(buff);
8595 + return;
8596 +}
8597 +
8598 +/*
8599 + * libdpkg - Debian packaging suite library routines
8600 + * vercmp.c - comparison of version numbers
8601 + *
8602 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8603 + */
8604 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8605 +{
8606 + int r;
8607 +
8608 + if (pkg->epoch > ref_pkg->epoch) {
8609 + return 1;
8610 + }
8611 +
8612 + if (pkg->epoch < ref_pkg->epoch) {
8613 + return -1;
8614 + }
8615 +
8616 + r = verrevcmp(pkg->version, ref_pkg->version);
8617 + if (r) {
8618 + return r;
8619 + }
8620 +
8621 +#ifdef USE_DEBVERSION
8622 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8623 + if (r) {
8624 + return r;
8625 + }
8626 +
8627 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8628 +#endif
8629 +
8630 + return r;
8631 +}
8632 +
8633 +int verrevcmp(const char *val, const char *ref)
8634 +{
8635 + int vc, rc;
8636 + long vl, rl;
8637 + const char *vp, *rp;
8638 + const char *vsep, *rsep;
8639 +
8640 + if (!val) val= "";
8641 + if (!ref) ref= "";
8642 + for (;;) {
8643 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8644 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8645 + for (;;) {
8646 + vc= (val == vp) ? 0 : *val++;
8647 + rc= (ref == rp) ? 0 : *ref++;
8648 + if (!rc && !vc) break;
8649 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8650 + if (rc && !isalpha(rc)) rc += 256;
8651 + if (vc != rc) return vc - rc;
8652 + }
8653 + val= vp;
8654 + ref= rp;
8655 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8656 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8657 + if (vl != rl) return vl - rl;
8658 +
8659 + vc = *val;
8660 + rc = *ref;
8661 + vsep = strchr(".-", vc);
8662 + rsep = strchr(".-", rc);
8663 + if (vsep && !rsep) return -1;
8664 + if (!vsep && rsep) return +1;
8665 +
8666 + if (!*val && !*ref) return 0;
8667 + if (!*val) return -1;
8668 + if (!*ref) return +1;
8669 + }
8670 +}
8671 +
8672 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8673 +{
8674 + int r;
8675 +
8676 + r = pkg_compare_versions(it, ref);
8677 +
8678 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8679 + return r <= 0;
8680 + }
8681 +
8682 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8683 + return r >= 0;
8684 + }
8685 +
8686 + if (strcmp(op, "<<") == 0) {
8687 + return r < 0;
8688 + }
8689 +
8690 + if (strcmp(op, ">>") == 0) {
8691 + return r > 0;
8692 + }
8693 +
8694 + if (strcmp(op, "=") == 0) {
8695 + return r == 0;
8696 + }
8697 +
8698 + fprintf(stderr, "unknown operator: %s", op);
8699 + return 0;
8700 +}
8701 +
8702 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8703 +{
8704 + int namecmp;
8705 + int vercmp;
8706 + if (!a->name || !b->name) {
8707 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8708 + a, a->name, b, b->name);
8709 + return 0;
8710 + }
8711 +
8712 + namecmp = strcmp(a->name, b->name);
8713 + if (namecmp)
8714 + return namecmp;
8715 + vercmp = pkg_compare_versions(a, b);
8716 + if (vercmp)
8717 + return vercmp;
8718 + if (!a->arch_priority || !b->arch_priority) {
8719 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8720 + a, a->arch_priority, b, b->arch_priority);
8721 + return 0;
8722 + }
8723 + if (a->arch_priority > b->arch_priority)
8724 + return 1;
8725 + if (a->arch_priority < b->arch_priority)
8726 + return -1;
8727 + return 0;
8728 +}
8729 +
8730 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8731 +{
8732 + if (!a->name || !b->name) {
8733 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8734 + a, a->name, b, b->name);
8735 + return 0;
8736 + }
8737 + return strcmp(a->name, b->name);
8738 +}
8739 +
8740 +
8741 +char *pkg_version_str_alloc(pkg_t *pkg)
8742 +{
8743 + char *complete_version;
8744 + char *epoch_str;
8745 +#ifdef USE_DEBVERSION
8746 + char *revision_str;
8747 + char *familiar_revision_str;
8748 +#endif
8749 +
8750 + if (pkg->epoch) {
8751 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8752 + } else {
8753 + epoch_str = strdup("");
8754 + }
8755 +
8756 +#ifdef USE_DEBVERSION
8757 + if (pkg->revision && strlen(pkg->revision)) {
8758 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8759 + } else {
8760 + revision_str = strdup("");
8761 + }
8762 +
8763 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8764 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8765 + } else {
8766 + familiar_revision_str = strdup("");
8767 + }
8768 +#endif
8769 +
8770 +#ifdef USE_DEBVERSION
8771 + sprintf_alloc(&complete_version, "%s%s%s%s",
8772 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8773 +#else
8774 + sprintf_alloc(&complete_version, "%s%s",
8775 + epoch_str, pkg->version);
8776 +#endif
8777 +
8778 + free(epoch_str);
8779 +#ifdef USE_DEBVERSION
8780 + free(revision_str);
8781 + free(familiar_revision_str);
8782 +#endif
8783 +
8784 + return complete_version;
8785 +}
8786 +
8787 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8788 +{
8789 + int err;
8790 + char *list_file_name = NULL;
8791 + FILE *list_file = NULL;
8792 + char *line;
8793 + char *installed_file_name;
8794 + int rootdirlen;
8795 +
8796 + pkg->installed_files_ref_cnt++;
8797 +
8798 + if (pkg->installed_files) {
8799 + return pkg->installed_files;
8800 + }
8801 +
8802 + pkg->installed_files = str_list_alloc();
8803 + if (pkg->installed_files == NULL) {
8804 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8805 + return NULL;
8806 + }
8807 +
8808 + /* For uninstalled packages, get the file list firectly from the package.
8809 + For installed packages, look at the package.list file in the database.
8810 + */
8811 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8812 + if (pkg->local_filename == NULL) {
8813 + return pkg->installed_files;
8814 + }
8815 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8816 + file. In other words, change deb_extract so that it can
8817 + simply return the file list as a char *[] rather than
8818 + insisting on writing in to a FILE * as it does now. */
8819 + list_file = tmpfile();
8820 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8821 + if (err) {
8822 + fclose(list_file);
8823 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8824 + __FUNCTION__, pkg->local_filename, strerror(err));
8825 + return pkg->installed_files;
8826 + }
8827 + rewind(list_file);
8828 + } else {
8829 + sprintf_alloc(&list_file_name, "%s/%s.list",
8830 + pkg->dest->info_dir, pkg->name);
8831 + if (! file_exists(list_file_name)) {
8832 + free(list_file_name);
8833 + return pkg->installed_files;
8834 + }
8835 +
8836 + list_file = fopen(list_file_name, "r");
8837 + if (list_file == NULL) {
8838 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8839 + list_file_name, strerror(errno));
8840 + free(list_file_name);
8841 + return pkg->installed_files;
8842 + }
8843 + free(list_file_name);
8844 + }
8845 +
8846 + rootdirlen = strlen( pkg->dest->root_dir );
8847 + while (1) {
8848 + char *file_name;
8849 +
8850 + line = file_read_line_alloc(list_file);
8851 + if (line == NULL) {
8852 + break;
8853 + }
8854 + str_chomp(line);
8855 + file_name = line;
8856 +
8857 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8858 + if( strncmp( pkg->dest->root_dir,
8859 + file_name,
8860 + rootdirlen ) ) {
8861 + if (*file_name == '.') {
8862 + file_name++;
8863 + }
8864 + if (*file_name == '/') {
8865 + file_name++;
8866 + }
8867 +
8868 + /* Freed in pkg_free_installed_files */
8869 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8870 + } else {
8871 + // already contains root_dir as header -> ABSOLUTE
8872 + sprintf_alloc(&installed_file_name, "%s", file_name);
8873 + }
8874 + str_list_append(pkg->installed_files, installed_file_name);
8875 + free(line);
8876 + }
8877 +
8878 + fclose(list_file);
8879 +
8880 + return pkg->installed_files;
8881 +}
8882 +
8883 +/* XXX: CLEANUP: This function and it's counterpart,
8884 + (pkg_get_installed_files), do not match our init/deinit naming
8885 + convention. Nor the alloc/free convention. But, then again, neither
8886 + of these conventions currrently fit the way these two functions
8887 + work. */
8888 +int pkg_free_installed_files(pkg_t *pkg)
8889 +{
8890 + str_list_elt_t *iter;
8891 +
8892 + pkg->installed_files_ref_cnt--;
8893 + if (pkg->installed_files_ref_cnt > 0) {
8894 + return 0;
8895 + }
8896 +
8897 + if (pkg->installed_files) {
8898 +
8899 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8900 + /* malloced in pkg_get_installed_files */
8901 + free (iter->data);
8902 + iter->data = NULL;
8903 + }
8904 +
8905 + str_list_deinit(pkg->installed_files);
8906 + }
8907 +
8908 + pkg->installed_files = NULL;
8909 +
8910 + return 0;
8911 +}
8912 +
8913 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8914 +{
8915 + int err;
8916 + char *list_file_name;
8917 +
8918 + //I don't think pkg_free_installed_files should be called here. Jamey
8919 + //pkg_free_installed_files(pkg);
8920 +
8921 + sprintf_alloc(&list_file_name, "%s/%s.list",
8922 + pkg->dest->info_dir, pkg->name);
8923 + if (!conf->noaction) {
8924 + err = unlink(list_file_name);
8925 + free(list_file_name);
8926 +
8927 + if (err) {
8928 + return errno;
8929 + }
8930 + }
8931 + return 0;
8932 +}
8933 +
8934 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8935 +{
8936 + conffile_list_elt_t *iter;
8937 + conffile_t *conffile;
8938 +
8939 + if (pkg == NULL) {
8940 + return NULL;
8941 + }
8942 +
8943 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8944 + conffile = iter->data;
8945 +
8946 + if (strcmp(conffile->name, file_name) == 0) {
8947 + return conffile;
8948 + }
8949 + }
8950 +
8951 + return NULL;
8952 +}
8953 +
8954 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8955 + const char *script, const char *args)
8956 +{
8957 + int err;
8958 + char *path;
8959 + char *cmd;
8960 +
8961 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8962 + maintainer script within a chroot environment. */
8963 +
8964 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8965 + have scripts in pkg->tmp_unpack_dir. */
8966 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8967 + if (pkg->dest == NULL) {
8968 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8969 + __FUNCTION__, pkg->name);
8970 + return EINVAL;
8971 + }
8972 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8973 + } else {
8974 + if (pkg->tmp_unpack_dir == NULL) {
8975 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8976 + __FUNCTION__, pkg->name);
8977 + return EINVAL;
8978 + }
8979 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8980 + }
8981 +
8982 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8983 + if (conf->noaction) return 0;
8984 +
8985 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8986 + scripts when running with offline_root mode and/or a dest other
8987 + than '/'. I've been playing around with some clever chroot
8988 + tricks and I might come up with something workable. */
8989 + if (conf->offline_root) {
8990 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8991 + }
8992 +
8993 + setenv("PKG_ROOT",
8994 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8995 +
8996 + if (! file_exists(path)) {
8997 + free(path);
8998 + return 0;
8999 + }
9000 +
9001 + if (conf->offline_root) {
9002 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9003 + free(path);
9004 + return 0;
9005 + }
9006 +
9007 + sprintf_alloc(&cmd, "%s %s", path, args);
9008 + free(path);
9009 +
9010 + err = xsystem(cmd);
9011 + free(cmd);
9012 +
9013 + if (err) {
9014 + fprintf(stderr, "%s script returned status %d\n", script, err);
9015 + return err;
9016 + }
9017 +
9018 + return 0;
9019 +}
9020 +
9021 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9022 +{
9023 + int i;
9024 +
9025 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9026 + if (pkg_state_want_map[i].value == sw) {
9027 + return strdup(pkg_state_want_map[i].str);
9028 + }
9029 + }
9030 +
9031 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9032 + __FUNCTION__, sw);
9033 + return strdup("<STATE_WANT_UNKNOWN>");
9034 +}
9035 +
9036 +pkg_state_want_t pkg_state_want_from_str(char *str)
9037 +{
9038 + int i;
9039 +
9040 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9041 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9042 + return pkg_state_want_map[i].value;
9043 + }
9044 + }
9045 +
9046 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9047 + __FUNCTION__, str);
9048 + return SW_UNKNOWN;
9049 +}
9050 +
9051 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9052 +{
9053 + int i;
9054 + int len = 3; /* ok\000 is minimum */
9055 + char *str = NULL;
9056 +
9057 + /* clear the temporary flags before converting to string */
9058 + sf &= SF_NONVOLATILE_FLAGS;
9059 +
9060 + if (sf == 0) {
9061 + return strdup("ok");
9062 + } else {
9063 +
9064 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9065 + if (sf & pkg_state_flag_map[i].value) {
9066 + len += strlen(pkg_state_flag_map[i].str) + 1;
9067 + }
9068 + }
9069 + str = malloc(len);
9070 + if ( str == NULL ) {
9071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9072 + return NULL;
9073 + }
9074 + str[0] = 0;
9075 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9076 + if (sf & pkg_state_flag_map[i].value) {
9077 + strcat(str, pkg_state_flag_map[i].str);
9078 + strcat(str, ",");
9079 + }
9080 + }
9081 + len = strlen(str);
9082 + str[len-1] = 0; /* squash last comma */
9083 + return str;
9084 + }
9085 +}
9086 +
9087 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9088 +{
9089 + int i;
9090 + int sf = SF_OK;
9091 +
9092 + if (strcmp(str, "ok") == 0) {
9093 + return SF_OK;
9094 + }
9095 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9096 + const char *sfname = pkg_state_flag_map[i].str;
9097 + int sfname_len = strlen(sfname);
9098 + if (strncmp(str, sfname, sfname_len) == 0) {
9099 + sf |= pkg_state_flag_map[i].value;
9100 + str += sfname_len;
9101 + if (str[0] == ',') {
9102 + str++;
9103 + } else {
9104 + break;
9105 + }
9106 + }
9107 + }
9108 +
9109 + return sf;
9110 +}
9111 +
9112 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9113 +{
9114 + int i;
9115 +
9116 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9117 + if (pkg_state_status_map[i].value == ss) {
9118 + return strdup(pkg_state_status_map[i].str);
9119 + }
9120 + }
9121 +
9122 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9123 + __FUNCTION__, ss);
9124 + return strdup("<STATE_STATUS_UNKNOWN>");
9125 +}
9126 +
9127 +pkg_state_status_t pkg_state_status_from_str(char *str)
9128 +{
9129 + int i;
9130 +
9131 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9132 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9133 + return pkg_state_status_map[i].value;
9134 + }
9135 + }
9136 +
9137 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9138 + __FUNCTION__, str);
9139 + return SS_NOT_INSTALLED;
9140 +}
9141 +
9142 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9143 +{
9144 + nv_pair_list_elt_t *l;
9145 +
9146 + if (!pkg->architecture)
9147 + return 1;
9148 +
9149 + l = conf->arch_list.head;
9150 +
9151 + while (l) {
9152 + nv_pair_t *nv = l->data;
9153 + if (strcmp(nv->name, pkg->architecture) == 0) {
9154 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9155 + return 1;
9156 + }
9157 + l = l->next;
9158 + }
9159 +
9160 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9161 + return 0;
9162 +}
9163 +
9164 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9165 +{
9166 + nv_pair_list_elt_t *l;
9167 +
9168 + l = conf->arch_list.head;
9169 +
9170 + while (l) {
9171 + nv_pair_t *nv = l->data;
9172 + if (strcmp(nv->name, archname) == 0) {
9173 + int priority = strtol(nv->value, NULL, 0);
9174 + return priority;
9175 + }
9176 + l = l->next;
9177 + }
9178 + return 0;
9179 +}
9180 +
9181 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9182 +{
9183 + int i;
9184 + hash_table_t *pkg_hash = &conf->pkg_hash;
9185 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9186 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9187 +
9188 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9189 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9190 + /* update arch_priority for each package */
9191 + for (i = 0; i < available_pkgs->len; i++) {
9192 + pkg_t *pkg = available_pkgs->pkgs[i];
9193 + int arch_priority = 1;
9194 + if (!pkg)
9195 + continue;
9196 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9197 + if (pkg->architecture)
9198 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9199 + else
9200 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9201 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9202 + pkg->arch_priority = arch_priority;
9203 + }
9204 +
9205 + for (i = 0; i < available_pkgs->len; i++) {
9206 + pkg_t *pkg = available_pkgs->pkgs[i];
9207 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9208 + /* clear flags and want for any uninstallable package */
9209 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9210 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9211 + pkg->state_want = SW_UNKNOWN;
9212 + pkg->state_flag = 0;
9213 + }
9214 + }
9215 + pkg_vec_free(available_pkgs);
9216 +
9217 + /* update the file owner data structure */
9218 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9219 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9220 + for (i = 0; i < installed_pkgs->len; i++) {
9221 + pkg_t *pkg = installed_pkgs->pkgs[i];
9222 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9223 + str_list_elt_t *iter;
9224 + if (installed_files == NULL) {
9225 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9226 + break;
9227 + }
9228 + for (iter = installed_files->head; iter; iter = iter->next) {
9229 + char *installed_file = iter->data;
9230 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9231 + file_hash_set_file_owner(conf, installed_file, pkg);
9232 + }
9233 + }
9234 + pkg_vec_free(installed_pkgs);
9235 +
9236 + return 0;
9237 +}
9238 +
9239 +struct pkg_write_filelist_data {
9240 + ipkg_conf_t *conf;
9241 + pkg_t *pkg;
9242 + FILE *stream;
9243 +};
9244 +
9245 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9246 +{
9247 + struct pkg_write_filelist_data *data = data_;
9248 + pkg_t *entry = entry_;
9249 + if (entry == data->pkg) {
9250 + fprintf(data->stream, "%s\n", key);
9251 + }
9252 +}
9253 +
9254 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9255 +{
9256 + struct pkg_write_filelist_data data;
9257 + char *list_file_name = NULL;
9258 + int err = 0;
9259 +
9260 + if (!pkg) {
9261 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9262 + return -EINVAL;
9263 + }
9264 + ipkg_message(conf, IPKG_INFO,
9265 + " creating %s.list file\n", pkg->name);
9266 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9267 + if (!list_file_name) {
9268 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9269 + return -ENOMEM;
9270 + }
9271 + ipkg_message(conf, IPKG_INFO,
9272 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9273 + data.stream = fopen(list_file_name, "w");
9274 + if (!data.stream) {
9275 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9276 + list_file_name, strerror(errno));
9277 + return errno;
9278 + }
9279 + data.pkg = pkg;
9280 + data.conf = conf;
9281 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9282 + fclose(data.stream);
9283 + free(list_file_name);
9284 +
9285 + return err;
9286 +}
9287 +
9288 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9289 +{
9290 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9291 + hash_table_t *pkg_hash = &conf->pkg_hash;
9292 + int i;
9293 + int err;
9294 + if (conf->noaction)
9295 + return 0;
9296 +
9297 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9298 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9299 + for (i = 0; i < installed_pkgs->len; i++) {
9300 + pkg_t *pkg = installed_pkgs->pkgs[i];
9301 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9302 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9303 + err = pkg_write_filelist(conf, pkg);
9304 + if (err)
9305 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9306 + }
9307 + }
9308 + return 0;
9309 +}
9310 Index: busybox-1.7.2/archival/libipkg/pkg_depends.c
9311 ===================================================================
9312 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9313 +++ busybox-1.7.2/archival/libipkg/pkg_depends.c 2007-10-30 15:35:05.000000000 -0500
9314 @@ -0,0 +1,1031 @@
9315 +/* pkg_depends.c - the itsy package management system
9316 +
9317 + Steven M. Ayer
9318 +
9319 + Copyright (C) 2002 Compaq Computer Corporation
9320 +
9321 + This program is free software; you can redistribute it and/or
9322 + modify it under the terms of the GNU General Public License as
9323 + published by the Free Software Foundation; either version 2, or (at
9324 + your option) any later version.
9325 +
9326 + This program is distributed in the hope that it will be useful, but
9327 + WITHOUT ANY WARRANTY; without even the implied warranty of
9328 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9329 + General Public License for more details.
9330 +*/
9331 +
9332 +#include "ipkg.h"
9333 +#include <errno.h>
9334 +#include <ctype.h>
9335 +
9336 +#include "pkg.h"
9337 +#include "ipkg_utils.h"
9338 +#include "pkg_hash.h"
9339 +#include "ipkg_message.h"
9340 +#include "pkg_parse.h"
9341 +#include "hash_table.h"
9342 +
9343 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9344 +static depend_t * depend_init(void);
9345 +static void depend_deinit(depend_t *d);
9346 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9347 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9348 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9349 +
9350 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9351 +{
9352 + depend_t *depend = (depend_t *)cdata;
9353 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9354 + return 1;
9355 + else
9356 + return 0;
9357 +}
9358 +
9359 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9360 +{
9361 + depend_t *depend = (depend_t *)cdata;
9362 +#if 0
9363 + pkg_t * temp = pkg_new();
9364 + int comparison;
9365 + parseVersion(temp, depend->version);
9366 + comparison = pkg_compare_versions(pkg, temp);
9367 + free(temp);
9368 +
9369 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9370 + __FUNCTION__, pkg->name, pkg->version,
9371 + depend, depend->constraint, depend->version,
9372 + comparison, version_constraints_satisfied(depend, pkg));
9373 +#endif
9374 + if (version_constraints_satisfied(depend, pkg))
9375 + return 1;
9376 + else
9377 + return 0;
9378 +}
9379 +
9380 +/* returns ndependences or negative error value */
9381 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9382 + pkg_vec_t *unsatisfied, char *** unresolved)
9383 +{
9384 + pkg_t * satisfier_entry_pkg;
9385 + register int i, j, k, l;
9386 + int count, found;
9387 + char ** the_lost;
9388 + abstract_pkg_t * ab_pkg;
9389 +
9390 + /*
9391 + * this is a setup to check for redundant/cyclic dependency checks,
9392 + * which are marked at the abstract_pkg level
9393 + */
9394 + if (!(ab_pkg = pkg->parent)) {
9395 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9396 + *unresolved = NULL;
9397 + return 0;
9398 + }
9399 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9400 + *unresolved = NULL;
9401 + return 0;
9402 + } else {
9403 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9404 + }
9405 + /**/
9406 +
9407 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9408 + if (!count){
9409 + *unresolved = NULL;
9410 + return 0;
9411 + }
9412 +
9413 + the_lost = NULL;
9414 +
9415 + /* foreach dependency */
9416 + for (i = 0; i < count; i++) {
9417 + compound_depend_t * compound_depend = &pkg->depends[i];
9418 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9419 + found = 0;
9420 + satisfier_entry_pkg = NULL;
9421 +
9422 + if (compound_depend->type == GREEDY_DEPEND) {
9423 + /* foreach possible satisfier */
9424 + for (j = 0; j < compound_depend->possibility_count; j++) {
9425 + /* foreach provided_by, which includes the abstract_pkg itself */
9426 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9427 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9428 + int nposs = ab_provider_vec->len;
9429 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9430 + for (l = 0; l < nposs; l++) {
9431 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9432 + /* if no depends on this one, try the first package that Provides this one */
9433 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9434 + continue;
9435 + }
9436 +
9437 + /* cruise this possiblity's pkg_vec looking for an installed version */
9438 + for (k = 0; k < test_vec->len; k++) {
9439 + pkg_t *pkg_scout = test_vec->pkgs[k];
9440 + /* not installed, and not already known about? */
9441 + if ((pkg_scout->state_want != SW_INSTALL)
9442 + && !pkg_scout->parent->dependencies_checked
9443 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9444 + char ** newstuff = NULL;
9445 + int rc;
9446 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9447 + /* check for not-already-installed dependencies */
9448 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9449 + pkg_scout,
9450 + tmp_vec,
9451 + &newstuff);
9452 + if (newstuff == NULL) {
9453 + int ok = 1;
9454 + for (l = 0; l < rc; l++) {
9455 + pkg_t *p = tmp_vec->pkgs[l];
9456 + if (p->state_want == SW_INSTALL)
9457 + continue;
9458 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9459 + ok = 0;
9460 + break;
9461 + }
9462 + pkg_vec_free (tmp_vec);
9463 + if (ok) {
9464 + /* mark this one for installation */
9465 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9466 + pkg_vec_insert(unsatisfied, pkg_scout);
9467 + }
9468 + } else {
9469 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9470 + free (newstuff);
9471 + }
9472 + }
9473 + }
9474 + }
9475 + }
9476 +
9477 + continue;
9478 + }
9479 +
9480 + /* foreach possible satisfier, look for installed package */
9481 + for (j = 0; j < compound_depend->possibility_count; j++) {
9482 + /* foreach provided_by, which includes the abstract_pkg itself */
9483 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9484 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9485 + pkg_t *satisfying_pkg =
9486 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9487 + pkg_installed_and_constraint_satisfied,
9488 + dependence_to_satisfy, 1);
9489 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9490 + if (satisfying_pkg != NULL) {
9491 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9492 + satisfying_pkg = NULL;
9493 + }
9494 + }
9495 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9496 + if (satisfying_pkg != NULL) {
9497 + found = 1;
9498 + break;
9499 + }
9500 +
9501 + }
9502 + /* if nothing installed matches, then look for uninstalled satisfier */
9503 + if (!found) {
9504 + /* foreach possible satisfier, look for installed package */
9505 + for (j = 0; j < compound_depend->possibility_count; j++) {
9506 + /* foreach provided_by, which includes the abstract_pkg itself */
9507 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9508 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9509 + pkg_t *satisfying_pkg =
9510 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9511 + pkg_constraint_satisfied,
9512 + dependence_to_satisfy, 1);
9513 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9514 + if (satisfying_pkg != NULL) {
9515 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9516 + satisfying_pkg = NULL;
9517 + }
9518 + }
9519 +
9520 + /* user request overrides package recommendation */
9521 + if (satisfying_pkg != NULL
9522 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9523 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9524 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9525 + pkg->name, satisfying_pkg->name);
9526 + continue;
9527 + }
9528 +
9529 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9530 + if (satisfying_pkg != NULL) {
9531 + satisfier_entry_pkg = satisfying_pkg;
9532 + break;
9533 + }
9534 + }
9535 + }
9536 +
9537 + /* we didn't find one, add something to the unsatisfied vector */
9538 + if (!found) {
9539 + if (!satisfier_entry_pkg) {
9540 + /* failure to meet recommendations is not an error */
9541 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9542 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9543 + else
9544 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9545 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9546 + }
9547 + else {
9548 + if (compound_depend->type == SUGGEST) {
9549 + /* just mention it politely */
9550 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9551 + pkg->name, satisfier_entry_pkg->name);
9552 + } else {
9553 + char ** newstuff = NULL;
9554 +
9555 + if (satisfier_entry_pkg != pkg &&
9556 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9557 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9558 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9559 + satisfier_entry_pkg,
9560 + unsatisfied,
9561 + &newstuff);
9562 + the_lost = merge_unresolved(the_lost, newstuff);
9563 + }
9564 + }
9565 + }
9566 + }
9567 + }
9568 + *unresolved = the_lost;
9569 +
9570 + return unsatisfied->len;
9571 +}
9572 +
9573 +/*checking for conflicts !in replaces
9574 + If a packages conflicts with another but is also replacing it, I should not consider it a
9575 + really conflicts
9576 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9577 +*/
9578 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9579 +{
9580 + int i ;
9581 + int replaces_count = pkg->replaces_count;
9582 + abstract_pkg_t **replaces;
9583 +
9584 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9585 + return 0;
9586 +
9587 + replaces = pkg->replaces;
9588 +
9589 + for (i = 0; i < replaces_count; i++) {
9590 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9591 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9592 + return 1;
9593 + }
9594 + }
9595 + return 0;
9596 +
9597 +}
9598 +
9599 +
9600 +/* Abhaya: added support for conflicts */
9601 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9602 +{
9603 + pkg_vec_t * installed_conflicts, * test_vec;
9604 + compound_depend_t * conflicts;
9605 + depend_t ** possible_satisfiers;
9606 + depend_t * possible_satisfier;
9607 + register int i, j, k;
9608 + int count;
9609 + abstract_pkg_t * ab_pkg;
9610 + pkg_t **pkg_scouts;
9611 + pkg_t *pkg_scout;
9612 +
9613 + /*
9614 + * this is a setup to check for redundant/cyclic dependency checks,
9615 + * which are marked at the abstract_pkg level
9616 + */
9617 + if(!(ab_pkg = pkg->parent)){
9618 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9619 + return (pkg_vec_t *)NULL;
9620 + }
9621 +
9622 + conflicts = pkg->conflicts;
9623 + if(!conflicts){
9624 + return (pkg_vec_t *)NULL;
9625 + }
9626 + installed_conflicts = pkg_vec_alloc();
9627 +
9628 + count = pkg->conflicts_count;
9629 +
9630 +
9631 +
9632 + /* foreach conflict */
9633 + for(i = 0; i < pkg->conflicts_count; i++){
9634 +
9635 + possible_satisfiers = conflicts->possibilities;
9636 +
9637 + /* foreach possible satisfier */
9638 + for(j = 0; j < conflicts->possibility_count; j++){
9639 + possible_satisfier = possible_satisfiers[j];
9640 + if (!possible_satisfier)
9641 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9642 + if (!possible_satisfier->pkg)
9643 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9644 + test_vec = possible_satisfier->pkg->pkgs;
9645 + if (test_vec) {
9646 + /* pkg_vec found, it is an actual package conflict
9647 + * cruise this possiblity's pkg_vec looking for an installed version */
9648 + pkg_scouts = test_vec->pkgs;
9649 + for(k = 0; k < test_vec->len; k++){
9650 + pkg_scout = pkg_scouts[k];
9651 + if (!pkg_scout) {
9652 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9653 + continue;
9654 + }
9655 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9656 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9657 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9658 + pkg_vec_insert(installed_conflicts, pkg_scout);
9659 + }
9660 + }
9661 + }
9662 + }
9663 + }
9664 + conflicts++;
9665 + }
9666 +
9667 + if (installed_conflicts->len)
9668 + return installed_conflicts;
9669 + pkg_vec_free(installed_conflicts);
9670 + return (pkg_vec_t *)NULL;
9671 +}
9672 +
9673 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9674 +{
9675 + pkg_t * temp;
9676 + int comparison;
9677 +
9678 + if(depends->constraint == NONE)
9679 + return 1;
9680 +
9681 + temp = pkg_new();
9682 +
9683 + parseVersion(temp, depends->version);
9684 +
9685 + comparison = pkg_compare_versions(pkg, temp);
9686 +
9687 + free(temp);
9688 +
9689 + if((depends->constraint == EARLIER) &&
9690 + (comparison < 0))
9691 + return 1;
9692 + else if((depends->constraint == LATER) &&
9693 + (comparison > 0))
9694 + return 1;
9695 + else if(comparison == 0)
9696 + return 1;
9697 + else if((depends->constraint == LATER_EQUAL) &&
9698 + (comparison >= 0))
9699 + return 1;
9700 + else if((depends->constraint == EARLIER_EQUAL) &&
9701 + (comparison <= 0))
9702 + return 1;
9703 +
9704 + return 0;
9705 +}
9706 +
9707 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9708 +{
9709 + abstract_pkg_t *apkg = depend->pkg;
9710 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9711 + int n_providers = provider_apkgs->len;
9712 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9713 + pkg_vec_t *pkg_vec;
9714 + int n_pkgs ;
9715 + int i;
9716 + int j;
9717 +
9718 + for (i = 0; i < n_providers; i++) {
9719 + abstract_pkg_t *papkg = apkgs[i];
9720 + pkg_vec = papkg->pkgs;
9721 + if (pkg_vec) {
9722 + n_pkgs = pkg_vec->len;
9723 + for (j = 0; j < n_pkgs; j++) {
9724 + pkg_t *pkg = pkg_vec->pkgs[j];
9725 + if (version_constraints_satisfied(depend, pkg)) {
9726 + return 1;
9727 + }
9728 + }
9729 + }
9730 + }
9731 + return 0;
9732 +}
9733 +
9734 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9735 +{
9736 + abstract_pkg_t *apkg = depend->pkg;
9737 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9738 + int n_providers = provider_apkgs->len;
9739 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9740 + int i;
9741 + int n_pkgs;
9742 + int j;
9743 +
9744 + for (i = 0; i < n_providers; i++) {
9745 + abstract_pkg_t *papkg = apkgs[i];
9746 + pkg_vec_t *pkg_vec = papkg->pkgs;
9747 + if (pkg_vec) {
9748 + n_pkgs = pkg_vec->len;
9749 + for (j = 0; j < n_pkgs; j++) {
9750 + pkg_t *pkg = pkg_vec->pkgs[j];
9751 + if (version_constraints_satisfied(depend, pkg)) {
9752 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9753 + return 1;
9754 + }
9755 + }
9756 + }
9757 + }
9758 + return 0;
9759 +}
9760 +
9761 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9762 +{
9763 + register int i;
9764 + pkg_t ** pkgs = vec->pkgs;
9765 +
9766 + for(i = 0; i < vec->len; i++)
9767 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9768 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9769 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9770 + return 1;
9771 + return 0;
9772 +}
9773 +
9774 +
9775 +#ifdef DeadCode
9776 +/**
9777 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9778 + * the same abstract package and 0 otherwise.
9779 + */
9780 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9781 +{
9782 + abstract_pkg_t **provides = pkg->provides;
9783 + int provides_count = pkg->provides_count;
9784 + abstract_pkg_t **replacee_provides = replacee->provides;
9785 + int replacee_provides_count = replacee->provides_count;
9786 + int i, j;
9787 + for (i = 0; i < provides_count; i++) {
9788 + abstract_pkg_t *apkg = provides[i];
9789 + for (j = 0; j < replacee_provides_count; j++) {
9790 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9791 + if (apkg == replacee_apkg)
9792 + return 1;
9793 + }
9794 + }
9795 + return 0;
9796 +}
9797 +#endif
9798 +
9799 +/**
9800 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9801 + * and 0 otherwise.
9802 + */
9803 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9804 +{
9805 + abstract_pkg_t **provides = pkg->provides;
9806 + int provides_count = pkg->provides_count;
9807 + int i;
9808 + for (i = 0; i < provides_count; i++) {
9809 + if (provides[i] == providee)
9810 + return 1;
9811 + }
9812 + return 0;
9813 +}
9814 +
9815 +/**
9816 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9817 + * otherwise.
9818 + */
9819 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9820 +{
9821 + abstract_pkg_t **replaces = pkg->replaces;
9822 + int replaces_count = pkg->replaces_count;
9823 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9824 + int replacee_provides_count = pkg->provides_count; */
9825 + int i, j;
9826 + for (i = 0; i < replaces_count; i++) {
9827 + abstract_pkg_t *abstract_replacee = replaces[i];
9828 + for (j = 0; j < replaces_count; j++) {
9829 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9830 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9831 + if (replacee->provides[j] == abstract_replacee)
9832 + return 1;
9833 + }
9834 + }
9835 + return 0;
9836 +}
9837 +
9838 +
9839 +/**
9840 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9841 + * otherwise.
9842 + */
9843 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9844 +{
9845 + compound_depend_t *conflicts = pkg->conflicts;
9846 + int conflicts_count = pkg->conflicts_count;
9847 + int i, j;
9848 + for (i = 0; i < conflicts_count; i++) {
9849 + int possibility_count = conflicts[i].possibility_count;
9850 + struct depend **possibilities = conflicts[i].possibilities;
9851 + for (j = 0; j < possibility_count; j++) {
9852 + if (possibilities[j]->pkg == conflictee) {
9853 + return 1;
9854 + }
9855 + }
9856 + }
9857 + return 0;
9858 +}
9859 +
9860 +/**
9861 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9862 + * conflictee's provides and 0 otherwise.
9863 + */
9864 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9865 +{
9866 + compound_depend_t *conflicts = pkg->conflicts;
9867 + int conflicts_count = pkg->conflicts_count;
9868 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9869 + int conflictee_provides_count = conflictee->provides_count;
9870 + int i, j, k;
9871 + int possibility_count;
9872 + struct depend **possibilities;
9873 + abstract_pkg_t *possibility ;
9874 +
9875 + for (i = 0; i < conflicts_count; i++) {
9876 + possibility_count = conflicts[i].possibility_count;
9877 + possibilities = conflicts[i].possibilities;
9878 + for (j = 0; j < possibility_count; j++) {
9879 + possibility = possibilities[j]->pkg;
9880 + for (k = 0; k < conflictee_provides_count; k++) {
9881 + if (possibility == conflictee_provides[k]) {
9882 + return 1;
9883 + }
9884 + }
9885 + }
9886 + }
9887 + return 0;
9888 +}
9889 +
9890 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9891 +{
9892 + int oldlen = 0, newlen = 0;
9893 + char ** result;
9894 + register int i, j;
9895 +
9896 + if(!newstuff)
9897 + return oldstuff;
9898 +
9899 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9900 + while(newstuff && newstuff[newlen]) newlen++;
9901 +
9902 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9903 + if (result == NULL) {
9904 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9905 + return NULL;
9906 + }
9907 +
9908 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9909 + *(result + i) = *(newstuff + j);
9910 +
9911 + *(result + i) = NULL;
9912 +
9913 + return result;
9914 +}
9915 +
9916 +/*
9917 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9918 + * this is null terminated, no count is carried around
9919 + */
9920 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9921 +{
9922 + int count;
9923 + char ** resized;
9924 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9925 +
9926 + count = 0;
9927 + while(the_lost && the_lost[count]) count++;
9928 +
9929 + count++; /* need one to hold the null */
9930 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9931 + if (resized == NULL) {
9932 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9933 + return NULL;
9934 + }
9935 + resized[count - 1] = strdup(depend_str);
9936 + resized[count] = NULL;
9937 +
9938 + return resized;
9939 +}
9940 +
9941 +void printDepends(pkg_t * pkg)
9942 +{
9943 + register int i, j;
9944 + compound_depend_t * depend;
9945 + int count;
9946 +
9947 + count = pkg->pre_depends_count + pkg->depends_count;
9948 +
9949 + depend = pkg->depends;
9950 + if(!depend){
9951 + fprintf(stderr, "Depends pointer is NULL\n");
9952 + return;
9953 + }
9954 + for(i = 0; i < count; i++){
9955 + fprintf(stderr, "%s has %d possibilities:\n",
9956 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9957 + depend->possibility_count);
9958 + for(j = 0; j < depend->possibility_count; j++)
9959 + fprintf(stderr, "\t%s version %s (%d)\n",
9960 + depend->possibilities[j]->pkg->name,
9961 + depend->possibilities[j]->version,
9962 + depend->possibilities[j]->constraint);
9963 + depend++;
9964 + }
9965 +}
9966 +
9967 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9968 +{
9969 + register int i, j;
9970 +
9971 + /* every pkg provides itself */
9972 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9973 +
9974 + if (!pkg->provides_count)
9975 + return 0;
9976 +
9977 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9978 + if (pkg->provides == NULL) {
9979 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9980 + return -1 ;
9981 + }
9982 + pkg->provides[0] = ab_pkg;
9983 +
9984 + // if (strcmp(ab_pkg->name, pkg->name))
9985 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9986 +
9987 + for(i = 0; i < pkg->provides_count; i++){
9988 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9989 +
9990 + pkg->provides[i+1] = provided_abpkg;
9991 +
9992 + j = 0;
9993 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9994 + }
9995 + return 0;
9996 +}
9997 +
9998 +/* Abhaya: added conflicts support */
9999 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10000 +{
10001 + register int i;
10002 + compound_depend_t * conflicts;
10003 +
10004 + if (!pkg->conflicts_count)
10005 + return 0;
10006 +
10007 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10008 + pkg->conflicts_count);
10009 + if (conflicts == NULL) {
10010 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10011 + return -1;
10012 + }
10013 + for (i = 0; i < pkg->conflicts_count; i++) {
10014 + conflicts->type = CONFLICTS;
10015 + parseDepends(conflicts, hash,
10016 + pkg->conflicts_str[i]);
10017 +#if 0
10018 + for (j = 0; j < conflicts->possibility_count; j++) {
10019 + depend_t *possibility = conflicts->possibilities[j];
10020 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10021 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10022 + }
10023 +#endif
10024 + conflicts++;
10025 + }
10026 + return 0;
10027 +}
10028 +
10029 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10030 +{
10031 + register int i, j;
10032 +
10033 + if (!pkg->replaces_count)
10034 + return 0;
10035 +
10036 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10037 + if (pkg->replaces == NULL) {
10038 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10039 + return -1;
10040 + }
10041 +
10042 + // if (strcmp(ab_pkg->name, pkg->name))
10043 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10044 +
10045 + for(i = 0; i < pkg->replaces_count; i++){
10046 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10047 +
10048 + pkg->replaces[i] = old_abpkg;
10049 +
10050 + j = 0;
10051 + if (!old_abpkg->replaced_by)
10052 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10053 + if ( old_abpkg->replaced_by == NULL ){
10054 + return -1;
10055 + }
10056 + /* if a package pkg both replaces and conflicts old_abpkg,
10057 + * then add it to the replaced_by vector so that old_abpkg
10058 + * will be upgraded to ab_pkg automatically */
10059 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10060 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10061 + }
10062 + return 0;
10063 +}
10064 +
10065 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10066 +{
10067 + int count;
10068 + register int i;
10069 + compound_depend_t * depends;
10070 +
10071 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10072 + return 0;
10073 +
10074 + if (0 && pkg->pre_depends_count)
10075 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10076 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10077 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10078 + if (depends == NULL) {
10079 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10080 + return -1;
10081 + }
10082 +
10083 +
10084 + for(i = 0; i < pkg->pre_depends_count; i++){
10085 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10086 + if (0 && pkg->pre_depends_count)
10087 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10088 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10089 + depends->type = PREDEPEND;
10090 + depends++;
10091 + }
10092 +
10093 + for(i = 0; i < pkg->recommends_count; i++){
10094 + parseDepends(depends, hash, pkg->recommends_str[i]);
10095 + if (0 && pkg->recommends_count)
10096 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10097 + pkg->recommends_str[i], depends, depends->possibility_count);
10098 + depends->type = RECOMMEND;
10099 + depends++;
10100 + }
10101 +
10102 + for(i = 0; i < pkg->suggests_count; i++){
10103 + parseDepends(depends, hash, pkg->suggests_str[i]);
10104 + if (0 && pkg->suggests_count)
10105 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10106 + pkg->suggests_str[i], depends, depends->possibility_count);
10107 + depends->type = SUGGEST;
10108 + depends++;
10109 + }
10110 +
10111 + for(i = 0; i < pkg->depends_count; i++){
10112 + parseDepends(depends, hash, pkg->depends_str[i]);
10113 + if (0 && pkg->depends_count)
10114 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10115 + pkg->depends_str[i], depends, depends->possibility_count);
10116 + depends++;
10117 + }
10118 + return 0;
10119 +}
10120 +
10121 +/*
10122 + * pkg_depend_string: returns the depends string specified by index.
10123 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10124 + * [0,npredepends) -> returns pre_depends_str[index]
10125 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10126 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10127 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10128 + */
10129 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10130 +{
10131 + if (pkg_index < pkg->pre_depends_count) {
10132 + return pkg->pre_depends_str[pkg_index];
10133 + }
10134 + pkg_index -= pkg->pre_depends_count;
10135 +
10136 + if (pkg_index < pkg->recommends_count) {
10137 + return pkg->recommends_str[pkg_index];
10138 + }
10139 + pkg_index -= pkg->recommends_count;
10140 +
10141 + if (pkg_index < pkg->suggests_count) {
10142 + return pkg->suggests_str[pkg_index];
10143 + }
10144 + pkg_index -= pkg->suggests_count;
10145 +
10146 + if (pkg_index < pkg->depends_count) {
10147 + return pkg->depends_str[pkg_index];
10148 + }
10149 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10150 + return NULL;
10151 +}
10152 +
10153 +void freeDepends(pkg_t *pkg)
10154 +{
10155 + int i;
10156 +
10157 + if (pkg == NULL || pkg->depends == NULL) {
10158 + return;
10159 + }
10160 +
10161 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10162 + for (i=0; i < pkg->depends->possibility_count; i++) {
10163 + depend_deinit(pkg->depends->possibilities[i]);
10164 + }
10165 + free(pkg->depends->possibilities);
10166 + free(pkg->depends);
10167 + pkg->depends = NULL;
10168 +}
10169 +
10170 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10171 +{
10172 + compound_depend_t * depends;
10173 + int count, othercount;
10174 + register int i, j;
10175 + abstract_pkg_t * ab_depend;
10176 + abstract_pkg_t ** temp;
10177 +
10178 + count = pkg->pre_depends_count + pkg->depends_count;
10179 + depends = pkg->depends;
10180 +
10181 + if (0 && pkg->pre_depends_count)
10182 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10183 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10184 + for (i = 0; i < count; i++) {
10185 + if (0 && pkg->pre_depends_count)
10186 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10187 + for (j = 0; j < depends->possibility_count; j++){
10188 + ab_depend = depends->possibilities[j]->pkg;
10189 + if(!ab_depend->depended_upon_by)
10190 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10191 +
10192 + temp = ab_depend->depended_upon_by;
10193 + othercount = 1;
10194 + while(*temp){
10195 + temp++;
10196 + othercount++;
10197 + }
10198 + *temp = ab_pkg;
10199 +
10200 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10201 + (othercount + 1) * sizeof(abstract_pkg_t *));
10202 + /* the array may have moved */
10203 + temp = ab_depend->depended_upon_by + othercount;
10204 + *temp = NULL;
10205 + }
10206 + depends++;
10207 + }
10208 +}
10209 +
10210 +static depend_t * depend_init(void)
10211 +{
10212 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10213 + if ( d==NULL ){
10214 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10215 + return NULL;
10216 + }
10217 + d->constraint = NONE;
10218 + d->version = NULL;
10219 + d->pkg = NULL;
10220 +
10221 + return d;
10222 +}
10223 +
10224 +static void depend_deinit(depend_t *d)
10225 +{
10226 + free(d);
10227 +}
10228 +
10229 +static int parseDepends(compound_depend_t *compound_depend,
10230 + hash_table_t * hash, char * depend_str)
10231 +{
10232 + char * pkg_name, buffer[2048];
10233 + int num_of_ors = 0;
10234 + register int i;
10235 + register char * src, * dest;
10236 + depend_t ** possibilities;
10237 +
10238 + /* first count the number of ored possibilities for satisfying dependency */
10239 + src = depend_str;
10240 + while(*src)
10241 + if(*src++ == '|')
10242 + num_of_ors++;
10243 +
10244 + compound_depend->type = DEPEND;
10245 +
10246 + compound_depend->possibility_count = num_of_ors + 1;
10247 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10248 + if (!possibilities)
10249 + return -ENOMEM;
10250 + compound_depend->possibilities = possibilities;
10251 +
10252 + src = depend_str;
10253 + for(i = 0; i < num_of_ors + 1; i++){
10254 + possibilities[i] = depend_init();
10255 + if (!possibilities[i])
10256 + return -ENOMEM;
10257 + /* gobble up just the name first */
10258 + dest = buffer;
10259 + while(*src &&
10260 + !isspace(*src) &&
10261 + (*src != '(') &&
10262 + (*src != '*') &&
10263 + (*src != '|'))
10264 + *dest++ = *src++;
10265 + *dest = '\0';
10266 + pkg_name = trim_alloc(buffer);
10267 + if (pkg_name == NULL )
10268 + return -ENOMEM;
10269 +
10270 + /* now look at possible version info */
10271 +
10272 + /* skip to next chars */
10273 + if(isspace(*src))
10274 + while(*src && isspace(*src)) src++;
10275 +
10276 + /* extract constraint and version */
10277 + if(*src == '('){
10278 + src++;
10279 + if(!strncmp(src, "<<", 2)){
10280 + possibilities[i]->constraint = EARLIER;
10281 + src += 2;
10282 + }
10283 + else if(!strncmp(src, "<=", 2)){
10284 + possibilities[i]->constraint = EARLIER_EQUAL;
10285 + src += 2;
10286 + }
10287 + else if(!strncmp(src, ">=", 2)){
10288 + possibilities[i]->constraint = LATER_EQUAL;
10289 + src += 2;
10290 + }
10291 + else if(!strncmp(src, ">>", 2)){
10292 + possibilities[i]->constraint = LATER;
10293 + src += 2;
10294 + }
10295 + else if(!strncmp(src, "=", 1)){
10296 + possibilities[i]->constraint = EQUAL;
10297 + src++;
10298 + }
10299 + /* should these be here to support deprecated designations; dpkg does */
10300 + else if(!strncmp(src, "<", 1)){
10301 + possibilities[i]->constraint = EARLIER_EQUAL;
10302 + src++;
10303 + }
10304 + else if(!strncmp(src, ">", 1)){
10305 + possibilities[i]->constraint = LATER_EQUAL;
10306 + src++;
10307 + }
10308 +
10309 + /* now we have any constraint, pass space to version string */
10310 + while(isspace(*src)) src++;
10311 +
10312 + /* this would be the version string */
10313 + dest = buffer;
10314 + while(*src && *src != ')')
10315 + *dest++ = *src++;
10316 + *dest = '\0';
10317 +
10318 + possibilities[i]->version = trim_alloc(buffer);
10319 + /* fprintf(stderr, "let's print the depends version string:");
10320 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10321 + if (possibilities[i]->version == NULL )
10322 + return -ENOMEM;
10323 +
10324 +
10325 + }
10326 + /* hook up the dependency to its abstract pkg */
10327 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10328 +
10329 + free(pkg_name);
10330 +
10331 + /* now get past the ) and any possible | chars */
10332 + while(*src &&
10333 + (isspace(*src) ||
10334 + (*src == ')') ||
10335 + (*src == '|')))
10336 + src++;
10337 + if (*src == '*')
10338 + {
10339 + compound_depend->type = GREEDY_DEPEND;
10340 + src++;
10341 + }
10342 + }
10343 +
10344 + return 0;
10345 +}
10346 Index: busybox-1.7.2/archival/libipkg/pkg_depends.h
10347 ===================================================================
10348 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10349 +++ busybox-1.7.2/archival/libipkg/pkg_depends.h 2007-10-30 15:35:05.000000000 -0500
10350 @@ -0,0 +1,105 @@
10351 +/* pkg_depends.h - the itsy package management system
10352 +
10353 + Steven M. Ayer
10354 +
10355 + Copyright (C) 2002 Compaq Computer Corporation
10356 +
10357 + This program is free software; you can redistribute it and/or
10358 + modify it under the terms of the GNU General Public License as
10359 + published by the Free Software Foundation; either version 2, or (at
10360 + your option) any later version.
10361 +
10362 + This program is distributed in the hope that it will be useful, but
10363 + WITHOUT ANY WARRANTY; without even the implied warranty of
10364 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10365 + General Public License for more details.
10366 +*/
10367 +
10368 +#ifndef PKG_DEPENDS_H
10369 +#define PKG_DEPENDS_H
10370 +
10371 +#include "pkg.h"
10372 +#include "pkg_hash.h"
10373 +
10374 +enum depend_type {
10375 + PREDEPEND,
10376 + DEPEND,
10377 + CONFLICTS,
10378 + GREEDY_DEPEND,
10379 + RECOMMEND,
10380 + SUGGEST
10381 +};
10382 +typedef enum depend_type depend_type_t;
10383 +
10384 +enum version_constraint {
10385 + NONE,
10386 + EARLIER,
10387 + EARLIER_EQUAL,
10388 + EQUAL,
10389 + LATER_EQUAL,
10390 + LATER
10391 +};
10392 +typedef enum version_constraint version_constraint_t;
10393 +
10394 +struct depend{
10395 + version_constraint_t constraint;
10396 + char * version;
10397 + abstract_pkg_t * pkg;
10398 +};
10399 +typedef struct depend depend_t;
10400 +
10401 +struct compound_depend{
10402 + depend_type_t type;
10403 + int possibility_count;
10404 + struct depend ** possibilities;
10405 +};
10406 +typedef struct compound_depend compound_depend_t;
10407 +
10408 +#include "hash_table.h"
10409 +
10410 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10411 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10412 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10413 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10414 +
10415 +/**
10416 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10417 + * the same abstract package and 0 otherwise.
10418 + */
10419 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10420 +
10421 +/**
10422 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10423 + * otherwise.
10424 + */
10425 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10426 +
10427 +/**
10428 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10429 + * otherwise.
10430 + */
10431 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10432 +
10433 +/**
10434 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10435 + * otherwise.
10436 + */
10437 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10438 +
10439 +/**
10440 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10441 + * otherwise.
10442 + */
10443 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10444 +
10445 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10446 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10447 +void freeDepends(pkg_t *pkg);
10448 +void printDepends(pkg_t * pkg);
10449 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10450 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10451 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10452 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10453 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10454 +
10455 +#endif
10456 Index: busybox-1.7.2/archival/libipkg/pkg_dest.c
10457 ===================================================================
10458 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10459 +++ busybox-1.7.2/archival/libipkg/pkg_dest.c 2007-10-30 15:35:05.000000000 -0500
10460 @@ -0,0 +1,92 @@
10461 +/* pkg_dest.c - the itsy package management system
10462 +
10463 + Carl D. Worth
10464 +
10465 + Copyright (C) 2001 University of Southern California
10466 +
10467 + This program is free software; you can redistribute it and/or
10468 + modify it under the terms of the GNU General Public License as
10469 + published by the Free Software Foundation; either version 2, or (at
10470 + your option) any later version.
10471 +
10472 + This program is distributed in the hope that it will be useful, but
10473 + WITHOUT ANY WARRANTY; without even the implied warranty of
10474 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10475 + General Public License for more details.
10476 +*/
10477 +
10478 +#include "ipkg.h"
10479 +
10480 +#include "pkg_dest.h"
10481 +#include "file_util.h"
10482 +#include "str_util.h"
10483 +#include "sprintf_alloc.h"
10484 +
10485 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10486 +{
10487 + dest->name = strdup(name);
10488 +
10489 + /* Guarantee that dest->root_dir ends with a '/' */
10490 + if (str_ends_with(root_dir, "/")) {
10491 + dest->root_dir = strdup(root_dir);
10492 + } else {
10493 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10494 + }
10495 + file_mkdir_hier(dest->root_dir, 0755);
10496 +
10497 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10498 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10499 + file_mkdir_hier(dest->ipkg_dir, 0755);
10500 +
10501 + if (str_starts_with (lists_dir, "/"))
10502 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10503 + else
10504 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10505 +
10506 + file_mkdir_hier(dest->lists_dir, 0755);
10507 +
10508 + sprintf_alloc(&dest->info_dir, "%s/%s",
10509 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10510 + file_mkdir_hier(dest->info_dir, 0755);
10511 +
10512 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10513 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10514 +
10515 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10516 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10517 +
10518 + dest->status_file = NULL;
10519 +
10520 + return 0;
10521 +}
10522 +
10523 +void pkg_dest_deinit(pkg_dest_t *dest)
10524 +{
10525 + free(dest->name);
10526 + dest->name = NULL;
10527 +
10528 + free(dest->root_dir);
10529 + dest->root_dir = NULL;
10530 +
10531 + free(dest->ipkg_dir);
10532 + dest->ipkg_dir = NULL;
10533 +
10534 + free(dest->lists_dir);
10535 + dest->lists_dir = NULL;
10536 +
10537 + free(dest->info_dir);
10538 + dest->info_dir = NULL;
10539 +
10540 + free(dest->status_file_name);
10541 + dest->status_file_name = NULL;
10542 +
10543 + free(dest->status_file_tmp_name);
10544 + dest->status_file_tmp_name = NULL;
10545 +
10546 + if (dest->status_file) {
10547 + fclose(dest->status_file);
10548 + }
10549 + dest->status_file = NULL;
10550 +
10551 + dest->root_dir = NULL;
10552 +}
10553 Index: busybox-1.7.2/archival/libipkg/pkg_dest.h
10554 ===================================================================
10555 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10556 +++ busybox-1.7.2/archival/libipkg/pkg_dest.h 2007-10-30 15:35:05.000000000 -0500
10557 @@ -0,0 +1,38 @@
10558 +/* pkg_dest.h - the itsy package management system
10559 +
10560 + Carl D. Worth
10561 +
10562 + Copyright (C) 2001 University of Southern California
10563 +
10564 + This program is free software; you can redistribute it and/or
10565 + modify it under the terms of the GNU General Public License as
10566 + published by the Free Software Foundation; either version 2, or (at
10567 + your option) any later version.
10568 +
10569 + This program is distributed in the hope that it will be useful, but
10570 + WITHOUT ANY WARRANTY; without even the implied warranty of
10571 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10572 + General Public License for more details.
10573 +*/
10574 +
10575 +#ifndef PKG_DEST_H
10576 +#define PKG_DEST_H
10577 +
10578 +typedef struct pkg_dest pkg_dest_t;
10579 +struct pkg_dest
10580 +{
10581 + char *name;
10582 + char *root_dir;
10583 + char *ipkg_dir;
10584 + char *lists_dir;
10585 + char *info_dir;
10586 + char *status_file_name;
10587 + char *status_file_tmp_name;
10588 + FILE *status_file;
10589 +};
10590 +
10591 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10592 +void pkg_dest_deinit(pkg_dest_t *dest);
10593 +
10594 +#endif
10595 +
10596 Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.c
10597 ===================================================================
10598 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10599 +++ busybox-1.7.2/archival/libipkg/pkg_dest_list.c 2007-10-30 15:35:05.000000000 -0500
10600 @@ -0,0 +1,85 @@
10601 +/* pkg_dest_list.c - the itsy package management system
10602 +
10603 + Carl D. Worth
10604 +
10605 + Copyright (C) 2001 University of Southern California
10606 +
10607 + This program is free software; you can redistribute it and/or
10608 + modify it under the terms of the GNU General Public License as
10609 + published by the Free Software Foundation; either version 2, or (at
10610 + your option) any later version.
10611 +
10612 + This program is distributed in the hope that it will be useful, but
10613 + WITHOUT ANY WARRANTY; without even the implied warranty of
10614 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10615 + General Public License for more details.
10616 +*/
10617 +
10618 +#include "ipkg.h"
10619 +
10620 +#include "pkg_dest.h"
10621 +#include "void_list.h"
10622 +#include "pkg_dest_list.h"
10623 +
10624 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10625 +{
10626 + return void_list_elt_init((void_list_elt_t *) elt, data);
10627 +}
10628 +
10629 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10630 +{
10631 + void_list_elt_deinit((void_list_elt_t *) elt);
10632 +}
10633 +
10634 +int pkg_dest_list_init(pkg_dest_list_t *list)
10635 +{
10636 + return void_list_init((void_list_t *) list);
10637 +}
10638 +
10639 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10640 +{
10641 + pkg_dest_list_elt_t *iter;
10642 + pkg_dest_t *pkg_dest;
10643 +
10644 + for (iter = list->head; iter; iter = iter->next) {
10645 + pkg_dest = iter->data;
10646 + pkg_dest_deinit(pkg_dest);
10647 +
10648 + /* malloced in pkg_dest_list_append */
10649 + free(pkg_dest);
10650 + iter->data = NULL;
10651 + }
10652 + void_list_deinit((void_list_t *) list);
10653 +}
10654 +
10655 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10656 + const char *root_dir,const char *lists_dir)
10657 +{
10658 + int err;
10659 + pkg_dest_t *pkg_dest;
10660 +
10661 + /* freed in plg_dest_list_deinit */
10662 + pkg_dest = malloc(sizeof(pkg_dest_t));
10663 + if (pkg_dest == NULL) {
10664 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10665 + return NULL;
10666 + }
10667 +
10668 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10669 + err = void_list_append((void_list_t *) list, pkg_dest);
10670 + if (err) {
10671 + return NULL;
10672 + }
10673 +
10674 + return pkg_dest;
10675 +}
10676 +
10677 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10678 +{
10679 + return void_list_push((void_list_t *) list, data);
10680 +}
10681 +
10682 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10683 +{
10684 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10685 +}
10686 Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.h
10687 ===================================================================
10688 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10689 +++ busybox-1.7.2/archival/libipkg/pkg_dest_list.h 2007-10-30 15:35:05.000000000 -0500
10690 @@ -0,0 +1,50 @@
10691 +/* pkg_dest_list.h - the itsy package management system
10692 +
10693 + Carl D. Worth
10694 +
10695 + Copyright (C) 2001 University of Southern California
10696 +
10697 + This program is free software; you can redistribute it and/or
10698 + modify it under the terms of the GNU General Public License as
10699 + published by the Free Software Foundation; either version 2, or (at
10700 + your option) any later version.
10701 +
10702 + This program is distributed in the hope that it will be useful, but
10703 + WITHOUT ANY WARRANTY; without even the implied warranty of
10704 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10705 + General Public License for more details.
10706 +*/
10707 +
10708 +#ifndef PKG_DEST_LIST_H
10709 +#define PKG_DEST_LIST_H
10710 +
10711 +#include "pkg_dest.h"
10712 +
10713 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10714 +struct pkg_dest_list_elt
10715 +{
10716 + pkg_dest_list_elt_t *next;
10717 + pkg_dest_t *data;
10718 +};
10719 +
10720 +typedef struct pkg_dest_list pkg_dest_list_t;
10721 +struct pkg_dest_list
10722 +{
10723 + pkg_dest_list_elt_t pre_head;
10724 + pkg_dest_list_elt_t *head;
10725 + pkg_dest_list_elt_t *tail;
10726 +};
10727 +
10728 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10729 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10730 +
10731 +int pkg_dest_list_init(pkg_dest_list_t *list);
10732 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10733 +
10734 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10735 + const char *root_dir,const char* lists_dir);
10736 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10737 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10738 +
10739 +#endif
10740 +
10741 Index: busybox-1.7.2/archival/libipkg/pkg_extract.c
10742 ===================================================================
10743 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10744 +++ busybox-1.7.2/archival/libipkg/pkg_extract.c 2007-10-30 15:35:05.000000000 -0500
10745 @@ -0,0 +1,224 @@
10746 +/* pkg_extract.c - the itsy package management system
10747 +
10748 + Carl D. Worth
10749 +
10750 + Copyright (C) 2001 University of Southern California
10751 +
10752 + This program is free software; you can redistribute it and/or
10753 + modify it under the terms of the GNU General Public License as
10754 + published by the Free Software Foundation; either version 2, or (at
10755 + your option) any later version.
10756 +
10757 + This program is distributed in the hope that it will be useful, but
10758 + WITHOUT ANY WARRANTY; without even the implied warranty of
10759 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10760 + General Public License for more details.
10761 +*/
10762 +
10763 +#include "ipkg.h"
10764 +#include <errno.h>
10765 +#include <fcntl.h>
10766 +#include <stdio.h>
10767 +
10768 +#include "pkg_extract.h"
10769 +
10770 +#include "libbb.h"
10771 +#include "file_util.h"
10772 +#include "sprintf_alloc.h"
10773 +#include "unarchive.h"
10774 +
10775 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10776 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10777 +#define IPKG_CONTROL_FILE "control"
10778 +
10779 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10780 +{
10781 + archive_handle_t *archive;
10782 + char *path;
10783 +
10784 + sprintf_alloc(&path, "%s/", dir);
10785 + archive = init_handle();
10786 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10787 + archive->filter = filter_accept_list;
10788 + llist_add_to(&(archive->accept), (char *)filename);
10789 + archive->buffer = path;
10790 + archive->action_data = data_extract_all_prefix;
10791 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10792 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10793 + close(archive->src_fd);
10794 + free(archive->accept);
10795 + free(archive);
10796 + free(path);
10797 +}
10798 +
10799 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10800 +{
10801 + unsigned int size = strlen(archive->file_header->name) + 2;
10802 +
10803 + if (archive->buffer == NULL) {
10804 + archive->buffer = xmalloc(size);
10805 + strcpy(archive->buffer, archive->file_header->name);
10806 + } else {
10807 + size += strlen(archive->buffer);
10808 + archive->buffer = xrealloc(archive->buffer, size);
10809 + strcat(archive->buffer, archive->file_header->name);
10810 + }
10811 + strcat(archive->buffer, "\n");
10812 + data_skip(archive);
10813 +}
10814 +
10815 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10816 +{
10817 + archive_handle_t *archive;
10818 + char *name;
10819 +
10820 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10821 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10822 + archive = init_handle();
10823 + archive->src_fd = xopen(name, O_RDONLY);
10824 + archive->filter = filter_accept_list;
10825 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10826 + archive->action_data = data_extract_to_buffer;
10827 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10828 + close(archive->src_fd);
10829 + fputs(archive->buffer, stream);
10830 + free(archive->buffer);
10831 + free(archive->accept);
10832 + free(archive);
10833 + free(name);
10834 +
10835 + return 0;
10836 +}
10837 +
10838 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10839 +{
10840 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10841 +}
10842 +
10843 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10844 +{
10845 + archive_handle_t *archive;
10846 + char *name;
10847 + char *path;
10848 +
10849 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10850 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10851 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10852 + archive = init_handle();
10853 + archive->src_fd = xopen(name, O_RDONLY);
10854 + archive->filter = filter_accept_all;
10855 + archive->buffer = path;
10856 + archive->action_data = data_extract_all_prefix;
10857 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10858 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10859 + close(archive->src_fd);
10860 + free(archive);
10861 + free(path);
10862 + free(name);
10863 +
10864 + return 0;
10865 +}
10866 +
10867 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10868 +{
10869 + archive_handle_t *archive;
10870 + char *name;
10871 + char *path;
10872 +
10873 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10874 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10875 + sprintf_alloc(&path, "%s/", dir);
10876 + archive = init_handle();
10877 + archive->src_fd = xopen(name, O_RDONLY);
10878 + archive->filter = filter_accept_all;
10879 + archive->buffer = path;
10880 + archive->action_data = data_extract_all_prefix;
10881 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10882 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10883 + close(archive->src_fd);
10884 + free(archive);
10885 + free(path);
10886 + free(name);
10887 +
10888 + return 0;
10889 +}
10890 +
10891 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10892 +{
10893 + int err=0;
10894 + char *line, *data_file;
10895 + FILE *file;
10896 + FILE *tmp;
10897 +
10898 + file = fopen(file_name, "w");
10899 + if (file == NULL) {
10900 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10901 + __FUNCTION__, file_name);
10902 + return EINVAL;
10903 + }
10904 +
10905 + tmp = tmpfile();
10906 + if (pkg->installed_files) {
10907 + str_list_elt_t *elt;
10908 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10909 + fprintf(file, "%s\n", elt->data);
10910 + }
10911 + } else {
10912 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10913 + if (err) {
10914 + fclose(file);
10915 + fclose(tmp);
10916 + return err;
10917 + }
10918 +
10919 + /* Fixup data file names by removing the initial '.' */
10920 + rewind(tmp);
10921 + while (1) {
10922 + line = file_read_line_alloc(tmp);
10923 + if (line == NULL) {
10924 + break;
10925 + }
10926 +
10927 + data_file = line;
10928 + if (*data_file == '.') {
10929 + data_file++;
10930 + }
10931 +
10932 + if (*data_file != '/') {
10933 + fputs("/", file);
10934 + }
10935 +
10936 + /* I have no idea why, but this is what dpkg does */
10937 + if (strcmp(data_file, "/\n") == 0) {
10938 + fputs("/.\n", file);
10939 + } else {
10940 + fputs(data_file, file);
10941 + }
10942 + }
10943 + }
10944 + fclose(tmp);
10945 + fclose(file);
10946 +
10947 + return err;
10948 +}
10949 +
10950 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10951 +{
10952 + archive_handle_t *archive;
10953 + char *name;
10954 +
10955 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10956 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10957 + archive = init_handle();
10958 + archive->src_fd = xopen(name, O_RDONLY);
10959 + archive->filter = filter_accept_all;
10960 + archive->action_data = data_extract_file_name_to_buffer;
10961 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10962 + close(archive->src_fd);
10963 + fputs(archive->buffer, file);
10964 + free(archive->buffer);
10965 + free(archive);
10966 + free(name);
10967 +
10968 + return 0;
10969 +}
10970 Index: busybox-1.7.2/archival/libipkg/pkg_extract.h
10971 ===================================================================
10972 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10973 +++ busybox-1.7.2/archival/libipkg/pkg_extract.h 2007-10-30 15:35:05.000000000 -0500
10974 @@ -0,0 +1,32 @@
10975 +/* pkg_extract.c - the itsy package management system
10976 +
10977 + Carl D. Worth
10978 +
10979 + Copyright (C) 2001 University of Southern California
10980 +
10981 + This program is free software; you can redistribute it and/or
10982 + modify it under the terms of the GNU General Public License as
10983 + published by the Free Software Foundation; either version 2, or (at
10984 + your option) any later version.
10985 +
10986 + This program is distributed in the hope that it will be useful, but
10987 + WITHOUT ANY WARRANTY; without even the implied warranty of
10988 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10989 + General Public License for more details.
10990 +*/
10991 +
10992 +#ifndef PKG_EXTRACT_H
10993 +#define PKG_EXTRACT_H
10994 +
10995 +#include "pkg.h"
10996 +
10997 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10998 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10999 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11000 + const char *dir,
11001 + const char *prefix);
11002 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11003 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11004 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11005 +
11006 +#endif
11007 Index: busybox-1.7.2/archival/libipkg/pkg.h
11008 ===================================================================
11009 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11010 +++ busybox-1.7.2/archival/libipkg/pkg.h 2007-10-30 15:35:05.000000000 -0500
11011 @@ -0,0 +1,229 @@
11012 +/* pkg.h - the itsy package management system
11013 +
11014 + Carl D. Worth
11015 +
11016 + Copyright (C) 2001 University of Southern California
11017 +
11018 + This program is free software; you can redistribute it and/or
11019 + modify it under the terms of the GNU General Public License as
11020 + published by the Free Software Foundation; either version 2, or (at
11021 + your option) any later version.
11022 +
11023 + This program is distributed in the hope that it will be useful, but
11024 + WITHOUT ANY WARRANTY; without even the implied warranty of
11025 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11026 + General Public License for more details.
11027 +*/
11028 +
11029 +#ifndef PKG_H
11030 +#define PKG_H
11031 +
11032 +#include <sys/types.h>
11033 +#include <sys/stat.h>
11034 +#include <unistd.h>
11035 +
11036 +#include "pkg_vec.h"
11037 +#include "str_list.h"
11038 +#include "pkg_src.h"
11039 +#include "pkg_dest.h"
11040 +#include "ipkg_conf.h"
11041 +#include "conffile_list.h"
11042 +
11043 +struct ipkg_conf;
11044 +
11045 +/* I think "Size" is currently the shortest field name */
11046 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11047 +
11048 +enum pkg_state_want
11049 +{
11050 + SW_UNKNOWN = 1,
11051 + SW_INSTALL,
11052 + SW_DEINSTALL,
11053 + SW_PURGE,
11054 + SW_LAST_STATE_WANT
11055 +};
11056 +typedef enum pkg_state_want pkg_state_want_t;
11057 +
11058 +enum pkg_state_flag
11059 +{
11060 + SF_OK = 0,
11061 + SF_REINSTREQ = 1,
11062 + SF_HOLD = 2, /* do not upgrade version */
11063 + SF_REPLACE = 4, /* replace this package */
11064 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11065 + SF_PREFER = 16, /* prefer this version */
11066 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11067 + SF_MARKED = 64, /* temporary mark */
11068 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11069 + SF_USER = 256,
11070 + SF_LAST_STATE_FLAG
11071 +};
11072 +typedef enum pkg_state_flag pkg_state_flag_t;
11073 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11074 +
11075 +enum pkg_state_status
11076 +{
11077 + SS_NOT_INSTALLED = 1,
11078 + SS_UNPACKED,
11079 + SS_HALF_CONFIGURED,
11080 + SS_INSTALLED,
11081 + SS_HALF_INSTALLED,
11082 + SS_CONFIG_FILES,
11083 + SS_POST_INST_FAILED,
11084 + SS_REMOVAL_FAILED,
11085 + SS_LAST_STATE_STATUS
11086 +};
11087 +typedef enum pkg_state_status pkg_state_status_t;
11088 +
11089 +struct abstract_pkg{
11090 + char * name;
11091 + int dependencies_checked;
11092 + pkg_vec_t * pkgs;
11093 + pkg_state_status_t state_status;
11094 + pkg_state_flag_t state_flag;
11095 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11096 + abstract_pkg_vec_t * provided_by;
11097 + abstract_pkg_vec_t * replaced_by;
11098 +};
11099 +
11100 +#include "pkg_depends.h"
11101 +
11102 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11103 +
11104 + The 3 version fields should go into a single version struct. (This
11105 + is especially important since, currently, pkg->version can easily
11106 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11107 + distinct. This has been the source of multiple bugs.
11108 +
11109 + The 3 state fields could possibly also go into their own struct.
11110 +
11111 + All fields which deal with lists of packages, (Depends,
11112 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11113 + be handled by a single struct in pkg_t
11114 +
11115 + All string fields for which there is a small set of possible
11116 + values, (section, maintainer, architecture, maybe version?), that
11117 + are reused among different packages -- for all such packages we
11118 + should move from "char *"s to some atom datatype to share data
11119 + storage and use less memory. We might even do reference counting,
11120 + but probably not since most often we only create new pkg_t structs,
11121 + we don't often free them. */
11122 +struct pkg
11123 +{
11124 + char *name;
11125 + unsigned long epoch;
11126 + char *version;
11127 + char *revision;
11128 + char *familiar_revision;
11129 + pkg_src_t *src;
11130 + pkg_dest_t *dest;
11131 + char *architecture;
11132 + char *section;
11133 + char *maintainer;
11134 + char *description;
11135 + pkg_state_want_t state_want;
11136 + pkg_state_flag_t state_flag;
11137 + pkg_state_status_t state_status;
11138 + char **depends_str;
11139 + int depends_count;
11140 + char **pre_depends_str;
11141 + int pre_depends_count;
11142 + char **recommends_str;
11143 + int recommends_count;
11144 + char **suggests_str;
11145 + int suggests_count;
11146 + compound_depend_t * depends;
11147 +
11148 + /* Abhaya: new conflicts */
11149 + char **conflicts_str;
11150 + compound_depend_t * conflicts;
11151 + int conflicts_count;
11152 +
11153 + char **replaces_str;
11154 + int replaces_count;
11155 + abstract_pkg_t ** replaces;
11156 +
11157 + char **provides_str;
11158 + int provides_count;
11159 + abstract_pkg_t ** provides;
11160 +
11161 + abstract_pkg_t *parent;
11162 +
11163 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11164 +
11165 + char *filename;
11166 + char *local_filename;
11167 + char *url;
11168 + char *tmp_unpack_dir;
11169 + char *md5sum;
11170 + char *size;
11171 + char *installed_size;
11172 + char *priority;
11173 + char *source;
11174 + conffile_list_t conffiles;
11175 + time_t installed_time;
11176 + /* As pointer for lazy evaluation */
11177 + str_list_t *installed_files;
11178 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11179 + mechanism to avoid the problem here, (which is that the
11180 + installed_files list was being freed from an inner loop while
11181 + still being used within an outer loop. */
11182 + int installed_files_ref_cnt;
11183 + int essential;
11184 + int arch_priority;
11185 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11186 + int provided_by_hand;
11187 +};
11188 +
11189 +pkg_t *pkg_new(void);
11190 +int pkg_init(pkg_t *pkg);
11191 +void pkg_deinit(pkg_t *pkg);
11192 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11193 +abstract_pkg_t *abstract_pkg_new(void);
11194 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11195 +
11196 +/*
11197 + * merges fields from newpkg into oldpkg.
11198 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11199 + */
11200 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11201 +
11202 +char *pkg_version_str_alloc(pkg_t *pkg);
11203 +
11204 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11205 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11206 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11207 +
11208 +char * pkg_formatted_info(pkg_t *pkg );
11209 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11210 +
11211 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11212 +
11213 +void pkg_print_info(pkg_t *pkg, FILE *file);
11214 +void pkg_print_status(pkg_t * pkg, FILE * file);
11215 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11216 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11217 +int pkg_free_installed_files(pkg_t *pkg);
11218 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11219 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11220 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11221 + const char *script, const char *args);
11222 +
11223 +/* enum mappings */
11224 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11225 +pkg_state_want_t pkg_state_want_from_str(char *str);
11226 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11227 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11228 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11229 +pkg_state_status_t pkg_state_status_from_str(char *str);
11230 +
11231 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11232 +
11233 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11234 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11235 +int pkg_free_installed_files(pkg_t *pkg);
11236 +
11237 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11238 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11239 +
11240 +#endif
11241 Index: busybox-1.7.2/archival/libipkg/pkg_hash.c
11242 ===================================================================
11243 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11244 +++ busybox-1.7.2/archival/libipkg/pkg_hash.c 2007-10-30 15:35:05.000000000 -0500
11245 @@ -0,0 +1,616 @@
11246 +/* ipkg_hash.c - the itsy package management system
11247 +
11248 + Steven M. Ayer
11249 +
11250 + Copyright (C) 2002 Compaq Computer Corporation
11251 +
11252 + This program is free software; you can redistribute it and/or
11253 + modify it under the terms of the GNU General Public License as
11254 + published by the Free Software Foundation; either version 2, or (at
11255 + your option) any later version.
11256 +
11257 + This program is distributed in the hope that it will be useful, but
11258 + WITHOUT ANY WARRANTY; without even the implied warranty of
11259 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11260 + General Public License for more details.
11261 +*/
11262 +
11263 +#include "ipkg.h"
11264 +#include <errno.h>
11265 +#include <ctype.h>
11266 +#include <stdlib.h>
11267 +#include <string.h>
11268 +
11269 +#include "hash_table.h"
11270 +#include "pkg.h"
11271 +#include "ipkg_message.h"
11272 +#include "pkg_vec.h"
11273 +#include "pkg_hash.h"
11274 +#include "pkg_parse.h"
11275 +#include "ipkg_utils.h"
11276 +
11277 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11278 +
11279 +/*
11280 + * this will talk to both feeds-lists files and installed status files
11281 + * example api:
11282 + *
11283 + * hash_table_t hash;
11284 + * pkg_hash_init(name, &hash, 1000);
11285 + * pkg_hash_add_from_file(<feed filename>);
11286 + *
11287 + * the query function is just there as a shell to prove to me that this
11288 + * sort of works, but isn't far from doing something useful
11289 + *
11290 + * -sma, 12/21/01
11291 + * modified: CDW 3 Jan. 2002
11292 + */
11293 +
11294 +
11295 +\f
11296 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11297 +{
11298 + return hash_table_init(name, hash, len);
11299 +}
11300 +
11301 +void pkg_hash_deinit(hash_table_t *hash)
11302 +{
11303 + hash_table_deinit(hash);
11304 +}
11305 +
11306 +
11307 +/* Find the default arch for a given package status file if none is given. */
11308 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11309 +{
11310 + nv_pair_list_elt_t *l;
11311 + char *def_arch = HOST_CPU_STR; /* Default arch */
11312 + int def_prio = 0; /* Other archs override this */
11313 +
11314 + l = conf->arch_list.head;
11315 +
11316 + while (l) {
11317 + nv_pair_t *nv = l->data;
11318 + int priority = strtol(nv->value, NULL, 0);
11319 +
11320 + /* Check if this arch has higher priority, and is valid */
11321 + if ((priority > def_prio) &&
11322 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11323 + /* Our new default */
11324 + def_prio = priority;
11325 + def_arch = nv->name;
11326 + }
11327 + l = l->next;
11328 + }
11329 +
11330 + return strdup(def_arch);
11331 +}
11332 +
11333 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11334 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11335 +{
11336 + hash_table_t *hash = &conf->pkg_hash;
11337 + char **raw;
11338 + char **raw_start;
11339 + pkg_t *pkg;
11340 +
11341 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11342 + if (!raw)
11343 + return -ENOMEM;
11344 +
11345 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11346 + pkg = pkg_new();
11347 + if (!pkg)
11348 + return -ENOMEM;
11349 +
11350 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11351 + if (!pkg->architecture) {
11352 + char *version_str = pkg_version_str_alloc(pkg);
11353 + pkg->architecture = pkg_get_default_arch(conf);
11354 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11355 + pkg->name, version_str, pkg->architecture);
11356 + free(version_str);
11357 + }
11358 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11359 + } else {
11360 + free(pkg);
11361 + }
11362 + }
11363 +
11364 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11365 + memory after read_raw_pkgs_from_file */
11366 + raw = raw_start;
11367 + while (*raw) {
11368 + free(*raw++);
11369 + }
11370 + free(raw_start);
11371 + return 0;
11372 +}
11373 +
11374 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11375 +{
11376 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11377 +}
11378 +
11379 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11380 +{
11381 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11382 + if (apkg)
11383 + return NULL;
11384 + return apkg->provided_by;
11385 +}
11386 +
11387 +
11388 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11389 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11390 +{
11391 + int i, j;
11392 + int nprovides = 0;
11393 + int nmatching = 0;
11394 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11395 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11396 + abstract_pkg_vec_t *provided_apkg_vec;
11397 + abstract_pkg_t **provided_apkgs;
11398 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11399 + pkg_t *latest_installed_parent = NULL;
11400 + pkg_t *latest_matching = NULL;
11401 + pkg_t *held_pkg = NULL;
11402 + pkg_t *good_pkg_by_name = NULL;
11403 +
11404 + if (matching_apkgs == NULL || providers == NULL ||
11405 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11406 + return NULL;
11407 +
11408 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11409 +
11410 + provided_apkg_vec = apkg->provided_by;
11411 + nprovides = provided_apkg_vec->len;
11412 + provided_apkgs = provided_apkg_vec->pkgs;
11413 + if (nprovides > 1)
11414 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11415 +
11416 + /* accumulate all the providers */
11417 + for (i = 0; i < nprovides; i++) {
11418 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11419 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11420 + abstract_pkg_vec_insert(providers, provider_apkg);
11421 + }
11422 + nprovides = providers->len;
11423 +
11424 + for (i = 0; i < nprovides; i++) {
11425 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11426 + abstract_pkg_t *replacement_apkg = NULL;
11427 + pkg_vec_t *vec;
11428 +
11429 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11430 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11431 + if (provider_apkg->replaced_by->len > 1) {
11432 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11433 + provider_apkg->name, replacement_apkg->name);
11434 + }
11435 + }
11436 +
11437 + if (replacement_apkg)
11438 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11439 + replacement_apkg->name, provider_apkg->name);
11440 +
11441 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11442 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11443 + continue;
11444 + else
11445 + provider_apkg = replacement_apkg;
11446 + }
11447 +
11448 + if (!(vec = provider_apkg->pkgs)) {
11449 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11450 + continue;
11451 + }
11452 +
11453 +
11454 + /* now check for supported architecture */
11455 + {
11456 + int max_count = 0;
11457 +
11458 + /* count packages matching max arch priority and keep track of last one */
11459 + for (j = 0; j < vec->len; j++) {
11460 + pkg_t *maybe = vec->pkgs[j];
11461 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11462 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11463 + if (maybe->arch_priority > 0) {
11464 + max_count++;
11465 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11466 + pkg_vec_insert(matching_pkgs, maybe);
11467 + }
11468 + }
11469 + }
11470 + }
11471 +
11472 + if (matching_pkgs->len > 1)
11473 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11474 + if (matching_apkgs->len > 1)
11475 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11476 +
11477 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11478 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11479 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11480 + Until now I always got the latest, but that breaks the downgrade option.
11481 + If I stop at the first one, I would probably miss the new ones
11482 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11483 + or from a Packages feed.
11484 + 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*/
11485 +/*Pigi*/
11486 +
11487 + for (i = 0; i < matching_pkgs->len; i++) {
11488 + pkg_t *matching = matching_pkgs->pkgs[i];
11489 + if (constraint_fcn(matching, cdata)) { /* We found it */
11490 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11491 + good_pkg_by_name = matching;
11492 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11493 + break;
11494 + }
11495 + }
11496 +
11497 +
11498 + for (i = 0; i < matching_pkgs->len; i++) {
11499 + pkg_t *matching = matching_pkgs->pkgs[i];
11500 + latest_matching = matching;
11501 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11502 + latest_installed_parent = matching;
11503 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11504 + if (held_pkg)
11505 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11506 + held_pkg->name, matching->name);
11507 + held_pkg = matching;
11508 + }
11509 + }
11510 +
11511 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11512 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11513 + apkg->name, matching_apkgs->len);
11514 + for (i = 0; i < matching_apkgs->len; i++) {
11515 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11516 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11517 + }
11518 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11519 + }
11520 +
11521 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11522 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11523 + __FUNCTION__, apkg->name, matching_pkgs->len);
11524 + for (i = 0; i < matching_pkgs->len; i++) {
11525 + pkg_t *matching = matching_pkgs->pkgs[i];
11526 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11527 + matching->name, matching->version, matching->architecture);
11528 + }
11529 + }
11530 +
11531 + nmatching = matching_apkgs->len;
11532 +
11533 + pkg_vec_free(matching_pkgs);
11534 + abstract_pkg_vec_free(matching_apkgs);
11535 + abstract_pkg_vec_free(providers);
11536 +
11537 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11538 + return good_pkg_by_name;
11539 + }
11540 + if (held_pkg) {
11541 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11542 + return held_pkg;
11543 + }
11544 + if (latest_installed_parent) {
11545 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11546 + return latest_installed_parent;
11547 + }
11548 + if (nmatching > 1) {
11549 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11550 + return NULL;
11551 + }
11552 + if (latest_matching) {
11553 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11554 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11555 + return latest_matching;
11556 + }
11557 + return NULL;
11558 +}
11559 +
11560 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11561 +{
11562 + const char *name = (const char *)cdata;
11563 + if (strcmp(pkg->name, name) == 0)
11564 + return 1;
11565 + else
11566 + return 0;
11567 +}
11568 +
11569 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11570 +{
11571 + hash_table_t *hash = &conf->pkg_hash;
11572 + abstract_pkg_t *apkg = NULL;
11573 +
11574 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11575 + return NULL;
11576 +
11577 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11578 +}
11579 +
11580 +
11581 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11582 + const char *pkg_name,
11583 + const char * version)
11584 +{
11585 + pkg_vec_t * vec;
11586 + register int i;
11587 + char *version_str = NULL;
11588 +
11589 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11590 + return NULL;
11591 +
11592 + for(i = 0; i < vec->len; i++) {
11593 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11594 + if(!strcmp(version_str, version)) {
11595 + free(version_str);
11596 + break;
11597 + }
11598 + free(version_str);
11599 + }
11600 +
11601 + if(i == vec->len)
11602 + return NULL;
11603 +
11604 + return vec->pkgs[i];
11605 +}
11606 +
11607 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11608 + const char *pkg_name,
11609 + pkg_dest_t *dest)
11610 +{
11611 + pkg_vec_t * vec;
11612 + register int i;
11613 +
11614 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11615 + return NULL;
11616 + }
11617 +
11618 + for(i = 0; i < vec->len; i++)
11619 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11620 + return vec->pkgs[i];
11621 + }
11622 + return NULL;
11623 +}
11624 +
11625 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11626 + const char *pkg_name)
11627 +{
11628 + pkg_vec_t * vec;
11629 + register int i;
11630 +
11631 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11632 + return NULL;
11633 + }
11634 +
11635 + for(i = 0; i < vec->len; i++)
11636 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11637 + return vec->pkgs[i];
11638 + }
11639 +
11640 + return NULL;
11641 +}
11642 +
11643 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11644 +{
11645 + abstract_pkg_t * ab_pkg;
11646 +
11647 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11648 + return NULL;
11649 + }
11650 +
11651 + if (ab_pkg->pkgs) {
11652 + return ab_pkg->pkgs;
11653 + } else if (ab_pkg->provided_by) {
11654 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11655 + if (abpkg != NULL){
11656 + return abpkg->pkgs;
11657 + } else {
11658 + return ab_pkg->pkgs;
11659 + }
11660 + } else {
11661 + return NULL;
11662 + }
11663 +}
11664 +
11665 +static int pkg_compare_names(const void *p1, const void *p2)
11666 +{
11667 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11668 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11669 + if (pkg1->name == NULL)
11670 + return 1;
11671 + if (pkg2->name == NULL)
11672 + return -1;
11673 + return(strcmp(pkg1->name, pkg2->name));
11674 +}
11675 +
11676 +
11677 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11678 +{
11679 + int j;
11680 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11681 + pkg_vec_t *all = (pkg_vec_t *)data;
11682 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11683 + if (pkg_vec) {
11684 + for (j = 0; j < pkg_vec->len; j++) {
11685 + pkg_t *pkg = pkg_vec->pkgs[j];
11686 + pkg_vec_insert(all, pkg);
11687 + }
11688 + }
11689 +}
11690 +
11691 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11692 +{
11693 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11694 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11695 +}
11696 +
11697 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11698 +{
11699 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11700 + pkg_vec_t *all = (pkg_vec_t *)data;
11701 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11702 + int j;
11703 + if (pkg_vec) {
11704 + for (j = 0; j < pkg_vec->len; j++) {
11705 + pkg_t *pkg = pkg_vec->pkgs[j];
11706 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11707 + pkg_vec_insert(all, pkg);
11708 + }
11709 + }
11710 + }
11711 +}
11712 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11713 +{
11714 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11715 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11716 +}
11717 +
11718 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11719 +{
11720 + int i;
11721 + pkg_t *pkg;
11722 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11723 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11724 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11725 + fprintf(stdout, "%s\n", ab_pkg->name);
11726 + i = 0;
11727 + if (dependents != NULL)
11728 + while (dependents [i] != NULL)
11729 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11730 + dependents = ab_pkg->provided_by->pkgs;
11731 + i = 0;
11732 + if (dependents != NULL)
11733 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11734 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11735 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11736 + if (pkg) {
11737 + i = 0;
11738 + while (i < pkg->depends_count)
11739 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11740 + }
11741 +}
11742 +void pkg_hash_dump(hash_table_t *hash, void *data)
11743 +{
11744 +
11745 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11746 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11747 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11748 +}
11749 +
11750 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11751 +{
11752 + abstract_pkg_t * ab_pkg;
11753 +
11754 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11755 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11756 +
11757 + return ab_pkg;
11758 +}
11759 +
11760 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11761 +{
11762 + abstract_pkg_t * ab_pkg;
11763 + int arch_priority;
11764 +
11765 + if(!pkg)
11766 + return pkg;
11767 +
11768 + arch_priority = pkg->arch_priority;
11769 +
11770 + if (buildDepends(hash, pkg)<0){
11771 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11772 + return NULL;
11773 + }
11774 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11775 +
11776 + if (set_status) {
11777 + if (pkg->state_status == SS_INSTALLED) {
11778 + ab_pkg->state_status = SS_INSTALLED;
11779 + } else if (pkg->state_status == SS_UNPACKED) {
11780 + ab_pkg->state_status = SS_UNPACKED;
11781 + }
11782 + }
11783 +
11784 + if(!ab_pkg->pkgs)
11785 + ab_pkg->pkgs = pkg_vec_alloc();
11786 +
11787 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11788 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11789 + pkg->parent = ab_pkg;
11790 +
11791 + if (buildProvides(hash, ab_pkg, pkg)<0){
11792 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11793 + return NULL;
11794 + }
11795 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11796 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11797 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11798 + return NULL;
11799 + }
11800 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11801 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11802 + return NULL;
11803 + }
11804 +
11805 + buildDependedUponBy(pkg, ab_pkg);
11806 + return pkg;
11807 +}
11808 +
11809 +/*
11810 + * this will assume that we've already determined that
11811 + * the abstract pkg doesn't exist, 'cause we should know these things...
11812 + */
11813 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11814 +{
11815 + abstract_pkg_t * ab_pkg;
11816 +
11817 + ab_pkg = abstract_pkg_new();
11818 + if (ab_pkg == NULL) { return NULL; }
11819 +
11820 + ab_pkg->name = strdup(pkg_name);
11821 + hash_table_insert(hash, pkg_name, ab_pkg);
11822 +
11823 + return ab_pkg;
11824 +}
11825 +
11826 +
11827 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11828 +{
11829 + hash_table_t *file_hash = &conf->file_hash;
11830 +
11831 + return hash_table_get(file_hash, file_name);
11832 +}
11833 +
11834 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11835 +{
11836 + hash_table_t *file_hash = &conf->file_hash;
11837 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11838 + int file_name_len = strlen(file_name);
11839 +
11840 + if (file_name[file_name_len -1] == '/')
11841 + return 0;
11842 +
11843 + if (conf->offline_root) {
11844 + int len = strlen(conf->offline_root);
11845 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11846 + file_name += len;
11847 + }
11848 + }
11849 +
11850 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11851 + hash_table_insert(file_hash, file_name, owning_pkg);
11852 + if (old_owning_pkg) {
11853 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11854 + /* mark this package to have its filelist written */
11855 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11856 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11857 + }
11858 + return 0;
11859 +}
11860 +
11861 +
11862 Index: busybox-1.7.2/archival/libipkg/pkg_hash.h
11863 ===================================================================
11864 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11865 +++ busybox-1.7.2/archival/libipkg/pkg_hash.h 2007-10-30 15:35:05.000000000 -0500
11866 @@ -0,0 +1,61 @@
11867 +/* pkg_hash.h - the itsy package management system
11868 +
11869 + Steven M. Ayer
11870 +
11871 + Copyright (C) 2002 Compaq Computer Corporation
11872 +
11873 + This program is free software; you can redistribute it and/or
11874 + modify it under the terms of the GNU General Public License as
11875 + published by the Free Software Foundation; either version 2, or (at
11876 + your option) any later version.
11877 +
11878 + This program is distributed in the hope that it will be useful, but
11879 + WITHOUT ANY WARRANTY; without even the implied warranty of
11880 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11881 + General Public License for more details.
11882 +*/
11883 +
11884 +#ifndef PKG_HASH_H
11885 +#define PKG_HASH_H
11886 +
11887 +#include "pkg.h"
11888 +#include "pkg_vec.h"
11889 +#include "hash_table.h"
11890 +
11891 +
11892 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11893 +void pkg_hash_deinit(hash_table_t *hash);
11894 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11895 +
11896 +void pkg_hash_dump(hash_table_t *hash, void *data);
11897 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11898 +
11899 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11900 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11901 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11902 +
11903 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11904 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11905 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11906 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11907 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11908 + const char *pkg_name,
11909 + const char * version);
11910 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11911 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11912 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11913 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11914 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11915 + const char *pkg_name);
11916 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11917 + const char *pkg_name,
11918 + pkg_dest_t *dest);
11919 +
11920 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11921 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11922 +
11923 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11924 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11925 +
11926 +#endif
11927 +
11928 Index: busybox-1.7.2/archival/libipkg/pkg_parse.c
11929 ===================================================================
11930 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11931 +++ busybox-1.7.2/archival/libipkg/pkg_parse.c 2007-10-30 15:35:05.000000000 -0500
11932 @@ -0,0 +1,366 @@
11933 +/* pkg_parse.c - the itsy package management system
11934 +
11935 + Steven M. Ayer
11936 +
11937 + Copyright (C) 2002 Compaq Computer Corporation
11938 +
11939 + This program is free software; you can redistribute it and/or
11940 + modify it under the terms of the GNU General Public License as
11941 + published by the Free Software Foundation; either version 2, or (at
11942 + your option) any later version.
11943 +
11944 + This program is distributed in the hope that it will be useful, but
11945 + WITHOUT ANY WARRANTY; without even the implied warranty of
11946 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11947 + General Public License for more details.
11948 +*/
11949 +
11950 +#include "ipkg.h"
11951 +#include <errno.h>
11952 +#include <ctype.h>
11953 +
11954 +#include "pkg.h"
11955 +#include "ipkg_utils.h"
11956 +#include "pkg_parse.h"
11957 +
11958 +int isGenericFieldType(char * type, char * line)
11959 +{
11960 + if(!strncmp(line, type, strlen(type)))
11961 + return 1;
11962 + return 0;
11963 +}
11964 +
11965 +char * parseGenericFieldType(char * type, char * raw)
11966 +{
11967 + char * field_value = raw + (strlen(type) + 1);
11968 + return trim_alloc(field_value);
11969 +}
11970 +
11971 +void parseStatus(pkg_t *pkg, char * raw)
11972 +{
11973 + char sw_str[64], sf_str[64], ss_str[64];
11974 +
11975 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11976 + pkg->state_want = pkg_state_want_from_str(sw_str);
11977 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11978 + pkg->state_status = pkg_state_status_from_str(ss_str);
11979 +}
11980 +
11981 +char ** parseDependsString(char * raw, int * depends_count)
11982 +{
11983 + char ** depends = NULL;
11984 + int line_count = 0;
11985 + char buff[2048], * dest;
11986 +
11987 + while(raw && *raw && !isspace(*raw)) {
11988 + raw++;
11989 + }
11990 +
11991 + if(line_is_blank(raw)){
11992 + *depends_count = line_count;
11993 + return NULL;
11994 + }
11995 + while(raw && *raw){
11996 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11997 +
11998 + while(isspace(*raw)) raw++;
11999 +
12000 + dest = buff;
12001 + while((*raw != ',') && *raw)
12002 + *dest++ = *raw++;
12003 +
12004 + *dest = '\0';
12005 + depends[line_count] = trim_alloc(buff);
12006 + if(depends[line_count] ==NULL)
12007 + return NULL;
12008 + line_count++;
12009 + if(*raw == ',')
12010 + raw++;
12011 + }
12012 + *depends_count = line_count;
12013 + return depends;
12014 +}
12015 +
12016 +void parseConffiles(pkg_t * pkg, char * raw)
12017 +{
12018 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12019 +
12020 + if(!strncmp(raw, "Conffiles:", 10))
12021 + raw += strlen("Conffiles:");
12022 +
12023 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12024 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12025 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12026 + while (*raw && isspace(*raw)) {
12027 + raw++;
12028 + }
12029 + raw += strlen(file_name);
12030 + while (*raw && isspace(*raw)) {
12031 + raw++;
12032 + }
12033 + raw += strlen(md5sum);
12034 + }
12035 +}
12036 +
12037 +int parseVersion(pkg_t *pkg, char *raw)
12038 +{
12039 + char *colon, *eepochcolon;
12040 +#ifdef USE_DEBVERSION
12041 + char *hyphen;
12042 +#endif
12043 + unsigned long epoch;
12044 +
12045 + if (!*raw) {
12046 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12047 + return EINVAL;
12048 + }
12049 +
12050 + if (strncmp(raw, "Version:", 8) == 0) {
12051 + raw += 8;
12052 + }
12053 + while (*raw && isspace(*raw)) {
12054 + raw++;
12055 + }
12056 +
12057 + colon= strchr(raw,':');
12058 + if (colon) {
12059 + epoch= strtoul(raw,&eepochcolon,10);
12060 + if (colon != eepochcolon) {
12061 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12062 + return EINVAL;
12063 + }
12064 + if (!*++colon) {
12065 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12066 + return EINVAL;
12067 + }
12068 + raw= colon;
12069 + pkg->epoch= epoch;
12070 + } else {
12071 + pkg->epoch= 0;
12072 + }
12073 +
12074 + pkg->revision = "";
12075 + pkg->familiar_revision = "";
12076 +
12077 + pkg->version= malloc(strlen(raw)+1);
12078 + if ( pkg->version == NULL ) {
12079 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12080 + return ENOMEM;
12081 + }
12082 + strcpy(pkg->version, raw);
12083 +
12084 +#ifdef USE_DEBVERSION
12085 + hyphen= strrchr(pkg->version,'-');
12086 +
12087 + if (hyphen) {
12088 + *hyphen++= 0;
12089 + if (strncmp("fam", hyphen, 3) == 0) {
12090 + pkg->familiar_revision=hyphen+3;
12091 + hyphen= strrchr(pkg->version,'-');
12092 + if (hyphen) {
12093 + *hyphen++= 0;
12094 + pkg->revision = hyphen;
12095 + }
12096 + } else {
12097 + pkg->revision = hyphen;
12098 + }
12099 + }
12100 +#endif
12101 +
12102 +/*
12103 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12104 + pkg->epoch,
12105 + pkg->version,
12106 + pkg->revision,
12107 + pkg->familiar_revision);
12108 +*/
12109 +
12110 + return 0;
12111 +}
12112 +
12113 +
12114 +/* This code is needed to insert in first position the keyword for the aligning bug */
12115 +
12116 +int alterProvidesLine(char *raw, char *temp)
12117 +{
12118 +
12119 +
12120 + if (!*raw) {
12121 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12122 + return -EINVAL;
12123 + }
12124 +
12125 + if ( temp == NULL ) {
12126 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12127 + return -ENOMEM;
12128 + }
12129 +
12130 + if (strncmp(raw, "Provides:", 9) == 0) {
12131 + raw += 9;
12132 + }
12133 + while (*raw && isspace(*raw)) {
12134 + raw++;
12135 + }
12136 +
12137 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12138 + while (*raw) {
12139 + strncat( temp, raw++, 1);
12140 + }
12141 + return 0;
12142 +
12143 +}
12144 +
12145 +/* Some random thoughts from Carl:
12146 +
12147 + This function could be considerably simplified if we just kept
12148 + an array of all the generic string-valued field names, and looped
12149 + through those looking for a match. Also, these fields could perhaps
12150 + be stored in the package as an array as well, (or, probably better,
12151 + as an nv_pair_list_t).
12152 +
12153 + Fields which require special parsing or storage, (such as Depends:
12154 + and Status:) could be handled as they are now.
12155 +*/
12156 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12157 + to a dependency list. And, since we already have
12158 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12159 + Enhances, perhaps we could generalize all of these and save some
12160 + code duplication.
12161 +*/
12162 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12163 +{
12164 + int reading_conffiles, reading_description;
12165 + int pkg_false_provides=1;
12166 + char ** lines;
12167 + char * provide=NULL;
12168 +
12169 + pkg->src = src;
12170 + pkg->dest = dest;
12171 +
12172 + reading_conffiles = reading_description = 0;
12173 +
12174 + for (lines = *raw; *lines; lines++) {
12175 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12176 + if(isGenericFieldType("Package:", *lines))
12177 + pkg->name = parseGenericFieldType("Package", *lines);
12178 + else if(isGenericFieldType("Architecture:", *lines))
12179 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12180 + else if(isGenericFieldType("Filename:", *lines))
12181 + pkg->filename = parseGenericFieldType("Filename", *lines);
12182 + else if(isGenericFieldType("Section:", *lines))
12183 + pkg->section = parseGenericFieldType("Section", *lines);
12184 + else if(isGenericFieldType("MD5sum:", *lines))
12185 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12186 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12187 + let's parse it either way */
12188 + else if(isGenericFieldType("MD5Sum:", *lines))
12189 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12190 + else if(isGenericFieldType("Size:", *lines))
12191 + pkg->size = parseGenericFieldType("Size", *lines);
12192 + else if(isGenericFieldType("Source:", *lines))
12193 + pkg->source = parseGenericFieldType("Source", *lines);
12194 + else if(isGenericFieldType("Installed-Size:", *lines))
12195 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12196 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12197 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12198 + pkg->installed_time = strtoul(time_str, NULL, 0);
12199 + } else if(isGenericFieldType("Priority:", *lines))
12200 + pkg->priority = parseGenericFieldType("Priority", *lines);
12201 + else if(isGenericFieldType("Essential:", *lines)) {
12202 + char *essential_value;
12203 + essential_value = parseGenericFieldType("Essential", *lines);
12204 + if (strcmp(essential_value, "yes") == 0) {
12205 + pkg->essential = 1;
12206 + }
12207 + free(essential_value);
12208 + }
12209 + else if(isGenericFieldType("Status", *lines))
12210 + parseStatus(pkg, *lines);
12211 + else if(isGenericFieldType("Version", *lines))
12212 + parseVersion(pkg, *lines);
12213 + else if(isGenericFieldType("Maintainer", *lines))
12214 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12215 + else if(isGenericFieldType("Conffiles", *lines)){
12216 + parseConffiles(pkg, *lines);
12217 + reading_conffiles = 1;
12218 + }
12219 + else if(isGenericFieldType("Description", *lines)) {
12220 + pkg->description = parseGenericFieldType("Description", *lines);
12221 + reading_conffiles = 0;
12222 + reading_description = 1;
12223 + }
12224 +
12225 + else if(isGenericFieldType("Provides", *lines)){
12226 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12227 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12228 + if ( alterProvidesLine(*lines,provide) ){
12229 + return EINVAL;
12230 + }
12231 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12232 +/* Let's try to hack a bit here.
12233 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12234 + in alot of other places. We will remove it before writing down the status database */
12235 + pkg_false_provides=0;
12236 + free(provide);
12237 + }
12238 +
12239 + else if(isGenericFieldType("Depends", *lines))
12240 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12241 + else if(isGenericFieldType("Pre-Depends", *lines))
12242 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12243 + else if(isGenericFieldType("Recommends", *lines))
12244 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12245 + else if(isGenericFieldType("Suggests", *lines))
12246 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12247 + /* Abhaya: support for conflicts */
12248 + else if(isGenericFieldType("Conflicts", *lines))
12249 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12250 + else if(isGenericFieldType("Replaces", *lines))
12251 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12252 + else if(line_is_blank(*lines)) {
12253 + lines++;
12254 + break;
12255 + }
12256 + else if(**lines == ' '){
12257 + if(reading_description) {
12258 + /* we already know it's not blank, so the rest of description */
12259 + pkg->description = realloc(pkg->description,
12260 + strlen(pkg->description)
12261 + + 1 + strlen(*lines) + 1);
12262 + strcat(pkg->description, "\n");
12263 + strcat(pkg->description, (*lines));
12264 + }
12265 + else if(reading_conffiles)
12266 + parseConffiles(pkg, *lines);
12267 + }
12268 + }
12269 + *raw = lines;
12270 +/* If the ipk has not a Provides line, we insert our false line */
12271 + if ( pkg_false_provides==1)
12272 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12273 +
12274 + if (pkg->name) {
12275 + return 0;
12276 + } else {
12277 + return EINVAL;
12278 + }
12279 +}
12280 +
12281 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12282 +{
12283 + char ** lines;
12284 +
12285 + for (lines = *raw; *lines; lines++) {
12286 + if(isGenericFieldType("Essential:", *lines)) {
12287 + char *essential_value;
12288 + essential_value = parseGenericFieldType("Essential", *lines);
12289 + if (strcmp(essential_value, "yes") == 0) {
12290 + pkg->essential = 1;
12291 + }
12292 + free(essential_value);
12293 + }
12294 + }
12295 + *raw = lines;
12296 +
12297 + return 0;
12298 +}
12299 Index: busybox-1.7.2/archival/libipkg/pkg_parse.h
12300 ===================================================================
12301 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12302 +++ busybox-1.7.2/archival/libipkg/pkg_parse.h 2007-10-30 15:35:05.000000000 -0500
12303 @@ -0,0 +1,31 @@
12304 +/* pkg_parse.h - the itsy package management system
12305 +
12306 + Steven M. Ayer
12307 +
12308 + Copyright (C) 2002 Compaq Computer Corporation
12309 +
12310 + This program is free software; you can redistribute it and/or
12311 + modify it under the terms of the GNU General Public License as
12312 + published by the Free Software Foundation; either version 2, or (at
12313 + your option) any later version.
12314 +
12315 + This program is distributed in the hope that it will be useful, but
12316 + WITHOUT ANY WARRANTY; without even the implied warranty of
12317 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12318 + General Public License for more details.
12319 +*/
12320 +
12321 +#ifndef PKG_PARSE_H
12322 +#define PKG_PARSE_H
12323 +
12324 +int isGenericFieldType(char * type, char * line);
12325 +char * parseGenericFieldType(char * type, char * raw);
12326 +void parseStatus(pkg_t *pkg, char * raw);
12327 +int parseVersion(pkg_t *pkg, char *raw);
12328 +char ** parseDependsString(char * raw, int * depends_count);
12329 +int parseVersion(pkg_t *pkg, char *raw);
12330 +void parseConffiles(pkg_t * pkg, char * raw);
12331 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12332 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12333 +
12334 +#endif
12335 Index: busybox-1.7.2/archival/libipkg/pkg_src.c
12336 ===================================================================
12337 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12338 +++ busybox-1.7.2/archival/libipkg/pkg_src.c 2007-10-30 15:35:05.000000000 -0500
12339 @@ -0,0 +1,43 @@
12340 +/* pkg_src.c - the itsy package management system
12341 +
12342 + Carl D. Worth
12343 +
12344 + Copyright (C) 2001 University of Southern California
12345 +
12346 + This program is free software; you can redistribute it and/or
12347 + modify it under the terms of the GNU General Public License as
12348 + published by the Free Software Foundation; either version 2, or (at
12349 + your option) any later version.
12350 +
12351 + This program is distributed in the hope that it will be useful, but
12352 + WITHOUT ANY WARRANTY; without even the implied warranty of
12353 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12354 + General Public License for more details.
12355 +*/
12356 +
12357 +#include "ipkg.h"
12358 +
12359 +#include "pkg_src.h"
12360 +#include "str_util.h"
12361 +
12362 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12363 +{
12364 + src->gzip = gzip;
12365 + src->name = str_dup_safe (name);
12366 + src->value = str_dup_safe (base_url);
12367 + if (extra_data)
12368 + src->extra_data = str_dup_safe (extra_data);
12369 + else
12370 + src->extra_data = NULL;
12371 + return 0;
12372 +}
12373 +
12374 +void pkg_src_deinit(pkg_src_t *src)
12375 +{
12376 + free (src->name);
12377 + free (src->value);
12378 + if (src->extra_data)
12379 + free (src->extra_data);
12380 +}
12381 +
12382 +
12383 Index: busybox-1.7.2/archival/libipkg/pkg_src.h
12384 ===================================================================
12385 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12386 +++ busybox-1.7.2/archival/libipkg/pkg_src.h 2007-10-30 15:35:05.000000000 -0500
12387 @@ -0,0 +1,34 @@
12388 +/* pkg_src.h - the itsy package management system
12389 +
12390 + Carl D. Worth
12391 +
12392 + Copyright (C) 2001 University of Southern California
12393 +
12394 + This program is free software; you can redistribute it and/or
12395 + modify it under the terms of the GNU General Public License as
12396 + published by the Free Software Foundation; either version 2, or (at
12397 + your option) any later version.
12398 +
12399 + This program is distributed in the hope that it will be useful, but
12400 + WITHOUT ANY WARRANTY; without even the implied warranty of
12401 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12402 + General Public License for more details.
12403 +*/
12404 +
12405 +#ifndef PKG_SRC_H
12406 +#define PKG_SRC_H
12407 +
12408 +#include "nv_pair.h"
12409 +
12410 +typedef struct
12411 +{
12412 + char *name;
12413 + char *value;
12414 + char *extra_data;
12415 + int gzip;
12416 +} pkg_src_t;
12417 +
12418 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12419 +void pkg_src_deinit(pkg_src_t *src);
12420 +
12421 +#endif
12422 Index: busybox-1.7.2/archival/libipkg/pkg_src_list.c
12423 ===================================================================
12424 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12425 +++ busybox-1.7.2/archival/libipkg/pkg_src_list.c 2007-10-30 15:35:05.000000000 -0500
12426 @@ -0,0 +1,75 @@
12427 +/* pkg_src_list.c - the itsy package management system
12428 +
12429 + Carl D. Worth
12430 +
12431 + Copyright (C) 2001 University of Southern California
12432 +
12433 + This program is free software; you can redistribute it and/or
12434 + modify it under the terms of the GNU General Public License as
12435 + published by the Free Software Foundation; either version 2, or (at
12436 + your option) any later version.
12437 +
12438 + This program is distributed in the hope that it will be useful, but
12439 + WITHOUT ANY WARRANTY; without even the implied warranty of
12440 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12441 + General Public License for more details.
12442 +*/
12443 +
12444 +#include "ipkg.h"
12445 +
12446 +#include "pkg_src_list.h"
12447 +#include "void_list.h"
12448 +
12449 +int pkg_src_list_init(pkg_src_list_t *list)
12450 +{
12451 + return void_list_init((void_list_t *) list);
12452 +}
12453 +
12454 +void pkg_src_list_deinit(pkg_src_list_t *list)
12455 +{
12456 + pkg_src_list_elt_t *iter;
12457 + pkg_src_t *pkg_src;
12458 +
12459 + for (iter = list->head; iter; iter = iter->next) {
12460 + pkg_src = iter->data;
12461 + pkg_src_deinit(pkg_src);
12462 +
12463 + /* malloced in pkg_src_list_append */
12464 + free(pkg_src);
12465 + iter->data = NULL;
12466 + }
12467 + void_list_deinit((void_list_t *) list);
12468 +}
12469 +
12470 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12471 + const char *name, const char *base_url, const char *extra_data,
12472 + int gzip)
12473 +{
12474 + int err;
12475 +
12476 + /* freed in pkg_src_list_deinit */
12477 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12478 +
12479 + if (pkg_src == NULL) {
12480 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12481 + return NULL;
12482 + }
12483 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12484 +
12485 + err = void_list_append((void_list_t *) list, pkg_src);
12486 + if (err) {
12487 + return NULL;
12488 + }
12489 +
12490 + return pkg_src;
12491 +}
12492 +
12493 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12494 +{
12495 + return void_list_push((void_list_t *) list, data);
12496 +}
12497 +
12498 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12499 +{
12500 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12501 +}
12502 Index: busybox-1.7.2/archival/libipkg/pkg_src_list.h
12503 ===================================================================
12504 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12505 +++ busybox-1.7.2/archival/libipkg/pkg_src_list.h 2007-10-30 15:35:05.000000000 -0500
12506 @@ -0,0 +1,57 @@
12507 +/* pkg_src_list.h - the itsy package management system
12508 +
12509 + Carl D. Worth
12510 +
12511 + Copyright (C) 2001 University of Southern California
12512 +
12513 + This program is free software; you can redistribute it and/or
12514 + modify it under the terms of the GNU General Public License as
12515 + published by the Free Software Foundation; either version 2, or (at
12516 + your option) any later version.
12517 +
12518 + This program is distributed in the hope that it will be useful, but
12519 + WITHOUT ANY WARRANTY; without even the implied warranty of
12520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12521 + General Public License for more details.
12522 +*/
12523 +
12524 +#ifndef PKG_SRC_LIST_H
12525 +#define PKG_SRC_LIST_H
12526 +
12527 +#include "pkg_src.h"
12528 +
12529 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12530 +struct pkg_src_list_elt
12531 +{
12532 + pkg_src_list_elt_t *next;
12533 + pkg_src_t *data;
12534 +};
12535 +
12536 +typedef struct pkg_src_list pkg_src_list_t;
12537 +struct pkg_src_list
12538 +{
12539 + pkg_src_list_elt_t pre_head;
12540 + pkg_src_list_elt_t *head;
12541 + pkg_src_list_elt_t *tail;
12542 +};
12543 +
12544 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12545 +{
12546 + if (list->head == NULL)
12547 + return 1;
12548 + else
12549 + return 0;
12550 +}
12551 +
12552 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12553 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12554 +
12555 +int pkg_src_list_init(pkg_src_list_t *list);
12556 +void pkg_src_list_deinit(pkg_src_list_t *list);
12557 +
12558 +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);
12559 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12560 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12561 +
12562 +#endif
12563 +
12564 Index: busybox-1.7.2/archival/libipkg/pkg_vec.c
12565 ===================================================================
12566 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12567 +++ busybox-1.7.2/archival/libipkg/pkg_vec.c 2007-10-30 15:35:05.000000000 -0500
12568 @@ -0,0 +1,230 @@
12569 +/* pkg_vec.c - the itsy package management system
12570 +
12571 + Steven M. Ayer
12572 +
12573 + Copyright (C) 2002 Compaq Computer Corporation
12574 +
12575 + This program is free software; you can redistribute it and/or
12576 + modify it under the terms of the GNU General Public License as
12577 + published by the Free Software Foundation; either version 2, or (at
12578 + your option) any later version.
12579 +
12580 + This program is distributed in the hope that it will be useful, but
12581 + WITHOUT ANY WARRANTY; without even the implied warranty of
12582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12583 + General Public License for more details.
12584 +*/
12585 +
12586 +#include <stdlib.h>
12587 +#include <fnmatch.h>
12588 +#include "xregex.h"
12589 +#include "ipkg.h"
12590 +#include "pkg.h"
12591 +
12592 +pkg_vec_t * pkg_vec_alloc(void)
12593 +{
12594 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12595 + if (!vec) {
12596 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12597 + return NULL;
12598 + }
12599 + vec->pkgs = NULL;
12600 + vec->len = 0;
12601 +
12602 + return vec;
12603 +}
12604 +
12605 +void pkg_vec_free(pkg_vec_t *vec)
12606 +{
12607 + free(vec->pkgs);
12608 + free(vec);
12609 +}
12610 +
12611 +/*
12612 + * assumption: all names in a vector are identical
12613 + * assumption: all version strings are trimmed,
12614 + * so identical versions have identical version strings,
12615 + * implying identical packages; let's marry these
12616 + */
12617 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12618 +{
12619 + int i;
12620 + int found = 0;
12621 +
12622 + /* look for a duplicate pkg by name, version, and architecture */
12623 + for (i = 0; i < vec->len; i++){
12624 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12625 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12626 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12627 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12628 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12629 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12630 + found = 1;
12631 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12632 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12633 + break;
12634 + }
12635 + }
12636 +
12637 + /* we didn't find one, add it */
12638 + if (!found){
12639 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12640 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12641 +
12642 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12643 + vec->pkgs[vec->len] = pkg;
12644 + vec->len++;
12645 + return pkg;
12646 + }
12647 + /* update the one that we have */
12648 + else {
12649 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12650 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12651 + if (set_status) {
12652 + /* this is from the status file, so need to merge with existing database */
12653 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12654 + pkg_merge(vec->pkgs[i], pkg, set_status);
12655 + /* XXX: CLEANUP: It's not so polite to free something here
12656 + that was passed in from above. */
12657 + pkg_deinit(pkg);
12658 + free(pkg);
12659 + } else {
12660 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12661 + /* just overwrite the old one */
12662 + pkg_deinit(vec->pkgs[i]);
12663 + free(vec->pkgs[i]);
12664 + vec->pkgs[i] = pkg;
12665 + }
12666 + return vec->pkgs[i];
12667 + }
12668 +}
12669 +
12670 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12671 +{
12672 + int i;
12673 + int found = 0;
12674 +
12675 + /* look for a duplicate pkg by name, version, and architecture */
12676 + for (i = 0; i < vec->len; i++)
12677 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12678 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12679 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12680 + found = 1;
12681 + break;
12682 + }
12683 +
12684 + /* we didn't find one, add it */
12685 + if(!found){
12686 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12687 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12688 + vec->len++;
12689 + }
12690 +}
12691 +
12692 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12693 +{
12694 + int i;
12695 + for (i = 0; i < vec->len; i++)
12696 + if (vec->pkgs[i] == apkg)
12697 + return 1;
12698 + return 0;
12699 +}
12700 +
12701 +typedef int (*compare_fcn_t)(const void *, const void *);
12702 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12703 +{
12704 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12705 +}
12706 +
12707 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12708 +{
12709 + int npkgs = vec->len;
12710 + int i;
12711 + for (i = 0; i < npkgs; i++) {
12712 + pkg_t *pkg = vec->pkgs[i];
12713 + pkg->state_flag &= ~SF_MARKED;
12714 + }
12715 + return 0;
12716 +}
12717 +
12718 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12719 +{
12720 + int matching_count = 0;
12721 + pkg_t **pkgs = vec->pkgs;
12722 + int npkgs = vec->len;
12723 + int i;
12724 + for (i = 0; i < npkgs; i++) {
12725 + pkg_t *pkg = pkgs[i];
12726 + if (fnmatch(pattern, pkg->name, 0)==0) {
12727 + pkg->state_flag |= SF_MARKED;
12728 + matching_count++;
12729 + }
12730 + }
12731 + return matching_count;
12732 +}
12733 +
12734 +
12735 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12736 +{
12737 + abstract_pkg_vec_t * vec ;
12738 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12739 + if (!vec) {
12740 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12741 + return NULL;
12742 + }
12743 + vec->pkgs = NULL;
12744 + vec->len = 0;
12745 +
12746 + return vec;
12747 +}
12748 +
12749 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12750 +{
12751 + free(vec->pkgs);
12752 + free(vec);
12753 +}
12754 +
12755 +/*
12756 + * assumption: all names in a vector are unique
12757 + */
12758 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12759 +{
12760 + int i;
12761 +
12762 + /* look for a duplicate pkg by name */
12763 + for(i = 0; i < vec->len; i++)
12764 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12765 + break;
12766 +
12767 + /* we didn't find one, add it */
12768 + if(i == vec->len){
12769 + vec->pkgs =
12770 + (abstract_pkg_t **)
12771 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12772 + vec->pkgs[vec->len] = pkg;
12773 + vec->len++;
12774 + }
12775 +}
12776 +
12777 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12778 +{
12779 + if (vec->len > i)
12780 + return vec->pkgs[i];
12781 + else
12782 + return NULL;
12783 +}
12784 +
12785 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12786 +{
12787 + int i;
12788 + for (i = 0; i < vec->len; i++)
12789 + if (vec->pkgs[i] == apkg)
12790 + return 1;
12791 + return 0;
12792 +}
12793 +
12794 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12795 +{
12796 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12797 +}
12798 +
12799 Index: busybox-1.7.2/archival/libipkg/pkg_vec.h
12800 ===================================================================
12801 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12802 +++ busybox-1.7.2/archival/libipkg/pkg_vec.h 2007-10-30 15:35:05.000000000 -0500
12803 @@ -0,0 +1,64 @@
12804 +/* pkg_vec.h - the itsy package management system
12805 +
12806 + Steven M. Ayer
12807 +
12808 + Copyright (C) 2002 Compaq Computer Corporation
12809 +
12810 + This program is free software; you can redistribute it and/or
12811 + modify it under the terms of the GNU General Public License as
12812 + published by the Free Software Foundation; either version 2, or (at
12813 + your option) any later version.
12814 +
12815 + This program is distributed in the hope that it will be useful, but
12816 + WITHOUT ANY WARRANTY; without even the implied warranty of
12817 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12818 + General Public License for more details.
12819 +*/
12820 +
12821 +#ifndef PKG_VEC_H
12822 +#define PKG_VEC_H
12823 +
12824 +typedef struct pkg pkg_t;
12825 +typedef struct abstract_pkg abstract_pkg_t;
12826 +
12827 +struct pkg_vec
12828 +{
12829 + pkg_t **pkgs;
12830 + int len;
12831 +};
12832 +typedef struct pkg_vec pkg_vec_t;
12833 +
12834 +struct abstract_pkg_vec
12835 +{
12836 + abstract_pkg_t **pkgs;
12837 + int len;
12838 +};
12839 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12840 +
12841 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12842 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12843 +
12844 +pkg_vec_t * pkg_vec_alloc(void);
12845 +void pkg_vec_free(pkg_vec_t *vec);
12846 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12847 +
12848 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12849 +/* pkg_vec_insert_merge: might munge pkg.
12850 +* returns the pkg that is in the pkg graph */
12851 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12852 +/* this one never munges pkg */
12853 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12854 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12855 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12856 +
12857 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12858 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12859 +
12860 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12861 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12862 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12863 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12864 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12865 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12866 +#endif
12867 +
12868 Index: busybox-1.7.2/archival/libipkg/sprintf_alloc.h
12869 ===================================================================
12870 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12871 +++ busybox-1.7.2/archival/libipkg/sprintf_alloc.h 2007-10-30 15:35:05.000000000 -0500
12872 @@ -0,0 +1,25 @@
12873 +/* sprintf_alloca.c -- like sprintf with memory allocation
12874 +
12875 + Carl D. Worth
12876 +
12877 + Copyright (C) 2001 University of Southern California
12878 +
12879 + This program is free software; you can redistribute it and/or modify
12880 + it under the terms of the GNU General Public License as published by
12881 + the Free Software Foundation; either version 2, or (at your option)
12882 + any later version.
12883 +
12884 + This program is distributed in the hope that it will be useful,
12885 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12886 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12887 + GNU General Public License for more details.
12888 +*/
12889 +
12890 +#ifndef SPRINTF_ALLOC_H
12891 +#define SPRINTF_ALLOC_H
12892 +
12893 +#include "libbb.h"
12894 +
12895 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12896 +
12897 +#endif
12898 Index: busybox-1.7.2/archival/libipkg/str_list.c
12899 ===================================================================
12900 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12901 +++ busybox-1.7.2/archival/libipkg/str_list.c 2007-10-30 15:35:05.000000000 -0500
12902 @@ -0,0 +1,76 @@
12903 +/* str_list.c - the itsy package management system
12904 +
12905 + Carl D. Worth
12906 +
12907 + Copyright (C) 2001 University of Southern California
12908 +
12909 + This program is free software; you can redistribute it and/or
12910 + modify it under the terms of the GNU General Public License as
12911 + published by the Free Software Foundation; either version 2, or (at
12912 + your option) any later version.
12913 +
12914 + This program is distributed in the hope that it will be useful, but
12915 + WITHOUT ANY WARRANTY; without even the implied warranty of
12916 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12917 + General Public License for more details.
12918 +*/
12919 +
12920 +#include "ipkg.h"
12921 +
12922 +#include "str_list.h"
12923 +
12924 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12925 +{
12926 + return void_list_elt_init((void_list_elt_t *) elt, data);
12927 +}
12928 +
12929 +void str_list_elt_deinit(str_list_elt_t *elt)
12930 +{
12931 + void_list_elt_deinit((void_list_elt_t *) elt);
12932 +}
12933 +
12934 +str_list_t *str_list_alloc()
12935 +{
12936 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12937 + if (list)
12938 + str_list_init(list);
12939 + return list;
12940 +}
12941 +
12942 +int str_list_init(str_list_t *list)
12943 +{
12944 + return void_list_init((void_list_t *) list);
12945 +}
12946 +
12947 +void str_list_deinit(str_list_t *list)
12948 +{
12949 + void_list_deinit((void_list_t *) list);
12950 +}
12951 +
12952 +int str_list_append(str_list_t *list, char *data)
12953 +{
12954 + return void_list_append((void_list_t *) list, data);
12955 +}
12956 +
12957 +int str_list_push(str_list_t *list, char *data)
12958 +{
12959 + return void_list_push((void_list_t *) list, data);
12960 +}
12961 +
12962 +str_list_elt_t *str_list_pop(str_list_t *list)
12963 +{
12964 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12965 +}
12966 +
12967 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12968 +{
12969 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12970 + (void_list_elt_t **) iter);
12971 +}
12972 +
12973 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12974 +{
12975 + return (char *)void_list_remove_elt((void_list_t *) list,
12976 + (void *)target_str,
12977 + (void_list_cmp_t)strcmp);
12978 +}
12979 Index: busybox-1.7.2/archival/libipkg/str_list.h
12980 ===================================================================
12981 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12982 +++ busybox-1.7.2/archival/libipkg/str_list.h 2007-10-30 15:35:05.000000000 -0500
12983 @@ -0,0 +1,51 @@
12984 +/* str_list.h - the itsy package management system
12985 +
12986 + Carl D. Worth
12987 +
12988 + Copyright (C) 2001 University of Southern California
12989 +
12990 + This program is free software; you can redistribute it and/or
12991 + modify it under the terms of the GNU General Public License as
12992 + published by the Free Software Foundation; either version 2, or (at
12993 + your option) any later version.
12994 +
12995 + This program is distributed in the hope that it will be useful, but
12996 + WITHOUT ANY WARRANTY; without even the implied warranty of
12997 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12998 + General Public License for more details.
12999 +*/
13000 +
13001 +#ifndef STR_LIST_H
13002 +#define STR_LIST_H
13003 +
13004 +#include "void_list.h"
13005 +
13006 +typedef struct str_list_elt str_list_elt_t;
13007 +struct str_list_elt
13008 +{
13009 + str_list_elt_t *next;
13010 + char *data;
13011 +};
13012 +
13013 +typedef struct xstr_list str_list_t;
13014 +struct xstr_list
13015 +{
13016 + str_list_elt_t pre_head;
13017 + str_list_elt_t *head;
13018 + str_list_elt_t *tail;
13019 +};
13020 +
13021 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13022 +void str_list_elt_deinit(str_list_elt_t *elt);
13023 +
13024 +str_list_t *str_list_alloc(void);
13025 +int str_list_init(str_list_t *list);
13026 +void str_list_deinit(str_list_t *list);
13027 +
13028 +int str_list_append(str_list_t *list, char *data);
13029 +int str_list_push(str_list_t *list, char *data);
13030 +str_list_elt_t *str_list_pop(str_list_t *list);
13031 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13032 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13033 +
13034 +#endif
13035 Index: busybox-1.7.2/archival/libipkg/str_util.c
13036 ===================================================================
13037 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13038 +++ busybox-1.7.2/archival/libipkg/str_util.c 2007-10-30 15:35:05.000000000 -0500
13039 @@ -0,0 +1,63 @@
13040 +/* str_utils.c - the itsy package management system
13041 +
13042 + Carl D. Worth
13043 +
13044 + Copyright (C) 2001 University of Southern California
13045 +
13046 + This program is free software; you can redistribute it and/or
13047 + modify it under the terms of the GNU General Public License as
13048 + published by the Free Software Foundation; either version 2, or (at
13049 + your option) any later version.
13050 +
13051 + This program is distributed in the hope that it will be useful, but
13052 + WITHOUT ANY WARRANTY; without even the implied warranty of
13053 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13054 + General Public License for more details.
13055 +*/
13056 +
13057 +#include "ipkg.h"
13058 +
13059 +int str_starts_with(const char *str, const char *prefix)
13060 +{
13061 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13062 +}
13063 +
13064 +int str_ends_with(const char *str, const char *suffix)
13065 +{
13066 + int suffix_len;
13067 + int str_len;
13068 +
13069 + str_len = strlen(str);
13070 + suffix_len = strlen(suffix);
13071 +
13072 + if (str_len < suffix_len) {
13073 + return 0;
13074 + }
13075 +
13076 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13077 +}
13078 +
13079 +int str_chomp(char *str)
13080 +{
13081 + if (str[strlen(str) - 1] == '\n') {
13082 + str[strlen(str) - 1] = '\0';
13083 + return 1;
13084 + }
13085 + return 0;
13086 +}
13087 +
13088 +int str_toupper(char *str)
13089 +{
13090 + while (*str) {
13091 + *str = toupper(*str);
13092 + str++;
13093 + }
13094 +
13095 + return 0;
13096 +}
13097 +
13098 +char *str_dup_safe(const char *str)
13099 +{
13100 + return str ? strdup(str) : NULL;
13101 +}
13102 +
13103 Index: busybox-1.7.2/archival/libipkg/str_util.h
13104 ===================================================================
13105 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13106 +++ busybox-1.7.2/archival/libipkg/str_util.h 2007-10-30 15:35:05.000000000 -0500
13107 @@ -0,0 +1,27 @@
13108 +/* str_utils.h - the itsy package management system
13109 +
13110 + Carl D. Worth
13111 +
13112 + Copyright (C) 2001 University of Southern California
13113 +
13114 + This program is free software; you can redistribute it and/or
13115 + modify it under the terms of the GNU General Public License as
13116 + published by the Free Software Foundation; either version 2, or (at
13117 + your option) any later version.
13118 +
13119 + This program is distributed in the hope that it will be useful, but
13120 + WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13122 + General Public License for more details.
13123 +*/
13124 +
13125 +#ifndef STR_UTILS_H
13126 +#define STR_UTILS_H
13127 +
13128 +int str_starts_with(const char *str, const char *prefix);
13129 +int str_ends_with(const char *str, const char *suffix);
13130 +int str_chomp(char *str);
13131 +int str_toupper(char *str);
13132 +char *str_dup_safe(const char *str);
13133 +
13134 +#endif
13135 Index: busybox-1.7.2/archival/libipkg/user.c
13136 ===================================================================
13137 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13138 +++ busybox-1.7.2/archival/libipkg/user.c 2007-10-30 15:35:05.000000000 -0500
13139 @@ -0,0 +1,58 @@
13140 +/* user.c - the itsy package management system
13141 +
13142 + Jamey Hicks
13143 +
13144 + Copyright (C) 2002 Hewlett Packard Company
13145 + Copyright (C) 2001 University of Southern California
13146 +
13147 + This program is free software; you can redistribute it and/or
13148 + modify it under the terms of the GNU General Public License as
13149 + published by the Free Software Foundation; either version 2, or (at
13150 + your option) any later version.
13151 +
13152 + This program is distributed in the hope that it will be useful, but
13153 + WITHOUT ANY WARRANTY; without even the implied warranty of
13154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13155 + General Public License for more details.
13156 +*/
13157 +
13158 +#include <stdio.h>
13159 +#include <stdarg.h>
13160 +#include "file_util.h"
13161 +#include "str_util.h"
13162 +#ifdef IPKG_LIB
13163 +#include "libipkg.h"
13164 +#endif
13165 +
13166 +
13167 +#ifdef IPKG_LIB
13168 +static char *question = NULL;
13169 +static int question_len = 255;
13170 +#endif
13171 +char *get_user_response(const char *format, ...)
13172 +{
13173 + int len = question_len;
13174 + va_list ap;
13175 + char *response;
13176 + va_start(ap, format);
13177 +
13178 +#ifndef IPKG_LIB
13179 + vprintf(format, ap);
13180 + do {
13181 + response = file_read_line_alloc(stdin);
13182 + } while (response == NULL);
13183 +#else
13184 + do {
13185 + if (question == NULL || len > question_len) {
13186 + question = realloc(question, len + 1);
13187 + question_len = len;
13188 + }
13189 + len = vsnprintf(question,question_len,format,ap);
13190 + } while (len > question_len);
13191 + response = strdup(ipkg_cb_response(question));
13192 +#endif
13193 + str_chomp(response);
13194 + str_tolower(response);
13195 +
13196 + return response;
13197 +}
13198 Index: busybox-1.7.2/archival/libipkg/user.h
13199 ===================================================================
13200 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13201 +++ busybox-1.7.2/archival/libipkg/user.h 2007-10-30 15:35:05.000000000 -0500
13202 @@ -0,0 +1,23 @@
13203 +/* user.c - the itsy package management system
13204 +
13205 + Jamey Hicks
13206 +
13207 + Copyright (C) 2002 Hewlett Packard Company
13208 + Copyright (C) 2001 University of Southern California
13209 +
13210 + This program is free software; you can redistribute it and/or
13211 + modify it under the terms of the GNU General Public License as
13212 + published by the Free Software Foundation; either version 2, or (at
13213 + your option) any later version.
13214 +
13215 + This program is distributed in the hope that it will be useful, but
13216 + WITHOUT ANY WARRANTY; without even the implied warranty of
13217 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13218 + General Public License for more details.
13219 +*/
13220 +
13221 +#include <stdio.h>
13222 +#include <stdarg.h>
13223 +
13224 +char *get_user_response(const char *format, ...);
13225 +
13226 Index: busybox-1.7.2/archival/libipkg/void_list.c
13227 ===================================================================
13228 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13229 +++ busybox-1.7.2/archival/libipkg/void_list.c 2007-10-30 15:35:05.000000000 -0500
13230 @@ -0,0 +1,194 @@
13231 +/* void_list.c - the itsy package management system
13232 +
13233 + Carl D. Worth
13234 +
13235 + Copyright (C) 2001 University of Southern California
13236 +
13237 + This program is free software; you can redistribute it and/or
13238 + modify it under the terms of the GNU General Public License as
13239 + published by the Free Software Foundation; either version 2, or (at
13240 + your option) any later version.
13241 +
13242 + This program is distributed in the hope that it will be useful, but
13243 + WITHOUT ANY WARRANTY; without even the implied warranty of
13244 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13245 + General Public License for more details.
13246 +*/
13247 +
13248 +#include "ipkg.h"
13249 +#include <errno.h>
13250 +
13251 +#include "void_list.h"
13252 +
13253 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13254 +{
13255 + elt->next = NULL;
13256 + elt->data = data;
13257 +
13258 + return 0;
13259 +}
13260 +
13261 +void void_list_elt_deinit(void_list_elt_t *elt)
13262 +{
13263 + void_list_elt_init(elt, NULL);
13264 +}
13265 +
13266 +int void_list_init(void_list_t *list)
13267 +{
13268 + void_list_elt_init(&list->pre_head, NULL);
13269 + list->head = NULL;
13270 + list->pre_head.next = list->head;
13271 + list->tail = NULL;
13272 +
13273 + return 0;
13274 +}
13275 +
13276 +void void_list_deinit(void_list_t *list)
13277 +{
13278 + void_list_elt_t *elt;
13279 +
13280 + while (list->head) {
13281 + elt = void_list_pop(list);
13282 + void_list_elt_deinit(elt);
13283 + /* malloced in void_list_append */
13284 + free(elt);
13285 + }
13286 +}
13287 +
13288 +int void_list_append(void_list_t *list, void *data)
13289 +{
13290 + void_list_elt_t *elt;
13291 +
13292 + /* freed in void_list_deinit */
13293 + elt = malloc(sizeof(void_list_elt_t));
13294 + if (elt == NULL) {
13295 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13296 + return ENOMEM;
13297 + }
13298 +
13299 + void_list_elt_init(elt, data);
13300 +
13301 + if (list->tail) {
13302 + list->tail->next = elt;
13303 + list->tail = elt;
13304 + } else {
13305 + list->head = elt;
13306 + list->pre_head.next = list->head;
13307 + list->tail = elt;
13308 + }
13309 +
13310 + return 0;
13311 +}
13312 +
13313 +int void_list_push(void_list_t *list, void *data)
13314 +{
13315 + void_list_elt_t *elt;
13316 +
13317 + elt = malloc(sizeof(void_list_elt_t));
13318 + if (elt == NULL) {
13319 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13320 + return ENOMEM;
13321 + }
13322 +
13323 + void_list_elt_init(elt, data);
13324 +
13325 + elt->next = list->head;
13326 + list->head->next = elt;
13327 + if (list->tail == NULL) {
13328 + list->tail = list->head;
13329 + }
13330 +
13331 + return 0;
13332 +}
13333 +
13334 +void_list_elt_t *void_list_pop(void_list_t *list)
13335 +{
13336 + void_list_elt_t *elt;
13337 +
13338 + elt = list->head;
13339 +
13340 + if (list->head) {
13341 + list->head = list->head->next;
13342 + list->pre_head.next = list->head;
13343 + if (list->head == NULL) {
13344 + list->tail = NULL;
13345 + }
13346 + }
13347 +
13348 + return elt;
13349 +}
13350 +
13351 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13352 +{
13353 + void_list_elt_t *prior;
13354 + void_list_elt_t *old_elt;
13355 + void *old_data;
13356 +
13357 + old_elt = *iter;
13358 + old_data = old_elt->data;
13359 +
13360 + if (old_elt == list->head) {
13361 + prior = &list->pre_head;
13362 + void_list_pop(list);
13363 + } else {
13364 + for (prior = list->head; prior; prior = prior->next) {
13365 + if (prior->next == old_elt) {
13366 + break;
13367 + }
13368 + }
13369 + if (prior == NULL || prior->next != old_elt) {
13370 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13371 + return NULL;
13372 + }
13373 + prior->next = old_elt->next;
13374 +
13375 + if (old_elt == list->tail) {
13376 + list->tail = prior;
13377 + }
13378 + }
13379 +
13380 + void_list_elt_deinit(old_elt);
13381 + *iter = prior;
13382 +
13383 + return old_data;
13384 +}
13385 +
13386 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13387 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13388 +{
13389 + void_list_elt_t *prior;
13390 + void_list_elt_t *old_elt = NULL;
13391 + void *old_data = NULL;
13392 +
13393 + /* first element */
13394 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13395 + old_elt = list->head;
13396 + old_data = list->head->data;
13397 + void_list_pop(list);
13398 + } else {
13399 + int found = 0;
13400 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13401 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13402 + old_elt = prior->next;
13403 + old_data = old_elt->data;
13404 + found = 1;
13405 + break;
13406 + }
13407 + }
13408 + if (!found) {
13409 + return NULL;
13410 + }
13411 + prior->next = old_elt->next;
13412 +
13413 + if (old_elt == list->tail) {
13414 + list->tail = prior;
13415 + }
13416 + }
13417 + if (old_elt)
13418 + void_list_elt_deinit(old_elt);
13419 +
13420 + if (old_data)
13421 + return old_data;
13422 + else
13423 + return NULL;
13424 +}
13425 Index: busybox-1.7.2/archival/libipkg/void_list.h
13426 ===================================================================
13427 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13428 +++ busybox-1.7.2/archival/libipkg/void_list.h 2007-10-30 15:35:05.000000000 -0500
13429 @@ -0,0 +1,59 @@
13430 +/* void_list.h - the itsy package management system
13431 +
13432 + Carl D. Worth
13433 +
13434 + Copyright (C) 2001 University of Southern California
13435 +
13436 + This program is free software; you can redistribute it and/or
13437 + modify it under the terms of the GNU General Public License as
13438 + published by the Free Software Foundation; either version 2, or (at
13439 + your option) any later version.
13440 +
13441 + This program is distributed in the hope that it will be useful, but
13442 + WITHOUT ANY WARRANTY; without even the implied warranty of
13443 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13444 + General Public License for more details.
13445 +*/
13446 +
13447 +#ifndef VOID_LIST_H
13448 +#define VOID_LIST_H
13449 +
13450 +typedef struct void_list_elt void_list_elt_t;
13451 +struct void_list_elt
13452 +{
13453 + void_list_elt_t *next;
13454 + void *data;
13455 +};
13456 +
13457 +typedef struct void_list void_list_t;
13458 +struct void_list
13459 +{
13460 + void_list_elt_t pre_head;
13461 + void_list_elt_t *head;
13462 + void_list_elt_t *tail;
13463 +};
13464 +
13465 +static inline int void_list_empty(void_list_t *list)
13466 +{
13467 + if (list->head == NULL)
13468 + return 1;
13469 + else
13470 + return 0;
13471 +}
13472 +
13473 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13474 +void void_list_elt_deinit(void_list_elt_t *elt);
13475 +
13476 +int void_list_init(void_list_t *list);
13477 +void void_list_deinit(void_list_t *list);
13478 +
13479 +int void_list_append(void_list_t *list, void *data);
13480 +int void_list_push(void_list_t *list, void *data);
13481 +void_list_elt_t *void_list_pop(void_list_t *list);
13482 +
13483 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13484 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13485 +typedef int (*void_list_cmp_t)(const void *, const void *);
13486 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13487 +
13488 +#endif
13489 Index: busybox-1.7.2/archival/libipkg/xsystem.c
13490 ===================================================================
13491 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13492 +++ busybox-1.7.2/archival/libipkg/xsystem.c 2007-10-30 15:35:05.000000000 -0500
13493 @@ -0,0 +1,64 @@
13494 +/* xsystem.c - system(3) with error messages
13495 +
13496 + Carl D. Worth
13497 +
13498 + Copyright (C) 2001 University of Southern California
13499 +
13500 + This program is free software; you can redistribute it and/or
13501 + modify it under the terms of the GNU General Public License as
13502 + published by the Free Software Foundation; either version 2, or (at
13503 + your option) any later version.
13504 +
13505 + This program is distributed in the hope that it will be useful, but
13506 + WITHOUT ANY WARRANTY; without even the implied warranty of
13507 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13508 + General Public License for more details.
13509 +*/
13510 +
13511 +#include "ipkg.h"
13512 +#include <sys/wait.h>
13513 +
13514 +#include "xsystem.h"
13515 +
13516 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13517 + really need the /bin/sh invocation which takes resources and
13518 + introduces security problems. I should switch all of this to a sort
13519 + of execl() or execv() interface/implementation.
13520 +*/
13521 +
13522 +/* Like system(3), but with error messages printed if the fork fails
13523 + or if the child process dies due to an uncaught signal. Also, the
13524 + return value is a bit simpler:
13525 +
13526 + -1 if there was any problem
13527 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13528 + as defined in <sys/wait.h>.
13529 +*/
13530 +int xsystem(const char *cmd)
13531 +{
13532 + int err;
13533 +
13534 + err = system(cmd);
13535 +
13536 + if (err == -1) {
13537 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13538 + __FUNCTION__, cmd);
13539 + return -1;
13540 + }
13541 +
13542 + if (WIFSIGNALED(err)) {
13543 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13544 + __FUNCTION__, WTERMSIG(err), cmd);
13545 + return -1;
13546 + }
13547 +
13548 + if (WIFEXITED(err)) {
13549 + /* Normal child exit */
13550 + return WEXITSTATUS(err);
13551 + }
13552 +
13553 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13554 + __FUNCTION__, err);
13555 + return -1;
13556 +}
13557 +
13558 Index: busybox-1.7.2/archival/libipkg/xsystem.h
13559 ===================================================================
13560 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13561 +++ busybox-1.7.2/archival/libipkg/xsystem.h 2007-10-30 15:35:05.000000000 -0500
13562 @@ -0,0 +1,34 @@
13563 +/* xsystem.h - system(3) with error messages
13564 +
13565 + Carl D. Worth
13566 +
13567 + Copyright (C) 2001 University of Southern California
13568 +
13569 + This program is free software; you can redistribute it and/or
13570 + modify it under the terms of the GNU General Public License as
13571 + published by the Free Software Foundation; either version 2, or (at
13572 + your option) any later version.
13573 +
13574 + This program is distributed in the hope that it will be useful, but
13575 + WITHOUT ANY WARRANTY; without even the implied warranty of
13576 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13577 + General Public License for more details.
13578 +*/
13579 +
13580 +#ifndef XSYSTEM_H
13581 +#define XSYSTEM_H
13582 +
13583 +#include <stdlib.h>
13584 +
13585 +/* Like system(3), but with error messages printed if the fork fails
13586 + or if the child process dies due to an uncaught signal. Also, the
13587 + return value is a bit simpler:
13588 +
13589 + -1 if there was any problem
13590 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13591 + as defined in <sys/wait.h>.
13592 +*/
13593 +int xsystem(const char *cmd);
13594 +
13595 +#endif
13596 +
13597 Index: busybox-1.7.2/archival/libunarchive/data_extract_all.c
13598 ===================================================================
13599 --- busybox-1.7.2.orig/archival/libunarchive/data_extract_all.c 2007-10-30 15:34:59.000000000 -0500
13600 +++ busybox-1.7.2/archival/libunarchive/data_extract_all.c 2007-10-30 15:35:05.000000000 -0500
13601 @@ -129,3 +129,17 @@
13602 }
13603 }
13604 }
13605 +
13606 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13607 +{
13608 + char *name_ptr = archive_handle->file_header->name;
13609 +
13610 + name_ptr += strspn(name_ptr, "./");
13611 + if (name_ptr[0] != '\0') {
13612 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13613 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13614 + strcat(archive_handle->file_header->name, name_ptr);
13615 + data_extract_all(archive_handle);
13616 + }
13617 +}
13618 +
13619 Index: busybox-1.7.2/archival/libunarchive/Kbuild
13620 ===================================================================
13621 --- busybox-1.7.2.orig/archival/libunarchive/Kbuild 2007-10-30 15:34:59.000000000 -0500
13622 +++ busybox-1.7.2/archival/libunarchive/Kbuild 2007-10-30 15:35:05.000000000 -0500
13623 @@ -55,6 +55,7 @@
13624 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13625 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13626 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13627 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13628 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13629 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13630 lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
13631 Index: busybox-1.7.2/include/applets.h
13632 ===================================================================
13633 --- busybox-1.7.2.orig/include/applets.h 2007-10-30 15:35:03.000000000 -0500
13634 +++ busybox-1.7.2/include/applets.h 2007-10-30 15:35:05.000000000 -0500
13635 @@ -190,6 +190,7 @@
13636 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13637 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13638 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13639 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13640 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13641 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13642 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13643 Index: busybox-1.7.2/include/unarchive.h
13644 ===================================================================
13645 --- busybox-1.7.2.orig/include/unarchive.h 2007-10-30 15:34:59.000000000 -0500
13646 +++ busybox-1.7.2/include/unarchive.h 2007-10-30 15:35:05.000000000 -0500
13647 @@ -74,6 +74,7 @@
13648
13649 extern void data_skip(archive_handle_t *archive_handle);
13650 extern void data_extract_all(archive_handle_t *archive_handle);
13651 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13652 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13653 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13654
13655 Index: busybox-1.7.2/include/usage.h
13656 ===================================================================
13657 --- busybox-1.7.2.orig/include/usage.h 2007-10-30 15:35:03.000000000 -0500
13658 +++ busybox-1.7.2/include/usage.h 2007-10-30 15:35:05.000000000 -0500
13659 @@ -1226,6 +1226,82 @@
13660 "$ ls -la /tmp/busybox*\n" \
13661 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13662
13663 +#define ipkg_trivial_usage \
13664 + "[options]... sub-command [arguments]..."
13665 +#define ipkg_full_usage \
13666 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13667 + "\n" \
13668 + "Sub-commands:\n" \
13669 + "\nPackage Manipulation:\n" \
13670 + "\tupdate Update list of available packages\n" \
13671 + "\tupgrade Upgrade all installed packages to latest version\n" \
13672 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13673 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13674 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13675 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13676 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13677 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13678 + "\n" \
13679 + "Informational Commands:\n" \
13680 + "\tlist List available packages and descriptions\n" \
13681 + "\tlist_installed List all and only the installed packages and description \n" \
13682 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13683 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13684 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13685 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13686 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13687 + "\tcompare_versions <v1> <op> <v2>\n" \
13688 + "\t compare versions using <= < > >= = << >>\n" \
13689 + "\tprint_architecture prints the architecture.\n" \
13690 + "\tprint_installation_architecture\n" \
13691 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13692 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13693 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13694 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13695 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13696 + "\t prints the installation architecture.\n" \
13697 + "\n" \
13698 + "\nOptions:\n" \
13699 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13700 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13701 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13702 + "\t 0 errors only\n" \
13703 + "\t 1 normal messages (default)\n" \
13704 + "\t 2 informative messages\n" \
13705 + "\t 3 debug output\n" \
13706 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13707 + "\t-conf <conf_file> Default configuration file location\n" \
13708 + " is /etc/ipkg.conf\n" \
13709 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13710 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13711 + " <dest_name> should be a defined dest name from\n" \
13712 + " the configuration file, (but can also be a\n" \
13713 + " directory name in a pinch).\n" \
13714 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13715 + "\t-offline <offline_root> offline installation of packages.\n" \
13716 + "\t-verbose_wget more wget messages\n" \
13717 + "\n" \
13718 + "Force Options (use when ipkg is too smart for its own good):\n" \
13719 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13720 + "\t Install/remove package in spite of failed dependences\n" \
13721 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13722 + " (no prompts). Note that this will not prevent\n" \
13723 + " package installation scripts from prompting.\n" \
13724 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13725 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13726 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13727 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13728 + "\t-noaction No action -- test only\n" \
13729 + "\t-nodeps Do not follow dependences\n" \
13730 + "\t-force-removal-of-dependent-packages\n" \
13731 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13732 + "\t-test No action -- test only\n" \
13733 + "\t-t Specify tmp-dir.\n" \
13734 + "\t--tmp-dir Specify tmp-dir.\n" \
13735 + "\n" \
13736 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13737 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13738 +
13739 #define halt_trivial_usage \
13740 "[-d delay] [-n] [-f]"
13741 #define halt_full_usage \
13742 Index: busybox-1.7.2/Makefile
13743 ===================================================================
13744 --- busybox-1.7.2.orig/Makefile 2007-10-30 15:34:59.000000000 -0500
13745 +++ busybox-1.7.2/Makefile 2007-10-30 15:35:05.000000000 -0500
13746 @@ -428,6 +428,7 @@
13747
13748 libs-y := \
13749 archival/ \
13750 + archival/libipkg/ \
13751 archival/libunarchive/ \
13752 console-tools/ \
13753 coreutils/ \