Implements TCP/IP + SSL COMSTACK. More...
#include <stdio.h>#include <string.h>#include <assert.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <yaz/comstack.h>#include <yaz/tcpip.h>Go to the source code of this file.
Data Structures | |
| struct | tcpip_state |
Defines | |
| #define | TRC(X) |
| #define | YAZ_SOCKLEN_T int |
| #define | CERTF "ztest.pem" |
| #define | KEYF "ztest.pem" |
| #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_put_connect (COMSTACK h, char *buf, int size) |
| static int | tcpip_get_connect (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) |
| 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) |
| COMSTACK | tcpip_type (int s, int flags, int protocol, void *vp) |
| 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) |
| struct addrinfo * | tcpip_getaddrinfo (const char *str, const char *port) |
| int | tcpip_strtoaddr_ex (const char *str, struct sockaddr_in *add, int default_port) |
| 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) |
Implements TCP/IP + SSL COMSTACK.
Definition in file tcpip.c.
| #define CS_TCPIP_BUFCHUNK 4096 |
Definition at line 994 of file tcpip.c.
Referenced by tcpip_get().
| #define TRC | ( | X | ) |
Definition at line 99 of file tcpip.c.
Referenced by tcpip_accept(), tcpip_bind(), tcpip_close(), tcpip_connect(), tcpip_get(), tcpip_listen(), tcpip_put(), tcpip_rcvconnect(), tcpip_strtoaddr_ex(), tcpip_type(), unix_accept(), unix_bind(), unix_close(), unix_connect(), unix_get(), unix_listen(), unix_put(), unix_rcvconnect(), unix_straddr1(), unix_strtoaddr(), unix_strtoaddr_ex(), and unix_type().
| #define YAZ_SOCKLEN_T int |
Definition at line 103 of file tcpip.c.
Referenced by tcpip_addrstr(), tcpip_listen(), and unix_listen().
| typedef struct tcpip_state tcpip_state |
| int cs_get_peer_certificate_x509 | ( | COMSTACK | cs, | |
| char ** | buf, | |||
| int * | len | |||
| ) |
Definition at line 1574 of file tcpip.c.
References cs_get_ssl(), and xmalloc.
Referenced by get_cert().
| void* cs_get_ssl | ( | COMSTACK | cs | ) |
Definition at line 1528 of file tcpip.c.
References comstack::cprivate, ssl_type(), and comstack::type.
Referenced by cs_get_peer_certificate_x509().
| void cs_print_session_info | ( | COMSTACK | cs | ) |
Definition at line 1490 of file tcpip.c.
References comstack::cprivate.
| int cs_set_ssl_certificate_file | ( | COMSTACK | cs, | |
| const char * | fname | |||
| ) |
Definition at line 1559 of file tcpip.c.
References comstack::cprivate, ssl_type(), and comstack::type.
Referenced by add_listener().
| int cs_set_ssl_ctx | ( | COMSTACK | cs, | |
| void * | ctx | |||
| ) |
Definition at line 1541 of file tcpip.c.
References comstack::cprivate, ssl_type(), and comstack::type.
| COMSTACK ssl_type | ( | int | s, | |
| int | flags, | |||
| int | protocol, | |||
| void * | vp | |||
| ) |
Definition at line 274 of file tcpip.c.
References comstack::cprivate, comstack::f_get, comstack::f_put, ssl_type(), tcpip_type(), and comstack::type.
Referenced by cs_get_ssl(), cs_parse_host(), cs_set_ssl_certificate_file(), cs_set_ssl_ctx(), ssl_type(), tcpip_bind(), and tcpip_rcvconnect().
Definition at line 824 of file tcpip.c.
References tcpip_state::ai, tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::altsize, comstack::cerrno, tcpip_state::complete, tcpip_state::connect_request_buf, tcpip_state::connect_response_buf, comstack::cprivate, cs_close, CS_DATA, CS_ST_ACCEPT, CS_ST_DATAXFER, CS_ST_IDLE, CS_ST_INCON, CSOUTSTATE, CSYSERR, comstack::event, comstack::flags, comstack::io_pending, comstack::iofile, comstack::newfd, comstack::state, tcpip_set_blocking(), tcpip_state::towrite, TRC, tcpip_state::written, xfree, and xmalloc.
Referenced by tcpip_type().
| const char * tcpip_addrstr | ( | COMSTACK | h | ) | [static] |
Definition at line 1396 of file tcpip.c.
References tcpip_state::buf, comstack::cerrno, comstack::cprivate, CS_FLAGS_NUMERICHOST, CSYSERR, comstack::flags, comstack::iofile, PROTO_HTTP, comstack::protocol, and YAZ_SOCKLEN_T.
Referenced by tcpip_type().
| static int tcpip_bind | ( | COMSTACK | h, | |
| void * | address, | |||
| int | mode | |||
| ) | [static] |
Definition at line 638 of file tcpip.c.
References tcpip_state::ai, comstack::cerrno, comstack::cprivate, CS_LISTEN, CS_SERVER, CS_ST_IDLE, CSERRORSSL, CSYSERR, comstack::event, comstack::iofile, ssl_type(), comstack::state, TRC, and comstack::type.
Referenced by tcpip_type().
| void tcpip_close | ( | COMSTACK | h | ) | [static] |
Definition at line 1334 of file tcpip.c.
References tcpip_state::ai, tcpip_state::altbuf, tcpip_state::connect_request_buf, tcpip_state::connect_response_buf, comstack::cprivate, comstack::iofile, TRC, and xfree.
Referenced by tcpip_type().
| int tcpip_connect | ( | COMSTACK | h, | |
| void * | address | |||
| ) | [static] |
Definition at line 506 of file tcpip.c.
References tcpip_state::ai, comstack::cerrno, comstack::cprivate, CS_CONNECT, CS_ST_CONNECTING, CS_ST_UNBND, CS_WANT_READ, CS_WANT_WRITE, CSOUTSTATE, CSYSERR, comstack::event, comstack::io_pending, comstack::iofile, comstack::state, tcpip_rcvconnect(), TRC, and yaz_errno().
Referenced by tcpip_type().
| int tcpip_get | ( | COMSTACK | h, | |
| char ** | buf, | |||
| int * | bufsize | |||
| ) | [static] |
Definition at line 1000 of file tcpip.c.
References tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::altsize, comstack::cerrno, tcpip_state::complete, comstack::cprivate, CS_TCPIP_BUFCHUNK, CS_WANT_READ, CSBUFSIZE, CSYSERR, comstack::io_pending, comstack::iofile, comstack::max_recv_bytes, TRC, xmalloc, xrealloc, yaz_errno(), and yaz_set_errno().
Referenced by tcpip_get_connect(), and tcpip_type().
| static int tcpip_get_connect | ( | COMSTACK | h, | |
| char ** | buf, | |||
| int * | bufsize | |||
| ) | [static] |
Definition at line 1613 of file tcpip.c.
References tcpip_state::complete, tcpip_state::connect_response_buf, tcpip_state::connect_response_len, comstack::cprivate, cs_complete_auto(), comstack::f_get, and tcpip_get().
Referenced by yaz_tcpip_create().
| struct addrinfo* tcpip_getaddrinfo | ( | const char * | str, | |
| const char * | port | |||
| ) | [read] |
Definition at line 338 of file tcpip.c.
Referenced by tcpip_straddr().
| static int tcpip_init | ( | void | ) | [static] |
Definition at line 162 of file tcpip.c.
Referenced by tcpip_straddr(), and tcpip_type().
| int tcpip_listen | ( | COMSTACK | h, | |
| char * | raddr, | |||
| int * | addrlen, | |||
| int(*)(void *cd, const char *a, int len, int t) | check_ip, | |||
| void * | cd | |||
| ) |
Definition at line 750 of file tcpip.c.
References comstack::cerrno, CS_ST_IDLE, CS_ST_INCON, CSDENY, CSNODATA, CSOUTSTATE, CSYSERR, comstack::iofile, comstack::newfd, comstack::state, TRC, yaz_errno(), and YAZ_SOCKLEN_T.
| 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().
| int tcpip_more | ( | COMSTACK | h | ) | [static] |
Definition at line 494 of file tcpip.c.
References tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::complete, and comstack::cprivate.
Referenced by tcpip_type().
| int tcpip_put | ( | COMSTACK | h, | |
| char * | buf, | |||
| int | size | |||
| ) | [static] |
Definition at line 1215 of file tcpip.c.
References comstack::cerrno, comstack::cprivate, CS_DATA, CS_WANT_WRITE, CSWRONGBUF, CSYSERR, comstack::event, comstack::io_pending, comstack::iofile, tcpip_state::towrite, TRC, tcpip_state::written, and yaz_errno().
Referenced by tcpip_put_connect(), and tcpip_type().
| static int tcpip_put_connect | ( | COMSTACK | h, | |
| char * | buf, | |||
| int | size | |||
| ) | [static] |
Definition at line 1598 of file tcpip.c.
References tcpip_state::connect_request_buf, tcpip_state::connect_request_len, comstack::cprivate, comstack::f_put, and tcpip_put().
Referenced by yaz_tcpip_create().
| int tcpip_rcvconnect | ( | COMSTACK | h | ) | [static] |
Definition at line 560 of file tcpip.c.
References comstack::cerrno, comstack::cprivate, CS_DATA, CS_ST_CONNECTING, CS_ST_DATAXFER, CSERRORSSL, CSOUTSTATE, comstack::event, comstack::iofile, ssl_type(), comstack::state, TRC, and comstack::type.
Referenced by tcpip_connect(), and tcpip_type().
| static int tcpip_set_blocking | ( | COMSTACK | p, | |
| int | blocking | |||
| ) | [static] |
Definition at line 1466 of file tcpip.c.
References CS_FLAGS_BLOCKING, comstack::flags, and comstack::iofile.
Referenced by tcpip_accept(), tcpip_straddr(), and tcpip_type().
| void * tcpip_straddr | ( | COMSTACK | h, | |
| const char * | str | |||
| ) | [static] |
Definition at line 421 of file tcpip.c.
References tcpip_state::ai, comstack::cprivate, CS_ST_UNBND, comstack::flags, comstack::iofile, PROTO_HTTP, comstack::protocol, comstack::state, tcpip_getaddrinfo(), tcpip_init(), and tcpip_set_blocking().
Referenced by tcpip_type().
| int tcpip_strtoaddr_ex | ( | const char * | str, | |
| struct sockaddr_in * | add, | |||
| int | default_port | |||
| ) |
| COMSTACK tcpip_type | ( | int | s, | |
| int | flags, | |||
| int | protocol, | |||
| void * | vp | |||
| ) |
Definition at line 172 of file tcpip.c.
References tcpip_state::ai, tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::altsize, comstack::cerrno, tcpip_state::complete, completeWAIS(), COMSTACK_DEFAULT_TIMEOUT, tcpip_state::connect_request_buf, tcpip_state::connect_request_len, tcpip_state::connect_response_buf, tcpip_state::connect_response_len, comstack::cprivate, cs_complete_auto(), CS_NONE, CS_ST_IDLE, CS_ST_UNBND, comstack::event, comstack::f_accept, comstack::f_addrstr, comstack::f_bind, comstack::f_close, comstack::f_connect, comstack::f_get, comstack::f_listen, comstack::f_more, comstack::f_put, comstack::f_rcvconnect, comstack::f_set_blocking, comstack::f_straddr, comstack::flags, comstack::io_pending, comstack::iofile, comstack::max_recv_bytes, PROTO_WAIS, comstack::protocol, comstack::state, tcpip_accept(), tcpip_addrstr(), tcpip_bind(), tcpip_close(), tcpip_connect(), tcpip_get(), tcpip_init(), tcpip_listen(), tcpip_more(), tcpip_put(), tcpip_rcvconnect(), tcpip_set_blocking(), tcpip_straddr(), tcpip_type(), comstack::timeout, tcpip_state::towrite, TRC, comstack::type, comstack::user, tcpip_state::written, and xmalloc.
Referenced by cs_create_host(), cs_parse_host(), inetd_connection(), ssl_type(), tcpip_type(), and yaz_tcpip_create().
| COMSTACK yaz_tcpip_create | ( | int | s, | |
| int | flags, | |||
| int | protocol, | |||
| const char * | connect_host | |||
| ) |
Definition at line 243 of file tcpip.c.
References tcpip_state::complete, tcpip_state::connect_request_buf, tcpip_state::connect_request_len, comstack::cprivate, cs_complete_auto_head(), comstack::f_get, comstack::f_put, tcpip_get_connect(), tcpip_put_connect(), tcpip_type(), and xmalloc.
Referenced by cs_create_host().
1.6.3