projects/libpws

annotate include/pws.h @ 0:d541e748cfd8

Initial revision
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Tue Feb 10 11:29:54 2015 +0100 (2015-02-10)
parents
children 96a507a110c8
rev   line source
guido+libpws@0 1 /*
guido+libpws@0 2 * Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
guido+libpws@0 3 *
guido+libpws@0 4 * Permission is hereby granted, free of charge, to any person obtaining
guido+libpws@0 5 * a copy of this software and associated documentation files (the
guido+libpws@0 6 * "Software"), to deal in the Software without restriction, including
guido+libpws@0 7 * without limitation the rights to use, copy, modify, merge, publish,
guido+libpws@0 8 * distribute, sublicense, and/or sell copies of the Software, and to
guido+libpws@0 9 * permit persons to whom the Software is furnished to do so, subject to
guido+libpws@0 10 * the following conditions:
guido+libpws@0 11 *
guido+libpws@0 12 * The above copyright notice and this permission notice shall be included
guido+libpws@0 13 * in all copies or substantial portions of the Software.
guido+libpws@0 14 *
guido+libpws@0 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
guido+libpws@0 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
guido+libpws@0 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
guido+libpws@0 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
guido+libpws@0 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
guido+libpws@0 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
guido+libpws@0 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
guido+libpws@0 22 */
guido+libpws@0 23
guido+libpws@0 24 #ifndef PWS_H
guido+libpws@0 25 #define PWS_H
guido+libpws@0 26
guido+libpws@0 27 #ifdef __cplusplus
guido+libpws@0 28 extern "C" {
guido+libpws@0 29 #endif /* __cplusplus */
guido+libpws@0 30
guido+libpws@0 31 #include <stdint.h>
guido+libpws@0 32 #include <sys/types.h>
guido+libpws@0 33 #include <stdio.h>
guido+libpws@0 34
guido+libpws@0 35 #define LIBPWS_VERSION_MAJOR 1
guido+libpws@0 36 #define LIBPWS_VERSION_MINOR 0
guido+libpws@0 37 #define LIBPWS_VERSION_MICRO 0
guido+libpws@0 38
guido+libpws@0 39 #define PWS3_VERSION 0x030D
guido+libpws@0 40
guido+libpws@0 41 #define PWS3_MAX_FIELD_SIZE (16 * 1024)
guido+libpws@0 42 #define PWS3_MAX_PASSWORD_LEN 1023
guido+libpws@0 43 #define PWS3_UUID_SIZE 16
guido+libpws@0 44
guido+libpws@0 45 struct pws3_field;
guido+libpws@0 46 struct pws3_record;
guido+libpws@0 47 struct pws3_file;
guido+libpws@0 48
guido+libpws@0 49 enum pws_error_code {
guido+libpws@0 50 PWS_ERR_GENERIC_ERROR,
guido+libpws@0 51 PWS_ERR_NO_MEMORY,
guido+libpws@0 52 PWS_ERR_IO_ERROR,
guido+libpws@0 53 PWS_ERR_TRUNCATED_FILE,
guido+libpws@0 54 PWS_ERR_INVALID_CHECKSUM,
guido+libpws@0 55 PWS_ERR_INVALID_RECORD,
guido+libpws@0 56 PWS_ERR_INVALID_HEADER,
guido+libpws@0 57 PWS_ERR_UNSUPPORTED_VERSION
guido+libpws@0 58 };
guido+libpws@0 59
guido+libpws@0 60 enum pws_data_type {
guido+libpws@0 61 PWS_DATA_TYPE_BYTES,
guido+libpws@0 62 PWS_DATA_TYPE_UUID,
guido+libpws@0 63 PWS_DATA_TYPE_TEXT,
guido+libpws@0 64 PWS_DATA_TYPE_TIME,
guido+libpws@0 65 PWS_DATA_TYPE_UINT8,
guido+libpws@0 66 PWS_DATA_TYPE_UINT16,
guido+libpws@0 67 PWS_DATA_TYPE_UINT32
guido+libpws@0 68 };
guido+libpws@0 69
guido+libpws@0 70 enum pws3_header_field_type {
guido+libpws@0 71 PWS3_HEADER_FIELD_VERSION, /* 0x00 */
guido+libpws@0 72 PWS3_HEADER_FIELD_UUID, /* 0x01 */
guido+libpws@0 73 PWS3_HEADER_FIELD_NON_DEFAULT_PREFERENCES, /* 0x02 */
guido+libpws@0 74 PWS3_HEADER_FIELD_TREE_DISPLAY_STATUS, /* 0x03 */
guido+libpws@0 75 PWS3_HEADER_FIELD_SAVE_TIMESTAMP, /* 0x04 */
guido+libpws@0 76 PWS3_HEADER_FIELD_SAVE_USER_HOST, /* 0x05 */
guido+libpws@0 77 PWS3_HEADER_FIELD_SAVE_APPLICATION, /* 0x06 */
guido+libpws@0 78 PWS3_HEADER_FIELD_SAVE_USER, /* 0x07 */
guido+libpws@0 79 PWS3_HEADER_FIELD_SAVE_HOST, /* 0x08 */
guido+libpws@0 80 PWS3_HEADER_FIELD_DATABASE_NAME, /* 0x09 */
guido+libpws@0 81 PWS3_HEADER_FIELD_DATABASE_DESCRIPTION, /* 0x0a */
guido+libpws@0 82 PWS3_HEADER_FIELD_DATABASE_FILTERS, /* 0x0b */
guido+libpws@0 83 PWS3_HEADER_FIELD_RESERVED_1, /* 0x0c */
guido+libpws@0 84 PWS3_HEADER_FIELD_RESERVED_2, /* 0x0d */
guido+libpws@0 85 PWS3_HEADER_FIELD_RESERVED_3, /* 0x0e */
guido+libpws@0 86 PWS3_HEADER_FIELD_RECENTLY_USED_ENTRIES, /* 0x0f */
guido+libpws@0 87 PWS3_HEADER_FIELD_NAMED_PASSWORD_POLICIES, /* 0x10 */
guido+libpws@0 88 PWS3_HEADER_FIELD_EMPTY_GROUPS, /* 0x11 */
guido+libpws@0 89 PWS3_HEADER_FIELD_YUBICO, /* 0x12 */
guido+libpws@0 90 PWS3_HEADER_FIELD_END = 0xff
guido+libpws@0 91 };
guido+libpws@0 92
guido+libpws@0 93 enum pws3_record_field_type {
guido+libpws@0 94 PWS3_RECORD_FIELD_UUID = 0x01,
guido+libpws@0 95 PWS3_RECORD_FIELD_GROUP, /* 0x02 */
guido+libpws@0 96 PWS3_RECORD_FIELD_TITLE, /* 0x03 */
guido+libpws@0 97 PWS3_RECORD_FIELD_USERNAME, /* 0x04 */
guido+libpws@0 98 PWS3_RECORD_FIELD_NOTES, /* 0x05 */
guido+libpws@0 99 PWS3_RECORD_FIELD_PASSWORD, /* 0x06 */
guido+libpws@0 100 PWS3_RECORD_FIELD_CREATION_TIME, /* 0x07 */
guido+libpws@0 101 PWS3_RECORD_FIELD_PASSWORD_MODIFICATION_TIME, /* 0x08 */
guido+libpws@0 102 PWS3_RECORD_FIELD_ACCESS_TIME, /* 0x09 */
guido+libpws@0 103 PWS3_RECORD_FIELD_PASSWORD_EXPIRY_TIME, /* 0x0a */
guido+libpws@0 104 PWS3_RECORD_FIELD_RESERVED_1, /* 0x0b */
guido+libpws@0 105 PWS3_RECORD_FIELD_MODIFICATION_TIME, /* 0x0c */
guido+libpws@0 106 PWS3_RECORD_FIELD_URL, /* 0x0d */
guido+libpws@0 107 PWS3_RECORD_FIELD_AUTOTYPE, /* 0x0e */
guido+libpws@0 108 PWS3_RECORD_FIELD_PASSWORD_HISTORY, /* 0x0f */
guido+libpws@0 109 PWS3_RECORD_FIELD_PASSWORD_POLICY, /* 0x10 */
guido+libpws@0 110 PWS3_RECORD_FIELD_PASSWORD_EXPIRY_INTERVAL, /* 0x11 */
guido+libpws@0 111 PWS3_RECORD_FIELD_RUN_COMMAND, /* 0x12 */
guido+libpws@0 112 PWS3_RECORD_FIELD_DOUBLE_CLICK_ACTION, /* 0x13 */
guido+libpws@0 113 PWS3_RECORD_FIELD_EMAIL_ADDRESS, /* 0x14 */
guido+libpws@0 114 PWS3_RECORD_FIELD_PROTECTED, /* 0x15 */
guido+libpws@0 115 PWS3_RECORD_FIELD_ALLOWED_PASSWORD_SYMBOLS, /* 0x16 */
guido+libpws@0 116 PWS3_RECORD_FIELD_SHIFT_DOUBLE_CLICK_ACTION, /* 0x17 */
guido+libpws@0 117 PWS3_RECORD_FIELD_PASSWORD_POLICY_NAME, /* 0x18 */
guido+libpws@0 118 PWS3_RECORD_FIELD_KEYBOARD_SHORTCUT, /* 0x19 */
guido+libpws@0 119 PWS3_RECORD_FIELD_END = 0xff
guido+libpws@0 120 };
guido+libpws@0 121
guido+libpws@0 122 int pws_init(void);
guido+libpws@0 123 void pws_finalize(void);
guido+libpws@0 124 void pws_set_alloc_functions(void *(*)(size_t),
guido+libpws@0 125 void *(*)(void *, size_t), void (*)(void *, size_t), void *(*)(size_t),
guido+libpws@0 126 void *(*)(void *, size_t), void (*)(void *, size_t));
guido+libpws@0 127 int pws_generate_uuid(unsigned char [static PWS3_UUID_SIZE]);
guido+libpws@0 128
guido+libpws@0 129 struct pws3_field * pws3_field_create(int, uint8_t);
guido+libpws@0 130 void pws3_field_destroy(struct pws3_field *);
guido+libpws@0 131 int pws3_field_is_header(struct pws3_field *);
guido+libpws@0 132 uint8_t pws3_field_get_type(struct pws3_field *);
guido+libpws@0 133 enum pws_data_type pws3_field_get_data_type(struct pws3_field *);
guido+libpws@0 134 int pws3_field_set_uuid(struct pws3_field *,
guido+libpws@0 135 const unsigned char [static PWS3_UUID_SIZE]);
guido+libpws@0 136 int pws3_field_set_text(struct pws3_field *, const char [static 1]);
guido+libpws@0 137 int pws3_field_set_time(struct pws3_field *, time_t);
guido+libpws@0 138 int pws3_field_set_uint8(struct pws3_field *, uint8_t);
guido+libpws@0 139 int pws3_field_set_uint16(struct pws3_field *, uint16_t);
guido+libpws@0 140 int pws3_field_set_uint32(struct pws3_field *, uint32_t);
guido+libpws@0 141 int pws3_field_set_bytes(struct pws3_field *,
guido+libpws@0 142 const unsigned char [static 1], size_t);
guido+libpws@0 143 const unsigned char * pws3_field_get_uuid(struct pws3_field *);
guido+libpws@0 144 const char * pws3_field_get_text(struct pws3_field *);
guido+libpws@0 145 time_t pws3_field_get_time(struct pws3_field *);
guido+libpws@0 146 uint8_t pws3_field_get_uint8(struct pws3_field *);
guido+libpws@0 147 uint16_t pws3_field_get_uint16(struct pws3_field *);
guido+libpws@0 148 uint32_t pws3_field_get_uint32(struct pws3_field *);
guido+libpws@0 149 void pws3_field_get_bytes(struct pws3_field *,
guido+libpws@0 150 const unsigned char **, size_t *);
guido+libpws@0 151
guido+libpws@0 152 void pws3_record_destroy(struct pws3_record *);
guido+libpws@0 153 struct pws3_record * pws3_record_create(void);
guido+libpws@0 154 void pws3_record_set_field(struct pws3_record *,
guido+libpws@0 155 struct pws3_field *);
guido+libpws@0 156 struct pws3_field * pws3_record_get_field(struct pws3_record *, uint8_t);
guido+libpws@0 157 struct pws3_field * pws3_record_remove_field(struct pws3_record *, uint8_t);
guido+libpws@0 158
guido+libpws@0 159 void pws3_file_destroy(struct pws3_file *);
guido+libpws@0 160 struct pws3_file * pws3_file_create(void);
guido+libpws@0 161 enum pws_error_code pws3_file_get_error_code(struct pws3_file *);
guido+libpws@0 162 const char * pws3_file_get_error_message(struct pws3_file *);
guido+libpws@0 163 int pws3_file_read_mem(struct pws3_file *, const char *,
guido+libpws@0 164 unsigned char *, size_t);
guido+libpws@0 165 int pws3_file_read_stream(struct pws3_file *, const char *, FILE *);
guido+libpws@0 166 int pws3_file_write_mem(struct pws3_file *, const char *, uint32_t,
guido+libpws@0 167 unsigned char **, size_t *);
guido+libpws@0 168 int pws3_file_write_stream(struct pws3_file *, const char *,
guido+libpws@0 169 uint32_t, FILE *);
guido+libpws@0 170
guido+libpws@0 171 void pws3_file_set_header_field(struct pws3_file *,
guido+libpws@0 172 struct pws3_field *);
guido+libpws@0 173 struct pws3_field * pws3_file_get_header_field(struct pws3_file *, uint8_t);
guido+libpws@0 174 struct pws3_field * pws3_file_remove_header_field(struct pws3_file *, uint8_t);
guido+libpws@0 175
guido+libpws@0 176 void pws3_file_insert_empty_group(struct pws3_file *,
guido+libpws@0 177 struct pws3_field *);
guido+libpws@0 178 struct pws3_field * pws3_file_get_empty_group(struct pws3_file *, const char *);
guido+libpws@0 179 struct pws3_field * pws3_file_remove_empty_group(struct pws3_file *,
guido+libpws@0 180 const char *);
guido+libpws@0 181 struct pws3_field * pws3_file_first_empty_group(struct pws3_file *);
guido+libpws@0 182 struct pws3_field * pws3_file_last_empty_group(struct pws3_file *);
guido+libpws@0 183 struct pws3_field * pws3_file_next_empty_group(struct pws3_file *,
guido+libpws@0 184 struct pws3_field *);
guido+libpws@0 185 struct pws3_field * pws3_file_prev_empty_group(struct pws3_file *,
guido+libpws@0 186 struct pws3_field *);
guido+libpws@0 187
guido+libpws@0 188 void pws3_file_insert_record(struct pws3_file *,
guido+libpws@0 189 struct pws3_record *);
guido+libpws@0 190 struct pws3_record * pws3_file_get_record(struct pws3_file *,
guido+libpws@0 191 const unsigned char [static PWS3_UUID_SIZE]);
guido+libpws@0 192 struct pws3_record * pws3_file_remove_record(struct pws3_file *,
guido+libpws@0 193 const unsigned char [static PWS3_UUID_SIZE]);
guido+libpws@0 194 struct pws3_record * pws3_file_first_record(struct pws3_file *);
guido+libpws@0 195 struct pws3_record * pws3_file_last_record(struct pws3_file *);
guido+libpws@0 196 struct pws3_record * pws3_file_next_record(struct pws3_file *,
guido+libpws@0 197 struct pws3_record *);
guido+libpws@0 198 struct pws3_record * pws3_file_prev_record(struct pws3_file *,
guido+libpws@0 199 struct pws3_record *);
guido+libpws@0 200
guido+libpws@0 201 #ifdef __cplusplus
guido+libpws@0 202 }
guido+libpws@0 203 #endif /* __cplusplus */
guido+libpws@0 204
guido+libpws@0 205 #endif /* !PWS_H */