Skip to content

Commit

Permalink
merge #778
Browse files Browse the repository at this point in the history
  • Loading branch information
bduranleau-nr committed Dec 1, 2023
1 parent d295ecd commit 84ef834
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
30 changes: 20 additions & 10 deletions agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
nr_php_wrap_callable(func, nr_wordpress_wrap_hook TSRMLS_CC);
}

static void free_tag(void* tag) {
nr_free(tag);
}

/*
* Some plugins generate transient tag names. We can detect these by checking
* the substrings returned from our regex rule. If the tag is transient, we
Expand All @@ -366,8 +370,7 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
* Example: (old) add_option__transient_timeout_twccr_382402301f44c883bc0137_cat
* (new) add_option__transient_timeout_twccr_*_cat
*/
static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
char* orig_tag = NULL;
static char* nr_wordpress_clean_tag(const zval* tag) {
char* clean_tag = NULL;
nr_regex_t* regex = NULL;
nr_regex_substrings_t* ss = NULL;
Expand All @@ -381,8 +384,16 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
return NULL;
}

orig_tag = nr_strndup(Z_STRVAL_P(tag), Z_STRLEN_P(tag));
ss = nr_regex_match_capture(regex, orig_tag, nr_strlen(orig_tag));
if (NULL == NRPRG(wordpress_clean_tag_cache)) {
NRPRG(wordpress_clean_tag_cache) = nr_hashmap_create(free_tag);
}

if (nr_hashmap_get_into(NRPRG(wordpress_clean_tag_cache), Z_STRVAL_P(tag),
Z_STRLEN_P(tag), (void**)&clean_tag)) {
return clean_tag;
}

ss = nr_regex_match_capture(regex, Z_STRVAL_P(tag), Z_STRLEN_P(tag));
clean_tag = nr_regex_substrings_get(ss, 5);

/*
Expand All @@ -403,7 +414,9 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
}

nr_regex_substrings_destroy(&ss);
nr_free(orig_tag);

nr_hashmap_set(NRPRG(wordpress_clean_tag_cache), Z_STRVAL_P(tag),
Z_STRLEN_P(tag), clean_tag);

return clean_tag;
}
Expand All @@ -429,9 +442,8 @@ NR_PHP_WRAPPER(nr_wordpress_exec_handle_tag) {

NRPRG(check_cufa) = true;

NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag TSRMLS_CC);
NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag);
NR_PHP_WRAPPER_CALL;
nr_free(NRPRG(wordpress_tag));
NRPRG(wordpress_tag) = old_tag;
if (NULL == NRPRG(wordpress_tag)) {
NRPRG(check_cufa) = false;
Expand Down Expand Up @@ -517,10 +529,8 @@ NR_PHP_WRAPPER(nr_wordpress_apply_filters) {

NRPRG(check_cufa) = true;

NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag TSRMLS_CC);

NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag);
NR_PHP_WRAPPER_CALL;
nr_free(NRPRG(wordpress_tag));
NRPRG(wordpress_tag) = old_tag;
if (NULL == NRPRG(wordpress_tag)) {
NRPRG(check_cufa) = false;
Expand Down
1 change: 1 addition & 0 deletions agent/php_newrelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ nr_matcher_t* wordpress_theme_matcher; /* Matcher for theme filenames */
nr_matcher_t* wordpress_core_matcher; /* Matcher for plugin filenames */
nr_hashmap_t* wordpress_file_metadata; /* Metadata for plugin and theme names
given a filename */
nr_hashmap_t* wordpress_clean_tag_cache; /* Cached clean tags */

char* doctrine_dql; /* The current Doctrine DQL. Only non-NULL while a Doctrine
object is on the stack. */
Expand Down
1 change: 1 addition & 0 deletions agent/php_rshutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int nr_php_post_deactivate(void) {
nr_matcher_destroy(&NRPRG(wordpress_core_matcher));
nr_matcher_destroy(&NRPRG(wordpress_theme_matcher));
nr_hashmap_destroy(&NRPRG(wordpress_file_metadata));
nr_hashmap_destroy(&NRPRG(wordpress_clean_tag_cache));

nr_free(NRPRG(mysql_last_conn));
nr_free(NRPRG(pgsql_last_conn));
Expand Down

0 comments on commit 84ef834

Please sign in to comment.