Add minimal API for spec packages and sources
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 1 Oct 2010 12:03:22 +0000 (15:03 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 1 Oct 2010 12:03:22 +0000 (15:03 +0300)
- Iterators for both (these could easily done as self-iteration over
  ->next but to keep the api similar to other rpm iterators...)
- Minimal getters to satisfy python bindings needs

build/rpmspec.h
build/spec.c

index d753116..c52aebb 100644 (file)
@@ -17,6 +17,8 @@ extern "C" {
  */
 typedef struct Package_s * rpmSpecPkg;
 typedef struct Source * rpmSpecSrc;
+typedef struct rpmSpecIter_s * rpmSpecPkgIter;
+typedef struct rpmSpecIter_s * rpmSpecSrcIter;
 
 enum rpmSourceFlags_e {
     RPMBUILD_ISSOURCE  = (1 << 0),
@@ -45,6 +47,24 @@ typedef rpmFlags rpmSpecFlags;
  */
 rpmSpec rpmSpecFree(rpmSpec spec);
 
+/* Iterator for spec packages */
+rpmSpecPkgIter rpmSpecPkgIterInit(rpmSpec spec);
+rpmSpecPkg rpmSpecPkgIterNext(rpmSpecPkgIter iter);
+rpmSpecPkgIter rpmSpecPkgIterFree(rpmSpecPkgIter iter);
+
+/* Getters for spec package attributes */
+Header rpmSpecPkgHeader(rpmSpecPkg pkg);
+
+/* Iterator for spec sources */
+rpmSpecSrcIter rpmSpecSrcIterInit(rpmSpec spec);
+rpmSpecSrc rpmSpecSrcIterNext(rpmSpecSrcIter iter);
+rpmSpecSrcIter rpmSpecSrcIterFree(rpmSpecSrcIter iter);
+
+/* Getters for spec source attributes */
+rpmSourceFlags rpmSpecSrcFlags(rpmSpecSrc src);
+int rpmSpecSrcNum(rpmSpecSrc src);
+const char * rpmSpecSrcFilename(rpmSpecSrc src, int full);
+
 /** \ingroup rpmbuild
  * Function to query spec file(s).
  * @param ts           transaction set
index 0159c20..2de17de 100644 (file)
@@ -331,6 +331,85 @@ rpmps rpmSpecCheckDeps(rpmts ts, rpmSpec spec)
     return probs;
 }
 
+struct rpmSpecIter_s {
+    void *next;
+};
+
+#define SPEC_LISTITER_INIT(_itertype, _iteritem)       \
+    _itertype iter = NULL;                             \
+    if (spec) {                                                \
+       iter = xcalloc(1, sizeof(*iter));               \
+       iter->next = spec->_iteritem;                   \
+    }                                                  \
+    return iter
+
+#define SPEC_LISTITER_NEXT(_valuetype)                 \
+    _valuetype item = NULL;                            \
+    if (iter) {                                                \
+       item = iter->next;                              \
+       iter->next = (item) ? item->next : NULL;        \
+    }                                                  \
+    return item
+
+#define SPEC_LISTITER_FREE()                           \
+    free(iter);                                                \
+    return NULL
+
+
+rpmSpecPkgIter rpmSpecPkgIterInit(rpmSpec spec)
+{
+    SPEC_LISTITER_INIT(rpmSpecPkgIter, packages);
+}
+
+rpmSpecPkgIter rpmSpecPkgIterFree(rpmSpecPkgIter iter)
+{
+    SPEC_LISTITER_FREE();
+}
+
+rpmSpecPkg rpmSpecPkgIterNext(rpmSpecPkgIter iter)
+{
+    SPEC_LISTITER_NEXT(rpmSpecPkg);
+}
+
+Header rpmSpecPkgHeader(rpmSpecPkg pkg)
+{
+    return (pkg != NULL) ? pkg->header : NULL;
+}
+
+rpmSpecSrcIter rpmSpecSrcIterInit(rpmSpec spec)
+{
+    SPEC_LISTITER_INIT(rpmSpecSrcIter, sources);
+}
+
+rpmSpecSrcIter rpmSpecSrcIterFree(rpmSpecSrcIter iter)
+{
+    SPEC_LISTITER_FREE();
+}
+
+rpmSpecSrc rpmSpecSrcIterNext(rpmSpecSrcIter iter)
+{
+    SPEC_LISTITER_NEXT(rpmSpecSrc);
+}
+
+rpmSourceFlags rpmSpecSrcFlags(rpmSpecSrc src)
+{
+    return (src != NULL) ? src->flags : 0;
+}
+
+int rpmSpecSrcNum(rpmSpecSrc src)
+{
+    return (src != NULL) ? src->num : -1;
+}
+
+const char * rpmSpecSrcFilename(rpmSpecSrc src, int full)
+{
+    const char *source = NULL;
+    if (src) {
+       source = full ? src->fullSource : src->source;
+    }
+    return source;
+}
+
 int rpmspecQuery(rpmts ts, QVA_t qva, const char * arg)
 {
     rpmSpec spec = NULL;