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

1.34      paf         1: 
1.5       paf         2: /** @file
1.14      paf         3:        Parser: @b file parser type.
1.3       paf         4: 
1.36    ! 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    ! paf         9: static const char* IDENT_VFILE_C="$Date: 2002/11/25 14:10:53 $";
1.1       paf        10: 
                     11: #include "pa_vfile.h"
                     12: #include "pa_vstring.h"
1.3       paf        13: #include "pa_vint.h"
1.1       paf        14: 
1.13      paf        15: void VFile::set(bool tainted, 
                     16:                                const void *avalue_ptr, size_t avalue_size,
1.9       paf        17:                                const char *afile_name,
1.32      paf        18:                                Value *content_type) {
1.8       paf        19:        fvalue_ptr=avalue_ptr;
                     20:        fvalue_size=avalue_size;
                     21: 
1.33      paf        22:        const char *origin_file=afile_name?afile_name:"user (input type=file)";
1.15      paf        23: 
1.10      paf        24:        ffields.clear();
1.3       paf        25:        // $name
1.14      paf        26:        char *lfile_name;
1.10      paf        27:        if(afile_name) {
1.14      paf        28:                lfile_name=(char *)malloc(strlen(afile_name)+1);
1.10      paf        29:                strcpy(lfile_name, afile_name);
                     30:                if(char *after_slash=rsplit(lfile_name, '\\'))
                     31:                        lfile_name=after_slash;
                     32:                if(char *after_slash=rsplit(lfile_name, '/'))
                     33:                        lfile_name=after_slash;
1.14      paf        34:                
                     35:        } else
1.16      paf        36:                lfile_name=NONAME_DAT;
1.15      paf        37:        String& sfile_name=*NEW String(pool());
1.20      parser     38:        sfile_name.APPEND(lfile_name, 0, String::UL_FILE_SPEC, origin_file, 0);
1.15      paf        39:        ffields.put(*name_name, NEW VString(sfile_name));
1.3       paf        40:        // $size
1.10      paf        41:        ffields.put(*size_name, NEW VInt(pool(), fvalue_size));
1.3       paf        42:        // $text
1.29      paf        43:        if(fvalue_ptr && fvalue_size) { // assigned files don't have ptr, and we really have some bytes
1.14      paf        44:                String& text=*NEW String(pool());
                     45:                char *premature_zero_pos=(char *)memchr(fvalue_ptr, 0, fvalue_size);
1.29      paf        46:                if(premature_zero_pos!=fvalue_ptr) {
                     47:                        size_t copy_size=premature_zero_pos?premature_zero_pos-(char *)fvalue_ptr:fvalue_size;
                     48:                        char *copy_ptr=(char *)malloc(copy_size);
                     49:                        memcpy(copy_ptr, fvalue_ptr, copy_size);
                     50:                        fix_line_breaks(copy_ptr, copy_size);
                     51:                        text.APPEND(copy_ptr,  copy_size, 
1.28      paf        52:                                tainted? String::UL_TAINTED : String::UL_AS_IS,
1.18      parser     53:                                origin_file, 0);
1.29      paf        54:                }
1.14      paf        55:                ffields.put(*text_name, NEW VString(text));
                     56:        }
1.9       paf        57:        // $mime-type
1.32      paf        58:        if(content_type)
                     59:                ffields.put(*content_type_name, content_type);
1.35      paf        60: }
                     61: 
                     62: Value *VFile::get_element(const String& aname, Value& aself, bool looking_up) {
                     63:        // $method
                     64:        if(Value *result=VStateless_object::get_element(aname, aself, looking_up))
                     65:                return result;
                     66: 
                     67:        // $field
                     68:        return static_cast<Value *>(ffields.get(aname));
1.3       paf        69: }

E-mail: