Commit a6e4dca6 authored by Niels Möller's avatar Niels Möller
Browse files

* src/config_parse.y: Deleted file, use a recursive-descent parser

instead.

* src/disconnect.c, src/disconnect.h: Deleted files, code moved to
connection.c.

Rev: src/config_parse.h:1.3(DEAD)
Rev: src/config_parse.y:1.3(DEAD)
Rev: src/disconnect.c:1.23(DEAD)
Rev: src/disconnect.h:1.9(DEAD)
parent cfd156ac
/* config_parse.h
*
* $id$ */
#include "lsh.h"
#include <stdio.h>
enum config_type { RULE_DEFAULT, RULE_NET, RULE_HOST };
#define GABA_DECLARE
#include "config_parse.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name config_pair)
(vars
(next object config_pair)
(name string)
(value string)))
*/
static struct config_pair *
make_config_pair(struct lsh_string *name, struct lsh_string *value);
/* GABA:
(class
(name config_rule)
(vars
(next object config_rule)
(type . "enum config_type")
(tag string)
(config object config_pair)))
*/
static struct config_rule *
make_config_rule(enum config_type type,
struct lsh_string *tag);
struct config_rule *
config_parse(FILE *f);
%{
/* C declarations */
#include "config_parse.h"
#include "string_buffer.h"
#include "xalloc.h"
#include <ctype.h>
#define GABA_DEFINE
#include "config_parse.h.x"
#undef GABA_DEFINE
struct parse_state
{
FILE *f;
struct config_rule *value;
};
#define YYPARSE_PARAM state
#define STATE ((struct parse_state *) state)
static void yyerror(const char *s);
static int
yylex(YYSTYPE *val, void *state);
%}
/* Declarations */
%pure_parser
%union {
struct lsh_string *string;
struct config_pair *pair;
struct config_rule *rule;
}
%token HOST
%token NET
%token DEFAULT
%token NL
%token <string> ID
%type <pair> pair config
%type <rule> rule rules type
%%
/* Grammar */
start: rules { STATE->value = $1; } ;
rules: /* Empty */ { $$ = NULL; }
| rules rule { $2->next = $1; $$ = $1 }
;
rule: type '{' config optsemi '}' { $1->config = $3; $$ = $1; } ;
type: HOST ID { $$ = make_config_rule(RULE_HOST, $2) }
| NET ID { $$ = make_config_rule(RULE_NET, $2) }
| DEFAULT { $$ = make_config_rule(RULE_DEFAULT, NULL) }
;
config: /* Empty */ { $$ = NULL; }
| config sep pair { $3->next = $1; $$ = $3; }
;
sep: ';' | NL ;
optsemi: /* Empty */ | ';' ;
pair: ID ID { $$ = make_config_pair($1, $2) };
%%
/* C code */
static struct config_pair *
make_config_pair(struct lsh_string *name, struct lsh_string *value)
{
NEW(config_pair, self);
self->next = NULL;
self->name = name;
self->value = value;
return self;
}
static struct config_rule *
make_config_rule(enum config_type type,
struct lsh_string *tag)
{
NEW(config_rule, self);
self->next = NULL;
self->type = type;
self->tag = tag;
self->config = NULL;
return self;
}
struct config_rule *
config_parse(FILE *f)
{
struct parse_state state;
state->f = f;
return (yyparse(&state) == 0) ? state.value : NULL;
}
static void
skip_line(FILE *f)
{
for (;;)
{
int c = getc(f);
if (c == EOF)
return 0;
else if (c == '\n')
return NL;
}
}
static int
quoted_string(FILE *f, struct lsh_string **val)
{
struct string_buffer buffer;
string_buffer_init(&buffer, 20);
for (;;)
{
int c = getc(f);
switch (c)
{
case EOF:
werror("Parse error: Unexpected EOF in string.\n");
/* What should yylex return in errors? */
fail:
string_buffer_clear(&buffer);
return -1;
case '\n':
werror("Parse error: New line in quoted string.\n");
goto fail;
case '\\':
switch (c = getc(f))
{
case '\\':
string_buffer_putc(&buffer, '\\');
break;
case 'n':
string_buffer_putc(&buffer, '\n');
break;
case 't':
string_buffer_putc(&buffer, '\t');
break;
default:
werror("Parse error: Unknown escape sequence `\\%c'\n",
c);
goto fail;
}
break;
case '"':
*val = string_buffer_final(&buffer, buffer.left);
return STRING;
default:
string_buffer_putc(&buffer, c);
}
}
}
/* Whitespace except '\n'. */
#define WS ' ': case '\t': case '\r': case '\v'
static int
get_word(FILE *f, int c, struct lsh_string **val)
{
struct string_buffer buffer;
struct lsh_string *s;
string_buffer_init(&buffer, 20);
string_buffer_putc(&buffer, c);
for (;;)
{
c = getc(f);
switch (c)
{
case '\n': case '{': case '}': case ';':
ungetc(c, f);
/* Fall through */
case WS:
case EOF:
/* End of word found. Is it magic? */
s = string_buffer_final(&buffer, buffer->left);
switch (s->length)
{
case '3':
if (!memcmp(s->data, "net", 3))
{
lsh_string_free(s);
return NET;
}
break;
case '4':
if (!memcmp(s->data, "host", 4))
{
lsh_string_free(s);
return HOST;
}
break;
case '7':
if (!memcmp(s->data, "default", 7))
{
lsh_string_free(s);
return DEFAULT;
}
break;
}
*val = s;
return STRING;
default:
string_buffer_putc(&buffer, c);
}
}
}
static int
yylex(YYSTYPE *val, void *state)
{
for (;;)
{
int c = getc(STATE->f);
switch (c)
{
case WS:
continue;
case '"':
return quoted_string(STATE->f, &val->string);
case '\n':
return NL;
case '{': case '}': case ';':
return c;
case '#':
return skip_line(STATE->f);
case EOF:
return 0;
default:
return word(STATE->f, c, &val->string);
}
}
}
/* disconnect.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Mller
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#warning disconnect.c is obsolete
#if 0
#include "disconnect.h"
#include "connection.h"
#include "format.h"
#include "parse.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
struct lsh_string *
format_disconnect(int code, const char *msg,
const char *language)
{
return ssh_format("%c%i%z%z",
SSH_MSG_DISCONNECT,
code,
msg, language);
}
static void
do_disconnect(struct packet_handler *closure UNUSED,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct simple_buffer buffer;
unsigned msg_number;
UINT32 reason;
UINT32 length;
const UINT8 *msg;
const UINT8 *language;
UINT32 language_length;
static const struct exception disconnect_exception =
STATIC_EXCEPTION(EXC_FINISH_IO, "Received disconnect message.");
simple_buffer_init(&buffer, packet->length, packet->data);
if (parse_uint8(&buffer, &msg_number)
&& (msg_number == SSH_MSG_DISCONNECT)
&& (parse_uint32(&buffer, &reason))
&& (parse_string(&buffer, &length, &msg))
&& (parse_string(&buffer, &language_length, &language))
&& parse_eod(&buffer))
{
/* FIXME: Display a better message */
werror("Disconnect for reason %i: %ups\n", reason, length, msg);
}
else
werror("Invalid disconnect message!\n");
EXCEPTION_RAISE(connection->e, &disconnect_exception);
}
struct packet_handler disconnect_handler =
{ STATIC_HEADER, do_disconnect };
#endif
/* disconnect.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#warning disconnect.h is obsolete
#ifndef LSH_DISCONNECT_H_INCLUDED
#define LSH_DISCONNECT_H_INCLUDED
#include "lsh_types.h"
struct lsh_string *format_disconnect(int code, const char *msg,
const char *language);
extern struct packet_handler disconnect_handler;
#endif /* LSH_DISCONNECT_H_INCLUDED */
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