updateinfo: Add updateinfo module with datatype definitions
authorTomas Mlcoch <tmlcoch@redhat.com>
Wed, 30 Jul 2014 12:39:06 +0000 (14:39 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Wed, 30 Jul 2014 13:23:14 +0000 (15:23 +0200)
src/CMakeLists.txt
src/createrepo_c.h
src/updateinfo.c [new file with mode: 0644]
src/updateinfo.h [new file with mode: 0644]

index a795ac8..91aba3e 100644 (file)
@@ -15,6 +15,7 @@ SET (createrepo_c_SRCS
      repomd.c
      sqlite.c
      threads.c
+     updateinfo.c
      xml_dump.c
      xml_dump_deltapackage.c
      xml_dump_filelists.c
@@ -46,6 +47,7 @@ SET(headers
     repomd.h
     sqlite.h
     threads.h
+    updateinfo.h
     version.h
     xml_dump.h
     xml_file.h
index 3bf35a4..d2f50a3 100644 (file)
@@ -52,6 +52,7 @@ extern "C" {
 #include "repomd.h"
 #include "sqlite.h"
 #include "threads.h"
+#include "updateinfo.h"
 #include "version.h"
 #include "xml_dump.h"
 #include "xml_file.h"
diff --git a/src/updateinfo.c b/src/updateinfo.c
new file mode 100644 (file)
index 0000000..c68422b
--- /dev/null
@@ -0,0 +1,168 @@
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2014  Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include <glib.h>
+#include <errno.h>
+#include <string.h>
+#include <assert.h>
+#include "updateinfo.h"
+#include "error.h"
+#include "misc.h"
+#include "checksum.h"
+
+
+/*
+ * cr_UpdateCollectionPackage
+ */
+
+cr_UpdateCollectionPackage *
+cr_updatecollectionpackage_new(void)
+{
+    cr_UpdateCollectionPackage *pkg = g_malloc0(sizeof(*pkg));
+    return pkg;
+}
+
+void
+cr_updatecollectionpackage_free(cr_UpdateCollectionPackage *pkg)
+{
+    if (!pkg)
+        return;
+    g_string_chunk_free(pkg->chunk);
+    g_free(pkg);
+}
+
+
+/*
+ * cr_UpdateCollection
+ */
+
+cr_UpdateCollection *
+cr_updatecollection_new(void)
+{
+    cr_UpdateCollection *collection = g_malloc0(sizeof(*collection));
+    return collection;
+}
+
+void
+cr_updatecollection_free(cr_UpdateCollection *collection)
+{
+    if (!collection)
+        return;
+    cr_slist_free_full(collection->packages,
+                       (GDestroyNotify) cr_updatecollectionpackage_free);
+    g_string_chunk_free(collection->chunk);
+    g_free(collection);
+}
+
+void
+cr_updatecollection_append_package(cr_UpdateCollection *collection,
+                                   cr_UpdateCollectionPackage *pkg)
+{
+    if (!collection || !pkg) return;
+    collection->packages = g_slist_append(collection->packages, pkg);
+}
+
+
+/*
+ * cr_UpdateReference
+ */
+
+cr_UpdateReference *
+cr_updatereference_new(void)
+{
+    cr_UpdateReference *ref = g_malloc0(sizeof(*ref));
+    return ref;
+}
+
+void
+cr_updatereference_free(cr_UpdateReference *ref)
+{
+    if (!ref)
+        return;
+    g_string_chunk_free(ref->chunk);
+    g_free(ref);
+}
+
+
+/*
+ * cr_UpdateRecord
+ */
+
+cr_UpdateRecord *
+cr_updaterecord_new(void)
+{
+    cr_UpdateRecord *rec = g_malloc0(sizeof(*rec));
+    return rec;
+}
+
+void
+cr_updaterecord_free(cr_UpdateRecord *rec)
+{
+    if (!rec)
+        return;
+    cr_slist_free_full(rec->references, (GDestroyNotify) cr_updatereference_free);
+    cr_slist_free_full(rec->collections, (GDestroyNotify) cr_updatecollection_free);
+    g_string_chunk_free(rec->chunk);
+    g_free(rec);
+}
+
+void
+cr_updaterecord_append_reference(cr_UpdateRecord *record,
+                                 cr_UpdateReference *ref)
+{
+    if (!record || !ref) return;
+    record->references = g_slist_append(record->references, ref);
+}
+
+void
+cr_updaterecord_append_collection(cr_UpdateRecord *record,
+                                  cr_UpdateCollection *collection)
+{
+    if (!record || !collection) return;
+    record->collections = g_slist_append(record->collections, record);
+}
+
+
+/*
+ * cr_Updateinfo
+ */
+
+cr_UpdateInfo *
+cr_updateinfo_new(void)
+{
+    cr_UpdateInfo *uinfo = g_malloc0(sizeof(*uinfo));
+    return uinfo;
+}
+
+void
+cr_updateinfo_free(cr_UpdateInfo *uinfo)
+{
+    if (!uinfo)
+        return;
+    cr_slist_free_full(uinfo->updates, (GDestroyNotify) cr_updaterecord_free);
+    g_free(uinfo);
+}
+
+void
+cr_updateinfo_apped_record(cr_UpdateInfo *uinfo, cr_UpdateRecord *record)
+{
+    if (!uinfo || !record) return;
+    uinfo->updates = g_slist_append(uinfo->updates, record);
+}
+
diff --git a/src/updateinfo.h b/src/updateinfo.h
new file mode 100644 (file)
index 0000000..ebe6e1d
--- /dev/null
@@ -0,0 +1,167 @@
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2014  Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#ifndef __C_CREATEREPOLIB_UPDATEINFO_H__
+#define __C_CREATEREPOLIB_UPDATEINFO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+#include "checksum.h"
+
+/** \defgroup   updateinfo            Updateinfo API.
+ *
+ * Module for generating updateinfo.xml.
+ *
+ *  \addtogroup updateinfo
+ *  @{
+ */
+
+typedef struct {
+    gchar *name;
+    gchar *version;
+    gchar *release;
+    gchar *epoch;
+    gchar *arch;
+    gchar *src;
+    gchar *filename;
+    gchar *sum;
+    cr_ChecksumType sum_type;
+    gboolean reboot_suggested;
+
+    GStringChunk *chunk;
+} cr_UpdateCollectionPackage;
+
+typedef struct {
+    gchar *shortname;   /*!< e.g. rhn-tools-rhel-x86_64-server-6.5.aus */
+    gchar *name;        /*!< e.g. RHN Tools for RHEL AUS (v. 6.5 for 64-bit x86_64) */
+    GSList *packages;   /*!< List of cr_UpdateCollectionPackage */
+    GStringChunk *chunk;
+} cr_UpdateCollection;
+
+typedef struct {
+    gchar *id;      /*!< id (e.g. 1035288, NULL for errata, ...) */
+    gchar *href;    /*!< URL (e.g. to related bugzilla, errata, ...) */
+    gchar *type;    /*!< reference type ("self" for errata, "bugzilla", ...) */
+    gchar *title;   /*!< Name of errata, name of bug, etc. */
+    GStringChunk *chunk;
+} cr_UpdateReference;
+
+typedef struct {
+    gchar *from;        /*!< Source of the update (e.g. security@redhat.com) */
+    gchar *type;        /*!< Update type ("enhancement", "bugfix", ...) */
+    gchar *title;       /*!< Update name */
+    gchar *status;      /*!< Update status ("final", ...) */
+    gchar *version;     /*!< Update version (probably always an integer number) */
+    gchar *id;          /*!< Update id (short update name, e.g. RHEA-2013:1777) */
+    gchar *issued_date; /*!< Date string (e.g. "2013-12-02 00:00:00") */
+    gchar *updated_date;/*!< Date string */
+    gchar *rights;      /*!< Copyright */
+    gchar *release;     /*!< Release */
+    gchar *pushcount;   /*!< Push count */
+    gchar *severity;    /*!< Severity */
+    gchar *summary;     /*!< Short summary */
+    gchar *description; /*!< Update description */
+    gchar *solution;    /*!< Solution */
+    gboolean *reboot_suggested;/*!< Reboot suggested */
+
+    GSList *references; /*!< List of cr_UpdateReference */
+    GSList *collections;/*!< List of cr_UpdateCollection */
+
+    GStringChunk *chunk;/*!< String chunk */
+} cr_UpdateRecord;
+
+typedef struct {
+    GSList *updates;    /*!< List of cr_UpdateRecord */
+} cr_UpdateInfo;
+
+/*
+ * cr_UpdateCollectionPackage
+ */
+
+cr_UpdateCollectionPackage *
+cr_updatecollectionpackage_new(void);
+
+void
+cr_updatecollectionpackage_free(cr_UpdateCollectionPackage *pkg);
+
+/*
+ * cr_UpdateCollection
+ */
+
+cr_UpdateCollection *
+cr_updatecollection_new(void);
+
+void
+cr_updatecollection_free(cr_UpdateCollection *collection);
+
+void
+cr_updatecollection_append_package(cr_UpdateCollection *collection,
+                                   cr_UpdateCollectionPackage *pkg);
+
+/*
+ * cr_UpdateReference
+ */
+
+cr_UpdateReference *
+cr_updatereference_new(void);
+
+void
+cr_updatereference_free(cr_UpdateReference *ref);
+
+/*
+ * cr_UpdateRecord
+ */
+
+cr_UpdateRecord *
+cr_updaterecord_new(void);
+
+void
+cr_updaterecord_free(cr_UpdateRecord *record);
+
+void
+cr_updaterecord_append_reference(cr_UpdateRecord *record,
+                                 cr_UpdateReference *ref);
+
+void
+cr_updaterecord_append_collection(cr_UpdateRecord *record,
+                                  cr_UpdateCollection *collection);
+
+/*
+ * cr_Updateinfo
+ */
+
+cr_UpdateInfo *
+cr_updateinfo_new(void);
+
+void
+cr_updateinfo_free(cr_UpdateInfo *uinfo);
+
+void
+cr_updateinfo_apped_record(cr_UpdateInfo *uinfo, cr_UpdateRecord *record);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __C_CREATEREPOLIB_UPDATEINFO_H__ */