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 | 49 | #ifdef HAVE_ICONV |
50 | 50 | this->converter.local = (iconv_t) (-1); |
51 | 51 | this->converter.host = (iconv_t) (-1); |
52 | +#else | |
53 | + this->converter = nullptr; | |
52 | 54 | #endif |
53 | 55 | |
54 | 56 | } |
... | ... | @@ -63,6 +65,13 @@ |
63 | 65 | if(this->converter.host != (iconv_t) (-1)) |
64 | 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 | 75 | #endif |
67 | 76 | |
68 | 77 | } |
... | ... | @@ -102,8 +111,12 @@ |
102 | 111 | |
103 | 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 | 120 | #endif |
108 | 121 | |
109 | 122 | |
... | ... | @@ -147,21 +160,48 @@ |
147 | 160 | |
148 | 161 | /// @brief Converte string recebida do host para o charset atual. |
149 | 162 | std::string Abstract::Session::convertFromHost(const std::string &str) const { |
150 | -// debug(__FUNCTION__,"(",str.c_str(),")"); | |
163 | + | |
151 | 164 | #ifdef HAVE_ICONV |
165 | + | |
152 | 166 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str.c_str(),str.size()); |
167 | + | |
153 | 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 | 178 | return str; |
179 | + | |
155 | 180 | #endif // HAVE_ICONV |
156 | 181 | } |
157 | 182 | |
158 | 183 | // @brief Converte string do charset atual para o charset do host. |
159 | 184 | std::string Abstract::Session::convertToHost(const char *text, int length) const { |
185 | + | |
160 | 186 | #ifdef HAVE_ICONV |
187 | + | |
161 | 188 | return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,text,length); |
189 | + | |
162 | 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 | 201 | #endif // HAVE_ICONV |
202 | + | |
203 | + return std::string(text,length); | |
204 | + | |
165 | 205 | } |
166 | 206 | |
167 | 207 | /// @brief Converte string do charset atual para o charset do host. | ... | ... |
client/src/include/ipc-client-internals.h
... | ... | @@ -61,13 +61,17 @@ |
61 | 61 | #include <stdexcept> |
62 | 62 | #include <string> |
63 | 63 | |
64 | +#ifndef HAVE_ICONV | |
65 | + #include <lib3270/charset.h> | |
66 | +#endif // !HAVE_ICONV | |
67 | + | |
64 | 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 | 72 | #else |
69 | - #define _( x ) x | |
70 | - #define N_( x ) x | |
73 | + #define _( x ) x | |
74 | + #define N_( x ) x | |
71 | 75 | #endif // HAVE_LIBINTL |
72 | 76 | |
73 | 77 | // |
... | ... | @@ -145,10 +149,15 @@ |
145 | 149 | |
146 | 150 | } converter; |
147 | 151 | |
148 | - /// @brief Converte charset. | |
149 | 152 | static std::string convertCharset(iconv_t &converter, const char *str, int length); |
153 | + | |
154 | +#else | |
155 | + | |
156 | + LIB3270_ICONV * converter; | |
157 | + | |
150 | 158 | #endif |
151 | 159 | |
160 | + /// @brief Converte charset. | |
152 | 161 | |
153 | 162 | protected: |
154 | 163 | ... | ... |
client/src/session/local/init.cc