--- parser3/src/classes/file.C 2001/11/05 11:46:20 1.65 +++ parser3/src/classes/file.C 2002/04/18 10:50:59 1.80 @@ -1,10 +1,10 @@ /** @file Parser: @b file parser class. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) - $Id: file.C,v 1.65 2001/11/05 11:46:20 paf Exp $ + $Id: file.C,v 1.80 2002/04/18 10:50:59 paf Exp $ */ #include "pa_config_includes.h" @@ -20,13 +20,12 @@ #include "pa_vdate.h" #include "pa_dir.h" #include "pa_vtable.h" +#include "pa_charset.h" // consts // defines -#define FILE_CLASS_NAME "file" - #define TEXT_MODE_NAME "text" // class @@ -60,20 +59,18 @@ static void _save(Request& r, const Stri } static void _delete(Request& r, const String&, MethodParams *params) { - Pool& pool=r.pool(); Value& vfile_name=params->as_no_junction(0, "file name must not be code"); // unlink - file_delete(pool, r.absolute(vfile_name.as_string())); + file_delete(r.absolute(vfile_name.as_string())); } static void _move(Request& r, const String&, MethodParams *params) { - Pool& pool=r.pool(); Value& vfrom_file_name=params->as_no_junction(0, "from file name must not be code"); Value& vto_file_name=params->as_no_junction(1, "to file name must not be code"); // move - file_move(pool, + file_move( r.absolute(vfrom_file_name.as_string()), r.absolute(vto_file_name.as_string())); } @@ -86,18 +83,18 @@ static void _find(Request& r, const Stri // passed file name simply exists in current dir if(file_readable(r.absolute(lfile_name))) { - r.write_no_lang(*new(pool) VString(lfile_name)); + r.write_no_lang(lfile_name); return; } // scan .. dirs for result for(int i=0; i(r.self); @@ -252,9 +250,9 @@ static void _exec_cgi(Request& r, const } if(pos<0) { delim_size=0; // calm down, compiler - throw Exception(0, 0, + throw Exception(0, &method_name, - "output does not contain CGI header; exit code=%d; outsize=%u; out: \"%s\"; errsize=%u; err: \"%s\"", + "output does not contain CGI header; exit status=%d; stdoutsize=%u; stdout: \"%s\"; stderrsize=%u; stderr: \"%s\"", status, (uint)out.size(), out.cstr(), (uint)err.size(), err.cstr()); @@ -311,10 +309,10 @@ static void _list(Request& r, const Stri int erroffset; regexp_code=pcre_compile(pattern, PCRE_EXTRA | PCRE_DOTALL, &errptr, &erroffset, - r.pcre_tables()); + pool.get_client_charset().pcre_tables); if(!regexp_code) - throw Exception(0, 0, + throw Exception(0, ®exp->mid(erroffset, regexp->size()), "regular expression syntax error - %s", errptr); @@ -342,7 +340,7 @@ static void _list(Request& r, const Stri suits=false; else if(exec_result<0) { (*pcre_free)(regexp_code); - throw Exception(0, 0, + throw Exception(0, regexp, "regular expression execute (%d)", exec_result); @@ -367,16 +365,32 @@ static void _list(Request& r, const Stri // write out result VTable& result=*new(pool) VTable(pool, &table); - result.set_name(method_name); r.write_no_lang(result); } -// constructor +#ifndef DOXYGEN +struct Lock_execute_body_info { + Request *r; + Value *body_code; +}; +#endif +static void lock_execute_body(int , void *context) { + Lock_execute_body_info& info=*static_cast(context); -MFile::MFile(Pool& apool) : Methoded(apool) { - set_name(*NEW String(pool(), FILE_CLASS_NAME)); + // execute body + info.r->write_assign_lang(info.r->process(*info.body_code)); +}; +static void _lock(Request& r, const String& method_name, MethodParams *params) { + const String& file_spec=r.absolute(params->as_string(0, "file name must be string")); + Value& body_code=params->as_junction(1, "body must be code"); + Lock_execute_body_info info={&r, &body_code}; + file_write_action_under_lock(file_spec, "lock", lock_execute_body, &info); +} +// constructor + +MFile::MFile(Pool& apool) : Methoded(apool, "file") { // ^save[mode;file-name] add_native_method("save", Method::CT_DYNAMIC, _save, 2, 2); @@ -411,6 +425,9 @@ MFile::MFile(Pool& apool) : Methoded(apo // ^file:list[path][regexp] add_native_method("list", Method::CT_STATIC, _list, 1, 2); + // ^file:lock[path]{code} + add_native_method("lock", Method::CT_STATIC, _lock, 2, 2); + } // global variable