45632f00c130c018bb5752e70642ae8166202f11
[platform/core/api/http.git] / include / http.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __TIZEN_NETWORK_HTTP_H__
18 #define __TIZEN_NETWORK_HTTP_H__
19
20 #include <tizen.h>
21 #include <stdlib.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef TIZEN_ERROR_HTTP
28 #define TIZEN_ERROR_HTTP -0x03000000
29 #endif
30
31 /**
32  * @file http.h
33  */
34
35 /**
36  * @addtogroup CAPI_NETWORK_HTTP_MODULE
37  * @{
38  */
39
40 /**
41  * @brief The HTTP Session handle.
42  * @since_tizen 3.0
43  */
44 typedef void * http_session_h;
45
46 /**
47   * @brief The HTTP Transaction handle.
48   * @since_tizen 3.0
49   */
50 typedef void * http_transaction_h;
51
52 /**
53  * @}
54  */
55
56 /**
57   * @addtogroup CAPI_NETWORK_HTTP_SESSION_MODULE
58   * @{
59   */
60
61 /**
62  * @brief Enumeration for the http session.
63  * @since_tizen 3.0
64  */
65 typedef enum {
66         HTTP_SESSION_MODE_NORMAL,           /**< The Normal Mode */
67         HTTP_SESSION_MODE_PIPELINING,       /**< The Pipelining mode */
68 } http_session_mode_e;
69
70 /**
71   * @}
72   */
73
74 /**
75 * @addtogroup CAPI_NETWORK_HTTP_MODULE
76 * @{
77 */
78
79 /**
80  * @brief Enumeration for the http method.
81  * @since_tizen 3.0
82  */
83 typedef enum {
84         HTTP_METHOD_GET = 0x40,         /**< The HTTP GET Method */
85         HTTP_METHOD_OPTIONS = 0x41,     /**< The HTTP OPTIONS Method */
86         HTTP_METHOD_HEAD = 0x42,        /**< The HTTP HEAD Method */
87         HTTP_METHOD_DELETE = 0x43,      /**< The HTTP DELETE Method */
88         HTTP_METHOD_TRACE = 0x44,       /**< The HTTP TRACE Method */
89         HTTP_METHOD_POST = 0x60,        /**< The HTTP POST Method */
90         HTTP_METHOD_PUT = 0x61,         /**< The HTTP PUT Method */
91         HTTP_METHOD_CONNECT = 0x70,     /**< The HTTP CONNECT Method */
92 } http_method_e;
93
94 /**
95  * @brief Enumeration for the http version.
96  * @since_tizen 3.0
97  */
98 typedef enum {
99         HTTP_VERSION_1_0,   /**< HTTP version 1.0 */
100         HTTP_VERSION_1_1    /**< HTTP version 1.1 */
101 } http_version_e;
102
103 /**
104  * @brief Enumeration for transfer pause state
105  * @since_tizen 3.0
106  */
107 typedef enum {
108         HTTP_PAUSE_RECV = 1 << 0,   /**< Pause receiving data */
109         HTTP_PAUSE_SEND = 1 << 2,    /**< Pause sending data */
110         HTTP_PAUSE_ALL =  HTTP_PAUSE_RECV |  HTTP_PAUSE_SEND  /**< Pause both directions */
111 } http_pause_type_e;
112
113 /**
114  * @brief Enumeration for the http error code.
115  * @since_tizen 3.0
116  */
117 typedef enum {
118     HTTP_ERROR_NONE = TIZEN_ERROR_NONE,                                                         /**< Successful */
119         HTTP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,           /**< Out of memory */
120         HTTP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied */
121     HTTP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,       /**< Invalid parameter */
122     HTTP_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,       /**< Invalid operation */
123         HTTP_ERROR_OPERATION_FAILED = TIZEN_ERROR_HTTP|0x01,            /**< Operation failed */
124         HTTP_ERROR_COULDNT_RESOLVE_HOST = TIZEN_ERROR_HTTP|0x06,        /**< Couldn't resolve host */
125         HTTP_ERROR_COULDNT_CONNECT = TIZEN_ERROR_HTTP|0x07,                             /**< Couldn't Connect to host */
126         HTTP_ERROR_OPERATION_TIMEDOUT = TIZEN_ERROR_HTTP|0x28,           /**< Timeout */
127         HTTP_ERROR_SSL_CONNECT_ERROR = TIZEN_ERROR_HTTP|0x35,                   /**< SSL Error */
128         HTTP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,           /**< API is not supported */
129 } http_error_code_e;
130
131 /**
132  * @brief Enumeration for the http status code.
133  * @since_tizen 3.0
134  */
135 typedef enum {
136         HTTP_STATUS_UNDEFINED = 0,                                          /**< The undefined status */
137         HTTP_STATUS_CONTINUE = 100,                                         /**< The status code: 100 Continue */
138         HTTP_STATUS_SWITCHING_PROTOCOLS = 101,                              /**< The status code: 101 Switching Protocols */
139         HTTP_STATUS_OK = 200,                                               /**< The status code: 200 OK */
140         HTTP_STATUS_CREATED = 201,                                          /**< The status code: 201 Created */
141         HTTP_STATUS_ACCEPTED = 202,                                         /**< The status code: 202 Accepted */
142         HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203,                    /**< The status code: 203 Non-Authoritative Information */
143         HTTP_STATUS_NO_CONTENT = 204,                                       /**< The status code: 204 No %Content */
144         HTTP_STATUS_RESET_CONTENT = 205,                                    /**< The status code: 205 Reset %Content */
145         HTTP_STATUS_PARTIAL_CONTENT = 206,                                  /**< The status code: 206 Partial %Content */
146
147         HTTP_STATUS_MULTIPLE_CHOICE = 300,                                  /**< The status code: 300 Multiple Choices */
148         HTTP_STATUS_MOVED_PERMANENTLY = 301,                                /**< The status code: 301 Moved Permanently */
149         HTTP_STATUS_MOVED_TEMPORARILY = 302,                                /**< The status code: 302 Found */
150         HTTP_STATUS_SEE_OTHER = 303,                                        /**< The status code: 303 See Other */
151         HTTP_STATUS_NOT_MODIFIED = 304,                                     /**< The status code: 304 Not Modified */
152         HTTP_STATUS_USE_PROXY = 305,                                        /**< The status code: 305 Use Proxy */
153
154         HTTP_STATUS_BAD_REQUEST = 400,                                      /**< The status code: 400 Bad Request */
155         HTTP_STATUS_UNAUTHORIZED = 401,                                     /**< The status code: 401 Unauthorized */
156         HTTP_STATUS_PAYMENT_REQUIRED = 402,                                 /**< The status code: 402 Payment Required */
157         HTTP_STATUS_FORBIDDEN = 403,                                        /**< The status code: 403 Forbidden */
158         HTTP_STATUS_NOT_FOUND = 404,                                        /**< The status code: 404 Not Found */
159         HTTP_STATUS_METHOD_NOT_ALLOWED = 405,                               /**< The status code: 405 Method Not Allowed */
160         HTTP_STATUS_NOT_ACCEPTABLE = 406,                                   /**< The status code: 406 Not Acceptable */
161         HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407,                    /**< The status code: 407 Proxy Authentication Required */
162         HTTP_STATUS_REQUEST_TIME_OUT = 408,                                 /**< The status code: 408 Request Timeout (not used) */
163         HTTP_STATUS_CONFLICT = 409,                                         /**< The status code: 409 Conflict */
164         HTTP_STATUS_GONE = 410,                                             /**< The status code: 410 Gone */
165         HTTP_STATUS_LENGTH_REQUIRED = 411,                                  /**< The status code: 411 Length Required */
166         HTTP_STATUS_PRECONDITION_FAILED = 412,                              /**< The status code: 412 Precondition Failed */
167         HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE = 413,                         /**< The status code: 413 Request Entity Too Large (not used) */
168         HTTP_STATUS_REQUEST_URI_TOO_LARGE = 414,                            /**< The status code: 414 Request-URI Too Long (not used) */
169         HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,                           /**< The status code: 415 Unsupported %Media Type */
170
171         HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,                            /**< The status code: 500 Internal Server Error */
172         HTTP_STATUS_NOT_IMPLEMENTED = 501,                                  /**< The status code: 501 Not Implemented */
173         HTTP_STATUS_BAD_GATEWAY = 502,                                      /**< The status code: 502 Bad Gateway */
174         HTTP_STATUS_SERVICE_UNAVAILABLE = 503,                              /**< The status code: 503 Service Unavailable */
175         HTTP_STATUS_GATEWAY_TIME_OUT = 504,                                 /**< The status code: 504 Gateway Timeout */
176         HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505                        /**< The status code: 505 HTTP Version Not Supported */
177 } http_status_code_e;
178
179 /**
180  * @brief Called when the http header is received.
181  * @since_tizen 3.0
182  * @param[in]  http_transaction The http transaction handle
183  * @param[in]  header                   The header information of Http Transaction
184  * @param[in]  header_len               The length of the Http Transaction header
185  * @param[in]  user_data                The user data
186  * @see http_transaction_set_received_header_cb()
187  */
188 typedef void (*http_transaction_header_cb)(http_transaction_h http_transaction, char *header, size_t header_len, void *user_data);
189
190 /**
191  * @brief Called when the http response is received.
192  * @since_tizen 3.0
193  * @param[in]  http_transaction The http transaction handle
194  * @param[in]  body                             Response information of Http Transaction
195  * @param[in]  size                             Size in bytes of each element to be written
196  * @param[in]  count                    Number of elements, each one with a size of size bytes
197  * @param[in]  user_data                The user data
198  * @see http_transaction_set_received_body_cb()
199  */
200 typedef void (*http_transaction_body_cb)(http_transaction_h http_transaction, char *body, size_t size, size_t count, void *user_data);
201
202 /**
203  * @brief Called when the http ready to write event is received.
204  * @since_tizen 3.0
205  * @param[in]  http_transaction                 The http transaction handle
206  * @param[in]  recommended_chunk_size   Recommended chunk length(bytes) of the Http transaction
207  * @param[in]  user_data                                The user data
208  * @see http_transaction_set_uploaded_cb()
209  */
210 typedef void (*http_transaction_write_cb)(http_transaction_h http_transaction, int recommended_chunk_size, void *user_data);
211
212 /**
213  * @brief Called when the http transaction is completed.
214  * @since_tizen 3.0
215  * @param[in]  http_transaction The http transaction handle
216  * @param[in]  user_data                The user data
217  * @see http_transaction_set_completed_cb()
218  */
219 typedef void (*http_transaction_completed_cb)(http_transaction_h http_transaction, void *user_data);
220
221 /**
222  * @brief Called when the http transaction is aborted.
223  * @details Following error codes can be delivered. \n
224  *              #HTTP_ERROR_OPERATION_FAILED, \n
225  *              #HTTP_ERROR_COULDNT_RESOLVE_HOST, \n
226  *              #HTTP_ERROR_COULDNT_CONNECT, \n
227  *              #HTTP_ERROR_OPERATION_TIMEDOUT, \n
228  *              #HTTP_ERROR_SSL_CONNECT_ERROR
229  * @since_tizen 3.0
230  * @param[in]  http_transaction The http transaction handle
231  * @param[in]  error                    The error code about aborted reason
232  * @param[in]  user_data                The user data
233  * @see http_transaction_set_aborted_cb()
234  */
235 typedef void (*http_transaction_aborted_cb)(http_transaction_h http_transaction, http_error_code_e error, void *user_data);
236
237 /**
238  * @brief Called to notify when the content body of the response message is being downloaded or uploaded.
239  * @since_tizen 3.0
240  * @param[in]  http_transaction         The http transaction handle
241  * @param[in]  download_total           The total length of the data (in bytes) to download
242  * @param[in]  download_now                     The current length of the downloaded data (in bytes)
243  * @param[in]  upload_total                     The total length of the data (in bytes) to upload
244  * @param[in]  upload_now                       The current length of the uploaded data (in bytes)
245  * @param[in]  user_data                        The user data
246  * @see http_transaction_set_progress_cb()
247  */
248 typedef void (*http_transaction_progress_cb)(http_transaction_h http_transaction, double download_total, double download_now, double upload_total, double upload_now, void *user_data);
249
250 /**
251  * @brief Initializes the Http module.
252  * @since_tizen 3.0
253  * @return 0 on success, otherwise negative error value
254  * @retval  #HTTP_ERROR_NONE  Successful
255  * @retval  #HTTP_ERROR_OPERATION_FAILED Operation failed
256  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
257  * @see         http_deinit()
258  */
259 int http_init(void);
260
261 /**
262  * @brief Deinitializes the Http module.
263  * @since_tizen 3.0
264  * @return 0 on success, otherwise negative error value
265  * @retval  #HTTP_ERROR_NONE  Successful
266  * @retval  #HTTP_ERROR_OPERATION_FAILED Operation failed
267  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
268  * @see         http_init()
269  */
270 int http_deinit(void);
271
272 /**
273  * @}
274  */
275
276 /**
277  * @addtogroup CAPI_NETWORK_HTTP_SESSION_MODULE
278  * @{
279  */
280
281 /**
282  * @brief Creates the Http session handle.
283  * @since_tizen 3.0
284  * @remarks The @a http_session should be released using http_session_destroy(). \
285  *                      Opened transactions can't be submitted after destroing session handle.
286  * @param[in]   mode            The http session mode
287  * @param[out]  http_session    The http session handle
288  * @return 0 on success, otherwise negative error value
289  * @retval  #HTTP_ERROR_NONE  Successful
290  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
291  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
292  * @retval  #HTTP_ERROR_OUT_OF_MEMORY  Out of memory
293  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
294  * @see         http_session_destroy()
295  */
296 int http_session_create(http_session_mode_e mode, http_session_h *http_session);
297
298 /**
299  * @brief Destroys the Http session handle.
300  * @since_tizen 3.0
301  * @param[in]  http_session  The http session handle
302  * @return 0 on success, otherwise negative error value
303  * @retval  #HTTP_ERROR_NONE  Successful
304  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
305  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
306  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
307  * @see     http_session_create()
308  */
309 int http_session_destroy(http_session_h http_session);
310
311 /**
312  * @brief Opens Http transaction from the Http Session.
313  * @since_tizen 3.0
314  * @remarks The @a http_transaction should be released using http_transaction_destroy().
315  * @param[in]  http_session             The http session handle
316  * @param[in]  method                   The http request method
317  * @param[out] http_transaction The http transaction handle
318  * @return 0 on success, otherwise negative error value
319  * @retval  #HTTP_ERROR_NONE  Successful
320  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
321  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
322  * @retval  #HTTP_ERROR_OUT_OF_MEMORY  Out of memory
323  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
324  */
325 int http_session_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction);
326
327 /**
328  * @brief  Sets the value to redirect the HTTP request automatically.
329  * @since_tizen 3.0
330  * @param[in]  http_session     The http session handle
331  * @param[in]  auto_redirection The value which determines whether allow redirection or not
332  * @return 0 on success, otherwise negative error value
333  * @retval  #HTTP_ERROR_NONE  Successful
334  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
335  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
336  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
337  * @see         http_session_get_auto_redirection()
338  */
339 int http_session_set_auto_redirection(http_session_h http_session, bool auto_redirection);
340
341 /**
342  * @brief Gets the auto redirection for the HTTP request.
343  * @since_tizen 3.0
344  * @param[in]   http_session  The http session handle
345  * @param[out]  auto_redirect The value of auto redirect
346  * @return 0 on success, otherwise negative error value
347  * @retval  #HTTP_ERROR_NONE  Successful
348  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
349  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
350  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
351  * @see     http_session_set_auto_redirection()
352  */
353 int http_session_get_auto_redirection(http_session_h http_session, bool *auto_redirect);
354
355 /**
356  * @brief Gets the number of active transactions in the current session.
357  * @since_tizen 3.0
358  * @param[in]   http_session                            The http session handle
359  * @param[out]  active_transaction_count        The number of activated transactions
360  * @return 0 on success, otherwise negative error value
361  * @retval  #HTTP_ERROR_NONE  Successful
362  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
363  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
364  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
365  */
366 int http_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count);
367
368 /**
369  * @brief Gets the maximum number of transactions for the current session.
370  * @since_tizen 3.0
371  * @param[in]   http_session            The http session handle
372  * @param[out]  transaction_count       The maximum transaction count
373  * @return 0 on success, otherwise negative error value
374  * @retval  #HTTP_ERROR_NONE  Successful
375  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
376  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
377  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
378  */
379 int http_session_get_max_transaction_count(http_session_h http_session, int *transaction_count);
380
381 /*
382  * @brief Destroys all transaction.
383  * @since_tizen 3.0
384  * @param[in]  http_session  The http session handle
385  * @return 0 on success, otherwise negative error value
386  * @retval  #HTTP_ERROR_NONE  Successful
387  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
388  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
389  * @retval  #HTTP_ERROR_OPERATION_fAILED  Operation failed
390  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
391  */
392 int http_session_destroy_all_transactions(http_session_h http_session);
393 /**
394  * @}
395  */
396
397 /**
398  * @addtogroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE
399  * @{
400  */
401
402 /**
403  * @brief Submits the Http request.
404  * @since_tizen 3.0
405  * @privlevel public
406  * @privilege %http://tizen.org/privilege/internet
407  * @param[in]  http_transaction  The http transaction handle
408  * @return 0 on success, otherwise negative error value
409  * @retval  #HTTP_ERROR_NONE  Successful
410  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
411  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
412  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
413  * @retval  #HTTP_ERROR_PERMISSION_DENIED Permission denied
414  */
415 int http_transaction_submit(http_transaction_h http_transaction);
416
417 /**
418  * @brief Closes the http transaction handle.
419  * @since_tizen 3.0
420  * @remarks  The @a transaction is released by http_transaction_destroy().
421  *                       It should be used after finishing http trasaction.
422  * @param[in]  http_transaction  The http transaction handle
423  * @return 0 on success, otherwise negative error value
424  * @retval  #HTTP_ERROR_NONE  Successful
425  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
426  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
427  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
428  * @see         http_transaction_create()
429  */
430 int http_transaction_destroy(http_transaction_h http_transaction);
431
432 /*
433  * @brief Registers callback called when receive header.
434  * @since_tizen 3.0
435  * @param[in]  http_transaction  The http transaction handle
436  * @param[in]  header_cb                 The callback function to be called
437  * @param[in]  user_data                 The user data passed to the callback function
438  * @return 0 on success, otherwise negative error value
439  * @retval  #HTTP_ERROR_NONE  Successful
440  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
441  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
442  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
443  */
444 int http_transaction_set_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data);
445
446 /*
447  * @brief Registers callback called when receive body.
448  * @since_tizen 3.0
449  * @param[in]  http_transaction  The http transaction handle
450  * @param[in]  body_cb                   The callback function to be called
451  * @param[in]  user_data                 The user data passed to the callback function
452  * @return 0 on success, otherwise negative error value
453  * @retval  #HTTP_ERROR_NONE  Successful
454  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
455  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
456  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
457  */
458 int http_transaction_set_received_body_cb(http_transaction_h http_transaction, http_transaction_body_cb body_cb, void* user_data);
459
460 /*
461  * @brief Registers callback called when write data.
462  * @since_tizen 3.0
463  * @param[in]  http_transaction  The http transaction handle
464  * @param[in]  write_cb                  The callback function to be called
465  * @param[in]  user_data                 The user data passed to the callback function
466  * @return 0 on success, otherwise negative error value
467  * @retval  #HTTP_ERROR_NONE  Successful
468  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
469  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
470  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
471  */
472 int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, http_transaction_write_cb write_cb, void* user_data);
473
474 /*
475  * @brief Registers callback called when transaction is completed.
476  * @since_tizen 3.0
477  * @param[in]  http_transaction  The http transaction handle
478  * @param[in]  completed_cb      The callback function to be called
479  * @param[in]  user_data                 The user data passed to the callback function
480  * @return 0 on success, otherwise negative error value
481  * @retval  #HTTP_ERROR_NONE  Successful
482  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
483  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
484  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
485  */
486 int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data);
487
488 /*
489  * @brief Registers callback called when transaction is aborted.
490  * @since_tizen 3.0
491  * @param[in]  http_transaction  The http transaction handle
492  * @param[in]  header_cb                 The callback function to be called
493  * @param[in]  user_data                 The user data passed to the callback function
494  * @return 0 on success, otherwise negative error value
495  * @retval  #HTTP_ERROR_NONE  Successful
496  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
497  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
498  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
499  */
500 int http_transaction_set_aborted_cb(http_transaction_h http_http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data);
501
502
503 /**
504  * @brief Registers the progress callbacks.
505  * @details Registers callback that is called when data is uploaded/downloaded.
506  * @since_tizen 3.0
507  * @param[in]  http_transaction  The http transaction handle
508  * @param[in]  progress_cb               The callback function to be called
509  * @param[in]  user_data         The user data passed to the callback function
510  * @return 0 on success, otherwise negative error value
511  * @retval  #HTTP_ERROR_NONE  Successful
512  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
513  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
514  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
515  */
516 int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data);
517
518 /**
519  * @brief Sets the timeout in seconds that is the timeout for waiting the transaction.
520  * @details Sets the timeout in seconds that is the timeout for waiting the transaction. \n
521  *  A timeout value of zero means an infinite timeout.
522  * @since_tizen 3.0
523  * @param[in]  http_transaction  The http transaction handle
524  * @param[in]  timeout                   The timeout in seconds
525  * @return 0 on success, otherwise negative error value
526  * @retval  #HTTP_ERROR_NONE  Successful
527  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
528  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
529  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
530  */
531 int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout);
532
533 /**
534  * @brief Gets the time out in seconds for the transaction.
535  * @since_tizen 3.0
536  * @param[in]  http_transaction  The http transaction handle
537  * @param[out] timeout                   The timeout in seconds
538  * @return 0 on success, otherwise negative error value
539  * @retval  #HTTP_ERROR_NONE  Successful
540  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
541  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
542  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
543  */
544 int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout);
545
546 /**
547  * @brief Resumes the transaction.
548  * @since_tizen 3.0
549  * @param[in]  http_transaction  The http transaction handle
550  * @return 0 on success, otherwise negative error value
551  * @retval  #HTTP_ERROR_NONE  Successful
552  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
553  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
554  * @retval  #HTTP_ERROR_OPERATION_FAILED  Operation failed
555  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
556  */
557 int http_transaction_resume(http_transaction_h http_transaction);
558
559 /**
560  * @brief Pauses the transaction.
561  * @since_tizen 3.0
562  * @param[in]  http_transaction  The http transaction handle
563  * @param[in]  pause_type                The pause type of the connection
564  * @return 0 on success, otherwise negative error value
565  * @retval  #HTTP_ERROR_NONE  Successful
566  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
567  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
568  * @retval  #HTTP_ERROR_OPERATION_FAILED  Operation failed
569  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
570  */
571 int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type);
572
573 /**
574  * @brief Sets ready to write event for a transaction.
575  * @since_tizen 3.0
576  * @param[in]  http_transaction  The http transaction handle
577  * @param[out] read_to_write     Enable/disable ready to write
578  * @return 0 on success, otherwise negative error value
579  * @retval  #HTTP_ERROR_NONE  Successful
580  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
581  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
582  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
583  */
584 int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write);
585
586 /**
587  * @brief Sets the interface name.
588  * @since_tizen 3.0
589  * @param[in]  http_transaction  The http transaction handle
590  * @param[in]  interface_name    The interface name to use as outgoing network interface
591  * @return 0 on success, otherwise negative error value
592  * @retval  #HTTP_ERROR_NONE  Successful
593  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
594  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
595  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
596  */
597 int http_transaction_set_interface_name(http_transaction_h http_transaction, const char *interface_name);
598
599 /**
600  * @brief Gets the interface name.
601  * @since_tizen 3.0
602  * @remarks  The @a interface_name should be freed using free().
603  * @param[in]   http_transaction  The http transaction handle
604  * @param[out]  interface_name    The interface name
605  * @return 0 on success, otherwise negative error value
606  * @retval  #HTTP_ERROR_NONE  Successful
607  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
608  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
609  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
610  */
611 int http_transaction_get_interface_name(http_transaction_h http_transaction, char **interface_name);
612
613 /**
614  * @brief Sets the flag to verify a server certificate.
615  * @details The verify determines whether verifies the peer's certificate.
616  * @since_tizen 3.0
617  * @param[in]  http_transaction  The http transaction handle
618  * @param[in]  verify                    The flag to verify a server certificate; true means verifies; false means it doesn't.
619  * @return 0 on success, otherwise negative error value
620  * @retval  #HTTP_ERROR_NONE  Successful
621  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
622  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
623  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
624  */
625 int http_transaction_set_server_certificate_verification(http_transaction_h http_transaction, bool verify);
626
627 /**
628  * @brief Gets the flag to verify a server certificate.
629  * @since_tizen 3.0
630  * @param[in]  http_transaction  The http transaction handle
631  * @param[out] verify                    The flag to verify a server certificate; true means verifies; false means it doesn't.
632  * @return 0 on success, otherwise negative error value
633  * @retval  #HTTP_ERROR_NONE  Successful
634  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
635  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
636  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
637  */
638 int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify);
639
640 /**
641  * @brief Adds a named field to header.
642  * @details Adds a named field, which is a <@c fieldName, @c fieldValue> pair, to the current instance of Http Transaction.
643  * @since_tizen 3.0
644  * @param[in]  http_transaction  The http transaction handle
645  * @param[in]  field_name                The http Header Field name
646  * @param[in]  field_value       The http Header Field value
647  * @return 0 on success, otherwise negative error value
648  * @retval  #HTTP_ERROR_NONE  Successful
649  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
650  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
651  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
652  */
653 int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value);
654
655 /**
656  * @brief Removes the named field from header.
657  * @details Remove the named field, which is a <@c fieldName, @c fieldValue> pair, from the current instance of Http Transaction.
658  * @since_tizen 3.0
659  * @param[in]  http_transaction  The http transaction handle
660  * @param[in]  field_name                The http Header Field name
661  * @return 0 on success, otherwise negative error value
662  * @retval  #HTTP_ERROR_NONE  Successful
663  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
664  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
665  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
666  */
667 int http_transaction_header_remove_field(http_transaction_h http_transaction, const char *field_name);
668
669 /**
670  * @brief Gets the Http Header Field value from custom header.
671  * @since_tizen 3.0
672  * @remarks The @a field_value should be freed using free().
673  * @param[in]  http_transaction  The http transaction handle
674  * @param[in]  field_name                The http Header Field name
675  * @param[out] field_value       The http Header Field value
676  * @return 0 on success, otherwise negative error value
677  * @retval  #HTTP_ERROR_NONE  Successful
678  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
679  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
680  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
681  */
682 int http_transaction_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value);
683
684 /**
685  * @}
686  */
687
688 /**
689  * @addtogroup CAPI_NETWORK_HTTP_REQUEST_MODULE
690  * @{
691  */
692
693 /**
694  * @brief Sets an HTTP method of the request header.
695  * @details Set an HTTP method such as GET, POST, PUT and etc.
696  * @since_tizen 3.0
697  * @remarks The default method is GET.
698  * @param[in]  http_transaction  The http transaction handle
699  * @param[in]  method                    The http method
700  * @return 0 on success, otherwise negative error value
701  * @retval  #HTTP_ERROR_NONE  Successful
702  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
703  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
704  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
705  */
706 int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method);
707
708 /**
709  * @brief Gets the Http method from request header.
710  * @since_tizen 3.0
711  * @param[in]  http_transaction  The http transaction handle
712  * @param[out] method                    The http method
713  * @return 0 on success, otherwise negative error value
714  * @retval  #HTTP_ERROR_NONE  Successful
715  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
716  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
717  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
718  */
719 int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method);
720
721 /**
722  * @brief Sets an HTTP version of the request header.
723  * @since_tizen 3.0
724  * @remarks The default version is HTTP 1.1.
725  * @param[in]  http_transaction The http transaction handle
726  * @param[in]  version                  The http version
727  * @return 0 on success, otherwise negative error value
728  * @retval  #HTTP_ERROR_NONE  Successful
729  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
730  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
731  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
732  */
733 int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version);
734
735 /**
736  * @brief Gets the Http version from request header.
737  * @details Get the Http version.
738  * @since_tizen 3.0
739  * @param[in]  http_transaction The http transaction handle
740  * @param[out]  version                 The http version
741  * @return 0 on success, otherwise negative error value
742  * @retval  #HTTP_ERROR_NONE  Successful
743  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
744  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
745  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
746  */
747 int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version);
748
749 /**
750  * @brief Sets a URI of the request header.
751  * @details Sets a URI of the request header.
752  * @since_tizen 3.0
753  * @remarks It should be used before http_transaction_submit().
754  * @param[in]  http_transaction The http transaction handle
755  * @param[in]  host_uri                 The uri to use in the request
756  * @return 0 on success, otherwise negative error value
757  * @retval  #HTTP_ERROR_NONE  Successful
758  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
759  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
760  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
761  */
762 int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri);
763
764 /**
765  * @brief Gets the uri.
766  * @since_tizen 3.0
767  * @remarks  The @a host_uri should be freed using free().
768  * @param[in]  http_transaction The http transaction handle
769  * @param[out] host_uri                 The host uri
770  * @return 0 on success, otherwise negative error value
771  * @retval  #HTTP_ERROR_NONE  Successful
772  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
773  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
774  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
775  */
776 int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri);
777
778 /**
779  * @brief Sets the Accept-Encoding header field of HttpRequest.
780  * @details The Accept-Encoding header enables automatic decompression of HTTP downloads.
781  * @since_tizen 3.0
782  * @remarks  If empty string is set, an Accept-Encoding header contains all supported built-in compressions.
783  * @param[in]  http_transaction The http transaction handle
784  * @param[in]  encoding                 The encoding algorithms (e.g. gizp, deflate)
785  * @return 0 on success, otherwise negative error value
786  * @retval  #HTTP_ERROR_NONE  Successful
787  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
788  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
789  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
790  */
791 int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding);
792
793 /**
794  * @brief Gets the Accept-Encoding header field of HttpRequest.
795  * @since_tizen 3.0
796  * @remarks  The @a encoding should be freed using free().
797  * @param[in]  http_transaction The http transaction handle
798  * @param[out] encoding                 The encoding algorithms
799  * @return 0 on success, otherwise negative error value
800  * @retval  #HTTP_ERROR_NONE  Successful
801  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
802  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
803  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
804  */
805 int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding);
806
807 /**
808  * @brief Sets a cookie in the HTTP request.
809  * @since_tizen 3.0
810  * @remarks  The format of string should be NME=CONTENTS (e.g. "name1=hello; name2=tizen;")
811  * @param[in]  http_transaction The http transaction handle
812  * @param[in]  cookie                   The cookie
813  * @return 0 on success, otherwise negative error value
814  * @retval  #HTTP_ERROR_NONE  Successful
815  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
816  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
817  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
818  */
819 int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie);
820
821 /**
822  * @brief Gets a cookie in the HTT request.
823  * @since_tizen 3.0
824  * @remarks  The @a cookie should be freed using free().
825  * @param[in]  http_transaction The http transaction handle
826  * @param[out] cookie                   The cookie
827  * @return 0 on success, otherwise negative error value
828  * @retval  #HTTP_ERROR_NONE  Successful
829  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
830  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
831  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
832  */
833 int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie);
834
835 /**
836  * @brief Writes the request message body.
837  * @details This function writes the request message body in the internal queue. \n
838  *                      The written queue for request body is uploaded after invoking http_transaction_submit() 
839  * @since_tizen 3.0
840  * @param[in]  http_transaction The http transaction handle
841  * @param[in]  body                     The message body data
842  * @return 0 on success, otherwise negative error value
843  * @retval  #HTTP_ERROR_NONE  Successful
844  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
845  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
846  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
847  */
848 int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body);
849
850 /**
851  * @}
852  */
853
854 /**
855  * @addtogroup CAPI_NETWORK_HTTP_RESPONSE_MODULE
856  * @{
857  */
858
859 /**
860  * @brief Gets the Http status code from Http Response.
861  * @since_tizen 3.0
862  * @param[in]  http_transaction  The http transaction handle
863  * @param[out] status_code               The http status code
864  * @return 0 on success, otherwise negative error value
865  * @retval  #HTTP_ERROR_NONE  Successful
866  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
867  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
868  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
869  */
870 int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code);
871
872 /**
873  * @brief Gets the Http status text from Http Response.
874  * @since_tizen 3.0
875  * @remarks  The @a status_text should be freed using free().
876  * @param[in]  http_transaction  The http transaction handle
877  * @param[out] status_text       The http status text
878  * @return 0 on success, otherwise negative error value
879  * @retval  #HTTP_ERROR_NONE  Successful
880  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
881  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
882  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
883  */
884 int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text);
885
886 /**
887  * @brief Gets the Http version from Http Response.
888  * @since_tizen 3.0
889  * @param[in]  http_transaction  The http transaction handle
890  * @param[out] version                   The http version
891  * @return 0 on success, otherwise negative error value
892  * @retval  #HTTP_ERROR_NONE  Successful
893  * @retval  #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
894  * @retval  #HTTP_ERROR_INVALID_OPERATION  Invalid operation
895  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
896  */
897 int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version);
898
899 /**
900  * @}
901  */
902
903 #ifdef __cplusplus
904  }
905 #endif
906
907 #endif /* __TIZEN_NETWORK_HTTP_H__ */