| 6641 | } |
| 6642 | |
| 6643 | static int |
| 6644 | cli_rule_file_process(const char *file_name, |
| 6645 | size_t line_len_max, |
| 6646 | struct table_rule_list **rule_list, |
| 6647 | uint32_t *n_rules, |
| 6648 | uint32_t *line_number, |
| 6649 | char *out, |
| 6650 | size_t out_size) |
| 6651 | { |
| 6652 | struct table_rule_list *list = NULL; |
| 6653 | char *line = NULL; |
| 6654 | FILE *f = NULL; |
| 6655 | uint32_t rule_id = 0, line_id = 0; |
| 6656 | int status = 0; |
| 6657 | |
| 6658 | /* Check input arguments */ |
| 6659 | if ((file_name == NULL) || |
| 6660 | (strlen(file_name) == 0) || |
| 6661 | (line_len_max == 0) || |
| 6662 | (rule_list == NULL) || |
| 6663 | (n_rules == NULL) || |
| 6664 | (line_number == NULL) || |
| 6665 | (out == NULL)) { |
| 6666 | status = -EINVAL; |
| 6667 | goto cli_rule_file_process_free; |
| 6668 | } |
| 6669 | |
| 6670 | /* Memory allocation */ |
| 6671 | list = malloc(sizeof(struct table_rule_list)); |
| 6672 | if (list == NULL) { |
| 6673 | status = -ENOMEM; |
| 6674 | goto cli_rule_file_process_free; |
| 6675 | } |
| 6676 | |
| 6677 | TAILQ_INIT(list); |
| 6678 | |
| 6679 | line = malloc(line_len_max + 1); |
| 6680 | if (line == NULL) { |
| 6681 | status = -ENOMEM; |
| 6682 | goto cli_rule_file_process_free; |
| 6683 | } |
| 6684 | |
| 6685 | /* Open file */ |
| 6686 | f = fopen(file_name, "r"); |
| 6687 | if (f == NULL) { |
| 6688 | status = -EIO; |
| 6689 | goto cli_rule_file_process_free; |
| 6690 | } |
| 6691 | |
| 6692 | /* Read file */ |
| 6693 | for (line_id = 1, rule_id = 0; ; line_id++) { |
| 6694 | char *tokens[CMD_MAX_TOKENS]; |
| 6695 | struct table_rule *rule = NULL; |
| 6696 | uint32_t n_tokens, n_tokens_parsed, t0; |
| 6697 | |
| 6698 | /* Read next line from file. */ |
| 6699 | if (fgets(line, line_len_max + 1, f) == NULL) |
| 6700 | break; |
no test coverage detected