source: filezilla/trunk/fuentes/src/putty/misc.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 2 years ago

Update new version: 3.15.02

File size: 6.2 KB
Line 
1/*
2 * Header for misc.c.
3 */
4
5#ifndef PUTTY_MISC_H
6#define PUTTY_MISC_H
7
8#include "puttymem.h"
9
10#include <stdio.h>                     /* for FILE * */
11#include <stdarg.h>                    /* for va_list */
12#include <time.h>                      /* for struct tm */
13
14#ifndef FALSE
15#define FALSE 0
16#endif
17#ifndef TRUE
18#define TRUE 1
19#endif
20
21typedef struct Filename Filename;
22typedef struct FontSpec FontSpec;
23
24unsigned long parse_blocksize(const char *bs);
25char ctrlparse(char *s, char **next);
26
27size_t host_strcspn(const char *s, const char *set);
28char *host_strchr(const char *s, int c);
29char *host_strrchr(const char *s, int c);
30char *host_strduptrim(const char *s);
31
32char *dupstr(const char *s);
33char *dupcat(const char *s1, ...);
34char *dupprintf(const char *fmt, ...)
35#ifdef __GNUC__
36    __attribute__ ((format (printf, 1, 2)))
37#endif
38    ;
39char *dupvprintf(const char *fmt, va_list ap);
40void burnstr(char *string);
41
42/* String-to-Unicode converters that auto-allocate the destination and
43 * work around the rather deficient interface of mb_to_wc.
44 *
45 * These actually live in miscucs.c, not misc.c (the distinction being
46 * that the former is only linked into tools that also have the main
47 * Unicode support). */
48wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len);
49wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string);
50
51int toint(unsigned);
52
53char *fgetline(FILE *fp);
54char *chomp(char *str);
55int strstartswith(const char *s, const char *t);
56int strendswith(const char *s, const char *t);
57
58void base64_encode_atom(const unsigned char *data, int n, char *out);
59int base64_decode_atom(const char *atom, unsigned char *out);
60
61struct bufchain_granule;
62typedef struct bufchain_tag {
63    struct bufchain_granule *head, *tail;
64    int buffersize;                    /* current amount of buffered data */
65} bufchain;
66
67void bufchain_init(bufchain *ch);
68void bufchain_clear(bufchain *ch);
69int bufchain_size(bufchain *ch);
70void bufchain_add(bufchain *ch, const void *data, int len);
71void bufchain_prefix(bufchain *ch, void **data, int *len);
72void bufchain_consume(bufchain *ch, int len);
73void bufchain_fetch(bufchain *ch, void *data, int len);
74
75int validate_manual_hostkey(char *key);
76
77struct tm ltime(void);
78
79/* Wipe sensitive data out of memory that's about to be freed. Simpler
80 * than memset because we don't need the fill char parameter; also
81 * attempts (by fiddly use of volatile) to inhibit the compiler from
82 * over-cleverly trying to optimise the memset away because it knows
83 * the variable is going out of scope. */
84void smemclr(void *b, size_t len);
85
86/* Compare two fixed-length chunks of memory for equality, without
87 * data-dependent control flow (so an attacker with a very accurate
88 * stopwatch can't try to guess where the first mismatching byte was).
89 * Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at
90 * by the 'eq' in the name. */
91int smemeq(const void *av, const void *bv, size_t len);
92
93/* Extracts an SSH-marshalled string from the start of *data. If
94 * successful (*datalen is not too small), advances data/datalen past
95 * the string and returns a pointer to the string itself and its
96 * length in *stringlen. Otherwise does nothing and returns NULL.
97 *
98 * Like strchr, this function can discard const from its parameter.
99 * Treat it as if it was a family of two functions, one returning a
100 * non-const string given a non-const pointer, and one taking and
101 * returning const. */
102void *get_ssh_string(int *datalen, const void **data, int *stringlen);
103/* Extracts an SSH uint32, similarly. Returns TRUE on success, and
104 * leaves the extracted value in *ret. */
105int get_ssh_uint32(int *datalen, const void **data, unsigned *ret);
106/* Given a not-necessarily-zero-terminated string in (length,data)
107 * form, check if it equals an ordinary C zero-terminated string. */
108int match_ssh_id(int stringlen, const void *string, const char *id);
109
110/*
111 * Debugging functions.
112 *
113 * Output goes to debug.log
114 *
115 * debug(()) (note the double brackets) is like printf().
116 *
117 * dmemdump() and dmemdumpl() both do memory dumps.  The difference
118 * is that dmemdumpl() is more suited for when the memory address is
119 * important (say because you'll be recording pointer values later
120 * on).  dmemdump() is more concise.
121 */
122
123#ifdef DEBUG
124void debug_printf(const char *fmt, ...);
125void debug_memdump(const void *buf, int len, int L);
126#define debug(x) (debug_printf x)
127#define dmemdump(buf,len) debug_memdump (buf, len, 0);
128#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
129#else
130#define debug(x)
131#define dmemdump(buf,len)
132#define dmemdumpl(buf,len)
133#endif
134
135#ifndef lenof
136#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
137#endif
138
139#ifndef min
140#define min(x,y) ( (x) < (y) ? (x) : (y) )
141#endif
142#ifndef max
143#define max(x,y) ( (x) > (y) ? (x) : (y) )
144#endif
145
146#define GET_32BIT_LSB_FIRST(cp) \
147  (((unsigned long)(unsigned char)(cp)[0]) | \
148  ((unsigned long)(unsigned char)(cp)[1] << 8) | \
149  ((unsigned long)(unsigned char)(cp)[2] << 16) | \
150  ((unsigned long)(unsigned char)(cp)[3] << 24))
151
152#define PUT_32BIT_LSB_FIRST(cp, value) ( \
153  (cp)[0] = (unsigned char)(value), \
154  (cp)[1] = (unsigned char)((value) >> 8), \
155  (cp)[2] = (unsigned char)((value) >> 16), \
156  (cp)[3] = (unsigned char)((value) >> 24) )
157
158#define GET_16BIT_LSB_FIRST(cp) \
159  (((unsigned long)(unsigned char)(cp)[0]) | \
160  ((unsigned long)(unsigned char)(cp)[1] << 8))
161
162#define PUT_16BIT_LSB_FIRST(cp, value) ( \
163  (cp)[0] = (unsigned char)(value), \
164  (cp)[1] = (unsigned char)((value) >> 8) )
165
166#define GET_32BIT_MSB_FIRST(cp) \
167  (((unsigned long)(unsigned char)(cp)[0] << 24) | \
168  ((unsigned long)(unsigned char)(cp)[1] << 16) | \
169  ((unsigned long)(unsigned char)(cp)[2] << 8) | \
170  ((unsigned long)(unsigned char)(cp)[3]))
171
172#define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
173
174#define PUT_32BIT_MSB_FIRST(cp, value) ( \
175  (cp)[0] = (unsigned char)((value) >> 24), \
176  (cp)[1] = (unsigned char)((value) >> 16), \
177  (cp)[2] = (unsigned char)((value) >> 8), \
178  (cp)[3] = (unsigned char)(value) )
179
180#define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
181
182#define GET_16BIT_MSB_FIRST(cp) \
183  (((unsigned long)(unsigned char)(cp)[0] << 8) | \
184  ((unsigned long)(unsigned char)(cp)[1]))
185
186#define PUT_16BIT_MSB_FIRST(cp, value) ( \
187  (cp)[0] = (unsigned char)((value) >> 8), \
188  (cp)[1] = (unsigned char)(value) )
189
190#endif
Note: See TracBrowser for help on using the repository browser.