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