Ticket #30: nnrpd-argify

File nnrpd-argify, 4.7 KB (added by eagle, 12 years ago)

Patch to make nnrpd use new Argify()

Line 
1diff -u -r1.52 commands.c
2--- commands.c  2001/06/29 21:42:23     1.52
3+++ commands.c  2001/12/12 04:55:36
4@@ -255,6 +255,8 @@
5     } else {
6
7        if (caseEQ(av[1], "simple")) {
8+           ac--;
9+           ac += reArgify(av[ac],&av[ac],2); // two more should make four
10            if (ac != 4) {
11                Reply("%d AUTHINFO SIMPLE <USER> <PASS>\r\n", NNTP_BAD_COMMAND_VAL);
12                return;
13diff -u -r1.52 misc.c
14--- misc.c      2001/07/11 07:40:46     1.52
15+++ misc.c      2001/12/12 04:55:36
16@@ -33,6 +33,7 @@
17 #endif
18
19
20+
21 /*
22 **  Parse a string into a NULL-terminated array of words; return number
23 **  of words.  If argvp isn't NULL, it and what it points to will be
24@@ -43,7 +44,24 @@
25     char               *line;
26     char               ***argvp;
27 {
28-    register char      **argv;
29+    return nArgify(line,argvp,-1);
30+}
31+
32+
33+/*
34+**  Parse a string into a NULL-terminated array of at most n words;
35+**  return number of words.  If there are more than n words, stop
36+**  processing at the beginning of the (n+1)th word, store everything
37+**  from the beginning of word n+1 in argv[n] and return n+1.  If n is
38+**  negative, parses all words.  If argvp isn't NULL, it and what it
39+**  points to will be DISPOSE'd.
40+*/
41+int
42+nArgify(line, argvp, n)
43+    char               *line;
44+    char               ***argvp;
45+    int                        n;
46+{
47     register char      *p;
48     register int       i;
49
50@@ -59,10 +77,46 @@
51     p = NEW(char, i + 1);
52     (void)strcpy(p, line);
53
54-    /* Allocate worst-case amount of space. */
55-    for (*argvp = argv = NEW(char*, i + 2); *p; ) {
56-       /* Mark start of this word, find its end. */
57-       for (*argv++ = p; *p && !ISWHITE(*p); )
58+    *argvp = NEW(char*, i + 2);
59+
60+    return reArgify(p, *argvp, n);
61+}
62+
63+
64+/*
65+**  Destructively parse a string into a NULL-terminated array of at most
66+**  n words; return number of words.  Behavior on negative n and strings
67+**  of more than n words matches that of nArgify (see above).  Caller
68+**  must supply an array of sufficient size (such as created by
69+**  nArgify).
70+**
71+**  Note that the sequence
72+**     ac = nArgify(line, &argv, n1);
73+**      ac--;
74+**     ac += reArgify(argv[ac], &argv[ac], n2);
75+**  is equivalent to
76+**     ac = nArgify(line, &argv, n1 + n2);
77+*/
78+int
79+reArgify(p, argv, n)
80+    register char      *p;
81+    char               **argv;
82+    int                        n;
83+{
84+    char               **save=argv;
85+
86+
87+    /* Should never happen unless caller modifies argv between calls */
88+    while (ISWHITE(*p))
89+       p++;
90+
91+    for ( ; *p; ) {
92+       if (n == 0) {
93+           *argv++ = p;
94+           break;
95+       }
96+       /* Decrement limit, mark start of this word, find its end. */
97+       for (n--, *argv++ = p; *p && !ISWHITE(*p); )
98            p++;
99        if (*p == '\0')
100            break;
101@@ -72,7 +126,7 @@
102            p++;
103     }
104     *argv = NULL;
105-    return argv - *argvp;
106+    return argv - save;
107 }
108
109
110diff -u -r1.120 nnrpd.c
111--- nnrpd.c     2001/09/25 07:32:15     1.120
112+++ nnrpd.c     2001/12/12 04:55:36
113@@ -123,7 +123,7 @@
114 static char    CMDfetchhelp[] = "[MessageID|Number]";
115
116 static CMDENT  CMDtable[] = {
117-    {  "authinfo",     CMDauthinfo,    FALSE,  3,      CMDany,
118+    {  "authinfo",     CMDauthinfo,    FALSE,  2,      CMDany,
119        "user Name|pass Password|generic <prog> <args>" },
120 #ifdef HAVE_SSL
121     {  "starttls",     CMDstarttls,    FALSE,  1,      1,
122@@ -1169,7 +1169,7 @@
123                continue;
124            if (Tracing)
125                syslog(L_TRACE, "%s < %s", ClientHost, PushedBack);
126-           ac = Argify(PushedBack, &av);
127+           ac = nArgify(PushedBack, &av, 1);
128            r = RTok;
129        }
130        else
131@@ -1195,7 +1195,7 @@
132                    syslog(L_TRACE, "%s < %s", ClientHost, buff);
133                if (buff[0] == '\0')
134                    continue;
135-               ac = Argify(buff, &av);
136+               ac = nArgify(buff, &av, 1);
137                break;
138            case RTeof:
139                /* Handled below. */
140@@ -1220,6 +1220,10 @@
141            Reply("%d What?\r\n", NNTP_BAD_COMMAND_VAL);
142            continue;
143        }
144+
145+       ac--;
146+       ac += reArgify(av[ac], &av[ac],
147+                       (cp->Maxac != CMDany ? cp->Maxac : cp->Minac - ac));
148
149        /* Check usage. */
150        if ((cp->Minac != CMDany && ac < cp->Minac)
151diff -u -r1.52 nnrpd.h
152--- nnrpd.h     2001/07/29 14:36:36     1.52
153+++ nnrpd.h     2001/12/12 04:55:36
154@@ -188,6 +188,8 @@
155 extern bool            ARTreadschema();
156 extern char            *Glom();
157 extern int             Argify();
158+extern int             nArgify();
159+extern int             reArgify();
160 extern void            ExitWithStats(int x, bool readconf);
161 extern bool            GetGroupList();
162 extern char            *GetHeader(char *header, bool IsLines);