Skip to content

Commit

Permalink
simplify return value - always a string
Browse files Browse the repository at this point in the history
This approach adds some level of protection (compiler type checking) from
misusing the API.
  • Loading branch information
lavarou committed Jun 26, 2024
1 parent 3f6c283 commit 1a4bc74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions agent/csec_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "php_compat.h"
#include "php_newrelic.h"

int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, void** p) {
int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) {
const char* value = NULL;

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

switch (key) {
case NR_PHP_CSEC_METADATA_HIGH_SECURITY:
*p = nr_zalloc(sizeof(int));
if (NULL == *p) {
return -3;
if (NRPRG(app)->info.high_security) {
value = "true";
} else {
value = "false";
}
*((int*)*p) = NRPRG(app)->info.high_security;
return 0;
break;
case NR_PHP_CSEC_METADATA_ENTITY_NAME:
value = nr_app_get_entity_name(NRPRG(app));
break;
Expand Down
7 changes: 4 additions & 3 deletions agent/csec_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ typedef enum {
/*
* Purpose : Copy requested app meta data into allocated *value.
* The caller is responsible for freeing the memory
* allocated.
* allocated. The value is a string representation of
* the requested metadata.
*
* Params : Pointer to a nr_php_csec_metadata_t structure
*
Expand All @@ -32,7 +33,7 @@ typedef enum {
* -4 for invalid metadata key
* -5 for inability to retrieve metadata value
*/
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, void** value);
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, void** value);
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, char** value);
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, char** value);
#define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata"
#endif

0 comments on commit 1a4bc74

Please sign in to comment.