Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
/* sexp-parse.h - S-expression helper functions
|
2007-05-15 16:10:48 +00:00
|
|
|
* Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc.
|
2003-06-05 07:14:21 +00:00
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of either
|
2003-06-05 07:14:21 +00:00
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
2003-06-05 07:14:21 +00:00
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - 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.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
2003-06-05 07:14:21 +00:00
|
|
|
* 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
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-06-05 07:14:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SEXP_PARSE_H
|
|
|
|
#define SEXP_PARSE_H
|
|
|
|
|
2003-12-01 10:53:26 +00:00
|
|
|
#include <gpg-error.h>
|
2003-06-05 07:14:21 +00:00
|
|
|
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/* Return the length of the next S-Exp part and update the pointer to
|
2003-12-01 10:53:26 +00:00
|
|
|
the first data byte. 0 is returned on error */
|
2003-06-05 07:14:21 +00:00
|
|
|
static inline size_t
|
|
|
|
snext (unsigned char const **buf)
|
|
|
|
{
|
|
|
|
const unsigned char *s;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
s = *buf;
|
2003-12-01 10:53:26 +00:00
|
|
|
for (n=0; *s && *s != ':' && (*s >= '0' && *s <= '9'); s++)
|
|
|
|
n = n*10 + (*s - '0');
|
2003-06-05 07:14:21 +00:00
|
|
|
if (!n || *s != ':')
|
|
|
|
return 0; /* we don't allow empty lengths */
|
|
|
|
*buf = s+1;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip over the S-Expression BUF points to and update BUF to point to
|
2016-04-12 14:20:53 +02:00
|
|
|
the character right behind. DEPTH gives the initial number of open
|
2003-06-05 07:14:21 +00:00
|
|
|
lists and may be passed as a positive number to skip over the
|
|
|
|
remainder of an S-Expression if the current position is somewhere
|
|
|
|
in an S-Expression. The function may return an error code if it
|
2007-12-13 15:45:40 +00:00
|
|
|
encounters an impossible condition. */
|
2003-12-01 10:53:26 +00:00
|
|
|
static inline gpg_error_t
|
2003-06-05 07:14:21 +00:00
|
|
|
sskip (unsigned char const **buf, int *depth)
|
|
|
|
{
|
|
|
|
const unsigned char *s = *buf;
|
|
|
|
size_t n;
|
|
|
|
int d = *depth;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
while (d > 0)
|
|
|
|
{
|
|
|
|
if (*s == '(')
|
|
|
|
{
|
|
|
|
d++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else if (*s == ')')
|
|
|
|
{
|
|
|
|
d--;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!d)
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
|
|
|
n = snext (&s);
|
|
|
|
if (!n)
|
2011-02-04 12:57:53 +01:00
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
2003-06-05 07:14:21 +00:00
|
|
|
s += n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buf = s;
|
|
|
|
*depth = d;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check whether the the string at the address BUF points to matches
|
|
|
|
the token. Return true on match and update BUF to point behind the
|
2010-10-01 20:33:53 +00:00
|
|
|
token. Return false and do not update the buffer if it does not
|
2003-12-01 10:53:26 +00:00
|
|
|
match. */
|
2003-06-05 07:14:21 +00:00
|
|
|
static inline int
|
|
|
|
smatch (unsigned char const **buf, size_t buflen, const char *token)
|
|
|
|
{
|
|
|
|
size_t toklen = strlen (token);
|
|
|
|
|
|
|
|
if (buflen != toklen || memcmp (*buf, token, toklen))
|
|
|
|
return 0;
|
|
|
|
*buf += toklen;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-05-15 16:10:48 +00:00
|
|
|
/* Format VALUE for use as the length indicatior of an S-expression.
|
|
|
|
The caller needs to provide a buffer HELP_BUFFER wth a length of
|
|
|
|
HELP_BUFLEN. The return value is a pointer into HELP_BUFFER with
|
|
|
|
the formatted length string. The colon and a trailing nul are
|
|
|
|
appended. HELP_BUFLEN must be at least 3 - a more useful value is
|
|
|
|
15. If LENGTH is not NULL, the LENGTH of the resulting string
|
|
|
|
(excluding the terminating nul) is stored at that address. */
|
|
|
|
static inline char *
|
|
|
|
smklen (char *help_buffer, size_t help_buflen, size_t value, size_t *length)
|
|
|
|
{
|
|
|
|
char *p = help_buffer + help_buflen;
|
|
|
|
|
|
|
|
if (help_buflen >= 3)
|
|
|
|
{
|
|
|
|
*--p = 0;
|
|
|
|
*--p = ':';
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*--p = '0' + (value % 10);
|
|
|
|
value /= 10;
|
|
|
|
}
|
|
|
|
while (value && p > help_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
*length = (help_buffer + help_buflen) - p;
|
|
|
|
return p;
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2007-05-15 16:10:48 +00:00
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
#endif /*SEXP_PARSE_H*/
|