[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 |
---|
| 50 | #define false -1 |
---|
| 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 | |
---|
| 68 | struct MemoryStruct { |
---|
[579] | 69 | char *memory; //!< the memory space to store data |
---|
| 70 | size_t size; //!< side of the memory space |
---|
[1] | 71 | }; |
---|
| 72 | |
---|
[579] | 73 | /** |
---|
| 74 | * Individual CURL handler |
---|
| 75 | */ |
---|
[1] | 76 | typedef struct { |
---|
[579] | 77 | CURL *handle; //!< the CURL handler |
---|
| 78 | struct curl_slist *header; //!< the headers to send |
---|
| 79 | char* filename; //!< the cached file name |
---|
| 80 | FILE* file; //!< the file pointer |
---|
| 81 | unsigned char *pabyData; //!< the downloaded content |
---|
| 82 | char *mimeType; //!< the mimeType returned by the server |
---|
| 83 | int hasCacheFile; //!< 1 if we used a cache file |
---|
| 84 | int nDataLen; //!< the length of the downloaded content |
---|
| 85 | int nDataAlloc; //!< |
---|
| 86 | int id; //!< The position of the element in the queue |
---|
[492] | 87 | } _HINTERNET; |
---|
| 88 | |
---|
[579] | 89 | /** |
---|
| 90 | * Multiple CURL handlers |
---|
| 91 | */ |
---|
[492] | 92 | typedef struct { |
---|
[579] | 93 | CURLM *handle; //!< the CURLM handler |
---|
| 94 | _HINTERNET ihandle[MAX_REQ]; //!< individual handlers in the queue |
---|
| 95 | char *waitingRequests[MAX_REQ]; //!< request in the queue |
---|
| 96 | char *agent; //!< The User-Agent to use for HTTP request |
---|
| 97 | int nb; //!< number of element in the queue |
---|
[1] | 98 | } HINTERNET; |
---|
| 99 | |
---|
| 100 | size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data); |
---|
| 101 | |
---|
| 102 | size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data); |
---|
| 103 | |
---|
| 104 | void setProxy(CURL* handle,char* host,long port); |
---|
| 105 | |
---|
| 106 | #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) |
---|
| 107 | |
---|
| 108 | #include <CoreServices/CoreServices.h> |
---|
| 109 | #include <SystemConfiguration/SystemConfiguration.h> |
---|
| 110 | char* CFStringToCString(CFStringRef dest,char * buffer); |
---|
| 111 | OSStatus setProxiesForProtcol(CURL* handle,const char *proto); |
---|
| 112 | |
---|
| 113 | #else |
---|
| 114 | |
---|
| 115 | //#include <gconf/gconf-client.h> |
---|
| 116 | int setProxiesForProtcol(CURL* handle,const char *proto); |
---|
| 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* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags); |
---|
| 129 | |
---|
[492] | 130 | void InternetCloseHandle(HINTERNET* handle); |
---|
[1] | 131 | |
---|
| 132 | #define INTERNET_FLAG_EXISTING_CONNECT 0 |
---|
| 133 | #define INTERNET_FLAG_HYPERLINK 1 |
---|
| 134 | #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID 2 |
---|
| 135 | #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 3 |
---|
| 136 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP 4 |
---|
| 137 | #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS 5 |
---|
| 138 | #define INTERNET_FLAG_KEEP_CONNECTION 6 |
---|
| 139 | #define INTERNET_FLAG_NEED_FILE 7 |
---|
| 140 | #define INTERNET_FLAG_NO_AUTH 8 |
---|
| 141 | #define INTERNET_FLAG_NO_AUTO_REDIRECT 9 |
---|
| 142 | #define INTERNET_FLAG_NO_CACHE_WRITE 10 |
---|
| 143 | //typedef char* LPVOID; |
---|
| 144 | #ifndef WIN32 |
---|
| 145 | typedef void* LPVOID; |
---|
| 146 | typedef void* LPTSTR; |
---|
| 147 | typedef size_t* LPDWORD; |
---|
| 148 | #endif |
---|
| 149 | #ifndef bool |
---|
| 150 | #define bool int |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | # define CHECK_INET_HANDLE(h) (h.handle != 0) |
---|
| 154 | |
---|
[492] | 155 | HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext); |
---|
[1] | 156 | |
---|
[492] | 157 | int processDownloads(HINTERNET* hInternet); |
---|
| 158 | |
---|
[1] | 159 | int freeCookieList(HINTERNET hInternet); |
---|
| 160 | |
---|
[492] | 161 | int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead); |
---|
[1] | 162 | |
---|
| 163 | #ifdef __cplusplus |
---|
| 164 | } |
---|
| 165 | #endif |
---|
| 166 | |
---|
| 167 | #endif |
---|
| 168 | |
---|