2024-09-04 18:35:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "parslib.h"
|
|
|
|
|
|
|
|
char *req_test_data = {
|
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
"Host: archive.0xdeadbeer.xyz\r\n"
|
|
|
|
"User-Agent: curl/8.9.1\r\n"
|
|
|
|
"Accept: */*\r\n"
|
|
|
|
"\r\n"
|
|
|
|
"{\"key\": \"kefjoiawejfojgorgjbosejrgo\"}|"
|
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
"Host: google.com\r\n"
|
|
|
|
"User-Agent: curl/8.9.1\r\n"
|
|
|
|
"Accept: */*\r\n|"
|
|
|
|
};
|
|
|
|
char *res_test_data = {
|
|
|
|
"HTTP/1.1 301 Moved Permanently\r\n"
|
|
|
|
"Location: http://www.google.com/\r\n"
|
|
|
|
"Content-Type: text/html; charset=UTF-8\r\n"
|
2024-09-04 18:39:57 +00:00
|
|
|
"Content-Security-Policy-Report-Only: object-src 'none';base-uri"
|
|
|
|
"'self';script-src 'nonce-7hRaJZVpUAa6E54ys6qpuA' 'strict-dynamic'"
|
|
|
|
"'report-sample' 'unsafe-eval' 'unsafe-inline' https:"
|
|
|
|
"http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp\r\n"
|
2024-09-04 18:35:50 +00:00
|
|
|
"Date: Wed, 04 Sep 2024 17:52:02 GMT\r\n"
|
|
|
|
"Expires: Fri, 04 Oct 2024 17:52:02 GMT\r\n"
|
|
|
|
"Cache-Control: public, max-age=2592000\r\n"
|
|
|
|
"Server: gws\r\n"
|
|
|
|
"Content-Length: 219\r\n"
|
|
|
|
"X-XSS-Protection: 0\r\n"
|
|
|
|
"X-Frame-Options: SAMEORIGIN\r\n|"
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
int ret = 0;
|
|
|
|
char *reqs = strdup(req_test_data);
|
|
|
|
if (!reqs) {
|
|
|
|
fprintf(stderr, "Not enough dynamic memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *reses = strdup(res_test_data);
|
|
|
|
if (!reses) {
|
|
|
|
fprintf(stderr, "Not enough dynamic memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:39:57 +00:00
|
|
|
struct httpareq *req =
|
|
|
|
(struct httpareq *) calloc(1, sizeof(struct httpareq));
|
2024-09-04 18:35:50 +00:00
|
|
|
if (!req) {
|
|
|
|
fprintf(stderr, "Not enough dynamic memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:39:57 +00:00
|
|
|
struct httpares *res =
|
|
|
|
(struct httpares *) calloc(1, sizeof(struct httpares));
|
2024-09-04 18:35:50 +00:00
|
|
|
if (!res) {
|
|
|
|
fprintf(stderr, "Not enough dynamic memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = initres();
|
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Failed initializing parser\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stdout, "xxxREQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
|
|
|
|
for (char *ch = strtok(reqs, "|"); ch != NULL; ch = strtok(NULL, "|")) {
|
|
|
|
ret = pareq(ch, req);
|
|
|
|
fprintf(stdout, "-------------------------------------\n");
|
|
|
|
printfpareq(req);
|
|
|
|
fprintf(stdout, "-------------------------------------\n");
|
2024-09-08 19:41:17 +00:00
|
|
|
|
|
|
|
frepareq(req);
|
2024-09-04 18:35:50 +00:00
|
|
|
}
|
|
|
|
fprintf(stdout, "xxxRESxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
|
|
|
|
for (char *ch = strtok(reses, "|"); ch != NULL; ch = strtok(NULL, "|")) {
|
|
|
|
ret = pares(ch, res);
|
|
|
|
fprintf(stdout, "-------------------------------------\n");
|
|
|
|
printfpares(res);
|
|
|
|
fprintf(stdout, "-------------------------------------\n");
|
2024-09-08 19:41:17 +00:00
|
|
|
|
|
|
|
frepares(res);
|
2024-09-04 18:35:50 +00:00
|
|
|
}
|
|
|
|
fprintf(stdout, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
|
|
|
|
|
|
|
|
fretres();
|
|
|
|
free(res);
|
|
|
|
free(req);
|
|
|
|
free(reses);
|
|
|
|
free(reqs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|