Exemplo n.º 1
0
static void pop3_gen_send(Pop3Session *session, const gchar *format, ...)
{
	gchar buf[POPBUFSIZE + 1];
	va_list args;

	va_start(args, format);
	g_vsnprintf(buf, sizeof(buf) - 2, format, args);
	va_end(args);

	if (!g_ascii_strncasecmp(buf, "PASS ", 5))
		log_print(LOG_PROTOCOL, "POP3> PASS ********\n");
	else
		log_print(LOG_PROTOCOL, "POP3> %s\n", buf);

	session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf);
}
Exemplo n.º 2
0
void
dfilter_fail(const char *format, ...)
{
	va_list	args;

	/* If we've already reported one error, don't overwite it */
	if (dfilter_error_msg != NULL)
		return;

	va_start(args, format);

	g_vsnprintf(dfilter_error_msg_buf, sizeof(dfilter_error_msg_buf),
			format, args);
	dfilter_error_msg = dfilter_error_msg_buf;
	va_end(args);
}
Exemplo n.º 3
0
void LogDebug(const char *func,
              const char *file,
              unsigned line,
              const char *fmt,
              ...)
{
   gchar buf[4096];

   va_list args;
   va_start(args, fmt);
   g_vsnprintf(buf, sizeof buf, fmt, args);
   buf[sizeof buf - 1] = '\0';
   va_end(args);

   g_debug("[function %s, file %s, line %d], %s\n",
           func, file, line, buf);
}
Exemplo n.º 4
0
gchar *
wmem_strdup_vprintf(wmem_allocator_t *allocator, const gchar *fmt, va_list ap)
{
    va_list ap2;
    gsize len;
    gchar* dst;

    G_VA_COPY(ap2, ap);

    len = g_printf_string_upper_bound(fmt, ap);

    dst = (gchar *)wmem_alloc(allocator, len+1);
    g_vsnprintf(dst, (gulong) len, fmt, ap2);
    va_end(ap2);

    return dst;
}
Exemplo n.º 5
0
void
say (char *fmt, ...)
{
  va_list ap;
  char buf[200];
  guint context_id;

  if (test_computer_play > 0) return;
  va_start (ap, fmt);
  g_vsnprintf (buf, 200, fmt, ap);
  va_end (ap);

  context_id =
    gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "message");
  gtk_statusbar_pop (GTK_STATUSBAR (statusbar), context_id);
  gtk_statusbar_push (GTK_STATUSBAR (statusbar), context_id, buf);
}
Exemplo n.º 6
0
static void parent_fatal(int exit_code, const char* fmt, ...) {
	va_list ap;
	char str[1024];

	va_start(ap,fmt);
	g_vsnprintf(str,1024,fmt,ap);
	va_end(ap);

#ifdef DEBUG_PARENT
	PARENT_DBG((0,"Fatal error: exit_code=%d str=%s",exit_code,str));
#else
	fprintf(stderr,"Fatal error: exit_code=%d str=%s",exit_code,str);
#endif

	kill(parent.dispatcher_pid,SIGTERM);
	exit(exit_code);
}
Exemplo n.º 7
0
janus_sdp_attribute *janus_sdp_attribute_create(const char *name, const char *value, ...) {
	if(!name)
		return NULL;
	janus_sdp_attribute *a = g_malloc(sizeof(janus_sdp_attribute));
	a->name = g_strdup(name);
	a->direction = JANUS_SDP_DEFAULT;
	a->value = NULL;
	if(value) {
		char buffer[512];
		va_list ap;
		va_start(ap, value);
		g_vsnprintf(buffer, sizeof(buffer), value, ap);
		va_end(ap);
		a->value = g_strdup(buffer);
	}
	return a;
}
Exemplo n.º 8
0
static void
LogErrorPosixCodeV(int code,
                   const char *func,
                   const char *file,
                   unsigned line,
                   const char *fmt,
                   va_list args)
{
   char errMsg[4096];
   gchar buf[4096];

   g_vsnprintf(buf, sizeof buf, fmt, args);
   buf[sizeof buf - 1] = '\0';
   strerror_s(errMsg, sizeof errMsg, code);
   g_warning("[function %s, file %s, line %d], %s, [errno = %d] %s\n",
             func, file, line, buf, code, errMsg);
}
Exemplo n.º 9
0
/**
 * rig_protobuf_c_data_buffer_vprintf:
 * @buffer: the buffer to append to.
 * @format: printf-style format string describing what to append to buffer.
 * @args: values referenced by @format string.
 *
 * Append printf-style content to a buffer, given a va_list.
 */
void     rig_protobuf_c_data_buffer_vprintf             (ProtobufCDataBuffer    *buffer,
					 const char   *format,
					 va_list       args)
{
  gsize size = g_printf_string_upper_bound (format, args);
  if (size < 1024)
    {
      char buf[1024];
      g_vsnprintf (buf, sizeof (buf), format, args);
      rig_protobuf_c_data_buffer_append_string (buffer, buf);
    }
  else
    {
      char *buf = g_strdup_vprintf (format, args);
      rig_protobuf_c_data_buffer_append_foreign (buffer, buf, strlen (buf), g_free, buf);
    }
}
Exemplo n.º 10
0
/**
 * gnomemeeting_dialog
 *
 * @parent: The parent window of the dialog.
 * @format: a char * including printf formats
 * @args  : va_list that the @format char * uses.
 * @type  : specifies the kind of GtkMessageType dialogs to use. 
 *
 * Creates and runs a dialog and destroys it afterward. 
 **/
static GtkWidget *
gnomemeeting_dialog (GtkWindow *parent,
		     const char *prim_text,
                     const char *format, 
                     va_list args, 
                     GtkMessageType type)
{
  GtkWidget *dialog;
  gchar *primary_text = NULL;
  gchar *dialog_text = NULL;
  char buffer [1025];

  primary_text =
    g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>",
		     prim_text);
  
  if (format == NULL)
    buffer[0] = 0;
  else 
    g_vsnprintf (buffer, 1024, format, args);

  dialog_text =
    g_strdup_printf ("%s\n\n%s", primary_text, buffer);
  
  dialog =
    gtk_message_dialog_new (parent, 
                            GTK_DIALOG_MODAL, 
                            type,
			    GTK_BUTTONS_OK, NULL);

  gtk_window_set_title (GTK_WINDOW (dialog), "");
  gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
				 dialog_text);
  
  g_signal_connect_swapped (dialog, "response",
                            G_CALLBACK (gtk_widget_destroy),
                            dialog);
  
  /* Can be called from threads */
  gm_window_show (dialog);

  g_free (dialog_text);
  g_free (primary_text);

  return dialog;
}
Exemplo n.º 11
0
Arquivo: log.c Projeto: gonter/jpilot
/*
 * This function writes data to the parent process.
 * A line feed, or a null must be the last character written.
 */
int write_to_parent(int command, const char *format, ...)
{
   va_list val;
   int len, size;
   char real_buf[WRITE_MAX_BUF+32];
   char *buf;
   char cmd[20];

   buf=&(real_buf[16]);
   buf[0] = '\0';

   va_start(val, format);
   g_vsnprintf(buf, WRITE_MAX_BUF, format, val);
   /* glibc >2.1 can return size > WRITE_MAX_BUF */
   /* just in case g_vsnprintf reached the max */
   buf[WRITE_MAX_BUF-1] = '\0';
   size=strlen(buf);
   va_end(val);

   /* This is for jpilot-sync */
   if (pipe_to_parent==STDOUT_FILENO) {
      if (command==PIPE_PRINT) {
         if (write(pipe_to_parent, buf, strlen(buf)) < 0) {
            jp_logf(JP_LOG_WARN, "write failed %s %d\n", __FILE__, __LINE__);
         }
      }
      return TRUE;
   }

   sprintf(cmd, "%d:", command);
   len = strlen(cmd);
   buf = buf-len;
   strncpy(buf, cmd, len);
   size += len;
   /* The pipe doesn't flush unless a CR is written */
   /* This is our key to the parent for a record separator */
   buf[size]='\0';
   buf[size+1]='\n';
   size += 2;
   if (write(pipe_to_parent, buf, size) < 0) {
      jp_logf(JP_LOG_WARN, "write failed %s %d\n", __FILE__, __LINE__);
   }

   return TRUE;
}
Exemplo n.º 12
0
void dbg_print(const gint* which, gint how, FILE* where, const gchar* fmt, ... ) {
	static gchar debug_buffer[DEBUG_BUFFER_SIZE];
	va_list list;

	if ( ! which || *which < how ) return;

	va_start( list, fmt );
	g_vsnprintf(debug_buffer,DEBUG_BUFFER_SIZE,fmt,list);
	va_end( list );

	if (! where) {
		g_message("%s", debug_buffer);
	} else {
		fputs(debug_buffer,where);
		fputs("\n",where);
	}

}
Exemplo n.º 13
0
int
sio_printf (struct siobuf *sio, const char *format, ...)
{
  va_list alist;
  char buf[1024];
  int len;

  assert (sio != NULL && format != NULL);

  va_start (alist, format);
  len = g_vsnprintf (buf, sizeof buf, format, alist);
  va_end (alist);
  if (len >= (int) sizeof buf - 1)
    len = sizeof buf - 1;
  if (len > 0)
    sio_write (sio, buf, len);
  return len;
}
Exemplo n.º 14
0
static void admin_write(gchar * fmt, ...)
{
	char buff[ADMIN_BUFSIZE];
	va_list ap;

	strncpy(buff, "admin ", ADMIN_PREFIX_LEN);

	if (!_admin_session) {
		admin_open_session();
	}

	va_start(ap, fmt);
	g_vsnprintf(&buff[ADMIN_PREFIX_LEN],
		    ADMIN_BUFSIZE - ADMIN_PREFIX_LEN, fmt, ap);
	va_end(ap);

	net_write(_admin_session, buff);
}
Exemplo n.º 15
0
static void
LogErrorWinCodeV(int code,
                 const char *func,
                 const char *file,
                 unsigned line,
                 const char *fmt,
                 va_list args)
{
   char *msgBuf = WinUtil_GetErrorText(code);
   gchar buf[4096];

   g_vsnprintf(buf, sizeof buf, fmt, args);
   buf[sizeof buf - 1] = '\0';

   g_warning("[function %s, file %s, line %d], %s, [Win32 Error = %d] %s\n",
             func, file, line, buf, code, (const char *)msgBuf);

   g_free(msgBuf);
}
Exemplo n.º 16
0
/* For the benefit of the podcast parsing code */
void
rb_debug_realf (const char *func,
	        const char *file,
	        int line,
	        gboolean newline,
	        const char *format, ...)
{
	va_list args;
	char buffer[1025];

	if (debug == FALSE)
		return;

	va_start (args, format);
	g_vsnprintf (buffer, 1024, format, args);
	va_end (args);

	g_printerr (newline ? "%s:%d [%s] %s\n" : "%s:%d [%s] %s",
		    file, line, func, buffer);
}
Exemplo n.º 17
0
static gint
print (gchar       *buf,
       gint         len,
       gint         start,
       const gchar *fmt,
       ...)
{
    va_list args;
    gint printed;

    va_start (args, fmt);

    printed = g_vsnprintf (buf + start, len - start, fmt, args);
    if (printed < 0)
        printed = len - start;

    va_end (args);

    return printed;
}
Exemplo n.º 18
0
/**
 * g_process_message:
 * @fmt: format string
 * @...: arguments to @fmt
 *
 * This function sends a message to the client preferring to use the stderr
 * channel as long as it is available and switching to using syslog() if it
 * isn't. Generally the stderr channell will be available in the startup
 * process and in the beginning of the first startup in the
 * supervisor/daemon processes. Later on the stderr fd will be closed and we
 * have to fall back to using the system log.
 **/
void
g_process_message(const gchar *fmt, ...)
{
  gchar buf[2048];
  va_list ap;

  va_start(ap, fmt);
  g_vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  if (stderr_present)
    fprintf(stderr, "%s: %s\n", process_opts.name, buf);
  else
    {
      gchar name[32];

      g_snprintf(name, sizeof(name), "%s/%s", process_kind == G_PK_SUPERVISOR ? "supervise" : "daemon", process_opts.name);
      openlog(name, LOG_PID, LOG_DAEMON);
      syslog(LOG_CRIT, "%s\n", buf);
      closelog();
    }
}
/**
 * rb_debug_realf:
 * @func: function name
 * @file: file name
 * @line: line number
 * @newline: if TRUE, add a newline to the output
 * @format: printf style format specifier
 * @Varargs: substitution values for @format
 *
 * If the debug output settings match the function or file names,
 * the debug message will be formatted and written to standard error.
 */
void
rb_debug_realf (const char *func,
		const char *file,
		const int line,
		gboolean newline,
		const char *format, ...)
{
	va_list args;
	char buffer[1025];

	if (!rb_debug_matches (func, file))
		return;

	va_start (args, format);

	g_vsnprintf (buffer, 1024, format, args);

	va_end (args);

	_rb_debug_print (func, file, line, newline, buffer);
}
Exemplo n.º 20
0
void
InterfaceGtk::vmsg(MessageType type, const gchar *fmt, va_list ap)
{
	static const GtkMessageType type2gtk[] = {
		/* [MSG_USER]		= */ GTK_MESSAGE_OTHER,
		/* [MSG_INFO]		= */ GTK_MESSAGE_INFO,
		/* [MSG_WARNING]	= */ GTK_MESSAGE_WARNING,
		/* [MSG_ERROR]		= */ GTK_MESSAGE_ERROR
	};

	va_list aq;
	gchar buf[255];

	va_copy(aq, ap);
	stdio_vmsg(type, fmt, ap);
	g_vsnprintf(buf, sizeof(buf), fmt, aq);
	va_end(aq);

	gtk_info_bar_set_message_type(GTK_INFO_BAR(info_widget),
				      type2gtk[type]);
	gtk_label_set_text(GTK_LABEL(message_widget), buf);
}
Exemplo n.º 21
0
static void
wmem_strbuf_append_vprintf(wmem_strbuf_t *strbuf, const gchar *fmt, va_list ap)
{
    va_list ap2;
    gsize append_len;

    G_VA_COPY(ap2, ap);

    append_len = g_printf_string_upper_bound(fmt, ap);

    /* -1 because g_printf_string_upper_bound counts the null-terminator, but
     * wmem_strbuf_grow does not */
    wmem_strbuf_grow(strbuf, append_len - 1);

    append_len = g_vsnprintf(&strbuf->str[strbuf->len],
            (gulong) WMEM_STRBUF_RAW_ROOM(strbuf),
            fmt, ap2);

    va_end(ap2);

    strbuf->len = MIN(strbuf->len + append_len, strbuf->alloc_len - 1);
}
Exemplo n.º 22
0
void
console_print(ConsoleUI *cui, char *type, const char *text, ...) {
	char buf[4096];
	va_list ap;
	GtkTextBuffer *buffer;
	GtkTextIter iter;

	va_start(ap, text);
	g_vsnprintf(buf, 4096, text, ap);
	va_end(ap);

	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(cui->display));
	gtk_text_buffer_get_end_iter(buffer, &iter);
	if (type) {
		gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
				buf, -1, type, NULL);
	} else {
		gtk_text_buffer_insert(buffer, &iter, buf, -1);
	}
	gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(cui->display),
			cui->mark_end, 0.0, FALSE, 0, 0);
}
Exemplo n.º 23
0
static void
print_padded_string (gint columns, gchar padchar, gboolean padright, const gchar *fmt, ...)
{
	gchar buf[1024];
	gchar *padstring;

	va_list ap;

	va_start (ap, fmt);
	g_vsnprintf (buf, 1024, fmt, ap);
	va_end (ap);

	padstring = g_strnfill (columns - g_utf8_strlen (buf, -1), padchar);

	if (padright) {
		print_info ("%s%s", buf, padstring);
	} else {
		print_info ("%s%s", padstring, buf);
	}

	g_free (padstring);
}
Exemplo n.º 24
0
void
nm_utils_strbuf_append (char **buf, gsize *len, const char *format, ...)
{
	char *p = *buf;
	va_list args;
	gint retval;

	if (*len == 0)
		return;

	va_start (args, format);
	retval = g_vsnprintf (p, *len, format, args);
	va_end (args);

	if (retval >= *len) {
		*buf = &p[*len];
		*len = 0;
	} else {
		*buf = &p[retval];
		*len -= retval;
	}
}
Exemplo n.º 25
0
printf_arglist_function2(char *log_genstring, logtype_t, typ, char *, pname, char *, format)
{
    va_list argp;
    char *leader = NULL;
    char linebuf[STR_SIZE];
    char *xlated_fmt = dgettext("C", format);

    /* format error message */

    if((int)typ <= (int)L_BOGUS || (int)typ > (int)L_MARKER) typ = L_BOGUS;

    if(multiline > 0) {
	leader = stralloc("  ");		/* continuation line */
    } else {
	leader = vstralloc(logtype_str[(int)typ], " ", pname, " ", NULL);
    }

    arglist_start(argp, format);
    g_vsnprintf(linebuf, SIZEOF(linebuf)-1, xlated_fmt, argp);
						/* -1 to allow for '\n' */
    arglist_end(argp);
    return(vstralloc(leader, linebuf, "\n", NULL));
}
Exemplo n.º 26
0
void
xmr_debug_real(
			const gchar *func,
			const gchar *file,
			gint		 line,
			gboolean	 newline,
			const gchar *format,
			...
			)
{
	va_list args;
	gchar buffer[1025];

	if (!enable_debug)
		return;

	va_start(args, format);

	g_vsnprintf(buffer, 1024, format, args);

	va_end(args);

	xmr_debug_print(func, file, line, newline, buffer);
}
Exemplo n.º 27
0
/*!
 *\brief	display an error with a View Log button
 *
 */
void alertpanel_error_log(const gchar *format, ...)
{
	va_list args;
	int val;
	MainWindow *mainwin;
	gchar buf[ALERT_PANEL_BUFSIZE];

	va_start(args, format);
	g_vsnprintf(buf, sizeof(buf), format, args);
	va_end(args);
	strretchomp(buf);

	mainwin = mainwindow_get_mainwindow();
	
	if (mainwin && mainwin->logwin) {
		mainwindow_clear_error(mainwin);
		val = alertpanel_full(_("Error"), buf, GTK_STOCK_CLOSE,
				      _("_View log"), NULL, ALERTFOCUS_FIRST, FALSE, NULL,
				      ALERT_ERROR);
		if (val == G_ALERTALTERNATE)
			log_window_show(mainwin->logwin);
	} else
		alertpanel_error("%s", buf);
}
Exemplo n.º 28
0
void print_vfs_message (char *msg, ...)
{
    va_list ap;
    char str [128];

    va_start (ap, msg);

    g_vsnprintf (str, sizeof (str), msg, ap);
    va_end (ap);

    if (midnight_shutdown)
	return;

    if (!message_visible || !the_hint || !the_hint->widget.parent) {
	int col, row;

	if (!nice_rotating_dash || (ok_to_refresh <= 0))
	    return;

	/* Preserve current cursor position */
	getyx (stdscr, row, col);

	move (0, 0);
	attrset (NORMAL_COLOR);
	printw ("%-*s", COLS-1, str);

	/* Restore cursor position */
	move(row, col);
	mc_refresh ();
	return;
    }

    if (message_visible) {
        set_hintbar(str);
    }
}
Exemplo n.º 29
0
static gchar*
internal_get_file_r (const gchar *dir,
                     gchar       *buffer,
                     gsize        len,
                     const gchar *format,
                     va_list      ap)
{
  gsize n;

  g_return_val_if_fail(buffer != NULL, NULL);
  g_return_val_if_fail(format != NULL, NULL);
  g_return_val_if_fail(len > 0, NULL);

  if ((n = g_strlcpy(buffer, dir, len)) >= len)
    return NULL;

  if ((n = g_strlcat(buffer, G_DIR_SEPARATOR_S, len)) >= len)
    return NULL;

  if ((gsize) g_vsnprintf(buffer + n, len - n, format, ap) >= len - n)
    return NULL;

  return buffer;
}
Exemplo n.º 30
0
/*  used to intensivelly check ep canaries
 */
void ep_check_canary_integrity(const char* fmt, ...) {
	va_list ap;
	static gchar there[128] = {
		'L','a','u','n','c','h',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	gchar here[128];
	emem_chunk_t* npc = NULL;

	if (! intense_canary_checking ) return;

	here[126] = '\0';
	here[127] = '\0';

	va_start(ap,fmt);
	g_vsnprintf(here, 126,fmt, ap);
	va_end(ap);

	for (npc = ep_packet_mem.free_list; npc != NULL; npc = npc->next) {
		static unsigned i_ctr;

		if (npc->canary_info->c_count > 0x00ffffff) {
			g_error("ep_packet_mem.free_list was corrupted\nbetween: %s\nand: %s",there, here);
		}

		for (i_ctr = 0; i_ctr < npc->canary_info->c_count; i_ctr++) {
			if (memcmp(npc->canary_info->canary[i_ctr], &ep_canary, npc->canary_info->cmp_len[i_ctr]) != 0) {
				g_error("Per-packet memory corrupted\nbetween: %s\nand: %s",there, here);
			}
		}
	}

	strncpy(there,here,126);

}