putty/storage.h

117 строки
4.1 KiB
C
Исходник Обычный вид История

/*
* storage.h: interface defining functions for storage and recovery
* of PuTTY's persistent data.
*/
#ifndef PUTTY_STORAGE_H
#define PUTTY_STORAGE_H
/* ----------------------------------------------------------------------
* Functions to save and restore PuTTY sessions. Note that this is
* only the low-level code to do the reading and writing. The
Post-release destabilisation! Completely remove the struct type 'Config' in putty.h, which stores all PuTTY's settings and includes an arbitrary length limit on every single one of those settings which is stored in string form. In place of it is 'Conf', an opaque data type everywhere outside the new file conf.c, which stores a list of (key, value) pairs in which every key contains an integer identifying a configuration setting, and for some of those integers the key also contains extra parts (so that, for instance, CONF_environmt is a string-to-string mapping). Everywhere that a Config was previously used, a Conf is now; everywhere there was a Config structure copy, conf_copy() is called; every lookup, adjustment, load and save operation on a Config has been rewritten; and there's a mechanism for serialising a Conf into a binary blob and back for use with Duplicate Session. User-visible effects of this change _should_ be minimal, though I don't doubt I've introduced one or two bugs here and there which will eventually be found. The _intended_ visible effects of this change are that all arbitrary limits on configuration strings and lists (e.g. limit on number of port forwardings) should now disappear; that list boxes in the configuration will now be displayed in a sorted order rather than the arbitrary order in which they were added to the list (since the underlying data structure is now a sorted tree234 rather than an ad-hoc comma-separated string); and one more specific change, which is that local and dynamic port forwardings on the same port number are now mutually exclusive in the configuration (putting 'D' in the key rather than the value was a mistake in the first place). One other reorganisation as a result of this is that I've moved all the dialog.c standard handlers (dlg_stdeditbox_handler and friends) out into config.c, because I can't really justify calling them generic any more. When they took a pointer to an arbitrary structure type and the offset of a field within that structure, they were independent of whether that structure was a Config or something completely different, but now they really do expect to talk to a Conf, which can _only_ be used for PuTTY configuration, so I've renamed them all things like conf_editbox_handler and moved them out of the nominally independent dialog-box management module into the PuTTY-specific config.c. [originally from svn r9214]
2011-07-14 22:52:21 +04:00
* higher-level code that translates an internal Conf structure into
* a set of (key,value) pairs in their external storage format is
* elsewhere, since it doesn't (mostly) change between platforms.
*/
/*
* Write a saved session. The caller is expected to call
* open_setting_w() to get a `void *' handle, then pass that to a
* number of calls to write_setting_s() and write_setting_i(), and
* then close it using close_settings_w(). At the end of this call
* sequence the settings should have been written to the PuTTY
* persistent storage area.
*
* A given key will be written at most once while saving a session.
* Keys may be up to 255 characters long. String values have no length
* limit.
*
* Any returned error message must be freed after use.
*/
settings_w *open_settings_w(const char *sessionname, char **errmsg);
void write_setting_s(settings_w *handle, const char *key, const char *value);
void write_setting_i(settings_w *handle, const char *key, int value);
void write_setting_filename(settings_w *handle,
const char *key, Filename *value);
void write_setting_fontspec(settings_w *handle,
const char *key, FontSpec *font);
void close_settings_w(settings_w *handle);
/*
* Read a saved session. The caller is expected to call
* open_setting_r() to get a `void *' handle, then pass that to a
* number of calls to read_setting_s() and read_setting_i(), and
* then close it using close_settings_r().
*
Post-release destabilisation! Completely remove the struct type 'Config' in putty.h, which stores all PuTTY's settings and includes an arbitrary length limit on every single one of those settings which is stored in string form. In place of it is 'Conf', an opaque data type everywhere outside the new file conf.c, which stores a list of (key, value) pairs in which every key contains an integer identifying a configuration setting, and for some of those integers the key also contains extra parts (so that, for instance, CONF_environmt is a string-to-string mapping). Everywhere that a Config was previously used, a Conf is now; everywhere there was a Config structure copy, conf_copy() is called; every lookup, adjustment, load and save operation on a Config has been rewritten; and there's a mechanism for serialising a Conf into a binary blob and back for use with Duplicate Session. User-visible effects of this change _should_ be minimal, though I don't doubt I've introduced one or two bugs here and there which will eventually be found. The _intended_ visible effects of this change are that all arbitrary limits on configuration strings and lists (e.g. limit on number of port forwardings) should now disappear; that list boxes in the configuration will now be displayed in a sorted order rather than the arbitrary order in which they were added to the list (since the underlying data structure is now a sorted tree234 rather than an ad-hoc comma-separated string); and one more specific change, which is that local and dynamic port forwardings on the same port number are now mutually exclusive in the configuration (putting 'D' in the key rather than the value was a mistake in the first place). One other reorganisation as a result of this is that I've moved all the dialog.c standard handlers (dlg_stdeditbox_handler and friends) out into config.c, because I can't really justify calling them generic any more. When they took a pointer to an arbitrary structure type and the offset of a field within that structure, they were independent of whether that structure was a Config or something completely different, but now they really do expect to talk to a Conf, which can _only_ be used for PuTTY configuration, so I've renamed them all things like conf_editbox_handler and moved them out of the nominally independent dialog-box management module into the PuTTY-specific config.c. [originally from svn r9214]
2011-07-14 22:52:21 +04:00
* read_setting_s() returns a dynamically allocated string which the
* caller must free. read_setting_filename() and
* read_setting_fontspec() likewise return dynamically allocated
* structures.
*
* If a particular string setting is not present in the session,
* read_setting_s() can return NULL, in which case the caller
* should invent a sensible default. If an integer setting is not
* present, read_setting_i() returns its provided default.
*/
settings_r *open_settings_r(const char *sessionname);
char *read_setting_s(settings_r *handle, const char *key);
int read_setting_i(settings_r *handle, const char *key, int defvalue);
Filename *read_setting_filename(settings_r *handle, const char *key);
FontSpec *read_setting_fontspec(settings_r *handle, const char *key);
void close_settings_r(settings_r *handle);
/*
* Delete a whole saved session.
*/
void del_settings(const char *sessionname);
/*
* Enumerate all saved sessions.
*/
settings_e *enum_settings_start(void);
bool enum_settings_next(settings_e *handle, strbuf *out);
void enum_settings_finish(settings_e *handle);
/* ----------------------------------------------------------------------
* Functions to access PuTTY's host key database.
*/
/*
* See if a host key matches the database entry. Return values can
* be 0 (entry matches database), 1 (entry is absent in database),
* or 2 (entry exists in database and is different).
*/
int verify_host_key(const char *hostname, int port,
const char *keytype, const char *key);
/*
* Write a host key into the database, overwriting any previous
* entry that might have been there.
*/
void store_host_key(const char *hostname, int port,
const char *keytype, const char *key);
/* ----------------------------------------------------------------------
* Functions to access PuTTY's random number seed file.
*/
typedef void (*noise_consumer_t) (void *data, int len);
/*
* Read PuTTY's random seed file and pass its contents to a noise
* consumer function.
*/
void read_random_seed(noise_consumer_t consumer);
/*
* Write PuTTY's random seed file from a given chunk of noise.
*/
void write_random_seed(void *data, int len);
/* ----------------------------------------------------------------------
* Cleanup function: remove all of PuTTY's persistent state.
*/
void cleanup_all(void);
#endif