~ubuntu-branches/ubuntu/trusty/mapnik/trusty

« back to all changes in this revision

Viewing changes to plugins/input/osm/basiccurl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-20 15:39:58 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090520153958-cf6z1ql9zva4y4dq
Tags: 0.6.0-1ubuntu1
* Merge from debian unstable (LP: #378819), remaining changes:
  - debian/control:
    + Change bdeps from python2.5-dev to python-all-dev (>= 2.5)
    + Change XS-Python-Version from 2.5 to >= 2.5
  - debian/rules:
    + Various changes to enable python2.5 and python2.6 builds
* debian/patches/libtool2_2.diff Dropped. Included upsteam.
* Removed quilt support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "basiccurl.h"
 
2
 
 
3
CURL_LOAD_DATA *grab_http_response(const char *url)
 
4
{
 
5
        CURL_LOAD_DATA *data;
 
6
 
 
7
        CURL *curl =  curl_easy_init(); 
 
8
 
 
9
        if(curl)
 
10
        {
 
11
                data = do_grab(curl,url);
 
12
                curl_easy_cleanup(curl);
 
13
                return data;
 
14
        }
 
15
        return NULL;
 
16
}
 
17
 
 
18
CURL_LOAD_DATA *do_grab(CURL *curl,const char *url)
 
19
{
 
20
        CURLcode res;
 
21
        CURL_LOAD_DATA *data = (CURL_LOAD_DATA *)malloc(sizeof(CURL_LOAD_DATA));
 
22
        data->data = NULL;
 
23
        data->nbytes = 0;
 
24
        
 
25
        curl_easy_setopt(curl,CURLOPT_URL,url);
 
26
        curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,response_callback);
 
27
        curl_easy_setopt(curl,CURLOPT_WRITEDATA,data);
 
28
 
 
29
        res=curl_easy_perform(curl);
 
30
 
 
31
        return data;
 
32
}
 
33
 
 
34
size_t response_callback(void *ptr,size_t size,size_t nmemb, void *d)
 
35
{
 
36
        size_t rsize=size*nmemb;
 
37
        CURL_LOAD_DATA *data=(CURL_LOAD_DATA *)d;
 
38
//      fprintf(stderr,"rsize is %d\n", rsize);
 
39
        data->data=(char *)realloc(data->data,(data->nbytes+rsize)
 
40
                                                                                *sizeof(char));
 
41
        memcpy(&(data->data[data->nbytes]),ptr,rsize);
 
42
        data->nbytes += rsize;
 
43
//      fprintf(stderr,"data->nbytes is %d\n", data->nbytes);
 
44
        return rsize;
 
45
}