format.h 2.41 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
/* format.h
 *
 * Create a packet from a format string and arguments.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * $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., 675 Mass Ave, Cambridge, MA 02139, USA.
Niels Möller's avatar
Niels Möller committed
24
25
26
27
28
29
30
 */

#ifndef LSH_FORMAT_H_INCLUDED
#define LSH_FORMAT_H_INCLUDED

#include <stdarg.h>

Niels Möller's avatar
Niels Möller committed
31
32
33
#include "atoms.h"
#include "bignum.h"

Niels Möller's avatar
Niels Möller committed
34
35
36
37
38
39
40
41
42
43
/* Format strings can contain the following %-specifications:
 *
 * %%  Insert a %-sign
 *
 * %c  Insert an 8-bit character
 *
 * %i  Insert an 32-bit integer, in network byte order
 *
 * %s  Insert a string, given by a length and a pointer.
 *
Niels Möller's avatar
Niels Möller committed
44
45
 * %S  Insert a string, given as a struct lsh_string pointer.
 *
Niels Möller's avatar
Niels Möller committed
46
47
48
 * %z  Insert a string, using a null-terminated argument.
 *
 * %r  Reserves space in the string, and stores a pointer to this space
49
 *     into the given UINT8 ** argument.
Niels Möller's avatar
Niels Möller committed
50
 *
Niels Möller's avatar
Niels Möller committed
51
52
53
 * %a  Insert a string containing one atom.
 *
 * %A  Insert a string containing a list of atoms. The corresponding
54
 *     argument sublist should be a int* pointing to a list of atoms,
55
 *     terminated with -1. Zero elements are allowed and ignored.
56
57
58
 *
 * %X  Insert a string containing a list of atoms. The corresponding
 *     argument sublist should be terminated with a zero. (Not used)
Niels Möller's avatar
Niels Möller committed
59
60
61
 *
 * %n  Insert a string containing a bignum.
 *
62
 * There are two valid modifiers:
Niels Möller's avatar
Niels Möller committed
63
64
 *
 * "l" (as in literal). It is applicable to the s, a, A, n and r
65
66
 * specifiers, and outputs strings *without* a length field.
 *
Niels Möller's avatar
Niels Möller committed
67
 * "f" (as in free). Frees the input string after it has been copied.
68
 * Applicable to %S only. */
Niels Möller's avatar
Niels Möller committed
69
70

UINT32 ssh_vformat_length(char *format, va_list args);
71
UINT32 ssh_vformat(char *format, UINT8 *buffer, va_list args);
Niels Möller's avatar
Niels Möller committed
72
struct lsh_string *ssh_format(char *format, ...);
Niels Möller's avatar
Niels Möller committed
73

Niels Möller's avatar
Niels Möller committed
74
75
76
/* Short cut */
#define lsh_string_dup(s) (ssh_format("%lS", (s)))

Niels Möller's avatar
Niels Möller committed
77
#endif /* LSH_FORMAT_H_INCLUDED */