Commit eb180443d335d18b97227156259573af04a9f29f
1 parent
b6d40b6e
Exists in
master
and in
5 other branches
Corrigindo segfaults aleatórios durante a montagem dos formulários html, inician…
…do implementação do arquivo de configuração em android
Showing
3 changed files
with
53 additions
and
61 deletions
Show diff stats
android/src/br/com/bb/pw3270/PW3270Activity.java
... | ... | @@ -7,6 +7,7 @@ import android.os.Bundle; |
7 | 7 | // import android.widget.EditText; |
8 | 8 | import android.util.Log; |
9 | 9 | // import android.view.View; |
10 | +import android.content.SharedPreferences; | |
10 | 11 | import android.content.res.*; |
11 | 12 | import android.app.AlertDialog; |
12 | 13 | import android.webkit.WebView; |
... | ... | @@ -31,6 +32,15 @@ public class PW3270Activity extends Activity |
31 | 32 | |
32 | 33 | terminal() |
33 | 34 | { |
35 | + SharedPreferences settings = getSharedPreferences(TAG, 0); | |
36 | + hostname = settings.getString("hostname",hostname); | |
37 | + port = settings.getInt("port",port); | |
38 | + ssl = settings.getBoolean("ssl",ssl); | |
39 | + | |
40 | + setToggle("dstrace",settings.getBoolean("dstrace",true)); | |
41 | + setToggle("screentrace",settings.getBoolean("screentrace",true)); | |
42 | + setToggle("eventtrace",settings.getBoolean("eventtrace",true)); | |
43 | + | |
34 | 44 | } |
35 | 45 | |
36 | 46 | protected void updateProgramMessage(int id) | ... | ... |
android/src/br/com/bb/pw3270/lib3270.java
... | ... | @@ -24,9 +24,9 @@ public class lib3270 |
24 | 24 | DataOutputStream outData = null; |
25 | 25 | DataInputStream inData = null; |
26 | 26 | |
27 | - private String hostname = "3270.df.bb"; | |
28 | - private int port = 8023; | |
29 | - private boolean ssl = false; | |
27 | + protected String hostname = "3270.df.bb"; | |
28 | + protected int port = 8023; | |
29 | + protected boolean ssl = false; | |
30 | 30 | |
31 | 31 | static |
32 | 32 | { |
... | ... | @@ -36,9 +36,6 @@ public class lib3270 |
36 | 36 | |
37 | 37 | lib3270() |
38 | 38 | { |
39 | - setToggle("dstrace",true); | |
40 | - setToggle("screentrace",true); | |
41 | - setToggle("eventtrace",true); | |
42 | 39 | changed = false; |
43 | 40 | mainloop = null; |
44 | 41 | } |
... | ... | @@ -150,6 +147,10 @@ public class lib3270 |
150 | 147 | { |
151 | 148 | // Connecta no host |
152 | 149 | SocketFactory socketFactory; |
150 | + | |
151 | + if(hostname == "") | |
152 | + return false; | |
153 | + | |
153 | 154 | if(ssl) |
154 | 155 | { |
155 | 156 | // Host é SSL | ... | ... |
src/lib3270/html.c
... | ... | @@ -110,8 +110,7 @@ |
110 | 110 | } mode; |
111 | 111 | |
112 | 112 | char * text; |
113 | - char * input; | |
114 | - char * block; | |
113 | + int block; | |
115 | 114 | int maxlength; |
116 | 115 | unsigned short fg; |
117 | 116 | unsigned short bg; |
... | ... | @@ -189,11 +188,7 @@ |
189 | 188 | |
190 | 189 | snprintf(name,29,"F%04d",addr); |
191 | 190 | |
192 | - info->block = info->text+strlen(info->text); | |
193 | - | |
194 | -#ifdef DEBUG | |
195 | - append_string(info,"\n"); | |
196 | -#endif // DEBUG | |
191 | + info->block = strlen(info->text); | |
197 | 192 | |
198 | 193 | append_string(info,"<input type=\""); |
199 | 194 | append_string(info,mode == HTML_MODE_INPUT_TEXT ? "text" : "password" ); |
... | ... | @@ -202,44 +197,35 @@ |
202 | 197 | append_string(info,"\" value=\""); |
203 | 198 | info->mode = mode; |
204 | 199 | info->maxlength = 0; |
205 | - info->input = info->text+strlen(info->text); | |
206 | 200 | |
207 | 201 | } |
208 | 202 | |
209 | 203 | static void close_input(struct html_info *info) |
210 | 204 | { |
211 | - char buffer[80]; | |
212 | - char *ptr; | |
213 | - char *mark; | |
205 | + char buffer[80]; | |
206 | + int pos; | |
214 | 207 | |
215 | 208 | if(info->mode == HTML_MODE_TEXT) |
216 | 209 | return; |
217 | 210 | |
211 | + trace("maxlength=%d",info->maxlength); | |
212 | + | |
218 | 213 | if(info->maxlength < 1) |
219 | 214 | { |
220 | - *info->block = 0; | |
215 | + info->text[info->block] = 0; | |
221 | 216 | info->mode = HTML_MODE_TEXT; |
222 | 217 | info->maxlength = 0; |
223 | 218 | return; |
224 | 219 | } |
225 | 220 | |
226 | - for(ptr=mark=info->input;*ptr;ptr++) | |
227 | - { | |
228 | - if(*ptr != ' ') | |
229 | - mark=ptr+1; | |
230 | - } | |
231 | - *mark = 0; | |
221 | + for(pos = strlen(info->text)-1;pos > 0 && info->text[pos] == ' '; pos--) | |
222 | + info->text[pos] = 0; | |
232 | 223 | |
233 | 224 | snprintf(buffer,80,"\" maxlength=\"%d\" class=\"IW%03d\"",info->maxlength,info->maxlength); |
234 | 225 | append_string(info,buffer); |
235 | 226 | |
236 | 227 | append_string(info,"></input>"); |
237 | 228 | |
238 | -#ifdef DEBUG | |
239 | - append_string(info,"\n"); | |
240 | -#endif // DEBUG | |
241 | - | |
242 | - | |
243 | 229 | info->mode = HTML_MODE_TEXT; |
244 | 230 | info->maxlength = 0; |
245 | 231 | } |
... | ... | @@ -266,30 +252,12 @@ |
266 | 252 | baddr = 0; |
267 | 253 | for(row=0;row < session->rows;row++) |
268 | 254 | { |
269 | - int cr = 0; | |
270 | - int len = 0; | |
271 | 255 | int col; |
272 | 256 | |
273 | -#ifdef DEBUG | |
274 | - { | |
275 | - char buffer[4096]; | |
276 | - snprintf(buffer,4095,"\n<!-- R%02d/%02d --->\t",row,session->rows); | |
277 | - append_string(&info,buffer); | |
278 | - } | |
279 | -#endif // DEBUG | |
280 | - | |
281 | 257 | for(col = 0; col < session->cols;col++) |
282 | 258 | { |
283 | - if( session->text[baddr+col].chr != ' ' || (session->text[baddr+col].attr & LIB3270_ATTR_CG)) | |
284 | - len = col; | |
285 | - } | |
286 | - | |
287 | - for(col = 0; col <= len || (col < session->cols && info.mode != HTML_MODE_TEXT);col++) | |
288 | - { | |
289 | 259 | if((option & LIB3270_HTML_OPTION_ALL) || (session->text[baddr+col].attr & LIB3270_ATTR_SELECTED)) |
290 | 260 | { |
291 | - cr++; | |
292 | - | |
293 | 261 | if((session->text[baddr+col].attr & LIB3270_ATTR_MARKER) && (option & LIB3270_HTML_OPTION_FORM) ) |
294 | 262 | { |
295 | 263 | int fa = (session->ea_buf[baddr+col].fa & FA_MASK); |
... | ... | @@ -303,12 +271,10 @@ |
303 | 271 | { |
304 | 272 | // Input field |
305 | 273 | unsigned char attr = get_field_attribute(session,baddr+col+1); |
306 | - //char * text = lib3270_get_field_at(session,baddr+col+1); | |
307 | - | |
308 | 274 | open_input(&info,baddr+col+1,FA_IS_ZERO(attr) ? HTML_MODE_INPUT_PASSWORD : HTML_MODE_INPUT_TEXT); |
309 | 275 | |
310 | 276 | } |
311 | - else if(col < len && session->text[baddr+col+1].chr == 'F') | |
277 | + else if(session->text[baddr+col+1].chr == 'F') | |
312 | 278 | { |
313 | 279 | char *text = lib3270_get_field_at(session,baddr+col+1); |
314 | 280 | |
... | ... | @@ -336,8 +302,7 @@ |
336 | 302 | append_string(&info,"\" />"); |
337 | 303 | info.mode = HTML_MODE_INPUT_BUTTON; |
338 | 304 | info.maxlength = 0; |
339 | - info.input = info.text+strlen(info.text); | |
340 | - | |
305 | + info.block = strlen(info.text); | |
341 | 306 | } |
342 | 307 | } |
343 | 308 | lib3270_free(text); |
... | ... | @@ -414,17 +379,16 @@ |
414 | 379 | enum HTML_MODE mode = info.mode; |
415 | 380 | |
416 | 381 | close_input(&info); |
417 | - | |
418 | - if(cr) | |
419 | - append_element(&info,HTML_ELEMENT_LINE_BREAK); | |
420 | - | |
382 | + append_element(&info,HTML_ELEMENT_LINE_BREAK); | |
421 | 383 | open_input(&info,baddr,mode); |
422 | 384 | |
423 | 385 | } |
424 | - else if(cr) | |
386 | + else | |
425 | 387 | { |
426 | 388 | append_element(&info,HTML_ELEMENT_LINE_BREAK); |
427 | - | |
389 | +#if defined(DEBUG) || defined(ANDROID) | |
390 | + append_string(&info,"\n"); | |
391 | +#endif // DEBUG | |
428 | 392 | } |
429 | 393 | |
430 | 394 | } |
... | ... | @@ -441,8 +405,8 @@ |
441 | 405 | |
442 | 406 | if(info.form) |
443 | 407 | { |
444 | - static const char * prefix = "<form name=\"" PACKAGE_NAME "\" id=\"form3270\" >"; | |
445 | - static const char * suffix = "</form>"; | |
408 | + static const char * prefix = "<form name=\"" PACKAGE_NAME "\" id=\"form3270\" >\n"; | |
409 | + static const char * suffix = "</form>\n"; | |
446 | 410 | char *text = info.text; |
447 | 411 | |
448 | 412 | info.text = lib3270_malloc(strlen(prefix)+strlen(suffix)+strlen(text)+4); |
... | ... | @@ -454,7 +418,24 @@ |
454 | 418 | lib3270_free(text); |
455 | 419 | } |
456 | 420 | |
457 | - return lib3270_realloc(info.text,strlen(info.text)+2); | |
421 | + info.text = lib3270_realloc(info.text,strlen(info.text)+2); | |
422 | + | |
423 | +#if defined(DEBUG) || defined(ANDROID) | |
424 | + { | |
425 | + char *text = strdup(info.text); | |
426 | + char *save; | |
427 | + char *ptr; | |
428 | + | |
429 | + for(ptr=strtok_r(text,"\n",&save);ptr;ptr = strtok_r(NULL,"\n",&save)) | |
430 | + { | |
431 | + trace("%s",ptr); | |
432 | + } | |
433 | + | |
434 | + free(text); | |
435 | + } | |
436 | +#endif // DEBUG | |
437 | + | |
438 | + return info.text; | |
458 | 439 | } |
459 | 440 | |
460 | 441 | ... | ... |