summaryrefslogtreecommitdiffstats
path: root/server-msg.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:50:49 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:50:49 +0000
commit5ef6d077c67b80fdb5e2153172f6d1ec1302050f (patch)
treee43cda0a503957b18d769c25c0c9191faa893b99 /server-msg.c
parent8d019841828d30beee5c78500b07f0c80e69457e (diff)
Join oldest session if non specified. Fix errors.
Diffstat (limited to 'server-msg.c')
-rw-r--r--server-msg.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/server-msg.c b/server-msg.c
index 1cce4481..0f8d092d 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.3 2007-09-26 18:09:23 nicm Exp $ */
+/* $Id: server-msg.c,v 1.4 2007-09-26 18:50:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -139,6 +139,8 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
{
struct attach_data data;
char *msg;
+ struct session *s;
+ u_int i;
if (c->session != NULL)
return (0);
@@ -153,10 +155,21 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
if (c->sy == 0)
c->sy = 25;
- if (*data.name != '\0')
- c->session = session_find(data.name);
+ if (*data.name != '\0') {
+ if ((c->session = session_find(data.name)) == NULL)
+ xasprintf(&msg, "session not found: %s", data.name);
+ } else {
+ /* Find the oldest session. */
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
+ continue;
+ if (c->session == NULL || s->tim < c->session->tim)
+ c->session = s;
+ }
+ if (c->session == NULL)
+ xasprintf(&msg, "no sessions found");
+ }
if (c->session == NULL) {
- xasprintf(&msg, "session not found: %s", data.name);
server_write_client(c, MSG_ERROR, msg, strlen(msg));
xfree(msg);
return (0);