Rev 5728 | Rev 5731 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5728 | serge | 1 | #include |
5725 | serge | 2 | #include |
3 | #include |
||
4 | #include |
||
5 | #include |
||
6 | #include |
||
7 | #include |
||
5728 | serge | 8 | #include |
9 | |||
10 | #include "package.h" |
||
5725 | serge | 11 | #include "http.h" |
12 | |||
13 | #define BUFFSIZE (64*1024) |
||
14 | |||
5726 | serge | 15 | |
16 | char *make_url(const char *name) |
||
5725 | serge | 17 | { |
5726 | serge | 18 | static char url_buf[128] = "http://ftp.kolibrios.org/users/Serge/new/OS/"; |
19 | strcpy(&url_buf[44], name); |
||
20 | return url_buf; |
||
21 | }; |
||
5725 | serge | 22 | |
5727 | serge | 23 | char *make_tmp_path(const char *path) |
5726 | serge | 24 | { |
25 | static char path_buf[64] = "/tmp0/1/"; |
||
26 | strcpy(&path_buf[8], path); |
||
27 | return path_buf; |
||
28 | }; |
||
5725 | serge | 29 | |
5727 | serge | 30 | char *make_cache_path(const char *path) |
31 | { |
||
32 | static char path_buf[64] = "/kolibrios/kpm/cache/"; |
||
33 | strcpy(&path_buf[21], path); |
||
34 | return path_buf; |
||
35 | }; |
||
36 | |||
5725 | serge | 37 | int http_load_file(const char *path, const char *url) |
38 | { |
||
39 | http_t *http; |
||
40 | int received = 0; |
||
41 | int offset = 0; |
||
42 | int tail; |
||
43 | char *buf; |
||
44 | int fd; |
||
45 | int i; |
||
46 | |||
47 | buf = user_alloc(BUFFSIZE); |
||
48 | for(i = 0; i < 16; i++) |
||
49 | buf[i*4096] = 0; |
||
50 | |||
51 | fd = open(path, O_CREAT|O_WRONLY); |
||
52 | if(fd == -1) |
||
53 | { |
||
54 | user_free(buf); |
||
55 | return 0; |
||
56 | }; |
||
57 | |||
58 | http = http_get(url, NULL,FLAG_STREAM|FLAG_REUSE_BUFFER, NULL); |
||
59 | if(http == NULL) |
||
60 | goto err_get; |
||
61 | |||
62 | do |
||
63 | { |
||
64 | if(http_receive_with_retry(http, 500) == 0) |
||
65 | { |
||
66 | int count; |
||
67 | |||
5729 | serge | 68 | // if(http->flags & 0xffff0000) |
69 | // break; |
||
5725 | serge | 70 | |
71 | count = http->content_received - received; |
||
72 | if(count+offset <= BUFFSIZE) |
||
73 | { |
||
74 | memcpy(buf+offset, http->content_ptr, count); |
||
75 | offset+= count; |
||
5727 | serge | 76 | } else |
5725 | serge | 77 | { |
78 | tail = count+offset-BUFFSIZE; |
||
79 | count = BUFFSIZE - offset; |
||
80 | if(count) |
||
81 | { |
||
82 | memcpy(buf+offset, http->content_ptr, count); |
||
83 | offset = 0; |
||
84 | }; |
||
85 | |||
86 | |||
87 | |||
88 | |||
89 | { |
||
90 | memcpy(buf, http->content_ptr+count, tail); |
||
91 | offset = tail; |
||
92 | } |
||
93 | } |
||
94 | received = http->content_received; |
||
95 | } |
||
96 | else break; |
||
97 | |||
98 | |||
99 | |||
100 | |||
101 | { |
||
102 | write(fd, buf, offset); |
||
103 | } |
||
104 | |||
105 | |||
106 | close(fd); |
||
107 | |||
108 | |||
109 | user_free(http->content_ptr); |
||
110 | http_free(http); |
||
111 | |||
112 | |||
113 | |||
114 | |||
115 | |||
116 | |||
117 | printf("HTTP GET failed\n"); |
||
118 | return received; |
||
119 | } |
||
120 | |||
121 | |||
122 | |||
123 | { |
||
124 | int count; |
||
125 | char *cache_path; |
||
5726 | serge | 126 | char *tmp_path; |
5727 | serge | 127 | |
5725 | serge | 128 | |
129 | goto err_init; |
||
130 | |||
131 | |||
5727 | serge | 132 | |
5725 | serge | 133 | |
5727 | serge | 134 | |
5726 | serge | 135 | |
5725 | serge | 136 | { |
137 | collection_t *collection; |
||
138 | package_t *pkg; |
||
5727 | serge | 139 | LIST_HEAD(install_list); |
140 | LIST_HEAD(download_list); |
||
141 | |||
5725 | serge | 142 | |
5727 | serge | 143 | |
5725 | serge | 144 | |
5727 | serge | 145 | { |
5725 | serge | 146 | if(build_download_list(&download_list, &install_list)) |
5727 | serge | 147 | do_download(&download_list); |
5728 | serge | 148 | |
149 | |||
150 | remove_missing_packages(&install_list, &download_list); |
||
5729 | serge | 151 | |
5728 | serge | 152 | |
153 | printf("install package %s-%s\n", pkg->name, pkg->version); |
||
154 | |||
5729 | serge | 155 | |
156 | |||
157 | |||
158 | }; |
||
5725 | serge | 159 | } |
160 | |||
161 | |||
162 | |||
163 | |||
164 | printf("HTTP library initialization failed\n"); |
||
165 | return -1; |
||
166 | } |
||
167 | |||
5728 | serge | 168 | |
169 | { |
||
170 | pkg_group_t *gr; |
||
171 | int count = 0; |
||
172 | |||
173 | |||
174 | { |
||
175 | package_t *pkg, *tmp; |
||
176 | |||
177 | |||
178 | { |
||
179 | pkg = (package_t*)malloc(sizeof(package_t)); |
||
180 | |||
181 | |||
182 | pkg->id = tmp->id; |
||
183 | pkg->name = strdup(tmp->name); |
||
184 | pkg->version = strdup(tmp->version); |
||
185 | pkg->filename = strdup(tmp->filename); |
||
186 | pkg->description = strdup(tmp->description); |
||
187 | list_add_tail(&pkg->list, list); |
||
188 | count++; |
||
189 | } |
||
190 | }; |
||
191 | return count; |
||
192 | } |
||
193 | |||
194 | |||
195 | { |
||
196 | int count = 0; |
||
197 | char *cache_path; |
||
198 | package_t *pkg, *tmp; |
||
199 | fileinfo_t info; |
||
200 | list_for_each_entry(tmp, src, list) |
||
201 | { |
||
202 | cache_path = make_cache_path(tmp->filename); |
||
203 | |||
204 | |||
205 | { |
||
206 | pkg = (package_t*)malloc(sizeof(package_t)); |
||
207 | |||
208 | |||
209 | pkg->id = tmp->id; |
||
210 | pkg->name = strdup(tmp->name); |
||
211 | pkg->version = strdup(tmp->version); |
||
212 | pkg->filename = strdup(tmp->filename); |
||
213 | pkg->description = strdup(tmp->description); |
||
214 | list_add_tail(&pkg->list, download); |
||
215 | count++; |
||
216 | }; |
||
217 | } |
||
218 | return count; |
||
219 | }; |
||
220 | |||
221 | |||
222 | { |
||
223 | package_t *pkg, *tmp; |
||
224 | char *cache_path; |
||
225 | int count; |
||
226 | |||
227 | |||
228 | { |
||
229 | printf("package %s-%s\n", pkg->name, pkg->version); |
||
230 | cache_path = make_cache_path(pkg->filename); |
||
231 | count = http_load_file(cache_path, make_url(pkg->filename)); |
||
232 | printf("%s loaded %d bytes\n",cache_path, count); |
||
233 | if( !test_archive(cache_path)) |
||
234 | list_del_pkg(pkg); |
||
235 | else |
||
5729 | serge | 236 | unlink(cache_path); |
237 | }; |
||
5728 | serge | 238 | } |
239 | |||
240 | |||
5729 | serge | 241 | { |
5728 | serge | 242 | package_t *mpkg, *mtmp, *ipkg, *itmp; |
243 | |||
244 | |||
245 | { |
||
246 | list_for_each_entry_safe(ipkg, itmp, install, list) |
||
247 | { |
||
248 | if(ipkg->id == mpkg->id) |
||
249 | { |
||
250 | printf("skip missing package %s-%s\n", ipkg->name, ipkg->version); |
||
5729 | serge | 251 | list_del_pkg(ipkg); |
5728 | serge | 252 | }; |
253 | } |
||
254 | list_del_pkg(mpkg); |
||
255 | }; |
||
256 | };=>> |
||
257 |