1 |
/* $MidnightBSD: src/lib/libmport/mport.h,v 1.20 2011/05/21 19:35:29 laffer1 Exp $ |
2 |
* |
3 |
* Copyright (c) 2007-2009 Chris Reinhardt |
4 |
* All rights reserved. |
5 |
* |
6 |
* Redistribution and use in source and binary forms, with or without |
7 |
* modification, are permitted provided that the following conditions |
8 |
* are met: |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* 2. Redistributions in binary form must reproduce the above copyright |
12 |
* notice, this list of conditions and the following disclaimer in the |
13 |
* documentation and/or other materials provided with the distribution. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
*/ |
28 |
|
29 |
#ifndef _MPORT_H_ |
30 |
#define _MPORT_H_ |
31 |
|
32 |
|
33 |
#include <sys/cdefs.h> |
34 |
#include <archive.h> |
35 |
#include <sqlite3.h> |
36 |
#include <sys/queue.h> |
37 |
#include <stdio.h> |
38 |
|
39 |
typedef void (*mport_msg_cb)(const char *); |
40 |
typedef void (*mport_progress_init_cb)(const char *); |
41 |
typedef void (*mport_progress_step_cb)(int, int, const char *); |
42 |
typedef void (*mport_progress_free_cb)(void); |
43 |
typedef int (*mport_confirm_cb)(const char *, const char *, const char *, int); |
44 |
|
45 |
/* Mport Instance (an installed copy of the mport system) */ |
46 |
#define MPORT_INST_HAVE_INDEX 1 |
47 |
|
48 |
typedef struct { |
49 |
int flags; |
50 |
sqlite3 *db; |
51 |
char *root; |
52 |
mport_msg_cb msg_cb; |
53 |
mport_progress_init_cb progress_init_cb; |
54 |
mport_progress_step_cb progress_step_cb; |
55 |
mport_progress_free_cb progress_free_cb; |
56 |
mport_confirm_cb confirm_cb; |
57 |
} mportInstance; |
58 |
|
59 |
mportInstance * mport_instance_new(void); |
60 |
int mport_instance_init(mportInstance *, const char *); |
61 |
int mport_instance_free(mportInstance *); |
62 |
|
63 |
void mport_set_msg_cb(mportInstance *, mport_msg_cb); |
64 |
void mport_set_progress_init_cb(mportInstance *, mport_progress_init_cb); |
65 |
void mport_set_progress_step_cb(mportInstance *, mport_progress_step_cb); |
66 |
void mport_set_progress_free_cb(mportInstance *, mport_progress_free_cb); |
67 |
void mport_set_confirm_cb(mportInstance *, mport_confirm_cb); |
68 |
|
69 |
void mport_default_msg_cb(const char *); |
70 |
int mport_default_confirm_cb(const char *, const char *, const char *, int); |
71 |
void mport_default_progress_init_cb(const char *); |
72 |
void mport_default_progress_step_cb(int, int, const char *); |
73 |
void mport_default_progress_free_cb(void); |
74 |
|
75 |
/* For now this is just the FreeBSD list, this will change soon. */ |
76 |
enum _AssetListEntryType { |
77 |
ASSET_INVALID, ASSET_FILE, ASSET_CWD, ASSET_CHMOD, ASSET_CHOWN, ASSET_CHGRP, |
78 |
ASSET_COMMENT, ASSET_IGNORE, ASSET_NAME, ASSET_EXEC, ASSET_UNEXEC, |
79 |
ASSET_SRC, ASSET_DISPLY, ASSET_PKGDEP, ASSET_CONFLICTS, ASSET_MTREE, |
80 |
ASSET_DIRRM, ASSET_DIRRMTRY, ASSET_IGNORE_INST, ASSET_OPTION, ASSET_ORIGIN, |
81 |
ASSET_DEPORIGIN, ASSET_NOINST, ASSET_DISPLAY |
82 |
}; |
83 |
|
84 |
typedef enum _AssetListEntryType mportAssetListEntryType; |
85 |
|
86 |
struct _AssetListEntry { |
87 |
mportAssetListEntryType type; |
88 |
char *data; |
89 |
STAILQ_ENTRY(_AssetListEntry) next; |
90 |
}; |
91 |
|
92 |
STAILQ_HEAD(_AssetList, _AssetListEntry); |
93 |
|
94 |
typedef struct _AssetList mportAssetList; |
95 |
typedef struct _AssetListEntry mportAssetListEntry; |
96 |
|
97 |
mportAssetList* mport_assetlist_new(void); |
98 |
void mport_assetlist_free(mportAssetList *); |
99 |
int mport_parse_plistfile(FILE *, mportAssetList *); |
100 |
|
101 |
/* Package Meta-data structure */ |
102 |
|
103 |
typedef struct { |
104 |
char *name; |
105 |
char *version; |
106 |
char *lang; |
107 |
char *options; |
108 |
char *comment; |
109 |
char *desc; |
110 |
char *prefix; |
111 |
char *origin; |
112 |
char **categories; |
113 |
} mportPackageMeta; |
114 |
|
115 |
|
116 |
mportPackageMeta * mport_pkgmeta_new(void); |
117 |
void mport_pkgmeta_free(mportPackageMeta *); |
118 |
void mport_pkgmeta_vec_free(mportPackageMeta **); |
119 |
int mport_pkgmeta_search_master(mportInstance *, mportPackageMeta ***, const char *, ...); |
120 |
int mport_pkgmeta_list(mportInstance *mport, mportPackageMeta ***ref); |
121 |
int mport_pkgmeta_get_downdepends(mportInstance *, mportPackageMeta *, mportPackageMeta ***); |
122 |
int mport_pkgmeta_get_updepends(mportInstance *, mportPackageMeta *, mportPackageMeta ***); |
123 |
|
124 |
|
125 |
/* index */ |
126 |
typedef struct { |
127 |
char *pkgname; |
128 |
char *version; |
129 |
char *comment; |
130 |
char *bundlefile; |
131 |
char *license; |
132 |
char *hash; |
133 |
} mportIndexEntry; |
134 |
|
135 |
int mport_index_load(mportInstance *); |
136 |
int mport_index_lookup_pkgname(mportInstance *, const char *, mportIndexEntry ***); |
137 |
int mport_index_search(mportInstance *, mportIndexEntry ***, const char *, ...); |
138 |
void mport_index_entry_free_vec(mportIndexEntry **); |
139 |
void mport_index_entry_free(mportIndexEntry *); |
140 |
|
141 |
/* Package creation */ |
142 |
|
143 |
typedef struct { |
144 |
char *pkg_filename; |
145 |
char *sourcedir; |
146 |
char **depends; |
147 |
char *mtree; |
148 |
char **conflicts; |
149 |
char *pkginstall; |
150 |
char *pkgdeinstall; |
151 |
char *pkgmessage; |
152 |
} mportCreateExtras; |
153 |
|
154 |
mportCreateExtras * mport_createextras_new(void); |
155 |
void mport_createextras_free(mportCreateExtras *); |
156 |
|
157 |
int mport_create_primative(mportAssetList *, mportPackageMeta *, mportCreateExtras *); |
158 |
|
159 |
/* Merge primative */ |
160 |
int mport_merge_primative(const char **, const char *); |
161 |
|
162 |
/* Package installation */ |
163 |
int mport_install(mportInstance *, const char *, const char *); |
164 |
int mport_install_primative(mportInstance *, const char *, const char *); |
165 |
|
166 |
/* package updating */ |
167 |
int mport_update_primative(mportInstance *, const char *); |
168 |
|
169 |
/* Package deletion */ |
170 |
int mport_delete_primative(mportInstance *, mportPackageMeta *, int); |
171 |
|
172 |
|
173 |
/* version comparing */ |
174 |
int mport_version_cmp(const char *, const char *); |
175 |
|
176 |
/* Errors */ |
177 |
int mport_err_code(void); |
178 |
const char * mport_err_string(void); |
179 |
|
180 |
|
181 |
#define MPORT_OK 0 |
182 |
#define MPORT_ERR_FATAL 1 |
183 |
#define MPORT_ERR_WARN 2 |
184 |
|
185 |
/* Clean */ |
186 |
int mport_clean_database(mportInstance *); |
187 |
int mport_clean_oldpackages(mportInstance *); |
188 |
|
189 |
/* Setting */ |
190 |
char * mport_setting_get(mportInstance *, const char *); |
191 |
int mport_setting_set(mportInstance *, const char *, const char *); |
192 |
|
193 |
/* Utils */ |
194 |
void mport_parselist(char *, char ***); |
195 |
int mport_verify_hash(const char *, const char *); |
196 |
int mport_file_exists(const char *); |
197 |
|
198 |
#endif /* ! defined _MPORT_H */ |
199 |
|