ZOO-Project
ulinet.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright 2008-2019 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 1
27 
28 #ifdef USE_JS
29 #ifdef WIN32
30 #define XP_WIN 1
31 #else
32 #define XP_UNIX 0
33 #endif
34 #include "jsapi.h"
35 #endif
36 #include <stdlib.h>
37 #include <fcntl.h>
38 #include <curl/curl.h>
39 #include <curl/curlver.h>
40 #include "service.h"
41 #ifndef WIN32
42 #include <unistd.h>
43 #endif
44 #include <string.h>
45 #include "time.h"
46 #ifndef __cplusplus
47 // knut: see new def of bool in service.h
48 //#ifndef bool
49 //#define bool int
50 //#endif
51 //#ifndef true
52 //#define true 1
53 //#define false 0
54 //#endif
55 #endif
56 
57 #define MAX_REQ 50
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
67  struct MemoryStruct {
68  char *memory;
69  size_t size;
70  };
71 
75  typedef struct {
76  long code;
78  int id;
79  size_t nDataLen;
80  size_t nDataAlloc;
81  CURL *handle;
82  struct curl_slist *header;
83  char* filename;
84  FILE* file;
85  unsigned char *pabyData;
86  char *url;
87  char *mimeType;
88  char *post;
89  char* cookie;
90  char* location;
91  } _HINTERNET;
92 
96  typedef struct {
97  int nb;
98  CURLM *handle;
99  _HINTERNET ihandle[MAX_REQ];
100  char *waitingRequests[MAX_REQ];
101  char *agent;
102  } HINTERNET;
103 
104  size_t write_data_into(void*,size_t,size_t,void*);
105 
106  size_t write_data_into_file(void*,size_t,size_t,void*);
107 
108  size_t header_write_data(void*,size_t,size_t,void*);
109 
110  void setProxy(CURL*,char*,long);
111 
112 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
113 
114 #include <CoreServices/CoreServices.h>
115 #include <SystemConfiguration/SystemConfiguration.h>
116  char* CFStringToCString(CFStringRef,char*);
117  OSStatus setProxiesForProtcol(CURL*,const char*);
118 
119 #else
120 
121 //#include <gconf/gconf-client.h>
122  int setProxiesForProtcol(CURL*,const char*);
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
134  HINTERNET InternetOpen(char*,int,char*,char*,int);
135 
136  char* getProvenance(maps*,const char*);
137  int isProtectedHost(const char*,const char*);
138  int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*);
140 
142 
143 #define INTERNET_FLAG_EXISTING_CONNECT 0
144 #define INTERNET_FLAG_HYPERLINK 1
145 #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID 2
146 #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 3
147 #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP 4
148 #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS 5
149 #define INTERNET_FLAG_KEEP_CONNECTION 6
150 #define INTERNET_FLAG_NEED_FILE 7
151 #define INTERNET_FLAG_NO_AUTH 8
152 #define INTERNET_FLAG_NO_AUTO_REDIRECT 9
153 #define INTERNET_FLAG_NO_CACHE_WRITE 10
154 //typedef char* LPVOID;
155 #ifndef WIN32
156  typedef void* LPVOID;
157  typedef void* LPTSTR;
158  typedef size_t* LPDWORD;
159 #endif
160 // knut: see new definition of bool in service.h
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,const maps*);
168 
170 
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 
_HINTERNET::header
struct curl_slist * header
the headers to send
Definition: ulinet.h:82
setProxiesForProtcol
int setProxiesForProtcol(CURL *, const char *)
MACOSX.
Definition: ulinet.c:236
InternetReadFile
int InternetReadFile(_HINTERNET, LPVOID, int, size_t *)
Copy a downloaded content.
Definition: ulinet.c:690
HINTERNET::nb
int nb
number of element in the queue
Definition: ulinet.h:97
InternetCloseHandle
void InternetCloseHandle(HINTERNET *)
Close a HINTERNET connection and free allocated resources.
Definition: ulinet.c:423
getProvenance
char * getProvenance(maps *, const char *)
Verify if the URL should use a shared cache or not.
Definition: ulinet.c:288
HINTERNET::handle
CURLM * handle
the CURLM handler
Definition: ulinet.h:98
service.h
MemoryStruct::size
size_t size
size of the memory space
Definition: ulinet.h:69
_HINTERNET::post
char * post
the potential POST XML content
Definition: ulinet.h:88
freeCookieList
int freeCookieList(HINTERNET)
Initialize the cookie for a specific index (hInternet.nb)
Definition: ulinet.c:673
AddHeaderEntries
void AddHeaderEntries(HINTERNET *, maps *)
Add headers defined in [security] > attributes to an existing HINTERNET.
Definition: ulinet.c:377
write_data_into
size_t write_data_into(void *, size_t, size_t, void *)
Write the downloaded content to a _HINTERNET structure.
Definition: ulinet.c:44
_HINTERNET::hasCacheFile
int hasCacheFile
1 if we used a cache file
Definition: ulinet.h:77
_HINTERNET::pabyData
unsigned char * pabyData
the downloaded content
Definition: ulinet.h:85
isProtectedHost
int isProtectedHost(const char *, const char *)
Verify if a host is protected (appear in [security] > hosts)
Definition: ulinet.c:344
InternetOpen
HINTERNET InternetOpen(char *, int, char *, char *, int)
Create a HINTERNET.
Definition: ulinet.c:255
header_write_data
size_t header_write_data(void *, size_t, size_t, void *)
In case of presence of "Set-Cookie" in the headers red, store the cookie identifier in cookie.
Definition: ulinet.c:110
_HINTERNET::id
int id
The position of the element in the queue.
Definition: ulinet.h:78
LPDWORD
size_t * LPDWORD
Definition: ulinet.h:158
processDownloads
int processDownloads(HINTERNET *)
Download all opened urls in the queue.
Definition: ulinet.c:609
LPVOID
void * LPVOID
Definition: ulinet.h:156
_HINTERNET::filename
char * filename
the cached file name
Definition: ulinet.h:83
_HINTERNET::mimeType
char * mimeType
the mimeType returned by the server
Definition: ulinet.h:87
_HINTERNET::code
long code
the last received response code
Definition: ulinet.h:76
MemoryStruct
Headers storage.
Definition: ulinet.h:67
MAX_REQ
#define MAX_REQ
Definition: ulinet.h:57
maps
linked list of map pointer
Definition: service.h:678
setBasicAuth
int setBasicAuth(HINTERNET, char *, char *)
Use basic authentication for accessing a resource.
Definition: ulinet.c:741
_HINTERNET::file
FILE * file
the file pointer
Definition: ulinet.h:84
_HINTERNET
Individual CURL handler.
Definition: ulinet.h:75
_HINTERNET::cookie
char * cookie
The potential Cookie returned by the server.
Definition: ulinet.h:89
LPCTSTR
char * LPCTSTR
Definition: ulinet.h:132
_HINTERNET::nDataAlloc
size_t nDataAlloc
Definition: ulinet.h:80
_HINTERNET::nDataLen
size_t nDataLen
the length of the downloaded content
Definition: ulinet.h:79
LPTSTR
void * LPTSTR
Definition: ulinet.h:157
_HINTERNET::url
char * url
the url used to access the server
Definition: ulinet.h:86
_HINTERNET::location
char * location
The potential Location header returned by the server.
Definition: ulinet.h:90
MemoryStruct::memory
char * memory
the memory space to store data
Definition: ulinet.h:68
AddMissingHeaderEntry
int AddMissingHeaderEntry(_HINTERNET *, const char *, const char *)
Add missing headers to an existing _HINTERNET.
Definition: ulinet.c:326
setProxy
void setProxy(CURL *, char *, long)
Define the proxy to use for a CURL handler.
Definition: ulinet.c:156
_HINTERNET::handle
CURL * handle
the CURL handler
Definition: ulinet.h:81
HINTERNET::agent
char * agent
The User-Agent to use for HTTP request.
Definition: ulinet.h:101
InternetOpenUrl
HINTERNET InternetOpenUrl(HINTERNET *, LPCTSTR, LPCTSTR, size_t, size_t, size_t, const maps *)
Create a new element in the download queue.
Definition: ulinet.c:487
write_data_into_file
size_t write_data_into_file(void *, size_t, size_t, void *)
Write the downloaded content in the file pouted by the _HINTERNET structure.
Definition: ulinet.c:80
HINTERNET
Multiple CURL handlers.
Definition: ulinet.h:96