--- parser3/src/include/pa_file.h 2026/09/27 17:14:23 1.1 +++ parser3/src/include/pa_file.h 2026/10/01 12:46:17 1.5 @@ -8,7 +8,7 @@ #ifndef PA_FILE_H #define PA_FILE_H -#define IDENT_PA_FILE_H "$Id: pa_file.h,v 1.1 2026/09/27 17:14:23 moko Exp $" +#define IDENT_PA_FILE_H "$Id: pa_file.h,v 1.5 2026/10/01 12:46:17 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); @@ -49,6 +50,22 @@ inline bool is_os_absolute_path(const St inline bool is_os_absolute_path(const char*) { return false; } #endif +/// recognized path scheme, also used as a bit mask of the schemes a caller allows +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 not '/'-normalized path: file://, http:// or parser://, PA_SCHEME_NONE otherwise +uint path_scheme(const String& path); + +/// 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); + +/// resolved file:// or null; the result is not '/'-normalized +const String* file_uri_to_path(const String& uri); + #define FILE_BUFFER_SIZE (128*0x400) int pa_lock_shared_blocking(int fd);