XBPS Library API  0.19
The X Binary Package System
xbps_api.h
1 /*-
2  * Copyright (c) 2008-2012 Juan Romero Pardines.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *-
25  */
26 
27 #ifndef _XBPS_API_H_
28 #define _XBPS_API_H_
29 
30 #include <stdio.h>
31 #include <inttypes.h>
32 
33 #include <archive.h>
34 #include <archive_entry.h>
35 #include <prop/proplib.h>
36 #include <confuse.h>
37 
38 #ifdef __cplusplus
39 # ifndef __BEGIN_DECLS
40 # define __BEGIN_DECLS extern "C" {
41 # endif
42 # ifndef __END_DECLS
43 # define __END_DECLS }
44 # endif
45 #else
46 # ifndef __BEGIN_DECLS
47 # define __BEGIN_DECLS
48 # endif
49 # ifndef __END_DECLS
50 # define __END_DECLS
51 # endif
52 #endif
53 
54 /**
55  * @file include/xbps_api.h
56  * @brief XBPS Library API header
57  *
58  * This header documents the full API for the XBPS Library.
59  */
60 
61 /**
62  * @def XBPS_PKGINDEX_VERSION
63  * Current version for the repository package index format.
64  */
65 #define XBPS_PKGINDEX_VERSION "1.6"
66 
67 #define XBPS_API_VERSION "20121215"
68 
69 #ifndef XBPS_VERSION
70  #define XBPS_VERSION "UNSET"
71 #endif
72 #ifndef XBPS_GIT
73  #define XBPS_GIT "UNSET"
74 #endif
75 /**
76  * @def XBPS_RELVER
77  * Current library release date.
78  */
79 #define XBPS_RELVER "XBPS: " XBPS_VERSION \
80  " API: " XBPS_API_VERSION \
81  " INDEX: " XBPS_PKGINDEX_VERSION \
82  " GIT: " XBPS_GIT
83 
84 /**
85  * @def XBPS_META_PATH
86  * Default root PATH to store metadata info.
87  */
88 #define XBPS_META_PATH "var/db/xbps"
89 
90 /**
91  * @def XBPS_CACHE_PATH
92  * Default cache PATH to store downloaded binpkgs.
93  */
94 #define XBPS_CACHE_PATH "var/cache/xbps"
95 
96 /**
97  * @def XBPS_PKGDB
98  * Filename for the package database.
99  */
100 #define XBPS_PKGDB "pkgdb.plist"
101 
102 /**
103  * @def XBPS_PKGPROPS
104  * Filename for package metadata property list.
105  */
106 #define XBPS_PKGPROPS "props.plist"
107 
108 /**
109  * @def XBPS_PKGFILES
110  * Filename for package metadata files property list.
111  */
112 #define XBPS_PKGFILES "files.plist"
113 
114 /**
115  * @def XBPS_PKGINDEX
116  * Filename for the repository package index property list.
117  */
118 #define XBPS_PKGINDEX "index.plist"
119 
120 /**
121  * @def XBPS_PKGINDEX_FILES
122  * Filename for the repository package index files property list.
123  */
124 #define XBPS_PKGINDEX_FILES "index-files.plist"
125 
126 /**
127  * @def XBPS_SYSCONF_PATH
128  * Default configuration PATH to find XBPS_CONF_PLIST.
129  */
130 #define XBPS_SYSDIR "/xbps"
131 #ifndef XBPS_SYSCONF_PATH
132 #define XBPS_SYSCONF_PATH "/etc" XBPS_SYSDIR
133 #endif
134 
135 /**
136  * @def XBPS_CONF_DEF
137  * Filename for the XBPS plist configuration file.
138  */
139 #define XBPS_CONF_DEF XBPS_SYSCONF_PATH "/xbps.conf"
140 
141 /**
142  * @def XBPS_FLAG_VERBOSE
143  * Verbose flag that can be used in the function callbacks to alter
144  * its behaviour. Must be set through the xbps_handle::flags member.
145  */
146 #define XBPS_FLAG_VERBOSE 0x00000001
147 
148 /**
149  * @def XBPS_FLAG_FORCE_CONFIGURE
150  * Force flag used in xbps_configure_pkg(), if set the package(s)
151  * will be reconfigured even if its state is XBPS_PKG_STATE_INSTALLED.
152  * Must be set through the xbps_handle::flags member.
153  */
154 #define XBPS_FLAG_FORCE_CONFIGURE 0x00000002
155 
156 /**
157  * @def XBPS_FLAG_FORCE_REMOVE_FILES
158  * Force flag used in xbps_remove_pkg_files(), if set the package
159  * files will be removed even if its SHA256 hash don't match.
160  * Must be set through the xbps_handle::flags member.
161  */
162 #define XBPS_FLAG_FORCE_REMOVE_FILES 0x00000004
163 
164 /**
165  * @def XBPS_FLAG_SYSLOG
166  * Enable syslog logging flag. To make clients aware that syslog
167  * will be used.
168  */
169 #define XBPS_FLAG_SYSLOG 0x00000008
170 
171 /**
172  * @def XBPS_FLAG_INSTALL_AUTO
173  * Enabled automatic install mode for a package and all dependencies
174  * installed direct and indirectly.
175  */
176 #define XBPS_FLAG_INSTALL_AUTO 0x00000010
177 
178 /**
179  * @def XBPS_FLAG_INSTALL_MANUAL
180  * Enabled manual install mode for a package and all dependencies
181  * installed direct and indirectly.
182  */
183 #define XBPS_FLAG_INSTALL_MANUAL 0x00000020
184 
185 /**
186  * @def XBPS_FLAG_DEBUG
187  * Enable debug mode to output debugging printfs to stdout/stderr.
188  */
189 #define XBPS_FLAG_DEBUG 0x00000040
190 
191 /**
192  * @def XBPS_FLAG_FORCE_INSTALL
193  * Force flag used in xbps_unpack_binary_pkg(). If set its package
194  * files will be unpacked overwritting the current ones.
195  * Must be set through the xbps_handle::flags member.
196  */
197 #define XBPS_FLAG_FORCE_INSTALL 0x00000080
198 
199 /**
200  * @def XBPS_FETCH_CACHECONN
201  * Default (global) limit of cached connections used in libfetch.
202  */
203 #define XBPS_FETCH_CACHECONN 6
204 
205 /**
206  * @def XBPS_FETCH_CACHECONN_HOST
207  * Default (per host) limit of cached connections used in libfetch.
208  */
209 #define XBPS_FETCH_CACHECONN_HOST 2
210 
211 /**
212  * @def XBPS_FETCH_TIMEOUT
213  * Default timeout limit (in seconds) to wait for stalled connections.
214  */
215 #define XBPS_FETCH_TIMEOUT 30
216 
217 __BEGIN_DECLS
218 
219 /** @addtogroup initend */
220 /*@{*/
221 
222 /**
223  * @enum xbps_state_t
224  *
225  * Integer representing the xbps callback returned state. Possible values:
226  *
227  * - XBPS_STATE_UKKNOWN: state hasn't been prepared or unknown error.
228  * - XBPS_STATE_TRANS_DOWNLOAD: transaction is downloading binary packages.
229  * - XBPS_STATE_TRANS_VERIFY: transaction is verifying binary package integrity.
230  * - XBPS_STATE_TRANS_RUN: transaction is performing operations:
231  * install, update, remove and replace.
232  * - XBPS_STATE_TRANS_CONFIGURE: transaction is configuring all
233  * unpacked packages.
234  * - XBPS_STATE_DOWNLOAD: a binary package is being downloaded.
235  * - XBPS_STATE_VERIFY: a binary package is being verified.
236  * - XBPS_STATE_REMOVE: a package is being removed.
237  * - XBPS_STATE_REMOVE_DONE: a package has been removed successfully.
238  * - XBPS_STATE_REMOVE_FILE: a package file is being removed.
239  * - XBPS_STATE_REMOVE_OBSOLETE: an obsolete package file is being removed.
240  * - XBPS_STATE_REPLACE: a package is being replaced.
241  * - XBPS_STATE_INSTALL: a package is being installed.
242  * - XBPS_STATE_INSTALL_DONE: a package has been installed successfully.
243  * - XBPS_STATE_UPDATE: a package is being updated.
244  * - XBPS_STATE_UPDATE_DONE: a package has been updated successfully.
245  * - XBPS_STATE_UNPACK: a package is being unpacked.
246  * - XBPS_STATE_CONFIGURE: a package is being configured.
247  * - XBPS_STATE_CONFIG_FILE: a package configuration file is being processed.
248  * - XBPS_STATE_REGISTER: a package is being registered.
249  * - XBPS_STATE_UNREGISTER: a package is being unregistered.
250  * - XBPS_STATE_REPOSYNC: a remote repository's package index is being
251  * synchronized.
252  * - XBPS_STATE_VERIFY_FAIL: binary package integrity has failed.
253  * - XBPS_STATE_DOWNLOAD_FAIL: binary package download has failed.
254  * - XBPS_STATE_REMOVE_FAIL: a package removal has failed.
255  * - XBPS_STATE_REMOVE_FILE_FAIL: a package file removal has failed.
256  * - XBPS_STATE_REMOVE_FILE_HASH_FAIL: a package file removal due to
257  * its hash has failed.
258  * - XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL: an obsolete package file
259  * removal has failed.
260  * - XBPS_STATE_CONFIGURE_FAIL: package configure has failed.
261  * - XBPS_STATE_CONFIG_FILE_FAIL: package configuration file operation
262  * has failed.
263  * - XBPS_STATE_UPDATE_FAIL: package update has failed.
264  * - XBPS_STATE_UNPACK_FAIL: package unpack has failed.
265  * - XBPS_STATE_REGISTER_FAIL: package register has failed.
266  * - XBPS_STATE_UNREGISTER_FAIL: package unregister has failed.
267  * - XBPS_STATE_REPOSYNC_FAIL: syncing remote repositories has failed.
268  */
269 typedef enum xbps_state {
270  XBPS_STATE_UNKNOWN = 0,
271  XBPS_STATE_TRANS_DOWNLOAD,
272  XBPS_STATE_TRANS_VERIFY,
273  XBPS_STATE_TRANS_RUN,
274  XBPS_STATE_TRANS_CONFIGURE,
275  XBPS_STATE_DOWNLOAD,
276  XBPS_STATE_VERIFY,
277  XBPS_STATE_REMOVE,
278  XBPS_STATE_REMOVE_DONE,
279  XBPS_STATE_REMOVE_FILE,
280  XBPS_STATE_REMOVE_FILE_OBSOLETE,
281  XBPS_STATE_PURGE,
282  XBPS_STATE_PURGE_DONE,
283  XBPS_STATE_REPLACE,
284  XBPS_STATE_INSTALL,
285  XBPS_STATE_INSTALL_DONE,
286  XBPS_STATE_UPDATE,
287  XBPS_STATE_UPDATE_DONE,
288  XBPS_STATE_UNPACK,
289  XBPS_STATE_CONFIGURE,
290  XBPS_STATE_CONFIG_FILE,
291  XBPS_STATE_REGISTER,
292  XBPS_STATE_UNREGISTER,
293  XBPS_STATE_REPOSYNC,
294  XBPS_STATE_VERIFY_FAIL,
295  XBPS_STATE_DOWNLOAD_FAIL,
296  XBPS_STATE_REMOVE_FAIL,
297  XBPS_STATE_REMOVE_FILE_FAIL,
298  XBPS_STATE_REMOVE_FILE_HASH_FAIL,
299  XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
300  XBPS_STATE_PURGE_FAIL,
301  XBPS_STATE_CONFIGURE_FAIL,
302  XBPS_STATE_CONFIG_FILE_FAIL,
303  XBPS_STATE_UPDATE_FAIL,
304  XBPS_STATE_UNPACK_FAIL,
305  XBPS_STATE_REGISTER_FAIL,
306  XBPS_STATE_UNREGISTER_FAIL,
307  XBPS_STATE_REPOSYNC_FAIL
308 } xbps_state_t;
309 
310 /**
311  * @struct xbps_state_cb_data xbps_api.h "xbps_api.h"
312  * @brief Structure to be passed as argument to the state function callback.
313  * All members are read-only and set internally by libxbps.
314  */
316  /**
317  * @var xhp
318  *
319  * Pointer to our struct xbps_handle passed to xbps_init().
320  */
321  struct xbps_handle *xhp;
322  /**
323  * @var state
324  *
325  * Current state.
326  */
328  /**
329  * @var desc
330  *
331  * Current state string description.
332  */
333  const char *desc;
334  /**
335  * @var arg0
336  *
337  * State string argument 0. String set on this
338  * variable may change depending on \a state.
339  */
340  const char *arg0;
341  /**
342  * @var arg1
343  *
344  * State string argument 1. String set on this
345  * variable may change depending on \a state.
346  */
347  const char *arg1;
348  /**
349  * @var err
350  *
351  * Current state error value (set internally, read-only).
352  */
353  int err;
354 };
355 
356 /**
357  * @struct xbps_fetch_cb_data xbps_api.h "xbps_api.h"
358  * @brief Structure to be passed to the fetch function callback.
359  *
360  * This structure is passed as argument to the fetch progress function
361  * callback and its members will be updated when there's any progress.
362  * All members marked as read-only in this struct are set internally by
363  * xbps_unpack_binary_pkg() and shouldn't be modified in the passed
364  * function callback.
365  */
367  /**
368  * @var xhp
369  *
370  * Pointer to our struct xbps_handle passed to xbps_init().
371  */
372  struct xbps_handle *xhp;
373  /**
374  * @var file_size
375  *
376  * Filename size for the file to be fetched.
377  */
378  off_t file_size;
379  /**
380  * @var file_offset
381  *
382  * Current offset for the filename being fetched.
383  */
384  off_t file_offset;
385  /**
386  * @var file_dloaded
387  *
388  * Bytes downloaded for the file being fetched.
389  */
391  /**
392  * @var file_name
393  *
394  * File name being fetched.
395  */
396  const char *file_name;
397  /**
398  * @var cb_start
399  *
400  * If true the function callback should be prepared to start
401  * the transfer progress.
402  */
403  bool cb_start;
404  /**
405  * @var cb_update
406  *
407  * If true the function callback should be prepared to
408  * update the transfer progress.
409  */
410  bool cb_update;
411  /**
412  * @var cb_end
413  *
414  * If true the function callback should be prepated to
415  * end the transfer progress.
416  */
417  bool cb_end;
418 };
419 
420 /**
421  * @struct xbps_unpack_cb_data xbps_api.h "xbps_api.h"
422  * @brief Structure to be passed to the unpack function callback.
423  *
424  * This structure is passed as argument to the unpack progress function
425  * callback and its members will be updated when there's any progress.
426  * All members in this struct are set internally by libxbps
427  * and should be used in read-only mode in the supplied function
428  * callback.
429  */
431  /**
432  * @var xhp
433  *
434  * Pointer to our struct xbps_handle passed to xbps_init().
435  */
436  struct xbps_handle *xhp;
437  /**
438  * @var pkgver
439  *
440  * Package name/version string of package being unpacked.
441  */
442  const char *pkgver;
443  /**
444  * @var entry
445  *
446  * Entry pathname string.
447  */
448  const char *entry;
449  /**
450  * @var entry_size
451  *
452  * Entry file size.
453  */
454  int64_t entry_size;
455  /**
456  * @var entry_extract_count
457  *
458  * Total number of extracted entries.
459  */
461  /**
462  * @var entry_total_count
463  *
464  * Total number of entries in package.
465  */
467  /**
468  * @var entry_is_conf
469  *
470  * If true "entry" is a configuration file.
471  */
473 };
474 
475 /**
476  * @struct xbps_handle xbps_api.h "xbps_api.h"
477  * @brief Generic XBPS structure handler for initialization.
478  *
479  * This structure sets some global properties for libxbps, to set some
480  * function callbacks and data to the fetch, transaction and unpack functions,
481  * the root and cache directory, flags, etc.
482  */
483 struct xbps_handle {
484  /**
485  * @private
486  */
487  cfg_t *cfg;
488  /**
489  * @private
490  *
491  * Array of dictionaries with all registered repositories.
492  */
493  prop_array_t repo_pool;
494  /**
495  * @private pkgdb.
496  *
497  * Internalized proplib array with the master package database
498  * stored in XBPS_META_PATH/XBPS_PKGDB.
499  */
500  prop_array_t pkgdb;
501  /**
502  * @private
503  *
504  * Proplib dictionary with pkg metafiles.
505  */
506  prop_dictionary_t pkg_metad;
507  /**
508  * @private pkgdb_revdeps.
509  *
510  * Proplib dictionary with full reverse dependencies from pkgdb.
511  */
512  prop_dictionary_t pkgdb_revdeps;
513 
514  /**
515  * @var transd;
516  *
517  * Proplib dictionary with transaction details, required by
518  * xbps_transaction_commit().
519  */
520  prop_dictionary_t transd;
521  /**
522  * Pointer to the supplifed function callback to be used
523  * in the XBPS possible states.
524  */
525  void (*state_cb)(struct xbps_state_cb_data *, void *);
526  /**
527  * Pointer to user supplied data to be passed as argument to
528  * the \a xbps_state_cb function callback.
529  */
531  /**
532  * Pointer to the supplied function callback to be used in
533  * xbps_unpack_binary_pkg().
534  */
535  void (*unpack_cb)(struct xbps_unpack_cb_data *, void *);
536  /**
537  * Pointer to user supplied data to be passed as argument to
538  * the \a xbps_unpack_cb function callback.
539  */
541  /**
542  * Pointer to the supplied function callback to be used in
543  * xbps_fetch_file().
544  */
545  void (*fetch_cb)(struct xbps_fetch_cb_data *, void *);
546  /**
547  * @var fetch_cb_data
548  *
549  * Pointer to user supplied data to be passed as argument to
550  * the \a xbps_fetch_cb function callback.
551  */
553  /**
554  * @var rootdir
555  *
556  * Root directory for all operations in XBPS. If NULL,
557  * by default it's set to /.
558  */
559  const char *rootdir;
560  /**
561  * @var cachedir
562  *
563  * Cache directory to store downloaded binary packages.
564  * If NULL default value in \a XBPS_CACHE_PATH is used.
565  */
566  const char *cachedir;
567  /**
568  * @var metadir
569  *
570  * Metadata directory for all operations in XBPS.
571  * If NULL, defaults to \a XBPS_CACHE_PATH (relative to rootdir).
572  */
573  const char *metadir;
574  /**
575  * @private
576  */
577  char *cachedir_priv;
578  char *metadir_priv;
579  char *un_machine;
580  /*
581  * @var repository
582  *
583  * Default repository to be used if a configuration file
584  * couldn't be found.
585  */
586  const char *repository;
587  /**
588  * @var conffile
589  *
590  * Full path to the xbps configuration file.
591  */
592  const char *conffile;
593  /**
594  * @var fetch_timeout
595  *
596  * Unsigned integer to specify libfetch's timeout limit.
597  * If not set, it defaults to 30 (in seconds). This is set internally
598  * by the API from a setting in configuration file.
599  */
600  uint16_t fetch_timeout;
601  /**
602  * @var flags
603  *
604  * Flags to be set globally by ORing them, possible values:
605  * - XBPS_FLAG_VERBOSE
606  * - XBPS_FLAG_FORCE_CONFIGURE
607  * - XBPS_FLAG_FORCE_REMOVE_FILES
608  * - XBPS_FLAG_DEBUG
609  * - XBPS_FLAG_SYSLOG
610  * - XBPS_FLAG_INSTALL_AUTO
611  * - XBPS_FLAG_INSTALL_MANUAL
612  */
613  int flags;
614  /**
615  * @private
616  */
617  bool initialized;
618 };
619 
620 void xbps_dbg_printf(struct xbps_handle *, const char *, ...);
621 void xbps_dbg_printf_append(struct xbps_handle *, const char *, ...);
622 void xbps_error_printf(const char *, ...);
623 void xbps_warn_printf(const char *, ...);
624 
625 /**
626  * Initialize the XBPS library with the following steps:
627  *
628  * - Set function callbacks for fetching and unpacking.
629  * - Set default cache connections for libfetch.
630  * - Parse configuration file.
631  *
632  * @param[in] xhp Pointer to an xbps_handle struct.
633  * @note It's assumed that \a xhp is a valid pointer.
634  *
635  * @return 0 on success, an errno value otherwise.
636  */
637 int xbps_init(struct xbps_handle *xhp);
638 
639 /**
640  * Releases all resources used by libxbps.
641  *
642  * @param[in] xhp Pointer to an xbps_handle struct.
643  */
644 void xbps_end(struct xbps_handle *xhp);
645 
646 /*@}*/
647 
648 /** @addtogroup configure */
649 /*@{*/
650 
651 /**
652  * Configure (or force reconfiguration of) a package.
653  *
654  * @param[in] xhp Pointer to an xbps_handle struct.
655  * @param[in] pkgname Package name to configure.
656  * @param[in] check_state Set it to true to check that package is
657  * in unpacked state.
658  * @param[in] update Set it to true if this package is being updated.
659  * @param[in] flush Set it to true to flush state to pkgdb.
660  *
661  * @return 0 on success, otherwise an errno value.
662  */
664  const char *pkgname,
665  bool check_state,
666  bool update,
667  bool flush);
668 
669 /**
670  * Configure (or force reconfiguration of) all packages.
671  *
672  * @param[in] xhp Pointer to an xbps_handle struct.
673  * @param[in] flush Set it to true to flush state to pkgdb.
674  *
675  * @return 0 on success, otherwise an errno value.
676  */
677 int xbps_configure_packages(struct xbps_handle *xhp, bool flush);
678 
679 /*@}*/
680 
681 /** @addtogroup download */
682 /*@{*/
683 
684 /**
685  * Download a file from a remote URL to current working directory.
686  *
687  * @param[in] xhp Pointer to an xbps_handle struct.
688  * @param[in] uri Remote URI string.
689  * @param[in] flags Flags passed to libfetch's fetchXget().
690  *
691  * @return -1 on error, 0 if not downloaded (because local/remote size/mtime
692  * do not match) and 1 if downloaded successfully.
693  **/
694 int xbps_fetch_file(struct xbps_handle *xhp, const char *uri,
695  const char *flags);
696 
697 /**
698  * Returns last error string reported by xbps_fetch_file().
699  *
700  * @return A string with the appropiate error message.
701  */
702 const char *xbps_fetch_error_string(void);
703 
704 /*@}*/
705 
706 /**
707  * @ingroup pkg_orphans
708  *
709  * Finds all package orphans currently installed.
710  *
711  * @param[in] xhp Pointer to an xbps_handle struct.
712  * @param[in] orphans Proplib array of strings with package names of
713  * packages that should be treated as they were already removed (optional).
714  *
715  * @return A proplib array of dictionaries with all orphans found,
716  * on error NULL is returned and errno is set appropiately.
717  */
718 prop_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, prop_array_t orphans);
719 
720 /**
721  * @ingroup pkg_obsoletes
722  *
723  * Finds obsolete files by comparing installed files dictionary with
724  * a new files dictionary.
725  *
726  * @param[in] xhp The pointer to the xbps_handle struct.
727  * @param[in] instd Installed package files dictionary (\a XBPS_PKGFILES).
728  * @param[in] newd New package files dictionary (provided by a binary package).
729  *
730  * @return A proplib array of strings with a sorted list of obsolete files.
731  */
732 prop_array_t xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
733  prop_dictionary_t instd,
734  prop_dictionary_t newd);
735 
736 /** @addtogroup pkgdb */
737 /*@{*/
738 
739 /**
740  * Executes a function callback per a package dictionary registered
741  * in master package database (pkgdb) plist (downwards).
742  *
743  * @param[in] xhp The pointer to the xbps_handle struct.
744  * @param[in] fn Function callback to run for any pkg dictionary.
745  * @param[in] arg Argument to be passed to the function callback.
746  *
747  * @return 0 on success (all objects were processed), otherwise
748  * the value returned by the function callback.
749  */
751  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
752  void *arg);
753 
754 /**
755  * Executes a function callback per a package dictionary registered
756  * in master package database (pkgdb) plist, in reverse order (upwards).
757  *
758  * @param[in] xhp The pointer to the xbps_handle struct.
759  * @param[in] fn Function callback to run for any pkg dictionary.
760  * @param[in] arg Argument to be passed to the function callback.
761  *
762  * @return 0 on success (all objects were processed), otherwise
763  * the value returned by the funcion callback.
764  */
766  struct xbps_handle *xhp,
767  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
768  void *arg);
769 
770 /**
771  * Returns a package dictionary from master package database (pkgdb) plist,
772  * matching pkgname or pkgver object in \a pkg.
773  *
774  * @param[in] xhp The pointer to the xbps_handle struct.
775  * @param[in] pkg Package name or name-version to match.
776  *
777  * @return The matching proplib package dictionary, NULL otherwise.
778  */
779 prop_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp,
780  const char *pkg);
781 
782 /**
783  * Returns a package dictionary from master package database (pkgdb) plist,
784  * matching virtual pkgname or pkgver object in \a pkg.
785  *
786  * @param[in] xhp The pointer to the xbps_handle struct.
787  * @param[in] pkg Package name or name-version to match.
788  *
789  * @return The matching proplib package dictionary, NULL otherwise.
790  */
791 prop_dictionary_t xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp,
792  const char *pkg);
793 
794 /**
795  * Returns the package dictionary with all metadata info for \a pkg.
796  *
797  * @param[in] xhp The pointer to the xbps_handle struct.
798  * @param[in] pkg Package expression to match.
799  *
800  * @return The matching package metadata dictionary, NULL otherwise.
801  */
802 prop_dictionary_t xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp,
803  const char *pkg);
804 
805 /**
806  * Returns a proplib array of strings with reverse dependencies
807  * for \a pkg. The array is generated dynamically based on the list
808  * of packages currently installed.
809  *
810  * @param[in] xhp The pointer to the xbps_handle struct.
811  * @param[in] pkg Package expression to match.
812  *
813  * @return A proplib array of strings with reverse dependencies for \a pkg.
814  */
815 prop_array_t xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp,
816  const char *pkg);
817 
818 /**
819  * Removes a package dictionary from master package database (pkgdb) plist,
820  * matching pkgname or pkgver object in \a pkg.
821  *
822  * @param[in] xhp The pointer to the xbps_handle struct.
823  * @param[in] pkg Package name or pattern to match in a package dictionary.
824  * @param[in] flush If true, after successful replace the pkgdb contents
825  * in memory will be flushed atomically to storage.
826  *
827  * @return true on success, false otherwise.
828  */
829 bool xbps_pkgdb_remove_pkg(struct xbps_handle *xhp, const char *pkg,
830  bool flush);
831 
832 /**
833  * Replaces a package dictionary with \a dict in the master package database
834  * (pkgdb) plist, matching pkgname or pkgver object.
835  *
836  * @param[in] xhp The pointer to the xbps_handle struct.
837  * @param[in] pkgd Proplib dictionary to be added into pkgdb.
838  * @param[in] pkg Package name or pattern to match in a package dictionary.
839  * @param[in] flush If true, after successful replace the pkgdb contents in
840  * memory will be flushed atomically to storage.
841  *
842  * @return true on success, false otherwise.
843  */
844 bool xbps_pkgdb_replace_pkg(struct xbps_handle *xhp,
845  prop_dictionary_t pkgd,
846  const char *pkg,
847  bool flush);
848 
849 /**
850  * Updates the master package database (pkgdb) plist with new contents from
851  * disk to the cached copy in memory.
852  *
853  * @param[in] xhp The pointer to the xbps_handle struct.
854  * @param[in] flush If true the pkgdb plist contents in memory will
855  * be flushed atomically to storage.
856  *
857  * @return 0 on success, otherwise an errno value.
858  */
859 int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush);
860 
861 /**
862  * Creates a temporary file and executes it in rootdir.
863  *
864  * @param[in] xhp The pointer to the xbps_handle struct.
865  * @param[in] blob The buffer pointer where the data is stored.
866  * @param[in] blobsiz The size of the buffer data.
867  * @param[in] pkgname The package name associated.
868  * @param[in] version The package version associated.
869  * @param[in] action The action to execute on the temporary file.
870  * @param[in] update Set to true if package is being updated.
871  *
872  * @return 0 on success, or an errno value otherwise.
873  */
874 int xbps_pkg_exec_buffer(struct xbps_handle *xhp,
875  const void *blob,
876  const size_t blobsiz,
877  const char *pkgname,
878  const char *version,
879  const char *action,
880  bool update);
881 
882 /**
883  * Creates a temporary file and executes it in rootdir.
884  *
885  * @param[in] xhp The pointer to the xbps_handle struct.
886  * @param[in] d Package dictionary where the script data is stored.
887  * @param[in] script Key associated with the script in dictionary.
888  * @param[in] action The action to execute on the temporary file.
889  * @param[in] update Set to true if package is being updated.
890  *
891  * @return 0 on success, or an errno value otherwise.
892  */
893 int xbps_pkg_exec_script(struct xbps_handle *xhp,
894  prop_dictionary_t d,
895  const char *script,
896  const char *action,
897  bool update);
898 
899 /*@}*/
900 
901 /** @addtogroup plist */
902 /*@{*/
903 
904 /**
905  * Executes a function callback specified in \a fn with \a arg passed
906  * as its argument into they array \a array.
907  *
908  * @param[in] xhp The pointer to the xbps_handle struct.
909  * @param[in] array Proplib array to iterate.
910  * @param[in] fn Function callback to run on every object in the array.
911  * While running the function callback, the hird parameter (a pointer to
912  * a boolean) can be set to true to stop immediately the loop.
913  * @param[in] arg Argument to be passed to the function callback.
914  *
915  * @return 0 on success, otherwise the value returned by the function
916  * callback.
917  */
918 int xbps_callback_array_iter(struct xbps_handle *xhp,
919  prop_array_t array,
920  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
921  void *arg);
922 
923 /**
924  * Executes a function callback specified in \a fn with \a arg passed
925  * as its argument into they array \a array in reverse order (upwards).
926  *
927  * @param[in] xhp The pointer to the xbps_handle struct.
928  * @param[in] array Proplib array to iterate.
929  * @param[in] fn Function callback to run on every object in the array.
930  * While running the function callback, the hird parameter (a pointer to
931  * a boolean) can be set to true to stop immediately the loop.
932  * @param[in] arg Argument to be passed to the function callback.
933  *
934  * @return 0 on success, otherwise the value returned by the function
935  * callback.
936  */
938  prop_array_t array,
939  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
940  void *arg);
941 
942 /**
943  * Executes a function callback into the array associated with key \a key,
944  * contained in a proplib dictionary.
945  *
946  * @param[in] xhp The pointer to the xbps_handle struct.
947  * @param[in] dict Proplib dictionary where the array resides.
948  * @param[in] key Key associated with array.
949  * @param[in] fn Function callback to run on every
950  * object in the array. While running the function callback, the third
951  * parameter (a pointer to a boolean) can be set to true to stop
952  * immediately the loop.
953  * @param[in] arg Argument to be passed to the function callback.
954  *
955  * @return 0 on success (all objects were processed), otherwise
956  * the value returned by the function callback.
957  */
959  prop_dictionary_t dict,
960  const char *key,
961  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
962  void *arg);
963 
964 /**
965  * Executes a function callback (in reverse order) into the array
966  * associated with key \a key, contained in a proplib dictionary.
967  *
968  * @param[in] xhp The pointer to the xbps_handle struct.
969  * @param[in] dict Proplib dictionary where the array resides.
970  * @param[in] key Key associated with array.
971  * @param[in] fn Function callback to run on every
972  * object in the array. While running the function callback, the third
973  * parameter (a pointer to a boolean) can be set to true to stop
974  * immediately the loop.
975  * @param[in] arg Argument to be passed to the function callback.
976  *
977  * @return 0 on success (all objects were processed), otherwise
978  * the value returned by the function callback.
979  */
981  prop_dictionary_t dict,
982  const char *key,
983  int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
984  void *arg);
985 
986 /**
987  * Match a virtual package name or pattern by looking at package's
988  * dictionary "provides" array object.
989  *
990  * @param[in] pkgd Package dictionary.
991  * @param[in] str Virtual package name or package pattern to match.
992  * @param[in] bypattern If true, \a str should be a package name,
993  * otherwise it should be a package pattern, i.e `foo>=0' or `foo<1'.
994  *
995  * @return True if \a str matches a virtual package in \a pkgd, false
996  * otherwise.
997  */
998 bool xbps_match_virtual_pkg_in_dict(prop_dictionary_t pkgd,
999  const char *str,
1000  bool bypattern);
1001 
1002 /**
1003  * Match any virtual package from array \a provides in they array \a rundeps
1004  * with dependencies.
1005  *
1006  * @param[in] rundeps Proplib array with dependencies as strings, i.e foo>=2.0.
1007  * @param[in] provides Proplib array of strings with virtual pkgdeps, i.e
1008  * foo-1.0 blah-2.0.
1009  *
1010  * @return True if \a any virtualpkg has been matched, false otherwise.
1011  */
1012 bool xbps_match_any_virtualpkg_in_rundeps(prop_array_t rundeps,
1013  prop_array_t provides);
1014 
1015 /**
1016  * Match a package name in the specified array of strings.
1017  *
1018  * @param[in] array The proplib array to search on.
1019  * @param[in] pkgname The package name to match.
1020  *
1021  * @return true on success, false otherwise and errno is set appropiately.
1022  */
1023 bool xbps_match_pkgname_in_array(prop_array_t array, const char *pkgname);
1024 
1025 /**
1026  * Match a package pattern in the specified array of strings.
1027  *
1028  * @param[in] array The proplib array to search on.
1029  * @param[in] pattern The package pattern to match, i.e `foo>=0' or `foo<1'.
1030  *
1031  * @return true on success, false otherwise and errno is set appropiately.
1032  */
1033 bool xbps_match_pkgpattern_in_array(prop_array_t array, const char *pattern);
1034 
1035 /**
1036  * Match a package dependency against any package pattern in the specified
1037  * array of strings.
1038  *
1039  * @param[in] array The proplib array to search on.
1040  * @param[in] pkgver The package name-version to match, i.e `foo-1.0'.
1041  *
1042  * @return true on success, false otherwise and errno is set appropiately.
1043  */
1044 bool xbps_match_pkgdep_in_array(prop_array_t array, const char *pkgver);
1045 
1046 /**
1047  * Match a string (exact match) in the specified array of strings.
1048  *
1049  * @param[in] array The proplib array to search on.
1050  * @param[in] val The string to be matched.
1051  *
1052  * @return true on success, false otherwise and errno is set appropiately.
1053  */
1054 bool xbps_match_string_in_array(prop_array_t array, const char *val);
1055 
1056 /**
1057  * Returns a proplib object iterator associated with an array, contained
1058  * in a proplib dictionary matching the specified key.
1059  *
1060  * @param[in] dict Proplib dictionary where to look for the array.
1061  * @param[in] key Key associated with the array.
1062  *
1063  * @return A proplib object iterator on success, NULL otherwise and
1064  * errno is set appropiately.
1065  */
1066 prop_object_iterator_t xbps_array_iter_from_dict(prop_dictionary_t dict,
1067  const char *key);
1068 
1069 /*@}*/
1070 
1071 /** @addtogroup pkg_register */
1072 /*@{*/
1073 
1074 /**
1075  * Register a package into the installed packages database.
1076  *
1077  * @param[in] xhp The pointer to the xbps_handle struct.
1078  * @param[in] pkg_dict A dictionary with the following objects:
1079  * \a pkgname, \a version, \a pkgver, \a short_desc (string),
1080  * \a automatic-install (bool) and optionally \a provides (array of strings).
1081  * @param[in] flush Set to true to make sure that pkgdb plist
1082  * is written to storage on success.
1083  *
1084  * @return 0 on success, otherwise an errno value.
1085  */
1086 int xbps_register_pkg(struct xbps_handle *xhp,
1087  prop_dictionary_t pkg_dict,
1088  bool flush);
1089 
1090 /**
1091  * Unregister a package from the package database.
1092  *
1093  * @param[in] xhp The pointer to the xbps_handle struct.
1094  * @param[in] pkgver Package name-version to match.
1095  * @param[in] flush Set to true to make sure that pkgdb plist
1096  * is written to storage on success.
1097  *
1098  * @return 0 on success, otherwise an errno value.
1099  */
1100 int xbps_unregister_pkg(struct xbps_handle *xhp, const char *pkgver,
1101  bool flush);
1102 
1103 /*@}*/
1104 
1105 /** @addtogroup pkg_remove */
1106 /*@{*/
1107 
1108 /**
1109  * Remove an installed package.
1110  *
1111  * @param[in] xhp The pointer to the xbps_handle struct.
1112  * @param[in] pkgver Package name/version to match.
1113  * @param[in] update If true, some steps will be skipped. See in the
1114  * detailed description above for more information.
1115  * @param[in] soft_replace If true, some steps will be skipped. See in
1116  * the detailed description above for more information.
1117  *
1118  * @return 0 on success, otherwise an errno value.
1119  */
1120 int xbps_remove_pkg(struct xbps_handle *xhp,
1121  const char *pkgver,
1122  bool update,
1123  bool soft_replace);
1124 
1125 /**
1126  * Remove files defined in a proplib array as specified by \a key
1127  * of an installed package.
1128  *
1129  * @param[in] xhp The pointer to the xbps_handle struct.
1130  * @param[in] dict Proplib dictionary internalized from package's
1131  * <b>XBPS_PKGFILES</b> definition in package's metadata directory.
1132  * The image in Detailed description shows off its structure.
1133  * @param[in] key Key of the array object to match, valid values are:
1134  * <b>files</b>, <b>dirs</b>, <b>links</b> and <b>conf_files</b>.
1135  * @param[in] pkgver Package/version string matching package dictionary,
1136  * i.e `foo-1.0'.
1137  *
1138  * @return 0 on success, otherwise an errno value.
1139  */
1140 int xbps_remove_pkg_files(struct xbps_handle *xhp,
1141  prop_dictionary_t dict,
1142  const char *key,
1143  const char *pkgver);
1144 
1145 /*@}*/
1146 
1147 /** @addtogroup transaction */
1148 /*@{*/
1149 
1150 /**
1151  * Finds a package by name or by pattern and enqueues it into
1152  * the transaction dictionary for future use. If pkg is a pkgname, the best
1153  * package version in repository pool will be queued, otherwise the first
1154  * repository matching the package pattern wins.
1155  *
1156  * @param[in] xhp Pointer to the xbps_handle struct.
1157  * @param[in] pkg Package name, package/version or package pattern to match, i.e
1158  * `foo', `foo-1.0' or `foo>=1.2'.
1159  * @param[in] reinstall If true, package will be queued (if \a str matches)
1160  * even if package is already installed.
1161  *
1162  * @return 0 on success, otherwise an errno value.
1163  * @retval EEXIST Package is already installed (reinstall wasn't enabled).
1164  * @retval ENOENT Package not matched in repository pool.
1165  * @retval ENOTSUP No repositories are available.
1166  * @retval EINVAL Any other error ocurred in the process.
1167  */
1169  const char *pkg,
1170  bool reinstall);
1171 
1172 /**
1173  * Marks a package as "going to be updated" in the transaction dictionary.
1174  * All repositories in the pool will be used, and newest version
1175  * available will be enqueued if it's greater than current installed
1176  * version.
1177  *
1178  * @param[in] xhp Pointer to the xbps_handle struct.
1179  * @param[in] pkgname The package name to update.
1180  *
1181  * @return 0 on success, otherwise an errno value.
1182  */
1183 int xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkgname);
1184 
1185 /**
1186  * Finds newer versions for all installed packages by looking at the
1187  * repository pool. If a newer version exists, package will be enqueued
1188  * into the transaction dictionary.
1189  *
1190  * @param[in] xhp Pointer to the xbps_handle struct.
1191  * @return 0 on success, otherwise an errno value.
1192  */
1194 
1195 /**
1196  * Removes a package currently installed. The package dictionary will
1197  * be added into the transaction dictionary.
1198  *
1199  * @param[in] xhp Pointer to the xbps_handle struct.
1200  * @param[in] pkgname Package name to be removed.
1201  * @param[in] recursive If true, all packages that are currently depending
1202  * on the package to be removed, and if they are orphans, will be added.
1203  *
1204  * @retval 0 success.
1205  * @retval ENOENT Package is not installed.
1206  * @retval EEXIST Package has reverse dependencies.
1207  * @retval EINVAL
1208  * @retval ENXIO A problem ocurred in the process.
1209  */
1211  const char *pkgname,
1212  bool recursive);
1213 
1214 /**
1215  * Finds all package orphans currently installed and adds them into
1216  * the transaction dictionary.
1217  *
1218  * @param[in] xhp Pointer to the xbps_handle struct.
1219  *
1220  * @retval 0 success.
1221  * @retval ENOENT No package orphans were found.
1222  * @retval ENXIO
1223  * @retval EINVAL A problem ocurred in the process.
1224  */
1226 
1227 /**
1228  * Returns the transaction dictionary, as shown above in the image.
1229  * Before returning the package list is sorted in the correct order
1230  * and total installed/download size for the transaction is computed.
1231  *
1232  * @param[in] xhp Pointer to the xbps_handle struct.
1233  *
1234  * @retval 0 success.
1235  * @retval ENXIO if transaction dictionary and missing deps array were not created,
1236  * due to xbps_transaction_install_pkg() or xbps_transaction_update_pkg() not
1237  * previously called.
1238  * @retval ENODEV if there are missing dependencies in transaction ("missing_deps"
1239  * array of strings object in xhp->transd dictionary).
1240  * @retval EAGAIN if there are package conflicts in transaction ("conflicts"
1241  * array of strings object in xhp->transd dictionary).
1242  * @retval EINVAL There was an error sorting packages or computing the transaction
1243  * sizes.
1244  */
1245 int xbps_transaction_prepare(struct xbps_handle *xhp);
1246 
1247 /**
1248  * Commit a transaction. The transaction dictionary in xhp->transd contains all
1249  * steps to be executed in the transaction, as prepared by
1250  * xbps_transaction_prepare().
1251  *
1252  * @param[in] xhp Pointer to the xbps_handle struct.
1253  * @return 0 on success, otherwise an errno value.
1254  */
1255 int xbps_transaction_commit(struct xbps_handle *xhp);
1256 
1257 /*@}*/
1258 
1259 /** @addtogroup plist_fetch */
1260 /*@{*/
1261 
1262 /**
1263  * Internalizes a plist file in a binary package file stored locally or
1264  * remotely as specified in \a fname.
1265  *
1266  * @param[in] fname Full URL to binary package file (local or remote path).
1267  * @param[in] plistf Plist file name to internalize.
1268  *
1269  * @return An internalized proplib dictionary, otherwise NULL and
1270  * errno is set appropiately.
1271  */
1272 prop_dictionary_t xbps_get_pkg_plist_from_binpkg(const char *fname,
1273  const char *plistf);
1274 
1275 /*@}*/
1276 
1277 /** @addtogroup repopool */
1278 /*@{*/
1279 
1280 /**
1281  * @struct xbps_rindex xbps_api.h "xbps_api.h"
1282  * @brief Repository pool index structure
1283  *
1284  * Repository index object structure registered in a private simple queue.
1285  * The structure contains a dictionary and the URI associated with the
1286  * registered repository index.
1287  */
1288 struct xbps_rindex {
1289  /**
1290  * @var repod
1291  *
1292  * Internalized proplib dictionary of the index plist file
1293  * associated with repository.
1294  */
1295  prop_dictionary_t repod;
1296  /**
1297  * @var uri
1298  *
1299  * URI string associated with repository.
1300  */
1301  const char *uri;
1302  /**
1303  * @var xhp
1304  *
1305  * Pointer to our xbps_handle struct passed to xbps_rpool_foreach.
1306  * (read-only).
1307  */
1308  struct xbps_handle *xhp;
1309 };
1310 
1311 /**
1312  * Synchronizes \a file for all remote repositories
1313  * as specified in the configuration file or if \a uri argument is
1314  * set, just sync \a file for that repository.
1315  *
1316  * @param[in] xhp Pointer to the xbps_handle struct.
1317  * @param[in] file File to synchronize.
1318  * @param[in] uri Repository URI to match for sync (optional).
1319  *
1320  * @return 0 on success, ENOTSUP if no repositories were found in
1321  * the configuration file.
1322  */
1323 int xbps_rpool_sync(struct xbps_handle *xhp, const char *file, const char *uri);
1324 
1325 /**
1326  * Iterates over the repository pool and executes the \a fn function
1327  * callback passing in the void * \a arg argument to it. The bool pointer
1328  * argument can be used in the callbacks to stop immediately the loop if
1329  * set to true, otherwise it will only be stopped if it returns a
1330  * non-zero value.
1331  *
1332  * @param[in] xhp Pointer to the xbps_handle struct.
1333  * @param[in] fn Function callback to execute for every repository registered in
1334  * the pool.
1335  * @param[in] arg Opaque data passed in to the \a fn function callback for
1336  * client data.
1337  *
1338  * @return 0 on success, otherwise an errno value.
1339  */
1340 int xbps_rpool_foreach(struct xbps_handle *xhp,
1341  int (*fn)(struct xbps_rindex *, void *, bool *),
1342  void *arg);
1343 
1344 /**
1345  * Finds a package dictionary in the repository pool by specifying a
1346  * package pattern or a package name. This function does not take into
1347  * account virtual packages, just matches real packages.
1348  *
1349  * @param[in] xhp Pointer to the xbps_handle struct.
1350  * @param[in] pkg Package pattern, exact pkg or pkg name.
1351  *
1352  * @return The package dictionary if found, NULL otherwise.
1353  * @note When returned dictionary is no longer needed, you must release it
1354  * with prop_object_release(3).
1355  */
1356 prop_dictionary_t xbps_rpool_get_pkg(struct xbps_handle *xhp, const char *pkg);
1357 
1358 /**
1359  * Finds a package dictionary in repository pool by specifying a
1360  * virtual package pattern or a package name.
1361  *
1362  * @param[in] xhp Pointer to the xbps_handle struct.
1363  * @param[in] pkg Virtual package pattern or name to match.
1364  *
1365  * @return The package dictionary if found, NULL otherwise.
1366  * @note When returned dictionary is no longer needed, you must release it
1367  * with prop_object_release(3).
1368  */
1369 prop_dictionary_t xbps_rpool_get_virtualpkg(struct xbps_handle *xhp,
1370  const char *pkg);
1371 
1372 /**
1373  * Iterate over the the repository pool and search for a metadata plist
1374  * file in a binary package matching `pattern'. If a package is matched
1375  * the plist file \a plistf will be internalized into a proplib dictionary.
1376  *
1377  * When \a pattern is a pkgname, the newest package available in repositories
1378  * will be used. Otherwise the first repository matching \a pattern.
1379  *
1380  * @param[in] xhp Pointer to the xbps_handle struct.
1381  * @param[in] pattern Package name or package pattern to match, i.e `foo>=1.0'.
1382  * @param[in] plistf Plist file name to match, i.e XBPS_PKGPROPS or XBPS_PKGFILES.
1383  *
1384  * @return An internalized proplib dictionary of \a plistf, otherwise NULL
1385  * and errno is set appropiately.
1386  *
1387  * @note if NULL is returned and errno is ENOENT, that means that
1388  * binary package file has been found but the plist file could not
1389  * be found.
1390  */
1391 prop_dictionary_t xbps_rpool_get_pkg_plist(struct xbps_handle *xhp,
1392  const char *pattern,
1393  const char *plistf);
1394 
1395 /*@}*/
1396 
1397 /** @addtogroup rindex */
1398 /*@{*/
1399 
1400 /**
1401  * Returns a pkg dictionary from a repository index \a ri matching
1402  * the expression \a pkg.
1403  *
1404  * @param[in] ri Pointer to an xbps_rindex structure.
1405  * @param[in] pkg Package expression to match in this repository index.
1406  *
1407  * @return The pkg dictionary on success, NULL otherwise.
1408  */
1409 prop_dictionary_t xbps_rindex_get_pkg(struct xbps_rindex *ri, const char *pkg);
1410 
1411 /**
1412  * Returns a pkg dictionary from a repository index \a ri matching
1413  * the expression \a pkg. On match the first package matching the virtual
1414  * package expression will be returned.
1415  *
1416  * @param[in] ri Pointer to an xbps_rindex structure.
1417  * @param[in] pkg Package expression to match in this repository index.
1418  *
1419  * @return The pkg dictionary on success, NULL otherwise.
1420  */
1421 prop_dictionary_t xbps_rindex_get_virtualpkg(struct xbps_rindex *ri,
1422  const char *pkg);
1423 
1424 /*@}*/
1425 
1426 /** @addtogroup pkgstates */
1427 /*@{*/
1428 
1429 /**
1430  * @enum pkg_state_t
1431  *
1432  * Integer representing a state on which a package may be. Possible
1433  * values for this are:
1434  *
1435  * - XBPS_PKG_STATE_UNPACKED: Package has been unpacked correctly
1436  * but has not been configured due to unknown reasons.
1437  * - XBPS_PKG_STATE_INSTALLED: Package has been installed successfully.
1438  * - XBPS_PKG_STATE_BROKEN: not yet used.
1439  * - XBPS_PKG_STATE_HALF_REMOVED: Package has been removed but not
1440  * completely: the purge action in REMOVE script wasn't executed, pkg
1441  * metadata directory still exists and is registered in package database.
1442  * - XBPS_PKG_STATE_NOT_INSTALLED: Package going to be installed in
1443  * a transaction dictionary but that has not been yet unpacked.
1444  */
1445 typedef enum pkg_state {
1446  XBPS_PKG_STATE_UNPACKED = 1,
1447  XBPS_PKG_STATE_INSTALLED,
1448  XBPS_PKG_STATE_BROKEN,
1449  XBPS_PKG_STATE_HALF_REMOVED,
1450  XBPS_PKG_STATE_NOT_INSTALLED,
1451 } pkg_state_t;
1452 
1453 /**
1454  * Gets package state from package \a pkgname, and sets its state
1455  * into \a state.
1456  *
1457  * @param[in] xhp The pointer to an xbps_handle struct.
1458  * @param[in] pkgname Package name.
1459  * @param[out] state Package state returned.
1460  *
1461  * @return 0 on success, otherwise an errno value.
1462  */
1463 int xbps_pkg_state_installed(struct xbps_handle *xhp,
1464  const char *pkgname,
1465  pkg_state_t *state);
1466 
1467 /**
1468  * Gets package state from a package dictionary \a dict, and sets its
1469  * state into \a state.
1470  *
1471  * @param[in] dict Package dictionary.
1472  * @param[out] state Package state returned.
1473  *
1474  * @return 0 on success, otherwise an errno value.
1475  */
1476 int xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state);
1477 
1478 /**
1479  * Sets package state \a state in package \a pkgname.
1480  *
1481  * @param[in] xhp The pointer to an xbps_handle struct.
1482  * @param[in] pkgname Package name.
1483  * @param[in] version Package version.
1484  * @param[in] state Package state to be set.
1485  *
1486  * @return 0 on success, otherwise an errno value.
1487  */
1489  const char *pkgname,
1490  const char *version,
1491  pkg_state_t state);
1492 
1493 /**
1494  * Sets package state \a state in package dictionary \a dict.
1495  *
1496  * @param[in] dict Package dictionary.
1497  * @param[in] state Package state to be set.
1498  *
1499  * @return 0 on success, otherwise an errno value.
1500  */
1501 int xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state);
1502 
1503 /*@}*/
1504 
1505 /** @addtogroup util */
1506 /*@{*/
1507 
1508 /**
1509  * Creates a directory (and required components if necessary).
1510  *
1511  * @param[in] path Path for final directory.
1512  * @param[in] mode Mode for final directory (0755 if not specified).
1513  *
1514  * @return 0 on success, -1 on error and errno set appropiately.
1515  */
1516 int xbps_mkpath(const char *path, mode_t mode);
1517 
1518 /**
1519  * Returns a string by concatenating its variable argument list
1520  * as specified by the format string \a fmt.
1521  *
1522  * @param[in] fmt Format string, see printf(3).
1523  * @return A pointer to a malloc(3)ed string, NULL otherwise and errno
1524  * is set appropiately. The pointer should be free(3)d when it's
1525  * no longer needed.
1526  */
1527 char *xbps_xasprintf(const char *fmt, ...);
1528 
1529 /**
1530  * Returns a string with the sha256 hash for the file specified
1531  * by \a file.
1532  *
1533  * @param[in] file Path to a file.
1534  * @return A pointer to a malloc(3)ed string, NULL otherwise and errno
1535  * is set appropiately. The pointer should be free(3)d when it's no
1536  * longer needed.
1537  */
1538 char *xbps_file_hash(const char *file);
1539 
1540 /**
1541  * Compares the sha256 hash of the file \a file with the sha256
1542  * string specified by \a sha256.
1543  *
1544  * @param[in] file Path to a file.
1545  * @param[in] sha256 SHA256 hash to compare.
1546  *
1547  * @return 0 if \a file and \a sha256 have the same hash, ERANGE
1548  * if it differs, or any other errno value on error.
1549  */
1550 int xbps_file_hash_check(const char *file, const char *sha256);
1551 
1552 /**
1553  * Checks if a package is currently installed by matching \a pkg.
1554  *
1555  * @param[in] xhp The pointer to an xbps_handle struct.
1556  * @param[in] pkg Package name, version pattern or exact pkg to match.
1557  *
1558  * @return -1 on error (errno set appropiately), 0 if \a pkg
1559  * didn't match installed package, 1 if \a pkg pattern fully
1560  * matched installed package.
1561  */
1562 int xbps_pkg_is_installed(struct xbps_handle *xhp, const char *pkg);
1563 
1564 /**
1565  * Checks if the URI specified by \a uri is remote or local.
1566  *
1567  * @param[in] uri URI string.
1568  *
1569  * @return true if URI is remote, false if local.
1570  */
1571 bool xbps_repository_is_remote(const char *uri);
1572 
1573 /**
1574  * Gets the full path to a repository package index plist file, as
1575  * specified by \a uri.
1576  *
1577  * @param[in] xhp The pointer to an xbps_handle struct.
1578  * @param[in] uri Repository URI.
1579  *
1580  * @return A pointer to a malloc(3)d string, NULL otherwise and
1581  * errno is set appropiately. The pointer should be free(3)d when it's
1582  * no longer needed.
1583  */
1584 char *xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri);
1585 
1586 /**
1587  * Returns the full path to a repository package index files plist file,
1588  * as specified by \a uri.
1589  *
1590  * @param[in] xhp The pointer to an xbps_handle struct.
1591  * @param[in] uri Repository URI.
1592  *
1593  * @return A pointer to a malloc(3)ed string, NULL otherwise and
1594  * errno is set appropiately. The pointer should be free(3)d when it's
1595  * no longer needded.
1596  */
1597 char *xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri);
1598 
1599 /**
1600  * Gets the name of a package string. Package strings are composed
1601  * by a @<pkgname@>/@<version@> pair and separated by the <em>minus</em>
1602  * sign, i.e <b>foo-2.0</b>.
1603  *
1604  * @param[in] pkg Package string.
1605  *
1606  * @return A pointer to a malloc(3)d string, NULL otherwise and
1607  * errno is set appropiately. The pointer should be free(3)d when it's
1608  * no longer needed.
1609  */
1610 char *xbps_pkg_name(const char *pkg);
1611 
1612 /**
1613  * Gets a the package name of a package pattern string specified by
1614  * the \a pattern argument.
1615  *
1616  * @param[in] pattern A package pattern. Package patterns are composed
1617  * by looking at <b>'><='</b> to split components, i.e <b>foo>=2.0</b>,
1618  * <b>blah<1.0</b>, <b>blob==2.0</b>, etc.
1619  *
1620  * @return A pointer to a malloc(3)ed string with the package name,
1621  * NULL otherwise and errno is set appropiately. The pointer should be
1622  * free(3)d when it's no longer needed.
1623  */
1624 char *xbps_pkgpattern_name(const char *pattern);
1625 
1626 /**
1627  * Gets the package version in a package string, i.e <b>foo-2.0</b>.
1628  *
1629  * @param[in] pkg Package string.
1630  *
1631  * @return A string with the version string, NULL if it couldn't
1632  * find the version component.
1633  */
1634 const char *xbps_pkg_version(const char *pkg);
1635 
1636 /**
1637  * Gets the package version of a package pattern string specified by
1638  * the \a pattern argument.
1639  *
1640  * @param[in] pattern A package pattern. The same rules in
1641  * xbps_get_pkgpattern_name() apply here.
1642  *
1643  * @return A string with the pattern version, NULL otherwise and
1644  * errno is set appropiately.
1645  */
1646 const char *xbps_pkgpattern_version(const char *pattern);
1647 
1648 /**
1649  * Package pattern matching.
1650  *
1651  * @param[in] pkgver Package name/version, i.e `foo-1.0'.
1652  * @param[in] pattern Package pattern to match against \a pkgver.
1653  * There are 3 strategies for version matching:
1654  * - simple compare: pattern equals to pkgver.
1655  * - shell wildcards: see fnmatch(3).
1656  * - relational dewey matching: '>' '<' '>=' '<='.
1657  *
1658  * @return 1 if \a pkgver is matched against \a pattern, 0 if no match.
1659  */
1660 int xbps_pkgpattern_match(const char *pkgver, const char *pattern);
1661 
1662 /**
1663  * Gets the package version revision in a package string.
1664  *
1665  * @param[in] pkg Package string, i.e <b>foo-2.0_1</b>.
1666  *
1667  * @return A string with the revision number, NULL if it couldn't
1668  * find the revision component.
1669  */
1670 const char *xbps_pkg_revision(const char *pkg);
1671 
1672 /**
1673  * Checks if a package has run dependencies.
1674  *
1675  * @param[in] dict Package dictionary.
1676  *
1677  * @return True if package has run dependencies, false otherwise.
1678  */
1679 bool xbps_pkg_has_rundeps(prop_dictionary_t dict);
1680 
1681 /**
1682  * Returns true if provided string is valid for target architecture.
1683  *
1684  * @param[in] xhp The pointer to an xbps_handle struct.
1685  * @param[in] orig Architecture to match.
1686  * @param[in] target If not NULL, \a orig will be matched against it
1687  * rather than returned value of uname(2).
1688  *
1689  * @return True on match, false otherwise.
1690  */
1691 bool xbps_pkg_arch_match(struct xbps_handle *xhp,
1692  const char *orig,
1693  const char *target);
1694 
1695 /**
1696  * Converts the 64 bits signed number specified in \a bytes to
1697  * a human parsable string buffer pointed to \a buf.
1698  *
1699  * @param[out] buf Buffer to store the resulting string. At least
1700  * it should have space for 6 chars.
1701  * @param[in] bytes 64 bits signed number to convert.
1702  *
1703  * @return A negative number is returned on error, 0 otherwise.
1704  */
1705 int xbps_humanize_number(char *buf, int64_t bytes);
1706 
1707 /**
1708  * Compares package version strings.
1709  *
1710  * The package version is defined by:
1711  * ${VERSION}[_${REVISION}].
1712  *
1713  * @param[in] pkg1 a package version string.
1714  * @param[in] pkg2 a package version string.
1715  *
1716  * @return -1, 0 or 1 depending if pkg1 is less than, equal to or
1717  * greater than pkg2.
1718  */
1719 int xbps_cmpver(const char *pkg1, const char *pkg2);
1720 
1721 /*@}*/
1722 
1723 __END_DECLS
1724 
1725 #endif /* !_XBPS_API_H_ */