Exemple #1
0
xmlnode * _h_elim_init ( const char *name ,
                         const char *id   ,
                         SEXP_VALUE *args ,
                         gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    char    *dir = ALIST_VAL_STRING( args, "dot-dir" );
    char    *ui  = ALIST_VAL_STRING( args, "ui-id"   );
    gboolean dbg = ALIST_VAL_BOOL  ( args, "debug"   );

    if( !ui ) { ui = "elim"; }

    // libpurple initialisation:
    purple_util_set_user_dir       ( dir  );
    purple_util_init               ();
    purple_core_set_ui_ops         ( &elim_core_ui_ops         );
    purple_eventloop_set_ui_ops    ( &elim_eventloop_ui_ops    );
    purple_blist_set_ui_ops        ( &elim_blist_ui_ops        );
    purple_accounts_set_ui_ops     ( &elim_account_ui_ops      );
    purple_request_set_ui_ops      ( &elim_request_ui_ops      );
    purple_idle_set_ui_ops         ( &elim_idle_ui_ops         );
    purple_connections_set_ui_ops  ( &elim_connections_ui_ops  );
    purple_conversations_set_ui_ops( &elim_conversation_ui_ops );
    purple_notify_set_ui_ops       ( &elim_notify_ui_ops       );

    // load any data for init:    
    if( purple_get_core() == NULL )
    {
        // purple debug goes to stdout if we don't divert it here:
        g_set_print_handler( (GPrintFunc)_h_elim_warning );
        // look for plugins in user specified directory tree:
        char *ppath = g_build_filename( purple_user_dir(), "plugins", NULL );
        purple_plugins_add_search_path ( ppath );
        purple_debug_set_enabled( dbg );
        purple_core_init ( ui );
        purple_set_blist ( purple_blist_new() );
        purple_prefs_load();
        purple_blist_load();
        // glib signal initialisation:
        elim_ft_signals_init();
        // tidy up:
        g_free( ppath );
    }
    else
    {
        const char *cur_ui = purple_core_get_ui();
        if( strcmp( cur_ui, name ) )
        {
            sexp_val_free( args );
            return response_error( EINVAL, id, name, 
                                   "purple has already been initialised" );
        }
    }

    sexp_val_free( args );
    xmlnode *rval = xnode_new( "alist" );
    AL_STR( rval, "ui-id", purple_core_get_ui() );
    return response_value( 0, id, name, rval );
}
void
_pidgin_smiley_theme_init(void)
{
	GList *it;
	const gchar *user_smileys_dir;
	const gchar *theme_name;

	probe_dirs = g_new0(gchar*, 3);
	probe_dirs[0] = g_build_filename(
		PURPLE_DATADIR, "pixmaps", "pidgin", "emotes", NULL);
	user_smileys_dir = probe_dirs[1] = g_build_filename(
		purple_user_dir(), "smileys", NULL);

	if (!g_file_test(user_smileys_dir, G_FILE_TEST_IS_DIR)) {
		if (g_mkdir(user_smileys_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
			purple_debug_error("gtksmiley-theme",
				"Failed to create user smileys dir");
		}
	}

	/* setting theme by name (copy-paste from gtkprefs) */
	pidgin_smiley_theme_probe();
	theme_name = purple_prefs_get_string(
		PIDGIN_PREFS_ROOT "/smileys/theme");
	for (it = smiley_themes; it; it = g_list_next(it)) {
		PidginSmileyTheme *theme = it->data;

		if (g_strcmp0(pidgin_smiley_theme_get_name(theme), theme_name))
			continue;

		purple_smiley_theme_set_current(PURPLE_SMILEY_THEME(theme));
	}
}
Exemple #3
0
gboolean
purple_core_ensure_single_instance()
{
    gboolean is_single_instance = TRUE;
#ifdef HAVE_DBUS
    /* in the future, other mechanisms might have already set this to FALSE */
    if (is_single_instance)
    {
        if (!purple_dbus_is_owner())
        {
            const char *user_dir = purple_user_dir();
            char *dbus_owner_user_dir = purple_dbus_owner_user_dir();

            if (NULL == user_dir && NULL != dbus_owner_user_dir)
                is_single_instance = TRUE;
            else if (NULL != user_dir && NULL == dbus_owner_user_dir)
                is_single_instance = TRUE;
            else if (NULL == user_dir && NULL == dbus_owner_user_dir)
                is_single_instance = FALSE;
            else
                is_single_instance = strcmp(dbus_owner_user_dir, user_dir);

            g_free(dbus_owner_user_dir);
        }
    }
#endif /* HAVE_DBUS */

    return is_single_instance;
}
static gboolean plugin_load(PurplePlugin * plugin) {
    asprintf(&hook_script, "%s/%s", purple_user_dir(), AUTORESPOND);
    void *conv_handle = purple_conversations_get_handle();
    purple_signal_connect(conv_handle, "received-im-msg", plugin, 
        PURPLE_CALLBACK(received_im_msg_cb), NULL);
    return TRUE;
}
/* Makes a filename path for a certificate. If id is NULL,
 * just return the directory
 */
static gchar *
make_certificate_path(const gchar *id)
{
	return g_build_filename(purple_user_dir(),
				"certificates", "tls",
				id != NULL ? purple_escape_filename(id) : NULL,
				NULL);
}
static void
init_plugin (PurplePlugin * plugin)
{
   gchar *dir = g_build_filename(purple_user_dir(), "autostatus.config", NULL);

	purple_prefs_add_none(PREF_NONE);
	purple_prefs_add_string(PREF_CONFIG, dir);
}
Exemple #7
0
static void destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) {
	PidginLogViewer *lv = syslog_viewer;

#ifdef _WIN32
	if (resp == GTK_RESPONSE_HELP) {
		GtkTreeSelection *sel;
		GtkTreeIter iter;
		GtkTreeModel *model;
		PurpleLog *log = NULL;
		char *logdir;

		if (ht != NULL)
			lv = g_hash_table_lookup(log_viewers, ht);
		model = GTK_TREE_MODEL(lv->treestore);

		sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(lv->treeview));
		if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
			GValue val;

			val.g_type = 0;
			gtk_tree_model_get_value (model, &iter, 1, &val);
			log = g_value_get_pointer(&val);
			g_value_unset(&val);
		}


		if (log == NULL)
			logdir = g_build_filename(purple_user_dir(), "logs", NULL);
		else
			logdir = purple_log_get_log_dir(log->type, log->name, log->account);

		winpidgin_shell_execute(logdir, "explore", NULL);
		g_free(logdir);
		return;
	}
#endif

	if (ht != NULL) {
		lv = g_hash_table_lookup(log_viewers, ht);
		g_hash_table_remove(log_viewers, ht);

		g_free(ht->screenname);
		g_free(ht);
	} else
		syslog_viewer = NULL;

	purple_request_close_with_handle(lv);

	g_list_foreach(lv->logs, (GFunc)purple_log_free, NULL);
	g_list_free(lv->logs);

	g_free(lv->search);
	g_free(lv);

	gtk_widget_destroy(w);
}
Exemple #8
0
void
purple_smileys_init(void)
{
	smiley_shortcut_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	smiley_checksum_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);

	smileys_dir = g_build_filename(purple_user_dir(), SMILEYS_DEFAULT_FOLDER, NULL);

	purple_smileys_load();
}
Exemple #9
0
gboolean gfire_game_load_config_xml(gboolean p_force)
{
	if(!p_force && gfire_games_config)
		return TRUE;

	xmlnode *node = NULL;

	gchar *filename = g_build_filename(purple_user_dir(), "gfire_game_config.xml", NULL);
	if(filename)
	{
		purple_debug(PURPLE_DEBUG_INFO, "gfire", "Loading Game Launch Data from: %s\n", filename);
		g_free(filename);
	}

	node = purple_util_read_xml_from_file("gfire_game_config.xml", "Gfire Game Config List");
	if(!node)
	{
		purple_debug(PURPLE_DEBUG_ERROR, "gfire", "gfire_game_load_config_xml: Couldn't load game config.\n");
		return FALSE;
	}

	// Check for a valid game config
	if(g_utf8_collate(node->name, "game_config"))
	{
		xmlnode_free(node);
		return FALSE;
	}

	// Check for a valid version
	if(!xmlnode_get_attrib(node, "version") || g_utf8_collate(xmlnode_get_attrib(node, "version"), "2"))
	{
		xmlnode_free(node);
		return FALSE;
	}

	// Delete all old configurations
	gfire_game_config_cleanup();

	// Parse all games
	xmlnode *game_node = xmlnode_get_child(node, "game");
	while(game_node)
	{
		gfire_game_configuration *gconf = gfire_game_configuration_create_from_xml(game_node);
		if(gconf)
			gfire_games_config = g_list_append(gfire_games_config, gconf);

		game_node = xmlnode_get_next_twin(game_node);
	}

	gfire_game_config_sort();

	xmlnode_free(node);

	return TRUE;
}
Exemple #10
0
static void
init_plugin(PurplePlugin *plugin)
{
    char *dirname = NULL;

    g_type_init();
    dirname = g_build_filename(purple_user_dir(), "pidgin-twitter", "icons", NULL);
    if(dirname)
        purple_prefs_add_string(OPT_ICON_DIR, dirname);
    g_free(dirname);

    /* add plugin preferences */
    purple_prefs_add_none(OPT_PIDGINTWITTER);
    purple_prefs_add_bool(OPT_TRANSLATE_RECIPIENT, TRUE);
    purple_prefs_add_bool(OPT_TRANSLATE_SENDER, TRUE);
    purple_prefs_add_bool(OPT_TRANSLATE_CHANNEL, TRUE);
    purple_prefs_add_bool(OPT_ESCAPE_PSEUDO, TRUE);
    purple_prefs_add_bool(OPT_STRIP_EXCESS_LF, TRUE);

    purple_prefs_add_bool(OPT_PLAYSOUND_RECIPIENT, TRUE);
    purple_prefs_add_bool(OPT_PLAYSOUND_SENDER, TRUE);
    purple_prefs_add_int(OPT_SOUNDID_RECIPIENT, PURPLE_SOUND_POUNCE_DEFAULT);
    purple_prefs_add_string(OPT_USERLIST_RECIPIENT, DEFAULT_LIST);
    purple_prefs_add_int(OPT_SOUNDID_SENDER, PURPLE_SOUND_POUNCE_DEFAULT);
    purple_prefs_add_string(OPT_USERLIST_SENDER, DEFAULT_LIST);

    purple_prefs_add_bool(OPT_COUNTER, TRUE);
    purple_prefs_add_bool(OPT_SUPPRESS_OOPS, TRUE);
    purple_prefs_add_bool(OPT_PREVENT_NOTIFICATION, FALSE);

    purple_prefs_add_bool(OPT_API_BASE_POST, TRUE);
    purple_prefs_add_int(OPT_API_BASE_GET_INTERVAL, TWITTER_DEFAULT_INTERVAL);
    purple_prefs_add_int(OPT_RETRIEVE_COUNT, TWITTER_DEFAULT_RETRIEVE_COUNT);
    purple_prefs_add_string(OPT_SCREEN_NAME_TWITTER, EMPTY);
    purple_prefs_add_string(OPT_PASSWORD_TWITTER, EMPTY);
    purple_prefs_add_string(OPT_SCREEN_NAME_WASSR, EMPTY);
    purple_prefs_add_string(OPT_SCREEN_NAME_IDENTICA, EMPTY);
    purple_prefs_add_string(OPT_SCREEN_NAME_JISKO, EMPTY);
    purple_prefs_add_string(OPT_SCREEN_NAME_FFEED, EMPTY);

    purple_prefs_add_bool(OPT_SHOW_ICON, TRUE);
    purple_prefs_add_int(OPT_ICON_SIZE, DEFAULT_ICON_SIZE);
    purple_prefs_add_bool(OPT_UPDATE_ICON, TRUE);
    purple_prefs_add_int(OPT_ICON_MAX_COUNT, DEFAULT_ICON_MAX_COUNT);
    purple_prefs_add_int(OPT_ICON_MAX_DAYS, DEFAULT_ICON_MAX_DAYS);
    purple_prefs_add_bool(OPT_LOG_OUTPUT, FALSE);

    purple_prefs_add_bool(OPT_FILTER, TRUE);
    purple_prefs_add_bool(OPT_FILTER_EXCLUDE_REPLY, TRUE);
    purple_prefs_add_string(OPT_FILTER_TWITTER, DEFAULT_LIST);
    purple_prefs_add_string(OPT_FILTER_WASSR, DEFAULT_LIST);
    purple_prefs_add_string(OPT_FILTER_IDENTICA, DEFAULT_LIST);
    purple_prefs_add_string(OPT_FILTER_JISKO, DEFAULT_LIST);
    purple_prefs_add_string(OPT_FILTER_FFEED, DEFAULT_LIST);
}
Exemple #11
0
gboolean gfire_game_load_games_xml()
{
	xmlnode *node = NULL;

	gchar *filename = g_build_filename(purple_user_dir(), "gfire_games.xml", NULL);
	if(filename)
	{
		purple_debug(PURPLE_DEBUG_INFO, "gfire", "Loading Game Data from: %s\n", filename);
		g_free(filename);
	}

	node = purple_util_read_xml_from_file("gfire_games.xml", "Gfire Games List");
	if(!node)
	{
		purple_debug(PURPLE_DEBUG_ERROR, "gfire", "gfire_game_load_games_xml: Couldn't load game list.\n");
		return FALSE;
	}

	// Delete all old games
	gfire_game_cleanup();

	// Read the games version
	if(g_utf8_collate(node->name, "games"))
	{
		xmlnode_free(node);
		return FALSE;
	}

	if(!xmlnode_get_attrib(node, "version"))
		gfire_games_version = 0;
	else
		sscanf(xmlnode_get_attrib(node, "version"), "%u", &gfire_games_version);

	// Read all games
	xmlnode *game_node = xmlnode_get_child(node, "game");
	while(game_node)
	{
		gboolean external = FALSE;
		gfire_game *game = gfire_game_create_from_xml(game_node, &external);
		if(game)
		{
			gfire_games = g_list_append(gfire_games, game);
			if(external)
				gfire_games_external = g_list_append(gfire_games_external, game);
		}

		game_node = xmlnode_get_next_twin(game_node);
	}

	xmlnode_free(node);

	return TRUE;
}
Exemple #12
0
static void
init_plugin(PurplePlugin *plugin) {
	char *dirname;

	dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL);
	purple_prefs_add_none(PREF_PREFIX);
	purple_prefs_add_string(PREF_PATH, dirname);
	purple_prefs_add_bool(PREF_NOTIFY, TRUE);
	purple_prefs_add_bool(PREF_NEWDIR, TRUE);
	purple_prefs_add_bool(PREF_ESCAPE, TRUE);
	g_free(dirname);
}
static void tgprpl_set_buddy_icon (PurpleConnection * gc, PurpleStoredImage * img) {
  debug ("tgprpl_set_buddy_icon()\n");
  
  telegram_conn *conn = purple_connection_get_protocol_data (gc);
  if (purple_imgstore_get_filename (img)) {
    char* filename = g_strdup_printf ("%s/icons/%s", purple_user_dir(), purple_imgstore_get_filename (img));
    debug (filename);
    
    tgl_do_set_profile_photo (conn->TLS, filename, NULL, NULL);
    
    g_free (filename);
  }
}
static void
ensure_codecs_conf()
{
	gchar *filename;
	filename = g_build_filename(purple_user_dir(), "fs-codec.conf", NULL);

	if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
		int fd = g_open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
		gchar *fs_codecs_conf = FS_CODECS_CONF;
		if ((fd < 0) || write(fd, fs_codecs_conf, strlen(fs_codecs_conf)) == -1)
			SIPE_DEBUG_ERROR_NOFORMAT("Can not create fs-codec.conf!");
		if (fd >= 0)
			close(fd);
	}

	g_free(filename);
}
Exemple #15
0
static void
debug_part_to_file(MsnSlpMessage *msg, gboolean send)
{
	char *tmp;
	char *dir;
	char *data;
	int c;
	gsize data_size;

	dir = send ? "send" : "recv";
	c = send ? m_sc++ : m_rc++;
	tmp = g_strdup_printf("%s/msntest/%s/%03d", purple_user_dir(), dir, c);
	data = msn_slpmsg_serialize(msg, &data_size);
	if (!purple_util_write_data_to_file_absolute(tmp, data, data_size))
	{
		purple_debug_error("msn", "could not save debug file\n");
	}
	g_free(tmp);
}
Exemple #16
0
void
purple_buddy_icons_init()
{
	account_cache = g_hash_table_new_full(
		g_direct_hash, g_direct_equal,
		NULL, (GFreeFunc)g_hash_table_destroy);

	icon_data_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
	                                        g_free, NULL);
	icon_file_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
	                                        g_free, NULL);
	pointer_icon_cache = g_hash_table_new(g_direct_hash, g_direct_equal);

	if (!cache_dir)
		cache_dir = g_build_filename(purple_user_dir(), "icons", NULL);

	purple_signal_connect(purple_imgstore_get_handle(), "image-deleting",
	                      purple_buddy_icons_get_handle(),
	                      G_CALLBACK(image_deleting_cb), NULL);
}
Exemple #17
0
static gboolean create_database_connection() {
	gchar *path;
	int rc;

	if(_db)
		return TRUE;

	/* build the path */
	path = g_build_filename(purple_user_dir(), "cap.db", (gchar *)NULL);

	/* make database connection here */
	rc = sqlite3_open(path, &_db);
	g_free(path);
	if(rc != SQLITE_OK)
		return FALSE;

	/* Add tables here */
	create_tables();
	purple_debug_info("cap", "Database connection successfully made.\n");
	return TRUE;
}
/*------------------------------------------------------------------------
 * Save a new splash-screen for later display.
 *
 *  @param session		The MXit session object
 *  @param splashID		The ID of the splash-screen
 *  @param data			Splash-screen image data (PNG format)
 *  @param datalen		Splash-screen image data size
 */
void splash_update(struct MXitSession* session, const char* splashId, const char* data, unsigned int datalen, gboolean clickable)
{
	char* dir;
	char* filename;

	/* Remove the current splash-screen */
	splash_remove(session);

	/* Save the new splash image */
	dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit", purple_user_dir());
	purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR);		/* ensure directory exists */

	filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s.png", dir, purple_escape_filename(splashId));
	if (purple_util_write_data_to_file_absolute(filename, data, datalen)) {
		/* Store new splash-screen ID to settings */
		purple_account_set_string(session->acc, MXIT_CONFIG_SPLASHID, splashId);
		purple_account_set_bool(session->acc, MXIT_CONFIG_SPLASHCLICK, clickable );
	}

	g_free(dir);
	g_free(filename);
}
static gboolean
purple_pounces_load(void)
{
	gchar *filename = g_build_filename(purple_user_dir(), "pounces.xml", NULL);
	gchar *contents = NULL;
	gsize length;
	GMarkupParseContext *context;
	GError *error = NULL;
	PounceParserData *parser_data;

	if (filename == NULL) {
		pounces_loaded = TRUE;
		return FALSE;
	}

	if (!g_file_get_contents(filename, &contents, &length, &error)) {
		purple_debug(PURPLE_DEBUG_ERROR, "pounce",
				   "Error reading pounces: %s\n", error->message);

		g_free(filename);
		g_error_free(error);

		pounces_loaded = TRUE;
		return FALSE;
	}

	parser_data = g_new0(PounceParserData, 1);

	context = g_markup_parse_context_new(&pounces_parser, 0,
										 parser_data, free_parser_data);

	if (!g_markup_parse_context_parse(context, contents, length, NULL)) {
		g_markup_parse_context_free(context);
		g_free(contents);
		g_free(filename);

		pounces_loaded = TRUE;

		return FALSE;
	}

	if (!g_markup_parse_context_end_parse(context, NULL)) {
		purple_debug(PURPLE_DEBUG_ERROR, "pounce", "Error parsing %s\n",
				   filename);

		g_markup_parse_context_free(context);
		g_free(contents);
		g_free(filename);
		pounces_loaded = TRUE;

		return FALSE;
	}

	g_markup_parse_context_free(context);
	g_free(contents);
	g_free(filename);

	pounces_loaded = TRUE;

	return TRUE;
}
Exemple #20
0
static void
install_selected_file_cb(gpointer handle, const char *filename)
{
	/* Try to init the selected file.
	 * If it succeeds, try to make a copy of the file in $USERDIR/plugins/.
	 * If the copy succeeds, unload and destroy the plugin in the original
	 *  location and init+load the new one.
	 * Select the plugin in the plugin list.
	 */
	char *path;
	PurplePlugin *plugin;

	g_return_if_fail(plugins.window);

	plugin = purple_plugin_probe(filename);
	if (!plugin) {
		purple_notify_error(handle, _("Error loading plugin"),
				_("The selected file is not a valid plugin."),
				_("Please open the debug window and try again to see the exact error message."), NULL);
		return;
	}
	if (g_list_find(gnt_tree_get_rows(GNT_TREE(plugins.tree)), plugin)) {
		purple_plugin_load(plugin);
		gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin));
		gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin);
		return;
	}

	path = g_build_filename(purple_user_dir(), "plugins", NULL);
	if (purple_build_dir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
		char *content = NULL;
		gsize length = 0;

		if (g_file_get_contents(filename, &content, &length, NULL)) {
			char *file = g_path_get_basename(filename);
			g_free(path);
			path = g_build_filename(purple_user_dir(), "plugins", file, NULL);
			if (purple_util_write_data_to_file_absolute(path, content, length)) {
				purple_plugin_destroy(plugin);
				plugin = purple_plugin_probe(path);
				if (!plugin) {
					purple_debug_warning("gntplugin", "This is really strange. %s can be loaded, but %s can't!\n",
							filename, path);
					g_unlink(path);
					plugin = purple_plugin_probe(filename);
				}
			} else {
			}
		}
		g_free(content);
	}
	g_free(path);

	purple_plugin_load(plugin);

	if (plugin->info->type == PURPLE_PLUGIN_LOADER) {
		GList *cur;
		for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL;
				cur = cur->next)
			purple_plugins_probe(cur->data);
		return;
	}

	if (plugin->info->type != PURPLE_PLUGIN_STANDARD ||
			(plugin->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) ||
			plugin->error)
		return;

	gnt_tree_add_choice(GNT_TREE(plugins.tree), plugin,
			gnt_tree_create_row(GNT_TREE(plugins.tree), plugin->info->name), NULL, NULL);
	gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin));
	gnt_tree_set_row_flags(GNT_TREE(plugins.tree), plugin, GNT_TEXT_FLAG_BOLD);
	gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin);
}
Exemple #21
0
GstElement *
purple_media_manager_get_pipeline(PurpleMediaManager *manager)
{
#ifdef USE_VV
	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), NULL);

	if (manager->priv->pipeline == NULL) {
		FsElementAddedNotifier *notifier;
		gchar *filename;
		GError *err = NULL;
		GKeyFile *keyfile;
		GstBus *bus;
		manager->priv->pipeline = gst_pipeline_new(NULL);

		bus = gst_pipeline_get_bus(
				GST_PIPELINE(manager->priv->pipeline));
		gst_bus_add_signal_watch(GST_BUS(bus));
		g_signal_connect(G_OBJECT(bus), "message",
				G_CALLBACK(pipeline_bus_call), manager);
		gst_bus_set_sync_handler(bus,
				gst_bus_sync_signal_handler, NULL);
		gst_object_unref(bus);

		filename = g_build_filename(purple_user_dir(),
				"fs-element.conf", NULL);
		keyfile = g_key_file_new();
		if (!g_key_file_load_from_file(keyfile, filename,
				G_KEY_FILE_NONE, &err)) {
			if (err->code == 4)
				purple_debug_info("mediamanager",
						"Couldn't read "
						"fs-element.conf: %s\n",
						err->message);
			else
				purple_debug_error("mediamanager",
						"Error reading "
						"fs-element.conf: %s\n",
						err->message);
			g_error_free(err);
		}
		g_free(filename);

		/* Hack to make alsasrc stop messing up audio timestamps */
		if (!g_key_file_has_key(keyfile,
				"alsasrc", "slave-method", NULL)) {
			g_key_file_set_integer(keyfile,
					"alsasrc", "slave-method", 2);
		}

		notifier = fs_element_added_notifier_new();
		fs_element_added_notifier_add(notifier,
				GST_BIN(manager->priv->pipeline));
		fs_element_added_notifier_set_properties_from_keyfile(
				notifier, keyfile);

		gst_element_set_state(manager->priv->pipeline,
				GST_STATE_PLAYING);
	}

	return manager->priv->pipeline;
#else
	return NULL;
#endif
}
Exemple #22
0
gboolean
purple_core_migrate(void)
{
    const char *user_dir = purple_user_dir();
    char *old_user_dir = g_strconcat(purple_home_dir(),
                                     G_DIR_SEPARATOR_S ".gaim", NULL);
    char *status_file;
    FILE *fp;
    GDir *dir;
    GError *err;
    const char *entry;
#ifndef _WIN32
    char *logs_dir;
#endif
    char *old_icons_dir;

    if (!g_file_test(old_user_dir, G_FILE_TEST_EXISTS))
    {
        /* ~/.gaim doesn't exist, so there's nothing to migrate. */
        g_free(old_user_dir);
        return TRUE;
    }

    status_file = g_strconcat(user_dir, G_DIR_SEPARATOR_S "migrating", NULL);

    if (g_file_test(user_dir, G_FILE_TEST_EXISTS))
    {
        /* If we're here, we have both ~/.gaim and .purple. */

        if (!g_file_test(status_file, G_FILE_TEST_EXISTS))
        {
            /* There's no "migrating" status file,
             * so ~/.purple is all up to date. */
            g_free(status_file);
            g_free(old_user_dir);
            return TRUE;
        }
    }

    /* If we're here, it's time to migrate from ~/.gaim to ~/.purple. */

    /* Ensure the user directory exists */
    if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR))
    {
        if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
        {
            purple_debug_error("core", "Error creating directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                               user_dir, g_strerror(errno));
            g_free(status_file);
            g_free(old_user_dir);
            return FALSE;
        }
    }

    /* This writes ~/.purple/migrating, which allows us to detect
     * incomplete migrations and properly retry. */
    if (!(fp = g_fopen(status_file, "w")))
    {
        purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                           status_file, g_strerror(errno));
        g_free(status_file);
        g_free(old_user_dir);
        return FALSE;
    }
    fclose(fp);

    /* Open ~/.gaim so we can loop over its contents. */
    err = NULL;
    if (!(dir = g_dir_open(old_user_dir, 0, &err)))
    {
        purple_debug_error("core", "Error opening directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                           status_file,
                           (err ? err->message : "Unknown error"));
        if (err)
            g_error_free(err);
        g_free(status_file);
        g_free(old_user_dir);
        return FALSE;
    }

    /* Loop over the contents of ~/.gaim */
    while ((entry = g_dir_read_name(dir)))
    {
        char *name = g_build_filename(old_user_dir, entry, NULL);

#ifndef _WIN32
        /* Deal with symlinks... */
        if (g_file_test(name, G_FILE_TEST_IS_SYMLINK))
        {
            /* We're only going to duplicate a logs symlink. */
            if (!strcmp(entry, "logs"))
            {
                char *link;
#if GLIB_CHECK_VERSION(2,4,0)
                GError *err = NULL;

                if ((link = g_file_read_link(name, &err)) == NULL)
                {
                    char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
                    purple_debug_error("core", "Error reading symlink %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       name_utf8 ? name_utf8 : name, err->message);
                    g_free(name_utf8);
                    g_error_free(err);
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }
#else
                char buf[MAXPATHLEN];
                size_t linklen;

                if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1))
                {
                    char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
                    purple_debug_error("core", "Error reading symlink %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       name_utf8, g_strerror(errno));
                    g_free(name_utf8);
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }
                buf[linklen] = '\0';

                /* This way we don't have to GLIB_VERSION_CHECK every g_free(link) below. */
                link = g_strdup(buf);
#endif

                logs_dir = g_build_filename(user_dir, "logs", NULL);

                if (!strcmp(link, "../.purple/logs") || !strcmp(link, logs_dir))
                {
                    /* If the symlink points to the new directory, we're
                     * likely just trying again after a failed migration,
                     * so there's no need to fail here. */
                    g_free(link);
                    g_free(logs_dir);
                    continue;
                }

                /* In case we are trying again after a failed migration, we need
                 * to unlink any existing symlink.  If it's a directory, this
                 * will fail, and so will the symlink below, which is good
                 * because the user should sort things out. */
                g_unlink(logs_dir);

                /* Relative links will most likely still be
                 * valid from ~/.purple, though it's not
                 * guaranteed.  Oh well. */
                if (symlink(link, logs_dir))
                {
                    purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       logs_dir, link, g_strerror(errno));
                    g_free(link);
                    g_free(name);
                    g_free(logs_dir);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }

                g_free(link);
                g_free(logs_dir);
                continue;
            }

            /* Ignore all other symlinks. */
            continue;
        }
#endif

        /* Deal with directories... */
        if (g_file_test(name, G_FILE_TEST_IS_DIR))
        {
            if (!strcmp(entry, "icons"))
            {
                /* This is a special case for the Album plugin, which
                 * stores data in the icons folder.  We're not copying
                 * the icons directory over because previous bugs
                 * meant that it filled up with junk for many users.
                 * This is a great time to purge it. */

                GDir *icons_dir;
                char *new_icons_dir;
                const char *icons_entry;

                err = NULL;
                if (!(icons_dir = g_dir_open(name, 0, &err)))
                {
                    purple_debug_error("core", "Error opening directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       name,
                                       (err ? err->message : "Unknown error"));
                    if (err)
                        g_error_free(err);
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }

                new_icons_dir = g_build_filename(user_dir, "icons", NULL);
                /* Ensure the new icon directory exists */
                if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR))
                {
                    if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
                    {
                        purple_debug_error("core", "Error creating directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                           new_icons_dir, g_strerror(errno));
                        g_free(new_icons_dir);
                        g_dir_close(icons_dir);
                        g_free(name);
                        g_dir_close(dir);
                        g_free(status_file);
                        g_free(old_user_dir);
                        return FALSE;
                    }
                }

                while ((icons_entry = g_dir_read_name(icons_dir)))
                {
                    char *icons_name = g_build_filename(name, icons_entry, NULL);

                    if (g_file_test(icons_name, G_FILE_TEST_IS_DIR))
                    {
                        if (!move_and_symlink_dir(icons_name, icons_entry,
                                                  name, new_icons_dir, "../../.purple/icons"))
                        {
                            g_free(icons_name);
                            g_free(new_icons_dir);
                            g_dir_close(icons_dir);
                            g_free(name);
                            g_dir_close(dir);
                            g_free(status_file);
                            g_free(old_user_dir);
                            return FALSE;
                        }
                    }
                    g_free(icons_name);
                }

                g_dir_close(icons_dir);
            }
            else if (!strcmp(entry, "plugins"))
            {
                /* Do nothing, because we broke plugin compatibility.
                 * This means that the plugins directory gets left behind. */
            }
            else
            {
                /* All other directories are moved and symlinked. */
                if (!move_and_symlink_dir(name, entry, old_user_dir, user_dir, "../.purple"))
                {
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }
            }
        }
        else if (g_file_test(name, G_FILE_TEST_IS_REGULAR))
        {
            /* Regular files are copied. */

            char *new_name;
            FILE *new_file;

            if (!(fp = g_fopen(name, "rb")))
            {
                purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                   name, g_strerror(errno));
                g_free(name);
                g_dir_close(dir);
                g_free(status_file);
                g_free(old_user_dir);
                return FALSE;
            }

            new_name = g_build_filename(user_dir, entry, NULL);
            if (!(new_file = g_fopen(new_name, "wb")))
            {
                purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                   new_name, g_strerror(errno));
                fclose(fp);
                g_free(new_name);
                g_free(name);
                g_dir_close(dir);
                g_free(status_file);
                g_free(old_user_dir);
                return FALSE;
            }

            while (!feof(fp))
            {
                unsigned char buf[256];
                size_t size;

                size = fread(buf, 1, sizeof(buf), fp);
                if (size != sizeof(buf) && !feof(fp))
                {
                    purple_debug_error("core", "Error reading %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       name, g_strerror(errno));
                    fclose(new_file);
                    fclose(fp);
                    g_free(new_name);
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }

                if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0)
                {
                    purple_debug_error("core", "Error writing %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                       new_name, g_strerror(errno));
                    fclose(new_file);
                    fclose(fp);
                    g_free(new_name);
                    g_free(name);
                    g_dir_close(dir);
                    g_free(status_file);
                    g_free(old_user_dir);
                    return FALSE;
                }
            }

            if (fclose(new_file))
            {
                purple_debug_error("core", "Error writing: %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                                   new_name, g_strerror(errno));
            }
            if (fclose(fp))
            {
                purple_debug_warning("core", "Error closing %s: %s\n",
                                     name, g_strerror(errno));
            }
            g_free(new_name);
        }
        else
            purple_debug_warning("core", "Not a regular file or directory: %s\n", name);

        g_free(name);
    }

    /* The migration was successful, so delete the status file. */
    if (g_unlink(status_file))
    {
        purple_debug_error("core", "Error unlinking file %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                           status_file, g_strerror(errno));
        g_free(status_file);
        return FALSE;
    }

    old_icons_dir = g_build_filename(old_user_dir, "icons", NULL);
    _purple_buddy_icon_set_old_icons_dir(old_icons_dir);
    g_free(old_icons_dir);

    g_free(old_user_dir);

    g_free(status_file);
    return TRUE;
}
Exemple #23
0
void finch_ui_init()
{
#ifdef STANDALONE
#ifdef _WIN32 /* TODO: don't change it when using FHS under win32 */
	gnt_set_config_dir(purple_user_dir());
#endif /* _WIN32 */

	gnt_init();
#endif /* STANDALONE */

	purple_prefs_add_none("/purple/gnt");

	/* Accounts */
	finch_accounts_init();
	purple_accounts_set_ui_ops(finch_accounts_get_ui_ops());

	/* Connections */
	finch_connections_init();
	purple_connections_set_ui_ops(finch_connections_get_ui_ops());

	/* Initialize the buddy list */
	finch_blist_init();
	purple_blist_set_ui_ops(finch_blist_get_ui_ops());

	/* Initialize sound */
	purple_sound_set_ui_ops(finch_sound_get_ui_ops());

	/* Now the conversations */
	finch_conversation_init();
	purple_conversations_set_ui_ops(finch_conv_get_ui_ops());

	/* Notify */
	finch_notify_init();
	purple_notify_set_ui_ops(finch_notify_get_ui_ops());

	/* Request */
	finch_request_init();
	purple_request_set_ui_ops(finch_request_get_ui_ops());

	/* Pounce */
	finch_pounces_init();

	/* Log */
	finch_log_init();

	/* File transfer */
	finch_xfers_init();
	purple_xfers_set_ui_ops(finch_xfers_get_ui_ops());

	/* Roomlist */
	finch_roomlist_init();
	purple_roomlist_set_ui_ops(finch_roomlist_get_ui_ops());

	/* Media */
	finch_media_manager_init();

	gnt_register_action(_("Accounts"), finch_accounts_show_all);
	gnt_register_action(_("Buddy List"), finch_blist_show);
	gnt_register_action(_("Buddy Pounces"), finch_pounces_manager_show);
	gnt_register_action(_("Certificates"), finch_certmgr_show);
	gnt_register_action(_("Debug Window"), finch_debug_window_show);
	gnt_register_action(_("File Transfers"), finch_xfer_dialog_show);
	gnt_register_action(_("Plugins"), finch_plugins_show_all);
	gnt_register_action(_("Room List"), finch_roomlist_show_all);
	gnt_register_action(_("Sounds"), finch_sounds_show_all);
	gnt_register_action(_("Preferences"), finch_prefs_show_all);
	gnt_register_action(_("Keyring settings"), finch_prefs_show_keyring);
	gnt_register_action(_("Statuses"), finch_savedstatus_show_all);

#ifdef STANDALONE
}
/*------------------------------------------------------------------------
 * Remove the stored splash-screen (if it exists).
 *
 *  @param session		The MXit session object
 */
void splash_remove(struct MXitSession* session)
{
	const char* splashId = NULL;
	char* filename;

	/* Get current splash ID */
	splashId = splash_current(session);

	if (splashId != NULL) {
		purple_debug_info(MXIT_PLUGIN_ID, "Removing splashId: '%s'\n", splashId);

		/* Delete stored splash image */
		filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit" G_DIR_SEPARATOR_S "%s.png", purple_user_dir(), purple_escape_filename(splashId));
		g_unlink(filename);
		g_free(filename);

		/* Clear current splash ID from settings */
		purple_account_set_string(session->acc, MXIT_CONFIG_SPLASHID, "");
		purple_account_set_bool(session->acc, MXIT_CONFIG_SPLASHCLICK, FALSE);
	}
}
/*------------------------------------------------------------------------
 * Display the current splash-screen.
 *
 *  @param session		The MXit session object
 */
void splash_display(struct MXitSession* session)
{
	const char* splashId = NULL;
	char* filename;
	gchar* imgdata;
	gsize imglen;
	int imgid = -1;

	/* Get current splash ID */
	splashId = splash_current(session);
	if (splashId == NULL)		/* no splash-screen */
		return;

	purple_debug_info(MXIT_PLUGIN_ID, "Display Splash: '%s'\n", splashId);

	/* Load splash-screen image from file */
	filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit" G_DIR_SEPARATOR_S "%s.png", purple_user_dir(), purple_escape_filename(splashId));
	if (g_file_get_contents(filename, &imgdata, &imglen, NULL)) {
		char buf[128];

		/* Add splash-image to imagestore */
		imgid = purple_imgstore_add_with_id(g_memdup(imgdata, imglen), imglen, NULL);

		/* Generate and display message */
		g_snprintf(buf, sizeof(buf), "<img id=\"%d\">", imgid);

		/* Open a request-type popup to display the image */
		{
			PurpleRequestFields*		fields;
			PurpleRequestFieldGroup*	group;
			PurpleRequestField*			field;

			fields = purple_request_fields_new();
			group = purple_request_field_group_new(NULL);
			purple_request_fields_add_group(fields, group);

			field = purple_request_field_image_new("splash", "", imgdata, imglen);		/* add splash image */
			purple_request_field_group_add_field(group, field);

			if (splash_clickable(session)) {
				purple_request_fields(session->con, _("MXit Advertising"), NULL, NULL, fields,
					_("More Information"), G_CALLBACK(splash_click_ok), _("Close"), NULL, session->acc, NULL, NULL, session->con);
			}
			else {
				purple_request_fields(session->con, _("MXit Advertising"), NULL, NULL, fields,
					_("Continue"), G_CALLBACK(splash_click_ok), _("Close"), NULL, session->acc, NULL, NULL, session->con);
			}
		}

		/* Release reference to image */
		purple_imgstore_unref_by_id(imgid);

		g_free(imgdata);
	}

	g_free(filename);
}
Exemple #26
0
string IM::getBuddyIconPath() const
{
	return string(purple_user_dir()) + "/buddy_icon/";
}
Exemple #27
0
static int
init_libpurple(int argc, char **argv)
{
	char *path;
	int opt;
	gboolean opt_help = FALSE;
	gboolean opt_nologin = FALSE;
	gboolean opt_version = FALSE;
	char *opt_config_dir_arg = NULL;
	gboolean debug_enabled = FALSE;

	struct option long_options[] = {
		{"config",   required_argument, NULL, 'c'},
		{"debug",    no_argument,       NULL, 'd'},
		{"help",     no_argument,       NULL, 'h'},
		{"nologin",  no_argument,       NULL, 'n'},
		{"version",  no_argument,       NULL, 'v'},
		{0, 0, 0, 0}
	};

#ifdef ENABLE_NLS
	bindtextdomain(PACKAGE, PURPLE_LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "UTF-8");
	textdomain(PACKAGE);
#endif

#ifdef HAVE_SETLOCALE
	setlocale(LC_ALL, "");
#endif

	/* scan command-line options */
	opterr = 1;
	while ((opt = getopt_long(argc, argv, "c:dhn::v",
				  long_options, NULL)) != -1) {
		switch (opt) {
		case 'c':	/* config dir */
			g_free(opt_config_dir_arg);
			opt_config_dir_arg = g_strdup(optarg);
			break;
		case 'd':	/* debug */
			debug_enabled = TRUE;
			break;
		case 'h':	/* help */
			opt_help = TRUE;
			break;
		case 'n':	/* no autologin */
			opt_nologin = TRUE;
			break;
		case 'v':	/* version */
			opt_version = TRUE;
			break;
		case '?':	/* show terse help */
		default:
			show_usage(argv[0], TRUE);
			return 0;
			break;
		}
	}

	/* show help message */
	if (opt_help) {
		show_usage(argv[0], FALSE);
		return 0;
	}
	/* show version message */
	if (opt_version) {
		/* Translators may want to transliterate the name.
		 It is not to be translated. */
		printf("%s %s (%s)\n", _("Finch"), DISPLAY_VERSION, REVISION);
		return 0;
	}

	/* set a user-specified config directory */
	if (opt_config_dir_arg != NULL) {
		if (g_path_is_absolute(opt_config_dir_arg)) {
			purple_util_set_user_dir(opt_config_dir_arg);
		} else {
			/* Make an absolute (if not canonical) path */
			char *cwd = g_get_current_dir();
			char *path = g_build_path(G_DIR_SEPARATOR_S, cwd, opt_config_dir_arg, NULL);
			purple_util_set_user_dir(path);
			g_free(path);
			g_free(cwd);
		}

		g_free(opt_config_dir_arg);
	}

	/*
	 * We're done piddling around with command line arguments.
	 * Fire up this baby.
	 */

	/* We don't want debug-messages to show up and corrupt the display */
	purple_debug_set_enabled(debug_enabled);

	purple_core_set_ui_ops(gnt_core_get_ui_ops());
	purple_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops());
	purple_idle_set_ui_ops(finch_idle_get_ui_ops());

	if (!purple_core_init(FINCH_UI))
	{
		fprintf(stderr,
				"Initialization of the Purple core failed. Dumping core.\n"
				"Please report this!\n");
		abort();
	}

	path = g_build_filename(purple_user_dir(), "plugins", NULL);
	if (g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0 && errno != EEXIST)
		fprintf(stderr, "Couldn't create plugins dir\n");
	purple_plugins_add_search_path(path);
	g_free(path);

	purple_plugins_add_search_path(FINCH_LIBDIR);
	purple_plugins_refresh();

	/* TODO: should this be moved into finch_prefs_init() ? */
	finch_prefs_update_old();

	/* load plugins we had when we quit */
	purple_plugins_load_saved("/finch/plugins/loaded");

	if (opt_nologin)
	{
		/* Set all accounts to "offline" */
		PurpleSavedStatus *saved_status;

		/* If we've used this type+message before, lookup the transient status */
		saved_status = purple_savedstatus_find_transient_by_type_and_message(
							PURPLE_STATUS_OFFLINE, NULL);

		/* If this type+message is unique then create a new transient saved status */
		if (saved_status == NULL)
			saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);

		/* Set the status for each account */
		purple_savedstatus_activate(saved_status);
	}
	else
	{
		/* Everything is good to go--sign on already */
		if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
			purple_savedstatus_activate(purple_savedstatus_get_startup());
		purple_accounts_restore_current_statuses();
	}

	return 1;
}
Exemple #28
0
int main(int argc, char *argv[])
#endif
{
	gboolean opt_force_online = FALSE;
	gboolean opt_help = FALSE;
	gboolean opt_login = FALSE;
	gboolean opt_nologin = FALSE;
	gboolean opt_version = FALSE;
	gboolean opt_si = TRUE;     /* Check for single instance? */
	char *opt_config_dir_arg = NULL;
	char *opt_login_arg = NULL;
	char *opt_session_arg = NULL;
	char *search_path;
	GList *accounts;
#ifdef HAVE_SIGNAL_H
	int sig_indx;	/* for setting up signal catching */
	sigset_t sigset;
	RETSIGTYPE (*prev_sig_disp)(int);
	char errmsg[BUFSIZ];
	GIOChannel *signal_channel;
	GIOStatus signal_status;
	guint signal_channel_watcher;
#ifndef DEBUG
	char *segfault_message_tmp;
#endif
	GError *error;
#endif
	int opt;
	gboolean gui_check;
	gboolean debug_enabled;
	gboolean migration_failed = FALSE;
	GList *active_accounts;
	struct stat st;

	struct option long_options[] = {
		{"config",       required_argument, NULL, 'c'},
		{"debug",        no_argument,       NULL, 'd'},
		{"force-online", no_argument,       NULL, 'f'},
		{"help",         no_argument,       NULL, 'h'},
		{"login",        optional_argument, NULL, 'l'},
		{"multiple",     no_argument,       NULL, 'm'},
		{"nologin",      no_argument,       NULL, 'n'},
		{"session",      required_argument, NULL, 's'},
		{"version",      no_argument,       NULL, 'v'},
		{"display",      required_argument, NULL, 'D'},
		{"sync",         no_argument,       NULL, 'S'},
		{0, 0, 0, 0}
	};

#ifdef DEBUG
	debug_enabled = TRUE;
#else
	debug_enabled = FALSE;
#endif

	/* Initialize GThread before calling any Glib or GTK+ functions. */
	g_thread_init(NULL);

	g_set_prgname("Pidgin");

#ifdef ENABLE_NLS
	bindtextdomain(PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "UTF-8");
	textdomain(PACKAGE);
#endif

#ifdef HAVE_SETLOCALE
	/* Locale initialization is not complete here.  See gtk_init_check() */
	setlocale(LC_ALL, "");
#endif

#ifdef HAVE_SIGNAL_H

#ifndef DEBUG
		/* We translate this here in case the crash breaks gettext. */
		segfault_message_tmp = g_strdup_printf(_(
			"%s %s has segfaulted and attempted to dump a core file.\n"
			"This is a bug in the software and has happened through\n"
			"no fault of your own.\n\n"
			"If you can reproduce the crash, please notify the developers\n"
			"by reporting a bug at:\n"
			"%ssimpleticket/\n\n"
			"Please make sure to specify what you were doing at the time\n"
			"and post the backtrace from the core file.  If you do not know\n"
			"how to get the backtrace, please read the instructions at\n"
			"%swiki/GetABacktrace\n"),
			PIDGIN_NAME, DISPLAY_VERSION, PURPLE_DEVEL_WEBSITE, PURPLE_DEVEL_WEBSITE
		);

		/* we have to convert the message (UTF-8 to console
		   charset) early because after a segmentation fault
		   it's not a good practice to allocate memory */
		error = NULL;
		segfault_message = g_locale_from_utf8(segfault_message_tmp,
						      -1, NULL, NULL, &error);
		if (segfault_message != NULL) {
			g_free(segfault_message_tmp);
		}
		else {
			/* use 'segfault_message_tmp' (UTF-8) as a fallback */
			g_warning("%s\n", error->message);
			g_error_free(error);
			segfault_message = segfault_message_tmp;
		}
#else
		/* Don't mark this for translation. */
		segfault_message = g_strdup(
			"Hi, user.  We need to talk.\n"
			"I think something's gone wrong here.  It's probably my fault.\n"
			"No, really, it's not you... it's me... no no no, I think we get along well\n"
			"it's just that.... well, I want to see other people.  I... what?!?  NO!  I \n"
			"haven't been cheating on you!!  How many times do you want me to tell you?!  And\n"
			"for the last time, it's just a rash!\n"
		);
#endif

	/*
	 * Create a socket pair for receiving unix signals from a signal
	 * handler.
	 */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_sockets) < 0) {
		perror("Failed to create sockets for GLib signal handling");
		exit(1);
	}
	signal_channel = g_io_channel_unix_new(signal_sockets[1]);

	/*
	 * Set the channel encoding to raw binary instead of the default of
	 * UTF-8, because we'll be sending integers across instead of strings.
	 */
	error = NULL;
	signal_status = g_io_channel_set_encoding(signal_channel, NULL, &error);
	if (signal_status != G_IO_STATUS_NORMAL) {
		fprintf(stderr, "Failed to set the signal channel to raw "
				"binary: %s", error->message);
		exit(1);
	}
	signal_channel_watcher = g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL);
	g_io_channel_unref(signal_channel);

	/* Let's not violate any PLA's!!!! */
	/* jseymour: whatever the fsck that means */
	/* Robot101: for some reason things like gdm like to block     *
	 * useful signals like SIGCHLD, so we unblock all the ones we  *
	 * declare a handler for. thanks JSeymour and Vann.            */
	if (sigemptyset(&sigset)) {
		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't initialise empty signal set");
		perror(errmsg);
	}
	for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) {
		if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d for catching",
				catch_sig_list[sig_indx]);
			perror(errmsg);
		}
		if(sigaddset(&sigset, catch_sig_list[sig_indx])) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't include signal %d for unblocking",
				catch_sig_list[sig_indx]);
			perror(errmsg);
		}
	}
	for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) {
		if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d to ignore",
				ignore_sig_list[sig_indx]);
			perror(errmsg);
		}
	}

	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals");
		perror(errmsg);
	}
#endif

	/* scan command-line options */
	opterr = 1;
	while ((opt = getopt_long(argc, argv,
#ifndef _WIN32
				  "c:dfhmnl::s:v",
#else
				  "c:dfhmnl::v",
#endif
				  long_options, NULL)) != -1) {
		switch (opt) {
		case 'c':	/* config dir */
			g_free(opt_config_dir_arg);
			opt_config_dir_arg = g_strdup(optarg);
			break;
		case 'd':	/* debug */
			debug_enabled = TRUE;
			break;
		case 'f':	/* force-online */
			opt_force_online = TRUE;
			break;
		case 'h':	/* help */
			opt_help = TRUE;
			break;
		case 'n':	/* no autologin */
			opt_nologin = TRUE;
			break;
		case 'l':	/* login, option username */
			opt_login = TRUE;
			g_free(opt_login_arg);
			if (optarg != NULL)
				opt_login_arg = g_strdup(optarg);
			break;
		case 's':	/* use existing session ID */
			g_free(opt_session_arg);
			opt_session_arg = g_strdup(optarg);
			break;
		case 'v':	/* version */
			opt_version = TRUE;
			break;
		case 'm':   /* do not ensure single instance. */
			opt_si = FALSE;
			break;
		case 'D':   /* --display */
		case 'S':   /* --sync */
			/* handled by gtk_init_check below */
			break;
		case '?':	/* show terse help */
		default:
			show_usage(argv[0], TRUE);
#ifdef HAVE_SIGNAL_H
			g_free(segfault_message);
#endif
			return 0;
			break;
		}
	}

	/* show help message */
	if (opt_help) {
		show_usage(argv[0], FALSE);
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}
	/* show version message */
	if (opt_version) {
		printf("%s %s (libpurple %s)\n", PIDGIN_NAME, DISPLAY_VERSION,
		                                 purple_core_get_version());
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	/* set a user-specified config directory */
	if (opt_config_dir_arg != NULL) {
		purple_util_set_user_dir(opt_config_dir_arg);
	}

	/*
	 * We're done piddling around with command line arguments.
	 * Fire up this baby.
	 */

	purple_debug_set_enabled(debug_enabled);

	/* If we're using a custom configuration directory, we
	 * do NOT want to migrate, or weird things will happen. */
	if (opt_config_dir_arg == NULL)
	{
		if (!purple_core_migrate())
		{
			migration_failed = TRUE;
		}
	}

	search_path = g_build_filename(purple_user_dir(), "gtkrc-2.0", NULL);
	gtk_rc_add_default_file(search_path);
	g_free(search_path);

	gui_check = gtk_init_check(&argc, &argv);
	if (!gui_check) {
		char *display = gdk_get_display();

		printf("%s %s\n", PIDGIN_NAME, DISPLAY_VERSION);

		g_warning("cannot open display: %s", display ? display : "unset");
		g_free(display);
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif

		return 1;
	}

	g_set_application_name(PIDGIN_NAME);

#ifdef _WIN32
	winpidgin_init(hint);
#endif

	if (migration_failed)
	{
		char *old = g_strconcat(purple_home_dir(),
		                        G_DIR_SEPARATOR_S ".gaim", NULL);
		const char *text = _(
			"%s encountered errors migrating your settings "
			"from %s to %s. Please investigate and complete the "
			"migration by hand. Please report this error at http://developer.pidgin.im");
		GtkWidget *dialog;

		dialog = gtk_message_dialog_new(NULL,
		                                0,
		                                GTK_MESSAGE_ERROR,
		                                GTK_BUTTONS_CLOSE,
		                                text, PIDGIN_NAME,
		                                old, purple_user_dir());
		g_free(old);

		g_signal_connect_swapped(dialog, "response",
		                         G_CALLBACK(gtk_main_quit), NULL);

		gtk_widget_show_all(dialog);

		gtk_main();

#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	purple_core_set_ui_ops(pidgin_core_get_ui_ops());
	purple_eventloop_set_ui_ops(pidgin_eventloop_get_ui_ops());

	/*
	 * Set plugin search directories. Give priority to the plugins
	 * in user's home directory.
	 */
	search_path = g_build_filename(purple_user_dir(), "plugins", NULL);
	if (!g_stat(search_path, &st))
		g_mkdir(search_path, S_IRUSR | S_IWUSR | S_IXUSR);
	purple_plugins_add_search_path(search_path);
	g_free(search_path);
	purple_plugins_add_search_path(LIBDIR);

	if (!purple_core_init(PIDGIN_UI)) {
		fprintf(stderr,
				"Initialization of the libpurple core failed. Dumping core.\n"
				"Please report this!\n");
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		abort();
	}

	if (opt_si && !purple_core_ensure_single_instance()) {
#ifdef HAVE_DBUS
		DBusConnection *conn = purple_dbus_get_connection();
		DBusMessage *message = dbus_message_new_method_call(DBUS_SERVICE_PURPLE, DBUS_PATH_PURPLE,
				DBUS_INTERFACE_PURPLE, "PurpleBlistSetVisible");
		gboolean tr = TRUE;
		dbus_message_append_args(message, DBUS_TYPE_INT32, &tr, DBUS_TYPE_INVALID);
		dbus_connection_send_with_reply_and_block(conn, message, -1, NULL);
		dbus_message_unref(message);
#endif
		gdk_notify_startup_complete();
		purple_core_quit();
		g_printerr(_("Exiting because another libpurple client is already running.\n"));
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	/* TODO: Move blist loading into purple_blist_init() */
	purple_set_blist(purple_blist_new());
	purple_blist_load();

	/* load plugins we had when we quit */
	purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded");

	/* TODO: Move pounces loading into purple_pounces_init() */
	purple_pounces_load();

	ui_main();

#ifdef USE_SM
	pidgin_session_init(argv[0], opt_session_arg, opt_config_dir_arg);
#endif
	if (opt_session_arg != NULL) {
		g_free(opt_session_arg);
		opt_session_arg = NULL;
	}
	if (opt_config_dir_arg != NULL) {
		g_free(opt_config_dir_arg);
		opt_config_dir_arg = NULL;
	}

	/* This needs to be before purple_blist_show() so the
	 * statusbox gets the forced online status. */
	if (opt_force_online)
		purple_network_force_online();

	/*
	 * We want to show the blist early in the init process so the
	 * user feels warm and fuzzy (not cold and prickley).
	 */
	purple_blist_show();

	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled"))
		pidgin_debug_window_show();

	if (opt_login) {
		/* disable all accounts */
		for (accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
			PurpleAccount *account = accounts->data;
			purple_account_set_enabled(account, PIDGIN_UI, FALSE);
		}
		/* honor the startup status preference */
		if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
			purple_savedstatus_activate(purple_savedstatus_get_startup());
		/* now enable the requested ones */
		dologin_named(opt_login_arg);
		if (opt_login_arg != NULL) {
			g_free(opt_login_arg);
			opt_login_arg = NULL;
		}
	} else if (opt_nologin)	{
		/* Set all accounts to "offline" */
		PurpleSavedStatus *saved_status;

		/* If we've used this type+message before, lookup the transient status */
		saved_status = purple_savedstatus_find_transient_by_type_and_message(
							PURPLE_STATUS_OFFLINE, NULL);

		/* If this type+message is unique then create a new transient saved status */
		if (saved_status == NULL)
			saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);

		/* Set the status for each account */
		purple_savedstatus_activate(saved_status);
	} else {
		/* Everything is good to go--sign on already */
		if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
			purple_savedstatus_activate(purple_savedstatus_get_startup());
		purple_accounts_restore_current_statuses();
	}

	if ((active_accounts = purple_accounts_get_all_active()) == NULL)
	{
		pidgin_accounts_window_show();
	}
	else
	{
		g_list_free(active_accounts);
	}

	/* GTK clears the notification for us when opening the first window,
	 * but we may have launched with only a status icon, so clear the it
	 * just in case. */
	gdk_notify_startup_complete();

#ifdef _WIN32
	winpidgin_post_init();
#endif

	gtk_main();

#ifdef HAVE_SIGNAL_H
	g_free(segfault_message);
	g_source_remove(signal_channel_watcher);
	close(signal_sockets[0]);
	close(signal_sockets[1]);
#endif

#ifdef _WIN32
	winpidgin_cleanup();
#endif

	return 0;
}
Exemple #29
0
gboolean
purple_prefs_load()
{
	gchar *filename = g_build_filename(purple_user_dir(), "prefs.xml", NULL);
	gchar *contents = NULL;
	gsize length;
	GMarkupParseContext *context;
	GError *error = NULL;

	if (!filename) {
		prefs_loaded = TRUE;
		return FALSE;
	}

	purple_debug_info("prefs", "Reading %s\n", filename);

	if(!g_file_get_contents(filename, &contents, &length, &error)) {
#ifdef _WIN32
		gchar *common_appdata = wpurple_get_special_folder(CSIDL_COMMON_APPDATA);
#endif
		g_free(filename);
		g_error_free(error);

		error = NULL;

                /* BEGIN SPICEBIRD CHANGES */
                filename = g_build_filename(g_getenv("MOZILLA_FIVE_HOME"),
                                            "purple", "prefs.xml", NULL);
#if 0
#ifdef _WIN32
		filename = g_build_filename(common_appdata ? common_appdata : "", "purple", "prefs.xml", NULL);
		g_free(common_appdata);
#else
		filename = g_build_filename(SYSCONFDIR, "purple", "prefs.xml", NULL);
#endif
#endif
                /* END SPICEBIRD CHANGES */


		purple_debug_info("prefs", "Reading %s\n", filename);

		if (!g_file_get_contents(filename, &contents, &length, &error)) {
			purple_debug_error("prefs", "Error reading prefs: %s\n",
					error->message);
			g_error_free(error);
			g_free(filename);
			prefs_loaded = TRUE;

			return FALSE;
		}
	}

	context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL);

	if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
		g_markup_parse_context_free(context);
		g_free(contents);
		g_free(filename);
		prefs_loaded = TRUE;

		return FALSE;
	}

	if(!g_markup_parse_context_end_parse(context, NULL)) {
		purple_debug_error("prefs", "Error parsing %s\n", filename);
		g_markup_parse_context_free(context);
		g_free(contents);
		g_free(filename);
		prefs_loaded = TRUE;

		return FALSE;
	}

	purple_debug_info("prefs", "Finished reading %s\n", filename);
	g_markup_parse_context_free(context);
	g_free(contents);
	g_free(filename);
	prefs_loaded = TRUE;

	return TRUE;
}