1 /* Copyright (C) 2005 Red Hat, Inc. */ 2 3 #ifndef _SEMANAGE_PARSE_UTILS_INTERNAL_H_ 4 #define _SEMANAGE_PARSE_UTILS_INTERNAL_H_ 5 6 #include <stdio.h> 7 #include <semanage/handle.h> 8 9 typedef struct parse_info { 10 unsigned int lineno; /* Current line number */ 11 char *orig_line; /* Original copy of the line being parsed */ 12 char *working_copy; /* Working copy of the line being parsed */ 13 char *ptr; /* Current parsing location */ 14 15 const char *filename; /* Input stream file name */ 16 FILE *file_stream; /* Input stream handle */ 17 18 void *parse_arg; /* Caller supplied argument */ 19 } parse_info_t; 20 21 /* Initialize structure */ 22 extern int parse_init(semanage_handle_t * handle, 23 const char *filename, 24 void *parse_arg, parse_info_t ** info); 25 26 /* Release structure */ 27 extern void parse_release(parse_info_t * info); 28 29 /* Open file */ 30 extern int parse_open(semanage_handle_t * handle, parse_info_t * info); 31 32 /* Close file */ 33 extern void parse_close(parse_info_t * info); 34 35 /* Release resources for current line */ 36 extern void parse_dispose_line(parse_info_t * info); 37 38 /* Skip all whitespace and comments */ 39 extern int parse_skip_space(semanage_handle_t * handle, parse_info_t * info); 40 41 /* Throw an error if we're at the EOF */ 42 extern int parse_assert_noeof(semanage_handle_t * handle, parse_info_t * info); 43 44 /* Throw an error if no whitespace follows, 45 * otherwise eat the whitespace */ 46 extern int parse_assert_space(semanage_handle_t * handle, parse_info_t * info); 47 48 /* Throw an error if the specified character 49 * does not follow, otherwise eat that character */ 50 extern int parse_assert_ch(semanage_handle_t * handle, 51 parse_info_t * info, const char ch); 52 53 /* Throw an error if the specified string 54 * does not follow is not found, otherwise 55 * eat the string */ 56 extern int parse_assert_str(semanage_handle_t * handle, 57 parse_info_t * info, const char *assert_str); 58 59 /* Eat the optional character, if found, 60 * or return STATUS_NODATA */ 61 extern int parse_optional_ch(parse_info_t * info, const char ch); 62 63 /* Eat the optional string, if found, 64 * or return STATUS_NODATA */ 65 extern int parse_optional_str(parse_info_t * info, const char *str); 66 67 /* Extract the next integer, and move 68 * the read pointer past it. Stop if 69 * the optional character delim is encountered, 70 * or if whitespace/eof is encountered */ 71 int parse_fetch_int(semanage_handle_t * hgandle, 72 parse_info_t * info, int *num, char delim); 73 74 /* Extract the next string (delimited by 75 * whitespace), and move the read pointer past it. 76 * Stop of the optional character delim is encountered, 77 * or if whitespace/eof is encountered. Fail if the 78 * string is of length 0. */ 79 extern int parse_fetch_string(semanage_handle_t * handle, 80 parse_info_t * info, char **str_ptr, char delim); 81 82 #endif 83