From 3cb4e8e54034952c13f434187455caef39e60fd9 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 19 Jul 2017 12:35:53 +0200 Subject: [PATCH] Split to directories --- Makefile | 11 ++--------- client/Makefile | 5 +++++ subauth.c => client/subauth.c | 0 configure | 2 +- server/Makefile | 6 ++++++ server/cmd.c | 16 ++++++++++++++++ subauthd.c => server/subauthd.c | 24 +----------------------- server/subauthd.h | 27 +++++++++++++++++++++++++++ 8 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 client/Makefile rename subauth.c => client/subauth.c (100%) create mode 100644 server/Makefile create mode 100644 server/cmd.c rename subauthd.c => server/subauthd.c (93%) create mode 100644 server/subauthd.h diff --git a/Makefile b/Makefile index 7ce559d..d538520 100644 --- a/Makefile +++ b/Makefile @@ -20,15 +20,8 @@ EXTRA_RUNDIRS=run CFLAGS+=$(LIBUCW_CFLAGS) $(LIBUCW_JSON_CFLAGS) LIBS+=$(LIBUCW_LIBS) $(LIBUCW_JSON_LIBS) -# Programs we want to compile -PROGS+=$(o)/subauthd $(o)/subauth - -# And how they are created -$(o)/subauthd: $(o)/subauthd.o -$(o)/subauth: $(o)/subauth.o - -# Configuration files -CONFIGS+=subauthd +include $(s)/server/Makefile +include $(s)/client/Makefile # And finally the default rules of the build system include $(BUILDSYS)/Makebottom diff --git a/client/Makefile b/client/Makefile new file mode 100644 index 0000000..608c26c --- /dev/null +++ b/client/Makefile @@ -0,0 +1,5 @@ +DIRS+=client + +PROGS+=$(o)/client/subauth + +$(o)/client/subauth: $(o)/client/subauth.o diff --git a/subauth.c b/client/subauth.c similarity index 100% rename from subauth.c rename to client/subauth.c diff --git a/configure b/configure index a964476..1b22783 100755 --- a/configure +++ b/configure @@ -8,7 +8,7 @@ use strict; our($srcdir, $libdir); BEGIN { # Find the sources - my $pkgfile = "subauthd.c"; + my $pkgfile = "server/subauthd.c"; if (!defined ($srcdir = $ENV{"SRCDIR"})) { if (-f $pkgfile) { $srcdir="."; diff --git a/server/Makefile b/server/Makefile new file mode 100644 index 0000000..54b613f --- /dev/null +++ b/server/Makefile @@ -0,0 +1,6 @@ +DIRS+=server + +PROGS+=$(o)/server/subauthd +CONFIGS+=subauthd + +$(o)/server/subauthd: $(addprefix $(o)/server/, subauthd.o cmd.o) diff --git a/server/cmd.c b/server/cmd.c new file mode 100644 index 0000000..5e8b898 --- /dev/null +++ b/server/cmd.c @@ -0,0 +1,16 @@ +/* + * Sub-authentication Daemon: Commands + * + * (c) 2017 Martin Mares + */ + +#include + +#include "subauthd.h" + +void cmd_error(struct client *c, const char *err) +{ + json_object_set(c->reply, "error", json_new_string(c->json, err)); +} + + diff --git a/subauthd.c b/server/subauthd.c similarity index 93% rename from subauthd.c rename to server/subauthd.c index bc76ef5..56d142f 100644 --- a/subauthd.c +++ b/server/subauthd.c @@ -7,10 +7,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -18,7 +16,7 @@ #include #include -#include "autoconf.h" +#include "subauthd.h" static char *socket_path = "subauthd.socket"; static uint max_connections = ~0U; @@ -26,19 +24,6 @@ static uint max_connections = ~0U; static struct main_file listen_socket; static uint num_connections; -#define SOCKET_TIMEOUT 60000 // in ms -#define MAX_PACKET_SIZE 16384 -#define MAX_OOB_DATA_SIZE 4096 - -struct client { - struct main_file socket; - struct main_timer timer; - int uid; - struct json_context *json; - struct json_node *request; - struct json_node *reply; -}; - static byte packet_buffer[MAX_PACKET_SIZE]; static byte oob_data_buffer[MAX_OOB_DATA_SIZE]; @@ -56,17 +41,10 @@ static void client_close(struct client *c) num_connections--; } -static void cmd_error(struct client *c, const char *err) -{ - json_object_set(c->reply, "error", json_new_string(c->json, err)); -} - static void socket_timeout_handler(struct main_timer *tm) { struct client *c = tm->data; - msg(L_INFO, "Client timeout"); - client_close(c); } diff --git a/server/subauthd.h b/server/subauthd.h new file mode 100644 index 0000000..4a104ec --- /dev/null +++ b/server/subauthd.h @@ -0,0 +1,27 @@ +/* + * Sub-authentication Daemon + * + * (c) 2017 Martin Mares + */ + +#include "autoconf.h" + +#include +#include + +#define SOCKET_TIMEOUT 60000 // in ms +#define MAX_PACKET_SIZE 16384 +#define MAX_OOB_DATA_SIZE 4096 + +struct client { + struct main_file socket; + struct main_timer timer; + int uid; + struct json_context *json; + struct json_node *request; + struct json_node *reply; +}; + +/* cmd.c */ + +void cmd_error(struct client *c, const char *err); -- 2.39.2