Added parenthesis to silence warning caused by setting variable in an if-statement. Added some inline documentation to explain the purpose of the actions feature and how to use it.

pull/111/head
Micah Snyder 7 years ago
parent ae3aede6ff
commit 04c12bd67d
  1. 12
      shared/actions.c
  2. 20
      shared/actions.h

@ -4,6 +4,12 @@
*
* Author: aCaB
*
* These functions are actions that may be taken when a sample alerts.
* The user may wish to:
* - move file to destination directory.
* - copy file to destination directory.
* - remove (delete) the file.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
@ -83,7 +89,7 @@ static void action_move(const char *filename)
char *nuname;
int fd = getdest(filename, &nuname), copied = 0;
if (fd < 0 || (rename(filename, nuname) && (copied = 1) && filecopy(filename, nuname))) {
if (fd < 0 || (rename(filename, nuname) && ((copied = 1)) && filecopy(filename, nuname))) {
logg("!Can't move file %s\n", filename);
notmoved++;
if (nuname) unlink(nuname);
@ -134,6 +140,10 @@ static int isdir(void)
return 1;
}
/*
* Call this function at the beginning to configure the user preference.
* Later, call the "action" callback function to perform the selection action.
*/
int actsetup(const struct optstruct *opts)
{
int move = optget(opts, "move")->enabled;

@ -4,6 +4,12 @@
*
* Authors: aCaB
*
* These functions are actions that may be taken when a sample alerts.
* The user may wish to:
* - move file to destination directory.
* - copy file to destination directory.
* - remove (delete) the file.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
@ -24,8 +30,22 @@
#include "shared/optparser.h"
/**
* @brief Callback function to perform the action requested when actsetup() was invoked.
*
* @param filename
*/
extern void (*action)(const char *);
/**
* @brief Select the appropriate callback function based on the configuration options.
*
* @param opts Application configuration options.
* @return int 0 if success.
* @return int 1 if move or copy were selected but the destination directory does not exist.
*/
int actsetup(const struct optstruct *opts);
extern unsigned int notremoved, notmoved;
#endif

Loading…
Cancel
Save