bool net::connection_list::build_index() { if (!allocate_indices()) { return false; } const node* nodes = _M_nodes.nodes; unsigned* indices = _M_index.indices; _M_index.used = 0; int idx = _M_head; while (idx != -1) { const node* n = &nodes[idx]; size_t pos; search(n->conn.srcip, n->conn.destip, pos); if (pos < _M_index.used) { memmove(&indices[pos + 1], &indices[pos], (_M_index.used - pos) * sizeof(unsigned)); } indices[pos] = idx; _M_index.used++; idx = n->next; } return true; }
/*}}}*/ static void allocate_indices(struct links *x, int *idx)/*{{{*/ { struct node *y; for (y = x->next; y != (struct node *) x; y = y->chain.next) { y->iscratch = *idx; ++*idx; allocate_indices(&y->kids, idx); } }
/*}}}*/ int process_list(char **x)/*{{{*/ { struct list_options options; int options_done = 0; int any_paths = 0; char index_buffer[256]; char *y; enum Priority prio = PRI_NORMAL, prio_to_use, node_prio; int prio_set = 0; time_t now = time(NULL); unsigned char *hits; int node_index, n_nodes; options.monochrome = 0; options.show_all = 0; options.show_postponed = 0; options.verbose = 0; options.set_depth = 0; if ( (getenv("TDL_LIST_MONOCHROME") != NULL) || (isatty(STDOUT_FILENO) == 0) ) { options.monochrome = 1; } /* Initialisation to support searching */ node_index = 0; allocate_indices(&top, &node_index); n_nodes = node_index; hits = n_nodes ? new_array(unsigned char, n_nodes) : NULL; /* all nodes match until proven otherwise */ memset(hits, 1, n_nodes); while ((y = *x) != 0) { /* An argument starting '1' or '+1' or '+-1' (or '-1' after '--') is * treated as the path of the top node to show */ if (isdigit(y[0]) || (y[0] == '.') || (options_done && (y[0] == '-') && isdigit(y[1])) || ((y[0] == '+') && (isdigit(y[1]) || ((y[1] == '-' && isdigit(y[2])))))) { struct node *n = lookup_node(y, 0, NULL); int summarise_kids; if (!n) return -1; any_paths = 1; index_buffer[0] = '\0'; strcat(index_buffer, y); summarise_kids = (options.set_depth && (options.depth==0)); if (hits[n->iscratch]) { print_details(n, 0, summarise_kids, &options, index_buffer, now); } if (!options.set_depth || (options.depth > 0)) { node_prio = n->priority; /* If the priority has been set on the cmd line, always use that. * Otherwise, use the priority from the specified node, _except_ when * that is higher than normal, in which case use normal. */ prio_to_use = (prio_set) ? prio : ((node_prio > prio) ? prio : node_prio); list_chain(&n->kids, INDENT_TAB, 0, &options, index_buffer, prio_to_use, now, hits); } } else if ((y[0] == '-') && (y[1] == '-')) { options_done = 1; } else if (y[0] == '-') { while (*++y) { switch (*y) { case 'v': options.verbose = 1; break; case 'a': options.show_all = 1; break; case 'm': options.monochrome = 1; break; case 'p': options.show_postponed = 1; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': options.set_depth = 1; options.depth = (*y) - '1'; break; default: fprintf(stderr, "Unrecognized option : -%c\n", *y); break; } } } else if (y[0] == '/') { /* search expression */ merge_search_condition(hits, n_nodes, y+1); } else { int error; prio = parse_priority(y, &error); if (error < 0) return error; prio_set = 1; } x++; } colours_init(&options); if (!any_paths) { struct node *narrow_top = get_narrow_top(); if (narrow_top) { index_buffer[0] = 0; if (hits[narrow_top->iscratch]) { int summarise_kids = (options.set_depth && (options.depth==0)); print_details(narrow_top, 0, summarise_kids, &options, index_buffer, now); } if (!options.set_depth || (options.depth > 0)) { list_chain(&narrow_top->kids, 0, 1, &options, index_buffer, prio, now, hits); } } else { index_buffer[0] = 0; list_chain(&top, 0, 0, &options, index_buffer, prio, now, hits); } } if (hits) free(hits); return 0; }