#include #include #include #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" "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" "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; } struct httpareq *req = (struct httpareq *) calloc(1, sizeof(struct httpareq)); if (!req) { fprintf(stderr, "Not enough dynamic memory\n"); return -1; } struct httpares *res = (struct httpares *) calloc(1, sizeof(struct httpares)); 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"); } 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"); } fprintf(stdout, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); fretres(); free(res); free(req); free(reses); free(reqs); return 0; }