Changeset 1154
- Timestamp:
- 03/09/08 16:31:37 (2 years ago)
- Location:
- trunk/pdns/modules/opendbxbackend
- Files:
-
- 3 modified
-
odbxbackend.cc (modified) (8 diffs)
-
odbxbackend.hh (modified) (6 diffs)
-
odbxprivate.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/modules/opendbxbackend/odbxbackend.cc
r1018 r1154 107 107 di.serial = 0; 108 108 109 if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL ) 110 { 111 di.id = strtol( tmp, NULL, 10 ); 112 } 113 114 if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL ) 115 { 116 di.zone = string( tmp, odbx_field_length( m_result, 1 ) ); 109 if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL ) 110 { 111 SOAData sd; 112 113 sd.serial = 0; 114 fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd ); 115 116 if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL ) 117 { 118 sd.serial = strtol( tmp, NULL, 10 ); 119 } 120 121 di.serial = sd.serial; 122 } 123 124 if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL ) 125 { 126 di.last_check = strtol( tmp, NULL, 10 ); 127 } 128 129 if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) 130 { 131 stringtok(di.masters, string( tmp, odbx_field_length( m_result, 3 ) ), ", \t"); 117 132 } 118 133 … … 129 144 } 130 145 131 if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) 132 { 133 string masters = string( tmp, odbx_field_length( m_result, 3 ) ); 134 stringtok(di.masters, masters, ", \t"); 135 } 136 137 if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL ) 138 { 139 di.last_check = strtol( tmp, NULL, 10 ); 140 } 141 142 if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL ) 143 { 144 SOAData sd; 145 146 sd.serial = 0; 147 fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd ); 148 di.serial = sd.serial; 146 if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL ) 147 { 148 di.zone = string( tmp, odbx_field_length( m_result, 1 ) ); 149 } 150 151 if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL ) 152 { 153 di.id = strtol( tmp, NULL, 10 ); 149 154 } 150 155 } … … 154 159 { 155 160 L.log( m_myname + " getDomainInfo: Caught STL exception - " + e.what(), Logger::Error ); 161 return false; 162 } 163 164 return true; 165 } 166 167 168 169 bool OdbxBackend::getSOA( const string& domain, SOAData& sd, DNSPacket* p ) 170 { 171 const char* tmp; 172 173 174 try 175 { 176 DLOG( L.log( m_myname + " getSOA()", Logger::Debug ) ); 177 178 string stmt = getArg( "sql-lookupsoa" ); 179 string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt ); 180 181 if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; } 182 if( !getRecord( READ ) ) { return false; } 183 184 do 185 { 186 sd.serial = 0; 187 188 if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL ) 189 { 190 fillSOAData( string( tmp, odbx_field_length( m_result, 2 ) ), sd ); 191 } 192 193 if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL ) 194 { 195 sd.serial = strtol( tmp, NULL, 10 ); 196 } 197 198 if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL ) 199 { 200 sd.domain_id = strtol( tmp, NULL, 10 ); 201 } 202 203 if( sd.nameserver.empty() ) 204 { 205 sd.nameserver = arg()["default-soa-name"]; 206 } 207 208 if( sd.hostmaster.empty() ) 209 { 210 sd.hostmaster = "hostmaster." + domain; 211 } 212 213 sd.db = this; 214 } 215 while( getRecord( READ ) ); 216 } 217 catch( exception& e ) 218 { 219 L.log( m_myname + " getSOA: Caught STL exception - " + e.what(), Logger::Error ); 156 220 return false; 157 221 } … … 212 276 m_result = NULL; 213 277 m_qname = qname; 214 278 215 279 if( zoneid < 0 ) 216 280 { … … 232 296 stmtref = strbind( ":type", qtype.getName(), stmt ); 233 297 } 234 298 235 299 size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid ); 236 300 … … 307 371 if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL ) 308 372 { 309 rr.priority = (u _int16_t) strtoul( tmp, NULL, 10 );373 rr.priority = (uint16_t) strtoul( tmp, NULL, 10 ); 310 374 } 311 375 … … 328 392 329 393 330 void OdbxBackend::setFresh( u _int32_t domain_id )394 void OdbxBackend::setFresh( uint32_t domain_id ) 331 395 { 332 396 size_t len; … … 371 435 372 436 373 void OdbxBackend::setNotified( u _int32_t domain_id, u_int32_t serial )437 void OdbxBackend::setNotified( uint32_t domain_id, uint32_t serial ) 374 438 { 375 439 try -
trunk/pdns/modules/opendbxbackend/odbxbackend.hh
r977 r1154 46 46 47 47 48 bool checkSlave( u _int32_t last, u_int32_t notified, SOAData* sd, DomainInfo* di );49 bool checkMaster( u _int32_t last, u_int32_t notified, SOAData* sd, DomainInfo* di );48 bool checkSlave( uint32_t last, uint32_t notified, SOAData* sd, DomainInfo* di ); 49 bool checkMaster( uint32_t last, uint32_t notified, SOAData* sd, DomainInfo* di ); 50 50 51 51 … … 66 66 string escape( const string& str, QueryType type ); 67 67 bool connectTo( const vector<string>& host, QueryType type ); 68 bool getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(u _int32_t,u_int32_t,SOAData*,DomainInfo*) );68 bool getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(uint32_t,uint32_t,SOAData*,DomainInfo*) ); 69 69 bool execStmt( const char* stmt, unsigned long length, QueryType type ); 70 70 bool getRecord( QueryType type ); … … 77 77 78 78 void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 ); 79 bool getSOA( const string& domain, SOAData& sd, DNSPacket* p ); 79 80 bool list( const string& target, int domain_id ); 80 81 bool get( DNSResourceRecord& rr ); … … 93 94 void getUnfreshSlaveInfos( vector<DomainInfo>* unfresh ); 94 95 95 void setFresh( u _int32_t domain_id );96 void setNotified( u _int32_t domain_id, u_int32_t serial );96 void setFresh( uint32_t domain_id ); 97 void setNotified( uint32_t domain_id, uint32_t serial ); 97 98 }; 98 99 … … 117 118 declare( suffix, "password","Password for connecting to the DBMS",""); 118 119 119 declare( suffix, "sql-list", "AXFR query", "SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE\"domain_id\"=:id" );120 declare( suffix, "sql-list", "AXFR query", "SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id" ); 120 121 121 declare( suffix, "sql-lookup", "Lookup query","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"name\"=':name'" ); 122 declare( suffix, "sql-lookupid", "Lookup query with id","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id AND \"name\"=':name'" ); 123 declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"name\"=':name' AND \"type\"=':type'" ); 124 declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id AND \"name\"=':name' AND \"type\"=':type'" ); 122 declare( suffix, "sql-lookup", "Lookup query","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name'" ); 123 declare( suffix, "sql-lookupid", "Lookup query with id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name'" ); 124 declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name' AND r.\"type\"=':type'" ); 125 declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name' AND r.\"type\"=':type'" ); 126 declare( suffix, "sql-lookupsoa","Lookup query for SOA record","SELECT d.\"id\", d.\"auto_serial\", r.\"content\" FROM \"records\" r JOIN \"domains\" d ON r.\"domain_id\"=d.\"id\" WHERE r.\"name\"=':name' AND r.\"type\"='SOA' AND d.\"status\"='A'" ); 125 127 126 declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM \"records\" WHERE\"domain_id\"=:id" );127 declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.\"id\", d.\"name\", d.\"type\", d.\"master\", d.\"last_check\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"name\"=':name' AND d.\"status\"='A'" );128 declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM \"records\" r WHERE r.\"domain_id\"=:id" ); 129 declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.\"id\", d.\"name\", d.\"type\", d.\"master\", d.\"last_check\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"name\"=':name' AND d.\"status\"='A'" ); 128 130 129 131 declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" ); … … 134 136 declare( suffix, "sql-insert-record","Feed record into table", "INSERT INTO \"records\" ( \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" ) VALUES ( %d, '%s', '%s', %d, %d, '%s' )" ); 135 137 136 declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE \"domains\" SET \"notified_serial\"=%d WHERE\"id\"=%d" );137 declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE \"domains\" SET \"last_check\"=%d WHERE\"id\"=%d" );138 declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE \"domains\" d SET d.\"notified_serial\"=%d WHERE d.\"id\"=%d" ); 139 declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE \"domains\" d SET d.\"last_check\"=%d WHERE d.\"id\"=%d" ); 138 140 139 declare( suffix, "sql-master", "Get master record for zone", "SELECT \"master\" FROM \"domains\" WHERE \"name\"=':name' AND \"status\"='A' AND\"type\"='SLAVE'" );140 declare( suffix, "sql-supermaster","Get supermaster info", "SELECT \"account\" FROM \"supermasters\" WHERE \"ip\"=':ip' AND\"nameserver\"=':ns'" );141 declare( suffix, "sql-master", "Get master record for zone", "SELECT d.\"master\" FROM \"domains\" d WHERE d.\"name\"=':name' AND d.\"status\"='A' AND d.\"type\"='SLAVE'" ); 142 declare( suffix, "sql-supermaster","Get supermaster info", "SELECT s.\"account\" FROM \"supermasters\" s WHERE s.\"ip\"=':ip' AND s.\"nameserver\"=':ns'" ); 141 143 142 declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\" notified_serial\", d.\"last_check\", r.\"change_date\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='SLAVE'" );143 declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\" notified_serial\", d.\"last_check\", r.\"change_date\", r.\"content\" FROM \"domains\" d JOIN \"records\" r ON d.\"id\"=r.\"domain_id\" WHERE d.\"status\"='A' AND d.\"type\"='MASTER' AND r.\"type\"='SOA'" );144 declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='SLAVE'" ); 145 declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='MASTER'" ); 144 146 145 147 declare( suffix, "host", "depricated, use host-read and host-write instead","" ); -
trunk/pdns/modules/opendbxbackend/odbxprivate.cc
r1024 r1154 19 19 odbx_finish( m_handle[type] ); 20 20 m_handle[type] = NULL; 21 } 22 23 if( type == WRITE && getArg( "backend" ) == "sqlite" ) 24 { 25 L.log( m_myname + " Using same SQLite connection for reading and writeing to '" + hosts[odbx_host_index[READ]] + "'", Logger::Notice ); 26 m_handle[WRITE] = m_handle[READ]; 27 return true; 21 28 } 22 29 … … 157 164 158 165 159 bool OdbxBackend::getDomainList( const string& stmt, vector<DomainInfo>* list, bool (*check_fcn)(u _int32_t,u_int32_t,SOAData*,DomainInfo*) )166 bool OdbxBackend::getDomainList( const string& stmt, vector<DomainInfo>* list, bool (*check_fcn)(uint32_t,uint32_t,SOAData*,DomainInfo*) ) 160 167 { 161 168 const char* tmp; 162 u _int32_t nlast, nserial;169 uint32_t nlast, nserial; 163 170 DomainInfo di; 164 171 SOAData sd; … … 189 196 if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL ) 190 197 { 198 nserial = strtol( tmp, NULL, 10 ); 199 } 200 201 if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) 202 { 191 203 nlast = strtol( tmp, NULL, 10 ); 192 }193 194 if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )195 {196 nserial = strtol( tmp, NULL, 10 );197 204 } 198 205 … … 229 236 230 237 231 bool checkSlave( u _int32_t nlast, u_int32_t nserial, SOAData* sd, DomainInfo* di )232 { 233 if( nlast + sd->refresh < (u _int32_t) time( 0 ) )238 bool checkSlave( uint32_t nlast, uint32_t nserial, SOAData* sd, DomainInfo* di ) 239 { 240 if( nlast + sd->refresh < (uint32_t) time( 0 ) ) 234 241 { 235 242 di->kind = DomainInfo::Slave; … … 242 249 243 250 244 bool checkMaster( u _int32_t nlast, u_int32_t nserial, SOAData* sd, DomainInfo* di )251 bool checkMaster( uint32_t nlast, uint32_t nserial, SOAData* sd, DomainInfo* di ) 245 252 { 246 253 if( nserial != sd->serial )