mirror of
https://github.com/ksherlock/gopher.git
synced 2024-12-28 04:31:44 +00:00
add verbose logging for the connection initiation.
This commit is contained in:
parent
cd55a2de3b
commit
b7e90885aa
7
TODO.txt
7
TODO.txt
@ -4,6 +4,13 @@
|
|||||||
* orca/merlin compatability
|
* 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
|
fixed
|
||||||
|
3
common.c
3
common.c
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ int ConnectLoop(char *host, Word port, Connection *connection)
|
|||||||
{
|
{
|
||||||
LongWord qtick;
|
LongWord qtick;
|
||||||
|
|
||||||
ConnectionInit(connection, MMStartUp());
|
ConnectionInit(connection, MMStartUp(), flags._v ? DisplayCallback : NULL);
|
||||||
ConnectionOpenC(connection, host, port);
|
ConnectionOpenC(connection, host, port);
|
||||||
|
|
||||||
// 30 second timeout.
|
// 30 second timeout.
|
||||||
|
63
connection.c
63
connection.c
@ -1,10 +1,14 @@
|
|||||||
#pragma optimize 79
|
#pragma optimize 79
|
||||||
#pragma noroot
|
#pragma noroot
|
||||||
|
|
||||||
|
#include <IntMath.h>
|
||||||
|
#include "Memory.h"
|
||||||
|
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "s16debug.h"
|
#include "s16debug.h"
|
||||||
|
|
||||||
|
|
||||||
static char pstring[256];
|
static char pstring[256];
|
||||||
|
|
||||||
|
|
||||||
@ -13,6 +17,27 @@ static Word LoginAndOpen(Connection *buffer)
|
|||||||
Word ipid;
|
Word ipid;
|
||||||
Word terr;
|
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(
|
ipid = TCPIPLogin(
|
||||||
buffer->memID,
|
buffer->memID,
|
||||||
buffer->dnr.DNRIPaddress,
|
buffer->dnr.DNRIPaddress,
|
||||||
@ -65,6 +90,12 @@ Word ConnectionPoll(Connection *buffer)
|
|||||||
else if (buffer->dnr.DNRstatus != DNR_Pending)
|
else if (buffer->dnr.DNRstatus != DNR_Pending)
|
||||||
{
|
{
|
||||||
buffer->state = kConnectionStateError;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +183,7 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
|
|||||||
buffer->terr = 0;
|
buffer->terr = 0;
|
||||||
buffer->port = port;
|
buffer->port = port;
|
||||||
|
|
||||||
if (!buffer || !*buffer) return -1;
|
if (!buffer || !*buffer || !host || !*host) return -1;
|
||||||
|
|
||||||
// 1. check if we need to do DNR.
|
// 1. check if we need to do DNR.
|
||||||
if (TCPIPValidateIPString(host))
|
if (TCPIPValidateIPString(host))
|
||||||
@ -165,17 +196,31 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
|
|||||||
return LoginAndOpen(buffer);
|
return LoginAndOpen(buffer);
|
||||||
}
|
}
|
||||||
// do dnr.
|
// 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);
|
TCPIPDNRNameToIP(host, &buffer->dnr);
|
||||||
if (_toolErr)
|
if (_toolErr)
|
||||||
{
|
{
|
||||||
buffer->state = kConnectionStateError;
|
buffer->state = kConnectionStateError;
|
||||||
|
if (buffer->displayPtr)
|
||||||
|
{
|
||||||
|
static char message[] = "\pDNR lookup tool error: $xxxx";
|
||||||
|
Int2Hex(_toolErr, message + 25, 4);
|
||||||
|
buffer->displayPtr(message);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buffer->state = kConnectionStateDNR;
|
buffer->state = kConnectionStateDNR;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionInit(Connection *buffer, Word memID)
|
void ConnectionInit(Connection *buffer, Word memID, ConnectionCallback displayPtr)
|
||||||
{
|
{
|
||||||
buffer->memID = memID;
|
buffer->memID = memID;
|
||||||
buffer->ipid = 0;
|
buffer->ipid = 0;
|
||||||
@ -184,6 +229,7 @@ void ConnectionInit(Connection *buffer, Word memID)
|
|||||||
buffer->port = 0;
|
buffer->port = 0;
|
||||||
buffer->dnr.DNRstatus = 0;
|
buffer->dnr.DNRstatus = 0;
|
||||||
buffer->dnr.DNRIPaddress = 0;
|
buffer->dnr.DNRIPaddress = 0;
|
||||||
|
buffer->displayPtr = displayPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Word ConnectionClose(Connection *buffer)
|
Word ConnectionClose(Connection *buffer)
|
||||||
@ -195,6 +241,13 @@ Word ConnectionClose(Connection *buffer)
|
|||||||
{
|
{
|
||||||
buffer->state = kConnectionStateDisconnecting;
|
buffer->state = kConnectionStateDisconnecting;
|
||||||
buffer->terr = TCPIPCloseTCP(buffer->ipid);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +255,12 @@ Word ConnectionClose(Connection *buffer)
|
|||||||
{
|
{
|
||||||
TCPIPCancelDNR(&buffer->dnr);
|
TCPIPCancelDNR(&buffer->dnr);
|
||||||
buffer->state = 0;
|
buffer->state = 0;
|
||||||
|
|
||||||
|
if (buffer->displayPtr)
|
||||||
|
{
|
||||||
|
static char message[] = "\pDNR lookup canceled";
|
||||||
|
buffer->displayPtr(message);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ enum {
|
|||||||
kConnectionStateError
|
kConnectionStateError
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*ConnectionCallback)(const char *message);
|
||||||
typedef struct Connection {
|
typedef struct Connection {
|
||||||
Word memID;
|
Word memID;
|
||||||
Word ipid;
|
Word ipid;
|
||||||
@ -21,11 +22,12 @@ typedef struct Connection {
|
|||||||
Word state;
|
Word state;
|
||||||
dnrBuffer dnr;
|
dnrBuffer dnr;
|
||||||
Word port;
|
Word port;
|
||||||
|
ConnectionCallback displayPtr;
|
||||||
} Connection;
|
} Connection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConnectionInit(Connection *, Word memID);
|
void ConnectionInit(Connection *, Word memID, ConnectionCallback displayPtr);
|
||||||
|
|
||||||
Word ConnectionOpen(Connection *, const char *host, Word port);
|
Word ConnectionOpen(Connection *, const char *host, Word port);
|
||||||
Word ConnectionOpenC(Connection *, const char *host, Word port);
|
Word ConnectionOpenC(Connection *, const char *host, Word port);
|
||||||
|
20
main.c
20
main.c
@ -185,6 +185,7 @@ void help(void)
|
|||||||
puts("");
|
puts("");
|
||||||
puts("-h show help");
|
puts("-h show help");
|
||||||
puts("-V show version");
|
puts("-V show version");
|
||||||
|
puts("-v be verbose");
|
||||||
puts("-o file write output to file");
|
puts("-o file write output to file");
|
||||||
puts("-O write output to file based on URL");
|
puts("-O write output to file based on URL");
|
||||||
puts("");
|
puts("");
|
||||||
@ -196,6 +197,19 @@ void help(void)
|
|||||||
puts("-I print only headers (HEAD)");
|
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)
|
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)
|
if (mf < 0)
|
||||||
{
|
{
|
||||||
@ -236,8 +250,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
const char *url;
|
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);
|
ShutDownTZ(tf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
#define CLI() asm { cli }
|
#define CLI() asm { cli }
|
||||||
|
|
||||||
|
|
||||||
|
pascal void DisplayCallback(const char *message);
|
||||||
|
|
||||||
|
|
||||||
typedef struct ReadBlock
|
typedef struct ReadBlock
|
||||||
{
|
{
|
||||||
LongWord requestCount;
|
LongWord requestCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user