server/fns.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: fns.cxx,v $
00032  * Revision 1.15  2004/09/11 15:02:00  jrush
00033  * Fixed Doxygen tags on all Session parameter arguments.
00034  *
00035  * Revision 1.14  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.13  2004/09/04 16:02:18  jrush
00040  * Added Doxygen headers before each and every function definition.
00041  *
00042  * Revision 1.12  2004/08/28 13:35:26  jrush
00043  * Catching up CVS to various incomplete versions on local disk.
00044  *
00045  * Revision 1.11  2002/05/28 03:58:42  jrush
00046  * Sources modified to comply with GPL licensing.
00047  *
00048  * Revision 1.10  2002/04/13 14:08:35  jrush
00049  * Changed typedef of structs into just structs, for C++ style.
00050  *
00051  * Revision 1.9  2002/04/12 11:48:50  jrush
00052  * Major reorganization of includes into a single base-include style.
00053  *
00054  * Revision 1.8  2002/04/10 18:01:54  jrush
00055  * Renamed class typeisa to IStreamAddr.
00056  *
00057  * Revision 1.7  2002/04/09 21:45:46  jrush
00058  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00059  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00060  * up the type/class tree.
00061  *
00062  * Revision 1.6  2002/04/08 18:55:56  jrush
00063  * Switched from using global variable 'user' to object 'Session' as a
00064  * connection for tracking open document descriptors in the bert table.
00065  *
00066  * Revision 1.5  2002/04/07 14:03:48  jrush
00067  * Moved console-interactive functions examine(), showorgl() and showenfilades()
00068  * from libsrc/test.cxx to server/fns.cxx.
00069  *
00070  * Revision 1.4  2002/04/07 13:11:13  jrush
00071  * Relocated fns.cxx from libsrc to server directory
00072  *
00073  * Revision 1.5  2002/04/06 17:05:57  jrush
00074  * Switched from referring to 'task' for a client connection to 'session',
00075  * and converted the typetask typedef/struct into a Session C++ class.
00076  *
00077  * Revision 1.4  2002/04/06 15:01:17  jrush
00078  * Changed INT to just 'int'.
00079  *
00080  * Revision 1.3  2002/04/02 18:45:12  jrush
00081  * Purely cosmetic changes.
00082  *
00083  * Revision 1.2  2002/02/14 09:27:43  jrush
00084  * Cleaned up source:
00085  *
00086  * 1. ran thru the indent tool to achieve a standard look,
00087  * 2. added structured comments at top for use with DOxygen reporting
00088  *    as well as CVS keywords,
00089  * 3. fixed compiler warnings re ambiguous assign/compares,
00090  *    needed casts and unused/uninitialized variables,
00091  * 4. fixed funcs that didn't specify a return type,
00092  * 5. centralized prototypes in protos.h, removing incomplete ones,
00093  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00094  * 7. fixed initializer nesting in tumbler constants,
00095  * 8. renamed vars that conflict with C++ keywords (new, this),
00096  * 9. fixed global/extern confusion re some global vars.
00097  *
00098  */
00099 
00100 #include "udanax.h"
00101 #include "players.h"
00102 #include "requests.h"
00103 
00104 bool  getfinddocscontaining(Session * sess, typespecset * specsetptr);
00105 bool  getcopy(Session * sess, IStreamAddr * docisaptr, IStreamAddr * vsaptr, typespecset * localspecsetptr);
00106 bool  getinsert(Session * sess, IStreamAddr * docisaptr, Tumbler * vsaptr, typetextset * textsetptr);
00107 bool  getcreatelink(Session * sess, IStreamAddr * docisaptr, typespecset * fromspecsetptr, typespecset * tospecsetptr, typespecset * threespecsetptr);
00108 bool  getfollowlink(Session * sess, IStreamAddr * linkisaptr, int * whichendptr);
00109 bool  getcreatenewversion(Session * sess, IStreamAddr * docisaptr);
00110 bool  getretrievedocvspanset(Session * sess, IStreamAddr * docisaptr);
00111 bool  getretrievedocvspan(Session * sess, IStreamAddr * docisaptr);
00112 bool  getrearrange(Session * sess, IStreamAddr * docisaptr, typecutseq * cutseqptr);
00113 bool  getretrievev(Session * sess, typespecset * specsetptr);
00114 bool  getfindlinksfromtothree(Session * sess, typespecset * fromvspecsetptr, typespecset * tovspecsetptr, typespecset * threevspecsetptr, typeispanset * homesetptr);
00115 bool  getfindnumoflinksfromtothree(Session * sess, typespecset * fromvspecsetptr, typespecset * tovspecsetptr, typespecset * threevspecsetptr, typeispanset * homesetptr);
00116 bool  getfindnextnlinksfromtothree(Session * sess, typespecset * fromvspecsetptr, typespecset * tovspecsetptr, typespecset * threevspecsetptr, typeispanset * homesetptr, IStreamAddr * lastlinkptr, int * nptr);
00117 bool  getshowrelationof2versions(Session * sess, typespecset * version1ptr, typespecset * version2ptr);
00118 void  getcreatenewdocument();
00119 bool  getdeletevspan(Session * sess, IStreamAddr * docisaptr, typevspan * vspanptr);
00120 void  setdebug(Session * sess);
00121 void  playwithalloc(Session * sess);
00122 bool  getretrieveendsets(Session * sess, typespecset * specsetptr);
00123 bool  getxaccount(Session * sess, IStreamAddr * accountptr);
00124 bool  getcreatenode_or_account(Session *sess, Tumbler *tp);
00125 bool  getopen(Session *sess, Tumbler *tp, int *typep, int *modep);
00126 bool  getclose(Session *sess, Tumbler *tp);
00127 bool  gettumbler(Session * sess, Tumbler * tumblerptr);
00128 
00129 void  prompt(Session * sess, char *string);
00130 void  error(Session * sess, char *string);
00131 void  puttumbler(FILE * outfile, Tumbler * tumblerptr);
00132 void  putnum(FILE * outfile, int num);
00133 void  putisa(Session * sess, IStreamAddr * isaptr);
00134 void  putitemset(Session * sess, typeitemset itemset);
00135 void  putitem(Session * sess, typeitem * itemptr);
00136 void  putspan(Session * sess, typespan * spanptr);
00137 void  puttext(Session * sess, typetext * textptr);
00138 void  putspanpairset(Session * sess, typespanpairset spanpairset);
00139 void  putspanpair(Session * sess, typespanpair * spanpair);
00140 void  putcreatelink(Session * sess, IStreamAddr * istreamptr);
00141 void  putfollowlink(Session * sess, typespecset specset);
00142 void  putretrievedocvspanset(Session * sess, typespanset * spansetptr);
00143 void  putretrievedocvspan(Session * sess, typespan * vspanptr);
00144 void  putretrievev(Session * sess, typevstuffset * vstuffsetptr);
00145 void  putfindlinksfromtothree(Session * sess, typelinkset linkset);
00146 void  putfindnumoflinksfromtothree(Session * sess, int num);
00147 void  putfindnextnlinksfromtothree(Session * sess, int n, typelinkset nextlinkset);
00148 void  putshowrelationof2versions(Session * sess, typespanpairset relation);
00149 void  putcreatenewdocument(Session * sess, IStreamAddr * newdocisaptr);
00150 void  putcreatenewversion(Session * sess, IStreamAddr * newdocisaptr);
00151 void  putfinddocscontaining(Session * sess, typeitemset addressset);
00152 void  putretrieveendsets(Session * sess, typespecset fromset, typespecset toset, typespecset threeset);
00153 void  putinsert(Session * sess);
00154 void  putcopy(Session * sess);
00155 void  putdeletevspan(Session * sess);
00156 void  putrearrange(Session * sess);
00157 void  putrequestfailed(Session * sess);
00158 void  putxaccount(Session * sess);
00159 void  putcreatenode_or_account(Session * sess, Tumbler * tp);
00160 void  putopen(Session * sess, Tumbler * tp);
00161 void  putclose(Session * sess);
00162 void  putquitxanadu(Session * sess);
00163 
00164 extern FILE *interfaceinput;
00165 
00166 extern int backenddaemon;
00167 
00168 extern bool docreatenewversion(Session *sess, IStreamAddr *isaptr, IStreamAddr *wheretoputit, IStreamAddr *newisaptr);
00169 
00177     void
00178 finddocscontaining(
00179     Session *sess)    
00180 {
00181     typespecset specset;
00182     typelinkset addressset;
00183 
00184     if (getfinddocscontaining(sess, &specset) && dofinddocscontaining(sess, specset, &addressset))
00185         putfinddocscontaining(sess, (typeitemset) addressset);
00186     else
00187         putrequestfailed(sess);
00188 }
00189 
00197     void
00198 copy(
00199     Session *sess)    
00200 {
00201     IStreamAddr docisa, vsa;
00202     typespecset localspecset;
00203 
00204     if (getcopy(sess, &docisa, &vsa, &localspecset) && docopy(sess, &docisa, &vsa, localspecset))
00205         putcopy(sess);
00206     else
00207         putrequestfailed(sess);
00208 }
00209 
00210 #ifdef UnDEfined
00211     void
00212 copy(
00213     Session * sess)    
00214 {                                      /* kluged unix version for speed */
00215     IStreamAddr docisa, vsa;
00216     typespecset localspecset;
00217 
00218     getcopy(sess, &docisa, &vsa, &localspecset);
00219     putcopy(sess);
00220 
00221     if (!docopy(sess, &docisa, &vsa, /* & ECH according to lint */ &localspecset))   /* zzz * aug * 21 * 1999 *
00222                                                                                          * reg * ? * this * may *
00223                                                                                          * cause * trouble * * */
00224 #ifndef DISTRIBUTION
00225         L("copy failed \n");
00226 #else
00227         ;
00228 #endif
00229 }
00230 #endif
00231 
00232 /* void insert (sess) Session *sess; { IStreamAddr docisa, vsa; typetextset textset; bool getinsert(), doinsert();
00233  * if ( getinsert (sess, &docisa, &vsa, &textset) && doinsert (sess, &docisa, &vsa, textset)) putinsert
00234  * (sess); else putrequestfailed (sess); } */
00235 
00243     void
00244 insert(
00245     Session *sess)    
00246 {                                      /* cheating version for unix zzz */
00247     IStreamAddr docisa, vsa;
00248     typetextset textset;
00249 
00250     getinsert(sess, &docisa, &vsa, &textset);
00251     putinsert(sess);
00252 
00253     if (!doinsert(sess, &docisa, &vsa, textset))
00254 #ifndef DISTRIBUTION
00255         L("requestfailed in insert\n");
00256 #else
00257         ;
00258 #endif
00259 }
00260 
00268     void
00269 createlink(
00270     Session *sess)    
00271 {
00272     IStreamAddr docisa, linkisa;
00273     typespecset fromspecset, tospecset, threespecset;
00274 
00275     if (getcreatelink(sess, &docisa, &fromspecset, &tospecset, &threespecset)
00276         && docreatelink(sess, &docisa, fromspecset, tospecset, threespecset, &linkisa)) {
00277         putcreatelink(sess, &linkisa);
00278     } else
00279         putrequestfailed(sess);
00280 }
00281 
00289     void
00290 followlink(
00291     Session *sess)    
00292 {
00293     IStreamAddr linkisa;
00294     typespecset specset;
00295     int whichend;
00296 
00297     if (getfollowlink(sess, &linkisa, &whichend)
00298         && dofollowlink(sess, &linkisa, &specset, whichend)) {
00299         putfollowlink(sess, specset);
00300     } else
00301         putrequestfailed(sess);
00302 }
00303 
00311     void
00312 retrievedocvspanset(
00313     Session *sess)    
00314 {
00315     IStreamAddr docisa;
00316     typevspanset vspanset;
00317 
00318     if (getretrievedocvspanset(sess, &docisa)
00319         && doretrievedocvspanset(sess, &docisa, &vspanset))
00320         putretrievedocvspanset(sess, &vspanset);
00321     else
00322         putrequestfailed(sess);
00323 }
00324 
00325 /* void rearrange (sess) Session *sess; { IStreamAddr docisa; typecutseq cutseq; bool getrearrange(), dorearrange();
00326  * if ( getrearrange (sess, &docisa, &cutseq) && dorearrange (sess, &docisa, &cutseq)) putrearrange (sess); else 
00327  * putrequestfailed (sess); } */
00328 
00336     void
00337 rearrange(
00338     Session *sess)    
00339 {                                      /* speed hack for unix */
00340     IStreamAddr docisa;
00341     typecutseq cutseq;
00342 
00343     (void)getrearrange(sess, &docisa, &cutseq);
00344     putrearrange(sess);
00345     if (!dorearrange(sess, &docisa, &cutseq))
00346 #ifndef DISTRIBUTION
00347         L("rearrange failed \n");
00348 #else
00349         ;
00350 #endif
00351 }
00352 
00360     void
00361 retrievev(
00362     Session *sess)    
00363 {
00364     typespecset specset;
00365     typevstuffset vstuffset;
00366 
00367     if (getretrievev(sess, &specset)
00368         && doretrievev(sess, specset, &vstuffset))
00369         putretrievev(sess, &vstuffset);
00370     else
00371         putrequestfailed(sess);
00372 }
00373 
00381     void
00382 findlinksfromtothree(
00383     Session *sess)    
00384 {
00385     typespecset fromvspecset, tovspecset, threevspecset;
00386     typeispanset homeset;
00387     typelinkset linkset;
00388 
00389     if (getfindlinksfromtothree(sess, &fromvspecset, &tovspecset, &threevspecset, &homeset)
00390         && dofindlinksfromtothree(sess, fromvspecset, tovspecset, threevspecset, (typeispan *) NULL /* homeset */ ,
00391                                   &linkset))
00392         putfindlinksfromtothree(sess, linkset);
00393     else
00394         putrequestfailed(sess);
00395 }
00396 
00404     void
00405 findnumoflinksfromtothree(
00406     Session *sess)    
00407 {
00408     typespecset fromvspecset, tovspecset, threevspecset;
00409     typeispanset homeset;
00410     int numberoflinks;
00411 
00412     if (getfindnumoflinksfromtothree(sess, &fromvspecset, &tovspecset, &threevspecset, &homeset)
00413         && dofindnumoflinksfromtothree(sess, (typespec **) fromvspecset, (typespec **) tovspecset, (typespec **) threevspecset, homeset, &numberoflinks))
00414         putfindnumoflinksfromtothree(sess, numberoflinks);
00415     else
00416         putrequestfailed(sess);
00417 }
00418 
00426     void
00427 findnextnlinksfromtothree(
00428     Session *sess)    
00429 {
00430     typespecset fromvspecset, tovspecset, threevspecset;
00431     typeispanset homeset;
00432     IStreamAddr lastlink;
00433     typelinkset nextlinkset;
00434     int n;
00435 
00436     if (getfindnextnlinksfromtothree(sess, &fromvspecset, &tovspecset, &threevspecset, &homeset, &lastlink, &n)
00437         && dofindnextnlinksfromtothree(sess, (typevspec *) fromvspecset, (typevspec *) tovspecset, (typevspec *) threevspecset, homeset, &lastlink,
00438                                        &nextlinkset, &n))
00439         putfindnextnlinksfromtothree(sess, n, nextlinkset);
00440     else
00441         putrequestfailed(sess);
00442 }
00443 
00451     void
00452 navigateonht(
00453     Session *sess)    
00454 {
00455 #ifndef DISTRIBUTION
00456     error(sess, "GACK !  (historical trace)\n");
00457 #endif
00458 
00459 /* 
00460  * IStreamAddr docisa, htisa; typehtpath turninginstructions; bool
00461  * getnavigateonht(); if (getnavigateonht(sess, &docisa, &htisa,
00462  * &turninginstructions)) donavigateonht(sess, &docisa, &htisa,
00463  * &turninginstructions); */
00464 }
00465 
00473     void
00474 showrelationof2versions(
00475     Session *sess)    
00476 {
00477     typespecset version1, version2;
00478     typespanpairset relation;
00479 
00480     if (getshowrelationof2versions(sess, &version1, &version2)
00481         && doshowrelationof2versions(sess, version1, version2, &relation))
00482         putshowrelationof2versions(sess, relation);
00483     else
00484         putrequestfailed(sess);
00485 }
00486 
00487 /* 
00488  * void showrelationof2versions (sess) Session *sess; { IStreamAddr doc1,
00489  * doc2; int relation; // temp // bool getshowrelationof2versions(),
00490  * doshowrelationof2versions();
00491  * 
00492  * if (getshowrelationof2versions(sess, &doc1, &doc2)) if
00493  * (doshowrelationof2versions(sess, &doc1, &doc2, &relation))
00494  * putshowrelationof2versions(sess, &relation); } */
00495 
00503     void
00504 createnewdocument(
00505     Session *sess)    
00506 {
00507     IStreamAddr newdocisa;
00508 
00509     getcreatenewdocument();
00510     if (docreatenewdocument(sess, &newdocisa))
00511         putcreatenewdocument(sess, &newdocisa);
00512     else
00513         putrequestfailed(sess);
00514 }
00515 
00523     void
00524 createnewversion(
00525     Session *sess)    
00526 {
00527     IStreamAddr originaldocisa, newdocisa;
00528 
00529     if (getcreatenewversion(sess, &originaldocisa)
00530         && docreatenewversion(sess, &originaldocisa, &originaldocisa, &newdocisa))
00531         putcreatenewversion(sess, &newdocisa);
00532     else
00533         putrequestfailed(sess);
00534 }
00535 
00543     void
00544 retrievedocvspan(
00545     Session *sess)    
00546 {
00547     IStreamAddr docisa;
00548     typevspan vspan;
00549 
00550     if (getretrievedocvspan(sess, &docisa)
00551         && doretrievedocvspan(sess, &docisa, &vspan))
00552         putretrievedocvspan(sess, &vspan);
00553     else
00554         putrequestfailed(sess);
00555 }
00556 
00557 /* 
00558  * void deletevspan (sess) Session *sess; { IStreamAddr docisa; typespan
00559  * vspan; bool getdeletevspan(), dodeletevspan();
00560  * 
00561  * if ( getdeletevspan (sess, &docisa, &vspan) && dodeletevspan (sess,
00562  * &docisa, &vspan)) putdeletevspan (sess); else putrequestfailed
00563  * (sess); } */
00564 
00572     void
00573 deletevspan(
00574     Session *sess)    
00575 {                                      /* kluged unix version for speed */
00576     IStreamAddr docisa;
00577     typespan vspan;
00578 
00579     (void)getdeletevspan(sess, &docisa, &vspan);
00580     putdeletevspan(sess);
00581     if (!dodeletevspan(sess, &docisa, &vspan))
00582 #ifndef DISTRIBUTION
00583         L("deletevspan failed \n");
00584 #else
00585         ;
00586 #endif
00587 }
00588 
00596     void
00597 retrieveendsets(
00598     Session *sess)    
00599 {
00600     typespecset specset, fromset, toset, threeset;
00601 
00602     if (getretrieveendsets(sess, &specset)
00603         && doretrieveendsets(sess, specset, &fromset, &toset, &threeset)) {
00604 
00605         putretrieveendsets(sess, fromset, toset, threeset);
00606     } else
00607         putrequestfailed(sess);
00608 }
00609 
00617     void
00618 xaccount(
00619     Session *sess)    
00620 {
00621     if (getxaccount(sess, (IStreamAddr *) &(player[user].account))) {
00622         putxaccount(sess);
00623     } else {
00624         putrequestfailed(sess);
00625     }
00626 }
00627 
00635     void
00636 createnode_or_account(
00637     Session *sess)    
00638 {
00639     IStreamAddr t;
00640 
00641     if (getcreatenode_or_account(sess, &t)
00642         && docreatenode_or_account(sess, &t)) {
00643         putcreatenode_or_account(sess, &t);
00644     } else {
00645         putrequestfailed(sess);
00646     }
00647 }
00648 
00656     void
00657 myopen(
00658     Session *sess)    
00659 {
00660     IStreamAddr t, newt;
00661     int type, mode;
00662 
00663     if (getopen(sess, &t, &type, &mode)
00664         && doopen(sess, &t, &newt, type, mode)) {
00665         putopen(sess, &newt);
00666     } else {
00667         putrequestfailed(sess);
00668     }
00669 }
00670 
00678     void
00679 myclose(
00680     Session *sess)    
00681 {
00682     IStreamAddr t;
00683 
00684     if (getclose(sess, &t)
00685         && doclose(sess, &t)) {
00686         putclose(sess);
00687     } else {
00688         putrequestfailed(sess);
00689     }
00690 }
00691 
00699     void
00700 quitxanadu(
00701     Session *sess)    
00702 {
00703     putquitxanadu(sess);
00704 
00705     if (!backenddaemon) {
00706         if (interfaceinput) {
00707             fprintf(interfaceinput, "%d~\n", QUIT);
00708             fclose(interfaceinput);
00709         }
00710         diskexit();
00711     } else
00712         closeberts(sess);              /* Close all of the user's outstanding opens */
00713 }
00714 
00722     void
00723 examine(
00724     Session *sess)    
00725 {
00726 #ifndef DISTRIBUTION
00727     char c;
00728     //UNUSED IStreamAddr orglisa;
00729     //UNUSED typeorgl orgl;
00730 
00731     prompt(sess, "\nspanf (s), orgl (o) or istream (i) ? ");
00732     c = getc(sess->inp);
00733     if (c != '\n')
00734         getc(sess->inp);
00735 
00736     L("\n");
00737     switch (c) {
00738     case 'i':
00739         showistream((typecuc *) granf);
00740         break;
00741     case 's':
00742         showspanf((typecuc *) spanf);
00743         break;
00744 
00745     case 'o':
00746 /* prompt (sess, "orgl isa => "); if (!( gettumbler (sess, &orglisa) && findorgl (sess, granf, &orglisa,
00747  * &orgl,READBERT))) { L(sess->errp, "\nnot found\n"); } else { showspanf (orgl); } */
00748         showorgl(sess);
00749         break;
00750 
00751     default:
00752         return;
00753     }
00754 #endif
00755 }
00756 
00764     void
00765 showorgl(
00766     Session *sess)    
00767 {
00768 #ifndef DISTRIBUTION
00769     typeorgl orgl;
00770     IStreamAddr orglisa;
00771 
00772     prompt(sess, "orgl isa => ");
00773     if (!(gettumbler(sess, &orglisa)
00774           && findorgl(sess, granf, &orglisa, &orgl, READBERT))) {
00775         L("\nnot found\n");
00776     } else {
00777         showsubtree((typecorecrum *) orgl);
00778     }
00779 #endif
00780 }
00781 
00789     void
00790 showenfilades(
00791     Session *sess)    
00792 {
00793 #ifndef DISTRIBUTION
00794     char c;
00795 
00796     prompt(sess, "\ngranf (g), spanf (s) or orgl (o) ? ");
00797     c = getc(sess->inp);
00798     if (c != '\n')
00799         getc(sess->inp);
00800 
00801     L("\n");
00802 
00803     switch (c) {
00804     case 'o':  showorgl(sess);                           break;
00805     case 'g':  showsubtree((typecorecrumhedr *) granf);  break;
00806     case 's':  showsubtree((typecorecrumhedr *) spanf);  break;
00807     default:                                             break;
00808     }
00809 #endif
00810 }

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