Ignore:
Timestamp:
2004-07-13T10:57:05+12:00 (20 years ago)
Author:
kjdon
Message:

commiting John T's changes (c/- DL Consulting) to stop phind hanging the browser if the gsdl server goes boom

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/phindaction.cpp

    r7417 r7734  
    181181
    182182    DocNumArray result;
    183     find_phrase_number_from_word(basepath, word, result);
     183    /** In order to prevent browser crashing problems, any method which
     184     *  previously suffered a silent fatal error, now instead returns false
     185     *  to indicate a fatal error has occured. We can then dispatch an
     186     *  appropriate error tag to the Phind applet (rather than leave it
     187     *  whiling away the milliseconds until the end of existence - or at
     188     *  least your browser - in an infinite loop!)
     189     *  DLConsulting 12-07-2004
     190     */
     191    if(!find_phrase_number_from_word(basepath, word, result)) {
     192    output_error("phindaction: Fatal Error! Couldn't load index information in find_phrase_number_from_word()",
     193             textout, outconvert, disp, logout, XMLmode);
     194    return true;
     195    }
    184196   
    185197    if (result.empty()) {
     
    205217  if (!textdata.LoadData (base, fullpathc)) {
    206218    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
    207     exit (0);
     219    //exit(0);
     220    /** We must return something to the client, whether this error is fatal or
     221     *  no, otherwise we risk sending their browser into an infinite loop!
     222     *  DLConsulting 12-07-2004
     223     */
     224    output_error("phindaction: Fatal Error! Couldn't load text information for collection",
     225         textout, outconvert, disp, logout, XMLmode);
     226    return true;
    208227  }
    209228
    210229  delete []fullpathc;
    211230
    212   get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el,
    213               linkdest, linktype, docNums, docfreq);
     231  /** Another previously silent method can now cry out.
     232   *  DLConsulting 12-07-2004
     233   */
     234  if(!get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el,
     235              linkdest, linktype, docNums, docfreq)) {
     236    output_error(
     237      "phindaction: Fatal Error! Couldn't parse phrase in get_phrase_all_data()",
     238      textout, outconvert, disp, logout, XMLmode);
     239      return true;   
     240  }
    214241
    215242  // Output the header
     
    243270          << "\" start=\"" << first_l
    244271          << "\" end=\"" << last_l << "\">\n";
    245       print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
    246                 first_l, last_l, disp, outconvert, textout);
     272      /** DLConsulting 12-07-2004 */
     273      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
     274                   first_l, last_l, disp, outconvert, textout)) {
     275    output_error(
     276             "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
     277             textout, outconvert, disp, logout, XMLmode);
     278    return true;   
     279      }
    247280      textout << "</thesauruslist>\n";
    248281    }
     
    257290
    258291      textout << "<p><table border=1><tr><th>type</th><th>topic</th><th>freq</th><th>docs</th></tr>\n";
    259       print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
    260                 first_l, last_l, disp, outconvert, textout);
     292      /** DLConsulting 12-07-2004 */
     293      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
     294                   first_l, last_l, disp, outconvert, textout)) {
     295    output_error(
     296             "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
     297             textout, outconvert, disp, logout, XMLmode);
     298    return true;
     299      }
    261300      textout << "</table>\n";
    262301
     
    368407          << "\" end=\"" << last_d << "\">\n";
    369408     
    370       print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
    371               first_d, last_d, disp, outconvert, textout);
     409      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
     410              first_d, last_d, disp, outconvert, textout)) {
     411    output_error(
     412             "phindaction: Fatal Error! Couldn't load text information in print_documents() or get_document_all_data()",
     413             textout, outconvert, disp, logout, XMLmode);
     414    return true;   
     415      }
    372416
    373417      textout << "</documentlist>\n";
     
    384428
    385429      textout << "<p><table border=1><tr><th align=left>document</th><th>freq</th></tr>\n";
    386       print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
    387               first_d, last_d, disp, outconvert, textout);
     430      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
     431              first_d, last_d, disp, outconvert, textout)) {
     432    output_error(
     433             "phindaction: Fatal Error! Couldn't load text information in print_documents()",
     434             textout, outconvert, disp, logout, XMLmode);
     435    return true;
     436      }
    388437      textout << "</table>\n";
    389438     
     
    430479
    431480// Find the phrase number of a word in the index file
    432 void phindaction::find_phrase_number_from_word(const text_t &basepath,
     481bool phindaction::find_phrase_number_from_word(const text_t &basepath,
    433482                           const text_t &query,
    434483                           DocNumArray &result) {
     
    447496  if (!indexData.LoadData (base, fullpathc)) {
    448497    //    FatalError (1, "Couldn't load index information for \"%s\"", fullpathc);
    449     exit (0);
     498    //exit(0);
     499    /** Don't handle fatal errors here anymore.
     500     *  DLConsulting 12-07-2004
     501     */
     502    return false; // Indicates something very bad has happened
    450503  }
    451504
     
    478531
    479532  indexData.UnloadData();
     533
     534  /** This method now returns a boolean, so...
     535   *  DLConsulting 12-07-2004
     536   */
     537  return true; // Indicates that what happened is all good, baby.
    480538}
    481539
     
    492550//   ll - the list of phrases that are thesaurus links
    493551//   dl - the list of documents that contain phrase
    494 void phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,
     552bool phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,
    495553                      text_t &word, unsigned long &tf, unsigned long &ef,
    496554                      unsigned long &lf, unsigned long &df,
     
    507565  if (!GetDocText (textdata, docLevel, phrase, text)) {
    508566    //    FatalError (1, "Error while trying to get phrase %u", phrase);
    509     exit (0);
     567    //exit(0);
     568    return false; // Something very bad has happened.
    510569  }
    511570
     
    630689    }
    631690  }
    632 }
    633 
    634 void phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode,
     691
     692  return true; // Indicates that what happened is all good, baby.
     693}
     694
     695bool phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode,
    635696                    TextData &textdata, vector <unsigned long> &linkdest,
    636697                    vector <UCArray> &linktype, unsigned long first,
     
    647708    phrase = linkdest[l];
    648709    type = linktype[l];
    649     get_phrase_freq_data(textdata, phrase, text, tf, ef, df);
     710
     711    /** DLConsulting 12-07-2004 */
     712    if(!get_phrase_freq_data(textdata, phrase, text, tf, ef, df)) {
     713      return false;
     714    }
    650715   
    651716    if (XMLmode) {
     
    665730    }
    666731  }
     732
     733  /** DLConsulting 12-07-2004 */
     734  return true;
    667735}
    668736
     
    675743//   ef - the expansion frequency of the phrase
    676744//   df - the document frequency of the phrase
    677 void phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase,
     745/**
     746 *   Returns:
     747 *     false if the method suffered a fatal error, true otherwise
     748 */
     749bool phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase,
    678750                       UCArray &word, unsigned long &tf,
    679751                       unsigned long &ef, unsigned long &df) {
     
    686758  if (!GetDocText (textdata, docLevel, phrase, text)) {
    687759    //    FatalError (1, "Error while trying to get phrase %u", phrase);
    688     exit (0);
     760    //exit(0);
     761    /** DLConsulting 12-07-2004 */
     762    return false;
    689763  }
    690764
     
    719793    df += (*next - '0');
    720794  }
     795
     796  /** DLConsulting 12-07-2004 */
     797  return true;
    721798}
    722799
     
    844921}
    845922
    846 void phindaction::print_documents(bool XMLmode, const text_t &basepath,
     923bool phindaction::print_documents(bool XMLmode, const text_t &basepath,
    847924                  const text_t &collection,
    848925                  const vector <unsigned long> &docNums,
     
    865942  if (!docdata.LoadData (base, fullpathc)) {
    866943    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
    867     exit (0);
     944    //exit(0);
     945    /** DLConsulting 12-07-2004 */
     946    return false;
    868947  }
    869948
     
    877956    freq = docFreq[d];
    878957
    879     get_document_all_data(docdata, doc, title, hash);
     958    /** DLConsulting 13-07-2004 */
     959    if(!get_document_all_data(docdata, doc, title, hash)) {
     960      return false;
     961    }
    880962
    881963    if (XMLmode) {
     
    894976
    895977  docdata.UnloadData();
     978
     979  /** DLConsulting 12-07-2004 */
     980  return true;
    896981}
    897982
     
    902987//   title - the document's title
    903988//   hash - the document's unique OID
    904 void phindaction::get_document_all_data(TextData &docdata, unsigned long docNum,
     989/** Returns:
     990 *   false if a fatal error occured, true otherwise
     991 *  DLConsulting 12-07-2004
     992 */
     993bool phindaction::get_document_all_data(TextData &docdata, unsigned long docNum,
    905994                    UCArray &title, UCArray &hash) {
    906995
     
    9121001  if (!GetDocText (docdata, docLevel, docNum, text)) {
    9131002    //    FatalError (1, "Error while trying to get document %u", docNum);
    914     exit (0);
     1003    //exit(0);
     1004    /** DLConsulting 13-07-2004 */
     1005    return false;
    9151006  }
    9161007
     
    9311022    title.push_back(*next);
    9321023  }
     1024
     1025  /** DLConsulting 13-07-2004 */
     1026  return true;
    9331027}
    9341028
     
    9661060
    9671061#endif //GSDL_USE_PHIND_ACTION
     1062
Note: See TracChangeset for help on using the changeset viewer.