2014-09-07 17:28:10 +02:00
|
|
|
/*
|
|
|
|
* plugin-api.h: plugin API for ponymap
|
|
|
|
*
|
2020-09-28 04:55:23 +02:00
|
|
|
* Copyright (c) 2014, Přemysl Eric Janouch <p@janouch.name>
|
2014-09-07 17:28:10 +02:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2018-06-24 05:11:10 +02:00
|
|
|
* purpose with or without fee is hereby granted.
|
2014-09-07 17:28:10 +02:00
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-09-21 01:06:47 +02:00
|
|
|
#ifndef PLUGIN_API_H
|
|
|
|
#define PLUGIN_API_H
|
|
|
|
|
2014-09-07 17:28:10 +02:00
|
|
|
// This API is meant to be as simplistic as is realistically possible.
|
|
|
|
|
|
|
|
/// The version of the API, and by extension, of all the following structs
|
|
|
|
#define API_VERSION 1
|
|
|
|
|
|
|
|
///< Opaque object with data relating to a service scan
|
|
|
|
struct unit;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SERVICE_SUPPORTS_TLS = (1 << 0) ///< Plain TLS can be used
|
|
|
|
};
|
|
|
|
|
|
|
|
struct service
|
|
|
|
{
|
|
|
|
const char *name; ///< Name of the service
|
|
|
|
int flags; ///< Service flags
|
2015-01-18 04:07:05 +01:00
|
|
|
void *user_data; ///< User data
|
2014-09-07 17:28:10 +02:00
|
|
|
|
2015-05-13 06:57:06 +02:00
|
|
|
// scan_init -> on_data* -> [on_eof/on_error] -> on_stopped -> scan_free
|
2014-09-10 23:14:53 +02:00
|
|
|
|
2014-09-07 17:28:10 +02:00
|
|
|
/// Initialize a scan, returning a handle to it
|
2015-01-18 04:07:05 +01:00
|
|
|
void *(*scan_init) (struct service *self, struct unit *u);
|
2014-09-07 17:28:10 +02:00
|
|
|
|
2014-09-10 23:14:53 +02:00
|
|
|
/// Destroy the handle created for the scan
|
|
|
|
void (*scan_free) (void *handle);
|
|
|
|
|
2014-09-07 17:28:10 +02:00
|
|
|
/// We have received some data from the peer
|
2014-09-23 22:59:01 +02:00
|
|
|
void (*on_data) (void *handle, const void *data, size_t len);
|
2014-09-07 17:28:10 +02:00
|
|
|
|
|
|
|
/// Server has closed the connection
|
2014-09-23 22:59:01 +02:00
|
|
|
void (*on_eof) (void *handle);
|
2014-09-07 17:28:10 +02:00
|
|
|
|
2014-09-21 00:58:19 +02:00
|
|
|
// XXX: do we need these at all? Is there any use for them?
|
|
|
|
|
2014-09-07 17:28:10 +02:00
|
|
|
/// Network or other error has occured
|
2014-09-23 22:59:01 +02:00
|
|
|
void (*on_error) (void *handle);
|
2014-09-07 17:28:10 +02:00
|
|
|
|
2015-05-13 06:57:06 +02:00
|
|
|
/// The scan has been stopped
|
|
|
|
void (*on_stopped) (void *handle);
|
2014-09-07 17:28:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct plugin_api
|
|
|
|
{
|
|
|
|
/// Register the plugin for a service
|
|
|
|
void (*register_service) (void *ctx, struct service *info);
|
|
|
|
|
2015-01-18 04:07:05 +01:00
|
|
|
/// Retrieve an item from the configuration
|
|
|
|
const char *(*get_config) (void *ctx, const char *key);
|
|
|
|
|
2014-09-20 18:10:29 +02:00
|
|
|
/// Get the IP address of the target as a string
|
|
|
|
const char *(*unit_get_address) (struct unit *u);
|
|
|
|
|
2014-09-07 17:28:10 +02:00
|
|
|
/// Send some data to the peer
|
|
|
|
ssize_t (*unit_write) (struct unit *u, const void *buf, size_t len);
|
|
|
|
|
|
|
|
/// Mark the scan as un/successful
|
|
|
|
void (*unit_set_success) (struct unit *u, bool success);
|
|
|
|
|
|
|
|
/// Add some information resulting from the scan
|
|
|
|
void (*unit_add_info) (struct unit *u, const char *result);
|
|
|
|
|
|
|
|
/// Abort the scan, close the connection
|
2015-05-13 06:57:06 +02:00
|
|
|
void (*unit_stop) (struct unit *u);
|
2014-09-07 17:28:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct plugin_info
|
|
|
|
{
|
|
|
|
/// Version of the API used by this plugin
|
|
|
|
int32_t api_version;
|
|
|
|
|
|
|
|
/// Let the plugin initialize itself and register any services.
|
|
|
|
/// The context needs to be passed to the relevant API functions.
|
|
|
|
bool (*initialize) (void *ctx, struct plugin_api *api);
|
|
|
|
};
|
2014-09-21 01:06:47 +02:00
|
|
|
|
|
|
|
#endif // ! PLUGIN_API_H
|