HTTP_ERROR_COULDNT_CONNECT = TIZEN_ERROR_HTTP|0x07, /**< Couldn't Connect to host */
HTTP_ERROR_OPERATION_TIMEDOUT = TIZEN_ERROR_HTTP|0x28, /**< Timeout */
HTTP_ERROR_SSL_CONNECT_ERROR = TIZEN_ERROR_HTTP|0x35, /**< SSL Error */
+ HTTP_ERROR_CANCELED = TIZEN_ERROR_CANCELED, /**< Operation Canceled */
HTTP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< API is not supported */
} http_error_code_e;
int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type);
/**
+ * @brief Cancels the transaction.
+ * @details This function cancels the transaction.\n
+ * The aborted callback is invoked after using it.
+ * @since_tizen 3.0
+ * @param[in] http_transaction The http transaction handle
+ * @return 0 on success, otherwise negative error value
+ * @retval #HTTP_ERROR_NONE Successful
+ * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #HTTP_ERROR_OPERATION_FAILED Operation failed
+ * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
+ */
+int http_transaction_cancel(http_transaction_h http_transaction);
+
+/**
* @brief Sets ready to write event for a transaction.
* @since_tizen 3.0
* @param[in] http_transaction The http transaction handle
int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body);
/**
+ * @brief Sets the file path for uploading a file.
+ * @since_tizen 3.0
+ * @remarks It is used with #HTTP_METHOD_PUT
+ * @param[in] http_transaction The http transaction handle
+ * @param[in] file_path The path for file
+ * @return 0 on success, otherwise negative error value
+ * @retval #HTTP_ERROR_NONE Successful
+ * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
+ */
+int http_transaction_request_set_upload_file(http_transaction_h http_transaction, const char *file_path);
+
+/**
* @}
*/
*/
int http_transaction_get_realm(http_transaction_h http_transaction, char **realm);
+
/**
* @}
*/
} http_formdata_type_e;
/**
- * @brief Sets file path for uploading a file.
- * @since_tizen 3.0
- * @remarks It is used with #HTTP_METHOD_PUT
- * @param[in] http_transaction The http transaction handle
- * @param[in] file_path The path for file
- * @return 0 on success, otherwise negative error value
- * @retval #HTTP_ERROR_NONE Successful
- * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
- * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
- */
-int http_transaction_request_set_upload_file(http_transaction_h http_transaction, const char *file_path);
-
-/**
* @brief Adds the multipart/form-data.
* @since_tizen 3.0
* @remarks It is used with #HTTP_METHOD_POST
bool verify_peer;
gchar *ca_path;
gchar error[CURL_ERROR_SIZE];
+ bool cancel;
/*Authentication Info*/
bool auth_required;
Name: capi-network-http
Summary: Http Framework
-Version: 0.0.13
+Version: 0.0.14
Release: 0
Group: System/Network
License: Apache-2.0
if (transaction->aborted_cb)
transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data);
break;
+ case CURLE_ABORTED_BY_CALLBACK:
+ if (transaction->aborted_cb)
+ transaction->aborted_cb(transaction, HTTP_ERROR_CANCELED, transaction->aborted_user_data);
+ break;
default:
if (transaction->aborted_cb)
transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_FAILED, transaction->aborted_user_data);
transaction->progress_cb(transaction, total_download, current_download,
total_upload, current_upload, transaction->progress_user_data);
- return 0;
+ return transaction->cancel;
}
//LCOV_EXCL_START
}
//LCOV_EXCL_STOP
+API int http_transaction_cancel(http_transaction_h http_transaction)
+{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
+ _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(http_transaction) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+
+ transaction->cancel = true;
+
+ return HTTP_ERROR_NONE;
+}
+
API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data)
{
_retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
FILE* fp2 = NULL;
http_session_h session = NULL;
+int cancel = 0;
+
void _register_callbacks(http_transaction_h transaction);
void _write_message_body(http_transaction_h transaction, const char *file_path);
{
PRG("transaction_aborted_cb", transaction);
DBG("aborted reason: %d\n", reason);
+
+ int ret = http_transaction_destroy(transaction);
+ if (ret == HTTP_ERROR_NONE) DBG("Success to close transaction\n");
+ else DBG("Fail to close transaction\n");
+
+ transaction = NULL;
+ cancel = 0;
}
void __transaction_progress_cb(http_transaction_h transaction, double download_total, double download_now, double upload_total, double upload_now, void *user_data)
{
PRG("__transaction_progress_cb", transaction);
- DBG("Download ====>: DOWN(%lf/%lf)\n", download_total, download_now);
- DBG("Upload ====>: UP(%lf/%lf)\n", upload_total, upload_now);
+
+ if (cancel)
+ http_transaction_cancel(transaction);
}
void _register_callbacks(http_transaction_h transaction)
return 1;
}
+int test_cancel(void)
+{
+ char uri[1024];
+ int ret;
+ http_transaction_h transaction = NULL;
+ http_method_e method;
+
+ cancel = 1;
+
+ printf("Input uri: ");
+ ret = scanf("%1023s", uri);
+
+ ret = http_session_open_transaction(session, HTTP_METHOD_GET, &transaction);
+ if (ret != 0) {
+ ERR("Fail to open transaction", ret);
+ return 0;
+ }
+
+ http_transaction_request_get_method(transaction, &method);
+ ret = http_transaction_request_set_uri(transaction, uri);
+ if (ret != 0) {
+ ERR("Fail to set URI", ret);
+ return 0;
+ }
+
+ _register_callbacks(transaction);
+ ret = http_transaction_submit(transaction);
+
+ if (ret != 0) {
+ ERR("Fail to submit transaction", ret);
+ return 0;
+ }
+
+ return 1;
+}
+
gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
{
int rv;
printf("9 - Simple Authentication GET\n");
printf("a - Upload file (PUT)\n");
printf("b - Upload file (POST)\n");
+ printf("c - Cancel\n");
printf("0 - Exit \n");
printf("ENTER - Show options menu.......\n");
}
case 'b':
rv = test_post_chunk();
break;
+ case 'c':
+ rv = test_cancel();
+ break;
}
if (rv == 1)