1/*-------------------------------------------------------------------------
2 *
3 * foreign.h
4 * support for foreign-data wrappers, servers and user mappings.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 *
9 * src/include/foreign/foreign.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef FOREIGN_H
14#define FOREIGN_H
15
16#include "nodes/parsenodes.h"
17
18
19/* Helper for obtaining username for user mapping */
20#define MappingUserName(userid) \
21 (OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public")
22
23
24/*
25 * Generic option types for validation.
26 * NB! These are treated as flags, so use only powers of two here.
27 */
28typedef enum
29{
30 ServerOpt = 1, /* options applicable to SERVER */
31 UserMappingOpt = 2, /* options for USER MAPPING */
32 FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */
33} GenericOptionFlags;
34
35typedef struct ForeignDataWrapper
36{
37 Oid fdwid; /* FDW Oid */
38 Oid owner; /* FDW owner user Oid */
39 char *fdwname; /* Name of the FDW */
40 Oid fdwhandler; /* Oid of handler function, or 0 */
41 Oid fdwvalidator; /* Oid of validator function, or 0 */
42 List *options; /* fdwoptions as DefElem list */
43} ForeignDataWrapper;
44
45typedef struct ForeignServer
46{
47 Oid serverid; /* server Oid */
48 Oid fdwid; /* foreign-data wrapper */
49 Oid owner; /* server owner user Oid */
50 char *servername; /* name of the server */
51 char *servertype; /* server type, optional */
52 char *serverversion; /* server version, optional */
53 List *options; /* srvoptions as DefElem list */
54} ForeignServer;
55
56typedef struct UserMapping
57{
58 Oid umid; /* Oid of user mapping */
59 Oid userid; /* local user Oid */
60 Oid serverid; /* server Oid */
61 List *options; /* useoptions as DefElem list */
62} UserMapping;
63
64typedef struct ForeignTable
65{
66 Oid relid; /* relation Oid */
67 Oid serverid; /* server Oid */
68 List *options; /* ftoptions as DefElem list */
69} ForeignTable;
70
71/* Flags for GetForeignServerExtended */
72#define FSV_MISSING_OK 0x01
73
74/* Flags for GetForeignDataWrapperExtended */
75#define FDW_MISSING_OK 0x01
76
77
78extern ForeignServer *GetForeignServer(Oid serverid);
79extern ForeignServer *GetForeignServerExtended(Oid serverid,
80 bits16 flags);
81extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok);
82extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
83extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid);
84extern ForeignDataWrapper *GetForeignDataWrapperExtended(Oid fdwid,
85 bits16 flags);
86extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name,
87 bool missing_ok);
88extern ForeignTable *GetForeignTable(Oid relid);
89
90extern List *GetForeignColumnOptions(Oid relid, AttrNumber attnum);
91
92extern Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok);
93extern Oid get_foreign_server_oid(const char *servername, bool missing_ok);
94
95#endif /* FOREIGN_H */
96