/*** * Iterate over node_map, where first_nodes and last_nodes * are mapped with the names and categories of the connected * ways to detect errors. */ void analyse_nodes() { int count_first_node, count_last_node; long fid = 1; vector<const char*> names; vector<char> category_in; vector<char> category_out; for (auto node : ds.node_map) { ErrorSum *sum = new ErrorSum(); osmium::object_id_type node_id = node.first; count_first_node = 0; count_last_node = 0; names.clear(); category_in.clear(); category_out.clear(); for (auto wway : node.second) { if (wway->first_node == node_id) { count_first_node++; names.push_back(wway->name.c_str()); category_out.push_back(wway->category); } if (wway->last_node == node_id) { count_last_node++; names.push_back(wway->name.c_str()); category_in.push_back(wway->category); } } detect_direction_error(count_first_node, count_last_node, sum); detect_name_error(names, sum); detect_flow_errors(category_in, category_out, sum); if (!handle_node(node_id, sum)) { continue; } fid++; } }
void opml_urlreader::rec_find_rss_outlines(xmlNode * node, std::string tag) { while (node) { char * type = (char *)xmlGetProp(node, (const xmlChar *)"type"); std::string newtag = tag; if (strcmp((const char *)node->name, "outline")==0) { if (type && strcmp(type,"rss")==0) { handle_node(node, tag); } else { char * text = (char *)xmlGetProp(node, (const xmlChar *)"title"); if (text) { if (newtag.length() > 0) { newtag.append("/"); } newtag.append(text); xmlFree(text); } } } rec_find_rss_outlines(node->children, newtag); node = node->next; } }
void svndump_read(const char *url) { char *val; char *t; uint32_t active_ctx = DUMP_CTX; uint32_t len; uint32_t key; reset_dump_ctx(pool_intern(url)); while ((t = buffer_read_line())) { val = strstr(t, ": "); if (!val) continue; *val++ = '\0'; *val++ = '\0'; key = pool_intern(t); if (key == keys.uuid) { dump_ctx.uuid = pool_intern(val); } else if (key == keys.revision_number) { if (active_ctx == NODE_CTX) handle_node(); if (active_ctx != DUMP_CTX) handle_revision(); active_ctx = REV_CTX; reset_rev_ctx(atoi(val)); } else if (key == keys.node_path) { if (active_ctx == NODE_CTX) handle_node(); active_ctx = NODE_CTX; reset_node_ctx(val); } else if (key == keys.node_kind) { if (!strcmp(val, "dir")) node_ctx.type = REPO_MODE_DIR; else if (!strcmp(val, "file")) node_ctx.type = REPO_MODE_BLB; else fprintf(stderr, "Unknown node-kind: %s\n", val); } else if (key == keys.node_action) { if (!strcmp(val, "delete")) { node_ctx.action = NODEACT_DELETE; } else if (!strcmp(val, "add")) { node_ctx.action = NODEACT_ADD; } else if (!strcmp(val, "change")) { node_ctx.action = NODEACT_CHANGE; } else if (!strcmp(val, "replace")) { node_ctx.action = NODEACT_REPLACE; } else { fprintf(stderr, "Unknown node-action: %s\n", val); node_ctx.action = NODEACT_UNKNOWN; } } else if (key == keys.node_copyfrom_path) { pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.src, "/", val); } else if (key == keys.node_copyfrom_rev) { node_ctx.srcRev = atoi(val); } else if (key == keys.text_content_length) { node_ctx.textLength = atoi(val); } else if (key == keys.prop_content_length) { node_ctx.propLength = atoi(val); } else if (key == keys.content_length) { len = atoi(val); buffer_read_line(); if (active_ctx == REV_CTX) { read_props(); } else if (active_ctx == NODE_CTX) { handle_node(); active_ctx = REV_CTX; } else { fprintf(stderr, "Unexpected content length header: %d\n", len); buffer_skip_bytes(len); } } } if (active_ctx == NODE_CTX) handle_node(); if (active_ctx != DUMP_CTX) handle_revision(); }
void k8s_dispatcher::dispatch() { for (list::iterator it = m_messages.begin(); it != m_messages.end();) { if(is_ready(*it)) { Json::Value root; Json::Reader reader; if(reader.parse(*it, root, false)) { std::ostringstream os; msg_data data = get_msg_data(root); if(data.is_valid()) { std::ostringstream os; os << '[' << to_reason_desc(data.m_reason) << ','; switch (m_type) { case k8s_component::K8S_NODES: os << "NODE,"; handle_node(root, data); break; case k8s_component::K8S_NAMESPACES: os << "NAMESPACE,"; handle_namespace(root, data); break; case k8s_component::K8S_PODS: os << "POD,"; handle_pod(root, data); break; case k8s_component::K8S_REPLICATIONCONTROLLERS: os << "REPLICATION_CONTROLLER,"; handle_rc(root, data); break; case k8s_component::K8S_SERVICES: os << "SERVICE,"; handle_service(root, data); break; default: { std::ostringstream eos; eos << "Unknown component: " << static_cast<int>(m_type); throw sinsp_exception(os.str()); } } os << data.m_name << ',' << data.m_uid << ',' << data.m_namespace << ']'; g_logger.log(os.str(), sinsp_logger::SEV_INFO); //g_logger.log(root.toStyledString(), sinsp_logger::SEV_DEBUG); { K8S_LOCK_GUARD_MUTEX; m_state.update_cache(m_type); } } } else { // TODO: bad notification - discard or throw? g_logger.log("Bad JSON message received.", sinsp_logger::SEV_ERROR); } it = m_messages.erase(it); } else { ++it; } } }
void svndump_read(const char *url) { char *val; char *t; uint32_t active_ctx = DUMP_CTX; uint32_t len; reset_dump_ctx(url); while ((t = buffer_read_line(&input))) { val = strchr(t, ':'); if (!val) continue; val++; if (*val != ' ') continue; val++; /* strlen(key) + 1 */ switch (val - t - 1) { case sizeof("SVN-fs-dump-format-version"): if (constcmp(t, "SVN-fs-dump-format-version")) continue; dump_ctx.version = atoi(val); if (dump_ctx.version > 3) die("expected svn dump format version <= 3, found %"PRIu32, dump_ctx.version); break; case sizeof("UUID"): if (constcmp(t, "UUID")) continue; strbuf_reset(&dump_ctx.uuid); strbuf_addstr(&dump_ctx.uuid, val); break; case sizeof("Revision-number"): if (constcmp(t, "Revision-number")) continue; if (active_ctx == NODE_CTX) handle_node(); if (active_ctx == REV_CTX) begin_revision(); if (active_ctx != DUMP_CTX) end_revision(); active_ctx = REV_CTX; reset_rev_ctx(atoi(val)); break; case sizeof("Node-path"): if (prefixcmp(t, "Node-")) continue; if (!constcmp(t + strlen("Node-"), "path")) { if (active_ctx == NODE_CTX) handle_node(); if (active_ctx == REV_CTX) begin_revision(); active_ctx = NODE_CTX; reset_node_ctx(val); break; } if (constcmp(t + strlen("Node-"), "kind")) continue; if (!strcmp(val, "dir")) node_ctx.type = REPO_MODE_DIR; else if (!strcmp(val, "file")) node_ctx.type = REPO_MODE_BLB; else fprintf(stderr, "Unknown node-kind: %s\n", val); break; case sizeof("Node-action"): if (constcmp(t, "Node-action")) continue; if (!strcmp(val, "delete")) { node_ctx.action = NODEACT_DELETE; } else if (!strcmp(val, "add")) { node_ctx.action = NODEACT_ADD; } else if (!strcmp(val, "change")) { node_ctx.action = NODEACT_CHANGE; } else if (!strcmp(val, "replace")) { node_ctx.action = NODEACT_REPLACE; } else { fprintf(stderr, "Unknown node-action: %s\n", val); node_ctx.action = NODEACT_UNKNOWN; } break; case sizeof("Node-copyfrom-path"): if (constcmp(t, "Node-copyfrom-path")) continue; strbuf_reset(&node_ctx.src); strbuf_addstr(&node_ctx.src, val); break; case sizeof("Node-copyfrom-rev"): if (constcmp(t, "Node-copyfrom-rev")) continue; node_ctx.srcRev = atoi(val); break; case sizeof("Text-content-length"): if (!constcmp(t, "Text-content-length")) { char *end; uintmax_t textlen; textlen = strtoumax(val, &end, 10); if (!isdigit(*val) || *end) die("invalid dump: non-numeric length %s", val); if (textlen > maximum_signed_value_of_type(off_t)) die("unrepresentable length in dump: %s", val); node_ctx.text_length = (off_t) textlen; break; } if (constcmp(t, "Prop-content-length")) continue; node_ctx.propLength = atoi(val); break; case sizeof("Text-delta"): if (!constcmp(t, "Text-delta")) { node_ctx.text_delta = !strcmp(val, "true"); break; } if (constcmp(t, "Prop-delta")) continue; node_ctx.prop_delta = !strcmp(val, "true"); break; case sizeof("Content-length"): if (constcmp(t, "Content-length")) continue; len = atoi(val); t = buffer_read_line(&input); if (!t) die_short_read(); if (*t) die("invalid dump: expected blank line after content length header"); if (active_ctx == REV_CTX) { read_props(); } else if (active_ctx == NODE_CTX) { handle_node(); active_ctx = INTERNODE_CTX; } else { fprintf(stderr, "Unexpected content length header: %"PRIu32"\n", len); if (buffer_skip_bytes(&input, len) != len) die_short_read(); } } } if (buffer_ferror(&input)) die_short_read(); if (active_ctx == NODE_CTX) handle_node(); if (active_ctx == REV_CTX) begin_revision(); if (active_ctx != DUMP_CTX) end_revision(); }