changeset 151:4557170a0481

client: store volume group in connection state after login Also, reject future login attempts after one has been successful. This closes #33. Signed-off-by: Holly Sipek <holly.sipek@gmail.com> Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Holly Sipek <holly.sipek@gmail.com>
date Sun, 18 Oct 2015 14:40:47 -0400
parents 5b4d4496c9c6
children 3bf63abd5bd9
files src/client/cmd_dir.c src/client/cmd_login.c src/client/cmd_nop.c src/client/cmd_obj.c src/client/cmds.c src/client/cmds.h
diffstat 6 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/client/cmd_dir.c	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmd_dir.c	Sun Oct 18 14:40:47 2015 -0400
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015 Holly Sipek
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -24,17 +25,17 @@
 
 #include "cmds.h"
 
-int cmd_create(union cmd *cmd)
+int cmd_create(struct fsconn *conn, union cmd *cmd)
 {
 	return ENOTSUP;
 }
 
-int cmd_lookup(union cmd *cmd)
+int cmd_lookup(struct fsconn *conn, union cmd *cmd)
 {
 	return ENOTSUP;
 }
 
-int cmd_remove(union cmd *cmd)
+int cmd_remove(struct fsconn *conn, union cmd *cmd)
 {
 	return ENOTSUP;
 }
--- a/src/client/cmd_login.c	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmd_login.c	Sun Oct 18 14:40:47 2015 -0400
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015 Holly Sipek
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +27,7 @@
 
 #include "cmds.h"
 
-int cmd_login(union cmd *cmd)
+int cmd_login(struct fsconn *conn, union cmd *cmd)
 {
 	struct rpc_login_req *req = &cmd->login.req;
 	struct rpc_login_res *res = &cmd->login.res;
@@ -34,9 +35,16 @@
 
 	printf("LOGIN: conn = '%s', vg = '%s'\n", req->conn, req->vg);
 
+	if (conn->vg) {
+		printf("LOGIN: error: this connection already logged in.\n");
+		return EALREADY;
+	}
+
 	vg = objstore_vg_lookup(req->vg);
 	if (!vg)
 		return ENOENT;
 
+	conn->vg = vg;
+
 	return objstore_getroot(vg, &res->root);
 }
--- a/src/client/cmd_nop.c	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmd_nop.c	Sun Oct 18 14:40:47 2015 -0400
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015 Holly Sipek
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +23,7 @@
 
 #include "cmds.h"
 
-int cmd_nop(union cmd *cmd)
+int cmd_nop(struct fsconn *conn, union cmd *cmd)
 {
 	return 0;
 }
--- a/src/client/cmd_obj.c	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmd_obj.c	Sun Oct 18 14:40:47 2015 -0400
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015 Holly Sipek
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +25,7 @@
 
 #include "cmds.h"
 
-int cmd_stat(union cmd *cmd)
+int cmd_stat(struct fsconn *conn, union cmd *cmd)
 {
 	return ENOTSUP;
 }
--- a/src/client/cmds.c	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmds.c	Sun Oct 18 14:40:47 2015 -0400
@@ -58,7 +58,7 @@
 static const struct cmdtbl {
 	const char *name;
 	uint16_t opcode;
-	int (*handler)(union cmd *);
+	int (*handler)(struct fsconn *, union cmd *);
 	size_t reqoff;
 	size_t resoff;
 
@@ -151,7 +151,7 @@
 		}
 
 		/* invoke the handler */
-		ret = def->handler(&cmd);
+		ret = def->handler(conn, &cmd);
 
 		/* send back the response header */
 		ok = send_response(&xdr, conn->fd, ret);
--- a/src/client/cmds.h	Sun Oct 18 14:40:45 2015 -0400
+++ b/src/client/cmds.h	Sun Oct 18 14:40:47 2015 -0400
@@ -68,11 +68,11 @@
 extern bool process_connection(struct fsconn *conn);
 
 /* RPC handlers */
-extern int cmd_create(union cmd *cmd);
-extern int cmd_login(union cmd *cmd);
-extern int cmd_lookup(union cmd *cmd);
-extern int cmd_nop(union cmd *cmd);
-extern int cmd_remove(union cmd *cmd);
-extern int cmd_stat(union cmd *cmd);
+extern int cmd_create(struct fsconn *conn, union cmd *cmd);
+extern int cmd_login(struct fsconn *conn, union cmd *cmd);
+extern int cmd_lookup(struct fsconn *conn, union cmd *cmd);
+extern int cmd_nop(struct fsconn *conn, union cmd *cmd);
+extern int cmd_remove(struct fsconn *conn, union cmd *cmd);
+extern int cmd_stat(struct fsconn *conn, union cmd *cmd);
 
 #endif