Introduce domain manager
[profile/ivi/genivi/genivi-audio-manager.git] / domain-manager / ini-parser.h
1 /*
2 Copyright (c) 2012, Intel Corporation
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7
8     * Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10
11     * Redistributions in binary form must reproduce the above copyright
12       notice, this list of conditions and the following disclaimer in
13       the documentation and/or other materials provided with the
14       distribution.
15
16     * Neither the name of Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived
18       from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef __MURPHY_PLUGIN_UDEV_INI_PARSER_H__
34 #define __MURPHY_PLUGIN_UDEV_INI_PARSER_H__
35
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <stdbool.h>
40 #include <string.h>
41
42 #include <murphy/common.h>
43
44 #define CHARACTER_BUFFER_SIZE 16384
45 #define MAX_BUFFERS 10
46
47 typedef struct {
48     mrp_list_hook_t hook;
49     char *modifier;
50     char *key;
51     char *value;
52 } ini_parser_keyvaluepair_t;
53
54 typedef struct {
55     mrp_list_hook_t hook;
56
57     char *name;
58     /* list of key-value-pairs */
59     mrp_list_hook_t pairs;
60
61     ini_parser_keyvaluepair_t *current;
62 } ini_parser_section_t;
63
64 typedef struct {
65     /* list of sections */
66     mrp_list_hook_t sections;
67
68     ini_parser_section_t *current;
69 } ini_parser_result_t;
70
71 typedef struct {
72     char *buffers[MAX_BUFFERS];
73     char *current;
74     char *end;
75     int buffer_i;
76     void *user_data;
77     int error;
78     ini_parser_result_t *r;
79 } ini_parser_context_t;
80
81 char *new_parser_str(ini_parser_context_t *ctx, char *input);
82 int initialize_parser_buffer(ini_parser_context_t *ctx);
83 void delete_parser_buffer(ini_parser_context_t *ctx);
84
85 bool mrp_parse_ini_file(const char *filename, ini_parser_result_t *result);
86
87
88 void init_result(ini_parser_result_t *result);
89 void add_section(ini_parser_result_t *result, const char *name);
90 void add_key(ini_parser_result_t *result, const char *key);
91 void add_modifier(ini_parser_result_t *result, const char *modifier);
92 void add_value(ini_parser_result_t *result, const char *value);
93 void deinit_result(ini_parser_result_t *result);
94 void print_result(ini_parser_result_t *result);
95
96 #endif