diff --git a/.gitignore b/.gitignore index 709140d..93bbd66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ -# executables -moxerver - -# object files +# object files/output directories *.o +*.dir # logs directory during development logs diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fb156f3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: cpp + +compiler: +- gcc +- clang + +script: make install diff --git a/Makefile b/Makefile index fa9aaef..49f1fee 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,38 @@ -# target name -TARGET = moxerver +# components +SERVER = moxerver +TOOLS = tools -# special include directories -INCDIRS = -I. -# special library directories -LIBDIRS = -L. -# used libraries -#LIBS = -lm -LIBS = -lpthread +# system install root directory +INSTALL_ROOT = $(abspath ./install.dir) -# compiler and flags -CC = gcc -CFLAGS = -Wall $(INCDIRS) $(LIBDIRS) $(LIBS) +# prefix for /bin directory +BIN_PREFIX = /usr -# objects are .o files created from all .c files in the directory (same name) -OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) -# headers are all .h files in the directory -HEADERS = $(wildcard *.h) +# ============================================================================== -# all objects are built from their .c files and all headers in the directory -%.o: %.c $(HEADERS) - $(CC) $(CFLAGS) -c $< -o $@ +# directories used for local component builds +BUILDDIR = build.dir +# directory configuration for local component builds +DIR_CONFIG = BUILDDIR=$(BUILDDIR) INSTALLDIR=$(INSTALL_ROOT) BIN_PREFIX=$(BIN_PREFIX) -# target is built from all object files -$(TARGET): $(OBJECTS) - $(CC) $(OBJECTS) $(CFLAGS) -o $@ +# ============================================================================== +# supported make options (clean, install...) +.PHONY: default install clean -# support for default, clean and all options -.PHONY: default all clean +# default builds components +default: + cd $(SERVER) && make $(DIR_CONFIG) + cd $(TOOLS) && make $(DIR_CONFIG) -# all calls all other options -all: default +# install handles component installation +install: default + mkdir -p $(INSTALL_ROOT) + cd $(SERVER) && make install $(DIR_CONFIG) + cd $(TOOLS) && make install $(DIR_CONFIG) -# default builds target -default: $(TARGET) - -# clean removed object files and target +# clean removes build and install results clean: - -rm -f *.o - -rm -f $(TARGET) - + cd $(SERVER) && make clean $(DIR_CONFIG) + cd $(TOOLS) && make clean $(DIR_CONFIG) + -rm -rf $(INSTALL_ROOT) diff --git a/README.md b/README.md index e3f8b1c..ede4025 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,40 @@ -moxanix +[![Build Status](https://travis-ci.org/socec/moxanix.svg?branch=master)](https://travis-ci.org/socec/moxanix) + +Moxanix ======= A serial device server, provides console access to multiple serial devices through telnet connection. +Architecture +============ + +The serial device server is broken down into multiple micro servers dedicated to a single serial device and TCP port pair. +These micro servers are then managed by a control script. The control script allows the user to start and stop these micro servers or check their status. +Connections between serial devices and TCP ports are configured in a separate file. +This design allows scalability and customization based on the number of available serial connections and TCP port availability. moxerver -------- -- server application handling the session between a specific TCP port and a specific serial device +- a light server application handling the session between one TCP port and one serial device - allows bidirectional communication -- it is expected to run a separate instance for every serial device +- it is expected to run a separate instance for every serial device and TCP port pair -moxanix.sh ----------- +moxerverctl +----------- - starts, stops or displays status for different moxervers - commands can handle one specific or all moxervers at once + +moxerver.cfg +------------ +- defines connections between serial devices and TCP ports +- each line corresponds to one micro server handling the defined connection + +Build and install +================= + +Run `make` to build the project and `make install` to install it. +This default build will produce artifacts in a directory "install.dir" with executables installed in "usr/bin" (default prefix is "usr"). + +You can install directly into some other directory with `make INSTALL_ROOT=/some/dir`. +You can change the default install prefix for executables with `make BIN_PREFIX=someprefix`. +These options can also be combined into `make INSTALL_ROOT=/some/dir BIN_PREFIX=someprefix` diff --git a/moxerver/Makefile b/moxerver/Makefile new file mode 100644 index 0000000..b04f9d0 --- /dev/null +++ b/moxerver/Makefile @@ -0,0 +1,65 @@ +# target names +TARGET_BINARY = moxerver + +# ============================================================================== + +# directory for build results +BUILDDIR = $(abspath build.dir) +# installation root +INSTALLDIR = $(abspath install.dir) +# prefix for /bin directory +BIN_PREFIX = /usr + +# ============================================================================== + +# add include directories +INCDIRS = -I. +# add library directories +LIBDIRS = -L. +# list used libraries +#LIBS = -lm +LIBS = -lpthread + +# ============================================================================== + +# compiler and flags +CC = gcc +CFLAGS = -Wall $(INCDIRS) $(LIBDIRS) $(LIBS) + +# ============================================================================== + +# build everything in a dedicated directory $(BUILDDIR) + +# objects are .o files created from all .c files in the directory (same name) +OBJECTS = $(patsubst %.c, $(BUILDDIR)/%.o, $(wildcard *.c)) +# headers are all .h files in the directory +HEADERS = $(wildcard *.h) + +# all objects are built from their .c files in the directory +$(BUILDDIR)/%.o: %.c + mkdir -p $(BUILDDIR) + $(CC) $(CFLAGS) -c $< -o $@ + +# target binary is built from all object files +$(BUILDDIR)/$(TARGET_BINARY): $(OBJECTS) + $(CC) $(OBJECTS) $(CFLAGS) -o $@ + +# ============================================================================== + +# supported make options (clean, install...) +.PHONY: all default install clean + +# all calls all other options +all: default install + +# default builds target +default: $(BUILDDIR)/$(TARGET_BINARY) + +# install target binary +install: default + install -Dm0755 $(BUILDDIR)/$(TARGET_BINARY) $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_BINARY) + +# clean removes object files and target (ignore errors with "-" before commands) +clean: + -rm -rf $(BUILDDIR) + -rm -rf $(INSTALLDIR) diff --git a/client.c b/moxerver/client.c similarity index 98% rename from client.c rename to moxerver/client.c index 673c199..65ee94a 100644 --- a/client.c +++ b/moxerver/client.c @@ -133,7 +133,7 @@ int client_ask_username(client_t *client) /* show username request to the client */ snprintf(msg, BUFFER_LEN, - "\nPlease provide a username to identify yourself to" + "\nPlease provide a username to identify yourself to " "other users (max %d characters):\n", USERNAME_LEN); client_write(client, msg, strlen(msg)); diff --git a/client.h b/moxerver/client.h similarity index 100% rename from client.h rename to moxerver/client.h diff --git a/common.h b/moxerver/common.h similarity index 100% rename from common.h rename to moxerver/common.h diff --git a/moxerver.c b/moxerver/moxerver.c similarity index 100% rename from moxerver.c rename to moxerver/moxerver.c diff --git a/server.c b/moxerver/server.c similarity index 100% rename from server.c rename to moxerver/server.c diff --git a/server.h b/moxerver/server.h similarity index 100% rename from server.h rename to moxerver/server.h diff --git a/task_threads.c b/moxerver/task_threads.c similarity index 100% rename from task_threads.c rename to moxerver/task_threads.c diff --git a/task_threads.h b/moxerver/task_threads.h similarity index 100% rename from task_threads.h rename to moxerver/task_threads.h diff --git a/telnet.c b/moxerver/telnet.c similarity index 100% rename from telnet.c rename to moxerver/telnet.c diff --git a/telnet.h b/moxerver/telnet.h similarity index 100% rename from telnet.h rename to moxerver/telnet.h diff --git a/tty.c b/moxerver/tty.c similarity index 100% rename from tty.c rename to moxerver/tty.c diff --git a/tty.h b/moxerver/tty.h similarity index 100% rename from tty.h rename to moxerver/tty.h diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..9bc4e54 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,32 @@ +# target names +TARGET_CONTROL = moxerverctl +TARGET_CONFIG = moxerver.cfg + +# ============================================================================== + +# directory for build results +BUILDDIR = $(abspath build.dir) +# installation root +INSTALLDIR = $(abspath install.dir) +# prefix for /bin directory +BIN_PREFIX = /usr + +# ============================================================================== + +# supported make options (clean, install...) +.PHONY: default install clean + +# default does nothing +default: + +# install targets +install: + # install configuration file + install -Dm0644 $(TARGET_CONFIG) $(INSTALLDIR)/etc/$(TARGET_CONFIG) + # install control script, referring to the configuration file + install -Dm0755 $(TARGET_CONTROL) $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_CONTROL) + sed -i -e 's#ROOT=\"\"#ROOT=$(INSTALLDIR)#' $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_CONTROL) + +# clean removes object files and target (ignore errors with "-" before commands) +clean: + -rm -rf $(INSTALLDIR) diff --git a/moxanix.cfg b/tools/moxerver.cfg similarity index 100% rename from moxanix.cfg rename to tools/moxerver.cfg diff --git a/moxanix.sh b/tools/moxerverctl old mode 100755 new mode 100644 similarity index 94% rename from moxanix.sh rename to tools/moxerverctl index 03b72be..d37eb3e --- a/moxanix.sh +++ b/tools/moxerverctl @@ -4,10 +4,12 @@ # setup # ===== +ROOT="" + # parameters -CONFIGURATION_FILE="./moxanix.cfg" -SERVER_BINARY="./moxerver" -LOG_DIRECTORY="./logs" +CONFIGURATION_FILE="$ROOT/etc/moxerver.cfg" +SERVER_BINARY="moxerver" +LOG_DIRECTORY="$ROOT/var/log/moxerver" # global variables for configuration @@ -61,9 +63,9 @@ do_read_config() # configuration lines CONF_LINES[$CONF_SIZE]=$(echo -n $line) # extract configuration arguments - tcp=$(echo $line | awk '{print $1}' | tr -d "tcp=") - tty=$(echo $line | awk '{print $2}' | tr -d "tty=") - baud=$(echo $line | awk '{print $3}' | tr -d "baud=") + tcp=$(echo $line | awk '{print $1}' | sed -e 's/tcp=//') + tty=$(echo $line | awk '{print $2}' | sed -e 's/tty=//') + baud=$(echo $line | awk '{print $3}' | sed -e 's/baud=//') # compose configuration argument lines for passing to the servers CONF_ARGS[$CONF_SIZE]="-p $tcp -t $tty -b $baud" # increment configuration size (array index)