int cr_xmlfile_add_pkg(cr_XmlFile *f, cr_Package *pkg, GError **err) { char *xml; GError *tmp_err = NULL; assert(f); assert(pkg); assert(!err || *err == NULL); assert(f->footer == 0); switch (f->type) { case CR_XMLFILE_PRIMARY: xml = cr_xml_dump_primary(pkg, &tmp_err); break; case CR_XMLFILE_FILELISTS: xml = cr_xml_dump_filelists(pkg, &tmp_err); break; case CR_XMLFILE_OTHER: xml = cr_xml_dump_other(pkg, &tmp_err); break; default: g_critical("%s: Bad file type", __func__); assert(0); g_set_error(err, ERR_DOMAIN, CRE_ASSERT, "Bad file type"); return CRE_ASSERT; } if (tmp_err) { int code = tmp_err->code; g_propagate_error(err, tmp_err); return code; } if (xml) { cr_xmlfile_add_chunk(f, xml, &tmp_err); g_free(xml); if (tmp_err) { int code = tmp_err->code; g_propagate_error(err, tmp_err); return code; } } return CRE_OK; }
PyObject * py_xml_dump_primary(G_GNUC_UNUSED PyObject *self, PyObject *args) { PyObject *py_pkg, *py_str; char *xml; GError *err = NULL; if (!PyArg_ParseTuple(args, "O!:py_xml_dump_primary", &Package_Type, &py_pkg)) return NULL; xml = cr_xml_dump_primary(Package_FromPyObject(py_pkg), &err); if (err) { nice_exception(&err, NULL); return NULL; } py_str = PyUnicodeOrNone_FromString(xml); free(xml); return py_str; }
struct cr_XmlStruct cr_xml_dump(cr_Package *pkg, GError **err) { struct cr_XmlStruct result; GError *tmp_err = NULL; assert(!err || *err == NULL); result.primary = NULL; result.filelists = NULL; result.other = NULL; if (!pkg) return result; result.primary = cr_xml_dump_primary(pkg, &tmp_err); if (tmp_err) { g_propagate_error(err, tmp_err); return result; } result.filelists = cr_xml_dump_filelists(pkg, &tmp_err); if (tmp_err) { g_propagate_error(err, tmp_err); g_free(result.primary); result.primary = NULL; return result; } result.other = cr_xml_dump_other(pkg, &tmp_err); if (tmp_err) { g_propagate_error(err, tmp_err); g_free(result.primary); result.primary = NULL; g_free(result.filelists); result.filelists = NULL; return result; } return result; }