}
rspamd_regexp_t*
-rspamd_regexp_new (const gchar *pattern, const gchar *flags,
+rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags,
GError **err)
{
- const gchar *start = pattern, *end, *flags_str = NULL;
+ const gchar *start = pattern, *end = start + len, *flags_str = NULL;
gchar *err_str;
rspamd_regexp_t *res;
gboolean explicit_utf = FALSE;
return NULL;
}
- if (flags == NULL) {
+ if (flags == NULL && start < end) {
/* We need to parse pattern and detect flags set */
if (*start == '/') {
sep = '/';
rspamd_flags |= RSPAMD_REGEXP_FLAG_FULL_MATCH;
}
- if (sep == '\0' || g_ascii_isalnum (sep)) {
+ if (g_ascii_isalnum (sep)) {
/* We have no flags, no separators and just use all line as expr */
start = pattern;
- end = start + strlen (pattern);
rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH;
}
else {
- end = strrchr (pattern, sep);
+ end = rspamd_memrchr(pattern, sep, len);
if (end == NULL || end <= start) {
g_set_error (err, rspamd_regexp_quark(), EINVAL,
/* Strictly check all flags */
strict_flags = TRUE;
start = pattern;
- end = pattern + strlen (pattern);
flags_str = flags;
}
#endif
if (flags_str != NULL) {
- while (*flags_str) {
+ while (flags_str < end) {
switch (*flags_str) {
case 'i':
regexp_flags |= PCRE_FLAG(CASELESS);
return res;
}
+rspamd_regexp_t *
+rspamd_regexp_new (const gchar *pattern, const gchar *flags,
+ GError **err)
+{
+ return rspamd_regexp_new_len(pattern, strlen(pattern), flags, err);
+}
+
#ifndef WITH_PCRE2
gboolean
-rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
+rspamd_regexp_search (const rspamd_regexp_t *re, const gchar *text, gsize len,
const gchar **start, const gchar **end, gboolean raw,
GArray *captures)
{
#else
/* PCRE 2 version */
gboolean
-rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
+rspamd_regexp_search (const rspamd_regexp_t *re, const gchar *text, gsize len,
const gchar **start, const gchar **end, gboolean raw,
GArray *captures)
{
#endif
const char*
-rspamd_regexp_get_pattern (rspamd_regexp_t *re)
+rspamd_regexp_get_pattern (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
guint
-rspamd_regexp_get_flags (rspamd_regexp_t *re)
+rspamd_regexp_get_flags (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
guint
-rspamd_regexp_get_pcre_flags (rspamd_regexp_t *re)
+rspamd_regexp_get_pcre_flags (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
gint
-rspamd_regexp_get_nbackrefs (rspamd_regexp_t *re)
+rspamd_regexp_get_nbackrefs (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
gint
-rspamd_regexp_get_ncaptures (rspamd_regexp_t *re)
+rspamd_regexp_get_ncaptures (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
guint
-rspamd_regexp_get_maxhits (rspamd_regexp_t *re)
+rspamd_regexp_get_maxhits (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
guint64
-rspamd_regexp_get_cache_id (rspamd_regexp_t *re)
+rspamd_regexp_get_cache_id (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
gboolean
-rspamd_regexp_match (rspamd_regexp_t *re, const gchar *text, gsize len,
+rspamd_regexp_match (const rspamd_regexp_t *re, const gchar *text, gsize len,
gboolean raw)
{
const gchar *start = NULL, *end = NULL;
g_assert (re != NULL);
g_assert (text != NULL);
- if (len == 0 && text != NULL) {
+ if (len == 0) {
len = strlen (text);
}
}
gpointer
-rspamd_regexp_get_ud (rspamd_regexp_t *re)
+rspamd_regexp_get_ud (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
gpointer
-rspamd_regexp_get_id (rspamd_regexp_t *re)
+rspamd_regexp_get_id (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
}
gpointer
-rspamd_regexp_get_class (rspamd_regexp_t *re)
+rspamd_regexp_get_class (const rspamd_regexp_t *re)
{
g_assert (re != NULL);
rspamd_regexp_t *rspamd_regexp_new (const gchar *pattern, const gchar *flags,
GError **err);
+/**
+ * Create new rspamd regexp
+ * @param pattern regexp pattern
+ * @param flags flags (may be enclosed inside pattern)
+ * @param err error pointer set if compilation failed
+ * @return new regexp object
+ */
+rspamd_regexp_t *rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags,
+ GError **err);
+
/**
* Search the specified regexp in the text
* @param re
* @param captures array of captured strings of type rspamd_fstring_capture or NULL
* @return
*/
-gboolean rspamd_regexp_search (rspamd_regexp_t *re,
+gboolean rspamd_regexp_search (const rspamd_regexp_t *re,
const gchar *text, gsize len,
const gchar **start, const gchar **end, gboolean raw,
GArray *captures);
* @param len
* @return
*/
-gboolean rspamd_regexp_match (rspamd_regexp_t *re,
+gboolean rspamd_regexp_match (const rspamd_regexp_t *re,
const gchar *text, gsize len, gboolean raw);
/**
* @param re regexp object
* @return opaque pointer
*/
-gpointer rspamd_regexp_get_ud (rspamd_regexp_t *re);
+gpointer rspamd_regexp_get_ud (const rspamd_regexp_t *re);
/**
* Get regexp ID suitable for hashing
* @param re
* @return
*/
-gpointer rspamd_regexp_get_id (rspamd_regexp_t *re);
+gpointer rspamd_regexp_get_id (const rspamd_regexp_t *re);
/**
* Get pattern for the specified regexp object
* @param re
* @return
*/
-const char *rspamd_regexp_get_pattern (rspamd_regexp_t *re);
+const char *rspamd_regexp_get_pattern (const rspamd_regexp_t *re);
/**
* Get PCRE flags for the regexp
*/
-guint rspamd_regexp_get_pcre_flags (rspamd_regexp_t *re);
+guint rspamd_regexp_get_pcre_flags (const rspamd_regexp_t *re);
/**
* Get rspamd flags for the regexp
*/
-guint rspamd_regexp_get_flags (rspamd_regexp_t *re);
+guint rspamd_regexp_get_flags (const rspamd_regexp_t *re);
/**
* Set rspamd flags for the regexp
/**
* Set regexp maximum hits
*/
-guint rspamd_regexp_get_maxhits (rspamd_regexp_t *re);
+guint rspamd_regexp_get_maxhits (const rspamd_regexp_t *re);
/**
* Get regexp maximum hits
/**
* Returns number of backreferences in a regexp
*/
-gint rspamd_regexp_get_nbackrefs (rspamd_regexp_t *re);
+gint rspamd_regexp_get_nbackrefs (const rspamd_regexp_t *re);
/**
* Returns number of capture groups in a regexp
*/
-gint rspamd_regexp_get_ncaptures (rspamd_regexp_t *re);
+gint rspamd_regexp_get_ncaptures (const rspamd_regexp_t *re);
/**
* Returns cache id for a regexp
*/
-guint64 rspamd_regexp_get_cache_id (rspamd_regexp_t *re);
+guint64 rspamd_regexp_get_cache_id (const rspamd_regexp_t *re);
/**
* Sets cache id for a regexp
/**
* Get regexp class for the re object
*/
-gpointer rspamd_regexp_get_class (rspamd_regexp_t *re);
+gpointer rspamd_regexp_get_class (const rspamd_regexp_t *re);
/**
* Set regexp class for the re object