25 const char DIRECTIVE_FLAG =
'$';
26 const char MESSAGE_FLAG =
'%';
43 ifstream infile(file.c_str());
52 getline(infile, line);
55 while (infile.good()) {
57 processLine(line, mode);
58 getline(infile, line);
80 }
else if (text[0] == DIRECTIVE_FLAG) {
84 }
else if (text[0] == MESSAGE_FLAG) {
85 parseMessage(text, mode);
96 MessageReader::parseDirective(
const std::string& text) {
104 if (
tokens[0] ==
string(
"$PREFIX")) {
107 }
else if (
tokens[0] ==
string(
"$NAMESPACE")) {
113 isc_throw_3(MessageException,
"Unrecognized directive",
121 MessageReader::parsePrefix(
const vector<string>&
tokens) {
132 }
else if (
tokens.size() == 2) {
138 if (invalidSymbol(prefix_)) {
146 isc_throw_2(MessageException,
"Too many arguments",
156 MessageReader::invalidSymbol(
const string& symbol) {
157 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 158 "abcdefghijklmnopqrstuvwxyz" 160 return ( symbol.empty() ||
161 (symbol.find_first_not_of(valid_chars) != string::npos) ||
162 (std::isdigit(symbol[0])));
171 MessageReader::parseNamespace(
const vector<string>&
tokens) {
178 }
else if (
tokens.size() > 2) {
179 isc_throw_2(MessageException,
"Too many arguments",
188 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 189 "abcdefghijklmnopqrstuvwxyz" 191 if (
tokens[1].find_first_not_of(valid_chars) != string::npos) {
197 if (ns_.size() != 0) {
198 isc_throw_2(MessageException,
"Duplicate namespace",
216 MessageReader::parseMessage(
const std::string& text, MessageReader::Mode mode) {
218 static string delimiters(
"\t\n ");
222 assert((text.size() >= 1) && (text[0] == MESSAGE_FLAG));
225 if (text.size() == 1) {
234 size_t first_delim = message_line.find_first_of(delimiters);
235 if (first_delim == string::npos) {
239 message_line, lineno_);
246 string ident = prefix_ + message_line.substr(0, first_delim);
247 if (prefix_.empty()) {
248 if (invalidSymbol(ident)) {
249 isc_throw_3(MessageException,
"Invalid message ID",
256 size_t first_text = message_line.find_first_not_of(delimiters, first_delim);
257 if (first_text == string::npos) {
263 message_line, lineno_);
270 added = dictionary_->add(ident, message_line.substr(first_text));
273 added = dictionary_->replace(ident, message_line.substr(first_text));
276 not_added_.push_back(ident);
const isc::log::MessageID LOG_INVALID_MESSAGE_ID
const isc::log::MessageID LOG_READ_ERROR
const isc::log::MessageID LOG_INPUT_OPEN_FAIL
const isc::log::MessageID LOG_NO_MESSAGE_TEXT
#define isc_throw_3(type, stream, param1, param2, param3)
Similar as isc_throw, but allows the exception to have three additional parameters (the stream/text g...
const isc::log::MessageID LOG_UNRECOGNIZED_DIRECTIVE
#define isc_throw_4(type, stream, param1, param2, param3, param4)
Similar as isc_throw, but allows the exception to have four additional parameters (the stream/text go...
#define isc_throw_2(type, stream, param1, param2)
Similar as isc_throw, but allows the exception to have two additional parameters (the stream/text goe...
std::string readFile(const std::string &file_path)
Reads contents of the specified file.
void uppercase(std::string &text)
Uppercase String.
const isc::log::MessageID LOG_DUPLICATE_NAMESPACE
const isc::log::MessageID LOG_NAMESPACE_EXTRA_ARGS
vector< string > tokens(const std::string &text, const std::string &delim, bool escape)
Split String into Tokens.
const isc::log::MessageID LOG_NAMESPACE_NO_ARGS
const isc::log::MessageID LOG_PREFIX_EXTRA_ARGS
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::log::MessageID LOG_NO_MESSAGE_ID
const isc::log::MessageID LOG_PREFIX_INVALID_ARG
string trim(const string &instring)
Trim Leading and Trailing Spaces.
const isc::log::MessageID LOG_NAMESPACE_INVALID_ARG