Aborting units -> stopping units

This commit is contained in:
Přemysl Eric Janouch 2015-05-13 06:57:06 +02:00
parent b2cc2709c6
commit de4009fb4d
8 changed files with 46 additions and 46 deletions

View File

@ -39,7 +39,7 @@ struct service
int flags; ///< Service flags int flags; ///< Service flags
void *user_data; ///< User data void *user_data; ///< User data
// scan_init -> on_data* -> [on_eof/on_error] -> on_aborted -> scan_free // scan_init -> on_data* -> [on_eof/on_error] -> on_stopped -> scan_free
/// Initialize a scan, returning a handle to it /// Initialize a scan, returning a handle to it
void *(*scan_init) (struct service *self, struct unit *u); void *(*scan_init) (struct service *self, struct unit *u);
@ -58,8 +58,8 @@ struct service
/// Network or other error has occured /// Network or other error has occured
void (*on_error) (void *handle); void (*on_error) (void *handle);
/// The scan has been aborted /// The scan has been stopped
void (*on_aborted) (void *handle); void (*on_stopped) (void *handle);
}; };
struct plugin_api struct plugin_api
@ -83,7 +83,7 @@ struct plugin_api
void (*unit_add_info) (struct unit *u, const char *result); void (*unit_add_info) (struct unit *u, const char *result);
/// Abort the scan, close the connection /// Abort the scan, close the connection
void (*unit_abort) (struct unit *u); void (*unit_stop) (struct unit *u);
}; };
struct plugin_info struct plugin_info

View File

@ -90,7 +90,7 @@ on_headers_complete (http_parser *parser)
struct scan_data *scan = parser->data; struct scan_data *scan = parser->data;
// We've got this far, this must be an HTTP server // We've got this far, this must be an HTTP server
g_data.api->unit_set_success (scan->u, true); g_data.api->unit_set_success (scan->u, true);
g_data.api->unit_abort (scan->u); g_data.api->unit_stop (scan->u);
return 1; return 1;
} }
@ -144,12 +144,12 @@ on_data (void *handle, const void *data, size_t len)
if (parser->upgrade) if (parser->upgrade)
{ {
// We should never get here though because `on_headers_complete' // We should never get here though because `on_headers_complete'
// is called first and ends up aborting the unit. // is called first and ends up stopping the unit.
g_data.api->unit_add_info (scan->u, "upgrades to a different protocol"); g_data.api->unit_add_info (scan->u, "upgrades to a different protocol");
g_data.api->unit_abort (scan->u); g_data.api->unit_stop (scan->u);
} }
else if (n_parsed != len && parser->http_errno != HPE_CB_headers_complete) else if (n_parsed != len && parser->http_errno != HPE_CB_headers_complete)
g_data.api->unit_abort (scan->u); g_data.api->unit_stop (scan->u);
} }
static void static void
@ -168,7 +168,7 @@ static struct service g_http_service =
.on_data = on_data, .on_data = on_data,
.on_eof = on_eof, .on_eof = on_eof,
.on_error = NULL, .on_error = NULL,
.on_aborted = NULL .on_stopped = NULL
}; };
static bool static bool

View File

@ -107,7 +107,7 @@ on_irc_message (const struct irc_message *msg, const char *raw, void *user_data)
g_data.api->unit_add_info (scan->u, info); g_data.api->unit_add_info (scan->u, info);
free (info); free (info);
g_data.api->unit_abort (scan->u); g_data.api->unit_stop (scan->u);
} }
} }
} }
@ -130,7 +130,7 @@ static struct service g_irc_service =
.on_data = on_data, .on_data = on_data,
.on_eof = NULL, .on_eof = NULL,
.on_error = NULL, .on_error = NULL,
.on_aborted = NULL .on_stopped = NULL
}; };
static bool static bool

View File

@ -110,10 +110,10 @@ xlua_unit_add_info (lua_State *L)
} }
static int static int
xlua_unit_abort (lua_State *L) xlua_unit_stop (lua_State *L)
{ {
struct unit_wrapper *data = luaL_checkudata (L, 1, UNIT_METATABLE); struct unit_wrapper *data = luaL_checkudata (L, 1, UNIT_METATABLE);
g_data.api->unit_abort (data->unit); g_data.api->unit_stop (data->unit);
return 0; return 0;
} }
@ -133,7 +133,7 @@ static luaL_Reg xlua_unit_table[] =
{ "write", xlua_unit_write }, { "write", xlua_unit_write },
{ "set_success", xlua_unit_set_success }, { "set_success", xlua_unit_set_success },
{ "add_info", xlua_unit_add_info }, { "add_info", xlua_unit_add_info },
{ "abort", xlua_unit_abort }, { "stop", xlua_unit_stop },
{ "__gc", xlua_unit_destroy }, { "__gc", xlua_unit_destroy },
{ NULL, NULL } { NULL, NULL }
}; };
@ -208,7 +208,7 @@ handle_scan_method_failure (struct scan_data *data)
{ {
print_error ("Lua: service `%s': %s", data->service->name, print_error ("Lua: service `%s': %s", data->service->name,
lua_tostring (data->L, -1)); lua_tostring (data->L, -1));
g_data.api->unit_abort (data->unit); g_data.api->unit_stop (data->unit);
lua_pop (data->L, 1); lua_pop (data->L, 1);
} }
@ -273,10 +273,10 @@ on_error (void *handle)
} }
static void static void
on_aborted (void *handle) on_stopped (void *handle)
{ {
struct scan_data *data = handle; struct scan_data *data = handle;
if (!prepare_scan_method (data, "on_aborted")) if (!prepare_scan_method (data, "on_stopped"))
return; return;
if (lua_pcall (data->L, 1, 0, 0)) if (lua_pcall (data->L, 1, 0, 0))
handle_scan_method_failure (data); handle_scan_method_failure (data);
@ -329,7 +329,7 @@ xlua_register_service (lua_State *L)
s->on_data = on_data; s->on_data = on_data;
s->on_eof = on_eof; s->on_eof = on_eof;
s->on_error = on_error; s->on_error = on_error;
s->on_aborted = on_aborted; s->on_stopped = on_stopped;
g_data.api->register_service (g_data.ctx, s); g_data.api->register_service (g_data.ctx, s);
return 0; return 0;

View File

@ -34,7 +34,7 @@ function MPD:on_data (data)
self.unit:add_info ("version " .. version) self.unit:add_info ("version " .. version)
self.unit:set_success (true) self.unit:set_success (true)
end end
self.unit:abort () self.unit:stop ()
end end
end end

View File

@ -38,7 +38,7 @@ function Socks4:on_data (data)
if null == 0 and code >= 90 and code <= 93 then if null == 0 and code >= 90 and code <= 93 then
self.unit:set_success (true) self.unit:set_success (true)
end end
self.unit:abort () self.unit:stop ()
end end
end end
@ -75,7 +75,7 @@ function Socks5:on_data (data)
end end
self.unit:set_success (true) self.unit:set_success (true)
end end
self.unit:abort () self.unit:stop ()
end end
end end

View File

@ -77,7 +77,7 @@ on_data (void *handle, const void *data, size_t len)
g_data.api->unit_set_success (scan->u, true); g_data.api->unit_set_success (scan->u, true);
end_scan: end_scan:
g_data.api->unit_abort (scan->u); g_data.api->unit_stop (scan->u);
} }
static struct service g_ssh_service = static struct service g_ssh_service =
@ -90,7 +90,7 @@ static struct service g_ssh_service =
.on_data = on_data, .on_data = on_data,
.on_eof = NULL, .on_eof = NULL,
.on_error = NULL, .on_error = NULL,
.on_aborted = NULL .on_stopped = NULL
}; };
static bool static bool

View File

@ -204,7 +204,7 @@ struct target
/// All currently running units for this target, holding a reference to us. /// All currently running units for this target, holding a reference to us.
/// They remove themselves from this list upon terminating. The purpose of /// They remove themselves from this list upon terminating. The purpose of
/// this list is making it possible to abort them forcefully. /// this list is making it possible to stop them forcefully.
struct unit *running_units; struct unit *running_units;
}; };
@ -235,8 +235,8 @@ struct unit
struct str_vector info; ///< Info resulting from the scan struct str_vector info; ///< Info resulting from the scan
bool scan_started; ///< Whether the scan has been started bool scan_started; ///< Whether the scan has been started
bool abortion_requested; ///< Abortion requested by service bool stop_requested; ///< Stopping requested by service
bool aborted; ///< Scan has been aborted bool stopped; ///< Scan has been stopped
bool success; ///< Service has been found bool success; ///< Service has been found
}; };
@ -522,16 +522,16 @@ unit_unref (struct unit *self)
} }
static void static void
unit_abort (struct unit *u) unit_stop (struct unit *u)
{ {
if (u->aborted) if (u->stopped)
return; return;
u->aborted = true; u->stopped = true;
if (u->scan_started) if (u->scan_started)
{ {
if (u->service->on_aborted) if (u->service->on_stopped)
u->service->on_aborted (u->service_data); u->service->on_stopped (u->service_data);
u->service->scan_free (u->service_data); u->service->scan_free (u->service_data);
u->transport->cleanup (u); u->transport->cleanup (u);
@ -599,8 +599,8 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
service->on_data (u->service_data, buf->str, buf->len); service->on_data (u->service_data, buf->str, buf->len);
str_remove_slice (buf, 0, buf->len); str_remove_slice (buf, 0, buf->len);
if (u->abortion_requested) if (u->stop_requested)
goto abort; goto stop;
} }
if ((result = transport->on_writeable (u)) == TRANSPORT_IO_ERROR) if ((result = transport->on_writeable (u)) == TRANSPORT_IO_ERROR)
@ -611,8 +611,8 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
{ {
if (service->on_eof) if (service->on_eof)
service->on_eof (u->service_data); service->on_eof (u->service_data);
if (u->abortion_requested || !u->write_buffer.len) if (u->stop_requested || !u->write_buffer.len)
goto abort; goto stop;
} }
unit_update_poller (u, pfd); unit_update_poller (u, pfd);
@ -622,8 +622,8 @@ error:
if (service->on_error) if (service->on_error)
service->on_error (u->service_data); service->on_error (u->service_data);
abort: stop:
unit_abort (u); unit_stop (u);
} }
static void static void
@ -632,7 +632,7 @@ unit_start_scan (struct unit *u)
if (!u->transport->init (u)) if (!u->transport->init (u))
{ {
// TODO: maybe print a message with the problem? // TODO: maybe print a message with the problem?
unit_abort (u); unit_stop (u);
return; return;
} }
@ -663,7 +663,7 @@ on_unit_connected (const struct pollfd *pfd, struct unit *u)
// But POSIX seems to say that this can block, too. // But POSIX seems to say that this can block, too.
soft_assert (error != EADDRNOTAVAIL); soft_assert (error != EADDRNOTAVAIL);
unit_abort (u); unit_stop (u);
} }
else else
unit_start_scan (u); unit_start_scan (u);
@ -686,7 +686,7 @@ unit_new (struct target *target, int socket_fd, uint16_t port,
str_vector_init (&u->info); str_vector_init (&u->info);
poller_timer_init (&u->timeout_event, &target->ctx->poller); poller_timer_init (&u->timeout_event, &target->ctx->poller);
u->timeout_event.dispatcher = (poller_timer_fn) unit_abort; u->timeout_event.dispatcher = (poller_timer_fn) unit_stop;
u->timeout_event.user_data = u; u->timeout_event.user_data = u;
poller_fd_init (&u->fd_event, &target->ctx->poller, socket_fd); poller_fd_init (&u->fd_event, &target->ctx->poller, socket_fd);
@ -773,7 +773,7 @@ initiate_quit (struct app_context *ctx)
for (u_iter = t_iter->running_units; u_iter; u_iter = u_next) for (u_iter = t_iter->running_units; u_iter; u_iter = u_next)
{ {
u_next = u_iter->next; u_next = u_iter->next;
unit_abort (u_iter); unit_stop (u_iter);
} }
} }
@ -813,7 +813,7 @@ plugin_api_unit_get_address (struct unit *u)
static ssize_t static ssize_t
plugin_api_unit_write (struct unit *u, const void *buf, size_t len) plugin_api_unit_write (struct unit *u, const void *buf, size_t len)
{ {
if (u->abortion_requested || u->aborted) if (u->stop_requested || u->stopped)
return -1; return -1;
str_append_data (&u->write_buffer, buf, len); str_append_data (&u->write_buffer, buf, len);
@ -833,9 +833,9 @@ plugin_api_unit_add_info (struct unit *u, const char *result)
} }
static void static void
plugin_api_unit_abort (struct unit *u) plugin_api_unit_stop (struct unit *u)
{ {
u->abortion_requested = true; u->stop_requested = true;
} }
static struct plugin_api g_plugin_vtable = static struct plugin_api g_plugin_vtable =
@ -846,7 +846,7 @@ static struct plugin_api g_plugin_vtable =
.unit_write = plugin_api_unit_write, .unit_write = plugin_api_unit_write,
.unit_set_success = plugin_api_unit_set_success, .unit_set_success = plugin_api_unit_set_success,
.unit_add_info = plugin_api_unit_add_info, .unit_add_info = plugin_api_unit_add_info,
.unit_abort = plugin_api_unit_abort .unit_stop = plugin_api_unit_stop
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1546,7 +1546,7 @@ target_unref (struct target *self)
if (self->results) if (self->results)
target_dump_results (self); target_dump_results (self);
// These must have been aborted already (although we could do that in here) // These must have been stopped already (although we could do that in here)
hard_assert (!self->running_units); hard_assert (!self->running_units);
struct unit *iter, *next; struct unit *iter, *next;