1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
/* createrepo_c - Library of routines for manipulation with repodata
* Copyright (C) 2013 Tomas Mlcoch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#ifndef __C_CREATEREPOLIB_XML_PARSER_H__
#define __C_CREATEREPOLIB_XML_PARSER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <glib.h>
#include "package.h"
#include "repomd.h"
#include "updateinfo.h"
/** \defgroup xml_parser XML parser API.
* \addtogroup xml_parser
* @{
*/
#define CR_CB_RET_OK 0 /*!< Return value for callbacks signalizing success */
#define CR_CB_RET_ERR 1 /*!< Return value for callbacks signalizing error */
/** Type of warnings reported by parsers by the warning callback.
*/
typedef enum {
CR_XML_WARNING_UNKNOWNTAG, /*!< Unknown tag */
CR_XML_WARNING_MISSINGATTR, /*!< Missing attribute */
CR_XML_WARNING_UNKNOWNVAL, /*!< Unknown tag or attribute value */
CR_XML_WARNING_BADATTRVAL, /*!< Bad attribute value */
CR_XML_WARNING_MISSINGVAL, /*!< Missing tag value */
CR_XML_WARNING_BADMDTYPE, /*!< Bad metadata type (expected mandatory tag was not found) */
CR_XML_WARNING_SENTINEL,
} cr_XmlParserWarningType;
/** Callback for XML parser which is called when a new package object parsing
* is started. This function has to set *pkg to package object which will
* be populated by parser. The object could be empty, or already partially
* filled (by other XML parsers) package object.
* If the pointer is set to NULL, current package will be skiped.
* Note: For the primary.xml file pkgId, name and arch are NULL!
* @param pkg Package that will be populated.
* @param pkgId pkgId (hash) of the new package (in case of filelists.xml
* or other.xml) or package type ("rpm" in case
* of primary.xml).
* @param name Name of the new package.
* @param arch Arch of the new package.
* @param cbdata User data.
* @param err GError **
* @return CR_CB_RET_OK (0) or CR_CB_RET_ERR (1) - stops the parsing
*/
typedef int (*cr_XmlParserNewPkgCb)(cr_Package **pkg,
const char *pkgId,
const char *name,
const char *arch,
void *cbdata,
GError **err);
/** Callback for XML parser which is called when a package element is parsed.
* @param pkg Currently parsed package.
* @param cbdata User data.
* @param err GError **
* @return CR_CB_RET_OK (0) or CR_CB_RET_ERR (1) - stops the parsing
*/
typedef int (*cr_XmlParserPkgCb)(cr_Package *pkg,
void *cbdata,
GError **err);
/** Callback for XML parser warnings. All reported warnings are non-fatal,
* and ignored by default. But if callback return CR_CB_RET_ERR instead of
* CR_CB_RET_OK then parsing is immediately interrupted.
* @param type Type of warning
* @param msg Warning msg. The message is destroyed after the call.
* If you want to use the message later, you have to copy it.
* @param cbdata User data.
* @param err GError **
* @return CR_CB_RET_OK (0) or CR_CB_RET_ERR (1) - stops the parsing
*/
typedef int (*cr_XmlParserWarningCb)(cr_XmlParserWarningType type,
char *msg,
void *cbdata,
GError **err);
/** Parse primary.xml. File could be compressed.
* @param path Path to filelists.xml
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param do_files 0 - Ignore file tags in primary.xml.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_primary(const char *path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
int do_files,
GError **err);
/** Parse string snippet of primary xml repodata. Snippet cannot contain
* root xml element <metadata>. It contains only <package> elemetns.
* @param xml_string String containg primary xml data
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param do_files 0 - Ignore file tags in primary.xml.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_primary_snippet(const char *xml_string,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
int do_files,
GError **err);
/** Parse filelists[_ext].xml. File could be compressed.
* @param path Path to filelists[_ext].xml
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_filelists(const char *path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
/** Parse string snippet of filelists[_ext] xml repodata. Snippet cannot contain
* root xml element <filelists[_ext]>. It contains only <package> elemetns.
* @param xml_string String containg filelists[_ext] xml data
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_filelists_snippet(const char *xml_string,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
/** Parse other.xml. File could be compressed.
* @param path Path to other.xml
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_other(const char *path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
/** Parse string snippet of other xml repodata. Snippet cannot contain
* root xml element <otherdata>. It contains only <package> elemetns.
* @param xml_string String containg other xml data
* @param newpkgcb Callback for new package (Called when new package
* xml chunk is found and package object to store
* the data is needed). If NULL cr_newpkgcb is used.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. (Called when complete package
* xml chunk is parsed.). Could be NULL if newpkgcb is
* not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int cr_xml_parse_other_snippet(const char *xml_string,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
/** Parse repomd.xml. File could be compressed.
* @param path Path to repomd.xml
* @param repomd cr_Repomd object.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int
cr_xml_parse_repomd(const char *path,
cr_Repomd *repomd,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
/** Parse updateinfo.xml. File could be compressed.
* @param path Path to updateinfo.xml
* @param updateinfo cr_UpdateInfo object.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int
cr_xml_parse_updateinfo(const char *path,
cr_UpdateInfo *updateinfo,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
typedef struct _cr_PkgIterator cr_PkgIterator;
cr_PkgIterator *
cr_PkgIterator_new(const char *primary_path,
const char *filelists_path,
const char *other_path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);
cr_Package* cr_PkgIterator_parse_next(cr_PkgIterator *iter, GError **err);
void cr_PkgIterator_free(cr_PkgIterator *iter, GError **err);
gboolean cr_PkgIterator_is_finished(cr_PkgIterator *iter);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* __C_CREATEREPOLIB_XML_PARSER_H__ */
|