const char * irc_info_info_irc_is_channel_cb (void *data, const char *info_name, const char *arguments) { char *pos_comma, *server; const char *pos_channel; static char str_true[2] = "1"; struct t_irc_server *ptr_server; /* make C compiler happy */ (void) data; (void) info_name; ptr_server = NULL; pos_channel = arguments; pos_comma = strchr (arguments, ','); if (pos_comma) { pos_channel = pos_comma + 1; server = dogechat_strndup (arguments, pos_comma - arguments); if (server) { ptr_server = irc_server_search (server); free (server); } } if (irc_channel_is_channel (ptr_server, pos_channel)) return str_true; return NULL; }
const char * irc_info_info_irc_server_isupport_value_cb (void *data, const char *info_name, const char *arguments) { char *pos_comma, *server; const char *isupport_value; struct t_irc_server *ptr_server; /* make C compiler happy */ (void) data; (void) info_name; isupport_value = NULL; pos_comma = strchr (arguments, ','); if (pos_comma) { server = dogechat_strndup (arguments, pos_comma - arguments); if (server) { ptr_server = irc_server_search (server); if (ptr_server) { isupport_value = irc_server_get_isupport_value (ptr_server, pos_comma + 1); } } } return isupport_value; }
void alias_string_add_word_range (char **alias, int *length, const char *start, const char *end) { char *word; word = dogechat_strndup (start, end - start); if (word) { alias_string_add_word (alias, length, word); free (word); } }
void relay_server_get_protocol_args (const char *protocol_and_args, int *ipv4, int *ipv6, int *ssl, char **protocol, char **protocol_args) { int opt_ipv4, opt_ipv6, opt_ssl; char *pos; opt_ipv4 = -1; opt_ipv6 = -1; opt_ssl = 0; while (1) { if (strncmp (protocol_and_args, "ipv4.", 5) == 0) { opt_ipv4 = 1; protocol_and_args += 5; } else if (strncmp (protocol_and_args, "ipv6.", 5) == 0) { opt_ipv6 = 1; protocol_and_args += 5; } else if (strncmp (protocol_and_args, "ssl.", 4) == 0) { opt_ssl = 1; protocol_and_args += 4; } else break; } if ((opt_ipv4 == -1) && (opt_ipv6 == -1)) { /* * no IPv4/IPv6 specified, then use defaults: * - IPv4 enabled * - IPv6 enabled if option relay.network.ipv6 is on */ opt_ipv4 = 1; opt_ipv6 = dogechat_config_boolean (relay_config_network_ipv6); } else { if (opt_ipv4 == -1) opt_ipv4 = 0; if (opt_ipv6 == -1) opt_ipv6 = 0; } if (!opt_ipv4 && !opt_ipv6) { /* both IPv4/IPv6 disabled (should never occur!) */ opt_ipv4 = 1; } if (ipv4) *ipv4 = opt_ipv4; if (ipv6) *ipv6 = opt_ipv6; if (ssl) *ssl = opt_ssl; pos = strchr (protocol_and_args, '.'); if (pos) { if (protocol) { *protocol = dogechat_strndup (protocol_and_args, pos - protocol_and_args); } if (protocol_args) *protocol_args = strdup (pos + 1); } else { if (protocol) *protocol = strdup (protocol_and_args); if (protocol_args) *protocol_args = NULL; } }
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 = dogechat_strndup (text + 8, pos - text - 8); else text2 = strdup (text + 8); } else text2 = strdup (text); text_decoded = irc_color_decode ( (text2) ? text2 : text, dogechat_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,notify_none,no_highlight"); } else { str_color = irc_color_for_tags ( dogechat_config_color ( dogechat_config_get ("dogechat.color.chat_nick_self"))); snprintf (str_tags, sizeof (str_tags), "notify_none,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) { dogechat_printf_tags ( buffer, irc_protocol_tags ( "privmsg", str_tags, (ptr_nick) ? ptr_nick->name : ptr_server->nick, NULL), "%s%s%s%s%s %s", dogechat_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 { dogechat_printf_tags ( buffer, 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 irc_input_send_cb (void *data, const char *signal, const char *type_data, void *signal_data) { const char *ptr_string, *ptr_message; char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4, *error; char *server, *channel, *flags, *tags; long flags_value; char *data_with_colors; struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; struct t_gui_buffer *ptr_buffer; /* make C compiler happy */ (void) data; (void) signal; (void) type_data; ptr_string = (const char *)signal_data; server = NULL; channel = NULL; flags = NULL; tags = NULL; ptr_message = NULL; ptr_server = NULL; ptr_channel = NULL; pos_semicol1 = strchr (ptr_string, ';'); if (pos_semicol1) { if (pos_semicol1 > ptr_string + 1) { server = dogechat_strndup (ptr_string, pos_semicol1 - ptr_string); } pos_semicol2 = strchr (pos_semicol1 + 1, ';'); if (pos_semicol2) { if (pos_semicol2 > pos_semicol1 + 1) { channel = dogechat_strndup (pos_semicol1 + 1, pos_semicol2 - pos_semicol1 - 1); } pos_semicol3 = strchr (pos_semicol2 + 1, ';'); if (pos_semicol3) { if (pos_semicol3 > pos_semicol2 + 1) { flags = dogechat_strndup (pos_semicol2 + 1, pos_semicol3 - pos_semicol2 - 1); } pos_semicol4 = strchr (pos_semicol3 + 1, ';'); if (pos_semicol4) { if (pos_semicol4 > pos_semicol3 + 1) { tags = dogechat_strndup (pos_semicol3 + 1, pos_semicol4 - pos_semicol3 - 1); } ptr_message = pos_semicol4 + 1; } } } } flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; if (flags) { error = NULL; flags_value = strtol (flags, &error, 10); if (flags_value < 0) flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; } if (server && ptr_message) { ptr_server = irc_server_search (server); if (ptr_server) { ptr_buffer = ptr_server->buffer; if (channel) { ptr_channel = irc_channel_search (ptr_server, channel); if (ptr_channel) ptr_buffer = ptr_channel->buffer; } /* set tags to use by default */ irc_server_set_send_default_tags (tags); /* send text to buffer, or execute command */ if (dogechat_string_input_for_buffer (ptr_message)) { /* text as input */ irc_input_data (ptr_buffer, ptr_message, flags_value); } else { /* command */ data_with_colors = irc_color_encode ( ptr_message, dogechat_config_boolean (irc_config_network_colors_send)); dogechat_command ( ptr_buffer, (data_with_colors) ? data_with_colors : ptr_message); if (data_with_colors) free (data_with_colors); } /* reset tags to use by default */ irc_server_set_send_default_tags (NULL); } } if (server) free (server); if (channel) free (channel); if (flags) free (flags); if (tags) free (tags); return DOGECHAT_RC_OK; }
const char * irc_info_info_irc_buffer_cb (void *data, const char *info_name, const char *arguments) { char *pos_comma, *pos_comma2, *server, *channel, *host; const char *nick; struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; /* make C compiler happy */ (void) data; (void) info_name; if (!arguments || !arguments[0]) return NULL; server = NULL; channel = NULL; host = NULL; ptr_server = NULL; ptr_channel = NULL; pos_comma = strchr (arguments, ','); if (pos_comma) { server = dogechat_strndup (arguments, pos_comma - arguments); pos_comma2 = strchr (pos_comma + 1, ','); if (pos_comma2) { channel = dogechat_strndup (pos_comma + 1, pos_comma2 - pos_comma - 1); host = strdup (pos_comma2 + 1); } else channel = strdup (pos_comma + 1); } else { if (irc_server_search (arguments)) server = strdup (arguments); else channel = strdup (arguments); } if (server) ptr_server = irc_server_search (server); /* * replace channel by nick in host if channel is not a channel * (private ?) */ if (channel && host) { if (!irc_channel_is_channel (ptr_server, channel)) { free (channel); channel = NULL; nick = irc_message_get_nick_from_host (host); if (nick) channel = strdup (nick); } } /* search for server or channel buffer */ if (server && ptr_server && channel) ptr_channel = irc_channel_search (ptr_server, channel); if (server) free (server); if (channel) free (channel); if (host) free (host); if (ptr_channel) { irc_info_create_string_with_pointer (&ptr_channel->buffer_as_string, ptr_channel->buffer); return ptr_channel->buffer_as_string; } if (ptr_server) { irc_info_create_string_with_pointer (&ptr_server->buffer_as_string, ptr_server->buffer); return ptr_server->buffer_as_string; } return NULL; }
void exec_concat_output (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *text) { int length, new_size; const char *ptr_text; char *new_output, *pos, *line; ptr_text = text; /* if output is not sent as hsignal, display lines (ending with '\n') */ if (!exec_cmd->hsignal) { ptr_text = text; while (ptr_text[0]) { pos = strchr (ptr_text, '\n'); if (!pos) break; if (exec_cmd->output_size[out] > 0) { length = exec_cmd->output_size[out] + (pos - ptr_text) + 1; line = malloc (length); if (line) { memcpy (line, exec_cmd->output[out], exec_cmd->output_size[out]); memcpy (line + exec_cmd->output_size[out], ptr_text, pos - ptr_text); line[length - 1] = '\0'; } } else line = dogechat_strndup (ptr_text, pos - ptr_text); if (!line) break; if (exec_cmd->output[out]) { free (exec_cmd->output[out]); exec_cmd->output[out] = NULL; } exec_cmd->output_size[out] = 0; exec_display_line (exec_cmd, buffer, out, line); free (line); ptr_text = pos + 1; } } /* concatenate ptr_text to output buffer */ length = strlen (ptr_text); if (length > 0) { new_size = exec_cmd->output_size[out] + length; new_output = realloc (exec_cmd->output[out], new_size + 1); if (!new_output) return; exec_cmd->output[out] = new_output; memcpy (exec_cmd->output[out] + exec_cmd->output_size[out], ptr_text, length + 1); exec_cmd->output_size[out] = new_size; } }