summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOBATA Akio <[email protected]>2020-02-15 18:41:49 +0900
committerTDE Gitea <[email protected]>2020-04-06 15:49:00 +0000
commitb3bb3dbd4b7546e4affdb94d2b77735a67da1dcd (patch)
tree8aa7992847dd4d7c15af995cf1a4524956d6c624
parentb03db896434a9a2eb7f47690a38750641d97cf5f (diff)
downloadlibcarddav-b3bb3dbd4b7546e4affdb94d2b77735a67da1dcd.tar.gz
libcarddav-b3bb3dbd4b7546e4affdb94d2b77735a67da1dcd.zip
Fix to set error code and message properly
Signed-off-by: OBATA Akio <[email protected]>
-rw-r--r--src/delete-carddav-object.c96
-rw-r--r--src/modify-carddav-object.c91
2 files changed, 91 insertions, 96 deletions
diff --git a/src/delete-carddav-object.c b/src/delete-carddav-object.c
index f790965..f838c7a 100644
--- a/src/delete-carddav-object.c
+++ b/src/delete-carddav-object.c
@@ -182,6 +182,8 @@ gboolean carddav_delete(carddav_settings* settings, carddav_error* error) {
if (url) {
int lock = 0;
carddav_error lock_error;
+ lock_error.code = 0;
+ lock_error.str = NULL;
file = g_strdup(etag);
g_free(etag);
@@ -236,37 +238,37 @@ 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 (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) {
carddav_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 {
@@ -353,7 +355,6 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_error* error)
// Use the given URI to issue the delete command
/* enable uploading */
- long code;
gchar* url = NULL;
gchar* etag = NULL;
url = uid;
@@ -370,6 +371,8 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_error* error)
if (url) {
int lock = 0;
carddav_error lock_error;
+ lock_error.code = 0;
+ lock_error.str = NULL;
file = g_strdup(etag);
g_free(etag);
@@ -424,45 +427,42 @@ 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 (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) {
carddav_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-carddav-object.c b/src/modify-carddav-object.c
index 30015d6..a6a9c84 100644
--- a/src/modify-carddav-object.c
+++ b/src/modify-carddav-object.c
@@ -182,6 +182,8 @@ gboolean carddav_modify(carddav_settings* settings, carddav_error* error) {
if (url) {
int lock = 0;
carddav_error lock_error;
+ lock_error.code = 0;
+ lock_error.str = NULL;
file = g_strdup(etag);
g_free(etag);
@@ -237,37 +239,37 @@ 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 (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) {
carddav_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 {
@@ -363,7 +365,6 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_error* error)
g_free(file);
/* enable uploading */
- long code;
gchar* url = NULL;
gchar* etag = NULL;
url = uid;
@@ -383,6 +384,8 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_error* error)
if (url) {
int lock = 0;
carddav_error lock_error;
+ lock_error.code = 0;
+ lock_error.str = NULL;
file = g_strdup(etag);
g_free(etag);
@@ -435,6 +438,21 @@ 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 (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) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
@@ -442,38 +460,15 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_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;
}
}