don't try to use gnu wget specific options in ipkg
[openwrt.git] / package / busybox / patches / 911-ipkg.patch
1 # Copyright (C) 2006 OpenWrt.org
2 #
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5 #
6 # add ipkg support to busybox
7 #
8 diff -ruN busybox-1.2.0-orig/archival/Config.in busybox-1.2.0+ipkg-0.99.162/archival/Config.in
9 --- busybox-1.2.0-orig/archival/Config.in 2006-07-01 00:42:04.000000000 +0200
10 +++ busybox-1.2.0+ipkg-0.99.162/archival/Config.in 2006-07-22 16:31:25.000000000 +0200
11 @@ -121,6 +121,14 @@
12 gzip is used to compress files.
13 It's probably the most widely used UNIX compression program.
14
15 +config CONFIG_IPKG
16 + bool "ipkg"
17 + default n
18 + select CONFIG_MD5SUM
19 + select CONFIG_WGET
20 + help
21 + ipkg is the itsy package management system.
22 +
23 config CONFIG_RPM2CPIO
24 bool "rpm2cpio"
25 default n
26 diff -ruN busybox-1.2.0-orig/archival/dpkg.c busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c
27 --- busybox-1.2.0-orig/archival/dpkg.c 2006-07-01 00:42:04.000000000 +0200
28 +++ busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c 2006-07-22 16:31:25.000000000 +0200
29 @@ -1430,6 +1430,10 @@
30 return(ar_handle->sub_archive->buffer);
31 }
32
33 +/*
34 +
35 +// moved to data_extract_all.c
36 +
37 static void data_extract_all_prefix(archive_handle_t *archive_handle)
38 {
39 char *name_ptr = archive_handle->file_header->name;
40 @@ -1442,6 +1446,8 @@
41 return;
42 }
43
44 +*/
45 +
46 static void unpack_package(deb_file_t *deb_file)
47 {
48 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
49 diff -ruN busybox-1.2.0-orig/archival/ipkg.c busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c
50 --- busybox-1.2.0-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
51 +++ busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c 2006-07-22 16:31:25.000000000 +0200
52 @@ -0,0 +1,26 @@
53 +/* ipkg.c - the itsy package management system
54 +
55 + Florina Boor
56 +
57 + Copyright (C) 2003 kernel concepts
58 +
59 + This program is free software; you can redistribute it and/or
60 + modify it under the terms of the GNU General Public License as
61 + published by the Free Software Foundation; either version 2, or (at
62 + your option) any later version.
63 +
64 + This program is distributed in the hope that it will be useful, but
65 + WITHOUT ANY WARRANTY; without even the implied warranty of
66 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67 + General Public License for more details.
68 +
69 + ipkg command line frontend using libipkg
70 +
71 +*/
72 +
73 +#include "libipkg/libipkg.h"
74 +
75 +int ipkg_main(int argc, char **argv)
76 +{
77 + return ipkg_op(argc, argv);
78 +}
79 diff -ruN busybox-1.2.0-orig/archival/libipkg/args.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c
80 --- busybox-1.2.0-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
81 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c 2006-07-22 16:31:25.000000000 +0200
82 @@ -0,0 +1,242 @@
83 +/* args.c - parse command-line args
84 +
85 + Carl D. Worth
86 +
87 + Copyright 2001 University of Southern California
88 +
89 + This program is free software; you can redistribute it and/or modify
90 + it under the terms of the GNU General Public License as published by
91 + the Free Software Foundation; either version 2, or (at your option)
92 + any later version.
93 +
94 + This program is distributed in the hope that it will be useful,
95 + but WITHOUT ANY WARRANTY; without even the implied warranty of
96 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 + GNU General Public License for more details.
98 + */
99 +
100 +#include <getopt.h>
101 +#include <stdlib.h>
102 +#include <string.h>
103 +#include <unistd.h>
104 +
105 +#include "ipkg.h"
106 +#include "ipkg_message.h"
107 +
108 +#include "args.h"
109 +#include "sprintf_alloc.h"
110 +
111 +#include "libbb.h"
112 +
113 +
114 +static void print_version(void);
115 +
116 +enum long_args_opt
117 +{
118 + ARGS_OPT_FORCE_DEFAULTS = 129,
119 + ARGS_OPT_FORCE_DEPENDS,
120 + ARGS_OPT_FORCE_OVERWRITE,
121 + ARGS_OPT_FORCE_DOWNGRADE,
122 + ARGS_OPT_FORCE_REINSTALL,
123 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
124 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
125 + ARGS_OPT_FORCE_SPACE,
126 + ARGS_OPT_NOACTION,
127 + ARGS_OPT_NODEPS,
128 + ARGS_OPT_VERBOSE_WGET,
129 + ARGS_OPT_VERBOSITY,
130 + ARGS_OPT_MULTIPLE_PROVIDERS
131 +};
132 +
133 +int args_init(args_t *args)
134 +{
135 + char *conf_file_dir;
136 +
137 + memset(args, 0, sizeof(args_t));
138 +
139 + args->dest = ARGS_DEFAULT_DEST;
140 +
141 + conf_file_dir = getenv("IPKG_CONF_DIR");
142 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
143 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
144 + }
145 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
146 + ARGS_DEFAULT_CONF_FILE_NAME);
147 +
148 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
149 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
150 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
151 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
152 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
153 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
154 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
155 + args->noaction = ARGS_DEFAULT_NOACTION;
156 + args->nodeps = ARGS_DEFAULT_NODEPS;
157 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
158 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
159 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
160 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
161 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
162 + args->multiple_providers = 0;
163 + args->nocheckfordirorfile = 0;
164 + args->noreadfeedsfile = 0;
165 +
166 + return 1;
167 +}
168 +
169 +void args_deinit(args_t *args)
170 +{
171 + free(args->conf_file);
172 + args->conf_file = NULL;
173 +}
174 +
175 +int args_parse(args_t *args, int argc, char *argv[])
176 +{
177 + int c;
178 + int option_index = 0;
179 + int parse_err = 0;
180 + static struct option long_options[] = {
181 + {"query-all", 0, 0, 'A'},
182 + {"conf-file", 1, 0, 'f'},
183 + {"conf", 1, 0, 'f'},
184 + {"dest", 1, 0, 'd'},
185 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
186 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
187 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
188 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
189 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
190 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
191 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
192 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
193 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
194 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
195 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
196 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
197 + {"recursive", 0, 0,
198 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
199 + {"force-removal-of-dependent-packages", 0, 0,
200 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
201 + {"force_removal_of_dependent_packages", 0, 0,
202 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
203 + {"force-removal-of-essential-packages", 0, 0,
204 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
205 + {"force_removal_of_essential_packages", 0, 0,
206 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
207 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
208 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
209 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
210 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
211 + {"offline", 1, 0, 'o'},
212 + {"offline-root", 1, 0, 'o'},
213 + {"test", 0, 0, ARGS_OPT_NOACTION},
214 + {"tmp-dir", 1, 0, 't'},
215 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
216 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
217 + {"verbosity", 2, 0, 'V'},
218 + {"version", 0, 0, 'v'},
219 + {0, 0, 0, 0}
220 + };
221 +
222 + while (1) {
223 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
224 + if (c == -1)
225 + break;
226 +
227 + switch (c) {
228 + case 'A':
229 + args->query_all = 1;
230 + break;
231 + case 'd':
232 + args->dest = optarg;
233 + break;
234 + case 'f':
235 + free(args->conf_file);
236 + args->conf_file = strdup(optarg);
237 + break;
238 + case 'o':
239 + args->offline_root = optarg;
240 + break;
241 + case 'n':
242 + args->noaction = 1;
243 + break;
244 + case 't':
245 + args->tmp_dir = strdup(optarg);
246 + break;
247 + case 'v':
248 + print_version();
249 + exit(0);
250 + case 'V':
251 + case ARGS_OPT_VERBOSITY:
252 + if (optarg)
253 + args->verbosity = atoi(optarg);
254 + else
255 + args->verbosity += 1;
256 + break;
257 + case ARGS_OPT_FORCE_DEFAULTS:
258 + args->force_defaults = 1;
259 + break;
260 + case ARGS_OPT_FORCE_DEPENDS:
261 + args->force_depends = 1;
262 + break;
263 + case ARGS_OPT_FORCE_OVERWRITE:
264 + args->force_overwrite = 1;
265 + break;
266 + case ARGS_OPT_FORCE_DOWNGRADE:
267 + args->force_downgrade = 1;
268 + break;
269 + case ARGS_OPT_FORCE_REINSTALL:
270 + args->force_reinstall = 1;
271 + break;
272 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
273 + args->force_removal_of_essential_packages = 1;
274 + break;
275 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
276 + args->force_removal_of_dependent_packages = 1;
277 + break;
278 + case ARGS_OPT_FORCE_SPACE:
279 + args->force_space = 1;
280 + break;
281 + case ARGS_OPT_VERBOSE_WGET:
282 + args->verbose_wget = 1;
283 + break;
284 + case ARGS_OPT_MULTIPLE_PROVIDERS:
285 + args->multiple_providers = 1;
286 + break;
287 + case ARGS_OPT_NODEPS:
288 + args->nodeps = 1;
289 + break;
290 + case ARGS_OPT_NOACTION:
291 + args->noaction = 1;
292 + break;
293 + case ':':
294 + parse_err++;
295 + break;
296 + case '?':
297 + parse_err++;
298 + break;
299 + default:
300 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
301 + }
302 + }
303 +
304 + if (parse_err) {
305 + return -parse_err;
306 + } else {
307 + return optind;
308 + }
309 +}
310 +
311 +void args_usage(char *complaint)
312 +{
313 + if (complaint) {
314 + bb_error_msg("%s\n", complaint);
315 + }
316 + print_version();
317 + bb_show_usage();
318 + exit(1);
319 +}
320 +
321 +static void print_version(void)
322 +{
323 + bb_error_msg("version %s\n", IPKG_VERSION);
324 +}
325 diff -ruN busybox-1.2.0-orig/archival/libipkg/args.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h
326 --- busybox-1.2.0-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
327 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h 2006-07-22 16:31:25.000000000 +0200
328 @@ -0,0 +1,72 @@
329 +/* args.h - parse command-line args
330 +
331 + Carl D. Worth
332 +
333 + Copyright 2001 University of Southern California
334 +
335 + This program is free software; you can redistribute it and/or modify
336 + it under the terms of the GNU General Public License as published by
337 + the Free Software Foundation; either version 2, or (at your option)
338 + any later version.
339 +
340 + This program is distributed in the hope that it will be useful,
341 + but WITHOUT ANY WARRANTY; without even the implied warranty of
342 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343 + GNU General Public License for more details.
344 +*/
345 +
346 +#ifndef ARGS_H
347 +#define ARGS_H
348 +
349 +struct args
350 +{
351 + char *conf_file;
352 + char *dest;
353 + char *tmp_dir;
354 + int force_defaults;
355 + int force_depends;
356 + int force_overwrite;
357 + int force_downgrade;
358 + int force_reinstall;
359 + int force_removal_of_essential_packages;
360 + int force_removal_of_dependent_packages;
361 + int force_space;
362 + int noaction;
363 + int nodeps;
364 + int multiple_providers;
365 + int query_all;
366 + int verbose_wget;
367 + int verbosity;
368 + int nocheckfordirorfile;
369 + int noreadfeedsfile;
370 + char *offline_root;
371 + char *offline_root_pre_script_cmd;
372 + char *offline_root_post_script_cmd;
373 +};
374 +typedef struct args args_t;
375 +
376 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
377 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
378 +#define ARGS_DEFAULT_DEST NULL
379 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
380 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
381 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
382 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
383 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
384 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
385 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
386 +#define ARGS_DEFAULT_FORCE_SPACE 0
387 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
388 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
389 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
390 +#define ARGS_DEFAULT_NOACTION 0
391 +#define ARGS_DEFAULT_NODEPS 0
392 +#define ARGS_DEFAULT_VERBOSE_WGET 0
393 +#define ARGS_DEFAULT_VERBOSITY 1
394 +
395 +int args_init(args_t *args);
396 +void args_deinit(args_t *args);
397 +int args_parse(args_t *args, int argc, char *argv[]);
398 +void args_usage(char *complaint);
399 +
400 +#endif
401 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c
402 --- busybox-1.2.0-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
403 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c 2006-07-22 16:31:25.000000000 +0200
404 @@ -0,0 +1,64 @@
405 +/* conffile.c - the itsy package management system
406 +
407 + Carl D. Worth
408 +
409 + Copyright (C) 2001 University of Southern California
410 +
411 + This program is free software; you can redistribute it and/or
412 + modify it under the terms of the GNU General Public License as
413 + published by the Free Software Foundation; either version 2, or (at
414 + your option) any later version.
415 +
416 + This program is distributed in the hope that it will be useful, but
417 + WITHOUT ANY WARRANTY; without even the implied warranty of
418 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
419 + General Public License for more details.
420 +*/
421 +
422 +#include <string.h>
423 +#include <stdlib.h>
424 +
425 +#include "ipkg.h"
426 +#include "ipkg_message.h"
427 +
428 +#include "conffile.h"
429 +#include "file_util.h"
430 +#include "sprintf_alloc.h"
431 +
432 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
433 +{
434 + return nv_pair_init(conffile, file_name, md5sum);
435 +}
436 +
437 +void conffile_deinit(conffile_t *conffile)
438 +{
439 + nv_pair_deinit(conffile);
440 +}
441 +
442 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
443 +{
444 + char *md5sum;
445 + char *filename = conffile->name;
446 + char *root_filename;
447 + int ret;
448 +
449 + if (conffile->value == NULL) {
450 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
451 + return 1;
452 + }
453 +
454 + root_filename = root_filename_alloc(conf, filename);
455 +
456 + md5sum = file_md5sum_alloc(root_filename);
457 +
458 + ret = strcmp(md5sum, conffile->value);
459 + if (ret) {
460 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
461 + conffile->name, md5sum, conffile->value);
462 + }
463 +
464 + free(root_filename);
465 + free(md5sum);
466 +
467 + return ret;
468 +}
469 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h
470 --- busybox-1.2.0-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
471 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h 2006-07-22 16:31:25.000000000 +0200
472 @@ -0,0 +1,30 @@
473 +/* conffile.h - the itsy package management system
474 +
475 + Carl D. Worth
476 +
477 + Copyright (C) 2001 University of Southern California
478 +
479 + This program is free software; you can redistribute it and/or
480 + modify it under the terms of the GNU General Public License as
481 + published by the Free Software Foundation; either version 2, or (at
482 + your option) any later version.
483 +
484 + This program is distributed in the hope that it will be useful, but
485 + WITHOUT ANY WARRANTY; without even the implied warranty of
486 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
487 + General Public License for more details.
488 +*/
489 +
490 +#ifndef CONFFILE_H
491 +#define CONFFILE_H
492 +
493 +#include "nv_pair.h"
494 +
495 +typedef struct nv_pair conffile_t;
496 +
497 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
498 +void conffile_deinit(conffile_t *conffile);
499 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
500 +
501 +#endif
502 +
503 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.c
504 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
505 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.c 2006-07-22 16:31:25.000000000 +0200
506 @@ -0,0 +1,47 @@
507 +/* conffile_list.c - the itsy package management system
508 +
509 + Carl D. Worth
510 +
511 + Copyright (C) 2001 University of Southern California
512 +
513 + This program is free software; you can redistribute it and/or
514 + modify it under the terms of the GNU General Public License as
515 + published by the Free Software Foundation; either version 2, or (at
516 + your option) any later version.
517 +
518 + This program is distributed in the hope that it will be useful, but
519 + WITHOUT ANY WARRANTY; without even the implied warranty of
520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
521 + General Public License for more details.
522 +*/
523 +
524 +#include "ipkg.h"
525 +
526 +#include "conffile_list.h"
527 +
528 +int conffile_list_init(conffile_list_t *list)
529 +{
530 + return nv_pair_list_init(list);
531 +}
532 +
533 +void conffile_list_deinit(conffile_list_t *list)
534 +{
535 + nv_pair_list_deinit(list);
536 +}
537 +
538 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
539 + const char *md5sum)
540 +{
541 + return nv_pair_list_append(list, file_name, md5sum);
542 +}
543 +
544 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
545 +{
546 + return nv_pair_list_push(list, data);
547 +}
548 +
549 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
550 +{
551 + return nv_pair_list_pop(list);
552 +}
553 +
554 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.h
555 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
556 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.h 2006-07-22 16:31:25.000000000 +0200
557 @@ -0,0 +1,36 @@
558 +/* conffile_list.h - the itsy package management system
559 +
560 + Carl D. Worth
561 +
562 + Copyright (C) 2001 University of Southern California
563 +
564 + This program is free software; you can redistribute it and/or
565 + modify it under the terms of the GNU General Public License as
566 + published by the Free Software Foundation; either version 2, or (at
567 + your option) any later version.
568 +
569 + This program is distributed in the hope that it will be useful, but
570 + WITHOUT ANY WARRANTY; without even the implied warranty of
571 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
572 + General Public License for more details.
573 +*/
574 +
575 +#ifndef CONFFILE_LIST_H
576 +#define CONFFILE_LIST_H
577 +
578 +#include "conffile.h"
579 +#include "nv_pair_list.h"
580 +
581 +typedef struct nv_pair_list_elt conffile_list_elt_t;
582 +typedef struct nv_pair_list conffile_list_t;
583 +
584 +int conffile_list_init(conffile_list_t *list);
585 +void conffile_list_deinit(conffile_list_t *list);
586 +
587 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
588 + const char *root_dir);
589 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
590 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
591 +
592 +#endif
593 +
594 diff -ruN busybox-1.2.0-orig/archival/libipkg/file_util.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.c
595 --- busybox-1.2.0-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
596 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.c 2006-07-22 16:31:25.000000000 +0200
597 @@ -0,0 +1,177 @@
598 +/* file_util.c - convenience routines for common stat operations
599 +
600 + Carl D. Worth
601 +
602 + Copyright (C) 2001 University of Southern California
603 +
604 + This program is free software; you can redistribute it and/or
605 + modify it under the terms of the GNU General Public License as
606 + published by the Free Software Foundation; either version 2, or (at
607 + your option) any later version.
608 +
609 + This program is distributed in the hope that it will be useful, but
610 + WITHOUT ANY WARRANTY; without even the implied warranty of
611 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
612 + General Public License for more details.
613 +*/
614 +
615 +#include "ipkg.h"
616 +#include <sys/types.h>
617 +#include <sys/stat.h>
618 +
619 +#include "sprintf_alloc.h"
620 +#include "file_util.h"
621 +#include "md5.h"
622 +#include "libbb.h"
623 +#undef strlen
624 +
625 +int file_exists(const char *file_name)
626 +{
627 + int err;
628 + struct stat stat_buf;
629 +
630 + err = stat(file_name, &stat_buf);
631 + if (err == 0) {
632 + return 1;
633 + } else {
634 + return 0;
635 + }
636 +}
637 +
638 +int file_is_dir(const char *file_name)
639 +{
640 + int err;
641 + struct stat stat_buf;
642 +
643 + err = stat(file_name, &stat_buf);
644 + if (err) {
645 + return 0;
646 + }
647 +
648 + return S_ISDIR(stat_buf.st_mode);
649 +}
650 +
651 +/* read a single line from a file, stopping at a newline or EOF.
652 + If a newline is read, it will appear in the resulting string.
653 + Return value is a malloc'ed char * which should be freed at
654 + some point by the caller.
655 +
656 + Return value is NULL if the file is at EOF when called.
657 +*/
658 +#define FILE_READ_LINE_BUF_SIZE 1024
659 +char *file_read_line_alloc(FILE *file)
660 +{
661 + char buf[FILE_READ_LINE_BUF_SIZE];
662 + int buf_len;
663 + char *line = NULL;
664 + int line_size = 0;
665 +
666 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
667 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
668 + buf_len = strlen(buf);
669 + if (line) {
670 + line_size += buf_len;
671 + line = realloc(line, line_size);
672 + if (line == NULL) {
673 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
674 + break;
675 + }
676 + strcat(line, buf);
677 + } else {
678 + line_size = buf_len + 1;
679 + line = strdup(buf);
680 + }
681 + if (buf[buf_len - 1] == '\n') {
682 + break;
683 + }
684 + }
685 +
686 + return line;
687 +}
688 +
689 +int file_move(const char *src, const char *dest)
690 +{
691 + int err;
692 +
693 + err = rename(src, dest);
694 +
695 + if (err && errno == EXDEV) {
696 + err = file_copy(src, dest);
697 + unlink(src);
698 + } else if (err) {
699 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
700 + __FUNCTION__, src, dest, strerror(errno));
701 + }
702 +
703 + return err;
704 +}
705 +
706 +/* I put these here to keep libbb dependencies from creeping all over
707 + the ipkg code */
708 +int file_copy(const char *src, const char *dest)
709 +{
710 + int err;
711 +
712 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
713 + if (err) {
714 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
715 + __FUNCTION__, src, dest);
716 + }
717 +
718 + return err;
719 +}
720 +
721 +int file_mkdir_hier(const char *path, long mode)
722 +{
723 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
724 +}
725 +
726 +char *file_md5sum_alloc(const char *file_name)
727 +{
728 + static const int md5sum_bin_len = 16;
729 + static const int md5sum_hex_len = 32;
730 +
731 + static const unsigned char bin2hex[16] = {
732 + '0', '1', '2', '3',
733 + '4', '5', '6', '7',
734 + '8', '9', 'a', 'b',
735 + 'c', 'd', 'e', 'f'
736 + };
737 +
738 + int i, err;
739 + FILE *file;
740 + unsigned char *md5sum_hex;
741 + unsigned char md5sum_bin[md5sum_bin_len];
742 +
743 + md5sum_hex = malloc(md5sum_hex_len + 1);
744 + if (md5sum_hex == NULL) {
745 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
746 + return strdup("");
747 + }
748 +
749 + file = fopen(file_name, "r");
750 + if (file == NULL) {
751 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
752 + __FUNCTION__, file_name, strerror(errno));
753 + return strdup("");
754 + }
755 +
756 + err = md5_stream(file, md5sum_bin);
757 + if (err) {
758 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
759 + __FUNCTION__, file_name, strerror(err));
760 + return strdup("");
761 + }
762 +
763 + fclose(file);
764 +
765 + for (i=0; i < md5sum_bin_len; i++) {
766 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
767 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
768 + }
769 +
770 + md5sum_hex[md5sum_hex_len] = '\0';
771 +
772 + return md5sum_hex;
773 +}
774 +
775 diff -ruN busybox-1.2.0-orig/archival/libipkg/file_util.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.h
776 --- busybox-1.2.0-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
777 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.h 2006-07-22 16:31:25.000000000 +0200
778 @@ -0,0 +1,29 @@
779 +/* file_util.h - convenience routines for common file operations
780 +
781 + Carl D. Worth
782 +
783 + Copyright (C) 2001 University of Southern California
784 +
785 + This program is free software; you can redistribute it and/or
786 + modify it under the terms of the GNU General Public License as
787 + published by the Free Software Foundation; either version 2, or (at
788 + your option) any later version.
789 +
790 + This program is distributed in the hope that it will be useful, but
791 + WITHOUT ANY WARRANTY; without even the implied warranty of
792 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
793 + General Public License for more details.
794 +*/
795 +
796 +#ifndef FILE_UTIL_H
797 +#define FILE_UTIL_H
798 +
799 +int file_exists(const char *file_name);
800 +int file_is_dir(const char *file_name);
801 +char *file_read_line_alloc(FILE *file);
802 +int file_move(const char *src, const char *dest);
803 +int file_copy(const char *src, const char *dest);
804 +int file_mkdir_hier(const char *path, long mode);
805 +char *file_md5sum_alloc(const char *file_name);
806 +
807 +#endif
808 diff -ruN busybox-1.2.0-orig/archival/libipkg/hash_table.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.c
809 --- busybox-1.2.0-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
810 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.c 2006-07-22 16:31:25.000000000 +0200
811 @@ -0,0 +1,155 @@
812 +/* hash.c - hash tables for ipkg
813 +
814 + Steven M. Ayer, Jamey Hicks
815 +
816 + Copyright (C) 2002 Compaq Computer Corporation
817 +
818 + This program is free software; you can redistribute it and/or
819 + modify it under the terms of the GNU General Public License as
820 + published by the Free Software Foundation; either version 2, or (at
821 + your option) any later version.
822 +
823 + This program is distributed in the hope that it will be useful, but
824 + WITHOUT ANY WARRANTY; without even the implied warranty of
825 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
826 + General Public License for more details.
827 +*/
828 +
829 +#include <errno.h>
830 +#include <stdio.h>
831 +#include <stdlib.h>
832 +#include <string.h>
833 +#include "hash_table.h"
834 +#include "ipkg_message.h"
835 +
836 +
837 +static int hash_index(hash_table_t *hash, const char *pkg_name);
838 +static int rotating(const char *key, int len, int prime);
839 +
840 +static int hash_index(hash_table_t *hash, const char *pkg_name)
841 +{
842 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
843 +}
844 +
845 +static int rotating(const char *key, int len, int prime)
846 +{
847 + unsigned int hash, i;
848 + for (hash=len, i=0; i<len; ++i)
849 + hash = (hash<<4)^(hash>>28)^key[i];
850 + return (hash % prime);
851 +}
852 +
853 +
854 +/*
855 + * this is an open table keyed by strings
856 + */
857 +int hash_table_init(const char *name, hash_table_t *hash, int len)
858 +{
859 + static int primes_table[] = {
860 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
861 + 19471, 23143, 33961, 46499, 49727, 99529, 0
862 + };
863 + int *picker;
864 +
865 + if (hash->entries != NULL) {
866 + /* we have been here already */
867 + return 0;
868 + }
869 +
870 + hash->name = name;
871 + hash->entries = NULL;
872 + hash->n_entries = 0;
873 + hash->hash_entry_key = NULL;
874 +
875 + picker = primes_table;
876 + while(*picker && (*picker++ < len));
877 + if(!*picker)
878 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
879 + --picker;
880 +
881 + hash->n_entries = *picker;
882 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
883 + if (hash->entries == NULL) {
884 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
885 + return ENOMEM;
886 + }
887 + return 0;
888 +}
889 +
890 +void hash_table_deinit(hash_table_t *hash)
891 +{
892 + free(hash->entries);
893 + hash->entries = NULL;
894 + hash->n_entries = 0;
895 +}
896 +
897 +void *hash_table_get(hash_table_t *hash, const char *key)
898 +{
899 + int ndx= hash_index(hash, key);
900 + hash_entry_t *hash_entry = hash->entries + ndx;
901 + while (hash_entry)
902 + {
903 + if (hash_entry->key)
904 + {
905 + if (strcmp(key, hash_entry->key) == 0) {
906 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
907 + return hash_entry->data;
908 + }
909 + }
910 + hash_entry = hash_entry->next;
911 + }
912 + return NULL;
913 +}
914 +
915 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
916 +{
917 + int ndx= hash_index(hash, key);
918 + hash_entry_t *hash_entry = hash->entries + ndx;
919 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
920 + if (hash_entry->key) {
921 + if (strcmp(hash_entry->key, key) == 0) {
922 + /* alread in table, update the value */
923 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
924 + hash_entry->data = value;
925 + return 0;
926 + } else {
927 + /*
928 + * if this is a collision, we have to go to the end of the ll,
929 + * then add a new entry
930 + * before we can hook up the value
931 + */
932 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
933 + while (hash_entry->next)
934 + hash_entry = hash_entry->next;
935 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
936 + if (!hash_entry->next) {
937 + return -ENOMEM;
938 + }
939 + hash_entry = hash_entry->next;
940 + hash_entry->next = NULL;
941 + }
942 + }
943 + hash->n_elements++;
944 + hash_entry->key = strdup(key);
945 + hash_entry->data = value;
946 +
947 + return 0;
948 +}
949 +
950 +
951 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
952 +{
953 + int i;
954 + if (!hash || !f)
955 + return;
956 +
957 + for (i = 0; i < hash->n_entries; i++) {
958 + hash_entry_t *hash_entry = (hash->entries + i);
959 + do {
960 + if(hash_entry->key) {
961 + f(hash_entry->key, hash_entry->data, data);
962 + }
963 + } while((hash_entry = hash_entry->next));
964 + }
965 +}
966 +
967 diff -ruN busybox-1.2.0-orig/archival/libipkg/hash_table.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.h
968 --- busybox-1.2.0-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
969 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.h 2006-07-22 16:31:25.000000000 +0200
970 @@ -0,0 +1,44 @@
971 +/* hash.h - hash tables for ipkg
972 +
973 + Steven M. Ayer, Jamey Hicks
974 +
975 + Copyright (C) 2002 Compaq Computer Corporation
976 +
977 + This program is free software; you can redistribute it and/or
978 + modify it under the terms of the GNU General Public License as
979 + published by the Free Software Foundation; either version 2, or (at
980 + your option) any later version.
981 +
982 + This program is distributed in the hope that it will be useful, but
983 + WITHOUT ANY WARRANTY; without even the implied warranty of
984 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
985 + General Public License for more details.
986 +*/
987 +
988 +#ifndef _HASH_TABLE_H_
989 +#define _HASH_TABLE_H_
990 +
991 +typedef struct hash_entry hash_entry_t;
992 +typedef struct hash_table hash_table_t;
993 +
994 +struct hash_entry {
995 + const char * key;
996 + void * data;
997 + struct hash_entry * next;
998 +};
999 +
1000 +struct hash_table {
1001 + const char *name;
1002 + hash_entry_t * entries;
1003 + int n_entries; /* number of buckets */
1004 + int n_elements;
1005 + const char * (*hash_entry_key)(void * data);
1006 +};
1007 +
1008 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1009 +void hash_table_deinit(hash_table_t *hash);
1010 +void *hash_table_get(hash_table_t *hash, const char *key);
1011 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1012 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1013 +
1014 +#endif /* _HASH_TABLE_H_ */
1015 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c
1016 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1017 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c 2006-07-22 16:31:25.000000000 +0200
1018 @@ -0,0 +1,1431 @@
1019 +/* ipkg_cmd.c - the itsy package management system
1020 +
1021 + Carl D. Worth
1022 +
1023 + Copyright (C) 2001 University of Southern California
1024 +
1025 + This program is free software; you can redistribute it and/or
1026 + modify it under the terms of the GNU General Public License as
1027 + published by the Free Software Foundation; either version 2, or (at
1028 + your option) any later version.
1029 +
1030 + This program is distributed in the hope that it will be useful, but
1031 + WITHOUT ANY WARRANTY; without even the implied warranty of
1032 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1033 + General Public License for more details.
1034 +*/
1035 +
1036 +#include <string.h>
1037 +
1038 +#include "ipkg.h"
1039 +#include <libgen.h>
1040 +#include <glob.h>
1041 +#include <errno.h>
1042 +#include <stdlib.h>
1043 +#include <unistd.h>
1044 +#include <signal.h>
1045 +#include <stdio.h>
1046 +#include <dirent.h>
1047 +
1048 +#include "ipkg_conf.h"
1049 +#include "ipkg_cmd.h"
1050 +#include "ipkg_message.h"
1051 +#include "pkg.h"
1052 +#include "pkg_dest.h"
1053 +#include "pkg_parse.h"
1054 +#include "sprintf_alloc.h"
1055 +#include "pkg.h"
1056 +#include "file_util.h"
1057 +#include "str_util.h"
1058 +#include "libbb.h"
1059 +#include "unarchive.h"
1060 +
1061 +#include <fnmatch.h>
1062 +
1063 +
1064 +#include "ipkg_download.h"
1065 +#include "ipkg_install.h"
1066 +#include "ipkg_upgrade.h"
1067 +#include "ipkg_remove.h"
1068 +#include "ipkg_configure.h"
1069 +#include "ipkg_message.h"
1070 +
1071 +#ifdef IPKG_LIB
1072 +#include "libipkg.h"
1073 +static void *p_userdata = NULL;
1074 +#endif
1075 +
1076 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1077 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1078 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1079 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1080 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1081 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1082 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1083 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1084 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1085 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1086 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1087 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1088 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1089 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1090 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1091 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1092 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1093 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1094 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1095 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1096 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1097 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1098 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1099 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1100 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1101 +
1102 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1103 + array for easier maintenance */
1104 +static ipkg_cmd_t cmds[] = {
1105 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1106 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1107 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1108 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1109 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1110 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1111 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1112 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1113 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1114 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1115 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1116 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1117 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1118 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1119 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1120 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1121 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1122 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1123 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1124 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1125 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1126 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1127 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1128 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1129 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1130 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1131 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1132 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1133 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1134 +};
1135 +
1136 +int ipkg_state_changed;
1137 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1138 +{
1139 + if (ipkg_state_changed && !conf->noaction) {
1140 + ipkg_message(conf, IPKG_INFO,
1141 + " writing status file\n");
1142 + ipkg_conf_write_status_files(conf);
1143 + pkg_write_changed_filelists(conf);
1144 + } else {
1145 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1146 + }
1147 +}
1148 +
1149 +
1150 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1151 +
1152 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1153 +{
1154 + int i;
1155 + ipkg_cmd_t *cmd;
1156 +
1157 + for (i=0; i < num_cmds; i++) {
1158 + cmd = &cmds[i];
1159 + if (strcmp(name, cmd->name) == 0) {
1160 + return cmd;
1161 + }
1162 + }
1163 +
1164 + return NULL;
1165 +}
1166 +
1167 +#ifdef IPKG_LIB
1168 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1169 +{
1170 + int result;
1171 + p_userdata = userdata;
1172 +
1173 +
1174 + result = (cmd->fun)(conf, argc, argv);
1175 + if ( result == 0 ) {
1176 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1177 + } else {
1178 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1179 +
1180 + }
1181 + if ( error_list ) {
1182 + reverse_error_list(&error_list);
1183 +
1184 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1185 + /* Here we print the errors collected and free the list */
1186 + while (error_list != NULL) {
1187 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1188 + error_list = error_list->next;
1189 +
1190 + }
1191 + free_error_list(&error_list);
1192 +
1193 + }
1194 +
1195 + p_userdata = NULL;
1196 + return result;
1197 +}
1198 +#else
1199 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1200 +{
1201 + return (cmd->fun)(conf, argc, argv);
1202 +}
1203 +#endif
1204 +
1205 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1206 +{
1207 + int err;
1208 + int failures;
1209 + char *lists_dir;
1210 + pkg_src_list_elt_t *iter;
1211 + pkg_src_t *src;
1212 +
1213 +
1214 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1215 +
1216 + if (! file_is_dir(lists_dir)) {
1217 + if (file_exists(lists_dir)) {
1218 + ipkg_message(conf, IPKG_ERROR,
1219 + "%s: ERROR: %s exists, but is not a directory\n",
1220 + __FUNCTION__, lists_dir);
1221 + free(lists_dir);
1222 + return EINVAL;
1223 + }
1224 + err = file_mkdir_hier(lists_dir, 0755);
1225 + if (err) {
1226 + ipkg_message(conf, IPKG_ERROR,
1227 + "%s: ERROR: failed to make directory %s: %s\n",
1228 + __FUNCTION__, lists_dir, strerror(errno));
1229 + free(lists_dir);
1230 + return EINVAL;
1231 + }
1232 + }
1233 +
1234 + failures = 0;
1235 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1236 + char *url, *list_file_name;
1237 +
1238 + src = iter->data;
1239 +
1240 + if (src->extra_data) /* debian style? */
1241 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1242 + src->gzip ? "Packages.gz" : "Packages");
1243 + else
1244 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1245 +
1246 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1247 + if (src->gzip) {
1248 + char *tmp;
1249 + char *tmp_file_name;
1250 + FILE *in, *out;
1251 +
1252 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1253 +
1254 + if (mkdtemp (tmp) == NULL) {
1255 + perror ("mkdtemp");
1256 + failures++;
1257 + continue;
1258 + }
1259 +
1260 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1261 + err = ipkg_download(conf, url, tmp_file_name);
1262 + if (err == 0) {
1263 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1264 + in = fopen (tmp_file_name, "r");
1265 + out = fopen (list_file_name, "w");
1266 + if (in && out)
1267 + inflate_unzip (in, out);
1268 + else
1269 + err = 1;
1270 + if (in)
1271 + fclose (in);
1272 + if (out)
1273 + fclose (out);
1274 + unlink (tmp_file_name);
1275 + rmdir (tmp);
1276 + free (tmp);
1277 + }
1278 + } else
1279 + err = ipkg_download(conf, url, list_file_name);
1280 + if (err) {
1281 + failures++;
1282 + } else {
1283 + ipkg_message(conf, IPKG_NOTICE,
1284 + "Updated list of available packages in %s\n",
1285 + list_file_name);
1286 + }
1287 + free(url);
1288 + free(list_file_name);
1289 + }
1290 + free(lists_dir);
1291 +
1292 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1293 +#warning here
1294 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1295 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1296 + * -Jamey 3/1/03
1297 + */
1298 + {
1299 + int i;
1300 + int changed = 0;
1301 + pkg_vec_t *available = pkg_vec_alloc();
1302 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1303 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1304 + for (i = 0; i < available->len; i++) {
1305 + pkg_t *pkg = available->pkgs[i];
1306 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1307 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1308 + pkg->state_want = SW_UNKNOWN;
1309 + changed = 1;
1310 + }
1311 + }
1312 + pkg_vec_free(available);
1313 + if (changed) {
1314 + write_status_files_if_changed(conf);
1315 + }
1316 + }
1317 +#endif
1318 +
1319 + return failures;
1320 +}
1321 +
1322 +
1323 +/* scan the args passed and cache the local filenames of the packages */
1324 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1325 +{
1326 + int i;
1327 + int err;
1328 +
1329 + /*
1330 + * First scan through package names/urls
1331 + * For any urls, download the packages and install in database.
1332 + * For any files, install package info in database.
1333 + */
1334 + for (i = 0; i < argc; i ++) {
1335 + char *filename = argv [i];
1336 + //char *tmp = basename (tmp);
1337 + //int tmplen = strlen (tmp);
1338 +
1339 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1340 + // continue;
1341 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1342 + // continue;
1343 +
1344 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1345 +
1346 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1347 + if (err)
1348 + return err;
1349 + }
1350 + return 0;
1351 +}
1352 +
1353 +struct ipkg_intercept
1354 +{
1355 + char *oldpath;
1356 + char *statedir;
1357 +};
1358 +
1359 +typedef struct ipkg_intercept *ipkg_intercept_t;
1360 +
1361 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1362 +{
1363 + ipkg_intercept_t ctx;
1364 + char *newpath;
1365 + int gen;
1366 +
1367 + ctx = malloc (sizeof (*ctx));
1368 + ctx->oldpath = strdup (getenv ("PATH"));
1369 +
1370 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1371 + setenv ("PATH", newpath, 1);
1372 + free (newpath);
1373 +
1374 + gen = 0;
1375 + retry:
1376 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1377 + if (mkdir (ctx->statedir, 0770) < 0) {
1378 + if (errno == EEXIST) {
1379 + free (ctx->statedir);
1380 + gen++;
1381 + goto retry;
1382 + }
1383 + perror (ctx->statedir);
1384 + return NULL;
1385 + }
1386 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1387 + return ctx;
1388 +}
1389 +
1390 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1391 +{
1392 + char *cmd;
1393 + DIR *dir;
1394 + int err = 0;
1395 +
1396 + setenv ("PATH", ctx->oldpath, 1);
1397 + free (ctx->oldpath);
1398 +
1399 + dir = opendir (ctx->statedir);
1400 + if (dir) {
1401 + struct dirent *de;
1402 + while (de = readdir (dir), de != NULL) {
1403 + char *path;
1404 +
1405 + if (de->d_name[0] == '.')
1406 + continue;
1407 +
1408 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1409 + if (access (path, X_OK) == 0) {
1410 + if (system (path)) {
1411 + err = errno;
1412 + perror (de->d_name);
1413 + }
1414 + }
1415 + free (path);
1416 + }
1417 + } else
1418 + perror (ctx->statedir);
1419 +
1420 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1421 + system (cmd);
1422 + free (cmd);
1423 +
1424 + free (ctx->statedir);
1425 + free (ctx);
1426 +
1427 + return err;
1428 +}
1429 +
1430 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1431 +{
1432 + pkg_vec_t *all;
1433 + int i;
1434 + pkg_t *pkg;
1435 + ipkg_intercept_t ic;
1436 + int r, err = 0;
1437 +
1438 + ipkg_message(conf, IPKG_INFO,
1439 + "Configuring unpacked packages\n");
1440 + fflush( stdout );
1441 +
1442 + all = pkg_vec_alloc();
1443 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1444 +
1445 + ic = ipkg_prep_intercepts (conf);
1446 +
1447 + for(i = 0; i < all->len; i++) {
1448 + pkg = all->pkgs[i];
1449 +
1450 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1451 + continue;
1452 +
1453 + if (pkg->state_status == SS_UNPACKED) {
1454 + ipkg_message(conf, IPKG_NOTICE,
1455 + "Configuring %s\n", pkg->name);
1456 + fflush( stdout );
1457 + r = ipkg_configure(conf, pkg);
1458 + if (r == 0) {
1459 + pkg->state_status = SS_INSTALLED;
1460 + pkg->parent->state_status = SS_INSTALLED;
1461 + pkg->state_flag &= ~SF_PREFER;
1462 + } else {
1463 + if (!err)
1464 + err = r;
1465 + }
1466 + }
1467 + }
1468 +
1469 + r = ipkg_finalize_intercepts (ic);
1470 + if (r && !err)
1471 + err = r;
1472 +
1473 + pkg_vec_free(all);
1474 + return err;
1475 +}
1476 +
1477 +static void sigint_handler(int sig)
1478 +{
1479 + signal(sig, SIG_DFL);
1480 + ipkg_message(NULL, IPKG_NOTICE,
1481 + "ipkg: interrupted. writing out status database\n");
1482 + write_status_files_if_changed(global_conf);
1483 + exit(128 + sig);
1484 +}
1485 +
1486 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1487 +{
1488 + int i;
1489 + char *arg;
1490 + int err=0;
1491 +
1492 + global_conf = conf;
1493 + signal(SIGINT, sigint_handler);
1494 +
1495 + /*
1496 + * Now scan through package names and install
1497 + */
1498 + for (i=0; i < argc; i++) {
1499 + arg = argv[i];
1500 +
1501 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1502 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1503 + if (err != EINVAL && err != 0)
1504 + return err;
1505 + }
1506 + pkg_info_preinstall_check(conf);
1507 +
1508 + for (i=0; i < argc; i++) {
1509 + arg = argv[i];
1510 + if (conf->multiple_providers)
1511 + err = ipkg_install_multi_by_name(conf, arg);
1512 + else{
1513 + err = ipkg_install_by_name(conf, arg);
1514 + }
1515 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1516 + ipkg_message(conf, IPKG_ERROR,
1517 + "Cannot find package %s.\n"
1518 + "Check the spelling or perhaps run 'ipkg update'\n",
1519 + arg);
1520 + }
1521 + }
1522 +
1523 + /* recheck to verify that all dependences are satisfied */
1524 + if (0) ipkg_satisfy_all_dependences(conf);
1525 +
1526 + ipkg_configure_packages(conf, NULL);
1527 +
1528 + write_status_files_if_changed(conf);
1529 +
1530 + return err;
1531 +}
1532 +
1533 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1534 +{
1535 + int i;
1536 + pkg_t *pkg;
1537 + int err;
1538 +
1539 + global_conf = conf;
1540 + signal(SIGINT, sigint_handler);
1541 +
1542 + if (argc) {
1543 + for (i=0; i < argc; i++) {
1544 + char *arg = argv[i];
1545 +
1546 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1547 + if (err != EINVAL && err != 0)
1548 + return err;
1549 + }
1550 + pkg_info_preinstall_check(conf);
1551 +
1552 + for (i=0; i < argc; i++) {
1553 + char *arg = argv[i];
1554 + if (conf->restrict_to_default_dest) {
1555 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1556 + argv[i],
1557 + conf->default_dest);
1558 + if (pkg == NULL) {
1559 + ipkg_message(conf, IPKG_NOTICE,
1560 + "Package %s not installed in %s\n",
1561 + argv[i], conf->default_dest->name);
1562 + continue;
1563 + }
1564 + } else {
1565 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1566 + argv[i]);
1567 + }
1568 + if (pkg)
1569 + ipkg_upgrade_pkg(conf, pkg);
1570 + else {
1571 + ipkg_install_by_name(conf, arg);
1572 + }
1573 + }
1574 + } else {
1575 + pkg_vec_t *installed = pkg_vec_alloc();
1576 +
1577 + pkg_info_preinstall_check(conf);
1578 +
1579 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1580 + for (i = 0; i < installed->len; i++) {
1581 + pkg = installed->pkgs[i];
1582 + ipkg_upgrade_pkg(conf, pkg);
1583 + }
1584 + pkg_vec_free(installed);
1585 + }
1586 +
1587 + /* recheck to verify that all dependences are satisfied */
1588 + if (0) ipkg_satisfy_all_dependences(conf);
1589 +
1590 + ipkg_configure_packages(conf, NULL);
1591 +
1592 + write_status_files_if_changed(conf);
1593 +
1594 + return 0;
1595 +}
1596 +
1597 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1598 +{
1599 + int i, err;
1600 + char *arg;
1601 + pkg_t *pkg;
1602 +
1603 + pkg_info_preinstall_check(conf);
1604 + for (i = 0; i < argc; i++) {
1605 + arg = argv[i];
1606 +
1607 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1608 + if (pkg == NULL) {
1609 + ipkg_message(conf, IPKG_ERROR,
1610 + "Cannot find package %s.\n"
1611 + "Check the spelling or perhaps run 'ipkg update'\n",
1612 + arg);
1613 + continue;
1614 + }
1615 +
1616 + err = ipkg_download_pkg(conf, pkg, ".");
1617 +
1618 + if (err) {
1619 + ipkg_message(conf, IPKG_ERROR,
1620 + "Failed to download %s\n", pkg->name);
1621 + } else {
1622 + ipkg_message(conf, IPKG_NOTICE,
1623 + "Downloaded %s as %s\n",
1624 + pkg->name, pkg->local_filename);
1625 + }
1626 + }
1627 +
1628 + return 0;
1629 +}
1630 +
1631 +
1632 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1633 +{
1634 + int i ;
1635 + pkg_vec_t *available;
1636 + pkg_t *pkg;
1637 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1638 + char *newline;
1639 + char *pkg_name = NULL;
1640 + char *version_str;
1641 +
1642 + if (argc > 0) {
1643 + pkg_name = argv[0];
1644 + }
1645 + available = pkg_vec_alloc();
1646 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1647 + for (i=0; i < available->len; i++) {
1648 + pkg = available->pkgs[i];
1649 + /* if we have package name or pattern and pkg does not match, then skip it */
1650 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1651 + continue;
1652 + if (pkg->description) {
1653 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1654 + } else {
1655 + desc_short[0] = '\0';
1656 + }
1657 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1658 + newline = strchr(desc_short, '\n');
1659 + if (newline) {
1660 + *newline = '\0';
1661 + }
1662 +#ifndef IPKG_LIB
1663 + printf("%s - %s\n", pkg->name, desc_short);
1664 +#else
1665 + if (ipkg_cb_list) {
1666 + version_str = pkg_version_str_alloc(pkg);
1667 + ipkg_cb_list(pkg->name,desc_short,
1668 + version_str,
1669 + pkg->state_status,
1670 + p_userdata);
1671 + free(version_str);
1672 + }
1673 +#endif
1674 + }
1675 + pkg_vec_free(available);
1676 +
1677 + return 0;
1678 +}
1679 +
1680 +
1681 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1682 +{
1683 + int i ;
1684 + pkg_vec_t *available;
1685 + pkg_t *pkg;
1686 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1687 + char *newline;
1688 + char *pkg_name = NULL;
1689 + char *version_str;
1690 +
1691 + if (argc > 0) {
1692 + pkg_name = argv[0];
1693 + }
1694 + available = pkg_vec_alloc();
1695 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1696 + for (i=0; i < available->len; i++) {
1697 + pkg = available->pkgs[i];
1698 + /* if we have package name or pattern and pkg does not match, then skip it */
1699 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1700 + continue;
1701 + if (pkg->description) {
1702 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1703 + } else {
1704 + desc_short[0] = '\0';
1705 + }
1706 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1707 + newline = strchr(desc_short, '\n');
1708 + if (newline) {
1709 + *newline = '\0';
1710 + }
1711 +#ifndef IPKG_LIB
1712 + printf("%s - %s\n", pkg->name, desc_short);
1713 +#else
1714 + if (ipkg_cb_list) {
1715 + version_str = pkg_version_str_alloc(pkg);
1716 + ipkg_cb_list(pkg->name,desc_short,
1717 + version_str,
1718 + pkg->state_status,
1719 + p_userdata);
1720 + free(version_str);
1721 + }
1722 +#endif
1723 + }
1724 +
1725 + return 0;
1726 +}
1727 +
1728 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1729 +{
1730 + int i;
1731 + pkg_vec_t *available;
1732 + pkg_t *pkg;
1733 + char *pkg_name = NULL;
1734 + char **pkg_fields = NULL;
1735 + int n_fields = 0;
1736 + char *buff ; // = (char *)malloc(1);
1737 +
1738 + if (argc > 0) {
1739 + pkg_name = argv[0];
1740 + }
1741 + if (argc > 1) {
1742 + pkg_fields = &argv[1];
1743 + n_fields = argc - 1;
1744 + }
1745 +
1746 + available = pkg_vec_alloc();
1747 + if (installed_only)
1748 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1749 + else
1750 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1751 + for (i=0; i < available->len; i++) {
1752 + pkg = available->pkgs[i];
1753 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1754 + continue;
1755 + }
1756 +#ifndef IPKG_LIB
1757 + if (n_fields) {
1758 + for (j = 0; j < n_fields; j++)
1759 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1760 + } else {
1761 + pkg_print_info(pkg, stdout);
1762 + }
1763 +#else
1764 +
1765 + buff = pkg_formatted_info(pkg);
1766 + if ( buff ) {
1767 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1768 + pkg->state_status,
1769 + buff,
1770 + p_userdata);
1771 +/*
1772 + We should not forget that actually the pointer is allocated.
1773 + We need to free it :) ( Thanks florian for seeing the error )
1774 +*/
1775 + free(buff);
1776 + }
1777 +#endif
1778 + if (conf->verbosity > 1) {
1779 + conffile_list_elt_t *iter;
1780 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1781 + conffile_t *cf = iter->data;
1782 + int modified = conffile_has_been_modified(conf, cf);
1783 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1784 + cf->name, cf->value, modified);
1785 + }
1786 + }
1787 + }
1788 +#ifndef IPKG_LIB
1789 + if (buff)
1790 + free(buff);
1791 +#endif
1792 + pkg_vec_free(available);
1793 +
1794 + return 0;
1795 +}
1796 +
1797 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1798 +{
1799 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1800 +}
1801 +
1802 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1803 +{
1804 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1805 +}
1806 +
1807 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1808 +{
1809 +
1810 + int err;
1811 + if (argc > 0) {
1812 + char *pkg_name = NULL;
1813 +
1814 + pkg_name = argv[0];
1815 +
1816 + err = ipkg_configure_packages (conf, pkg_name);
1817 +
1818 + } else {
1819 + err = ipkg_configure_packages (conf, NULL);
1820 + }
1821 +
1822 + write_status_files_if_changed(conf);
1823 +
1824 + return err;
1825 +}
1826 +
1827 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1828 +{
1829 + int i, err;
1830 + char *globpattern;
1831 + glob_t globbuf;
1832 +
1833 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1834 + err = glob(globpattern, 0, NULL, &globbuf);
1835 + free(globpattern);
1836 + if (err) {
1837 + return 0;
1838 + }
1839 +
1840 + ipkg_message(conf, IPKG_NOTICE,
1841 + "The following packages in %s will now be installed.\n",
1842 + conf->pending_dir);
1843 + for (i = 0; i < globbuf.gl_pathc; i++) {
1844 + ipkg_message(conf, IPKG_NOTICE,
1845 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1846 + }
1847 + ipkg_message(conf, IPKG_NOTICE, "\n");
1848 + for (i = 0; i < globbuf.gl_pathc; i++) {
1849 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1850 + if (err == 0) {
1851 + err = unlink(globbuf.gl_pathv[i]);
1852 + if (err) {
1853 + ipkg_message(conf, IPKG_ERROR,
1854 + "%s: ERROR: failed to unlink %s: %s\n",
1855 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1856 + return err;
1857 + }
1858 + }
1859 + }
1860 + globfree(&globbuf);
1861 +
1862 + return err;
1863 +}
1864 +
1865 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1866 +{
1867 + int i,a,done;
1868 + pkg_t *pkg;
1869 + pkg_t *pkg_to_remove;
1870 + pkg_vec_t *available;
1871 + char *pkg_name = NULL;
1872 + global_conf = conf;
1873 + signal(SIGINT, sigint_handler);
1874 +
1875 +// ENH: Add the "no pkg removed" just in case.
1876 +
1877 + done = 0;
1878 +
1879 + available = pkg_vec_alloc();
1880 + pkg_info_preinstall_check(conf);
1881 + if ( argc > 0 ) {
1882 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1883 + for (i=0; i < argc; i++) {
1884 + pkg_name = malloc(strlen(argv[i])+2);
1885 + strcpy(pkg_name,argv[i]);
1886 + for (a=0; a < available->len; a++) {
1887 + pkg = available->pkgs[a];
1888 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1889 + continue;
1890 + }
1891 + if (conf->restrict_to_default_dest) {
1892 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1893 + pkg->name,
1894 + conf->default_dest);
1895 + } else {
1896 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1897 + }
1898 +
1899 + if (pkg == NULL) {
1900 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1901 + continue;
1902 + }
1903 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1904 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1905 + continue;
1906 + }
1907 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1908 + done = 1;
1909 + }
1910 + free (pkg_name);
1911 + }
1912 + pkg_vec_free(available);
1913 + } else {
1914 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1915 + int i;
1916 + int flagged_pkg_count = 0;
1917 + int removed;
1918 +
1919 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1920 +
1921 + for (i = 0; i < installed_pkgs->len; i++) {
1922 + pkg_t *pkg = installed_pkgs->pkgs[i];
1923 + if (pkg->state_flag & SF_USER) {
1924 + flagged_pkg_count++;
1925 + } else {
1926 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1927 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1928 + }
1929 + }
1930 + if (!flagged_pkg_count) {
1931 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1932 + "so refusing to uninstall unflagged non-leaf packages\n");
1933 + return 0;
1934 + }
1935 +
1936 + /* find packages not flagged SF_USER (i.e., installed to
1937 + * satisfy a dependence) and not having any dependents, and
1938 + * remove them */
1939 + do {
1940 + removed = 0;
1941 + for (i = 0; i < installed_pkgs->len; i++) {
1942 + pkg_t *pkg = installed_pkgs->pkgs[i];
1943 + if (!(pkg->state_flag & SF_USER)
1944 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1945 + removed++;
1946 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1947 + ipkg_remove_pkg(conf, pkg,0);
1948 + done = 1;
1949 + }
1950 + }
1951 + } while (removed);
1952 + pkg_vec_free(installed_pkgs);
1953 + }
1954 +
1955 + if ( done == 0 )
1956 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1957 +
1958 + write_status_files_if_changed(conf);
1959 + return 0;
1960 +}
1961 +
1962 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1963 +{
1964 + int i;
1965 + pkg_t *pkg;
1966 +
1967 + global_conf = conf;
1968 + signal(SIGINT, sigint_handler);
1969 +
1970 + pkg_info_preinstall_check(conf);
1971 +
1972 + for (i=0; i < argc; i++) {
1973 + if (conf->restrict_to_default_dest) {
1974 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1975 + argv[i],
1976 + conf->default_dest);
1977 + } else {
1978 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1979 + }
1980 +
1981 + if (pkg == NULL) {
1982 + ipkg_message(conf, IPKG_ERROR,
1983 + "Package %s is not installed.\n", argv[i]);
1984 + continue;
1985 + }
1986 + ipkg_purge_pkg(conf, pkg);
1987 + }
1988 +
1989 + write_status_files_if_changed(conf);
1990 + return 0;
1991 +}
1992 +
1993 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1994 +{
1995 + int i;
1996 + pkg_t *pkg;
1997 + const char *flags = argv[0];
1998 +
1999 + global_conf = conf;
2000 + signal(SIGINT, sigint_handler);
2001 +
2002 + for (i=1; i < argc; i++) {
2003 + if (conf->restrict_to_default_dest) {
2004 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2005 + argv[i],
2006 + conf->default_dest);
2007 + } else {
2008 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2009 + }
2010 +
2011 + if (pkg == NULL) {
2012 + ipkg_message(conf, IPKG_ERROR,
2013 + "Package %s is not installed.\n", argv[i]);
2014 + continue;
2015 + }
2016 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2017 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2018 + pkg->state_flag = pkg_state_flag_from_str(flags);
2019 + }
2020 +/* pb_ asked this feature 03292004 */
2021 +/* Actually I will use only this two, but this is an open for various status */
2022 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2023 + pkg->state_status = pkg_state_status_from_str(flags);
2024 + }
2025 + ipkg_state_changed++;
2026 + ipkg_message(conf, IPKG_NOTICE,
2027 + "Setting flags for package %s to %s\n",
2028 + pkg->name, flags);
2029 + }
2030 +
2031 + write_status_files_if_changed(conf);
2032 + return 0;
2033 +}
2034 +
2035 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2036 +{
2037 + pkg_t *pkg;
2038 + str_list_t *installed_files;
2039 + str_list_elt_t *iter;
2040 + char *pkg_version;
2041 + size_t buff_len = 8192;
2042 + size_t used_len;
2043 + char *buff ;
2044 +
2045 + buff = (char *)malloc(buff_len);
2046 + if ( buff == NULL ) {
2047 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2048 + return ENOMEM;
2049 + }
2050 +
2051 + if (argc < 1) {
2052 + return EINVAL;
2053 + }
2054 +
2055 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2056 + argv[0]);
2057 + if (pkg == NULL) {
2058 + ipkg_message(conf, IPKG_ERROR,
2059 + "Package %s not installed.\n", argv[0]);
2060 + return 0;
2061 + }
2062 +
2063 + installed_files = pkg_get_installed_files(pkg);
2064 + pkg_version = pkg_version_str_alloc(pkg);
2065 +
2066 +#ifndef IPKG_LIB
2067 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2068 + pkg->name, pkg_version, pkg->dest->name);
2069 + for (iter = installed_files->head; iter; iter = iter->next) {
2070 + puts(iter->data);
2071 + }
2072 +#else
2073 + if (buff) {
2074 + try_again:
2075 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2076 + pkg->name, pkg_version, pkg->dest->name) + 1;
2077 + if (used_len > buff_len) {
2078 + buff_len *= 2;
2079 + buff = realloc (buff, buff_len);
2080 + goto try_again;
2081 + }
2082 + for (iter = installed_files->head; iter; iter = iter->next) {
2083 + used_len += strlen (iter->data) + 1;
2084 + while (buff_len <= used_len) {
2085 + buff_len *= 2;
2086 + buff = realloc (buff, buff_len);
2087 + }
2088 + strncat(buff, iter->data, buff_len);
2089 + strncat(buff, "\n", buff_len);
2090 + }
2091 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2092 + buff,
2093 + pkg_version_str_alloc(pkg),
2094 + pkg->state_status,
2095 + p_userdata);
2096 + free(buff);
2097 + }
2098 +#endif
2099 +
2100 + free(pkg_version);
2101 + pkg_free_installed_files(pkg);
2102 +
2103 + return 0;
2104 +}
2105 +
2106 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2107 +{
2108 +
2109 + if (argc > 0) {
2110 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2111 + const char *rel_str = "depends on";
2112 + int i;
2113 +
2114 + pkg_info_preinstall_check(conf);
2115 +
2116 + if (conf->query_all)
2117 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2118 + else
2119 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2120 + for (i = 0; i < argc; i++) {
2121 + const char *target = argv[i];
2122 + int j;
2123 +
2124 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2125 +
2126 + for (j = 0; j < available_pkgs->len; j++) {
2127 + pkg_t *pkg = available_pkgs->pkgs[j];
2128 + if (fnmatch(target, pkg->name, 0) == 0) {
2129 + int k;
2130 + int count = pkg->depends_count + pkg->pre_depends_count;
2131 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2132 + target, pkg->architecture, rel_str);
2133 + for (k = 0; k < count; k++) {
2134 + compound_depend_t *cdepend = &pkg->depends[k];
2135 + int l;
2136 + for (l = 0; l < cdepend->possibility_count; l++) {
2137 + depend_t *possibility = cdepend->possibilities[l];
2138 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2139 + if (conf->verbosity > 0) {
2140 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2141 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2142 + if (possibility->version) {
2143 + char *typestr = NULL;
2144 + switch (possibility->constraint) {
2145 + case NONE: typestr = "none"; break;
2146 + case EARLIER: typestr = "<"; break;
2147 + case EARLIER_EQUAL: typestr = "<="; break;
2148 + case EQUAL: typestr = "="; break;
2149 + case LATER_EQUAL: typestr = ">="; break;
2150 + case LATER: typestr = ">"; break;
2151 + }
2152 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2153 + }
2154 + // free(ver);
2155 + }
2156 + ipkg_message(conf, IPKG_ERROR, "\n");
2157 + }
2158 + }
2159 + }
2160 + }
2161 + }
2162 + pkg_vec_free(available_pkgs);
2163 + }
2164 + return 0;
2165 +}
2166 +
2167 +enum what_field_type {
2168 + WHATDEPENDS,
2169 + WHATCONFLICTS,
2170 + WHATPROVIDES,
2171 + WHATREPLACES,
2172 + WHATRECOMMENDS,
2173 + WHATSUGGESTS
2174 +};
2175 +
2176 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2177 +{
2178 +
2179 + if (argc > 0) {
2180 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2181 + const char *rel_str = NULL;
2182 + int i;
2183 + int changed;
2184 +
2185 + switch (what_field_type) {
2186 + case WHATDEPENDS: rel_str = "depends on"; break;
2187 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2188 + case WHATSUGGESTS: rel_str = "suggests"; break;
2189 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2190 + case WHATPROVIDES: rel_str = "provides"; break;
2191 + case WHATREPLACES: rel_str = "replaces"; break;
2192 + }
2193 +
2194 + if (conf->query_all)
2195 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2196 + else
2197 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2198 +
2199 + /* mark the root set */
2200 + pkg_vec_clear_marks(available_pkgs);
2201 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2202 + for (i = 0; i < argc; i++) {
2203 + const char *dependee_pattern = argv[i];
2204 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2205 + }
2206 + for (i = 0; i < available_pkgs->len; i++) {
2207 + pkg_t *pkg = available_pkgs->pkgs[i];
2208 + if (pkg->state_flag & SF_MARKED) {
2209 + /* mark the parent (abstract) package */
2210 + pkg_mark_provides(pkg);
2211 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2212 + }
2213 + }
2214 +
2215 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2216 + do {
2217 + int j;
2218 + changed = 0;
2219 +
2220 + for (j = 0; j < available_pkgs->len; j++) {
2221 + pkg_t *pkg = available_pkgs->pkgs[j];
2222 + int k;
2223 + int count = ((what_field_type == WHATCONFLICTS)
2224 + ? pkg->conflicts_count
2225 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2226 + /* skip this package if it is already marked */
2227 + if (pkg->parent->state_flag & SF_MARKED) {
2228 + continue;
2229 + }
2230 + for (k = 0; k < count; k++) {
2231 + compound_depend_t *cdepend =
2232 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2233 + int l;
2234 + for (l = 0; l < cdepend->possibility_count; l++) {
2235 + depend_t *possibility = cdepend->possibilities[l];
2236 + if (possibility->pkg->state_flag & SF_MARKED) {
2237 + /* mark the depending package so we won't visit it again */
2238 + pkg->state_flag |= SF_MARKED;
2239 + pkg_mark_provides(pkg);
2240 + changed++;
2241 +
2242 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2243 + if (conf->verbosity > 0) {
2244 + char *ver = pkg_version_str_alloc(pkg);
2245 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2246 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2247 + if (possibility->version) {
2248 + char *typestr = NULL;
2249 + switch (possibility->constraint) {
2250 + case NONE: typestr = "none"; break;
2251 + case EARLIER: typestr = "<"; break;
2252 + case EARLIER_EQUAL: typestr = "<="; break;
2253 + case EQUAL: typestr = "="; break;
2254 + case LATER_EQUAL: typestr = ">="; break;
2255 + case LATER: typestr = ">"; break;
2256 + }
2257 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2258 + }
2259 + free(ver);
2260 + if (!pkg_dependence_satisfiable(conf, possibility))
2261 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2262 + }
2263 + ipkg_message(conf, IPKG_NOTICE, "\n");
2264 + goto next_package;
2265 + }
2266 + }
2267 + }
2268 + next_package:
2269 + ;
2270 + }
2271 + } while (changed && recursive);
2272 + pkg_vec_free(available_pkgs);
2273 + }
2274 +
2275 + return 0;
2276 +}
2277 +
2278 +int pkg_mark_provides(pkg_t *pkg)
2279 +{
2280 + int provides_count = pkg->provides_count;
2281 + abstract_pkg_t **provides = pkg->provides;
2282 + int i;
2283 + pkg->parent->state_flag |= SF_MARKED;
2284 + for (i = 0; i < provides_count; i++) {
2285 + provides[i]->state_flag |= SF_MARKED;
2286 + }
2287 + return 0;
2288 +}
2289 +
2290 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2291 +{
2292 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2293 +}
2294 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2295 +{
2296 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2297 +}
2298 +
2299 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2300 +{
2301 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2302 +}
2303 +
2304 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2305 +{
2306 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2307 +}
2308 +
2309 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2310 +{
2311 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2312 +}
2313 +
2314 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2315 +{
2316 +
2317 + if (argc > 0) {
2318 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2319 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2320 + int i;
2321 +
2322 + pkg_info_preinstall_check(conf);
2323 +
2324 + if (conf->query_all)
2325 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2326 + else
2327 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2328 + for (i = 0; i < argc; i++) {
2329 + const char *target = argv[i];
2330 + int j;
2331 +
2332 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2333 + rel_str, target);
2334 + for (j = 0; j < available_pkgs->len; j++) {
2335 + pkg_t *pkg = available_pkgs->pkgs[j];
2336 + int k;
2337 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2338 + for (k = 0; k < count; k++) {
2339 + abstract_pkg_t *apkg =
2340 + ((what_field_type == WHATPROVIDES)
2341 + ? pkg->provides[k]
2342 + : pkg->replaces[k]);
2343 + if (fnmatch(target, apkg->name, 0) == 0) {
2344 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2345 + if (strcmp(target, apkg->name) != 0)
2346 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2347 + ipkg_message(conf, IPKG_ERROR, "\n");
2348 + }
2349 + }
2350 + }
2351 + }
2352 + pkg_vec_free(available_pkgs);
2353 + }
2354 + return 0;
2355 +}
2356 +
2357 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2358 +{
2359 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2360 +}
2361 +
2362 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2363 +{
2364 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2365 +}
2366 +
2367 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2368 +{
2369 + int i;
2370 +
2371 + pkg_vec_t *installed;
2372 + pkg_t *pkg;
2373 + str_list_t *installed_files;
2374 + str_list_elt_t *iter;
2375 + char *installed_file;
2376 +
2377 + if (argc < 1) {
2378 + return EINVAL;
2379 + }
2380 +
2381 + installed = pkg_vec_alloc();
2382 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2383 +
2384 + for (i=0; i < installed->len; i++) {
2385 + pkg = installed->pkgs[i];
2386 +
2387 + installed_files = pkg_get_installed_files(pkg);
2388 +
2389 + for (iter = installed_files->head; iter; iter = iter->next) {
2390 + installed_file = iter->data;
2391 + if (fnmatch(argv[0], installed_file, 0)==0) {
2392 +#ifndef IPKG_LIB
2393 + printf("%s: %s\n", pkg->name, installed_file);
2394 +#else
2395 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2396 + installed_file,
2397 + pkg_version_str_alloc(pkg),
2398 + pkg->state_status, p_userdata);
2399 +#endif
2400 + }
2401 + }
2402 +
2403 + pkg_free_installed_files(pkg);
2404 + }
2405 +
2406 + /* XXX: CLEANUP: It's not obvious from the name of
2407 + pkg_hash_fetch_all_installed that we need to call
2408 + pkg_vec_free to avoid a memory leak. */
2409 + pkg_vec_free(installed);
2410 +
2411 + return 0;
2412 +}
2413 +
2414 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2415 +{
2416 + if (argc == 3) {
2417 + /* this is a bit gross */
2418 + struct pkg p1, p2;
2419 + parseVersion(&p1, argv[0]);
2420 + parseVersion(&p2, argv[2]);
2421 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2422 + } else {
2423 + ipkg_message(conf, IPKG_ERROR,
2424 + "ipkg compare_versions <v1> <op> <v2>\n"
2425 + "<op> is one of <= >= << >> =\n");
2426 + return -1;
2427 + }
2428 +}
2429 +
2430 +#ifndef HOST_CPU_STR
2431 +#define HOST_CPU_STR__(X) #X
2432 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2433 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2434 +#endif
2435 +
2436 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2437 +{
2438 + nv_pair_list_elt_t *l;
2439 +
2440 + l = conf->arch_list.head;
2441 + while (l) {
2442 + nv_pair_t *nv = l->data;
2443 + printf("arch %s %s\n", nv->name, nv->value);
2444 + l = l->next;
2445 + }
2446 + return 0;
2447 +}
2448 +
2449 +
2450 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h
2451 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2452 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h 2006-07-22 16:31:25.000000000 +0200
2453 @@ -0,0 +1,46 @@
2454 +/* ipkg_cmd.h - the itsy package management system
2455 +
2456 + Carl D. Worth
2457 +
2458 + Copyright (C) 2001 University of Southern California
2459 +
2460 + This program is free software; you can redistribute it and/or
2461 + modify it under the terms of the GNU General Public License as
2462 + published by the Free Software Foundation; either version 2, or (at
2463 + your option) any later version.
2464 +
2465 + This program is distributed in the hope that it will be useful, but
2466 + WITHOUT ANY WARRANTY; without even the implied warranty of
2467 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2468 + General Public License for more details.
2469 +*/
2470 +
2471 +#ifndef IPKG_CMD_H
2472 +#define IPKG_CMD_H
2473 +
2474 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2475 +
2476 +struct ipkg_cmd
2477 +{
2478 + char *name;
2479 + int requires_args;
2480 + ipkg_cmd_fun_t fun;
2481 +};
2482 +typedef struct ipkg_cmd ipkg_cmd_t;
2483 +
2484 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2485 +#ifdef IPKG_LIB
2486 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2487 + const char **argv, void *userdata);
2488 +#else
2489 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2490 +#endif
2491 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2492 +/* install any packges with state_want == SW_INSTALL */
2493 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2494 +/* ensure that all dependences are satisfied */
2495 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2496 +
2497 +int pkg_mark_provides(pkg_t *pkg);
2498 +
2499 +#endif
2500 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_conf.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.c
2501 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2502 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.c 2006-07-22 16:31:25.000000000 +0200
2503 @@ -0,0 +1,711 @@
2504 +/* ipkg_conf.c - the itsy package management system
2505 +
2506 + Carl D. Worth
2507 +
2508 + Copyright (C) 2001 University of Southern California
2509 +
2510 + This program is free software; you can redistribute it and/or
2511 + modify it under the terms of the GNU General Public License as
2512 + published by the Free Software Foundation; either version 2, or (at
2513 + your option) any later version.
2514 +
2515 + This program is distributed in the hope that it will be useful, but
2516 + WITHOUT ANY WARRANTY; without even the implied warranty of
2517 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2518 + General Public License for more details.
2519 +*/
2520 +
2521 +#include <glob.h>
2522 +
2523 +#include "ipkg.h"
2524 +#include "ipkg_conf.h"
2525 +
2526 +#include "xregex.h"
2527 +#include "sprintf_alloc.h"
2528 +#include "ipkg_conf.h"
2529 +#include "ipkg_message.h"
2530 +#include "file_util.h"
2531 +#include "str_util.h"
2532 +#include "xsystem.h"
2533 +
2534 +
2535 +ipkg_conf_t *global_conf;
2536 +
2537 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2538 + pkg_src_list_t *pkg_src_list,
2539 + nv_pair_list_t *tmp_dest_nv_pair_list,
2540 + char **tmp_lists_dir);
2541 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2542 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2543 + const char *name, const char *value);
2544 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2545 + const char *default_dest_name);
2546 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2547 + pkg_src_list_t *nv_pair_list);
2548 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2549 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2550 +
2551 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2552 +{
2553 + ipkg_option_t tmp[] = {
2554 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2555 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2556 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2557 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2558 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2559 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2560 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2561 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2562 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2563 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2564 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2565 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2566 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2567 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2568 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2569 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2570 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2571 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2572 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2573 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2574 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2575 + { NULL }
2576 + };
2577 +
2578 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2579 + if ( options == NULL ){
2580 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2581 + return -1;
2582 + }
2583 +
2584 + memcpy(*options, tmp, sizeof(tmp));
2585 + return 0;
2586 +};
2587 +
2588 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2589 +{
2590 + if (arg_str) {
2591 + if (*conf_str) {
2592 + free(*conf_str);
2593 + }
2594 + *conf_str = strdup(arg_str);
2595 + }
2596 +}
2597 +
2598 +static void ipkg_conf_free_string(char **conf_str)
2599 +{
2600 + if (*conf_str) {
2601 + free(*conf_str);
2602 + *conf_str = NULL;
2603 + }
2604 +}
2605 +
2606 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2607 +{
2608 + int err;
2609 + char *tmp_dir_base;
2610 + nv_pair_list_t tmp_dest_nv_pair_list;
2611 + char * lists_dir =NULL;
2612 + glob_t globbuf;
2613 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2614 + char *pending_dir =NULL;
2615 +
2616 + memset(conf, 0, sizeof(ipkg_conf_t));
2617 +
2618 + pkg_src_list_init(&conf->pkg_src_list);
2619 +
2620 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2621 + pkg_dest_list_init(&conf->pkg_dest_list);
2622 +
2623 + nv_pair_list_init(&conf->arch_list);
2624 +
2625 + conf->restrict_to_default_dest = 0;
2626 + conf->default_dest = NULL;
2627 +
2628 +
2629 + if (args->tmp_dir)
2630 + tmp_dir_base = args->tmp_dir;
2631 + else
2632 + tmp_dir_base = getenv("TMPDIR");
2633 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2634 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2635 + IPKG_CONF_TMP_DIR_SUFFIX);
2636 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2637 + if (conf->tmp_dir == NULL) {
2638 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2639 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2640 + return errno;
2641 + }
2642 +
2643 + conf->force_depends = 0;
2644 + conf->force_defaults = 0;
2645 + conf->force_overwrite = 0;
2646 + conf->force_downgrade = 0;
2647 + conf->force_reinstall = 0;
2648 + conf->force_space = 0;
2649 + conf->force_removal_of_essential_packages = 0;
2650 + conf->force_removal_of_dependent_packages = 0;
2651 + conf->nodeps = 0;
2652 + conf->verbose_wget = 0;
2653 + conf->offline_root = NULL;
2654 + conf->offline_root_pre_script_cmd = NULL;
2655 + conf->offline_root_post_script_cmd = NULL;
2656 + conf->multiple_providers = 0;
2657 + conf->verbosity = 1;
2658 + conf->noaction = 0;
2659 +
2660 + conf->http_proxy = NULL;
2661 + conf->ftp_proxy = NULL;
2662 + conf->no_proxy = NULL;
2663 + conf->proxy_user = NULL;
2664 + conf->proxy_passwd = NULL;
2665 +
2666 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2667 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2668 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2669 + lists_dir=(char *)malloc(1);
2670 + lists_dir[0]='\0';
2671 + if (args->conf_file) {
2672 + struct stat stat_buf;
2673 + err = stat(args->conf_file, &stat_buf);
2674 + if (err == 0)
2675 + if (ipkg_conf_parse_file(conf, args->conf_file,
2676 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2677 + /* Memory leakage from ipkg_conf_parse-file */
2678 + return -1;
2679 + }
2680 +
2681 + }
2682 +
2683 + /* if (!lists_dir ){*/
2684 + if (strlen(lists_dir)<=1 ){
2685 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2686 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2687 + }
2688 +
2689 + if (args->offline_root) {
2690 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2691 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2692 + free(lists_dir);
2693 + lists_dir = tmp;
2694 + }
2695 +
2696 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2697 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2698 +
2699 + conf->lists_dir = strdup(lists_dir);
2700 + conf->pending_dir = strdup(pending_dir);
2701 +
2702 + if (args->offline_root)
2703 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2704 + memset(&globbuf, 0, sizeof(globbuf));
2705 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2706 + if (!err) {
2707 + int i;
2708 + for (i = 0; i < globbuf.gl_pathc; i++) {
2709 + if (globbuf.gl_pathv[i])
2710 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2711 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2712 + /* Memory leakage from ipkg_conf_parse-file */
2713 + return -1;
2714 + }
2715 + }
2716 + }
2717 + globfree(&globbuf);
2718 +
2719 + /* if no architectures were defined, then default all, noarch, and host architecture */
2720 + if (nv_pair_list_empty(&conf->arch_list)) {
2721 + nv_pair_list_append(&conf->arch_list, "all", "1");
2722 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2723 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2724 + }
2725 +
2726 + /* Even if there is no conf file, we'll need at least one dest. */
2727 + if (tmp_dest_nv_pair_list.head == NULL) {
2728 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2729 + IPKG_CONF_DEFAULT_DEST_NAME,
2730 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2731 + }
2732 +
2733 + /* After parsing the file, set options from command-line, (so that
2734 + command-line arguments take precedence) */
2735 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2736 + really needs to be cleaned up. There is so much duplication
2737 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2738 + a pointer to args_t (which could then not be freed), rather
2739 + than duplicating every field here? */
2740 + if (args->force_depends) {
2741 + conf->force_depends = 1;
2742 + }
2743 + if (args->force_defaults) {
2744 + conf->force_defaults = 1;
2745 + }
2746 + if (args->force_overwrite) {
2747 + conf->force_overwrite = 1;
2748 + }
2749 + if (args->force_downgrade) {
2750 + conf->force_downgrade = 1;
2751 + }
2752 + if (args->force_reinstall) {
2753 + conf->force_reinstall = 1;
2754 + }
2755 + if (args->force_removal_of_dependent_packages) {
2756 + conf->force_removal_of_dependent_packages = 1;
2757 + }
2758 + if (args->force_removal_of_essential_packages) {
2759 + conf->force_removal_of_essential_packages = 1;
2760 + }
2761 + if (args->nodeps) {
2762 + conf->nodeps = 1;
2763 + }
2764 + if (args->noaction) {
2765 + conf->noaction = 1;
2766 + }
2767 + if (args->query_all) {
2768 + conf->query_all = 1;
2769 + }
2770 + if (args->verbose_wget) {
2771 + conf->verbose_wget = 1;
2772 + }
2773 + if (args->multiple_providers) {
2774 + conf->multiple_providers = 1;
2775 + }
2776 + if (args->verbosity != conf->verbosity) {
2777 + conf->verbosity = args->verbosity;
2778 + }
2779 +
2780 + ipkg_conf_override_string(&conf->offline_root,
2781 + args->offline_root);
2782 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2783 + args->offline_root_pre_script_cmd);
2784 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2785 + args->offline_root_post_script_cmd);
2786 +
2787 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2788 + read anything from there.
2789 +*/
2790 + if ( !(args->nocheckfordirorfile)){
2791 + /* need to run load the source list before dest list -Jamey */
2792 + if ( !(args->noreadfeedsfile))
2793 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2794 +
2795 + /* Now that we have resolved conf->offline_root, we can commit to
2796 + the directory names for the dests and load in all the package
2797 + lists. */
2798 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2799 +
2800 + if (args->dest) {
2801 + err = ipkg_conf_set_default_dest(conf, args->dest);
2802 + if (err) {
2803 + return err;
2804 + }
2805 + }
2806 + }
2807 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2808 + free(lists_dir);
2809 + free(pending_dir);
2810 +
2811 + return 0;
2812 +}
2813 +
2814 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2815 +{
2816 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2817 +#error
2818 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2819 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2820 + __FUNCTION__, conf->tmp_dir);
2821 +#else
2822 + int err;
2823 +
2824 + err = rmdir(conf->tmp_dir);
2825 + if (err) {
2826 + if (errno == ENOTEMPTY) {
2827 + char *cmd;
2828 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2829 + err = xsystem(cmd);
2830 + free(cmd);
2831 + }
2832 + if (err)
2833 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2834 + }
2835 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2836 +
2837 + free(conf->tmp_dir); /*XXX*/
2838 +
2839 + pkg_src_list_deinit(&conf->pkg_src_list);
2840 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2841 + nv_pair_list_deinit(&conf->arch_list);
2842 + if (&conf->pkg_hash)
2843 + pkg_hash_deinit(&conf->pkg_hash);
2844 + if (&conf->file_hash)
2845 + hash_table_deinit(&conf->file_hash);
2846 + if (&conf->obs_file_hash)
2847 + hash_table_deinit(&conf->obs_file_hash);
2848 +
2849 + ipkg_conf_free_string(&conf->offline_root);
2850 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2851 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2852 +
2853 + if (conf->verbosity > 1) {
2854 + int i;
2855 + hash_table_t *hashes[] = {
2856 + &conf->pkg_hash,
2857 + &conf->file_hash,
2858 + &conf->obs_file_hash };
2859 + for (i = 0; i < 3; i++) {
2860 + hash_table_t *hash = hashes[i];
2861 + int c = 0;
2862 + int n_conflicts = 0;
2863 + int j;
2864 + for (j = 0; j < hash->n_entries; j++) {
2865 + int len = 0;
2866 + hash_entry_t *e = &hash->entries[j];
2867 + if (e->next)
2868 + n_conflicts++;
2869 + while (e && e->key) {
2870 + len++;
2871 + e = e->next;
2872 + }
2873 + if (len > c)
2874 + c = len;
2875 + }
2876 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2877 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2878 + hash_table_deinit(hash);
2879 + }
2880 + }
2881 +}
2882 +
2883 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2884 + const char *default_dest_name)
2885 +{
2886 + pkg_dest_list_elt_t *iter;
2887 + pkg_dest_t *dest;
2888 +
2889 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2890 + dest = iter->data;
2891 + if (strcmp(dest->name, default_dest_name) == 0) {
2892 + conf->default_dest = dest;
2893 + conf->restrict_to_default_dest = 1;
2894 + return 0;
2895 + }
2896 + }
2897 +
2898 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2899 +
2900 + return 1;
2901 +}
2902 +
2903 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2904 +{
2905 + pkg_src_list_elt_t *iter;
2906 + pkg_src_t *src;
2907 + char *list_file;
2908 +
2909 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2910 + src = iter->data;
2911 + if (src == NULL) {
2912 + continue;
2913 + }
2914 +
2915 + sprintf_alloc(&list_file, "%s/%s",
2916 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2917 + src->name);
2918 +
2919 + if (file_exists(list_file)) {
2920 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2921 + }
2922 + free(list_file);
2923 + }
2924 +
2925 + return 0;
2926 +}
2927 +
2928 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2929 +{
2930 + nv_pair_list_elt_t *iter;
2931 + nv_pair_t *nv_pair;
2932 + pkg_dest_t *dest;
2933 + char *root_dir;
2934 +
2935 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2936 + nv_pair = iter->data;
2937 +
2938 + if (conf->offline_root) {
2939 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2940 + } else {
2941 + root_dir = strdup(nv_pair->value);
2942 + }
2943 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2944 + free(root_dir);
2945 + if (dest == NULL) {
2946 + continue;
2947 + }
2948 + if (conf->default_dest == NULL) {
2949 + conf->default_dest = dest;
2950 + }
2951 + if (file_exists(dest->status_file_name)) {
2952 + pkg_hash_add_from_file(conf, dest->status_file_name,
2953 + NULL, dest, 1);
2954 + }
2955 + }
2956 +
2957 + return 0;
2958 +}
2959 +
2960 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2961 + pkg_src_list_t *pkg_src_list,
2962 + nv_pair_list_t *tmp_dest_nv_pair_list,
2963 + char **lists_dir)
2964 +{
2965 + ipkg_option_t * options;
2966 + FILE *file = fopen(filename, "r");
2967 + regex_t valid_line_re, comment_re;
2968 +#define regmatch_size 12
2969 + regmatch_t regmatch[regmatch_size];
2970 +
2971 + if (ipkg_init_options_array(conf, &options)<0)
2972 + return ENOMEM;
2973 +
2974 + if (file == NULL) {
2975 + fprintf(stderr, "%s: failed to open %s: %s\n",
2976 + __FUNCTION__, filename, strerror(errno));
2977 + free(options);
2978 + return errno;
2979 + }
2980 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2981 +
2982 + xregcomp(&comment_re,
2983 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2984 + REG_EXTENDED);
2985 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2986 +
2987 + while(1) {
2988 + int line_num = 0;
2989 + char *line;
2990 + char *type, *name, *value, *extra;
2991 +
2992 + line = file_read_line_alloc(file);
2993 + line_num++;
2994 + if (line == NULL) {
2995 + break;
2996 + }
2997 +
2998 + str_chomp(line);
2999 +
3000 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3001 + goto NEXT_LINE;
3002 + }
3003 +
3004 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3005 + str_chomp(line);
3006 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3007 + filename, line_num, line);
3008 + goto NEXT_LINE;
3009 + }
3010 +
3011 + /* This has to be so ugly to deal with optional quotation marks */
3012 + if (regmatch[2].rm_so > 0) {
3013 + type = strndup(line + regmatch[2].rm_so,
3014 + regmatch[2].rm_eo - regmatch[2].rm_so);
3015 + } else {
3016 + type = strndup(line + regmatch[3].rm_so,
3017 + regmatch[3].rm_eo - regmatch[3].rm_so);
3018 + }
3019 + if (regmatch[5].rm_so > 0) {
3020 + name = strndup(line + regmatch[5].rm_so,
3021 + regmatch[5].rm_eo - regmatch[5].rm_so);
3022 + } else {
3023 + name = strndup(line + regmatch[6].rm_so,
3024 + regmatch[6].rm_eo - regmatch[6].rm_so);
3025 + }
3026 + if (regmatch[8].rm_so > 0) {
3027 + value = strndup(line + regmatch[8].rm_so,
3028 + regmatch[8].rm_eo - regmatch[8].rm_so);
3029 + } else {
3030 + value = strndup(line + regmatch[9].rm_so,
3031 + regmatch[9].rm_eo - regmatch[9].rm_so);
3032 + }
3033 + extra = NULL;
3034 + if (regmatch[11].rm_so > 0) {
3035 + extra = strndup (line + regmatch[11].rm_so,
3036 + regmatch[11].rm_eo - regmatch[11].rm_so);
3037 + }
3038 +
3039 + /* We use the tmp_dest_nv_pair_list below instead of
3040 + conf->pkg_dest_list because we might encounter an
3041 + offline_root option later and that would invalidate the
3042 + directories we would have computed in
3043 + pkg_dest_list_init. (We do a similar thing with
3044 + tmp_src_nv_pair_list for sake of symmetry.) */
3045 + if (strcmp(type, "option") == 0) {
3046 + ipkg_conf_set_option(options, name, value);
3047 + } else if (strcmp(type, "src") == 0) {
3048 + if (!nv_pair_list_find(pkg_src_list, name)) {
3049 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3050 + } else {
3051 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3052 + name, value);
3053 + }
3054 + } else if (strcmp(type, "src/gz") == 0) {
3055 + if (!nv_pair_list_find(pkg_src_list, name)) {
3056 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3057 + } else {
3058 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3059 + name, value);
3060 + }
3061 + } else if (strcmp(type, "dest") == 0) {
3062 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3063 + } else if (strcmp(type, "lists_dir") == 0) {
3064 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3065 + if (*lists_dir == NULL) {
3066 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3067 + free(options);
3068 + return EINVAL;
3069 + }
3070 + sprintf (*lists_dir,"%s",value);
3071 + } else if (strcmp(type, "arch") == 0) {
3072 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3073 + if (!value) {
3074 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3075 + value = strdup("10");
3076 + }
3077 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3078 + } else {
3079 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3080 + "parameter: %s %s %s\n", type, name, value);
3081 + free(options);
3082 + return EINVAL;
3083 + }
3084 +
3085 + free(type);
3086 + free(name);
3087 + free(value);
3088 + if (extra)
3089 + free (extra);
3090 +
3091 + NEXT_LINE:
3092 + free(line);
3093 + }
3094 +
3095 + free(options);
3096 + regfree(&comment_re);
3097 + regfree(&valid_line_re);
3098 + fclose(file);
3099 +
3100 + return 0;
3101 +}
3102 +
3103 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3104 + const char *name, const char *value)
3105 +{
3106 + int i = 0;
3107 + while (options[i].name) {
3108 + if (strcmp(options[i].name, name) == 0) {
3109 + switch (options[i].type) {
3110 + case IPKG_OPT_TYPE_BOOL:
3111 + *((int *)options[i].value) = 1;
3112 + return 0;
3113 + case IPKG_OPT_TYPE_INT:
3114 + if (value) {
3115 + *((int *)options[i].value) = atoi(value);
3116 + return 0;
3117 + } else {
3118 + printf("%s: Option %s need an argument\n",
3119 + __FUNCTION__, name);
3120 + return EINVAL;
3121 + }
3122 + case IPKG_OPT_TYPE_STRING:
3123 + if (value) {
3124 + *((char **)options[i].value) = strdup(value);
3125 + return 0;
3126 + } else {
3127 + printf("%s: Option %s need an argument\n",
3128 + __FUNCTION__, name);
3129 + return EINVAL;
3130 + }
3131 + }
3132 + }
3133 + i++;
3134 + }
3135 +
3136 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3137 + __FUNCTION__, name, value);
3138 + return EINVAL;
3139 +}
3140 +
3141 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3142 +{
3143 + pkg_dest_list_elt_t *iter;
3144 + pkg_dest_t *dest;
3145 + pkg_vec_t *all;
3146 + pkg_t *pkg;
3147 + register int i;
3148 + int err;
3149 +
3150 + if (conf->noaction)
3151 + return 0;
3152 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3153 + dest = iter->data;
3154 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3155 + if (dest->status_file == NULL) {
3156 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3157 + __FUNCTION__, dest->status_file_name, strerror(errno));
3158 + }
3159 + }
3160 +
3161 + all = pkg_vec_alloc();
3162 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3163 +
3164 + for(i = 0; i < all->len; i++) {
3165 + pkg = all->pkgs[i];
3166 + /* We don't need most uninstalled packages in the status file */
3167 + if (pkg->state_status == SS_NOT_INSTALLED
3168 + && (pkg->state_want == SW_UNKNOWN
3169 + || pkg->state_want == SW_DEINSTALL
3170 + || pkg->state_want == SW_PURGE)) {
3171 + continue;
3172 + }
3173 + if (!pkg) {
3174 + fprintf(stderr, "Null package\n");
3175 + }
3176 + if (pkg->dest == NULL) {
3177 + fprintf(stderr, "%s: ERROR: Can't write status for "
3178 + "package %s since it has a NULL dest\n",
3179 + __FUNCTION__, pkg->name);
3180 + continue;
3181 + }
3182 + if (pkg->dest->status_file) {
3183 + pkg_print_status(pkg, pkg->dest->status_file);
3184 + }
3185 + }
3186 +
3187 + pkg_vec_free(all);
3188 +
3189 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3190 + dest = iter->data;
3191 + if (dest->status_file) {
3192 + err = ferror(dest->status_file);
3193 + fclose(dest->status_file);
3194 + dest->status_file = NULL;
3195 + if (!err) {
3196 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3197 + } else {
3198 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3199 + "retaining old %s\n", __FUNCTION__,
3200 + dest->status_file_tmp_name, dest->status_file_name);
3201 + }
3202 + }
3203 + }
3204 +
3205 + return 0;
3206 +}
3207 +
3208 +
3209 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3210 +{
3211 + char *root_filename;
3212 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3213 + return root_filename;
3214 +}
3215 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_conf.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.h
3216 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3217 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.h 2006-07-22 16:31:25.000000000 +0200
3218 @@ -0,0 +1,107 @@
3219 +/* ipkg_conf.h - the itsy package management system
3220 +
3221 + Carl D. Worth
3222 +
3223 + Copyright (C) 2001 University of Southern California
3224 +
3225 + This program is free software; you can redistribute it and/or
3226 + modify it under the terms of the GNU General Public License as
3227 + published by the Free Software Foundation; either version 2, or (at
3228 + your option) any later version.
3229 +
3230 + This program is distributed in the hope that it will be useful, but
3231 + WITHOUT ANY WARRANTY; without even the implied warranty of
3232 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3233 + General Public License for more details.
3234 +*/
3235 +
3236 +#ifndef IPKG_CONF_H
3237 +#define IPKG_CONF_H
3238 +
3239 +typedef struct ipkg_conf ipkg_conf_t;
3240 +
3241 +#include "hash_table.h"
3242 +#include "ipkg.h"
3243 +#include "args.h"
3244 +#include "pkg.h"
3245 +#include "pkg_hash.h"
3246 +#include "pkg_src_list.h"
3247 +#include "pkg_dest_list.h"
3248 +#include "nv_pair_list.h"
3249 +
3250 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3251 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3252 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3253 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3254 +
3255 +/* In case the config file defines no dest */
3256 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3257 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3258 +
3259 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3260 +
3261 +struct ipkg_conf
3262 +{
3263 + pkg_src_list_t pkg_src_list;
3264 + pkg_dest_list_t pkg_dest_list;
3265 + nv_pair_list_t arch_list;
3266 +
3267 + int restrict_to_default_dest;
3268 + pkg_dest_t *default_dest;
3269 +
3270 + char *tmp_dir;
3271 + const char *lists_dir;
3272 + const char *pending_dir;
3273 +
3274 + /* options */
3275 + int force_depends;
3276 + int force_defaults;
3277 + int force_overwrite;
3278 + int force_downgrade;
3279 + int force_reinstall;
3280 + int force_space;
3281 + int force_removal_of_dependent_packages;
3282 + int force_removal_of_essential_packages;
3283 + int nodeps; /* do not follow dependences */
3284 + int verbose_wget;
3285 + int multiple_providers;
3286 + char *offline_root;
3287 + char *offline_root_pre_script_cmd;
3288 + char *offline_root_post_script_cmd;
3289 + int query_all;
3290 + int verbosity;
3291 + int noaction;
3292 +
3293 + /* proxy options */
3294 + char *http_proxy;
3295 + char *ftp_proxy;
3296 + char *no_proxy;
3297 + char *proxy_user;
3298 + char *proxy_passwd;
3299 +
3300 + hash_table_t pkg_hash;
3301 + hash_table_t file_hash;
3302 + hash_table_t obs_file_hash;
3303 +};
3304 +
3305 +enum ipkg_option_type {
3306 + IPKG_OPT_TYPE_BOOL,
3307 + IPKG_OPT_TYPE_INT,
3308 + IPKG_OPT_TYPE_STRING
3309 +};
3310 +typedef enum ipkg_option_type ipkg_option_type_t;
3311 +
3312 +typedef struct ipkg_option ipkg_option_t;
3313 +struct ipkg_option {
3314 + const char *name;
3315 + const ipkg_option_type_t type;
3316 + const void *value;
3317 +};
3318 +
3319 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3320 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3321 +
3322 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3323 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3324 +
3325 +#endif
3326 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_configure.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.c
3327 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3328 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.c 2006-07-22 16:31:25.000000000 +0200
3329 @@ -0,0 +1,40 @@
3330 +/* ipkg_configure.c - the itsy package management system
3331 +
3332 + Carl D. Worth
3333 +
3334 + Copyright (C) 2001 University of Southern California
3335 +
3336 + This program is free software; you can redistribute it and/or
3337 + modify it under the terms of the GNU General Public License as
3338 + published by the Free Software Foundation; either version 2, or (at
3339 + your option) any later version.
3340 +
3341 + This program is distributed in the hope that it will be useful, but
3342 + WITHOUT ANY WARRANTY; without even the implied warranty of
3343 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3344 + General Public License for more details.
3345 +*/
3346 +
3347 +#include "ipkg.h"
3348 +
3349 +#include "ipkg_configure.h"
3350 +
3351 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3352 +{
3353 + int err;
3354 +
3355 + /* DPKG_INCOMPATIBILITY:
3356 + dpkg actually does some conffile handling here, rather than at the
3357 + end of ipkg_install(). Do we care? */
3358 + /* DPKG_INCOMPATIBILITY:
3359 + dpkg actually includes a version number to this script call */
3360 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3361 + if (err) {
3362 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3363 + return err;
3364 + }
3365 +
3366 + ipkg_state_changed++;
3367 + return 0;
3368 +}
3369 +
3370 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_configure.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.h
3371 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3372 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.h 2006-07-22 16:31:25.000000000 +0200
3373 @@ -0,0 +1,25 @@
3374 +/* ipkg_configure.h - the itsy package management system
3375 +
3376 + Carl D. Worth
3377 +
3378 + Copyright (C) 2001 University of Southern California
3379 +
3380 + This program is free software; you can redistribute it and/or
3381 + modify it under the terms of the GNU General Public License as
3382 + published by the Free Software Foundation; either version 2, or (at
3383 + your option) any later version.
3384 +
3385 + This program is distributed in the hope that it will be useful, but
3386 + WITHOUT ANY WARRANTY; without even the implied warranty of
3387 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3388 + General Public License for more details.
3389 +*/
3390 +
3391 +#ifndef IPKG_CONFIGURE_H
3392 +#define IPKG_CONFIGURE_H
3393 +
3394 +#include "ipkg_conf.h"
3395 +
3396 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3397 +
3398 +#endif
3399 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_download.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.c
3400 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3401 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.c 2006-07-22 16:31:25.000000000 +0200
3402 @@ -0,0 +1,190 @@
3403 +/* ipkg_download.c - the itsy package management system
3404 +
3405 + Carl D. Worth
3406 +
3407 + Copyright (C) 2001 University of Southern California
3408 +
3409 + This program is free software; you can redistribute it and/or
3410 + modify it under the terms of the GNU General Public License as
3411 + published by the Free Software Foundation; either version 2, or (at
3412 + your option) any later version.
3413 +
3414 + This program is distributed in the hope that it will be useful, but
3415 + WITHOUT ANY WARRANTY; without even the implied warranty of
3416 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3417 + General Public License for more details.
3418 +*/
3419 +
3420 +#include "ipkg.h"
3421 +#include "ipkg_download.h"
3422 +#include "ipkg_message.h"
3423 +
3424 +#include "sprintf_alloc.h"
3425 +#include "xsystem.h"
3426 +#include "file_util.h"
3427 +#include "str_util.h"
3428 +
3429 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3430 +{
3431 + int err = 0;
3432 +
3433 + char *src_basec = strdup(src);
3434 + char *src_base = basename(src_basec);
3435 + char *tmp_file_location;
3436 + char *cmd;
3437 +
3438 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3439 +
3440 + fflush(stdout);
3441 +
3442 + if (str_starts_with(src, "file:")) {
3443 + int ret;
3444 + const char *file_src = src + 5;
3445 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3446 + ret = file_copy(src + 5, dest_file_name);
3447 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3448 + return ret;
3449 + }
3450 +
3451 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3452 + err = unlink(tmp_file_location);
3453 + if (err && errno != ENOENT) {
3454 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3455 + __FUNCTION__, tmp_file_location, strerror(errno));
3456 + free(tmp_file_location);
3457 + return errno;
3458 + }
3459 +
3460 + if (conf->http_proxy) {
3461 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3462 + setenv("http_proxy", conf->http_proxy, 1);
3463 + }
3464 + if (conf->ftp_proxy) {
3465 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3466 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3467 + }
3468 + if (conf->no_proxy) {
3469 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3470 + setenv("no_proxy", conf->no_proxy, 1);
3471 + }
3472 +
3473 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3474 + sprintf_alloc(&cmd, "wget %s -P %s %s",
3475 + conf->verbose_wget ? "" : "-q",
3476 + conf->tmp_dir,
3477 + src);
3478 + err = xsystem(cmd);
3479 + if (err) {
3480 + if (err != -1) {
3481 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3482 + __FUNCTION__, err, cmd);
3483 + }
3484 + unlink(tmp_file_location);
3485 + free(tmp_file_location);
3486 + free(src_basec);
3487 + free(cmd);
3488 + return EINVAL;
3489 + }
3490 + free(cmd);
3491 +
3492 + err = file_move(tmp_file_location, dest_file_name);
3493 +
3494 + free(tmp_file_location);
3495 + free(src_basec);
3496 +
3497 + if (err) {
3498 + return err;
3499 + }
3500 +
3501 + return 0;
3502 +}
3503 +
3504 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3505 +{
3506 + int err;
3507 + char *url;
3508 +
3509 + if (pkg->src == NULL) {
3510 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3511 + pkg->name, pkg->parent->name);
3512 + return -1;
3513 + }
3514 +
3515 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3516 +
3517 + /* XXX: BUG: The pkg->filename might be something like
3518 + "../../foo.ipk". While this is correct, and exactly what we
3519 + want to use to construct url above, here we actually need to
3520 + use just the filename part, without any directory. */
3521 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3522 +
3523 + err = ipkg_download(conf, url, pkg->local_filename);
3524 + free(url);
3525 +
3526 + return err;
3527 +}
3528 +
3529 +/*
3530 + * Downloads file from url, installs in package database, return package name.
3531 + */
3532 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3533 +{
3534 + int err = 0;
3535 + pkg_t *pkg;
3536 + pkg = pkg_new();
3537 + if (pkg == NULL)
3538 + return ENOMEM;
3539 +
3540 + if (str_starts_with(url, "http://")
3541 + || str_starts_with(url, "ftp://")) {
3542 + char *tmp_file;
3543 + char *file_basec = strdup(url);
3544 + char *file_base = basename(file_basec);
3545 +
3546 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3547 + err = ipkg_download(conf, url, tmp_file);
3548 + if (err)
3549 + return err;
3550 +
3551 + err = pkg_init_from_file(pkg, tmp_file);
3552 + if (err)
3553 + return err;
3554 + pkg->local_filename = strdup(tmp_file);
3555 +
3556 + free(tmp_file);
3557 + free(file_basec);
3558 +
3559 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3560 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3561 +
3562 + err = pkg_init_from_file(pkg, url);
3563 + if (err)
3564 + return err;
3565 + pkg->local_filename = strdup(url);
3566 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3567 + pkg->provided_by_hand = 1;
3568 +
3569 + } else {
3570 + pkg_deinit(pkg);
3571 + free(pkg);
3572 + return 0;
3573 + }
3574 +
3575 + if (!pkg->architecture) {
3576 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3577 + return -EINVAL;
3578 + }
3579 +
3580 + pkg->dest = conf->default_dest;
3581 + pkg->state_want = SW_INSTALL;
3582 + pkg->state_flag |= SF_PREFER;
3583 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3584 + if ( pkg == NULL ){
3585 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3586 + return 0;
3587 + }
3588 + if (namep) {
3589 + *namep = strdup(pkg->name);
3590 + }
3591 + return 0;
3592 +}
3593 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_download.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h
3594 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3595 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-07-22 16:31:25.000000000 +0200
3596 @@ -0,0 +1,30 @@
3597 +/* ipkg_download.h - the itsy package management system
3598 +
3599 + Carl D. Worth
3600 +
3601 + Copyright (C) 2001 University of Southern California
3602 +
3603 + This program is free software; you can redistribute it and/or
3604 + modify it under the terms of the GNU General Public License as
3605 + published by the Free Software Foundation; either version 2, or (at
3606 + your option) any later version.
3607 +
3608 + This program is distributed in the hope that it will be useful, but
3609 + WITHOUT ANY WARRANTY; without even the implied warranty of
3610 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3611 + General Public License for more details.
3612 +*/
3613 +
3614 +#ifndef IPKG_DOWNLOAD_H
3615 +#define IPKG_DOWNLOAD_H
3616 +
3617 +#include "ipkg_conf.h"
3618 +
3619 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3620 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3621 +/*
3622 + * Downloads file from url, installs in package database, return package name.
3623 + */
3624 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3625 +
3626 +#endif
3627 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h
3628 --- busybox-1.2.0-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3629 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h 2006-07-22 16:31:25.000000000 +0200
3630 @@ -0,0 +1,74 @@
3631 +/* ipkg.h - the itsy package management system
3632 +
3633 + Carl D. Worth
3634 +
3635 + Copyright (C) 2001 University of Southern California
3636 +
3637 + This program is free software; you can redistribute it and/or
3638 + modify it under the terms of the GNU General Public License as
3639 + published by the Free Software Foundation; either version 2, or (at
3640 + your option) any later version.
3641 +
3642 + This program is distributed in the hope that it will be useful, but
3643 + WITHOUT ANY WARRANTY; without even the implied warranty of
3644 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3645 + General Public License for more details.
3646 +*/
3647 +
3648 +#ifndef IPKG_H
3649 +#define IPKG_H
3650 +
3651 +/*
3652 +#ifdef HAVE_CONFIG_H
3653 +#include "config.h"
3654 +#endif
3655 +*/
3656 +
3657 +#if 0
3658 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3659 +#endif
3660 +
3661 +#include "ipkg_includes.h"
3662 +#include "ipkg_conf.h"
3663 +#include "ipkg_message.h"
3664 +
3665 +#define IPKG_PKG_EXTENSION ".ipk"
3666 +#define DPKG_PKG_EXTENSION ".deb"
3667 +
3668 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3669 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3670 +
3671 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3672 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3673 +#define IPKG_INFO_DIR_SUFFIX "info"
3674 +#define IPKG_STATUS_FILE_SUFFIX "status"
3675 +
3676 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3677 +
3678 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3679 +
3680 +#define IPKG_VERSION "0.99.162"
3681 +
3682 +
3683 +enum ipkg_error {
3684 + IPKG_SUCCESS = 0,
3685 + IPKG_PKG_DEPS_UNSATISFIED,
3686 + IPKG_PKG_IS_ESSENTIAL,
3687 + IPKG_PKG_HAS_DEPENDENTS,
3688 + IPKG_PKG_HAS_NO_CANDIDATE
3689 +};
3690 +typedef enum ipkg_error ipkg_error_t;
3691 +
3692 +extern int ipkg_state_changed;
3693 +
3694 +
3695 +struct errlist {
3696 + char * errmsg;
3697 + struct errlist * next;
3698 +} ;
3699 +
3700 +extern struct errlist* error_list;
3701 +
3702 +extern ipkg_conf_t *global_conf;
3703 +
3704 +#endif
3705 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h
3706 --- busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3707 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-07-22 16:31:25.000000000 +0200
3708 @@ -0,0 +1,79 @@
3709 +#ifndef IPKG_INCLUDES_H
3710 +#define IPKG_INCLUDES_H
3711 +
3712 +/* Define to 1 if you have the <memory.h> header file. */
3713 +#define HAVE_MEMORY_H 1
3714 +
3715 +/* Define to 1 if you have the <regex.h> header file. */
3716 +#define HAVE_REGEX_H 1
3717 +
3718 +/* Define to 1 if you have the <stdlib.h> header file. */
3719 +#define HAVE_STDLIB_H 1
3720 +
3721 +/* Define to 1 if you have the <strings.h> header file. */
3722 +#define HAVE_STRINGS_H 1
3723 +
3724 +/* Define to 1 if you have the <string.h> header file. */
3725 +#define HAVE_STRING_H 1
3726 +
3727 +/* Define to 1 if you have the <sys/stat.h> header file. */
3728 +#define HAVE_SYS_STAT_H 1
3729 +
3730 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3731 +#define HAVE_SYS_WAIT_H 1
3732 +
3733 +/* Define to 1 if you have the <unistd.h> header file. */
3734 +#define HAVE_UNISTD_H 1
3735 +
3736 +/* Define to 1 if you have the ANSI C header files. */
3737 +#define STDC_HEADERS 1
3738 +
3739 +
3740 +#include <stdio.h>
3741 +
3742 +#if STDC_HEADERS
3743 +# include <stdlib.h>
3744 +# include <stdarg.h>
3745 +# include <stddef.h>
3746 +# include <ctype.h>
3747 +# include <errno.h>
3748 +#else
3749 +# if HAVE_STDLIB_H
3750 +# include <stdlib.h>
3751 +# endif
3752 +#endif
3753 +
3754 +#if HAVE_REGEX_H
3755 +# include <regex.h>
3756 +#endif
3757 +
3758 +#if HAVE_STRING_H
3759 +# if !STDC_HEADERS && HAVE_MEMORY_H
3760 +# include <memory.h>
3761 +# endif
3762 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3763 +# if __GNUC__
3764 +# define __USE_GNU 1
3765 +# endif
3766 +# include <string.h>
3767 +# undef __USE_GNU
3768 +#endif
3769 +
3770 +#if HAVE_STRINGS_H
3771 +# include <strings.h>
3772 +#endif
3773 +
3774 +#if HAVE_SYS_STAT_H
3775 +# include <sys/stat.h>
3776 +#endif
3777 +
3778 +#if HAVE_SYS_WAIT_H
3779 +# include <sys/wait.h>
3780 +#endif
3781 +
3782 +#if HAVE_UNISTD_H
3783 +# include <sys/types.h>
3784 +# include <unistd.h>
3785 +#endif
3786 +
3787 +#endif /* IPKG_INCLUDES_H */
3788 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_install.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c
3789 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3790 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-07-22 16:31:25.000000000 +0200
3791 @@ -0,0 +1,1942 @@
3792 +/* ipkg_install.c - the itsy package management system
3793 +
3794 + Carl D. Worth
3795 +
3796 + Copyright (C) 2001 University of Southern California
3797 +
3798 + This program is free software; you can redistribute it and/or
3799 + modify it under the terms of the GNU General Public License as
3800 + published by the Free Software Foundation; either version 2, or (at
3801 + your option) any later version.
3802 +
3803 + This program is distributed in the hope that it will be useful, but
3804 + WITHOUT ANY WARRANTY; without even the implied warranty of
3805 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3806 + General Public License for more details.
3807 +*/
3808 +
3809 +#include "ipkg.h"
3810 +#include <errno.h>
3811 +#include <dirent.h>
3812 +#include <glob.h>
3813 +#include <time.h>
3814 +#include <signal.h>
3815 +typedef void (*sighandler_t)(int);
3816 +
3817 +#include "pkg.h"
3818 +#include "pkg_hash.h"
3819 +#include "pkg_extract.h"
3820 +
3821 +#include "ipkg_install.h"
3822 +#include "ipkg_configure.h"
3823 +#include "ipkg_download.h"
3824 +#include "ipkg_remove.h"
3825 +
3826 +#include "ipkg_utils.h"
3827 +#include "ipkg_message.h"
3828 +
3829 +#include "sprintf_alloc.h"
3830 +#include "file_util.h"
3831 +#include "str_util.h"
3832 +#include "xsystem.h"
3833 +#include "user.h"
3834 +
3835 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3836 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3837 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3838 +
3839 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3842 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3843 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3847 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3848 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3849 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3850 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3851 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3852 +
3853 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3854 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3855 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3856 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3857 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3858 +
3859 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3860 +
3861 +static int user_prefers_old_conffile(const char *file, const char *backup);
3862 +
3863 +static char *backup_filename_alloc(const char *file_name);
3864 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3865 +static int backup_exists_for(const char *file_name);
3866 +static int backup_remove(const char *file_name);
3867 +
3868 +
3869 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3870 +{
3871 + int err, cmp;
3872 + pkg_t *pkg, *old;
3873 + char *old_version, *new_version;
3874 +
3875 + pkg = pkg_new();
3876 + if (pkg == NULL) {
3877 + return ENOMEM;
3878 + }
3879 +
3880 + err = pkg_init_from_file(pkg, filename);
3881 + if (err) {
3882 + return err;
3883 + }
3884 +
3885 + if (!pkg->architecture) {
3886 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3887 + return -EINVAL;
3888 + }
3889 +
3890 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3891 + freeing the pkg that we pass in. It might be nice to clean this up
3892 + if possible. */
3893 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3894 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3895 +
3896 + pkg->local_filename = strdup(filename);
3897 +
3898 + if (old) {
3899 + old_version = pkg_version_str_alloc(old);
3900 + new_version = pkg_version_str_alloc(pkg);
3901 +
3902 + cmp = pkg_compare_versions(old, pkg);
3903 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3904 + cmp = -1 ; /* then we force ipkg to downgrade */
3905 + /* We need to use a value < 0 because in the 0 case we are asking to */
3906 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3907 + }
3908 + if (cmp > 0) {
3909 + ipkg_message(conf, IPKG_NOTICE,
3910 + "Not downgrading package %s on %s from %s to %s.\n",
3911 + old->name, old->dest->name, old_version, new_version);
3912 + pkg->state_want = SW_DEINSTALL;
3913 + pkg->state_flag |= SF_OBSOLETE;
3914 + free(old_version);
3915 + free(new_version);
3916 + return 0;
3917 + } else {
3918 + free(old_version);
3919 + free(new_version);
3920 + }
3921 + }
3922 +
3923 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3924 + return ipkg_install_pkg(conf, pkg,0);
3925 +}
3926 +
3927 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3928 +{
3929 + int cmp;
3930 + pkg_t *old, *new;
3931 + char *old_version, *new_version;
3932 +
3933 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3934 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3935 + if ( old )
3936 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3937 +
3938 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3939 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3940 + if ( new )
3941 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3942 +
3943 +/* Pigi Basically here is broken the version stuff.
3944 + What's happening is that nothing provide the version to differents
3945 + functions, so the returned struct is always the latest.
3946 + That's why the install by name don't work.
3947 +*/
3948 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3949 +
3950 + if ( old )
3951 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3952 + if ( new )
3953 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3954 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3955 +
3956 + if (new == NULL) {
3957 + return IPKG_PKG_HAS_NO_CANDIDATE;
3958 + }
3959 +
3960 + new->state_flag |= SF_USER;
3961 + if (old) {
3962 + old_version = pkg_version_str_alloc(old);
3963 + new_version = pkg_version_str_alloc(new);
3964 +
3965 + cmp = pkg_compare_versions(old, new);
3966 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3967 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3968 + cmp = -1 ; /* then we force ipkg to downgrade */
3969 + /* We need to use a value < 0 because in the 0 case we are asking to */
3970 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3971 + }
3972 + ipkg_message(conf, IPKG_DEBUG,
3973 + "Comparing visible versions of pkg %s:"
3974 + "\n\t%s is installed "
3975 + "\n\t%s is available "
3976 + "\n\t%d was comparison result\n",
3977 + pkg_name, old_version, new_version, cmp);
3978 + if (cmp == 0 && !conf->force_reinstall) {
3979 + ipkg_message(conf, IPKG_NOTICE,
3980 + "Package %s (%s) installed in %s is up to date.\n",
3981 + old->name, old_version, old->dest->name);
3982 + free(old_version);
3983 + free(new_version);
3984 + return 0;
3985 + } else if (cmp > 0) {
3986 + ipkg_message(conf, IPKG_NOTICE,
3987 + "Not downgrading package %s on %s from %s to %s.\n",
3988 + old->name, old->dest->name, old_version, new_version);
3989 + free(old_version);
3990 + free(new_version);
3991 + return 0;
3992 + } else if (cmp < 0) {
3993 + new->dest = old->dest;
3994 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3995 + }
3996 + }
3997 +
3998 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3999 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4000 + return any kind of integer, (might be errno from a syscall,
4001 + etc.). This is a real mess and will need to be cleaned up if
4002 + anyone ever wants to make a nice libipkg. */
4003 +
4004 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4005 + return ipkg_install_pkg(conf, new,0);
4006 +}
4007 +
4008 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4009 +{
4010 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4011 + int i;
4012 + ipkg_error_t err;
4013 + abstract_pkg_t *ppkg ;
4014 +
4015 + if (providers == NULL)
4016 + return IPKG_PKG_HAS_NO_CANDIDATE;
4017 +
4018 + for (i = 0; i < providers->len; i++) {
4019 + ppkg = abstract_pkg_vec_get(providers, i);
4020 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4021 + err = ipkg_install_by_name(conf, ppkg->name);
4022 + if (err)
4023 + return err;
4024 +/* XXX Maybe ppkg should be freed ? */
4025 + }
4026 + return 0;
4027 +}
4028 +
4029 +/*
4030 + * Walk dependence graph starting with pkg, collect packages to be
4031 + * installed into pkgs_needed, in dependence order.
4032 + */
4033 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4034 +{
4035 + int i, err;
4036 + pkg_vec_t *depends = pkg_vec_alloc();
4037 + char **unresolved = NULL;
4038 + int ndepends;
4039 +
4040 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4041 + pkg, depends,
4042 + &unresolved);
4043 +
4044 + if (unresolved) {
4045 + ipkg_message(conf, IPKG_ERROR,
4046 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4047 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4048 + while (*unresolved) {
4049 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4050 + unresolved++;
4051 + }
4052 + ipkg_message(conf, IPKG_ERROR, "\n");
4053 + if (! conf->force_depends) {
4054 + ipkg_message(conf, IPKG_INFO,
4055 + "This could mean that your package list is out of date or that the packages\n"
4056 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4057 + "of this problem try again with the '-force-depends' option.\n");
4058 + pkg_vec_free(depends);
4059 + return IPKG_PKG_DEPS_UNSATISFIED;
4060 + }
4061 + }
4062 +
4063 + if (ndepends <= 0) {
4064 + pkg_vec_free(depends);
4065 + return 0;
4066 + }
4067 +
4068 + for (i = 0; i < depends->len; i++) {
4069 + pkg_t *dep = depends->pkgs[i];
4070 + /* The package was uninstalled when we started, but another
4071 + dep earlier in this loop may have depended on it and pulled
4072 + it in, so check first. */
4073 + if ((dep->state_status != SS_INSTALLED)
4074 + && (dep->state_status != SS_UNPACKED)
4075 + && (dep->state_want != SW_INSTALL)) {
4076 +
4077 + /* Mark packages as to-be-installed */
4078 + dep->state_want = SW_INSTALL;
4079 +
4080 + /* Dependencies should be installed the same place as pkg */
4081 + if (dep->dest == NULL) {
4082 + dep->dest = pkg->dest;
4083 + }
4084 +
4085 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4086 + if (err) {
4087 + pkg_vec_free(depends);
4088 + return err;
4089 + }
4090 + }
4091 + }
4092 + if (pkgs_needed)
4093 + pkg_vec_insert(pkgs_needed, pkg);
4094 +
4095 + pkg_vec_free(depends);
4096 +
4097 + return 0;
4098 +}
4099 +
4100 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4101 +{
4102 + int cmp;
4103 + pkg_t *old, *new;
4104 + char *old_version, *new_version;
4105 +
4106 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4107 +
4108 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4109 + if (new == NULL) {
4110 + return IPKG_PKG_HAS_NO_CANDIDATE;
4111 + }
4112 + if (old) {
4113 + old_version = pkg_version_str_alloc(old);
4114 + new_version = pkg_version_str_alloc(new);
4115 +
4116 + cmp = pkg_compare_versions(old, new);
4117 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4118 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4119 + cmp = -1 ; /* then we force ipkg to downgrade */
4120 + /* We need to use a value < 0 because in the 0 case we are asking to */
4121 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4122 + }
4123 + ipkg_message(conf, IPKG_DEBUG,
4124 + "comparing visible versions of pkg %s:"
4125 + "\n\t%s is installed "
4126 + "\n\t%s is available "
4127 + "\n\t%d was comparison result\n",
4128 + pkg_name, old_version, new_version, cmp);
4129 + if (cmp == 0 && !conf->force_reinstall) {
4130 + ipkg_message(conf, IPKG_NOTICE,
4131 + "Package %s (%s) installed in %s is up to date.\n",
4132 + old->name, old_version, old->dest->name);
4133 + free(old_version);
4134 + free(new_version);
4135 + return 0;
4136 + } else if (cmp > 0) {
4137 + ipkg_message(conf, IPKG_NOTICE,
4138 + "Not downgrading package %s on %s from %s to %s.\n",
4139 + old->name, old->dest->name, old_version, new_version);
4140 + free(old_version);
4141 + free(new_version);
4142 + return 0;
4143 + } else if (cmp < 0) {
4144 + new->dest = old->dest;
4145 + old->state_want = SW_DEINSTALL;
4146 + old->state_flag |= SF_OBSOLETE;
4147 + }
4148 + }
4149 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4150 +}
4151 +
4152 +\f
4153 +
4154 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4155 +{
4156 + int i, err;
4157 + pkg_vec_t *depends = pkg_vec_alloc();
4158 + pkg_t *dep;
4159 + char **unresolved = NULL;
4160 + int ndepends;
4161 +
4162 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4163 + pkg, depends,
4164 + &unresolved);
4165 +
4166 + if (unresolved) {
4167 + ipkg_message(conf, IPKG_ERROR,
4168 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4169 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4170 + while (*unresolved) {
4171 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4172 + unresolved++;
4173 + }
4174 + ipkg_message(conf, IPKG_ERROR, "\n");
4175 + if (! conf->force_depends) {
4176 + ipkg_message(conf, IPKG_INFO,
4177 + "This could mean that your package list is out of date or that the packages\n"
4178 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4179 + "of this problem try again with the '-force-depends' option.\n");
4180 + pkg_vec_free(depends);
4181 + return IPKG_PKG_DEPS_UNSATISFIED;
4182 + }
4183 + }
4184 +
4185 + if (ndepends <= 0) {
4186 + return 0;
4187 + }
4188 +
4189 + /* Mark packages as to-be-installed */
4190 + for (i=0; i < depends->len; i++) {
4191 + /* Dependencies should be installed the same place as pkg */
4192 + if (depends->pkgs[i]->dest == NULL) {
4193 + depends->pkgs[i]->dest = pkg->dest;
4194 + }
4195 + depends->pkgs[i]->state_want = SW_INSTALL;
4196 + }
4197 +
4198 + for (i = 0; i < depends->len; i++) {
4199 + dep = depends->pkgs[i];
4200 + /* The package was uninstalled when we started, but another
4201 + dep earlier in this loop may have depended on it and pulled
4202 + it in, so check first. */
4203 + if ((dep->state_status != SS_INSTALLED)
4204 + && (dep->state_status != SS_UNPACKED)) {
4205 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4206 + err = ipkg_install_pkg(conf, dep,0);
4207 + if (err) {
4208 + pkg_vec_free(depends);
4209 + return err;
4210 + }
4211 + }
4212 + }
4213 +
4214 + pkg_vec_free(depends);
4215 +
4216 + return 0;
4217 +}
4218 +
4219 +
4220 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4221 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4222 +{
4223 + if (conf->nodeps == 0) {
4224 + int i;
4225 + pkg_vec_t *installed = pkg_vec_alloc();
4226 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4227 + for (i = 0; i < installed->len; i++) {
4228 + pkg_t *pkg = installed->pkgs[i];
4229 + satisfy_dependencies_for(conf, pkg);
4230 + }
4231 + pkg_vec_free(installed);
4232 + }
4233 + return 0;
4234 +}
4235 +
4236 +\f
4237 +
4238 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4239 +{
4240 + int i;
4241 + pkg_vec_t *conflicts = NULL;
4242 + int level;
4243 + const char *prefix;
4244 + if (conf->force_depends) {
4245 + level = IPKG_NOTICE;
4246 + prefix = "Warning";
4247 + } else {
4248 + level = IPKG_ERROR;
4249 + prefix = "ERROR";
4250 + }
4251 +
4252 + if (!conf->force_depends)
4253 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4254 +
4255 + if (conflicts) {
4256 + ipkg_message(conf, level,
4257 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4258 + i = 0;
4259 + while (i < conflicts->len)
4260 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4261 + ipkg_message(conf, level, "\n");
4262 + pkg_vec_free(conflicts);
4263 + return IPKG_PKG_DEPS_UNSATISFIED;
4264 + }
4265 + return 0;
4266 +}
4267 +
4268 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4269 +{
4270 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4271 + str_list_elt_t *iter;
4272 +
4273 + for (iter = new_list->head; iter; iter = iter->next) {
4274 + char *new_file = iter->data;
4275 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4276 + if (!new_file)
4277 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4278 + if (!owner || (owner == old_pkg))
4279 + file_hash_set_file_owner(conf, new_file, new_pkg);
4280 + }
4281 + if (old_pkg) {
4282 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4283 + for (iter = old_list->head; iter; iter = iter->next) {
4284 + char *old_file = iter->data;
4285 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4286 + if (owner == old_pkg) {
4287 + /* obsolete */
4288 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4289 + }
4290 + }
4291 + }
4292 + return 0;
4293 +}
4294 +
4295 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4296 +{
4297 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4298 +
4299 + /* sma 6.20.02: yup; here's the first bit */
4300 + /*
4301 + * XXX: BUG easy for cworth
4302 + * 1) please point the call below to the correct current root destination
4303 + * 2) we need to resolve how to check the required space for a pending pkg,
4304 + * my diddling with the .ipk file size below isn't going to cut it.
4305 + * 3) return a proper error code instead of 1
4306 + */
4307 + int comp_size, blocks_available;
4308 +
4309 + if (!conf->force_space && pkg->installed_size != NULL) {
4310 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4311 +
4312 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4313 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4314 + comp_size = (int)((comp_size + 1023) / 1024);
4315 +
4316 + if (comp_size >= blocks_available) {
4317 + ipkg_message(conf, IPKG_ERROR,
4318 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4319 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4320 + return ENOSPC;
4321 + }
4322 + }
4323 + return 0;
4324 +}
4325 +
4326 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4327 +{
4328 + int err;
4329 + char *conffiles_file_name;
4330 + char *root_dir;
4331 + FILE *conffiles_file;
4332 +
4333 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4334 +
4335 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4336 + if (pkg->tmp_unpack_dir == NULL) {
4337 + ipkg_message(conf, IPKG_ERROR,
4338 + "%s: Failed to create temporary directory '%s': %s\n",
4339 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4340 + return errno;
4341 + }
4342 +
4343 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4344 + if (err) {
4345 + return err;
4346 + }
4347 +
4348 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4349 + conffiles. Seems like I should be able to get everything to go
4350 + through pkg_init_from_file. If so, maybe it would make sense to
4351 + move all of unpack_pkg_control_files to that function. */
4352 +
4353 + /* Don't need to re-read conffiles if we already have it */
4354 + if (pkg->conffiles.head) {
4355 + return 0;
4356 + }
4357 +
4358 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4359 + if (! file_exists(conffiles_file_name)) {
4360 + free(conffiles_file_name);
4361 + return 0;
4362 + }
4363 +
4364 + conffiles_file = fopen(conffiles_file_name, "r");
4365 + if (conffiles_file == NULL) {
4366 + fprintf(stderr, "%s: failed to open %s: %s\n",
4367 + __FUNCTION__, conffiles_file_name, strerror(errno));
4368 + free(conffiles_file_name);
4369 + return errno;
4370 + }
4371 + free(conffiles_file_name);
4372 +
4373 + while (1) {
4374 + char *cf_name;
4375 + char *cf_name_in_dest;
4376 +
4377 + cf_name = file_read_line_alloc(conffiles_file);
4378 + if (cf_name == NULL) {
4379 + break;
4380 + }
4381 + str_chomp(cf_name);
4382 + if (cf_name[0] == '\0') {
4383 + continue;
4384 + }
4385 +
4386 + /* Prepend dest->root_dir to conffile name.
4387 + Take pains to avoid multiple slashes. */
4388 + root_dir = pkg->dest->root_dir;
4389 + if (conf->offline_root)
4390 + /* skip the offline_root prefix */
4391 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4392 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4393 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4394 +
4395 + /* Can't get an md5sum now, (file isn't extracted yet).
4396 + We'll wait until resolve_conffiles */
4397 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4398 +
4399 + free(cf_name);
4400 + free(cf_name_in_dest);
4401 + }
4402 +
4403 + fclose(conffiles_file);
4404 +
4405 + return 0;
4406 +}
4407 +
4408 +/* returns number of installed replacees */
4409 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4410 +{
4411 + abstract_pkg_t **replaces = pkg->replaces;
4412 + int replaces_count = pkg->replaces_count;
4413 + int i, j;
4414 + for (i = 0; i < replaces_count; i++) {
4415 + abstract_pkg_t *ab_pkg = replaces[i];
4416 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4417 + if (pkg_vec) {
4418 + for (j = 0; j < pkg_vec->len; j++) {
4419 + pkg_t *replacee = pkg_vec->pkgs[j];
4420 + if (!pkg_conflicts(pkg, replacee))
4421 + continue;
4422 + if (replacee->state_status == SS_INSTALLED) {
4423 + pkg_vec_insert(installed_replacees, replacee);
4424 + }
4425 + }
4426 + }
4427 + }
4428 + return installed_replacees->len;
4429 +}
4430 +
4431 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4432 +{
4433 + int i;
4434 + int replaces_count = replacees->len;
4435 + for (i = 0; i < replaces_count; i++) {
4436 + pkg_t *replacee = replacees->pkgs[i];
4437 + int err;
4438 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4439 + err = ipkg_remove_pkg(conf, replacee,0);
4440 + if (err)
4441 + return err;
4442 + }
4443 + return 0;
4444 +}
4445 +
4446 +/* to unwind the removal: make sure they are installed */
4447 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4448 +{
4449 + int i, err;
4450 + int replaces_count = replacees->len;
4451 + for (i = 0; i < replaces_count; i++) {
4452 + pkg_t *replacee = replacees->pkgs[i];
4453 + if (replacee->state_status != SS_INSTALLED) {
4454 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4455 + err = ipkg_install_pkg(conf, replacee,0);
4456 + if (err)
4457 + return err;
4458 + }
4459 + }
4460 + return 0;
4461 +}
4462 +
4463 +int caught_sigint = 0;
4464 +static void ipkg_install_pkg_sigint_handler(int sig)
4465 +{
4466 + caught_sigint = sig;
4467 +}
4468 +
4469 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4470 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4471 +{
4472 + if (old_pkg) {
4473 + char message_out[15];
4474 + char *old_version = pkg_version_str_alloc(old_pkg);
4475 + char *new_version = pkg_version_str_alloc(pkg);
4476 + int cmp = pkg_compare_versions(old_pkg, pkg);
4477 + int rc = 0;
4478 +
4479 + memset(message_out,'\x0',15);
4480 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4481 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4482 + cmp = -1 ; /* then we force ipkg to downgrade */
4483 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4484 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4485 + }
4486 +
4487 + if (cmp > 0) {
4488 + ipkg_message(conf, IPKG_NOTICE,
4489 + "Not downgrading package %s on %s from %s to %s.\n",
4490 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4491 + rc = 1;
4492 + } else if (cmp < 0) {
4493 + ipkg_message(conf, IPKG_NOTICE,
4494 + "%s%s on %s from %s to %s...\n",
4495 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4496 + pkg->dest = old_pkg->dest;
4497 + rc = 0;
4498 + } else /* cmp == 0 */ {
4499 + if (conf->force_reinstall) {
4500 + ipkg_message(conf, IPKG_NOTICE,
4501 + "Reinstalling %s (%s) on %s...\n",
4502 + pkg->name, new_version, old_pkg->dest->name);
4503 + pkg->dest = old_pkg->dest;
4504 + rc = 0;
4505 + } else {
4506 + ipkg_message(conf, IPKG_NOTICE,
4507 + "Not installing %s (%s) on %s -- already installed.\n",
4508 + pkg->name, new_version, old_pkg->dest->name);
4509 + rc = 1;
4510 + }
4511 + }
4512 + free(old_version);
4513 + free(new_version);
4514 + return rc;
4515 + } else {
4516 + char message_out[15] ;
4517 + memset(message_out,'\x0',15);
4518 + if ( message )
4519 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4520 + else
4521 + strncpy( message_out,"Installing ",strlen("Installing ") );
4522 + char *version = pkg_version_str_alloc(pkg);
4523 +
4524 + ipkg_message(conf, IPKG_NOTICE,
4525 + "%s%s (%s) to %s...\n", message_out,
4526 + pkg->name, version, pkg->dest->name);
4527 + free(version);
4528 + return 0;
4529 + }
4530 +}
4531 +
4532 +/* and now the meat... */
4533 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4534 +{
4535 + int err = 0;
4536 + int message = 0;
4537 + pkg_t *old_pkg = NULL;
4538 + pkg_vec_t *replacees;
4539 + abstract_pkg_t *ab_pkg = NULL;
4540 + int old_state_flag;
4541 + char* file_md5;
4542 +
4543 +
4544 + if ( from_upgrade )
4545 + message = 1; /* Coming from an upgrade, and should change the output message */
4546 +
4547 + if (!pkg) {
4548 + ipkg_message(conf, IPKG_ERROR,
4549 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4550 + return -EINVAL;
4551 + }
4552 +
4553 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4554 +
4555 + if (!pkg_arch_supported(conf, pkg)) {
4556 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4557 + pkg->architecture, pkg->name);
4558 + return -EINVAL;
4559 + }
4560 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4561 + err = satisfy_dependencies_for(conf, pkg);
4562 + if (err) { return err; }
4563 +
4564 + ipkg_message(conf, IPKG_NOTICE,
4565 + "Package %s is already installed in %s.\n",
4566 + pkg->name, pkg->dest->name);
4567 + return 0;
4568 + }
4569 +
4570 + if (pkg->dest == NULL) {
4571 + pkg->dest = conf->default_dest;
4572 + }
4573 +
4574 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4575 +
4576 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4577 + if (err) { return err; }
4578 +
4579 + pkg->state_want = SW_INSTALL;
4580 + if (old_pkg){
4581 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4582 + }
4583 +
4584 +
4585 + /* Abhaya: conflicts check */
4586 + err = check_conflicts_for(conf, pkg);
4587 + if (err) { return err; }
4588 +
4589 + /* this setup is to remove the upgrade scenario in the end when
4590 + installing pkg A, A deps B & B deps on A. So both B and A are
4591 + installed. Then A's installation is started resulting in an
4592 + uncecessary upgrade */
4593 + if (pkg->state_status == SS_INSTALLED
4594 + && conf->force_reinstall == 0) return 0;
4595 +
4596 + err = verify_pkg_installable(conf, pkg);
4597 + if (err) { return err; }
4598 +
4599 + if (pkg->local_filename == NULL) {
4600 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4601 + if (err) {
4602 + ipkg_message(conf, IPKG_ERROR,
4603 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4604 + pkg->name);
4605 + return err;
4606 + }
4607 + }
4608 +
4609 +/* Check for md5 values */
4610 + if (pkg->md5sum)
4611 + {
4612 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4613 + if (strcmp(file_md5, pkg->md5sum))
4614 + {
4615 + ipkg_message(conf, IPKG_ERROR,
4616 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4617 + pkg->name);
4618 + free(file_md5);
4619 + return err;
4620 + }
4621 + free(file_md5);
4622 + }
4623 +
4624 + if (pkg->tmp_unpack_dir == NULL) {
4625 + unpack_pkg_control_files(conf, pkg);
4626 + }
4627 +
4628 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4629 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4630 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4631 + err = update_file_ownership(conf, pkg, old_pkg);
4632 + if (err) { return err; }
4633 +
4634 + if (conf->nodeps == 0) {
4635 + err = satisfy_dependencies_for(conf, pkg);
4636 + if (err) { return err; }
4637 + }
4638 +
4639 + replacees = pkg_vec_alloc();
4640 + pkg_get_installed_replacees(conf, pkg, replacees);
4641 +
4642 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4643 + {
4644 + sigset_t newset, oldset;
4645 + sighandler_t old_handler = NULL;
4646 + int use_signal = 0;
4647 + caught_sigint = 0;
4648 + if (use_signal) {
4649 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4650 + } else {
4651 + sigemptyset(&newset);
4652 + sigaddset(&newset, SIGINT);
4653 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4654 + }
4655 +
4656 + ipkg_state_changed++;
4657 + pkg->state_flag |= SF_FILELIST_CHANGED;
4658 +
4659 + /* XXX: BUG: we really should treat replacement more like an upgrade
4660 + * Instead, we're going to remove the replacees
4661 + */
4662 + err = pkg_remove_installed_replacees(conf, replacees);
4663 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4664 +
4665 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4666 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4667 +
4668 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4669 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4670 +
4671 + err = preinst_configure(conf, pkg, old_pkg);
4672 + if (err) goto UNWIND_PREINST_CONFIGURE;
4673 +
4674 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4675 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4676 +
4677 + err = check_data_file_clashes(conf, pkg, old_pkg);
4678 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4679 +
4680 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4681 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4682 +
4683 + if (conf->noaction) return 0;
4684 +
4685 + /* point of no return: no unwinding after this */
4686 + if (old_pkg && !conf->force_reinstall) {
4687 + old_pkg->state_want = SW_DEINSTALL;
4688 +
4689 + if (old_pkg->state_flag & SF_NOPRUNE) {
4690 + ipkg_message(conf, IPKG_INFO,
4691 + " not removing obsolesced files because package marked noprune\n");
4692 + } else {
4693 + ipkg_message(conf, IPKG_INFO,
4694 + " removing obsolesced files\n");
4695 + remove_obsolesced_files(conf, pkg, old_pkg);
4696 + }
4697 + /* removing files from old package, to avoid ghost files */
4698 + remove_data_files_and_list(conf, old_pkg);
4699 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4700 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4701 + remove_postrm(conf, old_pkg);
4702 +/* Pigi */
4703 +
4704 + }
4705 +
4706 +
4707 + ipkg_message(conf, IPKG_INFO,
4708 + " installing maintainer scripts\n");
4709 + install_maintainer_scripts(conf, pkg, old_pkg);
4710 +
4711 + /* the following just returns 0 */
4712 + remove_disappeared(conf, pkg);
4713 +
4714 + ipkg_message(conf, IPKG_INFO,
4715 + " installing data files\n");
4716 + install_data_files(conf, pkg);
4717 +
4718 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4719 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4720 +
4721 + ipkg_message(conf, IPKG_INFO,
4722 + " resolving conf files\n");
4723 + resolve_conffiles(conf, pkg);
4724 +
4725 + pkg->state_status = SS_UNPACKED;
4726 + old_state_flag = pkg->state_flag;
4727 + pkg->state_flag &= ~SF_PREFER;
4728 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4729 +
4730 + if (old_pkg && !conf->force_reinstall) {
4731 + old_pkg->state_status = SS_NOT_INSTALLED;
4732 + }
4733 +
4734 + time(&pkg->installed_time);
4735 +
4736 + ipkg_message(conf, IPKG_INFO,
4737 + " cleanup temp files\n");
4738 + cleanup_temporary_files(conf, pkg);
4739 +
4740 + ab_pkg = pkg->parent;
4741 + if (ab_pkg)
4742 + ab_pkg->state_status = pkg->state_status;
4743 +
4744 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4745 +
4746 + if (use_signal)
4747 + signal(SIGINT, old_handler);
4748 + else
4749 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4750 +
4751 + return 0;
4752 +
4753 +
4754 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4755 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4756 + UNWIND_CHECK_DATA_FILE_CLASHES:
4757 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4758 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4759 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4760 + UNWIND_PREINST_CONFIGURE:
4761 + preinst_configure_unwind(conf, pkg, old_pkg);
4762 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4763 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4764 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4765 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4766 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4767 + pkg_remove_installed_replacees_unwind(conf, replacees);
4768 +
4769 + ipkg_message(conf, IPKG_INFO,
4770 + " cleanup temp files\n");
4771 + cleanup_temporary_files(conf, pkg);
4772 +
4773 + ipkg_message(conf, IPKG_INFO,
4774 + "Failed.\n");
4775 + if (use_signal)
4776 + signal(SIGINT, old_handler);
4777 + else
4778 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4779 +
4780 + return err;
4781 + }
4782 +}
4783 +
4784 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4785 +{
4786 + /* DPKG_INCOMPATIBILITY:
4787 + dpkg does some things here that we don't do yet. Do we care?
4788 +
4789 + 1. If a version of the package is already installed, call
4790 + old-prerm upgrade new-version
4791 + 2. If the script runs but exits with a non-zero exit status
4792 + new-prerm failed-upgrade old-version
4793 + Error unwind, for both the above cases:
4794 + old-postinst abort-upgrade new-version
4795 + */
4796 + return 0;
4797 +}
4798 +
4799 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4800 +{
4801 + /* DPKG_INCOMPATIBILITY:
4802 + dpkg does some things here that we don't do yet. Do we care?
4803 + (See prerm_upgrade_old_package for details)
4804 + */
4805 + return 0;
4806 +}
4807 +
4808 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4809 +{
4810 + /* DPKG_INCOMPATIBILITY:
4811 + dpkg does some things here that we don't do yet. Do we care?
4812 + 2. If a 'conflicting' package is being removed at the same time:
4813 + 1. If any packages depended on that conflicting package and
4814 + --auto-deconfigure is specified, call, for each such package:
4815 + deconfigured's-prerm deconfigure \
4816 + in-favour package-being-installed version \
4817 + removing conflicting-package version
4818 + Error unwind:
4819 + deconfigured's-postinst abort-deconfigure \
4820 + in-favour package-being-installed-but-failed version \
4821 + removing conflicting-package version
4822 +
4823 + The deconfigured packages are marked as requiring
4824 + configuration, so that if --install is used they will be
4825 + configured again if possible.
4826 + 2. To prepare for removal of the conflicting package, call:
4827 + conflictor's-prerm remove in-favour package new-version
4828 + Error unwind:
4829 + conflictor's-postinst abort-remove in-favour package new-version
4830 + */
4831 + return 0;
4832 +}
4833 +
4834 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4835 +{
4836 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4837 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4838 + details) */
4839 + return 0;
4840 +}
4841 +
4842 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4843 +{
4844 + int err;
4845 + char *preinst_args;
4846 +
4847 + if (old_pkg) {
4848 + char *old_version = pkg_version_str_alloc(old_pkg);
4849 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4850 + free(old_version);
4851 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4852 + char *pkg_version = pkg_version_str_alloc(pkg);
4853 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4854 + free(pkg_version);
4855 + } else {
4856 + preinst_args = strdup("install");
4857 + }
4858 +
4859 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4860 + if (err) {
4861 + ipkg_message(conf, IPKG_ERROR,
4862 + "Aborting installation of %s\n", pkg->name);
4863 + return 1;
4864 + }
4865 +
4866 + free(preinst_args);
4867 +
4868 + return 0;
4869 +}
4870 +
4871 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4872 +{
4873 + /* DPKG_INCOMPATIBILITY:
4874 + dpkg does the following error unwind, should we?
4875 + pkg->postrm abort-upgrade old-version
4876 + OR pkg->postrm abort-install old-version
4877 + OR pkg->postrm abort-install
4878 + */
4879 + return 0;
4880 +}
4881 +
4882 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4883 +{
4884 + int err;
4885 + conffile_list_elt_t *iter;
4886 + conffile_t *cf;
4887 +
4888 + if (conf->noaction) return 0;
4889 +
4890 + /* Backup all modified conffiles */
4891 + if (old_pkg) {
4892 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4893 + char *cf_name;
4894 +
4895 + cf = iter->data;
4896 + cf_name = root_filename_alloc(conf, cf->name);
4897 +
4898 + /* Don't worry if the conffile is just plain gone */
4899 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4900 + err = backup_make_backup(conf, cf_name);
4901 + if (err) {
4902 + return err;
4903 + }
4904 + }
4905 + free(cf_name);
4906 + }
4907 + }
4908 +
4909 + /* Backup all conffiles that were not conffiles in old_pkg */
4910 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4911 + char *cf_name;
4912 + cf = iter->data;
4913 + cf_name = root_filename_alloc(conf, cf->name);
4914 + /* Ignore if this was a conffile in old_pkg as well */
4915 + if (pkg_get_conffile(old_pkg, cf->name)) {
4916 + continue;
4917 + }
4918 +
4919 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4920 + err = backup_make_backup(conf, cf_name);
4921 + if (err) {
4922 + return err;
4923 + }
4924 + }
4925 + free(cf_name);
4926 + }
4927 +
4928 + return 0;
4929 +}
4930 +
4931 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4932 +{
4933 + conffile_list_elt_t *iter;
4934 +
4935 + if (old_pkg) {
4936 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4937 + backup_remove(iter->data->name);
4938 + }
4939 + }
4940 +
4941 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4942 + backup_remove(iter->data->name);
4943 + }
4944 +
4945 + return 0;
4946 +}
4947 +
4948 +
4949 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4950 +{
4951 + /* DPKG_INCOMPATIBILITY:
4952 + ipkg takes a slightly different approach than dpkg at this
4953 + point. dpkg installs each file in the new package while
4954 + creating a backup for any file that is replaced, (so that it
4955 + can unwind if necessary). To avoid complexity and redundant
4956 + storage, ipkg doesn't do any installation until later, (at the
4957 + point at which dpkg removes the backups.
4958 +
4959 + But, we do have to check for data file clashes, since after
4960 + installing a package with a file clash, removing either of the
4961 + packages involved in the clash has the potential to break the
4962 + other package.
4963 + */
4964 + str_list_t *files_list;
4965 + str_list_elt_t *iter;
4966 +
4967 + int clashes = 0;
4968 +
4969 + files_list = pkg_get_installed_files(pkg);
4970 + for (iter = files_list->head; iter; iter = iter->next) {
4971 + char *root_filename;
4972 + char *filename = iter->data;
4973 + root_filename = root_filename_alloc(conf, filename);
4974 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4975 + pkg_t *owner;
4976 + pkg_t *obs;
4977 + /* Pre-existing conffiles are OK */
4978 + /* @@@@ should have way to check that it is a conffile -Jamey */
4979 + if (backup_exists_for(root_filename)) {
4980 + continue;
4981 + }
4982 +
4983 + /* Pre-existing files are OK if force-overwrite was asserted. */
4984 + if (conf->force_overwrite) {
4985 + /* but we need to change who owns this file */
4986 + file_hash_set_file_owner(conf, filename, pkg);
4987 + continue;
4988 + }
4989 +
4990 + owner = file_hash_get_file_owner(conf, filename);
4991 +
4992 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4993 + if (owner && old_pkg) {
4994 + if (strcmp(owner->name, old_pkg->name) == 0) {
4995 + continue;
4996 + }
4997 + }
4998 +
4999 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5000 + if (owner) {
5001 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5002 + if (pkg_replaces(pkg, owner)) {
5003 + continue;
5004 + }
5005 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5006 + then it's ok to overwrite. */
5007 + if (strcmp(owner->name,pkg->name)==0){
5008 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5009 + continue;
5010 + }
5011 + }
5012 +
5013 + /* Pre-existing files are OK if they are obsolete */
5014 + obs = hash_table_get(&conf->obs_file_hash, filename);
5015 + if (obs) {
5016 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5017 + continue;
5018 + }
5019 +
5020 + /* We have found a clash. */
5021 + ipkg_message(conf, IPKG_ERROR,
5022 + "Package %s wants to install file %s\n"
5023 + "\tBut that file is already provided by package ",
5024 + pkg->name, filename);
5025 + if (owner) {
5026 + ipkg_message(conf, IPKG_ERROR,
5027 + "%s\n", owner->name);
5028 + } else {
5029 + ipkg_message(conf, IPKG_ERROR,
5030 + "<no package>\nPlease move this file out of the way and try again.\n");
5031 + }
5032 + clashes++;
5033 + }
5034 + free(root_filename);
5035 + }
5036 + pkg_free_installed_files(pkg);
5037 +
5038 + return clashes;
5039 +}
5040 +
5041 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5042 +{
5043 + /* Basically that's the worst hack I could do to be able to change ownership of
5044 + file list, but, being that we have no way to unwind the mods, due to structure
5045 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5046 + What we do here is change the ownership of file in hash if a replace ( or similar events
5047 + happens )
5048 + Only the action that are needed to change name should be considered.
5049 + @@@ To change after 1.0 release.
5050 + */
5051 + str_list_t *files_list;
5052 + str_list_elt_t *iter;
5053 +
5054 + int clashes = 0;
5055 +
5056 + files_list = pkg_get_installed_files(pkg);
5057 + for (iter = files_list->head; iter; iter = iter->next) {
5058 + char *root_filename;
5059 + char *filename = iter->data;
5060 + root_filename = root_filename_alloc(conf, filename);
5061 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5062 + pkg_t *owner;
5063 +
5064 + if (conf->force_overwrite) {
5065 + /* but we need to change who owns this file */
5066 + file_hash_set_file_owner(conf, filename, pkg);
5067 + continue;
5068 + }
5069 +
5070 + owner = file_hash_get_file_owner(conf, filename);
5071 +
5072 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5073 + if (owner) {
5074 + if (pkg_replaces(pkg, owner)) {
5075 +/* It's now time to change the owner of that file.
5076 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5077 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5078 + file_hash_set_file_owner(conf, filename, pkg);
5079 + continue;
5080 + }
5081 + }
5082 +
5083 + }
5084 + free(root_filename);
5085 + }
5086 + pkg_free_installed_files(pkg);
5087 +
5088 + return clashes;
5089 +}
5090 +
5091 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5092 +{
5093 + /* Nothing to do since check_data_file_clashes doesn't change state */
5094 + return 0;
5095 +}
5096 +
5097 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5098 +{
5099 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5100 + 1. If the package is being upgraded, call
5101 + old-postrm upgrade new-version
5102 + 2. If this fails, attempt:
5103 + new-postrm failed-upgrade old-version
5104 + Error unwind, for both cases:
5105 + old-preinst abort-upgrade new-version */
5106 + return 0;
5107 +}
5108 +
5109 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5110 +{
5111 + /* DPKG_INCOMPATIBILITY:
5112 + dpkg does some things here that we don't do yet. Do we care?
5113 + (See postrm_upgrade_old_pkg for details)
5114 + */
5115 + return 0;
5116 +}
5117 +
5118 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5119 +{
5120 + int err;
5121 + str_list_t *old_files;
5122 + str_list_elt_t *of;
5123 + str_list_t *new_files;
5124 + str_list_elt_t *nf;
5125 +
5126 + if (old_pkg == NULL) {
5127 + return 0;
5128 + }
5129 +
5130 + old_files = pkg_get_installed_files(old_pkg);
5131 + new_files = pkg_get_installed_files(pkg);
5132 +
5133 + for (of = old_files->head; of; of = of->next) {
5134 + pkg_t *owner;
5135 + char *old, *new;
5136 + old = of->data;
5137 + for (nf = new_files->head; nf; nf = nf->next) {
5138 + new = nf->data;
5139 + if (strcmp(old, new) == 0) {
5140 + goto NOT_OBSOLETE;
5141 + }
5142 + }
5143 + if (file_is_dir(old)) {
5144 + continue;
5145 + }
5146 + owner = file_hash_get_file_owner(conf, old);
5147 + if (owner != old_pkg) {
5148 + /* in case obsolete file no longer belongs to old_pkg */
5149 + continue;
5150 + }
5151 +
5152 + /* old file is obsolete */
5153 + ipkg_message(conf, IPKG_INFO,
5154 + " removing obsolete file %s\n", old);
5155 + if (!conf->noaction) {
5156 + err = unlink(old);
5157 + if (err) {
5158 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5159 + strerror(errno));
5160 + }
5161 + }
5162 +
5163 + NOT_OBSOLETE:
5164 + ;
5165 + }
5166 +
5167 + pkg_free_installed_files(old_pkg);
5168 + pkg_free_installed_files(pkg);
5169 +
5170 + return 0;
5171 +}
5172 +
5173 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5174 +{
5175 + int i;
5176 + int err = 0;
5177 + char *globpattern;
5178 + glob_t globbuf;
5179 + if (0) {
5180 + if (!pkg->dest) {
5181 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5182 + return -1;
5183 + }
5184 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5185 + err = glob(globpattern, 0, NULL, &globbuf);
5186 + free(globpattern);
5187 + if (err) {
5188 + return err;
5189 + }
5190 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5191 + for (i = 0; i < globbuf.gl_pathc; i++) {
5192 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5193 + globbuf.gl_pathv[i], old_pkg->name);
5194 + if (!conf->noaction)
5195 + unlink(globbuf.gl_pathv[i]);
5196 + }
5197 + globfree(&globbuf);
5198 + }
5199 + return err;
5200 +}
5201 +
5202 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5203 +{
5204 + int ret;
5205 + char *prefix;
5206 +
5207 + if (old_pkg)
5208 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5209 + sprintf_alloc(&prefix, "%s.", pkg->name);
5210 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5211 + pkg->dest->info_dir,
5212 + prefix);
5213 + free(prefix);
5214 + return ret;
5215 +}
5216 +
5217 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5218 +{
5219 + /* DPKG_INCOMPATIBILITY:
5220 + This is a fairly sophisticated dpkg operation. Shall we
5221 + skip it? */
5222 +
5223 + /* Any packages all of whose files have been overwritten during the
5224 + installation, and which aren't required for dependencies, are
5225 + considered to have been removed. For each such package
5226 + 1. disappearer's-postrm disappear overwriter overwriter-version
5227 + 2. The package's maintainer scripts are removed
5228 + 3. It is noted in the status database as being in a sane state,
5229 + namely not installed (any conffiles it may have are ignored,
5230 + rather than being removed by dpkg). Note that disappearing
5231 + packages do not have their prerm called, because dpkg doesn't
5232 + know in advance that the package is going to vanish.
5233 + */
5234 + return 0;
5235 +}
5236 +
5237 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5238 +{
5239 + int err;
5240 +
5241 + /* ipkg takes a slightly different approach to data file backups
5242 + than dpkg. Rather than removing backups at this point, we
5243 + actually do the data file installation now. See comments in
5244 + check_data_file_clashes() for more details. */
5245 +
5246 + ipkg_message(conf, IPKG_INFO,
5247 + " extracting data files to %s\n", pkg->dest->root_dir);
5248 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5249 + if (err) {
5250 + return err;
5251 + }
5252 +
5253 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5254 + so we can't save ourself from removing important packages
5255 + At this point we (should) have extracted the .control file, so it
5256 + would be a good idea to reload the data in it, and set the Essential
5257 + state in *pkg. From now on the Essential is back in status file and
5258 + we can protect again.
5259 + We should operate this way:
5260 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5261 + check for "Essential" in it
5262 + set the value in pkg->essential.
5263 + This new routine could be useful also for every other flag
5264 + Pigi: 16/03/2004 */
5265 + set_flags_from_control(conf, pkg) ;
5266 +
5267 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5268 + err = pkg_write_filelist(conf, pkg);
5269 + if (err)
5270 + return err;
5271 +
5272 + /* XXX: FEATURE: ipkg should identify any files which existed
5273 + before installation and which were overwritten, (see
5274 + check_data_file_clashes()). What it must do is remove any such
5275 + files from the filelist of the old package which provided the
5276 + file. Otherwise, if the old package were removed at some point
5277 + it would break the new package. Removing the new package will
5278 + also break the old one, but this cannot be helped since the old
5279 + package's file has already been deleted. This is the importance
5280 + of check_data_file_clashes(), and only allowing ipkg to install
5281 + a clashing package with a user force. */
5282 +
5283 + return 0;
5284 +}
5285 +
5286 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5287 +{
5288 + conffile_list_elt_t *iter;
5289 + conffile_t *cf;
5290 + char *cf_backup;
5291 +
5292 + char *md5sum;
5293 +
5294 +
5295 + if (conf->noaction) return 0;
5296 +
5297 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5298 + char *root_filename;
5299 + cf = iter->data;
5300 + root_filename = root_filename_alloc(conf, cf->name);
5301 +
5302 + /* Might need to initialize the md5sum for each conffile */
5303 + if (cf->value == NULL) {
5304 + cf->value = file_md5sum_alloc(root_filename);
5305 + }
5306 +
5307 + if (!file_exists(root_filename)) {
5308 + free(root_filename);
5309 + continue;
5310 + }
5311 +
5312 + cf_backup = backup_filename_alloc(root_filename);
5313 +
5314 +
5315 + if (file_exists(cf_backup)) {
5316 + /* Let's compute md5 to test if files are changed */
5317 + md5sum = file_md5sum_alloc(cf_backup);
5318 + if (strcmp( cf->value,md5sum) != 0 ) {
5319 + if (conf->force_defaults
5320 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5321 + rename(cf_backup, root_filename);
5322 + }
5323 + }
5324 + unlink(cf_backup);
5325 + free(md5sum);
5326 + }
5327 +
5328 + free(cf_backup);
5329 + free(root_filename);
5330 + }
5331 +
5332 + return 0;
5333 +}
5334 +
5335 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5336 +{
5337 + char *response;
5338 + const char *short_file_name;
5339 +
5340 + short_file_name = strrchr(file_name, '/');
5341 + if (short_file_name) {
5342 + short_file_name++;
5343 + } else {
5344 + short_file_name = file_name;
5345 + }
5346 +
5347 + while (1) {
5348 + response = get_user_response(" Configuration file '%s'\n"
5349 + " ==> File on system created by you or by a script.\n"
5350 + " ==> File also in package provided by package maintainer.\n"
5351 + " What would you like to do about it ? Your options are:\n"
5352 + " Y or I : install the package maintainer's version\n"
5353 + " N or O : keep your currently-installed version\n"
5354 + " D : show the differences between the versions (if diff is installed)\n"
5355 + " The default action is to keep your current version.\n"
5356 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5357 + if (strcmp(response, "y") == 0
5358 + || strcmp(response, "i") == 0
5359 + || strcmp(response, "yes") == 0) {
5360 + free(response);
5361 + return 0;
5362 + }
5363 +
5364 + if (strcmp(response, "d") == 0) {
5365 + char *cmd;
5366 +
5367 + free(response);
5368 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5369 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5370 + xsystem(cmd);
5371 + free(cmd);
5372 + printf(" [Press ENTER to continue]\n");
5373 + response = file_read_line_alloc(stdin);
5374 + free(response);
5375 + continue;
5376 + }
5377 +
5378 + free(response);
5379 + return 1;
5380 + }
5381 +}
5382 +
5383 +/* XXX: CLEANUP: I'd like to move all of the code for
5384 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5385 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5386 + pkg_deinit for example). */
5387 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5388 +{
5389 + DIR *tmp_dir;
5390 + struct dirent *dirent;
5391 + char *tmp_file;
5392 +
5393 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5394 +#error
5395 + ipkg_message(conf, IPKG_DEBUG,
5396 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5397 + __FUNCTION__, pkg->tmp_unpack_dir);
5398 + return 0;
5399 +#endif
5400 +
5401 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5402 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5403 + if (tmp_dir) {
5404 + while (1) {
5405 + dirent = readdir(tmp_dir);
5406 + if (dirent == NULL) {
5407 + break;
5408 + }
5409 + sprintf_alloc(&tmp_file, "%s/%s",
5410 + pkg->tmp_unpack_dir, dirent->d_name);
5411 + if (! file_is_dir(tmp_file)) {
5412 + unlink(tmp_file);
5413 + }
5414 + free(tmp_file);
5415 + }
5416 + closedir(tmp_dir);
5417 + rmdir(pkg->tmp_unpack_dir);
5418 + free(pkg->tmp_unpack_dir);
5419 + pkg->tmp_unpack_dir = NULL;
5420 + }
5421 + }
5422 +
5423 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5424 + pkg->name, pkg->local_filename, conf->tmp_dir);
5425 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5426 + unlink(pkg->local_filename);
5427 + free(pkg->local_filename);
5428 + pkg->local_filename = NULL;
5429 + }
5430 +
5431 + return 0;
5432 +}
5433 +
5434 +static char *backup_filename_alloc(const char *file_name)
5435 +{
5436 + char *backup;
5437 +
5438 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5439 +
5440 + return backup;
5441 +}
5442 +
5443 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5444 +{
5445 + int err;
5446 + char *backup;
5447 +
5448 + backup = backup_filename_alloc(file_name);
5449 + err = file_copy(file_name, backup);
5450 + if (err) {
5451 + ipkg_message(conf, IPKG_ERROR,
5452 + "%s: Failed to copy %s to %s\n",
5453 + __FUNCTION__, file_name, backup);
5454 + }
5455 +
5456 + free(backup);
5457 +
5458 + return err;
5459 +}
5460 +
5461 +static int backup_exists_for(const char *file_name)
5462 +{
5463 + int ret;
5464 + char *backup;
5465 +
5466 + backup = backup_filename_alloc(file_name);
5467 +
5468 + ret = file_exists(backup);
5469 +
5470 + free(backup);
5471 +
5472 + return ret;
5473 +}
5474 +
5475 +static int backup_remove(const char *file_name)
5476 +{
5477 + char *backup;
5478 +
5479 + backup = backup_filename_alloc(file_name);
5480 + unlink(backup);
5481 + free(backup);
5482 +
5483 + return 0;
5484 +}
5485 +
5486 +\f
5487 +
5488 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5489 +
5490 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5491 +{
5492 + /* first, remove the packages that need removing */
5493 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5494 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5495 + err = ipkg_remove_pkg(conf, pkg,0);
5496 + if (err) return err;
5497 + }
5498 + return 0;
5499 +}
5500 +
5501 +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)
5502 +{
5503 + int i;
5504 + /* now one more pass checking on the ones that need to be installed */
5505 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5506 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5507 + if (pkg->dest == NULL)
5508 + pkg->dest = conf->default_dest;
5509 +
5510 + pkg->state_want = SW_INSTALL;
5511 +
5512 + /* Abhaya: conflicts check */
5513 + err = check_conflicts_for(conf, pkg);
5514 + if (err) { return err; }
5515 + }
5516 + return 0;
5517 +}
5518 +
5519 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5520 +{
5521 + int i;
5522 + /* now one more pass checking on the ones that need to be installed */
5523 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5524 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5525 +
5526 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5527 + pkg_vec_t *replacees = pkg_vec_alloc();
5528 + pkg_get_installed_replacees(conf, pkg, replacees);
5529 +
5530 + /* XXX: BUG: we really should treat replacement more like an upgrade
5531 + * Instead, we're going to remove the replacees
5532 + */
5533 + err = pkg_remove_installed_replacees(conf, replacees);
5534 + if (err) return err;
5535 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5536 + }
5537 + return 0;
5538 +}
5539 +
5540 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5541 +{
5542 + int i;
5543 + /* now one more pass checking on the ones that need to be installed */
5544 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5545 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5546 + if (pkg->local_filename == NULL) {
5547 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5548 + if (err) {
5549 + ipkg_message(conf, IPKG_ERROR,
5550 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5551 + pkg->name);
5552 + return err;
5553 + }
5554 + }
5555 + if (pkg->tmp_unpack_dir == NULL) {
5556 + err = unpack_pkg_control_files(conf, pkg);
5557 + if (err) return err;
5558 + }
5559 + }
5560 + return 0;
5561 +}
5562 +
5563 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5564 +{
5565 + int i;
5566 + /* now one more pass checking on the ones that need to be installed */
5567 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5568 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5569 + pkg_t *old_pkg = pkg->old_pkg;
5570 +
5571 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5572 + if (err) return err;
5573 +
5574 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5575 + if (err) return err;
5576 +
5577 + err = preinst_configure(conf, pkg, old_pkg);
5578 + if (err) return err;
5579 +
5580 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5581 + if (err) return err;
5582 +
5583 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5584 + if (err) return err;
5585 + }
5586 + return 0;
5587 +}
5588 +
5589 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5590 +{
5591 + int i;
5592 + /* now one more pass checking on the ones that need to be installed */
5593 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5594 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5595 + pkg_t *old_pkg = pkg->old_pkg;
5596 +
5597 + if (old_pkg) {
5598 + old_pkg->state_want = SW_DEINSTALL;
5599 +
5600 + if (old_pkg->state_flag & SF_NOPRUNE) {
5601 + ipkg_message(conf, IPKG_INFO,
5602 + " not removing obsolesced files because package marked noprune\n");
5603 + } else {
5604 + ipkg_message(conf, IPKG_INFO,
5605 + " removing obsolesced files\n");
5606 + remove_obsolesced_files(conf, pkg, old_pkg);
5607 + }
5608 + }
5609 +
5610 + ipkg_message(conf, IPKG_INFO,
5611 + " installing maintainer scripts\n");
5612 + install_maintainer_scripts(conf, pkg, old_pkg);
5613 +
5614 + /* the following just returns 0 */
5615 + remove_disappeared(conf, pkg);
5616 +
5617 + ipkg_message(conf, IPKG_INFO,
5618 + " installing data files\n");
5619 + install_data_files(conf, pkg);
5620 +
5621 + ipkg_message(conf, IPKG_INFO,
5622 + " resolving conf files\n");
5623 + resolve_conffiles(conf, pkg);
5624 +
5625 + pkg->state_status = SS_UNPACKED;
5626 +
5627 + if (old_pkg) {
5628 + old_pkg->state_status = SS_NOT_INSTALLED;
5629 + }
5630 +
5631 + time(&pkg->installed_time);
5632 +
5633 + ipkg_message(conf, IPKG_INFO,
5634 + " cleanup temp files\n");
5635 + cleanup_temporary_files(conf, pkg);
5636 +
5637 + if (pkg->parent)
5638 + pkg->parent->state_status = pkg->state_status;
5639 + }
5640 + return 0;
5641 +}
5642 +
5643 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5644 +{
5645 + int i;
5646 + /* now one more pass checking on the ones that need to be installed */
5647 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5648 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5649 + pkg_t *old_pkg = pkg->old_pkg;
5650 +
5651 + if (old_pkg) {
5652 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5653 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5654 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5655 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5656 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5657 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5658 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5659 + preinst_configure_unwind(conf, pkg, old_pkg);
5660 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5661 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5662 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5663 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5664 +
5665 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5666 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5667 +
5668 + }
5669 + }
5670 + return 0;
5671 +}
5672 +
5673 +/*
5674 + * Perform all the actions.
5675 + *
5676 + * pkgs_to_remove are packages marked for removal.
5677 + * pkgs_superseded are the old packages being replaced by upgrades.
5678 + *
5679 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5680 + */
5681 +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)
5682 +{
5683 + int err;
5684 + int i;
5685 +
5686 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5687 + if (err) return err;
5688 +
5689 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5690 + if (err) return err;
5691 +
5692 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5693 + if (err) goto UNWIND;
5694 +
5695 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5696 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5697 + if (err) goto UNWIND;
5698 +
5699 + /*
5700 + * Now that we have the packages unpacked, we can look for data
5701 + * file clashes. First, we mark the files from the superseded
5702 + * packages as obsolete. Then we scan the files in
5703 + * pkgs_to_install, and only complain about clashes with
5704 + * non-obsolete files.
5705 + */
5706 +
5707 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5708 + if (err) goto UNWIND;
5709 +
5710 + /* this was before checking data file clashes */
5711 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5712 + if (err) goto UNWIND;
5713 +
5714 + /* point of no return: no unwinding after this */
5715 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5716 + if (err) return err;
5717 +
5718 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5719 + return 0;
5720 +
5721 + UNWIND:
5722 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5723 +
5724 + ipkg_message(conf, IPKG_INFO,
5725 + " cleanup temp files\n");
5726 + cleanup_temporary_files(conf, pkg);
5727 +
5728 + ipkg_message(conf, IPKG_INFO,
5729 + "Failed.\n");
5730 + return err;
5731 +}
5732 +
5733 +#endif
5734 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_install.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h
5735 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5736 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-07-22 16:31:25.000000000 +0200
5737 @@ -0,0 +1,35 @@
5738 +/* ipkg_install.h - the itsy package management system
5739 +
5740 + Carl D. Worth
5741 +
5742 + Copyright (C) 2001 University of Southern California
5743 +
5744 + This program is free software; you can redistribute it and/or
5745 + modify it under the terms of the GNU General Public License as
5746 + published by the Free Software Foundation; either version 2, or (at
5747 + your option) any later version.
5748 +
5749 + This program is distributed in the hope that it will be useful, but
5750 + WITHOUT ANY WARRANTY; without even the implied warranty of
5751 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5752 + General Public License for more details.
5753 +*/
5754 +
5755 +#ifndef IPKG_INSTALL_H
5756 +#define IPKG_INSTALL_H
5757 +
5758 +#include "pkg.h"
5759 +#include "ipkg_conf.h"
5760 +
5761 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5762 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5763 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5764 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5765 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5766 +
5767 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5768 +
5769 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5770 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5771 +
5772 +#endif
5773 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_message.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c
5774 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5775 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-07-22 16:31:25.000000000 +0200
5776 @@ -0,0 +1,61 @@
5777 +/* ipkg_message.c - the itsy package management system
5778 +
5779 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5780 +
5781 + This program is free software; you can redistribute it and/or
5782 + modify it under the terms of the GNU General Public License as
5783 + published by the Free Software Foundation; either version 2, or (at
5784 + your option) any later version.
5785 +
5786 + This program is distributed in the hope that it will be useful, but
5787 + WITHOUT ANY WARRANTY; without even the implied warranty of
5788 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5789 + General Public License for more details.
5790 +*/
5791 +
5792 +
5793 +#include "ipkg.h"
5794 +#include "ipkg_conf.h"
5795 +#include "ipkg_message.h"
5796 +
5797 +#ifndef IPKG_LIB
5798 +
5799 +void
5800 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5801 +{
5802 + va_list ap;
5803 +
5804 + if (conf && (conf->verbosity < level))
5805 + {
5806 + return;
5807 + }
5808 + else
5809 + {
5810 +
5811 + va_start (ap, fmt);
5812 + vprintf (fmt, ap);
5813 + va_end (ap);
5814 + }
5815 +}
5816 +
5817 +#else
5818 +
5819 +#include "libipkg.h"
5820 +
5821 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5822 +
5823 +void
5824 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5825 +{
5826 + va_list ap;
5827 + char ts[256];
5828 +
5829 + if (ipkg_cb_message)
5830 + {
5831 + va_start (ap, fmt);
5832 + vsnprintf (ts,256,fmt, ap);
5833 + va_end (ap);
5834 + ipkg_cb_message(conf,level,ts);
5835 + }
5836 +}
5837 +#endif
5838 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_message.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h
5839 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5840 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-07-22 16:31:25.000000000 +0200
5841 @@ -0,0 +1,32 @@
5842 +/* ipkg_message.h - the itsy package management system
5843 +
5844 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5845 +
5846 + This program is free software; you can redistribute it and/or
5847 + modify it under the terms of the GNU General Public License as
5848 + published by the Free Software Foundation; either version 2, or (at
5849 + your option) any later version.
5850 +
5851 + This program is distributed in the hope that it will be useful, but
5852 + WITHOUT ANY WARRANTY; without even the implied warranty of
5853 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5854 + General Public License for more details.
5855 +*/
5856 +
5857 +#ifndef _IPKG_MESSAGE_H_
5858 +#define _IPKG_MESSAGE_H_
5859 +
5860 +#include "ipkg.h"
5861 +#include "ipkg_conf.h"
5862 +
5863 +typedef enum {
5864 + IPKG_ERROR, /* error conditions */
5865 + IPKG_NOTICE, /* normal but significant condition */
5866 + IPKG_INFO, /* informational message */
5867 + IPKG_DEBUG, /* debug level message */
5868 + IPKG_DEBUG2, /* more debug level message */
5869 +} message_level_t;
5870 +
5871 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5872 +
5873 +#endif /* _IPKG_MESSAGE_H_ */
5874 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c
5875 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5876 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-07-22 16:31:25.000000000 +0200
5877 @@ -0,0 +1,383 @@
5878 +/* ipkg_remove.c - the itsy package management system
5879 +
5880 + Carl D. Worth
5881 +
5882 + Copyright (C) 2001 University of Southern California
5883 +
5884 + This program is free software; you can redistribute it and/or
5885 + modify it under the terms of the GNU General Public License as
5886 + published by the Free Software Foundation; either version 2, or (at
5887 + your option) any later version.
5888 +
5889 + This program is distributed in the hope that it will be useful, but
5890 + WITHOUT ANY WARRANTY; without even the implied warranty of
5891 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5892 + General Public License for more details.
5893 +*/
5894 +
5895 +#include "ipkg.h"
5896 +#include "ipkg_message.h"
5897 +
5898 +#include <glob.h>
5899 +
5900 +#include "ipkg_remove.h"
5901 +
5902 +#include "file_util.h"
5903 +#include "sprintf_alloc.h"
5904 +#include "str_util.h"
5905 +
5906 +#include "ipkg_cmd.h"
5907 +
5908 +/*
5909 + * Returns number of the number of packages depending on the packages provided by this package.
5910 + * Every package implicitly provides itself.
5911 + */
5912 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5913 +{
5914 + int nprovides = pkg->provides_count;
5915 + abstract_pkg_t **provides = pkg->provides;
5916 + int n_installed_dependents = 0;
5917 + int i;
5918 + for (i = 0; i <= nprovides; i++) {
5919 + abstract_pkg_t *providee = provides[i];
5920 + abstract_pkg_t **dependers = providee->depended_upon_by;
5921 + abstract_pkg_t *dep_ab_pkg;
5922 + if (dependers == NULL)
5923 + continue;
5924 + while ((dep_ab_pkg = *dependers++) != NULL) {
5925 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5926 + n_installed_dependents++;
5927 + }
5928 + }
5929 +
5930 + }
5931 + /* if caller requested the set of installed dependents */
5932 + if (pdependents) {
5933 + int p = 0;
5934 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5935 +
5936 + if ( dependents == NULL ){
5937 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5938 + return -1;
5939 + }
5940 +
5941 + *pdependents = dependents;
5942 + for (i = 0; i <= nprovides; i++) {
5943 + abstract_pkg_t *providee = provides[i];
5944 + abstract_pkg_t **dependers = providee->depended_upon_by;
5945 + abstract_pkg_t *dep_ab_pkg;
5946 + if (dependers == NULL)
5947 + continue;
5948 + while ((dep_ab_pkg = *dependers++) != NULL) {
5949 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5950 + dependents[p++] = dep_ab_pkg;
5951 + dep_ab_pkg->state_flag |= SF_MARKED;
5952 + }
5953 + }
5954 + }
5955 + dependents[p] = NULL;
5956 + /* now clear the marks */
5957 + for (i = 0; i < p; i++) {
5958 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5959 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5960 + }
5961 + }
5962 + return n_installed_dependents;
5963 +}
5964 +
5965 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5966 +{
5967 + int i;
5968 + int a;
5969 + int count;
5970 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5971 + abstract_pkg_t * ab_pkg;
5972 +
5973 + if((ab_pkg = pkg->parent) == NULL){
5974 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5975 + __FUNCTION__, pkg->name);
5976 + return 0;
5977 + }
5978 +
5979 + if (dependents == NULL)
5980 + return 0;
5981 +
5982 + // here i am using the dependencies_checked
5983 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5984 + return 0; // has already been encountered in the process
5985 + // of marking packages for removal - Karthik
5986 + ab_pkg->dependencies_checked = 2;
5987 +
5988 + i = 0;
5989 + count = 1;
5990 + while (dependents [i] != NULL) {
5991 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5992 +
5993 + if (dep_ab_pkg->dependencies_checked == 2){
5994 + i++;
5995 + continue;
5996 + }
5997 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5998 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5999 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6000 + if (dep_pkg->state_status == SS_INSTALLED) {
6001 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6002 + count++;
6003 + }
6004 + }
6005 + }
6006 + i++;
6007 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6008 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6009 + }
6010 +
6011 + if (count == 1)
6012 + return 0;
6013 +
6014 +
6015 + for (i = 0; i < dependent_pkgs->len; i++) {
6016 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6017 + if (err)
6018 + return err;
6019 + }
6020 + return 0;
6021 +}
6022 +
6023 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6024 +{
6025 + abstract_pkg_t *dep_ab_pkg;
6026 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6027 + while ((dep_ab_pkg = *dependents++) != NULL) {
6028 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6029 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6030 + }
6031 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6032 + ipkg_message(conf, IPKG_ERROR, "");
6033 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6034 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6035 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6036 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6037 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6038 + return 0;
6039 +}
6040 +
6041 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6042 +{
6043 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6044 + thus I wan't check for essential, as I'm upgrading.
6045 + I hope it won't break anything :)
6046 +*/
6047 + int err;
6048 + abstract_pkg_t *parent_pkg = NULL;
6049 +
6050 + if (pkg->essential && !message) {
6051 + if (conf->force_removal_of_essential_packages) {
6052 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6053 + "\tIf your system breaks, you get to keep both pieces\n",
6054 + pkg->name);
6055 + } else {
6056 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6057 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6058 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6059 + "\tits will with the option: -force-removal-of-essential-packages\n",
6060 + pkg->name);
6061 + return IPKG_PKG_IS_ESSENTIAL;
6062 + }
6063 + }
6064 +
6065 + if ((parent_pkg = pkg->parent) == NULL)
6066 + return 0;
6067 +
6068 + /* only attempt to remove dependent installed packages if
6069 + * force_depends is not specified or the package is being
6070 + * replaced.
6071 + */
6072 + if (!conf->force_depends
6073 + && !(pkg->state_flag & SF_REPLACE)) {
6074 + abstract_pkg_t **dependents;
6075 + int has_installed_dependents =
6076 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6077 +
6078 + if (has_installed_dependents) {
6079 + /*
6080 + * if this package is depended up by others, then either we should
6081 + * not remove it or we should remove it and all of its dependents
6082 + */
6083 +
6084 + if (!conf->force_removal_of_dependent_packages
6085 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6086 + return IPKG_PKG_HAS_DEPENDENTS;
6087 + }
6088 +
6089 + /* remove packages depending on this package - Karthik */
6090 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6091 + free(dependents);
6092 + if (err) return err;
6093 + }
6094 + }
6095 +
6096 + if ( message==0 ){
6097 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6098 + fflush(stdout);
6099 + }
6100 + pkg->state_flag |= SF_FILELIST_CHANGED;
6101 +
6102 + pkg->state_want = SW_DEINSTALL;
6103 + ipkg_state_changed++;
6104 +
6105 + pkg_run_script(conf, pkg, "prerm", "remove");
6106 +
6107 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6108 + maintains an empty filelist rather than deleting it. That seems
6109 + like a big pain, and I don't see that that should make a big
6110 + difference, but for anyone who wants tighter compatibility,
6111 + feel free to fix this. */
6112 + remove_data_files_and_list(conf, pkg);
6113 +
6114 + pkg_run_script(conf, pkg, "postrm", "remove");
6115 +
6116 + remove_maintainer_scripts_except_postrm(conf, pkg);
6117 +
6118 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6119 + * space, it doesn't make sense to leave extra configurations, files,
6120 + * and maintainer scripts left around. So, we make remove like purge,
6121 + * and take out all the crap :) */
6122 +
6123 + remove_postrm(conf, pkg);
6124 + pkg->state_status = SS_NOT_INSTALLED;
6125 +
6126 + if (parent_pkg)
6127 + parent_pkg->state_status = SS_NOT_INSTALLED;
6128 +
6129 + return 0;
6130 +}
6131 +
6132 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6133 +{
6134 + ipkg_remove_pkg(conf, pkg,0);
6135 + return 0;
6136 +}
6137 +
6138 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6139 +{
6140 + str_list_t installed_dirs;
6141 + str_list_t *installed_files;
6142 + str_list_elt_t *iter;
6143 + char *file_name;
6144 + conffile_t *conffile;
6145 + int removed_a_dir;
6146 + pkg_t *owner;
6147 +
6148 + str_list_init(&installed_dirs);
6149 + installed_files = pkg_get_installed_files(pkg);
6150 +
6151 + for (iter = installed_files->head; iter; iter = iter->next) {
6152 + file_name = iter->data;
6153 +
6154 + if (file_is_dir(file_name)) {
6155 + str_list_append(&installed_dirs, strdup(file_name));
6156 + continue;
6157 + }
6158 +
6159 + conffile = pkg_get_conffile(pkg, file_name);
6160 + if (conffile) {
6161 + /* XXX: QUESTION: Is this right? I figure we only need to
6162 + save the conffile if it has been modified. Is that what
6163 + dpkg does? Or does dpkg preserve all conffiles? If so,
6164 + this seems like a better thing to do to conserve
6165 + space. */
6166 + if (conffile_has_been_modified(conf, conffile)) {
6167 + printf(" not deleting modified conffile %s\n", file_name);
6168 + fflush(stdout);
6169 + continue;
6170 + }
6171 + }
6172 +
6173 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6174 + if (!conf->noaction)
6175 + unlink(file_name);
6176 + }
6177 +
6178 + if (!conf->noaction) {
6179 + do {
6180 + removed_a_dir = 0;
6181 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6182 + file_name = iter->data;
6183 +
6184 + if (rmdir(file_name) == 0) {
6185 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6186 + removed_a_dir = 1;
6187 + str_list_remove(&installed_dirs, &iter);
6188 + }
6189 + }
6190 + } while (removed_a_dir);
6191 + }
6192 +
6193 + pkg_free_installed_files(pkg);
6194 + /* We have to remove the file list now, so that
6195 + find_pkg_owning_file does not always just report this package */
6196 + pkg_remove_installed_files_list(conf, pkg);
6197 +
6198 + /* Don't print warning for dirs that are provided by other packages */
6199 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6200 + file_name = iter->data;
6201 +
6202 + owner = file_hash_get_file_owner(conf, file_name);
6203 + if (owner) {
6204 + free(iter->data);
6205 + iter->data = NULL;
6206 + str_list_remove(&installed_dirs, &iter);
6207 + }
6208 + }
6209 +
6210 + /* cleanup */
6211 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6212 + free(iter->data);
6213 + iter->data = NULL;
6214 + }
6215 + str_list_deinit(&installed_dirs);
6216 +
6217 + return 0;
6218 +}
6219 +
6220 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6221 +{
6222 + int i, err;
6223 + char *globpattern;
6224 + glob_t globbuf;
6225 +
6226 + if (conf->noaction) return 0;
6227 +
6228 + sprintf_alloc(&globpattern, "%s/%s.*",
6229 + pkg->dest->info_dir, pkg->name);
6230 + err = glob(globpattern, 0, NULL, &globbuf);
6231 + free(globpattern);
6232 + if (err) {
6233 + return 0;
6234 + }
6235 +
6236 + for (i = 0; i < globbuf.gl_pathc; i++) {
6237 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6238 + continue;
6239 + }
6240 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6241 + unlink(globbuf.gl_pathv[i]);
6242 + }
6243 + globfree(&globbuf);
6244 +
6245 + return 0;
6246 +}
6247 +
6248 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6249 +{
6250 + char *postrm_file_name;
6251 +
6252 + if (conf->noaction) return 0;
6253 +
6254 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6255 + pkg->dest->info_dir, pkg->name);
6256 + unlink(postrm_file_name);
6257 + free(postrm_file_name);
6258 +
6259 + return 0;
6260 +}
6261 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h
6262 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6263 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-07-22 16:31:25.000000000 +0200
6264 @@ -0,0 +1,33 @@
6265 +/* ipkg_remove.h - the itsy package management system
6266 +
6267 + Carl D. Worth
6268 +
6269 + Copyright (C) 2001 University of Southern California
6270 +
6271 + This program is free software; you can redistribute it and/or
6272 + modify it under the terms of the GNU General Public License as
6273 + published by the Free Software Foundation; either version 2, or (at
6274 + your option) any later version.
6275 +
6276 + This program is distributed in the hope that it will be useful, but
6277 + WITHOUT ANY WARRANTY; without even the implied warranty of
6278 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6279 + General Public License for more details.
6280 +*/
6281 +
6282 +#ifndef IPKG_REMOVE_H
6283 +#define IPKG_REMOVE_H
6284 +
6285 +#include "pkg.h"
6286 +#include "ipkg_conf.h"
6287 +
6288 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6289 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6290 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6291 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6292 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6293 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6294 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6295 +
6296 +
6297 +#endif
6298 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c
6299 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6300 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-07-22 16:31:25.000000000 +0200
6301 @@ -0,0 +1,77 @@
6302 +/* ipkg_upgrade.c - the itsy package management system
6303 +
6304 + Carl D. Worth
6305 + Copyright (C) 2001 University of Southern California
6306 +
6307 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6308 +
6309 + This program is free software; you can redistribute it and/or
6310 + modify it under the terms of the GNU General Public License as
6311 + published by the Free Software Foundation; either version 2, or (at
6312 + your option) any later version.
6313 +
6314 + This program is distributed in the hope that it will be useful, but
6315 + WITHOUT ANY WARRANTY; without even the implied warranty of
6316 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6317 + General Public License for more details.
6318 +*/
6319 +
6320 +#include "ipkg.h"
6321 +#include "ipkg_install.h"
6322 +#include "ipkg_message.h"
6323 +
6324 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6325 +{
6326 + pkg_t *new;
6327 + int cmp;
6328 + char *old_version, *new_version;
6329 +
6330 + if (old->state_flag & SF_HOLD) {
6331 + ipkg_message(conf, IPKG_NOTICE,
6332 + "Not upgrading package %s which is marked "
6333 + "hold (flags=%#x)\n", old->name, old->state_flag);
6334 + return 0;
6335 + }
6336 +
6337 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6338 + if (new == NULL) {
6339 + old_version = pkg_version_str_alloc(old);
6340 + ipkg_message(conf, IPKG_NOTICE,
6341 + "Assuming locally installed package %s (%s) "
6342 + "is up to date.\n", old->name, old_version);
6343 + free(old_version);
6344 + return 0;
6345 + }
6346 +
6347 + old_version = pkg_version_str_alloc(old);
6348 + new_version = pkg_version_str_alloc(new);
6349 +
6350 + cmp = pkg_compare_versions(old, new);
6351 + ipkg_message(conf, IPKG_DEBUG,
6352 + "comparing visible versions of pkg %s:"
6353 + "\n\t%s is installed "
6354 + "\n\t%s is available "
6355 + "\n\t%d was comparison result\n",
6356 + old->name, old_version, new_version, cmp);
6357 + if (cmp == 0) {
6358 + ipkg_message(conf, IPKG_INFO,
6359 + "Package %s (%s) installed in %s is up to date.\n",
6360 + old->name, old_version, old->dest->name);
6361 + free(old_version);
6362 + free(new_version);
6363 + return 0;
6364 + } else if (cmp > 0) {
6365 + ipkg_message(conf, IPKG_NOTICE,
6366 + "Not downgrading package %s on %s from %s to %s.\n",
6367 + old->name, old->dest->name, old_version, new_version);
6368 + free(old_version);
6369 + free(new_version);
6370 + return 0;
6371 + } else if (cmp < 0) {
6372 + new->dest = old->dest;
6373 + old->state_want = SW_DEINSTALL;
6374 + }
6375 +
6376 + new->state_flag |= SF_USER;
6377 + return ipkg_install_pkg(conf, new,1);
6378 +}
6379 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h
6380 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6381 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-07-22 16:31:25.000000000 +0200
6382 @@ -0,0 +1,18 @@
6383 +/* ipkg_upgrade.c - the itsy package management system
6384 +
6385 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6386 +
6387 + This program is free software; you can redistribute it and/or
6388 + modify it under the terms of the GNU General Public License as
6389 + published by the Free Software Foundation; either version 2, or (at
6390 + your option) any later version.
6391 +
6392 + This program is distributed in the hope that it will be useful, but
6393 + WITHOUT ANY WARRANTY; without even the implied warranty of
6394 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6395 + General Public License for more details.
6396 +*/
6397 +
6398 +#include "ipkg.h"
6399 +
6400 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6401 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c
6402 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6403 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-07-22 16:31:25.000000000 +0200
6404 @@ -0,0 +1,181 @@
6405 +/* ipkg_utils.c - the itsy package management system
6406 +
6407 + Steven M. Ayer
6408 +
6409 + Copyright (C) 2002 Compaq Computer Corporation
6410 +
6411 + This program is free software; you can redistribute it and/or
6412 + modify it under the terms of the GNU General Public License as
6413 + published by the Free Software Foundation; either version 2, or (at
6414 + your option) any later version.
6415 +
6416 + This program is distributed in the hope that it will be useful, but
6417 + WITHOUT ANY WARRANTY; without even the implied warranty of
6418 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6419 + General Public License for more details.
6420 +*/
6421 +
6422 +#include "ipkg.h"
6423 +#include <errno.h>
6424 +#include <ctype.h>
6425 +#include <sys/vfs.h>
6426 +
6427 +#include "ipkg_utils.h"
6428 +#include "pkg.h"
6429 +#include "pkg_hash.h"
6430 +
6431 +struct errlist* error_list;
6432 +
6433 +int get_available_blocks(char * filesystem)
6434 +{
6435 + struct statfs sfs;
6436 +
6437 + if(statfs(filesystem, &sfs)){
6438 + fprintf(stderr, "bad statfs\n");
6439 + return 0;
6440 + }
6441 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6442 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6443 +}
6444 +
6445 +char **read_raw_pkgs_from_file(const char *file_name)
6446 +{
6447 + FILE *fp;
6448 + char **ret;
6449 +
6450 + if(!(fp = fopen(file_name, "r"))){
6451 + fprintf(stderr, "can't get %s open for read\n", file_name);
6452 + return NULL;
6453 + }
6454 +
6455 + ret = read_raw_pkgs_from_stream(fp);
6456 +
6457 + fclose(fp);
6458 +
6459 + return ret;
6460 +}
6461 +
6462 +char **read_raw_pkgs_from_stream(FILE *fp)
6463 +{
6464 + char **raw = NULL, *buf, *scout;
6465 + int count = 0;
6466 + size_t size = 512;
6467 +
6468 + buf = malloc (size);
6469 +
6470 + while (fgets(buf, size, fp)) {
6471 + while (strlen (buf) == (size - 1)
6472 + && buf[size-2] != '\n') {
6473 + size_t o = size - 1;
6474 + size *= 2;
6475 + buf = realloc (buf, size);
6476 + if (fgets (buf + o, size - o, fp) == NULL)
6477 + break;
6478 + }
6479 +
6480 + if(!(count % 50))
6481 + raw = realloc(raw, (count + 50) * sizeof(char *));
6482 +
6483 + if((scout = strchr(buf, '\n')))
6484 + *scout = '\0';
6485 +
6486 + raw[count++] = strdup(buf);
6487 + }
6488 +
6489 + raw = realloc(raw, (count + 1) * sizeof(char *));
6490 + raw[count] = NULL;
6491 +
6492 + free (buf);
6493 +
6494 + return raw;
6495 +}
6496 +
6497 +/* something to remove whitespace, a hash pooper */
6498 +char *trim_alloc(char *line)
6499 +{
6500 + char *new;
6501 + char *dest, *src, *end;
6502 +
6503 + new = malloc(strlen(line) + 1);
6504 + if ( new == NULL ){
6505 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6506 + return NULL;
6507 + }
6508 + dest = new, src = line, end = line + (strlen(line) - 1);
6509 +
6510 + /* remove it from the front */
6511 + while(src &&
6512 + isspace(*src) &&
6513 + *src)
6514 + src++;
6515 + /* and now from the back */
6516 + while((end > src) &&
6517 + isspace(*end))
6518 + end--;
6519 + end++;
6520 + *end = '\0';
6521 + strcpy(new, src);
6522 + /* this does from the first space
6523 + * blasting away any versions stuff in depends
6524 + while(src &&
6525 + !isspace(*src) &&
6526 + *src)
6527 + *dest++ = *src++;
6528 + *dest = '\0';
6529 + */
6530 +
6531 + return new;
6532 +}
6533 +
6534 +int line_is_blank(const char *line)
6535 +{
6536 + const char *s;
6537 +
6538 + for (s = line; *s; s++) {
6539 + if (!isspace(*s))
6540 + return 0;
6541 + }
6542 + return 1;
6543 +}
6544 +
6545 +void push_error_list(struct errlist ** errors, char * msg){
6546 + struct errlist *err_lst_tmp;
6547 +
6548 +
6549 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6550 + err_lst_tmp->errmsg=strdup(msg) ;
6551 + err_lst_tmp->next = *errors;
6552 + *errors = err_lst_tmp;
6553 +}
6554 +
6555 +
6556 +void reverse_error_list(struct errlist **errors){
6557 + struct errlist *result=NULL;
6558 + struct errlist *current= *errors;
6559 + struct errlist *next;
6560 +
6561 + while ( current != NULL ) {
6562 + next = current->next;
6563 + current->next=result;
6564 + result=current;
6565 + current=next;
6566 + }
6567 + *errors=result;
6568 +
6569 +}
6570 +
6571 +
6572 +void free_error_list(struct errlist **errors){
6573 + struct errlist *current = *errors;
6574 +
6575 + while (current != NULL) {
6576 + free(current->errmsg);
6577 + current = (*errors)->next;
6578 + free(*errors);
6579 + *errors = current;
6580 + }
6581 +
6582 +
6583 +}
6584 +
6585 +
6586 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h
6587 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6588 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-07-22 16:31:25.000000000 +0200
6589 @@ -0,0 +1,29 @@
6590 +/* ipkg_utils.h - the itsy package management system
6591 +
6592 + Steven M. Ayer
6593 +
6594 + Copyright (C) 2002 Compaq Computer Corporation
6595 +
6596 + This program is free software; you can redistribute it and/or
6597 + modify it under the terms of the GNU General Public License as
6598 + published by the Free Software Foundation; either version 2, or (at
6599 + your option) any later version.
6600 +
6601 + This program is distributed in the hope that it will be useful, but
6602 + WITHOUT ANY WARRANTY; without even the implied warranty of
6603 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6604 + General Public License for more details.
6605 +*/
6606 +
6607 +#ifndef IPKG_UTILS_H
6608 +#define IPKG_UTILS_H
6609 +
6610 +#include "pkg.h"
6611 +
6612 +int get_available_blocks(char * filesystem);
6613 +char **read_raw_pkgs_from_file(const char *file_name);
6614 +char **read_raw_pkgs_from_stream(FILE *fp);
6615 +char *trim_alloc(char * line);
6616 +int line_is_blank(const char *line);
6617 +
6618 +#endif
6619 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c
6620 --- busybox-1.2.0-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6621 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-07-22 16:31:25.000000000 +0200
6622 @@ -0,0 +1,527 @@
6623 +/* ipkglib.c - the itsy package management system
6624 +
6625 + Florina Boor
6626 +
6627 + Copyright (C) 2003 kernel concepts
6628 +
6629 + This program is free software; you can redistribute it and/or
6630 + modify it under the terms of the GNU General Public License as
6631 + published by the Free Software Foundation; either version 2, or (at
6632 + your option) any later version.
6633 +
6634 + This program is distributed in the hope that it will be useful, but
6635 + WITHOUT ANY WARRANTY; without even the implied warranty of
6636 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6637 + General Public License for more details.
6638 +*/
6639 +
6640 +#ifdef IPKG_LIB
6641 +
6642 +#include "ipkg.h"
6643 +#include "ipkg_includes.h"
6644 +#include "libipkg.h"
6645 +
6646 +#include "args.h"
6647 +#include "ipkg_conf.h"
6648 +#include "ipkg_cmd.h"
6649 +#include "file_util.h"
6650 +
6651 +
6652 +
6653 +ipkg_message_callback ipkg_cb_message = NULL;
6654 +ipkg_response_callback ipkg_cb_response = NULL;
6655 +ipkg_status_callback ipkg_cb_status = NULL;
6656 +ipkg_list_callback ipkg_cb_list = NULL;
6657 +
6658 +
6659 +int
6660 +ipkg_init (ipkg_message_callback mcall,
6661 + ipkg_response_callback rcall,
6662 + args_t * args)
6663 +{
6664 + ipkg_cb_message = mcall;
6665 + ipkg_cb_response = rcall;
6666 +
6667 + args_init (args);
6668 +
6669 + return 0;
6670 +}
6671 +
6672 +
6673 +int
6674 +ipkg_deinit (args_t * args)
6675 +{
6676 + args_deinit (args);
6677 + ipkg_cb_message = NULL;
6678 + ipkg_cb_response = NULL;
6679 +
6680 + /* place other cleanup stuff here */
6681 +
6682 + return 0;
6683 +}
6684 +
6685 +
6686 +int
6687 +ipkg_packages_list(args_t *args,
6688 + const char *packages,
6689 + ipkg_list_callback cblist,
6690 + void *userdata)
6691 +{
6692 + ipkg_cmd_t *cmd;
6693 + ipkg_conf_t ipkg_conf;
6694 + int err;
6695 +
6696 + err = ipkg_conf_init (&ipkg_conf, args);
6697 + if (err)
6698 + {
6699 + return err;
6700 + }
6701 +
6702 + ipkg_cb_list = cblist;
6703 + /* we need to do this because of static declarations,
6704 + * maybe a good idea to change */
6705 + cmd = ipkg_cmd_find ("list");
6706 + if (packages)
6707 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6708 + else
6709 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6710 + ipkg_cb_list = NULL;
6711 + ipkg_conf_deinit (&ipkg_conf);
6712 + return (err);
6713 +}
6714 +
6715 +
6716 +int
6717 +ipkg_packages_status(args_t *args,
6718 + const char *packages,
6719 + ipkg_status_callback cbstatus,
6720 + void *userdata)
6721 +{
6722 + ipkg_cmd_t *cmd;
6723 + ipkg_conf_t ipkg_conf;
6724 + int err;
6725 +
6726 + err = ipkg_conf_init (&ipkg_conf, args);
6727 + if (err)
6728 + {
6729 + return err;
6730 + }
6731 +
6732 + ipkg_cb_status = cbstatus;
6733 +
6734 + /* we need to do this because of static declarations,
6735 + * maybe a good idea to change */
6736 + cmd = ipkg_cmd_find ("status");
6737 + if (packages)
6738 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6739 + else
6740 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6741 +
6742 + ipkg_cb_status = NULL;
6743 + ipkg_conf_deinit (&ipkg_conf);
6744 + return (err);
6745 +}
6746 +
6747 +
6748 +int
6749 +ipkg_packages_info(args_t *args,
6750 + const char *packages,
6751 + ipkg_status_callback cbstatus,
6752 + void *userdata)
6753 +{
6754 + ipkg_cmd_t *cmd;
6755 + ipkg_conf_t ipkg_conf;
6756 + int err;
6757 +
6758 + err = ipkg_conf_init (&ipkg_conf, args);
6759 + if (err)
6760 + {
6761 + return err;
6762 + }
6763 +
6764 + ipkg_cb_status = cbstatus;
6765 +
6766 + /* we need to do this because of static declarations,
6767 + * maybe a good idea to change */
6768 + cmd = ipkg_cmd_find ("info");
6769 + if (packages)
6770 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6771 + else
6772 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6773 +
6774 + ipkg_cb_status = NULL;
6775 + ipkg_conf_deinit (&ipkg_conf);
6776 + return (err);
6777 +}
6778 +
6779 +
6780 +int
6781 +ipkg_packages_install (args_t * args, const char *name)
6782 +{
6783 + ipkg_cmd_t *cmd;
6784 + ipkg_conf_t ipkg_conf;
6785 + int err;
6786 +
6787 + /* this error should be handled in application */
6788 + if (!name || !strlen (name))
6789 + return (-1);
6790 +
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6792 + if (err)
6793 + {
6794 + return err;
6795 + }
6796 +
6797 + /* we need to do this because of static declarations,
6798 + * maybe a good idea to change */
6799 + cmd = ipkg_cmd_find ("install");
6800 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6801 +
6802 + ipkg_conf_deinit(&ipkg_conf);
6803 + return (err);
6804 +}
6805 +
6806 +
6807 +int
6808 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6809 +{
6810 + ipkg_cmd_t *cmd;
6811 + ipkg_conf_t ipkg_conf;
6812 + int err;
6813 +
6814 + /* this error should be handled in application */
6815 + if (!name || !strlen (name))
6816 + return (-1);
6817 +
6818 + err = ipkg_conf_init (&ipkg_conf, args);
6819 + if (err)
6820 + {
6821 + return err;
6822 + }
6823 +
6824 + /* we need to do this because of static declarations,
6825 + * maybe a good idea to change */
6826 + if (purge)
6827 + cmd = ipkg_cmd_find ("purge");
6828 + else
6829 + cmd = ipkg_cmd_find ("remove");
6830 +
6831 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6832 +
6833 + ipkg_conf_deinit(&ipkg_conf);
6834 + return (err);
6835 +}
6836 +
6837 +
6838 +int
6839 +ipkg_lists_update(args_t *args)
6840 +{
6841 + ipkg_cmd_t *cmd;
6842 + ipkg_conf_t ipkg_conf;
6843 + int err;
6844 +
6845 + err = ipkg_conf_init (&ipkg_conf, args);
6846 + if (err)
6847 + {
6848 + return err;
6849 + }
6850 +
6851 + /* we need to do this because of static declarations,
6852 + * maybe a good idea to change */
6853 + cmd = ipkg_cmd_find ("update");
6854 +
6855 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6856 +
6857 + ipkg_conf_deinit(&ipkg_conf);
6858 + return (err);
6859 +}
6860 +
6861 +
6862 +int
6863 +ipkg_packages_upgrade(args_t *args)
6864 +{
6865 + ipkg_cmd_t *cmd;
6866 + ipkg_conf_t ipkg_conf;
6867 + int err;
6868 +
6869 + err = ipkg_conf_init (&ipkg_conf, args);
6870 + if (err)
6871 + {
6872 + return err;
6873 + }
6874 +
6875 + /* we need to do this because of static declarations,
6876 + * maybe a good idea to change */
6877 + cmd = ipkg_cmd_find ("upgrade");
6878 +
6879 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6880 +
6881 + ipkg_conf_deinit(&ipkg_conf);
6882 + return (err);
6883 +}
6884 +
6885 +
6886 +int
6887 +ipkg_packages_download (args_t * args, const char *name)
6888 +{
6889 + ipkg_cmd_t *cmd;
6890 + ipkg_conf_t ipkg_conf;
6891 + int err;
6892 +
6893 + /* this error should be handled in application */
6894 + if (!name || !strlen (name))
6895 + return (-1);
6896 +
6897 + err = ipkg_conf_init (&ipkg_conf, args);
6898 + if (err)
6899 + {
6900 + return err;
6901 + }
6902 +
6903 + /* we need to do this because of static declarations,
6904 + * maybe a good idea to change */
6905 + cmd = ipkg_cmd_find ("download");
6906 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6907 +
6908 + ipkg_conf_deinit(&ipkg_conf);
6909 + return (err);
6910 +}
6911 +
6912 +
6913 +int
6914 +ipkg_package_files(args_t *args,
6915 + const char *name,
6916 + ipkg_list_callback cblist,
6917 + void *userdata)
6918 +{
6919 + ipkg_cmd_t *cmd;
6920 + ipkg_conf_t ipkg_conf;
6921 + int err;
6922 +
6923 + /* this error should be handled in application */
6924 + if (!name || !strlen (name))
6925 + return (-1);
6926 +
6927 + err = ipkg_conf_init (&ipkg_conf, args);
6928 + if (err)
6929 + {
6930 + return err;
6931 + }
6932 +
6933 + ipkg_cb_list = cblist;
6934 +
6935 + /* we need to do this because of static declarations,
6936 + * maybe a good idea to change */
6937 + cmd = ipkg_cmd_find ("files");
6938 +
6939 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6940 +
6941 + ipkg_cb_list = NULL;
6942 + ipkg_conf_deinit(&ipkg_conf);
6943 + return (err);
6944 +}
6945 +
6946 +
6947 +int
6948 +ipkg_file_search(args_t *args,
6949 + const char *file,
6950 + ipkg_list_callback cblist,
6951 + void *userdata)
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 (!file || !strlen (file))
6959 + return (-1);
6960 +
6961 + err = ipkg_conf_init (&ipkg_conf, args);
6962 + if (err)
6963 + {
6964 + return err;
6965 + }
6966 +
6967 + ipkg_cb_list = cblist;
6968 +
6969 + /* we need to do this because of static declarations,
6970 + * maybe a good idea to change */
6971 + cmd = ipkg_cmd_find ("search");
6972 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6973 +
6974 + ipkg_cb_list = NULL;
6975 + ipkg_conf_deinit(&ipkg_conf);
6976 + return(err);
6977 +}
6978 +
6979 +
6980 +int
6981 +ipkg_file_what(args_t *args, const char *file, const char* command)
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 (!file || !strlen (file))
6989 + return (-1);
6990 +
6991 + err = ipkg_conf_init (&ipkg_conf, args);
6992 + if (err)
6993 + {
6994 + return err;
6995 + }
6996 +
6997 + /* we need to do this because of static declarations,
6998 + * maybe a good idea to change */
6999 + cmd = ipkg_cmd_find (command);
7000 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7001 +
7002 + ipkg_conf_deinit(&ipkg_conf);
7003 + return(err);
7004 +}
7005 +
7006 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7007 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7008 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7009 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7010 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7011 +
7012 +
7013 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7014 + char *msg)
7015 +{
7016 + if (conf && (conf->verbosity < level)) {
7017 + return 0;
7018 + } else {
7019 +#ifdef IPKG_LIB
7020 + if ( level == IPKG_ERROR ){
7021 + push_error_list(&error_list, msg);
7022 +// printf(msg);
7023 + } else
7024 +#endif
7025 + printf(msg);
7026 + }
7027 + return 0;
7028 +}
7029 +
7030 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7031 + pkg_state_status_t status, void *userdata)
7032 +{
7033 + if (desc)
7034 + printf("%s - %s - %s\n", name, version, desc);
7035 + else
7036 + printf("%s - %s\n", name, version);
7037 + return 0;
7038 +}
7039 +
7040 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7041 + pkg_state_status_t status, void *userdata)
7042 +{
7043 + if (desc)
7044 + printf("%s\n", desc);
7045 + return 0;
7046 +}
7047 +
7048 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7049 + void *userdata)
7050 +{
7051 + printf("%s\n", desc);
7052 + return 0;
7053 +}
7054 +
7055 +char* default_ipkg_response_callback(char *question)
7056 +{
7057 + char *response = NULL;
7058 + printf(question);
7059 + fflush(stdout);
7060 + do {
7061 + response = (char *)file_read_line_alloc(stdin);
7062 + } while (response == NULL);
7063 + return response;
7064 +}
7065 +
7066 +/* This is used for backward compatibility */
7067 +int
7068 +ipkg_op (int argc, char *argv[])
7069 +{
7070 + int err, optind;
7071 + args_t args;
7072 + char *cmd_name;
7073 + ipkg_cmd_t *cmd;
7074 + ipkg_conf_t ipkg_conf;
7075 +
7076 + args_init (&args);
7077 +
7078 + optind = args_parse (&args, argc, argv);
7079 + if (optind == argc || optind < 0)
7080 + {
7081 + args_usage ("ipkg must have one sub-command argument");
7082 + }
7083 +
7084 + cmd_name = argv[optind++];
7085 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7086 + read anything from there.
7087 +*/
7088 + if ( !strcmp(cmd_name,"print-architecture") ||
7089 + !strcmp(cmd_name,"print_architecture") ||
7090 + !strcmp(cmd_name,"print-installation-architecture") ||
7091 + !strcmp(cmd_name,"print_installation_architecture") )
7092 + args.nocheckfordirorfile = 1;
7093 +
7094 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7095 + read anything from there.
7096 +*/
7097 + if ( !strcmp(cmd_name,"flag") ||
7098 + !strcmp(cmd_name,"configure") ||
7099 + !strcmp(cmd_name,"remove") ||
7100 + !strcmp(cmd_name,"files") ||
7101 + !strcmp(cmd_name,"search") ||
7102 + !strcmp(cmd_name,"compare_versions") ||
7103 + !strcmp(cmd_name,"compare-versions") ||
7104 + !strcmp(cmd_name,"list_installed") ||
7105 + !strcmp(cmd_name,"list-installed") ||
7106 + !strcmp(cmd_name,"status") )
7107 + args.noreadfeedsfile = 1;
7108 +
7109 +
7110 + err = ipkg_conf_init (&ipkg_conf, &args);
7111 + if (err)
7112 + {
7113 + return err;
7114 + }
7115 +
7116 + args_deinit (&args);
7117 +
7118 + ipkg_cb_message = default_ipkg_message_callback;
7119 + ipkg_cb_response = default_ipkg_response_callback;
7120 + ipkg_cb_status = default_ipkg_status_callback;
7121 + if ( strcmp(cmd_name, "files")==0)
7122 + ipkg_cb_list = default_ipkg_files_callback;
7123 + else
7124 + ipkg_cb_list = default_ipkg_list_callback;
7125 +
7126 + cmd = ipkg_cmd_find (cmd_name);
7127 + if (cmd == NULL)
7128 + {
7129 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7130 + cmd_name);
7131 + args_usage (NULL);
7132 + }
7133 +
7134 + if (cmd->requires_args && optind == argc)
7135 + {
7136 + fprintf (stderr,
7137 + "%s: the ``%s'' command requires at least one argument\n",
7138 + __FUNCTION__, cmd_name);
7139 + args_usage (NULL);
7140 + }
7141 +
7142 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7143 +
7144 + ipkg_conf_deinit (&ipkg_conf);
7145 +
7146 + return err;
7147 +}
7148 +
7149 +#endif /* IPKG_LIB */
7150 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h
7151 --- busybox-1.2.0-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7152 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-07-22 16:31:25.000000000 +0200
7153 @@ -0,0 +1,87 @@
7154 +/* ipkglib.h - the itsy package management system
7155 +
7156 + Florian Boor <florian.boor@kernelconcepts.de>
7157 +
7158 + This program is free software; you can redistribute it and/or
7159 + modify it under the terms of the GNU General Public License as
7160 + published by the Free Software Foundation; either version 2, or (at
7161 + your option) any later version.
7162 +
7163 + This program is distributed in the hope that it will be useful, but
7164 + WITHOUT ANY WARRANTY; without even the implied warranty of
7165 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7166 + General Public License for more details.
7167 +*/
7168 +
7169 +#ifndef IPKGLIB_H
7170 +#define IPKGLIB_H
7171 +
7172 +#ifdef IPKG_LIB
7173 +
7174 +#include "ipkg_conf.h"
7175 +#include "ipkg_message.h"
7176 +
7177 +#include "args.h"
7178 +#include "pkg.h"
7179 +
7180 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7181 + char *msg);
7182 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7183 + pkg_state_status_t status, void *userdata);
7184 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7185 + void *userdata);
7186 +typedef char* (*ipkg_response_callback)(char *question);
7187 +
7188 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7189 +extern int ipkg_init (ipkg_message_callback mcall,
7190 + ipkg_response_callback rcall,
7191 + args_t * args);
7192 +
7193 +extern int ipkg_deinit (args_t *args);
7194 +extern int ipkg_packages_list(args_t *args,
7195 + const char *packages,
7196 + ipkg_list_callback cblist,
7197 + void *userdata);
7198 +extern int ipkg_packages_status(args_t *args,
7199 + const char *packages,
7200 + ipkg_status_callback cbstatus,
7201 + void *userdata);
7202 +extern int ipkg_packages_info(args_t *args,
7203 + const char *packages,
7204 + ipkg_status_callback cbstatus,
7205 + void *userdata);
7206 +extern int ipkg_packages_install(args_t *args, const char *name);
7207 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7208 +extern int ipkg_lists_update(args_t *args);
7209 +extern int ipkg_packages_upgrade(args_t *args);
7210 +extern int ipkg_packages_download(args_t *args, const char *name);
7211 +extern int ipkg_package_files(args_t *args,
7212 + const char *name,
7213 + ipkg_list_callback cblist,
7214 + void *userdata);
7215 +extern int ipkg_file_search(args_t *args,
7216 + const char *file,
7217 + ipkg_list_callback cblist,
7218 + void *userdata);
7219 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7220 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7221 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7222 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7223 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7224 +
7225 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7226 +extern ipkg_response_callback ipkg_cb_response;
7227 +extern ipkg_status_callback ipkg_cb_status;
7228 +extern ipkg_list_callback ipkg_cb_list;
7229 +extern void push_error_list(struct errlist **errors,char * msg);
7230 +extern void reverse_error_list(struct errlist **errors);
7231 +extern void free_error_list(struct errlist **errors);
7232 +
7233 +#else
7234 +
7235 +extern int ipkg_op(int argc, char *argv[]);
7236 +
7237 +#endif
7238 +
7239 +
7240 +#endif
7241 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile
7242 --- busybox-1.2.0-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
7243 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile 2006-07-22 16:31:25.000000000 +0200
7244 @@ -0,0 +1,32 @@
7245 +# Makefile for busybox
7246 +#
7247 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7248 +#
7249 +# This program is free software; you can redistribute it and/or modify
7250 +# it under the terms of the GNU General Public License as published by
7251 +# the Free Software Foundation; either version 2 of the License, or
7252 +# (at your option) any later version.
7253 +#
7254 +# This program is distributed in the hope that it will be useful,
7255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7257 +# General Public License for more details.
7258 +#
7259 +# You should have received a copy of the GNU General Public License
7260 +# along with this program; if not, write to the Free Software
7261 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7262 +#
7263 +
7264 +top_srcdir=../..
7265 +top_builddir=../..
7266 +srcdir=$(top_srcdir)/archival/libipkg
7267 +LIBIPKG_DIR:=./
7268 +include $(top_builddir)/Rules.mak
7269 +include $(top_builddir)/.config
7270 +include $(srcdir)/Makefile.in
7271 +all: $(libraries-y)
7272 +-include $(top_builddir)/.depend
7273 +
7274 +clean:
7275 + rm -f *.o *.a $(AR_TARGET)
7276 +
7277 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in
7278 --- busybox-1.2.0-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
7279 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in 2006-07-22 16:31:25.000000000 +0200
7280 @@ -0,0 +1,85 @@
7281 +# Makefile for busybox
7282 +#
7283 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7284 +#
7285 +# This program is free software; you can redistribute it and/or modify
7286 +# it under the terms of the GNU General Public License as published by
7287 +# the Free Software Foundation; either version 2 of the License, or
7288 +# (at your option) any later version.
7289 +#
7290 +# This program is distributed in the hope that it will be useful,
7291 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7292 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7293 +# General Public License for more details.
7294 +#
7295 +# You should have received a copy of the GNU General Public License
7296 +# along with this program; if not, write to the Free Software
7297 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7298 +#
7299 +
7300 +LIBIPKG_AR:=libipkg.a
7301 +ifndef $(LIBIPKG_DIR)
7302 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
7303 +endif
7304 +srcdir=$(top_srcdir)/archival/libipkg
7305 +
7306 +LIBIPKG_CORE_SOURCES:= \
7307 + args.c \
7308 + libipkg.c \
7309 + user.c \
7310 +
7311 +LIBIPKG_CMD_SOURCES:= \
7312 + ipkg_cmd.c \
7313 + ipkg_configure.c \
7314 + ipkg_download.c \
7315 + ipkg_install.c \
7316 + ipkg_remove.c \
7317 + ipkg_upgrade.c \
7318 +
7319 +LIBIPKG_DB_SOURCES:= \
7320 + hash_table.c \
7321 + ipkg_conf.c \
7322 + ipkg_utils.c \
7323 + pkg.c \
7324 + pkg_depends.c \
7325 + pkg_extract.c \
7326 + pkg_hash.c \
7327 + pkg_parse.c \
7328 + pkg_vec.c \
7329 +
7330 +LIBIPKG_LIST_SOURCES:= \
7331 + conffile.c \
7332 + conffile_list.c \
7333 + nv_pair.c \
7334 + nv_pair_list.c \
7335 + pkg_dest.c \
7336 + pkg_dest_list.c \
7337 + pkg_src.c \
7338 + pkg_src_list.c \
7339 + str_list.c \
7340 + void_list.c \
7341 +
7342 +LIBIPKG_UTIL_SOURCES:= \
7343 + file_util.c \
7344 + ipkg_message.c \
7345 + md5.c \
7346 + str_util.c \
7347 + xsystem.c \
7348 +
7349 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CORE_SOURCES)
7350 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CMD_SOURCES)
7351 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_DB_SOURCES)
7352 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_LIST_SOURCES)
7353 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_SOURCES)
7354 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
7355 +
7356 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
7357 +
7358 +libraries-$(CONFIG_IPKG) += $(LIBIPKG_DIR)$(LIBIPKG_AR)
7359 +
7360 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
7361 + $(do_ar)
7362 +
7363 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
7364 + $(compile.c)
7365 +
7366 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c
7367 --- busybox-1.2.0-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7368 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c 2006-07-22 16:31:25.000000000 +0200
7369 @@ -0,0 +1,48 @@
7370 +/* md5.c - wrappers to busybox md5 functions
7371 + *
7372 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7373 + *
7374 + * This program is free software; you can redistribute it and/or modify
7375 + * it under the terms of the GNU General Public License as published by
7376 + * the Free Software Foundation; either version 2, or (at your option)
7377 + * any later version.
7378 + *
7379 + * This program is distributed in the hope that it will be useful,
7380 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7382 + * GNU General Public License for more details.
7383 + *
7384 + * You should have received a copy of the GNU General Public License
7385 + * along with this program; if not, write to the Free Software Foundation,
7386 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7387 + */
7388 +
7389 +#include <stdio.h>
7390 +#include "libbb.h"
7391 +
7392 +#include "md5.h"
7393 +
7394 +int md5_stream(FILE *stream, void *resblock)
7395 +{
7396 + int fd;
7397 + int sum;
7398 +
7399 + if( (fd = fileno(stream)) == -1 ) {
7400 + bb_error_msg("bad file descriptor");
7401 + return 1;
7402 + }
7403 +
7404 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7405 +
7406 + return 0;
7407 +}
7408 +
7409 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7410 +{
7411 + md5_ctx_t md5_cx;
7412 +
7413 + md5_begin(&md5_cx);
7414 + md5_hash(buffer, len, &md5_cx);
7415 + return md5_end(resblock, &md5_cx);
7416 +}
7417 +
7418 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h
7419 --- busybox-1.2.0-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7420 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h 2006-07-22 16:31:25.000000000 +0200
7421 @@ -0,0 +1,35 @@
7422 +/* md5.h - Compute MD5 checksum of files or strings according to the
7423 + * definition of MD5 in RFC 1321 from April 1992.
7424 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7425 + *
7426 + * This program is free software; you can redistribute it and/or modify
7427 + * it under the terms of the GNU General Public License as published by
7428 + * the Free Software Foundation; either version 2, or (at your option)
7429 + * any later version.
7430 + *
7431 + * This program is distributed in the hope that it will be useful,
7432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7434 + * GNU General Public License for more details.
7435 + *
7436 + * You should have received a copy of the GNU General Public License
7437 + * along with this program; if not, write to the Free Software Foundation,
7438 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7439 + */
7440 +
7441 +#ifndef MD5_H
7442 +#define MD5_H
7443 +
7444 +/* Compute MD5 message digest for bytes read from STREAM. The
7445 + resulting message digest number will be written into the 16 bytes
7446 + beginning at RESBLOCK. */
7447 +int md5_stream(FILE *stream, void *resblock);
7448 +
7449 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7450 + result is always in little endian byte order, so that a byte-wise
7451 + output yields to the wanted ASCII representation of the message
7452 + digest. */
7453 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7454 +
7455 +#endif
7456 +
7457 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c
7458 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7459 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-07-22 16:31:25.000000000 +0200
7460 @@ -0,0 +1,40 @@
7461 +/* nv_pair.c - the itsy package management system
7462 +
7463 + Carl D. Worth
7464 +
7465 + Copyright (C) 2001 University of Southern California
7466 +
7467 + This program is free software; you can redistribute it and/or
7468 + modify it under the terms of the GNU General Public License as
7469 + published by the Free Software Foundation; either version 2, or (at
7470 + your option) any later version.
7471 +
7472 + This program is distributed in the hope that it will be useful, but
7473 + WITHOUT ANY WARRANTY; without even the implied warranty of
7474 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7475 + General Public License for more details.
7476 +*/
7477 +
7478 +#include "ipkg.h"
7479 +
7480 +#include "nv_pair.h"
7481 +#include "str_util.h"
7482 +
7483 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7484 +{
7485 + nv_pair->name = str_dup_safe(name);
7486 + nv_pair->value = str_dup_safe(value);
7487 +
7488 + return 0;
7489 +}
7490 +
7491 +void nv_pair_deinit(nv_pair_t *nv_pair)
7492 +{
7493 + free(nv_pair->name);
7494 + nv_pair->name = NULL;
7495 +
7496 + free(nv_pair->value);
7497 + nv_pair->value = NULL;
7498 +}
7499 +
7500 +
7501 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h
7502 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7503 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-07-22 16:31:25.000000000 +0200
7504 @@ -0,0 +1,32 @@
7505 +/* nv_pair.h - the itsy package management system
7506 +
7507 + Carl D. Worth
7508 +
7509 + Copyright (C) 2001 University of Southern California
7510 +
7511 + This program is free software; you can redistribute it and/or
7512 + modify it under the terms of the GNU General Public License as
7513 + published by the Free Software Foundation; either version 2, or (at
7514 + your option) any later version.
7515 +
7516 + This program is distributed in the hope that it will be useful, but
7517 + WITHOUT ANY WARRANTY; without even the implied warranty of
7518 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7519 + General Public License for more details.
7520 +*/
7521 +
7522 +#ifndef NV_PAIR_H
7523 +#define NV_PAIR_H
7524 +
7525 +typedef struct nv_pair nv_pair_t;
7526 +struct nv_pair
7527 +{
7528 + char *name;
7529 + char *value;
7530 +};
7531 +
7532 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7533 +void nv_pair_deinit(nv_pair_t *nv_pair);
7534 +
7535 +#endif
7536 +
7537 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c
7538 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7539 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-07-22 16:31:25.000000000 +0200
7540 @@ -0,0 +1,98 @@
7541 +/* nv_pair_list.c - the itsy package management system
7542 +
7543 + Carl D. Worth
7544 +
7545 + Copyright (C) 2001 University of Southern California
7546 +
7547 + This program is free software; you can redistribute it and/or
7548 + modify it under the terms of the GNU General Public License as
7549 + published by the Free Software Foundation; either version 2, or (at
7550 + your option) any later version.
7551 +
7552 + This program is distributed in the hope that it will be useful, but
7553 + WITHOUT ANY WARRANTY; without even the implied warranty of
7554 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7555 + General Public License for more details.
7556 +*/
7557 +
7558 +#include "ipkg.h"
7559 +
7560 +#include "nv_pair.h"
7561 +#include "void_list.h"
7562 +#include "nv_pair_list.h"
7563 +
7564 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7565 +{
7566 + return void_list_elt_init((void_list_elt_t *) elt, data);
7567 +}
7568 +
7569 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7570 +{
7571 + void_list_elt_deinit((void_list_elt_t *) elt);
7572 +}
7573 +
7574 +int nv_pair_list_init(nv_pair_list_t *list)
7575 +{
7576 + return void_list_init((void_list_t *) list);
7577 +}
7578 +
7579 +void nv_pair_list_deinit(nv_pair_list_t *list)
7580 +{
7581 + nv_pair_list_elt_t *iter;
7582 + nv_pair_t *nv_pair;
7583 +
7584 + for (iter = list->head; iter; iter = iter->next) {
7585 + nv_pair = iter->data;
7586 + nv_pair_deinit(nv_pair);
7587 +
7588 + /* malloced in nv_pair_list_append */
7589 + free(nv_pair);
7590 + iter->data = NULL;
7591 + }
7592 + void_list_deinit((void_list_t *) list);
7593 +}
7594 +
7595 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7596 +{
7597 + int err;
7598 +
7599 + /* freed in nv_pair_list_deinit */
7600 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7601 +
7602 + if (nv_pair == NULL) {
7603 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7604 + return NULL;
7605 + }
7606 + nv_pair_init(nv_pair, name, value);
7607 +
7608 + err = void_list_append((void_list_t *) list, nv_pair);
7609 + if (err) {
7610 + return NULL;
7611 + }
7612 +
7613 + return nv_pair;
7614 +}
7615 +
7616 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7617 +{
7618 + return void_list_push((void_list_t *) list, data);
7619 +}
7620 +
7621 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7622 +{
7623 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7624 +}
7625 +
7626 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7627 +{
7628 + nv_pair_list_elt_t *iter;
7629 + nv_pair_t *nv_pair;
7630 +
7631 + for (iter = list->head; iter; iter = iter->next) {
7632 + nv_pair = iter->data;
7633 + if (strcmp(nv_pair->name, name) == 0) {
7634 + return nv_pair->value;
7635 + }
7636 + }
7637 + return NULL;
7638 +}
7639 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h
7640 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7641 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-07-22 16:31:25.000000000 +0200
7642 @@ -0,0 +1,60 @@
7643 +/* nv_pair_list.h - the itsy package management system
7644 +
7645 + Carl D. Worth
7646 +
7647 + Copyright (C) 2001 University of Southern California
7648 +
7649 + This program is free software; you can redistribute it and/or
7650 + modify it under the terms of the GNU General Public License as
7651 + published by the Free Software Foundation; either version 2, or (at
7652 + your option) any later version.
7653 +
7654 + This program is distributed in the hope that it will be useful, but
7655 + WITHOUT ANY WARRANTY; without even the implied warranty of
7656 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7657 + General Public License for more details.
7658 +*/
7659 +
7660 +#ifndef NV_PAIR_LIST_H
7661 +#define NV_PAIR_LIST_H
7662 +
7663 +#include "nv_pair.h"
7664 +#include "void_list.h"
7665 +
7666 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7667 +struct nv_pair_list_elt
7668 +{
7669 + nv_pair_list_elt_t *next;
7670 + nv_pair_t *data;
7671 +};
7672 +
7673 +typedef struct nv_pair_list nv_pair_list_t;
7674 +struct nv_pair_list
7675 +{
7676 + nv_pair_list_elt_t pre_head;
7677 + nv_pair_list_elt_t *head;
7678 + nv_pair_list_elt_t *tail;
7679 +};
7680 +
7681 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7682 +{
7683 + if (list->head == NULL)
7684 + return 1;
7685 + else
7686 + return 0;
7687 +}
7688 +
7689 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7690 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7691 +
7692 +int nv_pair_list_init(nv_pair_list_t *list);
7693 +void nv_pair_list_deinit(nv_pair_list_t *list);
7694 +
7695 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7696 + const char *name, const char *value);
7697 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7698 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7699 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7700 +
7701 +#endif
7702 +
7703 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c
7704 --- busybox-1.2.0-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7705 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c 2006-07-22 16:31:25.000000000 +0200
7706 @@ -0,0 +1,1754 @@
7707 +/* pkg.c - the itsy package management system
7708 +
7709 + Carl D. Worth
7710 +
7711 + Copyright (C) 2001 University of Southern California
7712 +
7713 + This program is free software; you can redistribute it and/or
7714 + modify it under the terms of the GNU General Public License as
7715 + published by the Free Software Foundation; either version 2, or (at
7716 + your option) any later version.
7717 +
7718 + This program is distributed in the hope that it will be useful, but
7719 + WITHOUT ANY WARRANTY; without even the implied warranty of
7720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7721 + General Public License for more details.
7722 +*/
7723 +
7724 +#include "ipkg.h"
7725 +#include <ctype.h>
7726 +#include <string.h>
7727 +#include <errno.h>
7728 +
7729 +#include "pkg.h"
7730 +
7731 +#include "pkg_parse.h"
7732 +#include "pkg_extract.h"
7733 +#include "ipkg_message.h"
7734 +#include "ipkg_utils.h"
7735 +
7736 +#include "sprintf_alloc.h"
7737 +#include "file_util.h"
7738 +#include "str_util.h"
7739 +#include "xsystem.h"
7740 +#include "ipkg_conf.h"
7741 +
7742 +typedef struct enum_map enum_map_t;
7743 +struct enum_map
7744 +{
7745 + int value;
7746 + char *str;
7747 +};
7748 +
7749 +static const enum_map_t pkg_state_want_map[] = {
7750 + { SW_UNKNOWN, "unknown"},
7751 + { SW_INSTALL, "install"},
7752 + { SW_DEINSTALL, "deinstall"},
7753 + { SW_PURGE, "purge"}
7754 +};
7755 +
7756 +static const enum_map_t pkg_state_flag_map[] = {
7757 + { SF_OK, "ok"},
7758 + { SF_REINSTREQ, "reinstreq"},
7759 + { SF_HOLD, "hold"},
7760 + { SF_REPLACE, "replace"},
7761 + { SF_NOPRUNE, "noprune"},
7762 + { SF_PREFER, "prefer"},
7763 + { SF_OBSOLETE, "obsolete"},
7764 + { SF_USER, "user"},
7765 +};
7766 +
7767 +static const enum_map_t pkg_state_status_map[] = {
7768 + { SS_NOT_INSTALLED, "not-installed" },
7769 + { SS_UNPACKED, "unpacked" },
7770 + { SS_HALF_CONFIGURED, "half-configured" },
7771 + { SS_INSTALLED, "installed" },
7772 + { SS_HALF_INSTALLED, "half-installed" },
7773 + { SS_CONFIG_FILES, "config-files" },
7774 + { SS_POST_INST_FAILED, "post-inst-failed" },
7775 + { SS_REMOVAL_FAILED, "removal-failed" }
7776 +};
7777 +
7778 +static int verrevcmp(const char *val, const char *ref);
7779 +
7780 +
7781 +pkg_t *pkg_new(void)
7782 +{
7783 + pkg_t *pkg;
7784 +
7785 + pkg = malloc(sizeof(pkg_t));
7786 + if (pkg == NULL) {
7787 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7788 + return NULL;
7789 + }
7790 +
7791 + pkg_init(pkg);
7792 +
7793 + return pkg;
7794 +}
7795 +
7796 +int pkg_init(pkg_t *pkg)
7797 +{
7798 + memset(pkg, 0, sizeof(pkg_t));
7799 + pkg->name = NULL;
7800 + pkg->epoch = 0;
7801 + pkg->version = NULL;
7802 + pkg->revision = NULL;
7803 + pkg->familiar_revision = NULL;
7804 + pkg->dest = NULL;
7805 + pkg->src = NULL;
7806 + pkg->architecture = NULL;
7807 + pkg->maintainer = NULL;
7808 + pkg->section = NULL;
7809 + pkg->description = NULL;
7810 + pkg->state_want = SW_UNKNOWN;
7811 + pkg->state_flag = SF_OK;
7812 + pkg->state_status = SS_NOT_INSTALLED;
7813 + pkg->depends_str = NULL;
7814 + pkg->provides_str = NULL;
7815 + pkg->depends_count = 0;
7816 + pkg->depends = NULL;
7817 + pkg->suggests_str = NULL;
7818 + pkg->recommends_str = NULL;
7819 + pkg->suggests_count = 0;
7820 + pkg->recommends_count = 0;
7821 +
7822 + /* Abhaya: added init for conflicts fields */
7823 + pkg->conflicts = NULL;
7824 + pkg->conflicts_count = 0;
7825 +
7826 + /* added for replaces. Jamey 7/23/2002 */
7827 + pkg->replaces = NULL;
7828 + pkg->replaces_count = 0;
7829 +
7830 + pkg->pre_depends_count = 0;
7831 + pkg->pre_depends_str = NULL;
7832 + pkg->provides_count = 0;
7833 + pkg->provides = NULL;
7834 + pkg->filename = NULL;
7835 + pkg->local_filename = NULL;
7836 + pkg->tmp_unpack_dir = NULL;
7837 + pkg->md5sum = NULL;
7838 + pkg->size = NULL;
7839 + pkg->installed_size = NULL;
7840 + pkg->priority = NULL;
7841 + pkg->source = NULL;
7842 + conffile_list_init(&pkg->conffiles);
7843 + pkg->installed_files = NULL;
7844 + pkg->installed_files_ref_cnt = 0;
7845 + pkg->essential = 0;
7846 + pkg->provided_by_hand = 0;
7847 +
7848 + return 0;
7849 +}
7850 +
7851 +void pkg_deinit(pkg_t *pkg)
7852 +{
7853 + free(pkg->name);
7854 + pkg->name = NULL;
7855 + pkg->epoch = 0;
7856 + free(pkg->version);
7857 + pkg->version = NULL;
7858 + /* revision and familiar_revision share storage with version, so
7859 + don't free */
7860 + pkg->revision = NULL;
7861 + pkg->familiar_revision = NULL;
7862 + /* owned by ipkg_conf_t */
7863 + pkg->dest = NULL;
7864 + /* owned by ipkg_conf_t */
7865 + pkg->src = NULL;
7866 + free(pkg->architecture);
7867 + pkg->architecture = NULL;
7868 + free(pkg->maintainer);
7869 + pkg->maintainer = NULL;
7870 + free(pkg->section);
7871 + pkg->section = NULL;
7872 + free(pkg->description);
7873 + pkg->description = NULL;
7874 + pkg->state_want = SW_UNKNOWN;
7875 + pkg->state_flag = SF_OK;
7876 + pkg->state_status = SS_NOT_INSTALLED;
7877 + free(pkg->depends_str);
7878 + pkg->depends_str = NULL;
7879 + free(pkg->provides_str);
7880 + pkg->provides_str = NULL;
7881 + pkg->depends_count = 0;
7882 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7883 + pkg->pre_depends_count = 0;
7884 + free(pkg->pre_depends_str);
7885 + pkg->pre_depends_str = NULL;
7886 + pkg->provides_count = 0;
7887 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7888 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7889 + free(pkg->filename);
7890 + pkg->filename = NULL;
7891 + free(pkg->local_filename);
7892 + pkg->local_filename = NULL;
7893 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7894 + ipkg_install.c here. See comment in
7895 + ipkg_install.c:cleanup_temporary_files */
7896 + free(pkg->tmp_unpack_dir);
7897 + pkg->tmp_unpack_dir = NULL;
7898 + free(pkg->md5sum);
7899 + pkg->md5sum = NULL;
7900 + free(pkg->size);
7901 + pkg->size = NULL;
7902 + free(pkg->installed_size);
7903 + pkg->installed_size = NULL;
7904 + free(pkg->priority);
7905 + pkg->priority = NULL;
7906 + free(pkg->source);
7907 + pkg->source = NULL;
7908 + conffile_list_deinit(&pkg->conffiles);
7909 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7910 + since if they are calling deinit, they should know. Maybe do an
7911 + assertion here instead? */
7912 + pkg->installed_files_ref_cnt = 1;
7913 + pkg_free_installed_files(pkg);
7914 + pkg->essential = 0;
7915 +}
7916 +
7917 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7918 +{
7919 + int err;
7920 + char **raw;
7921 + FILE *control_file;
7922 +
7923 + err = pkg_init(pkg);
7924 + if (err) { return err; }
7925 +
7926 + pkg->local_filename = strdup(filename);
7927 +
7928 + control_file = tmpfile();
7929 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7930 + if (err) { return err; }
7931 +
7932 + rewind(control_file);
7933 + raw = read_raw_pkgs_from_stream(control_file);
7934 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7935 +
7936 + fclose(control_file);
7937 +
7938 + return 0;
7939 +}
7940 +
7941 +/* Merge any new information in newpkg into oldpkg */
7942 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7943 + newpkg, but should leave it usable. This rework is so that
7944 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7945 +/*
7946 + * uh, i thought that i had originally written this so that it took
7947 + * two pkgs and returned a new one? we can do that again... -sma
7948 + */
7949 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7950 +{
7951 + if (oldpkg == newpkg) {
7952 + return 0;
7953 + }
7954 +
7955 + if (!oldpkg->src)
7956 + oldpkg->src = newpkg->src;
7957 + if (!oldpkg->dest)
7958 + oldpkg->dest = newpkg->dest;
7959 + if (!oldpkg->architecture)
7960 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7961 + if (!oldpkg->arch_priority)
7962 + oldpkg->arch_priority = newpkg->arch_priority;
7963 + if (!oldpkg->section)
7964 + oldpkg->section = str_dup_safe(newpkg->section);
7965 + if(!oldpkg->maintainer)
7966 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7967 + if(!oldpkg->description)
7968 + oldpkg->description = str_dup_safe(newpkg->description);
7969 + if (set_status) {
7970 + /* merge the state_flags from the new package */
7971 + oldpkg->state_want = newpkg->state_want;
7972 + oldpkg->state_status = newpkg->state_status;
7973 + oldpkg->state_flag = newpkg->state_flag;
7974 + } else {
7975 + if (oldpkg->state_want == SW_UNKNOWN)
7976 + oldpkg->state_want = newpkg->state_want;
7977 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7978 + oldpkg->state_status = newpkg->state_status;
7979 + oldpkg->state_flag |= newpkg->state_flag;
7980 + }
7981 +
7982 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7983 + oldpkg->depends_str = newpkg->depends_str;
7984 + newpkg->depends_str = NULL;
7985 + oldpkg->depends_count = newpkg->depends_count;
7986 + newpkg->depends_count = 0;
7987 +
7988 + oldpkg->depends = newpkg->depends;
7989 + newpkg->depends = NULL;
7990 +
7991 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7992 + newpkg->pre_depends_str = NULL;
7993 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7994 + newpkg->pre_depends_count = 0;
7995 +
7996 + oldpkg->recommends_str = newpkg->recommends_str;
7997 + newpkg->recommends_str = NULL;
7998 + oldpkg->recommends_count = newpkg->recommends_count;
7999 + newpkg->recommends_count = 0;
8000 +
8001 + oldpkg->suggests_str = newpkg->suggests_str;
8002 + newpkg->suggests_str = NULL;
8003 + oldpkg->suggests_count = newpkg->suggests_count;
8004 + newpkg->suggests_count = 0;
8005 + }
8006 +
8007 + if (!oldpkg->provides_str) {
8008 + oldpkg->provides_str = newpkg->provides_str;
8009 + newpkg->provides_str = NULL;
8010 + oldpkg->provides_count = newpkg->provides_count;
8011 + newpkg->provides_count = 0;
8012 +
8013 + oldpkg->provides = newpkg->provides;
8014 + newpkg->provides = NULL;
8015 + }
8016 +
8017 + if (!oldpkg->conflicts_str) {
8018 + oldpkg->conflicts_str = newpkg->conflicts_str;
8019 + newpkg->conflicts_str = NULL;
8020 + oldpkg->conflicts_count = newpkg->conflicts_count;
8021 + newpkg->conflicts_count = 0;
8022 +
8023 + oldpkg->conflicts = newpkg->conflicts;
8024 + newpkg->conflicts = NULL;
8025 + }
8026 +
8027 + if (!oldpkg->replaces_str) {
8028 + oldpkg->replaces_str = newpkg->replaces_str;
8029 + newpkg->replaces_str = NULL;
8030 + oldpkg->replaces_count = newpkg->replaces_count;
8031 + newpkg->replaces_count = 0;
8032 +
8033 + oldpkg->replaces = newpkg->replaces;
8034 + newpkg->replaces = NULL;
8035 + }
8036 +
8037 + if (!oldpkg->filename)
8038 + oldpkg->filename = str_dup_safe(newpkg->filename);
8039 + if (0)
8040 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8041 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8042 + if (!oldpkg->local_filename)
8043 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8044 + if (!oldpkg->tmp_unpack_dir)
8045 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8046 + if (!oldpkg->md5sum)
8047 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8048 + if (!oldpkg->size)
8049 + oldpkg->size = str_dup_safe(newpkg->size);
8050 + if (!oldpkg->installed_size)
8051 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8052 + if (!oldpkg->priority)
8053 + oldpkg->priority = str_dup_safe(newpkg->priority);
8054 + if (!oldpkg->source)
8055 + oldpkg->source = str_dup_safe(newpkg->source);
8056 + if (oldpkg->conffiles.head == NULL){
8057 + oldpkg->conffiles = newpkg->conffiles;
8058 + conffile_list_init(&newpkg->conffiles);
8059 + }
8060 + if (!oldpkg->installed_files){
8061 + oldpkg->installed_files = newpkg->installed_files;
8062 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8063 + newpkg->installed_files = NULL;
8064 + }
8065 + if (!oldpkg->essential)
8066 + oldpkg->essential = newpkg->essential;
8067 +
8068 + return 0;
8069 +}
8070 +
8071 +abstract_pkg_t *abstract_pkg_new(void)
8072 +{
8073 + abstract_pkg_t * ab_pkg;
8074 +
8075 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8076 +
8077 + if (ab_pkg == NULL) {
8078 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8079 + return NULL;
8080 + }
8081 +
8082 + if ( abstract_pkg_init(ab_pkg) < 0 )
8083 + return NULL;
8084 +
8085 + return ab_pkg;
8086 +}
8087 +
8088 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8089 +{
8090 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8091 +
8092 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8093 + if (ab_pkg->provided_by==NULL){
8094 + return -1;
8095 + }
8096 + ab_pkg->dependencies_checked = 0;
8097 + ab_pkg->state_status = SS_NOT_INSTALLED;
8098 +
8099 + return 0;
8100 +}
8101 +
8102 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8103 + char * temp_str;
8104 + char **raw =NULL;
8105 + char **raw_start=NULL;
8106 +
8107 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8108 + if (temp_str == NULL ){
8109 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8110 + return;
8111 + }
8112 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8113 +
8114 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8115 + if (raw == NULL ){
8116 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8117 + return;
8118 + }
8119 +
8120 + while(*raw){
8121 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8122 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8123 + }
8124 + }
8125 + raw = raw_start;
8126 + while (*raw) {
8127 + if (raw!=NULL)
8128 + free(*raw++);
8129 + }
8130 +
8131 + free(raw_start);
8132 + free(temp_str);
8133 +
8134 + return ;
8135 +
8136 +}
8137 +
8138 +char * pkg_formatted_info(pkg_t *pkg )
8139 +{
8140 + char *line;
8141 + char * buff;
8142 +
8143 + buff = malloc(8192);
8144 + if (buff == NULL) {
8145 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8146 + return NULL;
8147 + }
8148 +
8149 + buff[0] = '\0';
8150 +
8151 + line = pkg_formatted_field(pkg, "Package");
8152 + strncat(buff ,line, strlen(line));
8153 + free(line);
8154 +
8155 + line = pkg_formatted_field(pkg, "Version");
8156 + strncat(buff ,line, strlen(line));
8157 + free(line);
8158 +
8159 + line = pkg_formatted_field(pkg, "Depends");
8160 + strncat(buff ,line, strlen(line));
8161 + free(line);
8162 +
8163 + line = pkg_formatted_field(pkg, "Recommends");
8164 + strncat(buff ,line, strlen(line));
8165 + free(line);
8166 +
8167 + line = pkg_formatted_field(pkg, "Suggests");
8168 + strncat(buff ,line, strlen(line));
8169 + free(line);
8170 +
8171 + line = pkg_formatted_field(pkg, "Provides");
8172 + strncat(buff ,line, strlen(line));
8173 + free(line);
8174 +
8175 + line = pkg_formatted_field(pkg, "Replaces");
8176 + strncat(buff ,line, strlen(line));
8177 + free(line);
8178 +
8179 + line = pkg_formatted_field(pkg, "Conflicts");
8180 + strncat(buff ,line, strlen(line));
8181 + free(line);
8182 +
8183 + line = pkg_formatted_field(pkg, "Status");
8184 + strncat(buff ,line, strlen(line));
8185 + free(line);
8186 +
8187 + line = pkg_formatted_field(pkg, "Section");
8188 + strncat(buff ,line, strlen(line));
8189 + free(line);
8190 +
8191 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8192 + strncat(buff ,line, strlen(line));
8193 + free(line);
8194 +
8195 + line = pkg_formatted_field(pkg, "Architecture");
8196 + strncat(buff ,line, strlen(line));
8197 + free(line);
8198 +
8199 + line = pkg_formatted_field(pkg, "Maintainer");
8200 + strncat(buff ,line, strlen(line));
8201 + free(line);
8202 +
8203 + line = pkg_formatted_field(pkg, "MD5sum");
8204 + strncat(buff ,line, strlen(line));
8205 + free(line);
8206 +
8207 + line = pkg_formatted_field(pkg, "Size");
8208 + strncat(buff ,line, strlen(line));
8209 + free(line);
8210 +
8211 + line = pkg_formatted_field(pkg, "Filename");
8212 + strncat(buff ,line, strlen(line));
8213 + free(line);
8214 +
8215 + line = pkg_formatted_field(pkg, "Conffiles");
8216 + strncat(buff ,line, strlen(line));
8217 + free(line);
8218 +
8219 + line = pkg_formatted_field(pkg, "Source");
8220 + strncat(buff ,line, strlen(line));
8221 + free(line);
8222 +
8223 + line = pkg_formatted_field(pkg, "Description");
8224 + strncat(buff ,line, strlen(line));
8225 + free(line);
8226 +
8227 + line = pkg_formatted_field(pkg, "Installed-Time");
8228 + strncat(buff ,line, strlen(line));
8229 + free(line);
8230 +
8231 + return buff;
8232 +}
8233 +
8234 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8235 +{
8236 + static size_t LINE_LEN = 128;
8237 + char * temp = (char *)malloc(1);
8238 + int len = 0;
8239 + int flag_provide_false = 0;
8240 +
8241 +/*
8242 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8243 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8244 +*/
8245 +
8246 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8247 + goto UNKNOWN_FMT_FIELD;
8248 + }
8249 +
8250 + temp[0]='\0';
8251 +
8252 + switch (field[0])
8253 + {
8254 + case 'a':
8255 + case 'A':
8256 + if (strcasecmp(field, "Architecture") == 0) {
8257 + /* Architecture */
8258 + if (pkg->architecture) {
8259 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8260 + if ( temp == NULL ){
8261 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8262 + return NULL;
8263 + }
8264 + temp[0]='\0';
8265 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8266 + }
8267 + } else {
8268 + goto UNKNOWN_FMT_FIELD;
8269 + }
8270 + break;
8271 + case 'c':
8272 + case 'C':
8273 + if (strcasecmp(field, "Conffiles") == 0) {
8274 + /* Conffiles */
8275 + conffile_list_elt_t *iter;
8276 + char confstr[LINE_LEN];
8277 +
8278 + if (pkg->conffiles.head == NULL) {
8279 + return temp;
8280 + }
8281 +
8282 + len = 14 ;
8283 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8284 + if (iter->data->name && iter->data->value) {
8285 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8286 + }
8287 + }
8288 + temp = (char *)realloc(temp,len);
8289 + if ( temp == NULL ){
8290 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8291 + return NULL;
8292 + }
8293 + temp[0]='\0';
8294 + strncpy(temp, "Conffiles:\n", 12);
8295 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8296 + if (iter->data->name && iter->data->value) {
8297 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8298 + strncat(temp, confstr, strlen(confstr));
8299 + }
8300 + }
8301 + } else if (strcasecmp(field, "Conflicts") == 0) {
8302 + int i;
8303 +
8304 + if (pkg->conflicts_count) {
8305 + char conflictstr[LINE_LEN];
8306 + len = 14 ;
8307 + for(i = 0; i < pkg->conflicts_count; i++) {
8308 + len = len + (strlen(pkg->conflicts_str[i])+5);
8309 + }
8310 + temp = (char *)realloc(temp,len);
8311 + if ( temp == NULL ){
8312 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8313 + return NULL;
8314 + }
8315 + temp[0]='\0';
8316 + strncpy(temp, "Conflicts:", 11);
8317 + for(i = 0; i < pkg->conflicts_count; i++) {
8318 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8319 + strncat(temp, conflictstr, strlen(conflictstr));
8320 + }
8321 + strncat(temp, "\n", strlen("\n"));
8322 + }
8323 + } else {
8324 + goto UNKNOWN_FMT_FIELD;
8325 + }
8326 + break;
8327 + case 'd':
8328 + case 'D':
8329 + if (strcasecmp(field, "Depends") == 0) {
8330 + /* Depends */
8331 + int i;
8332 +
8333 + if (pkg->depends_count) {
8334 + char depstr[LINE_LEN];
8335 + len = 14 ;
8336 + for(i = 0; i < pkg->depends_count; i++) {
8337 + len = len + (strlen(pkg->depends_str[i])+4);
8338 + }
8339 + temp = (char *)realloc(temp,len);
8340 + if ( temp == NULL ){
8341 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8342 + return NULL;
8343 + }
8344 + temp[0]='\0';
8345 + strncpy(temp, "Depends:", 10);
8346 + for(i = 0; i < pkg->depends_count; i++) {
8347 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8348 + strncat(temp, depstr, strlen(depstr));
8349 + }
8350 + strncat(temp, "\n", strlen("\n"));
8351 + }
8352 + } else if (strcasecmp(field, "Description") == 0) {
8353 + /* Description */
8354 + if (pkg->description) {
8355 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8356 + if ( temp == NULL ){
8357 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8358 + return NULL;
8359 + }
8360 + temp[0]='\0';
8361 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8362 + }
8363 + } else {
8364 + goto UNKNOWN_FMT_FIELD;
8365 + }
8366 + break;
8367 + case 'e':
8368 + case 'E': {
8369 + /* Essential */
8370 + if (pkg->essential) {
8371 + temp = (char *)realloc(temp,16);
8372 + if ( temp == NULL ){
8373 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8374 + return NULL;
8375 + }
8376 + temp[0]='\0';
8377 + snprintf(temp, (16), "Essential: yes\n");
8378 + }
8379 + }
8380 + break;
8381 + case 'f':
8382 + case 'F': {
8383 + /* Filename */
8384 + if (pkg->filename) {
8385 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8386 + if ( temp == NULL ){
8387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8388 + return NULL;
8389 + }
8390 + temp[0]='\0';
8391 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8392 + }
8393 + }
8394 + break;
8395 + case 'i':
8396 + case 'I': {
8397 + if (strcasecmp(field, "Installed-Size") == 0) {
8398 + /* Installed-Size */
8399 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8400 + if ( temp == NULL ){
8401 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8402 + return NULL;
8403 + }
8404 + temp[0]='\0';
8405 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8406 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8407 + temp = (char *)realloc(temp,29);
8408 + if ( temp == NULL ){
8409 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8410 + return NULL;
8411 + }
8412 + temp[0]='\0';
8413 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8414 + }
8415 + }
8416 + break;
8417 + case 'm':
8418 + case 'M': {
8419 + /* Maintainer | MD5sum */
8420 + if (strcasecmp(field, "Maintainer") == 0) {
8421 + /* Maintainer */
8422 + if (pkg->maintainer) {
8423 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8424 + if ( temp == NULL ){
8425 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8426 + return NULL;
8427 + }
8428 + temp[0]='\0';
8429 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8430 + }
8431 + } else if (strcasecmp(field, "MD5sum") == 0) {
8432 + /* MD5sum */
8433 + if (pkg->md5sum) {
8434 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8435 + if ( temp == NULL ){
8436 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8437 + return NULL;
8438 + }
8439 + temp[0]='\0';
8440 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8441 + }
8442 + } else {
8443 + goto UNKNOWN_FMT_FIELD;
8444 + }
8445 + }
8446 + break;
8447 + case 'p':
8448 + case 'P': {
8449 + if (strcasecmp(field, "Package") == 0) {
8450 + /* Package */
8451 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8452 + if ( temp == NULL ){
8453 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8454 + return NULL;
8455 + }
8456 + temp[0]='\0';
8457 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8458 + } else if (strcasecmp(field, "Priority") == 0) {
8459 + /* Priority */
8460 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8461 + if ( temp == NULL ){
8462 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8463 + return NULL;
8464 + }
8465 + temp[0]='\0';
8466 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8467 + } else if (strcasecmp(field, "Provides") == 0) {
8468 + /* Provides */
8469 + int i;
8470 +
8471 + if (pkg->provides_count) {
8472 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8473 + for ( i=0; i < pkg->provides_count; i++ ){
8474 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8475 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8476 + flag_provide_false = 1;
8477 + }
8478 + }
8479 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8480 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8481 + char provstr[LINE_LEN];
8482 + len = 15;
8483 + for(i = 0; i < pkg->provides_count; i++) {
8484 + len = len + (strlen(pkg->provides_str[i])+5);
8485 + }
8486 + temp = (char *)realloc(temp,len);
8487 + if ( temp == NULL ){
8488 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8489 + return NULL;
8490 + }
8491 + temp[0]='\0';
8492 + strncpy(temp, "Provides:", 12);
8493 + for(i = 0; i < pkg->provides_count; i++) {
8494 + if (strlen(pkg->provides_str[i])>0){;
8495 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8496 + strncat(temp, provstr, strlen(provstr));
8497 + }
8498 + }
8499 + strncat(temp, "\n", strlen("\n"));
8500 + }
8501 + }
8502 + } else {
8503 + goto UNKNOWN_FMT_FIELD;
8504 + }
8505 + }
8506 + break;
8507 + case 'r':
8508 + case 'R': {
8509 + int i;
8510 + /* Replaces | Recommends*/
8511 + if (strcasecmp (field, "Replaces") == 0) {
8512 + if (pkg->replaces_count) {
8513 + char replstr[LINE_LEN];
8514 + len = 14;
8515 + for (i = 0; i < pkg->replaces_count; i++) {
8516 + len = len + (strlen(pkg->replaces_str[i])+5);
8517 + }
8518 + temp = (char *)realloc(temp,len);
8519 + if ( temp == NULL ){
8520 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8521 + return NULL;
8522 + }
8523 + temp[0]='\0';
8524 + strncpy(temp, "Replaces:", 12);
8525 + for (i = 0; i < pkg->replaces_count; i++) {
8526 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8527 + strncat(temp, replstr, strlen(replstr));
8528 + }
8529 + strncat(temp, "\n", strlen("\n"));
8530 + }
8531 + } else if (strcasecmp (field, "Recommends") == 0) {
8532 + if (pkg->recommends_count) {
8533 + char recstr[LINE_LEN];
8534 + len = 15;
8535 + for(i = 0; i < pkg->recommends_count; i++) {
8536 + len = len + (strlen( pkg->recommends_str[i])+5);
8537 + }
8538 + temp = (char *)realloc(temp,len);
8539 + if ( temp == NULL ){
8540 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8541 + return NULL;
8542 + }
8543 + temp[0]='\0';
8544 + strncpy(temp, "Recommends:", 13);
8545 + for(i = 0; i < pkg->recommends_count; i++) {
8546 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8547 + strncat(temp, recstr, strlen(recstr));
8548 + }
8549 + strncat(temp, "\n", strlen("\n"));
8550 + }
8551 + } else {
8552 + goto UNKNOWN_FMT_FIELD;
8553 + }
8554 + }
8555 + break;
8556 + case 's':
8557 + case 'S': {
8558 + /* Section | Size | Source | Status | Suggests */
8559 + if (strcasecmp(field, "Section") == 0) {
8560 + /* Section */
8561 + if (pkg->section) {
8562 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8563 + if ( temp == NULL ){
8564 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8565 + return NULL;
8566 + }
8567 + temp[0]='\0';
8568 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8569 + }
8570 + } else if (strcasecmp(field, "Size") == 0) {
8571 + /* Size */
8572 + if (pkg->size) {
8573 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8574 + if ( temp == NULL ){
8575 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8576 + return NULL;
8577 + }
8578 + temp[0]='\0';
8579 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8580 + }
8581 + } else if (strcasecmp(field, "Source") == 0) {
8582 + /* Source */
8583 + if (pkg->source) {
8584 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8585 + if ( temp == NULL ){
8586 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8587 + return NULL;
8588 + }
8589 + temp[0]='\0';
8590 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8591 + }
8592 + } else if (strcasecmp(field, "Status") == 0) {
8593 + /* Status */
8594 + /* Benjamin Pineau note: we should avoid direct usage of
8595 + * strlen(arg) without keeping "arg" for later free()
8596 + */
8597 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8598 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8599 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8600 +
8601 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8602 + temp = (char *)realloc(temp,sum_of_sizes);
8603 + if ( temp == NULL ){
8604 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8605 + return NULL;
8606 + }
8607 + temp[0]='\0';
8608 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8609 + free(pflag);
8610 + free(pwant);
8611 + if(pstat) /* pfstat can be NULL if ENOMEM */
8612 + free(pstat);
8613 + } else if (strcasecmp(field, "Suggests") == 0) {
8614 + if (pkg->suggests_count) {
8615 + int i;
8616 + char sugstr[LINE_LEN];
8617 + len = 13;
8618 + for(i = 0; i < pkg->suggests_count; i++) {
8619 + len = len + (strlen(pkg->suggests_str[i])+5);
8620 + }
8621 + temp = (char *)realloc(temp,len);
8622 + if ( temp == NULL ){
8623 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8624 + return NULL;
8625 + }
8626 + temp[0]='\0';
8627 + strncpy(temp, "Suggests:", 10);
8628 + for(i = 0; i < pkg->suggests_count; i++) {
8629 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8630 + strncat(temp, sugstr, strlen(sugstr));
8631 + }
8632 + strncat(temp, "\n", strlen("\n"));
8633 + }
8634 + } else {
8635 + goto UNKNOWN_FMT_FIELD;
8636 + }
8637 + }
8638 + break;
8639 + case 'v':
8640 + case 'V': {
8641 + /* Version */
8642 + char *version = pkg_version_str_alloc(pkg);
8643 + temp = (char *)realloc(temp,strlen(version)+14);
8644 + if ( temp == NULL ){
8645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8646 + return NULL;
8647 + }
8648 + temp[0]='\0';
8649 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8650 + free(version);
8651 + }
8652 + break;
8653 + default:
8654 + goto UNKNOWN_FMT_FIELD;
8655 + }
8656 +
8657 + if ( strlen(temp)<2 ) {
8658 + temp[0]='\0';
8659 + }
8660 + return temp;
8661 +
8662 + UNKNOWN_FMT_FIELD:
8663 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8664 + if ( strlen(temp)<2 ) {
8665 + temp[0]='\0';
8666 + }
8667 +
8668 + return temp;
8669 +}
8670 +
8671 +void pkg_print_info(pkg_t *pkg, FILE *file)
8672 +{
8673 + char * buff;
8674 + if (pkg == NULL) {
8675 + return;
8676 + }
8677 +
8678 + buff = pkg_formatted_info(pkg);
8679 + if ( buff == NULL )
8680 + return;
8681 + if (strlen(buff)>2){
8682 + fwrite(buff, 1, strlen(buff), file);
8683 + }
8684 + free(buff);
8685 +}
8686 +
8687 +void pkg_print_status(pkg_t * pkg, FILE * file)
8688 +{
8689 + if (pkg == NULL) {
8690 + return;
8691 + }
8692 +
8693 + /* XXX: QUESTION: Do we actually want more fields here? The
8694 + original idea was to save space by installing only what was
8695 + needed for actual computation, (package, version, status,
8696 + essential, conffiles). The assumption is that all other fields
8697 + can be found in th available file.
8698 +
8699 + But, someone proposed the idea to make it possible to
8700 + reconstruct a .ipk from an installed package, (ie. for beaming
8701 + from one handheld to another). So, maybe we actually want a few
8702 + more fields here, (depends, suggests, etc.), so that that would
8703 + be guaranteed to work even in the absence of more information
8704 + from the available file.
8705 +
8706 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8707 + the essential info needs to be here for all installed packages
8708 + because they may not appear in the Packages files on various
8709 + feeds. Furthermore, one should be able to install from URL or
8710 + local storage without requiring a Packages file from any feed.
8711 + -Jamey
8712 + */
8713 + pkg_print_field(pkg, file, "Package");
8714 + pkg_print_field(pkg, file, "Version");
8715 + pkg_print_field(pkg, file, "Depends");
8716 + pkg_print_field(pkg, file, "Recommends");
8717 + pkg_print_field(pkg, file, "Suggests");
8718 + pkg_print_field(pkg, file, "Provides");
8719 + pkg_print_field(pkg, file, "Replaces");
8720 + pkg_print_field(pkg, file, "Conflicts");
8721 + pkg_print_field(pkg, file, "Status");
8722 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8723 + pkg_print_field(pkg, file, "Architecture");
8724 + pkg_print_field(pkg, file, "Conffiles");
8725 + pkg_print_field(pkg, file, "Installed-Time");
8726 + fputs("\n", file);
8727 +}
8728 +
8729 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8730 +{
8731 + char *buff;
8732 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8733 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8734 + __FUNCTION__, field);
8735 + }
8736 + buff = pkg_formatted_field(pkg, field);
8737 + if (strlen(buff)>2) {
8738 + fprintf(file, "%s", buff);
8739 + fflush(file);
8740 + }
8741 + free(buff);
8742 + return;
8743 +}
8744 +
8745 +/*
8746 + * libdpkg - Debian packaging suite library routines
8747 + * vercmp.c - comparison of version numbers
8748 + *
8749 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8750 + */
8751 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8752 +{
8753 + int r;
8754 +
8755 + if (pkg->epoch > ref_pkg->epoch) {
8756 + return 1;
8757 + }
8758 +
8759 + if (pkg->epoch < ref_pkg->epoch) {
8760 + return -1;
8761 + }
8762 +
8763 + r = verrevcmp(pkg->version, ref_pkg->version);
8764 + if (r) {
8765 + return r;
8766 + }
8767 +
8768 +#ifdef USE_DEBVERSION
8769 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8770 + if (r) {
8771 + return r;
8772 + }
8773 +
8774 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8775 +#endif
8776 +
8777 + return r;
8778 +}
8779 +
8780 +int verrevcmp(const char *val, const char *ref)
8781 +{
8782 + int vc, rc;
8783 + long vl, rl;
8784 + const char *vp, *rp;
8785 + const char *vsep, *rsep;
8786 +
8787 + if (!val) val= "";
8788 + if (!ref) ref= "";
8789 + for (;;) {
8790 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8791 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8792 + for (;;) {
8793 + vc= (val == vp) ? 0 : *val++;
8794 + rc= (ref == rp) ? 0 : *ref++;
8795 + if (!rc && !vc) break;
8796 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8797 + if (rc && !isalpha(rc)) rc += 256;
8798 + if (vc != rc) return vc - rc;
8799 + }
8800 + val= vp;
8801 + ref= rp;
8802 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8803 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8804 + if (vl != rl) return vl - rl;
8805 +
8806 + vc = *val;
8807 + rc = *ref;
8808 + vsep = strchr(".-", vc);
8809 + rsep = strchr(".-", rc);
8810 + if (vsep && !rsep) return -1;
8811 + if (!vsep && rsep) return +1;
8812 +
8813 + if (!*val && !*ref) return 0;
8814 + if (!*val) return -1;
8815 + if (!*ref) return +1;
8816 + }
8817 +}
8818 +
8819 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8820 +{
8821 + int r;
8822 +
8823 + r = pkg_compare_versions(it, ref);
8824 +
8825 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8826 + return r <= 0;
8827 + }
8828 +
8829 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8830 + return r >= 0;
8831 + }
8832 +
8833 + if (strcmp(op, "<<") == 0) {
8834 + return r < 0;
8835 + }
8836 +
8837 + if (strcmp(op, ">>") == 0) {
8838 + return r > 0;
8839 + }
8840 +
8841 + if (strcmp(op, "=") == 0) {
8842 + return r == 0;
8843 + }
8844 +
8845 + fprintf(stderr, "unknown operator: %s", op);
8846 + return 0;
8847 +}
8848 +
8849 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8850 +{
8851 + const pkg_t *a = *(const pkg_t **)p1;
8852 + const pkg_t *b = *(const pkg_t **)p2;
8853 + int namecmp;
8854 + int vercmp;
8855 + if (!a->name || !b->name) {
8856 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8857 + a, a->name, b, b->name);
8858 + return 0;
8859 + }
8860 +
8861 + namecmp = strcmp(a->name, b->name);
8862 + if (namecmp)
8863 + return namecmp;
8864 + vercmp = pkg_compare_versions(a, b);
8865 + if (vercmp)
8866 + return vercmp;
8867 + if (!a->arch_priority || !b->arch_priority) {
8868 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8869 + a, a->arch_priority, b, b->arch_priority);
8870 + return 0;
8871 + }
8872 + if (a->arch_priority > b->arch_priority)
8873 + return 1;
8874 + if (a->arch_priority < b->arch_priority)
8875 + return -1;
8876 + return 0;
8877 +}
8878 +
8879 +int abstract_pkg_name_compare(void *p1, void *p2)
8880 +{
8881 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8882 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8883 + if (!a->name || !b->name) {
8884 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8885 + a, a->name, b, b->name);
8886 + return 0;
8887 + }
8888 + return strcmp(a->name, b->name);
8889 +}
8890 +
8891 +
8892 +char *pkg_version_str_alloc(pkg_t *pkg)
8893 +{
8894 + char *complete_version;
8895 + char *epoch_str;
8896 +#ifdef USE_DEBVERSION
8897 + char *revision_str;
8898 + char *familiar_revision_str;
8899 +#endif
8900 +
8901 + if (pkg->epoch) {
8902 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8903 + } else {
8904 + epoch_str = strdup("");
8905 + }
8906 +
8907 +#ifdef USE_DEBVERSION
8908 + if (pkg->revision && strlen(pkg->revision)) {
8909 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8910 + } else {
8911 + revision_str = strdup("");
8912 + }
8913 +
8914 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8915 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8916 + } else {
8917 + familiar_revision_str = strdup("");
8918 + }
8919 +#endif
8920 +
8921 +#ifdef USE_DEBVERSION
8922 + sprintf_alloc(&complete_version, "%s%s%s%s",
8923 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8924 +#else
8925 + sprintf_alloc(&complete_version, "%s%s",
8926 + epoch_str, pkg->version);
8927 +#endif
8928 +
8929 + free(epoch_str);
8930 +#ifdef USE_DEBVERSION
8931 + free(revision_str);
8932 + free(familiar_revision_str);
8933 +#endif
8934 +
8935 + return complete_version;
8936 +}
8937 +
8938 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8939 +{
8940 + int err;
8941 + char *list_file_name = NULL;
8942 + FILE *list_file = NULL;
8943 + char *line;
8944 + char *installed_file_name;
8945 + int rootdirlen;
8946 +
8947 + pkg->installed_files_ref_cnt++;
8948 +
8949 + if (pkg->installed_files) {
8950 + return pkg->installed_files;
8951 + }
8952 +
8953 + pkg->installed_files = str_list_alloc();
8954 + if (pkg->installed_files == NULL) {
8955 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8956 + return NULL;
8957 + }
8958 +
8959 + /* For uninstalled packages, get the file list firectly from the package.
8960 + For installed packages, look at the package.list file in the database.
8961 + */
8962 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8963 + if (pkg->local_filename == NULL) {
8964 + return pkg->installed_files;
8965 + }
8966 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8967 + file. In other words, change deb_extract so that it can
8968 + simply return the file list as a char *[] rather than
8969 + insisting on writing in to a FILE * as it does now. */
8970 + list_file = tmpfile();
8971 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8972 + if (err) {
8973 + fclose(list_file);
8974 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8975 + __FUNCTION__, pkg->local_filename, strerror(err));
8976 + return pkg->installed_files;
8977 + }
8978 + rewind(list_file);
8979 + } else {
8980 + sprintf_alloc(&list_file_name, "%s/%s.list",
8981 + pkg->dest->info_dir, pkg->name);
8982 + if (! file_exists(list_file_name)) {
8983 + free(list_file_name);
8984 + return pkg->installed_files;
8985 + }
8986 +
8987 + list_file = fopen(list_file_name, "r");
8988 + if (list_file == NULL) {
8989 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8990 + list_file_name, strerror(errno));
8991 + free(list_file_name);
8992 + return pkg->installed_files;
8993 + }
8994 + free(list_file_name);
8995 + }
8996 +
8997 + rootdirlen = strlen( pkg->dest->root_dir );
8998 + while (1) {
8999 + char *file_name;
9000 +
9001 + line = file_read_line_alloc(list_file);
9002 + if (line == NULL) {
9003 + break;
9004 + }
9005 + str_chomp(line);
9006 + file_name = line;
9007 +
9008 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9009 + if( strncmp( pkg->dest->root_dir,
9010 + file_name,
9011 + rootdirlen ) ) {
9012 + if (*file_name == '.') {
9013 + file_name++;
9014 + }
9015 + if (*file_name == '/') {
9016 + file_name++;
9017 + }
9018 +
9019 + /* Freed in pkg_free_installed_files */
9020 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9021 + } else {
9022 + // already contains root_dir as header -> ABSOLUTE
9023 + sprintf_alloc(&installed_file_name, "%s", file_name);
9024 + }
9025 + str_list_append(pkg->installed_files, installed_file_name);
9026 + free(line);
9027 + }
9028 +
9029 + fclose(list_file);
9030 +
9031 + return pkg->installed_files;
9032 +}
9033 +
9034 +/* XXX: CLEANUP: This function and it's counterpart,
9035 + (pkg_get_installed_files), do not match our init/deinit naming
9036 + convention. Nor the alloc/free convention. But, then again, neither
9037 + of these conventions currrently fit the way these two functions
9038 + work. */
9039 +int pkg_free_installed_files(pkg_t *pkg)
9040 +{
9041 + str_list_elt_t *iter;
9042 +
9043 + pkg->installed_files_ref_cnt--;
9044 + if (pkg->installed_files_ref_cnt > 0) {
9045 + return 0;
9046 + }
9047 +
9048 + if (pkg->installed_files) {
9049 +
9050 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9051 + /* malloced in pkg_get_installed_files */
9052 + free (iter->data);
9053 + iter->data = NULL;
9054 + }
9055 +
9056 + str_list_deinit(pkg->installed_files);
9057 + }
9058 +
9059 + pkg->installed_files = NULL;
9060 +
9061 + return 0;
9062 +}
9063 +
9064 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9065 +{
9066 + int err;
9067 + char *list_file_name;
9068 +
9069 + //I don't think pkg_free_installed_files should be called here. Jamey
9070 + //pkg_free_installed_files(pkg);
9071 +
9072 + sprintf_alloc(&list_file_name, "%s/%s.list",
9073 + pkg->dest->info_dir, pkg->name);
9074 + if (!conf->noaction) {
9075 + err = unlink(list_file_name);
9076 + free(list_file_name);
9077 +
9078 + if (err) {
9079 + return errno;
9080 + }
9081 + }
9082 + return 0;
9083 +}
9084 +
9085 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9086 +{
9087 + conffile_list_elt_t *iter;
9088 + conffile_t *conffile;
9089 +
9090 + if (pkg == NULL) {
9091 + return NULL;
9092 + }
9093 +
9094 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9095 + conffile = iter->data;
9096 +
9097 + if (strcmp(conffile->name, file_name) == 0) {
9098 + return conffile;
9099 + }
9100 + }
9101 +
9102 + return NULL;
9103 +}
9104 +
9105 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9106 + const char *script, const char *args)
9107 +{
9108 + int err;
9109 + char *path;
9110 + char *cmd;
9111 +
9112 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9113 + maintainer script within a chroot environment. */
9114 +
9115 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9116 + have scripts in pkg->tmp_unpack_dir. */
9117 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9118 + if (pkg->dest == NULL) {
9119 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9120 + __FUNCTION__, pkg->name);
9121 + return EINVAL;
9122 + }
9123 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9124 + } else {
9125 + if (pkg->tmp_unpack_dir == NULL) {
9126 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9127 + __FUNCTION__, pkg->name);
9128 + return EINVAL;
9129 + }
9130 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9131 + }
9132 +
9133 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9134 + if (conf->noaction) return 0;
9135 +
9136 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9137 + scripts when running with offline_root mode and/or a dest other
9138 + than '/'. I've been playing around with some clever chroot
9139 + tricks and I might come up with something workable. */
9140 + if (conf->offline_root) {
9141 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9142 + }
9143 +
9144 + setenv("PKG_ROOT",
9145 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9146 +
9147 + if (! file_exists(path)) {
9148 + free(path);
9149 + return 0;
9150 + }
9151 +
9152 + if (conf->offline_root) {
9153 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9154 + free(path);
9155 + return 0;
9156 + }
9157 +
9158 + sprintf_alloc(&cmd, "%s %s", path, args);
9159 + free(path);
9160 +
9161 + err = xsystem(cmd);
9162 + free(cmd);
9163 +
9164 + if (err) {
9165 + fprintf(stderr, "%s script returned status %d\n", script, err);
9166 + return err;
9167 + }
9168 +
9169 + return 0;
9170 +}
9171 +
9172 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9173 +{
9174 + int i;
9175 +
9176 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9177 + if (pkg_state_want_map[i].value == sw) {
9178 + return strdup(pkg_state_want_map[i].str);
9179 + }
9180 + }
9181 +
9182 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9183 + __FUNCTION__, sw);
9184 + return strdup("<STATE_WANT_UNKNOWN>");
9185 +}
9186 +
9187 +pkg_state_want_t pkg_state_want_from_str(char *str)
9188 +{
9189 + int i;
9190 +
9191 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9192 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9193 + return pkg_state_want_map[i].value;
9194 + }
9195 + }
9196 +
9197 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9198 + __FUNCTION__, str);
9199 + return SW_UNKNOWN;
9200 +}
9201 +
9202 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9203 +{
9204 + int i;
9205 + int len = 3; /* ok\000 is minimum */
9206 + char *str = NULL;
9207 +
9208 + /* clear the temporary flags before converting to string */
9209 + sf &= SF_NONVOLATILE_FLAGS;
9210 +
9211 + if (sf == 0) {
9212 + return strdup("ok");
9213 + } else {
9214 +
9215 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9216 + if (sf & pkg_state_flag_map[i].value) {
9217 + len += strlen(pkg_state_flag_map[i].str) + 1;
9218 + }
9219 + }
9220 + str = malloc(len);
9221 + if ( str == NULL ) {
9222 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9223 + return NULL;
9224 + }
9225 + str[0] = 0;
9226 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9227 + if (sf & pkg_state_flag_map[i].value) {
9228 + strcat(str, pkg_state_flag_map[i].str);
9229 + strcat(str, ",");
9230 + }
9231 + }
9232 + len = strlen(str);
9233 + str[len-1] = 0; /* squash last comma */
9234 + return str;
9235 + }
9236 +}
9237 +
9238 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9239 +{
9240 + int i;
9241 + int sf = SF_OK;
9242 +
9243 + if (strcmp(str, "ok") == 0) {
9244 + return SF_OK;
9245 + }
9246 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9247 + const char *sfname = pkg_state_flag_map[i].str;
9248 + int sfname_len = strlen(sfname);
9249 + if (strncmp(str, sfname, sfname_len) == 0) {
9250 + sf |= pkg_state_flag_map[i].value;
9251 + str += sfname_len;
9252 + if (str[0] == ',') {
9253 + str++;
9254 + } else {
9255 + break;
9256 + }
9257 + }
9258 + }
9259 +
9260 + return sf;
9261 +}
9262 +
9263 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9264 +{
9265 + int i;
9266 +
9267 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9268 + if (pkg_state_status_map[i].value == ss) {
9269 + return strdup(pkg_state_status_map[i].str);
9270 + }
9271 + }
9272 +
9273 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9274 + __FUNCTION__, ss);
9275 + return strdup("<STATE_STATUS_UNKNOWN>");
9276 +}
9277 +
9278 +pkg_state_status_t pkg_state_status_from_str(char *str)
9279 +{
9280 + int i;
9281 +
9282 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9283 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9284 + return pkg_state_status_map[i].value;
9285 + }
9286 + }
9287 +
9288 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9289 + __FUNCTION__, str);
9290 + return SS_NOT_INSTALLED;
9291 +}
9292 +
9293 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9294 +{
9295 + nv_pair_list_elt_t *l;
9296 +
9297 + if (!pkg->architecture)
9298 + return 1;
9299 +
9300 + l = conf->arch_list.head;
9301 +
9302 + while (l) {
9303 + nv_pair_t *nv = l->data;
9304 + if (strcmp(nv->name, pkg->architecture) == 0) {
9305 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9306 + return 1;
9307 + }
9308 + l = l->next;
9309 + }
9310 +
9311 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9312 + return 0;
9313 +}
9314 +
9315 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9316 +{
9317 + nv_pair_list_elt_t *l;
9318 +
9319 + l = conf->arch_list.head;
9320 +
9321 + while (l) {
9322 + nv_pair_t *nv = l->data;
9323 + if (strcmp(nv->name, archname) == 0) {
9324 + int priority = strtol(nv->value, NULL, 0);
9325 + return priority;
9326 + }
9327 + l = l->next;
9328 + }
9329 + return 0;
9330 +}
9331 +
9332 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9333 +{
9334 + int i;
9335 + hash_table_t *pkg_hash = &conf->pkg_hash;
9336 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9337 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9338 +
9339 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9340 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9341 + /* update arch_priority for each package */
9342 + for (i = 0; i < available_pkgs->len; i++) {
9343 + pkg_t *pkg = available_pkgs->pkgs[i];
9344 + int arch_priority = 1;
9345 + if (!pkg)
9346 + continue;
9347 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9348 + if (pkg->architecture)
9349 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9350 + else
9351 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9352 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9353 + pkg->arch_priority = arch_priority;
9354 + }
9355 +
9356 + for (i = 0; i < available_pkgs->len; i++) {
9357 + pkg_t *pkg = available_pkgs->pkgs[i];
9358 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9359 + /* clear flags and want for any uninstallable package */
9360 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9361 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9362 + pkg->state_want = SW_UNKNOWN;
9363 + pkg->state_flag = 0;
9364 + }
9365 + }
9366 + pkg_vec_free(available_pkgs);
9367 +
9368 + /* update the file owner data structure */
9369 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9370 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9371 + for (i = 0; i < installed_pkgs->len; i++) {
9372 + pkg_t *pkg = installed_pkgs->pkgs[i];
9373 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9374 + str_list_elt_t *iter;
9375 + if (installed_files == NULL) {
9376 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9377 + break;
9378 + }
9379 + for (iter = installed_files->head; iter; iter = iter->next) {
9380 + char *installed_file = iter->data;
9381 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9382 + file_hash_set_file_owner(conf, installed_file, pkg);
9383 + }
9384 + }
9385 + pkg_vec_free(installed_pkgs);
9386 +
9387 + return 0;
9388 +}
9389 +
9390 +struct pkg_write_filelist_data {
9391 + ipkg_conf_t *conf;
9392 + pkg_t *pkg;
9393 + FILE *stream;
9394 +};
9395 +
9396 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9397 +{
9398 + struct pkg_write_filelist_data *data = data_;
9399 + pkg_t *entry = entry_;
9400 + if (entry == data->pkg) {
9401 + fprintf(data->stream, "%s\n", key);
9402 + }
9403 +}
9404 +
9405 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9406 +{
9407 + struct pkg_write_filelist_data data;
9408 + char *list_file_name = NULL;
9409 + int err = 0;
9410 +
9411 + if (!pkg) {
9412 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9413 + return -EINVAL;
9414 + }
9415 + ipkg_message(conf, IPKG_INFO,
9416 + " creating %s.list file\n", pkg->name);
9417 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9418 + if (!list_file_name) {
9419 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9420 + return -ENOMEM;
9421 + }
9422 + ipkg_message(conf, IPKG_INFO,
9423 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9424 + data.stream = fopen(list_file_name, "w");
9425 + if (!data.stream) {
9426 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9427 + list_file_name, strerror(errno));
9428 + return errno;
9429 + }
9430 + data.pkg = pkg;
9431 + data.conf = conf;
9432 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9433 + fclose(data.stream);
9434 + free(list_file_name);
9435 +
9436 + return err;
9437 +}
9438 +
9439 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9440 +{
9441 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9442 + hash_table_t *pkg_hash = &conf->pkg_hash;
9443 + int i;
9444 + int err;
9445 + if (conf->noaction)
9446 + return 0;
9447 +
9448 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9449 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9450 + for (i = 0; i < installed_pkgs->len; i++) {
9451 + pkg_t *pkg = installed_pkgs->pkgs[i];
9452 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9453 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9454 + err = pkg_write_filelist(conf, pkg);
9455 + if (err)
9456 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9457 + }
9458 + }
9459 + return 0;
9460 +}
9461 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_depends.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c
9462 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9463 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-07-22 16:31:25.000000000 +0200
9464 @@ -0,0 +1,1033 @@
9465 +/* pkg_depends.c - the itsy package management system
9466 +
9467 + Steven M. Ayer
9468 +
9469 + Copyright (C) 2002 Compaq Computer Corporation
9470 +
9471 + This program is free software; you can redistribute it and/or
9472 + modify it under the terms of the GNU General Public License as
9473 + published by the Free Software Foundation; either version 2, or (at
9474 + your option) any later version.
9475 +
9476 + This program is distributed in the hope that it will be useful, but
9477 + WITHOUT ANY WARRANTY; without even the implied warranty of
9478 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9479 + General Public License for more details.
9480 +*/
9481 +
9482 +#include "ipkg.h"
9483 +#include <errno.h>
9484 +#include <ctype.h>
9485 +
9486 +#include "pkg.h"
9487 +#include "ipkg_utils.h"
9488 +#include "pkg_hash.h"
9489 +#include "ipkg_message.h"
9490 +#include "pkg_parse.h"
9491 +#include "hash_table.h"
9492 +
9493 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9494 +static depend_t * depend_init(void);
9495 +static void depend_deinit(depend_t *d);
9496 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9497 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9498 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9499 +
9500 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9501 +{
9502 + depend_t *depend = (depend_t *)cdata;
9503 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9504 + return 1;
9505 + else
9506 + return 0;
9507 +}
9508 +
9509 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9510 +{
9511 + depend_t *depend = (depend_t *)cdata;
9512 +#if 0
9513 + pkg_t * temp = pkg_new();
9514 + int comparison;
9515 + parseVersion(temp, depend->version);
9516 + comparison = pkg_compare_versions(pkg, temp);
9517 + free(temp);
9518 +
9519 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9520 + __FUNCTION__, pkg->name, pkg->version,
9521 + depend, depend->constraint, depend->version,
9522 + comparison, version_constraints_satisfied(depend, pkg));
9523 +#endif
9524 + if (version_constraints_satisfied(depend, pkg))
9525 + return 1;
9526 + else
9527 + return 0;
9528 +}
9529 +
9530 +/* returns ndependences or negative error value */
9531 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9532 + pkg_vec_t *unsatisfied, char *** unresolved)
9533 +{
9534 + pkg_t * satisfier_entry_pkg;
9535 + register int i, j, k;
9536 + int count, found;
9537 + char ** the_lost;
9538 + abstract_pkg_t * ab_pkg;
9539 +
9540 + /*
9541 + * this is a setup to check for redundant/cyclic dependency checks,
9542 + * which are marked at the abstract_pkg level
9543 + */
9544 + if (!(ab_pkg = pkg->parent)) {
9545 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9546 + *unresolved = NULL;
9547 + return 0;
9548 + }
9549 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9550 + *unresolved = NULL;
9551 + return 0;
9552 + } else {
9553 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9554 + }
9555 + /**/
9556 +
9557 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9558 + if (!count){
9559 + *unresolved = NULL;
9560 + return 0;
9561 + }
9562 +
9563 + the_lost = NULL;
9564 +
9565 + /* foreach dependency */
9566 + for (i = 0; i < count; i++) {
9567 + compound_depend_t * compound_depend = &pkg->depends[i];
9568 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9569 + found = 0;
9570 + satisfier_entry_pkg = NULL;
9571 +
9572 + if (compound_depend->type == GREEDY_DEPEND) {
9573 + /* foreach possible satisfier */
9574 + for (j = 0; j < compound_depend->possibility_count; j++) {
9575 + /* foreach provided_by, which includes the abstract_pkg itself */
9576 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9577 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9578 + int nposs = ab_provider_vec->len;
9579 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9580 + int l;
9581 + for (l = 0; l < nposs; l++) {
9582 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9583 + /* if no depends on this one, try the first package that Provides this one */
9584 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9585 + continue;
9586 + }
9587 +
9588 + /* cruise this possiblity's pkg_vec looking for an installed version */
9589 + for (k = 0; k < test_vec->len; k++) {
9590 + pkg_t *pkg_scout = test_vec->pkgs[k];
9591 + /* not installed, and not already known about? */
9592 + if ((pkg_scout->state_want != SW_INSTALL)
9593 + && !pkg_scout->parent->dependencies_checked
9594 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9595 + char ** newstuff = NULL;
9596 + int rc;
9597 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9598 + /* check for not-already-installed dependencies */
9599 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9600 + pkg_scout,
9601 + tmp_vec,
9602 + &newstuff);
9603 + if (newstuff == NULL) {
9604 + int i;
9605 + int ok = 1;
9606 + for (i = 0; i < rc; i++) {
9607 + pkg_t *p = tmp_vec->pkgs[i];
9608 + if (p->state_want == SW_INSTALL)
9609 + continue;
9610 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9611 + ok = 0;
9612 + break;
9613 + }
9614 + pkg_vec_free (tmp_vec);
9615 + if (ok) {
9616 + /* mark this one for installation */
9617 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9618 + pkg_vec_insert(unsatisfied, pkg_scout);
9619 + }
9620 + } else {
9621 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9622 + free (newstuff);
9623 + }
9624 + }
9625 + }
9626 + }
9627 + }
9628 +
9629 + continue;
9630 + }
9631 +
9632 + /* foreach possible satisfier, look for installed package */
9633 + for (j = 0; j < compound_depend->possibility_count; j++) {
9634 + /* foreach provided_by, which includes the abstract_pkg itself */
9635 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9636 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9637 + pkg_t *satisfying_pkg =
9638 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9639 + pkg_installed_and_constraint_satisfied,
9640 + dependence_to_satisfy, 1);
9641 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9642 + if (satisfying_pkg != NULL) {
9643 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9644 + satisfying_pkg = NULL;
9645 + }
9646 + }
9647 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9648 + if (satisfying_pkg != NULL) {
9649 + found = 1;
9650 + break;
9651 + }
9652 +
9653 + }
9654 + /* if nothing installed matches, then look for uninstalled satisfier */
9655 + if (!found) {
9656 + /* foreach possible satisfier, look for installed package */
9657 + for (j = 0; j < compound_depend->possibility_count; j++) {
9658 + /* foreach provided_by, which includes the abstract_pkg itself */
9659 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9660 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9661 + pkg_t *satisfying_pkg =
9662 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9663 + pkg_constraint_satisfied,
9664 + dependence_to_satisfy, 1);
9665 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9666 + if (satisfying_pkg != NULL) {
9667 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9668 + satisfying_pkg = NULL;
9669 + }
9670 + }
9671 +
9672 + /* user request overrides package recommendation */
9673 + if (satisfying_pkg != NULL
9674 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9675 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9676 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9677 + pkg->name, satisfying_pkg->name);
9678 + continue;
9679 + }
9680 +
9681 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9682 + if (satisfying_pkg != NULL) {
9683 + satisfier_entry_pkg = satisfying_pkg;
9684 + break;
9685 + }
9686 + }
9687 + }
9688 +
9689 + /* we didn't find one, add something to the unsatisfied vector */
9690 + if (!found) {
9691 + if (!satisfier_entry_pkg) {
9692 + /* failure to meet recommendations is not an error */
9693 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9694 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9695 + else
9696 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9697 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9698 + }
9699 + else {
9700 + if (compound_depend->type == SUGGEST) {
9701 + /* just mention it politely */
9702 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9703 + pkg->name, satisfier_entry_pkg->name);
9704 + } else {
9705 + char ** newstuff = NULL;
9706 +
9707 + if (satisfier_entry_pkg != pkg &&
9708 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9709 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9710 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9711 + satisfier_entry_pkg,
9712 + unsatisfied,
9713 + &newstuff);
9714 + the_lost = merge_unresolved(the_lost, newstuff);
9715 + }
9716 + }
9717 + }
9718 + }
9719 + }
9720 + *unresolved = the_lost;
9721 +
9722 + return unsatisfied->len;
9723 +}
9724 +
9725 +/*checking for conflicts !in replaces
9726 + If a packages conflicts with another but is also replacing it, I should not consider it a
9727 + really conflicts
9728 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9729 +*/
9730 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9731 +{
9732 + int i ;
9733 + int replaces_count = pkg->replaces_count;
9734 + abstract_pkg_t **replaces;
9735 +
9736 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9737 + return 0;
9738 +
9739 + replaces = pkg->replaces;
9740 +
9741 + for (i = 0; i < replaces_count; i++) {
9742 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9743 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9744 + return 1;
9745 + }
9746 + }
9747 + return 0;
9748 +
9749 +}
9750 +
9751 +
9752 +/* Abhaya: added support for conflicts */
9753 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9754 +{
9755 + pkg_vec_t * installed_conflicts, * test_vec;
9756 + compound_depend_t * conflicts;
9757 + depend_t ** possible_satisfiers;
9758 + depend_t * possible_satisfier;
9759 + register int i, j, k;
9760 + int count;
9761 + abstract_pkg_t * ab_pkg;
9762 + pkg_t **pkg_scouts;
9763 + pkg_t *pkg_scout;
9764 +
9765 + /*
9766 + * this is a setup to check for redundant/cyclic dependency checks,
9767 + * which are marked at the abstract_pkg level
9768 + */
9769 + if(!(ab_pkg = pkg->parent)){
9770 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9771 + return (pkg_vec_t *)NULL;
9772 + }
9773 +
9774 + conflicts = pkg->conflicts;
9775 + if(!conflicts){
9776 + return (pkg_vec_t *)NULL;
9777 + }
9778 + installed_conflicts = pkg_vec_alloc();
9779 +
9780 + count = pkg->conflicts_count;
9781 +
9782 +
9783 +
9784 + /* foreach conflict */
9785 + for(i = 0; i < pkg->conflicts_count; i++){
9786 +
9787 + possible_satisfiers = conflicts->possibilities;
9788 +
9789 + /* foreach possible satisfier */
9790 + for(j = 0; j < conflicts->possibility_count; j++){
9791 + possible_satisfier = possible_satisfiers[j];
9792 + if (!possible_satisfier)
9793 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9794 + if (!possible_satisfier->pkg)
9795 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9796 + test_vec = possible_satisfier->pkg->pkgs;
9797 + if (test_vec) {
9798 + /* pkg_vec found, it is an actual package conflict
9799 + * cruise this possiblity's pkg_vec looking for an installed version */
9800 + pkg_scouts = test_vec->pkgs;
9801 + for(k = 0; k < test_vec->len; k++){
9802 + pkg_scout = pkg_scouts[k];
9803 + if (!pkg_scout) {
9804 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9805 + continue;
9806 + }
9807 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9808 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9809 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9810 + pkg_vec_insert(installed_conflicts, pkg_scout);
9811 + }
9812 + }
9813 + }
9814 + }
9815 + }
9816 + conflicts++;
9817 + }
9818 +
9819 + if (installed_conflicts->len)
9820 + return installed_conflicts;
9821 + pkg_vec_free(installed_conflicts);
9822 + return (pkg_vec_t *)NULL;
9823 +}
9824 +
9825 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9826 +{
9827 + pkg_t * temp;
9828 + int comparison;
9829 +
9830 + if(depends->constraint == NONE)
9831 + return 1;
9832 +
9833 + temp = pkg_new();
9834 +
9835 + parseVersion(temp, depends->version);
9836 +
9837 + comparison = pkg_compare_versions(pkg, temp);
9838 +
9839 + free(temp);
9840 +
9841 + if((depends->constraint == EARLIER) &&
9842 + (comparison < 0))
9843 + return 1;
9844 + else if((depends->constraint == LATER) &&
9845 + (comparison > 0))
9846 + return 1;
9847 + else if(comparison == 0)
9848 + return 1;
9849 + else if((depends->constraint == LATER_EQUAL) &&
9850 + (comparison >= 0))
9851 + return 1;
9852 + else if((depends->constraint == EARLIER_EQUAL) &&
9853 + (comparison <= 0))
9854 + return 1;
9855 +
9856 + return 0;
9857 +}
9858 +
9859 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9860 +{
9861 + abstract_pkg_t *apkg = depend->pkg;
9862 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9863 + int n_providers = provider_apkgs->len;
9864 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9865 + pkg_vec_t *pkg_vec;
9866 + int n_pkgs ;
9867 + int i;
9868 + int j;
9869 +
9870 + for (i = 0; i < n_providers; i++) {
9871 + abstract_pkg_t *papkg = apkgs[i];
9872 + pkg_vec = papkg->pkgs;
9873 + if (pkg_vec) {
9874 + n_pkgs = pkg_vec->len;
9875 + for (j = 0; j < n_pkgs; j++) {
9876 + pkg_t *pkg = pkg_vec->pkgs[j];
9877 + if (version_constraints_satisfied(depend, pkg)) {
9878 + return 1;
9879 + }
9880 + }
9881 + }
9882 + }
9883 + return 0;
9884 +}
9885 +
9886 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9887 +{
9888 + abstract_pkg_t *apkg = depend->pkg;
9889 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9890 + int n_providers = provider_apkgs->len;
9891 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9892 + int i;
9893 + int n_pkgs;
9894 + int j;
9895 +
9896 + for (i = 0; i < n_providers; i++) {
9897 + abstract_pkg_t *papkg = apkgs[i];
9898 + pkg_vec_t *pkg_vec = papkg->pkgs;
9899 + if (pkg_vec) {
9900 + n_pkgs = pkg_vec->len;
9901 + for (j = 0; j < n_pkgs; j++) {
9902 + pkg_t *pkg = pkg_vec->pkgs[j];
9903 + if (version_constraints_satisfied(depend, pkg)) {
9904 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9905 + return 1;
9906 + }
9907 + }
9908 + }
9909 + }
9910 + return 0;
9911 +}
9912 +
9913 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9914 +{
9915 + register int i;
9916 + pkg_t ** pkgs = vec->pkgs;
9917 +
9918 + for(i = 0; i < vec->len; i++)
9919 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9920 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9921 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9922 + return 1;
9923 + return 0;
9924 +}
9925 +
9926 +
9927 +#ifdef DeadCode
9928 +/**
9929 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9930 + * the same abstract package and 0 otherwise.
9931 + */
9932 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9933 +{
9934 + abstract_pkg_t **provides = pkg->provides;
9935 + int provides_count = pkg->provides_count;
9936 + abstract_pkg_t **replacee_provides = replacee->provides;
9937 + int replacee_provides_count = replacee->provides_count;
9938 + int i, j;
9939 + for (i = 0; i < provides_count; i++) {
9940 + abstract_pkg_t *apkg = provides[i];
9941 + for (j = 0; j < replacee_provides_count; j++) {
9942 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9943 + if (apkg == replacee_apkg)
9944 + return 1;
9945 + }
9946 + }
9947 + return 0;
9948 +}
9949 +#endif
9950 +
9951 +/**
9952 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9953 + * and 0 otherwise.
9954 + */
9955 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9956 +{
9957 + abstract_pkg_t **provides = pkg->provides;
9958 + int provides_count = pkg->provides_count;
9959 + int i;
9960 + for (i = 0; i < provides_count; i++) {
9961 + if (provides[i] == providee)
9962 + return 1;
9963 + }
9964 + return 0;
9965 +}
9966 +
9967 +/**
9968 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9969 + * otherwise.
9970 + */
9971 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9972 +{
9973 + abstract_pkg_t **replaces = pkg->replaces;
9974 + int replaces_count = pkg->replaces_count;
9975 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9976 + int replacee_provides_count = pkg->provides_count; */
9977 + int i, j;
9978 + for (i = 0; i < replaces_count; i++) {
9979 + abstract_pkg_t *abstract_replacee = replaces[i];
9980 + for (j = 0; j < replaces_count; j++) {
9981 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9982 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9983 + if (replacee->provides[j] == abstract_replacee)
9984 + return 1;
9985 + }
9986 + }
9987 + return 0;
9988 +}
9989 +
9990 +
9991 +/**
9992 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9993 + * otherwise.
9994 + */
9995 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9996 +{
9997 + compound_depend_t *conflicts = pkg->conflicts;
9998 + int conflicts_count = pkg->conflicts_count;
9999 + int i, j;
10000 + for (i = 0; i < conflicts_count; i++) {
10001 + int possibility_count = conflicts[i].possibility_count;
10002 + struct depend **possibilities = conflicts[i].possibilities;
10003 + for (j = 0; j < possibility_count; j++) {
10004 + if (possibilities[j]->pkg == conflictee) {
10005 + return 1;
10006 + }
10007 + }
10008 + }
10009 + return 0;
10010 +}
10011 +
10012 +/**
10013 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10014 + * conflictee's provides and 0 otherwise.
10015 + */
10016 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10017 +{
10018 + compound_depend_t *conflicts = pkg->conflicts;
10019 + int conflicts_count = pkg->conflicts_count;
10020 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10021 + int conflictee_provides_count = conflictee->provides_count;
10022 + int i, j, k;
10023 + int possibility_count;
10024 + struct depend **possibilities;
10025 + abstract_pkg_t *possibility ;
10026 +
10027 + for (i = 0; i < conflicts_count; i++) {
10028 + possibility_count = conflicts[i].possibility_count;
10029 + possibilities = conflicts[i].possibilities;
10030 + for (j = 0; j < possibility_count; j++) {
10031 + possibility = possibilities[j]->pkg;
10032 + for (k = 0; k < conflictee_provides_count; k++) {
10033 + if (possibility == conflictee_provides[k]) {
10034 + return 1;
10035 + }
10036 + }
10037 + }
10038 + }
10039 + return 0;
10040 +}
10041 +
10042 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10043 +{
10044 + int oldlen = 0, newlen = 0;
10045 + char ** result;
10046 + register int i, j;
10047 +
10048 + if(!newstuff)
10049 + return oldstuff;
10050 +
10051 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10052 + while(newstuff && newstuff[newlen]) newlen++;
10053 +
10054 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10055 + if (result == NULL) {
10056 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10057 + return NULL;
10058 + }
10059 +
10060 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10061 + *(result + i) = *(newstuff + j);
10062 +
10063 + *(result + i) = NULL;
10064 +
10065 + return result;
10066 +}
10067 +
10068 +/*
10069 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10070 + * this is null terminated, no count is carried around
10071 + */
10072 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10073 +{
10074 + int count;
10075 + char ** resized;
10076 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10077 +
10078 + count = 0;
10079 + while(the_lost && the_lost[count]) count++;
10080 +
10081 + count++; /* need one to hold the null */
10082 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10083 + if (resized == NULL) {
10084 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10085 + return NULL;
10086 + }
10087 + resized[count - 1] = strdup(depend_str);
10088 + resized[count] = NULL;
10089 +
10090 + return resized;
10091 +}
10092 +
10093 +void printDepends(pkg_t * pkg)
10094 +{
10095 + register int i, j;
10096 + compound_depend_t * depend;
10097 + int count;
10098 +
10099 + count = pkg->pre_depends_count + pkg->depends_count;
10100 +
10101 + depend = pkg->depends;
10102 + if(!depend){
10103 + fprintf(stderr, "Depends pointer is NULL\n");
10104 + return;
10105 + }
10106 + for(i = 0; i < count; i++){
10107 + fprintf(stderr, "%s has %d possibilities:\n",
10108 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10109 + depend->possibility_count);
10110 + for(j = 0; j < depend->possibility_count; j++)
10111 + fprintf(stderr, "\t%s version %s (%d)\n",
10112 + depend->possibilities[j]->pkg->name,
10113 + depend->possibilities[j]->version,
10114 + depend->possibilities[j]->constraint);
10115 + depend++;
10116 + }
10117 +}
10118 +
10119 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10120 +{
10121 + register int i, j;
10122 +
10123 + /* every pkg provides itself */
10124 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10125 +
10126 + if (!pkg->provides_count)
10127 + return 0;
10128 +
10129 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10130 + if (pkg->provides == NULL) {
10131 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10132 + return -1 ;
10133 + }
10134 + pkg->provides[0] = ab_pkg;
10135 +
10136 + // if (strcmp(ab_pkg->name, pkg->name))
10137 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10138 +
10139 + for(i = 0; i < pkg->provides_count; i++){
10140 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10141 +
10142 + pkg->provides[i+1] = provided_abpkg;
10143 +
10144 + j = 0;
10145 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10146 + }
10147 + return 0;
10148 +}
10149 +
10150 +/* Abhaya: added conflicts support */
10151 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10152 +{
10153 + register int i;
10154 + compound_depend_t * conflicts;
10155 +
10156 + if (!pkg->conflicts_count)
10157 + return 0;
10158 +
10159 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10160 + pkg->conflicts_count);
10161 + if (conflicts == NULL) {
10162 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10163 + return -1;
10164 + }
10165 + for (i = 0; i < pkg->conflicts_count; i++) {
10166 + conflicts->type = CONFLICTS;
10167 + parseDepends(conflicts, hash,
10168 + pkg->conflicts_str[i]);
10169 +#if 0
10170 + for (j = 0; j < conflicts->possibility_count; j++) {
10171 + depend_t *possibility = conflicts->possibilities[j];
10172 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10173 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10174 + }
10175 +#endif
10176 + conflicts++;
10177 + }
10178 + return 0;
10179 +}
10180 +
10181 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10182 +{
10183 + register int i, j;
10184 +
10185 + if (!pkg->replaces_count)
10186 + return 0;
10187 +
10188 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10189 + if (pkg->replaces == NULL) {
10190 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10191 + return -1;
10192 + }
10193 +
10194 + // if (strcmp(ab_pkg->name, pkg->name))
10195 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10196 +
10197 + for(i = 0; i < pkg->replaces_count; i++){
10198 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10199 +
10200 + pkg->replaces[i] = old_abpkg;
10201 +
10202 + j = 0;
10203 + if (!old_abpkg->replaced_by)
10204 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10205 + if ( old_abpkg->replaced_by == NULL ){
10206 + return -1;
10207 + }
10208 + /* if a package pkg both replaces and conflicts old_abpkg,
10209 + * then add it to the replaced_by vector so that old_abpkg
10210 + * will be upgraded to ab_pkg automatically */
10211 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10212 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10213 + }
10214 + return 0;
10215 +}
10216 +
10217 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10218 +{
10219 + int count;
10220 + register int i;
10221 + compound_depend_t * depends;
10222 +
10223 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10224 + return 0;
10225 +
10226 + if (0 && pkg->pre_depends_count)
10227 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10228 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10229 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10230 + if (depends == NULL) {
10231 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10232 + return -1;
10233 + }
10234 +
10235 +
10236 + for(i = 0; i < pkg->pre_depends_count; i++){
10237 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10238 + if (0 && pkg->pre_depends_count)
10239 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10240 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10241 + depends->type = PREDEPEND;
10242 + depends++;
10243 + }
10244 +
10245 + for(i = 0; i < pkg->recommends_count; i++){
10246 + parseDepends(depends, hash, pkg->recommends_str[i]);
10247 + if (0 && pkg->recommends_count)
10248 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10249 + pkg->recommends_str[i], depends, depends->possibility_count);
10250 + depends->type = RECOMMEND;
10251 + depends++;
10252 + }
10253 +
10254 + for(i = 0; i < pkg->suggests_count; i++){
10255 + parseDepends(depends, hash, pkg->suggests_str[i]);
10256 + if (0 && pkg->suggests_count)
10257 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10258 + pkg->suggests_str[i], depends, depends->possibility_count);
10259 + depends->type = SUGGEST;
10260 + depends++;
10261 + }
10262 +
10263 + for(i = 0; i < pkg->depends_count; i++){
10264 + parseDepends(depends, hash, pkg->depends_str[i]);
10265 + if (0 && pkg->depends_count)
10266 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10267 + pkg->depends_str[i], depends, depends->possibility_count);
10268 + depends++;
10269 + }
10270 + return 0;
10271 +}
10272 +
10273 +/*
10274 + * pkg_depend_string: returns the depends string specified by index.
10275 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10276 + * [0,npredepends) -> returns pre_depends_str[index]
10277 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10278 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10279 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10280 + */
10281 +char *pkg_depend_str(pkg_t *pkg, int index)
10282 +{
10283 + if (index < pkg->pre_depends_count) {
10284 + return pkg->pre_depends_str[index];
10285 + }
10286 + index -= pkg->pre_depends_count;
10287 +
10288 + if (index < pkg->recommends_count) {
10289 + return pkg->recommends_str[index];
10290 + }
10291 + index -= pkg->recommends_count;
10292 +
10293 + if (index < pkg->suggests_count) {
10294 + return pkg->suggests_str[index];
10295 + }
10296 + index -= pkg->suggests_count;
10297 +
10298 + if (index < pkg->depends_count) {
10299 + return pkg->depends_str[index];
10300 + }
10301 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10302 + return NULL;
10303 +}
10304 +
10305 +void freeDepends(pkg_t *pkg)
10306 +{
10307 + int i;
10308 +
10309 + if (pkg == NULL || pkg->depends == NULL) {
10310 + return;
10311 + }
10312 +
10313 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10314 + for (i=0; i < pkg->depends->possibility_count; i++) {
10315 + depend_deinit(pkg->depends->possibilities[i]);
10316 + }
10317 + free(pkg->depends->possibilities);
10318 + free(pkg->depends);
10319 + pkg->depends = NULL;
10320 +}
10321 +
10322 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10323 +{
10324 + compound_depend_t * depends;
10325 + int count, othercount;
10326 + register int i, j;
10327 + abstract_pkg_t * ab_depend;
10328 + abstract_pkg_t ** temp;
10329 +
10330 + count = pkg->pre_depends_count + pkg->depends_count;
10331 + depends = pkg->depends;
10332 +
10333 + if (0 && pkg->pre_depends_count)
10334 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10335 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10336 + for (i = 0; i < count; i++) {
10337 + if (0 && pkg->pre_depends_count)
10338 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10339 + for (j = 0; j < depends->possibility_count; j++){
10340 + ab_depend = depends->possibilities[j]->pkg;
10341 + if(!ab_depend->depended_upon_by)
10342 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10343 +
10344 + temp = ab_depend->depended_upon_by;
10345 + othercount = 1;
10346 + while(*temp){
10347 + temp++;
10348 + othercount++;
10349 + }
10350 + *temp = ab_pkg;
10351 +
10352 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10353 + (othercount + 1) * sizeof(abstract_pkg_t *));
10354 + /* the array may have moved */
10355 + temp = ab_depend->depended_upon_by + othercount;
10356 + *temp = NULL;
10357 + }
10358 + depends++;
10359 + }
10360 +}
10361 +
10362 +static depend_t * depend_init(void)
10363 +{
10364 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10365 + if ( d==NULL ){
10366 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10367 + return NULL;
10368 + }
10369 + d->constraint = NONE;
10370 + d->version = NULL;
10371 + d->pkg = NULL;
10372 +
10373 + return d;
10374 +}
10375 +
10376 +static void depend_deinit(depend_t *d)
10377 +{
10378 + free(d);
10379 +}
10380 +
10381 +static int parseDepends(compound_depend_t *compound_depend,
10382 + hash_table_t * hash, char * depend_str)
10383 +{
10384 + char * pkg_name, buffer[2048];
10385 + int num_of_ors = 0;
10386 + register int i;
10387 + register char * src, * dest;
10388 + depend_t ** possibilities;
10389 +
10390 + /* first count the number of ored possibilities for satisfying dependency */
10391 + src = depend_str;
10392 + while(*src)
10393 + if(*src++ == '|')
10394 + num_of_ors++;
10395 +
10396 + compound_depend->type = DEPEND;
10397 +
10398 + compound_depend->possibility_count = num_of_ors + 1;
10399 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10400 + if (!possibilities)
10401 + return -ENOMEM;
10402 + compound_depend->possibilities = possibilities;
10403 +
10404 + src = depend_str;
10405 + for(i = 0; i < num_of_ors + 1; i++){
10406 + possibilities[i] = depend_init();
10407 + if (!possibilities[i])
10408 + return -ENOMEM;
10409 + /* gobble up just the name first */
10410 + dest = buffer;
10411 + while(*src &&
10412 + !isspace(*src) &&
10413 + (*src != '(') &&
10414 + (*src != '*') &&
10415 + (*src != '|'))
10416 + *dest++ = *src++;
10417 + *dest = '\0';
10418 + pkg_name = trim_alloc(buffer);
10419 + if (pkg_name == NULL )
10420 + return -ENOMEM;
10421 +
10422 + /* now look at possible version info */
10423 +
10424 + /* skip to next chars */
10425 + if(isspace(*src))
10426 + while(*src && isspace(*src)) src++;
10427 +
10428 + /* extract constraint and version */
10429 + if(*src == '('){
10430 + src++;
10431 + if(!strncmp(src, "<<", 2)){
10432 + possibilities[i]->constraint = EARLIER;
10433 + src += 2;
10434 + }
10435 + else if(!strncmp(src, "<=", 2)){
10436 + possibilities[i]->constraint = EARLIER_EQUAL;
10437 + src += 2;
10438 + }
10439 + else if(!strncmp(src, ">=", 2)){
10440 + possibilities[i]->constraint = LATER_EQUAL;
10441 + src += 2;
10442 + }
10443 + else if(!strncmp(src, ">>", 2)){
10444 + possibilities[i]->constraint = LATER;
10445 + src += 2;
10446 + }
10447 + else if(!strncmp(src, "=", 1)){
10448 + possibilities[i]->constraint = EQUAL;
10449 + src++;
10450 + }
10451 + /* should these be here to support deprecated designations; dpkg does */
10452 + else if(!strncmp(src, "<", 1)){
10453 + possibilities[i]->constraint = EARLIER_EQUAL;
10454 + src++;
10455 + }
10456 + else if(!strncmp(src, ">", 1)){
10457 + possibilities[i]->constraint = LATER_EQUAL;
10458 + src++;
10459 + }
10460 +
10461 + /* now we have any constraint, pass space to version string */
10462 + while(isspace(*src)) src++;
10463 +
10464 + /* this would be the version string */
10465 + dest = buffer;
10466 + while(*src && *src != ')')
10467 + *dest++ = *src++;
10468 + *dest = '\0';
10469 +
10470 + possibilities[i]->version = trim_alloc(buffer);
10471 + /* fprintf(stderr, "let's print the depends version string:");
10472 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10473 + if (possibilities[i]->version == NULL )
10474 + return -ENOMEM;
10475 +
10476 +
10477 + }
10478 + /* hook up the dependency to its abstract pkg */
10479 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10480 +
10481 + free(pkg_name);
10482 +
10483 + /* now get past the ) and any possible | chars */
10484 + while(*src &&
10485 + (isspace(*src) ||
10486 + (*src == ')') ||
10487 + (*src == '|')))
10488 + src++;
10489 + if (*src == '*')
10490 + {
10491 + compound_depend->type = GREEDY_DEPEND;
10492 + src++;
10493 + }
10494 + }
10495 +
10496 + return 0;
10497 +}
10498 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_depends.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h
10499 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10500 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-07-22 16:31:25.000000000 +0200
10501 @@ -0,0 +1,105 @@
10502 +/* pkg_depends.h - the itsy package management system
10503 +
10504 + Steven M. Ayer
10505 +
10506 + Copyright (C) 2002 Compaq Computer Corporation
10507 +
10508 + This program is free software; you can redistribute it and/or
10509 + modify it under the terms of the GNU General Public License as
10510 + published by the Free Software Foundation; either version 2, or (at
10511 + your option) any later version.
10512 +
10513 + This program is distributed in the hope that it will be useful, but
10514 + WITHOUT ANY WARRANTY; without even the implied warranty of
10515 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10516 + General Public License for more details.
10517 +*/
10518 +
10519 +#ifndef PKG_DEPENDS_H
10520 +#define PKG_DEPENDS_H
10521 +
10522 +#include "pkg.h"
10523 +#include "pkg_hash.h"
10524 +
10525 +enum depend_type {
10526 + PREDEPEND,
10527 + DEPEND,
10528 + CONFLICTS,
10529 + GREEDY_DEPEND,
10530 + RECOMMEND,
10531 + SUGGEST
10532 +};
10533 +typedef enum depend_type depend_type_t;
10534 +
10535 +enum version_constraint {
10536 + NONE,
10537 + EARLIER,
10538 + EARLIER_EQUAL,
10539 + EQUAL,
10540 + LATER_EQUAL,
10541 + LATER
10542 +};
10543 +typedef enum version_constraint version_constraint_t;
10544 +
10545 +struct depend{
10546 + version_constraint_t constraint;
10547 + char * version;
10548 + abstract_pkg_t * pkg;
10549 +};
10550 +typedef struct depend depend_t;
10551 +
10552 +struct compound_depend{
10553 + depend_type_t type;
10554 + int possibility_count;
10555 + struct depend ** possibilities;
10556 +};
10557 +typedef struct compound_depend compound_depend_t;
10558 +
10559 +#include "hash_table.h"
10560 +
10561 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10562 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10563 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10564 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10565 +
10566 +/**
10567 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10568 + * the same abstract package and 0 otherwise.
10569 + */
10570 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10571 +
10572 +/**
10573 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10574 + * otherwise.
10575 + */
10576 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10577 +
10578 +/**
10579 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10580 + * otherwise.
10581 + */
10582 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10583 +
10584 +/**
10585 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10586 + * otherwise.
10587 + */
10588 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10589 +
10590 +/**
10591 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10592 + * otherwise.
10593 + */
10594 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10595 +
10596 +char *pkg_depend_str(pkg_t *pkg, int index);
10597 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10598 +void freeDepends(pkg_t *pkg);
10599 +void printDepends(pkg_t * pkg);
10600 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10601 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10602 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10603 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10604 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10605 +
10606 +#endif
10607 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c
10608 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10609 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-07-22 16:31:25.000000000 +0200
10610 @@ -0,0 +1,92 @@
10611 +/* pkg_dest.c - the itsy package management system
10612 +
10613 + Carl D. Worth
10614 +
10615 + Copyright (C) 2001 University of Southern California
10616 +
10617 + This program is free software; you can redistribute it and/or
10618 + modify it under the terms of the GNU General Public License as
10619 + published by the Free Software Foundation; either version 2, or (at
10620 + your option) any later version.
10621 +
10622 + This program is distributed in the hope that it will be useful, but
10623 + WITHOUT ANY WARRANTY; without even the implied warranty of
10624 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10625 + General Public License for more details.
10626 +*/
10627 +
10628 +#include "ipkg.h"
10629 +
10630 +#include "pkg_dest.h"
10631 +#include "file_util.h"
10632 +#include "str_util.h"
10633 +#include "sprintf_alloc.h"
10634 +
10635 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10636 +{
10637 + dest->name = strdup(name);
10638 +
10639 + /* Guarantee that dest->root_dir ends with a '/' */
10640 + if (str_ends_with(root_dir, "/")) {
10641 + dest->root_dir = strdup(root_dir);
10642 + } else {
10643 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10644 + }
10645 + file_mkdir_hier(dest->root_dir, 0755);
10646 +
10647 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10648 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10649 + file_mkdir_hier(dest->ipkg_dir, 0755);
10650 +
10651 + if (str_starts_with (lists_dir, "/"))
10652 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10653 + else
10654 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10655 +
10656 + file_mkdir_hier(dest->lists_dir, 0755);
10657 +
10658 + sprintf_alloc(&dest->info_dir, "%s/%s",
10659 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10660 + file_mkdir_hier(dest->info_dir, 0755);
10661 +
10662 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10663 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10664 +
10665 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10666 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10667 +
10668 + dest->status_file = NULL;
10669 +
10670 + return 0;
10671 +}
10672 +
10673 +void pkg_dest_deinit(pkg_dest_t *dest)
10674 +{
10675 + free(dest->name);
10676 + dest->name = NULL;
10677 +
10678 + free(dest->root_dir);
10679 + dest->root_dir = NULL;
10680 +
10681 + free(dest->ipkg_dir);
10682 + dest->ipkg_dir = NULL;
10683 +
10684 + free(dest->lists_dir);
10685 + dest->lists_dir = NULL;
10686 +
10687 + free(dest->info_dir);
10688 + dest->info_dir = NULL;
10689 +
10690 + free(dest->status_file_name);
10691 + dest->status_file_name = NULL;
10692 +
10693 + free(dest->status_file_tmp_name);
10694 + dest->status_file_tmp_name = NULL;
10695 +
10696 + if (dest->status_file) {
10697 + fclose(dest->status_file);
10698 + }
10699 + dest->status_file = NULL;
10700 +
10701 + dest->root_dir = NULL;
10702 +}
10703 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h
10704 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10705 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-07-22 16:31:25.000000000 +0200
10706 @@ -0,0 +1,38 @@
10707 +/* pkg_dest.h - the itsy package management system
10708 +
10709 + Carl D. Worth
10710 +
10711 + Copyright (C) 2001 University of Southern California
10712 +
10713 + This program is free software; you can redistribute it and/or
10714 + modify it under the terms of the GNU General Public License as
10715 + published by the Free Software Foundation; either version 2, or (at
10716 + your option) any later version.
10717 +
10718 + This program is distributed in the hope that it will be useful, but
10719 + WITHOUT ANY WARRANTY; without even the implied warranty of
10720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10721 + General Public License for more details.
10722 +*/
10723 +
10724 +#ifndef PKG_DEST_H
10725 +#define PKG_DEST_H
10726 +
10727 +typedef struct pkg_dest pkg_dest_t;
10728 +struct pkg_dest
10729 +{
10730 + char *name;
10731 + char *root_dir;
10732 + char *ipkg_dir;
10733 + char *lists_dir;
10734 + char *info_dir;
10735 + char *status_file_name;
10736 + char *status_file_tmp_name;
10737 + FILE *status_file;
10738 +};
10739 +
10740 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10741 +void pkg_dest_deinit(pkg_dest_t *dest);
10742 +
10743 +#endif
10744 +
10745 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c
10746 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10747 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-07-22 16:31:25.000000000 +0200
10748 @@ -0,0 +1,85 @@
10749 +/* pkg_dest_list.c - the itsy package management system
10750 +
10751 + Carl D. Worth
10752 +
10753 + Copyright (C) 2001 University of Southern California
10754 +
10755 + This program is free software; you can redistribute it and/or
10756 + modify it under the terms of the GNU General Public License as
10757 + published by the Free Software Foundation; either version 2, or (at
10758 + your option) any later version.
10759 +
10760 + This program is distributed in the hope that it will be useful, but
10761 + WITHOUT ANY WARRANTY; without even the implied warranty of
10762 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10763 + General Public License for more details.
10764 +*/
10765 +
10766 +#include "ipkg.h"
10767 +
10768 +#include "pkg_dest.h"
10769 +#include "void_list.h"
10770 +#include "pkg_dest_list.h"
10771 +
10772 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10773 +{
10774 + return void_list_elt_init((void_list_elt_t *) elt, data);
10775 +}
10776 +
10777 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10778 +{
10779 + void_list_elt_deinit((void_list_elt_t *) elt);
10780 +}
10781 +
10782 +int pkg_dest_list_init(pkg_dest_list_t *list)
10783 +{
10784 + return void_list_init((void_list_t *) list);
10785 +}
10786 +
10787 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10788 +{
10789 + pkg_dest_list_elt_t *iter;
10790 + pkg_dest_t *pkg_dest;
10791 +
10792 + for (iter = list->head; iter; iter = iter->next) {
10793 + pkg_dest = iter->data;
10794 + pkg_dest_deinit(pkg_dest);
10795 +
10796 + /* malloced in pkg_dest_list_append */
10797 + free(pkg_dest);
10798 + iter->data = NULL;
10799 + }
10800 + void_list_deinit((void_list_t *) list);
10801 +}
10802 +
10803 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10804 + const char *root_dir,const char *lists_dir)
10805 +{
10806 + int err;
10807 + pkg_dest_t *pkg_dest;
10808 +
10809 + /* freed in plg_dest_list_deinit */
10810 + pkg_dest = malloc(sizeof(pkg_dest_t));
10811 + if (pkg_dest == NULL) {
10812 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10813 + return NULL;
10814 + }
10815 +
10816 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10817 + err = void_list_append((void_list_t *) list, pkg_dest);
10818 + if (err) {
10819 + return NULL;
10820 + }
10821 +
10822 + return pkg_dest;
10823 +}
10824 +
10825 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10826 +{
10827 + return void_list_push((void_list_t *) list, data);
10828 +}
10829 +
10830 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10831 +{
10832 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10833 +}
10834 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h
10835 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10836 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-07-22 16:31:25.000000000 +0200
10837 @@ -0,0 +1,50 @@
10838 +/* pkg_dest_list.h - the itsy package management system
10839 +
10840 + Carl D. Worth
10841 +
10842 + Copyright (C) 2001 University of Southern California
10843 +
10844 + This program is free software; you can redistribute it and/or
10845 + modify it under the terms of the GNU General Public License as
10846 + published by the Free Software Foundation; either version 2, or (at
10847 + your option) any later version.
10848 +
10849 + This program is distributed in the hope that it will be useful, but
10850 + WITHOUT ANY WARRANTY; without even the implied warranty of
10851 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10852 + General Public License for more details.
10853 +*/
10854 +
10855 +#ifndef PKG_DEST_LIST_H
10856 +#define PKG_DEST_LIST_H
10857 +
10858 +#include "pkg_dest.h"
10859 +
10860 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10861 +struct pkg_dest_list_elt
10862 +{
10863 + pkg_dest_list_elt_t *next;
10864 + pkg_dest_t *data;
10865 +};
10866 +
10867 +typedef struct pkg_dest_list pkg_dest_list_t;
10868 +struct pkg_dest_list
10869 +{
10870 + pkg_dest_list_elt_t pre_head;
10871 + pkg_dest_list_elt_t *head;
10872 + pkg_dest_list_elt_t *tail;
10873 +};
10874 +
10875 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10876 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10877 +
10878 +int pkg_dest_list_init(pkg_dest_list_t *list);
10879 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10880 +
10881 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10882 + const char *root_dir,const char* lists_dir);
10883 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10884 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10885 +
10886 +#endif
10887 +
10888 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_extract.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c
10889 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10890 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-07-22 16:31:25.000000000 +0200
10891 @@ -0,0 +1,224 @@
10892 +/* pkg_extract.c - the itsy package management system
10893 +
10894 + Carl D. Worth
10895 +
10896 + Copyright (C) 2001 University of Southern California
10897 +
10898 + This program is free software; you can redistribute it and/or
10899 + modify it under the terms of the GNU General Public License as
10900 + published by the Free Software Foundation; either version 2, or (at
10901 + your option) any later version.
10902 +
10903 + This program is distributed in the hope that it will be useful, but
10904 + WITHOUT ANY WARRANTY; without even the implied warranty of
10905 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10906 + General Public License for more details.
10907 +*/
10908 +
10909 +#include "ipkg.h"
10910 +#include <errno.h>
10911 +#include <fcntl.h>
10912 +#include <stdio.h>
10913 +
10914 +#include "pkg_extract.h"
10915 +
10916 +#include "libbb.h"
10917 +#include "file_util.h"
10918 +#include "sprintf_alloc.h"
10919 +#include "unarchive.h"
10920 +
10921 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10922 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10923 +#define IPKG_CONTROL_FILE "control"
10924 +
10925 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10926 +{
10927 + archive_handle_t *archive;
10928 + char *path;
10929 +
10930 + sprintf_alloc(&path, "%s/", dir);
10931 + archive = init_handle();
10932 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10933 + archive->filter = filter_accept_list;
10934 + llist_add_to(&(archive->accept), (char *)filename);
10935 + archive->buffer = path;
10936 + archive->action_data = data_extract_all_prefix;
10937 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10938 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10939 + close(archive->src_fd);
10940 + free(archive->accept);
10941 + free(archive);
10942 + free(path);
10943 +}
10944 +
10945 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10946 +{
10947 + unsigned int size = strlen(archive->file_header->name) + 2;
10948 +
10949 + if (archive->buffer == NULL) {
10950 + archive->buffer = xmalloc(size);
10951 + strcpy(archive->buffer, archive->file_header->name);
10952 + } else {
10953 + size += strlen(archive->buffer);
10954 + archive->buffer = xrealloc(archive->buffer, size);
10955 + strcat(archive->buffer, archive->file_header->name);
10956 + }
10957 + strcat(archive->buffer, "\n");
10958 + data_skip(archive);
10959 +}
10960 +
10961 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10962 +{
10963 + archive_handle_t *archive;
10964 + char *name;
10965 +
10966 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10967 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10968 + archive = init_handle();
10969 + archive->src_fd = bb_xopen(name, O_RDONLY);
10970 + archive->filter = filter_accept_list;
10971 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10972 + archive->action_data = data_extract_to_buffer;
10973 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10974 + close(archive->src_fd);
10975 + fputs(archive->buffer, stream);
10976 + free(archive->buffer);
10977 + free(archive->accept);
10978 + free(archive);
10979 + free(name);
10980 +
10981 + return 0;
10982 +}
10983 +
10984 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10985 +{
10986 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10987 +}
10988 +
10989 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10990 +{
10991 + archive_handle_t *archive;
10992 + char *name;
10993 + char *path;
10994 +
10995 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10996 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10997 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10998 + archive = init_handle();
10999 + archive->src_fd = bb_xopen(name, O_RDONLY);
11000 + archive->filter = filter_accept_all;
11001 + archive->buffer = path;
11002 + archive->action_data = data_extract_all_prefix;
11003 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11004 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11005 + close(archive->src_fd);
11006 + free(archive);
11007 + free(path);
11008 + free(name);
11009 +
11010 + return 0;
11011 +}
11012 +
11013 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11014 +{
11015 + archive_handle_t *archive;
11016 + char *name;
11017 + char *path;
11018 +
11019 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11020 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11021 + sprintf_alloc(&path, "%s/", dir);
11022 + archive = init_handle();
11023 + archive->src_fd = bb_xopen(name, O_RDONLY);
11024 + archive->filter = filter_accept_all;
11025 + archive->buffer = path;
11026 + archive->action_data = data_extract_all_prefix;
11027 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11028 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11029 + close(archive->src_fd);
11030 + free(archive);
11031 + free(path);
11032 + free(name);
11033 +
11034 + return 0;
11035 +}
11036 +
11037 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11038 +{
11039 + int err=0;
11040 + char *line, *data_file;
11041 + FILE *file;
11042 + FILE *tmp;
11043 +
11044 + file = fopen(file_name, "w");
11045 + if (file == NULL) {
11046 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11047 + __FUNCTION__, file_name);
11048 + return EINVAL;
11049 + }
11050 +
11051 + tmp = tmpfile();
11052 + if (pkg->installed_files) {
11053 + str_list_elt_t *elt;
11054 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11055 + fprintf(file, "%s\n", elt->data);
11056 + }
11057 + } else {
11058 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11059 + if (err) {
11060 + fclose(file);
11061 + fclose(tmp);
11062 + return err;
11063 + }
11064 +
11065 + /* Fixup data file names by removing the initial '.' */
11066 + rewind(tmp);
11067 + while (1) {
11068 + line = file_read_line_alloc(tmp);
11069 + if (line == NULL) {
11070 + break;
11071 + }
11072 +
11073 + data_file = line;
11074 + if (*data_file == '.') {
11075 + data_file++;
11076 + }
11077 +
11078 + if (*data_file != '/') {
11079 + fputs("/", file);
11080 + }
11081 +
11082 + /* I have no idea why, but this is what dpkg does */
11083 + if (strcmp(data_file, "/\n") == 0) {
11084 + fputs("/.\n", file);
11085 + } else {
11086 + fputs(data_file, file);
11087 + }
11088 + }
11089 + }
11090 + fclose(tmp);
11091 + fclose(file);
11092 +
11093 + return err;
11094 +}
11095 +
11096 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11097 +{
11098 + archive_handle_t *archive;
11099 + char *name;
11100 +
11101 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11102 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11103 + archive = init_handle();
11104 + archive->src_fd = bb_xopen(name, O_RDONLY);
11105 + archive->filter = filter_accept_all;
11106 + archive->action_data = data_extract_file_name_to_buffer;
11107 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11108 + close(archive->src_fd);
11109 + fputs(archive->buffer, file);
11110 + free(archive->buffer);
11111 + free(archive);
11112 + free(name);
11113 +
11114 + return 0;
11115 +}
11116 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_extract.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h
11117 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11118 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-07-22 16:31:25.000000000 +0200
11119 @@ -0,0 +1,32 @@
11120 +/* pkg_extract.c - the itsy package management system
11121 +
11122 + Carl D. Worth
11123 +
11124 + Copyright (C) 2001 University of Southern California
11125 +
11126 + This program is free software; you can redistribute it and/or
11127 + modify it under the terms of the GNU General Public License as
11128 + published by the Free Software Foundation; either version 2, or (at
11129 + your option) any later version.
11130 +
11131 + This program is distributed in the hope that it will be useful, but
11132 + WITHOUT ANY WARRANTY; without even the implied warranty of
11133 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11134 + General Public License for more details.
11135 +*/
11136 +
11137 +#ifndef PKG_EXTRACT_H
11138 +#define PKG_EXTRACT_H
11139 +
11140 +#include "pkg.h"
11141 +
11142 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11143 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11144 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11145 + const char *dir,
11146 + const char *prefix);
11147 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11148 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11149 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11150 +
11151 +#endif
11152 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h
11153 --- busybox-1.2.0-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
11154 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h 2006-07-22 16:31:25.000000000 +0200
11155 @@ -0,0 +1,232 @@
11156 +/* pkg.h - the itsy package management system
11157 +
11158 + Carl D. Worth
11159 +
11160 + Copyright (C) 2001 University of Southern California
11161 +
11162 + This program is free software; you can redistribute it and/or
11163 + modify it under the terms of the GNU General Public License as
11164 + published by the Free Software Foundation; either version 2, or (at
11165 + your option) any later version.
11166 +
11167 + This program is distributed in the hope that it will be useful, but
11168 + WITHOUT ANY WARRANTY; without even the implied warranty of
11169 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11170 + General Public License for more details.
11171 +*/
11172 +
11173 +#ifndef PKG_H
11174 +#define PKG_H
11175 +
11176 +#include <sys/types.h>
11177 +#include <sys/stat.h>
11178 +#include <unistd.h>
11179 +
11180 +#include "pkg_vec.h"
11181 +#include "str_list.h"
11182 +#include "pkg_src.h"
11183 +#include "pkg_dest.h"
11184 +#include "ipkg_conf.h"
11185 +#include "conffile_list.h"
11186 +
11187 +struct ipkg_conf;
11188 +
11189 +
11190 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11191 +
11192 +/* I think "Size" is currently the shortest field name */
11193 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11194 +
11195 +enum pkg_state_want
11196 +{
11197 + SW_UNKNOWN = 1,
11198 + SW_INSTALL,
11199 + SW_DEINSTALL,
11200 + SW_PURGE,
11201 + SW_LAST_STATE_WANT
11202 +};
11203 +typedef enum pkg_state_want pkg_state_want_t;
11204 +
11205 +enum pkg_state_flag
11206 +{
11207 + SF_OK = 0,
11208 + SF_REINSTREQ = 1,
11209 + SF_HOLD = 2, /* do not upgrade version */
11210 + SF_REPLACE = 4, /* replace this package */
11211 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11212 + SF_PREFER = 16, /* prefer this version */
11213 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11214 + SF_MARKED = 64, /* temporary mark */
11215 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11216 + SF_USER = 256,
11217 + SF_LAST_STATE_FLAG
11218 +};
11219 +typedef enum pkg_state_flag pkg_state_flag_t;
11220 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11221 +
11222 +enum pkg_state_status
11223 +{
11224 + SS_NOT_INSTALLED = 1,
11225 + SS_UNPACKED,
11226 + SS_HALF_CONFIGURED,
11227 + SS_INSTALLED,
11228 + SS_HALF_INSTALLED,
11229 + SS_CONFIG_FILES,
11230 + SS_POST_INST_FAILED,
11231 + SS_REMOVAL_FAILED,
11232 + SS_LAST_STATE_STATUS
11233 +};
11234 +typedef enum pkg_state_status pkg_state_status_t;
11235 +
11236 +struct abstract_pkg{
11237 + char * name;
11238 + int dependencies_checked;
11239 + pkg_vec_t * pkgs;
11240 + pkg_state_status_t state_status;
11241 + pkg_state_flag_t state_flag;
11242 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11243 + abstract_pkg_vec_t * provided_by;
11244 + abstract_pkg_vec_t * replaced_by;
11245 +};
11246 +
11247 +#include "pkg_depends.h"
11248 +
11249 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11250 +
11251 + The 3 version fields should go into a single version struct. (This
11252 + is especially important since, currently, pkg->version can easily
11253 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11254 + distinct. This has been the source of multiple bugs.
11255 +
11256 + The 3 state fields could possibly also go into their own struct.
11257 +
11258 + All fields which deal with lists of packages, (Depends,
11259 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11260 + be handled by a single struct in pkg_t
11261 +
11262 + All string fields for which there is a small set of possible
11263 + values, (section, maintainer, architecture, maybe version?), that
11264 + are reused among different packages -- for all such packages we
11265 + should move from "char *"s to some atom datatype to share data
11266 + storage and use less memory. We might even do reference counting,
11267 + but probably not since most often we only create new pkg_t structs,
11268 + we don't often free them. */
11269 +struct pkg
11270 +{
11271 + char *name;
11272 + unsigned long epoch;
11273 + char *version;
11274 + char *revision;
11275 + char *familiar_revision;
11276 + pkg_src_t *src;
11277 + pkg_dest_t *dest;
11278 + char *architecture;
11279 + char *section;
11280 + char *maintainer;
11281 + char *description;
11282 + pkg_state_want_t state_want;
11283 + pkg_state_flag_t state_flag;
11284 + pkg_state_status_t state_status;
11285 + char **depends_str;
11286 + int depends_count;
11287 + char **pre_depends_str;
11288 + int pre_depends_count;
11289 + char **recommends_str;
11290 + int recommends_count;
11291 + char **suggests_str;
11292 + int suggests_count;
11293 + compound_depend_t * depends;
11294 +
11295 + /* Abhaya: new conflicts */
11296 + char **conflicts_str;
11297 + compound_depend_t * conflicts;
11298 + int conflicts_count;
11299 +
11300 + char **replaces_str;
11301 + int replaces_count;
11302 + abstract_pkg_t ** replaces;
11303 +
11304 + char **provides_str;
11305 + int provides_count;
11306 + abstract_pkg_t ** provides;
11307 +
11308 + abstract_pkg_t *parent;
11309 +
11310 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11311 +
11312 + char *filename;
11313 + char *local_filename;
11314 + char *url;
11315 + char *tmp_unpack_dir;
11316 + char *md5sum;
11317 + char *size;
11318 + char *installed_size;
11319 + char *priority;
11320 + char *source;
11321 + conffile_list_t conffiles;
11322 + time_t installed_time;
11323 + /* As pointer for lazy evaluation */
11324 + str_list_t *installed_files;
11325 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11326 + mechanism to avoid the problem here, (which is that the
11327 + installed_files list was being freed from an inner loop while
11328 + still being used within an outer loop. */
11329 + int installed_files_ref_cnt;
11330 + int essential;
11331 + int arch_priority;
11332 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11333 + int provided_by_hand;
11334 +};
11335 +
11336 +pkg_t *pkg_new(void);
11337 +int pkg_init(pkg_t *pkg);
11338 +void pkg_deinit(pkg_t *pkg);
11339 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11340 +abstract_pkg_t *abstract_pkg_new(void);
11341 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11342 +
11343 +/*
11344 + * merges fields from newpkg into oldpkg.
11345 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11346 + */
11347 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11348 +
11349 +char *pkg_version_str_alloc(pkg_t *pkg);
11350 +
11351 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11352 +int pkg_name_version_and_architecture_compare(void *a, void *b);
11353 +int abstract_pkg_name_compare(void *a, void *b);
11354 +
11355 +char * pkg_formatted_info(pkg_t *pkg );
11356 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11357 +
11358 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11359 +
11360 +void pkg_print_info(pkg_t *pkg, FILE *file);
11361 +void pkg_print_status(pkg_t * pkg, FILE * file);
11362 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11363 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11364 +int pkg_free_installed_files(pkg_t *pkg);
11365 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11366 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11367 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11368 + const char *script, const char *args);
11369 +
11370 +/* enum mappings */
11371 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11372 +pkg_state_want_t pkg_state_want_from_str(char *str);
11373 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11374 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11375 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11376 +pkg_state_status_t pkg_state_status_from_str(char *str);
11377 +
11378 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11379 +
11380 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11381 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11382 +int pkg_free_installed_files(pkg_t *pkg);
11383 +
11384 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11385 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11386 +
11387 +#endif
11388 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_hash.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c
11389 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11390 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-07-22 16:31:25.000000000 +0200
11391 @@ -0,0 +1,617 @@
11392 +/* ipkg_hash.c - the itsy package management system
11393 +
11394 + Steven M. Ayer
11395 +
11396 + Copyright (C) 2002 Compaq Computer Corporation
11397 +
11398 + This program is free software; you can redistribute it and/or
11399 + modify it under the terms of the GNU General Public License as
11400 + published by the Free Software Foundation; either version 2, or (at
11401 + your option) any later version.
11402 +
11403 + This program is distributed in the hope that it will be useful, but
11404 + WITHOUT ANY WARRANTY; without even the implied warranty of
11405 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11406 + General Public License for more details.
11407 +*/
11408 +
11409 +#include "ipkg.h"
11410 +#include <errno.h>
11411 +#include <ctype.h>
11412 +#include <stdlib.h>
11413 +#include <string.h>
11414 +
11415 +#include "hash_table.h"
11416 +#include "pkg.h"
11417 +#include "ipkg_message.h"
11418 +#include "pkg_vec.h"
11419 +#include "pkg_hash.h"
11420 +#include "pkg_parse.h"
11421 +#include "ipkg_utils.h"
11422 +
11423 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11424 +
11425 +/*
11426 + * this will talk to both feeds-lists files and installed status files
11427 + * example api:
11428 + *
11429 + * hash_table_t hash;
11430 + * pkg_hash_init(name, &hash, 1000);
11431 + * pkg_hash_add_from_file(<feed filename>);
11432 + *
11433 + * the query function is just there as a shell to prove to me that this
11434 + * sort of works, but isn't far from doing something useful
11435 + *
11436 + * -sma, 12/21/01
11437 + * modified: CDW 3 Jan. 2002
11438 + */
11439 +
11440 +
11441 +\f
11442 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11443 +{
11444 + return hash_table_init(name, hash, len);
11445 +}
11446 +
11447 +void pkg_hash_deinit(hash_table_t *hash)
11448 +{
11449 + hash_table_deinit(hash);
11450 +}
11451 +
11452 +
11453 +/* Find the default arch for a given package status file if none is given. */
11454 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11455 +{
11456 + nv_pair_list_elt_t *l;
11457 + char *def_arch = HOST_CPU_STR; /* Default arch */
11458 + int def_prio = 0; /* Other archs override this */
11459 +
11460 + l = conf->arch_list.head;
11461 +
11462 + while (l) {
11463 + nv_pair_t *nv = l->data;
11464 + int priority = strtol(nv->value, NULL, 0);
11465 +
11466 + /* Check if this arch has higher priority, and is valid */
11467 + if ((priority > def_prio) &&
11468 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11469 + /* Our new default */
11470 + def_prio = priority;
11471 + def_arch = nv->name;
11472 + }
11473 + l = l->next;
11474 + }
11475 +
11476 + return strdup(def_arch);
11477 +}
11478 +
11479 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11480 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11481 +{
11482 + hash_table_t *hash = &conf->pkg_hash;
11483 + char **raw;
11484 + char **raw_start;
11485 + pkg_t *pkg;
11486 +
11487 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11488 + if (!raw)
11489 + return -ENOMEM;
11490 +
11491 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11492 + pkg = pkg_new();
11493 + if (!pkg)
11494 + return -ENOMEM;
11495 +
11496 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11497 + if (!pkg->architecture) {
11498 + char *version_str = pkg_version_str_alloc(pkg);
11499 + pkg->architecture = pkg_get_default_arch(conf);
11500 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11501 + pkg->name, version_str, pkg->architecture);
11502 + free(version_str);
11503 + }
11504 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11505 + } else {
11506 + free(pkg);
11507 + }
11508 + }
11509 +
11510 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11511 + memory after read_raw_pkgs_from_file */
11512 + raw = raw_start;
11513 + while (*raw) {
11514 + free(*raw++);
11515 + }
11516 + free(raw_start);
11517 + return 0;
11518 +}
11519 +
11520 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11521 +{
11522 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11523 +}
11524 +
11525 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11526 +{
11527 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11528 + if (apkg)
11529 + return NULL;
11530 + return apkg->provided_by;
11531 +}
11532 +
11533 +
11534 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11535 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11536 +{
11537 + int i;
11538 + int nprovides = 0;
11539 + int nmatching = 0;
11540 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11541 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11542 + abstract_pkg_vec_t *provided_apkg_vec;
11543 + abstract_pkg_t **provided_apkgs;
11544 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11545 + pkg_t *latest_installed_parent = NULL;
11546 + pkg_t *latest_matching = NULL;
11547 + pkg_t *held_pkg = NULL;
11548 + pkg_t *good_pkg_by_name = NULL;
11549 +
11550 + if (matching_apkgs == NULL || providers == NULL ||
11551 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11552 + return NULL;
11553 +
11554 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11555 +
11556 + provided_apkg_vec = apkg->provided_by;
11557 + nprovides = provided_apkg_vec->len;
11558 + provided_apkgs = provided_apkg_vec->pkgs;
11559 + if (nprovides > 1)
11560 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11561 +
11562 + /* accumulate all the providers */
11563 + for (i = 0; i < nprovides; i++) {
11564 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11565 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11566 + abstract_pkg_vec_insert(providers, provider_apkg);
11567 + }
11568 + nprovides = providers->len;
11569 +
11570 + for (i = 0; i < nprovides; i++) {
11571 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11572 + abstract_pkg_t *replacement_apkg = NULL;
11573 + pkg_vec_t *vec;
11574 +
11575 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11576 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11577 + if (provider_apkg->replaced_by->len > 1) {
11578 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11579 + provider_apkg->name, replacement_apkg->name);
11580 + }
11581 + }
11582 +
11583 + if (replacement_apkg)
11584 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11585 + replacement_apkg->name, provider_apkg->name);
11586 +
11587 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11588 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11589 + continue;
11590 + else
11591 + provider_apkg = replacement_apkg;
11592 + }
11593 +
11594 + if (!(vec = provider_apkg->pkgs)) {
11595 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11596 + continue;
11597 + }
11598 +
11599 +
11600 + /* now check for supported architecture */
11601 + {
11602 + int max_count = 0;
11603 + int i;
11604 +
11605 + /* count packages matching max arch priority and keep track of last one */
11606 + for (i = 0; i < vec->len; i++) {
11607 + pkg_t *maybe = vec->pkgs[i];
11608 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11609 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11610 + if (maybe->arch_priority > 0) {
11611 + max_count++;
11612 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11613 + pkg_vec_insert(matching_pkgs, maybe);
11614 + }
11615 + }
11616 + }
11617 + }
11618 +
11619 + if (matching_pkgs->len > 1)
11620 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11621 + if (matching_apkgs->len > 1)
11622 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11623 +
11624 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11625 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11626 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11627 + Until now I always got the latest, but that breaks the downgrade option.
11628 + If I stop at the first one, I would probably miss the new ones
11629 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11630 + or from a Packages feed.
11631 + 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*/
11632 +/*Pigi*/
11633 +
11634 + for (i = 0; i < matching_pkgs->len; i++) {
11635 + pkg_t *matching = matching_pkgs->pkgs[i];
11636 + if (constraint_fcn(matching, cdata)) { /* We found it */
11637 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11638 + good_pkg_by_name = matching;
11639 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11640 + break;
11641 + }
11642 + }
11643 +
11644 +
11645 + for (i = 0; i < matching_pkgs->len; i++) {
11646 + pkg_t *matching = matching_pkgs->pkgs[i];
11647 + latest_matching = matching;
11648 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11649 + latest_installed_parent = matching;
11650 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11651 + if (held_pkg)
11652 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11653 + held_pkg->name, matching->name);
11654 + held_pkg = matching;
11655 + }
11656 + }
11657 +
11658 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11659 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11660 + apkg->name, matching_apkgs->len);
11661 + for (i = 0; i < matching_apkgs->len; i++) {
11662 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11663 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11664 + }
11665 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11666 + }
11667 +
11668 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11669 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11670 + __FUNCTION__, apkg->name, matching_pkgs->len);
11671 + for (i = 0; i < matching_pkgs->len; i++) {
11672 + pkg_t *matching = matching_pkgs->pkgs[i];
11673 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11674 + matching->name, matching->version, matching->architecture);
11675 + }
11676 + }
11677 +
11678 + nmatching = matching_apkgs->len;
11679 +
11680 + pkg_vec_free(matching_pkgs);
11681 + abstract_pkg_vec_free(matching_apkgs);
11682 + abstract_pkg_vec_free(providers);
11683 +
11684 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11685 + return good_pkg_by_name;
11686 + }
11687 + if (held_pkg) {
11688 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11689 + return held_pkg;
11690 + }
11691 + if (latest_installed_parent) {
11692 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11693 + return latest_installed_parent;
11694 + }
11695 + if (nmatching > 1) {
11696 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11697 + return NULL;
11698 + }
11699 + if (latest_matching) {
11700 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11701 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11702 + return latest_matching;
11703 + }
11704 + return NULL;
11705 +}
11706 +
11707 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11708 +{
11709 + const char *name = (const char *)cdata;
11710 + if (strcmp(pkg->name, name) == 0)
11711 + return 1;
11712 + else
11713 + return 0;
11714 +}
11715 +
11716 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11717 +{
11718 + hash_table_t *hash = &conf->pkg_hash;
11719 + abstract_pkg_t *apkg = NULL;
11720 +
11721 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11722 + return NULL;
11723 +
11724 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11725 +}
11726 +
11727 +
11728 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11729 + const char *pkg_name,
11730 + const char * version)
11731 +{
11732 + pkg_vec_t * vec;
11733 + register int i;
11734 + char *version_str = NULL;
11735 +
11736 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11737 + return NULL;
11738 +
11739 + for(i = 0; i < vec->len; i++) {
11740 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11741 + if(!strcmp(version_str, version)) {
11742 + free(version_str);
11743 + break;
11744 + }
11745 + free(version_str);
11746 + }
11747 +
11748 + if(i == vec->len)
11749 + return NULL;
11750 +
11751 + return vec->pkgs[i];
11752 +}
11753 +
11754 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11755 + const char *pkg_name,
11756 + pkg_dest_t *dest)
11757 +{
11758 + pkg_vec_t * vec;
11759 + register int i;
11760 +
11761 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11762 + return NULL;
11763 + }
11764 +
11765 + for(i = 0; i < vec->len; i++)
11766 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11767 + return vec->pkgs[i];
11768 + }
11769 + return NULL;
11770 +}
11771 +
11772 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11773 + const char *pkg_name)
11774 +{
11775 + pkg_vec_t * vec;
11776 + register int i;
11777 +
11778 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11779 + return NULL;
11780 + }
11781 +
11782 + for(i = 0; i < vec->len; i++)
11783 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11784 + return vec->pkgs[i];
11785 + }
11786 +
11787 + return NULL;
11788 +}
11789 +
11790 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11791 +{
11792 + abstract_pkg_t * ab_pkg;
11793 +
11794 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11795 + return NULL;
11796 + }
11797 +
11798 + if (ab_pkg->pkgs) {
11799 + return ab_pkg->pkgs;
11800 + } else if (ab_pkg->provided_by) {
11801 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11802 + if (abpkg != NULL){
11803 + return abpkg->pkgs;
11804 + } else {
11805 + return ab_pkg->pkgs;
11806 + }
11807 + } else {
11808 + return NULL;
11809 + }
11810 +}
11811 +
11812 +static int pkg_compare_names(const void *p1, const void *p2)
11813 +{
11814 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11815 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11816 + if (pkg1->name == NULL)
11817 + return 1;
11818 + if (pkg2->name == NULL)
11819 + return -1;
11820 + return(strcmp(pkg1->name, pkg2->name));
11821 +}
11822 +
11823 +
11824 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11825 +{
11826 + int j;
11827 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11828 + pkg_vec_t *all = (pkg_vec_t *)data;
11829 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11830 + if (pkg_vec) {
11831 + for (j = 0; j < pkg_vec->len; j++) {
11832 + pkg_t *pkg = pkg_vec->pkgs[j];
11833 + pkg_vec_insert(all, pkg);
11834 + }
11835 + }
11836 +}
11837 +
11838 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11839 +{
11840 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11841 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11842 +}
11843 +
11844 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11845 +{
11846 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11847 + pkg_vec_t *all = (pkg_vec_t *)data;
11848 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11849 + int j;
11850 + if (pkg_vec) {
11851 + for (j = 0; j < pkg_vec->len; j++) {
11852 + pkg_t *pkg = pkg_vec->pkgs[j];
11853 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11854 + pkg_vec_insert(all, pkg);
11855 + }
11856 + }
11857 + }
11858 +}
11859 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11860 +{
11861 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11862 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11863 +}
11864 +
11865 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11866 +{
11867 + int i;
11868 + pkg_t *pkg;
11869 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11870 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11871 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11872 + fprintf(stdout, "%s\n", ab_pkg->name);
11873 + i = 0;
11874 + if (dependents != NULL)
11875 + while (dependents [i] != NULL)
11876 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11877 + dependents = ab_pkg->provided_by->pkgs;
11878 + i = 0;
11879 + if (dependents != NULL)
11880 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11881 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11882 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11883 + if (pkg) {
11884 + i = 0;
11885 + while (i < pkg->depends_count)
11886 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11887 + }
11888 +}
11889 +void pkg_hash_dump(hash_table_t *hash, void *data)
11890 +{
11891 +
11892 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11893 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11894 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11895 +}
11896 +
11897 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11898 +{
11899 + abstract_pkg_t * ab_pkg;
11900 +
11901 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11902 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11903 +
11904 + return ab_pkg;
11905 +}
11906 +
11907 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11908 +{
11909 + abstract_pkg_t * ab_pkg;
11910 + int arch_priority;
11911 +
11912 + if(!pkg)
11913 + return pkg;
11914 +
11915 + arch_priority = pkg->arch_priority;
11916 +
11917 + if (buildDepends(hash, pkg)<0){
11918 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11919 + return NULL;
11920 + }
11921 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11922 +
11923 + if (set_status) {
11924 + if (pkg->state_status == SS_INSTALLED) {
11925 + ab_pkg->state_status = SS_INSTALLED;
11926 + } else if (pkg->state_status == SS_UNPACKED) {
11927 + ab_pkg->state_status = SS_UNPACKED;
11928 + }
11929 + }
11930 +
11931 + if(!ab_pkg->pkgs)
11932 + ab_pkg->pkgs = pkg_vec_alloc();
11933 +
11934 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11935 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11936 + pkg->parent = ab_pkg;
11937 +
11938 + if (buildProvides(hash, ab_pkg, pkg)<0){
11939 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11940 + return NULL;
11941 + }
11942 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11943 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11944 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11945 + return NULL;
11946 + }
11947 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11948 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11949 + return NULL;
11950 + }
11951 +
11952 + buildDependedUponBy(pkg, ab_pkg);
11953 + return pkg;
11954 +}
11955 +
11956 +/*
11957 + * this will assume that we've already determined that
11958 + * the abstract pkg doesn't exist, 'cause we should know these things...
11959 + */
11960 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11961 +{
11962 + abstract_pkg_t * ab_pkg;
11963 +
11964 + ab_pkg = abstract_pkg_new();
11965 + if (ab_pkg == NULL) { return NULL; }
11966 +
11967 + ab_pkg->name = strdup(pkg_name);
11968 + hash_table_insert(hash, pkg_name, ab_pkg);
11969 +
11970 + return ab_pkg;
11971 +}
11972 +
11973 +
11974 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11975 +{
11976 + hash_table_t *file_hash = &conf->file_hash;
11977 +
11978 + return hash_table_get(file_hash, file_name);
11979 +}
11980 +
11981 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11982 +{
11983 + hash_table_t *file_hash = &conf->file_hash;
11984 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11985 + int file_name_len = strlen(file_name);
11986 +
11987 + if (file_name[file_name_len -1] == '/')
11988 + return 0;
11989 +
11990 + if (conf->offline_root) {
11991 + int len = strlen(conf->offline_root);
11992 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11993 + file_name += len;
11994 + }
11995 + }
11996 +
11997 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11998 + hash_table_insert(file_hash, file_name, owning_pkg);
11999 + if (old_owning_pkg) {
12000 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12001 + /* mark this package to have its filelist written */
12002 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12003 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12004 + }
12005 + return 0;
12006 +}
12007 +
12008 +
12009 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_hash.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h
12010 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12011 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-07-22 16:31:25.000000000 +0200
12012 @@ -0,0 +1,61 @@
12013 +/* pkg_hash.h - the itsy package management system
12014 +
12015 + Steven M. Ayer
12016 +
12017 + Copyright (C) 2002 Compaq Computer Corporation
12018 +
12019 + This program is free software; you can redistribute it and/or
12020 + modify it under the terms of the GNU General Public License as
12021 + published by the Free Software Foundation; either version 2, or (at
12022 + your option) any later version.
12023 +
12024 + This program is distributed in the hope that it will be useful, but
12025 + WITHOUT ANY WARRANTY; without even the implied warranty of
12026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12027 + General Public License for more details.
12028 +*/
12029 +
12030 +#ifndef PKG_HASH_H
12031 +#define PKG_HASH_H
12032 +
12033 +#include "pkg.h"
12034 +#include "pkg_vec.h"
12035 +#include "hash_table.h"
12036 +
12037 +
12038 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12039 +void pkg_hash_deinit(hash_table_t *hash);
12040 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12041 +
12042 +void pkg_hash_dump(hash_table_t *hash, void *data);
12043 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12044 +
12045 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12046 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12047 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12048 +
12049 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12050 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12051 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12052 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12053 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12054 + const char *pkg_name,
12055 + const char * version);
12056 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12057 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12058 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12059 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12060 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12061 + const char *pkg_name);
12062 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12063 + const char *pkg_name,
12064 + pkg_dest_t *dest);
12065 +
12066 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12067 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12068 +
12069 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12070 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12071 +
12072 +#endif
12073 +
12074 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_parse.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c
12075 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12076 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-07-22 16:31:25.000000000 +0200
12077 @@ -0,0 +1,366 @@
12078 +/* pkg_parse.c - the itsy package management system
12079 +
12080 + Steven M. Ayer
12081 +
12082 + Copyright (C) 2002 Compaq Computer Corporation
12083 +
12084 + This program is free software; you can redistribute it and/or
12085 + modify it under the terms of the GNU General Public License as
12086 + published by the Free Software Foundation; either version 2, or (at
12087 + your option) any later version.
12088 +
12089 + This program is distributed in the hope that it will be useful, but
12090 + WITHOUT ANY WARRANTY; without even the implied warranty of
12091 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12092 + General Public License for more details.
12093 +*/
12094 +
12095 +#include "ipkg.h"
12096 +#include <errno.h>
12097 +#include <ctype.h>
12098 +
12099 +#include "pkg.h"
12100 +#include "ipkg_utils.h"
12101 +#include "pkg_parse.h"
12102 +
12103 +int isGenericFieldType(char * type, char * line)
12104 +{
12105 + if(!strncmp(line, type, strlen(type)))
12106 + return 1;
12107 + return 0;
12108 +}
12109 +
12110 +char * parseGenericFieldType(char * type, char * raw)
12111 +{
12112 + char * field_value = raw + (strlen(type) + 1);
12113 + return trim_alloc(field_value);
12114 +}
12115 +
12116 +void parseStatus(pkg_t *pkg, char * raw)
12117 +{
12118 + char sw_str[64], sf_str[64], ss_str[64];
12119 +
12120 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12121 + pkg->state_want = pkg_state_want_from_str(sw_str);
12122 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12123 + pkg->state_status = pkg_state_status_from_str(ss_str);
12124 +}
12125 +
12126 +char ** parseDependsString(char * raw, int * depends_count)
12127 +{
12128 + char ** depends = NULL;
12129 + int line_count = 0;
12130 + char buff[2048], * dest;
12131 +
12132 + while(raw && *raw && !isspace(*raw)) {
12133 + raw++;
12134 + }
12135 +
12136 + if(line_is_blank(raw)){
12137 + *depends_count = line_count;
12138 + return NULL;
12139 + }
12140 + while(raw && *raw){
12141 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12142 +
12143 + while(isspace(*raw)) raw++;
12144 +
12145 + dest = buff;
12146 + while((*raw != ',') && *raw)
12147 + *dest++ = *raw++;
12148 +
12149 + *dest = '\0';
12150 + depends[line_count] = trim_alloc(buff);
12151 + if(depends[line_count] ==NULL)
12152 + return NULL;
12153 + line_count++;
12154 + if(*raw == ',')
12155 + raw++;
12156 + }
12157 + *depends_count = line_count;
12158 + return depends;
12159 +}
12160 +
12161 +void parseConffiles(pkg_t * pkg, char * raw)
12162 +{
12163 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12164 +
12165 + if(!strncmp(raw, "Conffiles:", 10))
12166 + raw += strlen("Conffiles:");
12167 +
12168 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12169 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12170 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12171 + while (*raw && isspace(*raw)) {
12172 + raw++;
12173 + }
12174 + raw += strlen(file_name);
12175 + while (*raw && isspace(*raw)) {
12176 + raw++;
12177 + }
12178 + raw += strlen(md5sum);
12179 + }
12180 +}
12181 +
12182 +int parseVersion(pkg_t *pkg, char *raw)
12183 +{
12184 + char *colon, *eepochcolon;
12185 +#ifdef USE_DEBVERSION
12186 + char *hyphen;
12187 +#endif
12188 + unsigned long epoch;
12189 +
12190 + if (!*raw) {
12191 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12192 + return EINVAL;
12193 + }
12194 +
12195 + if (strncmp(raw, "Version:", 8) == 0) {
12196 + raw += 8;
12197 + }
12198 + while (*raw && isspace(*raw)) {
12199 + raw++;
12200 + }
12201 +
12202 + colon= strchr(raw,':');
12203 + if (colon) {
12204 + epoch= strtoul(raw,&eepochcolon,10);
12205 + if (colon != eepochcolon) {
12206 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12207 + return EINVAL;
12208 + }
12209 + if (!*++colon) {
12210 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12211 + return EINVAL;
12212 + }
12213 + raw= colon;
12214 + pkg->epoch= epoch;
12215 + } else {
12216 + pkg->epoch= 0;
12217 + }
12218 +
12219 + pkg->revision = "";
12220 + pkg->familiar_revision = "";
12221 +
12222 + pkg->version= malloc(strlen(raw)+1);
12223 + if ( pkg->version == NULL ) {
12224 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12225 + return ENOMEM;
12226 + }
12227 + strcpy(pkg->version, raw);
12228 +
12229 +#ifdef USE_DEBVERSION
12230 + hyphen= strrchr(pkg->version,'-');
12231 +
12232 + if (hyphen) {
12233 + *hyphen++= 0;
12234 + if (strncmp("fam", hyphen, 3) == 0) {
12235 + pkg->familiar_revision=hyphen+3;
12236 + hyphen= strrchr(pkg->version,'-');
12237 + if (hyphen) {
12238 + *hyphen++= 0;
12239 + pkg->revision = hyphen;
12240 + }
12241 + } else {
12242 + pkg->revision = hyphen;
12243 + }
12244 + }
12245 +#endif
12246 +
12247 +/*
12248 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12249 + pkg->epoch,
12250 + pkg->version,
12251 + pkg->revision,
12252 + pkg->familiar_revision);
12253 +*/
12254 +
12255 + return 0;
12256 +}
12257 +
12258 +
12259 +/* This code is needed to insert in first position the keyword for the aligning bug */
12260 +
12261 +int alterProvidesLine(char *raw, char *temp)
12262 +{
12263 +
12264 +
12265 + if (!*raw) {
12266 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12267 + return -EINVAL;
12268 + }
12269 +
12270 + if ( temp == NULL ) {
12271 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12272 + return -ENOMEM;
12273 + }
12274 +
12275 + if (strncmp(raw, "Provides:", 9) == 0) {
12276 + raw += 9;
12277 + }
12278 + while (*raw && isspace(*raw)) {
12279 + raw++;
12280 + }
12281 +
12282 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12283 + while (*raw) {
12284 + strncat( temp, raw++, 1);
12285 + }
12286 + return 0;
12287 +
12288 +}
12289 +
12290 +/* Some random thoughts from Carl:
12291 +
12292 + This function could be considerably simplified if we just kept
12293 + an array of all the generic string-valued field names, and looped
12294 + through those looking for a match. Also, these fields could perhaps
12295 + be stored in the package as an array as well, (or, probably better,
12296 + as an nv_pair_list_t).
12297 +
12298 + Fields which require special parsing or storage, (such as Depends:
12299 + and Status:) could be handled as they are now.
12300 +*/
12301 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12302 + to a dependency list. And, since we already have
12303 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12304 + Enhances, perhaps we could generalize all of these and save some
12305 + code duplication.
12306 +*/
12307 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12308 +{
12309 + int reading_conffiles, reading_description;
12310 + int pkg_false_provides=1;
12311 + char ** lines;
12312 + char * provide=NULL;
12313 +
12314 + pkg->src = src;
12315 + pkg->dest = dest;
12316 +
12317 + reading_conffiles = reading_description = 0;
12318 +
12319 + for (lines = *raw; *lines; lines++) {
12320 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12321 + if(isGenericFieldType("Package:", *lines))
12322 + pkg->name = parseGenericFieldType("Package", *lines);
12323 + else if(isGenericFieldType("Architecture:", *lines))
12324 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12325 + else if(isGenericFieldType("Filename:", *lines))
12326 + pkg->filename = parseGenericFieldType("Filename", *lines);
12327 + else if(isGenericFieldType("Section:", *lines))
12328 + pkg->section = parseGenericFieldType("Section", *lines);
12329 + else if(isGenericFieldType("MD5sum:", *lines))
12330 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12331 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12332 + let's parse it either way */
12333 + else if(isGenericFieldType("MD5Sum:", *lines))
12334 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12335 + else if(isGenericFieldType("Size:", *lines))
12336 + pkg->size = parseGenericFieldType("Size", *lines);
12337 + else if(isGenericFieldType("Source:", *lines))
12338 + pkg->source = parseGenericFieldType("Source", *lines);
12339 + else if(isGenericFieldType("Installed-Size:", *lines))
12340 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12341 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12342 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12343 + pkg->installed_time = strtoul(time_str, NULL, 0);
12344 + } else if(isGenericFieldType("Priority:", *lines))
12345 + pkg->priority = parseGenericFieldType("Priority", *lines);
12346 + else if(isGenericFieldType("Essential:", *lines)) {
12347 + char *essential_value;
12348 + essential_value = parseGenericFieldType("Essential", *lines);
12349 + if (strcmp(essential_value, "yes") == 0) {
12350 + pkg->essential = 1;
12351 + }
12352 + free(essential_value);
12353 + }
12354 + else if(isGenericFieldType("Status", *lines))
12355 + parseStatus(pkg, *lines);
12356 + else if(isGenericFieldType("Version", *lines))
12357 + parseVersion(pkg, *lines);
12358 + else if(isGenericFieldType("Maintainer", *lines))
12359 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12360 + else if(isGenericFieldType("Conffiles", *lines)){
12361 + parseConffiles(pkg, *lines);
12362 + reading_conffiles = 1;
12363 + }
12364 + else if(isGenericFieldType("Description", *lines)) {
12365 + pkg->description = parseGenericFieldType("Description", *lines);
12366 + reading_conffiles = 0;
12367 + reading_description = 1;
12368 + }
12369 +
12370 + else if(isGenericFieldType("Provides", *lines)){
12371 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12372 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12373 + if ( alterProvidesLine(*lines,provide) ){
12374 + return EINVAL;
12375 + }
12376 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12377 +/* Let's try to hack a bit here.
12378 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12379 + in alot of other places. We will remove it before writing down the status database */
12380 + pkg_false_provides=0;
12381 + free(provide);
12382 + }
12383 +
12384 + else if(isGenericFieldType("Depends", *lines))
12385 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12386 + else if(isGenericFieldType("Pre-Depends", *lines))
12387 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12388 + else if(isGenericFieldType("Recommends", *lines))
12389 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12390 + else if(isGenericFieldType("Suggests", *lines))
12391 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12392 + /* Abhaya: support for conflicts */
12393 + else if(isGenericFieldType("Conflicts", *lines))
12394 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12395 + else if(isGenericFieldType("Replaces", *lines))
12396 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12397 + else if(line_is_blank(*lines)) {
12398 + lines++;
12399 + break;
12400 + }
12401 + else if(**lines == ' '){
12402 + if(reading_description) {
12403 + /* we already know it's not blank, so the rest of description */
12404 + pkg->description = realloc(pkg->description,
12405 + strlen(pkg->description)
12406 + + 1 + strlen(*lines) + 1);
12407 + strcat(pkg->description, "\n");
12408 + strcat(pkg->description, (*lines));
12409 + }
12410 + else if(reading_conffiles)
12411 + parseConffiles(pkg, *lines);
12412 + }
12413 + }
12414 + *raw = lines;
12415 +/* If the ipk has not a Provides line, we insert our false line */
12416 + if ( pkg_false_provides==1)
12417 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12418 +
12419 + if (pkg->name) {
12420 + return 0;
12421 + } else {
12422 + return EINVAL;
12423 + }
12424 +}
12425 +
12426 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12427 +{
12428 + char ** lines;
12429 +
12430 + for (lines = *raw; *lines; lines++) {
12431 + if(isGenericFieldType("Essential:", *lines)) {
12432 + char *essential_value;
12433 + essential_value = parseGenericFieldType("Essential", *lines);
12434 + if (strcmp(essential_value, "yes") == 0) {
12435 + pkg->essential = 1;
12436 + }
12437 + free(essential_value);
12438 + }
12439 + }
12440 + *raw = lines;
12441 +
12442 + return 0;
12443 +}
12444 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_parse.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h
12445 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12446 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-07-22 16:31:25.000000000 +0200
12447 @@ -0,0 +1,31 @@
12448 +/* pkg_parse.h - the itsy package management system
12449 +
12450 + Steven M. Ayer
12451 +
12452 + Copyright (C) 2002 Compaq Computer Corporation
12453 +
12454 + This program is free software; you can redistribute it and/or
12455 + modify it under the terms of the GNU General Public License as
12456 + published by the Free Software Foundation; either version 2, or (at
12457 + your option) any later version.
12458 +
12459 + This program is distributed in the hope that it will be useful, but
12460 + WITHOUT ANY WARRANTY; without even the implied warranty of
12461 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12462 + General Public License for more details.
12463 +*/
12464 +
12465 +#ifndef PKG_PARSE_H
12466 +#define PKG_PARSE_H
12467 +
12468 +int isGenericFieldType(char * type, char * line);
12469 +char * parseGenericFieldType(char * type, char * raw);
12470 +void parseStatus(pkg_t *pkg, char * raw);
12471 +int parseVersion(pkg_t *pkg, char *raw);
12472 +char ** parseDependsString(char * raw, int * depends_count);
12473 +int parseVersion(pkg_t *pkg, char *raw);
12474 +void parseConffiles(pkg_t * pkg, char * raw);
12475 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12476 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12477 +
12478 +#endif
12479 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c
12480 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12481 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-07-22 16:31:25.000000000 +0200
12482 @@ -0,0 +1,43 @@
12483 +/* pkg_src.c - the itsy package management system
12484 +
12485 + Carl D. Worth
12486 +
12487 + Copyright (C) 2001 University of Southern California
12488 +
12489 + This program is free software; you can redistribute it and/or
12490 + modify it under the terms of the GNU General Public License as
12491 + published by the Free Software Foundation; either version 2, or (at
12492 + your option) any later version.
12493 +
12494 + This program is distributed in the hope that it will be useful, but
12495 + WITHOUT ANY WARRANTY; without even the implied warranty of
12496 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12497 + General Public License for more details.
12498 +*/
12499 +
12500 +#include "ipkg.h"
12501 +
12502 +#include "pkg_src.h"
12503 +#include "str_util.h"
12504 +
12505 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12506 +{
12507 + src->gzip = gzip;
12508 + src->name = str_dup_safe (name);
12509 + src->value = str_dup_safe (base_url);
12510 + if (extra_data)
12511 + src->extra_data = str_dup_safe (extra_data);
12512 + else
12513 + src->extra_data = NULL;
12514 + return 0;
12515 +}
12516 +
12517 +void pkg_src_deinit(pkg_src_t *src)
12518 +{
12519 + free (src->name);
12520 + free (src->value);
12521 + if (src->extra_data)
12522 + free (src->extra_data);
12523 +}
12524 +
12525 +
12526 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h
12527 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12528 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-07-22 16:31:25.000000000 +0200
12529 @@ -0,0 +1,34 @@
12530 +/* pkg_src.h - the itsy package management system
12531 +
12532 + Carl D. Worth
12533 +
12534 + Copyright (C) 2001 University of Southern California
12535 +
12536 + This program is free software; you can redistribute it and/or
12537 + modify it under the terms of the GNU General Public License as
12538 + published by the Free Software Foundation; either version 2, or (at
12539 + your option) any later version.
12540 +
12541 + This program is distributed in the hope that it will be useful, but
12542 + WITHOUT ANY WARRANTY; without even the implied warranty of
12543 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12544 + General Public License for more details.
12545 +*/
12546 +
12547 +#ifndef PKG_SRC_H
12548 +#define PKG_SRC_H
12549 +
12550 +#include "nv_pair.h"
12551 +
12552 +typedef struct
12553 +{
12554 + char *name;
12555 + char *value;
12556 + char *extra_data;
12557 + int gzip;
12558 +} pkg_src_t;
12559 +
12560 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12561 +void pkg_src_deinit(pkg_src_t *src);
12562 +
12563 +#endif
12564 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c
12565 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12566 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-07-22 16:31:25.000000000 +0200
12567 @@ -0,0 +1,75 @@
12568 +/* pkg_src_list.c - the itsy package management system
12569 +
12570 + Carl D. Worth
12571 +
12572 + Copyright (C) 2001 University of Southern California
12573 +
12574 + This program is free software; you can redistribute it and/or
12575 + modify it under the terms of the GNU General Public License as
12576 + published by the Free Software Foundation; either version 2, or (at
12577 + your option) any later version.
12578 +
12579 + This program is distributed in the hope that it will be useful, but
12580 + WITHOUT ANY WARRANTY; without even the implied warranty of
12581 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12582 + General Public License for more details.
12583 +*/
12584 +
12585 +#include "ipkg.h"
12586 +
12587 +#include "pkg_src_list.h"
12588 +#include "void_list.h"
12589 +
12590 +int pkg_src_list_init(pkg_src_list_t *list)
12591 +{
12592 + return void_list_init((void_list_t *) list);
12593 +}
12594 +
12595 +void pkg_src_list_deinit(pkg_src_list_t *list)
12596 +{
12597 + pkg_src_list_elt_t *iter;
12598 + pkg_src_t *pkg_src;
12599 +
12600 + for (iter = list->head; iter; iter = iter->next) {
12601 + pkg_src = iter->data;
12602 + pkg_src_deinit(pkg_src);
12603 +
12604 + /* malloced in pkg_src_list_append */
12605 + free(pkg_src);
12606 + iter->data = NULL;
12607 + }
12608 + void_list_deinit((void_list_t *) list);
12609 +}
12610 +
12611 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12612 + const char *name, const char *base_url, const char *extra_data,
12613 + int gzip)
12614 +{
12615 + int err;
12616 +
12617 + /* freed in pkg_src_list_deinit */
12618 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12619 +
12620 + if (pkg_src == NULL) {
12621 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12622 + return NULL;
12623 + }
12624 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12625 +
12626 + err = void_list_append((void_list_t *) list, pkg_src);
12627 + if (err) {
12628 + return NULL;
12629 + }
12630 +
12631 + return pkg_src;
12632 +}
12633 +
12634 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12635 +{
12636 + return void_list_push((void_list_t *) list, data);
12637 +}
12638 +
12639 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12640 +{
12641 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12642 +}
12643 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h
12644 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12645 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-07-22 16:31:25.000000000 +0200
12646 @@ -0,0 +1,57 @@
12647 +/* pkg_src_list.h - the itsy package management system
12648 +
12649 + Carl D. Worth
12650 +
12651 + Copyright (C) 2001 University of Southern California
12652 +
12653 + This program is free software; you can redistribute it and/or
12654 + modify it under the terms of the GNU General Public License as
12655 + published by the Free Software Foundation; either version 2, or (at
12656 + your option) any later version.
12657 +
12658 + This program is distributed in the hope that it will be useful, but
12659 + WITHOUT ANY WARRANTY; without even the implied warranty of
12660 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12661 + General Public License for more details.
12662 +*/
12663 +
12664 +#ifndef PKG_SRC_LIST_H
12665 +#define PKG_SRC_LIST_H
12666 +
12667 +#include "pkg_src.h"
12668 +
12669 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12670 +struct pkg_src_list_elt
12671 +{
12672 + pkg_src_list_elt_t *next;
12673 + pkg_src_t *data;
12674 +};
12675 +
12676 +typedef struct pkg_src_list pkg_src_list_t;
12677 +struct pkg_src_list
12678 +{
12679 + pkg_src_list_elt_t pre_head;
12680 + pkg_src_list_elt_t *head;
12681 + pkg_src_list_elt_t *tail;
12682 +};
12683 +
12684 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12685 +{
12686 + if (list->head == NULL)
12687 + return 1;
12688 + else
12689 + return 0;
12690 +}
12691 +
12692 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12693 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12694 +
12695 +int pkg_src_list_init(pkg_src_list_t *list);
12696 +void pkg_src_list_deinit(pkg_src_list_t *list);
12697 +
12698 +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);
12699 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12700 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12701 +
12702 +#endif
12703 +
12704 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_vec.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c
12705 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12706 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-07-22 16:31:26.000000000 +0200
12707 @@ -0,0 +1,230 @@
12708 +/* pkg_vec.c - the itsy package management system
12709 +
12710 + Steven M. Ayer
12711 +
12712 + Copyright (C) 2002 Compaq Computer Corporation
12713 +
12714 + This program is free software; you can redistribute it and/or
12715 + modify it under the terms of the GNU General Public License as
12716 + published by the Free Software Foundation; either version 2, or (at
12717 + your option) any later version.
12718 +
12719 + This program is distributed in the hope that it will be useful, but
12720 + WITHOUT ANY WARRANTY; without even the implied warranty of
12721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12722 + General Public License for more details.
12723 +*/
12724 +
12725 +#include <stdlib.h>
12726 +#include <fnmatch.h>
12727 +#include "xregex.h"
12728 +#include "ipkg.h"
12729 +#include "pkg.h"
12730 +
12731 +pkg_vec_t * pkg_vec_alloc(void)
12732 +{
12733 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12734 + if (!vec) {
12735 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12736 + return NULL;
12737 + }
12738 + vec->pkgs = NULL;
12739 + vec->len = 0;
12740 +
12741 + return vec;
12742 +}
12743 +
12744 +void pkg_vec_free(pkg_vec_t *vec)
12745 +{
12746 + free(vec->pkgs);
12747 + free(vec);
12748 +}
12749 +
12750 +/*
12751 + * assumption: all names in a vector are identical
12752 + * assumption: all version strings are trimmed,
12753 + * so identical versions have identical version strings,
12754 + * implying identical packages; let's marry these
12755 + */
12756 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12757 +{
12758 + int i;
12759 + int found = 0;
12760 +
12761 + /* look for a duplicate pkg by name, version, and architecture */
12762 + for (i = 0; i < vec->len; i++){
12763 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12764 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12765 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12766 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12767 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12768 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12769 + found = 1;
12770 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12771 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12772 + break;
12773 + }
12774 + }
12775 +
12776 + /* we didn't find one, add it */
12777 + if (!found){
12778 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12779 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12780 +
12781 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12782 + vec->pkgs[vec->len] = pkg;
12783 + vec->len++;
12784 + return pkg;
12785 + }
12786 + /* update the one that we have */
12787 + else {
12788 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12789 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12790 + if (set_status) {
12791 + /* this is from the status file, so need to merge with existing database */
12792 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12793 + pkg_merge(vec->pkgs[i], pkg, set_status);
12794 + /* XXX: CLEANUP: It's not so polite to free something here
12795 + that was passed in from above. */
12796 + pkg_deinit(pkg);
12797 + free(pkg);
12798 + } else {
12799 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12800 + /* just overwrite the old one */
12801 + pkg_deinit(vec->pkgs[i]);
12802 + free(vec->pkgs[i]);
12803 + vec->pkgs[i] = pkg;
12804 + }
12805 + return vec->pkgs[i];
12806 + }
12807 +}
12808 +
12809 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12810 +{
12811 + int i;
12812 + int found = 0;
12813 +
12814 + /* look for a duplicate pkg by name, version, and architecture */
12815 + for (i = 0; i < vec->len; i++)
12816 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12817 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12818 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12819 + found = 1;
12820 + break;
12821 + }
12822 +
12823 + /* we didn't find one, add it */
12824 + if(!found){
12825 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12826 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12827 + vec->len++;
12828 + }
12829 +}
12830 +
12831 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12832 +{
12833 + int i;
12834 + for (i = 0; i < vec->len; i++)
12835 + if (vec->pkgs[i] == apkg)
12836 + return 1;
12837 + return 0;
12838 +}
12839 +
12840 +typedef int (*compare_fcn_t)(const void *, const void *);
12841 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12842 +{
12843 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12844 +}
12845 +
12846 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12847 +{
12848 + int npkgs = vec->len;
12849 + int i;
12850 + for (i = 0; i < npkgs; i++) {
12851 + pkg_t *pkg = vec->pkgs[i];
12852 + pkg->state_flag &= ~SF_MARKED;
12853 + }
12854 + return 0;
12855 +}
12856 +
12857 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12858 +{
12859 + int matching_count = 0;
12860 + pkg_t **pkgs = vec->pkgs;
12861 + int npkgs = vec->len;
12862 + int i;
12863 + for (i = 0; i < npkgs; i++) {
12864 + pkg_t *pkg = pkgs[i];
12865 + if (fnmatch(pattern, pkg->name, 0)==0) {
12866 + pkg->state_flag |= SF_MARKED;
12867 + matching_count++;
12868 + }
12869 + }
12870 + return matching_count;
12871 +}
12872 +
12873 +
12874 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12875 +{
12876 + abstract_pkg_vec_t * vec ;
12877 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12878 + if (!vec) {
12879 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12880 + return NULL;
12881 + }
12882 + vec->pkgs = NULL;
12883 + vec->len = 0;
12884 +
12885 + return vec;
12886 +}
12887 +
12888 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12889 +{
12890 + free(vec->pkgs);
12891 + free(vec);
12892 +}
12893 +
12894 +/*
12895 + * assumption: all names in a vector are unique
12896 + */
12897 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12898 +{
12899 + int i;
12900 +
12901 + /* look for a duplicate pkg by name */
12902 + for(i = 0; i < vec->len; i++)
12903 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12904 + break;
12905 +
12906 + /* we didn't find one, add it */
12907 + if(i == vec->len){
12908 + vec->pkgs =
12909 + (abstract_pkg_t **)
12910 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12911 + vec->pkgs[vec->len] = pkg;
12912 + vec->len++;
12913 + }
12914 +}
12915 +
12916 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12917 +{
12918 + if (vec->len > i)
12919 + return vec->pkgs[i];
12920 + else
12921 + return NULL;
12922 +}
12923 +
12924 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12925 +{
12926 + int i;
12927 + for (i = 0; i < vec->len; i++)
12928 + if (vec->pkgs[i] == apkg)
12929 + return 1;
12930 + return 0;
12931 +}
12932 +
12933 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12934 +{
12935 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12936 +}
12937 +
12938 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_vec.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h
12939 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12940 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-07-22 16:31:26.000000000 +0200
12941 @@ -0,0 +1,62 @@
12942 +/* pkg_vec.h - the itsy package management system
12943 +
12944 + Steven M. Ayer
12945 +
12946 + Copyright (C) 2002 Compaq Computer Corporation
12947 +
12948 + This program is free software; you can redistribute it and/or
12949 + modify it under the terms of the GNU General Public License as
12950 + published by the Free Software Foundation; either version 2, or (at
12951 + your option) any later version.
12952 +
12953 + This program is distributed in the hope that it will be useful, but
12954 + WITHOUT ANY WARRANTY; without even the implied warranty of
12955 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12956 + General Public License for more details.
12957 +*/
12958 +
12959 +#ifndef PKG_VEC_H
12960 +#define PKG_VEC_H
12961 +
12962 +typedef struct pkg pkg_t;
12963 +typedef struct abstract_pkg abstract_pkg_t;
12964 +
12965 +struct pkg_vec
12966 +{
12967 + pkg_t **pkgs;
12968 + int len;
12969 +};
12970 +typedef struct pkg_vec pkg_vec_t;
12971 +
12972 +struct abstract_pkg_vec
12973 +{
12974 + abstract_pkg_t **pkgs;
12975 + int len;
12976 +};
12977 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12978 +
12979 +
12980 +pkg_vec_t * pkg_vec_alloc(void);
12981 +void pkg_vec_free(pkg_vec_t *vec);
12982 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12983 +
12984 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12985 +/* pkg_vec_insert_merge: might munge pkg.
12986 +* returns the pkg that is in the pkg graph */
12987 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12988 +/* this one never munges pkg */
12989 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12990 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12991 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12992 +
12993 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12994 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12995 +
12996 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12997 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12998 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12999 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13000 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13001 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13002 +#endif
13003 +
13004 diff -ruN busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h
13005 --- busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13006 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-07-22 16:31:26.000000000 +0200
13007 @@ -0,0 +1,25 @@
13008 +/* sprintf_alloca.c -- like sprintf with memory allocation
13009 +
13010 + Carl D. Worth
13011 +
13012 + Copyright (C) 2001 University of Southern California
13013 +
13014 + This program is free software; you can redistribute it and/or modify
13015 + it under the terms of the GNU General Public License as published by
13016 + the Free Software Foundation; either version 2, or (at your option)
13017 + any later version.
13018 +
13019 + This program is distributed in the hope that it will be useful,
13020 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13021 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13022 + GNU General Public License for more details.
13023 +*/
13024 +
13025 +#ifndef SPRINTF_ALLOC_H
13026 +#define SPRINTF_ALLOC_H
13027 +
13028 +#include "libbb.h"
13029 +
13030 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13031 +
13032 +#endif
13033 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c
13034 --- busybox-1.2.0-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13035 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c 2006-07-22 16:31:26.000000000 +0200
13036 @@ -0,0 +1,76 @@
13037 +/* str_list.c - the itsy package management system
13038 +
13039 + Carl D. Worth
13040 +
13041 + Copyright (C) 2001 University of Southern California
13042 +
13043 + This program is free software; you can redistribute it and/or
13044 + modify it under the terms of the GNU General Public License as
13045 + published by the Free Software Foundation; either version 2, or (at
13046 + your option) any later version.
13047 +
13048 + This program is distributed in the hope that it will be useful, but
13049 + WITHOUT ANY WARRANTY; without even the implied warranty of
13050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13051 + General Public License for more details.
13052 +*/
13053 +
13054 +#include "ipkg.h"
13055 +
13056 +#include "str_list.h"
13057 +
13058 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13059 +{
13060 + return void_list_elt_init((void_list_elt_t *) elt, data);
13061 +}
13062 +
13063 +void str_list_elt_deinit(str_list_elt_t *elt)
13064 +{
13065 + void_list_elt_deinit((void_list_elt_t *) elt);
13066 +}
13067 +
13068 +str_list_t *str_list_alloc()
13069 +{
13070 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13071 + if (list)
13072 + str_list_init(list);
13073 + return list;
13074 +}
13075 +
13076 +int str_list_init(str_list_t *list)
13077 +{
13078 + return void_list_init((void_list_t *) list);
13079 +}
13080 +
13081 +void str_list_deinit(str_list_t *list)
13082 +{
13083 + void_list_deinit((void_list_t *) list);
13084 +}
13085 +
13086 +int str_list_append(str_list_t *list, char *data)
13087 +{
13088 + return void_list_append((void_list_t *) list, data);
13089 +}
13090 +
13091 +int str_list_push(str_list_t *list, char *data)
13092 +{
13093 + return void_list_push((void_list_t *) list, data);
13094 +}
13095 +
13096 +str_list_elt_t *str_list_pop(str_list_t *list)
13097 +{
13098 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13099 +}
13100 +
13101 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13102 +{
13103 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13104 + (void_list_elt_t **) iter);
13105 +}
13106 +
13107 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13108 +{
13109 + return (char *)void_list_remove_elt((void_list_t *) list,
13110 + (void *)target_str,
13111 + (void_list_cmp_t)strcmp);
13112 +}
13113 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h
13114 --- busybox-1.2.0-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13115 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h 2006-07-22 16:31:26.000000000 +0200
13116 @@ -0,0 +1,51 @@
13117 +/* str_list.h - the itsy package management system
13118 +
13119 + Carl D. Worth
13120 +
13121 + Copyright (C) 2001 University of Southern California
13122 +
13123 + This program is free software; you can redistribute it and/or
13124 + modify it under the terms of the GNU General Public License as
13125 + published by the Free Software Foundation; either version 2, or (at
13126 + your option) any later version.
13127 +
13128 + This program is distributed in the hope that it will be useful, but
13129 + WITHOUT ANY WARRANTY; without even the implied warranty of
13130 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13131 + General Public License for more details.
13132 +*/
13133 +
13134 +#ifndef STR_LIST_H
13135 +#define STR_LIST_H
13136 +
13137 +#include "void_list.h"
13138 +
13139 +typedef struct str_list_elt str_list_elt_t;
13140 +struct str_list_elt
13141 +{
13142 + str_list_elt_t *next;
13143 + char *data;
13144 +};
13145 +
13146 +typedef struct xstr_list str_list_t;
13147 +struct xstr_list
13148 +{
13149 + str_list_elt_t pre_head;
13150 + str_list_elt_t *head;
13151 + str_list_elt_t *tail;
13152 +};
13153 +
13154 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13155 +void str_list_elt_deinit(str_list_elt_t *elt);
13156 +
13157 +str_list_t *str_list_alloc(void);
13158 +int str_list_init(str_list_t *list);
13159 +void str_list_deinit(str_list_t *list);
13160 +
13161 +int str_list_append(str_list_t *list, char *data);
13162 +int str_list_push(str_list_t *list, char *data);
13163 +str_list_elt_t *str_list_pop(str_list_t *list);
13164 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13165 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13166 +
13167 +#endif
13168 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_util.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c
13169 --- busybox-1.2.0-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13170 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c 2006-07-22 16:31:26.000000000 +0200
13171 @@ -0,0 +1,73 @@
13172 +/* str_utils.c - the itsy package management system
13173 +
13174 + Carl D. Worth
13175 +
13176 + Copyright (C) 2001 University of Southern California
13177 +
13178 + This program is free software; you can redistribute it and/or
13179 + modify it under the terms of the GNU General Public License as
13180 + published by the Free Software Foundation; either version 2, or (at
13181 + your option) any later version.
13182 +
13183 + This program is distributed in the hope that it will be useful, but
13184 + WITHOUT ANY WARRANTY; without even the implied warranty of
13185 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13186 + General Public License for more details.
13187 +*/
13188 +
13189 +#include "ipkg.h"
13190 +
13191 +int str_starts_with(const char *str, const char *prefix)
13192 +{
13193 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13194 +}
13195 +
13196 +int str_ends_with(const char *str, const char *suffix)
13197 +{
13198 + int suffix_len;
13199 + int str_len;
13200 +
13201 + str_len = strlen(str);
13202 + suffix_len = strlen(suffix);
13203 +
13204 + if (str_len < suffix_len) {
13205 + return 0;
13206 + }
13207 +
13208 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13209 +}
13210 +
13211 +int str_chomp(char *str)
13212 +{
13213 + if (str[strlen(str) - 1] == '\n') {
13214 + str[strlen(str) - 1] = '\0';
13215 + return 1;
13216 + }
13217 + return 0;
13218 +}
13219 +
13220 +int str_tolower(char *str)
13221 +{
13222 + while (*str) {
13223 + *str = tolower(*str);
13224 + str++;
13225 + }
13226 +
13227 + return 0;
13228 +}
13229 +
13230 +int str_toupper(char *str)
13231 +{
13232 + while (*str) {
13233 + *str = toupper(*str);
13234 + str++;
13235 + }
13236 +
13237 + return 0;
13238 +}
13239 +
13240 +char *str_dup_safe(const char *str)
13241 +{
13242 + return str ? strdup(str) : NULL;
13243 +}
13244 +
13245 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_util.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h
13246 --- busybox-1.2.0-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13247 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h 2006-07-22 16:31:26.000000000 +0200
13248 @@ -0,0 +1,28 @@
13249 +/* str_utils.h - the itsy package management system
13250 +
13251 + Carl D. Worth
13252 +
13253 + Copyright (C) 2001 University of Southern California
13254 +
13255 + This program is free software; you can redistribute it and/or
13256 + modify it under the terms of the GNU General Public License as
13257 + published by the Free Software Foundation; either version 2, or (at
13258 + your option) any later version.
13259 +
13260 + This program is distributed in the hope that it will be useful, but
13261 + WITHOUT ANY WARRANTY; without even the implied warranty of
13262 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13263 + General Public License for more details.
13264 +*/
13265 +
13266 +#ifndef STR_UTILS_H
13267 +#define STR_UTILS_H
13268 +
13269 +int str_starts_with(const char *str, const char *prefix);
13270 +int str_ends_with(const char *str, const char *suffix);
13271 +int str_chomp(char *str);
13272 +int str_tolower(char *str);
13273 +int str_toupper(char *str);
13274 +char *str_dup_safe(const char *str);
13275 +
13276 +#endif
13277 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c
13278 --- busybox-1.2.0-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13279 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c 2006-07-22 16:31:26.000000000 +0200
13280 @@ -0,0 +1,58 @@
13281 +/* user.c - the itsy package management system
13282 +
13283 + Jamey Hicks
13284 +
13285 + Copyright (C) 2002 Hewlett Packard Company
13286 + Copyright (C) 2001 University of Southern California
13287 +
13288 + This program is free software; you can redistribute it and/or
13289 + modify it under the terms of the GNU General Public License as
13290 + published by the Free Software Foundation; either version 2, or (at
13291 + your option) any later version.
13292 +
13293 + This program is distributed in the hope that it will be useful, but
13294 + WITHOUT ANY WARRANTY; without even the implied warranty of
13295 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13296 + General Public License for more details.
13297 +*/
13298 +
13299 +#include <stdio.h>
13300 +#include <stdarg.h>
13301 +#include "file_util.h"
13302 +#include "str_util.h"
13303 +#ifdef IPKG_LIB
13304 +#include "libipkg.h"
13305 +#endif
13306 +
13307 +
13308 +#ifdef IPKG_LIB
13309 +static char *question = NULL;
13310 +static int question_len = 255;
13311 +#endif
13312 +char *get_user_response(const char *format, ...)
13313 +{
13314 + int len = question_len;
13315 + va_list ap;
13316 + char *response;
13317 + va_start(ap, format);
13318 +
13319 +#ifndef IPKG_LIB
13320 + vprintf(format, ap);
13321 + do {
13322 + response = file_read_line_alloc(stdin);
13323 + } while (response == NULL);
13324 +#else
13325 + do {
13326 + if (question == NULL || len > question_len) {
13327 + question = realloc(question, len + 1);
13328 + question_len = len;
13329 + }
13330 + len = vsnprintf(question,question_len,format,ap);
13331 + } while (len > question_len);
13332 + response = strdup(ipkg_cb_response(question));
13333 +#endif
13334 + str_chomp(response);
13335 + str_tolower(response);
13336 +
13337 + return response;
13338 +}
13339 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h
13340 --- busybox-1.2.0-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13341 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h 2006-07-22 16:31:26.000000000 +0200
13342 @@ -0,0 +1,23 @@
13343 +/* user.c - the itsy package management system
13344 +
13345 + Jamey Hicks
13346 +
13347 + Copyright (C) 2002 Hewlett Packard Company
13348 + Copyright (C) 2001 University of Southern California
13349 +
13350 + This program is free software; you can redistribute it and/or
13351 + modify it under the terms of the GNU General Public License as
13352 + published by the Free Software Foundation; either version 2, or (at
13353 + your option) any later version.
13354 +
13355 + This program is distributed in the hope that it will be useful, but
13356 + WITHOUT ANY WARRANTY; without even the implied warranty of
13357 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13358 + General Public License for more details.
13359 +*/
13360 +
13361 +#include <stdio.h>
13362 +#include <stdarg.h>
13363 +
13364 +char *get_user_response(const char *format, ...);
13365 +
13366 diff -ruN busybox-1.2.0-orig/archival/libipkg/void_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c
13367 --- busybox-1.2.0-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13368 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c 2006-07-22 16:31:26.000000000 +0200
13369 @@ -0,0 +1,194 @@
13370 +/* void_list.c - the itsy package management system
13371 +
13372 + Carl D. Worth
13373 +
13374 + Copyright (C) 2001 University of Southern California
13375 +
13376 + This program is free software; you can redistribute it and/or
13377 + modify it under the terms of the GNU General Public License as
13378 + published by the Free Software Foundation; either version 2, or (at
13379 + your option) any later version.
13380 +
13381 + This program is distributed in the hope that it will be useful, but
13382 + WITHOUT ANY WARRANTY; without even the implied warranty of
13383 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13384 + General Public License for more details.
13385 +*/
13386 +
13387 +#include "ipkg.h"
13388 +#include <errno.h>
13389 +
13390 +#include "void_list.h"
13391 +
13392 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13393 +{
13394 + elt->next = NULL;
13395 + elt->data = data;
13396 +
13397 + return 0;
13398 +}
13399 +
13400 +void void_list_elt_deinit(void_list_elt_t *elt)
13401 +{
13402 + void_list_elt_init(elt, NULL);
13403 +}
13404 +
13405 +int void_list_init(void_list_t *list)
13406 +{
13407 + void_list_elt_init(&list->pre_head, NULL);
13408 + list->head = NULL;
13409 + list->pre_head.next = list->head;
13410 + list->tail = NULL;
13411 +
13412 + return 0;
13413 +}
13414 +
13415 +void void_list_deinit(void_list_t *list)
13416 +{
13417 + void_list_elt_t *elt;
13418 +
13419 + while (list->head) {
13420 + elt = void_list_pop(list);
13421 + void_list_elt_deinit(elt);
13422 + /* malloced in void_list_append */
13423 + free(elt);
13424 + }
13425 +}
13426 +
13427 +int void_list_append(void_list_t *list, void *data)
13428 +{
13429 + void_list_elt_t *elt;
13430 +
13431 + /* freed in void_list_deinit */
13432 + elt = malloc(sizeof(void_list_elt_t));
13433 + if (elt == NULL) {
13434 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13435 + return ENOMEM;
13436 + }
13437 +
13438 + void_list_elt_init(elt, data);
13439 +
13440 + if (list->tail) {
13441 + list->tail->next = elt;
13442 + list->tail = elt;
13443 + } else {
13444 + list->head = elt;
13445 + list->pre_head.next = list->head;
13446 + list->tail = elt;
13447 + }
13448 +
13449 + return 0;
13450 +}
13451 +
13452 +int void_list_push(void_list_t *list, void *data)
13453 +{
13454 + void_list_elt_t *elt;
13455 +
13456 + elt = malloc(sizeof(void_list_elt_t));
13457 + if (elt == NULL) {
13458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13459 + return ENOMEM;
13460 + }
13461 +
13462 + void_list_elt_init(elt, data);
13463 +
13464 + elt->next = list->head;
13465 + list->head->next = elt;
13466 + if (list->tail == NULL) {
13467 + list->tail = list->head;
13468 + }
13469 +
13470 + return 0;
13471 +}
13472 +
13473 +void_list_elt_t *void_list_pop(void_list_t *list)
13474 +{
13475 + void_list_elt_t *elt;
13476 +
13477 + elt = list->head;
13478 +
13479 + if (list->head) {
13480 + list->head = list->head->next;
13481 + list->pre_head.next = list->head;
13482 + if (list->head == NULL) {
13483 + list->tail = NULL;
13484 + }
13485 + }
13486 +
13487 + return elt;
13488 +}
13489 +
13490 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13491 +{
13492 + void_list_elt_t *prior;
13493 + void_list_elt_t *old_elt;
13494 + void *old_data;
13495 +
13496 + old_elt = *iter;
13497 + old_data = old_elt->data;
13498 +
13499 + if (old_elt == list->head) {
13500 + prior = &list->pre_head;
13501 + void_list_pop(list);
13502 + } else {
13503 + for (prior = list->head; prior; prior = prior->next) {
13504 + if (prior->next == old_elt) {
13505 + break;
13506 + }
13507 + }
13508 + if (prior == NULL || prior->next != old_elt) {
13509 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13510 + return NULL;
13511 + }
13512 + prior->next = old_elt->next;
13513 +
13514 + if (old_elt == list->tail) {
13515 + list->tail = prior;
13516 + }
13517 + }
13518 +
13519 + void_list_elt_deinit(old_elt);
13520 + *iter = prior;
13521 +
13522 + return old_data;
13523 +}
13524 +
13525 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13526 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13527 +{
13528 + void_list_elt_t *prior;
13529 + void_list_elt_t *old_elt = NULL;
13530 + void *old_data = NULL;
13531 +
13532 + /* first element */
13533 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13534 + old_elt = list->head;
13535 + old_data = list->head->data;
13536 + void_list_pop(list);
13537 + } else {
13538 + int found = 0;
13539 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13540 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13541 + old_elt = prior->next;
13542 + old_data = old_elt->data;
13543 + found = 1;
13544 + break;
13545 + }
13546 + }
13547 + if (!found) {
13548 + return NULL;
13549 + }
13550 + prior->next = old_elt->next;
13551 +
13552 + if (old_elt == list->tail) {
13553 + list->tail = prior;
13554 + }
13555 + }
13556 + if (old_elt)
13557 + void_list_elt_deinit(old_elt);
13558 +
13559 + if (old_data)
13560 + return old_data;
13561 + else
13562 + return NULL;
13563 +}
13564 diff -ruN busybox-1.2.0-orig/archival/libipkg/void_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h
13565 --- busybox-1.2.0-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13566 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h 2006-07-22 16:31:26.000000000 +0200
13567 @@ -0,0 +1,59 @@
13568 +/* void_list.h - the itsy package management system
13569 +
13570 + Carl D. Worth
13571 +
13572 + Copyright (C) 2001 University of Southern California
13573 +
13574 + This program is free software; you can redistribute it and/or
13575 + modify it under the terms of the GNU General Public License as
13576 + published by the Free Software Foundation; either version 2, or (at
13577 + your option) any later version.
13578 +
13579 + This program is distributed in the hope that it will be useful, but
13580 + WITHOUT ANY WARRANTY; without even the implied warranty of
13581 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13582 + General Public License for more details.
13583 +*/
13584 +
13585 +#ifndef VOID_LIST_H
13586 +#define VOID_LIST_H
13587 +
13588 +typedef struct void_list_elt void_list_elt_t;
13589 +struct void_list_elt
13590 +{
13591 + void_list_elt_t *next;
13592 + void *data;
13593 +};
13594 +
13595 +typedef struct void_list void_list_t;
13596 +struct void_list
13597 +{
13598 + void_list_elt_t pre_head;
13599 + void_list_elt_t *head;
13600 + void_list_elt_t *tail;
13601 +};
13602 +
13603 +static inline int void_list_empty(void_list_t *list)
13604 +{
13605 + if (list->head == NULL)
13606 + return 1;
13607 + else
13608 + return 0;
13609 +}
13610 +
13611 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13612 +void void_list_elt_deinit(void_list_elt_t *elt);
13613 +
13614 +int void_list_init(void_list_t *list);
13615 +void void_list_deinit(void_list_t *list);
13616 +
13617 +int void_list_append(void_list_t *list, void *data);
13618 +int void_list_push(void_list_t *list, void *data);
13619 +void_list_elt_t *void_list_pop(void_list_t *list);
13620 +
13621 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13622 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13623 +typedef int (*void_list_cmp_t)(const void *, const void *);
13624 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13625 +
13626 +#endif
13627 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c
13628 --- busybox-1.2.0-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13629 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-07-22 16:31:26.000000000 +0200
13630 @@ -0,0 +1,64 @@
13631 +/* xsystem.c - system(3) with error messages
13632 +
13633 + Carl D. Worth
13634 +
13635 + Copyright (C) 2001 University of Southern California
13636 +
13637 + This program is free software; you can redistribute it and/or
13638 + modify it under the terms of the GNU General Public License as
13639 + published by the Free Software Foundation; either version 2, or (at
13640 + your option) any later version.
13641 +
13642 + This program is distributed in the hope that it will be useful, but
13643 + WITHOUT ANY WARRANTY; without even the implied warranty of
13644 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13645 + General Public License for more details.
13646 +*/
13647 +
13648 +#include "ipkg.h"
13649 +#include <sys/wait.h>
13650 +
13651 +#include "xsystem.h"
13652 +
13653 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13654 + really need the /bin/sh invocation which takes resources and
13655 + introduces security problems. I should switch all of this to a sort
13656 + of execl() or execv() interface/implementation.
13657 +*/
13658 +
13659 +/* Like system(3), but with error messages printed if the fork fails
13660 + or if the child process dies due to an uncaught signal. Also, the
13661 + return value is a bit simpler:
13662 +
13663 + -1 if there was any problem
13664 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13665 + as defined in <sys/wait.h>.
13666 +*/
13667 +int xsystem(const char *cmd)
13668 +{
13669 + int err;
13670 +
13671 + err = system(cmd);
13672 +
13673 + if (err == -1) {
13674 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13675 + __FUNCTION__, cmd);
13676 + return -1;
13677 + }
13678 +
13679 + if (WIFSIGNALED(err)) {
13680 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13681 + __FUNCTION__, WTERMSIG(err), cmd);
13682 + return -1;
13683 + }
13684 +
13685 + if (WIFEXITED(err)) {
13686 + /* Normal child exit */
13687 + return WEXITSTATUS(err);
13688 + }
13689 +
13690 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13691 + __FUNCTION__, err);
13692 + return -1;
13693 +}
13694 +
13695 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h
13696 --- busybox-1.2.0-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13697 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-07-22 16:31:26.000000000 +0200
13698 @@ -0,0 +1,34 @@
13699 +/* xsystem.h - system(3) with error messages
13700 +
13701 + Carl D. Worth
13702 +
13703 + Copyright (C) 2001 University of Southern California
13704 +
13705 + This program is free software; you can redistribute it and/or
13706 + modify it under the terms of the GNU General Public License as
13707 + published by the Free Software Foundation; either version 2, or (at
13708 + your option) any later version.
13709 +
13710 + This program is distributed in the hope that it will be useful, but
13711 + WITHOUT ANY WARRANTY; without even the implied warranty of
13712 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13713 + General Public License for more details.
13714 +*/
13715 +
13716 +#ifndef XSYSTEM_H
13717 +#define XSYSTEM_H
13718 +
13719 +#include <stdlib.h>
13720 +
13721 +/* Like system(3), but with error messages printed if the fork fails
13722 + or if the child process dies due to an uncaught signal. Also, the
13723 + return value is a bit simpler:
13724 +
13725 + -1 if there was any problem
13726 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13727 + as defined in <sys/wait.h>.
13728 +*/
13729 +int xsystem(const char *cmd);
13730 +
13731 +#endif
13732 +
13733 diff -ruN busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c
13734 --- busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c 2006-07-01 00:42:04.000000000 +0200
13735 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-07-22 16:31:26.000000000 +0200
13736 @@ -126,3 +126,17 @@
13737 utime(file_header->name, &t);
13738 }
13739 }
13740 +
13741 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13742 +{
13743 + char *name_ptr = archive_handle->file_header->name;
13744 +
13745 + name_ptr += strspn(name_ptr, "./");
13746 + if (name_ptr[0] != '\0') {
13747 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13748 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13749 + strcat(archive_handle->file_header->name, name_ptr);
13750 + data_extract_all(archive_handle);
13751 + }
13752 +}
13753 +
13754 diff -ruN busybox-1.2.0-orig/archival/libunarchive/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in
13755 --- busybox-1.2.0-orig/archival/libunarchive/Makefile.in 2006-07-01 00:42:03.000000000 +0200
13756 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-07-22 16:31:26.000000000 +0200
13757 @@ -58,6 +58,7 @@
13758 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13759 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13760 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13761 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13762 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13763 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13764 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13765 diff -ruN busybox-1.2.0-orig/archival/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in
13766 --- busybox-1.2.0-orig/archival/Makefile.in 2006-07-01 00:42:04.000000000 +0200
13767 +++ busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in 2006-07-22 16:31:25.000000000 +0200
13768 @@ -20,6 +20,7 @@
13769 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
13770 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
13771 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
13772 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
13773 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
13774 ARCHIVAL-$(CONFIG_RPM) += rpm.o
13775 ARCHIVAL-$(CONFIG_TAR) += tar.o
13776 diff -ruN busybox-1.2.0-orig/include/applets.h busybox-1.2.0+ipkg-0.99.162/include/applets.h
13777 --- busybox-1.2.0-orig/include/applets.h 2006-07-01 00:42:10.000000000 +0200
13778 +++ busybox-1.2.0+ipkg-0.99.162/include/applets.h 2006-07-22 16:35:35.000000000 +0200
13779 @@ -152,6 +152,7 @@
13780 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13781 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13782 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13783 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13784 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13785 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13786 USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER))
13787 diff -ruN busybox-1.2.0-orig/include/unarchive.h busybox-1.2.0+ipkg-0.99.162/include/unarchive.h
13788 --- busybox-1.2.0-orig/include/unarchive.h 2006-07-01 00:42:10.000000000 +0200
13789 +++ busybox-1.2.0+ipkg-0.99.162/include/unarchive.h 2006-07-22 16:31:26.000000000 +0200
13790 @@ -77,6 +77,7 @@
13791
13792 extern void data_skip(archive_handle_t *archive_handle);
13793 extern void data_extract_all(archive_handle_t *archive_handle);
13794 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13795 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13796 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13797
13798 diff -ruN busybox-1.2.0-orig/include/usage.h busybox-1.2.0+ipkg-0.99.162/include/usage.h
13799 --- busybox-1.2.0-orig/include/usage.h 2006-07-01 00:42:10.000000000 +0200
13800 +++ busybox-1.2.0+ipkg-0.99.162/include/usage.h 2006-07-22 16:31:26.000000000 +0200
13801 @@ -982,6 +982,82 @@
13802 "$ ls -la /tmp/busybox*\n" \
13803 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13804
13805 +#define ipkg_trivial_usage \
13806 + "[options]... sub-command [arguments]..."
13807 +#define ipkg_full_usage \
13808 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13809 + "\n" \
13810 + "Sub-commands:\n" \
13811 + "\nPackage Manipulation:\n" \
13812 + "\tupdate Update list of available packages\n" \
13813 + "\tupgrade Upgrade all installed packages to latest version\n" \
13814 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13815 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13816 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13817 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13818 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13819 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13820 + "\n" \
13821 + "Informational Commands:\n" \
13822 + "\tlist List available packages and descriptions\n" \
13823 + "\tlist_installed List all and only the installed packages and description \n" \
13824 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13825 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13826 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13827 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13828 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13829 + "\tcompare_versions <v1> <op> <v2>\n" \
13830 + "\t compare versions using <= < > >= = << >>\n" \
13831 + "\tprint_architecture prints the architecture.\n" \
13832 + "\tprint_installation_architecture\n" \
13833 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13834 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13835 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13836 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13837 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13838 + "\t prints the installation architecture.\n" \
13839 + "\n" \
13840 + "\nOptions:\n" \
13841 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13842 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13843 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13844 + "\t 0 errors only\n" \
13845 + "\t 1 normal messages (default)\n" \
13846 + "\t 2 informative messages\n" \
13847 + "\t 3 debug output\n" \
13848 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13849 + "\t-conf <conf_file> Default configuration file location\n" \
13850 + " is /etc/ipkg.conf\n" \
13851 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13852 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13853 + " <dest_name> should be a defined dest name from\n" \
13854 + " the configuration file, (but can also be a\n" \
13855 + " directory name in a pinch).\n" \
13856 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13857 + "\t-offline <offline_root> offline installation of packages.\n" \
13858 + "\t-verbose_wget more wget messages\n" \
13859 + "\n" \
13860 + "Force Options (use when ipkg is too smart for its own good):\n" \
13861 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13862 + "\t Install/remove package in spite of failed dependences\n" \
13863 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13864 + " (no prompts). Note that this will not prevent\n" \
13865 + " package installation scripts from prompting.\n" \
13866 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13867 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13868 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13869 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13870 + "\t-noaction No action -- test only\n" \
13871 + "\t-nodeps Do not follow dependences\n" \
13872 + "\t-force-removal-of-dependent-packages\n" \
13873 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13874 + "\t-test No action -- test only\n" \
13875 + "\t-t Specify tmp-dir.\n" \
13876 + "\t--tmp-dir Specify tmp-dir.\n" \
13877 + "\n" \
13878 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13879 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13880 +
13881 #define halt_trivial_usage \
13882 "[-d<delay>] [-n<nosync>] [-f<force>]"
13883 #define halt_full_usage \
13884 diff -ruN busybox-1.2.0-orig/Makefile busybox-1.2.0+ipkg-0.99.162/Makefile
13885 --- busybox-1.2.0-orig/Makefile 2006-07-01 00:42:13.000000000 +0200
13886 +++ busybox-1.2.0+ipkg-0.99.162/Makefile 2006-07-22 16:31:25.000000000 +0200
13887 @@ -31,7 +31,7 @@
13888 export srctree=$(top_srcdir)
13889 vpath %/Config.in $(srctree)
13890
13891 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
13892 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
13893 debianutils editors findutils init miscutils modutils networking \
13894 networking/libiproute networking/udhcp procps loginutils shell \
13895 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
This page took 0.635049 seconds and 5 git commands to generate.