Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
curl_tools.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
22 #ifndef GRASSROOTS_CURL_TOOLS_H
23 #define GRASSROOTS_CURL_TOOLS_H
24 
25 #include <stdio.h>
26 
27 #include <curl/curl.h>
28 
29 #include "jansson.h"
30 
31 #include "typedefs.h"
32 #include "network_library.h"
33 #include "byte_buffer.h"
34 
35 
41 typedef enum CurlMode
42 {
45 
48 
51 } CurlMode;
52 
53 
54 typedef struct TemporaryFile
55 {
57  FILE *tf_temp_f;
58 
60  char *tf_temp_file_contents_s;
61 
63 
65 
66 
74 typedef struct CurlTool
75 {
77  CURL *ct_curl_p;
78 
79 
81  char *ct_username_s;
82 
84  char *ct_password_s;
85 
86 
88  CurlMode ct_mode;
89 
91  ByteBuffer *ct_buffer_p;
92 
94  TemporaryFile *ct_temp_file_p;
95 
97  struct curl_httppost *ct_form_p;
98 
100  struct curl_httppost *ct_last_field_p;
101 
103  struct curl_slist *ct_headers_list_p;
104 } CurlTool;
105 
106 
107 
108 #ifdef __cplusplus
109  extern "C" {
110 #endif
111 
112 
113 
121 
122 
128 GRASSROOTS_NETWORK_LOCAL void FreeCurl (CURL *curl_p);
129 
140 GRASSROOTS_NETWORK_API bool SetSSLEngine (CurlTool *curl_p, const char *cryptograph_engine_name_s);
141 
142 
155 GRASSROOTS_NETWORK_API bool CallSecureUrl (const char *url_s, const char *header_data_s, const char *ca_cert_name_s, const char * const cert_name_s, const char *key_name_s, const bool verify_certs, ByteBuffer *buffer_p);
156 
157 
168 GRASSROOTS_NETWORK_API bool AddCurlCallback (CurlTool *curl_tool_p, curl_write_callback callback_fn, void *callback_data_p);
169 
170 
180 GRASSROOTS_NETWORK_API bool SetUriForCurlTool (CurlTool *tool_p, const char * const uri_s);
181 
182 
191 GRASSROOTS_NETWORK_API CURLcode RunCurlTool (CurlTool *tool_p);
192 
193 
203 
204 
216 GRASSROOTS_NETWORK_API const char *GetCurlToolData (CurlTool * const tool_p);
217 
218 
219 
231 GRASSROOTS_NETWORK_API size_t GetCurlToolDataSize (CurlTool * const tool_p);
232 
233 
244 GRASSROOTS_NETWORK_API bool MakeRemoteJSONCallFromCurlTool (CurlTool *tool_p, const json_t *req_p);
245 
246 
257 GRASSROOTS_NETWORK_API bool SetCurlToolHeader (CurlTool *tool_p, const char *key_s, const char *value_s);
258 
259 
264 GRASSROOTS_NETWORK_API bool SetCurlToolAuth (CurlTool *tool_p, const char *username_s, const char *password_s);
265 
266 
272 
273 
274 
285 GRASSROOTS_NETWORK_API char *GetURLEscapedString (CurlTool *tool_p, const char *src_s);
286 
287 
295 GRASSROOTS_NETWORK_API void FreeURLEscapedString (char *value_s);
296 
297 
298 
299 GRASSROOTS_NETWORK_API CurlTool *AllocateFileCurlTool (const char * const filename_s);
300 
301 
302 
303 GRASSROOTS_NETWORK_API CurlTool *AllocateMemoryCurlTool (const size_t buffer_size);
304 
305 
306 GRASSROOTS_NETWORK_API char *GetWebData (const char *url_s);
307 
308 
309 
310 GRASSROOTS_NETWORK_API void SetCurlToolTimeout (CurlTool *tool_p, const long timeout);
311 
312 
313 GRASSROOTS_NETWORK_LOCAL TemporaryFile *AllocateTemporaryFile (const char * const filename_s);
314 
315 
316 
317 GRASSROOTS_NETWORK_LOCAL void FreeTemporaryFile (TemporaryFile *temp_p);
318 
319 
320 GRASSROOTS_NETWORK_LOCAL char *GetTemporaryFileContentsAsString (TemporaryFile *temp_p);
321 
322 
324 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 
331 #endif /* #ifndef GRASSROOTS_CURL_TOOLS_H */
332 
ClearCurlToolData
void ClearCurlToolData(CurlTool *tool_p)
CurlMode
CurlMode
An enum specifying where any resultant data from running a CurlTool will be stored.
Definition: curl_tools.h:41
GRASSROOTS_NETWORK_API
#define GRASSROOTS_NETWORK_API
Definition: network_library.h:46
CurlTool
A tool for making http(s) requests and responses.
Definition: curl_tools.h:74
CurlTool::FreeURLEscapedString
void FreeURLEscapedString(char *value_s)
Free a previously allocated string created by GetURLEscapedString.
TemporaryFile
Definition: curl_tools.h:54
CM_NUM_MODES
The number of available modes.
Definition: curl_tools.h:50
CurlTool::ClearCurlToolAuth
void ClearCurlToolAuth(CurlTool *tool_p)
network_library.h
CurlTool::GetURLEscapedString
char * GetURLEscapedString(CurlTool *tool_p, const char *src_s)
Get the URL encoded version of a string.
GetWebData
char * GetWebData(const char *url_s)
CurlTool::GetCurlToolData
const char * GetCurlToolData(CurlTool *const tool_p)
Get the downloaded data from a CurlTool.
AllocateMemoryCurlTool
CurlTool * AllocateMemoryCurlTool(const size_t buffer_size)
CM_MEMORY
The data will be stored in memory.
Definition: curl_tools.h:44
CallSecureUrl
bool CallSecureUrl(const char *url_s, const char *header_data_s, const char *ca_cert_name_s, const char *const cert_name_s, const char *key_name_s, const bool verify_certs, ByteBuffer *buffer_p)
Call a secure web address.
SetCurlToolTimeout
void SetCurlToolTimeout(CurlTool *tool_p, const long timeout)
CurlTool::SetCurlToolForJSONPost
bool SetCurlToolForJSONPost(CurlTool *tool_p)
Set up a CurlTool to do a JSON post when it is run.
CurlTool::AddCurlCallback
bool AddCurlCallback(CurlTool *curl_tool_p, curl_write_callback callback_fn, void *callback_data_p)
Add a callback to write the HTTP response for this CURL object to the given buffer.
typedefs.h
byte_buffer.h
AllocateFileCurlTool
CurlTool * AllocateFileCurlTool(const char *const filename_s)
CurlTool::SetUriForCurlTool
bool SetUriForCurlTool(CurlTool *tool_p, const char *const uri_s)
Set the URI that the CurlTool will try to get the html data from.
CurlTool::SetCurlToolHeader
bool SetCurlToolHeader(CurlTool *tool_p, const char *key_s, const char *value_s)
Add a key value pair to the request header that a CurlTool will send when it is run.
CurlTool::GetCurlToolDataSize
size_t GetCurlToolDataSize(CurlTool *const tool_p)
Get the size in bytes of the downloaded data from a CurlTool.
ByteBuffer
A datatype to allow an automatically growing buffer for appending data to.
Definition: byte_buffer.h:35
CurlTool::MakeRemoteJSONCallFromCurlTool
bool MakeRemoteJSONCallFromCurlTool(CurlTool *tool_p, const json_t *req_p)
Send a JSON request using a CurlTool.
CurlTool::SetCurlToolAuth
bool SetCurlToolAuth(CurlTool *tool_p, const char *username_s, const char *password_s)
GRASSROOTS_NETWORK_LOCAL
#define GRASSROOTS_NETWORK_LOCAL
Definition: network_library.h:47
TemporaryFile::tf_temp_file_size
size_t tf_temp_file_size
Definition: curl_tools.h:62
CurlTool::RunCurlTool
CURLcode RunCurlTool(CurlTool *tool_p)
Run a CurlTool.
CM_FILE
The data will be written to disk.
Definition: curl_tools.h:47
CurlTool::FreeCurlTool
void FreeCurlTool(CurlTool *curl_p)
Free a CurlTool.
CurlTool::SetSSLEngine
bool SetSSLEngine(CurlTool *curl_p, const char *cryptograph_engine_name_s)
Set the cryptographic engine to use.