clsync
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1/*
2 clsync - file tree sync utility based on inotify
3
4 Copyright (C) 2013 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __CLSYNC_SOCKET_H
21#define __CLSYNC_SOCKET_H
22
23#ifdef __linux__
24#include <linux/limits.h>
25#endif
26
27#include <pthread.h>
28#include <stdint.h>
29
30#include "port-hacks.h"
31#include "clsync.h"
32#include "ctx.h"
33
34#define SOCKET_DEFAULT_PROT 0
35#define SOCKET_DEFAULT_SUBPROT SUBPROT0_TEXT
36
37// buffer size
38#define SOCKET_BUFSIZ (1<<12)
39
40#if PIC
41# define SOCKET_PROVIDER_LIBCLSYNC
42#else
43# define SOCKET_PROVIDER_CLSYNC
44#endif
45
46#ifdef SOCKET_PROVIDER_LIBCLSYNC
47# define SOCKET_MAX SOCKET_MAX_LIBCLSYNC
48#endif
49#ifdef SOCKET_PROVIDER_CLSYNC
50# define SOCKET_MAX SOCKET_MAX_CLSYNC
51#endif
52
54struct sockcmd;
55
56typedef int ( *clsyncsock_cb_funct_t ) ( struct socket_sockthreaddata *thread, struct sockcmd *sockcmd_p, void *arg );
64
65struct clsyncsock {
66 int sock;
67 uint16_t prot;
68 uint16_t subprot;
69
70 uint64_t cmd_num;
71
74 clsynccbqueue_t *cbqueue_cache[4 * CLSYNCSOCK_WINDOW + 1]; // It's a hacky hash-table of size "CLSYNCSOCK_WINDOW*2"
75};
76typedef struct clsyncsock clsyncsock_t;
77
84
89typedef enum subprot0 subprot0_t;
90
99
128
130 uint16_t prot;
131 uint16_t subprot;
132};
134
136 uint64_t cmd_num;
137 uint16_t cmd_id;
138};
140#define sockcmd_dat_einval sockcmd_dat_ack
141#define sockcmd_dat_einval_t sockcmd_dat_ack_t
142#define sockcmd_dat_unknowncmd sockcmd_dat_ack
143#define sockcmd_dat_unknowncmd_t sockcmd_dat_ack_t
144
146 uint64_t cmd_num;
147};
149
151 int major;
152 int minor;
153 char revision[1 << 8];
154};
156
158 char config_block[1 << 8];
159 char label[1 << 8];
162};
164
166 char dir_path[PATH_MAX];
167};
169
171 char file_path[PATH_MAX];
172};
174
177};
179
181 char key[BUFSIZ];
183};
185
186struct sockcmd {
187 uint64_t cmd_num;
188 uint16_t cmd_id;
189 size_t data_len;
190 void *data;
191};
192typedef struct sockcmd sockcmd_t;
193
198
205
208typedef void ( *freefunct_t ) ( void * );
222
223extern int socket_reply ( clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p, sockcmd_id_t cmd_id, ... );
224extern int socket_send ( clsyncsock_t *clsyncsock, sockcmd_id_t cmd_id, ... );
225extern int socket_send_cb ( clsyncsock_t *clsyncsock_p, sockcmd_id_t cmd_id, clsyncsock_cb_funct_t cb, void *cb_arg, ... );
226extern int socket_sendinvalid ( clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p );
228extern int socket_check_bysock ( int sock );
229extern clsyncsock_t *socket_accept ( int sock );
232extern int socket_init();
233extern int socket_deinit();
235extern clsyncsock_t *socket_connect_unix ( const char *const socket_path );
236extern clsyncsock_t *socket_listen_unix ( const char *const socket_path );
237
239extern int socket_thread_start ( socket_sockthreaddata_t *threaddata_p );
240
241extern int clsyncsocks_num;
242extern int clsyncsocks_count;
243extern int clsyncsocks_last;
244
245extern const char *const textmessage_args[];
246extern const char *const textmessage_descr[];
247
248#endif
249
#define CLSYNCSOCK_WINDOW
#define BUFSIZ
#define OPTION_FLAGS
Definition ctx.h:37
int socket_init()
Definition socket.c:818
enum sockauth_id sockauth_id_t
Definition socket.h:204
clsyncsock_state
Definition socket.h:91
@ CLSTATE_DIED
Definition socket.h:96
@ CLSTATE_MAIN
Definition socket.h:94
@ CLSTATE_NONE
Definition socket.h:92
@ CLSTATE_AUTH
Definition socket.h:93
@ CLSTATE_DYING
Definition socket.h:95
subprot0
Definition socket.h:85
@ SUBPROT0_TEXT
Definition socket.h:86
@ SUBPROT0_BINARY
Definition socket.h:87
clsyncsock_t * socket_listen_unix(const char *const socket_path)
Definition socket.c:192
int clsyncsocks_last
int(* clsyncsock_cb_funct_t)(struct socket_sockthreaddata *thread, struct sockcmd *sockcmd_p, void *arg)
Definition socket.h:56
enum clsyncsock_state clsyncsock_state_t
Definition socket.h:98
enum sockprocflags sockprocflags_t
Definition socket.h:197
void(* freefunct_t)(void *)
Definition socket.h:208
sockcmd_id
Definition socket.h:100
@ SOCKCMD_REQUEST_QUIT
Definition socket.h:116
@ SOCKCMD_REPLY_EPERM
Definition socket.h:108
@ SOCKCMD_REPLY_NEGOTIATION
Definition socket.h:102
@ SOCKCMD_REPLY_UNEXPECTEDEND
Definition socket.h:124
@ SOCKCMD_REPLY_LOGIN
Definition socket.h:120
@ 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_MAXID
Definition socket.h:125
@ SOCKCMD_REPLY_SET
Definition socket.h:121
@ SOCKCMD_REPLY_UNKNOWNCMD
Definition socket.h:104
@ SOCKCMD_REQUEST_NEGOTIATION
Definition socket.h:101
@ SOCKCMD_REQUEST_DIE
Definition socket.h:115
@ SOCKCMD_REPLY_ACK
Definition socket.h:103
@ SOCKCMD_REPLY_EINVAL
Definition socket.h:106
@ SOCKCMD_REPLY_DUMP
Definition socket.h:119
@ SOCKCMD_REQUEST_VERSION
Definition socket.h:110
@ SOCKCMD_REPLY_DIE
Definition socket.h:122
@ SOCKCMD_REPLY_EEXIST
Definition socket.h:107
@ SOCKCMD_REPLY_INVALIDCMDID
Definition socket.h:105
@ SOCKCMD_REPLY_BYE
Definition socket.h:123
@ SOCKCMD_REQUEST_INFO
Definition socket.h:111
@ SOCKCMD_REQUEST_LOGIN
Definition socket.h:113
@ SOCKCMD_REQUEST_DUMP
Definition socket.h:112
const char *const textmessage_args[]
Definition socket.c:72
int socket_sendinvalid(clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p)
Definition socket.c:621
socket_sockthreaddata_t * socket_thread_attach(clsyncsock_t *clsyncsock_p)
Definition socket.c:797
clsyncsock_t * socket_connect_unix(const char *const socket_path)
int socket_send(clsyncsock_t *clsyncsock, sockcmd_id_t cmd_id,...)
Definition socket.c:342
enum subprot0 subprot0_t
Definition socket.h:89
enum sockcmd_id sockcmd_id_t
Definition socket.h:127
int socket_close(clsyncsock_t *clsyncsock_p)
Definition socket.c:150
int socket_procclsyncsock(socket_sockthreaddata_t *arg)
Definition socket.c:629
int socket_check_bysock(int sock)
Definition socket.c:108
sockprocflags
Definition socket.h:194
@ SOCKPROCFLAG_NONE
Definition socket.h:195
const char *const textmessage_descr[]
Definition socket.c:88
int socket_deinit()
Definition socket.c:823
int socket_reply(clsyncsock_t *clsyncsock_p, sockcmd_t *sockcmd_p, sockcmd_id_t cmd_id,...)
Definition socket.c:331
clsyncsock_t * socket_accept(int sock)
Definition socket.c:177
int socket_thread_start(socket_sockthreaddata_t *threaddata_p)
Definition socket.c:808
int clsyncsocks_count
int socket_send_cb(clsyncsock_t *clsyncsock_p, sockcmd_id_t cmd_id, clsyncsock_cb_funct_t cb, void *cb_arg,...)
Definition socket.c:352
int socket_cleanup(clsyncsock_t *clsyncsock_p)
Definition socket.c:140
sockauth_id
Definition socket.h:199
@ SOCKAUTH_UNSET
Definition socket.h:200
@ SOCKAUTH_PAM
Definition socket.h:202
@ SOCKAUTH_NULL
Definition socket.h:201
int clsyncsocks_num
int socket_recv(clsyncsock_t *clsyncsock, sockcmd_t *sockcmd)
Definition socket.c:501
int(* clsyncsock_procfunct_t)(struct socket_sockthreaddata *, sockcmd_t *)
Definition socket.h:207
uint64_t cmd_num
Definition socket.h:58
void * callback_arg
Definition socket.h:61
clsyncsock_cb_funct_t callback_funct
Definition socket.h:60
uint64_t cmd_num
Definition socket.h:70
size_t cbqueue_len
Definition socket.h:72
clsynccbqueue_t * cbqueue_cache[4 *CLSYNCSOCK_WINDOW+1]
Definition socket.h:74
uint16_t subprot
Definition socket.h:68
uint16_t prot
Definition socket.h:67
int sock
Definition socket.h:66
clsynccbqueue_t cbqueue[CLSYNCSOCK_WINDOW+1]
Definition socket.h:73
void * arg
Definition socket.h:80
clsyncsock_t * clsyncsock_p
Definition socket.h:79
void * funct_arg_free
Definition socket.h:81
uint16_t cmd_id
Definition socket.h:137
uint64_t cmd_num
Definition socket.h:136
char dir_path[PATH_MAX]
Definition socket.h:166
char file_path[PATH_MAX]
Definition socket.h:171
char descr[BUFSIZ]
Definition socket.h:176
char label[1<< 8]
Definition socket.h:159
char flags[(1<< 10)]
Definition socket.h:160
char flags_set[(1<< 10)]
Definition socket.h:161
char config_block[1<< 8]
Definition socket.h:158
char key[BUFSIZ]
Definition socket.h:181
char value[BUFSIZ]
Definition socket.h:182
char revision[1<< 8]
Definition socket.h:153
size_t data_len
Definition socket.h:189
uint16_t cmd_id
Definition socket.h:188
uint64_t cmd_num
Definition socket.h:187
void * data
Definition socket.h:190
clsyncsock_t * clsyncsock_p
Definition socket.h:213
clsyncsock_state_t state
Definition socket.h:215
clsyncsock_procfunct_t procfunct
Definition socket.h:211
sockauth_id_t authtype
Definition socket.h:216
sockprocflags_t flags
Definition socket.h:218
freefunct_t freefunct_arg
Definition socket.h:212