add an abs2rel.pl helper script (returns a path relative to another)
[openwrt.git] / package / busybox / patches / 911-ipkg.patch
1 Index: busybox-1.4.2/archival/Config.in
2 ===================================================================
3 --- busybox-1.4.2.orig/archival/Config.in 2007-06-04 13:21:31.573176816 +0200
4 +++ busybox-1.4.2/archival/Config.in 2007-06-04 13:21:36.706396448 +0200
5 @@ -121,6 +121,14 @@
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 + help
15 + ipkg is the itsy package management system.
16 +
17 config RPM2CPIO
18 bool "rpm2cpio"
19 default n
20 Index: busybox-1.4.2/archival/dpkg.c
21 ===================================================================
22 --- busybox-1.4.2.orig/archival/dpkg.c 2007-06-04 13:21:31.579175904 +0200
23 +++ busybox-1.4.2/archival/dpkg.c 2007-06-04 13:21:36.706396448 +0200
24 @@ -1463,6 +1463,10 @@
25 return ar_handle->sub_archive->buffer;
26 }
27
28 +/*
29 +
30 +// moved to data_extract_all.c
31 +
32 static void data_extract_all_prefix(archive_handle_t *archive_handle)
33 {
34 char *name_ptr = archive_handle->file_header->name;
35 @@ -1475,6 +1479,8 @@
36 return;
37 }
38
39 +*/
40 +
41 static void unpack_package(deb_file_t *deb_file)
42 {
43 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
44 Index: busybox-1.4.2/archival/ipkg.c
45 ===================================================================
46 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
47 +++ busybox-1.4.2/archival/ipkg.c 2007-06-04 13:21:36.707396296 +0200
48 @@ -0,0 +1,26 @@
49 +/* ipkg.c - the itsy package management system
50 +
51 + Florina Boor
52 +
53 + Copyright (C) 2003 kernel concepts
54 +
55 + This program is free software; you can redistribute it and/or
56 + modify it under the terms of the GNU General Public License as
57 + published by the Free Software Foundation; either version 2, or (at
58 + your option) any later version.
59 +
60 + This program is distributed in the hope that it will be useful, but
61 + WITHOUT ANY WARRANTY; without even the implied warranty of
62 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63 + General Public License for more details.
64 +
65 + ipkg command line frontend using libipkg
66 +
67 +*/
68 +
69 +#include "libipkg/libipkg.h"
70 +
71 +int ipkg_main(int argc, char **argv)
72 +{
73 + return ipkg_op(argc, argv);
74 +}
75 Index: busybox-1.4.2/archival/Kbuild
76 ===================================================================
77 --- busybox-1.4.2.orig/archival/Kbuild 2007-06-04 13:21:31.588174536 +0200
78 +++ busybox-1.4.2/archival/Kbuild 2007-06-04 13:21:36.707396296 +0200
79 @@ -15,6 +15,7 @@
80 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
81 lib-$(CONFIG_GUNZIP) += gunzip.o
82 lib-$(CONFIG_GZIP) += gzip.o
83 +lib-$(CONFIG_IPKG) += ipkg.o
84 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
85 lib-$(CONFIG_RPM) += rpm.o
86 lib-$(CONFIG_TAR) += tar.o
87 Index: busybox-1.4.2/archival/libipkg/args.c
88 ===================================================================
89 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
90 +++ busybox-1.4.2/archival/libipkg/args.c 2007-06-04 13:21:36.707396296 +0200
91 @@ -0,0 +1,242 @@
92 +/* args.c - parse command-line args
93 +
94 + Carl D. Worth
95 +
96 + Copyright 2001 University of Southern California
97 +
98 + This program is free software; you can redistribute it and/or modify
99 + it under the terms of the GNU General Public License as published by
100 + the Free Software Foundation; either version 2, or (at your option)
101 + any later version.
102 +
103 + This program is distributed in the hope that it will be useful,
104 + but WITHOUT ANY WARRANTY; without even the implied warranty of
105 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106 + GNU General Public License for more details.
107 + */
108 +
109 +#include <getopt.h>
110 +#include <stdlib.h>
111 +#include <string.h>
112 +#include <unistd.h>
113 +
114 +#include "ipkg.h"
115 +#include "ipkg_message.h"
116 +
117 +#include "args.h"
118 +#include "sprintf_alloc.h"
119 +
120 +#include "libbb.h"
121 +
122 +
123 +static void print_version(void);
124 +
125 +enum long_args_opt
126 +{
127 + ARGS_OPT_FORCE_DEFAULTS = 129,
128 + ARGS_OPT_FORCE_DEPENDS,
129 + ARGS_OPT_FORCE_OVERWRITE,
130 + ARGS_OPT_FORCE_DOWNGRADE,
131 + ARGS_OPT_FORCE_REINSTALL,
132 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
133 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
134 + ARGS_OPT_FORCE_SPACE,
135 + ARGS_OPT_NOACTION,
136 + ARGS_OPT_NODEPS,
137 + ARGS_OPT_VERBOSE_WGET,
138 + ARGS_OPT_VERBOSITY,
139 + ARGS_OPT_MULTIPLE_PROVIDERS
140 +};
141 +
142 +int args_init(args_t *args)
143 +{
144 + char *conf_file_dir;
145 +
146 + memset(args, 0, sizeof(args_t));
147 +
148 + args->dest = ARGS_DEFAULT_DEST;
149 +
150 + conf_file_dir = getenv("IPKG_CONF_DIR");
151 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
152 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
153 + }
154 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
155 + ARGS_DEFAULT_CONF_FILE_NAME);
156 +
157 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
158 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
159 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
160 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
161 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
162 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
163 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
164 + args->noaction = ARGS_DEFAULT_NOACTION;
165 + args->nodeps = ARGS_DEFAULT_NODEPS;
166 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
167 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
168 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
169 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
170 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
171 + args->multiple_providers = 0;
172 + args->nocheckfordirorfile = 0;
173 + args->noreadfeedsfile = 0;
174 +
175 + return 1;
176 +}
177 +
178 +void args_deinit(args_t *args)
179 +{
180 + free(args->conf_file);
181 + args->conf_file = NULL;
182 +}
183 +
184 +int args_parse(args_t *args, int argc, char *argv[])
185 +{
186 + int c;
187 + int option_index = 0;
188 + int parse_err = 0;
189 + static struct option long_options[] = {
190 + {"query-all", 0, 0, 'A'},
191 + {"conf-file", 1, 0, 'f'},
192 + {"conf", 1, 0, 'f'},
193 + {"dest", 1, 0, 'd'},
194 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
195 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
196 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
197 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
198 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
199 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
200 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
201 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
202 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
203 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
204 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
205 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
206 + {"recursive", 0, 0,
207 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
208 + {"force-removal-of-dependent-packages", 0, 0,
209 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
210 + {"force_removal_of_dependent_packages", 0, 0,
211 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
212 + {"force-removal-of-essential-packages", 0, 0,
213 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
214 + {"force_removal_of_essential_packages", 0, 0,
215 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
216 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
217 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
218 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
219 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
220 + {"offline", 1, 0, 'o'},
221 + {"offline-root", 1, 0, 'o'},
222 + {"test", 0, 0, ARGS_OPT_NOACTION},
223 + {"tmp-dir", 1, 0, 't'},
224 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
225 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
226 + {"verbosity", 2, 0, 'V'},
227 + {"version", 0, 0, 'v'},
228 + {0, 0, 0, 0}
229 + };
230 +
231 + while (1) {
232 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
233 + if (c == -1)
234 + break;
235 +
236 + switch (c) {
237 + case 'A':
238 + args->query_all = 1;
239 + break;
240 + case 'd':
241 + args->dest = optarg;
242 + break;
243 + case 'f':
244 + free(args->conf_file);
245 + args->conf_file = strdup(optarg);
246 + break;
247 + case 'o':
248 + args->offline_root = optarg;
249 + break;
250 + case 'n':
251 + args->noaction = 1;
252 + break;
253 + case 't':
254 + args->tmp_dir = strdup(optarg);
255 + break;
256 + case 'v':
257 + print_version();
258 + exit(0);
259 + case 'V':
260 + case ARGS_OPT_VERBOSITY:
261 + if (optarg)
262 + args->verbosity = atoi(optarg);
263 + else
264 + args->verbosity += 1;
265 + break;
266 + case ARGS_OPT_FORCE_DEFAULTS:
267 + args->force_defaults = 1;
268 + break;
269 + case ARGS_OPT_FORCE_DEPENDS:
270 + args->force_depends = 1;
271 + break;
272 + case ARGS_OPT_FORCE_OVERWRITE:
273 + args->force_overwrite = 1;
274 + break;
275 + case ARGS_OPT_FORCE_DOWNGRADE:
276 + args->force_downgrade = 1;
277 + break;
278 + case ARGS_OPT_FORCE_REINSTALL:
279 + args->force_reinstall = 1;
280 + break;
281 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
282 + args->force_removal_of_essential_packages = 1;
283 + break;
284 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
285 + args->force_removal_of_dependent_packages = 1;
286 + break;
287 + case ARGS_OPT_FORCE_SPACE:
288 + args->force_space = 1;
289 + break;
290 + case ARGS_OPT_VERBOSE_WGET:
291 + args->verbose_wget = 1;
292 + break;
293 + case ARGS_OPT_MULTIPLE_PROVIDERS:
294 + args->multiple_providers = 1;
295 + break;
296 + case ARGS_OPT_NODEPS:
297 + args->nodeps = 1;
298 + break;
299 + case ARGS_OPT_NOACTION:
300 + args->noaction = 1;
301 + break;
302 + case ':':
303 + parse_err++;
304 + break;
305 + case '?':
306 + parse_err++;
307 + break;
308 + default:
309 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
310 + }
311 + }
312 +
313 + if (parse_err) {
314 + return -parse_err;
315 + } else {
316 + return optind;
317 + }
318 +}
319 +
320 +void args_usage(char *complaint)
321 +{
322 + if (complaint) {
323 + bb_error_msg("%s\n", complaint);
324 + }
325 + print_version();
326 + bb_show_usage();
327 + exit(1);
328 +}
329 +
330 +static void print_version(void)
331 +{
332 + bb_error_msg("version %s\n", IPKG_VERSION);
333 +}
334 Index: busybox-1.4.2/archival/libipkg/args.h
335 ===================================================================
336 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
337 +++ busybox-1.4.2/archival/libipkg/args.h 2007-06-04 13:21:36.707396296 +0200
338 @@ -0,0 +1,72 @@
339 +/* args.h - parse command-line args
340 +
341 + Carl D. Worth
342 +
343 + Copyright 2001 University of Southern California
344 +
345 + This program is free software; you can redistribute it and/or modify
346 + it under the terms of the GNU General Public License as published by
347 + the Free Software Foundation; either version 2, or (at your option)
348 + any later version.
349 +
350 + This program is distributed in the hope that it will be useful,
351 + but WITHOUT ANY WARRANTY; without even the implied warranty of
352 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
353 + GNU General Public License for more details.
354 +*/
355 +
356 +#ifndef ARGS_H
357 +#define ARGS_H
358 +
359 +struct args
360 +{
361 + char *conf_file;
362 + char *dest;
363 + char *tmp_dir;
364 + int force_defaults;
365 + int force_depends;
366 + int force_overwrite;
367 + int force_downgrade;
368 + int force_reinstall;
369 + int force_removal_of_essential_packages;
370 + int force_removal_of_dependent_packages;
371 + int force_space;
372 + int noaction;
373 + int nodeps;
374 + int multiple_providers;
375 + int query_all;
376 + int verbose_wget;
377 + int verbosity;
378 + int nocheckfordirorfile;
379 + int noreadfeedsfile;
380 + char *offline_root;
381 + char *offline_root_pre_script_cmd;
382 + char *offline_root_post_script_cmd;
383 +};
384 +typedef struct args args_t;
385 +
386 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
387 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
388 +#define ARGS_DEFAULT_DEST NULL
389 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
390 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
391 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
392 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
393 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
394 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
395 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
396 +#define ARGS_DEFAULT_FORCE_SPACE 0
397 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
398 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
399 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
400 +#define ARGS_DEFAULT_NOACTION 0
401 +#define ARGS_DEFAULT_NODEPS 0
402 +#define ARGS_DEFAULT_VERBOSE_WGET 0
403 +#define ARGS_DEFAULT_VERBOSITY 1
404 +
405 +int args_init(args_t *args);
406 +void args_deinit(args_t *args);
407 +int args_parse(args_t *args, int argc, char *argv[]);
408 +void args_usage(char *complaint);
409 +
410 +#endif
411 Index: busybox-1.4.2/archival/libipkg/conffile.c
412 ===================================================================
413 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
414 +++ busybox-1.4.2/archival/libipkg/conffile.c 2007-06-04 13:21:36.708396144 +0200
415 @@ -0,0 +1,64 @@
416 +/* conffile.c - the itsy package management system
417 +
418 + Carl D. Worth
419 +
420 + Copyright (C) 2001 University of Southern California
421 +
422 + This program is free software; you can redistribute it and/or
423 + modify it under the terms of the GNU General Public License as
424 + published by the Free Software Foundation; either version 2, or (at
425 + your option) any later version.
426 +
427 + This program is distributed in the hope that it will be useful, but
428 + WITHOUT ANY WARRANTY; without even the implied warranty of
429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
430 + General Public License for more details.
431 +*/
432 +
433 +#include <string.h>
434 +#include <stdlib.h>
435 +
436 +#include "ipkg.h"
437 +#include "ipkg_message.h"
438 +
439 +#include "conffile.h"
440 +#include "file_util.h"
441 +#include "sprintf_alloc.h"
442 +
443 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
444 +{
445 + return nv_pair_init(conffile, file_name, md5sum);
446 +}
447 +
448 +void conffile_deinit(conffile_t *conffile)
449 +{
450 + nv_pair_deinit(conffile);
451 +}
452 +
453 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
454 +{
455 + char *md5sum;
456 + char *filename = conffile->name;
457 + char *root_filename;
458 + int ret;
459 +
460 + if (conffile->value == NULL) {
461 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
462 + return 1;
463 + }
464 +
465 + root_filename = root_filename_alloc(conf, filename);
466 +
467 + md5sum = file_md5sum_alloc(root_filename);
468 +
469 + ret = strcmp(md5sum, conffile->value);
470 + if (ret) {
471 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
472 + conffile->name, md5sum, conffile->value);
473 + }
474 +
475 + free(root_filename);
476 + free(md5sum);
477 +
478 + return ret;
479 +}
480 Index: busybox-1.4.2/archival/libipkg/conffile.h
481 ===================================================================
482 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
483 +++ busybox-1.4.2/archival/libipkg/conffile.h 2007-06-04 13:21:36.708396144 +0200
484 @@ -0,0 +1,30 @@
485 +/* conffile.h - the itsy package management system
486 +
487 + Carl D. Worth
488 +
489 + Copyright (C) 2001 University of Southern California
490 +
491 + This program is free software; you can redistribute it and/or
492 + modify it under the terms of the GNU General Public License as
493 + published by the Free Software Foundation; either version 2, or (at
494 + your option) any later version.
495 +
496 + This program is distributed in the hope that it will be useful, but
497 + WITHOUT ANY WARRANTY; without even the implied warranty of
498 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
499 + General Public License for more details.
500 +*/
501 +
502 +#ifndef CONFFILE_H
503 +#define CONFFILE_H
504 +
505 +#include "nv_pair.h"
506 +
507 +typedef struct nv_pair conffile_t;
508 +
509 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
510 +void conffile_deinit(conffile_t *conffile);
511 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
512 +
513 +#endif
514 +
515 Index: busybox-1.4.2/archival/libipkg/conffile_list.c
516 ===================================================================
517 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
518 +++ busybox-1.4.2/archival/libipkg/conffile_list.c 2007-06-04 13:21:36.708396144 +0200
519 @@ -0,0 +1,47 @@
520 +/* conffile_list.c - the itsy package management system
521 +
522 + Carl D. Worth
523 +
524 + Copyright (C) 2001 University of Southern California
525 +
526 + This program is free software; you can redistribute it and/or
527 + modify it under the terms of the GNU General Public License as
528 + published by the Free Software Foundation; either version 2, or (at
529 + your option) any later version.
530 +
531 + This program is distributed in the hope that it will be useful, but
532 + WITHOUT ANY WARRANTY; without even the implied warranty of
533 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
534 + General Public License for more details.
535 +*/
536 +
537 +#include "ipkg.h"
538 +
539 +#include "conffile_list.h"
540 +
541 +int conffile_list_init(conffile_list_t *list)
542 +{
543 + return nv_pair_list_init(list);
544 +}
545 +
546 +void conffile_list_deinit(conffile_list_t *list)
547 +{
548 + nv_pair_list_deinit(list);
549 +}
550 +
551 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
552 + const char *md5sum)
553 +{
554 + return nv_pair_list_append(list, file_name, md5sum);
555 +}
556 +
557 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
558 +{
559 + return nv_pair_list_push(list, data);
560 +}
561 +
562 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
563 +{
564 + return nv_pair_list_pop(list);
565 +}
566 +
567 Index: busybox-1.4.2/archival/libipkg/conffile_list.h
568 ===================================================================
569 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
570 +++ busybox-1.4.2/archival/libipkg/conffile_list.h 2007-06-04 13:21:36.708396144 +0200
571 @@ -0,0 +1,36 @@
572 +/* conffile_list.h - the itsy package management system
573 +
574 + Carl D. Worth
575 +
576 + Copyright (C) 2001 University of Southern California
577 +
578 + This program is free software; you can redistribute it and/or
579 + modify it under the terms of the GNU General Public License as
580 + published by the Free Software Foundation; either version 2, or (at
581 + your option) any later version.
582 +
583 + This program is distributed in the hope that it will be useful, but
584 + WITHOUT ANY WARRANTY; without even the implied warranty of
585 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
586 + General Public License for more details.
587 +*/
588 +
589 +#ifndef CONFFILE_LIST_H
590 +#define CONFFILE_LIST_H
591 +
592 +#include "conffile.h"
593 +#include "nv_pair_list.h"
594 +
595 +typedef struct nv_pair_list_elt conffile_list_elt_t;
596 +typedef struct nv_pair_list conffile_list_t;
597 +
598 +int conffile_list_init(conffile_list_t *list);
599 +void conffile_list_deinit(conffile_list_t *list);
600 +
601 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
602 + const char *root_dir);
603 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
604 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
605 +
606 +#endif
607 +
608 Index: busybox-1.4.2/archival/libipkg/file_util.c
609 ===================================================================
610 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
611 +++ busybox-1.4.2/archival/libipkg/file_util.c 2007-06-04 13:21:36.708396144 +0200
612 @@ -0,0 +1,132 @@
613 +/* file_util.c - convenience routines for common stat operations
614 +
615 + Carl D. Worth
616 +
617 + Copyright (C) 2001 University of Southern California
618 +
619 + This program is free software; you can redistribute it and/or
620 + modify it under the terms of the GNU General Public License as
621 + published by the Free Software Foundation; either version 2, or (at
622 + your option) any later version.
623 +
624 + This program is distributed in the hope that it will be useful, but
625 + WITHOUT ANY WARRANTY; without even the implied warranty of
626 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
627 + General Public License for more details.
628 +*/
629 +
630 +#include "ipkg.h"
631 +#include <sys/types.h>
632 +#include <sys/stat.h>
633 +
634 +#include "sprintf_alloc.h"
635 +#include "file_util.h"
636 +#include "libbb.h"
637 +#undef strlen
638 +
639 +int file_exists(const char *file_name)
640 +{
641 + int err;
642 + struct stat stat_buf;
643 +
644 + err = stat(file_name, &stat_buf);
645 + if (err == 0) {
646 + return 1;
647 + } else {
648 + return 0;
649 + }
650 +}
651 +
652 +int file_is_dir(const char *file_name)
653 +{
654 + int err;
655 + struct stat stat_buf;
656 +
657 + err = stat(file_name, &stat_buf);
658 + if (err) {
659 + return 0;
660 + }
661 +
662 + return S_ISDIR(stat_buf.st_mode);
663 +}
664 +
665 +/* read a single line from a file, stopping at a newline or EOF.
666 + If a newline is read, it will appear in the resulting string.
667 + Return value is a malloc'ed char * which should be freed at
668 + some point by the caller.
669 +
670 + Return value is NULL if the file is at EOF when called.
671 +*/
672 +#define FILE_READ_LINE_BUF_SIZE 1024
673 +char *file_read_line_alloc(FILE *file)
674 +{
675 + char buf[FILE_READ_LINE_BUF_SIZE];
676 + int buf_len;
677 + char *line = NULL;
678 + int line_size = 0;
679 +
680 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
681 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
682 + buf_len = strlen(buf);
683 + if (line) {
684 + line_size += buf_len;
685 + line = realloc(line, line_size);
686 + if (line == NULL) {
687 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
688 + break;
689 + }
690 + strcat(line, buf);
691 + } else {
692 + line_size = buf_len + 1;
693 + line = strdup(buf);
694 + }
695 + if (buf[buf_len - 1] == '\n') {
696 + break;
697 + }
698 + }
699 +
700 + return line;
701 +}
702 +
703 +int file_move(const char *src, const char *dest)
704 +{
705 + int err;
706 +
707 + err = rename(src, dest);
708 +
709 + if (err && errno == EXDEV) {
710 + err = file_copy(src, dest);
711 + unlink(src);
712 + } else if (err) {
713 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
714 + __FUNCTION__, src, dest, strerror(errno));
715 + }
716 +
717 + return err;
718 +}
719 +
720 +/* I put these here to keep libbb dependencies from creeping all over
721 + the ipkg code */
722 +int file_copy(const char *src, const char *dest)
723 +{
724 + int err;
725 +
726 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
727 + if (err) {
728 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
729 + __FUNCTION__, src, dest);
730 + }
731 +
732 + return err;
733 +}
734 +
735 +int file_mkdir_hier(const char *path, long mode)
736 +{
737 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
738 +}
739 +
740 +char *file_md5sum_alloc(const char *file_name)
741 +{
742 + return hash_file(file_name, HASH_MD5);
743 +}
744 +
745 Index: busybox-1.4.2/archival/libipkg/file_util.h
746 ===================================================================
747 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
748 +++ busybox-1.4.2/archival/libipkg/file_util.h 2007-06-04 13:21:36.708396144 +0200
749 @@ -0,0 +1,29 @@
750 +/* file_util.h - convenience routines for common file operations
751 +
752 + Carl D. Worth
753 +
754 + Copyright (C) 2001 University of Southern California
755 +
756 + This program is free software; you can redistribute it and/or
757 + modify it under the terms of the GNU General Public License as
758 + published by the Free Software Foundation; either version 2, or (at
759 + your option) any later version.
760 +
761 + This program is distributed in the hope that it will be useful, but
762 + WITHOUT ANY WARRANTY; without even the implied warranty of
763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
764 + General Public License for more details.
765 +*/
766 +
767 +#ifndef FILE_UTIL_H
768 +#define FILE_UTIL_H
769 +
770 +int file_exists(const char *file_name);
771 +int file_is_dir(const char *file_name);
772 +char *file_read_line_alloc(FILE *file);
773 +int file_move(const char *src, const char *dest);
774 +int file_copy(const char *src, const char *dest);
775 +int file_mkdir_hier(const char *path, long mode);
776 +char *file_md5sum_alloc(const char *file_name);
777 +
778 +#endif
779 Index: busybox-1.4.2/archival/libipkg/hash_table.c
780 ===================================================================
781 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
782 +++ busybox-1.4.2/archival/libipkg/hash_table.c 2007-06-04 13:21:36.709395992 +0200
783 @@ -0,0 +1,155 @@
784 +/* hash.c - hash tables for ipkg
785 +
786 + Steven M. Ayer, Jamey Hicks
787 +
788 + Copyright (C) 2002 Compaq Computer Corporation
789 +
790 + This program is free software; you can redistribute it and/or
791 + modify it under the terms of the GNU General Public License as
792 + published by the Free Software Foundation; either version 2, or (at
793 + your option) any later version.
794 +
795 + This program is distributed in the hope that it will be useful, but
796 + WITHOUT ANY WARRANTY; without even the implied warranty of
797 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
798 + General Public License for more details.
799 +*/
800 +
801 +#include <errno.h>
802 +#include <stdio.h>
803 +#include <stdlib.h>
804 +#include <string.h>
805 +#include "hash_table.h"
806 +#include "ipkg_message.h"
807 +
808 +
809 +static int hash_index(hash_table_t *hash, const char *pkg_name);
810 +static int rotating(const char *key, int len, int prime);
811 +
812 +static int hash_index(hash_table_t *hash, const char *pkg_name)
813 +{
814 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
815 +}
816 +
817 +static int rotating(const char *key, int len, int prime)
818 +{
819 + unsigned int hash, i;
820 + for (hash=len, i=0; i<len; ++i)
821 + hash = (hash<<4)^(hash>>28)^key[i];
822 + return (hash % prime);
823 +}
824 +
825 +
826 +/*
827 + * this is an open table keyed by strings
828 + */
829 +int hash_table_init(const char *name, hash_table_t *hash, int len)
830 +{
831 + static int primes_table[] = {
832 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
833 + 19471, 23143, 33961, 46499, 49727, 99529, 0
834 + };
835 + int *picker;
836 +
837 + if (hash->entries != NULL) {
838 + /* we have been here already */
839 + return 0;
840 + }
841 +
842 + hash->name = name;
843 + hash->entries = NULL;
844 + hash->n_entries = 0;
845 + hash->hash_entry_key = NULL;
846 +
847 + picker = primes_table;
848 + while(*picker && (*picker++ < len));
849 + if(!*picker)
850 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
851 + --picker;
852 +
853 + hash->n_entries = *picker;
854 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
855 + if (hash->entries == NULL) {
856 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
857 + return ENOMEM;
858 + }
859 + return 0;
860 +}
861 +
862 +void hash_table_deinit(hash_table_t *hash)
863 +{
864 + free(hash->entries);
865 + hash->entries = NULL;
866 + hash->n_entries = 0;
867 +}
868 +
869 +void *hash_table_get(hash_table_t *hash, const char *key)
870 +{
871 + int ndx= hash_index(hash, key);
872 + hash_entry_t *hash_entry = hash->entries + ndx;
873 + while (hash_entry)
874 + {
875 + if (hash_entry->key)
876 + {
877 + if (strcmp(key, hash_entry->key) == 0) {
878 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
879 + return hash_entry->data;
880 + }
881 + }
882 + hash_entry = hash_entry->next;
883 + }
884 + return NULL;
885 +}
886 +
887 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
888 +{
889 + int ndx= hash_index(hash, key);
890 + hash_entry_t *hash_entry = hash->entries + ndx;
891 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
892 + if (hash_entry->key) {
893 + if (strcmp(hash_entry->key, key) == 0) {
894 + /* alread in table, update the value */
895 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
896 + hash_entry->data = value;
897 + return 0;
898 + } else {
899 + /*
900 + * if this is a collision, we have to go to the end of the ll,
901 + * then add a new entry
902 + * before we can hook up the value
903 + */
904 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
905 + while (hash_entry->next)
906 + hash_entry = hash_entry->next;
907 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
908 + if (!hash_entry->next) {
909 + return -ENOMEM;
910 + }
911 + hash_entry = hash_entry->next;
912 + hash_entry->next = NULL;
913 + }
914 + }
915 + hash->n_elements++;
916 + hash_entry->key = strdup(key);
917 + hash_entry->data = value;
918 +
919 + return 0;
920 +}
921 +
922 +
923 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
924 +{
925 + int i;
926 + if (!hash || !f)
927 + return;
928 +
929 + for (i = 0; i < hash->n_entries; i++) {
930 + hash_entry_t *hash_entry = (hash->entries + i);
931 + do {
932 + if(hash_entry->key) {
933 + f(hash_entry->key, hash_entry->data, data);
934 + }
935 + } while((hash_entry = hash_entry->next));
936 + }
937 +}
938 +
939 Index: busybox-1.4.2/archival/libipkg/hash_table.h
940 ===================================================================
941 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
942 +++ busybox-1.4.2/archival/libipkg/hash_table.h 2007-06-04 13:21:36.709395992 +0200
943 @@ -0,0 +1,44 @@
944 +/* hash.h - hash tables for ipkg
945 +
946 + Steven M. Ayer, Jamey Hicks
947 +
948 + Copyright (C) 2002 Compaq Computer Corporation
949 +
950 + This program is free software; you can redistribute it and/or
951 + modify it under the terms of the GNU General Public License as
952 + published by the Free Software Foundation; either version 2, or (at
953 + your option) any later version.
954 +
955 + This program is distributed in the hope that it will be useful, but
956 + WITHOUT ANY WARRANTY; without even the implied warranty of
957 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
958 + General Public License for more details.
959 +*/
960 +
961 +#ifndef _HASH_TABLE_H_
962 +#define _HASH_TABLE_H_
963 +
964 +typedef struct hash_entry hash_entry_t;
965 +typedef struct hash_table hash_table_t;
966 +
967 +struct hash_entry {
968 + const char * key;
969 + void * data;
970 + struct hash_entry * next;
971 +};
972 +
973 +struct hash_table {
974 + const char *name;
975 + hash_entry_t * entries;
976 + int n_entries; /* number of buckets */
977 + int n_elements;
978 + const char * (*hash_entry_key)(void * data);
979 +};
980 +
981 +int hash_table_init(const char *name, hash_table_t *hash, int len);
982 +void hash_table_deinit(hash_table_t *hash);
983 +void *hash_table_get(hash_table_t *hash, const char *key);
984 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
985 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
986 +
987 +#endif /* _HASH_TABLE_H_ */
988 Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.c
989 ===================================================================
990 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
991 +++ busybox-1.4.2/archival/libipkg/ipkg_cmd.c 2007-06-04 13:21:36.710395840 +0200
992 @@ -0,0 +1,1431 @@
993 +/* ipkg_cmd.c - the itsy package management system
994 +
995 + Carl D. Worth
996 +
997 + Copyright (C) 2001 University of Southern California
998 +
999 + This program is free software; you can redistribute it and/or
1000 + modify it under the terms of the GNU General Public License as
1001 + published by the Free Software Foundation; either version 2, or (at
1002 + your option) any later version.
1003 +
1004 + This program is distributed in the hope that it will be useful, but
1005 + WITHOUT ANY WARRANTY; without even the implied warranty of
1006 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1007 + General Public License for more details.
1008 +*/
1009 +
1010 +#include <string.h>
1011 +
1012 +#include "ipkg.h"
1013 +#include <libgen.h>
1014 +#include <glob.h>
1015 +#include <errno.h>
1016 +#include <stdlib.h>
1017 +#include <unistd.h>
1018 +#include <signal.h>
1019 +#include <stdio.h>
1020 +#include <dirent.h>
1021 +
1022 +#include "ipkg_conf.h"
1023 +#include "ipkg_cmd.h"
1024 +#include "ipkg_message.h"
1025 +#include "pkg.h"
1026 +#include "pkg_dest.h"
1027 +#include "pkg_parse.h"
1028 +#include "sprintf_alloc.h"
1029 +#include "pkg.h"
1030 +#include "file_util.h"
1031 +#include "str_util.h"
1032 +#include "libbb.h"
1033 +#include "unarchive.h"
1034 +
1035 +#include <fnmatch.h>
1036 +
1037 +
1038 +#include "ipkg_download.h"
1039 +#include "ipkg_install.h"
1040 +#include "ipkg_upgrade.h"
1041 +#include "ipkg_remove.h"
1042 +#include "ipkg_configure.h"
1043 +#include "ipkg_message.h"
1044 +
1045 +#ifdef IPKG_LIB
1046 +#include "libipkg.h"
1047 +static void *p_userdata = NULL;
1048 +#endif
1049 +
1050 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1051 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1052 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +
1076 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1077 + array for easier maintenance */
1078 +static ipkg_cmd_t cmds[] = {
1079 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1080 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1081 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1082 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1083 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1084 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1085 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1086 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1087 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1088 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1089 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1090 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1091 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1092 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1093 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1094 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1095 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1096 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1097 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1098 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1101 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1102 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1103 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1104 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1105 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1106 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1107 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1108 +};
1109 +
1110 +int ipkg_state_changed;
1111 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1112 +{
1113 + if (ipkg_state_changed && !conf->noaction) {
1114 + ipkg_message(conf, IPKG_INFO,
1115 + " writing status file\n");
1116 + ipkg_conf_write_status_files(conf);
1117 + pkg_write_changed_filelists(conf);
1118 + } else {
1119 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1120 + }
1121 +}
1122 +
1123 +
1124 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1125 +
1126 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1127 +{
1128 + int i;
1129 + ipkg_cmd_t *cmd;
1130 +
1131 + for (i=0; i < num_cmds; i++) {
1132 + cmd = &cmds[i];
1133 + if (strcmp(name, cmd->name) == 0) {
1134 + return cmd;
1135 + }
1136 + }
1137 +
1138 + return NULL;
1139 +}
1140 +
1141 +#ifdef IPKG_LIB
1142 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1143 +{
1144 + int result;
1145 + p_userdata = userdata;
1146 +
1147 +
1148 + result = (cmd->fun)(conf, argc, argv);
1149 + if ( result == 0 ) {
1150 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1151 + } else {
1152 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1153 +
1154 + }
1155 + if ( error_list ) {
1156 + reverse_error_list(&error_list);
1157 +
1158 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1159 + /* Here we print the errors collected and free the list */
1160 + while (error_list != NULL) {
1161 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1162 + error_list = error_list->next;
1163 +
1164 + }
1165 + free_error_list(&error_list);
1166 +
1167 + }
1168 +
1169 + p_userdata = NULL;
1170 + return result;
1171 +}
1172 +#else
1173 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1174 +{
1175 + return (cmd->fun)(conf, argc, argv);
1176 +}
1177 +#endif
1178 +
1179 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1180 +{
1181 + int err;
1182 + int failures;
1183 + char *lists_dir;
1184 + pkg_src_list_elt_t *iter;
1185 + pkg_src_t *src;
1186 +
1187 +
1188 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1189 +
1190 + if (! file_is_dir(lists_dir)) {
1191 + if (file_exists(lists_dir)) {
1192 + ipkg_message(conf, IPKG_ERROR,
1193 + "%s: ERROR: %s exists, but is not a directory\n",
1194 + __FUNCTION__, lists_dir);
1195 + free(lists_dir);
1196 + return EINVAL;
1197 + }
1198 + err = file_mkdir_hier(lists_dir, 0755);
1199 + if (err) {
1200 + ipkg_message(conf, IPKG_ERROR,
1201 + "%s: ERROR: failed to make directory %s: %s\n",
1202 + __FUNCTION__, lists_dir, strerror(errno));
1203 + free(lists_dir);
1204 + return EINVAL;
1205 + }
1206 + }
1207 +
1208 + failures = 0;
1209 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1210 + char *url, *list_file_name;
1211 +
1212 + src = iter->data;
1213 +
1214 + if (src->extra_data) /* debian style? */
1215 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1216 + src->gzip ? "Packages.gz" : "Packages");
1217 + else
1218 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1219 +
1220 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1221 + if (src->gzip) {
1222 + char *tmp;
1223 + char *tmp_file_name;
1224 + FILE *in, *out;
1225 +
1226 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1227 +
1228 + if (mkdtemp (tmp) == NULL) {
1229 + perror ("mkdtemp");
1230 + failures++;
1231 + continue;
1232 + }
1233 +
1234 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1235 + err = ipkg_download(conf, url, tmp_file_name);
1236 + if (err == 0) {
1237 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1238 + in = fopen (tmp_file_name, "r");
1239 + out = fopen (list_file_name, "w");
1240 + if (in && out) {
1241 + inflate_unzip_result res;
1242 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1243 + } else
1244 + err = 1;
1245 + if (in)
1246 + fclose (in);
1247 + if (out)
1248 + fclose (out);
1249 + unlink (tmp_file_name);
1250 + rmdir (tmp);
1251 + free (tmp);
1252 + }
1253 + } else
1254 + err = ipkg_download(conf, url, list_file_name);
1255 + if (err) {
1256 + failures++;
1257 + } else {
1258 + ipkg_message(conf, IPKG_NOTICE,
1259 + "Updated list of available packages in %s\n",
1260 + list_file_name);
1261 + }
1262 + free(url);
1263 + free(list_file_name);
1264 + }
1265 + free(lists_dir);
1266 +
1267 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1268 +#warning here
1269 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1270 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1271 + * -Jamey 3/1/03
1272 + */
1273 + {
1274 + int i;
1275 + int changed = 0;
1276 + pkg_vec_t *available = pkg_vec_alloc();
1277 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1278 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1279 + for (i = 0; i < available->len; i++) {
1280 + pkg_t *pkg = available->pkgs[i];
1281 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1282 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1283 + pkg->state_want = SW_UNKNOWN;
1284 + changed = 1;
1285 + }
1286 + }
1287 + pkg_vec_free(available);
1288 + if (changed) {
1289 + write_status_files_if_changed(conf);
1290 + }
1291 + }
1292 +#endif
1293 +
1294 + return failures;
1295 +}
1296 +
1297 +
1298 +/* scan the args passed and cache the local filenames of the packages */
1299 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1300 +{
1301 + int i;
1302 + int err;
1303 +
1304 + /*
1305 + * First scan through package names/urls
1306 + * For any urls, download the packages and install in database.
1307 + * For any files, install package info in database.
1308 + */
1309 + for (i = 0; i < argc; i ++) {
1310 + char *filename = argv [i];
1311 + //char *tmp = basename (tmp);
1312 + //int tmplen = strlen (tmp);
1313 +
1314 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1315 + // continue;
1316 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1317 + // continue;
1318 +
1319 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1320 +
1321 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1322 + if (err)
1323 + return err;
1324 + }
1325 + return 0;
1326 +}
1327 +
1328 +struct ipkg_intercept
1329 +{
1330 + char *oldpath;
1331 + char *statedir;
1332 +};
1333 +
1334 +typedef struct ipkg_intercept *ipkg_intercept_t;
1335 +
1336 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1337 +{
1338 + ipkg_intercept_t ctx;
1339 + char *newpath;
1340 + int gen;
1341 +
1342 + ctx = malloc (sizeof (*ctx));
1343 + ctx->oldpath = strdup (getenv ("PATH"));
1344 +
1345 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1346 + setenv ("PATH", newpath, 1);
1347 + free (newpath);
1348 +
1349 + gen = 0;
1350 + retry:
1351 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1352 + if (mkdir (ctx->statedir, 0770) < 0) {
1353 + if (errno == EEXIST) {
1354 + free (ctx->statedir);
1355 + gen++;
1356 + goto retry;
1357 + }
1358 + perror (ctx->statedir);
1359 + return NULL;
1360 + }
1361 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1362 + return ctx;
1363 +}
1364 +
1365 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1366 +{
1367 + char *cmd;
1368 + DIR *dir;
1369 + int err = 0;
1370 +
1371 + setenv ("PATH", ctx->oldpath, 1);
1372 + free (ctx->oldpath);
1373 +
1374 + dir = opendir (ctx->statedir);
1375 + if (dir) {
1376 + struct dirent *de;
1377 + while (de = readdir (dir), de != NULL) {
1378 + char *path;
1379 +
1380 + if (de->d_name[0] == '.')
1381 + continue;
1382 +
1383 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1384 + if (access (path, X_OK) == 0) {
1385 + if (system (path)) {
1386 + err = errno;
1387 + perror (de->d_name);
1388 + }
1389 + }
1390 + free (path);
1391 + }
1392 + } else
1393 + perror (ctx->statedir);
1394 +
1395 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1396 + system (cmd);
1397 + free (cmd);
1398 +
1399 + free (ctx->statedir);
1400 + free (ctx);
1401 +
1402 + return err;
1403 +}
1404 +
1405 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1406 +{
1407 + pkg_vec_t *all;
1408 + int i;
1409 + pkg_t *pkg;
1410 + ipkg_intercept_t ic;
1411 + int r, err = 0;
1412 +
1413 + ipkg_message(conf, IPKG_INFO,
1414 + "Configuring unpacked packages\n");
1415 + fflush( stdout );
1416 +
1417 + all = pkg_vec_alloc();
1418 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1419 +
1420 + ic = ipkg_prep_intercepts (conf);
1421 +
1422 + for(i = 0; i < all->len; i++) {
1423 + pkg = all->pkgs[i];
1424 +
1425 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1426 + continue;
1427 +
1428 + if (pkg->state_status == SS_UNPACKED) {
1429 + ipkg_message(conf, IPKG_NOTICE,
1430 + "Configuring %s\n", pkg->name);
1431 + fflush( stdout );
1432 + r = ipkg_configure(conf, pkg);
1433 + if (r == 0) {
1434 + pkg->state_status = SS_INSTALLED;
1435 + pkg->parent->state_status = SS_INSTALLED;
1436 + pkg->state_flag &= ~SF_PREFER;
1437 + } else {
1438 + if (!err)
1439 + err = r;
1440 + }
1441 + }
1442 + }
1443 +
1444 + r = ipkg_finalize_intercepts (ic);
1445 + if (r && !err)
1446 + err = r;
1447 +
1448 + pkg_vec_free(all);
1449 + return err;
1450 +}
1451 +
1452 +static void sigint_handler(int sig)
1453 +{
1454 + signal(sig, SIG_DFL);
1455 + ipkg_message(NULL, IPKG_NOTICE,
1456 + "ipkg: interrupted. writing out status database\n");
1457 + write_status_files_if_changed(global_conf);
1458 + exit(128 + sig);
1459 +}
1460 +
1461 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1462 +{
1463 + int i;
1464 + char *arg;
1465 + int err=0;
1466 +
1467 + global_conf = conf;
1468 + signal(SIGINT, sigint_handler);
1469 +
1470 + /*
1471 + * Now scan through package names and install
1472 + */
1473 + for (i=0; i < argc; i++) {
1474 + arg = argv[i];
1475 +
1476 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1477 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1478 + if (err != EINVAL && err != 0)
1479 + return err;
1480 + }
1481 + pkg_info_preinstall_check(conf);
1482 +
1483 + for (i=0; i < argc; i++) {
1484 + arg = argv[i];
1485 + if (conf->multiple_providers)
1486 + err = ipkg_install_multi_by_name(conf, arg);
1487 + else{
1488 + err = ipkg_install_by_name(conf, arg);
1489 + }
1490 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1491 + ipkg_message(conf, IPKG_ERROR,
1492 + "Cannot find package %s.\n"
1493 + "Check the spelling or perhaps run 'ipkg update'\n",
1494 + arg);
1495 + }
1496 + }
1497 +
1498 + /* recheck to verify that all dependences are satisfied */
1499 + if (0) ipkg_satisfy_all_dependences(conf);
1500 +
1501 + ipkg_configure_packages(conf, NULL);
1502 +
1503 + write_status_files_if_changed(conf);
1504 +
1505 + return err;
1506 +}
1507 +
1508 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1509 +{
1510 + int i;
1511 + pkg_t *pkg;
1512 + int err;
1513 +
1514 + global_conf = conf;
1515 + signal(SIGINT, sigint_handler);
1516 +
1517 + if (argc) {
1518 + for (i=0; i < argc; i++) {
1519 + char *arg = argv[i];
1520 +
1521 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1522 + if (err != EINVAL && err != 0)
1523 + return err;
1524 + }
1525 + pkg_info_preinstall_check(conf);
1526 +
1527 + for (i=0; i < argc; i++) {
1528 + char *arg = argv[i];
1529 + if (conf->restrict_to_default_dest) {
1530 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1531 + argv[i],
1532 + conf->default_dest);
1533 + if (pkg == NULL) {
1534 + ipkg_message(conf, IPKG_NOTICE,
1535 + "Package %s not installed in %s\n",
1536 + argv[i], conf->default_dest->name);
1537 + continue;
1538 + }
1539 + } else {
1540 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1541 + argv[i]);
1542 + }
1543 + if (pkg)
1544 + ipkg_upgrade_pkg(conf, pkg);
1545 + else {
1546 + ipkg_install_by_name(conf, arg);
1547 + }
1548 + }
1549 + } else {
1550 + pkg_vec_t *installed = pkg_vec_alloc();
1551 +
1552 + pkg_info_preinstall_check(conf);
1553 +
1554 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1555 + for (i = 0; i < installed->len; i++) {
1556 + pkg = installed->pkgs[i];
1557 + ipkg_upgrade_pkg(conf, pkg);
1558 + }
1559 + pkg_vec_free(installed);
1560 + }
1561 +
1562 + /* recheck to verify that all dependences are satisfied */
1563 + if (0) ipkg_satisfy_all_dependences(conf);
1564 +
1565 + ipkg_configure_packages(conf, NULL);
1566 +
1567 + write_status_files_if_changed(conf);
1568 +
1569 + return 0;
1570 +}
1571 +
1572 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1573 +{
1574 + int i, err;
1575 + char *arg;
1576 + pkg_t *pkg;
1577 +
1578 + pkg_info_preinstall_check(conf);
1579 + for (i = 0; i < argc; i++) {
1580 + arg = argv[i];
1581 +
1582 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1583 + if (pkg == NULL) {
1584 + ipkg_message(conf, IPKG_ERROR,
1585 + "Cannot find package %s.\n"
1586 + "Check the spelling or perhaps run 'ipkg update'\n",
1587 + arg);
1588 + continue;
1589 + }
1590 +
1591 + err = ipkg_download_pkg(conf, pkg, ".");
1592 +
1593 + if (err) {
1594 + ipkg_message(conf, IPKG_ERROR,
1595 + "Failed to download %s\n", pkg->name);
1596 + } else {
1597 + ipkg_message(conf, IPKG_NOTICE,
1598 + "Downloaded %s as %s\n",
1599 + pkg->name, pkg->local_filename);
1600 + }
1601 + }
1602 +
1603 + return 0;
1604 +}
1605 +
1606 +
1607 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1608 +{
1609 + int i ;
1610 + pkg_vec_t *available;
1611 + pkg_t *pkg;
1612 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1613 + char *newline;
1614 + char *pkg_name = NULL;
1615 + char *version_str;
1616 +
1617 + if (argc > 0) {
1618 + pkg_name = argv[0];
1619 + }
1620 + available = pkg_vec_alloc();
1621 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1622 + for (i=0; i < available->len; i++) {
1623 + pkg = available->pkgs[i];
1624 + /* if we have package name or pattern and pkg does not match, then skip it */
1625 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1626 + continue;
1627 + if (pkg->description) {
1628 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1629 + } else {
1630 + desc_short[0] = '\0';
1631 + }
1632 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1633 + newline = strchr(desc_short, '\n');
1634 + if (newline) {
1635 + *newline = '\0';
1636 + }
1637 +#ifndef IPKG_LIB
1638 + printf("%s - %s\n", pkg->name, desc_short);
1639 +#else
1640 + if (ipkg_cb_list) {
1641 + version_str = pkg_version_str_alloc(pkg);
1642 + ipkg_cb_list(pkg->name,desc_short,
1643 + version_str,
1644 + pkg->state_status,
1645 + p_userdata);
1646 + free(version_str);
1647 + }
1648 +#endif
1649 + }
1650 + pkg_vec_free(available);
1651 +
1652 + return 0;
1653 +}
1654 +
1655 +
1656 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1657 +{
1658 + int i ;
1659 + pkg_vec_t *available;
1660 + pkg_t *pkg;
1661 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1662 + char *newline;
1663 + char *pkg_name = NULL;
1664 + char *version_str;
1665 +
1666 + if (argc > 0) {
1667 + pkg_name = argv[0];
1668 + }
1669 + available = pkg_vec_alloc();
1670 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1671 + for (i=0; i < available->len; i++) {
1672 + pkg = available->pkgs[i];
1673 + /* if we have package name or pattern and pkg does not match, then skip it */
1674 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1675 + continue;
1676 + if (pkg->description) {
1677 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1678 + } else {
1679 + desc_short[0] = '\0';
1680 + }
1681 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1682 + newline = strchr(desc_short, '\n');
1683 + if (newline) {
1684 + *newline = '\0';
1685 + }
1686 +#ifndef IPKG_LIB
1687 + printf("%s - %s\n", pkg->name, desc_short);
1688 +#else
1689 + if (ipkg_cb_list) {
1690 + version_str = pkg_version_str_alloc(pkg);
1691 + ipkg_cb_list(pkg->name,desc_short,
1692 + version_str,
1693 + pkg->state_status,
1694 + p_userdata);
1695 + free(version_str);
1696 + }
1697 +#endif
1698 + }
1699 +
1700 + return 0;
1701 +}
1702 +
1703 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1704 +{
1705 + int i;
1706 + pkg_vec_t *available;
1707 + pkg_t *pkg;
1708 + char *pkg_name = NULL;
1709 + char **pkg_fields = NULL;
1710 + int n_fields = 0;
1711 + char *buff ; // = (char *)malloc(1);
1712 +
1713 + if (argc > 0) {
1714 + pkg_name = argv[0];
1715 + }
1716 + if (argc > 1) {
1717 + pkg_fields = &argv[1];
1718 + n_fields = argc - 1;
1719 + }
1720 +
1721 + available = pkg_vec_alloc();
1722 + if (installed_only)
1723 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1724 + else
1725 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1726 + for (i=0; i < available->len; i++) {
1727 + pkg = available->pkgs[i];
1728 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1729 + continue;
1730 + }
1731 +#ifndef IPKG_LIB
1732 + if (n_fields) {
1733 + for (j = 0; j < n_fields; j++)
1734 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1735 + } else {
1736 + pkg_print_info(pkg, stdout);
1737 + }
1738 +#else
1739 +
1740 + buff = pkg_formatted_info(pkg);
1741 + if ( buff ) {
1742 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1743 + pkg->state_status,
1744 + buff,
1745 + p_userdata);
1746 +/*
1747 + We should not forget that actually the pointer is allocated.
1748 + We need to free it :) ( Thanks florian for seeing the error )
1749 +*/
1750 + free(buff);
1751 + }
1752 +#endif
1753 + if (conf->verbosity > 1) {
1754 + conffile_list_elt_t *iter;
1755 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1756 + conffile_t *cf = iter->data;
1757 + int modified = conffile_has_been_modified(conf, cf);
1758 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1759 + cf->name, cf->value, modified);
1760 + }
1761 + }
1762 + }
1763 +#ifndef IPKG_LIB
1764 + if (buff)
1765 + free(buff);
1766 +#endif
1767 + pkg_vec_free(available);
1768 +
1769 + return 0;
1770 +}
1771 +
1772 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1773 +{
1774 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1775 +}
1776 +
1777 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1778 +{
1779 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1780 +}
1781 +
1782 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1783 +{
1784 +
1785 + int err;
1786 + if (argc > 0) {
1787 + char *pkg_name = NULL;
1788 +
1789 + pkg_name = argv[0];
1790 +
1791 + err = ipkg_configure_packages (conf, pkg_name);
1792 +
1793 + } else {
1794 + err = ipkg_configure_packages (conf, NULL);
1795 + }
1796 +
1797 + write_status_files_if_changed(conf);
1798 +
1799 + return err;
1800 +}
1801 +
1802 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1803 +{
1804 + int i, err;
1805 + char *globpattern;
1806 + glob_t globbuf;
1807 +
1808 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1809 + err = glob(globpattern, 0, NULL, &globbuf);
1810 + free(globpattern);
1811 + if (err) {
1812 + return 0;
1813 + }
1814 +
1815 + ipkg_message(conf, IPKG_NOTICE,
1816 + "The following packages in %s will now be installed.\n",
1817 + conf->pending_dir);
1818 + for (i = 0; i < globbuf.gl_pathc; i++) {
1819 + ipkg_message(conf, IPKG_NOTICE,
1820 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1821 + }
1822 + ipkg_message(conf, IPKG_NOTICE, "\n");
1823 + for (i = 0; i < globbuf.gl_pathc; i++) {
1824 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1825 + if (err == 0) {
1826 + err = unlink(globbuf.gl_pathv[i]);
1827 + if (err) {
1828 + ipkg_message(conf, IPKG_ERROR,
1829 + "%s: ERROR: failed to unlink %s: %s\n",
1830 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1831 + return err;
1832 + }
1833 + }
1834 + }
1835 + globfree(&globbuf);
1836 +
1837 + return err;
1838 +}
1839 +
1840 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1841 +{
1842 + int i,a,done;
1843 + pkg_t *pkg;
1844 + pkg_t *pkg_to_remove;
1845 + pkg_vec_t *available;
1846 + char *pkg_name = NULL;
1847 + global_conf = conf;
1848 + signal(SIGINT, sigint_handler);
1849 +
1850 +// ENH: Add the "no pkg removed" just in case.
1851 +
1852 + done = 0;
1853 +
1854 + available = pkg_vec_alloc();
1855 + pkg_info_preinstall_check(conf);
1856 + if ( argc > 0 ) {
1857 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1858 + for (i=0; i < argc; i++) {
1859 + pkg_name = malloc(strlen(argv[i])+2);
1860 + strcpy(pkg_name,argv[i]);
1861 + for (a=0; a < available->len; a++) {
1862 + pkg = available->pkgs[a];
1863 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1864 + continue;
1865 + }
1866 + if (conf->restrict_to_default_dest) {
1867 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1868 + pkg->name,
1869 + conf->default_dest);
1870 + } else {
1871 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1872 + }
1873 +
1874 + if (pkg == NULL) {
1875 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1876 + continue;
1877 + }
1878 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1879 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1880 + continue;
1881 + }
1882 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1883 + done = 1;
1884 + }
1885 + free (pkg_name);
1886 + }
1887 + pkg_vec_free(available);
1888 + } else {
1889 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1890 + int flagged_pkg_count = 0;
1891 + int removed;
1892 +
1893 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1894 +
1895 + for (i = 0; i < installed_pkgs->len; i++) {
1896 + pkg = installed_pkgs->pkgs[i];
1897 + if (pkg->state_flag & SF_USER) {
1898 + flagged_pkg_count++;
1899 + } else {
1900 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1901 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1902 + }
1903 + }
1904 + if (!flagged_pkg_count) {
1905 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1906 + "so refusing to uninstall unflagged non-leaf packages\n");
1907 + return 0;
1908 + }
1909 +
1910 + /* find packages not flagged SF_USER (i.e., installed to
1911 + * satisfy a dependence) and not having any dependents, and
1912 + * remove them */
1913 + do {
1914 + removed = 0;
1915 + for (i = 0; i < installed_pkgs->len; i++) {
1916 + pkg = installed_pkgs->pkgs[i];
1917 + if (!(pkg->state_flag & SF_USER)
1918 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1919 + removed++;
1920 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1921 + ipkg_remove_pkg(conf, pkg,0);
1922 + done = 1;
1923 + }
1924 + }
1925 + } while (removed);
1926 + pkg_vec_free(installed_pkgs);
1927 + }
1928 +
1929 + if ( done == 0 )
1930 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1931 +
1932 + write_status_files_if_changed(conf);
1933 + return 0;
1934 +}
1935 +
1936 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1937 +{
1938 + int i;
1939 + pkg_t *pkg;
1940 +
1941 + global_conf = conf;
1942 + signal(SIGINT, sigint_handler);
1943 +
1944 + pkg_info_preinstall_check(conf);
1945 +
1946 + for (i=0; i < argc; i++) {
1947 + if (conf->restrict_to_default_dest) {
1948 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1949 + argv[i],
1950 + conf->default_dest);
1951 + } else {
1952 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1953 + }
1954 +
1955 + if (pkg == NULL) {
1956 + ipkg_message(conf, IPKG_ERROR,
1957 + "Package %s is not installed.\n", argv[i]);
1958 + continue;
1959 + }
1960 + ipkg_purge_pkg(conf, pkg);
1961 + }
1962 +
1963 + write_status_files_if_changed(conf);
1964 + return 0;
1965 +}
1966 +
1967 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1968 +{
1969 + int i;
1970 + pkg_t *pkg;
1971 + char *flags = argv[0];
1972 +
1973 + global_conf = conf;
1974 + signal(SIGINT, sigint_handler);
1975 +
1976 + for (i=1; i < argc; i++) {
1977 + if (conf->restrict_to_default_dest) {
1978 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1979 + argv[i],
1980 + conf->default_dest);
1981 + } else {
1982 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1983 + }
1984 +
1985 + if (pkg == NULL) {
1986 + ipkg_message(conf, IPKG_ERROR,
1987 + "Package %s is not installed.\n", argv[i]);
1988 + continue;
1989 + }
1990 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1991 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1992 + pkg->state_flag = pkg_state_flag_from_str(flags);
1993 + }
1994 +/* pb_ asked this feature 03292004 */
1995 +/* Actually I will use only this two, but this is an open for various status */
1996 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1997 + pkg->state_status = pkg_state_status_from_str(flags);
1998 + }
1999 + ipkg_state_changed++;
2000 + ipkg_message(conf, IPKG_NOTICE,
2001 + "Setting flags for package %s to %s\n",
2002 + pkg->name, flags);
2003 + }
2004 +
2005 + write_status_files_if_changed(conf);
2006 + return 0;
2007 +}
2008 +
2009 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2010 +{
2011 + pkg_t *pkg;
2012 + str_list_t *installed_files;
2013 + str_list_elt_t *iter;
2014 + char *pkg_version;
2015 + size_t buff_len = 8192;
2016 + size_t used_len;
2017 + char *buff ;
2018 +
2019 + buff = (char *)malloc(buff_len);
2020 + if ( buff == NULL ) {
2021 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2022 + return ENOMEM;
2023 + }
2024 +
2025 + if (argc < 1) {
2026 + return EINVAL;
2027 + }
2028 +
2029 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2030 + argv[0]);
2031 + if (pkg == NULL) {
2032 + ipkg_message(conf, IPKG_ERROR,
2033 + "Package %s not installed.\n", argv[0]);
2034 + return 0;
2035 + }
2036 +
2037 + installed_files = pkg_get_installed_files(pkg);
2038 + pkg_version = pkg_version_str_alloc(pkg);
2039 +
2040 +#ifndef IPKG_LIB
2041 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2042 + pkg->name, pkg_version, pkg->dest->name);
2043 + for (iter = installed_files->head; iter; iter = iter->next) {
2044 + puts(iter->data);
2045 + }
2046 +#else
2047 + if (buff) {
2048 + try_again:
2049 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2050 + pkg->name, pkg_version, pkg->dest->name) + 1;
2051 + if (used_len > buff_len) {
2052 + buff_len *= 2;
2053 + buff = realloc (buff, buff_len);
2054 + goto try_again;
2055 + }
2056 + for (iter = installed_files->head; iter; iter = iter->next) {
2057 + used_len += strlen (iter->data) + 1;
2058 + while (buff_len <= used_len) {
2059 + buff_len *= 2;
2060 + buff = realloc (buff, buff_len);
2061 + }
2062 + strncat(buff, iter->data, buff_len);
2063 + strncat(buff, "\n", buff_len);
2064 + }
2065 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2066 + buff,
2067 + pkg_version_str_alloc(pkg),
2068 + pkg->state_status,
2069 + p_userdata);
2070 + free(buff);
2071 + }
2072 +#endif
2073 +
2074 + free(pkg_version);
2075 + pkg_free_installed_files(pkg);
2076 +
2077 + return 0;
2078 +}
2079 +
2080 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2081 +{
2082 +
2083 + if (argc > 0) {
2084 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2085 + const char *rel_str = "depends on";
2086 + int i;
2087 +
2088 + pkg_info_preinstall_check(conf);
2089 +
2090 + if (conf->query_all)
2091 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2092 + else
2093 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2094 + for (i = 0; i < argc; i++) {
2095 + const char *target = argv[i];
2096 + int j;
2097 +
2098 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2099 +
2100 + for (j = 0; j < available_pkgs->len; j++) {
2101 + pkg_t *pkg = available_pkgs->pkgs[j];
2102 + if (fnmatch(target, pkg->name, 0) == 0) {
2103 + int k;
2104 + int count = pkg->depends_count + pkg->pre_depends_count;
2105 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2106 + target, pkg->architecture, rel_str);
2107 + for (k = 0; k < count; k++) {
2108 + compound_depend_t *cdepend = &pkg->depends[k];
2109 + int l;
2110 + for (l = 0; l < cdepend->possibility_count; l++) {
2111 + depend_t *possibility = cdepend->possibilities[l];
2112 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2113 + if (conf->verbosity > 0) {
2114 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2115 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2116 + if (possibility->version) {
2117 + char *typestr = NULL;
2118 + switch (possibility->constraint) {
2119 + case NONE: typestr = "none"; break;
2120 + case EARLIER: typestr = "<"; break;
2121 + case EARLIER_EQUAL: typestr = "<="; break;
2122 + case EQUAL: typestr = "="; break;
2123 + case LATER_EQUAL: typestr = ">="; break;
2124 + case LATER: typestr = ">"; break;
2125 + }
2126 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2127 + }
2128 + // free(ver);
2129 + }
2130 + ipkg_message(conf, IPKG_ERROR, "\n");
2131 + }
2132 + }
2133 + }
2134 + }
2135 + }
2136 + pkg_vec_free(available_pkgs);
2137 + }
2138 + return 0;
2139 +}
2140 +
2141 +enum what_field_type {
2142 + WHATDEPENDS,
2143 + WHATCONFLICTS,
2144 + WHATPROVIDES,
2145 + WHATREPLACES,
2146 + WHATRECOMMENDS,
2147 + WHATSUGGESTS
2148 +};
2149 +
2150 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2151 +{
2152 +
2153 + if (argc > 0) {
2154 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2155 + const char *rel_str = NULL;
2156 + int i;
2157 + int changed;
2158 +
2159 + switch (what_field_type) {
2160 + case WHATDEPENDS: rel_str = "depends on"; break;
2161 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2162 + case WHATSUGGESTS: rel_str = "suggests"; break;
2163 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2164 + case WHATPROVIDES: rel_str = "provides"; break;
2165 + case WHATREPLACES: rel_str = "replaces"; break;
2166 + }
2167 +
2168 + if (conf->query_all)
2169 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2170 + else
2171 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2172 +
2173 + /* mark the root set */
2174 + pkg_vec_clear_marks(available_pkgs);
2175 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2176 + for (i = 0; i < argc; i++) {
2177 + const char *dependee_pattern = argv[i];
2178 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2179 + }
2180 + for (i = 0; i < available_pkgs->len; i++) {
2181 + pkg_t *pkg = available_pkgs->pkgs[i];
2182 + if (pkg->state_flag & SF_MARKED) {
2183 + /* mark the parent (abstract) package */
2184 + pkg_mark_provides(pkg);
2185 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2186 + }
2187 + }
2188 +
2189 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2190 + do {
2191 + int j;
2192 + changed = 0;
2193 +
2194 + for (j = 0; j < available_pkgs->len; j++) {
2195 + pkg_t *pkg = available_pkgs->pkgs[j];
2196 + int k;
2197 + int count = ((what_field_type == WHATCONFLICTS)
2198 + ? pkg->conflicts_count
2199 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2200 + /* skip this package if it is already marked */
2201 + if (pkg->parent->state_flag & SF_MARKED) {
2202 + continue;
2203 + }
2204 + for (k = 0; k < count; k++) {
2205 + compound_depend_t *cdepend =
2206 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2207 + int l;
2208 + for (l = 0; l < cdepend->possibility_count; l++) {
2209 + depend_t *possibility = cdepend->possibilities[l];
2210 + if (possibility->pkg->state_flag & SF_MARKED) {
2211 + /* mark the depending package so we won't visit it again */
2212 + pkg->state_flag |= SF_MARKED;
2213 + pkg_mark_provides(pkg);
2214 + changed++;
2215 +
2216 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2217 + if (conf->verbosity > 0) {
2218 + char *ver = pkg_version_str_alloc(pkg);
2219 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2220 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2221 + if (possibility->version) {
2222 + char *typestr = NULL;
2223 + switch (possibility->constraint) {
2224 + case NONE: typestr = "none"; break;
2225 + case EARLIER: typestr = "<"; break;
2226 + case EARLIER_EQUAL: typestr = "<="; break;
2227 + case EQUAL: typestr = "="; break;
2228 + case LATER_EQUAL: typestr = ">="; break;
2229 + case LATER: typestr = ">"; break;
2230 + }
2231 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2232 + }
2233 + free(ver);
2234 + if (!pkg_dependence_satisfiable(conf, possibility))
2235 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2236 + }
2237 + ipkg_message(conf, IPKG_NOTICE, "\n");
2238 + goto next_package;
2239 + }
2240 + }
2241 + }
2242 + next_package:
2243 + ;
2244 + }
2245 + } while (changed && recursive);
2246 + pkg_vec_free(available_pkgs);
2247 + }
2248 +
2249 + return 0;
2250 +}
2251 +
2252 +int pkg_mark_provides(pkg_t *pkg)
2253 +{
2254 + int provides_count = pkg->provides_count;
2255 + abstract_pkg_t **provides = pkg->provides;
2256 + int i;
2257 + pkg->parent->state_flag |= SF_MARKED;
2258 + for (i = 0; i < provides_count; i++) {
2259 + provides[i]->state_flag |= SF_MARKED;
2260 + }
2261 + return 0;
2262 +}
2263 +
2264 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2265 +{
2266 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2267 +}
2268 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2269 +{
2270 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2271 +}
2272 +
2273 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2274 +{
2275 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2276 +}
2277 +
2278 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2279 +{
2280 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2281 +}
2282 +
2283 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2284 +{
2285 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2286 +}
2287 +
2288 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2289 +{
2290 +
2291 + if (argc > 0) {
2292 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2293 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2294 + int i;
2295 +
2296 + pkg_info_preinstall_check(conf);
2297 +
2298 + if (conf->query_all)
2299 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2300 + else
2301 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2302 + for (i = 0; i < argc; i++) {
2303 + const char *target = argv[i];
2304 + int j;
2305 +
2306 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2307 + rel_str, target);
2308 + for (j = 0; j < available_pkgs->len; j++) {
2309 + pkg_t *pkg = available_pkgs->pkgs[j];
2310 + int k;
2311 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2312 + for (k = 0; k < count; k++) {
2313 + abstract_pkg_t *apkg =
2314 + ((what_field_type == WHATPROVIDES)
2315 + ? pkg->provides[k]
2316 + : pkg->replaces[k]);
2317 + if (fnmatch(target, apkg->name, 0) == 0) {
2318 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2319 + if (strcmp(target, apkg->name) != 0)
2320 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2321 + ipkg_message(conf, IPKG_ERROR, "\n");
2322 + }
2323 + }
2324 + }
2325 + }
2326 + pkg_vec_free(available_pkgs);
2327 + }
2328 + return 0;
2329 +}
2330 +
2331 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2332 +{
2333 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2334 +}
2335 +
2336 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2337 +{
2338 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2339 +}
2340 +
2341 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2342 +{
2343 + int i;
2344 +
2345 + pkg_vec_t *installed;
2346 + pkg_t *pkg;
2347 + str_list_t *installed_files;
2348 + str_list_elt_t *iter;
2349 + char *installed_file;
2350 +
2351 + if (argc < 1) {
2352 + return EINVAL;
2353 + }
2354 +
2355 + installed = pkg_vec_alloc();
2356 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2357 +
2358 + for (i=0; i < installed->len; i++) {
2359 + pkg = installed->pkgs[i];
2360 +
2361 + installed_files = pkg_get_installed_files(pkg);
2362 +
2363 + for (iter = installed_files->head; iter; iter = iter->next) {
2364 + installed_file = iter->data;
2365 + if (fnmatch(argv[0], installed_file, 0)==0) {
2366 +#ifndef IPKG_LIB
2367 + printf("%s: %s\n", pkg->name, installed_file);
2368 +#else
2369 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2370 + installed_file,
2371 + pkg_version_str_alloc(pkg),
2372 + pkg->state_status, p_userdata);
2373 +#endif
2374 + }
2375 + }
2376 +
2377 + pkg_free_installed_files(pkg);
2378 + }
2379 +
2380 + /* XXX: CLEANUP: It's not obvious from the name of
2381 + pkg_hash_fetch_all_installed that we need to call
2382 + pkg_vec_free to avoid a memory leak. */
2383 + pkg_vec_free(installed);
2384 +
2385 + return 0;
2386 +}
2387 +
2388 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2389 +{
2390 + if (argc == 3) {
2391 + /* this is a bit gross */
2392 + struct pkg p1, p2;
2393 + parseVersion(&p1, argv[0]);
2394 + parseVersion(&p2, argv[2]);
2395 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2396 + } else {
2397 + ipkg_message(conf, IPKG_ERROR,
2398 + "ipkg compare_versions <v1> <op> <v2>\n"
2399 + "<op> is one of <= >= << >> =\n");
2400 + return -1;
2401 + }
2402 +}
2403 +
2404 +#ifndef HOST_CPU_STR
2405 +#define HOST_CPU_STR__(X) #X
2406 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2407 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2408 +#endif
2409 +
2410 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2411 +{
2412 + nv_pair_list_elt_t *l;
2413 +
2414 + l = conf->arch_list.head;
2415 + while (l) {
2416 + nv_pair_t *nv = l->data;
2417 + printf("arch %s %s\n", nv->name, nv->value);
2418 + l = l->next;
2419 + }
2420 + return 0;
2421 +}
2422 +
2423 +
2424 Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.h
2425 ===================================================================
2426 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2427 +++ busybox-1.4.2/archival/libipkg/ipkg_cmd.h 2007-06-04 13:21:36.710395840 +0200
2428 @@ -0,0 +1,46 @@
2429 +/* ipkg_cmd.h - the itsy package management system
2430 +
2431 + Carl D. Worth
2432 +
2433 + Copyright (C) 2001 University of Southern California
2434 +
2435 + This program is free software; you can redistribute it and/or
2436 + modify it under the terms of the GNU General Public License as
2437 + published by the Free Software Foundation; either version 2, or (at
2438 + your option) any later version.
2439 +
2440 + This program is distributed in the hope that it will be useful, but
2441 + WITHOUT ANY WARRANTY; without even the implied warranty of
2442 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2443 + General Public License for more details.
2444 +*/
2445 +
2446 +#ifndef IPKG_CMD_H
2447 +#define IPKG_CMD_H
2448 +
2449 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2450 +
2451 +struct ipkg_cmd
2452 +{
2453 + char *name;
2454 + int requires_args;
2455 + ipkg_cmd_fun_t fun;
2456 +};
2457 +typedef struct ipkg_cmd ipkg_cmd_t;
2458 +
2459 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2460 +#ifdef IPKG_LIB
2461 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2462 + const char **argv, void *userdata);
2463 +#else
2464 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2465 +#endif
2466 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2467 +/* install any packges with state_want == SW_INSTALL */
2468 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2469 +/* ensure that all dependences are satisfied */
2470 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2471 +
2472 +int pkg_mark_provides(pkg_t *pkg);
2473 +
2474 +#endif
2475 Index: busybox-1.4.2/archival/libipkg/ipkg_conf.c
2476 ===================================================================
2477 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2478 +++ busybox-1.4.2/archival/libipkg/ipkg_conf.c 2007-06-04 13:21:36.711395688 +0200
2479 @@ -0,0 +1,711 @@
2480 +/* ipkg_conf.c - the itsy package management system
2481 +
2482 + Carl D. Worth
2483 +
2484 + Copyright (C) 2001 University of Southern California
2485 +
2486 + This program is free software; you can redistribute it and/or
2487 + modify it under the terms of the GNU General Public License as
2488 + published by the Free Software Foundation; either version 2, or (at
2489 + your option) any later version.
2490 +
2491 + This program is distributed in the hope that it will be useful, but
2492 + WITHOUT ANY WARRANTY; without even the implied warranty of
2493 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2494 + General Public License for more details.
2495 +*/
2496 +
2497 +#include <glob.h>
2498 +
2499 +#include "ipkg.h"
2500 +#include "ipkg_conf.h"
2501 +
2502 +#include "xregex.h"
2503 +#include "sprintf_alloc.h"
2504 +#include "ipkg_conf.h"
2505 +#include "ipkg_message.h"
2506 +#include "file_util.h"
2507 +#include "str_util.h"
2508 +#include "xsystem.h"
2509 +
2510 +
2511 +ipkg_conf_t *global_conf;
2512 +
2513 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2514 + pkg_src_list_t *pkg_src_list,
2515 + nv_pair_list_t *tmp_dest_nv_pair_list,
2516 + char **tmp_lists_dir);
2517 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2518 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2519 + const char *name, const char *value);
2520 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2521 + const char *default_dest_name);
2522 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2523 + pkg_src_list_t *nv_pair_list);
2524 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2525 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2526 +
2527 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2528 +{
2529 + ipkg_option_t tmp[] = {
2530 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2531 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2532 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2533 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2534 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2535 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2536 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2537 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2538 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2539 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2540 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2541 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2542 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2543 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2544 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2545 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2546 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2547 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2548 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2549 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2550 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2551 + { NULL }
2552 + };
2553 +
2554 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2555 + if ( options == NULL ){
2556 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2557 + return -1;
2558 + }
2559 +
2560 + memcpy(*options, tmp, sizeof(tmp));
2561 + return 0;
2562 +};
2563 +
2564 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2565 +{
2566 + if (arg_str) {
2567 + if (*conf_str) {
2568 + free(*conf_str);
2569 + }
2570 + *conf_str = strdup(arg_str);
2571 + }
2572 +}
2573 +
2574 +static void ipkg_conf_free_string(char **conf_str)
2575 +{
2576 + if (*conf_str) {
2577 + free(*conf_str);
2578 + *conf_str = NULL;
2579 + }
2580 +}
2581 +
2582 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2583 +{
2584 + int err;
2585 + char *tmp_dir_base;
2586 + nv_pair_list_t tmp_dest_nv_pair_list;
2587 + char * lists_dir =NULL;
2588 + glob_t globbuf;
2589 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2590 + char *pending_dir =NULL;
2591 +
2592 + memset(conf, 0, sizeof(ipkg_conf_t));
2593 +
2594 + pkg_src_list_init(&conf->pkg_src_list);
2595 +
2596 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2597 + pkg_dest_list_init(&conf->pkg_dest_list);
2598 +
2599 + nv_pair_list_init(&conf->arch_list);
2600 +
2601 + conf->restrict_to_default_dest = 0;
2602 + conf->default_dest = NULL;
2603 +
2604 +
2605 + if (args->tmp_dir)
2606 + tmp_dir_base = args->tmp_dir;
2607 + else
2608 + tmp_dir_base = getenv("TMPDIR");
2609 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2610 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2611 + IPKG_CONF_TMP_DIR_SUFFIX);
2612 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2613 + if (conf->tmp_dir == NULL) {
2614 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2615 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2616 + return errno;
2617 + }
2618 +
2619 + conf->force_depends = 0;
2620 + conf->force_defaults = 0;
2621 + conf->force_overwrite = 0;
2622 + conf->force_downgrade = 0;
2623 + conf->force_reinstall = 0;
2624 + conf->force_space = 0;
2625 + conf->force_removal_of_essential_packages = 0;
2626 + conf->force_removal_of_dependent_packages = 0;
2627 + conf->nodeps = 0;
2628 + conf->verbose_wget = 0;
2629 + conf->offline_root = NULL;
2630 + conf->offline_root_pre_script_cmd = NULL;
2631 + conf->offline_root_post_script_cmd = NULL;
2632 + conf->multiple_providers = 0;
2633 + conf->verbosity = 1;
2634 + conf->noaction = 0;
2635 +
2636 + conf->http_proxy = NULL;
2637 + conf->ftp_proxy = NULL;
2638 + conf->no_proxy = NULL;
2639 + conf->proxy_user = NULL;
2640 + conf->proxy_passwd = NULL;
2641 +
2642 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2643 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2644 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + lists_dir=(char *)malloc(1);
2646 + lists_dir[0]='\0';
2647 + if (args->conf_file) {
2648 + struct stat stat_buf;
2649 + err = stat(args->conf_file, &stat_buf);
2650 + if (err == 0)
2651 + if (ipkg_conf_parse_file(conf, args->conf_file,
2652 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2653 + /* Memory leakage from ipkg_conf_parse-file */
2654 + return -1;
2655 + }
2656 +
2657 + }
2658 +
2659 + /* if (!lists_dir ){*/
2660 + if (strlen(lists_dir)<=1 ){
2661 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2662 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2663 + }
2664 +
2665 + if (args->offline_root) {
2666 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2667 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2668 + free(lists_dir);
2669 + lists_dir = tmp;
2670 + }
2671 +
2672 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2673 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2674 +
2675 + conf->lists_dir = strdup(lists_dir);
2676 + conf->pending_dir = strdup(pending_dir);
2677 +
2678 + if (args->offline_root)
2679 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2680 + memset(&globbuf, 0, sizeof(globbuf));
2681 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2682 + if (!err) {
2683 + int i;
2684 + for (i = 0; i < globbuf.gl_pathc; i++) {
2685 + if (globbuf.gl_pathv[i])
2686 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2687 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2688 + /* Memory leakage from ipkg_conf_parse-file */
2689 + return -1;
2690 + }
2691 + }
2692 + }
2693 + globfree(&globbuf);
2694 +
2695 + /* if no architectures were defined, then default all, noarch, and host architecture */
2696 + if (nv_pair_list_empty(&conf->arch_list)) {
2697 + nv_pair_list_append(&conf->arch_list, "all", "1");
2698 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2699 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2700 + }
2701 +
2702 + /* Even if there is no conf file, we'll need at least one dest. */
2703 + if (tmp_dest_nv_pair_list.head == NULL) {
2704 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2705 + IPKG_CONF_DEFAULT_DEST_NAME,
2706 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2707 + }
2708 +
2709 + /* After parsing the file, set options from command-line, (so that
2710 + command-line arguments take precedence) */
2711 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2712 + really needs to be cleaned up. There is so much duplication
2713 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2714 + a pointer to args_t (which could then not be freed), rather
2715 + than duplicating every field here? */
2716 + if (args->force_depends) {
2717 + conf->force_depends = 1;
2718 + }
2719 + if (args->force_defaults) {
2720 + conf->force_defaults = 1;
2721 + }
2722 + if (args->force_overwrite) {
2723 + conf->force_overwrite = 1;
2724 + }
2725 + if (args->force_downgrade) {
2726 + conf->force_downgrade = 1;
2727 + }
2728 + if (args->force_reinstall) {
2729 + conf->force_reinstall = 1;
2730 + }
2731 + if (args->force_removal_of_dependent_packages) {
2732 + conf->force_removal_of_dependent_packages = 1;
2733 + }
2734 + if (args->force_removal_of_essential_packages) {
2735 + conf->force_removal_of_essential_packages = 1;
2736 + }
2737 + if (args->nodeps) {
2738 + conf->nodeps = 1;
2739 + }
2740 + if (args->noaction) {
2741 + conf->noaction = 1;
2742 + }
2743 + if (args->query_all) {
2744 + conf->query_all = 1;
2745 + }
2746 + if (args->verbose_wget) {
2747 + conf->verbose_wget = 1;
2748 + }
2749 + if (args->multiple_providers) {
2750 + conf->multiple_providers = 1;
2751 + }
2752 + if (args->verbosity != conf->verbosity) {
2753 + conf->verbosity = args->verbosity;
2754 + }
2755 +
2756 + ipkg_conf_override_string(&conf->offline_root,
2757 + args->offline_root);
2758 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2759 + args->offline_root_pre_script_cmd);
2760 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2761 + args->offline_root_post_script_cmd);
2762 +
2763 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2764 + read anything from there.
2765 +*/
2766 + if ( !(args->nocheckfordirorfile)){
2767 + /* need to run load the source list before dest list -Jamey */
2768 + if ( !(args->noreadfeedsfile))
2769 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2770 +
2771 + /* Now that we have resolved conf->offline_root, we can commit to
2772 + the directory names for the dests and load in all the package
2773 + lists. */
2774 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2775 +
2776 + if (args->dest) {
2777 + err = ipkg_conf_set_default_dest(conf, args->dest);
2778 + if (err) {
2779 + return err;
2780 + }
2781 + }
2782 + }
2783 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2784 + free(lists_dir);
2785 + free(pending_dir);
2786 +
2787 + return 0;
2788 +}
2789 +
2790 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2791 +{
2792 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2793 +#error
2794 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2795 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2796 + __FUNCTION__, conf->tmp_dir);
2797 +#else
2798 + int err;
2799 +
2800 + err = rmdir(conf->tmp_dir);
2801 + if (err) {
2802 + if (errno == ENOTEMPTY) {
2803 + char *cmd;
2804 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2805 + err = xsystem(cmd);
2806 + free(cmd);
2807 + }
2808 + if (err)
2809 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2810 + }
2811 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2812 +
2813 + free(conf->tmp_dir); /*XXX*/
2814 +
2815 + pkg_src_list_deinit(&conf->pkg_src_list);
2816 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2817 + nv_pair_list_deinit(&conf->arch_list);
2818 + if (&conf->pkg_hash)
2819 + pkg_hash_deinit(&conf->pkg_hash);
2820 + if (&conf->file_hash)
2821 + hash_table_deinit(&conf->file_hash);
2822 + if (&conf->obs_file_hash)
2823 + hash_table_deinit(&conf->obs_file_hash);
2824 +
2825 + ipkg_conf_free_string(&conf->offline_root);
2826 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2827 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2828 +
2829 + if (conf->verbosity > 1) {
2830 + int i;
2831 + hash_table_t *hashes[] = {
2832 + &conf->pkg_hash,
2833 + &conf->file_hash,
2834 + &conf->obs_file_hash };
2835 + for (i = 0; i < 3; i++) {
2836 + hash_table_t *hash = hashes[i];
2837 + int c = 0;
2838 + int n_conflicts = 0;
2839 + int j;
2840 + for (j = 0; j < hash->n_entries; j++) {
2841 + int len = 0;
2842 + hash_entry_t *e = &hash->entries[j];
2843 + if (e->next)
2844 + n_conflicts++;
2845 + while (e && e->key) {
2846 + len++;
2847 + e = e->next;
2848 + }
2849 + if (len > c)
2850 + c = len;
2851 + }
2852 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2853 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2854 + hash_table_deinit(hash);
2855 + }
2856 + }
2857 +}
2858 +
2859 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2860 + const char *default_dest_name)
2861 +{
2862 + pkg_dest_list_elt_t *iter;
2863 + pkg_dest_t *dest;
2864 +
2865 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2866 + dest = iter->data;
2867 + if (strcmp(dest->name, default_dest_name) == 0) {
2868 + conf->default_dest = dest;
2869 + conf->restrict_to_default_dest = 1;
2870 + return 0;
2871 + }
2872 + }
2873 +
2874 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2875 +
2876 + return 1;
2877 +}
2878 +
2879 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2880 +{
2881 + pkg_src_list_elt_t *iter;
2882 + pkg_src_t *src;
2883 + char *list_file;
2884 +
2885 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2886 + src = iter->data;
2887 + if (src == NULL) {
2888 + continue;
2889 + }
2890 +
2891 + sprintf_alloc(&list_file, "%s/%s",
2892 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2893 + src->name);
2894 +
2895 + if (file_exists(list_file)) {
2896 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2897 + }
2898 + free(list_file);
2899 + }
2900 +
2901 + return 0;
2902 +}
2903 +
2904 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2905 +{
2906 + nv_pair_list_elt_t *iter;
2907 + nv_pair_t *nv_pair;
2908 + pkg_dest_t *dest;
2909 + char *root_dir;
2910 +
2911 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2912 + nv_pair = iter->data;
2913 +
2914 + if (conf->offline_root) {
2915 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2916 + } else {
2917 + root_dir = strdup(nv_pair->value);
2918 + }
2919 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2920 + free(root_dir);
2921 + if (dest == NULL) {
2922 + continue;
2923 + }
2924 + if (conf->default_dest == NULL) {
2925 + conf->default_dest = dest;
2926 + }
2927 + if (file_exists(dest->status_file_name)) {
2928 + pkg_hash_add_from_file(conf, dest->status_file_name,
2929 + NULL, dest, 1);
2930 + }
2931 + }
2932 +
2933 + return 0;
2934 +}
2935 +
2936 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2937 + pkg_src_list_t *pkg_src_list,
2938 + nv_pair_list_t *tmp_dest_nv_pair_list,
2939 + char **lists_dir)
2940 +{
2941 + ipkg_option_t * options;
2942 + FILE *file = fopen(filename, "r");
2943 + regex_t valid_line_re, comment_re;
2944 +#define regmatch_size 12
2945 + regmatch_t regmatch[regmatch_size];
2946 +
2947 + if (ipkg_init_options_array(conf, &options)<0)
2948 + return ENOMEM;
2949 +
2950 + if (file == NULL) {
2951 + fprintf(stderr, "%s: failed to open %s: %s\n",
2952 + __FUNCTION__, filename, strerror(errno));
2953 + free(options);
2954 + return errno;
2955 + }
2956 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2957 +
2958 + xregcomp(&comment_re,
2959 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2960 + REG_EXTENDED);
2961 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2962 +
2963 + while(1) {
2964 + int line_num = 0;
2965 + char *line;
2966 + char *type, *name, *value, *extra;
2967 +
2968 + line = file_read_line_alloc(file);
2969 + line_num++;
2970 + if (line == NULL) {
2971 + break;
2972 + }
2973 +
2974 + str_chomp(line);
2975 +
2976 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2977 + goto NEXT_LINE;
2978 + }
2979 +
2980 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2981 + str_chomp(line);
2982 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2983 + filename, line_num, line);
2984 + goto NEXT_LINE;
2985 + }
2986 +
2987 + /* This has to be so ugly to deal with optional quotation marks */
2988 + if (regmatch[2].rm_so > 0) {
2989 + type = strndup(line + regmatch[2].rm_so,
2990 + regmatch[2].rm_eo - regmatch[2].rm_so);
2991 + } else {
2992 + type = strndup(line + regmatch[3].rm_so,
2993 + regmatch[3].rm_eo - regmatch[3].rm_so);
2994 + }
2995 + if (regmatch[5].rm_so > 0) {
2996 + name = strndup(line + regmatch[5].rm_so,
2997 + regmatch[5].rm_eo - regmatch[5].rm_so);
2998 + } else {
2999 + name = strndup(line + regmatch[6].rm_so,
3000 + regmatch[6].rm_eo - regmatch[6].rm_so);
3001 + }
3002 + if (regmatch[8].rm_so > 0) {
3003 + value = strndup(line + regmatch[8].rm_so,
3004 + regmatch[8].rm_eo - regmatch[8].rm_so);
3005 + } else {
3006 + value = strndup(line + regmatch[9].rm_so,
3007 + regmatch[9].rm_eo - regmatch[9].rm_so);
3008 + }
3009 + extra = NULL;
3010 + if (regmatch[11].rm_so > 0) {
3011 + extra = strndup (line + regmatch[11].rm_so,
3012 + regmatch[11].rm_eo - regmatch[11].rm_so);
3013 + }
3014 +
3015 + /* We use the tmp_dest_nv_pair_list below instead of
3016 + conf->pkg_dest_list because we might encounter an
3017 + offline_root option later and that would invalidate the
3018 + directories we would have computed in
3019 + pkg_dest_list_init. (We do a similar thing with
3020 + tmp_src_nv_pair_list for sake of symmetry.) */
3021 + if (strcmp(type, "option") == 0) {
3022 + ipkg_conf_set_option(options, name, value);
3023 + } else if (strcmp(type, "src") == 0) {
3024 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3025 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3026 + } else {
3027 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3028 + name, value);
3029 + }
3030 + } else if (strcmp(type, "src/gz") == 0) {
3031 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3032 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3033 + } else {
3034 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3035 + name, value);
3036 + }
3037 + } else if (strcmp(type, "dest") == 0) {
3038 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3039 + } else if (strcmp(type, "lists_dir") == 0) {
3040 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3041 + if (*lists_dir == NULL) {
3042 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3043 + free(options);
3044 + return EINVAL;
3045 + }
3046 + sprintf (*lists_dir,"%s",value);
3047 + } else if (strcmp(type, "arch") == 0) {
3048 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3049 + if (!value) {
3050 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3051 + value = strdup("10");
3052 + }
3053 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3054 + } else {
3055 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3056 + "parameter: %s %s %s\n", type, name, value);
3057 + free(options);
3058 + return EINVAL;
3059 + }
3060 +
3061 + free(type);
3062 + free(name);
3063 + free(value);
3064 + if (extra)
3065 + free (extra);
3066 +
3067 + NEXT_LINE:
3068 + free(line);
3069 + }
3070 +
3071 + free(options);
3072 + regfree(&comment_re);
3073 + regfree(&valid_line_re);
3074 + fclose(file);
3075 +
3076 + return 0;
3077 +}
3078 +
3079 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3080 + const char *name, const char *value)
3081 +{
3082 + int i = 0;
3083 + while (options[i].name) {
3084 + if (strcmp(options[i].name, name) == 0) {
3085 + switch (options[i].type) {
3086 + case IPKG_OPT_TYPE_BOOL:
3087 + *((int *)options[i].value) = 1;
3088 + return 0;
3089 + case IPKG_OPT_TYPE_INT:
3090 + if (value) {
3091 + *((int *)options[i].value) = atoi(value);
3092 + return 0;
3093 + } else {
3094 + printf("%s: Option %s need an argument\n",
3095 + __FUNCTION__, name);
3096 + return EINVAL;
3097 + }
3098 + case IPKG_OPT_TYPE_STRING:
3099 + if (value) {
3100 + *((char **)options[i].value) = strdup(value);
3101 + return 0;
3102 + } else {
3103 + printf("%s: Option %s need an argument\n",
3104 + __FUNCTION__, name);
3105 + return EINVAL;
3106 + }
3107 + }
3108 + }
3109 + i++;
3110 + }
3111 +
3112 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3113 + __FUNCTION__, name, value);
3114 + return EINVAL;
3115 +}
3116 +
3117 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3118 +{
3119 + pkg_dest_list_elt_t *iter;
3120 + pkg_dest_t *dest;
3121 + pkg_vec_t *all;
3122 + pkg_t *pkg;
3123 + register int i;
3124 + int err;
3125 +
3126 + if (conf->noaction)
3127 + return 0;
3128 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3129 + dest = iter->data;
3130 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3131 + if (dest->status_file == NULL) {
3132 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3133 + __FUNCTION__, dest->status_file_name, strerror(errno));
3134 + }
3135 + }
3136 +
3137 + all = pkg_vec_alloc();
3138 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3139 +
3140 + for(i = 0; i < all->len; i++) {
3141 + pkg = all->pkgs[i];
3142 + /* We don't need most uninstalled packages in the status file */
3143 + if (pkg->state_status == SS_NOT_INSTALLED
3144 + && (pkg->state_want == SW_UNKNOWN
3145 + || pkg->state_want == SW_DEINSTALL
3146 + || pkg->state_want == SW_PURGE)) {
3147 + continue;
3148 + }
3149 + if (!pkg) {
3150 + fprintf(stderr, "Null package\n");
3151 + }
3152 + if (pkg->dest == NULL) {
3153 + fprintf(stderr, "%s: ERROR: Can't write status for "
3154 + "package %s since it has a NULL dest\n",
3155 + __FUNCTION__, pkg->name);
3156 + continue;
3157 + }
3158 + if (pkg->dest->status_file) {
3159 + pkg_print_status(pkg, pkg->dest->status_file);
3160 + }
3161 + }
3162 +
3163 + pkg_vec_free(all);
3164 +
3165 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3166 + dest = iter->data;
3167 + if (dest->status_file) {
3168 + err = ferror(dest->status_file);
3169 + fclose(dest->status_file);
3170 + dest->status_file = NULL;
3171 + if (!err) {
3172 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3173 + } else {
3174 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3175 + "retaining old %s\n", __FUNCTION__,
3176 + dest->status_file_tmp_name, dest->status_file_name);
3177 + }
3178 + }
3179 + }
3180 +
3181 + return 0;
3182 +}
3183 +
3184 +
3185 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3186 +{
3187 + char *root_filename;
3188 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3189 + return root_filename;
3190 +}
3191 Index: busybox-1.4.2/archival/libipkg/ipkg_conf.h
3192 ===================================================================
3193 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3194 +++ busybox-1.4.2/archival/libipkg/ipkg_conf.h 2007-06-04 13:21:36.711395688 +0200
3195 @@ -0,0 +1,107 @@
3196 +/* ipkg_conf.h - the itsy package management system
3197 +
3198 + Carl D. Worth
3199 +
3200 + Copyright (C) 2001 University of Southern California
3201 +
3202 + This program is free software; you can redistribute it and/or
3203 + modify it under the terms of the GNU General Public License as
3204 + published by the Free Software Foundation; either version 2, or (at
3205 + your option) any later version.
3206 +
3207 + This program is distributed in the hope that it will be useful, but
3208 + WITHOUT ANY WARRANTY; without even the implied warranty of
3209 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3210 + General Public License for more details.
3211 +*/
3212 +
3213 +#ifndef IPKG_CONF_H
3214 +#define IPKG_CONF_H
3215 +
3216 +typedef struct ipkg_conf ipkg_conf_t;
3217 +
3218 +#include "hash_table.h"
3219 +#include "ipkg.h"
3220 +#include "args.h"
3221 +#include "pkg.h"
3222 +#include "pkg_hash.h"
3223 +#include "pkg_src_list.h"
3224 +#include "pkg_dest_list.h"
3225 +#include "nv_pair_list.h"
3226 +
3227 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3228 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3229 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3230 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3231 +
3232 +/* In case the config file defines no dest */
3233 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3234 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3235 +
3236 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3237 +
3238 +struct ipkg_conf
3239 +{
3240 + pkg_src_list_t pkg_src_list;
3241 + pkg_dest_list_t pkg_dest_list;
3242 + nv_pair_list_t arch_list;
3243 +
3244 + int restrict_to_default_dest;
3245 + pkg_dest_t *default_dest;
3246 +
3247 + char *tmp_dir;
3248 + const char *lists_dir;
3249 + const char *pending_dir;
3250 +
3251 + /* options */
3252 + int force_depends;
3253 + int force_defaults;
3254 + int force_overwrite;
3255 + int force_downgrade;
3256 + int force_reinstall;
3257 + int force_space;
3258 + int force_removal_of_dependent_packages;
3259 + int force_removal_of_essential_packages;
3260 + int nodeps; /* do not follow dependences */
3261 + int verbose_wget;
3262 + int multiple_providers;
3263 + char *offline_root;
3264 + char *offline_root_pre_script_cmd;
3265 + char *offline_root_post_script_cmd;
3266 + int query_all;
3267 + int verbosity;
3268 + int noaction;
3269 +
3270 + /* proxy options */
3271 + char *http_proxy;
3272 + char *ftp_proxy;
3273 + char *no_proxy;
3274 + char *proxy_user;
3275 + char *proxy_passwd;
3276 +
3277 + hash_table_t pkg_hash;
3278 + hash_table_t file_hash;
3279 + hash_table_t obs_file_hash;
3280 +};
3281 +
3282 +enum ipkg_option_type {
3283 + IPKG_OPT_TYPE_BOOL,
3284 + IPKG_OPT_TYPE_INT,
3285 + IPKG_OPT_TYPE_STRING
3286 +};
3287 +typedef enum ipkg_option_type ipkg_option_type_t;
3288 +
3289 +typedef struct ipkg_option ipkg_option_t;
3290 +struct ipkg_option {
3291 + const char *name;
3292 + const ipkg_option_type_t type;
3293 + const void *value;
3294 +};
3295 +
3296 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3297 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3298 +
3299 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3300 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3301 +
3302 +#endif
3303 Index: busybox-1.4.2/archival/libipkg/ipkg_configure.c
3304 ===================================================================
3305 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3306 +++ busybox-1.4.2/archival/libipkg/ipkg_configure.c 2007-06-04 13:21:36.712395536 +0200
3307 @@ -0,0 +1,40 @@
3308 +/* ipkg_configure.c - the itsy package management system
3309 +
3310 + Carl D. Worth
3311 +
3312 + Copyright (C) 2001 University of Southern California
3313 +
3314 + This program is free software; you can redistribute it and/or
3315 + modify it under the terms of the GNU General Public License as
3316 + published by the Free Software Foundation; either version 2, or (at
3317 + your option) any later version.
3318 +
3319 + This program is distributed in the hope that it will be useful, but
3320 + WITHOUT ANY WARRANTY; without even the implied warranty of
3321 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3322 + General Public License for more details.
3323 +*/
3324 +
3325 +#include "ipkg.h"
3326 +
3327 +#include "ipkg_configure.h"
3328 +
3329 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3330 +{
3331 + int err;
3332 +
3333 + /* DPKG_INCOMPATIBILITY:
3334 + dpkg actually does some conffile handling here, rather than at the
3335 + end of ipkg_install(). Do we care? */
3336 + /* DPKG_INCOMPATIBILITY:
3337 + dpkg actually includes a version number to this script call */
3338 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3339 + if (err) {
3340 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3341 + return err;
3342 + }
3343 +
3344 + ipkg_state_changed++;
3345 + return 0;
3346 +}
3347 +
3348 Index: busybox-1.4.2/archival/libipkg/ipkg_configure.h
3349 ===================================================================
3350 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3351 +++ busybox-1.4.2/archival/libipkg/ipkg_configure.h 2007-06-04 13:21:36.712395536 +0200
3352 @@ -0,0 +1,25 @@
3353 +/* ipkg_configure.h - the itsy package management system
3354 +
3355 + Carl D. Worth
3356 +
3357 + Copyright (C) 2001 University of Southern California
3358 +
3359 + This program is free software; you can redistribute it and/or
3360 + modify it under the terms of the GNU General Public License as
3361 + published by the Free Software Foundation; either version 2, or (at
3362 + your option) any later version.
3363 +
3364 + This program is distributed in the hope that it will be useful, but
3365 + WITHOUT ANY WARRANTY; without even the implied warranty of
3366 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3367 + General Public License for more details.
3368 +*/
3369 +
3370 +#ifndef IPKG_CONFIGURE_H
3371 +#define IPKG_CONFIGURE_H
3372 +
3373 +#include "ipkg_conf.h"
3374 +
3375 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3376 +
3377 +#endif
3378 Index: busybox-1.4.2/archival/libipkg/ipkg_download.c
3379 ===================================================================
3380 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3381 +++ busybox-1.4.2/archival/libipkg/ipkg_download.c 2007-06-04 13:21:36.712395536 +0200
3382 @@ -0,0 +1,195 @@
3383 +/* ipkg_download.c - the itsy package management system
3384 +
3385 + Carl D. Worth
3386 +
3387 + Copyright (C) 2001 University of Southern California
3388 +
3389 + This program is free software; you can redistribute it and/or
3390 + modify it under the terms of the GNU General Public License as
3391 + published by the Free Software Foundation; either version 2, or (at
3392 + your option) any later version.
3393 +
3394 + This program is distributed in the hope that it will be useful, but
3395 + WITHOUT ANY WARRANTY; without even the implied warranty of
3396 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3397 + General Public License for more details.
3398 +*/
3399 +
3400 +#include "ipkg.h"
3401 +#include "ipkg_download.h"
3402 +#include "ipkg_message.h"
3403 +
3404 +#include "sprintf_alloc.h"
3405 +#include "xsystem.h"
3406 +#include "file_util.h"
3407 +#include "str_util.h"
3408 +
3409 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3410 +{
3411 + int err = 0;
3412 +
3413 + char *src_basec = strdup(src);
3414 + char *src_base = basename(src_basec);
3415 + char *tmp_file_location;
3416 + char *cmd;
3417 +
3418 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3419 +
3420 + fflush(stdout);
3421 +
3422 + if (str_starts_with(src, "file:")) {
3423 + int ret;
3424 + const char *file_src = src + 5;
3425 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3426 + ret = file_copy(src + 5, dest_file_name);
3427 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3428 + return ret;
3429 + }
3430 +
3431 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3432 + err = unlink(tmp_file_location);
3433 + if (err && errno != ENOENT) {
3434 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3435 + __FUNCTION__, tmp_file_location, strerror(errno));
3436 + free(tmp_file_location);
3437 + return errno;
3438 + }
3439 +
3440 + if (conf->http_proxy) {
3441 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3442 + setenv("http_proxy", conf->http_proxy, 1);
3443 + }
3444 + if (conf->ftp_proxy) {
3445 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3446 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3447 + }
3448 + if (conf->no_proxy) {
3449 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3450 + setenv("no_proxy", conf->no_proxy, 1);
3451 + }
3452 +
3453 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3454 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3455 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3456 + conf->proxy_user ? "--proxy-user=" : "",
3457 + conf->proxy_user ? conf->proxy_user : "",
3458 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3459 + conf->proxy_passwd ? conf->proxy_passwd : "",
3460 + conf->verbose_wget ? "" : "-q",
3461 + conf->tmp_dir,
3462 + src);
3463 + err = xsystem(cmd);
3464 + if (err) {
3465 + if (err != -1) {
3466 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3467 + __FUNCTION__, err, cmd);
3468 + }
3469 + unlink(tmp_file_location);
3470 + free(tmp_file_location);
3471 + free(src_basec);
3472 + free(cmd);
3473 + return EINVAL;
3474 + }
3475 + free(cmd);
3476 +
3477 + err = file_move(tmp_file_location, dest_file_name);
3478 +
3479 + free(tmp_file_location);
3480 + free(src_basec);
3481 +
3482 + if (err) {
3483 + return err;
3484 + }
3485 +
3486 + return 0;
3487 +}
3488 +
3489 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3490 +{
3491 + int err;
3492 + char *url;
3493 +
3494 + if (pkg->src == NULL) {
3495 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3496 + pkg->name, pkg->parent->name);
3497 + return -1;
3498 + }
3499 +
3500 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3501 +
3502 + /* XXX: BUG: The pkg->filename might be something like
3503 + "../../foo.ipk". While this is correct, and exactly what we
3504 + want to use to construct url above, here we actually need to
3505 + use just the filename part, without any directory. */
3506 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3507 +
3508 + err = ipkg_download(conf, url, pkg->local_filename);
3509 + free(url);
3510 +
3511 + return err;
3512 +}
3513 +
3514 +/*
3515 + * Downloads file from url, installs in package database, return package name.
3516 + */
3517 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3518 +{
3519 + int err = 0;
3520 + pkg_t *pkg;
3521 + pkg = pkg_new();
3522 + if (pkg == NULL)
3523 + return ENOMEM;
3524 +
3525 + if (str_starts_with(url, "http://")
3526 + || str_starts_with(url, "ftp://")) {
3527 + char *tmp_file;
3528 + char *file_basec = strdup(url);
3529 + char *file_base = basename(file_basec);
3530 +
3531 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3532 + err = ipkg_download(conf, url, tmp_file);
3533 + if (err)
3534 + return err;
3535 +
3536 + err = pkg_init_from_file(pkg, tmp_file);
3537 + if (err)
3538 + return err;
3539 + pkg->local_filename = strdup(tmp_file);
3540 +
3541 + free(tmp_file);
3542 + free(file_basec);
3543 +
3544 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3545 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3546 +
3547 + err = pkg_init_from_file(pkg, url);
3548 + if (err)
3549 + return err;
3550 + pkg->local_filename = strdup(url);
3551 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3552 + pkg->provided_by_hand = 1;
3553 +
3554 + } else {
3555 + pkg_deinit(pkg);
3556 + free(pkg);
3557 + return 0;
3558 + }
3559 +
3560 + if (!pkg->architecture) {
3561 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3562 + return -EINVAL;
3563 + }
3564 +
3565 + pkg->dest = conf->default_dest;
3566 + pkg->state_want = SW_INSTALL;
3567 + pkg->state_flag |= SF_PREFER;
3568 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3569 + if ( pkg == NULL ){
3570 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3571 + return 0;
3572 + }
3573 + if (namep) {
3574 + *namep = strdup(pkg->name);
3575 + }
3576 + return 0;
3577 +}
3578 Index: busybox-1.4.2/archival/libipkg/ipkg_download.h
3579 ===================================================================
3580 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3581 +++ busybox-1.4.2/archival/libipkg/ipkg_download.h 2007-06-04 13:21:36.712395536 +0200
3582 @@ -0,0 +1,30 @@
3583 +/* ipkg_download.h - the itsy package management system
3584 +
3585 + Carl D. Worth
3586 +
3587 + Copyright (C) 2001 University of Southern California
3588 +
3589 + This program is free software; you can redistribute it and/or
3590 + modify it under the terms of the GNU General Public License as
3591 + published by the Free Software Foundation; either version 2, or (at
3592 + your option) any later version.
3593 +
3594 + This program is distributed in the hope that it will be useful, but
3595 + WITHOUT ANY WARRANTY; without even the implied warranty of
3596 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3597 + General Public License for more details.
3598 +*/
3599 +
3600 +#ifndef IPKG_DOWNLOAD_H
3601 +#define IPKG_DOWNLOAD_H
3602 +
3603 +#include "ipkg_conf.h"
3604 +
3605 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3606 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3607 +/*
3608 + * Downloads file from url, installs in package database, return package name.
3609 + */
3610 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3611 +
3612 +#endif
3613 Index: busybox-1.4.2/archival/libipkg/ipkg.h
3614 ===================================================================
3615 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3616 +++ busybox-1.4.2/archival/libipkg/ipkg.h 2007-06-04 13:21:36.712395536 +0200
3617 @@ -0,0 +1,74 @@
3618 +/* ipkg.h - the itsy package management system
3619 +
3620 + Carl D. Worth
3621 +
3622 + Copyright (C) 2001 University of Southern California
3623 +
3624 + This program is free software; you can redistribute it and/or
3625 + modify it under the terms of the GNU General Public License as
3626 + published by the Free Software Foundation; either version 2, or (at
3627 + your option) any later version.
3628 +
3629 + This program is distributed in the hope that it will be useful, but
3630 + WITHOUT ANY WARRANTY; without even the implied warranty of
3631 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3632 + General Public License for more details.
3633 +*/
3634 +
3635 +#ifndef IPKG_H
3636 +#define IPKG_H
3637 +
3638 +/*
3639 +#ifdef HAVE_CONFIG_H
3640 +#include "config.h"
3641 +#endif
3642 +*/
3643 +
3644 +#if 0
3645 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3646 +#endif
3647 +
3648 +#include "ipkg_includes.h"
3649 +#include "ipkg_conf.h"
3650 +#include "ipkg_message.h"
3651 +
3652 +#define IPKG_PKG_EXTENSION ".ipk"
3653 +#define DPKG_PKG_EXTENSION ".deb"
3654 +
3655 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3656 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3657 +
3658 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3659 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3660 +#define IPKG_INFO_DIR_SUFFIX "info"
3661 +#define IPKG_STATUS_FILE_SUFFIX "status"
3662 +
3663 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3664 +
3665 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3666 +
3667 +#define IPKG_VERSION "0.99.162"
3668 +
3669 +
3670 +enum ipkg_error {
3671 + IPKG_SUCCESS = 0,
3672 + IPKG_PKG_DEPS_UNSATISFIED,
3673 + IPKG_PKG_IS_ESSENTIAL,
3674 + IPKG_PKG_HAS_DEPENDENTS,
3675 + IPKG_PKG_HAS_NO_CANDIDATE
3676 +};
3677 +typedef enum ipkg_error ipkg_error_t;
3678 +
3679 +extern int ipkg_state_changed;
3680 +
3681 +
3682 +struct errlist {
3683 + char * errmsg;
3684 + struct errlist * next;
3685 +} ;
3686 +
3687 +extern struct errlist* error_list;
3688 +
3689 +extern ipkg_conf_t *global_conf;
3690 +
3691 +#endif
3692 Index: busybox-1.4.2/archival/libipkg/ipkg_includes.h
3693 ===================================================================
3694 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3695 +++ busybox-1.4.2/archival/libipkg/ipkg_includes.h 2007-06-04 13:21:36.713395384 +0200
3696 @@ -0,0 +1,79 @@
3697 +#ifndef IPKG_INCLUDES_H
3698 +#define IPKG_INCLUDES_H
3699 +
3700 +/* Define to 1 if you have the <memory.h> header file. */
3701 +#define HAVE_MEMORY_H 1
3702 +
3703 +/* Define to 1 if you have the <regex.h> header file. */
3704 +#define HAVE_REGEX_H 1
3705 +
3706 +/* Define to 1 if you have the <stdlib.h> header file. */
3707 +#define HAVE_STDLIB_H 1
3708 +
3709 +/* Define to 1 if you have the <strings.h> header file. */
3710 +#define HAVE_STRINGS_H 1
3711 +
3712 +/* Define to 1 if you have the <string.h> header file. */
3713 +#define HAVE_STRING_H 1
3714 +
3715 +/* Define to 1 if you have the <sys/stat.h> header file. */
3716 +#define HAVE_SYS_STAT_H 1
3717 +
3718 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3719 +#define HAVE_SYS_WAIT_H 1
3720 +
3721 +/* Define to 1 if you have the <unistd.h> header file. */
3722 +#define HAVE_UNISTD_H 1
3723 +
3724 +/* Define to 1 if you have the ANSI C header files. */
3725 +#define STDC_HEADERS 1
3726 +
3727 +
3728 +#include <stdio.h>
3729 +
3730 +#if STDC_HEADERS
3731 +# include <stdlib.h>
3732 +# include <stdarg.h>
3733 +# include <stddef.h>
3734 +# include <ctype.h>
3735 +# include <errno.h>
3736 +#else
3737 +# if HAVE_STDLIB_H
3738 +# include <stdlib.h>
3739 +# endif
3740 +#endif
3741 +
3742 +#if HAVE_REGEX_H
3743 +# include <regex.h>
3744 +#endif
3745 +
3746 +#if HAVE_STRING_H
3747 +# if !STDC_HEADERS && HAVE_MEMORY_H
3748 +# include <memory.h>
3749 +# endif
3750 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3751 +# if __GNUC__
3752 +# define __USE_GNU 1
3753 +# endif
3754 +# include <string.h>
3755 +# undef __USE_GNU
3756 +#endif
3757 +
3758 +#if HAVE_STRINGS_H
3759 +# include <strings.h>
3760 +#endif
3761 +
3762 +#if HAVE_SYS_STAT_H
3763 +# include <sys/stat.h>
3764 +#endif
3765 +
3766 +#if HAVE_SYS_WAIT_H
3767 +# include <sys/wait.h>
3768 +#endif
3769 +
3770 +#if HAVE_UNISTD_H
3771 +# include <sys/types.h>
3772 +# include <unistd.h>
3773 +#endif
3774 +
3775 +#endif /* IPKG_INCLUDES_H */
3776 Index: busybox-1.4.2/archival/libipkg/ipkg_install.c
3777 ===================================================================
3778 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3779 +++ busybox-1.4.2/archival/libipkg/ipkg_install.c 2007-06-04 13:21:36.714395232 +0200
3780 @@ -0,0 +1,1942 @@
3781 +/* ipkg_install.c - the itsy package management system
3782 +
3783 + Carl D. Worth
3784 +
3785 + Copyright (C) 2001 University of Southern California
3786 +
3787 + This program is free software; you can redistribute it and/or
3788 + modify it under the terms of the GNU General Public License as
3789 + published by the Free Software Foundation; either version 2, or (at
3790 + your option) any later version.
3791 +
3792 + This program is distributed in the hope that it will be useful, but
3793 + WITHOUT ANY WARRANTY; without even the implied warranty of
3794 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3795 + General Public License for more details.
3796 +*/
3797 +
3798 +#include "ipkg.h"
3799 +#include <errno.h>
3800 +#include <dirent.h>
3801 +#include <glob.h>
3802 +#include <time.h>
3803 +#include <signal.h>
3804 +typedef void (*sighandler_t)(int);
3805 +
3806 +#include "pkg.h"
3807 +#include "pkg_hash.h"
3808 +#include "pkg_extract.h"
3809 +
3810 +#include "ipkg_install.h"
3811 +#include "ipkg_configure.h"
3812 +#include "ipkg_download.h"
3813 +#include "ipkg_remove.h"
3814 +
3815 +#include "ipkg_utils.h"
3816 +#include "ipkg_message.h"
3817 +
3818 +#include "sprintf_alloc.h"
3819 +#include "file_util.h"
3820 +#include "str_util.h"
3821 +#include "xsystem.h"
3822 +#include "user.h"
3823 +
3824 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3825 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3826 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3827 +
3828 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3829 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3830 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3831 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3832 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3833 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3834 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +
3842 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3843 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3845 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3846 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3847 +
3848 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3849 +
3850 +static int user_prefers_old_conffile(const char *file, const char *backup);
3851 +
3852 +static char *backup_filename_alloc(const char *file_name);
3853 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3854 +static int backup_exists_for(const char *file_name);
3855 +static int backup_remove(const char *file_name);
3856 +
3857 +
3858 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3859 +{
3860 + int err, cmp;
3861 + pkg_t *pkg, *old;
3862 + char *old_version, *new_version;
3863 +
3864 + pkg = pkg_new();
3865 + if (pkg == NULL) {
3866 + return ENOMEM;
3867 + }
3868 +
3869 + err = pkg_init_from_file(pkg, filename);
3870 + if (err) {
3871 + return err;
3872 + }
3873 +
3874 + if (!pkg->architecture) {
3875 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3876 + return -EINVAL;
3877 + }
3878 +
3879 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3880 + freeing the pkg that we pass in. It might be nice to clean this up
3881 + if possible. */
3882 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3883 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3884 +
3885 + pkg->local_filename = strdup(filename);
3886 +
3887 + if (old) {
3888 + old_version = pkg_version_str_alloc(old);
3889 + new_version = pkg_version_str_alloc(pkg);
3890 +
3891 + cmp = pkg_compare_versions(old, pkg);
3892 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3893 + cmp = -1 ; /* then we force ipkg to downgrade */
3894 + /* We need to use a value < 0 because in the 0 case we are asking to */
3895 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3896 + }
3897 + if (cmp > 0) {
3898 + ipkg_message(conf, IPKG_NOTICE,
3899 + "Not downgrading package %s on %s from %s to %s.\n",
3900 + old->name, old->dest->name, old_version, new_version);
3901 + pkg->state_want = SW_DEINSTALL;
3902 + pkg->state_flag |= SF_OBSOLETE;
3903 + free(old_version);
3904 + free(new_version);
3905 + return 0;
3906 + } else {
3907 + free(old_version);
3908 + free(new_version);
3909 + }
3910 + }
3911 +
3912 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3913 + return ipkg_install_pkg(conf, pkg,0);
3914 +}
3915 +
3916 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3917 +{
3918 + int cmp;
3919 + pkg_t *old, *new;
3920 + char *old_version, *new_version;
3921 +
3922 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3923 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3924 + if ( old )
3925 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3926 +
3927 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3928 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3929 + if ( new )
3930 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3931 +
3932 +/* Pigi Basically here is broken the version stuff.
3933 + What's happening is that nothing provide the version to differents
3934 + functions, so the returned struct is always the latest.
3935 + That's why the install by name don't work.
3936 +*/
3937 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3938 +
3939 + if ( old )
3940 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3941 + if ( new )
3942 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3943 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3944 +
3945 + if (new == NULL) {
3946 + return IPKG_PKG_HAS_NO_CANDIDATE;
3947 + }
3948 +
3949 + new->state_flag |= SF_USER;
3950 + if (old) {
3951 + old_version = pkg_version_str_alloc(old);
3952 + new_version = pkg_version_str_alloc(new);
3953 +
3954 + cmp = pkg_compare_versions(old, new);
3955 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3956 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3957 + cmp = -1 ; /* then we force ipkg to downgrade */
3958 + /* We need to use a value < 0 because in the 0 case we are asking to */
3959 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3960 + }
3961 + ipkg_message(conf, IPKG_DEBUG,
3962 + "Comparing visible versions of pkg %s:"
3963 + "\n\t%s is installed "
3964 + "\n\t%s is available "
3965 + "\n\t%d was comparison result\n",
3966 + pkg_name, old_version, new_version, cmp);
3967 + if (cmp == 0 && !conf->force_reinstall) {
3968 + ipkg_message(conf, IPKG_NOTICE,
3969 + "Package %s (%s) installed in %s is up to date.\n",
3970 + old->name, old_version, old->dest->name);
3971 + free(old_version);
3972 + free(new_version);
3973 + return 0;
3974 + } else if (cmp > 0) {
3975 + ipkg_message(conf, IPKG_NOTICE,
3976 + "Not downgrading package %s on %s from %s to %s.\n",
3977 + old->name, old->dest->name, old_version, new_version);
3978 + free(old_version);
3979 + free(new_version);
3980 + return 0;
3981 + } else if (cmp < 0) {
3982 + new->dest = old->dest;
3983 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3984 + }
3985 + }
3986 +
3987 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3988 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3989 + return any kind of integer, (might be errno from a syscall,
3990 + etc.). This is a real mess and will need to be cleaned up if
3991 + anyone ever wants to make a nice libipkg. */
3992 +
3993 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3994 + return ipkg_install_pkg(conf, new,0);
3995 +}
3996 +
3997 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
3998 +{
3999 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4000 + int i;
4001 + ipkg_error_t err;
4002 + abstract_pkg_t *ppkg ;
4003 +
4004 + if (providers == NULL)
4005 + return IPKG_PKG_HAS_NO_CANDIDATE;
4006 +
4007 + for (i = 0; i < providers->len; i++) {
4008 + ppkg = abstract_pkg_vec_get(providers, i);
4009 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4010 + err = ipkg_install_by_name(conf, ppkg->name);
4011 + if (err)
4012 + return err;
4013 +/* XXX Maybe ppkg should be freed ? */
4014 + }
4015 + return 0;
4016 +}
4017 +
4018 +/*
4019 + * Walk dependence graph starting with pkg, collect packages to be
4020 + * installed into pkgs_needed, in dependence order.
4021 + */
4022 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4023 +{
4024 + int i, err;
4025 + pkg_vec_t *depends = pkg_vec_alloc();
4026 + char **unresolved = NULL;
4027 + int ndepends;
4028 +
4029 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4030 + pkg, depends,
4031 + &unresolved);
4032 +
4033 + if (unresolved) {
4034 + ipkg_message(conf, IPKG_ERROR,
4035 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4036 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4037 + while (*unresolved) {
4038 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4039 + unresolved++;
4040 + }
4041 + ipkg_message(conf, IPKG_ERROR, "\n");
4042 + if (! conf->force_depends) {
4043 + ipkg_message(conf, IPKG_INFO,
4044 + "This could mean that your package list is out of date or that the packages\n"
4045 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4046 + "of this problem try again with the '-force-depends' option.\n");
4047 + pkg_vec_free(depends);
4048 + return IPKG_PKG_DEPS_UNSATISFIED;
4049 + }
4050 + }
4051 +
4052 + if (ndepends <= 0) {
4053 + pkg_vec_free(depends);
4054 + return 0;
4055 + }
4056 +
4057 + for (i = 0; i < depends->len; i++) {
4058 + pkg_t *dep = depends->pkgs[i];
4059 + /* The package was uninstalled when we started, but another
4060 + dep earlier in this loop may have depended on it and pulled
4061 + it in, so check first. */
4062 + if ((dep->state_status != SS_INSTALLED)
4063 + && (dep->state_status != SS_UNPACKED)
4064 + && (dep->state_want != SW_INSTALL)) {
4065 +
4066 + /* Mark packages as to-be-installed */
4067 + dep->state_want = SW_INSTALL;
4068 +
4069 + /* Dependencies should be installed the same place as pkg */
4070 + if (dep->dest == NULL) {
4071 + dep->dest = pkg->dest;
4072 + }
4073 +
4074 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4075 + if (err) {
4076 + pkg_vec_free(depends);
4077 + return err;
4078 + }
4079 + }
4080 + }
4081 + if (pkgs_needed)
4082 + pkg_vec_insert(pkgs_needed, pkg);
4083 +
4084 + pkg_vec_free(depends);
4085 +
4086 + return 0;
4087 +}
4088 +
4089 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4090 +{
4091 + int cmp;
4092 + pkg_t *old, *new;
4093 + char *old_version, *new_version;
4094 +
4095 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4096 +
4097 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4098 + if (new == NULL) {
4099 + return IPKG_PKG_HAS_NO_CANDIDATE;
4100 + }
4101 + if (old) {
4102 + old_version = pkg_version_str_alloc(old);
4103 + new_version = pkg_version_str_alloc(new);
4104 +
4105 + cmp = pkg_compare_versions(old, new);
4106 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4107 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4108 + cmp = -1 ; /* then we force ipkg to downgrade */
4109 + /* We need to use a value < 0 because in the 0 case we are asking to */
4110 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4111 + }
4112 + ipkg_message(conf, IPKG_DEBUG,
4113 + "comparing visible versions of pkg %s:"
4114 + "\n\t%s is installed "
4115 + "\n\t%s is available "
4116 + "\n\t%d was comparison result\n",
4117 + pkg_name, old_version, new_version, cmp);
4118 + if (cmp == 0 && !conf->force_reinstall) {
4119 + ipkg_message(conf, IPKG_NOTICE,
4120 + "Package %s (%s) installed in %s is up to date.\n",
4121 + old->name, old_version, old->dest->name);
4122 + free(old_version);
4123 + free(new_version);
4124 + return 0;
4125 + } else if (cmp > 0) {
4126 + ipkg_message(conf, IPKG_NOTICE,
4127 + "Not downgrading package %s on %s from %s to %s.\n",
4128 + old->name, old->dest->name, old_version, new_version);
4129 + free(old_version);
4130 + free(new_version);
4131 + return 0;
4132 + } else if (cmp < 0) {
4133 + new->dest = old->dest;
4134 + old->state_want = SW_DEINSTALL;
4135 + old->state_flag |= SF_OBSOLETE;
4136 + }
4137 + }
4138 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4139 +}
4140 +
4141 +\f
4142 +
4143 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4144 +{
4145 + int i, err;
4146 + pkg_vec_t *depends = pkg_vec_alloc();
4147 + pkg_t *dep;
4148 + char **unresolved = NULL;
4149 + int ndepends;
4150 +
4151 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4152 + pkg, depends,
4153 + &unresolved);
4154 +
4155 + if (unresolved) {
4156 + ipkg_message(conf, IPKG_ERROR,
4157 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4158 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4159 + while (*unresolved) {
4160 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4161 + unresolved++;
4162 + }
4163 + ipkg_message(conf, IPKG_ERROR, "\n");
4164 + if (! conf->force_depends) {
4165 + ipkg_message(conf, IPKG_INFO,
4166 + "This could mean that your package list is out of date or that the packages\n"
4167 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4168 + "of this problem try again with the '-force-depends' option.\n");
4169 + pkg_vec_free(depends);
4170 + return IPKG_PKG_DEPS_UNSATISFIED;
4171 + }
4172 + }
4173 +
4174 + if (ndepends <= 0) {
4175 + return 0;
4176 + }
4177 +
4178 + /* Mark packages as to-be-installed */
4179 + for (i=0; i < depends->len; i++) {
4180 + /* Dependencies should be installed the same place as pkg */
4181 + if (depends->pkgs[i]->dest == NULL) {
4182 + depends->pkgs[i]->dest = pkg->dest;
4183 + }
4184 + depends->pkgs[i]->state_want = SW_INSTALL;
4185 + }
4186 +
4187 + for (i = 0; i < depends->len; i++) {
4188 + dep = depends->pkgs[i];
4189 + /* The package was uninstalled when we started, but another
4190 + dep earlier in this loop may have depended on it and pulled
4191 + it in, so check first. */
4192 + if ((dep->state_status != SS_INSTALLED)
4193 + && (dep->state_status != SS_UNPACKED)) {
4194 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4195 + err = ipkg_install_pkg(conf, dep,0);
4196 + if (err) {
4197 + pkg_vec_free(depends);
4198 + return err;
4199 + }
4200 + }
4201 + }
4202 +
4203 + pkg_vec_free(depends);
4204 +
4205 + return 0;
4206 +}
4207 +
4208 +
4209 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4210 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4211 +{
4212 + if (conf->nodeps == 0) {
4213 + int i;
4214 + pkg_vec_t *installed = pkg_vec_alloc();
4215 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4216 + for (i = 0; i < installed->len; i++) {
4217 + pkg_t *pkg = installed->pkgs[i];
4218 + satisfy_dependencies_for(conf, pkg);
4219 + }
4220 + pkg_vec_free(installed);
4221 + }
4222 + return 0;
4223 +}
4224 +
4225 +\f
4226 +
4227 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4228 +{
4229 + int i;
4230 + pkg_vec_t *conflicts = NULL;
4231 + int level;
4232 + const char *prefix;
4233 + if (conf->force_depends) {
4234 + level = IPKG_NOTICE;
4235 + prefix = "Warning";
4236 + } else {
4237 + level = IPKG_ERROR;
4238 + prefix = "ERROR";
4239 + }
4240 +
4241 + if (!conf->force_depends)
4242 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4243 +
4244 + if (conflicts) {
4245 + ipkg_message(conf, level,
4246 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4247 + i = 0;
4248 + while (i < conflicts->len)
4249 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4250 + ipkg_message(conf, level, "\n");
4251 + pkg_vec_free(conflicts);
4252 + return IPKG_PKG_DEPS_UNSATISFIED;
4253 + }
4254 + return 0;
4255 +}
4256 +
4257 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4258 +{
4259 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4260 + str_list_elt_t *iter;
4261 +
4262 + for (iter = new_list->head; iter; iter = iter->next) {
4263 + char *new_file = iter->data;
4264 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4265 + if (!new_file)
4266 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4267 + if (!owner || (owner == old_pkg))
4268 + file_hash_set_file_owner(conf, new_file, new_pkg);
4269 + }
4270 + if (old_pkg) {
4271 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4272 + for (iter = old_list->head; iter; iter = iter->next) {
4273 + char *old_file = iter->data;
4274 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4275 + if (owner == old_pkg) {
4276 + /* obsolete */
4277 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4278 + }
4279 + }
4280 + }
4281 + return 0;
4282 +}
4283 +
4284 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4285 +{
4286 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4287 +
4288 + /* sma 6.20.02: yup; here's the first bit */
4289 + /*
4290 + * XXX: BUG easy for cworth
4291 + * 1) please point the call below to the correct current root destination
4292 + * 2) we need to resolve how to check the required space for a pending pkg,
4293 + * my diddling with the .ipk file size below isn't going to cut it.
4294 + * 3) return a proper error code instead of 1
4295 + */
4296 + int comp_size, blocks_available;
4297 +
4298 + if (!conf->force_space && pkg->installed_size != NULL) {
4299 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4300 +
4301 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4302 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4303 + comp_size = (int)((comp_size + 1023) / 1024);
4304 +
4305 + if (comp_size >= blocks_available) {
4306 + ipkg_message(conf, IPKG_ERROR,
4307 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4308 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4309 + return ENOSPC;
4310 + }
4311 + }
4312 + return 0;
4313 +}
4314 +
4315 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4316 +{
4317 + int err;
4318 + char *conffiles_file_name;
4319 + char *root_dir;
4320 + FILE *conffiles_file;
4321 +
4322 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4323 +
4324 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4325 + if (pkg->tmp_unpack_dir == NULL) {
4326 + ipkg_message(conf, IPKG_ERROR,
4327 + "%s: Failed to create temporary directory '%s': %s\n",
4328 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4329 + return errno;
4330 + }
4331 +
4332 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4333 + if (err) {
4334 + return err;
4335 + }
4336 +
4337 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4338 + conffiles. Seems like I should be able to get everything to go
4339 + through pkg_init_from_file. If so, maybe it would make sense to
4340 + move all of unpack_pkg_control_files to that function. */
4341 +
4342 + /* Don't need to re-read conffiles if we already have it */
4343 + if (pkg->conffiles.head) {
4344 + return 0;
4345 + }
4346 +
4347 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4348 + if (! file_exists(conffiles_file_name)) {
4349 + free(conffiles_file_name);
4350 + return 0;
4351 + }
4352 +
4353 + conffiles_file = fopen(conffiles_file_name, "r");
4354 + if (conffiles_file == NULL) {
4355 + fprintf(stderr, "%s: failed to open %s: %s\n",
4356 + __FUNCTION__, conffiles_file_name, strerror(errno));
4357 + free(conffiles_file_name);
4358 + return errno;
4359 + }
4360 + free(conffiles_file_name);
4361 +
4362 + while (1) {
4363 + char *cf_name;
4364 + char *cf_name_in_dest;
4365 +
4366 + cf_name = file_read_line_alloc(conffiles_file);
4367 + if (cf_name == NULL) {
4368 + break;
4369 + }
4370 + str_chomp(cf_name);
4371 + if (cf_name[0] == '\0') {
4372 + continue;
4373 + }
4374 +
4375 + /* Prepend dest->root_dir to conffile name.
4376 + Take pains to avoid multiple slashes. */
4377 + root_dir = pkg->dest->root_dir;
4378 + if (conf->offline_root)
4379 + /* skip the offline_root prefix */
4380 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4381 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4382 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4383 +
4384 + /* Can't get an md5sum now, (file isn't extracted yet).
4385 + We'll wait until resolve_conffiles */
4386 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4387 +
4388 + free(cf_name);
4389 + free(cf_name_in_dest);
4390 + }
4391 +
4392 + fclose(conffiles_file);
4393 +
4394 + return 0;
4395 +}
4396 +
4397 +/* returns number of installed replacees */
4398 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4399 +{
4400 + abstract_pkg_t **replaces = pkg->replaces;
4401 + int replaces_count = pkg->replaces_count;
4402 + int i, j;
4403 + for (i = 0; i < replaces_count; i++) {
4404 + abstract_pkg_t *ab_pkg = replaces[i];
4405 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4406 + if (pkg_vec) {
4407 + for (j = 0; j < pkg_vec->len; j++) {
4408 + pkg_t *replacee = pkg_vec->pkgs[j];
4409 + if (!pkg_conflicts(pkg, replacee))
4410 + continue;
4411 + if (replacee->state_status == SS_INSTALLED) {
4412 + pkg_vec_insert(installed_replacees, replacee);
4413 + }
4414 + }
4415 + }
4416 + }
4417 + return installed_replacees->len;
4418 +}
4419 +
4420 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4421 +{
4422 + int i;
4423 + int replaces_count = replacees->len;
4424 + for (i = 0; i < replaces_count; i++) {
4425 + pkg_t *replacee = replacees->pkgs[i];
4426 + int err;
4427 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4428 + err = ipkg_remove_pkg(conf, replacee,0);
4429 + if (err)
4430 + return err;
4431 + }
4432 + return 0;
4433 +}
4434 +
4435 +/* to unwind the removal: make sure they are installed */
4436 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4437 +{
4438 + int i, err;
4439 + int replaces_count = replacees->len;
4440 + for (i = 0; i < replaces_count; i++) {
4441 + pkg_t *replacee = replacees->pkgs[i];
4442 + if (replacee->state_status != SS_INSTALLED) {
4443 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4444 + err = ipkg_install_pkg(conf, replacee,0);
4445 + if (err)
4446 + return err;
4447 + }
4448 + }
4449 + return 0;
4450 +}
4451 +
4452 +int caught_sigint = 0;
4453 +static void ipkg_install_pkg_sigint_handler(int sig)
4454 +{
4455 + caught_sigint = sig;
4456 +}
4457 +
4458 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4459 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4460 +{
4461 + if (old_pkg) {
4462 + char message_out[15];
4463 + char *old_version = pkg_version_str_alloc(old_pkg);
4464 + char *new_version = pkg_version_str_alloc(pkg);
4465 + int cmp = pkg_compare_versions(old_pkg, pkg);
4466 + int rc = 0;
4467 +
4468 + memset(message_out,'\x0',15);
4469 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4470 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4471 + cmp = -1 ; /* then we force ipkg to downgrade */
4472 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4473 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4474 + }
4475 +
4476 + if (cmp > 0) {
4477 + ipkg_message(conf, IPKG_NOTICE,
4478 + "Not downgrading package %s on %s from %s to %s.\n",
4479 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4480 + rc = 1;
4481 + } else if (cmp < 0) {
4482 + ipkg_message(conf, IPKG_NOTICE,
4483 + "%s%s on %s from %s to %s...\n",
4484 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4485 + pkg->dest = old_pkg->dest;
4486 + rc = 0;
4487 + } else /* cmp == 0 */ {
4488 + if (conf->force_reinstall) {
4489 + ipkg_message(conf, IPKG_NOTICE,
4490 + "Reinstalling %s (%s) on %s...\n",
4491 + pkg->name, new_version, old_pkg->dest->name);
4492 + pkg->dest = old_pkg->dest;
4493 + rc = 0;
4494 + } else {
4495 + ipkg_message(conf, IPKG_NOTICE,
4496 + "Not installing %s (%s) on %s -- already installed.\n",
4497 + pkg->name, new_version, old_pkg->dest->name);
4498 + rc = 1;
4499 + }
4500 + }
4501 + free(old_version);
4502 + free(new_version);
4503 + return rc;
4504 + } else {
4505 + char message_out[15], *version ;
4506 + memset(message_out,'\x0',15);
4507 + if ( message )
4508 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4509 + else
4510 + strncpy( message_out,"Installing ",strlen("Installing ") );
4511 + version = pkg_version_str_alloc(pkg);
4512 +
4513 + ipkg_message(conf, IPKG_NOTICE,
4514 + "%s%s (%s) to %s...\n", message_out,
4515 + pkg->name, version, pkg->dest->name);
4516 + free(version);
4517 + return 0;
4518 + }
4519 +}
4520 +
4521 +/* and now the meat... */
4522 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4523 +{
4524 + int err = 0;
4525 + int message = 0;
4526 + pkg_t *old_pkg = NULL;
4527 + pkg_vec_t *replacees;
4528 + abstract_pkg_t *ab_pkg = NULL;
4529 + int old_state_flag;
4530 + char* file_md5;
4531 +
4532 +
4533 + if ( from_upgrade )
4534 + message = 1; /* Coming from an upgrade, and should change the output message */
4535 +
4536 + if (!pkg) {
4537 + ipkg_message(conf, IPKG_ERROR,
4538 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4539 + return -EINVAL;
4540 + }
4541 +
4542 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4543 +
4544 + if (!pkg_arch_supported(conf, pkg)) {
4545 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4546 + pkg->architecture, pkg->name);
4547 + return -EINVAL;
4548 + }
4549 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4550 + err = satisfy_dependencies_for(conf, pkg);
4551 + if (err) { return err; }
4552 +
4553 + ipkg_message(conf, IPKG_NOTICE,
4554 + "Package %s is already installed in %s.\n",
4555 + pkg->name, pkg->dest->name);
4556 + return 0;
4557 + }
4558 +
4559 + if (pkg->dest == NULL) {
4560 + pkg->dest = conf->default_dest;
4561 + }
4562 +
4563 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4564 +
4565 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4566 + if (err) { return err; }
4567 +
4568 + pkg->state_want = SW_INSTALL;
4569 + if (old_pkg){
4570 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4571 + }
4572 +
4573 +
4574 + /* Abhaya: conflicts check */
4575 + err = check_conflicts_for(conf, pkg);
4576 + if (err) { return err; }
4577 +
4578 + /* this setup is to remove the upgrade scenario in the end when
4579 + installing pkg A, A deps B & B deps on A. So both B and A are
4580 + installed. Then A's installation is started resulting in an
4581 + uncecessary upgrade */
4582 + if (pkg->state_status == SS_INSTALLED
4583 + && conf->force_reinstall == 0) return 0;
4584 +
4585 + err = verify_pkg_installable(conf, pkg);
4586 + if (err) { return err; }
4587 +
4588 + if (pkg->local_filename == NULL) {
4589 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4590 + if (err) {
4591 + ipkg_message(conf, IPKG_ERROR,
4592 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4593 + pkg->name);
4594 + return err;
4595 + }
4596 + }
4597 +
4598 +/* Check for md5 values */
4599 + if (pkg->md5sum)
4600 + {
4601 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4602 + if (strcmp(file_md5, pkg->md5sum))
4603 + {
4604 + ipkg_message(conf, IPKG_ERROR,
4605 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4606 + pkg->name);
4607 + free(file_md5);
4608 + return err;
4609 + }
4610 + free(file_md5);
4611 + }
4612 +
4613 + if (pkg->tmp_unpack_dir == NULL) {
4614 + unpack_pkg_control_files(conf, pkg);
4615 + }
4616 +
4617 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4618 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4619 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4620 + err = update_file_ownership(conf, pkg, old_pkg);
4621 + if (err) { return err; }
4622 +
4623 + if (conf->nodeps == 0) {
4624 + err = satisfy_dependencies_for(conf, pkg);
4625 + if (err) { return err; }
4626 + }
4627 +
4628 + replacees = pkg_vec_alloc();
4629 + pkg_get_installed_replacees(conf, pkg, replacees);
4630 +
4631 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4632 + {
4633 + sigset_t newset, oldset;
4634 + sighandler_t old_handler = NULL;
4635 + int use_signal = 0;
4636 + caught_sigint = 0;
4637 + if (use_signal) {
4638 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4639 + } else {
4640 + sigemptyset(&newset);
4641 + sigaddset(&newset, SIGINT);
4642 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4643 + }
4644 +
4645 + ipkg_state_changed++;
4646 + pkg->state_flag |= SF_FILELIST_CHANGED;
4647 +
4648 + /* XXX: BUG: we really should treat replacement more like an upgrade
4649 + * Instead, we're going to remove the replacees
4650 + */
4651 + err = pkg_remove_installed_replacees(conf, replacees);
4652 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4653 +
4654 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4655 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4656 +
4657 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4658 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4659 +
4660 + err = preinst_configure(conf, pkg, old_pkg);
4661 + if (err) goto UNWIND_PREINST_CONFIGURE;
4662 +
4663 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4664 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4665 +
4666 + err = check_data_file_clashes(conf, pkg, old_pkg);
4667 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4668 +
4669 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4670 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4671 +
4672 + if (conf->noaction) return 0;
4673 +
4674 + /* point of no return: no unwinding after this */
4675 + if (old_pkg && !conf->force_reinstall) {
4676 + old_pkg->state_want = SW_DEINSTALL;
4677 +
4678 + if (old_pkg->state_flag & SF_NOPRUNE) {
4679 + ipkg_message(conf, IPKG_INFO,
4680 + " not removing obsolesced files because package marked noprune\n");
4681 + } else {
4682 + ipkg_message(conf, IPKG_INFO,
4683 + " removing obsolesced files\n");
4684 + remove_obsolesced_files(conf, pkg, old_pkg);
4685 + }
4686 + /* removing files from old package, to avoid ghost files */
4687 + remove_data_files_and_list(conf, old_pkg);
4688 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4689 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4690 + remove_postrm(conf, old_pkg);
4691 +/* Pigi */
4692 +
4693 + }
4694 +
4695 +
4696 + ipkg_message(conf, IPKG_INFO,
4697 + " installing maintainer scripts\n");
4698 + install_maintainer_scripts(conf, pkg, old_pkg);
4699 +
4700 + /* the following just returns 0 */
4701 + remove_disappeared(conf, pkg);
4702 +
4703 + ipkg_message(conf, IPKG_INFO,
4704 + " installing data files\n");
4705 + install_data_files(conf, pkg);
4706 +
4707 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4708 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4709 +
4710 + ipkg_message(conf, IPKG_INFO,
4711 + " resolving conf files\n");
4712 + resolve_conffiles(conf, pkg);
4713 +
4714 + pkg->state_status = SS_UNPACKED;
4715 + old_state_flag = pkg->state_flag;
4716 + pkg->state_flag &= ~SF_PREFER;
4717 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4718 +
4719 + if (old_pkg && !conf->force_reinstall) {
4720 + old_pkg->state_status = SS_NOT_INSTALLED;
4721 + }
4722 +
4723 + time(&pkg->installed_time);
4724 +
4725 + ipkg_message(conf, IPKG_INFO,
4726 + " cleanup temp files\n");
4727 + cleanup_temporary_files(conf, pkg);
4728 +
4729 + ab_pkg = pkg->parent;
4730 + if (ab_pkg)
4731 + ab_pkg->state_status = pkg->state_status;
4732 +
4733 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4734 +
4735 + if (use_signal)
4736 + signal(SIGINT, old_handler);
4737 + else
4738 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4739 +
4740 + return 0;
4741 +
4742 +
4743 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4744 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4745 + UNWIND_CHECK_DATA_FILE_CLASHES:
4746 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4747 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4748 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4749 + UNWIND_PREINST_CONFIGURE:
4750 + preinst_configure_unwind(conf, pkg, old_pkg);
4751 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4752 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4753 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4754 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4755 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4756 + pkg_remove_installed_replacees_unwind(conf, replacees);
4757 +
4758 + ipkg_message(conf, IPKG_INFO,
4759 + " cleanup temp files\n");
4760 + cleanup_temporary_files(conf, pkg);
4761 +
4762 + ipkg_message(conf, IPKG_INFO,
4763 + "Failed.\n");
4764 + if (use_signal)
4765 + signal(SIGINT, old_handler);
4766 + else
4767 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4768 +
4769 + return err;
4770 + }
4771 +}
4772 +
4773 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4774 +{
4775 + /* DPKG_INCOMPATIBILITY:
4776 + dpkg does some things here that we don't do yet. Do we care?
4777 +
4778 + 1. If a version of the package is already installed, call
4779 + old-prerm upgrade new-version
4780 + 2. If the script runs but exits with a non-zero exit status
4781 + new-prerm failed-upgrade old-version
4782 + Error unwind, for both the above cases:
4783 + old-postinst abort-upgrade new-version
4784 + */
4785 + return 0;
4786 +}
4787 +
4788 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4789 +{
4790 + /* DPKG_INCOMPATIBILITY:
4791 + dpkg does some things here that we don't do yet. Do we care?
4792 + (See prerm_upgrade_old_package for details)
4793 + */
4794 + return 0;
4795 +}
4796 +
4797 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4798 +{
4799 + /* DPKG_INCOMPATIBILITY:
4800 + dpkg does some things here that we don't do yet. Do we care?
4801 + 2. If a 'conflicting' package is being removed at the same time:
4802 + 1. If any packages depended on that conflicting package and
4803 + --auto-deconfigure is specified, call, for each such package:
4804 + deconfigured's-prerm deconfigure \
4805 + in-favour package-being-installed version \
4806 + removing conflicting-package version
4807 + Error unwind:
4808 + deconfigured's-postinst abort-deconfigure \
4809 + in-favour package-being-installed-but-failed version \
4810 + removing conflicting-package version
4811 +
4812 + The deconfigured packages are marked as requiring
4813 + configuration, so that if --install is used they will be
4814 + configured again if possible.
4815 + 2. To prepare for removal of the conflicting package, call:
4816 + conflictor's-prerm remove in-favour package new-version
4817 + Error unwind:
4818 + conflictor's-postinst abort-remove in-favour package new-version
4819 + */
4820 + return 0;
4821 +}
4822 +
4823 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4824 +{
4825 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4826 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4827 + details) */
4828 + return 0;
4829 +}
4830 +
4831 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4832 +{
4833 + int err;
4834 + char *preinst_args;
4835 +
4836 + if (old_pkg) {
4837 + char *old_version = pkg_version_str_alloc(old_pkg);
4838 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4839 + free(old_version);
4840 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4841 + char *pkg_version = pkg_version_str_alloc(pkg);
4842 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4843 + free(pkg_version);
4844 + } else {
4845 + preinst_args = strdup("install");
4846 + }
4847 +
4848 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4849 + if (err) {
4850 + ipkg_message(conf, IPKG_ERROR,
4851 + "Aborting installation of %s\n", pkg->name);
4852 + return 1;
4853 + }
4854 +
4855 + free(preinst_args);
4856 +
4857 + return 0;
4858 +}
4859 +
4860 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4861 +{
4862 + /* DPKG_INCOMPATIBILITY:
4863 + dpkg does the following error unwind, should we?
4864 + pkg->postrm abort-upgrade old-version
4865 + OR pkg->postrm abort-install old-version
4866 + OR pkg->postrm abort-install
4867 + */
4868 + return 0;
4869 +}
4870 +
4871 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4872 +{
4873 + int err;
4874 + conffile_list_elt_t *iter;
4875 + conffile_t *cf;
4876 +
4877 + if (conf->noaction) return 0;
4878 +
4879 + /* Backup all modified conffiles */
4880 + if (old_pkg) {
4881 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4882 + char *cf_name;
4883 +
4884 + cf = iter->data;
4885 + cf_name = root_filename_alloc(conf, cf->name);
4886 +
4887 + /* Don't worry if the conffile is just plain gone */
4888 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4889 + err = backup_make_backup(conf, cf_name);
4890 + if (err) {
4891 + return err;
4892 + }
4893 + }
4894 + free(cf_name);
4895 + }
4896 + }
4897 +
4898 + /* Backup all conffiles that were not conffiles in old_pkg */
4899 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4900 + char *cf_name;
4901 + cf = iter->data;
4902 + cf_name = root_filename_alloc(conf, cf->name);
4903 + /* Ignore if this was a conffile in old_pkg as well */
4904 + if (pkg_get_conffile(old_pkg, cf->name)) {
4905 + continue;
4906 + }
4907 +
4908 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4909 + err = backup_make_backup(conf, cf_name);
4910 + if (err) {
4911 + return err;
4912 + }
4913 + }
4914 + free(cf_name);
4915 + }
4916 +
4917 + return 0;
4918 +}
4919 +
4920 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4921 +{
4922 + conffile_list_elt_t *iter;
4923 +
4924 + if (old_pkg) {
4925 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4926 + backup_remove(iter->data->name);
4927 + }
4928 + }
4929 +
4930 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4931 + backup_remove(iter->data->name);
4932 + }
4933 +
4934 + return 0;
4935 +}
4936 +
4937 +
4938 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4939 +{
4940 + /* DPKG_INCOMPATIBILITY:
4941 + ipkg takes a slightly different approach than dpkg at this
4942 + point. dpkg installs each file in the new package while
4943 + creating a backup for any file that is replaced, (so that it
4944 + can unwind if necessary). To avoid complexity and redundant
4945 + storage, ipkg doesn't do any installation until later, (at the
4946 + point at which dpkg removes the backups.
4947 +
4948 + But, we do have to check for data file clashes, since after
4949 + installing a package with a file clash, removing either of the
4950 + packages involved in the clash has the potential to break the
4951 + other package.
4952 + */
4953 + str_list_t *files_list;
4954 + str_list_elt_t *iter;
4955 +
4956 + int clashes = 0;
4957 +
4958 + files_list = pkg_get_installed_files(pkg);
4959 + for (iter = files_list->head; iter; iter = iter->next) {
4960 + char *root_filename;
4961 + char *filename = iter->data;
4962 + root_filename = root_filename_alloc(conf, filename);
4963 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4964 + pkg_t *owner;
4965 + pkg_t *obs;
4966 + /* Pre-existing conffiles are OK */
4967 + /* @@@@ should have way to check that it is a conffile -Jamey */
4968 + if (backup_exists_for(root_filename)) {
4969 + continue;
4970 + }
4971 +
4972 + /* Pre-existing files are OK if force-overwrite was asserted. */
4973 + if (conf->force_overwrite) {
4974 + /* but we need to change who owns this file */
4975 + file_hash_set_file_owner(conf, filename, pkg);
4976 + continue;
4977 + }
4978 +
4979 + owner = file_hash_get_file_owner(conf, filename);
4980 +
4981 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4982 + if (owner && old_pkg) {
4983 + if (strcmp(owner->name, old_pkg->name) == 0) {
4984 + continue;
4985 + }
4986 + }
4987 +
4988 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4989 + if (owner) {
4990 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4991 + if (pkg_replaces(pkg, owner)) {
4992 + continue;
4993 + }
4994 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4995 + then it's ok to overwrite. */
4996 + if (strcmp(owner->name,pkg->name)==0){
4997 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4998 + continue;
4999 + }
5000 + }
5001 +
5002 + /* Pre-existing files are OK if they are obsolete */
5003 + obs = hash_table_get(&conf->obs_file_hash, filename);
5004 + if (obs) {
5005 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5006 + continue;
5007 + }
5008 +
5009 + /* We have found a clash. */
5010 + ipkg_message(conf, IPKG_ERROR,
5011 + "Package %s wants to install file %s\n"
5012 + "\tBut that file is already provided by package ",
5013 + pkg->name, filename);
5014 + if (owner) {
5015 + ipkg_message(conf, IPKG_ERROR,
5016 + "%s\n", owner->name);
5017 + } else {
5018 + ipkg_message(conf, IPKG_ERROR,
5019 + "<no package>\nPlease move this file out of the way and try again.\n");
5020 + }
5021 + clashes++;
5022 + }
5023 + free(root_filename);
5024 + }
5025 + pkg_free_installed_files(pkg);
5026 +
5027 + return clashes;
5028 +}
5029 +
5030 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5031 +{
5032 + /* Basically that's the worst hack I could do to be able to change ownership of
5033 + file list, but, being that we have no way to unwind the mods, due to structure
5034 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5035 + What we do here is change the ownership of file in hash if a replace ( or similar events
5036 + happens )
5037 + Only the action that are needed to change name should be considered.
5038 + @@@ To change after 1.0 release.
5039 + */
5040 + str_list_t *files_list;
5041 + str_list_elt_t *iter;
5042 +
5043 + int clashes = 0;
5044 +
5045 + files_list = pkg_get_installed_files(pkg);
5046 + for (iter = files_list->head; iter; iter = iter->next) {
5047 + char *root_filename;
5048 + char *filename = iter->data;
5049 + root_filename = root_filename_alloc(conf, filename);
5050 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5051 + pkg_t *owner;
5052 +
5053 + if (conf->force_overwrite) {
5054 + /* but we need to change who owns this file */
5055 + file_hash_set_file_owner(conf, filename, pkg);
5056 + continue;
5057 + }
5058 +
5059 + owner = file_hash_get_file_owner(conf, filename);
5060 +
5061 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5062 + if (owner) {
5063 + if (pkg_replaces(pkg, owner)) {
5064 +/* It's now time to change the owner of that file.
5065 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5066 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5067 + file_hash_set_file_owner(conf, filename, pkg);
5068 + continue;
5069 + }
5070 + }
5071 +
5072 + }
5073 + free(root_filename);
5074 + }
5075 + pkg_free_installed_files(pkg);
5076 +
5077 + return clashes;
5078 +}
5079 +
5080 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5081 +{
5082 + /* Nothing to do since check_data_file_clashes doesn't change state */
5083 + return 0;
5084 +}
5085 +
5086 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5087 +{
5088 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5089 + 1. If the package is being upgraded, call
5090 + old-postrm upgrade new-version
5091 + 2. If this fails, attempt:
5092 + new-postrm failed-upgrade old-version
5093 + Error unwind, for both cases:
5094 + old-preinst abort-upgrade new-version */
5095 + return 0;
5096 +}
5097 +
5098 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5099 +{
5100 + /* DPKG_INCOMPATIBILITY:
5101 + dpkg does some things here that we don't do yet. Do we care?
5102 + (See postrm_upgrade_old_pkg for details)
5103 + */
5104 + return 0;
5105 +}
5106 +
5107 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5108 +{
5109 + int err;
5110 + str_list_t *old_files;
5111 + str_list_elt_t *of;
5112 + str_list_t *new_files;
5113 + str_list_elt_t *nf;
5114 +
5115 + if (old_pkg == NULL) {
5116 + return 0;
5117 + }
5118 +
5119 + old_files = pkg_get_installed_files(old_pkg);
5120 + new_files = pkg_get_installed_files(pkg);
5121 +
5122 + for (of = old_files->head; of; of = of->next) {
5123 + pkg_t *owner;
5124 + char *old, *new;
5125 + old = of->data;
5126 + for (nf = new_files->head; nf; nf = nf->next) {
5127 + new = nf->data;
5128 + if (strcmp(old, new) == 0) {
5129 + goto NOT_OBSOLETE;
5130 + }
5131 + }
5132 + if (file_is_dir(old)) {
5133 + continue;
5134 + }
5135 + owner = file_hash_get_file_owner(conf, old);
5136 + if (owner != old_pkg) {
5137 + /* in case obsolete file no longer belongs to old_pkg */
5138 + continue;
5139 + }
5140 +
5141 + /* old file is obsolete */
5142 + ipkg_message(conf, IPKG_INFO,
5143 + " removing obsolete file %s\n", old);
5144 + if (!conf->noaction) {
5145 + err = unlink(old);
5146 + if (err) {
5147 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5148 + strerror(errno));
5149 + }
5150 + }
5151 +
5152 + NOT_OBSOLETE:
5153 + ;
5154 + }
5155 +
5156 + pkg_free_installed_files(old_pkg);
5157 + pkg_free_installed_files(pkg);
5158 +
5159 + return 0;
5160 +}
5161 +
5162 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5163 +{
5164 + int i;
5165 + int err = 0;
5166 + char *globpattern;
5167 + glob_t globbuf;
5168 + if (0) {
5169 + if (!pkg->dest) {
5170 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5171 + return -1;
5172 + }
5173 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5174 + err = glob(globpattern, 0, NULL, &globbuf);
5175 + free(globpattern);
5176 + if (err) {
5177 + return err;
5178 + }
5179 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5180 + for (i = 0; i < globbuf.gl_pathc; i++) {
5181 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5182 + globbuf.gl_pathv[i], old_pkg->name);
5183 + if (!conf->noaction)
5184 + unlink(globbuf.gl_pathv[i]);
5185 + }
5186 + globfree(&globbuf);
5187 + }
5188 + return err;
5189 +}
5190 +
5191 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5192 +{
5193 + int ret;
5194 + char *prefix;
5195 +
5196 + if (old_pkg)
5197 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5198 + sprintf_alloc(&prefix, "%s.", pkg->name);
5199 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5200 + pkg->dest->info_dir,
5201 + prefix);
5202 + free(prefix);
5203 + return ret;
5204 +}
5205 +
5206 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5207 +{
5208 + /* DPKG_INCOMPATIBILITY:
5209 + This is a fairly sophisticated dpkg operation. Shall we
5210 + skip it? */
5211 +
5212 + /* Any packages all of whose files have been overwritten during the
5213 + installation, and which aren't required for dependencies, are
5214 + considered to have been removed. For each such package
5215 + 1. disappearer's-postrm disappear overwriter overwriter-version
5216 + 2. The package's maintainer scripts are removed
5217 + 3. It is noted in the status database as being in a sane state,
5218 + namely not installed (any conffiles it may have are ignored,
5219 + rather than being removed by dpkg). Note that disappearing
5220 + packages do not have their prerm called, because dpkg doesn't
5221 + know in advance that the package is going to vanish.
5222 + */
5223 + return 0;
5224 +}
5225 +
5226 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5227 +{
5228 + int err;
5229 +
5230 + /* ipkg takes a slightly different approach to data file backups
5231 + than dpkg. Rather than removing backups at this point, we
5232 + actually do the data file installation now. See comments in
5233 + check_data_file_clashes() for more details. */
5234 +
5235 + ipkg_message(conf, IPKG_INFO,
5236 + " extracting data files to %s\n", pkg->dest->root_dir);
5237 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5238 + if (err) {
5239 + return err;
5240 + }
5241 +
5242 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5243 + so we can't save ourself from removing important packages
5244 + At this point we (should) have extracted the .control file, so it
5245 + would be a good idea to reload the data in it, and set the Essential
5246 + state in *pkg. From now on the Essential is back in status file and
5247 + we can protect again.
5248 + We should operate this way:
5249 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5250 + check for "Essential" in it
5251 + set the value in pkg->essential.
5252 + This new routine could be useful also for every other flag
5253 + Pigi: 16/03/2004 */
5254 + set_flags_from_control(conf, pkg) ;
5255 +
5256 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5257 + err = pkg_write_filelist(conf, pkg);
5258 + if (err)
5259 + return err;
5260 +
5261 + /* XXX: FEATURE: ipkg should identify any files which existed
5262 + before installation and which were overwritten, (see
5263 + check_data_file_clashes()). What it must do is remove any such
5264 + files from the filelist of the old package which provided the
5265 + file. Otherwise, if the old package were removed at some point
5266 + it would break the new package. Removing the new package will
5267 + also break the old one, but this cannot be helped since the old
5268 + package's file has already been deleted. This is the importance
5269 + of check_data_file_clashes(), and only allowing ipkg to install
5270 + a clashing package with a user force. */
5271 +
5272 + return 0;
5273 +}
5274 +
5275 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5276 +{
5277 + conffile_list_elt_t *iter;
5278 + conffile_t *cf;
5279 + char *cf_backup;
5280 +
5281 + char *md5sum;
5282 +
5283 +
5284 + if (conf->noaction) return 0;
5285 +
5286 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5287 + char *root_filename;
5288 + cf = iter->data;
5289 + root_filename = root_filename_alloc(conf, cf->name);
5290 +
5291 + /* Might need to initialize the md5sum for each conffile */
5292 + if (cf->value == NULL) {
5293 + cf->value = file_md5sum_alloc(root_filename);
5294 + }
5295 +
5296 + if (!file_exists(root_filename)) {
5297 + free(root_filename);
5298 + continue;
5299 + }
5300 +
5301 + cf_backup = backup_filename_alloc(root_filename);
5302 +
5303 +
5304 + if (file_exists(cf_backup)) {
5305 + /* Let's compute md5 to test if files are changed */
5306 + md5sum = file_md5sum_alloc(cf_backup);
5307 + if (strcmp( cf->value,md5sum) != 0 ) {
5308 + if (conf->force_defaults
5309 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5310 + rename(cf_backup, root_filename);
5311 + }
5312 + }
5313 + unlink(cf_backup);
5314 + free(md5sum);
5315 + }
5316 +
5317 + free(cf_backup);
5318 + free(root_filename);
5319 + }
5320 +
5321 + return 0;
5322 +}
5323 +
5324 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5325 +{
5326 + char *response;
5327 + const char *short_file_name;
5328 +
5329 + short_file_name = strrchr(file_name, '/');
5330 + if (short_file_name) {
5331 + short_file_name++;
5332 + } else {
5333 + short_file_name = file_name;
5334 + }
5335 +
5336 + while (1) {
5337 + response = get_user_response(" Configuration file '%s'\n"
5338 + " ==> File on system created by you or by a script.\n"
5339 + " ==> File also in package provided by package maintainer.\n"
5340 + " What would you like to do about it ? Your options are:\n"
5341 + " Y or I : install the package maintainer's version\n"
5342 + " N or O : keep your currently-installed version\n"
5343 + " D : show the differences between the versions (if diff is installed)\n"
5344 + " The default action is to keep your current version.\n"
5345 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5346 + if (strcmp(response, "y") == 0
5347 + || strcmp(response, "i") == 0
5348 + || strcmp(response, "yes") == 0) {
5349 + free(response);
5350 + return 0;
5351 + }
5352 +
5353 + if (strcmp(response, "d") == 0) {
5354 + char *cmd;
5355 +
5356 + free(response);
5357 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5358 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5359 + xsystem(cmd);
5360 + free(cmd);
5361 + printf(" [Press ENTER to continue]\n");
5362 + response = file_read_line_alloc(stdin);
5363 + free(response);
5364 + continue;
5365 + }
5366 +
5367 + free(response);
5368 + return 1;
5369 + }
5370 +}
5371 +
5372 +/* XXX: CLEANUP: I'd like to move all of the code for
5373 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5374 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5375 + pkg_deinit for example). */
5376 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5377 +{
5378 + DIR *tmp_dir;
5379 + struct dirent *dirent;
5380 + char *tmp_file;
5381 +
5382 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5383 +#error
5384 + ipkg_message(conf, IPKG_DEBUG,
5385 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5386 + __FUNCTION__, pkg->tmp_unpack_dir);
5387 + return 0;
5388 +#endif
5389 +
5390 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5391 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5392 + if (tmp_dir) {
5393 + while (1) {
5394 + dirent = readdir(tmp_dir);
5395 + if (dirent == NULL) {
5396 + break;
5397 + }
5398 + sprintf_alloc(&tmp_file, "%s/%s",
5399 + pkg->tmp_unpack_dir, dirent->d_name);
5400 + if (! file_is_dir(tmp_file)) {
5401 + unlink(tmp_file);
5402 + }
5403 + free(tmp_file);
5404 + }
5405 + closedir(tmp_dir);
5406 + rmdir(pkg->tmp_unpack_dir);
5407 + free(pkg->tmp_unpack_dir);
5408 + pkg->tmp_unpack_dir = NULL;
5409 + }
5410 + }
5411 +
5412 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5413 + pkg->name, pkg->local_filename, conf->tmp_dir);
5414 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5415 + unlink(pkg->local_filename);
5416 + free(pkg->local_filename);
5417 + pkg->local_filename = NULL;
5418 + }
5419 +
5420 + return 0;
5421 +}
5422 +
5423 +static char *backup_filename_alloc(const char *file_name)
5424 +{
5425 + char *backup;
5426 +
5427 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5428 +
5429 + return backup;
5430 +}
5431 +
5432 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5433 +{
5434 + int err;
5435 + char *backup;
5436 +
5437 + backup = backup_filename_alloc(file_name);
5438 + err = file_copy(file_name, backup);
5439 + if (err) {
5440 + ipkg_message(conf, IPKG_ERROR,
5441 + "%s: Failed to copy %s to %s\n",
5442 + __FUNCTION__, file_name, backup);
5443 + }
5444 +
5445 + free(backup);
5446 +
5447 + return err;
5448 +}
5449 +
5450 +static int backup_exists_for(const char *file_name)
5451 +{
5452 + int ret;
5453 + char *backup;
5454 +
5455 + backup = backup_filename_alloc(file_name);
5456 +
5457 + ret = file_exists(backup);
5458 +
5459 + free(backup);
5460 +
5461 + return ret;
5462 +}
5463 +
5464 +static int backup_remove(const char *file_name)
5465 +{
5466 + char *backup;
5467 +
5468 + backup = backup_filename_alloc(file_name);
5469 + unlink(backup);
5470 + free(backup);
5471 +
5472 + return 0;
5473 +}
5474 +
5475 +\f
5476 +
5477 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5478 +
5479 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5480 +{
5481 + /* first, remove the packages that need removing */
5482 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5483 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5484 + err = ipkg_remove_pkg(conf, pkg,0);
5485 + if (err) return err;
5486 + }
5487 + return 0;
5488 +}
5489 +
5490 +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)
5491 +{
5492 + int i;
5493 + /* now one more pass checking on the ones that need to be installed */
5494 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5495 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5496 + if (pkg->dest == NULL)
5497 + pkg->dest = conf->default_dest;
5498 +
5499 + pkg->state_want = SW_INSTALL;
5500 +
5501 + /* Abhaya: conflicts check */
5502 + err = check_conflicts_for(conf, pkg);
5503 + if (err) { return err; }
5504 + }
5505 + return 0;
5506 +}
5507 +
5508 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5509 +{
5510 + int i;
5511 + /* now one more pass checking on the ones that need to be installed */
5512 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5513 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5514 +
5515 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5516 + pkg_vec_t *replacees = pkg_vec_alloc();
5517 + pkg_get_installed_replacees(conf, pkg, replacees);
5518 +
5519 + /* XXX: BUG: we really should treat replacement more like an upgrade
5520 + * Instead, we're going to remove the replacees
5521 + */
5522 + err = pkg_remove_installed_replacees(conf, replacees);
5523 + if (err) return err;
5524 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5525 + }
5526 + return 0;
5527 +}
5528 +
5529 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5530 +{
5531 + int i;
5532 + /* now one more pass checking on the ones that need to be installed */
5533 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5534 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5535 + if (pkg->local_filename == NULL) {
5536 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5537 + if (err) {
5538 + ipkg_message(conf, IPKG_ERROR,
5539 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5540 + pkg->name);
5541 + return err;
5542 + }
5543 + }
5544 + if (pkg->tmp_unpack_dir == NULL) {
5545 + err = unpack_pkg_control_files(conf, pkg);
5546 + if (err) return err;
5547 + }
5548 + }
5549 + return 0;
5550 +}
5551 +
5552 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5553 +{
5554 + int i;
5555 + /* now one more pass checking on the ones that need to be installed */
5556 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5557 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5558 + pkg_t *old_pkg = pkg->old_pkg;
5559 +
5560 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5561 + if (err) return err;
5562 +
5563 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5564 + if (err) return err;
5565 +
5566 + err = preinst_configure(conf, pkg, old_pkg);
5567 + if (err) return err;
5568 +
5569 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5570 + if (err) return err;
5571 +
5572 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5573 + if (err) return err;
5574 + }
5575 + return 0;
5576 +}
5577 +
5578 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5579 +{
5580 + int i;
5581 + /* now one more pass checking on the ones that need to be installed */
5582 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5583 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5584 + pkg_t *old_pkg = pkg->old_pkg;
5585 +
5586 + if (old_pkg) {
5587 + old_pkg->state_want = SW_DEINSTALL;
5588 +
5589 + if (old_pkg->state_flag & SF_NOPRUNE) {
5590 + ipkg_message(conf, IPKG_INFO,
5591 + " not removing obsolesced files because package marked noprune\n");
5592 + } else {
5593 + ipkg_message(conf, IPKG_INFO,
5594 + " removing obsolesced files\n");
5595 + remove_obsolesced_files(conf, pkg, old_pkg);
5596 + }
5597 + }
5598 +
5599 + ipkg_message(conf, IPKG_INFO,
5600 + " installing maintainer scripts\n");
5601 + install_maintainer_scripts(conf, pkg, old_pkg);
5602 +
5603 + /* the following just returns 0 */
5604 + remove_disappeared(conf, pkg);
5605 +
5606 + ipkg_message(conf, IPKG_INFO,
5607 + " installing data files\n");
5608 + install_data_files(conf, pkg);
5609 +
5610 + ipkg_message(conf, IPKG_INFO,
5611 + " resolving conf files\n");
5612 + resolve_conffiles(conf, pkg);
5613 +
5614 + pkg->state_status = SS_UNPACKED;
5615 +
5616 + if (old_pkg) {
5617 + old_pkg->state_status = SS_NOT_INSTALLED;
5618 + }
5619 +
5620 + time(&pkg->installed_time);
5621 +
5622 + ipkg_message(conf, IPKG_INFO,
5623 + " cleanup temp files\n");
5624 + cleanup_temporary_files(conf, pkg);
5625 +
5626 + if (pkg->parent)
5627 + pkg->parent->state_status = pkg->state_status;
5628 + }
5629 + return 0;
5630 +}
5631 +
5632 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5633 +{
5634 + int i;
5635 + /* now one more pass checking on the ones that need to be installed */
5636 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5637 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5638 + pkg_t *old_pkg = pkg->old_pkg;
5639 +
5640 + if (old_pkg) {
5641 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5642 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5643 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5644 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5645 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5646 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5647 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5648 + preinst_configure_unwind(conf, pkg, old_pkg);
5649 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5650 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5651 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5652 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5653 +
5654 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5655 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5656 +
5657 + }
5658 + }
5659 + return 0;
5660 +}
5661 +
5662 +/*
5663 + * Perform all the actions.
5664 + *
5665 + * pkgs_to_remove are packages marked for removal.
5666 + * pkgs_superseded are the old packages being replaced by upgrades.
5667 + *
5668 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5669 + */
5670 +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)
5671 +{
5672 + int err;
5673 + int i;
5674 +
5675 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5676 + if (err) return err;
5677 +
5678 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5679 + if (err) return err;
5680 +
5681 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5682 + if (err) goto UNWIND;
5683 +
5684 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5685 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5686 + if (err) goto UNWIND;
5687 +
5688 + /*
5689 + * Now that we have the packages unpacked, we can look for data
5690 + * file clashes. First, we mark the files from the superseded
5691 + * packages as obsolete. Then we scan the files in
5692 + * pkgs_to_install, and only complain about clashes with
5693 + * non-obsolete files.
5694 + */
5695 +
5696 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5697 + if (err) goto UNWIND;
5698 +
5699 + /* this was before checking data file clashes */
5700 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5701 + if (err) goto UNWIND;
5702 +
5703 + /* point of no return: no unwinding after this */
5704 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5705 + if (err) return err;
5706 +
5707 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5708 + return 0;
5709 +
5710 + UNWIND:
5711 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5712 +
5713 + ipkg_message(conf, IPKG_INFO,
5714 + " cleanup temp files\n");
5715 + cleanup_temporary_files(conf, pkg);
5716 +
5717 + ipkg_message(conf, IPKG_INFO,
5718 + "Failed.\n");
5719 + return err;
5720 +}
5721 +
5722 +#endif
5723 Index: busybox-1.4.2/archival/libipkg/ipkg_install.h
5724 ===================================================================
5725 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5726 +++ busybox-1.4.2/archival/libipkg/ipkg_install.h 2007-06-04 13:21:36.715395080 +0200
5727 @@ -0,0 +1,35 @@
5728 +/* ipkg_install.h - the itsy package management system
5729 +
5730 + Carl D. Worth
5731 +
5732 + Copyright (C) 2001 University of Southern California
5733 +
5734 + This program is free software; you can redistribute it and/or
5735 + modify it under the terms of the GNU General Public License as
5736 + published by the Free Software Foundation; either version 2, or (at
5737 + your option) any later version.
5738 +
5739 + This program is distributed in the hope that it will be useful, but
5740 + WITHOUT ANY WARRANTY; without even the implied warranty of
5741 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5742 + General Public License for more details.
5743 +*/
5744 +
5745 +#ifndef IPKG_INSTALL_H
5746 +#define IPKG_INSTALL_H
5747 +
5748 +#include "pkg.h"
5749 +#include "ipkg_conf.h"
5750 +
5751 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5752 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5753 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5754 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5755 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5756 +
5757 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5758 +
5759 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5760 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5761 +
5762 +#endif
5763 Index: busybox-1.4.2/archival/libipkg/ipkg_message.c
5764 ===================================================================
5765 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5766 +++ busybox-1.4.2/archival/libipkg/ipkg_message.c 2007-06-04 13:21:36.715395080 +0200
5767 @@ -0,0 +1,61 @@
5768 +/* ipkg_message.c - the itsy package management system
5769 +
5770 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5771 +
5772 + This program is free software; you can redistribute it and/or
5773 + modify it under the terms of the GNU General Public License as
5774 + published by the Free Software Foundation; either version 2, or (at
5775 + your option) any later version.
5776 +
5777 + This program is distributed in the hope that it will be useful, but
5778 + WITHOUT ANY WARRANTY; without even the implied warranty of
5779 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5780 + General Public License for more details.
5781 +*/
5782 +
5783 +
5784 +#include "ipkg.h"
5785 +#include "ipkg_conf.h"
5786 +#include "ipkg_message.h"
5787 +
5788 +#ifndef IPKG_LIB
5789 +
5790 +void
5791 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5792 +{
5793 + va_list ap;
5794 +
5795 + if (conf && (conf->verbosity < level))
5796 + {
5797 + return;
5798 + }
5799 + else
5800 + {
5801 +
5802 + va_start (ap, fmt);
5803 + vprintf (fmt, ap);
5804 + va_end (ap);
5805 + }
5806 +}
5807 +
5808 +#else
5809 +
5810 +#include "libipkg.h"
5811 +
5812 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5813 +
5814 +void
5815 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5816 +{
5817 + va_list ap;
5818 + char ts[256];
5819 +
5820 + if (ipkg_cb_message)
5821 + {
5822 + va_start (ap, fmt);
5823 + vsnprintf (ts,256,fmt, ap);
5824 + va_end (ap);
5825 + ipkg_cb_message(conf,level,ts);
5826 + }
5827 +}
5828 +#endif
5829 Index: busybox-1.4.2/archival/libipkg/ipkg_message.h
5830 ===================================================================
5831 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5832 +++ busybox-1.4.2/archival/libipkg/ipkg_message.h 2007-06-04 13:21:36.715395080 +0200
5833 @@ -0,0 +1,32 @@
5834 +/* ipkg_message.h - the itsy package management system
5835 +
5836 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5837 +
5838 + This program is free software; you can redistribute it and/or
5839 + modify it under the terms of the GNU General Public License as
5840 + published by the Free Software Foundation; either version 2, or (at
5841 + your option) any later version.
5842 +
5843 + This program is distributed in the hope that it will be useful, but
5844 + WITHOUT ANY WARRANTY; without even the implied warranty of
5845 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5846 + General Public License for more details.
5847 +*/
5848 +
5849 +#ifndef _IPKG_MESSAGE_H_
5850 +#define _IPKG_MESSAGE_H_
5851 +
5852 +#include "ipkg.h"
5853 +#include "ipkg_conf.h"
5854 +
5855 +typedef enum {
5856 + IPKG_ERROR, /* error conditions */
5857 + IPKG_NOTICE, /* normal but significant condition */
5858 + IPKG_INFO, /* informational message */
5859 + IPKG_DEBUG, /* debug level message */
5860 + IPKG_DEBUG2, /* more debug level message */
5861 +} message_level_t;
5862 +
5863 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5864 +
5865 +#endif /* _IPKG_MESSAGE_H_ */
5866 Index: busybox-1.4.2/archival/libipkg/ipkg_remove.c
5867 ===================================================================
5868 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5869 +++ busybox-1.4.2/archival/libipkg/ipkg_remove.c 2007-06-04 13:21:36.716394928 +0200
5870 @@ -0,0 +1,383 @@
5871 +/* ipkg_remove.c - the itsy package management system
5872 +
5873 + Carl D. Worth
5874 +
5875 + Copyright (C) 2001 University of Southern California
5876 +
5877 + This program is free software; you can redistribute it and/or
5878 + modify it under the terms of the GNU General Public License as
5879 + published by the Free Software Foundation; either version 2, or (at
5880 + your option) any later version.
5881 +
5882 + This program is distributed in the hope that it will be useful, but
5883 + WITHOUT ANY WARRANTY; without even the implied warranty of
5884 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5885 + General Public License for more details.
5886 +*/
5887 +
5888 +#include "ipkg.h"
5889 +#include "ipkg_message.h"
5890 +
5891 +#include <glob.h>
5892 +
5893 +#include "ipkg_remove.h"
5894 +
5895 +#include "file_util.h"
5896 +#include "sprintf_alloc.h"
5897 +#include "str_util.h"
5898 +
5899 +#include "ipkg_cmd.h"
5900 +
5901 +/*
5902 + * Returns number of the number of packages depending on the packages provided by this package.
5903 + * Every package implicitly provides itself.
5904 + */
5905 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5906 +{
5907 + int nprovides = pkg->provides_count;
5908 + abstract_pkg_t **provides = pkg->provides;
5909 + int n_installed_dependents = 0;
5910 + int i;
5911 + for (i = 0; i <= nprovides; i++) {
5912 + abstract_pkg_t *providee = provides[i];
5913 + abstract_pkg_t **dependers = providee->depended_upon_by;
5914 + abstract_pkg_t *dep_ab_pkg;
5915 + if (dependers == NULL)
5916 + continue;
5917 + while ((dep_ab_pkg = *dependers++) != NULL) {
5918 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5919 + n_installed_dependents++;
5920 + }
5921 + }
5922 +
5923 + }
5924 + /* if caller requested the set of installed dependents */
5925 + if (pdependents) {
5926 + int p = 0;
5927 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5928 +
5929 + if ( dependents == NULL ){
5930 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5931 + return -1;
5932 + }
5933 +
5934 + *pdependents = dependents;
5935 + for (i = 0; i <= nprovides; i++) {
5936 + abstract_pkg_t *providee = provides[i];
5937 + abstract_pkg_t **dependers = providee->depended_upon_by;
5938 + abstract_pkg_t *dep_ab_pkg;
5939 + if (dependers == NULL)
5940 + continue;
5941 + while ((dep_ab_pkg = *dependers++) != NULL) {
5942 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5943 + dependents[p++] = dep_ab_pkg;
5944 + dep_ab_pkg->state_flag |= SF_MARKED;
5945 + }
5946 + }
5947 + }
5948 + dependents[p] = NULL;
5949 + /* now clear the marks */
5950 + for (i = 0; i < p; i++) {
5951 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5952 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5953 + }
5954 + }
5955 + return n_installed_dependents;
5956 +}
5957 +
5958 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5959 +{
5960 + int i;
5961 + int a;
5962 + int count;
5963 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5964 + abstract_pkg_t * ab_pkg;
5965 +
5966 + if((ab_pkg = pkg->parent) == NULL){
5967 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5968 + __FUNCTION__, pkg->name);
5969 + return 0;
5970 + }
5971 +
5972 + if (dependents == NULL)
5973 + return 0;
5974 +
5975 + // here i am using the dependencies_checked
5976 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5977 + return 0; // has already been encountered in the process
5978 + // of marking packages for removal - Karthik
5979 + ab_pkg->dependencies_checked = 2;
5980 +
5981 + i = 0;
5982 + count = 1;
5983 + while (dependents [i] != NULL) {
5984 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5985 +
5986 + if (dep_ab_pkg->dependencies_checked == 2){
5987 + i++;
5988 + continue;
5989 + }
5990 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5991 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5992 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5993 + if (dep_pkg->state_status == SS_INSTALLED) {
5994 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5995 + count++;
5996 + }
5997 + }
5998 + }
5999 + i++;
6000 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6001 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6002 + }
6003 +
6004 + if (count == 1)
6005 + return 0;
6006 +
6007 +
6008 + for (i = 0; i < dependent_pkgs->len; i++) {
6009 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6010 + if (err)
6011 + return err;
6012 + }
6013 + return 0;
6014 +}
6015 +
6016 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6017 +{
6018 + abstract_pkg_t *dep_ab_pkg;
6019 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6020 + while ((dep_ab_pkg = *dependents++) != NULL) {
6021 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6022 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6023 + }
6024 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6025 + ipkg_message(conf, IPKG_ERROR, "");
6026 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6027 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6028 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6029 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6030 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6031 + return 0;
6032 +}
6033 +
6034 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6035 +{
6036 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6037 + thus I wan't check for essential, as I'm upgrading.
6038 + I hope it won't break anything :)
6039 +*/
6040 + int err;
6041 + abstract_pkg_t *parent_pkg = NULL;
6042 +
6043 + if (pkg->essential && !message) {
6044 + if (conf->force_removal_of_essential_packages) {
6045 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6046 + "\tIf your system breaks, you get to keep both pieces\n",
6047 + pkg->name);
6048 + } else {
6049 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6050 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6051 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6052 + "\tits will with the option: -force-removal-of-essential-packages\n",
6053 + pkg->name);
6054 + return IPKG_PKG_IS_ESSENTIAL;
6055 + }
6056 + }
6057 +
6058 + if ((parent_pkg = pkg->parent) == NULL)
6059 + return 0;
6060 +
6061 + /* only attempt to remove dependent installed packages if
6062 + * force_depends is not specified or the package is being
6063 + * replaced.
6064 + */
6065 + if (!conf->force_depends
6066 + && !(pkg->state_flag & SF_REPLACE)) {
6067 + abstract_pkg_t **dependents;
6068 + int has_installed_dependents =
6069 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6070 +
6071 + if (has_installed_dependents) {
6072 + /*
6073 + * if this package is depended up by others, then either we should
6074 + * not remove it or we should remove it and all of its dependents
6075 + */
6076 +
6077 + if (!conf->force_removal_of_dependent_packages
6078 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6079 + return IPKG_PKG_HAS_DEPENDENTS;
6080 + }
6081 +
6082 + /* remove packages depending on this package - Karthik */
6083 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6084 + free(dependents);
6085 + if (err) return err;
6086 + }
6087 + }
6088 +
6089 + if ( message==0 ){
6090 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6091 + fflush(stdout);
6092 + }
6093 + pkg->state_flag |= SF_FILELIST_CHANGED;
6094 +
6095 + pkg->state_want = SW_DEINSTALL;
6096 + ipkg_state_changed++;
6097 +
6098 + pkg_run_script(conf, pkg, "prerm", "remove");
6099 +
6100 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6101 + maintains an empty filelist rather than deleting it. That seems
6102 + like a big pain, and I don't see that that should make a big
6103 + difference, but for anyone who wants tighter compatibility,
6104 + feel free to fix this. */
6105 + remove_data_files_and_list(conf, pkg);
6106 +
6107 + pkg_run_script(conf, pkg, "postrm", "remove");
6108 +
6109 + remove_maintainer_scripts_except_postrm(conf, pkg);
6110 +
6111 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6112 + * space, it doesn't make sense to leave extra configurations, files,
6113 + * and maintainer scripts left around. So, we make remove like purge,
6114 + * and take out all the crap :) */
6115 +
6116 + remove_postrm(conf, pkg);
6117 + pkg->state_status = SS_NOT_INSTALLED;
6118 +
6119 + if (parent_pkg)
6120 + parent_pkg->state_status = SS_NOT_INSTALLED;
6121 +
6122 + return 0;
6123 +}
6124 +
6125 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6126 +{
6127 + ipkg_remove_pkg(conf, pkg,0);
6128 + return 0;
6129 +}
6130 +
6131 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6132 +{
6133 + str_list_t installed_dirs;
6134 + str_list_t *installed_files;
6135 + str_list_elt_t *iter;
6136 + char *file_name;
6137 + conffile_t *conffile;
6138 + int removed_a_dir;
6139 + pkg_t *owner;
6140 +
6141 + str_list_init(&installed_dirs);
6142 + installed_files = pkg_get_installed_files(pkg);
6143 +
6144 + for (iter = installed_files->head; iter; iter = iter->next) {
6145 + file_name = iter->data;
6146 +
6147 + if (file_is_dir(file_name)) {
6148 + str_list_append(&installed_dirs, strdup(file_name));
6149 + continue;
6150 + }
6151 +
6152 + conffile = pkg_get_conffile(pkg, file_name);
6153 + if (conffile) {
6154 + /* XXX: QUESTION: Is this right? I figure we only need to
6155 + save the conffile if it has been modified. Is that what
6156 + dpkg does? Or does dpkg preserve all conffiles? If so,
6157 + this seems like a better thing to do to conserve
6158 + space. */
6159 + if (conffile_has_been_modified(conf, conffile)) {
6160 + printf(" not deleting modified conffile %s\n", file_name);
6161 + fflush(stdout);
6162 + continue;
6163 + }
6164 + }
6165 +
6166 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6167 + if (!conf->noaction)
6168 + unlink(file_name);
6169 + }
6170 +
6171 + if (!conf->noaction) {
6172 + do {
6173 + removed_a_dir = 0;
6174 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6175 + file_name = iter->data;
6176 +
6177 + if (rmdir(file_name) == 0) {
6178 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6179 + removed_a_dir = 1;
6180 + str_list_remove(&installed_dirs, &iter);
6181 + }
6182 + }
6183 + } while (removed_a_dir);
6184 + }
6185 +
6186 + pkg_free_installed_files(pkg);
6187 + /* We have to remove the file list now, so that
6188 + find_pkg_owning_file does not always just report this package */
6189 + pkg_remove_installed_files_list(conf, pkg);
6190 +
6191 + /* Don't print warning for dirs that are provided by other packages */
6192 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6193 + file_name = iter->data;
6194 +
6195 + owner = file_hash_get_file_owner(conf, file_name);
6196 + if (owner) {
6197 + free(iter->data);
6198 + iter->data = NULL;
6199 + str_list_remove(&installed_dirs, &iter);
6200 + }
6201 + }
6202 +
6203 + /* cleanup */
6204 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6205 + free(iter->data);
6206 + iter->data = NULL;
6207 + }
6208 + str_list_deinit(&installed_dirs);
6209 +
6210 + return 0;
6211 +}
6212 +
6213 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6214 +{
6215 + int i, err;
6216 + char *globpattern;
6217 + glob_t globbuf;
6218 +
6219 + if (conf->noaction) return 0;
6220 +
6221 + sprintf_alloc(&globpattern, "%s/%s.*",
6222 + pkg->dest->info_dir, pkg->name);
6223 + err = glob(globpattern, 0, NULL, &globbuf);
6224 + free(globpattern);
6225 + if (err) {
6226 + return 0;
6227 + }
6228 +
6229 + for (i = 0; i < globbuf.gl_pathc; i++) {
6230 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6231 + continue;
6232 + }
6233 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6234 + unlink(globbuf.gl_pathv[i]);
6235 + }
6236 + globfree(&globbuf);
6237 +
6238 + return 0;
6239 +}
6240 +
6241 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6242 +{
6243 + char *postrm_file_name;
6244 +
6245 + if (conf->noaction) return 0;
6246 +
6247 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6248 + pkg->dest->info_dir, pkg->name);
6249 + unlink(postrm_file_name);
6250 + free(postrm_file_name);
6251 +
6252 + return 0;
6253 +}
6254 Index: busybox-1.4.2/archival/libipkg/ipkg_remove.h
6255 ===================================================================
6256 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6257 +++ busybox-1.4.2/archival/libipkg/ipkg_remove.h 2007-06-04 13:21:36.716394928 +0200
6258 @@ -0,0 +1,33 @@
6259 +/* ipkg_remove.h - the itsy package management system
6260 +
6261 + Carl D. Worth
6262 +
6263 + Copyright (C) 2001 University of Southern California
6264 +
6265 + This program is free software; you can redistribute it and/or
6266 + modify it under the terms of the GNU General Public License as
6267 + published by the Free Software Foundation; either version 2, or (at
6268 + your option) any later version.
6269 +
6270 + This program is distributed in the hope that it will be useful, but
6271 + WITHOUT ANY WARRANTY; without even the implied warranty of
6272 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6273 + General Public License for more details.
6274 +*/
6275 +
6276 +#ifndef IPKG_REMOVE_H
6277 +#define IPKG_REMOVE_H
6278 +
6279 +#include "pkg.h"
6280 +#include "ipkg_conf.h"
6281 +
6282 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6283 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6284 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6285 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6286 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6287 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6288 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6289 +
6290 +
6291 +#endif
6292 Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.c
6293 ===================================================================
6294 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6295 +++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.c 2007-06-04 13:21:36.716394928 +0200
6296 @@ -0,0 +1,77 @@
6297 +/* ipkg_upgrade.c - the itsy package management system
6298 +
6299 + Carl D. Worth
6300 + Copyright (C) 2001 University of Southern California
6301 +
6302 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6303 +
6304 + This program is free software; you can redistribute it and/or
6305 + modify it under the terms of the GNU General Public License as
6306 + published by the Free Software Foundation; either version 2, or (at
6307 + your option) any later version.
6308 +
6309 + This program is distributed in the hope that it will be useful, but
6310 + WITHOUT ANY WARRANTY; without even the implied warranty of
6311 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6312 + General Public License for more details.
6313 +*/
6314 +
6315 +#include "ipkg.h"
6316 +#include "ipkg_install.h"
6317 +#include "ipkg_message.h"
6318 +
6319 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6320 +{
6321 + pkg_t *new;
6322 + int cmp;
6323 + char *old_version, *new_version;
6324 +
6325 + if (old->state_flag & SF_HOLD) {
6326 + ipkg_message(conf, IPKG_NOTICE,
6327 + "Not upgrading package %s which is marked "
6328 + "hold (flags=%#x)\n", old->name, old->state_flag);
6329 + return 0;
6330 + }
6331 +
6332 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6333 + if (new == NULL) {
6334 + old_version = pkg_version_str_alloc(old);
6335 + ipkg_message(conf, IPKG_NOTICE,
6336 + "Assuming locally installed package %s (%s) "
6337 + "is up to date.\n", old->name, old_version);
6338 + free(old_version);
6339 + return 0;
6340 + }
6341 +
6342 + old_version = pkg_version_str_alloc(old);
6343 + new_version = pkg_version_str_alloc(new);
6344 +
6345 + cmp = pkg_compare_versions(old, new);
6346 + ipkg_message(conf, IPKG_DEBUG,
6347 + "comparing visible versions of pkg %s:"
6348 + "\n\t%s is installed "
6349 + "\n\t%s is available "
6350 + "\n\t%d was comparison result\n",
6351 + old->name, old_version, new_version, cmp);
6352 + if (cmp == 0) {
6353 + ipkg_message(conf, IPKG_INFO,
6354 + "Package %s (%s) installed in %s is up to date.\n",
6355 + old->name, old_version, old->dest->name);
6356 + free(old_version);
6357 + free(new_version);
6358 + return 0;
6359 + } else if (cmp > 0) {
6360 + ipkg_message(conf, IPKG_NOTICE,
6361 + "Not downgrading package %s on %s from %s to %s.\n",
6362 + old->name, old->dest->name, old_version, new_version);
6363 + free(old_version);
6364 + free(new_version);
6365 + return 0;
6366 + } else if (cmp < 0) {
6367 + new->dest = old->dest;
6368 + old->state_want = SW_DEINSTALL;
6369 + }
6370 +
6371 + new->state_flag |= SF_USER;
6372 + return ipkg_install_pkg(conf, new,1);
6373 +}
6374 Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.h
6375 ===================================================================
6376 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6377 +++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.h 2007-06-04 13:21:36.716394928 +0200
6378 @@ -0,0 +1,18 @@
6379 +/* ipkg_upgrade.c - the itsy package management system
6380 +
6381 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6382 +
6383 + This program is free software; you can redistribute it and/or
6384 + modify it under the terms of the GNU General Public License as
6385 + published by the Free Software Foundation; either version 2, or (at
6386 + your option) any later version.
6387 +
6388 + This program is distributed in the hope that it will be useful, but
6389 + WITHOUT ANY WARRANTY; without even the implied warranty of
6390 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6391 + General Public License for more details.
6392 +*/
6393 +
6394 +#include "ipkg.h"
6395 +
6396 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6397 Index: busybox-1.4.2/archival/libipkg/ipkg_utils.c
6398 ===================================================================
6399 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6400 +++ busybox-1.4.2/archival/libipkg/ipkg_utils.c 2007-06-04 13:21:36.716394928 +0200
6401 @@ -0,0 +1,181 @@
6402 +/* ipkg_utils.c - the itsy package management system
6403 +
6404 + Steven M. Ayer
6405 +
6406 + Copyright (C) 2002 Compaq Computer Corporation
6407 +
6408 + This program is free software; you can redistribute it and/or
6409 + modify it under the terms of the GNU General Public License as
6410 + published by the Free Software Foundation; either version 2, or (at
6411 + your option) any later version.
6412 +
6413 + This program is distributed in the hope that it will be useful, but
6414 + WITHOUT ANY WARRANTY; without even the implied warranty of
6415 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6416 + General Public License for more details.
6417 +*/
6418 +
6419 +#include "ipkg.h"
6420 +#include <errno.h>
6421 +#include <ctype.h>
6422 +#include <sys/vfs.h>
6423 +
6424 +#include "ipkg_utils.h"
6425 +#include "pkg.h"
6426 +#include "pkg_hash.h"
6427 +
6428 +struct errlist* error_list;
6429 +
6430 +int get_available_blocks(char * filesystem)
6431 +{
6432 + struct statfs sfs;
6433 +
6434 + if(statfs(filesystem, &sfs)){
6435 + fprintf(stderr, "bad statfs\n");
6436 + return 0;
6437 + }
6438 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6439 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6440 +}
6441 +
6442 +char **read_raw_pkgs_from_file(const char *file_name)
6443 +{
6444 + FILE *fp;
6445 + char **ret;
6446 +
6447 + if(!(fp = fopen(file_name, "r"))){
6448 + fprintf(stderr, "can't get %s open for read\n", file_name);
6449 + return NULL;
6450 + }
6451 +
6452 + ret = read_raw_pkgs_from_stream(fp);
6453 +
6454 + fclose(fp);
6455 +
6456 + return ret;
6457 +}
6458 +
6459 +char **read_raw_pkgs_from_stream(FILE *fp)
6460 +{
6461 + char **raw = NULL, *buf, *scout;
6462 + int count = 0;
6463 + size_t size = 512;
6464 +
6465 + buf = malloc (size);
6466 +
6467 + while (fgets(buf, size, fp)) {
6468 + while (strlen (buf) == (size - 1)
6469 + && buf[size-2] != '\n') {
6470 + size_t o = size - 1;
6471 + size *= 2;
6472 + buf = realloc (buf, size);
6473 + if (fgets (buf + o, size - o, fp) == NULL)
6474 + break;
6475 + }
6476 +
6477 + if(!(count % 50))
6478 + raw = realloc(raw, (count + 50) * sizeof(char *));
6479 +
6480 + if((scout = strchr(buf, '\n')))
6481 + *scout = '\0';
6482 +
6483 + raw[count++] = strdup(buf);
6484 + }
6485 +
6486 + raw = realloc(raw, (count + 1) * sizeof(char *));
6487 + raw[count] = NULL;
6488 +
6489 + free (buf);
6490 +
6491 + return raw;
6492 +}
6493 +
6494 +/* something to remove whitespace, a hash pooper */
6495 +char *trim_alloc(char *line)
6496 +{
6497 + char *new;
6498 + char *dest, *src, *end;
6499 +
6500 + new = malloc(strlen(line) + 1);
6501 + if ( new == NULL ){
6502 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6503 + return NULL;
6504 + }
6505 + dest = new, src = line, end = line + (strlen(line) - 1);
6506 +
6507 + /* remove it from the front */
6508 + while(src &&
6509 + isspace(*src) &&
6510 + *src)
6511 + src++;
6512 + /* and now from the back */
6513 + while((end > src) &&
6514 + isspace(*end))
6515 + end--;
6516 + end++;
6517 + *end = '\0';
6518 + strcpy(new, src);
6519 + /* this does from the first space
6520 + * blasting away any versions stuff in depends
6521 + while(src &&
6522 + !isspace(*src) &&
6523 + *src)
6524 + *dest++ = *src++;
6525 + *dest = '\0';
6526 + */
6527 +
6528 + return new;
6529 +}
6530 +
6531 +int line_is_blank(const char *line)
6532 +{
6533 + const char *s;
6534 +
6535 + for (s = line; *s; s++) {
6536 + if (!isspace(*s))
6537 + return 0;
6538 + }
6539 + return 1;
6540 +}
6541 +
6542 +void push_error_list(struct errlist ** errors, char * msg){
6543 + struct errlist *err_lst_tmp;
6544 +
6545 +
6546 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6547 + err_lst_tmp->errmsg=strdup(msg) ;
6548 + err_lst_tmp->next = *errors;
6549 + *errors = err_lst_tmp;
6550 +}
6551 +
6552 +
6553 +void reverse_error_list(struct errlist **errors){
6554 + struct errlist *result=NULL;
6555 + struct errlist *current= *errors;
6556 + struct errlist *next;
6557 +
6558 + while ( current != NULL ) {
6559 + next = current->next;
6560 + current->next=result;
6561 + result=current;
6562 + current=next;
6563 + }
6564 + *errors=result;
6565 +
6566 +}
6567 +
6568 +
6569 +void free_error_list(struct errlist **errors){
6570 + struct errlist *current = *errors;
6571 +
6572 + while (current != NULL) {
6573 + free(current->errmsg);
6574 + current = (*errors)->next;
6575 + free(*errors);
6576 + *errors = current;
6577 + }
6578 +
6579 +
6580 +}
6581 +
6582 +
6583 Index: busybox-1.4.2/archival/libipkg/ipkg_utils.h
6584 ===================================================================
6585 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6586 +++ busybox-1.4.2/archival/libipkg/ipkg_utils.h 2007-06-04 13:21:36.717394776 +0200
6587 @@ -0,0 +1,29 @@
6588 +/* ipkg_utils.h - the itsy package management system
6589 +
6590 + Steven M. Ayer
6591 +
6592 + Copyright (C) 2002 Compaq Computer Corporation
6593 +
6594 + This program is free software; you can redistribute it and/or
6595 + modify it under the terms of the GNU General Public License as
6596 + published by the Free Software Foundation; either version 2, or (at
6597 + your option) any later version.
6598 +
6599 + This program is distributed in the hope that it will be useful, but
6600 + WITHOUT ANY WARRANTY; without even the implied warranty of
6601 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6602 + General Public License for more details.
6603 +*/
6604 +
6605 +#ifndef IPKG_UTILS_H
6606 +#define IPKG_UTILS_H
6607 +
6608 +#include "pkg.h"
6609 +
6610 +int get_available_blocks(char * filesystem);
6611 +char **read_raw_pkgs_from_file(const char *file_name);
6612 +char **read_raw_pkgs_from_stream(FILE *fp);
6613 +char *trim_alloc(char * line);
6614 +int line_is_blank(const char *line);
6615 +
6616 +#endif
6617 Index: busybox-1.4.2/archival/libipkg/Kbuild
6618 ===================================================================
6619 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6620 +++ busybox-1.4.2/archival/libipkg/Kbuild 2007-06-04 13:21:36.717394776 +0200
6621 @@ -0,0 +1,60 @@
6622 +# Makefile for busybox
6623 +#
6624 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6625 +# Copyright (C) 2006 OpenWrt.org
6626 +#
6627 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6628 +
6629 +LIBIPKG_CORE_OBJS:= \
6630 + args.o \
6631 + libipkg.o \
6632 + user.o \
6633 +
6634 +LIBIPKG_CMD_OBJS:= \
6635 + ipkg_cmd.o \
6636 + ipkg_configure.o \
6637 + ipkg_download.o \
6638 + ipkg_install.o \
6639 + ipkg_remove.o \
6640 + ipkg_upgrade.o \
6641 +
6642 +LIBIPKG_DB_OBJS:= \
6643 + hash_table.o \
6644 + ipkg_conf.o \
6645 + ipkg_utils.o \
6646 + pkg.o \
6647 + pkg_depends.o \
6648 + pkg_extract.o \
6649 + pkg_hash.o \
6650 + pkg_parse.o \
6651 + pkg_vec.o \
6652 +
6653 +LIBIPKG_LIST_OBJS:= \
6654 + conffile.o \
6655 + conffile_list.o \
6656 + nv_pair.o \
6657 + nv_pair_list.o \
6658 + pkg_dest.o \
6659 + pkg_dest_list.o \
6660 + pkg_src.o \
6661 + pkg_src_list.o \
6662 + str_list.o \
6663 + void_list.o \
6664 +
6665 +LIBIPKG_UTIL_OBJS:= \
6666 + file_util.o \
6667 + ipkg_message.o \
6668 + str_util.o \
6669 + xsystem.o \
6670 +
6671 +lib-y :=
6672 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6673 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6677 +
6678 +ifeq ($(strip $(IPKG_ARCH)),)
6679 +IPKG_ARCH:=$(TARGET_ARCH)
6680 +endif
6681 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6682 Index: busybox-1.4.2/archival/libipkg/libipkg.c
6683 ===================================================================
6684 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6685 +++ busybox-1.4.2/archival/libipkg/libipkg.c 2007-06-04 13:21:36.717394776 +0200
6686 @@ -0,0 +1,527 @@
6687 +/* ipkglib.c - the itsy package management system
6688 +
6689 + Florina Boor
6690 +
6691 + Copyright (C) 2003 kernel concepts
6692 +
6693 + This program is free software; you can redistribute it and/or
6694 + modify it under the terms of the GNU General Public License as
6695 + published by the Free Software Foundation; either version 2, or (at
6696 + your option) any later version.
6697 +
6698 + This program is distributed in the hope that it will be useful, but
6699 + WITHOUT ANY WARRANTY; without even the implied warranty of
6700 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6701 + General Public License for more details.
6702 +*/
6703 +
6704 +#ifdef IPKG_LIB
6705 +
6706 +#include "ipkg.h"
6707 +#include "ipkg_includes.h"
6708 +#include "libipkg.h"
6709 +
6710 +#include "args.h"
6711 +#include "ipkg_conf.h"
6712 +#include "ipkg_cmd.h"
6713 +#include "file_util.h"
6714 +
6715 +
6716 +
6717 +ipkg_message_callback ipkg_cb_message = NULL;
6718 +ipkg_response_callback ipkg_cb_response = NULL;
6719 +ipkg_status_callback ipkg_cb_status = NULL;
6720 +ipkg_list_callback ipkg_cb_list = NULL;
6721 +
6722 +
6723 +int
6724 +ipkg_init (ipkg_message_callback mcall,
6725 + ipkg_response_callback rcall,
6726 + args_t * args)
6727 +{
6728 + ipkg_cb_message = mcall;
6729 + ipkg_cb_response = rcall;
6730 +
6731 + args_init (args);
6732 +
6733 + return 0;
6734 +}
6735 +
6736 +
6737 +int
6738 +ipkg_deinit (args_t * args)
6739 +{
6740 + args_deinit (args);
6741 + ipkg_cb_message = NULL;
6742 + ipkg_cb_response = NULL;
6743 +
6744 + /* place other cleanup stuff here */
6745 +
6746 + return 0;
6747 +}
6748 +
6749 +
6750 +int
6751 +ipkg_packages_list(args_t *args,
6752 + const char *packages,
6753 + ipkg_list_callback cblist,
6754 + void *userdata)
6755 +{
6756 + ipkg_cmd_t *cmd;
6757 + ipkg_conf_t ipkg_conf;
6758 + int err;
6759 +
6760 + err = ipkg_conf_init (&ipkg_conf, args);
6761 + if (err)
6762 + {
6763 + return err;
6764 + }
6765 +
6766 + ipkg_cb_list = cblist;
6767 + /* we need to do this because of static declarations,
6768 + * maybe a good idea to change */
6769 + cmd = ipkg_cmd_find ("list");
6770 + if (packages)
6771 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6772 + else
6773 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6774 + ipkg_cb_list = NULL;
6775 + ipkg_conf_deinit (&ipkg_conf);
6776 + return (err);
6777 +}
6778 +
6779 +
6780 +int
6781 +ipkg_packages_status(args_t *args,
6782 + const char *packages,
6783 + ipkg_status_callback cbstatus,
6784 + void *userdata)
6785 +{
6786 + ipkg_cmd_t *cmd;
6787 + ipkg_conf_t ipkg_conf;
6788 + int err;
6789 +
6790 + err = ipkg_conf_init (&ipkg_conf, args);
6791 + if (err)
6792 + {
6793 + return err;
6794 + }
6795 +
6796 + ipkg_cb_status = cbstatus;
6797 +
6798 + /* we need to do this because of static declarations,
6799 + * maybe a good idea to change */
6800 + cmd = ipkg_cmd_find ("status");
6801 + if (packages)
6802 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6803 + else
6804 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6805 +
6806 + ipkg_cb_status = NULL;
6807 + ipkg_conf_deinit (&ipkg_conf);
6808 + return (err);
6809 +}
6810 +
6811 +
6812 +int
6813 +ipkg_packages_info(args_t *args,
6814 + const char *packages,
6815 + ipkg_status_callback cbstatus,
6816 + void *userdata)
6817 +{
6818 + ipkg_cmd_t *cmd;
6819 + ipkg_conf_t ipkg_conf;
6820 + int err;
6821 +
6822 + err = ipkg_conf_init (&ipkg_conf, args);
6823 + if (err)
6824 + {
6825 + return err;
6826 + }
6827 +
6828 + ipkg_cb_status = cbstatus;
6829 +
6830 + /* we need to do this because of static declarations,
6831 + * maybe a good idea to change */
6832 + cmd = ipkg_cmd_find ("info");
6833 + if (packages)
6834 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6835 + else
6836 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6837 +
6838 + ipkg_cb_status = NULL;
6839 + ipkg_conf_deinit (&ipkg_conf);
6840 + return (err);
6841 +}
6842 +
6843 +
6844 +int
6845 +ipkg_packages_install (args_t * args, const char *name)
6846 +{
6847 + ipkg_cmd_t *cmd;
6848 + ipkg_conf_t ipkg_conf;
6849 + int err;
6850 +
6851 + /* this error should be handled in application */
6852 + if (!name || !strlen (name))
6853 + return (-1);
6854 +
6855 + err = ipkg_conf_init (&ipkg_conf, args);
6856 + if (err)
6857 + {
6858 + return err;
6859 + }
6860 +
6861 + /* we need to do this because of static declarations,
6862 + * maybe a good idea to change */
6863 + cmd = ipkg_cmd_find ("install");
6864 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6865 +
6866 + ipkg_conf_deinit(&ipkg_conf);
6867 + return (err);
6868 +}
6869 +
6870 +
6871 +int
6872 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6873 +{
6874 + ipkg_cmd_t *cmd;
6875 + ipkg_conf_t ipkg_conf;
6876 + int err;
6877 +
6878 + /* this error should be handled in application */
6879 + if (!name || !strlen (name))
6880 + return (-1);
6881 +
6882 + err = ipkg_conf_init (&ipkg_conf, args);
6883 + if (err)
6884 + {
6885 + return err;
6886 + }
6887 +
6888 + /* we need to do this because of static declarations,
6889 + * maybe a good idea to change */
6890 + if (purge)
6891 + cmd = ipkg_cmd_find ("purge");
6892 + else
6893 + cmd = ipkg_cmd_find ("remove");
6894 +
6895 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6896 +
6897 + ipkg_conf_deinit(&ipkg_conf);
6898 + return (err);
6899 +}
6900 +
6901 +
6902 +int
6903 +ipkg_lists_update(args_t *args)
6904 +{
6905 + ipkg_cmd_t *cmd;
6906 + ipkg_conf_t ipkg_conf;
6907 + int err;
6908 +
6909 + err = ipkg_conf_init (&ipkg_conf, args);
6910 + if (err)
6911 + {
6912 + return err;
6913 + }
6914 +
6915 + /* we need to do this because of static declarations,
6916 + * maybe a good idea to change */
6917 + cmd = ipkg_cmd_find ("update");
6918 +
6919 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6920 +
6921 + ipkg_conf_deinit(&ipkg_conf);
6922 + return (err);
6923 +}
6924 +
6925 +
6926 +int
6927 +ipkg_packages_upgrade(args_t *args)
6928 +{
6929 + ipkg_cmd_t *cmd;
6930 + ipkg_conf_t ipkg_conf;
6931 + int err;
6932 +
6933 + err = ipkg_conf_init (&ipkg_conf, args);
6934 + if (err)
6935 + {
6936 + return err;
6937 + }
6938 +
6939 + /* we need to do this because of static declarations,
6940 + * maybe a good idea to change */
6941 + cmd = ipkg_cmd_find ("upgrade");
6942 +
6943 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6944 +
6945 + ipkg_conf_deinit(&ipkg_conf);
6946 + return (err);
6947 +}
6948 +
6949 +
6950 +int
6951 +ipkg_packages_download (args_t * args, const char *name)
6952 +{
6953 + ipkg_cmd_t *cmd;
6954 + ipkg_conf_t ipkg_conf;
6955 + int err;
6956 +
6957 + /* this error should be handled in application */
6958 + if (!name || !strlen (name))
6959 + return (-1);
6960 +
6961 + err = ipkg_conf_init (&ipkg_conf, args);
6962 + if (err)
6963 + {
6964 + return err;
6965 + }
6966 +
6967 + /* we need to do this because of static declarations,
6968 + * maybe a good idea to change */
6969 + cmd = ipkg_cmd_find ("download");
6970 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6971 +
6972 + ipkg_conf_deinit(&ipkg_conf);
6973 + return (err);
6974 +}
6975 +
6976 +
6977 +int
6978 +ipkg_package_files(args_t *args,
6979 + const char *name,
6980 + ipkg_list_callback cblist,
6981 + void *userdata)
6982 +{
6983 + ipkg_cmd_t *cmd;
6984 + ipkg_conf_t ipkg_conf;
6985 + int err;
6986 +
6987 + /* this error should be handled in application */
6988 + if (!name || !strlen (name))
6989 + return (-1);
6990 +
6991 + err = ipkg_conf_init (&ipkg_conf, args);
6992 + if (err)
6993 + {
6994 + return err;
6995 + }
6996 +
6997 + ipkg_cb_list = cblist;
6998 +
6999 + /* we need to do this because of static declarations,
7000 + * maybe a good idea to change */
7001 + cmd = ipkg_cmd_find ("files");
7002 +
7003 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7004 +
7005 + ipkg_cb_list = NULL;
7006 + ipkg_conf_deinit(&ipkg_conf);
7007 + return (err);
7008 +}
7009 +
7010 +
7011 +int
7012 +ipkg_file_search(args_t *args,
7013 + const char *file,
7014 + ipkg_list_callback cblist,
7015 + void *userdata)
7016 +{
7017 + ipkg_cmd_t *cmd;
7018 + ipkg_conf_t ipkg_conf;
7019 + int err;
7020 +
7021 + /* this error should be handled in application */
7022 + if (!file || !strlen (file))
7023 + return (-1);
7024 +
7025 + err = ipkg_conf_init (&ipkg_conf, args);
7026 + if (err)
7027 + {
7028 + return err;
7029 + }
7030 +
7031 + ipkg_cb_list = cblist;
7032 +
7033 + /* we need to do this because of static declarations,
7034 + * maybe a good idea to change */
7035 + cmd = ipkg_cmd_find ("search");
7036 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7037 +
7038 + ipkg_cb_list = NULL;
7039 + ipkg_conf_deinit(&ipkg_conf);
7040 + return(err);
7041 +}
7042 +
7043 +
7044 +int
7045 +ipkg_file_what(args_t *args, const char *file, const char* command)
7046 +{
7047 + ipkg_cmd_t *cmd;
7048 + ipkg_conf_t ipkg_conf;
7049 + int err;
7050 +
7051 + /* this error should be handled in application */
7052 + if (!file || !strlen (file))
7053 + return (-1);
7054 +
7055 + err = ipkg_conf_init (&ipkg_conf, args);
7056 + if (err)
7057 + {
7058 + return err;
7059 + }
7060 +
7061 + /* we need to do this because of static declarations,
7062 + * maybe a good idea to change */
7063 + cmd = ipkg_cmd_find (command);
7064 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7065 +
7066 + ipkg_conf_deinit(&ipkg_conf);
7067 + return(err);
7068 +}
7069 +
7070 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7071 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7072 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7073 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7074 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7075 +
7076 +
7077 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7078 + char *msg)
7079 +{
7080 + if (conf && (conf->verbosity < level)) {
7081 + return 0;
7082 + } else {
7083 +#ifdef IPKG_LIB
7084 + if ( level == IPKG_ERROR ){
7085 + push_error_list(&error_list, msg);
7086 +// printf(msg);
7087 + } else
7088 +#endif
7089 + printf(msg);
7090 + }
7091 + return 0;
7092 +}
7093 +
7094 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7095 + pkg_state_status_t status, void *userdata)
7096 +{
7097 + if (desc)
7098 + printf("%s - %s - %s\n", name, version, desc);
7099 + else
7100 + printf("%s - %s\n", name, version);
7101 + return 0;
7102 +}
7103 +
7104 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7105 + pkg_state_status_t status, void *userdata)
7106 +{
7107 + if (desc)
7108 + printf("%s\n", desc);
7109 + return 0;
7110 +}
7111 +
7112 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7113 + void *userdata)
7114 +{
7115 + printf("%s\n", desc);
7116 + return 0;
7117 +}
7118 +
7119 +char* default_ipkg_response_callback(char *question)
7120 +{
7121 + char *response = NULL;
7122 + printf(question);
7123 + fflush(stdout);
7124 + do {
7125 + response = (char *)file_read_line_alloc(stdin);
7126 + } while (response == NULL);
7127 + return response;
7128 +}
7129 +
7130 +/* This is used for backward compatibility */
7131 +int
7132 +ipkg_op (int argc, char *argv[])
7133 +{
7134 + int err, opt_index;
7135 + args_t args;
7136 + char *cmd_name;
7137 + ipkg_cmd_t *cmd;
7138 + ipkg_conf_t ipkg_conf;
7139 +
7140 + args_init (&args);
7141 +
7142 + opt_index = args_parse (&args, argc, argv);
7143 + if (opt_index == argc || opt_index < 0)
7144 + {
7145 + args_usage ("ipkg must have one sub-command argument");
7146 + }
7147 +
7148 + cmd_name = argv[opt_index++];
7149 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7150 + read anything from there.
7151 +*/
7152 + if ( !strcmp(cmd_name,"print-architecture") ||
7153 + !strcmp(cmd_name,"print_architecture") ||
7154 + !strcmp(cmd_name,"print-installation-architecture") ||
7155 + !strcmp(cmd_name,"print_installation_architecture") )
7156 + args.nocheckfordirorfile = 1;
7157 +
7158 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7159 + read anything from there.
7160 +*/
7161 + if ( !strcmp(cmd_name,"flag") ||
7162 + !strcmp(cmd_name,"configure") ||
7163 + !strcmp(cmd_name,"remove") ||
7164 + !strcmp(cmd_name,"files") ||
7165 + !strcmp(cmd_name,"search") ||
7166 + !strcmp(cmd_name,"compare_versions") ||
7167 + !strcmp(cmd_name,"compare-versions") ||
7168 + !strcmp(cmd_name,"list_installed") ||
7169 + !strcmp(cmd_name,"list-installed") ||
7170 + !strcmp(cmd_name,"status") )
7171 + args.noreadfeedsfile = 1;
7172 +
7173 +
7174 + err = ipkg_conf_init (&ipkg_conf, &args);
7175 + if (err)
7176 + {
7177 + return err;
7178 + }
7179 +
7180 + args_deinit (&args);
7181 +
7182 + ipkg_cb_message = default_ipkg_message_callback;
7183 + ipkg_cb_response = default_ipkg_response_callback;
7184 + ipkg_cb_status = default_ipkg_status_callback;
7185 + if ( strcmp(cmd_name, "files")==0)
7186 + ipkg_cb_list = default_ipkg_files_callback;
7187 + else
7188 + ipkg_cb_list = default_ipkg_list_callback;
7189 +
7190 + cmd = ipkg_cmd_find (cmd_name);
7191 + if (cmd == NULL)
7192 + {
7193 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7194 + cmd_name);
7195 + args_usage (NULL);
7196 + }
7197 +
7198 + if (cmd->requires_args && opt_index == argc)
7199 + {
7200 + fprintf (stderr,
7201 + "%s: the ``%s'' command requires at least one argument\n",
7202 + __FUNCTION__, cmd_name);
7203 + args_usage (NULL);
7204 + }
7205 +
7206 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7207 +
7208 + ipkg_conf_deinit (&ipkg_conf);
7209 +
7210 + return err;
7211 +}
7212 +
7213 +#endif /* IPKG_LIB */
7214 Index: busybox-1.4.2/archival/libipkg/libipkg.h
7215 ===================================================================
7216 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7217 +++ busybox-1.4.2/archival/libipkg/libipkg.h 2007-06-04 13:21:36.718394624 +0200
7218 @@ -0,0 +1,87 @@
7219 +/* ipkglib.h - the itsy package management system
7220 +
7221 + Florian Boor <florian.boor@kernelconcepts.de>
7222 +
7223 + This program is free software; you can redistribute it and/or
7224 + modify it under the terms of the GNU General Public License as
7225 + published by the Free Software Foundation; either version 2, or (at
7226 + your option) any later version.
7227 +
7228 + This program is distributed in the hope that it will be useful, but
7229 + WITHOUT ANY WARRANTY; without even the implied warranty of
7230 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7231 + General Public License for more details.
7232 +*/
7233 +
7234 +#ifndef IPKGLIB_H
7235 +#define IPKGLIB_H
7236 +
7237 +#ifdef IPKG_LIB
7238 +
7239 +#include "ipkg_conf.h"
7240 +#include "ipkg_message.h"
7241 +
7242 +#include "args.h"
7243 +#include "pkg.h"
7244 +
7245 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7246 + char *msg);
7247 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7248 + pkg_state_status_t status, void *userdata);
7249 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7250 + void *userdata);
7251 +typedef char* (*ipkg_response_callback)(char *question);
7252 +
7253 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7254 +extern int ipkg_init (ipkg_message_callback mcall,
7255 + ipkg_response_callback rcall,
7256 + args_t * args);
7257 +
7258 +extern int ipkg_deinit (args_t *args);
7259 +extern int ipkg_packages_list(args_t *args,
7260 + const char *packages,
7261 + ipkg_list_callback cblist,
7262 + void *userdata);
7263 +extern int ipkg_packages_status(args_t *args,
7264 + const char *packages,
7265 + ipkg_status_callback cbstatus,
7266 + void *userdata);
7267 +extern int ipkg_packages_info(args_t *args,
7268 + const char *packages,
7269 + ipkg_status_callback cbstatus,
7270 + void *userdata);
7271 +extern int ipkg_packages_install(args_t *args, const char *name);
7272 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7273 +extern int ipkg_lists_update(args_t *args);
7274 +extern int ipkg_packages_upgrade(args_t *args);
7275 +extern int ipkg_packages_download(args_t *args, const char *name);
7276 +extern int ipkg_package_files(args_t *args,
7277 + const char *name,
7278 + ipkg_list_callback cblist,
7279 + void *userdata);
7280 +extern int ipkg_file_search(args_t *args,
7281 + const char *file,
7282 + ipkg_list_callback cblist,
7283 + void *userdata);
7284 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7285 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7286 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7287 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7288 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7289 +
7290 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7291 +extern ipkg_response_callback ipkg_cb_response;
7292 +extern ipkg_status_callback ipkg_cb_status;
7293 +extern ipkg_list_callback ipkg_cb_list;
7294 +extern void push_error_list(struct errlist **errors,char * msg);
7295 +extern void reverse_error_list(struct errlist **errors);
7296 +extern void free_error_list(struct errlist **errors);
7297 +
7298 +#else
7299 +
7300 +extern int ipkg_op(int argc, char *argv[]);
7301 +
7302 +#endif
7303 +
7304 +
7305 +#endif
7306 Index: busybox-1.4.2/archival/libipkg/nv_pair.c
7307 ===================================================================
7308 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7309 +++ busybox-1.4.2/archival/libipkg/nv_pair.c 2007-06-04 13:21:36.718394624 +0200
7310 @@ -0,0 +1,40 @@
7311 +/* nv_pair.c - the itsy package management system
7312 +
7313 + Carl D. Worth
7314 +
7315 + Copyright (C) 2001 University of Southern California
7316 +
7317 + This program is free software; you can redistribute it and/or
7318 + modify it under the terms of the GNU General Public License as
7319 + published by the Free Software Foundation; either version 2, or (at
7320 + your option) any later version.
7321 +
7322 + This program is distributed in the hope that it will be useful, but
7323 + WITHOUT ANY WARRANTY; without even the implied warranty of
7324 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7325 + General Public License for more details.
7326 +*/
7327 +
7328 +#include "ipkg.h"
7329 +
7330 +#include "nv_pair.h"
7331 +#include "str_util.h"
7332 +
7333 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7334 +{
7335 + nv_pair->name = str_dup_safe(name);
7336 + nv_pair->value = str_dup_safe(value);
7337 +
7338 + return 0;
7339 +}
7340 +
7341 +void nv_pair_deinit(nv_pair_t *nv_pair)
7342 +{
7343 + free(nv_pair->name);
7344 + nv_pair->name = NULL;
7345 +
7346 + free(nv_pair->value);
7347 + nv_pair->value = NULL;
7348 +}
7349 +
7350 +
7351 Index: busybox-1.4.2/archival/libipkg/nv_pair.h
7352 ===================================================================
7353 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7354 +++ busybox-1.4.2/archival/libipkg/nv_pair.h 2007-06-04 13:21:36.718394624 +0200
7355 @@ -0,0 +1,32 @@
7356 +/* nv_pair.h - the itsy package management system
7357 +
7358 + Carl D. Worth
7359 +
7360 + Copyright (C) 2001 University of Southern California
7361 +
7362 + This program is free software; you can redistribute it and/or
7363 + modify it under the terms of the GNU General Public License as
7364 + published by the Free Software Foundation; either version 2, or (at
7365 + your option) any later version.
7366 +
7367 + This program is distributed in the hope that it will be useful, but
7368 + WITHOUT ANY WARRANTY; without even the implied warranty of
7369 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7370 + General Public License for more details.
7371 +*/
7372 +
7373 +#ifndef NV_PAIR_H
7374 +#define NV_PAIR_H
7375 +
7376 +typedef struct nv_pair nv_pair_t;
7377 +struct nv_pair
7378 +{
7379 + char *name;
7380 + char *value;
7381 +};
7382 +
7383 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7384 +void nv_pair_deinit(nv_pair_t *nv_pair);
7385 +
7386 +#endif
7387 +
7388 Index: busybox-1.4.2/archival/libipkg/nv_pair_list.c
7389 ===================================================================
7390 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7391 +++ busybox-1.4.2/archival/libipkg/nv_pair_list.c 2007-06-04 13:21:36.718394624 +0200
7392 @@ -0,0 +1,98 @@
7393 +/* nv_pair_list.c - the itsy package management system
7394 +
7395 + Carl D. Worth
7396 +
7397 + Copyright (C) 2001 University of Southern California
7398 +
7399 + This program is free software; you can redistribute it and/or
7400 + modify it under the terms of the GNU General Public License as
7401 + published by the Free Software Foundation; either version 2, or (at
7402 + your option) any later version.
7403 +
7404 + This program is distributed in the hope that it will be useful, but
7405 + WITHOUT ANY WARRANTY; without even the implied warranty of
7406 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7407 + General Public License for more details.
7408 +*/
7409 +
7410 +#include "ipkg.h"
7411 +
7412 +#include "nv_pair.h"
7413 +#include "void_list.h"
7414 +#include "nv_pair_list.h"
7415 +
7416 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7417 +{
7418 + return void_list_elt_init((void_list_elt_t *) elt, data);
7419 +}
7420 +
7421 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7422 +{
7423 + void_list_elt_deinit((void_list_elt_t *) elt);
7424 +}
7425 +
7426 +int nv_pair_list_init(nv_pair_list_t *list)
7427 +{
7428 + return void_list_init((void_list_t *) list);
7429 +}
7430 +
7431 +void nv_pair_list_deinit(nv_pair_list_t *list)
7432 +{
7433 + nv_pair_list_elt_t *iter;
7434 + nv_pair_t *nv_pair;
7435 +
7436 + for (iter = list->head; iter; iter = iter->next) {
7437 + nv_pair = iter->data;
7438 + nv_pair_deinit(nv_pair);
7439 +
7440 + /* malloced in nv_pair_list_append */
7441 + free(nv_pair);
7442 + iter->data = NULL;
7443 + }
7444 + void_list_deinit((void_list_t *) list);
7445 +}
7446 +
7447 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7448 +{
7449 + int err;
7450 +
7451 + /* freed in nv_pair_list_deinit */
7452 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7453 +
7454 + if (nv_pair == NULL) {
7455 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7456 + return NULL;
7457 + }
7458 + nv_pair_init(nv_pair, name, value);
7459 +
7460 + err = void_list_append((void_list_t *) list, nv_pair);
7461 + if (err) {
7462 + return NULL;
7463 + }
7464 +
7465 + return nv_pair;
7466 +}
7467 +
7468 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7469 +{
7470 + return void_list_push((void_list_t *) list, data);
7471 +}
7472 +
7473 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7474 +{
7475 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7476 +}
7477 +
7478 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7479 +{
7480 + nv_pair_list_elt_t *iter;
7481 + nv_pair_t *nv_pair;
7482 +
7483 + for (iter = list->head; iter; iter = iter->next) {
7484 + nv_pair = iter->data;
7485 + if (strcmp(nv_pair->name, name) == 0) {
7486 + return nv_pair->value;
7487 + }
7488 + }
7489 + return NULL;
7490 +}
7491 Index: busybox-1.4.2/archival/libipkg/nv_pair_list.h
7492 ===================================================================
7493 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7494 +++ busybox-1.4.2/archival/libipkg/nv_pair_list.h 2007-06-04 13:21:36.718394624 +0200
7495 @@ -0,0 +1,60 @@
7496 +/* nv_pair_list.h - the itsy package management system
7497 +
7498 + Carl D. Worth
7499 +
7500 + Copyright (C) 2001 University of Southern California
7501 +
7502 + This program is free software; you can redistribute it and/or
7503 + modify it under the terms of the GNU General Public License as
7504 + published by the Free Software Foundation; either version 2, or (at
7505 + your option) any later version.
7506 +
7507 + This program is distributed in the hope that it will be useful, but
7508 + WITHOUT ANY WARRANTY; without even the implied warranty of
7509 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7510 + General Public License for more details.
7511 +*/
7512 +
7513 +#ifndef NV_PAIR_LIST_H
7514 +#define NV_PAIR_LIST_H
7515 +
7516 +#include "nv_pair.h"
7517 +#include "void_list.h"
7518 +
7519 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7520 +struct nv_pair_list_elt
7521 +{
7522 + nv_pair_list_elt_t *next;
7523 + nv_pair_t *data;
7524 +};
7525 +
7526 +typedef struct nv_pair_list nv_pair_list_t;
7527 +struct nv_pair_list
7528 +{
7529 + nv_pair_list_elt_t pre_head;
7530 + nv_pair_list_elt_t *head;
7531 + nv_pair_list_elt_t *tail;
7532 +};
7533 +
7534 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7535 +{
7536 + if (list->head == NULL)
7537 + return 1;
7538 + else
7539 + return 0;
7540 +}
7541 +
7542 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7543 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7544 +
7545 +int nv_pair_list_init(nv_pair_list_t *list);
7546 +void nv_pair_list_deinit(nv_pair_list_t *list);
7547 +
7548 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7549 + const char *name, const char *value);
7550 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7551 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7552 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7553 +
7554 +#endif
7555 +
7556 Index: busybox-1.4.2/archival/libipkg/pkg.c
7557 ===================================================================
7558 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7559 +++ busybox-1.4.2/archival/libipkg/pkg.c 2007-06-04 13:21:36.720394320 +0200
7560 @@ -0,0 +1,1747 @@
7561 +/* pkg.c - the itsy package management system
7562 +
7563 + Carl D. Worth
7564 +
7565 + Copyright (C) 2001 University of Southern California
7566 +
7567 + This program is free software; you can redistribute it and/or
7568 + modify it under the terms of the GNU General Public License as
7569 + published by the Free Software Foundation; either version 2, or (at
7570 + your option) any later version.
7571 +
7572 + This program is distributed in the hope that it will be useful, but
7573 + WITHOUT ANY WARRANTY; without even the implied warranty of
7574 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7575 + General Public License for more details.
7576 +*/
7577 +
7578 +#include "ipkg.h"
7579 +#include <ctype.h>
7580 +#include <string.h>
7581 +#include <errno.h>
7582 +
7583 +#include "pkg.h"
7584 +
7585 +#include "pkg_parse.h"
7586 +#include "pkg_extract.h"
7587 +#include "ipkg_message.h"
7588 +#include "ipkg_utils.h"
7589 +
7590 +#include "sprintf_alloc.h"
7591 +#include "file_util.h"
7592 +#include "str_util.h"
7593 +#include "xsystem.h"
7594 +#include "ipkg_conf.h"
7595 +
7596 +typedef struct enum_map enum_map_t;
7597 +struct enum_map
7598 +{
7599 + int value;
7600 + char *str;
7601 +};
7602 +
7603 +static const enum_map_t pkg_state_want_map[] = {
7604 + { SW_UNKNOWN, "unknown"},
7605 + { SW_INSTALL, "install"},
7606 + { SW_DEINSTALL, "deinstall"},
7607 + { SW_PURGE, "purge"}
7608 +};
7609 +
7610 +static const enum_map_t pkg_state_flag_map[] = {
7611 + { SF_OK, "ok"},
7612 + { SF_REINSTREQ, "reinstreq"},
7613 + { SF_HOLD, "hold"},
7614 + { SF_REPLACE, "replace"},
7615 + { SF_NOPRUNE, "noprune"},
7616 + { SF_PREFER, "prefer"},
7617 + { SF_OBSOLETE, "obsolete"},
7618 + { SF_USER, "user"},
7619 +};
7620 +
7621 +static const enum_map_t pkg_state_status_map[] = {
7622 + { SS_NOT_INSTALLED, "not-installed" },
7623 + { SS_UNPACKED, "unpacked" },
7624 + { SS_HALF_CONFIGURED, "half-configured" },
7625 + { SS_INSTALLED, "installed" },
7626 + { SS_HALF_INSTALLED, "half-installed" },
7627 + { SS_CONFIG_FILES, "config-files" },
7628 + { SS_POST_INST_FAILED, "post-inst-failed" },
7629 + { SS_REMOVAL_FAILED, "removal-failed" }
7630 +};
7631 +
7632 +static int verrevcmp(const char *val, const char *ref);
7633 +
7634 +
7635 +pkg_t *pkg_new(void)
7636 +{
7637 + pkg_t *pkg;
7638 +
7639 + pkg = malloc(sizeof(pkg_t));
7640 + if (pkg == NULL) {
7641 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7642 + return NULL;
7643 + }
7644 +
7645 + pkg_init(pkg);
7646 +
7647 + return pkg;
7648 +}
7649 +
7650 +int pkg_init(pkg_t *pkg)
7651 +{
7652 + memset(pkg, 0, sizeof(pkg_t));
7653 + pkg->name = NULL;
7654 + pkg->epoch = 0;
7655 + pkg->version = NULL;
7656 + pkg->revision = NULL;
7657 + pkg->familiar_revision = NULL;
7658 + pkg->dest = NULL;
7659 + pkg->src = NULL;
7660 + pkg->architecture = NULL;
7661 + pkg->maintainer = NULL;
7662 + pkg->section = NULL;
7663 + pkg->description = NULL;
7664 + pkg->state_want = SW_UNKNOWN;
7665 + pkg->state_flag = SF_OK;
7666 + pkg->state_status = SS_NOT_INSTALLED;
7667 + pkg->depends_str = NULL;
7668 + pkg->provides_str = NULL;
7669 + pkg->depends_count = 0;
7670 + pkg->depends = NULL;
7671 + pkg->suggests_str = NULL;
7672 + pkg->recommends_str = NULL;
7673 + pkg->suggests_count = 0;
7674 + pkg->recommends_count = 0;
7675 +
7676 + /* Abhaya: added init for conflicts fields */
7677 + pkg->conflicts = NULL;
7678 + pkg->conflicts_count = 0;
7679 +
7680 + /* added for replaces. Jamey 7/23/2002 */
7681 + pkg->replaces = NULL;
7682 + pkg->replaces_count = 0;
7683 +
7684 + pkg->pre_depends_count = 0;
7685 + pkg->pre_depends_str = NULL;
7686 + pkg->provides_count = 0;
7687 + pkg->provides = NULL;
7688 + pkg->filename = NULL;
7689 + pkg->local_filename = NULL;
7690 + pkg->tmp_unpack_dir = NULL;
7691 + pkg->md5sum = NULL;
7692 + pkg->size = NULL;
7693 + pkg->installed_size = NULL;
7694 + pkg->priority = NULL;
7695 + pkg->source = NULL;
7696 + conffile_list_init(&pkg->conffiles);
7697 + pkg->installed_files = NULL;
7698 + pkg->installed_files_ref_cnt = 0;
7699 + pkg->essential = 0;
7700 + pkg->provided_by_hand = 0;
7701 +
7702 + return 0;
7703 +}
7704 +
7705 +void pkg_deinit(pkg_t *pkg)
7706 +{
7707 + free(pkg->name);
7708 + pkg->name = NULL;
7709 + pkg->epoch = 0;
7710 + free(pkg->version);
7711 + pkg->version = NULL;
7712 + /* revision and familiar_revision share storage with version, so
7713 + don't free */
7714 + pkg->revision = NULL;
7715 + pkg->familiar_revision = NULL;
7716 + /* owned by ipkg_conf_t */
7717 + pkg->dest = NULL;
7718 + /* owned by ipkg_conf_t */
7719 + pkg->src = NULL;
7720 + free(pkg->architecture);
7721 + pkg->architecture = NULL;
7722 + free(pkg->maintainer);
7723 + pkg->maintainer = NULL;
7724 + free(pkg->section);
7725 + pkg->section = NULL;
7726 + free(pkg->description);
7727 + pkg->description = NULL;
7728 + pkg->state_want = SW_UNKNOWN;
7729 + pkg->state_flag = SF_OK;
7730 + pkg->state_status = SS_NOT_INSTALLED;
7731 + free(pkg->depends_str);
7732 + pkg->depends_str = NULL;
7733 + free(pkg->provides_str);
7734 + pkg->provides_str = NULL;
7735 + pkg->depends_count = 0;
7736 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7737 + pkg->pre_depends_count = 0;
7738 + free(pkg->pre_depends_str);
7739 + pkg->pre_depends_str = NULL;
7740 + pkg->provides_count = 0;
7741 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7742 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7743 + free(pkg->filename);
7744 + pkg->filename = NULL;
7745 + free(pkg->local_filename);
7746 + pkg->local_filename = NULL;
7747 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7748 + ipkg_install.c here. See comment in
7749 + ipkg_install.c:cleanup_temporary_files */
7750 + free(pkg->tmp_unpack_dir);
7751 + pkg->tmp_unpack_dir = NULL;
7752 + free(pkg->md5sum);
7753 + pkg->md5sum = NULL;
7754 + free(pkg->size);
7755 + pkg->size = NULL;
7756 + free(pkg->installed_size);
7757 + pkg->installed_size = NULL;
7758 + free(pkg->priority);
7759 + pkg->priority = NULL;
7760 + free(pkg->source);
7761 + pkg->source = NULL;
7762 + conffile_list_deinit(&pkg->conffiles);
7763 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7764 + since if they are calling deinit, they should know. Maybe do an
7765 + assertion here instead? */
7766 + pkg->installed_files_ref_cnt = 1;
7767 + pkg_free_installed_files(pkg);
7768 + pkg->essential = 0;
7769 +}
7770 +
7771 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7772 +{
7773 + int err;
7774 + char **raw;
7775 + FILE *control_file;
7776 +
7777 + err = pkg_init(pkg);
7778 + if (err) { return err; }
7779 +
7780 + pkg->local_filename = strdup(filename);
7781 +
7782 + control_file = tmpfile();
7783 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7784 + if (err) { return err; }
7785 +
7786 + rewind(control_file);
7787 + raw = read_raw_pkgs_from_stream(control_file);
7788 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7789 +
7790 + fclose(control_file);
7791 +
7792 + return 0;
7793 +}
7794 +
7795 +/* Merge any new information in newpkg into oldpkg */
7796 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7797 + newpkg, but should leave it usable. This rework is so that
7798 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7799 +/*
7800 + * uh, i thought that i had originally written this so that it took
7801 + * two pkgs and returned a new one? we can do that again... -sma
7802 + */
7803 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7804 +{
7805 + if (oldpkg == newpkg) {
7806 + return 0;
7807 + }
7808 +
7809 + if (!oldpkg->src)
7810 + oldpkg->src = newpkg->src;
7811 + if (!oldpkg->dest)
7812 + oldpkg->dest = newpkg->dest;
7813 + if (!oldpkg->architecture)
7814 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7815 + if (!oldpkg->arch_priority)
7816 + oldpkg->arch_priority = newpkg->arch_priority;
7817 + if (!oldpkg->section)
7818 + oldpkg->section = str_dup_safe(newpkg->section);
7819 + if(!oldpkg->maintainer)
7820 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7821 + if(!oldpkg->description)
7822 + oldpkg->description = str_dup_safe(newpkg->description);
7823 + if (set_status) {
7824 + /* merge the state_flags from the new package */
7825 + oldpkg->state_want = newpkg->state_want;
7826 + oldpkg->state_status = newpkg->state_status;
7827 + oldpkg->state_flag = newpkg->state_flag;
7828 + } else {
7829 + if (oldpkg->state_want == SW_UNKNOWN)
7830 + oldpkg->state_want = newpkg->state_want;
7831 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7832 + oldpkg->state_status = newpkg->state_status;
7833 + oldpkg->state_flag |= newpkg->state_flag;
7834 + }
7835 +
7836 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7837 + oldpkg->depends_str = newpkg->depends_str;
7838 + newpkg->depends_str = NULL;
7839 + oldpkg->depends_count = newpkg->depends_count;
7840 + newpkg->depends_count = 0;
7841 +
7842 + oldpkg->depends = newpkg->depends;
7843 + newpkg->depends = NULL;
7844 +
7845 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7846 + newpkg->pre_depends_str = NULL;
7847 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7848 + newpkg->pre_depends_count = 0;
7849 +
7850 + oldpkg->recommends_str = newpkg->recommends_str;
7851 + newpkg->recommends_str = NULL;
7852 + oldpkg->recommends_count = newpkg->recommends_count;
7853 + newpkg->recommends_count = 0;
7854 +
7855 + oldpkg->suggests_str = newpkg->suggests_str;
7856 + newpkg->suggests_str = NULL;
7857 + oldpkg->suggests_count = newpkg->suggests_count;
7858 + newpkg->suggests_count = 0;
7859 + }
7860 +
7861 + if (!oldpkg->provides_str) {
7862 + oldpkg->provides_str = newpkg->provides_str;
7863 + newpkg->provides_str = NULL;
7864 + oldpkg->provides_count = newpkg->provides_count;
7865 + newpkg->provides_count = 0;
7866 +
7867 + oldpkg->provides = newpkg->provides;
7868 + newpkg->provides = NULL;
7869 + }
7870 +
7871 + if (!oldpkg->conflicts_str) {
7872 + oldpkg->conflicts_str = newpkg->conflicts_str;
7873 + newpkg->conflicts_str = NULL;
7874 + oldpkg->conflicts_count = newpkg->conflicts_count;
7875 + newpkg->conflicts_count = 0;
7876 +
7877 + oldpkg->conflicts = newpkg->conflicts;
7878 + newpkg->conflicts = NULL;
7879 + }
7880 +
7881 + if (!oldpkg->replaces_str) {
7882 + oldpkg->replaces_str = newpkg->replaces_str;
7883 + newpkg->replaces_str = NULL;
7884 + oldpkg->replaces_count = newpkg->replaces_count;
7885 + newpkg->replaces_count = 0;
7886 +
7887 + oldpkg->replaces = newpkg->replaces;
7888 + newpkg->replaces = NULL;
7889 + }
7890 +
7891 + if (!oldpkg->filename)
7892 + oldpkg->filename = str_dup_safe(newpkg->filename);
7893 + if (0)
7894 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7895 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7896 + if (!oldpkg->local_filename)
7897 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7898 + if (!oldpkg->tmp_unpack_dir)
7899 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7900 + if (!oldpkg->md5sum)
7901 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7902 + if (!oldpkg->size)
7903 + oldpkg->size = str_dup_safe(newpkg->size);
7904 + if (!oldpkg->installed_size)
7905 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7906 + if (!oldpkg->priority)
7907 + oldpkg->priority = str_dup_safe(newpkg->priority);
7908 + if (!oldpkg->source)
7909 + oldpkg->source = str_dup_safe(newpkg->source);
7910 + if (oldpkg->conffiles.head == NULL){
7911 + oldpkg->conffiles = newpkg->conffiles;
7912 + conffile_list_init(&newpkg->conffiles);
7913 + }
7914 + if (!oldpkg->installed_files){
7915 + oldpkg->installed_files = newpkg->installed_files;
7916 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7917 + newpkg->installed_files = NULL;
7918 + }
7919 + if (!oldpkg->essential)
7920 + oldpkg->essential = newpkg->essential;
7921 +
7922 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7923 +
7924 + return 0;
7925 +}
7926 +
7927 +abstract_pkg_t *abstract_pkg_new(void)
7928 +{
7929 + abstract_pkg_t * ab_pkg;
7930 +
7931 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7932 +
7933 + if (ab_pkg == NULL) {
7934 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7935 + return NULL;
7936 + }
7937 +
7938 + if ( abstract_pkg_init(ab_pkg) < 0 )
7939 + return NULL;
7940 +
7941 + return ab_pkg;
7942 +}
7943 +
7944 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7945 +{
7946 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7947 +
7948 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7949 + if (ab_pkg->provided_by==NULL){
7950 + return -1;
7951 + }
7952 + ab_pkg->dependencies_checked = 0;
7953 + ab_pkg->state_status = SS_NOT_INSTALLED;
7954 +
7955 + return 0;
7956 +}
7957 +
7958 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7959 + char * temp_str;
7960 + char **raw =NULL;
7961 + char **raw_start=NULL;
7962 +
7963 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7964 + if (temp_str == NULL ){
7965 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7966 + return;
7967 + }
7968 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7969 +
7970 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7971 + if (raw == NULL ){
7972 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7973 + return;
7974 + }
7975 +
7976 + while(*raw){
7977 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7978 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7979 + }
7980 + }
7981 + raw = raw_start;
7982 + while (*raw) {
7983 + if (raw!=NULL)
7984 + free(*raw++);
7985 + }
7986 +
7987 + free(raw_start);
7988 + free(temp_str);
7989 +
7990 + return ;
7991 +
7992 +}
7993 +
7994 +char * pkg_formatted_info(pkg_t *pkg )
7995 +{
7996 + char *line;
7997 + char * buff;
7998 +
7999 + buff = malloc(8192);
8000 + if (buff == NULL) {
8001 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8002 + return NULL;
8003 + }
8004 +
8005 + buff[0] = '\0';
8006 +
8007 + line = pkg_formatted_field(pkg, "Package");
8008 + strncat(buff ,line, strlen(line));
8009 + free(line);
8010 +
8011 + line = pkg_formatted_field(pkg, "Version");
8012 + strncat(buff ,line, strlen(line));
8013 + free(line);
8014 +
8015 + line = pkg_formatted_field(pkg, "Depends");
8016 + strncat(buff ,line, strlen(line));
8017 + free(line);
8018 +
8019 + line = pkg_formatted_field(pkg, "Recommends");
8020 + strncat(buff ,line, strlen(line));
8021 + free(line);
8022 +
8023 + line = pkg_formatted_field(pkg, "Suggests");
8024 + strncat(buff ,line, strlen(line));
8025 + free(line);
8026 +
8027 + line = pkg_formatted_field(pkg, "Provides");
8028 + strncat(buff ,line, strlen(line));
8029 + free(line);
8030 +
8031 + line = pkg_formatted_field(pkg, "Replaces");
8032 + strncat(buff ,line, strlen(line));
8033 + free(line);
8034 +
8035 + line = pkg_formatted_field(pkg, "Conflicts");
8036 + strncat(buff ,line, strlen(line));
8037 + free(line);
8038 +
8039 + line = pkg_formatted_field(pkg, "Status");
8040 + strncat(buff ,line, strlen(line));
8041 + free(line);
8042 +
8043 + line = pkg_formatted_field(pkg, "Section");
8044 + strncat(buff ,line, strlen(line));
8045 + free(line);
8046 +
8047 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8048 + strncat(buff ,line, strlen(line));
8049 + free(line);
8050 +
8051 + line = pkg_formatted_field(pkg, "Architecture");
8052 + strncat(buff ,line, strlen(line));
8053 + free(line);
8054 +
8055 + line = pkg_formatted_field(pkg, "Maintainer");
8056 + strncat(buff ,line, strlen(line));
8057 + free(line);
8058 +
8059 + line = pkg_formatted_field(pkg, "MD5sum");
8060 + strncat(buff ,line, strlen(line));
8061 + free(line);
8062 +
8063 + line = pkg_formatted_field(pkg, "Size");
8064 + strncat(buff ,line, strlen(line));
8065 + free(line);
8066 +
8067 + line = pkg_formatted_field(pkg, "Filename");
8068 + strncat(buff ,line, strlen(line));
8069 + free(line);
8070 +
8071 + line = pkg_formatted_field(pkg, "Conffiles");
8072 + strncat(buff ,line, strlen(line));
8073 + free(line);
8074 +
8075 + line = pkg_formatted_field(pkg, "Source");
8076 + strncat(buff ,line, strlen(line));
8077 + free(line);
8078 +
8079 + line = pkg_formatted_field(pkg, "Description");
8080 + strncat(buff ,line, strlen(line));
8081 + free(line);
8082 +
8083 + line = pkg_formatted_field(pkg, "Installed-Time");
8084 + strncat(buff ,line, strlen(line));
8085 + free(line);
8086 +
8087 + return buff;
8088 +}
8089 +
8090 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8091 +{
8092 + static size_t LINE_LEN = 128;
8093 + char line_str[LINE_LEN];
8094 + char * temp = (char *)malloc(1);
8095 + int len = 0;
8096 + int flag_provide_false = 0;
8097 +
8098 +/*
8099 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8100 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8101 +*/
8102 +
8103 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8104 + goto UNKNOWN_FMT_FIELD;
8105 + }
8106 +
8107 + temp[0]='\0';
8108 +
8109 + switch (field[0])
8110 + {
8111 + case 'a':
8112 + case 'A':
8113 + if (strcasecmp(field, "Architecture") == 0) {
8114 + /* Architecture */
8115 + if (pkg->architecture) {
8116 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8117 + if ( temp == NULL ){
8118 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8119 + return NULL;
8120 + }
8121 + temp[0]='\0';
8122 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8123 + }
8124 + } else {
8125 + goto UNKNOWN_FMT_FIELD;
8126 + }
8127 + break;
8128 + case 'c':
8129 + case 'C':
8130 + if (strcasecmp(field, "Conffiles") == 0) {
8131 + /* Conffiles */
8132 + conffile_list_elt_t *iter;
8133 +
8134 + if (pkg->conffiles.head == NULL) {
8135 + return temp;
8136 + }
8137 +
8138 + len = 14 ;
8139 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8140 + if (iter->data->name && iter->data->value) {
8141 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8142 + }
8143 + }
8144 + temp = (char *)realloc(temp,len);
8145 + if ( temp == NULL ){
8146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8147 + return NULL;
8148 + }
8149 + temp[0]='\0';
8150 + strncpy(temp, "Conffiles:\n", 12);
8151 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8152 + if (iter->data->name && iter->data->value) {
8153 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8154 + strncat(temp, line_str, strlen(line_str));
8155 + }
8156 + }
8157 + } else if (strcasecmp(field, "Conflicts") == 0) {
8158 + int i;
8159 +
8160 + if (pkg->conflicts_count) {
8161 + len = 14 ;
8162 + for(i = 0; i < pkg->conflicts_count; i++) {
8163 + len = len + (strlen(pkg->conflicts_str[i])+5);
8164 + }
8165 + temp = (char *)realloc(temp,len);
8166 + if ( temp == NULL ){
8167 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8168 + return NULL;
8169 + }
8170 + temp[0]='\0';
8171 + strncpy(temp, "Conflicts:", 11);
8172 + for(i = 0; i < pkg->conflicts_count; i++) {
8173 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8174 + strncat(temp, line_str, strlen(line_str));
8175 + }
8176 + strncat(temp, "\n", strlen("\n"));
8177 + }
8178 + } else {
8179 + goto UNKNOWN_FMT_FIELD;
8180 + }
8181 + break;
8182 + case 'd':
8183 + case 'D':
8184 + if (strcasecmp(field, "Depends") == 0) {
8185 + /* Depends */
8186 + int i;
8187 +
8188 + if (pkg->depends_count) {
8189 + len = 14 ;
8190 + for(i = 0; i < pkg->depends_count; i++) {
8191 + len = len + (strlen(pkg->depends_str[i])+4);
8192 + }
8193 + temp = (char *)realloc(temp,len);
8194 + if ( temp == NULL ){
8195 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8196 + return NULL;
8197 + }
8198 + temp[0]='\0';
8199 + strncpy(temp, "Depends:", 10);
8200 + for(i = 0; i < pkg->depends_count; i++) {
8201 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8202 + strncat(temp, line_str, strlen(line_str));
8203 + }
8204 + strncat(temp, "\n", strlen("\n"));
8205 + }
8206 + } else if (strcasecmp(field, "Description") == 0) {
8207 + /* Description */
8208 + if (pkg->description) {
8209 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8210 + if ( temp == NULL ){
8211 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8212 + return NULL;
8213 + }
8214 + temp[0]='\0';
8215 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8216 + }
8217 + } else {
8218 + goto UNKNOWN_FMT_FIELD;
8219 + }
8220 + break;
8221 + case 'e':
8222 + case 'E': {
8223 + /* Essential */
8224 + if (pkg->essential) {
8225 + temp = (char *)realloc(temp,16);
8226 + if ( temp == NULL ){
8227 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8228 + return NULL;
8229 + }
8230 + temp[0]='\0';
8231 + snprintf(temp, (16), "Essential: yes\n");
8232 + }
8233 + }
8234 + break;
8235 + case 'f':
8236 + case 'F': {
8237 + /* Filename */
8238 + if (pkg->filename) {
8239 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8240 + if ( temp == NULL ){
8241 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8242 + return NULL;
8243 + }
8244 + temp[0]='\0';
8245 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8246 + }
8247 + }
8248 + break;
8249 + case 'i':
8250 + case 'I': {
8251 + if (strcasecmp(field, "Installed-Size") == 0) {
8252 + /* Installed-Size */
8253 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8254 + if ( temp == NULL ){
8255 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8256 + return NULL;
8257 + }
8258 + temp[0]='\0';
8259 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8260 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8261 + temp = (char *)realloc(temp,29);
8262 + if ( temp == NULL ){
8263 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8264 + return NULL;
8265 + }
8266 + temp[0]='\0';
8267 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8268 + }
8269 + }
8270 + break;
8271 + case 'm':
8272 + case 'M': {
8273 + /* Maintainer | MD5sum */
8274 + if (strcasecmp(field, "Maintainer") == 0) {
8275 + /* Maintainer */
8276 + if (pkg->maintainer) {
8277 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8278 + if ( temp == NULL ){
8279 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8280 + return NULL;
8281 + }
8282 + temp[0]='\0';
8283 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8284 + }
8285 + } else if (strcasecmp(field, "MD5sum") == 0) {
8286 + /* MD5sum */
8287 + if (pkg->md5sum) {
8288 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8289 + if ( temp == NULL ){
8290 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8291 + return NULL;
8292 + }
8293 + temp[0]='\0';
8294 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8295 + }
8296 + } else {
8297 + goto UNKNOWN_FMT_FIELD;
8298 + }
8299 + }
8300 + break;
8301 + case 'p':
8302 + case 'P': {
8303 + if (strcasecmp(field, "Package") == 0) {
8304 + /* Package */
8305 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8306 + if ( temp == NULL ){
8307 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8308 + return NULL;
8309 + }
8310 + temp[0]='\0';
8311 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8312 + } else if (strcasecmp(field, "Priority") == 0) {
8313 + /* Priority */
8314 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8315 + if ( temp == NULL ){
8316 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8317 + return NULL;
8318 + }
8319 + temp[0]='\0';
8320 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8321 + } else if (strcasecmp(field, "Provides") == 0) {
8322 + /* Provides */
8323 + int i;
8324 +
8325 + if (pkg->provides_count) {
8326 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8327 + for ( i=0; i < pkg->provides_count; i++ ){
8328 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8329 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8330 + flag_provide_false = 1;
8331 + }
8332 + }
8333 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8334 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8335 + char provstr[LINE_LEN];
8336 + len = 15;
8337 + for(i = 0; i < pkg->provides_count; i++) {
8338 + len = len + (strlen(pkg->provides_str[i])+5);
8339 + }
8340 + temp = (char *)realloc(temp,len);
8341 + if ( temp == NULL ){
8342 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8343 + return NULL;
8344 + }
8345 + temp[0]='\0';
8346 + strncpy(temp, "Provides:", 12);
8347 + for(i = 0; i < pkg->provides_count; i++) {
8348 + if (strlen(pkg->provides_str[i])>0){;
8349 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8350 + strncat(temp, provstr, strlen(provstr));
8351 + }
8352 + }
8353 + strncat(temp, "\n", strlen("\n"));
8354 + }
8355 + }
8356 + } else {
8357 + goto UNKNOWN_FMT_FIELD;
8358 + }
8359 + }
8360 + break;
8361 + case 'r':
8362 + case 'R': {
8363 + int i;
8364 + /* Replaces | Recommends*/
8365 + if (strcasecmp (field, "Replaces") == 0) {
8366 + if (pkg->replaces_count) {
8367 + len = 14;
8368 + for (i = 0; i < pkg->replaces_count; i++) {
8369 + len = len + (strlen(pkg->replaces_str[i])+5);
8370 + }
8371 + temp = (char *)realloc(temp,len);
8372 + if ( temp == NULL ){
8373 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8374 + return NULL;
8375 + }
8376 + temp[0]='\0';
8377 + strncpy(temp, "Replaces:", 12);
8378 + for (i = 0; i < pkg->replaces_count; i++) {
8379 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8380 + strncat(temp, line_str, strlen(line_str));
8381 + }
8382 + strncat(temp, "\n", strlen("\n"));
8383 + }
8384 + } else if (strcasecmp (field, "Recommends") == 0) {
8385 + if (pkg->recommends_count) {
8386 + len = 15;
8387 + for(i = 0; i < pkg->recommends_count; i++) {
8388 + len = len + (strlen( pkg->recommends_str[i])+5);
8389 + }
8390 + temp = (char *)realloc(temp,len);
8391 + if ( temp == NULL ){
8392 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8393 + return NULL;
8394 + }
8395 + temp[0]='\0';
8396 + strncpy(temp, "Recommends:", 13);
8397 + for(i = 0; i < pkg->recommends_count; i++) {
8398 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8399 + strncat(temp, line_str, strlen(line_str));
8400 + }
8401 + strncat(temp, "\n", strlen("\n"));
8402 + }
8403 + } else {
8404 + goto UNKNOWN_FMT_FIELD;
8405 + }
8406 + }
8407 + break;
8408 + case 's':
8409 + case 'S': {
8410 + /* Section | Size | Source | Status | Suggests */
8411 + if (strcasecmp(field, "Section") == 0) {
8412 + /* Section */
8413 + if (pkg->section) {
8414 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8415 + if ( temp == NULL ){
8416 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8417 + return NULL;
8418 + }
8419 + temp[0]='\0';
8420 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8421 + }
8422 + } else if (strcasecmp(field, "Size") == 0) {
8423 + /* Size */
8424 + if (pkg->size) {
8425 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8426 + if ( temp == NULL ){
8427 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8428 + return NULL;
8429 + }
8430 + temp[0]='\0';
8431 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8432 + }
8433 + } else if (strcasecmp(field, "Source") == 0) {
8434 + /* Source */
8435 + if (pkg->source) {
8436 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8437 + if ( temp == NULL ){
8438 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8439 + return NULL;
8440 + }
8441 + temp[0]='\0';
8442 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8443 + }
8444 + } else if (strcasecmp(field, "Status") == 0) {
8445 + /* Status */
8446 + /* Benjamin Pineau note: we should avoid direct usage of
8447 + * strlen(arg) without keeping "arg" for later free()
8448 + */
8449 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8450 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8451 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8452 +
8453 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8454 + temp = (char *)realloc(temp,sum_of_sizes);
8455 + if ( temp == NULL ){
8456 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8457 + return NULL;
8458 + }
8459 + temp[0]='\0';
8460 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8461 + free(pflag);
8462 + free(pwant);
8463 + if(pstat) /* pfstat can be NULL if ENOMEM */
8464 + free(pstat);
8465 + } else if (strcasecmp(field, "Suggests") == 0) {
8466 + if (pkg->suggests_count) {
8467 + int i;
8468 + len = 13;
8469 + for(i = 0; i < pkg->suggests_count; i++) {
8470 + len = len + (strlen(pkg->suggests_str[i])+5);
8471 + }
8472 + temp = (char *)realloc(temp,len);
8473 + if ( temp == NULL ){
8474 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8475 + return NULL;
8476 + }
8477 + temp[0]='\0';
8478 + strncpy(temp, "Suggests:", 10);
8479 + for(i = 0; i < pkg->suggests_count; i++) {
8480 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8481 + strncat(temp, line_str, strlen(line_str));
8482 + }
8483 + strncat(temp, "\n", strlen("\n"));
8484 + }
8485 + } else {
8486 + goto UNKNOWN_FMT_FIELD;
8487 + }
8488 + }
8489 + break;
8490 + case 'v':
8491 + case 'V': {
8492 + /* Version */
8493 + char *version = pkg_version_str_alloc(pkg);
8494 + temp = (char *)realloc(temp,strlen(version)+14);
8495 + if ( temp == NULL ){
8496 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8497 + return NULL;
8498 + }
8499 + temp[0]='\0';
8500 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8501 + free(version);
8502 + }
8503 + break;
8504 + default:
8505 + goto UNKNOWN_FMT_FIELD;
8506 + }
8507 +
8508 + if ( strlen(temp)<2 ) {
8509 + temp[0]='\0';
8510 + }
8511 + return temp;
8512 +
8513 + UNKNOWN_FMT_FIELD:
8514 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8515 + if ( strlen(temp)<2 ) {
8516 + temp[0]='\0';
8517 + }
8518 +
8519 + return temp;
8520 +}
8521 +
8522 +void pkg_print_info(pkg_t *pkg, FILE *file)
8523 +{
8524 + char * buff;
8525 + if (pkg == NULL) {
8526 + return;
8527 + }
8528 +
8529 + buff = pkg_formatted_info(pkg);
8530 + if ( buff == NULL )
8531 + return;
8532 + if (strlen(buff)>2){
8533 + fwrite(buff, 1, strlen(buff), file);
8534 + }
8535 + free(buff);
8536 +}
8537 +
8538 +void pkg_print_status(pkg_t * pkg, FILE * file)
8539 +{
8540 + if (pkg == NULL) {
8541 + return;
8542 + }
8543 +
8544 + /* XXX: QUESTION: Do we actually want more fields here? The
8545 + original idea was to save space by installing only what was
8546 + needed for actual computation, (package, version, status,
8547 + essential, conffiles). The assumption is that all other fields
8548 + can be found in th available file.
8549 +
8550 + But, someone proposed the idea to make it possible to
8551 + reconstruct a .ipk from an installed package, (ie. for beaming
8552 + from one handheld to another). So, maybe we actually want a few
8553 + more fields here, (depends, suggests, etc.), so that that would
8554 + be guaranteed to work even in the absence of more information
8555 + from the available file.
8556 +
8557 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8558 + the essential info needs to be here for all installed packages
8559 + because they may not appear in the Packages files on various
8560 + feeds. Furthermore, one should be able to install from URL or
8561 + local storage without requiring a Packages file from any feed.
8562 + -Jamey
8563 + */
8564 + pkg_print_field(pkg, file, "Package");
8565 + pkg_print_field(pkg, file, "Version");
8566 + pkg_print_field(pkg, file, "Depends");
8567 + pkg_print_field(pkg, file, "Recommends");
8568 + pkg_print_field(pkg, file, "Suggests");
8569 + pkg_print_field(pkg, file, "Provides");
8570 + pkg_print_field(pkg, file, "Replaces");
8571 + pkg_print_field(pkg, file, "Conflicts");
8572 + pkg_print_field(pkg, file, "Status");
8573 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8574 + pkg_print_field(pkg, file, "Architecture");
8575 + pkg_print_field(pkg, file, "Conffiles");
8576 + pkg_print_field(pkg, file, "Installed-Time");
8577 + fputs("\n", file);
8578 +}
8579 +
8580 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8581 +{
8582 + char *buff;
8583 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8584 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8585 + __FUNCTION__, field);
8586 + }
8587 + buff = pkg_formatted_field(pkg, field);
8588 + if (strlen(buff)>2) {
8589 + fprintf(file, "%s", buff);
8590 + fflush(file);
8591 + }
8592 + free(buff);
8593 + return;
8594 +}
8595 +
8596 +/*
8597 + * libdpkg - Debian packaging suite library routines
8598 + * vercmp.c - comparison of version numbers
8599 + *
8600 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8601 + */
8602 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8603 +{
8604 + int r;
8605 +
8606 + if (pkg->epoch > ref_pkg->epoch) {
8607 + return 1;
8608 + }
8609 +
8610 + if (pkg->epoch < ref_pkg->epoch) {
8611 + return -1;
8612 + }
8613 +
8614 + r = verrevcmp(pkg->version, ref_pkg->version);
8615 + if (r) {
8616 + return r;
8617 + }
8618 +
8619 +#ifdef USE_DEBVERSION
8620 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8621 + if (r) {
8622 + return r;
8623 + }
8624 +
8625 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8626 +#endif
8627 +
8628 + return r;
8629 +}
8630 +
8631 +int verrevcmp(const char *val, const char *ref)
8632 +{
8633 + int vc, rc;
8634 + long vl, rl;
8635 + const char *vp, *rp;
8636 + const char *vsep, *rsep;
8637 +
8638 + if (!val) val= "";
8639 + if (!ref) ref= "";
8640 + for (;;) {
8641 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8642 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8643 + for (;;) {
8644 + vc= (val == vp) ? 0 : *val++;
8645 + rc= (ref == rp) ? 0 : *ref++;
8646 + if (!rc && !vc) break;
8647 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8648 + if (rc && !isalpha(rc)) rc += 256;
8649 + if (vc != rc) return vc - rc;
8650 + }
8651 + val= vp;
8652 + ref= rp;
8653 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8654 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8655 + if (vl != rl) return vl - rl;
8656 +
8657 + vc = *val;
8658 + rc = *ref;
8659 + vsep = strchr(".-", vc);
8660 + rsep = strchr(".-", rc);
8661 + if (vsep && !rsep) return -1;
8662 + if (!vsep && rsep) return +1;
8663 +
8664 + if (!*val && !*ref) return 0;
8665 + if (!*val) return -1;
8666 + if (!*ref) return +1;
8667 + }
8668 +}
8669 +
8670 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8671 +{
8672 + int r;
8673 +
8674 + r = pkg_compare_versions(it, ref);
8675 +
8676 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8677 + return r <= 0;
8678 + }
8679 +
8680 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8681 + return r >= 0;
8682 + }
8683 +
8684 + if (strcmp(op, "<<") == 0) {
8685 + return r < 0;
8686 + }
8687 +
8688 + if (strcmp(op, ">>") == 0) {
8689 + return r > 0;
8690 + }
8691 +
8692 + if (strcmp(op, "=") == 0) {
8693 + return r == 0;
8694 + }
8695 +
8696 + fprintf(stderr, "unknown operator: %s", op);
8697 + return 0;
8698 +}
8699 +
8700 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8701 +{
8702 + int namecmp;
8703 + int vercmp;
8704 + if (!a->name || !b->name) {
8705 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8706 + a, a->name, b, b->name);
8707 + return 0;
8708 + }
8709 +
8710 + namecmp = strcmp(a->name, b->name);
8711 + if (namecmp)
8712 + return namecmp;
8713 + vercmp = pkg_compare_versions(a, b);
8714 + if (vercmp)
8715 + return vercmp;
8716 + if (!a->arch_priority || !b->arch_priority) {
8717 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8718 + a, a->arch_priority, b, b->arch_priority);
8719 + return 0;
8720 + }
8721 + if (a->arch_priority > b->arch_priority)
8722 + return 1;
8723 + if (a->arch_priority < b->arch_priority)
8724 + return -1;
8725 + return 0;
8726 +}
8727 +
8728 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8729 +{
8730 + if (!a->name || !b->name) {
8731 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8732 + a, a->name, b, b->name);
8733 + return 0;
8734 + }
8735 + return strcmp(a->name, b->name);
8736 +}
8737 +
8738 +
8739 +char *pkg_version_str_alloc(pkg_t *pkg)
8740 +{
8741 + char *complete_version;
8742 + char *epoch_str;
8743 +#ifdef USE_DEBVERSION
8744 + char *revision_str;
8745 + char *familiar_revision_str;
8746 +#endif
8747 +
8748 + if (pkg->epoch) {
8749 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8750 + } else {
8751 + epoch_str = strdup("");
8752 + }
8753 +
8754 +#ifdef USE_DEBVERSION
8755 + if (pkg->revision && strlen(pkg->revision)) {
8756 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8757 + } else {
8758 + revision_str = strdup("");
8759 + }
8760 +
8761 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8762 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8763 + } else {
8764 + familiar_revision_str = strdup("");
8765 + }
8766 +#endif
8767 +
8768 +#ifdef USE_DEBVERSION
8769 + sprintf_alloc(&complete_version, "%s%s%s%s",
8770 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8771 +#else
8772 + sprintf_alloc(&complete_version, "%s%s",
8773 + epoch_str, pkg->version);
8774 +#endif
8775 +
8776 + free(epoch_str);
8777 +#ifdef USE_DEBVERSION
8778 + free(revision_str);
8779 + free(familiar_revision_str);
8780 +#endif
8781 +
8782 + return complete_version;
8783 +}
8784 +
8785 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8786 +{
8787 + int err;
8788 + char *list_file_name = NULL;
8789 + FILE *list_file = NULL;
8790 + char *line;
8791 + char *installed_file_name;
8792 + int rootdirlen;
8793 +
8794 + pkg->installed_files_ref_cnt++;
8795 +
8796 + if (pkg->installed_files) {
8797 + return pkg->installed_files;
8798 + }
8799 +
8800 + pkg->installed_files = str_list_alloc();
8801 + if (pkg->installed_files == NULL) {
8802 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8803 + return NULL;
8804 + }
8805 +
8806 + /* For uninstalled packages, get the file list firectly from the package.
8807 + For installed packages, look at the package.list file in the database.
8808 + */
8809 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8810 + if (pkg->local_filename == NULL) {
8811 + return pkg->installed_files;
8812 + }
8813 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8814 + file. In other words, change deb_extract so that it can
8815 + simply return the file list as a char *[] rather than
8816 + insisting on writing in to a FILE * as it does now. */
8817 + list_file = tmpfile();
8818 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8819 + if (err) {
8820 + fclose(list_file);
8821 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8822 + __FUNCTION__, pkg->local_filename, strerror(err));
8823 + return pkg->installed_files;
8824 + }
8825 + rewind(list_file);
8826 + } else {
8827 + sprintf_alloc(&list_file_name, "%s/%s.list",
8828 + pkg->dest->info_dir, pkg->name);
8829 + if (! file_exists(list_file_name)) {
8830 + free(list_file_name);
8831 + return pkg->installed_files;
8832 + }
8833 +
8834 + list_file = fopen(list_file_name, "r");
8835 + if (list_file == NULL) {
8836 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8837 + list_file_name, strerror(errno));
8838 + free(list_file_name);
8839 + return pkg->installed_files;
8840 + }
8841 + free(list_file_name);
8842 + }
8843 +
8844 + rootdirlen = strlen( pkg->dest->root_dir );
8845 + while (1) {
8846 + char *file_name;
8847 +
8848 + line = file_read_line_alloc(list_file);
8849 + if (line == NULL) {
8850 + break;
8851 + }
8852 + str_chomp(line);
8853 + file_name = line;
8854 +
8855 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8856 + if( strncmp( pkg->dest->root_dir,
8857 + file_name,
8858 + rootdirlen ) ) {
8859 + if (*file_name == '.') {
8860 + file_name++;
8861 + }
8862 + if (*file_name == '/') {
8863 + file_name++;
8864 + }
8865 +
8866 + /* Freed in pkg_free_installed_files */
8867 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8868 + } else {
8869 + // already contains root_dir as header -> ABSOLUTE
8870 + sprintf_alloc(&installed_file_name, "%s", file_name);
8871 + }
8872 + str_list_append(pkg->installed_files, installed_file_name);
8873 + free(line);
8874 + }
8875 +
8876 + fclose(list_file);
8877 +
8878 + return pkg->installed_files;
8879 +}
8880 +
8881 +/* XXX: CLEANUP: This function and it's counterpart,
8882 + (pkg_get_installed_files), do not match our init/deinit naming
8883 + convention. Nor the alloc/free convention. But, then again, neither
8884 + of these conventions currrently fit the way these two functions
8885 + work. */
8886 +int pkg_free_installed_files(pkg_t *pkg)
8887 +{
8888 + str_list_elt_t *iter;
8889 +
8890 + pkg->installed_files_ref_cnt--;
8891 + if (pkg->installed_files_ref_cnt > 0) {
8892 + return 0;
8893 + }
8894 +
8895 + if (pkg->installed_files) {
8896 +
8897 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8898 + /* malloced in pkg_get_installed_files */
8899 + free (iter->data);
8900 + iter->data = NULL;
8901 + }
8902 +
8903 + str_list_deinit(pkg->installed_files);
8904 + }
8905 +
8906 + pkg->installed_files = NULL;
8907 +
8908 + return 0;
8909 +}
8910 +
8911 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8912 +{
8913 + int err;
8914 + char *list_file_name;
8915 +
8916 + //I don't think pkg_free_installed_files should be called here. Jamey
8917 + //pkg_free_installed_files(pkg);
8918 +
8919 + sprintf_alloc(&list_file_name, "%s/%s.list",
8920 + pkg->dest->info_dir, pkg->name);
8921 + if (!conf->noaction) {
8922 + err = unlink(list_file_name);
8923 + free(list_file_name);
8924 +
8925 + if (err) {
8926 + return errno;
8927 + }
8928 + }
8929 + return 0;
8930 +}
8931 +
8932 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8933 +{
8934 + conffile_list_elt_t *iter;
8935 + conffile_t *conffile;
8936 +
8937 + if (pkg == NULL) {
8938 + return NULL;
8939 + }
8940 +
8941 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8942 + conffile = iter->data;
8943 +
8944 + if (strcmp(conffile->name, file_name) == 0) {
8945 + return conffile;
8946 + }
8947 + }
8948 +
8949 + return NULL;
8950 +}
8951 +
8952 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8953 + const char *script, const char *args)
8954 +{
8955 + int err;
8956 + char *path;
8957 + char *cmd;
8958 +
8959 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8960 + maintainer script within a chroot environment. */
8961 +
8962 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8963 + have scripts in pkg->tmp_unpack_dir. */
8964 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8965 + if (pkg->dest == NULL) {
8966 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8967 + __FUNCTION__, pkg->name);
8968 + return EINVAL;
8969 + }
8970 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8971 + } else {
8972 + if (pkg->tmp_unpack_dir == NULL) {
8973 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8974 + __FUNCTION__, pkg->name);
8975 + return EINVAL;
8976 + }
8977 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8978 + }
8979 +
8980 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8981 + if (conf->noaction) return 0;
8982 +
8983 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8984 + scripts when running with offline_root mode and/or a dest other
8985 + than '/'. I've been playing around with some clever chroot
8986 + tricks and I might come up with something workable. */
8987 + if (conf->offline_root) {
8988 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8989 + }
8990 +
8991 + setenv("PKG_ROOT",
8992 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8993 +
8994 + if (! file_exists(path)) {
8995 + free(path);
8996 + return 0;
8997 + }
8998 +
8999 + if (conf->offline_root) {
9000 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9001 + free(path);
9002 + return 0;
9003 + }
9004 +
9005 + sprintf_alloc(&cmd, "%s %s", path, args);
9006 + free(path);
9007 +
9008 + err = xsystem(cmd);
9009 + free(cmd);
9010 +
9011 + if (err) {
9012 + fprintf(stderr, "%s script returned status %d\n", script, err);
9013 + return err;
9014 + }
9015 +
9016 + return 0;
9017 +}
9018 +
9019 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9020 +{
9021 + int i;
9022 +
9023 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9024 + if (pkg_state_want_map[i].value == sw) {
9025 + return strdup(pkg_state_want_map[i].str);
9026 + }
9027 + }
9028 +
9029 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9030 + __FUNCTION__, sw);
9031 + return strdup("<STATE_WANT_UNKNOWN>");
9032 +}
9033 +
9034 +pkg_state_want_t pkg_state_want_from_str(char *str)
9035 +{
9036 + int i;
9037 +
9038 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9039 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9040 + return pkg_state_want_map[i].value;
9041 + }
9042 + }
9043 +
9044 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9045 + __FUNCTION__, str);
9046 + return SW_UNKNOWN;
9047 +}
9048 +
9049 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9050 +{
9051 + int i;
9052 + int len = 3; /* ok\000 is minimum */
9053 + char *str = NULL;
9054 +
9055 + /* clear the temporary flags before converting to string */
9056 + sf &= SF_NONVOLATILE_FLAGS;
9057 +
9058 + if (sf == 0) {
9059 + return strdup("ok");
9060 + } else {
9061 +
9062 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9063 + if (sf & pkg_state_flag_map[i].value) {
9064 + len += strlen(pkg_state_flag_map[i].str) + 1;
9065 + }
9066 + }
9067 + str = malloc(len);
9068 + if ( str == NULL ) {
9069 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9070 + return NULL;
9071 + }
9072 + str[0] = 0;
9073 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9074 + if (sf & pkg_state_flag_map[i].value) {
9075 + strcat(str, pkg_state_flag_map[i].str);
9076 + strcat(str, ",");
9077 + }
9078 + }
9079 + len = strlen(str);
9080 + str[len-1] = 0; /* squash last comma */
9081 + return str;
9082 + }
9083 +}
9084 +
9085 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9086 +{
9087 + int i;
9088 + int sf = SF_OK;
9089 +
9090 + if (strcmp(str, "ok") == 0) {
9091 + return SF_OK;
9092 + }
9093 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9094 + const char *sfname = pkg_state_flag_map[i].str;
9095 + int sfname_len = strlen(sfname);
9096 + if (strncmp(str, sfname, sfname_len) == 0) {
9097 + sf |= pkg_state_flag_map[i].value;
9098 + str += sfname_len;
9099 + if (str[0] == ',') {
9100 + str++;
9101 + } else {
9102 + break;
9103 + }
9104 + }
9105 + }
9106 +
9107 + return sf;
9108 +}
9109 +
9110 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9111 +{
9112 + int i;
9113 +
9114 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9115 + if (pkg_state_status_map[i].value == ss) {
9116 + return strdup(pkg_state_status_map[i].str);
9117 + }
9118 + }
9119 +
9120 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9121 + __FUNCTION__, ss);
9122 + return strdup("<STATE_STATUS_UNKNOWN>");
9123 +}
9124 +
9125 +pkg_state_status_t pkg_state_status_from_str(char *str)
9126 +{
9127 + int i;
9128 +
9129 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9130 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9131 + return pkg_state_status_map[i].value;
9132 + }
9133 + }
9134 +
9135 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9136 + __FUNCTION__, str);
9137 + return SS_NOT_INSTALLED;
9138 +}
9139 +
9140 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9141 +{
9142 + nv_pair_list_elt_t *l;
9143 +
9144 + if (!pkg->architecture)
9145 + return 1;
9146 +
9147 + l = conf->arch_list.head;
9148 +
9149 + while (l) {
9150 + nv_pair_t *nv = l->data;
9151 + if (strcmp(nv->name, pkg->architecture) == 0) {
9152 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9153 + return 1;
9154 + }
9155 + l = l->next;
9156 + }
9157 +
9158 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9159 + return 0;
9160 +}
9161 +
9162 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9163 +{
9164 + nv_pair_list_elt_t *l;
9165 +
9166 + l = conf->arch_list.head;
9167 +
9168 + while (l) {
9169 + nv_pair_t *nv = l->data;
9170 + if (strcmp(nv->name, archname) == 0) {
9171 + int priority = strtol(nv->value, NULL, 0);
9172 + return priority;
9173 + }
9174 + l = l->next;
9175 + }
9176 + return 0;
9177 +}
9178 +
9179 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9180 +{
9181 + int i;
9182 + hash_table_t *pkg_hash = &conf->pkg_hash;
9183 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9184 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9185 +
9186 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9187 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9188 + /* update arch_priority for each package */
9189 + for (i = 0; i < available_pkgs->len; i++) {
9190 + pkg_t *pkg = available_pkgs->pkgs[i];
9191 + int arch_priority = 1;
9192 + if (!pkg)
9193 + continue;
9194 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9195 + if (pkg->architecture)
9196 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9197 + else
9198 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9199 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9200 + pkg->arch_priority = arch_priority;
9201 + }
9202 +
9203 + for (i = 0; i < available_pkgs->len; i++) {
9204 + pkg_t *pkg = available_pkgs->pkgs[i];
9205 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9206 + /* clear flags and want for any uninstallable package */
9207 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9208 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9209 + pkg->state_want = SW_UNKNOWN;
9210 + pkg->state_flag = 0;
9211 + }
9212 + }
9213 + pkg_vec_free(available_pkgs);
9214 +
9215 + /* update the file owner data structure */
9216 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9217 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9218 + for (i = 0; i < installed_pkgs->len; i++) {
9219 + pkg_t *pkg = installed_pkgs->pkgs[i];
9220 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9221 + str_list_elt_t *iter;
9222 + if (installed_files == NULL) {
9223 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9224 + break;
9225 + }
9226 + for (iter = installed_files->head; iter; iter = iter->next) {
9227 + char *installed_file = iter->data;
9228 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9229 + file_hash_set_file_owner(conf, installed_file, pkg);
9230 + }
9231 + }
9232 + pkg_vec_free(installed_pkgs);
9233 +
9234 + return 0;
9235 +}
9236 +
9237 +struct pkg_write_filelist_data {
9238 + ipkg_conf_t *conf;
9239 + pkg_t *pkg;
9240 + FILE *stream;
9241 +};
9242 +
9243 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9244 +{
9245 + struct pkg_write_filelist_data *data = data_;
9246 + pkg_t *entry = entry_;
9247 + if (entry == data->pkg) {
9248 + fprintf(data->stream, "%s\n", key);
9249 + }
9250 +}
9251 +
9252 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9253 +{
9254 + struct pkg_write_filelist_data data;
9255 + char *list_file_name = NULL;
9256 + int err = 0;
9257 +
9258 + if (!pkg) {
9259 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9260 + return -EINVAL;
9261 + }
9262 + ipkg_message(conf, IPKG_INFO,
9263 + " creating %s.list file\n", pkg->name);
9264 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9265 + if (!list_file_name) {
9266 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9267 + return -ENOMEM;
9268 + }
9269 + ipkg_message(conf, IPKG_INFO,
9270 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9271 + data.stream = fopen(list_file_name, "w");
9272 + if (!data.stream) {
9273 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9274 + list_file_name, strerror(errno));
9275 + return errno;
9276 + }
9277 + data.pkg = pkg;
9278 + data.conf = conf;
9279 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9280 + fclose(data.stream);
9281 + free(list_file_name);
9282 +
9283 + return err;
9284 +}
9285 +
9286 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9287 +{
9288 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9289 + hash_table_t *pkg_hash = &conf->pkg_hash;
9290 + int i;
9291 + int err;
9292 + if (conf->noaction)
9293 + return 0;
9294 +
9295 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9296 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9297 + for (i = 0; i < installed_pkgs->len; i++) {
9298 + pkg_t *pkg = installed_pkgs->pkgs[i];
9299 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9300 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9301 + err = pkg_write_filelist(conf, pkg);
9302 + if (err)
9303 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9304 + }
9305 + }
9306 + return 0;
9307 +}
9308 Index: busybox-1.4.2/archival/libipkg/pkg_depends.c
9309 ===================================================================
9310 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9311 +++ busybox-1.4.2/archival/libipkg/pkg_depends.c 2007-06-04 13:21:36.724393712 +0200
9312 @@ -0,0 +1,1031 @@
9313 +/* pkg_depends.c - the itsy package management system
9314 +
9315 + Steven M. Ayer
9316 +
9317 + Copyright (C) 2002 Compaq Computer Corporation
9318 +
9319 + This program is free software; you can redistribute it and/or
9320 + modify it under the terms of the GNU General Public License as
9321 + published by the Free Software Foundation; either version 2, or (at
9322 + your option) any later version.
9323 +
9324 + This program is distributed in the hope that it will be useful, but
9325 + WITHOUT ANY WARRANTY; without even the implied warranty of
9326 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9327 + General Public License for more details.
9328 +*/
9329 +
9330 +#include "ipkg.h"
9331 +#include <errno.h>
9332 +#include <ctype.h>
9333 +
9334 +#include "pkg.h"
9335 +#include "ipkg_utils.h"
9336 +#include "pkg_hash.h"
9337 +#include "ipkg_message.h"
9338 +#include "pkg_parse.h"
9339 +#include "hash_table.h"
9340 +
9341 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9342 +static depend_t * depend_init(void);
9343 +static void depend_deinit(depend_t *d);
9344 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9345 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9346 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9347 +
9348 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9349 +{
9350 + depend_t *depend = (depend_t *)cdata;
9351 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9352 + return 1;
9353 + else
9354 + return 0;
9355 +}
9356 +
9357 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9358 +{
9359 + depend_t *depend = (depend_t *)cdata;
9360 +#if 0
9361 + pkg_t * temp = pkg_new();
9362 + int comparison;
9363 + parseVersion(temp, depend->version);
9364 + comparison = pkg_compare_versions(pkg, temp);
9365 + free(temp);
9366 +
9367 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9368 + __FUNCTION__, pkg->name, pkg->version,
9369 + depend, depend->constraint, depend->version,
9370 + comparison, version_constraints_satisfied(depend, pkg));
9371 +#endif
9372 + if (version_constraints_satisfied(depend, pkg))
9373 + return 1;
9374 + else
9375 + return 0;
9376 +}
9377 +
9378 +/* returns ndependences or negative error value */
9379 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9380 + pkg_vec_t *unsatisfied, char *** unresolved)
9381 +{
9382 + pkg_t * satisfier_entry_pkg;
9383 + register int i, j, k, l;
9384 + int count, found;
9385 + char ** the_lost;
9386 + abstract_pkg_t * ab_pkg;
9387 +
9388 + /*
9389 + * this is a setup to check for redundant/cyclic dependency checks,
9390 + * which are marked at the abstract_pkg level
9391 + */
9392 + if (!(ab_pkg = pkg->parent)) {
9393 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9394 + *unresolved = NULL;
9395 + return 0;
9396 + }
9397 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9398 + *unresolved = NULL;
9399 + return 0;
9400 + } else {
9401 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9402 + }
9403 + /**/
9404 +
9405 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9406 + if (!count){
9407 + *unresolved = NULL;
9408 + return 0;
9409 + }
9410 +
9411 + the_lost = NULL;
9412 +
9413 + /* foreach dependency */
9414 + for (i = 0; i < count; i++) {
9415 + compound_depend_t * compound_depend = &pkg->depends[i];
9416 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9417 + found = 0;
9418 + satisfier_entry_pkg = NULL;
9419 +
9420 + if (compound_depend->type == GREEDY_DEPEND) {
9421 + /* foreach possible satisfier */
9422 + for (j = 0; j < compound_depend->possibility_count; j++) {
9423 + /* foreach provided_by, which includes the abstract_pkg itself */
9424 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9425 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9426 + int nposs = ab_provider_vec->len;
9427 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9428 + for (l = 0; l < nposs; l++) {
9429 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9430 + /* if no depends on this one, try the first package that Provides this one */
9431 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9432 + continue;
9433 + }
9434 +
9435 + /* cruise this possiblity's pkg_vec looking for an installed version */
9436 + for (k = 0; k < test_vec->len; k++) {
9437 + pkg_t *pkg_scout = test_vec->pkgs[k];
9438 + /* not installed, and not already known about? */
9439 + if ((pkg_scout->state_want != SW_INSTALL)
9440 + && !pkg_scout->parent->dependencies_checked
9441 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9442 + char ** newstuff = NULL;
9443 + int rc;
9444 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9445 + /* check for not-already-installed dependencies */
9446 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9447 + pkg_scout,
9448 + tmp_vec,
9449 + &newstuff);
9450 + if (newstuff == NULL) {
9451 + int ok = 1;
9452 + for (l = 0; l < rc; l++) {
9453 + pkg_t *p = tmp_vec->pkgs[l];
9454 + if (p->state_want == SW_INSTALL)
9455 + continue;
9456 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9457 + ok = 0;
9458 + break;
9459 + }
9460 + pkg_vec_free (tmp_vec);
9461 + if (ok) {
9462 + /* mark this one for installation */
9463 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9464 + pkg_vec_insert(unsatisfied, pkg_scout);
9465 + }
9466 + } else {
9467 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9468 + free (newstuff);
9469 + }
9470 + }
9471 + }
9472 + }
9473 + }
9474 +
9475 + continue;
9476 + }
9477 +
9478 + /* foreach possible satisfier, look for installed package */
9479 + for (j = 0; j < compound_depend->possibility_count; j++) {
9480 + /* foreach provided_by, which includes the abstract_pkg itself */
9481 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9482 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9483 + pkg_t *satisfying_pkg =
9484 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9485 + pkg_installed_and_constraint_satisfied,
9486 + dependence_to_satisfy, 1);
9487 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9488 + if (satisfying_pkg != NULL) {
9489 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9490 + satisfying_pkg = NULL;
9491 + }
9492 + }
9493 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9494 + if (satisfying_pkg != NULL) {
9495 + found = 1;
9496 + break;
9497 + }
9498 +
9499 + }
9500 + /* if nothing installed matches, then look for uninstalled satisfier */
9501 + if (!found) {
9502 + /* foreach possible satisfier, look for installed package */
9503 + for (j = 0; j < compound_depend->possibility_count; j++) {
9504 + /* foreach provided_by, which includes the abstract_pkg itself */
9505 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9506 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9507 + pkg_t *satisfying_pkg =
9508 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9509 + pkg_constraint_satisfied,
9510 + dependence_to_satisfy, 1);
9511 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9512 + if (satisfying_pkg != NULL) {
9513 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9514 + satisfying_pkg = NULL;
9515 + }
9516 + }
9517 +
9518 + /* user request overrides package recommendation */
9519 + if (satisfying_pkg != NULL
9520 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9521 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9522 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9523 + pkg->name, satisfying_pkg->name);
9524 + continue;
9525 + }
9526 +
9527 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9528 + if (satisfying_pkg != NULL) {
9529 + satisfier_entry_pkg = satisfying_pkg;
9530 + break;
9531 + }
9532 + }
9533 + }
9534 +
9535 + /* we didn't find one, add something to the unsatisfied vector */
9536 + if (!found) {
9537 + if (!satisfier_entry_pkg) {
9538 + /* failure to meet recommendations is not an error */
9539 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9540 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9541 + else
9542 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9543 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9544 + }
9545 + else {
9546 + if (compound_depend->type == SUGGEST) {
9547 + /* just mention it politely */
9548 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9549 + pkg->name, satisfier_entry_pkg->name);
9550 + } else {
9551 + char ** newstuff = NULL;
9552 +
9553 + if (satisfier_entry_pkg != pkg &&
9554 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9555 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9556 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9557 + satisfier_entry_pkg,
9558 + unsatisfied,
9559 + &newstuff);
9560 + the_lost = merge_unresolved(the_lost, newstuff);
9561 + }
9562 + }
9563 + }
9564 + }
9565 + }
9566 + *unresolved = the_lost;
9567 +
9568 + return unsatisfied->len;
9569 +}
9570 +
9571 +/*checking for conflicts !in replaces
9572 + If a packages conflicts with another but is also replacing it, I should not consider it a
9573 + really conflicts
9574 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9575 +*/
9576 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9577 +{
9578 + int i ;
9579 + int replaces_count = pkg->replaces_count;
9580 + abstract_pkg_t **replaces;
9581 +
9582 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9583 + return 0;
9584 +
9585 + replaces = pkg->replaces;
9586 +
9587 + for (i = 0; i < replaces_count; i++) {
9588 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9589 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9590 + return 1;
9591 + }
9592 + }
9593 + return 0;
9594 +
9595 +}
9596 +
9597 +
9598 +/* Abhaya: added support for conflicts */
9599 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9600 +{
9601 + pkg_vec_t * installed_conflicts, * test_vec;
9602 + compound_depend_t * conflicts;
9603 + depend_t ** possible_satisfiers;
9604 + depend_t * possible_satisfier;
9605 + register int i, j, k;
9606 + int count;
9607 + abstract_pkg_t * ab_pkg;
9608 + pkg_t **pkg_scouts;
9609 + pkg_t *pkg_scout;
9610 +
9611 + /*
9612 + * this is a setup to check for redundant/cyclic dependency checks,
9613 + * which are marked at the abstract_pkg level
9614 + */
9615 + if(!(ab_pkg = pkg->parent)){
9616 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9617 + return (pkg_vec_t *)NULL;
9618 + }
9619 +
9620 + conflicts = pkg->conflicts;
9621 + if(!conflicts){
9622 + return (pkg_vec_t *)NULL;
9623 + }
9624 + installed_conflicts = pkg_vec_alloc();
9625 +
9626 + count = pkg->conflicts_count;
9627 +
9628 +
9629 +
9630 + /* foreach conflict */
9631 + for(i = 0; i < pkg->conflicts_count; i++){
9632 +
9633 + possible_satisfiers = conflicts->possibilities;
9634 +
9635 + /* foreach possible satisfier */
9636 + for(j = 0; j < conflicts->possibility_count; j++){
9637 + possible_satisfier = possible_satisfiers[j];
9638 + if (!possible_satisfier)
9639 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9640 + if (!possible_satisfier->pkg)
9641 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9642 + test_vec = possible_satisfier->pkg->pkgs;
9643 + if (test_vec) {
9644 + /* pkg_vec found, it is an actual package conflict
9645 + * cruise this possiblity's pkg_vec looking for an installed version */
9646 + pkg_scouts = test_vec->pkgs;
9647 + for(k = 0; k < test_vec->len; k++){
9648 + pkg_scout = pkg_scouts[k];
9649 + if (!pkg_scout) {
9650 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9651 + continue;
9652 + }
9653 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9654 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9655 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9656 + pkg_vec_insert(installed_conflicts, pkg_scout);
9657 + }
9658 + }
9659 + }
9660 + }
9661 + }
9662 + conflicts++;
9663 + }
9664 +
9665 + if (installed_conflicts->len)
9666 + return installed_conflicts;
9667 + pkg_vec_free(installed_conflicts);
9668 + return (pkg_vec_t *)NULL;
9669 +}
9670 +
9671 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9672 +{
9673 + pkg_t * temp;
9674 + int comparison;
9675 +
9676 + if(depends->constraint == NONE)
9677 + return 1;
9678 +
9679 + temp = pkg_new();
9680 +
9681 + parseVersion(temp, depends->version);
9682 +
9683 + comparison = pkg_compare_versions(pkg, temp);
9684 +
9685 + free(temp);
9686 +
9687 + if((depends->constraint == EARLIER) &&
9688 + (comparison < 0))
9689 + return 1;
9690 + else if((depends->constraint == LATER) &&
9691 + (comparison > 0))
9692 + return 1;
9693 + else if(comparison == 0)
9694 + return 1;
9695 + else if((depends->constraint == LATER_EQUAL) &&
9696 + (comparison >= 0))
9697 + return 1;
9698 + else if((depends->constraint == EARLIER_EQUAL) &&
9699 + (comparison <= 0))
9700 + return 1;
9701 +
9702 + return 0;
9703 +}
9704 +
9705 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9706 +{
9707 + abstract_pkg_t *apkg = depend->pkg;
9708 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9709 + int n_providers = provider_apkgs->len;
9710 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9711 + pkg_vec_t *pkg_vec;
9712 + int n_pkgs ;
9713 + int i;
9714 + int j;
9715 +
9716 + for (i = 0; i < n_providers; i++) {
9717 + abstract_pkg_t *papkg = apkgs[i];
9718 + pkg_vec = papkg->pkgs;
9719 + if (pkg_vec) {
9720 + n_pkgs = pkg_vec->len;
9721 + for (j = 0; j < n_pkgs; j++) {
9722 + pkg_t *pkg = pkg_vec->pkgs[j];
9723 + if (version_constraints_satisfied(depend, pkg)) {
9724 + return 1;
9725 + }
9726 + }
9727 + }
9728 + }
9729 + return 0;
9730 +}
9731 +
9732 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9733 +{
9734 + abstract_pkg_t *apkg = depend->pkg;
9735 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9736 + int n_providers = provider_apkgs->len;
9737 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9738 + int i;
9739 + int n_pkgs;
9740 + int j;
9741 +
9742 + for (i = 0; i < n_providers; i++) {
9743 + abstract_pkg_t *papkg = apkgs[i];
9744 + pkg_vec_t *pkg_vec = papkg->pkgs;
9745 + if (pkg_vec) {
9746 + n_pkgs = pkg_vec->len;
9747 + for (j = 0; j < n_pkgs; j++) {
9748 + pkg_t *pkg = pkg_vec->pkgs[j];
9749 + if (version_constraints_satisfied(depend, pkg)) {
9750 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9751 + return 1;
9752 + }
9753 + }
9754 + }
9755 + }
9756 + return 0;
9757 +}
9758 +
9759 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9760 +{
9761 + register int i;
9762 + pkg_t ** pkgs = vec->pkgs;
9763 +
9764 + for(i = 0; i < vec->len; i++)
9765 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9766 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9767 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9768 + return 1;
9769 + return 0;
9770 +}
9771 +
9772 +
9773 +#ifdef DeadCode
9774 +/**
9775 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9776 + * the same abstract package and 0 otherwise.
9777 + */
9778 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9779 +{
9780 + abstract_pkg_t **provides = pkg->provides;
9781 + int provides_count = pkg->provides_count;
9782 + abstract_pkg_t **replacee_provides = replacee->provides;
9783 + int replacee_provides_count = replacee->provides_count;
9784 + int i, j;
9785 + for (i = 0; i < provides_count; i++) {
9786 + abstract_pkg_t *apkg = provides[i];
9787 + for (j = 0; j < replacee_provides_count; j++) {
9788 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9789 + if (apkg == replacee_apkg)
9790 + return 1;
9791 + }
9792 + }
9793 + return 0;
9794 +}
9795 +#endif
9796 +
9797 +/**
9798 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9799 + * and 0 otherwise.
9800 + */
9801 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9802 +{
9803 + abstract_pkg_t **provides = pkg->provides;
9804 + int provides_count = pkg->provides_count;
9805 + int i;
9806 + for (i = 0; i < provides_count; i++) {
9807 + if (provides[i] == providee)
9808 + return 1;
9809 + }
9810 + return 0;
9811 +}
9812 +
9813 +/**
9814 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9815 + * otherwise.
9816 + */
9817 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9818 +{
9819 + abstract_pkg_t **replaces = pkg->replaces;
9820 + int replaces_count = pkg->replaces_count;
9821 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9822 + int replacee_provides_count = pkg->provides_count; */
9823 + int i, j;
9824 + for (i = 0; i < replaces_count; i++) {
9825 + abstract_pkg_t *abstract_replacee = replaces[i];
9826 + for (j = 0; j < replaces_count; j++) {
9827 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9828 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9829 + if (replacee->provides[j] == abstract_replacee)
9830 + return 1;
9831 + }
9832 + }
9833 + return 0;
9834 +}
9835 +
9836 +
9837 +/**
9838 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9839 + * otherwise.
9840 + */
9841 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9842 +{
9843 + compound_depend_t *conflicts = pkg->conflicts;
9844 + int conflicts_count = pkg->conflicts_count;
9845 + int i, j;
9846 + for (i = 0; i < conflicts_count; i++) {
9847 + int possibility_count = conflicts[i].possibility_count;
9848 + struct depend **possibilities = conflicts[i].possibilities;
9849 + for (j = 0; j < possibility_count; j++) {
9850 + if (possibilities[j]->pkg == conflictee) {
9851 + return 1;
9852 + }
9853 + }
9854 + }
9855 + return 0;
9856 +}
9857 +
9858 +/**
9859 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9860 + * conflictee's provides and 0 otherwise.
9861 + */
9862 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9863 +{
9864 + compound_depend_t *conflicts = pkg->conflicts;
9865 + int conflicts_count = pkg->conflicts_count;
9866 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9867 + int conflictee_provides_count = conflictee->provides_count;
9868 + int i, j, k;
9869 + int possibility_count;
9870 + struct depend **possibilities;
9871 + abstract_pkg_t *possibility ;
9872 +
9873 + for (i = 0; i < conflicts_count; i++) {
9874 + possibility_count = conflicts[i].possibility_count;
9875 + possibilities = conflicts[i].possibilities;
9876 + for (j = 0; j < possibility_count; j++) {
9877 + possibility = possibilities[j]->pkg;
9878 + for (k = 0; k < conflictee_provides_count; k++) {
9879 + if (possibility == conflictee_provides[k]) {
9880 + return 1;
9881 + }
9882 + }
9883 + }
9884 + }
9885 + return 0;
9886 +}
9887 +
9888 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9889 +{
9890 + int oldlen = 0, newlen = 0;
9891 + char ** result;
9892 + register int i, j;
9893 +
9894 + if(!newstuff)
9895 + return oldstuff;
9896 +
9897 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9898 + while(newstuff && newstuff[newlen]) newlen++;
9899 +
9900 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9901 + if (result == NULL) {
9902 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9903 + return NULL;
9904 + }
9905 +
9906 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9907 + *(result + i) = *(newstuff + j);
9908 +
9909 + *(result + i) = NULL;
9910 +
9911 + return result;
9912 +}
9913 +
9914 +/*
9915 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9916 + * this is null terminated, no count is carried around
9917 + */
9918 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9919 +{
9920 + int count;
9921 + char ** resized;
9922 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9923 +
9924 + count = 0;
9925 + while(the_lost && the_lost[count]) count++;
9926 +
9927 + count++; /* need one to hold the null */
9928 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9929 + if (resized == NULL) {
9930 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9931 + return NULL;
9932 + }
9933 + resized[count - 1] = strdup(depend_str);
9934 + resized[count] = NULL;
9935 +
9936 + return resized;
9937 +}
9938 +
9939 +void printDepends(pkg_t * pkg)
9940 +{
9941 + register int i, j;
9942 + compound_depend_t * depend;
9943 + int count;
9944 +
9945 + count = pkg->pre_depends_count + pkg->depends_count;
9946 +
9947 + depend = pkg->depends;
9948 + if(!depend){
9949 + fprintf(stderr, "Depends pointer is NULL\n");
9950 + return;
9951 + }
9952 + for(i = 0; i < count; i++){
9953 + fprintf(stderr, "%s has %d possibilities:\n",
9954 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9955 + depend->possibility_count);
9956 + for(j = 0; j < depend->possibility_count; j++)
9957 + fprintf(stderr, "\t%s version %s (%d)\n",
9958 + depend->possibilities[j]->pkg->name,
9959 + depend->possibilities[j]->version,
9960 + depend->possibilities[j]->constraint);
9961 + depend++;
9962 + }
9963 +}
9964 +
9965 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9966 +{
9967 + register int i, j;
9968 +
9969 + /* every pkg provides itself */
9970 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9971 +
9972 + if (!pkg->provides_count)
9973 + return 0;
9974 +
9975 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9976 + if (pkg->provides == NULL) {
9977 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9978 + return -1 ;
9979 + }
9980 + pkg->provides[0] = ab_pkg;
9981 +
9982 + // if (strcmp(ab_pkg->name, pkg->name))
9983 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9984 +
9985 + for(i = 0; i < pkg->provides_count; i++){
9986 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9987 +
9988 + pkg->provides[i+1] = provided_abpkg;
9989 +
9990 + j = 0;
9991 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9992 + }
9993 + return 0;
9994 +}
9995 +
9996 +/* Abhaya: added conflicts support */
9997 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9998 +{
9999 + register int i;
10000 + compound_depend_t * conflicts;
10001 +
10002 + if (!pkg->conflicts_count)
10003 + return 0;
10004 +
10005 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10006 + pkg->conflicts_count);
10007 + if (conflicts == NULL) {
10008 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10009 + return -1;
10010 + }
10011 + for (i = 0; i < pkg->conflicts_count; i++) {
10012 + conflicts->type = CONFLICTS;
10013 + parseDepends(conflicts, hash,
10014 + pkg->conflicts_str[i]);
10015 +#if 0
10016 + for (j = 0; j < conflicts->possibility_count; j++) {
10017 + depend_t *possibility = conflicts->possibilities[j];
10018 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10019 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10020 + }
10021 +#endif
10022 + conflicts++;
10023 + }
10024 + return 0;
10025 +}
10026 +
10027 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10028 +{
10029 + register int i, j;
10030 +
10031 + if (!pkg->replaces_count)
10032 + return 0;
10033 +
10034 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10035 + if (pkg->replaces == NULL) {
10036 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10037 + return -1;
10038 + }
10039 +
10040 + // if (strcmp(ab_pkg->name, pkg->name))
10041 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10042 +
10043 + for(i = 0; i < pkg->replaces_count; i++){
10044 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10045 +
10046 + pkg->replaces[i] = old_abpkg;
10047 +
10048 + j = 0;
10049 + if (!old_abpkg->replaced_by)
10050 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10051 + if ( old_abpkg->replaced_by == NULL ){
10052 + return -1;
10053 + }
10054 + /* if a package pkg both replaces and conflicts old_abpkg,
10055 + * then add it to the replaced_by vector so that old_abpkg
10056 + * will be upgraded to ab_pkg automatically */
10057 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10058 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10059 + }
10060 + return 0;
10061 +}
10062 +
10063 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10064 +{
10065 + int count;
10066 + register int i;
10067 + compound_depend_t * depends;
10068 +
10069 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10070 + return 0;
10071 +
10072 + if (0 && pkg->pre_depends_count)
10073 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10074 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10075 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10076 + if (depends == NULL) {
10077 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10078 + return -1;
10079 + }
10080 +
10081 +
10082 + for(i = 0; i < pkg->pre_depends_count; i++){
10083 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10084 + if (0 && pkg->pre_depends_count)
10085 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10086 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10087 + depends->type = PREDEPEND;
10088 + depends++;
10089 + }
10090 +
10091 + for(i = 0; i < pkg->recommends_count; i++){
10092 + parseDepends(depends, hash, pkg->recommends_str[i]);
10093 + if (0 && pkg->recommends_count)
10094 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10095 + pkg->recommends_str[i], depends, depends->possibility_count);
10096 + depends->type = RECOMMEND;
10097 + depends++;
10098 + }
10099 +
10100 + for(i = 0; i < pkg->suggests_count; i++){
10101 + parseDepends(depends, hash, pkg->suggests_str[i]);
10102 + if (0 && pkg->suggests_count)
10103 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10104 + pkg->suggests_str[i], depends, depends->possibility_count);
10105 + depends->type = SUGGEST;
10106 + depends++;
10107 + }
10108 +
10109 + for(i = 0; i < pkg->depends_count; i++){
10110 + parseDepends(depends, hash, pkg->depends_str[i]);
10111 + if (0 && pkg->depends_count)
10112 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10113 + pkg->depends_str[i], depends, depends->possibility_count);
10114 + depends++;
10115 + }
10116 + return 0;
10117 +}
10118 +
10119 +/*
10120 + * pkg_depend_string: returns the depends string specified by index.
10121 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10122 + * [0,npredepends) -> returns pre_depends_str[index]
10123 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10124 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10125 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10126 + */
10127 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10128 +{
10129 + if (pkg_index < pkg->pre_depends_count) {
10130 + return pkg->pre_depends_str[pkg_index];
10131 + }
10132 + pkg_index -= pkg->pre_depends_count;
10133 +
10134 + if (pkg_index < pkg->recommends_count) {
10135 + return pkg->recommends_str[pkg_index];
10136 + }
10137 + pkg_index -= pkg->recommends_count;
10138 +
10139 + if (pkg_index < pkg->suggests_count) {
10140 + return pkg->suggests_str[pkg_index];
10141 + }
10142 + pkg_index -= pkg->suggests_count;
10143 +
10144 + if (pkg_index < pkg->depends_count) {
10145 + return pkg->depends_str[pkg_index];
10146 + }
10147 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10148 + return NULL;
10149 +}
10150 +
10151 +void freeDepends(pkg_t *pkg)
10152 +{
10153 + int i;
10154 +
10155 + if (pkg == NULL || pkg->depends == NULL) {
10156 + return;
10157 + }
10158 +
10159 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10160 + for (i=0; i < pkg->depends->possibility_count; i++) {
10161 + depend_deinit(pkg->depends->possibilities[i]);
10162 + }
10163 + free(pkg->depends->possibilities);
10164 + free(pkg->depends);
10165 + pkg->depends = NULL;
10166 +}
10167 +
10168 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10169 +{
10170 + compound_depend_t * depends;
10171 + int count, othercount;
10172 + register int i, j;
10173 + abstract_pkg_t * ab_depend;
10174 + abstract_pkg_t ** temp;
10175 +
10176 + count = pkg->pre_depends_count + pkg->depends_count;
10177 + depends = pkg->depends;
10178 +
10179 + if (0 && pkg->pre_depends_count)
10180 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10181 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10182 + for (i = 0; i < count; i++) {
10183 + if (0 && pkg->pre_depends_count)
10184 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10185 + for (j = 0; j < depends->possibility_count; j++){
10186 + ab_depend = depends->possibilities[j]->pkg;
10187 + if(!ab_depend->depended_upon_by)
10188 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10189 +
10190 + temp = ab_depend->depended_upon_by;
10191 + othercount = 1;
10192 + while(*temp){
10193 + temp++;
10194 + othercount++;
10195 + }
10196 + *temp = ab_pkg;
10197 +
10198 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10199 + (othercount + 1) * sizeof(abstract_pkg_t *));
10200 + /* the array may have moved */
10201 + temp = ab_depend->depended_upon_by + othercount;
10202 + *temp = NULL;
10203 + }
10204 + depends++;
10205 + }
10206 +}
10207 +
10208 +static depend_t * depend_init(void)
10209 +{
10210 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10211 + if ( d==NULL ){
10212 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10213 + return NULL;
10214 + }
10215 + d->constraint = NONE;
10216 + d->version = NULL;
10217 + d->pkg = NULL;
10218 +
10219 + return d;
10220 +}
10221 +
10222 +static void depend_deinit(depend_t *d)
10223 +{
10224 + free(d);
10225 +}
10226 +
10227 +static int parseDepends(compound_depend_t *compound_depend,
10228 + hash_table_t * hash, char * depend_str)
10229 +{
10230 + char * pkg_name, buffer[2048];
10231 + int num_of_ors = 0;
10232 + register int i;
10233 + register char * src, * dest;
10234 + depend_t ** possibilities;
10235 +
10236 + /* first count the number of ored possibilities for satisfying dependency */
10237 + src = depend_str;
10238 + while(*src)
10239 + if(*src++ == '|')
10240 + num_of_ors++;
10241 +
10242 + compound_depend->type = DEPEND;
10243 +
10244 + compound_depend->possibility_count = num_of_ors + 1;
10245 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10246 + if (!possibilities)
10247 + return -ENOMEM;
10248 + compound_depend->possibilities = possibilities;
10249 +
10250 + src = depend_str;
10251 + for(i = 0; i < num_of_ors + 1; i++){
10252 + possibilities[i] = depend_init();
10253 + if (!possibilities[i])
10254 + return -ENOMEM;
10255 + /* gobble up just the name first */
10256 + dest = buffer;
10257 + while(*src &&
10258 + !isspace(*src) &&
10259 + (*src != '(') &&
10260 + (*src != '*') &&
10261 + (*src != '|'))
10262 + *dest++ = *src++;
10263 + *dest = '\0';
10264 + pkg_name = trim_alloc(buffer);
10265 + if (pkg_name == NULL )
10266 + return -ENOMEM;
10267 +
10268 + /* now look at possible version info */
10269 +
10270 + /* skip to next chars */
10271 + if(isspace(*src))
10272 + while(*src && isspace(*src)) src++;
10273 +
10274 + /* extract constraint and version */
10275 + if(*src == '('){
10276 + src++;
10277 + if(!strncmp(src, "<<", 2)){
10278 + possibilities[i]->constraint = EARLIER;
10279 + src += 2;
10280 + }
10281 + else if(!strncmp(src, "<=", 2)){
10282 + possibilities[i]->constraint = EARLIER_EQUAL;
10283 + src += 2;
10284 + }
10285 + else if(!strncmp(src, ">=", 2)){
10286 + possibilities[i]->constraint = LATER_EQUAL;
10287 + src += 2;
10288 + }
10289 + else if(!strncmp(src, ">>", 2)){
10290 + possibilities[i]->constraint = LATER;
10291 + src += 2;
10292 + }
10293 + else if(!strncmp(src, "=", 1)){
10294 + possibilities[i]->constraint = EQUAL;
10295 + src++;
10296 + }
10297 + /* should these be here to support deprecated designations; dpkg does */
10298 + else if(!strncmp(src, "<", 1)){
10299 + possibilities[i]->constraint = EARLIER_EQUAL;
10300 + src++;
10301 + }
10302 + else if(!strncmp(src, ">", 1)){
10303 + possibilities[i]->constraint = LATER_EQUAL;
10304 + src++;
10305 + }
10306 +
10307 + /* now we have any constraint, pass space to version string */
10308 + while(isspace(*src)) src++;
10309 +
10310 + /* this would be the version string */
10311 + dest = buffer;
10312 + while(*src && *src != ')')
10313 + *dest++ = *src++;
10314 + *dest = '\0';
10315 +
10316 + possibilities[i]->version = trim_alloc(buffer);
10317 + /* fprintf(stderr, "let's print the depends version string:");
10318 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10319 + if (possibilities[i]->version == NULL )
10320 + return -ENOMEM;
10321 +
10322 +
10323 + }
10324 + /* hook up the dependency to its abstract pkg */
10325 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10326 +
10327 + free(pkg_name);
10328 +
10329 + /* now get past the ) and any possible | chars */
10330 + while(*src &&
10331 + (isspace(*src) ||
10332 + (*src == ')') ||
10333 + (*src == '|')))
10334 + src++;
10335 + if (*src == '*')
10336 + {
10337 + compound_depend->type = GREEDY_DEPEND;
10338 + src++;
10339 + }
10340 + }
10341 +
10342 + return 0;
10343 +}
10344 Index: busybox-1.4.2/archival/libipkg/pkg_depends.h
10345 ===================================================================
10346 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10347 +++ busybox-1.4.2/archival/libipkg/pkg_depends.h 2007-06-04 13:21:36.724393712 +0200
10348 @@ -0,0 +1,105 @@
10349 +/* pkg_depends.h - the itsy package management system
10350 +
10351 + Steven M. Ayer
10352 +
10353 + Copyright (C) 2002 Compaq Computer Corporation
10354 +
10355 + This program is free software; you can redistribute it and/or
10356 + modify it under the terms of the GNU General Public License as
10357 + published by the Free Software Foundation; either version 2, or (at
10358 + your option) any later version.
10359 +
10360 + This program is distributed in the hope that it will be useful, but
10361 + WITHOUT ANY WARRANTY; without even the implied warranty of
10362 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10363 + General Public License for more details.
10364 +*/
10365 +
10366 +#ifndef PKG_DEPENDS_H
10367 +#define PKG_DEPENDS_H
10368 +
10369 +#include "pkg.h"
10370 +#include "pkg_hash.h"
10371 +
10372 +enum depend_type {
10373 + PREDEPEND,
10374 + DEPEND,
10375 + CONFLICTS,
10376 + GREEDY_DEPEND,
10377 + RECOMMEND,
10378 + SUGGEST
10379 +};
10380 +typedef enum depend_type depend_type_t;
10381 +
10382 +enum version_constraint {
10383 + NONE,
10384 + EARLIER,
10385 + EARLIER_EQUAL,
10386 + EQUAL,
10387 + LATER_EQUAL,
10388 + LATER
10389 +};
10390 +typedef enum version_constraint version_constraint_t;
10391 +
10392 +struct depend{
10393 + version_constraint_t constraint;
10394 + char * version;
10395 + abstract_pkg_t * pkg;
10396 +};
10397 +typedef struct depend depend_t;
10398 +
10399 +struct compound_depend{
10400 + depend_type_t type;
10401 + int possibility_count;
10402 + struct depend ** possibilities;
10403 +};
10404 +typedef struct compound_depend compound_depend_t;
10405 +
10406 +#include "hash_table.h"
10407 +
10408 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10409 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10410 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10411 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10412 +
10413 +/**
10414 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10415 + * the same abstract package and 0 otherwise.
10416 + */
10417 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10418 +
10419 +/**
10420 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10421 + * otherwise.
10422 + */
10423 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10424 +
10425 +/**
10426 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10427 + * otherwise.
10428 + */
10429 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10430 +
10431 +/**
10432 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10433 + * otherwise.
10434 + */
10435 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10436 +
10437 +/**
10438 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10439 + * otherwise.
10440 + */
10441 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10442 +
10443 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10444 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10445 +void freeDepends(pkg_t *pkg);
10446 +void printDepends(pkg_t * pkg);
10447 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10448 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10449 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10450 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10451 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10452 +
10453 +#endif
10454 Index: busybox-1.4.2/archival/libipkg/pkg_dest.c
10455 ===================================================================
10456 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10457 +++ busybox-1.4.2/archival/libipkg/pkg_dest.c 2007-06-04 13:21:36.725393560 +0200
10458 @@ -0,0 +1,92 @@
10459 +/* pkg_dest.c - the itsy package management system
10460 +
10461 + Carl D. Worth
10462 +
10463 + Copyright (C) 2001 University of Southern California
10464 +
10465 + This program is free software; you can redistribute it and/or
10466 + modify it under the terms of the GNU General Public License as
10467 + published by the Free Software Foundation; either version 2, or (at
10468 + your option) any later version.
10469 +
10470 + This program is distributed in the hope that it will be useful, but
10471 + WITHOUT ANY WARRANTY; without even the implied warranty of
10472 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10473 + General Public License for more details.
10474 +*/
10475 +
10476 +#include "ipkg.h"
10477 +
10478 +#include "pkg_dest.h"
10479 +#include "file_util.h"
10480 +#include "str_util.h"
10481 +#include "sprintf_alloc.h"
10482 +
10483 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10484 +{
10485 + dest->name = strdup(name);
10486 +
10487 + /* Guarantee that dest->root_dir ends with a '/' */
10488 + if (str_ends_with(root_dir, "/")) {
10489 + dest->root_dir = strdup(root_dir);
10490 + } else {
10491 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10492 + }
10493 + file_mkdir_hier(dest->root_dir, 0755);
10494 +
10495 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10496 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10497 + file_mkdir_hier(dest->ipkg_dir, 0755);
10498 +
10499 + if (str_starts_with (lists_dir, "/"))
10500 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10501 + else
10502 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10503 +
10504 + file_mkdir_hier(dest->lists_dir, 0755);
10505 +
10506 + sprintf_alloc(&dest->info_dir, "%s/%s",
10507 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10508 + file_mkdir_hier(dest->info_dir, 0755);
10509 +
10510 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10511 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10512 +
10513 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10514 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10515 +
10516 + dest->status_file = NULL;
10517 +
10518 + return 0;
10519 +}
10520 +
10521 +void pkg_dest_deinit(pkg_dest_t *dest)
10522 +{
10523 + free(dest->name);
10524 + dest->name = NULL;
10525 +
10526 + free(dest->root_dir);
10527 + dest->root_dir = NULL;
10528 +
10529 + free(dest->ipkg_dir);
10530 + dest->ipkg_dir = NULL;
10531 +
10532 + free(dest->lists_dir);
10533 + dest->lists_dir = NULL;
10534 +
10535 + free(dest->info_dir);
10536 + dest->info_dir = NULL;
10537 +
10538 + free(dest->status_file_name);
10539 + dest->status_file_name = NULL;
10540 +
10541 + free(dest->status_file_tmp_name);
10542 + dest->status_file_tmp_name = NULL;
10543 +
10544 + if (dest->status_file) {
10545 + fclose(dest->status_file);
10546 + }
10547 + dest->status_file = NULL;
10548 +
10549 + dest->root_dir = NULL;
10550 +}
10551 Index: busybox-1.4.2/archival/libipkg/pkg_dest.h
10552 ===================================================================
10553 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10554 +++ busybox-1.4.2/archival/libipkg/pkg_dest.h 2007-06-04 13:21:36.725393560 +0200
10555 @@ -0,0 +1,38 @@
10556 +/* pkg_dest.h - the itsy package management system
10557 +
10558 + Carl D. Worth
10559 +
10560 + Copyright (C) 2001 University of Southern California
10561 +
10562 + This program is free software; you can redistribute it and/or
10563 + modify it under the terms of the GNU General Public License as
10564 + published by the Free Software Foundation; either version 2, or (at
10565 + your option) any later version.
10566 +
10567 + This program is distributed in the hope that it will be useful, but
10568 + WITHOUT ANY WARRANTY; without even the implied warranty of
10569 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10570 + General Public License for more details.
10571 +*/
10572 +
10573 +#ifndef PKG_DEST_H
10574 +#define PKG_DEST_H
10575 +
10576 +typedef struct pkg_dest pkg_dest_t;
10577 +struct pkg_dest
10578 +{
10579 + char *name;
10580 + char *root_dir;
10581 + char *ipkg_dir;
10582 + char *lists_dir;
10583 + char *info_dir;
10584 + char *status_file_name;
10585 + char *status_file_tmp_name;
10586 + FILE *status_file;
10587 +};
10588 +
10589 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10590 +void pkg_dest_deinit(pkg_dest_t *dest);
10591 +
10592 +#endif
10593 +
10594 Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.c
10595 ===================================================================
10596 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10597 +++ busybox-1.4.2/archival/libipkg/pkg_dest_list.c 2007-06-04 13:21:36.725393560 +0200
10598 @@ -0,0 +1,85 @@
10599 +/* pkg_dest_list.c - the itsy package management system
10600 +
10601 + Carl D. Worth
10602 +
10603 + Copyright (C) 2001 University of Southern California
10604 +
10605 + This program is free software; you can redistribute it and/or
10606 + modify it under the terms of the GNU General Public License as
10607 + published by the Free Software Foundation; either version 2, or (at
10608 + your option) any later version.
10609 +
10610 + This program is distributed in the hope that it will be useful, but
10611 + WITHOUT ANY WARRANTY; without even the implied warranty of
10612 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10613 + General Public License for more details.
10614 +*/
10615 +
10616 +#include "ipkg.h"
10617 +
10618 +#include "pkg_dest.h"
10619 +#include "void_list.h"
10620 +#include "pkg_dest_list.h"
10621 +
10622 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10623 +{
10624 + return void_list_elt_init((void_list_elt_t *) elt, data);
10625 +}
10626 +
10627 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10628 +{
10629 + void_list_elt_deinit((void_list_elt_t *) elt);
10630 +}
10631 +
10632 +int pkg_dest_list_init(pkg_dest_list_t *list)
10633 +{
10634 + return void_list_init((void_list_t *) list);
10635 +}
10636 +
10637 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10638 +{
10639 + pkg_dest_list_elt_t *iter;
10640 + pkg_dest_t *pkg_dest;
10641 +
10642 + for (iter = list->head; iter; iter = iter->next) {
10643 + pkg_dest = iter->data;
10644 + pkg_dest_deinit(pkg_dest);
10645 +
10646 + /* malloced in pkg_dest_list_append */
10647 + free(pkg_dest);
10648 + iter->data = NULL;
10649 + }
10650 + void_list_deinit((void_list_t *) list);
10651 +}
10652 +
10653 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10654 + const char *root_dir,const char *lists_dir)
10655 +{
10656 + int err;
10657 + pkg_dest_t *pkg_dest;
10658 +
10659 + /* freed in plg_dest_list_deinit */
10660 + pkg_dest = malloc(sizeof(pkg_dest_t));
10661 + if (pkg_dest == NULL) {
10662 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10663 + return NULL;
10664 + }
10665 +
10666 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10667 + err = void_list_append((void_list_t *) list, pkg_dest);
10668 + if (err) {
10669 + return NULL;
10670 + }
10671 +
10672 + return pkg_dest;
10673 +}
10674 +
10675 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10676 +{
10677 + return void_list_push((void_list_t *) list, data);
10678 +}
10679 +
10680 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10681 +{
10682 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10683 +}
10684 Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.h
10685 ===================================================================
10686 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10687 +++ busybox-1.4.2/archival/libipkg/pkg_dest_list.h 2007-06-04 13:21:36.725393560 +0200
10688 @@ -0,0 +1,50 @@
10689 +/* pkg_dest_list.h - the itsy package management system
10690 +
10691 + Carl D. Worth
10692 +
10693 + Copyright (C) 2001 University of Southern California
10694 +
10695 + This program is free software; you can redistribute it and/or
10696 + modify it under the terms of the GNU General Public License as
10697 + published by the Free Software Foundation; either version 2, or (at
10698 + your option) any later version.
10699 +
10700 + This program is distributed in the hope that it will be useful, but
10701 + WITHOUT ANY WARRANTY; without even the implied warranty of
10702 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10703 + General Public License for more details.
10704 +*/
10705 +
10706 +#ifndef PKG_DEST_LIST_H
10707 +#define PKG_DEST_LIST_H
10708 +
10709 +#include "pkg_dest.h"
10710 +
10711 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10712 +struct pkg_dest_list_elt
10713 +{
10714 + pkg_dest_list_elt_t *next;
10715 + pkg_dest_t *data;
10716 +};
10717 +
10718 +typedef struct pkg_dest_list pkg_dest_list_t;
10719 +struct pkg_dest_list
10720 +{
10721 + pkg_dest_list_elt_t pre_head;
10722 + pkg_dest_list_elt_t *head;
10723 + pkg_dest_list_elt_t *tail;
10724 +};
10725 +
10726 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10727 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10728 +
10729 +int pkg_dest_list_init(pkg_dest_list_t *list);
10730 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10731 +
10732 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10733 + const char *root_dir,const char* lists_dir);
10734 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10735 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10736 +
10737 +#endif
10738 +
10739 Index: busybox-1.4.2/archival/libipkg/pkg_extract.c
10740 ===================================================================
10741 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10742 +++ busybox-1.4.2/archival/libipkg/pkg_extract.c 2007-06-04 13:21:36.726393408 +0200
10743 @@ -0,0 +1,224 @@
10744 +/* pkg_extract.c - the itsy package management system
10745 +
10746 + Carl D. Worth
10747 +
10748 + Copyright (C) 2001 University of Southern California
10749 +
10750 + This program is free software; you can redistribute it and/or
10751 + modify it under the terms of the GNU General Public License as
10752 + published by the Free Software Foundation; either version 2, or (at
10753 + your option) any later version.
10754 +
10755 + This program is distributed in the hope that it will be useful, but
10756 + WITHOUT ANY WARRANTY; without even the implied warranty of
10757 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10758 + General Public License for more details.
10759 +*/
10760 +
10761 +#include "ipkg.h"
10762 +#include <errno.h>
10763 +#include <fcntl.h>
10764 +#include <stdio.h>
10765 +
10766 +#include "pkg_extract.h"
10767 +
10768 +#include "libbb.h"
10769 +#include "file_util.h"
10770 +#include "sprintf_alloc.h"
10771 +#include "unarchive.h"
10772 +
10773 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10774 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10775 +#define IPKG_CONTROL_FILE "control"
10776 +
10777 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10778 +{
10779 + archive_handle_t *archive;
10780 + char *path;
10781 +
10782 + sprintf_alloc(&path, "%s/", dir);
10783 + archive = init_handle();
10784 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10785 + archive->filter = filter_accept_list;
10786 + llist_add_to(&(archive->accept), (char *)filename);
10787 + archive->buffer = path;
10788 + archive->action_data = data_extract_all_prefix;
10789 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10790 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10791 + close(archive->src_fd);
10792 + free(archive->accept);
10793 + free(archive);
10794 + free(path);
10795 +}
10796 +
10797 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10798 +{
10799 + unsigned int size = strlen(archive->file_header->name) + 2;
10800 +
10801 + if (archive->buffer == NULL) {
10802 + archive->buffer = xmalloc(size);
10803 + strcpy(archive->buffer, archive->file_header->name);
10804 + } else {
10805 + size += strlen(archive->buffer);
10806 + archive->buffer = xrealloc(archive->buffer, size);
10807 + strcat(archive->buffer, archive->file_header->name);
10808 + }
10809 + strcat(archive->buffer, "\n");
10810 + data_skip(archive);
10811 +}
10812 +
10813 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10814 +{
10815 + archive_handle_t *archive;
10816 + char *name;
10817 +
10818 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10819 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10820 + archive = init_handle();
10821 + archive->src_fd = xopen(name, O_RDONLY);
10822 + archive->filter = filter_accept_list;
10823 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10824 + archive->action_data = data_extract_to_buffer;
10825 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10826 + close(archive->src_fd);
10827 + fputs(archive->buffer, stream);
10828 + free(archive->buffer);
10829 + free(archive->accept);
10830 + free(archive);
10831 + free(name);
10832 +
10833 + return 0;
10834 +}
10835 +
10836 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10837 +{
10838 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10839 +}
10840 +
10841 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10842 +{
10843 + archive_handle_t *archive;
10844 + char *name;
10845 + char *path;
10846 +
10847 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10848 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10849 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10850 + archive = init_handle();
10851 + archive->src_fd = xopen(name, O_RDONLY);
10852 + archive->filter = filter_accept_all;
10853 + archive->buffer = path;
10854 + archive->action_data = data_extract_all_prefix;
10855 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10856 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10857 + close(archive->src_fd);
10858 + free(archive);
10859 + free(path);
10860 + free(name);
10861 +
10862 + return 0;
10863 +}
10864 +
10865 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10866 +{
10867 + archive_handle_t *archive;
10868 + char *name;
10869 + char *path;
10870 +
10871 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10872 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10873 + sprintf_alloc(&path, "%s/", dir);
10874 + archive = init_handle();
10875 + archive->src_fd = xopen(name, O_RDONLY);
10876 + archive->filter = filter_accept_all;
10877 + archive->buffer = path;
10878 + archive->action_data = data_extract_all_prefix;
10879 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10880 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10881 + close(archive->src_fd);
10882 + free(archive);
10883 + free(path);
10884 + free(name);
10885 +
10886 + return 0;
10887 +}
10888 +
10889 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10890 +{
10891 + int err=0;
10892 + char *line, *data_file;
10893 + FILE *file;
10894 + FILE *tmp;
10895 +
10896 + file = fopen(file_name, "w");
10897 + if (file == NULL) {
10898 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10899 + __FUNCTION__, file_name);
10900 + return EINVAL;
10901 + }
10902 +
10903 + tmp = tmpfile();
10904 + if (pkg->installed_files) {
10905 + str_list_elt_t *elt;
10906 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10907 + fprintf(file, "%s\n", elt->data);
10908 + }
10909 + } else {
10910 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10911 + if (err) {
10912 + fclose(file);
10913 + fclose(tmp);
10914 + return err;
10915 + }
10916 +
10917 + /* Fixup data file names by removing the initial '.' */
10918 + rewind(tmp);
10919 + while (1) {
10920 + line = file_read_line_alloc(tmp);
10921 + if (line == NULL) {
10922 + break;
10923 + }
10924 +
10925 + data_file = line;
10926 + if (*data_file == '.') {
10927 + data_file++;
10928 + }
10929 +
10930 + if (*data_file != '/') {
10931 + fputs("/", file);
10932 + }
10933 +
10934 + /* I have no idea why, but this is what dpkg does */
10935 + if (strcmp(data_file, "/\n") == 0) {
10936 + fputs("/.\n", file);
10937 + } else {
10938 + fputs(data_file, file);
10939 + }
10940 + }
10941 + }
10942 + fclose(tmp);
10943 + fclose(file);
10944 +
10945 + return err;
10946 +}
10947 +
10948 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10949 +{
10950 + archive_handle_t *archive;
10951 + char *name;
10952 +
10953 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10954 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10955 + archive = init_handle();
10956 + archive->src_fd = xopen(name, O_RDONLY);
10957 + archive->filter = filter_accept_all;
10958 + archive->action_data = data_extract_file_name_to_buffer;
10959 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10960 + close(archive->src_fd);
10961 + fputs(archive->buffer, file);
10962 + free(archive->buffer);
10963 + free(archive);
10964 + free(name);
10965 +
10966 + return 0;
10967 +}
10968 Index: busybox-1.4.2/archival/libipkg/pkg_extract.h
10969 ===================================================================
10970 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10971 +++ busybox-1.4.2/archival/libipkg/pkg_extract.h 2007-06-04 13:21:36.726393408 +0200
10972 @@ -0,0 +1,32 @@
10973 +/* pkg_extract.c - the itsy package management system
10974 +
10975 + Carl D. Worth
10976 +
10977 + Copyright (C) 2001 University of Southern California
10978 +
10979 + This program is free software; you can redistribute it and/or
10980 + modify it under the terms of the GNU General Public License as
10981 + published by the Free Software Foundation; either version 2, or (at
10982 + your option) any later version.
10983 +
10984 + This program is distributed in the hope that it will be useful, but
10985 + WITHOUT ANY WARRANTY; without even the implied warranty of
10986 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10987 + General Public License for more details.
10988 +*/
10989 +
10990 +#ifndef PKG_EXTRACT_H
10991 +#define PKG_EXTRACT_H
10992 +
10993 +#include "pkg.h"
10994 +
10995 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10996 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10997 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
10998 + const char *dir,
10999 + const char *prefix);
11000 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11001 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11002 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11003 +
11004 +#endif
11005 Index: busybox-1.4.2/archival/libipkg/pkg.h
11006 ===================================================================
11007 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11008 +++ busybox-1.4.2/archival/libipkg/pkg.h 2007-06-04 13:21:36.726393408 +0200
11009 @@ -0,0 +1,232 @@
11010 +/* pkg.h - the itsy package management system
11011 +
11012 + Carl D. Worth
11013 +
11014 + Copyright (C) 2001 University of Southern California
11015 +
11016 + This program is free software; you can redistribute it and/or
11017 + modify it under the terms of the GNU General Public License as
11018 + published by the Free Software Foundation; either version 2, or (at
11019 + your option) any later version.
11020 +
11021 + This program is distributed in the hope that it will be useful, but
11022 + WITHOUT ANY WARRANTY; without even the implied warranty of
11023 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11024 + General Public License for more details.
11025 +*/
11026 +
11027 +#ifndef PKG_H
11028 +#define PKG_H
11029 +
11030 +#include <sys/types.h>
11031 +#include <sys/stat.h>
11032 +#include <unistd.h>
11033 +
11034 +#include "pkg_vec.h"
11035 +#include "str_list.h"
11036 +#include "pkg_src.h"
11037 +#include "pkg_dest.h"
11038 +#include "ipkg_conf.h"
11039 +#include "conffile_list.h"
11040 +
11041 +struct ipkg_conf;
11042 +
11043 +
11044 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11045 +
11046 +/* I think "Size" is currently the shortest field name */
11047 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11048 +
11049 +enum pkg_state_want
11050 +{
11051 + SW_UNKNOWN = 1,
11052 + SW_INSTALL,
11053 + SW_DEINSTALL,
11054 + SW_PURGE,
11055 + SW_LAST_STATE_WANT
11056 +};
11057 +typedef enum pkg_state_want pkg_state_want_t;
11058 +
11059 +enum pkg_state_flag
11060 +{
11061 + SF_OK = 0,
11062 + SF_REINSTREQ = 1,
11063 + SF_HOLD = 2, /* do not upgrade version */
11064 + SF_REPLACE = 4, /* replace this package */
11065 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11066 + SF_PREFER = 16, /* prefer this version */
11067 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11068 + SF_MARKED = 64, /* temporary mark */
11069 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11070 + SF_USER = 256,
11071 + SF_LAST_STATE_FLAG
11072 +};
11073 +typedef enum pkg_state_flag pkg_state_flag_t;
11074 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11075 +
11076 +enum pkg_state_status
11077 +{
11078 + SS_NOT_INSTALLED = 1,
11079 + SS_UNPACKED,
11080 + SS_HALF_CONFIGURED,
11081 + SS_INSTALLED,
11082 + SS_HALF_INSTALLED,
11083 + SS_CONFIG_FILES,
11084 + SS_POST_INST_FAILED,
11085 + SS_REMOVAL_FAILED,
11086 + SS_LAST_STATE_STATUS
11087 +};
11088 +typedef enum pkg_state_status pkg_state_status_t;
11089 +
11090 +struct abstract_pkg{
11091 + char * name;
11092 + int dependencies_checked;
11093 + pkg_vec_t * pkgs;
11094 + pkg_state_status_t state_status;
11095 + pkg_state_flag_t state_flag;
11096 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11097 + abstract_pkg_vec_t * provided_by;
11098 + abstract_pkg_vec_t * replaced_by;
11099 +};
11100 +
11101 +#include "pkg_depends.h"
11102 +
11103 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11104 +
11105 + The 3 version fields should go into a single version struct. (This
11106 + is especially important since, currently, pkg->version can easily
11107 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11108 + distinct. This has been the source of multiple bugs.
11109 +
11110 + The 3 state fields could possibly also go into their own struct.
11111 +
11112 + All fields which deal with lists of packages, (Depends,
11113 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11114 + be handled by a single struct in pkg_t
11115 +
11116 + All string fields for which there is a small set of possible
11117 + values, (section, maintainer, architecture, maybe version?), that
11118 + are reused among different packages -- for all such packages we
11119 + should move from "char *"s to some atom datatype to share data
11120 + storage and use less memory. We might even do reference counting,
11121 + but probably not since most often we only create new pkg_t structs,
11122 + we don't often free them. */
11123 +struct pkg
11124 +{
11125 + char *name;
11126 + unsigned long epoch;
11127 + char *version;
11128 + char *revision;
11129 + char *familiar_revision;
11130 + pkg_src_t *src;
11131 + pkg_dest_t *dest;
11132 + char *architecture;
11133 + char *section;
11134 + char *maintainer;
11135 + char *description;
11136 + pkg_state_want_t state_want;
11137 + pkg_state_flag_t state_flag;
11138 + pkg_state_status_t state_status;
11139 + char **depends_str;
11140 + int depends_count;
11141 + char **pre_depends_str;
11142 + int pre_depends_count;
11143 + char **recommends_str;
11144 + int recommends_count;
11145 + char **suggests_str;
11146 + int suggests_count;
11147 + compound_depend_t * depends;
11148 +
11149 + /* Abhaya: new conflicts */
11150 + char **conflicts_str;
11151 + compound_depend_t * conflicts;
11152 + int conflicts_count;
11153 +
11154 + char **replaces_str;
11155 + int replaces_count;
11156 + abstract_pkg_t ** replaces;
11157 +
11158 + char **provides_str;
11159 + int provides_count;
11160 + abstract_pkg_t ** provides;
11161 +
11162 + abstract_pkg_t *parent;
11163 +
11164 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11165 +
11166 + char *filename;
11167 + char *local_filename;
11168 + char *url;
11169 + char *tmp_unpack_dir;
11170 + char *md5sum;
11171 + char *size;
11172 + char *installed_size;
11173 + char *priority;
11174 + char *source;
11175 + conffile_list_t conffiles;
11176 + time_t installed_time;
11177 + /* As pointer for lazy evaluation */
11178 + str_list_t *installed_files;
11179 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11180 + mechanism to avoid the problem here, (which is that the
11181 + installed_files list was being freed from an inner loop while
11182 + still being used within an outer loop. */
11183 + int installed_files_ref_cnt;
11184 + int essential;
11185 + int arch_priority;
11186 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11187 + int provided_by_hand;
11188 +};
11189 +
11190 +pkg_t *pkg_new(void);
11191 +int pkg_init(pkg_t *pkg);
11192 +void pkg_deinit(pkg_t *pkg);
11193 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11194 +abstract_pkg_t *abstract_pkg_new(void);
11195 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11196 +
11197 +/*
11198 + * merges fields from newpkg into oldpkg.
11199 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11200 + */
11201 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11202 +
11203 +char *pkg_version_str_alloc(pkg_t *pkg);
11204 +
11205 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11206 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11207 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11208 +
11209 +char * pkg_formatted_info(pkg_t *pkg );
11210 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11211 +
11212 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11213 +
11214 +void pkg_print_info(pkg_t *pkg, FILE *file);
11215 +void pkg_print_status(pkg_t * pkg, FILE * file);
11216 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11217 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11218 +int pkg_free_installed_files(pkg_t *pkg);
11219 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11220 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11221 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11222 + const char *script, const char *args);
11223 +
11224 +/* enum mappings */
11225 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11226 +pkg_state_want_t pkg_state_want_from_str(char *str);
11227 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11228 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11229 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11230 +pkg_state_status_t pkg_state_status_from_str(char *str);
11231 +
11232 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11233 +
11234 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11235 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11236 +int pkg_free_installed_files(pkg_t *pkg);
11237 +
11238 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11239 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11240 +
11241 +#endif
11242 Index: busybox-1.4.2/archival/libipkg/pkg_hash.c
11243 ===================================================================
11244 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11245 +++ busybox-1.4.2/archival/libipkg/pkg_hash.c 2007-06-04 13:21:36.727393256 +0200
11246 @@ -0,0 +1,616 @@
11247 +/* ipkg_hash.c - the itsy package management system
11248 +
11249 + Steven M. Ayer
11250 +
11251 + Copyright (C) 2002 Compaq Computer Corporation
11252 +
11253 + This program is free software; you can redistribute it and/or
11254 + modify it under the terms of the GNU General Public License as
11255 + published by the Free Software Foundation; either version 2, or (at
11256 + your option) any later version.
11257 +
11258 + This program is distributed in the hope that it will be useful, but
11259 + WITHOUT ANY WARRANTY; without even the implied warranty of
11260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11261 + General Public License for more details.
11262 +*/
11263 +
11264 +#include "ipkg.h"
11265 +#include <errno.h>
11266 +#include <ctype.h>
11267 +#include <stdlib.h>
11268 +#include <string.h>
11269 +
11270 +#include "hash_table.h"
11271 +#include "pkg.h"
11272 +#include "ipkg_message.h"
11273 +#include "pkg_vec.h"
11274 +#include "pkg_hash.h"
11275 +#include "pkg_parse.h"
11276 +#include "ipkg_utils.h"
11277 +
11278 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11279 +
11280 +/*
11281 + * this will talk to both feeds-lists files and installed status files
11282 + * example api:
11283 + *
11284 + * hash_table_t hash;
11285 + * pkg_hash_init(name, &hash, 1000);
11286 + * pkg_hash_add_from_file(<feed filename>);
11287 + *
11288 + * the query function is just there as a shell to prove to me that this
11289 + * sort of works, but isn't far from doing something useful
11290 + *
11291 + * -sma, 12/21/01
11292 + * modified: CDW 3 Jan. 2002
11293 + */
11294 +
11295 +
11296 +\f
11297 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11298 +{
11299 + return hash_table_init(name, hash, len);
11300 +}
11301 +
11302 +void pkg_hash_deinit(hash_table_t *hash)
11303 +{
11304 + hash_table_deinit(hash);
11305 +}
11306 +
11307 +
11308 +/* Find the default arch for a given package status file if none is given. */
11309 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11310 +{
11311 + nv_pair_list_elt_t *l;
11312 + char *def_arch = HOST_CPU_STR; /* Default arch */
11313 + int def_prio = 0; /* Other archs override this */
11314 +
11315 + l = conf->arch_list.head;
11316 +
11317 + while (l) {
11318 + nv_pair_t *nv = l->data;
11319 + int priority = strtol(nv->value, NULL, 0);
11320 +
11321 + /* Check if this arch has higher priority, and is valid */
11322 + if ((priority > def_prio) &&
11323 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11324 + /* Our new default */
11325 + def_prio = priority;
11326 + def_arch = nv->name;
11327 + }
11328 + l = l->next;
11329 + }
11330 +
11331 + return strdup(def_arch);
11332 +}
11333 +
11334 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11335 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11336 +{
11337 + hash_table_t *hash = &conf->pkg_hash;
11338 + char **raw;
11339 + char **raw_start;
11340 + pkg_t *pkg;
11341 +
11342 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11343 + if (!raw)
11344 + return -ENOMEM;
11345 +
11346 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11347 + pkg = pkg_new();
11348 + if (!pkg)
11349 + return -ENOMEM;
11350 +
11351 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11352 + if (!pkg->architecture) {
11353 + char *version_str = pkg_version_str_alloc(pkg);
11354 + pkg->architecture = pkg_get_default_arch(conf);
11355 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11356 + pkg->name, version_str, pkg->architecture);
11357 + free(version_str);
11358 + }
11359 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11360 + } else {
11361 + free(pkg);
11362 + }
11363 + }
11364 +
11365 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11366 + memory after read_raw_pkgs_from_file */
11367 + raw = raw_start;
11368 + while (*raw) {
11369 + free(*raw++);
11370 + }
11371 + free(raw_start);
11372 + return 0;
11373 +}
11374 +
11375 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11376 +{
11377 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11378 +}
11379 +
11380 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11381 +{
11382 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11383 + if (apkg)
11384 + return NULL;
11385 + return apkg->provided_by;
11386 +}
11387 +
11388 +
11389 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11390 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11391 +{
11392 + int i, j;
11393 + int nprovides = 0;
11394 + int nmatching = 0;
11395 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11396 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11397 + abstract_pkg_vec_t *provided_apkg_vec;
11398 + abstract_pkg_t **provided_apkgs;
11399 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11400 + pkg_t *latest_installed_parent = NULL;
11401 + pkg_t *latest_matching = NULL;
11402 + pkg_t *held_pkg = NULL;
11403 + pkg_t *good_pkg_by_name = NULL;
11404 +
11405 + if (matching_apkgs == NULL || providers == NULL ||
11406 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11407 + return NULL;
11408 +
11409 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11410 +
11411 + provided_apkg_vec = apkg->provided_by;
11412 + nprovides = provided_apkg_vec->len;
11413 + provided_apkgs = provided_apkg_vec->pkgs;
11414 + if (nprovides > 1)
11415 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11416 +
11417 + /* accumulate all the providers */
11418 + for (i = 0; i < nprovides; i++) {
11419 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11420 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11421 + abstract_pkg_vec_insert(providers, provider_apkg);
11422 + }
11423 + nprovides = providers->len;
11424 +
11425 + for (i = 0; i < nprovides; i++) {
11426 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11427 + abstract_pkg_t *replacement_apkg = NULL;
11428 + pkg_vec_t *vec;
11429 +
11430 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11431 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11432 + if (provider_apkg->replaced_by->len > 1) {
11433 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11434 + provider_apkg->name, replacement_apkg->name);
11435 + }
11436 + }
11437 +
11438 + if (replacement_apkg)
11439 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11440 + replacement_apkg->name, provider_apkg->name);
11441 +
11442 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11443 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11444 + continue;
11445 + else
11446 + provider_apkg = replacement_apkg;
11447 + }
11448 +
11449 + if (!(vec = provider_apkg->pkgs)) {
11450 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11451 + continue;
11452 + }
11453 +
11454 +
11455 + /* now check for supported architecture */
11456 + {
11457 + int max_count = 0;
11458 +
11459 + /* count packages matching max arch priority and keep track of last one */
11460 + for (j = 0; j < vec->len; j++) {
11461 + pkg_t *maybe = vec->pkgs[j];
11462 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11463 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11464 + if (maybe->arch_priority > 0) {
11465 + max_count++;
11466 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11467 + pkg_vec_insert(matching_pkgs, maybe);
11468 + }
11469 + }
11470 + }
11471 + }
11472 +
11473 + if (matching_pkgs->len > 1)
11474 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11475 + if (matching_apkgs->len > 1)
11476 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11477 +
11478 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11479 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11480 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11481 + Until now I always got the latest, but that breaks the downgrade option.
11482 + If I stop at the first one, I would probably miss the new ones
11483 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11484 + or from a Packages feed.
11485 + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
11486 +/*Pigi*/
11487 +
11488 + for (i = 0; i < matching_pkgs->len; i++) {
11489 + pkg_t *matching = matching_pkgs->pkgs[i];
11490 + if (constraint_fcn(matching, cdata)) { /* We found it */
11491 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11492 + good_pkg_by_name = matching;
11493 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11494 + break;
11495 + }
11496 + }
11497 +
11498 +
11499 + for (i = 0; i < matching_pkgs->len; i++) {
11500 + pkg_t *matching = matching_pkgs->pkgs[i];
11501 + latest_matching = matching;
11502 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11503 + latest_installed_parent = matching;
11504 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11505 + if (held_pkg)
11506 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11507 + held_pkg->name, matching->name);
11508 + held_pkg = matching;
11509 + }
11510 + }
11511 +
11512 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11513 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11514 + apkg->name, matching_apkgs->len);
11515 + for (i = 0; i < matching_apkgs->len; i++) {
11516 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11517 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11518 + }
11519 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11520 + }
11521 +
11522 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11523 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11524 + __FUNCTION__, apkg->name, matching_pkgs->len);
11525 + for (i = 0; i < matching_pkgs->len; i++) {
11526 + pkg_t *matching = matching_pkgs->pkgs[i];
11527 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11528 + matching->name, matching->version, matching->architecture);
11529 + }
11530 + }
11531 +
11532 + nmatching = matching_apkgs->len;
11533 +
11534 + pkg_vec_free(matching_pkgs);
11535 + abstract_pkg_vec_free(matching_apkgs);
11536 + abstract_pkg_vec_free(providers);
11537 +
11538 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11539 + return good_pkg_by_name;
11540 + }
11541 + if (held_pkg) {
11542 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11543 + return held_pkg;
11544 + }
11545 + if (latest_installed_parent) {
11546 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11547 + return latest_installed_parent;
11548 + }
11549 + if (nmatching > 1) {
11550 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11551 + return NULL;
11552 + }
11553 + if (latest_matching) {
11554 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11555 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11556 + return latest_matching;
11557 + }
11558 + return NULL;
11559 +}
11560 +
11561 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11562 +{
11563 + const char *name = (const char *)cdata;
11564 + if (strcmp(pkg->name, name) == 0)
11565 + return 1;
11566 + else
11567 + return 0;
11568 +}
11569 +
11570 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11571 +{
11572 + hash_table_t *hash = &conf->pkg_hash;
11573 + abstract_pkg_t *apkg = NULL;
11574 +
11575 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11576 + return NULL;
11577 +
11578 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11579 +}
11580 +
11581 +
11582 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11583 + const char *pkg_name,
11584 + const char * version)
11585 +{
11586 + pkg_vec_t * vec;
11587 + register int i;
11588 + char *version_str = NULL;
11589 +
11590 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11591 + return NULL;
11592 +
11593 + for(i = 0; i < vec->len; i++) {
11594 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11595 + if(!strcmp(version_str, version)) {
11596 + free(version_str);
11597 + break;
11598 + }
11599 + free(version_str);
11600 + }
11601 +
11602 + if(i == vec->len)
11603 + return NULL;
11604 +
11605 + return vec->pkgs[i];
11606 +}
11607 +
11608 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11609 + const char *pkg_name,
11610 + pkg_dest_t *dest)
11611 +{
11612 + pkg_vec_t * vec;
11613 + register int i;
11614 +
11615 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11616 + return NULL;
11617 + }
11618 +
11619 + for(i = 0; i < vec->len; i++)
11620 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11621 + return vec->pkgs[i];
11622 + }
11623 + return NULL;
11624 +}
11625 +
11626 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11627 + const char *pkg_name)
11628 +{
11629 + pkg_vec_t * vec;
11630 + register int i;
11631 +
11632 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11633 + return NULL;
11634 + }
11635 +
11636 + for(i = 0; i < vec->len; i++)
11637 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11638 + return vec->pkgs[i];
11639 + }
11640 +
11641 + return NULL;
11642 +}
11643 +
11644 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11645 +{
11646 + abstract_pkg_t * ab_pkg;
11647 +
11648 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11649 + return NULL;
11650 + }
11651 +
11652 + if (ab_pkg->pkgs) {
11653 + return ab_pkg->pkgs;
11654 + } else if (ab_pkg->provided_by) {
11655 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11656 + if (abpkg != NULL){
11657 + return abpkg->pkgs;
11658 + } else {
11659 + return ab_pkg->pkgs;
11660 + }
11661 + } else {
11662 + return NULL;
11663 + }
11664 +}
11665 +
11666 +static int pkg_compare_names(const void *p1, const void *p2)
11667 +{
11668 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11669 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11670 + if (pkg1->name == NULL)
11671 + return 1;
11672 + if (pkg2->name == NULL)
11673 + return -1;
11674 + return(strcmp(pkg1->name, pkg2->name));
11675 +}
11676 +
11677 +
11678 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11679 +{
11680 + int j;
11681 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11682 + pkg_vec_t *all = (pkg_vec_t *)data;
11683 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11684 + if (pkg_vec) {
11685 + for (j = 0; j < pkg_vec->len; j++) {
11686 + pkg_t *pkg = pkg_vec->pkgs[j];
11687 + pkg_vec_insert(all, pkg);
11688 + }
11689 + }
11690 +}
11691 +
11692 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11693 +{
11694 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11695 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11696 +}
11697 +
11698 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11699 +{
11700 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11701 + pkg_vec_t *all = (pkg_vec_t *)data;
11702 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11703 + int j;
11704 + if (pkg_vec) {
11705 + for (j = 0; j < pkg_vec->len; j++) {
11706 + pkg_t *pkg = pkg_vec->pkgs[j];
11707 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11708 + pkg_vec_insert(all, pkg);
11709 + }
11710 + }
11711 + }
11712 +}
11713 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11714 +{
11715 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11716 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11717 +}
11718 +
11719 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11720 +{
11721 + int i;
11722 + pkg_t *pkg;
11723 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11724 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11725 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11726 + fprintf(stdout, "%s\n", ab_pkg->name);
11727 + i = 0;
11728 + if (dependents != NULL)
11729 + while (dependents [i] != NULL)
11730 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11731 + dependents = ab_pkg->provided_by->pkgs;
11732 + i = 0;
11733 + if (dependents != NULL)
11734 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11735 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11736 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11737 + if (pkg) {
11738 + i = 0;
11739 + while (i < pkg->depends_count)
11740 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11741 + }
11742 +}
11743 +void pkg_hash_dump(hash_table_t *hash, void *data)
11744 +{
11745 +
11746 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11747 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11748 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11749 +}
11750 +
11751 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11752 +{
11753 + abstract_pkg_t * ab_pkg;
11754 +
11755 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11756 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11757 +
11758 + return ab_pkg;
11759 +}
11760 +
11761 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11762 +{
11763 + abstract_pkg_t * ab_pkg;
11764 + int arch_priority;
11765 +
11766 + if(!pkg)
11767 + return pkg;
11768 +
11769 + arch_priority = pkg->arch_priority;
11770 +
11771 + if (buildDepends(hash, pkg)<0){
11772 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11773 + return NULL;
11774 + }
11775 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11776 +
11777 + if (set_status) {
11778 + if (pkg->state_status == SS_INSTALLED) {
11779 + ab_pkg->state_status = SS_INSTALLED;
11780 + } else if (pkg->state_status == SS_UNPACKED) {
11781 + ab_pkg->state_status = SS_UNPACKED;
11782 + }
11783 + }
11784 +
11785 + if(!ab_pkg->pkgs)
11786 + ab_pkg->pkgs = pkg_vec_alloc();
11787 +
11788 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11789 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11790 + pkg->parent = ab_pkg;
11791 +
11792 + if (buildProvides(hash, ab_pkg, pkg)<0){
11793 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11794 + return NULL;
11795 + }
11796 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11797 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11798 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11799 + return NULL;
11800 + }
11801 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11802 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11803 + return NULL;
11804 + }
11805 +
11806 + buildDependedUponBy(pkg, ab_pkg);
11807 + return pkg;
11808 +}
11809 +
11810 +/*
11811 + * this will assume that we've already determined that
11812 + * the abstract pkg doesn't exist, 'cause we should know these things...
11813 + */
11814 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11815 +{
11816 + abstract_pkg_t * ab_pkg;
11817 +
11818 + ab_pkg = abstract_pkg_new();
11819 + if (ab_pkg == NULL) { return NULL; }
11820 +
11821 + ab_pkg->name = strdup(pkg_name);
11822 + hash_table_insert(hash, pkg_name, ab_pkg);
11823 +
11824 + return ab_pkg;
11825 +}
11826 +
11827 +
11828 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11829 +{
11830 + hash_table_t *file_hash = &conf->file_hash;
11831 +
11832 + return hash_table_get(file_hash, file_name);
11833 +}
11834 +
11835 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11836 +{
11837 + hash_table_t *file_hash = &conf->file_hash;
11838 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11839 + int file_name_len = strlen(file_name);
11840 +
11841 + if (file_name[file_name_len -1] == '/')
11842 + return 0;
11843 +
11844 + if (conf->offline_root) {
11845 + int len = strlen(conf->offline_root);
11846 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11847 + file_name += len;
11848 + }
11849 + }
11850 +
11851 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11852 + hash_table_insert(file_hash, file_name, owning_pkg);
11853 + if (old_owning_pkg) {
11854 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11855 + /* mark this package to have its filelist written */
11856 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11857 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11858 + }
11859 + return 0;
11860 +}
11861 +
11862 +
11863 Index: busybox-1.4.2/archival/libipkg/pkg_hash.h
11864 ===================================================================
11865 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11866 +++ busybox-1.4.2/archival/libipkg/pkg_hash.h 2007-06-04 13:21:36.727393256 +0200
11867 @@ -0,0 +1,61 @@
11868 +/* pkg_hash.h - the itsy package management system
11869 +
11870 + Steven M. Ayer
11871 +
11872 + Copyright (C) 2002 Compaq Computer Corporation
11873 +
11874 + This program is free software; you can redistribute it and/or
11875 + modify it under the terms of the GNU General Public License as
11876 + published by the Free Software Foundation; either version 2, or (at
11877 + your option) any later version.
11878 +
11879 + This program is distributed in the hope that it will be useful, but
11880 + WITHOUT ANY WARRANTY; without even the implied warranty of
11881 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11882 + General Public License for more details.
11883 +*/
11884 +
11885 +#ifndef PKG_HASH_H
11886 +#define PKG_HASH_H
11887 +
11888 +#include "pkg.h"
11889 +#include "pkg_vec.h"
11890 +#include "hash_table.h"
11891 +
11892 +
11893 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11894 +void pkg_hash_deinit(hash_table_t *hash);
11895 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11896 +
11897 +void pkg_hash_dump(hash_table_t *hash, void *data);
11898 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11899 +
11900 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11901 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11902 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11903 +
11904 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11905 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11906 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11907 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11908 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11909 + const char *pkg_name,
11910 + const char * version);
11911 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11912 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11913 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11914 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11915 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11916 + const char *pkg_name);
11917 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11918 + const char *pkg_name,
11919 + pkg_dest_t *dest);
11920 +
11921 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11922 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11923 +
11924 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11925 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11926 +
11927 +#endif
11928 +
11929 Index: busybox-1.4.2/archival/libipkg/pkg_parse.c
11930 ===================================================================
11931 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11932 +++ busybox-1.4.2/archival/libipkg/pkg_parse.c 2007-06-04 13:21:36.727393256 +0200
11933 @@ -0,0 +1,366 @@
11934 +/* pkg_parse.c - the itsy package management system
11935 +
11936 + Steven M. Ayer
11937 +
11938 + Copyright (C) 2002 Compaq Computer Corporation
11939 +
11940 + This program is free software; you can redistribute it and/or
11941 + modify it under the terms of the GNU General Public License as
11942 + published by the Free Software Foundation; either version 2, or (at
11943 + your option) any later version.
11944 +
11945 + This program is distributed in the hope that it will be useful, but
11946 + WITHOUT ANY WARRANTY; without even the implied warranty of
11947 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11948 + General Public License for more details.
11949 +*/
11950 +
11951 +#include "ipkg.h"
11952 +#include <errno.h>
11953 +#include <ctype.h>
11954 +
11955 +#include "pkg.h"
11956 +#include "ipkg_utils.h"
11957 +#include "pkg_parse.h"
11958 +
11959 +int isGenericFieldType(char * type, char * line)
11960 +{
11961 + if(!strncmp(line, type, strlen(type)))
11962 + return 1;
11963 + return 0;
11964 +}
11965 +
11966 +char * parseGenericFieldType(char * type, char * raw)
11967 +{
11968 + char * field_value = raw + (strlen(type) + 1);
11969 + return trim_alloc(field_value);
11970 +}
11971 +
11972 +void parseStatus(pkg_t *pkg, char * raw)
11973 +{
11974 + char sw_str[64], sf_str[64], ss_str[64];
11975 +
11976 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11977 + pkg->state_want = pkg_state_want_from_str(sw_str);
11978 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11979 + pkg->state_status = pkg_state_status_from_str(ss_str);
11980 +}
11981 +
11982 +char ** parseDependsString(char * raw, int * depends_count)
11983 +{
11984 + char ** depends = NULL;
11985 + int line_count = 0;
11986 + char buff[2048], * dest;
11987 +
11988 + while(raw && *raw && !isspace(*raw)) {
11989 + raw++;
11990 + }
11991 +
11992 + if(line_is_blank(raw)){
11993 + *depends_count = line_count;
11994 + return NULL;
11995 + }
11996 + while(raw && *raw){
11997 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11998 +
11999 + while(isspace(*raw)) raw++;
12000 +
12001 + dest = buff;
12002 + while((*raw != ',') && *raw)
12003 + *dest++ = *raw++;
12004 +
12005 + *dest = '\0';
12006 + depends[line_count] = trim_alloc(buff);
12007 + if(depends[line_count] ==NULL)
12008 + return NULL;
12009 + line_count++;
12010 + if(*raw == ',')
12011 + raw++;
12012 + }
12013 + *depends_count = line_count;
12014 + return depends;
12015 +}
12016 +
12017 +void parseConffiles(pkg_t * pkg, char * raw)
12018 +{
12019 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12020 +
12021 + if(!strncmp(raw, "Conffiles:", 10))
12022 + raw += strlen("Conffiles:");
12023 +
12024 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12025 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12026 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12027 + while (*raw && isspace(*raw)) {
12028 + raw++;
12029 + }
12030 + raw += strlen(file_name);
12031 + while (*raw && isspace(*raw)) {
12032 + raw++;
12033 + }
12034 + raw += strlen(md5sum);
12035 + }
12036 +}
12037 +
12038 +int parseVersion(pkg_t *pkg, char *raw)
12039 +{
12040 + char *colon, *eepochcolon;
12041 +#ifdef USE_DEBVERSION
12042 + char *hyphen;
12043 +#endif
12044 + unsigned long epoch;
12045 +
12046 + if (!*raw) {
12047 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12048 + return EINVAL;
12049 + }
12050 +
12051 + if (strncmp(raw, "Version:", 8) == 0) {
12052 + raw += 8;
12053 + }
12054 + while (*raw && isspace(*raw)) {
12055 + raw++;
12056 + }
12057 +
12058 + colon= strchr(raw,':');
12059 + if (colon) {
12060 + epoch= strtoul(raw,&eepochcolon,10);
12061 + if (colon != eepochcolon) {
12062 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12063 + return EINVAL;
12064 + }
12065 + if (!*++colon) {
12066 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12067 + return EINVAL;
12068 + }
12069 + raw= colon;
12070 + pkg->epoch= epoch;
12071 + } else {
12072 + pkg->epoch= 0;
12073 + }
12074 +
12075 + pkg->revision = "";
12076 + pkg->familiar_revision = "";
12077 +
12078 + pkg->version= malloc(strlen(raw)+1);
12079 + if ( pkg->version == NULL ) {
12080 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12081 + return ENOMEM;
12082 + }
12083 + strcpy(pkg->version, raw);
12084 +
12085 +#ifdef USE_DEBVERSION
12086 + hyphen= strrchr(pkg->version,'-');
12087 +
12088 + if (hyphen) {
12089 + *hyphen++= 0;
12090 + if (strncmp("fam", hyphen, 3) == 0) {
12091 + pkg->familiar_revision=hyphen+3;
12092 + hyphen= strrchr(pkg->version,'-');
12093 + if (hyphen) {
12094 + *hyphen++= 0;
12095 + pkg->revision = hyphen;
12096 + }
12097 + } else {
12098 + pkg->revision = hyphen;
12099 + }
12100 + }
12101 +#endif
12102 +
12103 +/*
12104 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12105 + pkg->epoch,
12106 + pkg->version,
12107 + pkg->revision,
12108 + pkg->familiar_revision);
12109 +*/
12110 +
12111 + return 0;
12112 +}
12113 +
12114 +
12115 +/* This code is needed to insert in first position the keyword for the aligning bug */
12116 +
12117 +int alterProvidesLine(char *raw, char *temp)
12118 +{
12119 +
12120 +
12121 + if (!*raw) {
12122 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12123 + return -EINVAL;
12124 + }
12125 +
12126 + if ( temp == NULL ) {
12127 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12128 + return -ENOMEM;
12129 + }
12130 +
12131 + if (strncmp(raw, "Provides:", 9) == 0) {
12132 + raw += 9;
12133 + }
12134 + while (*raw && isspace(*raw)) {
12135 + raw++;
12136 + }
12137 +
12138 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12139 + while (*raw) {
12140 + strncat( temp, raw++, 1);
12141 + }
12142 + return 0;
12143 +
12144 +}
12145 +
12146 +/* Some random thoughts from Carl:
12147 +
12148 + This function could be considerably simplified if we just kept
12149 + an array of all the generic string-valued field names, and looped
12150 + through those looking for a match. Also, these fields could perhaps
12151 + be stored in the package as an array as well, (or, probably better,
12152 + as an nv_pair_list_t).
12153 +
12154 + Fields which require special parsing or storage, (such as Depends:
12155 + and Status:) could be handled as they are now.
12156 +*/
12157 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12158 + to a dependency list. And, since we already have
12159 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12160 + Enhances, perhaps we could generalize all of these and save some
12161 + code duplication.
12162 +*/
12163 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12164 +{
12165 + int reading_conffiles, reading_description;
12166 + int pkg_false_provides=1;
12167 + char ** lines;
12168 + char * provide=NULL;
12169 +
12170 + pkg->src = src;
12171 + pkg->dest = dest;
12172 +
12173 + reading_conffiles = reading_description = 0;
12174 +
12175 + for (lines = *raw; *lines; lines++) {
12176 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12177 + if(isGenericFieldType("Package:", *lines))
12178 + pkg->name = parseGenericFieldType("Package", *lines);
12179 + else if(isGenericFieldType("Architecture:", *lines))
12180 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12181 + else if(isGenericFieldType("Filename:", *lines))
12182 + pkg->filename = parseGenericFieldType("Filename", *lines);
12183 + else if(isGenericFieldType("Section:", *lines))
12184 + pkg->section = parseGenericFieldType("Section", *lines);
12185 + else if(isGenericFieldType("MD5sum:", *lines))
12186 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12187 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12188 + let's parse it either way */
12189 + else if(isGenericFieldType("MD5Sum:", *lines))
12190 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12191 + else if(isGenericFieldType("Size:", *lines))
12192 + pkg->size = parseGenericFieldType("Size", *lines);
12193 + else if(isGenericFieldType("Source:", *lines))
12194 + pkg->source = parseGenericFieldType("Source", *lines);
12195 + else if(isGenericFieldType("Installed-Size:", *lines))
12196 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12197 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12198 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12199 + pkg->installed_time = strtoul(time_str, NULL, 0);
12200 + } else if(isGenericFieldType("Priority:", *lines))
12201 + pkg->priority = parseGenericFieldType("Priority", *lines);
12202 + else if(isGenericFieldType("Essential:", *lines)) {
12203 + char *essential_value;
12204 + essential_value = parseGenericFieldType("Essential", *lines);
12205 + if (strcmp(essential_value, "yes") == 0) {
12206 + pkg->essential = 1;
12207 + }
12208 + free(essential_value);
12209 + }
12210 + else if(isGenericFieldType("Status", *lines))
12211 + parseStatus(pkg, *lines);
12212 + else if(isGenericFieldType("Version", *lines))
12213 + parseVersion(pkg, *lines);
12214 + else if(isGenericFieldType("Maintainer", *lines))
12215 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12216 + else if(isGenericFieldType("Conffiles", *lines)){
12217 + parseConffiles(pkg, *lines);
12218 + reading_conffiles = 1;
12219 + }
12220 + else if(isGenericFieldType("Description", *lines)) {
12221 + pkg->description = parseGenericFieldType("Description", *lines);
12222 + reading_conffiles = 0;
12223 + reading_description = 1;
12224 + }
12225 +
12226 + else if(isGenericFieldType("Provides", *lines)){
12227 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12228 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12229 + if ( alterProvidesLine(*lines,provide) ){
12230 + return EINVAL;
12231 + }
12232 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12233 +/* Let's try to hack a bit here.
12234 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12235 + in alot of other places. We will remove it before writing down the status database */
12236 + pkg_false_provides=0;
12237 + free(provide);
12238 + }
12239 +
12240 + else if(isGenericFieldType("Depends", *lines))
12241 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12242 + else if(isGenericFieldType("Pre-Depends", *lines))
12243 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12244 + else if(isGenericFieldType("Recommends", *lines))
12245 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12246 + else if(isGenericFieldType("Suggests", *lines))
12247 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12248 + /* Abhaya: support for conflicts */
12249 + else if(isGenericFieldType("Conflicts", *lines))
12250 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12251 + else if(isGenericFieldType("Replaces", *lines))
12252 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12253 + else if(line_is_blank(*lines)) {
12254 + lines++;
12255 + break;
12256 + }
12257 + else if(**lines == ' '){
12258 + if(reading_description) {
12259 + /* we already know it's not blank, so the rest of description */
12260 + pkg->description = realloc(pkg->description,
12261 + strlen(pkg->description)
12262 + + 1 + strlen(*lines) + 1);
12263 + strcat(pkg->description, "\n");
12264 + strcat(pkg->description, (*lines));
12265 + }
12266 + else if(reading_conffiles)
12267 + parseConffiles(pkg, *lines);
12268 + }
12269 + }
12270 + *raw = lines;
12271 +/* If the ipk has not a Provides line, we insert our false line */
12272 + if ( pkg_false_provides==1)
12273 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12274 +
12275 + if (pkg->name) {
12276 + return 0;
12277 + } else {
12278 + return EINVAL;
12279 + }
12280 +}
12281 +
12282 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12283 +{
12284 + char ** lines;
12285 +
12286 + for (lines = *raw; *lines; lines++) {
12287 + if(isGenericFieldType("Essential:", *lines)) {
12288 + char *essential_value;
12289 + essential_value = parseGenericFieldType("Essential", *lines);
12290 + if (strcmp(essential_value, "yes") == 0) {
12291 + pkg->essential = 1;
12292 + }
12293 + free(essential_value);
12294 + }
12295 + }
12296 + *raw = lines;
12297 +
12298 + return 0;
12299 +}
12300 Index: busybox-1.4.2/archival/libipkg/pkg_parse.h
12301 ===================================================================
12302 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12303 +++ busybox-1.4.2/archival/libipkg/pkg_parse.h 2007-06-04 13:21:36.728393104 +0200
12304 @@ -0,0 +1,31 @@
12305 +/* pkg_parse.h - the itsy package management system
12306 +
12307 + Steven M. Ayer
12308 +
12309 + Copyright (C) 2002 Compaq Computer Corporation
12310 +
12311 + This program is free software; you can redistribute it and/or
12312 + modify it under the terms of the GNU General Public License as
12313 + published by the Free Software Foundation; either version 2, or (at
12314 + your option) any later version.
12315 +
12316 + This program is distributed in the hope that it will be useful, but
12317 + WITHOUT ANY WARRANTY; without even the implied warranty of
12318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12319 + General Public License for more details.
12320 +*/
12321 +
12322 +#ifndef PKG_PARSE_H
12323 +#define PKG_PARSE_H
12324 +
12325 +int isGenericFieldType(char * type, char * line);
12326 +char * parseGenericFieldType(char * type, char * raw);
12327 +void parseStatus(pkg_t *pkg, char * raw);
12328 +int parseVersion(pkg_t *pkg, char *raw);
12329 +char ** parseDependsString(char * raw, int * depends_count);
12330 +int parseVersion(pkg_t *pkg, char *raw);
12331 +void parseConffiles(pkg_t * pkg, char * raw);
12332 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12333 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12334 +
12335 +#endif
12336 Index: busybox-1.4.2/archival/libipkg/pkg_src.c
12337 ===================================================================
12338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12339 +++ busybox-1.4.2/archival/libipkg/pkg_src.c 2007-06-04 13:21:36.728393104 +0200
12340 @@ -0,0 +1,43 @@
12341 +/* pkg_src.c - the itsy package management system
12342 +
12343 + Carl D. Worth
12344 +
12345 + Copyright (C) 2001 University of Southern California
12346 +
12347 + This program is free software; you can redistribute it and/or
12348 + modify it under the terms of the GNU General Public License as
12349 + published by the Free Software Foundation; either version 2, or (at
12350 + your option) any later version.
12351 +
12352 + This program is distributed in the hope that it will be useful, but
12353 + WITHOUT ANY WARRANTY; without even the implied warranty of
12354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12355 + General Public License for more details.
12356 +*/
12357 +
12358 +#include "ipkg.h"
12359 +
12360 +#include "pkg_src.h"
12361 +#include "str_util.h"
12362 +
12363 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12364 +{
12365 + src->gzip = gzip;
12366 + src->name = str_dup_safe (name);
12367 + src->value = str_dup_safe (base_url);
12368 + if (extra_data)
12369 + src->extra_data = str_dup_safe (extra_data);
12370 + else
12371 + src->extra_data = NULL;
12372 + return 0;
12373 +}
12374 +
12375 +void pkg_src_deinit(pkg_src_t *src)
12376 +{
12377 + free (src->name);
12378 + free (src->value);
12379 + if (src->extra_data)
12380 + free (src->extra_data);
12381 +}
12382 +
12383 +
12384 Index: busybox-1.4.2/archival/libipkg/pkg_src.h
12385 ===================================================================
12386 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12387 +++ busybox-1.4.2/archival/libipkg/pkg_src.h 2007-06-04 13:21:36.728393104 +0200
12388 @@ -0,0 +1,34 @@
12389 +/* pkg_src.h - the itsy package management system
12390 +
12391 + Carl D. Worth
12392 +
12393 + Copyright (C) 2001 University of Southern California
12394 +
12395 + This program is free software; you can redistribute it and/or
12396 + modify it under the terms of the GNU General Public License as
12397 + published by the Free Software Foundation; either version 2, or (at
12398 + your option) any later version.
12399 +
12400 + This program is distributed in the hope that it will be useful, but
12401 + WITHOUT ANY WARRANTY; without even the implied warranty of
12402 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12403 + General Public License for more details.
12404 +*/
12405 +
12406 +#ifndef PKG_SRC_H
12407 +#define PKG_SRC_H
12408 +
12409 +#include "nv_pair.h"
12410 +
12411 +typedef struct
12412 +{
12413 + char *name;
12414 + char *value;
12415 + char *extra_data;
12416 + int gzip;
12417 +} pkg_src_t;
12418 +
12419 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12420 +void pkg_src_deinit(pkg_src_t *src);
12421 +
12422 +#endif
12423 Index: busybox-1.4.2/archival/libipkg/pkg_src_list.c
12424 ===================================================================
12425 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12426 +++ busybox-1.4.2/archival/libipkg/pkg_src_list.c 2007-06-04 13:21:36.728393104 +0200
12427 @@ -0,0 +1,75 @@
12428 +/* pkg_src_list.c - the itsy package management system
12429 +
12430 + Carl D. Worth
12431 +
12432 + Copyright (C) 2001 University of Southern California
12433 +
12434 + This program is free software; you can redistribute it and/or
12435 + modify it under the terms of the GNU General Public License as
12436 + published by the Free Software Foundation; either version 2, or (at
12437 + your option) any later version.
12438 +
12439 + This program is distributed in the hope that it will be useful, but
12440 + WITHOUT ANY WARRANTY; without even the implied warranty of
12441 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12442 + General Public License for more details.
12443 +*/
12444 +
12445 +#include "ipkg.h"
12446 +
12447 +#include "pkg_src_list.h"
12448 +#include "void_list.h"
12449 +
12450 +int pkg_src_list_init(pkg_src_list_t *list)
12451 +{
12452 + return void_list_init((void_list_t *) list);
12453 +}
12454 +
12455 +void pkg_src_list_deinit(pkg_src_list_t *list)
12456 +{
12457 + pkg_src_list_elt_t *iter;
12458 + pkg_src_t *pkg_src;
12459 +
12460 + for (iter = list->head; iter; iter = iter->next) {
12461 + pkg_src = iter->data;
12462 + pkg_src_deinit(pkg_src);
12463 +
12464 + /* malloced in pkg_src_list_append */
12465 + free(pkg_src);
12466 + iter->data = NULL;
12467 + }
12468 + void_list_deinit((void_list_t *) list);
12469 +}
12470 +
12471 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12472 + const char *name, const char *base_url, const char *extra_data,
12473 + int gzip)
12474 +{
12475 + int err;
12476 +
12477 + /* freed in pkg_src_list_deinit */
12478 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12479 +
12480 + if (pkg_src == NULL) {
12481 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12482 + return NULL;
12483 + }
12484 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12485 +
12486 + err = void_list_append((void_list_t *) list, pkg_src);
12487 + if (err) {
12488 + return NULL;
12489 + }
12490 +
12491 + return pkg_src;
12492 +}
12493 +
12494 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12495 +{
12496 + return void_list_push((void_list_t *) list, data);
12497 +}
12498 +
12499 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12500 +{
12501 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12502 +}
12503 Index: busybox-1.4.2/archival/libipkg/pkg_src_list.h
12504 ===================================================================
12505 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12506 +++ busybox-1.4.2/archival/libipkg/pkg_src_list.h 2007-06-04 13:21:36.728393104 +0200
12507 @@ -0,0 +1,57 @@
12508 +/* pkg_src_list.h - the itsy package management system
12509 +
12510 + Carl D. Worth
12511 +
12512 + Copyright (C) 2001 University of Southern California
12513 +
12514 + This program is free software; you can redistribute it and/or
12515 + modify it under the terms of the GNU General Public License as
12516 + published by the Free Software Foundation; either version 2, or (at
12517 + your option) any later version.
12518 +
12519 + This program is distributed in the hope that it will be useful, but
12520 + WITHOUT ANY WARRANTY; without even the implied warranty of
12521 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12522 + General Public License for more details.
12523 +*/
12524 +
12525 +#ifndef PKG_SRC_LIST_H
12526 +#define PKG_SRC_LIST_H
12527 +
12528 +#include "pkg_src.h"
12529 +
12530 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12531 +struct pkg_src_list_elt
12532 +{
12533 + pkg_src_list_elt_t *next;
12534 + pkg_src_t *data;
12535 +};
12536 +
12537 +typedef struct pkg_src_list pkg_src_list_t;
12538 +struct pkg_src_list
12539 +{
12540 + pkg_src_list_elt_t pre_head;
12541 + pkg_src_list_elt_t *head;
12542 + pkg_src_list_elt_t *tail;
12543 +};
12544 +
12545 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12546 +{
12547 + if (list->head == NULL)
12548 + return 1;
12549 + else
12550 + return 0;
12551 +}
12552 +
12553 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12554 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12555 +
12556 +int pkg_src_list_init(pkg_src_list_t *list);
12557 +void pkg_src_list_deinit(pkg_src_list_t *list);
12558 +
12559 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
12560 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12561 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12562 +
12563 +#endif
12564 +
12565 Index: busybox-1.4.2/archival/libipkg/pkg_vec.c
12566 ===================================================================
12567 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12568 +++ busybox-1.4.2/archival/libipkg/pkg_vec.c 2007-06-04 13:21:36.729392952 +0200
12569 @@ -0,0 +1,230 @@
12570 +/* pkg_vec.c - the itsy package management system
12571 +
12572 + Steven M. Ayer
12573 +
12574 + Copyright (C) 2002 Compaq Computer Corporation
12575 +
12576 + This program is free software; you can redistribute it and/or
12577 + modify it under the terms of the GNU General Public License as
12578 + published by the Free Software Foundation; either version 2, or (at
12579 + your option) any later version.
12580 +
12581 + This program is distributed in the hope that it will be useful, but
12582 + WITHOUT ANY WARRANTY; without even the implied warranty of
12583 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12584 + General Public License for more details.
12585 +*/
12586 +
12587 +#include <stdlib.h>
12588 +#include <fnmatch.h>
12589 +#include "xregex.h"
12590 +#include "ipkg.h"
12591 +#include "pkg.h"
12592 +
12593 +pkg_vec_t * pkg_vec_alloc(void)
12594 +{
12595 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12596 + if (!vec) {
12597 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12598 + return NULL;
12599 + }
12600 + vec->pkgs = NULL;
12601 + vec->len = 0;
12602 +
12603 + return vec;
12604 +}
12605 +
12606 +void pkg_vec_free(pkg_vec_t *vec)
12607 +{
12608 + free(vec->pkgs);
12609 + free(vec);
12610 +}
12611 +
12612 +/*
12613 + * assumption: all names in a vector are identical
12614 + * assumption: all version strings are trimmed,
12615 + * so identical versions have identical version strings,
12616 + * implying identical packages; let's marry these
12617 + */
12618 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12619 +{
12620 + int i;
12621 + int found = 0;
12622 +
12623 + /* look for a duplicate pkg by name, version, and architecture */
12624 + for (i = 0; i < vec->len; i++){
12625 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12626 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12627 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12628 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12629 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12630 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12631 + found = 1;
12632 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12633 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12634 + break;
12635 + }
12636 + }
12637 +
12638 + /* we didn't find one, add it */
12639 + if (!found){
12640 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12641 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12642 +
12643 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12644 + vec->pkgs[vec->len] = pkg;
12645 + vec->len++;
12646 + return pkg;
12647 + }
12648 + /* update the one that we have */
12649 + else {
12650 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12651 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12652 + if (set_status) {
12653 + /* this is from the status file, so need to merge with existing database */
12654 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12655 + pkg_merge(vec->pkgs[i], pkg, set_status);
12656 + /* XXX: CLEANUP: It's not so polite to free something here
12657 + that was passed in from above. */
12658 + pkg_deinit(pkg);
12659 + free(pkg);
12660 + } else {
12661 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12662 + /* just overwrite the old one */
12663 + pkg_deinit(vec->pkgs[i]);
12664 + free(vec->pkgs[i]);
12665 + vec->pkgs[i] = pkg;
12666 + }
12667 + return vec->pkgs[i];
12668 + }
12669 +}
12670 +
12671 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12672 +{
12673 + int i;
12674 + int found = 0;
12675 +
12676 + /* look for a duplicate pkg by name, version, and architecture */
12677 + for (i = 0; i < vec->len; i++)
12678 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12679 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12680 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12681 + found = 1;
12682 + break;
12683 + }
12684 +
12685 + /* we didn't find one, add it */
12686 + if(!found){
12687 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12688 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12689 + vec->len++;
12690 + }
12691 +}
12692 +
12693 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12694 +{
12695 + int i;
12696 + for (i = 0; i < vec->len; i++)
12697 + if (vec->pkgs[i] == apkg)
12698 + return 1;
12699 + return 0;
12700 +}
12701 +
12702 +typedef int (*compare_fcn_t)(const void *, const void *);
12703 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12704 +{
12705 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12706 +}
12707 +
12708 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12709 +{
12710 + int npkgs = vec->len;
12711 + int i;
12712 + for (i = 0; i < npkgs; i++) {
12713 + pkg_t *pkg = vec->pkgs[i];
12714 + pkg->state_flag &= ~SF_MARKED;
12715 + }
12716 + return 0;
12717 +}
12718 +
12719 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12720 +{
12721 + int matching_count = 0;
12722 + pkg_t **pkgs = vec->pkgs;
12723 + int npkgs = vec->len;
12724 + int i;
12725 + for (i = 0; i < npkgs; i++) {
12726 + pkg_t *pkg = pkgs[i];
12727 + if (fnmatch(pattern, pkg->name, 0)==0) {
12728 + pkg->state_flag |= SF_MARKED;
12729 + matching_count++;
12730 + }
12731 + }
12732 + return matching_count;
12733 +}
12734 +
12735 +
12736 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12737 +{
12738 + abstract_pkg_vec_t * vec ;
12739 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12740 + if (!vec) {
12741 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12742 + return NULL;
12743 + }
12744 + vec->pkgs = NULL;
12745 + vec->len = 0;
12746 +
12747 + return vec;
12748 +}
12749 +
12750 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12751 +{
12752 + free(vec->pkgs);
12753 + free(vec);
12754 +}
12755 +
12756 +/*
12757 + * assumption: all names in a vector are unique
12758 + */
12759 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12760 +{
12761 + int i;
12762 +
12763 + /* look for a duplicate pkg by name */
12764 + for(i = 0; i < vec->len; i++)
12765 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12766 + break;
12767 +
12768 + /* we didn't find one, add it */
12769 + if(i == vec->len){
12770 + vec->pkgs =
12771 + (abstract_pkg_t **)
12772 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12773 + vec->pkgs[vec->len] = pkg;
12774 + vec->len++;
12775 + }
12776 +}
12777 +
12778 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12779 +{
12780 + if (vec->len > i)
12781 + return vec->pkgs[i];
12782 + else
12783 + return NULL;
12784 +}
12785 +
12786 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12787 +{
12788 + int i;
12789 + for (i = 0; i < vec->len; i++)
12790 + if (vec->pkgs[i] == apkg)
12791 + return 1;
12792 + return 0;
12793 +}
12794 +
12795 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12796 +{
12797 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12798 +}
12799 +
12800 Index: busybox-1.4.2/archival/libipkg/pkg_vec.h
12801 ===================================================================
12802 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12803 +++ busybox-1.4.2/archival/libipkg/pkg_vec.h 2007-06-04 13:21:36.729392952 +0200
12804 @@ -0,0 +1,64 @@
12805 +/* pkg_vec.h - the itsy package management system
12806 +
12807 + Steven M. Ayer
12808 +
12809 + Copyright (C) 2002 Compaq Computer Corporation
12810 +
12811 + This program is free software; you can redistribute it and/or
12812 + modify it under the terms of the GNU General Public License as
12813 + published by the Free Software Foundation; either version 2, or (at
12814 + your option) any later version.
12815 +
12816 + This program is distributed in the hope that it will be useful, but
12817 + WITHOUT ANY WARRANTY; without even the implied warranty of
12818 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12819 + General Public License for more details.
12820 +*/
12821 +
12822 +#ifndef PKG_VEC_H
12823 +#define PKG_VEC_H
12824 +
12825 +typedef struct pkg pkg_t;
12826 +typedef struct abstract_pkg abstract_pkg_t;
12827 +
12828 +struct pkg_vec
12829 +{
12830 + pkg_t **pkgs;
12831 + int len;
12832 +};
12833 +typedef struct pkg_vec pkg_vec_t;
12834 +
12835 +struct abstract_pkg_vec
12836 +{
12837 + abstract_pkg_t **pkgs;
12838 + int len;
12839 +};
12840 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12841 +
12842 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12843 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12844 +
12845 +pkg_vec_t * pkg_vec_alloc(void);
12846 +void pkg_vec_free(pkg_vec_t *vec);
12847 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12848 +
12849 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12850 +/* pkg_vec_insert_merge: might munge pkg.
12851 +* returns the pkg that is in the pkg graph */
12852 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12853 +/* this one never munges pkg */
12854 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12855 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12856 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12857 +
12858 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12859 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12860 +
12861 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12862 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12863 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12864 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12865 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12866 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12867 +#endif
12868 +
12869 Index: busybox-1.4.2/archival/libipkg/sprintf_alloc.h
12870 ===================================================================
12871 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12872 +++ busybox-1.4.2/archival/libipkg/sprintf_alloc.h 2007-06-04 13:21:36.729392952 +0200
12873 @@ -0,0 +1,25 @@
12874 +/* sprintf_alloca.c -- like sprintf with memory allocation
12875 +
12876 + Carl D. Worth
12877 +
12878 + Copyright (C) 2001 University of Southern California
12879 +
12880 + This program is free software; you can redistribute it and/or modify
12881 + it under the terms of the GNU General Public License as published by
12882 + the Free Software Foundation; either version 2, or (at your option)
12883 + any later version.
12884 +
12885 + This program is distributed in the hope that it will be useful,
12886 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12887 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12888 + GNU General Public License for more details.
12889 +*/
12890 +
12891 +#ifndef SPRINTF_ALLOC_H
12892 +#define SPRINTF_ALLOC_H
12893 +
12894 +#include "libbb.h"
12895 +
12896 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12897 +
12898 +#endif
12899 Index: busybox-1.4.2/archival/libipkg/str_list.c
12900 ===================================================================
12901 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12902 +++ busybox-1.4.2/archival/libipkg/str_list.c 2007-06-04 13:21:36.729392952 +0200
12903 @@ -0,0 +1,76 @@
12904 +/* str_list.c - the itsy package management system
12905 +
12906 + Carl D. Worth
12907 +
12908 + Copyright (C) 2001 University of Southern California
12909 +
12910 + This program is free software; you can redistribute it and/or
12911 + modify it under the terms of the GNU General Public License as
12912 + published by the Free Software Foundation; either version 2, or (at
12913 + your option) any later version.
12914 +
12915 + This program is distributed in the hope that it will be useful, but
12916 + WITHOUT ANY WARRANTY; without even the implied warranty of
12917 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12918 + General Public License for more details.
12919 +*/
12920 +
12921 +#include "ipkg.h"
12922 +
12923 +#include "str_list.h"
12924 +
12925 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12926 +{
12927 + return void_list_elt_init((void_list_elt_t *) elt, data);
12928 +}
12929 +
12930 +void str_list_elt_deinit(str_list_elt_t *elt)
12931 +{
12932 + void_list_elt_deinit((void_list_elt_t *) elt);
12933 +}
12934 +
12935 +str_list_t *str_list_alloc()
12936 +{
12937 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12938 + if (list)
12939 + str_list_init(list);
12940 + return list;
12941 +}
12942 +
12943 +int str_list_init(str_list_t *list)
12944 +{
12945 + return void_list_init((void_list_t *) list);
12946 +}
12947 +
12948 +void str_list_deinit(str_list_t *list)
12949 +{
12950 + void_list_deinit((void_list_t *) list);
12951 +}
12952 +
12953 +int str_list_append(str_list_t *list, char *data)
12954 +{
12955 + return void_list_append((void_list_t *) list, data);
12956 +}
12957 +
12958 +int str_list_push(str_list_t *list, char *data)
12959 +{
12960 + return void_list_push((void_list_t *) list, data);
12961 +}
12962 +
12963 +str_list_elt_t *str_list_pop(str_list_t *list)
12964 +{
12965 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12966 +}
12967 +
12968 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12969 +{
12970 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12971 + (void_list_elt_t **) iter);
12972 +}
12973 +
12974 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12975 +{
12976 + return (char *)void_list_remove_elt((void_list_t *) list,
12977 + (void *)target_str,
12978 + (void_list_cmp_t)strcmp);
12979 +}
12980 Index: busybox-1.4.2/archival/libipkg/str_list.h
12981 ===================================================================
12982 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12983 +++ busybox-1.4.2/archival/libipkg/str_list.h 2007-06-04 13:21:36.729392952 +0200
12984 @@ -0,0 +1,51 @@
12985 +/* str_list.h - the itsy package management system
12986 +
12987 + Carl D. Worth
12988 +
12989 + Copyright (C) 2001 University of Southern California
12990 +
12991 + This program is free software; you can redistribute it and/or
12992 + modify it under the terms of the GNU General Public License as
12993 + published by the Free Software Foundation; either version 2, or (at
12994 + your option) any later version.
12995 +
12996 + This program is distributed in the hope that it will be useful, but
12997 + WITHOUT ANY WARRANTY; without even the implied warranty of
12998 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12999 + General Public License for more details.
13000 +*/
13001 +
13002 +#ifndef STR_LIST_H
13003 +#define STR_LIST_H
13004 +
13005 +#include "void_list.h"
13006 +
13007 +typedef struct str_list_elt str_list_elt_t;
13008 +struct str_list_elt
13009 +{
13010 + str_list_elt_t *next;
13011 + char *data;
13012 +};
13013 +
13014 +typedef struct xstr_list str_list_t;
13015 +struct xstr_list
13016 +{
13017 + str_list_elt_t pre_head;
13018 + str_list_elt_t *head;
13019 + str_list_elt_t *tail;
13020 +};
13021 +
13022 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13023 +void str_list_elt_deinit(str_list_elt_t *elt);
13024 +
13025 +str_list_t *str_list_alloc(void);
13026 +int str_list_init(str_list_t *list);
13027 +void str_list_deinit(str_list_t *list);
13028 +
13029 +int str_list_append(str_list_t *list, char *data);
13030 +int str_list_push(str_list_t *list, char *data);
13031 +str_list_elt_t *str_list_pop(str_list_t *list);
13032 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13033 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13034 +
13035 +#endif
13036 Index: busybox-1.4.2/archival/libipkg/str_util.c
13037 ===================================================================
13038 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13039 +++ busybox-1.4.2/archival/libipkg/str_util.c 2007-06-04 13:21:36.730392800 +0200
13040 @@ -0,0 +1,73 @@
13041 +/* str_utils.c - the itsy package management system
13042 +
13043 + Carl D. Worth
13044 +
13045 + Copyright (C) 2001 University of Southern California
13046 +
13047 + This program is free software; you can redistribute it and/or
13048 + modify it under the terms of the GNU General Public License as
13049 + published by the Free Software Foundation; either version 2, or (at
13050 + your option) any later version.
13051 +
13052 + This program is distributed in the hope that it will be useful, but
13053 + WITHOUT ANY WARRANTY; without even the implied warranty of
13054 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13055 + General Public License for more details.
13056 +*/
13057 +
13058 +#include "ipkg.h"
13059 +
13060 +int str_starts_with(const char *str, const char *prefix)
13061 +{
13062 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13063 +}
13064 +
13065 +int str_ends_with(const char *str, const char *suffix)
13066 +{
13067 + int suffix_len;
13068 + int str_len;
13069 +
13070 + str_len = strlen(str);
13071 + suffix_len = strlen(suffix);
13072 +
13073 + if (str_len < suffix_len) {
13074 + return 0;
13075 + }
13076 +
13077 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13078 +}
13079 +
13080 +int str_chomp(char *str)
13081 +{
13082 + if (str[strlen(str) - 1] == '\n') {
13083 + str[strlen(str) - 1] = '\0';
13084 + return 1;
13085 + }
13086 + return 0;
13087 +}
13088 +
13089 +int str_tolower(char *str)
13090 +{
13091 + while (*str) {
13092 + *str = tolower(*str);
13093 + str++;
13094 + }
13095 +
13096 + return 0;
13097 +}
13098 +
13099 +int str_toupper(char *str)
13100 +{
13101 + while (*str) {
13102 + *str = toupper(*str);
13103 + str++;
13104 + }
13105 +
13106 + return 0;
13107 +}
13108 +
13109 +char *str_dup_safe(const char *str)
13110 +{
13111 + return str ? strdup(str) : NULL;
13112 +}
13113 +
13114 Index: busybox-1.4.2/archival/libipkg/str_util.h
13115 ===================================================================
13116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13117 +++ busybox-1.4.2/archival/libipkg/str_util.h 2007-06-04 13:21:36.730392800 +0200
13118 @@ -0,0 +1,28 @@
13119 +/* str_utils.h - the itsy package management system
13120 +
13121 + Carl D. Worth
13122 +
13123 + Copyright (C) 2001 University of Southern California
13124 +
13125 + This program is free software; you can redistribute it and/or
13126 + modify it under the terms of the GNU General Public License as
13127 + published by the Free Software Foundation; either version 2, or (at
13128 + your option) any later version.
13129 +
13130 + This program is distributed in the hope that it will be useful, but
13131 + WITHOUT ANY WARRANTY; without even the implied warranty of
13132 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13133 + General Public License for more details.
13134 +*/
13135 +
13136 +#ifndef STR_UTILS_H
13137 +#define STR_UTILS_H
13138 +
13139 +int str_starts_with(const char *str, const char *prefix);
13140 +int str_ends_with(const char *str, const char *suffix);
13141 +int str_chomp(char *str);
13142 +int str_tolower(char *str);
13143 +int str_toupper(char *str);
13144 +char *str_dup_safe(const char *str);
13145 +
13146 +#endif
13147 Index: busybox-1.4.2/archival/libipkg/user.c
13148 ===================================================================
13149 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13150 +++ busybox-1.4.2/archival/libipkg/user.c 2007-06-04 13:21:36.730392800 +0200
13151 @@ -0,0 +1,58 @@
13152 +/* user.c - the itsy package management system
13153 +
13154 + Jamey Hicks
13155 +
13156 + Copyright (C) 2002 Hewlett Packard Company
13157 + Copyright (C) 2001 University of Southern California
13158 +
13159 + This program is free software; you can redistribute it and/or
13160 + modify it under the terms of the GNU General Public License as
13161 + published by the Free Software Foundation; either version 2, or (at
13162 + your option) any later version.
13163 +
13164 + This program is distributed in the hope that it will be useful, but
13165 + WITHOUT ANY WARRANTY; without even the implied warranty of
13166 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13167 + General Public License for more details.
13168 +*/
13169 +
13170 +#include <stdio.h>
13171 +#include <stdarg.h>
13172 +#include "file_util.h"
13173 +#include "str_util.h"
13174 +#ifdef IPKG_LIB
13175 +#include "libipkg.h"
13176 +#endif
13177 +
13178 +
13179 +#ifdef IPKG_LIB
13180 +static char *question = NULL;
13181 +static int question_len = 255;
13182 +#endif
13183 +char *get_user_response(const char *format, ...)
13184 +{
13185 + int len = question_len;
13186 + va_list ap;
13187 + char *response;
13188 + va_start(ap, format);
13189 +
13190 +#ifndef IPKG_LIB
13191 + vprintf(format, ap);
13192 + do {
13193 + response = file_read_line_alloc(stdin);
13194 + } while (response == NULL);
13195 +#else
13196 + do {
13197 + if (question == NULL || len > question_len) {
13198 + question = realloc(question, len + 1);
13199 + question_len = len;
13200 + }
13201 + len = vsnprintf(question,question_len,format,ap);
13202 + } while (len > question_len);
13203 + response = strdup(ipkg_cb_response(question));
13204 +#endif
13205 + str_chomp(response);
13206 + str_tolower(response);
13207 +
13208 + return response;
13209 +}
13210 Index: busybox-1.4.2/archival/libipkg/user.h
13211 ===================================================================
13212 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13213 +++ busybox-1.4.2/archival/libipkg/user.h 2007-06-04 13:21:36.730392800 +0200
13214 @@ -0,0 +1,23 @@
13215 +/* user.c - the itsy package management system
13216 +
13217 + Jamey Hicks
13218 +
13219 + Copyright (C) 2002 Hewlett Packard Company
13220 + Copyright (C) 2001 University of Southern California
13221 +
13222 + This program is free software; you can redistribute it and/or
13223 + modify it under the terms of the GNU General Public License as
13224 + published by the Free Software Foundation; either version 2, or (at
13225 + your option) any later version.
13226 +
13227 + This program is distributed in the hope that it will be useful, but
13228 + WITHOUT ANY WARRANTY; without even the implied warranty of
13229 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13230 + General Public License for more details.
13231 +*/
13232 +
13233 +#include <stdio.h>
13234 +#include <stdarg.h>
13235 +
13236 +char *get_user_response(const char *format, ...);
13237 +
13238 Index: busybox-1.4.2/archival/libipkg/void_list.c
13239 ===================================================================
13240 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13241 +++ busybox-1.4.2/archival/libipkg/void_list.c 2007-06-04 13:21:36.731392648 +0200
13242 @@ -0,0 +1,194 @@
13243 +/* void_list.c - the itsy package management system
13244 +
13245 + Carl D. Worth
13246 +
13247 + Copyright (C) 2001 University of Southern California
13248 +
13249 + This program is free software; you can redistribute it and/or
13250 + modify it under the terms of the GNU General Public License as
13251 + published by the Free Software Foundation; either version 2, or (at
13252 + your option) any later version.
13253 +
13254 + This program is distributed in the hope that it will be useful, but
13255 + WITHOUT ANY WARRANTY; without even the implied warranty of
13256 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13257 + General Public License for more details.
13258 +*/
13259 +
13260 +#include "ipkg.h"
13261 +#include <errno.h>
13262 +
13263 +#include "void_list.h"
13264 +
13265 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13266 +{
13267 + elt->next = NULL;
13268 + elt->data = data;
13269 +
13270 + return 0;
13271 +}
13272 +
13273 +void void_list_elt_deinit(void_list_elt_t *elt)
13274 +{
13275 + void_list_elt_init(elt, NULL);
13276 +}
13277 +
13278 +int void_list_init(void_list_t *list)
13279 +{
13280 + void_list_elt_init(&list->pre_head, NULL);
13281 + list->head = NULL;
13282 + list->pre_head.next = list->head;
13283 + list->tail = NULL;
13284 +
13285 + return 0;
13286 +}
13287 +
13288 +void void_list_deinit(void_list_t *list)
13289 +{
13290 + void_list_elt_t *elt;
13291 +
13292 + while (list->head) {
13293 + elt = void_list_pop(list);
13294 + void_list_elt_deinit(elt);
13295 + /* malloced in void_list_append */
13296 + free(elt);
13297 + }
13298 +}
13299 +
13300 +int void_list_append(void_list_t *list, void *data)
13301 +{
13302 + void_list_elt_t *elt;
13303 +
13304 + /* freed in void_list_deinit */
13305 + elt = malloc(sizeof(void_list_elt_t));
13306 + if (elt == NULL) {
13307 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13308 + return ENOMEM;
13309 + }
13310 +
13311 + void_list_elt_init(elt, data);
13312 +
13313 + if (list->tail) {
13314 + list->tail->next = elt;
13315 + list->tail = elt;
13316 + } else {
13317 + list->head = elt;
13318 + list->pre_head.next = list->head;
13319 + list->tail = elt;
13320 + }
13321 +
13322 + return 0;
13323 +}
13324 +
13325 +int void_list_push(void_list_t *list, void *data)
13326 +{
13327 + void_list_elt_t *elt;
13328 +
13329 + elt = malloc(sizeof(void_list_elt_t));
13330 + if (elt == NULL) {
13331 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13332 + return ENOMEM;
13333 + }
13334 +
13335 + void_list_elt_init(elt, data);
13336 +
13337 + elt->next = list->head;
13338 + list->head->next = elt;
13339 + if (list->tail == NULL) {
13340 + list->tail = list->head;
13341 + }
13342 +
13343 + return 0;
13344 +}
13345 +
13346 +void_list_elt_t *void_list_pop(void_list_t *list)
13347 +{
13348 + void_list_elt_t *elt;
13349 +
13350 + elt = list->head;
13351 +
13352 + if (list->head) {
13353 + list->head = list->head->next;
13354 + list->pre_head.next = list->head;
13355 + if (list->head == NULL) {
13356 + list->tail = NULL;
13357 + }
13358 + }
13359 +
13360 + return elt;
13361 +}
13362 +
13363 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13364 +{
13365 + void_list_elt_t *prior;
13366 + void_list_elt_t *old_elt;
13367 + void *old_data;
13368 +
13369 + old_elt = *iter;
13370 + old_data = old_elt->data;
13371 +
13372 + if (old_elt == list->head) {
13373 + prior = &list->pre_head;
13374 + void_list_pop(list);
13375 + } else {
13376 + for (prior = list->head; prior; prior = prior->next) {
13377 + if (prior->next == old_elt) {
13378 + break;
13379 + }
13380 + }
13381 + if (prior == NULL || prior->next != old_elt) {
13382 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13383 + return NULL;
13384 + }
13385 + prior->next = old_elt->next;
13386 +
13387 + if (old_elt == list->tail) {
13388 + list->tail = prior;
13389 + }
13390 + }
13391 +
13392 + void_list_elt_deinit(old_elt);
13393 + *iter = prior;
13394 +
13395 + return old_data;
13396 +}
13397 +
13398 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13399 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13400 +{
13401 + void_list_elt_t *prior;
13402 + void_list_elt_t *old_elt = NULL;
13403 + void *old_data = NULL;
13404 +
13405 + /* first element */
13406 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13407 + old_elt = list->head;
13408 + old_data = list->head->data;
13409 + void_list_pop(list);
13410 + } else {
13411 + int found = 0;
13412 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13413 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13414 + old_elt = prior->next;
13415 + old_data = old_elt->data;
13416 + found = 1;
13417 + break;
13418 + }
13419 + }
13420 + if (!found) {
13421 + return NULL;
13422 + }
13423 + prior->next = old_elt->next;
13424 +
13425 + if (old_elt == list->tail) {
13426 + list->tail = prior;
13427 + }
13428 + }
13429 + if (old_elt)
13430 + void_list_elt_deinit(old_elt);
13431 +
13432 + if (old_data)
13433 + return old_data;
13434 + else
13435 + return NULL;
13436 +}
13437 Index: busybox-1.4.2/archival/libipkg/void_list.h
13438 ===================================================================
13439 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13440 +++ busybox-1.4.2/archival/libipkg/void_list.h 2007-06-04 13:21:36.731392648 +0200
13441 @@ -0,0 +1,59 @@
13442 +/* void_list.h - the itsy package management system
13443 +
13444 + Carl D. Worth
13445 +
13446 + Copyright (C) 2001 University of Southern California
13447 +
13448 + This program is free software; you can redistribute it and/or
13449 + modify it under the terms of the GNU General Public License as
13450 + published by the Free Software Foundation; either version 2, or (at
13451 + your option) any later version.
13452 +
13453 + This program is distributed in the hope that it will be useful, but
13454 + WITHOUT ANY WARRANTY; without even the implied warranty of
13455 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13456 + General Public License for more details.
13457 +*/
13458 +
13459 +#ifndef VOID_LIST_H
13460 +#define VOID_LIST_H
13461 +
13462 +typedef struct void_list_elt void_list_elt_t;
13463 +struct void_list_elt
13464 +{
13465 + void_list_elt_t *next;
13466 + void *data;
13467 +};
13468 +
13469 +typedef struct void_list void_list_t;
13470 +struct void_list
13471 +{
13472 + void_list_elt_t pre_head;
13473 + void_list_elt_t *head;
13474 + void_list_elt_t *tail;
13475 +};
13476 +
13477 +static inline int void_list_empty(void_list_t *list)
13478 +{
13479 + if (list->head == NULL)
13480 + return 1;
13481 + else
13482 + return 0;
13483 +}
13484 +
13485 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13486 +void void_list_elt_deinit(void_list_elt_t *elt);
13487 +
13488 +int void_list_init(void_list_t *list);
13489 +void void_list_deinit(void_list_t *list);
13490 +
13491 +int void_list_append(void_list_t *list, void *data);
13492 +int void_list_push(void_list_t *list, void *data);
13493 +void_list_elt_t *void_list_pop(void_list_t *list);
13494 +
13495 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13496 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13497 +typedef int (*void_list_cmp_t)(const void *, const void *);
13498 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13499 +
13500 +#endif
13501 Index: busybox-1.4.2/archival/libipkg/xsystem.c
13502 ===================================================================
13503 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13504 +++ busybox-1.4.2/archival/libipkg/xsystem.c 2007-06-04 13:21:36.731392648 +0200
13505 @@ -0,0 +1,64 @@
13506 +/* xsystem.c - system(3) with error messages
13507 +
13508 + Carl D. Worth
13509 +
13510 + Copyright (C) 2001 University of Southern California
13511 +
13512 + This program is free software; you can redistribute it and/or
13513 + modify it under the terms of the GNU General Public License as
13514 + published by the Free Software Foundation; either version 2, or (at
13515 + your option) any later version.
13516 +
13517 + This program is distributed in the hope that it will be useful, but
13518 + WITHOUT ANY WARRANTY; without even the implied warranty of
13519 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13520 + General Public License for more details.
13521 +*/
13522 +
13523 +#include "ipkg.h"
13524 +#include <sys/wait.h>
13525 +
13526 +#include "xsystem.h"
13527 +
13528 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13529 + really need the /bin/sh invocation which takes resources and
13530 + introduces security problems. I should switch all of this to a sort
13531 + of execl() or execv() interface/implementation.
13532 +*/
13533 +
13534 +/* Like system(3), but with error messages printed if the fork fails
13535 + or if the child process dies due to an uncaught signal. Also, the
13536 + return value is a bit simpler:
13537 +
13538 + -1 if there was any problem
13539 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13540 + as defined in <sys/wait.h>.
13541 +*/
13542 +int xsystem(const char *cmd)
13543 +{
13544 + int err;
13545 +
13546 + err = system(cmd);
13547 +
13548 + if (err == -1) {
13549 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13550 + __FUNCTION__, cmd);
13551 + return -1;
13552 + }
13553 +
13554 + if (WIFSIGNALED(err)) {
13555 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13556 + __FUNCTION__, WTERMSIG(err), cmd);
13557 + return -1;
13558 + }
13559 +
13560 + if (WIFEXITED(err)) {
13561 + /* Normal child exit */
13562 + return WEXITSTATUS(err);
13563 + }
13564 +
13565 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13566 + __FUNCTION__, err);
13567 + return -1;
13568 +}
13569 +
13570 Index: busybox-1.4.2/archival/libipkg/xsystem.h
13571 ===================================================================
13572 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13573 +++ busybox-1.4.2/archival/libipkg/xsystem.h 2007-06-04 13:21:36.731392648 +0200
13574 @@ -0,0 +1,34 @@
13575 +/* xsystem.h - system(3) with error messages
13576 +
13577 + Carl D. Worth
13578 +
13579 + Copyright (C) 2001 University of Southern California
13580 +
13581 + This program is free software; you can redistribute it and/or
13582 + modify it under the terms of the GNU General Public License as
13583 + published by the Free Software Foundation; either version 2, or (at
13584 + your option) any later version.
13585 +
13586 + This program is distributed in the hope that it will be useful, but
13587 + WITHOUT ANY WARRANTY; without even the implied warranty of
13588 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13589 + General Public License for more details.
13590 +*/
13591 +
13592 +#ifndef XSYSTEM_H
13593 +#define XSYSTEM_H
13594 +
13595 +#include <stdlib.h>
13596 +
13597 +/* Like system(3), but with error messages printed if the fork fails
13598 + or if the child process dies due to an uncaught signal. Also, the
13599 + return value is a bit simpler:
13600 +
13601 + -1 if there was any problem
13602 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13603 + as defined in <sys/wait.h>.
13604 +*/
13605 +int xsystem(const char *cmd);
13606 +
13607 +#endif
13608 +
13609 Index: busybox-1.4.2/archival/libunarchive/data_extract_all.c
13610 ===================================================================
13611 --- busybox-1.4.2.orig/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:31.879130304 +0200
13612 +++ busybox-1.4.2/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:36.731392648 +0200
13613 @@ -117,3 +117,17 @@
13614 utime(file_header->name, &t);
13615 }
13616 }
13617 +
13618 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13619 +{
13620 + char *name_ptr = archive_handle->file_header->name;
13621 +
13622 + name_ptr += strspn(name_ptr, "./");
13623 + if (name_ptr[0] != '\0') {
13624 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13625 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13626 + strcat(archive_handle->file_header->name, name_ptr);
13627 + data_extract_all(archive_handle);
13628 + }
13629 +}
13630 +
13631 Index: busybox-1.4.2/archival/libunarchive/Kbuild
13632 ===================================================================
13633 --- busybox-1.4.2.orig/archival/libunarchive/Kbuild 2007-06-04 13:21:31.886129240 +0200
13634 +++ busybox-1.4.2/archival/libunarchive/Kbuild 2007-06-04 13:21:36.732392496 +0200
13635 @@ -47,6 +47,7 @@
13636 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13637 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13638 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13639 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13640 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13641 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13642 lib-$(CONFIG_TAR) += get_header_tar.o
13643 Index: busybox-1.4.2/include/applets.h
13644 ===================================================================
13645 --- busybox-1.4.2.orig/include/applets.h 2007-06-04 13:21:34.786688288 +0200
13646 +++ busybox-1.4.2/include/applets.h 2007-06-04 13:21:36.732392496 +0200
13647 @@ -160,6 +160,7 @@
13648 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13649 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13650 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13651 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13652 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13653 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13654 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13655 Index: busybox-1.4.2/include/unarchive.h
13656 ===================================================================
13657 --- busybox-1.4.2.orig/include/unarchive.h 2007-06-04 13:21:31.897127568 +0200
13658 +++ busybox-1.4.2/include/unarchive.h 2007-06-04 13:21:36.732392496 +0200
13659 @@ -76,6 +76,7 @@
13660
13661 extern void data_skip(archive_handle_t *archive_handle);
13662 extern void data_extract_all(archive_handle_t *archive_handle);
13663 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13664 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13665 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13666
13667 Index: busybox-1.4.2/include/usage.h
13668 ===================================================================
13669 --- busybox-1.4.2.orig/include/usage.h 2007-06-04 13:21:35.005655000 +0200
13670 +++ busybox-1.4.2/include/usage.h 2007-06-04 13:21:36.734392192 +0200
13671 @@ -1133,6 +1133,82 @@
13672 "$ ls -la /tmp/busybox*\n" \
13673 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13674
13675 +#define ipkg_trivial_usage \
13676 + "[options]... sub-command [arguments]..."
13677 +#define ipkg_full_usage \
13678 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13679 + "\n" \
13680 + "Sub-commands:\n" \
13681 + "\nPackage Manipulation:\n" \
13682 + "\tupdate Update list of available packages\n" \
13683 + "\tupgrade Upgrade all installed packages to latest version\n" \
13684 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13685 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13686 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13687 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13688 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13689 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13690 + "\n" \
13691 + "Informational Commands:\n" \
13692 + "\tlist List available packages and descriptions\n" \
13693 + "\tlist_installed List all and only the installed packages and description \n" \
13694 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13695 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13696 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13697 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13698 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13699 + "\tcompare_versions <v1> <op> <v2>\n" \
13700 + "\t compare versions using <= < > >= = << >>\n" \
13701 + "\tprint_architecture prints the architecture.\n" \
13702 + "\tprint_installation_architecture\n" \
13703 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13704 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13705 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13706 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13707 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13708 + "\t prints the installation architecture.\n" \
13709 + "\n" \
13710 + "\nOptions:\n" \
13711 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13712 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13713 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13714 + "\t 0 errors only\n" \
13715 + "\t 1 normal messages (default)\n" \
13716 + "\t 2 informative messages\n" \
13717 + "\t 3 debug output\n" \
13718 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13719 + "\t-conf <conf_file> Default configuration file location\n" \
13720 + " is /etc/ipkg.conf\n" \
13721 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13722 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13723 + " <dest_name> should be a defined dest name from\n" \
13724 + " the configuration file, (but can also be a\n" \
13725 + " directory name in a pinch).\n" \
13726 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13727 + "\t-offline <offline_root> offline installation of packages.\n" \
13728 + "\t-verbose_wget more wget messages\n" \
13729 + "\n" \
13730 + "Force Options (use when ipkg is too smart for its own good):\n" \
13731 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13732 + "\t Install/remove package in spite of failed dependences\n" \
13733 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13734 + " (no prompts). Note that this will not prevent\n" \
13735 + " package installation scripts from prompting.\n" \
13736 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13737 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13738 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13739 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13740 + "\t-noaction No action -- test only\n" \
13741 + "\t-nodeps Do not follow dependences\n" \
13742 + "\t-force-removal-of-dependent-packages\n" \
13743 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13744 + "\t-test No action -- test only\n" \
13745 + "\t-t Specify tmp-dir.\n" \
13746 + "\t--tmp-dir Specify tmp-dir.\n" \
13747 + "\n" \
13748 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13749 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13750 +
13751 #define halt_trivial_usage \
13752 "[-d<delay>] [-n<nosync>] [-f<force>]"
13753 #define halt_full_usage \
13754 Index: busybox-1.4.2/Makefile
13755 ===================================================================
13756 --- busybox-1.4.2.orig/Makefile 2007-06-04 13:21:31.910125592 +0200
13757 +++ busybox-1.4.2/Makefile 2007-06-04 13:21:36.734392192 +0200
13758 @@ -423,6 +423,7 @@
13759
13760 libs-y := \
13761 archival/ \
13762 + archival/libipkg/ \
13763 archival/libunarchive/ \
13764 console-tools/ \
13765 coreutils/ \
This page took 0.688373 seconds and 5 git commands to generate.