Fix to set error code and message properly

Signed-off-by: OBATA Akio <obache@wizdas.com>
pull/5/head
OBATA Akio 4 years ago committed by TDE Gitea
parent b03db89643
commit b3bb3dbd4b

@ -182,6 +182,8 @@ gboolean carddav_delete(carddav_settings* settings, carddav_error* error) {
if (url) { if (url) {
int lock = 0; int lock = 0;
carddav_error lock_error; carddav_error lock_error;
lock_error.code = 0;
lock_error.str = NULL;
file = g_strdup(etag); file = g_strdup(etag);
g_free(etag); g_free(etag);
@ -236,26 +238,10 @@ gboolean carddav_delete(carddav_settings* settings, carddav_error* error) {
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1); curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (LOCKSUPPORT) { if (res != 0 ) {
carddav_unlock_object( error->code = -1;
lock_token, url, settings, &lock_error); error->str = g_strdup_printf("%s", error_buf);
}
}
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; result = TRUE;
g_free(settings->file);
settings->file = NULL;
} }
else { else {
long code; long code;
@ -267,6 +253,22 @@ gboolean carddav_delete(carddav_settings* settings, carddav_error* error) {
result = TRUE; 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 (result) {
g_free(settings->file);
settings->file = NULL;
}
curl_slist_free_all(http_header); curl_slist_free_all(http_header);
} }
else { 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 // Use the given URI to issue the delete command
/* enable uploading */ /* enable uploading */
long code;
gchar* url = NULL; gchar* url = NULL;
gchar* etag = NULL; gchar* etag = NULL;
url = uid; url = uid;
@ -370,6 +371,8 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_error* error)
if (url) { if (url) {
int lock = 0; int lock = 0;
carddav_error lock_error; carddav_error lock_error;
lock_error.code = 0;
lock_error.str = NULL;
file = g_strdup(etag); file = g_strdup(etag);
g_free(etag); g_free(etag);
@ -424,26 +427,10 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_error* error)
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1); curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (LOCKSUPPORT) { if (res != 0) {
carddav_unlock_object( error->code = -1;
lock_token, url, settings, &lock_error); error->str = g_strdup_printf("%s", error_buf);
}
}
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; result = TRUE;
g_free(settings->file);
settings->file = NULL;
} }
else { else {
long code; long code;
@ -455,13 +442,26 @@ gboolean carddav_delete_by_uri(carddav_settings* settings, carddav_error* error)
result = TRUE; 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 (result) {
g_free(settings->file);
settings->file = NULL;
}
curl_slist_free_all(http_header); curl_slist_free_all(http_header);
} }
else { else {
error->code = code; error->code = 1;
if (chunk.memory)
error->str = g_strdup(chunk.memory);
else
error->str = g_strdup("No object found"); error->str = g_strdup("No object found");
result = TRUE; result = TRUE;
} }

@ -182,6 +182,8 @@ gboolean carddav_modify(carddav_settings* settings, carddav_error* error) {
if (url) { if (url) {
int lock = 0; int lock = 0;
carddav_error lock_error; carddav_error lock_error;
lock_error.code = 0;
lock_error.str = NULL;
file = g_strdup(etag); file = g_strdup(etag);
g_free(etag); g_free(etag);
@ -237,26 +239,10 @@ gboolean carddav_modify(carddav_settings* settings, carddav_error* error) {
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (LOCKSUPPORT) { if (res != 0) {
carddav_unlock_object( error->code = -1;
lock_token, url, settings, &lock_error); error->str = g_strdup_printf("%s", error_buf);
}
}
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; result = TRUE;
g_free(settings->file);
settings->file = NULL;
} }
else { else {
long code; long code;
@ -268,6 +254,22 @@ gboolean carddav_modify(carddav_settings* settings, carddav_error* error) {
result = TRUE; 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 (result) {
g_free(settings->file);
settings->file = NULL;
}
curl_slist_free_all(http_header); curl_slist_free_all(http_header);
} }
else { else {
@ -363,7 +365,6 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_error* error)
g_free(file); g_free(file);
/* enable uploading */ /* enable uploading */
long code;
gchar* url = NULL; gchar* url = NULL;
gchar* etag = NULL; gchar* etag = NULL;
url = uid; url = uid;
@ -383,6 +384,8 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_error* error)
if (url) { if (url) {
int lock = 0; int lock = 0;
carddav_error lock_error; carddav_error lock_error;
lock_error.code = 0;
lock_error.str = NULL;
file = g_strdup(etag); file = g_strdup(etag);
g_free(etag); g_free(etag);
@ -435,26 +438,10 @@ 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_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (LOCKSUPPORT) { if (res != 0) {
carddav_unlock_object( error->code = -1;
lock_token, url, settings, &lock_error); error->str = g_strdup_printf("%s", error_buf);
}
}
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; result = TRUE;
g_free(settings->file);
settings->file = NULL;
} }
else { else {
long code; long code;
@ -466,13 +453,21 @@ gboolean carddav_modify_by_uri(carddav_settings* settings, carddav_error* error)
result = TRUE; result = TRUE;
} }
} }
if (LOCKSUPPORT) {
carddav_unlock_object(
lock_token, url, settings, &lock_error);
}
}
g_free(url);
g_free(lock_token);
if (result) {
g_free(settings->file);
settings->file = NULL;
}
curl_slist_free_all(http_header); curl_slist_free_all(http_header);
} }
else { else {
error->code = code; error->code = -1;
if (chunk.memory)
error->str = g_strdup(chunk.memory);
else
error->str = g_strdup("No object found"); error->str = g_strdup("No object found");
result = TRUE; result = TRUE;
} }

Loading…
Cancel
Save