g_debug("Generating repomd.xml");
- cr_Repomd repomd_obj = cr_repomd_new();
-
- cr_RepomdRecord pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
- cr_RepomdRecord fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
- cr_RepomdRecord oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
- cr_RepomdRecord pri_db_rec = NULL;
- cr_RepomdRecord fil_db_rec = NULL;
- cr_RepomdRecord oth_db_rec = NULL;
- cr_RepomdRecord groupfile_rec = NULL;
- cr_RepomdRecord compressed_groupfile_rec = NULL;
- cr_RepomdRecord updateinfo_rec = NULL;
+ cr_Repomd *repomd_obj = cr_repomd_new();
+
+ cr_RepomdRecord *pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
+ cr_RepomdRecord *fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
+ cr_RepomdRecord *oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
+ cr_RepomdRecord *pri_db_rec = NULL;
+ cr_RepomdRecord *fil_db_rec = NULL;
+ cr_RepomdRecord *oth_db_rec = NULL;
+ cr_RepomdRecord *groupfile_rec = NULL;
+ cr_RepomdRecord *compressed_groupfile_rec = NULL;
+ cr_RepomdRecord *updateinfo_rec = NULL;
// XML
// Prepare repomd records
- cr_RepomdRecord pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
- cr_RepomdRecord fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
- cr_RepomdRecord oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
- cr_RepomdRecord pri_db_rec = NULL;
- cr_RepomdRecord fil_db_rec = NULL;
- cr_RepomdRecord oth_db_rec = NULL;
- cr_RepomdRecord groupfile_rec = NULL;
- cr_RepomdRecord compressed_groupfile_rec = NULL;
- cr_RepomdRecord update_info_rec = NULL;
- cr_RepomdRecord pkgorigins_rec = NULL;
+ cr_RepomdRecord *pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
+ cr_RepomdRecord *fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
+ cr_RepomdRecord *oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
+ cr_RepomdRecord *pri_db_rec = NULL;
+ cr_RepomdRecord *fil_db_rec = NULL;
+ cr_RepomdRecord *oth_db_rec = NULL;
+ cr_RepomdRecord *groupfile_rec = NULL;
+ cr_RepomdRecord *compressed_groupfile_rec = NULL;
+ cr_RepomdRecord *update_info_rec = NULL;
+ cr_RepomdRecord *pkgorigins_rec = NULL;
// XML
// Gen repomd.xml content
- cr_Repomd repomd_obj = cr_repomd_new();
+ cr_Repomd *repomd_obj = cr_repomd_new();
cr_repomd_set_record(repomd_obj, pri_xml_rec, "primary");
cr_repomd_set_record(repomd_obj, fil_xml_rec, "filelists");
cr_repomd_set_record(repomd_obj, oth_xml_rec, "other");
typedef struct {
PyObject_HEAD
- cr_Repomd repomd;
+ cr_Repomd *repomd;
} _RepomdObject;
static int
typedef struct {
PyObject_HEAD
- cr_RepomdRecord record;
+ cr_RepomdRecord *record;
} _RepomdRecordObject;
-cr_RepomdRecord
+cr_RepomdRecord *
RepomdRecord_FromPyObject(PyObject *o)
{
if (!RepomdRecordObject_Check(o)) {
/* getsetters */
-#define OFFSET(member) (void *) offsetof(struct _cr_RepomdRecord, member)
+#define OFFSET(member) (void *) offsetof(cr_RepomdRecord, member)
static PyObject *
get_long(_RepomdRecordObject *self, void *member_offset)
{
if (check_RepomdRecordStatus(self))
return NULL;
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
gint64 val = *((long *) ((size_t)rec + (size_t) member_offset));
return PyLong_FromLongLong((long long) val);
}
{
if (check_RepomdRecordStatus(self))
return NULL;
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
gint64 val = *((int *) ((size_t)rec + (size_t) member_offset));
return PyLong_FromLongLong((long long) val);
}
{
if (check_RepomdRecordStatus(self))
return NULL;
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
char *str = *((char **) ((size_t) rec + (size_t) member_offset));
if (str == NULL)
Py_RETURN_NONE;
PyErr_SetString(PyExc_ValueError, "Number expected!");
return -1;
}
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
*((long *) ((size_t) rec + (size_t) member_offset)) = val;
return 0;
}
PyErr_SetString(PyExc_ValueError, "Number expected!");
return -1;
}
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
*((int *) ((size_t) rec + (size_t) member_offset)) = (int) val;
return 0;
}
PyErr_SetString(PyExc_ValueError, "String expected!");
return -1;
}
- cr_RepomdRecord rec = self->record;
+ cr_RepomdRecord *rec = self->record;
char *str = g_string_chunk_insert(rec->chunk, PyString_AsString(value));
*((char **) ((size_t) rec + (size_t) member_offset)) = str;
return 0;
#include "src/createrepo_c.h"
extern PyTypeObject RepomdRecord_Type;
-cr_RepomdRecord RepomdRecord_FromPyObject(PyObject *o);
+cr_RepomdRecord *RepomdRecord_FromPyObject(PyObject *o);
#define RepomdRecordObject_Check(o) PyObject_TypeCheck(o, &RepomdRecord_Type)
#include "misc.h"
#include "checksum.h"
#include "repomd.h"
+#include "repomd_internal.h"
#include "compression_wrapper.h"
#define LOCATION_HREF_PREFIX "repodata/"
long size;
} contentStat;
-
-typedef struct _cr_Distro * cr_Distro;
-struct _cr_Distro {
- gchar *cpeid;
- gchar *val;
-};
-
-
-cr_Distro
-cr_new_distro()
+cr_DistroTag *
+cr_distrotag_new()
{
- return (cr_Distro) g_malloc0(sizeof(struct _cr_Distro));
+ return (cr_DistroTag *) g_malloc0(sizeof(cr_DistroTag));
}
-
void
-cr_free_distro(cr_Distro distro)
+cr_distrotag_free(cr_DistroTag *distro)
{
if (!distro) return;
g_free(distro->cpeid);
}
-cr_RepomdRecord
+cr_RepomdRecord *
cr_repomd_record_new(const char *path)
{
- cr_RepomdRecord md = (cr_RepomdRecord) g_malloc0(sizeof(*md));
+ cr_RepomdRecord *md = g_malloc0(sizeof(*md));
md->chunk = g_string_chunk_new(1024);
if (path) {
gchar *filename = cr_get_filename(path);
void
-cr_repomd_record_free(cr_RepomdRecord md)
+cr_repomd_record_free(cr_RepomdRecord *md)
{
if (!md)
return;
int
-cr_repomd_record_fill(cr_RepomdRecord md,
+cr_repomd_record_fill(cr_RepomdRecord *md,
cr_ChecksumType checksum_type,
GError **err)
{
int
-cr_repomd_record_compress_and_fill(cr_RepomdRecord record,
- cr_RepomdRecord crecord,
+cr_repomd_record_compress_and_fill(cr_RepomdRecord *record,
+ cr_RepomdRecord *crecord,
cr_ChecksumType checksum_type,
cr_CompressionType record_compression,
GError **err)
int
-cr_repomd_record_rename_file(cr_RepomdRecord md, GError **err)
+cr_repomd_record_rename_file(cr_RepomdRecord *md, GError **err)
{
int x, len;
gchar *location_prefix = NULL;
void
-cr_repomd_dump_data_items(xmlNodePtr root, cr_RepomdRecord md, const xmlChar *type)
+cr_repomd_dump_data_items(xmlNodePtr root,
+ cr_RepomdRecord *md,
+ const xmlChar *type)
{
xmlNodePtr data, node;
gchar str_buffer[STR_BUFFER_SIZE];
char *
-cr_repomd_xml_dump(cr_Repomd repomd)
+cr_repomd_xml_dump(cr_Repomd *repomd)
{
xmlDocPtr doc;
xmlNodePtr root;
element = repomd->distro_tags;
for (; element; element = g_slist_next(element)) {
xmlNodePtr distro_elem;
- cr_Distro distro = (cr_Distro) element->data;
+ cr_DistroTag *distro = (cr_DistroTag *) element->data;
distro_elem = xmlNewChild(tags,
NULL,
BAD_CAST "distro",
for (element = keys; element; element = g_list_next(element)) {
char *type = element->data;
- cr_RepomdRecord rec = g_hash_table_lookup(repomd->records, type);
+ cr_RepomdRecord *rec = g_hash_table_lookup(repomd->records, type);
cr_repomd_dump_data_items(root, rec, (const xmlChar *) type);
}
}
-cr_Repomd
+cr_Repomd *
cr_repomd_new()
{
- cr_Repomd repomd = g_malloc0(sizeof(struct _cr_Repomd));
+ cr_Repomd *repomd = g_malloc0(sizeof(cr_Repomd));
repomd->records = g_hash_table_new_full(g_str_hash,
g_str_equal,
g_free,
void
-cr_repomd_free(cr_Repomd repomd)
+cr_repomd_free(cr_Repomd *repomd)
{
if (!repomd) return;
g_hash_table_destroy(repomd->records);
cr_slist_free_full(repomd->repo_tags, g_free);
- cr_slist_free_full(repomd->distro_tags, (GDestroyNotify) cr_free_distro);
+ cr_slist_free_full(repomd->distro_tags, (GDestroyNotify) cr_distrotag_free);
cr_slist_free_full(repomd->content_tags, g_free);
g_free(repomd->revision);
g_free(repomd);
void
-cr_repomd_set_record(cr_Repomd repomd,
- cr_RepomdRecord record,
+cr_repomd_set_record(cr_Repomd *repomd,
+ cr_RepomdRecord *record,
const char *type)
{
if (!repomd || !record) return;
void
-cr_repomd_set_revision(cr_Repomd repomd, const char *revision)
+cr_repomd_set_revision(cr_Repomd *repomd, const char *revision)
{
if (!repomd) return;
if (repomd->revision) // A revision string already exists
void
-cr_repomd_add_distro_tag(cr_Repomd repomd, const char *cpeid, const char *tag)
+cr_repomd_add_distro_tag(cr_Repomd *repomd,
+ const char *cpeid,
+ const char *tag)
{
- cr_Distro distro;
+ cr_DistroTag *distro;
if (!repomd || !tag) return;
- distro = cr_new_distro();
+ distro = cr_distrotag_new();
distro->cpeid = g_strdup(cpeid);
distro->val = g_strdup(tag);
repomd->distro_tags = g_slist_prepend(repomd->distro_tags,
void
-cr_repomd_add_repo_tag(cr_Repomd repomd, const char *tag)
+cr_repomd_add_repo_tag(cr_Repomd *repomd, const char *tag)
{
if (!repomd) return;
repomd->repo_tags = g_slist_append(repomd->repo_tags, g_strdup(tag));
void
-cr_repomd_add_content_tag(cr_Repomd repomd, const char *tag)
+cr_repomd_add_content_tag(cr_Repomd *repomd, const char *tag)
{
if (!repomd) return;
repomd->content_tags = g_slist_append(repomd->content_tags, g_strdup(tag));
*
* \code
* char *xml;
- * cr_Repomd md = cr_repomd_new();
- * cr_RepomdRecord rec;
+ * cr_Repomd *md = cr_repomd_new();
+ * cr_RepomdRecord *rec;
*
* // Set some repomd stuff
* cr_repomd_set_revision(md, "007");
* @{
*/
-/** cr_RepomdRecord - object representing an item from repomd.xml
- */
-typedef struct _cr_RepomdRecord * cr_RepomdRecord;
-
-/** cr_Repomd - object representing repomd.xml
- */
-typedef struct _cr_Repomd * cr_Repomd;
-
/** Internal representation of cr_RepomdRecord object
*/
-struct _cr_RepomdRecord {
+typedef struct {
char *location_real; /*!< real path to the file */
char *location_href; /*!< location of the file (in repomd.xml) */
char *checksum; /*!< checksum of file */
int db_ver; /*!< version of database */
GStringChunk *chunk; /*!< string chunk */
-};
+} cr_RepomdRecord;
+
+/** Distro tag structure
+ */
+typedef struct {
+ gchar *cpeid;
+ gchar *val;
+} cr_DistroTag;
/** Internal representation of cr_Repomd object
*/
-struct _cr_Repomd {
- GHashTable *records;
- GSList *repo_tags;
- GSList *distro_tags;
- GSList *content_tags;
+typedef struct {
+ GHashTable *records; /*!< Hash table with cr_RepomdRecord */
+ GSList *repo_tags; /*!< List of strings */
+ GSList *distro_tags; /*!< List of cr_DistroTag* */
+ GSList *content_tags; /*!< List of strings */
gchar *revision;
-};
+} cr_Repomd;
/** Creates (alloc) new cr_RepomdRecord object
* @param path path to the compressed file
*/
-cr_RepomdRecord cr_repomd_record_new(const char *path);
+cr_RepomdRecord *cr_repomd_record_new(const char *path);
/** Destroy cr_RepomdRecord object.
* NOTE: Do NOT use this function on objects attached to cr_Repomd
* (by cr_repomd_set_record).
* @param record cr_RepomdRecord object
*/
-void cr_repomd_record_free(cr_RepomdRecord record);
+void cr_repomd_record_free(cr_RepomdRecord *record);
/** Fill unfilled items in the cr_RepomdRecord (calculate checksums,
* get file size before/after compression, etc.).
* @param err GError **
* @return cr_Error code
*/
-int cr_repomd_record_fill(cr_RepomdRecord record,
+int cr_repomd_record_fill(cr_RepomdRecord *record,
cr_ChecksumType checksum_type,
GError **err);
* @param err GError **
* @return cr_Error code
*/
-int cr_repomd_record_compress_and_fill(cr_RepomdRecord record,
- cr_RepomdRecord compressed_record,
+int cr_repomd_record_compress_and_fill(cr_RepomdRecord *record,
+ cr_RepomdRecord *compressed_record,
cr_ChecksumType checksum_type,
cr_CompressionType compression,
GError **err);
* @param err GError **
* @return cr_Error code
*/
-int cr_repomd_record_rename_file(cr_RepomdRecord record, GError **err);
+int cr_repomd_record_rename_file(cr_RepomdRecord *record, GError **err);
/** Create new empty cr_Repomd object wich represents content of repomd.xml.
*/
-cr_Repomd cr_repomd_new();
+cr_Repomd *cr_repomd_new();
/** Set cr_Repomd record into cr_Repomd object.
* @param repomd cr_Repomd object
* @param record cr_RepomdRecord object
* @param type type of record ("primary, "groupfile", ...)
*/
-void cr_repomd_set_record(cr_Repomd repomd,
- cr_RepomdRecord record,
+void cr_repomd_set_record(cr_Repomd *repomd,
+ cr_RepomdRecord *record,
const char *type);
/** Set custom revision string of repomd.
* @param repomd cr_Repomd object
* @param revision revision string
*/
-void cr_repomd_set_revision(cr_Repomd repomd, const char *revision);
+void cr_repomd_set_revision(cr_Repomd *repomd, const char *revision);
/** Add distro tag.
* @param repomd cr_Repomd object
* @param cpeid cpeid string (could be NULL)
* @param tag distro tag string
*/
-void cr_repomd_add_distro_tag(cr_Repomd repomd,
+void cr_repomd_add_distro_tag(cr_Repomd *repomd,
const char *cpeid,
const char *tag);
* @param repomd cr_Repomd object
* @param tag repo tag
*/
-void cr_repomd_add_repo_tag(cr_Repomd repomd, const char *tag);
+void cr_repomd_add_repo_tag(cr_Repomd *repomd, const char *tag);
/** Add content tag.
* @param repomd cr_Repomd object
* @param tag content tag
*/
-void cr_repomd_add_content_tag(cr_Repomd repomd, const char *tag);
+void cr_repomd_add_content_tag(cr_Repomd *repomd, const char *tag);
/** Frees cr_Repomd object and all its cr_RepomdRecord objects
* @param repomd cr_Repomd object
*/
-void cr_repomd_free(cr_Repomd repomd);
+void cr_repomd_free(cr_Repomd *repomd);
/** Generate repomd.xml content.
* @param repomd cr_Repomd object
* @return string with repomd.xml content
*/
-gchar *cr_repomd_xml_dump(cr_Repomd repomd);
+gchar *cr_repomd_xml_dump(cr_Repomd *repomd);
/** @} */
--- /dev/null
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013 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_REPOMD_INTERNAL_H__
+#define __C_CREATEREPOLIB_REPOMD_INTERNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <string.h>
+#include "error.h"
+
+cr_DistroTag *cr_distrotag_new();
+
+void cr_distrotag_free(cr_DistroTag *distro);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __C_CREATEREPOLIB_REPOMD_INTERNAL_H__ */