static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern)
{
	regex_t preg;
	git_revwalk *walk = NULL;
	int error;

	if ((error = build_regex(&preg, pattern)) < 0)
		return error;

	if ((error = git_revwalk_new(&walk, repo)) < 0)
		goto cleanup;

	git_revwalk_sorting(walk, GIT_SORT_TIME);

	if (spec_oid == NULL) {
		// TODO: @carlosmn: The glob should be refs/* but this makes git_revwalk_next() fails
		if ((error = git_revwalk_push_glob(walk, GIT_REFS_HEADS_DIR "*")) < 0)
			goto cleanup;
	} else if ((error = git_revwalk_push(walk, spec_oid)) < 0)
			goto cleanup;

	error = walk_and_search(out, walk, &preg);

cleanup:
	regfree(&preg);
	git_revwalk_free(walk);

	return error;
}
コード例 #2
0
int phishing_init(struct cl_engine* engine)
{
	struct phishcheck* pchk;
	if(!engine->phishcheck) {
		pchk = engine->phishcheck = mpool_malloc(engine->mempool, sizeof(struct phishcheck));
		if(!pchk) {
            cli_errmsg("Phishcheck: Unable to allocate memory for initialization\n");
			return CL_EMEM;
        }
		pchk->is_disabled=1;
	}
	else {
		pchk = engine->phishcheck;
		if(!pchk)
			return CL_ENULLARG;
		if(!pchk->is_disabled) {
			/* already initialized */
			return CL_SUCCESS;
		}
	}

	cli_dbgmsg("Initializing phishcheck module\n");

	if(build_regex(&pchk->preg_numeric,numeric_url_regex,1)) {
		mpool_free(engine->mempool, pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}
	pchk->is_disabled = 0;
	cli_dbgmsg("Phishcheck module initialized\n");
	return CL_SUCCESS;
}
コード例 #3
0
ファイル: example.c プロジェクト: johnbartholomew/libnfa
int main(int argc, char **argv) {
   Nfa *nfa;
   NfaCapture captures[MAX_CAPTURES];

   if (argc < 2) {
      fprintf(stderr, "usage: example PATTERN\n");
      return EXIT_FAILURE;
   }

   memset(captures, 0, sizeof(captures));

   nfa = build_regex(argv[1]);
   if (nfa) {
#ifndef NFA_NO_STDIO
      nfa_print_machine(nfa, stdout);
#endif
      if (argc > 2) {
         int i;
         for (i = 2; i < argc; ++i) {
            const int matched = nfa_match(nfa, captures, MAX_CAPTURES, argv[i], -1);
            if (matched < 0) {
               printf("error: %s\n", nfa_error_string(matched));
               continue;
            }
            printf("%s: '%s'\n", (matched ? "   MATCH" : "NO MATCH"), argv[i]);
            if (matched) {
               int j;
               for (j = 0; j < MAX_CAPTURES; ++j) {
                  int b = captures[j].begin;
                  int e = captures[j].end;
                  if (b || e) {
                     printf("capture %d: %d--%d '%.*s'\n", j, b, e, e - b, argv[i] + b);
                  }
               }
            }
         }
      }
      free(nfa);
   }
   return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: revparse.c プロジェクト: Arhzi/libgit2
static int maybe_describe(git_object**out, git_repository *repo, const char *spec)
{
	const char *substr;
	int error;
	regex_t regex;

	substr = strstr(spec, "-g");

	if (substr == NULL)
		return GIT_ENOTFOUND;

	if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0)
		return -1;

	error = regexec(&regex, spec, 0, NULL, 0);
	regfree(&regex);

	if (error)
		return GIT_ENOTFOUND;

	return maybe_abbrev(out, repo, substr+2);
}
コード例 #5
0
ファイル: revparse.c プロジェクト: Arhzi/libgit2
static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position)
{
	git_reference *ref = NULL;
	git_reflog *reflog = NULL;
	regex_t preg;
	int error = -1;
	size_t i, numentries, cur;
	const git_reflog_entry *entry;
	const char *msg;
	regmatch_t regexmatches[2];
	git_buf buf = GIT_BUF_INIT;

	cur = position;

	if (*identifier != '\0' || *base_ref != NULL)
		return GIT_EINVALIDSPEC;

	if (build_regex(&preg, "checkout: moving from (.*) to .*") < 0)
		return -1;

	if (git_reference_lookup(&ref, repo, GIT_HEAD_FILE) < 0)
		goto cleanup;

	if (git_reflog_read(&reflog, repo, GIT_HEAD_FILE) < 0)
		goto cleanup;

	numentries  = git_reflog_entrycount(reflog);

	for (i = 0; i < numentries; i++) {
		entry = git_reflog_entry_byindex(reflog, i);
		msg = git_reflog_entry_message(entry);
		if (!msg)
			continue;

		if (regexec(&preg, msg, 2, regexmatches, 0))
			continue;

		cur--;

		if (cur > 0)
			continue;

		git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);

		if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0)
			goto cleanup;

		if (error < 0 && error != GIT_ENOTFOUND)
			goto cleanup;

		error = maybe_abbrev(out, repo, git_buf_cstr(&buf));

		goto cleanup;
	}

	error = GIT_ENOTFOUND;

cleanup:
	git_reference_free(ref);
	git_buf_free(&buf);
	regfree(&preg);
	git_reflog_free(reflog);
	return error;
}
コード例 #6
0
static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *spec, const char *identifier, unsigned int position)
{
	git_reference *ref = NULL;
	git_reflog *reflog = NULL;
	regex_t preg;
	int numentries, i, cur, error = -1;
	const git_reflog_entry *entry;
	const char *msg;
	regmatch_t regexmatches[2];
	git_buf buf = GIT_BUF_INIT;

	cur = position;

	if (*identifier != '\0' || *base_ref != NULL)
		return revspec_error(spec);

	if (build_regex(&preg, "checkout: moving from (.*) to .*") < 0)
		return -1;

	if (git_reference_lookup(&ref, repo, GIT_HEAD_FILE) < 0)
		goto cleanup;

	if (git_reflog_read(&reflog, ref) < 0)
		goto cleanup;

	numentries  = git_reflog_entrycount(reflog);

	for (i = numentries - 1; i >= 0; i--) {
		entry = git_reflog_entry_byindex(reflog, i);
		msg = git_reflog_entry_msg(entry);
		
		if (regexec(&preg, msg, 2, regexmatches, 0))
			continue;

		cur--;

		if (cur > 0)
			continue;
		
		git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);

		if ((error = disambiguate_refname(base_ref, repo, git_buf_cstr(&buf))) == 0)
			goto cleanup;

		if (error < 0 && error != GIT_ENOTFOUND)
			goto cleanup;

		error = maybe_sha_or_abbrev(out, repo, git_buf_cstr(&buf));

		goto cleanup;
	}
	
	error = GIT_ENOTFOUND;

cleanup:
	git_reference_free(ref);
	git_buf_free(&buf);
	regfree(&preg);
	git_reflog_free(reflog);
	return error;
}
コード例 #7
0
int phishing_init(struct cl_engine* engine)
{
	char *url_regex, *realurl_regex;
	struct phishcheck* pchk;
	if(!engine->phishcheck) {
		pchk = engine->phishcheck = cli_malloc(sizeof(struct phishcheck));
		if(!pchk)
			return CL_EMEM;
		pchk->is_disabled = 1;
	}
	else {
		pchk = engine->phishcheck;
		if(!pchk)
			return CL_ENULLARG;
		if(!pchk->is_disabled) {
			/* already initialized */
			return CL_SUCCESS;
		}
	}

	cli_dbgmsg("Initializing phishcheck module\n");

	if(build_regex(&pchk->preg_hexurl,cloaked_host_regex,1)) {
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}

	if(build_regex(&pchk->preg_cctld,cctld_regex,1)) {
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}
	if(build_regex(&pchk->preg_tld,tld_regex,1)) {
		free_regex(&pchk->preg_cctld);
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;	
	}
	url_regex = str_compose("^ *(("URI_CHECK_PROTOCOLS")|("URI_fragmentaddress1,URI_fragmentaddress2,URI_fragmentaddress3")) *$");
	if(build_regex(&pchk->preg,url_regex,1)) {
		free_regex(&pchk->preg_cctld);
		free_regex(&pchk->preg_tld);
		free(url_regex);
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}
	free(url_regex);
	realurl_regex = str_compose("^ *(("URI_CHECK_PROTOCOLS")|("URI_path1,URI_fragmentaddress2,URI_fragmentaddress3")) *$");
	if(build_regex(&pchk->preg_realurl, realurl_regex,1)) {
		free_regex(&pchk->preg_cctld);
		free_regex(&pchk->preg_tld);
		free_regex(&pchk->preg);
		free(url_regex);
		free(realurl_regex);
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}
	free(realurl_regex);
	if(build_regex(&pchk->preg_numeric,numeric_url_regex,1)) {
		free_regex(&pchk->preg_cctld);
		free_regex(&pchk->preg_tld);
		free_regex(&pchk->preg);
		free_regex(&pchk->preg_realurl);
		free(pchk);
		engine->phishcheck = NULL;
		return CL_EFORMAT;
	}
	pchk->is_disabled = 0;
	cli_dbgmsg("Phishcheck module initialized\n");
	return CL_SUCCESS;
}