This source file includes following definitions.
- DBA_OPEN_FUNC
- DBA_CLOSE_FUNC
- DBA_FETCH_FUNC
- DBA_UPDATE_FUNC
- DBA_EXISTS_FUNC
- DBA_DELETE_FUNC
- DBA_FIRSTKEY_FUNC
- DBA_NEXTKEY_FUNC
- DBA_OPTIMIZE_FUNC
- DBA_SYNC_FUNC
- DBA_INFO_FUNC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "php.h"
26
27 #if DBA_INIFILE
28 #include "php_inifile.h"
29
30 #include "libinifile/inifile.h"
31
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <fcntl.h>
38
39 #define INIFILE_DATA \
40 inifile *dba = info->dbf
41
42 #define INIFILE_GKEY \
43 key_type ini_key; \
44 if (!key) { \
45 php_error_docref(NULL, E_WARNING, "No key specified"); \
46 return 0; \
47 } \
48 ini_key = inifile_key_split((char*)key)
49
50 #define INIFILE_DONE \
51 inifile_key_free(&ini_key)
52
53 DBA_OPEN_FUNC(inifile)
54 {
55 info->dbf = inifile_alloc(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT);
56
57 return info->dbf ? SUCCESS : FAILURE;
58 }
59
60 DBA_CLOSE_FUNC(inifile)
61 {
62 INIFILE_DATA;
63
64 inifile_free(dba, info->flags&DBA_PERSISTENT);
65 }
66
67 DBA_FETCH_FUNC(inifile)
68 {
69 val_type ini_val;
70
71 INIFILE_DATA;
72 INIFILE_GKEY;
73
74 ini_val = inifile_fetch(dba, &ini_key, skip);
75 *newlen = ini_val.value ? strlen(ini_val.value) : 0;
76 INIFILE_DONE;
77 return ini_val.value;
78 }
79
80 DBA_UPDATE_FUNC(inifile)
81 {
82 val_type ini_val;
83 int res;
84
85 INIFILE_DATA;
86 INIFILE_GKEY;
87
88 ini_val.value = val;
89
90 if (mode == 1) {
91 res = inifile_append(dba, &ini_key, &ini_val);
92 } else {
93 res = inifile_replace(dba, &ini_key, &ini_val);
94 }
95 INIFILE_DONE;
96 switch(res) {
97 case -1:
98 php_error_docref1(NULL, key, E_WARNING, "Operation not possible");
99 return FAILURE;
100 default:
101 case 0:
102 return SUCCESS;
103 case 1:
104 return FAILURE;
105 }
106 }
107
108 DBA_EXISTS_FUNC(inifile)
109 {
110 val_type ini_val;
111
112 INIFILE_DATA;
113 INIFILE_GKEY;
114
115 ini_val = inifile_fetch(dba, &ini_key, 0);
116 INIFILE_DONE;
117 if (ini_val.value) {
118 inifile_val_free(&ini_val);
119 return SUCCESS;
120 }
121 return FAILURE;
122 }
123
124 DBA_DELETE_FUNC(inifile)
125 {
126 int res;
127 zend_bool found = 0;
128
129 INIFILE_DATA;
130 INIFILE_GKEY;
131
132 res = inifile_delete_ex(dba, &ini_key, &found);
133
134 INIFILE_DONE;
135 return (res == -1 || !found ? FAILURE : SUCCESS);
136 }
137
138 DBA_FIRSTKEY_FUNC(inifile)
139 {
140 INIFILE_DATA;
141
142 if (inifile_firstkey(dba)) {
143 char *result = inifile_key_string(&dba->curr.key);
144 *newlen = strlen(result);
145 return result;
146 } else {
147 return NULL;
148 }
149 }
150
151 DBA_NEXTKEY_FUNC(inifile)
152 {
153 INIFILE_DATA;
154
155 if (!dba->curr.key.group && !dba->curr.key.name) {
156 return NULL;
157 }
158
159 if (inifile_nextkey(dba)) {
160 char *result = inifile_key_string(&dba->curr.key);
161 *newlen = strlen(result);
162 return result;
163 } else {
164 return NULL;
165 }
166 }
167
168 DBA_OPTIMIZE_FUNC(inifile)
169 {
170
171 return SUCCESS;
172 }
173
174 DBA_SYNC_FUNC(inifile)
175 {
176
177 return SUCCESS;
178 }
179
180 DBA_INFO_FUNC(inifile)
181 {
182 return estrdup(inifile_version());
183 }
184
185 #endif
186
187
188
189
190
191
192
193
194