server/src/exparse.c

47 lines
1,010 B
C
Raw Normal View History

#ifdef _MSC_VER
#include <platform.h>
#endif
2018-04-24 21:50:49 +02:00
#include "exparse.h"
2018-04-24 22:04:23 +02:00
#include "util/log.h"
2018-04-24 21:50:49 +02:00
#include <expat.h>
int exparse_readfile(const char * filename) {
2018-04-24 22:04:23 +02:00
XML_Parser xp;
FILE *F;
int err = 1;
char buf[4096];
F = fopen(filename, "r");
if (!F) {
return 2;
}
xp = XML_ParserCreate("UTF-8");
for (;;) {
size_t len = (int) fread(buf, 1, sizeof(buf), F);
int done;
if (ferror(F)) {
log_error("read error in %s", filename);
err = -2;
break;
2018-04-24 22:04:23 +02:00
}
done = feof(F);
if (XML_Parse(xp, buf, len, done) == XML_STATUS_ERROR) {
log_error("parse error at line %u of %s: %s",
XML_GetCurrentLineNumber(xp),
filename,
XML_ErrorString(XML_GetErrorCode(xp)));
err = -1;
break;
2018-04-24 22:04:23 +02:00
}
if (done) {
break;
}
}
XML_ParserFree(xp);
fclose(F);
return err;
2018-04-24 21:50:49 +02:00
}