summaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c108
1 files changed, 80 insertions, 28 deletions
diff --git a/server.c b/server.c
index d1bc769..2d78fd9 100644
--- a/server.c
+++ b/server.c
@@ -23,11 +23,44 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
* *
+ * *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
* ************************************************** */
#include "scope.h"
#include "x11.h"
+#ifdef SYSV
+#define bzero(s,l) memset(s, 0, l)
+#define bcopy(s,d,l) memmove(d,s,l)
+#endif
+
struct TypeDef TD[MaxTypes];
unsigned char RBf[2];
unsigned char SBf[4];
@@ -40,6 +73,7 @@ extern char ScopeEnabled;
/* */
/* ************************************************************ */
+void
ReportFromClient(fd, buf, n)
FD fd;
unsigned char *buf;
@@ -56,6 +90,7 @@ ReportFromClient(fd, buf, n)
ProcessBuffer(fd, buf, n);
}
+void
ReportFromServer(fd, buf, n)
FD fd;
unsigned char *buf;
@@ -83,13 +118,14 @@ static struct timeval tp;
/* print the time since we started in hundredths (1/100) of seconds */
+void
PrintTime()
{
static long lastsec = 0;
long sec /* seconds */ ;
long hsec /* hundredths of a second */ ;
- (void)gettimeofday(&tp, (struct timezone *)NULL);
+ gettimeofday(&tp, (struct timezone *)NULL);
if (ZeroTime1 == -1 || (tp.tv_sec - lastsec) >= 1000)
{
ZeroTime1 = tp.tv_sec;
@@ -174,6 +210,7 @@ Boolean IBool(buf)
/* we will need to save bytes until we get a complete request to
interpret. The following procedures provide this ability */
+static void
SaveBytes(fd, buf, n)
FD fd;
unsigned char *buf;
@@ -185,13 +222,10 @@ SaveBytes(fd, buf, n)
/* not enough room so far; malloc more space and copy */
long SizeofNewBytes = (CS[fd].NumberofSavedBytes + n + 1);
unsigned char *NewBytes = (unsigned char *)Malloc (SizeofNewBytes);
- if (CS[fd].NumberofSavedBytes > 0)
- {
- bcopy(/* from */(char *)CS[fd].SavedBytes,
- /* to */(char *)NewBytes,
- /* count */(int)CS[fd].NumberofSavedBytes);
- Free((char *)CS[fd].SavedBytes);
- }
+ bcopy(/* from */(char *)CS[fd].SavedBytes,
+ /* to */(char *)NewBytes,
+ /* count */(int)CS[fd].SizeofSavedBytes);
+ Free((char *)CS[fd].SavedBytes);
CS[fd].SavedBytes = NewBytes;
CS[fd].SizeofSavedBytes = SizeofNewBytes;
}
@@ -203,6 +237,7 @@ SaveBytes(fd, buf, n)
CS[fd].NumberofSavedBytes += n;
}
+static void
RemoveSavedBytes(fd, n)
FD fd;
long n;
@@ -233,15 +268,13 @@ RemoveSavedBytes(fd, n)
/* following are the possible values for ByteProcessing */
/* forward declarations */
-long StartSetUpMessage ();
-long FinishSetUpMessage ();
-long StartRequest ();
-long FinishRequest ();
+static long FinishSetUpMessage(FD fd, unsigned char *buf, long n);
+static long StartRequest(FD fd, unsigned char *buf, long n);
+static long FinishRequest(FD fd, unsigned char *buf, long n);
-long StartSetUpReply ();
-long FinishSetUpReply ();
-long ServerPacket ();
-long FinishReply ();
+static long FinishSetUpReply(FD fd, unsigned char *buf, long n);
+static long ServerPacket(FD fd, unsigned char *buf, long n);
+static long FinishReply(FD fd, unsigned char *buf, long n);
/* ************************************************************ */
@@ -251,6 +284,7 @@ long FinishReply ();
int littleEndian;
+void
ProcessBuffer(fd, buf, n)
FD fd;
unsigned char *buf;
@@ -411,6 +445,7 @@ FinishStuff (fd, buf, n)
}
}
+void
StartClientConnection(fd)
FD fd;
{
@@ -433,6 +468,7 @@ StartClientConnection(fd)
StartStuff (fd);
}
+void
StopClientConnection(fd)
FD fd;
{
@@ -448,8 +484,8 @@ long StartSetUpMessage (fd, buf, n)
unsigned char *buf;
long n;
{
- short namelength;
- short datalength;
+ unsigned short namelength;
+ unsigned short datalength;
enterprocedure("StartSetUpMessage");
/*
@@ -473,12 +509,17 @@ long StartSetUpMessage (fd, buf, n)
return(0);
}
-long FinishSetUpMessage (fd, buf, n)
+static long FinishSetUpMessage (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
{
enterprocedure("FinishSetUpMessage");
+ if( Raw || (Verbose > 3) )
+ DumpItem("Client Connect", fd, buf, n) ;
+ CS[fd].littleEndian = (buf[0] == 'l');
+ CS[ServerHalf(fd)].littleEndian = CS[fd].littleEndian;
+ littleEndian = CS[fd].littleEndian;
if (ScopeEnabled)
PrintSetUpMessage(buf);
@@ -498,6 +539,7 @@ long StartBigRequest (fd, buf, n)
/* bytes 0-3 are ignored now; bytes 4-8 tell us the request length */
CS[fd].requestLen = ILong(&buf[4]);
+
CS[fd].ByteProcessing = FinishRequest;
CS[fd].NumberofBytesNeeded = 4 * CS[fd].requestLen;
debug(8,(stderr, "need %d more bytes to finish request\n",
@@ -506,7 +548,7 @@ long StartBigRequest (fd, buf, n)
return(0);
}
-long StartRequest (fd, buf, n)
+static long StartRequest (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
@@ -534,7 +576,7 @@ long StartRequest (fd, buf, n)
}
-long FinishRequest (fd, buf, n)
+static long FinishRequest (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
@@ -553,6 +595,7 @@ long FinishRequest (fd, buf, n)
/* */
/* ************************************************************ */
+void
StartServerConnection(fd)
FD fd;
{
@@ -571,6 +614,7 @@ StartServerConnection(fd)
CS[fd].NumberofBytesNeeded = 8;
}
+void
StopServerConnection(fd)
FD fd;
{
@@ -581,12 +625,13 @@ StopServerConnection(fd)
Free((char *)CS[fd].SavedBytes);
}
-long StartSetUpReply (fd, buf, n)
+long
+StartSetUpReply (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
{
- short replylength;
+ unsigned short replylength;
enterprocedure("StartSetUpReply");
replylength = IShort(&buf[6]);
@@ -597,12 +642,15 @@ long StartSetUpReply (fd, buf, n)
return(0);
}
-long FinishSetUpReply (fd, buf, n)
+static long
+FinishSetUpReply (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
{
enterprocedure("FinishSetUpReply");
+ if( Raw || (Verbose > 3) )
+ DumpItem("Server Connect", fd, buf, n) ;
if (ScopeEnabled)
PrintSetUpReply(buf);
CS[fd].ByteProcessing = ServerPacket;
@@ -612,7 +660,8 @@ long FinishSetUpReply (fd, buf, n)
/* ************************************************************ */
-long ErrorPacket (fd, buf, n)
+static long
+ErrorPacket (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
@@ -624,7 +673,8 @@ long ErrorPacket (fd, buf, n)
}
-long EventPacket (fd, buf, n)
+static long
+EventPacket (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
@@ -637,7 +687,8 @@ long EventPacket (fd, buf, n)
}
-long ReplyPacket (fd, buf, n)
+static long
+ReplyPacket (fd, buf, n)
FD fd;
unsigned char *buf;
long n;
@@ -662,7 +713,8 @@ long ReplyPacket (fd, buf, n)
return(0);
}
-long ServerPacket (fd, buf, n)
+static long
+ServerPacket (fd, buf, n)
FD fd;
unsigned char *buf;
long n;