prot-a-parse.c 18.3 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: prot-a-parse.c,v 0.32 1998/07/08 13:41:55 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25 26 27 28 29 30
/*
 * prot-a-parse.c - parse protocol-A messages.
 *
 * BUG: Not all functions are used, I think. /ceder
 */

31 32
static const char *
rcsid = "$Id: prot-a-parse.c,v 0.32 1998/07/08 13:41:55 ceder Exp $";
33 34
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
35

36
#include <assert.h>
Per Cederqvist's avatar
Per Cederqvist committed
37
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
38
#include <setjmp.h>
Per Cederqvist's avatar
Per Cederqvist committed
39
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
40
#include <sys/types.h>
41
#include <sys/socket.h>
42 43 44
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
45 46 47
#ifdef HAVE_STDLIB_H
#  include <stdlib.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
48

49
#include "debug.h"
Per Cederqvist's avatar
Per Cederqvist committed
50
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
51
#include "kom-types.h"
52
#include "server/smalloc.h"
Per Cederqvist's avatar
Per Cederqvist committed
53
#include "com.h"
54
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
55 56 57 58
#include "connections.h"
#include "prot-a-parse.h"
#include "isc-parse.h"
#include "config.h"
59 60
#include "isc-interface.h"
#include "mux.h"
Per Cederqvist's avatar
Per Cederqvist committed
61
#include "log.h"
Per Cederqvist's avatar
Per Cederqvist committed
62
#include "minmax.h"
63
#include "param.h"
64

65 66
BUGDECL;

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/*
 * Return next token from the input stream. Note that the String returned
 * by this call points into data that might be freed by the next call to
 * get_token or any function which reads from the stream.
 */

static String
prot_a_get_token(Connection *client)
{
    String result;
    String_size old_first;

    old_first = client->first_to_parse;
    
    result = s_strtok(client->unparsed, &client->first_to_parse,
		      s_fcrea_str(WHITESPACE));

    /* Check that there was at least one trailing blank. */
    
    if ( client->first_to_parse >= s_strlen(client->unparsed) )
    {
88 89 90 91 92 93
        if (client->first_to_parse - old_first > 1000)
	{
	    mux_printf(client, "%%%%Insane token length.\n");
	    mux_flush(client);
	    longjmp(parse_env, ISC_LOGOUT);
	}
94 95 96 97 98 99 100 101
	client->first_to_parse = old_first;
	longjmp(parse_env, ISC_MSG_INCOMPLETE);
    }

    return result;
}


Per Cederqvist's avatar
Per Cederqvist committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
long
prot_a_parse_long(Connection *client)
{
    String	token;
    String_size end;
    long	res;

    token = prot_a_get_token(client);
    res = s_strtol(token, &end, PROTOCOL_NUMBER_BASE);
    if (end != s_strlen(token))
	longjmp(parse_env, ISC_PROTOCOL_ERR);
    
    return res;
}

117 118 119

void
prot_a_parse_num_list(Connection *client,
120 121
                      Number_list *res,
		      int maxlen)
122
{
123
    static unsigned long err_cnt = 0;
124

125
    switch (client->array_parse_pos)
126
    {
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    case 0:			/* The array size. */

	/* This could just as well have been an assertion. */
	if ((res->length != 0 || res->data != NULL) && err_cnt++ < 20)
	{
	    log("WNG: prot_a_parse_num_list(): len = %lu data = %lu\n",
		(unsigned long)res->length, (unsigned long)res->data);
	    res->length = 0;
	    res->data = NULL;
	    if (err_cnt == 20)
		log("The above warning is now turned off.");
	}

	res->length = prot_a_parse_long(client);
	if (res->length < 0)
	{
	    mux_printf(client, "%%%%Insane array size.\n");
	    mux_flush(client);
	    longjmp(parse_env, ISC_LOGOUT);
	}

	client->array_parse_pos = 1;
	/* Fall through */
    case 1:			/* The opening curly brace. */
	if ( parse_nonwhite_char(client) != '{' )
	    longjmp(parse_env, ISC_PROTOCOL_ERR);

	if (res->length <= maxlen)
	    res->data   = smalloc(sizeof(*res->data) * res->length);
	else
	{
	    assert(res->data == NULL);
	}

	client->array_parse_index = 0;
        client->array_parse_pos = 2;
	/* Fall through */
    case 2:			/* The elements in the array. */
	while (client->array_parse_index < res->length)
	{
	    long tmp = prot_a_parse_long(client);
	    if (res->data != NULL)
		res->data[client->array_parse_index] = tmp;
	    ++client->array_parse_index;
	}
	client->array_parse_pos = 3;
	/* Fall through */
    case 3:			/* Closing brace. */
	if ( parse_nonwhite_char(client) != '}' )
	    longjmp(parse_env, ISC_PROTOCOL_ERR);
    default:
	client->array_parse_pos = 0;
179 180 181
    }
}

Per Cederqvist's avatar
Per Cederqvist committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
void
prot_a_parse_priv_bits(Connection *client,
		       Priv_bits      *res)
{
    String token;

    token = prot_a_get_token(client);

    if ( s_strlen(token) != 16 )
	longjmp(parse_env, ISC_PROTOCOL_ERR);
    
    res->wheel = token.string[ 0 ] != '0';
    res->admin = token.string[ 1 ] != '0';
    res->statistic = token.string[ 2 ] != '0';
    res->create_pers = token.string[ 3 ] != '0';
    res->create_conf = token.string[ 4 ] != '0';
    res->change_name = token.string[ 5 ] != '0';
199
    res->extern_gw = token.string[ 6 ] != '0';
Per Cederqvist's avatar
Per Cederqvist committed
200 201 202 203 204 205 206 207 208 209 210
    res->flg8 = token.string[ 7 ] != '0';
    res->flg9 = token.string[ 8 ] != '0';
    res->flg10 = token.string[ 9 ] != '0';
    res->flg11 = token.string[ 10 ] != '0';
    res->flg12 = token.string[ 11 ] != '0';
    res->flg13 = token.string[ 12 ] != '0';
    res->flg14 = token.string[ 13 ] != '0';
    res->flg15 = token.string[ 14 ] != '0';
    res->flg16 = token.string[ 15 ] != '0';
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
void
prot_a_parse_membership_type(Connection *client,
                             Membership_type *res)
{
    String token;

    token = prot_a_get_token(client);
    if (s_strlen(token) != 8)
	longjmp(parse_env, ISC_PROTOCOL_ERR);
  
    res->invitation = token.string[ 0 ] != '0';
    res->passive    = token.string[ 1 ] != '0';
    res->secret     = token.string[ 2 ] != '0';
    res->reserved1  = token.string[ 3 ] != '0';
    res->reserved2  = token.string[ 4 ] != '0';
    res->reserved3  = token.string[ 5 ] != '0';
    res->reserved4  = token.string[ 6 ] != '0';
    res->reserved5  = token.string[ 7 ] != '0';
}

Per Cederqvist's avatar
Per Cederqvist committed
231 232 233 234 235 236 237 238
void
prot_a_parse_conf_type(Connection *client,
		Conf_type      *res)
{
    String token;

    token = prot_a_get_token(client);
    
239 240
    if ( s_strlen(token) != 4 &&
	 s_strlen(token) != 8)
Per Cederqvist's avatar
Per Cederqvist committed
241 242 243 244 245 246
	longjmp(parse_env, ISC_PROTOCOL_ERR);
  
    res->rd_prot = token.string[ 0 ] != '0';
    res->original = token.string[ 1 ] != '0';
    res->secret = token.string[ 2 ] != '0';
    res->letter_box = token.string[ 3 ] != '0';
247 248
    if (s_strlen(token) != 8)
    {
249
      res->allow_anon = 0;
250 251 252 253 254 255
      res->reserved1 = 0;
      res->reserved2 = 0;
      res->reserved3 = 0;
    }
    else
    {
256
      res->allow_anon = token.string[ 4 ] != '0';
257 258 259 260
      res->reserved1 = token.string[ 5 ] != '0';
      res->reserved2 = token.string[ 6 ] != '0';
      res->reserved3 = token.string[ 7 ] != '0';
    }
Per Cederqvist's avatar
Per Cederqvist committed
261 262 263 264 265
}

/*
 * Parse a string. At most 'maxlen' characters are allowed. If the
 * client sends a longer string only the first 'maxlen+1' characters
Per Cederqvist's avatar
Per Cederqvist committed
266 267 268 269
 * are read. Any remaining characters are discarded.
 */
/*
 * +++ This needs cleaning up. See comments in and above mux_parse_string.
Per Cederqvist's avatar
Per Cederqvist committed
270 271 272
 */
void
prot_a_parse_string(Connection  *client,
Per Cederqvist's avatar
Per Cederqvist committed
273 274
		    String	*result,
		    int		 maxlen)
Per Cederqvist's avatar
Per Cederqvist committed
275 276 277 278 279
{
    String_size hptr;		/* Pointer to 'H' */
    String_size client_len;	/* The len the client is sending. */
    String_size truncated_len;	/* How much the server will receive. */
    String_size to_skip;
Per Cederqvist's avatar
Per Cederqvist committed
280
    static unsigned long err_cnt = 0;
Per Cederqvist's avatar
Per Cederqvist committed
281 282 283 284

    switch ( client->string_parse_pos )
    {
    case 0:
285 286
	if ( (result->len != 0 || result->string != NULL) && err_cnt++ < 20 )
	{
Per Cederqvist's avatar
Per Cederqvist committed
287 288 289 290
	    log ("%s == %lu, result->string == %lu. %s\n",
		 "prot_a_parse_string(): result->len",
		 (unsigned long)result->len, (unsigned long)result->string,
		 "This memory will not be free()'d.");
291 292 293 294 295
	    *result = EMPTY_STRING;
	    if ( err_cnt == 20 )
		log("Won't log the above warning no more.");
	}

Per Cederqvist's avatar
Per Cederqvist committed
296
	/* Get number and discard trailing 'H' */
Per Cederqvist's avatar
Per Cederqvist committed
297 298 299 300
	client_len = s_strtol(s_fsubstr(client->unparsed,
					client->first_to_parse,
					END_OF_STRING),
			      &hptr, PROTOCOL_NUMBER_BASE);
Per Cederqvist's avatar
Per Cederqvist committed
301 302 303 304 305 306 307 308

	if ( hptr == -1
	    || client->first_to_parse + hptr
	    >= s_strlen(client->unparsed) )
	{
	    longjmp(parse_env, ISC_MSG_INCOMPLETE);
	}
	
309 310 311 312 313 314 315 316
	if (client_len < 0)
	{
	    mux_printf(client, "%%%%Insane string length.\n");
	    mux_flush(client);
	    BUG(("%%%%Insane string length.\n"));
	    longjmp(parse_env, ISC_LOGOUT);
	}
	
Per Cederqvist's avatar
Per Cederqvist committed
317 318 319 320 321 322 323 324 325 326 327 328 329
	/* Check that
	      a) there is a trailing H
	      b) there was at least one digit before the H */

	if ( client->unparsed.string[ client->first_to_parse
					  + hptr ] != 'H'
	    || hptr <= 0 )
	{
	    longjmp(parse_env, ISC_PROTOCOL_ERR);
	}

	client->first_to_parse += 1 + hptr;
	client->string_parse_pos = 1;
330
	result->len = client_len; /* +++ Transfer */
Per Cederqvist's avatar
Per Cederqvist committed
331 332
	/* Fall through */
    case 1:
333
	client_len = result->len;
Per Cederqvist's avatar
Per Cederqvist committed
334 335 336
	/* Check that the entire string is transmitted. */
	/* (Don't care about the trailing part that will be skipped if the
	 *  string is longer than maxlen) */
Per Cederqvist's avatar
Per Cederqvist committed
337
	truncated_len = min(maxlen + 1, client_len);
Per Cederqvist's avatar
Per Cederqvist committed
338 339 340 341 342 343 344
	
	if ( client->first_to_parse + truncated_len
	    > s_strlen(client->unparsed) )
	{
	    longjmp(parse_env, ISC_MSG_INCOMPLETE);
	}

345
	*result = EMPTY_STRING;
Per Cederqvist's avatar
Per Cederqvist committed
346 347 348 349 350

	s_mem_crea_str(result,
		       client->unparsed.string + client->first_to_parse,
		       truncated_len);
	result->len = client_len; /* Ugly! +++ */
Per Cederqvist's avatar
Per Cederqvist committed
351 352 353 354 355 356 357 358

	client->first_to_parse += truncated_len;
	client->string_parse_pos = 2;
	/* Fall through */
    case 2:
	/* Was the string too long? If so, skip the truncated data. */

	client_len = result->len;
359
	truncated_len = min(maxlen+1, client_len);
Per Cederqvist's avatar
Per Cederqvist committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
	
	if ( client_len > truncated_len )
	{
	    to_skip = min(client_len - truncated_len,
			   client->unparsed.len - client->first_to_parse);
	    client_len -= to_skip;
	    client->first_to_parse += to_skip;
	}

	result->len = client_len;
	
	if ( client_len > truncated_len )
	    longjmp(parse_env, ISC_MSG_INCOMPLETE);
	/* Fall through */
    default:
	client->string_parse_pos = 0;
    }
}

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
extern void
prot_a_parse_aux_item_flags(Connection *client,
                            Aux_item_flags *res)
{
    String token;

    token = prot_a_get_token(client);
    
    if ( s_strlen(token) != 8 )
	longjmp(parse_env, ISC_PROTOCOL_ERR);
  
    res->deleted    = token.string[ 0 ] != '0';
    res->inherit    = token.string[ 1 ] != '0';
    res->secret     = token.string[ 2 ] != '0';
    res->hide_creator = token.string[ 3 ] != '0';
394
    res->dont_garb  = token.string[ 4 ] != '0';
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
    res->reserved3  = token.string[ 5 ] != '0';
    res->reserved4  = token.string[ 6 ] != '0';
    res->reserved5  = token.string[ 7 ] != '0';
}


extern void
prot_a_parse_aux_item(Connection *client,
                      Aux_item *result)
{
    switch ( client->struct_parse_pos )
    {
    case 0:
        result->aux_no = prot_a_parse_long(client);
        client->struct_parse_pos = 1;
    case 1:
        result->tag = prot_a_parse_long(client);
        client->struct_parse_pos = 2;
    case 2:
        prot_a_parse_aux_item_flags(client, &result->flags);
        client->struct_parse_pos = 3;
    case 3:
        result->inherit_limit = prot_a_parse_long(client);
        client->struct_parse_pos = 4;
    case 4:
        prot_a_parse_string(client,
                            &(result->data),
                            param.text_len);
    default:
        client->struct_parse_pos = 0;
    }
}

extern void
prot_a_parse_aux_item_list(Connection *client,
                           Aux_item_list *result,
                           unsigned long maxlen)
{
    int i;

    switch (client->array_parse_pos)
    {
    case 0:
	result->length = prot_a_parse_long(client);
	client->array_parse_pos = 1;
    case 1:
	if ( parse_nonwhite_char(client) != '{' )
	    longjmp(parse_env, ISC_PROTOCOL_ERR);
	if ( result->length > maxlen )
	    longjmp(parse_env, ISC_PROTOCOL_ERR);

	result->items = smalloc(result->length * sizeof(Aux_item));
        for (i = 0; i < result->length; i++)
        {
            result->items[i].data = EMPTY_STRING;
        }
	client->array_parse_index = 0;
	client->array_parse_pos = 2;
    case 2:
	while( client->array_parse_index < result->length )
	{
	    prot_a_parse_aux_item(client,
                                  &result->items[client->array_parse_index]);
	    client->array_parse_index += 1;
	}
	client->array_parse_pos = 3;
    case 3:
	if ( parse_nonwhite_char(client) != '}' )
	    longjmp(parse_env, ISC_PROTOCOL_ERR);
    default:
	client->array_parse_pos = 0;
    }
}
                               
Per Cederqvist's avatar
Per Cederqvist committed
469 470 471 472 473 474 475 476

extern void
prot_a_parse_misc_info(Connection *client,
		       Misc_info      *result)
{
    switch ( client->struct_parse_pos )
    {
    case 0:
477
	result->type = (Info_type)prot_a_parse_long(client);
Per Cederqvist's avatar
Per Cederqvist committed
478 479 480 481 482 483 484 485 486 487 488 489 490
	client->struct_parse_pos = 1;
	/* Fall through */
    case 1:
	switch( result->type )
	{
	case recpt:
	    result->datum.recipient = prot_a_parse_long(client);
	    break;

	case cc_recpt:
	    result->datum.cc_recipient = prot_a_parse_long(client);
	    break;
	    
491 492 493 494
	case bcc_recpt:
	    result->datum.bcc_recipient = prot_a_parse_long(client);
	    break;
	    
Per Cederqvist's avatar
Per Cederqvist committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
	case loc_no:
	    result->datum.local_no = prot_a_parse_long(client);
	    break;
	    
	case comm_to:
	    result->datum.comment_to = prot_a_parse_long(client);
	    break;
	    
	case footn_to:
	    result->datum.footnote_to = prot_a_parse_long(client);
	    break;

	case comm_in:
	case footn_in:
	case rec_time:
	case sent_by:
	case sent_at:
	    /* Fall through */
	    
#ifndef COMPILE_CHECKS
	default:
#endif
	    longjmp(parse_env, ISC_PROTOCOL_ERR);
	}
    default:
	client->struct_parse_pos = 0;
    }
}


Per Cederqvist's avatar
Per Cederqvist committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
void
prot_a_parse_time_date(Connection *client,
		       struct tm  *result)
{
    /* A time never occur inside a string, and a string never occur
       inside a time. Thus I use string_parse_pos here instead of
       inventing a new variable. Lacgen will allocate variables as
       needed... */

    switch( client->string_parse_pos )
    {
    case 0:
	result->tm_sec = prot_a_parse_long(client);
	client->string_parse_pos = 1;
	/* Fall through */
    case 1:
	result->tm_min = prot_a_parse_long(client);
	client->string_parse_pos = 2;
	/* Fall through */
    case 2:
	result->tm_hour = prot_a_parse_long(client);
	client->string_parse_pos = 3;
	/* Fall through */
    case 3:
	result->tm_mday = prot_a_parse_long(client);
	client->string_parse_pos = 4;
	/* Fall through */
    case 4:
	result->tm_mon = prot_a_parse_long(client);
	client->string_parse_pos = 5;
	/* Fall through */
    case 5:
	result->tm_year = prot_a_parse_long(client);
	client->string_parse_pos = 6;
	/* Fall through */
    case 6:
	result->tm_wday = prot_a_parse_long(client);
	client->string_parse_pos = 7;
	/* Fall through */
    case 7:
	result->tm_yday = prot_a_parse_long(client);
	client->string_parse_pos = 8;
	/* Fall through */
    case 8:
	result->tm_isdst = prot_a_parse_long(client);
	/* Fall through */
    default:
	client->string_parse_pos = 0;
    }
}

576 577 578 579 580


void prot_a_parse_info(Connection *client,
                       Info *result)
{
581
    switch( client->struct_parse_pos )
582 583 584
    {
    case 0:
        result->version = prot_a_parse_long(client);
585
        client->struct_parse_pos = 1;
586 587 588
        /* Fall through */
    case 1:
        result->conf_pres_conf = prot_a_parse_long(client);
589
        client->struct_parse_pos = 2;
590 591 592
        /* Fall through */
    case 2:
        result->pers_pres_conf = prot_a_parse_long(client);
593
        client->struct_parse_pos = 3;
594 595 596
        /* Fall through */
    case 3:
        result->motd_conf = prot_a_parse_long(client);
597
        client->struct_parse_pos = 4;
598 599 600
        /* Fall through */
    case 4:
        result->kom_news_conf = prot_a_parse_long(client);
601
        client->struct_parse_pos = 5;
602 603 604 605 606
        /* Fall through */
    case 5:
        result->motd_of_lyskom = prot_a_parse_long(client);
        /* Fall through */
    default:
607
        client->struct_parse_pos = 0;
608 609
    }
}
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715

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();
	}
    }
}