#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)
http_create_hash(dest, h_a2_strings, ARRAY_SIZE(h_a2_strings));
http_create_hash(dest, resp_strings, ARRAY_SIZE(resp_strings));
}
+
+char *uclient_get_url_filename(const char *url, const char *default_name)
+{
+ const char *str;
+ int len = strcspn(url, ";&");
+
+ while (len > 0 && url[len - 1] == '/')
+ len--;
+
+ for (str = url + len - 1; str >= url; str--) {
+ if (*str == '/')
+ break;
+ }
+
+ str++;
+ len -= str - url;
+
+ if (len > 0)
+ return strncpy(calloc(1, len + 1), str, len);
+
+ return strdup(default_name);
+}
void http_digest_calculate_auth_hash(char *dest, const char *user, const char *realm, const char *password);
void http_digest_calculate_response(char *dest, const struct http_digest_data *data);
+char *uclient_get_url_filename(const char *url, const char *default_name);
+
#endif