Skip to content

Commit ba27e08

Browse files
committed
Merge branch 'PHP-5.4' of git.php.net:php-src into PHP-5.4
2 parents b4b3a65 + 5f22441 commit ba27e08

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

ext/standard/mail.c

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#endif
4040
#endif
4141

42+
#include "php_syslog.h"
4243
#include "php_mail.h"
4344
#include "php_ini.h"
4445
#include "php_string.h"
@@ -189,6 +190,37 @@ PHP_FUNCTION(mail)
189190
}
190191
/* }}} */
191192

193+
194+
void php_mail_log_crlf_to_spaces(char *message) {
195+
/* Find all instances of carriage returns or line feeds and
196+
* replace them with spaces. Thus, a log line is always one line
197+
* long
198+
*/
199+
char *p = message;
200+
while ((p = strpbrk(p, "\r\n"))) {
201+
*p = ' ';
202+
}
203+
}
204+
205+
void php_mail_log_to_syslog(char *message) {
206+
/* Write 'message' to syslog. */
207+
#ifdef HAVE_SYSLOG_H
208+
php_syslog(LOG_NOTICE, "%s", message);
209+
#endif
210+
}
211+
212+
213+
void php_mail_log_to_file(char *filename, char *message, size_t message_size TSRMLS_DC) {
214+
/* Write 'message' to the given file. */
215+
uint flags = IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR;
216+
php_stream *stream = php_stream_open_wrapper(filename, "a", flags, NULL);
217+
if (stream) {
218+
php_stream_write(stream, message, message_size);
219+
php_stream_close(stream);
220+
}
221+
}
222+
223+
192224
/* {{{ php_mail
193225
*/
194226
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
@@ -216,19 +248,22 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
216248
if (mail_log && *mail_log) {
217249
char *tmp;
218250
int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
219-
php_stream *stream = php_stream_open_wrapper(mail_log, "a", IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR, NULL);
220251

221-
if (hdr) { /* find all \r\n instances and replace them with spaces, so a log line is always one line long */
222-
char *p = tmp;
223-
while ((p = strpbrk(p, "\r\n"))) {
224-
*p = ' ';
225-
}
226-
tmp[l - 1] = '\n';
252+
if (hdr) {
253+
php_mail_log_crlf_to_spaces(tmp);
227254
}
228-
if (stream) {
229-
php_stream_write(stream, tmp, l);
230-
php_stream_close(stream);
255+
256+
if (!strcmp(mail_log, "syslog")) {
257+
/* Drop the final space when logging to syslog. */
258+
tmp[l - 1] = 0;
259+
php_mail_log_to_syslog(tmp);
260+
}
261+
else {
262+
/* Convert the final space to a newline when logging to file. */
263+
tmp[l - 1] = '\n';
264+
php_mail_log_to_file(mail_log, tmp, l TSRMLS_CC);
231265
}
266+
232267
efree(tmp);
233268
}
234269
if (PG(mail_x_header)) {

php.ini-development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,8 @@ mail.add_x_header = On
10201020
; The path to a log file that will log all mail() calls. Log entries include
10211021
; the full path of the script, line number, To address and headers.
10221022
;mail.log =
1023+
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
1024+
;mail.log = syslog
10231025

10241026
[SQL]
10251027
; http://php.net/sql.safe-mode

php.ini-production

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,8 @@ mail.add_x_header = On
10201020
; The path to a log file that will log all mail() calls. Log entries include
10211021
; the full path of the script, line number, To address and headers.
10221022
;mail.log =
1023+
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
1024+
;mail.log = syslog
10231025

10241026
[SQL]
10251027
; http://php.net/sql.safe-mode

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,19 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
455455

456456
#endif
457457

458-
int fpm_socket_unix_test_connect(struct sockaddr_un *sun, size_t socklen) /* {{{ */
458+
int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */
459459
{
460460
int fd;
461461

462-
if (!sun || sun->sun_family != AF_UNIX) {
462+
if (!sock || sock->sun_family != AF_UNIX) {
463463
return -1;
464464
}
465465

466466
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
467467
return -1;
468468
}
469469

470-
if (connect(fd, (struct sockaddr *)sun, socklen) == -1) {
470+
if (connect(fd, (struct sockaddr *)sock, socklen) == -1) {
471471
return -1;
472472
}
473473

0 commit comments

Comments
 (0)