Example #1
0
static int
dccrecv_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[2], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[2], sum);						/* word[2] is the full filename */
			/* try to print the checksum in the privmsg tab of the sender */
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  %s\n", word[1], sum);
		}
		else
		{
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]);
		}
	}
	else
	{
		xchat_printf (ph, "File access error!\n");
	}

	return XCHAT_EAT_NONE;
}
Example #2
0
/*
 * lua:  xchat.find_context(srv, chan)
 * desc: Finds a context based on a channel and servername. If servname is nil,
 *       it finds any channel (or query) by the given name. If channel is nil, 
 *       it finds the front-most tab/window of the given servname. If nil is 
 *       given for both arguments, the currently focused tab/window will be 
 *       returned.
 *       Changed in 2.6.1. If servname is nil, it finds the channel (or query)
 *       by the given name in the same server group as the current context. 
 *       If that doesn't exists then find any by the given name. 
 * ret:  context number (DON'T modify)
 * args: 
 *       * srv (string or nil): server name
 *       * chan (string or nil): channel / query name
 */
static int lxc_find_context(lua_State *L)
{
	const char *srv, *chan;
	long ctx;
	xchat_context *ptr;

	if (lua_type(L, 1) == LUA_TSTRING) {
		srv = lua_tostring(L, 1);
		if (srv[0] == '\0')
			srv = NULL;
	}
	else
		srv = NULL;
	
	if (lua_type(L, 2) == LUA_TSTRING) {
		chan = lua_tostring(L, 2);
		if (chan[0] == '\0')
			chan = NULL;
	}
	else
		chan = NULL;
	
	ptr = xchat_find_context(ph, srv, chan);
	ctx = (long)ptr;
#ifdef DEBUG
	fprintf(stderr, "find_context(): %#lx\n", (long)ptr);
#endif
	lua_pushnumber(L, (double)ctx);
	return 1;
}
Example #3
0
static VALUE static_ruby_xchat_find_context( VALUE klass,
                                             VALUE server,
                                             VALUE channel )
{
  char *s_server = NULL;
  char *s_channel = NULL;
  xchat_context *ctx;
  VALUE v_ctx;

  if( !NIL_P( server ) ) s_server = StringValueCStr( server );
  if( !NIL_P( channel ) ) s_channel = StringValueCStr( channel );

  ctx = xchat_find_context( static_plugin_handle,
                            s_server,
                            s_channel );

  if( ctx == NULL )
    return Qnil;

  v_ctx = Data_Wrap_Struct( static_xchat_context_klass,
                            NULL, NULL,
                            ctx );

  return v_ctx;
}
Example #4
0
static int
dccoffer_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[3], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[3], sum);						/* word[3] is the full filename */
			xchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum);
		}
		else
		{
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]);
		}
	}
	else
	{
		xchat_printf (ph, "File access error!\n");
	}

	return XCHAT_EAT_NONE;
}
Example #5
0
static void
set_network_mode (NetworkStatus status)
{
	xchat_list *channels_list;

	if (status == NETWORK_DOWN) {
		/* Store a list of currently connected networks & channels,
		 * so we can restore the previous state when the network
		 * becomes active again */
		channels_list = xchat_list_get (ph, "channels");
		if (channels_list == NULL)
			return;

		if (channels) g_hash_table_destroy (channels);
		if (networks) g_hash_table_destroy (networks);

		channels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
		networks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

		while (xchat_list_next (ph, channels_list)) {
			const gchar *channel, *server;
			gint type;

			channel = xchat_list_str (ph, channels_list, "channel");
			server  = xchat_list_str (ph, channels_list, "server");
			type    = xchat_list_int (ph, channels_list, "type");

			if (type == SESSION_TYPE_SERVER) {
				xchat_context *context = xchat_find_context (ph, server, channel);
				g_hash_table_insert (networks, (gpointer) g_strdup (server), context);
			} else if (type == SESSION_TYPE_CHANNEL) {
				gboolean exists;
				GList *network_channels;

				network_channels = g_hash_table_lookup (channels, server);
				exists = (network_channels != NULL);

				network_channels = g_list_prepend (network_channels, g_strdup (channel));

				if (exists)
					g_hash_table_replace (channels, (gpointer) g_strdup (server), network_channels);
				else
					g_hash_table_insert (channels, (gpointer) g_strdup (server), network_channels);
			}
		}

		g_hash_table_foreach (networks, (GHFunc) disconnect_from_network, NULL);
	} else {
		/*
		 * We need to tell the nameserver resolver to reread
		 * /etc/resolv.conf, since the nameservers might have changed
		 * when moving between networks.
		 */
		res_init();

		g_hash_table_foreach (networks, (GHFunc) connect_to_network, NULL);
	}
}
Example #6
0
static
XS (XS_Xchat_find_context)
{
	char *server = NULL;
	char *chan = NULL;
	xchat_context *RETVAL;

	dXSARGS;
	if (items > 2)
		xchat_print (ph, "Usage: Xchat::find_context ([channel, [server]])");
	{

		switch (items) {
		case 0:						  /* no server name and no channel name */
			/* nothing to do, server and chan are already NULL */
			break;
		case 1:						  /* channel name only */
			/* change channel value only if it is true or 0 */
			/* otherwise leave it as null */
			if (SvTRUE (ST (0)) || SvNIOK (ST (0))) {
				chan = SvPV_nolen (ST (0));
				/*                               xchat_printf( ph, "XSUB - find_context( %s, NULL )", chan ); */
			}
			/* else { xchat_print( ph, "XSUB - find_context( NULL, NULL )" ); } */
			/* chan is already NULL */
			break;
		case 2:						  /* server and channel */
			/* change channel value only if it is true or 0 */
			/* otherwise leave it as NULL */
			if (SvTRUE (ST (0)) || SvNIOK (ST (0))) {
				chan = SvPV_nolen (ST (0));
				/*                               xchat_printf( ph, "XSUB - find_context( %s, NULL )", SvPV_nolen(ST(0) )); */
			}

			/* else { xchat_print( ph, "XSUB - 2 arg NULL chan" ); } */
			/* change server value only if it is true or 0 */
			/* otherwise leave it as NULL */
			if (SvTRUE (ST (1)) || SvNIOK (ST (1))) {
				server = SvPV_nolen (ST (1));
				/*                               xchat_printf( ph, "XSUB - find_context( NULL, %s )", SvPV_nolen(ST(1) )); */
			}
			/*  else { xchat_print( ph, "XSUB - 2 arg NULL server" ); } */
			break;
		}

		RETVAL = xchat_find_context (ph, server, chan);
		if (RETVAL != NULL) {
			/*                      xchat_print (ph, "XSUB - context found"); */
			XSRETURN_IV (PTR2IV (RETVAL));
		} else {
			/*           xchat_print (ph, "XSUB - context not found"); */
			XSRETURN_UNDEF;
		}
	}
}
Example #7
0
static void
tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata)
{
	GtkWidget *menu;
	GtkWidget *submenu;
	GtkWidget *item;
	int away_status;

	/* ph may have an invalid context now */
	xchat_set_context (ph, xchat_find_context (ph, NULL, NULL));

	menu = gtk_menu_new ();
	/*gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));*/

	if (tray_get_window_status () == WS_HIDDEN)
		tray_make_item (menu, _("_Restore Window"), tray_menu_restore_cb, NULL);
	else
		tray_make_item (menu, _("_Hide Window"), tray_menu_restore_cb, NULL);
	tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);

#ifndef WIN32 /* somehow this is broken on win32 */
	submenu = mg_submenu (menu, _("_Blink on"));
	blink_item (&prefs.input_tray_chans, submenu, _("Channel Message"));
	blink_item (&prefs.input_tray_priv, submenu, _("Private Message"));
	blink_item (&prefs.input_tray_hilight, submenu, _("Highlighted Message"));
	/*blink_item (BIT_FILEOFFER, submenu, _("File Offer"));*/

	submenu = mg_submenu (menu, _("_Change status"));
	away_status = tray_find_away_status ();
	item = tray_make_item (submenu, _("_Away"), tray_foreach_server, "away");
	if (away_status == 1)
		gtk_widget_set_sensitive (item, FALSE);
	item = tray_make_item (submenu, _("_Back"), tray_foreach_server, "back");
	if (away_status == 2)
		gtk_widget_set_sensitive (item, FALSE);

	tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);
#endif

	mg_create_icon_item (_("_Quit"), GTK_STOCK_QUIT, menu, tray_menu_quit_cb, NULL);

	menu_add_plugin_items (menu, "\x5$TRAY", NULL);

	g_object_ref (menu);
	g_object_ref_sink (menu);
	g_object_unref (menu);
	g_signal_connect (G_OBJECT (menu), "selection-done",
							G_CALLBACK (tray_menu_destroy), NULL);

	gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu,
						 userdata, button, time);
}
Example #8
0
gboolean
tray_toggle_visibility (gboolean force_hide)
{
	static int x, y;
	static GdkScreen *screen;
	GtkWindow *win;

	if (!sticon)
		return FALSE;

	/* ph may have an invalid context now */
	xchat_set_context (ph, xchat_find_context (ph, NULL, NULL));

	win = (GtkWindow *)xchat_get_info (ph, "win_ptr");

	tray_stop_flash ();
	tray_reset_counts ();

	if (!win)
		return FALSE;

#if GTK_CHECK_VERSION(2,20,0)
	if (force_hide || gtk_widget_get_visible (win))
#else
	if (force_hide || GTK_WIDGET_VISIBLE (win))
#endif
	{
		gtk_window_get_position (win, &x, &y);
		screen = gtk_window_get_screen (win);
		gtk_widget_hide (GTK_WIDGET (win));
	}
	else
	{
		gtk_window_set_screen (win, screen);
		gtk_window_move (win, x, y);
		gtk_widget_show (GTK_WIDGET (win));
		gtk_window_present (win);
	}

	return TRUE;
}