|
2 | 2 |
|
3 | 3 | #include <cassert>
|
4 | 4 |
|
| 5 | +#include "datadog_conf_handler.h" |
| 6 | + |
5 | 7 | namespace datadog {
|
6 | 8 | namespace nginx {
|
7 | 9 |
|
8 |
| -char *warn_deprecated_command_datadog_tracing(ngx_conf_t *cf, |
9 |
| - ngx_command_t * /*command*/, |
10 |
| - void * /*conf*/) noexcept { |
| 10 | +char *silently_ignore_command(ngx_conf_t *cf, ngx_command_t *command, void *) { |
| 11 | + ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "Directive \"%V\" ignored", |
| 12 | + &command->name); |
| 13 | + return NGX_CONF_OK; |
| 14 | +} |
| 15 | + |
| 16 | +char *alias_directive(ngx_conf_t *cf, ngx_command_t *command, void *) noexcept { |
| 17 | + if (command->post == nullptr) { |
| 18 | + return static_cast<char *>(NGX_CONF_ERROR); |
| 19 | + } |
| 20 | + |
| 21 | + auto src_directive = static_cast<char *>(command->post); |
| 22 | + |
11 | 23 | const auto elements = static_cast<ngx_str_t *>(cf->args->elts);
|
12 | 24 | assert(cf->args->nelts >= 1);
|
13 | 25 |
|
14 |
| - ngx_log_error( |
15 |
| - NGX_LOG_WARN, cf->log, 0, |
16 |
| - "Directive \"%V\" is deprecated. Use datadog_tracing on/off instead", |
17 |
| - &elements[0]); |
| 26 | + const ngx_str_t new_name_ngx{.len = strlen(src_directive), |
| 27 | + .data = (u_char *)src_directive}; |
| 28 | + ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "Alias \"%V\" to \"%V\"", |
| 29 | + &command->name, &new_name_ngx); |
| 30 | + |
| 31 | + // Rename the command and let `datadog_conf_handler` dispatch to the |
| 32 | + // appropriate handler. |
| 33 | + elements[0] = new_name_ngx; |
| 34 | + auto rcode = datadog_conf_handler({.conf = cf, .skip_this_module = false}); |
| 35 | + if (rcode != NGX_OK) { |
| 36 | + return static_cast<char *>(NGX_CONF_ERROR); |
| 37 | + } |
| 38 | + |
| 39 | + return NGX_CONF_OK; |
| 40 | +} |
| 41 | + |
| 42 | +char *warn_deprecated_command(ngx_conf_t *cf, ngx_command_t *command, |
| 43 | + void *) noexcept { |
| 44 | + u_char buf[NGX_MAX_ERROR_STR] = {0}; |
| 45 | + u_char *last = buf + NGX_MAX_ERROR_STR; |
| 46 | + u_char *p = |
| 47 | + ngx_slprintf(buf, last, "Directive \"%V\" is deprecated", &command->name); |
| 48 | + |
| 49 | + if (command->post != nullptr) { |
| 50 | + auto reason = static_cast<char *>(command->post); |
| 51 | + ngx_slprintf(p, last, ". %s", reason); |
| 52 | + } |
| 53 | + |
| 54 | + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "%s", buf); |
| 55 | + return NGX_CONF_OK; |
| 56 | +} |
| 57 | + |
| 58 | +char *err_deprecated_command(ngx_conf_t *cf, ngx_command_t *command, |
| 59 | + void *) noexcept { |
| 60 | + u_char buf[NGX_MAX_ERROR_STR] = {0}; |
| 61 | + u_char *last = buf + NGX_MAX_ERROR_STR; |
| 62 | + u_char *p = |
| 63 | + ngx_slprintf(buf, last, "Directive \"%V\" is deprecated", &command->name); |
| 64 | + |
| 65 | + if (command->post != nullptr) { |
| 66 | + auto reason = static_cast<char *>(command->post); |
| 67 | + ngx_slprintf(p, last, ". %s", reason); |
| 68 | + } |
18 | 69 |
|
19 |
| - return NGX_OK; |
| 70 | + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "%s", buf); |
| 71 | + return static_cast<char *>(NGX_CONF_ERROR); |
20 | 72 | }
|
21 | 73 |
|
22 | 74 | } // namespace nginx
|
|
0 commit comments