NetSurf
messages.h
Go to the documentation of this file.
1/*
2 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Localised message support (interface).
22 *
23 * The messages module loads a file of keys and associated strings, and
24 * provides fast lookup by key. The messages file consists of key:value lines,
25 * comment lines starting with #, and other lines are ignored. Use
26 * messages_load() to read the file into memory. To lookup a key, use
27 * messages_get("key").
28 *
29 * It can also load additional messages files into different contexts and allow
30 * you to look up values in it independantly from the standard shared Messages
31 * file table. Use the _ctx versions of the functions to do this.
32 */
33
34#ifndef NETSURF_UTILS_MESSAGES_H_
35#define NETSURF_UTILS_MESSAGES_H_
36
37#include <stdint.h>
38
39#include "utils/errors.h"
40#include "netsurf/ssl_certs.h"
41
42/**
43 * Read keys and values from messages file into the standard Messages hash.
44 *
45 * The messages are merged with any previously loaded messages. Any
46 * keys which are present already are replaced with the new value. The
47 * file may be gzip compressed.
48 *
49 * \param path pathname of messages file.
50 * \return NSERROR_OK on success or error code on faliure.
51 */
53
54/**
55 * Read keys and values from inline message data into the standard Messages hash.
56 *
57 * The messages are merged with any previously loaded messages. Any
58 * keys which are present already are replaced with the new value. The
59 * data may be gzip compressed.
60 *
61 * \param data The inline message data.
62 * \param data_size The length of the message data.
63 * \return NSERROR_OK on success or error code on faliure.
64 */
65nserror messages_add_from_inline(const uint8_t *data, size_t data_size);
66
67/**
68 * Add a single message.
69 *
70 * The message is merged with any previously loaded messages.
71 *
72 * \return NSERROR_OK on success or error code on faliure.
73
74 */
75nserror messages_add_key_value(const char *key, const char *value);
76
77/**
78 * Fast lookup of a message by key from the standard Messages hash.
79 *
80 * \param key key of message
81 * \return value of message, or key if not found
82 */
83const char *messages_get(const char *key);
84
85/**
86 * lookup of a message by errorcode from the standard Messages hash.
87 *
88 * \param code errorcode of message
89 * \return message text
90 */
91const char *messages_get_errorcode(nserror code);
92
93/**
94 * lookup of a message by SSL error code from the standard Messages hash.
95 *
96 * \param code ssl error code
97 * \return message text
98 */
99const char *messages_get_sslcode(ssl_cert_err code);
100
101/**
102 * Formatted message from a key in the global message hash.
103 *
104 * \param key key of message
105 * \param ... message parameters
106 * \return buffer containing formatted message text or NULL if key is
107 * unavailable or memory allocation failed. The caller owns the
108 * returned buffer and is responsible for freeing it.
109 */
110char *messages_get_buff(const char *key, ...);
111
112/**
113 * Free memory used by the standard Messages hash
114 */
115void messages_destroy(void);
116
117#endif
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
nserror messages_add_key_value(const char *key, const char *value)
Add a single message.
Definition: messages.c:205
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
Definition: messages.c:177
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:263
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.
Definition: messages.c:190
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:256
char * messages_get_buff(const char *key,...)
Formatted message from a key in the global message hash.
Definition: messages.c:220
void messages_destroy(void)
Free memory used by the standard Messages hash.
Definition: messages.c:478
const char * messages_get_sslcode(ssl_cert_err code)
lookup of a message by SSL error code from the standard Messages hash.
Definition: messages.c:420
SSL related types and values.
ssl_cert_err
ssl certificate error status
Definition: ssl_certs.h:36
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821