[digraphanalysis-cvs] digraphanalysis/src main.c, output.c,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-05-14 19:34:38
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28728 Modified Files: main.c output.c Log Message: clean up Index: output.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/output.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** output.c 14 May 2005 19:29:57 -0000 1.1 --- output.c 14 May 2005 19:34:29 -0000 1.2 *************** *** 28,36 **** #include <unistd.h> - #include "alias.h" - #include "graph.h" - #include "main.h" - #include "node.h" - int analysis_main_directory(char *outputdir) --- 28,31 ---- Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** main.c 14 May 2005 03:02:38 -0000 1.9 --- main.c 14 May 2005 19:34:29 -0000 1.10 *************** *** 62,160 **** } - int - analysis_main_directory(char *outputdir) - { - char *dir; - int rtn; - - dir = NULL; - rtn = 0; - /* Create and enter the output directory */ - if((dir = dirname(outputdir)) == NULL) - errx(EX_OSERR, "Error on dirname"); - if((chdir(dir) == -1) || - (create_new_directory(outputdir) == -1) || - (chdir(outputdir) == -1)) - rtn = -1; - /* afaik the call to dirname isn't mangling a copied string it's giving us the address in memory of the actual fs dir label. thus segfaulting (badly) when trying to free it. - free(dir); */ - return rtn; - } - - void - analysis_output_report(struct graphlist *graph_list) - { - struct alias *alias; - FILE *filep; - struct graph *graph; - struct graphlink *graph_link; - int i; - int j; - int k; - float last_msd; - struct node *node; - struct nodelink *node_link; - - i = k = 1; - last_msd = -1.0; - graph_link = NULL; - filep = fopen("report.html", "w"); - fprintf(filep, "<html><body>\n"); - while(!LIST_EMPTY(graph_list)) - { - graph_link = LIST_FIRST(graph_list); - /* If the size of this web of trust is 1 then the remaining are of size 1, so group them all together */ - if(nodelist_size(((struct graph *) graph_link->graph)->node_list) == 1) - break; - fprintf(filep, "<div class=\"wottable\"><div class=\"wottable_title\">Web Of Trust %d</div>\n", i); - fprintf(filep, "<table><tr><td>Rank</td><td>KeyID</td><td>Name</td><td>MSD</td></tr>\n"); - - graph = (struct graph *) graph_link->graph; - while(!LIST_EMPTY(graph->node_list)) - { - node_link = LIST_FIRST(graph->node_list); - node = (struct node *) node_link->node; - if(node->msd != last_msd) - j = k; - ++k; - last_msd = node->msd; - alias = aliaslist_find(graph->alias_list, node->uid); - fprintf(filep, "<tr><td>%d</td><td><a href=\"%s/%s\">%s</a></td><td>%s</td><td>%f</td></tr>\n", j, node->uiddir, node->uid, node->uid, ((alias != NULL)?(alias->name):""), node->msd); - LIST_REMOVE(node_link, list); - } - fprintf(filep, "</table></div>\n"); - LIST_REMOVE(graph_link, list); - - j = k = 1; - last_msd = -1.0; - ++i; - } - - if(graph_link != NULL) - { - fprintf(filep, "<div class=\"wottable\"><div class=\"wottable_title\">Unconnected Keys</div>\n"); - fprintf(filep, "<table><tr><td>KeyID</td><td>Name</td></tr>\n"); - - while(graph_link != NULL) - { - graph = graph_link->graph; - LIST_FOREACH(node_link, graph->node_list, list) - { - node = (struct node *) node_link->node; - alias = aliaslist_find(graph->alias_list, node->uid); - fprintf(filep, "<tr><td><a href=\"%s/%s\">%s</a></td><td>%s</td></tr>\n", node->uiddir, node->uid, node->uid, ((alias != NULL)?(alias->name):"")); - } - - graph_link = LIST_NEXT(graph_link, list); - } - fprintf(filep, "</table></div>\n"); - } - - fprintf(filep, "</body></html>\n"); - fclose(filep); - - return; - } - struct graphlist * analysis_seperate_nodes(struct graph *graph) --- 62,65 ---- *************** *** 227,251 **** } - int - create_new_directory(char *dirname) - { - int rtn; - struct stat *sb; - - rtn = 0; - sb = NULL; - /* Allocate memory for sb */ - if(((sb = (struct stat *) malloc(sizeof(struct stat))) == NULL) || - /* Stat the current working directory for mode value */ - (stat(".", sb) == -1) || - /* Make the new directory with the cwd's mode value */ - (mkdir(dirname, sb->st_mode) == -1)) - rtn = -1; - free(sb); - return rtn; - } - - /* DONE - */ char *get_field() { --- 132,135 ---- *************** *** 283,289 **** char *output_dir; - warnx("DEBUG:001"); graph = graph_new(aliaslist_new(), nodelist_new()); - warnx("DEBUG:002"); output_dir = NULL; --- 167,171 ---- *************** *** 298,302 **** exit(EXIT_FAILURE); } - warnx("DEBUG:003"); if(output_dir == NULL) { --- 180,183 ---- *************** *** 304,383 **** exit(EXIT_FAILURE); } - warnx("DEBUG:004"); parse_input(graph); - warnx("DEBUG:005"); do_analysis(graph, output_dir); - warnx("DEBUG:006"); return EXIT_SUCCESS; } - /* key == node - */ - void - output_file(struct node *node, struct graph *graph) - { - struct alias *alias; - struct nodelink *node_link; - struct nodelist *nodes_we_link_to; - struct nodelist *tmp_nodelist; - FILE *filep; - unsigned int tmp_size; - - create_new_directory(node->uiddir); - - chdir(node->uiddir); - - filep = fopen(node->uid, "a"); - - fprintf(filep, "Keyid: %s\n", node->uid); - - alias = aliaslist_find(graph->alias_list, node->uid); - fprintf(filep, "Name: %s \n\n", alias->name); - - fprintf(filep, "Signatures to this key:\n"); - nodelist_print(filep, node->links); - tmp_size = nodelist_size(node->links); - fprintf(filep, " Total: %u signature%s to this key from this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - - nodes_we_link_to = nodelist_new(); - LIST_FOREACH(node_link, graph->node_list, list) - if(nodelist_find(((struct node *) node_link->node)->links, node) != NULL) - nodelist_add(nodes_we_link_to, node_link->node); - fprintf(filep, "Signatures from this key:\n"); - nodelist_print(filep, nodes_we_link_to); - tmp_size = nodelist_size(nodes_we_link_to); - fprintf(filep, " Total: %u signature%s from this key to this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - - fprintf(filep, "MSD: %.4f\n\n", node->msd); - - tmp_nodelist = nodelist_subtract(graph->node_list, nodelist_union(node->links, nodes_we_link_to)); - fprintf(filep, "This key has not signed, nor been signed by:\n"); - nodelist_print(filep, tmp_nodelist); - fprintf(filep, " Total: %u key%s in this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - - tmp_nodelist = nodelist_subtract(node->links, nodes_we_link_to); - fprintf(filep, "This key has not signed, but has been signed by:\n"); - nodelist_print(filep, tmp_nodelist); - tmp_size = nodelist_size(tmp_nodelist); - fprintf(filep, " Total: %u key%s in this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - nodelist_free(tmp_nodelist); - - tmp_nodelist = nodelist_subtract(nodes_we_link_to, node->links); - fprintf(filep, "This key has signed, but has not been signed by:\n"); - nodelist_print(filep, tmp_nodelist); - tmp_size = nodelist_size(tmp_nodelist); - fprintf(filep, " Total: %u key%s in this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - nodelist_free(tmp_nodelist); - - tmp_nodelist = nodelist_intersection(node->links, nodes_we_link_to); - fprintf(filep, "This key has signed and has been signed by:\n"); - nodelist_print(filep, tmp_nodelist); - tmp_size = nodelist_size(tmp_nodelist); - fprintf(filep, " Total: %u key%s in this set.\n\n", tmp_size, ((tmp_size == 1)?"":"s")); - nodelist_free(tmp_nodelist); - fclose(filep); - chdir(".."); - - return; - } void parse_input(struct graph *graph) --- 185,192 ---- *************** *** 476,497 **** } - void print_list(FILE *filep, struct graph *graph) - { - struct node *node; - struct nodelink *node_link; - char *uid; - char *name; - - LIST_FOREACH(node_link, graph->node_list, list) - { - node = node_link->node; - uid = node->uid; - name = aliaslist_find(graph->alias_list, uid)->name; - fprintf(filep, " %s %s\n", uid, name); - } - return; - - } - void usage(void) { --- 285,288 ---- |