Code

Let sdb_client_connect() send a username to the server.
authorSebastian Harl <sh@tokkee.org>
Mon, 9 Dec 2013 08:34:23 +0000 (09:34 +0100)
committerSebastian Harl <sh@tokkee.org>
Mon, 9 Dec 2013 08:34:23 +0000 (09:34 +0100)
… using a STARTUP message.

src/Makefile.am
src/client/sock.c
src/include/client/sock.h

index e59ea1f9fe877d6fe3d37ef663f7ccc2a24f41ab..5a18c7be82abc563d64f751052030c6c8a25eb3b 100644 (file)
@@ -33,7 +33,8 @@ pkgutilsinclude_HEADERS = \
 
 pkgclientincludedir = $(pkgincludedir)/client
 pkgclientinclude_HEADERS = \
-               include/client/sock.h
+               include/client/sock.h \
+               include/client/sysdb.h
 
 lib_LTLIBRARIES = libsysdbclient.la libsysdb.la
 
index b3be6157996fe7002661b783db2c055d7a382e45..18ab6a586a1c9f44018629533e4752ecf2ccfa73 100644 (file)
@@ -120,8 +120,12 @@ sdb_client_destroy(sdb_client_t *client)
 } /* sdb_client_destroy */
 
 int
-sdb_client_connect(sdb_client_t *client)
+sdb_client_connect(sdb_client_t *client, const char *username)
 {
+       sdb_strbuf_t *buf;
+       ssize_t status;
+       uint32_t rstatus;
+
        if ((! client) || (! client->address))
                return -1;
 
@@ -137,6 +141,32 @@ sdb_client_connect(sdb_client_t *client)
 
        if (client->fd < 0)
                return -1;
+
+       /* XXX */
+       if (! username)
+               username = "";
+
+       status = sdb_client_send(client, CONNECTION_STARTUP,
+                       (uint32_t)strlen(username), username);
+       if (status < 0) {
+               sdb_client_close(client);
+               return (int)status;
+       }
+
+       buf = sdb_strbuf_create(64);
+       rstatus = 0;
+       status = sdb_client_recv(client, &rstatus, buf);
+       if (status < 0) {
+               sdb_client_close(client);
+               sdb_strbuf_destroy(buf);
+               return (int)status;
+       }
+
+       if (rstatus != CONNECTION_OK) {
+               sdb_client_close(client);
+               sdb_strbuf_destroy(buf);
+               return -((int)rstatus);
+       }
        return 0;
 } /* sdb_client_connect */
 
index e33f4d769b01d2451ba6c019a7b0a885f4bfb3b5..c88fc9a02041d2a7d0f06970428e17dfcb064c07 100644 (file)
@@ -31,6 +31,8 @@
 #include "core/object.h"
 #include "core/data.h"
 
+#include "frontend/proto.h"
+
 #include "utils/strbuf.h"
 
 #include <sys/socket.h>
@@ -65,14 +67,14 @@ sdb_client_destroy(sdb_client_t *client);
 
 /*
  * sdb_client_connect:
- * Connect to the client's address.
+ * Connect to the client's address using the specified username.
  *
  * Returns:
  *  - 0 on success
  *  - a negative value else
  */
 int
-sdb_client_connect(sdb_client_t *client);
+sdb_client_connect(sdb_client_t *client, const char *username);
 
 /*
  * sdb_client_close: