| 1 | // $Id$ |
|---|
| 2 | |
|---|
| 3 | #include <string> |
|---|
| 4 | #include <map> |
|---|
| 5 | #include <fstream> |
|---|
| 6 | |
|---|
| 7 | #include <oci.h> |
|---|
| 8 | |
|---|
| 9 | #include "pdns/namespaces.hh" |
|---|
| 10 | |
|---|
| 11 | class OracleException : public DBException |
|---|
| 12 | { |
|---|
| 13 | public: |
|---|
| 14 | |
|---|
| 15 | OracleException (string r) : DBException(r) {} |
|---|
| 16 | |
|---|
| 17 | OracleException (string context, OCIError *theErrorHandle) |
|---|
| 18 | : DBException(context + ": ORA-UNKNOWN") |
|---|
| 19 | { |
|---|
| 20 | if (theErrorHandle != NULL) { |
|---|
| 21 | char msg[2048]; |
|---|
| 22 | sb4 errcode = 0; |
|---|
| 23 | |
|---|
| 24 | msg[0] = '\0'; |
|---|
| 25 | |
|---|
| 26 | OCIErrorGet((void *) theErrorHandle, 1, NULL, &errcode, (OraText*) msg, |
|---|
| 27 | sizeof(msg), OCI_HTYPE_ERROR); |
|---|
| 28 | |
|---|
| 29 | reason = context + ": " + msg; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | class OracleBackend : public DNSBackend |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | |
|---|
| 39 | OracleBackend(const string &suffix = "", OCIEnv *envh = |
|---|
| 40 | NULL, char *poolname = NULL); |
|---|
| 41 | virtual ~OracleBackend(); |
|---|
| 42 | |
|---|
| 43 | void lookup(const QType &qtype, const string &qname, DNSPacket *p = 0, |
|---|
| 44 | int zoneId = -1); |
|---|
| 45 | bool getBeforeAndAfterNames(uint32_t zoneId, const string& zone, |
|---|
| 46 | const string& name, |
|---|
| 47 | string& before, string& after); |
|---|
| 48 | bool getBeforeAndAfterNamesAbsolute(uint32_t zoneId, |
|---|
| 49 | const string& name, |
|---|
| 50 | string& unhashed, |
|---|
| 51 | string& before, |
|---|
| 52 | string& after); |
|---|
| 53 | bool get(DNSResourceRecord &rr); |
|---|
| 54 | vector<string> getDomainMasters(const string &domain, int zoneId); |
|---|
| 55 | bool isMaster(const string &domain, const string &master); |
|---|
| 56 | bool getDomainInfo(const string &domain, DomainInfo &di); |
|---|
| 57 | void alsoNotifies(const string &domain, set<string> *addrs); |
|---|
| 58 | void getUnfreshSlaveInfos(vector<DomainInfo>* domains); |
|---|
| 59 | void getUpdatedMasters(vector<DomainInfo>* domains); |
|---|
| 60 | void setFresh(uint32_t zoneId); // No, it's not int zoneId. Really. |
|---|
| 61 | void setNotified(uint32_t zoneId, uint32_t serial); // dito |
|---|
| 62 | bool list(const string &domain, int zoneId); |
|---|
| 63 | bool checkACL(const string &acl_type, const string &key, const string &val); |
|---|
| 64 | |
|---|
| 65 | bool startTransaction(const string &domain, int zoneId); |
|---|
| 66 | bool feedRecord(const DNSResourceRecord &rr); |
|---|
| 67 | bool commitTransaction(); |
|---|
| 68 | bool abortTransaction(); |
|---|
| 69 | bool superMasterBackend(const string &ip, const string &domain, |
|---|
| 70 | const vector<DNSResourceRecord> &nsset, |
|---|
| 71 | string *account, DNSBackend **backend); |
|---|
| 72 | bool createSlaveDomain(const string &ip, const string &domain, |
|---|
| 73 | const string &account); |
|---|
| 74 | |
|---|
| 75 | bool getDomainMetadata(const string& name, const std::string& kind, std::vector<std::string>& meta); |
|---|
| 76 | bool setDomainMetadata(const string& name, const std::string& kind, const std::vector<std::string>& meta); |
|---|
| 77 | |
|---|
| 78 | bool getDomainKeys(const string& name, unsigned int kind, vector<KeyData>& keys); |
|---|
| 79 | bool removeDomainKey(const string& name, unsigned int id); |
|---|
| 80 | int addDomainKey(const string& name, const KeyData& key); |
|---|
| 81 | bool activateDomainKey(const string& name, unsigned int id); |
|---|
| 82 | bool deactivateDomainKey(const string& name, unsigned int id); |
|---|
| 83 | |
|---|
| 84 | private: |
|---|
| 85 | |
|---|
| 86 | OCIEnv *mEnvironmentHandle; |
|---|
| 87 | OCIError *mErrorHandle; |
|---|
| 88 | OCISvcCtx *mServiceContextHandle; |
|---|
| 89 | |
|---|
| 90 | string basicQuerySQL; |
|---|
| 91 | OCIStmt *basicQueryHandle; |
|---|
| 92 | string basicIdQuerySQL; |
|---|
| 93 | OCIStmt *basicIdQueryHandle; |
|---|
| 94 | string anyQuerySQL; |
|---|
| 95 | OCIStmt *anyQueryHandle; |
|---|
| 96 | string anyIdQuerySQL; |
|---|
| 97 | OCIStmt *anyIdQueryHandle; |
|---|
| 98 | string listQuerySQL; |
|---|
| 99 | OCIStmt *listQueryHandle; |
|---|
| 100 | |
|---|
| 101 | string zoneInfoQuerySQL; |
|---|
| 102 | OCIStmt *zoneInfoQueryHandle; |
|---|
| 103 | string alsoNotifyQuerySQL; |
|---|
| 104 | OCIStmt *alsoNotifyQueryHandle; |
|---|
| 105 | string checkACLQuerySQL; |
|---|
| 106 | OCIStmt *checkACLQueryHandle; |
|---|
| 107 | string zoneMastersQuerySQL; |
|---|
| 108 | OCIStmt *zoneMastersQueryHandle; |
|---|
| 109 | string isZoneMasterQuerySQL; |
|---|
| 110 | OCIStmt *isZoneMasterQueryHandle; |
|---|
| 111 | string deleteZoneQuerySQL; |
|---|
| 112 | OCIStmt *deleteZoneQueryHandle; |
|---|
| 113 | string zoneSetLastCheckQuerySQL; |
|---|
| 114 | OCIStmt *zoneSetLastCheckQueryHandle; |
|---|
| 115 | string insertRecordQuerySQL; |
|---|
| 116 | OCIStmt *insertRecordQueryHandle; |
|---|
| 117 | string unfreshZonesQuerySQL; |
|---|
| 118 | OCIStmt *unfreshZonesQueryHandle; |
|---|
| 119 | string updatedMastersQuerySQL; |
|---|
| 120 | OCIStmt *updatedMastersQueryHandle; |
|---|
| 121 | string acceptSupernotificationQuerySQL; |
|---|
| 122 | OCIStmt *acceptSupernotificationQueryHandle; |
|---|
| 123 | string insertSlaveQuerySQL; |
|---|
| 124 | OCIStmt *insertSlaveQueryHandle; |
|---|
| 125 | string insertMasterQuerySQL; |
|---|
| 126 | OCIStmt *insertMasterQueryHandle; |
|---|
| 127 | string zoneSetNotifiedSerialQuerySQL; |
|---|
| 128 | OCIStmt *zoneSetNotifiedSerialQueryHandle; |
|---|
| 129 | |
|---|
| 130 | string prevNextNameQuerySQL; |
|---|
| 131 | OCIStmt *prevNextNameQueryHandle; |
|---|
| 132 | string prevNextHashQuerySQL; |
|---|
| 133 | OCIStmt *prevNextHashQueryHandle; |
|---|
| 134 | |
|---|
| 135 | string getZoneMetadataQuerySQL; |
|---|
| 136 | OCIStmt *getZoneMetadataQueryHandle; |
|---|
| 137 | string delZoneMetadataQuerySQL; |
|---|
| 138 | OCIStmt *delZoneMetadataQueryHandle; |
|---|
| 139 | string setZoneMetadataQuerySQL; |
|---|
| 140 | OCIStmt *setZoneMetadataQueryHandle; |
|---|
| 141 | |
|---|
| 142 | string getZoneKeysQuerySQL; |
|---|
| 143 | OCIStmt *getZoneKeysQueryHandle; |
|---|
| 144 | string delZoneKeyQuerySQL; |
|---|
| 145 | OCIStmt *delZoneKeyQueryHandle; |
|---|
| 146 | string addZoneKeyQuerySQL; |
|---|
| 147 | OCIStmt *addZoneKeyQueryHandle; |
|---|
| 148 | string setZoneKeyStateQuerySQL; |
|---|
| 149 | OCIStmt *setZoneKeyStateQueryHandle; |
|---|
| 150 | |
|---|
| 151 | OCIStmt *curStmtHandle; |
|---|
| 152 | sword mQueryResult; |
|---|
| 153 | |
|---|
| 154 | char myServerName[512]; |
|---|
| 155 | |
|---|
| 156 | char mQueryName[512]; |
|---|
| 157 | char mQueryType[64]; |
|---|
| 158 | char mQueryContent[4000]; |
|---|
| 159 | char mQueryZone[512]; |
|---|
| 160 | char mQueryAddr[64]; |
|---|
| 161 | int mQueryZoneId; |
|---|
| 162 | int mQueryTimestamp; |
|---|
| 163 | |
|---|
| 164 | char mResultName[512]; |
|---|
| 165 | sb2 mResultNameInd; |
|---|
| 166 | uint32_t mResultTTL; |
|---|
| 167 | sb2 mResultTTLInd; |
|---|
| 168 | char mResultType[32]; |
|---|
| 169 | sb2 mResultTypeInd; |
|---|
| 170 | char mResultContent[4000]; |
|---|
| 171 | sb2 mResultContentInd; |
|---|
| 172 | int mResultZoneId; |
|---|
| 173 | sb2 mResultZoneIdInd; |
|---|
| 174 | int mResultLastChange; |
|---|
| 175 | sb2 mResultLastChangeInd; |
|---|
| 176 | int mResultIsAuth; |
|---|
| 177 | sb2 mResultIsAuthInd; |
|---|
| 178 | char mResultPrevName[512]; |
|---|
| 179 | sb2 mResultPrevNameInd; |
|---|
| 180 | char mResultNextName[512]; |
|---|
| 181 | sb2 mResultNextNameInd; |
|---|
| 182 | |
|---|
| 183 | void Cleanup(); |
|---|
| 184 | |
|---|
| 185 | bool setDomainKeyState(const string& name, unsigned int id, int active); |
|---|
| 186 | |
|---|
| 187 | OCIStmt* prepare_query (string& code, const char *key); |
|---|
| 188 | void release_query (OCIStmt *stmt, const char *key); |
|---|
| 189 | void define_output_str (OCIStmt *s, ub4 pos, sb2 *ind, char *buf, sb4 buflen); |
|---|
| 190 | void define_output_int (OCIStmt *s, ub4 pos, sb2 *ind, int *buf); |
|---|
| 191 | void define_output_uint (OCIStmt *s, ub4 pos, sb2 *ind, unsigned int *buf); |
|---|
| 192 | void define_output_uint16 (OCIStmt *s, ub4 pos, sb2 *ind, uint16_t *buf); |
|---|
| 193 | void define_output_uint32 (OCIStmt *s, ub4 pos, sb2 *ind, uint32_t *buf); |
|---|
| 194 | void check_indicator (sb2 ind, bool null_okay); |
|---|
| 195 | void define_fwd_query (OCIStmt *s); |
|---|
| 196 | void bind_str (OCIStmt *s, const char *name, char *buf, sb4 buflen); |
|---|
| 197 | void bind_str_failokay (OCIStmt *s, const char *name, char *buf, sb4 buflen); |
|---|
| 198 | void bind_str_ind (OCIStmt *s, const char *name, char *buf, sb4 buflen, sb2 *ind); |
|---|
| 199 | void bind_int (OCIStmt *s, const char *name, int *buf); |
|---|
| 200 | void bind_uint (OCIStmt *s, const char *name, unsigned int *buf); |
|---|
| 201 | void bind_uint16 (OCIStmt *s, const char *name, uint16_t *buf); |
|---|
| 202 | void bind_uint16_ind (OCIStmt *s, const char *name, uint16_t *buf, sb2 *ind); |
|---|
| 203 | void bind_uint32 (OCIStmt *s, const char *name, uint32_t *buf); |
|---|
| 204 | |
|---|
| 205 | }; |
|---|
| 206 | |
|---|
| 207 | /* vi: set sw=2 et : */ |
|---|