add request url parsing / handling
This commit is contained in:
30
server/array.c
Normal file
30
server/array.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "include/array.h"
|
||||
#include "include/mongoose.h"
|
||||
|
||||
void array_mg_str_append(array_mg_str* arr, struct mg_str item) {
|
||||
if (arr->count >= arr->capacity) {
|
||||
if (arr->capacity == 0) arr->capacity = 8;
|
||||
else arr->capacity *= 2;
|
||||
|
||||
arr->items = realloc(arr->items, arr->capacity * sizeof(*arr->items));
|
||||
}
|
||||
arr->items[arr->count++] = item;
|
||||
}
|
||||
|
||||
void split_mg_str(struct mg_str* string, const char token, array_mg_str* return_array) {
|
||||
int start_index = 0;
|
||||
|
||||
for (int i = 0; i < string->len; i++) {
|
||||
if (string->buf[i] == token || string->len == i + 1) {
|
||||
if (i != start_index) {
|
||||
int slice_len = i - start_index;
|
||||
if (string->len == i + 1 && string->buf[i] != token) slice_len++;
|
||||
|
||||
struct mg_str tmp_mg_str = mg_str_n(string->buf + start_index, slice_len);
|
||||
|
||||
array_mg_str_append(return_array, tmp_mg_str);
|
||||
}
|
||||
start_index = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user