summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordeva <deva>2007-08-27 12:32:55 +0000
committerdeva <deva>2007-08-27 12:32:55 +0000
commit31aea852238dc58182188616c53df8510f4cab4d (patch)
treeda5fee9b5436d8ba4cbde4975a3c82f04e3fd2d3 /server
parent9591262f6204c31f622f57be28b3d727470e2fce (diff)
First dummy 'fetch a file' implementation.
Diffstat (limited to 'server')
-rw-r--r--server/etc/Makefile.am7
-rw-r--r--server/etc/pracrod.conf1
-rw-r--r--server/src/server.cc59
-rw-r--r--server/xml/Makefile.am7
-rw-r--r--server/xml/example.xml19
5 files changed, 93 insertions, 0 deletions
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 <config.h>
+
#include "tcpsocket.h"
#include <errno.h>
@@ -37,9 +40,65 @@
#include "configuration.h"
+// For open, read and close
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+/**
+\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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<macro name="test_macro" cpr="1505050505" version="1.0" macro_version="1.0">
+ <window name="mainwindow"
+ caption="This is the mainwindow"
+ width="800"
+ height="600"
+ layout="vbox">
+ <include name="patient"/>
+ <frame name="data_frame" layout="hbox">
+ <label caption="Some field"/>
+ <lineedit name="lineedit1" regexp="[0-9]+"/>
+ </frame>
+ <frame name="bottom_frame" layout="hbox">
+ <spacer />
+ <button caption="Close window" action="abort"/>
+ <button caption="Commit changes" action="commit"/>
+ </frame>
+ </window>
+</macro>