vttp
An HTTP backed Virtual Table extension for SQLite
Loading...
Searching...
No Matches
fetch.h
Go to the documentation of this file.
1
6#pragma once
7#include "pyc.h"
8#include <openssl/types.h>
9#include <stdbool.h>
10#include <stdio.h>
11
15struct url {
22 char *host;
23
29 struct str hostname;
30
37 char *pathname;
38
44 struct str port;
45
51 struct str protocol;
52};
53void url_free(struct url *url);
54
55struct dispatch {
56 int sockfd;
57 SSL *ssl;
58 SSL_CTX *ctx;
59 struct url url;
60 struct addrinfo *addrinfo;
61};
62void dispatch_free(struct dispatch *dispatch);
63struct dispatch *fetch_socket(const char *url, const char *init[4]);
64int use_fetch(int fds[4], struct dispatch *dispatch);
65
67 /* FDs */
68 int netfd; // TCP socket (nonblocking)
69 int outfd; // socketpair writer FD (nonblocking)
70 int ep; // epoll instance FD
71
72 char *hostname;
73 SSL_CTX *ssl_ctx;
74 SSL *ssl;
75
76 /* --- HTTP HEADER PARSING --- */
77 bool headers_done;
78 char header_buf[8192]; // store header bytes
79 size_t header_len;
80
81 bool chunked_mode;
82 size_t content_length;
83
84 /* --- CHUNKED DECODING STATE --- */
85 bool reading_chunk_size; // true = reading hex size line
86 char chunk_line[128]; // buffer for chunk-size line
87 size_t chunk_line_len; // how many chars collected
88 size_t current_chunk_size; // remaining bytes in current chunk
89 int expecting_crlf; // 2 -> expecting "\r\n"
90
91 FILE *stream;
92
93 /* --- NONBLOCKING SEND STATE FOR outfd --- */
94 char *pending_buf; // partial write buffer (JSON object)
95 size_t pending_len; // bytes left to send
96 size_t pending_off; // current offset in pending_send
97
98 /* --- TERMINATION STATE --- */
99 bool http_done; // reached end of chunked stream or TCP closed
100 bool closed_outfd; // have we closed outfd yet?
101};
102
103void *fetcher(void *arg);
A python-inspired API for general C scripts.
Definition fetch.h:55
Definition fetch.h:66
Buffer pointer + length.
Definition pyc.h:24
Definition fetch.h:15
char * host
A string containing the domain (that is the hostname) followed by (if a port was specified) a ':' and...
Definition fetch.h:22
char * pathname
A string containing an initial '/' followed by the path of the URL, not including the query string or...
Definition fetch.h:37
struct str port
A string containing the port number of the URL.
Definition fetch.h:44
struct str hostname
A string containing the domain of the URL.
Definition fetch.h:29
struct str protocol
A string containing the protocol scheme of the URL, including the final ':'.
Definition fetch.h:51