Example #1
0
int
gui_layout_add_to_infolist (struct t_infolist *infolist,
                            struct t_gui_layout *layout)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !layout)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "current_layout",
                                   (gui_layout_current == layout) ? 1 : 0))
        return 0;
    if (!infolist_new_var_string (ptr_item, "name", layout->name))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "internal_id", layout->internal_id))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "internal_id_current_window", layout->internal_id_current_window))
        return 0;

    return 1;
}
Example #2
0
int
gui_nicklist_add_nick_to_infolist (struct t_infolist *infolist,
                                   struct t_gui_nick *nick)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !nick)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "type", "nick"))
        return 0;
    if (nick->group)
    {
        if (!infolist_new_var_string (ptr_item, "group_name", nick->group->name))
            return 0;
    }
    if (!infolist_new_var_string (ptr_item, "name", nick->name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "color", nick->color))
        return 0;
    if (!infolist_new_var_string (ptr_item, "prefix", nick->prefix))
        return 0;
    if (!infolist_new_var_string (ptr_item, "prefix_color", nick->prefix_color))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "visible", nick->visible))
        return 0;

    return 1;
}
Example #3
0
int
proxy_add_to_infolist (struct t_infolist *infolist, struct t_proxy *proxy)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !proxy)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "name", proxy->name))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "type", CONFIG_INTEGER(proxy->options[PROXY_OPTION_TYPE])))
        return 0;
    if (!infolist_new_var_string (ptr_item, "type_string", proxy_type_string[CONFIG_INTEGER(proxy->options[PROXY_OPTION_TYPE])]))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "ipv6", CONFIG_INTEGER(proxy->options[PROXY_OPTION_IPV6])))
        return 0;
    if (!infolist_new_var_string (ptr_item, "address", CONFIG_STRING(proxy->options[PROXY_OPTION_ADDRESS])))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "port", CONFIG_INTEGER(proxy->options[PROXY_OPTION_PORT])))
        return 0;
    if (!infolist_new_var_string (ptr_item, "username", CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])))
        return 0;
    if (!infolist_new_var_string (ptr_item, "password", CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])))
        return 0;

    return 1;
}
Example #4
0
int
gui_nicklist_add_group_to_infolist (struct t_infolist *infolist,
                                    struct t_gui_nick_group *group)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !group)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "type", "group"))
        return 0;
    if (group->parent)
    {
        if (!infolist_new_var_string (ptr_item, "parent_name", group->parent->name))
            return 0;
    }
    if (!infolist_new_var_string (ptr_item, "name", group->name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "color", group->color))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "visible", group->visible))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "level", group->level))
        return 0;

    return 1;
}
Example #5
0
int
gui_bar_window_add_to_infolist (struct t_infolist *infolist,
                                struct t_gui_bar_window *bar_window)
{
    struct t_infolist_item *ptr_item;
    int i, j;
    char option_name[64];
    
    if (!infolist || !bar_window)
        return 0;
    
    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;
    
    if (!infolist_new_var_pointer (ptr_item, "bar", bar_window->bar))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "x", bar_window->x))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "y", bar_window->y))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "width", bar_window->width))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "height", bar_window->height))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "scroll_x", bar_window->scroll_x))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "scroll_y", bar_window->scroll_y))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "cursor_x", bar_window->cursor_x))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "cursor_y", bar_window->cursor_y))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "current_size", bar_window->current_size))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "items_count", bar_window->current_size))
        return 0;
    for (i = 0; i < bar_window->items_count; i++)
    {
        for (j = 0; j < bar_window->items_subcount[i]; j++)
        {
            snprintf (option_name, sizeof (option_name),
                      "items_content_%05d_%05d", i + 1, j + 1);
            if (!infolist_new_var_string (ptr_item, option_name,
                                          bar_window->items_content[i][j]))
                return 0;
        }
    }
    if (!infolist_new_var_pointer (ptr_item, "gui_objects", bar_window->gui_objects))
        return 0;
    
    return 1;
}
Example #6
0
int
weeurl_option_add_to_infolist (struct t_infolist *infolist,
                               struct t_url_option *option)
{
    struct t_infolist_item *ptr_item;
    char *constants;
    int i, length;

    if (!infolist || !option)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "name", option->name))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "option", option->option))
        return 0;
    if (!infolist_new_var_string (ptr_item, "type", url_type_string[option->type]))
        return 0;
    if (option->constants)
    {
        length = 1;
        for (i = 0; option->constants[i].name; i++)
        {
            length += strlen (option->constants[i].name) + 1;
        }
        constants = malloc (length);
        if (constants)
        {
            constants[0] = '\0';
            for (i = 0; option->constants[i].name; i++)
            {
                if (i > 0)
                    strcat (constants, ",");
                strcat (constants, option->constants[i].name);
            }
            if (!infolist_new_var_string (ptr_item, "constants", constants))
            {
                free (constants);
                return 0;
            }
            free (constants);
        }
    }

    return 1;
}
Example #7
0
int
gui_filter_add_to_infolist (struct t_infolist *infolist,
                            struct t_gui_filter *filter)
{
    struct t_infolist_item *ptr_item;
    char option_name[64], *tags;
    int i;

    if (!infolist || !filter)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "enabled", filter->enabled))
        return 0;
    if (!infolist_new_var_string (ptr_item, "name", filter->name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "buffer_name", filter->buffer_name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "tags", filter->tags))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "tags_count", filter->tags_count))
        return 0;
    for (i = 0; i < filter->tags_count; i++)
    {
        snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1);
        tags = string_build_with_split_string ((const char **)filter->tags_array[i],
                                               "+");
        if (tags)
        {
            if (!infolist_new_var_string (ptr_item, option_name, tags))
            {
                free (tags);
                return 0;
            }
            free (tags);
        }
    }
    if (!infolist_new_var_string (ptr_item, "regex", filter->regex))
        return 0;

    return 1;
}
Example #8
0
int
gui_history_add_to_infolist (struct t_infolist *infolist,
                             struct t_gui_history *history)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !history)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "text", history->text))
        return 0;

    return 1;
}
Example #9
0
int
upgrade_weechat_save_history (struct t_upgrade_file *upgrade_file,
                              struct t_gui_history *last_history)
{
    struct t_infolist *ptr_infolist;
    struct t_infolist_item *ptr_item;
    struct t_gui_history *ptr_history;
    int rc;

    if (!last_history)
        return 1;

    ptr_infolist = infolist_new (NULL);
    if (!ptr_infolist)
        return 0;

    ptr_history = last_history;
    while (ptr_history)
    {
        ptr_item = infolist_new_item (ptr_infolist);
        if (!ptr_item)
        {
            infolist_free (ptr_infolist);
            return 0;
        }

        if (!infolist_new_var_string (ptr_item, "text", ptr_history->text))
        {
            infolist_free (ptr_infolist);
            return 0;
        }

        ptr_history = ptr_history->prev_history;
    }

    rc = upgrade_file_write_object (upgrade_file,
                                    UPGRADE_WEECHAT_TYPE_HISTORY,
                                    ptr_infolist);
    infolist_free (ptr_infolist);
    if (!rc)
        return 0;

    return 1;
}
Example #10
0
int
upgrade_weechat_save_misc (struct t_upgrade_file *upgrade_file)
{
    struct t_infolist *ptr_infolist;
    struct t_infolist_item *ptr_item;
    int rc;

    ptr_infolist = infolist_new (NULL);
    if (!ptr_infolist)
        return 0;

    ptr_item = infolist_new_item (ptr_infolist);
    if (!ptr_item)
    {
        infolist_free (ptr_infolist);
        return 0;
    }
    if (!infolist_new_var_time (ptr_item, "start_time", weechat_first_start_time))
    {
        infolist_free (ptr_infolist);
        return 0;
    }
    if (!infolist_new_var_integer (ptr_item, "upgrade_count", weechat_upgrade_count))
    {
        infolist_free (ptr_infolist);
        return 0;
    }
    if (!infolist_new_var_integer (ptr_item, "current_window_number", gui_current_window->number))
    {
        infolist_free (ptr_infolist);
        return 0;
    }

    rc = upgrade_file_write_object (upgrade_file,
                                    UPGRADE_WEECHAT_TYPE_MISC,
                                    ptr_infolist);
    infolist_free (ptr_infolist);

    return rc;
}
Example #11
0
int
gui_layout_buffer_add_to_infolist (struct t_infolist *infolist,
                                   struct t_gui_layout_buffer *layout_buffer)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !layout_buffer)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_string (ptr_item, "plugin_name", layout_buffer->plugin_name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "buffer_name", layout_buffer->buffer_name))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "number", layout_buffer->number))
        return 0;

    return 1;
}
Example #12
0
int
gui_filter_add_to_infolist (struct t_infolist *infolist,
                            struct t_gui_filter *filter)
{
    struct t_infolist_item *ptr_item;
    char option_name[64];
    int i;

    if (!infolist || !filter)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "enabled", filter->enabled))
        return 0;
    if (!infolist_new_var_string (ptr_item, "name", filter->name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "buffer_name", filter->buffer_name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "tags", filter->tags))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "tags_count", filter->tags_count))
        return 0;
    for (i = 0; i < filter->tags_count; i++)
    {
        snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1);
        if (!infolist_new_var_string (ptr_item, option_name,
                                      filter->tags_array[i]))
            return 0;
    }
    if (!infolist_new_var_string (ptr_item, "regex", filter->regex))
        return 0;

    return 1;
}
Example #13
0
int
gui_layout_window_add_to_infolist (struct t_infolist *infolist,
                                   struct t_gui_layout_window *layout_window)
{
    struct t_infolist_item *ptr_item;

    if (!infolist || !layout_window)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "internal_id", layout_window->internal_id))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "parent_id",
                                   (layout_window->parent_node) ?
                                   (layout_window->parent_node)->internal_id : 0))
        return 0;
    if (!infolist_new_var_pointer (ptr_item, "parent_node", layout_window->parent_node))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "split_pct", layout_window->split_pct))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "split_horiz", layout_window->split_horiz))
        return 0;
    if (!infolist_new_var_pointer (ptr_item, "child1", layout_window->child1))
        return 0;
    if (!infolist_new_var_pointer (ptr_item, "child2", layout_window->child2))
        return 0;
    if (!infolist_new_var_string (ptr_item, "plugin_name", layout_window->plugin_name))
        return 0;
    if (!infolist_new_var_string (ptr_item, "buffer_name", layout_window->buffer_name))
        return 0;

    return 1;
}
Example #14
0
int
gui_hotlist_add_to_infolist (struct t_infolist *infolist,
                             struct t_gui_hotlist *hotlist)
{
    struct t_infolist_item *ptr_item;
    int i;
    char option_name[64];

    if (!infolist || !hotlist)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "priority", hotlist->priority))
        return 0;
    switch (hotlist->priority)
    {
        case GUI_HOTLIST_LOW:
            if (!infolist_new_var_string (ptr_item, "color",
                                          gui_color_get_name (CONFIG_COLOR(config_color_status_data_other))))
                return 0;
            break;
        case GUI_HOTLIST_MESSAGE:
            if (!infolist_new_var_string (ptr_item, "color",
                                          gui_color_get_name (CONFIG_COLOR(config_color_status_data_msg))))
                return 0;
            break;
        case GUI_HOTLIST_PRIVATE:
            if (!infolist_new_var_string (ptr_item, "color",
                                          gui_color_get_name (CONFIG_COLOR(config_color_status_data_private))))
                return 0;
            break;
        case GUI_HOTLIST_HIGHLIGHT:
            if (!infolist_new_var_string (ptr_item, "color",
                                          gui_color_get_name (CONFIG_COLOR(config_color_status_data_highlight))))
                return 0;
            break;
        case GUI_HOTLIST_NUM_PRIORITIES:
            /*
             * this constant is used to count hotlist priorities only,
             * it is never used as priority
             */
            break;
    }
    if (!infolist_new_var_buffer (ptr_item, "creation_time", &(hotlist->creation_time), sizeof (struct timeval)))
        return 0;
    if (!infolist_new_var_pointer (ptr_item, "buffer_pointer", hotlist->buffer))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "buffer_number", hotlist->buffer->number))
        return 0;
    if (!infolist_new_var_string (ptr_item, "plugin_name", gui_buffer_get_plugin_name (hotlist->buffer)))
        return 0;
    if (!infolist_new_var_string (ptr_item, "buffer_name", hotlist->buffer->name))
        return 0;
    for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
    {
        snprintf (option_name, sizeof (option_name), "count_%02d", i);
        if (!infolist_new_var_integer (ptr_item, option_name, hotlist->count[i]))
            return 0;
    }

    return 1;
}
Example #15
0
int
upgrade_file_read_object (struct t_upgrade_file *upgrade_file)
{
    struct t_infolist *infolist;
    struct t_infolist_item *item;
    int rc, object_id, type, type_var, value, size;
    char *name, *value_str;
    void *buffer;
    time_t time;

    rc = 0;

    infolist = NULL;
    name = NULL;
    value_str = NULL;
    buffer = NULL;

    if (!upgrade_file_read_integer (upgrade_file, &type))
    {
        if (feof (upgrade_file->file))
            rc = 1;
        else
            UPGRADE_ERROR(_("read - object type"), "");
        goto end;
    }

    if (type != UPGRADE_TYPE_OBJECT_START)
    {
        UPGRADE_ERROR(_("read - bad object type ('object start' expected)"), "");
        goto end;
    }

    if (!upgrade_file_read_integer (upgrade_file, &object_id))
    {
        UPGRADE_ERROR(_("read - object id"), "");
        goto end;
    }

    infolist = infolist_new (NULL);
    if (!infolist)
    {
        UPGRADE_ERROR(_("read - infolist creation"), "");
        goto end;
    }
    item = infolist_new_item (infolist);
    if (!item)
    {
        UPGRADE_ERROR(_("read - infolist item creation"), "");
        goto end;
    }

    while (1)
    {
        if (!upgrade_file_read_integer (upgrade_file, &type))
        {
            UPGRADE_ERROR(_("read - object type"), "");
            goto end;
        }

        if (type == UPGRADE_TYPE_OBJECT_END)
            break;

        if (type == UPGRADE_TYPE_OBJECT_VAR)
        {
            if (!upgrade_file_read_string (upgrade_file, &name))
            {
                UPGRADE_ERROR(_("read - variable name"), "");
                goto end;
            }
            if (!name)
            {
                UPGRADE_ERROR(_("read - variable name"), "");
                goto end;
            }
            if (!upgrade_file_read_integer (upgrade_file, &type_var))
            {
                UPGRADE_ERROR(_("read - variable type"), "");
                goto end;
            }

            switch (type_var)
            {
                case INFOLIST_INTEGER:
                    if (!upgrade_file_read_integer (upgrade_file, &value))
                    {
                        UPGRADE_ERROR(_("read - variable"), "integer");
                        goto end;
                    }
                    infolist_new_var_integer (item, name, value);
                    break;
                case INFOLIST_STRING:
                    if (!upgrade_file_read_string (upgrade_file, &value_str))
                    {
                        UPGRADE_ERROR(_("read - variable"), "string");
                        goto end;
                    }
                    infolist_new_var_string (item, name, value_str);
                    break;
                case INFOLIST_POINTER:
                    break;
                case INFOLIST_BUFFER:
                    if (!upgrade_file_read_buffer (upgrade_file, &buffer, &size))
                    {
                        UPGRADE_ERROR(_("read - variable"), "buffer");
                        goto end;
                    }
                    infolist_new_var_buffer (item, name, buffer, size);
                    break;
                case INFOLIST_TIME:
                    if (!upgrade_file_read_time (upgrade_file, &time))
                    {
                        UPGRADE_ERROR(_("read - variable"), "time");
                        goto end;
                    }
                    infolist_new_var_time (item, name, time);
                    break;
            }
        }
    }

    rc = 1;

    if (upgrade_file->callback_read)
    {
        if ((int)(upgrade_file->callback_read) (upgrade_file->callback_read_data,
                                                upgrade_file,
                                                object_id,
                                                infolist) == WEECHAT_RC_ERROR)
            rc = 0;
    }

end:
    if (infolist)
        infolist_free (infolist);
    if (name)
        free (name);
    if (value_str)
        free (value_str);
    if (buffer)
        free (buffer);

    return rc;
}
Example #16
0
int
gui_line_add_to_infolist (struct t_infolist *infolist,
                          struct t_gui_lines *lines,
                          struct t_gui_line *line)
{
    struct t_infolist_item *ptr_item;
    int i, length;
    char option_name[64], *tags;

    if (!infolist || !line)
        return 0;

    ptr_item = infolist_new_item (infolist);
    if (!ptr_item)
        return 0;

    if (!infolist_new_var_integer (ptr_item, "y", line->data->y))
        return 0;
    if (!infolist_new_var_time (ptr_item, "date", line->data->date))
        return 0;
    if (!infolist_new_var_time (ptr_item, "date_printed", line->data->date_printed))
        return 0;
    if (!infolist_new_var_string (ptr_item, "str_time", line->data->str_time))
        return 0;

    /* write tags */
    if (!infolist_new_var_integer (ptr_item, "tags_count", line->data->tags_count))
        return 0;
    length = 0;
    for (i = 0; i < line->data->tags_count; i++)
    {
        snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1);
        if (!infolist_new_var_string (ptr_item, option_name,
                                      line->data->tags_array[i]))
            return 0;
        length += strlen (line->data->tags_array[i]) + 1;
    }
    tags = malloc (length + 1);
    if (!tags)
        return 0;
    tags[0] = '\0';
    for (i = 0; i < line->data->tags_count; i++)
    {
        strcat (tags, line->data->tags_array[i]);
        if (i < line->data->tags_count - 1)
            strcat (tags, ",");
    }
    if (!infolist_new_var_string (ptr_item, "tags", tags))
    {
        free (tags);
        return 0;
    }
    free (tags);

    if (!infolist_new_var_integer (ptr_item, "displayed", line->data->displayed))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "highlight", line->data->highlight))
        return 0;
    if (!infolist_new_var_string (ptr_item, "prefix", line->data->prefix))
        return 0;
    if (!infolist_new_var_string (ptr_item, "message", line->data->message))
        return 0;
    if (!infolist_new_var_integer (ptr_item, "last_read_line",
                                   (lines->last_read_line == line) ? 1 : 0))
        return 0;

    return 1;
}