#include <libubox/blobmsg.h>
#include "uclient.h"
+#include "uclient-utils.h"
#ifdef __APPLE__
#define LIB_EXT "dylib"
static int open_output_file(const char *path, bool create)
{
- const char *str;
char *filename;
- int len;
int flags = O_WRONLY;
+ int ret;
if (create)
flags |= O_CREAT;
if (create)
flags |= O_EXCL;
- len = strcspn(path, ";&");
- while (len > 0 && path[len - 1] == '/')
- len--;
-
- for (str = path + len - 1; str >= path; str--) {
- if (*str == '/')
- break;
- }
-
- str++;
- len -= str - path;
-
- if (len > 0) {
- filename = alloca(len + 1);
- strncpy(filename, str, len);
- filename[len] = 0;
- } else {
- filename = "index.html";
- }
+ filename = uclient_get_url_filename(path, "index.html");
+ ret = open(filename, flags, 0644);
+ free(filename);
- return open(filename, flags, 0644);
+ return ret;
}
static void request_done(struct uclient *cl)
{
static int retries;
- struct blob_attr *cur;
- int rem;
-
if (retries < 10 && uclient_http_redirect(cl)) {
if (!quiet)
fprintf(stderr, "Redirected to %s on %s\n", cl->url->location, cl->url->host);
}
retries = 0;
- if (!quiet) {
- fprintf(stderr, "Headers (%d): \n", cl->status_code);
- blobmsg_for_each_attr(cur, cl->meta, rem) {
- fprintf(stderr, "%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
- }
- }
-
switch (cl->status_code) {
case 204:
case 200:
break;
default:
+ if (!quiet)
+ fprintf(stderr, "HTTP error %d\n", cl->status_code);
request_done(cl);
error_ret = 8;
break;