Server Wait On Clients System - API Documentation  v1.6.4
Server Wait On Clients System.
libswoccommon.h File Reference

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>
Include dependency graph for libswoccommon.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SOCK_BUF_SIZE   256
 Socket buffer size. More...
 
#define SOCK_Q_LEN   10
 Queue length for listen backlog. More...
 
#define SSH_CHAN_POLL_TIMEOUT   10000
 Timeout for SSH channel read (in ms). More...
 

Enumerations

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...
 

Functions

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...
 

Variables

BEGIN_C_DECLS int pollint
 Polling interval. More...
 
int ssh
 Use SSH false == 0, true == 1. More...
 
char server []
 Server name. More...
 
int srvportno
 Server port number. More...
 
int sshportno
 Local port to use if using SSH. More...
 
char sshuser []
 Server username for SSH. More...
 

Detailed Description

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

Macro Definition Documentation

◆ SOCK_BUF_SIZE

#define SOCK_BUF_SIZE   256

Socket buffer size.

◆ SOCK_Q_LEN

#define SOCK_Q_LEN   10

Queue length for listen backlog.

◆ SSH_CHAN_POLL_TIMEOUT

#define SSH_CHAN_POLL_TIMEOUT   10000

Timeout for SSH channel read (in ms).

Enumeration Type Documentation

◆ comms_mode

enum 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 msg_source

enum identifying the source of a message.

Enumerator
swocclient 
swocserver 
swocserverd 
src_err 

Function Documentation

◆ close_sock()

int close_sock ( const int *  sockfd)

Close TCP socket.

Equivalent to close() with error handling. On error mge_errno is set.

Parameters
sockfdThe 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
sfdThe socket file descriptor.
servThe server name.
portnoThe port number.
hintsThe hints for getaddrinfo().
modesend_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_msgThe message to send.
om_lengthThe length of the outgoing message.
msgThe 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
sockfdThe socket file descriptor.
portnoThe port number.
srvThe 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
sfdThe 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()

void parse_msg ( struct mgemessage *  msg,
enum msg_arguments msg_args,
enum msg_source msg_src,
enum msg_request msg_req 
)

Parse a message.

Identify message source and request.

Parameters
msgThe message to process.
msg_argsThe arguments to the message.
msg_srcThe source of the message.
msg_reqThe 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
sockfdThe socket file descriptor.
portnoThe 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_msgThe message to send.
outgoing_msg_lengthThe length of the message.
newsockfdThe 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.

Variable Documentation

◆ pollint

BEGIN_C_DECLS int pollint
extern

Polling interval.

◆ server

char server[]
extern

Server name.

◆ srvportno

int srvportno
extern

Server port number.

◆ ssh

int ssh
extern

Use SSH false == 0, true == 1.

◆ sshportno

int sshportno
extern

Local port to use if using SSH.

◆ sshuser

char sshuser[]
extern

Server username for SSH.