1 /* librepo - A library providing (libcURL like) API to downloading repository
2  * Copyright (C) 2012  Tomas Mlcoch
3  *
4  * Licensed under the GNU Lesser General Public License Version 2.1
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef __LR_HANDLE_INTERNAL_H__
22 #define __LR_HANDLE_INTERNAL_H__
23 
24 #include <glib.h>
25 #include <curl/curl.h>
26 
27 #include "types.h"
28 #include "handle.h"
29 #include "lrmirrorlist.h"
30 #include "url_substitution.h"
31 
32 G_BEGIN_DECLS
33 
34 #define TMP_DIR_TEMPLATE    "librepo-XXXXXX"
35 
36 struct _LrHandle {
37 
38     CURL *curl_handle; /*!<
39         CURL handle */
40 
41     int update; /*!<
42         Just update existing repo */
43 
44     LrInternalMirrorlist *internal_mirrorlist; /*!<
45         Internal list of mirrors (Real used mirrorlist = baseurl + mirrors) */
46 
47     char **urls; /*!<
48         URLs of repositories */
49 
50     LrInternalMirrorlist *urls_mirrors; /*!<
51         Mirrors from urls */
52 
53     int fastestmirror; /*!<
54         Should be internal mirrorlist sorted by connection time */
55 
56     char *fastestmirrorcache; /*!<
57         Path to the fastestmirror's cache file. */
58 
59     long fastestmirrormaxage; /*!<
60         Maximum age of a record in cache (seconds). */
61 
62     LrFastestMirrorCb fastestmirrorcb; /*!<
63         Fastest mirror detection status callback */
64 
65     void *fastestmirrordata; /*!<
66         User data for fastestmirrorcb. */
67 
68     // Mirrorlist related stuff
69 
70     char *mirrorlist; /*!<
71         XXX: Deprecated!
72         List of or metalink */
73 
74     char *mirrorlisturl; /*!<
75         Mirrorlist URL */
76 
77     int mirrorlist_fd; /*!<
78         Raw downloaded mirrorlist file */
79 
80     LrInternalMirrorlist *mirrorlist_mirrors; /*!<
81         Mirrors from mirrorlist */
82 
83     // Metalink related stuff
84 
85     char * metalinkurl; /*!<
86         Metalink URL */
87 
88     int metalink_fd; /*!<
89         Raw downloaded metalink file */
90 
91     LrInternalMirrorlist *metalink_mirrors; /*!<
92         Mirrors from metalink */
93 
94     LrMetalink *metalink; /*!<
95         Parsed metalink for repomd.xml */
96 
97     LrInternalMirrorlist *mirrors;  /*!<
98         Mirrors from metalink or mirrorlist */
99 
100     char *onetimeflag; /*!<
101         See: LRO_ONETIMEFLAG */
102 
103     gboolean onetimeflag_apply; /*!<
104         Whether LRO_ONETIMEFLAG should be applied to the next CURL request */
105 
106     int local; /*!<
107         Do not duplicate local data */
108 
109     char *used_mirror; /*!<
110         Finally used mirror (if any) */
111 
112     char *destdir; /*!<
113         Destination directory */
114 
115     char *useragent; /*!<
116         User agent */
117 
118     LrRepotype repotype; /*!<
119         Type of repository */
120 
121     LrChecks checks; /*!<
122         Which check should be applied */
123 
124     LrProgressCb user_cb; /*!<
125         User progress callback */
126 
127     void *user_data; /*!<
128         User data for callback */
129 
130     int ignoremissing; /*!<
131         Ignore missing metadata files */
132 
133     int interruptible; /*!<
134         Setup own SIGTERM handler*/
135 
136     char **yumdlist; /*!<
137         Repomd data typenames to download NULL - Download all
138         yumdlist[0] = NULL - Only repomd.xml */
139 
140     char **yumblist; /*!<
141         Repomd data typenames to skip (skiplist). NULL as argument will
142         disable skiplist. */
143 
144     int fetchmirrors;   /*!<
145         Only fetch and parse mirrorlist. */
146 
147     int maxmirrortries; /*!<
148         Try at most this number of mirrors. */
149 
150     long maxparalleldownloads; /* !<
151         Maximum number of parallel downloads. */
152 
153     long maxdownloadspermirror; /* !<
154         Maximum number of parallel downloads per a single mirror. */
155 
156     LrUrlVars *urlvars; /*!<
157         List with url substitutions */
158 
159     long lowspeedtime; /*!<
160         The time in seconds that the transfer should be below the
161         LRO_LOWSPEEDLIMIT for the library to consider it too slow
162         and abort. */
163 
164     long lowspeedlimit; /*!<
165         The transfer speed in bytes per second that the transfer
166         should be below during LRO_LOWSPEEDTIME seconds for
167         the library to consider it too slow and abort. */
168 
169     LrHandleMirrorFailureCb hmfcb; /*!<
170         Callback called when a repodata download from a mirror fails. */
171 
172     gint64 maxspeed; /*!<
173         Max speed in bytes per sec */
174 
175     long sslverifypeer; /*!<
176         Determines whether verify the authenticity of the peer's certificate */
177 
178     long sslverifystatus; /*!<
179         Determines whether verify the the status of the server cert using the
180         'Certificate Status Request' TLS extension (aka. OCSP stapling). */
181 
182     long sslverifyhost; /*!<
183         Determines whether the server name should be checked against the name
184         in the certificate */
185 
186     char *sslclientcert; /*!<
187         Client certificate filename. */
188 
189     char *sslclientkey; /*!<
190         Client certificate key. */
191 
192     char *sslcacert; /*!<
193         CA certificate path. */
194 
195     long proxy_sslverifypeer; /*!<
196         Determines whether verify the authenticity of the proxy certificate */
197 
198     long proxy_sslverifyhost; /*!<
199         Determines whether the proxy name should be checked against the name
200         in the certificate */
201 
202     char *proxy_sslclientcert; /*!<
203         Client certificate filename. Used when talking to the proxy. */
204 
205     char *proxy_sslclientkey; /*!<
206         Client certificate key. Used for proxy. */
207 
208     char *proxy_sslcacert; /*!<
209         CA certificate path. Used for proxy. */
210 
211     LrIpResolveType ipresolve; /*!<
212         What kind of IP addresses to use when resolving host names. */
213 
214     long allowed_mirror_failures; /*!<
215         Number of allowed failed transfers, when there are no
216         successful ones, before a mirror gets ignored. */
217 
218     long adaptivemirrorsorting; /*!<
219         See: LRO_ADAPTIVEMIRRORSORTING */
220 
221     gchar *gnupghomedir; /*!<
222         GNUPG home dir. */
223 
224     gdouble fastestmirrortimeout; /*!<
225         Max length of fastest mirror measurement in seconds. */
226 
227     gchar **httpheader; /*!<
228         List of HTTP headers.
229         Curl doesn't copy HTTP header values from curl_slist.
230         We need to keep them around. */
231 
232     gboolean offline; /*!<
233         If TRUE, librepo should work offline - ignore all
234         non local URLs, etc. */
235 
236     LrAuth httpauthmethods; /*!<
237         Bitmask with auth methods */
238 
239     LrAuth proxyauthmethods; /*!<
240         Bitmask with auth methods */
241 
242     long ftpuseepsv; /*!<
243         Use FTP EPSV (extended passive mode) mode */
244 
245     gchar *cachedir; /*!<
246         Base cache dir for repositories */
247 
248     long preservetime; /*!<
249         Preserve timestamps of downloaded files */
250 
251     LrUrlVars *yumslist;
252 };
253 
254 /** Return new CURL easy handle with some default options setted.
255  */
256 CURL *
257 lr_get_curl_handle();
258 
259 /**
260  * Create (if do not exists) internal mirrorlist. Insert baseurl (if
261  * specified) and download, parse and insert mirrors from mirrorlist url.
262  * @param handle            Librepo handle.
263  * @param usefastestmirror  Sort internal mirrorlist by speed of mirrors
264  * @param err               GError **
265  * @return                  returns TRUE if error is not set and FALSE if it is.
266  */
267 gboolean
268 lr_handle_prepare_internal_mirrorlist(LrHandle *handle,
269                                       gboolean usefastestmirror,
270                                       GError **err);
271 
272 
273 G_END_DECLS
274 
275 #endif
276