ZOO-Project
ulinet.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef _ULINET_H
26 #define _ULINET_H
27 
28 #include "fcgi_stdio.h"
29 #include <stdlib.h>
30 #include <fcntl.h>
31 #include <curl/curl.h>
32 #include "service.h"
33 #ifndef WIN32
34 #include <unistd.h>
35 #endif
36 #include <string.h>
37 #include "time.h"
38 #ifdef USE_JS
39 #ifdef WIN32
40 #define XP_WIN 1
41 #else
42 #define XP_UNIX 0
43 #endif
44 #include "jsapi.h"
45 #endif
46 #ifndef bool
47 #define bool int
48 #endif
49 #ifndef true
50 #define true 1
51 #define false 0
52 #endif
53 
54 #define MAX_REQ 50
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
64  struct MemoryStruct {
65  char *memory;
66  size_t size;
67  };
68 
72  typedef struct {
73  CURL *handle;
74  struct curl_slist *header;
75  char* filename;
76  FILE* file;
77  unsigned char *pabyData;
78  char *url;
79  char *mimeType;
80  char *post;
81  char* cookie;
83  int nDataLen;
84  int nDataAlloc;
85  long code;
86  int id;
87  } _HINTERNET;
88 
92  typedef struct {
93  CURLM *handle;
94  _HINTERNET ihandle[MAX_REQ];
95  char *waitingRequests[MAX_REQ];
96  char *agent;
97  int nb;
98  } HINTERNET;
99 
100  size_t write_data_into(void*,size_t,size_t,void*);
101 
102  size_t header_write_data(void*,size_t,size_t,void*);
103 
104  void setProxy(CURL*,char*,long);
105 
106 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
107 
108 #include <CoreServices/CoreServices.h>
109 #include <SystemConfiguration/SystemConfiguration.h>
110  char* CFStringToCString(CFStringRef,char*);
111  OSStatus setProxiesForProtcol(CURL*,const char*);
112 
113 #else
114 
115 //#include <gconf/gconf-client.h>
116  int setProxiesForProtcol(CURL*,const char*);
117 
118 #endif
119 
120 
121 #define INTERNET_OPEN_TYPE_DIRECT 0
122 #define INTERNET_OPEN_TYPE_PRECONFIG 1
123 #define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 2
124 #define INTERNET_OPEN_TYPE_PROXY 3
125 #ifndef WIN32
126 typedef char* LPCTSTR;
127 #endif
128  HINTERNET InternetOpen(char*,int,char*,char*,int);
129 
130  int isProtectedHost(const char*,const char*);
131  int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*);
133 
135 
136 #define INTERNET_FLAG_EXISTING_CONNECT 0
137 #define INTERNET_FLAG_HYPERLINK 1
138 #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID 2
139 #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 3
140 #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP 4
141 #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS 5
142 #define INTERNET_FLAG_KEEP_CONNECTION 6
143 #define INTERNET_FLAG_NEED_FILE 7
144 #define INTERNET_FLAG_NO_AUTH 8
145 #define INTERNET_FLAG_NO_AUTO_REDIRECT 9
146 #define INTERNET_FLAG_NO_CACHE_WRITE 10
147 //typedef char* LPVOID;
148 #ifndef WIN32
149  typedef void* LPVOID;
150  typedef void* LPTSTR;
151  typedef size_t* LPDWORD;
152 #endif
153 #ifndef bool
154 #define bool int
155 #endif
156 
157 # define CHECK_INET_HANDLE(h) (h.handle != 0)
158 
159  HINTERNET InternetOpenUrl(HINTERNET*,LPCTSTR,LPCTSTR,size_t,size_t,size_t);
160 
162 
164 
165  int InternetReadFile(_HINTERNET,LPVOID,int,size_t*);
166 
167  int setBasicAuth(HINTERNET,char*,char*);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif
174 
int setProxiesForProtcol(CURL *, const char *)
MACOSX.
Definition: ulinet.c:191
char * mimeType
the mimeType returned by the server
Definition: ulinet.h:79
Individual CURL handler.
Definition: ulinet.h:72
HINTERNET InternetOpen(char *, int, char *, char *, int)
Create a HINTERNET.
Definition: ulinet.c:210
int processDownloads(HINTERNET *)
Download all opened urls in the queue.
Definition: ulinet.c:465
CURLM * handle
the CURLM handler
Definition: ulinet.h:93
void InternetCloseHandle(HINTERNET *)
Close a HINTERNET connection and free allocated resources.
Definition: ulinet.c:322
char * post
the potential POST XML content
Definition: ulinet.h:80
char * agent
The User-Agent to use for HTTP request.
Definition: ulinet.h:96
int hasCacheFile
1 if we used a cache file
Definition: ulinet.h:82
unsigned char * pabyData
the downloaded content
Definition: ulinet.h:77
int nb
number of element in the queue
Definition: ulinet.h:97
int freeCookieList(HINTERNET)
Initialize the cookie for a specific index (hInternet.nb)
Definition: ulinet.c:491
char * filename
the cached file name
Definition: ulinet.h:75
int isProtectedHost(const char *, const char *)
Verify if a host is protected (appear in [security] > hosts)
Definition: ulinet.c:246
size_t * LPDWORD
Definition: ulinet.h:151
long code
the last received response code
Definition: ulinet.h:85
size_t write_data_into(void *, size_t, size_t, void *)
Write the downloaded content to a _HINTERNET structure.
Definition: ulinet.c:43
int InternetReadFile(_HINTERNET, LPVOID, int, size_t *)
Copy a downloaded content.
Definition: ulinet.c:510
linked list of map pointer
Definition: main_conf_read.y:243
size_t header_write_data(void *, size_t, size_t, void *)
In case of presence of "Set-Cookie" in the headers red, store the cookie identifier in cookie...
Definition: ulinet.c:81
int setBasicAuth(HINTERNET, char *, char *)
Use basic authentication for accessing a resource.
Definition: ulinet.c:557
int nDataLen
the length of the downloaded content
Definition: ulinet.h:83
#define MAX_REQ
Definition: ulinet.h:54
int id
The position of the element in the queue.
Definition: ulinet.h:86
CURL * handle
the CURL handler
Definition: ulinet.h:73
int AddMissingHeaderEntry(_HINTERNET *, const char *, const char *)
Add missing headers to an existing _HINTERNET.
Definition: ulinet.c:228
char * cookie
The potential Cookie returned by the server.
Definition: ulinet.h:81
struct curl_slist * header
the headers to send
Definition: ulinet.h:74
char * url
the url used to access the server
Definition: ulinet.h:78
char * LPCTSTR
Definition: ulinet.h:126
char * memory
the memory space to store data
Definition: ulinet.h:65
void setProxy(CURL *, char *, long)
Define the proxy to use for a CURL handler.
Definition: ulinet.c:111
Headers storage.
Definition: ulinet.h:64
void * LPVOID
Definition: ulinet.h:149
void * LPTSTR
Definition: ulinet.h:150
void AddHeaderEntries(HINTERNET *, maps *)
Add headers defined in [security] > attributes to an existing HINTERNET.
Definition: ulinet.c:276
Multiple CURL handlers.
Definition: ulinet.h:92
int nDataAlloc
Definition: ulinet.h:84
FILE * file
the file pointer
Definition: ulinet.h:76
HINTERNET InternetOpenUrl(HINTERNET *, LPCTSTR, LPCTSTR, size_t, size_t, size_t)
Create a new element in the download queue.
Definition: ulinet.c:365
size_t size
size of the memory space
Definition: ulinet.h:66