Remove opkg_internal_use_only and fix associated assumptions RE pkg->provides.
[oweals/opkg-lede.git] / libopkg / pkg_parse.c
index 76cd6489119e601590f1182443516d3550ed39c6..12aabbe6c08a47fff7ea17ce0f5699450819647e 100644 (file)
@@ -22,6 +22,7 @@
 #include "pkg.h"
 #include "opkg_utils.h"
 #include "pkg_parse.h"
+#include "libbb/libbb.h"
 
 int isGenericFieldType(char * type, char * line)
 {
@@ -61,7 +62,7 @@ char ** parseDependsString(char * raw, int * depends_count)
        return NULL;
     }
     while(raw && *raw){
-       depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
+       depends = xrealloc(depends, sizeof(char *) * (line_count + 1));
        
        while(isspace(*raw)) raw++;
 
@@ -141,12 +142,8 @@ int parseVersion(pkg_t *pkg, char *raw)
 
   if (!pkg->version)
   {
-  pkg->version= calloc(1, strlen(raw)+1);
-  if ( pkg->version == NULL ) {
-     fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
-     return ENOMEM;
-  }
-  strcpy(pkg->version, raw);
+    pkg->version= xcalloc(1, strlen(raw)+1);
+    strcpy(pkg->version, raw);
   }
 
   hyphen= strrchr(pkg->version,'-');
@@ -159,38 +156,6 @@ int parseVersion(pkg_t *pkg, char *raw)
   return 0;
 }
 
-
-/* This code is needed to insert in first position the keyword for the aligning bug */
-
-int alterProvidesLine(char *raw, char *temp)
-{
-
-
-  if (!*raw) {
-      fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
-      return -EINVAL;
-  }
-
-  if ( temp == NULL ) {
-     fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
-     return -ENOMEM;
-  }
-
-  if (strncmp(raw, "Provides:", 9) == 0) {
-      raw += 9;
-  }
-  while (*raw && isspace(*raw)) {
-      raw++;
-  }      
-  
-  snprintf ( temp, 35, "Provides: opkg_internal_use_only, ");           /* First part of the line */
-  while (*raw) {
-     strncat( temp, raw++, 1);
-  }
-  return 0;
-}
-
 /* Some random thoughts from Carl:
 
    This function could be considerably simplified if we just kept
@@ -211,9 +176,7 @@ int alterProvidesLine(char *raw, char *temp)
 int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
 {
     int reading_conffiles, reading_description;
-    int pkg_false_provides=1;
     char ** lines;
-    char * provide=NULL;
 
     pkg->src = src;
     pkg->dest = dest;
@@ -229,17 +192,7 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
            else if(isGenericFieldType("Priority:", *lines))
                pkg->priority = parseGenericFieldType("Priority", *lines);
            else if(isGenericFieldType("Provides", *lines)){
-/* Here we add the internal_use to align the off by one problem between provides_str and provides */
-               provide = (char * ) calloc(1, strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
-               if ( alterProvidesLine(*lines,provide) ){
-                   return EINVAL;
-               }
-               pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
-/* Let's try to hack a bit here.
-   The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
-   in alot of other places. We will remove it before writing down the status database */
-               pkg_false_provides=0;
-               free(provide);
+               pkg->provides_str = parseDependsString(*lines, &pkg->provides_count);
            } 
            else if(isGenericFieldType("Pre-Depends", *lines))
                pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
@@ -266,6 +219,10 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
        case 'S':
            if(isGenericFieldType("Section:", *lines))
                pkg->section = parseGenericFieldType("Section", *lines);
+#ifdef HAVE_SHA256
+           else if(isGenericFieldType("SHA256sum:", *lines))
+               pkg->sha256sum = parseGenericFieldType("SHA256sum", *lines);
+#endif
            else if(isGenericFieldType("Size:", *lines))
                pkg->size = parseGenericFieldType("Size", *lines);
            else if(isGenericFieldType("Source:", *lines))
@@ -348,7 +305,7 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
        case ' ':
            if(reading_description) {
                /* we already know it's not blank, so the rest of description */      
-               pkg->description = realloc(pkg->description,
+               pkg->description = xrealloc(pkg->description,
                                           strlen(pkg->description)
                                           + 1 + strlen(*lines) + 1);
                strcat(pkg->description, "\n");
@@ -369,13 +326,6 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
 out:;
     
     *raw = lines;
-/* If the opk has not a Provides line, we insert our false line */ 
-    if ( pkg_false_provides==1)
-    {
-       pkg->provides_count = 1;
-       pkg->provides_str = calloc (1, sizeof (char*));
-       pkg->provides_str[0] = strdup ("opkg_internal_use_only");
-    }
 
     if (pkg->name) {
        return 0;