Skip to content

Commit c1deff2

Browse files
committed
cleanup code before code review
Remove experimental code from the code base - getallrawdata is far more performant than getinstalledpackages/getversion method.
1 parent e5864fb commit c1deff2

File tree

1 file changed

+1
-84
lines changed

1 file changed

+1
-84
lines changed

agent/lib_composer.c

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,13 @@ static bool nr_execute_handle_autoload_composer_is_initialized() {
2121
};
2222

2323
// the class is found - there's hope!
24-
#if 0
25-
if (NULL == nr_php_find_class_method(zce, "getinstalledpackages")
26-
|| NULL == nr_php_find_class_method(zce, "getversion")) {
27-
nrl_verbosedebug(
28-
NRL_INSTRUMENT,
29-
"Composer\\InstalledVersions class found, but methods not found");
30-
return false;
31-
}
32-
#else
3324
if (NULL == nr_php_find_class_method(zce, "getallrawdata")
3425
|| NULL == nr_php_find_class_method(zce, "getrootpackage")) {
3526
nrl_verbosedebug(
3627
NRL_INSTRUMENT,
3728
"Composer\\InstalledVersions class found, but methods not found");
3829
return false;
3930
}
40-
#endif
4131

4232
return true;
4333
}
@@ -119,32 +109,7 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
119109
return;
120110
}
121111

122-
#if 0
123-
char* getpackagename
124-
= ""
125-
"(function() {"
126-
" try {"
127-
" return \\Composer\\InstalledVersions::getInstalledPackages();"
128-
" } catch (Exception $e) {"
129-
" return NULL;"
130-
" }"
131-
"})();";
132-
133-
char* getversion
134-
= ""
135-
"(function() {"
136-
" try {"
137-
" $v = \\Composer\\InstalledVersions::getPrettyVersion(\"%s\");"
138-
" if ($v != null && strlen($v) > 0) {"
139-
" $v = ltrim($v, 'v');"
140-
" }"
141-
" return $v;"
142-
" } catch (Exception $e) {"
143-
" return NULL;"
144-
" }"
145-
"})();";
146-
#else
147-
char* getallrawdata
112+
char* getallrawdata
148113
= ""
149114
"(function() {"
150115
" try {"
@@ -165,7 +130,6 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
165130
" return NULL;"
166131
" }"
167132
"})();";
168-
#endif
169133

170134
if (NR_SUCCESS != nr_execute_handle_autoload_composer_init(vendor_path)) {
171135
nrl_debug(NRL_INSTRUMENT,
@@ -178,52 +142,6 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
178142
nrl_verbosedebug(NRL_INSTRUMENT, "%s - Composer runtime API available",
179143
__func__);
180144

181-
#if 0
182-
result = zend_eval_string(getpackagename, &retval,
183-
"get installed packages by name" TSRMLS_CC);
184-
if (result == SUCCESS) {
185-
if (Z_TYPE(retval) == IS_ARRAY) {
186-
zval* value;
187-
char* buf;
188-
int result2;
189-
zval retval2;
190-
char* version = NULL;
191-
(void)version;
192-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(retval), value) {
193-
if (Z_TYPE_P(value) == IS_STRING) {
194-
buf = nr_formatf(getversion, Z_STRVAL_P(value));
195-
result2 = zend_eval_string(buf, &retval2,
196-
"retrieve version for packages");
197-
nr_free(buf);
198-
if (SUCCESS == result2) {
199-
if (nr_php_is_zval_valid_string(&retval2)) {
200-
version = Z_STRVAL(retval2);
201-
} else if (nr_php_is_zval_null(&retval2)) {
202-
nrl_verbose(NRL_INSTRUMENT,
203-
"version was IS_NULL for package %s",
204-
Z_STRVAL_P(value));
205-
version = NULL;
206-
}
207-
}
208-
}
209-
zval_dtor(&retval2);
210-
nrl_verbosedebug(NRL_INSTRUMENT, "package %s, version %s",
211-
NRSAFESTR(Z_STRVAL_P(value)), NRSAFESTR(version));
212-
if (NULL != version) {
213-
if (NRINI(vulnerability_management_package_detection_enabled)) {
214-
nr_txn_add_php_package(NRPRG(txn), NRSAFESTR(Z_STRVAL_P(value)),
215-
NRSAFESTR(version));
216-
}
217-
}
218-
}
219-
ZEND_HASH_FOREACH_END();
220-
} else {
221-
zval_dtor(&retval);
222-
return;
223-
}
224-
zval_dtor(&retval);
225-
}
226-
#else
227145
result = zend_eval_string(getallrawdata, &retval, "composer_getallrawdata.php");
228146
if (SUCCESS != result) {
229147
nrl_verbosedebug(NRL_INSTRUMENT, "%s - composer_getallrawdata.php failed", __func__);
@@ -250,7 +168,6 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
250168
"%s - installed packages is not an array", __func__);
251169
}
252170
zval_dtor(&retval);
253-
#endif
254171
}
255172

256173
static char* nr_execute_handle_autoload_composer_get_vendor_path(

0 commit comments

Comments
 (0)