server/get2fe.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: get2fe.cxx,v $
00032  * Revision 1.17  2004/09/11 15:02:00  jrush
00033  * Fixed Doxygen tags on all Session parameter arguments.
00034  *
00035  * Revision 1.16  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.15  2004/09/04 16:02:18  jrush
00040  * Added Doxygen headers before each and every function definition.
00041  *
00042  * Revision 1.14  2002/07/26 04:33:47  jrush
00043  * Replaced gerror() with assert()
00044  *
00045  * Revision 1.13  2002/05/28 03:58:42  jrush
00046  * Sources modified to comply with GPL licensing.
00047  *
00048  * Revision 1.12  2002/04/16 22:39:50  jrush
00049  * Converted many #defines into enumeration types instead, and adjusted
00050  * function prototypes accordingly.
00051  *
00052  * Revision 1.11  2002/04/12 11:48:50  jrush
00053  * Major reorganization of includes into a single base-include style.
00054  *
00055  * Revision 1.10  2002/04/10 18:01:54  jrush
00056  * Renamed class typeisa to IStreamAddr.
00057  *
00058  * Revision 1.9  2002/04/09 21:45:47  jrush
00059  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00060  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00061  * up the type/class tree.
00062  *
00063  * Revision 1.8  2002/04/06 20:42:50  jrush
00064  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00065  *
00066  * Revision 1.7  2002/04/06 19:51:30  jrush
00067  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00068  *
00069  * Revision 1.6  2002/04/06 17:05:57  jrush
00070  * Switched from referring to 'task' for a client connection to 'session',
00071  * and converted the typetask typedef/struct into a Session C++ class.
00072  *
00073  * Revision 1.5  2002/04/06 15:01:45  jrush
00074  * Changed INT to just 'int'.
00075  *
00076  * Revision 1.4  2002/02/14 10:08:25  jrush
00077  * Cleaned up source:
00078  *
00079  * 1. ran thru the indent tool to achieve a standard look,
00080  * 2. added structured comments at top for use with DOxygen reporting
00081  *    as well as CVS keywords,
00082  * 3. centralized prototypes in protos.h, removing incomplete ones,
00083  * 4. cleaned up use of bool/BOOLEAN type to suit C++ type,
00084  * 5. fixed initializer nesting in tumbler constants,
00085  * 6. converted select() int bits into ANSI fd_set type,
00086  * 7. added Makefile.am for use by automake.
00087  *
00088  */
00089 
00090 #include <ctype.h>
00091 #include "udanax.h"
00092 #include "players.h"
00093 
00094 #define WORDELIM '~'
00095 #define TUMDELIM '.'
00096 #define SPANFLAG 's'
00097 #define VSPECFLAG 'v'
00098 #define TEXTFLAG 't'
00099 
00100 extern FILE *logfile;
00101 extern FILE *nulllog;
00102 extern FILE *reallog;
00103 
00104 extern bool logstuff;
00105 extern FILE *interfaceinput;
00106 extern FILE *febelog;
00107 
00108 bool  getnum(Session * sess, int * numptr);
00109 bool  gettdigit(Session * sess, int * valueptr);
00110 bool  getspan(Session * sess, typespan * spanptr, typeitemid id);
00111 bool  getvspec(Session * sess, typevspec * vspecptr);
00112 bool  getspanset(Session * sess, typespanset * spansetptr, typeitemid id);
00113 bool  gettext(Session * sess, typetext * textptr);
00114 bool  validrequest(Session * sess, typerequest request);
00115 void  error(Session * sess, char *string);
00116 void  frontenddied();
00117 
00125     void
00126 pushc(
00127     Session *sess,    
00128     char     c)
00129 {
00130     if (sess->charinbuff)
00131         error(sess, "charbuff occupied\n");
00132     else {
00133         sess->charinbuff = true;
00134         sess->charbuff = c;
00135     }
00136 }
00137 
00145     char
00146 pullc(
00147     Session *sess)    
00148 {
00149     int temp;
00150 
00151     if (sess->charinbuff) {
00152         sess->charinbuff = false;
00153         return sess->charbuff;
00154 
00155     } else {
00156         temp = getc(sess->inp);
00157         if (temp == EOF) {
00158             L("EOF on user %d in pullc\n", user);
00159             frontenddied();            /* does longjmp in backenddaemon, exit in backend */
00160 
00161             /* L("Premature end-of-file in backend\n"); diskexit (); // try to avoid screwing enf.enf //
00162  * assert(0); "pullc" */
00163         }
00164 
00165         temp &= 0x7f;
00166         if (logstuff && interfaceinput && interfaceinput != nulllog) {
00167             if (temp == WORDELIM)
00168                 putc('\n', interfaceinput);
00169             else
00170                 putc(temp, interfaceinput);
00171         }
00172 
00173         if (febelog && febelog != nulllog)
00174             putc(temp, febelog);
00175         return temp;
00176     }
00177 }
00178 
00186     bool
00187 gettumbler(
00188     Session *sess,    
00189     Tumbler *tumblerptr)
00190 {
00191     char c;
00192     int i, num, value;
00193 
00194 /* fprintf(sess->errp,"X gettumbler\n"); */
00195     tumblerclear(tumblerptr);
00196     getnum(sess, &num);
00197     tumblerptr->exp = -num;
00198 
00199     for (i = 0; gettdigit(sess, &value); i++) {
00200         if (i > NPLACES) {
00201             error(sess, "gettumbler overflow\n");
00202             return false;
00203         }
00204         tumblerptr->mantissa[i] = value;
00205     }
00206 /* fprintf (logfile, " "); puttumbler (logfile, tumblerptr); */
00207     return (c = pullc(sess)) == WORDELIM || c == '\n';
00208 }
00209 
00217     bool
00218 gettdigit(
00219     Session *sess,    
00220     int     *valueptr)
00221 {
00222     char c;
00223     if ((c = pullc(sess)) != TUMDELIM) {
00224         pushc(sess, c);
00225         return (false);
00226     }
00227     return getnum(sess, valueptr);
00228 }
00229 
00237     bool
00238 getnum(
00239     Session *sess,    
00240     int     *numptr)
00241 {
00242 /* fprintf(sess->errp,"X getnum\n"); */
00243     int num = 0;
00244     bool flag = false;
00245 
00246     char c;
00247     while ((c = pullc(sess)) /* && putc (c,sess->errp) */ &&isdigit(c)) {
00248         num = num * 10 + c - '0';
00249         flag = true;
00250     }
00251 
00252 /* fprintf(sess->errp,"\n"); */
00253     pushc(sess, c);
00254     *numptr = num;
00255     return flag;
00256 }
00257 
00265     bool
00266 getnumber(
00267     Session *sess,    
00268     int     *numptr)
00269 {
00270     int num = 0;
00271     bool flag = false;
00272 
00273     char c;
00274     while ((c = pullc(sess)) && isdigit(c)) {
00275         num = num * 10 + c - '0';
00276         flag = true;
00277     }
00278     *numptr = num;
00279 /* fprintf (logfile, " %d", *numptr); */
00280     return flag && (c == WORDELIM || c == '\n');
00281 }
00282 
00290     bool
00291 eatchar(
00292     Session *sess,    
00293     char     c)
00294 {
00295     metachar m;
00296 
00297     if ((m = pullc(sess)) != c) {
00298         pushc(sess, m);
00299         return false;
00300     } else
00301         return true;
00302 }
00303 
00311     bool
00312 getspecset(
00313     Session     *sess,    
00314     typespecset *specsetptr)
00315 {
00316     int num;
00317     char c, c1;
00318     typespecset specset;
00319 
00320     *specsetptr = NULL;
00321     if (!getnumber(sess, &num))
00322         return false;
00323 
00324     if (num == 0)
00325         return true;
00326 
00327     while (num--) {
00328         c = pullc(sess);
00329         if ((c != SPANFLAG) && (c != VSPECFLAG))
00330             return false;
00331 
00332 /* mightn't work */ if ((c1 = pullc(sess)) != WORDELIM && c1 != '\n')
00333             return false;
00334 
00335         if (c == SPANFLAG) {
00336             specset = (typespecset) new(sess) typespan;
00337 //            specset = (typespecset) sess->alloc(sizeof(typespan));
00338             if (!getspan(sess, (typespan *) specset, ISPANID))
00339                 return false;
00340         } else {
00341             specset = (typespecset) new(sess) typevspec;
00342 //            specset = (typespecset) sess->alloc(sizeof(typevspec));
00343             if (!getvspec(sess, (typevspec *) specset))
00344                 return false;
00345         }
00346 
00347         *specsetptr = specset;
00348         specsetptr = (typespecset *) & ((typeitemheader *) specset)->next;
00349     }
00350     return true;
00351 }
00352 
00360     bool
00361 getvspec(
00362     Session   *sess,    
00363     typevspec *vspecptr)
00364 {
00365 /* fprintf (logfile, " vspec"); fprintf (sess->errp, "X getvspec\n"); */
00366     vspecptr->itemid = VSPECID;
00367     vspecptr->next   = NULL;
00368     return gettumbler(sess, &vspecptr->docisa) && getspanset(sess, &vspecptr->vspanset, VSPANID);
00369 }
00370 
00378     bool
00379 getspanset(
00380     Session     *sess,    
00381     typespanset *spansetptr,
00382     typeitemid   id)
00383 {
00384     typespanset spanset;
00385     int num;
00386 
00387 /* fprintf (logfile, " spanset"); fprintf (sess->errp, "X getspanset\n"); */
00388     *spansetptr = NULL;
00389     if (!getnumber(sess, &num))
00390         return false;
00391 
00392 /* fprintf (sess->errp, "X nspans %d\n", num); fprintf (logfile, " {"); */
00393     while (num--) {
00394         spanset = (typespanset) new(sess) typespan;
00395 //        spanset = (typespanset) sess->alloc(sizeof(typespan));
00396         if (!getspan(sess, spanset, id))
00397             return (false);
00398         *spansetptr = spanset;
00399         spansetptr = &spanset->next;
00400     }
00401 /* fprintf (logfile, " }"); */
00402     return true;
00403 }
00404 
00412     bool
00413 getspan(
00414     Session    *sess,    
00415     typespan   *spanptr,
00416     typeitemid  id)
00417 {
00418 /* fprintf (logfile, " span"); fprintf (sess->errp, "X getspan\n"); */
00419     spanptr->itemid = id;
00420     spanptr->next = NULL;
00421     return gettumbler(sess, &spanptr->stream) && gettumbler(sess, &spanptr->width);
00422 }
00423 
00431     bool
00432 getcutseq(
00433     Session    *sess,    
00434     typecutseq *cutseqptr)
00435 {
00436     int ncuts, i;
00437 
00438 /* fprintf (logfile, " cutseq"); */
00439     if (!(getnumber(sess, &ncuts) && (ncuts == 3 || ncuts == 4)))
00440         return false;
00441 
00442 /* fprintf (logfile, " {"); */
00443     cutseqptr->numberofcuts = ncuts;
00444 
00445     for (i = 0; i < ncuts; ++i) {
00446         if (!gettumbler(sess, &cutseqptr->cutsarray[i]))
00447             return false;
00448     }
00449 /* fprintf (logfile, " }"); */
00450     return true;
00451 }
00452 
00460     bool
00461 gettextset(
00462     Session     *sess,    
00463     typetextset *textsetptr)
00464 {
00465     typetextset textset;
00466     int num;
00467 
00468 /* fprintf (logfile, " textset"); fprintf (sess->errp, "X gettextset\n"); */
00469     *textsetptr = NULL;
00470     if (!getnumber(sess, &num))
00471         return false;
00472 
00473 /* fprintf (sess->errp, "X number of texts is %d\n", num); fprintf (logfile, " {"); */
00474     while (num--) {
00475         textset = (typetextset) new(sess) typetext;
00476 //        textset = (typetextset) sess->alloc(sizeof(typetext));
00477         if (!gettext(sess, textset))
00478             return false;
00479 
00480         *textsetptr = textset;
00481         textsetptr = &textset->next;
00482     }
00483 /* fprintf (logfile, " }"); */
00484     return true;
00485 }
00486 
00494     bool
00495 gettext(
00496     Session  *sess,    
00497     typetext *textptr)
00498 {
00499     int i;
00500 
00501 /* fprintf (sess->errp, "X gettext\n"); */
00502     if (!(eatchar(sess, TEXTFLAG)
00503           && getnumber(sess, &textptr->length))) {
00504         fprintf(sess->errp, "\33[55;1fBackend receiving nothing in insert request.\n");
00505         return false;
00506     }
00507     textptr->itemid = TEXTID;
00508     textptr->next = NULL;
00509 
00510 /* fprintf (logfile, " \""); */
00511     for (i = 0; i < textptr->length; ++i) {
00512         textptr->string[i] = pullc(sess);
00513 /* fprintf (logfile, "%c", textptr->string[i]); */
00514     }
00515 
00516 /* 
00517  * if (i != -1 && i != 0) { write (fileno(sess->errp), textptr->string,
00518  * textptr->length); fprintf(sess->errp, "FINIS\n"); } else fprintf
00519  * (sess->errp, "read failed\n"); */
00520 /* if (! (eatchar (sess, WORDELIM) || eatchar (sess, '\n'))) return (false); REDUNDANT */
00521 /* fprintf (logfile, "\""); */
00522     return i != -1 && i != 0;
00523 }
00524 
00532     bool
00533 getrequest(
00534     Session     *sess,    
00535     typerequest *requestptr)
00536 {
00537     char c;
00538     int num;
00539     bool flag;
00540 
00541 /* fprintf (logfile, "\nrequest "); */
00542     sess->charinbuff = false;
00543 /* 
00544  * return ( getnumber (sess, requestptr) && validrequest (sess,
00545  * *requestptr)); */
00546     num = 0;
00547     flag = false;
00548     while ((c = pullc(sess)) != 0) {
00549         fprintf(logfile, "%c", c);
00550         if (!isdigit(c))
00551             break;
00552         num = num * 10 + c - '0';
00553         flag = true;
00554     }
00555     *requestptr = num;
00556     return flag && (c == WORDELIM || c == '\n') && validrequest(sess, *requestptr);
00557 }
00558 
00566     bool
00567 validrequest(
00568     Session     *sess,    
00569     typerequest  request)
00570 {
00571     if (request >= 0 && request < NREQUESTS && requestfns[request] != NULL)
00572         return true;
00573     else {
00574         fprintf(sess->errp, "invalid request: %d\n", request);
00575         return false;
00576     }
00577 }
00578 
00586     bool
00587 validaccount(
00588     Session     *sess,    
00589     IStreamAddr *accountptr)
00590 {
00591     return true;
00592 }

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