| 1420 | } |
| 1421 | |
| 1422 | static int _add_proxies_from_database(void) { |
| 1423 | |
| 1424 | /* select * from rtpproxy_sockets order by set_id */ |
| 1425 | db_key_t colsToReturn[2], order_by = &str_init("set_id"); |
| 1426 | db_res_t *result = NULL; |
| 1427 | int rowCount = 0; |
| 1428 | char *rtpp_socket; |
| 1429 | db_row_t *row; |
| 1430 | db_val_t *row_vals; |
| 1431 | int set_id; |
| 1432 | |
| 1433 | colsToReturn[0]=&rtpp_sock_col; |
| 1434 | colsToReturn[1]=&set_id_col; |
| 1435 | |
| 1436 | if(db_functions.use_table(db_connection, &table) < 0) { |
| 1437 | LM_ERR("Error trying to use table\n"); |
| 1438 | return -1; |
| 1439 | } |
| 1440 | |
| 1441 | if(db_functions.query(db_connection, 0, 0, 0,colsToReturn, 0, 2, order_by, |
| 1442 | &result) < 0) { |
| 1443 | LM_ERR("Error querying database\n"); |
| 1444 | if(result) |
| 1445 | db_functions.free_result(db_connection, result); |
| 1446 | return -1; |
| 1447 | } |
| 1448 | |
| 1449 | if(result == NULL) |
| 1450 | { |
| 1451 | LM_ERR("mysql query failed - NULL result\n"); |
| 1452 | return -1; |
| 1453 | } |
| 1454 | |
| 1455 | if (RES_ROW_N(result)<=0 || RES_ROWS(result)[0].values[0].nul != 0) { |
| 1456 | LM_DBG("No proxies were found\n"); |
| 1457 | if(db_functions.free_result(db_connection, result) < 0){ |
| 1458 | LM_ERR("Error freeing result\n"); |
| 1459 | return -1; |
| 1460 | } |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | for(rowCount=0; rowCount < RES_ROW_N(result); rowCount++) { |
| 1465 | |
| 1466 | row= &result->rows[rowCount]; |
| 1467 | row_vals = ROW_VALUES(row); |
| 1468 | |
| 1469 | rtpp_socket = (char*)row_vals[0].val.string_val; |
| 1470 | if(rtpp_socket == NULL) |
| 1471 | { |
| 1472 | LM_ERR("NULL value for rtpproxy_socket column\n"); |
| 1473 | goto error; |
| 1474 | } |
| 1475 | set_id= row_vals[1].val.int_val; |
| 1476 | |
| 1477 | if(rtpproxy_add_rtpproxy_set(rtpp_socket, set_id) == -1) |
| 1478 | { |
| 1479 | LM_ERR("failed to add rtp proxy\n"); |
no test coverage detected