fix parameters without value
[src/app-framework-binder.git] / src / afb-hreq.c
index aff204d..8928266 100644 (file)
@@ -438,13 +438,15 @@ static int opentempfile(char **path)
        int fd;
        char *fname;
 
-       fname = strdup("XXXXXX");
+       fname = strdup("XXXXXX"); /* TODO improve the path */
        if (fname == NULL)
                return -1;
 
-       fd = mkostemp(fname, O_CLOEXEC);
+       fd = mkostemp(fname, O_CLOEXEC|O_WRONLY);
        if (fd < 0)
                free(fname);
+       else
+               *path = fname;
        return fd;
 }
 
@@ -454,6 +456,7 @@ int afb_hreq_post_add_file(struct afb_hreq *hreq, const char *key, const char *f
        ssize_t sz;
        struct hreq_data *hdat = get_data(hreq, key, 1);
 
+fprintf(stderr, "%s=%s %s=%s %s\n",key,hdat->key,file,hdat->value,hdat->path);
        if (hdat->value == NULL) {
                hdat->value = strdup(file);
                if (hdat->value == NULL)
@@ -516,8 +519,8 @@ static int _iterargs_(struct iterdata *id, enum MHD_ValueKind kind, const char *
                return 1;
        return id->iterator(id->closure, (struct afb_arg){
                .name = key,
-               .value = value,
-               .size = 0,
+               .value = value ? : "",
+               .size = value ? strlen(value) : 0,
                .path = NULL
        });
 }