3 * $Id: ident.c,v 1.1 1999/07/01 08:56:23 mdw Exp $
5 * Parse replies from RFC931 servers
7 * (c) 1999 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the `fw' port forwarder.
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1999/07/01 08:56:23 mdw
35 * Revision 1.1.1.1 1999/05/21 22:22:27 mdw
36 * Initial import. Code not really finished yet.
40 /*----- Header files ------------------------------------------------------*/
49 /*----- Main code ---------------------------------------------------------*/
53 * Arguments: @char **pp@ = address of string pointer
55 * Returns: Address of next token.
57 * Use: Reads the next token from the result string. Tokens are
58 * terminated by whitespace, or `:' or `,' characters. The
59 * result string has had `\' escapes removed; it's stored in
60 * the same memory as the input string. The actual content
61 * of the delimiter doesn't seem to be interesting, so it
65 static char *next(char **pp)
69 /* --- Deal with reads past the end of the string --- */
74 /* --- Initialize various pointers into the string --- */
78 /* --- Skip past any leading whitespace --- */
80 while (isspace((unsigned char)*p))
83 /* --- Now start work on the string itself --- */
86 if (*p == 0 || *p == ':' || *p == ',' || isspace((unsigned char)*p))
88 else if (*p == '\\') {
98 /* --- Tidy up afterwards --- */
100 while (isspace((unsigned char)*p))
104 else if (*p == ':' || *p == ',')
113 /* --- @ident_parse@ --- *
115 * Arguments: @char *p@ = pointer to input string from identd
116 * @ident *i@ = pointer to output block
120 * Use: Parses a result string from an RFC931 (identd) server.
123 void ident_parse(char *p, ident *i)
127 /* --- Read the source and destination port numbers --- */
129 i->sport = atoi(next(&p));
130 i->dport = atoi(next(&p));
132 /* --- Find out what sort of a reply this is --- */
135 if (strcmp(q, "USERID") == 0) {
136 i->type = ident_userid;
137 i->u.userid.os = next(&p);
138 i->u.userid.user = next(&p);
139 } else if (strcmp(q, "ERROR") == 0) {
140 i->type = ident_error;
141 i->u.error = next(&p);
146 /*----- That's all, folks -------------------------------------------------*/