* This module has one known issue about a memory management.
* The issue acts in cases when you are using one single string chunk
* for all parsed packages.
- * (use_single_chunk != 0 during call of cr_new_metadata())
+ * (use_single_chunk != 0 during call of cr_metadata_new())
*
* Description of issue:
* During parsing of primary.xml, all string from obtained during parsing are
* stored into the chunk. When we have all the information from primary.xml and
* we found out that we don't want the package (according the pkglist passed
- * via cr_new_metadata) and we drop the package (package is not inserted
+ * via cr_metadata_new) and we drop the package (package is not inserted
* into the hashtable of metadatas), all strings from primary.xml are yet
* stored in the chunk and they remains there!
*
void
-free_values(gpointer data)
+cr_free_values(gpointer data)
{
cr_package_free((cr_Package *) data);
}
cr_new_metadata_hashtable()
{
GHashTable *hashtable = g_hash_table_new_full(g_str_hash, g_str_equal,
- NULL, free_values);
+ NULL, cr_free_values);
return hashtable;
}
cr_Metadata
-cr_new_metadata(cr_HashTableKey key, int use_single_chunk, GSList *pkglist)
+cr_metadata_new(cr_HashTableKey key, int use_single_chunk, GSList *pkglist)
{
cr_Metadata md = g_malloc0(sizeof(*md));
md->key = key;
void
-cr_destroy_metadata(cr_Metadata md)
+cr_metadata_free(cr_Metadata md)
{
if (!md)
return;
inline gchar *
-chunk_insert_len_or_null (GStringChunk *chunk, const gchar *str, gssize len)
+cr_chunk_insert_len_or_null (GStringChunk *chunk, const gchar *str, gssize len)
{
if (!str || len <= 0)
return NULL;
// primary.xml parser handlers
void
-pri_start_handler(void *data, const char *el, const char **attr)
+cr_pri_start_handler(void *data, const char *el, const char **attr)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
void
-pri_char_handler(void *data, const char *txt, int txtlen)
+cr_pri_char_handler(void *data, const char *txt, int txtlen)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
void
-pri_end_handler(void *data, const char *el)
+cr_pri_end_handler(void *data, const char *el)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
switch (ppd->last_elem) {
case NAME_ELEM:
- pkg->name = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->name = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case ARCH_ELEM:
- pkg->arch = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->arch = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case CHECKSUM_ELEM:
- pkg->pkgId = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->pkgId = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case SUMMARY_ELEM:
- pkg->summary = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->summary = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case DESCRIPTION_ELEM:
- pkg->description = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->description = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case PACKAGER_ELEM:
- pkg->rpm_packager = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_packager = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case URL_ELEM:
- pkg->url = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->url = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case RPM_LICENSE_ELEM:
- pkg->rpm_license = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_license = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case RPM_VENDOR_ELEM:
- pkg->rpm_vendor = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_vendor = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case RPM_GROUP_ELEM:
- pkg->rpm_group = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_group = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case RPM_BUILDHOST_ELEM:
- pkg->rpm_buildhost = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_buildhost = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case RPM_SOURCERPM_ELEM:
- pkg->rpm_sourcerpm = chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
+ pkg->rpm_sourcerpm = cr_chunk_insert_len_or_null(pkg->chunk, txt, txtlen);
break;
case FILE_ELEM:
case FILE_DIR_ELEM:
// filelists.xml parser handlers
void
-fil_start_handler(void *data, const char *el, const char **attr)
+cr_fil_start_handler(void *data, const char *el, const char **attr)
{
int i;
struct ParserData *ppd = (struct ParserData *) data;
void
-fil_char_handler(void *data, const char *txt, int txtlen)
+cr_fil_char_handler(void *data, const char *txt, int txtlen)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
void
-fil_end_handler(void *data, const char *el)
+cr_fil_end_handler(void *data, const char *el)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
// other.xml parser handlers
void
-oth_start_handler(void *data, const char *el, const char **attr)
+cr_oth_start_handler(void *data, const char *el, const char **attr)
{
int i;
struct ParserData *ppd = (struct ParserData *) data;
void
-oth_char_handler(void *data, const char *txt, int txtlen)
+cr_oth_char_handler(void *data, const char *txt, int txtlen)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
void
-oth_end_handler(void *data, const char *el)
+cr_oth_end_handler(void *data, const char *el)
{
struct ParserData *ppd = (struct ParserData *) data;
cr_Package *pkg = ppd->pkg;
int
-load_xml_files(GHashTable *hashtable, const char *primary_xml_path,
+cr_load_xml_files(GHashTable *hashtable, const char *primary_xml_path,
const char *filelists_xml_path, const char *other_xml_path,
GStringChunk *chunk, GHashTable *pkglist_ht)
{
pri_p = XML_ParserCreate(NULL);
XML_SetUserData(pri_p, (void *) &parser_data);
- XML_SetElementHandler(pri_p, pri_start_handler, pri_end_handler);
- XML_SetCharacterDataHandler(pri_p, pri_char_handler);
+ XML_SetElementHandler(pri_p, cr_pri_start_handler, cr_pri_end_handler);
+ XML_SetCharacterDataHandler(pri_p, cr_pri_char_handler);
fil_p = XML_ParserCreate(NULL);
XML_SetUserData(fil_p, (void *) &parser_data);
- XML_SetElementHandler(fil_p, fil_start_handler, fil_end_handler);
- XML_SetCharacterDataHandler(fil_p, fil_char_handler);
+ XML_SetElementHandler(fil_p, cr_fil_start_handler, cr_fil_end_handler);
+ XML_SetCharacterDataHandler(fil_p, cr_fil_char_handler);
oth_p = XML_ParserCreate(NULL);
XML_SetUserData(oth_p, (void *) &parser_data);
- XML_SetElementHandler(oth_p, oth_start_handler, oth_end_handler);
- XML_SetCharacterDataHandler(oth_p, oth_char_handler);
+ XML_SetElementHandler(oth_p, cr_oth_start_handler, cr_oth_end_handler);
+ XML_SetCharacterDataHandler(oth_p, cr_oth_char_handler);
// Parse
int
-cr_load_xml_metadata(cr_Metadata md, struct cr_MetadataLocation *ml)
+cr_metadata_load_xml(cr_Metadata md, struct cr_MetadataLocation *ml)
{
if (!md || !ml)
return CR_LOAD_METADATA_ERR;
GHashTable *intern_hashtable; // key is checksum (pkgId)
intern_hashtable = cr_new_metadata_hashtable();
- result = load_xml_files(intern_hashtable, ml->pri_xml_href,
+ result = cr_load_xml_files(intern_hashtable, ml->pri_xml_href,
ml->fil_xml_href, ml->oth_xml_href,
md->chunk, md->pkglist_ht);
int
-cr_locate_and_load_xml_metadata(cr_Metadata md, const char *repopath)
+cr_metadata_locate_and_load_xml(cr_Metadata md, const char *repopath)
{
if (!md || !repopath)
return CR_LOAD_METADATA_ERR;
int ret;
struct cr_MetadataLocation *ml = cr_locate_metadata(repopath, 1);
- ret = cr_load_xml_metadata(md, ml);
+ ret = cr_metadata_load_xml(md, ml);
cr_metadatalocation_free(ml);
return ret;
GHashTableIter iter;
gpointer key, value;
- metadata = cr_new_metadata(CR_HT_KEY_HASH, 0, NULL);
+ metadata = cr_metadata_new(CR_HT_KEY_HASH, 0, NULL);
ml = (struct cr_MetadataLocation *) element->data;
- if (cr_load_xml_metadata(metadata, ml) == CR_LOAD_METADATA_ERR) {
- cr_destroy_metadata(metadata);
+ if (cr_metadata_load_xml(metadata, ml) == CR_LOAD_METADATA_ERR) {
+ cr_metadata_free(metadata);
g_critical("Cannot load repo: \"%s\"", ml->original_url);
repoid++;
break;
cr_nvrea_free(nvrea);
}
- cr_destroy_metadata(metadata);
+ cr_metadata_free(metadata);
repoid++;
}
cr_Metadata metadata; // current repodata
struct cr_MetadataLocation *ml; // location of current repodata
- metadata = cr_new_metadata(CR_HT_KEY_HASH, 0, NULL);
+ metadata = cr_metadata_new(CR_HT_KEY_HASH, 0, NULL);
ml = (struct cr_MetadataLocation *) element->data;
repopath = cr_normalize_dir_path(ml->original_url);
g_debug("Processing: %s", repopath);
- if (cr_load_xml_metadata(metadata, ml) == CR_LOAD_METADATA_ERR) {
- cr_destroy_metadata(metadata);
+ if (cr_metadata_load_xml(metadata, ml) == CR_LOAD_METADATA_ERR) {
+ cr_metadata_free(metadata);
g_critical("Cannot load repo: \"%s\"", ml->repomd);
break;
}
}
loaded_packages += repo_loaded_packages;
- cr_destroy_metadata(metadata);
+ cr_metadata_free(metadata);
g_debug("Repo: %s (Loaded: %ld Used: %ld)", repopath,
(unsigned long) original_size, repo_loaded_packages);
g_free(repopath);
struct cr_MetadataLocation *noarch_ml;
noarch_ml = cr_locate_metadata(cmd_options->noarch_repo_url, 1);
- noarch_metadata = cr_new_metadata(CR_HT_KEY_FILENAME, 0, NULL);
+ noarch_metadata = cr_metadata_new(CR_HT_KEY_FILENAME, 0, NULL);
// Base paths in output of original createrepo doesn't have trailing '/'
gchar *noarch_repopath = cr_normalize_dir_path(noarch_ml->original_url);
g_debug("Loading noarch_repo: %s", noarch_repopath);
- if (cr_load_xml_metadata(noarch_metadata, noarch_ml) == CR_LOAD_METADATA_ERR) {
+ if (cr_metadata_load_xml(noarch_metadata, noarch_ml) == CR_LOAD_METADATA_ERR) {
g_error("Cannot load noarch repo: \"%s\"", noarch_ml->repomd);
- cr_destroy_metadata(noarch_metadata);
+ cr_metadata_free(noarch_metadata);
// TODO cleanup
cr_metadatalocation_free(noarch_ml);
return 1;
// Cleanup
g_free(groupfile);
- cr_destroy_metadata(noarch_metadata);
+ cr_metadata_free(noarch_metadata);
destroy_merged_metadata_hashtable(merged_hashtable);
free_options(cmd_options);
return 0;