Commit 39c876d0 authored by Niels Möller's avatar Niels Möller

* src/sexp_parser.c (sexp_parse_transport): New function.

(string_to_sexp): Added style argument. Updated all callers.

Rev: src/lsh.c:1.116
Rev: src/sexp.h:1.28
Rev: src/sexp_parser.c:1.17
parent 42f00867
......@@ -403,7 +403,7 @@ do_lsh_lookup(struct lookup_verifier *c,
}
case ATOM_SPKI:
{
struct sexp *e = string_to_sexp(key, 0);
struct sexp *e = string_to_sexp(SEXP_CANONICAL, key, 0);
if (!e)
{
werror("do_lsh_lookup: Invalid spki s-expression.\n");
......
......@@ -199,7 +199,10 @@ struct sexp *
sexp_parse_canonical(struct simple_buffer *buffer);
struct sexp *
string_to_sexp(struct lsh_string *src, int free);
sexp_parse_transport(struct simple_buffer *buffer);
struct sexp *
string_to_sexp(int style, struct lsh_string *src, int free);
/* Streamed parser */
......
......@@ -221,15 +221,70 @@ sexp_parse_canonical(struct simple_buffer *buffer)
}
struct sexp *
string_to_sexp(struct lsh_string *src, int free)
sexp_parse_transport(struct simple_buffer *buffer)
{
while (LEFT && (sexp_char_classes[*HERE] & CHAR_space))
ADVANCE(1);
if (!LEFT)
{
werror("sexp: Unexpected EOF.\n");
return NULL;
}
if (*HERE != '{')
return sexp_parse_canonical(buffer);
else
{
UINT32 length;
ADVANCE(1); /* Skip '{', and search for '}'. */
for (length = 0; length < LEFT; length++)
if (HERE[length] == '}')
{
struct lsh_string *canonical = decode_base64(length, HERE);
struct simple_buffer inner;
struct sexp *expr;
if (!canonical)
{
werror("sexp: Invalid transport encoding.\n");
return NULL;
}
simple_buffer_init(&inner, canonical->length, canonical->data);
expr = sexp_parse_canonical(&inner);
lsh_string_free(canonical);
ADVANCE(length + 1);
return expr;
}
werror("sexp: Missing } in transport encoding.\n");
return NULL;
}
}
struct sexp *
string_to_sexp(int style, struct lsh_string *src, int free)
{
struct simple_buffer buffer;
struct sexp *e = NULL;;
simple_buffer_init(&buffer, src->length, src->data);
if ( (e = sexp_parse_canonical(&buffer))
&& parse_eod(&buffer))
switch (style)
{
case SEXP_CANONICAL:
e = sexp_parse_canonical(&buffer);
break;
case SEXP_TRANSPORT:
e = sexp_parse_transport(&buffer);
break;
default:
fatal("string_to_sexp: Unsupported style.");
}
if (e && parse_eod(&buffer))
{
if (free)
lsh_string_free(src);
......
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