| 359 | } |
| 360 | |
| 361 | int db_ctl::load_dat_hosts(void) |
| 362 | { |
| 363 | const char* sql = "select id, addr, count, priority from tbl_host_dat"; |
| 364 | if (ctl_conn_->sql_select(sql) == false) |
| 365 | { |
| 366 | logger_error("sql(%s) invalid", sql); |
| 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | const std::vector<acl::db_row*>* rows = ctl_conn_->get_rows(); |
| 371 | if (rows == NULL) |
| 372 | { |
| 373 | logger_warn("tbl_host_dat empty"); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | unsigned int id; |
| 378 | const char* addr; |
| 379 | acl_int64 count; |
| 380 | int priority; |
| 381 | |
| 382 | size_t i; |
| 383 | for (i = 0; i < rows->size(); i++) |
| 384 | { |
| 385 | const acl::db_row* row = (*rows)[i]; |
| 386 | if ((id = row->field_int("id", -1)) == (unsigned int) -1) |
| 387 | { |
| 388 | logger_warn("id(-1) invalid"); |
| 389 | continue; |
| 390 | } |
| 391 | else if ((addr = row->field_string("addr")) == NULL) |
| 392 | { |
| 393 | logger_warn("addr null"); |
| 394 | continue; |
| 395 | } |
| 396 | else if ((count = row->field_int64("count", -1)) == -1) |
| 397 | { |
| 398 | logger_warn("count(-1) invalid"); |
| 399 | continue; |
| 400 | } |
| 401 | priority = row->field_int("priority", 0); |
| 402 | dat_host* host = new dat_host(id, addr, count, priority); |
| 403 | dat_hosts_.push_back(host); |
| 404 | } |
| 405 | |
| 406 | ctl_conn_->free_result(); |
| 407 | return (int) i; |
| 408 | } |
| 409 | |
| 410 | int db_ctl::load_db_hosts(void) |
| 411 | { |
nothing calls this directly
no test coverage detected