2
** id_parse.c Receive and parse a reply from an IDENT server
4
** Author: Peter Eriksson <pen@lysator.liu.se>
5
** Fiddling: P�r Emanuelsson <pell@lysator.liu.se>
13
#include <sys/types.h>
20
#if defined(ultrix) || defined(AIX_PS2)
27
if ((p = malloc(strlen(s) + 1)) != NULL)
36
(char *cp, char *cs, char *dc)
50
** No delimitor cs - return whole buffer and point at end
60
** Skip leading spaces
72
while (*bp && !index(cs, *bp))
76
** Remove trailing spaces
79
for (dc = bp-1; dc > cp && isspace(*dc); dc--)
92
struct timeval *timeout,
99
(id, timeout, lport, fport, identifier, opsys, charset)
101
struct timeval *timeout;
109
char c, *cp, *tmp_charset;
111
int pos, res, lp, fp;
118
if (lport) *lport = 0;
119
if (fport) *fport = 0;
120
if (identifier) *identifier = 0;
121
if (opsys) *opsys = 0;
122
if (charset) *charset = 0;
124
pos = strlen(id->buf);
131
if ((res = select(FD_SETSIZE, &rs, (fd_set *)0, (fd_set *)0, timeout)) < 0)
141
while (pos < sizeof(id->buf) &&
142
(res = read(id->fd, id->buf + pos, 1)) == 1 &&
143
id->buf[pos] != '\n')
155
if (id->buf[pos] != '\n')
158
id->buf[pos++] = '\0';
161
** Get first field (<lport> , <fport>)
163
cp = xstrtok(id->buf, ":", &c);
167
if (sscanf(cp, " %d , %d", &lp, &fp) != 2)
169
if (identifier) *identifier = strdup(cp);
173
if (lport) *lport = lp;
174
if (fport) *fport = fp;
177
** Get second field (USERID or ERROR)
179
cp = xstrtok((char *)0, ":", &c);
183
if (strcmp(cp, "ERROR") == 0)
185
cp = xstrtok((char *)0, "\n\r", &c);
189
if (identifier) *identifier = strdup(cp);
193
else if (strcmp(cp, "USERID") == 0)
196
** Get first subfield of third field <opsys>
198
cp = xstrtok((char *)0, ",:", &c);
202
if (opsys) *opsys = strdup(cp);
205
** We have a second subfield (<charset>)
209
cp = xstrtok((char *)0, ":", &c);
214
if (charset) *charset = strdup(cp);
217
** We have even more subfields - ignore them
220
xstrtok((char *)0, ":", &c);
223
if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0)
224
cp = xstrtok((char *)0, (char *)0, &c);
226
cp = xstrtok((char *)0, "\n\r", &c);
228
if (identifier) *identifier = strdup(cp);
233
if (identifier) *identifier = strdup(cp);