summaryrefslogtreecommitdiff
path: root/server/src/templateparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/templateparser.cc')
-rw-r--r--server/src/templateparser.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc
index 412924c..140051e 100644
--- a/server/src/templateparser.cc
+++ b/server/src/templateparser.cc
@@ -26,6 +26,7 @@
*/
#include "templateparser.h"
#include "configuration.h"
+#include "debug.h"
// For assert
#include <assert.h>
@@ -53,15 +54,25 @@ void TemplateParser::error(const char* fmt, ...)
{
// TODO: Throw exception here.
- fprintf(stderr, "Error in TemplateParser: ");
-
va_list argp;
- va_start(argp, fmt);
- vfprintf(stderr, fmt, argp);
- va_end(argp);
-
- fprintf(stderr, "\n");
-
+ int s = 256;
+ char *p = new char[s];
+ /* See printf(3) for details on the loop how to get the right buffersize. */
+ while(1) {
+ va_start(argp, fmt);
+ int n = vsnprintf(p, s, fmt, argp);
+ va_end(argp);
+ if(n > -1 && n < s)
+ break;
+ if(n > -1) /* glibc 2.1 */
+ s = n+1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ s *= 2; /* twice the old size */
+ delete[] p;
+ p = new char[s];
+ }
+ PRACRO_ERR_LOG(macro, "Error in TemplateParser: %s\n", p);
+ delete[] p;
throw Exception("Error in TemplateParser");
}
@@ -73,7 +84,7 @@ TemplateParser::TemplateParser(std::string course)
file = Conf::xml_basedir + "/templates/" + course + ".xml";
- printf("Using template file: %s\n", file.c_str());
+ PRACRO_DEBUG(macro, "Using template file: %s\n", file.c_str());
fd = open(file.c_str(), O_RDONLY);
if(fd == -1) error("Could not open file %s", file.c_str());
@@ -133,12 +144,12 @@ void TemplateParser::endTag(std::string name)
int TemplateParser::readData(char *data, size_t size)
{
if(fd == -1) {
- fprintf(stderr, "Invalid file descriptor.\n"); fflush(stderr);
+ PRACRO_ERR_LOG(macro, "Invalid file descriptor.\n");
return 0;
}
ssize_t r = read(fd, data, size);
if(r == -1) {
- printf("Could not read...%s\n", strerror(errno)); fflush(stdout);
+ PRACRO_ERR_LOG(macro, "Could not read...%s\n", strerror(errno));
return 0;
}
return r;