Skip to content
Snippets Groups Projects
Commit 588cf0b8 authored by Andy Green's avatar Andy Green
Browse files

lws_spa: add CLOSE callback

This should ease the situation where there was creation done in the
callback for LWS_UFS_OPEN
parent da3d8cb5
Branches
Tags
No related merge requests found
...@@ -47,8 +47,10 @@ enum lws_spa_fileupload_states { ...@@ -47,8 +47,10 @@ enum lws_spa_fileupload_states {
/**< a chunk of file content has arrived */ /**< a chunk of file content has arrived */
LWS_UFS_FINAL_CONTENT, LWS_UFS_FINAL_CONTENT,
/**< the last chunk (possibly zero length) of file content has arrived */ /**< the last chunk (possibly zero length) of file content has arrived */
LWS_UFS_OPEN LWS_UFS_OPEN,
/**< a new file is starting to arrive */ /**< a new file is starting to arrive */
LWS_UFS_CLOSE
/**< the file decode stuff is being destroyed */
}; };
/** /**
......
...@@ -136,7 +136,8 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, ...@@ -136,7 +136,8 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in,
while (len--) { while (len--) {
if (s->pos == s->out_len - s->mp - 1) { if (s->pos == s->out_len - s->mp - 1) {
if (s->output(s->data, s->name, &s->out, s->pos, 0)) if (s->output(s->data, s->name, &s->out, s->pos,
LWS_UFS_CONTENT))
return -1; return -1;
was_end = s->pos; was_end = s->pos;
...@@ -158,7 +159,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, ...@@ -158,7 +159,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in,
if (*in == '&') { if (*in == '&') {
s->name[s->pos] = '\0'; s->name[s->pos] = '\0';
if (s->output(s->data, s->name, &s->out, if (s->output(s->data, s->name, &s->out,
s->pos, 1)) s->pos, LWS_UFS_FINAL_CONTENT))
return -1; return -1;
s->pos = 0; s->pos = 0;
s->state = US_IDLE; s->state = US_IDLE;
...@@ -180,7 +181,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, ...@@ -180,7 +181,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in,
if (*in == '&') { if (*in == '&') {
s->out[s->pos] = '\0'; s->out[s->pos] = '\0';
if (s->output(s->data, s->name, &s->out, if (s->output(s->data, s->name, &s->out,
s->pos, 1)) s->pos, LWS_UFS_FINAL_CONTENT))
return -1; return -1;
s->pos = 0; s->pos = 0;
s->state = US_NAME; s->state = US_NAME;
...@@ -229,7 +230,8 @@ retry_as_first: ...@@ -229,7 +230,8 @@ retry_as_first:
if (s->pos || was_end) if (s->pos || was_end)
if (s->output(s->data, s->name, if (s->output(s->data, s->name,
&s->out, s->pos, 1)) &s->out, s->pos,
LWS_UFS_FINAL_CONTENT))
return -1; return -1;
s->pos = 0; s->pos = 0;
...@@ -409,9 +411,13 @@ lws_urldecode_s_destroy(struct lws_urldecode_stateful *s) ...@@ -409,9 +411,13 @@ lws_urldecode_s_destroy(struct lws_urldecode_stateful *s)
ret = -1; ret = -1;
if (!ret) if (!ret)
if (s->output(s->data, s->name, &s->out, s->pos, 1)) if (s->output(s->data, s->name, &s->out, s->pos,
LWS_UFS_FINAL_CONTENT))
ret = -1; ret = -1;
if (s->output(s->data, s->name, NULL, 0, LWS_UFS_CLOSE))
return -1;
lws_free(s); lws_free(s);
return ret; return ret;
...@@ -448,15 +454,14 @@ static int ...@@ -448,15 +454,14 @@ static int
lws_urldecode_spa_cb(void *data, const char *name, char **buf, int len, lws_urldecode_spa_cb(void *data, const char *name, char **buf, int len,
int final) int final)
{ {
struct lws_spa *spa = struct lws_spa *spa = (struct lws_spa *)data;
(struct lws_spa *)data;
int n; int n;
if (spa->s->content_disp_filename[0]) { if (final == LWS_UFS_CLOSE || spa->s->content_disp_filename[0]) {
if (spa->opt_cb) { if (spa->opt_cb) {
n = spa->opt_cb(spa->opt_data, name, n = spa->opt_cb(spa->opt_data, name,
spa->s->content_disp_filename, spa->s->content_disp_filename,
*buf, len, final); buf ? *buf : NULL, len, final);
if (n < 0) if (n < 0)
return -1; return -1;
......
...@@ -88,6 +88,8 @@ file_upload_cb(void *data, const char *name, const char *filename, ...@@ -88,6 +88,8 @@ file_upload_cb(void *data, const char *name, const char *filename,
close(pss->fd); close(pss->fd);
pss->fd = -1; pss->fd = -1;
break; break;
case LWS_UFS_CLOSE:
break;
} }
return 0; return 0;
......
...@@ -322,6 +322,8 @@ file_upload_cb(void *data, const char *name, const char *filename, ...@@ -322,6 +322,8 @@ file_upload_cb(void *data, const char *name, const char *filename,
pss->response_code = HTTP_STATUS_OK; pss->response_code = HTTP_STATUS_OK;
scan_upload_dir(pss->vhd); scan_upload_dir(pss->vhd);
break;
case LWS_UFS_CLOSE:
break; break;
} }
......
...@@ -107,6 +107,8 @@ file_upload_cb(void *data, const char *name, const char *filename, ...@@ -107,6 +107,8 @@ file_upload_cb(void *data, const char *name, const char *filename,
pss->fd = LWS_INVALID_FILE; pss->fd = LWS_INVALID_FILE;
#endif #endif
break; break;
case LWS_UFS_CLOSE:
break;
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment