From 31aea852238dc58182188616c53df8510f4cab4d Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 27 Aug 2007 12:32:55 +0000 Subject: First dummy 'fetch a file' implementation. --- server/etc/Makefile.am | 7 ++++++ server/etc/pracrod.conf | 1 + server/src/server.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ server/xml/Makefile.am | 7 ++++++ server/xml/example.xml | 19 ++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 server/etc/pracrod.conf create mode 100644 server/xml/example.xml diff --git a/server/etc/Makefile.am b/server/etc/Makefile.am index e69de29..eb5b4aa 100644 --- a/server/etc/Makefile.am +++ b/server/etc/Makefile.am @@ -0,0 +1,7 @@ +EXTRA_DIST = \ + pracrod.conf + +sysconfdir=${prefix}/etc/ + +dist_sysconf_DATA = \ + pracrod.conf diff --git a/server/etc/pracrod.conf b/server/etc/pracrod.conf new file mode 100644 index 0000000..ddf1856 --- /dev/null +++ b/server/etc/pracrod.conf @@ -0,0 +1 @@ +port = 12345; diff --git a/server/src/server.cc b/server/src/server.cc index 7f78f45..9d52369 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -26,6 +26,9 @@ */ #include "server.h" +// For XML +#include + #include "tcpsocket.h" #include @@ -37,9 +40,65 @@ #include "configuration.h" +// For open, read and close +#include +#include +#include +#include + + +/** +\section{Data transmission} +En transmission består af en række deltransmissioner som afhænger af +brugerens handling. +\begin{itemize} +\item Klienten beder om en XMLMakro by-name. +\item Serveren genererer makroen og sender den til klienten i en XML + stream. Forbindelsen lukkes efter end overførsel. +\item Brugeren udfylder input felterne og trykker på ``commit'' eller + ``abort'' knappen. +\item Hvis der blev trykket ``abort'' lukkes vinduet. +\item Hvis der blev trykket ``commit'' genereres et XML dokument på + klienten indeholdene alle input felternes navne og deres tilhørende + værdier. +\item Dette XML dokument sendes til serveren via en nyoprettet forbindelse. +\item Serveren producerer en plaintext klump som repræsenterer +\item Teksten sendes til klienten som appender til den PC-Praxis + journalfilen. +\item Klienten svarer til serveren at alt gik godt (eller det modsatte) og + makrovinduet lukkes. +\item Serveren lagrer dataene i en database hvis det gik godt. +\end{itemize} +*/ static void connection(Pentominos::TCPSocket &socket) { printf("Got connection...\n"); + + std::string macro_request; + + char inbuf[300]; // Must be at least 3 + memset(inbuf, 0, sizeof(inbuf)); // Ensure zero termination. + + // Get request. + while(socket.read(inbuf, sizeof(inbuf) - 1) == sizeof(inbuf) - 1) { + macro_request += inbuf; + memset(inbuf, 0, sizeof(inbuf)); // Ensure zero termination. + } + macro_request += inbuf; + + printf("Got request for [%s]\n", macro_request.c_str()); + + // Now handle the request. + char outbuf[3]; + int bytes; + + std::string macro = std::string(XML) + "/" + macro_request + ".xml"; + + int fd = open(macro.c_str(), O_RDONLY); + while((bytes = read(fd, outbuf, sizeof(outbuf))) ) { + socket.write(outbuf, bytes); + } + close(fd); } void server() diff --git a/server/xml/Makefile.am b/server/xml/Makefile.am index e69de29..3ad491e 100644 --- a/server/xml/Makefile.am +++ b/server/xml/Makefile.am @@ -0,0 +1,7 @@ +EXTRA_DIST = \ + example.xml + +xmldir = $(datadir)/xml + +xml_DATA = \ + example.xml diff --git a/server/xml/example.xml b/server/xml/example.xml new file mode 100644 index 0000000..03e2d59 --- /dev/null +++ b/server/xml/example.xml @@ -0,0 +1,19 @@ + + + + + +