Diff for /parser3/src/include/pa_request.h between versions 1.246 and 1.268

version 1.246, 2017/01/17 23:53:28 version 1.268, 2024/11/04 03:53:25
Line 1 Line 1
 /** @file  /** @file
         Parser: request class decl.          Parser: request class decl.
   
         Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #ifndef PA_REQUEST_H  #ifndef PA_REQUEST_H
Line 19 Line 19
 #include "pa_request_charsets.h"  #include "pa_request_charsets.h"
 #include "pa_sapi.h"  #include "pa_sapi.h"
   
   // defines for externs
   
   #define EXCEPTION_HANDLED_PART_NAME "handled"
   
   
   // externs
   
   extern const String main_method_name;
   extern const String auto_method_name;
   
   extern const String exception_type_part_name;
   extern const String exception_source_part_name;
   extern const String exception_comment_part_name;
   extern const String exception_handled_part_name;
   
   // defines for statics
   
   #define MAIN_CLASS_NAME "MAIN"
   #define AUTO_FILE_NAME "auto.p"
   
 // consts  // consts
   
 const size_t pseudo_file_no__process=1;  const size_t pseudo_file_no__process=1;
Line 36  class VStateless_class; Line 56  class VStateless_class;
 class VConsole;  class VConsole;
   
 extern int pa_loop_limit;  extern int pa_loop_limit;
 extern int pa_execute_recoursion_limit;  extern int pa_array_limit;
   extern int pa_execute_recursion_limit;
   extern int pa_httpd_timeout;
 extern size_t pa_file_size_limit;  extern size_t pa_file_size_limit;
   
 /// Main workhorse.  /// Main workhorse.
Line 45  class Request: public PA_Object { Line 67  class Request: public PA_Object {
         friend class Temp_connection;          friend class Temp_connection;
         friend class Temp_request_self;          friend class Temp_request_self;
         friend class Temp_value_element;          friend class Temp_value_element;
           friend class Temp_recursion;
         friend class Request_context_saver;          friend class Request_context_saver;
         friend class Exception_trace;          friend class Exception_trace;
   
Line 89  private: Line 112  private:
                 ArrayOperation& ops() const { return *fops; }                  ArrayOperation& ops() const { return *fops; }
                 VMethodFrame& method_frame() const { return *fmethod_frame; }                  VMethodFrame& method_frame() const { return *fmethod_frame; }
   
                 /// needed to fill unused Array entries  
                 StackItem() {}  
                 StackItem(Value& avalue): fvalue(&avalue) {}                  StackItem(Value& avalue): fvalue(&avalue) {}
                 StackItem(ArrayOperation& aops): fops(&aops) {}                  StackItem(ArrayOperation& aops): fops(&aops) {}
                 StackItem(VMethodFrame& amethod_frame): fmethod_frame(&amethod_frame) {}                  StackItem(VMethodFrame& amethod_frame): fmethod_frame(&amethod_frame) {}
Line 106  private: Line 127  private:
                 element_type bottom_value() { return get(bottom_index()); }                  element_type bottom_value() { return get(bottom_index()); }
   
                 void clear() {                  void clear() {
                         fused=fbottom=0;                          fsize=fbottom=0;
                 }                  }
   
                 bool is_empty() {                  bool is_empty() {
                         return fused==fbottom;                          return fsize==fbottom;
                 }                  }
   
                   Table &table(Request &r);
         };          };
   
         ///@{ core data          ///@{ core data
Line 126  private: Line 149  private:
         Array<String::Body> file_list;          Array<String::Body> file_list;
   
         /// endless execute(execute(... preventing counter          /// endless execute(execute(... preventing counter
         int anti_endless_execute_recoursion;          int anti_endless_execute_recursion;
   
         ///@}          ///@}
   
Line 187  public: Line 210  public:
         /// global classes          /// global classes
         HashString<VStateless_class*>& classes() { return fclasses; }          HashString<VStateless_class*>& classes() { return fclasses; }
         VStateless_class* get_class(const String& name);          VStateless_class* get_class(const String& name);
           VStateless_class& get_class_ref(const String& name);
         void put_class(VStateless_class *aclass){ classes().put(aclass->type(), aclass); }          void put_class(VStateless_class *aclass){ classes().put(aclass->type(), aclass); }
           bool add_class(const char* atype, VStateless_class *aclass);
   
         /**          /**
                 core request processing                  core request processing
                 BEWARE: may throw exception to you: catch it!                  BEWARE: may throw exception to you: catch it!
         */          */
         void core(const char* config_filespec, bool config_fail_on_read_problem, bool header_only);          void core(const char* config_filespec, bool header_only, const String& amain_method_name = main_method_name, const String* amain_class_name = NULL);
   
         /// executes ops          /// executes ops
         void execute(ArrayOperation& ops); // execute.C          void execute(ArrayOperation& ops); // execute.C
Line 226  public: Line 251  public:
   
         Value& construct(VStateless_class &class_value, const Method &method);          Value& construct(VStateless_class &class_value, const Method &method);
   
         /// execute ops with anti-recoursion check          /// execute ops with anti-recursion check
         void recoursion_checked_execute(ArrayOperation& ops) {          void recursion_checked_execute(ArrayOperation& ops) {
                 if(++anti_endless_execute_recoursion==pa_execute_recoursion_limit) {                  if(++anti_endless_execute_recursion==pa_execute_recursion_limit) {
                         anti_endless_execute_recoursion=0; // give @exception a chance                          anti_endless_execute_recursion=0; // give @exception a chance
                         throw Exception(PARSER_RUNTIME, 0, "call canceled - endless recursion detected");                          throw Exception(PARSER_RUNTIME, 0, "call canceled - endless recursion detected");
                 }                  }
                 execute(ops); // execute it                  execute(ops); // execute it
                 anti_endless_execute_recoursion--;                  anti_endless_execute_recursion--;
         }          }
   
         ///          ///
         void use_file_directly(VStateless_class& aclass, const String& file_spec, bool fail_on_read_problem=true, bool fail_on_file_absence=true);          void use_file_directly(const String& file_spec, bool fail_on_file_absence=true, bool with_auto_p=false);
   
         /// compiles the file, maybe forcing it's class @a name and @a base_class.          /// compiles the file in main class context by default
         void use_file(VStateless_class& aclass, const String& file_name, const String* use_filespec);          void use_file(const String& file_name, const String* use_filespec, bool with_auto_p=false);
   
         /// for @USE only, calls ^use (which may be user-defined)          /// for @USE only, calls ^use (which may be user-defined)
         void use_file(const String& file_name, const String* use_filespec, Operation::Origin origin);          void use_file(const String& file_name, const String* use_filespec, Operation::Origin origin);
Line 258  public: Line 283  public:
                 return process(input_value).as_string();                  return process(input_value).as_string();
         }          }
         //@}          //@}
           const Operation::Origin get_method_origin(const Method* method); // execute.C
         const String* get_method_filespec(const Method* method); // execute.C          const String* get_method_filespec(const Method* method); // execute.C
         const String* get_used_filespec(uint file_no);          const String* get_used_filespec(uint file_no);
                   
Line 280  public: Line 306  public:
         /// returns relative to @a path  path to @a file           /// returns relative to @a path  path to @a file 
         const String& relative(const char* apath, const String& relative_name);          const String& relative(const char* apath, const String& relative_name);
   
         /// returns an absolute @a path to relative @a name          const String& full_disk_path(const String& relative_name);
         const String& absolute(const String& relative_name);  
   
         /// returns the mime type of 'user_file_name'          /// returns the mime type of 'user_file_name'
         const String& mime_type_of(const String* file_name);          const String& mime_type_of(const String* file_name);
Line 342  public: // status read methods Line 367  public: // status read methods
         /// public for ^reflection:copy[]          /// public for ^reflection:copy[]
         void put_element(Value& ncontext, const String& name, Value* value);          void put_element(Value& ncontext, const String& name, Value* value);
   
         /// for @main[]          /// for @main[] and parser://method/call
         const String* execute_virtual_method(Value& aself, const String& method_name);          const String* execute_method(VStateless_class& aclass, const String& method_name, Value* optional_param = 0);
   
         //{ for @conf[filespec] and @auto[filespec] and parser://method/call  
         const String* execute_method(Value& aself, const Method& method, Value* optional_param, bool do_return_string);  
   
         struct Execute_nonvirtual_method_result {          //{ for @conf[filespec] and @auto[filespec]
                 const String* string;          bool execute_method_if_exists(VStateless_class& aclass, const String& method_name, Value* optional_param);
                 Method* method;          bool execute_auto_method_if_exists(VStateless_class& aclass, const String& method_name, Value* optional_param);
                 Execute_nonvirtual_method_result(): string(0), method(0) {}  
         };  
   
         Execute_nonvirtual_method_result execute_nonvirtual_method(VStateless_class& aclass, const String& method_name, VString* optional_param, bool do_return_string);  
         //}          //}
   
 #ifdef XML  #ifdef XML
Line 398  private: // mime types Line 417  private: // mime types
         /// $MAIN:MIME-TYPES          /// $MAIN:MIME-TYPES
         Table *mime_types;          Table *mime_types;
   
 private: // lang manipulation  
   
         String::Language set_lang(String::Language alang) {  
                 String::Language result=flang;  
                 flang=alang;  
                 return result;  
         }  
         void restore_lang(String::Language alang) {  
                 flang=alang;  
         }  
   
 private: // connection manipulation  private: // connection manipulation
   
         SQL_Connection* set_connection(SQL_Connection* aconnection) {          SQL_Connection* set_connection(SQL_Connection* aconnection) {
Line 434  class Request_context_saver { Line 442  class Request_context_saver {
         size_t exception_trace_bottom;          size_t exception_trace_bottom;
         /// execution stack          /// execution stack
         size_t stack;          size_t stack;
         uint anti_endless_execute_recoursion;          uint anti_endless_execute_recursion;
         /// contexts          /// contexts
         VMethodFrame* method_frame;          VMethodFrame* method_frame;
         Value* rcontext;          Value* rcontext;
Line 450  public: Line 458  public:
                 exception_trace_top(ar.exception_trace.top_index()),                  exception_trace_top(ar.exception_trace.top_index()),
                 exception_trace_bottom(ar.exception_trace.bottom_index()),                  exception_trace_bottom(ar.exception_trace.bottom_index()),
                 stack(ar.stack.top_index()),                  stack(ar.stack.top_index()),
                 anti_endless_execute_recoursion(ar.anti_endless_execute_recoursion),                  anti_endless_execute_recursion(ar.anti_endless_execute_recursion),
                 method_frame(ar.method_frame),                  method_frame(ar.method_frame),
                 rcontext(ar.rcontext),                  rcontext(ar.rcontext),
                 wcontext(ar.wcontext),                  wcontext(ar.wcontext),
Line 460  public: Line 468  public:
                 fr.exception_trace.set_top_index(exception_trace_top);                  fr.exception_trace.set_top_index(exception_trace_top);
                 fr.exception_trace.set_bottom_index(exception_trace_bottom);                  fr.exception_trace.set_bottom_index(exception_trace_bottom);
                 fr.stack.set_top_index(stack);                  fr.stack.set_top_index(stack);
                 fr.anti_endless_execute_recoursion=anti_endless_execute_recoursion;                  fr.anti_endless_execute_recursion=anti_endless_execute_recursion;
                 fr.method_frame=method_frame, fr.rcontext=rcontext; fr.wcontext=wcontext;                  fr.method_frame=method_frame, fr.rcontext=rcontext; fr.wcontext=wcontext;
                 fr.flang=flang;                  fr.flang=flang;
                 fr.fconnection=fconnection;                  fr.fconnection=fconnection;
Line 533  public: Line 541  public:
         ~Temp_value_element();          ~Temp_value_element();
 };  };
   
 // defines for externs  ///     Auto-object that temporarily increases recursion
   class Temp_recursion {
 #define EXCEPTION_HANDLED_PART_NAME "handled"          Request& frequest;
   public:
           Temp_recursion(Request& arequest) : frequest(arequest){
 // externs                  frequest.anti_endless_execute_recursion++;
           }
 extern const String main_method_name;          ~Temp_recursion(){
 extern const String auto_method_name;                  frequest.anti_endless_execute_recursion--;
           }
 extern const String exception_type_part_name;  };
 extern const String exception_source_part_name;  
 extern const String exception_comment_part_name;  
 extern const String exception_handled_part_name;  
   
 // defines for statics  
   
 #define MAIN_CLASS_NAME "MAIN"  
 #define AUTO_FILE_NAME "auto.p"  
   
 #endif  #endif

Removed from v.1.246  
changed lines
  Added in v.1.268


E-mail: