~ubuntu-branches/ubuntu/maverick/pdns/maverick-updates

« back to all changes in this revision

Viewing changes to modules/opendbxbackend/odbxbackend.cc

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Haas
  • Date: 2009-02-25 23:25:51 UTC
  • mfrom: (1.1.7 upstream) (12.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090225232551-ts3d9k9q0ti442i9
Tags: 2.9.22-1
New upstream version (closes: #513409).

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
                        di.backend = this;
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 ) );
117
 
                        }
118
 
 
119
 
                        if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
120
 
                        {
121
 
                                if( !strncmp( tmp, "SLAVE", 5 ) )
122
 
                                {
123
 
                                        di.kind = DomainInfo::Slave;
124
 
                                }
125
 
                                else if( !strncmp( tmp, "MASTER", 6 ) )
126
 
                                {
127
 
                                        di.kind = DomainInfo::Master;
128
 
                                }
129
 
                        }
130
 
 
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
109
                        if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
143
110
                        {
144
111
                                SOAData sd;
145
112
 
146
113
                                sd.serial = 0;
147
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
 
148
121
                                di.serial = sd.serial;
149
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");
 
132
                        }
 
133
 
 
134
                        if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
 
135
                        {
 
136
                                if( !strncmp( tmp, "SLAVE", 5 ) )
 
137
                                {
 
138
                                        di.kind = DomainInfo::Slave;
 
139
                                }
 
140
                                else if( !strncmp( tmp, "MASTER", 6 ) )
 
141
                                {
 
142
                                        di.kind = DomainInfo::Master;
 
143
                                }
 
144
                        }
 
145
 
 
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 );
 
154
                        }
150
155
                }
151
156
                while( getRecord( READ ) );
152
157
        }
161
166
 
162
167
 
163
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
                        sd.ttl = m_default_ttl;
 
188
 
 
189
                        if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
 
190
                        {
 
191
                                fillSOAData( string( tmp, odbx_field_length( m_result, 3 ) ), sd );
 
192
                        }
 
193
 
 
194
                        if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
 
195
                        {
 
196
                                sd.ttl = strtoul( tmp, NULL, 10 );
 
197
                        } 
 
198
 
 
199
                        if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
 
200
                        {
 
201
                                sd.serial = strtol( tmp, NULL, 10 );
 
202
                        }
 
203
 
 
204
                        if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
 
205
                        {
 
206
                                sd.domain_id = strtol( tmp, NULL, 10 );
 
207
                        }
 
208
 
 
209
                        if( sd.nameserver.empty() )
 
210
                        {
 
211
                                sd.nameserver = arg()["default-soa-name"];
 
212
                        }
 
213
 
 
214
                        if( sd.hostmaster.empty() )
 
215
                        {
 
216
                                sd.hostmaster = "hostmaster." + domain;
 
217
                        }
 
218
 
 
219
                        sd.db = this;
 
220
                }
 
221
                while( getRecord( READ ) );
 
222
        }
 
223
        catch( exception& e )
 
224
        {
 
225
                L.log( m_myname + " getSOA: Caught STL exception - " + e.what(),  Logger::Error );
 
226
                return false;
 
227
        }
 
228
 
 
229
        return true;
 
230
}
 
231
 
 
232
 
 
233
 
164
234
bool OdbxBackend::list( const string& target, int zoneid )
165
235
{
166
236
        try
211
281
 
212
282
                m_result = NULL;
213
283
                m_qname = qname;
214
 
                
 
284
 
215
285
                if( zoneid < 0 )
216
286
                {
217
287
                        if( qtype.getCode() == QType::ANY )
231
301
                                stmt = getArg( "sql-lookuptypeid" );
232
302
                                stmtref = strbind( ":type", qtype.getName(), stmt );
233
303
                        }
234
 
                        
 
304
 
235
305
                        size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
236
306
 
237
307
                        if( len < 0 )
306
376
 
307
377
                        if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
308
378
                        {
309
 
                                rr.priority = (u_int16_t) strtoul( tmp, NULL, 10 );
 
379
                                rr.priority = (uint16_t) strtoul( tmp, NULL, 10 );
310
380
                        }
311
381
 
312
382
                        if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
327
397
}
328
398
 
329
399
 
330
 
void OdbxBackend::setFresh( u_int32_t domain_id )
 
400
void OdbxBackend::setFresh( uint32_t domain_id )
331
401
{
332
402
        size_t len;
333
403
 
370
440
 
371
441
 
372
442
 
373
 
void OdbxBackend::setNotified( u_int32_t domain_id, u_int32_t serial )
 
443
void OdbxBackend::setNotified( uint32_t domain_id, uint32_t serial )
374
444
{
375
445
        try
376
446
        {