/* Look up colors. */ int raw_color(const security_context_t raw, char **color_str) { #define CHARS_PER_COLOR 16 context_t con; uint32_t i, j, mask = 0; const secolor_t *items[N_COLOR]; char *result, *components[N_COLOR]; char buf[CHARS_PER_COLOR + 1]; size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1; int rc = -1; if (!color_str || *color_str) { return -1; } /* parse context and allocate memory */ con = context_new(raw); if (!con) return -1; if (parse_components(con, components) < 0) goto out; result = malloc(result_size); if (!result) goto out; result[0] = '\0'; /* find colors for which we have a match */ for (i = 0; i < N_COLOR; i++) { items[i] = find_color(i, components[i], raw); if (items[i]) mask |= (1 << i); } if (mask == 0) { items[0] = &default_color; mask = 1; } /* propagate colors according to the precedence rules */ for (i = 0; i < N_COLOR; i++) if (!(mask & (1 << i))) for (j = 0; j < N_COLOR - 1; j++) if (mask & (1 << precedence[i][j])) { items[i] = items[precedence[i][j]]; break; } /* print results into a big long string */ for (i = 0; i < N_COLOR; i++) { snprintf(buf, sizeof(buf), "#%06x #%06x ", items[i]->fg, items[i]->bg); strncat(result, buf, result_size-1); } *color_str = result; rc = 0; out: context_free(con); return rc; }
void FeedParser::parse(XmlReader& xml, KPrintFun log) { if (xml.name() != "project" || xml.namespace_uri() != project_ns) { throw std::runtime_error("not a project feed"); } std::string id = xml.attribute("href", project_ns); if (id != spec.id) { spec.id = id; queue.current_id(id); } name = xml.attribute("name", project_ns); std::string tag = next_element(xml, log); if (tag == "meta") { xml.skip(); tag = next_element(xml, log); } if (tag == "variants") { parse_variants(xml); xml.skip(); tag = next_element(xml, log); } if (tag == "releases") { parse_releases(xml); xml.skip(); tag = next_element(xml, log); } if (tag == "build") { std::string vcs = xml.attribute("vcs", project_ns); std::string href = xml.attribute("href", project_ns); parse_build(xml, vcs, href); xml.skip(); tag = next_element(xml, log); } if (tag == "runtime") { parse_runtime(xml); xml.skip(); tag = next_element(xml, log); } else if (tag == "components") { parse_components(xml); xml.skip(); tag = next_element(xml, log); } if (tag == "packages") { Package group; parse_packages(xml, group); xml.skip(); tag = next_element(xml, log); } if (!tag.empty()) { Log(log, "element '%1%' not expected!!") % tag; } }