Skip to content

Commit

Permalink
webdav: add logging around http transactions to try to track failures (
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven authored Oct 26, 2024
1 parent 55d6a03 commit b955a2f
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions network/cloud_sync/webdav.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static char *webdav_get_auth_header(const char *method, const char *url)
static void webdav_log_http_failure(const char *path, http_transfer_data_t *data)
{
size_t i;
RARCH_WARN("webdav failed: %s: HTTP %d\n", path, data->status);
RARCH_WARN("[webdav] failed: %s: HTTP %d\n", path, data->status);
for (i = 0; data->headers && i < data->headers->size; i++)
RARCH_WARN("%s\n", data->headers->elems[i].data);
if (data->data)
Expand All @@ -467,6 +467,9 @@ static void webdav_stat_cb(retro_task_t *task, void *task_data, void *user_data,
if (!webdav_cb_st)
return;

if (!data)
RARCH_WARN("[webdav] did not get data for stat, is the server down?\n");

if (data && data->status == 401 && data->headers && webdav_st->basic == true)
{
size_t i;
Expand All @@ -476,6 +479,7 @@ static void webdav_stat_cb(retro_task_t *task, void *task_data, void *user_data,
if (!string_starts_with(data->headers->elems[i].data, "WWW-Authenticate: Digest "))
continue;

RARCH_DBG("[webdav] found WWW-Authenticate: Digest header\n");
if (webdav_create_digest_auth(data->headers->elems[i].data))
{
task_push_webdav_stat(webdav_st->url, true,
Expand All @@ -484,7 +488,7 @@ static void webdav_stat_cb(retro_task_t *task, void *task_data, void *user_data,
return;
}
else
RARCH_WARN("failure creating WWW-Authenticate: Digest header\n");
RARCH_WARN("[webdav] failure creating WWW-Authenticate: Digest header\n");
}
}

Expand Down Expand Up @@ -529,7 +533,10 @@ static bool webdav_sync_begin(cloud_sync_complete_handler_t cb, void *user_data)
task_push_webdav_stat(webdav_st->url, true, auth_header, webdav_stat_cb, webdav_cb_st);
}
else
{
RARCH_WARN("[webdav] no basic auth header, assuming no user, check username/password?\n");
cb(user_data, NULL, true, NULL);
}
return true;
}

Expand Down Expand Up @@ -618,6 +625,8 @@ static void webdav_mkdir_cb(retro_task_t *task, void *task_data, void *user_data
{
if (data)
webdav_log_http_failure(webdav_mkdir_st->url, data);
else
RARCH_WARN("[webdav] could not mkdir %s\n", webdav_mkdir_st ? webdav_mkdir_st->url : "<unknown>");
webdav_mkdir_st->cb(false, webdav_mkdir_st->cb_st);
free(webdav_mkdir_st);
return;
Expand All @@ -628,12 +637,14 @@ static void webdav_mkdir_cb(retro_task_t *task, void *task_data, void *user_data
if (webdav_mkdir_st->last_slash)
{
*webdav_mkdir_st->last_slash = '\0';
RARCH_DBG("[webdav] MKCOL %s\n", webdav_mkdir_st->url);
task_push_webdav_mkdir(webdav_mkdir_st->url, true,
webdav_get_auth_header("MKCOL", webdav_mkdir_st->url),
webdav_mkdir_cb, webdav_mkdir_st);
}
else
{
RARCH_DBG("[webdav] MKCOL %s success\n", webdav_mkdir_st->url);
webdav_mkdir_st->cb(true, webdav_mkdir_st->cb_st);
free(webdav_mkdir_st);
}
Expand Down Expand Up @@ -665,13 +676,17 @@ static void webdav_update_cb(retro_task_t *task, void *task_data, void *user_dat

if (!success && data)
webdav_log_http_failure(webdav_cb_st->path, data);
else if (!data)
RARCH_WARN("[webdav] could not upload %s\n", webdav_cb_st ? webdav_cb_st->path : "<unknown>");

/* TODO: it's possible we get a 401 here and need to redo the auth check with this request */
if (webdav_cb_st)
{
webdav_cb_st->cb(webdav_cb_st->user_data, webdav_cb_st->path, success, webdav_cb_st->rfile);
free(webdav_cb_st);
}
else
RARCH_WARN("[webdav] missing cb data in update?\n");
}

static void webdav_do_update(bool success, webdav_cb_state_t *webdav_cb_st)
Expand All @@ -687,6 +702,7 @@ static void webdav_do_update(bool success, webdav_cb_state_t *webdav_cb_st)

if (!success)
{
RARCH_DBG("[webdav] cannot upload %s\n", webdav_cb_st->path);
webdav_cb_st->cb(webdav_cb_st->user_data, webdav_cb_st->path, false, webdav_cb_st->rfile);
free(webdav_cb_st);
return;
Expand All @@ -700,6 +716,7 @@ static void webdav_do_update(bool success, webdav_cb_state_t *webdav_cb_st)
fill_pathname_join_special(url, webdav_st->url, webdav_cb_st->path, sizeof(url));
net_http_urlencode_full(url_encoded, url, sizeof(url_encoded));

RARCH_DBG("[webdav] PUT %s\n", url_encoded);
task_push_webdav_put(url_encoded, buf, len, true,
webdav_get_auth_header("PUT", url_encoded),
webdav_update_cb, webdav_cb_st);
Expand Down Expand Up @@ -737,14 +754,18 @@ static void webdav_delete_cb(retro_task_t *task, void *task_data, void *user_dat
bool success = (data != NULL && data->status >= 200 && data->status < 300);

if (!success && data)
webdav_log_http_failure(webdav_cb_st->path, data);
webdav_log_http_failure(webdav_cb_st->path, data);
else if (!data)
RARCH_WARN("[webdav] could not delete %s\n", webdav_cb_st ? webdav_cb_st->path : "<unknown>");

/* TODO: it's possible we get a 401 here and need to redo the auth check with this request */
if (webdav_cb_st)
{
webdav_cb_st->cb(webdav_cb_st->user_data, webdav_cb_st->path, success, NULL);
free(webdav_cb_st);
}
else
RARCH_WARN("[webdav] missing cb data in delete?\n");
}

static void webdav_backup_cb(retro_task_t *task, void *task_data, void *user_data, const char *err)
Expand All @@ -755,13 +776,17 @@ static void webdav_backup_cb(retro_task_t *task, void *task_data, void *user_dat

if (!success && data)
webdav_log_http_failure(webdav_cb_st->path, data);
else if (!data)
RARCH_WARN("[webdav] could not backup %s\n", webdav_cb_st ? webdav_cb_st->path : "<unknown>");

/* TODO: it's possible we get a 401 here and need to redo the auth check with this request */
if (webdav_cb_st)
{
webdav_cb_st->cb(webdav_cb_st->user_data, webdav_cb_st->path, success, NULL);
free(webdav_cb_st);
}
else
RARCH_WARN("[webdav] missing cb data in backup?\n");
}

static void webdav_do_backup(bool success, webdav_cb_state_t *webdav_cb_st)
Expand All @@ -780,6 +805,7 @@ static void webdav_do_backup(bool success, webdav_cb_state_t *webdav_cb_st)

if (!success)
{
RARCH_DBG("[webdav] cannot backup/delete %s\n", webdav_cb_st->path);
webdav_cb_st->cb(webdav_cb_st->user_data, webdav_cb_st->path, false, NULL);
free(webdav_cb_st);
return;
Expand All @@ -794,6 +820,7 @@ static void webdav_do_backup(bool success, webdav_cb_state_t *webdav_cb_st)
strftime(dest + len, sizeof(dest) - len, "-%y%m%d-%H%M%S", &tm_);
net_http_urlencode_full(dest_encoded, dest, sizeof(dest_encoded));

RARCH_DBG("[webdav] MOVE %s -> %s\n", url_encoded, dest_encoded);
task_push_webdav_move(url_encoded, dest_encoded, true,
webdav_get_auth_header("MOVE", url_encoded),
webdav_backup_cb, webdav_cb_st);
Expand Down Expand Up @@ -822,6 +849,7 @@ static bool webdav_delete(const char *path, cloud_sync_complete_handler_t cb, vo
fill_pathname_join_special(url, webdav_st->url, path, sizeof(url));
net_http_urlencode_full(url_encoded, url, sizeof(url_encoded));

RARCH_DBG("[webdav] DELETE %s\n", url_encoded);
task_push_webdav_delete(url_encoded, true,
webdav_get_auth_header("DELETE", url_encoded),
webdav_delete_cb, webdav_cb_st);
Expand Down

0 comments on commit b955a2f

Please sign in to comment.