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 _ULINET |
---|
57 | static char CCookie[MAX_REQ][1024]; |
---|
58 | #else |
---|
59 | /** |
---|
60 | * The cookies found |
---|
61 | */ |
---|
62 | extern char CCookie[MAX_REQ][1024]; |
---|
63 | #endif |
---|
64 | |
---|
65 | #ifdef __cplusplus |
---|
66 | extern "C" { |
---|
67 | #endif |
---|
68 | |
---|
69 | /** |
---|
70 | * Headers storage |
---|
71 | * @see header_write_data |
---|
72 | */ |
---|
73 | struct MemoryStruct { |
---|
74 | char *memory; //!< the memory space to store data |
---|
75 | size_t size; //!< size of the memory space |
---|
76 | }; |
---|
77 | |
---|
78 | /** |
---|
79 | * Individual CURL handler |
---|
80 | */ |
---|
81 | typedef struct { |
---|
82 | CURL *handle; //!< the CURL handler |
---|
83 | struct curl_slist *header; //!< the headers to send |
---|
84 | char* filename; //!< the cached file name |
---|
85 | FILE* file; //!< the file pointer |
---|
86 | unsigned char *pabyData; //!< the downloaded content |
---|
87 | char *url; //!< the url used to access the server |
---|
88 | char *mimeType; //!< the mimeType returned by the server |
---|
89 | char *post; //!< the potential POST XML content |
---|
90 | int hasCacheFile; //!< 1 if we used a cache file |
---|
91 | int nDataLen; //!< the length of the downloaded content |
---|
92 | int nDataAlloc; //!< |
---|
93 | long code; //!< the last received response code |
---|
94 | int id; //!< The position of the element in the queue |
---|
95 | } _HINTERNET; |
---|
96 | |
---|
97 | /** |
---|
98 | * Multiple CURL handlers |
---|
99 | */ |
---|
100 | typedef struct { |
---|
101 | CURLM *handle; //!< the CURLM handler |
---|
102 | _HINTERNET ihandle[MAX_REQ]; //!< individual handlers in the queue |
---|
103 | char *waitingRequests[MAX_REQ]; //!< request in the queue |
---|
104 | char *agent; //!< The User-Agent to use for HTTP request |
---|
105 | int nb; //!< number of element in the queue |
---|
106 | } HINTERNET; |
---|
107 | |
---|
108 | size_t write_data_into(void*,size_t,size_t,void*); |
---|
109 | |
---|
110 | size_t header_write_data(void*,size_t,size_t,void*); |
---|
111 | |
---|
112 | void setProxy(CURL*,char*,long); |
---|
113 | |
---|
114 | #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) |
---|
115 | |
---|
116 | #include <CoreServices/CoreServices.h> |
---|
117 | #include <SystemConfiguration/SystemConfiguration.h> |
---|
118 | char* CFStringToCString(CFStringRef,char*); |
---|
119 | OSStatus setProxiesForProtcol(CURL*,const char*); |
---|
120 | |
---|
121 | #else |
---|
122 | |
---|
123 | //#include <gconf/gconf-client.h> |
---|
124 | int setProxiesForProtcol(CURL*,const char*); |
---|
125 | |
---|
126 | #endif |
---|
127 | |
---|
128 | |
---|
129 | #define INTERNET_OPEN_TYPE_DIRECT 0 |
---|
130 | #define INTERNET_OPEN_TYPE_PRECONFIG 1 |
---|
131 | #define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 2 |
---|
132 | #define INTERNET_OPEN_TYPE_PROXY 3 |
---|
133 | #ifndef WIN32 |
---|
134 | typedef char* LPCTSTR; |
---|
135 | #endif |
---|
136 | HINTERNET InternetOpen(char*,int,char*,char*,int); |
---|
137 | |
---|
138 | int isProtectedHost(const char*,const char*); |
---|
139 | int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*); |
---|
140 | void AddHeaderEntries(HINTERNET*,maps*); |
---|
141 | |
---|
142 | void InternetCloseHandle(HINTERNET*); |
---|
143 | |
---|
144 | #define INTERNET_FLAG_EXISTING_CONNECT 0 |
---|
145 | #define INTERNET_FLAG_HYPERLINK 1 |
---|
146 | #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID 2 |
---|
147 | #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 3 |
---|
148 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP 4 |
---|
149 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS 5 |
---|
150 | #define INTERNET_FLAG_KEEP_CONNECTION 6 |
---|
151 | #define INTERNET_FLAG_NEED_FILE 7 |
---|
152 | #define INTERNET_FLAG_NO_AUTH 8 |
---|
153 | #define INTERNET_FLAG_NO_AUTO_REDIRECT 9 |
---|
154 | #define INTERNET_FLAG_NO_CACHE_WRITE 10 |
---|
155 | //typedef char* LPVOID; |
---|
156 | #ifndef WIN32 |
---|
157 | typedef void* LPVOID; |
---|
158 | typedef void* LPTSTR; |
---|
159 | typedef size_t* LPDWORD; |
---|
160 | #endif |
---|
161 | #ifndef bool |
---|
162 | #define bool int |
---|
163 | #endif |
---|
164 | |
---|
165 | # define CHECK_INET_HANDLE(h) (h.handle != 0) |
---|
166 | |
---|
167 | HINTERNET InternetOpenUrl(HINTERNET*,LPCTSTR,LPCTSTR,size_t,size_t,size_t); |
---|
168 | |
---|
169 | int processDownloads(HINTERNET*); |
---|
170 | |
---|
171 | int freeCookieList(HINTERNET); |
---|
172 | |
---|
173 | int InternetReadFile(_HINTERNET,LPVOID,int,size_t*); |
---|
174 | |
---|
175 | int setBasicAuth(HINTERNET,char*,char*); |
---|
176 | |
---|
177 | #ifdef __cplusplus |
---|
178 | } |
---|
179 | #endif |
---|
180 | |
---|
181 | #endif |
---|
182 | |
---|