#include <libtransmission/transmission.h>
#include <libtransmission/tr-getopt.h>
+#include <libtransmission/log.h>
#include <libtransmission/utils.h>
#include <libtransmission/variant.h>
#include <libtransmission/version.h>
{
if (!mySession)
{
- tr_inf ("Deferring reload until session is fully started.");
+ tr_logAddInfo ("Deferring reload until session is fully started.");
seenHUP = true;
}
else
}
configDir = tr_sessionGetConfigDir (mySession);
- tr_inf ("Reloading settings from \"%s\"", configDir);
+ tr_logAddInfo ("Reloading settings from \"%s\"", configDir);
tr_variantInitDict (&settings, 0);
tr_variantDictAddBool (&settings, TR_KEY_rpc_enabled, true);
tr_sessionLoadSettings (&settings, configDir, MY_NAME);
}
default:
- tr_err ("Unexpected signal (%d) in daemon, closing.", sig);
+ tr_logAddError ("Unexpected signal (%d) in daemon, closing.", sig);
/* no break */
case SIGINT:
tr_torrentNew (ctor, &err);
if (err == TR_PARSE_ERR)
- tr_err ("Error parsing .torrent file \"%s\"", file);
+ tr_logAddError ("Error parsing .torrent file \"%s\"", file);
else
{
bool trash = false;
int test = tr_ctorGetDeleteSource (ctor, &trash);
- tr_inf ("Parsing .torrent file successful \"%s\"", file);
+ tr_logAddInfo ("Parsing .torrent file successful \"%s\"", file);
if (!test && trash)
{
- tr_inf ("Deleting input .torrent file \"%s\"", file);
+ tr_logAddInfo ("Deleting input .torrent file \"%s\"", file);
if (remove (filename))
- tr_err ("Error deleting .torrent file: %s", tr_strerror (errno));
+ tr_logAddError ("Error deleting .torrent file: %s", tr_strerror (errno));
}
else
{
if (logfile != NULL)
{
char timestr[64];
- tr_getLogTimeStr (timestr, sizeof (timestr));
+ tr_logGetTimeStr (timestr, sizeof (timestr));
if (name)
fprintf (logfile, "[%s] %s %s (%s:%d)\n", timestr, name, message, file, line);
else
/* figure out the syslog priority */
switch (level) {
- case TR_MSG_ERR: priority = LOG_ERR; break;
- case TR_MSG_DBG: priority = LOG_DEBUG; break;
- default: priority = LOG_INFO; break;
+ case TR_LOG_ERROR: priority = LOG_ERR; break;
+ case TR_LOG_DEBUG: priority = LOG_DEBUG; break;
+ default: priority = LOG_INFO; break;
}
if (name)
static void
pumpLogMessages (FILE * logfile)
{
- const tr_msg_list * l;
- tr_msg_list * list = tr_getQueuedMessages ();
+ const tr_log_message * l;
+ tr_log_message * list = tr_logGetQueue ();
for (l=list; l!=NULL; l=l->next)
printMessage (logfile, l->level, l->name, l->message, l->file, l->line);
if (logfile != NULL)
fflush (logfile);
- tr_freeMessageList (list);
+ tr_logFreeQueue (list);
}
static tr_rpc_callback_status
break;
case 'Y': tr_variantDictAddBool (&settings, TR_KEY_lpd_enabled, false);
break;
- case 810: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_ERR);
+ case 810: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_LOG_ERROR);
break;
- case 811: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_INF);
+ case 811: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_LOG_INFO);
break;
- case 812: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_DBG);
+ case 812: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_LOG_DEBUG);
break;
case 830: tr_variantDictAddBool (&settings, TR_KEY_utp_enabled, true);
break;
if (!loaded)
{
- printMessage (logfile, TR_MSG_ERR, MY_NAME, "Error loading config file -- exiting.", __FILE__, __LINE__);
+ printMessage (logfile, TR_LOG_ERROR, MY_NAME, "Error loading config file -- exiting.", __FILE__, __LINE__);
return -1;
}
{
char buf[256];
tr_snprintf (buf, sizeof (buf), "Failed to daemonize: %s", tr_strerror (errno));
- printMessage (logfile, TR_MSG_ERR, MY_NAME, buf, __FILE__, __LINE__);
+ printMessage (logfile, TR_LOG_ERROR, MY_NAME, buf, __FILE__, __LINE__);
exit (1);
}
tr_formatter_speed_init (SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
session = tr_sessionInit ("daemon", configDir, true, &settings);
tr_sessionSetRPCCallback (session, on_rpc_callback, NULL);
- tr_ninf (NULL, "Using settings from \"%s\"", configDir);
+ tr_logAddNamedInfo (NULL, "Using settings from \"%s\"", configDir);
tr_sessionSaveSettings (session, configDir, &settings);
pid_filename = NULL;
{
fprintf (fp, "%d", (int)getpid ());
fclose (fp);
- tr_inf ("Saved pidfile \"%s\"", pid_filename);
+ tr_logAddInfo ("Saved pidfile \"%s\"", pid_filename);
pidfile_created = true;
}
else
- tr_err ("Unable to save pidfile \"%s\": %s", pid_filename, tr_strerror (errno));
+ tr_logAddError ("Unable to save pidfile \"%s\": %s", pid_filename, tr_strerror (errno));
}
if (tr_variantDictFindBool (&settings, TR_KEY_rpc_authentication_required, &boolVal) && boolVal)
- tr_ninf (MY_NAME, "requiring authentication");
+ tr_logAddNamedInfo (MY_NAME, "requiring authentication");
mySession = session;
&& dir
&& *dir)
{
- tr_inf ("Watching \"%s\" for new .torrent files", dir);
+ tr_logAddInfo ("Watching \"%s\" for new .torrent files", dir);
watchdir = dtr_watchdir_new (mySession, dir, onFileAdded);
}
}
#include <curl/curl.h>
#include <libtransmission/transmission.h>
+#include <libtransmission/log.h>
#include <libtransmission/rpcimpl.h>
#include <libtransmission/tr-getopt.h>
#include <libtransmission/utils.h>
if (tr_variantFromJson (&top, response, len))
{
- tr_nerr (MY_NAME, "Unable to parse response \"%*.*s\"", (int)len,
+ tr_logAddNamedError (MY_NAME, "Unable to parse response \"%*.*s\"", (int)len,
(int)len, (char*)response);
status |= EXIT_FAILURE;
}
if ((res = curl_easy_perform (curl)))
{
- tr_nerr (MY_NAME, " (%s) %s", rpcurl_http, curl_easy_strerror (res));
+ tr_logAddNamedError (MY_NAME, " (%s) %s", rpcurl_http, curl_easy_strerror (res));
status |= EXIT_FAILURE;
}
else
#include <dirent.h> /* readdir */
#include <libtransmission/transmission.h>
-#include <libtransmission/utils.h> /* tr_buildPath (), tr_inf () */
+#include <libtransmission/log.h>
+#include <libtransmission/utils.h> /* tr_buildPath (), tr_logAddInfo () */
#include "watch.h"
struct dtr_watchdir
}
else
{
- tr_inf ("Using inotify to watch directory \"%s\"", w->dir);
+ tr_logAddInfo ("Using inotify to watch directory \"%s\"", w->dir);
i = inotify_add_watch (w->inotify_fd, w->dir, DTR_INOTIFY_MASK);
}
if (i < 0)
{
- tr_err ("Unable to watch \"%s\": %s", w->dir, tr_strerror (errno));
+ tr_logAddError ("Unable to watch \"%s\": %s", w->dir, tr_strerror (errno));
}
else if ((odir = opendir (w->dir)))
{
if (!tr_str_has_suffix (name, ".torrent")) /* skip non-torrents */
continue;
- tr_inf ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
+ tr_logAddInfo ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
w->callback (w->session, w->dir, name);
}
const char * name = event->name;
if (tr_str_has_suffix (name, ".torrent"))
{
- tr_inf ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
+ tr_logAddInfo ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
w->callback (w->session, w->dir, name);
}
i += EVENT_SIZE + event->len;
static void
watchdir_new_impl (dtr_watchdir * w UNUSED)
{
- tr_inf ("Using readdir to watch directory \"%s\"", w->dir);
+ tr_logAddInfo ("Using readdir to watch directory \"%s\"", w->dir);
w->lastFiles = evbuffer_new ();
}
static void
/* if this file wasn't here last time, try adding it */
if (!is_file_in_list (w->lastFiles, name, len)) {
- tr_inf ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
+ tr_logAddInfo ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
w->callback (w->session, w->dir, name);
}
}
textdomain (MY_READABLE_NAME);
/* init glib/gtk */
+#if !GLIB_CHECK_VERSION(2,35,4)
g_type_init ();
+#endif
gtk_init (&argc, &argv);
g_set_application_name (_("Transmission"));
gtk_window_set_default_icon_name (MY_CONFIG_NAME);
break;
case TR_KEY_message_level:
- tr_setMessageLevel (gtr_pref_int_get (key));
+ tr_logSetLevel (gtr_pref_int_get (key));
break;
case TR_KEY_peer_port:
#include <gtk/gtk.h>
#include <libtransmission/transmission.h>
+#include <libtransmission/log.h>
#include "conf.h"
#include "hig.h"
GtkListStore * store;
GtkTreeModel * filter;
GtkTreeModel * sort;
- tr_msg_level maxLevel;
+ tr_log_level maxLevel;
gboolean isPaused;
guint refresh_tag;
};
-static struct tr_msg_list * myTail = NULL;
-static struct tr_msg_list * myHead = NULL;
+static struct tr_log_message * myTail = NULL;
+static struct tr_log_message * myHead = NULL;
/****
*****
const int level = gtr_combo_box_get_active_enum (combo_box);
const gboolean pinned_to_new = is_pinned_to_new (data);
- tr_setMessageLevel (level);
+ tr_logSetLevel (level);
gtr_core_set_pref_int (data->core, TR_KEY_message_level, level);
data->maxLevel = level;
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (data->filter));
{
char * date;
const char * levelStr;
- const struct tr_msg_list * node;
+ const struct tr_log_message * node;
gtk_tree_model_get (model, &iter, COL_TR_MSG, &node, -1);
date = gtr_localtime (node->when);
switch (node->level)
{
- case TR_MSG_DBG:
+ case TR_LOG_DEBUG:
levelStr = "debug";
break;
- case TR_MSG_ERR:
+ case TR_LOG_ERROR:
levelStr = "error";
break;
struct MsgData * data = gdata;
gtk_list_store_clear (data->store);
- tr_freeMessageList (myHead);
+ tr_logFreeQueue (myHead);
myHead = myTail = NULL;
}
{
switch (msgLevel)
{
- case TR_MSG_DBG: return "forestgreen";
- case TR_MSG_INF: return "black";
- case TR_MSG_ERR: return "red";
+ case TR_LOG_DEBUG: return "forestgreen";
+ case TR_LOG_INFO: return "black";
+ case TR_LOG_ERROR: return "red";
default: g_assert_not_reached (); return "black";
}
}
{
const int col = GPOINTER_TO_INT (gcol);
char * str = NULL;
- const struct tr_msg_list * node;
+ const struct tr_log_message * node;
gtk_tree_model_get (tree_model, iter, col, &str, COL_TR_MSG, &node, -1);
g_object_set (renderer, "text", str,
{
struct tm tm;
char buf[16];
- const struct tr_msg_list * node;
+ const struct tr_log_message * node;
gtk_tree_model_get (tree_model, iter, COL_TR_MSG, &node, -1);
tm = *localtime (&node->when);
static gboolean
isRowVisible (GtkTreeModel * model, GtkTreeIter * iter, gpointer gdata)
{
- const struct tr_msg_list * node;
+ const struct tr_log_message * node;
const struct MsgData * data = gdata;
gtk_tree_model_get (model, iter, COL_TR_MSG, &node, -1);
g_free (data);
}
-static tr_msg_list *
-addMessages (GtkListStore * store, struct tr_msg_list * head)
+static tr_log_message *
+addMessages (GtkListStore * store, struct tr_log_message * head)
{
- tr_msg_list * i;
+ tr_log_message * i;
static unsigned int sequence = 0;
const char * default_name = g_get_application_name ();
-1);
/* if it's an error message, dump it to the terminal too */
- if (i->level == TR_MSG_ERR)
+ if (i->level == TR_LOG_ERROR)
{
GString * gstr = g_string_sized_new (512);
g_string_append_printf (gstr, "%s:%d %s", i->file, i->line, i->message);
if (!data->isPaused)
{
- tr_msg_list * msgs = tr_getQueuedMessages ();
+ tr_log_message * msgs = tr_logGetQueue ();
if (msgs)
{
/* add the new messages and append them to the end of
* our persistent list */
- tr_msg_list * tail = addMessages (data->store, msgs);
+ tr_log_message * tail = addMessages (data->store, msgs);
if (myTail)
myTail->next = msgs;
else
static GtkWidget*
debug_level_combo_new (void)
{
- GtkWidget * w = gtr_combo_box_new_enum (_("Error"), TR_MSG_ERR,
- _("Information"), TR_MSG_INF,
- _("Debug"), TR_MSG_DBG,
+ GtkWidget * w = gtr_combo_box_new_enum (_("Error"), TR_LOG_ERROR,
+ _("Information"), TR_LOG_INFO,
+ _("Debug"), TR_LOG_DEBUG,
NULL);
gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (TR_KEY_message_level));
return w;
G_TYPE_UINT, /* sequence */
G_TYPE_POINTER, /* category */
G_TYPE_POINTER, /* message */
- G_TYPE_POINTER); /* struct tr_msg_list */
+ G_TYPE_POINTER); /* struct tr_log_message */
addMessages (data->store, myHead);
onRefresh (data); /* much faster to populate *before* it has listeners */
#include <event2/buffer.h>
#include <libtransmission/transmission.h>
+#include <libtransmission/log.h>
#include <libtransmission/rpcimpl.h>
#include <libtransmission/utils.h> /* tr_free */
#include <libtransmission/variant.h>
/* logging */
if (success)
{
- tr_inf ("%s", _("Inhibiting desktop hibernation"));
+ tr_logAddInfo ("%s", _("Inhibiting desktop hibernation"));
}
else
{
- tr_err (_("Couldn't inhibit desktop hibernation: %s"), err->message);
+ tr_logAddError (_("Couldn't inhibit desktop hibernation: %s"), err->message);
g_error_free (err);
}
/* logging */
if (err == NULL)
{
- tr_inf ("%s", _("Allowing desktop hibernation"));
+ tr_logAddInfo ("%s", _("Allowing desktop hibernation"));
}
else
{
history.c \
inout.c \
list.c \
+ log.c \
magnet.c \
makemeta.c \
metainfo.c \
jsonsl.h \
libtransmission-test.h \
list.h \
+ log.h \
magnet.h \
makemeta.h \
metainfo.h \
#include "transmission.h"
#include "announcer-common.h"
+#include "log.h"
#include "net.h" /* tr_globalIPv6 () */
#include "peer-mgr.h" /* pex */
#include "torrent.h"
#include "web.h" /* tr_http_escape () */
#define dbgmsg(name, ...) \
-if (tr_deepLoggingIsActive ()) do { \
- tr_deepLog (__FILE__, __LINE__, name, __VA_ARGS__); \
-} while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, name, __VA_ARGS__); \
+ } \
+ while (0)
/****
*****
#include "announcer.h"
#include "announcer-common.h"
#include "crypto.h" /* tr_cryptoRandBuf () */
+#include "log.h"
#include "peer-io.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex () */
#include "ptrarray.h"
#include "utils.h"
#define dbgmsg(name, ...) \
-if (tr_deepLoggingIsActive ()) do { \
- tr_deepLog (__FILE__, __LINE__, name, __VA_ARGS__); \
-} while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, name, __VA_ARGS__); \
+ } \
+ while (0)
/****
*****
#include "announcer.h"
#include "announcer-common.h"
#include "crypto.h" /* tr_cryptoRandInt (), tr_cryptoWeakRandInt () */
+#include "log.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex () */
#include "ptrarray.h"
#include "session.h"
char * buf, size_t buflen);
#define dbgmsg(tier, ...) \
-if (tr_deepLoggingIsActive ()) do { \
- char name[128]; \
- tier_build_log_name (tier, name, sizeof (name)); \
- tr_deepLog (__FILE__, __LINE__, name, __VA_ARGS__); \
-} while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ { \
+ char name[128]; \
+ tier_build_log_name (tier, name, sizeof (name)); \
+ tr_logAddDeep (__FILE__, __LINE__, name, __VA_ARGS__); \
+ } \
+ } \
+ while (0)
enum
{
static void
dbgmsg_tier_announce_queue (const tr_tier * tier)
{
- if (tr_deepLoggingIsActive ())
+ if (tr_logGetDeepEnabled ())
{
int i;
char name[128];
}
message = evbuffer_free_to_str (buf);
- tr_deepLog (__FILE__, __LINE__, name, "announce queue is %s", message);
+ tr_logAddDeep (__FILE__, __LINE__, name, "announce queue is %s", message);
tr_free (message);
}
}
/* set the error message */
dbgmsg (tier, "%s", err);
- tr_torinf (tier->tor, "%s", err);
+ tr_logAddTorInfo (tier->tor, "%s", err);
tr_strlcpy (tier->lastAnnounceStr, err, sizeof (tier->lastAnnounceStr));
/* switch to the next tracker */
/* schedule a reannounce */
interval = getRetryInterval (tier->currentTracker);
dbgmsg (tier, "Retrying announce in %d seconds.", interval);
- tr_torinf (tier->tor, "Retrying announce in %d seconds.", interval);
+ tr_logAddTorInfo (tier->tor, "Retrying announce in %d seconds.", interval);
tier_announce_event_push (tier, e, tr_time () + interval);
}
then a separate scrape isn't needed */
if ((scrape_fields >= 3) || (!tracker->scrape && (scrape_fields >= 1)))
{
- tr_tordbg (tier->tor, "Announce response contained scrape info; "
+ tr_logAddTorDbg (tier->tor, "Announce response contained scrape info; "
"rescheduling next scrape to %d seconds from now.",
tier->scrapeIntervalSec);
tier->scrapeAt = get_next_scrape_time (announcer->session, tier, tier->scrapeIntervalSec);
else if (!memcmp (request->url, "udp://", 6))
tr_tracker_udp_announce (session, request, callback, callback_data);
else
- tr_err ("Unsupported url: %s", request->url);
+ tr_logAddError ("Unsupported url: %s", request->url);
announce_request_free (request);
}
/* set the error message */
dbgmsg (tier, "Scrape error: %s", errmsg);
- tr_torinf (tier->tor, "Scrape error: %s", errmsg);
+ tr_logAddTorInfo (tier->tor, "Scrape error: %s", errmsg);
tr_strlcpy (tier->lastScrapeStr, errmsg, sizeof (tier->lastScrapeStr));
/* switch to the next tracker */
/* schedule a rescrape */
interval = getRetryInterval (tier->currentTracker);
dbgmsg (tier, "Retrying scrape in %zu seconds.", (size_t)interval);
- tr_torinf (tier->tor, "Retrying scrape in %zu seconds.", (size_t)interval);
+ tr_logAddTorInfo (tier->tor, "Retrying scrape in %zu seconds.", (size_t)interval);
tier->lastScrapeSucceeded = false;
tier->scrapeAt = get_next_scrape_time (session, tier, interval);
}
tier->scrapeIntervalSec = MAX (DEFAULT_SCRAPE_INTERVAL_SEC,
response->min_request_interval);
tier->scrapeAt = get_next_scrape_time (session, tier, tier->scrapeIntervalSec);
- tr_tordbg (tier->tor, "Scrape successful. Rescraping in %d seconds.",
+ tr_logAddTorDbg (tier->tor, "Scrape successful. Rescraping in %d seconds.",
tier->scrapeIntervalSec);
if ((tracker = tier->currentTracker))
else if (!memcmp (request->url, "udp://", 6))
tr_tracker_udp_scrape (session, request, callback, callback_data);
else
- tr_err ("Unsupported url: %s", request->url);
+ tr_logAddError ("Unsupported url: %s", request->url);
}
static void
n = MIN (tr_ptrArraySize (&announceMe), announcer->slotsAvailable);
for (i=0; i<n; ++i) {
tr_tier * tier = tr_ptrArrayNth (&announceMe, i);
- tr_tordbg (tier->tor, "%s", "Announcing to tracker");
+ tr_logAddTorDbg (tier->tor, "%s", "Announcing to tracker");
dbgmsg (tier, "announcing tier %d of %d", i, n);
tierAnnounce (announcer, tier);
}
#include "transmission.h"
#include "bandwidth.h"
#include "crypto.h" /* tr_cryptoWeakRandInt () */
+#include "log.h"
#include "peer-io.h"
#include "utils.h"
#define dbgmsg(...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, NULL, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, NULL, __VA_ARGS__); \
} \
while (0)
#include "transmission.h"
#include "blocklist.h"
+#include "log.h"
#include "net.h"
#include "utils.h"
fd = open (b->filename, O_RDONLY | O_BINARY);
if (fd == -1)
{
- tr_err (err_fmt, b->filename, tr_strerror (errno));
+ tr_logAddError (err_fmt, b->filename, tr_strerror (errno));
return;
}
b->rules = mmap (NULL, byteCount, PROT_READ, MAP_PRIVATE, fd, 0);
if (!b->rules)
{
- tr_err (err_fmt, b->filename, tr_strerror (errno));
+ tr_logAddError (err_fmt, b->filename, tr_strerror (errno));
close (fd);
return;
}
b->ruleCount = byteCount / sizeof (struct tr_ipv4_range);
base = tr_basename (b->filename);
- tr_inf (_("Blocklist \"%s\" contains %zu entries"), base, b->ruleCount);
+ tr_logAddInfo (_("Blocklist \"%s\" contains %zu entries"), base, b->ruleCount);
tr_free (base);
}
in = fopen (filename, "rb");
if (in == NULL)
{
- tr_err (err_fmt, filename, tr_strerror (errno));
+ tr_logAddError (err_fmt, filename, tr_strerror (errno));
return 0;
}
out = fopen (b->filename, "wb+");
if (out == NULL)
{
- tr_err (err_fmt, b->filename, tr_strerror (errno));
+ tr_logAddError (err_fmt, b->filename, tr_strerror (errno));
fclose (in);
return 0;
}
if (!parseLine (line, &range))
{
/* don't try to display the actual lines - it causes issues */
- tr_err (_("blocklist skipped invalid address at line %d"), inCount);
+ tr_logAddError (_("blocklist skipped invalid address at line %d"), inCount);
continue;
}
if (fwrite (ranges, sizeof (struct tr_ipv4_range), ranges_count, out) != ranges_count)
{
- tr_err (_("Couldn't save file \"%1$s\": %2$s"), b->filename, tr_strerror (errno));
+ tr_logAddError (_("Couldn't save file \"%1$s\": %2$s"), b->filename, tr_strerror (errno));
}
else
{
char * base = tr_basename (b->filename);
- tr_inf (_("Blocklist \"%s\" updated with %zu entries"), base, ranges_count);
+ tr_logAddInfo (_("Blocklist \"%s\" updated with %zu entries"), base, ranges_count);
tr_free (base);
}
#include "transmission.h"
#include "cache.h"
#include "inout.h"
+#include "log.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "ptrarray.h"
#include "torrent.h"
#define dbgmsg(...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
} \
while (0)
cache->max_blocks = getMaxBlocks (max_bytes);
tr_formatter_mem_B (buf, cache->max_bytes, sizeof (buf));
- tr_ndbg (MY_NAME, "Maximum cache size set to %s (%d blocks)", buf, cache->max_blocks);
+ tr_logAddNamedDbg (MY_NAME, "Maximum cache size set to %s (%d blocks)", buf, cache->max_blocks);
return cacheTrim (cache);
}
#include "transmission.h"
#include "crypto.h"
+#include "log.h"
#include "utils.h"
#define MY_NAME "tr_crypto"
#define logErrorFromSSL(...) \
do { \
- if (tr_msgLoggingIsActive (TR_MSG_ERR)) { \
+ if (tr_logLevelIsActive (TR_LOG_ERROR)) { \
char buf[512]; \
ERR_error_string_n (ERR_get_error (), buf, sizeof (buf)); \
- tr_msg (__FILE__, __LINE__, TR_MSG_ERR, MY_NAME, "%s", buf); \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_ERROR, MY_NAME, "%s", buf); \
} \
} while (0)
#include "transmission.h"
#include "fdlimit.h"
-#include "net.h"
+#include "log.h"
#include "session.h"
#include "torrent.h" /* tr_isTorrent () */
#define dbgmsg(...) \
- do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, NULL, __VA_ARGS__); \
- } while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, NULL, __VA_ARGS__); \
+ } \
+ while (0)
/***
****
const int err = tr_mkdirp (dir, 0777) ? errno : 0;
if (err)
{
- tr_err (_("Couldn't create \"%1$s\": %2$s"), dir, tr_strerror (err));
+ tr_logAddError (_("Couldn't create \"%1$s\": %2$s"), dir, tr_strerror (err));
tr_free (dir);
return err;
}
if (writable && !alreadyExisted && (allocation == TR_PREALLOCATE_FULL))
if (preallocate_file_full (filename, file_size))
- tr_dbg ("Preallocated file \"%s\"", filename);
+ tr_logAddDebug ("Preallocated file \"%s\"", filename);
/* open the file */
flags = writable ? (O_RDWR | O_CREAT) : O_RDONLY;
if (o->fd == -1)
{
const int err = errno;
- tr_err (_("Couldn't open \"%1$s\": %2$s"), filename, tr_strerror (err));
+ tr_logAddError (_("Couldn't open \"%1$s\": %2$s"), filename, tr_strerror (err));
return err;
}
if (ftruncate (o->fd, file_size) == -1)
{
const int err = errno;
- tr_err (_("Couldn't truncate \"%1$s\": %2$s"), filename, tr_strerror (err));
+ tr_logAddError (_("Couldn't truncate \"%1$s\": %2$s"), filename, tr_strerror (err));
return err;
}
}
limit.rlim_cur = new_limit;
setrlimit (RLIMIT_NOFILE, &limit);
getrlimit (RLIMIT_NOFILE, &limit);
- tr_inf ("Changed open file limit from %d to %d", old_limit, (int)limit.rlim_cur);
+ tr_logAddInfo ("Changed open file limit from %d to %d", old_limit, (int)limit.rlim_cur);
}
}
}
if (gFd->peerCount < session->peerLimit)
if ((s = socket (domain, type, 0)) < 0)
if (sockerrno != EAFNOSUPPORT)
- tr_err (_("Couldn't create socket: %s"), tr_strerror (sockerrno));
+ tr_logAddError (_("Couldn't create socket: %s"), tr_strerror (sockerrno));
if (s > -1)
++gFd->peerCount;
socklen_t size = sizeof (int);
buf_logged = true;
getsockopt (s, SOL_SOCKET, SO_SNDBUF, &i, &size);
- tr_dbg ("SO_SNDBUF size is %d", i);
+ tr_logAddDebug ("SO_SNDBUF size is %d", i);
getsockopt (s, SOL_SOCKET, SO_RCVBUF, &i, &size);
- tr_dbg ("SO_RCVBUF size is %d", i);
+ tr_logAddDebug ("SO_RCVBUF size is %d", i);
}
}
#include "clients.h"
#include "crypto.h"
#include "handshake.h"
+#include "log.h"
#include "peer-io.h"
#include "peer-mgr.h"
#include "session.h"
#define dbgmsg(handshake, ...) \
do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, tr_peerIoGetAddrStr (handshake->io), __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, tr_peerIoGetAddrStr (handshake->io), __VA_ARGS__); \
} while (0)
static const char*
#include "cache.h" /* tr_cacheReadBlock () */
#include "fdlimit.h"
#include "inout.h"
+#include "log.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "stats.h" /* tr_statsFileCreated () */
#include "torrent.h"
prealloc, file->length))) < 0)
{
err = errno;
- tr_torerr (tor, "tr_fdFileCheckout failed for \"%s\": %s",
+ tr_logAddTorErr (tor, "tr_fdFileCheckout failed for \"%s\": %s",
filename, tr_strerror (err));
}
else if (doWrite)
if (rc < 0)
{
err = errno;
- tr_torerr (tor, "read failed for \"%s\": %s", file->name, tr_strerror (err));
+ tr_logAddTorErr (tor, "read failed for \"%s\": %s", file->name, tr_strerror (err));
}
}
else if (ioMode == TR_IO_WRITE)
if (rc < 0)
{
err = errno;
- tr_torerr (tor, "write failed for \"%s\": %s", file->name, tr_strerror (err));
+ tr_logAddTorErr (tor, "write failed for \"%s\": %s", file->name, tr_strerror (err));
}
}
else if (ioMode == TR_IO_PREFETCH)
tr_variantDictAddStr (&dict, TR_KEY_download_dir, downloadDir);
tr_variantDictAddBool (&dict, TR_KEY_port_forwarding_enabled, false);
tr_variantDictAddBool (&dict, TR_KEY_dht_enabled, false);
- tr_variantDictAddInt (&dict, TR_KEY_message_level, verbose ? TR_MSG_DBG : TR_MSG_ERR);
+ tr_variantDictAddInt (&dict, TR_KEY_message_level, verbose ? TR_LOG_DEBUG : TR_LOG_ERROR);
session = tr_sessionInit ("libtransmission-test", sandbox, !verbose, &dict);
/* cleanup locals*/
libtransmission_test_session_close (void)
{
tr_sessionClose (session);
- tr_freeMessageList (tr_getQueuedMessages ());
+ tr_logFreeQueue (tr_logGetQueue ());
session = NULL;
rm_rf (sandbox);
--- /dev/null
+/*
+ * This file Copyright (C) Mnemosyne LLC
+ *
+ * This file is licensed by the GPL version 2. Works owned by the
+ * Transmission project are granted a special exemption to clause 2 (b)
+ * so that the bulk of its code can remain under the MIT license.
+ * This exemption does not extend to derived works not owned by
+ * the Transmission project.
+ *
+ * $Id: utils.c 13863 2013-01-24 23:59:52Z jordan $
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h> /* getenv() */
+
+#include <event2/buffer.h>
+
+#include "transmission.h"
+#include "log.h"
+#include "platform.h" /* tr_lock */
+#include "utils.h"
+
+tr_log_level __tr_message_level = TR_LOG_ERROR;
+
+static bool myQueueEnabled = false;
+static tr_log_message * myQueue = NULL;
+static tr_log_message ** myQueueTail = &myQueue;
+static int myQueueLength = 0;
+
+#ifndef WIN32
+ /* make null versions of these win32 functions */
+ static inline int IsDebuggerPresent (void) { return false; }
+ static inline void OutputDebugString (const void * unused UNUSED) { }
+#endif
+
+/***
+****
+***/
+
+tr_log_level
+tr_logGetLevel (void)
+{
+ return __tr_message_level;
+}
+
+/***
+****
+***/
+
+static tr_lock*
+getMessageLock (void)
+{
+ static tr_lock * l = NULL;
+
+ if (!l)
+ l = tr_lockNew ();
+
+ return l;
+}
+
+void*
+tr_logGetFile (void)
+{
+ static bool initialized = false;
+ static FILE * file = NULL;
+
+ if (!initialized)
+ {
+ int fd = 0;
+ const char * str = getenv ("TR_DEBUG_FD");
+
+ if (str && *str)
+ fd = atoi (str);
+
+ switch (fd)
+ {
+ case 1:
+ file = stdout;
+ break;
+
+ case 2:
+ file = stderr;
+ break;
+
+ default:
+ file = NULL;
+ break;
+ }
+
+ initialized = true;
+ }
+
+ return file;
+}
+
+void
+tr_logSetLevel (tr_log_level level)
+{
+ __tr_message_level = level;
+}
+
+void
+tr_logSetQueueEnabled (bool isEnabled)
+{
+ assert (tr_isBool (isEnabled));
+
+ myQueueEnabled = isEnabled;
+}
+
+bool
+tr_logGetQueueEnabled (void)
+{
+ return myQueueEnabled;
+}
+
+tr_log_message *
+tr_logGetQueue (void)
+{
+ tr_log_message * ret;
+ tr_lockLock (getMessageLock ());
+
+ ret = myQueue;
+ myQueue = NULL;
+ myQueueTail = &myQueue;
+ myQueueLength = 0;
+
+ tr_lockUnlock (getMessageLock ());
+ return ret;
+}
+
+void
+tr_logFreeQueue (tr_log_message * list)
+{
+ tr_log_message * next;
+
+ while (NULL != list)
+ {
+ next = list->next;
+ free (list->message);
+ free (list->name);
+ free (list);
+ list = next;
+ }
+}
+
+/**
+***
+**/
+
+char*
+tr_logGetTimeStr (char * buf, int buflen)
+{
+ char tmp[64];
+ struct tm now_tm;
+ struct timeval tv;
+ time_t seconds;
+ int milliseconds;
+
+ gettimeofday (&tv, NULL);
+
+ seconds = tv.tv_sec;
+ tr_localtime_r (&seconds, &now_tm);
+ strftime (tmp, sizeof (tmp), "%H:%M:%S", &now_tm);
+ milliseconds = tv.tv_usec / 1000;
+ tr_snprintf (buf, buflen, "%s.%03d", tmp, milliseconds);
+
+ return buf;
+}
+
+bool
+tr_logGetDeepEnabled (void)
+{
+ static int8_t deepLoggingIsActive = -1;
+
+ if (deepLoggingIsActive < 0)
+ deepLoggingIsActive = IsDebuggerPresent () || (tr_logGetFile ()!=NULL);
+
+ return deepLoggingIsActive != 0;
+}
+
+void
+tr_logAddDeep (const char * file,
+ int line,
+ const char * name,
+ const char * fmt,
+ ...)
+{
+ FILE * fp = tr_logGetFile ();
+ if (fp || IsDebuggerPresent ())
+ {
+ va_list args;
+ char timestr[64];
+ char * message;
+ struct evbuffer * buf = evbuffer_new ();
+ char * base = tr_basename (file);
+
+ evbuffer_add_printf (buf, "[%s] ",
+ tr_logGetTimeStr (timestr, sizeof (timestr)));
+ if (name)
+ evbuffer_add_printf (buf, "%s ", name);
+ va_start (args, fmt);
+ evbuffer_add_vprintf (buf, fmt, args);
+ va_end (args);
+ evbuffer_add_printf (buf, " (%s:%d)\n", base, line);
+ /* FIXME (libevent2) ifdef this out for nonwindows platforms */
+ message = evbuffer_free_to_str (buf);
+ OutputDebugString (message);
+ if (fp)
+ fputs (message, fp);
+
+ tr_free (message);
+ tr_free (base);
+ }
+}
+
+/***
+****
+***/
+
+void
+tr_logAddMessage (const char * file,
+ int line,
+ tr_log_level level,
+ const char * name,
+ const char * fmt,
+ ...)
+{
+ const int err = errno; /* message logging shouldn't affect errno */
+ char buf[1024];
+ va_list ap;
+ tr_lockLock (getMessageLock ());
+
+ /* build the text message */
+ *buf = '\0';
+ va_start (ap, fmt);
+ evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
+ va_end (ap);
+
+ OutputDebugString (buf);
+
+ if (*buf)
+ {
+ if (tr_logGetQueueEnabled ())
+ {
+ tr_log_message * newmsg;
+ newmsg = tr_new0 (tr_log_message, 1);
+ newmsg->level = level;
+ newmsg->when = tr_time ();
+ newmsg->message = tr_strdup (buf);
+ newmsg->file = file;
+ newmsg->line = line;
+ newmsg->name = tr_strdup (name);
+
+ *myQueueTail = newmsg;
+ myQueueTail = &newmsg->next;
+ ++myQueueLength;
+
+ if (myQueueLength > TR_LOG_MAX_QUEUE_LENGTH)
+ {
+ tr_log_message * old = myQueue;
+ myQueue = old->next;
+ old->next = NULL;
+ tr_logFreeQueue (old);
+ --myQueueLength;
+ assert (myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
+ }
+ }
+ else
+ {
+ FILE * fp;
+ char timestr[64];
+
+ fp = tr_logGetFile ();
+ if (fp == NULL)
+ fp = stderr;
+
+ tr_logGetTimeStr (timestr, sizeof (timestr));
+
+ if (name)
+ fprintf (fp, "[%s] %s: %s\n", timestr, name, buf);
+ else
+ fprintf (fp, "[%s] %s\n", timestr, buf);
+ fflush (fp);
+ }
+ }
+
+ tr_lockUnlock (getMessageLock ());
+ errno = err;
+}
--- /dev/null
+/*
+ * This file Copyright (C) Mnemosyne LLC
+ *
+ * This file is licensed by the GPL version 2. Works owned by the
+ * Transmission project are granted a special exemption to clause 2 (b)
+ * so that the bulk of its code can remain under the MIT license.
+ * This exemption does not extend to derived works not owned by
+ * the Transmission project.
+ *
+ * $Id:$
+ */
+
+#ifndef TR_LOG_H
+#define TR_LOG_H 1
+
+#include <stddef.h> /* size_t */
+#include "utils.h" /* TR_GNUC_PRINTF, TR_GNUC_NONNULL */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TR_LOG_MAX_QUEUE_LENGTH 10000
+
+tr_log_level tr_logGetLevel (void);
+
+static inline bool
+tr_logLevelIsActive (tr_log_level level)
+{
+ return tr_logGetLevel () >= level;
+}
+
+void tr_logAddMessage (const char * file,
+ int line,
+ tr_log_level level,
+ const char * torrent,
+ const char * fmt, ...) TR_GNUC_PRINTF (5, 6);
+
+#define tr_logAddNamedError(n, ...) \
+ do\
+ { \
+ if (tr_logLevelIsActive (TR_LOG_ERROR)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_ERROR, n, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddNamedInfo(n, ...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_INFO)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_INFO, n, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddNamedDbg(n, ...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_DEBUG)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_DEBUG, n, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddTorErr(tor, ...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_ERROR)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_ERROR, tr_torrentName (tor), __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddTorInfo(tor, ...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_INFO)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_INFO, tr_torrentName (tor), __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddTorDbg(tor, ...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_DEBUG)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_DEBUG, tr_torrentName (tor), __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddError(...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_ERROR)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_ERROR, NULL, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddInfo(...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_INFO)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_INFO, NULL, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define tr_logAddDebug(...) \
+ do \
+ { \
+ if (tr_logLevelIsActive (TR_LOG_DEBUG)) \
+ tr_logAddMessage (__FILE__, __LINE__, TR_LOG_DEBUG, NULL, __VA_ARGS__); \
+ } \
+ while (0)
+
+
+
+void* tr_logGetFile (void);
+
+/** @brief return true if deep logging has been enabled by the user; false otherwise */
+bool tr_logGetDeepEnabled (void);
+
+void tr_logAddDeep (const char * file,
+ int line,
+ const char * name,
+ const char * fmt,
+ ...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4);
+
+/** @brief set the buffer with the current time formatted for deep logging. */
+char* tr_logGetTimeStr (char * buf, int buflen) TR_GNUC_NONNULL (1);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
#include "transmission.h"
#include "crypto.h" /* tr_sha1 */
#include "fdlimit.h" /* tr_open_file_for_scanning () */
+#include "log.h"
#include "session.h"
#include "makemeta.h"
#include "platform.h" /* threads, locks */
i = stat (buf, &sb);
if (i)
{
- tr_err (_("Torrent Creator is skipping file \"%s\": %s"),
+ tr_logAddError (_("Torrent Creator is skipping file \"%s\": %s"),
buf, tr_strerror (errno));
tr_free (buf);
return list;
#include "transmission.h"
#include "session.h"
#include "crypto.h" /* tr_sha1 */
+#include "log.h"
#include "metainfo.h"
#include "platform.h" /* tr_getTorrentDir () */
#include "utils.h"
if (badTag)
{
- tr_nerr (inf->name, _("Invalid metadata entry \"%s\""), badTag);
+ tr_logAddNamedError (inf->name, _("Invalid metadata entry \"%s\""), badTag);
tr_metainfoFree (inf);
}
#include "transmission.h"
#include "natpmp_local.h"
+#include "log.h"
#include "net.h" /* tr_netCloseSocket */
#include "port-forwarding.h"
#include "utils.h"
if (ret == NATPMP_TRYAGAIN)
return;
if (ret >= 0)
- tr_ninf (getKey (), _("%s succeeded (%d)"), func, ret);
+ tr_logAddNamedInfo (getKey (), _("%s succeeded (%d)"), func, ret);
else
- tr_ndbg (
+ tr_logAddNamedDbg (
getKey (),
"%s failed. Natpmp returned %d (%s); errno is %d (%s)",
func, ret, strnatpmperr (ret), errno, tr_strerror (errno));
{
char str[128];
evutil_inet_ntop (AF_INET, &response.pnu.publicaddress.addr, str, sizeof (str));
- tr_ninf (getKey (), _("Found public address \"%s\""), str);
+ tr_logAddNamedInfo (getKey (), _("Found public address \"%s\""), str);
nat->state = TR_NATPMP_IDLE;
}
else if (val != NATPMP_TRYAGAIN)
{
const int private_port = resp.pnu.newportmapping.privateport;
- tr_ninf (getKey (), _("no longer forwarding port %d"), private_port);
+ tr_logAddNamedInfo (getKey (), _("no longer forwarding port %d"), private_port);
if (nat->private_port == private_port)
{
nat->renew_time = tr_time () + (resp.pnu.newportmapping.lifetime / 2);
nat->private_port = resp.pnu.newportmapping.privateport;
nat->public_port = resp.pnu.newportmapping.mappedpublicport;
- tr_ninf (getKey (), _("Port %d forwarded successfully"), nat->private_port);
+ tr_logAddNamedInfo (getKey (), _("Port %d forwarded successfully"), nat->private_port);
}
else if (val != NATPMP_TRYAGAIN)
{
#include "peer-io.h" /* tr_peerIoAddrStr () FIXME this should be moved to net.h */
#include "session.h" /* tr_sessionGetPublicAddress () */
#include "tr-utp.h" /* tr_utpSendTo () */
-#include "utils.h" /* tr_time (), tr_dbg () */
+#include "log.h"
+#include "utils.h" /* tr_time (), tr_logAddDebug () */
#ifndef IN_MULTICAST
#define IN_MULTICAST(a) (((a) & 0xf0000000) == 0xe0000000)
if (clientIsSeed) {
int n = 8192;
if (setsockopt (s, SOL_SOCKET, SO_RCVBUF, &n, sizeof (n)))
- tr_inf ("Unable to set SO_RCVBUF on socket %d: %s", s, tr_strerror (sockerrno));
+ tr_logAddInfo ("Unable to set SO_RCVBUF on socket %d: %s", s, tr_strerror (sockerrno));
}
if (evutil_make_socket_nonblocking (s) < 0) {
sourcelen = setup_sockaddr (source_addr, 0, &source_sock);
if (bind (s, (struct sockaddr *) &source_sock, sourcelen))
{
- tr_err (_("Couldn't set source address %s on %d: %s"),
+ tr_logAddError (_("Couldn't set source address %s on %d: %s"),
tr_address_to_string (source_addr), s, tr_strerror (errno));
return -errno;
}
tmperrno = sockerrno;
if ((tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH)
|| addr->type == TR_AF_INET)
- tr_err (_("Couldn't connect socket %d to %s, port %d (errno %d - %s)"),
+ tr_logAddError (_("Couldn't connect socket %d to %s, port %d (errno %d - %s)"),
s, tr_address_to_string (addr), (int)ntohs (port), tmperrno,
tr_strerror (tmperrno));
tr_netClose (session, s);
s = -tmperrno;
}
- tr_deepLog (__FILE__, __LINE__, NULL, "New OUTGOING connection %d (%s)",
- s, tr_peerIoAddrStr (addr, port));
+ tr_logAddDeep (__FILE__, __LINE__, NULL, "New OUTGOING connection %d (%s)",
+ s, tr_peerIoAddrStr (addr, port));
return s;
}
else
fmt = _("Couldn't bind port %d on %s: %s (%s)");
- tr_err (fmt, port, tr_address_to_string (addr), tr_strerror (err), hint);
+ tr_logAddError (fmt, port, tr_address_to_string (addr), tr_strerror (err), hint);
}
tr_netCloseSocket (fd);
*errOut = err;
}
if (!suppressMsgs)
- tr_dbg ("Bound socket %d to port %d on %s", fd, port, tr_address_to_string (addr));
+ tr_logAddDebug ("Bound socket %d to port %d on %s", fd, port, tr_address_to_string (addr));
if (listen (fd, 128) == -1) {
*errOut = sockerrno;
#include "session.h"
#include "bandwidth.h"
#include "crypto.h"
+#include "log.h"
#include "net.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "peer-io.h"
**/
#define dbgmsg(io, ...) \
- do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, tr_peerIoGetAddrStr (io), __VA_ARGS__); \
- } while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, tr_peerIoGetAddrStr (io), __VA_ARGS__); \
+ } \
+ while (0)
/**
***
const int rc = tr_netSetCongestionControl (socket, algorithm);
if (rc < 0)
- tr_ninf ("Net", "Can't set congestion control algorithm '%s': %s",
+ tr_logAddNamedInfo ("Net", "Can't set congestion control algorithm '%s': %s",
algorithm, tr_strerror (errno));
}
}
dbgmsg (io, "utp_on_read got %zu bytes", buflen);
if (rc < 0) {
- tr_nerr ("UTP", "On read evbuffer_add");
+ tr_logAddNamedError ("UTP", "On read evbuffer_add");
return;
}
dbgmsg (io, "utp_on_write sending %zu bytes... evbuffer_remove returned %d", buflen, rc);
assert (rc == (int)buflen); /* if this fails, we've corrupted our bookkeeping somewhere */
if (rc < (long)buflen) {
- tr_nerr ("UTP", "Short write: %d < %ld", rc, (long)buflen);
+ tr_logAddNamedError ("UTP", "Short write: %d < %ld", rc, (long)buflen);
}
didWriteWrapper (io, buflen);
if (io->gotError)
io->gotError (io, BEV_EVENT_EOF, io->userData);
} else if (state == UTP_STATE_DESTROYING) {
- tr_nerr ("UTP", "Impossible state UTP_STATE_DESTROYING");
+ tr_logAddNamedError ("UTP", "Impossible state UTP_STATE_DESTROYING");
return;
} else {
- tr_nerr ("UTP", "Unknown state %d", state);
+ tr_logAddNamedError ("UTP", "Unknown state %d", state);
}
}
dummy_read (void * closure UNUSED, const unsigned char *buf UNUSED, size_t buflen UNUSED)
{
/* This cannot happen, as far as I'm aware. */
- tr_nerr ("UTP", "On_read called on closed socket");
+ tr_logAddNamedError ("UTP", "On_read called on closed socket");
}
{
/* This can very well happen if we've shut down a peer connection that
had unflushed buffers. Complain and send zeroes. */
- tr_ndbg ("UTP", "On_write called on closed socket");
+ tr_logAddNamedDbg ("UTP", "On_write called on closed socket");
memset (buf, 0, buflen);
}
#include "completion.h"
#include "crypto.h"
#include "handshake.h"
+#include "log.h"
#include "net.h"
#include "peer-io.h"
#include "peer-mgr.h"
#define tordbg(t, ...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, tr_torrentName (t->tor), __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, tr_torrentName (t->tor), __VA_ARGS__); \
} \
while (0)
#define dbgmsg(...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, NULL, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, NULL, __VA_ARGS__); \
} \
while (0)
if (!ok)
{
- tr_torerr (tor, _("Piece %lu, which was just downloaded, failed its checksum test"),
+ tr_logAddTorErr (tor, _("Piece %lu, which was just downloaded, failed its checksum test"),
(unsigned long)p);
}
if (tr_sessionIsAddressBlocked (session, addr))
{
- tr_dbg ("Banned IP address \"%s\" tried to connect to us", tr_address_to_string (addr));
+ tr_logAddDebug ("Banned IP address \"%s\" tried to connect to us", tr_address_to_string (addr));
if (socket >= 0)
tr_netClose (session, socket);
else
#include "cache.h"
#include "completion.h"
#include "crypto.h" /* tr_sha1 () */
+#include "log.h"
#include "peer-io.h"
#include "peer-mgr.h"
#include "peer-msgs.h"
const struct tr_peermsgs * msgs,
const char * fmt, ...)
{
- FILE * fp = tr_getLog ();
+ FILE * fp = tr_logGetFile ();
if (fp)
{
char * message;
evbuffer_add_printf (buf, "[%s] %s - %s [%s]: ",
- tr_getLogTimeStr (timestr, sizeof (timestr)),
+ tr_logGetTimeStr (timestr, sizeof (timestr)),
tr_torrentName (msgs->torrent),
tr_peerIoGetAddrStr (msgs->peer->io),
tr_quark_get_string (msgs->peer->client, NULL));
#define dbgmsg(msgs, ...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
+ if (tr_logGetDeepEnabled ()) \
myDebug (__FILE__, __LINE__, msgs, __VA_ARGS__); \
} \
while (0)
#include "transmission.h"
#include "session.h"
#include "list.h"
+#include "log.h"
#include "platform.h"
#include "utils.h"
}
if (count)
- tr_inf (_("Migrated %1$d files from \"%2$s\" to \"%3$s\""), count, oldDir, newDir);
+ tr_logAddInfo (_("Migrated %1$d files from \"%2$s\" to \"%3$s\""), count, oldDir, newDir);
closedir (dirh);
}
struct stat sb;
char * tmp = tr_buildPath (path, "index.html", NULL);
const int ret = !stat (tmp, &sb);
- tr_inf (_("Searching for web interface file \"%s\""), tmp);
+ tr_logAddInfo (_("Searching for web interface file \"%s\""), tmp);
tr_free (tmp);
return ret;
#include "transmission.h"
#include "natpmp_local.h"
+#include "log.h"
#include "net.h"
#include "peer-mgr.h"
#include "port-forwarding.h"
newStatus = tr_sharedTraversalStatus (s);
if (newStatus != oldStatus)
- tr_ninf (getKey (), _("State changed from \"%1$s\" to \"%2$s\""),
+ tr_logAddNamedInfo (getKey (), _("State changed from \"%1$s\" to \"%2$s\""),
getNatStateStr (oldStatus),
getNatStateStr (newStatus));
}
static void
stop_forwarding (tr_shared * s)
{
- tr_ninf (getKey (), "%s", _("Stopped"));
+ tr_logAddNamedInfo (getKey (), "%s", _("Stopped"));
natPulse (s, false);
tr_natpmpClose (s->natpmp);
#include "transmission.h"
#include "completion.h"
+#include "log.h"
#include "metainfo.h" /* tr_metainfoGetBasename () */
#include "peer-mgr.h" /* pex */
#include "platform.h" /* tr_getResumeDir () */
if (tr_variantDictFindRaw (dict, TR_KEY_peers, &str, &len))
{
const int numAdded = addPeers (tor, str, len);
- tr_tordbg (tor, "Loaded %d IPv4 peers from resume file", numAdded);
+ tr_logAddTorDbg (tor, "Loaded %d IPv4 peers from resume file", numAdded);
ret = TR_FR_PEERS;
}
if (tr_variantDictFindRaw (dict, TR_KEY_peers6, &str, &len))
{
const int numAdded = addPeers (tor, str, len);
- tr_tordbg (tor, "Loaded %d IPv6 peers from resume file", numAdded);
+ tr_logAddTorDbg (tor, "Loaded %d IPv6 peers from resume file", numAdded);
ret = TR_FR_PEERS;
}
if (dndCount)
{
tr_torrentInitFileDLs (tor, dnd, dndCount, false);
- tr_tordbg (tor, "Resume file found %d files listed as dnd",
+ tr_logAddTorDbg (tor, "Resume file found %d files listed as dnd",
dndCount);
}
if (dlCount)
{
tr_torrentInitFileDLs (tor, dl, dlCount, true);
- tr_tordbg (tor,
+ tr_logAddTorDbg (tor,
"Resume file found %d files marked for download",
dlCount);
}
}
else
{
- tr_tordbg (
+ tr_logAddTorDbg (
tor,
"Couldn't load DND flags. DND list (%p) has %zu children; torrent has %d files",
list, tr_variantListSize (list), (int)n);
else err = "Couldn't find 'pieces' or 'have' or 'bitfield'";
if (err != NULL)
- tr_tordbg (tor, "Torrent needs to be verified - %s", err);
+ tr_logAddTorDbg (tor, "Torrent needs to be verified - %s", err);
else
tr_cpBlockInit (&tor->completion, &blocks);
if (tr_variantFromFile (&top, TR_VARIANT_FMT_BENC, filename))
{
- tr_tordbg (tor, "Couldn't read \"%s\"", filename);
+ tr_logAddTorDbg (tor, "Couldn't read \"%s\"", filename);
tr_free (filename);
return fieldsLoaded;
}
- tr_tordbg (tor, "Read resume file \"%s\"", filename);
+ tr_logAddTorDbg (tor, "Read resume file \"%s\"", filename);
if ((fieldsToLoad & TR_FR_CORRUPT)
&& tr_variantDictFindInt (&top, TR_KEY_corrupt, &i))
#include "crypto.h" /* tr_cryptoRandBuf (), tr_ssha1_matches () */
#include "fdlimit.h"
#include "list.h"
+#include "log.h"
#include "net.h"
#include "platform.h" /* tr_getWebClientDir () */
#include "ptrarray.h"
#define dbgmsg(...) \
do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
} while (0)
char * token = tr_strndup (walk, len);
tr_list_append (&server->whitelist, token);
if (strcspn (token, "+-") < len)
- tr_ninf (MY_NAME, "Adding address to whitelist: %s (And it has a '+' or '-'! Are you using an old ACL by mistake?)", token);
+ tr_logAddNamedInfo (MY_NAME, "Adding address to whitelist: %s (And it has a '+' or '-'! Are you using an old ACL by mistake?)", token);
else
- tr_ninf (MY_NAME, "Adding address to whitelist: %s", token);
+ tr_logAddNamedInfo (MY_NAME, "Adding address to whitelist: %s", token);
if (walk[len]=='\0')
break;
missing_settings_key (const tr_quark q)
{
const char * str = tr_quark_get_string (q, NULL);
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), str);
+ tr_logAddNamedError (MY_NAME, _("Couldn't find settings key \"%s\""), str);
}
tr_rpc_server *
missing_settings_key (key);
address = tr_inaddr_any;
} else if (!tr_address_from_string (&address, str)) {
- tr_nerr (MY_NAME, _("%s is not a valid address"), str);
+ tr_logAddNamedError (MY_NAME, _("%s is not a valid address"), str);
address = tr_inaddr_any;
} else if (address.type != TR_AF_INET) {
- tr_nerr (MY_NAME, _("%s is not an IPv4 address. RPC listeners must be IPv4"), str);
+ tr_logAddNamedError (MY_NAME, _("%s is not an IPv4 address. RPC listeners must be IPv4"), str);
address = tr_inaddr_any;
}
s->bindAddress = address.addr.addr4;
if (s->isEnabled)
{
- tr_ninf (MY_NAME, _("Serving RPC and Web requests on port 127.0.0.1:%d%s"), (int) s->port, s->url);
+ tr_logAddNamedInfo (MY_NAME, _("Serving RPC and Web requests on port 127.0.0.1:%d%s"), (int) s->port, s->url);
tr_runInEventThread (session, startServer, s);
if (s->isWhitelistEnabled)
- tr_ninf (MY_NAME, "%s", _("Whitelist enabled"));
+ tr_logAddNamedInfo (MY_NAME, "%s", _("Whitelist enabled"));
if (s->isPasswordEnabled)
- tr_ninf (MY_NAME, "%s", _("Password required"));
+ tr_logAddNamedInfo (MY_NAME, "%s", _("Password required"));
}
return s;
#include "transmission.h"
#include "completion.h"
#include "fdlimit.h"
+#include "log.h"
#include "rpcimpl.h"
#include "session.h"
#include "torrent.h"
} while (0)
#else
#define dbgmsg(...) \
- do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, "RPC", __VA_ARGS__); \
- } while (0)
+ do \
+ { \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, "RPC", __VA_ARGS__); \
+ } \
+ while (0)
#endif
tr_snprintf (result, sizeof (result), _("Couldn't save file \"%1$s\": %2$s"), filename, tr_strerror (errno));
if (*result)
- tr_err ("%s", result);
+ tr_logAddError ("%s", result);
else {
/* feed it to the session and give the client a response */
const int rule_count = tr_blocklistSetContent (session, filename);
#include "crypto.h"
#include "fdlimit.h"
#include "list.h"
+#include "log.h"
#include "net.h"
#include "peer-io.h"
#include "peer-mgr.h"
#define dbgmsg(...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, NULL, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, NULL, __VA_ARGS__); \
} \
while (0)
clientSocket = tr_netAccept (session, fd, &clientAddr, &clientPort);
if (clientSocket > 0) {
- tr_deepLog (__FILE__, __LINE__, NULL, "new incoming connection %d (%s)",
- clientSocket, tr_peerIoAddrStr (&clientAddr, clientPort));
+ tr_logAddDeep (__FILE__, __LINE__, NULL, "new incoming connection %d (%s)",
+ clientSocket, tr_peerIoAddrStr (&clientAddr, clientPort));
tr_peerMgrAddIncoming (session->peerMgr, &clientAddr, clientPort,
clientSocket, NULL);
}
tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled, false);
tr_variantDictAddStr (d, TR_KEY_incomplete_dir, tr_getDefaultDownloadDir ());
tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled, false);
- tr_variantDictAddInt (d, TR_KEY_message_level, TR_MSG_INF);
+ tr_variantDictAddInt (d, TR_KEY_message_level, TR_LOG_INFO);
tr_variantDictAddInt (d, TR_KEY_download_queue_size, 5);
tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, true);
tr_variantDictAddInt (d, TR_KEY_peer_limit_global, atoi (TR_DEFAULT_PEER_LIMIT_GLOBAL_STR));
tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled, tr_sessionIsIdleLimited (s));
tr_variantDictAddStr (d, TR_KEY_incomplete_dir, tr_sessionGetIncompleteDir (s));
tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled, tr_sessionIsIncompleteDirEnabled (s));
- tr_variantDictAddInt (d, TR_KEY_message_level, tr_getMessageLevel ());
+ tr_variantDictAddInt (d, TR_KEY_message_level, tr_logGetLevel ());
tr_variantDictAddInt (d, TR_KEY_peer_limit_global, s->peerLimit);
tr_variantDictAddInt (d, TR_KEY_peer_limit_per_torrent, s->peerLimitPerTorrent);
tr_variantDictAddInt (d, TR_KEY_peer_port, tr_sessionGetPeerPort (s));
tr_session * session = vsession;
if (tr_cacheFlushDone (session->cache))
- tr_err ("Error while flushing completed pieces from cache");
+ tr_logAddError ("Error while flushing completed pieces from cache");
while ((tor = tr_torrentNext (session, tor)))
tr_torrentSave (tor);
/* nice to start logging at the very beginning */
if (tr_variantDictFindInt (clientSettings, TR_KEY_message_level, &i))
- tr_setMessageLevel (i);
+ tr_logSetLevel (i);
/* start the libtransmission thread */
tr_netInit (); /* must go before tr_eventInit */
signal (SIGPIPE, SIG_IGN);
#endif
- tr_setMessageQueuing (data->messageQueuingEnabled);
+ tr_logSetQueueEnabled (data->messageQueuingEnabled);
tr_setConfigDir (session, data->configDir);
/* first %s is the application name
second %s is the version number */
- tr_inf (_("%s %s started"), TR_NAME, LONG_VERSION_STRING);
+ tr_logAddInfo (_("%s %s started"), TR_NAME, LONG_VERSION_STRING);
tr_statsInit (session);
assert (tr_amInEventThread (session));
if (tr_variantDictFindInt (settings, TR_KEY_message_level, &i))
- tr_setMessageLevel (i);
+ tr_logSetLevel (i);
if (tr_variantDictFindInt (settings, TR_KEY_umask, &i)) {
session->umask = (mode_t)i;
if (!alreadySwitched)
{
- tr_inf ("Time to turn %s turtle mode!", (enabled?"on":"off"));
+ tr_logAddInfo ("Time to turn %s turtle mode!", (enabled?"on":"off"));
t->autoTurtleState = newAutoTurtleState;
useAltSpeed (s, t, enabled, false);
}
static void
userPokedTheClock (tr_session * s, struct tr_turtle_info * t)
{
- tr_dbg ("Refreshing the turtle mode clock due to user changes");
+ tr_logAddDebug ("Refreshing the turtle mode clock due to user changes");
t->autoTurtleState = TR_AUTO_SWITCH_UNUSED;
tr_list_free (&list, NULL);
if (n)
- tr_inf (_("Loaded %d torrents"), n);
+ tr_logAddInfo (_("Loaded %d torrents"), n);
if (data->setmeCount)
*data->setmeCount = n;
tr_ctorFree (ctor);
session->metainfoLookup = lookup;
- tr_dbg ("Found %d torrents in \"%s\"", n, dirname);
+ tr_logAddDebug ("Found %d torrents in \"%s\"", n, dirname);
}
const char*
#include "transmission.h"
#include "session.h"
+#include "log.h"
#include "platform.h" /* tr_sessionGetConfigDir () */
#include "stats.h"
#include "utils.h" /* tr_buildPath */
tr_variantDictAddInt (&top, TR_KEY_uploaded_bytes, s->uploadedBytes);
filename = getFilename (session);
- tr_deepLog (__FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename);
+ tr_logAddDeep (__FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename);
tr_variantToFile (&top, TR_VARIANT_FMT_JSON, filename);
tr_free (filename);
#include "transmission.h"
#include "crypto.h" /* tr_sha1 () */
+#include "log.h"
#include "magnet.h"
#include "metainfo.h"
#include "resume.h"
#define dbgmsg(tor, ...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, tr_torrentName (tor), __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, tr_torrentName (tor), __VA_ARGS__); \
} \
while (0)
m->piecesNeededCount = n;
dbgmsg (tor, "metadata error; trying again. %d pieces left", n);
- tr_err ("magnet status: checksum passed %d, metainfo parsed %d",
+ tr_logAddError ("magnet status: checksum passed %d, metainfo parsed %d",
(int)checksumPassed, (int)metainfoParsed);
}
}
#include "resume.h"
#include "fdlimit.h" /* tr_fdTorrentClose */
#include "inout.h" /* tr_ioTestPiece () */
+#include "log.h"
#include "magnet.h"
#include "metainfo.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#define tr_deeplog_tor(tor, ...) \
do \
{ \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, tr_torrentName (tor), __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, tr_torrentName (tor), __VA_ARGS__); \
} \
while (0)
/* if we're seeding and reach our seed ratio limit, stop the torrent */
if (tr_torrentIsSeedRatioDone (tor))
{
- tr_torinf (tor, "%s", "Seed ratio reached; pausing torrent");
+ tr_logAddTorInfo (tor, "%s", "Seed ratio reached; pausing torrent");
tor->isStopping = true;
/* if we're seeding and reach our inactiviy limit, stop the torrent */
else if (tr_torrentIsSeedIdleLimitDone (tor))
{
- tr_torinf (tor, "%s", "Seeding idle limit reached; pausing torrent");
+ tr_logAddTorInfo (tor, "%s", "Seeding idle limit reached; pausing torrent");
tor->isStopping = true;
tor->finishedSeedingByIdle = true;
evutil_vsnprintf (tor->errorString, sizeof (tor->errorString), fmt, ap);
va_end (ap);
- tr_torerr (tor, "%s", tor->errorString);
+ tr_logAddTorErr (tor, "%s", tor->errorString);
if (tor->isRunning)
tor->isStopping = true;
const bool allAreSeeds = seedProbability == 100;
if (allAreSeeds)
- tr_tordbg (tor, "Got %zu seeds from tracker", event->pexCount);
+ tr_logAddTorDbg (tor, "Got %zu seeds from tracker", event->pexCount);
else
- tr_tordbg (tor, "Got %zu peers from tracker", event->pexCount);
+ tr_logAddTorDbg (tor, "Got %zu peers from tracker", event->pexCount);
for (i = 0; i < event->pexCount; ++i)
tr_peerMgrAddPex (tor, TR_PEER_FROM_TRACKER, &event->pex[i], seedProbability);
}
case TR_TRACKER_WARNING:
- tr_torerr (tor, _("Tracker warning: \"%s\""), event->text);
+ tr_logAddTorErr (tor, _("Tracker warning: \"%s\""), event->text);
tor->error = TR_STAT_TRACKER_WARNING;
tr_strlcpy (tor->errorTracker, event->tracker, sizeof (tor->errorTracker));
tr_strlcpy (tor->errorString, event->text, sizeof (tor->errorString));
break;
case TR_TRACKER_ERROR:
- tr_torerr (tor, _("Tracker error: \"%s\""), event->text);
+ tr_logAddTorErr (tor, _("Tracker error: \"%s\""), event->text);
tor->error = TR_STAT_TRACKER_ERROR;
tr_strlcpy (tor->errorTracker, event->tracker, sizeof (tor->errorTracker));
tr_strlcpy (tor->errorString, event->text, sizeof (tor->errorString));
/* allow finished torrents to be resumed */
if (tr_torrentIsSeedRatioDone (tor)) {
- tr_torinf (tor, "%s", _("Restarted manually -- disabling its seed ratio"));
+ tr_logAddTorInfo (tor, "%s", _("Restarted manually -- disabling its seed ratio"));
tr_torrentSetRatioMode (tor, TR_RATIOLIMIT_UNLIMITED);
}
stopTorrent (void * vtor)
{
tr_torrent * tor = vtor;
- tr_torinf (tor, "%s", "Pausing");
+ tr_logAddTorInfo (tor, "%s", "Pausing");
assert (tr_isTorrent (tor));
tr_variantDictAddInt (d, TR_KEY_id, tor->uniqueId);
tr_variantDictAddInt (d, TR_KEY_date, tr_time ());
- tr_torinf (tor, "%s", _("Removing torrent"));
+ tr_logAddTorInfo (tor, "%s", _("Removing torrent"));
stopTorrent (tor);
tr_strdup_printf ("TR_TORRENT_NAME=%s", tr_torrentName (tor)),
NULL };
- tr_torinf (tor, "Calling script \"%s\"", script);
+ tr_logAddTorInfo (tor, "Calling script \"%s\"", script);
#ifdef WIN32
if (_spawnvpe (_P_NOWAIT, script, (const char*)cmd, env) == -1)
- tr_torerr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
+ tr_logAddTorErr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
#else
signal (SIGCHLD, onSigCHLD);
putenv (env[i]);
if (execvp (script, cmd) == -1)
- tr_torerr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
+ tr_logAddTorErr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
_exit (0);
}
const bool wasRunning = tor->isRunning;
if (recentChange)
- tr_torinf (tor, _("State changed from \"%1$s\" to \"%2$s\""),
+ tr_logAddTorInfo (tor, _("State changed from \"%1$s\" to \"%2$s\""),
getCompletionString (tor->completeness),
getCompletionString (completeness));
else if (tr_pieceOffset (tor, index, offset, length) > tor->info.totalSize)
err = 5;
- if (err) tr_tordbg (tor, "index %lu offset %lu length %lu err %d\n",
+ if (err) tr_logAddTorDbg (tor, "index %lu offset %lu length %lu err %d\n",
(unsigned long)index,
(unsigned long)offset,
(unsigned long)length,
assert (tr_isTorrent (tor));
- tr_dbg ("Moving \"%s\" location from currentDir \"%s\" to \"%s\"",
+ tr_logAddDebug ("Moving \"%s\" location from currentDir \"%s\" to \"%s\"",
tr_torrentName (tor), tor->currentDir, location);
tr_mkdirp (location, 0777);
char * oldpath = tr_buildPath (oldbase, sub, NULL);
char * newpath = tr_buildPath (location, sub, NULL);
- tr_dbg ("Found file #%d: %s", (int)i, oldpath);
+ tr_logAddDebug ("Found file #%d: %s", (int)i, oldpath);
if (do_move && !tr_is_same_file (oldpath, newpath))
{
bool renamed = false;
errno = 0;
- tr_torinf (tor, "moving \"%s\" to \"%s\"", oldpath, newpath);
+ tr_logAddTorInfo (tor, "moving \"%s\" to \"%s\"", oldpath, newpath);
if (tr_moveFile (oldpath, newpath, &renamed))
{
err = true;
- tr_torerr (tor, "error moving \"%s\" to \"%s\": %s",
+ tr_logAddTorErr (tor, "error moving \"%s\" to \"%s\": %s",
oldpath, newpath, tr_strerror (errno));
}
}
char * newpath = tr_buildPath (base, f->name, NULL);
if (rename (oldpath, newpath))
- tr_torerr (tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror (errno));
+ tr_logAddTorErr (tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror (errno));
tr_free (newpath);
tr_free (oldpath);
/* libT */
#include "transmission.h"
#include "crypto.h"
+#include "log.h"
#include "net.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex () */
#include "platform.h" /* tr_threadNew () */
rc = getaddrinfo (name, pp, &hints, &info);
if (rc != 0) {
- tr_nerr ("DHT", "%s:%s: %s", name, pp, gai_strerror (rc));
+ tr_logAddNamedError ("DHT", "%s:%s: %s", name, pp, gai_strerror (rc));
return;
}
return;
if (cl->len > 0)
- tr_ninf ("DHT", "Bootstrapping from %d IPv4 nodes", num);
+ tr_logAddNamedInfo ("DHT", "Bootstrapping from %d IPv4 nodes", num);
if (cl->len6 > 0)
- tr_ninf ("DHT", "Bootstrapping from %d IPv6 nodes", num6);
+ tr_logAddNamedInfo ("DHT", "Bootstrapping from %d IPv6 nodes", num6);
for (i = 0; i < MAX (num, num6); i++) {
if (bootstrap_file)
f = fopen (bootstrap_file, "rb");
if (f != NULL) {
- tr_ninf ("DHT", "Attempting manual bootstrap");
+ tr_logAddNamedInfo ("DHT", "Attempting manual bootstrap");
for (;;) {
char buf[201];
char *p;
if (p != NULL)
port = atoi (p + 1);
if (p == NULL || port <= 0 || port >= 0x10000) {
- tr_nerr ("DHT", "Couldn't parse %s", buf);
+ tr_logAddNamedError ("DHT", "Couldn't parse %s", buf);
continue;
}
if (bootstrap_done (cl->session, 0))
break;
if (i == 0)
- tr_ninf ("DHT",
+ tr_logAddNamedInfo ("DHT",
"Attempting bootstrap from dht.transmissionbt.com");
bootstrap_from_name ("dht.transmissionbt.com", 6881,
bootstrap_af (session));
if (cl->nodes6)
tr_free (cl->nodes6);
tr_free (closure);
- tr_ndbg ("DHT", "Finished bootstrapping");
+ tr_logAddNamedDbg ("DHT", "Finished bootstrapping");
}
int
if (session) /* already initialized */
return -1;
- tr_ndbg ("DHT", "Initializing DHT");
+ tr_logAddNamedDbg ("DHT", "Initializing DHT");
if (getenv ("TR_DHT_VERBOSE") != NULL)
dht_debug = stderr;
len6 = 0;
if (have_id)
- tr_ninf ("DHT", "Reusing old id");
+ tr_logAddNamedInfo ("DHT", "Reusing old id");
else {
/* Note that DHT ids need to be distributed uniformly,
* so it should be something truly random. */
- tr_ninf ("DHT", "Generating new id");
+ tr_logAddNamedInfo ("DHT", "Generating new id");
tr_cryptoRandBuf (myid, 20);
}
dht_timer = evtimer_new (session->event_base, timer_callback, session);
tr_timerAdd (dht_timer, 0, tr_cryptoWeakRandInt (1000000));
- tr_ndbg ("DHT", "DHT initialized");
+ tr_logAddNamedDbg ("DHT", "DHT initialized");
return 1;
fail:
- tr_ndbg ("DHT", "DHT initialization failed (errno = %d)", errno);
+ tr_logAddNamedDbg ("DHT", "DHT initialization failed (errno = %d)", errno);
session = NULL;
return -1;
}
if (session != ss)
return;
- tr_ndbg ("DHT", "Uninitializing DHT");
+ tr_logAddNamedDbg ("DHT", "Uninitializing DHT");
if (dht_timer != NULL) {
event_free (dht_timer);
don't know enough nodes. */
if ((tr_dhtStatus (ss, AF_INET, NULL) < TR_DHT_FIREWALLED) &&
(tr_dhtStatus (ss, AF_INET6, NULL) < TR_DHT_FIREWALLED)) {
- tr_ninf ("DHT", "Not saving nodes, DHT not ready");
+ tr_logAddNamedInfo ("DHT", "Not saving nodes, DHT not ready");
} else {
tr_variant benc;
struct sockaddr_in sins[300];
int i, j, num = 300, num6 = 300;
int n = dht_get_nodes (sins, &num, sins6, &num6);
- tr_ninf ("DHT", "Saving %d (%d + %d) nodes", n, num, num6);
+ tr_logAddNamedInfo ("DHT", "Saving %d (%d + %d) nodes", n, num, num6);
j = 0;
for (i=0; i<num; ++i) {
}
dht_uninit ();
- tr_ndbg ("DHT", "Done uninitializing DHT");
+ tr_logAddNamedDbg ("DHT", "Done uninitializing DHT");
session = NULL;
}
for (i=0; i<n; ++i)
tr_peerMgrAddPex (tor, TR_PEER_FROM_DHT, pex+i, -1);
tr_free (pex);
- tr_tordbg (tor, "Learned %d %s peers from DHT",
+ tr_logAddTorDbg (tor, "Learned %d %s peers from DHT",
(int)n,
event == DHT_EVENT_VALUES6 ? "IPv6" : "IPv4");
}
tr_torrent * tor = tr_torrentFindFromHash (session, info_hash);
if (tor) {
if (event == DHT_EVENT_SEARCH_DONE) {
- tr_torinf (tor, "%s", "IPv4 DHT announce done");
+ tr_logAddTorInfo (tor, "%s", "IPv4 DHT announce done");
tor->dhtAnnounceInProgress = 0;
} else {
- tr_torinf (tor, "%s", "IPv6 DHT announce done");
+ tr_logAddTorInfo (tor, "%s", "IPv6 DHT announce done");
tor->dhtAnnounce6InProgress = 0;
}
}
announce ? tr_sessionGetPeerPort (session) : 0,
af, callback, NULL);
if (rc >= 1) {
- tr_torinf (tor, "Starting %s DHT announce (%s, %d nodes)",
+ tr_logAddTorInfo (tor, "Starting %s DHT announce (%s, %d nodes)",
af == AF_INET6 ? "IPv6" : "IPv4",
tr_dhtPrintableStatus (status), numnodes);
if (af == AF_INET)
tor->dhtAnnounce6InProgress = true;
ret = 1;
} else {
- tr_torerr (tor, "%s DHT announce failed (%s, %d nodes): %s",
+ tr_logAddTorErr (tor, "%s DHT announce failed (%s, %d nodes): %s",
af == AF_INET6 ? "IPv6" : "IPv4",
tr_dhtPrintableStatus (status), numnodes,
tr_strerror (errno));
}
} else {
- tr_tordbg (tor, "%s DHT not ready (%s, %d nodes)",
+ tr_logAddTorDbg (tor, "%s DHT not ready (%s, %d nodes)",
af == AF_INET6 ? "IPv6" : "IPv4",
tr_dhtPrintableStatus (status), numnodes);
}
if (errno == EINTR) {
tosleep = 0;
} else {
- tr_nerr ("DHT", "dht_periodic failed: %s", tr_strerror (errno));
+ tr_logAddNamedError ("DHT", "dht_periodic failed: %s", tr_strerror (errno));
if (errno == EINVAL || errno == EFAULT)
abort ();
tosleep = 1;
/* libT */
#include "transmission.h"
+#include "log.h"
#include "net.h"
#include "peer-mgr.h" /* tr_peerMgrAddPex () */
#include "session.h"
if (lpd_port <= 0)
return -1;
- tr_ndbg ("LPD", "Initialising Local Peer Discovery");
+ tr_logAddNamedDbg ("LPD", "Initialising Local Peer Discovery");
/* setup datagram socket (receive) */
{
upkeep_timer = evtimer_new (ss->event_base, on_upkeep_timer, ss);
tr_timerAdd (upkeep_timer, UPKEEP_INTERVAL_SECS, 0);
- tr_ndbg ("LPD", "Local Peer Discovery initialised");
+ tr_logAddNamedDbg ("LPD", "Local Peer Discovery initialised");
return 1;
close (lpd_socket2);
lpd_socket = lpd_socket2 = -1;
session = NULL;
- tr_ndbg ("LPD", "LPD initialisation failed (errno = %d)", save);
+ tr_logAddNamedDbg ("LPD", "LPD initialisation failed (errno = %d)", save);
errno = save;
}
if (session != ss)
return;
- tr_ndbg ("LPD", "Uninitialising Local Peer Discovery");
+ tr_logAddNamedDbg ("LPD", "Uninitialising Local Peer Discovery");
event_free (lpd_event);
lpd_event = NULL;
/* just shut down, we won't remember any former nodes */
evutil_closesocket (lpd_socket);
evutil_closesocket (lpd_socket2);
- tr_ndbg ("LPD", "Done uninitialising Local Peer Discovery");
+ tr_logAddNamedDbg ("LPD", "Done uninitialising Local Peer Discovery");
session = NULL;
}
return false;
}
- tr_tordbg (t, "LPD announce message away");
+ tr_logAddTorDbg (t, "LPD announce message away");
return true;
}
{
/* we found a suitable peer, add it to the torrent */
tr_peerMgrAddPex (tor, TR_PEER_FROM_LPD, peer, -1);
- tr_tordbg (tor, "Learned %d local peer from LPD (%s:%u)",
+ tr_logAddTorDbg (tor, "Learned %d local peer from LPD (%s:%u)",
1, tr_address_to_string (&peer->addr), peerPort);
/* periodic reconnectPulse () deals with the rest... */
return 1;
}
else
- tr_ndbg ("LPD", "Cannot serve torrent #%s", hashString);
+ tr_logAddNamedDbg ("LPD", "Cannot serve torrent #%s", hashString);
}
return res;
const int maxAnnounceCap = interval * lpd_announceCapFactor;
if (lpd_unsolicitedMsgCounter < 0)
- tr_ninf ("LPD", "Dropped %d announces in the last interval (max. %d "
+ tr_logAddNamedInfo ("LPD", "Dropped %d announces in the last interval (max. %d "
"allowed)", -lpd_unsolicitedMsgCounter, maxAnnounceCap);
lpd_unsolicitedMsgCounter = maxAnnounceCap;
return; /* OK so far, no log message */
}
- tr_ndbg ("LPD", "Discarded invalid multicast message");
+ tr_logAddNamedDbg ("LPD", "Discarded invalid multicast message");
}
}
#include <libutp/utp.h>
#include "transmission.h"
+#include "log.h"
#include "net.h"
#include "session.h"
#include "tr-dht.h"
size = large ? RECV_BUFFER_SIZE : SMALL_BUFFER_SIZE;
rc = setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size));
if (rc < 0)
- tr_nerr ("UDP", "Failed to set receive buffer: %s",
+ tr_logAddNamedError ("UDP", "Failed to set receive buffer: %s",
tr_strerror (errno));
size = large ? SEND_BUFFER_SIZE : SMALL_BUFFER_SIZE;
rc = setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size));
if (rc < 0)
- tr_nerr ("UDP", "Failed to set send buffer: %s",
+ tr_logAddNamedError ("UDP", "Failed to set send buffer: %s",
tr_strerror (errno));
if (large) {
sbuf = 0;
if (rbuf < RECV_BUFFER_SIZE) {
- tr_nerr ("UDP", "Failed to set receive buffer: requested %d, got %d",
+ tr_logAddNamedError ("UDP", "Failed to set receive buffer: requested %d, got %d",
RECV_BUFFER_SIZE, rbuf);
#ifdef __linux__
- tr_ninf ("UDP",
+ tr_logAddNamedInfo ("UDP",
"Please add the line "
"\"net.core.rmem_max = %d\" to /etc/sysctl.conf",
RECV_BUFFER_SIZE);
}
if (sbuf < SEND_BUFFER_SIZE) {
- tr_nerr ("UDP", "Failed to set send buffer: requested %d, got %d",
+ tr_logAddNamedError ("UDP", "Failed to set send buffer: requested %d, got %d",
SEND_BUFFER_SIZE, sbuf);
#ifdef __linux__
- tr_ninf ("UDP",
+ tr_logAddNamedInfo ("UDP",
"Please add the line "
"\"net.core.wmem_max = %d\" to /etc/sysctl.conf",
SEND_BUFFER_SIZE);
fail:
/* Something went wrong. It's difficult to recover, so let's simply
set things up so that we try again next time. */
- tr_nerr ("UDP", "Couldn't rebind IPv6 socket");
+ tr_logAddNamedError ("UDP", "Couldn't rebind IPv6 socket");
if (s >= 0)
close (s);
if (ss->udp6_bound) {
buf[0] == 0 && buf[1] == 0 && buf[2] == 0 && buf[3] <= 3) {
rc = tau_handle_message (ss, buf, rc);
if (!rc)
- tr_ndbg ("UDP", "Couldn't parse UDP tracker packet.");
+ tr_logAddNamedDbg ("UDP", "Couldn't parse UDP tracker packet.");
} else {
if (tr_sessionIsUTPEnabled (ss)) {
rc = tr_utpPacket (buf, rc, (struct sockaddr*)&from, fromlen, ss);
if (!rc)
- tr_ndbg ("UDP", "Unexpected UDP packet");
+ tr_logAddNamedDbg ("UDP", "Unexpected UDP packet");
}
}
}
ss->udp_socket = socket (PF_INET, SOCK_DGRAM, 0);
if (ss->udp_socket < 0) {
- tr_nerr ("UDP", "Couldn't create IPv4 socket");
+ tr_logAddNamedError ("UDP", "Couldn't create IPv4 socket");
goto ipv6;
}
sin.sin_port = htons (ss->udp_port);
rc = bind (ss->udp_socket, (struct sockaddr*)&sin, sizeof (sin));
if (rc < 0) {
- tr_nerr ("UDP", "Couldn't bind IPv4 socket");
+ tr_logAddNamedError ("UDP", "Couldn't bind IPv4 socket");
close (ss->udp_socket);
ss->udp_socket = -1;
goto ipv6;
event_new (ss->event_base, ss->udp_socket, EV_READ | EV_PERSIST,
event_callback, ss);
if (ss->udp_event == NULL)
- tr_nerr ("UDP", "Couldn't allocate IPv4 event");
+ tr_logAddNamedError ("UDP", "Couldn't allocate IPv4 event");
ipv6:
if (tr_globalIPv6 ())
event_new (ss->event_base, ss->udp6_socket, EV_READ | EV_PERSIST,
event_callback, ss);
if (ss->udp6_event == NULL)
- tr_nerr ("UDP", "Couldn't allocate IPv6 event");
+ tr_logAddNamedError ("UDP", "Couldn't allocate IPv6 event");
}
tr_udpSetSocketBuffers (ss);
#include <libutp/utp.h>
#include "transmission.h"
+#include "log.h"
#include "net.h"
#include "session.h"
#include "crypto.h" /* tr_cryptoWeakRandInt () */
#define dbgmsg(...) \
do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
} while (0)
#ifndef WITH_UTP
void
UTP_Close (struct UTPSocket * socket)
{
- tr_nerr (MY_NAME, "UTP_Close (%p) was called.", socket);
+ tr_logAddNamedError (MY_NAME, "UTP_Close (%p) was called.", socket);
dbgmsg ("UTP_Close (%p) was called.", socket);
assert (0); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
void
UTP_RBDrained (struct UTPSocket *socket)
{
- tr_nerr (MY_NAME, "UTP_RBDrained (%p) was called.", socket);
+ tr_logAddNamedError (MY_NAME, "UTP_RBDrained (%p) was called.", socket);
dbgmsg ("UTP_RBDrained (%p) was called.", socket);
assert (0); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
bool
UTP_Write (struct UTPSocket *socket, size_t count)
{
- tr_nerr (MY_NAME, "UTP_RBDrained (%p, %zu) was called.", socket, count);
+ tr_logAddNamedError (MY_NAME, "UTP_RBDrained (%p, %zu) was called.", socket, count);
dbgmsg ("UTP_RBDrained (%p, %zu) was called.", socket, count);
assert (0); /* FIXME: this is too much for the long term, but probably needed in the short term */
return false;
UTP_GetPeerName (s, from, &fromlen);
if (!tr_address_from_sockaddr_storage (&addr, &port, &from_storage))
{
- tr_nerr ("UTP", "Unknown socket family");
+ tr_logAddNamedError ("UTP", "Unknown socket family");
UTP_Close (s);
return;
}
typedef enum
{
- TR_MSG_ERR = 1,
- TR_MSG_INF = 2,
- TR_MSG_DBG = 3
+ TR_LOG_ERROR = 1,
+ TR_LOG_INFO = 2,
+ TR_LOG_DEBUG = 3,
+ TR_LOG_FIREHOSE = 4
}
-tr_msg_level;
+tr_log_level;
-void tr_setMessageLevel (tr_msg_level);
+void tr_logSetLevel (tr_log_level);
-typedef struct tr_msg_list
+typedef struct tr_log_message
{
- /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */
- tr_msg_level level;
+ /* TR_LOG_ERROR, TR_LOG_INFO, or TR_LOG_DEBUG */
+ tr_log_level level;
- /* The line number in the source file where this message originated */
- int line;
+ /* The line number in the source file where this message originated */
+ int line;
- /* Time the message was generated */
- time_t when;
+ /* Time the message was generated */
+ time_t when;
- /* The torrent associated with this message,
- * or a module name such as "Port Forwarding" for non-torrent messages,
- * or NULL. */
- char * name;
+ /* The torrent associated with this message,
+ * or a module name such as "Port Forwarding" for non-torrent messages,
+ * or NULL. */
+ char * name;
- /* The message */
- char * message;
+ /* The message */
+ char * message;
- /* The source file where this message originated */
- const char * file;
+ /* The source file where this message originated */
+ const char * file;
- /* linked list of messages */
- struct tr_msg_list * next;
+ /* linked list of messages */
+ struct tr_log_message * next;
}
-tr_msg_list;
+tr_log_message;
-void tr_setMessageQueuing (bool isEnabled);
-
-bool tr_getMessageQueuing (void);
-
-tr_msg_list * tr_getQueuedMessages (void);
-
-void tr_freeMessageList (tr_msg_list * freeme);
+tr_log_message * tr_logGetQueue (void);
+bool tr_logGetQueueEnabled (void);
+void tr_logSetQueueEnabled (bool isEnabled);
+void tr_logFreeQueue (tr_log_message * freeme);
/** @addtogroup Blocklists
@{ */
#include <event2/event.h>
#include "transmission.h"
+#include "log.h"
#include "net.h"
#include "session.h"
if ((s = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
- tr_dbg ("pgpipe failed to create socket: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to create socket: %ui", WSAGetLastError ());
return -1;
}
serv_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
if (bind (s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
{
- tr_dbg ("pgpipe failed to bind: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to bind: %ui", WSAGetLastError ());
closesocket (s);
return -1;
}
if (listen (s, 1) == SOCKET_ERROR)
{
- tr_ndbg ("event","pgpipe failed to listen: %ui", WSAGetLastError ());
+ tr_logAddNamedDbg ("event","pgpipe failed to listen: %ui", WSAGetLastError ());
closesocket (s);
return -1;
}
if (getsockname (s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR)
{
- tr_dbg ("pgpipe failed to getsockname: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to getsockname: %ui", WSAGetLastError ());
closesocket (s);
return -1;
}
if ((handles[1] = socket (PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
- tr_dbg ("pgpipe failed to create socket 2: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to create socket 2: %ui", WSAGetLastError ());
closesocket (s);
return -1;
}
if (connect (handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
{
- tr_dbg ("pgpipe failed to connect socket: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to connect socket: %ui", WSAGetLastError ());
closesocket (s);
return -1;
}
if ((handles[0] = accept (s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
{
- tr_dbg ("pgpipe failed to accept socket: %ui", WSAGetLastError ());
+ tr_logAddDebug ("pgpipe failed to accept socket: %ui", WSAGetLastError ());
closesocket (handles[1]);
handles[1] = INVALID_SOCKET;
closesocket (s);
#define dbgmsg(...) \
do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, "event", __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, "event", __VA_ARGS__); \
} while (0)
static void
logFunc (int severity, const char * message)
{
if (severity >= _EVENT_LOG_ERR)
- tr_err ("%s", message);
+ tr_logAddError ("%s", message);
else
- tr_dbg ("%s", message);
+ tr_logAddDebug ("%s", message);
}
static void
event_base_free (base);
eh->session->events = NULL;
tr_free (eh);
- tr_dbg ("Closing libevent thread");
+ tr_logAddDebug ("Closing libevent thread");
}
void
assert (tr_isSession (session));
session->events->die = true;
- tr_deepLog (__FILE__, __LINE__, NULL, "closing trevent pipe");
+ tr_logAddDeep (__FILE__, __LINE__, NULL, "closing trevent pipe");
tr_netCloseSocket (session->events->fds[1]);
}
#endif
#include "transmission.h"
+#include "log.h"
#include "port-forwarding.h"
#include "session.h"
#include "upnp.h"
#endif
if (ret != UPNPCOMMAND_SUCCESS)
- tr_ndbg (getKey (), "upnpDiscover failed (errno %d - %s)", err, tr_strerror (err));
+ tr_logAddNamedDbg (getKey (), "upnpDiscover failed (errno %d - %s)", err, tr_strerror (err));
return ret;
}
#endif
if (err)
- tr_ndbg (getKey (), "%s Port forwarding failed with error %d (errno %d - %s)", proto, err, errno, tr_strerror (errno));
+ tr_logAddNamedDbg (getKey (), "%s Port forwarding failed with error %d (errno %d - %s)", proto, err, errno, tr_strerror (errno));
errno = old_errno;
return err;
if (UPNP_GetValidIGD (devlist, &handle->urls, &handle->data,
handle->lanaddr, sizeof (handle->lanaddr)) == UPNP_IGD_VALID_CONNECTED)
{
- tr_ninf (getKey (), _(
+ tr_logAddNamedInfo (getKey (), _(
"Found Internet Gateway Device \"%s\""),
handle->urls.controlURL);
- tr_ninf (getKey (), _(
+ tr_logAddNamedInfo (getKey (), _(
"Local Address is \"%s\""), handle->lanaddr);
handle->state = TR_UPNP_IDLE;
handle->hasDiscovered = 1;
else
{
handle->state = TR_UPNP_ERR;
- tr_ndbg (
+ tr_logAddNamedDbg (
getKey (), "UPNP_GetValidIGD failed (errno %d - %s)",
errno,
tr_strerror (errno));
- tr_ndbg (
+ tr_logAddNamedDbg (
getKey (),
"If your router supports UPnP, please make sure UPnP is enabled!");
}
if ((tr_upnpGetSpecificPortMappingEntry (handle, "TCP") != UPNPCOMMAND_SUCCESS) ||
(tr_upnpGetSpecificPortMappingEntry (handle, "UDP") != UPNPCOMMAND_SUCCESS))
{
- tr_ninf (getKey (), _("Port %d isn't forwarded"), handle->port);
+ tr_logAddNamedInfo (getKey (), _("Port %d isn't forwarded"), handle->port);
handle->isMapped = false;
}
}
tr_upnpDeletePortMapping (handle, "TCP", handle->port);
tr_upnpDeletePortMapping (handle, "UDP", handle->port);
- tr_ninf (getKey (),
+ tr_logAddNamedInfo (getKey (),
_("Stopping port forwarding through \"%s\", service \"%s\""),
handle->urls.controlURL, handle->data.first.servicetype);
handle->isMapped = !err_tcp | !err_udp;
}
- tr_ninf (getKey (),
+ tr_logAddNamedInfo (getKey (),
_("Port forwarding through \"%s\", service \"%s\". (local address: %s:%d)"),
handle->urls.controlURL, handle->data.first.servicetype,
handle->lanaddr, port);
if (handle->isMapped)
{
- tr_ninf (getKey (), "%s", _("Port forwarding successful!"));
+ tr_logAddNamedInfo (getKey (), "%s", _("Port forwarding successful!"));
handle->port = port;
handle->state = TR_UPNP_IDLE;
}
else
{
- tr_ndbg (getKey (), "If your router supports UPnP, please make sure UPnP is enabled!");
+ tr_logAddNamedDbg (getKey (), "If your router supports UPnP, please make sure UPnP is enabled!");
handle->port = -1;
handle->state = TR_UPNP_ERR;
}
#include "fdlimit.h"
#include "ConvertUTF.h"
#include "list.h"
+#include "log.h"
#include "utils.h"
#include "platform.h" /* tr_lockLock (), TR_PATH_MAX */
#include "variant.h"
#include "version.h"
-time_t __tr_current_time = 0;
-tr_msg_level __tr_message_level = TR_MSG_ERR;
-
-static bool messageQueuing = false;
-static tr_msg_list * messageQueue = NULL;
-static tr_msg_list ** messageQueueTail = &messageQueue;
-static int messageQueueCount = 0;
-
-#ifndef WIN32
- /* make null versions of these win32 functions */
- static inline int IsDebuggerPresent (void) { return false; }
- static inline void OutputDebugString (const void * unused UNUSED) { }
-#endif
+time_t __tr_current_time = 0;
/***
****
***/
-static tr_lock*
-getMessageLock (void)
-{
- static tr_lock * l = NULL;
-
- if (!l)
- l = tr_lockNew ();
-
- return l;
-}
-
-void*
-tr_getLog (void)
-{
- static bool initialized = false;
- static FILE * file = NULL;
-
- if (!initialized)
- {
- int fd = 0;
- const char * str = getenv ("TR_DEBUG_FD");
-
- if (str && *str)
- fd = atoi (str);
-
- switch (fd)
- {
- case 1:
- file = stdout;
- break;
-
- case 2:
- file = stderr;
- break;
-
- default:
- file = NULL;
- break;
- }
-
- initialized = true;
- }
-
- return file;
-}
-
-void
-tr_setMessageLevel (tr_msg_level level)
-{
- __tr_message_level = level;
-}
-
-void
-tr_setMessageQueuing (bool enabled)
-{
- messageQueuing = enabled;
-}
-
-bool
-tr_getMessageQueuing (void)
-{
- return messageQueuing != 0;
-}
-
-tr_msg_list *
-tr_getQueuedMessages (void)
-{
- tr_msg_list * ret;
- tr_lockLock (getMessageLock ());
-
- ret = messageQueue;
- messageQueue = NULL;
- messageQueueTail = &messageQueue;
-
- messageQueueCount = 0;
-
- tr_lockUnlock (getMessageLock ());
- return ret;
-}
-
-void
-tr_freeMessageList (tr_msg_list * list)
-{
- tr_msg_list * next;
-
- while (NULL != list)
- {
- next = list->next;
- free (list->message);
- free (list->name);
- free (list);
- list = next;
- }
-}
-
-/**
-***
-**/
-
struct tm *
tr_localtime_r (const time_t *_clock, struct tm *_result)
{
#endif
}
-char*
-tr_getLogTimeStr (char * buf, int buflen)
-{
- char tmp[64];
- struct tm now_tm;
- struct timeval tv;
- time_t seconds;
- int milliseconds;
-
- gettimeofday (&tv, NULL);
-
- seconds = tv.tv_sec;
- tr_localtime_r (&seconds, &now_tm);
- strftime (tmp, sizeof (tmp), "%H:%M:%S", &now_tm);
- milliseconds = tv.tv_usec / 1000;
- tr_snprintf (buf, buflen, "%s.%03d", tmp, milliseconds);
-
- return buf;
-}
-
-bool
-tr_deepLoggingIsActive (void)
-{
- static int8_t deepLoggingIsActive = -1;
-
- if (deepLoggingIsActive < 0)
- deepLoggingIsActive = IsDebuggerPresent () || (tr_getLog ()!=NULL);
-
- return deepLoggingIsActive != 0;
-}
-
-void
-tr_deepLog (const char * file,
- int line,
- const char * name,
- const char * fmt,
- ...)
-{
- FILE * fp = tr_getLog ();
- if (fp || IsDebuggerPresent ())
- {
- va_list args;
- char timestr[64];
- char * message;
- struct evbuffer * buf = evbuffer_new ();
- char * base = tr_basename (file);
-
- evbuffer_add_printf (buf, "[%s] ",
- tr_getLogTimeStr (timestr, sizeof (timestr)));
- if (name)
- evbuffer_add_printf (buf, "%s ", name);
- va_start (args, fmt);
- evbuffer_add_vprintf (buf, fmt, args);
- va_end (args);
- evbuffer_add_printf (buf, " (%s:%d)\n", base, line);
- /* FIXME (libevent2) ifdef this out for nonwindows platforms */
- message = evbuffer_free_to_str (buf);
- OutputDebugString (message);
- if (fp)
- fputs (message, fp);
-
- tr_free (message);
- tr_free (base);
- }
-}
-
-/***
-****
-***/
-
-void
-tr_msg (const char * file, int line,
- tr_msg_level level,
- const char * name,
- const char * fmt, ...)
-{
- const int err = errno; /* message logging shouldn't affect errno */
- char buf[1024];
- va_list ap;
- tr_lockLock (getMessageLock ());
-
- /* build the text message */
- *buf = '\0';
- va_start (ap, fmt);
- evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
- va_end (ap);
-
- OutputDebugString (buf);
-
- if (*buf)
- {
- if (messageQueuing)
- {
- tr_msg_list * newmsg;
- newmsg = tr_new0 (tr_msg_list, 1);
- newmsg->level = level;
- newmsg->when = tr_time ();
- newmsg->message = tr_strdup (buf);
- newmsg->file = file;
- newmsg->line = line;
- newmsg->name = tr_strdup (name);
-
- *messageQueueTail = newmsg;
- messageQueueTail = &newmsg->next;
- ++messageQueueCount;
-
- if (messageQueueCount > TR_MAX_MSG_LOG)
- {
- tr_msg_list * old = messageQueue;
- messageQueue = old->next;
- old->next = NULL;
- tr_freeMessageList (old);
- --messageQueueCount;
- assert (messageQueueCount == TR_MAX_MSG_LOG);
- }
- }
- else
- {
- FILE * fp;
- char timestr[64];
-
- fp = tr_getLog ();
- if (fp == NULL)
- fp = stderr;
-
- tr_getLogTimeStr (timestr, sizeof (timestr));
-
- if (name)
- fprintf (fp, "[%s] %s: %s\n", timestr, name, buf);
- else
- fprintf (fp, "[%s] %s\n", timestr, buf);
- fflush (fp);
- }
- }
-
- tr_lockUnlock (getMessageLock ());
- errno = err;
-}
-
/***
****
***/
if (stat (path, &sb))
{
const int err = errno;
- tr_dbg (err_fmt, path, tr_strerror (errno));
+ tr_logAddDebug (err_fmt, path, tr_strerror (errno));
errno = err;
return NULL;
}
if ((sb.st_mode & S_IFMT) != S_IFREG)
{
- tr_err (err_fmt, path, _("Not a regular file"));
+ tr_logAddError (err_fmt, path, _("Not a regular file"));
errno = EISDIR;
return NULL;
}
if (fd < 0)
{
const int err = errno;
- tr_err (err_fmt, path, tr_strerror (errno));
+ tr_logAddError (err_fmt, path, tr_strerror (errno));
errno = err;
return NULL;
}
if (!buf)
{
const int err = errno;
- tr_err (err_fmt, path, _("Memory allocation failed"));
+ tr_logAddError (err_fmt, path, _("Memory allocation failed"));
tr_close_file (fd);
errno = err;
return NULL;
if (n == -1)
{
const int err = errno;
- tr_err (err_fmt, path, tr_strerror (errno));
+ tr_logAddError (err_fmt, path, tr_strerror (errno));
tr_close_file (fd);
free (buf);
errno = err;
if (tr_mkdir (path, permissions))
{
tmperr = errno;
- tr_err (_("Couldn't create \"%1$s\": %2$s"), path, tr_strerror (tmperr));
+ tr_logAddError (_("Couldn't create \"%1$s\": %2$s"), path, tr_strerror (tmperr));
tr_free (path);
errno = tmperr;
return -1;
{
/* Node exists but isn't a folder */
char * buf = tr_strdup_printf (_("File \"%s\" is in the way"), path);
- tr_err (_("Couldn't create \"%1$s\": %2$s"), path_in, buf);
+ tr_logAddError (_("Couldn't create \"%1$s\": %2$s"), path_in, buf);
tr_free (buf);
tr_free (path);
errno = ENOTDIR;
*****
****/
-#define TR_MAX_MSG_LOG 10000
-
-extern tr_msg_level __tr_message_level;
-
-static inline tr_msg_level tr_getMessageLevel (void)
-{
- return __tr_message_level;
-}
-
-static inline bool tr_msgLoggingIsActive (tr_msg_level level)
-{
- return tr_getMessageLevel () >= level;
-}
-
-void tr_msg (const char * file, int line,
- tr_msg_level level,
- const char * torrent,
- const char * fmt, ...) TR_GNUC_PRINTF (5, 6);
-
-#define tr_nerr(n, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_ERR)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__); \
- } while (0)
-
-#define tr_ninf(n, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_INF)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__); \
- } while (0)
-
-#define tr_ndbg(n, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_DBG)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__); \
- } while (0)
-
-#define tr_torerr(tor, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_ERR)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_ERR, tr_torrentName (tor), __VA_ARGS__); \
- } while (0)
-
-#define tr_torinf(tor, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_INF)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_INF, tr_torrentName (tor), __VA_ARGS__); \
- } while (0)
-
-#define tr_tordbg(tor, ...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_DBG)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_DBG, tr_torrentName (tor), __VA_ARGS__); \
- } while (0)
-
-#define tr_err(...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_ERR)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__); \
- } while (0)
-
-#define tr_inf(...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_INF)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__); \
- } while (0)
-
-#define tr_dbg(...) \
- do { \
- if (tr_msgLoggingIsActive (TR_MSG_DBG)) \
- tr_msg (__FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__); \
- } while (0)
-
-
-
-void* tr_getLog (void);
-
-/** @brief return true if deep logging has been enabled by the user; false otherwise */
-bool tr_deepLoggingIsActive (void);
-
-void tr_deepLog (const char * file,
- int line,
- const char * name,
- const char * fmt,
- ...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4);
-
-/** @brief set the buffer with the current time formatted for deep logging. */
-char* tr_getLogTimeStr (char * buf, int buflen) TR_GNUC_NONNULL (1);
-
-
/**
* @brief Rich Salz's classic implementation of shell-style pattern matching for ?, \, [], and * characters.
* @return 1 if the pattern matches, 0 if it doesn't, or -1 if an error occured
#include "transmission.h"
#include "ConvertUTF.h"
#include "list.h"
+#include "log.h"
#include "ptrarray.h"
#include "utils.h"
#include "variant.h"
if (data->source)
{
- tr_err ("JSON parse failed in %s at pos %zu: %s -- remaining text \"%.16s\"",
+ tr_logAddError ("JSON parse failed in %s at pos %zu: %s -- remaining text \"%.16s\"",
data->source,
jsn->pos,
jsonsl_strerror (error),
}
else
{
- tr_err ("JSON parse failed at pos %zu: %s -- remaining text \"%.16s\"",
+ tr_logAddError ("JSON parse failed at pos %zu: %s -- remaining text \"%.16s\"",
jsn->pos,
jsonsl_strerror (error),
buf);
#include "transmission.h"
#include "ConvertUTF.h"
#include "fdlimit.h" /* tr_close_file() */
+#include "log.h"
#include "platform.h" /* TR_PATH_MAX */
#include "utils.h" /* tr_new(), tr_free() */
#include "variant.h"
default:
/* did caller give us an uninitialized val? */
- tr_err ("%s", _("Invalid metadata"));
+ tr_logAddError ("%s", _("Invalid metadata"));
break;
}
}
}
else
{
- tr_err ("tr_variantListCopy skipping item");
+ tr_logAddError ("tr_variantListCopy skipping item");
}
}
}
}
else
{
- tr_dbg ("tr_variantMergeDicts skipping \"%s\"", tr_quark_get_string(key,NULL));
+ tr_logAddDebug ("tr_variantMergeDicts skipping \"%s\"", tr_quark_get_string(key,NULL));
}
}
}
if (nleft > 0)
{
- tr_err (_("Couldn't save temporary file \"%1$s\": %2$s"), tmp, tr_strerror (err));
+ tr_logAddError (_("Couldn't save temporary file \"%1$s\": %2$s"), tmp, tr_strerror (err));
tr_close_file (fd);
unlink (tmp);
}
if (!rename (tmp, filename))
#endif
{
- tr_inf (_("Saved \"%s\""), filename);
+ tr_logAddInfo (_("Saved \"%s\""), filename);
}
else
{
err = errno;
- tr_err (_("Couldn't save file \"%1$s\": %2$s"), filename, tr_strerror (err));
+ tr_logAddError (_("Couldn't save file \"%1$s\": %2$s"), filename, tr_strerror (err));
unlink (tmp);
}
}
else
{
err = errno;
- tr_err (_("Couldn't save temporary file \"%1$s\": %2$s"), tmp, tr_strerror (err));
+ tr_logAddError (_("Couldn't save temporary file \"%1$s\": %2$s"), tmp, tr_strerror (err));
}
tr_free (tmp);
#include "completion.h"
#include "fdlimit.h"
#include "list.h"
+#include "log.h"
#include "platform.h" /* tr_lock () */
#include "torrent.h"
#include "utils.h" /* tr_valloc (), tr_free () */
SHA1_Init (&sha);
- tr_tordbg (tor, "%s", "verifying torrent...");
+ tr_logAddTorDbg (tor, "%s", "verifying torrent...");
tr_torrentSetChecked (tor, 0);
while (!*stopFlag && (pieceIndex < tor->info.pieceCount))
{
/* stopwatch */
end = tr_time ();
- tr_tordbg (tor, "Verification is done. It took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)",
+ tr_logAddTorDbg (tor, "Verification is done. It took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)",
(int)(end-begin), tor->info.totalSize,
(uint64_t)(tor->info.totalSize/ (1+ (end-begin))));
tr_free (node);
tr_lockUnlock (getVerifyLock ());
- tr_torinf (tor, "%s", _("Verifying torrent"));
+ tr_logAddTorInfo (tor, "%s", _("Verifying torrent"));
tr_torrentSetVerifyState (tor, TR_VERIFY_NOW);
changed = verifyTorrent (tor, &stopCurrent);
tr_torrentSetVerifyState (tor, TR_VERIFY_NONE);
struct verify_node * node;
assert (tr_isTorrent (tor));
- tr_torinf (tor, "%s", _("Queued for verification"));
+ tr_logAddTorInfo (tor, "%s", _("Queued for verification"));
node = tr_new (struct verify_node, 1);
node->torrent = tor;
#include <event2/buffer.h>
#include "transmission.h"
+#include "log.h"
#include "net.h" /* tr_address */
#include "platform.h" /* mutex */
#include "session.h"
#else
#define dbgmsg(...) \
do { \
- if (tr_deepLoggingIsActive ()) \
- tr_deepLog (__FILE__, __LINE__, "web", __VA_ARGS__); \
+ if (tr_logGetDeepEnabled ()) \
+ tr_logAddDeep (__FILE__, __LINE__, "web", __VA_ARGS__); \
} while (0)
#endif
web->curl_ca_bundle = getenv ("CURL_CA_BUNDLE");
if (web->curl_ssl_verify)
{
- tr_ninf ("web", "will verify tracker certs using envvar CURL_CA_BUNDLE: %s",
+ tr_logAddNamedInfo ("web", "will verify tracker certs using envvar CURL_CA_BUNDLE: %s",
web->curl_ca_bundle == NULL ? "none" : web->curl_ca_bundle);
- tr_ninf ("web", "NB: this only works if you built against libcurl with openssl or gnutls, NOT nss");
- tr_ninf ("web", "NB: invalid certs will show up as 'Could not connect to tracker' like many other errors");
+ tr_logAddNamedInfo ("web", "NB: this only works if you built against libcurl with openssl or gnutls, NOT nss");
+ tr_logAddNamedInfo ("web", "NB: invalid certs will show up as 'Could not connect to tracker' like many other errors");
}
web->cookie_filename = tr_buildPath (session->configDir, "cookies.txt", NULL);
- (void) updateLog: (NSTimer *) timer
{
- tr_msg_list * messages;
- if ((messages = tr_getQueuedMessages()) == NULL)
+ tr_log_message * messages;
+ if ((messages = tr_logGetQueue()) == NULL)
return;
[fLock lock];
BOOL changed = NO;
- for (tr_msg_list * currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next)
+ for (tr_log_message * currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next)
{
NSString * name = currentMessage->name != NULL ? [NSString stringWithUTF8String: currentMessage->name]
: [[NSProcessInfo processInfo] processName];
}
}
- if ([fMessages count] > TR_MAX_MSG_LOG)
+ if ([fMessages count] > TR_LOG_MAX_QUEUE_LENGTH)
{
const NSUInteger oldCount = [fDisplayedMessages count];
- NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMessages count]-TR_MAX_MSG_LOG)];
+ NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMessages count]-TR_LOG_MAX_QUEUE_LENGTH)];
NSArray * itemsToRemove = [fMessages objectsAtIndexes: removeIndexes];
[fMessages removeObjectsAtIndexes: removeIndexes];
[fLock unlock];
- tr_freeMessageList(messages);
+ tr_logFreeQueue (messages);
}
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
if( !single || myFilesDirty )
myFileTreeView->clear( );
if( single )
- myFileTreeView->update( torrents[0]->files( ) , myChangedTorrents );
- myFilesDirty = false;
+ myFileTreeView->update( torrents[0]->files( ) , myFilesDirty || myChangedTorrents );
+ myFilesDirty = false;
myChangedTorrents = false;
myHavePendingRefresh = false;
foreach( QWidget * w, myWidgets )
int priority,
uint64_t totalSize,
uint64_t haveSize,
- bool torrentChanged)
+ bool updateFields)
{
bool changed = false;
+std::cerr << __FILE__ << ':' << __LINE__ << " index " << index << " wanted " << wanted << " myIndex " << myIndex << " myWanted" << myIsWanted << std::endl;
+
if (myIndex != index)
{
myIndex = index;
changed = true;
}
- if (torrentChanged && myIsWanted != wanted)
+ if (updateFields && myIsWanted != wanted)
{
myIsWanted = wanted;
changed = true;
+std::cerr << __FILE__ << ':' << __LINE__ << " setting myIsWanted to " << myIsWanted << std::endl;
}
- if (torrentChanged && myPriority != priority)
+ if (updateFields && myPriority != priority)
{
myPriority = priority;
changed = true;
p = TR_PRI_HIGH;
else
p = TR_PRI_LOW;
+std::cerr << __FILE__ << ':' << __LINE__ << " twiddlePriority, p " << p << std::endl;
setSubtreePriority (p, ids);
}
void
FileTreeItem :: setSubtreeWanted (bool b, QSet<int>& ids)
{
- if(myIsWanted != b)
+std::cerr << __FILE__ << ':' << __LINE__ << " twiddleWanted, wanted " << b << std::endl;
+ if (myIsWanted != b)
{
myIsWanted = b;
void
FileTreeItem :: twiddleWanted (QSet<int>& ids, bool& wanted)
{
+std::cerr << __FILE__ << ':' << __LINE__ << " twiddleWanted" << std::endl;
wanted = isSubtreeWanted() != Qt::Checked;
setSubtreeWanted (wanted, ids);
}
FileTreeModel :: ~FileTreeModel()
{
+std::cerr << __FILE__ << ':' << __LINE__ << " dtor " << std::endl;
clear();
delete rootItem;
FileTreeModel :: clearSubtree (const QModelIndex& top)
{
size_t i = rowCount (top);
+std::cerr << __FILE__ << ':' << __LINE__ << " clearSubtree " << i << std::endl;
while (i > 0)
clearSubtree(index(--i, 0, top));
- delete static_cast<FileTreeItem*>(top.internalPointer());
+ delete static_cast<FileTreeItem*>(top.internalPointer());
}
void
FileTreeModel :: clear ()
{
+std::cerr << __FILE__ << ':' << __LINE__ << " clear" << std::endl;
clearSubtree (QModelIndex());
reset ();
uint64_t size,
uint64_t have,
QList<QModelIndex> & rowsAdded,
- bool torrentChanged)
+ bool updateFields)
{
+ bool added = false;
FileTreeItem * i (rootItem);
foreach (QString token, filename.split (QChar::fromAscii('/')))
FileTreeItem * child(i->child(token));
if (!child)
{
+ added = true;
QModelIndex parentIndex (indexOf(i, 0));
const int n (i->childCount());
beginInsertRows (parentIndex, n, n);
}
if (i != rootItem)
- if (i->update (index, wanted, priority, size, have, torrentChanged))
- dataChanged (indexOf(i, 0), indexOf(i, NUM_COLUMNS-1));
+ {
+ if (i->update (index, wanted, priority, size, have, added || updateFields))
+ {
+ std::cerr << __FILE__ << ':' << __LINE__ << " emitting dataChanged for row " << i << std::endl;
+ dataChanged (indexOf(i, 0), indexOf(i, NUM_COLUMNS-1));
+ }
+ }
}
void
QSet<int> file_ids;
FileTreeItem * item;
+std::cerr << "clicked in COL_PRIORITY" << std::endl;
item = static_cast<FileTreeItem*>(index.internalPointer());
item->twiddlePriority (file_ids, priority);
emit priorityChanged (file_ids, priority);
void
FileTreeView :: onClicked (const QModelIndex& proxyIndex)
{
- const QModelIndex modelIndex = myProxy->mapToSource(proxyIndex);
- myModel.clicked(modelIndex);
+ const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
+std::cerr << __FILE__ << ':' << __LINE__ << " calling myModel.clicked()" << std::endl;
+ myModel.clicked (modelIndex);
}
bool
return false;
}
+#if 0
// handle using the keyboard to toggle the
// wanted/unwanted state or the file priority
- else if(event->type() == QEvent::KeyPress)
+ else if (event->type() == QEvent::KeyPress)
{
+std::cerr << __FILE__ << ':' << __LINE__ << " " << qPrintable(dynamic_cast<QKeyEvent*>(event)->text()) << std::endl;
switch(dynamic_cast<QKeyEvent*>(event)->key())
{
case Qt::Key_Space:
+ std::cerr << __FILE__ << ':' << __LINE__ << " calling COL_WANTED.clicked()" << std::endl;
foreach (QModelIndex i, selectionModel()->selectedRows(COL_WANTED))
clicked (i);
return false;
case Qt::Key_Enter:
case Qt::Key_Return:
+ std::cerr << __FILE__ << ':' << __LINE__ << " calling COL_PRIORITY.clicked()" << std::endl;
foreach (QModelIndex i, selectionModel()->selectedRows(COL_PRIORITY))
clicked (i);
return false;
}
}
+#endif
return false;
}
}
void
-FileTreeView :: update (const FileList& files, bool torrentChanged)
+FileTreeView :: update (const FileList& files, bool updateFields)
{
+std::cerr << "update updateFields " << updateFields << std::endl;
foreach (const TrFile file, files)
{
QList<QModelIndex> added;
- myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, torrentChanged);
+std::cerr << __FILE__ << ':' << __LINE__ << " add file " << qPrintable(file.filename) << " wanted " << file.wanted << std::endl;
+ myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields);
foreach (QModelIndex i, added)
expand (myProxy->mapFromSource(i));
}
void
FileTreeView :: clear ()
{
+std::cerr << __FILE__ << ':' << __LINE__ << " clear" << std::endl;
myModel.clear();
}
int row () const;
const QString& name () const { return myName; }
QVariant data (int column, int role) const;
- bool update (int index, bool want, int priority, uint64_t total, uint64_t have, bool torrentChanged);
+ bool update (int index, bool want, int priority, uint64_t total, uint64_t have, bool updateFields);
void twiddleWanted (QSet<int>& fileIds, bool&);
void twiddlePriority (QSet<int>& fileIds, int&);
char * out2 = NULL;
tr_metainfo_builder * b = NULL;
- tr_setMessageLevel (TR_MSG_ERR);
+ tr_logSetLevel (TR_LOG_ERROR);
if (parseCommandLine (argc, (const char**)argv))
return EXIT_FAILURE;
files = tr_new0 (const char*, argc);
- tr_setMessageLevel (TR_MSG_ERR);
+ tr_logSetLevel (TR_LOG_ERROR);
if (parseCommandLine (argc, (const char**)argv))
return EXIT_FAILURE;
tr_info inf;
tr_ctor * ctor;
- tr_setMessageLevel (TR_MSG_ERR);
+ tr_logSetLevel (TR_LOG_ERROR);
tr_formatter_mem_init (MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
tr_formatter_size_init (DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
tr_formatter_speed_init (SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);