libreport
2.1.3
A tool to inform users about various problems on the running system
|
00001 /* 00002 Copyright (C) 2010 ABRT team 00003 Copyright (C) 2010 RedHat Inc 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 #ifndef LIBREPORT_CURL_H_ 00020 #define LIBREPORT_CURL_H_ 00021 00022 #include <curl/curl.h> 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 CURL* xcurl_easy_init(); 00029 00030 /* Set proxy according to the url and call curl_easy_perform */ 00031 CURLcode curl_easy_perform_with_proxy(CURL *handle, const char *url); 00032 00033 typedef struct post_state { 00034 /* Supplied by caller: */ 00035 int flags; 00036 const char *username; 00037 const char *password; 00038 /* Results of POST transaction: */ 00039 int http_resp_code; 00040 /* cast from CURLcode enum. 00041 * 0 = success. 00042 * -1 = curl_easy_perform wasn't even reached (file open error, etc). 00043 * Else curl_easy_perform's error (which is positive, see curl/curl.h). 00044 */ 00045 int curl_result; 00046 unsigned header_cnt; 00047 char **headers; 00048 char *curl_error_msg; 00049 char *body; 00050 size_t body_size; 00051 char errmsg[CURL_ERROR_SIZE]; 00052 } post_state_t; 00053 00054 post_state_t *new_post_state(int flags); 00055 void free_post_state(post_state_t *state); 00056 char *find_header_in_post_state(post_state_t *state, const char *str); 00057 00058 enum { 00059 POST_WANT_HEADERS = (1 << 0), 00060 POST_WANT_ERROR_MSG = (1 << 1), 00061 POST_WANT_BODY = (1 << 2), 00062 POST_WANT_SSL_VERIFY = (1 << 3), 00063 }; 00064 enum { 00065 /* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */ 00066 POST_DATA_STRING = -1, 00067 POST_DATA_FROMFILE = -2, 00068 POST_DATA_FROMFILE_PUT = -3, 00069 POST_DATA_FROMFILE_AS_FORM_DATA = -4, 00070 POST_DATA_STRING_AS_FORM_DATA = -5, 00071 }; 00072 int 00073 post(post_state_t *state, 00074 const char *url, 00075 const char *content_type, 00076 const char **additional_headers, 00077 const char *data, 00078 off_t data_size); 00079 static inline int 00080 post_string(post_state_t *state, 00081 const char *url, 00082 const char *content_type, 00083 const char **additional_headers, 00084 const char *str) 00085 { 00086 return post(state, url, content_type, additional_headers, 00087 str, POST_DATA_STRING); 00088 } 00089 static inline int 00090 post_string_as_form_data(post_state_t *state, 00091 const char *url, 00092 const char *content_type, 00093 const char **additional_headers, 00094 const char *str) 00095 { 00096 return post(state, url, content_type, additional_headers, 00097 str, POST_DATA_STRING_AS_FORM_DATA); 00098 } 00099 static inline int 00100 post_file(post_state_t *state, 00101 const char *url, 00102 const char *content_type, 00103 const char **additional_headers, 00104 const char *filename) 00105 { 00106 return post(state, url, content_type, additional_headers, 00107 filename, POST_DATA_FROMFILE); 00108 } 00109 static inline int 00110 post_file_as_form(post_state_t *state, 00111 const char *url, 00112 const char *content_type, 00113 const char **additional_headers, 00114 const char *filename) 00115 { 00116 return post(state, url, content_type, additional_headers, 00117 filename, POST_DATA_FROMFILE_AS_FORM_DATA); 00118 } 00119 00120 #define upload_file libreport_upload_file 00121 char *upload_file(const char *url, const char *filename); 00122 00123 #ifdef __cplusplus 00124 } 00125 #endif 00126 00127 #endif