2024-08-15 23:12:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2024-09-04 09:04:08 +00:00
|
|
|
#include "parslib.h"
|
2024-09-02 22:03:32 +00:00
|
|
|
#include "streecmp/streecmp.h"
|
|
|
|
|
2024-09-03 19:07:52 +00:00
|
|
|
extern char *methods;
|
2024-09-04 07:06:42 +00:00
|
|
|
extern char *headers;
|
|
|
|
|
|
|
|
static struct nod *method_tree = NULL;
|
|
|
|
static struct nod *header_tree = NULL;
|
|
|
|
|
2024-09-09 18:55:21 +00:00
|
|
|
int stoin(char *str, int len, int *out) {
|
2024-09-04 10:16:40 +00:00
|
|
|
int ret = 0;
|
|
|
|
int place = 1;
|
2024-09-04 18:35:50 +00:00
|
|
|
for (char *chr = str+len-1; chr >= str; chr--) {
|
2024-09-04 10:16:40 +00:00
|
|
|
if (chr == str) {
|
2024-09-04 18:35:50 +00:00
|
|
|
if (*chr == '+') {
|
2024-09-04 10:16:40 +00:00
|
|
|
goto _proceed;
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (*chr == '-') {
|
2024-09-04 10:16:40 +00:00
|
|
|
goto _proceed;
|
|
|
|
}
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (*chr >= '0' && *chr <= '9') {
|
2024-09-04 10:16:40 +00:00
|
|
|
goto _proceed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
_proceed:
|
|
|
|
|
|
|
|
if (*chr == '-') {
|
|
|
|
ret = -ret;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*chr == '+') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int number = *chr-'0';
|
|
|
|
ret += number * place;
|
|
|
|
place *= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = ret;
|
2024-09-04 18:35:50 +00:00
|
|
|
return 0;
|
2024-09-04 10:16:40 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
void printfpareq(struct httpareq *req) {
|
2024-09-04 07:06:42 +00:00
|
|
|
fprintf(stderr, "\tstats:\n"
|
|
|
|
"\t\tmethod\t: %d\n"
|
|
|
|
"\t\turi\t: %.*s\n"
|
|
|
|
"\t\tver\t: %.*s\n",
|
2024-09-04 18:35:50 +00:00
|
|
|
req->titl.method,
|
|
|
|
req->titl.uri.len, req->titl.uri.er,
|
|
|
|
req->titl.ver.len, req->titl.ver.er
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf(stdout, "\theaders:\n");
|
|
|
|
for (int i = 0; i < header_count; i++) {
|
|
|
|
struct point *pnt = &req->hentries[i];
|
|
|
|
if (!pnt->er) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stdout, "\t\t%d\t: %.*s\n", i, pnt->len, pnt->er);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void printfpares(struct httpares *res) {
|
|
|
|
fprintf(stderr, "\tstats:\n"
|
|
|
|
"\t\tver\t: %.*s\n"
|
|
|
|
"\t\tcode\t: %d\n"
|
|
|
|
"\t\tstext\t: %.*s\n",
|
|
|
|
res->titl.ver.len, res->titl.ver.er,
|
|
|
|
res->titl.code,
|
|
|
|
res->titl.stxt.len, res->titl.stxt.er
|
2024-09-04 07:06:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
fprintf(stdout, "\theaders:\n");
|
|
|
|
for (int i = 0; i < header_count; i++) {
|
2024-09-04 18:35:50 +00:00
|
|
|
struct point *pnt = &res->hentries[i];
|
2024-09-04 07:06:42 +00:00
|
|
|
if (!pnt->er) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stdout, "\t\t%d\t: %.*s\n", i, pnt->len, pnt->er);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int initres(void) {
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
header_tree = allocnod();
|
|
|
|
if (!header_tree) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-04 07:06:42 +00:00
|
|
|
method_tree = allocnod();
|
|
|
|
if (!method_tree) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-12 17:30:09 +00:00
|
|
|
ret = gentree(header_tree, headers, NULL, LOOSE_CHECK);
|
2024-09-04 07:06:42 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-09-02 22:03:32 +00:00
|
|
|
|
2024-09-12 17:30:09 +00:00
|
|
|
ret = gentree(method_tree, methods, NULL, LOOSE_CHECK);
|
2024-09-04 07:06:42 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fretres(void) {
|
2024-09-04 18:35:50 +00:00
|
|
|
frenod(method_tree);
|
|
|
|
frenod(header_tree);
|
2024-09-04 07:06:42 +00:00
|
|
|
}
|
|
|
|
|
2024-09-08 19:41:17 +00:00
|
|
|
void frepareq(struct httpareq *req) {
|
|
|
|
struct httitlereq *titl = &req->titl;
|
|
|
|
free(titl->uri.er);
|
2024-09-12 17:30:09 +00:00
|
|
|
titl->uri.er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
free(titl->ver.er);
|
2024-09-12 17:30:09 +00:00
|
|
|
titl->uri.er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < header_count; i++) {
|
|
|
|
struct point *e = &req->hentries[i];
|
|
|
|
if (!e->er) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(e->er);
|
2024-09-12 17:30:09 +00:00
|
|
|
e->er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void frepares(struct httpares *res) {
|
|
|
|
struct httitleres *titl = &res->titl;
|
|
|
|
free(titl->ver.er);
|
2024-09-12 17:30:09 +00:00
|
|
|
titl->ver.er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
free(titl->stxt.er);
|
2024-09-12 17:30:09 +00:00
|
|
|
titl->stxt.er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < header_count; i++) {
|
|
|
|
struct point *e = &res->hentries[i];
|
|
|
|
if (!e->er) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(e->er);
|
2024-09-12 17:30:09 +00:00
|
|
|
e->er = NULL;
|
2024-09-08 19:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 07:16:55 +00:00
|
|
|
int readlin(char **buff, char **buff_lim) {
|
2024-08-15 23:12:06 +00:00
|
|
|
int diff = 0;
|
2024-09-04 07:06:42 +00:00
|
|
|
if ((*buff) >= (*buff_lim)) {
|
2024-09-02 22:03:32 +00:00
|
|
|
return diff;
|
|
|
|
}
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-02 22:03:32 +00:00
|
|
|
int ret = 0;
|
2024-09-04 07:06:42 +00:00
|
|
|
char *match = strstr(*buff, "\r\n");
|
2024-09-02 22:03:32 +00:00
|
|
|
if (match) {
|
2024-09-04 07:06:42 +00:00
|
|
|
ret = match-(*buff);
|
|
|
|
*buff += 2;
|
2024-09-02 22:03:32 +00:00
|
|
|
} else {
|
2024-09-04 07:06:42 +00:00
|
|
|
ret = (*buff_lim)-(*buff);
|
2024-09-02 22:03:32 +00:00
|
|
|
}
|
2024-09-04 07:06:42 +00:00
|
|
|
*buff += ret;
|
2024-09-02 22:03:32 +00:00
|
|
|
return ret;
|
2024-08-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 07:06:42 +00:00
|
|
|
int parshfield(char *offset, int len, struct point *hentries) {
|
2024-09-03 19:51:27 +00:00
|
|
|
int key = 0;
|
2024-09-02 22:03:32 +00:00
|
|
|
int ret = 0;
|
2024-09-03 19:51:27 +00:00
|
|
|
int diff = 0;
|
|
|
|
|
|
|
|
char *cursor = offset;
|
|
|
|
char *cursor_lim = offset+len;
|
|
|
|
|
|
|
|
// header title
|
2024-09-03 20:09:09 +00:00
|
|
|
char *htitle_lim = strchr(cursor, ':');
|
2024-09-03 19:51:27 +00:00
|
|
|
if (!htitle_lim) {
|
2024-09-02 22:03:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-03 19:51:27 +00:00
|
|
|
if (htitle_lim > cursor_lim) {
|
2024-09-02 22:03:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-03 19:51:27 +00:00
|
|
|
diff = htitle_lim-cursor;
|
2024-09-12 17:30:09 +00:00
|
|
|
ret = streencmp(header_tree, cursor, diff, LOOSE_CHECK);
|
2024-09-03 19:51:27 +00:00
|
|
|
if (!ret) {
|
2024-09-04 18:35:50 +00:00
|
|
|
return 0; // skip it
|
2024-09-02 22:03:32 +00:00
|
|
|
}
|
|
|
|
|
2024-09-03 19:51:27 +00:00
|
|
|
key = ret;
|
|
|
|
cursor += diff;
|
|
|
|
|
|
|
|
// white space and seperators
|
2024-09-03 20:09:09 +00:00
|
|
|
_loop:
|
|
|
|
if (cursor > cursor_lim) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cursor == ':') {
|
|
|
|
cursor++;
|
|
|
|
goto _loop;
|
|
|
|
}
|
|
|
|
if (*cursor == ' ') {
|
2024-09-03 19:51:27 +00:00
|
|
|
cursor++;
|
2024-09-03 20:09:09 +00:00
|
|
|
goto _loop;
|
2024-09-03 19:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// header value
|
|
|
|
diff = cursor_lim-cursor;
|
2024-09-08 19:41:17 +00:00
|
|
|
char *e = strndup(cursor, diff);
|
|
|
|
if (!e) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-09-03 19:51:27 +00:00
|
|
|
|
2024-09-08 19:41:17 +00:00
|
|
|
hentries[key].er = e;
|
2024-09-04 07:06:42 +00:00
|
|
|
hentries[key].len = diff;
|
2024-09-02 22:03:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-09 18:55:21 +00:00
|
|
|
int pahostinfo(char *offset, int len, struct hostinfo *info) {
|
|
|
|
int diff = 0;
|
|
|
|
int usedefault = 0;
|
|
|
|
char *delim = strchr(offset, ':');
|
|
|
|
if (!delim) {
|
|
|
|
delim = offset+len;
|
|
|
|
usedefault = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = delim-offset;
|
|
|
|
info->hostname = strndup(offset, diff);
|
|
|
|
if (!info->hostname) {
|
|
|
|
goto _err;
|
|
|
|
}
|
|
|
|
info->hostname_len = diff;
|
|
|
|
|
|
|
|
if (usedefault) {
|
|
|
|
diff = strlen(DEFAULT_HTTP);
|
|
|
|
info->service = strndup(DEFAULT_HTTP, diff);
|
|
|
|
if (!info->service) {
|
|
|
|
goto _err_service;
|
|
|
|
}
|
|
|
|
info->service_len = diff;
|
|
|
|
} else {
|
|
|
|
char *service_offset = delim+1;
|
|
|
|
char *end = offset+len;
|
|
|
|
diff = end-service_offset;
|
|
|
|
info->service = strndup(service_offset, diff);
|
|
|
|
if (!info->service) {
|
|
|
|
goto _err_service;
|
|
|
|
}
|
|
|
|
info->service_len = diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
_err_service:
|
|
|
|
free(info->hostname);
|
|
|
|
|
|
|
|
_err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
int pareqtitl(char *offset, int len, struct httitlereq *titl) {
|
2024-09-04 10:16:40 +00:00
|
|
|
int ret = 0;
|
2024-09-04 18:35:50 +00:00
|
|
|
int diff = 0;
|
|
|
|
char *cursor = offset;
|
|
|
|
char *cursor_lim = cursor+len;
|
2024-09-04 10:16:40 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// method
|
|
|
|
char *method_lim = strchr(cursor, ' ');
|
|
|
|
if (!method_lim) {
|
2024-09-04 10:16:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (method_lim > cursor_lim) {
|
2024-09-04 10:16:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
diff = method_lim-cursor;
|
2024-09-12 17:30:09 +00:00
|
|
|
ret = streencmp(method_tree, cursor, diff, LOOSE_CHECK);
|
2024-09-04 18:35:50 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-09-04 10:16:40 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->method = ret;
|
2024-09-04 10:16:40 +00:00
|
|
|
cursor += diff;
|
|
|
|
|
|
|
|
// white space
|
2024-09-04 18:35:50 +00:00
|
|
|
_loop1:
|
2024-09-04 10:16:40 +00:00
|
|
|
if (cursor > cursor_lim) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cursor == ' ') {
|
|
|
|
cursor++;
|
|
|
|
goto _loop1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// uri
|
|
|
|
char *uri_lim = strchr(cursor, ' ');
|
|
|
|
if (!uri_lim) {
|
2024-09-04 10:16:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (uri_lim > cursor_lim) {
|
2024-09-04 10:16:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
diff = uri_lim-cursor;
|
2024-09-08 19:41:17 +00:00
|
|
|
char *e = strndup(cursor, diff);
|
|
|
|
if (!e) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
titl->uri.er = e;
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->uri.len = diff;
|
2024-09-04 10:16:40 +00:00
|
|
|
|
|
|
|
cursor += diff;
|
2024-09-04 18:35:50 +00:00
|
|
|
|
2024-09-04 10:16:40 +00:00
|
|
|
// white space
|
2024-09-04 18:35:50 +00:00
|
|
|
_loop2:
|
2024-09-04 10:16:40 +00:00
|
|
|
if (cursor > cursor_lim) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cursor == ' ') {
|
2024-09-04 18:35:50 +00:00
|
|
|
cursor++;
|
2024-09-04 10:16:40 +00:00
|
|
|
goto _loop2;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// ver
|
2024-09-04 10:16:40 +00:00
|
|
|
diff = cursor_lim-cursor;
|
2024-09-08 19:41:17 +00:00
|
|
|
e = strndup(cursor, diff);
|
|
|
|
if (!e) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
titl->ver.er = e;
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->ver.len = diff;
|
2024-09-04 10:16:40 +00:00
|
|
|
|
|
|
|
cursor += diff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
int parestitl(char *offset, int len, struct httitleres *titl) {
|
2024-09-03 19:07:52 +00:00
|
|
|
int ret = 0;
|
2024-09-04 18:35:50 +00:00
|
|
|
int diff = 0;
|
|
|
|
char *cursor = offset;
|
|
|
|
char *cursor_lim = cursor+len;
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// ver
|
|
|
|
char *ver_lim = strchr(cursor, ' ');
|
|
|
|
if (!ver_lim) {
|
2024-09-03 19:07:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (ver_lim > cursor_lim) {
|
2024-09-03 20:09:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
diff = ver_lim-cursor;
|
2024-09-08 19:41:17 +00:00
|
|
|
char *e = strndup(cursor, diff);
|
|
|
|
if (!e) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
titl->ver.er = e;
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->ver.len = diff;
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-03 19:07:52 +00:00
|
|
|
cursor += diff;
|
|
|
|
|
|
|
|
// white space
|
2024-09-04 18:35:50 +00:00
|
|
|
_loop1:
|
2024-09-03 20:09:09 +00:00
|
|
|
if (cursor > cursor_lim) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cursor == ' ') {
|
2024-09-03 19:07:52 +00:00
|
|
|
cursor++;
|
2024-09-03 20:09:09 +00:00
|
|
|
goto _loop1;
|
2024-09-03 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// code
|
|
|
|
char *code_lim = strchr(cursor, ' ');
|
|
|
|
if (!code_lim) {
|
2024-09-03 19:07:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-04 18:35:50 +00:00
|
|
|
if (code_lim > cursor_lim) {
|
2024-09-03 20:09:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2024-09-03 19:07:52 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
diff = code_lim-cursor;
|
|
|
|
int code;
|
|
|
|
ret = stoin(cursor, diff, &code);
|
|
|
|
if (ret < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-09-03 19:07:52 +00:00
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->code = code;
|
2024-09-03 19:07:52 +00:00
|
|
|
cursor += diff;
|
2024-09-04 18:35:50 +00:00
|
|
|
|
2024-09-03 19:07:52 +00:00
|
|
|
// white space
|
2024-09-04 18:35:50 +00:00
|
|
|
_loop2:
|
2024-09-03 20:09:09 +00:00
|
|
|
if (cursor > cursor_lim) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cursor == ' ') {
|
2024-09-04 18:35:50 +00:00
|
|
|
cursor++;
|
2024-09-03 20:09:09 +00:00
|
|
|
goto _loop2;
|
2024-08-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
// status text
|
2024-09-03 19:07:52 +00:00
|
|
|
diff = cursor_lim-cursor;
|
2024-09-08 19:41:17 +00:00
|
|
|
e = strndup(cursor, diff);
|
|
|
|
if (!e) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
titl->stxt.er = e;
|
2024-09-04 18:35:50 +00:00
|
|
|
titl->stxt.len = diff;
|
2024-09-03 19:07:52 +00:00
|
|
|
|
|
|
|
cursor += diff;
|
|
|
|
|
2024-08-15 23:12:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
int pareq(char *buff, struct httpareq *req) {
|
2024-08-15 23:12:06 +00:00
|
|
|
int ret;
|
2024-09-04 07:06:42 +00:00
|
|
|
char *buff_lim = buff+strlen(buff);
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-04 07:06:42 +00:00
|
|
|
char *title_offset = buff;
|
2024-09-04 07:16:55 +00:00
|
|
|
int title_len = readlin(&buff, &buff_lim);
|
2024-09-04 18:35:50 +00:00
|
|
|
if ((ret = pareqtitl(title_offset, title_len, &req->titl)) < 0) {
|
2024-08-15 23:12:06 +00:00
|
|
|
fprintf(stderr, "Failed parsing title\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-02 22:03:32 +00:00
|
|
|
for (int bound = 0; bound < MAX_BOUND; bound++) {
|
2024-09-04 07:06:42 +00:00
|
|
|
char *header_offset = buff;
|
2024-09-04 07:16:55 +00:00
|
|
|
int header_len = readlin(&buff, &buff_lim);
|
2024-09-02 22:03:32 +00:00
|
|
|
char *header_limit = header_offset+header_len;
|
|
|
|
|
|
|
|
// IF END OF MESSAGE
|
|
|
|
if (!header_len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-09-04 07:06:42 +00:00
|
|
|
if ((ret = parshfield(header_offset,
|
|
|
|
header_len,
|
2024-09-04 18:35:50 +00:00
|
|
|
req->hentries)) < 0) {
|
2024-09-02 22:03:32 +00:00
|
|
|
fprintf(stderr, "Failed parsing header\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-15 23:12:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:35:50 +00:00
|
|
|
int pares(char *buff, struct httpares *res) {
|
|
|
|
int ret;
|
|
|
|
char *buff_lim = buff+strlen(buff);
|
|
|
|
|
|
|
|
char *title_offset = buff;
|
|
|
|
int title_len = readlin(&buff, &buff_lim);
|
|
|
|
if ((ret = parestitl(title_offset, title_len, &res->titl)) < 0) {
|
|
|
|
fprintf(stderr, "Failed parsing title\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int bound = 0; bound < MAX_BOUND; bound++) {
|
|
|
|
char *header_offset = buff;
|
|
|
|
int header_len = readlin(&buff, &buff_lim);
|
|
|
|
char *header_limit = header_offset+header_len;
|
|
|
|
|
|
|
|
// IF END OF MESSAGE
|
|
|
|
if (!header_len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = parshfield(header_offset,
|
|
|
|
header_len,
|
|
|
|
res->hentries)) < 0) {
|
|
|
|
fprintf(stderr, "Failed parsing header\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|