storage.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * storage.h: interface defining functions for storage and recovery
  3. * of PuTTY's persistent data.
  4. */
  5. #ifndef PUTTY_STORAGE_H
  6. #define PUTTY_STORAGE_H
  7. /* ----------------------------------------------------------------------
  8. * Functions to save and restore PuTTY sessions. Note that this is
  9. * only the low-level code to do the reading and writing. The
  10. * higher-level code that translates an internal Conf structure into
  11. * a set of (key,value) pairs in their external storage format is
  12. * elsewhere, since it doesn't (mostly) change between platforms.
  13. */
  14. /*
  15. * Write a saved session. The caller is expected to call
  16. * open_setting_w() to get a `void *' handle, then pass that to a
  17. * number of calls to write_setting_s() and write_setting_i(), and
  18. * then close it using close_settings_w(). At the end of this call
  19. * sequence the settings should have been written to the PuTTY
  20. * persistent storage area.
  21. *
  22. * A given key will be written at most once while saving a session.
  23. * Keys may be up to 255 characters long. String values have no length
  24. * limit.
  25. *
  26. * Any returned error message must be freed after use.
  27. */
  28. void *open_settings_w(const char *sessionname, char **errmsg);
  29. void write_setting_s(void *handle, const char *key, const char *value);
  30. void write_setting_i(void *handle, const char *key, int value);
  31. void write_setting_filename(void *handle, const char *key, Filename *value);
  32. void write_setting_fontspec(void *handle, const char *key, FontSpec *font);
  33. void close_settings_w(void *handle);
  34. /*
  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().
  39. *
  40. * read_setting_s() returns a dynamically allocated string which the
  41. * caller must free. read_setting_filename() and
  42. * read_setting_fontspec() likewise return dynamically allocated
  43. * structures.
  44. *
  45. * If a particular string setting is not present in the session,
  46. * read_setting_s() can return NULL, in which case the caller
  47. * should invent a sensible default. If an integer setting is not
  48. * present, read_setting_i() returns its provided default.
  49. */
  50. void *open_settings_r(const char *sessionname);
  51. char *read_setting_s(void *handle, const char *key);
  52. int read_setting_i(void *handle, const char *key, int defvalue);
  53. Filename *read_setting_filename(void *handle, const char *key);
  54. FontSpec *read_setting_fontspec(void *handle, const char *key);
  55. void close_settings_r(void *handle);
  56. /*
  57. * Delete a whole saved session.
  58. */
  59. void del_settings(const char *sessionname);
  60. /*
  61. * Enumerate all saved sessions.
  62. */
  63. void *enum_settings_start(void);
  64. char *enum_settings_next(void *handle, char *buffer, int buflen);
  65. void enum_settings_finish(void *handle);
  66. /* ----------------------------------------------------------------------
  67. * Functions to access PuTTY's host key database.
  68. */
  69. #ifdef MPEXT
  70. int retrieve_host_key(const char *hostname, int port,
  71. const char *keytype, char *key, int maxlen);
  72. #else
  73. /*
  74. * See if a host key matches the database entry. Return values can
  75. * be 0 (entry matches database), 1 (entry is absent in database),
  76. * or 2 (entry exists in database and is different).
  77. */
  78. int verify_host_key(const char *hostname, int port,
  79. const char *keytype, const char *key);
  80. #endif
  81. /*
  82. * Write a host key into the database, overwriting any previous
  83. * entry that might have been there.
  84. */
  85. void store_host_key(const char *hostname, int port,
  86. const char *keytype, const char *key);
  87. /* ----------------------------------------------------------------------
  88. * Functions to access PuTTY's random number seed file.
  89. */
  90. typedef void (*noise_consumer_t) (void *data, int len);
  91. /*
  92. * Read PuTTY's random seed file and pass its contents to a noise
  93. * consumer function.
  94. */
  95. void read_random_seed(noise_consumer_t consumer);
  96. /*
  97. * Write PuTTY's random seed file from a given chunk of noise.
  98. */
  99. void write_random_seed(void *data, int len);
  100. /* ----------------------------------------------------------------------
  101. * Cleanup function: remove all of PuTTY's persistent state.
  102. */
  103. void cleanup_all(void);
  104. #endif