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; }
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_get( VALUE klass, VALUE name ) { xchat_list *list; char *s_name; VALUE v_list; s_name = StringValueCStr( name ); list = xchat_list_get( static_plugin_handle, s_name ); if( list == NULL ) return Qnil; v_list = Data_Wrap_Struct( static_xchat_list_internal_klass, NULL, static_free_xchat_list, list ); return v_list; }
static XS (XS_Xchat_get_list) { SV *name; xchat_list *list; const char *const *fields; int count = 0; /* return value for scalar context */ dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::get_list(name)"); } else { SP -= items; /*remove the argument list from the stack */ name = ST (0); list = xchat_list_get (ph, SvPV_nolen (name)); if (list == NULL) { XSRETURN_EMPTY; } if (GIMME_V == G_SCALAR) { while (xchat_list_next (ph, list)) { count++; } xchat_list_free (ph, list); XSRETURN_IV ((IV) count); } fields = xchat_list_fields (ph, SvPV_nolen (name)); while (xchat_list_next (ph, list)) { XPUSHs (list_item_to_sv (list, fields)); } xchat_list_free (ph, list); PUTBACK; return; } }
/* * 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; }