static gboolean _eventc_light_connection_expect_disconnected(EventcLightConnection *self, gint *error) { if ( ( ! eventc_light_connection_is_connected(self, error) ) && ( *error == 0 ) ) return TRUE; if ( *error == 0 ) *error = -EISCONN; return FALSE; }
/** * eventc_light_connection_close: * @connection: an #EventcLightConnection * * Closes the connection. * * Returns: 0 if the connection was successfully closed, a negative %errno value otherwise */ EVENTD_EXPORT gint eventc_light_connection_close(EventcLightConnection *self) { g_return_val_if_fail(self != NULL, -EFAULT); gint error = 0; if ( eventc_light_connection_is_connected(self, &error) ) _eventc_light_connection_send_message(self, eventd_protocol_generate_bye(self->protocol, NULL)); else if ( error != 0 ) return error; _eventc_light_connection_close_internal(self); return 0; }
static void _wec_disconnect(void) { if ( _wec_context.connect_hook != NULL ) weechat_unhook(_wec_context.connect_hook); gint error = 0; if ( eventc_light_connection_is_connected(_wec_context.client, &error) ) { weechat_unhook(_wec_context.fd_hook); eventc_light_connection_close(_wec_context.client); } _wec_context.connect_hook = NULL; _wec_context.fd = 0; _wec_context.fd_hook = NULL; }
static gint _wec_try_connect(gconstpointer user_data, gpointer data, gint remaining_calls) { gint error = 0; if ( eventc_light_connection_is_connected(_wec_context.client, &error) ) return WEECHAT_RC_OK; if ( _wec_context.connect_hook != NULL ) return WEECHAT_RC_ERROR; if ( eventc_light_connection_connect(_wec_context.client) < 0 ) { _wec_context.connect_hook = weechat_hook_timer(GPOINTER_TO_UINT(user_data) * 1000, 60, 1, _wec_try_connect, GUINT_TO_POINTER(GPOINTER_TO_UINT(user_data) * 2), NULL); return WEECHAT_RC_ERROR; } _wec_context.connect_hook = NULL; _wec_context.fd = eventc_light_connection_get_socket(_wec_context.client); _wec_context.fd_hook = weechat_hook_fd(_wec_context.fd, 1, 0, 0, _wec_fd_callback, NULL, NULL); return WEECHAT_RC_OK; }
static gint _wec_print_callback(gconstpointer user_data, gpointer data, struct t_gui_buffer *buffer, time_t date, gint tags_count, const gchar **tags, gint displayed, gint highlight, const gchar *prefix, const gchar *message) { if ( ( ! displayed ) || ( buffer == NULL ) ) return WEECHAT_RC_OK; const gchar *plugin = weechat_buffer_get_string(buffer, "plugin"); if ( g_strcmp0(plugin, "irc") != 0 ) return WEECHAT_RC_OK; if ( _wec_config_boolean(restrictions, ignore_current_buffer) && ( buffer == weechat_current_buffer() ) ) return WEECHAT_RC_OK; gint error = 0; if ( ! eventc_light_connection_is_connected(_wec_context.client, &error) ) return WEECHAT_RC_OK; const gchar *category = NULL; const gchar *name = NULL; const gchar *channel = NULL; const gchar *buffer_type = weechat_buffer_get_string(buffer, "localvar_type"); if ( g_strcmp0(buffer_type, "channel") == 0 ) { category = "chat"; channel = weechat_buffer_get_string(buffer, "localvar_channel"); } else if ( g_strcmp0(buffer_type, "private") == 0 ) category = "im"; const gchar *nick = NULL; gchar *msg = NULL; gint i; for ( i = 0 ; i < tags_count ; ++i ) { const gchar *tag = tags[i]; if ( g_str_has_prefix(tag, "log") || g_str_has_prefix(tag, "no_") ) continue; if ( ( g_strcmp0(tag, "away_info") == 0 ) || ( g_strcmp0(tag, "notify_none") == 0 ) ) goto cleanup; if ( g_str_has_prefix(tag, "irc_") ) { tag += strlen("irc_"); if ( g_strcmp0(tag, "privmsg") == 0 ) { if ( highlight && _wec_config_boolean(events, highlight) ) { name = "highlight"; continue; } if ( ( channel != NULL ) && ( ! _wec_config_boolean(events, chat) ) ) break; if ( ! _wec_config_boolean(events, im) ) break; name = "received"; } else if ( g_strcmp0(tag, "notice") == 0 ) { category = "im"; if ( highlight && _wec_config_boolean(events, highlight) ) { name = "highlight"; continue; } if ( ! _wec_config_boolean(events, notice) ) break; name = "received"; } else if ( g_str_has_prefix(tag, "notify_") ) { if ( ! _wec_config_boolean(events, notify) ) break; tag += strlen("notify_"); category = "presence"; if ( g_strcmp0(tag, "join") == 0 ) name = "signed-on"; else if ( g_strcmp0(tag, "quit") == 0 ) name = "signed-off"; else if ( g_strcmp0(tag, "back") == 0 ) name = "back"; else if ( g_strcmp0(tag, "away") == 0 ) { name = "away"; msg = _wec_split_message(message); } else if ( g_strcmp0(tag, "still_away") == 0 ) { name = "message"; msg = _wec_split_message(message); } } else if ( g_strcmp0(tag, "join") == 0 ) { if ( ! _wec_config_boolean(events, join) ) break; category = "presence"; name = "join"; } else if ( g_strcmp0(tag, "leave") == 0 ) { if ( ! _wec_config_boolean(events, leave) ) break; category = "presence"; name = "leave"; } else if ( g_strcmp0(tag, "quit") == 0 ) { if ( ! _wec_config_boolean(events, quit) ) break; category = "presence"; name = "signed-off"; } } else if ( g_str_has_prefix(tag, "nick_") ) nick = tag + strlen("nick_"); } if ( ( category == NULL ) || ( name == NULL ) ) goto cleanup; if ( g_hash_table_contains(_wec_context.blacklist, nick) ) goto cleanup; EventdEvent *event; event = eventd_event_new(category, name); if ( nick != NULL ) eventd_event_add_data_string(event, g_strdup("buddy-name"), g_strdup(nick)); if ( channel != NULL ) eventd_event_add_data_string(event, g_strdup("channel"), g_strdup(channel)); eventd_event_add_data_string(event, g_strdup("message"), ( msg != NULL ) ? msg : g_strdup(message)); msg = NULL; eventc_light_connection_event(_wec_context.client, event); eventd_event_unref(event); cleanup: g_free(msg); return WEECHAT_RC_OK; }