Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repomd.h « src - github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c000f659f9202c678759720110f89f152979a04f (plain)
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) 2012  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_REPOMD_H__
#define __C_CREATEREPOLIB_REPOMD_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <glib.h>
#include "checksum.h"
#include "compression_wrapper.h"
#include "package.h"

/** \defgroup   repomd            Repomd API.
 *
 * Module for generating repomd.xml.
 *
 * Example:
 *
 * \code
 * char *xml;
 * cr_Repomd *md = cr_repomd_new();
 * cr_RepomdRecord *rec;
 *
 * cr_xml_dump_init();
 *
 * // Set some repomd stuff
 * cr_repomd_set_revision(md, "007");
 * cr_repomd_add_repo_tag(md, "repotag");
 * cr_repomd_add_content_tag(md, "contenttag");
 * cr_repomd_add_distro_tag(md, "foocpeid", "data");
 *
 * // Create record for new metadata file
 * rec = cr_repomd_record_new("primary", "/foo/bar/repodata/primary.xml.xz");
 * // Calculate all needed parameters (uncompresed size, checksum, ...)
 * cr_repomd_record_fill(rec, CR_CHECKSUM_SHA256);
 * // Rename source file - insert checksum into the filename
 * cr_repomd_record_rename_file(rec)
 * // Append the record into the repomd
 * cr_repomd_set_record(md, rec);
 *
 * // Get repomd.xml content
 * xml = cr_xml_dump_repomd(md, NULL);
 *
 * // Cleanup
 * cr_repomd_free(md);
 * cr_xml_dump_cleanup();
 * \endcode
 *
 *  \addtogroup repomd
 *  @{
 */

/** Internal representation of cr_RepomdRecord object
 */
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 */
    char *checksum_open_type;   /*!< checksum type of uncompressed file */
    char *checksum_header;      /*!< checksum of header */
    char *checksum_header_type; /*!< checksum type of header */
    gint64 timestamp;           /*!< mtime of the file */
    gint64 size;                /*!< size of file in bytes */
    gint64 size_open;           /*!< size of uncompressed file in bytes */
    gint64 size_header;         /*!< header size */
    int db_ver;                 /*!< version of database */

    GStringChunk *chunk;        /*!< String chunk */
} cr_RepomdRecord;

/** Distro tag structure
 */
typedef struct {
    gchar *cpeid;   /*!< cpeid value or NULL */
    gchar *val;     /*!< Tag value */
} cr_DistroTag;

/** Internal representation of cr_Repomd object
 */
typedef struct {
    gchar *revision;            /*!< Revison */
    gchar *repoid;              /*!< OBSOLETE, replaced by contenthash */
    gchar *repoid_type;         /*!< OBSOLETE, replaced by contenthash_type */
    gchar *contenthash;         /*!< Content hash */
    gchar *contenthash_type;    /*!< Content hash type ("sha256", ...) */
    GSList *repo_tags;          /*!< List of strings */
    GSList *content_tags;       /*!< List of strings */
    GSList *distro_tags;        /*!< List of cr_DistroTag* */
    GSList *records;            /*!< List with cr_RepomdRecords */

    GStringChunk *chunk;        /*!< String chunk for repomd strings
                                     (Note: RepomdRecord strings are stored
                                      in RepomdRecord->chunk) */
} cr_Repomd;

/** Creates (alloc) new cr_RepomdRecord object
 * @param type                  Type of record ("primary", "filelists", ..)
 * @param path                  path to the compressed file
 */
cr_RepomdRecord *cr_repomd_record_new(const char *type, const char *path);

/** Destroy cr_RepomdRecord object.
 * NOTE: Do NOT use this function on objects attached to cr_Repomd
 * (by cr_repomd_set_record).
 * @param record                cr_RepomdRecord object
 */
void cr_repomd_record_free(cr_RepomdRecord *record);

/** Copy cr_RepomdRecord object.
 * @param orig              cr_RepomdRecord object
 * @return                  copy of cr_RepomdRecord object
 */
cr_RepomdRecord *cr_repomd_record_copy(const cr_RepomdRecord *orig);

/** Fill unfilled items in the cr_RepomdRecord (calculate checksums,
 * get file size before/after compression, etc.).
 * Note: If checksum_open, checksum_open_type and size_open are filed
 * then their calculation will be skiped. This items could be filled
 * directly on our own or use function for load them from a cr_ContentStat.
 * If no open stats are supplied, then this function has to decompress
 * the file for the open checksum calculation.
 * @param record                cr_RepomdRecord object
 * @param checksum_type         type of checksum to use
 * @param err                   GError **
 * @return                      cr_Error code
 */
int cr_repomd_record_fill(cr_RepomdRecord *record,
                          cr_ChecksumType checksum_type,
                          GError **err);

/** Almost analogous to cr_repomd_record_fill but suitable for groupfile.
 * Record must be set with the path to existing non compressed groupfile.
 * Compressed file will be created and compressed_record updated.
 * @param record                cr_RepomdRecord initialized to an existing
 *                              uncompressed file
 * @param compressed_record     empty cr_RepomdRecord object that will by filled
 * @param checksum_type         type of checksums
 * @param compression           type of compression
 * @param zck_dict_dir          Location of zchunk dictionaries (NULL if unused)
 * @param err                   GError **
 * @return                      cr_Error code
 */
int cr_repomd_record_compress_and_fill(cr_RepomdRecord *record,
                                       cr_RepomdRecord *compressed_record,
                                       cr_ChecksumType checksum_type,
                                       cr_CompressionType compression,
                                       const char *zck_dict_dir,
                                       GError **err);

/** Add a hash as prefix to the filename.
 * @param record                cr_RepomdRecord of file to be renamed
 * @param err                   GError **
 * @return                      cr_Error code
 */
int cr_repomd_record_rename_file(cr_RepomdRecord *record, GError **err);

/** Set timestamp of the file. Needed to reproduce bit-by-bit identical metadata.
 * @param record                cr_RepomdRecord of file to be renamed
 * @param timestamp             timestamp in number of seconds since 1970-01-01
 */
void cr_repomd_record_set_timestamp(cr_RepomdRecord *record, gint64 timestamp);

/** Load the open stats (checksum_open, checksum_open_type and size_open)
 * from the cr_ContentStat object.
 * @param record                cr_RepomdRecord
 * @param stats                 cr_ContentStat
 */
void cr_repomd_record_load_contentstat(cr_RepomdRecord *record,
                                       cr_ContentStat *stats);

/** Load the zchunk stats (zck_header_checksum, zck_header_checksum_type and zck_header_size)
 * from the cr_ContentStat object.
 * @param record                cr_RepomdRecord
 * @param stats                 cr_ContentStat
 */
void cr_repomd_record_load_zck_contentstat(cr_RepomdRecord *record,
                                           cr_ContentStat *stats);

/** Create new empty cr_Repomd object wich represents content of repomd.xml.
 */
cr_Repomd *cr_repomd_new();

/** Create copy of cr_Repomd
 * @param repomd                cr_Repomd object
 * @return                      Copy of the input cr_Repomd object
 */
cr_Repomd *cr_repomd_copy(cr_Repomd *repomd);

/** Set cr_Repomd record into cr_Repomd object.
 * @param repomd                cr_Repomd object
 * @param record                cr_RepomdRecord object
 */
void cr_repomd_set_record(cr_Repomd *repomd, cr_RepomdRecord *record);

/** Set custom revision string of repomd.
 * @param repomd                cr_Repomd object
 * @param revision              revision string
 */
void cr_repomd_set_revision(cr_Repomd *repomd, const char *revision);

/** Set a repoid - OBSOLETE, use cr_repomd_set_contenthash instead
 * @param repomd                cr_Repomd object
 * @param repoid                RepoId
 * @param type                  Type of hash function used to calculate repoid
 */
void cr_repomd_set_repoid(cr_Repomd *repomd,
                          const char *repoid,
                          const char *type);

/** Set a contenthash
 * @param repomd                cr_Repomd object
 * @param hash                  content hash
 * @param type                  Type of hash function
 */
void cr_repomd_set_contenthash(cr_Repomd *repomd,
                               const char *hash,
                               const char *type);

/** Add distro tag.
 * @param repomd                cr_Repomd object
 * @param cpeid                 cpeid string (could be NULL)
 * @param tag                   distro tag string
 */
void cr_repomd_add_distro_tag(cr_Repomd *repomd,
                              const char *cpeid,
                              const char *tag);

/** Add repo tag.
 * @param repomd                cr_Repomd object
 * @param tag                   repo tag
 */
void cr_repomd_add_repo_tag(cr_Repomd *repomd, const char *tag);

/** Add content tag.
 * @param repomd                cr_Repomd object
 * @param tag                   content tag
 */
void cr_repomd_add_content_tag(cr_Repomd *repomd, const char *tag);

/** Get repomd record from the repomd object.
 * @param repomd                cr_Repomd object
 * @param type                  Type of the record ("primary", "primary_db", ..)
 * @return                      Pointer to a record of desired type or NULL
 */
cr_RepomdRecord *cr_repomd_get_record(cr_Repomd *repomd, const char *type);

/** Detach this record from the repomd records list.
 * Note: Responsibility of freeing record memory no longer belongs to
 * cr_Repomd object.
 * @param repomd                cr_Repomd object
 * @param rec                   Record to be removed
 */
void cr_repomd_detach_record(cr_Repomd *repomd, cr_RepomdRecord *rec);

/** Remove first record of the specified type
 * @param repomd                cr_Repomd object
 * @param type                  Type of the record ("primary", "primary_db", ..)
 */
void cr_repomd_remove_record(cr_Repomd *repomd, const char *type);

/** Records are stored in order they were added to the repomd.
 * Because sometimes deterministic output is desirable this function
 * exists.
 * @param repomd                cr_Repomd object
 */
void cr_repomd_sort_records(cr_Repomd *repomd);

/** Frees cr_Repomd object and all its cr_RepomdRecord objects
 * @param repomd                cr_Repomd object
 */
void cr_repomd_free(cr_Repomd *repomd);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* __C_CREATEREPOLIB_REPOMD_H__ */