--- parser3/src/include/pa_common.h 2019/11/22 23:11:24 1.179 +++ parser3/src/include/pa_common.h 2020/12/20 20:45:24 1.189 @@ -1,14 +1,14 @@ /** @file Parser: commonly used functions. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_COMMON_H #define PA_COMMON_H -#define IDENT_PA_COMMON_H "$Id: pa_common.h,v 1.179 2019/11/22 23:11:24 moko Exp $" +#define IDENT_PA_COMMON_H "$Id: pa_common.h,v 1.189 2020/12/20 20:45:24 moko Exp $" #include "pa_string.h" #include "pa_hash.h" @@ -20,7 +20,6 @@ class Request; #define HTTP_STATUS_CAPITALIZED "Status" #define HTTP_CONTENT_LENGTH "content-length" -#define HTTP_CONTENT_LENGTH_CAPITALIZED "Content-Length" #define HTTP_CONTENT_TYPE "content-type" #define HTTP_CONTENT_TYPE_UPPER "CONTENT-TYPE" @@ -82,6 +81,8 @@ int pa_stat(const char *pathname, struct int pa_open(const char *pathname, int flags, int mode=0); FILE *pa_fopen(const char *pathname, const char *mode); +#define pa_lseek _lseeki64 + #else #define pa_stat stat @@ -90,6 +91,8 @@ FILE *pa_fopen(const char *pathname, con #define pa_open open #define pa_fopen fopen +#define pa_lseek lseek + #endif /** @@ -141,19 +144,14 @@ struct File_read_result { if fail_on_read_problem is true[default] throws an exception */ -File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem = true, char* buf = 0, size_t offset = 0, size_t size = 0); +File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem = true, char* buf = 0, uint64_t offset = 0, size_t limit = 0); /** load specified file if fail_on_read_problem is true[default] throws an exception */ -File_read_result file_load(Request& r, - const String& file_spec, - bool as_text, - HashStringValue* options=0, - bool fail_on_read_problem=true, - size_t offset=0, size_t size=0, bool transcode_text_result=true); +File_read_result file_load(Request& r, const String& file_spec, bool as_text, HashStringValue* options=0, bool fail_on_read_problem=true, bool transcode_text_result=true); typedef void (*File_write_action)(int f, void *context); @@ -207,13 +205,13 @@ const String* file_exist(const String& p bool file_executable(const String& file_spec); bool file_stat(const String& file_spec, uint64_t& rsize, time_t& ratime, time_t& rmtime, time_t& rctime, bool fail_on_read_problem=true); -size_t check_file_size(uint64_t size, const String& file_spec); +size_t check_file_size(uint64_t size, const String* file_spec); size_t stdout_write(const void *buf, size_t size); void check_safe_mode(struct stat finfo, const String& file_spec, const char* fname); -int file_block_read(const int f, unsigned char* buffer, const size_t size); +ssize_t file_block_read(const int f, void* buffer, const size_t size); /** String related functions @@ -250,9 +248,14 @@ int remove_crlf(char *start, char *end); inline bool pa_isalpha(unsigned char c) { return (((c>='A') && (c<='Z')) || ((c>='a') && (c<='z'))); } inline bool pa_isalnum(unsigned char c) { return (((c>='0') && (c<='9')) || pa_isalpha(c)); } +char *pa_strcat(const char *a, const char *b, const char *c = 0); +const char *pa_filename(const char *path); + const char* capitalize(const char* s); -char *str_lower(const char *s, size_t helper_length=0); -char *str_upper(const char *s, size_t helper_length=0); +char *str_lower(const char *s, size_t length); +char *str_upper(const char *s, size_t length); +inline char *str_lower(const char *s) { return str_lower(s, strlen(s)); } +inline char *str_upper(const char *s) { return str_upper(s, strlen(s)); } const char* hex_string(unsigned char* bytes, size_t size, bool upcase); extern const char* hex_digits;