libopkg: remove config.h references
[oweals/opkg-lede.git] / libopkg / pkg_parse.c
index cfa551e100bf82c98dab243677e5287befea3bea..ae52deb2556766211e0e19062340e3030fe1af74 100644 (file)
@@ -16,8 +16,6 @@
    General Public License for more details.
 */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <ctype.h>
 #include <unistd.h>
@@ -28,6 +26,7 @@
 #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)
@@ -41,7 +40,7 @@ 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);
 }
 
@@ -94,16 +93,20 @@ int parse_version(pkg_t * pkg, const char *vstr)
        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);
-       }
-       return 0;
+       while (isspace(*s))
+               s++;
+
+       e = s + strlen(s);
+
+       while (e > s && isspace(*e))
+               e--;
+
+       return pkg_set_architecture(pkg, s, e - s);
 }
 
 int pkg_parse_line(void *ptr, const char *line, uint mask)
@@ -114,6 +117,7 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
        /* these flags are a bit hackish... */
        static int reading_conffiles = 0, reading_description = 0;
        static char *description = NULL;
+       char *s;
        int ret = 0;
 
        /* Exclude globally masked fields. */
@@ -124,11 +128,9 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
 
        switch (*line) {
        case 'A':
-               if ((mask & PFM_ARCHITECTURE) && is_field("Architecture", line)) {
-                       pkg_set_int(pkg, 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_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)
@@ -182,20 +184,25 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
                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(DEPEND, "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))
@@ -217,7 +224,7 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
                        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);
+                       pkg_set_sha256(pkg, line + strlen("SHA256sum") + 1);
 #endif
                else if ((mask & PFM_SIZE) && is_field("Size", line)) {
                        pkg_set_int(pkg, PKG_SIZE, strtoul(line + strlen("Size") + 1, NULL, 0));