Fix the IRC plugin, and not only that
This commit is contained in:
parent
e7d8b244a9
commit
6c90cc85db
|
@ -217,8 +217,10 @@ static void *
|
||||||
scan_init (struct unit *u)
|
scan_init (struct unit *u)
|
||||||
{
|
{
|
||||||
char nick[IRC_MAX_NICKNAME + 1];
|
char nick[IRC_MAX_NICKNAME + 1];
|
||||||
for (size_t i = 0; i < sizeof nick - 1; i++)
|
size_t i;
|
||||||
|
for (i = 0; i < sizeof nick - 1; i++)
|
||||||
nick[i] = 'a' + rand () % ('z' - 'a' + 1);
|
nick[i] = 'a' + rand () % ('z' - 'a' + 1);
|
||||||
|
nick[i] = '\0';
|
||||||
|
|
||||||
struct str hello;
|
struct str hello;
|
||||||
str_init (&hello);
|
str_init (&hello);
|
||||||
|
@ -267,7 +269,7 @@ on_irc_message (const struct irc_message *msg, const char *raw, void *user_data)
|
||||||
if (code == IRC_RPL_MYINFO && msg->params.len > 0)
|
if (code == IRC_RPL_MYINFO && msg->params.len > 0)
|
||||||
{
|
{
|
||||||
char *info = xstrdup_printf ("%s: %s",
|
char *info = xstrdup_printf ("%s: %s",
|
||||||
"server name", msg->params.vector[0]);
|
"server name", msg->params.vector[1]);
|
||||||
g_data.api->unit_add_info (scan->u, info);
|
g_data.api->unit_add_info (scan->u, info);
|
||||||
free (info);
|
free (info);
|
||||||
|
|
||||||
|
|
28
ponymap.c
28
ponymap.c
|
@ -229,6 +229,7 @@ struct unit
|
||||||
struct poller_timer timeout_event; ///< Timeout event
|
struct poller_timer timeout_event; ///< Timeout event
|
||||||
struct poller_fd fd_event; ///< FD event
|
struct poller_fd fd_event; ///< FD event
|
||||||
|
|
||||||
|
bool abortion_requested; ///< Abortion requested by service
|
||||||
bool aborted; ///< Scan has been aborted
|
bool aborted; ///< Scan has been aborted
|
||||||
bool success; ///< Service has been found
|
bool success; ///< Service has been found
|
||||||
struct str_vector info; ///< Info resulting from the scan
|
struct str_vector info; ///< Info resulting from the scan
|
||||||
|
@ -537,9 +538,10 @@ unit_abort (struct unit *u)
|
||||||
if (u->success)
|
if (u->success)
|
||||||
{
|
{
|
||||||
// Now we're a part of the target
|
// Now we're a part of the target
|
||||||
LIST_PREPEND (u->target->results, u);
|
struct target *target = u->target;
|
||||||
target_unref (u->target);
|
LIST_PREPEND (target->results, u);
|
||||||
u->target = NULL;
|
u->target = NULL;
|
||||||
|
target_unref (target);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
unit_unref (u);
|
unit_unref (u);
|
||||||
|
@ -562,10 +564,6 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
|
||||||
struct service *service = u->service;
|
struct service *service = u->service;
|
||||||
enum transport_io_result result;
|
enum transport_io_result result;
|
||||||
|
|
||||||
// We hold a reference so that unit_abort(), which may also be
|
|
||||||
// called by handlers within the service, doesn't free the unit.
|
|
||||||
unit_ref (u);
|
|
||||||
|
|
||||||
if ((result = transport->on_readable (u)))
|
if ((result = transport->on_readable (u)))
|
||||||
goto exception;
|
goto exception;
|
||||||
if (u->read_buffer.len)
|
if (u->read_buffer.len)
|
||||||
|
@ -574,15 +572,15 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
|
||||||
service->on_data (u->service_data, u, buf);
|
service->on_data (u->service_data, u, buf);
|
||||||
str_remove_slice (buf, 0, buf->len);
|
str_remove_slice (buf, 0, buf->len);
|
||||||
|
|
||||||
if (u->aborted)
|
if (u->abortion_requested)
|
||||||
goto end;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result = transport->on_writeable (u)))
|
if ((result = transport->on_writeable (u)))
|
||||||
goto exception;
|
goto exception;
|
||||||
if (!u->aborted)
|
|
||||||
unit_update_poller (u, pfd);
|
unit_update_poller (u, pfd);
|
||||||
goto end;
|
return;
|
||||||
|
|
||||||
exception:
|
exception:
|
||||||
if (result == TRANSPORT_IO_EOF)
|
if (result == TRANSPORT_IO_EOF)
|
||||||
|
@ -596,10 +594,8 @@ exception:
|
||||||
service->on_error (u->service_data, u);
|
service->on_error (u->service_data, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abort:
|
||||||
unit_abort (u);
|
unit_abort (u);
|
||||||
|
|
||||||
end:
|
|
||||||
unit_unref (u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -783,7 +779,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->aborted)
|
if (u->abortion_requested || u->aborted)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
str_append_data (&u->write_buffer, buf, len);
|
str_append_data (&u->write_buffer, buf, len);
|
||||||
|
@ -805,7 +801,7 @@ 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_abort (struct unit *u)
|
||||||
{
|
{
|
||||||
unit_abort (u);
|
u->abortion_requested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct plugin_api g_plugin_vtable =
|
static struct plugin_api g_plugin_vtable =
|
||||||
|
|
Loading…
Reference in New Issue