summaryrefslogtreecommitdiff
path: root/server/src/transactionparser.cc
diff options
context:
space:
mode:
authordeva <deva>2010-05-07 09:31:26 +0000
committerdeva <deva>2010-05-07 09:31:26 +0000
commit965e43178736e6635cf27410e6d73f4ec0fdced2 (patch)
tree7cc297f68e93f6974baaf185259ac88f35df0355 /server/src/transactionparser.cc
parent3241d29dec9beb0c367340465bd8d9bcab863692 (diff)
LOTS of changes. libmicrohttpd fix for 'chunked' POST handling and LUA parameter checker from Pentominos among other things.
Diffstat (limited to 'server/src/transactionparser.cc')
-rw-r--r--server/src/transactionparser.cc73
1 files changed, 31 insertions, 42 deletions
diff --git a/server/src/transactionparser.cc b/server/src/transactionparser.cc
index f1f79c6..7422a13 100644
--- a/server/src/transactionparser.cc
+++ b/server/src/transactionparser.cc
@@ -36,31 +36,6 @@
#include "debug.h"
#include "exception.h"
-static void error(const char* fmt, ...)
-{
- PRACRO_ERR_LOG(transactionparser, "Error in TransactionParser: ");
-
- {
- va_list argp;
- va_start(argp, fmt);
- PRACRO_ERR_LOG_VA(macro, fmt, argp);
- va_end(argp);
-
- fprintf(stderr, "\n");
- }
-
- {
- char *p;
- va_list argp;
- va_start(argp, fmt);
- if(vasprintf(&p, fmt, argp) != -1) {
- throw Exception("Error in TransactionParser: " + std::string(p));
- free(p);
- }
- va_end(argp);
- }
-}
-
TransactionParser::TransactionParser(Transaction *transaction)
{
this->transaction = transaction;
@@ -68,8 +43,11 @@ TransactionParser::TransactionParser(Transaction *transaction)
totalbytes = 0;
}
-void TransactionParser::startTag(std::string name, std::map< std::string, std::string> attributes)
+void TransactionParser::startTag(std::string name,
+ std::map<std::string, std::string> attributes)
{
+ PRACRO_DEBUG(transactionparser, "<%s>\n", name.c_str());
+
if(name == "pracro") {
transaction->user = attributes["user"];
transaction->cpr = attributes["cpr"];
@@ -92,26 +70,37 @@ void TransactionParser::startTag(std::string name, std::map< std::string, std::s
}
if(name == "field") {
- if(!transaction->commits.size()) error("Field without a commit tag!");
- if(attributes.find("name") == attributes.end()) error("Field is missing 'name' attribute");
- if(attributes.find("value") == attributes.end()) error("Field is missing 'value' attribute");
- transaction->commits.back().fields[attributes["name"]] = attributes["value"];
+ if(!transaction->commits.size()) {
+ PRACRO_ERR(transactionparser, "Field without a commit tag!");
+ return;
+ }
+
+ if(attributes.find("name") == attributes.end()) {
+ PRACRO_ERR(transactionparser, "Field is missing 'name' attribute");
+ return;
+ }
+
+ if(attributes.find("value") == attributes.end()) {
+ PRACRO_ERR(transactionparser, "Field is missing 'value' attribute");
+ return;
+ }
+
+ transaction->commits.back().fields[attributes["name"]] =
+ attributes["value"];
}
}
-void TransactionParser::parseError(const char *buf, size_t len, std::string error, int lineno)
+void TransactionParser::parseError(const char *buf, size_t len,
+ std::string error, int lineno)
{
- PRACRO_ERR_LOG(transactionparser, "TransactionParser error at line %d: %s\n",
- lineno, error.c_str());
- PRACRO_ERR_LOG(transactionparser, "\tBuffer %u bytes: [", len);
- if(fwrite(buf, len, 1, stderr) != len) {}
- PRACRO_ERR_LOG(transactionparser, "]\n");
-
- char *slineno;
- if(asprintf(&slineno, " at line %d\n", lineno) != -1) {
- throw Exception(error + slineno);
- free(slineno);
- }
+ PRACRO_ERR(transactionparser, "TransactionParser error at line %d: %s\n",
+ lineno, error.c_str());
+
+ std::string xml;
+ xml.append(buf, len);
+
+ PRACRO_ERR(transactionparser, "\tBuffer %u bytes: [%s]\n",
+ len, xml.c_str());
}
#ifdef TEST_TRANSACTIONPARSER