drpm
A library for making, reading and applying deltarpm packages
drpm.h
Go to the documentation of this file.
1 /*
2  Authors:
3  Pavel Tobias <ptobias@redhat.com>
4  Matej Chalk <mchalk@redhat.com>
5 
6  Copyright (C) 2014 Red Hat
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 /**
23  * @file
24  * @author Pavel Tobias <ptobias@redhat.com>
25  * @author Matej Chalk <mchalk@redhat.com>
26  * @date 2014-2016
27  * @copyright Copyright &copy; 2014-2016 Red Hat, Inc.
28  * This project is released under the GNU Lesser Public License.
29  */
30 
31 #ifndef _DRPM_H_
32 #define _DRPM_H_
33 
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 
38 /**
39  * @defgroup drpmMake DRPM Make
40  * Tools for creating a DeltaRPM file from two RPM files,
41  * providing the same functionality as
42  * [makedeltarpm(8)](http://linux.die.net/man/8/makedeltarpm).
43  * @{
44  * @defgroup drpmMakeOptions DRPM Make Options
45  * Tools for customizing DeltaRPM creation.
46  * @}
47  *
48  * @defgroup drpmApply DRPM Apply
49  * Tools for applying a DeltaRPM file to re-create a new RPM file
50  * (from an old RPM file or from filesystem data),
51  * providing the same functionality as
52  * [applydeltarpm(8)](http://linux.die.net/man/8/applydeltarpm).
53  * @{
54  * @defgroup drpmCheck DRPM Check
55  * Tools for checking if the reconstruction is possible
56  * (like <tt>applydeltarpm { -c | -C }</tt>).
57  * @}
58  *
59  * @defgroup drpmRead DRPM Read
60  * Tools for extracting information from DeltaRPM files.
61  */
62 
63 /**
64  * @name Errors / Return values
65  * @{
66  */
67 #define DRPM_ERR_OK 0 /**< no error */
68 #define DRPM_ERR_MEMORY 1 /**< memory allocation error */
69 #define DRPM_ERR_ARGS 2 /**< bad arguments */
70 #define DRPM_ERR_IO 3 /**< I/O error */
71 #define DRPM_ERR_FORMAT 4 /**< wrong file format */
72 #define DRPM_ERR_CONFIG 5 /**< misconfigured external library */
73 #define DRPM_ERR_OTHER 6 /**< unspecified/unknown error */
74 #define DRPM_ERR_OVERFLOW 7 /**< file too large */
75 #define DRPM_ERR_PROG 8 /**< internal programming error */
76 #define DRPM_ERR_MISMATCH 9 /**< file changed */
77 #define DRPM_ERR_NOINSTALL 10 /**< old RPM not installed */
78 /** @} */
79 
80 /**
81  * @name Delta Types
82  * @{
83  */
84 #define DRPM_TYPE_STANDARD 0 /**< standard deltarpm */
85 #define DRPM_TYPE_RPMONLY 1 /**< rpm-only deltarpm */
86 /** @} */
87 
88 /**
89  * @name Compression Types
90  * @{
91  */
92 #define DRPM_COMP_NONE 0 /**< no compression */
93 #define DRPM_COMP_GZIP 1 /**< gzip */
94 #define DRPM_COMP_BZIP2 2 /**< bzip2 */
95 #define DRPM_COMP_LZMA 3 /**< lzma */
96 #define DRPM_COMP_XZ 4 /**< xz */
97 #ifdef HAVE_LZLIB_DEVEL
98 /**
99  * @brief lzip
100  *
101  * The original deltarpm implementation does not support lzip.
102  * DeltaRPM packages compressed with lzip will work within this API, but
103  * will not be backwards-compatible.
104  *
105  * This compression algorithm is supported because newer versions
106  * of RPM packages may be compressed with lzip.
107  */
108 #endif
109 #define DRPM_COMP_LZIP 5 /**< lzip */
110 #define DRPM_COMP_ZSTD 6 /**< zstd */
111 /** @} */
112 
113 /**
114  * @name Info Tags
115  * @{
116  */
117 #define DRPM_TAG_FILENAME 0 /**< file name */
118 #define DRPM_TAG_VERSION 1 /**< version */
119 #define DRPM_TAG_TYPE 2 /**< delta type */
120 #define DRPM_TAG_COMP 3 /**< compression type */
121 #define DRPM_TAG_SEQUENCE 4 /**< sequence */
122 #define DRPM_TAG_SRCNEVR 5 /**< source NEVR (name-epoch:version-release) */
123 #define DRPM_TAG_TGTNEVR 6 /**< target NEVR (name-epoch:version-release) */
124 #define DRPM_TAG_TGTSIZE 7 /**< target size */
125 #define DRPM_TAG_TGTMD5 8 /**< target MD5 */
126 #define DRPM_TAG_TGTCOMP 9 /**< target compression type */
127 #define DRPM_TAG_TGTCOMPPARAM 10 /**< target compression parameter block */
128 #define DRPM_TAG_TGTHEADERLEN 11 /**< target header length */
129 #define DRPM_TAG_ADJELEMS 12 /**< offset adjustment elements */
130 #define DRPM_TAG_TGTLEAD 13 /**< lead/signatures of the new rpm */
131 #define DRPM_TAG_PAYLOADFMTOFF 14 /**< payload format offset */
132 #define DRPM_TAG_INTCOPIES 15 /**< copies from internal data (number of external copies to do before internal copy & length of internal copy) */
133 #define DRPM_TAG_EXTCOPIES 16 /**< copies from external data (offset adjustment of external copy & length of external copy) */
134 #define DRPM_TAG_EXTDATALEN 17 /**< length of external data */
135 #define DRPM_TAG_INTDATALEN 18 /**< length of internal data */
136 /** @} */
137 
138 /**
139  * @name Compression Levels
140  * @{
141  */
142 #define DRPM_COMP_LEVEL_DEFAULT 0 /**< default compression level for given compression type */
143 /** @} */
144 
145 /**
146  * @name Check Modes
147  * @{
148  */
149 #define DRPM_CHECK_NONE 0 /**< no file checking */
150 #define DRPM_CHECK_FULL 1 /**< full (i.e.\ slow) on-disk checking */
151 #define DRPM_CHECK_FILESIZES 2 /**< only checking if filesizes have changed */
152 /** @} */
153 
154 /**
155  * @brief DeltaRPM package info
156  * @ingroup drpmRead
157  */
158 typedef struct drpm drpm;
159 
160 /**
161  * @brief Options for drpm_make()
162  * @ingroup drpmMakeOptions
163  */
165 
166 /**
167  * @ingroup drpmApply
168  * @brief Applies a DeltaRPM to an old RPM or on-disk data to re-create a new RPM.
169  * @param [in] oldrpm Name of old RPM file (if @c NULL, filesystem data is used).
170  * @param [in] deltarpm Name of DeltaRPM file.
171  * @param [in] newrpm Name of new RPM file to be (re-)created.
172  * @return Error code.
173  */
174 int drpm_apply(const char *oldrpm, const char *deltarpm, const char *newrpm);
175 
176 /**
177  * @ingroup drpmCheck
178  * @brief Checks if the reconstruction is possible based on DeltaRPM file.
179  * @param [in] deltarpm Name of DeltaRPM file.
180  * @param [in] checkmode Full check or filesize changes only.
181  * @return Error code.
182  * @see DRPM_CHECK_FULL, DRPM_CHECK_FILESIZES
183  */
184 int drpm_check(const char *deltarpm, int checkmode);
185 
186 /**
187  * @ingroup drpmCheck
188  * @brief Checks if the reconstruction is possible based on sequence ID.
189  * @param [in] oldrpm Name of old RPM file (if @c NULL, filesystem data is used).
190  * @param [in] sequence Sequence ID of the DeltaRPM.
191  * @param [in] checkmode Full check or filesize changes only.
192  * @return Error code.
193  * @see DRPM_CHECK_FULL, DRPM_CHECK_FILESIZES
194  */
195 int drpm_check_sequence(const char *oldrpm, const char *sequence, int checkmode);
196 
197 /**
198  * @ingroup drpmMake
199  * @brief Creates a DeltaRPM from two RPMs.
200  * The DeltaRPM can later be used to recreate the new RPM from either
201  * filesystem data or the old RPM.
202  *
203  * Does the same thing as the
204  * [makedeltarpm(8)](http://linux.die.net/man/8/makedeltarpm)
205  * command-line utility.
206  *
207  * Examples of function calls (without error handling):
208  * @code
209  * // makedeltarpm foo.rpm goo.rpm fg.drpm
210  * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", NULL);
211  * @endcode
212  * @code
213  * // makedeltarpm -r -z xz.6 -s seqfile.txt foo.rpm goo.rpm fg.drpm
214  *
215  * drpm_make_options *opts;
216  *
217  * drpm_make_options_init(&opts);
218  * drpm_make_options_set_type(opts, DRPM_TYPE_RPMONLY);
219  * drpm_make_options_set_seqfile(opts, "seqfile.txt");
220  * drpm_make_options_set_delta_comp(opts, DRPM_COMP_XZ, 6);
221  *
222  * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
223  *
224  * drpm_make_options_destroy(&opts);
225  * @endcode
226  * @code
227  * // makedeltarpm -V 2 -z gzip,off -p foo-print.rpml foo-patch.rpml foo.rpm goo.rpm fg.drpm
228  *
229  * drpm_make_options *opts;
230  *
231  * drpm_make_options_init(&opts);
232  * drpm_make_options_set_version(opts, 2);
233  * drpm_make_options_set_delta_comp(opts, DRPM_COMP_GZIP, DRPM_COMP_LEVEL_DEFAULT);
234  * drpm_make_options_forbid_addblk(opts);
235  * drpm_make_options_add_patches(opts, "foo-print.rpml", "foo-patch.rpml");
236  *
237  * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
238  *
239  * drpm_make_options_destroy(&opts);
240  * @endcode
241  * @code
242  * // makedeltarpm -z uncompressed,bzip2.9 foo.rpm goo.rpm fg.drpm
243  *
244  * drpm_make_options *opts;
245  *
246  * drpm_make_options_init(&opts);
247  * drpm_make_options_set_delta_comp(opts, DRPM_COMP_NONE, 0);
248  * drpm_make_options_set_addblk_comp(opts, DRPM_COMP_BZIP2, 9);
249  *
250  * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
251  *
252  * drpm_make_options_destroy(&opts);
253  * @endcode
254  * @code
255  * // makedeltarpm -u foo.rpm foo.drpm
256  * drpm_make("foo.rpm", NULL, "foo.drpm", NULL);
257  * @endcode
258  * @param [in] oldrpm Name of old RPM file.
259  * @param [in] newrpm Name of new RPM file.
260  * @param [in] deltarpm Name of DeltaRPM file to be created.
261  * @param [in] opts Options (if @c NULL, defaults used).
262  * @return Error code.
263  * @note If either @p old_rpm or @p new_rpm is @c NULL, an "identity"
264  * deltarpm is created (may be useful to just replace the signature
265  * of an RPM or to reconstruct an RPM from the filesystem).
266  * @warning If not @c NULL, @p opts should have been initialized with
267  * drpm_make_options_init(), otherwise behaviour is undefined.
268  */
269 int drpm_make(const char *oldrpm, const char *newrpm, const char *deltarpm, const drpm_make_options *opts);
270 
271 /**
272  * @addtogroup drpmMakeOptions
273  * @{
274  */
275 
276 /**
277  * @brief Initializes ::drpm_make_options with default options.
278  * Passing @p *opts to drpm_make() immediately after would have the same
279  * effect as passing @c NULL instead.
280  * @param [out] opts Address of options structure pointer.
281  * @return Error code.
282  * @see drpm_make()
283  */
285 
286 /**
287  * @brief Frees ::drpm_make_options.
288  * @param [out] opts Address of options structure pointer.
289  * @return Error code.
290  * @see drpm_make()
291  */
293 
294 /**
295  * @brief Resets options to default values.
296  * Passing @p opts to drpm_make() immediately after would have the same
297  * effect as passing @c NULL instead.
298  * @param [out] opts Structure specifying options for drpm_make().
299  * @return Error code.
300  * @see drpm_make()
301  */
303 
304 /**
305  * @brief Copies ::drpm_make_options.
306  * Copies data from @p src to @p dst.
307  * @param [out] dst Destination options.
308  * @param [in] src Source options.
309  * @return Error code.
310  * @warning @p dst should have also been initialized with
311  * drpm_make_options_init() previously, otherwise behaviour is undefined.
312  * @see drpm_make()
313  */
315 
316 /**
317  * @brief Sets DeltaRPM type.
318  * There are two types of DeltaRPMs: standard and "rpm-only".
319  * The latter was introduced in version 3.
320  * It does not work with filesystem data but is smaller and faster to
321  * combine.
322  * @param [out] opts Structure specifying options for drpm_make().
323  * @param [in] type Type of deltarpm.
324  * @return Error code.
325  * @see drpm_make()
326  * @see DRPM_TYPE_STANDARD, DRPM_TYPE_RPMONLY
327  */
328 int drpm_make_options_set_type(drpm_make_options *opts, unsigned short type);
329 
330 /**
331  * @brief Sets DeltaRPM version.
332  * The default DeltaRPM format is V3, but an older version may also be
333  * specified.
334  * @param [out] opts Structure specifying options for drpm_make().
335  * @param [in] version Version (1-3).
336  * @return Error code.
337  * @see drpm_make()
338  */
339 int drpm_make_options_set_version(drpm_make_options *opts, unsigned short version);
340 
341 /**
342  * @brief Sets DeltaRPM compression type and level.
343  * By default, the compression method is the same as used in the new RPM.
344  * @param [out] opts Structure specifying options for drpm_make().
345  * @param [in] comp Compression type.
346  * @param [in] level Compression level (1-9 or default).
347  * @return Error code.
348  * @see drpm_make()
349  * @see DRPM_COMP_NONE, DRPM_COMP_GZIP, DRPM_COMP_BZIP2,
350  * DRPM_COMP_LZMA, DRPM_COMP_XZ
351  * @see DRPM_COMP_LEVEL_DEFAULT
352  */
353 int drpm_make_options_set_delta_comp(drpm_make_options *opts, unsigned short comp, unsigned short level);
354 
355 /**
356  * @brief DeltaRPM compression method is the same as used in the new RPM.
357  * May be used to reset DeltaRPM compression option after previously
358  * calling drpm_make_options_delta_comp().
359  * @param [out] opts Structure specifying options for drpm_make().
360  * @return Error code.
361  * @see drpm_make()
362  */
364 
365 /**
366  * @brief Forbids add block creation.
367  * An "add block" is a highly compressible block used to store
368  * bytewise subtractions of segments where less than half the bytes
369  * have changed.
370  * It is used in re-creating the new RPM with drpm_apply(), unless this
371  * functions is called to tell drpm_make() not to create an add block.
372  * @param [out] opts Structure specifying options for drpm_make().
373  * @return Error code.
374  * @see drpm_make()
375  */
377 
378 /**
379  * @brief Sets add block compression type and level.
380  * The default add block compression type is bzip2, which gives the best
381  * results.
382  * @param [out] opts Structure specifying options for drpm_make().
383  * @param [in] comp Compression type.
384  * @param [in] level Compression level (1-9 or default).
385  * @return Error code.
386  * @see drpm_make()
387  * @see DRPM_COMP_NONE, DRPM_COMP_GZIP, DRPM_COMP_BZIP2,
388  * DRPM_COMP_LZMA, DRPM_COMP_XZ
389  * @see DRPM_COMP_LEVEL_DEFAULT
390  */
391 int drpm_make_options_set_addblk_comp(drpm_make_options *opts, unsigned short comp, unsigned short level);
392 
393 /**
394  * @brief Specifies file to which to write DeltaRPM sequence ID.
395  * If a valid file name is given, drpm_make() will write out
396  * the sequence ID to the file @p seqfile.
397  * @param [out] opts Structure specifying options for drpm_make().
398  * @param [in] seqfile Name of file to which to write out sequence.
399  * @return Error code.
400  * @note If @p seqfile is @c NULL, sequence ID shall not be written.
401  * @see drpm_make()
402  */
403 int drpm_make_options_set_seqfile(drpm_make_options *opts, const char *seqfile);
404 
405 /**
406  * @brief Requests incorporation of RPM patch files for the old RPM.
407  * This option enables the usage of patch RPMs, telling drpm_make() to
408  * exclude all files that were not included in the patch RPM but are not
409  * bytewise identical to the ones in the old RPM.
410  * @param [out] opts Structure specifying options for drpm_make().
411  * @param [in] oldrpmprint The rpm-print of the old RPM.
412  * @param [in] oldpatchrpm The created patch RPM.
413  * @return Error code.
414  * @see drpm_make()
415  */
416 int drpm_make_options_add_patches(drpm_make_options *opts, const char *oldrpmprint, const char *oldpatchrpm);
417 
418 /**
419  * @brief Limits memory usage.
420  * As drpm_make() normally needs about three to four times the size of
421  * the rpm's uncompressed payload, this option may be used to enable
422  * a sliding block algorithm that needs @p mbytes megabytes of memory.
423  * This trades memory usage with the size of the created DeltaRPM.
424  * @param [out] opts Structure specifying options for drpm_make().
425  * @param [in] mbytes Permitted memory usage in megabytes.
426  * @return Error code.
427  * @see drpm_make()
428  */
429 //int drpm_make_options_set_memlimit(drpm_make_options *opts, unsigned mbytes);
430 
431 /** @} */
432 
433 /**
434  * @addtogroup drpmRead
435  * @{
436  */
437 
438 /**
439  * @brief Reads information from a DeltaRPM.
440  * Reads information from DeltaRPM package @p filename into @p *delta.
441  * Example of usage:
442  * @code
443  * drpm *delta = NULL;
444  *
445  * int error = drpm_read(&delta, "foo.drpm");
446  *
447  * if (error != DRPM_ERR_OK) {
448  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
449  * return;
450  * }
451  * @endcode
452  * @param [out] delta DeltaRPM to be filled with info.
453  * @param [in] filename Name of DeltaRPM file whose data is to be read.
454  * @return Error code.
455  * @note Memory allocated by calling drpm_read() should later be freed
456  * by calling drpm_destroy().
457  */
458 int drpm_read(drpm **delta, const char *filename);
459 
460 /**
461  * @brief Fetches information representable as an unsigned integer.
462  * Fetches information identified by @p tag from @p delta and copies it
463  * to address pointed to by @p target.
464  *
465  * Example of usage:
466  * @code
467  * unsigned type;
468  *
469  * int error = drpm_get_uint(delta, DRPM_TAG_TYPE, &type);
470  *
471  * if (error != DRPM_ERR_OK) {
472  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
473  * return;
474  * }
475  *
476  * printf("This is a %s deltarpm\n", (type == DRPM_TYPE_STANDARD) ? "standard" : "rpm-only");
477  * @endcode
478  * @param [in] delta DeltaRPM containing required info.
479  * @param [in] tag Identifies which info is required.
480  * @param [out] target Tagged info will be copied here.
481  * @return error number
482  * @warning @p delta should have been previously initialized with
483  * drpm_read(), otherwise behaviour is undefined.
484  * @see DRPM_TAG_VERSION
485  * @see DRPM_TAG_TYPE
486  * @see DRPM_TAG_COMP
487  * @see DRPM_TAG_TGTCOMP
488  */
489 int drpm_get_uint(drpm *delta, int tag, unsigned *target);
490 
491 /**
492  * @brief Fetches information representable as an unsigned long integer.
493  * Fetches information identified by @p tag from @p delta and copies it
494  * to address pointed to by @p target.
495  *
496  * Example of usage:
497  * @code
498  * unsigned long tgt_size;
499  *
500  * int error = drpm_get_ulong(delta, DRPM_TAG_TGTSIZE, &tgt_size);
501  *
502  * if (error != DRPM_ERR_OK) {
503  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
504  * return;
505  * }
506  *
507  * printf("Size of new RPM: %lu\n", tgt_size);
508  * @endcode
509  * @param [in] delta Deltarpm containing required info.
510  * @param [in] tag Identifies which info is required.
511  * @param [out] target Tagged info will be copied here.
512  * @return Error code.
513  * @warning @p delta should have been previously initialized with
514  * drpm_read(), otherwise behaviour is undefined.
515  * @see DRPM_TAG_TGTSIZE
516  * @see DRPM_TAG_TGTHEADERLEN
517  * @see DRPM_TAG_PAYLOADFMTOFF
518  */
519 int drpm_get_ulong(drpm *delta, int tag, unsigned long *target);
520 
521 /**
522  * @brief Fetches information representable as an unsigned long long integer.
523  * Fetches information identified by @p tag from @p delta and copies it
524  * to address pointed to by @p target.
525  *
526  * Example of usage:
527  * @code
528  * unsigned long long int_data_len;
529  *
530  * int error = drpm_get_ullong(delta, DRPM_TAG_INTDATALEN, &int_data_len);
531  *
532  * if (error != DRPM_ERR_OK) {
533  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
534  * return;
535  * }
536  *
537  * printf("Length of internal data: %llu\n", int_data_len);
538  * @endcode
539  * @param [in] delta Deltarpm containing required info.
540  * @param [in] tag Identifies which info is required.
541  * @param [out] target Tagged info will be copied here.
542  * @return Error code.
543  * @warning @p delta should have been previously initialized with
544  * drpm_read(), otherwise behaviour is undefined.
545  * @see DRPM_TAG_EXTDATALEN
546  * @see DRPM_TAG_INTDATALEN
547  */
548 int drpm_get_ullong(drpm *delta, int tag, unsigned long long *target);
549 
550 /**
551  * @brief Fetches information representable as a string.
552  * Fetches string-type information identified by @p tag from @p delta,
553  * copies it to space previously allocated by the function itself and
554  * saves the address to @p *target.
555  *
556  * Example of usage:
557  * @code
558  * char *tgt_nevr;
559  *
560  * int error = drpm_get_string(delta, DRPM_TAG_TGTNEVR, &tgt_nevr);
561  *
562  * if (error != DRPM_ERR_OK) {
563  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
564  * return;
565  * }
566  *
567  * printf("Target NEVR: %s\n", tgt_nevr);
568  *
569  * free(tgt_nevr);
570  * @endcode
571  * @param [in] delta Deltarpm containing required info.
572  * @param [in] tag Identifies which info is required.
573  * @param [out] target Tagged info will be copied here.
574  * @return Error code.
575  * @note @p *target should be freed manually by the user when no longer needed.
576  * @warning @p delta should have been previously initialized with
577  * drpm_read(), otherwise behaviour is undefined.
578  * @see DRPM_TAG_FILENAME
579  * @see DRPM_TAG_SEQUENCE
580  * @see DRPM_TAG_SRCNEVR
581  * @see DRPM_TAG_TGTNEVR
582  * @see DRPM_TAG_TGTMD5
583  * @see DRPM_TAG_TGTCOMPPARAM
584  * @see DRPM_TAG_TGTLEAD
585  */
586 int drpm_get_string(drpm *delta, int tag, char **target);
587 
588 /**
589  * @brief Fetches information representable as an array of unsigned long integers.
590  * Fetches information identified by @p tag from @p delta,
591  * copies it to space previously allocated by the function itself,
592  * saves the address to @p *target and stores size in @p *size.
593  *
594  * Example of usage:
595  * @code
596  * unsigned long *ext_copies;
597  * unsigned long ext_copies_size;
598  *
599  * int error = drpm_get_ulong_array(delta, DRPM_TAG_EXTCOPIES, &ext_copies, &ext_copies_size);
600  *
601  * if (error != DRPM_ERR_OK) {
602  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
603  * return;
604  * }
605  *
606  * for (unsigned long i = 1; i < ext_copies_size; i += 2)
607  * printf("External copy: offset adjustment = %lu, length = %lu\n", ext_copies[i-1], ext_copies[i]);
608  *
609  * free(ext_copies);
610  * @endcode
611  * @param [in] delta Deltarpm containing required info.
612  * @param [in] tag Identifies which info is required.
613  * @param [out] target Tagged info will be copied here.
614  * @param [out] size Size of array will be copied here.
615  * @return Error code.
616  * @note @p *target should be freed manually by the user when no longer needed.
617  * @warning @p delta should have been previously initialized with
618  * drpm_read(), otherwise behaviour is undefined.
619  * @see DRPM_TAG_ADJELEMS
620  * @see DRPM_TAG_INTCOPIES
621  * @see DRPM_TAG_EXTCOPIES
622  */
623 int drpm_get_ulong_array(drpm *delta, int tag, unsigned long **target, unsigned long *size);
624 
625 /**
626  * @brief Frees memory allocated by drpm_read().
627  * Frees memory pointed to by @p *delta and sets @p *delta to @c NULL.
628  *
629  * Example of usage:
630  * @code
631  * int error = drpm_destroy(&delta);
632  *
633  * if (error != DRPM_ERR_OK) {
634  * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
635  * return;
636  * }
637  * @endcode
638  * @param [out] delta Deltarpm that is to be freed.
639  * @return Error code.
640  * @warning @p delta should have been previously initialized with
641  * drpm_read(), otherwise behaviour is undefined.
642  */
643 int drpm_destroy(drpm **delta);
644 
645 /** @} */
646 
647 /**
648  * @brief Returns description of error code as a string.
649  * Works very similarly to
650  * [strerror(3)](http://linux.die.net/man/3/strerror).
651  * @param [in] error error code
652  * @return error description
653  */
654 const char *drpm_strerror(int error);
655 
656 #endif
int drpm_make_options_add_patches(drpm_make_options *opts, const char *oldrpmprint, const char *oldpatchrpm)
Requests incorporation of RPM patch files for the old RPM.
int drpm_get_string(drpm *delta, int tag, char **target)
Fetches information representable as a string.
int drpm_make_options_destroy(drpm_make_options **opts)
Frees drpm_make_options.
int drpm_check(const char *deltarpm, int checkmode)
Checks if the reconstruction is possible based on DeltaRPM file.
int drpm_apply(const char *oldrpm, const char *deltarpm, const char *newrpm)
Applies a DeltaRPM to an old RPM or on-disk data to re-create a new RPM.
int drpm_destroy(drpm **delta)
Frees memory allocated by drpm_read().
int drpm_make_options_init(drpm_make_options **opts)
Initializes drpm_make_options with default options.
int drpm_check_sequence(const char *oldrpm, const char *sequence, int checkmode)
Checks if the reconstruction is possible based on sequence ID.
struct drpm drpm
DeltaRPM package info.
Definition: drpm.h:158
int drpm_get_uint(drpm *delta, int tag, unsigned *target)
Fetches information representable as an unsigned integer.
int drpm_get_ullong(drpm *delta, int tag, unsigned long long *target)
Fetches information representable as an unsigned long long integer.
int drpm_make_options_set_addblk_comp(drpm_make_options *opts, unsigned short comp, unsigned short level)
Sets add block compression type and level.
struct drpm_make_options drpm_make_options
Options for drpm_make()
Definition: drpm.h:164
int drpm_make_options_set_version(drpm_make_options *opts, unsigned short version)
Sets DeltaRPM version.
int drpm_make_options_get_delta_comp_from_rpm(drpm_make_options *opts)
DeltaRPM compression method is the same as used in the new RPM.
int drpm_get_ulong_array(drpm *delta, int tag, unsigned long **target, unsigned long *size)
Fetches information representable as an array of unsigned long integers.
int drpm_get_ulong(drpm *delta, int tag, unsigned long *target)
Fetches information representable as an unsigned long integer.
int drpm_make_options_set_seqfile(drpm_make_options *opts, const char *seqfile)
Specifies file to which to write DeltaRPM sequence ID.
int drpm_read(drpm **delta, const char *filename)
Reads information from a DeltaRPM.
int drpm_make_options_defaults(drpm_make_options *opts)
Resets options to default values.
const char * drpm_strerror(int error)
Returns description of error code as a string.
int drpm_make(const char *oldrpm, const char *newrpm, const char *deltarpm, const drpm_make_options *opts)
Creates a DeltaRPM from two RPMs.
int drpm_make_options_set_type(drpm_make_options *opts, unsigned short type)
Sets DeltaRPM type.
int drpm_make_options_set_delta_comp(drpm_make_options *opts, unsigned short comp, unsigned short level)
Sets DeltaRPM compression type and level.
int drpm_make_options_forbid_addblk(drpm_make_options *opts)
Forbids add block creation.
int drpm_make_options_copy(drpm_make_options *dst, const drpm_make_options *src)
Copies drpm_make_options.