Example #1
0
/**
 * Print a message to the logging system
 *
 * @param level Log level
 * @param fmt   Formatted message
 * @param ap    Variable argument list
 */
void vlog(enum log_level level, const char *fmt, va_list ap)
{
	char buf[4096];
	struct le *le;

	if (level < lg.level)
		return;

	if (re_vsnprintf(buf, sizeof(buf), fmt, ap) < 0)
		return;

	if (lg.enable_stdout) {

		bool color = level == LEVEL_WARN || level == LEVEL_ERROR;

		if (color)
			(void)re_fprintf(stdout, "\x1b[31m"); /* Red */

		(void)re_fprintf(stdout, "%s", buf);

		if (color)
			(void)re_fprintf(stdout, "\x1b[;m");
	}

	le = lg.logl.head;

	while (le) {

		struct log *log = le->data;
		le = le->next;

		if (log->h)
			log->h(level, buf);
	}
}
Example #2
0
/* Formatted output to print handler and/or logfile */
static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
{
	char buf[256];
	int len;

	if (level > dbg.level)
		return;

	if (!dbg.ph && !dbg.f)
		return;

	dbg_lock();

	len = re_vsnprintf(buf, sizeof(buf), fmt, ap);
	if (len <= 0)
		goto out;

	/* Print handler? */
	if (dbg.ph) {
		dbg.ph(level, buf, len, dbg.arg);
	}

	/* Output to file */
	if (dbg.f) {
		if (fwrite(buf, 1, len, dbg.f) > 0)
			(void)fflush(dbg.f);
	}

 out:
	dbg_unlock();
}
Example #3
0
/**
 * Print a formatted string to a buffer
 *
 * @param str  Buffer for output string
 * @param size Size of buffer
 * @param fmt  Formatted string
 *
 * @return The number of characters printed, or -1 if error
 */
int re_snprintf(char *str, size_t size, const char *fmt, ...)
{
	va_list ap;
	int n;

	va_start(ap, fmt);
	n = re_vsnprintf(str, size, fmt, ap);
	va_end(ap);

	return n;
}
Example #4
0
static int query(MYSQL_RES **res, const char *fmt, ...)
{
	bool failed = false;
	char qstr[1024];
	va_list ap;
	int err;

	va_start(ap, fmt);
	err = re_vsnprintf(qstr, sizeof(qstr), fmt, ap);
	va_end(ap);

	if (err < 0)
		return -1;

 retry:
	if (!mysql_query(&my.mysql, qstr)) {
		if (res) {
			*res = mysql_store_result(&my.mysql);
			if (!(*res))
				return ENOMEM;
		}

		return 0;
	}

	if (failed)
		return -1;

	switch (mysql_errno(&my.mysql)) {

	case CR_SERVER_GONE_ERROR:
	case CR_SERVER_LOST:
		failed = true;
		mysql_close(&my.mysql);

		err = myconnect();
		if (err) {
			restund_error("mysql: %s\n", mysql_error(&my.mysql));
			break;
		}

		goto retry;

	default:
		err = -1;
		break;
	}

	return err;
}
Example #5
0
static void call_event_handler(struct call *call, enum call_event ev,
			       const char *fmt, ...)
{
	call_event_h *eh = call->eh;
	void *eh_arg = call->arg;
	char buf[256];
	va_list ap;

	if (!eh)
		return;

	va_start(ap, fmt);
	(void)re_vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);

	eh(call, ev, buf, eh_arg);
}
int store_remove_pathf(const char *fmt, ...)
{
#ifdef ANDROID
	return ENOSYS;
#else
	char path[1024];
	va_list ap;
	int err;

	va_start(ap, fmt);
	err = re_vsnprintf(path, sizeof(path), fmt, ap);
	va_end(ap);
	if (err == -1)
		return EINVAL;

	return remove_path(path);
#endif
}
Example #7
0
static void warning_dialog(const char *title, const char *fmt, ...)
{
	va_list ap;
	char msg[512];
	GtkWidget *dialog;

	va_start(ap, fmt);
	(void)re_vsnprintf(msg, sizeof msg, fmt, ap);
	va_end(ap);

	dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR,
			GTK_BUTTONS_CLOSE, "%s", title);
	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
			"%s", msg);
	g_signal_connect_swapped(G_OBJECT(dialog), "response",
			G_CALLBACK(gtk_widget_destroy), dialog);
	gtk_window_set_title(GTK_WINDOW(dialog), title);
	gtk_widget_show(dialog);
}
Example #8
0
File: ui.c Project: QXIP/baresip
/**
 * Send output to all modules registered in the UI subsystem
 *
 * @param fmt Formatted output string
 */
void ui_output(const char *fmt, ...)
{
	char buf[512];
	struct le *le;
	va_list ap;
	int n;

	va_start(ap, fmt);
	n = re_vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);

	if (n < 0)
		return;

	for (le = uil.head; le; le = le->next) {
		const struct ui *ui = le->data;

		if (ui->outputh)
			ui->outputh(buf);
	}
}
Example #9
0
void restund_vlog(uint32_t level, const char *fmt, va_list ap)
{
	char buf[4096];
	struct le *le;

	if (re_vsnprintf(buf, sizeof(buf), fmt, ap) < 0)
		return;

	if (lg.stder)
		(void)re_fprintf(stderr, "%s", buf);

	le = lg.logl.head;

	while (le) {

		struct restund_log *log = le->data;
		le = le->next;

		if (log->h)
			log->h(level, buf);
	}
}
Example #10
0
void ua_event(struct ua *ua, enum ua_event ev, struct call *call,
	      const char *fmt, ...)
{
	struct le *le;
	char buf[256];
	va_list ap;

	if (!ua)
		return;

	va_start(ap, fmt);
	(void)re_vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);

	/* send event to all clients */
	le = uag.ehl.head;
	while (le) {
		struct ua_eh *eh = le->data;
		le = le->next;

		eh->h(ua, ev, call, buf, eh->arg);
	}
}