summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 88f23d9)
raw | patch | inline | side by side (parent: 88f23d9)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Dec 2013 08:34:23 +0000 (09:34 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Dec 2013 08:34:23 +0000 (09:34 +0100) |
… using a STARTUP message.
src/Makefile.am | patch | blob | history | |
src/client/sock.c | patch | blob | history | |
src/include/client/sock.h | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index e59ea1f9fe877d6fe3d37ef663f7ccc2a24f41ab..5a18c7be82abc563d64f751052030c6c8a25eb3b 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
pkgclientincludedir = $(pkgincludedir)/client
pkgclientinclude_HEADERS = \
- include/client/sock.h
+ include/client/sock.h \
+ include/client/sysdb.h
lib_LTLIBRARIES = libsysdbclient.la libsysdb.la
diff --git a/src/client/sock.c b/src/client/sock.c
index b3be6157996fe7002661b783db2c055d7a382e45..18ab6a586a1c9f44018629533e4752ecf2ccfa73 100644 (file)
--- a/src/client/sock.c
+++ b/src/client/sock.c
} /* 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;
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)
#include "core/object.h"
#include "core/data.h"
+#include "frontend/proto.h"
+
#include "utils/strbuf.h"
#include <sys/socket.h>
/*
* 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: