alpm.h

Go to the documentation of this file.
00001 /*
00002  * alpm.h
00003  *
00004  *  Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
00005  *  Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
00006  *  Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
00007  *  Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021  */
00022 #ifndef _ALPM_H
00023 #define _ALPM_H
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #include <time.h> /* for time_t */
00030 #include <stdarg.h> /* for va_list */
00031 
00032 #include <alpm_list.h>
00033 
00034 #define DEPRECATED __attribute__((deprecated))
00035 
00036 /*
00037  * Arch Linux Package Management library
00038  */
00039 
00040 /*
00041  * Structures
00042  */
00043 
00044 typedef struct __pmdb_t pmdb_t;
00045 typedef struct __pmpkg_t pmpkg_t;
00046 typedef struct __pmdelta_t pmdelta_t;
00047 typedef struct __pmgrp_t pmgrp_t;
00048 typedef struct __pmserver_t pmserver_t;
00049 typedef struct __pmtrans_t pmtrans_t;
00050 typedef struct __pmsyncpkg_t pmsyncpkg_t;
00051 typedef struct __pmdepend_t pmdepend_t;
00052 typedef struct __pmdepmissing_t pmdepmissing_t;
00053 typedef struct __pmconflict_t pmconflict_t;
00054 typedef struct __pmfileconflict_t pmfileconflict_t;
00055 typedef struct __pmgraph_t pmgraph_t;
00056 
00057 /*
00058  * Library
00059  */
00060 
00061 int alpm_initialize(void);
00062 int alpm_release(void);
00063 
00064 /*
00065  * Logging facilities
00066  */
00067 
00068 /* Levels */
00069 typedef enum _pmloglevel_t {
00070     PM_LOG_ERROR    = 0x01,
00071     PM_LOG_WARNING  = 0x02,
00072     PM_LOG_DEBUG    = 0x04,
00073     PM_LOG_FUNCTION = 0x08
00074 } pmloglevel_t;
00075 
00076 typedef void (*alpm_cb_log)(pmloglevel_t, char *, va_list);
00077 int alpm_logaction(char *fmt, ...);
00078 
00079 /*
00080  * Downloading
00081  */
00082 
00083 typedef void (*alpm_cb_download)(const char *filename, int file_xfered,
00084         int file_total, int list_xfered, int list_total);
00085 
00086 /*
00087  * Options
00088  */
00089 
00090 #define PM_DLFNM_LEN 22
00091 
00092 alpm_cb_log alpm_option_get_logcb();
00093 void alpm_option_set_logcb(alpm_cb_log cb);
00094 
00095 alpm_cb_download alpm_option_get_dlcb();
00096 void alpm_option_set_dlcb(alpm_cb_download cb);
00097 
00098 const char *alpm_option_get_root();
00099 int alpm_option_set_root(const char *root);
00100 
00101 const char *alpm_option_get_dbpath();
00102 int alpm_option_set_dbpath(const char *dbpath);
00103 
00104 alpm_list_t *alpm_option_get_cachedirs();
00105 int alpm_option_add_cachedir(const char *cachedir);
00106 void alpm_option_set_cachedirs(alpm_list_t *cachedirs);
00107 int alpm_option_remove_cachedir(const char *cachedir);
00108 
00109 const char *alpm_option_get_logfile();
00110 int alpm_option_set_logfile(const char *logfile);
00111 
00112 const char *alpm_option_get_lockfile();
00113 /* no set_lockfile, path is determined from dbpath */
00114 
00115 unsigned short alpm_option_get_usesyslog();
00116 void alpm_option_set_usesyslog(unsigned short usesyslog);
00117 
00118 alpm_list_t *alpm_option_get_noupgrades();
00119 void alpm_option_add_noupgrade(const char *pkg);
00120 void alpm_option_set_noupgrades(alpm_list_t *noupgrade);
00121 int alpm_option_remove_noupgrade(const char *pkg);
00122 
00123 alpm_list_t *alpm_option_get_noextracts();
00124 void alpm_option_add_noextract(const char *pkg);
00125 void alpm_option_set_noextracts(alpm_list_t *noextract);
00126 int alpm_option_remove_noextract(const char *pkg);
00127 
00128 alpm_list_t *alpm_option_get_ignorepkgs();
00129 void alpm_option_add_ignorepkg(const char *pkg);
00130 void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
00131 int alpm_option_remove_ignorepkg(const char *pkg);
00132 
00133 alpm_list_t *alpm_option_get_holdpkgs();
00134 void alpm_option_add_holdpkg(const char *pkg);
00135 void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
00136 int alpm_option_remove_holdpkg(const char *pkg);
00137 
00138 alpm_list_t *alpm_option_get_ignoregrps();
00139 void alpm_option_add_ignoregrp(const char *grp);
00140 void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
00141 int alpm_option_remove_ignoregrp(const char *grp);
00142 
00143 const char *alpm_option_get_xfercommand();
00144 void alpm_option_set_xfercommand(const char *cmd);
00145 
00146 unsigned short alpm_option_get_nopassiveftp();
00147 void alpm_option_set_nopassiveftp(unsigned short nopasv);
00148 void alpm_option_set_usedelta(unsigned short usedelta);
00149 
00150 pmdb_t *alpm_option_get_localdb();
00151 alpm_list_t *alpm_option_get_syncdbs();
00152 
00153 /*
00154  * Databases
00155  */
00156 
00157 /* Preferred interfaces db_register_local and db_register_sync */
00158 pmdb_t *alpm_db_register_local(void);
00159 pmdb_t *alpm_db_register_sync(const char *treename);
00160 int alpm_db_unregister(pmdb_t *db);
00161 int alpm_db_unregister_all(void);
00162 
00163 const char *alpm_db_get_name(const pmdb_t *db);
00164 const char *alpm_db_get_url(const pmdb_t *db);
00165 
00166 int alpm_db_setserver(pmdb_t *db, const char *url);
00167 
00168 int alpm_db_update(int level, pmdb_t *db);
00169 
00170 pmpkg_t *alpm_db_get_pkg(pmdb_t *db, const char *name);
00171 alpm_list_t *alpm_db_getpkgcache(pmdb_t *db);
00172 alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
00173 
00174 pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
00175 alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
00176 alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles);
00177 
00178 /*
00179  * Packages
00180  */
00181 
00182 /* Info parameters */
00183 
00184 /* reasons -- ie, why the package was installed */
00185 typedef enum _pmpkgreason_t {
00186     PM_PKG_REASON_EXPLICIT = 0,  /* explicitly requested by the user */
00187     PM_PKG_REASON_DEPEND = 1  /* installed as a dependency for another package */
00188 } pmpkgreason_t;
00189 
00190 int alpm_pkg_load(const char *filename, unsigned short full, pmpkg_t **pkg);
00191 int alpm_pkg_free(pmpkg_t *pkg);
00192 int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
00193 char *alpm_fetch_pkgurl(const char *url);
00194 int alpm_pkg_vercmp(const char *ver1, const char *ver2);
00195 alpm_list_t *alpm_pkg_compute_requiredby(pmpkg_t *pkg);
00196 
00197 const char *alpm_pkg_get_filename(pmpkg_t *pkg);
00198 const char *alpm_pkg_get_name(pmpkg_t *pkg);
00199 const char *alpm_pkg_get_version(pmpkg_t *pkg);
00200 const char *alpm_pkg_get_desc(pmpkg_t *pkg);
00201 const char *alpm_pkg_get_url(pmpkg_t *pkg);
00202 time_t alpm_pkg_get_builddate(pmpkg_t *pkg);
00203 time_t alpm_pkg_get_installdate(pmpkg_t *pkg);
00204 const char *alpm_pkg_get_packager(pmpkg_t *pkg);
00205 const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
00206 const char *alpm_pkg_get_arch(pmpkg_t *pkg);
00207 unsigned long alpm_pkg_get_size(pmpkg_t *pkg);
00208 unsigned long alpm_pkg_get_isize(pmpkg_t *pkg);
00209 pmpkgreason_t alpm_pkg_get_reason(pmpkg_t *pkg);
00210 alpm_list_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
00211 alpm_list_t *alpm_pkg_get_groups(pmpkg_t *pkg);
00212 alpm_list_t *alpm_pkg_get_depends(pmpkg_t *pkg);
00213 alpm_list_t *alpm_pkg_get_optdepends(pmpkg_t *pkg);
00214 alpm_list_t *alpm_pkg_get_conflicts(pmpkg_t *pkg);
00215 alpm_list_t *alpm_pkg_get_provides(pmpkg_t *pkg);
00216 alpm_list_t *alpm_pkg_get_deltas(pmpkg_t *pkg);
00217 alpm_list_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
00218 alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
00219 alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
00220 void *alpm_pkg_changelog_open(pmpkg_t *pkg);
00221 size_t alpm_pkg_changelog_read(void *ptr, size_t size,
00222         const pmpkg_t *pkg, const void *fp);
00223 /*int alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp);*/
00224 int alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp);
00225 unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
00226 
00227 unsigned long alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local);
00228 
00229 /*
00230  * Deltas
00231  */
00232 
00233 const char *alpm_delta_get_from(pmdelta_t *delta);
00234 const char *alpm_delta_get_to(pmdelta_t *delta);
00235 unsigned long alpm_delta_get_size(pmdelta_t *delta);
00236 const char *alpm_delta_get_filename(pmdelta_t *delta);
00237 const char *alpm_delta_get_md5sum(pmdelta_t *delta);
00238 
00239 /*
00240  * Groups
00241  */
00242 const char *alpm_grp_get_name(const pmgrp_t *grp);
00243 const alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
00244 
00245 /*
00246  * Sync
00247  */
00248 
00249 /* Types */
00250 typedef enum _pmsynctype_t {
00251     PM_SYNC_TYPE_REPLACE = 1,
00252     PM_SYNC_TYPE_UPGRADE,
00253     PM_SYNC_TYPE_DEPEND
00254 } pmsynctype_t;
00255 
00256 pmsynctype_t alpm_sync_get_type(const pmsyncpkg_t *sync);
00257 pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync);
00258 void *alpm_sync_get_data(const pmsyncpkg_t *sync);
00259 int alpm_sync_sysupgrade(pmdb_t *db_local,
00260         alpm_list_t *dbs_sync, alpm_list_t **syncpkgs);
00261 
00262 /*
00263  * Transactions
00264  */
00265 
00266 /* Types */
00267 typedef enum _pmtranstype_t {
00268     PM_TRANS_TYPE_ADD = 1,
00269     PM_TRANS_TYPE_REMOVE,
00270     PM_TRANS_TYPE_REMOVEUPGRADE,
00271     PM_TRANS_TYPE_UPGRADE,
00272     PM_TRANS_TYPE_SYNC
00273 } pmtranstype_t;
00274 
00275 /* Flags */
00276 typedef enum _pmtransflag_t {
00277     PM_TRANS_FLAG_NODEPS = 0x01,
00278     PM_TRANS_FLAG_FORCE = 0x02,
00279     PM_TRANS_FLAG_NOSAVE = 0x04,
00280     /* 0x08 flag can go here */
00281     PM_TRANS_FLAG_CASCADE = 0x10,
00282     PM_TRANS_FLAG_RECURSE = 0x20,
00283     PM_TRANS_FLAG_DBONLY = 0x40,
00284     PM_TRANS_FLAG_DEPENDSONLY = 0x80,
00285     PM_TRANS_FLAG_ALLDEPS = 0x100,
00286     PM_TRANS_FLAG_DOWNLOADONLY = 0x200,
00287     PM_TRANS_FLAG_NOSCRIPTLET = 0x400,
00288     PM_TRANS_FLAG_NOCONFLICTS = 0x800,
00289     PM_TRANS_FLAG_PRINTURIS = 0x1000,
00290     PM_TRANS_FLAG_NEEDED = 0x2000
00291 } pmtransflag_t;
00292 
00293 /* Transaction Events */
00294 typedef enum _pmtransevt_t {
00295     PM_TRANS_EVT_CHECKDEPS_START = 1,
00296     PM_TRANS_EVT_CHECKDEPS_DONE,
00297     PM_TRANS_EVT_FILECONFLICTS_START,
00298     PM_TRANS_EVT_FILECONFLICTS_DONE,
00299     PM_TRANS_EVT_RESOLVEDEPS_START,
00300     PM_TRANS_EVT_RESOLVEDEPS_DONE,
00301     PM_TRANS_EVT_INTERCONFLICTS_START,
00302     PM_TRANS_EVT_INTERCONFLICTS_DONE,
00303     PM_TRANS_EVT_ADD_START,
00304     PM_TRANS_EVT_ADD_DONE,
00305     PM_TRANS_EVT_REMOVE_START,
00306     PM_TRANS_EVT_REMOVE_DONE,
00307     PM_TRANS_EVT_UPGRADE_START,
00308     PM_TRANS_EVT_UPGRADE_DONE,
00309     PM_TRANS_EVT_EXTRACT_DONE,
00310     PM_TRANS_EVT_INTEGRITY_START,
00311     PM_TRANS_EVT_INTEGRITY_DONE,
00312     PM_TRANS_EVT_DELTA_INTEGRITY_START,
00313     PM_TRANS_EVT_DELTA_INTEGRITY_DONE,
00314     PM_TRANS_EVT_DELTA_PATCHES_START,
00315     PM_TRANS_EVT_DELTA_PATCHES_DONE,
00316     PM_TRANS_EVT_DELTA_PATCH_START,
00317     PM_TRANS_EVT_DELTA_PATCH_DONE,
00318     PM_TRANS_EVT_DELTA_PATCH_FAILED,
00319     PM_TRANS_EVT_SCRIPTLET_INFO,
00320     PM_TRANS_EVT_PRINTURI,
00321     PM_TRANS_EVT_RETRIEVE_START,
00322 } pmtransevt_t;
00323 
00324 /* Transaction Conversations (ie, questions) */
00325 typedef enum _pmtransconv_t {
00326     PM_TRANS_CONV_INSTALL_IGNOREPKG = 0x01,
00327     PM_TRANS_CONV_REPLACE_PKG = 0x02,
00328     PM_TRANS_CONV_CONFLICT_PKG = 0x04,
00329     PM_TRANS_CONV_CORRUPTED_PKG = 0x08,
00330     PM_TRANS_CONV_LOCAL_NEWER = 0x10,
00331     /* 0x20 flag can go here */
00332     PM_TRANS_CONV_REMOVE_HOLDPKG = 0x40
00333 } pmtransconv_t;
00334 
00335 /* Transaction Progress */
00336 typedef enum _pmtransprog_t {
00337     PM_TRANS_PROGRESS_ADD_START,
00338     PM_TRANS_PROGRESS_UPGRADE_START,
00339     PM_TRANS_PROGRESS_REMOVE_START,
00340     PM_TRANS_PROGRESS_CONFLICTS_START
00341 } pmtransprog_t;
00342 
00343 /* Transaction Event callback */
00344 typedef void (*alpm_trans_cb_event)(pmtransevt_t, void *, void *);
00345 
00346 /* Transaction Conversation callback */
00347 typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
00348                                    void *, int *);
00349 
00350 /* Transaction Progress callback */
00351 typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
00352 
00353 pmtranstype_t alpm_trans_get_type();
00354 unsigned int alpm_trans_get_flags();
00355 alpm_list_t * alpm_trans_get_targets();
00356 alpm_list_t * alpm_trans_get_pkgs();
00357 int alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
00358                     alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
00359                     alpm_trans_cb_progress cb_progress);
00360 int alpm_trans_sysupgrade(void);
00361 int alpm_trans_addtarget(char *target);
00362 int alpm_trans_prepare(alpm_list_t **data);
00363 int alpm_trans_commit(alpm_list_t **data);
00364 int alpm_trans_interrupt(void);
00365 int alpm_trans_release(void);
00366 
00367 /*
00368  * Dependencies and conflicts
00369  */
00370 
00371 typedef enum _pmdepmod_t {
00372     PM_DEP_MOD_ANY = 1,
00373     PM_DEP_MOD_EQ,
00374     PM_DEP_MOD_GE,
00375     PM_DEP_MOD_LE,
00376     PM_DEP_MOD_GT,
00377     PM_DEP_MOD_LT
00378 } pmdepmod_t;
00379 
00380 pmdepend_t *alpm_splitdep(const char *depstring);
00381 int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
00382 alpm_list_t *alpm_checkdeps(pmdb_t *db, int reversedeps,
00383         alpm_list_t *remove, alpm_list_t *upgrade);
00384 
00385 const char *alpm_miss_get_target(const pmdepmissing_t *miss);
00386 pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
00387 
00388 const char *alpm_conflict_get_package1(pmconflict_t *conflict);
00389 const char *alpm_conflict_get_package2(pmconflict_t *conflict);
00390 
00391 pmdepmod_t alpm_dep_get_mod(const pmdepend_t *dep);
00392 const char *alpm_dep_get_name(const pmdepend_t *dep);
00393 const char *alpm_dep_get_version(const pmdepend_t *dep);
00394 char *alpm_dep_get_string(const pmdepend_t *dep);
00395 
00396 /*
00397  * File conflicts
00398  */
00399 
00400 typedef enum _pmfileconflicttype_t {
00401     PM_FILECONFLICT_TARGET = 1,
00402     PM_FILECONFLICT_FILESYSTEM
00403 } pmfileconflicttype_t;
00404 
00405 const char *alpm_fileconflict_get_target(pmfileconflict_t *conflict);
00406 pmfileconflicttype_t alpm_fileconflict_get_type(pmfileconflict_t *conflict);
00407 const char *alpm_fileconflict_get_file(pmfileconflict_t *conflict);
00408 const char *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict);
00409 
00410 /*
00411  * Helpers
00412  */
00413 
00414 /* checksums */
00415 char *alpm_get_md5sum(const char *name);
00416 
00417 /*
00418  * Errors
00419  */
00420 enum _pmerrno_t {
00421     PM_ERR_MEMORY = 1,
00422     PM_ERR_SYSTEM,
00423     PM_ERR_BADPERMS,
00424     PM_ERR_NOT_A_FILE,
00425     PM_ERR_NOT_A_DIR,
00426     PM_ERR_WRONG_ARGS,
00427     /* Interface */
00428     PM_ERR_HANDLE_NULL,
00429     PM_ERR_HANDLE_NOT_NULL,
00430     PM_ERR_HANDLE_LOCK,
00431     /* Databases */
00432     PM_ERR_DB_OPEN,
00433     PM_ERR_DB_CREATE,
00434     PM_ERR_DB_NULL,
00435     PM_ERR_DB_NOT_NULL,
00436     PM_ERR_DB_NOT_FOUND,
00437     PM_ERR_DB_WRITE,
00438     PM_ERR_DB_REMOVE,
00439     /* Servers */
00440     PM_ERR_SERVER_BAD_URL,
00441     /* Configuration */
00442     PM_ERR_OPT_LOGFILE,
00443     PM_ERR_OPT_DBPATH,
00444     PM_ERR_OPT_LOCALDB,
00445     PM_ERR_OPT_SYNCDB,
00446     PM_ERR_OPT_USESYSLOG,
00447     /* Transactions */
00448     PM_ERR_TRANS_NOT_NULL,
00449     PM_ERR_TRANS_NULL,
00450     PM_ERR_TRANS_DUP_TARGET,
00451     PM_ERR_TRANS_NOT_INITIALIZED,
00452     PM_ERR_TRANS_NOT_PREPARED,
00453     PM_ERR_TRANS_ABORT,
00454     PM_ERR_TRANS_TYPE,
00455     PM_ERR_TRANS_COMMITING,
00456     PM_ERR_TRANS_DOWNLOADING,
00457     /* Packages */
00458     PM_ERR_PKG_NOT_FOUND,
00459     PM_ERR_PKG_INVALID,
00460     PM_ERR_PKG_OPEN,
00461     PM_ERR_PKG_LOAD,
00462     PM_ERR_PKG_INSTALLED,
00463     PM_ERR_PKG_CANT_FRESH,
00464     PM_ERR_PKG_CANT_REMOVE,
00465     PM_ERR_PKG_INVALID_NAME,
00466     PM_ERR_PKG_CORRUPTED,
00467     PM_ERR_PKG_REPO_NOT_FOUND,
00468     /* Deltas */
00469     PM_ERR_DLT_CORRUPTED,
00470     PM_ERR_DLT_PATCHFAILED,
00471     /* Groups */
00472     PM_ERR_GRP_NOT_FOUND,
00473     /* Dependencies */
00474     PM_ERR_UNSATISFIED_DEPS,
00475     PM_ERR_CONFLICTING_DEPS,
00476     PM_ERR_FILE_CONFLICTS,
00477     /* Misc */
00478     PM_ERR_USER_ABORT,
00479     PM_ERR_INTERNAL_ERROR,
00480     PM_ERR_LIBARCHIVE_ERROR,
00481     PM_ERR_DB_SYNC,
00482     PM_ERR_RETRIEVE,
00483     PM_ERR_PKG_HOLD,
00484     PM_ERR_INVALID_REGEX,
00485   /* Downloading */
00486     PM_ERR_CONNECT_FAILED,
00487   PM_ERR_FORK_FAILED
00488 };
00489 
00490 extern enum _pmerrno_t pm_errno;
00491 
00492 const char *alpm_strerror(int err);
00493 const char *alpm_strerrorlast(void);
00494 
00495 #ifdef __cplusplus
00496 }
00497 #endif
00498 #endif /* _ALPM_H */
00499 
00500 /* vim: set ts=2 sw=2 noet: */

Generated on Mon Jan 14 23:53:39 2008 for libalpm by  doxygen 1.5.4