コード例 #1
0
static int regexp_compile(lua_State *L) {
  const char *pattern = luaL_checkstring(L, 1);
  int options = luaL_optint(L, 2, 0) | PCRE_UTF8;
  int study_options_type = lua_type(L, 3);
  int study_options;
  if (study_options_type != LUA_TNIL) {
    study_options = luaL_optint(L, 3, PCRE_STUDY_JIT_COMPILE);
  }
  int err_code;
  const char *err_text;
  int err_offset;

  cs_regexp_t *regexp = lua_newuserdata(L, sizeof(cs_regexp_t));
  memset(regexp, 0, sizeof(cs_regexp_t));
  luaL_getmetatable(L, RE_MTBL_NAME);
  lua_setmetatable(L, -2);

  regexp->re = pcre_compile2(pattern, options, &err_code, &err_text,
      &err_offset, NULL);
  if (!regexp->re)
    return luaL_error(L, "%s (pattern offset: %d)", err_text, err_offset + 1);

  if (study_options_type != LUA_TNIL) {
    regexp->extra = pcre_study(regexp->re, study_options, &err_text);
    if (err_text)
      return luaL_error(L, "%s", err_text);
  }

  pcre_fullinfo(regexp->re, regexp->extra, PCRE_INFO_CAPTURECOUNT,
      &regexp->capture_cnt);

  return 1;
}
コード例 #2
0
ファイル: edi.c プロジェクト: varphone/appweb-4
int ediAddValidation(Edi *edi, cchar *name, cchar *tableName, cchar *columnName, cvoid *data)
{
    EdiService          *es;
    EdiValidation       *vp; 
    cchar               *errMsg;
    int                 column;

    es = MPR->ediService;
    if ((vp = mprAllocObj(EdiValidation, manageValidation)) == 0) {
        return MPR_ERR_MEMORY;
    }
    vp->name = sclone(name);
    if ((vp->vfn = mprLookupKey(es->validations, name)) == 0) {
        mprError("Can't find validation '%s'", name);
        return MPR_ERR_CANT_FIND;
    }
    if (smatch(name, "format")) {
        if ((vp->mdata = pcre_compile2(data, 0, 0, &errMsg, &column, NULL)) == 0) {
            mprError("Can't compile validation pattern. Error %s at column %d", errMsg, column); 
            return MPR_ERR_BAD_SYNTAX;
        }
        data = 0;
    }
    vp->data = data;
    return edi->provider->addValidation(edi, tableName, columnName, vp);
}
コード例 #3
0
ファイル: pcreposix.c プロジェクト: 1HLtd/php-src
PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
regcomp(regex_t *preg, const char *pattern, int cflags)
{
const char *errorptr;
int erroffset;
int errorcode;
int options = 0;
int re_nsub = 0;

if ((cflags & REG_ICASE) != 0)    options |= PCRE_CASELESS;
if ((cflags & REG_NEWLINE) != 0)  options |= PCRE_MULTILINE;
if ((cflags & REG_DOTALL) != 0)   options |= PCRE_DOTALL;
if ((cflags & REG_NOSUB) != 0)    options |= PCRE_NO_AUTO_CAPTURE;
if ((cflags & REG_UTF8) != 0)     options |= PCRE_UTF8;
if ((cflags & REG_UCP) != 0)      options |= PCRE_UCP;
if ((cflags & REG_UNGREEDY) != 0) options |= PCRE_UNGREEDY;

preg->re_pcre = pcre_compile2(pattern, options, &errorcode, &errorptr,
  &erroffset, NULL);
preg->re_erroffset = erroffset;

/* Safety: if the error code is too big for the translation vector (which
should not happen, but we all make mistakes), return REG_BADPAT. */

if (preg->re_pcre == NULL)
  {
  return (errorcode < (int)(sizeof(eint)/sizeof(const int)))?
    eint[errorcode] : REG_BADPAT;
  }

(void)pcre_fullinfo((const pcre *)preg->re_pcre, NULL, PCRE_INFO_CAPTURECOUNT,
  &re_nsub);
preg->re_nsub = (size_t)re_nsub;
return 0;
}
コード例 #4
0
/*
 * 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
*/
AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags)
{
    const char *errorptr;
    int erroffset;
    int errcode = 0;
    int options = PCRE_DUPNAMES;

    if ((cflags & AP_REG_ICASE) != 0)
        options |= PCRE_CASELESS;
    if ((cflags & AP_REG_NEWLINE) != 0)
        options |= PCRE_MULTILINE;
    if ((cflags & AP_REG_DOTALL) != 0)
        options |= PCRE_DOTALL;

    preg->re_pcre =
        pcre_compile2(pattern, options, &errcode, &errorptr, &erroffset, NULL);
    preg->re_erroffset = erroffset;

    if (preg->re_pcre == NULL) {
        /*
         * There doesn't seem to be constants defined for compile time error
         * codes. 21 is "failed to get memory" according to pcreapi(3).
         */
        if (errcode == 21)
            return AP_REG_ESPACE;
        return AP_REG_INVARG;
    }

    pcre_fullinfo((const pcre *)preg->re_pcre, NULL,
                   PCRE_INFO_CAPTURECOUNT, &(preg->re_nsub));
    return 0;
}
コード例 #5
0
ファイル: ejsRegExp.c プロジェクト: varphone/ejs-2
/*
    Create an initialized regular expression object. The pattern should include
    the slash delimiters. For example: /abc/ or /abc/g
 */
EjsRegExp *ejsCreateRegExp(Ejs *ejs, EjsString *pattern)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    MprChar     *flags;
    int         column, errCode;

    if (pattern->length == 0 || pattern->value[0] != '/') {
        ejsThrowArgError(ejs, "Bad regular expression pattern. Must start with '/'");
        return 0;
    }
    rp = ejsCreateObj(ejs, ESV(RegExp), 0);
    if (rp != 0) {
        /*
            Strip off flags for passing to pcre_compile2
         */
        rp->pattern = sclone(&pattern->value[1]);
        if ((flags = wrchr(rp->pattern, '/')) != 0) {
            rp->options = parseFlags(rp, &flags[1]);
            *flags = 0;
        }
        //  TODO - UNICODE is pattern meant to be 
        rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
        if (rp->compiled == NULL) {
            ejsThrowArgError(ejs, "Can't compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
            return 0;
        }
    }
    return rp;
}
コード例 #6
0
ファイル: radix.c プロジェクト: balabit/syslog-ng
gpointer
r_parser_pcre_compile_state(const gchar *expr)
{
  RParserPCREState *self = g_new0(RParserPCREState, 1);
  const gchar *errptr;
  gint erroffset;
  gint rc;

  self->re = pcre_compile2(expr, PCRE_ANCHORED, &rc, &errptr, &erroffset, NULL);
  if (!self->re)
    {
      msg_error("Error while compiling regular expression",
                evt_tag_str("regular_expression", expr),
                evt_tag_str("error_at", &expr[erroffset]),
                evt_tag_int("error_offset", erroffset),
                evt_tag_str("error_message", errptr),
                evt_tag_int("error_code", rc));
      g_free(self);
      return NULL;
    }
  self->extra = pcre_study(self->re, 0, &errptr);
  if (errptr)
    {
      msg_error("Error while optimizing regular expression",
                evt_tag_str("regular_expression", expr),
                evt_tag_str("error_message", errptr));
      pcre_free(self->re);
      if (self->extra)
        pcre_free(self->extra);
      g_free(self);
      return NULL;
    }
  return (gpointer) self;
}
コード例 #7
0
ファイル: krb5_utils-tests.c プロジェクト: nguay/SSSD
END_TEST

START_TEST(test_illegal_patterns)
{
    int ret;
    char *cwd;
    char *dirname;
    char *filename;
    uid_t uid = getuid();
    gid_t gid = getgid();
    pcre *illegal_re;
    const char *errstr;
    int errval;
    int errpos;

    illegal_re = pcre_compile2(ILLEGAL_PATH_PATTERN, 0,
                               &errval, &errstr, &errpos, NULL);
    fail_unless(illegal_re != NULL, "Invalid Regular Expression pattern at "
                                    " position %d. (Error: %d [%s])\n",
                                    errpos, errval, errstr);

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    dirname = talloc_asprintf(tmp_ctx, "%s/%s/priv_ccdir", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(dirname != NULL, "talloc_asprintf failed.");


    filename = talloc_asprintf(tmp_ctx, "abc/./ccfile");
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    ret = create_ccache_dir(filename, illegal_re, uid, gid, true);
    fail_unless(ret == EINVAL, "create_ccache_dir allowed relative path [%s].",
                               filename);

    filename = talloc_asprintf(tmp_ctx, "%s/abc/./ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    ret = create_ccache_dir(filename, illegal_re, uid, gid, true);
    fail_unless(ret == EINVAL, "create_ccache_dir allowed "
                               "illegal pattern '/./' in filename [%s].",
                               filename);

    filename = talloc_asprintf(tmp_ctx, "%s/abc/../ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    ret = create_ccache_dir(filename, illegal_re, uid, gid, true);
    fail_unless(ret == EINVAL, "create_ccache_dir allowed "
                               "illegal pattern '/../' in filename [%s].",
                               filename);

    filename = talloc_asprintf(tmp_ctx, "%s/abc//ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    ret = create_ccache_dir(filename, illegal_re, uid, gid, true);
    fail_unless(ret == EINVAL, "create_ccache_dir allowed "
                               "illegal pattern '//' in filename [%s].",
                               filename);

}
コード例 #8
0
ファイル: patable.c プロジェクト: cinsk/evhttpserv
int
patable_add(struct patable *table, const char *pattern,
            const void *data)
{
  int i;
  struct patentry *p;
  size_t newsz;
  int ecode, eoff;
  const char *emsg;

  // int options = PCRE_ANCHORED | PCRE_DOLLAR_ENDONLY;
  int options = PCRE_ANCHORED;

  if (table->cur >= table->npat) {
    /* TODO: check if there's a bug here */
    newsz = table->npat * 2;
    p = realloc(table->pat, sizeof(*p) * newsz);
    if (!p)
      return 0;
    for (i = table->npat; i < newsz; i++) {
      table->pat[i].re = 0;
    }
    table->pat = p;
    table->npat = newsz;
  }

  for (i = table->cur; i < table->npat; i++) {
    if (table->pat[i].re == 0) {
      table->pat[i].re = pcre_compile2(pattern, options,
                                       &ecode, &emsg, &eoff, NULL);
      if (!table->pat[i].re) {
        xdebug(0, "invalid regular expresssion in \"%s\": %s", pattern, emsg);
        return 0;
      }
      table->pat[i].ext = pcre_study(table->pat[i].re,
                                     PCRE_STUDY_EXTRA_NEEDED |
                                     PCRE_STUDY_JIT_COMPILE,
                                     &emsg);

      if (!table->pat[i].ext) {
        xdebug(0, "analyzing regular expresssion in \"%s\": %s", pattern, emsg);
        pcre_free(table->pat[i].re);
        table->pat[i].re = 0;
        return 0;
      }
      table->pat[i].data = (void *)data;

      table->cur = i + 1;
      return 1;
    }
  }

  table->cur = i;
  return patable_add(table, pattern, data);
}
コード例 #9
0
ファイル: mud-regex.c プロジェクト: GNOME/gnome-mud
/* Public Methods */
gboolean
mud_regex_check(MudRegex *regex,
                const gchar *data,
		guint length,
		const gchar *rx,
		gint ovector[1020])
{
    pcre *re = NULL;
    const gchar *error = NULL;
    gint errorcode;
    gint erroroffset;
    gint rc;

    if(!MUD_IS_REGEX(regex))
        return FALSE;

    re = pcre_compile2(rx, 0, &errorcode, &error, &erroroffset, NULL);

    if(!re)
    {
	gint i;

	/*
	   This should never be called since we check the regex validity
	   at entry time.  But You Never Know(tm) so its here to catch
	   any runtime errors that cosmic rays, evil magic, errant gconf
	   editing, and Monday mornings might produce.
	 */

	g_warning("Error in Regex! - ErrCode: %d - %s", errorcode, error);
	printf("--> %s\n    ", rx);

	for(i = 0; i < erroroffset - 1; i++)
	    printf(" ");

	printf("^\n");

	return FALSE;

    }

    rc = pcre_exec(re, NULL, data, length, 0, 0, ovector, 1020);

    if(rc < 0)
	return FALSE;

    if(regex->priv->substring_list)
	pcre_free_substring_list(regex->priv->substring_list);

    pcre_get_substring_list(data, ovector, rc, &regex->priv->substring_list);
    regex->priv->substring_count = rc;

    return TRUE;
}
コード例 #10
0
ファイル: RegExp.cpp プロジェクト: AbdelghaniDr/mirror
bool RegExp::Compile(bool recompile)
{
	if(cpattern)
	{
		if(recompile)
			pcre_free(cpattern);
		else
			return true;
	}
	cpattern = pcre_compile2(pattern, compile_options, &error_code, &error_string, &error_offset, NULL);
	return error_code == 0;
}
コード例 #11
0
ファイル: krb5_utils-tests.c プロジェクト: nguay/SSSD
END_TEST

#ifdef HAVE_KRB5_DIRCACHE
START_TEST(test_cc_dir_create)
{
    char *residual;
    char *dirname;
    char *cwd;
    uid_t uid = getuid();
    gid_t gid = getgid();
    pcre *illegal_re;
    errno_t ret;
    const char *errstr;
    int errval;
    int errpos;

    illegal_re = pcre_compile2(ILLEGAL_PATH_PATTERN, 0,
                               &errval, &errstr, &errpos, NULL);
    fail_unless(illegal_re != NULL, "Invalid Regular Expression pattern at "
                                    " position %d. (Error: %d [%s])\n",
                                    errpos, errval, errstr);

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    dirname = talloc_asprintf(tmp_ctx, "%s/%s/user_dir",
                              cwd, TESTS_PATH);
    fail_unless(dirname != NULL, "talloc_asprintf failed.");
    residual = talloc_asprintf(tmp_ctx, "DIR:%s/%s", dirname, "ccdir");
    fail_unless(residual != NULL, "talloc_asprintf failed.");

    ret = cc_dir_create(residual, illegal_re, uid, gid, true);
    fail_unless(ret == EOK, "cc_dir_create failed\n");
    ret = rmdir(dirname);
    if (ret < 0) ret = errno;
    fail_unless(ret == 0, "Cannot remove %s: %s\n", dirname, strerror(ret));
    talloc_free(residual);

    dirname = talloc_asprintf(tmp_ctx, "%s/%s/user_dir2",
                              cwd, TESTS_PATH);
    fail_unless(dirname != NULL, "talloc_asprintf failed.");
    residual = talloc_asprintf(tmp_ctx, "DIR:%s/%s", dirname, "ccdir/");
    fail_unless(residual != NULL, "talloc_asprintf failed.");

    ret = cc_dir_create(residual, illegal_re, uid, gid, true);
    fail_unless(ret == EOK, "cc_dir_create failed\n");
    ret = rmdir(dirname);
    if (ret < 0) ret = errno;
    fail_unless(ret == 0, "Cannot remove %s: %s\n", dirname, strerror(ret));
    talloc_free(residual);
    free(cwd);
}
コード例 #12
0
static void *srcompile(cchar *pattern)
{
    pcre    *pp;
    cchar   *err;
    int     column, options;

    options = PCRE_JAVASCRIPT_COMPAT;
    if ((pp = pcre_compile2(pattern, options, 0, &err, &column, NULL)) == 0) {
        mprLog("error ejscript", 0, "Cannot compile pattern %s. Error %s at column %d", pattern, err, column);
        return 0;
    }
    return pp;
}
コード例 #13
0
ファイル: krb5_utils-tests.c プロジェクト: abbra/sssd
END_TEST

START_TEST(test_illegal_patterns)
{
    char *cwd;
    char *dirname;
    char *filename;
    pcre *illegal_re;
    const char *errstr;
    int errval;
    int errpos;
    char *result = NULL;

    illegal_re = pcre_compile2(ILLEGAL_PATH_PATTERN, 0,
                               &errval, &errstr, &errpos, NULL);
    fail_unless(illegal_re != NULL, "Invalid Regular Expression pattern at "
                                    " position %d. (Error: %d [%s])\n",
                                    errpos, errval, errstr);

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    dirname = talloc_asprintf(tmp_ctx, "%s/%s/priv_ccdir", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(dirname != NULL, "talloc_asprintf failed.");

    result = expand_ccname_template(tmp_ctx, kr, "abc/./ccfile", illegal_re, true, true);
    fail_unless(result == NULL, "expand_ccname_template allowed relative path\n");

    filename = talloc_asprintf(tmp_ctx, "%s/abc/./ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    result = expand_ccname_template(tmp_ctx, kr, filename, illegal_re, true, true);
    fail_unless(result == NULL, "expand_ccname_template allowed "
                                "illegal pattern '/./'\n");

    filename = talloc_asprintf(tmp_ctx, "%s/abc/../ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    result = expand_ccname_template(tmp_ctx, kr, filename, illegal_re, true, true);
    fail_unless(result == NULL, "expand_ccname_template allowed "
                                "illegal pattern '/../' in filename [%s].",
                                filename);

    filename = talloc_asprintf(tmp_ctx, "%s/abc//ccfile", dirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");
    result = expand_ccname_template(tmp_ctx, kr, filename, illegal_re, true, true);
    fail_unless(result == NULL, "expand_ccname_template allowed "
                                "illegal pattern '//' in filename [%s].",
                                filename);

    pcre_free(illegal_re);
}
コード例 #14
0
ファイル: PlatRE.cpp プロジェクト: russelljk/pika
Pika_regex* Pika_regcomp(const char* pattern, int cflags, char* errmsg, size_t errlen, int* errorcode)
{
    int err = 0;
    const char* errdescr = 0;
    int erroff = 0;
    int options = PCRE_UTF8 | PCRE_NO_UTF8_CHECK | PCRE_MULTILINE | cflags;
    pcre* re = pcre_compile2(pattern, options, &err, &errdescr, &erroff, 0);
    
    if (!re && errmsg && errlen > 0)
        strncpy(errmsg, errdescr, pika::Min(errlen, strlen(errdescr)));    
    if (errorcode)
        *errorcode = err;
    return (Pika_regex*)re;
}
コード例 #15
0
ファイル: ejsRegExp.c プロジェクト: liexusong/ejs-2
/*
    Parse a regular expression string. The string should include the slash delimiters and may contain appended flags. 
    For example: /abc/ or /abc/g
 */
PUBLIC EjsRegExp *ejsParseRegExp(Ejs *ejs, EjsString *pattern)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    char        *cp, *dp;
    wchar       *flags;
    int         column, errCode;

    if (pattern->length == 0 || pattern->value[0] != '/') {
        ejsThrowArgError(ejs, "Bad regular expression pattern. Must start with '/'");
        return 0;
    }
    if ((rp = ejsCreateObj(ejs, ESV(RegExp), 0)) == 0) {
        return 0;
    }
    /*
        Strip off flags for passing to pcre_compile2
     */
    if (pattern->value[0] == '/') {
        rp->pattern = sclone(&pattern->value[1]);
        if ((flags = wrchr(rp->pattern, '/')) != 0) {
            if (flags == rp->pattern) {
                ejsThrowArgError(ejs, "Bad regular expression pattern. Must end with '/'");
                return 0;
            }
            rp->options = parseFlags(rp, &flags[1]);
            *flags = 0;
        }
        /*
            NOTE: we don't expect backquotes to be quoted. That only happens when interpreting literal js code and JSON
         */
        for (dp = cp = rp->pattern; *cp; ) {
            if (*cp == '\\' && cp[1] == '/') {
                cp++;
            }
            *dp++ = *cp++;
        }
        *dp++ = '\0';

    } else {
        rp->pattern = sclone(&pattern->value[1]);
    }
    rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
    if (rp->compiled == NULL) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
コード例 #16
0
ファイル: usertools.c プロジェクト: 3van/sssd
int sss_names_init_from_args(TALLOC_CTX *mem_ctx, const char *re_pattern,
                             const char *fq_fmt, struct sss_names_ctx **out)
{
    struct sss_names_ctx *ctx;
    const char *errstr;
    int errval;
    int errpos;
    int ret;

    ctx = talloc_zero(mem_ctx, struct sss_names_ctx);
    if (!ctx) return ENOMEM;
    talloc_set_destructor(ctx, sss_names_ctx_destructor);

    ctx->re_pattern = talloc_strdup(ctx, re_pattern);
    if (ctx->re_pattern == NULL) {
        ret = ENOMEM;
        goto done;
    }

    DEBUG(SSSDBG_CONF_SETTINGS, "Using re [%s].\n", ctx->re_pattern);

    ret = sss_fqnames_init(ctx, fq_fmt);
    if (ret != EOK) {
        DEBUG(SSSDBG_OP_FAILURE, "Could not check the FQ names format"
              "[%d]: %s\n", ret, sss_strerror(ret));
        goto done;
    }

    ctx->re = pcre_compile2(ctx->re_pattern,
                            NAME_DOMAIN_PATTERN_OPTIONS,
                            &errval, &errstr, &errpos, NULL);
    if (!ctx->re) {
        DEBUG(SSSDBG_CRIT_FAILURE,
              "Invalid Regular Expression pattern at position %d."
                  " (Error: %d [%s])\n", errpos, errval, errstr);
        ret = EFAULT;
        goto done;
    }

    *out = ctx;
    ret = EOK;

done:
    if (ret != EOK) {
        talloc_free(ctx);
    }
    return ret;
}
コード例 #17
0
ファイル: ejsRegExp.c プロジェクト: liexusong/ejs-2
/*
    Create an initialized regular expression object. The pattern should NOT include the slash delimiters. 
 */
PUBLIC EjsRegExp *ejsCreateRegExp(Ejs *ejs, cchar *pattern, cchar *flags)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    int         column, errCode;

    if ((rp = ejsCreateObj(ejs, ESV(RegExp), 0)) == 0) {
        return 0;
    }
    rp->pattern = sclone(pattern);
    rp->options = parseFlags(rp, (wchar*) flags);
    rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
    if (rp->compiled == NULL) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
コード例 #18
0
ファイル: pcre.c プロジェクト: baeeq/watchman
static w_query_expr *pcre_parser(w_query *query,
    json_t *term, bool caseless)
{
  const char *ignore, *pattern, *scope = "basename";
  const char *which = caseless ? "ipcre" : "pcre";
  struct match_pcre *data;
  pcre *re;
  const char *errptr = NULL;
  int erroff = 0;
  int errcode = 0;

  if (json_unpack(term, "[s,s,s]", &ignore, &pattern, &scope) != 0 &&
      json_unpack(term, "[s,s]", &ignore, &pattern) != 0) {
    asprintf(&query->errmsg,
        "Expected [\"%s\", \"pattern\", \"scope\"?]",
        which);
    return NULL;
  }

  if (strcmp(scope, "basename") && strcmp(scope, "wholename")) {
    asprintf(&query->errmsg,
        "Invalid scope '%s' for %s expression",
        scope, which);
    return NULL;
  }

  re = pcre_compile2(pattern, caseless ? PCRE_CASELESS : 0,
        &errcode, &errptr, &erroff, NULL);
  if (!re) {
    asprintf(&query->errmsg,
      "invalid %s: code %d %s at offset %d in %s",
      which, errcode, errptr, erroff, pattern);
    return NULL;
  }

  data = malloc(sizeof(*data));
  data->re = re;
  data->extra = pcre_study(re, 0, &errptr);
  data->wholename = !strcmp(scope, "wholename");

  return w_query_expr_new(eval_pcre, dispose_pcre, data);
}
コード例 #19
0
PcRe::PcRe (const std::wstring &regex)
{
    const char *err;
	int erroffset;
	re = pcre_compile2 (wstring_to_utf8 (regex).c_str (),
#ifdef PCRE_UTF8
			PCRE_UTF8|
#endif
#ifdef PCRE_NO_UTF8_CHECK
			PCRE_NO_UTF8_CHECK|
#endif
			PCRE_MULTILINE|PCRE_CASELESS,
			0, &err, &erroffset, 0);
	if (re) {
		re_ex = pcre_study ((const pcre *)re, 0, &err);
	}
	else {
		re_ex = 0;
	}
}
コード例 #20
0
ファイル: ejsRegExp.c プロジェクト: liexusong/ejs-2
static EjsRegExp *regex_Constructor(Ejs *ejs, EjsRegExp *rp, int argc, EjsObj **argv)
{
    cchar       *errMsg;
    int         column, errCode;

    rp->pattern = wclone(ejsToString(ejs, argv[0])->value);
    rp->options = PCRE_JAVASCRIPT_COMPAT;

    if (argc == 2) {
        rp->options |= parseFlags(rp, ejsToString(ejs, argv[1])->value);
    }
    if (rp->compiled) {
        free(rp->compiled);
    }
    if ((rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL)) == 0) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
コード例 #21
0
MultiLineRegexp *
multi_line_regexp_compile(const gchar *regexp, GError **error)
{
  MultiLineRegexp *self = g_new0(MultiLineRegexp, 1);
  gint optflags = 0;
  gint rc;
  const gchar *errptr;
  gint erroffset;

  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

  /* complile the regexp */
  self->pattern = pcre_compile2(regexp, 0, &rc, &errptr, &erroffset, NULL);
  if (!self->pattern)
    {
      g_set_error(error, 0, 0, "Error while compiling multi-line regexp as a PCRE expression, error=%s, error_at=%d", errptr, erroffset);
      goto error;
    }

#ifdef PCRE_STUDY_JIT_COMPILE
  optflags = PCRE_STUDY_JIT_COMPILE;
#endif

  /* optimize regexp */
  self->extra = pcre_study(self->pattern, optflags, &errptr);
  if (errptr != NULL)
    {
      g_set_error(error, 0, 0, "Error while studying multi-line regexp, error=%s", errptr);
      goto error;
    }

  return self;
 error:
  if (self->pattern)
    pcre_free(self->pattern);
  g_free(self);
  return NULL;
}
コード例 #22
0
ファイル: pcre_compat.c プロジェクト: gphalkes/t3highlight
pcre2_code_8 *pcre2_compile_8(PCRE2_SPTR8 pattern, PCRE2_SIZE pattern_size, uint32_t options,
                              int *errorcode, PCRE2_SIZE *erroroffset, void *ccontext) {
  const char *error_message;
  if (pattern_size != PCRE2_ZERO_TERMINATED) {
    abort();
  }
  if (ccontext != NULL) {
    abort();
  }
  pcre2_code_8 *result = malloc(sizeof(pcre2_code_8));
  result->regex = NULL;
  result->extra = NULL;

  result->regex =
      pcre_compile2((const char *)pattern, options, errorcode, &error_message, erroroffset, NULL);
  if (result->regex == NULL) {
    last_error_message = error_message;
    last_error_code = *errorcode;
    free(result);
    return NULL;
  }
  return result;
}
コード例 #23
0
ファイル: pcreposix.c プロジェクト: GYGit/Soar
PCREPOSIX_EXP_DEFN int
regcomp(regex_t *preg, const char *pattern, int cflags)
{
const char *errorptr;
int erroffset;
int errorcode;
int options = 0;

if ((cflags & REG_ICASE) != 0)   options |= PCRE_CASELESS;
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
if ((cflags & REG_DOTALL) != 0)  options |= PCRE_DOTALL;
if ((cflags & REG_NOSUB) != 0)   options |= PCRE_NO_AUTO_CAPTURE;
if ((cflags & REG_UTF8) != 0)    options |= PCRE_UTF8;

preg->re_pcre = pcre_compile2(pattern, options, &errorcode, &errorptr,
  &erroffset, NULL);
preg->re_erroffset = erroffset;

if (preg->re_pcre == NULL) return eint[errorcode];

preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
return 0;
}
コード例 #24
0
ファイル: orderly_json_parse.c プロジェクト: gno/orderly
static orderly_json_parse_status
parse_json_schema(orderly_alloc_funcs * alloc,
                  orderly_json * j, orderly_node ** n)
{
    orderly_json_parse_status s = orderly_json_parse_s_ok;
    
    orderly_json * k;
    *n = NULL;
    if (j->t != orderly_json_object) {
        /* XXX: offset into the buffer!? */
        return orderly_json_parse_s_object_expected;
    }

    *n = orderly_alloc_node(alloc, orderly_node_empty);
    (*n)->additional_properties = orderly_node_any;

    for (k=j->v.children.first; k != NULL; k=k->next) {
        if (k->k != NULL) {
            if (!strcmp(k->k, "type")) {
                if (k->t == orderly_json_string) {
                    (*n)->t = orderly_string_to_node_type(k->v.s, strlen(k->v.s));
                    if ((*n)->t == orderly_node_empty) {
                        s = orderly_json_parse_s_invalid_type_value;
                        goto toErrIsHuman;
                    }
                } else if (k->t == orderly_json_array) {
                    /* support items containing an *array* of schema
                     * for tuple typing */
                    orderly_json * pj = NULL;
                    orderly_node ** last = &((*n)->child);
                    (*n)->t = orderly_node_union;

                    for (pj = k->v.children.first; pj; pj = pj->next)
                    {
                        s = parse_json_schema(alloc, pj, last);
                        if (s != orderly_json_parse_s_ok) {
                            goto toErrIsHuman;
                        }
                        last = &((*last)->sibling);
                    }
                } else {
                    s = orderly_json_parse_s_type_expects_string_or_array;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "properties")) {
                orderly_json * p = NULL;
                orderly_node ** last = &((*n)->child);

                if (k->t != orderly_json_object) {                
                    s = orderly_json_parse_s_invalid_properties_value;
                    goto toErrIsHuman;
                }

                for (p=k->v.children.first; p != NULL; p=p->next) {
                    orderly_node * pn = NULL;
                    s = parse_json_schema(alloc, p, &pn);
                    if (pn) {
                        *last = pn;
                        last = &(pn->sibling);
                        BUF_STRDUP(pn->name, alloc, p->k, strlen(p->k));
                    }
                    
                    if (s != orderly_json_parse_s_ok) {
                        goto toErrIsHuman;
                    }
                }
            }
            else if (!strcmp(k->k, "items")) {
                /* support items containing an *array* of schema
                *  for tuple typing */
                if (k->t == orderly_json_array) {
                    orderly_json * pj = NULL;
                    orderly_node ** last = &((*n)->child);
                    (*n)->tuple_typed = 1;
                    for (pj = k->v.children.first; pj; pj = pj->next)
                    {
                        s = parse_json_schema(alloc, pj, last);
                        if (s != orderly_json_parse_s_ok) {
                            goto toErrIsHuman;
                        }
                        last = &((*last)->sibling);
                    }
                } else if (k->t == orderly_json_object) {
                    orderly_node * pn = NULL;
                    s = parse_json_schema(alloc, k, &pn);
                    if (s != orderly_json_parse_s_ok) {
                        goto toErrIsHuman;
                    }
                    (*n)->child = pn;
                } else {
                    s = orderly_json_parse_s_items_gets_object_or_array;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "optional")) {
                if (k->t != orderly_json_boolean) {
                    s = orderly_json_parse_s_invalid_optional_value;
                    goto toErrIsHuman;
                }
                (*n)->optional = k->v.b;
            }
            else if (!strcmp(k->k, "minimum")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_LHS_INT;
                    (*n)->range.lhs.i = k->v.i;
                } else if (k->t == orderly_json_number) {
                    (*n)->range.info |= ORDERLY_RANGE_LHS_DOUBLE;
                    (*n)->range.lhs.d = k->v.n;
                } else {
                    s = orderly_json_parse_s_minimum_requires_number;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "maximum")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_RHS_INT;
                    (*n)->range.rhs.i = k->v.i;
                } else if (k->t == orderly_json_number) {
                    (*n)->range.info |= ORDERLY_RANGE_RHS_DOUBLE;
                    (*n)->range.rhs.d = k->v.n;
                } else {
                    s = orderly_json_parse_s_maximum_requires_number;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "minLength")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_LHS_INT;
                    (*n)->range.lhs.i = k->v.i;
                } else {
                    s = orderly_json_parse_s_minlength_requires_integer;
                    goto toErrIsHuman;
                }

            }
            else if (!strcmp(k->k, "maxLength")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_RHS_INT;
                    (*n)->range.rhs.i = k->v.i;
                } else {
                    s = orderly_json_parse_s_maxlength_requires_integer;
                    goto toErrIsHuman;
                }

            }
            else if (!strcmp(k->k, "minItems")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_LHS_INT;
                    (*n)->range.lhs.i = k->v.i;
                } else {
                    s = orderly_json_parse_s_minitems_requires_integer;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "maxItems")) {
                if (k->t == orderly_json_integer) {
                    (*n)->range.info |= ORDERLY_RANGE_RHS_INT;
                    (*n)->range.rhs.i = k->v.i;
                } else {
                    s = orderly_json_parse_s_maxitems_requires_integer;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "additionalProperties")) {
                if (k->t == orderly_json_boolean) {
                    (*n)->additional_properties = 
                      k->v.b 
                      ? orderly_node_any
                      : orderly_node_empty;
                } else if (k->t == orderly_json_object
                           && !strcmp(k->v.children.first->k, "type")) {
                  if (k->v.children.first->t == orderly_json_string) {
                      (*n)->additional_properties = 
                        orderly_string_to_node_type(k->v.children.first->v.s, 
                                                    strlen(k->v.children.first->v.s));
                    } else {
                      s = orderly_json_parse_s_invalid_type_value;
                      goto toErrIsHuman;
                    }
                } else {
                  s = orderly_json_parse_s_addprop_requires_boolean;
                }
            }
            else if (!strcmp(k->k, "default")) {
                /* clone */
                (*n)->default_value = orderly_clone_json(alloc, k);
                /* remove the key */
                OR_FREE(alloc, (char *) (*n)->default_value->k);
                (*n)->default_value->k = NULL;

            }
            else if (!strcmp(k->k, "enum")) {
                /* clone */
                (*n)->values = orderly_clone_json(alloc, k);
                /* remove the key */
                OR_FREE(alloc, (char *) (*n)->values->k);
                (*n)->values->k = NULL;
            }
            else if (!strcmp(k->k, "pattern")) {
                if (k->t == orderly_json_string) {
                    pcre *regex;
                    const char *regerror;
                    int erroffset;
                    int error_code = 0;
                    BUF_STRDUP((*n)->regex, alloc, k->v.s, strlen(k->v.s));
                    regex = pcre_compile2((*n)->regex,
                                          0,
                                          &error_code,
                                          &regerror,
                                          &erroffset,
                                          NULL);
                    if (regex) {
                      pcre_free(regex);
                    }
                    if (error_code != 0) {
                      s = orderly_parse_s_regex_error + error_code;
                      goto toErrIsHuman;
                    }
                } else {
                    s = orderly_json_parse_s_pattern_requires_string;
                    goto toErrIsHuman;
                }
            }
            else if (!strcmp(k->k, "requires")) {
                if ((*n)->requires) {
                    s = orderly_json_parse_s_duplicate_requires;
                    goto toErrIsHuman;
                }
                
                if (k->t == orderly_json_string) {
                    (*n)->requires = OR_MALLOC(alloc, 2 * sizeof(char *));
                    BUF_STRDUP((*n)->requires[0], alloc, k->v.s, strlen(k->v.s));
                    (*n)->requires[1] = NULL;
                } else if (k->t == orderly_json_array) {
                    unsigned int num = 0;
                    orderly_json * ks;
                    
                    for (ks = k->v.children.first; ks; ks = ks->next)
                    {
                        unsigned int i;
                        char ** p;

                        if (ks->t != orderly_json_string) {
                            s = orderly_json_parse_s_requires_value_error;
                            goto toErrIsHuman;
                        }
                        num++;
                        p = OR_MALLOC(alloc, sizeof(char *) * (num + 1));
                        for (i = 0; i < num - 1; i++) p[i] = (char *) (*n)->requires[i];
                        BUF_STRDUP(p[i], alloc, ks->v.s, strlen(ks->v.s));
                        p[++i] = NULL;
                        if ((*n)->requires) OR_FREE(alloc, (*n)->requires);
                        (*n)->requires = (const char **) p;
                    }
                }
            }
            else if (!strcmp(k->k, "$schema")) {
              /* XXX: detect schema version, and store it somewhere!?,
                 then go back and adjust things */
              

            } else {
                orderly_json ** jPtr;
                    
                /* all unexpected properties are passed through using
                 * the passthrough_properties element of the node. */
                /* XXX: should this behavior be configurable? */
                if ((*n)->passthrough_properties == NULL) {
                    (*n)->passthrough_properties =
                        orderly_alloc_json(alloc, orderly_json_object);
                }
                jPtr = &((*n)->passthrough_properties->v.children.first);
                while (*jPtr) jPtr = &((*jPtr)->next);
                /* clone onto the passthrough object */
                (*jPtr) = orderly_clone_json(alloc, k);
            }
        }
    }
    
    /* json schema has some implied defaults, insert them */
    interject_defaults(alloc,*n);

    return s;

  toErrIsHuman:
    if (*n) orderly_free_node(alloc, n);
    return s;
}
コード例 #25
0
ファイル: krb5_init.c プロジェクト: SSSD/sssd
errno_t sssm_krb5_init(TALLOC_CTX *mem_ctx,
                       struct be_ctx *be_ctx,
                       struct data_provider *provider,
                       const char *module_name,
                       void **_module_data)
{
    struct krb5_ctx *ctx;
    const char *errstr;
    int errval;
    int errpos;
    errno_t ret;

    ctx = talloc_zero(mem_ctx, struct krb5_ctx);
    if (ctx == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero() failed\n");
        return ENOMEM;
    }

    /* Only needed to generate random ccache names for non-POSIX domains */
    srand(time(NULL) * getpid());

    ret = sss_krb5_get_options(ctx, be_ctx->cdb, be_ctx->conf_path, &ctx->opts);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get krb5 options [%d]: %s\n",
              ret, sss_strerror(ret));
        goto done;
    }

    ctx->action = INIT_PW;
    ctx->config_type = K5C_GENERIC;

    ret = krb5_init_kdc(ctx, be_ctx);
    if (ret != EOK) {
        goto done;
    }

    ret = krb5_init_kpasswd(ctx, be_ctx);
    if (ret != EOK) {
        goto done;
    }

    ret = krb5_child_init(ctx, be_ctx);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "Could not initialize krb5_child settings "
              "[%d]: %s\n", ret, sss_strerror(ret));
        goto done;
    }

    ctx->illegal_path_re = pcre_compile2(ILLEGAL_PATH_PATTERN, 0,
                                         &errval, &errstr, &errpos, NULL);
    if (ctx->illegal_path_re == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid Regular Expression pattern "
              "at position %d. (Error: %d [%s])\n", errpos, errval, errstr);
        ret = EFAULT;
        goto done;
    }
    talloc_set_destructor(ctx, krb5_ctx_re_destructor);

    ret = be_fo_set_dns_srv_lookup_plugin(be_ctx, NULL);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to set SRV lookup plugin "
              "[%d]: %s\n", ret, sss_strerror(ret));
        goto done;
    }

    *_module_data = ctx;

    ret = EOK;

done:
    if (ret != EOK) {
        talloc_free(ctx);
    }

    return ret;
}
コード例 #26
0
ファイル: mapimp.c プロジェクト: pezcode/mapimp
int mask_compile(mask_t* msk, TCHAR* subj)
{
	int mod = 0, cntr_msk = 1, cntr_repl;
	TCHAR buffer[TEXTLEN];
	if (subj[0] == '/')
	{
		if ((subj[cntr_msk] == 'i') || (subj[cntr_msk] == 'I'))
		{
			mod = PCRE_CASELESS;
			cntr_msk++;
		}
		if ((subj[cntr_msk] == 's') || (subj[cntr_msk] == 'S'))
		{
			msk->regex = pcre_compile2(&subj[cntr_msk + 1], mod, &msk->errcode, &msk->errptr, &msk->erroffset, NULL);
			if (!msk->errcode)
			{
				msk->extra = pcre_study((const pcre*)msk->regex, 0, &msk->errptr);
				msk->type = FILTER_SKIP;
			}
			else
			{
				msk->erroffset += cntr_msk + 1;
			}
		}
		else if ((subj[cntr_msk] == 'c') || (subj[cntr_msk] == 'C'))
		{
			msk->regex = pcre_compile2(&subj[cntr_msk + 1], mod, &msk->errcode, &msk->errptr, &msk->erroffset, NULL);
			if (!msk->errcode)
			{
				msk->extra = pcre_study(msk->regex, 0, &msk->errptr);
				msk->type = FILTER_CUT;
			}
			else
			{
				msk->erroffset += cntr_msk + 1;
			}
		}
		else if ((subj[cntr_msk] == 'r') || (subj[cntr_msk] == 'R'))
		{
			msk->insert = -1;
			for (cntr_msk++, cntr_repl = 0; TRUE; cntr_msk++)
			{
				if (subj[cntr_msk] == '\0')
				{
					msk->errcode = FILTER_INVALID_REPLACEMENT;
					return FILTER_INVALID_REPLACEMENT;
				}
				else if (subj[cntr_msk] == '/')
				{
					break;
				}
				else if (subj[cntr_msk] == '\\')
				{
					buffer[cntr_repl] = subj[cntr_msk + 1];
					cntr_msk++;
					cntr_repl++;
				}
				else if (subj[cntr_msk] == '%')
				{
					if (msk->insert < 0)
					{
						msk->insert = cntr_repl;
					}
				}
				else
				{
					buffer[cntr_repl] = subj[cntr_msk];
					cntr_repl++;
				}
			}
			buffer[cntr_repl] = '\0';
			msk->regex = pcre_compile2(&subj[cntr_msk + 1], mod, &msk->errcode, &msk->errptr, &msk->erroffset, NULL);
			if (!msk->errcode)
			{
				msk->repl_s = (strlen(buffer) + 1) * sizeof(TCHAR);
				msk->repl = malloc(msk->repl_s * sizeof(TCHAR));
				strcpy(msk->repl, buffer);
				msk->extra = pcre_study(msk->regex, 0, &msk->errptr);
				msk->type = FILTER_REPLACE;
			}
			else
			{
				msk->erroffset += cntr_msk + 1;
			}
		}
		else
		{
			msk->errcode = FILTER_INVALID_KEY;
			msk->erroffset = cntr_msk + 1;
		}
	}
	else
	{
		msk->errcode = FILTER_INVALID_MASK;
		msk->erroffset = 1;
	}
	return msk->errcode;
}
コード例 #27
0
ファイル: logmatcher.c プロジェクト: jbfuzier/syslog-ng
static gboolean
log_matcher_pcre_re_compile(LogMatcher *s, const gchar *re, GError **error)
{
  LogMatcherPcreRe *self = (LogMatcherPcreRe *) s;
  gint rc;
  const gchar *re_comp = re;
  const gchar *errptr;
  gint erroffset;
  gint flags = 0;
  gint optflags = 0;
 
  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

  if (self->super.flags & LMF_ICASE)
    flags |= PCRE_CASELESS;
#ifdef PCRE_NEWLINE_ANYCRLF
  if (self->super.flags & LMF_NEWLINE)
    flags |= PCRE_NEWLINE_ANYCRLF;
#else
  if (self->super.flags & LMF_NEWLINE)
    msg_warning("syslog-ng was compiled against an old PCRE which doesn't support the 'newline' flag", NULL);
#endif
  if (self->super.flags & LMF_UTF8)
    {
       gint support;
       flags |= PCRE_UTF8 | PCRE_NO_UTF8_CHECK;
       self->match_options |= PCRE_NO_UTF8_CHECK;
 
       pcre_config(PCRE_CONFIG_UTF8, &support);
       if (!support)
         {
           g_set_error(error, LOG_TEMPLATE_ERROR, 0, "PCRE library is compiled without UTF8 support and utf8 flag was present");
           return FALSE;
         }

       pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &support);
       if (!support)
         {
           g_set_error(error, LOG_TEMPLATE_ERROR, 0, "PCRE library is compiled without UTF8 properties support and utf8 flag was present");
           return FALSE;
         }
    }
 
  /* complile the regexp */ 
  self->pattern = pcre_compile2(re_comp, flags, &rc, &errptr, &erroffset, NULL);
  if (!self->pattern)
    {
      g_set_error(error, LOG_TEMPLATE_ERROR, 0, "Error while compiling PCRE expression, error=%s, error_at=%d", errptr, erroffset);
      return FALSE;
    }

#ifdef PCRE_STUDY_JIT_COMPILE
  optflags = PCRE_STUDY_JIT_COMPILE;
#endif

  /* optimize regexp */
  self->extra = pcre_study(self->pattern, optflags, &errptr);
  if (errptr != NULL)
    {
      g_set_error(error, LOG_TEMPLATE_ERROR, 0, "Error while optimizing regular expression, error=%s", errptr);
      return FALSE;
    }

  return TRUE;
}
コード例 #28
0
ファイル: mire.c プロジェクト: avokhmin/RPM5
int mireRegcomp(miRE mire, const char * pattern)
{
    int rc = 0;

    mire->pattern = xstrdup(pattern);

    switch (mire->mode) {
    case RPMMIRE_STRCMP:
	break;
    case RPMMIRE_PCRE:
#ifdef	WITH_PCRE
	mire->errcode = 0;
	mire->errmsg = NULL;
	mire->erroff = 0;
	mire->pcre = pcre_compile2(mire->pattern, mire->coptions,
		&mire->errcode, &mire->errmsg, &mire->erroff, mire->table);
	if (mire->pcre == NULL) {
	    if (_mire_debug)
		rpmlog(RPMLOG_ERR,
		    _("pcre_compile2 failed: %s(%d) at offset %d of \"%s\"\n"),
		    mire->errmsg, mire->errcode, mire->erroff, mire->pattern);
	    rc = -1;
	    goto exit;	/* XXX HACK: rpmgrep is not expecting mireClean. */
	}
#else
	rc = -99;
#endif
	break;
    case RPMMIRE_DEFAULT:
    case RPMMIRE_REGEX:
	mire->preg = xcalloc(1, sizeof(*mire->preg));
	if (mire->cflags == 0)
	    mire->cflags = _mireREGEXoptions;
	rc = regcomp(mire->preg, mire->pattern, mire->cflags);
	if (rc) {
	    char msg[256];
	    (void) regerror(rc, mire->preg, msg, sizeof(msg)-1);
	    msg[sizeof(msg)-1] = '\0';
	    rpmlog(RPMLOG_ERR, _("%s: regcomp failed: %s\n"),
			mire->pattern, msg);
	}
	break;
    case RPMMIRE_GLOB:
	if (mire->fnflags == 0)
	    mire->fnflags = _mireGLOBoptions;
	break;
    default:
	rc = -1;
	break;
    }

    if (rc)
	(void) mireClean(mire);

#ifdef	WITH_PCRE
exit:
#endif
/*@-modfilesys@*/
if (_mire_debug)
fprintf(stderr, "<-- mireRegcomp(%p, \"%s\") rc %d\n", mire, pattern, rc);
/*@=modfilesys@*/
    return rc;
}