From 7128eac364dd089757d7298e41e84bf070ccd9eb Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Thu, 15 Dec 2011 13:15:23 +0100 Subject: [PATCH] Hou hou! "Seems to be working" implementation! --- Makefile | 4 ++-- package.c | 10 +++++++++ package.h | 1 + package.i | 4 +++- xml_dump.c | 15 +++++++------ xml_dump.i | 5 ++++- xml_dump_filelists.c | 23 ++++++++++++------- xml_dump_other.c | 34 ++++++++++++++++++---------- xml_dump_primary.c | 62 +++++++++++++++++++++++++++++++++------------------- 9 files changed, 105 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 283f2d2..98eb880 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ xml_dump_other.o: xml_dump_other.c xml_dump.h package.so: package_wrap.o package.o ld $(LINKFLAGS) -shared package.o package_wrap.o -o _package.so -xml_dump.so: xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o - ld $(LINKFLAGS) -shared xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _xml_dump.so +xml_dump.so: package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o + ld $(LINKFLAGS) -shared package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _xml_dump.so main: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o gcc $(LINKFLAGS) $(CFLAGS) package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o main.c -o main diff --git a/package.c b/package.c index dfd9ed9..b283cd9 100644 --- a/package.c +++ b/package.c @@ -97,3 +97,13 @@ package_free (Package *package) g_free (package); } + +void +package_add_changelog (Package *package, ChangelogEntry *entry) +{ + ChangelogEntry *f = changelog_entry_new(); + f->author = g_string_chunk_insert(package->chunk, entry->author); + f->date = entry->date; + f->changelog = g_string_chunk_insert(package->chunk, entry->changelog); + package->changelogs = g_slist_append (package->changelogs, f); +} diff --git a/package.h b/package.h index 93b1b6c..4d6b550 100644 --- a/package.h +++ b/package.h @@ -69,5 +69,6 @@ PackageFile *package_file_new (void); ChangelogEntry *changelog_entry_new (void); Package *package_new (void); void package_free (Package *package); +void package_add_changelog (Package *, ChangelogEntry *); #endif /* __YUM_PACKAGE_H__ */ diff --git a/package.i b/package.i index ecce25b..fe35d76 100644 --- a/package.i +++ b/package.i @@ -1,8 +1,10 @@ %module package +%include + %{ #include "package.h" %} -%include "package.h" +//%include "package.h" diff --git a/xml_dump.c b/xml_dump.c index b78662d..14c67b3 100644 --- a/xml_dump.c +++ b/xml_dump.c @@ -3,6 +3,9 @@ #include #include "xml_dump.h" +//#define DEBUG +#undef DEBUG + //xmlCharEncodingHandlerPtr handler = NULL; xmlChar * @@ -19,7 +22,6 @@ ConvertInput(const char *in, xmlCharEncodingHandlerPtr handler) } if (!handler) { -// printf("Nic neprevadim\n"); return (xmlChar*) in; } @@ -33,9 +35,7 @@ ConvertInput(const char *in, xmlCharEncodingHandlerPtr handler) if (out != NULL) { temp = size - 1; -// printf("JDU PREVADET\n"); ret = handler->input(out, &out_size, (const xmlChar *) in, &temp); -// printf("JDU PREVADET\n"); if ((ret < 0) || (temp - size + 1)) { if (ret < 0) { printf("ConvertInput: conversion wasn't successful.\n"); @@ -87,7 +87,6 @@ dump_files(xmlTextWriterPtr writer, Package *package, int primary, GSList *element = NULL; for(element = package->files; element; element=element->next) { - PackageFile *entry = (PackageFile*) element->data; if (primary) { @@ -117,7 +116,7 @@ dump_files(xmlTextWriterPtr writer, Package *package, int primary, } // Write type - if (entry->type && strlen(entry->type)) { + if (entry->type && strlen(entry->type) && strcmp(entry->type, "file")) { tmp = ConvertInput(entry->type, handler); rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type", tmp); if (rc < 0) { @@ -129,8 +128,10 @@ dump_files(xmlTextWriterPtr writer, Package *package, int primary, // Write text (file path) tmp = ConvertInput(entry->name, handler); - xmlTextWriterWriteString(writer, BAD_CAST tmp); - if (handler && tmp != NULL) xmlFree(tmp); + if (tmp) { + xmlTextWriterWriteString(writer, BAD_CAST tmp); + if (handler && tmp != NULL) xmlFree(tmp); + } // Close file element rc = xmlTextWriterEndElement(writer); diff --git a/xml_dump.i b/xml_dump.i index 126f37b..cc9995f 100644 --- a/xml_dump.i +++ b/xml_dump.i @@ -1,6 +1,9 @@ %module xml_dump +%include + %{ +#include "package.h" #include "xml_dump.h" %} @@ -8,4 +11,4 @@ char *xml_dump_primary(Package *, const char *); char *xml_dump_filelists(Package *, const char *); -char *xml_dump_other(Package *, const char *); \ No newline at end of file +char *xml_dump_other(Package *, const char *); diff --git a/xml_dump_filelists.c b/xml_dump_filelists.c index bee7346..f4f48af 100644 --- a/xml_dump_filelists.c +++ b/xml_dump_filelists.c @@ -29,6 +29,7 @@ void dump_filelists_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandlerPtr handler) { int rc; + char n[] = ""; xmlChar *tmp = NULL; gchar *tmp2 = NULL; @@ -54,28 +55,31 @@ dump_filelists_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingH /* Add an attribute to package */ tmp = ConvertInput(package->pkgId, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); tmp = ConvertInput(package->name, handler); - rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); + if (!tmp) tmp = n; + rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); tmp = ConvertInput(package->arch, handler); - rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); + if (!tmp) tmp = n; + rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "arch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: version @@ -88,30 +92,33 @@ dump_filelists_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingH /* Write version attribute epoch */ tmp = ConvertInput(package->epoch, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "epoch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute ver */ tmp = ConvertInput(package->version, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ver", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute rel */ tmp = ConvertInput(package->release, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "rel", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Close version element */ rc = xmlTextWriterEndElement(writer); diff --git a/xml_dump_other.c b/xml_dump_other.c index 2655a95..b93fb67 100644 --- a/xml_dump_other.c +++ b/xml_dump_other.c @@ -23,6 +23,8 @@ dump_changelog(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandler printf("CALLED dump_changelog\n"); #endif + int rc; + char n[] = ""; xmlChar *tmp = NULL; gchar *tmp2 = NULL; @@ -34,11 +36,10 @@ dump_changelog(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandler for(element = package->changelogs; element; element=element->next) { ChangelogEntry *entry = (ChangelogEntry*) element->data; + // *********************************** // Element: file // ************************************ - - int rc; rc = xmlTextWriterStartElement(writer, BAD_CAST "changelog"); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); @@ -47,12 +48,13 @@ dump_changelog(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandler // Write param author tmp = ConvertInput(entry->author, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "author", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); // Write param date tmp2 = g_strdup_printf("%d", entry->date); @@ -65,8 +67,9 @@ dump_changelog(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandler // Write text (file path) tmp = ConvertInput(entry->changelog, handler); + if (!tmp) tmp = n; xmlTextWriterWriteString(writer, BAD_CAST tmp); - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); // Close file element rc = xmlTextWriterEndElement(writer); @@ -91,6 +94,7 @@ void dump_other_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandlerPtr handler) { int rc; + char n[] = ""; xmlChar *tmp = NULL; gchar *tmp2 = NULL; @@ -116,28 +120,31 @@ dump_other_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandl /* Add an attribute to package */ tmp = ConvertInput(package->pkgId, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); tmp = ConvertInput(package->name, handler); - rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); + if (!tmp) tmp = n; + rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); tmp = ConvertInput(package->arch, handler); - rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); + if (!tmp) tmp = n; + rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "arch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: version @@ -150,30 +157,33 @@ dump_other_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandl /* Write version attribute epoch */ tmp = ConvertInput(package->epoch, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "epoch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute ver */ tmp = ConvertInput(package->version, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ver", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute rel */ tmp = ConvertInput(package->release, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "rel", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Close version element */ rc = xmlTextWriterEndElement(writer); diff --git a/xml_dump_primary.c b/xml_dump_primary.c index 655cae9..5c92193 100644 --- a/xml_dump_primary.c +++ b/xml_dump_primary.c @@ -178,6 +178,7 @@ void dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandlerPtr handler) { int rc; + char n[] = ""; xmlChar *tmp = NULL; gchar *tmp2 = NULL; @@ -191,7 +192,6 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle return; } - /*********************************** Element: package ************************************/ @@ -212,23 +212,25 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle Element: name ************************************/ tmp = ConvertInput(package->name, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "name", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: arch ************************************/ tmp = ConvertInput(package->arch, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "arch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: version @@ -241,30 +243,33 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle /* Write version attribute epoch */ tmp = ConvertInput(package->epoch, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "epoch", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute ver */ tmp = ConvertInput(package->version, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ver", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write version attribute rel */ tmp = ConvertInput(package->release, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "rel", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Close version element */ rc = xmlTextWriterEndElement(writer); @@ -284,30 +289,33 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle /* Write checksum attribute pkgid */ tmp = ConvertInput("YES", handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "pkgid", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write checksum attribute checksum_type */ tmp = ConvertInput(package->checksum_type, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write element string */ tmp = ConvertInput(package->pkgId, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteString(writer, BAD_CAST tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteString\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Close checksum element */ rc = xmlTextWriterEndElement(writer); @@ -320,45 +328,49 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle Element: summary ************************************/ tmp = ConvertInput(package->summary, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "summary", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: description ************************************/ tmp = ConvertInput(package->description, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "description", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: packager ************************************/ tmp = ConvertInput(package->rpm_packager, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "packager", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: url ************************************/ tmp = ConvertInput(package->url, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "url", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: time @@ -448,23 +460,25 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle /* Write location attribute href */ tmp = ConvertInput(package->location_href, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "href", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Write location attribute base */ tmp = ConvertInput(package->location_base, handler); - if (strlen(package->location_base)) { + if (!tmp) tmp = n; + if (package->location_base && strlen(package->location_base)) { rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "base", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteAttribute\n"); return; } } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /* Close location element */ rc = xmlTextWriterEndElement(writer); @@ -486,56 +500,61 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle Element: license ************************************/ tmp = ConvertInput(package->rpm_license, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "rpm:license", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: vendor ************************************/ tmp = ConvertInput(package->rpm_vendor, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "rpm:vendor", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: group ************************************/ tmp = ConvertInput(package->rpm_group, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "rpm:group", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: buildhost ************************************/ tmp = ConvertInput(package->rpm_buildhost, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "rpm:buildhost", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: sourcerpm ************************************/ tmp = ConvertInput(package->rpm_sourcerpm, handler); + if (!tmp) tmp = n; rc = xmlTextWriterWriteElement(writer, BAD_CAST "rpm:sourcerpm", tmp); if (rc < 0) { printf("Error at xmlTextWriterWriteElement\n"); return; } - if (handler && tmp != NULL) xmlFree(tmp); + if (handler && tmp != NULL && tmp != n) xmlFree(tmp); /*********************************** Element: header-range @@ -571,7 +590,6 @@ dump_base_items(xmlTextWriterPtr writer, Package *package, xmlCharEncodingHandle return; } - /* Files dump */ dump_pco(writer, package, PROVIDES, handler); dump_pco(writer, package, REQUIRES, handler); -- 2.7.4