19 const int JSONFeed::RECEIVE_START_ST;
20 const int JSONFeed::WHITESPACE_BEFORE_JSON_ST;
21 const int JSONFeed::EOL_COMMENT_BEFORE_JSON_ST;
22 const int JSONFeed::START_COMMENT_BEFORE_JSON_ST;
23 const int JSONFeed::C_COMMENT_BEFORE_JSON_ST;
24 const int JSONFeed::STOP_COMMENT_BEFORE_JSON_ST;
25 const int JSONFeed::JSON_START_ST;
26 const int JSONFeed::INNER_JSON_ST;
27 const int JSONFeed::STRING_JSON_ST;
28 const int JSONFeed::ESCAPE_JSON_ST;
29 const int JSONFeed::EOL_COMMENT_ST;
30 const int JSONFeed::START_COMMENT_ST;
31 const int JSONFeed::C_COMMENT_ST;
32 const int JSONFeed::STOP_COMMENT_ST;
33 const int JSONFeed::JSON_END_ST;
34 const int JSONFeed::FEED_OK_ST;
35 const int JSONFeed::FEED_FAILED_ST;
37 const int JSONFeed::DATA_READ_OK_EVT;
38 const int JSONFeed::NEED_MORE_DATA_EVT;
39 const int JSONFeed::MORE_DATA_PROVIDED_EVT;
40 const int JSONFeed::FEED_OK_EVT;
41 const int JSONFeed::FEED_FAILED_EVT;
70 }
catch (
const std::exception& ex) {
91 " JSON feed while parsing hasn't finished");
94 return (Element::fromWire(output_));
96 }
catch (
const std::exception& ex) {
111 buffer_.assign(static_cast<const char*>(buf),
112 static_cast<const char*>(buf) + buf_size);
118 JSONFeed::defineEvents() {
119 StateModel::defineEvents();
130 JSONFeed::verifyEvents() {
131 StateModel::verifyEvents();
141 JSONFeed::defineStates() {
143 StateModel::defineStates();
146 std::bind(&JSONFeed::receiveStartHandler,
this));
148 std::bind(&JSONFeed::whiteSpaceBeforeJSONHandler,
this));
150 std::bind(&JSONFeed::eolCommentBeforeJSONHandler,
this));
152 std::bind(&JSONFeed::startCommentBeforeJSONHandler,
this));
154 std::bind(&JSONFeed::cCommentBeforeJSONHandler,
this));
156 std::bind(&JSONFeed::stopCommentBeforeJSONHandler,
this));
158 std::bind(&JSONFeed::innerJSONHandler,
this));
160 std::bind(&JSONFeed::stringJSONHandler,
this));
162 std::bind(&JSONFeed::escapeJSONHandler,
this));
164 std::bind(&JSONFeed::eolCommentHandler,
this));
166 std::bind(&JSONFeed::startCommentHandler,
this));
168 std::bind(&JSONFeed::cCommentHandler,
this));
170 std::bind(&JSONFeed::stopCommentHandler,
this));
172 std::bind(&JSONFeed::endJSONHandler,
this));
176 JSONFeed::feedFailure(
const std::string& error_msg) {
177 error_message_ = error_msg;
182 JSONFeed::onModelFailure(
const std::string& explanation) {
183 if (error_message_.empty()) {
184 error_message_ = explanation;
189 JSONFeed::popNextFromBuffer(
char& next) {
191 if (!buffer_.empty() && (data_ptr_ < buffer_.size())) {
192 next = buffer_[data_ptr_++];
199 JSONFeed::getNextFromBuffer() {
208 "JSONFeed requires new data to progress, but no data"
209 " have been provided. The transaction is aborted to avoid"
214 const bool data_exist = popNextFromBuffer(c);
220 "JSONFeed state indicates that new data have been"
221 " provided to be parsed, but the transaction buffer"
222 " contains no new data.");
235 JSONFeed::invalidEventError(
const std::string& handler_name,
236 const unsigned int event) {
237 isc_throw(JSONFeedError, handler_name <<
": invalid event "
242 JSONFeed::receiveStartHandler() {
243 char c = getNextFromBuffer();
265 output_.push_back(c);
273 feedFailure(
"invalid first character " + std::string(1, c));
279 invalidEventError(
"receiveStartHandler",
getNextEvent());
285 JSONFeed::whiteSpaceBeforeJSONHandler() {
286 char c = getNextFromBuffer();
306 output_.push_back(c);
314 feedFailure(
"invalid character " + std::string(1, c));
320 JSONFeed::eolCommentBeforeJSONHandler() {
321 char c = getNextFromBuffer();
336 JSONFeed::startCommentBeforeJSONHandler() {
337 char c = getNextFromBuffer();
349 feedFailure(
"invalid characters /" + std::string(1, c));
355 JSONFeed::cCommentBeforeJSONHandler() {
356 char c = getNextFromBuffer();
371 JSONFeed::stopCommentBeforeJSONHandler() {
372 char c = getNextFromBuffer();
391 JSONFeed::innerJSONHandler() {
392 char c = getNextFromBuffer();
397 output_.push_back(c);
404 output_.push_back(c);
405 if (--open_scopes_ == 0) {
414 output_.push_back(c);
427 output_.push_back(c);
434 JSONFeed::stringJSONHandler() {
435 char c = getNextFromBuffer();
437 output_.push_back(c);
455 JSONFeed::escapeJSONHandler() {
456 char c = getNextFromBuffer();
458 output_.push_back(c);
465 JSONFeed::eolCommentHandler() {
466 char c = getNextFromBuffer();
470 output_.push_back(c);
482 JSONFeed::startCommentHandler() {
483 char c = getNextFromBuffer();
495 feedFailure(
"invalid characters /" + std::string(1, c));
501 JSONFeed::cCommentHandler() {
502 char c = getNextFromBuffer();
510 output_.push_back(c);
522 JSONFeed::stopCommentHandler() {
523 char c = getNextFromBuffer();
535 output_.push_back(c);
547 JSONFeed::endJSONHandler() {
void defineState(unsigned int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
Adds an state value and associated label to the set of states.
static const int NOP_EVT
Signifies that no event has occurred.
static const int DATA_READ_OK_EVT
Chunk of data successfully read and parsed.
void postBuffer(const void *buf, const size_t buf_size)
Receives additional data read from a data stream.
static const int START_COMMENT_BEFORE_JSON_ST
Starting one of the comments beginning with a slash before actual JSON.
Implements a finite state machine.
static const int FEED_FAILED_EVT
Invalid syntax detected.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
static const int EOL_COMMENT_BEFORE_JSON_ST
Skipping an end-of-line comment before actual JSON.
const StatePtr getState(unsigned int value)
Fetches the state referred to by value.
static const int WHITESPACE_BEFORE_JSON_ST
Skipping whitespaces before actual JSON.
static const int RECEIVE_START_ST
State indicating a beginning of a feed.
void abortModel(const std::string &explanation)
Aborts model execution.
static const int START_EVT
Event issued to start the model execution.
unsigned int getLastEvent() const
Fetches the model's last event.
boost::shared_ptr< Element > ElementPtr
void setState(unsigned int state)
Sets the current state to the given state value.
static const int MORE_DATA_PROVIDED_EVT
New data provided and parsing should continue.
A generic exception thrown upon an error in the JSONFeed.
unsigned int getCurrState() const
Fetches the model's current state.
static const int STRING_JSON_ST
Parsing JSON string.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static const int INNER_JSON_ST
Parsing JSON.
static const int NEED_MORE_DATA_EVT
Unable to proceed with parsing until new data is provided.
static const int ESCAPE_JSON_ST
JSON escape next character.
const OutputBuffer * buffer_
bool needData() const
Checks if the model needs additional data to continue.
static const int FEED_OK_EVT
Found opening brace and the matching closing brace.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const int C_COMMENT_BEFORE_JSON_ST
Skipping a C style comment before actual JSON.
static const int START_COMMENT_ST
Starting one of the comments beginning with a slash.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
static const int STOP_COMMENT_BEFORE_JSON_ST
Stopping a C style comment before actual JSON.
static const int C_COMMENT_ST
Skipping a C style comment.
static const int JSON_END_ST
Found last closing brace or square bracket.
bool feedOk() const
Checks if the data have been successfully processed.
static const int STOP_COMMENT_ST
Stopping a C style comment.
void initDictionaries()
Initializes the event and state dictionaries.
static const int END_ST
Final state, all the state model has reached its conclusion.
data::ElementPtr toElement() const
Returns processed data as a structure of isc::data::Element objects.
bool isModelDone() const
Returns whether or not the model has finished execution.
static const int EOL_COMMENT_ST
Skipping an end-of-line comment.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
unsigned int getNextEvent() const
Fetches the model's next event.
void poll()
Runs the model as long as data is available.
static const int END_EVT
Event issued to end the model execution.
void initModel()
Initializes state model.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.
static const int FEED_FAILED_ST
Invalid syntax detected.