File: sb_l10n.c

package info (click to toggle)
scratchbox2 2.2.4-1debian1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 5,392 kB
  • ctags: 5,239
  • sloc: ansic: 21,734; sh: 4,360; perl: 2,170; cpp: 1,913; makefile: 610; python: 184
file content (162 lines) | stat: -rw-r--r-- 4,522 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * sb_l10n.c -- exec_policy based localization support.
 *
 * Copyright (C) 2008 Nokia Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "libsb2.h"
#include "exported.h"

static void check_textdomain(const char *);

char *bindtextdomain_gate(int *result_errno_ptr,
	char *(*realfn)(const char *, const char *),
	const char *realfn_name, const char *domainname, const char *dirname)
{
	mapping_results_t res;
	const char *mapped_dirname = dirname;
	char *result = NULL;

	clear_mapping_results_struct(&res);

	if (dirname != NULL) { 
		sbox_map_path(realfn_name, dirname, 0, &res);
		assert(res.mres_result_path != NULL);

		mapped_dirname = res.mres_result_path;

		SB_LOG(SB_LOGLEVEL_DEBUG, "binding domain %s to %s",
		    domainname, mapped_dirname);
	}

	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname, mapped_dirname);
	*result_errno_ptr = errno;

	free_mapping_results(&res);
	if (result && (*result != '\0')) {
		char *sbox_path = NULL;
		sbox_path = scratchbox_reverse_path(realfn_name, result);
		if (sbox_path) {
			/* FIXME: this will leak memory. nobody will free
			 * the buffer at *sbox_path; in fact the manual
			 * page denies that ("..must not be modified
			 * or freed")
			*/
			result = sbox_path;
		}
	}
	return (result);
}

static void check_textdomain(const char *domainname)
{
	/*
	 * We read back current bindings for given domainname and
	 * call bindtextdomain() which then goes into our gate
	 * function that maps the path if exec policy says so.
	 */
	(void) bindtextdomain(domainname, bindtextdomain(domainname, NULL));
}

/*ARGSUSED*/
char *textdomain_gate(int *result_errno_ptr,
	char *(*realfn)(const char *), const char *realfn_name,
	const char *domainname)
{
	char	*result;

	(void)realfn_name;

	check_textdomain(domainname);
	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname);
	*result_errno_ptr = errno;
	return(result);
}

/*ARGSUSED*/
char *dgettext_gate(int *result_errno_ptr,
	char *(*realfn)(const char *, const char *),
	const char *realfn_name, const char *domainname, const char *msgid)
{
	char	*result;

	(void)realfn_name;

	check_textdomain(domainname);
	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname, msgid);
	*result_errno_ptr = errno;
	return(result);
}

/*ARGSUSED*/
char *dcgettext_gate(int *result_errno_ptr,
	char *(*realfn)(const char *, const char *, int),
	const char *realfn_name, const char *domainname, const char *msgid,
	int category)
{
	char	*result;

	(void)realfn_name;

	check_textdomain(domainname);
	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname, msgid, category);
	*result_errno_ptr = errno;
	return(result);
}

/*ARGSUSED*/
char *dngettext_gate(int *result_errno_ptr,
	char *(*realfn)(const char *, const char *, const char *,
	unsigned long int n), const char *realfn_name,
	const char *domainname, const char *msgid,
	const char *msgid_plural, unsigned long int n)
{
	char	*result;

	(void)realfn_name;

	check_textdomain(domainname);
	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname, msgid, msgid_plural, n);
	*result_errno_ptr = errno;
	return(result);
}

/*ARGSUSED*/
char *dcngettext_gate(int *result_errno_ptr,
	char *(*realfn)(const char *, const char *, const char *,
	unsigned long int, int), const char *realfn_name,
	const char *domainname, const char *msgid,
	const char *msgid_plural, unsigned long int n, int category)
{
	char	*result;

	(void)realfn_name;

	check_textdomain(domainname);
	errno = *result_errno_ptr; /* restore to orig.value */
	result = (*realfn)(domainname, msgid, msgid_plural, n, category);
	*result_errno_ptr = errno;
	return(result);
}