int xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer, const char *input_data) { struct t_xfer *ptr_xfer; char *input_data_color, str_tags[256], *str_color; /* make C compiler happy */ (void) data; ptr_xfer = xfer_search_by_buffer (buffer); if (ptr_xfer) { if (!XFER_HAS_ENDED(ptr_xfer->status)) { xfer_chat_sendf (ptr_xfer, "%s\r\n", input_data); if (!XFER_HAS_ENDED(ptr_xfer->status)) { str_color = xfer_chat_color_for_tags (weechat_config_color (weechat_config_get ("weechat.color.chat_nick_self"))); snprintf (str_tags, sizeof (str_tags), "irc_privmsg,no_highlight,prefix_nick_%s,nick_%s,log1", (str_color) ? str_color : "default", ptr_xfer->local_nick); if (str_color) free (str_color); input_data_color = weechat_hook_modifier_exec ("irc_color_decode", "1", input_data); weechat_printf_tags (buffer, str_tags, "%s%s\t%s", weechat_color ("chat_nick_self"), ptr_xfer->local_nick, (input_data_color) ? input_data_color : input_data); if (input_data_color) free (input_data_color); } } } return WEECHAT_RC_OK; }
int command_recommand(void *data, struct t_gui_buffer *buffer, int argc, char *argv[], char *argv_eol[]) { char *server = weechat_buffer_get_string(buffer, "localvar_server"); if (server == NULL) { weechat_printf(buffer, "Not a server buffer."); } else { // format config key size_t length = strlen("irc.server..command") + strlen(server) + 1; char config[length]; snprintf(config, length, "irc.server.%s.command", server); // get command struct t_config_option *option = weechat_config_get(config); const char *cmd; if (option != NULL && (cmd = weechat_config_string(option)) != NULL) { // execute weechat_command(buffer, cmd); } else { weechat_printf(buffer, "There is no command for the server %s.", server); } } return WEECHAT_RC_OK; }
int xfer_chat_recv_cb (void *arg_xfer, int fd) { struct t_xfer *xfer; static char buffer[4096 + 2]; char *buf2, *pos, *ptr_buf, *ptr_buf2, *next_ptr_buf; char *ptr_buf_decoded, *ptr_buf_without_weechat_colors, *ptr_buf_color; char str_tags[256], *str_color; const char *pv_tags; int num_read, length, ctcp_action; /* make C compiler happy */ (void) fd; xfer = (struct t_xfer *)arg_xfer; num_read = recv (xfer->sock, buffer, sizeof (buffer) - 2, 0); if (num_read > 0) { buffer[num_read] = '\0'; buf2 = NULL; ptr_buf = buffer; if (xfer->unterminated_message) { buf2 = malloc (strlen (xfer->unterminated_message) + strlen (buffer) + 1); if (buf2) { strcpy (buf2, xfer->unterminated_message); strcat (buf2, buffer); } ptr_buf = buf2; free (xfer->unterminated_message); xfer->unterminated_message = NULL; } while (ptr_buf && ptr_buf[0]) { next_ptr_buf = NULL; pos = strstr (ptr_buf, "\n"); if (pos) { pos[0] = '\0'; next_ptr_buf = pos + 1; } else { xfer->unterminated_message = strdup (ptr_buf); ptr_buf = NULL; next_ptr_buf = NULL; } if (ptr_buf) { ctcp_action = 0; length = strlen (ptr_buf); if (ptr_buf[length - 1] == '\r') { ptr_buf[length - 1] = '\0'; length--; } if ((ptr_buf[0] == '\01') && (ptr_buf[length - 1] == '\01')) { ptr_buf[length - 1] = '\0'; ptr_buf++; if (strncmp (ptr_buf, "ACTION ", 7) == 0) { ptr_buf += 7; ctcp_action = 1; } } ptr_buf_decoded = (xfer->charset_modifier) ? weechat_hook_modifier_exec ("charset_decode", xfer->charset_modifier, ptr_buf) : NULL; ptr_buf_without_weechat_colors = weechat_string_remove_color ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf, "?"); ptr_buf_color = weechat_hook_modifier_exec ("irc_color_decode", "1", (ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf)); ptr_buf2 = (ptr_buf_color) ? ptr_buf_color : ((ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf)); pv_tags = weechat_config_string (xfer_config_look_pv_tags); if (ctcp_action) { snprintf (str_tags, sizeof (str_tags), "irc_privmsg,irc_action,%s%snick_%s,log1", (pv_tags && pv_tags[0]) ? pv_tags : "", (pv_tags && pv_tags[0]) ? "," : "", xfer->remote_nick); weechat_printf_tags (xfer->buffer, str_tags, "%s%s%s%s%s%s", weechat_prefix ("action"), weechat_color ((xfer->remote_nick_color) ? xfer->remote_nick_color : "chat_nick_other"), xfer->remote_nick, weechat_color ("chat"), (ptr_buf2[0]) ? " " : "", ptr_buf2); } else { str_color = xfer_chat_color_for_tags ( (xfer->remote_nick_color) ? xfer->remote_nick_color : weechat_config_color (weechat_config_get ("weechat.color.chat_nick_other"))); snprintf (str_tags, sizeof (str_tags), "irc_privmsg,%s%sprefix_nick_%s,nick_%s,log1", (pv_tags && pv_tags[0]) ? pv_tags : "", (pv_tags && pv_tags[0]) ? "," : "", (str_color) ? str_color : "default", xfer->remote_nick); if (str_color) free (str_color); weechat_printf_tags (xfer->buffer, str_tags, "%s%s\t%s", weechat_color ((xfer->remote_nick_color) ? xfer->remote_nick_color : "chat_nick_other"), xfer->remote_nick, ptr_buf2); } if (ptr_buf_decoded) free (ptr_buf_decoded); if (ptr_buf_without_weechat_colors) free (ptr_buf_without_weechat_colors); if (ptr_buf_color) free (ptr_buf_color); } ptr_buf = next_ptr_buf; } if (buf2) free (buf2); } else { xfer_close (xfer, XFER_STATUS_ABORTED); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); } return WEECHAT_RC_OK; }
void irc_input_user_message_display (struct t_gui_buffer *buffer, int action, const char *text) { struct t_irc_nick *ptr_nick; char *pos, *text2, *text_decoded, str_tags[256], *str_color; const char *ptr_text; /* if message is an action, force "action" to 1 and extract message */ if (strncmp (text, "\01ACTION ", 8) == 0) { action = 1; pos = strrchr (text + 8, '\01'); if (pos) text2 = weechat_strndup (text + 8, pos - text - 8); else text2 = strdup (text + 8); } else text2 = strdup (text); text_decoded = irc_color_decode ( (text2) ? text2 : text, weechat_config_boolean (irc_config_network_colors_send)); IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (ptr_channel) { ptr_nick = NULL; if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) { ptr_nick = irc_nick_search (ptr_server, ptr_channel, ptr_server->nick); } if (action) { snprintf (str_tags, sizeof (str_tags), "irc_action,self_msg,notify_none,no_highlight"); } else { str_color = irc_color_for_tags ( weechat_config_color ( weechat_config_get ("weechat.color.chat_nick_self"))); snprintf (str_tags, sizeof (str_tags), "notify_none,self_msg,no_highlight,prefix_nick_%s", (str_color) ? str_color : "default"); if (str_color) free (str_color); } ptr_text = (text_decoded) ? text_decoded : ((text2) ? text2 : text); if (action) { weechat_printf_date_tags ( buffer, 0, irc_protocol_tags ( "privmsg", str_tags, (ptr_nick) ? ptr_nick->name : ptr_server->nick, NULL), "%s%s%s%s%s %s", weechat_prefix ("action"), irc_nick_mode_for_display (ptr_server, ptr_nick, 0), IRC_COLOR_CHAT_NICK_SELF, ptr_server->nick, IRC_COLOR_RESET, ptr_text); } else { weechat_printf_date_tags ( buffer, 0, irc_protocol_tags ( "privmsg", str_tags, (ptr_nick) ? ptr_nick->name : ptr_server->nick, NULL), "%s%s", irc_nick_as_prefix ( ptr_server, (ptr_nick) ? ptr_nick : NULL, (ptr_nick) ? NULL : ptr_server->nick, IRC_COLOR_CHAT_NICK_SELF), ptr_text); } } if (text2) free (text2); if (text_decoded) free (text_decoded); }
int weechat_aspell_string_is_nick (struct t_gui_buffer *buffer, const char *word) { char *pos, *pos_nick_completer, *pos_space, saved_char; const char *nick_completer, *buffer_type, *buffer_nick, *buffer_channel; int rc, len_completer; nick_completer = weechat_config_string ( weechat_config_get ("weechat.completion.nick_completer")); len_completer = (nick_completer) ? strlen (nick_completer) : 0; pos_nick_completer = (nick_completer) ? strstr (word, nick_completer) : NULL; pos_space = strchr (word, ' '); pos = NULL; if (pos_nick_completer && pos_space) { if ((pos_nick_completer < pos_space) && (pos_nick_completer + len_completer == pos_space)) { pos = pos_nick_completer; } else pos = pos_space; } else { pos = (pos_nick_completer && !pos_nick_completer[len_completer]) ? pos_nick_completer : pos_space; } if (pos) { saved_char = pos[0]; pos[0] = '\0'; } rc = (weechat_nicklist_search_nick (buffer, NULL, word)) ? 1 : 0; if (!rc) { /* for "private" buffers, check if word is self or remote nick */ buffer_type = weechat_buffer_get_string (buffer, "localvar_type"); if (buffer_type && (strcmp (buffer_type, "private") == 0)) { /* check self nick */ buffer_nick = weechat_buffer_get_string (buffer, "localvar_nick"); if (buffer_nick && (weechat_strcasecmp (buffer_nick, word) == 0)) { rc = 1; } else { /* check remote nick */ buffer_channel = weechat_buffer_get_string (buffer, "localvar_channel"); if (buffer_channel && (weechat_strcasecmp (buffer_channel, word) == 0)) { rc = 1; } } } } if (pos) pos[0] = saved_char; return rc; }
void logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) { const char *charset; struct t_logger_line *last_lines, *ptr_lines; char *pos_message, *pos_tab, *error, *message, text_time[256], *text_time2; struct timeval tv_time; struct tm *local_time; time_t datetime, time_now; struct tm tm_line; int num_lines, old_mday, old_mon, old_year; charset = weechat_info_get ("charset_terminal", ""); weechat_buffer_set (buffer, "print_hooks_enabled", "0"); gettimeofday (&tv_time, NULL); local_time = localtime (&tv_time.tv_sec); old_mday = local_time->tm_mday; old_mon = local_time->tm_mon; old_year = local_time->tm_year; num_lines = 0; last_lines = logger_tail_file (filename, lines); ptr_lines = last_lines; while (ptr_lines) { datetime = 0; pos_message = strchr (ptr_lines->data, '\t'); if (pos_message) { /* initialize structure, because strptime does not do it */ memset (&tm_line, 0, sizeof (struct tm)); /* * we get current time to initialize daylight saving time in * structure tm_line, otherwise printed time will be shifted * and will not use DST used on machine */ time_now = time (NULL); localtime_r (&time_now, &tm_line); pos_message[0] = '\0'; error = strptime (ptr_lines->data, weechat_config_string (logger_config_file_time_format), &tm_line); if (error && !error[0] && (tm_line.tm_year > 0)) { datetime = mktime (&tm_line); if ((tm_line.tm_mday != old_mday) || (tm_line.tm_mon != old_mon) || (tm_line.tm_year != old_year)) { strftime (text_time, sizeof (text_time), weechat_config_string (weechat_config_get ("weechat.look.day_change_time_format")), &tm_line); text_time2 = weechat_iconv_to_internal (NULL, text_time); weechat_printf_tags (buffer, "no_highlight,notify_none", _("\t\tDay changed to %s"), (text_time2) ? text_time2 : text_time); if (text_time2) free (text_time2); old_mday = tm_line.tm_mday; old_mon = tm_line.tm_mon; old_year = tm_line.tm_year; } } pos_message[0] = '\t'; } pos_message = (pos_message && (datetime != 0)) ? pos_message + 1 : ptr_lines->data; message = (charset) ? weechat_iconv_to_internal (charset, pos_message) : strdup (pos_message); if (message) { pos_tab = strchr (message, '\t'); if (pos_tab) pos_tab[0] = '\0'; weechat_printf_date_tags (buffer, datetime, "no_highlight,notify_none", "%s%s%s%s%s", weechat_color (weechat_config_string (logger_config_color_backlog_line)), message, (pos_tab) ? "\t" : "", (pos_tab) ? weechat_color (weechat_config_string (logger_config_color_backlog_line)) : "", (pos_tab) ? pos_tab + 1 : ""); if (pos_tab) pos_tab[0] = '\t'; free (message); } num_lines++; ptr_lines = ptr_lines->next_line; } if (last_lines) logger_tail_free (last_lines); if (num_lines > 0) { weechat_printf_tags (buffer, "no_highlight,notify_none", _("%s===\t%s========== End of backlog (%d lines) =========="), weechat_color (weechat_config_string (logger_config_color_backlog_end)), weechat_color (weechat_config_string (logger_config_color_backlog_end)), num_lines); weechat_buffer_set (buffer, "unread", ""); } weechat_buffer_set (buffer, "print_hooks_enabled", "1"); }