Redesign the macnet.c infrastructure, largely so as to avoid using Gestalt(),

which didn't detect the MacTCP emulation in Owen's Open Transport.

[originally from svn r2703]
This commit is contained in:
Ben Harris 2003-01-24 00:25:33 +00:00
Родитель 596f6e9787
Коммит 6993486b43
3 изменённых файлов: 93 добавлений и 93 удалений

Просмотреть файл

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.35 2003/01/23 22:57:43 ben Exp $ */
/* $Id: mac.c,v 1.36 2003/01/24 00:25:33 ben Exp $ */
/*
* Copyright (c) 1999 Ben Harris
* All rights reserved.
@ -172,22 +172,7 @@ static void mac_startup(void) {
DisposeHandle((Handle)ti);
}
#if 0 /* OpenTransport? */
if (Gestalt(gestaltOpenTpt, &mac_gestalts.otptattr) != noErr ||
(mac_gestalts.otptattr & gestaltOpenTptTCPPresentMask) == 0 ||
ot_init() != noErr)
#endif
mac_gestalts.otptattr = 0;
if (mac_gestalts.otptattr == 0) {
/* MacTCP? */
if (Gestalt(FOUR_CHAR_CODE('mtcp'), &mac_gestalts.mtcpvers) != noErr)
mac_gestalts.mtcpvers = 0;
if (mac_gestalts.mtcpvers > 0) {
if (mactcp_init() != noErr)
mac_gestalts.mtcpvers = 0;
}
} else
mac_gestalts.mtcpvers = 0;
sk_init();
/* We've been tested with the Appearance Manager */
if (mac_gestalts.apprvers != 0)
@ -254,10 +239,7 @@ static void mac_eventloop(void) {
mac_event(&event);
if (borednow)
cleanup_exit(0);
if (mac_gestalts.mtcpvers != 0)
mactcp_poll();
if (mac_gestalts.otptattr != 0)
ot_poll();
sk_poll();
mac_pollterm();
}
DisposeRgn(cursrgn);

Просмотреть файл

@ -28,8 +28,6 @@ struct mac_gestalts {
long windattr;
long encvvers; /* TEC version (from TECGetInfo()) */
long uncvattr; /* Unicode Converter attributes (frem TECGetInfo()) */
long mtcpvers;
long otptattr;
};
extern struct mac_gestalts mac_gestalts;
@ -112,6 +110,8 @@ extern void *open_settings_r_fsp(FSSpec *);
extern void *open_settings_w_fsp(FSSpec *);
/* from macucs.c */
extern void init_ucs(Session *);
/* from macnet.c */
extern void sk_poll(void);
/* from mtcpnet.c */
extern OSErr mactcp_init(void);
extern void mactcp_cleanup(void);

Просмотреть файл

@ -2,6 +2,52 @@
#include "network.h"
#include "mac.h"
struct macnet_stack {
SockAddr (*namelookup)(char const *, char **);
SockAddr (*nonamelookup)(char const *);
void (*getaddr)(SockAddr, char *, int);
int (*hostname_is_local)(char *);
int (*address_is_local)(SockAddr);
int (*addrtype)(SockAddr);
void (*addrcopy)(SockAddr, char *);
void (*addr_free)(SockAddr);
Socket (*skregister)(void *, Plug); /* "register" is a reserved word */
Socket (*new)(SockAddr, int, int, int, int, Plug);
Socket (*newlistener)(char *, int, Plug, int);
char *(*addr_error)(SockAddr);
void (*poll)(void);
void (*cleanup)(void);
};
static struct macnet_stack *stack;
static struct macnet_stack ot = {
ot_namelookup, ot_nonamelookup, ot_getaddr, ot_hostname_is_local,
ot_address_is_local, ot_addrtype, ot_addrcopy, ot_addr_free,
ot_register, ot_new, ot_newlistener, ot_addr_error, ot_poll, ot_cleanup
};
static struct macnet_stack mactcp = {
mactcp_namelookup, mactcp_nonamelookup, mactcp_getaddr,
mactcp_hostname_is_local, mactcp_address_is_local, mactcp_addrtype,
mactcp_addrcopy, mactcp_addr_free, mactcp_register, mactcp_new,
mactcp_newlistener, mactcp_addr_error, mactcp_poll, mactcp_cleanup
};
void sk_init(void)
{
#if 0
if (ot_init() == noErr)
stack = &ot;
else
#endif
if (mactcp_init() == noErr)
stack = &mactcp;
else
stack = NULL;
}
/*
* Network functions exported to the world. These choose whether to call
* MacTCP or OpenTransport and behave accordingly.
@ -9,32 +55,24 @@
SockAddr sk_namelookup(char const *host, char **canonicalname)
{
if (mac_gestalts.otptattr != 0)
return ot_namelookup(host, canonicalname);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_namelookup(host, canonicalname);
else
if (stack != NULL)
return stack->namelookup(host, canonicalname);
return NULL;
}
SockAddr sk_nonamelookup(char const *host)
{
if (mac_gestalts.otptattr != 0)
return ot_nonamelookup(host);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_nonamelookup(host);
else
if (stack != NULL)
return stack->nonamelookup(host);
return NULL;
}
void sk_getaddr(SockAddr addr, char *buf, int buflen)
{
if (mac_gestalts.otptattr != 0)
ot_getaddr(addr, buf, buflen);
else if (mac_gestalts.mtcpvers != 0)
mactcp_getaddr(addr, buf, buflen);
if (stack != NULL)
stack->getaddr(addr, buf, buflen);
else
*buf = '\0';
}
@ -42,62 +80,46 @@ void sk_getaddr(SockAddr addr, char *buf, int buflen)
int sk_hostname_is_local(char *name)
{
if (mac_gestalts.otptattr != 0)
return ot_hostname_is_local(name);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_hostname_is_local(name);
else
if (stack != NULL)
return stack->hostname_is_local(name);
return 0;
}
int sk_address_is_local(SockAddr addr)
{
if (mac_gestalts.otptattr != 0)
return ot_address_is_local(addr);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_address_is_local(addr);
else
if (stack != NULL)
return stack->address_is_local(addr);
return 0;
}
int sk_addrtype(SockAddr addr)
{
if (mac_gestalts.otptattr != 0)
return ot_addrtype(addr);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_addrtype(addr);
else
if (stack != NULL)
return stack->addrtype(addr);
return 0;
}
void sk_addrcopy(SockAddr addr, char *buf)
{
if (mac_gestalts.otptattr != 0)
ot_addrcopy(addr, buf);
else if (mac_gestalts.mtcpvers != 0)
mactcp_addrcopy(addr, buf);
if (stack != NULL)
stack->addrcopy(addr, buf);
}
void sk_addr_free(SockAddr addr)
{
if (mac_gestalts.otptattr != 0)
ot_addr_free(addr);
else if (mac_gestalts.mtcpvers != 0)
mactcp_addr_free(addr);
if (stack != NULL)
stack->addr_free(addr);
}
Socket sk_register(void *sock, Plug plug)
{
if (mac_gestalts.otptattr != 0)
return ot_register(sock, plug);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_register(sock, plug);
else
if (stack != NULL)
return stack->skregister(sock, plug);
return NULL;
}
@ -105,43 +127,39 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
int nodelay, Plug plug)
{
if (mac_gestalts.otptattr != 0)
return ot_new(addr, port, privport, oobinline, nodelay, plug);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_new(addr, port, privport, oobinline, nodelay, plug);
else
if (stack != NULL)
return stack->new(addr, port, privport, oobinline, nodelay, plug);
return NULL;
}
Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
{
if (mac_gestalts.otptattr != 0)
return ot_newlistener(srcaddr, port, plug, local_host_only);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_newlistener(srcaddr, port, plug, local_host_only);
else
if (stack != NULL)
return stack->newlistener(srcaddr, port, plug, local_host_only);
return NULL;
}
char *sk_addr_error(SockAddr addr)
{
if (mac_gestalts.otptattr != 0)
return ot_addr_error(addr);
else if (mac_gestalts.mtcpvers != 0)
return mactcp_addr_error(addr);
else
if (stack != NULL)
return stack->addr_error(addr);
return "No TCP/IP stack installed";
}
void sk_poll(void)
{
if (stack != NULL)
stack->poll();
}
void sk_cleanup(void)
{
if (mac_gestalts.otptattr != 0)
ot_cleanup();
else if (mac_gestalts.mtcpvers != 0)
mactcp_cleanup();
if (stack != NULL)
stack->cleanup();
}
/*