diff options
author | Emmanuel Bouthenot <kolter@openics.org> | 2006-01-31 13:54:27 +0000 |
---|---|---|
committer | Emmanuel Bouthenot <kolter@openics.org> | 2006-01-31 13:54:27 +0000 |
commit | f222a6ad7ae5a60a23efd7235eab70e90a1e8fdf (patch) | |
tree | ee4e364fb3cd51da2662f720c0f73208a14cd37b /src | |
parent | fe5731dc84bb00b330f6cbe9221089d7ae0e3dd1 (diff) | |
download | weechat-f222a6ad7ae5a60a23efd7235eab70e90a1e8fdf.zip |
extending plugins/scripts API by adding get_server_info, get_channel_info and get_nick_info
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/plugins-interface.c | 274 | ||||
-rw-r--r-- | src/plugins/plugins.c | 6 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl.c | 257 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 264 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 250 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 75 |
6 files changed, 1078 insertions, 48 deletions
diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c index 5d4312c00..6d131e844 100644 --- a/src/plugins/plugins-interface.c +++ b/src/plugins/plugins-interface.c @@ -662,3 +662,277 @@ weechat_plugin_set_plugin_config (t_weechat_plugin *plugin, char *option, char * } return 0; } + +/* + * weechat_plugin_get_server_info: get list of server info + */ + +t_plugin_server_info * +weechat_plugin_get_server_info (t_weechat_plugin *plugin) +{ + t_plugin_server_info *server_info, *last_server_info, *new_server_info; + t_irc_server *ptr_server; + + if (!plugin) + return NULL; + + if (irc_servers) + { + server_info = NULL; + last_server_info = NULL; + for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) + { + new_server_info = (t_plugin_server_info *) malloc (sizeof (t_plugin_server_info)); + if (new_server_info) + { + new_server_info->name = (ptr_server->name) ? strdup (ptr_server->name) : strdup (""); + new_server_info->autoconnect = ptr_server->autoconnect; + new_server_info->autoreconnect = ptr_server->autoreconnect; + new_server_info->autoreconnect_delay = ptr_server->autoreconnect_delay; + new_server_info->command_line = ptr_server->command_line; + new_server_info->address = (ptr_server->address) ? strdup (ptr_server->address) : strdup (""); + new_server_info->port = ptr_server->port; + new_server_info->ipv6 = ptr_server->ipv6; + new_server_info->ssl = ptr_server->ssl; + new_server_info->password = (ptr_server->password) ? strdup (ptr_server->password) : strdup (""); + new_server_info->nick1 = (ptr_server->nick1) ? strdup (ptr_server->nick1) : strdup (""); + new_server_info->nick2 = (ptr_server->nick2) ? strdup (ptr_server->nick2) : strdup (""); + new_server_info->nick3 = (ptr_server->nick3) ? strdup (ptr_server->nick3) : strdup (""); + new_server_info->username = (ptr_server->username) ? strdup (ptr_server->username) : strdup (""); + new_server_info->realname = (ptr_server->realname) ? strdup (ptr_server->realname) : strdup (""); + new_server_info->command = (ptr_server->command) ? strdup (ptr_server->command) : strdup (""); + new_server_info->command_delay = ptr_server->command_delay; + new_server_info->autojoin = (ptr_server->autojoin) ? strdup (ptr_server->autojoin) : strdup (""); + new_server_info->autorejoin = ptr_server->autorejoin; + new_server_info->notify_levels = (ptr_server->notify_levels) ? strdup (ptr_server->notify_levels) : strdup (""); + new_server_info->charset_decode_iso = (ptr_server->charset_decode_iso) ? strdup (ptr_server->charset_decode_iso) : strdup (""); + new_server_info->charset_decode_utf = (ptr_server->charset_decode_utf) ? strdup (ptr_server->charset_decode_utf) : strdup (""); + new_server_info->charset_encode = (ptr_server->charset_encode) ? strdup (ptr_server->charset_encode) : strdup (""); + new_server_info->is_connected = ptr_server->is_connected; + new_server_info->ssl_connected = ptr_server->ssl_connected; + new_server_info->nick = (ptr_server->nick) ? strdup (ptr_server->nick) : strdup (""); + new_server_info->is_away = ptr_server->is_away; + new_server_info->away_time = ptr_server->away_time; + new_server_info->lag = ptr_server->lag; + + new_server_info->prev_info = last_server_info; + new_server_info->next_info = NULL; + if (!server_info) + server_info = new_server_info; + else + last_server_info->next_info = new_server_info; + last_server_info = new_server_info; + } + } + + return server_info; + } + + return NULL; +} + +/* + * weechat_plugin_free_server_info: free server info struct list + */ + +void +weechat_plugin_free_server_info (t_weechat_plugin *plugin, t_plugin_server_info *server_info) +{ + t_plugin_server_info *new_server_info; + + if (!plugin || !server_info) + return; + + while (server_info) + { + if (server_info->name) + free (server_info->name); + if (server_info->address) + free (server_info->address); + if (server_info->password) + free (server_info->password); + if (server_info->nick1) + free (server_info->nick1); + if (server_info->nick2) + free (server_info->nick2); + if (server_info->nick3) + free (server_info->nick3); + if (server_info->username) + free (server_info->username); + if (server_info->realname) + free (server_info->realname); + if (server_info->command) + free (server_info->command); + if (server_info->autojoin) + free (server_info->autojoin); + if (server_info->notify_levels) + free (server_info->notify_levels); + if (server_info->charset_decode_iso) + free (server_info->charset_decode_iso); + if (server_info->charset_decode_utf) + free (server_info->charset_decode_utf); + if (server_info->charset_encode) + free (server_info->charset_encode); + if (server_info->nick) + free (server_info->nick); + new_server_info = server_info->next_info; + free (server_info); + server_info = new_server_info; + } +} + +/* + * weechat_plugin_get_channel_info: get list of channel info from a server + */ + +t_plugin_channel_info * +weechat_plugin_get_channel_info (t_weechat_plugin *plugin, char *server) +{ + t_plugin_channel_info *channel_info, *last_channel_info, *new_channel_info; + t_irc_channel *ptr_channel, *ptr_channels; + t_irc_server *ptr_server; + + if (!plugin || !server || !server[0]) + return NULL; + + ptr_server = server_search (server); + if (!ptr_server) + return NULL; + + ptr_channels = ptr_server->channels; + + if (ptr_channels) + { + channel_info = NULL; + last_channel_info = NULL; + for (ptr_channel = ptr_channels; ptr_channel; ptr_channel = ptr_channel->next_channel) + { + new_channel_info = (t_plugin_channel_info *) malloc (sizeof (t_plugin_channel_info)); + if (new_channel_info) + { + new_channel_info->type = ptr_channel->type; + new_channel_info->name = (ptr_channel->name) ? strdup (ptr_channel->name) : strdup (""); + new_channel_info->topic = (ptr_channel->topic) ? strdup (ptr_channel->topic) : strdup (""); + new_channel_info->modes = (ptr_channel->modes) ? strdup (ptr_channel->modes) : strdup (""); + new_channel_info->limit = ptr_channel->limit; + new_channel_info->key = (ptr_channel->key) ? strdup (ptr_channel->key) : strdup (""); + new_channel_info->nicks_count = ptr_channel->nicks_count; + + new_channel_info->prev_info = last_channel_info; + new_channel_info->next_info = NULL; + if (!channel_info) + channel_info = new_channel_info; + else + last_channel_info->next_info = new_channel_info; + last_channel_info = new_channel_info; + } + } + + return channel_info; + } + + return NULL; +} + +/* + * weechat_plugin_free_channel_info: free channel info struct list + */ + +void +weechat_plugin_free_channel_info (t_weechat_plugin *plugin, t_plugin_channel_info *channel_info) +{ + t_plugin_channel_info *new_channel_info; + + if (!plugin || !channel_info) + return; + + while (channel_info) + { + if (channel_info->name) + free (channel_info->name); + if (channel_info->topic) + free (channel_info->topic); + if (channel_info->modes) + free (channel_info->modes); + if (channel_info->key) + free (channel_info->key); + new_channel_info = channel_info->next_info; + free (channel_info); + channel_info = new_channel_info; + } +} + +/* + * weechat_plugin_get_nick_info: get list of nick info from a server/channel + */ + +t_plugin_nick_info * +weechat_plugin_get_nick_info (t_weechat_plugin *plugin, char *server, char *channel) +{ + t_plugin_nick_info *nick_info, *last_nick_info, *new_nick_info; + t_irc_nick *ptr_nick, *ptr_nicks; + t_irc_channel *ptr_channel; + t_irc_server *ptr_server; + + if (!plugin || !server || !server[0] || !channel || !channel[0]) + return NULL; + + ptr_server = server_search (server); + if (!ptr_server) + return NULL; + + ptr_channel = channel_search (ptr_server, channel); + if (!ptr_channel) + return NULL; + + ptr_nicks = ptr_channel->nicks; + + if (ptr_nicks) + { + nick_info = NULL; + last_nick_info = NULL; + for (ptr_nick = ptr_nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + new_nick_info = (t_plugin_nick_info *) malloc (sizeof (t_plugin_nick_info)); + if (new_nick_info) + { + new_nick_info->nick = (ptr_nick->nick) ? strdup (ptr_nick->nick) : strdup (""); + new_nick_info->flags = ptr_nick->flags; + + new_nick_info->prev_nick = last_nick_info; + new_nick_info->next_nick = NULL; + if (!nick_info) + nick_info = new_nick_info; + else + last_nick_info->next_nick = new_nick_info; + last_nick_info = new_nick_info; + } + } + + return nick_info; + } + + return NULL; +} + +/* + * weechat_plugin_free_nick_info: free nick info struct list + */ + +void +weechat_plugin_free_nick_info (t_weechat_plugin *plugin, t_plugin_nick_info *nick_info) +{ + t_plugin_nick_info *new_nick_info; + + if (!plugin || !nick_info) + return; + + while (nick_info) + { + if (nick_info->nick) + free (nick_info->nick); + new_nick_info = nick_info->next_nick; + free (nick_info); + nick_info = new_nick_info; + } +} diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 41d8eb9bc..bd09f23bd 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -633,6 +633,12 @@ plugin_load (char *filename) new_plugin->set_config = &weechat_plugin_set_config; new_plugin->get_plugin_config = &weechat_plugin_get_plugin_config; new_plugin->set_plugin_config = &weechat_plugin_set_plugin_config; + new_plugin->get_server_info = &weechat_plugin_get_server_info; + new_plugin->free_server_info = &weechat_plugin_free_server_info; + new_plugin->get_channel_info = &weechat_plugin_get_channel_info; + new_plugin->free_channel_info = &weechat_plugin_free_channel_info; + new_plugin->get_nick_info = &weechat_plugin_get_nick_info; + new_plugin->free_nick_info = &weechat_plugin_free_nick_info; /* handlers */ new_plugin->handlers = NULL; diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index b61d38031..e30eb6491 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -563,8 +563,8 @@ static XS (XS_weechat_get_info) static XS (XS_weechat_get_dcc_info) { - t_plugin_dcc_info *dcc_info, *ptr_dcc; - int dcc_count; + t_plugin_dcc_info *dcc_info, *ptr_dcc; + int count; char timebuffer1[64]; char timebuffer2[64]; struct in_addr in; @@ -579,14 +579,13 @@ static XS (XS_weechat_get_dcc_info) perl_plugin->printf_server (perl_plugin, "Perl error: unable to get DCC info, " "script not initialized"); - XSRETURN_NO; + XSRETURN_EMPTY; } - + dcc_info = perl_plugin->get_dcc_info (perl_plugin); - dcc_count = 0; - + count = 0; if (!dcc_info) - XSRETURN_NO; + XSRETURN_EMPTY; for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) { @@ -596,32 +595,31 @@ static XS (XS_weechat_get_dcc_info) localtime(&ptr_dcc->start_transfer)); in.s_addr = htonl(ptr_dcc->addr); - HV *infohash = (HV *) sv_2mortal((SV *) newHV()); + HV *dcc_hash_member = (HV *) sv_2mortal ((SV *) newHV()); - hv_store (infohash, "server", 6, newSVpv (ptr_dcc->server, 0), 0); - hv_store (infohash, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0); - hv_store (infohash, "type", 4, newSViv (ptr_dcc->type), 0); - hv_store (infohash, "status", 6, newSViv (ptr_dcc->status), 0); - hv_store (infohash, "start_time", 10, newSVpv (timebuffer1, 0), 0); - hv_store (infohash, "start_transfer", 14, newSVpv (timebuffer2, 0), 0); - hv_store (infohash, "address", 7, newSVpv (inet_ntoa(in), 0), 0); - hv_store (infohash, "port", 4, newSViv (ptr_dcc->port), 0); - hv_store (infohash, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0); - hv_store (infohash, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0); - hv_store (infohash, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0); - hv_store (infohash, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0); - hv_store (infohash, "size", 4, newSVnv (ptr_dcc->size), 0); - hv_store (infohash, "pos", 3, newSVnv (ptr_dcc->pos), 0); - hv_store (infohash, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0); - hv_store (infohash, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0); + hv_store (dcc_hash_member, "server", 6, newSVpv (ptr_dcc->server, 0), 0); + hv_store (dcc_hash_member, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0); + hv_store (dcc_hash_member, "type", 4, newSViv (ptr_dcc->type), 0); + hv_store (dcc_hash_member, "status", 6, newSViv (ptr_dcc->status), 0); + hv_store (dcc_hash_member, "start_time", 10, newSVpv (timebuffer1, 0), 0); + hv_store (dcc_hash_member, "start_transfer", 14, newSVpv (timebuffer2, 0), 0); + hv_store (dcc_hash_member, "address", 7, newSVpv (inet_ntoa(in), 0), 0); + hv_store (dcc_hash_member, "port", 4, newSViv (ptr_dcc->port), 0); + hv_store (dcc_hash_member, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0); + hv_store (dcc_hash_member, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0); + hv_store (dcc_hash_member, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0); + hv_store (dcc_hash_member, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0); + hv_store (dcc_hash_member, "size", 4, newSVnv (ptr_dcc->size), 0); + hv_store (dcc_hash_member, "pos", 3, newSVnv (ptr_dcc->pos), 0); + hv_store (dcc_hash_member, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0); + hv_store (dcc_hash_member, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0); - XPUSHs(newRV((SV *) infohash)); - dcc_count++; + XPUSHs(newRV_inc((SV *) dcc_hash_member)); + count++; } + perl_plugin->free_dcc_info (perl_plugin, dcc_info); - perl_plugin->free_dcc_info (perl_plugin, dcc_info); - - XSRETURN (dcc_count); + XSRETURN (count); } /* @@ -805,6 +803,204 @@ static XS (XS_weechat_set_plugin_config) } /* + * weechat::get_server_info: get infos about servers + */ + +static XS (XS_weechat_get_server_info) +{ + t_plugin_server_info *server_info, *ptr_server; + char timebuffer[64]; + dXSARGS; + + /* make gcc happy */ + (void) cv; + (void) items; + + if (!perl_current_script) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: unable to get server info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + server_info = perl_plugin->get_server_info (perl_plugin); + if (!server_info) { + XSRETURN_EMPTY; + } + + + HV *server_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!server_hash) + XSRETURN_EMPTY; + + for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_info) + { + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_server->away_time)); + + HV *server_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (server_hash_member, "autoconnect", 11, newSViv (ptr_server->autoconnect), 0); + hv_store (server_hash_member, "autoreconnect", 13, newSViv (ptr_server->autoreconnect), 0); + hv_store (server_hash_member, "autoreconnect_delay", 19, newSViv (ptr_server->autoreconnect_delay), 0); + hv_store (server_hash_member, "command_line", 12, newSViv (ptr_server->command_line), 0); + hv_store (server_hash_member, "address", 7, newSVpv (ptr_server->address, 0), 0); + hv_store (server_hash_member, "port", 4, newSViv (ptr_server->port), 0); + hv_store (server_hash_member, "ipv6", 4, newSViv (ptr_server->ipv6), 0); + hv_store (server_hash_member, "ssl", 3, newSViv (ptr_server->ssl), 0); + hv_store (server_hash_member, "password", 8, newSVpv (ptr_server->password, 0), 0); + hv_store (server_hash_member, "nick1", 5, newSVpv (ptr_server->nick1, 0), 0); + hv_store (server_hash_member, "nick2", 5, newSVpv (ptr_server->nick2, 0), 0); + hv_store (server_hash_member, "nick3", 5, newSVpv (ptr_server->nick3, 0), 0); + hv_store (server_hash_member, "username", 8, newSVpv (ptr_server->username, 0), 0); + hv_store (server_hash_member, "realname", 8, newSVpv (ptr_server->realname, 0), 0); + hv_store (server_hash_member, "command", 7, newSVpv (ptr_server->command, 0), 0); + hv_store (server_hash_member, "command_delay", 13, newSViv (ptr_server->command_delay), 0); + hv_store (server_hash_member, "autojoin", 8, newSVpv (ptr_server->autojoin, 0), 0); + hv_store (server_hash_member, "autorejoin", 10, newSViv (ptr_server->autorejoin), 0); + hv_store (server_hash_member, "notify_levels", 13, newSVpv (ptr_server->notify_levels, 0), 0); + hv_store (server_hash_member, "charset_decode_iso", 18, newSVpv (ptr_server->charset_decode_iso, 0), 0); + hv_store (server_hash_member, "charset_decode_utf", 18, newSVpv (ptr_server->charset_decode_utf, 0), 0); + hv_store (server_hash_member, "charset_encode", 14, newSVpv (ptr_server->charset_encode, 0), 0); + hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0); + hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0); + hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0); + hv_store (server_hash_member, "away_time", 9, newSVpv (timebuffer, 0), 0); + hv_store (server_hash_member, "lag", 3, newSViv (ptr_server->lag), 0); + + hv_store (server_hash, ptr_server->name, strlen(ptr_server->name), newRV_inc((SV *) server_hash_member), 0); + } + perl_plugin->free_server_info (perl_plugin, server_info); + + //XPUSHs(newRV_inc((SV *) server_hash)); + ST (0) = newRV_inc((SV *) server_hash); + XSRETURN (1); +} + +/* + * weechat::get_channel_info: get infos about channels + */ + +static XS (XS_weechat_get_channel_info) +{ + t_plugin_channel_info *channel_info, *ptr_channel; + char *server; + unsigned int integer; + dXSARGS; + + /* make gcc happy */ + (void) cv; + + if (!perl_current_script) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: unable to get channel info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items != 1) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: wrong parameters for " + "\"get_channel_info\" function"); + XSRETURN_EMPTY; + } + + server = SvPV (ST (0), integer); + if (!server) + XSRETURN_EMPTY; + + channel_info = perl_plugin->get_channel_info (perl_plugin, server); + if (!channel_info) { + XSRETURN_EMPTY; + } + + HV *channel_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!channel_hash) + XSRETURN_EMPTY; + + for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_info) + { + HV *channel_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (channel_hash_member, "type", 4, newSViv (ptr_channel->type), 0); + hv_store (channel_hash_member, "topic", 5, newSVpv (ptr_channel->topic, 0), 0); + hv_store (channel_hash_member, "modes", 5, newSVpv (ptr_channel->modes, 0), 0); + hv_store (channel_hash_member, "limit", 5, newSViv (ptr_channel->limit), 0); + hv_store (channel_hash_member, "key", 3, newSVpv (ptr_channel->key, 0), 0); + hv_store (channel_hash_member, "nicks_count", 11, newSViv (ptr_channel->nicks_count), 0); + + hv_store (channel_hash, ptr_channel->name, strlen(ptr_channel->name), newRV_inc((SV *) channel_hash_member), 0); + } + perl_plugin->free_channel_info (perl_plugin, channel_info); + + //XPUSHs(newRV_inc((SV *) channel_hash)); + ST (0) = newRV_inc((SV *) channel_hash); + XSRETURN (1); +} + +/* + * weechat::get_nick_info: get infos about nicks + */ + +static XS (XS_weechat_get_nick_info) +{ + t_plugin_nick_info *nick_info, *ptr_nick; + char *server, *channel; + unsigned int integer; + dXSARGS; + + /* make gcc happy */ + (void) cv; + + if (!perl_current_script) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: unable to get nick info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items != 2) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: wrong parameters for " + "\"get_nick_info\" function"); + XSRETURN_EMPTY; + } + + server = SvPV (ST (0), integer); + channel = SvPV (ST (1), integer); + if (!server || !channel) + XSRETURN_EMPTY; + + nick_info = perl_plugin->get_nick_info (perl_plugin, server, channel); + if (!nick_info) { + XSRETURN_EMPTY; + } + + HV *nick_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!nick_hash) + XSRETURN_EMPTY; + + for (ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + HV *nick_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (nick_hash_member, "flags", 5, newSViv (ptr_nick->flags), 0); + + hv_store (nick_hash, ptr_nick->nick, strlen(ptr_nick->nick), newRV_inc((SV *) nick_hash_member), 0); + } + perl_plugin->free_nick_info (perl_plugin, nick_info); + + //XPUSHs(newRV_inc((SV *) nick_hash)); + ST (0) = newRV_inc((SV *) nick_hash); + XSRETURN (1); +} + +/* * weechat_perl_xs_init: initialize subroutines */ @@ -829,6 +1025,9 @@ weechat_perl_xs_init (pTHX) newXS ("weechat::set_config", XS_weechat_set_config, "weechat"); newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat"); newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat"); + newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat"); + newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat"); + newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat"); /* interface constants */ stash = gv_stashpv ("weechat", TRUE); diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index a62ae57a5..7ebc55a48 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -110,7 +110,7 @@ weechat_python_handler (t_weechat_plugin *plugin, } /* - * weechat.register: startup function for all WeeChat Python scripts + * weechat_python_register: startup function for all WeeChat Python scripts */ static PyObject * @@ -172,7 +172,7 @@ weechat_python_register (PyObject *self, PyObject *args) } /* - * weechat.print: print message into a buffer (current or specified one) + * weechat_python_print: print message into a buffer (current or specified one) */ static PyObject * @@ -211,7 +211,7 @@ weechat_python_print (PyObject *self, PyObject *args) } /* - * weechat.print_infobar: print message to infobar + * weechat_python_print_infobar: print message to infobar */ static PyObject * @@ -248,7 +248,7 @@ weechat_python_print_infobar (PyObject *self, PyObject *args) } /* - * weechat.command: send command to server + * weechat_python_command: send command to server */ static PyObject * @@ -287,7 +287,7 @@ weechat_python_command (PyObject *self, PyObject *args) } /* - * weechat.add_message_handler: add handler for messages + * weechat_python_add_message_handler: add handler for messages */ static PyObject * @@ -326,7 +326,7 @@ weechat_python_add_message_handler (PyObject *self, PyObject *args) } /* - * weechat.add_command_handler: define/redefines commands + * weechat_python_add_command_handler: define/redefines commands */ static PyObject * @@ -378,7 +378,7 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args) } /* - * weechat.remove_handler: remove a handler + * weechat_python_remove_handler: remove a handler */ static PyObject * @@ -415,7 +415,7 @@ weechat_python_remove_handler (PyObject *self, PyObject *args) } /* - * weechat.get_info: get various infos + * weechat_python_get_info: get various infos */ static PyObject * @@ -462,15 +462,14 @@ weechat_python_get_info (PyObject *self, PyObject *args) } /* - * weechat.get_dcc_info: get infos about DCC + * weechat_python_get_dcc_info: get infos about DCC */ static PyObject * weechat_python_get_dcc_info (PyObject *self, PyObject *args) { t_plugin_dcc_info *dcc_info, *ptr_dcc; - PyObject *dcc_list; - PyObject *dcc_list_member; + PyObject *dcc_list, *dcc_list_member; char timebuffer1[64]; char timebuffer2[64]; struct in_addr in; @@ -487,8 +486,7 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args) return Py_None; } - dcc_list = PyList_New (0); - + dcc_list = PyList_New (0); if (!dcc_list) return Py_None; @@ -565,7 +563,7 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args) } /* - * weechat.get_config: get value of a WeeChat config option + * weechat_python_get_config: get value of a WeeChat config option */ static PyObject * @@ -611,7 +609,7 @@ weechat_python_get_config (PyObject *self, PyObject *args) } /* - * weechat.set_config: set value of a WeeChat config option + * weechat_python_set_config: set value of a WeeChat config option */ static PyObject * @@ -651,7 +649,7 @@ weechat_python_set_config (PyObject *self, PyObject *args) } /* - * weechat.get_plugin_config: get value of a plugin config option + * weechat_python_get_plugin_config: get value of a plugin config option */ static PyObject * @@ -699,7 +697,7 @@ weechat_python_get_plugin_config (PyObject *self, PyObject *args) } /* - * weechat.set_plugin_config: set value of a plugin config option + * weechat_python_set_plugin_config: set value of a plugin config option */ static PyObject * @@ -741,6 +739,235 @@ weechat_python_set_plugin_config (PyObject *self, PyObject *args) } /* + * weechat_python_get_server_info: get infos about servers + */ + +static PyObject * +weechat_python_get_server_info (PyObject *self, PyObject *args) +{ + t_plugin_server_info *server_info, *ptr_server; + PyObject *server_hash, *server_hash_member; + char timebuffer[64]; + + /* make gcc happy */ + (void) self; + (void) args; + + if (!python_current_script) + { + python_plugin->printf_server (python_plugin, + "Python error: unable to get server infos, " + "script not initialized"); + return Py_BuildValue ("i", 0); + } + + server_hash = PyDict_New (); + if (!server_hash) + return Py_None; + + server_info = python_plugin->get_server_info (python_plugin); + if (!server_info) + return server_hash; + + for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_info) + { + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_server->away_time)); + + server_hash_member = PyDict_New(); + + if (server_hash_member) + { + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "autoconnect"), + Py_BuildValue("i", ptr_server->autoconnect)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "autoreconnect"), + Py_BuildValue("i", ptr_server->autoreconnect)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "autoreconnect_delay"), + Py_BuildValue("i", ptr_server->autoreconnect_delay)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "command_line"), + Py_BuildValue("i", ptr_server->command_line)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "address"), + Py_BuildValue("s", ptr_server->address)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "port"), + Py_BuildValue("i", ptr_server->port)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "ipv6"), + Py_BuildValue("i", ptr_server->ipv6)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "ssl"), + Py_BuildValue("i", ptr_server->ssl)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "password"), + Py_BuildValue("s", ptr_server->password)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick1"), + Py_BuildValue("s", ptr_server->nick1)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick2"), + Py_BuildValue("s", ptr_server->nick2)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick3"), + Py_BuildValue("s", ptr_server->nick3)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "username"), + Py_BuildValue("s", ptr_server->username)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "realname"), + Py_BuildValue("s", ptr_server->realname)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "command"), + Py_BuildValue("s", ptr_server->command)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "command_delay"), + Py_BuildValue("i", ptr_server->command_delay)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "autojoin"), + Py_BuildValue("s", ptr_server->autojoin)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "autorejoin"), + Py_BuildValue("i", ptr_server->autorejoin)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "notify_levels"), + Py_BuildValue("s", ptr_server->notify_levels)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_decode_iso"), + Py_BuildValue("s", ptr_server->charset_decode_iso)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_decode_utf"), + Py_BuildValue("s", ptr_server->charset_decode_utf)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_encode"), + Py_BuildValue("s", ptr_server->charset_encode)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "is_connected"), + Py_BuildValue("i", ptr_server->is_connected)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "ssl_connected"), + Py_BuildValue("i", ptr_server->ssl_connected)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick"), + Py_BuildValue("s", ptr_server->nick)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "away_time"), + Py_BuildValue("s", timebuffer)); + PyDict_SetItem(server_hash_member, Py_BuildValue("s", "lag"), + Py_BuildValue("i", ptr_server->lag)); + + PyDict_SetItem(server_hash, Py_BuildValue("s", ptr_server->name), server_hash_member); + } + } + + python_plugin->free_server_info(python_plugin, server_info); + + return server_hash; +} + +/* + * weechat_python_get_channel_info: get infos about channels + */ + +static PyObject * +weechat_python_get_channel_info (PyObject *self, PyObject *args) +{ + t_plugin_channel_info *channel_info, *ptr_channel; + PyObject *channel_hash, *channel_hash_member; + char *server; + + /* make gcc happy */ + (void) self; + + if (!python_current_script) + { + python_plugin->printf_server (python_plugin, + "Python error: unable to get channel infos, " + "script not initialized"); + return Py_BuildValue ("i", 0); + } + + server = NULL; + if (!PyArg_ParseTuple (args, "s", &server)) + { + python_plugin->printf_server (python_plugin, + "Python error: wrong parameters for " + "\"get_channel_info\" function"); + return Py_BuildValue ("i", 0); + } + + channel_hash = PyDict_New (); + if (!channel_hash) + return Py_None; + + channel_info = python_plugin->get_channel_info (python_plugin, server); + if (!channel_info) + return channel_hash; + + for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_info) + { + channel_hash_member = PyDict_New(); + + if (channel_hash_member) + { + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "type"), + Py_BuildValue("i", ptr_channel->type)); + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "topic"), + Py_BuildValue("s", ptr_channel->topic)); + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "modes"), + Py_BuildValue("s", ptr_channel->modes)); + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "limit"), + Py_BuildValue("i", ptr_channel->limit)); + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "key"), + Py_BuildValue("s", ptr_channel->key)); + PyDict_SetItem(channel_hash_member, Py_BuildValue("s", "nicks_count"), + Py_BuildValue("i", ptr_channel->nicks_count)); + + PyDict_SetItem(channel_hash, Py_BuildValue("s", ptr_channel->name), channel_hash_member); + } + } + + python_plugin->free_channel_info(python_plugin, channel_info); + + return channel_hash; +} + +/* + * weechat_python_get_nick_info: get infos about nicks + */ + +static PyObject * +weechat_python_get_nick_info (PyObject *self, PyObject *args) +{ + t_plugin_nick_info *nick_info, *ptr_nick; + PyObject *nick_hash, *nick_hash_member; + char *server, *channel; + + /* make gcc happy */ + (void) self; + + if (!python_current_script) + { + python_plugin->printf_server (python_plugin, + "Python error: unable to get nick infos, " + "script not initialized"); + return Py_BuildValue ("i", 0); + } + + server = NULL; + channel = NULL; + if (!PyArg_ParseTuple (args, "ss", &server, &channel)) + { + python_plugin->printf_server (python_plugin, + "Python error: wrong parameters for " + "\"get_nick_info\" function"); + return Py_BuildValue ("i", 0); + } + + nick_hash = PyDict_New (); + if (!nick_hash) + return Py_None; + + nick_info = python_plugin->get_nick_info (python_plugin, server, channel); + if (!nick_info) + return nick_hash; + + for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + nick_hash_member = PyDict_New(); + + if (nick_hash_member) + { + PyDict_SetItem(nick_hash_member, Py_BuildValue("s", "flags"), + Py_BuildValue("i", ptr_nick->flags)); + + PyDict_SetItem(nick_hash, Py_BuildValue("s", ptr_nick->nick), nick_hash_member); + } + } + + python_plugin->free_nick_info(python_plugin, nick_info); + + return nick_hash; +} + +/* * Python subroutines */ @@ -759,6 +986,9 @@ PyMethodDef weechat_python_funcs[] = { { "set_config", weechat_python_set_config, METH_VARARGS, "" }, { "get_plugin_config", weechat_python_get_plugin_config, METH_VARARGS, "" }, { "set_plugin_config", weechat_python_set_plugin_config, METH_VARARGS, "" }, + { "get_server_info", weechat_python_get_server_info, METH_VARARGS, "" }, + { "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" }, + { "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" }, { NULL, NULL, 0, NULL } }; diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index b251f2981..60b22141a 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -441,7 +441,7 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function) } /* - * weechat_add_command_handler: define/redefines commands + * weechat_ruby_add_command_handler: define/redefines commands */ static VALUE @@ -531,7 +531,7 @@ weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class) } /* - * weechat_remove_handler: remove a handler + * weechat_ruby_remove_handler: remove a handler */ static VALUE @@ -927,6 +927,249 @@ weechat_ruby_set_plugin_config (VALUE class, VALUE option, VALUE value) } /* + * weechat_ruby_get_server_info: get infos about servers + */ + +static VALUE +weechat_ruby_get_server_info (VALUE class) +{ + t_plugin_server_info *server_info, *ptr_server; + VALUE server_hash, server_hash_member; + char timebuffer[64]; + + /* make gcc happy */ + (void) class; + + if (!ruby_current_script) + { + ruby_plugin->printf_server (ruby_plugin, + "Ruby error: unable to get server infos, " + "script not initialized"); + return INT2FIX (0); + } + + server_hash = rb_hash_new (); + if (!server_hash) + return Qnil; + + server_info = ruby_plugin->get_server_info (ruby_plugin); + if (!server_info) + return server_hash; + + for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_info) + { + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_server->away_time)); + + server_hash_member = rb_hash_new (); + + if (server_hash_member) + { + rb_hash_aset (server_hash_member, rb_str_new2("autoconnect"), + INT2FIX(ptr_server->autoconnect)); + rb_hash_aset (server_hash_member, rb_str_new2("autoreconnect"), + INT2FIX(ptr_server->autoreconnect)); + rb_hash_aset (server_hash_member, rb_str_new2("autoreconnect_delay"), + INT2FIX(ptr_server->autoreconnect_delay)); + rb_hash_aset (server_hash_member, rb_str_new2("command_line"), + INT2FIX(ptr_server->command_line)); + rb_hash_aset (server_hash_member, rb_str_new2("address"), + rb_str_new2(ptr_server->address)); + rb_hash_aset (server_hash_member, rb_str_new2("port"), + INT2FIX(ptr_server->port)); + rb_hash_aset (server_hash_member, rb_str_new2("ipv6"), + INT2FIX(ptr_server->ipv6)); + rb_hash_aset (server_hash_member, rb_str_new2("ssl"), + INT2FIX(ptr_server->ssl)); + rb_hash_aset (server_hash_member, rb_str_new2("password"), + rb_str_new2(ptr_server->password)); + rb_hash_aset (server_hash_member, rb_str_new2("nick1"), + rb_str_new2(ptr_server->nick1)); + rb_hash_aset (server_hash_member, rb_str_new2("nick2"), + rb_str_new2(ptr_server->nick2)); + rb_hash_aset (server_hash_member, rb_str_new2("nick3"), + rb_str_new2(ptr_server->nick3)); + rb_hash_aset (server_hash_member, rb_str_new2("username"), + rb_str_new2(ptr_server->username)); + rb_hash_aset (server_hash_member, rb_str_new2("realname"), + rb_str_new2(ptr_server->realname)); + rb_hash_aset (server_hash_member, rb_str_new2("command"), + rb_str_new2(ptr_server->command)); + rb_hash_aset (server_hash_member, rb_str_new2("command_delay"), + INT2FIX(ptr_server->command_delay)); + rb_hash_aset (server_hash_member, rb_str_new2("autojoin"), + rb_str_new2(ptr_server->autojoin)); + rb_hash_aset (server_hash_member, rb_str_new2("autorejoin"), + INT2FIX(ptr_server->autorejoin)); + rb_hash_aset (server_hash_member, rb_str_new2("notify_levels"), + rb_str_new2(ptr_server->notify_levels)); + rb_hash_aset (server_hash_member, rb_str_new2("charset_decode_iso"), + rb_str_new2(ptr_server->charset_decode_iso)); + rb_hash_aset (server_hash_member, rb_str_new2("charset_decode_utf"), + rb_str_new2(ptr_server->charset_decode_utf)); + rb_hash_aset (server_hash_member, rb_str_new2("charset_encode"), + rb_str_new2(ptr_server->charset_encode)); + rb_hash_aset (server_hash_member, rb_str_new2("is_connected"), + INT2FIX(ptr_server->is_connected)); + rb_hash_aset (server_hash_member, rb_str_new2("ssl_connected"), + INT2FIX(ptr_server->ssl_connected)); + rb_hash_aset (server_hash_member, rb_str_new2("nick"), + rb_str_new2(ptr_server->nick)); + rb_hash_aset (server_hash_member, rb_str_new2("away_time"), + rb_str_new2(timebuffer)); + rb_hash_aset (server_hash_member, rb_str_new2("lag"), + INT2FIX(ptr_server->lag)); + + rb_hash_aset (server_hash, rb_str_new2(ptr_server->name), server_hash_member); + } + } + + ruby_plugin->free_server_info(ruby_plugin, server_info); + + return server_hash; +} + +/* + * weechat_ruby_get_channel_info: get infos about channels + */ + +static VALUE +weechat_ruby_get_channel_info (VALUE class, VALUE server) +{ + t_plugin_channel_info *channel_info, *ptr_channel; + VALUE channel_hash, channel_hash_member; + char *c_server; + + /* make gcc happy */ + (void) class; + + if (!ruby_current_script) + { + ruby_plugin->printf_server (ruby_plugin, + "Ruby error: unable to get channel infos, " + "script not initialized"); + return INT2FIX (0); + } + + c_server = NULL; + if (NIL_P (server)) + { + ruby_plugin->printf_server (ruby_plugin, + "Ruby error: wrong parameters for " + "\"get_channel_info\" function"); + return INT2FIX (0); + } + + Check_Type (server, T_STRING); + c_server = STR2CSTR (server); + + if (!c_server) + return INT2FIX (0); + + channel_hash = rb_hash_new (); + if (!channel_hash) + return Qnil; + + channel_info = ruby_plugin->get_channel_info (ruby_plugin, c_server); + if (!channel_info) + return channel_hash; + + for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_info) + { + channel_hash_member = rb_hash_new (); + + if (channel_hash_member) + { + rb_hash_aset (channel_hash_member, rb_str_new2("type"), + INT2FIX(ptr_channel->type)); + rb_hash_aset (channel_hash_member, rb_str_new2("topic"), + rb_str_new2(ptr_channel->topic)); + rb_hash_aset (channel_hash_member, rb_str_new2("modes"), + rb_str_new2(ptr_channel->modes)); + rb_hash_aset (channel_hash_member, rb_str_new2("limit"), + INT2FIX(ptr_channel->limit)); + rb_hash_aset (channel_hash_member, rb_str_new2("key"), + rb_str_new2(ptr_channel->key)); + rb_hash_aset (channel_hash_member, rb_str_new2("nicks_count"), + INT2FIX(ptr_channel->nicks_count)); + + rb_hash_aset (channel_hash, rb_str_new2(ptr_channel->name), channel_hash_member); + } + } + + ruby_plugin->free_channel_info(ruby_plugin, channel_info); + + return channel_hash; +} + +/* + * weechat_ruby_get_nick_info: get infos about nicks + */ + +static VALUE +weechat_ruby_get_nick_info (VALUE class, VALUE server, VALUE channel) +{ + t_plugin_nick_info *nick_info, *ptr_nick; + VALUE nick_hash, nick_hash_member; + char *c_server, *c_channel; + + /* make gcc happy */ + (void) class; + + if (!ruby_current_script) + { + ruby_plugin->printf_server (ruby_plugin, + "Ruby error: unable to get channel infos, " + "script not initialized"); + return INT2FIX (0); + } + + c_server = NULL; + c_channel = NULL; + if (NIL_P (server) || NIL_P (channel)) + { + ruby_plugin->printf_server (ruby_plugin, + "Ruby error: wrong parameters for " + "\"get_nick_info\" function"); + return INT2FIX (0); + } + + Check_Type (server, T_STRING); + Check_Type (channel, T_STRING); + + c_server = STR2CSTR (server); + c_channel = STR2CSTR (channel); + + if (!c_server || !c_channel) + return INT2FIX (0); + + nick_hash = rb_hash_new (); + if (!nick_hash) + return Qnil; + + nick_info = ruby_plugin->get_nick_info (ruby_plugin, c_server, c_channel); + if (!nick_info) + return nick_hash; + + for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + nick_hash_member = rb_hash_new (); + + if (nick_hash_member) + { + rb_hash_aset (nick_hash_member, rb_str_new2("flags"), + INT2FIX(ptr_nick->flags)); + + rb_hash_aset (nick_hash, rb_str_new2(ptr_nick->nick), nick_hash_member); + } + } + + ruby_plugin->free_nick_info(ruby_plugin, nick_info); + + return nick_hash; +} + +/* * weechat_ruby_output : redirection for stdout and stderr */ @@ -1324,6 +1567,9 @@ weechat_plugin_init (t_weechat_plugin *plugin) rb_define_module_function (mWeechat, "set_config", weechat_ruby_set_config, 2); rb_define_module_function (mWeechat, "get_plugin_config", weechat_ruby_get_plugin_config, 1); rb_define_module_function (mWeechat, "set_plugin_config", weechat_ruby_set_plugin_config, 2); + rb_define_module_function (mWeechat, "get_server_info", weechat_ruby_get_server_info, 0); + rb_define_module_function (mWeechat, "get_channel_info", weechat_ruby_get_channel_info, 1); + rb_define_module_function (mWeechat, "get_nick_info", weechat_ruby_get_nick_info, 2); /* redirect stdin and stdout */ mWeechatOutputs = rb_define_module("WeechatOutputs"); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 75c02f4a3..ce57c7efb 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -60,6 +60,69 @@ struct t_plugin_dcc_info t_plugin_dcc_info *next_dcc; /* link to next dcc file/chat */ }; +typedef struct t_plugin_server_info t_plugin_server_info; + +struct t_plugin_server_info +{ + char *name; /* name of server (only for display) */ + int autoconnect; /* = 1 if auto connect at startup */ + int autoreconnect; /* = 1 if auto reco when disconnected */ + int autoreconnect_delay; /* delay before trying again reconnect */ + int command_line; /* server was given on command line */ + char *address; /* address of server (IP or name) */ + int port; /* port for server (6667 by default) */ + int ipv6; /* use IPv6 protocol */ + int ssl; /* SSL protocol */ + char *password; /* password for server */ + char *nick1; /* first nickname for the server */ + char *nick2; /* alternate nickname */ + char *nick3; /* 2nd alternate nickname */ + char *username; /* user name */ + char *realname; /* real name */ + char *command; /* command to run once connected */ + int command_delay; /* delay after execution of command */ + char *autojoin; /* channels to automatically join */ + int autorejoin; /* auto rejoin channels when kicked */ + char *notify_levels; /* channels notify levels */ + char *charset_decode_iso; /* channels charsets for decoding ISO */ + char *charset_decode_utf; /* channels charsets for decoding UTF */ + char *charset_encode; /* channels charsets for encoding msgs */ + int is_connected; /* 1 if WeeChat is connected to server */ + int ssl_connected; /* = 1 if connected with SSL */ + char *nick; /* current nickname */ + int is_away; /* 1 is user is marker as away */ + time_t away_time; /* time() when user marking as away */ + int lag; /* lag (in milliseconds) */ + t_plugin_server_info *prev_info; /* link to previous server info */ + t_plugin_server_info *next_info; /* link to next server info */ +}; + +typedef struct t_plugin_channel_info t_plugin_channel_info; + +struct t_plugin_channel_info +{ + int type; /* channel type */ + char *name; /* name of channel (exemple: "#abc") */ + char *topic; /* topic of channel (host for private) */ + char *modes; /* channel modes */ + int limit; /* user limit (0 is limit not set) */ + char *key; /* channel key (NULL if no key is set) */ + int nicks_count; /* # nicks on channel (0 if dcc/pv) */ + t_plugin_channel_info *prev_info; /* link to previous channel infp */ + t_plugin_channel_info *next_info; /* link to next channel info */ +}; + +typedef struct t_plugin_nick_info t_plugin_nick_info; + +struct t_plugin_nick_info +{ + char *nick; /* nickname */ + int flags; /* chanowner/chanadmin (unrealircd), */ + /* op, halfop, voice, away */ + t_plugin_nick_info *prev_nick; /* link to previous nick */ + t_plugin_nick_info *next_nick; /* link to next nick */ +}; + typedef struct t_weechat_plugin t_weechat_plugin; typedef int (t_plugin_handler_func) (t_weechat_plugin *, char *, char *, char *, char *, void *); @@ -158,6 +221,12 @@ struct t_weechat_plugin int (*set_config) (t_weechat_plugin *, char *, char *); char *(*get_plugin_config) (t_weechat_plugin *, char *); int (*set_plugin_config) (t_weechat_plugin *, char *, char *); + t_plugin_server_info *(*get_server_info) (t_weechat_plugin *); + void (*free_server_info) (t_weechat_plugin *, t_plugin_server_info *); + t_plugin_channel_info *(*get_channel_info) (t_weechat_plugin *, char *); + void (*free_channel_info) (t_weechat_plugin *, t_plugin_channel_info *); + t_plugin_nick_info *(*get_nick_info) (t_weechat_plugin *, char*, char*); + void (*free_nick_info) (t_weechat_plugin *, t_plugin_nick_info *); /* WeeChat developers: ALWAYS add new functions at the end */ }; @@ -197,5 +266,11 @@ extern char *weechat_plugin_get_config (t_weechat_plugin *, char *); extern int weechat_plugin_set_config (t_weechat_plugin *, char *, char *); extern char *weechat_plugin_get_plugin_config (t_weechat_plugin *, char *); extern int weechat_plugin_set_plugin_config (t_weechat_plugin *, char *, char *); +extern t_plugin_server_info *weechat_plugin_get_server_info (t_weechat_plugin *); +extern void weechat_plugin_free_server_info (t_weechat_plugin *, t_plugin_server_info *); +extern t_plugin_channel_info *weechat_plugin_get_channel_info (t_weechat_plugin *, char *); +extern void weechat_plugin_free_channel_info (t_weechat_plugin *, t_plugin_channel_info *); +extern t_plugin_nick_info *weechat_plugin_get_nick_info (t_weechat_plugin *, char *, char *); +extern void weechat_plugin_free_nick_info (t_weechat_plugin *, t_plugin_nick_info *); #endif /* weechat-plugin.h */ |