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