[vhffs-dev] [1264] sed -i -e s/coucou_/vhffsfssync_/g -e s/COUCOU_/VHFFSFSSYNC_/g |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1264
Author: gradator
Date: 2008-10-07 13:10:20 +0200 (Tue, 07 Oct 2008)
Log Message:
-----------
sed -i -e s/coucou_/vhffsfssync_/g -e s/COUCOU_/VHFFSFSSYNC_/g
Modified Paths:
--------------
trunk/vhffs-fssync/client.c
trunk/vhffs-fssync/getevents.c
Modified: trunk/vhffs-fssync/client.c
===================================================================
--- trunk/vhffs-fssync/client.c 2008-10-07 11:04:17 UTC (rev 1263)
+++ trunk/vhffs-fssync/client.c 2008-10-07 11:10:20 UTC (rev 1264)
@@ -26,29 +26,29 @@
/* -- network stuff -- */
// huge buffer size reduce syscalls
-#define COUCOU_NET_BUF_LEN 262144
+#define VHFFSFSSYNC_NET_BUF_LEN 262144
typedef struct {
int fd;
struct sockaddr_in sockaddr;
- char buf[COUCOU_NET_BUF_LEN];
+ char buf[VHFFSFSSYNC_NET_BUF_LEN];
uint32_t buf_len;
char *buf_cur;
FILE *chunk_file;
size_t chunk_stilltoread;
-} coucou_conn;
+} vhffsfssync_conn;
// protos
-int coucou_remove(char *pathname);
-int coucou_mkdir(char *pathname, mode_t mode);
-int coucou_event(coucou_conn *conn, char *event);
-int coucou_parse(coucou_conn *conn);
+int vhffsfssync_remove(char *pathname);
+int vhffsfssync_mkdir(char *pathname, mode_t mode);
+int vhffsfssync_event(vhffsfssync_conn *conn, char *event);
+int vhffsfssync_parse(vhffsfssync_conn *conn);
/* ---------------------------------------- */
-int coucou_remove(char *pathname) {
+int vhffsfssync_remove(char *pathname) {
struct stat st;
if(! lstat(pathname, &st) ) {
@@ -65,7 +65,7 @@
char *sep = "/";
if( pathname[strlen(pathname)-1] == '/' ) sep = "";
path = g_strdup_printf("%s%s%s", pathname, sep, dir->d_name);
- coucou_remove(path);
+ vhffsfssync_remove(path);
free(path);
}
}
@@ -95,7 +95,7 @@
}
-int coucou_mkdir(char *pathname, mode_t mode) {
+int vhffsfssync_mkdir(char *pathname, mode_t mode) {
char *cur, *dirs[64];
int i, fd, fd_, argc;
@@ -126,7 +126,7 @@
}
-int coucou_event(coucou_conn *conn, char *event) {
+int vhffsfssync_event(vhffsfssync_conn *conn, char *event) {
char *cur, *args[10];
int argc;
@@ -153,7 +153,7 @@
if(!strcmp(args[0], "remove")) {
char *pathname = args[1];
- coucou_remove(pathname);
+ vhffsfssync_remove(pathname);
}
else if(!strcmp(args[0], "create")) {
char *pathname = args[1];
@@ -169,7 +169,7 @@
}
else if(!strcmp(args[0], "mkdir")) {
char *path = args[1];
- coucou_mkdir(path, 0755);
+ vhffsfssync_mkdir(path, 0755);
}
else if(!strcmp(args[0], "symlink")) {
char *from = args[1];
@@ -232,7 +232,7 @@
}
-int coucou_parse(coucou_conn *conn) {
+int vhffsfssync_parse(vhffsfssync_conn *conn) {
char *cur, *end;
cur = conn->buf;
@@ -249,7 +249,7 @@
if( *cur == '\n' ) {
*cur = '\0';
- coucou_event(conn, begin);
+ vhffsfssync_event(conn, begin);
begin = ++cur;
}
@@ -259,7 +259,7 @@
//printf("Not parsed %d\n", len);
// buffer is full and we didn't manage to fetch everything
- if(len == COUCOU_NET_BUF_LEN) {
+ if(len == VHFFSFSSYNC_NET_BUF_LEN) {
fprintf(stderr, "The buffer is not large enough, throwing away the content\n");
conn->buf_cur = conn->buf;
conn->buf_len = 0;
@@ -316,7 +316,7 @@
char *root, *host;
int flags, port;
- coucou_conn *conn;
+ vhffsfssync_conn *conn;
/* chdir() to the filesystem to write the data */
root = argv[1];
@@ -330,7 +330,7 @@
host = argv[2];
port = atoi(argv[3]);
signal(SIGPIPE, SIG_IGN);
- conn = malloc(sizeof(coucou_conn));
+ conn = malloc(sizeof(vhffsfssync_conn));
/* -- main loop -- */
while(1) {
@@ -399,7 +399,7 @@
if(FD_ISSET(conn->fd, &readfs) ) {
ssize_t len;
- len = read(conn->fd, conn->buf_cur, COUCOU_NET_BUF_LEN - (conn->buf_cur - conn->buf) );
+ len = read(conn->fd, conn->buf_cur, VHFFSFSSYNC_NET_BUF_LEN - (conn->buf_cur - conn->buf) );
if(len < 0) {
switch(errno) {
case EAGAIN:
@@ -420,7 +420,7 @@
else {
//printf("Read %d\n", len);
conn->buf_len += len;
- coucou_parse(conn);
+ vhffsfssync_parse(conn);
}
}
}
Modified: trunk/vhffs-fssync/getevents.c
===================================================================
--- trunk/vhffs-fssync/getevents.c 2008-10-07 11:04:17 UTC (rev 1263)
+++ trunk/vhffs-fssync/getevents.c 2008-10-07 11:10:20 UTC (rev 1264)
@@ -30,50 +30,50 @@
/* -- inotify stuff -- */
-#define COUCOU_BUF_LEN 4096
-#define COUCOU_WATCH_MASK IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MODIFY|IN_MOVE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_DONT_FOLLOW|IN_ONLYDIR
+#define VHFFSFSSYNC_BUF_LEN 4096
+#define VHFFSFSSYNC_WATCH_MASK IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MODIFY|IN_MOVE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_DONT_FOLLOW|IN_ONLYDIR
// Not used: IN_ACCESS, IN_CLOSE_NOWRITE, IN_OPEN
// the maximum number of files simultaneously opened
// huge values offer better performance
-// actually it is MAX = COUCOU_MAX_OPENFILES + number of clients
-#define COUCOU_MAX_OPENFILES 512
+// actually it is MAX = VHFFSFSSYNC_MAX_OPENFILES + number of clients
+#define VHFFSFSSYNC_MAX_OPENFILES 512
// each monitor entry is associated with a path, we need to keep it to compute the path
-//char **coucou_wd_to_path = NULL;
-//int coucou_wd_to_path_len = 0; // number of allocated paths
-GHashTable *coucou_wd_to_path;
-GHashTable *coucou_path_to_wd;
+//char **vhffsfssync_wd_to_path = NULL;
+//int vhffsfssync_wd_to_path_len = 0; // number of allocated paths
+GHashTable *vhffsfssync_wd_to_path;
+GHashTable *vhffsfssync_path_to_wd;
// return a timestamp in ms (it loops for 100000 sec)
-/*inline int coucou_timestamp() {
+/*inline int vhffsfssync_timestamp() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec%100000)*1000+tv.tv_usec/1000;
}*/
-struct coucou_cookie {
+struct vhffsfssync_cookie {
uint32_t id;
char *from;
gboolean isdir;
};
-static struct coucou_cookie coucou_cookie;
+static struct vhffsfssync_cookie vhffsfssync_cookie;
-int coucou_openfiles;
+int vhffsfssync_openfiles;
// protos
-int coucou_add_watch(int inotifyfd, const char *pathname, uint32_t mask);
-int coucou_del_watch(int inotifyfd, const char *pathname, int wd);
-int coucou_add_watch_recursively(int inotifyfd, const char *pathname, uint32_t mask);
-int coucou_manage_event_create(int inotifyfd, char *pathname, gboolean sendfile);
-int coucou_manage_event(int inotifyfd, struct inotify_event *event);
-int coucou_fake_events_recursively(int inotifyfd, char *pathname);
+int vhffsfssync_add_watch(int inotifyfd, const char *pathname, uint32_t mask);
+int vhffsfssync_del_watch(int inotifyfd, const char *pathname, int wd);
+int vhffsfssync_add_watch_recursively(int inotifyfd, const char *pathname, uint32_t mask);
+int vhffsfssync_manage_event_create(int inotifyfd, char *pathname, gboolean sendfile);
+int vhffsfssync_manage_event(int inotifyfd, struct inotify_event *event);
+int vhffsfssync_fake_events_recursively(int inotifyfd, char *pathname);
/* -- network stuff -- */
-#define COUCOU_NET_MESSAGE_FILE_CHUNK 65536
+#define VHFFSFSSYNC_NET_MESSAGE_FILE_CHUNK 65536
-GList *coucou_conns;
+GList *vhffsfssync_conns;
typedef struct {
int fd;
@@ -86,57 +86,57 @@
// char *sendbuf;
// ssize_t sendbuf_cur;
// ssize_t sendbuf_size;
-} coucou_conn;
+} vhffsfssync_conn;
/* message - generic */
typedef unsigned short int msg_family_t;
enum {
- COUCOU_NET_MESSAGE_UNSPEC=0,
- COUCOU_NET_MESSAGE_DATA,
- COUCOU_NET_MESSAGE_FILE
+ VHFFSFSSYNC_NET_MESSAGE_UNSPEC=0,
+ VHFFSFSSYNC_NET_MESSAGE_DATA,
+ VHFFSFSSYNC_NET_MESSAGE_FILE
};
/* message - priorities */
enum {
- COUCOU_NET_PRIO_HIGHEST=100, // values < 100 may be used internally, please don't set anything below 100 or die!
- COUCOU_NET_PRIO_HIGH, // values >= 1000 are used for files, don't use them too
- COUCOU_NET_PRIO_MEDIUM,
- COUCOU_NET_PRIO_LOW,
- COUCOU_NET_PRIO_LOWEST
+ VHFFSFSSYNC_NET_PRIO_HIGHEST=100, // values < 100 may be used internally, please don't set anything below 100 or die!
+ VHFFSFSSYNC_NET_PRIO_HIGH, // values >= 1000 are used for files, don't use them too
+ VHFFSFSSYNC_NET_PRIO_MEDIUM,
+ VHFFSFSSYNC_NET_PRIO_LOW,
+ VHFFSFSSYNC_NET_PRIO_LOWEST
};
-#define __COUCOU_NET_MESSAGE_COMMON(msg_prefix) \
+#define __VHFFSFSSYNC_NET_MESSAGE_COMMON(msg_prefix) \
msg_family_t msg_prefix##family; \
uint32_t msg_prefix##priority; \
uint32_t msg_prefix##order
-#define __COUCOU_NET_MESSAGE_COMMON_SIZE ( sizeof (msg_family_t) + sizeof(uint32_t) + sizeof(uint32_t) )
+#define __VHFFSFSSYNC_NET_MESSAGE_COMMON_SIZE ( sizeof (msg_family_t) + sizeof(uint32_t) + sizeof(uint32_t) )
typedef struct {
- __COUCOU_NET_MESSAGE_COMMON(msg_);
+ __VHFFSFSSYNC_NET_MESSAGE_COMMON(msg_);
char msg_data[200];
-} coucou_net_message;
+} vhffsfssync_net_message;
/* message - common data */
typedef struct {
- __COUCOU_NET_MESSAGE_COMMON(data_);
+ __VHFFSFSSYNC_NET_MESSAGE_COMMON(data_);
char *data_buffer;
ssize_t data_len;
ssize_t data_cur;
- /* pad to size of `coucou_net_message' */
- unsigned char sin_zero[ sizeof(coucou_net_message)
- - __COUCOU_NET_MESSAGE_COMMON_SIZE
+ /* pad to size of `vhffsfssync_net_message' */
+ unsigned char sin_zero[ sizeof(vhffsfssync_net_message)
+ - __VHFFSFSSYNC_NET_MESSAGE_COMMON_SIZE
- sizeof(char*)
- sizeof(ssize_t)
- sizeof(ssize_t) ];
-} coucou_net_message_data;
+} vhffsfssync_net_message_data;
/* message - file */
typedef struct {
- __COUCOU_NET_MESSAGE_COMMON(file_);
+ __VHFFSFSSYNC_NET_MESSAGE_COMMON(file_);
FILE *file_stream;
off_t file_offset;
off_t file_size;
@@ -144,39 +144,39 @@
off_t file_chunkcur;
char *file_pathname;
- /* pad to size of `coucou_net_message' */
- unsigned char sin_zero[ sizeof(coucou_net_message)
- - __COUCOU_NET_MESSAGE_COMMON_SIZE
+ /* pad to size of `vhffsfssync_net_message' */
+ unsigned char sin_zero[ sizeof(vhffsfssync_net_message)
+ - __VHFFSFSSYNC_NET_MESSAGE_COMMON_SIZE
- sizeof(FILE*)
- sizeof(off_t)
- sizeof(off_t)
- sizeof(off_t)
- sizeof(off_t)
- sizeof(char*) ];
-} coucou_net_message_file;
+} vhffsfssync_net_message_file;
// protos
-void coucou_net_conn_disable(coucou_conn *conn);
-void coucou_net_conn_destroy(coucou_conn *conn);
-inline coucou_net_message *coucou_net_new_message(coucou_conn *conn, msg_family_t family, uint32_t priority);
-gint coucou_net_message_insert_compare(gconstpointer a, gconstpointer b);
-inline void coucou_net_destroy_message(coucou_conn *conn, coucou_net_message *msg);
-int coucou_net_send_data(coucou_conn *conn, char *data, ssize_t len, uint32_t priority);
-void coucou_net_destroy_data(coucou_conn *conn, coucou_net_message_data *datamsg);
-inline int coucou_net_send_string(coucou_conn *conn, char *data, uint32_t priority) ;
-void coucou_net_broadcast_string(char *data, uint32_t priority);
-int coucou_net_send_file(coucou_conn *conn, char *pathname);
-void coucou_net_destroy_file(coucou_conn *conn, coucou_net_message_file *filemsg);
-FILE *coucou_net_file_open(coucou_conn *conn, const char *pathname, const char *mode);
-int coucou_net_file_close(coucou_conn *conn, FILE *stream);
-int coucou_net_remove_file(coucou_conn *conn, char *pathname);
-void coucou_net_broadcast_file(char *pathname);
-int coucou_net_send(coucou_conn *conn);
+void vhffsfssync_net_conn_disable(vhffsfssync_conn *conn);
+void vhffsfssync_net_conn_destroy(vhffsfssync_conn *conn);
+inline vhffsfssync_net_message *vhffsfssync_net_new_message(vhffsfssync_conn *conn, msg_family_t family, uint32_t priority);
+gint vhffsfssync_net_message_insert_compare(gconstpointer a, gconstpointer b);
+inline void vhffsfssync_net_destroy_message(vhffsfssync_conn *conn, vhffsfssync_net_message *msg);
+int vhffsfssync_net_send_data(vhffsfssync_conn *conn, char *data, ssize_t len, uint32_t priority);
+void vhffsfssync_net_destroy_data(vhffsfssync_conn *conn, vhffsfssync_net_message_data *datamsg);
+inline int vhffsfssync_net_send_string(vhffsfssync_conn *conn, char *data, uint32_t priority) ;
+void vhffsfssync_net_broadcast_string(char *data, uint32_t priority);
+int vhffsfssync_net_send_file(vhffsfssync_conn *conn, char *pathname);
+void vhffsfssync_net_destroy_file(vhffsfssync_conn *conn, vhffsfssync_net_message_file *filemsg);
+FILE *vhffsfssync_net_file_open(vhffsfssync_conn *conn, const char *pathname, const char *mode);
+int vhffsfssync_net_file_close(vhffsfssync_conn *conn, FILE *stream);
+int vhffsfssync_net_remove_file(vhffsfssync_conn *conn, char *pathname);
+void vhffsfssync_net_broadcast_file(char *pathname);
+int vhffsfssync_net_send(vhffsfssync_conn *conn);
/* ----------------------------------------- */
-void coucou_net_conn_disable(coucou_conn *conn) {
+void vhffsfssync_net_conn_disable(vhffsfssync_conn *conn) {
GList *msgs;
if(conn->fd >= 0) {
@@ -189,22 +189,22 @@
conn->fd = -1;
while( (msgs = g_list_first(conn->messages)) ) {
- coucou_net_destroy_message(conn, (coucou_net_message*)msgs->data );
+ vhffsfssync_net_destroy_message(conn, (vhffsfssync_net_message*)msgs->data );
}
}
-void coucou_net_conn_destroy(coucou_conn *conn) {
- coucou_conns = g_list_remove(coucou_conns, conn);
- coucou_net_conn_disable(conn);
+void vhffsfssync_net_conn_destroy(vhffsfssync_conn *conn) {
+ vhffsfssync_conns = g_list_remove(vhffsfssync_conns, conn);
+ vhffsfssync_net_conn_disable(conn);
free(conn);
}
/* -- network stuff -- */
-inline coucou_net_message *coucou_net_new_message(coucou_conn *conn, msg_family_t family, uint32_t priority) {
- coucou_net_message *msg;
- msg = malloc( sizeof(coucou_net_message) );
+inline vhffsfssync_net_message *vhffsfssync_net_new_message(vhffsfssync_conn *conn, msg_family_t family, uint32_t priority) {
+ vhffsfssync_net_message *msg;
+ msg = malloc( sizeof(vhffsfssync_net_message) );
msg->msg_family = family;
msg->msg_priority = priority;
msg->msg_order = conn->order++;
@@ -212,9 +212,9 @@
}
-gint coucou_net_message_insert_compare(gconstpointer a, gconstpointer b) {
- coucou_net_message *first = (coucou_net_message*)a;
- coucou_net_message *second = (coucou_net_message*)b;
+gint vhffsfssync_net_message_insert_compare(gconstpointer a, gconstpointer b) {
+ vhffsfssync_net_message *first = (vhffsfssync_net_message*)a;
+ vhffsfssync_net_message *second = (vhffsfssync_net_message*)b;
// lowest priority is preferred
if(first->msg_priority != second->msg_priority)
@@ -225,59 +225,59 @@
}
-inline void coucou_net_destroy_message(coucou_conn *conn, coucou_net_message *msg) {
- if(msg->msg_family == COUCOU_NET_MESSAGE_DATA) {
- coucou_net_destroy_data(conn, (coucou_net_message_data*)msg);
+inline void vhffsfssync_net_destroy_message(vhffsfssync_conn *conn, vhffsfssync_net_message *msg) {
+ if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_DATA) {
+ vhffsfssync_net_destroy_data(conn, (vhffsfssync_net_message_data*)msg);
}
- else if(msg->msg_family == COUCOU_NET_MESSAGE_FILE) {
- coucou_net_destroy_file(conn, (coucou_net_message_file*)msg);
+ else if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_FILE) {
+ vhffsfssync_net_destroy_file(conn, (vhffsfssync_net_message_file*)msg);
}
}
// !!!!!! the buffer is freed when the message has been sent, DON'T send static string and DON'T free() the data yourself
-int coucou_net_send_data(coucou_conn *conn, char *data, ssize_t len, uint32_t priority) {
- coucou_net_message_data *msg;
+int vhffsfssync_net_send_data(vhffsfssync_conn *conn, char *data, ssize_t len, uint32_t priority) {
+ vhffsfssync_net_message_data *msg;
if(!conn || !data || len <= 0) return -1;
- msg = (coucou_net_message_data*)coucou_net_new_message(conn, COUCOU_NET_MESSAGE_DATA, priority);
+ msg = (vhffsfssync_net_message_data*)vhffsfssync_net_new_message(conn, VHFFSFSSYNC_NET_MESSAGE_DATA, priority);
msg->data_buffer = data;
msg->data_len = len;
msg->data_cur = 0;
- conn->messages = g_list_insert_sorted(conn->messages, msg, coucou_net_message_insert_compare);
+ conn->messages = g_list_insert_sorted(conn->messages, msg, vhffsfssync_net_message_insert_compare);
return 0;
}
-void coucou_net_destroy_data(coucou_conn *conn, coucou_net_message_data *datamsg) {
- conn->messages = g_list_remove(conn->messages, (coucou_net_message*)datamsg);
+void vhffsfssync_net_destroy_data(vhffsfssync_conn *conn, vhffsfssync_net_message_data *datamsg) {
+ conn->messages = g_list_remove(conn->messages, (vhffsfssync_net_message*)datamsg);
free(datamsg->data_buffer);
free(datamsg);
}
-inline int coucou_net_send_string(coucou_conn *conn, char *data, uint32_t priority) {
- return coucou_net_send_data(conn, data, strlen(data), priority);
+inline int vhffsfssync_net_send_string(vhffsfssync_conn *conn, char *data, uint32_t priority) {
+ return vhffsfssync_net_send_data(conn, data, strlen(data), priority);
}
-void coucou_net_broadcast_string(char *data, uint32_t priority) {
+void vhffsfssync_net_broadcast_string(char *data, uint32_t priority) {
GList *conns;
- for(conns = g_list_first(coucou_conns) ; conns ; ) {
- coucou_conn *conn = conns->data;
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
- coucou_net_send_string(conn, strdup(data), priority);
+ vhffsfssync_net_send_string(conn, strdup(data), priority);
}
free(data);
}
// prototype is simple, files are always the lowest of the lowest priority messages
-int coucou_net_send_file(coucou_conn *conn, char *pathname) {
- coucou_net_message_file *msg;
+int vhffsfssync_net_send_file(vhffsfssync_conn *conn, char *pathname) {
+ vhffsfssync_net_message_file *msg;
struct stat st;
uint32_t maxprio = -1; // 4294967295
FILE *stream;
@@ -297,33 +297,33 @@
return -1;
}
- stream = coucou_net_file_open(conn, pathname, "r");
+ stream = vhffsfssync_net_file_open(conn, pathname, "r");
if(!stream) {
return -1;
}
// if the file is being sent, cancel it
- coucou_net_remove_file(conn, pathname);
+ vhffsfssync_net_remove_file(conn, pathname);
//printf("%d SENDING FILE %s\n", conn->fd, pathname);
- coucou_net_send_string( conn, g_strdup_printf("create\x1F%s\n", pathname) , COUCOU_NET_PRIO_MEDIUM);
+ vhffsfssync_net_send_string( conn, g_strdup_printf("create\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
// the size of the file is the priority (small files are sent with more priority)
// but don't set the priority too low, low value can be used for anything else
- msg = (coucou_net_message_file*)coucou_net_new_message(conn, COUCOU_NET_MESSAGE_FILE, MAX(MIN(st.st_size, maxprio),1000) );
+ msg = (vhffsfssync_net_message_file*)vhffsfssync_net_new_message(conn, VHFFSFSSYNC_NET_MESSAGE_FILE, MAX(MIN(st.st_size, maxprio),1000) );
msg->file_stream = stream;
msg->file_offset = 0;
msg->file_pathname = strdup(pathname);
msg->file_size = st.st_size;
msg->file_chunksize = -1;
msg->file_chunkcur = 0;
- conn->messages = g_list_insert_sorted(conn->messages, msg, coucou_net_message_insert_compare);
+ conn->messages = g_list_insert_sorted(conn->messages, msg, vhffsfssync_net_message_insert_compare);
return 0;
}
-void coucou_net_destroy_file(coucou_conn *conn, coucou_net_message_file *filemsg) {
- conn->messages = g_list_remove(conn->messages, (coucou_net_message*)filemsg);
+void vhffsfssync_net_destroy_file(vhffsfssync_conn *conn, vhffsfssync_net_message_file *filemsg) {
+ conn->messages = g_list_remove(conn->messages, (vhffsfssync_net_message*)filemsg);
/* we need to finish the chunk anyway */
if(filemsg->file_chunksize > 0) {
@@ -331,17 +331,17 @@
if(len > 0) {
char *data = malloc(len);
memset(data, 0, len);
- coucou_net_send_data(conn, data, len, 0);
+ vhffsfssync_net_send_data(conn, data, len, 0);
}
}
- coucou_net_file_close(conn, filemsg->file_stream);
+ vhffsfssync_net_file_close(conn, filemsg->file_stream);
free(filemsg->file_pathname);
free(filemsg);
}
-FILE *coucou_net_file_open(coucou_conn *conn, const char *pathname, const char *mode) {
+FILE *vhffsfssync_net_file_open(vhffsfssync_conn *conn, const char *pathname, const char *mode) {
FILE *stream;
if(!conn || !pathname || !mode)
@@ -353,20 +353,20 @@
return stream;
}
- coucou_openfiles++;
+ vhffsfssync_openfiles++;
// do we need to free a file fd ?
- if(coucou_openfiles > COUCOU_MAX_OPENFILES) {
+ if(vhffsfssync_openfiles > VHFFSFSSYNC_MAX_OPENFILES) {
GList *msgs;
// we prefer to fclose() the fd of the msg with the lowest priority
for(msgs = g_list_last(conn->messages) ; msgs ; ) {
- coucou_net_message *msg = msgs->data;
+ vhffsfssync_net_message *msg = msgs->data;
msgs = g_list_previous(msgs);
- if(msg->msg_family == COUCOU_NET_MESSAGE_FILE) {
- coucou_net_message_file *filemsg = (coucou_net_message_file*)msg;
+ if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_FILE) {
+ vhffsfssync_net_message_file *filemsg = (vhffsfssync_net_message_file*)msg;
if(filemsg->file_stream && filemsg->file_chunksize < 0) {
- coucou_net_file_close(conn, filemsg->file_stream);
+ vhffsfssync_net_file_close(conn, filemsg->file_stream);
filemsg->file_stream = NULL;
break;
}
@@ -378,7 +378,7 @@
}
-int coucou_net_file_close(coucou_conn *conn, FILE *stream) {
+int vhffsfssync_net_file_close(vhffsfssync_conn *conn, FILE *stream) {
int r;
if(!stream)
@@ -389,33 +389,33 @@
fprintf(stderr, "fclose() failed: %s\n", strerror(errno));
return r;
}
- coucou_openfiles--;
+ vhffsfssync_openfiles--;
return r;
}
-void coucou_net_broadcast_file(char *pathname) {
+void vhffsfssync_net_broadcast_file(char *pathname) {
GList *conns;
- for(conns = g_list_first(coucou_conns) ; conns ; ) {
- coucou_conn *conn = conns->data;
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
- coucou_net_send_file(conn, pathname);
+ vhffsfssync_net_send_file(conn, pathname);
}
}
-int coucou_net_remove_file(coucou_conn *conn, char *pathname) {
+int vhffsfssync_net_remove_file(vhffsfssync_conn *conn, char *pathname) {
GList *msgs;
for(msgs = g_list_first(conn->messages) ; msgs ; ) {
- coucou_net_message *msg = msgs->data;
+ vhffsfssync_net_message *msg = msgs->data;
msgs = g_list_next(msgs);
- if(msg->msg_family == COUCOU_NET_MESSAGE_FILE) {
- coucou_net_message_file *filemsg = (coucou_net_message_file*)msg;
+ if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_FILE) {
+ vhffsfssync_net_message_file *filemsg = (vhffsfssync_net_message_file*)msg;
if(!strcmp(filemsg->file_pathname, pathname)) {
//printf("%d CANCELLING %s\n", conn->fd, pathname);
- coucou_net_destroy_file(conn, filemsg);
+ vhffsfssync_net_destroy_file(conn, filemsg);
}
}
}
@@ -423,7 +423,7 @@
}
-int coucou_net_send(coucou_conn *conn) {
+int vhffsfssync_net_send(vhffsfssync_conn *conn) {
GList *msgs;
gboolean full = FALSE;
@@ -433,20 +433,20 @@
printf("conn: %d, to: %s\n", conn->fd, inet_ntoa(conn->sockaddr.sin_addr));
#endif
while(!full && conn->fd >= 0 && (msgs = g_list_first(conn->messages)) ) {
- coucou_net_message *msg = msgs->data;
+ vhffsfssync_net_message *msg = msgs->data;
#if DEBUG_NET
printf(" family: %d , priority: %d , order: %d\n", msg->msg_family, msg->msg_priority, msg->msg_order);
#endif
// data
- if(msg->msg_family == COUCOU_NET_MESSAGE_DATA) {
- coucou_net_message_data *datamsg;
+ if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_DATA) {
+ vhffsfssync_net_message_data *datamsg;
ssize_t written;
ssize_t lentowrite;
// we need to make sure that the message will not be truncated, we set the current message to the highest priority
msg->msg_priority = 0;
- datamsg = (coucou_net_message_data*)msg;
+ datamsg = (vhffsfssync_net_message_data*)msg;
#if DEBUG_NET
printf(" buffer: %d bytes, %d already written\n", datamsg->data_len, datamsg->data_cur);
#endif
@@ -464,7 +464,7 @@
break;
default:
fprintf(stderr, "write() failed on socket %d: %s\n", conn->fd, strerror(errno));
- coucou_net_conn_disable(conn);
+ vhffsfssync_net_conn_disable(conn);
}
}
else {
@@ -478,36 +478,36 @@
}
/* buffer is now empty */
else {
- coucou_net_destroy_data(conn, datamsg);
+ vhffsfssync_net_destroy_data(conn, datamsg);
}
}
}
// file
- else if(msg->msg_family == COUCOU_NET_MESSAGE_FILE) {
- coucou_net_message_file *filemsg;
+ else if(msg->msg_family == VHFFSFSSYNC_NET_MESSAGE_FILE) {
+ vhffsfssync_net_message_file *filemsg;
ssize_t written;
off_t lentowrite;
- filemsg = (coucou_net_message_file*)msg;
+ filemsg = (vhffsfssync_net_message_file*)msg;
#if DEBUG_NET
printf(" file: %s, offset = %lld, size = %lld\n", filemsg->file_pathname, (long long int)filemsg->file_offset, (long long int)filemsg->file_size);
#endif
/* new chunk */
if(filemsg->file_chunksize < 0) {
if(!filemsg->file_stream) {
- filemsg->file_stream = coucou_net_file_open(conn, filemsg->file_pathname, "r");
+ filemsg->file_stream = vhffsfssync_net_file_open(conn, filemsg->file_pathname, "r");
if(!filemsg->file_stream) {
- coucou_net_destroy_file(conn, filemsg);
+ vhffsfssync_net_destroy_file(conn, filemsg);
break;
}
}
- lentowrite = filemsg->file_chunksize = MIN(COUCOU_NET_MESSAGE_FILE_CHUNK, filemsg->file_size - filemsg->file_offset);
+ lentowrite = filemsg->file_chunksize = MIN(VHFFSFSSYNC_NET_MESSAGE_FILE_CHUNK, filemsg->file_size - filemsg->file_offset);
filemsg->file_chunkcur = 0;
// we need to make sure that the chunk will not be truncated, we set the current message to the highest priority
msg->msg_priority = 1;
- coucou_net_send_string(conn, g_strdup_printf("write\x1F%s\x1F%lld\x1F%lld\n", filemsg->file_pathname, (long long int)filemsg->file_offset, (long long int)filemsg->file_chunksize) , 0);
+ vhffsfssync_net_send_string(conn, g_strdup_printf("write\x1F%s\x1F%lld\x1F%lld\n", filemsg->file_pathname, (long long int)filemsg->file_offset, (long long int)filemsg->file_chunksize) , 0);
// we need to reset here in order to consider the new priorities
continue;
}
@@ -529,7 +529,7 @@
break;
default:
fprintf(stderr, "sendfile() failed from file %s to socket %d: %s\n", filemsg->file_pathname, conn->fd, strerror(errno));
- coucou_net_conn_disable(conn);
+ vhffsfssync_net_conn_disable(conn);
}
}
else {
@@ -540,7 +540,7 @@
/* end of file or file completed */
if( written == 0 || filemsg->file_offset == filemsg->file_size ) {
- coucou_net_destroy_file(conn, filemsg);
+ vhffsfssync_net_destroy_file(conn, filemsg);
}
/* the chunk is not fully sent yet */
@@ -558,7 +558,7 @@
// reschedule this file to a nicer priority
msg->msg_priority = MAX(MIN(filemsg->file_size - filemsg->file_offset, maxprio),1000);
conn->messages = g_list_remove(conn->messages, msg);
- conn->messages = g_list_insert_sorted(conn->messages, msg, coucou_net_message_insert_compare);
+ conn->messages = g_list_insert_sorted(conn->messages, msg, vhffsfssync_net_message_insert_compare);
}
}
}
@@ -572,7 +572,7 @@
#if 0
-int coucou_net_write(coucou_conn *conn, char *buffer, ssize_t len) {
+int vhffsfssync_net_write(vhffsfssync_conn *conn, char *buffer, ssize_t len) {
ssize_t written = -1;
@@ -656,13 +656,13 @@
/* -- inotify stuff -- */
-int coucou_add_watch(int inotifyfd, const char *pathname, uint32_t mask) {
+int vhffsfssync_add_watch(int inotifyfd, const char *pathname, uint32_t mask) {
int wd;
int *_wd;
char *_pathname;
- if( g_hash_table_lookup(coucou_path_to_wd, pathname) ) {
+ if( g_hash_table_lookup(vhffsfssync_path_to_wd, pathname) ) {
return -1;
}
@@ -677,34 +677,34 @@
_wd = g_new(int, 1);
*_wd = wd;
_pathname = g_strdup(pathname);
- g_hash_table_insert(coucou_wd_to_path, _wd, _pathname);
- g_hash_table_insert(coucou_path_to_wd, _pathname, _wd);
+ g_hash_table_insert(vhffsfssync_wd_to_path, _wd, _pathname);
+ g_hash_table_insert(vhffsfssync_path_to_wd, _pathname, _wd);
-// if(wd >= coucou_wd_to_path_len) {
-// coucou_wd_to_path_len = ( (wd >>10) +1) <<10;
-// coucou_wd_to_path = realloc( coucou_wd_to_path, coucou_wd_to_path_len * sizeof(void*) );
+// if(wd >= vhffsfssync_wd_to_path_len) {
+// vhffsfssync_wd_to_path_len = ( (wd >>10) +1) <<10;
+// vhffsfssync_wd_to_path = realloc( vhffsfssync_wd_to_path, vhffsfssync_wd_to_path_len * sizeof(void*) );
// }
-// coucou_wd_to_path[wd] = strdup(pathname);
+// vhffsfssync_wd_to_path[wd] = strdup(pathname);
#if DEBUG_INOTIFY
printf("+ %d %s\n", wd, pathname);
#endif
- if(g_hash_table_size(coucou_wd_to_path) != g_hash_table_size(coucou_path_to_wd)) {
+ if(g_hash_table_size(vhffsfssync_wd_to_path) != g_hash_table_size(vhffsfssync_path_to_wd)) {
exit(-1);
}
return wd;
}
-int coucou_del_watch(int inotifyfd, const char *pathname, int wd) {
+int vhffsfssync_del_watch(int inotifyfd, const char *pathname, int wd) {
if(!pathname && wd > 0) {
- pathname = (char*)g_hash_table_lookup(coucou_wd_to_path, &wd);
+ pathname = (char*)g_hash_table_lookup(vhffsfssync_wd_to_path, &wd);
// this wd has already been deleted
if(!pathname) return -1;
}
else if(pathname && wd == 0) {
int *_wd;
- _wd = g_hash_table_lookup(coucou_path_to_wd, pathname);
+ _wd = g_hash_table_lookup(vhffsfssync_path_to_wd, pathname);
// this wd has already been deleted
if(!_wd) return -1;
wd = *_wd;
@@ -713,33 +713,33 @@
#if DEBUG_INOTIFY
printf("- %d %s\n", wd, pathname);
#endif
- g_hash_table_remove(coucou_path_to_wd, pathname);
- g_hash_table_remove(coucou_wd_to_path, &wd);
- if(g_hash_table_size(coucou_wd_to_path) != g_hash_table_size(coucou_path_to_wd)) {
+ g_hash_table_remove(vhffsfssync_path_to_wd, pathname);
+ g_hash_table_remove(vhffsfssync_wd_to_path, &wd);
+ if(g_hash_table_size(vhffsfssync_wd_to_path) != g_hash_table_size(vhffsfssync_path_to_wd)) {
exit(-1);
}
return inotify_rm_watch(inotifyfd, wd);
}
-int coucou_modify_watch(int inotifyfd, const char *from, const char *to) {
+int vhffsfssync_modify_watch(int inotifyfd, const char *from, const char *to) {
int wd;
int *_wd;
char *_to;
- _wd = g_hash_table_lookup(coucou_path_to_wd, from);
+ _wd = g_hash_table_lookup(vhffsfssync_path_to_wd, from);
if(!_wd) return -1;
wd = *_wd;
- g_hash_table_remove(coucou_path_to_wd, from);
- g_hash_table_remove(coucou_wd_to_path, _wd);
+ g_hash_table_remove(vhffsfssync_path_to_wd, from);
+ g_hash_table_remove(vhffsfssync_wd_to_path, _wd);
_wd = g_new(int, 1);
*_wd = wd;
_to = strdup(to);
- g_hash_table_insert(coucou_wd_to_path, _wd, _to);
- g_hash_table_insert(coucou_path_to_wd, _to, _wd);
+ g_hash_table_insert(vhffsfssync_wd_to_path, _wd, _to);
+ g_hash_table_insert(vhffsfssync_path_to_wd, _to, _wd);
#if DEBUG_INOTIFY
printf("= %d %s -> %s\n", wd, from, to);
@@ -748,13 +748,13 @@
}
-int coucou_add_watch_recursively(int inotifyfd, const char *pathname, uint32_t mask) {
+int vhffsfssync_add_watch_recursively(int inotifyfd, const char *pathname, uint32_t mask) {
int wd;
DIR *d;
struct dirent *dir;
- wd = coucou_add_watch(inotifyfd, pathname, mask);
+ wd = vhffsfssync_add_watch(inotifyfd, pathname, mask);
if(wd < 0) return wd;
d = opendir(pathname);
@@ -765,7 +765,7 @@
char *sep = "/";
if( pathname[strlen(pathname)-1] == '/' ) sep = "";
path = g_strdup_printf("%s%s%s", pathname, sep, dir->d_name);
- wd = coucou_add_watch_recursively(inotifyfd, path, mask);
+ wd = vhffsfssync_add_watch_recursively(inotifyfd, path, mask);
free(path);
}
}
@@ -776,7 +776,7 @@
}
-int coucou_manage_event_remove(int inotifyfd, char *pathname) {
+int vhffsfssync_manage_event_remove(int inotifyfd, char *pathname) {
GList *conns;
int *_wd;
@@ -784,22 +784,22 @@
printf("==> REMOVE %s\n", pathname);
#endif
- if( (_wd = g_hash_table_lookup(coucou_path_to_wd, pathname)) ) {
- coucou_del_watch(inotifyfd, NULL, *_wd);
+ if( (_wd = g_hash_table_lookup(vhffsfssync_path_to_wd, pathname)) ) {
+ vhffsfssync_del_watch(inotifyfd, NULL, *_wd);
}
/* connections */
- for(conns = g_list_first(coucou_conns) ; conns ; ) {
- coucou_conn *conn = conns->data;
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
- coucou_net_remove_file(conn, pathname);
- coucou_net_send_string(conn, g_strdup_printf("remove\x1F%s\n", pathname) , COUCOU_NET_PRIO_MEDIUM);
+ vhffsfssync_net_remove_file(conn, pathname);
+ vhffsfssync_net_send_string(conn, g_strdup_printf("remove\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
return 0;
}
-int coucou_manage_event_create(int inotifyfd, char *pathname, gboolean sendfile) {
+int vhffsfssync_manage_event_create(int inotifyfd, char *pathname, gboolean sendfile) {
struct stat st;
if(! lstat(pathname, &st) ) {
@@ -808,9 +808,9 @@
#if DEBUG_INOTIFY
printf("==> CREATE %s\n", pathname);
#endif
- coucou_net_broadcast_string( g_strdup_printf("create\x1F%s\n", pathname) , COUCOU_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_string( g_strdup_printf("create\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
if(sendfile && st.st_size > 0) {
- coucou_net_broadcast_file(pathname);
+ vhffsfssync_net_broadcast_file(pathname);
}
}
@@ -818,11 +818,11 @@
#if DEBUG_INOTIFY
printf("==> MKDIR %s\n", pathname);
#endif
- coucou_add_watch(inotifyfd, pathname, COUCOU_WATCH_MASK);
- coucou_net_broadcast_string( g_strdup_printf("mkdir\x1F%s\n", pathname) , COUCOU_NET_PRIO_MEDIUM);
+ vhffsfssync_add_watch(inotifyfd, pathname, VHFFSFSSYNC_WATCH_MASK);
+ vhffsfssync_net_broadcast_string( g_strdup_printf("mkdir\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
/* there is a short delay between the mkdir() and the add_watch(),
we need to send events about the data which have already been written */
- coucou_fake_events_recursively( inotifyfd, pathname );
+ vhffsfssync_fake_events_recursively( inotifyfd, pathname );
}
else if( S_ISLNK(st.st_mode) ) {
@@ -835,13 +835,13 @@
#if DEBUG_INOTIFY
printf("==> SYMLINK %s -> %s\n", pathname, linkto);
#endif
- coucou_net_broadcast_string( g_strdup_printf("symlink\x1F%s\x1F%s\n", pathname, linkto) , COUCOU_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_string( g_strdup_printf("symlink\x1F%s\x1F%s\n", pathname, linkto) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
free(linkto);
if(ret < 0) {
if(errno == ENOENT) {
// file already disappeared (common for temporary files)
- coucou_manage_event_remove(inotifyfd, pathname);
+ vhffsfssync_manage_event_remove(inotifyfd, pathname);
} else {
fprintf(stderr, "cannot readlink() '%s': %s\n", pathname, strerror(errno));
return -1;
@@ -854,7 +854,7 @@
else {
if(errno == ENOENT) {
// file already disappeared (common for temporary files)
- coucou_manage_event_remove(inotifyfd, pathname);
+ vhffsfssync_manage_event_remove(inotifyfd, pathname);
} else {
fprintf(stderr, "cannot lstat() '%s': %s\n", pathname, strerror(errno));
return -1;
@@ -865,7 +865,7 @@
}
-int coucou_manage_event(int inotifyfd, struct inotify_event *event) {
+int vhffsfssync_manage_event(int inotifyfd, struct inotify_event *event) {
char *dirpath, *pathname;
#if DEBUG_INOTIFY
@@ -879,7 +879,7 @@
return -1;
}
- dirpath = (char*)g_hash_table_lookup(coucou_wd_to_path, &event->wd);
+ dirpath = (char*)g_hash_table_lookup(vhffsfssync_wd_to_path, &event->wd);
// this wd has been deleted
if(!dirpath) return -1;
@@ -890,11 +890,11 @@
}
// this event is not waiting for a cookie, delete file if necessary (IN_MOVED_FROM not followed with IN_MOVED_TO)
- if( !(event->mask & IN_MOVED_TO) && coucou_cookie.id ) {
+ if( !(event->mask & IN_MOVED_TO) && vhffsfssync_cookie.id ) {
- coucou_manage_event_remove(inotifyfd, coucou_cookie.from);
- coucou_cookie.id = 0;
- free(coucou_cookie.from);
+ vhffsfssync_manage_event_remove(inotifyfd, vhffsfssync_cookie.from);
+ vhffsfssync_cookie.id = 0;
+ free(vhffsfssync_cookie.from);
}
// useless at the moment (chmod, chown, touch, ...)
@@ -908,14 +908,14 @@
#if DEBUG_INOTIFY
printf("IN_CREATE\n");
#endif
- coucou_manage_event_create(inotifyfd, pathname, FALSE);
+ vhffsfssync_manage_event_create(inotifyfd, pathname, FALSE);
// deleted file, directory or symlink
} else if( event->mask & IN_DELETE ) {
#if DEBUG_INOTIFY
printf("IN_DELETE\n");
#endif
- coucou_manage_event_remove(inotifyfd, pathname);
+ vhffsfssync_manage_event_remove(inotifyfd, pathname);
// watch deleted, not used
} else if( event->mask & IN_DELETE_SELF ) {
@@ -927,7 +927,7 @@
// and we'll not receive a IN_DELETE_SELF for it
//
//implicit deletion (IN_IGNORED will follow this event)
- //coucou_del_watch(inotifyfd, event->wd);
+ //vhffsfssync_del_watch(inotifyfd, event->wd);
// file modified
} else if( event->mask & IN_MODIFY ) {
@@ -943,7 +943,7 @@
/* we must send the data here */
printf("==> SEND %s\n", pathname);
#endif
- coucou_net_broadcast_file(pathname);
+ vhffsfssync_net_broadcast_file(pathname);
// watch moved, not used
} else if( event->mask & IN_MOVE_SELF ) {
@@ -963,29 +963,29 @@
printf("IN_MOVED_FROM\n");
#endif
// set the cookie
- coucou_cookie.id = event->cookie;
- coucou_cookie.from = strdup(pathname);
- coucou_cookie.isdir = !!( event->mask & IN_ISDIR );
+ vhffsfssync_cookie.id = event->cookie;
+ vhffsfssync_cookie.from = strdup(pathname);
+ vhffsfssync_cookie.isdir = !!( event->mask & IN_ISDIR );
} else if( event->mask & IN_MOVED_TO ) {
#if DEBUG_INOTIFY
printf("IN_MOVED_TO\n");
#endif
// mv
- if(coucou_cookie.id == event->cookie) {
+ if(vhffsfssync_cookie.id == event->cookie) {
#if DEBUG_INOTIFY
- printf("==> MOVE %s -> %s (used cookie %d)\n", coucou_cookie.from, pathname, coucou_cookie.id);
+ printf("==> MOVE %s -> %s (used cookie %d)\n", vhffsfssync_cookie.from, pathname, vhffsfssync_cookie.id);
#endif
- if( coucou_cookie.isdir )
- coucou_modify_watch(inotifyfd, coucou_cookie.from, pathname);
+ if( vhffsfssync_cookie.isdir )
+ vhffsfssync_modify_watch(inotifyfd, vhffsfssync_cookie.from, pathname);
- coucou_net_broadcast_string( g_strdup_printf("move\x1F%s\x1F%s\n", coucou_cookie.from, pathname) , COUCOU_NET_PRIO_MEDIUM);
- coucou_cookie.id = 0;
- free(coucou_cookie.from);
+ vhffsfssync_net_broadcast_string( g_strdup_printf("move\x1F%s\x1F%s\n", vhffsfssync_cookie.from, pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_cookie.id = 0;
+ free(vhffsfssync_cookie.from);
}
// create
else {
- coucou_manage_event_create(inotifyfd, pathname, TRUE);
+ vhffsfssync_manage_event_create(inotifyfd, pathname, TRUE);
}
// watch deleted, clean it
@@ -993,7 +993,7 @@
#if DEBUG_INOTIFY
printf("IN_IGNORED\n");
#endif
- coucou_del_watch(inotifyfd, NULL, event->wd);
+ vhffsfssync_del_watch(inotifyfd, NULL, event->wd);
// this event is not handled, this should not happen
} else {
@@ -1007,7 +1007,7 @@
}
-int coucou_fake_events_recursively(int inotifyfd, char *pathname) {
+int vhffsfssync_fake_events_recursively(int inotifyfd, char *pathname) {
DIR *d;
struct dirent *dir;
@@ -1021,9 +1021,9 @@
if( pathname[strlen(pathname)-1] == '/' ) sep = "";
path = g_strdup_printf("%s%s%s", pathname, sep, dir->d_name);
- // recursivity is done through coucou_manage_event_create()
+ // recursivity is done through vhffsfssync_manage_event_create()
// which calls this function
- coucou_manage_event_create(inotifyfd, path, TRUE);
+ vhffsfssync_manage_event_create(inotifyfd, path, TRUE);
free(path);
}
}
@@ -1059,11 +1059,11 @@
/* -- inotify stuff -- */
- coucou_wd_to_path = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
- coucou_path_to_wd = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
- coucou_cookie.id = 0;
- coucou_cookie.from = NULL;
- coucou_openfiles = 0;
+ vhffsfssync_wd_to_path = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+ vhffsfssync_path_to_wd = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+ vhffsfssync_cookie.id = 0;
+ vhffsfssync_cookie.from = NULL;
+ vhffsfssync_openfiles = 0;
inotifyfd = inotify_init();
@@ -1074,7 +1074,7 @@
fcntl(inotifyfd, F_SETFL, flags);
}
- wd = coucou_add_watch_recursively(inotifyfd, root, COUCOU_WATCH_MASK);
+ wd = vhffsfssync_add_watch_recursively(inotifyfd, root, VHFFSFSSYNC_WATCH_MASK);
if(wd < 0) {
fprintf(stderr, "Maximum number of watches probably reached, consider adding more or fixing what is being wrong before running me again (strace is your friend)... byebye!\n");
return -1;
@@ -1082,7 +1082,7 @@
/* -- network stuff -- */
- coucou_conns = NULL;
+ vhffsfssync_conns = NULL;
signal(SIGPIPE, SIG_IGN);
@@ -1145,13 +1145,13 @@
if(listenfd > max_fd) max_fd = listenfd;
/* connections */
- for(conns = g_list_first(coucou_conns) ; conns ; ) {
- coucou_conn *conn = conns->data;
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
/* this connnection was disabled, destroy it */
if(conn->fd < 0) {
- coucou_net_conn_destroy(conn);
+ vhffsfssync_net_conn_destroy(conn);
continue;
}
@@ -1175,10 +1175,10 @@
if(ret > 0) {
/* inotify events */
if( FD_ISSET(inotifyfd, &readfs) ) {
- char buf[COUCOU_BUF_LEN];
+ char buf[VHFFSFSSYNC_BUF_LEN];
ssize_t len;
- len = read(inotifyfd, buf, COUCOU_BUF_LEN);
+ len = read(inotifyfd, buf, VHFFSFSSYNC_BUF_LEN);
if(len < 0) {
switch(errno) {
case EAGAIN:
@@ -1195,7 +1195,7 @@
struct inotify_event *ie;
ie = (struct inotify_event*)cur;
- coucou_manage_event( inotifyfd, ie );
+ vhffsfssync_manage_event( inotifyfd, ie );
next = sizeof(struct inotify_event);
next += ie->len;
len -= next;
@@ -1209,7 +1209,7 @@
struct sockaddr_in addr;
int newfd, flags;
socklen_t addr_len;
- coucou_conn *conn;
+ vhffsfssync_conn *conn;
//struct hostent *ent;
addr_len = sizeof(addr);
@@ -1240,7 +1240,7 @@
}
/* register the connection */
- conn = malloc(sizeof(coucou_conn));
+ conn = malloc(sizeof(vhffsfssync_conn));
conn->fd = newfd;
conn->sockaddr = addr;
conn->order = 0;
@@ -1251,52 +1251,52 @@
//conn->sendbuf_cur = 0;
//conn->sendbuf_size = 0;
conn->messages = NULL;
- coucou_conns = g_list_append(coucou_conns, conn);
+ vhffsfssync_conns = g_list_append(vhffsfssync_conns, conn);
#if DEBUG_NET
printf("Welcome %s ! (using fd %d)\n", inet_ntoa(conn->sockaddr.sin_addr), conn->fd);
#endif
- coucou_net_send_string(conn, strdup("hello\n"), COUCOU_NET_PRIO_HIGHEST);
+ vhffsfssync_net_send_string(conn, strdup("hello\n"), VHFFSFSSYNC_NET_PRIO_HIGHEST);
/*
grosbuf=malloc(10485760);
memset(grosbuf, 'A', 10485760);
- coucou_net_send_data(conn, grosbuf, 1048576, 3);
+ vhffsfssync_net_send_data(conn, grosbuf, 1048576, 3);
grosbuf=malloc(10485760);
memset(grosbuf, 'B', 10485760);
- coucou_net_send_data(conn, grosbuf, 1048576, 2);
+ vhffsfssync_net_send_data(conn, grosbuf, 1048576, 2);
grosbuf=malloc(10485760);
memset(grosbuf, 'C', 10485760);
- coucou_net_send_data(conn, grosbuf, 1048576, 1);
+ vhffsfssync_net_send_data(conn, grosbuf, 1048576, 1);
grosbuf=malloc(10485760);
memset(grosbuf, 'D', 10485760);
- coucou_net_send_data(conn, grosbuf, 1048576, 0);
+ vhffsfssync_net_send_data(conn, grosbuf, 1048576, 0);
*/
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 1);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 1);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
- //coucou_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
- //coucou_net_write(conn, "Salut!\n", strlen("Salut!\n"));
- //coucou_net_write(conn, grosbuf, 104857600);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 1);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 1);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 2);
+ //vhffsfssync_net_send_data(conn, strdup("Salut!\n"), strlen("Salut!\n"), 0);
+ //vhffsfssync_net_write(conn, "Salut!\n", strlen("Salut!\n"));
+ //vhffsfssync_net_write(conn, grosbuf, 104857600);
}
}
/* connections */
- for(conns = g_list_first(coucou_conns) ; conns ; ) {
- coucou_conn *conn = conns->data;
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
/* data to read ?, give give ! */
if( FD_ISSET(conn->fd, &readfs) ) {
- char buf[COUCOU_BUF_LEN];
+ char buf[VHFFSFSSYNC_BUF_LEN];
ssize_t len;
- len = read(conn->fd, buf, COUCOU_BUF_LEN);
+ len = read(conn->fd, buf, VHFFSFSSYNC_BUF_LEN);
if(len < 0) {
switch(errno) {
case EAGAIN:
@@ -1304,11 +1304,11 @@
break;
default:
fprintf(stderr, "read() failed on socket %d: %s\n", conn->fd, strerror(errno));
- coucou_net_conn_disable(conn);
+ vhffsfssync_net_conn_disable(conn);
}
}
else if(len == 0) {
- coucou_net_conn_disable(conn);
+ vhffsfssync_net_conn_disable(conn);
}
else {
char *plop = malloc(len+1);
@@ -1321,7 +1321,7 @@
/* try to send more data */
if(conn && conn->messages && FD_ISSET(conn->fd, &writefs) ) {
- coucou_net_send(conn);
+ vhffsfssync_net_send(conn);
}
}
}