* DefineExtprotocol */
| 45 | * DefineExtprotocol |
| 46 | */ |
| 47 | void |
| 48 | DefineExtProtocol(List *name, List *parameters, bool trusted) |
| 49 | { |
| 50 | char *protName; |
| 51 | List *readfuncName = NIL; |
| 52 | List *writefuncName = NIL; |
| 53 | List *validatorfuncName = NIL; |
| 54 | ListCell *pl; |
| 55 | Oid protOid; |
| 56 | |
| 57 | if (!superuser()) |
| 58 | ereport(ERROR, |
| 59 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 60 | errmsg("must be superuser to create an external protocol"))); |
| 61 | |
| 62 | protName = strVal(linitial(name)); |
| 63 | |
| 64 | foreach(pl, parameters) |
| 65 | { |
| 66 | DefElem *defel = (DefElem *) lfirst(pl); |
| 67 | |
| 68 | if (pg_strcasecmp(defel->defname, "readfunc") == 0) |
| 69 | readfuncName = defGetQualifiedName(defel); |
| 70 | else if (pg_strcasecmp(defel->defname, "writefunc") == 0) |
| 71 | writefuncName = defGetQualifiedName(defel); |
| 72 | else if (pg_strcasecmp(defel->defname, "validatorfunc") == 0) |
| 73 | validatorfuncName = defGetQualifiedName(defel); |
| 74 | else |
| 75 | ereport(ERROR, |
| 76 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 77 | errmsg("protocol attribute \"%s\" not recognized", |
| 78 | defel->defname))); |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * make sure we have our required definitions |
| 83 | */ |
| 84 | if (readfuncName == NULL && writefuncName == NULL) |
| 85 | ereport(ERROR, |
| 86 | (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), |
| 87 | errmsg("protocol must be specify at least a readfunc or a writefunc"))); |
| 88 | |
| 89 | |
| 90 | /* |
| 91 | * Most of the argument-checking is done inside of ExtProtocolCreate |
| 92 | */ |
| 93 | protOid = ExtProtocolCreate(protName, /* protocol name */ |
| 94 | readfuncName, /* read function name */ |
| 95 | writefuncName, /* write function name */ |
| 96 | validatorfuncName, /* validator function name */ |
| 97 | trusted); |
| 98 | |
| 99 | if (Gp_role == GP_ROLE_DISPATCH) |
| 100 | { |
| 101 | DefineStmt * stmt = makeNode(DefineStmt); |
| 102 | stmt->kind = OBJECT_EXTPROTOCOL; |
| 103 | stmt->oldstyle = false; |
| 104 | stmt->defnames = name; |
no test coverage detected