summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOBATA Akio <obache@wizdas.com>2020-02-09 18:51:21 +0900
committerSlávek Banko <slavek.banko@axis.cz>2020-04-06 17:49:50 +0200
commitc4edcdff7565bc1381ee6dc6cbdea0558c64feb2 (patch)
tree0a5a126fddb454f2d2e79d47c3974e7b8ee2632b
parentae9320b8706081773f4693b72ad892423dd9b922 (diff)
downloadlibcarddav-c4edcdff7565bc1381ee6dc6cbdea0558c64feb2.tar.gz
libcarddav-c4edcdff7565bc1381ee6dc6cbdea0558c64feb2.zip
Simplify lock condition
Change to handle as LOCK is not suuported for the case response of LOCK is unimplemented. Then * LOCKSUPPORT == FALSE: LOCK is not suuported * 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 b03db896434a9a2eb7f47690a38750641d97cf5f)
-rw-r--r--src/delete-carddav-object.c18
-rw-r--r--src/modify-carddav-object.c15
2 files changed, 21 insertions, 12 deletions
diff --git a/src/delete-carddav-object.c b/src/delete-carddav-object.c
index 4e3a603..f790965 100644
--- a/src/delete-carddav-object.c
+++ b/src/delete-carddav-object.c
@@ -217,13 +217,16 @@ gboolean carddav_delete(carddav_settings* settings, carddav_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);
@@ -233,7 +236,7 @@ gboolean carddav_delete(carddav_settings* settings, carddav_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) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
}
@@ -402,13 +405,16 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_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);
@@ -418,7 +424,7 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_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) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
}
diff --git a/src/modify-carddav-object.c b/src/modify-carddav-object.c
index 6c97ed3..30015d6 100644
--- a/src/modify-carddav-object.c
+++ b/src/modify-carddav-object.c
@@ -217,13 +217,16 @@ gboolean carddav_modify(carddav_settings* settings, carddav_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);
@@ -234,7 +237,7 @@ gboolean carddav_modify(carddav_settings* settings, carddav_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) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
}
@@ -415,13 +418,13 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_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);
@@ -432,7 +435,7 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_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) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
}