1 #ifndef VCARDFAST_H
2 #define VCARDFAST_H
3 
4 #include <stdlib.h>
5 #include "util.h"
6 #include "strarray.h"
7 
8 enum parse_error {
9 PE_OK = 0,
10 PE_BACKQUOTE_EOF,
11 PE_BEGIN_PARAMS,
12 PE_ENTRY_MULTIGROUP,
13 PE_FINISHED_EARLY,
14 PE_KEY_EOF,
15 PE_KEY_EOL,
16 PE_MISMATCHED_CARD,
17 PE_NAME_EOF,
18 PE_NAME_EOL,
19 PE_PARAMVALUE_EOF,
20 PE_PARAMVALUE_EOL,
21 PE_QSTRING_EOF,
22 PE_QSTRING_EOL,
23 PE_QSTRING_COMMA,
24 PE_ILLEGAL_CHAR,
25 PE_NUMERR /* last */
26 };
27 
28 struct vparse_state {
29     struct buf buf;
30     const char *base;
31     const char *itemstart;
32     const char *p;
33     strarray_t *multivalsemi;
34     strarray_t *multivalcomma;
35     strarray_t *multiparam;
36     int barekeys;
37 
38     /* current items */
39     struct vparse_card *card;
40     struct vparse_param *param;
41     struct vparse_entry *entry;
42 };
43 
44 struct vparse_param {
45     char *name;
46     char *value;
47     struct vparse_param *next;
48 };
49 
50 struct vparse_entry {
51     char *group;
52     char *name;
53     char multivaluesep;
54     union {
55         char *value;
56         strarray_t *values;
57     } v;
58     struct vparse_param *params;
59     struct vparse_entry *next;
60 };
61 
62 struct vparse_card {
63     char *type;
64     struct vparse_entry *properties;
65     struct vparse_card *objects;
66     struct vparse_card *next;
67 };
68 
69 struct vparse_errorpos {
70     int startpos;
71     int startline;
72     int startchar;
73     int errorpos;
74     int errorline;
75     int errorchar;
76 };
77 
78 extern int vparse_parse(struct vparse_state *state, int only_one);
79 extern void vparse_free(struct vparse_state *state);
80 extern void vparse_fillpos(struct vparse_state *state, struct vparse_errorpos *pos);
81 extern const char *vparse_errstr(int err);
82 
83 extern void vparse_set_multival(struct vparse_state *state, const char *name, char split);
84 extern void vparse_set_multiparam(struct vparse_state *state, const char *name);
85 
86 extern const char *vparse_stringval(const struct vparse_card *card, const char *name);
87 extern const strarray_t *vparse_multival(const struct vparse_card *card, const char *name);
88 
89 /* editing functions */
90 extern struct vparse_card *vparse_new_card(const char *type);
91 extern void vparse_free_card(struct vparse_card *card);
92 extern void vparse_free_entry(struct vparse_entry *entry);
93 extern void vparse_delete_entries(struct vparse_card *card, const char *group, const char *name);
94 extern struct vparse_entry *vparse_get_entry(struct vparse_card *card, const char *group, const char *name);
95 extern struct vparse_entry *vparse_add_entry(struct vparse_card *card, const char *group, const char *name, const char *value);
96 extern void vparse_replace_entry(struct vparse_card *card, const char *group, const char *name, const char *value);
97 extern void vparse_set_value(struct vparse_entry *entry, const char *value);
98 /* XXX - multivalue should be strarray_t */
99 //extern void vparse_set_multivalue(struct vparse_entry *entry, const strarray_t *values);
100 
101 extern void vparse_delete_params(struct vparse_entry *entry, const char *name);
102 extern struct vparse_param *vparse_get_param(struct vparse_entry *entry, const char *name);
103 extern struct vparse_param *vparse_add_param(struct vparse_entry *entry, const char *name, const char *value);
104 
105 extern void vparse_tobuf(const struct vparse_card *card, struct buf *buf);
106 extern int vparse_restriction_check(struct vparse_card *card);
107 
108 #endif /* VCARDFAST_H */
109 
110