Beispiel #1
0
PGM_GNUC_INTERNAL
void
pgm__logv (
	const int		log_level,
	const char*		format,
	va_list			args
	)
{
	char tbuf[1024];

	pgm_mutex_lock (&messages_mutex);
	const int offset = pgm_snprintf_s (tbuf, sizeof (tbuf), _TRUNCATE, "%s: ", log_level_text (log_level));
	pgm_vsnprintf_s (tbuf + offset, sizeof(tbuf) - offset, _TRUNCATE, format, args);
	if (log_handler) {
		log_handler (log_level, tbuf, log_handler_closure);
	} else {
#ifdef _MSC_VER
		const int stdoutfd = _fileno (stdout);
		_write (stdoutfd, tbuf, (unsigned)strlen (tbuf));
		_write (stdoutfd, "\n", 1);
#else
/* ignore return value */
		(void) write (STDOUT_FILENO, tbuf, strlen (tbuf));
		(void) write (STDOUT_FILENO, "\n", 1);
#endif
	}
		
	pgm_mutex_unlock (&messages_mutex);
}
Beispiel #2
0
/****************
 * This is our log function which prints all log messages to stderr or
 * using the function defined with gcry_set_log_handler().
 */
static void
_gcry_logv( int level, const char *fmt, va_list arg_ptr )
{
  if (log_handler)
    log_handler (log_handler_value, level, fmt, arg_ptr);
  else 
    {
      switch (level) 
        {
        case GCRY_LOG_CONT:  break;
        case GCRY_LOG_INFO:  break;
        case GCRY_LOG_WARN:  break;
        case GCRY_LOG_ERROR: break;
        case GCRY_LOG_FATAL: fputs("Fatal: ",stderr ); break;
        case GCRY_LOG_BUG:   fputs("Ohhhh jeeee: ", stderr); break;
        case GCRY_LOG_DEBUG: fputs("DBG: ", stderr ); break;
        default: fprintf(stderr,"[Unknown log level %d]: ", level ); break;
	}
      vfprintf(stderr,fmt,arg_ptr) ;
    }
  
  if ( level == GCRY_LOG_FATAL || level == GCRY_LOG_BUG )
    {
      fips_signal_fatal_error ("internal error (fatal or bug)");
      _gcry_secmem_term ();
      abort ();
    }
}
Beispiel #3
0
static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
                           const gchar *message, gpointer data)
{
    if (ob_state() == OB_STATE_RUNNING)
        prompt_show_message(message, _("Openbox"), _("Close"));
    else
        log_handler(log_domain, log_level, message, data);
}
Beispiel #4
0
void blog(int log_level, const char *format, ...)
{
	va_list args;

	va_start(args, format);
	log_handler(log_level, format, args);
	va_end(args);
}
Beispiel #5
0
void
sc_log (const char *filename, int lineno,
        int package, int category, int priority, const char *msg)
{
  int                 log_threshold;
  sc_log_handler_t    log_handler;
  sc_package_t       *p;

  if (package != -1 && !sc_package_is_registered (package)) {
    package = -1;
  }
  if (package == -1) {
    p = NULL;
    log_threshold = sc_default_log_threshold;
    log_handler = sc_default_log_handler;
  }
  else {
    p = sc_packages + package;
    log_threshold =
      (p->log_threshold ==
       SC_LP_DEFAULT) ? sc_default_log_threshold : p->log_threshold;
    log_handler =
      (p->log_handler == NULL) ? sc_default_log_handler : p->log_handler;
  }
  if (!(category == SC_LC_NORMAL || category == SC_LC_GLOBAL))
    return;
  if (!(priority > SC_LP_ALWAYS && priority < SC_LP_SILENT))
    return;
  if (category == SC_LC_GLOBAL && sc_identifier > 0)
    return;

#ifdef SC_ENABLE_PTHREAD
  sc_package_lock (package);
#endif
  if (sc_trace_file != NULL && priority >= sc_trace_prio)
    log_handler (sc_trace_file, filename, lineno,
                 package, category, priority, msg);

  if (priority >= log_threshold)
    log_handler (sc_log_stream != NULL ? sc_log_stream : stdout,
                 filename, lineno, package, category, priority, msg);
#ifdef SC_ENABLE_PTHREAD
  sc_package_unlock (package);
#endif
}
Beispiel #6
0
static void __run_bq(void *_job) {
	bq_job_base_t *job = (bq_job_base_t *)_job;

	log::handler_default_t log_handler(job->name, &job->log_backend);

	safe_run(*job, &bq_job_base_t::_run);

	delete job;
}
Beispiel #7
0
static void
glib_vlog(os_handler_t         *handler,
	  enum ipmi_log_type_e log_type,
	  const char           *format,
	  va_list              ap)
{
    GLogLevelFlags  flags;
    vlog_data_t     *info;
    g_os_hnd_data_t *ginfo = handler->internal_data;
    os_vlog_t       log_handler = ginfo->log_handler;

    if (log_handler) {
	log_handler(handler, format, log_type, ap);
	return;
    }

    switch (log_type) {
    case IPMI_LOG_INFO:		flags = G_LOG_LEVEL_INFO; break;
    case IPMI_LOG_WARNING:	flags = G_LOG_LEVEL_WARNING; break;
    case IPMI_LOG_SEVERE:	flags = G_LOG_LEVEL_CRITICAL; break;
    case IPMI_LOG_FATAL:	flags = G_LOG_LEVEL_ERROR; break;
    case IPMI_LOG_ERR_INFO:	flags = G_LOG_LEVEL_MESSAGE; break;
    case IPMI_LOG_DEBUG:	flags = G_LOG_LEVEL_DEBUG; break;

    case IPMI_LOG_DEBUG_END:
	info = get_vlog_data();
	if (!info)
	    return;
	add_vlog_data(info, format, ap);
	g_log("OpenIPMI", G_LOG_LEVEL_DEBUG, "%s", info->data);
	info->curr = 0;
	return;

    case IPMI_LOG_DEBUG_START:
	info = get_vlog_data();
	if (!info)
	    return;
	info->curr = 0;
	add_vlog_data(info, format, ap);
	return;

    case IPMI_LOG_DEBUG_CONT:
	info = get_vlog_data();
	if (!info)
	    return;
	add_vlog_data(info, format, ap);
	return;

    default:
	flags = G_LOG_LEVEL_INFO;
	break;
    }

    g_logv("OpenIPMI", flags, format, ap);
}
Beispiel #8
0
int log_warn(const char *fmt, ...) {
    int rc= LOG_OK;
    va_list args;
    if (log_level >= LOG_LEVEL_WARN) {
        va_start(args,fmt);
        if (log_handler != NULL) {
            rc= log_handler(LOG_LEVEL_WARN,fmt,args);
        }
        va_end(args);
    }
    return rc;
}
Beispiel #9
0
static void *__run_thr(void *_job) {
	bq_job_base_t *job = (bq_job_base_t *)_job;

	MKCSTR(_name, job->name);

	prctl(PR_SET_NAME, _name);

	log::handler_default_t log_handler(job->name, &job->log_backend);

	safe_run(*job, &bq_job_base_t::_run);

	delete job;

	return NULL;
}
Beispiel #10
0
int log_redirect(unsigned int level, const char *format, ...)
{
  if((log_levels & level)==0)
    return 0;
  if(log_handle==NULL)
    return 0;
  {
    int res;
    va_list ap;
    va_start(ap, format);
    res=log_handler(format, ap);
    va_end(ap);
    return res;
  }
}
static void
sposix_vlog(os_handler_t         *handler,
	    enum ipmi_log_type_e log_type,
	    const char           *format,
	    va_list              ap)
{
    pt_os_hnd_data_t *info = handler->internal_data;
    os_vlog_t        log_handler = info->log_handler;

    if (log_handler)
	log_handler(handler, format, log_type, ap);
    else if (posix_vlog)
	posix_vlog((char *) format, log_type, ap);
    else
	default_vlog(format, log_type, ap);
}
Beispiel #12
0
void log_message(LogCategory category, LogLevel level,
                 const char *file, int line,
                 const char *function, const char *format, ...)
{
	va_list arguments;

	if (level > _levels[category]) {
		return;
	}

	va_start(arguments, format);
	mutex_lock(&_mutex);

	log_handler(level, file, line, function, format, arguments);
	log_handler_platform(level, file, line, function, format, arguments);

	mutex_unlock(&_mutex);
	va_end(arguments);
}
Beispiel #13
0
DECLARE_TEST(error, output) {
#if BUILD_ENABLE_LOG
	error_handler_fn handler_error = error_handler();
	log_handler_fn handler_log = log_handler();
	string_const_t shortmsg = string_const(STRING_CONST("Short message with prefix"));
    string_const_t longmsg = string_const(STRING_CONST("Longer message which should be output without a prefix"));

	error_set_handler(ignore_error_handler);
	log_set_handler(log_verify_handler);

    log_enable_stdout(false);
    EXPECT_EQ(log_stdout(), false);
    log_warn(HASH_TEST, WARNING_SUSPICIOUS, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
    EXPECT_EQ(log_stdout(), true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [suspicious]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_warn(HASH_TEST, (warning_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_prefix(false);
    log_enable_stdout(false);
	log_warn(HASH_TEST, WARNING_SYSTEM_CALL_FAIL, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

#  if BUILD_ENABLE_ERROR_CONTEXT
    
	error_context_push(STRING_CONST("one"), STRING_CONST("dataone"));
	error_context_push(STRING_CONST("two"), STRING_CONST("datatwo"));
	error_context_push(STRING_CONST("three"), STRING_CONST("datathree"));

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error_context(HASH_TEST, ERRORLEVEL_INFO);
    log_enable_stdout(true);

    error_context_pop();
    error_context_pop();
    error_context_pop();

	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When one: dataone"), 0), STRING_NPOS);
	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When two: datatwo"), 0), STRING_NPOS);
	EXPECT_SIZENE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When three: datathree"), 0), STRING_NPOS);

#  endif

	log_set_handler(handler_log);
	error_set_handler(handler_error);
#endif
	return 0;
}
Beispiel #14
0
void app_log(const std::string &msg)
{
    log_handler(msg.c_str(), RendNotice);
}
Beispiel #15
0
static gboolean mpv_event_handler(gpointer data)
{
	GmpvMpv *mpv = data;
	gboolean done = !mpv;

	while(!done)
	{
		mpv_event *event =	mpv->mpv_ctx?
					mpv_wait_event(mpv->mpv_ctx, 0):
					NULL;

		if(!event)
		{
			done = TRUE;
		}
		else if(event->event_id == MPV_EVENT_PROPERTY_CHANGE)
		{
			mpv_event_property *prop = event->data;

			mpv_prop_change_handler(mpv, prop);

			g_signal_emit_by_name(	mpv,
						"mpv-prop-change",
						prop->name );
		}
		else if(event->event_id == MPV_EVENT_IDLE)
		{
			if(mpv->state.loaded)
			{
				mpv->state.loaded = FALSE;

				gmpv_mpv_set_property_flag
					(mpv, "pause", TRUE);
				gmpv_playlist_reset(mpv->playlist);
			}

			mpv->state.init_load = FALSE;
		}
		else if(event->event_id == MPV_EVENT_FILE_LOADED)
		{
			mpv->state.loaded = TRUE;
			mpv->state.init_load = FALSE;

			update_playlist(mpv);
		}
		else if(event->event_id == MPV_EVENT_END_FILE)
		{
			mpv_event_end_file *ef_event = event->data;

			mpv->state.init_load = FALSE;

			if(mpv->state.loaded)
			{
				mpv->state.new_file = FALSE;
			}

			if(ef_event->reason == MPV_END_FILE_REASON_ERROR)
			{
				const gchar *err;
				gchar *msg;

				err = mpv_error_string(ef_event->error);
				msg = g_strdup_printf
					(	_("Playback was terminated "
						"abnormally. Reason: %s."),
						err );

				gmpv_mpv_set_property_flag
					(mpv, "pause", TRUE);
				g_signal_emit_by_name(mpv, "mpv-error", msg);

				g_free(msg);
			}
		}
		else if(event->event_id == MPV_EVENT_VIDEO_RECONFIG)
		{
			if(mpv->state.new_file)
			{
				gmpv_mpv_opt_handle_autofit(mpv);
			}
		}
		else if(event->event_id == MPV_EVENT_PLAYBACK_RESTART)
		{
			g_signal_emit_by_name(mpv, "mpv-playback-restart");
		}
		else if(event->event_id == MPV_EVENT_LOG_MESSAGE)
		{
			log_handler(mpv, event->data);
		}
		else if(event->event_id == MPV_EVENT_SHUTDOWN
		|| event->event_id == MPV_EVENT_NONE)
		{
			done = TRUE;
		}

		if(event)
		{
			if(mpv->event_callback)
			{
				mpv->event_callback
					(event, mpv->event_callback_data);
			}

			if(mpv->mpv_ctx)
			{
				g_signal_emit_by_name
					(mpv, "mpv-event", event->event_id);
			}
			else
			{
				done = TRUE;
			}
		}
	}

	return FALSE;
}
Beispiel #16
0
DECLARE_TEST(exception, assert_handler) {
    EXPECT_EQ(assert_handler(), 0);

    assert_set_handler(handle_assert);
    EXPECT_EQ(assert_handler(), handle_assert);

    log_enable_stdout(false);
    EXPECT_EQ(assert_report(1, STRING_CONST("condition"), STRING_CONST("file"), 2, STRING_CONST("msg")),
              1234);
    log_enable_stdout(true);
    EXPECT_EQ(assert_handler(), handle_assert);
    EXPECT_EQ(handled_context, 1);
    EXPECT_STRINGEQ(string(handled_condition, string_length(handled_condition)), string_const(STRING_CONST("condition")));
    EXPECT_STRINGEQ(string(handled_file, string_length(handled_file)), string_const(STRING_CONST("file")));
    EXPECT_EQ(handled_line, 2);
    EXPECT_STRINGEQ(string(handled_msg, string_length(handled_msg)), string_const(STRING_CONST("msg")));

    assert_set_handler(0);
    EXPECT_EQ(assert_handler(), 0);

#if BUILD_ENABLE_LOG
    _global_log_handler = log_handler();
    log_set_handler(handle_log);
#endif
    log_enable_stdout(false);
    EXPECT_EQ(assert_report_formatted(1, STRING_CONST("assert_report_formatted"), STRING_CONST("file"),
                                      2, STRING_CONST("%.*s"), 3, "msg"), 1);
    log_enable_stdout(true);
    EXPECT_EQ(error(), ERROR_ASSERT);
#if BUILD_ENABLE_LOG
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log),
                                   STRING_CONST("assert_report_formatted"), 0) != STRING_NPOS);
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log), STRING_CONST("msg"),
                                   0) != STRING_NPOS);

    log_enable_stdout(false);
    log_set_suppress(HASH_TEST, ERRORLEVEL_NONE);
#if BUILD_ENABLE_DEBUG_LOG
    log_debugf(HASH_TEST, STRING_CONST("%s"),
#else
    log_infof(HASH_TEST, STRING_CONST("%s"),
#endif
               "To test log handler and memory handling this test will print "
               "a really long log line with complete nonsense. Log handlers only occur for non-suppressed "
               "log levels, which is why this will be visible. However, it will not be printed to stdout. "
               "Lorem ipsum dolor sit amet, an quas vivendum sed, in est summo conclusionemque, an est nulla nonumy option. "
               "Malorum invidunt et mel, mei et hinc adolescens, eu velit deleniti urbanitas cum. Ei pericula omittantur duo, "
               "eam ei malis pertinacia, eum hinc dictas et. Duo et velit dolorem explicari, an tacimates abhorreant qui, "
               "esse possit intellegat ad vis. Eros populo numquam pro ea. Eius altera volumus duo ex, offendit comprehensam "
               "sit te. Ea facete nostrum fabellas sea. Vel ea rebum ridens quodsi, etiam urbanitas mea an. Ornatus commune et his, "
               "quo habeo denique an, id his amet diceret. Eam ei essent denique, cu quaestio perpetua vim. Mei utamur maluisset ex, "
               "iriure tritani eu per. Pro at rebum maluisset, nec ei eirmod scaevola consulatu, ius in meis patrioque. Vis at summo "
               "ancillae omnesque, inani moderatius delicatissimi qui an. Et illum vocibus eum, aliquando intellegat ex ius. Ius at "
               "tation veritus. Scripta reprehendunt at sed. Hinc idque mollis in cum, at elit habemus civibus eam, sea et modus "
               "eripuit. Alii ipsum electram id vel, mei alterum percipitur cu. Pro cu minim erant graecis, no vis tation nominavi "
               "imperdiet, mei affert probatus ut. Quo veri modus ad, solet nostrud atomorum ius ea. Everti aliquid ne usu, populo "
               "sapientem pro te. Persecuti definitionem qui ei, dicit dicunt ea quo. Sed minimum copiosae ei, pri dicat possit "
               "urbanitas eu. Tritani interesset theophrastus id sit, phaedrum facilisis his eu. Dictas accusam eu quo. Ea democritum "
               "consetetur vel. Iudicabit definitionem est eu, oportere temporibus at nec."
              );
    log_set_suppress(HASH_TEST, ERRORLEVEL_DEBUG);
    log_enable_stdout(true);
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log), STRING_CONST("Lorem ipsum"),
                                   0) != STRING_NPOS);

    log_set_handler(_global_log_handler);
#endif

    return 0;
}
Beispiel #17
0
void blogva(int log_level, const char *format, va_list args)
{
	log_handler(log_level, format, args);
}
Beispiel #18
0
/**
 * @brief sighandler the signal handler of zimg
 *
 * @param signal the signal zimg get
 * @param siginfo signal info
 * @param arg the arg for handler
 */
static void sighandler(int signal, siginfo_t *siginfo, void *arg) {
    char msg[128];
    msg[0] = '\0';
    str_lcat(msg, "----/--/-- --:--:--:------ [INFO] signal Terminal received zimg shutting down", sizeof(msg));
    //str_lcat(msg, strsignal(signal));
    log_handler(msg);
    write(STDOUT_FILENO, "\nbye bye!\n", 10);

    //evbase_t *evbase = (evbase_t *)arg;
    struct timeval tv = { .tv_usec = 100000, .tv_sec = 0 }; /* 100 ms */
    event_base_loopexit(evbase, &tv);
}

/**
 * @brief init_thread the init function of threads
 *
 * @param htp evhtp object
 * @param thread the current thread
 * @param arg the arg for init
 */
void init_thread(evhtp_t *htp, evthr_t *thread, void *arg) {
    thr_arg_t *thr_args;
    thr_args = calloc(1, sizeof(thr_arg_t));
    LOG_PRINT(LOG_DEBUG, "thr_args alloc");
    thr_args->thread = thread;

    char mserver[32];

    if (settings.cache_on == true) {
        memcached_st *memc = memcached_create(NULL);
        snprintf(mserver, 32, "%s:%d", settings.cache_ip, settings.cache_port);
        memcached_server_st *servers = memcached_servers_parse(mserver);
        memcached_server_push(memc, servers);
        memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
        memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
        memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
        memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, 1);
        thr_args->cache_conn = memc;
        LOG_PRINT(LOG_DEBUG, "Memcached Connection Init Finished.");
        memcached_server_list_free(servers);
    } else
        thr_args->cache_conn = NULL;

    if (settings.mode == 2) {
        thr_args->ssdb_conn = NULL;
        memcached_st *beans = memcached_create(NULL);
        snprintf(mserver, 32, "%s:%d", settings.beansdb_ip, settings.beansdb_port);
        memcached_server_st *servers = memcached_servers_parse(mserver);
        servers = memcached_servers_parse(mserver);
        memcached_server_push(beans, servers);
        memcached_behavior_set(beans, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 0);
        memcached_behavior_set(beans, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
        memcached_behavior_set(beans, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, 1);
        thr_args->beansdb_conn = beans;
        LOG_PRINT(LOG_DEBUG, "beansdb Connection Init Finished.");
        memcached_server_list_free(servers);
    } else if (settings.mode == 3) {
        thr_args->beansdb_conn = NULL;
        redisContext* c = redisConnect(settings.ssdb_ip, settings.ssdb_port);
        if (c->err) {
            redisFree(c);
            LOG_PRINT(LOG_DEBUG, "Connect to ssdb server faile");
        } else {
            thr_args->ssdb_conn = c;
            LOG_PRINT(LOG_DEBUG, "Connect to ssdb server Success");
        }
    }

    thr_args->L = luaL_newstate();
    LOG_PRINT(LOG_DEBUG, "luaL_newstate alloc");
    if (thr_args->L != NULL) {
        luaL_openlibs(thr_args->L);
        luaL_openlib(thr_args->L, "zimg", zimg_lib, 0);
        luaL_openlib(thr_args->L, "log", loglib, 0);
    }
    luaL_loadfile(thr_args->L, settings.script_name);
    lua_pcall(thr_args->L, 0, 0, 0);

    evthr_set_aux(thread, thr_args);

    lua_State *L = luaL_newstate();
    if (L != NULL) {
        luaL_openlibs(L);
        if (luaL_loadfile(L, conf_file) || lua_pcall(L, 0, 0, 0)) {
            lua_close(L);
        } else {
            pthread_setspecific(gLuaStateKey, (void *)L);
        }
    }
}
int main(int argc, char* argv[])
{
    std::string server;
    std::string port;
    std::string user;
    std::string folder;
    std::string password;
    std::vector<fs::path> from;
    std::vector<fs::path> entity;
    fs::path to;
    
    //[Gmail]/Sent Mail
    po::options_description general_options("General");
    general_options.add_options()
        ("help", "list options");
    po::options_description file_options("Load");
    file_options.add_options()
        ("save-raw", po::value<fs::path>(&to), "path to save the data (after download phase)");
    po::options_description download_options("Download");
    download_options.add_options()
        ("server", po::value<std::string>(&server), "imap server dns/ip")
        ("port", po::value<std::string>(&port)->default_value("993"), "imap port")
        ("folder", po::value<std::string>(&folder)->default_value("Sent"), "imap folder")
        ("user", po::value<std::string>(&user), "imap username")
        ("password", po::value<std::string>(&password), "imap password (will ask if not specified)");
    po::options_description run_options("Run");
    
    po::options_description all_options("Email Topology Options");
    all_options
        .add(general_options)
        .add(file_options)
        .add(download_options);

    if(argc < 2) {
        std::cout << all_options << std::endl;
        return 1;
    }

    po::variables_map vm;
    try {
        int options_style = po::command_line_style::default_style;
        po::store(po::parse_command_line(argc, argv, all_options, options_style), vm);
        po::notify(vm);
    } catch(std::exception& e) {
        std::cout << all_options << std::endl;
        std::cout << "Command line parsing failed: " << e.what() << std::endl;
        return 1;
    }
    
    if(vm.count("help")) {
        std::cout << all_options << std::endl;
        return 1;
    }

    email_id_bimap email_id;
    connectedness_graph cg;
    entity_map em;
    initial_group_partition_map igpm;

    if(!vm.count("save-raw")) {
        std::cout << "you must specify --save-raw with a file name" << std::endl;
        return 1;
    }
    if(!vm.count("password")) {
        password = getpass("Password: "******"missing server for download" << std::endl;
        return 1;
    }
    if(user.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    if(password.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    //this is our network block, downloads all messages headers
    try
    {
        std::cout << "downloading " << folder << " from " << server << std::endl;
        //use to dedupe if there are dupes
        message_id_set message_id;        

        typedef boost::function<void (const std::string&, const std::list<std::string>& args)> untagged_handler;
        std::string pending_tag = "* ";
        std::list<std::string> pending_command;
        pending_command.push_back("WAIT_FOR_ACK");
        untagged_handler pending_handler;
        unsigned int command_id = 0;

        //The sequence of imap commands we want to run
        std::list<std::list<std::string> > commands;
        std::list<untagged_handler> handlers;

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        std::ostringstream login_os;
        login_os << "LOGIN \"" << user << "\" {" << password.size() << "}";
        commands.back().push_back(login_os.str()); 
        commands.back().push_back(password); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("LIST \"\" *"); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("SELECT \"" + folder + "\""); 

        handlers.push_back(header_handler(email_id, cg, em, message_id, igpm));
        commands.push_back(std::list<std::string>());
        commands.back().push_back("FETCH 1:* (BODY.PEEK[HEADER.FIELDS (MESSAGE-ID FROM TO CC)])");
        commands.push_back(std::list<std::string>());

        handlers.push_back(log_handler());
        commands.back().push_back("LOGOUT");
    
        //open ssl connection to the server, no cert checking
        asio::io_service io_service;
        asio::ip::tcp::resolver resolver(io_service);
        asio::ip::tcp::resolver::query query(server, port);
        asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
        asio::ssl::context context(io_service, asio::ssl::context::sslv23);
        context.set_verify_mode(asio::ssl::context::verify_none);
        asio::ssl::stream<asio::ip::tcp::socket> socket(io_service, context);
        socket.lowest_layer().connect(*iterator);
        socket.handshake(asio::ssl::stream_base::client);
        asio::streambuf buf;

        while(true) {
            //read the next line of data
            std::size_t line_length = asio::read_until(socket, buf, re_crlf);
            std::string line(
                asio::buffers_begin(buf.data()),
                asio::buffers_begin(buf.data()) + line_length);
            buf.consume(line_length);
            boost::match_results<std::string::iterator> what;
            std::size_t initial = 0;
            std::list<std::string> args;
            //the line may be split into segments with chunks of data embedded, this is the case
            //for bodies or message header blocks that are returned, we only handle this case if it
            //comes in untagged response (*) not a continuation (+), i think that is normal
            while(regex_search(line.begin() + initial, line.end(), what, re_byte_buffer, boost::match_default)) {
                unsigned int bytes = boost::lexical_cast<unsigned int>(what[1].str());
                if(buf.size() < bytes)
                    asio::read(socket, buf, asio::transfer_at_least(bytes - buf.size()));
                args.push_back(
                    std::string(
                        asio::buffers_begin(buf.data()),
                        asio::buffers_begin(buf.data()) + bytes));
                buf.consume(bytes);
                line.resize(what[1].second - line.begin());
                initial = line.size();
                //read the next line of data
                line_length = asio::read_until(socket, buf, re_crlf);
                line += std::string(
                    asio::buffers_begin(buf.data()),
                    asio::buffers_begin(buf.data()) + line_length);
                buf.consume(line_length);
            }
            if(boost::algorithm::starts_with(line, pending_tag)) {
                //if the command is being completed, then we will go here, bail out if the response wasn't ok
                if(!boost::algorithm::starts_with(line, pending_tag + "OK")) {
                    std::cout << line;
                    throw std::runtime_error("command failed");
                }
                //pull the next command off the list
                pending_tag = "A" + boost::lexical_cast<std::string>(command_id++) + " ";
                if(commands.size() == 0)
                    break;
                pending_handler = handlers.front();
                pending_command = commands.front();
                commands.pop_front();
                handlers.pop_front();

                //send the command along with any data arguments
                std::cout << pending_tag << pending_command.front() << std::endl;
                asio::write(socket, asio::buffer(pending_tag.data(), pending_tag.size()));
                for(std::list<std::string>::iterator i = pending_command.begin(); i != pending_command.end(); ++i) {
                    if(i != pending_command.begin()) {
                        //print the continuation response
                        std::size_t line_length = asio::read_until(socket, buf, re_crlf);
                        std::string line(
                            asio::buffers_begin(buf.data()),
                            asio::buffers_begin(buf.data()) + line_length);
                        buf.consume(line_length);
                        std::cout << line << std::flush;
                        if(!boost::algorithm::starts_with(line, "+ ")) {
                            throw std::runtime_error("bad response when writing extra data");
                        }
                    } else {
                        //print it out as well (but not the args)
                        std::cout << *i << std::endl;
                    }
                    asio::write(socket, asio::buffer(i->data(), i->size()));
                    asio::write(socket, asio::buffer("\r\n", 2));
                }
            } else if(boost::algorithm::starts_with(line, "* ")) {
                //if there is a registered handler, dispatch to it
                if(pending_handler)
                    pending_handler(line, args);
            } else {
                throw std::runtime_error("unrecognized response");
            }
        }
    }
    catch (std::exception& e) {
        std::cout << "Exception: " << e.what() << std::endl;
        return 1;
    }
    std::cout << std::endl;
    
    if(to.empty()) {
        std::cout << "Missing output file for save" << std::endl;
        return 1;
    }
    if(fs::exists(to))
        fs::remove(to);
    fs::ofstream out(to);
    std::cout << "saving data to " << to.file_string();        
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        out << (unsigned long long)cg[*i].weight;
        for(members_t::iterator j = cg[*i].members.begin(); j != cg[*i].members.end(); ++j) {
            out << "\t" << email_id.by<bit>().equal_range(*j).first->second;
        }
        out << std::endl;
    }
    out << "-" << std::endl;
    for(entity_map::iterator i = em.begin(); i != em.end(); ++i) {
        out << i->first;
        for(std::set<std::string>::iterator k = i->second.begin(); k != i->second.end(); ++k) {
            out << "\t" << *k; 
        }
        out << std::endl;
    }
    return 0;
}