------------------------------------------------------------------------- RecParseConfigFile -------------------------------------------------------------------------
| 133 | // RecParseConfigFile |
| 134 | //------------------------------------------------------------------------- |
| 135 | int |
| 136 | RecConfigFileParse(const char *path, RecConfigEntryCallback handler) |
| 137 | { |
| 138 | char *fbuf; |
| 139 | int fsize; |
| 140 | |
| 141 | const char *line; |
| 142 | int line_num; |
| 143 | |
| 144 | char *rec_type_str, *name_str, *data_type_str, *data_str; |
| 145 | const char *value_str; |
| 146 | RecT rec_type; |
| 147 | RecDataT data_type; |
| 148 | |
| 149 | Tokenizer line_tok("\r\n"); |
| 150 | tok_iter_state line_tok_state; |
| 151 | |
| 152 | RecDebug(DL_Note, "Reading '%s'", path); |
| 153 | |
| 154 | // watch out, we're altering our g_rec_config_xxx structures |
| 155 | ink_mutex_acquire(&g_rec_config_lock); |
| 156 | |
| 157 | if (RecFileImport_Xmalloc(path, &fbuf, &fsize) == REC_ERR_FAIL) { |
| 158 | RecLog(DL_Warning, "Could not import '%s'", path); |
| 159 | ink_mutex_release(&g_rec_config_lock); |
| 160 | return REC_ERR_FAIL; |
| 161 | } |
| 162 | |
| 163 | line_tok.Initialize(fbuf, SHARE_TOKS | ALLOW_EMPTY_TOKS); |
| 164 | line = line_tok.iterFirst(&line_tok_state); |
| 165 | line_num = 1; |
| 166 | while (line) { |
| 167 | char *lc = ats_strdup(line); |
| 168 | char *lt = lc; |
| 169 | char *ln; |
| 170 | |
| 171 | while (isspace(*lt)) { |
| 172 | lt++; |
| 173 | } |
| 174 | rec_type_str = strtok_r(lt, " \t", &ln); |
| 175 | |
| 176 | // check for blank lines and comments |
| 177 | if ((!rec_type_str) || (rec_type_str && (*rec_type_str == '#'))) { |
| 178 | goto L_done; |
| 179 | } |
| 180 | |
| 181 | name_str = strtok_r(nullptr, " \t", &ln); |
| 182 | data_type_str = strtok_r(nullptr, " \t", &ln); |
| 183 | |
| 184 | // extract the string data (a little bit tricker since it can have spaces) |
| 185 | if (ln) { |
| 186 | // 'ln' will point to either the next token or a bunch of spaces |
| 187 | // if the user didn't supply a value (e.g. 'STRING '). First |
| 188 | // scan past all of the spaces. If we hit a '\0', then we |
| 189 | // know we didn't have a valid value. If not, set 'data_str' to |
| 190 | // the start of the token and scan until we find the end. Once |
| 191 | // the end is found, back-peddle to remove any trailing spaces. |
| 192 | while (isspace(*ln)) { |
no test coverage detected