php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
dba_inifile.c
Go to the documentation of this file.
1
/*
2
+----------------------------------------------------------------------+
3
| Copyright (c) The PHP Group |
4
+----------------------------------------------------------------------+
5
| This source file is subject to version 3.01 of the PHP license, |
6
| that is bundled with this package in the file LICENSE, and is |
7
| available through the world-wide-web at the following url: |
8
| https://www.php.net/license/3_01.txt |
9
| If you did not receive a copy of the PHP license and are unable to |
10
| obtain it through the world-wide-web, please send a note to |
11
| license@php.net so we can mail you a copy immediately. |
12
+----------------------------------------------------------------------+
13
| Author: Marcus Boerger <helly@php.net> |
14
+----------------------------------------------------------------------+
15
*/
16
17
#ifdef HAVE_CONFIG_H
18
#include <config.h>
19
#endif
20
21
#include "
php.h
"
22
23
#ifdef DBA_INIFILE
24
#include "
php_inifile.h
"
25
26
#include "
libinifile/inifile.h
"
27
28
#ifdef HAVE_UNISTD_H
29
#include <
unistd.h
>
30
#endif
31
#include <sys/types.h>
32
#include <sys/stat.h>
33
#include <fcntl.h>
34
35
DBA_OPEN_FUNC(
inifile
)
36
{
37
info->dbf =
inifile_alloc
(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT);
38
39
return
info->dbf ?
SUCCESS
:
FAILURE
;
40
}
41
42
DBA_CLOSE_FUNC(
inifile
)
43
{
44
inifile
*dba = info->dbf;
45
46
inifile_free
(dba, info->flags&DBA_PERSISTENT);
47
}
48
49
DBA_FETCH_FUNC(
inifile
)
50
{
51
inifile
*dba = info->dbf;
52
val_type
ini_val;
53
key_type
ini_key;
54
zend_string
*fetched_val =
NULL
;
55
56
if
(!
key
) {
57
php_error_docref
(
NULL
,
E_WARNING
,
"No key specified"
);
58
return
0;
59
}
60
ini_key =
inifile_key_split
(
ZSTR_VAL
(
key
));
/* keylen not needed here */
61
62
ini_val =
inifile_fetch
(dba, &ini_key, skip);
63
inifile_key_free
(&ini_key);
64
if
(ini_val.
value
) {
65
fetched_val = zend_string_init(ini_val.
value
,
strlen
(ini_val.
value
),
/* persistent */
false
);
66
inifile_val_free
(&ini_val);
67
}
68
return
fetched_val;
69
}
70
71
DBA_UPDATE_FUNC(
inifile
)
72
{
73
inifile
*dba = info->dbf;
74
val_type
ini_val;
75
int
res
;
76
key_type
ini_key;
77
78
if
(!
key
) {
79
php_error_docref
(
NULL
,
E_WARNING
,
"No key specified"
);
80
return
0;
81
}
82
ini_key =
inifile_key_split
(
ZSTR_VAL
(
key
));
/* keylen not needed here */
83
84
ini_val.
value
=
ZSTR_VAL
(
val
);
85
86
if
(
mode
== 1) {
87
res
=
inifile_append
(dba, &ini_key, &ini_val);
88
}
else
{
89
res
=
inifile_replace
(dba, &ini_key, &ini_val);
90
}
91
inifile_key_free
(&ini_key);
92
switch
(
res
) {
93
case
-1:
94
// TODO Check when this happens and confirm this can even happen
95
php_error_docref
(
NULL
,
E_WARNING
,
"Operation not possible"
);
96
return
FAILURE
;
97
default
:
98
case
0:
99
return
SUCCESS
;
100
case
1:
101
return
FAILURE
;
102
}
103
}
104
105
DBA_EXISTS_FUNC(
inifile
)
106
{
107
inifile
*dba = info->dbf;
108
val_type
ini_val;
109
key_type
ini_key;
110
111
if
(!
key
) {
112
php_error_docref
(
NULL
,
E_WARNING
,
"No key specified"
);
113
return
0;
114
}
115
ini_key =
inifile_key_split
(
ZSTR_VAL
(
key
));
/* keylen not needed here */
116
117
ini_val =
inifile_fetch
(dba, &ini_key, 0);
118
inifile_key_free
(&ini_key);
119
if
(ini_val.
value
) {
120
inifile_val_free
(&ini_val);
121
return
SUCCESS
;
122
}
123
return
FAILURE
;
124
}
125
126
DBA_DELETE_FUNC(
inifile
)
127
{
128
inifile
*dba = info->dbf;
129
int
res
;
130
bool
found = 0;
131
key_type
ini_key;
132
133
if
(!
key
) {
134
php_error_docref
(
NULL
,
E_WARNING
,
"No key specified"
);
135
return
0;
136
}
137
ini_key =
inifile_key_split
(
ZSTR_VAL
(
key
));
/* keylen not needed here */
138
139
res
=
inifile_delete_ex
(dba, &ini_key, &found);
140
141
inifile_key_free
(&ini_key);
142
return
(
res
== -1 || !found ?
FAILURE
:
SUCCESS
);
143
}
144
145
DBA_FIRSTKEY_FUNC(
inifile
)
146
{
147
inifile
*dba = info->dbf;
148
149
if
(
inifile_firstkey
(dba)) {
150
char
*
result
=
inifile_key_string
(&dba->
curr
.
key
);
151
zend_string
*
key
= zend_string_init(
result
,
strlen
(
result
),
/* persistent */
false
);
152
efree
(
result
);
153
return
key
;
154
}
else
{
155
return
NULL
;
156
}
157
}
158
159
DBA_NEXTKEY_FUNC(
inifile
)
160
{
161
inifile
*dba = info->dbf;
162
163
if
(!dba->
curr
.
key
.
group
&& !dba->
curr
.
key
.
name
) {
164
return
NULL
;
165
}
166
167
if
(
inifile_nextkey
(dba)) {
168
char
*
result
=
inifile_key_string
(&dba->
curr
.
key
);
169
zend_string
*
key
= zend_string_init(
result
,
strlen
(
result
),
/* persistent */
false
);
170
efree
(
result
);
171
return
key
;
172
}
else
{
173
return
NULL
;
174
}
175
}
176
177
DBA_OPTIMIZE_FUNC(
inifile
)
178
{
179
/* dummy */
180
return
SUCCESS
;
181
}
182
183
DBA_SYNC_FUNC(
inifile
)
184
{
185
/* dummy */
186
return
SUCCESS
;
187
}
188
189
DBA_INFO_FUNC(
inifile
)
190
{
191
return
estrdup
(
inifile_version
());
192
}
193
194
#endif
res
zend_string * res
Definition
ffi.c:4692
val
zval * val
Definition
ffi.c:4262
mode
char * mode
Definition
func_interceptors.c:282
NULL
#define NULL
Definition
gdcache.h:45
SUCCESS
#define SUCCESS
Definition
hash_sha3.c:261
inifile_append
int inifile_append(inifile *dba, const key_type *key, const val_type *value)
Definition
inifile.c:586
inifile_free
void inifile_free(inifile *dba, int persistent)
Definition
inifile.c:100
inifile_firstkey
int inifile_firstkey(inifile *dba)
Definition
inifile.c:284
inifile_alloc
inifile * inifile_alloc(php_stream *fp, int readonly, int persistent)
Definition
inifile.c:80
inifile_delete_ex
int inifile_delete_ex(inifile *dba, const key_type *key, bool *found)
Definition
inifile.c:565
inifile_fetch
val_type inifile_fetch(inifile *dba, const key_type *key, int skip)
Definition
inifile.c:241
inifile_key_string
char * inifile_key_string(const key_type *key)
Definition
inifile.c:128
inifile_version
const char * inifile_version(void)
Definition
inifile.c:41
inifile_nextkey
int inifile_nextkey(inifile *dba)
Definition
inifile.c:292
inifile_replace
int inifile_replace(inifile *dba, const key_type *key, const val_type *value)
Definition
inifile.c:572
inifile_key_free
void inifile_key_free(key_type *key)
Definition
inifile.c:48
inifile_val_free
void inifile_val_free(val_type *val)
Definition
inifile.c:61
inifile_key_split
key_type inifile_key_split(const char *group_name)
Definition
inifile.c:111
inifile.h
php_error_docref
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition
main.c:1173
php.h
php_inifile.h
key
unsigned char key[REFLECTION_KEY_LEN]
Definition
php_reflection.c:63
inifile
Definition
inifile.h:35
inifile::curr
line_type curr
Definition
inifile.h:40
key_type
Definition
inifile.h:20
key_type::name
char * name
Definition
inifile.h:22
key_type::group
char * group
Definition
inifile.h:21
line_type::key
key_type key
Definition
inifile.h:30
val_type
Definition
inifile.h:25
val_type::value
char * value
Definition
inifile.h:26
unistd.h
efree
#define efree(ptr)
Definition
zend_alloc.h:155
estrdup
#define estrdup(s)
Definition
zend_alloc.h:164
strlen
strlen(string $string)
Definition
zend_builtin_functions.stub.php:25
E_WARNING
#define E_WARNING
Definition
zend_errors.h:24
zend_string
struct _zend_string zend_string
Definition
zend_map_ptr.h:24
ZSTR_VAL
#define ZSTR_VAL(zstr)
Definition
zend_string.h:68
FAILURE
@ FAILURE
Definition
zend_types.h:61
result
bool result
Definition
zend_vm_def.h:455
ext
dba
dba_inifile.c
Generated on Sat Aug 23 2025 01:46:06 for php-internal-docs by
1.13.2