|
@@ -18,7 +18,7 @@
|
|
|
*
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
*
|
|
|
*/
|
|
|
|
|
@@ -33,27 +33,23 @@
|
|
|
|
|
|
extern data_t _data;
|
|
|
|
|
|
-void rpc_kill_call(rpc_t* rpc, void* ctx)
|
|
|
-{
|
|
|
+void rpc_kill_call(rpc_t* rpc, void* ctx) {
|
|
|
call_t *call;
|
|
|
hash_tables_t *hts;
|
|
|
str callid;
|
|
|
|
|
|
- if (!rpc->scan(ctx, "S", &callid))
|
|
|
- {
|
|
|
+ if (!rpc->scan(ctx, "S", &callid)) {
|
|
|
LM_ERR("%s: error reading RPC param\n", __FUNCTION__);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (try_get_call_entry(&callid, &call, &hts) != 0)
|
|
|
- {
|
|
|
+ if (try_get_call_entry(&callid, &call, &hts) != 0) {
|
|
|
LM_ERR("%s: call [%.*s] not found\n", __FUNCTION__, callid.len, callid.s);
|
|
|
rpc->fault(ctx, 404, "CallID Not Found");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (call == NULL)
|
|
|
- {
|
|
|
+ if (call == NULL) {
|
|
|
LM_ERR("%s: call [%.*s] is in null state\n", __FUNCTION__, callid.len, callid.s);
|
|
|
rpc->fault(ctx, 500, "Call is NULL");
|
|
|
return;
|
|
@@ -68,29 +64,25 @@ void rpc_kill_call(rpc_t* rpc, void* ctx)
|
|
|
lock_release(&call->lock);
|
|
|
}
|
|
|
|
|
|
-void rpc_check_client_stats(rpc_t* rpc, void* ctx)
|
|
|
-{
|
|
|
+void rpc_check_client_stats(rpc_t* rpc, void* ctx) {
|
|
|
call_t *call, *tmp;
|
|
|
int index = 0;
|
|
|
str client_id, rows;
|
|
|
char row_buffer[512];
|
|
|
credit_data_t *credit_data;
|
|
|
|
|
|
- if (!rpc->scan(ctx, "S", &client_id))
|
|
|
- {
|
|
|
+ if (!rpc->scan(ctx, "S", &client_id)) {
|
|
|
LM_ERR("%s: error reading RPC param\n", __FUNCTION__);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (try_get_credit_data_entry(&client_id, &credit_data) != 0)
|
|
|
- {
|
|
|
+ if (try_get_credit_data_entry(&client_id, &credit_data) != 0) {
|
|
|
LM_ERR("%s: client [%.*s] not found\n", __FUNCTION__, client_id.len, client_id.s);
|
|
|
rpc->fault(ctx, 404, "Not Found");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (credit_data == NULL)
|
|
|
- {
|
|
|
+ if (credit_data == NULL) {
|
|
|
LM_ERR("%s: credit data for client [%.*s] is NULL\n", __FUNCTION__, client_id.len, client_id.s);
|
|
|
rpc->fault(ctx, 500, "Internal Server Error");
|
|
|
return;
|
|
@@ -98,8 +90,7 @@ void rpc_check_client_stats(rpc_t* rpc, void* ctx)
|
|
|
|
|
|
lock_get(&credit_data->lock);
|
|
|
|
|
|
- if (credit_data->number_of_calls <= 0)
|
|
|
- {
|
|
|
+ if (credit_data->number_of_calls <= 0) {
|
|
|
lock_release(&credit_data->lock);
|
|
|
LM_INFO("No calls for current client\n");
|
|
|
return;
|
|
@@ -111,43 +102,40 @@ void rpc_check_client_stats(rpc_t* rpc, void* ctx)
|
|
|
if (rows.s == NULL)
|
|
|
goto nomem;
|
|
|
|
|
|
- clist_foreach_safe(credit_data->call_list, call, tmp, next)
|
|
|
- {
|
|
|
+ clist_foreach_safe(credit_data->call_list, call, tmp, next) {
|
|
|
int row_len = 0;
|
|
|
|
|
|
memset(row_buffer, 0, sizeof(row_buffer));
|
|
|
|
|
|
if (credit_data->type == CREDIT_MONEY)
|
|
|
snprintf(row_buffer, sizeof(row_buffer), "id:%d,confirmed:%s,local_consumed_amount:%f,global_consumed_amount:%f,local_max_amount:%f,global_max_amount:%f,call_id:%.*s,start_timestamp:%d"
|
|
|
- ",inip:%d,finp:%d,cps:%f;",
|
|
|
- index,
|
|
|
- call->confirmed ? "yes" : "no",
|
|
|
- call->consumed_amount,
|
|
|
- credit_data->consumed_amount,
|
|
|
- call->max_amount,
|
|
|
- credit_data->max_amount,
|
|
|
- call->sip_data.callid.len, call->sip_data.callid.s,
|
|
|
- call->start_timestamp,
|
|
|
- call->money_based.initial_pulse,
|
|
|
- call->money_based.final_pulse,
|
|
|
- call->money_based.cost_per_second
|
|
|
- );
|
|
|
+ ",inip:%d,finp:%d,cps:%f;",
|
|
|
+ index,
|
|
|
+ call->confirmed ? "yes" : "no",
|
|
|
+ call->consumed_amount,
|
|
|
+ credit_data->consumed_amount,
|
|
|
+ call->max_amount,
|
|
|
+ credit_data->max_amount,
|
|
|
+ call->sip_data.callid.len, call->sip_data.callid.s,
|
|
|
+ call->start_timestamp,
|
|
|
+ call->money_based.initial_pulse,
|
|
|
+ call->money_based.final_pulse,
|
|
|
+ call->money_based.cost_per_second);
|
|
|
else
|
|
|
snprintf(row_buffer, sizeof(row_buffer), "id:%d,confirmed:%s,local_consumed_amount:%d,global_consumed_amount:%d,local_max_amount:%d,global_max_amount:%d,call_id:%.*s,start_timestamp:%d;",
|
|
|
- index,
|
|
|
- call->confirmed ? "yes" : "no",
|
|
|
- (int) call->consumed_amount,
|
|
|
- (int) credit_data->consumed_amount,
|
|
|
- (int) call->max_amount,
|
|
|
- (int) credit_data->max_amount,
|
|
|
- call->sip_data.callid.len, call->sip_data.callid.s,
|
|
|
- call->start_timestamp);
|
|
|
+ index,
|
|
|
+ call->confirmed ? "yes" : "no",
|
|
|
+ (int) call->consumed_amount,
|
|
|
+ (int) credit_data->consumed_amount,
|
|
|
+ (int) call->max_amount,
|
|
|
+ (int) credit_data->max_amount,
|
|
|
+ call->sip_data.callid.len, call->sip_data.callid.s,
|
|
|
+ call->start_timestamp);
|
|
|
|
|
|
row_len = strlen(row_buffer);
|
|
|
rows.s = pkg_realloc(rows.s, rows.len + row_len);
|
|
|
|
|
|
- if (rows.s == NULL)
|
|
|
- {
|
|
|
+ if (rows.s == NULL) {
|
|
|
lock_release(&credit_data->lock);
|
|
|
goto nomem;
|
|
|
}
|
|
@@ -160,8 +148,7 @@ void rpc_check_client_stats(rpc_t* rpc, void* ctx)
|
|
|
|
|
|
lock_release(&credit_data->lock);
|
|
|
|
|
|
- if (rpc->add(ctx, "S", &rows) < 0)
|
|
|
- {
|
|
|
+ if (rpc->add(ctx, "S", &rows) < 0) {
|
|
|
LM_ERR("%s: error creating RPC struct\n", __FUNCTION__);
|
|
|
}
|
|
|
|
|
@@ -175,8 +162,7 @@ nomem:
|
|
|
rpc->fault(ctx, 500, "No more memory\n");
|
|
|
}
|
|
|
|
|
|
-static int iterate_over_table(hash_tables_t *hts, str *result, credit_type_t type)
|
|
|
-{
|
|
|
+static int iterate_over_table(hash_tables_t *hts, str *result, credit_type_t type) {
|
|
|
struct str_hash_entry *h_entry, *tmp;
|
|
|
char row_buffer[512];
|
|
|
int index = 0;
|
|
@@ -185,8 +171,7 @@ static int iterate_over_table(hash_tables_t *hts, str *result, credit_type_t typ
|
|
|
|
|
|
if (hts->credit_data_by_client->table)
|
|
|
for(index = 0; index < hts->credit_data_by_client->size; index++)
|
|
|
- clist_foreach_safe(&hts->credit_data_by_client->table[index], h_entry, tmp, next)
|
|
|
- {
|
|
|
+ clist_foreach_safe(&hts->credit_data_by_client->table[index], h_entry, tmp, next) {
|
|
|
credit_data_t *credit_data = (credit_data_t *) h_entry->u.p;
|
|
|
lock_get(&credit_data->lock);
|
|
|
|
|
@@ -194,39 +179,36 @@ static int iterate_over_table(hash_tables_t *hts, str *result, credit_type_t typ
|
|
|
|
|
|
memset(row_buffer, 0, sizeof(row_buffer));
|
|
|
|
|
|
- if (type == CREDIT_TIME)
|
|
|
- {
|
|
|
+ if (type == CREDIT_TIME) {
|
|
|
snprintf(row_buffer, sizeof(row_buffer), "client_id:%.*s,"
|
|
|
- "number_of_calls:%d,"
|
|
|
- "concurrent_calls:%d,"
|
|
|
- "type:%d,"
|
|
|
- "max_amount:%d,"
|
|
|
- "consumed_amount:%d;",
|
|
|
- credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
|
|
|
- credit_data->number_of_calls,
|
|
|
- credit_data->concurrent_calls,
|
|
|
- type,
|
|
|
- (int) credit_data->max_amount,
|
|
|
- (int) credit_data->consumed_amount);
|
|
|
+ "number_of_calls:%d,"
|
|
|
+ "concurrent_calls:%d,"
|
|
|
+ "type:%d,"
|
|
|
+ "max_amount:%d,"
|
|
|
+ "consumed_amount:%d;",
|
|
|
+ credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
|
|
|
+ credit_data->number_of_calls,
|
|
|
+ credit_data->concurrent_calls,
|
|
|
+ type,
|
|
|
+ (int) credit_data->max_amount,
|
|
|
+ (int) credit_data->consumed_amount);
|
|
|
}
|
|
|
- else if (type == CREDIT_MONEY)
|
|
|
- {
|
|
|
+ else if (type == CREDIT_MONEY) {
|
|
|
snprintf(row_buffer, sizeof(row_buffer), "client_id:%.*s,"
|
|
|
- "number_of_calls:%d,"
|
|
|
- "concurrent_calls:%d,"
|
|
|
- "type:%d,"
|
|
|
- "max_amount:%f,"
|
|
|
- "consumed_amount:%f;",
|
|
|
- credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
|
|
|
- credit_data->number_of_calls,
|
|
|
- credit_data->concurrent_calls,
|
|
|
- type,
|
|
|
- credit_data->max_amount,
|
|
|
- credit_data->consumed_amount);
|
|
|
+ "number_of_calls:%d,"
|
|
|
+ "concurrent_calls:%d,"
|
|
|
+ "type:%d,"
|
|
|
+ "max_amount:%f,"
|
|
|
+ "consumed_amount:%f;",
|
|
|
+ credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
|
|
|
+ credit_data->number_of_calls,
|
|
|
+ credit_data->concurrent_calls,
|
|
|
+ type,
|
|
|
+ credit_data->max_amount,
|
|
|
+ credit_data->consumed_amount);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- LM_ERR("Unknown credit type: %d", type);
|
|
|
+ else {
|
|
|
+ LM_ERR("Unknown credit type: %d\n", type);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -235,8 +217,7 @@ static int iterate_over_table(hash_tables_t *hts, str *result, credit_type_t typ
|
|
|
row_len = strlen(row_buffer);
|
|
|
result->s = pkg_realloc(result->s, result->len + row_len);
|
|
|
|
|
|
- if (result->s == NULL)
|
|
|
- {
|
|
|
+ if (result->s == NULL) {
|
|
|
lock_release(&hts->lock);
|
|
|
goto nomem;
|
|
|
}
|
|
@@ -255,8 +236,7 @@ nomem:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-void rpc_active_clients(rpc_t* rpc, void* ctx)
|
|
|
-{
|
|
|
+void rpc_active_clients(rpc_t* rpc, void* ctx) {
|
|
|
str rows;
|
|
|
|
|
|
rows.s = pkg_malloc(10);
|
|
@@ -269,8 +249,7 @@ void rpc_active_clients(rpc_t* rpc, void* ctx)
|
|
|
iterate_over_table(&_data.time, &rows, CREDIT_TIME);
|
|
|
iterate_over_table(&_data.money, &rows, CREDIT_MONEY);
|
|
|
|
|
|
- if (!rpc->add(ctx, "S", &rows) < 0)
|
|
|
- {
|
|
|
+ if (!rpc->add(ctx, "S", &rows) < 0) {
|
|
|
LM_ERR("%s: error creating RPC struct\n", __FUNCTION__);
|
|
|
}
|
|
|
|
|
@@ -280,7 +259,7 @@ void rpc_active_clients(rpc_t* rpc, void* ctx)
|
|
|
return;
|
|
|
|
|
|
nomem:
|
|
|
- LM_ERR("No more pkg memory");
|
|
|
+ LM_ERR("No more pkg memory\n");
|
|
|
rpc->fault(ctx, 500, "No more memory\n");
|
|
|
}
|
|
|
|