diff options
author | deva <deva> | 2008-05-20 14:03:10 +0000 |
---|---|---|
committer | deva <deva> | 2008-05-20 14:03:10 +0000 |
commit | 556f00e4af55e78836c45f47b0662ab44bbb8b48 (patch) | |
tree | a5c315b35d400a397a35a86b86fe656d3a829af9 /server/src | |
parent | 91d56787bec83a3a7c2ad6afd84d2b82c5d869b9 (diff) |
Made fixes pointed out by GCC 4.2 and -D_FORTIFY_SOURCES=2
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/daemon.cc | 6 | ||||
-rw-r--r-- | server/src/database.cc | 2 | ||||
-rw-r--r-- | server/src/journal_commit.cc | 10 | ||||
-rw-r--r-- | server/src/pracrod.cc | 7 | ||||
-rw-r--r-- | server/src/queryhandler.cc | 7 | ||||
-rw-r--r-- | server/src/queryparser.cc | 13 | ||||
-rw-r--r-- | server/src/queryparser.h | 1 | ||||
-rw-r--r-- | server/src/saxparser.cc | 16 | ||||
-rw-r--r-- | server/src/saxparser.h | 2 | ||||
-rw-r--r-- | server/src/server.cc | 13 | ||||
-rw-r--r-- | server/src/templateparser.cc | 40 | ||||
-rw-r--r-- | server/src/templateparser.h | 5 | ||||
-rw-r--r-- | server/src/transactionparser.cc | 9 | ||||
-rw-r--r-- | server/src/transactionparser.h | 2 |
14 files changed, 88 insertions, 45 deletions
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 ¯o = (*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 ¯o = (*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); |