s3-registry: add support for registration entries (.reg) files
[obnox/samba-ctdb.git] / source3 / registry / reg_parse_internal.h
1 /* Samba Unix/Linux SMB client library
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 /**
18  * @brief  Some stuff used by reg_parse and reg_format.
19  * It might be usefull elsewehre but need some review of the interfaces.
20  * @file   reg_parse_internal.h
21  * @author Gregor Beck <gb@sernet.de>
22  * @date   Sep 2010
23  */
24 #ifndef __REG_PARSE_INTERNAL_H
25 #define __REG_PARSE_INTERNAL_H
26
27 #include "includes.h"
28
29 struct cbuf;
30
31 #define USE_NATIVE_ICONV
32 #ifdef USE_NATIVE_ICONV
33 #  define smb_iconv_t     iconv_t
34 #  define smb_iconv(CD, IPTR, ILEN, OPTR, OLEN) \
35         iconv(CD, (char**)(IPTR), ILEN, OPTR, OLEN)
36 #  define smb_iconv_open  iconv_open
37 #  define smb_iconv_close iconv_close
38 #endif
39
40 size_t iconvert_talloc(const void* ctx,
41                        smb_iconv_t cd,
42                        const char* src, size_t srclen,
43                        char** pdst);
44
45 struct hive_info {
46         uint32_t handle;
47         const char* short_name;
48         size_t short_name_len;
49         const char* long_name;
50         size_t long_name_len;
51 };
52
53 const struct hive_info* hive_info(const char* name, int nlen);
54
55 const char* get_charset(const char* c);
56
57 bool set_iconv(smb_iconv_t* t, const char* to, const char* from);
58
59 /**
60  * Parse option string
61  * @param[in,out] ptr parse position
62  * @param[in] mem_ctx talloc context
63  * @param[out] name ptr 2 value
64  * @param[out] value ptr 2 value
65  * @return true on success
66  */
67 bool srprs_option(const char** ptr, const void* mem_ctx, char** name, char** value);
68
69 /**
70  * Write Byte Order Mark for \p charset to file.
71  * If \c charset==NULL write BOM for \p ctype.
72  *
73  * @param[in] file file to write to
74  * @param[in] charset
75  * @param[in] ctype
76  *
77  * @return number of bytes written, -1 on error
78  * @todo write to cbuf
79  */
80 int write_bom(FILE* file, const char* charset, charset_t ctype);
81
82 /**
83  * Parse Byte Order Mark.
84  *
85  * @param[in,out] ptr parse position
86  * @param[out] name name of characterset
87  * @param[out] ctype charset_t
88  *
89  * @return true if found
90  * @ingroup parse bom
91  */
92 bool srprs_bom(const char** ptr, const char** name, charset_t* ctype);
93
94 enum fmt_case {
95         FMT_CASE_PRESERVE=0,
96         FMT_CASE_UPPER,
97         FMT_CASE_LOWER,
98         FMT_CASE_TITLE
99 };
100 int cbuf_puts_case(struct cbuf* s, const char* str, size_t len, enum fmt_case fmt);
101
102 #endif /* __REG_PARSE_INTERNAL_H */