Subversion Repositories Kolibri OS

Rev

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