summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-23 22:59:01 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-23 22:59:01 +0200
commit1f9f9b9a395351fd2b001c24ffe89c546723763d (patch)
treed688869ae29c20c2e5deb72f4e35dd9d6233cb37 /plugins
parentf9d6627456e8232fe7a2ae1283347236aa2b34df (diff)
downloadponymap-1f9f9b9a395351fd2b001c24ffe89c546723763d.tar.gz
ponymap-1f9f9b9a395351fd2b001c24ffe89c546723763d.tar.xz
ponymap-1f9f9b9a395351fd2b001c24ffe89c546723763d.zip
Simplify the plugin API
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http.c45
-rw-r--r--plugins/irc.c6
-rw-r--r--plugins/ssh.c16
3 files changed, 31 insertions, 36 deletions
diff --git a/plugins/http.c b/plugins/http.c
index 0bf7378..1aa2bd9 100644
--- a/plugins/http.c
+++ b/plugins/http.c
@@ -48,13 +48,13 @@ struct scan_data
};
static void
-on_header_read (struct scan_data *data)
+on_header_read (struct scan_data *scan)
{
- if (!strcasecmp (data->field.str, "Server"))
+ if (!strcasecmp (scan->field.str, "Server"))
{
char *info = xstrdup_printf ("%s: %s",
- "server software", data->value.str);
- g_data.api->unit_add_info (data->u, info);
+ "server software", scan->value.str);
+ g_data.api->unit_add_info (scan->u, info);
free (info);
}
}
@@ -62,15 +62,15 @@ on_header_read (struct scan_data *data)
static int
on_header_field (http_parser *parser, const char *at, size_t len)
{
- struct scan_data *data = parser->data;
- if (data->state == STATE_VALUE)
+ struct scan_data *scan = parser->data;
+ if (scan->state == STATE_VALUE)
{
- on_header_read (data);
- str_reset (&data->field);
- str_reset (&data->value);
+ on_header_read (scan);
+ str_reset (&scan->field);
+ str_reset (&scan->value);
}
- str_append_data (&data->field, at, len);
- data->state = STATE_FIELD;
+ str_append_data (&scan->field, at, len);
+ scan->state = STATE_FIELD;
return 0;
}
@@ -86,10 +86,10 @@ on_header_value (http_parser *parser, const char *at, size_t len)
static int
on_headers_complete (http_parser *parser)
{
- struct scan_data *data = parser->data;
+ struct scan_data *scan = parser->data;
// We've got this far, this must be an HTTP server
- g_data.api->unit_set_success (data->u, true);
- g_data.api->unit_abort (data->u);
+ g_data.api->unit_set_success (scan->u, true);
+ g_data.api->unit_abort (scan->u);
return 1;
}
@@ -125,7 +125,7 @@ scan_free (void *handle)
}
static void
-on_data (void *handle, struct unit *u, struct str *data)
+on_data (void *handle, const void *data, size_t len)
{
static const http_parser_settings http_settings =
{
@@ -136,26 +136,23 @@ on_data (void *handle, struct unit *u, struct str *data)
struct scan_data *scan = handle;
http_parser *parser = &scan->parser;
-
- size_t len = data ? data->len : 0;
- const char *str = data ? data->str : NULL;
- size_t n_parsed = http_parser_execute (parser, &http_settings, str, len);
+ size_t n_parsed = http_parser_execute (parser, &http_settings, data, len);
if (parser->upgrade)
{
// We should never get here though because `on_headers_complete'
// is called first and ends up aborting the unit.
- g_data.api->unit_add_info (u, "upgrades to a different protocol");
- g_data.api->unit_abort (u);
+ g_data.api->unit_add_info (scan->u, "upgrades to a different protocol");
+ g_data.api->unit_abort (scan->u);
}
else if (n_parsed != len && parser->http_errno != HPE_CB_headers_complete)
- g_data.api->unit_abort (u);
+ g_data.api->unit_abort (scan->u);
}
static void
-on_eof (void *handle, struct unit *u)
+on_eof (void *handle)
{
- on_data (handle, u, NULL);
+ on_data (handle, NULL, 0);
}
static struct service g_http_service =
diff --git a/plugins/irc.c b/plugins/irc.c
index c0e967d..554c00c 100644
--- a/plugins/irc.c
+++ b/plugins/irc.c
@@ -279,12 +279,10 @@ on_irc_message (const struct irc_message *msg, const char *raw, void *user_data)
}
static void
-on_data (void *handle, struct unit *u, struct str *data)
+on_data (void *handle, const void *data, size_t len)
{
- (void) u;
-
struct scan_data *scan = handle;
- str_append_str (&scan->input, data);
+ str_append_data (&scan->input, data, len);
irc_process_buffer (&scan->input, on_irc_message, scan);
}
diff --git a/plugins/ssh.c b/plugins/ssh.c
index cf18c3c..8a1cc3a 100644
--- a/plugins/ssh.c
+++ b/plugins/ssh.c
@@ -32,16 +32,16 @@ g_data;
struct scan_data
{
+ struct unit *u; ///< Scan unit
struct str input; ///< Input buffer
};
static void *
scan_init (struct unit *u)
{
- (void) u;
-
struct scan_data *scan = xcalloc (1, sizeof *scan);
str_init (&scan->input);
+ scan->u = u;
return scan;
}
@@ -54,14 +54,14 @@ scan_free (void *handle)
}
static void
-on_data (void *handle, struct unit *u, struct str *data)
+on_data (void *handle, const void *data, size_t len)
{
// See RFC 4253 -- we check for a valid SSH banner
struct scan_data *scan = handle;
- if (scan->input.len + data->len > 255)
+ if (scan->input.len + len > 255)
goto end_scan;
- str_append_str (&scan->input, data);
+ str_append_data (&scan->input, data, len);
char *input = scan->input.str;
char *nl = strstr (input, "\r\n");
if (!nl)
@@ -71,11 +71,11 @@ on_data (void *handle, struct unit *u, struct str *data)
goto end_scan;
*nl = '\0';
- g_data.api->unit_add_info (u, input);
- g_data.api->unit_set_success (u, true);
+ g_data.api->unit_add_info (scan->u, input);
+ g_data.api->unit_set_success (scan->u, true);
end_scan:
- g_data.api->unit_abort (u);
+ g_data.api->unit_abort (scan->u);
}
static struct service g_ssh_service =