diff options
author | OBATA Akio <obache@wizdas.com> | 2020-05-06 14:03:34 +0900 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2020-05-06 10:55:28 +0200 |
commit | 1878ff088b3b08876c607d9caf8bada1f6c16956 (patch) | |
tree | cdd5462dad88fa630fda008f64d2759db00e3095 | |
parent | f9ba2ffabd0fae01d702ea65f30f9b6422cd65bb (diff) | |
download | libcaldav-1878ff088b3b08876c607d9caf8bada1f6c16956.tar.gz libcaldav-1878ff088b3b08876c607d9caf8bada1f6c16956.zip |
Simplify lock condition
Change to handle as LOCK is not supported for the case response of LOCK is
unimplemented.
Then
* LOCKSUPPORT == FALSE: LOCK is not supported
* LOCKSUPPORT == TRUE: LOCK is supported
* lock == 0: no LOCK error
* lock == -1: failed to LOCK
Signed-off-by: OBATA Akio <obache@wizdas.com>
(cherry picked from commit da62c8127a8396b8623c22c1337d07dcc6d4c2f6)
-rw-r--r-- | src/delete-caldav-object.c | 18 | ||||
-rw-r--r-- | src/modify-caldav-object.c | 15 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/delete-caldav-object.c b/src/delete-caldav-object.c index 9a85168..3e5c078 100644 --- a/src/delete-caldav-object.c +++ b/src/delete-caldav-object.c @@ -235,13 +235,16 @@ gboolean caldav_delete(caldav_settings* settings, caldav_error* error) { * hoping for the best. */ else if (lock_error.code == 501) { - lock_token = g_strdup(""); + lock_error.code = 0; + g_free(lock_error.str); + lock_error.str = NULL; + LOCKSUPPORT = FALSE; } else { lock = -1; } } - if (! LOCKSUPPORT || (LOCKSUPPORT && lock_token && lock_error.code != 423)) { + if (lock == 0) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header); curl_easy_setopt(curl, CURLOPT_URL, rebuild_url(settings, url)); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL); @@ -251,7 +254,7 @@ 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 (LOCKSUPPORT && lock_token) { + if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } @@ -465,13 +468,16 @@ gboolean caldav_tasks_delete(caldav_settings* settings, caldav_error* error) { * hoping for the best. */ else if (lock_error.code == 501) { - lock_token = g_strdup(""); + lock_error.code = 0; + g_free(lock_error.str); + lock_error.str = NULL; + LOCKSUPPORT = FALSE; } else { lock = -1; } } - if (! LOCKSUPPORT || (LOCKSUPPORT && lock_token && lock_error.code != 423)) { + if (lock == 0) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header); curl_easy_setopt(curl, CURLOPT_URL, rebuild_url(settings, url)); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL); @@ -481,7 +487,7 @@ 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 (LOCKSUPPORT && lock_token) { + if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } diff --git a/src/modify-caldav-object.c b/src/modify-caldav-object.c index fb3a4d0..3db1e59 100644 --- a/src/modify-caldav-object.c +++ b/src/modify-caldav-object.c @@ -235,13 +235,16 @@ gboolean caldav_modify(caldav_settings* settings, caldav_error* error) { * hoping for the best. */ else if (lock_error.code == 501) { - lock_token = g_strdup(""); + lock_error.code = 0; + g_free(lock_error.str); + lock_error.str = NULL; + LOCKSUPPORT = FALSE; } else { lock = -1; } } - if (! LOCKSUPPORT || (LOCKSUPPORT && lock_token && lock_error.code != 423)) { + if (lock == 0) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header); curl_easy_setopt(curl, CURLOPT_URL, rebuild_url(settings, url)); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, settings->file); @@ -252,7 +255,7 @@ 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 (LOCKSUPPORT && lock_token) { + if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } @@ -475,13 +478,13 @@ gboolean caldav_tasks_modify(caldav_settings* settings, caldav_error* error) { * hoping for the best. */ else if (lock_error.code == 501) { - lock_token = g_strdup(""); + LOCKSUPPORT = FALSE; } else { lock = -1; } } - if (! LOCKSUPPORT || (LOCKSUPPORT && lock_token && lock_error.code != 423)) { + if (lock == 0) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header); curl_easy_setopt(curl, CURLOPT_URL, rebuild_url(settings, url)); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, settings->file); @@ -492,7 +495,7 @@ 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 (LOCKSUPPORT && lock_token) { + if (LOCKSUPPORT) { caldav_unlock_object( lock_token, url, settings, &lock_error); } |