Fix log format arguments
Remove the misuse of va_list and emulate behavior of purple debugging functions in our own code, since a va_list cannot be passed to purple_debug_info,
This commit is contained in:
parent
93f4bd25ae
commit
90f7b39e11
4 changed files with 37 additions and 27 deletions
24
interface.c
24
interface.c
|
@ -1191,24 +1191,24 @@ void hexdump (int *in_ptr, int *in_end) {
|
|||
print_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
void logprintf (const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_message(format, ap);
|
||||
va_end (ap);
|
||||
/*
|
||||
int x = 0;
|
||||
if (!prompt_was) {
|
||||
x = 1;
|
||||
print_start ();
|
||||
}
|
||||
printf (COLOR_GREY " *** ");
|
||||
printf (COLOR_NORMAL);
|
||||
if (x) {
|
||||
print_end ();
|
||||
}
|
||||
*/
|
||||
//int x = 0;
|
||||
//if (!prompt_was) {
|
||||
// x = 1;
|
||||
// print_start ();
|
||||
//}
|
||||
//printf (COLOR_GREY " *** ");
|
||||
//printf (COLOR_NORMAL);
|
||||
//if (x) {
|
||||
// print_end ();
|
||||
//}
|
||||
}
|
||||
*/
|
||||
|
||||
int color_stack_pos;
|
||||
const char *color_stack[10];
|
||||
|
|
17
msglog.c
17
msglog.c
|
@ -14,26 +14,27 @@
|
|||
|
||||
#define COLOR_INVERSE "\033[7m"
|
||||
|
||||
void log_printf(const char *format, ...)
|
||||
/**
|
||||
* Log a message to the telegram-cli message log, by
|
||||
* just writing it to STDOUT and appending '***'
|
||||
*/
|
||||
void log_printf(const char *format, va_list ap)
|
||||
{
|
||||
printf (COLOR_GREY " *** ");
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
vfprintf (stdout, format, ap);
|
||||
va_end (ap);
|
||||
vprintf (format, ap);
|
||||
printf (COLOR_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback that will log the given msg to the used target
|
||||
*/
|
||||
void (*log_cb)(const char*, ...) = log_printf;
|
||||
void (*log_cb)(const char* format, va_list ap) = log_printf;
|
||||
|
||||
/**
|
||||
* Set a custom logging callback to use instead of the regular
|
||||
* printf to stdout
|
||||
*/
|
||||
void set_log_cb(void (*cb)(const char*, ...))
|
||||
void set_log_cb(void (*cb)(const char*, va_list ap))
|
||||
{
|
||||
log_cb = cb;
|
||||
}
|
||||
|
@ -41,7 +42,7 @@ void set_log_cb(void (*cb)(const char*, ...))
|
|||
/**
|
||||
* Log a message to the current message log
|
||||
*/
|
||||
void log_message(const char *format, ...)
|
||||
void logprintf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
|
|
6
msglog.h
6
msglog.h
|
@ -1,13 +1,15 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
* Set a custom logging callback to use instead of regular printing
|
||||
* to stdout
|
||||
*/
|
||||
void set_log_cb(void (*cb)(const char*, ...));
|
||||
void set_log_cb(void (*cb)(const char*, va_list ap));
|
||||
|
||||
/**
|
||||
* Log a message to the current message log
|
||||
*/
|
||||
void log_message(const char *format, ...);
|
||||
void logprintf(const char *format, ...);
|
||||
|
||||
/*
|
||||
void log_debug(const char* format, ...);
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
// test
|
||||
|
||||
|
@ -37,6 +40,8 @@
|
|||
#include "status.h"
|
||||
#include "util.h"
|
||||
#include "prpl.h"
|
||||
#include "prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
// Telegram Includes
|
||||
#include <tg-cli.h>
|
||||
|
@ -52,12 +57,14 @@ static PurplePlugin *_telegram_protocol = NULL;
|
|||
* Redirect the msglog of the telegram-cli application to the libpurple
|
||||
* logger
|
||||
*/
|
||||
void tg_cli_log_cb(const char* format, ...)
|
||||
void tg_cli_log_cb(const char* format, va_list ap)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
purple_debug_info(PLUGIN_ID, format, ap);
|
||||
va_end (ap);
|
||||
// emulate libpurple logging function, because we cant pass va_list
|
||||
// directly
|
||||
time_t mtime = time(NULL);
|
||||
const char *mdate = purple_utf8_strftime("%H:%M:%S", localtime(&mtime));
|
||||
printf("(%s) prpl-telegram: ", mdate);
|
||||
vprintf(format, ap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue