	Pseudo-telnet agent

	This agent is not a real Telnet agent, it only returns a MIME
	type [[application/x-telnet]] but doesn't really open a
	connection or retrieve data. It is there so that the browser
	can treat telnet connections the same as any other protocol.

	When [[openTelnet]] is called, the agent returns a file
	descriptor (opened on /dev/null), but it doesn't do anything
	else.

	[[readTelnet]] always returns 0, indicating an `end of file',
	which directs the browser to then call [[closeTelnet]].

	[[closeTelnet]] closes the file descriptor again.

	[[infoTelnet]] sets the [[mime_type]] field of the
	[[W3ADocumentInfo]] structure to [[application/x-telnet]].
	This is what causes the browser to select the Telnet viewer
	(which then opens and maintains its own connection).


	Bert Bos <bert@let.rug.nl>, 8 Nov 1994

	Copyright NBBI, 1994

<<*>>=
#include <config.h>
#include <fcntl.h>
#include <w3a.h>
#include <str.h>


EXPORT Bool initTELNET(char ***protocols, int *nrprotocols)
{
    static char *protos[] = {"telnet"};

    *protocols = protos;
    *nrprotocols = 1;
    return TRUE;
}

EXPORT int openTELNET(const char *url, int method, int flg, const char *refer)
{
    return open("/dev/null", O_RDONLY);		/* Need to return file desc */
}

EXPORT int readTELNET(int fd, char *buf, size_t nbytes) {return 0;} /* EOF */

EXPORT Bool doneTELNET(int fd) {return TRUE;}	/* means "query's been sent" */

EXPORT int peekTELNET(int fd) {return 1;}	/* means readTELNET is ready */

EXPORT int writeTELNET(int fd, const char *buf, size_t nbytes)
{
    errno = EMETHOD;
    return -1;
}

EXPORT Bool closeTELNET(int fd) {return close(fd) != -1;}

EXPORT Bool deleteTELNET(const char *url) {errno = EMETHOD; return -1;}

EXPORT Bool infoTELNET(int fd, W3ADocumentInfo *buf)
{
    dispose(buf->mime_type);
    dispose(buf->mime_params);
    buf->mime_type = newstring("application/x-telnet");
    return TRUE;
}

