--- parser3/src/include/pa_file.h 2026/09/29 02:56:52 1.2 +++ parser3/src/include/pa_file.h 2026/11/03 16:04:19 1.8 @@ -8,7 +8,7 @@ #ifndef PA_FILE_H #define PA_FILE_H -#define IDENT_PA_FILE_H "$Id: pa_file.h,v 1.2 2026/09/29 02:56:52 moko Exp $" +#define IDENT_PA_FILE_H "$Id: pa_file.h,v 1.8 2026/11/03 16:04:19 moko Exp $" #include "pa_common.h" @@ -41,6 +41,7 @@ FILE *pa_fopen(const char *pathname, con #endif +/// the path should not be '/'-normalized yet, as \\server would become the web path //server #ifdef WIN32 bool is_os_absolute_path(const String& path); bool is_os_absolute_path(const char* path); @@ -53,15 +54,24 @@ inline bool is_os_absolute_path(const ch enum { PA_SCHEME_NONE=0, PA_SCHEME_FILE=1, PA_SCHEME_HTTP=2, PA_SCHEME_PARSER=4 }; enum { PA_ALLOW_HTTP=PA_SCHEME_HTTP, PA_ALLOW_ALL=PA_SCHEME_HTTP|PA_SCHEME_PARSER }; -/// scheme of a path: file://, http:// or parser://, PA_SCHEME_NONE otherwise +/// scheme of a not '/'-normalized path: file://, http:// or parser://, PA_SCHEME_NONE otherwise uint path_scheme(const String& path); -/// throws unless the scheme is allowed, file:// always is +/// false if the scheme is tainted +bool clean_path_scheme(uint scheme, const String& path); + +/// throws unless the scheme is allowed, file:// always is, or if the scheme is tainted void check_path_scheme(uint scheme, const String& path, uint allowed); -/// strips file://, 0 unless its authority is empty or localhost +/// resolved file:// or null; the result is not '/'-normalized const String* file_uri_to_path(const String& uri); +/// strncmp for disk paths, case insensitive under windows +int path_cmp(const char* path, const char* dir, size_t length); + +/// returns ", actual filename '...'" only if escaping changed the file name (exception source shows the original file) +const char* actual_filename(const String& file_spec, const char* fname); + #define FILE_BUFFER_SIZE (128*0x400) int pa_lock_shared_blocking(int fd); @@ -142,6 +152,9 @@ void file_write( // delete specified file; throws an exception in case of problems bool file_delete(const String& file_spec, bool fail_on_problem=true, bool keep_empty_dirs=false); +// delete specified empty directory; throws an exception in case of problems +bool dir_delete(const String& dir_spec, bool fail_on_problem=true); + // move specified file; throw an exception in case of problems void file_move(const String& old_spec, const String& new_spec, bool keep_empty_dirs=false);