String progress

FossilOrigin-Name: 8fb6b3a2e74a21d346b11c3515f54dad5d8f5616202b8c27f255e2739edc1d47
This commit is contained in:
me@ow.nekobit.net 2022-04-11 17:39:50 +00:00
parent 439b4c8b4b
commit f6291ca0ad
7 changed files with 81 additions and 4 deletions

1
dist/treebird20.css vendored
View File

@ -120,6 +120,7 @@ table.ui-table td
max-width: 608px !important;
min-width: 608px;
border-collapse: collapse !important;
background-color: #fafafa;
padding: 0;
}

View File

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stddef.h>
#include "mime.h"
#include "string.h"
char* get_mime_boundary(char* content_type_str, char** bound)
{
@ -98,9 +99,12 @@ static char* read_key(char** r, char* key)
#define STRSCMP(begin, str) strncmp((begin), (str), sizeof(str)-1)
char* read_form_data(char* boundary, char* begin, struct http_form_info* info)
char* read_form_data(char* boundary,
char* begin,
struct http_form_info* info,
size_t size)
{
ptrdiff_t data_size;
ptrdiff_t data_size, begin_to_value_size;
// Step 1: Parse name
// Parser variables
char* r, *read_val;
@ -163,6 +167,7 @@ char* read_form_data(char* boundary, char* begin, struct http_form_info* info)
// Last step: Find data
info->value = r;
begin_to_value_size = info->value - begin;
// Look for end
if ((r = strstr(r, boundary)) &&

View File

@ -18,6 +18,7 @@
#ifndef MIME_H
#define MIME_H
#include <stddef.h>
struct http_form_info
{
@ -29,6 +30,9 @@ struct http_form_info
};
char* get_mime_boundary(char* content_type, char** res);
char* read_form_data(char* boundary, char* begin, struct http_form_info* info);
char* read_form_data(char* boundary,
char* begin,
struct http_form_info* info,
size_t size);
#endif /* MIME_H */

View File

@ -93,6 +93,7 @@ void key_files(char* val, struct form_props* form, void* arg)
char* read_post_data(struct query_values* post)
{
ptrdiff_t begin_curr_size;
struct http_query_info query_info;
struct http_form_info form_info;
struct form_props form_props;
@ -142,10 +143,13 @@ char* read_post_data(struct query_values* post)
{
if (mime_mem)
{
// Get size from here to the end
begin_curr_size = p_query_read - p_query;
// Mime value
p_query_read = read_form_data(mime_boundary,
p_query_read,
&form_info);
&form_info,
len - begin_curr_size);
form_props.filename = form_info.filename;
form_props.filetype = form_info.content_type;
form_props.data_size = form_info.value_size;

37
src/string.c Normal file
View File

@ -0,0 +1,37 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "string.h"
int streql(char* cmp1, char* cmp2)
{
while (*cmp1 || *cmp2)
if (*cmp1++ != *cmp2++)
return 0;
return 1;
}
char* strnstr(const char* haystack, const char* needle, size_t s)
{
for (size_t i = 0; i < s; ++i)
{
}
return NULL;
}

26
src/string.h Normal file
View File

@ -0,0 +1,26 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef TREE_STRING_H
#define TREE_STRING_H
#include <stddef.h>
int streql(char* cmp1, char* cmp2);
char* strnstr(const char* haystack, const char* needle, size_t s);
#endif // TREE_STRING_H

BIN
test/test_upload_file Normal file

Binary file not shown.