Internal header file for Server Wait on Client common library.
More...
#include <netdb.h>
#include <sys/types.h>
#include <libmgec/mge-message.h>
#include <libmgec/mge-portability.h>
Go to the source code of this file.
|
enum | msg_source { swocclient
, swocserver
, swocserverd
, src_err
} |
| enum identifying the source of a message. More...
|
|
enum | msg_request {
swocallow
, swocblock
, swocblocklist
, swocblockstatus
,
swocdisallow
, swocend
, swocid
, swoclock
,
swocrelease
, swocreload
, swocreset
, swocstatus
,
swocunblock
, req_err
} |
| enum identifying the message request. More...
|
|
enum | msg_arguments { args_ok
, args_err
} |
| enum specifying error status of arguments. More...
|
|
enum | comms_mode { recv_mode
, send_mode
} |
| enum indentify send or receive mode. More...
|
|
|
int | swcom_validate_config (void) |
| Parse and validate the config file. More...
|
|
int | prep_recv_sock (int *sockfd, int *portno) |
| Prepare TCP socket to receive connections. More...
|
|
int | init_conn (int *sockfd, int *portno, char *srv) |
| Initiate TCP stream socket connection. More...
|
|
int | est_connect (int *sfd, char *serv, int *portno, struct addrinfo *hints, enum comms_mode *mode) |
| Establish send or receive connection. More...
|
|
int | listen_sock (const int *sfd) |
| Set TCP socket to listen. More...
|
|
int | close_sock (const int *sockfd) |
| Close TCP socket. More...
|
|
void | parse_msg (struct mgemessage *msg, enum msg_arguments *msg_args, enum msg_source *msg_src, enum msg_request *msg_req) |
| Parse a message. More...
|
|
int | send_outgoing_msg (char *outgoing_msg, size_t outgoing_msg_length, int *newsockfd) |
| Send a message. More...
|
|
int | exch_msg (char *outgoing_msg, size_t om_length, struct mgemessage *msg) |
| Exchange messages. More...
|
|
int | open_ssh_tunnel (void) |
| Establish SSH connection. More...
|
|
int | close_ssh_tunnel (void) |
| Disconnect and close an SSH session. More...
|
|
char * | libswoccommon_get_pkg_version (void) |
| Get the git-describe based package version. More...
|
|
char * | libswoccommon_get_src_version (void) |
| Get the source version. More...
|
|
void | libswoccommon_print_pkg_version (void) |
| Print the package version string to stdout. More...
|
|
void | libswoccommon_print_src_version (void) |
| Print the source version string to stdout. More...
|
|
Internal header file for Server Wait on Client common library.
- Author
- Copyright (C) 2017-2022 Mark Grant
Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only
- Version
- v1.1.3 ==== 17/09/2022
◆ SOCK_BUF_SIZE
#define SOCK_BUF_SIZE 256 |
◆ SOCK_Q_LEN
Queue length for listen backlog.
◆ SSH_CHAN_POLL_TIMEOUT
#define SSH_CHAN_POLL_TIMEOUT 10000 |
Timeout for SSH channel read (in ms).
◆ comms_mode
enum indentify send or receive mode.
Enumerator |
---|
recv_mode | |
send_mode | |
◆ msg_arguments
enum specifying error status of arguments.
Enumerator |
---|
args_ok | |
args_err | |
◆ msg_request
enum identifying the message request.
Enumerator |
---|
swocallow | |
swocblock | |
swocblocklist | |
swocblockstatus | |
swocdisallow | |
swocend | |
swocid | |
swoclock | |
swocrelease | |
swocreload | |
swocreset | |
swocstatus | |
swocunblock | |
req_err | |
◆ msg_source
enum identifying the source of a message.
Enumerator |
---|
swocclient | |
swocserver | |
swocserverd | |
src_err | |
◆ close_sock()
int close_sock |
( |
const int * |
sockfd | ) |
|
Close TCP socket.
Equivalent to close() with error handling. On error mge_errno is set.
- Parameters
-
sockfd | The socket file descriptor. |
- Returns
- 0 on success, < zero on failure.
◆ close_ssh_tunnel()
int close_ssh_tunnel |
( |
void |
| ) |
|
Disconnect and close an SSH session.
Join data relay thread, free channel and disconnect session. On error mge_errno will be set.
- Returns
- 0 on success, < zero on failure.
◆ est_connect()
int est_connect |
( |
int * |
sfd, |
|
|
char * |
serv, |
|
|
int * |
portno, |
|
|
struct addrinfo * |
hints, |
|
|
enum comms_mode * |
mode |
|
) |
| |
Establish send or receive connection.
Bind or connect depending on mode - listen or send. On error mge_errno is set.
- Parameters
-
sfd | The socket file descriptor. |
serv | The server name. |
portno | The port number. |
hints | The hints for getaddrinfo(). |
mode | send_mode or recv_mode. |
- Returns
- 0 on success, < zero on failure.
◆ exch_msg()
int exch_msg |
( |
char * |
outgoing_msg, |
|
|
size_t |
om_length, |
|
|
struct mgemessage * |
msg |
|
) |
| |
Exchange messages.
Send and receive 1 requested message after sending ID message. On error mge_errno will be set.
- Parameters
-
outgoing_msg | The message to send. |
om_length | The length of the outgoing message. |
msg | The received message. |
- Returns
- 0 on success, < zero on error.
◆ init_conn()
int init_conn |
( |
int * |
sockfd, |
|
|
int * |
portno, |
|
|
char * |
srv |
|
) |
| |
Initiate TCP stream socket connection.
On error mge_errno is set.
- Parameters
-
sockfd | The socket file descriptor. |
portno | The port number. |
srv | The server name. |
- Returns
- 0 on success, < zero on failure.
◆ libswoccommon_get_pkg_version()
char* libswoccommon_get_pkg_version |
( |
void |
| ) |
|
Get the git-describe based package version.
- Returns
- The package version string.
◆ libswoccommon_get_src_version()
char* libswoccommon_get_src_version |
( |
void |
| ) |
|
Get the source version.
- Returns
- The source version string.
◆ libswoccommon_print_pkg_version()
void libswoccommon_print_pkg_version |
( |
void |
| ) |
|
Print the package version string to stdout.
◆ libswoccommon_print_src_version()
void libswoccommon_print_src_version |
( |
void |
| ) |
|
Print the source version string to stdout.
◆ listen_sock()
int listen_sock |
( |
const int * |
sfd | ) |
|
Set TCP socket to listen.
Equivalent to listen() with error handling. A race is possible with other swoc invocations to listen on that socket, so if it is in use do a few retries. On error mge_errno is set.
- Parameters
-
sfd | The socket file descriptor. |
- Returns
- 0 on success, < zero on failure.
◆ open_ssh_tunnel()
int open_ssh_tunnel |
( |
void |
| ) |
|
Establish SSH connection.
Create session, connect to server, create a tunnel and spawn a thread to relay data through the tunnel. On error mge_errno will be set.
- Returns
- 0 on success, < zero on error.
◆ parse_msg()
Parse a message.
Identify message source and request.
- Parameters
-
msg | The message to process. |
msg_args | The arguments to the message. |
msg_src | The source of the message. |
msg_req | The request contained in the message. |
◆ prep_recv_sock()
int prep_recv_sock |
( |
int * |
sockfd, |
|
|
int * |
portno |
|
) |
| |
Prepare TCP socket to receive connections.
On error mge_errno is set.
- Parameters
-
sockfd | The socket file descriptor. |
portno | The port number. |
- Returns
- 0 on success, < zero on failure.
◆ send_outgoing_msg()
int send_outgoing_msg |
( |
char * |
outgoing_msg, |
|
|
size_t |
outgoing_msg_length, |
|
|
int * |
newsockfd |
|
) |
| |
Send a message.
On error mge_errno will be set.
- Parameters
-
outgoing_msg | The message to send. |
outgoing_msg_length | The length of the message. |
newsockfd | The socket file descriptor. |
- Returns
- 0 on success, < zero on error.
◆ swcom_validate_config()
int swcom_validate_config |
( |
void |
| ) |
|
Parse and validate the config file.
On error mge_errno is set.
- Returns
- 0 on success, < zero on failure.
◆ pollint
BEGIN_C_DECLS int pollint |
|
extern |
◆ server
◆ srvportno
◆ ssh
Use SSH false == 0, true == 1.
◆ sshportno
Local port to use if using SSH.
◆ sshuser