X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=source3%2Fintl%2Flang_tdb.c;h=14b075e6d7591964a010df57ab6bda8233b32221;hb=5e54558c6dea67b56bbfaba5698f3a434d3dffb6;hp=5409ce6619dd8ec40735f70fc6dac70ac142ee34;hpb=68e83434b53ebc43ced224488749a3eb41624dd1;p=vlendec%2Fsamba-autobuild%2F.git diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c index 5409ce6619d..14b075e6d75 100644 --- a/source3/intl/lang_tdb.c +++ b/source3/intl/lang_tdb.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" @@ -32,15 +31,18 @@ static BOOL load_msg(const char *msg_file) char **lines; int num_lines, i; char *msgid, *msgstr; - TDB_DATA key, data; + TDB_DATA data; - lines = file_lines_load(msg_file, &num_lines); + lines = file_lines_load(msg_file, &num_lines,0); if (!lines) { return False; } - if (tdb_lockall(tdb) != 0) return False; + if (tdb_lockall(tdb) != 0) { + file_lines_free(lines); + return False; + } /* wipe the db */ tdb_traverse(tdb, tdb_traverse_delete_fn, NULL); @@ -60,11 +62,8 @@ static BOOL load_msg(const char *msg_file) } all_string_sub(msgid, "\\n", "\n", 0); all_string_sub(msgstr, "\\n", "\n", 0); - key.dptr = msgid; - key.dsize = strlen(msgid)+1; - data.dptr = msgstr; - data.dsize = strlen(msgstr)+1; - tdb_store(tdb, key, data, 0); + data = string_term_tdb_data(msgstr); + tdb_store_bystring(tdb, msgid, data, 0); msgid = NULL; } } @@ -131,7 +130,7 @@ BOOL lang_tdb_init(const char *lang) asprintf(&msg_path, "%s.msg", lib_path((const char *)lang)); if (stat(msg_path, &st) != 0) { /* the msg file isn't available */ - DEBUG(10, ("lang_tdb_init: %s: %s", msg_path, + DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, strerror(errno))); goto done; } @@ -148,7 +147,7 @@ BOOL lang_tdb_init(const char *lang) strerror(errno))); goto done; } - current_lang = strdup(lang); + current_lang = SMB_STRDUP(lang); result = True; goto done; } @@ -160,7 +159,7 @@ BOOL lang_tdb_init(const char *lang) tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL)); } - current_lang = strdup(lang); + current_lang = SMB_STRDUP(lang); result = True; done: @@ -175,21 +174,50 @@ BOOL lang_tdb_init(const char *lang) */ const char *lang_msg(const char *msgid) { - TDB_DATA key, data; + TDB_DATA data; + const char *p; + char *q, *msgid_quoted; + int count; lang_tdb_init(NULL); if (!tdb) return msgid; - key.dptr = (char *)msgid; - key.dsize = strlen(msgid)+1; - - data = tdb_fetch(tdb, key); + /* Due to the way quotes in msgids are escaped in the msg file we + must replace " with \" before doing a lookup in the tdb. */ + + count = 0; + + for(p = msgid; *p; p++) { + if (*p == '\"') + count++; + } + + if (!(msgid_quoted = (char *)SMB_MALLOC(strlen(msgid) + count + 1))) + return msgid; + + /* string_sub() is unsuitable here as it replaces some punctuation + chars with underscores. */ + + for(p = msgid, q = msgid_quoted; *p; p++) { + if (*p == '\"') { + *q = '\\'; + q++; + } + *q = *p; + q++; + } + + *q = 0; + + data = tdb_fetch_bystring(tdb, msgid_quoted); + + free(msgid_quoted); /* if the message isn't found then we still need to return a pointer that can be freed. Pity. */ if (!data.dptr) - return strdup(msgid); + return SMB_STRDUP(msgid); return (const char *)data.dptr; } @@ -202,32 +230,6 @@ void lang_msg_free(const char *msgstr) free((void *)msgstr); } - -/* - when the _() translation macro is used there is no obvious place to free - the resulting string and there is no easy way to give a static pointer. - All we can do is rotate between some static buffers and hope a single d_printf() - doesn't have more calls to _() than the number of buffers -*/ -const char *lang_msg_rotate(const char *msgid) -{ -#define NUM_LANG_BUFS 4 - char *msgstr; - static pstring bufs[NUM_LANG_BUFS]; - static int next; - - msgstr = (char *)lang_msg(msgid); - if (!msgstr) return msgid; - - pstrcpy(bufs[next], msgstr); - msgstr = bufs[next]; - - next = (next+1) % NUM_LANG_BUFS; - - return msgstr; -} - - /* return the current language - needed for language file mappings */