1 /*$Id: tagmsg.c,v 1.11 1999/11/10 04:08:27 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
10 #include "subscribe.h"
13 #include <mysqld_error.h>
15 static stralloc line
= {0};
16 static stralloc key
= {0};
17 static char hash
[COOKIE
];
18 static char strnum
[FMT_ULONG
]; /* message number as sz */
20 static void die_nomem(fatal
)
23 strerr_die2x(100,fatal
,ERR_NOMEM
);
26 void tagmsg(dir
,msgnum
,seed
,action
,hashout
,bodysize
,chunk
,fatal
)
27 /* This routine creates a cookie from num,seed and the */
28 /* list key and returns that cookie in hashout. The use of sender/num and */
29 /* first char of action is used to make cookie differ between messages, */
30 /* the key is the secret list key. The cookie will be inserted into */
31 /* table_cookie where table and other data is taken from dir/sql. We log */
32 /* arrival of the message (done=0). */
34 char *dir
; /* db base dir */
35 unsigned long msgnum
; /* number of this message */
36 char *seed
; /* seed. NULL ok, but less entropy */
37 char *action
; /* to make it certain the cookie differs from*/
38 /* one used for a digest */
39 char *hashout
; /* calculated hash goes here */
40 unsigned long bodysize
;
44 char *table
= (char *) 0;
48 strnum
[fmt_ulong(strnum
,msgnum
)] = '\0'; /* message nr ->string*/
50 switch(slurp("key",&key
,32)) {
52 strerr_die3sys(111,fatal
,ERR_READ
,"key: ");
54 strerr_die3x(100,fatal
,"key",ERR_NOEXIST
);
56 cookie(hash
,key
.s
,key
.len
,strnum
,seed
,action
);
57 for (i
= 0; i
< COOKIE
; i
++)
60 if ((ret
= opensql(dir
,&table
))) {
61 if (*ret
) strerr_die2x(111,fatal
,ret
);
62 return; /* no sql => success */
65 if (chunk
>= 53L) chunk
= 0L; /* sanity */
67 /* INSERT INTO table_cookie (msgnum,cookie) VALUES (num,cookie) */
68 /* (we may have tried message before, but failed to complete, so */
69 /* ER_DUP_ENTRY is ok) */
70 if (!stralloc_copys(&line
,"INSERT INTO ")) die_nomem(fatal
);
71 if (!stralloc_cats(&line
,table
)) die_nomem(fatal
);
72 if (!stralloc_cats(&line
,"_cookie (msgnum,cookie,bodysize,chunk) VALUES ("))
74 if (!stralloc_cats(&line
,strnum
)) die_nomem(fatal
);
75 if (!stralloc_cats(&line
,",'")) die_nomem(fatal
);
76 if (!stralloc_catb(&line
,hash
,COOKIE
)) die_nomem(fatal
);
77 if (!stralloc_cats(&line
,"',")) die_nomem(fatal
);
78 if (!stralloc_catb(&line
,strnum
,fmt_ulong(strnum
,bodysize
)))
80 if (!stralloc_cats(&line
,",")) die_nomem(fatal
);
81 if (!stralloc_catb(&line
,strnum
,fmt_ulong(strnum
,chunk
))) die_nomem(fatal
);
82 if (!stralloc_cats(&line
,")")) die_nomem(fatal
);
83 if (mysql_real_query((MYSQL
*) psql
,line
.s
,line
.len
) != 0)
84 if (mysql_errno((MYSQL
*) psql
) != ER_DUP_ENTRY
) /* ignore dups */
85 strerr_die2x(111,fatal
,mysql_error((MYSQL
*) psql
)); /* cookie query */
87 if (! (ret
= logmsg(dir
,msgnum
,0L,0L,1))) return; /* log done=1*/
88 if (*ret
) strerr_die2x(111,fatal
,ret
);