1 /***************************************************************************
2 ini.h - Backend for ini-style like files
6 copyright : (C) 2005 by Markus Raab
7 email : debian@markus-raab.org
8 ***************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the BSD License (revised). *
15 ***************************************************************************/
19 /***************************************************************************
21 * This is a ini-style backend.
22 * Key/Value Pairs are stored in files in following scheme:
27 * allow subkeys setting/getting
28 * setting existing keys again
29 * setting errno properly (update doc, how it should be)
30 * KDB_ERR_NOMEM bei malloc errors
32 ***************************************************************************/
38 #include <kdbbackend.h>
40 #define BACKENDNAME "ini"
41 #define BACKENDVERSION "0.1.2"
49 typedef struct _backendData backendData;
51 #define FILEDES ((((backendData*)kdbhGetBackendData (handle))->fd))
52 #define FILEPTR ((((backendData*)kdbhGetBackendData (handle))->fc))
54 int IniReadDir(KDB *handle, Key * key, KeySet * returned, unsigned long options);
55 int IniChooseFile(KDB *handle, Key * key, KeySet * returned, unsigned long options);
56 int IniReadFile (KDB *handle, Key * key, KeySet * returned, unsigned long options);
57 int IniSetKeys (KDB *handle, KeySet * origKeys);
60 int open_file (KDB *handle, char * filename, char mode);
61 int close_file (KDB *handle);
62 int enlarge_file (KDB *handle, long where, long space);
63 int shrink_file (KDB *handle, long where, long space);
64 int read_key (KDB *handle, Key * key, char * root);
65 int write_key (KDB *handle, Key * key, long oldpos);
66 int remove_key (KDB *handle, Key * key, long oldpos);
68 int kdbiRealloc (void ** buffer, size_t size);
70 int stat_file (Key * forKey, char * filename);
71 size_t base_name (const Key * forKey, char * basename);
72 size_t file_name (const Key * forKey, char * basename);
74 void * open_dir (char * pathname);
75 int create_dir (char * filename);
76 int read_dir (void * dir, char * filename);
77 int close_dir (void * dir);
79 /**Parsing functions*/
80 int parse_buffer (char * c);
81 int convert_engine (char * c);
82 int convert_strlen (char * p, int size);
83 int convert_stream (char * buffer, int size, FILE * stream);
84 int make_key (Key * key, char * root, char * buffer_key, char * buffer_value, char * buffer_comment);
86 /**Some systems have even longer pathnames */
88 #define MAX_PATH_LENGTH PATH_MAX
89 /**This value is garanteed on any Posix system */
91 #define MAX_PATH_LENGTH _POSIX_PATH_MAX
93 /**Fallback: This value should be useful*/
94 #define MAX_PATH_LENGTH 4096
98 /**This buffer size is fastest for reading and writing
100 #define BUFFER_RDWR_SIZE 8024
102 /**Buffer for holding strings*/
104 #define BUFFER_SIZE 4048
107 /**Some more key types needed for ini
108 * FILE ... is a real file on the system
109 * DIR ... is a real directory
110 * SUBDIR ... is a subdirectoy within a file*/
111 #define KEY_TYPE_FILE 4
112 #define KEY_TYPE_DIR 8
113 #define KEY_TYPE_SUBDIR 16