Пример #1
0
void maintainr_config_handle_backup ()
{
	gchar *path;

	path = conf_file_path ();
	if (access (path, F_OK) == 0)
		g_thread_new (NULL, manage_backups, path);
}
Пример #2
0
void maintainr_config_save (MaintainrConfig *conf)
{
	gchar *path;
	gchar *data;
	FILE *file;
	GList *iter;

	path = conf_file_path ();

	if (access (path, F_OK) != 0) {
		data = g_dirname (path);
		g_mkdir_with_parents (data, 0744);
		g_free (data);
	}

	file = fopen (path, "w");
	if (file != NULL) {
		fprintf (file, "<maintainr>\n\n");

		fprintf (file, "<application>\n");
		fprintf (file, "<windowx>%d</windowx>\n", conf->priv->window_x);
		fprintf (file, "<windowy>%d</windowy>\n", conf->priv->window_y);
		fprintf (file, "<windowwidth>%d</windowwidth>\n", conf->priv->window_width);
		fprintf (file, "<windowheight>%d</windowheight>\n", conf->priv->window_height);
		fprintf (file, "</application>\n");

		for (iter = conf->priv->projects; iter; iter = iter->next) {
			data = maintainr_projectconf_write (iter->data);
			fprintf (file, "%s\n", data);
			g_free (data);
		}

		fprintf (file, "\n</maintainr>\n");
		fclose (file);
	}
	else {
		g_warning ("Unable to save configuration on file %s: %s", path, strerror (errno));
	}

	g_free (path);
}
Пример #3
0
MaintainrConfig* maintainr_config_read_configuration ()
{
	gchar *path;
	xmlDocPtr doc;
	xmlNode *root;
	xmlNode *node;
	MaintainrConfig *ret;
	MaintainrProjectconf *proj;

	ret = g_object_new (MAINTAINR_CONFIG_TYPE, NULL);
	path = conf_file_path ();

	if (access (path, F_OK) == 0) {
		doc = xmlReadFile (path, NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOENT);
		g_free (path);

		root = xmlDocGetRootElement (doc);

		if (strcmp ((gchar*) root->name, "maintainr") == 0) {
			for (node = root->children; node; node = node->next) {
				if (strcmp ((gchar*) node->name, "project") == 0) {
					proj = maintainr_projectconf_new ();
					maintainr_projectconf_read (proj, node->children);
					ret->priv->projects = g_list_prepend (ret->priv->projects, proj);
				}
				else if (strcmp ((gchar*) node->name, "application") == 0) {
					read_application_configuration (ret, node->children);
				}
			}
		}

		xmlFreeDoc (doc);
		maintainr_config_sort_projects (ret);
	}

	return ret;
}
Пример #4
0
int main(int argc, char **argv) {
	// we don't use printf so make cout/cerr a little bit faster
	std::ios_base::sync_with_stdio(false);

	conf = new config();

	bool verbose = false, conf_arg = false;
	std::string conf_file_path("./ocelot.conf");
	for (int i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-v")) {
			verbose = true;
		} else if (!strcmp(argv[i], "-c") && i < argc - 1) {
			conf_arg = true;
			conf_file_path = argv[++i];
		} else {
			std::cout << "Usage: " << argv[0] << " [-v] [-c configfile]" << std::endl;
			return 0;
		}
	}

	std::ifstream conf_file(conf_file_path);
	if (conf_file.fail()) {
		std::cout << "Using default config because '" << conf_file_path << "' couldn't be opened" << std::endl;
		if (!conf_arg) {
			std::cout << "Start Ocelot with -c <path> to specify config file if necessary" << std::endl;
		}
	} else {
		conf->load(conf_file_path, conf_file);
	}

	db = new mysql(conf);

	if (!db->connected()) {
		std::cout << "Exiting" << std::endl;
		return 0;
	}
	db->verbose_flush = verbose;

	sc = new site_comm(conf);
	sc->verbose_flush = verbose;

	user_list users_list;
	torrent_list torrents_list;
	std::vector<std::string> whitelist;
	db->load_users(users_list);
	db->load_torrents(torrents_list);
	//db->load_whitelist(whitelist);

	stats.open_connections = 0;
	stats.opened_connections = 0;
	stats.connection_rate = 0;
	stats.requests = 0;
	stats.request_rate = 0;
	stats.leechers = 0;
	stats.seeders = 0;
	stats.announcements = 0;
	stats.succ_announcements = 0;
	stats.scrapes = 0;
	stats.bytes_read = 0;
	stats.bytes_written = 0;
	stats.start_time = time(NULL);

	// Create worker object, which handles announces and scrapes and all that jazz
	work = new worker(conf, torrents_list, users_list, whitelist, db, sc);

	// Create schedule object
	sched = new schedule(conf, work, db, sc);

	// Create connection mother, which binds to its socket and handles the event stuff
	mother = new connection_mother(conf, work, db, sc, sched);

	// Add signal handlers now that all objects have been created
	struct sigaction handler, ignore;
	ignore.sa_handler = SIG_IGN;
	handler.sa_handler = sig_handler;
	sigemptyset(&handler.sa_mask);
	handler.sa_flags = 0;

	sigaction(SIGINT, &handler, NULL);
	sigaction(SIGTERM, &handler, NULL);
	sigaction(SIGHUP, &handler, NULL);
	sigaction(SIGUSR1, &handler, NULL);
	sigaction(SIGUSR2, &ignore, NULL);

	mother->run();

	return 0;
}