#include "dnxPlugin.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "pfopen.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <poll.h>
Go to the source code of this file.
Data Structures | |
struct | iDnxModule |
The DNX module implementation data structure. More... | |
struct | iDnxPlugin |
The DNX plugin implementation data structure. More... | |
struct | DnxPlugin |
An abstract data type for a DNX plugin object. More... | |
struct | DnxModule |
An abstract data type for a DNX module object. More... | |
Defines | |
#define | USE_POLL |
#define | MPLEXER "poll" |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
#define | MAX_PLUGIN_PREFIX 1024 |
The maximum plugin prefix. | |
#define | MAX_PLUGIN_PATH 2048 |
The maximum plugin path. | |
#define | DNX_MAX_ARGV 256 |
The maximum number of arguments. | |
#define | MAX_INPUT_BUFFER 1024 |
The maximum input buffer. | |
#define | DNX_MAX_PLUGIN_NAME 255 |
The maximum plugin name length. | |
Functions | |
static char * | dnxFgets (char *data, int size, FILE *fp, int timeout) |
Perform a time sensitive fgets. | |
static void | strip (char *buf) |
Strip leading and trailing whitespace from a specified string. | |
static int | dnxPluginRegister (char *szPlugin, char *szErrMsg) |
Register a dnx plugin with entry points. | |
static int | dnxPluginLoad (DnxModule *module) |
Load a dnx plugin module into memory. | |
static void | dnxPluginUnload (DnxModule *module) |
Unload a dnx plugin module from memory. | |
static int | dnxPluginBaseName (char *command, char *baseName, int maxData) |
Isolate the base name of a plugin command. | |
static int | dnxPluginLocate (char *command, DnxPlugin **plugin) |
Search for a plugin in the plugin chain. | |
static int | dnxPluginVector (char *command, int *argc, char **argv, int maxargs) |
Convert a dnx plugin string to a vector array. | |
static void | dnxPluginInternal (DnxPlugin *plugin, char *command, int *resCode, char *resData, int maxData, int timeout, char *myaddr) |
Executes an internal plugin module. | |
static void | dnxPluginExternal (char *command, int *resCode, char *resData, int maxData, int timeout, char *myaddr) |
Execute an external command line; capture stdout and stderr. | |
void | dnxPluginExecute (char *command, int *resCode, char *resData, int maxData, int timeout, char *myaddr) |
Find an appropriate dnx plugin and use it to execute a commmand. | |
int | dnxPluginInit (char *pluginPath) |
Initialize the dnx client plugin utility library. | |
void | dnxPluginRelease (void) |
Clean up the dnx plugin utility library. | |
Variables | |
static iDnxModule * | gModules |
The loaded module chain. | |
static iDnxPlugin * | gPlugins |
The loaded plugin chain. | |
static char * | gPluginPath |
The configured plugin path. | |
static int | gInitialized = 0 |
The module initialization flag. |
Definition in file dnxPlugin.c.
#define DNX_MAX_ARGV 256 |
The maximum number of arguments.
Definition at line 59 of file dnxPlugin.c.
Referenced by dnxPluginInternal().
#define DNX_MAX_PLUGIN_NAME 255 |
The maximum plugin name length.
Definition at line 61 of file dnxPlugin.c.
Referenced by dnxPluginLocate().
#define elemcount | ( | x | ) | (sizeof(x)/sizeof(*(x))) |
Definition at line 55 of file dnxPlugin.c.
#define MAX_INPUT_BUFFER 1024 |
The maximum input buffer.
Definition at line 60 of file dnxPlugin.c.
Referenced by dnxPluginExternal(), dnxPluginInternal(), and neb_unload_module().
#define MAX_PLUGIN_PATH 2048 |
The maximum plugin path.
Definition at line 58 of file dnxPlugin.c.
Referenced by dnxPluginExternal().
#define MAX_PLUGIN_PREFIX 1024 |
The maximum plugin prefix.
Definition at line 57 of file dnxPlugin.c.
Referenced by dnxPluginInit().
#define MPLEXER "poll" |
#define USE_POLL |
Definition at line 45 of file dnxPlugin.c.
static char* dnxFgets | ( | char * | data, | |
int | size, | |||
FILE * | fp, | |||
int | timeout | |||
) | [static] |
Perform a time sensitive fgets.
[out] | data | - the address of storage for returning data from fp . |
[in] | size | - the maximum size of data in bytes. |
[in] | fp | - the file pointer to be read. |
[in] | timeout | - the maximum number of seconds to wait for data to be returned before failing with a timeout error. |
data
on success, or 0 on error.Definition at line 117 of file dnxPlugin.c.
static int dnxPluginBaseName | ( | char * | command, | |
char * | baseName, | |||
int | maxData | |||
) | [static] |
Isolate the base name of a plugin command.
[in] | command | - the command for which to have the base name isolated. |
[out] | baseName | - the address of storage for the returned base name. |
[in] | maxData | - the maximum size of the baseName buffer. |
Definition at line 232 of file dnxPlugin.c.
References DNX_ERR_INVALID, DNX_ERR_MEMORY, and DNX_OK.
Referenced by dnxPluginLocate().
void dnxPluginExecute | ( | char * | command, | |
int * | resCode, | |||
char * | resData, | |||
int | maxData, | |||
int | timeout, | |||
char * | myaddr | |||
) |
Find an appropriate dnx plugin and use it to execute a commmand.
[in] | command | - the command to be executed by the plugin. |
[out] | resCode | - the address of storage for the command's result code. |
[out] | resData | - the address of storage for the command's stdout text. |
[in] | maxData | - the maximum size of the resData buffer. |
[in] | timeout | - the maximum number of seconds to wait for command to complete before returning a timeout error. |
[in] | myaddr | - the address (in human readable format) of this DNX node. |
Definition at line 861 of file dnxPlugin.c.
References DNX_ERR_NOTFOUND, DNX_OK, DNX_PLUGIN_RESULT_UNKNOWN, dnxDebug(), dnxPluginExternal(), dnxPluginInternal(), dnxPluginLocate(), and gInitialized.
Referenced by dnxWorker().
static void dnxPluginExternal | ( | char * | command, | |
int * | resCode, | |||
char * | resData, | |||
int | maxData, | |||
int | timeout, | |||
char * | myaddr | |||
) | [static] |
Execute an external command line; capture stdout and stderr.
[in] | command | - the command to be executed. |
[out] | resCode | - the address of storage for the result code returned by command . |
[out] | resData | - the resulting STDOUT text from the execution of command . |
[in] | maxData | - the maximum size of the resData buffer. |
[in] | timeout | - the maximum number of seconds to wait for command to complete before returning a timeout error. |
[in] | myaddr | - the address (in human readable format) of this DNX node. |
Definition at line 455 of file dnxPlugin.c.
References DNX_PLUGIN_RESULT_CRITICAL, DNX_PLUGIN_RESULT_UNKNOWN, elemcount, gInitialized, gPluginPath, MAX_INPUT_BUFFER, MAX_PLUGIN_PATH, MPLEXER, PF_ERR, PF_OUT, pfclose(), pfkill(), pfopen(), start_time, and strip().
Referenced by dnxPluginExecute().
int dnxPluginInit | ( | char * | pluginPath | ) |
Initialize the dnx client plugin utility library.
[in] | pluginPath | - the file system path where plugin libraries are to be found. |
Definition at line 887 of file dnxPlugin.c.
References DNX_ERR_INVALID, DNX_ERR_MEMORY, DNX_OK, dnxLog(), gInitialized, gPluginPath, MAX_PLUGIN_PREFIX, and xmalloc.
Referenced by ehProcessData(), and main().
static void dnxPluginInternal | ( | DnxPlugin * | plugin, | |
char * | command, | |||
int * | resCode, | |||
char * | resData, | |||
int | maxData, | |||
int | timeout, | |||
char * | myaddr | |||
) | [static] |
Executes an internal plugin module.
[in] | plugin | - the plugin module to execute against command . |
[in] | command | - the command to have plugin execute. |
[out] | resCode | - the address of storage for the result code returned by plugin . |
[out] | resData | - the resulting STDOUT text from the execution of command by plugin . |
[in] | maxData | - the maximum size of the resData buffer. |
[in] | timeout | - the maximum number of seconds to wait for plugin to complete execution of command before returning a timeout error. |
[in] | myaddr | - the address (in human readable format) of this DNX node. |
Definition at line 370 of file dnxPlugin.c.
References DNX_MAX_ARGV, DNX_OK, DNX_PLUGIN_RESULT_UNKNOWN, dnxPluginVector(), gInitialized, and MAX_INPUT_BUFFER.
Referenced by dnxPluginExecute().
static int dnxPluginLoad | ( | DnxModule * | module | ) | [static] |
Load a dnx plugin module into memory.
[in] | module | - the name of the module to be loaded. |
Definition at line 199 of file dnxPlugin.c.
References DNX_OK, and gInitialized.
static int dnxPluginLocate | ( | char * | command, | |
DnxPlugin ** | plugin | |||
) | [static] |
Search for a plugin in the plugin chain.
[in] | command | - the command to be executed. |
[out] | plugin | - the address of storage for the located plugin to be returned. |
Definition at line 275 of file dnxPlugin.c.
References DNX_ERR_NOTFOUND, DNX_MAX_PLUGIN_NAME, DNX_OK, dnxPluginBaseName(), and gInitialized.
Referenced by dnxPluginExecute().
static int dnxPluginRegister | ( | char * | szPlugin, | |
char * | szErrMsg | |||
) | [static] |
Register a dnx plugin with entry points.
[in] | szPlugin | - the name of the plugin to be registered. |
[in] | szErrMsg | - an error message to be displayed if the plugin could not be registered. |
Definition at line 183 of file dnxPlugin.c.
References DNX_OK, and gInitialized.
void dnxPluginRelease | ( | void | ) |
Clean up the dnx plugin utility library.
Definition at line 929 of file dnxPlugin.c.
References gInitialized, gPluginPath, and xfree.
Referenced by main().
static void dnxPluginUnload | ( | DnxModule * | module | ) | [static] |
Unload a dnx plugin module from memory.
[in] | module | - the name of the module to be unloaded. |
Definition at line 215 of file dnxPlugin.c.
References gInitialized.
static int dnxPluginVector | ( | char * | command, | |
int * | argc, | |||
char ** | argv, | |||
int | maxargs | |||
) | [static] |
Convert a dnx plugin string to a vector array.
The command
buffer is modified such that each command argument is null-terminated on return.
[in] | command | - the string to be converted. |
[out] | argc | - the address of storage for the number of elements actually returned in argv . |
[out] | argv | - the address of storage for returning a null-terminated array of pointers to white-space-separated arguments in command . |
[in] | maxargs | - the maximum number of entries in the argv array. |
Definition at line 313 of file dnxPlugin.c.
References DNX_ERR_MEMORY, DNX_OK, and xmalloc.
Referenced by dnxPluginInternal().
static void strip | ( | char * | buf | ) | [static] |
Strip leading and trailing whitespace from a specified string.
Leading white space is removed by moving all text from the first non- white space character and after to the beginning of buffer
. Trailing white space is removed by simply zero-terminating the string after the last non-white space character in buffer
.
[in,out] | buf | - the buffer whose leading and trailing white space should be removed. |
Definition at line 159 of file dnxPlugin.c.
Referenced by dnxPluginExternal().
int gInitialized = 0 [static] |
The module initialization flag.
Definition at line 94 of file dnxPlugin.c.
Referenced by dnxPluginExecute(), dnxPluginExternal(), dnxPluginInit(), dnxPluginInternal(), dnxPluginLoad(), dnxPluginLocate(), dnxPluginRegister(), dnxPluginRelease(), and dnxPluginUnload().
iDnxModule* gModules [static] |
char* gPluginPath [static] |
The configured plugin path.
Definition at line 93 of file dnxPlugin.c.
Referenced by dnxPluginExternal(), dnxPluginInit(), and dnxPluginRelease().
iDnxPlugin* gPlugins [static] |