fix dlen
[citadel.git] / citadel / server / usetable.c
1 // use table handler
2 //
3 // Copyright (c) 1987-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
7
8
9 #include <stdio.h>
10 #include <libcitadel.h>
11
12 #include "citserver.h"
13 #include "ctdl_module.h"
14 #include "config.h"
15 #include "control.h"
16
17
18 // Has an item already been seen (is it in the CDB_USETABLE) ?
19 // Returns 0 if it hasn't, 1 if it has
20 // In either case, writes the item to the database for next time.
21 int CheckIfAlreadySeen(StrBuf *guid) {
22         int found = 0;
23         struct UseTable ut;
24         struct cdbdata cdbut;
25         int hash = HashLittle(ChrPtr(guid), StrLength(guid));
26
27         syslog(LOG_DEBUG, "usetable: CheckIfAlreadySeen(0x%8x)", hash);
28         cdbut = cdb_fetch(CDB_USETABLE, &hash, sizeof(hash));
29         if (cdbut.ptr != NULL) {
30                 found = 1;
31         }
32
33         // (Re)write the record, to update the timestamp.
34         ut.hash = hash;
35         ut.timestamp = time(NULL);
36         cdb_store(CDB_USETABLE, &hash, sizeof(hash), &ut, sizeof(struct UseTable));
37         return(found);
38 }