Skip to content

Commit 4d257b4

Browse files
0-wiz-0Thomas Klausner
authored and
Thomas Klausner
committedJan 17, 1998
Slowly adding decoding.
1 parent 3e75d24 commit 4d257b4

11 files changed

+333
-37
lines changed
 

‎Makefile.am

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ INCLUDES=-I$(srcdir)/libmap
22

33
SUBIDRS=libmap
44

5-
bin_PROGRAMS=checkgroup
5+
bin_PROGRAMS=cg
66

7-
checkgroup_SOURCES=checkgroup.c sockets.c ranges.c parserc.l util.c newsrc.c
8-
checkgroup_LDADD=libmap/libmap.a @LIBOBJS@ @LEXLIB@
7+
cg_SOURCES=checkgroup.c sockets.c ranges.c parserc.l util.c newsrc.c
8+
cg_LDADD=libmap/libmap.a @LIBOBJS@ @LEXLIB@
99

10-
noinst_HEADER=ranges.h util.h newsrc.h globals.h
10+
noinst_HEADER=ranges.h util.h newsrc.h globals.h getopt.h

‎TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
* leftmost " - "
77
* NNTPSERVER from environment
88
* xref handling
9-
* [x of y]
9+
* reconnect upon timeout

‎checkgroup.c

+35-15
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ struct file {
2727
long size;
2828
};
2929

30-
#define MAX_PATTERNS 4
30+
#define MAX_PATTERNS 5
3131

3232
char *spattern[MAX_PATTERNS] = { /* ! ( ! */
33-
"(.*) - (.*[^ ]) *[[(]([0-9]*)/([0-9]*)[])]", /* "c - n ()" */
33+
"(.*) - (.*[^ ]) *[[(]([0-9]*)/([0-9]*)[])]", /* "c - n ()" */
3434
"- (.*[^ ]) *[[(]([0-9]*)/([0-9]*)[])] *(.*)", /* "- n () c" mac groups */
35-
"(.*)()[[(]([0-9]*)/([0-9]*)[])]", /* "n ()" desperate */
36-
"(.*)[[(]([0-9]+) of ([0-9]+)[])](.*)" /* "n[x of y]c" */
35+
"(.*)()[[(]([0-9]*)/([0-9]*)[])]", /* "n ()" desperate */
36+
"(.*)[[( ]([0-9]+) of ([0-9]+)[]) ](.*)", /* "c[x of y]n" */
37+
"(.*) *([^ ]*\\.[rst][a0-9][r0-9]) *$" /* "c n.rar" */
3738
};
3839

3940
regex_t pattern[MAX_PATTERNS];
4041

41-
int pat_key[MAX_PATTERNS] = { 2, 1, 1, 1 };
42-
int pat_comment[MAX_PATTERNS] = { 1, 4, 2, 4 };
43-
int pat_part[MAX_PATTERNS] = { 3, 2, 3, 2 };
44-
int pat_npart[MAX_PATTERNS] = { 4, 3, 4, 3 };
42+
int pat_key[MAX_PATTERNS] = { 2, 1, 1, 2, 2 };
43+
int pat_comment[MAX_PATTERNS] = { 1, 4, 2, 4, 1 };
44+
int pat_part[MAX_PATTERNS] = { 3, 2, 3, 1, 0 };
45+
int pat_npart[MAX_PATTERNS] = { 4, 3, 4, 3, 0 };
4546

4647
char *prg;
4748
char *nntp_response;
@@ -67,7 +68,7 @@ PACKAGE " under the terms of the GNU General Public License.\n\
6768
For more information about these matters, see the files named COPYING.\n";
6869

6970
char usage_string[] = "\
70-
Usage: %s [-m] group ...\n";
71+
Usage: %s [-cm] [-n rcfile] group ...\n";
7172

7273
char help_string[] = "\
7374
\n\
@@ -202,6 +203,17 @@ main(int argc, char **argv)
202203
continue;
203204
}
204205

206+
if (no_art == 0) {
207+
printf("%s: no new files found in %s\n", prg, argv[i]);
208+
continue;
209+
}
210+
211+
if (lower > upper || no_art < 0 || lower < 0 || upper < 0) {
212+
fprintf(stderr, "%s: invalid response from newsserver"
213+
" for group %s: %s\n", prg, argv[i], nntp_response);
214+
continue;
215+
}
216+
205217
readrc(argv[i], lower, upper, no_art);
206218

207219
nntp_put("xover %ld-%ld", lower, upper);
@@ -438,12 +450,20 @@ parse(map *parts, FILE *f)
438450

439451
key = extract(subj, match[pat_key[i]]);
440452
comment = extract(subj, match[pat_comment[i]]);
441-
s = extract(subj, match[pat_part[i]]);
442-
part = atoi(s);
443-
free(s);
444-
s = extract(subj, match[pat_npart[i]]);
445-
npart = atoi(s);
446-
free(s);
453+
if (pat_part[i]) {
454+
s = extract(subj, match[pat_part[i]]);
455+
part = atoi(s);
456+
free(s);
457+
}
458+
else
459+
part = 1;
460+
if (pat_npart[i]) {
461+
s = extract(subj, match[pat_npart[i]]);
462+
npart = atoi(s);
463+
free(s);
464+
}
465+
else
466+
npart = 1;
447467

448468
if (part == 0) {
449469
/* XXX save info */

‎decode.c

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
enum enctype
2+
decode(FILE *fin, FILE *fout, enum enctype type)
3+
{
4+
struct header *h;
5+
struct mime_hdr *m;
6+
char *s, *line;
7+
int nel;
8+
9+
if ((h=header_read(fin, 1)) == NULL)
10+
return enc_eof;
11+
12+
if (type == enc_unknown) {
13+
if ((s=header_get(h, HDR_CONTENT_TYPE))) {
14+
if ((m=mime_parse(s)) != NULL) {
15+
if (m->type == MIME_CT_MSG_PART) {
16+
/* XXX: message/partial */
17+
}
18+
else if (m->type == MIME_CT_MSG_MULTI) {
19+
/* XXX: message/multipart */
20+
}
21+
mime_free(m);
22+
}
23+
}
24+
else if ((s=header_get(h, HDR_CONTENT_TRENC))) {
25+
if ((m=mime_parse(s)) != NULL) {
26+
if (m->type == MIME_TE_BASE64) {
27+
/* XXX: mime base64 (single part) */
28+
29+
mime_free(m);
30+
return enc_eof;
31+
}
32+
mime_free(m);
33+
}
34+
}
35+
36+
/* non mime */
37+
38+
nel = 0;
39+
while (type == enc_unknown) {
40+
if ((line=getline(fin)) == NULL) {
41+
/* XXX: no encoded data found */
42+
}
43+
if (strncasecmp(line, "begin ", 6) == 0) {
44+
s = line+6 + strspn(line+6, "01234567");
45+
if (s != line+6 && *s == ' ') {
46+
/* found uuencoded data */
47+
48+
s = strdup(s+1);
49+
filename = s;
50+
fout = fopen_uniq(&filename);
51+
if (filename != s)
52+
free(s);
53+
type = enc_uu;
54+
decode_uu(fin, fout);
55+
}
56+
}
57+
else if (strcmp(line, BINHEX_TAG) == 0) {
58+
/* found binhexed data */
59+
type = enc_binhex;
60+
}
61+
else if (line[0] == 0) {
62+
nel++;
63+
}
64+
else {
65+
/* XXX: ignore BEGIN, CUT HERE, etc. */
66+
if (fdesc == NULL) {
67+
/* XXX: open desc file */
68+
}
69+
else {
70+
for (i=0; i<nel; i++)
71+
putc('\n', fdesc);
72+
nel = 0;
73+
}
74+
fprints(fdesc, "%s\n", line);
75+
}
76+
}
77+
if (fdesc) {
78+
/* XXX: check for errors */
79+
fclose(fdesc);
80+
}
81+
}
82+
else {
83+
/* XXX: not first part */
84+
}
85+
}

‎header.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "symbol.h"
2+
3+
struct header {
4+
symbol type;
5+
char *value;
6+
};
7+
8+
9+
10+
#define HDR_SUBJECT hdr_sym[0]
11+
#define HDR_MIME_VERSION hdr_sym[1]
12+
#define HDR_CONTENT_TYPE hdr_sym[2]
13+
#define HDR_CONTENT_TRENC hdr_sym[3]
14+
#define HDR_CONTENT_DISP hdr_sym[4]
15+
16+
#define HDR_MAX 5
17+
18+
char *hdr_string[HDR_MAX] = {
19+
"Subject",
20+
"Mime-Version",
21+
"Content-Type",
22+
"Content-Transfer-Encoding",
23+
"Content-Disposition"
24+
};
25+
26+
symbol hdr_sym[HDR_MAX];
27+
28+
29+
30+
int header_init(void);
31+
32+
struct header *header_read(FILE *f, int dotp);
33+
int header_print(FILE *f, struct header *header);
34+
char *header_get(struct header *header, symbol field);
35+

‎keymap.c

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
struct keymap **
2+
lookup(struct keymap *global, struct keymap *local, enum km_op what)
3+
{
4+
int key;
5+
struct keymap **k;
6+
7+
while (!end && (key=tty_readkey()) != EOF) {
8+
if (abort_key(key))
9+
return NULL;
10+
if (local) {
11+
k = getkey(local, key, what == km_op_ins_local);
12+
13+
if (k == NULL)
14+
local = NULL;
15+
else if (*k == NULL) {
16+
if (what == km_op_ins_local)
17+
return k;
18+
else
19+
local = NULL;
20+
}
21+
else {
22+
switch ((*k)->type) {
23+
case t_array:
24+
case t_list:
25+
local = *k;
26+
break;
27+
case t_key:
28+
return k;
29+
}
30+
}
31+
}
32+
if (global) {
33+
k = getkey(local, key, what == km_op_ins_global);
34+
35+
if (k == NULL)
36+
global = NULL;
37+
else if (*k == NULL) {
38+
if (what == km_op_ins_global)
39+
return k;
40+
else
41+
global = NULL;
42+
}
43+
else {
44+
switch ((*k)->type) {
45+
case t_array:
46+
case t_list:
47+
local = *k;
48+
break;
49+
case t_key:
50+
return k;
51+
}
52+
}
53+
}
54+
}
55+
}
56+
57+
58+
59+
struct keymap **
60+
getkey(struct keymap *m, int key, enum km_op what)
61+
{
62+
struct keymap *l;
63+
64+
switch (m->type) {
65+
case t_array:
66+
if (key < 0 || key >= MAX_KEY)
67+
return NULL;
68+
return &(m->v.a->keymap+key);
69+
70+
case t_list:
71+
for (l=m->v.l; l->next && l->next->key <= key; l=l->next) {
72+
if (l->next->key == key)
73+
return &(l->next->val);
74+
}
75+
76+
/* XXX: insert */
77+
return NULL;
78+
}
79+

‎keymap.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef _HAD_KEYMAP_H
2+
#define _HAD_KEYMAP_H
3+
4+
enum _type { t_array, t_list, t_key };
5+
6+
struct keymap {
7+
enum _type type;
8+
union {
9+
struct km_array *a;
10+
struct km_list *l;
11+
struct km_key *k;
12+
} v;
13+
};
14+
15+
struct km_array {
16+
struct *keymap[MAX_KEY];
17+
};
18+
19+
struct km_list {
20+
struct km_list *next;
21+
int key;
22+
struct keymap *val;
23+
};
24+
25+
struct km_key {
26+
};
27+
28+
#endif /* keymap.h */

‎mime.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef _HAD_MIME_H
2+
#define _HAD_MIME_H
3+
4+
#include "symbol.h"
5+
6+
struct mime_hdr {
7+
symbol type;
8+
struct mime_opt *option;
9+
};
10+
11+
struct mime_opt {
12+
symbol name;
13+
char *val;
14+
};
15+
16+
17+
18+
#define MIME_CT_MSG_PART mime_sym[0]
19+
#define MIME_CT_MSG_MULTI mime_sym[1]
20+
#define MIME_TE_BASE64 mime_sym[2]
21+
22+
#define MIME_MAX 2
23+
24+
char *mime_string[MIME_MAX] = {
25+
"message/partial",
26+
"message/multipart",
27+
"base64"
28+
};
29+
30+
symbol mime_sym[MIME_MAX];
31+
32+
33+
34+
int mime_init(void);
35+
struct mime_hdr *mime_parse(char *header);
36+
void mime_free(struct mime_hdr *m);
37+
38+
#endif /* mime.h */

‎newsrc.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ readrc(char *group, long lower, long upper, long no_art)
3232

3333
parserc(group, rc, lower, upper, no_art);
3434

35-
if (rcmap == NULL) {
35+
if (rcmap == NULL)
3636
rcmap = range_init(lower, upper, no_art);
37-
}
3837

3938
fclose(rc);
4039
return(0);
@@ -55,7 +54,7 @@ writerc(char *group)
5554
if (modified == 0) {
5655
sprintf(b, "%s~", newsrc);
5756
unlink(b);
58-
if (link(newsrc, b) < 0) {
57+
if (link(newsrc, b) < 0 && errno != ENOENT) {
5958
fprintf(stderr, "%s: can't backup newsrc `%s' (left unchanged): "
6059
"%s\n",
6160
prg, newsrc, strerror(errno));

‎parserc.l

+25-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* -*- fundamental -*- */
1+
/* -*- c -*- */
22
%{
33
#include "ranges.h"
44
#include <string.h>
@@ -16,32 +16,44 @@
1616
if (strcasecmp(yytext, group) == 0)
1717
BEGIN(GRUPPE);
1818
}
19-
<GRUPPE>1-[0-9]+ {
20-
if (sscanf(yytext, "%ld-%ld", &lower, &upper) != 2) {
21-
fprintf(stderr, "%s: error lexing\n", prg);
22-
exit(1);
23-
}
24-
rcmap=range_init((upper < min) ? min : upper, max, no_art);
25-
}
2619

2720
<GRUPPE>[0-9]+-[0-9]+ {
2821
if (sscanf(yytext, "%ld-%ld", &lower, &upper) != 2) {
2922
fprintf(stderr, "%s: error lexing\n", prg);
3023
exit(1);
3124
}
32-
range_fill(rcmap, lower, upper, 1);
33-
}
3425

35-
<GRUPPE>1 {
36-
rcmap=range_init((1 < min) ? min : 1, max, no_art);
26+
if (lower < min)
27+
lower = min;
28+
if (upper > max)
29+
upper = max;
30+
31+
if (lower <= upper) {
32+
if (rcmap == NULL) {
33+
if (lower == min) {
34+
rcmap = range_init(upper+1, (upper == max) ? upper+1 : max,
35+
no_art);
36+
}
37+
else {
38+
rcmap = range_init(min, max, no_art);
39+
range_fill(rcmap, lower, upper, 1);
40+
}
41+
}
42+
else
43+
range_fill(rcmap, lower, upper, 1);
44+
}
3745
}
3846

3947
<GRUPPE>[0-9]+ {
4048
if (sscanf(yytext, "%ld", &lower) != 1) {
4149
fprintf(stderr, "%s: error lexing\n", prg);
4250
exit(1);
4351
}
44-
range_set(rcmap, lower);
52+
if (lower >= min && lower <= max) {
53+
if (rcmap == NULL)
54+
rcmap = range_init((lower == min) ? min+1 : min, max, no_art);
55+
range_set(rcmap, lower);
56+
}
4557
}
4658

4759
<GRUPPE>, ;

‎ranges.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ range_init(int lower, int upper, int num)
2222
/* XXX: check for enormous (>100000) ranges */
2323

2424
r->first = lower;
25-
r->length = (upper-lower+7)/8;
25+
r->length = (upper-lower+1+7)/8;
2626
r->length = r->length*8;
2727
r->bitmap=(char *)xmalloc(r->length/8);
2828

0 commit comments

Comments
 (0)
Please sign in to comment.