summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/database.cc23
-rw-r--r--server/src/database.h2
-rw-r--r--server/src/journal_commit.cc17
-rw-r--r--server/src/queryhandler.cc26
4 files changed, 51 insertions, 17 deletions
diff --git a/server/src/database.cc b/server/src/database.cc
index 2b8b83c..96aa697 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -26,6 +26,8 @@
*/
#include "database.h"
+#include <config.h>
+
Database::Database(std::string hostname, std::string user, std::string password)
#ifndef WITHOUT_DB
: c("host=" + hostname + " user=" + user + " password=" + password + " dbname=pracro")
@@ -74,9 +76,12 @@ void Database::commit(std::string user,
oid << R.inserted_oid();
#else
oid << "###GENERATED_OID###";
- printf("%s\n", ts.c_str());
#endif/*WITHOUT_DB*/
+#ifdef WITH_DEBUG
+ printf("%s\n", ts.c_str());
+#endif/*WITH_DEBUG*/
+
std::map< std::string, std::string >::iterator i = fields.begin();
while(i != fields.end()) {
@@ -86,9 +91,11 @@ void Database::commit(std::string user,
#ifndef WITHOUT_DB
W.exec(fs);
-#else
- printf("%s\n", fs.c_str());
#endif/*WITHOUT_DB*/
+
+#ifdef WITH_DEBUG
+ printf("%s\n", fs.c_str());
+#endif/*WITH_DEBUG*/
i++;
}
@@ -158,9 +165,11 @@ Values Database::getValues(std::string cpr,
ri++;
}
-#else
- printf("%s\n", query.str().c_str());
#endif/*WITHOUT_DB*/
+
+#ifdef WITH_DEBUG
+ printf("%s\n", query.str().c_str());
+#endif/*WITH_DEBUG*/
return values;
}
@@ -181,6 +190,10 @@ bool Database::checkMacro(std::string cpr,
query << " AND timestamp >= " << oldest;
query << " ORDER BY timestamp";
+#ifdef WITH_DEBUG
+ printf("%s\n", query.str().c_str());
+#endif/*WITH_DEBUG*/
+
#ifndef WITHOUT_DB
try {
pqxx::result R = W.exec(query.str());
diff --git a/server/src/database.h b/server/src/database.h
index bd3139e..c15aca5 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -27,6 +27,8 @@
#ifndef __PRACRO_DATABASE_H__
#define __PRACRO_DATABASE_H__
+#include <config.h>
+
#include <pqxx/pqxx>
#include <string>
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc
index b1ae866..c10e8c7 100644
--- a/server/src/journal_commit.cc
+++ b/server/src/journal_commit.cc
@@ -26,6 +26,8 @@
*/
#include "journal_commit.h"
+#include <config.h>
+
// for gethostbyname
#include <netdb.h>
@@ -48,18 +50,22 @@ static int mwrite(int sock, const char *fmt, ...)
va_list args;
char *buffer;
- buffer = (char*)malloc(64*1024);
+ buffer = (char*)calloc(64*1024, 1);
va_start(args, fmt);
l = vsnprintf(buffer, 64*1024, fmt, args);
va_end(args);
- if(write(sock, buffer, l) != l) {
+ if(sock != -1 && write(sock, buffer, l) != l) {
fprintf(stderr, "write did not write all the bytes in the buffer.\n");
}
free(buffer);
+#ifdef WITH_DEBUG
+ printf(buffer);
+#endif/*WITH_DEBUG*/
+
return l;
}
@@ -67,7 +73,7 @@ int journal_commit(const char *cpr, const char *user,
const char *addr, unsigned short int port,
const char *buf, size_t size)
{
- int sock = 1;
+ int sock = -1;
#ifndef WITHOUT_UPLOADSERVER
struct sockaddr_in sin;
@@ -116,9 +122,12 @@ int journal_commit(const char *cpr, const char *user,
mwrite(sock, "\r\n");
// send body
- if(write(sock, buf, size) != (ssize_t)size) {
+ if(sock != -1 && write(sock, buf, size) != (ssize_t)size) {
fprintf(stderr, "write did not write all the bytes in the buffer.\n");
}
+#ifdef WITH_DEBUG
+ printf(buf);
+#endif/*WITH_DEBUG*/
#ifndef WITHOUT_UPLOADSERVER
// close socket
diff --git a/server/src/queryhandler.cc b/server/src/queryhandler.cc
index 573ce3a..29e8fda 100644
--- a/server/src/queryhandler.cc
+++ b/server/src/queryhandler.cc
@@ -26,6 +26,8 @@
*/
#include "queryhandler.h"
+#include <config.h>
+
// For time
#include <time.h>
@@ -155,10 +157,12 @@ std::string QueryHandler::exec()
" xsi:schemaLocation=\"http://www.aasimon.org/pentominos schema.xsd\">\n";
#ifndef WITHOUT_PENTOMINOS
socket->write(header, strlen(header));
-#else
- printf(header);
#endif/*WITHOUT_PENTOMINOS*/
+#ifdef WITH_DEBUG
+ printf(header);
+#endif/*WITH_DEBUG*/
+
sprintf(buf, " <pentominos:entry cpr=\"%s\"\n"
" src_addr=\"%s\"\n"
" dst_addr=\"%s\"\n"
@@ -176,10 +180,12 @@ std::string QueryHandler::exec()
uid.c_str());
#ifndef WITHOUT_PENTOMINOS
socket->write(buf, strlen(buf));
-#else
- printf(buf);
#endif/*WITHOUT_PENTOMINOS*/
+#ifdef WITH_DEBUG
+ printf(buf);
+#endif/*WITH_DEBUG*/
+
std::vector< Query >::iterator j = queries.begin();
while(j != queries.end()) {
Query query = *j;
@@ -194,10 +200,12 @@ std::string QueryHandler::exec()
#ifndef WITHOUT_PENTOMINOS
socket->write(buf, strlen(buf));
-#else
- printf(buf);
#endif/*WITHOUT_PENTOMINOS*/
+#ifdef WITH_DEBUG
+ printf(buf);
+#endif/*WITH_DEBUG*/
+
j++;
}
@@ -208,10 +216,12 @@ std::string QueryHandler::exec()
// Terminate
char term[] = "\0";
socket->write(term, 1);
-#else
- printf(buf);
#endif/*WITHOUT_PENTOMINOS*/
+#ifdef WITH_DEBUG
+ printf(buf);
+#endif/*WITH_DEBUG*/
+
std::string answer;
#ifndef WITHOUT_PENTOMINOS