1 /* 2 * alpm.h 3 * 4 * Copyright (c) 2006-2018 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> 9 * 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. 14 * 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. 19 * 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/>. 22 */ 23 #ifndef ALPM_H 24 #define ALPM_H 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #include <stdint.h> /* int64_t */ 31 #include <sys/types.h> /* off_t */ 32 #include <stdarg.h> /* va_list */ 33 34 /* libarchive */ 35 #include <archive.h> 36 #include <archive_entry.h> 37 38 #include <alpm_list.h> 39 40 /* 41 * Arch Linux Package Management library 42 */ 43 44 /* 45 * Opaque Structures 46 */ 47 typedef struct __alpm_handle_t alpm_handle_t; 48 typedef struct __alpm_db_t alpm_db_t; 49 typedef struct __alpm_pkg_t alpm_pkg_t; 50 typedef struct __alpm_trans_t alpm_trans_t; 51 52 /** @addtogroup alpm_api_errors Error Codes 53 * @{ 54 */ 55 typedef enum _alpm_errno_t { 56 ALPM_ERR_OK = 0, 57 ALPM_ERR_MEMORY, 58 ALPM_ERR_SYSTEM, 59 ALPM_ERR_BADPERMS, 60 ALPM_ERR_NOT_A_FILE, 61 ALPM_ERR_NOT_A_DIR, 62 ALPM_ERR_WRONG_ARGS, 63 ALPM_ERR_DISK_SPACE, 64 /* Interface */ 65 ALPM_ERR_HANDLE_NULL, 66 ALPM_ERR_HANDLE_NOT_NULL, 67 ALPM_ERR_HANDLE_LOCK, 68 /* Databases */ 69 ALPM_ERR_DB_OPEN, 70 ALPM_ERR_DB_CREATE, 71 ALPM_ERR_DB_NULL, 72 ALPM_ERR_DB_NOT_NULL, 73 ALPM_ERR_DB_NOT_FOUND, 74 ALPM_ERR_DB_INVALID, 75 ALPM_ERR_DB_INVALID_SIG, 76 ALPM_ERR_DB_VERSION, 77 ALPM_ERR_DB_WRITE, 78 ALPM_ERR_DB_REMOVE, 79 /* Servers */ 80 ALPM_ERR_SERVER_BAD_URL, 81 ALPM_ERR_SERVER_NONE, 82 /* Transactions */ 83 ALPM_ERR_TRANS_NOT_NULL, 84 ALPM_ERR_TRANS_NULL, 85 ALPM_ERR_TRANS_DUP_TARGET, 86 ALPM_ERR_TRANS_NOT_INITIALIZED, 87 ALPM_ERR_TRANS_NOT_PREPARED, 88 ALPM_ERR_TRANS_ABORT, 89 ALPM_ERR_TRANS_TYPE, 90 ALPM_ERR_TRANS_NOT_LOCKED, 91 ALPM_ERR_TRANS_HOOK_FAILED, 92 /* Packages */ 93 ALPM_ERR_PKG_NOT_FOUND, 94 ALPM_ERR_PKG_IGNORED, 95 ALPM_ERR_PKG_INVALID, 96 ALPM_ERR_PKG_INVALID_CHECKSUM, 97 ALPM_ERR_PKG_INVALID_SIG, 98 ALPM_ERR_PKG_MISSING_SIG, 99 ALPM_ERR_PKG_OPEN, 100 ALPM_ERR_PKG_CANT_REMOVE, 101 ALPM_ERR_PKG_INVALID_NAME, 102 ALPM_ERR_PKG_INVALID_ARCH, 103 ALPM_ERR_PKG_REPO_NOT_FOUND, 104 /* Signatures */ 105 ALPM_ERR_SIG_MISSING, 106 ALPM_ERR_SIG_INVALID, 107 /* Deltas */ 108 ALPM_ERR_DLT_INVALID, 109 ALPM_ERR_DLT_PATCHFAILED, 110 /* Dependencies */ 111 ALPM_ERR_UNSATISFIED_DEPS, 112 ALPM_ERR_CONFLICTING_DEPS, 113 ALPM_ERR_FILE_CONFLICTS, 114 /* Misc */ 115 ALPM_ERR_RETRIEVE, 116 ALPM_ERR_INVALID_REGEX, 117 /* External library errors */ 118 ALPM_ERR_LIBARCHIVE, 119 ALPM_ERR_LIBCURL, 120 ALPM_ERR_EXTERNAL_DOWNLOAD, 121 ALPM_ERR_GPGME 122 } alpm_errno_t; 123 124 /** Returns the current error code from the handle. */ 125 alpm_errno_t alpm_errno(alpm_handle_t *handle); 126 127 /** Returns the string corresponding to an error number. */ 128 const char *alpm_strerror(alpm_errno_t err); 129 130 /* End of alpm_api_errors */ 131 /** @} */ 132 133 /** @addtogroup alpm_api Public API 134 * The libalpm Public API 135 * @{ 136 */ 137 138 typedef int64_t alpm_time_t; 139 140 /* 141 * Enumerations 142 * These ones are used in multiple contexts, so are forward-declared. 143 */ 144 145 /** Package install reasons. */ 146 typedef enum _alpm_pkgreason_t { 147 /** Explicitly requested by the user. */ 148 ALPM_PKG_REASON_EXPLICIT = 0, 149 /** Installed as a dependency for another package. */ 150 ALPM_PKG_REASON_DEPEND = 1 151 } alpm_pkgreason_t; 152 153 /** Location a package object was loaded from. */ 154 typedef enum _alpm_pkgfrom_t { 155 ALPM_PKG_FROM_FILE = 1, 156 ALPM_PKG_FROM_LOCALDB, 157 ALPM_PKG_FROM_SYNCDB 158 } alpm_pkgfrom_t; 159 160 /** Method used to validate a package. */ 161 typedef enum _alpm_pkgvalidation_t { 162 ALPM_PKG_VALIDATION_UNKNOWN = 0, 163 ALPM_PKG_VALIDATION_NONE = (1 << 0), 164 ALPM_PKG_VALIDATION_MD5SUM = (1 << 1), 165 ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2), 166 ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3) 167 } alpm_pkgvalidation_t; 168 169 /** Types of version constraints in dependency specs. */ 170 typedef enum _alpm_depmod_t { 171 /** No version constraint */ 172 ALPM_DEP_MOD_ANY = 1, 173 /** Test version equality (package=x.y.z) */ 174 ALPM_DEP_MOD_EQ, 175 /** Test for at least a version (package>=x.y.z) */ 176 ALPM_DEP_MOD_GE, 177 /** Test for at most a version (package<=x.y.z) */ 178 ALPM_DEP_MOD_LE, 179 /** Test for greater than some version (package>x.y.z) */ 180 ALPM_DEP_MOD_GT, 181 /** Test for less than some version (package<x.y.z) */ 182 ALPM_DEP_MOD_LT 183 } alpm_depmod_t; 184 185 /** 186 * File conflict type. 187 * Whether the conflict results from a file existing on the filesystem, or with 188 * another target in the transaction. 189 */ 190 typedef enum _alpm_fileconflicttype_t { 191 ALPM_FILECONFLICT_TARGET = 1, 192 ALPM_FILECONFLICT_FILESYSTEM 193 } alpm_fileconflicttype_t; 194 195 /** PGP signature verification options */ 196 typedef enum _alpm_siglevel_t { 197 ALPM_SIG_PACKAGE = (1 << 0), 198 ALPM_SIG_PACKAGE_OPTIONAL = (1 << 1), 199 ALPM_SIG_PACKAGE_MARGINAL_OK = (1 << 2), 200 ALPM_SIG_PACKAGE_UNKNOWN_OK = (1 << 3), 201 202 ALPM_SIG_DATABASE = (1 << 10), 203 ALPM_SIG_DATABASE_OPTIONAL = (1 << 11), 204 ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12), 205 ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13), 206 207 ALPM_SIG_USE_DEFAULT = (1 << 30) 208 } alpm_siglevel_t; 209 210 /** PGP signature verification status return codes */ 211 typedef enum _alpm_sigstatus_t { 212 ALPM_SIGSTATUS_VALID, 213 ALPM_SIGSTATUS_KEY_EXPIRED, 214 ALPM_SIGSTATUS_SIG_EXPIRED, 215 ALPM_SIGSTATUS_KEY_UNKNOWN, 216 ALPM_SIGSTATUS_KEY_DISABLED, 217 ALPM_SIGSTATUS_INVALID 218 } alpm_sigstatus_t; 219 220 /** PGP signature verification status return codes */ 221 typedef enum _alpm_sigvalidity_t { 222 ALPM_SIGVALIDITY_FULL, 223 ALPM_SIGVALIDITY_MARGINAL, 224 ALPM_SIGVALIDITY_NEVER, 225 ALPM_SIGVALIDITY_UNKNOWN 226 } alpm_sigvalidity_t; 227 228 /* 229 * Structures 230 */ 231 232 /** Dependency */ 233 typedef struct _alpm_depend_t { 234 char *name; 235 char *version; 236 char *desc; 237 unsigned long name_hash; 238 alpm_depmod_t mod; 239 } alpm_depend_t; 240 241 /** Missing dependency */ 242 typedef struct _alpm_depmissing_t { 243 char *target; 244 alpm_depend_t *depend; 245 /* this is used only in the case of a remove dependency error */ 246 char *causingpkg; 247 } alpm_depmissing_t; 248 249 /** Conflict */ 250 typedef struct _alpm_conflict_t { 251 unsigned long package1_hash; 252 unsigned long package2_hash; 253 char *package1; 254 char *package2; 255 alpm_depend_t *reason; 256 } alpm_conflict_t; 257 258 /** File conflict */ 259 typedef struct _alpm_fileconflict_t { 260 char *target; 261 alpm_fileconflicttype_t type; 262 char *file; 263 char *ctarget; 264 } alpm_fileconflict_t; 265 266 /** Package group */ 267 typedef struct _alpm_group_t { 268 /** group name */ 269 char *name; 270 /** list of alpm_pkg_t packages */ 271 alpm_list_t *packages; 272 } alpm_group_t; 273 274 /** Package upgrade delta */ 275 typedef struct _alpm_delta_t { 276 /** filename of the delta patch */ 277 char *delta; 278 /** md5sum of the delta file */ 279 char *delta_md5; 280 /** filename of the 'before' file */ 281 char *from; 282 /** filename of the 'after' file */ 283 char *to; 284 /** filesize of the delta file */ 285 off_t delta_size; 286 /** download filesize of the delta file */ 287 off_t download_size; 288 } alpm_delta_t; 289 290 /** File in a package */ 291 typedef struct _alpm_file_t { 292 char *name; 293 off_t size; 294 mode_t mode; 295 } alpm_file_t; 296 297 /** Package filelist container */ 298 typedef struct _alpm_filelist_t { 299 size_t count; 300 alpm_file_t *files; 301 } alpm_filelist_t; 302 303 /** Local package or package file backup entry */ 304 typedef struct _alpm_backup_t { 305 char *name; 306 char *hash; 307 } alpm_backup_t; 308 309 typedef struct _alpm_pgpkey_t { 310 void *data; 311 char *fingerprint; 312 char *uid; 313 char *name; 314 char *email; 315 alpm_time_t created; 316 alpm_time_t expires; 317 unsigned int length; 318 unsigned int revoked; 319 char pubkey_algo; 320 } alpm_pgpkey_t; 321 322 /** 323 * Signature result. Contains the key, status, and validity of a given 324 * signature. 325 */ 326 typedef struct _alpm_sigresult_t { 327 alpm_pgpkey_t key; 328 alpm_sigstatus_t status; 329 alpm_sigvalidity_t validity; 330 } alpm_sigresult_t; 331 332 /** 333 * Signature list. Contains the number of signatures found and a pointer to an 334 * array of results. The array is of size count. 335 */ 336 typedef struct _alpm_siglist_t { 337 size_t count; 338 alpm_sigresult_t *results; 339 } alpm_siglist_t; 340 341 342 /* 343 * Hooks 344 */ 345 346 typedef enum _alpm_hook_when_t { 347 ALPM_HOOK_PRE_TRANSACTION = 1, 348 ALPM_HOOK_POST_TRANSACTION 349 } alpm_hook_when_t; 350 351 /* 352 * Logging facilities 353 */ 354 355 /** Logging Levels */ 356 typedef enum _alpm_loglevel_t { 357 ALPM_LOG_ERROR = 1, 358 ALPM_LOG_WARNING = (1 << 1), 359 ALPM_LOG_DEBUG = (1 << 2), 360 ALPM_LOG_FUNCTION = (1 << 3) 361 } alpm_loglevel_t; 362 363 typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list); 364 365 int alpm_logaction(alpm_handle_t *handle, const char *prefix, 366 const char *fmt, ...) __attribute__((format(printf, 3, 4))); 367 368 /** 369 * Type of events. 370 */ 371 typedef enum _alpm_event_type_t { 372 /** Dependencies will be computed for a package. */ 373 ALPM_EVENT_CHECKDEPS_START = 1, 374 /** Dependencies were computed for a package. */ 375 ALPM_EVENT_CHECKDEPS_DONE, 376 /** File conflicts will be computed for a package. */ 377 ALPM_EVENT_FILECONFLICTS_START, 378 /** File conflicts were computed for a package. */ 379 ALPM_EVENT_FILECONFLICTS_DONE, 380 /** Dependencies will be resolved for target package. */ 381 ALPM_EVENT_RESOLVEDEPS_START, 382 /** Dependencies were resolved for target package. */ 383 ALPM_EVENT_RESOLVEDEPS_DONE, 384 /** Inter-conflicts will be checked for target package. */ 385 ALPM_EVENT_INTERCONFLICTS_START, 386 /** Inter-conflicts were checked for target package. */ 387 ALPM_EVENT_INTERCONFLICTS_DONE, 388 /** Processing the package transaction is starting. */ 389 ALPM_EVENT_TRANSACTION_START, 390 /** Processing the package transaction is finished. */ 391 ALPM_EVENT_TRANSACTION_DONE, 392 /** Package will be installed/upgraded/downgraded/re-installed/removed; See 393 * alpm_event_package_operation_t for arguments. */ 394 ALPM_EVENT_PACKAGE_OPERATION_START, 395 /** Package was installed/upgraded/downgraded/re-installed/removed; See 396 * alpm_event_package_operation_t for arguments. */ 397 ALPM_EVENT_PACKAGE_OPERATION_DONE, 398 /** Target package's integrity will be checked. */ 399 ALPM_EVENT_INTEGRITY_START, 400 /** Target package's integrity was checked. */ 401 ALPM_EVENT_INTEGRITY_DONE, 402 /** Target package will be loaded. */ 403 ALPM_EVENT_LOAD_START, 404 /** Target package is finished loading. */ 405 ALPM_EVENT_LOAD_DONE, 406 /** Target delta's integrity will be checked. */ 407 ALPM_EVENT_DELTA_INTEGRITY_START, 408 /** Target delta's integrity was checked. */ 409 ALPM_EVENT_DELTA_INTEGRITY_DONE, 410 /** Deltas will be applied to packages. */ 411 ALPM_EVENT_DELTA_PATCHES_START, 412 /** Deltas were applied to packages. */ 413 ALPM_EVENT_DELTA_PATCHES_DONE, 414 /** Delta patch will be applied to target package; See 415 * alpm_event_delta_patch_t for arguments.. */ 416 ALPM_EVENT_DELTA_PATCH_START, 417 /** Delta patch was applied to target package. */ 418 ALPM_EVENT_DELTA_PATCH_DONE, 419 /** Delta patch failed to apply to target package. */ 420 ALPM_EVENT_DELTA_PATCH_FAILED, 421 /** Scriptlet has printed information; See alpm_event_scriptlet_info_t for 422 * arguments. */ 423 ALPM_EVENT_SCRIPTLET_INFO, 424 /** Files will be downloaded from a repository. */ 425 ALPM_EVENT_RETRIEVE_START, 426 /** Files were downloaded from a repository. */ 427 ALPM_EVENT_RETRIEVE_DONE, 428 /** Not all files were successfully downloaded from a repository. */ 429 ALPM_EVENT_RETRIEVE_FAILED, 430 /** A file will be downloaded from a repository; See alpm_event_pkgdownload_t 431 * for arguments */ 432 ALPM_EVENT_PKGDOWNLOAD_START, 433 /** A file was downloaded from a repository; See alpm_event_pkgdownload_t 434 * for arguments */ 435 ALPM_EVENT_PKGDOWNLOAD_DONE, 436 /** A file failed to be downloaded from a repository; See 437 * alpm_event_pkgdownload_t for arguments */ 438 ALPM_EVENT_PKGDOWNLOAD_FAILED, 439 /** Disk space usage will be computed for a package. */ 440 ALPM_EVENT_DISKSPACE_START, 441 /** Disk space usage was computed for a package. */ 442 ALPM_EVENT_DISKSPACE_DONE, 443 /** An optdepend for another package is being removed; See 444 * alpm_event_optdep_removal_t for arguments. */ 445 ALPM_EVENT_OPTDEP_REMOVAL, 446 /** A configured repository database is missing; See 447 * alpm_event_database_missing_t for arguments. */ 448 ALPM_EVENT_DATABASE_MISSING, 449 /** Checking keys used to create signatures are in keyring. */ 450 ALPM_EVENT_KEYRING_START, 451 /** Keyring checking is finished. */ 452 ALPM_EVENT_KEYRING_DONE, 453 /** Downloading missing keys into keyring. */ 454 ALPM_EVENT_KEY_DOWNLOAD_START, 455 /** Key downloading is finished. */ 456 ALPM_EVENT_KEY_DOWNLOAD_DONE, 457 /** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */ 458 ALPM_EVENT_PACNEW_CREATED, 459 /** A .pacsave file was created; See alpm_event_pacsave_created_t for 460 * arguments */ 461 ALPM_EVENT_PACSAVE_CREATED, 462 /** Processing hooks will be started. */ 463 ALPM_EVENT_HOOK_START, 464 /** Processing hooks is finished. */ 465 ALPM_EVENT_HOOK_DONE, 466 /** A hook is starting */ 467 ALPM_EVENT_HOOK_RUN_START, 468 /** A hook has finished running */ 469 ALPM_EVENT_HOOK_RUN_DONE 470 } alpm_event_type_t; 471 472 typedef struct _alpm_event_any_t { 473 /** Type of event. */ 474 alpm_event_type_t type; 475 } alpm_event_any_t; 476 477 typedef enum _alpm_package_operation_t { 478 /** Package (to be) installed. (No oldpkg) */ 479 ALPM_PACKAGE_INSTALL = 1, 480 /** Package (to be) upgraded */ 481 ALPM_PACKAGE_UPGRADE, 482 /** Package (to be) re-installed. */ 483 ALPM_PACKAGE_REINSTALL, 484 /** Package (to be) downgraded. */ 485 ALPM_PACKAGE_DOWNGRADE, 486 /** Package (to be) removed. (No newpkg) */ 487 ALPM_PACKAGE_REMOVE 488 } alpm_package_operation_t; 489 490 typedef struct _alpm_event_package_operation_t { 491 /** Type of event. */ 492 alpm_event_type_t type; 493 /** Type of operation. */ 494 alpm_package_operation_t operation; 495 /** Old package. */ 496 alpm_pkg_t *oldpkg; 497 /** New package. */ 498 alpm_pkg_t *newpkg; 499 } alpm_event_package_operation_t; 500 501 typedef struct _alpm_event_optdep_removal_t { 502 /** Type of event. */ 503 alpm_event_type_t type; 504 /** Package with the optdep. */ 505 alpm_pkg_t *pkg; 506 /** Optdep being removed. */ 507 alpm_depend_t *optdep; 508 } alpm_event_optdep_removal_t; 509 510 typedef struct _alpm_event_delta_patch_t { 511 /** Type of event. */ 512 alpm_event_type_t type; 513 /** Delta info */ 514 alpm_delta_t *delta; 515 } alpm_event_delta_patch_t; 516 517 typedef struct _alpm_event_scriptlet_info_t { 518 /** Type of event. */ 519 alpm_event_type_t type; 520 /** Line of scriptlet output. */ 521 const char *line; 522 } alpm_event_scriptlet_info_t; 523 524 typedef struct _alpm_event_database_missing_t { 525 /** Type of event. */ 526 alpm_event_type_t type; 527 /** Name of the database. */ 528 const char *dbname; 529 } alpm_event_database_missing_t; 530 531 typedef struct _alpm_event_pkgdownload_t { 532 /** Type of event. */ 533 alpm_event_type_t type; 534 /** Name of the file */ 535 const char *file; 536 } alpm_event_pkgdownload_t; 537 538 typedef struct _alpm_event_pacnew_created_t { 539 /** Type of event. */ 540 alpm_event_type_t type; 541 /** Whether the creation was result of a NoUpgrade or not */ 542 int from_noupgrade; 543 /** Old package. */ 544 alpm_pkg_t *oldpkg; 545 /** New Package. */ 546 alpm_pkg_t *newpkg; 547 /** Filename of the file without the .pacnew suffix */ 548 const char *file; 549 } alpm_event_pacnew_created_t; 550 551 typedef struct _alpm_event_pacsave_created_t { 552 /** Type of event. */ 553 alpm_event_type_t type; 554 /** Old package. */ 555 alpm_pkg_t *oldpkg; 556 /** Filename of the file without the .pacsave suffix. */ 557 const char *file; 558 } alpm_event_pacsave_created_t; 559 560 typedef struct _alpm_event_hook_t { 561 /** Type of event.*/ 562 alpm_event_type_t type; 563 /** Type of hooks. */ 564 alpm_hook_when_t when; 565 } alpm_event_hook_t; 566 567 typedef struct _alpm_event_hook_run_t { 568 /** Type of event.*/ 569 alpm_event_type_t type; 570 /** Name of hook */ 571 const char *name; 572 /** Description of hook to be outputted */ 573 const char *desc; 574 /** position of hook being run */ 575 size_t position; 576 /** total hooks being run */ 577 size_t total; 578 } alpm_event_hook_run_t; 579 580 /** Events. 581 * This is an union passed to the callback, that allows the frontend to know 582 * which type of event was triggered (via type). It is then possible to 583 * typecast the pointer to the right structure, or use the union field, in order 584 * to access event-specific data. */ 585 typedef union _alpm_event_t { 586 alpm_event_type_t type; 587 alpm_event_any_t any; 588 alpm_event_package_operation_t package_operation; 589 alpm_event_optdep_removal_t optdep_removal; 590 alpm_event_delta_patch_t delta_patch; 591 alpm_event_scriptlet_info_t scriptlet_info; 592 alpm_event_database_missing_t database_missing; 593 alpm_event_pkgdownload_t pkgdownload; 594 alpm_event_pacnew_created_t pacnew_created; 595 alpm_event_pacsave_created_t pacsave_created; 596 alpm_event_hook_t hook; 597 alpm_event_hook_run_t hook_run; 598 } alpm_event_t; 599 600 /** Event callback. */ 601 typedef void (*alpm_cb_event)(alpm_event_t *); 602 603 /** 604 * Type of questions. 605 * Unlike the events or progress enumerations, this enum has bitmask values 606 * so a frontend can use a bitmask map to supply preselected answers to the 607 * different types of questions. 608 */ 609 typedef enum _alpm_question_type_t { 610 ALPM_QUESTION_INSTALL_IGNOREPKG = (1 << 0), 611 ALPM_QUESTION_REPLACE_PKG = (1 << 1), 612 ALPM_QUESTION_CONFLICT_PKG = (1 << 2), 613 ALPM_QUESTION_CORRUPTED_PKG = (1 << 3), 614 ALPM_QUESTION_REMOVE_PKGS = (1 << 4), 615 ALPM_QUESTION_SELECT_PROVIDER = (1 << 5), 616 ALPM_QUESTION_IMPORT_KEY = (1 << 6) 617 } alpm_question_type_t; 618 619 typedef struct _alpm_question_any_t { 620 /** Type of question. */ 621 alpm_question_type_t type; 622 /** Answer. */ 623 int answer; 624 } alpm_question_any_t; 625 626 typedef struct _alpm_question_install_ignorepkg_t { 627 /** Type of question. */ 628 alpm_question_type_t type; 629 /** Answer: whether or not to install pkg anyway. */ 630 int install; 631 /* Package in IgnorePkg/IgnoreGroup. */ 632 alpm_pkg_t *pkg; 633 } alpm_question_install_ignorepkg_t; 634 635 typedef struct _alpm_question_replace_t { 636 /** Type of question. */ 637 alpm_question_type_t type; 638 /** Answer: whether or not to replace oldpkg with newpkg. */ 639 int replace; 640 /* Package to be replaced. */ 641 alpm_pkg_t *oldpkg; 642 /* Package to replace with. */ 643 alpm_pkg_t *newpkg; 644 /* DB of newpkg */ 645 alpm_db_t *newdb; 646 } alpm_question_replace_t; 647 648 typedef struct _alpm_question_conflict_t { 649 /** Type of question. */ 650 alpm_question_type_t type; 651 /** Answer: whether or not to remove conflict->package2. */ 652 int remove; 653 /** Conflict info. */ 654 alpm_conflict_t *conflict; 655 } alpm_question_conflict_t; 656 657 typedef struct _alpm_question_corrupted_t { 658 /** Type of question. */ 659 alpm_question_type_t type; 660 /** Answer: whether or not to remove filepath. */ 661 int remove; 662 /** Filename to remove */ 663 const char *filepath; 664 /** Error code indicating the reason for package invalidity */ 665 alpm_errno_t reason; 666 } alpm_question_corrupted_t; 667 668 typedef struct _alpm_question_remove_pkgs_t { 669 /** Type of question. */ 670 alpm_question_type_t type; 671 /** Answer: whether or not to skip packages. */ 672 int skip; 673 /** List of alpm_pkg_t* with unresolved dependencies. */ 674 alpm_list_t *packages; 675 } alpm_question_remove_pkgs_t; 676 677 typedef struct _alpm_question_select_provider_t { 678 /** Type of question. */ 679 alpm_question_type_t type; 680 /** Answer: which provider to use (index from providers). */ 681 int use_index; 682 /** List of alpm_pkg_t* as possible providers. */ 683 alpm_list_t *providers; 684 /** What providers provide for. */ 685 alpm_depend_t *depend; 686 } alpm_question_select_provider_t; 687 688 typedef struct _alpm_question_import_key_t { 689 /** Type of question. */ 690 alpm_question_type_t type; 691 /** Answer: whether or not to import key. */ 692 int import; 693 /** The key to import. */ 694 alpm_pgpkey_t *key; 695 } alpm_question_import_key_t; 696 697 /** 698 * Questions. 699 * This is an union passed to the callback, that allows the frontend to know 700 * which type of question was triggered (via type). It is then possible to 701 * typecast the pointer to the right structure, or use the union field, in order 702 * to access question-specific data. */ 703 typedef union _alpm_question_t { 704 alpm_question_type_t type; 705 alpm_question_any_t any; 706 alpm_question_install_ignorepkg_t install_ignorepkg; 707 alpm_question_replace_t replace; 708 alpm_question_conflict_t conflict; 709 alpm_question_corrupted_t corrupted; 710 alpm_question_remove_pkgs_t remove_pkgs; 711 alpm_question_select_provider_t select_provider; 712 alpm_question_import_key_t import_key; 713 } alpm_question_t; 714 715 /** Question callback */ 716 typedef void (*alpm_cb_question)(alpm_question_t *); 717 718 /** Progress */ 719 typedef enum _alpm_progress_t { 720 ALPM_PROGRESS_ADD_START, 721 ALPM_PROGRESS_UPGRADE_START, 722 ALPM_PROGRESS_DOWNGRADE_START, 723 ALPM_PROGRESS_REINSTALL_START, 724 ALPM_PROGRESS_REMOVE_START, 725 ALPM_PROGRESS_CONFLICTS_START, 726 ALPM_PROGRESS_DISKSPACE_START, 727 ALPM_PROGRESS_INTEGRITY_START, 728 ALPM_PROGRESS_LOAD_START, 729 ALPM_PROGRESS_KEYRING_START 730 } alpm_progress_t; 731 732 /** Progress callback */ 733 typedef void (*alpm_cb_progress)(alpm_progress_t, const char *, int, size_t, size_t); 734 735 /* 736 * Downloading 737 */ 738 739 /** Type of download progress callbacks. 740 * @param filename the name of the file being downloaded 741 * @param xfered the number of transferred bytes 742 * @param total the total number of bytes to transfer 743 */ 744 typedef void (*alpm_cb_download)(const char *filename, 745 off_t xfered, off_t total); 746 747 typedef void (*alpm_cb_totaldl)(off_t total); 748 749 /** A callback for downloading files 750 * @param url the URL of the file to be downloaded 751 * @param localpath the directory to which the file should be downloaded 752 * @param force whether to force an update, even if the file is the same 753 * @return 0 on success, 1 if the file exists and is identical, -1 on 754 * error. 755 */ 756 typedef int (*alpm_cb_fetch)(const char *url, const char *localpath, 757 int force); 758 759 /** Fetch a remote pkg. 760 * @param handle the context handle 761 * @param url URL of the package to download 762 * @return the downloaded filepath on success, NULL on error 763 */ 764 char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url); 765 766 /** @addtogroup alpm_api_options Options 767 * Libalpm option getters and setters 768 * @{ 769 */ 770 771 /** Returns the callback used for logging. */ 772 alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle); 773 /** Sets the callback used for logging. */ 774 int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb); 775 776 /** Returns the callback used to report download progress. */ 777 alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle); 778 /** Sets the callback used to report download progress. */ 779 int alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb); 780 781 /** Returns the downloading callback. */ 782 alpm_cb_fetch alpm_option_get_fetchcb(alpm_handle_t *handle); 783 /** Sets the downloading callback. */ 784 int alpm_option_set_fetchcb(alpm_handle_t *handle, alpm_cb_fetch cb); 785 786 /** Returns the callback used to report total download size. */ 787 alpm_cb_totaldl alpm_option_get_totaldlcb(alpm_handle_t *handle); 788 /** Sets the callback used to report total download size. */ 789 int alpm_option_set_totaldlcb(alpm_handle_t *handle, alpm_cb_totaldl cb); 790 791 /** Returns the callback used for events. */ 792 alpm_cb_event alpm_option_get_eventcb(alpm_handle_t *handle); 793 /** Sets the callback used for events. */ 794 int alpm_option_set_eventcb(alpm_handle_t *handle, alpm_cb_event cb); 795 796 /** Returns the callback used for questions. */ 797 alpm_cb_question alpm_option_get_questioncb(alpm_handle_t *handle); 798 /** Sets the callback used for questions. */ 799 int alpm_option_set_questioncb(alpm_handle_t *handle, alpm_cb_question cb); 800 801 /** Returns the callback used for operation progress. */ 802 alpm_cb_progress alpm_option_get_progresscb(alpm_handle_t *handle); 803 /** Sets the callback used for operation progress. */ 804 int alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress cb); 805 806 /** Returns the root of the destination filesystem. Read-only. */ 807 const char *alpm_option_get_root(alpm_handle_t *handle); 808 809 /** Returns the path to the database directory. Read-only. */ 810 const char *alpm_option_get_dbpath(alpm_handle_t *handle); 811 812 /** Get the name of the database lock file. Read-only. */ 813 const char *alpm_option_get_lockfile(alpm_handle_t *handle); 814 815 /** @name Accessors to the list of package cache directories. 816 * @{ 817 */ 818 alpm_list_t *alpm_option_get_cachedirs(alpm_handle_t *handle); 819 int alpm_option_set_cachedirs(alpm_handle_t *handle, alpm_list_t *cachedirs); 820 int alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir); 821 int alpm_option_remove_cachedir(alpm_handle_t *handle, const char *cachedir); 822 /** @} */ 823 824 /** @name Accessors to the list of package hook directories. 825 * @{ 826 */ 827 alpm_list_t *alpm_option_get_hookdirs(alpm_handle_t *handle); 828 int alpm_option_set_hookdirs(alpm_handle_t *handle, alpm_list_t *hookdirs); 829 int alpm_option_add_hookdir(alpm_handle_t *handle, const char *hookdir); 830 int alpm_option_remove_hookdir(alpm_handle_t *handle, const char *hookdir); 831 /** @} */ 832 833 alpm_list_t *alpm_option_get_overwrite_files(alpm_handle_t *handle); 834 int alpm_option_set_overwrite_files(alpm_handle_t *handle, alpm_list_t *globs); 835 int alpm_option_add_overwrite_file(alpm_handle_t *handle, const char *glob); 836 int alpm_option_remove_overwrite_file(alpm_handle_t *handle, const char *glob); 837 838 /** Returns the logfile name. */ 839 const char *alpm_option_get_logfile(alpm_handle_t *handle); 840 /** Sets the logfile name. */ 841 int alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile); 842 843 /** Returns the path to libalpm's GnuPG home directory. */ 844 const char *alpm_option_get_gpgdir(alpm_handle_t *handle); 845 /** Sets the path to libalpm's GnuPG home directory. */ 846 int alpm_option_set_gpgdir(alpm_handle_t *handle, const char *gpgdir); 847 848 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */ 849 int alpm_option_get_usesyslog(alpm_handle_t *handle); 850 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */ 851 int alpm_option_set_usesyslog(alpm_handle_t *handle, int usesyslog); 852 853 /** @name Accessors to the list of no-upgrade files. 854 * These functions modify the list of files which should 855 * not be updated by package installation. 856 * @{ 857 */ 858 alpm_list_t *alpm_option_get_noupgrades(alpm_handle_t *handle); 859 int alpm_option_add_noupgrade(alpm_handle_t *handle, const char *path); 860 int alpm_option_set_noupgrades(alpm_handle_t *handle, alpm_list_t *noupgrade); 861 int alpm_option_remove_noupgrade(alpm_handle_t *handle, const char *path); 862 int alpm_option_match_noupgrade(alpm_handle_t *handle, const char *path); 863 /** @} */ 864 865 /** @name Accessors to the list of no-extract files. 866 * These functions modify the list of filenames which should 867 * be skipped packages which should 868 * not be upgraded by a sysupgrade operation. 869 * @{ 870 */ 871 alpm_list_t *alpm_option_get_noextracts(alpm_handle_t *handle); 872 int alpm_option_add_noextract(alpm_handle_t *handle, const char *path); 873 int alpm_option_set_noextracts(alpm_handle_t *handle, alpm_list_t *noextract); 874 int alpm_option_remove_noextract(alpm_handle_t *handle, const char *path); 875 int alpm_option_match_noextract(alpm_handle_t *handle, const char *path); 876 /** @} */ 877 878 /** @name Accessors to the list of ignored packages. 879 * These functions modify the list of packages that 880 * should be ignored by a sysupgrade. 881 * @{ 882 */ 883 alpm_list_t *alpm_option_get_ignorepkgs(alpm_handle_t *handle); 884 int alpm_option_add_ignorepkg(alpm_handle_t *handle, const char *pkg); 885 int alpm_option_set_ignorepkgs(alpm_handle_t *handle, alpm_list_t *ignorepkgs); 886 int alpm_option_remove_ignorepkg(alpm_handle_t *handle, const char *pkg); 887 /** @} */ 888 889 /** @name Accessors to the list of ignored groups. 890 * These functions modify the list of groups whose packages 891 * should be ignored by a sysupgrade. 892 * @{ 893 */ 894 alpm_list_t *alpm_option_get_ignoregroups(alpm_handle_t *handle); 895 int alpm_option_add_ignoregroup(alpm_handle_t *handle, const char *grp); 896 int alpm_option_set_ignoregroups(alpm_handle_t *handle, alpm_list_t *ignoregrps); 897 int alpm_option_remove_ignoregroup(alpm_handle_t *handle, const char *grp); 898 /** @} */ 899 900 /** @name Accessors to the list of ignored dependencies. 901 * These functions modify the list of dependencies that 902 * should be ignored by a sysupgrade. 903 * @{ 904 */ 905 alpm_list_t *alpm_option_get_assumeinstalled(alpm_handle_t *handle); 906 int alpm_option_add_assumeinstalled(alpm_handle_t *handle, const alpm_depend_t *dep); 907 int alpm_option_set_assumeinstalled(alpm_handle_t *handle, alpm_list_t *deps); 908 int alpm_option_remove_assumeinstalled(alpm_handle_t *handle, const alpm_depend_t *dep); 909 /** @} */ 910 911 /** Returns the targeted architecture. */ 912 const char *alpm_option_get_arch(alpm_handle_t *handle); 913 /** Sets the targeted architecture. */ 914 int alpm_option_set_arch(alpm_handle_t *handle, const char *arch); 915 916 double alpm_option_get_deltaratio(alpm_handle_t *handle); 917 int alpm_option_set_deltaratio(alpm_handle_t *handle, double ratio); 918 919 int alpm_option_get_checkspace(alpm_handle_t *handle); 920 int alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace); 921 922 const char *alpm_option_get_dbext(alpm_handle_t *handle); 923 int alpm_option_set_dbext(alpm_handle_t *handle, const char *dbext); 924 925 int alpm_option_get_default_siglevel(alpm_handle_t *handle); 926 int alpm_option_set_default_siglevel(alpm_handle_t *handle, int level); 927 928 int alpm_option_get_local_file_siglevel(alpm_handle_t *handle); 929 int alpm_option_set_local_file_siglevel(alpm_handle_t *handle, int level); 930 931 int alpm_option_get_remote_file_siglevel(alpm_handle_t *handle); 932 int alpm_option_set_remote_file_siglevel(alpm_handle_t *handle, int level); 933 934 int alpm_option_set_disable_dl_timeout(alpm_handle_t *handle, unsigned short disable_dl_timeout); 935 936 /** @} */ 937 938 /** @addtogroup alpm_api_databases Database Functions 939 * Functions to query and manipulate the database of libalpm. 940 * @{ 941 */ 942 943 /** Get the database of locally installed packages. 944 * The returned pointer points to an internal structure 945 * of libalpm which should only be manipulated through 946 * libalpm functions. 947 * @return a reference to the local database 948 */ 949 alpm_db_t *alpm_get_localdb(alpm_handle_t *handle); 950 951 /** Get the list of sync databases. 952 * Returns a list of alpm_db_t structures, one for each registered 953 * sync database. 954 * @param handle the context handle 955 * @return a reference to an internal list of alpm_db_t structures 956 */ 957 alpm_list_t *alpm_get_syncdbs(alpm_handle_t *handle); 958 959 /** Register a sync database of packages. 960 * @param handle the context handle 961 * @param treename the name of the sync repository 962 * @param level what level of signature checking to perform on the 963 * database; note that this must be a '.sig' file type verification 964 * @return an alpm_db_t* on success (the value), NULL on error 965 */ 966 alpm_db_t *alpm_register_syncdb(alpm_handle_t *handle, const char *treename, 967 int level); 968 969 /** Unregister all package databases. 970 * @param handle the context handle 971 * @return 0 on success, -1 on error (pm_errno is set accordingly) 972 */ 973 int alpm_unregister_all_syncdbs(alpm_handle_t *handle); 974 975 /** Unregister a package database. 976 * @param db pointer to the package database to unregister 977 * @return 0 on success, -1 on error (pm_errno is set accordingly) 978 */ 979 int alpm_db_unregister(alpm_db_t *db); 980 981 /** Get the name of a package database. 982 * @param db pointer to the package database 983 * @return the name of the package database, NULL on error 984 */ 985 const char *alpm_db_get_name(const alpm_db_t *db); 986 987 /** Get the signature verification level for a database. 988 * Will return the default verification level if this database is set up 989 * with ALPM_SIG_USE_DEFAULT. 990 * @param db pointer to the package database 991 * @return the signature verification level 992 */ 993 int alpm_db_get_siglevel(alpm_db_t *db); 994 995 /** Check the validity of a database. 996 * This is most useful for sync databases and verifying signature status. 997 * If invalid, the handle error code will be set accordingly. 998 * @param db pointer to the package database 999 * @return 0 if valid, -1 if invalid (pm_errno is set accordingly) 1000 */ 1001 int alpm_db_get_valid(alpm_db_t *db); 1002 1003 /** @name Accessors to the list of servers for a database. 1004 * @{ 1005 */ 1006 alpm_list_t *alpm_db_get_servers(const alpm_db_t *db); 1007 int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers); 1008 int alpm_db_add_server(alpm_db_t *db, const char *url); 1009 int alpm_db_remove_server(alpm_db_t *db, const char *url); 1010 /** @} */ 1011 1012 int alpm_db_update(int force, alpm_db_t *db); 1013 1014 /** Get a package entry from a package database. 1015 * @param db pointer to the package database to get the package from 1016 * @param name of the package 1017 * @return the package entry on success, NULL on error 1018 */ 1019 alpm_pkg_t *alpm_db_get_pkg(alpm_db_t *db, const char *name); 1020 1021 /** Get the package cache of a package database. 1022 * @param db pointer to the package database to get the package from 1023 * @return the list of packages on success, NULL on error 1024 */ 1025 alpm_list_t *alpm_db_get_pkgcache(alpm_db_t *db); 1026 1027 /** Get a group entry from a package database. 1028 * @param db pointer to the package database to get the group from 1029 * @param name of the group 1030 * @return the groups entry on success, NULL on error 1031 */ 1032 alpm_group_t *alpm_db_get_group(alpm_db_t *db, const char *name); 1033 1034 /** Get the group cache of a package database. 1035 * @param db pointer to the package database to get the group from 1036 * @return the list of groups on success, NULL on error 1037 */ 1038 alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db); 1039 1040 /** Searches a database with regular expressions. 1041 * @param db pointer to the package database to search in 1042 * @param needles a list of regular expressions to search for 1043 * @return the list of packages matching all regular expressions on success, NULL on error 1044 */ 1045 alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles); 1046 1047 typedef enum _alpm_db_usage_ { 1048 ALPM_DB_USAGE_SYNC = 1, 1049 ALPM_DB_USAGE_SEARCH = (1 << 1), 1050 ALPM_DB_USAGE_INSTALL = (1 << 2), 1051 ALPM_DB_USAGE_UPGRADE = (1 << 3), 1052 ALPM_DB_USAGE_ALL = (1 << 4) - 1, 1053 } alpm_db_usage_t; 1054 1055 /** Sets the usage of a database. 1056 * @param db pointer to the package database to set the status for 1057 * @param usage a bitmask of alpm_db_usage_t values 1058 * @return 0 on success, or -1 on error 1059 */ 1060 int alpm_db_set_usage(alpm_db_t *db, int usage); 1061 1062 /** Gets the usage of a database. 1063 * @param db pointer to the package database to get the status of 1064 * @param usage pointer to an alpm_db_usage_t to store db's status 1065 * @return 0 on success, or -1 on error 1066 */ 1067 int alpm_db_get_usage(alpm_db_t *db, int *usage); 1068 1069 /** @} */ 1070 1071 /** @addtogroup alpm_api_packages Package Functions 1072 * Functions to manipulate libalpm packages 1073 * @{ 1074 */ 1075 1076 /** Create a package from a file. 1077 * If full is false, the archive is read only until all necessary 1078 * metadata is found. If it is true, the entire archive is read, which 1079 * serves as a verification of integrity and the filelist can be created. 1080 * The allocated structure should be freed using alpm_pkg_free(). 1081 * @param handle the context handle 1082 * @param filename location of the package tarball 1083 * @param full whether to stop the load after metadata is read or continue 1084 * through the full archive 1085 * @param level what level of package signature checking to perform on the 1086 * package; note that this must be a '.sig' file type verification 1087 * @param pkg address of the package pointer 1088 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1089 */ 1090 int alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full, 1091 int level, alpm_pkg_t **pkg); 1092 1093 /** Find a package in a list by name. 1094 * @param haystack a list of alpm_pkg_t 1095 * @param needle the package name 1096 * @return a pointer to the package if found or NULL 1097 */ 1098 alpm_pkg_t *alpm_pkg_find(alpm_list_t *haystack, const char *needle); 1099 1100 /** Free a package. 1101 * @param pkg package pointer to free 1102 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1103 */ 1104 int alpm_pkg_free(alpm_pkg_t *pkg); 1105 1106 /** Check the integrity (with md5) of a package from the sync cache. 1107 * @param pkg package pointer 1108 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1109 */ 1110 int alpm_pkg_checkmd5sum(alpm_pkg_t *pkg); 1111 1112 /** Compare two version strings and determine which one is 'newer'. */ 1113 int alpm_pkg_vercmp(const char *a, const char *b); 1114 1115 /** Computes the list of packages requiring a given package. 1116 * The return value of this function is a newly allocated 1117 * list of package names (char*), it should be freed by the caller. 1118 * @param pkg a package 1119 * @return the list of packages requiring pkg 1120 */ 1121 alpm_list_t *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg); 1122 1123 /** Computes the list of packages optionally requiring a given package. 1124 * The return value of this function is a newly allocated 1125 * list of package names (char*), it should be freed by the caller. 1126 * @param pkg a package 1127 * @return the list of packages optionally requiring pkg 1128 */ 1129 alpm_list_t *alpm_pkg_compute_optionalfor(alpm_pkg_t *pkg); 1130 1131 /** Test if a package should be ignored. 1132 * Checks if the package is ignored via IgnorePkg, or if the package is 1133 * in a group ignored via IgnoreGroup. 1134 * @param handle the context handle 1135 * @param pkg the package to test 1136 * @return 1 if the package should be ignored, 0 otherwise 1137 */ 1138 int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); 1139 1140 /** @name Package Property Accessors 1141 * Any pointer returned by these functions points to internal structures 1142 * allocated by libalpm. They should not be freed nor modified in any 1143 * way. 1144 * @{ 1145 */ 1146 1147 /** Gets the name of the file from which the package was loaded. 1148 * @param pkg a pointer to package 1149 * @return a reference to an internal string 1150 */ 1151 const char *alpm_pkg_get_filename(alpm_pkg_t *pkg); 1152 1153 /** Returns the package base name. 1154 * @param pkg a pointer to package 1155 * @return a reference to an internal string 1156 */ 1157 const char *alpm_pkg_get_base(alpm_pkg_t *pkg); 1158 1159 /** Returns the package name. 1160 * @param pkg a pointer to package 1161 * @return a reference to an internal string 1162 */ 1163 const char *alpm_pkg_get_name(alpm_pkg_t *pkg); 1164 1165 /** Returns the package version as a string. 1166 * This includes all available epoch, version, and pkgrel components. Use 1167 * alpm_pkg_vercmp() to compare version strings if necessary. 1168 * @param pkg a pointer to package 1169 * @return a reference to an internal string 1170 */ 1171 const char *alpm_pkg_get_version(alpm_pkg_t *pkg); 1172 1173 /** Returns the origin of the package. 1174 * @return an alpm_pkgfrom_t constant, -1 on error 1175 */ 1176 alpm_pkgfrom_t alpm_pkg_get_origin(alpm_pkg_t *pkg); 1177 1178 /** Returns the package description. 1179 * @param pkg a pointer to package 1180 * @return a reference to an internal string 1181 */ 1182 const char *alpm_pkg_get_desc(alpm_pkg_t *pkg); 1183 1184 /** Returns the package URL. 1185 * @param pkg a pointer to package 1186 * @return a reference to an internal string 1187 */ 1188 const char *alpm_pkg_get_url(alpm_pkg_t *pkg); 1189 1190 /** Returns the build timestamp of the package. 1191 * @param pkg a pointer to package 1192 * @return the timestamp of the build time 1193 */ 1194 alpm_time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg); 1195 1196 /** Returns the install timestamp of the package. 1197 * @param pkg a pointer to package 1198 * @return the timestamp of the install time 1199 */ 1200 alpm_time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg); 1201 1202 /** Returns the packager's name. 1203 * @param pkg a pointer to package 1204 * @return a reference to an internal string 1205 */ 1206 const char *alpm_pkg_get_packager(alpm_pkg_t *pkg); 1207 1208 /** Returns the package's MD5 checksum as a string. 1209 * The returned string is a sequence of 32 lowercase hexadecimal digits. 1210 * @param pkg a pointer to package 1211 * @return a reference to an internal string 1212 */ 1213 const char *alpm_pkg_get_md5sum(alpm_pkg_t *pkg); 1214 1215 /** Returns the package's SHA256 checksum as a string. 1216 * The returned string is a sequence of 64 lowercase hexadecimal digits. 1217 * @param pkg a pointer to package 1218 * @return a reference to an internal string 1219 */ 1220 const char *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg); 1221 1222 /** Returns the architecture for which the package was built. 1223 * @param pkg a pointer to package 1224 * @return a reference to an internal string 1225 */ 1226 const char *alpm_pkg_get_arch(alpm_pkg_t *pkg); 1227 1228 /** Returns the size of the package. This is only available for sync database 1229 * packages and package files, not those loaded from the local database. 1230 * @param pkg a pointer to package 1231 * @return the size of the package in bytes. 1232 */ 1233 off_t alpm_pkg_get_size(alpm_pkg_t *pkg); 1234 1235 /** Returns the installed size of the package. 1236 * @param pkg a pointer to package 1237 * @return the total size of files installed by the package. 1238 */ 1239 off_t alpm_pkg_get_isize(alpm_pkg_t *pkg); 1240 1241 /** Returns the package installation reason. 1242 * @param pkg a pointer to package 1243 * @return an enum member giving the install reason. 1244 */ 1245 alpm_pkgreason_t alpm_pkg_get_reason(alpm_pkg_t *pkg); 1246 1247 /** Returns the list of package licenses. 1248 * @param pkg a pointer to package 1249 * @return a pointer to an internal list of strings. 1250 */ 1251 alpm_list_t *alpm_pkg_get_licenses(alpm_pkg_t *pkg); 1252 1253 /** Returns the list of package groups. 1254 * @param pkg a pointer to package 1255 * @return a pointer to an internal list of strings. 1256 */ 1257 alpm_list_t *alpm_pkg_get_groups(alpm_pkg_t *pkg); 1258 1259 /** Returns the list of package dependencies as alpm_depend_t. 1260 * @param pkg a pointer to package 1261 * @return a reference to an internal list of alpm_depend_t structures. 1262 */ 1263 alpm_list_t *alpm_pkg_get_depends(alpm_pkg_t *pkg); 1264 1265 /** Returns the list of package optional dependencies. 1266 * @param pkg a pointer to package 1267 * @return a reference to an internal list of alpm_depend_t structures. 1268 */ 1269 alpm_list_t *alpm_pkg_get_optdepends(alpm_pkg_t *pkg); 1270 1271 /** Returns a list of package check dependencies 1272 * @param pkg a pointer to package 1273 * @return a reference to an internal list of alpm_depend_t structures. 1274 */ 1275 alpm_list_t *alpm_pkg_get_checkdepends(alpm_pkg_t *pkg); 1276 1277 /** Returns a list of package make dependencies 1278 * @param pkg a pointer to package 1279 * @return a reference to an internal list of alpm_depend_t structures. 1280 */ 1281 alpm_list_t *alpm_pkg_get_makedepends(alpm_pkg_t *pkg); 1282 1283 /** Returns the list of packages conflicting with pkg. 1284 * @param pkg a pointer to package 1285 * @return a reference to an internal list of alpm_depend_t structures. 1286 */ 1287 alpm_list_t *alpm_pkg_get_conflicts(alpm_pkg_t *pkg); 1288 1289 /** Returns the list of packages provided by pkg. 1290 * @param pkg a pointer to package 1291 * @return a reference to an internal list of alpm_depend_t structures. 1292 */ 1293 alpm_list_t *alpm_pkg_get_provides(alpm_pkg_t *pkg); 1294 1295 /** Returns the list of available deltas for pkg. 1296 * @param pkg a pointer to package 1297 * @return a reference to an internal list of strings. 1298 */ 1299 alpm_list_t *alpm_pkg_get_deltas(alpm_pkg_t *pkg); 1300 1301 /** Returns the list of packages to be replaced by pkg. 1302 * @param pkg a pointer to package 1303 * @return a reference to an internal list of alpm_depend_t structures. 1304 */ 1305 alpm_list_t *alpm_pkg_get_replaces(alpm_pkg_t *pkg); 1306 1307 /** Returns the list of files installed by pkg. 1308 * The filenames are relative to the install root, 1309 * and do not include leading slashes. 1310 * @param pkg a pointer to package 1311 * @return a pointer to a filelist object containing a count and an array of 1312 * package file objects 1313 */ 1314 alpm_filelist_t *alpm_pkg_get_files(alpm_pkg_t *pkg); 1315 1316 /** Returns the list of files backed up when installing pkg. 1317 * @param pkg a pointer to package 1318 * @return a reference to a list of alpm_backup_t objects 1319 */ 1320 alpm_list_t *alpm_pkg_get_backup(alpm_pkg_t *pkg); 1321 1322 /** Returns the database containing pkg. 1323 * Returns a pointer to the alpm_db_t structure the package is 1324 * originating from, or NULL if the package was loaded from a file. 1325 * @param pkg a pointer to package 1326 * @return a pointer to the DB containing pkg, or NULL. 1327 */ 1328 alpm_db_t *alpm_pkg_get_db(alpm_pkg_t *pkg); 1329 1330 /** Returns the base64 encoded package signature. 1331 * @param pkg a pointer to package 1332 * @return a reference to an internal string 1333 */ 1334 const char *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg); 1335 1336 /** Returns the method used to validate a package during install. 1337 * @param pkg a pointer to package 1338 * @return an enum member giving the validation method 1339 */ 1340 int alpm_pkg_get_validation(alpm_pkg_t *pkg); 1341 1342 /* End of alpm_pkg_t accessors */ 1343 /* @} */ 1344 1345 /** Open a package changelog for reading. 1346 * Similar to fopen in functionality, except that the returned 'file 1347 * stream' could really be from an archive as well as from the database. 1348 * @param pkg the package to read the changelog of (either file or db) 1349 * @return a 'file stream' to the package changelog 1350 */ 1351 void *alpm_pkg_changelog_open(alpm_pkg_t *pkg); 1352 1353 /** Read data from an open changelog 'file stream'. 1354 * Similar to fread in functionality, this function takes a buffer and 1355 * amount of data to read. If an error occurs pm_errno will be set. 1356 * @param ptr a buffer to fill with raw changelog data 1357 * @param size the size of the buffer 1358 * @param pkg the package that the changelog is being read from 1359 * @param fp a 'file stream' to the package changelog 1360 * @return the number of characters read, or 0 if there is no more data or an 1361 * error occurred. 1362 */ 1363 size_t alpm_pkg_changelog_read(void *ptr, size_t size, 1364 const alpm_pkg_t *pkg, void *fp); 1365 1366 int alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp); 1367 1368 /** Open a package mtree file for reading. 1369 * @param pkg the local package to read the changelog of 1370 * @return a archive structure for the package mtree file 1371 */ 1372 struct archive *alpm_pkg_mtree_open(alpm_pkg_t *pkg); 1373 1374 /** Read next entry from a package mtree file. 1375 * @param pkg the package that the mtree file is being read from 1376 * @param archive the archive structure reading from the mtree file 1377 * @param entry an archive_entry to store the entry header information 1378 * @return 0 if end of archive is reached, non-zero otherwise. 1379 */ 1380 int alpm_pkg_mtree_next(const alpm_pkg_t *pkg, struct archive *archive, 1381 struct archive_entry **entry); 1382 1383 int alpm_pkg_mtree_close(const alpm_pkg_t *pkg, struct archive *archive); 1384 1385 /** Returns whether the package has an install scriptlet. 1386 * @return 0 if FALSE, TRUE otherwise 1387 */ 1388 int alpm_pkg_has_scriptlet(alpm_pkg_t *pkg); 1389 1390 /** Returns the size of download. 1391 * Returns the size of the files that will be downloaded to install a 1392 * package. 1393 * @param newpkg the new package to upgrade to 1394 * @return the size of the download 1395 */ 1396 off_t alpm_pkg_download_size(alpm_pkg_t *newpkg); 1397 1398 alpm_list_t *alpm_pkg_unused_deltas(alpm_pkg_t *pkg); 1399 1400 /** Set install reason for a package in the local database. 1401 * The provided package object must be from the local database or this method 1402 * will fail. The write to the local database is performed immediately. 1403 * @param pkg the package to update 1404 * @param reason the new install reason 1405 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1406 */ 1407 int alpm_pkg_set_reason(alpm_pkg_t *pkg, alpm_pkgreason_t reason); 1408 1409 1410 /* End of alpm_pkg */ 1411 /** @} */ 1412 1413 /* 1414 * Filelists 1415 */ 1416 1417 /** Determines whether a package filelist contains a given path. 1418 * The provided path should be relative to the install root with no leading 1419 * slashes, e.g. "etc/localtime". When searching for directories, the path must 1420 * have a trailing slash. 1421 * @param filelist a pointer to a package filelist 1422 * @param path the path to search for in the package 1423 * @return a pointer to the matching file or NULL if not found 1424 */ 1425 alpm_file_t *alpm_filelist_contains(alpm_filelist_t *filelist, const char *path); 1426 1427 /* 1428 * Signatures 1429 */ 1430 1431 int alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, alpm_siglist_t *siglist); 1432 1433 int alpm_db_check_pgp_signature(alpm_db_t *db, alpm_siglist_t *siglist); 1434 1435 int alpm_siglist_cleanup(alpm_siglist_t *siglist); 1436 1437 int alpm_decode_signature(const char *base64_data, 1438 unsigned char **data, size_t *data_len); 1439 1440 int alpm_extract_keyid(alpm_handle_t *handle, const char *identifier, 1441 const unsigned char *sig, const size_t len, alpm_list_t **keys); 1442 1443 /* 1444 * Groups 1445 */ 1446 1447 alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name); 1448 1449 /* 1450 * Sync 1451 */ 1452 1453 alpm_pkg_t *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync); 1454 1455 /** @addtogroup alpm_api_trans Transaction Functions 1456 * Functions to manipulate libalpm transactions 1457 * @{ 1458 */ 1459 1460 /** Transaction flags */ 1461 typedef enum _alpm_transflag_t { 1462 /** Ignore dependency checks. */ 1463 ALPM_TRANS_FLAG_NODEPS = 1, 1464 /** Ignore file conflicts and overwrite files. */ 1465 ALPM_TRANS_FLAG_FORCE = (1 << 1), 1466 /** Delete files even if they are tagged as backup. */ 1467 ALPM_TRANS_FLAG_NOSAVE = (1 << 2), 1468 /** Ignore version numbers when checking dependencies. */ 1469 ALPM_TRANS_FLAG_NODEPVERSION = (1 << 3), 1470 /** Remove also any packages depending on a package being removed. */ 1471 ALPM_TRANS_FLAG_CASCADE = (1 << 4), 1472 /** Remove packages and their unneeded deps (not explicitly installed). */ 1473 ALPM_TRANS_FLAG_RECURSE = (1 << 5), 1474 /** Modify database but do not commit changes to the filesystem. */ 1475 ALPM_TRANS_FLAG_DBONLY = (1 << 6), 1476 /* (1 << 7) flag can go here */ 1477 /** Use ALPM_PKG_REASON_DEPEND when installing packages. */ 1478 ALPM_TRANS_FLAG_ALLDEPS = (1 << 8), 1479 /** Only download packages and do not actually install. */ 1480 ALPM_TRANS_FLAG_DOWNLOADONLY = (1 << 9), 1481 /** Do not execute install scriptlets after installing. */ 1482 ALPM_TRANS_FLAG_NOSCRIPTLET = (1 << 10), 1483 /** Ignore dependency conflicts. */ 1484 ALPM_TRANS_FLAG_NOCONFLICTS = (1 << 11), 1485 /* (1 << 12) flag can go here */ 1486 /** Do not install a package if it is already installed and up to date. */ 1487 ALPM_TRANS_FLAG_NEEDED = (1 << 13), 1488 /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */ 1489 ALPM_TRANS_FLAG_ALLEXPLICIT = (1 << 14), 1490 /** Do not remove a package if it is needed by another one. */ 1491 ALPM_TRANS_FLAG_UNNEEDED = (1 << 15), 1492 /** Remove also explicitly installed unneeded deps (use with ALPM_TRANS_FLAG_RECURSE). */ 1493 ALPM_TRANS_FLAG_RECURSEALL = (1 << 16), 1494 /** Do not lock the database during the operation. */ 1495 ALPM_TRANS_FLAG_NOLOCK = (1 << 17) 1496 } alpm_transflag_t; 1497 1498 /** Returns the bitfield of flags for the current transaction. 1499 * @param handle the context handle 1500 * @return the bitfield of transaction flags 1501 */ 1502 int alpm_trans_get_flags(alpm_handle_t *handle); 1503 1504 /** Returns a list of packages added by the transaction. 1505 * @param handle the context handle 1506 * @return a list of alpm_pkg_t structures 1507 */ 1508 alpm_list_t *alpm_trans_get_add(alpm_handle_t *handle); 1509 1510 /** Returns the list of packages removed by the transaction. 1511 * @param handle the context handle 1512 * @return a list of alpm_pkg_t structures 1513 */ 1514 alpm_list_t *alpm_trans_get_remove(alpm_handle_t *handle); 1515 1516 /** Initialize the transaction. 1517 * @param handle the context handle 1518 * @param flags flags of the transaction (like nodeps, etc; see alpm_transflag_t) 1519 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1520 */ 1521 int alpm_trans_init(alpm_handle_t *handle, int flags); 1522 1523 /** Prepare a transaction. 1524 * @param handle the context handle 1525 * @param data the address of an alpm_list where a list 1526 * of alpm_depmissing_t objects is dumped (conflicting packages) 1527 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1528 */ 1529 int alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data); 1530 1531 /** Commit a transaction. 1532 * @param handle the context handle 1533 * @param data the address of an alpm_list where detailed description 1534 * of an error can be dumped (i.e. list of conflicting files) 1535 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1536 */ 1537 int alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data); 1538 1539 /** Interrupt a transaction. 1540 * @param handle the context handle 1541 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1542 */ 1543 int alpm_trans_interrupt(alpm_handle_t *handle); 1544 1545 /** Release a transaction. 1546 * @param handle the context handle 1547 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1548 */ 1549 int alpm_trans_release(alpm_handle_t *handle); 1550 /** @} */ 1551 1552 /** @name Common Transactions */ 1553 /** @{ */ 1554 1555 /** Search for packages to upgrade and add them to the transaction. 1556 * @param handle the context handle 1557 * @param enable_downgrade allow downgrading of packages if the remote version is lower 1558 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1559 */ 1560 int alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade); 1561 1562 /** Add a package to the transaction. 1563 * If the package was loaded by alpm_pkg_load(), it will be freed upon 1564 * alpm_trans_release() invocation. 1565 * @param handle the context handle 1566 * @param pkg the package to add 1567 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1568 */ 1569 int alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg); 1570 1571 /** Add a package removal action to the transaction. 1572 * @param handle the context handle 1573 * @param pkg the package to uninstall 1574 * @return 0 on success, -1 on error (pm_errno is set accordingly) 1575 */ 1576 int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg); 1577 1578 /** @} */ 1579 1580 /** @addtogroup alpm_api_depends Dependency Functions 1581 * Functions dealing with libalpm representation of dependency 1582 * information. 1583 * @{ 1584 */ 1585 1586 alpm_list_t *alpm_checkdeps(alpm_handle_t *handle, alpm_list_t *pkglist, 1587 alpm_list_t *remove, alpm_list_t *upgrade, int reversedeps); 1588 alpm_pkg_t *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring); 1589 alpm_pkg_t *alpm_find_dbs_satisfier(alpm_handle_t *handle, 1590 alpm_list_t *dbs, const char *depstring); 1591 1592 alpm_list_t *alpm_checkconflicts(alpm_handle_t *handle, alpm_list_t *pkglist); 1593 1594 /** Returns a newly allocated string representing the dependency information. 1595 * @param dep a dependency info structure 1596 * @return a formatted string, e.g. "glibc>=2.12" 1597 */ 1598 char *alpm_dep_compute_string(const alpm_depend_t *dep); 1599 1600 /** Return a newly allocated dependency information parsed from a string 1601 * @param depstring a formatted string, e.g. "glibc=2.12" 1602 * @return a dependency info structure 1603 */ 1604 alpm_depend_t *alpm_dep_from_string(const char *depstring); 1605 1606 /** Free a dependency info structure 1607 * @param dep struct to free 1608 */ 1609 void alpm_dep_free(alpm_depend_t *dep); 1610 1611 /** @} */ 1612 1613 /** @} */ 1614 1615 /* 1616 * Helpers 1617 */ 1618 1619 /* checksums */ 1620 char *alpm_compute_md5sum(const char *filename); 1621 char *alpm_compute_sha256sum(const char *filename); 1622 1623 alpm_handle_t *alpm_initialize(const char *root, const char *dbpath, 1624 alpm_errno_t *err); 1625 int alpm_release(alpm_handle_t *handle); 1626 int alpm_unlock(alpm_handle_t *handle); 1627 1628 enum alpm_caps { 1629 ALPM_CAPABILITY_NLS = (1 << 0), 1630 ALPM_CAPABILITY_DOWNLOADER = (1 << 1), 1631 ALPM_CAPABILITY_SIGNATURES = (1 << 2) 1632 }; 1633 1634 const char *alpm_version(void); 1635 /* Return a bitfield of capabilities using values from 'enum alpm_caps' */ 1636 int alpm_capabilities(void); 1637 1638 void alpm_fileconflict_free(alpm_fileconflict_t *conflict); 1639 void alpm_depmissing_free(alpm_depmissing_t *miss); 1640 void alpm_conflict_free(alpm_conflict_t *conflict); 1641 1642 /* End of alpm_api */ 1643 /** @} */ 1644 1645 #ifdef __cplusplus 1646 } 1647 #endif 1648 #endif /* ALPM_H */ 1649