|
| 1 | +#ifndef PHP_STREAM_ERRORS_H |
| 2 | +#define PHP_STREAM_ERRORS_H |
| 3 | + |
| 4 | +#include "php.h" |
| 5 | +#include "php_streams.h" |
| 6 | + |
| 7 | +BEGIN_EXTERN_C() |
| 8 | + |
| 9 | +/* Error mode context options */ |
| 10 | +#define PHP_STREAM_ERROR_MODE_ERROR 0 |
| 11 | +#define PHP_STREAM_ERROR_MODE_EXCEPTION 1 |
| 12 | +#define PHP_STREAM_ERROR_MODE_SILENT 2 |
| 13 | + |
| 14 | +/* Error store context options */ |
| 15 | +#define PHP_STREAM_ERROR_STORE_AUTO 0 |
| 16 | +#define PHP_STREAM_ERROR_STORE_NONE 1 |
| 17 | +#define PHP_STREAM_ERROR_STORE_NON_TERM 2 |
| 18 | +#define PHP_STREAM_ERROR_STORE_TERMINAL 3 |
| 19 | +#define PHP_STREAM_ERROR_STORE_ALL 4 |
| 20 | + |
| 21 | +/* Error code definition for registration */ |
| 22 | +typedef struct { |
| 23 | + int code; |
| 24 | + const char *name; |
| 25 | +} php_stream_error_code_def; |
| 26 | + |
| 27 | +/* Stored error entry */ |
| 28 | +typedef struct { |
| 29 | + zend_string *message; |
| 30 | + int code; |
| 31 | + const char *wrapper_name; /* Points to wrapper->wops->label, no need to duplicate */ |
| 32 | + const char *param; /* Points to passed string, caller manages lifetime for storage */ |
| 33 | + int severity; |
| 34 | + bool terminal; |
| 35 | +} php_stream_error_entry; |
| 36 | + |
| 37 | +/* Sentinel for error code array termination */ |
| 38 | +#define PHP_STREAM_ERROR_CODE_END {0, NULL} |
| 39 | + |
| 40 | +/* Error code registration */ |
| 41 | +PHPAPI void php_stream_wrapper_register_error_codes( |
| 42 | + php_stream_wrapper *wrapper, |
| 43 | + const php_stream_error_code_def *codes |
| 44 | +); |
| 45 | + |
| 46 | +PHPAPI const char *php_stream_wrapper_get_error_name( |
| 47 | + php_stream_wrapper *wrapper, |
| 48 | + int code |
| 49 | +); |
| 50 | + |
| 51 | +/* Main error reporting functions */ |
| 52 | +PHPAPI void php_stream_wrapper_error( |
| 53 | + php_stream_wrapper *wrapper, |
| 54 | + php_stream_context *context, |
| 55 | + int options, |
| 56 | + int severity, |
| 57 | + bool terminal, |
| 58 | + int code, |
| 59 | + const char *fmt, |
| 60 | + ... |
| 61 | +) ZEND_ATTRIBUTE_FORMAT(printf, 7, 8); |
| 62 | + |
| 63 | +PHPAPI void php_stream_wrapper_error_param( |
| 64 | + php_stream_wrapper *wrapper, |
| 65 | + php_stream_context *context, |
| 66 | + int options, |
| 67 | + int severity, |
| 68 | + bool terminal, |
| 69 | + int code, |
| 70 | + const char *param, |
| 71 | + const char *fmt, |
| 72 | + ... |
| 73 | +) ZEND_ATTRIBUTE_FORMAT(printf, 8, 9); |
| 74 | + |
| 75 | +PHPAPI void php_stream_wrapper_error_param2( |
| 76 | + php_stream_wrapper *wrapper, |
| 77 | + php_stream_context *context, |
| 78 | + int options, |
| 79 | + int severity, |
| 80 | + bool terminal, |
| 81 | + int code, |
| 82 | + const char *param1, |
| 83 | + const char *param2, |
| 84 | + const char *fmt, |
| 85 | + ... |
| 86 | +) ZEND_ATTRIBUTE_FORMAT(printf, 9, 10); |
| 87 | + |
| 88 | +PHPAPI void php_stream_error( |
| 89 | + php_stream *stream, |
| 90 | + int severity, |
| 91 | + bool terminal, |
| 92 | + int code, |
| 93 | + const char *fmt, |
| 94 | + ... |
| 95 | +) ZEND_ATTRIBUTE_FORMAT(printf, 5, 6); |
| 96 | + |
| 97 | +/* Legacy wrapper error log - updated API */ |
| 98 | +PHPAPI void php_stream_wrapper_log_error( |
| 99 | + const php_stream_wrapper *wrapper, |
| 100 | + int options, |
| 101 | + int severity, |
| 102 | + bool terminal, |
| 103 | + int code, |
| 104 | + const char *fmt, |
| 105 | + ... |
| 106 | +) ZEND_ATTRIBUTE_FORMAT(printf, 6, 7); |
| 107 | + |
| 108 | +PHPAPI void php_stream_wrapper_log_error_param( |
| 109 | + const php_stream_wrapper *wrapper, |
| 110 | + int options, |
| 111 | + int severity, |
| 112 | + bool terminal, |
| 113 | + int code, |
| 114 | + const char *param, |
| 115 | + const char *fmt, |
| 116 | + ... |
| 117 | +) ZEND_ATTRIBUTE_FORMAT(printf, 7, 8); |
| 118 | + |
| 119 | +PHPAPI void php_stream_display_wrapper_errors( |
| 120 | + php_stream_wrapper *wrapper, |
| 121 | + const char *path, |
| 122 | + const char *caption |
| 123 | +); |
| 124 | + |
| 125 | +PHPAPI void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper); |
| 126 | + |
| 127 | +void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption); |
| 128 | +void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper); |
| 129 | + |
| 130 | +/* Convenience macros */ |
| 131 | +#define php_stream_wrapper_warn(wrapper, context, options, code, ...) \ |
| 132 | + php_stream_wrapper_error(wrapper, context, options, E_WARNING, true, code, __VA_ARGS__) |
| 133 | + |
| 134 | +#define php_stream_wrapper_warn_nt(wrapper, context, options, code, ...) \ |
| 135 | + php_stream_wrapper_error(wrapper, context, options, E_WARNING, false, code, __VA_ARGS__) |
| 136 | + |
| 137 | +#define php_stream_wrapper_notice(wrapper, context, options, code, ...) \ |
| 138 | + php_stream_wrapper_error(wrapper, context, options, E_NOTICE, false, code, __VA_ARGS__) |
| 139 | + |
| 140 | +#define php_stream_wrapper_warn_param(wrapper, context, options, code, param, ...) \ |
| 141 | + php_stream_wrapper_error_param(wrapper, context, options, E_WARNING, true, code, param, __VA_ARGS__) |
| 142 | + |
| 143 | +#define php_stream_warn(stream, code, ...) \ |
| 144 | + php_stream_error(stream, E_WARNING, true, code, __VA_ARGS__) |
| 145 | + |
| 146 | +#define php_stream_warn_nt(stream, code, ...) \ |
| 147 | + php_stream_error(stream, E_WARNING, false, code, __VA_ARGS__) |
| 148 | + |
| 149 | +#define php_stream_notice(stream, code, ...) \ |
| 150 | + php_stream_error(stream, E_NOTICE, false, code, __VA_ARGS__) |
| 151 | + |
| 152 | +#define php_stream_fatal(stream, code, ...) \ |
| 153 | + php_stream_error(stream, E_ERROR, true, code, __VA_ARGS__) |
| 154 | + |
| 155 | +/* Legacy log variants */ |
| 156 | +#define php_stream_wrapper_log_warn(wrapper, options, code, ...) \ |
| 157 | + php_stream_wrapper_log_error(wrapper, options, E_WARNING, true, code, __VA_ARGS__) |
| 158 | + |
| 159 | +#define php_stream_wrapper_log_warn_nt(wrapper, options, code, ...) \ |
| 160 | + php_stream_wrapper_log_error(wrapper, options, E_WARNING, false, code, __VA_ARGS__) |
| 161 | + |
| 162 | +#define php_stream_wrapper_log_notice(wrapper, options, code, ...) \ |
| 163 | + php_stream_wrapper_log_error(wrapper, options, E_NOTICE, false, code, __VA_ARGS__) |
| 164 | + |
| 165 | +END_EXTERN_C() |
| 166 | + |
| 167 | +#endif /* PHP_STREAM_ERRORS_H */ |
0 commit comments