Skip to content

Commit

Permalink
nginx/apache: add macro's for handling 4 arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Zandbelt <hans.zandbelt@openidc.com>
  • Loading branch information
zandbelt committed Sep 11, 2024
1 parent aa8546a commit d5e0628
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/oauth2/apache.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ int oauth2_apache_post_config(apr_pool_t *pool, apr_pool_t *p1, apr_pool_t *p2,
return func(srv_cfg->log, member, v1, v2, v3); \
}

#define OAUTH2_APACHE_CMD_ARGSV4(module, type, primitive, func, member) \
static const char *apache_##module##_set_##primitive( \
cmd_parms *cmd, void *m, int argc, char *const argv[]) \
{ \
oauth2_apache_cfg_srv_t *srv_cfg = ap_get_module_config( \
cmd->server->module_config, &module##_module); \
type *cfg = (type *)m; \
(void)cfg; \
return func(srv_cfg->log, member, argc > 0 ? argv[0] : NULL, \
argc > 1 ? argv[1] : NULL, \
argc > 2 ? argv[2] : NULL, \
argc > 3 ? argv[3] : NULL); \
}

#define OAUTH2_APACHE_CMD_ARGS(module, nargs, cmd, member, desc) \
AP_INIT_TAKE##nargs(cmd, apache_##module##_set_##member, NULL, \
RSRC_CONF | ACCESS_CONF | OR_AUTHCFG, desc)
Expand Down
25 changes: 25 additions & 0 deletions include/oauth2/nginx.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,31 @@
oauth2_mem_free(v1); \
OAUTH2_NGINX_CFG_FUNC_END(cf, rv)

#define OAUTH2_NGINX_CFG_FUNC_ARGS4(module, type, primitive, func, member) \
OAUTH2_NGINX_CFG_FUNC_START(module, type, primitive) \
char *v1 = cf->args->nelts > 1 \
? oauth2_strndup((const char *)value[1].data, \
(size_t)value[1].len) \
: NULL; \
char *v2 = cf->args->nelts > 2 \
? oauth2_strndup((const char *)value[2].data, \
(size_t)value[2].len) \
: NULL; \
char *v3 = cf->args->nelts > 3 \
? oauth2_strndup((const char *)value[3].data, \
(size_t)value[3].len) \
: NULL; \
char *v4 = cf->args->nelts > 4 \
? oauth2_strndup((const char *)value[3].data, \
(size_t)value[4].len) \
: NULL; \
rv = func(cfg->log, member, v1, v2, v3, v4); \
oauth2_mem_free(v4); \
oauth2_mem_free(v3); \
oauth2_mem_free(v2); \
oauth2_mem_free(v1); \
OAUTH2_NGINX_CFG_FUNC_END(cf, rv)

// commands

// clang-format off
Expand Down
2 changes: 2 additions & 0 deletions src/server/nginx.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ static void _oauth2_nginx_port_copy(oauth2_nginx_request_context_t *ctx)
sin6 =
(struct sockaddr_in6 *)ctx->r->connection->local_sockaddr;
port = ntohs(sin6->sin6_port);
break;
#endif
#if (NGX_HAVE_UNIX_DOMAIN)
case AF_UNIX:
port = 0;
break;
#endif
default: /* AF_INET */
sin = (struct sockaddr_in *)ctx->r->connection->local_sockaddr;
Expand Down

0 comments on commit d5e0628

Please sign in to comment.