| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
#include <stdio.h> |
| 24 |
|
| 25 |
#include <libintl.h> |
| 26 |
#define _(String) gettext (String) |
| 27 |
|
| 28 |
#include "trace.h" |
| 29 |
#include "collection.h" |
| 30 |
#include "collection_tools.h" |
| 31 |
#include "ini_defines.h" |
| 32 |
#include "ini_configobj.h" |
| 33 |
#include "ini_config_priv.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void print_config_parsing_errors(FILE *file, |
| 41 |
struct collection_item *error_set); |
| 42 |
|
| 43 |
|
| 44 |
void print_file_parsing_errors(FILE *file, |
| 45 |
struct collection_item *error_list); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#define COL_CLASS_INI_PESET COL_CLASS_INI_BASE + 3 |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
#define COL_CLASS_INI_GERROR COL_CLASS_INI_BASE + 5 |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
#define COL_CLASS_INI_VERROR COL_CLASS_INI_BASE + 6 |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
#define ERR_MAXGRAMMAR 0 |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
#define ERR_MAXVALID 0 |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
#ifdef HAVE_VALIDATION |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#define COL_CLASS_INI_LINES COL_CLASS_INI_BASE + 7 |
| 115 |
|
| 116 |
#endif |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
static const char *parsing_error_str(int parsing_error) |
| 122 |
{ |
| 123 |
const char *placeholder= _("Unknown pasing error."); |
| 124 |
const char *str_error[] = { _("Data is too long."), |
| 125 |
_("No closing bracket."), |
| 126 |
_("Section name is missing."), |
| 127 |
_("Section name is too long."), |
| 128 |
_("Equal sign is missing."), |
| 129 |
_("Property name is missing."), |
| 130 |
_("Property name is too long."), |
| 131 |
_("Failed to read line."), |
| 132 |
_("Invalid space character at the " |
| 133 |
"beginning of the line."), |
| 134 |
_("Duplicate key is not allowed."), |
| 135 |
_("Duplicate key is detected while " |
| 136 |
"merging sections."), |
| 137 |
_("Duplicate section is not allowed."), |
| 138 |
_("Invalid character at the " |
| 139 |
"beginning of the line."), |
| 140 |
_("Invalid tab character at the " |
| 141 |
"beginning of the line."), |
| 142 |
_("Incomplete comment at the " |
| 143 |
"end of the file.") |
| 144 |
}; |
| 145 |
|
| 146 |
|
| 147 |
if ((parsing_error < 1) || (parsing_error > ERR_MAXPARSE)) |
| 148 |
return placeholder; |
| 149 |
else |
| 150 |
return str_error[parsing_error-1]; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
static const char *grammar_error_str(int grammar_error) |
| 175 |
{ |
| 176 |
const char *placeholder= _("Unknown grammar error."); |
| 177 |
|
| 178 |
const char *str_error[] = { _(""), |
| 179 |
_(""), |
| 180 |
_(""), |
| 181 |
_(""), |
| 182 |
_(""), |
| 183 |
_(""), |
| 184 |
_("") |
| 185 |
}; |
| 186 |
|
| 187 |
|
| 188 |
if ((grammar_error < 1) || (grammar_error > ERR_MAXGRAMMAR)) |
| 189 |
return placeholder; |
| 190 |
else |
| 191 |
return str_error[grammar_error-1]; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
static const char *validation_error_str(int validation_error) |
| 216 |
{ |
| 217 |
const char *placeholder= _("Unknown validation error."); |
| 218 |
|
| 219 |
const char *str_error[] = { _(""), |
| 220 |
_(""), |
| 221 |
_(""), |
| 222 |
_(""), |
| 223 |
_(""), |
| 224 |
_(""), |
| 225 |
_("") |
| 226 |
}; |
| 227 |
|
| 228 |
|
| 229 |
if ((validation_error < 1) || (validation_error > ERR_MAXVALID)) |
| 230 |
return placeholder; |
| 231 |
else |
| 232 |
return str_error[validation_error-1]; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
const char *ini_get_error_str(int error, int family) |
| 237 |
{ |
| 238 |
const char *val; |
| 239 |
TRACE_FLOW_ENTRY(); |
| 240 |
|
| 241 |
switch(family) { |
| 242 |
case INI_FAMILY_PARSING: |
| 243 |
val = parsing_error_str(error); |
| 244 |
break; |
| 245 |
case INI_FAMILY_VALIDATION: |
| 246 |
val = validation_error_str(error); |
| 247 |
break; |
| 248 |
case INI_FAMILY_GRAMMAR: |
| 249 |
val = grammar_error_str(error); |
| 250 |
break; |
| 251 |
default: |
| 252 |
val = _("Unknown error category."); |
| 253 |
break; |
| 254 |
} |
| 255 |
|
| 256 |
TRACE_FLOW_EXIT(); |
| 257 |
return val; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
static void print_error_list(FILE *file, |
| 262 |
struct collection_item *error_list, |
| 263 |
int cclass, |
| 264 |
char *wrong_col_error, |
| 265 |
char *failed_to_process, |
| 266 |
char *error_header, |
| 267 |
char *line_format, |
| 268 |
int family) |
| 269 |
{ |
| 270 |
struct collection_iterator *iterator; |
| 271 |
int error; |
| 272 |
struct collection_item *item = NULL; |
| 273 |
struct ini_parse_error *pe; |
| 274 |
unsigned int count; |
| 275 |
|
| 276 |
TRACE_FLOW_STRING("print_error_list", "Entry"); |
| 277 |
|
| 278 |
|
| 279 |
if (error_list == NULL) { |
| 280 |
TRACE_ERROR_STRING("No error list",""); |
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
if (!col_is_of_class(error_list, cclass)) { |
| 286 |
TRACE_ERROR_STRING("Wrong collection class:", wrong_col_error); |
| 287 |
fprintf(file,"%s\n", wrong_col_error); |
| 288 |
return; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
error = col_bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); |
| 293 |
if (error) { |
| 294 |
TRACE_ERROR_STRING("Error (bind):", failed_to_process); |
| 295 |
fprintf(file, "%s\n", failed_to_process); |
| 296 |
return; |
| 297 |
} |
| 298 |
|
| 299 |
while(1) { |
| 300 |
|
| 301 |
error = col_iterate_collection(iterator, &item); |
| 302 |
if (error) { |
| 303 |
TRACE_ERROR_STRING("Error (iterate):", failed_to_process); |
| 304 |
fprintf(file, "%s\n", failed_to_process); |
| 305 |
col_unbind_iterator(iterator); |
| 306 |
return; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
if (item == NULL) break; |
| 311 |
|
| 312 |
|
| 313 |
if (col_get_item_type(item) == COL_TYPE_COLLECTION) { |
| 314 |
col_get_collection_count(item, &count); |
| 315 |
if (count <= 2) break; |
| 316 |
} else if (col_get_item_type(item) == COL_TYPE_STRING) { |
| 317 |
fprintf(file, error_header, (char *)col_get_item_data(item)); |
| 318 |
} |
| 319 |
else { |
| 320 |
|
| 321 |
pe = (struct ini_parse_error *)(col_get_item_data(item)); |
| 322 |
fprintf(file, line_format, |
| 323 |
col_get_item_property(item, NULL), |
| 324 |
pe->error, |
| 325 |
pe->line, |
| 326 |
ini_get_error_str(pe->error, |
| 327 |
family)); |
| 328 |
} |
| 329 |
|
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
col_unbind_iterator(iterator); |
| 334 |
|
| 335 |
TRACE_FLOW_STRING("print_error_list", "Exit"); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
void print_file_parsing_errors(FILE *file, |
| 340 |
struct collection_item *error_list) |
| 341 |
{ |
| 342 |
print_error_list(file, |
| 343 |
error_list, |
| 344 |
COL_CLASS_INI_PERROR, |
| 345 |
WRONG_COLLECTION, |
| 346 |
FAILED_TO_PROCCESS, |
| 347 |
ERROR_HEADER, |
| 348 |
LINE_FORMAT, |
| 349 |
INI_FAMILY_PARSING); |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
void print_grammar_errors(FILE *file, |
| 354 |
struct collection_item *error_list); |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
void print_grammar_errors(FILE *file, |
| 372 |
struct collection_item *error_list) |
| 373 |
{ |
| 374 |
print_error_list(file, |
| 375 |
error_list, |
| 376 |
COL_CLASS_INI_GERROR, |
| 377 |
WRONG_GRAMMAR, |
| 378 |
FAILED_TO_PROC_G, |
| 379 |
ERROR_HEADER_G, |
| 380 |
LINE_FORMAT, |
| 381 |
INI_FAMILY_GRAMMAR); |
| 382 |
} |
| 383 |
|
| 384 |
void print_validation_errors(FILE *file, |
| 385 |
struct collection_item *error_list); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
void print_validation_errors(FILE *file, |
| 403 |
struct collection_item *error_list) |
| 404 |
{ |
| 405 |
print_error_list(file, |
| 406 |
error_list, |
| 407 |
COL_CLASS_INI_VERROR, |
| 408 |
WRONG_VALIDATION, |
| 409 |
FAILED_TO_PROC_V, |
| 410 |
ERROR_HEADER_V, |
| 411 |
LINE_FORMAT, |
| 412 |
INI_FAMILY_VALIDATION); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
void print_config_parsing_errors(FILE *file, |
| 418 |
struct collection_item *error_list) |
| 419 |
{ |
| 420 |
struct collection_iterator *iterator; |
| 421 |
int error; |
| 422 |
struct collection_item *item = NULL; |
| 423 |
struct collection_item *file_errors = NULL; |
| 424 |
|
| 425 |
TRACE_FLOW_STRING("print_config_parsing_errors", "Entry"); |
| 426 |
|
| 427 |
|
| 428 |
if (error_list == NULL) { |
| 429 |
TRACE_ERROR_STRING("No error list", ""); |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
if (!col_is_of_class(error_list, COL_CLASS_INI_PESET)) { |
| 435 |
TRACE_ERROR_STRING("Wrong collection class:", WRONG_COLLECTION); |
| 436 |
fprintf(file, "%s\n", WRONG_COLLECTION); |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
error = col_bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); |
| 442 |
if (error) { |
| 443 |
TRACE_ERROR_STRING("Error (bind):", FAILED_TO_PROCCESS); |
| 444 |
fprintf(file,"%s\n", FAILED_TO_PROCCESS); |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
while(1) { |
| 449 |
|
| 450 |
error = col_iterate_collection(iterator, &item); |
| 451 |
if (error) { |
| 452 |
TRACE_ERROR_STRING("Error (iterate):", FAILED_TO_PROCCESS); |
| 453 |
fprintf(file, "%s\n", FAILED_TO_PROCCESS); |
| 454 |
col_unbind_iterator(iterator); |
| 455 |
return; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
if (item == NULL) break; |
| 460 |
|
| 461 |
|
| 462 |
if (col_get_item_type(item) == COL_TYPE_COLLECTIONREF) { |
| 463 |
|
| 464 |
error = col_get_reference_from_item(item, &file_errors); |
| 465 |
if (error) { |
| 466 |
TRACE_ERROR_STRING("Error (extract):", FAILED_TO_PROCCESS); |
| 467 |
fprintf(file, "%s\n", FAILED_TO_PROCCESS); |
| 468 |
col_unbind_iterator(iterator); |
| 469 |
return; |
| 470 |
} |
| 471 |
print_file_parsing_errors(file, file_errors); |
| 472 |
col_destroy_collection(file_errors); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
col_unbind_iterator(iterator); |
| 478 |
|
| 479 |
TRACE_FLOW_STRING("print_config_parsing_errors", "Exit"); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
void ini_config_print_errors(FILE *file, char **error_list) |
| 484 |
{ |
| 485 |
unsigned count = 0; |
| 486 |
|
| 487 |
TRACE_FLOW_ENTRY(); |
| 488 |
|
| 489 |
if (!error_list) { |
| 490 |
TRACE_FLOW_STRING("List is empty.", ""); |
| 491 |
return; |
| 492 |
} |
| 493 |
|
| 494 |
while (error_list[count]) { |
| 495 |
fprintf(file, "%s\n", error_list[count]); |
| 496 |
count++; |
| 497 |
} |
| 498 |
|
| 499 |
TRACE_FLOW_EXIT(); |
| 500 |
return; |
| 501 |
} |