[digraphanalysis-cvs] digraphanalysis/src output.c,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-05-14 19:30:06
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27958 Added Files: output.c Log Message: seperate functions that output data from main.c --- NEW FILE: output.c --- /* $Id: output.c,v 1.1 2005/05/14 19:29:57 jbreker Exp $ * * Copyright (C) 2005 Jeff Breker <jb...@sy...> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/stat.h> #include <sys/types.h> #include <ctype.h> #include <err.h> #include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> #include <unistd.h> #include "alias.h" #include "graph.h" #include "main.h" #include "node.h" 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; 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; } 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; } 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 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; } |