Example #1
0
struct t_infolist *
hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
                   void *pointer, const char *arguments)
{
    struct t_hook *ptr_hook, *next_hook;
    struct t_infolist *value;

    /* make C compiler happy */
    (void) plugin;

    if (!infolist_name || !infolist_name[0])
        return NULL;

    hook_exec_start ();

    ptr_hook = weechat_hooks[HOOK_TYPE_INFOLIST];
    while (ptr_hook)
    {
        next_hook = ptr_hook->next_hook;

        if (!ptr_hook->deleted
            && !ptr_hook->running
            && (string_strcasecmp (HOOK_INFOLIST(ptr_hook, infolist_name),
                                   infolist_name) == 0))
        {
            ptr_hook->running = 1;
            value = (HOOK_INFOLIST(ptr_hook, callback))
                (ptr_hook->callback_pointer,
                 ptr_hook->callback_data,
                 infolist_name,
                 pointer,
                 arguments);
            ptr_hook->running = 0;

            hook_exec_end ();
            return value;
        }

        ptr_hook = next_hook;
    }

    hook_exec_end ();

    /* infolist not found */
    return NULL;
}
struct t_hashtable *
hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
                         struct t_hashtable *hashtable)
{
    struct t_hook *ptr_hook, *next_hook;
    struct t_hashtable *value;

    /* make C compiler happy */
    (void) plugin;

    if (!info_name || !info_name[0])
        return NULL;

    hook_exec_start ();

    ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE];
    while (ptr_hook)
    {
        next_hook = ptr_hook->next_hook;

        if (!ptr_hook->deleted
            && !ptr_hook->running
            && (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name),
                                   info_name) == 0))
        {
            ptr_hook->running = 1;
            value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
                (ptr_hook->callback_pointer,
                 ptr_hook->callback_data,
                 info_name,
                 hashtable);
            ptr_hook->running = 0;

            hook_exec_end ();
            return value;
        }

        ptr_hook = next_hook;
    }

    hook_exec_end ();

    /* info not found */
    return NULL;
}
Example #3
0
void
hook_timer_exec ()
{
    struct timeval tv_time;
    struct t_hook *ptr_hook, *next_hook;

    if (!weechat_hooks[HOOK_TYPE_TIMER])
        return;

    hook_timer_check_system_clock ();

    gettimeofday (&tv_time, NULL);

    hook_exec_start ();

    ptr_hook = weechat_hooks[HOOK_TYPE_TIMER];
    while (ptr_hook)
    {
        next_hook = ptr_hook->next_hook;

        if (!ptr_hook->deleted
            && !ptr_hook->running
            && (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec),
                                  &tv_time) <= 0))
        {
            ptr_hook->running = 1;
            (void) (HOOK_TIMER(ptr_hook, callback))
                (ptr_hook->callback_pointer,
                 ptr_hook->callback_data,
                 (HOOK_TIMER(ptr_hook, remaining_calls) > 0) ?
                  HOOK_TIMER(ptr_hook, remaining_calls) - 1 : -1);
            ptr_hook->running = 0;
            if (!ptr_hook->deleted)
            {
                HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec;
                HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec;

                util_timeval_add (
                    &HOOK_TIMER(ptr_hook, next_exec),
                    ((long long)HOOK_TIMER(ptr_hook, interval)) * 1000);

                if (HOOK_TIMER(ptr_hook, remaining_calls) > 0)
                {
                    HOOK_TIMER(ptr_hook, remaining_calls)--;
                    if (HOOK_TIMER(ptr_hook, remaining_calls) == 0)
                        unhook (ptr_hook);
                }
            }
        }

        ptr_hook = next_hook;
    }

    hook_exec_end ();
}
Example #4
0
void
hook_line_exec (struct t_gui_line *line)
{
    struct t_hook *ptr_hook, *next_hook;
    struct t_hashtable *hashtable, *hashtable2;
    char str_value[128], *str_tags;

    if (!weechat_hooks[HOOK_TYPE_LINE])
        return;

    hashtable = NULL;

    hook_exec_start ();

    ptr_hook = weechat_hooks[HOOK_TYPE_LINE];
    while (ptr_hook)
    {
        next_hook = ptr_hook->next_hook;

        if (!ptr_hook->deleted && !ptr_hook->running
            && ((HOOK_LINE(ptr_hook, buffer_type) == -1)
                || ((int)(line->data->buffer->type) == (HOOK_LINE(ptr_hook, buffer_type))))
            && string_match_list (line->data->buffer->full_name,
                                  (const char **)HOOK_LINE(ptr_hook, buffers),
                                  0)
            && (!HOOK_LINE(ptr_hook, tags_array)
                || gui_line_match_tags (line->data,
                                        HOOK_LINE(ptr_hook, tags_count),
                                        HOOK_LINE(ptr_hook, tags_array))))
        {
            /* create the hashtable that will be sent to callback */
            if (!hashtable)
            {
                hashtable = hashtable_new (32,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL, NULL);
                if (!hashtable)
                    break;
            }
            HASHTABLE_SET_POINTER("buffer", line->data->buffer);
            HASHTABLE_SET_STR("buffer_name", line->data->buffer->full_name);
            HASHTABLE_SET_STR("buffer_type",
                              gui_buffer_type_string[line->data->buffer->type]);
            HASHTABLE_SET_INT("y", line->data->y);
            HASHTABLE_SET_TIME("date", line->data->date);
            HASHTABLE_SET_TIME("date_printed", line->data->date_printed);
            HASHTABLE_SET_STR_NOT_NULL("str_time", line->data->str_time);
            HASHTABLE_SET_INT("tags_count", line->data->tags_count);
            str_tags = string_build_with_split_string (
                (const char **)line->data->tags_array, ",");
            HASHTABLE_SET_STR_NOT_NULL("tags", str_tags);
            if (str_tags)
                free (str_tags);
            HASHTABLE_SET_INT("displayed", line->data->displayed);
            HASHTABLE_SET_INT("notify_level", line->data->notify_level);
            HASHTABLE_SET_INT("highlight", line->data->highlight);
            HASHTABLE_SET_STR_NOT_NULL("prefix", line->data->prefix);
            HASHTABLE_SET_STR_NOT_NULL("message", line->data->message);

            /* run callback */
            ptr_hook->running = 1;
            hashtable2 = (HOOK_LINE(ptr_hook, callback))
                (ptr_hook->callback_pointer,
                 ptr_hook->callback_data,
                 hashtable);
            ptr_hook->running = 0;

            if (hashtable2)
            {
                gui_line_hook_update (line, hashtable, hashtable2);
                hashtable_free (hashtable2);
                if (!line->data->buffer)
                    break;
            }
        }

        ptr_hook = next_hook;
    }

    hook_exec_end ();

    if (hashtable)
        hashtable_free (hashtable);
}