Rename pmpkg_t to alpm_pkg_t
[pacman-ng.git] / lib / libalpm / alpm.h
blob6bff5567508c75fea34c4d09a64879b6fc6d6d67
1 /*
2 * alpm.h
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _ALPM_H
24 #define _ALPM_H
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 #include <sys/types.h> /* for off_t */
31 #include <time.h> /* for time_t */
32 #include <stdarg.h> /* for va_list */
34 #include <alpm_list.h>
36 #define DEPRECATED __attribute__((deprecated))
39 * Arch Linux Package Management library
42 /** @addtogroup alpm_api Public API
43 * The libalpm Public API
44 * @{
48 * Enumerations
49 * These ones are used in multiple contexts, so are forward-declared.
52 /**
53 * Install reasons.
54 * Why the package was installed.
56 typedef enum _alpm_pkgreason_t {
57 /** Explicitly requested by the user. */
58 PM_PKG_REASON_EXPLICIT = 0,
59 /** Installed as a dependency for another package. */
60 PM_PKG_REASON_DEPEND = 1
61 } alpm_pkgreason_t;
63 /** Types of version constraints in dependency specs. */
64 typedef enum _alpm_depmod_t {
65 /** No version constraint */
66 PM_DEP_MOD_ANY = 1,
67 /** Test version equality (package=x.y.z) */
68 PM_DEP_MOD_EQ,
69 /** Test for at least a version (package>=x.y.z) */
70 PM_DEP_MOD_GE,
71 /** Test for at most a version (package<=x.y.z) */
72 PM_DEP_MOD_LE,
73 /** Test for greater than some version (package>x.y.z) */
74 PM_DEP_MOD_GT,
75 /** Test for less than some version (package<x.y.z) */
76 PM_DEP_MOD_LT
77 } alpm_depmod_t;
79 /**
80 * File conflict type.
81 * Whether the conflict results from a file existing on the filesystem, or with
82 * another target in the transaction.
84 typedef enum _alpm_fileconflicttype_t {
85 PM_FILECONFLICT_TARGET = 1,
86 PM_FILECONFLICT_FILESYSTEM
87 } alpm_fileconflicttype_t;
89 /**
90 * GPG signature verification options
92 typedef enum _pgp_verify_t {
93 PM_PGP_VERIFY_UNKNOWN,
94 PM_PGP_VERIFY_NEVER,
95 PM_PGP_VERIFY_OPTIONAL,
96 PM_PGP_VERIFY_ALWAYS
97 } pgp_verify_t;
100 * Structures
103 typedef struct __alpm_handle_t alpm_handle_t;
104 typedef struct __alpm_db_t alpm_db_t;
105 typedef struct __alpm_pkg_t alpm_pkg_t;
106 typedef struct __pmtrans_t pmtrans_t;
108 /** Dependency */
109 typedef struct _pmdepend_t {
110 char *name;
111 char *version;
112 unsigned long name_hash;
113 alpm_depmod_t mod;
114 } pmdepend_t;
116 /** Missing dependency */
117 typedef struct _pmdepmissing_t {
118 char *target;
119 pmdepend_t *depend;
120 /* this is used in case of remove dependency error only */
121 char *causingpkg;
122 } pmdepmissing_t;
124 /** Conflict */
125 typedef struct _pmconflict_t {
126 char *package1;
127 char *package2;
128 char *reason;
129 } pmconflict_t;
131 /** File conflict */
132 typedef struct _pmfileconflict_t {
133 char *target;
134 alpm_fileconflicttype_t type;
135 char *file;
136 char *ctarget;
137 } pmfileconflict_t;
139 /** Package group */
140 typedef struct _pmgrp_t {
141 /** group name */
142 char *name;
143 /** list of alpm_pkg_t packages */
144 alpm_list_t *packages;
145 } pmgrp_t;
147 /** Package upgrade delta */
148 typedef struct _pmdelta_t {
149 /** filename of the delta patch */
150 char *delta;
151 /** md5sum of the delta file */
152 char *delta_md5;
153 /** filename of the 'before' file */
154 char *from;
155 /** filename of the 'after' file */
156 char *to;
157 /** filesize of the delta file */
158 off_t delta_size;
159 /** download filesize of the delta file */
160 off_t download_size;
161 } pmdelta_t;
163 /** Local package or package file backup entry */
164 typedef struct _pmbackup_t {
165 char *name;
166 char *hash;
167 } pmbackup_t;
170 * Logging facilities
174 * Logging Levels
176 typedef enum _pmloglevel_t {
177 PM_LOG_ERROR = 1,
178 PM_LOG_WARNING = (1 << 1),
179 PM_LOG_DEBUG = (1 << 2),
180 PM_LOG_FUNCTION = (1 << 3)
181 } pmloglevel_t;
183 typedef void (*alpm_cb_log)(pmloglevel_t, const char *, va_list);
184 int alpm_logaction(alpm_handle_t *handle, const char *fmt, ...);
187 * Downloading
190 /** Type of download progress callbacks.
191 * @param filename the name of the file being downloaded
192 * @param xfered the number of transferred bytes
193 * @param total the total number of bytes to transfer
195 typedef void (*alpm_cb_download)(const char *filename,
196 off_t xfered, off_t total);
198 typedef void (*alpm_cb_totaldl)(off_t total);
200 /** A callback for downloading files
201 * @param url the URL of the file to be downloaded
202 * @param localpath the directory to which the file should be downloaded
203 * @param force whether to force an update, even if the file is the same
204 * @return 0 on success, 1 if the file exists and is identical, -1 on
205 * error.
207 typedef int (*alpm_cb_fetch)(const char *url, const char *localpath,
208 int force);
210 /** Fetch a remote pkg.
211 * @param handle the context handle
212 * @param url URL of the package to download
213 * @return the downloaded filepath on success, NULL on error
215 char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url);
217 /** @addtogroup alpm_api_options Options
218 * Libalpm option getters and setters
219 * @{
222 /** Returns the callback used for logging. */
223 alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle);
224 /** Sets the callback used for logging. */
225 int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb);
227 /** Returns the callback used to report download progress. */
228 alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
229 /** Sets the callback used to report download progress. */
230 int alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb);
232 /** Returns the downloading callback. */
233 alpm_cb_fetch alpm_option_get_fetchcb(alpm_handle_t *handle);
234 /** Sets the downloading callback. */
235 int alpm_option_set_fetchcb(alpm_handle_t *handle, alpm_cb_fetch cb);
237 /** Returns the callback used to report total download size. */
238 alpm_cb_totaldl alpm_option_get_totaldlcb(alpm_handle_t *handle);
239 /** Sets the callback used to report total download size. */
240 int alpm_option_set_totaldlcb(alpm_handle_t *handle, alpm_cb_totaldl cb);
242 /** Returns the root of the destination filesystem. Read-only. */
243 const char *alpm_option_get_root(alpm_handle_t *handle);
245 /** Returns the path to the database directory. Read-only. */
246 const char *alpm_option_get_dbpath(alpm_handle_t *handle);
248 /** Get the name of the database lock file. Read-only. */
249 const char *alpm_option_get_lockfile(alpm_handle_t *handle);
251 /** @name Accessors to the list of package cache directories.
252 * @{
254 alpm_list_t *alpm_option_get_cachedirs(alpm_handle_t *handle);
255 int alpm_option_set_cachedirs(alpm_handle_t *handle, alpm_list_t *cachedirs);
256 int alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir);
257 int alpm_option_remove_cachedir(alpm_handle_t *handle, const char *cachedir);
258 /** @} */
260 /** Returns the logfile name. */
261 const char *alpm_option_get_logfile(alpm_handle_t *handle);
262 /** Sets the logfile name. */
263 int alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile);
265 /** Returns the path to libalpm's GnuPG home directory. */
266 const char *alpm_option_get_gpgdir(alpm_handle_t *handle);
267 /** Sets the path to libalpm's GnuPG home directory. */
268 int alpm_option_set_gpgdir(alpm_handle_t *handle, const char *gpgdir);
270 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
271 int alpm_option_get_usesyslog(alpm_handle_t *handle);
272 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
273 int alpm_option_set_usesyslog(alpm_handle_t *handle, int usesyslog);
275 /** @name Accessors to the list of no-upgrade files.
276 * These functions modify the list of files which should
277 * not be updated by package installation.
278 * @{
280 alpm_list_t *alpm_option_get_noupgrades(alpm_handle_t *handle);
281 int alpm_option_add_noupgrade(alpm_handle_t *handle, const char *pkg);
282 int alpm_option_set_noupgrades(alpm_handle_t *handle, alpm_list_t *noupgrade);
283 int alpm_option_remove_noupgrade(alpm_handle_t *handle, const char *pkg);
284 /** @} */
286 /** @name Accessors to the list of no-extract files.
287 * These functions modify the list of filenames which should
288 * be skipped packages which should
289 * not be upgraded by a sysupgrade operation.
290 * @{
292 alpm_list_t *alpm_option_get_noextracts(alpm_handle_t *handle);
293 int alpm_option_add_noextract(alpm_handle_t *handle, const char *pkg);
294 int alpm_option_set_noextracts(alpm_handle_t *handle, alpm_list_t *noextract);
295 int alpm_option_remove_noextract(alpm_handle_t *handle, const char *pkg);
296 /** @} */
298 /** @name Accessors to the list of ignored packages.
299 * These functions modify the list of packages that
300 * should be ignored by a sysupgrade.
301 * @{
303 alpm_list_t *alpm_option_get_ignorepkgs(alpm_handle_t *handle);
304 int alpm_option_add_ignorepkg(alpm_handle_t *handle, const char *pkg);
305 int alpm_option_set_ignorepkgs(alpm_handle_t *handle, alpm_list_t *ignorepkgs);
306 int alpm_option_remove_ignorepkg(alpm_handle_t *handle, const char *pkg);
307 /** @} */
309 /** @name Accessors to the list of ignored groups.
310 * These functions modify the list of groups whose packages
311 * should be ignored by a sysupgrade.
312 * @{
314 alpm_list_t *alpm_option_get_ignoregrps(alpm_handle_t *handle);
315 int alpm_option_add_ignoregrp(alpm_handle_t *handle, const char *grp);
316 int alpm_option_set_ignoregrps(alpm_handle_t *handle, alpm_list_t *ignoregrps);
317 int alpm_option_remove_ignoregrp(alpm_handle_t *handle, const char *grp);
318 /** @} */
320 /** Returns the targeted architecture. */
321 const char *alpm_option_get_arch(alpm_handle_t *handle);
322 /** Sets the targeted architecture. */
323 int alpm_option_set_arch(alpm_handle_t *handle, const char *arch);
325 int alpm_option_get_usedelta(alpm_handle_t *handle);
326 int alpm_option_set_usedelta(alpm_handle_t *handle, int usedelta);
328 int alpm_option_get_checkspace(alpm_handle_t *handle);
329 int alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace);
331 pgp_verify_t alpm_option_get_default_sigverify(alpm_handle_t *handle);
332 int alpm_option_set_default_sigverify(alpm_handle_t *handle, pgp_verify_t level);
334 /** @} */
336 /** @addtogroup alpm_api_databases Database Functions
337 * Functions to query and manipulate the database of libalpm.
338 * @{
341 /** Get the database of locally installed packages.
342 * The returned pointer points to an internal structure
343 * of libalpm which should only be manipulated through
344 * libalpm functions.
345 * @return a reference to the local database
347 alpm_db_t *alpm_option_get_localdb(alpm_handle_t *handle);
349 /** Get the list of sync databases.
350 * Returns a list of alpm_db_t structures, one for each registered
351 * sync database.
352 * @param handle the context handle
353 * @return a reference to an internal list of alpm_db_t structures
355 alpm_list_t *alpm_option_get_syncdbs(alpm_handle_t *handle);
357 /** Register a sync database of packages.
358 * @param handle the context handle
359 * @param treename the name of the sync repository
360 * @param check_sig what level of signature checking to perform on the
361 * database; note that this must be a '.sig' file type verification
362 * @return a alpm_db_t* on success (the value), NULL on error
364 alpm_db_t *alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
365 pgp_verify_t check_sig);
367 /** Unregister a package database.
368 * @param db pointer to the package database to unregister
369 * @return 0 on success, -1 on error (pm_errno is set accordingly)
371 int alpm_db_unregister(alpm_db_t *db);
373 /** Unregister all package databases.
374 * @param handle the context handle
375 * @return 0 on success, -1 on error (pm_errno is set accordingly)
377 int alpm_db_unregister_all(alpm_handle_t *handle);
379 /** Get the name of a package database.
380 * @param db pointer to the package database
381 * @return the name of the package database, NULL on error
383 const char *alpm_db_get_name(const alpm_db_t *db);
385 /** @name Accessors to the list of servers for a database.
386 * @{
388 alpm_list_t *alpm_db_get_servers(const alpm_db_t *db);
389 int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers);
390 int alpm_db_add_server(alpm_db_t *db, const char *url);
391 int alpm_db_remove_server(alpm_db_t *db, const char *url);
392 /** @} */
394 int alpm_db_update(int level, alpm_db_t *db);
396 /** Get a package entry from a package database.
397 * @param db pointer to the package database to get the package from
398 * @param name of the package
399 * @return the package entry on success, NULL on error
401 alpm_pkg_t *alpm_db_get_pkg(alpm_db_t *db, const char *name);
403 /** Get the package cache of a package database.
404 * @param db pointer to the package database to get the package from
405 * @return the list of packages on success, NULL on error
407 alpm_list_t *alpm_db_get_pkgcache(alpm_db_t *db);
409 /** Get a group entry from a package database.
410 * @param db pointer to the package database to get the group from
411 * @param name of the group
412 * @return the groups entry on success, NULL on error
414 pmgrp_t *alpm_db_readgrp(alpm_db_t *db, const char *name);
416 /** Get the group cache of a package database.
417 * @param db pointer to the package database to get the group from
418 * @return the list of groups on success, NULL on error
420 alpm_list_t *alpm_db_get_grpcache(alpm_db_t *db);
422 /** Searches a database with regular expressions.
423 * @param db pointer to the package database to search in
424 * @param needles a list of regular expressions to search for
425 * @return the list of packages matching all regular expressions on success, NULL on error
427 alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles);
429 /** Set install reason for a package in db.
430 * @param db pointer to the package database
431 * @param name the name of the package
432 * @param reason the new install reason
433 * @return 0 on success, -1 on error (pm_errno is set accordingly)
435 int alpm_db_set_pkgreason(alpm_db_t *db, const char *name, alpm_pkgreason_t reason);
437 /** @} */
439 /** @addtogroup alpm_api_packages Package Functions
440 * Functions to manipulate libalpm packages
441 * @{
444 /** Create a package from a file.
445 * If full is false, the archive is read only until all necessary
446 * metadata is found. If it is true, the entire archive is read, which
447 * serves as a verification of integrity and the filelist can be created.
448 * The allocated structure should be freed using alpm_pkg_free().
449 * @param handle the context handle
450 * @param filename location of the package tarball
451 * @param full whether to stop the load after metadata is read or continue
452 * through the full archive
453 * @param check_sig what level of package signature checking to perform on the
454 * package; note that this must be a '.sig' file type verification
455 * @param pkg address of the package pointer
456 * @return 0 on success, -1 on error (pm_errno is set accordingly)
458 int alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full,
459 pgp_verify_t check_sig, alpm_pkg_t **pkg);
461 /** Free a package.
462 * @param pkg package pointer to free
463 * @return 0 on success, -1 on error (pm_errno is set accordingly)
465 int alpm_pkg_free(alpm_pkg_t *pkg);
467 /** Check the integrity (with md5) of a package from the sync cache.
468 * @param pkg package pointer
469 * @return 0 on success, -1 on error (pm_errno is set accordingly)
471 int alpm_pkg_checkmd5sum(alpm_pkg_t *pkg);
473 /** Compare two version strings and determine which one is 'newer'. */
474 int alpm_pkg_vercmp(const char *a, const char *b);
476 /** Computes the list of packages requiring a given package.
477 * The return value of this function is a newly allocated
478 * list of package names (char*), it should be freed by the caller.
479 * @param pkg a package
480 * @return the list of packages requiring pkg
482 alpm_list_t *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg);
484 /** @name Package Property Accessors
485 * Any pointer returned by these functions points to internal structures
486 * allocated by libalpm. They should not be freed nor modified in any
487 * way.
488 * @{
491 /** Gets the name of the file from which the package was loaded.
492 * @param pkg a pointer to package
493 * @return a reference to an internal string
495 const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
497 /** Returns the package name.
498 * @param pkg a pointer to package
499 * @return a reference to an internal string
501 const char *alpm_pkg_get_name(alpm_pkg_t *pkg);
503 /** Returns the package version as a string.
504 * This includes all available epoch, version, and pkgrel components. Use
505 * alpm_pkg_vercmp() to compare version strings if necessary.
506 * @param pkg a pointer to package
507 * @return a reference to an internal string
509 const char *alpm_pkg_get_version(alpm_pkg_t *pkg);
511 /** Returns the package description.
512 * @param pkg a pointer to package
513 * @return a reference to an internal string
515 const char *alpm_pkg_get_desc(alpm_pkg_t *pkg);
517 /** Returns the package URL.
518 * @param pkg a pointer to package
519 * @return a reference to an internal string
521 const char *alpm_pkg_get_url(alpm_pkg_t *pkg);
523 /** Returns the build timestamp of the package.
524 * @param pkg a pointer to package
525 * @return the timestamp of the build time
527 time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg);
529 /** Returns the install timestamp of the package.
530 * @param pkg a pointer to package
531 * @return the timestamp of the install time
533 time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg);
535 /** Returns the packager's name.
536 * @param pkg a pointer to package
537 * @return a reference to an internal string
539 const char *alpm_pkg_get_packager(alpm_pkg_t *pkg);
541 /** Returns the package's MD5 checksum as a string.
542 * The returned string is a sequence of lowercase hexadecimal digits.
543 * @param pkg a pointer to package
544 * @return a reference to an internal string
546 const char *alpm_pkg_get_md5sum(alpm_pkg_t *pkg);
548 /** Returns the architecture for which the package was built.
549 * @param pkg a pointer to package
550 * @return a reference to an internal string
552 const char *alpm_pkg_get_arch(alpm_pkg_t *pkg);
554 /** Returns the size of the package.
555 * @param pkg a pointer to package
556 * @return the size of the package in bytes.
558 off_t alpm_pkg_get_size(alpm_pkg_t *pkg);
560 /** Returns the installed size of the package.
561 * @param pkg a pointer to package
562 * @return the total size of files installed by the package.
564 off_t alpm_pkg_get_isize(alpm_pkg_t *pkg);
566 /** Returns the package installation reason.
567 * @param pkg a pointer to package
568 * @return an enum member giving the install reason.
570 alpm_pkgreason_t alpm_pkg_get_reason(alpm_pkg_t *pkg);
572 /** Returns the list of package licenses.
573 * @param pkg a pointer to package
574 * @return a pointer to an internal list of strings.
576 alpm_list_t *alpm_pkg_get_licenses(alpm_pkg_t *pkg);
578 /** Returns the list of package groups.
579 * @param pkg a pointer to package
580 * @return a pointer to an internal list of strings.
582 alpm_list_t *alpm_pkg_get_groups(alpm_pkg_t *pkg);
584 /** Returns the list of package dependencies as pmdepend_t.
585 * @param pkg a pointer to package
586 * @return a reference to an internal list of pmdepend_t structures.
588 alpm_list_t *alpm_pkg_get_depends(alpm_pkg_t *pkg);
590 /** Returns the list of package optional dependencies.
591 * @param pkg a pointer to package
592 * @return a reference to an internal list of strings.
594 alpm_list_t *alpm_pkg_get_optdepends(alpm_pkg_t *pkg);
596 /** Returns the list of package names conflicting with pkg.
597 * @param pkg a pointer to package
598 * @return a reference to an internal list of strings.
600 alpm_list_t *alpm_pkg_get_conflicts(alpm_pkg_t *pkg);
602 /** Returns the list of package names provided by pkg.
603 * @param pkg a pointer to package
604 * @return a reference to an internal list of strings.
606 alpm_list_t *alpm_pkg_get_provides(alpm_pkg_t *pkg);
608 /** Returns the list of available deltas for pkg.
609 * @param pkg a pointer to package
610 * @return a reference to an internal list of strings.
612 alpm_list_t *alpm_pkg_get_deltas(alpm_pkg_t *pkg);
614 /** Returns the list of packages to be replaced by pkg.
615 * @param pkg a pointer to package
616 * @return a reference to an internal list of strings.
618 alpm_list_t *alpm_pkg_get_replaces(alpm_pkg_t *pkg);
620 /** Returns the list of files installed by pkg.
621 * The filenames are relative to the install root,
622 * and do not include leading slashes.
623 * @param pkg a pointer to package
624 * @return a reference to an internal list of strings.
626 alpm_list_t *alpm_pkg_get_files(alpm_pkg_t *pkg);
628 /** Returns the list of files backed up when installing pkg.
629 * The elements of the returned list have the form
630 * "<filename>\t<md5sum>", where the given md5sum is that of
631 * the file as provided by the package.
632 * @param pkg a pointer to package
633 * @return a reference to an internal list of strings.
635 alpm_list_t *alpm_pkg_get_backup(alpm_pkg_t *pkg);
637 /** Returns the database containing pkg.
638 * Returns a pointer to the alpm_db_t structure the package is
639 * originating from, or NULL if the package was loaded from a file.
640 * @param pkg a pointer to package
641 * @return a pointer to the DB containing pkg, or NULL.
643 alpm_db_t *alpm_pkg_get_db(alpm_pkg_t *pkg);
645 /* End of alpm_pkg_t accessors */
646 /* @} */
648 /** Open a package changelog for reading.
649 * Similar to fopen in functionality, except that the returned 'file
650 * stream' could really be from an archive as well as from the database.
651 * @param pkg the package to read the changelog of (either file or db)
652 * @return a 'file stream' to the package changelog
654 void *alpm_pkg_changelog_open(alpm_pkg_t *pkg);
656 /** Read data from an open changelog 'file stream'.
657 * Similar to fread in functionality, this function takes a buffer and
658 * amount of data to read. If an error occurs pm_errno will be set.
659 * @param ptr a buffer to fill with raw changelog data
660 * @param size the size of the buffer
661 * @param pkg the package that the changelog is being read from
662 * @param fp a 'file stream' to the package changelog
663 * @return the number of characters read, or 0 if there is no more data or an
664 * error occurred.
666 size_t alpm_pkg_changelog_read(void *ptr, size_t size,
667 const alpm_pkg_t *pkg, const void *fp);
669 /*int alpm_pkg_changelog_feof(const alpm_pkg_t *pkg, void *fp);*/
671 int alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp);
673 /** Returns whether the package has an install scriptlet.
674 * @return 0 if FALSE, TRUE otherwise
676 int alpm_pkg_has_scriptlet(alpm_pkg_t *pkg);
678 /** Returns the size of download.
679 * Returns the size of the files that will be downloaded to install a
680 * package.
681 * @param newpkg the new package to upgrade to
682 * @return the size of the download
684 off_t alpm_pkg_download_size(alpm_pkg_t *newpkg);
686 alpm_list_t *alpm_pkg_unused_deltas(alpm_pkg_t *pkg);
688 /* End of alpm_pkg */
689 /** @} */
692 * Signatures
695 int alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg);
697 int alpm_db_check_pgp_signature(alpm_db_t *db);
700 * Groups
703 alpm_list_t *alpm_find_grp_pkgs(alpm_list_t *dbs, const char *name);
706 * Sync
709 alpm_pkg_t *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
711 /** @addtogroup alpm_api_trans Transaction Functions
712 * Functions to manipulate libalpm transactions
713 * @{
716 /** Transaction flags */
717 typedef enum _pmtransflag_t {
718 /** Ignore dependency checks. */
719 PM_TRANS_FLAG_NODEPS = 1,
720 /** Ignore file conflicts and overwrite files. */
721 PM_TRANS_FLAG_FORCE = (1 << 1),
722 /** Delete files even if they are tagged as backup. */
723 PM_TRANS_FLAG_NOSAVE = (1 << 2),
724 /** Ignore version numbers when checking dependencies. */
725 PM_TRANS_FLAG_NODEPVERSION = (1 << 3),
726 /** Remove also any packages depending on a package being removed. */
727 PM_TRANS_FLAG_CASCADE = (1 << 4),
728 /** Remove packages and their unneeded deps (not explicitly installed). */
729 PM_TRANS_FLAG_RECURSE = (1 << 5),
730 /** Modify database but do not commit changes to the filesystem. */
731 PM_TRANS_FLAG_DBONLY = (1 << 6),
732 /* (1 << 7) flag can go here */
733 /** Use PM_PKG_REASON_DEPEND when installing packages. */
734 PM_TRANS_FLAG_ALLDEPS = (1 << 8),
735 /** Only download packages and do not actually install. */
736 PM_TRANS_FLAG_DOWNLOADONLY = (1 << 9),
737 /** Do not execute install scriptlets after installing. */
738 PM_TRANS_FLAG_NOSCRIPTLET = (1 << 10),
739 /** Ignore dependency conflicts. */
740 PM_TRANS_FLAG_NOCONFLICTS = (1 << 11),
741 /* (1 << 12) flag can go here */
742 /** Do not install a package if it is already installed and up to date. */
743 PM_TRANS_FLAG_NEEDED = (1 << 13),
744 /** Use PM_PKG_REASON_EXPLICIT when installing packages. */
745 PM_TRANS_FLAG_ALLEXPLICIT = (1 << 14),
746 /** Do not remove a package if it is needed by another one. */
747 PM_TRANS_FLAG_UNNEEDED = (1 << 15),
748 /** Remove also explicitly installed unneeded deps (use with PM_TRANS_FLAG_RECURSE). */
749 PM_TRANS_FLAG_RECURSEALL = (1 << 16),
750 /** Do not lock the database during the operation. */
751 PM_TRANS_FLAG_NOLOCK = (1 << 17)
752 } pmtransflag_t;
754 /** Transaction events.
755 * NULL parameters are passed to in all events unless specified otherwise.
757 typedef enum _pmtransevt_t {
758 /** Dependencies will be computed for a package. */
759 PM_TRANS_EVT_CHECKDEPS_START = 1,
760 /** Dependencies were computed for a package. */
761 PM_TRANS_EVT_CHECKDEPS_DONE,
762 /** File conflicts will be computed for a package. */
763 PM_TRANS_EVT_FILECONFLICTS_START,
764 /** File conflicts were computed for a package. */
765 PM_TRANS_EVT_FILECONFLICTS_DONE,
766 /** Dependencies will be resolved for target package. */
767 PM_TRANS_EVT_RESOLVEDEPS_START,
768 /** Dependencies were resolved for target package. */
769 PM_TRANS_EVT_RESOLVEDEPS_DONE,
770 /** Inter-conflicts will be checked for target package. */
771 PM_TRANS_EVT_INTERCONFLICTS_START,
772 /** Inter-conflicts were checked for target package. */
773 PM_TRANS_EVT_INTERCONFLICTS_DONE,
774 /** Package will be installed.
775 * A pointer to the target package is passed to the callback.
777 PM_TRANS_EVT_ADD_START,
778 /** Package was installed.
779 * A pointer to the new package is passed to the callback.
781 PM_TRANS_EVT_ADD_DONE,
782 /** Package will be removed.
783 * A pointer to the target package is passed to the callback.
785 PM_TRANS_EVT_REMOVE_START,
786 /** Package was removed.
787 * A pointer to the removed package is passed to the callback.
789 PM_TRANS_EVT_REMOVE_DONE,
790 /** Package will be upgraded.
791 * A pointer to the upgraded package is passed to the callback.
793 PM_TRANS_EVT_UPGRADE_START,
794 /** Package was upgraded.
795 * A pointer to the new package, and a pointer to the old package is passed
796 * to the callback, respectively.
798 PM_TRANS_EVT_UPGRADE_DONE,
799 /** Target package's integrity will be checked. */
800 PM_TRANS_EVT_INTEGRITY_START,
801 /** Target package's integrity was checked. */
802 PM_TRANS_EVT_INTEGRITY_DONE,
803 /** Target deltas's integrity will be checked. */
804 PM_TRANS_EVT_DELTA_INTEGRITY_START,
805 /** Target delta's integrity was checked. */
806 PM_TRANS_EVT_DELTA_INTEGRITY_DONE,
807 /** Deltas will be applied to packages. */
808 PM_TRANS_EVT_DELTA_PATCHES_START,
809 /** Deltas were applied to packages. */
810 PM_TRANS_EVT_DELTA_PATCHES_DONE,
811 /** Delta patch will be applied to target package.
812 * The filename of the package and the filename of the patch is passed to the
813 * callback.
815 PM_TRANS_EVT_DELTA_PATCH_START,
816 /** Delta patch was applied to target package. */
817 PM_TRANS_EVT_DELTA_PATCH_DONE,
818 /** Delta patch failed to apply to target package. */
819 PM_TRANS_EVT_DELTA_PATCH_FAILED,
820 /** Scriptlet has printed information.
821 * A line of text is passed to the callback.
823 PM_TRANS_EVT_SCRIPTLET_INFO,
824 /** Files will be downloaded from a repository.
825 * The repository's tree name is passed to the callback.
827 PM_TRANS_EVT_RETRIEVE_START,
828 /** Disk space usage will be computed for a package */
829 PM_TRANS_EVT_DISKSPACE_START,
830 /** Disk space usage was computed for a package */
831 PM_TRANS_EVT_DISKSPACE_DONE,
832 } pmtransevt_t;
834 /** Transaction Conversations (ie, questions) */
835 typedef enum _pmtransconv_t {
836 PM_TRANS_CONV_INSTALL_IGNOREPKG = 1,
837 PM_TRANS_CONV_REPLACE_PKG = (1 << 1),
838 PM_TRANS_CONV_CONFLICT_PKG = (1 << 2),
839 PM_TRANS_CONV_CORRUPTED_PKG = (1 << 3),
840 PM_TRANS_CONV_LOCAL_NEWER = (1 << 4),
841 PM_TRANS_CONV_REMOVE_PKGS = (1 << 5),
842 PM_TRANS_CONV_SELECT_PROVIDER = (1 << 6),
843 } pmtransconv_t;
845 /** Transaction Progress */
846 typedef enum _pmtransprog_t {
847 PM_TRANS_PROGRESS_ADD_START,
848 PM_TRANS_PROGRESS_UPGRADE_START,
849 PM_TRANS_PROGRESS_REMOVE_START,
850 PM_TRANS_PROGRESS_CONFLICTS_START,
851 PM_TRANS_PROGRESS_DISKSPACE_START,
852 PM_TRANS_PROGRESS_INTEGRITY_START,
853 } pmtransprog_t;
855 /** Transaction Event callback */
856 typedef void (*alpm_trans_cb_event)(pmtransevt_t, void *, void *);
858 /** Transaction Conversation callback */
859 typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
860 void *, int *);
862 /** Transaction Progress callback */
863 typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t);
865 /** Returns the bitfield of flags for the current transaction.
866 * @param handle the context handle
867 * @return the bitfield of transaction flags
869 pmtransflag_t alpm_trans_get_flags(alpm_handle_t *handle);
871 /** Returns a list of packages added by the transaction.
872 * @param handle the context handle
873 * @return a list of alpm_pkg_t structures
875 alpm_list_t * alpm_trans_get_add(alpm_handle_t *handle);
877 /** Returns the list of packages removed by the transaction.
878 * @param handle the context handle
879 * @return a list of alpm_pkg_t structures
881 alpm_list_t * alpm_trans_get_remove(alpm_handle_t *handle);
883 /** Initialize the transaction.
884 * @param handle the context handle
885 * @param flags flags of the transaction (like nodeps, etc)
886 * @param event event callback function pointer
887 * @param conv question callback function pointer
888 * @param progress progress callback function pointer
889 * @return 0 on success, -1 on error (pm_errno is set accordingly)
891 int alpm_trans_init(alpm_handle_t *handle, pmtransflag_t flags,
892 alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
893 alpm_trans_cb_progress cb_progress);
895 /** Prepare a transaction.
896 * @param handle the context handle
897 * @param data the address of an alpm_list where a list
898 * of pmdepmissing_t objects is dumped (conflicting packages)
899 * @return 0 on success, -1 on error (pm_errno is set accordingly)
901 int alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data);
903 /** Commit a transaction.
904 * @param handle the context handle
905 * @param data the address of an alpm_list where detailed description
906 * of an error can be dumped (ie. list of conflicting files)
907 * @return 0 on success, -1 on error (pm_errno is set accordingly)
909 int alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data);
911 /** Interrupt a transaction.
912 * @param handle the context handle
913 * @return 0 on success, -1 on error (pm_errno is set accordingly)
915 int alpm_trans_interrupt(alpm_handle_t *handle);
917 /** Release a transaction.
918 * @param handle the context handle
919 * @return 0 on success, -1 on error (pm_errno is set accordingly)
921 int alpm_trans_release(alpm_handle_t *handle);
922 /** @} */
924 /** @name Common Transactions */
925 /** @{ */
927 /** Search for packages to upgrade and add them to the transaction.
928 * @param handle the context handle
929 * @param enable_downgrade allow downgrading of packages if the remote version is lower
930 * @return 0 on success, -1 on error (pm_errno is set accordingly)
932 int alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade);
934 /** Add a package to the transaction.
935 * If the package was loaded by alpm_pkg_load(), it will be freed upon
936 * alpm_trans_release() invocation.
937 * @param handle the context handle
938 * @param pkg the package to add
939 * @return 0 on success, -1 on error (pm_errno is set accordingly)
941 int alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
943 /** Add a package removal action to the transaction.
944 * @param handle the context handle
945 * @param pkg the package to uninstall
946 * @return 0 on success, -1 on error (pm_errno is set accordingly)
948 int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
950 /** @} */
952 /** @addtogroup alpm_api_depends Dependency Functions
953 * Functions dealing with libalpm representation of dependency
954 * information.
955 * @{
958 alpm_list_t *alpm_checkdeps(alpm_handle_t *handle, alpm_list_t *pkglist,
959 alpm_list_t *remove, alpm_list_t *upgrade, int reversedeps);
960 alpm_pkg_t *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring);
961 alpm_pkg_t *alpm_find_dbs_satisfier(alpm_handle_t *handle,
962 alpm_list_t *dbs, const char *depstring);
964 alpm_list_t *alpm_checkconflicts(alpm_handle_t *handle, alpm_list_t *pkglist);
966 /** Returns a newly allocated string representing the dependency information.
967 * @param dep a dependency info structure
968 * @return a formatted string, e.g. "glibc>=2.12"
970 char *alpm_dep_compute_string(const pmdepend_t *dep);
972 /** @} */
974 /** @} */
977 * Helpers
980 /* checksums */
981 char *alpm_compute_md5sum(const char *name);
983 /** @addtogroup alpm_api_errors Error Codes
984 * @{
986 enum _pmerrno_t {
987 PM_ERR_MEMORY = 1,
988 PM_ERR_SYSTEM,
989 PM_ERR_BADPERMS,
990 PM_ERR_NOT_A_FILE,
991 PM_ERR_NOT_A_DIR,
992 PM_ERR_WRONG_ARGS,
993 PM_ERR_DISK_SPACE,
994 /* Interface */
995 PM_ERR_HANDLE_NULL,
996 PM_ERR_HANDLE_NOT_NULL,
997 PM_ERR_HANDLE_LOCK,
998 /* Databases */
999 PM_ERR_DB_OPEN,
1000 PM_ERR_DB_CREATE,
1001 PM_ERR_DB_NULL,
1002 PM_ERR_DB_NOT_NULL,
1003 PM_ERR_DB_NOT_FOUND,
1004 PM_ERR_DB_INVALID,
1005 PM_ERR_DB_VERSION,
1006 PM_ERR_DB_WRITE,
1007 PM_ERR_DB_REMOVE,
1008 /* Servers */
1009 PM_ERR_SERVER_BAD_URL,
1010 PM_ERR_SERVER_NONE,
1011 /* Transactions */
1012 PM_ERR_TRANS_NOT_NULL,
1013 PM_ERR_TRANS_NULL,
1014 PM_ERR_TRANS_DUP_TARGET,
1015 PM_ERR_TRANS_NOT_INITIALIZED,
1016 PM_ERR_TRANS_NOT_PREPARED,
1017 PM_ERR_TRANS_ABORT,
1018 PM_ERR_TRANS_TYPE,
1019 PM_ERR_TRANS_NOT_LOCKED,
1020 /* Packages */
1021 PM_ERR_PKG_NOT_FOUND,
1022 PM_ERR_PKG_IGNORED,
1023 PM_ERR_PKG_INVALID,
1024 PM_ERR_PKG_OPEN,
1025 PM_ERR_PKG_CANT_REMOVE,
1026 PM_ERR_PKG_INVALID_NAME,
1027 PM_ERR_PKG_INVALID_ARCH,
1028 PM_ERR_PKG_REPO_NOT_FOUND,
1029 /* Signatures */
1030 PM_ERR_SIG_MISSINGDIR,
1031 PM_ERR_SIG_INVALID,
1032 PM_ERR_SIG_UNKNOWN,
1033 /* Deltas */
1034 PM_ERR_DLT_INVALID,
1035 PM_ERR_DLT_PATCHFAILED,
1036 /* Dependencies */
1037 PM_ERR_UNSATISFIED_DEPS,
1038 PM_ERR_CONFLICTING_DEPS,
1039 PM_ERR_FILE_CONFLICTS,
1040 /* Misc */
1041 PM_ERR_RETRIEVE,
1042 PM_ERR_INVALID_REGEX,
1043 /* External library errors */
1044 PM_ERR_LIBARCHIVE,
1045 PM_ERR_LIBCURL,
1046 PM_ERR_EXTERNAL_DOWNLOAD,
1047 PM_ERR_GPGME
1050 /** Returns the current error code from the handle. */
1051 enum _pmerrno_t alpm_errno(alpm_handle_t *handle);
1053 /** Returns the string corresponding to an error number. */
1054 const char *alpm_strerror(enum _pmerrno_t err);
1056 /* End of alpm_api_errors */
1057 /** @} */
1059 alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
1060 enum _pmerrno_t *err);
1061 int alpm_release(alpm_handle_t *handle);
1062 const char *alpm_version(void);
1064 /* End of alpm_api */
1065 /** @} */
1067 #ifdef __cplusplus
1069 #endif
1070 #endif /* _ALPM_H */
1072 /* vim: set ts=2 sw=2 noet: */