Import ezmlm-idx 0.40
[ezmlm] / sub_std / checktag.c
1 /*$Id: checktag.c,v 1.4 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 "cookie.h"
7 #include "makehash.h"
8 #include "strerr.h"
9 #include "errtxt.h"
10 #include "subscribe.h"
11
12 static stralloc key = {0};
13 static stralloc line = {0};
14 static stralloc quoted = {0};
15 static char strnum[FMT_ULONG];
16 static char newcookie[COOKIE];
17
18 char *checktag (dir,num,listno,action,seed,hash)
19 /* reads dir/sql. If not present, checks that the hash of seed matches */
20 /* hash and returns success (NULL). If not match returns "". If error, */
21 /* returns error string */
22
23 char *dir; /* the db base dir */
24 unsigned long num; /* message number */
25 unsigned long listno; /* bottom of range => slave */
26 char *action;
27 char *seed; /* cookie base */
28 char *hash; /* cookie */
29 {
30
31 if (!seed) return (char *) 0; /* no data - accept */
32
33 strnum[fmt_ulong(strnum,num)] = '\0'; /* message nr ->string*/
34
35 switch(slurp("key",&key,32)) {
36 case -1:
37 return ERR_READ_KEY;
38 case 0:
39 return ERR_NOEXIST_KEY;
40 }
41
42 cookie(newcookie,key.s,key.len,strnum,seed,action);
43 if (byte_diff(hash,COOKIE,newcookie)) return "";
44 else return (char *) 0;
45
46 }