Skip to content

Commit

Permalink
Merged pull request #736
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Apr 21, 2021
2 parents adde63b + 7bcc81b commit d98c285
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
35 changes: 29 additions & 6 deletions src/debugger/com.c
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2020 Derick Rethans |
| Copyright (c) 2002-2021 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand Down Expand Up @@ -447,9 +447,9 @@ static void xdebug_init_normal_debugger(xdebug_str *connection_attempts)
}
}

static void xdebug_init_cloud_debugger()
static void xdebug_init_cloud_debugger(const char *cloud_id)
{
unsigned long crc = xdebug_crc32(XINI_DBG(cloud_id), strlen(XINI_DBG(cloud_id)));
unsigned long crc = xdebug_crc32(cloud_id, strlen(cloud_id));
char *host;

host = xdebug_sprintf("%c.cloud.xdebug.com", (crc & 0x0f) + 'a');
Expand All @@ -460,17 +460,40 @@ static void xdebug_init_cloud_debugger()
xdfree(host);
}

/**
* dXXXXXXa-cXXa-4XX7-9XX3-fXXXXXXXXXX0
*/
static int ide_key_is_cloud_id()
{
const char *k = XG_DBG(ide_key);

if (strlen(k) != 36) {
return 0;
}

if (k[8] != '-' || k[13] != '-' || k[18] != '-' || k[23] != '-') {
return 0;
}

return 1;
}

static void xdebug_init_debugger()
{
xdebug_str *connection_attempts = xdebug_str_new();

/* Get handler from mode */
XG_DBG(context).handler = &xdebug_handler_dbgp;

if (strcmp(XINI_DBG(cloud_id), "") == 0) {
xdebug_init_normal_debugger(connection_attempts);
if (strcmp(XINI_DBG(cloud_id), "") != 0) {
xdebug_init_cloud_debugger(XINI_DBG(cloud_id));
XG_DBG(context).host_type = XDEBUG_CLOUD;
} else if (XG_DBG(ide_key) && ide_key_is_cloud_id()) {
xdebug_init_cloud_debugger(XG_DBG(ide_key));
XG_DBG(context).host_type = XDEBUG_CLOUD_FROM_TRIGGER_VALUE;
} else {
xdebug_init_cloud_debugger();
xdebug_init_normal_debugger(connection_attempts);
XG_DBG(context).host_type = XDEBUG_NORMAL;
}

/* Check whether we're connected, or why not */
Expand Down
9 changes: 6 additions & 3 deletions src/debugger/handler_dbgp.c
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2020 Derick Rethans |
| Copyright (c) 2002-2021 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand Down Expand Up @@ -2381,10 +2381,13 @@ int xdebug_dbgp_init(xdebug_con *context, int mode)
xdebug_xml_add_attribute_ex(response, "session", xdstrdup(getenv("DBGP_COOKIE")), 0, 1);
}

if (XINI_DBG(cloud_id) && *XINI_DBG(cloud_id)) {
if (XG_DBG(context).host_type == XDEBUG_CLOUD && XINI_DBG(cloud_id) && *XINI_DBG(cloud_id)) {
xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XINI_DBG(cloud_id)), 0, 1);
}
if (XG_DBG(ide_key) && *XG_DBG(ide_key)) {
if (XG_DBG(context).host_type == XDEBUG_CLOUD_FROM_TRIGGER_VALUE && XG_DBG(ide_key) && *XG_DBG(ide_key)) {
xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XG_DBG(ide_key)), 0, 1);
}
if (XG_DBG(context).host_type == XDEBUG_NORMAL && XG_DBG(ide_key) && *XG_DBG(ide_key)) {
xdebug_xml_add_attribute_ex(response, "idekey", xdstrdup(XG_DBG(ide_key)), 0, 1);
}

Expand Down
7 changes: 6 additions & 1 deletion src/debugger/handlers.h
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2020 Derick Rethans |
| Copyright (c) 2002-2021 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand Down Expand Up @@ -57,8 +57,13 @@ struct _xdebug_brk_admin {
char *key;
};

#define XDEBUG_NORMAL 0x01
#define XDEBUG_CLOUD 0x02
#define XDEBUG_CLOUD_FROM_TRIGGER_VALUE 0x03

struct _xdebug_con {
int socket;
int host_type; /* XDEBUG_NORMAL, XDEBUG_CLOUD, XDEBUG_CLOUD_FROM_TRIGGER_VALUE */
void *options;
xdebug_remote_handler *handler;
fd_buf *buffer;
Expand Down

0 comments on commit d98c285

Please sign in to comment.