#ifndef PARSER_H #define PARSER_H #define CRLF "\r\n" #define MAX_BOUND 1024 #define LINE_BUF 1024 #define TEST_ONE "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\"}" #define DEFAULT_HTTP "80" #define DEFAULT_HTTPS "443" // SRC:https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods enum methods { method_get = 1, method_head, method_post, method_put, method_delete, method_connect, method_options, method_trace, method_patch }; // SRC:https://en.wikipedia.org/wiki/List_of_HTTP_header_fields enum headers { header_a_im = 1, header_accept, header_accept_charset, header_accept_datetime, header_accept_encoding, header_accept_language, header_access_control_request_method, header_access_control_request_headers, header_authorization, header_cache_control, header_connection, header_content_encoding, header_content_length, header_content_md5, header_content_type, header_cookie, header_date, header_expect, header_forwarded, header_from, header_host, header_http2_settings, header_if_match, header_if_modified_since, header_if_none_match, header_if_range, header_if_unmodified_since, header_max_forwards, header_origin, header_pragma, header_prefer, header_proxy_authorization, header_range, header_referer, header_te, header_trailer, header_transfer_encoding, header_user_agent, header_upgrade, header_via, header_warning, header_upgrade_insecure_requests, header_x_requested_with, header_dnt, header_x_forwarded_for, header_x_forwarded_host, header_x_forwarded_proto, header_front_end_https, header_x_http_method_override, header_x_att_deviceid, header_x_wap_profile, header_proxy_connection, header_x_uidh, header_x_csrf_token, header_x_request_id, header_x_correlation_id, header_correlation_id, header_save_data, header_sec_gpc, header_accept_ch, header_access_control_allow_origin, header_access_control_allow_credentials, header_access_control_expose_headers, header_access_control_max_age, header_access_control_allow_methods, header_access_control_allow_headers, header_accept_patch, header_accept_ranges, header_age, header_allow, header_alt_svc, header_content_disposition, header_content_language, header_content_location, header_content_range, header_delta_base, header_etag, header_expires, header_im, header_last_modified, header_link, header_location, header_p3p, header_preference_applied, header_proxy_authenticate, header_public_key_pins, header_retry_after, header_server, header_set_cookie, header_strict_transport_security, header_tk, header_vary, header_www_authenticate, header_x_frame_options, header_content_security_policy, header_expect_ct, header_nel, header_permissions_policy, header_refresh, header_report_to, header_status, header_timing_allow_origin, header_x_content_duration, header_x_content_type_options, header_x_powered_by, header_x_redirect_by, header_x_ua_compatible, header_x_xss_protection, header_count }; struct point { char *er; int len; }; struct hostinfo { char *hostname; char *service; int hostname_len; int service_len; }; struct httitlereq { int method; struct point uri; struct point ver; }; struct httitleres { struct point ver; int code; struct point stxt; }; struct httpareq { struct httitlereq titl; struct point hentries[header_count]; }; struct httpares { struct httitleres titl; struct point hentries[header_count]; }; int stoin(char *str, int len, int *out); int initres(void); void fretres(void); void frepareq(struct httpareq *req); void frepares(struct httpares *res); int readlin(char **buff, char **buff_lim); int parshfield(char *offset, int len, /* out */ struct point *hentries); int pahostinfo(char *offset, int len, /* out */ struct hostinfo *info); int pareqtitl(char *offset, int len, struct httitlereq *titl); int parestitl(char *offset, int len, struct httitleres *titl); int pareq(char *buff, /* out */ struct httpareq *req); int pares(char *buff, /* out */ struct httpares *res); void printfpareq(struct httpareq *req); void printfpares(struct httpares *res); #endif