|
|
| version 1.143.2.16, 2003/02/06 14:24:50 | version 1.143.2.21, 2003/03/04 14:55:37 |
|---|---|
| Line 153 char* file_read_text(Pool& pool, Charset | Line 153 char* file_read_text(Pool& pool, Charset |
| StringPtr file_spec, | StringPtr file_spec, |
| bool fail_on_read_problem, | bool fail_on_read_problem, |
| HashStringValue* params/*, HashStringValuePtr* out_fields*/) { | HashStringValue* params/*, HashStringValuePtr* out_fields*/) { |
| char *result; size_t size; | File_read_result file= |
| File_read_result file_read_result=file_read(pool, charset, file_spec, result, size, true, params, fail_on_read_problem); | file_read(pool, charset, file_spec, true, params, fail_on_read_problem); |
| /* | return file.success?file.data:0; |
| // they asked to return out_fields | |
| if(out_fields) | |
| *out_fields=file_read_result.fields; | |
| */ | |
| return file_read_result.success?result:0; | |
| } | } |
| //http request stuff | //http request stuff |
| Line 184 static int http_read_response(Pool& pool | Line 179 static int http_read_response(Pool& pool |
| int result=0; | int result=0; |
| ssize_t EOLat=0; | ssize_t EOLat=0; |
| while(true) { | while(true) { |
| char *buf=(char *)pool.malloc(MAX_STRING); | char *buf=new(pool) char[MAX_STRING]; |
| ssize_t size=recv(sock, buf, MAX_STRING, 0); | ssize_t size=recv(sock, buf, MAX_STRING, 0); |
| if(size<=0) | if(size<=0) |
| break; | break; |
| Line 305 static void http_pass_header(HashStringV | Line 300 static void http_pass_header(HashStringV |
| info->user_agent_specified=true; | info->user_agent_specified=true; |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| struct File_read_http_info { | struct File_read_http_result { |
| char **data; size_t *data_size; | char *data; size_t size; |
| HashStringValuePtr headers; | HashStringValuePtr headers; |
| }; | }; |
| #endif | #endif |
| static File_read_http_info file_read_http(Pool& pool, Charset& charset, StringPtr file_spec, | static File_read_http_result file_read_http(Pool& pool, Charset& charset, StringPtr file_spec, |
| HashStringValue *options=0) { | HashStringValue *options=0) { |
| File_read_http_info result; | File_read_http_result result; |
| char host[MAX_STRING]; | char host[MAX_STRING]; |
| const char* uri; | const char* uri; |
| int port; | int port; |
| Line 422 static File_read_http_info file_read_htt | Line 417 static File_read_http_info file_read_htt |
| } | } |
| // output response | // output response |
| *result.data=new(pool) char[*result.data_size=body->size()]; | result.data=new(pool) char[1/*as text puts terminating zero later*/+(result.size=body->size())]; |
| body->store_to(*result.data, String::UL_AS_IS); | body->store_to(result.data, String::UL_AS_IS); |
| result.headers->put(file_status_name, ValuePtr(new VInt(status_code))); | result.headers->put(file_status_name, ValuePtr(new VInt(status_code))); |
| return result; | return result; |
| } | } |
| Line 440 static void file_read_action(Pool& pool, | Line 435 static void file_read_action(Pool& pool, |
| void *context) { | void *context) { |
| File_read_action_info& info=*static_cast<File_read_action_info *>(context); | File_read_action_info& info=*static_cast<File_read_action_info *>(context); |
| if(size_t to_read_size=(size_t)finfo.st_size) { | if(size_t to_read_size=(size_t)finfo.st_size) { |
| *info.data=pool.malloc(to_read_size+(as_text?1:0)); | *info.data=new(pool) char[to_read_size+(as_text?1:0)]; |
| *info.data_size=(size_t)read(f, *info.data, to_read_size); | *info.data_size=(size_t)read(f, *info.data, to_read_size); |
| if(ssize_t(*info.data_size)<0 || *info.data_size>to_read_size) | if(ssize_t(*info.data_size)<0 || *info.data_size>to_read_size) |
| Line 450 static void file_read_action(Pool& pool, | Line 445 static void file_read_action(Pool& pool, |
| *info.data_size, to_read_size); | *info.data_size, to_read_size); |
| } else { // empty file | } else { // empty file |
| if(as_text) { | if(as_text) { |
| *info.data=pool.malloc(1); | *info.data=new(pool) char[1]; |
| *(char*)(*info.data)=0; | *(char*)(*info.data)=0; |
| } else | } else |
| *info.data=0; | *info.data=0; |
| Line 464 File_read_result file_read(Pool& pool, C | Line 459 File_read_result file_read(Pool& pool, C |
| File_read_result result; | File_read_result result; |
| if(file_spec->starts_with("http://", 7)) { | if(file_spec->starts_with("http://", 7)) { |
| // fail on read problem | // fail on read problem |
| result.headers=file_read_http(pool, charset, file_spec, params).headers; | File_read_http_result http=file_read_http(pool, charset, file_spec, params); |
| result.success=true; | result.success=true; |
| result.data=http.data; | |
| result.size=http.size; | |
| result.headers=http.headers; | |
| } else { | } else { |
| File_read_action_info info={&result.data, &result.data_size}; | File_read_action_info info={&result.data, &result.size}; |
| result.success=file_read_action_under_lock(pool, file_spec, | result.success=file_read_action_under_lock(pool, file_spec, |
| "read", file_read_action, &info, | "read", file_read_action, &info, |
| as_text, fail_on_read_problem); | as_text, fail_on_read_problem); |
| Line 475 File_read_result file_read(Pool& pool, C | Line 473 File_read_result file_read(Pool& pool, C |
| if(result.success && as_text) { | if(result.success && as_text) { |
| // UTF-8 signature: EF BB BF | // UTF-8 signature: EF BB BF |
| if(result.data_size>=3) { | if(result.size>=3) { |
| char *in=(char *)result.data; | char *in=(char *)result.data; |
| if((in[0] == '\xEF') && (in[1] == '\xBB') && | if((in[0] == '\xEF') && (in[1] == '\xBB') && |
| (in[2] == '\xBF')) { | (in[2] == '\xBF')) { |
| result.data=in+3; result.data_size-=3;// skip prefix | result.data=in+3; result.size-=3;// skip prefix |
| } | } |
| } | } |
| fix_line_breaks((char *)(result.data), result.data_size); | fix_line_breaks((char *)(result.data), result.size); |
| // note: after fixing | // note: after fixing |
| ((char*&)(result.data))[result.data_size]=0; | ((char*&)(result.data))[result.size]=0; |
| } | } |
| return result; | return result; |
| Line 614 bool file_write_action_under_lock( | Line 612 bool file_write_action_under_lock( |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| struct File_write_action_info { | struct File_write_action_info { |
| const void *data; size_t size; | const char *data; size_t size; |
| }; | }; |
| #endif | #endif |
| static void file_write_action(int f, void *context) { | static void file_write_action(int f, void *context) { |
| Line 629 static void file_write_action(int f, voi | Line 627 static void file_write_action(int f, voi |
| } | } |
| void file_write( | void file_write( |
| StringPtr file_spec, | StringPtr file_spec, |
| const void *data, size_t size, | const char *data, size_t size, |
| bool as_text, | bool as_text, |
| bool do_append) { | bool do_append) { |
| File_write_action_info info={data, size}; | File_write_action_info info={data, size}; |
| Line 716 bool file_readable(StringPtr file_spec) | Line 714 bool file_readable(StringPtr file_spec) |
| bool dir_readable(StringPtr file_spec) { | bool dir_readable(StringPtr file_spec) { |
| return entry_readable(file_spec, true); | return entry_readable(file_spec, true); |
| } | } |
| StringPtr file_readable(StringPtr path, const String& name) { | StringPtr file_readable(String& path, String& name) { |
| StringPtr result(new String(*path)); | StringPtr result(new String(path)); |
| *result << "/"; | *result << "/"; |
| *result << name; | *result << name; |
| return file_readable(result)?result:StringPtr(0); | return file_readable(result)?result:StringPtr(0); |
| Line 826 size_t stdout_write(const void *buf, siz | Line 824 size_t stdout_write(const void *buf, siz |
| } | } |
| char* unescape_chars(Pool& pool, const char* cp, int len) { | char* unescape_chars(Pool& pool, const char* cp, int len) { |
| char* s=pool.malloc(len + 1); | char* s=new(pool) char[len + 1]; |
| enum EscapeState { | enum EscapeState { |
| EscapeRest, | EscapeRest, |
| EscapeFirst, | EscapeFirst, |