Skip to content

Commit c912dc9

Browse files
committed
simplify return value - always a string
This approach adds some level of protection (compiler type checking) from misusing the API.
1 parent c02f0d3 commit c912dc9

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

agent/csec_metadata.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "php_compat.h"
1515
#include "php_newrelic.h"
1616

17-
int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, void** p) {
17+
int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) {
1818
const char* value = NULL;
1919

2020
if (NULL == p) {
@@ -27,12 +27,12 @@ int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, void** p) {
2727

2828
switch (key) {
2929
case NR_PHP_CSEC_METADATA_HIGH_SECURITY:
30-
*p = nr_zalloc(sizeof(int));
31-
if (NULL == *p) {
32-
return -3;
30+
if (NRPRG(app)->info.high_security) {
31+
value = "true";
32+
} else {
33+
value = "false";
3334
}
34-
*((int*)*p) = NRPRG(app)->info.high_security;
35-
return 0;
35+
break;
3636
case NR_PHP_CSEC_METADATA_ENTITY_NAME:
3737
value = nr_app_get_entity_name(NRPRG(app));
3838
break;

agent/csec_metadata.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ typedef enum {
2121
/*
2222
* Purpose : Copy requested app meta data into allocated *value.
2323
* The caller is responsible for freeing the memory
24-
* allocated.
24+
* allocated. The value is a string representation of
25+
* the requested metadata.
2526
*
2627
* Params : Pointer to a nr_php_csec_metadata_t structure
2728
*
@@ -32,7 +33,7 @@ typedef enum {
3233
* -4 for invalid metadata key
3334
* -5 for inability to retrieve metadata value
3435
*/
35-
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, void** value);
36-
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, void** value);
36+
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, char** value);
37+
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, char** value);
3738
#define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata"
3839
#endif

0 commit comments

Comments
 (0)