|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
Copyright (C) 2010 ABRT team
|
|
Packit Service |
779887 |
Copyright (C) 2010 RedHat Inc
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
779887 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
779887 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
779887 |
(at your option) any later version.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
779887 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
779887 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
779887 |
GNU General Public License for more details.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
You should have received a copy of the GNU General Public License along
|
|
Packit Service |
779887 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit Service |
779887 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
#ifndef LIBREPORT_CURL_H_
|
|
Packit Service |
779887 |
#define LIBREPORT_CURL_H_
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#include <curl/curl.h>
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#ifdef __cplusplus
|
|
Packit Service |
779887 |
extern "C" {
|
|
Packit Service |
779887 |
#endif
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
CURL* xcurl_easy_init();
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/* Set proxy according to the url and call curl_easy_perform */
|
|
Packit Service |
779887 |
CURLcode curl_easy_perform_with_proxy(CURL *handle, const char *url);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
typedef struct post_state {
|
|
Packit Service |
779887 |
/* Supplied by caller: */
|
|
Packit Service |
779887 |
int flags;
|
|
Packit Service |
779887 |
const char *username;
|
|
Packit Service |
779887 |
const char *password;
|
|
Packit Service |
779887 |
const char *client_cert_path;
|
|
Packit Service |
779887 |
const char *client_key_path;
|
|
Packit Service |
779887 |
const char *cert_authority_cert_path;
|
|
Packit Service |
779887 |
/* SSH key files */
|
|
Packit Service |
779887 |
const char *client_ssh_public_keyfile;
|
|
Packit Service |
779887 |
const char *client_ssh_private_keyfile;
|
|
Packit Service |
779887 |
/* Results of POST transaction: */
|
|
Packit Service |
779887 |
int http_resp_code;
|
|
Packit Service |
779887 |
/* cast from CURLcode enum.
|
|
Packit Service |
779887 |
* 0 = success.
|
|
Packit Service |
779887 |
* -1 = curl_easy_perform wasn't even reached (file open error, etc).
|
|
Packit Service |
779887 |
* Else curl_easy_perform's error (which is positive, see curl/curl.h).
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
int curl_result;
|
|
Packit Service |
779887 |
unsigned header_cnt;
|
|
Packit Service |
779887 |
char **headers;
|
|
Packit Service |
779887 |
char *curl_error_msg;
|
|
Packit Service |
779887 |
char *body;
|
|
Packit Service |
779887 |
size_t body_size;
|
|
Packit Service |
779887 |
char errmsg[CURL_ERROR_SIZE];
|
|
Packit Service |
779887 |
} post_state_t;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
post_state_t *new_post_state(int flags);
|
|
Packit Service |
779887 |
void free_post_state(post_state_t *state);
|
|
Packit Service |
779887 |
char *find_header_in_post_state(post_state_t *state, const char *str);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
enum {
|
|
Packit Service |
779887 |
POST_WANT_HEADERS = (1 << 0),
|
|
Packit Service |
779887 |
POST_WANT_ERROR_MSG = (1 << 1),
|
|
Packit Service |
779887 |
POST_WANT_BODY = (1 << 2),
|
|
Packit Service |
779887 |
POST_WANT_SSL_VERIFY = (1 << 3),
|
|
Packit Service |
779887 |
};
|
|
Packit Service |
779887 |
enum {
|
|
Packit Service |
779887 |
/* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */
|
|
Packit Service |
779887 |
POST_DATA_STRING = -1,
|
|
Packit Service |
779887 |
POST_DATA_FROMFILE = -2,
|
|
Packit Service |
779887 |
POST_DATA_FROMFILE_PUT = -3,
|
|
Packit Service |
779887 |
POST_DATA_FROMFILE_AS_FORM_DATA = -4,
|
|
Packit Service |
779887 |
POST_DATA_STRING_AS_FORM_DATA = -5,
|
|
Packit Service |
779887 |
POST_DATA_GET = -6,
|
|
Packit Service |
779887 |
};
|
|
Packit Service |
779887 |
int
|
|
Packit Service |
779887 |
post(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers,
|
|
Packit Service |
779887 |
const char *data,
|
|
Packit Service |
779887 |
off_t data_size);
|
|
Packit Service |
779887 |
static inline int
|
|
Packit Service |
779887 |
get(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
return post(state, url, content_type, additional_headers,
|
|
Packit Service |
779887 |
NULL, POST_DATA_GET);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
static inline int
|
|
Packit Service |
779887 |
post_string(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers,
|
|
Packit Service |
779887 |
const char *str)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
return post(state, url, content_type, additional_headers,
|
|
Packit Service |
779887 |
str, POST_DATA_STRING);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
static inline int
|
|
Packit Service |
779887 |
post_string_as_form_data(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers,
|
|
Packit Service |
779887 |
const char *str)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
return post(state, url, content_type, additional_headers,
|
|
Packit Service |
779887 |
str, POST_DATA_STRING_AS_FORM_DATA);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
static inline int
|
|
Packit Service |
779887 |
post_file(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers,
|
|
Packit Service |
779887 |
const char *filename)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
return post(state, url, content_type, additional_headers,
|
|
Packit Service |
779887 |
filename, POST_DATA_FROMFILE);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
static inline int
|
|
Packit Service |
779887 |
post_file_as_form(post_state_t *state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *content_type,
|
|
Packit Service |
779887 |
const char **additional_headers,
|
|
Packit Service |
779887 |
const char *filename)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
return post(state, url, content_type, additional_headers,
|
|
Packit Service |
779887 |
filename, POST_DATA_FROMFILE_AS_FORM_DATA);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
enum {
|
|
Packit Service |
779887 |
UPLOAD_FILE_NOFLAGS = 0,
|
|
Packit Service |
779887 |
UPLOAD_FILE_HANDLE_ACCESS_DENIALS = 1 << 0,
|
|
Packit Service |
779887 |
};
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#define upload_file libreport_upload_file
|
|
Packit Service |
779887 |
char *upload_file(const char *url, const char *filename);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/* Uploads filename to url.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* If url does not ends with '/', base name of filename will be amended.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* Fails if the url does not have scheme or hostname.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @return Resulting URL on success (the URL does not contain userinfo);
|
|
Packit Service |
779887 |
* otherwise NULL.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
#define upload_file_ext libreport_upload_file_ext
|
|
Packit Service |
779887 |
char *upload_file_ext(post_state_t *post_state,
|
|
Packit Service |
779887 |
const char *url,
|
|
Packit Service |
779887 |
const char *filename,
|
|
Packit Service |
779887 |
int flags);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#ifdef __cplusplus
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
#endif
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#endif
|