NetSurf
Macros | Functions | Variables
messages.c File Reference

Localised message support implementation. More...

#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <zlib.h>
#include <stdarg.h>
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/hashtable.h"
Include dependency graph for messages.c:

Go to the source code of this file.

Macros

#define HASH_SIZE   101
 Messages are stored in a fixed-size hash table. More...
 

Functions

static struct hash_tablemessages_create_ctx (int hash_size)
 Create a message context. More...
 
static void messages_destroy_ctx (struct hash_table *ctx)
 Free memory used by a messages hash. More...
 
static nserror messages_load_ctx (const char *path, struct hash_table **ctx)
 Read keys and values from messages file. More...
 
static const char * messages_get_ctx (const char *key, struct hash_table *ctx)
 Fast lookup of a message by key. More...
 
nserror messages_add_from_file (const char *path)
 Read keys and values from messages file into the standard Messages hash. More...
 
nserror messages_add_from_inline (const uint8_t *data, size_t size)
 Read keys and values from inline message data into the standard Messages hash. More...
 
char * messages_get_buff (const char *key,...)
 Formatted message from a key in the global message hash. More...
 
const char * messages_get (const char *key)
 Fast lookup of a message by key from the standard Messages hash. More...
 
const char * messages_get_errorcode (nserror code)
 lookup of a message by errorcode from the standard Messages hash. More...
 
const char * messages_get_sslcode (ssl_cert_err code)
 lookup of a message by SSL error code from the standard Messages hash. More...
 
void messages_destroy (void)
 Free memory used by the standard Messages hash. More...
 

Variables

static struct hash_tablemessages_hash = NULL
 The hash table used to store the standard Messages file for the old API. More...
 

Detailed Description

Localised message support implementation.

Native language messages are loaded from a file and stored hashed by key for fast access.

Definition in file messages.c.

Macro Definition Documentation

◆ HASH_SIZE

#define HASH_SIZE   101

Messages are stored in a fixed-size hash table.

Definition at line 43 of file messages.c.

Function Documentation

◆ messages_add_from_file()

nserror messages_add_from_file ( const char *  path)

Read keys and values from messages file into the standard Messages hash.

The messages are merged with any previously loaded messages. Any keys which are present already are replaced with the new value. The file may be gzip compressed.

Parameters
pathpathname of messages file.
Returns
NSERROR_OK on success or error code on faliure.

Definition at line 177 of file messages.c.

References messages_hash, messages_load_ctx(), NSERROR_BAD_PARAMETER, NSLOG, and path().

Referenced by ami_theme_init(), gui_init_replicant(), main(), nsgtk_messages_init(), and nsw32_messages_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_add_from_inline()

nserror messages_add_from_inline ( const uint8_t *  data,
size_t  data_size 
)

Read keys and values from inline message data into the standard Messages hash.

The messages are merged with any previously loaded messages. Any keys which are present already are replaced with the new value. The data may be gzip compressed.

Parameters
dataThe inline message data.
data_sizeThe length of the message data.
Returns
NSERROR_OK on success or error code on faliure.

Definition at line 190 of file messages.c.

References hash_add_inline(), HASH_SIZE, messages_create_ctx(), messages_hash, NSERROR_NOMEM, and NSLOG.

Referenced by main(), nsgtk_messages_init(), and nsw32_messages_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_create_ctx()

static struct hash_table * messages_create_ctx ( int  hash_size)
static

Create a message context.

generate a message context populated with english fallbacks for some formatted messages.

Definition at line 57 of file messages.c.

References hash_add(), and hash_create().

Referenced by messages_add_from_inline(), and messages_load_ctx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_destroy()

void messages_destroy ( void  )

Free memory used by the standard Messages hash.

Definition at line 463 of file messages.c.

References messages_destroy_ctx(), and messages_hash.

Referenced by netsurf_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_destroy_ctx()

static void messages_destroy_ctx ( struct hash_table ctx)
static

Free memory used by a messages hash.

The context will not be valid after this function returns.

Parameters
ctxcontext of messages file to free

Definition at line 98 of file messages.c.

References hash_destroy().

Referenced by messages_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_get()

const char * messages_get ( const char *  key)

Fast lookup of a message by key from the standard Messages hash.

Parameters
keykey of message
Returns
value of message, or key if not found

Definition at line 241 of file messages.c.

References messages_get_ctx(), and messages_hash.

Referenced by ami_cookies_present(), ami_datatype_object_from_bitmap(), ami_download_check_overwrite(), ami_file_open(), ami_file_save_req(), ami_font_scan_gui_open(), ami_get_theme_filename(), ami_gui_close_tabs(), ami_gui_hotlist_scan(), ami_gui_opts_setup(), ami_history_global_present(), ami_history_local_present(), ami_hotlist_present(), ami_menu_alloc_item(), ami_menu_scan(), ami_misc_req(), ami_pageinfo_open(), ami_print_progress(), ami_print_ui_setup(), ami_quit_netsurf_delayed(), ami_search_open(), ami_theme_throbber_setup(), amiga_warn_user(), amiga_warn_user_multi(), atari_cookie_manager_init(), atari_global_history_init(), atari_hotlist_init(), atari_warn_user(), box_input(), box_select(), browser_window__handle_error(), content__init(), content_llcache_callback(), content_update_status(), cookie_manager_init_common_values(), cookie_manager_init_entry_fields(), cookie_manager_set_treeview_field_data(), cutomize_button_clicked_cb(), dcgettext(), default_mouse_action(), die(), dirlist_generate_headings(), dirlist_generate_parent_link(), dirlist_generate_row(), editor_init(), fetch_curl_process_headers(), fetch_curl_progress(), fetch_file_process_error(), fetch_resource_notfound_handler(), form__select_process_selection(), form_select_mouse_action(), gadget_mouse_action(), gen_nice_title(), global_history_create_dir(), global_history_create_treeview_field_data(), global_history_initialise_entry_fields(), gui_download_window_create(), gui_download_window_data(), gui_download_window_done(), gui_download_window_error(), gui_file_gadget_open(), gui_init2(), gui_launch_url(), gui_window_create(), gui_window_save_link(), hlcache_migrate_ctx(), HOOKF(), hotlist_add_folder_internal(), hotlist_add_url(), hotlist_generate(), hotlist_initialise_entry_fields(), hotlist_load(), hotlist_load_entry(), html_encoding(), html_finish_conversion(), html_redraw_file(), human_friendly_bytesize(), init_about_dialog(), llcache_fetch_cert_error(), llcache_fetch_redirect(), llcache_fetch_ssl_error(), make_menu_item(), make_toolbar_item_button(), make_toolbar_item_history(), make_toolbar_item_throbber(), menu_open_file(), navigate_internal_real(), nsbeos_new_scaffolding(), nsfont_check_fonts(), nsgtk_about_dialog_init(), nsgtk_check_for_downloads(), nsgtk_download_change_status(), nsgtk_download_dialog_show(), nsgtk_download_handle_error(), nsgtk_download_info_to_string(), nsgtk_download_tree_view_new(), nsgtk_download_update(), nsgtk_menu_add_image_item(), nsgtk_menu_developer_submenu(), nsgtk_menu_edit_submenu(), nsgtk_menu_export_submenu(), nsgtk_menu_file_submenu(), nsgtk_menu_help_submenu(), nsgtk_menu_nav_submenu(), nsgtk_menu_scaleview_submenu(), nsgtk_menu_tabs_submenu(), nsgtk_menu_toolbars_submenu(), nsgtk_menu_tools_submenu(), nsgtk_menu_view_submenu(), nsgtk_on_viewdata_save_as_activate(), nsgtk_saveas_dialog(), nsgtk_viewdata_file_save(), nsgtk_viewsource(), nsgtk_warning(), nsw32_about_dialog_init(), nsws_download_update_label(), nsws_prefs_font_prepare(), plaintext_button_clicked_cb(), print_button_clicked_cb(), print_fonts_callback(), process_dir_ent(), query_user_xy(), riscos_bitmap_save(), ro_cookie_init(), ro_global_history_init(), ro_gui_configure_register(), ro_gui_configure_translate(), ro_gui_download_save(), ro_gui_download_update_status(), ro_gui_hotlist_remove_page(), ro_gui_interactive_help_broadcast(), ro_gui_menu_translate(), ro_gui_options_fonts_init_menu(), ro_gui_options_language_name(), ro_gui_save_content(), ro_gui_save_set_state(), ro_gui_search_init(), ro_gui_search_set_status(), ro_gui_url_file_parse(), ro_gui_window_prepare_form_select_menu(), ro_gui_window_prepare_pageinfo(), ro_hotlist_init(), ro_warn_user(), savepage_button_clicked_cb(), scrollbar_mouse_status_to_message(), select_filepath(), set_item_action(), tab_init(), textplain_convert(), textplain_mouse_action(), theme_install_callback(), theme_install_start(), wimp_MENU(), and win32_warning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_get_buff()

char * messages_get_buff ( const char *  key,
  ... 
)

Formatted message from a key in the global message hash.

Parameters
keykey of message
...message parameters
Returns
buffer containing formatted message text or NULL if key is unavailable or memory allocation failed. The caller owns the returned buffer and is responsible for freeing it.

Definition at line 205 of file messages.c.

References hash_get(), and messages_hash.

Referenced by gif_convert(), nsbmp_convert(), nsico_convert(), nsjpeg_convert(), nsjpegxl_convert(), nspng_convert(), and nssprite_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_get_ctx()

static const char * messages_get_ctx ( const char *  key,
struct hash_table ctx 
)
static

Fast lookup of a message by key.

Parameters
keykey of message
ctxcontext of messages file to look up in
Returns
value of message, or key if not found

Definition at line 154 of file messages.c.

References hash_get().

Referenced by messages_get(), messages_get_errorcode(), and messages_get_sslcode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_get_errorcode()

const char * messages_get_errorcode ( nserror  code)

lookup of a message by errorcode from the standard Messages hash.

Parameters
codeerrorcode of message
Returns
message text

Definition at line 248 of file messages.c.

References messages_get_ctx(), messages_hash, NSERROR_BAD_AUTH, NSERROR_BAD_CERTS, NSERROR_BAD_CONTENT, NSERROR_BAD_ENCODING, NSERROR_BAD_PARAMETER, NSERROR_BAD_REDIRECT, NSERROR_BAD_SIZE, NSERROR_BAD_URL, NSERROR_BMP_ERROR, NSERROR_BOX_CONVERT, NSERROR_CLONE_FAILED, NSERROR_CSS, NSERROR_CSS_BASE, NSERROR_DOM, NSERROR_ENCODING_CHANGE, NSERROR_FRAME_DEPTH, NSERROR_GIF_ERROR, NSERROR_ICO_ERROR, NSERROR_INIT_FAILED, NSERROR_INVALID, NSERROR_NEED_DATA, NSERROR_NO_FETCH_HANDLER, NSERROR_NOMEM, NSERROR_NOSPACE, NSERROR_NOT_DIRECTORY, NSERROR_NOT_FOUND, NSERROR_NOT_IMPLEMENTED, NSERROR_OK, NSERROR_PERMISSION, NSERROR_PNG_ERROR, NSERROR_SAVE_FAILED, NSERROR_SPRITE_ERROR, NSERROR_STOPPED, NSERROR_SVG_ERROR, NSERROR_TIMEOUT, and NSERROR_UNKNOWN.

Referenced by about_open(), ami_gui_event(), ami_gui_new_blank_tab(), ami_handle_applib(), atari_about_show(), atari_treeview_create(), browser_window__handle_error(), contents_button_clicked_cb(), context_popup(), fb_url_enter(), gadget_mouse_action(), gui_download_window_create(), gui_init(), gui_init2(), guide_button_clicked_cb(), home_button_clicked_cb(), HOOKF(), html_drop_file_at_point(), html_mouse_action(), html_redraw_box(), info_button_clicked_cb(), initialise(), llcache_fetch_callback(), main(), menu_new_win(), menu_open_file(), monkey_window_handle_go(), monkey_window_handle_new(), navigate_internal_real(), newtab_button_clicked_cb(), newwindow_button_clicked_cb(), nsbeos_scaffolding_dispatch_event(), nsgtk_completion_match_select(), nsgtk_cw_keypress_event(), nsgtk_finalise(), nsgtk_init(), nsgtk_on_link_opentab_activate_menu(), nsgtk_on_link_openwin_activate_menu(), nsgtk_on_savelink_activate_menu(), nsgtk_page_info(), nsws_window_command(), openfile_button_clicked_cb(), ro_gui_dialog_openurl_apply(), ro_gui_iconbar_click(), ro_gui_iconbar_menu_select(), ro_gui_url_bar_menu_select(), ro_gui_window_action_home(), ro_gui_window_action_local_history(), ro_gui_window_action_new_window(), ro_gui_window_handle_local_keypress(), ro_gui_window_launch_url(), ro_gui_window_menu_select(), ro_gui_window_toolbar_click(), ro_msg_dataload(), ro_msg_dataopen(), ro_uri_message_received(), ro_url_message_received(), url_entry_activate_cb(), viewsource_button_clicked_cb(), websearch_entry_activate_cb(), win32_report_nserror(), win32_window_set_title(), and WinMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_get_sslcode()

const char * messages_get_sslcode ( ssl_cert_err  code)

lookup of a message by SSL error code from the standard Messages hash.

Parameters
codessl error code
Returns
message text

Definition at line 405 of file messages.c.

References messages_get_ctx(), messages_hash, SSL_CERT_ERR_BAD_ISSUER, SSL_CERT_ERR_BAD_SIG, SSL_CERT_ERR_CERT_MISSING, SSL_CERT_ERR_CHAIN_SELF_SIGNED, SSL_CERT_ERR_HOSTNAME_MISMATCH, SSL_CERT_ERR_OK, SSL_CERT_ERR_REVOKED, SSL_CERT_ERR_SELF_SIGNED, SSL_CERT_ERR_TOO_OLD, SSL_CERT_ERR_TOO_YOUNG, and SSL_CERT_ERR_UNKNOWN.

Referenced by browser_window__handle_bad_certs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messages_load_ctx()

static nserror messages_load_ctx ( const char *  path,
struct hash_table **  ctx 
)
static

Read keys and values from messages file.

Parameters
pathpathname of messages file
ctxreference of hash table to merge with or NULL to create one.
Returns
NSERROR_OK on sucess and ctx updated or error code on faliure.
Note
The passed hash is not copied here so this updates in place.

Definition at line 114 of file messages.c.

References hash_add_file(), hash_destroy(), HASH_SIZE, messages_create_ctx(), NSERROR_NOMEM, NSERROR_OK, NSLOG, and path().

Referenced by messages_add_from_file().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ messages_hash

struct hash_table* messages_hash = NULL
static

The hash table used to store the standard Messages file for the old API.

Definition at line 48 of file messages.c.

Referenced by messages_add_from_file(), messages_add_from_inline(), messages_destroy(), messages_get(), messages_get_buff(), messages_get_errorcode(), and messages_get_sslcode().