2 * Samba Unix/Linux SMB client library
4 * Copyright (C) Gregor Beck 2010
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @brief Parser for registration entries (.reg) files.
22 * A parser is a talloced incarnation of an opaque struct reg_parse.
23 * It is fed with the (.reg) file line by line calling @ref reg_parse_line
24 * and emits output by calling functions from its reg_parse_callback.
26 * @author Gregor Beck <gb@sernet.de>
37 * Protoype for function called on key found.
38 * The usual action to take is delete the key if del==true, open it if
39 * already existing or create a new one.
43 * @param klen number of elements in key
44 * @param del whether to delete the key
46 * @retval >=0 on success
50 typedef int (*reg_parse_callback_key_t
) (void* private_data
,
56 * Protoype for function called on value found.
57 * The usual action to take is set the value of the last opened key.
60 * @param name the values name
61 * @param type the values type
62 * @param data the values value
63 * @param len the number of bytes of data
65 * @retval >=0 on success
67 * @see reg_format_value
69 typedef int (*reg_parse_callback_val_t
) (void* private_data
,
76 * Protoype for function called on value delete found.
77 * Delete value from the last opened key. It is usually no error if
78 * no such value exist.
83 * @retval >=0 on success
85 * @see reg_format_value_delete
87 typedef int (*reg_parse_callback_val_del_t
) (void* private_data
,
92 * Protoype for function called on comment found.
95 * @param line comment with marker removed.
97 * @retval >=0 on success
99 * @see reg_format_comment
101 typedef int (*reg_parse_callback_comment_t
) (void* private_data
,
105 * Type handling the output of a reg_parse object.
106 * It containes the functions to call and an opaque data pointer.
108 typedef struct reg_parse_callback
{
109 reg_parse_callback_key_t key
; /**< Function called on key found */
110 reg_parse_callback_val_t val
; /**< Function called on value found */
111 /** Function called on value delete found */
112 reg_parse_callback_val_del_t val_del
;
113 /** Function called on comment found */
114 reg_parse_callback_comment_t comment
;
115 void* data
; /**< Private data passed to callback function */
116 } reg_parse_callback
;
119 * A Parser for a registration entries (.reg) file.
121 * It may be used as a reg_format_callback, so the following is valid:
123 * reg_format* f = reg_format_new(mem_ctx,
124 * (reg_format_callback)reg_parse_new(mem_ctx, cb, NULL, 0),
129 typedef struct reg_parse reg_parse
;
132 * Create a new reg_parse object.
134 * @param talloc_ctx the talloc parent
135 * @param cb the output handler
136 * @param str_enc the charset of hex encoded strings (REG_MULTI_SZ, REG_EXAND_SZ) if not UTF-16
139 * @return a talloc'ed reg_parse object, NULL on error
141 reg_parse
* reg_parse_new(const void* talloc_ctx
,
142 reg_parse_callback cb
,
147 * Feed one line to the parser.
150 * @param line one line from a (.reg) file, in UNIX charset
152 * @return 0 on success
154 * @see reg_format_callback_writeline_t
156 int reg_parse_line(struct reg_parse
* parser
, const char* line
);
160 * Parse a (.reg) file, read from a file descriptor.
162 * @param fd the file descriptor
163 * @param cb the output handler
166 * @return 0 on success
168 int reg_parse_fd(int fd
,
169 const reg_parse_callback
* cb
,
173 * Parse a (.reg) file
175 * @param filename the file to open
176 * @param cb the output handler
179 * @return 0 on success
181 int reg_parse_file(const char* filename
,
182 const reg_parse_callback
* cb
,
185 int reg_parse_set_options(reg_parse
* parser
, const char* opt
);
187 /******************************************************************************/
190 #endif /* REG_PARSE_H */