repomd: Add support for xml:base attr at location element.
authorTomas Mlcoch <tmlcoch@redhat.com>
Tue, 4 Jun 2013 14:08:23 +0000 (16:08 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Tue, 4 Jun 2013 14:08:23 +0000 (16:08 +0200)
src/python/repomdrecord-py.c
src/repomd.c
src/repomd.h
src/xml_parser_repomd.c
tests/python/tests/test_repomd.py
tests/python/tests/test_repomdrecord.py

index 57d5bc9..8c0ed6d 100644 (file)
@@ -308,6 +308,7 @@ static PyGetSetDef repomdrecord_getsetters[] = {
     {"type",                (getter)get_str, (setter)set_str, NULL, OFFSET(type)},
     {"location_real",       (getter)get_str, (setter)set_str, NULL, OFFSET(location_real)},
     {"location_href",       (getter)get_str, (setter)set_str, NULL, OFFSET(location_href)},
+    {"location_base",       (getter)get_str, (setter)set_str, NULL, OFFSET(location_base)},
     {"checksum",            (getter)get_str, (setter)set_str, NULL, OFFSET(checksum)},
     {"checksum_type",       (getter)get_str, (setter)set_str, NULL, OFFSET(checksum_type)},
     {"checksum_open",       (getter)get_str, (setter)set_str, NULL, OFFSET(checksum_open)},
index a1f0b0f..fe932e0 100644 (file)
@@ -97,6 +97,8 @@ cr_repomd_record_copy(const cr_RepomdRecord *orig)
                                                 orig->location_real);
     rec->location_href      = cr_safe_string_chunk_insert(rec->chunk,
                                                 orig->location_href);
+    rec->location_base      = cr_safe_string_chunk_insert(rec->chunk,
+                                                orig->location_base);
     rec->checksum           = cr_safe_string_chunk_insert(rec->chunk,
                                                 orig->checksum);
     rec->checksum_type      = cr_safe_string_chunk_insert(rec->chunk,
@@ -622,6 +624,8 @@ cr_repomd_dump_data_items(xmlNodePtr root, cr_RepomdRecord *md)
 
     node = xmlNewChild(data, NULL, BAD_CAST "location", NULL);
     xmlNewProp(node, BAD_CAST "href", BAD_CAST md->location_href);
+    if (md->location_base)
+        xmlNewProp(node, BAD_CAST "xml:base", BAD_CAST md->location_base);
 
     g_snprintf(str_buffer, STR_BUFFER_SIZE, "%ld", md->timestamp);
     xmlNewChild(data, NULL, BAD_CAST "timestamp", BAD_CAST str_buffer);
index 203d624..8cb694b 100644 (file)
@@ -74,6 +74,7 @@ typedef struct {
     char *type;                 /*!< type of record */
     char *location_real;        /*!< real path to the file */
     char *location_href;        /*!< location of the file (in repomd.xml) */
+    char *location_base;        /*!< base location of the file */
     char *checksum;             /*!< checksum of file */
     char *checksum_type;        /*!< checksum type */
     char *checksum_open;        /*!< checksum of uncompressed file */
index ab70ab0..9f660c6 100644 (file)
@@ -179,11 +179,11 @@ cr_start_handler(void *pdata, const char *element, const char **attr)
             cr_xml_parser_warning(pd, CR_XML_WARNING_MISSINGATTR,
                     "Missing attribute \"href\" of a location element");
 
-//        val = cr_find_attr("base", attr);
-//        if (val)
-//            pd->repomdrecord->location_base = g_string_chunk_insert(
-//                                                    pd->repodmrecord->chunk,
-//                                                    val);
+        val = cr_find_attr("xml:base", attr);
+        if (val)
+            pd->repomdrecord->location_base = g_string_chunk_insert(
+                                                    pd->repomdrecord->chunk,
+                                                    val);
 
         break;
 
index 436f1e5..bc18f22 100644 (file)
@@ -89,6 +89,7 @@ class TestCaseRepomd(unittest.TestCase):
         rec = cr.RepomdRecord("primary", self.path00)
         rec.fill(cr.SHA256)
         rec.timestamp = 1
+        rec.location_base = "http://foo/"
         md.set_record(rec)
 
         self.assertEqual(len(md.records), 1)
@@ -110,7 +111,7 @@ class TestCaseRepomd(unittest.TestCase):
   <data type="primary">
     <checksum type="sha256">dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9</checksum>
     <open-checksum type="sha256">e1e2ffd2fb1ee76f87b70750d00ca5677a252b397ab6c2389137a0c33e7b359f</open-checksum>
-    <location href="repodata/primary.xml.gz"/>
+    <location href="repodata/primary.xml.gz" xml:base="http://foo/"/>
     <timestamp>1</timestamp>
     <size>134</size>
     <open-size>167</open-size>
index 48d6cf5..36c2251 100644 (file)
@@ -30,6 +30,7 @@ class TestCaseRepomdRecord(unittest.TestCase):
 
         self.assertEqual(rec.location_real, self.path00)
         self.assertEqual(rec.location_href, "repodata/primary.xml.gz")
+        self.assertEqual(rec.location_base, None)
         self.assertEqual(rec.checksum, None)
         self.assertEqual(rec.checksum_type, None)
         self.assertEqual(rec.checksum_open, None)
@@ -43,6 +44,7 @@ class TestCaseRepomdRecord(unittest.TestCase):
 
         self.assertEqual(rec.location_real, self.path00)
         self.assertEqual(rec.location_href, "repodata/primary.xml.gz")
+        self.assertEqual(rec.location_base, None)
         self.assertEqual(rec.checksum, "dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9")
         self.assertEqual(rec.checksum_type, "sha256")
         self.assertEqual(rec.checksum_open, "e1e2ffd2fb1ee76f87b70750d00ca5677a252b397ab6c2389137a0c33e7b359f")