First set of fixes
There are still some problems but at least it does something now.
This commit is contained in:
@@ -49,24 +49,6 @@ on_data (void *handle, struct unit *u, struct str *data)
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
on_eof (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
on_error (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
on_aborted (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static struct service g_http_service =
|
||||
{
|
||||
.name = "HTTP",
|
||||
@@ -75,9 +57,9 @@ static struct service g_http_service =
|
||||
.scan_init = scan_init,
|
||||
.scan_free = scan_free,
|
||||
.on_data = on_data,
|
||||
.on_eof = on_eof,
|
||||
.on_error = on_error,
|
||||
.on_aborted = on_aborted
|
||||
.on_eof = NULL,
|
||||
.on_error = NULL,
|
||||
.on_aborted = NULL
|
||||
};
|
||||
|
||||
static bool
|
||||
|
||||
@@ -30,44 +30,50 @@ static struct plugin_data
|
||||
}
|
||||
g_data;
|
||||
|
||||
struct scan_data
|
||||
{
|
||||
struct str input; ///< Input buffer
|
||||
};
|
||||
|
||||
static void *
|
||||
scan_init (struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
return NULL;
|
||||
(void) u;
|
||||
|
||||
struct scan_data *scan = xcalloc (1, sizeof *scan);
|
||||
str_init (&scan->input);
|
||||
return scan;
|
||||
}
|
||||
|
||||
static void
|
||||
scan_free (void *handle)
|
||||
{
|
||||
// TODO
|
||||
struct scan_data *scan = handle;
|
||||
str_free (&scan->input);
|
||||
free (scan);
|
||||
}
|
||||
|
||||
static void
|
||||
on_data (void *handle, struct unit *u, struct str *data)
|
||||
{
|
||||
// TODO
|
||||
// TODO: don't let the input buffer grow too much
|
||||
struct scan_data *scan = handle;
|
||||
str_append_str (&scan->input, data);
|
||||
|
||||
char *input = scan->input.str;
|
||||
char *nl = strstr (input, "\r\n");
|
||||
if (!nl)
|
||||
return;
|
||||
|
||||
// TODO: parse the reply, make sure that it's actually SSH,
|
||||
// don't put just any garbage in the output info
|
||||
*nl = '\0';
|
||||
g_data.api->unit_add_info (u, input);
|
||||
g_data.api->unit_set_success (u, true);
|
||||
g_data.api->unit_abort (u);
|
||||
}
|
||||
|
||||
static void
|
||||
on_eof (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
on_error (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
on_aborted (void *handle, struct unit *u)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static struct service g_http_service =
|
||||
static struct service g_ssh_service =
|
||||
{
|
||||
.name = "SSH",
|
||||
.flags = 0,
|
||||
@@ -75,16 +81,16 @@ static struct service g_http_service =
|
||||
.scan_init = scan_init,
|
||||
.scan_free = scan_free,
|
||||
.on_data = on_data,
|
||||
.on_eof = on_eof,
|
||||
.on_error = on_error,
|
||||
.on_aborted = on_aborted
|
||||
.on_eof = NULL,
|
||||
.on_error = NULL,
|
||||
.on_aborted = NULL
|
||||
};
|
||||
|
||||
static bool
|
||||
initialize (void *ctx, struct plugin_api *api)
|
||||
{
|
||||
g_data = (struct plugin_data) { .ctx = ctx, .api = api };
|
||||
api->register_service (ctx, &g_http_service);
|
||||
api->register_service (ctx, &g_ssh_service);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user