Commit e88a1c03 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(prot_a_parse_num_list): New argument: maxlen. Rewritten.

parent 0153ade7
/*
* $Id: prot-a-parse.c,v 0.23 1996/06/14 15:53:40 byers Exp $
* $Id: prot-a-parse.c,v 0.24 1996/07/26 00:39:42 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -28,10 +28,11 @@
* BUG: Not all functions are used, I think. /ceder
*/
static char *rcsid = "$Id: prot-a-parse.c,v 0.23 1996/06/14 15:53:40 byers Exp $";
static char *rcsid = "$Id: prot-a-parse.c,v 0.24 1996/07/26 00:39:42 ceder Exp $";
#include "rcs.h"
USE(rcsid);
#include <assert.h>
#include <stdio.h>
#include <setjmp.h>
#include <time.h>
......@@ -49,6 +50,7 @@ USE(rcsid);
#include "kom-types.h"
#include "server/smalloc.h"
#include "com.h"
#include "async.h"
#include "connections.h"
#include "prot-a-parse.h"
#include "isc-parse.h"
......@@ -107,36 +109,66 @@ prot_a_parse_long(Connection *client)
void
prot_a_parse_num_list(Connection *client,
Number_list *res)
Number_list *res,
int maxlen)
{
String token;
token = prot_a_get_token(client);
static unsigned long err_cnt = 0;
if (client->array_parse_pos == 0)
{
res->length = atoi(token.string);
res->data = smalloc(sizeof(*res->data) * res->length);
client->array_parse_pos += 1;
}
if (client->array_parse_pos == 1) /* Ignore open-brace token or star */
switch (client->array_parse_pos)
{
token = prot_a_get_token(client); /* Ignore open-brace */
client->array_parse_pos += 1;
}
case 0: /* The array size. */
if (res->length == 0)
return;
while (client->array_parse_pos < res->length + 2)
{
token = prot_a_get_token(client);
res->data[client->array_parse_pos - 2] = atol(token.string);
client->array_parse_pos += 1;
/* 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;
}
token = prot_a_get_token(client); /* Ignore close-brace token */
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment