tMove global declarations to synk.h - synk - synchronize files between hosts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 11db759707a8de9f5dc0686083d679d16a756555
(DIR) parent 2634aec4e642158dd6970891129b9fa8f7e0e81e
(HTM) Author: Willy <willyatmailoodotorg>
Date: Wed, 7 Sep 2016 12:53:53 +0200
Move global declarations to synk.h
Diffstat:
M mkfile | 2 +-
M synk.c | 84 +++++++------------------------
A synk.h | 53 ++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+), 66 deletions(-)
---
(DIR) diff --git a/mkfile b/mkfile
t@@ -3,7 +3,7 @@
synk: synk.o sha512.o
$LD -o $target $prereq $LDFLAGS $LIBS
-%.o: %.c
+%.o: %.c synk.h
$CC $CFLAGS -c $stem.c -o $stem.o
clean:V:
(DIR) diff --git a/synk.c b/synk.c
t@@ -16,73 +16,27 @@
#include "arg.h"
#include "sha512.h"
+#include "synk.h"
#define IS_LOOPBACK(p) ((p)->peer.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
-#define log(l,...) if(verbose>=l){printf(__VA_ARGS__);}
-
-#define DEFADDR "127.0.0.1"
-#define DEFPORT 9723
-#define SERVERTIMEO 5 /* in seconds */
-#define RCVBUFSZ 512
-#define UTSLEN 19
-#define MAXCONNECT 1
-#define MAXRETRY 8
-#define PATHCONFIG "/etc/synk.conf"
-
-/* hold a socket connection, used to pass a connection to a thread */
-struct client_t {
- int fd;
- struct in_addr inet;
-};
-
-/* metadata informations about a file, to decide about the synkro state */
-struct metadata_t {
- char path[PATH_MAX];
- unsigned char hash[64];
- long mtime;
-};
-
-/* singly-linked list for all the nodes that should be in synk */
-struct peer_t {
- char host[HOST_NAME_MAX];
- struct metadata_t meta;
- struct sockaddr_in peer;
- SLIST_ENTRY(peer_t) entries;
-};
-SLIST_HEAD(peers_t, peer_t);
-
-/* different operationnal mode for TCP connection */
-enum {
- SYNK_CLIENT,
- SYNK_SERVER
-};
-
-enum {
- LOG_NONE = 0,
- LOG_ERROR = 1,
- LOG_VERBOSE = 2,
- LOG_DEBUG = 3,
-};
-
-void usage(char *name);
-char *echo(char * []);
-char **concat(int, ...);
-
-long gettimestamp(const char *path);
-struct in_addr *getinetaddr(char *);
-struct metadata_t *getmetadata(const char *);
-struct peer_t *addpeer(struct peers_t *, char *, in_port_t);
-struct peer_t *freshestpeer(struct peers_t *);
-int getpeermeta(struct peer_t *, struct metadata_t *);
-int loadpeers(struct peers_t *, const char *);
-int flushpeers(struct peers_t *);
-int spawnremote(struct peers_t *);
-int uptodate(struct peers_t *);
-int dosync(struct peer_t *master, struct peer_t *slave);
-int syncwithmaster(struct peer_t *master, struct peers_t *plist);
-int syncfile(struct peers_t *, const char *);
-int sendmetadata(struct client_t *);
-int waitclient(in_addr_t, in_port_t);
+
+static void usage(char *name);
+static char *echo(char * []);
+static char **concat(int, ...);
+
+static long gettimestamp(const char *path);
+static struct in_addr *getinetaddr(char *);
+static struct metadata_t *getmetadata(const char *);
+static struct peer_t *freshestpeer(struct peers_t *);
+static int getpeermeta(struct peer_t *, struct metadata_t *);
+static int flushpeers(struct peers_t *);
+static int spawnremote(struct peers_t *);
+static int uptodate(struct peers_t *);
+static int dosync(struct peer_t *master, struct peer_t *slave);
+static int syncwithmaster(struct peer_t *master, struct peers_t *plist);
+static int syncfile(struct peers_t *, const char *);
+static int sendmetadata(struct client_t *);
+static int waitclient(in_addr_t, in_port_t);
const char *rsync_cmd[] = { "rsync", "-azEq", "--delete", NULL };
const char *ssh_cmd[] = { "ssh", NULL };
(DIR) diff --git a/synk.h b/synk.h
t@@ -0,0 +1,53 @@
+#include <arpa/inet.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <limits.h>
+
+#define log(l,...) if(verbose>=l){printf(__VA_ARGS__);}
+
+#define DEFADDR "127.0.0.1"
+#define DEFPORT 9723
+#define SERVERTIMEO 5 /* in seconds */
+#define RCVBUFSZ 512
+#define UTSLEN 19
+#define MAXCONNECT 1
+#define MAXRETRY 8
+#define PATHCONFIG "/etc/synk.conf"
+
+/* hold a socket connection, used to pass a connection to a thread */
+struct client_t {
+ int fd;
+ struct in_addr inet;
+};
+
+/* metadata informations about a file, to decide about the synkro state */
+struct metadata_t {
+ char path[PATH_MAX];
+ unsigned char hash[64];
+ long mtime;
+};
+
+/* singly-linked list for all the nodes that should be in synk */
+struct peer_t {
+ char host[HOST_NAME_MAX];
+ struct metadata_t meta;
+ struct sockaddr_in peer;
+ SLIST_ENTRY(peer_t) entries;
+};
+SLIST_HEAD(peers_t, peer_t);
+
+/* different operationnal mode for TCP connection */
+enum {
+ SYNK_CLIENT,
+ SYNK_SERVER
+};
+
+enum {
+ LOG_NONE = 0,
+ LOG_ERROR = 1,
+ LOG_VERBOSE = 2,
+ LOG_DEBUG = 3,
+};
+
+struct peer_t *addpeer(struct peers_t *, char *, in_port_t);
+int parseconf(struct peers_t *, const char *);