void disconnect_client(struct client *c, const char *reason)
{
g_assert(c != NULL);
+ c->connected = FALSE;
g_assert(c->incoming != NULL);
- g_io_channel_ref(c->incoming);
+ g_io_channel_unref(c->incoming);
g_source_remove(c->incoming_id);
if (c->outgoing_id)
g_source_remove(c->outgoing_id);
if (c->exit_on_close)
exit(0);
+ client_unref(c);
+}
+
+static void free_client(struct client *c)
+{
+ g_assert(c->connected == FALSE);
g_free(c->charset);
g_free(c->description);
free_network_state(c->state);
void client_unref(struct client *c)
{
- if (c != NULL)
- c->references--;
+ if (c == NULL)
+ return;
+
+ c->references--;
+ if (c->references == 0)
+ free_client(c);
}
return close_server(s);
}
-/**
- * Check whether a client is still associated with a network.
- *
- * The client pointer does not have to point to a valid piece of memory.
- *
- * @param s Network the client should be associated with.
- * @param c The client.
- * @return Whether the client is still associated with the network.
- */
-gboolean verify_client(const struct network *s, const struct client *c)
-{
- GList *gl;
-
- g_assert(s);
- g_assert(c);
-
- for (gl = s->clients; gl; gl = gl->next) {
- struct client *nc = (struct client *)gl->data;
- if (c == nc) return 1;
- }
-
- return 0;
-}
-
/**
* Register a new virtual network type.
*
/* util.c */
G_MODULE_EXPORT char *list_make_string(GList *);
-G_MODULE_EXPORT int verify_client(const struct network *s,
- const struct client *c);
G_MODULE_EXPORT int str_rfc1459cmp(const char *a, const char *b);
G_MODULE_EXPORT int str_strictrfc1459cmp(const char *a, const char *b);
G_MODULE_EXPORT int str_asciicmp(const char *a, const char *b);
is_reply(s->query->end_replies, n))) {
/* Send to client that queried, if that client still exists */
- if (s->client != NULL && verify_client(s->network, s->client)) {
+ if (s->client != NULL) {
c = s->client;
client_send_line(s->client, l);
}
/* Remove from stack */
if (p == NULL)stack = s->next;
else p->next = s->next;
+ client_unref(s->client);
g_free(s);
}
if (p == NULL)stack = q->next;
else p->next = q->next;
n = q->next;
+ client_unref(q->client);
g_free(q);
q = n;
}
g_assert(n != NULL);
g_assert(q != NULL);
s->network = n;
- s->client = c;
+ s->client = client_ref(c);
s->time = time(NULL);
s->query = q;
s->next = stack;