From: Bert Hubert Date: Wed, 18 Jan 2006 22:01:16 +0000 (+0000) Subject: opendbx updates by Norbert X-Git-Tag: pdns-2.9.20~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1620e053f524e433ff02386fe4bb6436be6d8dc4;p=thirdparty%2Fpdns.git opendbx updates by Norbert git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@561 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/opendbxbackend/odbxbackend.cc b/modules/opendbxbackend/odbxbackend.cc index c03008c6cb..d810f33743 100644 --- a/modules/opendbxbackend/odbxbackend.cc +++ b/modules/opendbxbackend/odbxbackend.cc @@ -65,7 +65,7 @@ OdbxBackend::~OdbxBackend() bool OdbxBackend::getDomainInfo( const string& domain, DomainInfo& di ) { const char* tmp; - string stmt, type; + string stmt; try @@ -83,8 +83,10 @@ bool OdbxBackend::getDomainInfo( const string& domain, DomainInfo& di ) di.zone = ""; di.master = ""; di.last_check = 0; + di.notified_serial = 0; + di.kind = DomainInfo::Native; di.backend = this; - type = ""; + di.serial = 0; if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL ) { @@ -98,42 +100,33 @@ bool OdbxBackend::getDomainInfo( const string& domain, DomainInfo& di ) if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL ) { - di.master = string( tmp ); + if( !strncmp( tmp, "SLAVE", 5 ) ) + { + di.kind = DomainInfo::Slave; + } + else if( !strncmp( tmp, "MASTER", 6 ) ) + { + di.kind = DomainInfo::Master; + } } if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) { - di.last_check = strtol( tmp, NULL, 10 ); + di.master = string( tmp ); } if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL ) { - type = string( tmp ); + di.last_check = strtol( tmp, NULL, 10 ); } - di.kind = DomainInfo::Native; - - if( type == "SLAVE" ) + if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL ) { SOAData sd; sd.serial = 0; - - if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL ) - { DNSPacket::fillSOAData( string( tmp ), sd ); - } - else - { - L.log( m_myname + " getDomainInfo: No serial for '" + domain + "' found", Logger::Notice ); - } - di.serial = sd.serial; - di.kind = DomainInfo::Slave; - } - else if( type == "MASTER" ) - { - di.kind = DomainInfo::Master; } } while( getRecord() ); @@ -259,32 +252,32 @@ bool OdbxBackend::get( DNSResourceRecord& rr ) if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL ) { - rr.content = string( tmp ); + rr.domain_id = strtol( tmp, NULL, 10 ); } - if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL ) + if( m_qname.empty() && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL ) { - rr.ttl = strtoul( tmp, NULL, 10 ); + rr.qname = string( tmp ); } if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL ) { - rr.priority = (u_int16_t) strtoul( tmp, NULL, 10 ); + rr.qtype = QType( tmp ); } if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) { - rr.qtype = QType( tmp ); + rr.ttl = strtoul( tmp, NULL, 10 ); } if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL ) { - rr.domain_id = strtol( tmp, NULL, 10 ); + rr.priority = (u_int16_t) strtoul( tmp, NULL, 10 ); } - if( m_qname.empty() && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL ) + if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL ) { - rr.qname = string( tmp ); + rr.content = string( tmp ); } return true; diff --git a/modules/opendbxbackend/odbxbackend.hh b/modules/opendbxbackend/odbxbackend.hh index 798b515191..c064cf5121 100644 --- a/modules/opendbxbackend/odbxbackend.hh +++ b/modules/opendbxbackend/odbxbackend.hh @@ -113,31 +113,31 @@ public: declare( suffix, "username","User for connecting to the DBMS","powerdns"); declare( suffix, "password","Password for connecting to the DBMS",""); - declare( suffix, "sql-list", "AXFR query", "SELECT content, ttl, prio, type, domain_id, name FROM records WHERE domain_id=':id'" ); + declare( suffix, "sql-list", "AXFR query", "SELECT domain_id, name, type, ttl, prio, content FROM records WHERE domain_id=':id'" ); - declare( suffix, "sql-lookup", "Lookup query","SELECT content, ttl, prio, type, domain_id, name FROM records WHERE name=':name'" ); - declare( suffix, "sql-lookupid", "Lookup query with id","SELECT content, ttl, prio, type, domain_id, name FROM records WHERE name=':name' AND domain_id=':id'" ); - declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT content, ttl, prio, type, domain_id, name FROM records WHERE type=':type' AND name=':name'" ); - declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT content, ttl, prio, type, domain_id, name FROM records WHERE type=':type' AND name=':name' AND domain_id=':id'" ); + declare( suffix, "sql-lookup", "Lookup query","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE name=':name'" ); + 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'" ); + declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE name=':name' AND type=':type'" ); + 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'" ); declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM records WHERE domain_id=':id'" ); - declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.id, d.name, d.master, d.last_check, d.notified_serial, d.type, r.content FROM domains AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.name=':name' AND r.type='SOA' ) OR ( d.name=':name' AND r.domain_id IS NULL )" ); + declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.id, d.name, d.type, d.master, d.last_check, r.content FROM domains AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.name=':name' AND r.type='SOA' ) OR ( d.name=':name' AND r.domain_id IS NULL )" ); declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" ); declare( suffix, "sql-transactend", "Finish transaction", "COMMIT" ); declare( suffix, "sql-transactabort", "Abort transaction", "ROLLBACK" ); - declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO domains ( type, name, master, account ) VALUES ( 'SLAVE', '%s', '%s', '%s' )" ); + declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO domains ( name, type, master, account ) VALUES ( '%s', 'SLAVE', '%s', '%s' )" ); 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' )" ); declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE domains SET notified_serial='%d' WHERE id='%d'" ); declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE domains SET last_check='%d' WHERE id='%d'" ); - declare( suffix, "sql-master", "Get master record for zone", "SELECT master FROM domains WHERE type='SLAVE' AND name=':name'" ); + declare( suffix, "sql-master", "Get master record for zone", "SELECT master FROM domains WHERE name=':name' AND type='SLAVE'" ); declare( suffix, "sql-supermaster","Get supermaster info", "SELECT account FROM supermasters WHERE ip=':ip' AND nameserver=':ns'" ); - declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.id, d.name, d.master, d.last_check, d.notified_serial, r.change_date, r.content FROM domains AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.type='SLAVE' AND r.type='SOA' ) OR ( d.type='SLAVE' AND r.domain_id IS NULL )" ); - declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.id, d.name, d.master, d.last_check, d.notified_serial, r.change_date, r.content FROM domains AS d, records AS r WHERE d.type='MASTER' AND d.id=r.domain_id AND r.type='SOA'" ); + 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 AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.type='SLAVE' AND r.type='SOA' ) OR ( d.type='SLAVE' AND r.domain_id IS NULL )" ); + 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 AS d, records AS r WHERE d.type='MASTER' AND d.id=r.domain_id AND r.type='SOA'" ); } diff --git a/modules/opendbxbackend/odbxprivate.cc b/modules/opendbxbackend/odbxprivate.cc index 58a9d4ba13..0f0800f8c5 100644 --- a/modules/opendbxbackend/odbxprivate.cc +++ b/modules/opendbxbackend/odbxprivate.cc @@ -138,12 +138,12 @@ void OdbxBackend::getDomainList( const string& stmt, vector* list, b if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL ) { - nserial = strtol( tmp, NULL, 10 ); + nlast = strtol( tmp, NULL, 10 ); } if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL ) { - nlast = strtol( tmp, NULL, 10 ); + nserial = strtol( tmp, NULL, 10 ); } if( (*check_fcn)( nlast, nserial, &sd, &di ) )