* Arguments: * preg points to a structure for recording the compiled expression * pattern the pattern to compile * cflags compilation flags * * Returns: 0 on success * various non-zero codes on failure */
| 200 | * various non-zero codes on failure |
| 201 | */ |
| 202 | AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags) |
| 203 | { |
| 204 | #ifdef HAVE_PCRE2 |
| 205 | uint32_t capcount; |
| 206 | size_t erroffset; |
| 207 | #else |
| 208 | const char *errorptr; |
| 209 | int erroffset; |
| 210 | #endif |
| 211 | int errcode = 0; |
| 212 | int options = PCREn(DUPNAMES); |
| 213 | |
| 214 | if ((cflags & AP_REG_NO_DEFAULT) == 0) |
| 215 | cflags |= default_cflags; |
| 216 | |
| 217 | if ((cflags & AP_REG_ICASE) != 0) |
| 218 | options |= PCREn(CASELESS); |
| 219 | if ((cflags & AP_REG_NEWLINE) != 0) |
| 220 | options |= PCREn(MULTILINE); |
| 221 | if ((cflags & AP_REG_DOTALL) != 0) |
| 222 | options |= PCREn(DOTALL); |
| 223 | if ((cflags & AP_REG_DOLLAR_ENDONLY) != 0) |
| 224 | options |= PCREn(DOLLAR_ENDONLY); |
| 225 | |
| 226 | #ifdef HAVE_PCRE2 |
| 227 | preg->re_pcre = pcre2_compile((const unsigned char *)pattern, |
| 228 | PCRE2_ZERO_TERMINATED, options, &errcode, |
| 229 | &erroffset, NULL); |
| 230 | #else |
| 231 | preg->re_pcre = pcre_compile2(pattern, options, &errcode, |
| 232 | &errorptr, &erroffset, NULL); |
| 233 | #endif |
| 234 | |
| 235 | preg->re_erroffset = erroffset; |
| 236 | if (preg->re_pcre == NULL) { |
| 237 | /* Internal ERR21 is "failed to get memory" according to pcreapi(3) */ |
| 238 | if (errcode == 21) |
| 239 | return AP_REG_ESPACE; |
| 240 | return AP_REG_INVARG; |
| 241 | } |
| 242 | |
| 243 | #ifdef HAVE_PCRE2 |
| 244 | pcre2_pattern_info((const pcre2_code *)preg->re_pcre, |
| 245 | PCRE2_INFO_CAPTURECOUNT, &capcount); |
| 246 | preg->re_nsub = capcount; |
| 247 | #else |
| 248 | pcre_fullinfo((const pcre *)preg->re_pcre, NULL, |
| 249 | PCRE_INFO_CAPTURECOUNT, &(preg->re_nsub)); |
| 250 | #endif |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | |
| 255 |
no outgoing calls
no test coverage detected