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