#define FCE_FALSE 0\r
\r
/* We store our connection data here */\r
-static char coalesce[80] = {""};\r
+static uint32_t coalesce = 0;\r
static struct fce_history fce_history_list[FCE_HISTORY_LEN];\r
\r
-\r
-\r
-\r
/****\r
* With coalesce we try to reduce the events over UDP, the eventlistener would throw these \r
* events away anyway.\r
* event timeout. \r
* \r
****/\r
-static int coalesce_none()\r
-{\r
- return coalesce[0] == 0;\r
-}\r
-static int coalesce_all()\r
-{\r
- return !strcmp( coalesce, "all" );\r
-}\r
-static int coalesce_create()\r
-{\r
- return !strcmp( coalesce, "create" ) || coalesce_all();\r
-}\r
-static int coalesce_delete()\r
-{\r
- return !strcmp( coalesce, "delete" ) || coalesce_all();\r
-}\r
-\r
-void fce_initialize_history()\r
-{\r
- for (int i = 0; i < FCE_HISTORY_LEN; i++)\r
- {\r
- memset( &fce_history_list[i], 0, sizeof(fce_history_list[i]) );\r
- }\r
-}\r
\r
static long get_ms_difftime ( struct timeval *tv1, struct timeval *tv2 )\r
{\r
return s * 1000 + us/1000;\r
}\r
\r
-int fce_handle_coalescation( char *path, int is_dir, int mode )\r
-{\r
- if (coalesce_none())\r
- return FALSE;\r
-\r
- \r
+/******************************************************************************\r
+ * Public functions follow\r
+ ******************************************************************************/\r
\r
- // First one:\r
- // After a file creation *ALWAYS* a file modification is produced\r
- if (mode == FCE_FILE_CREATE)\r
- {\r
- if (coalesce_create())\r
- {\r
- return TRUE;\r
- }\r
+void fce_initialize_history()\r
+{\r
+ for (int i = 0; i < FCE_HISTORY_LEN; i++) {\r
+ memset( &fce_history_list[i], 0, sizeof(fce_history_list[i]) );\r
}\r
+}\r
\r
- /* get timestamp */\r
- struct timeval tv;\r
- gettimeofday(&tv, 0);\r
-\r
-\r
+int fce_handle_coalescation( char *path, int is_dir, int mode )\r
+{\r
/* These two are used to eval our next index in history */\r
/* the history is unsorted, speed should not be a problem, length is 10 */\r
unsigned long oldest_entry = (unsigned long )((long)-1);\r
int oldest_entry_idx = -1;\r
+ struct timeval tv;\r
+\r
+ if (coalesce == 0)\r
+ return FALSE;\r
+\r
+ /* After a file creation *ALWAYS* a file modification is produced */\r
+ if ((mode == FCE_FILE_CREATE) && (coalesce & FCE_COALESCE_CREATE))\r
+ return TRUE;\r
+\r
+ /* get timestamp */\r
+ gettimeofday(&tv, 0);\r
\r
/* Now detect events in the very near history */\r
- for (int i = 0; i < FCE_HISTORY_LEN; i++)\r
- {\r
+ for (int i = 0; i < FCE_HISTORY_LEN; i++) {\r
struct fce_history *fh = &fce_history_list[i];\r
\r
- //* Not inited ? */\r
- if (fh->tv.tv_sec == 0)\r
- {\r
+ /* Not inited ? */\r
+ if (fh->tv.tv_sec == 0) {\r
/* we can use it for new elements */\r
oldest_entry = 0;\r
oldest_entry_idx = i;\r
continue;\r
}\r
\r
- //* Too old ? */\r
- if (get_ms_difftime( &fh->tv, &tv ) > MAX_COALESCE_TIME_MS)\r
- {\r
+ /* Too old ? */\r
+ if (get_ms_difftime( &fh->tv, &tv ) > MAX_COALESCE_TIME_MS) {\r
/* Invalidate entry */\r
fh->tv.tv_sec = 0;\r
-\r
oldest_entry = 0;\r
oldest_entry_idx = i; \r
continue;\r
\r
\r
/* If we find a parent dir wich was created we are done */\r
- if (coalesce_create() && fh->mode == FCE_DIR_CREATE)\r
- {\r
- //* Parent dir ? */\r
- if (!strncmp( fh->path, path, strlen( fh->path ) ) )\r
- {\r
+ if ((coalesce & FCE_COALESCE_CREATE) && (fh->mode == FCE_DIR_CREATE)) {\r
+ /* Parent dir ? */\r
+ if (!strncmp(fh->path, path, strlen(fh->path)))\r
return TRUE;\r
- }\r
}\r
\r
/* If we find a parent dir we should be DELETED we are done */\r
- if (coalesce_delete() && fh->is_dir && (mode == FCE_FILE_DELETE || mode == FCE_DIR_DELETE))\r
- {\r
- //* Parent dir ? */\r
- if (!strncmp( fh->path, path, strlen( fh->path ) ) )\r
- {\r
+ if ((coalesce & FCE_COALESCE_DELETE)\r
+ && fh->is_dir\r
+ && (mode == FCE_FILE_DELETE || mode == FCE_DIR_DELETE)) {\r
+ /* Parent dir ? */\r
+ if (!strncmp(fh->path, path, strlen(fh->path)))\r
return TRUE;\r
- }\r
}\r
\r
- //* Detect oldest entry for next new entry */\r
- if (oldest_entry_idx == -1 || fh->tv.tv_sec < oldest_entry)\r
- {\r
+ /* Detect oldest entry for next new entry */\r
+ if (oldest_entry_idx == -1 || fh->tv.tv_sec < oldest_entry) {\r
oldest_entry = fh->tv.tv_sec;\r
oldest_entry_idx = i;\r
}\r
}\r
\r
/*\r
- *\r
* Set event coalescation to reduce number of events sent over UDP \r
* all|delete|create\r
- *\r
- *\r
- * */\r
+ */\r
\r
-int fce_set_coalesce( char *coalesce_opt )\r
+int fce_set_coalesce(char *opt)\r
{\r
- strncpy( coalesce, coalesce_opt, sizeof(coalesce) - 1 ); \r
+ char *e;\r
+ char *p;\r
+ \r
+ if (opt == NULL)\r
+ return AFPERR_PARAM;\r
+\r
+ e = strdup(opt);\r
+\r
+ for (p = strtok(e, ","); p; p = strtok(NULL, ",")) {\r
+ if (strcmp(p, "all") == 0) {\r
+ coalesce = FCE_COALESCE_ALL;\r
+ } else if (strcmp(p, "delete") == 0) {\r
+ coalesce = FCE_COALESCE_DELETE;\r
+ } else if (strcmp(p, "create") == 0) {\r
+ coalesce = FCE_COALESCE_CREATE;\r
+ }\r
+ }\r
+\r
+ free(e);\r
}\r
\r
\r