Skip to content

Commit d1146dc

Browse files
oauth: Rename macro to avoid collisions on Windows
Our json parsing defined the macros OPTIONAL and REQUIRED to decorate the structs with for increased readability. This however collides with macros in the <windef.h> header on Windows. ../src/interfaces/libpq/fe-auth-oauth-curl.c:398:9: warning: "OPTIONAL" redefined 398 | #define OPTIONAL false | ^~~~~~~~ In file included from D:/a/_temp/msys64/ucrt64/include/windef.h:9, from D:/a/_temp/msys64/ucrt64/include/windows.h:69, from D:/a/_temp/msys64/ucrt64/include/winsock2.h:23, from ../src/include/port/win32_port.h:60, from ../src/include/port.h:24, from ../src/include/c.h:1331, from ../src/include/postgres_fe.h:28, from ../src/interfaces/libpq/fe-auth-oauth-curl.c:16: include/minwindef.h:65:9: note: this is the location of the previous definition 65 | #define OPTIONAL | ^~~~~~~~ Rename to avoid compilation errors in anticipation of implementing support for Windows. Reported-by: Dave Cramer (on PostgreSQL Hacking Discord)
1 parent 03366b6 commit d1146dc

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/interfaces/libpq/fe-auth-oauth-curl.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ struct json_field
394394
};
395395

396396
/* Documentation macros for json_field.required. */
397-
#define REQUIRED true
398-
#define OPTIONAL false
397+
#define PG_OAUTH_REQUIRED true
398+
#define PG_OAUTH_OPTIONAL false
399399

400400
/* Parse state for parse_oauth_json(). */
401401
struct oauth_parse
@@ -844,8 +844,8 @@ static bool
844844
parse_provider(struct async_ctx *actx, struct provider *provider)
845845
{
846846
struct json_field fields[] = {
847-
{"issuer", JSON_TOKEN_STRING, {&provider->issuer}, REQUIRED},
848-
{"token_endpoint", JSON_TOKEN_STRING, {&provider->token_endpoint}, REQUIRED},
847+
{"issuer", JSON_TOKEN_STRING, {&provider->issuer}, PG_OAUTH_REQUIRED},
848+
{"token_endpoint", JSON_TOKEN_STRING, {&provider->token_endpoint}, PG_OAUTH_REQUIRED},
849849

850850
/*----
851851
* The following fields are technically REQUIRED, but we don't use
@@ -857,8 +857,8 @@ parse_provider(struct async_ctx *actx, struct provider *provider)
857857
* - id_token_signing_alg_values_supported
858858
*/
859859

860-
{"device_authorization_endpoint", JSON_TOKEN_STRING, {&provider->device_authorization_endpoint}, OPTIONAL},
861-
{"grant_types_supported", JSON_TOKEN_ARRAY_START, {.array = &provider->grant_types_supported}, OPTIONAL},
860+
{"device_authorization_endpoint", JSON_TOKEN_STRING, {&provider->device_authorization_endpoint}, PG_OAUTH_OPTIONAL},
861+
{"grant_types_supported", JSON_TOKEN_ARRAY_START, {.array = &provider->grant_types_supported}, PG_OAUTH_OPTIONAL},
862862

863863
{0},
864864
};
@@ -955,24 +955,24 @@ static bool
955955
parse_device_authz(struct async_ctx *actx, struct device_authz *authz)
956956
{
957957
struct json_field fields[] = {
958-
{"device_code", JSON_TOKEN_STRING, {&authz->device_code}, REQUIRED},
959-
{"user_code", JSON_TOKEN_STRING, {&authz->user_code}, REQUIRED},
960-
{"verification_uri", JSON_TOKEN_STRING, {&authz->verification_uri}, REQUIRED},
961-
{"expires_in", JSON_TOKEN_NUMBER, {&authz->expires_in_str}, REQUIRED},
958+
{"device_code", JSON_TOKEN_STRING, {&authz->device_code}, PG_OAUTH_REQUIRED},
959+
{"user_code", JSON_TOKEN_STRING, {&authz->user_code}, PG_OAUTH_REQUIRED},
960+
{"verification_uri", JSON_TOKEN_STRING, {&authz->verification_uri}, PG_OAUTH_REQUIRED},
961+
{"expires_in", JSON_TOKEN_NUMBER, {&authz->expires_in_str}, PG_OAUTH_REQUIRED},
962962

963963
/*
964964
* Some services (Google, Azure) spell verification_uri differently.
965965
* We accept either.
966966
*/
967-
{"verification_url", JSON_TOKEN_STRING, {&authz->verification_uri}, REQUIRED},
967+
{"verification_url", JSON_TOKEN_STRING, {&authz->verification_uri}, PG_OAUTH_REQUIRED},
968968

969969
/*
970970
* There is no evidence of verification_uri_complete being spelled
971971
* with "url" instead with any service provider, so only support
972972
* "uri".
973973
*/
974-
{"verification_uri_complete", JSON_TOKEN_STRING, {&authz->verification_uri_complete}, OPTIONAL},
975-
{"interval", JSON_TOKEN_NUMBER, {&authz->interval_str}, OPTIONAL},
974+
{"verification_uri_complete", JSON_TOKEN_STRING, {&authz->verification_uri_complete}, PG_OAUTH_OPTIONAL},
975+
{"interval", JSON_TOKEN_NUMBER, {&authz->interval_str}, PG_OAUTH_OPTIONAL},
976976

977977
{0},
978978
};
@@ -1010,9 +1010,9 @@ parse_token_error(struct async_ctx *actx, struct token_error *err)
10101010
{
10111011
bool result;
10121012
struct json_field fields[] = {
1013-
{"error", JSON_TOKEN_STRING, {&err->error}, REQUIRED},
1013+
{"error", JSON_TOKEN_STRING, {&err->error}, PG_OAUTH_REQUIRED},
10141014

1015-
{"error_description", JSON_TOKEN_STRING, {&err->error_description}, OPTIONAL},
1015+
{"error_description", JSON_TOKEN_STRING, {&err->error_description}, PG_OAUTH_OPTIONAL},
10161016

10171017
{0},
10181018
};
@@ -1069,8 +1069,8 @@ static bool
10691069
parse_access_token(struct async_ctx *actx, struct token *tok)
10701070
{
10711071
struct json_field fields[] = {
1072-
{"access_token", JSON_TOKEN_STRING, {&tok->access_token}, REQUIRED},
1073-
{"token_type", JSON_TOKEN_STRING, {&tok->token_type}, REQUIRED},
1072+
{"access_token", JSON_TOKEN_STRING, {&tok->access_token}, PG_OAUTH_REQUIRED},
1073+
{"token_type", JSON_TOKEN_STRING, {&tok->token_type}, PG_OAUTH_REQUIRED},
10741074

10751075
/*---
10761076
* We currently have no use for the following OPTIONAL fields:

0 commit comments

Comments
 (0)