[xdebug-dev] xdebug xdebug/xdebug_compat.c xdebug/xdebug_compat.h xdebug/xdebug.c xdebug/xdebug.dsp xdebug/xdebug_handler_dbgp.c functions php_var_dump() and php_base64_encode()/php_base64_decode() into the

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Sun Apr 04 2004 - 23:24:59 CEST

Date: Sun Apr 4 23:24:58 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
- Made Xdebug compile with all PHP 4.3.x versions by embedding the non-exported
  functions php_var_dump() and php_base64_encode()/php_base64_decode() into the
  Xdebug source.
#- BSD style licenses rock :)

Modified files:
           xdebug/xdebug.c (version: 1.202)
           xdebug/xdebug.dsp (version: 1.21)
           xdebug/xdebug_handler_dbgp.c (version: 1.35)
Added files:
           xdebug/xdebug_compat.c (new version: 1.1)
           xdebug/xdebug_compat.h (new version: 1.1)

[FILE: /xdebug/xdebug_compat.c]

/*
   +----------------------------------------------------------------------+
   | PHP Version 5 |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2004 The PHP Group |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license, |
   | that is bundled with this package in the file LICENSE, and is |
   | available through the world-wide-web at the following url: |
   | http://www.php.net/license/3_0.txt. |
   | If you did not receive a copy of the PHP license and are unable to |
   | obtain it through the world-wide-web, please send a note to |
   | license@php.net so we can mail you a copy immediately. |
   +----------------------------------------------------------------------+
   | Author: Jim Winstead <jimw@php.net> |
   +----------------------------------------------------------------------+
 */
/* $Id: cvstemp,v 1.1 2004/04/04 21:24:58 derick Exp $ */

#include "php.h"
#include "main/php_version.h"
#include "xdebug_compat.h"

#if (PHP_MAJOR_VERSION == 4) && (PHP_MINOR_VERSION == 3) && (PHP_RELEASE_VERSION <= 1)

#define COMMON ((*struc)->is_ref ? "&" : "")
/* {{{ xdebug_var_dump */

static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
{
        int level;
        TSRMLS_FETCH();

        level = va_arg(args, int);

        if (hash_key->nKeyLength==0) { /* numeric key */
                php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
        } else { /* string key */
                php_printf("%*c[\"", level + 1, ' ');
                PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
                php_printf("\"]=>\n");
        }
        xdebug_var_dump(zv, level + 2 TSRMLS_CC);
        return 0;
}

void xdebug_var_dump(zval **struc, int level TSRMLS_DC)
{
        HashTable *myht = NULL;
        zend_object *object = NULL;

        if (level > 1) {
                php_printf("%*c", level - 1, ' ');
        }

        switch (Z_TYPE_PP(struc)) {
        case IS_BOOL:
                php_printf("%sbool(%s)\n", COMMON, Z_LVAL_PP(struc)?"true":"false");
                break;
        case IS_NULL:
                php_printf("%sNULL\n", COMMON);
                break;
        case IS_LONG:
                php_printf("%sint(%ld)\n", COMMON, Z_LVAL_PP(struc));
                break;
        case IS_DOUBLE:
                php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc));
                break;
        case IS_STRING:
                php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
                PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
                PUTS("\"\n");
                break;
        case IS_ARRAY:
                myht = Z_ARRVAL_PP(struc);
                if (myht->nApplyCount > 1) {
                        PUTS("*RECURSION*\n");
                        return;
                }
                php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht));
                goto head_done;
        case IS_OBJECT:
                object = Z_OBJ_PP(struc);
                myht = Z_OBJPROP_PP(struc);
                if (myht->nApplyCount > 1) {
                        PUTS("*RECURSION*\n");
                        return;
                }
                php_printf("%sobject(%s)(%d) {\n", COMMON, Z_OBJCE_PP(struc)->name, zend_hash_num_elements(myht));
head_done:
                zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level);
                if (level > 1) {
                        php_printf("%*c", level-1, ' ');
                }
                PUTS("}\n");
                break;
        case IS_RESOURCE: {
                char *type_name;

                type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
                php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown");
                break;
        }
        default:
                php_printf("%sUNKNOWN:0\n", COMMON);
                break;
        }
}
/* }}} */
#endif

#if (PHP_MAJOR_VERSION == 4) && (PHP_MINOR_VERSION == 3) && (PHP_RELEASE_VERSION <= 4)

#include <string.h>

/* {{{ */
static const char base64_table[] =
        { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
          'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
          'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
          '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
        };

static const char base64_pad = '=';

static const short base64_reverse_table[256] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
        -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
        -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
/* }}} */

/* {{{ */
unsigned char *xdebug_base64_encode(const unsigned char *str, int length, int *ret_length)
{
        const unsigned char *current = str;
        int i = 0;
        unsigned char *result = (unsigned char *)emalloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));

        while (length > 2) { /* keep going until we have less than 24 bits */
                result[i++] = base64_table[current[0] >> 2];
                result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
                result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
                result[i++] = base64_table[current[2] & 0x3f];

                current += 3;
                length -= 3; /* we just handle 3 octets of data */
        }

        /* now deal with the tail end of things */
        if (length != 0) {
                result[i++] = base64_table[current[0] >> 2];
                if (length > 1) {
                        result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
                        result[i++] = base64_table[(current[1] & 0x0f) << 2];
                        result[i++] = base64_pad;
                }
                else {
                        result[i++] = base64_table[(current[0] & 0x03) << 4];
                        result[i++] = base64_pad;
                        result[i++] = base64_pad;
                }
        }
        if(ret_length) {
                *ret_length = i;
        }
        result[i] = '\0';
        return result;
}
/* }}} */

/* {{{ */
/* as above, but backwards. :) */
unsigned char *xdebug_base64_decode(const unsigned char *str, int length, int *ret_length)
{
        const unsigned char *current = str;
        int ch, i = 0, j = 0, k;
        /* this sucks for threaded environments */
        unsigned char *result;
        
        result = (unsigned char *)emalloc(length + 1);
        if (result == NULL) {
                return NULL;
        }

        /* run through the whole string, converting as we go */
        while ((ch = *current++) != '\0' && length-- > 0) {
                if (ch == base64_pad) break;

            /* When Base64 gets POSTed, all pluses are interpreted as spaces.
                   This line changes them back. It's not exactly the Base64 spec,
                   but it is completely compatible with it (the spec says that
                   spaces are invalid). This will also save many people considerable
                   headache. - Turadg Aleahmad <turadg@wise.berkeley.edu>
            */

                if (ch == ' ') ch = '+';

                ch = base64_reverse_table[ch];
                if (ch < 0) continue;

                switch(i % 4) {
                case 0:
                        result[j] = ch << 2;
                        break;
                case 1:
                        result[j++] |= ch >> 4;
                        result[j] = (ch & 0x0f) << 4;
                        break;
                case 2:
                        result[j++] |= ch >>2;
                        result[j] = (ch & 0x03) << 6;
                        break;
                case 3:
                        result[j++] |= ch;
                        break;
                }
                i++;
        }

        k = j;
        /* mop things up if we ended on a boundary */
        if (ch == base64_pad) {
                switch(i % 4) {
                case 0:
                case 1:
                        efree(result);
                        return NULL;
                case 2:
                        k++;
                case 3:
                        result[k++] = 0;
                }
        }
        if(ret_length) {
                *ret_length = j;
        }
        result[j] = '\0';
        return result;
}
/* }}} */

#endif

[FILE: /xdebug/xdebug_compat.h]

/*
   +----------------------------------------------------------------------+
   | Xdebug |
   +----------------------------------------------------------------------+
   | Copyright (c) 2002, 2003 Derick Rethans |
   +----------------------------------------------------------------------+
   | This source file is subject to version 1.0 of the Xdebug license, |
   | that is bundled with this package in the file LICENSE, and is |
   | available at through the world-wide-web at |
   | http://xdebug.derickrethans.nl/license.php |
   | If you did not receive a copy of the Xdebug license and are unable |
   | to obtain it through the world-wide-web, please send a note to |
   | xdebug@derickrethans.nl so we can mail you a copy immediately. |
   +----------------------------------------------------------------------+
   | Authors: Derick Rethans <derick@xdebug.org> |
   +----------------------------------------------------------------------+
 */

#ifndef __HAVE_XDEBUG_COMPAT_H__
#define __HAVE_XDEBUG_COMPAT_H__

#if (PHP_MAJOR_VERSION == 4) && (PHP_MINOR_VERSION == 3) && (PHP_RELEASE_VERSION <= 1)

void xdebug_var_dump(zval **struc, int level TSRMLS_DC);

#else

# include "ext/standard/php_var.h"
# define xdebug_var_dump php_var_dump

#endif

#if (PHP_MAJOR_VERSION == 4) && (PHP_MINOR_VERSION == 3) && (PHP_RELEASE_VERSION <= 4)

unsigned char *xdebug_base64_encode(const unsigned char *, int, int *);
unsigned char *xdebug_base64_decode(const unsigned char *str, int length, int *ret_length);

#else

# include "ext/standard/base64.h"
# define xdebug_base64_encode php_base64_encode
# define xdebug_base64_decode php_base64_decode

#endif

#endif

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.201
retrieving revision 1.202
diff -u -r1.201 -r1.202
--- xdebug/xdebug.c:1.201 Sat Apr 03 19:37:58 2004 GMT
+++ xdebug/xdebug.c Sun Apr 04 19:24:58 2004 GMT
@@ -23,6 +23,8 @@
 #endif
 
 #include "php.h"
+#include "main/php_version.h"
+#include "xdebug_compat.h"
 
 #if HAVE_XDEBUG
 
@@ -1436,7 +1438,7 @@
                         PHPWRITE(val, strlen(val));
                         xdfree(val);
                 } else {
- php_var_dump(args[i], 1 TSRMLS_CC);
+ xdebug_var_dump(args[i], 1 TSRMLS_CC);
                 }
         }
         

[FILE: /xdebug/xdebug.dsp]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- xdebug/xdebug.dsp:1.20 Mon Mar 15 15:39:55 2004 GMT
+++ xdebug/xdebug.dsp Sun Apr 04 19:24:58 2004 GMT
@@ -111,6 +111,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\xdebug_compat.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\xdebug_handler_dbgp.c
 # End Source File
 # Begin Source File
@@ -179,6 +183,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\xdebug_compat.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\xdebug_handler_dbgp.h
 # End Source File
 # Begin Source File

[FILE: /xdebug/xdebug_handler_dbgp.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- xdebug/xdebug_handler_dbgp.c:1.34 Tue Mar 30 18:07:49 2004 GMT
+++ xdebug/xdebug_handler_dbgp.c Sun Apr 04 19:24:58 2004 GMT
@@ -23,7 +23,7 @@
 #endif
 
 #include "php.h"
-#include "ext/standard/base64.h"
+
 #include "ext/standard/php_string.h"
 #include "ext/standard/url.h"
 #include "main/php_version.h"
@@ -39,6 +39,8 @@
 #include "xdebug_var.h"
 #include "xdebug_xml.h"
 
+#include "xdebug_compat.h"
+
 #ifdef PHP_WIN32
 #include "win32/time.h"
 #include <process.h>
@@ -718,7 +720,7 @@
         EG(error_reporting) = 0;
 
         /* base64 decode eval string */
- eval_string = php_base64_decode(CMD_OPTION('-'), strlen(CMD_OPTION('-')), &new_length);
+ eval_string = xdebug_base64_decode(CMD_OPTION('-'), strlen(CMD_OPTION('-')), &new_length);
 
         /* Do evaluation */
         XG(breakpoints_allowed) = 0;
@@ -822,7 +824,7 @@
                 RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_CANT_OPEN_FILE);
         } else {
                 xdebug_xml_add_attribute(*retval, "encoding", "base64");
- encoded_source = php_base64_encode(source, strlen(source), &new_len);
+ encoded_source = xdebug_base64_encode(source, strlen(source), &new_len);
                 xdebug_xml_add_text(*retval, xdstrdup(encoded_source));
                 efree(encoded_source);
                 xdfree(source);
@@ -1306,7 +1308,7 @@
 
 char *xdebug_dbgp_get_revision(void)
 {
- return "$Revision: 1.34 $";
+ return "$Revision: 1.35 $";
 }
 
 int xdebug_dbgp_cmdloop(xdebug_con *context TSRMLS_DC)
Received on Sun Apr 4 23:24:58 2004

This archive was generated by hypermail 2.1.8 : Wed Aug 20 2008 - 18:00:10 CEST