static xt_status handle_channel(struct xt_node *node, gpointer data) { struct xml_parsedata *xd = data; irc_channel_t *ic; char *name, *type; name = xt_find_attr(node, "name"); type = xt_find_attr(node, "type"); if (!name || !type) { return XT_ABORT; } /* The channel may exist already, for example if it's &bitlbee. Also, it's possible that the user just reconnected and the IRC client already rejoined all channels it was in. They should still get the right settings. */ if ((ic = irc_channel_by_name(xd->irc, name)) || (ic = irc_channel_new(xd->irc, name))) { set_setstr(&ic->set, "type", type); } handle_settings(node, &ic->set); return XT_HANDLED; }
static void cmd_chat(irc_t *irc, char **cmd) { account_t *acc; if (g_strcasecmp(cmd[1], "add") == 0) { char *channel, *s; struct irc_channel *ic; MIN_ARGS(3); if (!(acc = account_get(irc->b, cmd[2]))) { irc_rootmsg(irc, "Invalid account"); return; } else if (!acc->prpl->chat_join) { irc_rootmsg(irc, "Named chatrooms not supported on that account."); return; } if (cmd[4] == NULL) { channel = g_strdup(cmd[3]); if ((s = strchr(channel, '@'))) { *s = 0; } } else { channel = g_strdup(cmd[4]); } if (strchr(CTYPES, channel[0]) == NULL) { s = g_strdup_printf("#%s", channel); g_free(channel); channel = s; irc_channel_name_strip(channel); } if ((ic = irc_channel_new(irc, channel)) && set_setstr(&ic->set, "type", "chat") && set_setstr(&ic->set, "chat_type", "room") && set_setstr(&ic->set, "account", cmd[2]) && set_setstr(&ic->set, "room", cmd[3])) { irc_rootmsg(irc, "Chatroom successfully added."); } else { if (ic) { irc_channel_free(ic); } irc_rootmsg(irc, "Could not add chatroom."); } g_free(channel); } else if (g_strcasecmp(cmd[1], "with") == 0) { irc_user_t *iu; MIN_ARGS(2); if ((iu = irc_user_by_name(irc, cmd[2])) && iu->bu && iu->bu->ic->acc->prpl->chat_with) { if (!iu->bu->ic->acc->prpl->chat_with(iu->bu->ic, iu->bu->handle)) { irc_rootmsg(irc, "(Possible) failure while trying to open " "a groupchat with %s.", iu->nick); } } else { irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]); } } else if (g_strcasecmp(cmd[1], "list") == 0 || g_strcasecmp(cmd[1], "set") == 0 || g_strcasecmp(cmd[1], "del") == 0) { irc_rootmsg(irc, "Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command."); cmd_channel(irc, cmd); } else { irc_rootmsg(irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1]); } }
static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_name, const gchar **attr_names, const gchar **attr_values, gpointer data, GError **error ) { struct xml_parsedata *xd = data; irc_t *irc = xd->irc; if( xd->unknown_tag > 0 ) { xd->unknown_tag ++; } else if( g_strcasecmp( element_name, "user" ) == 0 ) { char *nick = xml_attr( attr_names, attr_values, "nick" ); char *pass = xml_attr( attr_names, attr_values, "password" ); int st; if( !nick || !pass ) { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); } else if( ( st = md5_verify_password( xd->given_pass, pass ) ) == -1 ) { xd->pass_st = XML_PASS_WRONG; g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Error while decoding password attribute" ); } else if( st == 0 ) { if( xd->pass_st != XML_PASS_CHECK_ONLY ) xd->pass_st = XML_PASS_OK; } else { xd->pass_st = XML_PASS_WRONG; g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Password mismatch" ); } } else if( xd->pass_st < XML_PASS_OK ) { /* Let's not parse anything else if we only have to check the password. */ } else if( g_strcasecmp( element_name, "account" ) == 0 ) { char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag; char *pass_b64 = NULL; unsigned char *pass_cr = NULL; int pass_len; struct prpl *prpl = NULL; handle = xml_attr( attr_names, attr_values, "handle" ); pass_b64 = xml_attr( attr_names, attr_values, "password" ); server = xml_attr( attr_names, attr_values, "server" ); autoconnect = xml_attr( attr_names, attr_values, "autoconnect" ); tag = xml_attr( attr_names, attr_values, "tag" ); protocol = xml_attr( attr_names, attr_values, "protocol" ); if( protocol ) prpl = find_protocol( protocol ); if( !handle || !pass_b64 || !protocol ) g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); else if( !prpl ) g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Unknown protocol: %s", protocol ); else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) && arc_decode( pass_cr, pass_len, &password, xd->given_pass ) >= 0 ) { xd->current_account = account_add( irc->b, prpl, handle, password ); if( server ) set_setstr( &xd->current_account->set, "server", server ); if( autoconnect ) set_setstr( &xd->current_account->set, "auto_connect", autoconnect ); if( tag ) set_setstr( &xd->current_account->set, "tag", tag ); } else { /* Actually the _decode functions don't even return error codes, but maybe they will later... */ g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Error while decrypting account password" ); } g_free( pass_cr ); g_free( password ); } else if( g_strcasecmp( element_name, "setting" ) == 0 ) { char *setting; if( xd->current_setting ) { g_free( xd->current_setting ); xd->current_setting = NULL; } if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) ) { if( xd->current_channel != NULL ) xd->current_set_head = &xd->current_channel->set; else if( xd->current_account != NULL ) xd->current_set_head = &xd->current_account->set; else xd->current_set_head = &xd->irc->b->set; xd->current_setting = g_strdup( setting ); } else g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); } else if( g_strcasecmp( element_name, "buddy" ) == 0 ) { char *handle, *nick; handle = xml_attr( attr_names, attr_values, "handle" ); nick = xml_attr( attr_names, attr_values, "nick" ); if( xd->current_account && handle && nick ) { nick_set_raw( xd->current_account, handle, nick ); } else { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); } } else if( g_strcasecmp( element_name, "channel" ) == 0 ) { char *name, *type; name = xml_attr( attr_names, attr_values, "name" ); type = xml_attr( attr_names, attr_values, "type" ); if( !name || !type ) { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); return; } /* The channel may exist already, for example if it's &bitlbee. Also, it's possible that the user just reconnected and the IRC client already rejoined all channels it was in. They should still get the right settings. */ if( ( xd->current_channel = irc_channel_by_name( irc, name ) ) || ( xd->current_channel = irc_channel_new( irc, name ) ) ) set_setstr(&xd->current_channel->set, "type", type ); } /* Backward compatibility: Keep this around for a while for people switching from BitlBee 1.2.4+. */ else if( g_strcasecmp( element_name, "chat" ) == 0 ) { char *handle, *channel; handle = xml_attr( attr_names, attr_values, "handle" ); channel = xml_attr( attr_names, attr_values, "channel" ); if( xd->current_account && handle && channel ) { irc_channel_t *ic; if( ( ic = irc_channel_new( irc, channel ) ) && set_setstr( &ic->set, "type", "chat" ) && set_setstr( &ic->set, "chat_type", "room" ) && set_setstr( &ic->set, "account", xd->current_account->tag ) && set_setstr( &ic->set, "room", handle ) ) { /* Try to pick up some settings where possible. */ xd->current_channel = ic; } else if( ic ) irc_channel_free( ic ); } else { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); } } else { xd->unknown_tag ++; irc_rootmsg( irc, "Warning: Unknown XML tag found in configuration file (%s). " "This may happen when downgrading BitlBee versions. " "This tag will be skipped and the information will be lost " "once you save your settings.", element_name ); /* g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unkown element: %s", element_name ); */ } }
int irc_upgrade_read_cb (void *data, struct t_upgrade_file *upgrade_file, int object_id, struct t_infolist *infolist) { int flags, sock, size, i, index, nicks_count, num_items; long number; time_t join_time; char *buf, option_name[64], **nicks, *nick_join, *pos, *error; char **items; const char *buffer_name, *str, *nick; struct t_irc_nick *ptr_nick; struct t_irc_redirect *ptr_redirect; struct t_irc_notify *ptr_notify; struct t_gui_buffer *ptr_buffer; /* make C compiler happy */ (void) data; (void) upgrade_file; weechat_infolist_reset_item_cursor (infolist); while (weechat_infolist_next (infolist)) { switch (object_id) { case IRC_UPGRADE_TYPE_SERVER: irc_upgrade_current_server = irc_server_search (weechat_infolist_string (infolist, "name")); if (irc_upgrade_current_server) { irc_upgrade_current_server->temp_server = weechat_infolist_integer (infolist, "temp_server"); irc_upgrade_current_server->buffer = NULL; buffer_name = weechat_infolist_string (infolist, "buffer_name"); if (buffer_name && buffer_name[0]) { ptr_buffer = weechat_buffer_search (IRC_PLUGIN_NAME, buffer_name); if (ptr_buffer) irc_upgrade_current_server->buffer = ptr_buffer; } irc_upgrade_current_server->index_current_address = weechat_infolist_integer (infolist, "index_current_address"); str = weechat_infolist_string (infolist, "current_address"); if (str) { irc_upgrade_current_server->current_address = strdup (str); irc_upgrade_current_server->current_port = weechat_infolist_integer (infolist, "current_port"); } else { if (irc_upgrade_current_server->index_current_address < irc_upgrade_current_server->addresses_count) { irc_upgrade_current_server->current_address = strdup (irc_upgrade_current_server->addresses_array[irc_upgrade_current_server->index_current_address]); irc_upgrade_current_server->current_port = irc_upgrade_current_server->ports_array[irc_upgrade_current_server->index_current_address]; } } str = weechat_infolist_string (infolist, "current_ip"); if (str) irc_upgrade_current_server->current_ip = strdup (str); sock = weechat_infolist_integer (infolist, "sock"); if (sock >= 0) { irc_upgrade_current_server->sock = sock; irc_upgrade_current_server->hook_fd = weechat_hook_fd (irc_upgrade_current_server->sock, 1, 0, 0, &irc_server_recv_cb, irc_upgrade_current_server); } irc_upgrade_current_server->is_connected = weechat_infolist_integer (infolist, "is_connected"); irc_upgrade_current_server->ssl_connected = weechat_infolist_integer (infolist, "ssl_connected"); irc_upgrade_current_server->disconnected = weechat_infolist_integer (infolist, "disconnected"); str = weechat_infolist_string (infolist, "unterminated_message"); if (str) irc_upgrade_current_server->unterminated_message = strdup (str); str = weechat_infolist_string (infolist, "nick"); if (str) irc_server_set_nick (irc_upgrade_current_server, str); str = weechat_infolist_string (infolist, "nick_modes"); if (str) irc_upgrade_current_server->nick_modes = strdup (str); str = weechat_infolist_string (infolist, "isupport"); if (str) irc_upgrade_current_server->isupport = strdup (str); /* * "prefix" is not any more in this infolist (since * WeeChat 0.3.4), but we read it to keep compatibility * with old WeeChat versions, on /upgrade) */ str = weechat_infolist_string (infolist, "prefix"); if (str) irc_server_set_prefix_modes_chars (irc_upgrade_current_server, str); /* "prefix_modes" is new in WeeChat 0.3.4 */ str = weechat_infolist_string (infolist, "prefix_modes"); if (str) { if (irc_upgrade_current_server->prefix_modes) free (irc_upgrade_current_server->prefix_modes); irc_upgrade_current_server->prefix_modes = strdup (str); } /* "prefix_chars" is new in WeeChat 0.3.4 */ str = weechat_infolist_string (infolist, "prefix_chars"); if (str) { if (irc_upgrade_current_server->prefix_chars) free (irc_upgrade_current_server->prefix_chars); irc_upgrade_current_server->prefix_chars = strdup (str); } irc_upgrade_current_server->nick_max_length = weechat_infolist_integer (infolist, "nick_max_length"); irc_upgrade_current_server->casemapping = weechat_infolist_integer (infolist, "casemapping"); str = weechat_infolist_string (infolist, "chantypes"); if (str) irc_upgrade_current_server->chantypes = strdup (str); str = weechat_infolist_string (infolist, "chanmodes"); if (str) irc_upgrade_current_server->chanmodes = strdup (str); else { str = irc_server_get_isupport_value (irc_upgrade_current_server, "CHANMODES"); if (str) irc_upgrade_current_server->chanmodes = strdup (str); } /* "monitor" is new in WeeChat 0.4.3 */ if (weechat_infolist_search_var (infolist, "monitor")) { irc_upgrade_current_server->monitor = weechat_infolist_integer (infolist, "monitor"); } else { /* WeeChat <= 0.4.2 */ str = irc_server_get_isupport_value (irc_upgrade_current_server, "MONITOR"); if (str) { error = NULL; number = strtol (str, &error, 10); if (error && !error[0]) irc_upgrade_current_server->monitor = (int)number; } } irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay"); irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start"); irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time"); irc_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join"); irc_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin"); irc_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away"); str = weechat_infolist_string (infolist, "away_message"); if (str) irc_upgrade_current_server->away_message = strdup (str); irc_upgrade_current_server->away_time = weechat_infolist_time (infolist, "away_time"); irc_upgrade_current_server->lag = weechat_infolist_integer (infolist, "lag"); buf = weechat_infolist_buffer (infolist, "lag_check_time", &size); if (buf) memcpy (&(irc_upgrade_current_server->lag_check_time), buf, size); irc_upgrade_current_server->lag_next_check = weechat_infolist_time (infolist, "lag_next_check"); irc_upgrade_current_server->lag_last_refresh = weechat_infolist_time (infolist, "lag_last_refresh"); irc_upgrade_current_server->last_user_message = weechat_infolist_time (infolist, "last_user_message"); irc_upgrade_current_server->last_away_check = weechat_infolist_time (infolist, "last_away_check"); irc_upgrade_current_server->last_data_purge = weechat_infolist_time (infolist, "last_data_purge"); } break; case IRC_UPGRADE_TYPE_CHANNEL: if (irc_upgrade_current_server) { irc_upgrade_current_channel = irc_channel_new (irc_upgrade_current_server, weechat_infolist_integer (infolist, "type"), weechat_infolist_string (infolist, "name"), 0, 0); if (irc_upgrade_current_channel) { str = weechat_infolist_string (infolist, "topic"); if (str) irc_channel_set_topic (irc_upgrade_current_channel, str); str = weechat_infolist_string (infolist, "modes"); if (str) irc_upgrade_current_channel->modes = strdup (str); irc_upgrade_current_channel->limit = weechat_infolist_integer (infolist, "limit"); str = weechat_infolist_string (infolist, "key"); if (str) irc_upgrade_current_channel->key = strdup (str); str = weechat_infolist_string (infolist, "join_msg_received"); if (str) { items = weechat_string_split (str, ",", 0, 0, &num_items); if (items) { for (i = 0; i < num_items; i++) { weechat_hashtable_set (irc_upgrade_current_channel->join_msg_received, items[i], "1"); } weechat_string_free_split (items); } } irc_upgrade_current_channel->checking_away = weechat_infolist_integer (infolist, "checking_away"); str = weechat_infolist_string (infolist, "away_message"); if (str) irc_upgrade_current_channel->away_message = strdup (str); irc_upgrade_current_channel->has_quit_server = weechat_infolist_integer (infolist, "has_quit_server"); irc_upgrade_current_channel->cycle = weechat_infolist_integer (infolist, "cycle"); irc_upgrade_current_channel->part = weechat_infolist_integer (infolist, "part"); irc_upgrade_current_channel->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset"); for (i = 0; i < 2; i++) { index = 0; while (1) { snprintf (option_name, sizeof (option_name), "nick_speaking%d_%05d", i, index); nick = weechat_infolist_string (infolist, option_name); if (!nick) break; irc_channel_nick_speaking_add (irc_upgrade_current_channel, nick, i); index++; } } index = 0; while (1) { snprintf (option_name, sizeof (option_name), "nick_speaking_time_nick_%05d", index); nick = weechat_infolist_string (infolist, option_name); if (!nick) break; snprintf (option_name, sizeof (option_name), "nick_speaking_time_time_%05d", index); irc_channel_nick_speaking_time_add (irc_upgrade_current_server, irc_upgrade_current_channel, nick, weechat_infolist_time (infolist, option_name)); index++; } str = weechat_infolist_string (infolist, "join_smart_filtered"); if (str) { nicks = weechat_string_split (str, ",", 0, 0, &nicks_count); if (nicks) { for (i = 0; i < nicks_count; i++) { pos = strchr (nicks[i], ':'); if (pos) { nick_join = weechat_strndup (nicks[i], pos - nicks[i]); if (nick_join) { error = NULL; number = strtol (pos + 1, &error, 10); if (error && !error[0]) { join_time = (time_t)number; irc_channel_join_smart_filtered_add (irc_upgrade_current_channel, nick_join, join_time); } free (nick_join); } } } weechat_string_free_split (nicks); } } } } break; case IRC_UPGRADE_TYPE_NICK: if (irc_upgrade_current_server && irc_upgrade_current_channel) { ptr_nick = irc_nick_new (irc_upgrade_current_server, irc_upgrade_current_channel, weechat_infolist_string (infolist, "name"), weechat_infolist_string (infolist, "host"), weechat_infolist_string (infolist, "prefixes"), weechat_infolist_integer (infolist, "away")); if (ptr_nick) { /* * "flags" is not any more in this infolist (since * WeeChat 0.3.4), but we read it to keep compatibility * with old WeeChat versions, on /upgrade) * We try to restore prefixes with old flags, but * this is approximation, it's not sure we will * restore good prefixes here (a /names on channel * will fix problem if prefixes are wrong). * Flags were defined in irc-nick.h: * #define IRC_NICK_CHANOWNER 1 * #define IRC_NICK_CHANADMIN 2 * #define IRC_NICK_CHANADMIN2 4 * #define IRC_NICK_OP 8 * #define IRC_NICK_HALFOP 16 * #define IRC_NICK_VOICE 32 * #define IRC_NICK_AWAY 64 * #define IRC_NICK_CHANUSER 128 */ flags = weechat_infolist_integer (infolist, "flags"); if (flags > 0) { /* channel owner */ if (flags & 1) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'q'); } /* channel admin */ if ((flags & 2) || (flags & 4)) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'a'); } /* op */ if (flags & 8) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'o'); } /* half-op */ if (flags & 16) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'h'); } /* voice */ if (flags & 32) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'v'); } /* away */ if (flags & 64) { irc_nick_set_away (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1); } /* channel user */ if (flags & 128) { irc_nick_set_mode (irc_upgrade_current_server, irc_upgrade_current_channel, ptr_nick, 1, 'u'); } } } } break; case IRC_UPGRADE_TYPE_REDIRECT: if (irc_upgrade_current_server) { ptr_redirect = irc_redirect_new_with_commands ( irc_upgrade_current_server, weechat_infolist_string (infolist, "pattern"), weechat_infolist_string (infolist, "signal"), weechat_infolist_integer (infolist, "count"), weechat_infolist_string (infolist, "string"), weechat_infolist_integer (infolist, "timeout"), weechat_infolist_string (infolist, "cmd_start"), weechat_infolist_string (infolist, "cmd_stop"), weechat_infolist_string (infolist, "cmd_extra"), weechat_infolist_string (infolist, "cmd_filter")); if (ptr_redirect) { ptr_redirect->current_count = weechat_infolist_integer (infolist, "current_count"); str = weechat_infolist_string (infolist, "command"); if (str) ptr_redirect->command = strdup (str); ptr_redirect->assigned_to_command = weechat_infolist_integer (infolist, "assigned_to_command"); ptr_redirect->start_time = weechat_infolist_time (infolist, "start_time"); ptr_redirect->cmd_start_received = weechat_infolist_integer (infolist, "cmd_start_received"); ptr_redirect->cmd_stop_received = weechat_infolist_integer (infolist, "cmd_stop_received"); str = weechat_infolist_string (infolist, "output"); if (str) ptr_redirect->output = strdup (str); ptr_redirect->output_size = weechat_infolist_integer (infolist, "output_size"); } } break; case IRC_UPGRADE_TYPE_REDIRECT_PATTERN: irc_redirect_pattern_new ( weechat_infolist_string (infolist, "name"), weechat_infolist_integer (infolist, "temp_pattern"), weechat_infolist_integer (infolist, "timeout"), weechat_infolist_string (infolist, "cmd_start"), weechat_infolist_string (infolist, "cmd_stop"), weechat_infolist_string (infolist, "cmd_extra")); break; case IRC_UPGRADE_TYPE_NOTIFY: if (irc_upgrade_current_server) { ptr_notify = irc_notify_search (irc_upgrade_current_server, weechat_infolist_string (infolist, "nick")); if (ptr_notify) { ptr_notify->is_on_server = weechat_infolist_integer (infolist, "is_on_server"); str = weechat_infolist_string (infolist, "away_message"); if (str) ptr_notify->away_message = strdup (str); } } break; case IRC_UPGRADE_TYPE_RAW_MESSAGE: irc_raw_message_add_to_list (weechat_infolist_time (infolist, "date"), weechat_infolist_string (infolist, "prefix"), weechat_infolist_string (infolist, "message")); break; } } return WEECHAT_RC_OK; }
static void irc_cmd_join( irc_t *irc, char **cmd ) { char *comma, *s = cmd[1]; while( s ) { irc_channel_t *ic; if( ( comma = strchr( s, ',' ) ) ) *comma = '\0'; if( ( ic = irc_channel_by_name( irc, s ) ) == NULL && ( ic = irc_channel_new( irc, s ) ) ) { if( strcmp( set_getstr( &ic->set, "type" ), "control" ) != 0 ) { /* Autoconfiguration is for control channels only ATM. */ } else if( bee_group_by_name( ic->irc->b, ic->name + 1, FALSE ) ) { set_setstr( &ic->set, "group", ic->name + 1 ); set_setstr( &ic->set, "fill_by", "group" ); } else if( set_setstr( &ic->set, "protocol", ic->name + 1 ) ) { set_setstr( &ic->set, "fill_by", "protocol" ); } else if( set_setstr( &ic->set, "account", ic->name + 1 ) ) { set_setstr( &ic->set, "fill_by", "account" ); } else { /* The set commands above will run this already, but if we didn't hit any, we have to fill the channel with the default population. */ bee_irc_channel_update( ic->irc, ic, NULL ); } } else if( ic == NULL ) { irc_send_num( irc, 479, "%s :Invalid channel name", s ); goto next; } if( ic->flags & IRC_CHANNEL_JOINED ) /* Dude, you're already there... RFC doesn't have any reply for that though? */ goto next; if( ic->f->join && !ic->f->join( ic ) ) /* The story is: FALSE either means the handler showed an error message, or is doing some work before the join should be confirmed. (In the latter case, the caller should take care of that confirmation.) TRUE means all's good, let the user join the channel right away. */ goto next; irc_channel_add_user( ic, irc->user ); next: if( comma ) { s = comma + 1; *comma = ','; } else break; } }
void irc_ctcp_recv (struct t_irc_server *server, const char *command, struct t_irc_channel *channel, const char *address, const char *nick, const char *remote_nick, char *arguments, char *message) { char *pos_end, *pos_space, *pos_args; const char *reply; char *decoded_reply; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; int nick_is_me; while (arguments && arguments[0]) { pos_end = strrchr (arguments + 1, '\01'); if (pos_end) pos_end[0] = '\0'; pos_args = NULL; pos_space = strchr (arguments + 1, ' '); if (pos_space) { pos_space[0] = '\0'; pos_args = pos_space + 1; while (pos_args[0] == ' ') { pos_args++; } } /* CTCP ACTION */ if (strcmp (arguments + 1, "ACTION") == 0) { nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0); if (channel) { ptr_nick = irc_nick_search (server, channel, nick); irc_channel_nick_speaking_add (channel, nick, (pos_args) ? weechat_string_has_highlight (pos_args, server->nick) : 0); irc_channel_nick_speaking_time_remove_old (channel); irc_channel_nick_speaking_time_add (server, channel, nick, time (NULL)); weechat_printf_tags (channel->buffer, irc_protocol_tags (command, (nick_is_me) ? "irc_action,notify_none,no_highlight" : "irc_action,notify_message", nick), "%s%s%s%s%s%s", weechat_prefix ("action"), (ptr_nick) ? ptr_nick->color : ((nick) ? irc_nick_find_color (nick) : IRC_COLOR_CHAT_NICK), nick, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); } else { ptr_channel = irc_channel_search (server, remote_nick); if (!ptr_channel) { ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_PRIVATE, remote_nick, 0, 0); if (!ptr_channel) { weechat_printf (server->buffer, _("%s%s: cannot create new " "private buffer \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, remote_nick); } } if (ptr_channel) { if (!ptr_channel->topic) irc_channel_set_topic (ptr_channel, address); weechat_printf_tags (ptr_channel->buffer, irc_protocol_tags (command, (nick_is_me) ? "irc_action,notify_none,no_highlight" : "irc_action,notify_private", nick), "%s%s%s%s%s%s", weechat_prefix ("action"), (nick_is_me) ? IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick), nick, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); weechat_hook_signal_send ("irc_pv", WEECHAT_HOOK_SIGNAL_STRING, message); } } } /* CTCP PING */ else if (strcmp (arguments + 1, "PING") == 0) { reply = irc_ctcp_get_reply (server, arguments + 1); irc_ctcp_display_request (server, command, channel, nick, arguments + 1, pos_args, reply); if (!reply || reply[0]) { irc_ctcp_reply_to_nick (server, command, channel, nick, arguments + 1, pos_args); } } /* CTCP DCC */ else if (strcmp (arguments + 1, "DCC") == 0) { irc_ctcp_recv_dcc (server, nick, pos_args, message); } /* other CTCP */ else { reply = irc_ctcp_get_reply (server, arguments + 1); if (reply) { irc_ctcp_display_request (server, command, channel, nick, arguments + 1, pos_args, reply); if (reply[0]) { decoded_reply = irc_ctcp_replace_variables (server, reply); if (decoded_reply) { irc_ctcp_reply_to_nick (server, command, channel, nick, arguments + 1, decoded_reply); free (decoded_reply); } } } else { if (weechat_config_boolean (irc_config_look_display_ctcp_unknown)) { weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, nick, NULL, "ctcp", (channel) ? channel->buffer : NULL), irc_protocol_tags (command, "irc_ctcp", NULL), _("%sUnknown CTCP requested by %s%s%s: " "%s%s%s%s%s"), weechat_prefix ("network"), IRC_COLOR_CHAT_NICK, nick, IRC_COLOR_RESET, IRC_COLOR_CHAT_CHANNEL, arguments + 1, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); } } } weechat_hook_signal_send ("irc_ctcp", WEECHAT_HOOK_SIGNAL_STRING, message); if (pos_space) pos_space[0] = ' '; if (pos_end) pos_end[0] = '\01'; arguments = (pos_end) ? pos_end + 1 : NULL; } }