6 * Copyright (C) 2013-2015 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Public interface to HTTP request service
28 * Interface dependencies:
33 /* Forward declarations */
34 struct sipe_core_private
;
35 struct sipe_http_request
;
36 struct sipe_http_session
;
39 * HTTP response callback
41 * @param sipe_private SIPE core private data
42 * @param status status code
43 * @param headers response headers (@c NULL if request aborted)
44 * @param body response body (@c NULL if request aborted)
45 * @param callback_data callback data
47 typedef void (sipe_http_response_callback
)(struct sipe_core_private
*sipe_private
,
51 gpointer callback_data
);
53 /* HTTP response status codes */
54 #define SIPE_HTTP_STATUS_FAILED 0 /* internal use */
55 #define SIPE_HTTP_STATUS_OK 200
56 #define SIPE_HTTP_STATUS_REDIRECTION 300 /* - 399 */
57 #define SIPE_HTTP_STATUS_CLIENT_ERROR 400 /* - 499 */
58 #define SIPE_HTTP_STATUS_CLIENT_UNAUTHORIZED 401
59 #define SIPE_HTTP_STATUS_CLIENT_FORBIDDEN 403
60 #define SIPE_HTTP_STATUS_CLIENT_PROXY_AUTH 407
61 #define SIPE_HTTP_STATUS_SERVER_ERROR 500 /* - 599 */
62 #define SIPE_HTTP_STATUS_CANCELLED -2 /* internal use */
63 #define SIPE_HTTP_STATUS_ABORTED -1 /* internal use */
68 * @param sipe_private SIPE core private data
70 void sipe_http_free(struct sipe_core_private
*sipe_private
);
75 * @return pointer to opaque HTTP session data structure
77 struct sipe_http_session
*sipe_http_session_start(void);
82 * @param session pointer to opaque HTTP session data structure
84 void sipe_http_session_close(struct sipe_http_session
*session
);
87 * Create HTTP GET request
89 * @param sipe_private SIPE core private data
91 * @param headers additional headers (may be @c NULL)
92 * @param callback callback function
93 * @param callback_data callback data
95 * @return pointer to opaque HTTP request data structure (@c NULL if failed)
97 struct sipe_http_request
*sipe_http_request_get(struct sipe_core_private
*sipe_private
,
100 sipe_http_response_callback
*callback
,
101 gpointer callback_data
);
104 * Create HTTP POST request
106 * @param sipe_private SIPE core private data
108 * @param headers additional headers (may be @c NULL)
109 * @param body body contents
110 * @param content_type body content type
111 * @param callback callback function
112 * @param callback_data callback data
114 * @return pointer to opaque HTTP request data structure (@c NULL if failed)
116 struct sipe_http_request
*sipe_http_request_post(struct sipe_core_private
*sipe_private
,
118 const gchar
*headers
,
120 const gchar
*content_type
,
121 sipe_http_response_callback
*callback
,
122 gpointer callback_data
);
125 * HTTP request is ready to be sent
127 * @param request pointer to opaque HTTP request data structure
129 void sipe_http_request_ready(struct sipe_http_request
*request
);
132 * Cancel pending HTTP request
134 * @param request pointer to opaque HTTP request data structure
136 void sipe_http_request_cancel(struct sipe_http_request
*request
);
139 * Assign request to HTTP session
141 * @param request pointer to opaque HTTP request data structure
142 * @param session pointer to opaque HTTP session data structure
144 void sipe_http_request_session(struct sipe_http_request
*request
,
145 struct sipe_http_session
*session
);
148 * Allow redirection of HTTP request
150 * @param request pointer to opaque HTTP request data structure
152 void sipe_http_request_allow_redirect(struct sipe_http_request
*request
);
155 * Provide authentication information for HTTP request
157 * @param request pointer to opaque HTTP request data structure
158 * @param user user name (MUST stay valid for duration of request!)
159 * @param password Password (MUST stay valid for duration of request!)
161 void sipe_http_request_authentication(struct sipe_http_request
*request
,
163 const gchar
*password
);