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 * Fast lookup of a message by key from the standard Messages hash.
69 *
70 * \param key key of message
71 * \return value of message, or key if not found
72 */
73const char *messages_get(const char *key);
74
75/**
76 * lookup of a message by errorcode from the standard Messages hash.
77 *
78 * \param code errorcode of message
79 * \return message text
80 */
81const char *messages_get_errorcode(nserror code);
82
83/**
84 * lookup of a message by SSL error code from the standard Messages hash.
85 *
86 * \param code ssl error code
87 * \return message text
88 */
89const char *messages_get_sslcode(ssl_cert_err code);
90
91/**
92 * Formatted message from a key in the global message hash.
93 *
94 * \param key key of message
95 * \param ... message parameters
96 * \return buffer containing formatted message text or NULL if key is
97 * unavailable or memory allocation failed. The caller owns the
98 * returned buffer and is responsible for freeing it.
99 */
100char *messages_get_buff(const char *key, ...);
101
102/**
103 * Free memory used by the standard Messages hash
104 */
105void messages_destroy(void);
106
107#endif
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
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:248
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:241
char * messages_get_buff(const char *key,...)
Formatted message from a key in the global message hash.
Definition: messages.c:205
void messages_destroy(void)
Free memory used by the standard Messages hash.
Definition: messages.c:463
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:405
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