XenevaOS
Loading...
Searching...
No Matches
https.h
Go to the documentation of this file.
1
30#ifndef XENEVA_HTTPS_H
31#define XENEVA_HTTPS_H
32
33#include <stddef.h>
34#include <stdint.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define XE_HTTP_ERR_MAX 160
41#define XE_HTTP_HDR_MAX 1024
42
52
53/* GET or HEAD. Returns 0 on a completed 1xx-3xx response, 22 on HTTP
54 * status >= 400 (body still filled), and -1 when the transfer failed. */
55int xe_http_get(const char* url,
56 const char* method,
57 const char* user_agent,
59 size_t max_body);
60
61/* How many GETs xe_http_get_many has in flight at once. Same-host
62 * requests share a TLS connection. A host gets at most two new
63 * handshakes; further GETs are keep-alive on those sockets. */
64#define XE_HTTP_MANY_MAX 8
65
66/* Fetch n independent GETs on this thread, XE_HTTP_MANY_MAX at a time.
67 * outs[i] matches urls[i]. max_body is one cap per URL, or NULL for
68 * 512 KiB each. rcs may be NULL; otherwise rcs[i] is 0, 22, or -1,
69 * the same as xe_http_get. No request body. Does not change the last URL.
70 * Returns 0 when the pump ran, or -1 if the arguments are unusable. */
71int xe_http_get_many(const char** urls, int n, const char* user_agent,
72 xe_http_response* outs, const size_t* max_body, int* rcs);
73
75
76/* Page the next request was started from. A request to that same host
77 * sends it as Referer. NULL or "" clears it. */
78void xe_http_set_referer(const char* url);
79
80/* One request body for the next xe_http_get. The call consumes it.
81 * NULL or a zero length clears a pending body. Used for form POST. */
82void xe_http_set_body(const char* content_type, const void* body, size_t len);
83
84/* URL of the last completed xe_http_get, after redirects. */
85void xe_http_last_url(char* dst, size_t dstsz);
86
87/* Store one Set-Cookie line, or one document.cookie assignment.
88 * from_http is 1 for a response header and 0 for a script. */
89void xe_cookie_set(const char* page_url, const char* set_cookie, int from_http);
90
91/* "n=v; n2=v2" for a Cookie request header, including HttpOnly. */
92int xe_cookie_header(const char* url, char* dst, size_t dstsz);
93
94/* document.cookie. HttpOnly names are left out. */
95int xe_cookie_document(const char* url, char* dst, size_t dstsz);
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif
#define out(...)
Definition main.cpp:65
#define XE_HTTP_ERR_MAX
Definition https.h:40
int xe_http_get(const char *url, const char *method, const char *user_agent, xe_http_response *out, size_t max_body)
Definition https.cpp:2741
void xe_http_response_free(xe_http_response *out)
Definition https.cpp:129
int xe_cookie_header(const char *url, char *dst, size_t dstsz)
Definition https.cpp:1283
void xe_cookie_set(const char *page_url, const char *set_cookie, int from_http)
Definition https.cpp:1276
int xe_http_get_many(const char **urls, int n, const char *user_agent, xe_http_response *outs, const size_t *max_body, int *rcs)
Definition https.cpp:2575
void xe_http_last_url(char *dst, size_t dstsz)
Definition https.cpp:1270
int xe_cookie_document(const char *url, char *dst, size_t dstsz)
Definition https.cpp:1293
void xe_http_set_referer(const char *url)
Definition https.cpp:1240
void xe_http_set_body(const char *content_type, const void *body, size_t len)
Definition https.cpp:1251
#define XE_HTTP_HDR_MAX
Definition https.h:41
size_t len
Definition initial.c:23
Definition https.h:43
int status
Definition https.h:44
char headers[XE_HTTP_HDR_MAX]
Definition https.h:50
int tls
Definition https.h:45
size_t body_len
Definition https.h:48
int https_to_http
Definition https.h:46
char error[XE_HTTP_ERR_MAX]
Definition https.h:49
char * body
Definition https.h:47