| 1 | /*$Id: tagmsg.c,v 1.3 1999/10/12 23:38:36 lindberg Exp $*/ |
| 2 | /*$Name: ezmlm-idx-040 $*/ |
| 3 | #include "stralloc.h" |
| 4 | #include "scan.h" |
| 5 | #include "fmt.h" |
| 6 | #include "strerr.h" |
| 7 | #include "cookie.h" |
| 8 | #include "slurp.h" |
| 9 | #include "errtxt.h" |
| 10 | #include "subscribe.h" |
| 11 | #include "makehash.h" |
| 12 | |
| 13 | static stralloc line = {0}; |
| 14 | static stralloc key = {0}; |
| 15 | static char hash[COOKIE]; |
| 16 | static char strnum[FMT_ULONG]; /* message number as sz */ |
| 17 | |
| 18 | static void die_nomem(fatal) |
| 19 | char *fatal; |
| 20 | { |
| 21 | strerr_die2x(100,fatal,ERR_NOMEM); |
| 22 | } |
| 23 | |
| 24 | void tagmsg(dir,msgnum,seed,action,hashout,bodysize,chunk,fatal) |
| 25 | /* This routine creates a cookie from num,seed and the */ |
| 26 | /* list key and returns that cookie in hashout. The use of sender/num and */ |
| 27 | /* first char of action is used to make cookie differ between messages, */ |
| 28 | /* the key is the secret list key. */ |
| 29 | |
| 30 | char *dir; /* db base dir */ |
| 31 | unsigned long msgnum; /* number of this message */ |
| 32 | char *seed; /* seed. NULL ok, but less entropy */ |
| 33 | char *action; /* to make it certain the cookie differs from*/ |
| 34 | /* one used for a digest */ |
| 35 | char *hashout; /* calculated hash goes here */ |
| 36 | unsigned long bodysize; |
| 37 | unsigned long chunk; |
| 38 | char *fatal; |
| 39 | { |
| 40 | unsigned int i; |
| 41 | |
| 42 | strnum[fmt_ulong(strnum,msgnum)] = '\0'; /* message nr ->string*/ |
| 43 | |
| 44 | switch(slurp("key",&key,32)) { |
| 45 | case -1: |
| 46 | strerr_die3sys(111,fatal,ERR_READ,"key: "); |
| 47 | case 0: |
| 48 | strerr_die3x(100,fatal,"key",ERR_NOEXIST); |
| 49 | } |
| 50 | cookie(hash,key.s,key.len,strnum,seed,action); |
| 51 | for (i = 0; i < COOKIE; i++) |
| 52 | hashout[i] = hash[i]; |
| 53 | |
| 54 | return; |
| 55 | } |