Add macro %isu_package to generate ISU Package
[platform/upstream/rpm.git] / lib / rpmcli.h
1 #ifndef H_RPMCLI
2 #define H_RPMCLI
3
4 /** \ingroup rpmcli rpmbuild
5  * \file lib/rpmcli.h
6  *
7  * Parsing RPM command line arguments
8  */
9
10 #include <popt.h>
11
12 #include <rpm/rpmlib.h>
13 #include <rpm/rpmurl.h>
14 #include <rpm/rpmmacro.h>
15 #include <rpm/rpmcallback.h>
16 #include <rpm/rpmts.h>
17 #include <rpm/rpmfi.h>
18 #include <rpm/rpmvf.h>
19 #include <rpm/argv.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /** \ingroup rpmcli
26  * Popt option table for options shared by all modes and executables.
27  */
28 extern struct poptOption                rpmcliAllPoptTable[];
29
30 extern const char * rpmcliPipeOutput;
31
32 extern const char * rpmcliRcfile;
33
34 extern const char * rpmcliRootDir;
35
36 /** \ingroup rpmcli
37  * Initialize most everything needed by an rpm CLI executable context.
38  * @param argc                  no. of args
39  * @param argv                  arg array
40  * @param optionsTable          popt option table
41  * @return                      popt context (or NULL)
42  */
43 poptContext
44 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable);
45
46 /** \ingroup rpmcli
47  * Make sure that rpm configuration has been read.
48  * @warning Options like --rcfile and --verbose must precede callers option.
49  */
50 void rpmcliConfigured(void);
51
52 /** \ingroup rpmcli
53  * Destroy most everything needed by an rpm CLI executable context.
54  * @param optCon                popt context
55  * @return                      NULL always
56  */
57 poptContext
58 rpmcliFini(poptContext optCon);
59
60 /**
61  * Common/global popt tokens used for command line option tables.
62  */
63 #define RPMCLI_POPT_NODEPS              -1025
64 #define RPMCLI_POPT_FORCE               -1026
65 #define RPMCLI_POPT_NOMD5               -1027
66 #define RPMCLI_POPT_NOFILEDIGEST        -1027   /* same as obsolete RPMCLI_POPT_NOMD5 */
67 #define RPMCLI_POPT_NOSCRIPTS           -1028
68 #define RPMCLI_POPT_NOSIGNATURE         -1029
69 #define RPMCLI_POPT_NODIGEST            -1030
70 #define RPMCLI_POPT_NOHDRCHK            -1031
71 #define RPMCLI_POPT_NOCONTEXTS          -1032
72 #define RPMCLI_POPT_NOCAPS              -1033
73 #define RPMCLI_POPT_TARGETPLATFORM      -1034
74
75 /* ==================================================================== */
76 /** \name RPMQV */
77
78 /** \ingroup rpmcli
79  * Query/Verify argument qualifiers.
80  * @todo Reassign to tag values.
81  */
82 enum rpmQVSources_e {
83     RPMQV_PACKAGE = 0,  /*!< ... from package name db search. */
84     RPMQV_PATH,         /*!< ... from file path db search. */
85     RPMQV_ALL,          /*!< ... from each installed package. */
86     RPMQV_RPM,          /*!< ... from reading binary rpm package. */
87     RPMQV_GROUP,        /*!< ... from group db search. */
88     RPMQV_WHATPROVIDES, /*!< ... from provides db search. */
89     RPMQV_WHATREQUIRES, /*!< ... from requires db search. */
90     RPMQV_TRIGGEREDBY,  /*!< ... from trigger db search. */
91     RPMQV_DBOFFSET,     /*!< ... from database header instance. */
92     RPMQV_SPECRPMS,     /*!< ... from spec file binaries (query only). */
93     RPMQV_SPECFILE = RPMQV_SPECRPMS, /*!< ... backwards compatibility */
94     RPMQV_PKGID,        /*!< ... from package id (header+payload MD5). */
95     RPMQV_HDRID,        /*!< ... from header id (immutable header SHA1). */
96     RPMQV_TID,          /*!< ... from install transaction id (time stamp). */
97     RPMQV_SPECSRPM,     /*!< ... from spec file source (query only). */
98     RPMQV_WHATRECOMMENDS,       /*!< ... from recommends db search. */
99     RPMQV_WHATSUGGESTS,         /*!< ... from suggests db search. */
100     RPMQV_WHATSUPPLEMENTS,      /*!< ... from supplements db search. */
101     RPMQV_WHATENHANCES,         /*!< ... from enhances db search. */
102     RPMQV_SPECBUILTRPMS,        /*!< ... from pkgs which would be built from spec */
103 };
104
105 typedef rpmFlags rpmQVSources;
106
107 /** \ingroup rpmcli
108  * Bit(s) to control rpmQuery() operation, stored in qva_flags.
109  * @todo Merge rpmQueryFlags, rpmVerifyFlags, and rpmVerifyAttrs?.
110  */
111 enum rpmQueryFlags_e {
112     QUERY_FOR_DEFAULT   = 0,            /*!< */
113     QUERY_MD5           = (1 << 0),     /*!< from --nomd5 */
114     QUERY_FILEDIGEST    = (1 << 0),     /*!< from --nofiledigest, same as --nomd5 */
115     QUERY_SIZE          = (1 << 1),     /*!< from --nosize */
116     QUERY_LINKTO        = (1 << 2),     /*!< from --nolink */
117     QUERY_USER          = (1 << 3),     /*!< from --nouser) */
118     QUERY_GROUP         = (1 << 4),     /*!< from --nogroup) */
119     QUERY_MTIME         = (1 << 5),     /*!< from --nomtime) */
120     QUERY_MODE          = (1 << 6),     /*!< from --nomode) */
121     QUERY_RDEV          = (1 << 7),     /*!< from --nodev */
122         /* bits 8-14 unused, reserved for rpmVerifyAttrs */
123     QUERY_CONTEXTS      = (1 << 15),    /*!< verify: from --nocontexts */
124     QUERY_FILES         = (1 << 16),    /*!< verify: from --nofiles */
125     QUERY_DEPS          = (1 << 17),    /*!< verify: from --nodeps */
126     QUERY_SCRIPT        = (1 << 18),    /*!< verify: from --noscripts */
127     QUERY_DIGEST        = (1 << 19),    /*!< verify: from --nodigest */
128     QUERY_SIGNATURE     = (1 << 20),    /*!< verify: from --nosignature */
129     QUERY_PATCHES       = (1 << 21),    /*!< verify: from --nopatches */
130     QUERY_HDRCHK        = (1 << 22),    /*!< verify: from --nohdrchk */
131     QUERY_FOR_LIST      = (1 << 23),    /*!< query:  from --list */
132     QUERY_FOR_STATE     = (1 << 24),    /*!< query:  from --state */
133     QUERY_FOR_DOCS      = (1 << 25),    /*!< query:  from --docfiles */
134     QUERY_FOR_CONFIG    = (1 << 26),    /*!< query:  from --configfiles */
135     QUERY_FOR_DUMPFILES = (1 << 27),    /*!< query:  from --dump */
136     QUERY_FOR_LICENSE   = (1 << 28),    /*!< query:  from --licensefiles */
137     QUERY_FOR_ARTIFACT  = (1 << 29),    /*!< query:  from --artifacts */
138 };
139
140 typedef rpmFlags rpmQueryFlags;
141
142 #define _QUERY_FOR_BITS \
143    (QUERY_FOR_LIST|QUERY_FOR_STATE|QUERY_FOR_DOCS|QUERY_FOR_CONFIG|\
144     QUERY_FOR_LICENSE|QUERY_FOR_DUMPFILES)
145
146 /** \ingroup rpmcli
147  * Bit(s) from common command line options.
148  */
149 extern rpmQueryFlags rpmcliQueryFlags;
150
151 /** \ingroup rpmcli
152  */
153 typedef struct rpmQVKArguments_s * QVA_t;
154
155 /** \ingroup rpmcli
156  * Function to display iterator matches.
157  *
158  * @param qva           parsed query/verify options
159  * @param ts            transaction set
160  * @param h             header to use for query/verify
161  * @return              0 on success
162  */
163 typedef int (*QVF_t) (QVA_t qva, rpmts ts, Header h);
164
165 /** \ingroup rpmcli
166  * Function to query spec file.
167  *
168  * @param ts            transaction set
169  * @param qva           parsed query/verify options
170  * @param arg           query argument
171  * @return              0 on success
172  */
173 typedef int (*QSpecF_t) (rpmts ts, QVA_t qva, const char * arg);
174
175 /** \ingroup rpmcli
176  * Describe query/verify/signature command line operation.
177  */
178 struct rpmQVKArguments_s {
179     rpmQVSources qva_source;    /*!< Identify CLI arg type. */
180     int         qva_sourceCount;/*!< Exclusive option check (>1 is error). */
181     rpmQueryFlags qva_flags;    /*!< Bit(s) to control operation. */
182     rpmfileAttrs qva_fflags;    /*!< Bit(s) to filter on attribute. */
183
184     QVF_t qva_showPackage;      /*!< Function to display iterator matches. */
185     QSpecF_t qva_specQuery;     /*!< Function to query spec file. */
186     char * qva_queryFormat;     /*!< Format for headerFormat(). */
187     char        qva_mode;
188                 /*!<
189                 - 'q'   from --query, -q
190                 - 'Q'   from --querytags
191                 - 'V'   from --verify, -V
192                 - 'I'   from --import
193                 - 'K'   from --checksig, -K
194                 */
195 };
196
197 /** \ingroup rpmcli
198  */
199 extern struct rpmQVKArguments_s rpmQVKArgs;
200
201 /** \ingroup rpmcli
202  */
203 extern struct poptOption rpmQVSourcePoptTable[];
204
205 /** \ingroup rpmcli
206  */
207 extern struct poptOption rpmQueryPoptTable[];
208
209 /** \ingroup rpmcli
210  */
211 extern struct poptOption rpmVerifyPoptTable[];
212
213 /** \ingroup rpmcli
214  * Display list of tags that can be used in --queryformat.
215  * @param fp    file handle to use for display
216  */
217 void rpmDisplayQueryTags(FILE * fp);
218
219 /** \ingroup rpmcli
220  * Display results of package query.
221  * @todo Devise a meaningful return code.
222  * @param qva           parsed query/verify options
223  * @param ts            transaction set
224  * @param h             header to use for query
225  * @return              0 always
226  */
227 int showQueryPackage(QVA_t qva, rpmts ts, Header h);
228
229 /** \ingroup rpmcli
230  * Iterate over query/verify arg list.
231  * @param ts            transaction set
232  * @param qva           parsed query/verify options
233  * @param argv          query argument(s) (or NULL)
234  * @return              0 on success, else no. of failures
235  */
236 int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv);
237
238 /** \ingroup rpmcli
239  * Display package information.
240  * @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
241  * @param ts            transaction set
242  * @param qva           parsed query/verify options
243  * @param argv          query argument(s) (or NULL)
244  * @return              0 on success, else no. of failures
245  */
246 int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv);
247
248 /** \ingroup rpmcli
249  * Display results of package verify.
250  * @param qva           parsed query/verify options
251  * @param ts            transaction set
252  * @param h             header to use for verify
253  * @return              result of last non-zero verify return
254  */
255 int showVerifyPackage(QVA_t qva, rpmts ts, Header h);
256
257 /**
258  * Check package and header signatures.
259  * @param qva           parsed query/verify options
260  * @param ts            transaction set
261  * @param fd            package file handle
262  * @param fn            package file name
263  * @return              0 on success, 1 on failure
264  */
265 int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, const char * fn);
266
267 /** \ingroup rpmcli
268  * Verify package install.
269  * @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
270  * @param ts            transaction set
271  * @param qva           parsed query/verify options
272  * @param argv          verify argument(s) (or NULL)
273  * @return              0 on success, else no. of failures
274  */
275 int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv);
276
277 /* ==================================================================== */
278 /** \name RPMEIU */
279 /* --- install/upgrade/erase modes */
280
281 /** \ingroup rpmcli
282  * Bit(s) to control rpmInstall() operation.
283  */
284 enum rpmInstallFlags_e {
285     INSTALL_NONE        = 0,
286     INSTALL_PERCENT     = (1 << 0),     /*!< from --percent */
287     INSTALL_HASH        = (1 << 1),     /*!< from --hash */
288     INSTALL_NODEPS      = (1 << 2),     /*!< from --nodeps */
289     INSTALL_NOORDER     = (1 << 3),     /*!< from --noorder */
290     INSTALL_LABEL       = (1 << 4),     /*!< from --verbose (notify) */
291     INSTALL_UPGRADE     = (1 << 5),     /*!< from --upgrade */
292     INSTALL_FRESHEN     = (1 << 6),     /*!< from --freshen */
293     INSTALL_INSTALL     = (1 << 7),     /*!< from --install */
294     INSTALL_ERASE       = (1 << 8),     /*!< from --erase */
295     INSTALL_ALLMATCHES  = (1 << 9),     /*!< from --allmatches */
296     INSTALL_REINSTALL   = (1 << 10),    /*!< from --reinstall */
297 };
298
299 typedef rpmFlags rpmInstallFlags;
300
301 /** \ingroup rpmcli
302  * Bit(s) to control rpmErase() operation.
303  */
304 #define UNINSTALL_NONE INSTALL_NONE
305 #define UNINSTALL_NODEPS INSTALL_NODEPS
306 #define UNINSTALL_ALLMATCHES INSTALL_ALLMATCHES
307
308 /** \ingroup rpmcli
309  * The rpm CLI generic transaction callback handler.
310  * @todo Remove headerFormat() from the progress callback.
311  * @deprecated Transaction callback arguments need to change, so don't rely on
312  * this routine in the rpmcli API.
313  *
314  * @param arg           per-callback private data (e.g. an rpm header)
315  * @param what          callback identifier
316  * @param amount        per-callback progress info
317  * @param total         per-callback progress info
318  * @param key           opaque header key (e.g. file name or PyObject)
319  * @param data          private data (e.g. rpmInstallInterfaceFlags)
320  * @return              per-callback data (e.g. an opened FD_t)
321  */
322 void * rpmShowProgress(const void * arg,
323                 const rpmCallbackType what,
324                 const rpm_loff_t amount,
325                 const rpm_loff_t total,
326                 fnpyKey key,
327                 void * data);
328
329 /** \ingroup rpmcli
330  * Install source rpm package.
331  * @param ts            transaction set
332  * @param arg           source rpm file name
333  * @retval *specFilePtr (installed) spec file name
334  * @retval *cookie
335  * @return              0 on success
336  */
337 int rpmInstallSource(rpmts ts, const char * arg,
338                 char ** specFilePtr,
339                 char ** cookie);
340
341
342 /** \ingroup rpmcli
343  * Describe database command line requests.
344  */
345 struct rpmInstallArguments_s {
346     rpmtransFlags transFlags;
347     rpmprobFilterFlags probFilter;
348     rpmInstallFlags installInterfaceFlags;
349     int numRelocations;
350     int noDeps;
351     int incldocs;
352     rpmRelocation * relocations;
353     char * prefix;
354 };
355
356 /** \ingroup rpmcli
357  * Install/upgrade/freshen/reinstall binary rpm package.
358  * @param ts            transaction set
359  * @param ia            mode flags and parameters
360  * @param fileArgv      array of package file names (NULL terminated)
361  * @return              0 on success
362  *
363  * @todo                fileArgv is modified on errors, should be ARGV_const_t
364  */
365 int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv);
366
367 /** \ingroup rpmcli
368  * Erase binary rpm package.
369  * @param ts            transaction set
370  * @param ia            control args/bits
371  * @param argv          array of package file names (NULL terminated)
372  * @return              0 on success
373  */
374
375 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv);
376
377 /** \ingroup rpmcli
378  */
379 extern struct rpmInstallArguments_s rpmIArgs;
380
381 /** \ingroup rpmcli
382  */
383 extern struct poptOption rpmInstallPoptTable[];
384
385 /* ==================================================================== */
386 /** \name RPMK */
387
388 /** Import public key(s) to rpm keyring
389  * @param ts            transaction set
390  * @param argv          array of pubkey path arguments (NULL terminated)
391  * @return              0 on success
392  */
393 int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv);
394
395 /** \ingroup rpmcli
396  * Verify package signatures
397  * @param ts            transaction set
398  * @param argv          array of package path arguments (NULL terminated)
399  * @return              0 on success
400  */
401 int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv);
402
403 #ifdef __cplusplus
404 }
405 #endif
406
407 #endif  /* H_RPMCLI */