int _gnutls_x509_crl_get_extension_oid (gnutls_x509_crl_t crl, int indx, void *oid, size_t * sizeof_oid) { return get_extension_oid (crl->crl, "tbsCertList.crlExtensions", indx, oid, sizeof_oid); }
/* This function will attempt to return the requested extension OID found in * the given X509v3 certificate. * * If you have passed the last extension, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will * be returned. */ int _gnutls_x509_crt_get_extension_oid (gnutls_x509_crt_t cert, int indx, void *oid, size_t * sizeof_oid) { return get_extension_oid (cert->cert, "tbsCertificate.extensions", indx, oid, sizeof_oid); }
/* * HasPaxosTable returns whether the given list of range tables contains * a Paxos table. */ static bool HasPaxosTable(List *rangeTableList) { ListCell *rangeTableCell = NULL; /* if the extension isn't created, it is never a Paxos query */ bool missingOK = true; Oid extensionOid = get_extension_oid(PG_PAXOS_EXTENSION_NAME, missingOK); if (extensionOid == InvalidOid) { return false; } if (rangeTableList == NIL) { return false; } foreach(rangeTableCell, rangeTableList) { Oid rangeTableOid = ExtractTableOid((Node *) lfirst(rangeTableCell)); if (IsPaxosTable(rangeTableOid)) { return true; } }
Datum create_empty_extension(PG_FUNCTION_ARGS) { text *extName = PG_GETARG_TEXT_PP(0); text *schemaName = PG_GETARG_TEXT_PP(1); bool relocatable = PG_GETARG_BOOL(2); text *extVersion = PG_GETARG_TEXT_PP(3); Datum extConfig; Datum extCondition; List *requiredExtensions; if (PG_ARGISNULL(4)) extConfig = PointerGetDatum(NULL); else extConfig = PG_GETARG_DATUM(4); if (PG_ARGISNULL(5)) extCondition = PointerGetDatum(NULL); else extCondition = PG_GETARG_DATUM(5); requiredExtensions = NIL; if (!PG_ARGISNULL(6)) { ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6); Datum *textDatums; int ndatums; int i; deconstruct_array(textArray, TEXTOID, -1, false, 'i', &textDatums, NULL, &ndatums); for (i = 0; i < ndatums; i++) { text *txtname = DatumGetTextPP(textDatums[i]); char *extName = text_to_cstring(txtname); Oid extOid = get_extension_oid(extName, false); requiredExtensions = lappend_oid(requiredExtensions, extOid); } } InsertExtensionTuple(text_to_cstring(extName), GetUserId(), get_namespace_oid(text_to_cstring(schemaName), false), relocatable, text_to_cstring(extVersion), extConfig, extCondition, requiredExtensions); PG_RETURN_VOID(); }
Datum binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS) { text *extName; text *schemaName; bool relocatable; text *extVersion; Datum extConfig; Datum extCondition; List *requiredExtensions; CHECK_IS_BINARY_UPGRADE; /* We must check these things before dereferencing the arguments */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3)) elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed"); extName = PG_GETARG_TEXT_PP(0); schemaName = PG_GETARG_TEXT_PP(1); relocatable = PG_GETARG_BOOL(2); extVersion = PG_GETARG_TEXT_PP(3); if (PG_ARGISNULL(4)) extConfig = PointerGetDatum(NULL); else extConfig = PG_GETARG_DATUM(4); if (PG_ARGISNULL(5)) extCondition = PointerGetDatum(NULL); else extCondition = PG_GETARG_DATUM(5); requiredExtensions = NIL; if (!PG_ARGISNULL(6)) { ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6); Datum *textDatums; int ndatums; int i; deconstruct_array(textArray, TEXTOID, -1, false, 'i', &textDatums, NULL, &ndatums); for (i = 0; i < ndatums; i++) { text *txtname = DatumGetTextPP(textDatums[i]); char *extName = text_to_cstring(txtname); Oid extOid = get_extension_oid(extName, false); requiredExtensions = lappend_oid(requiredExtensions, extOid); } } InsertExtensionTuple(text_to_cstring(extName), GetUserId(), get_namespace_oid(text_to_cstring(schemaName), false), relocatable, text_to_cstring(extVersion), extConfig, extCondition, requiredExtensions); PG_RETURN_VOID(); }
/* * Find an struct objaddr for a type of object that is identified by an * unqualified name. */ static struct objaddr get_objaddr_unqualified(objtype_e objtype, struct list *qualname) { const char *name; struct objaddr address; /* * The types of names handled by this function are not permitted to be * schema-qualified or catalog-qualified. */ if (list_length(qualname) != 1) { const char *msg; switch (objtype) { case OBJECT_DATABASE: msg = gettext_noop("database name cannot be qualified"); break; case OBJECT_EXTENSION: msg = gettext_noop("extension name cannot be qualified"); break; case OBJECT_TABLESPACE: msg = gettext_noop("tablespace name cannot be qualified"); break; case OBJECT_ROLE: msg = gettext_noop("role name cannot be qualified"); break; case OBJECT_SCHEMA: msg = gettext_noop("schema name cannot be qualified"); break; case OBJECT_LANGUAGE: msg = gettext_noop("language name cannot be qualified"); break; case OBJECT_FDW: msg = gettext_noop("foreign-data wrapper name cannot be qualified"); break; case OBJECT_FOREIGN_SERVER: msg = gettext_noop("server name cannot be qualified"); break; default: elog(ERROR, "unrecognized objtype: %d", (int) objtype); msg = NULL; /* placate compiler */ } ereport(ERROR, ( errcode(E_SYNTAX_ERROR), errmsg("%s", _(msg)))); } /* Format is valid, extract the actual name. */ name = str_value(linitial(qualname)); /* Translate name to OID. */ switch (objtype) { case OBJECT_DATABASE: address.classId = DatabaseRelationId; address.objectId = get_db_oid(name, false); address.objectSubId = 0; break; case OBJECT_EXTENSION: address.classId = ExtensionRelationId; address.objectId = get_extension_oid(name, false); address.objectSubId = 0; break; case OBJECT_TABLESPACE: address.classId = TableSpaceRelationId; address.objectId = tbs_get_oid(name, false); address.objectSubId = 0; break; case OBJECT_ROLE: address.classId = AuthIdRelationId; address.objectId = get_role_oid(name, false); address.objectSubId = 0; break; case OBJECT_SCHEMA: address.classId = NAMESPACE_RELATION_ID; address.objectId = get_ns_oid(name, false); address.objectSubId = 0; break; case OBJECT_LANGUAGE: address.classId = LanguageRelationId; address.objectId = get_lang_oid(name, false); address.objectSubId = 0; break; case OBJECT_FDW: address.classId = ForeignDataWrapperRelationId; address.objectId = get_fdw_oid(name, false); address.objectSubId = 0; break; case OBJECT_FOREIGN_SERVER: address.classId = ForeignServerRelationId; address.objectId = get_foreign_server_oid(name, false); address.objectSubId = 0; break; default: elog(ERROR, "unrecognized objtype: %d", (int) objtype); /* placate compiler, which doesn't know elog won't return */ address.classId = INVALID_OID; address.objectId = INVALID_OID; address.objectSubId = 0; } return address; }
/* * Find an ObjectAddress for a type of object that is identified by an * unqualified name. */ static ObjectAddress get_object_address_unqualified(ObjectType objtype, List *qualname) { const char *name; ObjectAddress address; /* * The types of names handled by this function are not permitted to be * schema-qualified or catalog-qualified. */ if (list_length(qualname) != 1) { const char *msg; switch (objtype) { case OBJECT_DATABASE: msg = gettext_noop("database name cannot be qualified"); break; case OBJECT_EXTENSION: msg = gettext_noop("extension name cannot be qualified"); break; case OBJECT_TABLESPACE: msg = gettext_noop("tablespace name cannot be qualified"); break; case OBJECT_ROLE: msg = gettext_noop("role name cannot be qualified"); break; case OBJECT_SCHEMA: msg = gettext_noop("schema name cannot be qualified"); break; case OBJECT_LANGUAGE: msg = gettext_noop("language name cannot be qualified"); break; default: elog(ERROR, "unrecognized objtype: %d", (int) objtype); msg = NULL; /* placate compiler */ } ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("%s", _(msg)))); } /* Format is valid, extract the actual name. */ name = strVal(linitial(qualname)); /* Translate name to OID. */ switch (objtype) { case OBJECT_DATABASE: address.classId = DatabaseRelationId; address.objectId = get_database_oid(name, false); address.objectSubId = 0; break; case OBJECT_EXTENSION: address.classId = ExtensionRelationId; address.objectId = get_extension_oid(name, false); address.objectSubId = 0; break; case OBJECT_TABLESPACE: address.classId = TableSpaceRelationId; address.objectId = get_tablespace_oid(name, false); address.objectSubId = 0; break; case OBJECT_ROLE: address.classId = AuthIdRelationId; address.objectId = get_role_oid(name, false); address.objectSubId = 0; break; case OBJECT_SCHEMA: address.classId = NamespaceRelationId; address.objectId = get_namespace_oid(name, false); address.objectSubId = 0; break; case OBJECT_LANGUAGE: address.classId = LanguageRelationId; address.objectId = get_language_oid(name, false); address.objectSubId = 0; break; default: elog(ERROR, "unrecognized objtype: %d", (int) objtype); /* placate compiler, which doesn't know elog won't return */ address.classId = InvalidOid; address.objectId = InvalidOid; address.objectSubId = 0; } return address; }
/* LocalTableSize returns the size on disk of the given table. */ static uint64 LocalTableSize(Oid relationId) { uint64 tableSize = 0; char relationType = 0; Datum relationIdDatum = ObjectIdGetDatum(relationId); relationType = get_rel_relkind(relationId); if (relationType == RELKIND_RELATION) { Datum tableSizeDatum = DirectFunctionCall1(pg_table_size, relationIdDatum); tableSize = DatumGetInt64(tableSizeDatum); } else if (relationType == RELKIND_FOREIGN_TABLE) { bool cstoreTable = CStoreTable(relationId); if (cstoreTable) { /* extract schema name of cstore */ Oid cstoreId = get_extension_oid(CSTORE_FDW_NAME, false); Oid cstoreSchemaOid = get_extension_schema(cstoreId); const char *cstoreSchemaName = get_namespace_name(cstoreSchemaOid); const int tableSizeArgumentCount = 1; Oid tableSizeFunctionOid = FunctionOid(cstoreSchemaName, CSTORE_TABLE_SIZE_FUNCTION_NAME, tableSizeArgumentCount); Datum tableSizeDatum = OidFunctionCall1(tableSizeFunctionOid, relationIdDatum); tableSize = DatumGetInt64(tableSizeDatum); } else { char *relationName = get_rel_name(relationId); struct stat fileStat; int statOK = 0; StringInfo localFilePath = makeStringInfo(); appendStringInfo(localFilePath, FOREIGN_CACHED_FILE_PATH, relationName); /* extract the file size using stat, analogous to pg_stat_file */ statOK = stat(localFilePath->data, &fileStat); if (statOK < 0) { ereport(ERROR, (errcode_for_file_access(), errmsg("could not stat file \"%s\": %m", localFilePath->data))); } tableSize = (uint64) fileStat.st_size; } } else { char *relationName = get_rel_name(relationId); ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot get size for table \"%s\"", relationName), errdetail("Only regular and foreign tables are supported."))); } return tableSize; }