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