3 * $Id: ident.c,v 1.2 1999/07/26 23:26:44 mdw Exp $
5 * Parse replies from RFC931 servers
7 * (c) 1999 Straylight/Edgeware
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.2 1999/07/26 23:26:44 mdw
33 * Change copyright notice.
35 * Revision 1.1.1.1 1999/07/01 08:56:23 mdw
38 * Revision 1.1.1.1 1999/05/21 22:22:27 mdw
39 * Initial import. Code not really finished yet.
43 /*----- Header files ------------------------------------------------------*/
52 /*----- Main code ---------------------------------------------------------*/
56 * Arguments: @char **pp@ = address of string pointer
58 * Returns: Address of next token.
60 * Use: Reads the next token from the result string. Tokens are
61 * terminated by whitespace, or `:' or `,' characters. The
62 * result string has had `\' escapes removed; it's stored in
63 * the same memory as the input string. The actual content
64 * of the delimiter doesn't seem to be interesting, so it
68 static char *next(char **pp)
72 /* --- Deal with reads past the end of the string --- */
77 /* --- Initialize various pointers into the string --- */
81 /* --- Skip past any leading whitespace --- */
83 while (isspace((unsigned char)*p))
86 /* --- Now start work on the string itself --- */
89 if (*p == 0 || *p == ':' || *p == ',' || isspace((unsigned char)*p))
91 else if (*p == '\\') {
101 /* --- Tidy up afterwards --- */
103 while (isspace((unsigned char)*p))
107 else if (*p == ':' || *p == ',')
116 /* --- @ident_parse@ --- *
118 * Arguments: @char *p@ = pointer to input string from identd
119 * @ident *i@ = pointer to output block
123 * Use: Parses a result string from an RFC931 (identd) server.
126 void ident_parse(char *p, ident *i)
130 /* --- Read the source and destination port numbers --- */
132 i->sport = atoi(next(&p));
133 i->dport = atoi(next(&p));
135 /* --- Find out what sort of a reply this is --- */
138 if (strcmp(q, "USERID") == 0) {
139 i->type = ident_userid;
140 i->u.userid.os = next(&p);
141 i->u.userid.user = next(&p);
142 } else if (strcmp(q, "ERROR") == 0) {
143 i->type = ident_error;
144 i->u.error = next(&p);
149 /*----- That's all, folks -------------------------------------------------*/