Commit 331a69dd4eed9b9f8c68f3482e812e17925b7429

Authored by perry.werneck@gmail.com
1 parent 332726eb

Atualizando para o novo mecanismo de conexão

src/classlib/remote.cc
@@ -667,7 +667,7 @@ @@ -667,7 +667,7 @@
667 667
668 #elif defined(HAVE_DBUS) 668 #elif defined(HAVE_DBUS)
669 669
670 - int rc = query_intval("connect", DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID); 670 + rc = query_intval("connect", DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID);
671 671
672 #else 672 #else
673 rc = -1; 673 rc = -1;
@@ -697,8 +697,7 @@ @@ -697,8 +697,7 @@
697 697
698 #elif defined(HAVE_DBUS) 698 #elif defined(HAVE_DBUS)
699 699
700 - #warning Implementar  
701 - return -1; 700 + rc = query_intval("setHost", DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID);
702 701
703 #else 702 #else
704 703
src/include/lib3270.h
@@ -419,6 +419,17 @@ @@ -419,6 +419,17 @@
419 LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h); 419 LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h);
420 420
421 /** 421 /**
  422 + * Get URL of the hostname for the connect/reconnect operations.
  423 + *
  424 + * @param h Session handle.
  425 + *
  426 + * @return Pointer to host URL set (internal data, do not change it)
  427 + *
  428 + */
  429 + LIB3270_EXPORT const char * lib3270_get_host(H3270 *h);
  430 +
  431 +
  432 + /**
422 * Network connect operation, keep main loop running 433 * Network connect operation, keep main loop running
423 * 434 *
424 * @param h Session handle. 435 * @param h Session handle.
src/lib3270/connect.c
@@ -136,7 +136,9 @@ static void net_connected(H3270 *hSession) @@ -136,7 +136,9 @@ static void net_connected(H3270 *hSession)
136 136
137 } 137 }
138 138
139 -#if defined(_WIN32) /*[*/ 139 +
  140 +#if defined(_WIN32)
  141 +
140 static void sockstart(H3270 *session) 142 static void sockstart(H3270 *session)
141 { 143 {
142 static int initted = 0; 144 static int initted = 0;
@@ -171,15 +173,11 @@ static void net_connected(H3270 *hSession) @@ -171,15 +173,11 @@ static void net_connected(H3270 *hSession)
171 _exit(1); 173 _exit(1);
172 } 174 }
173 } 175 }
174 -#endif /*]*/ 176 +#endif // WIN32
175 177
176 LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_CONNECT_OPTION opt) 178 LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_CONNECT_OPTION opt)
177 { 179 {
178 - int s;  
179 - int optval;  
180 - struct addrinfo hints;  
181 - struct addrinfo * result = NULL;  
182 - struct addrinfo * rp = NULL; 180 + CHECK_SESSION_HANDLE(hSession);
183 181
184 if(!hostname) 182 if(!hostname)
185 return EINVAL; 183 return EINVAL;
@@ -187,6 +185,48 @@ static void net_connected(H3270 *hSession) @@ -187,6 +185,48 @@ static void net_connected(H3270 *hSession)
187 if(!srvc) 185 if(!srvc)
188 srvc = "telnet"; 186 srvc = "telnet";
189 187
  188 + if(*hostname == '$')
  189 + {
  190 + const char *name = getenv(hostname+1);
  191 + if(!name)
  192 + {
  193 + lib3270_popup_dialog( hSession,
  194 + LIB3270_NOTIFY_ERROR,
  195 + _( "Connection error" ),
  196 + _( "Unable to find selected hostname." ),
  197 + _( "Can't determine value for environment variable \"%s\" " ),
  198 + hostname);
  199 + lib3270_set_disconnected(hSession);
  200 + return ENOENT;
  201 + }
  202 + hostname = name;
  203 + }
  204 +
  205 + hSession->host.opt = opt & ~LIB3270_CONNECT_OPTION_WAIT;
  206 + Replace(hSession->host.current,strdup(hostname));
  207 + Replace(hSession->host.srvc,strdup(srvc));
  208 +
  209 + Replace(hSession->host.full,
  210 + lib3270_strdup_printf(
  211 + "%s%s:%s",
  212 + opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "tn3270://",
  213 + hostname,
  214 + srvc ));
  215 +
  216 + trace("current_host=\"%s\"",hSession->host.current);
  217 +
  218 + return lib3270_connect(hSession,opt & LIB3270_CONNECT_OPTION_WAIT);
  219 +
  220 + }
  221 +
  222 + int lib3270_connect(H3270 *hSession, int wait)
  223 + {
  224 + int s;
  225 + int optval;
  226 + struct addrinfo hints;
  227 + struct addrinfo * result = NULL;
  228 + struct addrinfo * rp = NULL;
  229 +
190 CHECK_SESSION_HANDLE(hSession); 230 CHECK_SESSION_HANDLE(hSession);
191 231
192 lib3270_main_iterate(hSession,0); 232 lib3270_main_iterate(hSession,0);
@@ -201,20 +241,9 @@ static void net_connected(H3270 *hSession) @@ -201,20 +241,9 @@ static void net_connected(H3270 *hSession)
201 sockstart(hSession); 241 sockstart(hSession);
202 #endif 242 #endif
203 243
204 - hSession->host.opt = opt & ~LIB3270_CONNECT_OPTION_WAIT;  
205 - Replace(hSession->host.current,strdup(hostname));  
206 -  
207 - Replace(hSession->host.full,  
208 - lib3270_strdup_printf(  
209 - "%s%s:%s",  
210 - opt&LIB3270_CONNECT_OPTION_SSL ? "L:" : "",  
211 - hostname,  
212 - srvc ));  
213 -  
214 - trace("current_host=\"%s\"",hSession->host.current);  
215 -  
216 -  
217 set_ssl_state(hSession,LIB3270_SSL_UNSECURE); 244 set_ssl_state(hSession,LIB3270_SSL_UNSECURE);
  245 + snprintf(hSession->full_model_name,LIB3270_FULL_MODEL_NAME_LENGTH,"IBM-327%c-%d",hSession->m3279 ? '9' : '8', hSession->model_num);
  246 +
218 247
219 hSession->ever_3270 = False; 248 hSession->ever_3270 = False;
220 249
@@ -227,33 +256,17 @@ static void net_connected(H3270 *hSession) @@ -227,33 +256,17 @@ static void net_connected(H3270 *hSession)
227 hints.ai_addr = NULL; 256 hints.ai_addr = NULL;
228 hints.ai_next = NULL; 257 hints.ai_next = NULL;
229 258
230 - if(*hostname == '$')  
231 - {  
232 - const char *name = getenv(hostname+1);  
233 - if(!name)  
234 - {  
235 - lib3270_popup_dialog( hSession,  
236 - LIB3270_NOTIFY_ERROR,  
237 - _( "Connection error" ),  
238 - _( "Unable to find selected hostname." ),  
239 - _( "Can't determine value for environment variable \"%s\" " ),  
240 - hostname);  
241 - lib3270_set_disconnected(hSession);  
242 - return ENOENT;  
243 - }  
244 - hostname = name;  
245 - }  
246 259
247 hSession->cstate = LIB3270_RESOLVING; 260 hSession->cstate = LIB3270_RESOLVING;
248 lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True); 261 lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);
249 262
250 - s = getaddrinfo(hostname, srvc, &hints, &result); 263 + s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
251 264
252 if(s != 0) 265 if(s != 0)
253 { 266 {
254 char buffer[4096]; 267 char buffer[4096];
255 268
256 - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hostname, srvc); 269 + snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
257 270
258 #if defined(WIN32) && defined(HAVE_ICONV) 271 #if defined(WIN32) && defined(HAVE_ICONV)
259 { 272 {
@@ -303,7 +316,7 @@ static void net_connected(H3270 *hSession) @@ -303,7 +316,7 @@ static void net_connected(H3270 *hSession)
303 hSession->ever_3270 = False; 316 hSession->ever_3270 = False;
304 hSession->ssl_host = 0; 317 hSession->ssl_host = 0;
305 318
306 - if(opt&LIB3270_CONNECT_OPTION_SSL) 319 + if(hSession->host.opt&LIB3270_CONNECT_OPTION_SSL)
307 { 320 {
308 #if defined(HAVE_LIBSSL) 321 #if defined(HAVE_LIBSSL)
309 hSession->ssl_host = 1; 322 hSession->ssl_host = 1;
@@ -380,7 +393,7 @@ static void net_connected(H3270 *hSession) @@ -380,7 +393,7 @@ static void net_connected(H3270 *hSession)
380 if(err != WSAEWOULDBLOCK) 393 if(err != WSAEWOULDBLOCK)
381 { 394 {
382 char buffer[4096]; 395 char buffer[4096];
383 - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hostname, srvc); 396 + snprintf(buffer,4095,_( "Can't connect to %s"), lib3270_get_host(hSession));
384 397
385 lib3270_popup_dialog( hSession, 398 lib3270_popup_dialog( hSession,
386 LIB3270_NOTIFY_ERROR, 399 LIB3270_NOTIFY_ERROR,
@@ -431,7 +444,7 @@ static void net_connected(H3270 *hSession) @@ -431,7 +444,7 @@ static void net_connected(H3270 *hSession)
431 if( errno != EINPROGRESS ) 444 if( errno != EINPROGRESS )
432 { 445 {
433 char buffer[4096]; 446 char buffer[4096];
434 - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hostname, srvc); 447 + snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
435 448
436 lib3270_popup_dialog( hSession, 449 lib3270_popup_dialog( hSession,
437 LIB3270_NOTIFY_ERROR, 450 LIB3270_NOTIFY_ERROR,
@@ -511,7 +524,7 @@ static void net_connected(H3270 *hSession) @@ -511,7 +524,7 @@ static void net_connected(H3270 *hSession)
511 524
512 trace("%s: Connection in progress",__FUNCTION__); 525 trace("%s: Connection in progress",__FUNCTION__);
513 526
514 - if(opt&LIB3270_CONNECT_OPTION_WAIT) 527 + if(wait)
515 { 528 {
516 time_t end = time(0)+120; 529 time_t end = time(0)+120;
517 530
@@ -564,6 +577,7 @@ int non_blocking(H3270 *hSession, Boolean on) @@ -564,6 +577,7 @@ int non_blocking(H3270 *hSession, Boolean on)
564 _( "Connection error" ), 577 _( "Connection error" ),
565 _( "ioctlsocket(FIONBIO) failed." ), 578 _( "ioctlsocket(FIONBIO) failed." ),
566 "%s", lib3270_win32_strerror(GetLastError())); 579 "%s", lib3270_win32_strerror(GetLastError()));
  580 + return -1;
567 } 581 }
568 #else 582 #else
569 583
src/lib3270/globals.h
@@ -223,9 +223,21 @@ enum keytype @@ -223,9 +223,21 @@ enum keytype
223 KT_GE 223 KT_GE
224 }; 224 };
225 225
  226 +LIB3270_INTERNAL struct _ansictl
  227 +{
  228 + char vintr;
  229 + char vquit;
  230 + char verase;
  231 + char vkill;
  232 + char veof;
  233 + char vwerase;
  234 + char vrprnt;
  235 + char vlnext;
  236 +} ansictl;
  237 +
226 /* default charset translation tables */ 238 /* default charset translation tables */
227 -LIB3270_INTERNAL const unsigned short ebc2asc0[256];  
228 -LIB3270_INTERNAL const unsigned short asc2ft0[256]; 239 +// LIB3270_INTERNAL const unsigned short ebc2asc0[256];
  240 +// LIB3270_INTERNAL const unsigned short asc2ft0[256];
229 241
230 242
231 /* Library internal calls */ 243 /* Library internal calls */
src/lib3270/glue.c
@@ -94,36 +94,80 @@ @@ -94,36 +94,80 @@
94 94
95 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ 95 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
96 96
97 -#if defined WIN32  
98 -  
99 -BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) 97 +/*
  98 + * parse_ctlchar
  99 + * Parse an stty control-character specification.
  100 + * A cheap, non-complaining implementation.
  101 + */
  102 +static char parse_ctlchar(char *s)
100 { 103 {
101 -// Trace("%s - Library %s",__FUNCTION__,(dwcallpurpose == DLL_PROCESS_ATTACH) ? "Loaded" : "Unloaded");  
102 -  
103 - if(dwcallpurpose == DLL_PROCESS_ATTACH)  
104 - get_version_info();  
105 -  
106 - return TRUE; 104 + if (!s || !*s)
  105 + return 0;
  106 +
  107 + if ((int) strlen(s) > 1)
  108 + {
  109 + if (*s != '^')
  110 + return 0;
  111 + else if (*(s+1) == '?')
  112 + return 0177;
  113 + else
  114 + return *(s+1) - '@';
  115 + } else
  116 + return *s;
107 } 117 }
108 118
109 -#else  
110 -  
111 int lib3270_loaded(void) 119 int lib3270_loaded(void)
112 { 120 {
  121 + trace("%s",__FUNCTION__);
  122 +
  123 + ansictl.vintr = parse_ctlchar("^C");
  124 + ansictl.vquit = parse_ctlchar("^\\");
  125 + ansictl.verase = parse_ctlchar("^H");
  126 + ansictl.vkill = parse_ctlchar("^U");
  127 + ansictl.veof = parse_ctlchar("^D");
  128 + ansictl.vwerase = parse_ctlchar("^W");
  129 + ansictl.vrprnt = parse_ctlchar("^R");
  130 + ansictl.vlnext = parse_ctlchar("^V");
  131 +
113 return 0; 132 return 0;
114 } 133 }
115 134
116 int lib3270_unloaded(void) 135 int lib3270_unloaded(void)
117 { 136 {
  137 + trace("%s",__FUNCTION__);
118 return 0; 138 return 0;
119 } 139 }
120 140
  141 +
  142 +#if defined WIN32
  143 +
  144 +BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd)
  145 +{
  146 +// Trace("%s - Library %s",__FUNCTION__,(dwcallpurpose == DLL_PROCESS_ATTACH) ? "Loaded" : "Unloaded");
  147 +
  148 + switch(dwcallpurpose)
  149 + {
  150 + case DLL_PROCESS_ATTACH:
  151 + get_version_info();
  152 + lib3270_loaded();
  153 + break;
  154 +
  155 + case DLL_PROCESS_DETACH:
  156 + lib3270_unloaded();
  157 + break;
  158 +
  159 + }
  160 +
  161 + return TRUE;
  162 +}
  163 +
121 #endif 164 #endif
122 165
123 166
124 #ifdef DEBUG 167 #ifdef DEBUG
125 extern void lib3270_initialize(void) 168 extern void lib3270_initialize(void)
126 { 169 {
  170 + lib3270_loaded();
127 } 171 }
128 #endif 172 #endif
129 173
src/lib3270/host.c
@@ -312,151 +312,7 @@ split_success: @@ -312,151 +312,7 @@ split_success:
312 } 312 }
313 */ 313 */
314 314
315 -static int do_connect(H3270 *hSession)  
316 -{  
317 -// char nb[2048]; // name buffer  
318 -// char *s; // temporary  
319 - char *chost = NULL; // to whom we will connect  
320 -// char *ps = CN;  
321 -// char *port = CN;  
322 - Boolean resolving;  
323 - Boolean pending;  
324 -// static Boolean ansi_host;  
325 -// Boolean has_colons = False;  
326 -  
327 - if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress)  
328 - return EBUSY;  
329 -  
330 - /*  
331 - // Skip leading blanks.  
332 - while (*n == ' ')  
333 - n++;  
334 -  
335 - if (!*n)  
336 - {  
337 - popup_an_error(hSession,_( "Invalid (empty) hostname" ));  
338 - return -1;  
339 - }  
340 - */  
341 -  
342 - /*  
343 - // Save in a modifiable buffer.  
344 - (void) strncpy(nb, n, 2047);  
345 -  
346 - // Strip trailing blanks.  
347 - s = nb + strlen(nb) - 1;  
348 - while (*s == ' ')  
349 - *s-- = '\0';  
350 - */  
351 -  
352 - /* Remember this hostname, as the last hostname we connected to. */  
353 - // lib3270_set_host(hSession,nb);  
354 -  
355 - /*  
356 - {  
357 - Boolean needed;  
358 -  
359 - // Strip off and remember leading qualifiers.  
360 - if ((s = split_host(hSession, nb, &ansi_host, &hSession->std_ds_host,  
361 - &hSession->passthru_host, &hSession->non_tn3270e_host, &hSession->ssl_host,  
362 - &hSession->no_login_host, hSession->luname, &port,  
363 - &needed)) == CN)  
364 - return EINVAL;  
365 -  
366 - chost = s;  
367 -  
368 - // Default the port.  
369 - if (port == CN)  
370 - port = "telnet";  
371 - }  
372 -  
373 - //  
374 - // Store the original name in globals, even if we fail the connect  
375 - // later:  
376 - // current_host is the hostname part, stripped of qualifiers, luname  
377 - // and port number  
378 - // full_current_host is the entire string, for use in reconnecting  
379 - //  
380 - //  
381 - // Replace(hSession->current_host, CN);  
382 -  
383 - has_colons = (strchr(chost, ':') != NULL);  
384 -  
385 - Replace(hSession->host.qualified,  
386 - xs_buffer("%s%s%s%s:%s",  
387 - hSession->ssl_host? "L:": "",  
388 - has_colons? "[": "",  
389 - chost,  
390 - has_colons? "]": "",  
391 - port));  
392 - */  
393 -  
394 - /* Attempt contact. */  
395 - hSession->ever_3270 = False;  
396 - hSession->ssl_host = 0;  
397 -  
398 - if(hSession->host.opt&LIB3270_CONNECT_OPTION_SSL)  
399 - {  
400 -#if defined(HAVE_LIBSSL)  
401 - hSession->ssl_host = 1;  
402 - ssl_init(hSession);  
403 -#else  
404 - popup_system_error(hSession, _( "SSL error" ),  
405 - _( "Unable to connect to secure hosts" ),  
406 - _( "This version of %s was built without support for secure sockets layer (SSL)." ),  
407 - PACKAGE_NAME  
408 - );  
409 -#endif  
410 - }  
411 -  
412 - trace("Conneting to hostname=[%s] service=[%s]",hSession->host.current, hSession->host.srvc);  
413 - if(net_connect(hSession, hSession->host.current, hSession->host.srvc, 0, &resolving,&pending) != 0 && !resolving)  
414 - {  
415 - /* Redundantly signal a disconnect. */  
416 - lib3270_set_disconnected(hSession);  
417 - return -1;  
418 - }  
419 -  
420 - chost = lib3270_free(chost);  
421 -  
422 - /* Still thinking about it? */  
423 - if (resolving)  
424 - {  
425 - hSession->cstate = RESOLVING;  
426 - lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);  
427 - return 0;  
428 - }  
429 -  
430 - /* Success. */  
431 -  
432 - /* Setup socket I/O. */  
433 -// add_input_calls(hSession,net_input,net_exception);  
434 -#ifdef _WIN32  
435 - hSession->ns_exception_id = AddExcept(hSession->sockEvent, hSession, net_exception);  
436 - hSession->ns_read_id = AddInput(hSession->sockEvent, hSession, net_input);  
437 -#else  
438 - hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception);  
439 - hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input);  
440 -#endif // WIN32  
441 -  
442 - hSession->excepting = 1;  
443 - hSession->reading = 1;  
444 -  
445 -  
446 - /* Set state and tell the world. */  
447 - if (pending)  
448 - {  
449 - hSession->cstate = PENDING;  
450 - lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True);  
451 - }  
452 - else  
453 - {  
454 - lib3270_set_connected(hSession);  
455 - }  
456 -  
457 - return 0;  
458 -}  
459 - 315 +/*
460 int lib3270_connect(H3270 *hSession, int wait) 316 int lib3270_connect(H3270 *hSession, int wait)
461 { 317 {
462 int rc; 318 int rc;
@@ -496,6 +352,7 @@ int lib3270_connect(H3270 *hSession, int wait) @@ -496,6 +352,7 @@ int lib3270_connect(H3270 *hSession, int wait)
496 352
497 return rc; 353 return rc;
498 } 354 }
  355 +*/
499 356
500 /* 357 /*
501 * Called from timer to attempt an automatic reconnection. 358 * Called from timer to attempt an automatic reconnection.
@@ -725,6 +582,12 @@ LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h) @@ -725,6 +582,12 @@ LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h)
725 return h->host.current; 582 return h->host.current;
726 } 583 }
727 584
  585 +LIB3270_EXPORT const char * lib3270_get_host(H3270 *h)
  586 +{
  587 + CHECK_SESSION_HANDLE(h);
  588 + return h->host.full;
  589 +}
  590 +
728 /* 591 /*
729 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) 592 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
730 { 593 {
src/lib3270/sources.mak
@@ -33,7 +33,7 @@ TERMINAL_SOURCES = bounds.c ctlr.c util.c toggles.c screen.c selection.c kybd.c @@ -33,7 +33,7 @@ TERMINAL_SOURCES = bounds.c ctlr.c util.c toggles.c screen.c selection.c kybd.c
33 # tables.c utf8.c 33 # tables.c utf8.c
34 34
35 # Network I/O Sources 35 # Network I/O Sources
36 -NETWORK_SOURCES = iocalls.c proxy.c connect.c 36 +NETWORK_SOURCES = iocalls.c connect.c
37 37
38 # Full library sources 38 # Full library sources
39 SOURCES = $(TERMINAL_SOURCES) $(NETWORK_SOURCES) ft.c ft_cut.c ft_dft.c glue.c resources.c \ 39 SOURCES = $(TERMINAL_SOURCES) $(NETWORK_SOURCES) ft.c ft_cut.c ft_dft.c glue.c resources.c \
src/lib3270/telnet.c
@@ -120,7 +120,8 @@ @@ -120,7 +120,8 @@
120 #define E_OPT(n) (1 << (n)) 120 #define E_OPT(n) (1 << (n))
121 #endif // X3270_TN3270E 121 #endif // X3270_TN3270E
122 122
123 -#if defined(X3270_ANSI) /*[*/ 123 +/*
  124 +#if defined(X3270_ANSI)
124 static char vintr; 125 static char vintr;
125 static char vquit; 126 static char vquit;
126 static char verase; 127 static char verase;
@@ -129,7 +130,10 @@ static char veof; @@ -129,7 +130,10 @@ static char veof;
129 static char vwerase; 130 static char vwerase;
130 static char vrprnt; 131 static char vrprnt;
131 static char vlnext; 132 static char vlnext;
132 -#endif /*]*/ 133 +#endif
  134 +*/
  135 +
  136 +struct _ansictl ansictl = { 0 };
133 137
134 static int telnet_fsm(H3270 *session, unsigned char c); 138 static int telnet_fsm(H3270 *session, unsigned char c);
135 static void net_rawout(H3270 *session, unsigned const char *buf, size_t len); 139 static void net_rawout(H3270 *session, unsigned const char *buf, size_t len);
@@ -164,7 +168,7 @@ static void do_rprnt(H3270 *hSession, char c); @@ -164,7 +168,7 @@ static void do_rprnt(H3270 *hSession, char c);
164 static void do_eof(H3270 *hSession, char c); 168 static void do_eof(H3270 *hSession, char c);
165 static void do_eol(H3270 *hSession, char c); 169 static void do_eol(H3270 *hSession, char c);
166 static void do_lnext(H3270 *hSession, char c); 170 static void do_lnext(H3270 *hSession, char c);
167 -static char parse_ctlchar(char *s); 171 +// static char parse_ctlchar(char *s);
168 static void cooked_init(H3270 *hSession); 172 static void cooked_init(H3270 *hSession);
169 #endif /*]*/ 173 #endif /*]*/
170 174
@@ -270,7 +274,8 @@ static const char *trsp_flag[2] = { &quot;POSITIVE-RESPONSE&quot;, &quot;NEGATIVE-RESPONSE&quot; }; @@ -270,7 +274,8 @@ static const char *trsp_flag[2] = { &quot;POSITIVE-RESPONSE&quot;, &quot;NEGATIVE-RESPONSE&quot; };
270 274
271 /*--[ Implement ]------------------------------------------------------------------------------------*/ 275 /*--[ Implement ]------------------------------------------------------------------------------------*/
272 276
273 -#if defined(_WIN32) /*[*/ 277 +/*
  278 +#if defined(_WIN32)
274 void sockstart(H3270 *session) 279 void sockstart(H3270 *session)
275 { 280 {
276 static int initted = 0; 281 static int initted = 0;
@@ -305,7 +310,8 @@ void sockstart(H3270 *session) @@ -305,7 +310,8 @@ void sockstart(H3270 *session)
305 _exit(1); 310 _exit(1);
306 } 311 }
307 } 312 }
308 -#endif /*]*/ 313 +#endif
  314 +*/
309 315
310 static union { 316 static union {
311 struct sockaddr sa; 317 struct sockaddr sa;
@@ -323,6 +329,7 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...) @@ -323,6 +329,7 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...)
323 #else 329 #else
324 const char *msg = strerror(errno); 330 const char *msg = strerror(errno);
325 #endif // WIN32 331 #endif // WIN32
  332 +
326 va_list args; 333 va_list args;
327 char *text; 334 char *text;
328 335
@@ -332,11 +339,17 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...) @@ -332,11 +339,17 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...)
332 339
333 lib3270_write_log(hSession, "3270", "Network error:\n%s\n%s",text,msg); 340 lib3270_write_log(hSession, "3270", "Network error:\n%s\n%s",text,msg);
334 341
335 - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, _( "Network error" ), text, "%s", msg); 342 + lib3270_popup_dialog( hSession,
  343 + LIB3270_NOTIFY_ERROR,
  344 + _( "Network error" ),
  345 + text,
  346 + "%s", msg);
  347 +
336 348
337 lib3270_free(text); 349 lib3270_free(text);
338 } 350 }
339 351
  352 +/*
340 #pragma pack(1) 353 #pragma pack(1)
341 struct connect_parm 354 struct connect_parm
342 { 355 {
@@ -347,7 +360,9 @@ struct connect_parm @@ -347,7 +360,9 @@ struct connect_parm
347 int err; 360 int err;
348 }; 361 };
349 #pragma pack() 362 #pragma pack()
  363 +*/
350 364
  365 +/*
351 static int do_connect_sock(H3270 *h, struct connect_parm *p) 366 static int do_connect_sock(H3270 *h, struct connect_parm *p)
352 { 367 {
353 #ifdef WIN32 368 #ifdef WIN32
@@ -428,7 +443,9 @@ static int do_connect_sock(H3270 *h, struct connect_parm *p) @@ -428,7 +443,9 @@ static int do_connect_sock(H3270 *h, struct connect_parm *p)
428 443
429 return 0; 444 return 0;
430 } 445 }
  446 +*/
431 447
  448 +/*
432 static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr, socklen_t addrlen) 449 static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr, socklen_t addrlen)
433 { 450 {
434 struct connect_parm p = { sizeof(struct connect_parm), sockfd, addr, addrlen, -1 }; 451 struct connect_parm p = { sizeof(struct connect_parm), sockfd, addr, addrlen, -1 };
@@ -439,7 +456,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr @@ -439,7 +456,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr
439 456
440 return p.err; 457 return p.err;
441 } 458 }
442 - 459 +*/
443 460
444 /** 461 /**
445 * Establish a telnet socket to the given host passed as an argument. 462 * Establish a telnet socket to the given host passed as an argument.
@@ -450,7 +467,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr @@ -450,7 +467,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr
450 * @param session Handle to the session descriptor. 467 * @param session Handle to the session descriptor.
451 * 468 *
452 * @return 0 if ok, non zero if failed 469 * @return 0 if ok, non zero if failed
453 - */ 470 + */ /*
454 int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Boolean *resolving, Boolean *pending) 471 int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Boolean *resolving, Boolean *pending)
455 { 472 {
456 // struct servent * sp; 473 // struct servent * sp;
@@ -467,9 +484,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -467,9 +484,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
467 int optval; 484 int optval;
468 char errmsg[1024]; 485 char errmsg[1024];
469 int rc; 486 int rc;
470 -#if defined(OMTU) /*[*/ 487 +#if defined(OMTU)
471 int mtu = OMTU; 488 int mtu = OMTU;
472 -#endif /*]*/ 489 +#endif
473 490
474 #define close_fail { (void) SOCK_CLOSE(session->sock); session->sock = -1; return -1; } 491 #define close_fail { (void) SOCK_CLOSE(session->sock); session->sock = -1; return -1; }
475 492
@@ -482,7 +499,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -482,7 +499,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
482 // if (session->netrbuf == (unsigned char *)NULL) 499 // if (session->netrbuf == (unsigned char *)NULL)
483 // session->netrbuf = (unsigned char *)lib3270_malloc(BUFSZ); 500 // session->netrbuf = (unsigned char *)lib3270_malloc(BUFSZ);
484 501
485 -#if defined(X3270_ANSI) /*[*/ 502 +#if defined(X3270_ANSI)
486 if (!t_valid) 503 if (!t_valid)
487 { 504 {
488 vintr = parse_ctlchar("^C"); 505 vintr = parse_ctlchar("^C");
@@ -496,14 +513,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -496,14 +513,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
496 513
497 t_valid = 1; 514 t_valid = 1;
498 } 515 }
499 -#endif /*]*/ 516 +#endif
500 517
501 *resolving = False; 518 *resolving = False;
502 *pending = False; 519 *pending = False;
503 520
504 // Replace(session->hostname, NewString(host)); 521 // Replace(session->hostname, NewString(host));
505 522
506 - /* get the passthru host and port number */ 523 + // get the passthru host and port number
507 if (session->passthru_host) 524 if (session->passthru_host)
508 { 525 {
509 #if defined(HAVE_GETADDRINFO) 526 #if defined(HAVE_GETADDRINFO)
@@ -567,7 +584,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -567,7 +584,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
567 return -1; 584 return -1;
568 } 585 }
569 586
570 - /* fill in the socket address of the given host */ 587 + // fill in the socket address of the given host
571 (void) memset((char *) &haddr, 0, sizeof(haddr)); 588 (void) memset((char *) &haddr, 0, sizeof(haddr));
572 if (session->passthru_host) 589 if (session->passthru_host)
573 { 590 {
@@ -593,14 +610,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -593,14 +610,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
593 } 610 }
594 } 611 }
595 612
596 - /* create the socket */ 613 + // create the socket
597 if((session->sock = socket(haddr.sa.sa_family, SOCK_STREAM, 0)) == -1) 614 if((session->sock = socket(haddr.sa.sa_family, SOCK_STREAM, 0)) == -1)
598 { 615 {
599 popup_a_sockerr(session, N_( "socket" ) ); 616 popup_a_sockerr(session, N_( "socket" ) );
600 return -1; 617 return -1;
601 } 618 }
602 619
603 - /* set options for inline out-of-band data and keepalives */ 620 + // set options for inline out-of-band data and keepalives
604 if (setsockopt(session->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&on,sizeof(on)) < 0) 621 if (setsockopt(session->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&on,sizeof(on)) < 0)
605 { 622 {
606 popup_a_sockerr(session, N_( "setsockopt(%s)" ), "SO_OOBINLINE"); 623 popup_a_sockerr(session, N_( "setsockopt(%s)" ), "SO_OOBINLINE");
@@ -615,22 +632,22 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -615,22 +632,22 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
615 } 632 }
616 #endif 633 #endif
617 634
618 - /* set the socket to be non-delaying during connect */ 635 + // set the socket to be non-delaying during connect
619 if(non_blocking(session,False) < 0) 636 if(non_blocking(session,False) < 0)
620 close_fail; 637 close_fail;
621 638
622 #if !defined(_WIN32) 639 #if !defined(_WIN32)
623 - /* don't share the socket with our children */ 640 + // don't share the socket with our children
624 (void) fcntl(session->sock, F_SETFD, 1); 641 (void) fcntl(session->sock, F_SETFD, 1);
625 #endif 642 #endif
626 643
627 - /* init ssl */ 644 + // init ssl
628 #if defined(HAVE_LIBSSL) 645 #if defined(HAVE_LIBSSL)
629 if (session->ssl_host) 646 if (session->ssl_host)
630 ssl_init(session); 647 ssl_init(session);
631 #endif 648 #endif
632 649
633 - /* connect */ 650 + // connect
634 status_connecting(session,1); 651 status_connecting(session,1);
635 rc = connect_sock(session, session->sock, &haddr.sa,ha_len); 652 rc = connect_sock(session, session->sock, &haddr.sa,ha_len);
636 653
@@ -671,15 +688,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -671,15 +688,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
671 688
672 snprintf(session->full_model_name,LIB3270_FULL_MODEL_NAME_LENGTH,"IBM-327%c-%d",session->m3279 ? '9' : '8', session->model_num); 689 snprintf(session->full_model_name,LIB3270_FULL_MODEL_NAME_LENGTH,"IBM-327%c-%d",session->m3279 ? '9' : '8', session->model_num);
673 690
674 - /* set up temporary termtype  
675 - if (session->termname == CN && session->std_ds_host)  
676 - {  
677 - sprintf(session->ttype_tmpval, "IBM-327%c-%d",session->m3279 ? '9' : '8', session->model_num);  
678 - session->termtype = session->ttype_tmpval;  
679 - }  
680 - */  
681 691
682 - /* all done */ 692 + // all done
683 #if defined(_WIN32) 693 #if defined(_WIN32)
684 if(session->sockEvent == NULL) 694 if(session->sockEvent == NULL)
685 { 695 {
@@ -718,6 +728,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -718,6 +728,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
718 return 0; 728 return 0;
719 } 729 }
720 #undef close_fail 730 #undef close_fail
  731 +*/
721 732
722 /* Set up the LU list. */ 733 /* Set up the LU list. */
723 static void setup_lus(H3270 *hSession) 734 static void setup_lus(H3270 *hSession)
@@ -2113,21 +2124,21 @@ static void net_cookout(H3270 *hSession, const char *buf, int len) @@ -2113,21 +2124,21 @@ static void net_cookout(H3270 *hSession, const char *buf, int len)
2113 /* Control chars. */ 2124 /* Control chars. */
2114 if (c == '\n') 2125 if (c == '\n')
2115 do_eol(hSession,c); 2126 do_eol(hSession,c);
2116 - else if (c == vintr) 2127 + else if (c == ansictl.vintr)
2117 do_intr(hSession, c); 2128 do_intr(hSession, c);
2118 - else if (c == vquit) 2129 + else if (c == ansictl.vquit)
2119 do_quit(hSession,c); 2130 do_quit(hSession,c);
2120 - else if (c == verase) 2131 + else if (c == ansictl.verase)
2121 do_cerase(hSession,c); 2132 do_cerase(hSession,c);
2122 - else if (c == vkill) 2133 + else if (c == ansictl.vkill)
2123 do_kill(hSession,c); 2134 do_kill(hSession,c);
2124 - else if (c == vwerase) 2135 + else if (c == ansictl.vwerase)
2125 do_werase(hSession,c); 2136 do_werase(hSession,c);
2126 - else if (c == vrprnt) 2137 + else if (c == ansictl.vrprnt)
2127 do_rprnt(hSession,c); 2138 do_rprnt(hSession,c);
2128 - else if (c == veof) 2139 + else if (c == ansictl.veof)
2129 do_eof(hSession,c); 2140 do_eof(hSession,c);
2130 - else if (c == vlnext) 2141 + else if (c == ansictl.vlnext)
2131 do_lnext(hSession,c); 2142 do_lnext(hSession,c);
2132 else if (c == 0x08 || c == 0x7f) /* Yes, a hack. */ 2143 else if (c == 0x08 || c == 0x7f) /* Yes, a hack. */
2133 do_cerase(hSession,c); 2144 do_cerase(hSession,c);
@@ -2873,7 +2884,7 @@ void net_sends(H3270 *hSession,const char *s) @@ -2873,7 +2884,7 @@ void net_sends(H3270 *hSession,const char *s)
2873 */ 2884 */
2874 void net_send_erase(H3270 *hSession) 2885 void net_send_erase(H3270 *hSession)
2875 { 2886 {
2876 - net_cookout(hSession, &verase, 1); 2887 + net_cookout(hSession, &ansictl.verase, 1);
2877 } 2888 }
2878 2889
2879 /** 2890 /**
@@ -2881,7 +2892,7 @@ void net_send_erase(H3270 *hSession) @@ -2881,7 +2892,7 @@ void net_send_erase(H3270 *hSession)
2881 */ 2892 */
2882 void net_send_kill(H3270 *hSession) 2893 void net_send_kill(H3270 *hSession)
2883 { 2894 {
2884 - net_cookout(hSession, &vkill, 1); 2895 + net_cookout(hSession, &ansictl.vkill, 1);
2885 } 2896 }
2886 2897
2887 /** 2898 /**
@@ -2889,7 +2900,7 @@ void net_send_kill(H3270 *hSession) @@ -2889,7 +2900,7 @@ void net_send_kill(H3270 *hSession)
2889 */ 2900 */
2890 void net_send_werase(H3270 *hSession) 2901 void net_send_werase(H3270 *hSession)
2891 { 2902 {
2892 - net_cookout(hSession, &vwerase, 1); 2903 + net_cookout(hSession, &ansictl.vwerase, 1);
2893 } 2904 }
2894 #endif /*]*/ 2905 #endif /*]*/
2895 2906
@@ -2991,29 +3002,6 @@ void net_abort(H3270 *hSession) @@ -2991,29 +3002,6 @@ void net_abort(H3270 *hSession)
2991 } 3002 }
2992 #endif /*]*/ 3003 #endif /*]*/
2993 3004
2994 -#if defined(X3270_ANSI) /*[*/  
2995 -/*  
2996 - * parse_ctlchar  
2997 - * Parse an stty control-character specification.  
2998 - * A cheap, non-complaining implementation.  
2999 - */  
3000 -static char  
3001 -parse_ctlchar(char *s)  
3002 -{  
3003 - if (!s || !*s)  
3004 - return 0;  
3005 - if ((int) strlen(s) > 1) {  
3006 - if (*s != '^')  
3007 - return 0;  
3008 - else if (*(s+1) == '?')  
3009 - return 0177;  
3010 - else  
3011 - return *(s+1) - '@';  
3012 - } else  
3013 - return *s;  
3014 -}  
3015 -#endif /*]*/  
3016 -  
3017 /* Return the local address for the socket. */ 3005 /* Return the local address for the socket. */
3018 int net_getsockname(const H3270 *session, void *buf, int *len) 3006 int net_getsockname(const H3270 *session, void *buf, int *len)
3019 { 3007 {
src/plugins/dbus3270/gobject.c
@@ -86,10 +86,30 @@ void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context @@ -86,10 +86,30 @@ void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context
86 86
87 void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) 87 void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context)
88 { 88 {
  89 + H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object));
  90 +
89 trace("%s object=%p context=%p",__FUNCTION__,object,context); 91 trace("%s object=%p context=%p",__FUNCTION__,object,context);
90 92
91 - g_message("Connecting to \"%s\" by remote request",uri);  
92 - dbus_g_method_return(context,lib3270_connect(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri,0)); 93 + if(uri && *uri)
  94 + {
  95 + g_message("Connecting to \"%s\" by remote request",uri);
  96 + lib3270_set_host(hSession,uri);
  97 + }
  98 + else
  99 + {
  100 + g_message("%s","Connecting by remote request");
  101 + }
  102 +
  103 + dbus_g_method_return(context,lib3270_connect(hSession,0));
  104 +}
  105 +
  106 +void pw3270_dbus_set_host(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context)
  107 +{
  108 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  109 +
  110 + g_message("Changing host to \"%s\" by remote request",uri);
  111 +
  112 + dbus_g_method_return(context,lib3270_set_host(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != NULL);
93 } 113 }
94 114
95 void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context) 115 void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context)
src/plugins/dbus3270/pw3270dbus.xml
@@ -14,6 +14,11 @@ @@ -14,6 +14,11 @@
14 <arg type="s" name="uri" direction="in" /> 14 <arg type="s" name="uri" direction="in" />
15 <arg type="i" name="result" direction="out" /> 15 <arg type="i" name="result" direction="out" />
16 </method> 16 </method>
  17 + <method name="setHost">
  18 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  19 + <arg type="s" name="uri" direction="in" />
  20 + <arg type="i" name="result" direction="out" />
  21 + </method>
17 <method name="disconnect"> 22 <method name="disconnect">
18 <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> 23 <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
19 <arg type="i" name="result" direction="out" /> 24 <arg type="i" name="result" direction="out" />
src/plugins/dbus3270/service.h
@@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
66 void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context); 66 void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context);
67 void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); 67 void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context);
68 void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); 68 void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
  69 + void pw3270_dbus_set_host(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
69 void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); 70 void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context);
70 void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); 71 void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context);
71 void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); 72 void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context);