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 | #ifndef WIN32 |
---|
33 | #include <unistd.h> |
---|
34 | #endif |
---|
35 | #include <string.h> |
---|
36 | #include "time.h" |
---|
37 | #ifdef USE_JS |
---|
38 | #ifdef WIN32 |
---|
39 | #define XP_WIN 1 |
---|
40 | #else |
---|
41 | #define XP_UNIX 0 |
---|
42 | #endif |
---|
43 | #include "jsapi.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | |
---|
47 | #ifdef _ULINET |
---|
48 | static char CCookie[1024]; |
---|
49 | #else |
---|
50 | extern char HEADER[3072]; |
---|
51 | extern char CCookie[1024]; |
---|
52 | #endif |
---|
53 | |
---|
54 | #ifdef __cplusplus |
---|
55 | extern "C" { |
---|
56 | #endif |
---|
57 | |
---|
58 | //static pthread_mutex_t hMutexConnect = PTHREAD_MUTEX_INITIALIZER; |
---|
59 | |
---|
60 | struct MemoryStruct { |
---|
61 | char *memory; |
---|
62 | size_t size; |
---|
63 | }; |
---|
64 | |
---|
65 | typedef struct { |
---|
66 | CURLSH *handle; |
---|
67 | struct curl_slist *header; |
---|
68 | char* filename; |
---|
69 | FILE* file; |
---|
70 | size_t size; |
---|
71 | int hasCacheFile; |
---|
72 | int nDataLen; |
---|
73 | int nDataAlloc; |
---|
74 | unsigned char *pabyData; |
---|
75 | unsigned char *mimeType; |
---|
76 | } HINTERNET; |
---|
77 | |
---|
78 | size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data); |
---|
79 | |
---|
80 | size_t content_write_data(void *buffer, size_t size, size_t nmemb, void *data); |
---|
81 | |
---|
82 | size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data); |
---|
83 | |
---|
84 | |
---|
85 | void setProxy(CURL* handle,char* host,long port); |
---|
86 | |
---|
87 | |
---|
88 | #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) |
---|
89 | |
---|
90 | #include <CoreServices/CoreServices.h> |
---|
91 | #include <SystemConfiguration/SystemConfiguration.h> |
---|
92 | char* CFStringToCString(CFStringRef dest,char * buffer); |
---|
93 | OSStatus setProxiesForProtcol(CURL* handle,const char *proto); |
---|
94 | |
---|
95 | #else |
---|
96 | |
---|
97 | //#include <gconf/gconf-client.h> |
---|
98 | int setProxiesForProtcol(CURL* handle,const char *proto); |
---|
99 | |
---|
100 | #endif |
---|
101 | |
---|
102 | |
---|
103 | #define INTERNET_OPEN_TYPE_DIRECT 0 |
---|
104 | #define INTERNET_OPEN_TYPE_PRECONFIG 1 |
---|
105 | #define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 2 |
---|
106 | #define INTERNET_OPEN_TYPE_PROXY 3 |
---|
107 | #ifndef WIN32 |
---|
108 | typedef char* LPCTSTR; |
---|
109 | #endif |
---|
110 | HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags); |
---|
111 | |
---|
112 | void InternetCloseHandle(HINTERNET handle); |
---|
113 | |
---|
114 | #define INTERNET_FLAG_EXISTING_CONNECT 0 |
---|
115 | #define INTERNET_FLAG_HYPERLINK 1 |
---|
116 | #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID 2 |
---|
117 | #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 3 |
---|
118 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP 4 |
---|
119 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS 5 |
---|
120 | #define INTERNET_FLAG_KEEP_CONNECTION 6 |
---|
121 | #define INTERNET_FLAG_NEED_FILE 7 |
---|
122 | #define INTERNET_FLAG_NO_AUTH 8 |
---|
123 | #define INTERNET_FLAG_NO_AUTO_REDIRECT 9 |
---|
124 | #define INTERNET_FLAG_NO_CACHE_WRITE 10 |
---|
125 | //typedef char* LPVOID; |
---|
126 | #ifndef WIN32 |
---|
127 | typedef void* LPVOID; |
---|
128 | typedef void* LPTSTR; |
---|
129 | typedef size_t* LPDWORD; |
---|
130 | #endif |
---|
131 | #ifndef bool |
---|
132 | #define bool int |
---|
133 | #endif |
---|
134 | |
---|
135 | # define CHECK_INET_HANDLE(h) (h.handle != 0) |
---|
136 | |
---|
137 | HINTERNET InternetOpenUrl(HINTERNET hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext); |
---|
138 | |
---|
139 | int freeCookieList(HINTERNET hInternet); |
---|
140 | |
---|
141 | int InternetReadFile(HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead); |
---|
142 | |
---|
143 | bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize); |
---|
144 | |
---|
145 | #ifdef __cplusplus |
---|
146 | } |
---|
147 | #endif |
---|
148 | |
---|
149 | #endif |
---|
150 | |
---|