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