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_LRMIRRORLIST_H__ 22 #define __LR_LRMIRRORLIST_H__ 23 24 #include <glib.h> 25 26 #include "url_substitution.h" 27 #include "mirrorlist.h" 28 #include "metalink.h" 29 30 G_BEGIN_DECLS 31 32 typedef enum { 33 LR_PROTOCOL_OTHER, 34 LR_PROTOCOL_FILE, 35 LR_PROTOCOL_HTTP, 36 LR_PROTOCOL_FTP, 37 LR_PROTOCOL_RSYNC, 38 } LrProtocol; 39 40 /** A internal representation of a mirror */ 41 typedef struct { 42 char *url; /*!< URL of the mirror */ 43 int preference; /*!< Integer number 1-100 - higher is better */ 44 LrProtocol protocol; /*!< Protocol of this mirror */ 45 } LrInternalMirror; 46 47 typedef GSList LrInternalMirrorlist; 48 49 /** Detect URL protocol. 50 * @param url URL 51 * @return Type of detected protocol 52 */ 53 LrProtocol 54 lr_detect_protocol(const char *url); 55 56 /** Append url to the mirrorlist. 57 * @param list a LrInternalMirrorlist or NULL 58 * @param url the Url 59 * @param urlvars a LrUrlVars or NULL 60 * @return the new start of the LrInternalMirrorlist 61 */ 62 LrInternalMirrorlist * 63 lr_lrmirrorlist_append_url(LrInternalMirrorlist *list, 64 const char *url, 65 LrUrlVars *urlvars); 66 67 /** Append mirrors from mirrorlist to the internal mirrorlist. 68 * @param iml Internal mirrorlist or NULL 69 * @param mirrorlist Mirrorlist 70 * @param urlvars a LrUrlVars or NULL 71 * @return the new start of the LrInternalMirrorlist 72 */ 73 LrInternalMirrorlist * 74 lr_lrmirrorlist_append_mirrorlist(LrInternalMirrorlist *list, 75 LrMirrorlist *mirrorlist, 76 LrUrlVars *urlvars); 77 78 /** Append mirrors from metalink to the internal mirrorlist. 79 * @param iml Internal mirrorlist or NULL 80 * @param metalink Metalink 81 * @param suffix Suffix that shoud be removed from the metalink urls 82 * @param urlvars a LrUrlVars or NULL 83 * @return the new start of the LrInternalMirrorlist 84 */ 85 LrInternalMirrorlist * 86 lr_lrmirrorlist_append_metalink(LrInternalMirrorlist *list, 87 LrMetalink *metalink, 88 const char *suffix, 89 LrUrlVars *urlvars); 90 91 /** Append mirrors from another LrInternalMirrorlist. 92 * @param iml Internal mirrorlist 93 * @param ml Other internal mirrorlist 94 * @return the new start of the LrInternalMirrorlist 95 */ 96 LrInternalMirrorlist * 97 lr_lrmirrorlist_append_lrmirrorlist(LrInternalMirrorlist *list, 98 LrInternalMirrorlist *other); 99 100 /** Return mirror on the given position. 101 * @param list a LrInternalMirrorlist 102 * @param nth the position of the mirror 103 * @return the mirror 104 */ 105 LrInternalMirror * 106 lr_lrmirrorlist_nth(LrInternalMirrorlist *list, 107 unsigned int nth); 108 109 /** Return url of the mirror on at the given position. 110 * @param list a LrInternalMirrorlist 111 * @param nth the position of the mirror 112 * @return the url 113 */ 114 char * 115 lr_lrmirrorlist_nth_url(LrInternalMirrorlist *list, 116 unsigned int nth); 117 118 /** Free LrInternalMirrorlist. 119 * @param list Internal mirrorlist 120 */ 121 void 122 lr_lrmirrorlist_free(LrInternalMirrorlist *list); 123 124 G_END_DECLS 125 126 #endif 127