#include "dbms/owa.h" #include extern "C" { #include "access/xact.h" #include "utils/builtins.h" #include "utils/elog.h" #include "utils/numeric.h" #include "utils/timestamp.h" } namespace Owa { static std::string normalizeCacheLevel(const std::string &cache_level) { std::string normalizedLevel; normalizedLevel.reserve(cache_level.size()); for (unsigned char ch : cache_level) { normalizedLevel.push_back(pg_toupper(ch)); } return normalizedLevel; } void validateCacheEtag(const std::string &etag_value) { validateHeaderValue(etag_value, "p_etag"); if (etag_value.length() > 55) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_CACHE parameter p_etag is longer than 55 characters."))); } } std::string validateAndNormalizeCacheLevel(const std::string &level_value) { std::string normalizedLevel; validateHeaderValue(level_value, "p_level"); normalizedLevel = normalizeCacheLevel(level_value); if (normalizedLevel != "USER" && normalizedLevel != "SYSTEM") { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_CACHE parameter p_level must be USER or SYSTEM."))); } return normalizedLevel; } std::string renderCacheHeaders(const std::string &etag_value, const std::string &level_value) { std::string out; const char *cacheScope = (level_value == "USER") ? "private" : "public"; out.reserve(etag_value.size() + level_value.size() + 96); out += "ETag: \""; out += etag_value; out += "\"\n"; out += "Cache-Control: no-cache, "; out += cacheScope; out += "\n"; return out; } void validateCacheExpires(int32 expires_value) { if (expires_value <= 0 || expires_value > 525600) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_EXPIRES parameter p_expires must be between 1 and 525600."))); } } void validateSurrogateControlValue(const std::string &value) { validateHeaderValue(value, "p_value"); if (value.length() > 55) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_SURROGATE_CONTROL parameter p_value is longer than 55 characters."))); } } std::string renderExpiresHeaders(int32 expires_value, const std::string &level_value) { TimestampTz expiresTimestamp; text *expiresText = nullptr; char *expiresCString = nullptr; std::string out; const char *cacheScope = (level_value == "USER") ? "private" : "public"; expiresTimestamp = DatumGetTimestampTz(DirectFunctionCall2(timestamp_pl_interval, TimestampTzGetDatum(GetCurrentTimestamp()), DirectFunctionCall7(make_interval, Int32GetDatum(0), Int32GetDatum(0), Int32GetDatum(0), Int32GetDatum(0), Int32GetDatum(0), Int32GetDatum(expires_value), Float8GetDatum(0.0)))); expiresText = DatumGetTextPP(DirectFunctionCall2(timestamptz_to_char, TimestampTzGetDatum(expiresTimestamp), CStringGetTextDatum("Dy, DD Mon YYYY HH24:MI:SS \"GMT\""))); expiresCString = text_to_cstring(expiresText); out.reserve(strlen(expiresCString) + level_value.size() + 96); out += "Cache-Control: max-age="; out += std::to_string(expires_value * 60); out += ", "; out += cacheScope; out += "\n"; out += "Expires: "; out += expiresCString; out += "\n"; pfree(expiresCString); return out; } } /* namespace Owa */ extern "C" { PG_FUNCTION_INFO_V1(owa_cache_set_cache); PG_FUNCTION_INFO_V1(owa_cache_set_expires); PG_FUNCTION_INFO_V1(owa_cache_set_not_modified); PG_FUNCTION_INFO_V1(owa_cache_disable); PG_FUNCTION_INFO_V1(owa_cache_set_surrogate_control); PG_FUNCTION_INFO_V1(owa_cache_set_request_etag); PG_FUNCTION_INFO_V1(owa_cache_set_request_level); PG_FUNCTION_INFO_V1(owa_cache_get_etag); PG_FUNCTION_INFO_V1(owa_cache_get_etag2); PG_FUNCTION_INFO_V1(owa_cache_get_level); Datum owa_cache_disable(PG_FUNCTION_ARGS) { Owa::EventEntry ev; Owa::PageContext *ctx = Owa::current_page_context_; ereport(LOG, (errmsg("OWA_CACHE.DISABLE request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.DISABLE initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (ctx->state != Owa::PageState::HeadersOpen) { ereport(LOG, (errmsg("OWA_CACHE.DISABLE called after body started"), errdetail("page_state=%s", "BodyStarted"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.DISABLE must be called in HTTP header context"))); } ev.kind = Owa::EventKind::Cache; ev.subxid = GetCurrentSubTransactionId(); ev.cacheDisabled = true; ctx->events.push_back(std::move(ev)); ereport(LOG, (errmsg("OWA_CACHE.DISABLE stored disable cache headers"), errdetail("events_count=%zu", ctx->events.size()))); PG_RETURN_VOID(); } Datum owa_cache_set_cache(PG_FUNCTION_ARGS) { Owa::EventEntry ev; Owa::PageContext *ctx = Owa::current_page_context_; std::string etagValue; std::string levelValue; std::string normalizedLevel; ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1)) { ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE invalid NULL parameter"), errdetail("p_etag_is_null=%s, p_level_is_null=%s", (PG_NARGS() < 1 || PG_ARGISNULL(0)) ? "true" : "false", (PG_NARGS() < 2 || PG_ARGISNULL(1)) ? "true" : "false"))); ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_CACHE parameters p_etag and p_level must not be NULL."))); } if (ctx->state != Owa::PageState::HeadersOpen) { ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE called after body started"), errdetail("page_state=%s", "BodyStarted"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.SET_CACHE must be called in HTTP header context"))); } etagValue = Owa::textToString(PG_GETARG_TEXT_PP(0)); levelValue = Owa::textToString(PG_GETARG_TEXT_PP(1)); ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE parameters"), errdetail("p_etag=\"%s\", p_etag_length=%zu, p_level=\"%s\"", etagValue.c_str(), etagValue.length(), levelValue.c_str()))); Owa::validateCacheEtag(etagValue); normalizedLevel = Owa::validateAndNormalizeCacheLevel(levelValue); ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE normalized"), errdetail("normalized_level=\"%s\"", normalizedLevel.c_str()))); ev.kind = Owa::EventKind::Cache; ev.subxid = GetCurrentSubTransactionId(); ev.cacheEtag = std::move(etagValue); ev.cacheLevel = std::move(normalizedLevel); ctx->events.push_back(std::move(ev)); ereport(LOG, (errmsg("OWA_CACHE.SET_CACHE stored cache headers"), errdetail("events_count=%zu", ctx->events.size()))); PG_RETURN_VOID(); } Datum owa_cache_set_expires(PG_FUNCTION_ARGS) { Owa::EventEntry ev; Owa::PageContext *ctx = Owa::current_page_context_; Numeric expiresNumeric = nullptr; int32 expiresValue; std::string levelValue; std::string normalizedLevel; ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1)) { ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES invalid NULL parameter"), errdetail("p_expires_is_null=%s, p_level_is_null=%s", (PG_NARGS() < 1 || PG_ARGISNULL(0)) ? "true" : "false", (PG_NARGS() < 2 || PG_ARGISNULL(1)) ? "true" : "false"))); ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_EXPIRES parameters p_expires and p_level must not be NULL."))); } if (ctx->state != Owa::PageState::HeadersOpen) { ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES called after body started"), errdetail("page_state=%s", "BodyStarted"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.SET_EXPIRES must be called in HTTP header context"))); } expiresNumeric = PG_GETARG_NUMERIC(0); expiresValue = DatumGetInt32(DirectFunctionCall1(numeric_int4, NumericGetDatum(expiresNumeric))); levelValue = Owa::textToString(PG_GETARG_TEXT_PP(1)); ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES parameters"), errdetail("p_expires=%d, p_level=\"%s\"", expiresValue, levelValue.c_str()))); Owa::validateCacheExpires(expiresValue); normalizedLevel = Owa::validateAndNormalizeCacheLevel(levelValue); ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES normalized"), errdetail("normalized_level=\"%s\", p_expires=%d", normalizedLevel.c_str(), expiresValue))); ev.kind = Owa::EventKind::Cache; ev.subxid = GetCurrentSubTransactionId(); ev.cacheLevel = std::move(normalizedLevel); ev.cacheExpires = expiresValue; ctx->events.push_back(std::move(ev)); ereport(LOG, (errmsg("OWA_CACHE.SET_EXPIRES stored cache headers"), errdetail("events_count=%zu", ctx->events.size()))); PG_RETURN_VOID(); } Datum owa_cache_set_request_etag(PG_FUNCTION_ARGS) { Owa::PageContext *ctx = Owa::current_page_context_; std::string etagValue; ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_ETAG request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_ETAG initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (PG_NARGS() < 1 || PG_ARGISNULL(0)) { ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_ETAG invalid NULL parameter"), errdetail("p_etag_is_null=%s", (PG_NARGS() < 1 || PG_ARGISNULL(0)) ? "true" : "false"))); ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_REQUEST_ETAG parameter p_etag must not be NULL."))); } etagValue = Owa::textToString(PG_GETARG_TEXT_PP(0)); ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_ETAG parameters"), errdetail("p_etag=\"%s\", p_etag_length=%zu", etagValue.c_str(), etagValue.length()))); Owa::validateHeaderValue(etagValue, "p_etag"); if (etagValue.length() > 55) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_REQUEST_ETAG parameter p_etag is longer than 55 characters."))); } ctx->hasRequestCacheEtag = true; ctx->requestCacheEtag = std::move(etagValue); ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_ETAG stored request cache context"), errdetail("etag_length=%zu", ctx->requestCacheEtag.length()))); PG_RETURN_VOID(); } Datum owa_cache_set_surrogate_control(PG_FUNCTION_ARGS) { Owa::EventEntry ev; Owa::PageContext *ctx = Owa::current_page_context_; std::string value; ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (PG_NARGS() < 1 || PG_ARGISNULL(0)) { ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL invalid NULL parameter"), errdetail("p_value_is_null=%s", (PG_NARGS() < 1 || PG_ARGISNULL(0)) ? "true" : "false"))); ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_SURROGATE_CONTROL parameter p_value must not be NULL."))); } if (ctx->state != Owa::PageState::HeadersOpen) { ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL called after body started"), errdetail("page_state=%s", "BodyStarted"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.SET_SURROGATE_CONTROL must be called in HTTP header context"))); } value = Owa::textToString(PG_GETARG_TEXT_PP(0)); ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL parameters"), errdetail("p_value=\"%s\", p_value_length=%zu", value.c_str(), value.length()))); Owa::validateSurrogateControlValue(value); ev.kind = Owa::EventKind::Cache; ev.subxid = GetCurrentSubTransactionId(); ev.cacheSurrogateControl = std::move(value); ctx->events.push_back(std::move(ev)); ereport(LOG, (errmsg("OWA_CACHE.SET_SURROGATE_CONTROL stored surrogate control"), errdetail("events_count=%zu", ctx->events.size()))); PG_RETURN_VOID(); } Datum owa_cache_set_not_modified(PG_FUNCTION_ARGS) { Owa::PageContext *ctx = Owa::current_page_context_; const Owa::EventEntry *cacheEvent = nullptr; Owa::EventEntry ev; text *requestProtocolText = nullptr; std::string requestProtocol; ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (!ctx->hasRequestCacheEtag) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED missing request etag"), errdetail("request_cache_etag=absent"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_NOT_MODIFIED requires request If-None-Match etag."))); } if (ctx->state != Owa::PageState::HeadersOpen) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED called after body started"), errdetail("page_state=%s", "BodyStarted"))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.SET_NOT_MODIFIED must be called in HTTP header context"))); } for (auto it = ctx->events.rbegin(); it != ctx->events.rend(); ++it) { if (it->kind != Owa::EventKind::Cache) { continue; } if (it->cacheEtag.empty()) { continue; } cacheEvent = &(*it); break; } if (cacheEvent == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED missing response cache metadata"), errdetail("request_etag=\"%s\"", ctx->requestCacheEtag.c_str()))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_NOT_MODIFIED requires a prior OWA_CACHE.SET_CACHE call."))); } ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED compare"), errdetail("request_etag=\"%s\", response_etag=\"%s\", response_level=\"%s\"", ctx->requestCacheEtag.c_str(), cacheEvent->cacheEtag.c_str(), cacheEvent->cacheLevel.c_str()))); if (ctx->requestCacheEtag != cacheEvent->cacheEtag) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED etag mismatch"), errdetail("request_etag=\"%s\", response_etag=\"%s\"", ctx->requestCacheEtag.c_str(), cacheEvent->cacheEtag.c_str()))); PG_RETURN_VOID(); } if (ctx->hasRequestCacheLevel && ctx->requestCacheLevel != cacheEvent->cacheLevel) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED level mismatch"), errdetail("request_level=\"%s\", response_level=\"%s\"", ctx->requestCacheLevel.c_str(), cacheEvent->cacheLevel.c_str()))); PG_RETURN_VOID(); } requestProtocolText = DatumGetTextPP(DirectFunctionCall1(owa_util_get_cgi_env, CStringGetTextDatum("REQUEST_PROTOCOL"))); if (requestProtocolText == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED missing request protocol"), errdetail("request_etag=\"%s\", response_etag=\"%s\"", ctx->requestCacheEtag.c_str(), cacheEvent->cacheEtag.c_str()))); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.SET_NOT_MODIFIED requires REQUEST_PROTOCOL for 304 response"))); } requestProtocol = Owa::textToString(requestProtocolText); Owa::validateHeaderValue(requestProtocol, "request_protocol"); ev.kind = Owa::EventKind::Status; ev.subxid = GetCurrentSubTransactionId(); ev.statusCode = 304; ev.statusReason = "Not Modified"; ctx->events.push_back(std::move(ev)); ereport(LOG, (errmsg("OWA_CACHE.SET_NOT_MODIFIED stored status line"), errdetail("status_code=%d, reason=\"%s\", request_protocol=\"%s\", events_count=%zu", 304, "Not Modified", requestProtocol.c_str(), ctx->events.size()))); PG_RETURN_VOID(); } Datum owa_cache_set_request_level(PG_FUNCTION_ARGS) { Owa::PageContext *ctx = Owa::current_page_context_; std::string levelValue; std::string normalizedLevel; ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_LEVEL request"), errdetail("nargs=%d, ctx=%s", PG_NARGS(), ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_LEVEL initializing request context"), errdetail("reason=no active OWA page context"))); Owa::ensurePageContextViaServiceInit(); ctx = Owa::current_page_context_; } if (PG_NARGS() < 1 || PG_ARGISNULL(0)) { ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_LEVEL invalid NULL parameter"), errdetail("p_level_is_null=%s", (PG_NARGS() < 1 || PG_ARGISNULL(0)) ? "true" : "false"))); ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_REQUEST_LEVEL parameter p_level must not be NULL."))); } levelValue = Owa::textToString(PG_GETARG_TEXT_PP(0)); ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_LEVEL parameters"), errdetail("p_level=\"%s\"", levelValue.c_str()))); Owa::validateHeaderValue(levelValue, "p_level"); normalizedLevel.reserve(levelValue.size()); for (unsigned char ch : levelValue) { normalizedLevel.push_back(pg_toupper(ch)); } if (normalizedLevel != "USER" && normalizedLevel != "SYSTEM") { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ORA-06502: PL/SQL: numeric or value error"), errdetail("OWA_CACHE.SET_REQUEST_LEVEL parameter p_level must be USER or SYSTEM."))); } ctx->hasRequestCacheLevel = true; ctx->requestCacheLevel = std::move(normalizedLevel); ereport(LOG, (errmsg("OWA_CACHE.SET_REQUEST_LEVEL stored request cache context"), errdetail("normalized_level=\"%s\"", ctx->requestCacheLevel.c_str()))); PG_RETURN_VOID(); } Datum owa_cache_get_etag(PG_FUNCTION_ARGS) { Owa::PageContext *ctx = Owa::current_page_context_; (void) fcinfo; ereport(LOG, (errmsg("OWA_CACHE.GET_ETAG request"), errdetail("ctx=%s", ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.GET_ETAG result"), errdetail("etag=null, reason=no active OWA page context"))); PG_RETURN_NULL(); } if (!ctx->hasRequestCacheEtag) { ereport(LOG, (errmsg("OWA_CACHE.GET_ETAG result"), errdetail("etag=null, reason=request cache etag is absent"))); PG_RETURN_NULL(); } ereport(LOG, (errmsg("OWA_CACHE.GET_ETAG result"), errdetail("etag=\"%s\", etag_length=%zu", ctx->requestCacheEtag.c_str(), ctx->requestCacheEtag.length()))); PG_RETURN_TEXT_P(cstring_to_text(ctx->requestCacheEtag.c_str())); } Datum owa_cache_get_etag2(PG_FUNCTION_ARGS) { int32 serviceArg = 0; if (PG_NARGS() != 1) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("OWA_CACHE.GET_ETAG2 accepts exactly 1 argument"))); } if (!PG_ARGISNULL(0)) { serviceArg = PG_GETARG_INT32(0); } (void) serviceArg; return owa_cache_get_etag(fcinfo); } Datum owa_cache_get_level(PG_FUNCTION_ARGS) { Owa::PageContext *ctx = Owa::current_page_context_; (void) fcinfo; ereport(LOG, (errmsg("OWA_CACHE.GET_LEVEL request"), errdetail("ctx=%s", ctx == nullptr ? "null" : "present"))); if (ctx == nullptr) { ereport(LOG, (errmsg("OWA_CACHE.GET_LEVEL result"), errdetail("level=null, reason=no active OWA page context"))); PG_RETURN_NULL(); } if (!ctx->hasRequestCacheLevel) { ereport(LOG, (errmsg("OWA_CACHE.GET_LEVEL result"), errdetail("level=null, reason=request cache level is absent"))); PG_RETURN_NULL(); } ereport(LOG, (errmsg("OWA_CACHE.GET_LEVEL result"), errdetail("level=\"%s\"", ctx->requestCacheLevel.c_str()))); PG_RETURN_TEXT_P(cstring_to_text(ctx->requestCacheLevel.c_str())); } } /* extern "C" */