static char * create_test_dir (const char * name) { char * const test_dir = tr_buildPath (tr_sessionGetConfigDir (session), name, NULL); tr_sys_dir_create (test_dir, 0, 0777, NULL); return test_dir; }
void libttest_session_close (tr_session * session) { char * sandbox; sandbox = tr_strdup (tr_sessionGetConfigDir (session)); tr_sessionClose (session); tr_logFreeQueue (tr_logGetQueue ()); session = NULL; libtest_sandbox_destroy (sandbox); tr_free (sandbox); }
static void gotsig (int sig) { switch (sig) { case SIGHUP: { if (!mySession) { tr_logAddInfo ("Deferring reload until session is fully started."); seenHUP = true; } else { tr_variant settings; const char * configDir; /* reopen the logfile to allow for log rotation */ if (logfileName) { logfile = freopen (logfileName, LOGFILE_MODE_STR, logfile); if (!logfile) fprintf (stderr, "Couldn't reopen \"%s\": %s\n", logfileName, tr_strerror (errno)); } configDir = tr_sessionGetConfigDir (mySession); 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); tr_sessionSet (mySession, &settings); tr_variantFree (&settings); tr_sessionReloadBlocklists (mySession); } break; } default: tr_logAddError ("Unexpected signal (%d) in daemon, closing.", sig); /* no break */ case SIGINT: case SIGTERM: event_base_loopexit(ev_base, NULL); break; } }
static int test_parsing (void) { char * path; tr_session * session; /* init the session */ session = libttest_session_init (NULL); check (!tr_blocklistExists (session)); check_int_eq (0, tr_blocklistGetRuleCount (session)); /* init the blocklist */ path = tr_buildPath (tr_sessionGetConfigDir(session), "blocklists", "level1", NULL); create_text_file (path, contents1); tr_free (path); tr_sessionReloadBlocklists (session); check (tr_blocklistExists (session)); check_int_eq (4, tr_blocklistGetRuleCount (session)); /* enable the blocklist */ check (!tr_blocklistIsEnabled (session)); tr_blocklistSetEnabled (session, true); check (tr_blocklistIsEnabled (session)); /* test blocked addresses */ check (!address_is_blocked (session, "216.16.1.143")); check ( address_is_blocked (session, "216.16.1.144")); check ( address_is_blocked (session, "216.16.1.145")); check ( address_is_blocked (session, "216.16.1.146")); check ( address_is_blocked (session, "216.16.1.147")); check ( address_is_blocked (session, "216.16.1.148")); check ( address_is_blocked (session, "216.16.1.149")); check ( address_is_blocked (session, "216.16.1.150")); check ( address_is_blocked (session, "216.16.1.151")); check (!address_is_blocked (session, "216.16.1.152")); check (!address_is_blocked (session, "216.16.1.153")); check (!address_is_blocked (session, "217.0.0.1")); check (!address_is_blocked (session, "255.0.0.1")); /* cleanup */ libttest_session_close (session); return 0; }
static int test_updating (void) { char * path; tr_session * session; /* init the session */ session = libttest_session_init (NULL); path = tr_buildPath (tr_sessionGetConfigDir(session), "blocklists", "level1", NULL); /* no blocklist to start with... */ check_int_eq (0, tr_blocklistGetRuleCount (session)); /* test that updated source files will get loaded */ create_text_file (path, contents1); tr_sessionReloadBlocklists (session); check_int_eq (4, tr_blocklistGetRuleCount (session)); /* test that updated source files will get loaded */ create_text_file (path, contents2); tr_sessionReloadBlocklists (session); check_int_eq (5, tr_blocklistGetRuleCount (session)); /* test that updated source files will get loaded */ create_text_file (path, contents1); tr_sessionReloadBlocklists (session); check_int_eq (4, tr_blocklistGetRuleCount (session)); /* ensure that new files, if bad, get skipped */ create_text_file (path, "# nothing useful\n"); tr_sessionReloadBlocklists (session); check_int_eq (4, tr_blocklistGetRuleCount (session)); /* cleanup */ libttest_session_close (session); tr_free (path); return 0; }
static void gotsig( int sig ) { switch( sig ) { case SIGHUP: { tr_benc settings; const char * configDir = tr_sessionGetConfigDir( mySession ); tr_inf( "Reloading settings from \"%s\"", configDir ); tr_bencInitDict( &settings, 0 ); tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, TRUE ); tr_sessionLoadSettings( &settings, configDir, MY_NAME ); tr_sessionSet( mySession, &settings ); tr_bencFree( &settings ); tr_sessionReloadBlocklists( mySession ); break; } default: closing = TRUE; break; } }
static char* getFilename (const tr_session * session) { return tr_buildPath (tr_sessionGetConfigDir (session), "stats.json", NULL); }
static char* getOldFilename(tr_session const* session) { return tr_buildPath(tr_sessionGetConfigDir(session), "stats.benc", NULL); }