expose repo_lookup_str and add lookup_num (nonworking)
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 6 Feb 2008 02:08:15 +0000 (02:08 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 6 Feb 2008 02:08:15 +0000 (02:08 +0000)
src/repo.c
src/repo.h
src/repodata.c
src/repodata.h

index fd6abe3..9a78a3f 100644 (file)
@@ -766,6 +766,28 @@ repo_lookup_str(Solvable *s, Id key)
   return 0;
 }
 
+int
+repo_lookup_num(Solvable *s, Id key)
+{
+  Repo *repo = s->repo;
+  Pool *pool = repo->pool;
+  Repodata *data;
+  int i, j, n;
+
+  n = s - pool->solvables;
+  for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+    {
+      if (n < data->start || n >= data->end)
+       continue;
+      for (j = 1; j < data->nkeys; j++)
+       {
+         if (data->keys[j].name == key && (data->keys[j].type == TYPE_U32 || data->keys[j].type == TYPE_NUM))
+           return repodata_lookup_num(data, n - data->start, j);
+       }
+    }
+  return 0;
+}
+
 Repodata *
 repo_add_repodata(Repo *repo)
 {
index 34b100e..4deecc9 100644 (file)
@@ -163,6 +163,11 @@ typedef struct _KeyValue {
 Repodata *repo_add_repodata(Repo *repo);
 void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
 
+/* returns the string value of the attribute, or NULL if not found */
+const char * repo_lookup_str(Solvable *s, Id key);
+/* returns the string value of the attribute, or 0 if not found */
+int repo_lookup_num(Solvable *s, Id key);
+
 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
index 5bf576c..3a97470 100644 (file)
@@ -430,6 +430,34 @@ repodata_lookup_str(Repodata *data, Id entry, Id keyid)
   return id2str(data->repo->pool, id);
 }
 
+int
+repodata_lookup_num(Repodata *data, Id entry, Id keyid)
+{
+  Id schema;
+  Repokey *key;
+  Id *keyp;
+  KeyValue kv;
+  unsigned char *dp;
+
+  dp = data->incoredata + data->incoreoffset[entry];
+  dp = data_read_id(dp, &schema);
+  /* make sure the schema of this solvable contains the key */
+  for (keyp = data->schemadata + data->schemata[schema]; *keyp != keyid; keyp++)
+    if (!*keyp)
+      return 0;
+  dp = forward_to_key(data, keyid, schema, dp);
+  key = data->keys + keyid;
+  dp = get_data(data, key, &dp);
+  if (!dp)
+    return 0;
+  if (key->type == TYPE_NUM || key->type == TYPE_U32)
+  {
+    dp = data_fetch(dp, &kv, key);
+    return kv.num;
+  }
+  return 0;
+}
+
 void
 repodata_search(Repodata *data, Id entry, Id keyname, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata)
 {
index e4fb9e2..ec1d081 100644 (file)
@@ -101,6 +101,7 @@ typedef struct _Repodata {
 
 void repodata_search(Repodata *data, Id entry, Id keyname, int (*callback)(void *cbdata, Solvable *s, Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyid);
+int repodata_lookup_num(Repodata *data, Id entry, Id keyid);
 
 void repodata_extend(Repodata *data, Id p);