Exemple #1
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);
	}
}
Exemple #2
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));
}
static VALUE static_ruby_xchat_list_str( VALUE klass,
                                         VALUE list,
                                         VALUE name )
{
  xchat_list *x_list;
  char *str;
  char *s_name;

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

  str = (char*)xchat_list_str( static_plugin_handle, x_list, (const char*)s_name );
  if( str == NULL )
    return Qnil;

  return rb_str_new2( str );
}
Exemple #4
0
/* There is a cast in the interface to get a context from a pointer.
   To keep well typed, we do this cast explicitely here.
*/
const xchat_context * xchat_list_context (
	xchat_plugin *ph,
	xchat_list *xlist,
	const char *name
) { return (const xchat_context *) xchat_list_str(ph, xlist, name); }
Exemple #5
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;
}