ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
tagmsg.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "scan.h"
3#include "fmt.h"
4#include "logmsg.h"
5#include "cookie.h"
6#include "slurp.h"
7#include "errtxt.h"
8#include "subscribe.h"
9#include "makehash.h"
10#include "idx.h"
11#include <mysql.h>
12#include <mysqld_error.h>
13
14#define WHO "tagmsg"
15
21
22extern MYSQL *mysql;
23
24static stralloc line = {0};
25static stralloc key = {0};
26static char hash[COOKIE];
27static char strnum[FMT_ULONG]; /* message number as sz */
28
44
45void tagmsg(const char *dir,unsigned long msgnum,const char *seed,const char *action,
46 char *hashout, unsigned long bodysize,unsigned long chunk)
47{
48 const char *table = (char *) 0;
49 const char *ret;
50 unsigned int i;
51
52 strnum[fmt_ulong(strnum,msgnum)] = '\0'; /* message nr ->string*/
53
54 switch (slurp("key",&key,32)) {
55 case -1: logmsg(WHO,111,FATAL,B("ERR_READ :","key");
56 case 0: logmsg(WHO,100,FATAL,B("key","ERR_NOEXIST"));
57 }
58
59 cookie(hash,key.s,key.len,strnum,seed,action);
60
61 for (i = 0; i < COOKIE; i++)
62 hashout[i] = hash[i];
63
64 if ((ret = opensql(dir,&table))) {
65 if (*ret) logmsg(WHO,2x(111,FATAL,ret);
66 return; /* no sql => success */
67 } else {
68 if (chunk >= 53L) chunk = 0L; /* sanity */
69
70 /* INSERT INTO table_cookie (msgnum,cookie) VALUES (num,cookie) */
71 /* (we may have tried message before, but failed to complete, so */
72 /* ER_DUP_ENTRY is ok) */
73
74 if (!stralloc_copys(&line,"INSERT INTO ")) die_nomem();
75 if (!stralloc_cats(&line,table)) die_nomem();
76 if (!stralloc_cats(&line,"_cookie (msgnum,cookie,bodysize,chunk) VALUES (")) die_nomem();
77 if (!stralloc_cats(&line,strnum)) die_nomem();
78 if (!stralloc_cats(&line,",'")) die_nomem();
79 if (!stralloc_catb(&line,hash,COOKIE)) die_nomem();
80 if (!stralloc_cats(&line,"',")) die_nomem();
81 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,bodysize))) die_nomem();
82 if (!stralloc_cats(&line,",")) die_nomem();
83 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,chunk))) die_nomem();
84 if (!stralloc_cats(&line,")")) die_nomem();
85 if (mysql_real_query(mysql,line.s,line.len) != 0)
86 if (mysql_errno(mysql) != ER_DUP_ENTRY) /* ignore dups */
87 logmsg(WHO,111,FATAL,mysql_error(mysql)); /* cookie query */
88
89 if (!(ret = logmsg(dir,msgnum,0L,0L,1))) return; /* log done = 1*/
90 if (*ret) logmsg(WHO,111,FATAL,ret);
91 }
92
93 return;
94}
int slurp(const char *fn, struct stralloc *sa, int bufsize)
#define COOKIE
Definition cookie.h:4
Error messages. If you translate these, I would urge you to keep the English version as well....
const char * opensql(const char *dir, const char **table)
Definition opensql.c:13
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
stralloc seed
Definition ezmlm-get.c:74
char hashout[COOKIE]
Definition ezmlm-get.c:90
char * dir
void cookie(char *hash, const char *key, unsigned int keylen, const char *date, const char *addr, const char *action)
Definition cookie.c:14
unsigned long msgnum
stralloc action
Definition ezmlm-store.c:84
MYSQL * mysql
Definition opensql.c:23
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32
void tagmsg(const char *dir, unsigned long msgnum, const char *seed, const char *action, char *hashout, unsigned long bodysize, unsigned long chunk)
Definition tagmsg.c:45