General Public License for more details.
*/
-#include "config.h"
-
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "pkg.h"
#include "opkg_utils.h"
#include "pkg_parse.h"
+#include "pkg_depends.h"
#include "libbb/libbb.h"
+#include "file_util.h"
#include "parse_util.h"
static void parse_status(pkg_t * pkg, const char *sstr)
}
pkg->state_want = pkg_state_want_from_str(sw_str);
- pkg->state_flag = pkg_state_flag_from_str(sf_str);
+ pkg->state_flag |= pkg_state_flag_from_str(sf_str);
pkg->state_status = pkg_state_status_from_str(ss_str);
}
static void parse_conffiles(pkg_t * pkg, const char *cstr)
{
+ conffile_list_t *cl;
char file_name[1024], md5sum[85];
if (sscanf(cstr, "%1023s %84s", file_name, md5sum) != 2) {
return;
}
- conffile_list_append(&pkg->conffiles, file_name, md5sum);
+ cl = pkg_get_ptr(pkg, PKG_CONFFILES);
+
+ if (cl)
+ conffile_list_append(cl, file_name, md5sum);
}
int parse_version(pkg_t * pkg, const char *vstr)
{
- char *colon, *rev;
+ char *colon, *dup, *rev;
if (strncmp(vstr, "Version:", 8) == 0)
vstr += 8;
vstr = ++colon;
}
- rev = strrchr(pkg_set_string(pkg, PKG_VERSION, vstr), '-');
+
+ dup = xstrdup(vstr);
+ rev = strrchr(dup, '-');
if (rev) {
*rev++ = '\0';
- pkg_set_ptr(pkg, PKG_REVISION, rev);
+ pkg_set_string(pkg, PKG_REVISION, rev);
}
+ pkg_set_string(pkg, PKG_VERSION, dup);
+ free(dup);
+
return 0;
}
-static int get_arch_priority(const char *arch)
+static char *parse_architecture(pkg_t *pkg, const char *str)
{
- nv_pair_list_elt_t *l;
+ const char *s = str;
+ const char *e;
- list_for_each_entry(l, &conf->arch_list.head, node) {
- nv_pair_t *nv = (nv_pair_t *) l->data;
- if (strcmp(nv->name, arch) == 0)
- return strtol(nv->value, NULL, 0);
+ while (isspace(*s))
+ s++;
+
+ e = s + strlen(s);
+
+ while (e > s && isspace(*e))
+ e--;
+
+ return pkg_set_architecture(pkg, s, e - s);
+}
+
+static void parse_alternatives(pkg_t *pkg, char *list)
+{
+ char *item, *tok;
+ struct pkg_alternatives *pkg_alts;
+ struct pkg_alternative **alts;
+ int nalts;
+
+ pkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);
+ if (!pkg_alts) {
+ nalts = 0;
+ alts = NULL;
+ } else {
+ nalts = pkg_alts->nalts;
+ alts = pkg_alts->alts;
+ }
+
+ for (item = strtok_r(list, ",", &tok);
+ item;
+ item = strtok_r(NULL, ",", &tok)) {
+ enum pkg_alternative_field i;
+ char *val, *tok1;
+ /* the assignment was intended to quash the -Wmaybe-uninitialized warnings */
+ int prio = prio;
+ char *path = path, *altpath = altpath;
+
+ for (i = PAF_PRIO, val = strtok_r(item, ":", &tok1);
+ val && i < __PAF_MAX;
+ val = strtok_r(NULL, ":", &tok1), i++) {
+ switch (i) {
+ case PAF_PRIO:
+ prio = atoi(val);
+ break;
+ case PAF_PATH:
+ path = val;
+ break;
+ case PAF_ALTPATH:
+ altpath = val;
+ break;
+ default:
+ break;
+ }
+ }
+ if (!val && i == __PAF_MAX) {
+ char *_path, *_altpath;
+ struct pkg_alternative *alt;
+
+ /*
+ * - path must be absolute
+ * - altpath must be non-empty
+ */
+ if (path[0] != '/' || !altpath[0])
+ continue;
+
+ alt = calloc_a(sizeof(*alt),
+ &_path, strlen(path) + 1,
+ &_altpath, strlen(altpath) + 1);
+ if (!alt)
+ continue;
+ strcpy(_path, path);
+ strcpy(_altpath, altpath);
+ alt->prio = prio;
+ alt->path = _path;
+ alt->altpath = _altpath;
+ alts = xrealloc(alts, sizeof(*alts) * (nalts + 1));
+ alts[nalts++] = alt;
+ }
+ }
+
+ if (nalts > 0) {
+ if (!pkg_alts)
+ pkg_alts = xmalloc(sizeof(*pkg_alts));
+ pkg_alts->nalts = nalts;
+ pkg_alts->alts = alts;
+ pkg_set_ptr(pkg, PKG_ALTERNATIVES, pkg_alts);
}
- return 0;
}
-int pkg_parse_line(void *ptr, const char *line, uint mask)
+int pkg_parse_line(void *ptr, char *line, uint mask)
{
pkg_t *pkg = (pkg_t *) ptr;
+ abstract_pkg_t *ab_pkg = NULL;
+ conffile_list_t *cl;
/* these flags are a bit hackish... */
static int reading_conffiles = 0, reading_description = 0;
switch (*line) {
case 'A':
- if ((mask & PFM_ARCHITECTURE) && is_field("Architecture", line)) {
- pkg->arch_priority = get_arch_priority(
- pkg_set_string(pkg, PKG_ARCHITECTURE, line + strlen("Architecture") + 1));
-
- } else if ((mask & PFM_AUTO_INSTALLED)
+ if ((mask & PFM_ALTERNATIVES) && is_field("Alternatives", line))
+ parse_alternatives(pkg, line + strlen("Alternatives") + 1);
+ else if ((mask & PFM_ARCHITECTURE) && is_field("Architecture", line))
+ parse_architecture(pkg, line + strlen("Architecture") + 1);
+ else if ((mask & PFM_AUTO_INSTALLED)
&& is_field("Auto-Installed", line)) {
char *tmp = parse_simple("Auto-Installed", line);
if (strcmp(tmp, "yes") == 0)
if ((mask & PFM_CONFFILES) && is_field("Conffiles", line)) {
reading_conffiles = 1;
reading_description = 0;
+
+ cl = xcalloc(1, sizeof(*cl));
+ conffile_list_init(cl);
+ pkg_set_ptr(pkg, PKG_CONFFILES, cl);
+
goto dont_reset_flags;
} else if ((mask & PFM_CONFLICTS)
&& is_field("Conflicts", line))
- pkg->conflicts_str =
- parse_list(line, &pkg->conflicts_count, ',', 0);
+ parse_deplist(pkg, CONFLICTS, line + strlen("Conflicts") + 1);
break;
case 'D':
reading_description = 1;
goto dont_reset_flags;
} else if ((mask & PFM_DEPENDS) && is_field("Depends", line))
- pkg->depends_str =
- parse_list(line, &pkg->depends_count, ',', 0);
+ parse_deplist(pkg, DEPEND, line + strlen("Depends") + 1);
break;
case 'E':
break;
case 'M':
- if ((mask & PFM_MD5SUM) && is_field("MD5sum:", line))
- pkg_set_string(pkg, PKG_MD5SUM, line + strlen("MD5sum") + 1);
- /* The old opkg wrote out status files with the wrong
- * case for MD5sum, let's parse it either way */
- else if ((mask & PFM_MD5SUM) && is_field("MD5Sum:", line))
- pkg_set_string(pkg, PKG_MD5SUM, line + strlen("MD5Sum") + 1);
+ if ((mask & PFM_MD5SUM) && (is_field("MD5sum:", line) || is_field("MD5Sum:", line)))
+ pkg_set_md5(pkg, line + strlen("MD5sum") + 1);
else if ((mask & PFM_MAINTAINER)
&& is_field("Maintainer", line))
pkg_set_string(pkg, PKG_MAINTAINER, line + strlen("Maintainer") + 1);
break;
case 'P':
- if ((mask & PFM_PACKAGE) && is_field("Package", line))
+ if ((mask & PFM_PACKAGE) && is_field("Package", line)) {
pkg->name = parse_simple("Package", line);
+ ab_pkg = abstract_pkg_fetch_by_name(pkg->name);
+
+ if (ab_pkg && (ab_pkg->state_flag & SF_NEED_DETAIL)) {
+ if (!(pkg->state_flag & SF_NEED_DETAIL)) {
+ opkg_msg(DEBUG, "propagating abpkg flag to pkg %s\n", pkg->name);
+ pkg->state_flag |= SF_NEED_DETAIL;
+ }
+ }
+ }
else if ((mask & PFM_PRIORITY) && is_field("Priority", line))
pkg_set_string(pkg, PKG_PRIORITY, line + strlen("Priority") + 1);
else if ((mask & PFM_PROVIDES) && is_field("Provides", line))
- pkg->provides_str =
- parse_list(line, &pkg->provides_count, ',', 0);
+ parse_providelist(pkg, line + strlen("Provides") + 1);
else if ((mask & PFM_PRE_DEPENDS)
&& is_field("Pre-Depends", line))
- pkg->pre_depends_str =
- parse_list(line, &pkg->pre_depends_count, ',', 0);
+ parse_deplist(pkg, PREDEPEND, line + strlen("Pre-Depends") + 1);
break;
case 'R':
if ((mask & PFM_RECOMMENDS) && is_field("Recommends", line))
- pkg->recommends_str =
- parse_list(line, &pkg->recommends_count, ',', 0);
+ parse_deplist(pkg, RECOMMEND, line + strlen("Recommends") + 1);
else if ((mask & PFM_REPLACES) && is_field("Replaces", line))
- pkg->replaces_str =
- parse_list(line, &pkg->replaces_count, ',', 0);
-
+ parse_replacelist(pkg, line + strlen("Replaces") + 1);
break;
case 'S':
if ((mask & PFM_SECTION) && is_field("Section", line))
pkg_set_string(pkg, PKG_SECTION, line + strlen("Section") + 1);
-#ifdef HAVE_SHA256
else if ((mask & PFM_SHA256SUM) && is_field("SHA256sum", line))
- pkg_set_string(pkg, PKG_SHA256SUM, line + strlen("SHA256sum") + 1);
-#endif
+ pkg_set_sha256(pkg, line + strlen("SHA256sum") + 1);
else if ((mask & PFM_SIZE) && is_field("Size", line)) {
pkg_set_int(pkg, PKG_SIZE, strtoul(line + strlen("Size") + 1, NULL, 0));
} else if ((mask & PFM_SOURCE) && is_field("Source", line))
else if ((mask & PFM_STATUS) && is_field("Status", line))
parse_status(pkg, line);
else if ((mask & PFM_SUGGESTS) && is_field("Suggests", line))
- pkg->suggests_str =
- parse_list(line, &pkg->suggests_count, ',', 0);
+ parse_deplist(pkg, SUGGEST, line + strlen("Suggests") + 1);
break;
case 'T':
case ' ':
if ((mask & PFM_DESCRIPTION) && reading_description) {
- if (isatty(1)) {
- description = xrealloc(description,
- strlen(description)
- + 1 + strlen(line) +
- 1);
+ size_t len = (description ? strlen(description) : 0)
+ + (isatty(1) ? 1 : 0) + strlen(line) + 1;
+
+ description = description ? xrealloc(description, len)
+ : xcalloc(len, 1);
+
+ if (isatty(1))
strcat(description, "\n");
- } else {
- description = xrealloc(description,
- strlen(description)
- + 1 + strlen(line));
- }
- strcat(description, (line));
+
+ strcat(description, line);
goto dont_reset_flags;
} else if ((mask & PFM_CONFFILES) && reading_conffiles) {
parse_conffiles(pkg, line);