From: Sebastian Harl Date: Mon, 9 Dec 2013 08:34:23 +0000 (+0100) Subject: Let sdb_client_connect() send a username to the server. X-Git-Tag: sysdb-0.1.0~321 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=73c37f594ce06d3eec5ffc281949cac6a9e4b9bd Let sdb_client_connect() send a username to the server. … using a STARTUP message. --- 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: