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