From 6f9ae7bcb2985a6526f4e7ae8cbc6b1d4a31ae7a Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 29 Apr 2021 16:40:58 +0200 Subject: [PATCH] sharedsecret --- schema/createSchema.sql | 2 +- sink/sink20169.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/schema/createSchema.sql b/schema/createSchema.sql index 68f8bc4..e8b3148 100644 --- a/schema/createSchema.sql +++ b/schema/createSchema.sql @@ -2,7 +2,7 @@ CREATE SEQUENCE device_s START WITH 1 INCREMENT BY 1; CREATE TABLE device_t ( id integer PRIMARY KEY DEFAULT NEXTVAL('device_s'), - deviceid varchar(16) NOT NULL, + deviceid varchar(16) UNIQUE NOT NULL, sharedsecret varchar(31) NOT NULL, active boolean NOT NULL DEFAULT false ); \ No newline at end of file diff --git a/sink/sink20169.c b/sink/sink20169.c index 04165b8..57108b2 100644 --- a/sink/sink20169.c +++ b/sink/sink20169.c @@ -152,12 +152,12 @@ t_device *findDevice(t_commonHandle *handle, char *deviceId) { logmsg(LOG_INFO, "findDevice query fails, database returns %s", PQresStatus(execStatus)); } else { int ntuples = PQntuples(res2); - if (ntuples == 0) { - logmsg(LOG_ERR, "no device found"); - } else if (ntuples == 1) { + if (ntuples == 1) { logmsg(LOG_DEBUG, "device found"); + char *sharedsecret = PQgetvalue(res2, 0, 0); + logmsg(LOG_DEBUG, "found sharedsecret is %s", sharedsecret); } else { - logmsg(LOG_ERR, "strange number of devices found: %d", ntuples); + logmsg(LOG_ERR, "no device found"); } } PQclear(res2);