src/hg/instinct/hgHeatmap2/trashDirMD5.c 1.4
1.4 2009/06/04 03:50:37 jsanborn
added copyright notices, removed cluster library
Index: src/hg/instinct/hgHeatmap2/trashDirMD5.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgHeatmap2/trashDirMD5.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 1000000 -r1.3 -r1.4
--- src/hg/instinct/hgHeatmap2/trashDirMD5.c 3 Oct 2008 23:56:11 -0000 1.3
+++ src/hg/instinct/hgHeatmap2/trashDirMD5.c 4 Jun 2009 03:50:37 -0000 1.4
@@ -1,71 +1,71 @@
-// Code by: B-Con (http://b-con.us)
-// Released under the GNU GPL
-// MD5 Hash Digest implementation (little endian byte order)
+/********************************************************************************/
+/* Copyright 2007-2009 -- The Regents of the University of California */
+/********************************************************************************/
#include "common.h"
#include "hash.h"
#include "cart.h"
#include "portable.h"
#include "md5.h"
#include "linefile.h"
#include "hCommon.h"
#include "hdb.h"
#include "hPrint.h"
#include "htmshell.h"
#include "hui.h"
#include "web.h"
static char const rcsid[] = "$Id$";
char *md5HashString(char *msg)
{
if (!msg)
return NULL;
int i;
struct md5_context ctx;
unsigned char md5sum[16];
md5_starts(&ctx);
md5_update(&ctx, (uint8 *) msg, strlen(msg));
md5_finish(&ctx, md5sum);
if (!md5sum)
return NULL;
struct dyString *dy = newDyString(50);
for (i = 0; i < 16; i++)
dyStringPrintf(dy, "%02x", md5sum[i]);
return dy->string;
}
void trashDirMD5File(struct tempName *tn, char *dirName, char *suffix,
char *strToHash)
/* obtain a trash file name trash/dirName/<md5sum>.suffix */
{
if (!strToHash)
return;
static struct hash *dirHash = NULL;
if (!dirHash)
dirHash = newHash(0);
/* already created this directory ? */
if (!hashLookup(dirHash,dirName))
{
hashAddInt(dirHash, dirName, 1); /* remember, been here, done that */
mkdirTrashDirectory(dirName);
}
/* no need to duplicate the _ at the end of base, makeTempName is going
* to add _ to the given base, some CGIs pass "base_"
*/
char *hash = md5HashString(strToHash);
if (!hash)
errAbort("Couldn't compute md5 hash for %s", strToHash);
//char filename[128];
safef(tn->forCgi, sizeof(tn->forCgi), "../trash/%s/%s%s", dirName, hash, suffix);
safef(tn->forHtml, sizeof(tn->forHtml), "../trash/%s/%s%s", dirName, hash, suffix);
}