int upgrade_weechat_save_hotlist (struct t_upgrade_file *upgrade_file) { struct t_infolist *ptr_infolist; struct t_gui_hotlist *ptr_hotlist; int rc; for (ptr_hotlist = gui_hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) { ptr_infolist = infolist_new (NULL); if (!ptr_infolist) return 0; if (!gui_hotlist_add_to_infolist (ptr_infolist, ptr_hotlist)) { infolist_free (ptr_infolist); return 0; } rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_HOTLIST, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; } return 1; }
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; }
int upgrade_weechat_save_layout_window_tree (struct t_upgrade_file *upgrade_file, struct t_gui_layout_window *layout_window) { struct t_infolist *ptr_infolist; int rc; ptr_infolist = infolist_new (NULL); if (!ptr_infolist) return 0; if (!gui_layout_window_add_to_infolist (ptr_infolist, layout_window)) { infolist_free (ptr_infolist); return 0; } rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; if (layout_window->child1) { if (!upgrade_weechat_save_layout_window_tree (upgrade_file, layout_window->child1)) return 0; } if (layout_window->child2) { if (!upgrade_weechat_save_layout_window_tree (upgrade_file, layout_window->child2)) return 0; } return 1; }
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; }
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; }
struct t_infolist * plugin_api_infolist_get_internal (void *data, const char *infolist_name, void *pointer, const char *arguments) { struct t_infolist *ptr_infolist; struct t_gui_bar *ptr_bar; struct t_gui_bar_item *ptr_bar_item; struct t_gui_bar_window *ptr_bar_window; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; struct t_gui_history *ptr_history; struct t_gui_filter *ptr_filter; struct t_gui_window *ptr_window; struct t_gui_hotlist *ptr_hotlist; struct t_gui_key *ptr_key; struct t_weechat_plugin *ptr_plugin; struct t_proxy *ptr_proxy; struct t_gui_layout *ptr_layout; int context, number, i; char *error; /* make C compiler happy */ (void) data; if (!infolist_name || !infolist_name[0]) return NULL; if (string_strcasecmp (infolist_name, "bar") == 0) { /* invalid bar pointer ? */ if (pointer && (!gui_bar_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one bar */ if (!gui_bar_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all bars matching arguments */ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { if (!arguments || !arguments[0] || string_match (ptr_bar->name, arguments, 0)) { if (!gui_bar_add_to_infolist (ptr_infolist, ptr_bar)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "bar_item") == 0) { /* invalid bar item pointer ? */ if (pointer && (!gui_bar_item_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one bar item */ if (!gui_bar_item_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all bar items matching arguments */ for (ptr_bar_item = gui_bar_items; ptr_bar_item; ptr_bar_item = ptr_bar_item->next_item) { if (!arguments || !arguments[0] || string_match (ptr_bar_item->name, arguments, 0)) { if (!gui_bar_item_add_to_infolist (ptr_infolist, ptr_bar_item)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "bar_window") == 0) { /* invalid bar window pointer ? */ if (pointer && (!gui_bar_window_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one bar window */ if (!gui_bar_window_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all bar windows (from root and window bars) */ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { if (ptr_bar->bar_window) { if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar->bar_window)) { infolist_free (ptr_infolist); return NULL; } } } for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window) { for (ptr_bar_window = ptr_window->bar_windows; ptr_bar_window; ptr_bar_window = ptr_bar_window->next_bar_window) { if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar_window)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "buffer") == 0) { /* invalid buffer pointer ? */ if (pointer && (!gui_buffer_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one buffer */ if (!gui_buffer_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all buffers matching arguments */ for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { if (!arguments || !arguments[0] || string_match (ptr_buffer->full_name, arguments, 0)) { if (!gui_buffer_add_to_infolist (ptr_infolist, ptr_buffer)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "buffer_lines") == 0) { if (!pointer) pointer = gui_buffers; else { /* invalid buffer pointer ? */ if (!gui_buffer_valid (pointer)) return NULL; } ptr_infolist = infolist_new (); if (ptr_infolist) { for (ptr_line = ((struct t_gui_buffer *)pointer)->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (!gui_line_add_to_infolist (ptr_infolist, ((struct t_gui_buffer *)pointer)->own_lines, ptr_line)) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "filter") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { for (ptr_filter = gui_filters; ptr_filter; ptr_filter = ptr_filter->next_filter) { if (!arguments || !arguments[0] || string_match (ptr_filter->name, arguments, 0)) { if (!gui_filter_add_to_infolist (ptr_infolist, ptr_filter)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "history") == 0) { /* invalid buffer pointer ? */ if (pointer && (!gui_buffer_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { for (ptr_history = (pointer) ? ((struct t_gui_buffer *)pointer)->history : gui_history; ptr_history; ptr_history = ptr_history->next_history) { if (!gui_history_add_to_infolist (ptr_infolist, ptr_history)) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "hook") == 0) { /* invalid hook pointer ? */ if (pointer && !hook_valid (pointer)) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (!hook_add_to_infolist (ptr_infolist, pointer, arguments)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "hotlist") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { for (ptr_hotlist = gui_hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) { if (!gui_hotlist_add_to_infolist (ptr_infolist, ptr_hotlist)) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "key") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { if (arguments && arguments[0]) context = gui_key_search_context (arguments); else context = GUI_KEY_CONTEXT_DEFAULT; if (context >= 0) { for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key) { if (!gui_key_add_to_infolist (ptr_infolist, ptr_key)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "layout") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { for (ptr_layout = gui_layouts; ptr_layout; ptr_layout = ptr_layout->next_layout) { if (!gui_layout_add_to_infolist (ptr_infolist,ptr_layout)) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "nicklist") == 0) { /* invalid buffer pointer ? */ if (!pointer || (!gui_buffer_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (!gui_nicklist_add_to_infolist (ptr_infolist, pointer, arguments)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "option") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { if (!config_file_add_to_infolist (ptr_infolist, arguments)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "plugin") == 0) { /* invalid plugin pointer ? */ if (pointer && (!plugin_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one plugin */ if (!plugin_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all plugins matching arguments */ for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) { if (!arguments || !arguments[0] || string_match (ptr_plugin->name, arguments, 0)) { if (!plugin_add_to_infolist (ptr_infolist, ptr_plugin)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "proxy") == 0) { /* invalid proxy pointer ? */ if (pointer && (!proxy_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one proxy */ if (!proxy_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all proxies matching arguments */ for (ptr_proxy = weechat_proxies; ptr_proxy; ptr_proxy = ptr_proxy->next_proxy) { if (!arguments || !arguments[0] || string_match (ptr_proxy->name, arguments, 0)) { if (!proxy_add_to_infolist (ptr_infolist, ptr_proxy)) { infolist_free (ptr_infolist); return NULL; } } } return ptr_infolist; } } } else if (string_strcasecmp (infolist_name, "url_options") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { for (i = 0; url_options[i].name; i++) { if (!weeurl_option_add_to_infolist (ptr_infolist, &url_options[i])) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } else if (string_strcasecmp (infolist_name, "window") == 0) { /* invalid window pointer ? */ if (pointer && (!gui_window_valid (pointer))) return NULL; ptr_infolist = infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one window */ if (!gui_window_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { if (arguments && arguments[0]) { if ((string_strcasecmp (arguments, "current") == 0)) { if (gui_current_window) { if (!gui_window_add_to_infolist (ptr_infolist, gui_current_window)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } return NULL; } /* check if argument is a window number */ error = NULL; number = (int)strtol (arguments, &error, 10); if (error && !error[0]) { ptr_window = gui_window_search_by_number (number); if (ptr_window) { if (!gui_window_add_to_infolist (ptr_infolist, ptr_window)) { infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } } return NULL; } else { /* build list with all windows */ for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window) { if (!gui_window_add_to_infolist (ptr_infolist, ptr_window)) { infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } } } /* infolist not found */ return NULL; }
int upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) { struct t_infolist *ptr_infolist; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; int rc; for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { /* save buffer */ ptr_infolist = infolist_new (NULL); if (!ptr_infolist) return 0; if (!gui_buffer_add_to_infolist (ptr_infolist, ptr_buffer)) { infolist_free (ptr_infolist); return 0; } rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_BUFFER, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; /* save nicklist */ if (ptr_buffer->nicklist) { ptr_infolist = infolist_new (NULL); if (!ptr_infolist) return 0; if (!gui_nicklist_add_to_infolist (ptr_infolist, ptr_buffer, NULL)) { infolist_free (ptr_infolist); return 0; } rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_NICKLIST, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; } /* save buffer lines */ for (ptr_line = ptr_buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { ptr_infolist = infolist_new (NULL); if (!ptr_infolist) return 0; if (!gui_line_add_to_infolist (ptr_infolist, ptr_buffer->own_lines, ptr_line)) { infolist_free (ptr_infolist); return 0; } rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_BUFFER_LINE, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; } /* save command/text history of buffer */ if (ptr_buffer->history) { rc = upgrade_weechat_save_history (upgrade_file, ptr_buffer->last_history); if (!rc) return 0; } } return 1; }