Commit a046e5a6cb6d43a3ec76834f58f89c5e635dc712
1 parent
a2c1ad41
Exists in
master
and in
5 other branches
Android - Implementando string de logon para passar automaticamente pela tela inicial
Showing
9 changed files
with
65 additions
and
42 deletions
Show diff stats
android/jni/main.cpp
... | ... | @@ -77,10 +77,20 @@ static void changed(H3270 *session, int offset, int len) |
77 | 77 | trace("%s: offset=%d len=%d",__FUNCTION__,offset,len); |
78 | 78 | |
79 | 79 | { |
80 | - char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); | |
81 | - | |
80 | + char *text = lib3270_get_text(PW3270_SESSION,0,-1); | |
82 | 81 | if(text) |
82 | + { | |
83 | + char *strtok_r(char *str, const char *delim, char **saveptr); | |
84 | + char *save; | |
85 | + | |
86 | +/* | |
87 | + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n"); | |
88 | + for(char *ptr = strtok_r(text,"\n",&save);ptr;ptr = strtok_r(NULL,"\n",&save)) | |
89 | + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s\n",ptr); | |
90 | +*/ | |
91 | + | |
83 | 92 | lib3270_free(text); |
93 | + } | |
84 | 94 | } |
85 | 95 | |
86 | 96 | pw3270_jni_post_message(2,offset,len); |
... | ... | @@ -258,16 +268,25 @@ static void ctlr_done(H3270 *session) |
258 | 268 | |
259 | 269 | static void autostart(H3270 *session) |
260 | 270 | { |
261 | - // pw3270_jni_post_message(10); | |
262 | - | |
263 | 271 | { |
264 | 272 | char *text = lib3270_get_text(PW3270_SESSION,0,-1); |
265 | 273 | if(text) |
266 | 274 | { |
267 | - __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n%s\n",text); | |
275 | + char *strtok_r(char *str, const char *delim, char **saveptr); | |
276 | + char *save; | |
277 | + | |
278 | +/* | |
279 | + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n"); | |
280 | + for(char *ptr = strtok_r(text,"\n",&save);ptr;ptr = strtok_r(NULL,"\n",&save)) | |
281 | + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s\n",ptr); | |
282 | +*/ | |
283 | + | |
268 | 284 | lib3270_free(text); |
269 | 285 | } |
270 | 286 | } |
287 | + | |
288 | + pw3270_jni_post_message(10); | |
289 | + | |
271 | 290 | } |
272 | 291 | |
273 | 292 | jint JNI_OnLoad(JavaVM *vm, void *reserved) | ... | ... |
android/jni/text.cpp
... | ... | @@ -139,16 +139,18 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setTextAt(JNIEnv *env, jobj |
139 | 139 | PW3270_JNI_END |
140 | 140 | } |
141 | 141 | |
142 | -JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_input(JNIEnv *env, jobject obj, jstring str, jint pasting) | |
142 | +JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_runStartupString(JNIEnv *env, jobject obj, jstring str) | |
143 | 143 | { |
144 | 144 | int rc = -1; |
145 | 145 | |
146 | 146 | PW3270_JNI_BEGIN |
147 | 147 | |
148 | 148 | if(lib3270_connected(PW3270_SESSION)) |
149 | - rc = lib3270_emulate_input(PW3270_SESSION, env->GetStringUTFChars(str, 0), -1, (int) pasting); | |
149 | + { | |
150 | + lib3270_set_cursor_address(PW3270_SESSION,lib3270_get_next_unprotected(PW3270_SESSION,0)); | |
151 | + lib3270_emulate_input(PW3270_SESSION, env->GetStringUTFChars(str, 0), -1, 0); | |
152 | + } | |
150 | 153 | |
151 | 154 | PW3270_JNI_END |
152 | 155 | |
153 | - return rc; | |
154 | 156 | } | ... | ... |
android/src/br/com/bb/pw3270/lib3270.java
... | ... | @@ -140,22 +140,11 @@ public abstract class lib3270 |
140 | 140 | break; |
141 | 141 | |
142 | 142 | case 10: // Run autostart |
143 | - Log.v(TAG, "AAA---------------------------------------------------------------"); | |
144 | - Log.v(TAG, "In3270="+(in3270() ? "Yes" : "No")); | |
145 | 143 | |
146 | - /* | |
147 | 144 | String str = settings.getString("logonstring",""); |
148 | 145 | Log.v(TAG, "Logon string is \"" + str + "\""); |
149 | 146 | if( str != "") |
150 | - { | |
151 | - int sz = input(str,0); | |
152 | - Log.v(TAG, "Input exits with "+sz); | |
153 | - } | |
154 | - */ | |
155 | - | |
156 | - Log.v(TAG, "Contents:\n" + getText() + "\n"); | |
157 | - | |
158 | - Log.v(TAG, "AAA---------------------------------------------------------------"); | |
147 | + runStartupString(str); | |
159 | 148 | break; |
160 | 149 | |
161 | 150 | } |
... | ... | @@ -176,7 +165,7 @@ public abstract class lib3270 |
176 | 165 | this.screenState = -1; |
177 | 166 | |
178 | 167 | for(int f = 0; f < toggle.length; f++) |
179 | - setToggle(toggle[f],settings.getBoolean(toggle[f],true)); | |
168 | + setToggle(toggle[f],settings.getBoolean(toggle[f],false)); | |
180 | 169 | |
181 | 170 | } |
182 | 171 | |
... | ... | @@ -632,7 +621,7 @@ public abstract class lib3270 |
632 | 621 | |
633 | 622 | public native void setTextAt(int offset, byte[] str, int len); |
634 | 623 | |
635 | - public native int input(String text, int pasting); | |
636 | - | |
637 | 624 | public native boolean in3270(); |
625 | + | |
626 | + public native void runStartupString(String text); | |
638 | 627 | } | ... | ... |
src/include/lib3270.h
... | ... | @@ -441,7 +441,7 @@ |
441 | 441 | * @param len Size of the string (or -1 to null terminated strings) |
442 | 442 | * @param pasting Non zero for pasting (See comments). |
443 | 443 | * |
444 | - * @return The number of unprocessed characters. | |
444 | + * @return The number of unprocessed characters or -1 if failed | |
445 | 445 | */ |
446 | 446 | LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, const char *s, int len, int pasting); |
447 | 447 | |
... | ... | @@ -769,6 +769,17 @@ |
769 | 769 | LIB3270_EXPORT char * lib3270_get_field_at(H3270 *h, int baddr); |
770 | 770 | |
771 | 771 | /** |
772 | + * Find the next unprotected field. | |
773 | + * | |
774 | + * @param hSession Session handle. | |
775 | + * @param baddr0 Search start addr. | |
776 | + * | |
777 | + * @return address following the unprotected attribute byte, or 0 if no nonzero-width unprotected field can be found. | |
778 | + * | |
779 | + */ | |
780 | + LIB3270_EXPORT int lib3270_get_next_unprotected(H3270 *hSession, int baddr0); | |
781 | + | |
782 | + /** | |
772 | 783 | * Find the buffer address of the field attribute for a given buffer address. |
773 | 784 | * |
774 | 785 | * @param h Session handle. | ... | ... |
src/include/lib3270/log.h
... | ... | @@ -45,7 +45,8 @@ |
45 | 45 | #define lib3270_write_rc(s,m,r,f,...) __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", __VA_ARGS__ ) |
46 | 46 | #define lib3270_write_va_log(s,m,f,a) __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", a) |
47 | 47 | |
48 | - #define trace( fmt, ... ) __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); | |
48 | + // #define trace( fmt, ... ) __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); | |
49 | + #define trace(x, ...) // __VA_ARGS__ | |
49 | 50 | |
50 | 51 | #else |
51 | 52 | ... | ... |
src/lib3270/ctlr.c
... | ... | @@ -240,7 +240,6 @@ static void set_formatted(H3270 *hSession, int state) |
240 | 240 | hSession->update_formatted(hSession,hSession->formatted); |
241 | 241 | } |
242 | 242 | */ |
243 | - trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); | |
244 | 243 | } |
245 | 244 | |
246 | 245 | /** |
... | ... | @@ -366,12 +365,7 @@ unsigned char get_field_attribute(H3270 *hSession, int baddr) |
366 | 365 | return hSession->ea_buf[find_field_attribute(hSession,baddr)].fa; |
367 | 366 | } |
368 | 367 | |
369 | -/* | |
370 | - * Find the next unprotected field. Returns the address following the | |
371 | - * unprotected attribute byte, or 0 if no nonzero-width unprotected field | |
372 | - * can be found. | |
373 | - */ | |
374 | -int next_unprotected(H3270 *hSession, int baddr0) | |
368 | +LIB3270_EXPORT int lib3270_get_next_unprotected(H3270 *hSession, int baddr0) | |
375 | 369 | { |
376 | 370 | register int baddr, nbaddr; |
377 | 371 | ... | ... |
src/lib3270/ctlrc.h
... | ... | @@ -61,7 +61,9 @@ LIB3270_INTERNAL enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int b |
61 | 61 | LIB3270_INTERNAL void ctlr_write_sscp_lu(H3270 *session, unsigned char buf[], int buflen); |
62 | 62 | LIB3270_INTERNAL void mdt_clear(H3270 *hSession, int baddr); |
63 | 63 | LIB3270_INTERNAL void mdt_set(H3270 *hSession, int baddr); |
64 | -LIB3270_INTERNAL int next_unprotected(H3270 *session, int baddr0); | |
64 | + | |
65 | +#define next_unprotected(session, baddr0) lib3270_get_next_unprotected(session, baddr0) | |
66 | + | |
65 | 67 | LIB3270_INTERNAL enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen); |
66 | 68 | LIB3270_INTERNAL void ps_process(H3270 *hSession); |
67 | 69 | ... | ... |
src/lib3270/kybd.c
... | ... | @@ -86,7 +86,9 @@ struct ta; |
86 | 86 | #include "api.h" |
87 | 87 | |
88 | 88 | |
89 | -/*#define KYBDLOCK_TRACE 1*/ | |
89 | +#ifdef DEBUG | |
90 | + #define KYBDLOCK_TRACE | |
91 | +#endif // DEBUG | |
90 | 92 | |
91 | 93 | /* Statics */ |
92 | 94 | // static enum { NONE, COMPOSE, FIRST } composing = NONE; |
... | ... | @@ -372,12 +374,9 @@ static void kybdlock_set(H3270 *hSession, unsigned int bits) |
372 | 374 | n = hSession->kybdlock | bits; |
373 | 375 | if (n != hSession->kybdlock) |
374 | 376 | { |
375 | -/* | |
376 | 377 | #if defined(KYBDLOCK_TRACE) |
377 | - lib3270_trace_event(hSession," %s: kybdlock |= 0x%04x, 0x%04x -> 0x%04x\n", | |
378 | - cause, bits, kybdlock, n); | |
378 | + lib3270_trace_event(hSession," %s: kybdlock |= 0x%04x, 0x%04x -> 0x%04x\n", "set", bits, hSession->kybdlock, n); | |
379 | 379 | #endif |
380 | -*/ | |
381 | 380 | if ((hSession->kybdlock ^ bits) & KL_DEFERRED_UNLOCK) |
382 | 381 | { |
383 | 382 | /* Turned on deferred unlock. */ |
... | ... | @@ -396,10 +395,12 @@ void lib3270_kybdlock_clear(H3270 *hSession, LIB3270_KL_STATE bits) |
396 | 395 | { |
397 | 396 | unsigned int n = hSession->kybdlock & ~( (unsigned int) bits); |
398 | 397 | |
398 | + trace("%s: kybdlock=%d",__FUNCTION__,n); | |
399 | + | |
399 | 400 | if (n != hSession->kybdlock) |
400 | 401 | { |
401 | 402 | #if defined(KYBDLOCK_TRACE) |
402 | - lib3270_trace_event(hSession," %s: kybdlock &= ~0x%04x, 0x%04x -> 0x%04x\n", __FUNCTION__, bits, kybdlock, n); | |
403 | + lib3270_trace_event(hSession," %s: kybdlock &= ~0x%04x, 0x%04x -> 0x%04x\n", "clear", bits, hSession->kybdlock, n); | |
403 | 404 | #endif |
404 | 405 | if ((hSession->kybdlock ^ n) & KL_DEFERRED_UNLOCK) |
405 | 406 | { |
... | ... | @@ -2502,7 +2503,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len |
2502 | 2503 | len = mb_to_unicode(s, len, w_ibuf, w_ibuf_len, NULL); |
2503 | 2504 | if (len < 0) |
2504 | 2505 | { |
2505 | - return 0; /* failed */ | |
2506 | + return -1; /* failed */ | |
2506 | 2507 | } |
2507 | 2508 | ws = w_ibuf; |
2508 | 2509 | #else /*][*/ |
... | ... | @@ -2523,7 +2524,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len |
2523 | 2524 | if (hSession->kybdlock) |
2524 | 2525 | { |
2525 | 2526 | lib3270_trace_event(hSession," keyboard locked, string dropped\n"); |
2526 | - return 0; | |
2527 | + return -1; | |
2527 | 2528 | } |
2528 | 2529 | |
2529 | 2530 | if (pasting && IN_3270) | ... | ... |
src/lib3270/screen.c
... | ... | @@ -372,10 +372,14 @@ void screen_update(H3270 *session, int bstart, int bend) |
372 | 372 | session->changed(session,first,len); |
373 | 373 | } |
374 | 374 | |
375 | - if(session->starting && session->formatted && lib3270_in_3270(session)) | |
375 | + if(session->starting && session->formatted && !session->kybdlock && lib3270_in_3270(session)) | |
376 | 376 | { |
377 | 377 | session->starting = 0; |
378 | + | |
379 | +// cursor_move(session,next_unprotected(session,0)); | |
380 | +// lib3270_emulate_input(session,"\\n",-1,0); | |
378 | 381 | session->autostart(session); |
382 | + | |
379 | 383 | #ifdef DEBUG |
380 | 384 | { |
381 | 385 | char *text = lib3270_get_text(session,0,-1); | ... | ... |