/* DEBUG: section 25 MIME Parsing and Internal Icons */
#include "squid.h"
+#include "base/RegexPattern.h"
#include "disk.h"
#include "fde.h"
#include "globals.h"
MEMPROXY_CLASS(MimeEntry);
public:
- explicit MimeEntry(const char *aPattern, const regex_t &compiledPattern,
+ MimeEntry(const char *aPattern, const decltype(RegexPattern::flags) &reFlags,
const char *aContentType,
const char *aContentEncoding, const char *aTransferMode,
bool optionViewEnable, bool optionDownloadEnable,
const char *anIconName);
+ MimeEntry(const MimeEntry &) = delete;
+ MimeEntry(const MimeEntry &&) = delete;
~MimeEntry();
- const char *pattern;
- regex_t compiled_pattern;
+ RegexPattern pattern;
const char *content_type;
const char *content_encoding;
char transfer_mode;
t = NULL;
for (m = MimeTable; m; m = m->next) {
- if (regexec(&m->compiled_pattern, name, 0, 0, 0) == 0)
+ if (m->pattern.match(name))
break;
}
char buf[BUFSIZ];
char chopbuf[BUFSIZ];
char *t;
- char *pattern;
char *icon;
char *type;
char *encoding;
char *option;
int view_option;
int download_option;
- regex_t re;
MimeEntry *m;
- int re_flags = REG_EXTENDED | REG_NOSUB | REG_ICASE;
if (filename == NULL)
return;
mimeFreeMemory();
+ const auto re_flags = std::regex::extended | std::regex::nosubs | std::regex::icase;
+
while (fgets(buf, BUFSIZ, fp)) {
if ((t = strchr(buf, '#')))
*t = '\0';
xstrncpy(chopbuf, buf, BUFSIZ);
+ char *pattern;
if ((pattern = strtok(chopbuf, w_space)) == NULL) {
debugs(25, DBG_IMPORTANT, "mimeInit: parse error: '" << buf << "'");
continue;
debugs(25, DBG_IMPORTANT, "mimeInit: unknown option: '" << buf << "' (" << option << ")");
}
- if (regcomp(&re, pattern, re_flags) != 0) {
- debugs(25, DBG_IMPORTANT, "mimeInit: regcomp error: '" << buf << "'");
+ try {
+ m = new MimeEntry(pattern, re_flags, type, encoding, mode, view_option, download_option, icon);
+
+ } catch (std::regex_error &e) {
+ debugs(25, DBG_IMPORTANT, "mimeInit: invalid regular expression: '" << buf << "'");
continue;
}
- m = new MimeEntry(pattern,re,type,encoding,mode,view_option,
- download_option,icon);
-
*MimeTableTail = m;
MimeTableTail = &m->next;
MimeEntry::~MimeEntry()
{
- xfree(pattern);
xfree(content_type);
xfree(content_encoding);
- regfree(&compiled_pattern);
}
-MimeEntry::MimeEntry(const char *aPattern, const regex_t &compiledPattern,
+MimeEntry::MimeEntry(const char *aPattern, const decltype(RegexPattern::flags) &reFlags,
const char *aContentType, const char *aContentEncoding,
const char *aTransferMode, bool optionViewEnable,
bool optionDownloadEnable, const char *anIconName) :
- pattern(xstrdup(aPattern)),
- compiled_pattern(compiledPattern),
+ pattern(reFlags, aPattern),
content_type(xstrdup(aContentType)),
content_encoding(xstrdup(aContentEncoding)),
view_option(optionViewEnable),
download_option(optionDownloadEnable),
- theIcon(anIconName), next(NULL)
+ theIcon(anIconName),
+ next(nullptr)
{
if (!strcasecmp(aTransferMode, "ascii"))
transfer_mode = 'A';