ul_db_handle.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /* sp-ul_db module
  2. *
  3. * Copyright (C) 2007 1&1 Internet AG
  4. *
  5. * This file is part of Kamailio, a free SIP server.
  6. *
  7. * Kamailio is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "ul_db_handle.h"
  22. #include "p_usrloc_mod.h"
  23. #include "ul_db.h"
  24. #include "ul_db_watch.h"
  25. #include "../../crc.h"
  26. static ul_db_handle_list_t * db_handles = NULL;
  27. static ul_db_handle_t tmp;
  28. static ul_db_handle_t * allocate_handle(void);
  29. static ul_db_handle_list_t * allocate_handle_list(void);
  30. static void free_handle(ul_db_handle_list_t * element);
  31. static int check_status(ul_db_handle_t * a, ul_db_handle_t * b);
  32. static int compute_id(str* first, str* second);
  33. static int release_handle(ul_db_handle_t * handle);
  34. static int activate_handle(ul_db_handle_t * handle);
  35. ul_db_handle_t * get_handle(db_func_t * dbf, db1_con_t * dbh, str * first, str * second) {
  36. struct ul_db_handle_list * element;
  37. ul_db_handle_t * ret = NULL;
  38. int db_ok = 0;
  39. int id;
  40. switch(alg_location){
  41. case 1:default:{
  42. /* atm this is the only matching mode */
  43. if( max_loc_nr == 0){
  44. LM_WARN("max_loc_nr is 0 . Try to recompute value\n");
  45. if( load_location_number(dbf, dbh, &max_loc_nr) != 0 ){
  46. LM_ERR("Could not get location number\n");
  47. return NULL;
  48. }
  49. }
  50. if((id = compute_id(first, second)) < 0){
  51. return NULL;
  52. }
  53. break;
  54. }
  55. /* default:{
  56. LM_ERR("No suitable selection for location\n");
  57. return NULL;
  58. }
  59. */
  60. }
  61. if(load_data(dbf, dbh, &tmp, id) < 0){
  62. // load_data should explain this
  63. return NULL;
  64. }
  65. element = db_handles;
  66. db_ok = 0;
  67. while(element && element->handle) {
  68. if(element->handle->id == tmp.id) {
  69. LM_DBG("found handle with id %i\n", element->handle->id);
  70. element->handle->expires = time(NULL) + connection_expires;
  71. if(check_status(element->handle, &tmp) == 0) {
  72. db_ok = 1;
  73. }
  74. ret = element->handle;
  75. }
  76. if((element->handle->expires < time(NULL)) && element->handle->active){
  77. release_handle(element->handle);
  78. }
  79. element = element->next;
  80. }
  81. if(db_ok) {
  82. goto ret;
  83. }
  84. element = NULL;
  85. if(ret == NULL) {
  86. LM_DBG("didn't find handle with id %i\n", tmp.id);
  87. if((element = allocate_handle_list()) == NULL) {
  88. LM_ERR("could not allocate handle.\n");
  89. return NULL;
  90. }
  91. ret = element->handle;
  92. ret->id = tmp.id;
  93. activate_handle(ret);
  94. element->next = db_handles;
  95. db_handles = element;
  96. }
  97. if(refresh_handle(ret, &tmp, db_write) < 0) {
  98. ret = NULL;
  99. }
  100. ret:
  101. if(ret && !ret->active){
  102. activate_handle(ret);
  103. }
  104. return ret;
  105. }
  106. int refresh_handle(ul_db_handle_t * handle, ul_db_handle_t * new_data, int error_handling) {
  107. int db_ok = 0;
  108. int i, ret;
  109. str tmpurl;
  110. handle->id = new_data->id;
  111. handle->working = 0;
  112. handle->expires = time(NULL) + connection_expires;
  113. for(i=0; i<DB_NUM; i++) {
  114. handle->db[i].status = new_data->db[i].status;
  115. handle->db[i].errors = new_data->db[i].errors;
  116. handle->db[i].failover_time = new_data->db[i].failover_time;
  117. handle->db[i].rg = new_data->db[i].rg;
  118. handle->db[i].no = new_data->db[i].no;
  119. if((handle->db[i].url.len != new_data->db[i].url.len) || (strcmp(handle->db[i].url.s, new_data->db[i].url.s) != 0)) {
  120. memset(handle->db[i].url.s, 0, UL_DB_URL_LEN);
  121. strcpy(handle->db[i].url.s, new_data->db[i].url.s);
  122. handle->db[i].url.len = new_data->db[i].url.len;
  123. if(handle->db[i].dbh) {
  124. handle->db[i].dbf.close(handle->db[i].dbh);
  125. handle->db[i].dbh = NULL;
  126. }
  127. memset(&handle->db[i].dbf, 0, sizeof(db_func_t));
  128. tmpurl.len = handle->db[i].url.len;
  129. tmpurl.s = handle->db[i].url.s;
  130. if(db_bind_mod(&tmpurl, &handle->db[i].dbf) < 0){
  131. LM_ERR("could not bind db module.\n");
  132. return -1;
  133. }
  134. }
  135. if(handle->db[i].status == DB_ON) {
  136. handle->working++;
  137. if(handle->db[i].dbh) {
  138. db_ok++;
  139. } else {
  140. LM_DBG("connect id %i db %i.\n", handle->id, handle->db[i].no);
  141. tmpurl.len = handle->db[i].url.len;
  142. tmpurl.s = handle->db[i].url.s;
  143. if((handle->db[i].dbh = handle->db[i].dbf.init(&tmpurl)) == NULL) {
  144. LM_ERR("id: %i could not "
  145. "connect database %i.\n", handle->id, handle->db[i].no);
  146. if(error_handling){
  147. if(db_handle_error(handle, handle->db[i].no) < 0){
  148. LM_ERR("id: %i could not "
  149. "handle error on database %i.\n", handle->id, handle->db[i].no);
  150. }
  151. }
  152. } else {
  153. db_ok++;
  154. }
  155. }
  156. } else if (handle->db[i].status == DB_INACTIVE) {
  157. if(handle->db[i].dbh){
  158. LM_DBG("deactivate id %i db %i.\n", handle->id, handle->db[i].no);
  159. handle->db[i].dbf.close(handle->db[i].dbh);
  160. handle->db[i].dbh = NULL;
  161. }
  162. } else {
  163. if(handle->db[i].dbh) {
  164. LM_DBG("shutdown id %i db %i.\n", handle->id, handle->db[i].no);
  165. handle->db[i].dbf.close(handle->db[i].dbh);
  166. handle->db[i].dbh = NULL;
  167. }
  168. }
  169. }
  170. if((ret = db_check_policy(DB_POL_OP, db_ok, handle->working)) < 0){
  171. LM_ERR("id %i: too few dbs working\n", handle->id);
  172. }
  173. return ret;
  174. }
  175. static int release_handle(ul_db_handle_t * handle){
  176. int i;
  177. LM_NOTICE("deactivating handle id %i, db 1: %.*s, db2: %.*s\n", handle->id, handle->db[0].url.len, handle->db[0].url.s, handle->db[1].url.len, handle->db[1].url.s);
  178. for(i=0; i<DB_NUM; i++){
  179. if(handle->db[i].dbh){
  180. handle->db[i].dbf.close(handle->db[i].dbh);
  181. handle->db[i].dbh = NULL;
  182. }
  183. }
  184. handle->active = 0;
  185. return ul_unregister_watch_db(handle->id);
  186. }
  187. static int activate_handle(ul_db_handle_t * handle){
  188. LM_NOTICE("activating handle id %i, db 1: %.*s, db2: %.*s\n", handle->id, handle->db[0].url.len, handle->db[0].url.s, handle->db[1].url.len, handle->db[1].url.s);
  189. handle->active = 1;
  190. return ul_register_watch_db(handle->id);
  191. }
  192. static ul_db_handle_list_t * allocate_handle_list(void) {
  193. ul_db_handle_list_t * ret;
  194. if((ret = (ul_db_handle_list_t *)pkg_malloc(sizeof(ul_db_handle_list_t))) == NULL) {
  195. LM_ERR("couldn't allocate private memory.\n");
  196. return NULL;
  197. }
  198. if((ret->handle = allocate_handle()) == NULL) {
  199. pkg_free(ret);
  200. return NULL;
  201. }
  202. return ret;
  203. }
  204. static ul_db_handle_t * allocate_handle(void) {
  205. ul_db_handle_t * ret;
  206. if((ret = (ul_db_handle_t *)pkg_malloc(sizeof(ul_db_handle_t))) == NULL) {
  207. LM_ERR("couldn't allocate pkg mem.\n");
  208. return NULL;
  209. }
  210. memset(ret, 0, sizeof(ul_db_handle_t));
  211. if((ret->check = get_new_element()) == NULL) {
  212. pkg_free(ret);
  213. return NULL;
  214. }
  215. return ret;
  216. }
  217. int load_location_number(db_func_t * dbf, db1_con_t* dbh, int *loc_nr){
  218. static char query[UL_DB_QUERY_LEN];
  219. db1_res_t * res;
  220. db_row_t * row;
  221. int query_len;
  222. str tmp;
  223. if(!loc_nr || !dbf || !dbh){
  224. LM_ERR("NULL parameter passed \n");
  225. return -1;
  226. }
  227. query_len = 30 + id_col.len + reg_table.len + status_col.len;
  228. if(query_len > UL_DB_QUERY_LEN) {
  229. LM_ERR("weird: query larger than %i bytes.\n", UL_DB_QUERY_LEN);
  230. return -1;
  231. }
  232. memset(query, 0, UL_DB_QUERY_LEN);
  233. if(sprintf(query,
  234. "SELECT MAX(%.*s) "
  235. "FROM "
  236. "%.*s "
  237. "WHERE %.*s = 1;", id_col.len, id_col.s, reg_table.len, reg_table.s, status_col.len, status_col.s) < 0){
  238. LM_ERR("could not sprinf query\n");
  239. return -1;
  240. }
  241. LM_DBG("%s\n",query);
  242. tmp.s = query;
  243. tmp.len = strlen(query);
  244. if (dbf->raw_query (dbh, &tmp, &res) < 0) {
  245. LM_ERR("in database query.\n");
  246. return -1;
  247. }
  248. if (RES_ROW_N (res) == 0) {
  249. dbf->free_result (dbh, res);
  250. LM_DBG ("no data found\n");
  251. return 1;
  252. }
  253. row = RES_ROWS(res) + 0; /* only one row in answer */
  254. if (VAL_NULL (ROW_VALUES(row) + 0)) {
  255. LM_ERR("Weird: Empty Max ID Number\n");
  256. dbf->free_result (dbh, res);
  257. return 1;
  258. }
  259. *loc_nr = VAL_INT (ROW_VALUES(row) + 0);
  260. dbf->free_result (dbh, res);
  261. if(*loc_nr == 0){
  262. LM_ERR("No location in DB?!\n");
  263. return 1;
  264. }
  265. return 0;
  266. }
  267. int load_handles(db_func_t * dbf, db1_con_t * dbh) {
  268. static char query[UL_DB_QUERY_LEN];
  269. db1_res_t * res;
  270. db_row_t * row;
  271. ul_db_handle_list_t * element;
  272. int i, id, query_len;
  273. str tmp;
  274. if(!dbf || !dbh){
  275. LM_ERR("NULL parameter passed \n");
  276. return -1;
  277. }
  278. query_len = 25 + id_col.len + reg_table.len;
  279. if(query_len > UL_DB_QUERY_LEN) {
  280. LM_ERR("weird: query larger than %i bytes.\n", UL_DB_QUERY_LEN);
  281. return -1;
  282. }
  283. memset(query, 0, UL_DB_QUERY_LEN);
  284. if (sprintf(query,
  285. "SELECT DISTINCT "
  286. "%.*s "
  287. "FROM "
  288. "%.*s",
  289. id_col.len, id_col.s,
  290. reg_table.len, reg_table.s) < 0) {
  291. LM_ERR("could not print query\n");
  292. return -1;
  293. }
  294. tmp.s = query;
  295. tmp.len = strlen(query);
  296. if (dbf->raw_query (dbh, &tmp, &res) < 0) {
  297. LM_ERR("in database query.\n");
  298. return -1;
  299. }
  300. if (RES_ROW_N (res) == 0) {
  301. dbf->free_result (dbh, res);
  302. LM_DBG ("no data found\n");
  303. return 1;
  304. }
  305. for (i = 0; i < RES_ROW_N (res); ++i) {
  306. row = RES_ROWS (res) + i;
  307. if((element = allocate_handle_list()) == NULL) {
  308. LM_ERR("couldnt allocate handle.\n");
  309. goto errout;
  310. }
  311. if (VAL_NULL (ROW_VALUES(row) + 0)) {
  312. LM_ERR("Weird: Empty ID-Field\n");
  313. goto errout;
  314. }
  315. id = VAL_INT (ROW_VALUES(row) + 0);
  316. if(load_data(dbf, dbh, element->handle, id) < 0){
  317. LM_ERR("couldn't load handle data.\n");
  318. goto errout;
  319. }
  320. element->next = db_handles;
  321. db_handles = element;
  322. }
  323. dbf->free_result (dbh, res);
  324. return 0;
  325. errout:
  326. dbf->free_result (dbh, res);
  327. return -1;
  328. }
  329. int refresh_handles(db_func_t * dbf, db1_con_t * dbh) {
  330. ul_db_handle_list_t * element;
  331. int i;
  332. element = db_handles;
  333. while(element) {
  334. for(i=0; i<DB_NUM; i++) {
  335. if(element->handle->db[i].dbh) {
  336. dbf->close(element->handle->db[i].dbh);
  337. element->handle->db[i].dbh = NULL;
  338. }
  339. }
  340. if(load_data(dbf, dbh, &tmp, element->handle->id) < 0){
  341. LM_ERR("couldn't load handle data.\n");
  342. return -1;
  343. }
  344. if(refresh_handle(element->handle, &tmp, db_write) < 0) {
  345. LM_ERR("couldn't refresh handle data.\n");
  346. return -1;
  347. }
  348. element = element->next;
  349. }
  350. return 1;
  351. }
  352. void destroy_handles(void){
  353. ul_db_handle_list_t * element, * del;
  354. int i;
  355. element = db_handles;
  356. while(element){
  357. for(i=0; i<DB_NUM; i++){
  358. if(element->handle->db[i].dbh){
  359. element->handle->db[i].dbf.close(element->handle->db[i].dbh);
  360. element->handle->db[i].dbh = NULL;
  361. }
  362. }
  363. del = element;
  364. element = element->next;
  365. free_handle(del);
  366. }
  367. }
  368. ul_db_t * get_db_by_num(ul_db_handle_t * handle, int no) {
  369. int i;
  370. for(i=0; i<DB_NUM; i++) {
  371. if(handle->db[i].no == no) {
  372. return &handle->db[i];
  373. }
  374. }
  375. return NULL;
  376. }
  377. int check_handle(db_func_t * dbf, db1_con_t * dbh, ul_db_handle_t * handle){
  378. int i;
  379. str tmpurl;
  380. LM_INFO("checking id %i\n", handle->id);
  381. if(load_data(dbf, dbh, &tmp, handle->id) < 0){
  382. return -1;
  383. }
  384. refresh_handle(handle, &tmp, 1);
  385. for(i=0; i<DB_NUM; i++) {
  386. if(handle->db[i].url.len > 0){
  387. LM_INFO("checking id %i no %i, url %.*s, status %s\n", handle->id, handle->db[i].no,
  388. handle->db[i].url.len, handle->db[i].url.s, (handle->db[i].status == DB_ON ? "ON" : (handle->db[i].status == DB_OFF ? "OFF" : "DEACTIVATED")));
  389. if(handle->db[i].status == DB_OFF) {
  390. tmpurl.len = handle->db[i].url.len;
  391. tmpurl.s = handle->db[i].url.s;
  392. if((handle->db[i].dbh = handle->db[i].dbf.init(&tmpurl)) != NULL){
  393. if(db_reactivate(handle, handle->db[i].no) < 0) {
  394. LM_ERR("could not reactivate id %i, db %i.\n",
  395. handle->id, handle->db[i].no);
  396. handle->db[i].dbf.close(handle->db[i].dbh);
  397. handle->db[i].dbh = NULL;
  398. } else {
  399. handle->db[i].status = DB_ON;
  400. set_must_reconnect();
  401. }
  402. } else {
  403. LM_NOTICE("%s: db id %i, no %i url %.*s is still down\n", __FUNCTION__,
  404. handle->id, handle->db[i].no, handle->db[i].url.len, handle->db[i].url.s);
  405. }
  406. } else if((handle->db[i].status == DB_ON) && handle->db[i].dbh) {
  407. if((handle->db[i].failover_time < (time(NULL) - expire_time)) && (handle->db[i].failover_time != UL_DB_ZERO_TIME)){
  408. LM_ERR("%s: failover_time: %ld, now: %ld, delta: %ld, now going to reset failover time\n", __FUNCTION__,
  409. (long int)handle->db[i].failover_time, (long int)time(NULL), (long int)(time(NULL) - handle->db[i].failover_time));
  410. if(db_reset_failover_time(handle, handle->db[i].no) < 0) {
  411. LM_ERR("could not reset failover time for id %i, db %i.\n",
  412. handle->id, handle->db[i].no);
  413. }
  414. }
  415. }
  416. } else {
  417. LM_ERR("id %i, no url to check\n", handle->id);
  418. }
  419. }
  420. return 1;
  421. }
  422. static void free_handle(ul_db_handle_list_t * element) {
  423. if(element){
  424. if(element->handle){
  425. pkg_free(element->handle);
  426. }
  427. pkg_free(element);
  428. }
  429. return;
  430. }
  431. static int check_status(ul_db_handle_t * a, ul_db_handle_t * b){
  432. int i;
  433. if(!a->active){
  434. LM_NOTICE("id %i is inactive\n", a->id);
  435. return -1;
  436. }
  437. if(must_refresh(a->check)){
  438. LM_NOTICE("id %i must be refreshed\n", a->id);
  439. return -1;
  440. }
  441. if(must_reconnect(a->check)){
  442. LM_NOTICE("id %i must be reconnected\n", a->id);
  443. return -1;
  444. }
  445. for(i=0; i<DB_NUM; i++){
  446. if(strcmp(a->db[i].url.s, b->db[i].url.s) != 0){
  447. LM_NOTICE("id %i, db %s has different url\n", a->id, a->db[i].url.s);
  448. return -1;
  449. }
  450. if(a->db[i].status != b->db[i].status){
  451. LM_NOTICE("id %i, db %s has different status\n", a->id, a->db[i].url.s);
  452. return -1;
  453. }
  454. if(a->db[i].no != b->db[i].no){
  455. LM_NOTICE("id %i, db %s has different no\n", a->id, a->db[i].url.s);
  456. return -1;
  457. }
  458. if((a->db[i].status == DB_ON) && (!a->db[i].dbh)){
  459. LM_NOTICE("id %i, db %s has inconsistent status (1)\n", a->id, a->db[i].url.s);
  460. return -1;
  461. }
  462. if((a->db[i].status == DB_OFF) && (a->db[i].dbh)){
  463. LM_NOTICE("id %i, db %s has inconsistent status (2)\n", a->id, a->db[i].url.s);
  464. return -1;
  465. }
  466. }
  467. return 0;
  468. }
  469. static int compute_id(str* first, str* second){
  470. unsigned int crc32_val;
  471. #define BUF_MAXSIZE 1024
  472. char aux[BUF_MAXSIZE];
  473. str tmp;
  474. if(!first){
  475. LM_ERR("Null first parameter received\n");
  476. return -1;
  477. }
  478. if(use_domain){
  479. //compute crc32(user@domain)
  480. LM_DBG("XDBGX: compute_id HAS second key : %.*s", first->len, first->s);
  481. if(!second){
  482. LM_ERR("Null second parameter received and use_domain set to true\n");
  483. return -1;
  484. }
  485. tmp.len = first->len + second->len + 1;
  486. if( tmp.len > BUF_MAXSIZE - 1 ){
  487. LM_ERR("Very long user or domain\n");
  488. return -1;
  489. }
  490. memcpy(aux, first->s, first->len);
  491. aux[first->len] = '@';
  492. memcpy(aux + first->len + 1, second->s, second->len);
  493. tmp.s = aux;
  494. crc32_uint(&tmp, &crc32_val);
  495. return crc32_val % max_loc_nr + 1;
  496. }else{
  497. crc32_uint(first, &crc32_val);
  498. LM_DBG("crc32 for %.*s is %u\n", first->len, first->s, crc32_val);
  499. return crc32_val % max_loc_nr + 1;
  500. }
  501. }
  502. int load_data(db_func_t * dbf, db1_con_t * dbh, ul_db_handle_t * handle, int id){
  503. db1_res_t *res;
  504. db_row_t *row;
  505. db_key_t cols[7];
  506. db_key_t keys[2];
  507. db_val_t key_vals[2];
  508. db_op_t op[2];
  509. db_key_t order;
  510. int i, ret = 0;
  511. if(!dbf || !dbh || !handle){
  512. LM_ERR("NULL-Pointer in Parameter\n");
  513. return -1;
  514. }
  515. memset(handle, 0, sizeof(ul_db_handle_t));
  516. cols[0] = &num_col;
  517. cols[1] = &url_col;
  518. cols[2] = &status_col;
  519. cols[3] = &failover_time_col;
  520. cols[4] = &spare_col;
  521. cols[5] = &error_col;
  522. cols[6] = &risk_group_col;
  523. order = &num_col;
  524. keys[0] = &id_col;
  525. op[0] = OP_EQ;
  526. key_vals[0].type = DB1_INT;
  527. key_vals[0].nul = 0;
  528. key_vals[0].val.int_val = id;
  529. if(dbf->use_table(dbh, &reg_table) < 0){
  530. LM_ERR("could't use table.\n");
  531. return -1;
  532. }
  533. if(dbf->query(dbh, keys, op, key_vals, cols, 1, 7, order, &res) < 0){
  534. LM_ERR("error while doing db query.\n");
  535. return -1;
  536. }
  537. if(RES_ROW_N(res) < DB_NUM) {
  538. LM_ERR("keys have too few location databases\n");
  539. ret = -1;
  540. goto ret;
  541. }
  542. handle->id = id;
  543. for(i=0; i<DB_NUM; i++) {
  544. row = RES_ROWS(res) + i;
  545. handle->db[i].no = (int)VAL_INT(ROW_VALUES(row));
  546. if(VAL_NULL(ROW_VALUES(row) + 1)){
  547. LM_ERR("Weird: Empty database URL\n");
  548. ret = -1;
  549. goto ret;
  550. }
  551. if(strlen((char *)VAL_STRING(ROW_VALUES(row) + 1)) >= (UL_DB_URL_LEN - 1)){
  552. LM_ERR("weird: very large URL (%d Bytes)\n",
  553. (int)(strlen((char *)VAL_STRING(ROW_VALUES(row) + 1)) + 1));
  554. ret = -1;
  555. goto ret;
  556. }
  557. strcpy(handle->db[i].url.s, (char *)VAL_STRING(ROW_VALUES(row) + 1));
  558. handle->db[i].url.len = strlen(handle->db[i].url.s);
  559. handle->db[i].status = (int)VAL_INT(ROW_VALUES(row) + 2);
  560. handle->db[i].failover_time = VAL_TIME (ROW_VALUES(row) + 3);
  561. handle->db[i].spare = VAL_INT (ROW_VALUES(row) + 4);
  562. handle->db[i].errors = VAL_INT (ROW_VALUES(row) + 5);
  563. handle->db[i].rg = VAL_INT (ROW_VALUES(row) + 6);
  564. }
  565. ret:
  566. dbf->free_result(dbh, res);
  567. return ret;
  568. }