Make sure the socket is closed properly in the various SSH exit paths.
[u/mdw/putty] / storage.h
CommitLineData
d5859615 1/*
2 * storage.h: interface defining functions for storage and recovery
3 * of PuTTY's persistent data.
4 */
5
6#ifndef PUTTY_STORAGE_H
7#define PUTTY_STORAGE_H
8
9/* ----------------------------------------------------------------------
10 * Functions to save and restore PuTTY sessions. Note that this is
11 * only the low-level code to do the reading and writing. The
12 * higher-level code that translates a Config structure into a set
13 * of (key,value) pairs is elsewhere, since it doesn't (mostly)
14 * change between platforms.
15 */
16
17/*
18 * Write a saved session. The caller is expected to call
19 * open_setting_w() to get a `void *' handle, then pass that to a
20 * number of calls to write_setting_s() and write_setting_i(), and
21 * then close it using close_settings_w(). At the end of this call
22 * sequence the settings should have been written to the PuTTY
23 * persistent storage area.
91229c86 24 *
25 * A given key will be written at most once while saving a session.
26 * Keys may be up to 255 characters long. String values have no length
27 * limit.
d5859615 28 */
c85623f9 29void *open_settings_w(const char *sessionname);
30void write_setting_s(void *handle, const char *key, const char *value);
31void write_setting_i(void *handle, const char *key, int value);
9a30e26b 32void write_setting_filename(void *handle, const char *key, Filename value);
33void write_setting_fontspec(void *handle, const char *key, FontSpec font);
d1622aed 34void close_settings_w(void *handle);
d5859615 35
36/*
37 * Read a saved session. The caller is expected to call
38 * open_setting_r() to get a `void *' handle, then pass that to a
39 * number of calls to read_setting_s() and read_setting_i(), and
40 * then close it using close_settings_r().
41 *
42 * read_setting_s() writes into the provided buffer and returns a
43 * pointer to the same buffer.
44 *
45 * If a particular string setting is not present in the session,
46 * read_setting_s() can return NULL, in which case the caller
47 * should invent a sensible default. If an integer setting is not
48 * present, read_setting_i() returns its provided default.
9a30e26b 49 *
50 * read_setting_filename() and read_setting_fontspec() each read into
51 * the provided buffer, and return zero if they failed to.
d5859615 52 */
c85623f9 53void *open_settings_r(const char *sessionname);
54char *read_setting_s(void *handle, const char *key, char *buffer, int buflen);
55int read_setting_i(void *handle, const char *key, int defvalue);
9a30e26b 56int read_setting_filename(void *handle, const char *key, Filename *value);
57int read_setting_fontspec(void *handle, const char *key, FontSpec *font);
d1622aed 58void close_settings_r(void *handle);
59
60/*
61 * Delete a whole saved session.
62 */
c85623f9 63void del_settings(const char *sessionname);
d1622aed 64
65/*
66 * Enumerate all saved sessions.
67 */
68void *enum_settings_start(void);
69char *enum_settings_next(void *handle, char *buffer, int buflen);
70void enum_settings_finish(void *handle);
d5859615 71
72/* ----------------------------------------------------------------------
73 * Functions to access PuTTY's host key database.
74 */
75
76/*
77 * See if a host key matches the database entry. Return values can
78 * be 0 (entry matches database), 1 (entry is absent in database),
79 * or 2 (entry exists in database and is different).
80 */
c85623f9 81int verify_host_key(const char *hostname, int port,
82 const char *keytype, const char *key);
d5859615 83
84/*
85 * Write a host key into the database, overwriting any previous
86 * entry that might have been there.
87 */
c85623f9 88void store_host_key(const char *hostname, int port,
89 const char *keytype, const char *key);
d5859615 90
91/* ----------------------------------------------------------------------
92 * Functions to access PuTTY's random number seed file.
93 */
94
32874aea 95typedef void (*noise_consumer_t) (void *data, int len);
d5859615 96
97/*
98 * Read PuTTY's random seed file and pass its contents to a noise
99 * consumer function.
100 */
101void read_random_seed(noise_consumer_t consumer);
102
103/*
104 * Write PuTTY's random seed file from a given chunk of noise.
105 */
d1622aed 106void write_random_seed(void *data, int len);
d5859615 107
108/* ----------------------------------------------------------------------
109 * Cleanup function: remove all of PuTTY's persistent state.
110 */
111void cleanup_all(void);
112
113#endif