Blame samples/socks5-proxy/s5.h

Packit b5b901
/* Copyright StrongLoop, Inc. All rights reserved.
Packit b5b901
 *
Packit b5b901
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
 * of this software and associated documentation files (the "Software"), to
Packit b5b901
 * deal in the Software without restriction, including without limitation the
Packit b5b901
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
 * sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
 * furnished to do so, subject to the following conditions:
Packit b5b901
 *
Packit b5b901
 * The above copyright notice and this permission notice shall be included in
Packit b5b901
 * all copies or substantial portions of the Software.
Packit b5b901
 *
Packit b5b901
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
 * IN THE SOFTWARE.
Packit b5b901
 */
Packit b5b901
Packit b5b901
#ifndef S5_H_
Packit b5b901
#define S5_H_
Packit b5b901
Packit b5b901
#include <stddef.h>
Packit b5b901
#include <stdint.h>
Packit b5b901
Packit b5b901
#define S5_ERR_MAP(V)                                                         \
Packit b5b901
  V(-1, bad_version, "Bad protocol version.")                                 \
Packit b5b901
  V(-2, bad_cmd, "Bad protocol command.")                                     \
Packit b5b901
  V(-3, bad_atyp, "Bad address type.")                                        \
Packit b5b901
  V(0, ok, "No error.")                                                       \
Packit b5b901
  V(1, auth_select, "Select authentication method.")                          \
Packit b5b901
  V(2, auth_verify, "Verify authentication.")                                 \
Packit b5b901
  V(3, exec_cmd, "Execute command.")                                          \
Packit b5b901
Packit b5b901
typedef enum {
Packit b5b901
#define S5_ERR_GEN(code, name, _) s5_ ## name = code,
Packit b5b901
  S5_ERR_MAP(S5_ERR_GEN)
Packit b5b901
#undef S5_ERR_GEN
Packit b5b901
  s5_max_errors
Packit b5b901
} s5_err;
Packit b5b901
Packit b5b901
typedef enum {
Packit b5b901
  S5_AUTH_NONE = 1 << 0,
Packit b5b901
  S5_AUTH_GSSAPI = 1 << 1,
Packit b5b901
  S5_AUTH_PASSWD = 1 << 2
Packit b5b901
} s5_auth_method;
Packit b5b901
Packit b5b901
typedef enum {
Packit b5b901
  s5_auth_allow,
Packit b5b901
  s5_auth_deny
Packit b5b901
} s5_auth_result;
Packit b5b901
Packit b5b901
typedef enum {
Packit b5b901
  s5_atyp_ipv4,
Packit b5b901
  s5_atyp_ipv6,
Packit b5b901
  s5_atyp_host
Packit b5b901
} s5_atyp;
Packit b5b901
Packit b5b901
typedef enum {
Packit b5b901
  s5_cmd_tcp_connect,
Packit b5b901
  s5_cmd_tcp_bind,
Packit b5b901
  s5_cmd_udp_assoc
Packit b5b901
} s5_cmd;
Packit b5b901
Packit b5b901
typedef struct {
Packit b5b901
  uint32_t arg0;  /* Scratch space for the state machine. */
Packit b5b901
  uint32_t arg1;  /* Scratch space for the state machine. */
Packit b5b901
  uint8_t state;
Packit b5b901
  uint8_t methods;
Packit b5b901
  uint8_t cmd;
Packit b5b901
  uint8_t atyp;
Packit b5b901
  uint8_t userlen;
Packit b5b901
  uint8_t passlen;
Packit b5b901
  uint16_t dport;
Packit b5b901
  uint8_t username[257];
Packit b5b901
  uint8_t password[257];
Packit b5b901
  uint8_t daddr[257];  /* TODO(bnoordhuis) Merge with username/password. */
Packit b5b901
} s5_ctx;
Packit b5b901
Packit b5b901
void s5_init(s5_ctx *ctx);
Packit b5b901
Packit b5b901
s5_err s5_parse(s5_ctx *cx, uint8_t **data, size_t *size);
Packit b5b901
Packit b5b901
/* Only call after s5_parse() has returned s5_want_auth_method. */
Packit b5b901
unsigned int s5_auth_methods(const s5_ctx *cx);
Packit b5b901
Packit b5b901
/* Call after s5_parse() has returned s5_want_auth_method. */
Packit b5b901
int s5_select_auth(s5_ctx *cx, s5_auth_method method);
Packit b5b901
Packit b5b901
const char *s5_strerror(s5_err err);
Packit b5b901
Packit b5b901
#endif  /* S5_H_ */