A few final changes for the 3.0.6 release
[pacman.git] / lib / libalpm / alpm.h
blobfc4aed5985d8a650560c205f976dee7698af2992
1 /*
2 * alpm.h
3 *
4 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
5 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
6 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
7 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 * USA.
24 #ifndef _ALPM_H
25 #define _ALPM_H
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 #include <time.h> /* for time_t */
34 * Arch Linux Package Management library
37 #define PM_ROOT "/"
38 #define PM_DBPATH "var/lib/pacman/"
39 #define PM_CACHEDIR "var/cache/pacman/pkg/"
40 #define PM_LOCK "tmp/pacman.lck"
43 #define PM_EXT_PKG ".pkg.tar.gz"
44 #define PM_EXT_DB ".db.tar.gz"
46 /*
47 * Structures
50 typedef struct __alpm_list_t alpm_list_t;
52 typedef struct __pmdb_t pmdb_t;
53 typedef struct __pmpkg_t pmpkg_t;
54 typedef struct __pmgrp_t pmgrp_t;
55 typedef struct __pmserver_t pmserver_t;
56 typedef struct __pmtrans_t pmtrans_t;
57 typedef struct __pmsyncpkg_t pmsyncpkg_t;
58 typedef struct __pmdepend_t pmdepend_t;
59 typedef struct __pmdepmissing_t pmdepmissing_t;
60 typedef struct __pmconflict_t pmconflict_t;
63 * Library
66 int alpm_initialize();
67 int alpm_release(void);
70 * Logging facilities
73 /* Levels */
74 typedef enum _pmloglevel_t {
75 PM_LOG_ERROR = 0x01,
76 PM_LOG_WARNING = 0x02,
77 PM_LOG_DEBUG = 0x04,
78 PM_LOG_DOWNLOAD = 0x08,
79 PM_LOG_FUNCTION = 0x10
80 } pmloglevel_t;
82 typedef void (*alpm_cb_log)(unsigned short, char *);
83 int alpm_logaction(char *fmt, ...);
86 * Downloading
89 typedef void (*alpm_cb_download)(const char *filename, int xfered, int total);
92 * Options
95 #define PM_DLFNM_LEN 22
97 alpm_cb_log alpm_option_get_logcb();
98 void alpm_option_set_logcb(alpm_cb_log cb);
100 alpm_cb_download alpm_option_get_dlcb();
101 void alpm_option_set_dlcb(alpm_cb_download cb);
103 unsigned short alpm_option_get_logmask();
104 void alpm_option_set_logmask(unsigned short mask);
106 const char *alpm_option_get_root();
107 void alpm_option_set_root(const char *root);
109 const char *alpm_option_get_dbpath();
110 void alpm_option_set_dbpath(const char *dbpath);
112 const char *alpm_option_get_cachedir();
113 void alpm_option_set_cachedir(const char *cachedir);
115 const char *alpm_option_get_logfile();
116 void alpm_option_set_logfile(const char *logfile);
118 unsigned short alpm_option_get_usesyslog();
119 void alpm_option_set_usesyslog(unsigned short usesyslog);
121 alpm_list_t *alpm_option_get_noupgrades();
122 void alpm_option_add_noupgrade(char *pkg);
123 void alpm_option_set_noupgrades(alpm_list_t *noupgrade);
125 alpm_list_t *alpm_option_get_noextracts();
126 void alpm_option_add_noextract(char *pkg);
127 void alpm_option_set_noextracts(alpm_list_t *noextract);
129 alpm_list_t *alpm_option_get_ignorepkgs();
130 void alpm_option_add_ignorepkg(char *pkg);
131 void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
133 alpm_list_t *alpm_option_get_holdpkgs();
134 void alpm_option_add_holdpkg(char *pkg);
135 void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
137 time_t alpm_option_get_upgradedelay();
138 void alpm_option_set_upgradedelay(time_t delay);
140 const char *alpm_option_get_xfercommand();
141 void alpm_option_set_xfercommand(const char *cmd);
143 unsigned short alpm_option_get_nopassiveftp();
144 void alpm_option_set_nopassiveftp(unsigned short nopasv);
146 unsigned short alpm_option_get_chomp();
147 void alpm_option_set_chomp(unsigned short chomp);
149 alpm_list_t *alpm_option_get_needles();
150 void alpm_option_add_needle(char *needle);
151 void alpm_option_set_needles(alpm_list_t *needles);
153 unsigned short alpm_option_get_usecolor();
154 void alpm_option_set_usecolor(unsigned short usecolor);
156 pmdb_t *alpm_option_get_localdb();
157 alpm_list_t *alpm_option_get_syncdbs();
160 * Databases
163 /* Database registration callback */
164 typedef void (*alpm_cb_db_register)(const char *, pmdb_t *);
166 pmdb_t *alpm_db_register(char *treename);
167 int alpm_db_unregister(pmdb_t *db);
169 const char *alpm_db_get_name(pmdb_t *db);
170 const char *alpm_db_get_url(pmdb_t *db);
172 int alpm_db_setserver(pmdb_t *db, const char *url);
174 int alpm_db_update(int level, pmdb_t *db);
176 pmpkg_t *alpm_db_get_pkg(pmdb_t *db, const char *name);
177 alpm_list_t *alpm_db_getpkgcache(pmdb_t *db);
178 alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
180 pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
181 alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
182 alpm_list_t *alpm_db_search(pmdb_t *db, alpm_list_t* needles);
185 * Packages
188 /* Info parameters */
190 /* reasons -- ie, why the package was installed */
191 typedef enum _pmpkgreason_t {
192 PM_PKG_REASON_EXPLICIT = 0, /* explicitly requested by the user */
193 PM_PKG_REASON_DEPEND = 1 /* installed as a dependency for another package */
194 } pmpkgreason_t;
196 /* package name formats */
198 typedef enum _pmpkghasarch_t {
199 PM_PKG_WITHOUT_ARCH = 0, / pkgname-pkgver-pkgrel, used under PM_DBPATH /
200 PM_PKG_WITH_ARCH = 1 / pkgname-pkgver-pkgrel-arch, used under PM_CACHEDIR /
201 } pmpkghasarch_t;
204 int alpm_pkg_load(char *filename, pmpkg_t **pkg);
205 int alpm_pkg_free(pmpkg_t *pkg);
206 int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
207 int alpm_pkg_checksha1sum(pmpkg_t *pkg);
208 char *alpm_fetch_pkgurl(char *url);
209 int alpm_parse_config(char *file, alpm_cb_db_register callback,
210 const char *this_section);
211 int alpm_pkg_vercmp(const char *ver1, const char *ver2);
212 char *alpm_pkg_name_hasarch(char *pkgname);
214 const char *alpm_pkg_get_filename(pmpkg_t *pkg);
215 const char *alpm_pkg_get_name(pmpkg_t *pkg);
216 const char *alpm_pkg_get_version(pmpkg_t *pkg);
217 const char *alpm_pkg_get_desc(pmpkg_t *pkg);
218 const char *alpm_pkg_get_url(pmpkg_t *pkg);
219 const char *alpm_pkg_get_builddate(pmpkg_t *pkg);
220 const char *alpm_pkg_get_buildtype(pmpkg_t *pkg);
221 const char *alpm_pkg_get_installdate(pmpkg_t *pkg);
222 const char *alpm_pkg_get_packager(pmpkg_t *pkg);
223 const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
224 const char *alpm_pkg_get_sha1sum(pmpkg_t *pkg);
225 const char *alpm_pkg_get_arch(pmpkg_t *pkg);
226 unsigned long alpm_pkg_get_size(pmpkg_t *pkg);
227 unsigned long alpm_pkg_get_isize(pmpkg_t *pkg);
228 pmpkgreason_t alpm_pkg_get_reason(pmpkg_t *pkg);
229 alpm_list_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
230 alpm_list_t *alpm_pkg_get_groups(pmpkg_t *pkg);
231 alpm_list_t *alpm_pkg_get_depends(pmpkg_t *pkg);
232 alpm_list_t *alpm_pkg_get_removes(pmpkg_t *pkg);
233 alpm_list_t *alpm_pkg_get_requiredby(pmpkg_t *pkg);
234 alpm_list_t *alpm_pkg_get_conflicts(pmpkg_t *pkg);
235 alpm_list_t *alpm_pkg_get_provides(pmpkg_t *pkg);
236 alpm_list_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
237 alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
238 alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
239 unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
242 * Groups
244 const char *alpm_grp_get_name(pmgrp_t *grp);
245 alpm_list_t *alpm_grp_get_pkgs(pmgrp_t *grp);
248 * Sync
251 /* Types */
252 typedef enum _pmsynctype_t {
253 PM_SYNC_TYPE_REPLACE = 1,
254 PM_SYNC_TYPE_UPGRADE,
255 PM_SYNC_TYPE_DEPEND
256 } pmsynctype_t;
258 pmsynctype_t alpm_sync_get_type(pmsyncpkg_t *sync);
259 pmpkg_t *alpm_sync_get_pkg(pmsyncpkg_t *sync);
260 void *alpm_sync_get_data(pmsyncpkg_t *sync);
263 * Transactions
266 /* Types */
267 typedef enum _pmtranstype_t {
268 PM_TRANS_TYPE_ADD = 1,
269 PM_TRANS_TYPE_REMOVE,
270 PM_TRANS_TYPE_UPGRADE,
271 PM_TRANS_TYPE_SYNC
272 } pmtranstype_t;
274 /* Flags */
275 typedef enum _pmtransflag_t {
276 PM_TRANS_FLAG_NODEPS = 0x01,
277 PM_TRANS_FLAG_FORCE = 0x02,
278 PM_TRANS_FLAG_NOSAVE = 0x04,
279 PM_TRANS_FLAG_FRESHEN = 0x08,
280 PM_TRANS_FLAG_CASCADE = 0x10,
281 PM_TRANS_FLAG_RECURSE = 0x20,
282 PM_TRANS_FLAG_DBONLY = 0x40,
283 PM_TRANS_FLAG_DEPENDSONLY = 0x80,
284 PM_TRANS_FLAG_ALLDEPS = 0x100,
285 PM_TRANS_FLAG_DOWNLOADONLY = 0x200,
286 PM_TRANS_FLAG_NOSCRIPTLET = 0x400,
287 PM_TRANS_FLAG_NOCONFLICTS = 0x800,
288 PM_TRANS_FLAG_PRINTURIS = 0x1000
289 } pmtransflag_t;
291 /* Transaction Events */
292 typedef enum _pmtransevt_t {
293 PM_TRANS_EVT_CHECKDEPS_START = 1,
294 PM_TRANS_EVT_CHECKDEPS_DONE,
295 PM_TRANS_EVT_FILECONFLICTS_START,
296 PM_TRANS_EVT_FILECONFLICTS_DONE,
297 PM_TRANS_EVT_CLEANUP_START,
298 PM_TRANS_EVT_CLEANUP_DONE,
299 PM_TRANS_EVT_RESOLVEDEPS_START,
300 PM_TRANS_EVT_RESOLVEDEPS_DONE,
301 PM_TRANS_EVT_INTERCONFLICTS_START,
302 PM_TRANS_EVT_INTERCONFLICTS_DONE,
303 PM_TRANS_EVT_ADD_START,
304 PM_TRANS_EVT_ADD_DONE,
305 PM_TRANS_EVT_REMOVE_START,
306 PM_TRANS_EVT_REMOVE_DONE,
307 PM_TRANS_EVT_UPGRADE_START,
308 PM_TRANS_EVT_UPGRADE_DONE,
309 PM_TRANS_EVT_EXTRACT_DONE,
310 PM_TRANS_EVT_INTEGRITY_START,
311 PM_TRANS_EVT_INTEGRITY_DONE,
312 PM_TRANS_EVT_SCRIPTLET_INFO,
313 PM_TRANS_EVT_SCRIPTLET_START,
314 PM_TRANS_EVT_SCRIPTLET_DONE,
315 PM_TRANS_EVT_PRINTURI,
316 PM_TRANS_EVT_RETRIEVE_START,
317 } pmtransevt_t;
319 /* Transaction Conversations (ie, questions) */
320 typedef enum _pmtransconv_t {
321 PM_TRANS_CONV_INSTALL_IGNOREPKG = 0x01,
322 PM_TRANS_CONV_REPLACE_PKG = 0x02,
323 PM_TRANS_CONV_CONFLICT_PKG = 0x04,
324 PM_TRANS_CONV_CORRUPTED_PKG = 0x08,
325 PM_TRANS_CONV_LOCAL_NEWER = 0x10,
326 PM_TRANS_CONV_LOCAL_UPTODATE = 0x20,
327 PM_TRANS_CONV_REMOVE_HOLDPKG = 0x40
328 } pmtransconv_t;
330 /* Transaction Progress */
331 typedef enum _pmtransprog_t {
332 PM_TRANS_PROGRESS_ADD_START,
333 PM_TRANS_PROGRESS_UPGRADE_START,
334 PM_TRANS_PROGRESS_REMOVE_START,
335 PM_TRANS_PROGRESS_CONFLICTS_START
336 } pmtransprog_t;
338 /* Transaction Event callback */
339 typedef void (*alpm_trans_cb_event)(pmtransevt_t, void *, void *);
341 /* Transaction Conversation callback */
342 typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
343 void *, int *);
345 /* Transaction Progress callback */
346 typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
348 pmtranstype_t alpm_trans_get_type();
349 unsigned int alpm_trans_get_flags();
350 alpm_list_t * alpm_trans_get_targets();
351 alpm_list_t * alpm_trans_get_pkgs();
352 int alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
353 alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
354 alpm_trans_cb_progress cb_progress);
355 int alpm_trans_sysupgrade(void);
356 int alpm_trans_addtarget(char *target);
357 int alpm_trans_prepare(alpm_list_t **data);
358 int alpm_trans_commit(alpm_list_t **data);
359 int alpm_trans_release(void);
362 * Dependencies and conflicts
365 typedef enum _pmdepmod_t {
366 PM_DEP_MOD_ANY = 1,
367 PM_DEP_MOD_EQ,
368 PM_DEP_MOD_GE,
369 PM_DEP_MOD_LE
370 } pmdepmod_t;
372 typedef enum _pmdeptype_t {
373 PM_DEP_TYPE_DEPEND = 1,
374 PM_DEP_TYPE_CONFLICT
375 } pmdeptype_t;
377 pmdepend_t *alpm_splitdep(const char *depstring);
378 int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
380 const char *alpm_dep_get_target(pmdepmissing_t *miss);
381 pmdeptype_t alpm_dep_get_type(pmdepmissing_t *miss);
382 pmdepmod_t alpm_dep_get_mod(pmdepmissing_t *miss);
383 const char *alpm_dep_get_name(pmdepmissing_t *miss);
384 const char *alpm_dep_get_version(pmdepmissing_t *miss);
387 * File conflicts
390 typedef enum _pmconflicttype_t {
391 PM_CONFLICT_TYPE_TARGET = 1,
392 PM_CONFLICT_TYPE_FILE
393 } pmconflicttype_t;
395 const char *alpm_conflict_get_target(pmconflict_t *conflict);
396 pmconflicttype_t alpm_conflict_get_type(pmconflict_t *conflict);
397 const char *alpm_conflict_get_file(pmconflict_t *conflict);
398 const char *alpm_conflict_get_ctarget(pmconflict_t *conflict);
401 * Helpers
404 /* md5sums */
405 char *alpm_get_md5sum(char *name);
406 char *alpm_get_sha1sum(char *name);
409 * Errors
411 enum _pmerrno_t {
412 PM_ERR_MEMORY = 1,
413 PM_ERR_SYSTEM,
414 PM_ERR_BADPERMS,
415 PM_ERR_NOT_A_FILE,
416 PM_ERR_WRONG_ARGS,
417 /* Interface */
418 PM_ERR_HANDLE_NULL,
419 PM_ERR_HANDLE_NOT_NULL,
420 PM_ERR_HANDLE_LOCK,
421 /* Databases */
422 PM_ERR_DB_OPEN,
423 PM_ERR_DB_CREATE,
424 PM_ERR_DB_NULL,
425 PM_ERR_DB_NOT_NULL,
426 PM_ERR_DB_NOT_FOUND,
427 PM_ERR_DB_WRITE,
428 PM_ERR_DB_REMOVE,
429 /* Servers */
430 PM_ERR_SERVER_BAD_URL,
431 /* Configuration */
432 PM_ERR_OPT_LOGFILE,
433 PM_ERR_OPT_DBPATH,
434 PM_ERR_OPT_LOCALDB,
435 PM_ERR_OPT_SYNCDB,
436 PM_ERR_OPT_USESYSLOG,
437 /* Transactions */
438 PM_ERR_TRANS_NOT_NULL,
439 PM_ERR_TRANS_NULL,
440 PM_ERR_TRANS_DUP_TARGET,
441 PM_ERR_TRANS_NOT_INITIALIZED,
442 PM_ERR_TRANS_NOT_PREPARED,
443 PM_ERR_TRANS_ABORT,
444 PM_ERR_TRANS_TYPE,
445 PM_ERR_TRANS_COMMITING,
446 PM_ERR_TRANS_DOWNLOADING,
447 /* Packages */
448 PM_ERR_PKG_NOT_FOUND,
449 PM_ERR_PKG_INVALID,
450 PM_ERR_PKG_OPEN,
451 PM_ERR_PKG_LOAD,
452 PM_ERR_PKG_INSTALLED,
453 PM_ERR_PKG_CANT_FRESH,
454 PM_ERR_PKG_CANT_REMOVE,
455 PM_ERR_PKG_INVALID_NAME,
456 PM_ERR_PKG_CORRUPTED,
457 PM_ERR_PKG_REPO_NOT_FOUND,
458 /* Groups */
459 PM_ERR_GRP_NOT_FOUND,
460 /* Dependencies */
461 PM_ERR_UNSATISFIED_DEPS,
462 PM_ERR_CONFLICTING_DEPS,
463 PM_ERR_FILE_CONFLICTS,
464 /* Misc */
465 PM_ERR_USER_ABORT,
466 PM_ERR_INTERNAL_ERROR,
467 PM_ERR_LIBARCHIVE_ERROR,
468 PM_ERR_DISK_FULL,
469 PM_ERR_DB_SYNC,
470 PM_ERR_RETRIEVE,
471 PM_ERR_PKG_HOLD,
472 /* Configuration file */
473 PM_ERR_CONF_BAD_SECTION,
474 PM_ERR_CONF_LOCAL,
475 PM_ERR_CONF_BAD_SYNTAX,
476 PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION,
477 PM_ERR_INVALID_REGEX,
478 /* Downloading */
479 PM_ERR_CONNECT_FAILED,
480 PM_ERR_FORK_FAILED
483 extern enum _pmerrno_t pm_errno;
485 char *alpm_strerror(int err);
487 alpm_list_t *alpm_get_upgrades();
489 #ifdef __cplusplus
491 #endif
492 #endif /* _ALPM_H */
494 /* vim: set ts=2 sw=2 noet: */