forked from UtrechtUniversity/davrods
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurl_util.h
152 lines (105 loc) · 2.85 KB
/
curl_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* curl_tool.h
*
* Created on: 13 Apr 2018
* Author: billy
*/
#ifndef CURL_UTIL_H_
#define CURL_UTIL_H_
/*
** Copyright 2014-2016 The Earlham Institute
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/**
* @file
* @brief
*/
#ifndef GRASSROOTS_CURL_TOOLS_H
#define GRASSROOTS_CURL_TOOLS_H
#include <stdio.h>
#include <stdbool.h>
#include "httpd.h"
#include <curl/curl.h>
#include "apr_pools.h"
#include "apr_buckets.h"
/**
* @brief A tool for making http(s) requests and responses.
*
* A datatype that uses CURL to perform http(s) requests
* and responses.
* @ingroup network_group
*/
typedef struct CurlUtil
{
/** @private */
CURL *ct_curl_p;
/** @private */
apr_pool_t *ct_pool_p;
apr_bucket_brigade *ct_buffer_p;
request_rec *ct_req_p;
/** @private */
char *ct_buffer_s;
/** @private */
struct curl_httppost *ct_form_p;
/** @private */
struct curl_httppost *ct_last_field_p;
/** @private */
struct curl_slist *ct_headers_list_p;
} CurlUtil;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Allocate a CurlUtil.
*
* @param mode The CurlMode that this CurlUtil will use.
* @return A newly-allocated CurlUtil or <code>NULL</code> upon error.
* @memberof CurlUtil
* @see FreeCurlUtil
*/
CurlUtil *AllocateCurlUtil (request_rec *req_p, apr_pool_t *pool_p);
/**
* Free a CurlUtil
*
* @param curl_p The CurlUtil to free.
* @memberof CurlUtil
*/
void FreeCurlUtil (CurlUtil *curl_p);
bool ResetCurlUtil (CurlUtil *tool_p);
char *SimpleCallGetRequest (request_rec *req_p, apr_pool_t *pool_p, const char *uri_s);
char *CallGetRequest (CurlUtil *tool_p, const char *uri_s);
/**
* Get the URL encoded version of a string.
*
* @param tool_p The CurlUtil to use to generate the URL encoded string.
* @param src_s The string to encode.
* @return The URL encoded version of the input string. This must be freed with
* FreeURLEscapedString.
* @see GetURLEscapedString
* @memberof CurlUtil
*/
char *GetURLEscapedString (CurlUtil *tool_p, const char *src_s);
/**
* Free a previously allocated string created by GetURLEscapedString.
*
* @param value_s The string to free. This must have been created by GetURLEscapedString.
* @see GetURLEscapedString
* @memberof CurlUtil
*/
void FreeURLEscapedString (char *value_s);
#ifdef __cplusplus
}
#endif
#endif /* #ifndef GRASSROOTS_CURL_TOOLS_H */
#endif /* CURL_UTIL_H_ */