Annotation of parser3/src/types/pa_vfile.C, revision 1.36.2.10.2.2

1.34      paf         1: 
1.5       paf         2: /** @file
1.14      paf         3:        Parser: @b file parser type.
1.3       paf         4: 
1.36.2.4  paf         5:        Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.26      paf         6:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.30      paf         7: */
1.3       paf         8: 
1.36.2.10.2.2! (paf        9:: static const char* IDENT_VFILE_C="$Date: 2003/03/18 15:14:21 $";
1.1       paf        10: 
1.36.2.2  paf        11: #include "classes.h"
1.1       paf        12: #include "pa_vfile.h"
                     13: #include "pa_vstring.h"
1.3       paf        14: #include "pa_vint.h"
1.1       paf        15: 
1.36.2.2  paf        16: // externs
                     17: 
1.36.2.10.2.2! (paf       18:: extern Methoded* file_class;
1.36.2.2  paf        19: 
1.36.2.5  paf        20: // defines for statics
                     21: 
1.36.2.1  paf        22: #define SIZE_NAME "size"
                     23: #define TEXT_NAME "text"
                     24: 
                     25: // statics
                     26: 
1.36.2.10.2.1  (paf       27:: static const String& size_name(new String(SIZE_NAME));
                     28:: static const String& text_name(new String(TEXT_NAME));
1.36.2.1  paf        29: 
                     30: // methods
1.36.2.2  paf        31: 
1.36.2.10.2.2! (paf       32:: VStateless_class *VFile::get_class() { return file_class; }
1.36.2.1  paf        33: 
1.36.2.10.2.1  (paf       34:: void VFile::set(
1.36.2.1  paf        35:                                bool tainted, 
1.36.2.9  paf        36:                                const char* avalue_ptr, size_t avalue_size,
1.36.2.8  paf        37:                                const char* afile_name_cstr,
1.36.2.10.2.2! (paf       38::                               Value* acontent_type) {
1.8       paf        39:        fvalue_ptr=avalue_ptr;
                     40:        fvalue_size=avalue_size;
                     41: 
1.36.2.8  paf        42:        const char* origin_file=afile_name_cstr?afile_name_cstr:"user (input type=file)";
1.15      paf        43: 
1.10      paf        44:        ffields.clear();
1.3       paf        45:        // $name
1.14      paf        46:        char *lfile_name;
1.36.2.8  paf        47:        if(afile_name_cstr) {
                     48:                lfile_name=pool.copy(afile_name_cstr);
1.10      paf        49:                if(char *after_slash=rsplit(lfile_name, '\\'))
                     50:                        lfile_name=after_slash;
                     51:                if(char *after_slash=rsplit(lfile_name, '/'))
                     52:                        lfile_name=after_slash;
1.14      paf        53:        } else
1.16      paf        54:                lfile_name=NONAME_DAT;
1.36.2.10.2.1  (paf       55::       const String& sfile_name(new String);
1.36.2.10.2.2! (paf       56::       sfile_name->APPEND(lfile_name, 0, String::L_FILE_SPEC, origin_file, 0);
        !            57::       ffields.put(name_name, Value*(new VString(sfile_name)));
1.3       paf        58:        // $size
1.36.2.10.2.2! (paf       59::       ffields.put(size_name, Value*(new VInt(fvalue_size)));
1.3       paf        60:        // $text
1.29      paf        61:        if(fvalue_ptr && fvalue_size) { // assigned files don't have ptr, and we really have some bytes
1.36.2.10.2.1  (paf       62::               const String& text(new String);
1.14      paf        63:                char *premature_zero_pos=(char *)memchr(fvalue_ptr, 0, fvalue_size);
1.29      paf        64:                if(premature_zero_pos!=fvalue_ptr) {
                     65:                        size_t copy_size=premature_zero_pos?premature_zero_pos-(char *)fvalue_ptr:fvalue_size;
1.36.2.10  paf        66:                        char *copy_ptr=pool.copy(fvalue_ptr, copy_size);
1.29      paf        67:                        fix_line_breaks(copy_ptr, copy_size);
1.36.2.1  paf        68:                        text->APPEND(copy_ptr,  copy_size, 
1.36.2.10.2.2! (paf       69::                               tainted? String::L_TAINTED : String::L_AS_IS,
1.18      parser     70:                                origin_file, 0);
1.29      paf        71:                }
1.36.2.10.2.2! (paf       72::               ffields.put(text_name, Value*(new VString(text)));
1.14      paf        73:        }
1.9       paf        74:        // $mime-type
1.36.2.1  paf        75:        if(acontent_type)
                     76:                ffields.put(content_type_name, acontent_type);
1.35      paf        77: }
                     78: 
1.36.2.10.2.2! (paf       79:: Value* VFile::get_element(const String& aname, Value& aself, bool looking_up) {
1.35      paf        80:        // $method
1.36.2.10.2.2! (paf       81::       if(Value* result=VStateless_object::get_element(aname, aself, looking_up))
1.35      paf        82:                return result;
                     83: 
                     84:        // $field
1.36.2.1  paf        85:        return ffields.get(aname);
1.3       paf        86: }

E-mail: