clsync
Loading...
Searching...
No Matches
socket.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "configuration.h"
#include "error.h"
#include "malloc.h"
#include "program.h"
#include "socket.h"
Include dependency graph for socket.c:

Go to the source code of this file.

Macros

#define PREBUF0_SIZE   ((SOCKET_BUFSIZ >> 1) - 128)
 
#define PREBUF1_SIZE   (SOCKET_BUFSIZ >> 1)
 
#define PARSE_TEXT_DATA_SSCANF(dat_t, ...)
 

Functions

int socket_gc ()
 
int socket_check_bysock (int sock)
 
static int socket_check (clsyncsock_t *clsyncsock_p)
 
clsyncsock_tsocket_new (int clsyncsock_sock)
 
int socket_cleanup (clsyncsock_t *clsyncsock_p)
 
int socket_close (clsyncsock_t *clsyncsock_p)
 
int socket_thread_delete (socket_sockthreaddata_t *threaddata_p)
 
clsyncsock_tsocket_accept (int sock)
 
clsyncsock_tsocket_listen_unix (const char *const socket_path)
 
int _socket_send (clsyncsock_t *clsyncsock, uint64_t *cmd_num_p, sockcmd_id_t cmd_id, va_list ap)
 
int socket_reply (clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p, sockcmd_id_t cmd_id,...)
 
int socket_send (clsyncsock_t *clsyncsock_p, sockcmd_id_t cmd_id,...)
 
int socket_send_cb (clsyncsock_t *clsyncsock_p, sockcmd_id_t cmd_id, clsyncsock_cb_funct_t cb, void *cb_arg,...)
 
static int socket_overflow_fix (char *buf, char **data_start_p, char **data_end_p)
 
static int parse_text_data (sockcmd_t *sockcmd_p, char *args, size_t args_len)
 
int socket_recv (clsyncsock_t *clsyncsock, sockcmd_t *sockcmd_p)
 
int socket_sendinvalid (clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p)
 
int socket_procclsyncsock (socket_sockthreaddata_t *arg)
 
socket_sockthreaddata_tsocket_thread_new ()
 
socket_sockthreaddata_tsocket_thread_attach (clsyncsock_t *clsyncsock_p)
 
int socket_thread_start (socket_sockthreaddata_t *threaddata_p)
 
int socket_init ()
 
int socket_deinit ()
 

Variables

pthread_mutex_t socket_thread_mutex = PTHREAD_MUTEX_INITIALIZER
 
int clsyncsockthreads_last = -1
 
int clsyncsockthreads_count = 0
 
int clsyncsockthreads_num = 0
 
char clsyncsockthread_busy [8+1] = {0}
 
socket_sockthreaddata_t sockthreaddata [8+1] = {{0}}
 
static char * recv_stps [8]
 
static char * recv_ptrs [8]
 
const char *const textmessage_args [SOCKCMD_MAXID]
 
const char *const textmessage_descr [SOCKCMD_MAXID]
 

Macro Definition Documentation

◆ PARSE_TEXT_DATA_SSCANF

#define PARSE_TEXT_DATA_SSCANF ( dat_t,
... )
Value:
{\
sockcmd_p->data = xmalloc(sizeof(dat_t));\
dat_t *d = (dat_t *)sockcmd_p->data;\
if (sscanf(args, textmessage_args[sockcmd_p->cmd_id], __VA_ARGS__) < min_args)\
return EINVAL;\
}
const char *const textmessage_args[SOCKCMD_MAXID]
Definition socket.c:72

Definition at line 409 of file socket.c.

◆ PREBUF0_SIZE

#define PREBUF0_SIZE   ((SOCKET_BUFSIZ >> 1) - 128)

◆ PREBUF1_SIZE

#define PREBUF1_SIZE   (SOCKET_BUFSIZ >> 1)

Function Documentation

◆ _socket_send()

int _socket_send ( clsyncsock_t * clsyncsock,
uint64_t * cmd_num_p,
sockcmd_id_t cmd_id,
va_list ap )

Definition at line 270 of file socket.c.

Here is the caller graph for this function:

◆ parse_text_data()

static int parse_text_data ( sockcmd_t * sockcmd_p,
char * args,
size_t args_len )
inlinestatic

Definition at line 416 of file socket.c.

Here is the caller graph for this function:

◆ socket_accept()

clsyncsock_t * socket_accept ( int sock)

Definition at line 177 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_check()

static int socket_check ( clsyncsock_t * clsyncsock_p)
inlinestatic

Definition at line 125 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_check_bysock()

int socket_check_bysock ( int sock)

Definition at line 108 of file socket.c.

Here is the caller graph for this function:

◆ socket_cleanup()

int socket_cleanup ( clsyncsock_t * clsyncsock_p)

Definition at line 140 of file socket.c.

Here is the caller graph for this function:

◆ socket_close()

int socket_close ( clsyncsock_t * clsyncsock_p)

Definition at line 150 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_deinit()

int socket_deinit ( )

Definition at line 823 of file socket.c.

Here is the caller graph for this function:

◆ socket_gc()

int socket_gc ( )

Definition at line 47 of file socket.c.

Here is the caller graph for this function:

◆ socket_init()

int socket_init ( )

Definition at line 818 of file socket.c.

Here is the caller graph for this function:

◆ socket_listen_unix()

clsyncsock_t * socket_listen_unix ( const char *const socket_path)

Definition at line 192 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_new()

clsyncsock_t * socket_new ( int clsyncsock_sock)

Definition at line 130 of file socket.c.

Here is the caller graph for this function:

◆ socket_overflow_fix()

static int socket_overflow_fix ( char * buf,
char ** data_start_p,
char ** data_end_p )
inlinestatic

Definition at line 387 of file socket.c.

Here is the caller graph for this function:

◆ socket_procclsyncsock()

int socket_procclsyncsock ( socket_sockthreaddata_t * arg)

Definition at line 629 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_recv()

int socket_recv ( clsyncsock_t * clsyncsock,
sockcmd_t * sockcmd_p )

Definition at line 501 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_reply()

int socket_reply ( clsyncsock_t * clsyncsock_p,
sockcmd_t * sockcmd_p,
sockcmd_id_t cmd_id,
... )

Definition at line 331 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_send()

int socket_send ( clsyncsock_t * clsyncsock_p,
sockcmd_id_t cmd_id,
... )

Definition at line 342 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_send_cb()

int socket_send_cb ( clsyncsock_t * clsyncsock_p,
sockcmd_id_t cmd_id,
clsyncsock_cb_funct_t cb,
void * cb_arg,
... )

Definition at line 352 of file socket.c.

Here is the call graph for this function:

◆ socket_sendinvalid()

int socket_sendinvalid ( clsyncsock_t * clsyncsock_p,
sockcmd_t * sockcmd_p )

Definition at line 621 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_thread_attach()

socket_sockthreaddata_t * socket_thread_attach ( clsyncsock_t * clsyncsock_p)

Definition at line 797 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_thread_delete()

int socket_thread_delete ( socket_sockthreaddata_t * threaddata_p)

Definition at line 156 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_thread_new()

socket_sockthreaddata_t * socket_thread_new ( )

Definition at line 758 of file socket.c.

Here is the caller graph for this function:

◆ socket_thread_start()

int socket_thread_start ( socket_sockthreaddata_t * threaddata_p)

Definition at line 808 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ clsyncsockthread_busy

char clsyncsockthread_busy[8+1] = {0}

Definition at line 43 of file socket.c.

◆ clsyncsockthreads_count

int clsyncsockthreads_count = 0

Definition at line 40 of file socket.c.

◆ clsyncsockthreads_last

int clsyncsockthreads_last = -1

Definition at line 39 of file socket.c.

◆ clsyncsockthreads_num

int clsyncsockthreads_num = 0

Definition at line 41 of file socket.c.

◆ recv_ptrs

char* recv_ptrs[8]
static

Definition at line 70 of file socket.c.

◆ recv_stps

char* recv_stps[8]
static

Definition at line 69 of file socket.c.

◆ socket_thread_mutex

pthread_mutex_t socket_thread_mutex = PTHREAD_MUTEX_INITIALIZER

Definition at line 37 of file socket.c.

◆ sockthreaddata

socket_sockthreaddata_t sockthreaddata[8+1] = {{0}}

Definition at line 45 of file socket.c.

◆ textmessage_args

const char* const textmessage_args[SOCKCMD_MAXID]
Initial value:
= {
[SOCKCMD_REQUEST_SET] = "%s\003/ %s\003/",
[SOCKCMD_REPLY_ACK] = "%u %lu",
[SOCKCMD_REPLY_EINVAL] = "%u %lu",
[SOCKCMD_REPLY_VERSION] = "%u %u %s",
[SOCKCMD_REPLY_INFO] = "%s\003/ %s\003/ %x %x",
[SOCKCMD_REPLY_EEXIST] = "%s\003/",
[SOCKCMD_REPLY_EPERM] = "%s\003/",
[SOCKCMD_REPLY_ECUSTOM] = "%s\003/ %s\003/ %u %s\003/",
}
@ SOCKCMD_REPLY_EPERM
Definition socket.h:108
@ SOCKCMD_REPLY_NEGOTIATION
Definition socket.h:102
@ SOCKCMD_REPLY_VERSION
Definition socket.h:117
@ SOCKCMD_REPLY_INFO
Definition socket.h:118
@ SOCKCMD_REPLY_ECUSTOM
Definition socket.h:109
@ SOCKCMD_REQUEST_SET
Definition socket.h:114
@ SOCKCMD_REPLY_UNKNOWNCMD
Definition socket.h:104
@ SOCKCMD_REQUEST_NEGOTIATION
Definition socket.h:101
@ SOCKCMD_REPLY_ACK
Definition socket.h:103
@ SOCKCMD_REPLY_EINVAL
Definition socket.h:106
@ SOCKCMD_REPLY_EEXIST
Definition socket.h:107
@ SOCKCMD_REPLY_INVALIDCMDID
Definition socket.h:105
@ SOCKCMD_REQUEST_DUMP
Definition socket.h:112

Definition at line 72 of file socket.c.

◆ textmessage_descr

const char* const textmessage_descr[SOCKCMD_MAXID]
Initial value:
= {
[SOCKCMD_REQUEST_NEGOTIATION] = "Protocol version is %u.",
[SOCKCMD_REPLY_NEGOTIATION] = "Protocol version is %u.",
[SOCKCMD_REPLY_ACK] = "Acknowledged command: id == %u; num == %lu.",
[SOCKCMD_REPLY_EINVAL] = "Rejected command: id == %u; num == %lu. Invalid arguments: %s.",
[SOCKCMD_REPLY_LOGIN] = "Enter your login and password, please.",
[SOCKCMD_REPLY_UNEXPECTEDEND] = "Need to go, sorry. :)",
[SOCKCMD_REPLY_DIE] = "Okay :(",
[SOCKCMD_REPLY_BYE] = "Bye.",
[SOCKCMD_REPLY_VERSION] = "clsync v%u.%u%s",
[SOCKCMD_REPLY_INFO] = "config_block == \"%s\"; label == \"%s\"; flags == %x; flags_set == %x.",
[SOCKCMD_REPLY_SET] = "Set",
[SOCKCMD_REPLY_DUMP] = "Ready",
[SOCKCMD_REPLY_UNKNOWNCMD] = "Unknown command.",
[SOCKCMD_REPLY_INVALIDCMDID] = "Invalid command id. Required: 0 <= cmd_id < 1000.",
[SOCKCMD_REPLY_EEXIST] = "File exists: \"%s\".",
[SOCKCMD_REPLY_EPERM] = "Permission denied: \"%s\".",
[SOCKCMD_REPLY_ECUSTOM] = "%s(%s): Error #%u: \"%s\".",
}
@ SOCKCMD_REPLY_UNEXPECTEDEND
Definition socket.h:124
@ SOCKCMD_REPLY_LOGIN
Definition socket.h:120
@ SOCKCMD_REPLY_SET
Definition socket.h:121
@ SOCKCMD_REPLY_DUMP
Definition socket.h:119
@ SOCKCMD_REPLY_DIE
Definition socket.h:122
@ SOCKCMD_REPLY_BYE
Definition socket.h:123

Definition at line 88 of file socket.c.