|
|
1.1 ! root 1: /* ! 2: * This file implements server functions for the XNS courier library ! 3: */ ! 4: ! 5: /* ! 6: $Log: server.c,v $ ! 7: * Revision 2.2 86/12/10 14:21:10 ed ! 8: * Reset _serverConnection->abortseen in ReceiveCallMessage ! 9: * ! 10: * Revision 2.1 86/11/11 09:33:42 jqj ! 11: * In ReceiveCallMessage, set state to inprogress so server BDT will work ! 12: * right. ! 13: * ! 14: * Revision 2.0 85/11/21 07:22:19 jqj ! 15: * 4.3BSD standard release ! 16: * ! 17: * Revision 1.3 85/03/11 16:37:39 jqj ! 18: * *** empty log message *** ! 19: * ! 20: * Revision 1.3 85/03/11 16:37:39 jqj ! 21: * Public alpha-test version, released 11 March 1985 ! 22: * ! 23: * Revision 1.2 85/01/27 07:37:43 jqj ! 24: * finished but undebugged version ! 25: * ! 26: * Revision 1.1 85/1/4 2:40:00 jqj ! 27: * Initial revision -- Mogul's tcp-based version ! 28: */ ! 29: #ifndef lint ! 30: static char rcsid[] = "$Header: server.c,v 2.2 86/12/10 14:21:10 ed Exp $"; ! 31: #endif ! 32: ! 33: #include <stdio.h> ! 34: #include <sys/time.h> ! 35: #include <sys/types.h> /* for ns.h */ ! 36: #include <sys/socket.h> ! 37: #include <netns/ns.h> /* for XNS addresses and courierconnectin.h */ ! 38: #include <netns/sp.h> /* for spphdr */ ! 39: #include "courier.h" ! 40: #include "realcourierconnection.h" ! 41: #include <except.h> ! 42: #include <ctype.h> ! 43: ! 44: #if DEBUG ! 45: int CourierServerDebuggingFlag = 0; ! 46: #endif ! 47: ! 48: /* ! 49: * Message stream handle. ! 50: */ ! 51: CourierConnection *_serverConnection = 0; ! 52: Unspecified tid; /* transaction ID */ ! 53: ! 54: ! 55: /* CALL, transaction id, prognumh, prognuml, version, procedurenum */ ! 56: #define CALLHDRLEN 6 ! 57: ! 58: ! 59: Unspecified * ! 60: ReceiveCallMessage(procp, skipcount, skippedwords) ! 61: Cardinal *procp; ! 62: int skipcount; ! 63: Unspecified *skippedwords; ! 64: { ! 65: Cardinal msgtype, version; ! 66: LongCardinal programnumber; ! 67: Unspecified *buf, *bp, hdrbuf[CALLHDRLEN]; ! 68: int i; ! 69: ! 70: if (skipcount > 1 && _serverConnection->state == wantversion) { ! 71: skipcount -= 2; ! 72: _serverConnection->state = inprogress; /* per Ed Flint */ ! 73: skippedwords += 2; ! 74: } ! 75: ! 76: if (skipcount > CALLHDRLEN) { ! 77: fprintf(stderr,"ReceiveCallMessage: skipcount=%d, too big\n", ! 78: skipcount); ! 79: exit(1); ! 80: } ! 81: ! 82: _serverConnection->abortseen= FALSE; /* reset */ ! 83: ! 84: for (i=0; i < skipcount; i++) ! 85: hdrbuf[i] = skippedwords[i]; ! 86: buf = ReadMessage(_serverConnection, hdrbuf+skipcount, ! 87: CALLHDRLEN-skipcount); ! 88: bp = hdrbuf; ! 89: bp += internalize_Cardinal(&msgtype, bp); ! 90: bp += internalize_Unspecified(&tid, bp); ! 91: bp += internalize_LongCardinal(&programnumber, bp); ! 92: bp += internalize_Cardinal(&version, bp); ! 93: bp += internalize_Cardinal(procp, bp); ! 94: #if DEBUG ! 95: if (CourierServerDebuggingFlag) ! 96: fprintf(stderr, "[ReceiveCallMessage %D %d %d]\n", ! 97: programnumber, version, *procp); ! 98: #endif ! 99: return(buf); ! 100: } ! 101: ! 102: ! 103: SendReturnMessage(nwords, results) ! 104: Cardinal nwords; ! 105: Unspecified *results; ! 106: { ! 107: #define RETHDRLEN 2 ! 108: Unspecified *bp, buf[RETHDRLEN]; ! 109: static Cardinal msgtype = RETURN; ! 110: ! 111: #if DEBUG ! 112: if (CourierServerDebuggingFlag) ! 113: fprintf(stderr, "[SendReturnMessage %d]\n", nwords); ! 114: #endif ! 115: bp = buf; ! 116: bp += externalize_Cardinal(&msgtype, bp); ! 117: bp += externalize_Unspecified(&tid, bp); ! 118: CourierWrite(_serverConnection, (bp-buf), buf, nwords, results); ! 119: _serverConnection->bdtstate = wantdata; ! 120: } ! 121: ! 122: ! 123: static int ! 124: ServerInit(argc, argv, skippedwords) ! 125: int argc; ! 126: char *argv[]; ! 127: Unspecified skippedwords[]; ! 128: { ! 129: extern char *malloc(); ! 130: int skipcount; ! 131: #if DEBUG ! 132: int namelen; ! 133: #endif ! 134: int i; ! 135: ! 136: _serverConnection = (CourierConnection *) ! 137: malloc(sizeof(CourierConnection)); ! 138: _serverConnection->bdtstate = wantdata; ! 139: /* we normally don't bother to set up host, since the server will ! 140: * never reopen a closed connection ! 141: */ ! 142: #if DEBUG ! 143: namelen = sizeof(struct sockaddr_ns); ! 144: getpeername(_serverConnection->fd, &_serverConnection->host, &namelen); ! 145: fprintf(stderr,"[ServerInit: argc=%d]\n",argc); ! 146: for (i=0; i<argc; i++) fprintf(stderr,"\targv[%d]=%s\n", i,argv[i]); ! 147: ! 148: #endif ! 149: skipcount = -1; ! 150: while (argc-- > 0) { ! 151: #if DEBUG ! 152: if (strcmp(argv[0],"-d") == 0) ! 153: CourierServerDebuggingFlag = 1; ! 154: else ! 155: #endif ! 156: if (isdigit(*argv[0])) { ! 157: if (skipcount < 0) { ! 158: _serverConnection->fd = atoi(argv[0]); ! 159: skipcount++; ! 160: } ! 161: else if (skipcount < 8) ! 162: skippedwords[skipcount++] = atoi(argv[0]); ! 163: } ! 164: argv++; ! 165: } ! 166: if (skipcount < 0 || skipcount == 1) { ! 167: fprintf(stderr,"in ServerInit, skipcount=%d\n",skipcount); ! 168: exit(1); ! 169: } ! 170: _serverConnection->state = wantversion; ! 171: return(skipcount); ! 172: } ! 173: ! 174: ! 175: main(argc, argv) ! 176: int argc; ! 177: char *argv[]; ! 178: { ! 179: /* ! 180: * The caller may need to read a packet before getting to the ! 181: * program/version which it needs for dispatching. Data so read ! 182: * is passed in the argv list, and used to set skipcount and ! 183: * skippedwords. ! 184: */ ! 185: int skipcount; /* actual length of skippedwords */ ! 186: Unspecified skippedwords[8]; ! 187: ! 188: /* ServerInit() contains server-independent startup code */ ! 189: skipcount = ServerInit(argc, argv, skippedwords); ! 190: ! 191: /* Server() may terminate in 2 ways: ! 192: * (1) normally, with a return(0) and a closed connection, ! 193: * either from our timeout or from END sent by client. ! 194: * (2) abnormally, with an exit(1) indicating a protocol ! 195: * violation. We do not currently close down the ! 196: * connection in all such cases, but we should. ! 197: * Note that Server may also exec() a different server if ! 198: * a remote procedure for a different program arrives. ! 199: */ ! 200: Server(skipcount, skippedwords); ! 201: exit(0); ! 202: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.