1 /* release_parse.c - the opkg package management system
3 Copyright (C) 2010,2011 Javier Palacios
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2, or (at
8 your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
21 #include "release_parse.h"
22 #include "libbb/libbb.h"
23 #include "parse_util.h"
26 release_parse_line(release_t *release, const char *line)
29 unsigned int count = 0;
31 static int reading_md5sums = 0;
33 static int reading_sha256sums = 0;
38 if (is_field("Architectures", line)) {
39 release->architectures = parse_list(line, &release->architectures_count, ' ', 0);
44 if (is_field("Codename", line)) {
45 release->name = parse_simple("Codename", line);
47 else if (is_field("Components", line)) {
48 release->components = parse_list(line, &release->components_count, ' ', 0);
53 if (is_field("Date", line)) {
54 release->datestring = parse_simple("Date", line);
59 if (is_field("MD5sum", line)) {
61 if (release->md5sums == NULL) {
62 release->md5sums = xcalloc(1, sizeof(cksum_list_t));
63 cksum_list_init(release->md5sums);
65 goto dont_reset_flags;
71 if (is_field("SHA256", line)) {
72 reading_sha256sums = 1;
73 if (release->sha256sums == NULL) {
74 release->sha256sums = xcalloc(1, sizeof(cksum_list_t));
75 cksum_list_init(release->sha256sums);
77 goto dont_reset_flags;
83 if (reading_md5sums) {
84 list = parse_list(line, &count, ' ', 1);
85 cksum_list_append(release->md5sums, list);
86 goto dont_reset_flags;
89 else if (reading_sha256sums) {
90 list = parse_list(line, &count, ' ', 1);
91 cksum_list_append(release->sha256sums, list);
92 goto dont_reset_flags;
103 reading_sha256sums = 0;
112 release_parse_from_stream(release_t *release, FILE *fp)
116 size_t buflen, nread;
118 nread = getline(&buf, &buflen, fp);
119 while ( nread != -1 ) {
120 if (buf[nread-1] == '\n') buf[nread-1] = '\0';
121 if (release_parse_line(release, buf))
122 opkg_msg(DEBUG, "Failed to parse release line for %s:\n\t%s\n",
124 nread = getline(&buf, &buflen, fp);
128 opkg_perror(ERROR, "Problems reading Release file for %sd\n", release->name);