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

1.34      paf         1: 
1.5       paf         2: /** @file
1.14      paf         3:        Parser: @b file parser type.
1.3       paf         4: 
1.43    ! misha       5:        Copyright(c) 2001-2009 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.43    ! misha       9: static const char * const IDENT_VFILE_C="$Date: 2009-01-12 07:18:31 $";
1.1       paf        10: 
1.37      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.37      paf        16: // externs
                     17: 
                     18: extern Methoded* file_class;
                     19: 
                     20: // defines for statics
                     21: 
                     22: #define SIZE_NAME "size"
                     23: #define TEXT_NAME "text"
                     24: 
                     25: // statics
                     26: 
                     27: static const String size_name(SIZE_NAME);
                     28: static const String text_name(TEXT_NAME);
                     29: 
                     30: // methods
                     31: 
                     32: VStateless_class *VFile::get_class() { return file_class; }
                     33: 
                     34: void VFile::set(
1.43    ! misha      35:                bool atainted, 
1.37      paf        36:                const char* avalue_ptr, size_t avalue_size,
                     37:                const char* afile_name_cstr,
                     38:                Value* acontent_type) {
1.8       paf        39:        fvalue_ptr=avalue_ptr;
                     40:        fvalue_size=avalue_size;
1.43    ! misha      41:        ftext_tainted=atainted;
1.8       paf        42: 
1.10      paf        43:        ffields.clear();
1.43    ! misha      44: 
1.3       paf        45:        // $name
1.14      paf        46:        char *lfile_name;
1.37      paf        47:        if(afile_name_cstr) {
                     48:                lfile_name=strdup(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.37      paf        55:        String& sfile_name=*new String;
                     56:        sfile_name.append_help_length(lfile_name, 0, String::L_FILE_SPEC);
                     57:        ffields.put(name_name, new VString(sfile_name));
1.43    ! misha      58: 
1.3       paf        59:        // $size
1.37      paf        60:        ffields.put(size_name, new VInt(fvalue_size));
1.43    ! misha      61: 
        !            62:        // $mime-type
        !            63:        if(acontent_type)
        !            64:                ffields.put(content_type_name, acontent_type);
        !            65: }
        !            66: 
        !            67: Value* VFile::get_element(const String& aname, Value& aself, bool looking_up) {
        !            68:        Value* result;
        !            69: 
        !            70:        // $method
        !            71:        if(result=VStateless_object::get_element(aname, aself, looking_up))
        !            72:                return result;
        !            73: 
        !            74:        // $field
        !            75:        if(result=ffields.get(aname))
        !            76:                return result;
        !            77: 
        !            78:        // $text - if not cached
        !            79:        if (aname == text_name && fvalue_ptr && fvalue_size){
        !            80:                // assigned file have ptr and we really have some bytes
1.42      misha      81: 
                     82:                const char *premature_zero_pos=(const char *)memchr(fvalue_ptr, 0, fvalue_size);
                     83:                size_t copy_size=premature_zero_pos?premature_zero_pos-fvalue_ptr:fvalue_size;
                     84: 
1.43    ! misha      85:                char *copy_ptr=0;
1.42      misha      86:                if(copy_size){
1.43    ! misha      87:                        copy_ptr=strdup(fvalue_ptr, copy_size);
1.29      paf        88:                        fix_line_breaks(copy_ptr, copy_size);
                     89:                }
1.42      misha      90: 
1.43    ! misha      91:                result=new VString(*new String(copy_ptr, ftext_tainted ? String::L_TAINTED : String::L_AS_IS));
        !            92:                ffields.put(text_name, result);
1.35      paf        93: 
                     94:                return result;
1.43    ! misha      95:        }
1.35      paf        96: 
1.43    ! misha      97:        return 0;
1.3       paf        98: }

E-mail: