#include "phpdbg_list.h"
#include "phpdbg_utils.h"
#include "phpdbg_set.h"
+#include "phpdbg_io.h"
#include "zend_alloc.h"
/* {{{ remote console headers */
}
/* don't inline this, want to debug it easily, will inline when done */
-static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream) {
+static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream TSRMLS_DC) {
phpdbg_remote_close(*socket, *stream);
if (server < 0) {
/* setup remote server if necessary */
if (!cleaning && listen > 0) {
- server = phpdbg_open_socket(address, listen);
- if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) {
+ server = phpdbg_open_socket(address, listen TSRMLS_CC);
+ if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream TSRMLS_CC) == FAILURE) {
exit(0);
}
if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
/* renegociate connections */
- phpdbg_remote_init(address, listen, server, &socket, &stream);
+ phpdbg_remote_init(address, listen, server, &socket, &stream TSRMLS_CC);
/* set streams */
if (stream) {
#include "zend_ini_scanner.h"
#include "zend_stream.h"
#ifndef _WIN32
-# include "zend_signal.h"
+# include "zend_signal.h"
#endif
#include "SAPI.h"
#include <fcntl.h>
#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__)
-# include <windows.h>
-# include "config.w32.h"
-# undef strcasecmp
-# undef strncasecmp
-# define strcasecmp _stricmp
-# define strncasecmp _strnicmp
+# include <windows.h>
+# include "config.w32.h"
+# undef strcasecmp
+# undef strncasecmp
+# define strcasecmp _stricmp
+# define strncasecmp _strnicmp
#else
-# include "php_config.h"
+# include "php_config.h"
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifdef HAVE_LIBREADLINE
-# include <readline/readline.h>
-# include <readline/history.h>
+# include <readline/readline.h>
+# include <readline/history.h>
#endif
#ifdef HAVE_LIBEDIT
-# include <editline/readline.h>
+# include <editline/readline.h>
#endif
/* {{{ remote console headers */
# include <sys/un.h>
# include <sys/select.h>
# include <sys/types.h>
+# include <netdb.h>
#endif /* }}} */
/* {{{ strings */
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-PHPDBG_API int
-phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo)
-{/*{{{*/
+PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo TSRMLS_DC) {
int got_now, i = len, j;
char *p = ptr;
#ifndef PHP_WIN32
struct pollfd pfd;
- TSRMLS_FETCH();
if (tmo < 0) goto recv_once;
pfd.fd = sock;
#else
struct fd_set readfds;
struct timeval ttmo;
- TSRMLS_FETCH();
if (tmo < 0) goto recv_once;
FD_ZERO(&readfds);
}
return p - ptr;
-}/*}}}*/
+}
-PHPDBG_API int
-phpdbg_send_bytes(int sock, char *ptr, int len)
-{/*{{{*/
+PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len) {
int sent, i = len;
char *p = ptr;
/* XXX poll/select needed here? */
}
return len;
-}/*}}}*/
+}
-PHPDBG_API int
-phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC)
-{/*{{{*/
+PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC) {
if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
- return phpdbg_consume_bytes(sock, ptr, len, tmo);
+ return phpdbg_consume_bytes(sock, ptr, len, tmo TSRMLS_CC);
}
return read(sock, ptr, len);
-}/*}}}*/
+}
-PHPDBG_API int
-phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC)
-{/*{{{*/
+PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC) {
if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
return phpdbg_send_bytes(sock, ptr, len);
}
return write(sock, ptr, len);
-}/*}}}*/
+}
-PHPDBG_API int
-phpdbg_open_socket(const char *interface, short port) /* {{{ */
-{
+PHPDBG_API int phpdbg_open_socket(const char *interface, short port TSRMLS_DC) {
struct addrinfo res;
- int fd = phpdbg_create_listenable_socket(interface, port, &res);
+ int fd = phpdbg_create_listenable_socket(interface, port, &res TSRMLS_CC);
if (fd == -1) {
return -1;
listen(fd, 5);
return fd;
-} /* }}} */
+}
-PHPDBG_API int
-phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *addr_res)
-{/*{{{*/
+PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *addr_res TSRMLS_DC) {
int sock = -1, rc;
int reuse = 1;
struct in6_addr serveraddr;
struct addrinfo hints, *res = NULL;
char port_buf[8];
int8_t any_addr = *addr == '*';
- TSRMLS_FETCH();
do {
memset(&hints, 0, sizeof hints);
*addr_res = *res;
return sock;
-}/*}}}*/
+}
-PHPDBG_API void
-phpdbg_close_socket(int sock)
-{
+PHPDBG_API void phpdbg_close_socket(int sock) {
if (socket >= 0) {
#ifdef _WIN32
closesocket(sock);
#include "phpdbg.h"
-PHPDBG_API int
-phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo);
-
-PHPDBG_API int
-phpdbg_send_bytes(int sock, char *ptr, int len);
-
-PHPDBG_API int
-phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC);
-
-PHPDBG_API int
-phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC);
-
-PHPDBG_API int
-phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *res);
-
-PHPDBG_API int
-phpdbg_open_socket(const char *interface, short port);
-
-PHPDBG_API void
-phpdbg_close_socket(int sock);
+PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo TSRMLS_DC);
+PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len);
+PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC);
+PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC);
+
+PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *res TSRMLS_DC);
+PHPDBG_API int phpdbg_open_socket(const char *interface, short port TSRMLS_DC);
+PHPDBG_API void phpdbg_close_socket(int sock);
#endif /* PHPDBG_IO_H */
const char *severity;
if ((PHPDBG_G(flags) & PHPDBG_WRITE_XML) && PHPDBG_G(in_script_xml) && PHPDBG_G(in_script_xml) != type) {
- phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>") TSRMLS_CC);
PHPDBG_G(in_script_xml) = 0;
}
severity = "error";
if (!PHPDBG_G(last_was_newline)) {
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
- phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>") TSRMLS_CC);
} else {
- phpdbg_mixed_write(fd, ZEND_STRL("\n"));
+ phpdbg_mixed_write(fd, ZEND_STRL("\n") TSRMLS_CC);
}
PHPDBG_G(last_was_newline) = 1;
}
severity = "notice";
if (!PHPDBG_G(last_was_newline)) {
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
- phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>") TSRMLS_CC);
} else {
- phpdbg_mixed_write(fd, ZEND_STRL("\n"));
+ phpdbg_mixed_write(fd, ZEND_STRL("\n") TSRMLS_CC);
}
PHPDBG_G(last_was_newline) = 1;
}
if (PHPDBG_G(in_script_xml) != type) {
char *stream_buf;
int stream_buflen = spprintf(&stream_buf, 0, "<stream type=\"%s\">", type == P_STDERR ? "stderr" : "stdout");
- phpdbg_mixed_write(fd, stream_buf, stream_buflen);
+ phpdbg_mixed_write(fd, stream_buf, stream_buflen TSRMLS_CC);
efree(stream_buf);
PHPDBG_G(in_script_xml) = type;
}
buf = php_escape_html_entities((unsigned char *) msg, msglen, (size_t *) &buflen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
phpdbg_encode_ctrl_chars(&buf, &buflen);
- phpdbg_mixed_write(fd, buf, buflen);
+ phpdbg_mixed_write(fd, buf, buflen TSRMLS_CC);
efree(buf);
} else {
- phpdbg_mixed_write(fd, msg, msglen);
+ phpdbg_mixed_write(fd, msg, msglen TSRMLS_CC);
}
return msglen;
}
xml = xmlbuf;
}
if (msgout) {
-// unsigned char *tmp = msgout;
-// buf = php_escape_html_entities(tmp, msgoutlen, (size_t *) &buflen, 0, ENT_COMPAT, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
buflen = phpdbg_encode_xml(&buf, msgout, msgoutlen, '"', """);
xmloutlen = spprintf(&xmlout, 0, "<%s severity=\"%s\" %.*s msgout=\"%.*s\" />", tag, severity, xmllen, xml, buflen, buf);
}
phpdbg_encode_ctrl_chars(&xmlout, &xmloutlen);
- phpdbg_mixed_write(fd, xmlout, xmloutlen);
+ phpdbg_mixed_write(fd, xmlout, xmloutlen TSRMLS_CC);
efree(xmlout);
} else if (msgout) {
- phpdbg_mixed_write(fd, msgout, msgoutlen);
+ phpdbg_mixed_write(fd, msgout, msgoutlen TSRMLS_CC);
}
if (PHPDBG_G(req_id) && (PHPDBG_G(flags) & PHPDBG_WRITE_XML)) {
phpdbg_encode_ctrl_chars(&buffer, &buflen);
if (PHPDBG_G(in_script_xml)) {
- phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>") TSRMLS_CC);
PHPDBG_G(in_script_xml) = 0;
}
- len = phpdbg_mixed_write(fd, buffer, buflen);
+ len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC);
efree(buffer);
}
buflen = vspprintf(&buffer, 0, fmt, args);
va_end(args);
- len = phpdbg_mixed_write(fd, buffer, buflen);
+ len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC);
efree(buffer);
return len;
phpdbg_encode_ctrl_chars(&msg, &msglen);
if (PHPDBG_G(in_script_xml)) {
- phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>") TSRMLS_CC);
PHPDBG_G(in_script_xml) = 0;
}
- phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>"));
- len = phpdbg_mixed_write(fd, msg, msglen);
- phpdbg_mixed_write(fd, ZEND_STRL("</phpdbg>"));
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>") TSRMLS_CC);
+ len = phpdbg_mixed_write(fd, msg, msglen TSRMLS_CC);
+ phpdbg_mixed_write(fd, ZEND_STRL("</phpdbg>") TSRMLS_CC);
} else {
- len = phpdbg_mixed_write(fd, buffer, buflen);
+ len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC);
}
return len;
}
-PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...) { /* {{{ */
+PHPDBG_API int phpdbg_rlog_internal(int fd TSRMLS_DC, const char *fmt, ...) { /* {{{ */
int rc = 0;
va_list args;
rc = vspprintf(&outbuf, 0, format, args);
if (outbuf) {
- rc = phpdbg_mixed_write(fd, outbuf, rc);
+ rc = phpdbg_mixed_write(fd, outbuf, rc TSRMLS_CC);
efree(outbuf);
}
PHPDBG_API int phpdbg_log_internal(int fd TSRMLS_DC, const char *fmt, ...);
PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...);
-PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...);
+PHPDBG_API int phpdbg_rlog_internal(int fd TSRMLS_DC, const char *fmt, ...);
+#define phpdbg_rlog(fd, fmt, ...) phpdbg_rlog_internal(fd TSRMLS_CC, fmt, ##__VA_ARGS__)
#define phpdbg_error(tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)
#define phpdbg_notice(tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)