- if (SUCCESS != http_send_status_header(status, header)) {
- http_error_ex(E_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : "");
- if (free_header && header) {
- efree(header);
- }
+ time_t now;
+ struct tm nowtm;
+ char datetime[128];
+
+ HTTP_CHECK_OPEN_BASEDIR(file, return);
+
+ time(&now);
+ strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
+
+#define HTTP_LOG_WRITE(file, type, msg) \
+ if (file && *file) { \
+ php_stream *log = php_stream_open_wrapper(file, "ab", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL); \
+ \
+ if (log) { \
+ php_stream_printf(log TSRMLS_CC, "%s\t[%s]\t%s\t<%s>%s", datetime, type, msg, SG(request_info).request_uri, PHP_EOL); \
+ php_stream_close(log); \
+ } \
+ \
+ }
+
+ HTTP_LOG_WRITE(file, ident, message);
+ HTTP_LOG_WRITE(HTTP_G(log).composite, ident, message);
+}
+/* }}} */
+
+static void http_ob_blackhole(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
+{
+ *handled_output = ecalloc(1,1);
+ *handled_output_len = 0;
+}
+
+/* {{{ STATUS http_exit(int, char*, char*) */
+STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC)
+{
+ if ( (send_header && (SUCCESS != http_send_status_header(status, header))) ||
+ (!send_header && status && (SUCCESS != http_send_status(status)))) {
+ http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : "");
+ STR_FREE(header);
+ STR_FREE(body);