]> begriffs open source - sa-parse/blob - src/ical_parser.h
ical parser
[sa-parse] / src / ical_parser.h
1 #ifndef ICAL_PARSER_H
2 #define ICAL_PARSER_H
3
4 #include <stddef.h>
5 #include <stdio.h>
6 #include <stdbool.h>
7
8 /* Include collection library headers */
9 #include <derp/common.h>
10 #include <derp/vector.h>
11
12 /* Forward declarations */
13 typedef struct ical_parser ical_parser_t;
14 typedef struct ical_property ical_property_t;
15 typedef struct ical_parameter ical_parameter_t;
16 typedef struct ical_component ical_component_t;
17
18 /* Error codes */
19 typedef enum {
20     ICAL_SUCCESS = 0,
21     ICAL_ERROR_MEMORY = -1,
22     ICAL_ERROR_PARSE = -2,
23     ICAL_ERROR_INVALID_PARAMETER = -3,
24     ICAL_ERROR_IO = -4
25 } ical_error_t;
26
27 /* Error information structure */
28 typedef struct {
29     const char *message;        /* Error message (valid until next parse operation) */
30     int line;                   /* Line number where error occurred (1-based, 0 if unknown) */
31     int column;                 /* Column number where error occurred (1-based, 0 if unknown) */
32     bool has_location;          /* Whether line/column information is available */
33 } ical_error_info_t;
34
35 /* iCalendar parameter structure */
36 struct ical_parameter {
37     char *name;                 /* Parameter name (uppercase) */
38     char *value;                /* Parameter value */
39 };
40
41 /* iCalendar property structure */
42 struct ical_property {
43     char *name;                 /* Property name (uppercase) */
44     vector *parameters;         /* Vector of ical_parameter_t* */
45     char *value;                /* Property value */
46 };
47
48 /* iCalendar component structure */
49 struct ical_component {
50     char *type;                 /* Component type (uppercase, e.g., "VCALENDAR", "VEVENT") */
51     vector *properties;         /* Vector of ical_property_t* */
52     vector *subcomponents;      /* Vector of ical_component_t* (nested components) */
53 };
54
55 /* Parser (opaque, stateful - maintains error state between operations) */
56 struct ical_parser;
57
58 /**
59  * Create a new iCalendar parser
60  * @note Parser maintains error state; create separate parsers for concurrent use
61  */
62 ical_parser_t *ical_parser_create(void);
63
64 /**
65  * Free an iCalendar parser and all associated memory
66  */
67 void ical_parser_destroy(ical_parser_t *parser);
68
69 /**
70  * Parse iCalendar data from a string
71  * @note Sets *calendar to NULL on failure
72  * @return ical_component_t* representing the VCALENDAR on success, NULL on failure
73  */
74 ical_error_t ical_parser_parse_string(ical_parser_t *parser, const char *input, ical_component_t **calendar);
75
76 /**
77  * Parse iCalendar data from a file
78  * @note Sets *calendar to NULL on failure
79  * @note Advances file position to end of parsed content
80  * @return ical_component_t* representing the VCALENDAR on success, NULL on failure
81  */
82 ical_error_t ical_parser_parse_file(ical_parser_t *parser, FILE *file, ical_component_t **calendar);
83
84 /**
85  * Get detailed error information from the parser
86  * @note Message pointer is valid until the next parse operation
87  */
88 ical_error_info_t ical_parser_get_error_info(ical_parser_t *parser);
89
90 /**
91  * Convert error code to human-readable string
92  */
93 const char *ical_error_string(ical_error_t error);
94
95 /**
96  * Free an iCalendar component and all its associated memory
97  */
98 void ical_component_free(ical_component_t *component);
99
100 /**
101  * Free an iCalendar property and all its associated memory
102  */
103 void ical_property_free(ical_property_t *property);
104
105 /**
106  * Free an iCalendar parameter and all its associated memory
107  */
108 void ical_parameter_free(ical_parameter_t *parameter);
109
110 #endif /* ICAL_PARSER_H */