| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fetch.c,v 1.18 2009/02/05 23:29:14 joerg Exp $ */ | | 1 | /* $NetBSD: fetch.c,v 1.19 2009/08/11 20:48:06 joerg Exp $ */ |
2 | /*- | | 2 | /*- |
3 | * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav | | 3 | * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav |
4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org> | | 4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer | | 11 | * notice, this list of conditions and the following disclaimer |
12 | * in this position and unchanged. | | 12 | * in this position and unchanged. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -70,29 +70,27 @@ static struct fetcherr url_errlist[] = { | | | @@ -70,29 +70,27 @@ static struct fetcherr url_errlist[] = { |
70 | }; | | 70 | }; |
71 | | | 71 | |
72 | | | 72 | |
73 | /*** Public API **************************************************************/ | | 73 | /*** Public API **************************************************************/ |
74 | | | 74 | |
75 | /* | | 75 | /* |
76 | * Select the appropriate protocol for the URL scheme, and return a | | 76 | * Select the appropriate protocol for the URL scheme, and return a |
77 | * read-only stream connected to the document referenced by the URL. | | 77 | * read-only stream connected to the document referenced by the URL. |
78 | * Also fill out the struct url_stat. | | 78 | * Also fill out the struct url_stat. |
79 | */ | | 79 | */ |
80 | fetchIO * | | 80 | fetchIO * |
81 | fetchXGet(struct url *URL, struct url_stat *us, const char *flags) | | 81 | fetchXGet(struct url *URL, struct url_stat *us, const char *flags) |
82 | { | | 82 | { |
83 | int direct; | | | |
84 | | | 83 | |
85 | direct = CHECK_FLAG('d'); | | | |
86 | if (us != NULL) { | | 84 | if (us != NULL) { |
87 | us->size = -1; | | 85 | us->size = -1; |
88 | us->atime = us->mtime = 0; | | 86 | us->atime = us->mtime = 0; |
89 | } | | 87 | } |
90 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) | | 88 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) |
91 | return (fetchXGetFile(URL, us, flags)); | | 89 | return (fetchXGetFile(URL, us, flags)); |
92 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) | | 90 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) |
93 | return (fetchXGetFTP(URL, us, flags)); | | 91 | return (fetchXGetFTP(URL, us, flags)); |
94 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) | | 92 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) |
95 | return (fetchXGetHTTP(URL, us, flags)); | | 93 | return (fetchXGetHTTP(URL, us, flags)); |
96 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) | | 94 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) |
97 | return (fetchXGetHTTP(URL, us, flags)); | | 95 | return (fetchXGetHTTP(URL, us, flags)); |
98 | url_seterr(URL_BAD_SCHEME); | | 96 | url_seterr(URL_BAD_SCHEME); |
| @@ -106,78 +104,72 @@ fetchXGet(struct url *URL, struct url_st | | | @@ -106,78 +104,72 @@ fetchXGet(struct url *URL, struct url_st |
106 | fetchIO * | | 104 | fetchIO * |
107 | fetchGet(struct url *URL, const char *flags) | | 105 | fetchGet(struct url *URL, const char *flags) |
108 | { | | 106 | { |
109 | return (fetchXGet(URL, NULL, flags)); | | 107 | return (fetchXGet(URL, NULL, flags)); |
110 | } | | 108 | } |
111 | | | 109 | |
112 | /* | | 110 | /* |
113 | * Select the appropriate protocol for the URL scheme, and return a | | 111 | * Select the appropriate protocol for the URL scheme, and return a |
114 | * write-only stream connected to the document referenced by the URL. | | 112 | * write-only stream connected to the document referenced by the URL. |
115 | */ | | 113 | */ |
116 | fetchIO * | | 114 | fetchIO * |
117 | fetchPut(struct url *URL, const char *flags) | | 115 | fetchPut(struct url *URL, const char *flags) |
118 | { | | 116 | { |
119 | int direct; | | | |
120 | | | 117 | |
121 | direct = CHECK_FLAG('d'); | | | |
122 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) | | 118 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) |
123 | return (fetchPutFile(URL, flags)); | | 119 | return (fetchPutFile(URL, flags)); |
124 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) | | 120 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) |
125 | return (fetchPutFTP(URL, flags)); | | 121 | return (fetchPutFTP(URL, flags)); |
126 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) | | 122 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) |
127 | return (fetchPutHTTP(URL, flags)); | | 123 | return (fetchPutHTTP(URL, flags)); |
128 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) | | 124 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) |
129 | return (fetchPutHTTP(URL, flags)); | | 125 | return (fetchPutHTTP(URL, flags)); |
130 | url_seterr(URL_BAD_SCHEME); | | 126 | url_seterr(URL_BAD_SCHEME); |
131 | return (NULL); | | 127 | return (NULL); |
132 | } | | 128 | } |
133 | | | 129 | |
134 | /* | | 130 | /* |
135 | * Select the appropriate protocol for the URL scheme, and return the | | 131 | * Select the appropriate protocol for the URL scheme, and return the |
136 | * size of the document referenced by the URL if it exists. | | 132 | * size of the document referenced by the URL if it exists. |
137 | */ | | 133 | */ |
138 | int | | 134 | int |
139 | fetchStat(struct url *URL, struct url_stat *us, const char *flags) | | 135 | fetchStat(struct url *URL, struct url_stat *us, const char *flags) |
140 | { | | 136 | { |
141 | int direct; | | | |
142 | | | 137 | |
143 | direct = CHECK_FLAG('d'); | | | |
144 | if (us != NULL) { | | 138 | if (us != NULL) { |
145 | us->size = -1; | | 139 | us->size = -1; |
146 | us->atime = us->mtime = 0; | | 140 | us->atime = us->mtime = 0; |
147 | } | | 141 | } |
148 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) | | 142 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) |
149 | return (fetchStatFile(URL, us, flags)); | | 143 | return (fetchStatFile(URL, us, flags)); |
150 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) | | 144 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) |
151 | return (fetchStatFTP(URL, us, flags)); | | 145 | return (fetchStatFTP(URL, us, flags)); |
152 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) | | 146 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) |
153 | return (fetchStatHTTP(URL, us, flags)); | | 147 | return (fetchStatHTTP(URL, us, flags)); |
154 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) | | 148 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) |
155 | return (fetchStatHTTP(URL, us, flags)); | | 149 | return (fetchStatHTTP(URL, us, flags)); |
156 | url_seterr(URL_BAD_SCHEME); | | 150 | url_seterr(URL_BAD_SCHEME); |
157 | return (-1); | | 151 | return (-1); |
158 | } | | 152 | } |
159 | | | 153 | |
160 | /* | | 154 | /* |
161 | * Select the appropriate protocol for the URL scheme, and return a | | 155 | * Select the appropriate protocol for the URL scheme, and return a |
162 | * list of files in the directory pointed to by the URL. | | 156 | * list of files in the directory pointed to by the URL. |
163 | */ | | 157 | */ |
164 | int | | 158 | int |
165 | fetchList(struct url_list *ue, struct url *URL, const char *pattern, | | 159 | fetchList(struct url_list *ue, struct url *URL, const char *pattern, |
166 | const char *flags) | | 160 | const char *flags) |
167 | { | | 161 | { |
168 | int direct; | | | |
169 | | | 162 | |
170 | direct = CHECK_FLAG('d'); | | | |
171 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) | | 163 | if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) |
172 | return (fetchListFile(ue, URL, pattern, flags)); | | 164 | return (fetchListFile(ue, URL, pattern, flags)); |
173 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) | | 165 | else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) |
174 | return (fetchListFTP(ue, URL, pattern, flags)); | | 166 | return (fetchListFTP(ue, URL, pattern, flags)); |
175 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) | | 167 | else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) |
176 | return (fetchListHTTP(ue, URL, pattern, flags)); | | 168 | return (fetchListHTTP(ue, URL, pattern, flags)); |
177 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) | | 169 | else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0) |
178 | return (fetchListHTTP(ue, URL, pattern, flags)); | | 170 | return (fetchListHTTP(ue, URL, pattern, flags)); |
179 | url_seterr(URL_BAD_SCHEME); | | 171 | url_seterr(URL_BAD_SCHEME); |
180 | return -1; | | 172 | return -1; |
181 | } | | 173 | } |
182 | | | 174 | |
183 | /* | | 175 | /* |