projects/libpws

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/pws.h	Tue Feb 10 11:29:54 2015 +0100
     1.3 @@ -0,0 +1,205 @@
     1.4 +/*
     1.5 + * Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
     1.6 + *
     1.7 + * Permission is hereby granted, free of charge, to any person obtaining
     1.8 + * a copy of this software and associated documentation files (the
     1.9 + * "Software"), to deal in the Software without restriction, including
    1.10 + * without limitation the rights to use, copy, modify, merge, publish,
    1.11 + * distribute, sublicense, and/or sell copies of the Software, and to
    1.12 + * permit persons to whom the Software is furnished to do so, subject to
    1.13 + * the following conditions:
    1.14 + *
    1.15 + * The above copyright notice and this permission notice shall be included
    1.16 + * in all copies or substantial portions of the Software.
    1.17 + *
    1.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.25 + */
    1.26 +
    1.27 +#ifndef	PWS_H
    1.28 +#define	PWS_H
    1.29 +
    1.30 +#ifdef __cplusplus
    1.31 +extern "C" {
    1.32 +#endif /* __cplusplus */
    1.33 +
    1.34 +#include <stdint.h>
    1.35 +#include <sys/types.h>
    1.36 +#include <stdio.h>
    1.37 +
    1.38 +#define	LIBPWS_VERSION_MAJOR	1
    1.39 +#define	LIBPWS_VERSION_MINOR	0
    1.40 +#define	LIBPWS_VERSION_MICRO	0
    1.41 +
    1.42 +#define	PWS3_VERSION		0x030D
    1.43 +
    1.44 +#define	PWS3_MAX_FIELD_SIZE	(16 * 1024)
    1.45 +#define	PWS3_MAX_PASSWORD_LEN	1023
    1.46 +#define	PWS3_UUID_SIZE		16
    1.47 +
    1.48 +struct pws3_field;
    1.49 +struct pws3_record;
    1.50 +struct pws3_file;
    1.51 +
    1.52 +enum pws_error_code {
    1.53 +	PWS_ERR_GENERIC_ERROR,
    1.54 +	PWS_ERR_NO_MEMORY,
    1.55 +	PWS_ERR_IO_ERROR,
    1.56 +	PWS_ERR_TRUNCATED_FILE,
    1.57 +	PWS_ERR_INVALID_CHECKSUM,
    1.58 +	PWS_ERR_INVALID_RECORD,
    1.59 +	PWS_ERR_INVALID_HEADER,
    1.60 +	PWS_ERR_UNSUPPORTED_VERSION
    1.61 +};
    1.62 +
    1.63 +enum pws_data_type {
    1.64 +	PWS_DATA_TYPE_BYTES,
    1.65 +	PWS_DATA_TYPE_UUID,
    1.66 +	PWS_DATA_TYPE_TEXT,
    1.67 +	PWS_DATA_TYPE_TIME,
    1.68 +	PWS_DATA_TYPE_UINT8,
    1.69 +	PWS_DATA_TYPE_UINT16,
    1.70 +	PWS_DATA_TYPE_UINT32
    1.71 +};
    1.72 +
    1.73 +enum pws3_header_field_type {
    1.74 +	PWS3_HEADER_FIELD_VERSION,			/* 0x00 */
    1.75 +	PWS3_HEADER_FIELD_UUID,				/* 0x01 */
    1.76 +	PWS3_HEADER_FIELD_NON_DEFAULT_PREFERENCES,	/* 0x02 */
    1.77 +	PWS3_HEADER_FIELD_TREE_DISPLAY_STATUS,		/* 0x03 */
    1.78 +	PWS3_HEADER_FIELD_SAVE_TIMESTAMP,		/* 0x04 */
    1.79 +	PWS3_HEADER_FIELD_SAVE_USER_HOST,		/* 0x05 */
    1.80 +	PWS3_HEADER_FIELD_SAVE_APPLICATION,		/* 0x06 */
    1.81 +	PWS3_HEADER_FIELD_SAVE_USER,			/* 0x07 */
    1.82 +	PWS3_HEADER_FIELD_SAVE_HOST,			/* 0x08 */
    1.83 +	PWS3_HEADER_FIELD_DATABASE_NAME,		/* 0x09 */
    1.84 +	PWS3_HEADER_FIELD_DATABASE_DESCRIPTION,		/* 0x0a */
    1.85 +	PWS3_HEADER_FIELD_DATABASE_FILTERS,		/* 0x0b */
    1.86 +	PWS3_HEADER_FIELD_RESERVED_1,			/* 0x0c */
    1.87 +	PWS3_HEADER_FIELD_RESERVED_2,			/* 0x0d */
    1.88 +	PWS3_HEADER_FIELD_RESERVED_3,			/* 0x0e */
    1.89 +	PWS3_HEADER_FIELD_RECENTLY_USED_ENTRIES,	/* 0x0f */
    1.90 +	PWS3_HEADER_FIELD_NAMED_PASSWORD_POLICIES,	/* 0x10 */
    1.91 +	PWS3_HEADER_FIELD_EMPTY_GROUPS,			/* 0x11 */
    1.92 +	PWS3_HEADER_FIELD_YUBICO,			/* 0x12 */
    1.93 +	PWS3_HEADER_FIELD_END = 0xff
    1.94 +};
    1.95 +
    1.96 +enum pws3_record_field_type {
    1.97 +	PWS3_RECORD_FIELD_UUID = 0x01,
    1.98 +	PWS3_RECORD_FIELD_GROUP,			/* 0x02 */
    1.99 +	PWS3_RECORD_FIELD_TITLE,			/* 0x03 */
   1.100 +	PWS3_RECORD_FIELD_USERNAME,			/* 0x04 */
   1.101 +	PWS3_RECORD_FIELD_NOTES,			/* 0x05 */
   1.102 +	PWS3_RECORD_FIELD_PASSWORD,			/* 0x06 */
   1.103 +	PWS3_RECORD_FIELD_CREATION_TIME,		/* 0x07 */
   1.104 +	PWS3_RECORD_FIELD_PASSWORD_MODIFICATION_TIME,	/* 0x08 */
   1.105 +	PWS3_RECORD_FIELD_ACCESS_TIME,			/* 0x09 */
   1.106 +	PWS3_RECORD_FIELD_PASSWORD_EXPIRY_TIME,		/* 0x0a */
   1.107 +	PWS3_RECORD_FIELD_RESERVED_1,			/* 0x0b */
   1.108 +	PWS3_RECORD_FIELD_MODIFICATION_TIME,		/* 0x0c */
   1.109 +	PWS3_RECORD_FIELD_URL,				/* 0x0d */
   1.110 +	PWS3_RECORD_FIELD_AUTOTYPE,			/* 0x0e */
   1.111 +	PWS3_RECORD_FIELD_PASSWORD_HISTORY,		/* 0x0f */
   1.112 +	PWS3_RECORD_FIELD_PASSWORD_POLICY,		/* 0x10 */
   1.113 +	PWS3_RECORD_FIELD_PASSWORD_EXPIRY_INTERVAL,	/* 0x11 */
   1.114 +	PWS3_RECORD_FIELD_RUN_COMMAND,			/* 0x12 */
   1.115 +	PWS3_RECORD_FIELD_DOUBLE_CLICK_ACTION,		/* 0x13 */
   1.116 +	PWS3_RECORD_FIELD_EMAIL_ADDRESS,		/* 0x14 */
   1.117 +	PWS3_RECORD_FIELD_PROTECTED,			/* 0x15 */
   1.118 +	PWS3_RECORD_FIELD_ALLOWED_PASSWORD_SYMBOLS,	/* 0x16 */
   1.119 +	PWS3_RECORD_FIELD_SHIFT_DOUBLE_CLICK_ACTION,	/* 0x17 */
   1.120 +	PWS3_RECORD_FIELD_PASSWORD_POLICY_NAME,		/* 0x18 */
   1.121 +	PWS3_RECORD_FIELD_KEYBOARD_SHORTCUT,		/* 0x19 */
   1.122 +	PWS3_RECORD_FIELD_END = 0xff
   1.123 +};
   1.124 +
   1.125 +int		pws_init(void);
   1.126 +void		pws_finalize(void);
   1.127 +void		pws_set_alloc_functions(void *(*)(size_t),
   1.128 +    void *(*)(void *, size_t), void (*)(void *, size_t), void *(*)(size_t),
   1.129 +    void *(*)(void *, size_t), void (*)(void *, size_t));
   1.130 +int		pws_generate_uuid(unsigned char [static PWS3_UUID_SIZE]);
   1.131 +
   1.132 +struct pws3_field * pws3_field_create(int, uint8_t);
   1.133 +void		pws3_field_destroy(struct pws3_field *);
   1.134 +int		pws3_field_is_header(struct pws3_field *);
   1.135 +uint8_t		pws3_field_get_type(struct pws3_field *);
   1.136 +enum pws_data_type pws3_field_get_data_type(struct pws3_field *);
   1.137 +int		pws3_field_set_uuid(struct pws3_field *,
   1.138 +    const unsigned char [static PWS3_UUID_SIZE]);
   1.139 +int		pws3_field_set_text(struct pws3_field *, const char [static 1]);
   1.140 +int		pws3_field_set_time(struct pws3_field *, time_t);
   1.141 +int		pws3_field_set_uint8(struct pws3_field *, uint8_t);
   1.142 +int		pws3_field_set_uint16(struct pws3_field *, uint16_t);
   1.143 +int		pws3_field_set_uint32(struct pws3_field *, uint32_t);
   1.144 +int		pws3_field_set_bytes(struct pws3_field *,
   1.145 +    const unsigned char [static 1], size_t);
   1.146 +const unsigned char * pws3_field_get_uuid(struct pws3_field *);
   1.147 +const char *	pws3_field_get_text(struct pws3_field *);
   1.148 +time_t		pws3_field_get_time(struct pws3_field *);
   1.149 +uint8_t		pws3_field_get_uint8(struct pws3_field *);
   1.150 +uint16_t	pws3_field_get_uint16(struct pws3_field *);
   1.151 +uint32_t	pws3_field_get_uint32(struct pws3_field *);
   1.152 +void		pws3_field_get_bytes(struct pws3_field *,
   1.153 +    const unsigned char **, size_t *);
   1.154 +
   1.155 +void		pws3_record_destroy(struct pws3_record *);
   1.156 +struct pws3_record * pws3_record_create(void);
   1.157 +void		pws3_record_set_field(struct pws3_record *,
   1.158 +    struct pws3_field *);
   1.159 +struct pws3_field * pws3_record_get_field(struct pws3_record *, uint8_t);
   1.160 +struct pws3_field * pws3_record_remove_field(struct pws3_record *, uint8_t);
   1.161 +
   1.162 +void		pws3_file_destroy(struct pws3_file *);
   1.163 +struct pws3_file * pws3_file_create(void);
   1.164 +enum pws_error_code pws3_file_get_error_code(struct pws3_file *);
   1.165 +const char *	pws3_file_get_error_message(struct pws3_file *);
   1.166 +int		pws3_file_read_mem(struct pws3_file *, const char *,
   1.167 +    unsigned char *, size_t);
   1.168 +int		pws3_file_read_stream(struct pws3_file *, const char *, FILE *);
   1.169 +int		pws3_file_write_mem(struct pws3_file *, const char *, uint32_t,
   1.170 +    unsigned char **, size_t *);
   1.171 +int		pws3_file_write_stream(struct pws3_file *, const char *,
   1.172 +    uint32_t, FILE *);
   1.173 +
   1.174 +void		pws3_file_set_header_field(struct pws3_file *,
   1.175 +    struct pws3_field *);
   1.176 +struct pws3_field * pws3_file_get_header_field(struct pws3_file *, uint8_t);
   1.177 +struct pws3_field * pws3_file_remove_header_field(struct pws3_file *, uint8_t);
   1.178 +
   1.179 +void		pws3_file_insert_empty_group(struct pws3_file *,
   1.180 +    struct pws3_field *);
   1.181 +struct pws3_field * pws3_file_get_empty_group(struct pws3_file *, const char *);
   1.182 +struct pws3_field * pws3_file_remove_empty_group(struct pws3_file *,
   1.183 +    const char *);
   1.184 +struct pws3_field * pws3_file_first_empty_group(struct pws3_file *);
   1.185 +struct pws3_field * pws3_file_last_empty_group(struct pws3_file *);
   1.186 +struct pws3_field * pws3_file_next_empty_group(struct pws3_file *,
   1.187 +    struct pws3_field *);
   1.188 +struct pws3_field * pws3_file_prev_empty_group(struct pws3_file *,
   1.189 +    struct pws3_field *);
   1.190 +
   1.191 +void		pws3_file_insert_record(struct pws3_file *,
   1.192 +    struct pws3_record *);
   1.193 +struct pws3_record * pws3_file_get_record(struct pws3_file *,
   1.194 +    const unsigned char [static PWS3_UUID_SIZE]);
   1.195 +struct pws3_record * pws3_file_remove_record(struct pws3_file *,
   1.196 +    const unsigned char [static PWS3_UUID_SIZE]);
   1.197 +struct pws3_record * pws3_file_first_record(struct pws3_file *);
   1.198 +struct pws3_record * pws3_file_last_record(struct pws3_file *);
   1.199 +struct pws3_record * pws3_file_next_record(struct pws3_file *,
   1.200 +    struct pws3_record *);
   1.201 +struct pws3_record * pws3_file_prev_record(struct pws3_file *,
   1.202 +    struct pws3_record *);
   1.203 +
   1.204 +#ifdef __cplusplus
   1.205 +}
   1.206 +#endif /* __cplusplus */
   1.207 +
   1.208 +#endif /* !PWS_H */