X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=etc%2Fafpd%2Ffce_api.c;h=c2afc82f0dc2f5512b3b8d8604370e6630a4648c;hp=5c295c60e649ebb9b1367d7e0ed36e7ff43f5998;hb=f10a98003962ce2f731081a4796871172aa6aaee;hpb=5bc10701fe3992bc08ab1a265265ebca5a9fd472 diff --git a/etc/afpd/fce_api.c b/etc/afpd/fce_api.c index 5c295c60..c2afc82f 100644 --- a/etc/afpd/fce_api.c +++ b/etc/afpd/fce_api.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2010 Mark Williams + * Copyright (c) 2012 Frank Lahm * * File change event API for netatalk * @@ -29,15 +30,12 @@ #include #include #include - - #include #include #include #include #include - -#include +#include #include #include @@ -58,30 +56,43 @@ // ONLY USED IN THIS FILE #include "fce_api_internal.h" -#define FCE_TRUE 1 -#define FCE_FALSE 0 +extern int afprun_bg(int root, char *cmd); /* We store our connection data here */ static struct udp_entry udp_socket_list[FCE_MAX_UDP_SOCKS]; static int udp_sockets = 0; -static int udp_initialized = FCE_FALSE; +static bool udp_initialized = false; static unsigned long fce_ev_enabled = (1 << FCE_FILE_MODIFY) | (1 << FCE_FILE_DELETE) | (1 << FCE_DIR_DELETE) | (1 << FCE_FILE_CREATE) | - (1 << FCE_DIR_CREATE); + (1 << FCE_DIR_CREATE) | + (1 << FCE_FILE_MOVE) | + (1 << FCE_DIR_MOVE) | + (1 << FCE_LOGIN) | + (1 << FCE_LOGOUT); -static uint64_t tm_used; /* used for passing to event handler */ -#define MAXIOBUF 1024 -static char iobuf[MAXIOBUF]; -static const char *skip_files[] = -{ - ".DS_Store", - NULL -}; +static uint8_t fce_ev_info; /* flags of additional info to send in events */ + +#define MAXIOBUF 4096 +static unsigned char iobuf[MAXIOBUF]; +static const char **skip_files; static struct fce_close_event last_close_event; +static char *fce_event_names[] = { + "", + "FCE_FILE_MODIFY", + "FCE_FILE_DELETE", + "FCE_DIR_DELETE", + "FCE_FILE_CREATE", + "FCE_DIR_CREATE", + "FCE_FILE_MOVE", + "FCE_DIR_MOVE", + "FCE_LOGIN", + "FCE_LOGOUT" +}; + /* * * Initialize network structs for any listeners @@ -93,7 +104,7 @@ void fce_init_udp() int rv; struct addrinfo hints, *servinfo, *p; - if (udp_initialized == FCE_TRUE) + if (udp_initialized == true) return; memset(&hints, 0, sizeof hints); @@ -108,7 +119,7 @@ void fce_init_udp() close(udp_entry->sock); if ((rv = getaddrinfo(udp_entry->addr, udp_entry->port, &hints, &servinfo)) != 0) { - LOG(log_error, logtype_afpd, "fce_init_udp: getaddrinfo(%s:%s): %s", + LOG(log_error, logtype_fce, "fce_init_udp: getaddrinfo(%s:%s): %s", udp_entry->addr, udp_entry->port, gai_strerror(rv)); continue; } @@ -116,7 +127,7 @@ void fce_init_udp() /* loop through all the results and make a socket */ for (p = servinfo; p != NULL; p = p->ai_next) { if ((udp_entry->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { - LOG(log_error, logtype_afpd, "fce_init_udp: socket(%s:%s): %s", + LOG(log_error, logtype_fce, "fce_init_udp: socket(%s:%s): %s", udp_entry->addr, udp_entry->port, strerror(errno)); continue; } @@ -124,7 +135,7 @@ void fce_init_udp() } if (p == NULL) { - LOG(log_error, logtype_afpd, "fce_init_udp: no socket for %s:%s", + LOG(log_error, logtype_fce, "fce_init_udp: no socket for %s:%s", udp_entry->addr, udp_entry->port); } udp_entry->addrinfo = *p; @@ -133,12 +144,12 @@ void fce_init_udp() freeaddrinfo(servinfo); } - udp_initialized = FCE_TRUE; + udp_initialized = true; } void fce_cleanup() { - if (udp_initialized == FCE_FALSE ) + if (udp_initialized == false ) return; for (int i = 0; i < udp_sockets; i++) @@ -152,114 +163,207 @@ void fce_cleanup() udp_entry->sock = -1; } } - udp_initialized = FCE_FALSE; + udp_initialized = false; } - /* * Construct a UDP packet for our listeners and return packet size * */ -static ssize_t build_fce_packet( struct fce_packet *packet, char *path, int mode, uint32_t event_id ) +static ssize_t build_fce_packet(const AFPObj *obj, + char *iobuf, + fce_ev_t event, + const char *path, + const char *oldpath, + pid_t pid, + const char *user, + uint32_t event_id) { + char *p = iobuf; size_t pathlen; - ssize_t data_len = 0; + ssize_t datalen = 0; + uint16_t uint16; + uint32_t uint32; + uint64_t uint64; + uint8_t packet_info = fce_ev_info; + + /* FCE magic */ + memcpy(p, FCE_PACKET_MAGIC, 8); + p += 8; + datalen += 8; + + /* version */ + *p = FCE_PACKET_VERSION; + p += 1; + datalen += 1; + + /* optional: options */ + if (FCE_PACKET_VERSION > 1) { + if (oldpath) + packet_info |= FCE_EV_INFO_SRCPATH; + *p = packet_info; + p += 1; + datalen += 1; + } - strncpy(packet->magic, FCE_PACKET_MAGIC, sizeof(packet->magic) ); - packet->version = FCE_PACKET_VERSION; - packet->mode = mode; - packet->event_id = event_id; + /* event */ + *p = event; + p += 1; + datalen += 1; - pathlen = strlen(path) + 1; /* include string terminator */ + /* optional: padding */ + if (FCE_PACKET_VERSION > 1) { + p += 1; + datalen += 1; + } - /* This should never happen, but before we bust this server, we send nonsense, fce listener has to cope */ - if (pathlen >= MAXPATHLEN) - pathlen = MAXPATHLEN - 1; + /* optional: reserved */ + if (FCE_PACKET_VERSION > 1) { + p += 8; + datalen += 8; + } - /* This is the payload len. Means: the stream has len bytes more until packet is finished */ - /* A server should read the first 16 byte, decode them and then fetch the rest */ - data_len = FCE_PACKET_HEADER_SIZE + pathlen; - packet->datalen = pathlen; + /* event ID */ + uint32 = htonl(event_id); + memcpy(p, &uint32, sizeof(uint32)); + p += sizeof(uint32); + datalen += sizeof(uint32); + + /* optional: pid */ + if (packet_info & FCE_EV_INFO_PID) { + uint64 = pid; + uint64 = hton64(uint64); + memcpy(p, &uint64, sizeof(uint64)); + p += sizeof(uint64); + datalen += sizeof(uint64); + } - switch (mode) { - case FCE_TM_SIZE: - tm_used = hton64(tm_used); - memcpy(packet->data, &tm_used, sizeof(tm_used)); - strncpy(packet->data + sizeof(tm_used), path, pathlen); + /* optional: username */ + if (packet_info & FCE_EV_INFO_USER) { + uint16 = strlen(user); + uint16 = htons(uint16); + memcpy(p, &uint16, sizeof(uint16)); + p += sizeof(uint16); + datalen += sizeof(uint16); + memcpy(p, user, strlen(user)); + p += strlen(user); + datalen += strlen(user); + } - packet->datalen += sizeof(tm_used); - data_len += sizeof(tm_used); - break; - default: - strncpy(packet->data, path, pathlen); - break; + /* path */ + if ((pathlen = strlen(path)) >= MAXPATHLEN) + pathlen = MAXPATHLEN - 1; + uint16 = pathlen; + uint16 = htons(uint16); + memcpy(p, &uint16, sizeof(uint16)); + p += sizeof(uint16); + datalen += sizeof(uint16); + memcpy(p, path, pathlen); + p += pathlen; + datalen += pathlen; + + /* optional: source path */ + if (packet_info & FCE_EV_INFO_SRCPATH) { + if ((pathlen = strlen(oldpath)) >= MAXPATHLEN) + pathlen = MAXPATHLEN - 1; + uint16 = pathlen; + uint16 = htons(uint16); + memcpy(p, &uint16, sizeof(uint16)); + p += sizeof(uint16); + datalen += sizeof(uint16); + memcpy(p, oldpath, pathlen); + p += pathlen; + datalen += pathlen; } /* return the packet len */ - return data_len; -} - -static int pack_fce_packet(struct fce_packet *packet, unsigned char *buf) -{ - unsigned char *p = buf; - - memcpy(p, &packet->magic[0], sizeof(packet->magic)); - p += sizeof(packet->magic); - - *p = packet->version; - p++; - - *p = packet->mode; - p++; - - uint32_t id = htonl(packet->event_id); - memcpy(p, &id, sizeof(id)); - p += sizeof(packet->event_id); - - uint16_t l = htons(packet->datalen); - memcpy(p, &l, sizeof(l)); - p += sizeof(l); - - memcpy(p, &packet->data[0], packet->datalen); - p += packet->datalen; - - return 0; + return datalen; } /* * Send the fce information to all (connected) listeners * We dont give return code because all errors are handled internally (I hope..) * */ -static void send_fce_event( char *path, int mode ) +static void send_fce_event(const AFPObj *obj, int event, const char *path, const char *oldpath) { - static int first_event = FCE_TRUE; - - struct fce_packet packet; - void *data = &packet; + static bool first_event = true; static uint32_t event_id = 0; /* the unique packet couter to detect packet/data loss. Going from 0xFFFFFFFF to 0x0 is a valid increment */ + static char *user; time_t now = time(NULL); - - LOG(log_debug, logtype_afpd, "send_fce_event: start"); + ssize_t data_len; /* initialized ? */ - if (first_event == FCE_TRUE) { - first_event = FCE_FALSE; + if (first_event == true) { + first_event = false; + + struct passwd *pwd = getpwuid(obj->uid); + user = strdup(pwd->pw_name); + + switch (obj->fce_version) { + case 1: + /* fce_ev_info unused */ + break; + case 2: + fce_ev_info = FCE_EV_INFO_PID | FCE_EV_INFO_USER; + break; + default: + fce_ev_info = 0; + LOG(log_error, logtype_fce, "Unsupported FCE protocol version %d", obj->fce_version); + break; + } + fce_init_udp(); /* Notify listeners the we start from the beginning */ - send_fce_event( "", FCE_CONN_START ); + send_fce_event(obj, FCE_CONN_START, "", NULL); } - /* build our data packet */ - ssize_t data_len = build_fce_packet( &packet, path, mode, ++event_id ); - pack_fce_packet(&packet, iobuf); + /* run script */ + if (obj->fce_notify_script) { + static bstring quote = NULL; + static bstring quoterep = NULL; + static bstring slash = NULL; + static bstring slashrep = NULL; + + if (!quote) { + quote = bfromcstr("'"); + quoterep = bfromcstr("'\\''"); + slash = bfromcstr("\\"); + slashrep = bfromcstr("\\\\"); + } + + bstring cmd = bformat("%s -v %d -e %s -i %" PRIu32 "", + obj->fce_notify_script, + FCE_PACKET_VERSION, + fce_event_names[event], + event_id); + + if (path[0]) { + bstring bpath = bfromcstr(path); + bfindreplace(bpath, slash, slashrep, 0); + bfindreplace(bpath, quote, quoterep, 0); + bformata(cmd, " -P '%s'", bdata(bpath)); + bdestroy(bpath); + } + if (fce_ev_info | FCE_EV_INFO_PID) + bformata(cmd, " -p %" PRIu64 "", (uint64_t)getpid()); + if (fce_ev_info | FCE_EV_INFO_USER) + bformata(cmd, " -u %s", user); + if (oldpath) { + bstring boldpath = bfromcstr(oldpath); + bfindreplace(boldpath, slash, slashrep, 0); + bfindreplace(boldpath, quote, quoterep, 0); + bformata(cmd, " -S '%s'", bdata(boldpath)); + bdestroy(boldpath); + } + (void)afprun_bg(1, bdata(cmd)); + bdestroy(cmd); + } - for (int i = 0; i < udp_sockets; i++) - { + for (int i = 0; i < udp_sockets; i++) { int sent_data = 0; struct udp_entry *udp_entry = udp_socket_list + i; /* we had a problem earlier ? */ - if (udp_entry->sock == -1) - { + if (udp_entry->sock == -1) { /* We still have to wait ?*/ if (now < udp_entry->next_try_on_error) continue; @@ -271,7 +375,7 @@ static void send_fce_event( char *path, int mode ) if (udp_entry->sock == -1) { /* failed again, so go to rest again */ - LOG(log_error, logtype_afpd, "Cannot recreate socket for fce UDP connection: errno %d", errno ); + LOG(log_error, logtype_fce, "Cannot recreate socket for fce UDP connection: errno %d", errno ); udp_entry->next_try_on_error = now + FCE_SOCKET_RETRY_DELAY_S; continue; @@ -280,8 +384,7 @@ static void send_fce_event( char *path, int mode ) udp_entry->next_try_on_error = 0; /* Okay, we have a running socket again, send server that we had a problem on our side*/ - data_len = build_fce_packet( &packet, "", FCE_CONN_BROKEN, 0 ); - pack_fce_packet(&packet, iobuf); + data_len = build_fce_packet(obj, iobuf, FCE_CONN_BROKEN, "", NULL, getpid(), user, 0); sendto(udp_entry->sock, iobuf, @@ -289,12 +392,11 @@ static void send_fce_event( char *path, int mode ) 0, (struct sockaddr *)&udp_entry->sockaddr, udp_entry->addrinfo.ai_addrlen); - - /* Rebuild our original data packet */ - data_len = build_fce_packet( &packet, path, mode, event_id ); - pack_fce_packet(&packet, iobuf); } + /* build our data packet */ + data_len = build_fce_packet(obj, iobuf, event, path, oldpath, getpid(), user, event_id); + sent_data = sendto(udp_entry->sock, iobuf, data_len, @@ -305,7 +407,7 @@ static void send_fce_event( char *path, int mode ) /* Problems ? */ if (sent_data != data_len) { /* Argh, socket broke, we close and retry later */ - LOG(log_error, logtype_afpd, "send_fce_event: error sending packet to %s:%s, transfered %d of %d: %s", + LOG(log_error, logtype_fce, "send_fce_event: error sending packet to %s:%s, transfered %d of %d: %s", udp_entry->addr, udp_entry->port, sent_data, data_len, strerror(errno)); close( udp_entry->sock ); @@ -313,6 +415,8 @@ static void send_fce_event( char *path, int mode ) udp_entry->next_try_on_error = now + FCE_SOCKET_RETRY_DELAY_S; } } + + event_id++; } static int add_udp_socket(const char *target_ip, const char *target_port ) @@ -321,7 +425,7 @@ static int add_udp_socket(const char *target_ip, const char *target_port ) target_port = FCE_DEFAULT_PORT_STRING; if (udp_sockets >= FCE_MAX_UDP_SOCKS) { - LOG(log_error, logtype_afpd, "Too many file change api UDP connections (max %d allowed)", FCE_MAX_UDP_SOCKS ); + LOG(log_error, logtype_fce, "Too many file change api UDP connections (max %d allowed)", FCE_MAX_UDP_SOCKS ); return AFPERR_PARAM; } @@ -337,7 +441,7 @@ static int add_udp_socket(const char *target_ip, const char *target_port ) return AFP_OK; } -static void save_close_event(const char *path) +static void save_close_event(const AFPObj *obj, const char *path) { time_t now = time(NULL); @@ -345,92 +449,105 @@ static void save_close_event(const char *path) if (last_close_event.time /* is there any saved event ? */ && (strcmp(path, last_close_event.path) != 0)) { /* no, so send the saved event out now */ - send_fce_event(last_close_event.path, FCE_FILE_MODIFY); + send_fce_event(obj, FCE_FILE_MODIFY,last_close_event.path, NULL); } - LOG(log_debug, logtype_afpd, "save_close_event: %s", path); + LOG(log_debug, logtype_fce, "save_close_event: %s", path); last_close_event.time = now; strncpy(last_close_event.path, path, MAXPATHLEN); } +static void fce_init_ign_names(const char *ignores) +{ + int count = 0; + char *names = strdup(ignores); + char *p; + int i = 0; + + while (names[i]) { + count++; + for (; names[i] && names[i] != '/'; i++) + ; + if (!names[i]) + break; + i++; + } + + skip_files = calloc(count + 1, sizeof(char *)); + + for (i = 0, p = strtok(names, "/"); p ; p = strtok(NULL, "/")) + skip_files[i++] = strdup(p); + + free(names); +} + /* * * Dispatcher for all incoming file change events * * */ -static int register_fce(const char *u_name, int is_dir, int mode) +int fce_register(const AFPObj *obj, fce_ev_t event, const char *path, const char *oldpath) { - static int first_event = FCE_TRUE; + static bool first_event = true; + const char *bname; - if (udp_sockets == 0) - /* No listeners configured */ + if (!(fce_ev_enabled & (1 << event))) return AFP_OK; - if (u_name == NULL) - return AFPERR_PARAM; + AFP_ASSERT(event >= FCE_FIRST_EVENT && event <= FCE_LAST_EVENT); + AFP_ASSERT(path); + + LOG(log_debug, logtype_fce, "register_fce(path: %s, event: %s)", + path, fce_event_names[event]); + + bname = basename_safe(path); + + if ((udp_sockets == 0) && (obj->fce_notify_script == NULL)) { + /* No listeners configured */ + return AFP_OK; + } /* do some initialization on the fly the first time */ if (first_event) { fce_initialize_history(); - first_event = FCE_FALSE; + fce_init_ign_names(obj->fce_ign_names); + first_event = false; } /* handle files which should not cause events (.DS_Store atc. ) */ - for (int i = 0; skip_files[i] != NULL; i++) - { - if (!strcmp( u_name, skip_files[i])) + for (int i = 0; skip_files[i] != NULL; i++) { + if (strcmp(bname, skip_files[i]) == 0) return AFP_OK; } - - char full_path_buffer[MAXPATHLEN + 1] = {""}; - const char *cwd = getcwdpath(); - - if (mode == FCE_TM_SIZE) { - strlcpy(full_path_buffer, u_name, MAXPATHLEN); - } else if (!is_dir || mode == FCE_DIR_DELETE) { - if (strlen( cwd ) + strlen( u_name) + 1 >= MAXPATHLEN) { - LOG(log_error, logtype_afpd, "FCE file name too long: %s/%s", cwd, u_name ); - return AFPERR_PARAM; - } - sprintf( full_path_buffer, "%s/%s", cwd, u_name ); - } else { - if (strlen( cwd ) >= MAXPATHLEN) { - LOG(log_error, logtype_afpd, "FCE directory name too long: %s", cwd); - return AFPERR_PARAM; - } - strcpy( full_path_buffer, cwd); - } - /* Can we ignore this event based on type or history? */ - if (!(mode & FCE_TM_SIZE) && fce_handle_coalescation( full_path_buffer, is_dir, mode )) - { - LOG(log_debug9, logtype_afpd, "Coalesced fc event <%d> for <%s>", mode, full_path_buffer ); + if (fce_handle_coalescation(event, path)) { + LOG(log_debug9, logtype_fce, "Coalesced fc event <%d> for <%s>", event, path); return AFP_OK; } - LOG(log_debug9, logtype_afpd, "Detected fc event <%d> for <%s>", mode, full_path_buffer ); - - if (mode & FCE_FILE_MODIFY) { - save_close_event(full_path_buffer); - return AFP_OK; + switch (event) { + case FCE_FILE_MODIFY: + save_close_event(obj, path); + break; + default: + send_fce_event(obj, event, path, oldpath); + break; } - send_fce_event( full_path_buffer, mode ); - return AFP_OK; } -static void check_saved_close_events(int fmodwait) +static void check_saved_close_events(const AFPObj *obj) { time_t now = time(NULL); /* check if configured holdclose time has passed */ - if (last_close_event.time && ((last_close_event.time + fmodwait) < now)) { - LOG(log_debug, logtype_afpd, "check_saved_close_events: sending event: %s", last_close_event.path); + if (last_close_event.time && ((last_close_event.time + obj->options.fce_fmodwait) < now)) { + LOG(log_debug, logtype_fce, "check_saved_close_events: sending event: %s", last_close_event.path); /* yes, send event */ - send_fce_event(&last_close_event.path[0], FCE_FILE_MODIFY); + send_fce_event(obj, FCE_FILE_MODIFY, &last_close_event.path[0], NULL); last_close_event.path[0] = 0; last_close_event.time = 0; } @@ -441,114 +558,12 @@ static void check_saved_close_events(int fmodwait) /* * API-Calls for file change api, called form outside (file.c directory.c ofork.c filedir.c) * */ -#ifndef FCE_TEST_MAIN - -void fce_pending_events(AFPObj *obj) +void fce_pending_events(const AFPObj *obj) { - vol_fce_tm_event(); - check_saved_close_events(obj->options.fce_fmodwait); -} - -int fce_register_delete_file( struct path *path ) -{ - int ret = AFP_OK; - - if (path == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_FILE_DELETE))) - return ret; - - ret = register_fce( path->u_name, false, FCE_FILE_DELETE ); - - return ret; -} -int fce_register_delete_dir( char *name ) -{ - int ret = AFP_OK; - - if (name == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_DIR_DELETE))) - return ret; - - ret = register_fce( name, true, FCE_DIR_DELETE); - - return ret; -} - -int fce_register_new_dir( struct path *path ) -{ - int ret = AFP_OK; - - if (path == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_DIR_CREATE))) - return ret; - - ret = register_fce( path->u_name, true, FCE_DIR_CREATE ); - - return ret; -} - - -int fce_register_new_file( struct path *path ) -{ - int ret = AFP_OK; - - if (path == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_FILE_CREATE))) - return ret; - - ret = register_fce( path->u_name, false, FCE_FILE_CREATE ); - - return ret; -} - -int fce_register_file_modification( struct ofork *ofork ) -{ - char *u_name = NULL; - struct vol *vol; - int ret = AFP_OK; - - if (ofork == NULL || ofork->of_vol == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_FILE_MODIFY))) - return ret; - - vol = ofork->of_vol; - - if (NULL == (u_name = mtoupath(vol, of_name(ofork), ofork->of_did, utf8_encoding()))) - { - return AFPERR_MISC; - } - - ret = register_fce( u_name, false, FCE_FILE_MODIFY ); - - return ret; -} - -int fce_register_tm_size(const char *vol, size_t used) -{ - int ret = AFP_OK; - - if (vol == NULL) - return AFPERR_PARAM; - - if (!(fce_ev_enabled & (1 << FCE_TM_SIZE))) - return ret; - - tm_used = used; /* oh what a hack */ - ret = register_fce(vol, false, FCE_TM_SIZE); - - return ret; + if (!udp_sockets) + return; + check_saved_close_events(obj); } -#endif /* * @@ -582,7 +597,7 @@ int fce_set_events(const char *events) fce_ev_enabled = 0; - for (p = strtok(e, ","); p; p = strtok(NULL, ",")) { + for (p = strtok(e, ", "); p; p = strtok(NULL, ", ")) { if (strcmp(p, "fmod") == 0) { fce_ev_enabled |= (1 << FCE_FILE_MODIFY); } else if (strcmp(p, "fdel") == 0) { @@ -593,91 +608,18 @@ int fce_set_events(const char *events) fce_ev_enabled |= (1 << FCE_FILE_CREATE); } else if (strcmp(p, "dcre") == 0) { fce_ev_enabled |= (1 << FCE_DIR_CREATE); - } else if (strcmp(p, "tmsz") == 0) { - fce_ev_enabled |= (1 << FCE_TM_SIZE); + } else if (strcmp(p, "fmov") == 0) { + fce_ev_enabled |= (1 << FCE_FILE_MOVE); + } else if (strcmp(p, "dmov") == 0) { + fce_ev_enabled |= (1 << FCE_DIR_MOVE); + } else if (strcmp(p, "login") == 0) { + fce_ev_enabled |= (1 << FCE_LOGIN); + } else if (strcmp(p, "logout") == 0) { + fce_ev_enabled |= (1 << FCE_LOGOUT); } } free(e); -} - -#ifdef FCE_TEST_MAIN - -void shortsleep( unsigned int us ) -{ - usleep( us ); -} -int main( int argc, char*argv[] ) -{ - int c,ret; - - char *port = FCE_DEFAULT_PORT_STRING; - char *host = "localhost"; - int delay_between_events = 1000; - int event_code = FCE_FILE_MODIFY; - char pathbuff[1024]; - int duration_in_seconds = 0; // TILL ETERNITY - char target[256]; - char *path = getcwd( pathbuff, sizeof(pathbuff) ); - - // FULLSPEED TEST IS "-s 1001" -> delay is 0 -> send packets without pause - - while ((c = getopt(argc, argv, "d:e:h:p:P:s:")) != -1) { - switch(c) { - case '?': - fprintf(stdout, "%s: [ -p Port -h Listener1 [ -h Listener2 ...] -P path -s Delay_between_events_in_us -e event_code -d Duration ]\n", argv[0]); - exit(1); - break; - case 'd': - duration_in_seconds = atoi(optarg); - break; - case 'e': - event_code = atoi(optarg); - break; - case 'h': - host = strdup(optarg); - break; - case 'p': - port = strdup(optarg); - break; - case 'P': - path = strdup(optarg); - break; - case 's': - delay_between_events = atoi(optarg); - break; - } - } - - sprintf(target, "%s:%s", host, port); - if (fce_add_udp_socket(target) != 0) - return 1; - - int ev_cnt = 0; - time_t start_time = time(NULL); - time_t end_time = 0; - - if (duration_in_seconds) - end_time = start_time + duration_in_seconds; - - while (1) - { - time_t now = time(NULL); - if (now > start_time) - { - start_time = now; - fprintf( stdout, "%d events/s\n", ev_cnt ); - ev_cnt = 0; - } - if (end_time && now >= end_time) - break; - - register_fce( path, 0, event_code ); - ev_cnt++; - - - shortsleep( delay_between_events ); - } + return AFP_OK; } -#endif /* TESTMAIN*/