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