[digraphanalysis-cvs] digraphanalysis/src alias.c, alias.h, main.c, node.c, node.h,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-05-14 02:56:33
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1148/src Modified Files: alias.c alias.h main.c node.c node.h Log Message: changes Index: node.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** node.h 25 Apr 2005 04:53:14 -0000 1.7 --- node.h 14 May 2005 02:56:24 -0000 1.8 *************** *** 34,37 **** --- 34,38 ---- { char *uid; /* The primary uid identifier for the node */ + char *uiddir; float msd; struct nodelist *links; /* Other nodes that "sign" this node */ Index: alias.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/alias.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** alias.h 21 Apr 2005 19:03:12 -0000 1.4 --- alias.h 14 May 2005 02:56:24 -0000 1.5 *************** *** 43,46 **** --- 43,47 ---- struct alias *aliaslist_add(struct aliaslist *, struct alias *); + struct aliaslist *aliaslist_duplicate(struct aliaslist *); struct alias *aliaslist_find(struct aliaslist *, char *); void aliaslist_free(struct aliaslist *); Index: alias.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/alias.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** alias.c 21 Apr 2005 19:52:11 -0000 1.6 --- alias.c 14 May 2005 02:56:24 -0000 1.7 *************** *** 53,60 **** else { ! strncpy(alias->uid, uid, strlen(uid)); ! *(alias->uid + strlen(uid)) = '\0'; ! strncpy(alias->name, name, strlen(uid)); ! *(alias->name + strlen(name)) = '\0'; alias->node = node; } --- 53,58 ---- else { ! strlcpy(alias->uid, uid, strlen(uid) + 1); ! strlcpy(alias->name, name, strlen(name) + 1); alias->node = node; } *************** *** 97,100 **** --- 95,112 ---- } + struct aliaslist * + aliaslist_duplicate(struct aliaslist *alias_list1) + { + struct aliaslist *alias_list2; + struct aliaslink *alias_link; + + alias_list2 = aliaslist_new(); + + LIST_FOREACH(alias_link, alias_list1, list) + aliaslist_add(alias_list2, alias_link->alias); + + return alias_list2; + } + /* This should take a struct alias, not a char */ struct alias * Index: node.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** node.c 25 Apr 2005 15:07:16 -0000 1.10 --- node.c 14 May 2005 02:56:24 -0000 1.11 *************** *** 40,44 **** --- 40,46 ---- len = strlen(uid) + 1; node->uid = (char *) malloc(len); + node->uiddir = (char *) malloc((len >= 3)?3:len); strlcpy(node->uid, uid, len); + strlcpy(node->uiddir, uid, (len >=3)?3:len); node->msd = 0; Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.c 27 Apr 2005 02:18:26 -0000 1.7 --- main.c 14 May 2005 02:56:24 -0000 1.8 *************** *** 41,45 **** rtn = 0; sb = NULL; ! /* Allocate memory for sb */ if(((sb = (struct stat *) malloc(sizeof(struct stat))) == NULL) || --- 41,45 ---- rtn = 0; sb = NULL; ! warnx("DEBUG:015"); /* Allocate memory for sb */ if(((sb = (struct stat *) malloc(sizeof(struct stat))) == NULL) || *************** *** 49,55 **** (mkdir(dirname, sb->st_mode) == -1)) rtn = -1; ! free(sb); ! return rtn; } --- 49,55 ---- (mkdir(dirname, sb->st_mode) == -1)) rtn = -1; ! warnx("DEBUG:016"); free(sb); ! warnx("DEBUG:017"); return rtn; } *************** *** 65,77 **** struct graphlist *graph_list; if(analysis_main_directory(outputdir) == (-1)) return (-1); ! analysis_nodes(graph); ! graph_list = analysis_seperate_nodes(graph); ! analysis_output_report(graph_list); ! return 0; } --- 65,79 ---- struct graphlist *graph_list; + graph_list = NULL; + warnx("DEBUG:007"); if(analysis_main_directory(outputdir) == (-1)) return (-1); ! warnx("DEBUG:008"); analysis_nodes(graph); ! warnx("DEBUG:009"); graph_list = analysis_seperate_nodes(graph); ! warnx("DEBUG:010"); analysis_output_report(graph_list); ! warnx("DEBUG:011"); return 0; } *************** *** 96,109 **** dir = NULL; rtn = 0; ! /* Create and enter the output directory */ ! if(((dir = dirname(outputdir)) == NULL) || ! (chdir(dir) == -1) || (create_new_directory(outputdir) == -1) || (chdir(outputdir) == -1)) rtn = -1; ! ! free(dir); ! return rtn; } --- 98,113 ---- dir = NULL; rtn = 0; ! warnx("DEBUG:012"); /* 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; ! warnx("DEBUG:013"); ! /* ? ! free(dir); */ ! warnx("DEBUG:014"); return rtn; } *************** *** 113,117 **** { struct alias *alias; - char *dir; FILE *filep; struct graph *graph; --- 117,120 ---- *************** *** 124,136 **** struct nodelink *node_link; 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"); --- 127,144 ---- struct nodelink *node_link; + i = k = 1; + last_msd = -1.0; + graph_link = NULL; filep = fopen("report.html", "w"); fprintf(filep, "<html><body>\n"); ! warnx("OUTPUT:001"); while(!LIST_EMPTY(graph_list)) { + warnx("OUTPUT:002"); 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; + warnx("OUTPUT:006"); 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"); *************** *** 139,142 **** --- 147,151 ---- while(!LIST_EMPTY(graph->node_list)) { + warnx("OUTPUT:003"); node_link = LIST_FIRST(graph->node_list); node = (struct node *) node_link->node; *************** *** 145,154 **** ++k; last_msd = node->msd; - dir = (char *) malloc(3); - strncpy(dir, node->uid, 2); - *(dir + 2) = '\0'; 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, dir, node->uid, node->uid, ((alias != NULL)?(alias->name):""), node->msd); ! free(dir); LIST_REMOVE(node_link, list); } --- 154,159 ---- ++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); } *************** *** 163,166 **** --- 168,172 ---- if(graph_link != NULL) { + warnx("OUTPUT:004"); 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"); *************** *** 168,180 **** while(graph_link != NULL) { graph = graph_link->graph; ! node_link = LIST_FIRST(graph->node_list); ! node = (struct node *) node_link->node; ! dir = (char *) malloc(3); ! strncpy(dir, node->uid, 2); ! *(dir + 2) = '\0'; ! alias = aliaslist_find(graph->alias_list, node->uid); ! fprintf(filep, "<tr><td><a href=\"%s/%s\">%s</a></td><td>%s</td></tr>\n", dir, node->uid, node->uid, ((alias != NULL)?(alias->name):"")); ! free(dir); graph_link = LIST_NEXT(graph_link, list); } --- 174,186 ---- while(graph_link != NULL) { + warnx("OUTPUT:005"); 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); } *************** *** 199,218 **** struct nodelist *node_list_msd2; node_list = nodelist_duplicate(graph->node_list); graph_list = graphlist_new(); while(!LIST_EMPTY(node_list)) { if(((node_list_msd1 = nodelist_new()) == NULL) || ((node_list_msd2 = nodelist_new()) == NULL)) return NULL; nodelist_add_msd(node_list_msd1, LIST_FIRST(node_list)->node); ! LIST_REMOVE(LIST_FIRST(node_list), list); while(nodelist_size(node_list_msd1) != nodelist_size(node_list_msd2)) { nodelist_free(node_list_msd2); if((node_list_msd2 = nodelist_duplicate(node_list_msd1)) == NULL) return NULL; LIST_FOREACH(node_link1, node_list_msd2, list) LIST_FOREACH(node_link2, ((struct node *) node_link1->node)->links, list) --- 205,243 ---- struct nodelist *node_list_msd2; + /* Duplicate the graphs alias and node lists so as to not modify the original copies. + */ + alias_list = aliaslist_duplicate(graph->alias_list); node_list = nodelist_duplicate(graph->node_list); + + /* Create the list, to add the msd sorted graphs to. + */ graph_list = graphlist_new(); + /* Iterate through our copy of the original graph's node list. + */ while(!LIST_EMPTY(node_list)) { + /* Create two new node lists. + */ if(((node_list_msd1 = nodelist_new()) == NULL) || ((node_list_msd2 = nodelist_new()) == NULL)) return NULL; + /* Add the first node from the node list to our msd sorted node list. And remove it from the non msd sorted node list. + */ nodelist_add_msd(node_list_msd1, LIST_FIRST(node_list)->node); ! nodelist_remove(node_list, LIST_FIRST(node_list)->node); ! ! /* Add nodes that link to nodes in list2 to list1 then clone list1 onto list2 and repeat until no updates occur. ! */ while(nodelist_size(node_list_msd1) != nodelist_size(node_list_msd2)) { + /* Duplicate nodelist1 onto nodelist2. + */ nodelist_free(node_list_msd2); if((node_list_msd2 = nodelist_duplicate(node_list_msd1)) == NULL) return NULL; + /* Iterate through nodelist2 adding nodes to nodelist1. + */ LIST_FOREACH(node_link1, node_list_msd2, list) LIST_FOREACH(node_link2, ((struct node *) node_link1->node)->links, list) *************** *** 223,229 **** --- 248,262 ---- } } + + /* Add strongly connected nodelist to the graphlist. + */ graphlist_add(graph_list, graph_new(alias_list, node_list_msd1)); + + /* Free the 2nd nodelist so as to not leak memory. + */ nodelist_free(node_list_msd2); } + /* Free the copy of the node_list. + */ nodelist_free(node_list); *************** *** 268,272 **** --- 301,307 ---- char *output_dir; + warnx("DEBUG:001"); graph = graph_new(aliaslist_new(), nodelist_new()); + warnx("DEBUG:002"); output_dir = NULL; *************** *** 281,285 **** exit(EXIT_FAILURE); } ! if(output_dir == NULL) { --- 316,320 ---- exit(EXIT_FAILURE); } ! warnx("DEBUG:003"); if(output_dir == NULL) { *************** *** 287,294 **** exit(EXIT_FAILURE); } ! parse_input(graph); do_analysis(graph, output_dir); ! return EXIT_SUCCESS; } --- 322,330 ---- exit(EXIT_FAILURE); } ! warnx("DEBUG:004"); parse_input(graph); + warnx("DEBUG:005"); do_analysis(graph, output_dir); ! warnx("DEBUG:006"); return EXIT_SUCCESS; } *************** *** 298,320 **** output_file(struct node *node, struct graph *graph) { struct nodelink *node_link; struct nodelist *nodes_we_link_to; struct nodelist *tmp_nodelist; - char *file_dir; FILE *filep; unsigned int tmp_size; ! file_dir = (char *) malloc(3); ! strncpy(file_dir, node->uid, 2); ! *(file_dir + 2) = '\0'; ! ! create_new_directory(file_dir); ! chdir(file_dir); ! free(file_dir); filep = fopen(node->uid, "a"); ! fprintf(filep, "Keyid: %s\n\n", node->uid); fprintf(filep, "Signatures to this key:\n"); --- 334,354 ---- 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"); *************** *** 365,370 **** } - /* DONE - */ void parse_input(struct graph *graph) { --- 399,402 ---- *************** *** 466,471 **** struct node *node; struct nodelink *node_link; ! ! char *uid, *name; LIST_FOREACH(node_link, graph->node_list, list) --- 498,503 ---- struct node *node; struct nodelink *node_link; ! char *uid; ! char *name; LIST_FOREACH(node_link, graph->node_list, list) |