YAZ  5.34.0
Data Structures | Macros | Typedefs | Functions | Variables
tcpip.c File Reference

Implements TCP/IP + SSL COMSTACK. More...

#include <yaz/yconfig.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <yaz/thread_create.h>
#include <yaz/log.h>
#include <yaz/base64.h>
#include <yaz/comstack.h>
#include <yaz/tcpip.h>

Go to the source code of this file.

Data Structures

struct  tcpip_state
 

Macros

#define RESOLVER_THREAD   1
 
#define YAZ_SOCKLEN_T   int
 
#define CS_TCPIP_BUFCHUNK   4096
 

Typedefs

typedef struct tcpip_state tcpip_state
 

Functions

static void tcpip_close (COMSTACK h)
 
static int tcpip_put (COMSTACK h, char *buf, int size)
 
static int tcpip_get (COMSTACK h, char **buf, int *bufsize)
 
static int tcpip_connect (COMSTACK h, void *address)
 
static int tcpip_more (COMSTACK h)
 
static int tcpip_rcvconnect (COMSTACK h)
 
static int tcpip_bind (COMSTACK h, void *address, int mode)
 
static int tcpip_listen (COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
 
static int tcpip_set_blocking (COMSTACK p, int blocking)
 
struct addrinfo * tcpip_getaddrinfo (const char *str, const char *port, int *ipv6_only)
 
static COMSTACK tcpip_accept (COMSTACK h)
 
static const char * tcpip_addrstr (COMSTACK h)
 
static void * tcpip_straddr (COMSTACK h, const char *str)
 
static int tcpip_init (void)
 
static struct tcpip_statetcpip_state_create (void)
 
COMSTACK tcpip_type (int s, int flags, int protocol, void *vp)
 
static void connect_and_bind (COMSTACK p, const char *connect_host, const char *connect_auth, const char *bind_host)
 
COMSTACK yaz_tcpip_create3 (int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host)
 
COMSTACK yaz_tcpip_create2 (int s, int flags, int protocol, const char *connect_host, const char *bind_host)
 
COMSTACK yaz_tcpip_create (int s, int flags, int protocol, const char *connect_host)
 
COMSTACK ssl_type (int s, int flags, int protocol, void *vp)
 
COMSTACK yaz_ssl_create (int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host)
 
static void parse_host_port (const char *host_port, char *tmp, size_t tmp_sz, const char **host, const char **port)
 
static struct addrinfo * create_net_socket (COMSTACK h)
 
void * resolver_thread (void *arg)
 
static struct addrinfo * wait_resolver_thread (COMSTACK h)
 
static int cont_connect (COMSTACK h)
 
int tcpip_listen (COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int t), void *cd)
 
void cs_print_session_info (COMSTACK cs)
 
void * cs_get_ssl (COMSTACK cs)
 
int cs_set_ssl_ctx (COMSTACK cs, void *ctx)
 
int cs_set_ssl_certificate_file (COMSTACK cs, const char *fname)
 
int cs_get_peer_certificate_x509 (COMSTACK cs, char **buf, int *len)
 
int cs_set_head_only (COMSTACK cs, int head_only)
 

Variables

static int log_level = 0
 

Detailed Description

Implements TCP/IP + SSL COMSTACK.

Definition in file tcpip.c.

Macro Definition Documentation

◆ CS_TCPIP_BUFCHUNK

#define CS_TCPIP_BUFCHUNK   4096

Definition at line 1055 of file tcpip.c.

◆ RESOLVER_THREAD

#define RESOLVER_THREAD   1

Definition at line 69 of file tcpip.c.

◆ YAZ_SOCKLEN_T

#define YAZ_SOCKLEN_T   int

Definition at line 101 of file tcpip.c.

Typedef Documentation

◆ tcpip_state

typedef struct tcpip_state tcpip_state

Function Documentation

◆ connect_and_bind()

static void connect_and_bind ( COMSTACK  p,
const char *  connect_host,
const char *  connect_auth,
const char *  bind_host 
)
static

◆ cont_connect()

static int cont_connect ( COMSTACK  h)
static

◆ create_net_socket()

static struct addrinfo* create_net_socket ( COMSTACK  h)
static

◆ cs_get_peer_certificate_x509()

int cs_get_peer_certificate_x509 ( COMSTACK  cs,
char **  buf,
int *  len 
)

Definition at line 1563 of file tcpip.c.

References tcpip_state::buf, comstack::cprivate, ssl_type(), comstack::type, and xstrdup.

Referenced by get_cert().

◆ cs_get_ssl()

void* cs_get_ssl ( COMSTACK  cs)

Definition at line 1531 of file tcpip.c.

◆ cs_print_session_info()

void cs_print_session_info ( COMSTACK  cs)

Definition at line 1489 of file tcpip.c.

References comstack::cprivate, ssl_type(), and comstack::type.

◆ cs_set_head_only()

int cs_set_head_only ( COMSTACK  cs,
int  head_only 
)

◆ cs_set_ssl_certificate_file()

int cs_set_ssl_certificate_file ( COMSTACK  cs,
const char *  fname 
)

Definition at line 1549 of file tcpip.c.

References comstack::cprivate, ssl_type(), and comstack::type.

Referenced by add_listener().

◆ cs_set_ssl_ctx()

int cs_set_ssl_ctx ( COMSTACK  cs,
void *  ctx 
)

Definition at line 1537 of file tcpip.c.

References ssl_type(), and comstack::type.

◆ parse_host_port()

static void parse_host_port ( const char *  host_port,
char *  tmp,
size_t  tmp_sz,
const char **  host,
const char **  port 
)
static

Definition at line 376 of file tcpip.c.

References tcpip_state::host_port, and tcpip_state::port.

Referenced by tcpip_getaddrinfo(), and tcpip_rcvconnect().

◆ resolver_thread()

void* resolver_thread ( void *  arg)

◆ ssl_type()

COMSTACK ssl_type ( int  s,
int  flags,
int  protocol,
void *  vp 
)

◆ tcpip_accept()

COMSTACK tcpip_accept ( COMSTACK  h)
static

◆ tcpip_addrstr()

const char * tcpip_addrstr ( COMSTACK  h)
static

◆ tcpip_bind()

static int tcpip_bind ( COMSTACK  h,
void *  address,
int  mode 
)
static

◆ tcpip_close()

void tcpip_close ( COMSTACK  h)
static

◆ tcpip_connect()

int tcpip_connect ( COMSTACK  h,
void *  address 
)
static

◆ tcpip_get()

int tcpip_get ( COMSTACK  h,
char **  buf,
int *  bufsize 
)
static

◆ tcpip_getaddrinfo()

struct addrinfo * tcpip_getaddrinfo ( const char *  str,
const char *  port,
int *  ipv6_only 
)

Definition at line 415 of file tcpip.c.

References parse_host_port().

Referenced by create_net_socket(), resolver_thread(), and tcpip_straddr().

◆ tcpip_init()

static int tcpip_init ( void  )
static

Definition at line 146 of file tcpip.c.

References log_level, log_level_set, yaz_init_globals(), and yaz_log_module_level().

Referenced by tcpip_straddr(), and tcpip_type().

◆ tcpip_listen() [1/2]

int tcpip_listen ( COMSTACK  h,
char *  raddr,
int *  addrlen,
int(*)(void *cd, const char *a, int len, int t)  check_ip,
void *  cd 
)

◆ tcpip_listen() [2/2]

static int tcpip_listen ( COMSTACK  h,
char *  raddr,
int *  addrlen,
int(*)(void *cd, const char *a, int len, int type check_ip,
void *  cd 
)
static

Referenced by tcpip_type().

◆ tcpip_more()

int tcpip_more ( COMSTACK  h)
static

Definition at line 614 of file tcpip.c.

References tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::complete, and comstack::cprivate.

Referenced by tcpip_type().

◆ tcpip_put()

int tcpip_put ( COMSTACK  h,
char *  buf,
int  size 
)
static

◆ tcpip_rcvconnect()

int tcpip_rcvconnect ( COMSTACK  h)
static

◆ tcpip_set_blocking()

static int tcpip_set_blocking ( COMSTACK  p,
int  blocking 
)
static

◆ tcpip_state_create()

static struct tcpip_state* tcpip_state_create ( void  )
static

◆ tcpip_straddr()

void * tcpip_straddr ( COMSTACK  h,
const char *  str 
)
static

◆ tcpip_type()

COMSTACK tcpip_type ( int  s,
int  flags,
int  protocol,
void *  vp 
)

◆ wait_resolver_thread()

static struct addrinfo* wait_resolver_thread ( COMSTACK  h)
static

◆ yaz_ssl_create()

COMSTACK yaz_ssl_create ( int  s,
int  flags,
int  protocol,
const char *  connect_host,
const char *  connect_auth,
const char *  bind_host 
)

Definition at line 345 of file tcpip.c.

References tcpip_state::bind_host, connect_and_bind(), and ssl_type().

Referenced by cs_create_host2().

◆ yaz_tcpip_create()

COMSTACK yaz_tcpip_create ( int  s,
int  flags,
int  protocol,
const char *  connect_host 
)

Definition at line 307 of file tcpip.c.

References yaz_tcpip_create2().

◆ yaz_tcpip_create2()

COMSTACK yaz_tcpip_create2 ( int  s,
int  flags,
int  protocol,
const char *  connect_host,
const char *  bind_host 
)

Definition at line 300 of file tcpip.c.

References tcpip_state::bind_host, and yaz_tcpip_create3().

Referenced by yaz_tcpip_create().

◆ yaz_tcpip_create3()

COMSTACK yaz_tcpip_create3 ( int  s,
int  flags,
int  protocol,
const char *  connect_host,
const char *  connect_auth,
const char *  bind_host 
)

Definition at line 288 of file tcpip.c.

References tcpip_state::bind_host, connect_and_bind(), and tcpip_type().

Referenced by cs_create_host2(), and yaz_tcpip_create2().

Variable Documentation

◆ log_level

int log_level = 0
static