summaryrefslogtreecommitdiff
path: root/server/src/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/server.cc')
-rw-r--r--server/src/server.cc40
1 files changed, 17 insertions, 23 deletions
diff --git a/server/src/server.cc b/server/src/server.cc
index 3e41d67..b49f5b2 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -93,9 +93,10 @@ static std::string handleTransaction(Transaction *transaction,
mp.parse();
Macro *macro = mp.getMacro();
- db->commit(transaction->user, transaction->cpr, *macro, commit.fields);
-
std::string resume = resume_parser(macro->resume, commit);
+ commit.fields["journal.resume"] = resume;
+ db->commitTransaction(transaction->user, transaction->cpr, *macro, commit.fields);
+
bool store_in_journal = true;
// We always need to store in journal!
@@ -108,9 +109,6 @@ static std::string handleTransaction(Transaction *transaction,
resume.c_str(), resume.length());
}
- db->putResume(transaction->user, transaction->cpr,
- *macro, resume, time(NULL), store_in_journal);
-
i++;
}
}
@@ -122,7 +120,7 @@ static std::string handleTransaction(Transaction *transaction,
while(i != transaction->requests.end()) {
Request &request = *i;
- printf("Handling request - macro: %s, course: %s\n",
+ PRACRO_DEBUG(server, "Handling request - macro: %s, course: %s\n",
request.macro.c_str(), request.course.c_str());
// Read and parse the template file.
@@ -219,7 +217,7 @@ static std::string handleTransaction(Transaction *transaction,
if(completed) {
answer += " <resume>";
- answer += db->getResume(transaction->cpr, macro.attributes["name"], time(NULL) - Conf::db_max_ttl);
+ answer += db->getResume(transaction->cpr, macro, time(NULL) - Conf::db_max_ttl);
answer += "</resume>\n";
}
@@ -238,14 +236,12 @@ static std::string handleTransaction(Transaction *transaction,
answer += "</pracro>\n";
- } catch( PGSTD::runtime_error &e ) {
- answer = error_box(xml_encode(std::string("PostgreSQL server error:\n") + e.what()));
} catch( std::exception &e ) {
answer = error_box(xml_encode(e.what()));
}
- printf("Done handling transaction\n");
-
+ PRACRO_DEBUG(server, "Done handling transaction\n");
+ PRACRO_DEBUG(serverxml, "%s\n", answer.c_str());
return answer;
}
@@ -257,7 +253,7 @@ static void handleConnection(TCPSocket *socket)
pentominos_socket.connect(Conf::pentominos_addr, Conf::pentominos_port);
#endif/*WITHOUT_PENTOMINOS*/
- Database db(Conf::database_addr, Conf::database_user, Conf::database_passwd);
+ Database *db = new Database("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, "");
ssize_t size;
char buf[4096];
@@ -268,7 +264,7 @@ static void handleConnection(TCPSocket *socket)
// while( (size = socket->read(buf, sizeof(buf))) != -1) {
while( (size = socket->read(buf, sizeof(buf))) > 0) {
- printf("Read %d bytes from network\n", size);
+ PRACRO_DEBUG(server, "Read %d bytes from network\n", size);
while(size) {
@@ -280,13 +276,11 @@ static void handleConnection(TCPSocket *socket)
parser = new TransactionParser(transaction);
}
- printf("Got %d bytes in read loop\n", size);
+ PRACRO_DEBUG(server, "Got %d bytes in read loop\n", size);
if(parser->parse(buf, size)) {
- printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
- "!! Got complete XML document %d bytes used, %d bytes in current buffer.\n"
- "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", parser->usedBytes(), size);
+ PRACRO_DEBUG(server, "Got complete XML document %d bytes used, %d bytes in current buffer.\n", parser->usedBytes(), size);
- socket->write(handleTransaction(transaction, &pentominos_socket, &db));
+ socket->write(handleTransaction(transaction, &pentominos_socket, db));
size = size - parser->usedBytes();
delete transaction; transaction = NULL;
@@ -297,7 +291,7 @@ static void handleConnection(TCPSocket *socket)
if(size > 0) {
strcpy(buf, buf + size);
- printf("Replaying %d bytes.\n", size);
+ PRACRO_DEBUG(server, "Replaying %d bytes.\n", size);
}
}
}
@@ -312,7 +306,7 @@ static void handleConnection(TCPSocket *socket)
parser = NULL;
}
- printf("Out of read loop!\n");
+ PRACRO_DEBUG(server, "Out of read loop!\n");
}
//#define NON_FORKING
@@ -327,7 +321,7 @@ void server()
socket = new TCPSocket("Listen socket");
socket->listen(port);
} catch (Exception &e) {
- fprintf(stderr, "Error during parsing:\n%s\n",
+ PRACRO_ERR_LOG(server, "Error during parsing:\n%s\n",
e.what());
delete socket;
socket = NULL;
@@ -354,7 +348,7 @@ void server()
#ifndef NON_FORKING
switch(fork()) {
case -1: // error
- fprintf(stderr, "Could not fork: %s\n", strerror(errno));
+ PRACRO_ERR_LOG(server, "Could not fork: %s\n", strerror(errno));
break;
case 0: // child
@@ -377,7 +371,7 @@ void server()
//socket->shutdown();
delete socket;
- printf("Server gracefully shut down.\n");
+ PRACRO_DEBUG(server, "Server gracefully shut down.\n");
}