예제 #1
0
int sieve_test
(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
	const struct sieve_script_env *senv, struct sieve_error_handler *ehandler,
	struct ostream *stream, enum sieve_runtime_flags flags, bool *keep)
{
	struct sieve_result *result = NULL;
	int ret;

	if ( keep != NULL ) *keep = FALSE;

	/* Run the script */
	ret = sieve_run(sbin, &result, msgdata, senv, ehandler, flags);

	/* Print result if successful */
	if ( ret > 0 ) {
		ret = sieve_result_print(result, senv, stream, keep);
	} else if ( ret == 0 ) {
		if ( keep != NULL ) *keep = TRUE;
	}

	/* Cleanup */
	if ( result != NULL )
		sieve_result_unref(&result);

	return ret;
}
예제 #2
0
파일: sieve.c 프로젝트: dovecot/pigeonhole
void sieve_multiscript_run_discard
(struct sieve_multiscript *mscript, struct sieve_binary *sbin,
	struct sieve_error_handler *exec_ehandler,
	struct sieve_error_handler *action_ehandler,
	enum sieve_execute_flags flags)
{
	if ( !sieve_multiscript_will_discard(mscript) )
		return;
	i_assert( !mscript->discard_handled );

	sieve_result_set_keep_action
		(mscript->result, NULL, &act_store);

	/* Run the discard script */
	mscript->status = sieve_run(sbin, &mscript->result, mscript->msgdata,
		mscript->scriptenv, exec_ehandler, flags);

	if ( mscript->status >= 0 ) {
		mscript->keep = FALSE;

		if ( mscript->teststream != NULL ) {
			sieve_multiscript_test(mscript, &mscript->keep);
		} else {
			sieve_multiscript_execute(mscript,
				action_ehandler, flags, &mscript->keep);
		}
	}

	mscript->discard_handled = TRUE;
}
예제 #3
0
/*------------------------------------------------------------------------*/
static uint64
get_next_composite(sieve_fb_t *s)
{
	while (1) {
		uint32 curr_offset;
		p_sieve_t *p_sieve = &s->p_sieve;
		uint8 *sieve_block = p_sieve->sieve_block;
		uint32 cutoff = MIN(SIEVE_SIZE,
		    		    (s->p_max - p_sieve->sieve_start + 1) / 2);

		for (curr_offset = p_sieve->curr_offset; 
				curr_offset < cutoff; curr_offset++) {

			if (!(sieve_block[curr_offset] & 0x80)) 
				continue;

			p_sieve->curr_offset = curr_offset + 1;
			return p_sieve->sieve_start + (2 * curr_offset + 1);
		}

		p_sieve->sieve_start += 2 * SIEVE_SIZE;
		p_sieve->curr_offset = curr_offset = 0;
		if (p_sieve->sieve_start >= s->p_max)
			break;
		sieve_run(s);
	}

	return P_SEARCH_DONE;
}
예제 #4
0
파일: sieve.c 프로젝트: dovecot/pigeonhole
bool sieve_multiscript_run
(struct sieve_multiscript *mscript, struct sieve_binary *sbin,
	struct sieve_error_handler *exec_ehandler,
	struct sieve_error_handler *action_ehandler,
	enum sieve_execute_flags flags)
{
	if ( !mscript->active ) return FALSE;

	/* Run the script */
	mscript->status = sieve_run(sbin, &mscript->result, mscript->msgdata,
		mscript->scriptenv, exec_ehandler, flags);

	if ( mscript->status >= 0 ) {
		mscript->keep = FALSE;

		if ( mscript->teststream != NULL ) {
			sieve_multiscript_test(mscript, &mscript->keep);
		} else {
			sieve_multiscript_execute(mscript,
				action_ehandler, flags, &mscript->keep);
		}
		mscript->active =
			( mscript->active && mscript->keep && mscript->status > 0 );
	}

	if ( mscript->status <= 0 )
		return FALSE;

	return mscript->active;
}
예제 #5
0
파일: runtime.c 프로젝트: ssvlab/esbmc-gpu
int
mu_sieve_disass (mu_sieve_machine_t mach)
{
  int level = mach->debug_level;
  int rc;

  mach->debug_level = MU_SIEVE_DEBUG_INSTR | MU_SIEVE_DEBUG_DISAS;
  rc = sieve_run (mach);
  mach->debug_level = level;
  return rc;
}
예제 #6
0
파일: runtime.c 프로젝트: ssvlab/esbmc-gpu
static int
_sieve_action (mu_observer_t obs, size_t type, void *data, void *action_data)
{
  mu_sieve_machine_t mach;
  
  if (type != MU_EVT_MESSAGE_ADD)
    return 0;

  mach = mu_observer_get_owner (obs);
  mach->msgno++;
  mu_mailbox_get_message (mach->mailbox, mach->msgno, &mach->msg);
  sieve_run (mach);
  return 0;
}
예제 #7
0
파일: runtime.c 프로젝트: ssvlab/esbmc-gpu
int
mu_sieve_message (mu_sieve_machine_t mach, mu_message_t msg)
{
  int rc;
  
  if (!mach || !msg)
    return EINVAL;

  mach->msgno = 1;
  mach->msg = msg;
  mach->mailbox = NULL;
  rc = sieve_run (mach);
  mach->msg = NULL;
  
  return rc;
}
예제 #8
0
int sieve_execute
(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
	const struct sieve_script_env *senv,
	struct sieve_error_handler *exec_ehandler,
	struct sieve_error_handler *action_ehandler,
	enum sieve_runtime_flags flags, bool *keep)
{
	struct sieve_result *result = NULL;
	int ret;

	if ( keep != NULL ) *keep = FALSE;

	/* Run the script */
	ret = sieve_run(sbin, &result, msgdata, senv, exec_ehandler, flags);

	/* Evaluate status and execute the result:
	 *   Strange situations, e.g. currupt binaries, must be handled by the caller.
	 *   In that case no implicit keep is attempted, because the situation may be
	 *   resolved.
	 */
	if ( ret > 0 ) {
		/* Execute result */
		ret = sieve_result_execute(result, keep, action_ehandler);
	} else if ( ret == SIEVE_EXEC_FAILURE ) {
		/* Perform implicit keep if script failed with a normal runtime error */
		switch ( sieve_result_implicit_keep
			(result, action_ehandler) ) {
		case SIEVE_EXEC_OK:
			if ( keep != NULL ) *keep = TRUE;
			break;
		case SIEVE_EXEC_TEMP_FAILURE:
			ret = SIEVE_EXEC_TEMP_FAILURE;
			break;
		default:
			ret = SIEVE_EXEC_KEEP_FAILED;
		}
	}

	/* Cleanup */
	if ( result != NULL )
		sieve_result_unref(&result);

	return ret;
}
예제 #9
0
/*------------------------------------------------------------------------*/
void 
sieve_fb_reset(sieve_fb_t *s, uint64 p_min, uint64 p_max,
		uint32 num_roots_min, uint32 num_roots_max)
{
	uint32 i;

	free_prime_sieve(&s->p_prime);

	if (p_min % 2)
		p_min--;
	s->p_min = p_min;
	s->p_max = p_max;
	s->num_roots_min = num_roots_min;
	s->num_roots_max = num_roots_max;

	if (p_max > 10000000) {
		p_enum_t *p_enum = &s->p_enum;

		s->curr_algo = ALGO_ENUM;

		p_enum->next_prime = 0;
		p_enum->curr_entry = 0;

		p_enum->curr_list.num_entries = 1;
		p_enum->curr_list.list[0].num_factors = 0;
		p_enum->curr_list.list[0].prod = 1;
	}
	else {
		p_sieve_t *p_sieve = &s->p_sieve;
		sieve_prime_list_t *list;

		s->curr_algo = ALGO_SIEVE;
		p_sieve->sieve_start = p_min;

		list = &p_sieve->good_primes;
		for (i = 0; i < list->num_primes; i++) {

			sieve_prime_t *curr = list->primes + i;
			uint32 p = curr->p;
			uint32 rem = p - p_min % p;

			if (rem != p && rem % 2 == 0)
				rem += p;
			curr->r = rem / 2;
		}

		list = &p_sieve->bad_primes;
		for (i = 0; i < list->num_primes; i++) {

			sieve_prime_t *curr = list->primes + i;
			uint32 p = curr->p;
			uint32 rem = p - p_min % p;

			if (rem != p && rem % 2 == 0)
				rem += p;
			curr->r = rem / 2;
		}

		sieve_run(s);
	}
}