pmsyncpkg_t cleanup
[pacman-ng.git] / lib / libalpm / alpm.h
blob027b1fee2578db87512a87a5f1daf494b4332d7e
1 /*
2 * alpm.h
4 * Copyright (c) 2002-2007 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>
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, see <http://www.gnu.org/licenses/>.
22 #ifndef _ALPM_H
23 #define _ALPM_H
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
29 #include <time.h> /* for time_t */
30 #include <stdarg.h> /* for va_list */
32 #include <alpm_list.h>
34 #define DEPRECATED __attribute__((deprecated))
37 * Arch Linux Package Management library
41 * Structures
44 typedef struct __pmdb_t pmdb_t;
45 typedef struct __pmpkg_t pmpkg_t;
46 typedef struct __pmdelta_t pmdelta_t;
47 typedef struct __pmgrp_t pmgrp_t;
48 typedef struct __pmserver_t pmserver_t;
49 typedef struct __pmtrans_t pmtrans_t;
50 typedef struct __pmsyncpkg_t pmsyncpkg_t;
51 typedef struct __pmdepend_t pmdepend_t;
52 typedef struct __pmdepmissing_t pmdepmissing_t;
53 typedef struct __pmconflict_t pmconflict_t;
54 typedef struct __pmfileconflict_t pmfileconflict_t;
55 typedef struct __pmgraph_t pmgraph_t;
58 * Library
61 int alpm_initialize(void);
62 int alpm_release(void);
65 * Logging facilities
68 /* Levels */
69 typedef enum _pmloglevel_t {
70 PM_LOG_ERROR = 0x01,
71 PM_LOG_WARNING = 0x02,
72 PM_LOG_DEBUG = 0x04,
73 PM_LOG_FUNCTION = 0x08
74 } pmloglevel_t;
76 typedef void (*alpm_cb_log)(pmloglevel_t, char *, va_list);
77 int alpm_logaction(char *fmt, ...);
80 * Downloading
83 typedef void (*alpm_cb_download)(const char *filename, int file_xfered,
84 int file_total, int list_xfered, int list_total);
87 * Options
90 #define PM_DLFNM_LEN 22
92 alpm_cb_log alpm_option_get_logcb();
93 void alpm_option_set_logcb(alpm_cb_log cb);
95 alpm_cb_download alpm_option_get_dlcb();
96 void alpm_option_set_dlcb(alpm_cb_download cb);
98 const char *alpm_option_get_root();
99 int alpm_option_set_root(const char *root);
101 const char *alpm_option_get_dbpath();
102 int alpm_option_set_dbpath(const char *dbpath);
104 alpm_list_t *alpm_option_get_cachedirs();
105 int alpm_option_add_cachedir(const char *cachedir);
106 void alpm_option_set_cachedirs(alpm_list_t *cachedirs);
107 int alpm_option_remove_cachedir(const char *cachedir);
109 const char *alpm_option_get_logfile();
110 int alpm_option_set_logfile(const char *logfile);
112 const char *alpm_option_get_lockfile();
113 /* no set_lockfile, path is determined from dbpath */
115 unsigned short alpm_option_get_usesyslog();
116 void alpm_option_set_usesyslog(unsigned short usesyslog);
118 alpm_list_t *alpm_option_get_noupgrades();
119 void alpm_option_add_noupgrade(const char *pkg);
120 void alpm_option_set_noupgrades(alpm_list_t *noupgrade);
121 int alpm_option_remove_noupgrade(const char *pkg);
123 alpm_list_t *alpm_option_get_noextracts();
124 void alpm_option_add_noextract(const char *pkg);
125 void alpm_option_set_noextracts(alpm_list_t *noextract);
126 int alpm_option_remove_noextract(const char *pkg);
128 alpm_list_t *alpm_option_get_ignorepkgs();
129 void alpm_option_add_ignorepkg(const char *pkg);
130 void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
131 int alpm_option_remove_ignorepkg(const char *pkg);
133 alpm_list_t *alpm_option_get_holdpkgs();
134 void alpm_option_add_holdpkg(const char *pkg);
135 void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
136 int alpm_option_remove_holdpkg(const char *pkg);
138 alpm_list_t *alpm_option_get_ignoregrps();
139 void alpm_option_add_ignoregrp(const char *grp);
140 void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
141 int alpm_option_remove_ignoregrp(const char *grp);
143 const char *alpm_option_get_xfercommand();
144 void alpm_option_set_xfercommand(const char *cmd);
146 unsigned short alpm_option_get_nopassiveftp();
147 void alpm_option_set_nopassiveftp(unsigned short nopasv);
148 void alpm_option_set_usedelta(unsigned short usedelta);
150 pmdb_t *alpm_option_get_localdb();
151 alpm_list_t *alpm_option_get_syncdbs();
154 * Databases
157 /* Preferred interfaces db_register_local and db_register_sync */
158 pmdb_t *alpm_db_register_local(void);
159 pmdb_t *alpm_db_register_sync(const char *treename);
160 int alpm_db_unregister(pmdb_t *db);
161 int alpm_db_unregister_all(void);
163 const char *alpm_db_get_name(const pmdb_t *db);
164 const char *alpm_db_get_url(const pmdb_t *db);
166 int alpm_db_setserver(pmdb_t *db, const char *url);
168 int alpm_db_update(int level, pmdb_t *db);
170 pmpkg_t *alpm_db_get_pkg(pmdb_t *db, const char *name);
171 alpm_list_t *alpm_db_getpkgcache(pmdb_t *db);
172 alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
174 pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
175 alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
176 alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles);
179 * Packages
182 /* Info parameters */
184 /* reasons -- ie, why the package was installed */
185 typedef enum _pmpkgreason_t {
186 PM_PKG_REASON_EXPLICIT = 0, /* explicitly requested by the user */
187 PM_PKG_REASON_DEPEND = 1 /* installed as a dependency for another package */
188 } pmpkgreason_t;
190 int alpm_pkg_load(const char *filename, unsigned short full, pmpkg_t **pkg);
191 int alpm_pkg_free(pmpkg_t *pkg);
192 int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
193 char *alpm_fetch_pkgurl(const char *url);
194 int alpm_pkg_vercmp(const char *ver1, const char *ver2);
195 alpm_list_t *alpm_pkg_compute_requiredby(pmpkg_t *pkg);
197 const char *alpm_pkg_get_filename(pmpkg_t *pkg);
198 const char *alpm_pkg_get_name(pmpkg_t *pkg);
199 const char *alpm_pkg_get_version(pmpkg_t *pkg);
200 const char *alpm_pkg_get_desc(pmpkg_t *pkg);
201 const char *alpm_pkg_get_url(pmpkg_t *pkg);
202 time_t alpm_pkg_get_builddate(pmpkg_t *pkg);
203 time_t alpm_pkg_get_installdate(pmpkg_t *pkg);
204 const char *alpm_pkg_get_packager(pmpkg_t *pkg);
205 const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
206 const char *alpm_pkg_get_arch(pmpkg_t *pkg);
207 unsigned long alpm_pkg_get_size(pmpkg_t *pkg);
208 unsigned long alpm_pkg_get_isize(pmpkg_t *pkg);
209 pmpkgreason_t alpm_pkg_get_reason(pmpkg_t *pkg);
210 alpm_list_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
211 alpm_list_t *alpm_pkg_get_groups(pmpkg_t *pkg);
212 alpm_list_t *alpm_pkg_get_depends(pmpkg_t *pkg);
213 alpm_list_t *alpm_pkg_get_optdepends(pmpkg_t *pkg);
214 alpm_list_t *alpm_pkg_get_conflicts(pmpkg_t *pkg);
215 alpm_list_t *alpm_pkg_get_provides(pmpkg_t *pkg);
216 alpm_list_t *alpm_pkg_get_deltas(pmpkg_t *pkg);
217 alpm_list_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
218 alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
219 alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
220 void *alpm_pkg_changelog_open(pmpkg_t *pkg);
221 size_t alpm_pkg_changelog_read(void *ptr, size_t size,
222 const pmpkg_t *pkg, const void *fp);
223 /*int alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp);*/
224 int alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp);
225 unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
227 unsigned long alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local);
230 * Deltas
233 const char *alpm_delta_get_from(pmdelta_t *delta);
234 const char *alpm_delta_get_to(pmdelta_t *delta);
235 unsigned long alpm_delta_get_size(pmdelta_t *delta);
236 const char *alpm_delta_get_filename(pmdelta_t *delta);
237 const char *alpm_delta_get_md5sum(pmdelta_t *delta);
240 * Groups
242 const char *alpm_grp_get_name(const pmgrp_t *grp);
243 const alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
246 * Sync
249 pmpkgreason_t alpm_sync_get_newreason(const pmsyncpkg_t *sync);
250 pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync);
251 alpm_list_t *alpm_sync_get_removes(const pmsyncpkg_t *sync);
252 int alpm_sync_sysupgrade(pmdb_t *db_local,
253 alpm_list_t *dbs_sync, alpm_list_t **syncpkgs);
256 * Transactions
259 /* Types */
260 typedef enum _pmtranstype_t {
261 PM_TRANS_TYPE_ADD = 1,
262 PM_TRANS_TYPE_REMOVE,
263 PM_TRANS_TYPE_REMOVEUPGRADE,
264 PM_TRANS_TYPE_UPGRADE,
265 PM_TRANS_TYPE_SYNC
266 } pmtranstype_t;
268 /* Flags */
269 typedef enum _pmtransflag_t {
270 PM_TRANS_FLAG_NODEPS = 0x01,
271 PM_TRANS_FLAG_FORCE = 0x02,
272 PM_TRANS_FLAG_NOSAVE = 0x04,
273 /* 0x08 flag can go here */
274 PM_TRANS_FLAG_CASCADE = 0x10,
275 PM_TRANS_FLAG_RECURSE = 0x20,
276 PM_TRANS_FLAG_DBONLY = 0x40,
277 PM_TRANS_FLAG_DEPENDSONLY = 0x80,
278 PM_TRANS_FLAG_ALLDEPS = 0x100,
279 PM_TRANS_FLAG_DOWNLOADONLY = 0x200,
280 PM_TRANS_FLAG_NOSCRIPTLET = 0x400,
281 PM_TRANS_FLAG_NOCONFLICTS = 0x800,
282 PM_TRANS_FLAG_PRINTURIS = 0x1000,
283 PM_TRANS_FLAG_NEEDED = 0x2000,
284 PM_TRANS_FLAG_ALLEXPLICIT = 0x4000
285 } pmtransflag_t;
287 /* Transaction Events */
288 typedef enum _pmtransevt_t {
289 PM_TRANS_EVT_CHECKDEPS_START = 1,
290 PM_TRANS_EVT_CHECKDEPS_DONE,
291 PM_TRANS_EVT_FILECONFLICTS_START,
292 PM_TRANS_EVT_FILECONFLICTS_DONE,
293 PM_TRANS_EVT_RESOLVEDEPS_START,
294 PM_TRANS_EVT_RESOLVEDEPS_DONE,
295 PM_TRANS_EVT_INTERCONFLICTS_START,
296 PM_TRANS_EVT_INTERCONFLICTS_DONE,
297 PM_TRANS_EVT_ADD_START,
298 PM_TRANS_EVT_ADD_DONE,
299 PM_TRANS_EVT_REMOVE_START,
300 PM_TRANS_EVT_REMOVE_DONE,
301 PM_TRANS_EVT_UPGRADE_START,
302 PM_TRANS_EVT_UPGRADE_DONE,
303 PM_TRANS_EVT_EXTRACT_DONE,
304 PM_TRANS_EVT_INTEGRITY_START,
305 PM_TRANS_EVT_INTEGRITY_DONE,
306 PM_TRANS_EVT_DELTA_INTEGRITY_START,
307 PM_TRANS_EVT_DELTA_INTEGRITY_DONE,
308 PM_TRANS_EVT_DELTA_PATCHES_START,
309 PM_TRANS_EVT_DELTA_PATCHES_DONE,
310 PM_TRANS_EVT_DELTA_PATCH_START,
311 PM_TRANS_EVT_DELTA_PATCH_DONE,
312 PM_TRANS_EVT_DELTA_PATCH_FAILED,
313 PM_TRANS_EVT_SCRIPTLET_INFO,
314 PM_TRANS_EVT_PRINTURI,
315 PM_TRANS_EVT_RETRIEVE_START,
316 } pmtransevt_t;
318 /* Transaction Conversations (ie, questions) */
319 typedef enum _pmtransconv_t {
320 PM_TRANS_CONV_INSTALL_IGNOREPKG = 0x01,
321 PM_TRANS_CONV_REPLACE_PKG = 0x02,
322 PM_TRANS_CONV_CONFLICT_PKG = 0x04,
323 PM_TRANS_CONV_CORRUPTED_PKG = 0x08,
324 PM_TRANS_CONV_LOCAL_NEWER = 0x10,
325 /* 0x20 flag can go here */
326 PM_TRANS_CONV_REMOVE_HOLDPKG = 0x40
327 } pmtransconv_t;
329 /* Transaction Progress */
330 typedef enum _pmtransprog_t {
331 PM_TRANS_PROGRESS_ADD_START,
332 PM_TRANS_PROGRESS_UPGRADE_START,
333 PM_TRANS_PROGRESS_REMOVE_START,
334 PM_TRANS_PROGRESS_CONFLICTS_START
335 } pmtransprog_t;
337 /* Transaction Event callback */
338 typedef void (*alpm_trans_cb_event)(pmtransevt_t, void *, void *);
340 /* Transaction Conversation callback */
341 typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
342 void *, int *);
344 /* Transaction Progress callback */
345 typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
347 pmtranstype_t alpm_trans_get_type();
348 unsigned int alpm_trans_get_flags();
349 alpm_list_t * alpm_trans_get_targets();
350 alpm_list_t * alpm_trans_get_pkgs();
351 int alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
352 alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
353 alpm_trans_cb_progress cb_progress);
354 int alpm_trans_sysupgrade(void);
355 int alpm_trans_addtarget(char *target);
356 int alpm_trans_prepare(alpm_list_t **data);
357 int alpm_trans_commit(alpm_list_t **data);
358 int alpm_trans_interrupt(void);
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 PM_DEP_MOD_GT,
371 PM_DEP_MOD_LT
372 } pmdepmod_t;
374 int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
375 alpm_list_t *alpm_checkdeps(pmdb_t *db, int reversedeps,
376 alpm_list_t *remove, alpm_list_t *upgrade);
377 alpm_list_t *alpm_deptest(pmdb_t *db, alpm_list_t *targets);
379 const char *alpm_miss_get_target(const pmdepmissing_t *miss);
380 pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
382 alpm_list_t *alpm_checkdbconflicts(pmdb_t *db_local);
384 const char *alpm_conflict_get_package1(pmconflict_t *conflict);
385 const char *alpm_conflict_get_package2(pmconflict_t *conflict);
387 pmdepmod_t alpm_dep_get_mod(const pmdepend_t *dep);
388 const char *alpm_dep_get_name(const pmdepend_t *dep);
389 const char *alpm_dep_get_version(const pmdepend_t *dep);
390 char *alpm_dep_get_string(const pmdepend_t *dep);
393 * File conflicts
396 typedef enum _pmfileconflicttype_t {
397 PM_FILECONFLICT_TARGET = 1,
398 PM_FILECONFLICT_FILESYSTEM
399 } pmfileconflicttype_t;
401 const char *alpm_fileconflict_get_target(pmfileconflict_t *conflict);
402 pmfileconflicttype_t alpm_fileconflict_get_type(pmfileconflict_t *conflict);
403 const char *alpm_fileconflict_get_file(pmfileconflict_t *conflict);
404 const char *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict);
407 * Helpers
410 /* checksums */
411 char *alpm_get_md5sum(const char *name);
414 * Errors
416 enum _pmerrno_t {
417 PM_ERR_MEMORY = 1,
418 PM_ERR_SYSTEM,
419 PM_ERR_BADPERMS,
420 PM_ERR_NOT_A_FILE,
421 PM_ERR_NOT_A_DIR,
422 PM_ERR_WRONG_ARGS,
423 /* Interface */
424 PM_ERR_HANDLE_NULL,
425 PM_ERR_HANDLE_NOT_NULL,
426 PM_ERR_HANDLE_LOCK,
427 /* Databases */
428 PM_ERR_DB_OPEN,
429 PM_ERR_DB_CREATE,
430 PM_ERR_DB_NULL,
431 PM_ERR_DB_NOT_NULL,
432 PM_ERR_DB_NOT_FOUND,
433 PM_ERR_DB_WRITE,
434 PM_ERR_DB_REMOVE,
435 /* Servers */
436 PM_ERR_SERVER_BAD_URL,
437 /* Configuration */
438 PM_ERR_OPT_LOGFILE,
439 PM_ERR_OPT_DBPATH,
440 PM_ERR_OPT_LOCALDB,
441 PM_ERR_OPT_SYNCDB,
442 PM_ERR_OPT_USESYSLOG,
443 /* Transactions */
444 PM_ERR_TRANS_NOT_NULL,
445 PM_ERR_TRANS_NULL,
446 PM_ERR_TRANS_DUP_TARGET,
447 PM_ERR_TRANS_NOT_INITIALIZED,
448 PM_ERR_TRANS_NOT_PREPARED,
449 PM_ERR_TRANS_ABORT,
450 PM_ERR_TRANS_TYPE,
451 PM_ERR_TRANS_COMMITING,
452 PM_ERR_TRANS_DOWNLOADING,
453 /* Packages */
454 PM_ERR_PKG_NOT_FOUND,
455 PM_ERR_PKG_INVALID,
456 PM_ERR_PKG_OPEN,
457 PM_ERR_PKG_LOAD,
458 PM_ERR_PKG_INSTALLED,
459 PM_ERR_PKG_CANT_FRESH,
460 PM_ERR_PKG_CANT_REMOVE,
461 PM_ERR_PKG_INVALID_NAME,
462 PM_ERR_PKG_CORRUPTED,
463 PM_ERR_PKG_REPO_NOT_FOUND,
464 /* Deltas */
465 PM_ERR_DLT_CORRUPTED,
466 PM_ERR_DLT_PATCHFAILED,
467 /* Groups */
468 PM_ERR_GRP_NOT_FOUND,
469 /* Dependencies */
470 PM_ERR_UNSATISFIED_DEPS,
471 PM_ERR_CONFLICTING_DEPS,
472 PM_ERR_FILE_CONFLICTS,
473 /* Misc */
474 PM_ERR_USER_ABORT,
475 PM_ERR_INTERNAL_ERROR,
476 PM_ERR_LIBARCHIVE_ERROR,
477 PM_ERR_DB_SYNC,
478 PM_ERR_RETRIEVE,
479 PM_ERR_PKG_HOLD,
480 PM_ERR_INVALID_REGEX,
481 /* Downloading */
482 PM_ERR_CONNECT_FAILED,
483 PM_ERR_FORK_FAILED
486 extern enum _pmerrno_t pm_errno;
488 const char *alpm_strerror(int err);
489 const char *alpm_strerrorlast(void);
491 #ifdef __cplusplus
493 #endif
494 #endif /* _ALPM_H */
496 /* vim: set ts=2 sw=2 noet: */