From 9d3607a6ebaca1ec55edf37847e240ab39a2290b Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 7 Apr 2022 03:25:35 +0000 Subject: [PATCH] Move to mime file FossilOrigin-Name: 613210e2664cf18ce97174b814ca90655f0e65ab590af88cb202c9f35c90a8da --- src/mime.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mime.h | 25 +++++++++++++++++++++ src/status.c | 37 ------------------------------- 3 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 src/mime.c create mode 100644 src/mime.h diff --git a/src/mime.c b/src/mime.c new file mode 100644 index 0000000..6f9e358 --- /dev/null +++ b/src/mime.c @@ -0,0 +1,61 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "mime.h" + +char* get_mime_boundary() +{ + if (!getenv("CONTENT_TYPE")) return 1; + + // Data gets changed in place + char* content_type = malloc(strlen(getenv("CONTENT_TYPE"))+1); + if (!content_type) + { + perror("malloc"); + exit(1); + } + + 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) + goto error; + + bound_str += sizeof("boundary")-1; + + boundary = (tmp = strchr(bound_str, '\"')) ? tmp : + strchr(bound_str, '='); + if (!boundary) + goto error; + boundary++; + + if ((tmp = strchr(boundary, '\"'))) + *tmp = '\0'; + + return 0; +error: + free(content_type); + return 1; +} diff --git a/src/mime.h b/src/mime.h new file mode 100644 index 0000000..378e23f --- /dev/null +++ b/src/mime.h @@ -0,0 +1,25 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef MIME_H +#define MIME_H + +char* get_mime_boundary(); +char* read_mime_data(char* boundary, char* begin, struct http_mime_info* info); + +#endif /* MIME_H */ diff --git a/src/status.c b/src/status.c index 3f4f923..c08f957 100644 --- a/src/status.c +++ b/src/status.c @@ -46,37 +46,6 @@ 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; @@ -86,12 +55,6 @@ int try_post_status(struct session* ssn, mastodont_t* api) 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",