|
YAZ 5.38.1
|
Transport-independent communication endpoints for BER and HTTP. More...
Go to the source code of this file.
Data Structures | |
| struct | comstack |
| Public endpoint state and transport dispatch table. More... | |
Macros | |
| #define | CS_ST_UNBND 0 |
| #define | CS_ST_IDLE 1 |
| #define | CS_ST_INCON 2 |
| #define | CS_ST_OUTCON 3 |
| #define | CS_ST_DATAXFER 4 |
| #define | CS_ST_ACCEPT 5 |
| #define | CS_ST_CONNECTING 6 |
| #define | CS_NONE 0 |
| #define | CS_CONNECT 1 |
| #define | CS_DISCON 2 |
| #define | CS_LISTEN 3 |
| #define | CS_DATA 4 |
| #define | CS_CLIENT 0 |
| #define | CS_SERVER 1 |
| #define | cs_put(handle, buf, size) |
| Sends a complete message. | |
| #define | cs_get(handle, buf, size) |
| Receives a BER or HTTP message. | |
| #define | cs_more(handle) |
| Tests whether buffered input can be processed without another read. | |
| #define | cs_connect(handle, address) |
| Starts an outgoing connection. | |
| #define | cs_rcvconnect(handle) |
| Continues a pending outgoing connection, including TLS or CONNECT. | |
| #define | cs_bind(handle, ad, mo) |
| Binds an endpoint to a local address. | |
| #define | cs_listen(handle, ap, al) |
| Receives an incoming connection for subsequent cs_accept. | |
| #define | cs_listen_check(handle, ap, al, cf, cd) |
| Receives an incoming connection with an optional access check. | |
| #define | cs_accept(handle) |
| Creates an endpoint for a connection received by cs_listen. | |
| #define | cs_close(handle) |
| Closes the socket and frees the endpoint and its transport state. | |
| #define | cs_create(type, flags, proto) |
| Creates an endpoint using a transport constructor. | |
| #define | cs_createbysocket(sock, type, flags, proto) |
| Creates an endpoint around an existing socket. | |
| #define | cs_type(handle) |
| Returns the endpoint's CS_TYPE transport constructor. | |
| #define | cs_fileno(handle) |
| Returns the socket descriptor, or -1 if none has been created. | |
| #define | cs_getstate(handle) |
| Legacy accessor intended to return the connection state. | |
| #define | cs_errno(handle) |
| Returns the last COMSTACK error code. | |
| #define | cs_getproto(handle) |
| Returns the application protocol (enum oid_proto). | |
| #define | cs_addrstr(handle) |
| Formats the peer address as text. | |
| #define | cs_straddr(handle, str) |
| Parses a transport-specific address and prepares the endpoint. | |
| #define | cs_want_read(handle) |
| Tests whether a pending operation needs socket readability. | |
| #define | cs_want_write(handle) |
| Tests whether a pending operation needs socket writability. | |
| #define | cs_set_blocking(handle, blocking) |
| Updates endpoint flags and socket blocking mode. | |
| #define | CS_WANT_READ 1 |
| #define | CS_WANT_WRITE 2 |
| #define | CSNONE 0 |
| #define | CSYSERR 1 |
| #define | CSOUTSTATE 2 |
| #define | CSNODATA 3 |
| #define | CSWRONGBUF 4 |
| #define | CSDENY 5 |
| #define | CSERRORSSL 6 |
| #define | CSBUFSIZE 7 |
| #define | CSPROTERR 8 |
| #define | CSLASTERROR CSPROTERR |
| #define | CS_FLAGS_BLOCKING 1 |
| #define | CS_FLAGS_NUMERICHOST 2 |
| #define | CS_FLAGS_DNS_NO_BLOCK 4 |
| #define | CS_FLAGS_CHECK_CERT 8 |
Typedefs | |
| typedef struct comstack * | COMSTACK |
| Communication endpoint; release with cs_close. | |
| typedef COMSTACK(*) | CS_TYPE(int s, int flags, int protocol, void *vp) |
| Transport constructor and transport identity. | |
Functions | |
| int | cs_look (COMSTACK) |
| Returns the last recorded event (CS_NONE, CS_CONNECT, etc.). | |
| const char * | cs_strerror (COMSTACK h) |
| Returns a static message for the endpoint's last error. | |
| const char * | cs_errmsg (int n) |
| Returns a static message for a COMSTACK error code. | |
| int | cs_get_error (COMSTACK cs, const char **details) |
| Returns the last COMSTACK error and optional transport details. | |
| COMSTACK | cs_create_host (const char *type_and_host, int flags, void **vp) |
| Creates an endpoint from a host or URI specification. | |
| COMSTACK | cs_create_host_proxy (const char *vhost, int flags, void **vp, const char *proxy_host) |
| Creates an endpoint with an optional proxy. | |
| COMSTACK | cs_create_host2 (const char *vhost, int flags, void **vp, const char *proxy_host, int *proxy_mode) |
| Creates an endpoint and selects direct or proxy connection handling. | |
| void | cs_get_host_args (const char *type_and_host, const char **args) |
| Extracts application arguments from a host or URI specification. | |
| int | cs_complete_auto_head (const char *buf, int len) |
| Finds the length of a BER message or HTTP headers. | |
| int | cs_complete_auto (const char *buf, int len) |
| Finds the length of a complete BER or HTTP message. | |
| void * | cs_get_ssl (COMSTACK cs) |
| Legacy OpenSSL session accessor. | |
| int | cs_set_ssl_ctx (COMSTACK cs, void *ctx) |
| Legacy OpenSSL context setter. | |
| int | cs_set_ssl_certificate_file (COMSTACK cs, const char *fname) |
| Selects certificate and private key files for a TLS endpoint. | |
| int | cs_get_peer_certificate_x509 (COMSTACK cs, char **buf, int *len) |
| Gets a human-readable description of the first peer X.509 certificate. | |
| void | cs_set_max_recv_bytes (COMSTACK cs, int max_recv_bytes) |
| Sets the maximum incoming message size. | |
| void | cs_print_session_info (COMSTACK cs) |
| Prints TLS peer certificate information to standard output. | |
| int | cs_parse_host (const char *uri, const char **host, CS_TYPE *t, enum oid_proto *proto, char **connect_host) |
| Parses transport and protocol prefixes without resolving an address. | |
| int | cs_set_head_only (COMSTACK cs, int head_only) |
| Selects HTTP header-only framing for TCP/IP, SSL or UNIX transports. | |
Transport-independent communication endpoints for BER and HTTP.
Most operations dispatch through transport callbacks. Unless stated otherwise, handles and output pointers must be non-NULL. Macro arguments must not have side effects: a handle expression can be evaluated more than once.
Definition in file comstack.h.
| #define cs_accept | ( | handle | ) |
Creates an endpoint for a connection received by cs_listen.
| handle | listener, or an accepted endpoint with a pending TLS handshake |
The original listener remains usable. If the returned endpoint has pending I/O, wait for the indicated directions and call cs_accept on that endpoint again to continue its TLS handshake. A failed TLS handshake releases the pending endpoint. Close a successfully accepted endpoint with cs_close.
Definition at line 217 of file comstack.h.
Referenced by ir_session(), and listener().
| #define cs_addrstr | ( | handle | ) |
Formats the peer address as text.
| handle | endpoint |
Subsequent calls may overwrite the result. Network transports may perform reverse DNS unless CS_FLAGS_NUMERICHOST is set.
Definition at line 270 of file comstack.h.
Referenced by assoc_init_reset(), inetd_connection(), listener(), and new_session().
| #define cs_bind | ( | handle, | |
| ad, | |||
| mo ) |
Binds an endpoint to a local address.
| handle | endpoint |
| ad | transport address returned by cs_straddr or cs_create_host |
| mo | CS_SERVER to bind and listen, CS_CLIENT to bind only |
Definition at line 183 of file comstack.h.
Referenced by add_listener().
| #define CS_CLIENT 0 |
Bind a local address without listening.
Definition at line 114 of file comstack.h.
| #define cs_close | ( | handle | ) |
Closes the socket and frees the endpoint and its transport state.
| handle | endpoint, which must not be used after this call |
Does not free application data in user or the caller's cs_get buffer.
Definition at line 223 of file comstack.h.
Referenced by add_listener(), cs_create_host2(), do_connect_host(), ir_read(), ir_session(), listener(), tcpip_accept(), yaz_url_exec(), and ZOOM_connection_destroy().
| #define CS_CONNECT 1 |
Connection establishment event.
Definition at line 93 of file comstack.h.
Referenced by tcpip_connect(), tcpip_rcvconnect(), unix_connect(), and ZOOM_connection_do_io().
| #define cs_connect | ( | handle, | |
| address ) |
Starts an outgoing connection.
| handle | endpoint |
| address | transport address returned by cs_straddr or cs_create_host |
For a pending connection, wait as indicated by cs_want_read/cs_want_write and continue with cs_rcvconnect.
Definition at line 171 of file comstack.h.
Referenced by do_connect_host(), and yaz_url_exec().
| #define cs_create | ( | type, | |
| flags, | |||
| proto ) |
Creates an endpoint using a transport constructor.
| type | CS_TYPE constructor, such as tcpip_type or unix_type |
| flags | combination of CS_FLAGS_* bits |
| proto | application protocol (enum oid_proto) |
Definition at line 230 of file comstack.h.
Referenced by cs_create_host2().
| #define cs_createbysocket | ( | sock, | |
| type, | |||
| flags, | |||
| proto ) |
Creates an endpoint around an existing socket.
| sock | socket descriptor; ownership transfers on success |
| type | CS_TYPE transport constructor |
| flags | combination of CS_FLAGS_* bits |
| proto | application protocol (enum oid_proto) |
Definition at line 238 of file comstack.h.
Referenced by inetd_connection().
| #define CS_DATA 4 |
Data transfer event.
Definition at line 99 of file comstack.h.
Referenced by tcpip_accept(), tcpip_put(), tcpip_rcvconnect(), unix_accept(), unix_put(), unix_rcvconnect(), and ZOOM_connection_do_io().
| #define CS_DISCON 2 |
Disconnection event.
Definition at line 95 of file comstack.h.
| #define cs_errno | ( | handle | ) |
Returns the last COMSTACK error code.
| handle | endpoint |
Definition at line 258 of file comstack.h.
Referenced by add_listener(), do_read(), and ir_read().
| #define cs_fileno | ( | handle | ) |
Returns the socket descriptor, or -1 if none has been created.
| handle | endpoint |
Definition at line 247 of file comstack.h.
Referenced by add_listener(), inetd_connection(), new_session(), and yaz_url_exec().
| #define CS_FLAGS_BLOCKING 1 |
Use blocking I/O; without this bit operations may remain pending.
Definition at line 560 of file comstack.h.
Referenced by tcpip_connect(), tcpip_get(), tcpip_put(), tcpip_rcvconnect(), tcpip_set_blocking(), unix_accept(), unix_set_blocking(), and unix_type().
| #define CS_FLAGS_CHECK_CERT 8 |
Verify the TLS server certificate and hostname when connecting.
Definition at line 566 of file comstack.h.
Referenced by do_connect_host(), tcpip_rcvconnect(), and yaz_url_exec().
| #define CS_FLAGS_DNS_NO_BLOCK 4 |
Resolve asynchronously when resolver thread support is available.
Definition at line 564 of file comstack.h.
Referenced by do_connect_host(), and tcpip_straddr().
| #define CS_FLAGS_NUMERICHOST 2 |
Use numeric peer addresses instead of reverse DNS in cs_addrstr.
Definition at line 562 of file comstack.h.
Referenced by add_listener(), and tcpip_addrstr().
| #define cs_get | ( | handle, | |
| buf, | |||
| size ) |
Receives a BER or HTTP message.
| handle | endpoint |
| buf | address of a receive buffer pointer; initialize *buf to NULL |
| size | address of its allocated capacity; initialize *size to zero |
The transport allocates, resizes, or replaces *buf and updates *size. Retain both values for subsequent calls and eventually free *buf with xfree. A pending read may need either readability or writability; consult cs_want_read and cs_want_write.
Definition at line 155 of file comstack.h.
Referenced by do_read(), ir_read(), and yaz_url_exec().
| #define cs_getproto | ( | handle | ) |
Returns the application protocol (enum oid_proto).
| handle | endpoint |
Definition at line 262 of file comstack.h.
Referenced by create_association().
| #define cs_getstate | ( | handle | ) |
Legacy accessor intended to return the connection state.
| handle | endpoint |
Definition at line 253 of file comstack.h.
| #define CS_LISTEN 3 |
Listen event.
Definition at line 97 of file comstack.h.
Referenced by tcpip_bind(), and unix_bind().
| #define cs_listen | ( | handle, | |
| ap, | |||
| al ) |
Receives an incoming connection for subsequent cs_accept.
| handle | listening endpoint |
| ap | optional buffer for the transport's binary peer address |
| al | address buffer capacity on input, copied length on output; NULL to discard the address (ap may then be NULL) |
An insufficient address buffer produces an output length of zero.
Definition at line 194 of file comstack.h.
| #define cs_listen_check | ( | handle, | |
| ap, | |||
| al, | |||
| cf, | |||
| cd ) |
Receives an incoming connection with an optional access check.
| handle | listening endpoint |
| ap | optional peer address buffer, as for cs_listen |
| al | address buffer capacity/result length, as for cs_listen |
| cf | callback or NULL; nonzero rejects the connection with CSDENY |
| cd | application data passed to cf |
The callback receives cd, a binary peer address, its byte length, and its address family. The check is supported by TCP/IP and TLS on non-Windows systems; the UNIX transport ignores it.
Definition at line 207 of file comstack.h.
Referenced by listener().
| #define cs_more | ( | handle | ) |
Tests whether buffered input can be processed without another read.
| handle | endpoint |
Does not poll the socket. Call before waiting for socket readability.
Definition at line 162 of file comstack.h.
Referenced by ir_read().
| #define CS_NONE 0 |
No event recorded.
Definition at line 91 of file comstack.h.
Referenced by tcpip_type(), unix_accept(), unix_type(), and ZOOM_connection_do_io().
| #define cs_put | ( | handle, | |
| buf, | |||
| size ) |
Sends a complete message.
| handle | endpoint |
| buf | message bytes; keep valid until the write completes |
| size | number of bytes to send |
Retry pending writes with the same buffer and size after waiting for the directions indicated by cs_want_read and cs_want_write.
Definition at line 143 of file comstack.h.
Referenced by do_write_ex(), ir_session(), and yaz_url_exec().
| #define cs_rcvconnect | ( | handle | ) |
Continues a pending outgoing connection, including TLS or CONNECT.
| handle | endpoint |
Definition at line 176 of file comstack.h.
Referenced by yaz_url_exec(), and ZOOM_connection_do_io().
| #define CS_SERVER 1 |
Bind a local address and listen for connections.
Definition at line 116 of file comstack.h.
Referenced by add_listener(), tcpip_bind(), and unix_bind().
| #define cs_set_blocking | ( | handle, | |
| blocking ) |
Updates endpoint flags and socket blocking mode.
| handle | endpoint |
| blocking | complete set of CS_FLAGS_* bits, despite the parameter name |
Preserve other desired flag bits when setting or clearing CS_FLAGS_BLOCKING; this operation replaces the stored flags.
Definition at line 299 of file comstack.h.
| #define CS_ST_ACCEPT 5 |
Accepted connection with a pending TLS handshake.
Definition at line 83 of file comstack.h.
Referenced by tcpip_accept(), and unix_accept().
| #define CS_ST_CONNECTING 6 |
Outgoing connection establishment in progress.
Definition at line 85 of file comstack.h.
Referenced by tcpip_connect(), tcpip_rcvconnect(), unix_connect(), and unix_rcvconnect().
| #define CS_ST_DATAXFER 4 |
Established connection ready for data transfer.
Definition at line 81 of file comstack.h.
Referenced by tcpip_accept(), tcpip_rcvconnect(), unix_accept(), and unix_rcvconnect().
| #define CS_ST_IDLE 1 |
Bound endpoint ready to listen.
Definition at line 75 of file comstack.h.
Referenced by tcpip_accept(), tcpip_bind(), tcpip_listen(), tcpip_type(), unix_accept(), unix_bind(), unix_listen(), and unix_type().
| #define CS_ST_INCON 2 |
Incoming connection awaiting cs_accept.
Definition at line 77 of file comstack.h.
Referenced by tcpip_accept(), tcpip_listen(), unix_accept(), and unix_listen().
| #define CS_ST_OUTCON 3 |
Outgoing connection state (legacy).
Definition at line 79 of file comstack.h.
| #define CS_ST_UNBND 0 |
Unbound endpoint.
Definition at line 73 of file comstack.h.
Referenced by cont_connect(), tcpip_connect(), tcpip_rcvconnect(), tcpip_straddr(), tcpip_type(), unix_connect(), and unix_type().
| #define cs_straddr | ( | handle, | |
| str ) |
Parses a transport-specific address and prepares the endpoint.
| handle | endpoint |
| str | address without a transport prefix; see cs_create_host2 for the higher-level host/URI interface |
May resolve names and create a socket. Do not free the result; another cs_straddr call may replace it, and cs_close releases it.
Definition at line 280 of file comstack.h.
Referenced by cs_create_host2().
| #define cs_type | ( | handle | ) |
Returns the endpoint's CS_TYPE transport constructor.
| handle | endpoint |
Definition at line 243 of file comstack.h.
| #define CS_WANT_READ 1 |
Pending operation needs socket readability.
Definition at line 302 of file comstack.h.
Referenced by do_connect_host(), do_write_ex(), ir_session(), new_session(), tcpip_connect(), tcpip_get(), unix_get(), yaz_url_exec(), and ZOOM_connection_do_io().
| #define cs_want_read | ( | handle | ) |
Tests whether a pending operation needs socket readability.
| handle | endpoint |
Definition at line 285 of file comstack.h.
| #define CS_WANT_WRITE 2 |
Pending operation needs socket writability.
Definition at line 304 of file comstack.h.
Referenced by do_connect_host(), do_write_ex(), ir_read(), ir_session(), new_session(), tcpip_connect(), tcpip_put(), unix_connect(), unix_put(), yaz_url_exec(), and ZOOM_connection_do_io().
| #define cs_want_write | ( | handle | ) |
Tests whether a pending operation needs socket writability.
| handle | endpoint |
Definition at line 290 of file comstack.h.
| #define CSBUFSIZE 7 |
Incoming data exceeds the configured receive limit.
Definition at line 553 of file comstack.h.
Referenced by do_read(), ir_read(), tcpip_get(), and unix_get().
| #define CSDENY 5 |
Incoming connection was rejected by the access callback.
Definition at line 549 of file comstack.h.
Referenced by tcpip_listen(), and tcpip_rcvconnect().
| #define CSERRORSSL 6 |
TLS operation failed; cs_get_error may provide details.
Definition at line 551 of file comstack.h.
Referenced by tcpip_bind(), and tcpip_rcvconnect().
| #define CSLASTERROR CSPROTERR |
Highest COMSTACK error code; keep equal to the last error.
Definition at line 557 of file comstack.h.
Referenced by cs_errmsg().
| #define CSNODATA 3 |
No incoming connection is available yet.
Definition at line 545 of file comstack.h.
Referenced by tcpip_listen(), and unix_listen().
| #define CSNONE 0 |
No error, or an unspecified error.
Definition at line 539 of file comstack.h.
Referenced by cs_errmsg().
| #define CSOUTSTATE 2 |
Operation is invalid for this state or transport.
Definition at line 543 of file comstack.h.
Referenced by cs_set_head_only(), tcpip_accept(), tcpip_connect(), tcpip_listen(), tcpip_rcvconnect(), unix_accept(), unix_connect(), unix_listen(), unix_rcvconnect(), yaz_tcpip_set_head_only(), and yaz_unix_set_head_only().
| #define CSPROTERR 8 |
Malformed protocol data.
Definition at line 555 of file comstack.h.
Referenced by do_read(), ir_read(), tcpip_get(), tcpip_rcvconnect(), and unix_get().
| #define CSWRONGBUF 4 |
A pending write was retried with a different buffer or size.
Definition at line 547 of file comstack.h.
Referenced by tcpip_put(), and unix_put().
| #define CSYSERR 1 |
System call failed; consult the platform error information.
Definition at line 541 of file comstack.h.
Referenced by add_listener(), cont_connect(), create_net_socket(), tcpip_accept(), tcpip_addrstr(), tcpip_bind(), tcpip_get(), tcpip_listen(), tcpip_put(), unix_accept(), unix_bind(), unix_connect(), unix_get(), unix_listen(), and unix_put().
Communication endpoint; release with cs_close.
Definition at line 48 of file comstack.h.
| typedef COMSTACK(*) CS_TYPE(int s, int flags, int protocol, void *vp) |
Transport constructor and transport identity.
| s | existing socket, or -1 to create a new endpoint |
| flags | combination of CS_FLAGS_* bits |
| protocol | application protocol (enum oid_proto) |
| vp | transport-specific initialization data, or NULL |
Definition at line 56 of file comstack.h.
| int cs_complete_auto | ( | const char * | buf, |
| int | len ) |
Finds the length of a complete BER or HTTP message.
| buf | input bytes |
| len | number of available bytes |
Examines the first message only; does not modify the input.
Definition at line 514 of file comstack.c.
References cs_complete_auto(), and cs_complete_auto_x().
Referenced by cs_complete_auto(), tcpip_rcvconnect(), tcpip_state_create(), unix_type(), yaz_tcpip_set_head_only(), and yaz_unix_set_head_only().
| int cs_complete_auto_head | ( | const char * | buf, |
| int | len ) |
Finds the length of a BER message or HTTP headers.
| buf | input bytes |
| len | number of available bytes |
Examines the first message only; does not modify the input.
Definition at line 519 of file comstack.c.
References cs_complete_auto_head(), and cs_complete_auto_x().
Referenced by cs_complete_auto_head(), tcpip_rcvconnect(), yaz_tcpip_set_head_only(), and yaz_unix_set_head_only().
| COMSTACK cs_create_host | ( | const char * | type_and_host, |
| int | flags, | ||
| void ** | vp ) |
Creates an endpoint from a host or URI specification.
| type_and_host | host or URI; see cs_create_host2 for syntax |
| flags | combination of CS_FLAGS_* bits; zero for nonblocking I/O |
| vp | required address output pointer; owned by the returned COMSTACK |
Equivalent to cs_create_host2 with no proxy_host and with the proxy mode output discarded. This creates an endpoint but does not connect it. Pass the address of a void * variable as vp, then use *vp with cs_connect or cs_bind. Do not free *vp; cs_straddr may replace it and cs_close releases it. Do not use *vp on failure. Close the endpoint with cs_close.
Definition at line 177 of file comstack.c.
References cs_create_host(), and cs_create_host_proxy().
Referenced by add_listener(), and cs_create_host().
| COMSTACK cs_create_host2 | ( | const char * | vhost, |
| int | flags, | ||
| void ** | vp, | ||
| const char * | proxy_host, | ||
| int * | proxy_mode ) |
Creates an endpoint and selects direct or proxy connection handling.
| vhost | target host or URI specification (required) |
| flags | combination of CS_FLAGS_* bits; zero for nonblocking I/O |
| vp | required address output pointer; owned by the returned COMSTACK |
| proxy_host | proxy host or URI, or NULL for no separate proxy |
| proxy_mode | required output pointer: 0 for direct/CONNECT, 1 for application-level proxying; only use this value on success |
Supported case-sensitive target forms are:
Bracket IPv6 addresses, for example tcp:[::1]:210. Only HTTP/HTTPS prefixes strip leading slashes; tcp://host is not the TCP syntax. Network address resolution ignores suffixes starting with / or ?; the application interprets paths, queries, and database names. These specifications are not percent-decoded. Direct URI user information and fragments are not interpreted. TLS requires GnuTLS support, and UNIX sockets are unavailable on Windows. UNIX addresses also accept file=path,user=name-or-id,group=name-or-id,umask=mode, with file required and the other keys optional. The octal umask value sets socket permissions directly when binding; it is not a mask to subtract.
A local source address may follow the first space in vhost for TCP/IP or TLS. Put a path slash before the space, for example "tcp:server.example:210/ 192.0.2.10", so resolution excludes the suffix. The source port is forced to zero; for an IPv6 source include a port placeholder, for example "http://[::1]/ [::1]:0".
A separate proxy_host must select TCP/IP, not TLS or UNIX sockets, and must not contain another proxy specification. TLS targets always use CONNECT. A Z39.50 target with an HTTP proxy also uses CONNECT. Other TCP/IP target/proxy combinations use application-level proxying. In that case *proxy_mode is 1 and the caller must supply the proxy protocol messages (for example absolute HTTP request URIs). With CONNECT, proxy_mode is 0 and cs_connect/cs_rcvconnect perform the tunnel handshake. Explicit connect: and unix:path:target forms override proxy_host.
Specify both proxy and target ports explicitly for CONNECT: the target authority is sent without adding a default port, and an omitted proxy port defaults according to the target transport/protocol. Credentials before @ generate a Basic Proxy-Authorization header for CONNECT only; they may also appear in proxy_host when CONNECT is selected.
This function does not establish a connection. On success, pass *vp to cs_connect or cs_bind and eventually release the endpoint with cs_close. Do not free *vp; cs_straddr may replace it. Do not use *vp on failure. With CS_FLAGS_DNS_NO_BLOCK and resolver thread support, resolution errors may be reported later during connection establishment.
Definition at line 189 of file comstack.c.
References cs_close, cs_create, cs_create_host2(), cs_parse_host(), cs_straddr, PROTO_HTTP, PROTO_Z3950, ssl_type(), tcpip_type(), xfree, xstrdup, yaz_ssl_create(), and yaz_tcpip_create3().
Referenced by cs_create_host2(), cs_create_host_proxy(), do_connect_host(), and yaz_url_exec().
| COMSTACK cs_create_host_proxy | ( | const char * | vhost, |
| int | flags, | ||
| void ** | vp, | ||
| const char * | proxy_host ) |
Creates an endpoint with an optional proxy.
| vhost | target host or URI; see cs_create_host2 for syntax |
| flags | combination of CS_FLAGS_* bits; zero for nonblocking I/O |
| vp | required address output pointer; owned by the returned COMSTACK |
| proxy_host | proxy host or URI, or NULL for no separate proxy |
Equivalent to cs_create_host2 with the proxy mode output discarded. Address ownership and connection handling are as for cs_create_host.
Definition at line 182 of file comstack.c.
References cs_create_host2(), and cs_create_host_proxy().
Referenced by cs_create_host(), and cs_create_host_proxy().
| const char * cs_errmsg | ( | int | n | ) |
Returns a static message for a COMSTACK error code.
| n | error code (CSNONE through CSLASTERROR) |
Definition at line 39 of file comstack.c.
References cs_errlist, cs_errmsg(), CSLASTERROR, and CSNONE.
Referenced by add_comstack_details(), cs_errmsg(), cs_strerror(), do_read(), ir_read(), and log_comstack_error().
| int cs_get_error | ( | COMSTACK | cs, |
| const char ** | details ) |
Returns the last COMSTACK error and optional transport details.
| cs | endpoint |
| details | optional output pointer; set to borrowed text or NULL |
Details are currently available for TCP/IP and TLS. Do not free the text; it can be overwritten by a later error and is released by cs_close.
Definition at line 51 of file comstack.c.
References comstack::cerrno, cs_get_error(), and yaz_tcpip_get_error_details().
Referenced by add_comstack_details(), cs_get_error(), and log_comstack_error().
| void cs_get_host_args | ( | const char * | type_and_host, |
| const char ** | args ) |
Extracts application arguments from a host or URI specification.
| type_and_host | host or URI specification (required) |
| args | required output pointer to borrowed arguments, or an empty string |
Returns the portion after the first path slash, skipping a :// separator. For unix:path:args, returns args directly if that part contains no colon; otherwise extracts the target path. For example tcp:localhost:210/books yields books, and http://localhost/sru?version=1.2 yields sru?version=1.2. No decoding is performed. Do not free *args; a nonempty result points into type_and_host and is valid only while that input remains valid.
Definition at line 58 of file comstack.c.
References cs_get_host_args().
Referenced by cs_get_host_args(), yaz_check_location(), and ZOOM_connection_get_databases().
| int cs_get_peer_certificate_x509 | ( | COMSTACK | cs, |
| char ** | buf, | ||
| int * | len ) |
Gets a human-readable description of the first peer X.509 certificate.
| cs | endpoint with an established TLS session |
| buf | required output pointer to allocated, NUL-terminated text |
| len | required output pointer to text length, excluding the terminator |
Requires GnuTLS certificate printing support. Free *buf with xfree after success. The result is descriptive text, not a PEM-encoded certificate.
Definition at line 1733 of file tcpip.c.
References tcpip_state::buf, comstack::cprivate, cs_get_peer_certificate_x509(), ssl_type(), comstack::type, and xstrdup.
Referenced by cs_get_peer_certificate_x509(), and get_cert().
| void * cs_get_ssl | ( | COMSTACK | cs | ) |
Legacy OpenSSL session accessor.
| cs | endpoint |
Definition at line 1680 of file tcpip.c.
References cs_get_ssl().
Referenced by cs_get_ssl().
| int cs_look | ( | COMSTACK | cs | ) |
Returns the last recorded event (CS_NONE, CS_CONNECT, etc.).
The argument is the endpoint. This function does not poll for new events.
Definition at line 280 of file comstack.c.
References cs_look(), and comstack::event.
Referenced by cs_look(), and ZOOM_connection_do_io().
| int cs_parse_host | ( | const char * | uri, |
| const char ** | host, | ||
| CS_TYPE * | t, | ||
| enum oid_proto * | proto, | ||
| char ** | connect_host ) |
Parses transport and protocol prefixes without resolving an address.
| uri | host or URI specification (required); see cs_create_host2 |
| host | required output pointer into uri after recognized prefixes |
| t | required transport output pointer |
| proto | required protocol output pointer: PROTO_Z3950 or PROTO_HTTP |
| connect_host | required output pointer to an allocated proxy/socket address, or NULL when no such address is specified |
Recognizes connect: and unix: wrappers followed by tcp:, ssl:, http:, or https:. With no recognized protocol prefix, selects Z39.50. The default transport is TCP/IP. This function only parses prefixes; success does not imply that the address is valid or resolvable. On success, free a non-NULL *connect_host with xfree. Do not free *host; it is valid only while uri remains valid. On failure, *connect_host is NULL and the other outputs must not be used.
Definition at line 86 of file comstack.c.
References cs_parse_host(), PROTO_HTTP, PROTO_Z3950, ssl_type(), tcpip_type(), unix_type(), xfree, and xmalloc.
Referenced by cs_create_host2(), and cs_parse_host().
| void cs_print_session_info | ( | COMSTACK | cs | ) |
Prints TLS peer certificate information to standard output.
| cs | endpoint |
Does nothing for other transports or when no TLS session is available.
Definition at line 1638 of file tcpip.c.
References comstack::cprivate, cs_print_session_info(), ssl_type(), and comstack::type.
Referenced by cs_print_session_info().
| int cs_set_head_only | ( | COMSTACK | cs, |
| int | head_only ) |
Selects HTTP header-only framing for TCP/IP, SSL or UNIX transports.
| cs | COMSTACK handle |
| head_only | nonzero to stop at the end of HTTP headers; zero to restore normal message framing |
Definition at line 524 of file comstack.c.
References comstack::cerrno, cs_set_head_only(), CSOUTSTATE, ssl_type(), tcpip_type(), comstack::type, unix_type(), yaz_tcpip_set_head_only(), and yaz_unix_set_head_only().
Referenced by cs_set_head_only(), and yaz_url_exec().
| void cs_set_max_recv_bytes | ( | COMSTACK | cs, |
| int | max_recv_bytes ) |
Sets the maximum incoming message size.
| cs | endpoint |
| max_recv_bytes | receive limit in bytes (default 16777216) |
Oversized input is reported as CSBUFSIZE by cs_get.
Definition at line 536 of file comstack.c.
References cs_set_max_recv_bytes(), and comstack::max_recv_bytes.
Referenced by control_association(), and cs_set_max_recv_bytes().
| int cs_set_ssl_certificate_file | ( | COMSTACK | cs, |
| const char * | fname ) |
Selects certificate and private key files for a TLS endpoint.
| cs | endpoint, or NULL |
| fname | filename containing both certificate and key, or "certificate-file,key-file"; NULL or empty disables the default file |
Call before binding or connecting. Filenames are copied; success does not mean the files have been loaded or validated. This overrides the default server certificate filename yaz.pem.
Definition at line 1698 of file tcpip.c.
References comstack::cprivate, cs_set_ssl_certificate_file(), ssl_type(), and comstack::type.
Referenced by add_listener(), cs_set_ssl_certificate_file(), do_connect_host(), and yaz_url_exec().
| int cs_set_ssl_ctx | ( | COMSTACK | cs, |
| void * | ctx ) |
Legacy OpenSSL context setter.
| cs | endpoint, or NULL |
| ctx | ignored legacy context pointer |
Definition at line 1686 of file tcpip.c.
References cs_set_ssl_ctx(), ssl_type(), and comstack::type.
Referenced by cs_set_ssl_ctx().
| const char * cs_strerror | ( | COMSTACK | h | ) |
Returns a static message for the endpoint's last error.
| h | endpoint |
Definition at line 46 of file comstack.c.
References comstack::cerrno, cs_errmsg(), and cs_strerror().
Referenced by cs_strerror().