/* * * Dispatcher for all incoming file change events * * */ static int register_fce(const char *u_name, int is_dir, int mode) { if (udp_sockets == 0) /* No listeners configured */ return AFP_OK; if (u_name == NULL) return AFPERR_PARAM; static int first_event = FCE_TRUE; /* do some initialization on the fly the first time */ if (first_event) { fce_initialize_history(); } /* 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])) 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 ); return AFP_OK; } LOG(log_debug9, logtype_afpd, "Detected fc event <%d> for <%s>", mode, full_path_buffer ); /* we do initilization on the fly, no blocking calls in here * (except when using FQDN in broken DNS environment) */ if (first_event == FCE_TRUE) { fce_init_udp(); /* Notify listeners the we start from the beginning */ send_fce_event( "", FCE_CONN_START ); first_event = FCE_FALSE; } /* Handle UDP transport */ send_fce_event( full_path_buffer, mode ); return AFP_OK; }
/* * * Dispatcher for all incoming file change events * * */ static int register_fce(const char *u_name, int is_dir, int mode) { static int first_event = FCE_TRUE; if (udp_sockets == 0) /* No listeners configured */ return AFP_OK; if (u_name == NULL) return AFPERR_PARAM; /* do some initialization on the fly the first time */ if (first_event) { fce_initialize_history(); first_event = FCE_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])) 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 ); 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; } send_fce_event( full_path_buffer, mode ); return AFP_OK; }