diff --git a/TODO.txt b/TODO.txt index 2696cf8..6c803d3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,6 +4,13 @@ * orca/merlin compatability +* gopher -I http://yahoo.com ; gopher -I http://someplace else +- the second invocation sometimes returns the results of the first. +- seems to be an issue with the DNS lookup as it is, in fact, connecting + to the wrong address. + +- gopher -i http://... crashed, possibly in setfileattr (which should have even been called) + ---- fixed diff --git a/common.c b/common.c index 9e6d11e..ffbf488 100644 --- a/common.c +++ b/common.c @@ -12,8 +12,9 @@ #include +#include "options.h" #include "prototypes.h" - #include "connection.h" +#include "connection.h" int read_binary(Word ipid, FILE *file, ReadBlock *dcb) { @@ -116,7 +117,7 @@ int ConnectLoop(char *host, Word port, Connection *connection) { LongWord qtick; - ConnectionInit(connection, MMStartUp()); + ConnectionInit(connection, MMStartUp(), flags._v ? DisplayCallback : NULL); ConnectionOpenC(connection, host, port); // 30 second timeout. diff --git a/connection.c b/connection.c index d01b1d0..54fdbf7 100644 --- a/connection.c +++ b/connection.c @@ -1,10 +1,14 @@ #pragma optimize 79 #pragma noroot +#include +#include "Memory.h" + #include "connection.h" #include #include "s16debug.h" + static char pstring[256]; @@ -13,6 +17,27 @@ static Word LoginAndOpen(Connection *buffer) Word ipid; Word terr; + if (buffer->displayPtr) + { + static char message[] = "\pConnecting to xxx.xxx.xxx.xxx:xxxxx"; + + Word length; + Word tmp; + + length = 15; + // first the ip addresss... + tmp = TCPIPConvertIPToCASCII(buffer->dnr.DNRIPaddress, message + length, 0); + length += tmp; + + message[length++] = ':'; + // now the port... + Int2Dec(buffer->port, message + length, 5, 0); + length += 5; + message[length] = 0; + message[0] = length; + buffer->displayPtr(message); + } + ipid = TCPIPLogin( buffer->memID, buffer->dnr.DNRIPaddress, @@ -65,6 +90,12 @@ Word ConnectionPoll(Connection *buffer) else if (buffer->dnr.DNRstatus != DNR_Pending) { buffer->state = kConnectionStateError; + if (buffer->displayPtr) + { + static char message[] = "\pDNR lookup failed: $xxxx"; + Int2Hex(buffer->dnr.DNRstatus, message + 21, 4); + buffer->displayPtr(message); + } return -1; } } @@ -152,7 +183,7 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port) buffer->terr = 0; buffer->port = port; - if (!buffer || !*buffer) return -1; + if (!buffer || !*buffer || !host || !*host) return -1; // 1. check if we need to do DNR. if (TCPIPValidateIPString(host)) @@ -165,17 +196,31 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port) return LoginAndOpen(buffer); } // do dnr. + if (buffer->displayPtr) + { + static char message[256] = "\pDNR lookup: "; + BlockMove(host + 1, message + 13, host[0]); + message[0] = 13 + host[0]; + buffer->displayPtr(message); + } + TCPIPDNRNameToIP(host, &buffer->dnr); if (_toolErr) { buffer->state = kConnectionStateError; + if (buffer->displayPtr) + { + static char message[] = "\pDNR lookup tool error: $xxxx"; + Int2Hex(_toolErr, message + 25, 4); + buffer->displayPtr(message); + } return -1; } buffer->state = kConnectionStateDNR; return 0; } -void ConnectionInit(Connection *buffer, Word memID) +void ConnectionInit(Connection *buffer, Word memID, ConnectionCallback displayPtr) { buffer->memID = memID; buffer->ipid = 0; @@ -184,6 +229,7 @@ void ConnectionInit(Connection *buffer, Word memID) buffer->port = 0; buffer->dnr.DNRstatus = 0; buffer->dnr.DNRIPaddress = 0; + buffer->displayPtr = displayPtr; } Word ConnectionClose(Connection *buffer) @@ -195,6 +241,13 @@ Word ConnectionClose(Connection *buffer) { buffer->state = kConnectionStateDisconnecting; buffer->terr = TCPIPCloseTCP(buffer->ipid); + + if (buffer->displayPtr) + { + static char message[] = "\pClosing connection: $0000"; + Int2Hex(buffer->terr, message + 22, 4); + buffer->displayPtr(message); + } return 0; } @@ -202,6 +255,12 @@ Word ConnectionClose(Connection *buffer) { TCPIPCancelDNR(&buffer->dnr); buffer->state = 0; + + if (buffer->displayPtr) + { + static char message[] = "\pDNR lookup canceled"; + buffer->displayPtr(message); + } return 1; } diff --git a/connection.h b/connection.h index 56a1337..ff260a9 100644 --- a/connection.h +++ b/connection.h @@ -14,6 +14,7 @@ enum { kConnectionStateError }; +typedef void (*ConnectionCallback)(const char *message); typedef struct Connection { Word memID; Word ipid; @@ -21,11 +22,12 @@ typedef struct Connection { Word state; dnrBuffer dnr; Word port; + ConnectionCallback displayPtr; } Connection; -void ConnectionInit(Connection *, Word memID); +void ConnectionInit(Connection *, Word memID, ConnectionCallback displayPtr); Word ConnectionOpen(Connection *, const char *host, Word port); Word ConnectionOpenC(Connection *, const char *host, Word port); diff --git a/main.c b/main.c index 78f0816..81158bf 100644 --- a/main.c +++ b/main.c @@ -185,6 +185,7 @@ void help(void) puts(""); puts("-h show help"); puts("-V show version"); + puts("-v be verbose"); puts("-o file write output to file"); puts("-O write output to file based on URL"); puts(""); @@ -196,6 +197,19 @@ void help(void) puts("-I print only headers (HEAD)"); } +// #pragma databank [push | pop] would be nice... +#pragma databank 1 +pascal void DisplayCallback(const char *message) +{ + unsigned length; + + // message is a p-string. + length = message ? message[0] : 0; + if (!length) return; + + fprintf(stderr, "%.*s\n", length, message + 1); +} +#pragma databank 0 int main(int argc, char **argv) { @@ -225,7 +239,7 @@ int main(int argc, char **argv) } - mf = StartUpTCP(NULL); + mf = StartUpTCP(flags._v ? DisplayCallback : NULL); if (mf < 0) { @@ -236,8 +250,6 @@ int main(int argc, char **argv) - - if (argc == 2) { const char *url; @@ -272,7 +284,7 @@ int main(int argc, char **argv) } } - ShutDownTCP(mf, false, NULL); + ShutDownTCP(mf, false, flags._v ? DisplayCallback : NULL); ShutDownTZ(tf); return 0; diff --git a/prototypes.h b/prototypes.h index 1edc9af..637dfcb 100644 --- a/prototypes.h +++ b/prototypes.h @@ -14,6 +14,9 @@ #define CLI() asm { cli } +pascal void DisplayCallback(const char *message); + + typedef struct ReadBlock { LongWord requestCount;