This repository has been archived by the owner on Mar 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
augeas.vapi
262 lines (246 loc) · 9.38 KB
/
augeas.vapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* augeas.vapi
*
* Copyright (C) 2010-2011 Fabian Deutsch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Fabian Deutsch <[email protected]>
*/
/**
* A configuration file editing tool
*
* Augeas parses a configuration file in its native format using a "lens" and
* transforms it into a tree. Configuration changes are made by manipulating
* this tree and saving it back into the native configuration file.
*
* * ''Home'': [[http://augeas.net/]]
* * ''C-Documentation'': [[http://augeas.net/docs/references/c_api/files/augeas-h.html]]
*
* == Loading a Configuration File into the Tree ==
*
* The following example uses a //hosts// file. A hosts file maps network host
* names to Internet Protocol (IP) addresses. For Unix systems this is usually
* located at /etc/hosts
* {{{
* void main () {
* var tree = new Augeas.Tree ();
* tree.transform ("hosts", "/etc/hosts");
* tree.load ();
* tree.print ();
* }
* }}}
* The example creates an instance of Augeas.Tree and then adds a transform to
* the tree using the "hosts" lens for the file "/etc/hosts". A tree can
* have many transforms. There are also many lenses available for parsing
* different types of configuration files. The Augeas website has a list of
* [[http://augeas.net/stock_lenses.html|stock lenses]].
*
* The configuration file is then loaded in to the tree using the specified
* lens. The print () call shows how the tree is structured with the
* transformed configuration file.
*/
[CCode (cheader_filename = "augeas.h")]
namespace Augeas {
/**
* Flags to influence the behaviour of Augeas
*/
[Flags]
[CCode (cprefix = "AUG_")]
public enum InitFlags {
NONE,
/**
* Preserve originals of modified files with extension '.augsave'
*/
SAVE_BACKUP,
/**
* Save changes into a new file with extension '.augnew'
*
* Does not overwrite the original file
* and takes precedence over SAVE_BACKUP
*/
SAVE_NEWFILE,
/**
* Type check lenses
*
* Since it can be an expensive operation this is not done by default
*/
TYPE_CHECK,
/**
* Do not search the built in default directories for lenses
*/
NO_STDINC,
/**
* Make save a no-op process, just show what would have changed
*/
SAVE_NOOP,
/**
* Do not automatically load files associated with lenses on start up
*/
NO_LOAD,
/**
* Do not automatically load all lenses found in the search paths on start up
*/
NO_MODL_AUTOLOAD,
/**
* Load span positions for nodes related to a file
*/
ENABLE_SPAN,
/**
* Do not automatically close when encountering an error during start up
*/
NO_ERR_CLOSE,
/**
* Output a message when a lens is loaded, used by 'augparse --trace'
*/
TRACE_MODULE_LOADING
}
[CCode (cprefix= "AUG_")]
public enum ErrorCode
{
NOERROR,
ENOMEM,
EINTERNAL,
EPATHX,
ENOMATCH,
EMMATCH,
ESYNTAX,
ENOLENS,
EMXFM
}
[Compact]
[CCode (cname = "augeas", cprefix = "aug_", free_function = "aug_close")]
public class Tree {
/**
* Initialize the library.
*
* The Vala binding uses InitFlags.NO_MOD_AUTOLOAD as the default flag to make
* a quick initialization of the library. Otherwise the library can take several
* seconds to initialize because it will load all lenses and any corresponding
* files marked for auto-loading. With InitFlags.NO_MOD_AUTOLOAD
* //transform ()// and //load ()// need to be used to identify the lens and
* configuration file to load.
*
* @param root the filesystem root. If ROOT is NULL, use the value
* of the environment variable AUGEAS_ROOT. If that doesn’t exist, use "/".
* @param loadpath a colon-separated list of directories that modules should
* be searched in. This is in addition to the standard load path and the
* directories in AUGEAS_LENS_LIB
* @param flags a bitmask made up of values from InitFlags. The flag
* InitFlags.NO_ERR_CLOSE can be used to get more information on why
* initialization failed. If it is set in flags, the caller must check that
* //error ()// returns ErrorCode.NOERROR before using the returned augeas
* handle for any other operation. If the handle reports any error, the caller
* should only call the //error// functions and //close ()// on this handle.
* @return a handle to the Augeas tree upon success. If initialization fails,
* returns NULL if InitFlags.NO_ERR_CLOSE is not set in //flags//. If
* InitFlags.NO_ERR_CLOSE is set, might return an Augeas handle even on
* failure. In that case, caller must check for errors using //error ()//, and,
* if an error is reported, only use the handle with the //error// functions
* and //close ()//.
*/
[CCode (cname = "aug_init")]
public Tree (string? root = null, string? loadpath = null, InitFlags flags = InitFlags.NO_MODL_AUTOLOAD);
public int defvar (string name, string? expr);
public int defnode (string name, string expr, string val, out int created);
public int get (string path, out unowned string? val);
public int set (string path, string val);
public int setm (string base, string sub, string val);
public int insert (string path, string label, bool before);
public int rm (string path);
public int mv (string src, string dst);
[CCode (cname = "aug_match")]
int _match(string p, [CCode (array_length = false)] out string[]? matches);
[CCode (cname = "vala_aug_match")]
public string[]? match (string path)
{
string[] matches;
int len = _match (path, out matches);
if( matches != null ) matches.length = len;
return matches;
}
public int save ();
/**
* Load files into the tree.
*
* Which files to load and which lenses to use on them is specified under
* /augeas/load in the tree. Each entry /augeas/load/NAME specifies a
* "transform", having exactly one child "lens" and any number of children
* labelled //incl// and //excl//. The value of NAME has no meaning.
*
* The //lens// grandchild of /augeas/load specifies which lens to use, and can
* either be the fully qualified name of a lens 'module.lns' or 'module'.
* The latter form means that the lens from the transform marked for
* autoloading in MODULE should be used.
*
* The //incl// and //excl// grandchildren of /augeas/load indicate which files
* to transform. Their value are used as glob patterns. Any file that matches
* at least one 'incl' pattern and no 'excl' pattern is transformed. The order
* of //incl// and //excl// entries is irrelevant.
*
* Before loading any files, //load ()// will remove everything underneath
* /augeas/files and /files, regardless of whether any entries have been
* modified or not.
*
* @return 0 on success, -1 on error. Note that success includes the case
* where some files could not be loaded. Details of such files can be found
* under /augeas/ /error
*/
public int load ();
#if POSIX
public int print (string path = "/*", [CCode (pos = 0.5)] Posix.FILE output = Posix.stdout);
public int srun (string command = "help", [CCode (pos = 0.5)] Posix.FILE output = Posix.stdout);
#else
/**
* Print each node matching //path// and its descendants to //output//.
*
* @param path path expression, default is all nodes "/*"
* @param output file to send output to, default is STDOUT
* @return 0 on success, or a negative value on failure
*/
public int print (string path = "/*", [CCode (pos = 0.5)] GLib.FileStream output = GLib.stdout);
/**
* Run one or more newline separated commands.
*
* The output of the commands will be printed to //output//. Running just 'help'
* will print the available commands. Commands accepted by this are identical
* to those augtool accepts.
* @param command one or more newline separated commands, default is 'help'
* @param output file to send output to, default is STDOUT
* @return the number of executed commands on success, -1 on failure, and -2
* if a 'quit' command was encountered
*/
public int srun (string command = "help", [CCode (pos = 0.5)] GLib.FileStream output = GLib.stdout);
#endif
public void close ();
public int to_xml (string path, out Xml.Node doc, uint flags = 0);
/**
* Add a transform using //lens// for //file//.
*
* //excl// specifies if the file is to be included (0) or excluded (1) from
* the lens. The lens may be a module name or a full lens name. If a module
* name is given, then lns will be the lens assumed.
* @param lens lens name
* @param file file to transform
* @param excl include file if 0, exclude file if 1
* @return 1 on success, -1 on failure
*/
public int transform (string lens, string file, int excl = 0);
public ErrorCode error ();
public string error_message ();
public string error_minor_message ();
public string error_details ();
}
}