2 * storage.h: interface defining functions for storage and recovery
\r
3 * of PuTTY's persistent data.
\r
6 #ifndef PUTTY_STORAGE_H
\r
7 #define PUTTY_STORAGE_H
\r
11 /* ----------------------------------------------------------------------
\r
12 * Functions to save and restore PuTTY sessions. Note that this is
\r
13 * only the low-level code to do the reading and writing. The
\r
14 * higher-level code that translates an internal Conf structure into
\r
15 * a set of (key,value) pairs in their external storage format is
\r
16 * elsewhere, since it doesn't (mostly) change between platforms.
\r
20 * Write a saved session. The caller is expected to call
\r
21 * open_setting_w() to get a `void *' handle, then pass that to a
\r
22 * number of calls to write_setting_s() and write_setting_i(), and
\r
23 * then close it using close_settings_w(). At the end of this call
\r
24 * sequence the settings should have been written to the PuTTY
\r
25 * persistent storage area.
\r
27 * A given key will be written at most once while saving a session.
\r
28 * Keys may be up to 255 characters long. String values have no length
\r
31 * Any returned error message must be freed after use.
\r
33 settings_w *open_settings_w(const char *sessionname, char **errmsg);
\r
34 void write_setting_s(settings_w *handle, const char *key, const char *value);
\r
35 void write_setting_i(settings_w *handle, const char *key, int value);
\r
36 void write_setting_filename(settings_w *handle,
\r
37 const char *key, Filename *value);
\r
38 void write_setting_fontspec(settings_w *handle,
\r
39 const char *key, FontSpec *font);
\r
40 void close_settings_w(settings_w *handle);
\r
43 * Read a saved session. The caller is expected to call
\r
44 * open_setting_r() to get a `void *' handle, then pass that to a
\r
45 * number of calls to read_setting_s() and read_setting_i(), and
\r
46 * then close it using close_settings_r().
\r
48 * read_setting_s() returns a dynamically allocated string which the
\r
49 * caller must free. read_setting_filename() and
\r
50 * read_setting_fontspec() likewise return dynamically allocated
\r
53 * If a particular string setting is not present in the session,
\r
54 * read_setting_s() can return NULL, in which case the caller
\r
55 * should invent a sensible default. If an integer setting is not
\r
56 * present, read_setting_i() returns its provided default.
\r
58 settings_r *open_settings_r(const char *sessionname);
\r
59 char *read_setting_s(settings_r *handle, const char *key);
\r
60 int read_setting_i(settings_r *handle, const char *key, int defvalue);
\r
61 Filename *read_setting_filename(settings_r *handle, const char *key);
\r
62 FontSpec *read_setting_fontspec(settings_r *handle, const char *key);
\r
63 void close_settings_r(settings_r *handle);
\r
66 * Delete a whole saved session.
\r
68 void del_settings(const char *sessionname);
\r
71 * Enumerate all saved sessions.
\r
73 settings_e *enum_settings_start(void);
\r
74 bool enum_settings_next(settings_e *handle, strbuf *out);
\r
75 void enum_settings_finish(settings_e *handle);
\r
77 /* ----------------------------------------------------------------------
\r
78 * Functions to access PuTTY's host key database.
\r
82 * See if a host key matches the database entry. Return values can
\r
83 * be 0 (entry matches database), 1 (entry is absent in database),
\r
84 * or 2 (entry exists in database and is different).
\r
86 int check_stored_host_key(const char *hostname, int port,
\r
87 const char *keytype, const char *key);
\r
90 * Write a host key into the database, overwriting any previous
\r
91 * entry that might have been there.
\r
93 void store_host_key(const char *hostname, int port,
\r
94 const char *keytype, const char *key);
\r
96 /* ----------------------------------------------------------------------
\r
97 * Functions to access PuTTY's configuration for trusted host
\r
98 * certification authorities. This must be stored separately from the
\r
99 * saved-session data, because the whole point is to avoid having to
\r
100 * configure CAs separately per session.
\r
105 strbuf *ca_public_key;
\r
106 char *validity_expression;
\r
110 host_ca_enum *enum_host_ca_start(void);
\r
111 bool enum_host_ca_next(host_ca_enum *handle, strbuf *out);
\r
112 void enum_host_ca_finish(host_ca_enum *handle);
\r
114 host_ca *host_ca_load(const char *name);
\r
115 char *host_ca_save(host_ca *); /* NULL on success, or dynamic error msg */
\r
116 char *host_ca_delete(const char *name); /* likewise */
\r
118 host_ca *host_ca_new(void); /* initialises to default settings */
\r
119 void host_ca_free(host_ca *);
\r
121 /* ----------------------------------------------------------------------
\r
122 * Functions to access PuTTY's random number seed file.
\r
125 typedef void (*noise_consumer_t) (void *data, int len);
\r
128 * Read PuTTY's random seed file and pass its contents to a noise
\r
129 * consumer function.
\r
131 void read_random_seed(noise_consumer_t consumer);
\r
134 * Write PuTTY's random seed file from a given chunk of noise.
\r
136 void write_random_seed(void *data, int len);
\r
138 /* ----------------------------------------------------------------------
\r
139 * Cleanup function: remove all of PuTTY's persistent state.
\r
141 void cleanup_all(void);
\r