diff options
author | deva <deva> | 2007-09-24 12:47:16 +0000 |
---|---|---|
committer | deva <deva> | 2007-09-24 12:47:16 +0000 |
commit | a3cb015e6b69821062306981924a43a5487f3b5d (patch) | |
tree | fcacf4cab2bf2d188775b11f2f53fbf5a9235d7a /server/src/server.cc | |
parent | 574f7c69a0cb7d3af3e20d740e6202d2faaf2718 (diff) |
Server now parses XML and handles include.
Diffstat (limited to 'server/src/server.cc')
-rw-r--r-- | server/src/server.cc | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/server/src/server.cc b/server/src/server.cc index 24f55ef..064d8b9 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -26,9 +26,6 @@ */ #include "server.h" -// For XML -#include <config.h> - #include "tcpsocket.h" #include <errno.h> @@ -40,40 +37,33 @@ #include "configuration.h" -// For open, read and close -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - #include "transaction.h" #include "xmlparser.h" #include "database.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} -*/ +#include "macro.h" +#include "macro_parser.h" + +static void send_macro_widget(Widget &widget, TCPSocket &socket, std::string tabs) +{ + socket.write(tabs + "<" + widget.type); + WidgetPropertyList::iterator p = widget.properties.begin(); + while(p != widget.properties.end()) { + WidgetProperty &property = *p; + socket.write(" " + property.name + "=\"" + property.value + "\""); + p++; + } + socket.write(">\n"); + + WidgetList::iterator w = widget.widgets.begin(); + while(w != widget.widgets.end()) { + send_macro_widget(*w, socket, tabs + " "); + w++; + } + socket.write(tabs + "</" + widget.type + ">\n"); +} + static void connection(TCPSocket &socket) { printf("Got connection...\n"); @@ -91,24 +81,14 @@ static void connection(TCPSocket &socket) printf("Handling request for \"%s\"...", request.macro.c_str()); - // Now handle the request. - char outbuf[3]; - int bytes; - - std::string macro = std::string(XML) + "/" + request.macro + ".xml"; - - int fd = open(macro.c_str(), O_RDONLY); - if(fd == -1) { - printf("Cannot open file \"%s\"...", macro.c_str()); - printf("failed!\n"); - i++; - continue; - } + Macro macro; + parse_macro(request.macro, macro); - while((bytes = read(fd, outbuf, sizeof(outbuf))) ) { - socket.write(outbuf, bytes); + WidgetList::iterator w = macro.widgets.begin(); + while(w != macro.widgets.end()) { + send_macro_widget(*w, socket, " "); + w++; } - close(fd); printf("done.\n"); |