diff options
author | mvglasow <michael -at- vonglasow.com> | 2018-07-16 22:23:23 +0200 |
---|---|---|
committer | mvglasow <michael -at- vonglasow.com> | 2018-07-16 22:23:23 +0200 |
commit | 289f53510a5a98ac3eb4ddc7dd005c71ca588729 (patch) | |
tree | aebaf30e479a913efe4709f6333774b8f017824e | |
parent | 80cd50b3482926c4cb8f0eacc422b2b19b1d5e09 (diff) | |
download | navit-289f53510a5a98ac3eb4ddc7dd005c71ca588729.tar.gz |
Add:traffic:API function to parse XML data from a string
Signed-off-by: mvglasow <michael -at- vonglasow.com>
-rw-r--r-- | navit/traffic.c | 28 | ||||
-rw-r--r-- | navit/traffic.h | 11 |
2 files changed, 39 insertions, 0 deletions
diff --git a/navit/traffic.c b/navit/traffic.c index 82b0a9146..2dac34ed8 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -4574,6 +4574,34 @@ struct traffic_message ** traffic_get_messages_from_xml_file(struct traffic * th return ret; } +struct traffic_message ** traffic_get_messages_from_xml_string(struct traffic * this_, char * xml) { + struct traffic_message ** ret = NULL; + + struct xml_state state; + int i, count; + GList * msg_iter; + int read_success = 0; + + if (xml) { + memset(&state, 0, sizeof(struct xml_state)); + read_success = xml_parse_text(xml, &state, traffic_xml_start, traffic_xml_end, traffic_xml_text); + if (read_success) { + count = g_list_length(state.messages); + if (count) + ret = g_new0(struct traffic_message *, count + 1); + msg_iter = state.messages; + for (i = 0; i < count; i++) { + ret[i] = (struct traffic_message *) msg_iter->data; + msg_iter = g_list_next(msg_iter); + } + g_list_free(state.messages); + } else { + dbg(lvl_error,"no data supplied"); + } + } /* if (xml) */ + return ret; +} + int traffic_process_messages(struct traffic * this_, struct traffic_message ** messages) { return traffic_process_messages_int(this_, messages, 0); } diff --git a/navit/traffic.h b/navit/traffic.h index 8c8849620..dd8967a90 100644 --- a/navit/traffic.h +++ b/navit/traffic.h @@ -907,6 +907,17 @@ void traffic_init(void); struct traffic_message ** traffic_get_messages_from_xml_file(struct traffic * this_, char * filename); /** + * @brief Reads traffic messages from an XML string. + * + * @param this_ The traffic instance + * @param filename The XML document to parse, as a string + * + * @return A `NULL`-terminated pointer array. Each element points to one `struct traffic_message`. + * `NULL` is returned (rather than an empty pointer array) if there are no messages to report. + */ +struct traffic_message ** traffic_get_messages_from_xml_string(struct traffic * this_, char * xml); + +/** * @brief Returns the map for the traffic plugin. * * The map is created by the first traffic plugin loaded. If multiple traffic plugin instances are |