98
void YamlParser::serializeEvents()
99
void YamlParser::serializeEvents() throw(YamlParserException)
100
101
bool done = false;
105
if (!yaml_parser_parse (&parser, &event))
106
throw YamlParserException ("Error while parsing");
108
done = (event.type == YAML_STREAM_END_EVENT);
110
if (eventNumber > PARSER_MAXEVENT)
111
throw YamlParserException ("Reached maximum of event");
113
if (!copyEvent (& (events[eventNumber++]), &event))
114
throw YamlParserException ("Error copying event");
116
yaml_event_delete (&event);
102
yaml_event_t event, copiedEvent;
108
if (!yaml_parser_parse (&parser, &event))
109
throw YamlParserException ("Error while parsing");
111
done = (event.type == YAML_STREAM_END_EVENT);
113
copyEvent (&copiedEvent, &event);
115
events.push_back(copiedEvent);
119
yaml_event_delete (&event);
122
catch(YamlParserException &e) {
122
int YamlParser::copyEvent (yaml_event_t *event_to, yaml_event_t *event_from)
129
void YamlParser::copyEvent (yaml_event_t *event_to, yaml_event_t *event_from) throw(YamlParserException)
125
132
switch (event_from->type) {
126
133
case YAML_STREAM_START_EVENT: {
127
// _debug("YAML_STREAM_START_EVENT");
128
return yaml_stream_start_event_initialize (event_to,
129
event_from->data.stream_start.encoding);
134
if(yaml_stream_start_event_initialize (event_to,
135
event_from->data.stream_start.encoding) == 0) {
136
throw YamlParserException("Error stream start event");
132
141
case YAML_STREAM_END_EVENT: {
133
//_debug("YAML_STREAM_END_EVENT");
134
return yaml_stream_end_event_initialize (event_to);
142
if(yaml_stream_end_event_initialize (event_to) == 0) {
143
throw YamlParserException("Error stream end event");
137
148
case YAML_DOCUMENT_START_EVENT: {
138
// _debug("YAML_DOCUMENT_START_EVENT");
139
return yaml_document_start_event_initialize (event_to,
149
if(yaml_document_start_event_initialize (event_to,
140
150
event_from->data.document_start.version_directive,
141
151
event_from->data.document_start.tag_directives.start,
142
152
event_from->data.document_start.tag_directives.end,
143
event_from->data.document_start.implicit);
153
event_from->data.document_start.implicit) == 0) {
154
throw YamlParserException("Error document start event");
146
159
case YAML_DOCUMENT_END_EVENT: {
147
// _debug("YAML_DOCUMENT_END_EVENT");
148
return yaml_document_end_event_initialize (event_to,
149
event_from->data.document_end.implicit);
160
if(yaml_document_end_event_initialize (event_to,
161
event_from->data.document_end.implicit) == 0) {
162
throw YamlParserException("Error document end event");
151
166
case YAML_ALIAS_EVENT: {
152
// _debug("YAML_ALIAS_EVENT");
153
return yaml_alias_event_initialize (event_to,
154
event_from->data.alias.anchor);
167
if (yaml_alias_event_initialize (event_to,
168
event_from->data.alias.anchor) == 0) {
169
throw YamlParserException("Error alias event initialize");
156
173
case YAML_SCALAR_EVENT: {
157
// _debug("YAML_SCALAR_EVENT");
158
return yaml_scalar_event_initialize (event_to,
159
event_from->data.scalar.anchor,
160
event_from->data.scalar.tag,
161
event_from->data.scalar.value,
162
event_from->data.scalar.length,
163
event_from->data.scalar.plain_implicit,
164
event_from->data.scalar.quoted_implicit,
165
event_from->data.scalar.style);
174
if(yaml_scalar_event_initialize (event_to,
175
event_from->data.scalar.anchor,
176
event_from->data.scalar.tag,
177
event_from->data.scalar.value,
178
event_from->data.scalar.length,
179
event_from->data.scalar.plain_implicit,
180
event_from->data.scalar.quoted_implicit,
181
event_from->data.scalar.style) == 0) {
182
throw YamlParserException("Error scalar event initialize");
167
186
case YAML_SEQUENCE_START_EVENT: {
168
// _debug("YAML_SEQUENCE_START_EVENT");
169
return yaml_sequence_start_event_initialize (event_to,
187
if(yaml_sequence_start_event_initialize (event_to,
170
188
event_from->data.sequence_start.anchor,
171
189
event_from->data.sequence_start.tag,
172
190
event_from->data.sequence_start.implicit,
173
event_from->data.sequence_start.style);
191
event_from->data.sequence_start.style) == 0) {
192
throw YamlParserException("Error sequence start event");
175
196
case YAML_SEQUENCE_END_EVENT: {
176
// _debug("YAML_SEQUENCE_END_EVENT");
177
return yaml_sequence_end_event_initialize (event_to);
197
if(yaml_sequence_end_event_initialize (event_to) == 0) {
198
throw YamlParserException("Error sequence end event");
179
202
case YAML_MAPPING_START_EVENT: {
180
// _debug("YAML_MAPPING_START_EVENT");
181
return yaml_mapping_start_event_initialize (event_to,
203
if(yaml_mapping_start_event_initialize (event_to,
182
204
event_from->data.mapping_start.anchor,
183
205
event_from->data.mapping_start.tag,
184
206
event_from->data.mapping_start.implicit,
185
event_from->data.mapping_start.style);
207
event_from->data.mapping_start.style) == 0) {
208
throw YamlParserException("Error mapping start event");
187
212
case YAML_MAPPING_END_EVENT: {
188
// _debug("YAML_MAPPING_END_EVENT");
189
return yaml_mapping_end_event_initialize (event_to);
213
if(yaml_mapping_end_event_initialize (event_to) == 0) {
214
throw YamlParserException("Error mapping end event");
201
YamlDocument *YamlParser::composeEvents()
224
YamlDocument *YamlParser::composeEvents() throw(YamlParserException)
204
// _debug("YamlParser: Compose Events");
206
if (eventNumber == 0)
207
throw YamlParserException ("No event available");
209
if (events[0].type != YAML_STREAM_START_EVENT)
210
throw YamlParserException ("Parsing does not start with stream start");
227
if (eventNumber == 0)
228
throw YamlParserException ("No event available");
230
if (events[0].type != YAML_STREAM_START_EVENT)
231
throw YamlParserException ("Parsing does not start with stream start");
237
catch(YamlParserException &e) {
219
void YamlParser::processStream ()
245
void YamlParser::processStream () throw(YamlParserException)
222
// _debug("YamlParser: process stream");
224
while ( (eventIndex < eventNumber) && (events[eventIndex].type != YAML_STREAM_END_EVENT)) {
226
if (events[eventIndex].type == YAML_DOCUMENT_START_EVENT)
232
if (events[eventIndex].type != YAML_STREAM_END_EVENT)
233
throw YamlParserException ("Did not found end of stream");
248
while ( (eventIndex < eventNumber) && (events[eventIndex].type != YAML_STREAM_END_EVENT)) {
250
if (events[eventIndex].type == YAML_DOCUMENT_START_EVENT)
256
if (events[eventIndex].type != YAML_STREAM_END_EVENT)
257
throw YamlParserException ("Did not found end of stream");
259
catch(YamlParserException &e) {
237
void YamlParser::processDocument()
264
void YamlParser::processDocument() throw(YamlParserException)
239
// _debug("YamlParser: process document");
241
doc = new YamlDocument();
244
throw YamlParserException ("Not able to create new document");
246
while ( (eventIndex < eventNumber) && (events[eventIndex].type != YAML_DOCUMENT_END_EVENT)) {
248
switch (events[eventIndex].type) {
268
doc = new YamlDocument();
271
throw YamlParserException ("Not able to create new document");
273
while ( (eventIndex < eventNumber) && (events[eventIndex].type != YAML_DOCUMENT_END_EVENT)) {
275
switch (events[eventIndex].type) {
249
276
case YAML_SCALAR_EVENT:
250
processScalar ( (YamlNode *) doc);
277
processScalar ( (YamlNode *) doc);
252
279
case YAML_SEQUENCE_START_EVENT:
253
processSequence ( (YamlNode *) doc);
280
processSequence ( (YamlNode *) doc);
255
282
case YAML_MAPPING_START_EVENT:
256
283
processMapping ( (YamlNode *) doc);
265
if (events[eventIndex].type != YAML_DOCUMENT_END_EVENT)
266
throw YamlParserException ("Did not found end of document");
292
if (events[eventIndex].type != YAML_DOCUMENT_END_EVENT)
293
throw YamlParserException ("Did not found end of document");
296
catch(YamlParserException &e) {
271
void YamlParser::processScalar (YamlNode *topNode)
302
void YamlParser::processScalar (YamlNode *topNode) throw(YamlParserException)
274
// _debug("YamlParser: process scalar");
277
throw YamlParserException ("No container for scalar");
280
snprintf (buffer, 1000, "%s", events[eventIndex].data.scalar.value);
281
// _debug("and the scalar is: %s", buffer);
283
ScalarNode *sclr = new ScalarNode (buffer, topNode);
285
switch (topNode->getType()) {
307
throw YamlParserException ("No container for scalar");
310
snprintf (buffer, 1000, "%s", events[eventIndex].data.scalar.value);
312
ScalarNode *sclr = new ScalarNode (buffer, topNode);
314
switch (topNode->getType()) {
287
316
( (YamlDocument *) (topNode))->addNode (sclr);
435
479
throw YamlParserException ("Unknown type in configuration file, expect a mapping");
487
catch(YamlParserException &e) {
446
void YamlParser::mainNativeDataMapping (MappingNode *map)
494
void YamlParser::mainNativeDataMapping (MappingNode *map) throw(YamlParserException)
450
Mapping::iterator iter = map->getMapping()->begin();
452
Key accounts ("accounts");
453
Key addressbook ("addressbook");
456
Key preferences ("preferences");
457
Key voiplink ("voipPreferences");
458
Key shortcuts ("shortcuts");
460
while (iter != map->getMapping()->end()) {
462
_debug ("Iterating: %s", iter->first.c_str());
464
if (accounts.compare (iter->first) == 0) {
465
_debug ("YamlParser: Adding voip account preferences");
466
accountSequence = (SequenceNode *) (iter->second);
467
} else if (addressbook.compare (iter->first) == 0) {
468
_debug ("YamlParser: Adding addressbook preference");
469
addressbookSequence = (SequenceNode *) (iter->second);
470
} else if (audio.compare (iter->first) == 0) {
471
_debug ("YamlParser: Adding audio preference");
472
audioSequence = (SequenceNode *) (iter->second);
473
} else if (hooks.compare (iter->first) == 0) {
474
_debug ("YamlParser: Adding hooks preference");
475
hooksSequence = (SequenceNode *) (iter->second);
476
} else if (preferences.compare (iter->first) == 0) {
477
_debug ("YamlParser: Adding preference preference");
478
preferenceSequence = (SequenceNode *) (iter->second);
479
} else if (voiplink.compare (iter->first) == 0) {
480
_debug ("YamlParser: Adding voip preference");
481
voiplinkSequence = (SequenceNode *) (iter->second);
482
} else if (shortcuts.compare (iter->first) == 0) {
483
_debug ("YamlParser: Adding shortcut preference");
484
shortcutSequence = (SequenceNode *) (iter->second);
486
throw YamlParserException ("Unknow map key in configuration");
498
Mapping::iterator iter = map->getMapping()->begin();
500
Key accounts ("accounts");
501
Key addressbook ("addressbook");
504
Key preferences ("preferences");
505
Key voiplink ("voipPreferences");
506
Key shortcuts ("shortcuts");
508
while (iter != map->getMapping()->end()) {
510
_debug ("Iterating: %s", iter->first.c_str());
512
if (accounts.compare (iter->first) == 0) {
513
_debug ("YamlParser: Adding voip account preferences");
514
accountSequence = (SequenceNode *) (iter->second);
515
} else if (addressbook.compare (iter->first) == 0) {
516
_debug ("YamlParser: Adding addressbook preference");
517
addressbookSequence = (SequenceNode *) (iter->second);
518
} else if (audio.compare (iter->first) == 0) {
519
_debug ("YamlParser: Adding audio preference");
520
audioSequence = (SequenceNode *) (iter->second);
521
} else if (hooks.compare (iter->first) == 0) {
522
_debug ("YamlParser: Adding hooks preference");
523
hooksSequence = (SequenceNode *) (iter->second);
524
} else if (preferences.compare (iter->first) == 0) {
525
_debug ("YamlParser: Adding preference preference");
526
preferenceSequence = (SequenceNode *) (iter->second);
527
} else if (voiplink.compare (iter->first) == 0) {
528
_debug ("YamlParser: Adding voip preference");
529
voiplinkSequence = (SequenceNode *) (iter->second);
530
} else if (shortcuts.compare (iter->first) == 0) {
531
_debug ("YamlParser: Adding shortcut preference");
532
shortcutSequence = (SequenceNode *) (iter->second);
534
throw YamlParserException ("Unknow map key in configuration");
539
catch(YamlParserException &e) {