| 5396 | } |
| 5397 | |
| 5398 | static int |
| 5399 | parseServiceFile(const char *serviceFile, |
| 5400 | const char *service, |
| 5401 | PQconninfoOption *options, |
| 5402 | PQExpBuffer errorMessage, |
| 5403 | bool *group_found) |
| 5404 | { |
| 5405 | int result = 0, |
| 5406 | linenr = 0, |
| 5407 | i; |
| 5408 | FILE *f; |
| 5409 | char *line; |
| 5410 | char buf[1024]; |
| 5411 | |
| 5412 | *group_found = false; |
| 5413 | |
| 5414 | f = fopen(serviceFile, "r"); |
| 5415 | if (f == NULL) |
| 5416 | { |
| 5417 | appendPQExpBuffer(errorMessage, libpq_gettext("service file \"%s\" not found\n"), |
| 5418 | serviceFile); |
| 5419 | return 1; |
| 5420 | } |
| 5421 | |
| 5422 | while ((line = fgets(buf, sizeof(buf), f)) != NULL) |
| 5423 | { |
| 5424 | int len; |
| 5425 | |
| 5426 | linenr++; |
| 5427 | |
| 5428 | if (strlen(line) >= sizeof(buf) - 1) |
| 5429 | { |
| 5430 | appendPQExpBuffer(errorMessage, |
| 5431 | libpq_gettext("line %d too long in service file \"%s\"\n"), |
| 5432 | linenr, |
| 5433 | serviceFile); |
| 5434 | result = 2; |
| 5435 | goto exit; |
| 5436 | } |
| 5437 | |
| 5438 | /* ignore whitespace at end of line, especially the newline */ |
| 5439 | len = strlen(line); |
| 5440 | while (len > 0 && isspace((unsigned char) line[len - 1])) |
| 5441 | line[--len] = '\0'; |
| 5442 | |
| 5443 | /* ignore leading whitespace too */ |
| 5444 | while (*line && isspace((unsigned char) line[0])) |
| 5445 | line++; |
| 5446 | |
| 5447 | /* ignore comments and empty lines */ |
| 5448 | if (line[0] == '\0' || line[0] == '#') |
| 5449 | continue; |
| 5450 | |
| 5451 | /* Check for right groupname */ |
| 5452 | if (line[0] == '[') |
| 5453 | { |
| 5454 | if (*group_found) |
| 5455 | { |
no test coverage detected