ESP8266-based WiFi serial modem emulator ROM
1/*
2 * WiFiPPP
3 * Copyright (c) 2021 joshua stein <jcs@jcs.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#pragma once
19
20#include <WiFiClient.h>
21#include <WiFiClientSecure.h>
22
23class SocksClient : public WiFiClient {
24public:
25 virtual ~SocksClient();
26 SocksClient(int _slot, WiFiClient _client);
27
28 bool done();
29 void process();
30
31 bool tls() { return _tls; };
32 int state;
33 int slot;
34 WiFiClient local_client;
35 WiFiClient remote_client;
36 WiFiClientSecure remote_client_tls;
37
38private:
39 void verify_method();
40 bool verify_state(int _state);
41 bool verify_version();
42 void handle_request();
43 void fail_close(char code);
44 void connect();
45 void proxy();
46 void finish();
47
48 void dump_buf(char *buf, size_t len);
49
50 /* data from local client */
51 unsigned char local_buf[32];
52 size_t local_buf_len;
53
54 /* data from remote client */
55 unsigned char remote_buf[256];
56 size_t remote_buf_len;
57 unsigned char *remote_hostname;
58 ip4_addr_t remote_ip;
59 uint16_t remote_port;
60 bool _tls;
61};