Version: 0.6.0
curl.h
1 /******************************************************************************
2  * Project: wxGIS (GIS Catalog)
3  * Purpose: cURL class. This is smart clas for cURL handler
4  * Author: Bishop (aka Baryshnikov Dmitriy), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2008,2010,2011 Bishop
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include <curl/curl.h>
24 #include <stdlib.h>
25 
26 #include "wxgis/datasource/datasource.h"
27 
28 typedef struct _perform_result
29 {
30  wxString sHead, sBody;
31  unsigned int iSize;
32  bool IsValid;
34 
35 class WXDLLIMPEXP_GIS_DS wxGISCurl
36 {
37 public:
38  wxGISCurl(wxString proxy, wxString sHeaders, int dnscachetimeout, int timeout, int conntimeout);
39  virtual ~wxGISCurl(void);
40  bool IsValid(void){return m_bIsValid;};
41 private:
42  wxString m_sHeaders;
43  bool m_bIsValid, m_bUseProxy;
44  CURL *curl;
45  CURLcode res;
46  struct MemoryStruct
47  {
48  char *memory;
49  size_t size;
50  };
51  struct curl_slist *slist;
52  struct MemoryStruct bodystruct;
53  struct MemoryStruct headstruct;
54 
55  static void *myrealloc(void *ptr, size_t size)
56  {
57  /* There might be a realloc() out there that doesn't like reallocing
58  NULL pointers, so we take care of it here */
59  if (ptr)
60  return realloc(ptr, size);
61  else
62  return malloc(size);
63  }
64 
65  static size_t write_data(void *ptr, size_t size, size_t nmemb, void *data)
66  {
67  size_t realsize = size * nmemb;
68  struct MemoryStruct *mem = (struct MemoryStruct *)data;
69 
70  mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
71  if (mem->memory)
72  {
73  memcpy(&(mem->memory[mem->size]), ptr, realsize);
74  mem->size += realsize;
75  mem->memory[mem->size] = 0;
76  }
77  return realsize;
78  }
79 
80 public:
81  virtual void SetRestrictions(wxString sRestrict);
82  virtual void AppendHeader(wxString sHeadStr);
83  virtual void SetDefaultHeader(void);
84  virtual void FollowLocation(bool bSet, unsigned short iMaxRedirs);
85  virtual PERFORMRESULT Get(wxString sURL);
86  virtual bool GetFile(wxString sURL, wxString sPath);
87  virtual PERFORMRESULT Post(wxString sURL, wxString sPostData);
88 };
Definition: curl.h:28
Definition: curl.h:35