Esempio n. 1
0
static gboolean
_eventd_nd_event_timedout(gpointer user_data)
{
    EventdNdNotification *self = user_data;
    EventdEvent *event;

    self->timeout = 0;
    event = eventd_event_new(".notification", "timeout");
    eventd_event_add_data_string(event, g_strdup("source-event"), g_strdup(eventd_event_get_uuid(self->event)));
    eventd_plugin_core_push_event(self->context->core, event);
    eventd_event_unref(event);

    return G_SOURCE_REMOVE;
}
Esempio n. 2
0
void
eventd_nd_notification_dismiss(EventdNdNotification *self)
{
    if ( self->event == NULL )
    {
        eventd_nd_notification_dismiss_target(self->context, EVENTD_ND_DISMISS_ALL, self->queue);
        return;
    }

    EventdEvent *event;
    event = eventd_event_new(".notification", "dismiss");
    eventd_event_add_data_string(event, g_strdup("source-event"), g_strdup(eventd_event_get_uuid(self->event)));
    eventd_plugin_core_push_event(self->context->core, event);
    eventd_event_unref(event);
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
    int r = 0;
    gchar *host = NULL;
    gchar **event_data_name = NULL;
    gchar **event_data_content = NULL;

    gboolean print_version = FALSE;

    GOptionEntry entries[] =
    {
        { "data-name",    'd', 0, G_OPTION_ARG_STRING_ARRAY, &event_data_name,    "Event data name to send",                                "<name>" },
        { "data-content", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &event_data_content, "Event data content to send (must be after a data-name)", "<content>" },
        { "host",         'h', 0, G_OPTION_ARG_STRING,       &host,               "Host to connect to",                                     "<host>" },
        { "max-tries",    'm', 0, G_OPTION_ARG_INT,          &max_tries,          "Maximum connection attempts (0 for infinite)",           "<times>" },
        { "wait",         'w', 0, G_OPTION_ARG_NONE,         &wait_event_end,     "Wait the end of the event",                              NULL },
        { "version",      'V', 0, G_OPTION_ARG_NONE,         &print_version,      "Print version",                                          NULL },
        { NULL }
    };
    GOptionContext *opt_context = g_option_context_new("<event category> <event name> - Basic CLI client for eventd");

    g_option_context_add_main_entries(opt_context, entries, GETTEXT_PACKAGE);

    GError *error = NULL;
    if ( ! g_option_context_parse(opt_context, &argc, &argv, &error) )
    {
        g_warning("Couldn't parse the arguments: %s", error->message);
        g_option_context_free(opt_context);
        return 1;
    }
    g_option_context_free(opt_context);

    if ( print_version )
    {
        g_print("eventc %s (using libeventc %s)\n",
            PACKAGE_VERSION,
            eventc_get_version());
        goto end;
    }

    r = 1; /* We are checking arguments */

    if ( argc < 2 )
    {
        g_print("You must define the category of the event.\n");
        goto end;
    }
    if ( argc < 3 )
    {
        g_print("You must define the name of the event.\n");
        goto end;
    }
    guint n_length, c_length;

    n_length = ( event_data_name == NULL ) ? 0 : g_strv_length(event_data_name);
    c_length = ( event_data_content == NULL ) ? 0 : g_strv_length(event_data_content);
    if ( n_length != c_length )
    {
        g_warning("Not the same number of data names and data contents");
        g_strfreev(event_data_name);
        g_strfreev(event_data_content);
        goto end;
    }

    r = 0; /* Arguments are fine */

    const gchar *category = argv[1];
    const gchar *name = argv[2];

    client = eventc_connection_new(host);
    eventc_connection_set_passive(client, !wait_event_end);

    event = eventd_event_new(category, name);

    GHashTable *data;

    data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

    guint i;
    for ( i = 0 ; i < n_length ; ++i )
        g_hash_table_insert(data, event_data_name[i], event_data_content[i]);
    g_free(event_data_name);
    g_free(event_data_content);

    eventd_event_set_all_data(event, data);

    g_idle_add(_eventc_connect, NULL);

    loop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(loop);
    g_main_loop_unref(loop);

    g_object_unref(event);

    g_object_unref(client);

end:
    g_free(host);

    return r;
}