2 * storage.h: interface defining functions for storage and recovery
3 * of PuTTY's persistent data.
6 #ifndef PUTTY_STORAGE_H
7 #define PUTTY_STORAGE_H
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.
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.
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
29 void *open_settings_w(char *sessionname);
30 void write_setting_s(void *handle, char *key, char *value);
31 void write_setting_i(void *handle, char *key, int value);
32 void close_settings_w(void *handle);
35 * Read a saved session. The caller is expected to call
36 * open_setting_r() to get a `void *' handle, then pass that to a
37 * number of calls to read_setting_s() and read_setting_i(), and
38 * then close it using close_settings_r().
40 * read_setting_s() writes into the provided buffer and returns a
41 * pointer to the same buffer.
43 * If a particular string setting is not present in the session,
44 * read_setting_s() can return NULL, in which case the caller
45 * should invent a sensible default. If an integer setting is not
46 * present, read_setting_i() returns its provided default.
48 void *open_settings_r(char *sessionname);
49 char *read_setting_s(void *handle, char *key, char *buffer, int buflen);
50 int read_setting_i(void *handle, char *key, int defvalue);
51 void close_settings_r(void *handle);
54 * Delete a whole saved session.
56 void del_settings(char *sessionname);
59 * Enumerate all saved sessions.
61 void *enum_settings_start(void);
62 char *enum_settings_next(void *handle, char *buffer, int buflen);
63 void enum_settings_finish(void *handle);
65 /* ----------------------------------------------------------------------
66 * Functions to access PuTTY's host key database.
70 * See if a host key matches the database entry. Return values can
71 * be 0 (entry matches database), 1 (entry is absent in database),
72 * or 2 (entry exists in database and is different).
74 int verify_host_key(char *hostname, int port, char *keytype, char *key);
77 * Write a host key into the database, overwriting any previous
78 * entry that might have been there.
80 void store_host_key(char *hostname, int port, char *keytype, char *key);
82 /* ----------------------------------------------------------------------
83 * Functions to access PuTTY's random number seed file.
86 typedef void (*noise_consumer_t) (void *data, int len);
89 * Read PuTTY's random seed file and pass its contents to a noise
92 void read_random_seed(noise_consumer_t consumer);
95 * Write PuTTY's random seed file from a given chunk of noise.
97 void write_random_seed(void *data, int len);
99 /* ----------------------------------------------------------------------
100 * Cleanup function: remove all of PuTTY's persistent state.
102 void cleanup_all(void);