* ExtProtocolCreate */
| 47 | * ExtProtocolCreate |
| 48 | */ |
| 49 | Oid |
| 50 | ExtProtocolCreate(const char *protocolName, |
| 51 | List *readfuncName, |
| 52 | List *writefuncName, |
| 53 | List *validatorfuncName, |
| 54 | bool trusted) |
| 55 | { |
| 56 | Relation rel; |
| 57 | HeapTuple tup; |
| 58 | bool nulls[Natts_pg_extprotocol]; |
| 59 | Datum values[Natts_pg_extprotocol]; |
| 60 | Oid readfn = InvalidOid; |
| 61 | Oid writefn = InvalidOid; |
| 62 | Oid validatorfn = InvalidOid; |
| 63 | NameData prtname; |
| 64 | int i; |
| 65 | ObjectAddress myself, |
| 66 | referenced; |
| 67 | Oid ownerId = GetUserId(); |
| 68 | ScanKeyData skey; |
| 69 | SysScanDesc scan; |
| 70 | Oid protOid; |
| 71 | |
| 72 | /* sanity checks (caller should have caught these) */ |
| 73 | if (!protocolName) |
| 74 | elog(ERROR, "no protocol name supplied"); |
| 75 | |
| 76 | if (!readfuncName && !writefuncName) |
| 77 | elog(ERROR, "protocol must have at least one of readfunc or writefunc"); |
| 78 | |
| 79 | /* |
| 80 | * Until we add system protocols to pg_extprotocol, make sure no |
| 81 | * protocols with the same name are created. |
| 82 | */ |
| 83 | if (strcasecmp(protocolName, "file") == 0 || |
| 84 | strcasecmp(protocolName, "http") == 0 || |
| 85 | strcasecmp(protocolName, "gpfdist") == 0 || |
| 86 | strcasecmp(protocolName, "gpfdists") == 0) |
| 87 | { |
| 88 | ereport(ERROR, |
| 89 | (errcode(ERRCODE_RESERVED_NAME), |
| 90 | errmsg("protocol \"%s\" already exists", |
| 91 | protocolName), |
| 92 | errhint("pick a different protocol name"))); |
| 93 | } |
| 94 | |
| 95 | rel = table_open(ExtprotocolRelationId, RowExclusiveLock); |
| 96 | |
| 97 | /* make sure there is no existing protocol of same name */ |
| 98 | ScanKeyInit(&skey, |
| 99 | Anum_pg_extprotocol_ptcname, |
| 100 | BTEqualStrategyNumber, F_NAMEEQ, |
| 101 | CStringGetDatum(protocolName)); |
| 102 | scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true, |
| 103 | NULL, 1, &skey); |
| 104 | tup = systable_getnext(scan); |
| 105 | if (HeapTupleIsValid(tup)) |
| 106 | ereport(ERROR, |
no test coverage detected