Exemple #1
0
static int
num_open_dccs (void)
{
    xchat_list *list;
    int num = 0;

    list = xchat_list_get (ph, "dcc");
    if (!list)
        return 0;

    while (xchat_list_next (ph, list))
      {
          /* check only ACTIVE dccs */
          if (xchat_list_int (ph, list, "status") == 1)
            {
                /* check only SEND dccs */
                if (xchat_list_int (ph, list, "type") == 0)
                    num++;
            }
      }

    xchat_list_free (ph, list);

    return num;
}
Exemple #2
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);
	}
}
static VALUE static_ruby_xchat_list_int( VALUE klass,
                                         VALUE list,
                                         VALUE name )
{
  xchat_list *x_list;
  int rc;
  char *s_name;

  Data_Get_Struct( list, xchat_list, x_list );
  s_name = StringValueCStr( name );

  rc = xchat_list_int( static_plugin_handle, x_list, s_name );

  return INT2FIX( rc );
}
Exemple #4
0
static SV *
list_item_to_sv ( xchat_list *list, const char *const *fields )
{
	HV *hash = newHV();
	SV *field_value;
	const char *field;
	int field_index = 0;
	const char *field_name;
	int name_len;

	while (fields[field_index] != NULL) {
		field_name = fields[field_index] + 1;
		name_len = strlen (field_name);

		switch (fields[field_index][0]) {
		case 's':
			field = xchat_list_str (ph, list, field_name);
			if (field != NULL) {
				field_value = newSVpvn (field, strlen (field));
			} else {
				field_value = &PL_sv_undef;
			}
			break;
		case 'p':
			field_value = newSViv (PTR2IV (xchat_list_str (ph, list,
																	 field_name)));
			break;
		case 'i':
			field_value = newSVuv (xchat_list_int (ph, list, field_name));
			break;
		case 't':
			field_value = newSVnv (xchat_list_time (ph, list, field_name));
			break;
		default:
			field_value = &PL_sv_undef;
		}
		hv_store (hash, field_name, name_len, field_value, 0);
		field_index++;
	}
	return sv_2mortal (newRV_noinc ((SV *) hash));
}
Exemple #5
0
static int
printInfo (char *word[], char *word_eol[], void *user_data)
{
	/* query WMI info only at the first time WinSys is called, then cache it to save time */
	if (firstRun)
	{
		xchat_printf (ph, "%s first execution, querying and caching WMI info...\n", name);
		wmiOs = getWmiInfo (0);
		wmiCpu = getWmiInfo (1);
		wmiVga = getWmiInfo (2);
		firstRun = 0;
	}
	if (xchat_list_int (ph, NULL, "type") >= 2)
	{
		/* uptime will work correctly for up to 50 days, should be enough */
		xchat_commandf (ph, "ME ** WinSys ** Client: HexChat %s (x%d) ** OS: %s ** CPU: %s (%s) ** RAM: %s ** VGA: %s ** Uptime: %.2f Hours **",
			xchat_get_info (ph, "version"),
			getCpuArch (),
			wmiOs,
			wmiCpu,
			getCpuMhz (),
			getMemoryInfo (),
			wmiVga, (float) GetTickCount() / 1000 / 60 / 60);
	}
	else
	{
		xchat_printf (ph, " * Client:  HexChat %s (x%d)\n", xchat_get_info (ph, "version"), getCpuArch ());
		xchat_printf (ph, " * OS:      %s\n", wmiOs);
		xchat_printf (ph, " * CPU:     %s (%s)\n", wmiCpu, getCpuMhz ());
		xchat_printf (ph, " * RAM:     %s\n", getMemoryInfo ());
		xchat_printf (ph, " * VGA:     %s\n", wmiVga);
		xchat_printf (ph, " * Uptime:  %.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60);
	}

	return XCHAT_EAT_XCHAT;
}
Exemple #6
0
/* 
 * lua:  xchat.list_get(name)
 * desc: http://xchat.org/docs/plugin20.html#lists :)
 *       time_t values are stored as number => e.g.
 *         os.date("%Y-%m-%d, %H:%M:%S", time_t_value)
 *       pointers (channel -> context) as number... untested if this works
 * ret:  table with tables with all keys=Name, value=(Type)... or nil on error
 * args: 
 *       * name (string): the wanted list
 */
static int lxc_list_get(lua_State *L)
{
	const char *name          = luaL_checkstring(L, 1); 
	int i; /* item index */
	int l; /* list index */
	const char *str;
	double      num;
	time_t     date;
	long        ptr;
	const char *const *fields = xchat_list_fields(ph, name);
	xchat_list *list          = xchat_list_get(ph, name);

	if (!list) {
		lua_pushnil(L);
		return 1;
	}
	lua_newtable(L);
	/* this is like the perl plugin does it ;-) */
	l = 1;
	while (xchat_list_next(ph, list)) {
		i = 0;
		lua_pushnumber(L, l);
		lua_newtable(L);
		while (fields[i] != NULL) {
			switch (fields[i][0]) {
				case 's':
					str = xchat_list_str(ph, list, fields [i] + 1);
					lua_pushstring(L, fields[i]+1);
					if (str != NULL)
						lua_pushstring(L, str);
					else 
						lua_pushnil(L);
					lua_settable(L, -3);
					break;
				case 'p':
					ptr = (long)xchat_list_str(ph, list, fields [i] + 1);
					num = (double)ptr;
					lua_pushstring(L, fields[i]+1);
					lua_pushnumber(L, num);
					lua_settable(L, -3);
					break;
				case 'i':
					num = (double)xchat_list_int(ph, list, fields[i] + 1);
					lua_pushstring(L, fields[i]+1);
					lua_pushnumber(L, num);
					lua_settable(L, -3);
					break;
				case 't':
					date = xchat_list_time(ph, list, fields[i] + 1);
					lua_pushstring(L, fields[i]+1);
					lua_pushnumber(L, (double)date);
					lua_settable(L, -3);
					break;
			}
			i++;
		}
		lua_settable(L, -3);
		l++;
	}
	xchat_list_free(ph, list);
	return 1;
}