jcs
/detritus
/amendments
/4
client: Use progress windows for connection sequence
Change cursor in progress() appropriately
jcs made amendment 4 about 1 year ago
--- client.c Mon Sep 30 20:45:34 2024
+++ client.c Mon Sep 30 21:36:32 2024
@@ -89,7 +89,7 @@ client_init(void)
if (client == NULL)
panic("Out of memory allocating client");
- GetIndPattern(&fill_pattern, sysPatListID, 7);
+ GetIndPattern(&fill_pattern, sysPatListID, 10);
/* main window */
width = screenBits.bounds.right - screenBits.bounds.left - PADDING;
@@ -418,6 +418,9 @@ client_connect(struct client *client)
HUnlock(te->hText);
HUnlock(client->uri_te);
+ /* TODO: support URIs with port? */
+ client->req->port = DEFAULT_GEMINI_PORT;
+
if (count = 0, sscanf(client->req->uri, "gemini://%255[^/]/%*s%n",
&client->req->hostname, &count) == 1 && count > 10) {
/* gemini://host/path */
@@ -448,9 +451,6 @@ client_connect(struct client *client)
return;
}
- /* TODO: support URIs with port? */
- client->req->port = 6667; //DEFAULT_GEMINI_PORT;
-
TESetText(client->req->uri, strlen(client->req->uri), client->uri_te);
HLock(client->uri_te);
r = (*(client->uri_te))->viewRect;
@@ -461,27 +461,25 @@ client_connect(struct client *client)
sizeof(client->req->uri));
if (client->req->host_ip == 0) {
- client_printf(client, "[Resolving \"%s\"]\r",
- client->req->hostname);
+ progress("Resolving \"%s\"...", client->req->hostname);
err = DNSResolveName(client->req->hostname,
&client->req->host_ip, NULL);
- err = 0;
- client->req->host_ip = ip2long("192.168.1.196");
if (err) {
+ progress(NULL);
client_printf(client, "[Failed resolving: %d]\r", err);
return;
}
}
long2ip(client->req->host_ip, (char *)&ip_s);
- client_printf(client, "[Connecting to \"%s\" (%s) on port %d]\r",
- client->req->hostname, ip_s, client->req->port);
+ progress("Connecting to %s port %d...", ip_s, client->req->port);
err = _TCPCreate(&client->req->tcp_iopb, &client->req->tcp_stream,
(Ptr)client->req->tcp_buf, sizeof(client->req->tcp_buf), NULL, NULL,
NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[TCPCreate failed: %d]\r", err);
goto error;
}
@@ -490,6 +488,7 @@ client_connect(struct client *client)
client->req->host_ip, client->req->port, &local_ip, &local_port,
NULL, NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[Failed connecting to %s (%s) port %d: %d]\r",
client->req->hostname, ip_s, client->req->port, err);
goto error;
@@ -498,6 +497,7 @@ client_connect(struct client *client)
err = _TCPStatus(&client->req->tcp_iopb, client->req->tcp_stream,
&client->req->tcp_status_pb, NULL, NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[Failed TCPStatus on connection to %s (%s) "
"port %d: %d]\r", client->req->hostname, ip_s, port, err);
goto error;
@@ -512,9 +512,9 @@ client_connect(struct client *client)
tls_req.unix_time[2] = (time >> 8) & 0xff;
tls_req.unix_time[3] = (time) & 0xff;
- client->req->tls_id = 123;
+ client->req->tls_id = 1;
- client_printf(client, "[Creating TLS context]\r");
+ progress("Performing TLS handshake...");
scsi_tls_init(client->req->tls_id, client->scsi_buf,
sizeof(client->scsi_buf), &tls_req);
@@ -533,6 +533,7 @@ client_shuffle_data(struct client *client)
short cipherspace, plainspace, error;
if (client->req->tcp_iopb.ioResult > 0) {
+ progress(NULL);
client->req->state = REQ_STATE_DISCONNECTED;
return;
}
@@ -543,6 +544,7 @@ client_shuffle_data(struct client *client)
while (status != 0) {
if (status & 0x1) {
/* closed */
+ progress(NULL);
client_printf(client, "[TLS handshake failed: %d, 0x%x]\r",
error, status);
client->req->state = REQ_STATE_DISCONNECTED;
@@ -557,6 +559,7 @@ client_shuffle_data(struct client *client)
if (status & 0x10) {
/* tls has plaintext data for us */
+ progress(NULL);
shuffle_tls_read_plaintext(client);
status &= ~0x10;
}
@@ -574,6 +577,7 @@ client_shuffle_data(struct client *client)
}
if (status) {
+ progress(NULL);
client_printf(client, "[Status is 0x%x?]\r", status);
return;
}
@@ -604,6 +608,7 @@ shuffle_read_tls_ciphertext(struct client *client)
err = _TCPSend(&client->req->tcp_iopb, client->req->tcp_stream,
client->req->tcp_wds, NULL, NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[TCPSend failed: %d]\r", err);
client->req->state = REQ_STATE_DISCONNECTED;
return;
@@ -622,6 +627,7 @@ shuffle_read_tcp_ciphertext(struct client *client, sho
err = _TCPStatus(&client->req->tcp_iopb, client->req->tcp_stream,
&client->req->tcp_status_pb, NULL, NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[Failed TCPStatus: %d]\r", err);
client->req->state = REQ_STATE_DISCONNECTED;
return;
@@ -636,6 +642,7 @@ shuffle_read_tcp_ciphertext(struct client *client, sho
(Ptr)(client->req->tcp_input + client->req->tcp_input_len),
&slen, NULL, NULL, false);
if (err) {
+ progress(NULL);
client_printf(client, "[Failed TCPRcv: %d]\r", err);
client->req->state = REQ_STATE_DISCONNECTED;
return;
@@ -677,8 +684,11 @@ shuffle_read_tcp_ciphertext(struct client *client, sho
client->req->tcp_input_len);
}
} else {
+ progress(NULL);
client_printf(client, "[Failed sending %d bytes of ciphertext "
"to TLS]\r", slen);
+ client->req->state = REQ_STATE_DISCONNECTED;
+ return;
}
}
}
@@ -712,8 +722,11 @@ shuffle_tls_send_plaintext(struct client *client, shor
"TLS, %ld left]\r", len, client->req->uri_len);
}
} else {
+ progress(NULL);
client_printf(client, "[Failed sending %ld bytes of plaintext "
"to TLS]\r", slen);
+ client->req->state = REQ_STATE_DISCONNECTED;
+ return;
}
}
--- util.c Mon Sep 30 17:20:00 2024
+++ util.c Mon Sep 30 21:43:08 2024
@@ -878,6 +878,8 @@ void
progress(char *format, ...)
{
static Str255 progress_s;
+ Cursor c;
+ CursHandle ch;
Handle thandle;
va_list argptr;
Rect bounds;
@@ -889,6 +891,7 @@ progress(char *format, ...)
DisposDialog(progress_dialog);
DisposHandle(progress_ditl_h);
progress_dialog = NULL;
+ SetCursor(&arrow);
}
return;
}
@@ -912,6 +915,9 @@ progress(char *format, ...)
GetDItem(progress_dialog, 1, &ttype, &thandle, &trect);
SetIText(thandle, progress_s);
+ ch = GetCursor(watchCursor);
+ c = **ch;
+ SetCursor(&c);
ShowWindow(progress_dialog);
DrawDialog(progress_dialog);
}