1 |
/* $MidnightBSD$ |
2 |
* |
3 |
* Copyright (c) 2013, 2014 Lucas Holt |
4 |
* Copyright (c) 2007-2009 Chris Reinhardt |
5 |
* All rights reserved. |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions |
9 |
* are met: |
10 |
* 1. Redistributions of source code must retain the above copyright |
11 |
* notice, this list of conditions and the following disclaimer. |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the distribution. |
15 |
* |
16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
17 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 |
* SUCH DAMAGE. |
27 |
* |
28 |
*/ |
29 |
|
30 |
#ifndef _MPORT_H_ |
31 |
#define _MPORT_H_ |
32 |
|
33 |
|
34 |
#include <sys/cdefs.h> |
35 |
#include <archive.h> |
36 |
#include <sqlite3.h> |
37 |
#include <sys/queue.h> |
38 |
#include <stdio.h> |
39 |
|
40 |
#include "mport_dispatch.h" |
41 |
|
42 |
typedef void (*mport_msg_cb)(const char *); |
43 |
typedef void (*mport_progress_init_cb)(const char *); |
44 |
typedef void (*mport_progress_step_cb)(int, int, const char *); |
45 |
typedef void (*mport_progress_free_cb)(void); |
46 |
typedef int (*mport_confirm_cb)(const char *, const char *, const char *, int); |
47 |
|
48 |
/* Mport Instance (an installed copy of the mport system) */ |
49 |
#define MPORT_INST_HAVE_INDEX 1 |
50 |
|
51 |
typedef struct { |
52 |
int flags; |
53 |
sqlite3 *db; |
54 |
char *root; |
55 |
mport_msg_cb msg_cb; |
56 |
mport_progress_init_cb progress_init_cb; |
57 |
mport_progress_step_cb progress_step_cb; |
58 |
mport_progress_free_cb progress_free_cb; |
59 |
mport_confirm_cb confirm_cb; |
60 |
} mportInstance; |
61 |
|
62 |
mportInstance * mport_instance_new(void); |
63 |
int mport_instance_init(mportInstance *, const char *); |
64 |
int mport_instance_free(mportInstance *); |
65 |
|
66 |
void mport_set_msg_cb(mportInstance *, mport_msg_cb); |
67 |
void mport_set_progress_init_cb(mportInstance *, mport_progress_init_cb); |
68 |
void mport_set_progress_step_cb(mportInstance *, mport_progress_step_cb); |
69 |
void mport_set_progress_free_cb(mportInstance *, mport_progress_free_cb); |
70 |
void mport_set_confirm_cb(mportInstance *, mport_confirm_cb); |
71 |
|
72 |
void mport_default_msg_cb(const char *); |
73 |
int mport_default_confirm_cb(const char *, const char *, const char *, int); |
74 |
void mport_default_progress_init_cb(const char *); |
75 |
void mport_default_progress_step_cb(int, int, const char *); |
76 |
void mport_default_progress_free_cb(void); |
77 |
|
78 |
enum _AssetListEntryType { |
79 |
ASSET_INVALID, ASSET_FILE, ASSET_CWD, ASSET_CHMOD, ASSET_CHOWN, ASSET_CHGRP, |
80 |
ASSET_COMMENT, ASSET_IGNORE, ASSET_NAME, ASSET_EXEC, ASSET_UNEXEC, |
81 |
ASSET_SRC, ASSET_DISPLY, ASSET_PKGDEP, ASSET_CONFLICTS, ASSET_MTREE, |
82 |
ASSET_DIRRM, ASSET_DIRRMTRY, ASSET_IGNORE_INST, ASSET_OPTION, ASSET_ORIGIN, |
83 |
ASSET_DEPORIGIN, ASSET_NOINST, ASSET_DISPLAY, ASSET_DIR, |
84 |
ASSET_SAMPLE, ASSET_SHELL, |
85 |
ASSET_PREEXEC, ASSET_PREUNEXEC, ASSET_POSTEXEC, ASSET_POSTUNEXEC, |
86 |
ASSET_FILE_OWNER_MODE, ASSET_DIR_OWNER_MODE |
87 |
}; |
88 |
|
89 |
typedef enum _AssetListEntryType mportAssetListEntryType; |
90 |
|
91 |
struct _AssetListEntry { |
92 |
mportAssetListEntryType type; |
93 |
char *data; |
94 |
char *checksum; |
95 |
char *owner; |
96 |
char *group; |
97 |
char *mode; |
98 |
|
99 |
STAILQ_ENTRY(_AssetListEntry) next; |
100 |
}; |
101 |
|
102 |
STAILQ_HEAD(_AssetList, _AssetListEntry); |
103 |
|
104 |
typedef struct _AssetList mportAssetList; |
105 |
typedef struct _AssetListEntry mportAssetListEntry; |
106 |
|
107 |
mportAssetList* mport_assetlist_new(void); |
108 |
void mport_assetlist_free(mportAssetList *); |
109 |
int mport_parse_plistfile(FILE *, mportAssetList *); |
110 |
|
111 |
/* Package Meta-data structure */ |
112 |
|
113 |
typedef struct { |
114 |
char *name; |
115 |
char *version; |
116 |
char *lang; |
117 |
char *options; |
118 |
char *comment; |
119 |
char *desc; |
120 |
char *prefix; |
121 |
char *origin; |
122 |
char **categories; |
123 |
char *os_release; |
124 |
char *cpe; |
125 |
int locked; |
126 |
} mportPackageMeta; |
127 |
|
128 |
int mport_asset_get_assetlist(mportInstance *, mportPackageMeta *, mportAssetList **); |
129 |
int mport_asset_get_package_from_file_path(mportInstance *, const char *, mportPackageMeta **); |
130 |
|
131 |
mportPackageMeta * mport_pkgmeta_new(void); |
132 |
void mport_pkgmeta_free(mportPackageMeta *); |
133 |
void mport_pkgmeta_vec_free(mportPackageMeta **); |
134 |
int mport_pkgmeta_search_master(mportInstance *, mportPackageMeta ***, const char *, ...); |
135 |
int mport_pkgmeta_list(mportInstance *mport, mportPackageMeta ***ref); |
136 |
int mport_pkgmeta_get_downdepends(mportInstance *, mportPackageMeta *, mportPackageMeta ***); |
137 |
int mport_pkgmeta_get_updepends(mportInstance *, mportPackageMeta *, mportPackageMeta ***); |
138 |
|
139 |
|
140 |
/* index */ |
141 |
typedef struct { |
142 |
char *pkgname; |
143 |
char *version; |
144 |
char *comment; |
145 |
char *bundlefile; |
146 |
char *license; |
147 |
char *hash; |
148 |
} mportIndexEntry; |
149 |
|
150 |
int mport_index_load(mportInstance *); |
151 |
int mport_index_get(mportInstance *); |
152 |
int mport_index_list(mportInstance *, mportIndexEntry ***); |
153 |
int mport_index_lookup_pkgname(mportInstance *, const char *, mportIndexEntry ***); |
154 |
int mport_index_search(mportInstance *, mportIndexEntry ***, const char *, ...); |
155 |
void mport_index_entry_free_vec(mportIndexEntry **); |
156 |
void mport_index_entry_free(mportIndexEntry *); |
157 |
|
158 |
/* Index Depends */ |
159 |
|
160 |
typedef struct { |
161 |
char *pkgname; |
162 |
char *version; |
163 |
char *d_pkgname; |
164 |
char *d_version; |
165 |
} mportDependsEntry; |
166 |
|
167 |
int mport_index_depends_list(mportInstance *, const char *, const char *, mportDependsEntry ***); |
168 |
void mport_index_depends_free_vec(mportDependsEntry **); |
169 |
void mport_index_depends_free(mportDependsEntry *); |
170 |
|
171 |
|
172 |
/* Info */ |
173 |
char * mport_info(mportInstance *mport, const char *packageName); |
174 |
|
175 |
/* Package creation */ |
176 |
|
177 |
typedef struct { |
178 |
char *pkg_filename; |
179 |
char *sourcedir; |
180 |
char **depends; |
181 |
char *mtree; |
182 |
char **conflicts; |
183 |
char *pkginstall; |
184 |
char *pkgdeinstall; |
185 |
char *pkgmessage; |
186 |
} mportCreateExtras; |
187 |
|
188 |
mportCreateExtras * mport_createextras_new(void); |
189 |
void mport_createextras_free(mportCreateExtras *); |
190 |
|
191 |
int mport_create_primative(mportAssetList *, mportPackageMeta *, mportCreateExtras *); |
192 |
|
193 |
/* Merge primative */ |
194 |
int mport_merge_primative(const char **, const char *); |
195 |
|
196 |
/* Package installation */ |
197 |
int mport_install(mportInstance *, const char *, const char *, const char *); |
198 |
int mport_install_primative(mportInstance *, const char *, const char *); |
199 |
|
200 |
/* package updating */ |
201 |
int mport_update_primative(mportInstance *, const char *); |
202 |
|
203 |
/* Package deletion */ |
204 |
int mport_delete_primative(mportInstance *, mportPackageMeta *, int); |
205 |
|
206 |
/* package verify */ |
207 |
int mport_verify_package(mportInstance *, mportPackageMeta *); |
208 |
|
209 |
/* version comparing */ |
210 |
int mport_version_cmp(const char *, const char *); |
211 |
|
212 |
/* fetch XXX: This should become private */ |
213 |
int mport_fetch_bundle(mportInstance *, const char *); |
214 |
|
215 |
/* Errors */ |
216 |
int mport_err_code(void); |
217 |
const char * mport_err_string(void); |
218 |
|
219 |
|
220 |
#define MPORT_OK 0 |
221 |
#define MPORT_ERR_FATAL 1 |
222 |
#define MPORT_ERR_WARN 2 |
223 |
|
224 |
/* Clean */ |
225 |
int mport_clean_database(mportInstance *); |
226 |
int mport_clean_oldpackages(mportInstance *); |
227 |
|
228 |
/* Setting */ |
229 |
char * mport_setting_get(mportInstance *, const char *); |
230 |
int mport_setting_set(mportInstance *, const char *, const char *); |
231 |
|
232 |
/* Utils */ |
233 |
void mport_parselist(char *, char ***); |
234 |
int mport_verify_hash(const char *, const char *); |
235 |
int mport_file_exists(const char *); |
236 |
char * mport_version(void); |
237 |
char * mport_get_osrelease(void); |
238 |
|
239 |
/* Locks */ |
240 |
enum _LockState { |
241 |
MPORT_UNLOCKED, MPORT_LOCKED |
242 |
}; |
243 |
|
244 |
typedef enum _LockState mportLockState; |
245 |
|
246 |
int mport_lock_lock(mportInstance *, mportPackageMeta *); |
247 |
int mport_lock_unlock(mportInstance *, mportPackageMeta *); |
248 |
int mport_lock_islocked(mportPackageMeta *); |
249 |
|
250 |
/* Statistics */ |
251 |
typedef struct { |
252 |
unsigned int pkg_installed; |
253 |
unsigned int pkg_available; |
254 |
/* off_t pkg_installed_size; |
255 |
off_t pkg_available_size; */ |
256 |
} mportStats; |
257 |
|
258 |
int mport_stats(mportInstance *, mportStats **); |
259 |
int mport_stats_free(mportStats *); |
260 |
mportStats * mport_stats_new(void); |
261 |
|
262 |
#endif /* ! defined _MPORT_H */ |