summaryrefslogtreecommitdiff
path: root/server/src/transactionparser.cc
diff options
context:
space:
mode:
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