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 an internal Conf structure into 13 * a set of (key,value) pairs in their external storage format is 14 * elsewhere, since it doesn't (mostly) 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. 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. 28 * 29 * Any returned error message must be freed after use. 30 */ 31 settings_w *open_settings_w(const char *sessionname, char **errmsg); 32 void write_setting_s(settings_w *handle, const char *key, const char *value); 33 void write_setting_i(settings_w *handle, const char *key, int value); 34 void write_setting_filename(settings_w *handle, 35 const char *key, Filename *value); 36 void write_setting_fontspec(settings_w *handle, 37 const char *key, FontSpec *font); 38 void close_settings_w(settings_w *handle); 39 40 /* 41 * Read a saved session. The caller is expected to call 42 * open_setting_r() to get a `void *' handle, then pass that to a 43 * number of calls to read_setting_s() and read_setting_i(), and 44 * then close it using close_settings_r(). 45 * 46 * read_setting_s() returns a dynamically allocated string which the 47 * caller must free. read_setting_filename() and 48 * read_setting_fontspec() likewise return dynamically allocated 49 * structures. 50 * 51 * If a particular string setting is not present in the session, 52 * read_setting_s() can return NULL, in which case the caller 53 * should invent a sensible default. If an integer setting is not 54 * present, read_setting_i() returns its provided default. 55 */ 56 settings_r *open_settings_r(const char *sessionname); 57 char *read_setting_s(settings_r *handle, const char *key); 58 int read_setting_i(settings_r *handle, const char *key, int defvalue); 59 Filename *read_setting_filename(settings_r *handle, const char *key); 60 FontSpec *read_setting_fontspec(settings_r *handle, const char *key); 61 void close_settings_r(settings_r *handle); 62 63 /* 64 * Delete a whole saved session. 65 */ 66 void del_settings(const char *sessionname); 67 68 /* 69 * Enumerate all saved sessions. 70 */ 71 settings_e *enum_settings_start(void); 72 bool enum_settings_next(settings_e *handle, strbuf *out); 73 void enum_settings_finish(settings_e *handle); 74 75 /* ---------------------------------------------------------------------- 76 * Functions to access PuTTY's host key database. 77 */ 78 79 /* 80 * See if a host key matches the database entry. Return values can 81 * be 0 (entry matches database), 1 (entry is absent in database), 82 * or 2 (entry exists in database and is different). 83 */ 84 int verify_host_key(const char *hostname, int port, 85 const char *keytype, const char *key); 86 87 /* 88 * Write a host key into the database, overwriting any previous 89 * entry that might have been there. 90 */ 91 void store_host_key(const char *hostname, int port, 92 const char *keytype, const char *key); 93 94 /* ---------------------------------------------------------------------- 95 * Functions to access PuTTY's random number seed file. 96 */ 97 98 typedef void (*noise_consumer_t) (void *data, int len); 99 100 /* 101 * Read PuTTY's random seed file and pass its contents to a noise 102 * consumer function. 103 */ 104 void read_random_seed(noise_consumer_t consumer); 105 106 /* 107 * Write PuTTY's random seed file from a given chunk of noise. 108 */ 109 void write_random_seed(void *data, int len); 110 111 /* ---------------------------------------------------------------------- 112 * Cleanup function: remove all of PuTTY's persistent state. 113 */ 114 void cleanup_all(void); 115 116 #endif 117