YAZ 5.37.0
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>
#include <yaz/snprintf.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)
static int cont_connect (COMSTACK h)
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 1059 of file tcpip.c.

Referenced by tcpip_get().

◆ RESOLVER_THREAD

#define RESOLVER_THREAD   1

Definition at line 70 of file tcpip.c.

◆ YAZ_SOCKLEN_T

#define YAZ_SOCKLEN_T   int

Definition at line 102 of file tcpip.c.

Typedef Documentation

◆ tcpip_state

typedef struct tcpip_state tcpip_state

Function Documentation

◆ connect_and_bind()

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

◆ cont_connect()

◆ create_net_socket()

◆ cs_get_peer_certificate_x509()

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

Definition at line 1567 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 1535 of file tcpip.c.

◆ cs_print_session_info()

void cs_print_session_info ( COMSTACK cs)

Definition at line 1493 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 1553 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 1541 of file tcpip.c.

References ssl_type(), and comstack::type.

◆ parse_host_port()

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

Definition at line 377 of file tcpip.c.

Referenced by tcpip_getaddrinfo(), and tcpip_rcvconnect().

◆ ssl_type()

◆ tcpip_accept()

◆ tcpip_addrstr()

◆ tcpip_bind()

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

◆ tcpip_close()

◆ tcpip_connect()

◆ tcpip_get()

◆ tcpip_getaddrinfo()

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

Definition at line 416 of file tcpip.c.

References parse_host_port().

Referenced by create_net_socket(), and tcpip_straddr().

◆ tcpip_init()

int tcpip_init ( void )
static

Definition at line 147 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()

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

◆ tcpip_more()

int tcpip_more ( COMSTACK h)
static

Definition at line 618 of file tcpip.c.

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

Referenced by tcpip_type().

◆ tcpip_put()

◆ tcpip_rcvconnect()

◆ tcpip_set_blocking()

int tcpip_set_blocking ( COMSTACK p,
int blocking )
static

◆ tcpip_state_create()

◆ tcpip_straddr()

◆ tcpip_type()

◆ 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 346 of file tcpip.c.

References 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 308 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 301 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 289 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

Definition at line 145 of file tcpip.c.