2024-08-15 23:12:06 +00:00
|
|
|
#ifndef PARSER_H
|
|
|
|
#define PARSER_H
|
|
|
|
|
2024-09-02 22:03:32 +00:00
|
|
|
#define CRLF "\r\n"
|
|
|
|
#define MAX_BOUND 1024
|
2024-08-15 23:12:06 +00:00
|
|
|
#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"\
|
2024-09-02 22:03:32 +00:00
|
|
|
"Accept: */*\r\n"\
|
|
|
|
"\r\n"\
|
2024-09-09 18:55:21 +00:00
|
|
|
"{\"key\": \"kefjoiawejfojgorgjbosejrgo\"}"
|
|
|
|
#define DEFAULT_HTTP "80"
|
|
|
|
#define DEFAULT_HTTPS "443"
|
2024-08-15 23:12:06 +00:00
|
|
|
|
2024-09-02 22:03:32 +00:00
|
|
|
// SRC:https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
2024-08-15 23:12:06 +00:00
|
|
|
enum methods {
|
2024-09-03 19:07:52 +00:00
|
|
|
method_get = 1,
|
|
|
|
method_head,
|
2024-08-15 23:12:06 +00:00
|
|
|
method_post,
|
2024-09-03 19:07:52 +00:00
|
|
|
method_put,
|
|
|
|
method_delete,
|
|
|
|
method_connect,
|
|
|
|
method_options,
|
|
|
|
method_trace,
|
|
|
|
method_patch
|
2024-08-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2024-09-02 22:03:32 +00:00
|
|
|
// SRC:https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
|
2024-08-15 23:12:06 +00:00
|
|
|
enum headers {
|
2024-09-02 22:03:32 +00:00
|
|
|
header_a_im = 1,
|
2024-08-15 23:12:06 +00:00
|
|
|
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,
|
2024-09-02 22:03:32 +00:00
|
|
|
header_x_xss_protection,
|
|
|
|
|
|
|
|
header_count
|
2024-08-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2024-09-03 19:51:27 +00:00
|
|
|
struct point {
|
|
|
|
char *er;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
2024-09-09 18:55:21 +00:00
|
|
|
struct hostinfo {
|
|
|
|
char *hostname;
|
|
|
|
char *service;
|
|
|
|
int hostname_len;
|
|
|
|
int service_len;
|
|
|
|
};
|
|
|
|
|
2024-09-04 10:16:40 +00:00
|
|
|
struct httitlereq {
|
2024-09-04 07:06:42 +00:00
|
|
|
int method;
|
|
|
|
struct point uri;
|
|
|
|
struct point ver;
|
|
|
|
};
|
|
|
|
|
2024-09-04 10:16:40 +00:00
|
|
|
struct httitleres {
|
|
|
|
struct point ver;
|
|
|
|
int code;
|
|
|
|
struct point stxt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct httpareq {
|
|
|
|
struct httitlereq titl;
|
2024-09-04 07:06:42 +00:00
|
|
|
struct point hentries[header_count];
|
|
|
|
};
|
|
|
|
|
2024-09-04 10:16:40 +00:00
|
|
|
struct httpares {
|
|
|
|
struct httitleres titl;
|
|
|
|
struct point hentries[header_count];
|
2024-09-04 18:35:50 +00:00
|
|
|
};
|
2024-09-04 10:16:40 +00:00
|
|
|
|
2024-09-09 18:55:21 +00:00
|
|
|
int stoin(char *str, int len, int *out);
|
2024-09-04 07:06:42 +00:00
|
|
|
int initres(void);
|
|
|
|
void fretres(void);
|
2024-09-08 19:41:17 +00:00
|
|
|
void frepareq(struct httpareq *req);
|
|
|
|
void frepares(struct httpares *res);
|
2024-09-04 07:06:42 +00:00
|
|
|
int readlin(char **buff, char **buff_lim);
|
|
|
|
int parshfield(char *offset, int len, /* out */ struct point *hentries);
|
2024-09-04 18:35:50 +00:00
|
|
|
|
2024-09-09 18:55:21 +00:00
|
|
|
int pahostinfo(char *offset, int len, /* out */ struct hostinfo *info);
|
2024-09-04 18:35:50 +00:00
|
|
|
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);
|
2024-09-04 07:06:42 +00:00
|
|
|
|
2024-08-15 23:12:06 +00:00
|
|
|
#endif
|