Read boundary

FossilOrigin-Name: 1c992db00b8a6ff87c8661ebba105df4a9807180f6f2a16cbef0859d046f4bd8
This commit is contained in:
me@ow.nekobit.net 2022-04-06 19:32:45 +00:00
parent c00cf74f6d
commit 5f8eaa12b0
2 changed files with 43 additions and 1 deletions

View file

@ -46,12 +46,52 @@ struct status_args
struct mstdnt_status* status;
};
/* A cheap parser for multipart data
* It is designed only for files, don't use this for anything else */
static int parse_files(char*** files, size_t* files_len)
{
char* content_type = getenv("CONTENT_TYPE");
char* bound_str;
char* boundary;
/* Tmp reading variables */
char* tmp;
if (strstr(content_type, "multipart/form-data") == NULL ||
(bound_str = strstr(content_type, "boundary")) == NULL)
return 1;
bound_str += sizeof("boundary")-1;
boundary = (tmp = strchr(bound_str, '\"')) ? tmp :
strchr(bound_str, '=');
if (!boundary)
return 1;
boundary++;
if ((tmp = strchr(boundary, '\"')))
*tmp = '\0';
return 0;
}
int try_post_status(struct session* ssn, mastodont_t* api)
{
if (!(ssn->post.content)) return 1;
struct mstdnt_storage storage;
char** files;
size_t files_len;
if (parse_files(&files, &files_len) == 0)
{
}
return 1;
// Cookie copy and read
struct mstdnt_args args = {
.content_type = "text/plain",
@ -84,6 +124,7 @@ void content_status_create(struct session* ssn, mastodont_t* api, char** data)
try_post_status(ssn, api);
redirect(REDIRECT_303, referer);
}
int try_interact_status(struct session* ssn, mastodont_t* api, char* id)

View file

@ -1,9 +1,10 @@
<form action="%s/status/create" method="post">
<form action="%s/status/create" method="post" enctype="multipart/form-data">
%s
<div class="statusbox">
<textarea name="content" placeholder="Just landed in N.Y." rows="5">%s</textarea>
<div class="statusfooter">
<div class="statusfooter-left">
<input type="file" name="file" multiple>
<!-- Put text here -->
</div>
<div class="statusfooter-right">