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_YUMREPO_H__
22 #define __LR_YUMREPO_H__
23 
24 #include <glib.h>
25 
26 #include "handle.h"
27 #include "metalink.h"
28 #include "rcodes.h"
29 #include "repomd.h"
30 #include "result.h"
31 
32 G_BEGIN_DECLS
33 
34 /** \defgroup   yum       Yum repo manipulation
35  *  \addtogroup yum
36  *  @{
37  */
38 
39 /** Path to single metadata file from repomd.xml. */
40 typedef struct {
41     char *type;  /*!< Type of record (e.g. "primary") */
42     char *path;  /*!< Path to the file (e.g. foo/bar/repodata/primary.xml) */
43 } LrYumRepoPath;
44 
45 /** Yum repository */
46 typedef struct {
47     GSList *paths;      /*!< Paths to repo files. List of ::LrYumRepoPath*s */
48     char *repomd;       /*!< Path to repomd.xml */
49     char *url;          /*!< URL from where repo was downloaded */
50     char *destdir;      /*!< Local path to the repo */
51     char *signature;    /*!< Path to signature if available and
52                              signature was downloaded (GPG check
53                              was enabled during repo downloading) */
54     char *mirrorlist;   /*!< Mirrolist filename */
55     char *metalink;     /*!< Metalink filename */
56     gboolean use_zchunk; /*!< Use zchunk in this repo */
57 } LrYumRepo;
58 
59 /** Mirror Failure Callback Data
60  */
61 typedef struct CbData_s {
62     void *userdata;                 /*!< User data */
63     void *cbdata;                   /*!< User's callback data */
64     LrProgressCb progresscb;        /*!< Progress callback */
65     LrHandleMirrorFailureCb hmfcb;  /*!< Handle mirror failure callback */
66     char *metadata;                 /*!< "primary", "filelists", ... */
67 } CbData;
68 
69 /** Allocate new yum repo object.
70  * @return              New yum repo object.
71  */
72 LrYumRepo *
73 lr_yum_repo_init(void);
74 
75 /** Free yum repo - free its item and the repo itself.
76  * @param repo          Yum repo object.
77  */
78 void
79 lr_yum_repo_free(LrYumRepo *repo);
80 
81 /** Retruns path for the file from repository.
82  * @param repo          Yum repo object.
83  * @param type          Type of path. E.g. "primary", "filelists", ...
84  * @return              Path or NULL.
85  */
86 const char *
87 lr_yum_repo_path(LrYumRepo *repo, const char *type);
88 
89 /**
90  * Handle mirror failure callback
91  * @param clientp Pointer to user data.
92  * @param msg Error message.
93  * @param url Mirror URL.
94  * @return See LrCbReturnCode codes
95  */
96 int
97 hmfcb(void *clientp, const char *msg, const char *url);
98 
99 /** Prepares directory for repo data
100  * @param handle        Handle object containing path to repo data
101  * @param err           Object for storing errors
102  * @return              True on success
103  */
104 gboolean
105 lr_prepare_repodata_dir(LrHandle *handle, GError **err);
106 
107 
108 /** Stores mirror list files
109  * @param handle        Handle object containing path to mirror list
110  * @param repo          Yum repository
111  * @param err           Object for storing errors
112  * @return              True on success
113  */
114 gboolean
115 lr_store_mirrorlist_files(LrHandle *handle, LrYumRepo *repo, GError **err);
116 
117 /** Copies metalink content
118  * @param handle        Handle object containing dest dir path
119  * @param repo          Yum repository
120  * @param err           Object for storing errors
121  * @return              True on success
122  */
123 gboolean
124 lr_copy_metalink_content(LrHandle *handle, LrYumRepo *repo, GError **err);
125 
126 /** Prepares repomd.xml file
127  * @param handle        Handle object containing dest dir path
128  * @param path
129  * @param err           Object for storing errors
130  * @return              File descriptor of repomd.xml file
131  */
132 int
133 lr_prepare_repomd_xml_file(LrHandle *handle, char **path, GError **err);
134 
135 gboolean
136 lr_check_repomd_xml_asc_availability(LrHandle *handle, LrYumRepo *repo, int fd, char *path, GError **err);
137 
138 /** Stores best checksum on the beginning of @param checksums
139  * @param metalink      Metalink
140  * @param checksums     List of checksums
141  */
142 void
143 lr_get_best_checksum(const LrMetalink *metalink, GSList **checksums);
144 
145 /** Returns mirror failure callback data
146  * @param handle        Handle object
147  * @return              Mirror Failure Callback Data
148  */
149 CbData *
150 lr_get_metadata_failure_callback(const LrHandle *handle);
151 
152 /**
153  *
154  * @param targets
155  * @param err
156  * @return return TRUE on success, FALSE otherwise
157  */
158 gboolean
159 lr_yum_download_repos(GSList *targets,
160                       GError **err);
161 
162 /** @} */
163 
164 G_END_DECLS
165 
166 #endif
167