add a generic attribute lookup function 'repo_lookup'
authorKlaus Kaempf <kkaempf@suse.de>
Thu, 14 Feb 2008 16:09:57 +0000 (16:09 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Thu, 14 Feb 2008 16:09:57 +0000 (16:09 +0000)
src/repo.c
src/repo.h

index 58fed3c..08b230d 100644 (file)
@@ -795,6 +795,33 @@ repo_lookup_num(Solvable *s, Id key)
   return 0;
 }
 
+
+/*
+ * generic attribute lookup
+ * returns non-zero if found
+ * zero if not found
+ */
+
+int
+repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata)
+{
+  Repo *repo = s->repo;
+  Pool *pool = repo->pool;
+  Repodata *data;
+  int i, s_id;
+
+  s_id = s - pool->solvables;
+  for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+    {
+      if (s_id < data->start || s_id >= data->end)
+       continue;
+      repodata_search (data, s_id - data->start, key, callback, cbdata);
+      return 1;
+    }
+  return 0;
+}
+
+
 Repodata *
 repo_add_repodata(Repo *repo)
 {
index 619e77e..6b823fb 100644 (file)
@@ -167,6 +167,9 @@ void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*c
 const char * repo_lookup_str(Solvable *s, Id key);
 /* returns the integer value of the attribute, or 0 if not found */
 int repo_lookup_num(Solvable *s, Id key);
+/* generic attribute lookup */
+int repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
+
 
 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);