v0.2.2 release
[yandexfotkisp] / src / libsharing / sharing-http.h
1 /*
2  * This file is part of Sharing Application Library
3  *
4  * Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Bokovoy <alexander.bokovoy@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #ifndef _SHARING_HTTP_H_
25 #define _SHARING_HTTP_H_
26
27 #include <glib.h>
28 #include <conicconnection.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct SharingHTTP SharingHTTP;
33
34 /**
35  * SharingHTTPProgressCallback:
36  * @http: Pointer to #SharingHTTP object calling
37  * @bytes_sent: How many bytes is sent
38  * @user_data: User data pointer
39  *
40  * Progress callback function prototype for #SharingHTTP
41  *
42  * Returns: %TRUE to continue, %FALSE to cancel transfer
43  */
44 typedef gboolean (*SharingHTTPProgressCallback) (SharingHTTP * http,
45     guint64 bytes_sent, gpointer user_data);
46
47
48 /**
49  * SharingHTTPRunResponse:
50  * @SHARING_HTTP_RUNRES_SUCCESS: Run was a success.
51  * @SHARING_HTTP_RUNRES_UNKNOWN_FAILURE: Unknown failure.
52  * @SHARING_HTTP_RUNRES_INVALID_PARAMETERS: Invalid parameters given.
53  * @SHARING_HTTP_RUNRES_CONNECTION_PROBLEM: Couldn't get connection to URL.
54  * @SHARING_HTTP_RUNRES_CANCELLED: Run was cancelled by callback.
55  * @SHARING_HTTP_RUNRES_ALREADY_RUNNING: There is already active process
56  * ongoing.
57  *
58  * Response codes for sharing_http_run()
59  */  
60 typedef enum {
61     SHARING_HTTP_RUNRES_SUCCESS,
62     SHARING_HTTP_RUNRES_UNKNOWN_FAILURE, 
63     SHARING_HTTP_RUNRES_INVALID_PARAMETERS,
64     SHARING_HTTP_RUNRES_CONNECTION_PROBLEM,
65     SHARING_HTTP_RUNRES_CANCELLED,
66     SHARING_HTTP_RUNRES_ALREADY_RUNNING
67 } SharingHTTPRunResponse;
68
69 SharingHTTP * sharing_http_new();
70
71 gint sharing_http_ref (SharingHTTP * self);
72 gint sharing_http_unref (SharingHTTP * self);
73
74 void sharing_http_set_connection (SharingHTTP * self,
75     ConIcConnection * connection);
76 ConIcConnection * sharing_http_get_connection (SharingHTTP * self);
77
78 void sharing_http_set_timeouts (SharingHTTP * self, glong connecting_timeout,
79     glong connection_timeout);
80
81 void sharing_http_set_progress_callback (SharingHTTP * self,
82     SharingHTTPProgressCallback callback, gpointer user_data);
83
84 SharingHTTPRunResponse sharing_http_run (SharingHTTP * self, const gchar * url);
85
86 void sharing_http_cancel (SharingHTTP * self);
87
88 gboolean sharing_http_add_req_header (SharingHTTP * self, const gchar * name,
89     const gchar * value);
90 gboolean sharing_http_add_req_header_line (SharingHTTP * self,
91     const gchar * line);
92 void sharing_http_remove_req_headers (SharingHTTP * self);
93
94 gboolean sharing_http_add_req_multipart_file (SharingHTTP * self,
95     const gchar * name, const gchar * filepath, const gchar * type);
96     
97 gboolean sharing_http_add_req_multipart_file_with_filename (SharingHTTP * self,
98     const gchar * name, const gchar * filepath, const gchar * type,
99     const gchar * filename);    
100
101 gboolean sharing_http_add_req_multipart_data (SharingHTTP * self,
102     const gchar * name, const gchar * data, gint data_len, const gchar * type);
103     
104 void sharing_http_clear_multiparts (SharingHTTP * self);
105
106 void sharing_http_set_res_buffer_size_limit (SharingHTTP * self, gsize limit);
107 gsize sharing_http_get_res_buffer_size_limit (SharingHTTP * self);
108
109 gint sharing_http_get_res_code (SharingHTTP * self);
110 const gchar * sharing_http_get_res_content (SharingHTTP * self, gsize * len);
111 const gchar * sharing_http_get_res_body (SharingHTTP * self, gsize * len);
112
113 void sharing_http_set_user_agent_name (SharingHTTP * self,
114     const gchar * name);
115
116 G_END_DECLS
117
118 #endif /* #ifndef _SHARING_HTTP_H_ */
119