summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordeva <deva>2008-05-20 14:03:10 +0000
committerdeva <deva>2008-05-20 14:03:10 +0000
commit556f00e4af55e78836c45f47b0662ab44bbb8b48 (patch)
treea5c315b35d400a397a35a86b86fe656d3a829af9 /server
parent91d56787bec83a3a7c2ad6afd84d2b82c5d869b9 (diff)
Made fixes pointed out by GCC 4.2 and -D_FORTIFY_SOURCES=2
Diffstat (limited to 'server')
-rw-r--r--server/NOTES11
-rw-r--r--server/configure.in10
-rw-r--r--server/src/daemon.cc6
-rw-r--r--server/src/database.cc2
-rw-r--r--server/src/journal_commit.cc10
-rw-r--r--server/src/pracrod.cc7
-rw-r--r--server/src/queryhandler.cc7
-rw-r--r--server/src/queryparser.cc13
-rw-r--r--server/src/queryparser.h1
-rw-r--r--server/src/saxparser.cc16
-rw-r--r--server/src/saxparser.h2
-rw-r--r--server/src/server.cc13
-rw-r--r--server/src/templateparser.cc40
-rw-r--r--server/src/templateparser.h5
-rw-r--r--server/src/transactionparser.cc9
-rw-r--r--server/src/transactionparser.h2
-rw-r--r--server/xml/Makefile.am2
-rw-r--r--server/xml/example2.xml26
18 files changed, 124 insertions, 58 deletions
diff --git a/server/NOTES b/server/NOTES
index 9f72b34..59bfc3c 100644
--- a/server/NOTES
+++ b/server/NOTES
@@ -1,3 +1,14 @@
+-*- text -*-
+###################
+# Svar fra server #
+###################
+Svaret fra pracro serveren til klienten skal udover svar på eventuelle
+makro queries indeholde en liste af errorcodes tilhørende de atomare
+elementer i transaktionne, specielt commits.
+
+Det er vigtigt at man på klienten kan få at vide hvis der gik noget
+galt i en commit.
+
############
# Ordliste #
############
diff --git a/server/configure.in b/server/configure.in
index f2c6f7e..8cfb673 100644
--- a/server/configure.in
+++ b/server/configure.in
@@ -3,6 +3,15 @@
AC_INIT(src/pracrod.cc)
AM_INIT_AUTOMAKE( pracrod, 0.0.1 )
+dnl ======================
+dnl Compile with debug options
+dnl ======================
+AC_ARG_WITH(debug, [ --with-debug build with debug support])
+if test x$with_debug == xyes; then
+ AC_MSG_WARN([*** Building with debug support!])
+ CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0"
+fi
+
AC_PROG_CXX
AC_PROG_LIBTOOL
@@ -23,7 +32,6 @@ fi
AC_SUBST(MYPREFIX)
AC_DEFINE_UNQUOTED(ETC, "$MYPREFIX/etc", [The path to the config files])
-
dnl ======================
dnl Use efence in linking and includes
dnl ======================
diff --git a/server/src/daemon.cc b/server/src/daemon.cc
index a88fa39..655a234 100644
--- a/server/src/daemon.cc
+++ b/server/src/daemon.cc
@@ -81,7 +81,7 @@ Daemon::~Daemon()
int Daemon::run(const char *user, const char* group, bool detach)
{
- int f;
+ // int f;
int fd;
// Fetch user and group IDs
@@ -103,7 +103,9 @@ int Daemon::run(const char *user, const char* group, bool detach)
}
}
- chdir("/");
+ if(chdir("/")) {
+ fprintf(stderr, "Could not chdir to / : %s\n", strerror(errno));
+ }
umask(0);
if(detach) {
diff --git a/server/src/database.cc b/server/src/database.cc
index b2d5589..018f3bd 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -44,7 +44,7 @@ Database::~Database()
int Database::post(std::string &user, std::string &cpr, time_t now, Commit &commit)
{
char timestamp[32];
- sprintf(timestamp, "%u", now);
+ sprintf(timestamp, "%u", (unsigned int)now);
UID uid;
try {
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc
index 336ac7a..4b79a65 100644
--- a/server/src/journal_commit.cc
+++ b/server/src/journal_commit.cc
@@ -44,7 +44,7 @@
//#define NO_NETWORK
-static int mwrite(int sock, char *fmt, ...)
+static int mwrite(int sock, const char *fmt, ...)
{
int l = 0;
va_list args;
@@ -56,7 +56,9 @@ static int mwrite(int sock, char *fmt, ...)
l = vsnprintf(buffer, 64*1024, fmt, args);
va_end(args);
- write(sock, buffer, l);
+ if(write(sock, buffer, l) != l) {
+ fprintf(stderr, "write did not write all the bytes in the buffer.\n");
+ }
free(buffer);
@@ -115,7 +117,9 @@ int journal_commit(const char *cpr, const char *user,
mwrite(sock, "\r\n");
// send body
- write(sock, buf, size);
+ if(write(sock, buf, size) != (ssize_t)size) {
+ fprintf(stderr, "write did not write all the bytes in the buffer.\n");
+ }
// close socket
close(sock);
diff --git a/server/src/pracrod.cc b/server/src/pracrod.cc
index 134b212..fe8fb63 100644
--- a/server/src/pracrod.cc
+++ b/server/src/pracrod.cc
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
int option_index = 0;
while(1) {
- int this_option_optind = optind ? optind : 1;
+ // int this_option_optind = optind ? optind : 1;
static struct option long_options[] = {
{"foreground", no_argument, 0, 'f'},
{"config", required_argument, 0, 'c'},
@@ -167,8 +167,11 @@ int main(int argc, char *argv[])
}
}
+ char defval[512];
+ sprintf(defval, ETC"/pracrod.conf");
+
char *cfname = NULL;
- if(!configfile) cfname = ETC"/pracrod.conf";
+ if(!configfile) cfname = defval;//ETC"/pracrod.conf";
else cfname = configfile;
Configuration conf(cfname);
initConfig(&conf);
diff --git a/server/src/queryhandler.cc b/server/src/queryhandler.cc
index b78f8c4..b9ff7a1 100644
--- a/server/src/queryhandler.cc
+++ b/server/src/queryhandler.cc
@@ -62,7 +62,7 @@ typedef struct {
#define SIOCGIFCONF 0x8912 // get iface list
-static in_addr_t getIP(char *interface)
+static in_addr_t getIP(const char *interface)
{
in_addr_t ret = 0;
int numreqs = 30, sd, n;
@@ -112,7 +112,7 @@ static unsigned short getCounter()
}
static UID uid = {0,0,0,0};
-static std::string getUID(char *interface)
+static std::string getUID(const char *interface)
{
if(!uid.ip) uid.ip = getIP(interface);
@@ -188,7 +188,8 @@ std::string QueryHandler::exec()
socket->write(buf, strlen(buf));
// Terminate
- socket->write("\0", 1);
+ char term[] = "\0";
+ socket->write(term, 1);
// Wait for answer
char abuf[64];
diff --git a/server/src/queryparser.cc b/server/src/queryparser.cc
index 9649f1f..889810f 100644
--- a/server/src/queryparser.cc
+++ b/server/src/queryparser.cc
@@ -29,6 +29,10 @@
QueryParser::QueryParser(std::string document)
{
this->document = document;
+
+ // Make sure we always contain a valid xml document.
+ if(this->document == "") this->document = "<xml></xml>";
+
p = 0;
stack.push_back(&result);
}
@@ -62,6 +66,15 @@ int QueryParser::readData(char *data, size_t size)
return len;
}
+void QueryParser::parseError(char *buf, size_t len, std::string error, int lineno)
+{
+ fprintf(stderr, "QueryParser error at line %d: %s\n", lineno, error.c_str());
+ fprintf(stderr, "\tBuffer %u bytes: [", len);
+ if(fwrite(buf, len, 1, stderr) != len) {}
+ fprintf(stderr, "]\n");
+ fflush(stderr);
+}
+
#ifdef TEST_QUERYPARSER
#include "queryhandler.h"
diff --git a/server/src/queryparser.h b/server/src/queryparser.h
index 58f7f37..4a499a7 100644
--- a/server/src/queryparser.h
+++ b/server/src/queryparser.h
@@ -41,6 +41,7 @@ public:
void startTag(std::string name, std::map< std::string, std::string> attributes);
void endTag(std::string name);
+ void parseError(char *buf, size_t len, std::string error, int lineno);
QueryResult result;
diff --git a/server/src/saxparser.cc b/server/src/saxparser.cc
index e8e9eb4..5580e5b 100644
--- a/server/src/saxparser.cc
+++ b/server/src/saxparser.cc
@@ -90,10 +90,8 @@ int SAXParser::parse()
do {
len = readData(buf, sizeof(buf) - 1);
if (! XML_Parse(p, buf, len, len == 0)) {
- fprintf(stderr, "Parse error at line %d:\n%s\n",
- (int)XML_GetCurrentLineNumber(p),
- XML_ErrorString(XML_GetErrorCode(p)));
- return -1;
+ parseError(buf, len, XML_ErrorString(XML_GetErrorCode(p)), (int)XML_GetCurrentLineNumber(p));
+ return 1;
}
memset(buf, 0, sizeof(buf));
@@ -102,6 +100,16 @@ int SAXParser::parse()
return 0;
}
+void SAXParser::parseError(char *buf, size_t len, std::string error, int lineno)
+{
+ fprintf(stderr, "SAXParser error at line %d: %s\n", lineno, error.c_str());
+ fprintf(stderr, "\tBuffer %u bytes: [", len);
+ if(fwrite(buf, len, 1, stderr) != len) {}
+ fprintf(stderr, "]\n");
+ fflush(stderr);
+}
+
+
#ifdef TEST_SAXPARSER
/**
* Compile with: g++ -DTEST_SAXPARSER sax_parser.cc -lexpat -otext_saxparser
diff --git a/server/src/saxparser.h b/server/src/saxparser.h
index 3cb7997..65f17fe 100644
--- a/server/src/saxparser.h
+++ b/server/src/saxparser.h
@@ -42,6 +42,8 @@ public:
virtual void startTag(std::string name, std::map< std::string, std::string> attributes) {}
virtual void endTag(std::string name) {}
+ virtual void parseError(char *buf, size_t len, std::string error, int lineno);
+
protected:
virtual int readData(char *data, size_t size) { return 0; }
diff --git a/server/src/server.cc b/server/src/server.cc
index 1786f34..2f89c73 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -110,7 +110,6 @@ static void connection(TCPSocket &socket)
std::vector< Macro >::iterator mi = templ->course.macroes.begin();
while(mi != templ->course.macroes.end()) {
- printf("!!\n"); fflush(stdout);
Macro &macro = (*mi);
if(macro.attributes["name"] == request.macro) {
std::vector< Query >::iterator qi = macro.queries.begin();
@@ -123,6 +122,8 @@ static void connection(TCPSocket &socket)
}
std::string result = qh.exec();
+ printf("Got result: [%s]\n", result.c_str());
+
// Parse the result from the queries to pentominos
QueryParser qp(result);
qp.parse();
@@ -134,6 +135,7 @@ static void connection(TCPSocket &socket)
std::vector< Macro >::iterator mi2 = templ->course.macroes.begin();
while(mi2 != templ->course.macroes.end()) {
Macro &macro = (*mi2);
+ printf("Macro: %s ?= %s\n", macro.attributes["name"].c_str(), request.macro.c_str());
if(macro.attributes["name"] == request.macro) {
widgetgenerator(socket, macro, lqm);
}
@@ -158,7 +160,7 @@ void server()
return;
}
- TCPSocket *socket;
+ TCPSocket *socket = NULL;
try {
socket = new TCPSocket();
@@ -167,6 +169,7 @@ void server()
fprintf(stderr, "Error during parsing:\n%s\n",
e.what());
delete socket;
+ socket = NULL;
return;
}
@@ -192,9 +195,9 @@ void server()
TCPSocket child = socket->accept();
if(child.connected()) {
- socket->disconnect();
- connection(child);
- delete socket;
+ //socket->disconnect();
+ connection(child);
+ //delete socket;
/*
switch(fork()) {
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc
index 652a870..7a2a013 100644
--- a/server/src/templateparser.cc
+++ b/server/src/templateparser.cc
@@ -45,7 +45,7 @@
#include <errno.h>
-void TemplateParser::error(char* fmt, ...)
+void TemplateParser::error(const char* fmt, ...)
{
// TODO: Throw exception here.
@@ -66,7 +66,7 @@ TemplateParser::TemplateParser(std::string course)
current_macro = NULL;
current_map = NULL;
- std::string file = XML"/";
+ file = XML"/";
file.append(course);
file.append(".xml");
@@ -127,7 +127,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
assert(t); // A Template has not yet been allocated, cannot create macro!
Macro m;
- // m.attributes = attributes;
+ m.attributes = attributes;
t->course.macroes.push_back(m);
current_macro = &(t->course.macroes.back());
@@ -195,9 +195,6 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
current_macro->window.attributes["type"] = name;
Widget *current = &(current_macro->window);
-
- printf("%p %p\n", current); fflush(stdout);
-
widgetstack.push_back(current);
return;
@@ -213,21 +210,12 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
w.attributes = attributes;
w.attributes["type"] = name;
- printf("1 %d\n", widgetstack.size() ); fflush(stdout);
-
Widget *parent = widgetstack.back();
-
- printf("%d\n", parent->widgets.size()); fflush(stdout);
-
parent->widgets.push_back(w);
-
- printf("2\n"); fflush(stdout);
Widget *current = &(parent->widgets.back());
widgetstack.push_back(current);
- printf("3\n"); fflush(stdout);
-
return;
}
@@ -258,23 +246,18 @@ void TemplateParser::endTag(std::string name)
if(name == "window") state = MACRO;
if(state == WINDOW) {
-
- printf("4\n"); fflush(stdout);
-
assert(widgetstack.size()); // Widget stack is empty, cannot pop!
widgetstack.pop_back();
-
- printf("5\n"); fflush(stdout);
-
if(widgetstack.size() == 0) state = MACRO;
-
- printf("6\n"); fflush(stdout);
}
}
int TemplateParser::readData(char *data, size_t size)
{
- if(fd == -1) return 0;
+ if(fd == -1) {
+ fprintf(stderr, "Invalid file descriptor.\n"); fflush(stderr);
+ return 0;
+ }
ssize_t r = read(fd, data, size);
if(r == -1) {
printf("Could not read...%s\n", strerror(errno)); fflush(stdout);
@@ -283,6 +266,15 @@ int TemplateParser::readData(char *data, size_t size)
return r;
}
+void TemplateParser::parseError(char *buf, size_t len, std::string error, int lineno)
+{
+ fprintf(stderr, "TemplateParser[%s] error at line %d: %s\n", file.c_str(), lineno, error.c_str());
+ fprintf(stderr, "\tBuffer %u bytes: [", len);
+ if(fwrite(buf, len, 1, stderr) != len) {}
+ fprintf(stderr, "]\n");
+ fflush(stderr);
+}
+
Template *TemplateParser::getTemplate()
{
return t;
diff --git a/server/src/templateparser.h b/server/src/templateparser.h
index 6e5fb1a..425030f 100644
--- a/server/src/templateparser.h
+++ b/server/src/templateparser.h
@@ -50,6 +50,7 @@ public:
void characterData(std::string &data);
void startTag(std::string name, std::map< std::string, std::string> attributes);
void endTag(std::string name);
+ void parseError(char *buf, size_t len, std::string error, int lineno);
Template *getTemplate();
@@ -59,6 +60,8 @@ protected:
private:
int fd;
+ std::string file;
+
// Parser state data
ParserState state;
Template *t;
@@ -67,7 +70,7 @@ private:
std::vector< Widget* > widgetstack;
// Error callback function.
- void error(char* fmt, ...);
+ void error(const char* fmt, ...);
};
#endif/*__PRACRO_TEMPLATEPARSER_H__*/
diff --git a/server/src/transactionparser.cc b/server/src/transactionparser.cc
index 547a9a7..47df2bc 100644
--- a/server/src/transactionparser.cc
+++ b/server/src/transactionparser.cc
@@ -77,3 +77,12 @@ int TransactionParser::readData(char *data, size_t size)
if(done) return 0;
return socket->read(data, size);
}
+
+void TransactionParser::parseError(char *buf, size_t len, std::string error, int lineno)
+{
+ fprintf(stderr, "TransactionParser error at line %d: %s\n", lineno, error.c_str());
+ fprintf(stderr, "\tBuffer %u bytes: [", len);
+ if(fwrite(buf, len, 1, stderr) != len) {}
+ fprintf(stderr, "]\n");
+ fflush(stderr);
+}
diff --git a/server/src/transactionparser.h b/server/src/transactionparser.h
index 9528e47..2587a42 100644
--- a/server/src/transactionparser.h
+++ b/server/src/transactionparser.h
@@ -38,6 +38,8 @@ public:
void startTag(std::string name, std::map< std::string, std::string> attributes);
void endTag(std::string name);
+ void parseError(char *buf, size_t len, std::string error, int lineno);
+
protected:
int readData(char *data, size_t size);
diff --git a/server/xml/Makefile.am b/server/xml/Makefile.am
index ba48c9b..62905db 100644
--- a/server/xml/Makefile.am
+++ b/server/xml/Makefile.am
@@ -1,11 +1,9 @@
EXTRA_DIST = \
- example.xml \
patient.xml \
start.xml
xmldir = $(datadir)/xml
xml_DATA = \
- example.xml \
patient.xml \
start.xml
diff --git a/server/xml/example2.xml b/server/xml/example2.xml
index 42f4755..d30bfec 100644
--- a/server/xml/example2.xml
+++ b/server/xml/example2.xml
@@ -1,21 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version='1.0' encoding='UTF-8'?>
<template name="testcourse">
<course>
<macro name="example2" version="1.0"
- resume="${linse1}
-${linse2}">
+ resume="${linse1}${linse2}">
<queries>
- <query class="lensmeter" ttl="10000"/>
- <query class="autophoropter" ttl="10000" automap="true"/>
+ <query device_id="lensmeter" device_type="lensmeter" class="lensmeter" ttl="10000"/>
</queries>
<maps>
<map name="axis">
-- LUA program
return right.axis
</map>
- <map name="dioptri">
+ <map name="sphere">
-- LUA program
- return right.dioptri
+ return right.sphere
+ </map>
+ <map name="cyl">
+ -- LUA program
+ return right.cyl
</map>
</maps>
<window name="mainwindow"
@@ -26,11 +28,15 @@ ${linse2}">
<frame name="linse_frame" caption="Linser:" layout="vbox">
<frame name="linse_framea" layout="hbox">
<label name="a" width="300" caption="Akse rotation:"/>
- <lineedit name="linse1" regexp="[0-9]{1,3}D" map="axis" value="90K"/>
+ <lineedit name="linse1" regexp="[0-9]{1,3}" map="axis" value="90K"/>
</frame>
<frame name="linse_frameb" layout="hbox">
- <label name="b" width="300" caption="Diotri:"/>
- <lineedit name="linse2" regexp="[0-9]{1,3}D" map="dioptri" value="90K"/>
+ <label name="b" width="300" caption="Sphere:"/>
+ <lineedit name="linse2" regexp="[0-9]{1,3}" map="sphere" value="90K"/>
+ </frame>
+ <frame name="linse_framec" layout="hbox">
+ <label name="c" width="300" caption="Sphere:"/>
+ <lineedit name="linse3" regexp="[0-9]{1,3}" map="cyl" value="90K"/>
</frame>
</frame>
<frame name="buttons" layout="hbox">