Skip to content

Commit

Permalink
Restructing the web server to avoid method checking
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 27, 2024
1 parent ebfd352 commit 8ffa510
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 384 deletions.
27 changes: 25 additions & 2 deletions src/hal/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,39 @@ bool get_uint8(char *str, char *pattern, uint8_t *value) {
return true;
}


char *memstr(char *haystack, char *needle, int size, char needlesize) {
for (char *p = haystack; p <= (haystack - needlesize + size); p++)
if (!memcmp(p, needle, needlesize)) return p;
return NULL;
}


unsigned int millis() {
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
}

char *split(char **input, char *sep) {
char *curr = (char *)"";
while (curr && !curr[0] && *input) curr = strsep(input, sep);
return (curr);
}

void unescape_uri(char *uri) {
char *src = uri;
char *dst = uri;

while (*src && !isspace((int)(*src)) && (*src != '%'))
src++;

dst = src;
while (*src && !isspace((int)(*src)))
{
*dst++ = (*src == '+') ? ' ' :
((*src == '%') && src[1] && src[2]) ?
((*++src & 0x0F) + 9 * (*src > '9')) * 16 + ((*++src & 0x0F) + 9 * (*src > '9')) :
*src;
src++;
}
*dst = '\0';
}
12 changes: 11 additions & 1 deletion src/hal/tools.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <ctype.h>
#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
Expand All @@ -9,16 +10,25 @@
#include <sys/time.h>

int base64_encode_length(int len);

int base64_encode(char *encoded, const char *string, int len);

int compile_regex(regex_t *r, const char *regex_text);

const char *get_extension(const char *path);

bool get_uint64(char *str, char *pattern, uint64_t *value);

bool get_uint32(char *str, char *pattern, uint32_t *value);

bool get_uint16(char *str, char *pattern, uint16_t *value);

bool get_uint8(char *str, char *pattern, uint8_t *value);

char *memstr(char *haystack, char *needle, int size, char needlesize);
unsigned int millis();

unsigned int millis();

char *split(char **input, char *sep);

void unescape_uri(char *uri);
Loading

0 comments on commit 8ffa510

Please sign in to comment.