initial import (incomplete)
[project/uci.git] / libuci.h
1 /*
2  * libuci - Library for the Unified Configuration Interface
3  * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
4  *
5  * this program is free software; you can redistribute it and/or modify
6  * it under the terms of the gnu lesser general public license version 2.1
7  * as published by the free software foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #ifndef __LIBUCI_H
16 #define __LIBUCI_H
17
18 #include <setjmp.h>
19 #include <stdio.h>
20
21 enum
22 {
23         UCI_OK = 0,
24         UCI_ERR_MEM,
25         UCI_ERR_INVAL,
26         UCI_ERR_NOTFOUND,
27         UCI_ERR_PARSE,
28         UCI_ERR_UNKNOWN,
29         UCI_ERR_LAST
30 };
31
32 struct uci_config;
33 struct uci_parse_context;
34
35 struct uci_context
36 {
37         struct uci_config *root;
38         
39         /* for error handling only */
40         struct uci_parse_context *pctx;
41
42         /* private: */
43         int errno;
44         jmp_buf trap;
45 };
46
47 struct uci_parse_context
48 {
49         int line;
50         int byte;
51
52         /* private: */
53         FILE *file;
54         char *buf;
55         int bufsz;
56 };
57
58
59 /**
60  * uci_alloc: Allocate a new uci context
61  */
62 extern struct uci_context *uci_alloc(void);
63
64 /**
65  * uci_perror: Print the last uci error that occured
66  * @ctx: uci context
67  * @str: string to print before the error message
68  */ 
69 extern void uci_perror(struct uci_context *ctx, const char *str);
70
71 /**
72  * uci_parse: Parse an uci config file and store it in the uci context
73  *
74  * @ctx: uci context
75  * @name: name of the config file (relative to the config directory)
76  */
77 int uci_parse(struct uci_context *ctx, const char *name);
78
79 /**
80  * uci_cleanup: Clean up after an error
81  *
82  * @ctx: uci context
83  */
84 int uci_cleanup(struct uci_context *ctx);
85
86 #endif