void dump_xml(std::ostream& out, tinyxml2::XMLNode* node) { auto* elem = node->ToElement(); if (elem) { out << " " << elem->Name() << std::endl; } for (auto* child = node->FirstChild(); child; child = child->NextSibling()) { dump_xml(out, child); } }
static int xml_getinfo(lua_State *L) { lua_apr_xml_object *object; object = check_xml_parser(L, 1, CHECK_DOCUMENT); lua_newtable(L); dump_xml(L, object->doc->root); return 1; }
static void dump_xml(lua_State *L, apr_xml_elem *elem) { apr_xml_attr *attr; apr_xml_elem *child; apr_text *text; int i; luaL_checktype(L, -1, LUA_TTABLE); if (elem->name != NULL) { lua_pushstring(L, "tag"); lua_pushstring(L, elem->name); lua_rawset(L, -3); } if (elem->attr != NULL) { lua_newtable(L); i = 1; attr = elem->attr; while (attr != NULL) { lua_pushstring(L, attr->name); lua_rawseti(L, -2, i); lua_pushstring(L, attr->name); lua_pushstring(L, attr->value); lua_rawset(L, -3); attr = attr->next; i++; } /* XXX Reverse the order of the attributes in the array part of the table. * The apr_xml.h header doesn't document that attributes are reversed, in * fact the apr_xml_elem.attr field is documented as the "first attribute", * but in the definition of start_handler() in the apr_xml.c implementation * it _is_ mentioned that attributes end up in reverse order. */ reverse_table(L, lua_gettop(L), i - 1); lua_setfield(L, -2, "attr"); } i = 1; if (elem->first_child != NULL) { child = elem->first_child; while (child != NULL) { lua_newtable(L); dump_xml(L, child); lua_rawseti(L, -2, i); child = child->next; i++; } } else { text = elem->first_cdata.first; while (text != NULL) { lua_pushstring(L, text->text); lua_rawseti(L, -2, i); text = text->next; i++; } } }
int main(int argc, char** argv) { if (argc != 2) { std::cerr << "usage: main <config-file>" << std::endl; return 1; } std::string url = read_url(argv[1]); if (!url.size()) { std::cerr << "error: none or empty url" << std::endl; return 1; } std::cout << "retrieving XML from \"" << url << "\" ..." << std::endl; std::ostringstream data; try { curlpp::Cleanup cleanup; curlpp::Easy request; request.setOpt<curlpp::options::WriteStream>(&data); request.setOpt<curlpp::options::Url>(url); request.perform(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } std::cout << "parsing XML document ..." << std::endl << std::endl; tinyxml2::XMLDocument doc; tinyxml2::XMLError error = doc.Parse(data.str().c_str()); if (error != tinyxml2::XML_SUCCESS) { std::cerr << "tinyxml2 error: " << error << std::endl; return 1; } data << "\n\nTags:\n\n"; dump_xml(data, doc.RootElement()); #ifdef HAVE_QT5 QApplication app(argc, argv); QWidget window; QHBoxLayout layout(&window); window.setLayout(&layout); QLabel label(data.str().c_str()); layout.addWidget(&label); window.show(); return app.exec(); #else std::cout << data.str() << std::endl; return 0; #endif }
static void dump_xml(apr_xml_elem *e, int level) { apr_xml_attr *a; apr_xml_elem *ec; printf("%d: element %s\n", level, e->name); if (e->attr) { a = e->attr; printf("%d:\tattrs\t", level); while (a) { printf("%s=%s\t", a->name, a->value); a = a->next; } printf("\n"); } if (e->first_child) { ec = e->first_child; while (ec) { dump_xml(ec, level + 1); ec = ec->next; } } }
/* Refreshes the diagram. Called each refresh_period ms * 1. Checks for new protocols and displays them * 2. Updates nodes looks * 3. Updates links looks */ guint update_diagram(GtkWidget * canvas) { static struct timeval last_refresh_time = { 0, 0 }; double diffms; enum status_t status; /* if requested and enabled, dump to xml */ if (appdata.request_dump && appdata.export_file_signal) { g_warning (_("SIGUSR1 received: exporting to %s"), appdata.export_file_signal); dump_xml(appdata.export_file_signal); appdata.request_dump = FALSE; } status = get_capture_status(); if (status == PAUSE) return FALSE; if (status == CAP_EOF) { gui_eof_capture (); return FALSE; } /* * It could happen that during an intensive calculation, in order * to update the GUI and make the application responsive gtk_main_iteration * is called. But that could also trigger this very function's timeout. * If we let it run twice many problems could come up. Thus, * we are preventing it with the already_updating variable */ if (already_updating) { g_my_debug ("update_diagram called while already updating"); return FALSE; } already_updating = TRUE; gettimeofday (&appdata.now, NULL); /* update nodes */ diagram_update_nodes(canvas); /* update links */ diagram_update_links(canvas); /* Update protocol information */ protocol_summary_update_all(); /* update proto legend */ update_legend(); /* Now update info windows */ update_info_windows (); /* With this we make sure that we don't overload the * CPU with redraws */ if ((last_refresh_time.tv_sec == 0) && (last_refresh_time.tv_usec == 0)) last_refresh_time = appdata.now; /* Force redraw */ while (gtk_events_pending ()) gtk_main_iteration (); gettimeofday (&appdata.now, NULL); diffms = substract_times_ms(&appdata.now, &last_refresh_time); last_refresh_time = appdata.now; already_updating = FALSE; if (!is_idle) { if (diffms > pref.refresh_period * 1.2) return FALSE; /* Removes the timeout */ } else { if (diffms < pref.refresh_period) return FALSE; /* removes the idle */ } if (stop_requested) gui_stop_capture(); return TRUE; /* Keep on calling this function */ } /* update_diagram */
int main(int argc, const char *const * argv) { apr_pool_t *pool; apr_file_t *fd; apr_xml_parser *parser; apr_xml_doc *doc; apr_status_t rv; char errbuf[2000]; char errbufXML[2000]; (void) apr_initialize(); apr_pool_create(&pool, NULL); progname = argv[0]; if (argc == 1) { rv = create_dummy_file(pool, &fd); if (rv != APR_SUCCESS) { oops("cannot create dummy file", "oops", rv); } } else { if (argc == 2) { rv = apr_file_open(&fd, argv[1], APR_READ, APR_OS_DEFAULT, pool); if (rv != APR_SUCCESS) { oops("cannot open: %s", argv[1], rv); } } else { oops("usage: %s", usage, 0); } } rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000); if (rv != APR_SUCCESS) { fprintf(stderr, "APR Error %s\nXML Error: %s\n", apr_strerror(rv, errbuf, sizeof(errbuf)), apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML))); return rv; } dump_xml(doc->root, 0); apr_file_close(fd); if (argc == 1) { rv = create_dummy_file_error(pool, &fd); if (rv != APR_SUCCESS) { oops("cannot create error dummy file", "oops", rv); } rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000); if (rv != APR_SUCCESS) { fprintf(stdout, "APR Error %s\nXML Error: %s " "(EXPECTED) This is good.\n", apr_strerror(rv, errbuf, sizeof(errbuf)), apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML))); rv = APR_SUCCESS; /* reset the return code, as the test is supposed to get this error */ } else { fprintf(stderr, "Expected an error, but didn't get one ;( "); return APR_EGENERAL; } } apr_pool_destroy(pool); apr_terminate(); return rv; }