Commit b7f6660f31c098ccd7e85f8ca3b9666523273cf5
1 parent
85f3b35d
Exists in
master
and in
1 other branch
Adding falback to the lib3270's iconv wrapper.
Showing
3 changed files
with
58 additions
and
11 deletions
Show diff stats
client/src/core/abstract.cc
@@ -49,6 +49,8 @@ | @@ -49,6 +49,8 @@ | ||
49 | #ifdef HAVE_ICONV | 49 | #ifdef HAVE_ICONV |
50 | this->converter.local = (iconv_t) (-1); | 50 | this->converter.local = (iconv_t) (-1); |
51 | this->converter.host = (iconv_t) (-1); | 51 | this->converter.host = (iconv_t) (-1); |
52 | +#else | ||
53 | + this->converter = nullptr; | ||
52 | #endif | 54 | #endif |
53 | 55 | ||
54 | } | 56 | } |
@@ -63,6 +65,13 @@ | @@ -63,6 +65,13 @@ | ||
63 | if(this->converter.host != (iconv_t) (-1)) | 65 | if(this->converter.host != (iconv_t) (-1)) |
64 | iconv_close(this->converter.host); | 66 | iconv_close(this->converter.host); |
65 | 67 | ||
68 | +#else | ||
69 | + | ||
70 | + if(converter) { | ||
71 | + lib3270_iconv_free(converter); | ||
72 | + converter = nullptr; | ||
73 | + } | ||
74 | + | ||
66 | #endif | 75 | #endif |
67 | 76 | ||
68 | } | 77 | } |
@@ -102,8 +111,12 @@ | @@ -102,8 +111,12 @@ | ||
102 | 111 | ||
103 | #else | 112 | #else |
104 | 113 | ||
105 | - throw std::runtime_error("No ICONV Support"); | 114 | + if(converter) |
115 | + lib3270_iconv_free(converter); | ||
116 | + | ||
117 | + converter = lib3270_iconv_new(remote,local); | ||
106 | 118 | ||
119 | + debug("lib3270_iconv_new(",remote,",",local,"=",(void *) converter); | ||
107 | #endif | 120 | #endif |
108 | 121 | ||
109 | 122 | ||
@@ -147,21 +160,48 @@ | @@ -147,21 +160,48 @@ | ||
147 | 160 | ||
148 | /// @brief Converte string recebida do host para o charset atual. | 161 | /// @brief Converte string recebida do host para o charset atual. |
149 | std::string Abstract::Session::convertFromHost(const std::string &str) const { | 162 | std::string Abstract::Session::convertFromHost(const std::string &str) const { |
150 | -// debug(__FUNCTION__,"(",str.c_str(),")"); | 163 | + |
151 | #ifdef HAVE_ICONV | 164 | #ifdef HAVE_ICONV |
165 | + | ||
152 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str.c_str(),str.size()); | 166 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str.c_str(),str.size()); |
167 | + | ||
153 | #else | 168 | #else |
169 | + if(converter) { | ||
170 | + | ||
171 | + lib3270_auto_cleanup<char> converted = lib3270_iconv_from_host(converter,str.c_str(),str.size()); | ||
172 | + if(converted) { | ||
173 | + return std::string(converted); | ||
174 | + } | ||
175 | + | ||
176 | + } | ||
177 | + | ||
154 | return str; | 178 | return str; |
179 | + | ||
155 | #endif // HAVE_ICONV | 180 | #endif // HAVE_ICONV |
156 | } | 181 | } |
157 | 182 | ||
158 | // @brief Converte string do charset atual para o charset do host. | 183 | // @brief Converte string do charset atual para o charset do host. |
159 | std::string Abstract::Session::convertToHost(const char *text, int length) const { | 184 | std::string Abstract::Session::convertToHost(const char *text, int length) const { |
185 | + | ||
160 | #ifdef HAVE_ICONV | 186 | #ifdef HAVE_ICONV |
187 | + | ||
161 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,text,length); | 188 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,text,length); |
189 | + | ||
162 | #else | 190 | #else |
163 | - return std::string(text,length); | 191 | + |
192 | + if(converter) { | ||
193 | + | ||
194 | + lib3270_auto_cleanup<char> converted = lib3270_iconv_to_host(converter,text,length); | ||
195 | + if(converted) { | ||
196 | + return std::string(converted); | ||
197 | + } | ||
198 | + | ||
199 | + } | ||
200 | + | ||
164 | #endif // HAVE_ICONV | 201 | #endif // HAVE_ICONV |
202 | + | ||
203 | + return std::string(text,length); | ||
204 | + | ||
165 | } | 205 | } |
166 | 206 | ||
167 | /// @brief Converte string do charset atual para o charset do host. | 207 | /// @brief Converte string do charset atual para o charset do host. |
client/src/include/ipc-client-internals.h
@@ -61,13 +61,17 @@ | @@ -61,13 +61,17 @@ | ||
61 | #include <stdexcept> | 61 | #include <stdexcept> |
62 | #include <string> | 62 | #include <string> |
63 | 63 | ||
64 | +#ifndef HAVE_ICONV | ||
65 | + #include <lib3270/charset.h> | ||
66 | +#endif // !HAVE_ICONV | ||
67 | + | ||
64 | #ifdef HAVE_LIBINTL | 68 | #ifdef HAVE_LIBINTL |
65 | - #include <libintl.h> | ||
66 | - #define _( x ) dgettext(PACKAGE_NAME, x) | ||
67 | - #define N_( x ) x | 69 | + #include <libintl.h> |
70 | + #define _( x ) dgettext(PACKAGE_NAME, x) | ||
71 | + #define N_( x ) x | ||
68 | #else | 72 | #else |
69 | - #define _( x ) x | ||
70 | - #define N_( x ) x | 73 | + #define _( x ) x |
74 | + #define N_( x ) x | ||
71 | #endif // HAVE_LIBINTL | 75 | #endif // HAVE_LIBINTL |
72 | 76 | ||
73 | // | 77 | // |
@@ -145,10 +149,15 @@ | @@ -145,10 +149,15 @@ | ||
145 | 149 | ||
146 | } converter; | 150 | } converter; |
147 | 151 | ||
148 | - /// @brief Converte charset. | ||
149 | static std::string convertCharset(iconv_t &converter, const char *str, int length); | 152 | static std::string convertCharset(iconv_t &converter, const char *str, int length); |
153 | + | ||
154 | +#else | ||
155 | + | ||
156 | + LIB3270_ICONV * converter; | ||
157 | + | ||
150 | #endif | 158 | #endif |
151 | 159 | ||
160 | + /// @brief Converte charset. | ||
152 | 161 | ||
153 | protected: | 162 | protected: |
154 | 163 |
client/src/session/local/init.cc
@@ -67,9 +67,7 @@ | @@ -67,9 +67,7 @@ | ||
67 | 67 | ||
68 | lib3270_set_user_data(this->hSession,(void *) this); | 68 | lib3270_set_user_data(this->hSession,(void *) this); |
69 | 69 | ||
70 | -#ifdef HAVE_ICONV | ||
71 | setCharSet(); | 70 | setCharSet(); |
72 | -#endif // HAVE_ICONV | ||
73 | 71 | ||
74 | lib3270_set_popup_handler(this->hSession, popupHandler); | 72 | lib3270_set_popup_handler(this->hSession, popupHandler); |
75 | 73 |