From 73c37f594ce06d3eec5ffc281949cac6a9e4b9bd Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 9 Dec 2013 09:34:23 +0100 Subject: [PATCH] Let sdb_client_connect() send a username to the server. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … using a STARTUP message. --- src/Makefile.am | 3 ++- src/client/sock.c | 32 +++++++++++++++++++++++++++++++- src/include/client/sock.h | 6 ++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e59ea1f..5a18c7b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/client/sock.c b/src/client/sock.c index b3be615..18ab6a5 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -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 */ diff --git a/src/include/client/sock.h b/src/include/client/sock.h index e33f4d7..c88fc9a 100644 --- a/src/include/client/sock.h +++ b/src/include/client/sock.h @@ -31,6 +31,8 @@ #include "core/object.h" #include "core/data.h" +#include "frontend/proto.h" + #include "utils/strbuf.h" #include @@ -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: -- 2.30.2