Annotation of parser3/src/main/pa_request.C, revision 1.175
1.54 paf 1: /** @file
1.55 paf 2: Parser: request class main part. @see compile.C and execute.C.
3:
1.9 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.156 parser 5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.55 paf 6:
1.175 ! paf 7: $Id: pa_request.C,v 1.174 2001/11/01 15:45:28 paf Exp $
1.1 paf 8: */
9:
1.70 paf 10: #include "pa_config_includes.h"
1.166 parser 11:
12: //#include "pcre.h"
13: //#include "internal.h"
14: extern "C" unsigned char pcre_default_tables[]; // pcre/chartables.c
15:
1.69 paf 16: #include "pa_sapi.h"
1.53 paf 17: #include "pa_common.h"
1.1 paf 18: #include "pa_request.h"
1.3 paf 19: #include "pa_wwrapper.h"
20: #include "pa_vclass.h"
1.31 paf 21: #include "pa_globals.h"
1.30 paf 22: #include "pa_vint.h"
1.112 paf 23: #include "pa_vmethod_frame.h"
1.32 paf 24: #include "pa_types.h"
1.78 paf 25: #include "pa_vtable.h"
1.90 paf 26: #include "pa_vfile.h"
1.147 parser 27: #include "pa_dictionary.h"
1.164 parser 28: #include "pa_charset_manager.h"
1.159 parser 29:
1.82 paf 30: /// content type of exception response, when no @MAIN:exception handler defined
31: const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain";
32:
33: /// content type of response when no $MAIN:defaults.content-type defined
34: const char *DEFAULT_CONTENT_TYPE="text/html";
1.144 parser 35: const char *ORIGINS_CONTENT_TYPE="text/plain";
1.82 paf 36:
1.123 paf 37: Methoded *MOP_create(Pool&);
38:
1.160 parser 39: static void load_charset(const Hash::Key& akey, Hash::Val *avalue,
1.158 parser 40: void *info) {
1.164 parser 41: Value& value=*static_cast<Value *>(avalue);
1.158 parser 42: Hash& CTYPE=*static_cast<Hash *>(info);
43:
1.164 parser 44: Charset_connection& connection=charset_manager->get_connection(akey, value.as_string());
1.158 parser 45:
1.159 parser 46: // charset->pcre_tables
1.164 parser 47: CTYPE.put(akey, connection.pcre_tables());
1.157 parser 48: }
49:
50: //
51: Request::Request(Pool& apool,
52: Info& ainfo,
53: String::Untaint_lang adefault_lang) : Pooled(apool),
54: stack(apool),
55: OP(*MOP_create(apool)),
56: env(apool),
1.175 ! paf 57: status(apool),
1.157 parser 58: form(apool),
59: math(apool),
60: request(apool, *this),
61: response(apool),
62: cookie(apool),
63: fclasses(apool),
1.158 parser 64: CTYPE(apool),
1.157 parser 65: fdefault_lang(adefault_lang), flang(adefault_lang),
66: info(ainfo),
67: post_data(0), post_size(0),
68: used_files(apool),
69: default_content_type(0),
70: mime_types(0),
71: main_class(0),
72: connection(0),
73: classes_conf(apool),
1.171 parser 74: anti_endless_execute_recoursion(0),
75: trace(apool)
1.157 parser 76: {
77: /// directly used
78: // operators
79: OP.register_directly_used(*this);
80: // classes:
81: // table, file, random, mail, image, ...
82: methoded_array->register_directly_used(*this);
83:
84: /// methodless
85: // env class
86: classes().put(*NEW String(pool(), ENV_CLASS_NAME), &env);
1.175 ! paf 87: // status class
! 88: classes().put(*NEW String(pool(), STATUS_CLASS_NAME), &status);
1.157 parser 89: // request class
90: classes().put(*NEW String(pool(), REQUEST_CLASS_NAME), &request);
91: // cookie class
92: classes().put(*NEW String(pool(), COOKIE_CLASS_NAME), &cookie);
93:
94: /// methoded
95: // response class
96: classes().put(response.get_class()->name(), &response);
97:
98: /// bases used
99: // form class
100: classes().put(form.get_class()->base()->name(), &form);
101: // math class
102: classes().put(math.get_class()->base()->name(), &math);
1.117 paf 103: }
1.150 parser 104:
1.64 paf 105: /**
106: load MAIN class, execute @main.
107: MAIN class consists of all the auto.p files we'd manage to find
108: plus
109: the file user requested us to process
110: all located classes become children of one another,
111: composing class we name 'MAIN'
112: */
1.153 parser 113: void Request::core(
114: const char *root_config_filespec, bool root_config_fail_on_read_problem,
115: const char *site_config_filespec, bool site_config_fail_on_read_problem,
1.62 paf 116: bool header_only) {
1.121 paf 117: //_asm { int 3 }
1.169 parser 118: try {
1.29 paf 119: char *auto_filespec=(char *)malloc(MAX_STRING);
120:
1.153 parser 121: // loading root config
122: if(root_config_filespec) {
1.77 paf 123: String& filespec=*NEW String(pool());
1.153 parser 124: filespec.APPEND_CLEAN(root_config_filespec, 0, "root_config", 0);
1.29 paf 125: main_class=use_file(
1.148 parser 126: filespec,
1.153 parser 127: true/*ignore class_path*/, root_config_fail_on_read_problem,
1.37 paf 128: main_class_name, main_class);
1.29 paf 129: }
130:
1.164 parser 131: if(main_class) {
132: /* $MAIN:CHARSETS[
133: $.charsetname1[/full/path/to/charset/file.cfg]
134: ...
135: ]
136: */
137: if(Value *vcharsets=main_class->get_element(*charsets_name)) {
1.172 parser 138: if(Hash *charsets=vcharsets->get_hash(0))
1.164 parser 139: charsets->for_each(load_charset, &CTYPE);
140: else
1.169 parser 141: throw Exception(0, 0,
1.164 parser 142: &vcharsets->name(),
143: "must be hash");
144: }
145: }
146:
1.124 paf 147: // configure root options
1.72 paf 148: // until someone with less privileges have overriden them
1.129 paf 149: OP.configure_admin(*this);
1.124 paf 150: methoded_array->configure_admin(*this);
1.72 paf 151:
1.153 parser 152: // loading site config
153: if(site_config_filespec) {
1.77 paf 154: String& filespec=*NEW String(pool());
1.153 parser 155: filespec.APPEND_CLEAN(site_config_filespec, 0, "site_config", 0);
1.37 paf 156: main_class=use_file(
1.148 parser 157: filespec,
1.153 parser 158: true/*ignore class_path*/, site_config_fail_on_read_problem,
1.37 paf 159: main_class_name, main_class);
1.29 paf 160: }
1.8 paf 161:
1.72 paf 162: // loading auto.p files from document_root/..
163: // to the one beside requested file.
164: // all assigned bases from upper dir
165: {
1.115 paf 166: const char *after=info.path_translated;
167: size_t drlen=strlen(info.document_root);
168: if(memcmp(after, info.document_root, drlen)==0) {
169: after+=drlen;
170: if(after[-1]=='/')
171: --after;
172: }
173:
1.152 parser 174: int step=0;
1.115 paf 175: while(const char *before=strchr(after, '/')) {
1.152 parser 176: String& sfile_spec=*NEW String(pool());
1.115 paf 177: if(after!=info.path_translated) {
1.152 parser 178: sfile_spec.APPEND_CLEAN(
179: info.path_translated, before-info.path_translated,
180: "path-translated-scanned", step++);
181: sfile_spec << "/" AUTO_FILE_NAME;
182:
183: main_class=use_file(sfile_spec,
184: true/*ignore class_path*/, false/*ignore read problem*/,
185: main_class_name, main_class);
1.115 paf 186: }
187: after=before+1;
1.72 paf 188: }
189: }
1.34 paf 190:
1.125 paf 191: // compile requested file
1.77 paf 192: String& spath_translated=*NEW String(pool());
1.136 parser 193: spath_translated.APPEND_TAINTED(info.path_translated, 0, "user-request", 0);
1.148 parser 194: main_class=use_file(spath_translated,
195: true/*ignore class_path*/, true/*don't ignore read problem*/,
1.72 paf 196: main_class_name, main_class);
1.7 paf 197:
1.124 paf 198: // configure not-root=user options
1.129 paf 199: OP.configure_user(*this);
1.124 paf 200: methoded_array->configure_user(*this);
201:
1.85 paf 202: // $MAIN:DEFAULTS
1.78 paf 203: Value *defaults=main_class->get_element(*defaults_name);
1.75 paf 204: // value must be allocated on request's pool for that pool used on
205: // meaning constructing @see attributed_meaning_to_string
1.80 paf 206: default_content_type=defaults?defaults->get_element(*content_type_name):0;
1.155 parser 207: // record default charset
1.154 parser 208: if(default_content_type)
1.172 parser 209: if(Hash *hash=default_content_type->get_hash(0))
1.154 parser 210: if(Value *vcharset=(Value *)hash->get(*charset_name))
211: pool().set_charset(vcharset->as_string());
212:
1.117 paf 213: if(Value *element=main_class->get_element(*user_html_name))
1.87 paf 214: if(Table *table=element->get_table())
1.147 parser 215: pool().set_tag(NEW Dictionary(*table));
1.85 paf 216:
217: // $MAIN:MIME-TYPES
218: if(Value *element=main_class->get_element(*mime_types_name))
219: if(Table *table=element->get_table())
220: mime_types=table;
1.102 paf 221:
1.124 paf 222: // filling form fields
1.153 parser 223: form.fill_fields_and_tables(*this);
1.102 paf 224:
1.124 paf 225: // filling cookies
226: cookie.fill_fields(*this);
1.25 paf 227:
228: // execute @main[]
1.143 parser 229: const String *body_string=execute_virtual_method(
230: *main_class, *main_method_name);
1.41 paf 231: if(!body_string)
1.169 parser 232: throw Exception(0,0,
1.145 parser 233: 0,
234: "'"MAIN_METHOD_NAME"' method not found");
1.79 paf 235:
1.91 paf 236: VString body_vstring_before_post_process(*body_string);
237: VString *body_vstring_after_post_process=&body_vstring_before_post_process;
238:
1.119 paf 239: // @postprocess
1.91 paf 240: if(Value *value=main_class->get_element(*post_process_method_name))
241: if(Junction *junction=value->get_junction())
242: if(const Method *method=junction->method) {
243: // preparing to pass parameters to
1.119 paf 244: // @postprocess[data]
1.146 parser 245: VMethodFrame frame(pool(), value->name(), *junction);
1.91 paf 246: frame.set_self(*main_class);
247:
248: frame.store_param(method->name,
249: &body_vstring_before_post_process);
250: body_vstring_after_post_process=
251: NEW VString(*execute_method(frame, *method));
252: }
1.90 paf 253:
1.144 parser 254: bool origins_mode=main_class->get_element(*origins_mode_name)!=0;
255:
256: const VFile *body_file=body_vstring_after_post_process->as_vfile(
257: String::UL_UNSPECIFIED, origins_mode);
1.41 paf 258:
1.45 paf 259: // extract response body
260: Value *body_value=static_cast<Value *>(
261: response.fields().get(*body_name));
1.119 paf 262: if(body_value) // there is some $response.body
1.90 paf 263: body_file=body_value->as_vfile();
1.144 parser 264: else if(origins_mode)
265: response.fields().put(*content_type_name,
266: NEW VString(*NEW String(pool(), ORIGINS_CONTENT_TYPE)));
1.45 paf 267:
268: // OK. write out the result
1.90 paf 269: output_result(*body_file, header_only);
1.171 parser 270: } catch(const Exception& e) { // request handling problem
1.76 paf 271: // we're returning not result, but error explanation
1.169 parser 272: try {
1.76 paf 273: // log the beast
274: const String *problem_source=e.problem_source();
1.114 paf 275: if(problem_source && problem_source->size())
1.76 paf 276: SAPI::log(pool(),
277: #ifndef NO_STRING_ORIGIN
278: "%s(%d): "
279: #endif
280: "'%s' %s [%s %s]",
281: #ifndef NO_STRING_ORIGIN
282: problem_source->origin().file?problem_source->origin().file:"global",
283: problem_source->origin().line,
284: #endif
1.173 paf 285: problem_source->cstr(),
1.76 paf 286: e.comment(),
1.173 paf 287: e.type()?e.type()->cstr():"-",
288: e.code()?e.code()->cstr():"-"
1.76 paf 289: );
290: else
291: SAPI::log(pool(),
292: "%s [%s %s]",
293: e.comment(),
1.173 paf 294: e.type()?e.type()->cstr():"-",
295: e.code()?e.code()->cstr():"-"
1.76 paf 296: );
1.43 paf 297:
1.171 parser 298: /// @test log stack trace
299:
1.43 paf 300: // reset language to default
301: flang=fdefault_lang;
1.135 parser 302: if(flang==String::UL_USER_HTML)
1.137 parser 303: flang=String::UL_HTML; // no _ & Co conversions in @exception[params]
1.43 paf 304:
305: // reset response
306: response.fields().clear();
307:
308: // this is what we'd return in $response:body
1.41 paf 309: const String *body_string=0;
1.43 paf 310:
1.30 paf 311: if(main_class) { // we've managed to end up with some main_class
312: // maybe we'd be lucky enough as to report an error
313: // in a gracefull way...
314: if(Value *value=main_class->get_element(*exception_method_name))
315: if(Junction *junction=value->get_junction())
316: if(const Method *method=junction->method) {
1.169 parser 317: // preparing to pass parameters to
1.171 parser 318: // @exception[origin;source;comment;type;code;stack]
1.146 parser 319: VMethodFrame frame(pool(), value->name(), *junction);
1.38 paf 320: frame.set_self(*main_class);
1.30 paf 321:
322: const String *problem_source=e.problem_source();
323: // origin
1.38 paf 324: Value *origin_value=0;
1.30 paf 325: #ifndef NO_STRING_ORIGIN
1.114 paf 326: if(problem_source && problem_source->size()) {
1.38 paf 327: const Origin& origin=problem_source->origin();
328: if(origin.file) {
329: char *buf=(char *)malloc(MAX_STRING);
1.168 parser 330: size_t buf_size=snprintf(buf, MAX_STRING, "%s(%d)",
1.38 paf 331: origin.file, 1+origin.line);
1.171 parser 332: origin_value=NEW VString(*NEW String(pool(),
333: buf, buf_size, true));
1.38 paf 334: }
1.30 paf 335: }
336: #endif
1.91 paf 337: frame.store_param(method->name,
1.138 parser 338: origin_value?origin_value:NEW VVoid(pool()));
1.28 paf 339:
1.30 paf 340: // source
1.38 paf 341: Value *source_value=0;
1.114 paf 342: if(problem_source && problem_source->size()) {
1.47 paf 343: String& problem_source_copy=*NEW String(pool());
344: problem_source_copy.append(*problem_source,
345: flang, true);
1.43 paf 346: source_value=NEW VString(problem_source_copy);
347: }
1.91 paf 348: frame.store_param(method->name,
1.138 parser 349: source_value?source_value:NEW VVoid(pool()));
1.30 paf 350:
351: // comment
1.44 paf 352: String *comment_value=NEW String(pool(),
1.106 paf 353: e.comment(), 0, true);
1.91 paf 354: frame.store_param(method->name,
1.30 paf 355: NEW VString(*comment_value));
356:
357: // type
358: Value *type_value;
1.43 paf 359: if(e.type()) {
1.47 paf 360: String& type_copy=*NEW String(pool());
361: type_value=NEW VString(type_copy.append(*e.type(),
362: flang, true));
1.43 paf 363: } else
1.138 parser 364: type_value=NEW VVoid(pool());
1.91 paf 365: frame.store_param(method->name, type_value);
1.30 paf 366:
367: // code
368: Value *code_value;
1.43 paf 369: if(e.code()) {
1.47 paf 370: String& code_copy=*NEW String(pool());
371: code_value=NEW VString(code_copy.append(*e.code(),
372: flang, true));
1.43 paf 373: } else
1.138 parser 374: code_value=NEW VVoid(pool());
1.91 paf 375: frame.store_param(method->name, code_value);
1.30 paf 376:
1.171 parser 377: // $stack[^table::set{name origin}]
378: Array& stack_trace_columns=*NEW Array(pool());
379: stack_trace_columns+=NEW String(pool(), "name");
380: stack_trace_columns+=NEW String(pool(), "origin");
381: Table& stack_trace=*NEW Table(pool(), 0, &stack_trace_columns);
382: Array_iter tracei(trace);
383: while(tracei.has_next()) {
384: Array& row=*NEW Array(pool());
385:
386: const String *name=(const String *)tracei.next();
387: row+=name; // name column
388: #ifndef NO_STRING_ORIGIN
389: const Origin& origin=name->origin();
390: if(origin.file) {
391: char *buf=(char *)malloc(MAX_STRING);
392: size_t buf_size=snprintf(buf, MAX_STRING, "%s(%d)",
393: origin.file, 1+origin.line);
394: row+=NEW String(pool(), buf, buf_size, true); // origin column
395: }
396: #endif
397: stack_trace+=&row;
398: }
399: frame.store_param(method->name,
400: NEW VTable(pool(), &stack_trace));
401:
1.43 paf 402: // future $response:body=
1.171 parser 403: // execute ^exception[origin;source;comment;type;code;stack]
1.43 paf 404: body_string=execute_method(frame, *method);
1.30 paf 405: }
406: }
407:
1.41 paf 408: if(!body_string) { // couldn't report an error beautifully?
409: // doing that ugly
410:
411: // make up result: $origin $source $comment $type $code
412: char *buf=(char *)malloc(MAX_STRING);
1.30 paf 413: size_t printed=0;
414: const String *problem_source=e.problem_source();
415: if(problem_source) {
1.16 paf 416: #ifndef NO_STRING_ORIGIN
1.30 paf 417: const Origin& origin=problem_source->origin();
418: if(origin.file)
1.41 paf 419: printed+=snprintf(buf+printed, MAX_STRING-printed, "%s(%d): ",
1.30 paf 420: origin.file, 1+origin.line);
1.28 paf 421: #endif
1.41 paf 422: printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ",
1.173 paf 423: problem_source->cstr());
1.30 paf 424: }
1.41 paf 425: printed+=snprintf(buf+printed, MAX_STRING-printed, "%s",
1.30 paf 426: e.comment());
427: const String *type=e.type();
428: if(type) {
1.41 paf 429: printed+=snprintf(buf+printed, MAX_STRING-printed, " type: %s",
1.173 paf 430: type->cstr());
1.30 paf 431: const String *code=e.code();
432: if(code)
1.41 paf 433: printed+=snprintf(buf+printed, MAX_STRING-printed, ", code: %s",
1.173 paf 434: code->cstr());
1.30 paf 435: }
1.43 paf 436:
437: // future $response:content-type
1.49 paf 438: response.fields().put(*content_type_name,
1.82 paf 439: NEW VString(*NEW String(pool(), UNHANDLED_EXCEPTION_CONTENT_TYPE)));
1.43 paf 440: // future $response:body
1.44 paf 441: body_string=NEW String(pool(), buf);
1.30 paf 442: }
1.41 paf 443:
1.144 parser 444: VString body_vstring(*body_string);
1.90 paf 445: const VFile *body_file=body_vstring.as_vfile();
446:
1.45 paf 447: // ERROR. write it out
1.90 paf 448: output_result(*body_file, header_only);
1.170 parser 449: } catch(const Exception& ) {
1.169 parser 450: /*re*/throw;
1.3 paf 451: }
1.1 paf 452: }
453: }
454:
1.148 parser 455: VStateless_class *Request::use_file(const String& file_name,
456: bool ignore_class_path, bool fail_on_read_problem,
1.26 paf 457: const String *name,
458: VStateless_class *base_class) {
1.73 paf 459: // cyclic dependence check
1.148 parser 460: if(used_files.get(file_name))
1.73 paf 461: return base_class;
1.148 parser 462: used_files.put(file_name, (Hash::Val *)true);
1.73 paf 463:
1.148 parser 464: const String *file_spec;
1.153 parser 465: if(ignore_class_path) // ignore_class_path?
1.148 parser 466: file_spec=&file_name;
1.153 parser 467: else if(file_name.first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH?
468: file_spec=&absolute(file_name);
469: else {
470: file_spec=0;
471: if(main_class)
472: if(Value *element=main_class->get_element(*class_path_name)) {
473: if(element->is_string()) {
474: file_spec=file_readable(element->as_string(), file_name); // found at class_path?
475: } else if(Table *table=element->get_table()) {
476: int size=table->size();
477: for(int i=size; i--; ) {
478: const String& path=*static_cast<Array *>(table->get(i))->get_string(0);
479: if(file_spec=file_readable(path, file_name))
480: break; // found along class_path
1.148 parser 481: }
1.153 parser 482: } else
1.169 parser 483: throw Exception(0, 0,
1.153 parser 484: &element->name(),
485: "must be string or table");
486: if(!file_spec)
1.169 parser 487: throw Exception(0, 0,
1.153 parser 488: &file_name,
489: "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME);
490: }
491: if(!file_spec)
1.169 parser 492: throw Exception(0, 0,
1.153 parser 493: &file_name,
494: "usage failed - no " MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified");
1.148 parser 495: }
1.73 paf 496:
1.148 parser 497: char *source=file_read_text(pool(), *file_spec, fail_on_read_problem);
1.3 paf 498: if(!source)
1.12 paf 499: return base_class;
1.3 paf 500:
1.148 parser 501: return use_buf(source, file_spec->cstr(), 0/*new class*/, name, base_class);
1.16 paf 502: }
503:
1.67 paf 504: VStateless_class *Request::use_buf(const char *source, const char *file,
1.26 paf 505: VStateless_class *aclass, const String *name,
506: VStateless_class *base_class) {
1.5 paf 507: // compile loaded class
1.26 paf 508: VStateless_class& cclass=COMPILE(source, aclass, name, base_class, file);
1.1 paf 509:
1.4 paf 510: // locate and execute possible @auto[] static method
1.143 parser 511: execute_nonvirtual_method(cclass, *auto_method_name, false /*no result needed*/);
1.16 paf 512: return &cclass;
1.19 paf 513: }
514:
1.77 paf 515: const String& Request::relative(const char *apath, const String& relative_name) {
516: int lpath_buf_size=strlen(apath)+1;
517: char *lpath=(char *)malloc(lpath_buf_size);
518: memcpy(lpath, apath, lpath_buf_size);
1.120 paf 519: if(!rsplit(lpath, '/'))
520: strcpy(lpath, ".");
1.77 paf 521: String& result=*NEW String(pool(), lpath);
1.104 paf 522: result << "/" << relative_name;
1.19 paf 523: return result;
524: }
525:
1.77 paf 526: const String& Request::absolute(const String& relative_name) {
527: char *relative_name_cstr=relative_name.cstr();
528: if(relative_name_cstr[0]=='/') {
529: String& result=*NEW String(pool(), info.document_root);
1.104 paf 530: result << relative_name;
1.19 paf 531: return result;
532: } else
1.77 paf 533: return relative(info.path_translated, relative_name);
1.1 paf 534: }
1.45 paf 535:
1.101 paf 536: static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning,
537: void *info) {
538: String *attribute_to_exclude=static_cast<String *>(info);
539: if(aattribute==*attribute_to_exclude)
540: return;
541:
542: Value& lmeaning=*static_cast<Value *>(ameaning);
543: Pool& pool=lmeaning.pool();
544:
545: SAPI::add_header_attribute(pool,
1.173 paf 546: aattribute.cstr(),
1.101 paf 547: attributed_meaning_to_string(lmeaning, String::UL_HTTP_HEADER).cstr());
548: }
1.90 paf 549: void Request::output_result(const VFile& body_file, bool header_only) {
1.51 paf 550: // header: cookies
551: cookie.output_result();
552:
1.90 paf 553: // set content-type
554: if(String *body_file_content_type=static_cast<String *>(
555: body_file.fields().get(*vfile_mime_type_name))) {
556: // body file content type
557: response.fields().put(*content_type_name, body_file_content_type);
558: } else {
559: // default content type
560: response.fields().put_dont_replace(*content_type_name,
561: default_content_type?default_content_type
562: :NEW VString(*NEW String(pool(), DEFAULT_CONTENT_TYPE)));
1.92 paf 563: }
564:
565: // content-disposition
1.111 paf 566: if(VString *vfile_name=static_cast<VString *>(body_file.fields().get(*name_name)))
567: if(vfile_name->string()!=NONAME_DAT) {
568: VHash& vhash=*NEW VHash(pool());
1.174 paf 569: vhash.hash(0).put(*content_disposition_filename_name, vfile_name);
1.111 paf 570: response.fields().put(*content_disposition_name, &vhash);
571: }
1.49 paf 572:
1.62 paf 573: // prepare header: $response:fields without :body
1.73 paf 574: response.fields().for_each(add_header_attribute, /*excluding*/ body_name);
1.50 paf 575:
1.62 paf 576: // prepare...
1.90 paf 577: const void *body=body_file.value_ptr();
578: size_t content_length=body_file.value_size();
1.50 paf 579:
1.62 paf 580: // prepare header: content-length
1.65 paf 581: if(content_length) { // useful for redirecting [header "location: http://..."]
582: char content_length_cstr[MAX_NUMBER];
1.108 paf 583: snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length);
1.69 paf 584: SAPI::add_header_attribute(pool(), "content-length", content_length_cstr);
1.65 paf 585: }
1.62 paf 586:
587: // send header
1.69 paf 588: SAPI::send_header(pool());
1.71 paf 589:
1.62 paf 590: // send body
591: if(!header_only)
1.69 paf 592: SAPI::send_body(pool(), body, content_length);
1.50 paf 593: }
1.104 paf 594:
595: const String& Request::mime_type_of(const char *user_file_name_cstr) {
596: if(mime_types)
597: if(const char *cext=strrchr(user_file_name_cstr, '.')) {
598: String sext(pool(), ++cext);
599: if(mime_types->locate(0, sext))
600: if(const String *result=mime_types->item(1))
601: return *result;
602: else
1.169 parser 603: throw Exception(0, 0,
1.104 paf 604: mime_types->origin_string(),
605: "MIME-TYPE table column elements must not be empty");
606: }
607: return *NEW String(pool(), "application/octet-stream");
1.158 parser 608: }
609:
1.165 parser 610: const unsigned char *Request::pcre_tables() {
1.166 parser 611: if(unsigned char *result=(unsigned char *)CTYPE.get(pool().get_charset()))
612: return result;
613:
614: // this is not for pcre itself,
615: // it can do default, it's for string.lower&co
616: return pcre_default_tables;
1.133 parser 617: }
E-mail: