* repo_content.c
*
* Parses 'content' file into .solv
+ * A 'content' file is the repomd.xml of the susetags format
+ *
* See http://en.opensuse.org/Standards/YaST2_Repository_Metadata/content for a description
* of the syntax
*
#include "pool.h"
#include "repo.h"
#include "util.h"
+#include "chksum.h"
#include "repo_content.h"
#define DISABLE_SPLIT
#include "tools_util.h"
if (!rel || !evr)
{
pool_debug(pool, SAT_FATAL, "repo_content: bad relation '%s %s'\n", name, rel);
- exit(1);
+ continue;
}
for (flags = 0; flags < 6; flags++)
if (!strcmp(rel, flagtab[flags]))
if (flags == 6)
{
pool_debug(pool, SAT_FATAL, "repo_content: unknown relation '%s'\n", rel);
- exit(1);
+ continue;
}
id = rel2id(pool, id, str2id(pool, evr, 1), flags + 1, 1);
}
continue;
if (!*value)
continue;
- if (!strcasecmp(checksumtype, "sha") || !strcasecmp(checksumtype, "sha1"))
- l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
- else if (!strcasecmp(checksumtype, "sha256"))
- l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
- else if (!strcasecmp(checksumtype, "md5"))
- l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
- else
- {
+ type = sat_chksum_str2type(checksumtype);
+ if (!type)
+ {
fprintf(stderr, "Unknown checksum type: %s: %s\n", value, checksumtype);
- exit(1);
- }
- if (strlen(checksum) != l)
+ continue;
+ }
+ l = sat_chksum_len(type);
+ if (strlen(checksum) != 2 * l)
{
fprintf(stderr, "Invalid checksum length: %s: for %s\n", value, checksum);
- exit(1);
+ continue;
}
fh = repodata_new_handle(data);
repodata_set_poolstr(data, fh, SUSETAGS_FILE_TYPE, key);
if (defvendor)
free(defvendor);
+ if (s && !s->name)
+ {
+ pool_debug(pool, SAT_FATAL, "repo_content: 'content' incomplete, no product solvable created!\n");
+ repo_free_solvable_block(repo, s - pool->solvables, 1, 1);
+ s = 0;
+ }
if (s)
{
- if (!s->name)
- {
- pool_debug(pool, SAT_FATAL, "repo_content: 'content' incomplete, no product solvable created!\n");
- exit(1);
- }
-
if (pd.tmprel)
s->evr = makeevr(pool, join(&pd, pd.tmpvers, "-", pd.tmprel));
else
int havesource = 0;
char checksum[32 * 2 + 1];
Id checksumtype = 0;
+ Id newtype;
p = control;
while (*p)
s->recommends = makedeps(repo, q, s->recommends, 0);
break;
case 'S' << 8 | 'H':
- if (!strcasecmp(tag, "sha1") && checksumtype != REPOKEY_TYPE_SHA256 && strlen(q) == 20 * 2)
- {
- strcpy(checksum, q);
- checksumtype = REPOKEY_TYPE_SHA1;
- }
- else if (!strcasecmp(tag, "sha256") && strlen(q) == 32 * 2)
+ newtype = sat_chksum_str2type(tag);
+ if (!newtype || sat_chksum_len(newtype) * 2 != strlen(q))
+ break;
+ if (!checksumtype || (newtype == REPOKEY_TYPE_SHA1 && checksumtype != REPOKEY_TYPE_SHA256) || newtype == REPOKEY_TYPE_SHA256)
{
strcpy(checksum, q);
- checksumtype = REPOKEY_TYPE_SHA256;
+ checksumtype = newtype;
}
break;
case 'S' << 8 | 'O':
#include "pool.h"
#include "repo.h"
+#include "chksum.h"
#include "repo_updateinfoxml.h"
//#define DUMPOUT 0
case STATE_CHECKSUM:
case STATE_OPENCHECKSUM:
{
- int l;
- Id type;
- if (!strcasecmp(pd->tmpattr, "sha") || !strcasecmp(pd->tmpattr, "sha1"))
- l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
- else if (!strcasecmp(pd->tmpattr, "sha256"))
- l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
- else if (!strcasecmp(pd->tmpattr, "md5"))
- l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
- else
- {
+ Id type = sat_chksum_str2type(pd->tmpattr);
+ if (!type)
+ {
fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
exit(1);
- }
- if (strlen(pd->content) != l)
- {
+ }
+ if (strlen(pd->content) != 2 * sat_chksum_len(type))
+ {
fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
exit(1);
- }
+ }
repodata_set_checksum(pd->data, pd->rdhandle, pd->state == STATE_CHECKSUM ? REPOSITORY_REPOMD_CHECKSUM : REPOSITORY_REPOMD_OPENCHECKSUM, type, pd->content);
break;
}
break;
case STATE_CHECKSUM:
{
- int l;
Id type, index;
- if (!strcasecmp(pd->tmpattr, "sha") || !strcasecmp(pd->tmpattr, "sha1"))
- l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
- else if (!strcasecmp(pd->tmpattr, "sha256"))
- l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
- else if (!strcasecmp(pd->tmpattr, "md5"))
- l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
- else
- {
+ type = sat_chksum_str2type(pd->tmpattr);
+ if (!type)
+ {
fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
exit(1);
- }
- if (strlen(pd->content) != l)
+ }
+ if (strlen(pd->content) != 2 * sat_chksum_len(type))
{
fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
exit(1);
#include "pool.h"
#include "repo.h"
#include "hash.h"
+#include "chksum.h"
#include "tools_util.h"
#include "repo_susetags.h"
set_checksum(struct parsedata *pd, Repodata *data, Id handle, Id keyname, char *line)
{
char *sp[3];
- int l;
Id type;
if (split(line, sp, 3) != 2)
{
pool_debug(pd->repo->pool, SAT_FATAL, "susetags: bad checksum line: %d: %s\n", pd->lineno, line);
exit(1);
}
- if (!strcasecmp(sp[0], "sha1"))
- l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
- else if (!strcasecmp(sp[0], "sha256"))
- l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
- else if (!strcasecmp(sp[0], "md5"))
- l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
- else
+ type = sat_chksum_str2type(sp[0]);
+ if (!type)
{
pool_debug(pd->repo->pool, SAT_FATAL, "susetags: unknown checksum type: %d: %s\n", pd->lineno, sp[0]);
exit(1);
}
- if (strlen(sp[1]) != l)
+ if (strlen(sp[1]) != 2 * sat_chksum_len(type))
{
pool_debug(pd->repo->pool, SAT_FATAL, "susetags: bad checksum length: %d: for %s: %s\n", pd->lineno, sp[0], sp[1]);
exit(1);
return h->type;
}
+const char *
+sat_chksum_type2str(Id type)
+{
+ switch(type)
+ {
+ case REPOKEY_TYPE_MD5:
+ return "md5";
+ case REPOKEY_TYPE_SHA1:
+ return "sha1";
+ case REPOKEY_TYPE_SHA256:
+ return "sha256";
+ default:
+ return 0;
+ }
+}
+
+Id
+sat_chksum_str2type(const char *str)
+{
+ if (!strcasecmp(str, "md5"))
+ return REPOKEY_TYPE_MD5;
+ if (!strcasecmp(str, "sha") || !strcasecmp(str, "sha1"))
+ return REPOKEY_TYPE_SHA1;
+ if (!strcasecmp(str, "sha256"))
+ return REPOKEY_TYPE_SHA256;
+ return 0;
+}
+
void *
sat_chksum_free(void *handle, unsigned char *cp)
{
Id sat_chksum_get_type(void *handle);
const unsigned char *sat_chksum_get(void *handle, int *lenp);
void *sat_chksum_free(void *handle, unsigned char *cp);
+const char *sat_chksum_type2str(Id type);
+Id sat_chksum_str2type(const char *str);
static inline int sat_chksum_len(Id type)
{
#include "pool.h"
#include "repo.h"
+#include "chksum.h"
#include "repo_repomdxml.h"
#include "common_write.h"
case REPOKEY_TYPE_NUM:
printf("%d\n", di.kv.num);
break;
+ case REPOKEY_TYPE_MD5:
case REPOKEY_TYPE_SHA1:
- printf("sha1:%s\n", repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
- break;
case REPOKEY_TYPE_SHA256:
- printf("sha256:%s\n", repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
+ printf("%s:%s\n", sat_chksum_type2str(di.key->type), repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
break;
default:
break;