dns: Add support for TXT record to idl file
[Samba/id10ts.git] / source3 / registry / reg_parse.h
blob0694225ef50ea07d16bda9bc23e2cd274c12327e
1 /*
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/>.
20 /**
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.
25 * @file reg_parse.h
26 * @author Gregor Beck <gb@sernet.de>
27 * @date Jun 2010
30 #ifndef REG_PARSE_H
31 #define REG_PARSE_H
33 #include <stdint.h>
34 #include <stdbool.h>
36 /**
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.
41 * @param private_data
42 * @param key
43 * @param klen number of elements in key
44 * @param del whether to delete the key
46 * @retval >=0 on success
48 * @see reg_format_key
50 typedef int (*reg_parse_callback_key_t) (void* private_data,
51 const char* key[],
52 size_t klen,
53 bool del);
55 /**
56 * Protoype for function called on value found.
57 * The usual action to take is set the value of the last opened key.
59 * @param private_data
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,
70 const char* name,
71 uint32_t type,
72 const uint8_t* data,
73 uint32_t len);
75 /**
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.
80 * @param private_data
81 * @param name
83 * @retval >=0 on success
85 * @see reg_format_value_delete
87 typedef int (*reg_parse_callback_val_del_t) (void* private_data,
88 const char* name);
91 /**
92 * Protoype for function called on comment found.
94 * @param private_data
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,
102 const char* line);
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:
122 * @code
123 * reg_format* f = reg_format_new(mem_ctx,
124 * (reg_format_callback)reg_parse_new(mem_ctx, cb, NULL, 0),
125 * NULL, 0, "\\");
126 * @endcode
127 * @see reg_format
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
137 * @param flags
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,
143 const char* str_enc,
144 unsigned flags);
147 * Feed one line to the parser.
149 * @param 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
164 * @param opts
166 * @return 0 on success
168 int reg_parse_fd(int fd,
169 const reg_parse_callback* cb,
170 const char* opts);
173 * Parse a (.reg) file
175 * @param filename the file to open
176 * @param cb the output handler
177 * @param opts
179 * @return 0 on success
181 int reg_parse_file(const char* filename,
182 const reg_parse_callback* cb,
183 const char* opts);
185 int reg_parse_set_options(reg_parse* parser, const char* opt);
187 /******************************************************************************/
190 #endif /* REG_PARSE_H */