diff options
author | OBATA Akio <obache@wizdas.com> | 2020-05-06 14:31:28 +0900 |
---|---|---|
committer | OBATA Akio <obache@wizdas.com> | 2020-05-06 14:31:28 +0900 |
commit | afa497c628eb6a8a96f234db5215d5c4cc0489af (patch) | |
tree | 8cd9e791db8f25fb550fbe1f8669c88e98d93b5e | |
parent | da62c8127a8396b8623c22c1337d07dcc6d4c2f6 (diff) | |
download | libcaldav-afa497c628eb6a8a96f234db5215d5c4cc0489af.tar.gz libcaldav-afa497c628eb6a8a96f234db5215d5c4cc0489af.zip |
Fix to set error code and message properly
Signed-off-by: OBATA Akio <obache@wizdas.com>
-rw-r--r-- | src/delete-caldav-object.c | 95 | ||||
-rw-r--r-- | src/modify-caldav-object.c | 90 |
2 files changed, 91 insertions, 94 deletions
diff --git a/src/delete-caldav-object.c b/src/delete-caldav-object.c index 3e5c078..f55eae3 100644 --- a/src/delete-caldav-object.c +++ b/src/delete-caldav-object.c @@ -200,6 +200,8 @@ gboolean caldav_delete(caldav_settings* settings, caldav_error* error) { if (url) { int lock = 0; caldav_error lock_error; + lock_error.code = 0; + lock_error.str = NULL; file = g_strdup(etag); g_free(etag); @@ -254,37 +256,37 @@ gboolean caldav_delete(caldav_settings* settings, caldav_error* error) { curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); res = curl_easy_perform(curl); + if (res != 0) { + error->code = -1; + error->str = g_strdup_printf("%s", error_buf); + result = TRUE; + } + else { + long code; + res = curl_easy_getinfo( + curl, CURLINFO_RESPONSE_CODE, &code); + if (code != 204) { + error->code = code; + error->str = g_strdup(chunk.memory); + result = TRUE; + } + } if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } } + else { + error->code = lock_error.code; + error->str = g_strdup(lock_error.str); + result = TRUE; + } g_free(url); g_free(lock_token); - if (res != 0 || lock < 0) { - /* Is this a lock_error don't change error*/ - if (lock == 0 || lock_error.code == 423) { - error->code = code; - error->str = g_strdup(chunk.memory); - } - else { - error->code = lock_error.code; - error->str = g_strdup(lock_error.str); - } - result = TRUE; + if (result) { g_free(settings->file); settings->file = NULL; } - else { - long code; - res = curl_easy_getinfo( - curl, CURLINFO_RESPONSE_CODE, &code); - if (code != 204) { - error->code = code; - error->str = g_strdup(chunk.memory); - result = TRUE; - } - } curl_slist_free_all(http_header); } else { @@ -433,6 +435,8 @@ gboolean caldav_tasks_delete(caldav_settings* settings, caldav_error* error) { if (url) { int lock = 0; caldav_error lock_error; + lock_error.code = 0; + lock_error.str = NULL; file = g_strdup(etag); g_free(etag); @@ -487,45 +491,42 @@ gboolean caldav_tasks_delete(caldav_settings* settings, caldav_error* error) { curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); res = curl_easy_perform(curl); + if (res != 0) { + error->code = -1; + error->str = g_strdup_printf("%s", error_buf); + result = TRUE; + } + else { + long code; + res = curl_easy_getinfo( + curl, CURLINFO_RESPONSE_CODE, &code); + if (code != 204) { + error->code = code; + error->str = g_strdup(chunk.memory); + result = TRUE; + } + } if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } } + else { + error->code = lock_error.code; + error->str = g_strdup(lock_error.str); + result = TRUE; + } g_free(url); g_free(lock_token); - if (res != 0 || lock < 0) { - /* Is this a lock_error don't change error*/ - if (lock == 0 || lock_error.code == 423) { - error->code = code; - error->str = g_strdup(chunk.memory); - } - else { - error->code = lock_error.code; - error->str = g_strdup(lock_error.str); - } - result = TRUE; + if (result) { g_free(settings->file); settings->file = NULL; } - else { - long code; - res = curl_easy_getinfo( - curl, CURLINFO_RESPONSE_CODE, &code); - if (code != 204) { - error->code = code; - error->str = g_strdup(chunk.memory); - result = TRUE; - } - } curl_slist_free_all(http_header); } else { - error->code = code; - if (chunk.memory) - error->str = g_strdup(chunk.memory); - else - error->str = g_strdup("No object found"); + error->code = -1; + error->str = g_strdup("No object found"); result = TRUE; } } diff --git a/src/modify-caldav-object.c b/src/modify-caldav-object.c index 3db1e59..67bdb54 100644 --- a/src/modify-caldav-object.c +++ b/src/modify-caldav-object.c @@ -200,6 +200,8 @@ gboolean caldav_modify(caldav_settings* settings, caldav_error* error) { if (url) { int lock = 0; caldav_error lock_error; + lock_error.code = 0; + lock_error.str = NULL; file = g_strdup(etag); g_free(etag); @@ -255,37 +257,37 @@ gboolean caldav_modify(caldav_settings* settings, caldav_error* error) { curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); res = curl_easy_perform(curl); + if (res != 0) { + error->code = -1; + error->str = g_strdup_printf("%s", error_buf); + result = TRUE; + } + else { + long code; + res = curl_easy_getinfo( + cur, CURLINFO_RESPONSE_CODE, &code); + if (code != 204) { + error->code = code; + error->str = g_strdup(chunk.memory); + result = TRUE; + } + } if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } } + else { + error->code = lock_error.code; + error->str = g_strdup(lock_error.str); + result = TRUE; + } g_free(url); g_free(lock_token); - if (res != 0 || lock < 0) { - /* Is this a lock_error don't change error*/ - if (lock == 0 || lock_error.code == 423) { - error->code = code; - error->str = g_strdup(chunk.memory); - } - else { - error->code = lock_error.code; - error->str = g_strdup(lock_error.str); - } - result = TRUE; + if (result) { g_free(settings->file); settings->file = NULL; } - else { - long code; - res = curl_easy_getinfo( - curl, CURLINFO_RESPONSE_CODE, &code); - if (code != 204) { - error->code = code; - error->str = g_strdup(chunk.memory); - result = TRUE; - } - } curl_slist_free_all(http_header); } else { @@ -443,6 +445,8 @@ gboolean caldav_tasks_modify(caldav_settings* settings, caldav_error* error) { if (url) { int lock = 0; caldav_error lock_error; + lock_error.code = 0; + lock_error.str = NULL; file = g_strdup(etag); g_free(etag); @@ -495,6 +499,21 @@ gboolean caldav_tasks_modify(caldav_settings* settings, caldav_error* error) { curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); res = curl_easy_perform(curl); + if (res != 0) { + error->code = -1; + error->str = g_strdup_printf("%s", error_buf); + result = TRUE; + } + else { + long code; + res = curl_easy_getinfo( + curl, CURLINFO_RESPONSE_CODE, &code); + if (code != 204) { + error->code = code; + error->str = g_strdup(chnk.memory); + result = TRUE; + } + } if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); @@ -502,38 +521,15 @@ gboolean caldav_tasks_modify(caldav_settings* settings, caldav_error* error) { } g_free(url); g_free(lock_token); - if (res != 0 || lock < 0) { - /* Is this a lock_error don't change error*/ - if (lock == 0 || lock_error.code == 423) { - error->code = code; - error->str = g_strdup(chunk.memory); - } - else { - error->code = lock_error.code; - error->str = g_strdup(lock_error.str); - } - result = TRUE; + if (result) { g_free(settings->file); settings->file = NULL; } - else { - long code; - res = curl_easy_getinfo( - curl, CURLINFO_RESPONSE_CODE, &code); - if (code != 204) { - error->code = code; - error->str = g_strdup(chunk.memory); - result = TRUE; - } - } curl_slist_free_all(http_header); } else { - error->code = code; - if (chunk.memory) - error->str = g_strdup(chunk.memory); - else - error->str = g_strdup("No object found"); + error->code = -1; + error->str = g_strdup("No object found"); result = TRUE; } } |