1 /*  VER 022  TAB P   $Id: msgid.c,v 1.6.2.1 2002/01/29 06:44:48 egil Exp $
2  *
3  *  handle the message IDs
4  *  to ensure we don't read a message twice
5  *
6  *  copyright 1996, 1997 Egil Kvaleberg, egil@kvaleberg.no
7  *  the GNU General Public License applies
8  *
9  *  $Log: msgid.c,v $
10  *  Revision 1.6.2.1  2002/01/29 06:44:48  egil
11  *  Changing from xmalloc, xrealloc, xstrcpy to
12  *  malloc_perfect, realloc_perfect and strdup_perfect
13  *
14  *  Revision 1.6  1999/03/07 14:58:18  src
15  *  Read newsconfig supported. Storage API supported.
16  *
17  *  Revision 1.5  1998/09/09 07:32:12  src
18  *  Version 1.1
19  *
20  *  Revision 1.4  1998/07/12 09:39:29  src
21  *  newsx version 1.0
22  */
23 
24 #include "common.h"
25 #include "proto.h"
26 #include "news.h"
27 
28 /*
29  *  globals for message IDs
30  */
31 typedef struct message_id {
32     struct message_id *next;
33     char name[1]; /* extend as required... */
34 } MESSAGE_ID;
35 
36 #define MESSAGE_HASH 999
37 MESSAGE_ID *messageids[MESSAGE_HASH] = { 0 };
38 
39 /*
40  *  check if msgid is not seen before, adding
41  *  it to the list if not
42  */
43 int
new_msgid(char * msgid)44 new_msgid(char *msgid)
45 {
46     int n;
47     MESSAGE_ID *mp;
48     int h = hashindex(msgid,MESSAGE_HASH);
49 
50     /* find it first.. */
51     for (mp = messageids[h]; mp; mp = mp->next) {
52 	if (strcmp(mp->name,msgid)==0) {
53 	    log_msg(L_DEBUGMORE,"msgid %s fetched already",msgid);
54 	    return 0;
55 	}
56     }
57 
58     /* add to list */
59     n = sizeof(MESSAGE_ID) + strlen(msgid);
60     mp = malloc_perfect(n);
61     strcpy(mp->name,msgid);
62     mp->next = messageids[h];
63     messageids[h] = mp;
64 
65     /* new */
66     return 1;
67 }
68 
69