Subversion Repositories Kolibri OS

Rev

Rev 5725 | Rev 5727 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5725 Rev 5726
Line 7... Line 7...
7
#include "collection.h"
7
#include "collection.h"
8
#include "http.h"
8
#include "http.h"
Line 9... Line 9...
9
 
9
 
Line 10... Line -...
10
#define BUFFSIZE  (64*1024)
-
 
11
 
-
 
12
int http_load_mem(char *buf, const char *url)
-
 
13
{
-
 
14
    http_t *http;
-
 
Line 15... Line 10...
15
    int offset = 0;
10
#define BUFFSIZE  (64*1024)
16
    int count;
-
 
17
 
-
 
18
//    asm volatile("int3");
-
 
19
    http = http_get(url, NULL,FLAG_STREAM|FLAG_REUSE_BUFFER, NULL);
-
 
20
    if(http == NULL)
-
 
21
        goto err_get;
11
 
22
 
-
 
23
    do
-
 
24
    {
-
 
25
//        delay(100);
-
 
26
        if(http_receive_with_retry(http, 500)==0)
-
 
27
        {
-
 
28
            if(http->flags & 0xffff0000)
-
 
29
                goto err_http;
-
 
30
 
-
 
31
            count = http->content_received - offset;
12
 
32
            if(count == 0)
-
 
33
                continue;
-
 
34
            memcpy(buf+offset, http->content_ptr, count);
-
 
35
            offset = http->content_received;
-
 
36
        }
-
 
37
        else goto err_http;
-
 
38
 
-
 
39
    }while( (http->flags & FLAG_GOT_ALL_DATA) == 0);
-
 
40
 
-
 
41
    if(http->content_ptr)
-
 
42
        user_free(http->content_ptr);
-
 
43
    http_free(http);
-
 
44
 
-
 
45
    return offset;
-
 
46
 
-
 
47
err_http:
-
 
48
    if(http->content_ptr)
-
 
49
        user_free(http->content_ptr);
13
char *make_url(const char *name)
50
    http_free(http);
14
{
51
 
15
    static char url_buf[128] = "http://ftp.kolibrios.org/users/Serge/new/OS/";
52
    printf("HTTP receive failed\n");
-
 
53
    return offset;
-
 
54
 
-
 
Line -... Line 16...
-
 
16
    strcpy(&url_buf[44], name);
-
 
17
    return url_buf;
-
 
18
};
-
 
19
 
-
 
20
char *make_cache_path(const char *path)
55
err_get:
21
{
Line 56... Line 22...
56
    printf("HTTP GET failed\n");
22
    static char path_buf[64] = "/tmp0/1/";
57
    return offset;
23
    strcpy(&path_buf[8], path);
58
 
24
    return path_buf;
59
}
25
};
Line 145... Line 111...
145
 
111
 
146
 
112
 
147
int main(int argc, char *argv[])
113
int main(int argc, char *argv[])
-
 
114
{
Line 148... Line 115...
148
{
115
    int   count;
149
    int   count;
116
    char *cache_path;
Line -... Line 117...
-
 
117
 
-
 
118
    if(http_init())
150
 
119
        goto err_init;
Line 151... Line 120...
151
    if(http_init())
120
 
152
        goto err_init;
121
    cache_path = make_cache_path("packages.xml");
153
 
122
 
154
    count = http_load_file("/tmp0/1/packages.xml", "http://ftp.kolibrios.org/users/Serge/new/OS/packages.xml");
123
    count = http_load_file(cache_path, make_url("packages.xml"));
Line 155... Line 124...
155
 
124
 
Line 156... Line 125...
156
    if(count)
125
    if(count)
157
    {
126
    {
158
        collection_t *collection;
127
        collection_t *collection;
Line 159... Line 128...
159
        pkg_group_t *gr;
128
        pkg_group_t *gr;
160
 
129
 
161
        collection = load_collection_file("/tmp0/1/packages.xml");
130
        collection = load_collection_file(cache_path);
-
 
131
 
-
 
132
        list_for_each_entry(gr, &collection->groups, list)
-
 
133
        {
162
 
134
            package_t   *pkg;
163
        list_for_each_entry(gr, &collection->groups, list)
135
 
164
        {
136
            list_for_each_entry(pkg, &gr->packages, list)
Line 165... Line 137...
165
            package_t   *pkg;
137
            {