Example #1
0
void
cr_xml_dump_files(xmlNodePtr node, cr_Package *package, int primary)
{
    if (!node || !package->files) {
        return;
    }


    GSList *element = NULL;
    for(element = package->files; element; element=element->next) {
        cr_PackageFile *entry = (cr_PackageFile*) element->data;


        // File without name or path is suspicious => Skip it

        if (!(entry->path) || !(entry->name)) {
            continue;
        }


        // String concatenation (path + basename)

        gchar *fullname;
        fullname = g_strconcat(entry->path, entry->name, NULL);

        if (!fullname) {
            continue;
        }


        // Skip a file if we want primary files and the file is not one

        if (primary && !cr_is_primary(fullname)) {
            g_free(fullname);
            continue;
        }


        // ***********************************
        // Element: file
        // ************************************

        xmlNodePtr file_node;
        file_node = cr_xmlNewTextChild(node,
                                       NULL,
                                       BAD_CAST "file",
                                       BAD_CAST fullname);
        g_free(fullname);

        // Write type (skip type if type value is empty of "file")
        if (entry->type && entry->type[0] != '\0' && strcmp(entry->type, "file")) {
            cr_xmlNewProp(file_node, BAD_CAST "type", BAD_CAST entry->type);
        }
    }
}
Example #2
0
void
cr_xml_dump_repomd_record(xmlNodePtr root, cr_RepomdRecord *rec)
{
    xmlNodePtr data, node;
    gchar str_buffer[DATESIZE_STR_MAX_LEN];

    if (!rec)
        return;

    // Data element
    data = xmlNewChild(root, NULL, BAD_CAST "data", NULL);
    xmlNewProp(data, BAD_CAST "type", BAD_CAST rec->type);

    // Checksum element
    node = cr_xmlNewTextChild(data,
                              NULL,
                              BAD_CAST "checksum",
                              BAD_CAST rec->checksum);
    cr_xmlNewProp(node,
                  BAD_CAST "type",
                  BAD_CAST rec->checksum_type);

    // Checksum_open element
    if (rec->checksum_open) {
        node = cr_xmlNewTextChild(data,
                                  NULL,
                                  BAD_CAST "open-checksum",
                                  BAD_CAST rec->checksum_open);
        cr_xmlNewProp(node,
                      BAD_CAST "type",
                      BAD_CAST rec->checksum_open_type);
    }

    // Location element
    node = xmlNewChild(data,
                       NULL,
                       BAD_CAST "location",
                       NULL);
    cr_xmlNewProp(node,
                  BAD_CAST "href",
                  BAD_CAST rec->location_href);
    if (rec->location_base)
        cr_xmlNewProp(node,
                      BAD_CAST "xml:base",
                      BAD_CAST rec->location_base);

    // Timestamp element
    g_snprintf(str_buffer, DATESIZE_STR_MAX_LEN,
               "%"G_GINT64_FORMAT, rec->timestamp);
    xmlNewChild(data, NULL, BAD_CAST "timestamp", BAD_CAST str_buffer);

    // Size element
    g_snprintf(str_buffer, DATESIZE_STR_MAX_LEN,
               "%"G_GINT64_FORMAT, rec->size);
    xmlNewChild(data, NULL, BAD_CAST "size", BAD_CAST str_buffer);

    // Open-size element
    if (rec->size_open != -1) {
        g_snprintf(str_buffer, DATESIZE_STR_MAX_LEN,
                   "%"G_GINT64_FORMAT, rec->size_open);
        xmlNewChild(data, NULL, BAD_CAST "open-size", BAD_CAST str_buffer);
    }

    // Database_version element
    if (g_str_has_suffix((char *) rec->type, "_db")) {
        g_snprintf(str_buffer, DATESIZE_STR_MAX_LEN, "%d", rec->db_ver);
        xmlNewChild(data,
                    NULL,
                    BAD_CAST "database_version",
                    BAD_CAST str_buffer);
    }
}
Example #3
0
void
cr_xml_dump_repomd_body(xmlNodePtr root, cr_Repomd *repomd)
{
    GSList *element;

    // Add namespaces to the root element
    xmlNewNs(root, BAD_CAST CR_XML_REPOMD_NS, BAD_CAST NULL);
    xmlNewNs(root, BAD_CAST CR_XML_RPM_NS, BAD_CAST "rpm");

    // **********************************
    // Element: Revision
    // **********************************

    if (repomd->revision) {
        cr_xmlNewTextChild(root,
                           NULL,
                           BAD_CAST "revision",
                           BAD_CAST repomd->revision);
    } else {
        // Use the current time if no revision was explicitly specified
        gchar *rev = g_strdup_printf("%ld", time(NULL));
        xmlNewChild(root, NULL, BAD_CAST "revision", BAD_CAST rev);
        g_free(rev);
    }

    // **********************************
    // Element: Repoid
    // **********************************

    if (repomd->repoid) {
        xmlNodePtr repoid_elem = cr_xmlNewTextChild(root,
                                                    NULL,
                                                    BAD_CAST "repoid",
                                                    BAD_CAST repomd->repoid);
        if (repomd->repoid_type)
            cr_xmlNewProp(repoid_elem,
                          BAD_CAST "type",
                          BAD_CAST repomd->repoid_type);
    }

    // **********************************
    // Element: Contenthash
    // **********************************

    if (repomd->contenthash) {
        xmlNodePtr contenthash_elem = cr_xmlNewTextChild(root,
                                                NULL,
                                                BAD_CAST "contenthash",
                                                BAD_CAST repomd->contenthash);
        if (repomd->contenthash_type)
            cr_xmlNewProp(contenthash_elem,
                          BAD_CAST "type",
                          BAD_CAST repomd->contenthash_type);
    }

    // **********************************
    // Element: Tags
    // **********************************

    if (repomd->repo_tags || repomd->distro_tags || repomd->content_tags) {
        GSList *element;
        xmlNodePtr tags = xmlNewChild(root, NULL, BAD_CAST "tags", NULL);

        // Content tags
        element = repomd->content_tags;
        for (; element; element = g_slist_next(element))
            cr_xmlNewTextChild(tags, NULL,
                               BAD_CAST "content",
                               BAD_CAST element->data);

        // Repo tags
        element = repomd->repo_tags;
        for (; element; element = g_slist_next(element))
            cr_xmlNewTextChild(tags, NULL,
                               BAD_CAST "repo",
                               BAD_CAST element->data);

        // Distro tags
        element = repomd->distro_tags;
        for (; element; element = g_slist_next(element)) {
            cr_DistroTag *distro = (cr_DistroTag *) element->data;
            xmlNodePtr distro_elem = cr_xmlNewTextChild(tags,
                                                        NULL,
                                                        BAD_CAST "distro",
                                                        BAD_CAST distro->val);
            // Cpeid attribute of distro tag
            if (distro->cpeid)
                cr_xmlNewProp(distro_elem,
                              BAD_CAST "cpeid",
                              BAD_CAST distro->cpeid);
        }
    }

    // Dump records

    for (element = repomd->records; element; element = g_slist_next(element)) {
        cr_RepomdRecord *rec = element->data;
        cr_xml_dump_repomd_record(root, rec);
    }
}