Article View: news.software.readers
Article #22693slrn0.8.8.2 patch for killing cross posts
From: Felix von Leitner
Date: Wed, 12 Jun 1996 00:00
Date: Wed, 12 Jun 1996 00:00
239 lines
6595 bytes
6595 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Slrn *does* kill cross posts already. But your news servers needs to
have the Xref command in the xover output. The two news servers I use
don't. So I hacked together this little diff. It's a kludge. I'm sure
John could do it better. But it works for me.
What it does:
* keep a hash table with linked lists for each message ID together
with the first newsgroup it appeared in.
* when an article is scored (i.e. when you enter a newsgroup),
this code looks whether the message id is already in the hash table.
If it is, then the article is scored -9999. Otherwise it is entered
with the current newsgroup.
I carry the newsgroup around so that you can leave and re-enter a
newsgroup without getting all the articles killed.
I tried to minimize the memory requirements of my code by storing the
name of the first newsgroup where an article was sighted only once. To
achieve this, another hash table is created which holds just pointers
to newsgroup names.
Please note that the message ids are not stored persistently. If you
leave slrn without having entered a newsgroup where a cross posted
article occurred, it is not killed.
Please verify the digital signature with PGP. Then
apply this patch by piping verified article through "patch -s".
You can also get this patch from
http://www.math.fu-berlin.de/~leitner/slrn.crosspost.diff
Enjoy!
Felix
- --- slrn/src/modules.lis.orig Wed Jun 12 03:10:06 1996
+++ slrn/src/modules.lis Wed Jun 12 01:36:18 1996
@@ -12,3 +12,4 @@
uudecode
mime
menu
+killdupe
- --- slrn/src/slrn.c.orig Wed Jun 12 03:10:18 1996
+++ slrn/src/slrn.c Wed Jun 12 01:40:22 1996
@@ -49,6 +49,7 @@
#include "startup.h"
#include "art.h"
#include "score.h"
+#include "killdupe.h"
#ifdef __os2__
# define INCL_VIO
@@ -724,6 +725,7 @@
else usage (NULL);
}
+ inithashtab();
fprintf (stdout, "slrn %s\n", Slrn_Version);
if (dsc_flag && create_flag)
- --- slrn/src/killdupe.h.orig Wed Jun 12 03:10:43 1996
+++ slrn/src/killdupe.h Wed Jun 12 02:22:02 1996
@@ -0,0 +1,5 @@
+
+void inithashtab(); /* Initialize the msgid dupe killer */
+char *there(const char *c); /* return newsgroup where c was first sighted or NULL */
+void add(const char *c,const char *n); /* add c in newsgroup n. */
+char *alloc_newsgroup(const char *c); /* if given a newsgroup, return a pointer to a string where it will be stored, so that newsgroups don't need to be allocated 1000 times */
- --- slrn/src/killdupe.c.orig Wed Jun 12 03:10:46 1996
+++ slrn/src/killdupe.c Wed Jun 12 02:46:50 1996
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+unsigned short hash(const char *c) {
+ unsigned i=0;
+ while (*c) {
+ i=(i*7+(int) *c) % 4096;
+ c++;
+ }
+ return i;
+}
+
+struct node {
+ char *key,*key2;
+ struct node *next;
+};
+
+static struct node *hashtab[4096];
+static struct node *newsgroups[4096];
+static int dontgrow=0;
+
+void dump_hash(struct node *ht[]) {
+ int i;
+ struct node *h;
+ for (i=0;i<4096;i++) {
+ h=ht[i];
+ while (h) {
+ printf("%s %s\n",h->key,h->key2);
+ h=h->next;
+ }
+ }
+}
+
+struct node *hash_there(struct node *ht[], const char *c) {
+ int h=hash(c);
+ struct node *n=ht[h];
+ while (n) {
+ if (strcmp(n->key,c) == 0) {
+ return n;
+ }
+ n=n->next;
+ }
+ return 0;
+}
+
+int hash_add(struct node *ht[], const char *c, const char *second) {
+ int h=hash(c);
+ struct node *n=ht[h];
+ while (n) {
+ if (strcmp(n->key,c) == 0) {
+ return 1;
+ }
+ n=n->next;
+ }
+ if (dontgrow) return 0;
+ n=malloc(sizeof(struct node));
+ if (n == NULL) {
+ dontgrow=1;
+ return 0;
+ }
+ n->next = ht[h];
+ n->key = malloc(strlen(c)+1);
+ if (n->key==NULL) {
+ dontgrow=1;
+ return 0;
+ }
+ strcpy(n->key,c);
+ if (second) {
+ n->key2 = malloc(strlen(second)+1);
+ if (n->key2==NULL) {
+ dontgrow=1;
+ return 0;
+ }
+ strcpy(n->key2,second);
+ }
+ ht[h]=n;
+ return 0;
+}
+
+void inithashtab() {
+ int i;
+ for (i=0;i<4096;i++) {
+ hashtab[i]=0;
+ newsgroups[i]=0;
+ }
+}
+
+char *there(const char *c) {
+ struct node *n=hash_there(hashtab,c);
+ if (n)
+ return n->key2;
+ else
+ return NULL;
+}
+
+void add(const char *c,const char *n) {
+ hash_add(hashtab,c,n);
+}
+
+char *alloc_newsgroup(const char *c) {
+ struct node *n=hash_there(newsgroups,c);
+ if (n) return n->key;
+ hash_add(newsgroups,c,NULL);
+ n=hash_there(newsgroups,c);
+ return n->key;
+}
+
+/*
+int main()
+{
+ char s[1024];
+ int i;
+ inithashtab();
+ while (gets(s)) {
+ i = there(s);
+ if (i) {
+ printf("Huh: %d %s\n",i,s);
+ } else {
+ i=add(s);
+ }
+ }
+ return 0;
+}
+*/
- --- slrn/src/score.c.orig Wed Jun 12 03:10:54 1996
+++ slrn/src/score.c Wed Jun 12 02:52:01 1996
@@ -14,6 +14,7 @@
#include "score.h"
#include "misc.h"
#include "nntp.h"
+#include "killdupe.h"
/* This file will implement article scoring for slrn. Basically the idea is
* that the user will provide a set of regular expressions that will act on
@@ -124,6 +125,12 @@
char *s = NULL;
int ival = 0;
+ if ((s=there(h->msgid))) { /* This article is a dupe. */
+ if (strcmp(s,newsgroup)) return (-9999);
+ /* Kill it if this wasn't the newsgroup were we saw it */
+ }
+ add(h->msgid,alloc_newsgroup(newsgroup));
+ s=NULL;
st = Score_Root;
while (st != NULL)
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: latin1
iQCVAwUBMb4kiB/Da1Yoy+f1AQFZmgQAjMtskJBHyVz93fx8zzGJiLbSU34xdvvH
L578v9gXg99tCy6FJd5q/tPn1C9/2Ssyy7cHYPBZ20tSBtUwzUvmAFkbwVrT0ibc
1MDp3bkD06WCOi5Zj8C88fpJl6PSSrDXIL3ut44JsKGWKmoWriCHUOrNzDBrGJaM
I4NZHAkmaIY=
=3ZlW
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<slrn4rs94a.4n6.leitner@xorn.prz.tu-berlin.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <slrn4rs94a.4n6.leitner@xorn.prz.tu-berlin.de> Subject: slrn0.8.8.2 patch for killing cross posts Date: Wed, 12 Jun 1996 00:00:00 +0000 From: leitner@xorn.prz.tu-berlin.de (Felix von Leitner) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail X-Deja-AN: 159727106 Organization: Miscatonic University Reply-to: leitner@prz.tu-berlin.de Newsgroups: news.software.readers