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