1 --- a/libopkg/Makefile.am
2 +++ b/libopkg/Makefile.am
3 @@ -15,7 +15,6 @@ opkg_cmd_sources = opkg_cmd.c opkg_cmd.h
4 opkg_upgrade.c opkg_upgrade.h \
5 opkg_remove.c opkg_remove.h
6 opkg_db_sources = opkg_conf.c opkg_conf.h \
7 - release.c release.h release_parse.c release_parse.h \
8 opkg_utils.c opkg_utils.h pkg.c pkg.h hash_table.h \
9 pkg_depends.c pkg_depends.h pkg_extract.c pkg_extract.h \
10 hash_table.c pkg_hash.c pkg_hash.h pkg_parse.c pkg_parse.h \
11 @@ -28,7 +27,6 @@ opkg_list_sources = conffile.c conffile.
12 active_list.c active_list.h list.h
13 opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c md5.c md5.h \
14 parse_util.c parse_util.h \
15 - cksum_list.c cksum_list.h \
16 sprintf_alloc.c sprintf_alloc.h \
17 xregex.c xregex.h xsystem.c xsystem.h
19 --- a/libopkg/cksum_list.c
22 -/* cksum_lis.c - the opkg package management system
24 - Copyright (C) 2010,2011 Javier Palacios
26 - This program is free software; you can redistribute it and/or
27 - modify it under the terms of the GNU General Public License as
28 - published by the Free Software Foundation; either version 2, or (at
29 - your option) any later version.
31 - This program is distributed in the hope that it will be useful, but
32 - WITHOUT ANY WARRANTY; without even the implied warranty of
33 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 - General Public License for more details.
41 -#include "cksum_list.h"
42 -#include "libbb/libbb.h"
45 -int cksum_init(cksum_t *cksum, char **itemlist)
47 - cksum->value = xstrdup(*itemlist++);
48 - cksum->size = atoi(*itemlist++);
49 - cksum->name = xstrdup(*itemlist++);
54 -void cksum_deinit(cksum_t *cksum)
59 - free (cksum->value);
60 - cksum->value = NULL;
63 -void cksum_list_init(cksum_list_t *list)
65 - void_list_init((void_list_t *) list);
68 -void cksum_list_deinit(cksum_list_t *list)
70 - cksum_list_elt_t *iter, *n;
73 - list_for_each_entry_safe(iter, n, &list->head, node) {
74 - cksum = (cksum_t *)iter->data;
75 - cksum_deinit(cksum);
77 - /* malloced in cksum_list_append */
81 - void_list_deinit((void_list_t *) list);
84 -cksum_t *cksum_list_append(cksum_list_t *list, char **itemlist)
86 - /* freed in cksum_list_deinit */
87 - cksum_t *cksum = xcalloc(1, sizeof(cksum_t));
88 - cksum_init(cksum, itemlist);
90 - void_list_append((void_list_t *) list, cksum);
95 -const cksum_t *cksum_list_find(cksum_list_t *list, const char *name)
97 - cksum_list_elt_t *iter;
100 - list_for_each_entry(iter, &list->head, node) {
101 - cksum = (cksum_t *)iter->data;
102 - if (strcmp(cksum->name, name) == 0) {
109 --- a/libopkg/cksum_list.h
112 -/* cksum_list.h - the opkg package management system
114 - Copyright (C) 2010,2011 Javier Palacios
116 - This program is free software; you can redistribute it and/or
117 - modify it under the terms of the GNU General Public License as
118 - published by the Free Software Foundation; either version 2, or (at
119 - your option) any later version.
121 - This program is distributed in the hope that it will be useful, but
122 - WITHOUT ANY WARRANTY; without even the implied warranty of
123 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
124 - General Public License for more details.
127 -#ifndef CKSUM_LIST_H
128 -#define CKSUM_LIST_H
137 -int cksum_init(cksum_t *cksum, char **itemlist);
138 -void cksum_deinit(cksum_t *cksum);
140 -#include "void_list.h"
142 -typedef struct void_list_elt cksum_list_elt_t;
144 -typedef struct void_list cksum_list_t;
146 -static inline int cksum_list_empty(cksum_list_t *list)
148 - return void_list_empty ((void_list_t *)list);
151 -void cksum_list_init(cksum_list_t *list);
152 -void cksum_list_deinit(cksum_list_t *list);
154 -cksum_t *cksum_list_append(cksum_list_t *list, char **itemlist);
155 -const cksum_t *cksum_list_find(cksum_list_t *list, const char *name);
158 --- a/libopkg/release.c
161 -/* release.c - the opkg package management system
163 - Copyright (C) 2010,2011 Javier Palacios
165 - This program is free software; you can redistribute it and/or
166 - modify it under the terms of the GNU General Public License as
167 - published by the Free Software Foundation; either version 2, or (at
168 - your option) any later version.
170 - This program is distributed in the hope that it will be useful, but
171 - WITHOUT ANY WARRANTY; without even the implied warranty of
172 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
173 - General Public License for more details.
179 -#include "release.h"
180 -#include "opkg_utils.h"
181 -#include "libbb/libbb.h"
183 -#include "opkg_download.h"
184 -#include "sprintf_alloc.h"
186 -#include "release_parse.h"
188 -#include "parse_util.h"
189 -#include "file_util.h"
192 -release_init(release_t *release)
194 - release->name = NULL;
195 - release->datestring = NULL;
196 - release->architectures = NULL;
197 - release->architectures_count = 0;
198 - release->components = NULL;
199 - release->components_count = 0;
200 - release->complist = NULL;
201 - release->complist_count = 0;
207 - release_t *release;
209 - release = xcalloc(1, sizeof(release_t));
210 - release_init(release);
216 -release_deinit(release_t *release)
220 - free(release->name);
221 - free(release->datestring);
223 - for(i = 0; i < release->architectures_count; i++){
224 - free(release->architectures[i]);
226 - free(release->architectures);
228 - for(i = 0; i < release->components_count; i++){
229 - free(release->components[i]);
231 - free(release->components);
233 - for(i = 0; i < release->complist_count; i++){
234 - free(release->complist[i]);
236 - free(release->complist);
241 -release_init_from_file(release_t *release, const char *filename)
244 - FILE *release_file;
246 - release_file = fopen(filename, "r");
247 - if (release_file == NULL) {
248 - opkg_perror(ERROR, "Failed to open %s", filename);
252 - err=release_parse_from_stream(release, release_file);
254 - if (!release_arch_supported(release)) {
255 - opkg_msg(ERROR, "No valid architecture found on Release file.\n");
264 -item_in_list(const char *comp, char **complist, const unsigned int count)
271 - for(i = 0; i < count; i++){
272 - if (strcmp(comp, complist[i]) == 0)
273 - return complist[i];
280 -release_arch_supported(release_t *release)
282 - nv_pair_list_elt_t *l;
284 - list_for_each_entry(l , &conf->arch_list.head, node) {
285 - nv_pair_t *nv = (nv_pair_t *)l->data;
286 - if (item_in_list(nv->name, release->architectures, release->architectures_count)) {
287 - opkg_msg(DEBUG, "Arch %s (priority %s) supported for dist %s.\n",
288 - nv->name, nv->value, release->name);
297 -release_comps_supported(release_t *release, const char *complist)
303 - release->complist = parse_list(complist, &release->complist_count, ' ', 1);
304 - for(i = 0; i < release->complist_count; i++){
305 - if (!item_in_list(release->complist[i], release->components, release->components_count)) {
306 - opkg_msg(ERROR, "Component %s not supported for dist %s.\n",
307 - release->complist[i], release->name);
317 -release_comps(release_t *release, unsigned int *count)
319 - char **comps = release->complist;
322 - comps = release->components;
323 - *count = release->components_count;
325 - *count = release->complist_count;
328 - return (const char **)comps;
332 -release_download(release_t *release, pkg_src_t *dist, char *lists_dir, char *tmpdir)
335 - unsigned int ncomp;
336 - const char **comps = release_comps(release, &ncomp);
337 - nv_pair_list_elt_t *l;
340 - for(i = 0; i < ncomp; i++){
344 - sprintf_alloc(&prefix, "%s/dists/%s/%s/binary", dist->value, dist->name,
347 - list_for_each_entry(l , &conf->arch_list.head, node) {
349 - char *tmp_file_name, *list_file_name;
350 - char *subpath = NULL;
352 - nv_pair_t *nv = (nv_pair_t *)l->data;
354 - sprintf_alloc(&list_file_name, "%s/%s-%s-%s", lists_dir, dist->name, comps[i], nv->name);
356 - sprintf_alloc(&tmp_file_name, "%s/%s-%s-%s%s", tmpdir, dist->name, comps[i], nv->name, ".gz");
358 - sprintf_alloc(&subpath, "%s/binary-%s/%s", comps[i], nv->name, dist->gzip ? "Packages.gz" : "Packages");
361 - sprintf_alloc(&url, "%s-%s/Packages.gz", prefix, nv->name);
362 - err = opkg_download(url, tmp_file_name, NULL, NULL, 1);
364 - err = release_verify_file(release, tmp_file_name, subpath);
366 - unlink (tmp_file_name);
367 - unlink (list_file_name);
372 - opkg_msg(NOTICE, "Inflating %s.\n", url);
373 - in = fopen (tmp_file_name, "r");
374 - out = fopen (list_file_name, "w");
376 - err = unzip (in, out);
378 - opkg_msg(INFO, "Corrumpt file at %s.\n", url);
385 - unlink (tmp_file_name);
391 - sprintf_alloc(&url, "%s-%s/Packages", prefix, nv->name);
392 - err = opkg_download(url, list_file_name, NULL, NULL, 1);
394 - err = release_verify_file(release, tmp_file_name, subpath);
396 - unlink (list_file_name);
401 - free(tmp_file_name);
402 - free(list_file_name);
415 -release_get_size(release_t *release, const char *pathname)
417 - const cksum_t *cksum;
419 - if (release->md5sums) {
420 - cksum = cksum_list_find(release->md5sums, pathname);
421 - return cksum->size;
425 - if (release->sha256sums) {
426 - cksum = cksum_list_find(release->sha256sums, pathname);
427 - return cksum->size;
435 -release_get_md5(release_t *release, const char *pathname)
437 - const cksum_t *cksum;
439 - if (release->md5sums) {
440 - cksum = cksum_list_find(release->md5sums, pathname);
441 - return cksum->value;
449 -release_get_sha256(release_t *release, const char *pathname)
451 - const cksum_t *cksum;
453 - if (release->sha256sums) {
454 - cksum = cksum_list_find(release->sha256sums, pathname);
455 - return cksum->value;
463 -release_verify_file(release_t *release, const char* file_name, const char *pathname)
465 - struct stat f_info;
466 - char *f_md5 = NULL;
467 - const char *md5 = release_get_md5(release, pathname);
469 - char *f_sha256 = NULL;
470 - const char *sha256 = release_get_sha256(release, pathname);
474 - if (stat(file_name, &f_info) || (f_info.st_size!=release_get_size(release, pathname))) {
475 - opkg_msg(ERROR, "Size verification failed for %s - %s.\n", release->name, pathname);
479 - f_md5 = file_md5sum_alloc(file_name);
481 - f_sha256 = file_sha256sum_alloc(file_name);
484 - if (md5 && strcmp(md5, f_md5)) {
485 - opkg_msg(ERROR, "MD5 verification failed for %s - %s.\n", release->name, pathname);
488 - } else if (sha256 && strcmp(sha256, f_sha256)) {
489 - opkg_msg(ERROR, "SHA256 verification failed for %s - %s.\n", release->name, pathname);
503 --- a/libopkg/release.h
506 -/* release.h - the opkg package management system
508 - Copyright (C) 2010,2011 Javier Palacios
510 - This program is free software; you can redistribute it and/or
511 - modify it under the terms of the GNU General Public License as
512 - published by the Free Software Foundation; either version 2, or (at
513 - your option) any later version.
515 - This program is distributed in the hope that it will be useful, but
516 - WITHOUT ANY WARRANTY; without even the implied warranty of
517 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
518 - General Public License for more details.
526 -#include "cksum_list.h"
532 - char **architectures;
533 - unsigned int architectures_count;
535 - unsigned int components_count;
536 - cksum_list_t *md5sums;
538 - cksum_list_t *sha256sums;
541 - unsigned int complist_count;
544 -typedef struct release release_t;
546 -release_t *release_new(void);
547 -void release_deinit(release_t *release);
548 -int release_init_from_file(release_t *release, const char *filename);
550 -int release_arch_supported(release_t *release);
551 -int release_comps_supported(release_t *release, const char *complist);
552 -int release_download(release_t *release, pkg_src_t *dist, char *lists_dir, char *tmpdir);
554 -const char **release_comps(release_t *release, unsigned int *count);
556 -int release_verify_file(release_t *release, const char *filename, const char *pathname);
559 --- a/libopkg/release_parse.c
562 -/* release_parse.c - the opkg package management system
564 - Copyright (C) 2010,2011 Javier Palacios
566 - This program is free software; you can redistribute it and/or
567 - modify it under the terms of the GNU General Public License as
568 - published by the Free Software Foundation; either version 2, or (at
569 - your option) any later version.
571 - This program is distributed in the hope that it will be useful, but
572 - WITHOUT ANY WARRANTY; without even the implied warranty of
573 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
574 - General Public License for more details.
581 -#include "release.h"
582 -#include "release_parse.h"
583 -#include "libbb/libbb.h"
584 -#include "parse_util.h"
587 -release_parse_line(void *ptr, const char *line, uint mask)
589 - release_t *release = (release_t *) ptr;
592 - unsigned int count = 0;
594 - static int reading_md5sums = 0;
596 - static int reading_sha256sums = 0;
601 - if (is_field("Architectures", line)) {
602 - release->architectures = parse_list(line, &release->architectures_count, ' ', 0);
607 - if (is_field("Codename", line)) {
608 - release->name = parse_simple("Codename", line);
610 - else if (is_field("Components", line)) {
611 - release->components = parse_list(line, &release->components_count, ' ', 0);
616 - if (is_field("Date", line)) {
617 - release->datestring = parse_simple("Date", line);
622 - if (is_field("MD5sum", line)) {
623 - reading_md5sums = 1;
624 - if (release->md5sums == NULL) {
625 - release->md5sums = xcalloc(1, sizeof(cksum_list_t));
626 - cksum_list_init(release->md5sums);
628 - goto dont_reset_flags;
634 - if (is_field("SHA256", line)) {
635 - reading_sha256sums = 1;
636 - if (release->sha256sums == NULL) {
637 - release->sha256sums = xcalloc(1, sizeof(cksum_list_t));
638 - cksum_list_init(release->sha256sums);
640 - goto dont_reset_flags;
646 - if (reading_md5sums) {
647 - list = parse_list(line, &count, ' ', 1);
648 - cksum_list_append(release->md5sums, list);
649 - goto dont_reset_flags;
652 - else if (reading_sha256sums) {
653 - list = parse_list(line, &count, ' ', 1);
654 - cksum_list_append(release->sha256sums, list);
655 - goto dont_reset_flags;
664 - reading_md5sums = 0;
666 - reading_sha256sums = 0;
675 -release_parse_from_stream(release_t *release, FILE *fp)
679 - const size_t len = 4096;
681 - buf = xmalloc(len);
682 - ret = parse_from_stream_nomalloc(release_parse_line, release, fp, 0, &buf, len);
688 --- a/libopkg/release_parse.h
691 -/* release_parse.h - the opkg package management system
693 - Copyright (C) 2010,2011 Javier Palacios
695 - This program is free software; you can redistribute it and/or
696 - modify it under the terms of the GNU General Public License as
697 - published by the Free Software Foundation; either version 2, or (at
698 - your option) any later version.
700 - This program is distributed in the hope that it will be useful, but
701 - WITHOUT ANY WARRANTY; without even the implied warranty of
702 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
703 - General Public License for more details.
706 -#ifndef RELEASE_PARSE_H
707 -#define RELEASE_PARSE_H
709 -int release_parse_from_stream(release_t *release, FILE *fp);
712 --- a/libopkg/opkg_cmd.c
713 +++ b/libopkg/opkg_cmd.c
715 #include "opkg_conf.h"
716 #include "opkg_cmd.h"
717 #include "opkg_message.h"
718 -#include "release.h"
720 #include "pkg_dest.h"
721 #include "pkg_parse.h"
722 @@ -114,39 +113,6 @@ opkg_update_cmd(int argc, char **argv)
726 - for (iter = void_list_first(&conf->dist_src_list); iter; iter = void_list_next(&conf->dist_src_list, iter)) {
727 - char *url, *list_file_name;
729 - src = (pkg_src_t *)iter->data;
731 - sprintf_alloc(&url, "%s/dists/%s/Release", src->value, src->name);
733 - sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
734 - err = opkg_download(url, list_file_name, NULL, NULL, 0);
736 - opkg_msg(NOTICE, "Downloaded release files for dist %s.\n",
738 - release_t *release = release_new();
739 - err = release_init_from_file(release, list_file_name);
741 - if (!release_comps_supported(release, src->extra_data))
745 - err = release_download(release, src, lists_dir, tmp);
747 - release_deinit(release);
749 - unlink(list_file_name);
755 - free(list_file_name);
759 for (iter = void_list_first(&conf->pkg_src_list); iter; iter = void_list_next(&conf->pkg_src_list, iter)) {
760 char *url, *list_file_name;
762 --- a/libopkg/pkg_hash.c
763 +++ b/libopkg/pkg_hash.c
767 #include "hash_table.h"
768 -#include "release.h"
770 #include "opkg_message.h"
772 @@ -183,40 +182,6 @@ pkg_hash_load_feeds(void)
773 lists_dir = conf->restrict_to_default_dest ?
774 conf->default_dest->lists_dir : conf->lists_dir;
776 - for (iter = void_list_first(&conf->dist_src_list); iter;
777 - iter = void_list_next(&conf->dist_src_list, iter)) {
779 - src = (pkg_src_t *)iter->data;
781 - sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name);
783 - if (file_exists(list_file)) {
785 - release_t *release = release_new();
786 - if(release_init_from_file(release, list_file)) {
791 - unsigned int ncomp;
792 - const char **comps = release_comps(release, &ncomp);
793 - subdist = (pkg_src_t *) xmalloc(sizeof(pkg_src_t));
794 - memcpy(subdist, src, sizeof(pkg_src_t));
796 - for(i = 0; i < ncomp; i++){
797 - subdist->name = NULL;
798 - sprintf_alloc(&subdist->name, "%s-%s", src->name, comps[i]);
799 - if (dist_hash_add_from_file(lists_dir, subdist)) {
800 - free(subdist->name); free(subdist);
805 - free(subdist->name); free(subdist);
810 for (iter = void_list_first(&conf->pkg_src_list); iter;
811 iter = void_list_next(&conf->pkg_src_list, iter)) {