@@ -134,6 +134,91 @@ irods::error irodsCurl::get_str( char *url, char **buffer ) {
134
134
return SUCCESS ();
135
135
}
136
136
137
+ irods::error irodsCurl::del ( char *url, char **buffer ) {
138
+ CURLcode res = CURLE_OK;
139
+ string_t string;
140
+ curlProgress_t prog; // for progress and cutoff
141
+
142
+ // Destination string_t init
143
+ string.ptr = strdup (" " );
144
+ string.len = 0 ;
145
+
146
+ // Progress struct init
147
+ prog.downloaded = 0 ;
148
+ prog.cutoff = 0 ;
149
+
150
+ // Set up easy handler
151
+ curl_easy_setopt ( curl, CURLOPT_USERAGENT, " libcurl-agent/1.0" );
152
+ curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, &irodsCurl::write_str );
153
+ curl_easy_setopt ( curl, CURLOPT_WRITEDATA, &string );
154
+ curl_easy_setopt ( curl, CURLOPT_URL, url );
155
+ curl_easy_setopt ( curl, CURLOPT_CUSTOMREQUEST, " DELETE" );
156
+
157
+ // CURL call
158
+ res = curl_easy_perform ( curl );
159
+
160
+ // Output
161
+ *buffer = string.ptr ;
162
+
163
+ // Error logging
164
+ if ( res != CURLE_OK ) {
165
+ rodsLog ( LOG_ERROR, " irodsCurl::delete: cURL error: %s" , curl_easy_strerror ( res ) );
166
+ return CODE (PLUGIN_ERROR);
167
+ }
168
+
169
+ return SUCCESS ();
170
+ }
171
+
172
+ irods::error irodsCurl::put ( char *url, keyValPair_t *post_fields, char **response ) {
173
+ CURLcode res = CURLE_OK;
174
+
175
+ char *headers, *data; // input
176
+ char *encoded_data = NULL ;
177
+
178
+ struct curl_slist *header_list = NULL ;
179
+
180
+ string_t string; // server response
181
+ int must_encode = 0 ; // for the time being...
182
+
183
+ // Parse POST fields
184
+ data = getValByKey (post_fields, IRODS_CURL_DATA_KW);
185
+ headers = getValByKey (post_fields, IRODS_CURL_HEADERS_KW);
186
+
187
+ // Init string
188
+ string.ptr = strdup (" " );
189
+ string.len = 0 ;
190
+
191
+ // url-encode data
192
+ if (must_encode && data) {
193
+ encoded_data = curl_easy_escape (curl, data, 0 );
194
+ }
195
+
196
+ // Set headers
197
+ if (headers && strlen (headers)) {
198
+ header_list = curl_slist_append (header_list, headers);
199
+ curl_easy_setopt (curl, CURLOPT_HTTPHEADER, header_list);
200
+ }
201
+
202
+ // Set up easy handler
203
+ curl_easy_setopt (curl, CURLOPT_URL, url);
204
+ curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, " PUT" );
205
+ curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data);
206
+ curl_easy_setopt (curl, CURLOPT_USERAGENT, " libcurl-agent/1.0" );
207
+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &irodsCurl::write_str);
208
+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &string);
209
+
210
+ // CURL call
211
+ res = curl_easy_perform (curl);
212
+
213
+ // Cleanup
214
+ if (header_list) curl_slist_free_all (header_list);
215
+ if (encoded_data) curl_free (encoded_data);
216
+
217
+ // Output
218
+ *response = string.ptr ;
219
+
220
+ return CODE (res);
221
+ }
137
222
138
223
irods::error irodsCurl::post ( char *url, keyValPair_t *post_fields, char **response ) {
139
224
CURLcode res = CURLE_OK;
0 commit comments