server/be.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: be.cxx,v $
00032  * Revision 1.16  2004/09/11 15:02:00  jrush
00033  * Fixed Doxygen tags on all Session parameter arguments.
00034  *
00035  * Revision 1.15  2004/09/11 13:59:21  jrush
00036  * Changed all fprintf's to stderr to use the Nana library L() macro.  Also
00037  * removed a 2-3 minor compiler warnings.
00038  *
00039  * Revision 1.14  2004/09/04 16:02:18  jrush
00040  * Added Doxygen headers before each and every function definition.
00041  *
00042  * Revision 1.13  2004/08/28 13:35:26  jrush
00043  * Catching up CVS to various incomplete versions on local disk.
00044  *
00045  * Revision 1.12  2002/07/26 04:33:47  jrush
00046  * Replaced gerror() with assert()
00047  *
00048  * Revision 1.11  2002/05/28 03:58:42  jrush
00049  * Sources modified to comply with GPL licensing.
00050  *
00051  * Revision 1.10  2002/04/12 11:48:50  jrush
00052  * Major reorganization of includes into a single base-include style.
00053  *
00054  * Revision 1.9  2002/04/09 21:45:46  jrush
00055  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00056  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00057  * up the type/class tree.
00058  *
00059  * Revision 1.8  2002/04/07 14:04:37  jrush
00060  * Add ptr to Session to checkforopen() and isthisusersdocument() so that we
00061  * have session information available to make the decision.
00062  *
00063  * Revision 1.7  2002/04/06 19:51:30  jrush
00064  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00065  *
00066  * Revision 1.6  2002/04/06 17:05:57  jrush
00067  * Switched from referring to 'task' for a client connection to 'session',
00068  * and converted the typetask typedef/struct into a Session C++ class.
00069  *
00070  * Revision 1.5  2002/04/06 15:01:44  jrush
00071  * Changed INT to just 'int'.
00072  *
00073  * Revision 1.4  2002/02/14 10:08:25  jrush
00074  * Cleaned up source:
00075  *
00076  * 1. ran thru the indent tool to achieve a standard look,
00077  * 2. added structured comments at top for use with DOxygen reporting
00078  *    as well as CVS keywords,
00079  * 3. centralized prototypes in protos.h, removing incomplete ones,
00080  * 4. cleaned up use of bool/BOOLEAN type to suit C++ type,
00081  * 5. fixed initializer nesting in tumbler constants,
00082  * 6. converted select() int bits into ANSI fd_set type,
00083  * 7. added Makefile.am for use by automake.
00084  *
00085  */
00086 
00087 #include <stdlib.h>
00088 #include <time.h>
00089 #include "udanax.h"
00090 #include "players.h"
00091 
00092 #define MAX_PLAYERS 5
00093 int user = 0;
00094 PLAYER player[MAX_PLAYERS];
00095 extern int errno;
00096 
00097 FILE *logfile;
00098 FILE *nulllog;
00099 FILE *reallog;
00100 char outputbuffer[BUFSIZ];
00101 char inputbuffer[BUFSIZ];
00102 bool logstuff;
00103 FILE *interfaceinput;
00104 extern FILE *febelog;
00105 extern bool firstputforrequest;
00106 Session *sessx;    
00107 int backenddaemon;       /* backend version */
00108 Tumbler defaultaccount = { 0, 0, 0, 0, { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 } };        /* 1.1.0.1 */
00109 
00110 extern bool getrequest(Session *sess, typerequest *requestptr);
00111 extern void sendresultoutput(Session * session);
00112 extern char pullc(Session *sess);
00113 extern void xuputstring(char *string, FILE * fd);
00114 extern void processrcfile();
00115 
00123     void
00124 xanadu(
00125     Session *sess)    
00126 {
00127     typerequest request;
00128 
00129     if (febelog && febelog != nulllog)
00130         fprintf(febelog, "\nfe:\n");
00131     firstputforrequest = true;
00132     logstuff = false;
00133     if (getrequest(sess, &request)) {
00134         (*requestfns[request]) (sess);
00135         sendresultoutput(sess);
00136     } else {
00137         sess->inp = stdin;
00138     }
00139     sess->free();
00140 /* lookatalloc(); */
00141     if (interfaceinput && interfaceinput != nulllog)
00142         fflush(interfaceinput);
00143     logstuff = false;
00144 }
00145 
00153     bool
00154 establishprotocol(
00155     FILE *inp,
00156     FILE *outp)
00157 {
00158     char ch;
00159     Session tempsess;    
00160 
00161     if (febelog && febelog != nulllog)
00162         fprintf(febelog, "fe:\n");
00163     firstputforrequest = true;
00164 
00165 /* This is the metaprotocol for the time being */
00166 
00167     tempsess.inp = inp;
00168     tempsess.outp = outp;
00169     tempsess.errp = stderr;
00170 
00171     while ((ch = pullc(&tempsess)) != '\n') ;
00172     while ((ch = pullc(&tempsess)) == '\n') ;
00173     if (ch == 'P' && pullc(&tempsess) == '0' && pullc(&tempsess) == '~') {
00174         xuputstring("\nP0~", tempsess.outp);
00175         sendresultoutput(&tempsess);
00176         return true;
00177     } else {
00178         xuputstring("\nP?~", tempsess.outp);
00179         sendresultoutput(&tempsess);
00180         return false;
00181     }
00182 }
00183 
00191     int
00192 main(
00193     int   argc,
00194     char *argv[])
00195 {
00196     Session sess;    
00197     char buf[100];
00198     //UNUSED FILE *fd;
00199     struct tm *local;
00200     long clock;
00201 
00202     sessx = &sess;
00203     febelog = interfaceinput = reallog = logfile = nulllog = fopen("/dev/null", "a");
00204 
00205     clock = time(0);
00206     local = localtime(&clock);
00207     sprintf(buf, "ln%d.%d.%d:%d", local->tm_mon + 1, local->tm_mday, local->tm_hour, local->tm_min);
00208 /* 
00209  * #ifndef DISTRIBUTION
00210  * sprintf(buf,"febe%d.%d.%d:%d",local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min);
00211  * febelog = fopen(buf, "w"); #endif */
00212 
00213     freopen("backenderror", "w", stderr);       /* CHANGE THIS ?? */
00214     setbuf(stderr, NULL);
00215     processrcfile();
00216 
00217     setbuf(stdin, inputbuffer);
00218     setbuf(stdout, outputbuffer);
00219 
00220     if (!establishprotocol(stdin, stdout))
00221         exit(1);
00222 
00223     debug = false;
00224 
00225     init(1);
00226     //now uses a ctor:: inittask(&sess);
00227 
00228     initsession("enf.enf");
00229 
00230     movetumbler(&defaultaccount, &sess.account);
00231 
00232     for (;;) {
00233         nsessorcommand++;
00234         xanadu(&sess);
00235 /* testforreservedness ("main"); */
00236         logfile = nulllog;
00237     }
00238 /* lookatalloc(); */
00239     return 0;
00240 }
00241 
00249     void
00250 frontenddied()
00251 {
00252     L("The frontend apparently has died.\n");
00253     diskexit();
00254     assert(0); // The frontend died
00255 }
00256 
00264 /* for linker until we get this cleaned up */
00265     void
00266 setmaximumsetupsize(
00267     Session *sess)    
00268 {
00269 }
00270 
00278     void
00279 sourceunixcommand(
00280     Session *sess)    
00281 {
00282 }
00283 
00291     bool
00292 decrementusers()
00293 {
00294     return false;
00295 }
00296 
00304     bool
00305 isthisusersdocument(
00306     Session *sess,    
00307     Tumbler *tp)
00308 {
00309     return tumbleraccounteq(tp, &sess->account);
00310 }

Generated on Sun Aug 21 04:18:15 2005 for Udanax-Green by doxygen1.3.4