Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor to avoid 'transport' struct
Replace 'transport' struct, which would have to be versioned, with a simple
getter API of `get(key, &ptr)` signature.
  • Loading branch information
lavarou authored and anmol-ap committed Mar 13, 2025
commit d162d86f08c65f3cee6e5c4fd543c7a763e801ef
60 changes: 48 additions & 12 deletions agent/csec_metadata.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -14,24 +14,60 @@
#include "php_compat.h"
#include "php_newrelic.h"

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

if (NULL == p) {
return -1;
}

if (NULL == NRPRG(app)) {
return -2;
}

csec_metadata->high_security = NRPRG(app)->info.high_security;
csec_metadata->entity_name = nr_strdup(nr_app_get_entity_name(NRPRG(app)));
csec_metadata->entity_type = nr_strdup(nr_app_get_entity_type(NRPRG(app)));
csec_metadata->entity_guid = nr_strdup(nr_app_get_entity_guid(NRPRG(app)));
csec_metadata->host_name = nr_strdup(nr_app_get_host_name(NRPRG(app)));
csec_metadata->agent_run_id = nr_strdup(NRPRG(app)->agent_run_id);
csec_metadata->account_id = nr_strdup(NRPRG(app)->account_id);
csec_metadata->license = nr_strdup(NRPRG(license).value);
csec_metadata->plicense = nr_strdup(NRPRG(app)->plicense);
switch (key) {
case NR_PHP_CSEC_METADATA_HIGH_SECURITY:
*p = nr_zalloc(sizeof(int));
if (NULL == *p) {
return -3;
}
*((int*)*p) = NRPRG(app)->info.high_security;
return 0;
case NR_PHP_CSEC_METADATA_ENTITY_NAME:
value = nr_app_get_entity_name(NRPRG(app));
break;
case NR_PHP_CSEC_METADATA_ENTITY_TYPE:
value = nr_app_get_entity_type(NRPRG(app));
break;
case NR_PHP_CSEC_METADATA_ENTITY_GUID:
value = nr_app_get_entity_guid(NRPRG(app));
break;
case NR_PHP_CSEC_METADATA_HOST_NAME:
value = nr_app_get_host_name(NRPRG(app));
break;
case NR_PHP_CSEC_METADATA_AGENT_RUN_ID:
value = NRPRG(app)->agent_run_id;
break;
case NR_PHP_CSEC_METADATA_ACCOUNT_ID:
value = NRPRG(app)->account_id;
break;
case NR_PHP_CSEC_METADATA_LICENSE:
value = NRPRG(license).value;
break;
case NR_PHP_CSEC_METADATA_PLICENSE:
value = NRPRG(app)->plicense;
break;
default:
return -4;
}

if (NULL == value) {
return -5;
}

*p = nr_strdup(value);
if (NULL == *p) {
return -3;
}
return 0;
}
39 changes: 20 additions & 19 deletions agent/csec_metadata.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef CSEC_METADATA_H
#define CSEC_METADATA_H

typedef struct _nr_php_csec_metadata_t {
int high_security; /* Indicates if high security been set locally for this
application */
char* license; /* License key provided */
char* plicense; /* Printable license (abbreviated for security) */
char* host_name; /* Local host name reported to the daemon */
char* entity_name; /* Entity name related to this application */
char* entity_type; /* Entity type */
char* account_id; /* Security : Added for getting account id */
char* entity_guid; /* Entity guid related to this application */
char* agent_run_id; /* The collector's agent run ID; assigned from the
New Relic backend */
} nr_php_csec_metadata_t;
typedef enum {
NR_PHP_CSEC_METADATA_HIGH_SECURITY = 1,
NR_PHP_CSEC_METADATA_ENTITY_NAME,
NR_PHP_CSEC_METADATA_ENTITY_TYPE,
NR_PHP_CSEC_METADATA_ENTITY_GUID,
NR_PHP_CSEC_METADATA_HOST_NAME,
NR_PHP_CSEC_METADATA_AGENT_RUN_ID,
NR_PHP_CSEC_METADATA_ACCOUNT_ID,
NR_PHP_CSEC_METADATA_LICENSE,
NR_PHP_CSEC_METADATA_PLICENSE
} nr_php_csec_metadata_key_t;

/*
* Purpose : Return app meta data by populating nr_php_csec_metadata_t
* structure. The caller is responsible for freeing the memory
* allocated for the strings in the structure.
* Purpose : Copy requested app meta data into allocated *value.
* The caller is responsible for freeing the memory
* allocated.
*
* Params : Pointer to a nr_php_csec_metadata_t structure
*
* Returns : 0 for success
* -1 for invalid input
* -2 for invalid internal state
* -3 for inability to allocate memory
* -4 for invalid metadata key
* -5 for inability to retrieve metadata value
*/
extern int nr_php_csec_get_metadata(nr_php_csec_metadata_t*);
typedef int (*nr_php_csec_get_metadata_t)(nr_php_csec_metadata_t*);
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);
#define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata"
#endif