|
|
| version 1.127.2.22.2.27, 2003/04/03 10:48:24 | version 1.127.2.22.2.33, 2003/06/26 11:51:30 |
|---|---|
| Line 134 static void _taint(Request& r, MethodPar | Line 134 static void _taint(Request& r, MethodPar |
| static void _process(Request& r, MethodParams& params) { | static void _process(Request& r, MethodParams& params) { |
| Method* main_method; | Method* main_method; |
| Value& value=*params[0]; | |
| Value& target_self=params.count()>1? | size_t index=0; |
| params.as_no_junction(0, "target must not be code") | Value* target_self; |
| :r.get_method_frame()->caller()->self(); | Value& maybe_target_self=params[index]; |
| if(maybe_target_self.get_string() || maybe_target_self.get_junction()) | |
| target_self=&r.get_method_frame()->caller()->self(); | |
| else { | |
| target_self=&maybe_target_self; index++; | |
| } | |
| { | { |
| VStateless_class *target_class=target_self.get_last_derived_class(); | VStateless_class *target_class=target_self->get_last_derived_class(); |
| if(!target_class) | if(!target_class) |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| 0, | 0, |
| Line 153 static void _process(Request& r, MethodP | Line 158 static void _process(Request& r, MethodP |
| // temporary zero @auto so it wouldn't be auto-called in Request::use_buf | // temporary zero @auto so it wouldn't be auto-called in Request::use_buf |
| Temp_method temp_method_auto(*target_class, auto_method_name, 0); | Temp_method temp_method_auto(*target_class, auto_method_name, 0); |
| if(const String* file_name=params.last().get_string()) { // ^process...[file] | size_t main_alias_index=index+1; |
| r.use_file(*target_class, r.absolute(*file_name), true/*ignore_class_path*/); | const String* main_alias=0; |
| if(main_alias_index<params.count()) | |
| main_alias=¶ms.as_string(main_alias_index, "main alias must be string"); | |
| if(const String* file_name=params[index].get_string()) { // ^process...[file] | |
| r.use_file(*target_class, r.absolute(*file_name), main_alias, true/*ignore_class_path*/); | |
| } else { // process...{string} | } else { // process...{string} |
| Value& vjunction=params.as_junction(params.count()-1, "body must be code"); | Value& vjunction=params.as_junction(index, "body must be code"); |
| // evaluate source to process | // evaluate source to process |
| const String& source=r.process_to_string(vjunction); | const String& source=r.process_to_string(vjunction); |
| r.use_buf(*target_class, | r.use_buf(*target_class, |
| source.cstr(String::L_UNSPECIFIED, r.connection(false)), | source.cstr(String::L_UNSPECIFIED, r.connection(false)), |
| main_alias, | |
| pseudo_file_no__process); | pseudo_file_no__process); |
| } | } |
| Line 171 static void _process(Request& r, MethodP | Line 182 static void _process(Request& r, MethodP |
| // maybe-execute @main[] | // maybe-execute @main[] |
| if(main_method) { | if(main_method) { |
| // temporarily set method_frame's self to target_self | // temporarily set method_frame's self to target_self |
| Temp_method_frame_self tmfs(*r.get_method_frame(), target_self); | Temp_method_frame_self tmfs(*r.get_method_frame(), *target_self); |
| // execute! | // execute! |
| r.execute(*main_method->parser_code); | r.execute(*main_method->parser_code); |
| } | } |
| Line 214 static void _for(Request& r, MethodParam | Line 225 static void _for(Request& r, MethodParam |
| int from=params.as_int(1, "from must be int", r); | int from=params.as_int(1, "from must be int", r); |
| int to=params.as_int(2, "to must be int", r); | int to=params.as_int(2, "to must be int", r); |
| Value& body_code=params.as_junction(3, "body must be code"); | Value& body_code=params.as_junction(3, "body must be code"); |
| Value* delim_maybe_code=params.count()>4?params[4]:0; | Value* delim_maybe_code=params.count()>4?¶ms[4]:0; |
| if(to-from>=MAX_LOOPS) // too long loop? | if(to-from>=MAX_LOOPS) // too long loop? |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| Line 306 public: | Line 317 public: |
| }; | }; |
| #endif | #endif |
| static void _switch(Request& r, MethodParams& params) { | static void _switch(Request& r, MethodParams& params) { |
| Switch_data* data=new Switch_data(r, r.process_to_value(*params[0])); | Switch_data* data=new Switch_data(r, r.process_to_value(params[0])); |
| Temp_hash_value<const StringBody, PA_Object*> | Temp_hash_value<const StringBody, PA_Object*> |
| switch_data_setter(r.classes_conf, switch_data_name, data); | switch_data_setter(r.classes_conf, switch_data_name, data); |
| Line 336 static void _case(Request& r, MethodPara | Line 347 static void _case(Request& r, MethodPara |
| //code->get_junction()->change_context(0); | //code->get_junction()->change_context(0); |
| for(int i=0; i<count; i++) { | for(int i=0; i<count; i++) { |
| Value& value=r.process_to_value(*params[i]); | Value& value=r.process_to_value(params[i]); |
| if(value.as_string() == CASE_DEFAULT_VALUE) { | if(value.as_string() == CASE_DEFAULT_VALUE) { |
| data->_default=&code; | data->_default=&code; |
| Line 405 static void locked_process_and_cache_put | Line 416 static void locked_process_and_cache_put |
| // expiration time not spoiled by ^cache(0) or something? | // expiration time not spoiled by ^cache(0) or something? |
| if(info.data->expires > time(0)) { | if(info.data->expires > time(0)) { |
| // string -serialize> buffer | // string -serialize> buffer |
| String::C serialized=info.evaluated_body->serialize( | String::Cm serialized=info.evaluated_body->serialize( |
| sizeof(Data_string_serialized_prolog)); | sizeof(Data_string_serialized_prolog)); |
| Data_string_serialized_prolog& prolog= | Data_string_serialized_prolog& prolog= |
| *reinterpret_cast<Data_string_serialized_prolog *>(serialized.str); | *reinterpret_cast<Data_string_serialized_prolog *>(serialized.str); |
| Line 421 const String* locked_process_and_cache_p | Line 432 const String* locked_process_and_cache_p |
| Value& body_code, | Value& body_code, |
| Cache_data& data, | Cache_data& data, |
| const String& file_spec) { | const String& file_spec) { |
| Locked_process_and_cache_put_action_info info; | Locked_process_and_cache_put_action_info info={0}; |
| info.r=&r; | info.r=&r; |
| info.data=&data; | info.data=&data; |
| info.body_code=&body_code; | info.body_code=&body_code; |
| Line 438 const String* locked_process_and_cache_p | Line 449 const String* locked_process_and_cache_p |
| cache_delete(file_spec); | cache_delete(file_spec); |
| return result; | return result; |
| } | } |
| const String* cache_get(Charset& charset, const String& file_spec, time_t now) { | const String* cache_get(Request_charsets& charsets, const String& file_spec, time_t now) { |
| File_read_result file=file_read(charset, file_spec, | File_read_result file=file_read(charsets, file_spec, |
| false/*as_text*/, | false/*as_text*/, |
| 0, //no params | 0, //no params |
| false/*fail_on_read_problem*/); | false/*fail_on_read_problem*/); |
| Line 463 const String* cache_get(Charset& charset | Line 474 const String* cache_get(Charset& charset |
| static time_t as_expires(Request& r, MethodParams& params, | static time_t as_expires(Request& r, MethodParams& params, |
| int index, time_t now) { | int index, time_t now) { |
| time_t result; | time_t result; |
| if(Value* vdate=params[index]->as(VDATE_TYPE, false)) | if(Value* vdate=params[index].as(VDATE_TYPE, false)) |
| result=static_cast<VDate*>(vdate)->get_time(); | result=static_cast<VDate*>(vdate)->get_time(); |
| else | else |
| result=now+(time_t)params.as_double(index, "lifespan must be date or number", r); | result=now+(time_t)params.as_double(index, "lifespan must be date or number", r); |
| Line 478 static void _cache(Request& r, MethodPar | Line 489 static void _cache(Request& r, MethodPar |
| // ^cache[filename] ^cache(seconds) ^cache[expires date] | // ^cache[filename] ^cache(seconds) ^cache[expires date] |
| if(params.count()==1) { | if(params.count()==1) { |
| if(params[0]->is_string()) { // filename? | if(params[0].is_string()) { // filename? |
| cache_delete(as_file_spec(r, params, 0)); | cache_delete(as_file_spec(r, params, 0)); |
| return; | return; |
| } | } |
| Line 524 static void _cache(Request& r, MethodPar | Line 535 static void _cache(Request& r, MethodPar |
| // |lockSH succeeds; ... | // |lockSH succeeds; ... |
| for(int retry=0; retry<2; retry++) { | for(int retry=0; retry<2; retry++) { |
| if(const String* cached_body=cache_get(r.charsets.source(), file_spec, now)) { // have cached copy? | if(const String* cached_body=cache_get(r.charsets, file_spec, now)) { // have cached copy? |
| // write it out | // write it out |
| r.write_assign_lang(*cached_body); | r.write_assign_lang(*cached_body); |
| // happy with it | // happy with it |
| Line 573 static void _try_operator(Request& r, Me | Line 584 static void _try_operator(Request& r, Me |
| try { | try { |
| result=r.process(body_code); | result=r.process(body_code); |
| } catch(const Exception& e) { | } catch(const Exception& e) { |
| Request::Exception_details details=r.get_details(e); | |
| Request_context_saver throw_context(r); // taking snapshot of throw-context [stack trace contains error] | Request_context_saver throw_context(r); // taking snapshot of throw-context [stack trace contains error] |
| try_context.restore(); // restoring try-context to perform catch-code | try_context.restore(); // restoring try-context to perform catch-code |
| Request::Exception_details details=r.get_details(e); | |
| Junction* junction=catch_code.get_junction(); | Junction* junction=catch_code.get_junction(); |
| Value* method_frame=junction->method_frame; | Value* method_frame=junction->method_frame; |
| Value* saved_exception_var_value=method_frame->get_element(exception_var_name, *method_frame, false); | Value* saved_exception_var_value=method_frame->get_element(exception_var_name, *method_frame, false); |
| Line 600 static void _try_operator(Request& r, Me | Line 611 static void _try_operator(Request& r, Me |
| static void _throw_operator(Request& r, MethodParams& params) { | static void _throw_operator(Request& r, MethodParams& params) { |
| if(params.count()==1) { | if(params.count()==1) { |
| Value* param0=params[0]; | if(HashStringValue *hash=params[0].get_hash()) { |
| if(HashStringValue *hash=param0->get_hash()) { | |
| const char* type=0; | const char* type=0; |
| if(Value* value=hash->get(exception_type_part_name)) | if(Value* value=hash->get(exception_type_part_name)) |
| type=value->as_string().cstr(); | type=value->as_string().cstr(); |