24 const char DIRECTIVE_FLAG =
'$';
25 const char MESSAGE_FLAG =
'%';
42 ifstream infile(file.c_str());
51 getline(infile, line);
54 while (infile.good()) {
56 processLine(line, mode);
57 getline(infile, line);
79 }
else if (text[0] == DIRECTIVE_FLAG) {
83 }
else if (text[0] == MESSAGE_FLAG) {
84 parseMessage(text, mode);
95 MessageReader::parseDirective(
const std::string& text) {
103 if (tokens[0] ==
string(
"$PREFIX")) {
106 }
else if (tokens[0] ==
string(
"$NAMESPACE")) {
107 parseNamespace(tokens);
112 isc_throw_3(MessageException,
"Unrecognized directive",
120 MessageReader::parsePrefix(
const vector<string>& tokens) {
128 if (tokens.size() == 1) {
131 }
else if (tokens.size() == 2) {
137 if (invalidSymbol(prefix_)) {
145 isc_throw_2(MessageException,
"Too many arguments",
155 MessageReader::invalidSymbol(
const string& symbol) {
156 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
157 "abcdefghijklmnopqrstuvwxyz"
159 return ( symbol.empty() ||
160 (symbol.find_first_not_of(valid_chars) != string::npos) ||
161 (std::isdigit(symbol[0])));
170 MessageReader::parseNamespace(
const vector<string>& tokens) {
173 if (tokens.size() < 2) {
177 }
else if (tokens.size() > 2) {
178 isc_throw_2(MessageException,
"Too many arguments",
187 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
188 "abcdefghijklmnopqrstuvwxyz"
190 if (tokens[1].find_first_not_of(valid_chars) != string::npos) {
196 if (ns_.size() != 0) {
197 isc_throw_2(MessageException,
"Duplicate namespace",
215 MessageReader::parseMessage(
const std::string& text, MessageReader::Mode mode) {
217 static string delimiters(
"\t\n ");
224 if (text.size() == 1) {
233 size_t first_delim = message_line.find_first_of(delimiters);
234 if (first_delim == string::npos) {
238 message_line, lineno_);
245 string ident = prefix_ + message_line.substr(0, first_delim);
246 if (prefix_.empty()) {
247 if (invalidSymbol(ident)) {
248 isc_throw_3(MessageException,
"Invalid message ID",
255 size_t first_text = message_line.find_first_not_of(delimiters, first_delim);
256 if (first_text == string::npos) {
262 message_line, lineno_);
269 added = dictionary_->add(ident, message_line.substr(first_text));
272 added = dictionary_->replace(ident, message_line.substr(first_text));
275 not_added_.push_back(ident);
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
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