aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-06 19:24:02 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-06 19:24:02 +0200
commitc0453c34a58aac8150300ab829149a0ca4d9e5ee (patch)
tree615f1fc4efe819af7d0518c7cdddf754dfb62b87 /src
parente6298876fdbf457b6dd61556472060a9fa652c82 (diff)
upload of files
Change-Id: Ifbe226ddc11f67223b4215db66af1ad1108a11f5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/afb-hreq.c39
-rw-r--r--src/afb-hsrv.c7
2 files changed, 37 insertions, 9 deletions
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index 474b90e8..7c481e95 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -447,9 +447,29 @@ int afb_hreq_post_add(struct afb_hreq *hreq, const char *key, const char *data,
int afb_hreq_post_add_file(struct afb_hreq *hreq, const char *key, const char *file, const char *data, size_t size)
{
+ ssize_t sz;
struct hreq_data *hdat = get_data(hreq, key, 1);
- /* continuation with reopening */
+ if (hdat->value == NULL) {
+ hdat->file = open(file, O_WRONLY|O_TRUNC|O_CREAT, 0600);
+ if (hdat->file == 0) {
+ hdat->file = dup(0);
+ close(0);
+ }
+ if (hdat->file <= 0) {
+ hdat->file = 0;
+ return 0;
+ }
+ hdat->value = strdup(file);
+ if (hdat->value == NULL) {
+ close(hdat->file);
+ hdat->file = 0;
+ return 0;
+ }
+ } else {
+ if (strcmp(hdat->value, file))
+ return 0;
+ }
if (hdat->file < 0) {
hdat->file = open(hdat->value, O_WRONLY|O_APPEND);
if (hdat->file == 0) {
@@ -459,15 +479,16 @@ int afb_hreq_post_add_file(struct afb_hreq *hreq, const char *key, const char *f
if (hdat->file <= 0)
return 0;
}
- if (hdat->file > 0) {
- write(hdat->file, data, size);
- return 1;
+ while (size) {
+ sz = write(hdat->file, data, size);
+ if (sz >= 0) {
+ hdat->length += (size_t)sz;
+ size -= (size_t)sz;
+ data += sz;
+ } else if (errno != EINTR)
+ return 0;
}
-
- /* creation */
- /* TODO */
- return 0;
-
+ return 1;
}
int afb_hreq_is_argument_a_file(struct afb_hreq *hreq, const char *key)
diff --git a/src/afb-hsrv.c b/src/afb-hsrv.c
index 977aea63..afe865f7 100644
--- a/src/afb-hsrv.c
+++ b/src/afb-hsrv.c
@@ -56,6 +56,12 @@ struct afb_diralias {
int dirfd;
};
+struct afb_hsrv {
+ struct MHD_Daemon *httpd;
+ struct afb_hsrv_handler *handlers;
+ struct upoll *upoll;
+};
+
static struct upoll *upoll = NULL;
static struct afb_hsrv_handler *new_handler(
@@ -303,6 +309,7 @@ static int access_handler(
hreq->postform = MHD_create_post_processor (connection, 65500, postproc, hreq);
if (hreq->postform == NULL)
goto internal_error;
+ return MHD_YES;
} else if (strcasestr(type, JSON_CONTENT) == NULL) {
afb_hsrv_reply_error(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE);
return MHD_YES;