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
|
/* 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_FILE_H__
#define __C_CREATEREPOLIB_XML_FILE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <glib.h>
#include "compression_wrapper.h"
#include "package.h"
/** \defgroup xml_file XML file API.
* \addtogroup xml_file
* @{
*/
/** Supported types of xml files
*/
typedef enum {
CR_XMLFILE_PRIMARY, /*!< primary.xml */
CR_XMLFILE_FILELISTS, /*!< filelists.xml */
CR_XMLFILE_FILELISTS_EXT, /*!< filelists-ext.xml */
CR_XMLFILE_OTHER, /*!< other.xml */
CR_XMLFILE_PRESTODELTA, /*!< prestodelta.xml */
CR_XMLFILE_UPDATEINFO, /*!< updateinfo.xml */
CR_XMLFILE_SENTINEL, /*!< sentinel of the list */
} cr_XmlFileType;
/** cr_XmlFile structure.
*/
typedef struct {
CR_FILE *f; /*!<
File */
cr_XmlFileType type; /*!<
Type of XML file. */
int header; /*!<
0 if no header was written yet. */
int footer; /*!<
0 if no footer was written yet. */
long pkgs; /*!<
Number of packages */
} cr_XmlFile;
/** Open a new primary XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_primary(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_PRIMARY, COMTYPE, ERR)
/** Open a new primary XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_primary(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_PRIMARY, COMTYPE, STAT, ERR)
/** Open a new filelists XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of used compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_filelists(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_FILELISTS, COMTYPE, ERR)
/** Open a new filelists-ext XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of used compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_filelists_ext(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_FILELISTS_EXT, COMTYPE, ERR)
/** Open a new filelists XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_filelists(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_FILELISTS, COMTYPE, STAT, ERR)
/** Open a new filelists-ext XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_filelists_ext(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_FILELISTS_EXT, COMTYPE, STAT, ERR)
/** Open a new other XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of used compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_other(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_OTHER, COMTYPE, ERR)
/** Open a new other XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_other(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_OTHER, COMTYPE, STAT, ERR)
/** Open a new prestodelta XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of used compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_prestodelta(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_PRESTODELTA, COMTYPE, ERR)
/** Open a new prestodelta XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_prestodelta(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_PRESTODELTA, COMTYPE, STAT, ERR)
/** Open a new updateinfo XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of used compression.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open_updateinfo(FILENAME, COMTYPE, ERR) \
cr_xmlfile_open(FILENAME, CR_XMLFILE_UPDATEINFO, COMTYPE, ERR)
/** Open a new updateinfo XML file.
* @param FILENAME Filename.
* @param COMTYPE Type of compression.
* @param STAT cr_ContentStat object or NULL.
* @param ERR GError **
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_sopen_updateinfo(FILENAME, COMTYPE, STAT, ERR) \
cr_xmlfile_sopen(FILENAME, CR_XMLFILE_UPDATEINFO, COMTYPE, STAT, ERR)
/** Open a new XML file with stats.
* Note: Opened file must not exists! This function cannot
* open existing file!.
* @param FILENAME Filename.
* @param TYPE Type of XML file.
* @param COMTYPE Type of used compression.
* @param ERR **GError
* @return Opened cr_XmlFile or NULL on error
*/
#define cr_xmlfile_open(FILENAME, TYPE, COMTYPE, ERR) \
cr_xmlfile_sopen(FILENAME, TYPE, COMTYPE, NULL, ERR)
/** Open a new XML file.
* Note: Opened file must not exists! This function cannot
* open existing file!.
* @param filename Filename.
* @param type Type of XML file.
* @param comtype Type of used compression.
* @param stat pointer to cr_ContentStat or NULL
* @param err **GError
* @return Opened cr_XmlFile or NULL on error
*/
cr_XmlFile *cr_xmlfile_sopen(const char *filename,
cr_XmlFileType type,
cr_CompressionType comtype,
cr_ContentStat *stat,
GError **err);
/** Set total number of packages that will be in the file.
* This number must be set before any write operation
* (cr_xml_add_pkg, cr_xml_file_add_chunk, ..).
* @param f An opened cr_XmlFile
* @param num Total number of packages in the file.
* @param err **GError
* @return cr_Error code
*/
int cr_xmlfile_set_num_of_pkgs(cr_XmlFile *f, long num, GError **err);
/** Add package to the xml file.
* @param f An opened cr_XmlFile
* @param pkg Package object.
* @param err **GError
* @return cr_Error code
*/
int cr_xmlfile_add_pkg(cr_XmlFile *f, cr_Package *pkg, GError **err);
/** Add (write) string with XML chunk into the file.
* Note: Because of writing, in case of multithreaded program, should be
* guarded by locks, this function could be much more effective than
* cr_xml_file_add_pkg(). In case of _add_pkg() function, creating of
* string with xml chunk is done in a critical section. In _add_chunk()
* function, you could just dump XML whenever you want and in the
* critical section do only writting.
* @param f An opened cr_XmlFile
* @param chunk String with XML chunk.
* @param err **GError
* @return cr_Error code
*/
int cr_xmlfile_add_chunk(cr_XmlFile *f, const char *chunk, GError **err);
/** Close an opened cr_XmlFile.
* @param f An opened cr_XmlFile
* @param err **GError
* @return cr_Error code
*/
int cr_xmlfile_close(cr_XmlFile *f, GError **err);
/** Rewrite package count field in repodata header in xml file.
* In order to do this we have to decompress and after the change
* compress the whole file again, so entirely new file is created.
* @param original_filename Current file with wrong value in header
* @param package_count Actual package count (desired value in header)
* @param task_count Task count (current value in header)
* @param file_stat cr_ContentStat for stats of the new file, it will be modified
* @param zck_dict_file Optional path to zck dictionary
* @param err **GError
*/
void cr_rewrite_header_package_count(gchar *original_filename,
cr_CompressionType xml_compression,
int package_count,
int task_count,
cr_ContentStat *file_stat,
gchar *zck_dict_file,
GError **err);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* __C_CREATEREPOLIB_XML_FILE_H__ */
|