Imported Upstream version 4.14.1
[platform/upstream/rpm.git] / lib / rpmlib.h
1 #ifndef H_RPMLIB
2 #define H_RPMLIB
3
4 /** \ingroup rpmcli rpmrc rpmdep rpmtrans rpmdb lead signature header payload dbi
5  * \file lib/rpmlib.h
6  *
7  * In Memoriam: Steve Taylor <staylor@redhat.com> was here, now he's not.
8  *
9  */
10
11 #include <popt.h>
12
13 #include <rpm/rpmio.h>
14 #include <rpm/header.h>
15 #include <rpm/rpmtag.h>
16 #include <rpm/rpmds.h>  /* XXX move rpmlib provides to rpmds instead */
17 #include <rpm/rpmpgp.h>
18
19 #ifdef _RPM_4_4_COMPAT
20 #warning RPM 4.4.x compatibility layer has been removed in RPM >= 4.14
21 #endif
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 extern struct rpmMacroContext_s * rpmGlobalMacroContext;
28
29 extern struct rpmMacroContext_s * rpmCLIMacroContext;
30
31 extern const char * const RPMVERSION;
32
33 extern const char * const rpmNAME;
34
35 extern const char * const rpmEVR;
36
37 extern const int rpmFLAGS;
38
39 /* ==================================================================== */
40 /** \name RPMRC */
41
42 /** \ingroup rpmrc
43  * Build and install arch/os table identifiers.
44  * @todo Eliminate from API.
45  */
46 enum rpm_machtable_e {
47     RPM_MACHTABLE_INSTARCH      = 0,    /*!< Install platform architecture. */
48     RPM_MACHTABLE_INSTOS        = 1,    /*!< Install platform operating system. */
49     RPM_MACHTABLE_BUILDARCH     = 2,    /*!< Build platform architecture. */
50     RPM_MACHTABLE_BUILDOS       = 3     /*!< Build platform operating system. */
51 };
52 #define RPM_MACHTABLE_COUNT     4       /*!< No. of arch/os tables. */
53
54 /** \ingroup rpmrc
55  * Read macro configuration file(s) for a target.
56  * @param file          colon separated files to read (NULL uses default)
57  * @param target        target platform (NULL uses default)
58  * @return              0 on success, -1 on error
59  */
60 int rpmReadConfigFiles(const char * file,
61                 const char * target);
62
63 /** \ingroup rpmrc
64  * Return current arch name and/or number.
65  * @todo Generalize to extract arch component from target_platform macro.
66  * @retval name         address of arch name (or NULL)
67  * @retval num          address of arch number (or NULL)
68  */
69 void rpmGetArchInfo( const char ** name,
70                 int * num);
71
72 /** \ingroup rpmrc
73  * Return color for an arch
74  * @param arch          name of an architecture
75  * @return color        color of arch, -1 if the arch couldn't be determined
76  */
77 int rpmGetArchColor(const char *arch);
78
79 /** \ingroup rpmrc
80  * Return current os name and/or number.
81  * @todo Generalize to extract os component from target_platform macro.
82  * @retval name         address of os name (or NULL)
83  * @retval num          address of os number (or NULL)
84  */
85 void rpmGetOsInfo( const char ** name,
86                 int * num);
87
88 /** \ingroup rpmrc
89  * Return arch/os score of a name.
90  * An arch/os score measures the "nearness" of a name to the currently
91  * running (or defined) platform arch/os. For example, the score of arch
92  * "i586" on an i686 platform is (usually) 2. The arch/os score is used
93  * to select one of several otherwise identical packages using the arch/os
94  * tags from the header as hints of the intended platform for the package.
95  * @todo Rewrite to use RE's against config.guess target platform output.
96  *
97  * @param type          any of the RPM_MACHTABLE_* constants
98  * @param name          name
99  * @return              arch score (0 is no match, lower is preferred)
100  */
101 int rpmMachineScore(int type, const char * name);
102
103 /** \ingroup rpmrc
104  * Display current rpmrc (and macro) configuration.
105  * @param fp            output file handle
106  * @return              0 always
107  */
108 int rpmShowRC(FILE * fp);
109
110 /** \ingroup rpmrc
111  * Destroy rpmrc arch/os compatibility tables.
112  * @todo Eliminate from API.
113  */
114 void rpmFreeRpmrc(void);
115
116 /**
117  * Compare headers to determine which header is "newer".
118  * @param first         1st header
119  * @param second        2nd header
120  * @return              result of comparison
121  */
122 int rpmVersionCompare(Header first, Header second);
123
124 /**  \ingroup header
125  * Check header consistency, performing headerGetEntry() the hard way.
126  *  
127  * Sanity checks on the header are performed while looking for a
128  * header-only digest or signature to verify the blob. If found,
129  * the digest or signature is verified.
130  *
131  * @param ts            transaction set
132  * @param uh            unloaded header blob
133  * @param uc            no. of bytes in blob (or 0 to disable)
134  * @retval *msg         verification error message (or NULL)
135  * @return              RPMRC_OK on success
136  */
137 rpmRC headerCheck(rpmts ts, const void * uh, size_t uc, char ** msg);
138
139 /**  \ingroup header
140  * Return checked and loaded header.
141  * @param ts            unused
142  * @param fd            file handle
143  * @retval hdrp         address of header (or NULL)
144  * @retval *msg         verification error message (or NULL)
145  * @return              RPMRC_OK on success
146  */
147 rpmRC rpmReadHeader(rpmts ts, FD_t fd, Header *hdrp, char ** msg);
148
149 /** \ingroup header
150  * Return package header from file handle, verifying digests/signatures.
151  * @param ts            transaction set
152  * @param fd            file handle
153  * @param fn            file name
154  * @retval hdrp         address of header (or NULL)
155  * @return              RPMRC_OK on success
156  */
157 rpmRC rpmReadPackageFile(rpmts ts, FD_t fd,
158                 const char * fn, Header * hdrp);
159
160 /** \ingroup rpmtrans
161  * Install source package.
162  * @param ts            transaction set
163  * @param fd            file handle
164  * @retval specFilePtr  address of spec file name (or NULL)
165  * @retval cookie       address of cookie pointer (or NULL)
166  * @return              rpmRC return code
167  */
168 rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd,
169                         char ** specFilePtr,
170                         char ** cookie);
171
172 /** \ingroup rpmtrans
173  * Segmented string compare for version or release strings.
174  *
175  * @param a             1st string
176  * @param b             2nd string
177  * @return              +1 if a is "newer", 0 if equal, -1 if b is "newer"
178  */
179 int rpmvercmp(const char * a, const char * b);
180
181 #ifdef __cplusplus
182 }
183 #endif
184
185 #endif  /* H_RPMLIB */