server/xumain.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: xumain.cxx,v $
00032  * Revision 1.19  2004/09/11 15:02:00  jrush
00033  * Fixed Doxygen tags on all Session parameter arguments.
00034  *
00035  * Revision 1.18  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.17  2004/09/11 12:14:49  jrush
00040  * Broke tie on global variable defined in both the server and the library.
00041  *
00042  * Revision 1.16  2004/09/04 16:02:18  jrush
00043  * Added Doxygen headers before each and every function definition.
00044  *
00045  * Revision 1.15  2004/08/28 13:35:26  jrush
00046  * Catching up CVS to various incomplete versions on local disk.
00047  *
00048  * Revision 1.14  2002/07/26 04:33:47  jrush
00049  * Replaced gerror() with assert()
00050  *
00051  * Revision 1.13  2002/05/28 03:58:42  jrush
00052  * Sources modified to comply with GPL licensing.
00053  *
00054  * Revision 1.12  2002/04/12 11:48:51  jrush
00055  * Major reorganization of includes into a single base-include style.
00056  *
00057  * Revision 1.11  2002/04/10 18:01:54  jrush
00058  * Renamed class typeisa to IStreamAddr.
00059  *
00060  * Revision 1.10  2002/04/09 21:45:47  jrush
00061  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00062  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00063  * up the type/class tree.
00064  *
00065  * Revision 1.9  2002/04/07 14:04:37  jrush
00066  * Add ptr to Session to checkforopen() and isthisusersdocument() so that we
00067  * have session information available to make the decision.
00068  *
00069  * Revision 1.8  2002/04/06 20:42:50  jrush
00070  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00071  *
00072  * Revision 1.7  2002/04/06 19:51:30  jrush
00073  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00074  *
00075  * Revision 1.6  2002/04/06 17:05:57  jrush
00076  * Switched from referring to 'task' for a client connection to 'session',
00077  * and converted the typetask typedef/struct into a Session C++ class.
00078  *
00079  * Revision 1.5  2002/04/06 15:01:45  jrush
00080  * Changed INT to just 'int'.
00081  *
00082  * Revision 1.4  2002/02/14 10:08:26  jrush
00083  * Cleaned up source:
00084  *
00085  * 1. ran thru the indent tool to achieve a standard look,
00086  * 2. added structured comments at top for use with DOxygen reporting
00087  *    as well as CVS keywords,
00088  * 3. centralized prototypes in protos.h, removing incomplete ones,
00089  * 4. cleaned up use of bool/BOOLEAN type to suit C++ type,
00090  * 5. fixed initializer nesting in tumbler constants,
00091  * 6. converted select() int bits into ANSI fd_set type,
00092  * 7. added Makefile.am for use by automake.
00093  *
00094  */
00095 
00096 #include <errno.h>
00097 #include <unistd.h>
00098 #include <stdlib.h>
00099 #include <string.h>
00100 #include "udanax.h"
00101 #include "players.h"
00102 
00103 #define MAX_PLAYERS 5
00104 int user = 0;
00105 PLAYER player[MAX_PLAYERS];
00106 
00107 extern int errno;
00108 FILE *febelog = NULL;
00109 extern bool isxumain;
00110 bool maximumsetupsizehasbeenhit;
00111 extern int maximumsetupsize;
00112 bool logstuff;
00113 Session *sessx;    
00114 FILE *interfaceinput = NULL;
00115 int backenddaemon;       /* backend version */
00116 
00117 extern bool  getrequest(Session * sess, typerequest * requestptr);
00118 extern void  processrcfile();
00119 extern void  prompt(Session * sess, char *string);
00120 extern void  putcreatenewdocument(Session * sess, IStreamAddr * newdocisaptr);
00121 
00129 /* "xanadu" is the backend request dispatcher */
00130     void
00131 xanadu(
00132     Session *sess)    
00133 {
00134     typerequest request;
00135 
00136     logstuff = false;
00137     if (getrequest(sess, &request))
00138         (*requestfns[request]) (sess);
00139 /* 
00140  * else sess->inp = stdin; */
00141     logstuff = false;
00142     sess->free();
00143 }
00144 
00152     int
00153 main(
00154     int   argc,
00155     char *argv[])
00156 {                                      /* inside temporary */
00157     Session sess;    
00158     //UNUSED FILE *fd;
00159     //UNUSED int i = 0;
00160 
00161     isxumain = true;
00162 
00163     setbuf(stderr, NULL);
00164     debug = false;
00165     processrcfile();
00166     init(0);
00167     //now uses a ctor:: inittask(&sess);
00168 /* 
00169  * if (fd = fopen ("xusetup", "r")) sess.inp = fd; errno = 0; */
00170     initsession("enf.enf");
00171     sessx = &sess;
00172     sess.getaccount(&sess.account);
00173     for (;;) {
00174         nsessorcommand++;
00175 /* 
00176  * L("%d ",i++); */
00177         xanadu(&sess);
00178         testforreservedness("main");
00179 /* if (maximumsetupsizehasbeenhit) { L("Setup has reached size limit.\n"); diskexit (); } */
00180     }
00181     return 0;
00182 }
00183 
00191     bool
00192 setmaximumsetupsize(
00193     Session *sess)    
00194 {
00195     char buff[100];
00196 
00197     fprintf(sess->outp, "maximumsetupsize = ? ");
00198     maximumsetupsize = atoi(fgets(buff, 100, sess->inp));
00199     return true;
00200 }
00201 
00209     bool
00210 getmuchtext(
00211     Session  *sess,    
00212     typetext *textptr)
00213 {                                      /* 
00214                                         * * this code stolen from get2.d which could * use some improvement but be
00215                                         * careful */
00216     int numinstring = 0;
00217     int temp;
00218 
00219     numinstring = temp = 0;
00220     for (;;) {
00221         if (!fgets(textptr->string + numinstring, GRANTEXTLENGTH - numinstring, sess->inp)) {
00222             temp = 0;
00223             break;
00224         }
00225         temp = strlen(textptr->string + numinstring);
00226         if (temp < 1) {
00227             break;
00228         }
00229         numinstring += temp;
00230         if (numinstring >= GRANTEXTLENGTH) {
00231             break;
00232         }
00233     }
00234 
00235     if (numinstring > GRANTEXTLENGTH)
00236         assert(0); // got too much in getmuchtext
00237 
00238     if (numinstring == 0) {
00239         textptr->length = 0;
00240         return false;
00241     }
00242 
00243     textptr->length = numinstring;
00244     textptr->itemid = TEXTID;
00245     return true;
00246 }
00247 
00255     void
00256 sourceunixcommand(
00257     Session *sess)    
00258 {
00259     char unixcommand[132];
00260     char file[64];
00261     IStreamAddr docisa;
00262     typetext *textsetptr;
00263 
00264     FILE *infile;
00265     int count, lines, bugger;
00266     int status;
00267 
00268     count = 0;
00269     lines = 0;
00270     bugger = debug;
00271 
00272     sprintf(file, "xum%d", getpid());
00273     prompt(sess, " Enter unix command : ");
00274     fgets(unixcommand, 132, sess->inp);
00275 
00276     if (unixcommand[strlen(unixcommand) - 1] == '\n')
00277         unixcommand[strlen(unixcommand) - 1] = '\0';
00278 
00279     strcat(unixcommand, " >");
00280     strcat(unixcommand, file);
00281 
00282     if ((status = system(unixcommand)) != 0) {
00283         L("Exit status = %d\n", status);
00284         perror("Udanax(system call 0)");
00285 // return false;
00286     }
00287     if (debug) {
00288         prompt(sess, "lines until debug : ");
00289         count = atoi(fgets(unixcommand, 132, sess->inp));
00290         if (count)
00291             debug = 0;
00292     }
00293 
00294     docreatenewdocument(sess, &docisa);
00295 /* testforreservedness ("eatunixcommand createdoc"); */
00296     putcreatenewdocument(sess, &docisa);
00297 
00298     infile = sess->inp;
00299     if (!(sess->inp = fopen(file, "r"))) {
00300         perror("xanadu");
00301         L("Couldn't open %s\n", file);
00302         assert(0); // Awful badness in sourceunixfile
00303     }
00304     while ((textsetptr = new(sess) typetext) != NULL
00305 //    while ((textsetptr = (typetext *) sess->alloc(sizeof(typetext)))
00306            && (getmuchtext(sess, textsetptr) || (textsetptr->length > 0))) {
00307         if (debug)
00308             L("line # %d\n", lines);
00309         textsetptr->next = NULL;
00310         textsetptr->itemid = TEXTID;
00311         textsetptr->length = strlen(textsetptr->string);
00312         doappend(sess, &docisa, textsetptr);
00313 /* testforreservedness ("eatunixcommand loop"); */
00314         ++lines;
00315         sess->free();
00316         if (count && --count == 0)
00317             debug = bugger;
00318     }
00319     fclose(sess->inp);
00320     unlink(file);
00321     sess->inp = infile;
00322 
00323     //NOBODY CARES  return true;
00324 }
00325 
00333     bool
00334 decrementusers()
00335 {
00336     return (false);
00337 }
00338 
00346     bool
00347 isthisusersdocument(
00348     Session *sess,    
00349     Tumbler *tp)
00350 {
00351     return tumbleraccounteq(tp, &sess->account);
00352 }

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