diff --git a/src/server/prot-a-parse.c b/src/server/prot-a-parse.c index 6dd886f031d3215ba5ce132a5cd395de0bd54b66..5a265c28a900ed67acfd921fbc90c20be1bb8235 100644 --- a/src/server/prot-a-parse.c +++ b/src/server/prot-a-parse.c @@ -1,5 +1,5 @@ /* - * $Id: prot-a-parse.c,v 0.25 1996/07/28 13:37:28 ceder Exp $ + * $Id: prot-a-parse.c,v 0.26 1996/08/01 18:32:02 ceder Exp $ * Copyright (C) 1991, 1992, 1993, 1994, 1995 Lysator Academic Computer Association. * * This file is part of the LysKOM server. @@ -28,7 +28,7 @@ * BUG: Not all functions are used, I think. /ceder */ -static char *rcsid = "$Id: prot-a-parse.c,v 0.25 1996/07/28 13:37:28 ceder Exp $"; +static char *rcsid = "$Id: prot-a-parse.c,v 0.26 1996/08/01 18:32:02 ceder Exp $"; #include "rcs.h" USE(rcsid); @@ -485,3 +485,109 @@ void prot_a_parse_info(Connection *client, client->struct_parse_pos = 0; } } + +void +prot_a_hunt_nl(Connection *client) +{ + String_size number_end; + String_size len; + + while (1) + { + switch (client->fnc_parse_pos) + { + case 0: /* whitspace/simple tokens */ + if ( client->first_to_parse >= s_strlen(client->unparsed) ) + longjmp(parse_env, ISC_MSG_INCOMPLETE); + + switch(client->unparsed.string[client->first_to_parse]) + { + case ' ': + case '\r': + case '\t': + case '{': + case '}': + case '*': + client->first_to_parse++; + break; + case '\n': + /* We found a newline -- end of message. Return now. */ + client->first_to_parse++; + return; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Entering a number -- possibly a string. */ + /* Don't increase first_to_parse. */ + client->fnc_parse_pos = 1; + break; + default: + longjmp(parse_env, ISC_PROTOCOL_ERR); + } + break; + case 1: /* number/string */ + /* Entering a number. The first char is known to be a digit. + Parse the entire number at once. */ + len = client->unparsed.string[client->first_to_parse] - '0'; + for (number_end = client->first_to_parse + 1; + number_end < s_strlen(client->unparsed); + number_end++) + { + if (client->unparsed.string[number_end] >= '0' + && client->unparsed.string[number_end] <= '9') + { + len = 10 * len + client->unparsed.string[number_end] - '0'; + } + else + { + /* The end of the number was reached. */ + break; + } + } + + if (number_end == s_strlen(client->unparsed)) + longjmp(parse_env, ISC_MSG_INCOMPLETE); + + if (client->unparsed.string[number_end] == 'H') + { + /* We are entering a string. Use num0 to store the + lenght of the string to skip. */ + client->num0 = len; + client->first_to_parse = number_end + 1; + client->fnc_parse_pos = 2; + } + else + { + /* We have just skipped past a number that was not the + start of a string. */ + client->first_to_parse = number_end; + client->fnc_parse_pos = 0; + } + break; + case 2: /* Skipping a string. */ + if (client->num0 == 0) + { + /* The entire string has been skipped. */ + client->fnc_parse_pos = 0; + break; + } + len = s_strlen(client->unparsed) - client->first_to_parse; + if (client->num0 <= len) + { + /* The entire string is present. Skip it. */ + client->first_to_parse += client->num0; + client->fnc_parse_pos = 0; + break; + } + else + { + /* Skip as much of the string as possible. */ + client->num0 -= len; + client->first_to_parse = s_strlen(client->unparsed); + longjmp(parse_env, ISC_MSG_INCOMPLETE); + } + abort(); + default: + abort(); + } + } +} diff --git a/src/server/prot-a-parse.h b/src/server/prot-a-parse.h index ab0ac430dd810e0f780fca20089ef5e8b64dd2e1..a12ef466cbdfac6ad504fdb43b166b90e37f8f6f 100644 --- a/src/server/prot-a-parse.h +++ b/src/server/prot-a-parse.h @@ -1,5 +1,5 @@ /* - * $Id: prot-a-parse.h,v 0.11 1996/07/26 00:39:50 ceder Exp $ + * $Id: prot-a-parse.h,v 0.12 1996/08/01 18:32:05 ceder Exp $ * Copyright (C) 1991, 1992, 1994, 1995 Lysator Academic Computer Association. * * This file is part of the LysKOM server. @@ -23,7 +23,7 @@ * Please mail bug reports to bug-lyskom@lysator.liu.se. */ /* - * $Id: prot-a-parse.h,v 0.11 1996/07/26 00:39:50 ceder Exp $ + * $Id: prot-a-parse.h,v 0.12 1996/08/01 18:32:05 ceder Exp $ * */ extern long @@ -59,3 +59,6 @@ prot_a_parse_time_date(Connection *client, extern void prot_a_parse_info(Connection *client, Info *info); + +extern void +prot_a_hunt_nl(Connection *client);