Skip to content

Commit eb8c94d

Browse files
mi api: allow floats and wider integers in the json response
This commit changes the add_mi_int()/init_mi_result_int() functions to add_mi_number()/init_mi_result_number() which now take a double parameter instead of an int.
1 parent ca5fa4b commit eb8c94d

File tree

15 files changed

+67
-67
lines changed

15 files changed

+67
-67
lines changed

blacklists.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,9 @@ static mi_response_t *mi_print_blacklists(const mi_params_t *params,
674674
blst_heads[i].name.s, blst_heads[i].name.len) < 0)
675675
goto error;
676676

677-
if (add_mi_int(list_item, MI_SSTR("owner"), blst_heads[i].owner) < 0)
677+
if (add_mi_number(list_item, MI_SSTR("owner"), blst_heads[i].owner) < 0)
678678
goto error;
679-
if (add_mi_int(list_item, MI_SSTR("flags"), blst_heads[i].flags) < 0)
679+
if (add_mi_number(list_item, MI_SSTR("flags"), blst_heads[i].flags) < 0)
680680
goto error;
681681

682682
rules_arr = add_mi_array(list_item, MI_SSTR("Rules"));
@@ -688,7 +688,7 @@ static mi_response_t *mi_print_blacklists(const mi_params_t *params,
688688
if (!rule_item)
689689
goto error;
690690

691-
if (add_mi_int(rule_item, MI_SSTR("flags"), blr->flags) < 0)
691+
if (add_mi_number(rule_item, MI_SSTR("flags"), blr->flags) < 0)
692692
goto error;
693693

694694
p = ip_addr2a(&blr->ip_net.ip);
@@ -701,10 +701,10 @@ static mi_response_t *mi_print_blacklists(const mi_params_t *params,
701701
if (add_mi_string(rule_item, MI_SSTR("Mask"), p, len) < 0)
702702
goto error;
703703

704-
if (add_mi_int(rule_item, MI_SSTR("Proto"), blr->proto) < 0)
704+
if (add_mi_number(rule_item, MI_SSTR("Proto"), blr->proto) < 0)
705705
goto error;
706706

707-
if (add_mi_int(rule_item, MI_SSTR("Port"), blr->port) < 0)
707+
if (add_mi_number(rule_item, MI_SSTR("Port"), blr->port) < 0)
708708
goto error;
709709

710710
if (blr->body.s) {
@@ -715,7 +715,7 @@ static mi_response_t *mi_print_blacklists(const mi_params_t *params,
715715
}
716716

717717
if (blst_heads[i].flags&BL_DO_EXPIRE) {
718-
if (add_mi_int(rule_item, MI_SSTR("Expire"), blr->expire_end) < 0)
718+
if (add_mi_number(rule_item, MI_SSTR("Expire"), blr->expire_end) < 0)
719719
goto error;
720720
}
721721
}

evi/event_interface.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ mi_response_t *mi_events_list(const mi_params_t *params,
505505
events[i].name.s, events[i].name.len) < 0)
506506
goto error;
507507

508-
if (add_mi_int(event_item, MI_SSTR("id"), events[i].id) < 0)
508+
if (add_mi_number(event_item, MI_SSTR("id"), events[i].id) < 0)
509509
goto error;
510510
}
511511

@@ -544,7 +544,7 @@ static int evi_print_subscriber(mi_item_t *subs_obj, evi_subs_p subs)
544544
return -1;
545545

546546
if (sock->flags & EVI_EXPIRE) {
547-
if (add_mi_int(subs_obj, MI_SSTR("expire"), sock->expire) < 0)
547+
if (add_mi_number(subs_obj, MI_SSTR("expire"), sock->expire) < 0)
548548
return -1;
549549
} else {
550550
if (add_mi_string(subs_obj, MI_SSTR("expire"), MI_SSTR("never")) < 0)
@@ -566,7 +566,7 @@ static int evi_print_event(mi_item_t *ev_obj, evi_event_t *ev, evi_subs_p subs)
566566
if (add_mi_string(ev_obj, MI_SSTR("name"), ev->name.s, ev->name.len) < 0)
567567
goto error;
568568

569-
if (add_mi_int(ev_obj, MI_SSTR("id"), ev->id) < 0)
569+
if (add_mi_number(ev_obj, MI_SSTR("id"), ev->id) < 0)
570570
goto error;
571571

572572
if (subs) {

mem/shm_mem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ mi_response_t *mi_shm_check(const mi_params_t *params,
456456
if (!resp)
457457
return NULL;
458458

459-
if (add_mi_int(resp, MI_SSTR("total_fragments"), ret) < 0) {
459+
if (add_mi_number(resp, MI_SSTR("total_fragments"), ret) < 0) {
460460
LM_ERR("failed to add MI item\n");
461461
free_mi_response(resp);
462462
return NULL;

mi/item.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
int param_err_type = -2;
3636

37-
static mi_response_t *_init_mi_result(mi_item_t **item_out, int type, int ival,
37+
static mi_response_t *_init_mi_result(mi_item_t **item_out, int type, int dval,
3838
const char *sval, int sval_len)
3939
{
4040
mi_response_t *res = NULL;
@@ -62,7 +62,7 @@ static mi_response_t *_init_mi_result(mi_item_t **item_out, int type, int ival,
6262
*item_out = cJSON_CreateStr(sval, sval_len);
6363
break;
6464
case cJSON_Number:
65-
*item_out = cJSON_CreateNumber(ival);
65+
*item_out = cJSON_CreateNumber(dval);
6666
break;
6767
case cJSON_True:
6868
*item_out = cJSON_CreateTrue();
@@ -111,7 +111,7 @@ mi_response_t *init_mi_result_string(const char *value, int value_len)
111111
return _init_mi_result(&item, cJSON_String, 0, value, value_len);
112112
}
113113

114-
mi_response_t *init_mi_result_int(int value)
114+
mi_response_t *init_mi_result_number(double value)
115115
{
116116
mi_item_t *item;
117117

@@ -193,7 +193,7 @@ void free_mi_response(mi_response_t *response)
193193
}
194194

195195
static mi_item_t *_add_mi_item(mi_item_t *to, char *name, int name_len,
196-
int type, int ival, const char *sval, int sval_len)
196+
int type, int dval, const char *sval, int sval_len)
197197
{
198198
mi_item_t *item = NULL;
199199
str name_str;
@@ -211,7 +211,7 @@ static mi_item_t *_add_mi_item(mi_item_t *to, char *name, int name_len,
211211
item = cJSON_CreateStr(sval, sval_len);
212212
break;
213213
case cJSON_Number:
214-
item = cJSON_CreateNumber(ival);
214+
item = cJSON_CreateNumber(dval);
215215
break;
216216
case cJSON_True:
217217
item = cJSON_CreateTrue();
@@ -278,7 +278,7 @@ int add_mi_string_fmt(mi_item_t *to, char *name, int name_len,
278278
0 : -1;
279279
}
280280

281-
int add_mi_int(mi_item_t *to, char *name, int name_len, int value)
281+
int add_mi_number(mi_item_t *to, char *name, int name_len, double value)
282282
{
283283
return _add_mi_item(to, name, name_len, cJSON_Number, value, NULL, 0) ?
284284
0 : -1;

mi/item.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ mi_response_t *init_mi_result_string(const char *value, int value_len);
8080
#define init_mi_result_ok() init_mi_result_string(MI_SSTR(MI_OK_S))
8181

8282
/* Initializes a successful MI Response
83-
* with the provided integer.
83+
* with the provided double (as a 'number' json type).
8484
*/
85-
mi_response_t *init_mi_result_int(int value);
85+
mi_response_t *init_mi_result_number(double value);
8686

8787
/* Initializes a successful MI Response
8888
* with the provided boolean value.
@@ -135,10 +135,10 @@ int add_mi_string(mi_item_t *to, char *name, int name_len,
135135
int add_mi_string_fmt(mi_item_t *to, char *name, int name_len,
136136
char *fmt_val, ...);
137137

138-
/* Appends an integer to an array or to an object at the given name.
139-
* When appending to an array, @name and @name_len are ignored.
138+
/* Appends a double (as a 'number' json type) to an array or to an object at
139+
* the given name. When appending to an array, @name and @name_len are ignored.
140140
*/
141-
int add_mi_int(mi_item_t *to, char *name, int name_len, int value);
141+
int add_mi_number(mi_item_t *to, char *name, int name_len, double value);
142142

143143
/* Appends a boolean to an array or to an object at the given name.
144144
* When appending to an array, @name and @name_len are ignored.

mi/mi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ int add_id_to_response(mi_item_t *id, mi_response_t *resp)
424424

425425
switch ((id->type) & 0xFF) {
426426
case cJSON_Number:
427-
if (add_mi_int(resp, MI_SSTR(JSONRPC_ID_S), id->valueint) < 0) {
427+
if (add_mi_number(resp, MI_SSTR(JSONRPC_ID_S), id->valueint) < 0) {
428428
LM_ERR("Failed to add int value to MI item\n");
429429
return -1;
430430
}

mi/mi_core.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ static mi_response_t *mi_ps(const mi_params_t *params,
234234
if (!proc_item)
235235
goto error;
236236

237-
if (add_mi_int(proc_item, MI_SSTR("ID"), i) < 0)
237+
if (add_mi_number(proc_item, MI_SSTR("ID"), i) < 0)
238238
goto error;
239239

240-
if (add_mi_int(proc_item, MI_SSTR("PID"), pt[i].pid) < 0)
240+
if (add_mi_number(proc_item, MI_SSTR("PID"), pt[i].pid) < 0)
241241
goto error;
242242

243243
if (add_mi_string(proc_item, MI_SSTR("Type"),
@@ -278,10 +278,10 @@ mi_response_t *mi_log_level(const mi_params_t *params, pid_t pid)
278278
return 0;
279279

280280
if (pid) {
281-
if (add_mi_int(resp_obj, MI_SSTR("Log level"), new_level) < 0)
281+
if (add_mi_number(resp_obj, MI_SSTR("Log level"), new_level) < 0)
282282
goto error;
283283
} else {
284-
if (add_mi_int(resp_obj, MI_SSTR("New global log level"), new_level) < 0)
284+
if (add_mi_number(resp_obj, MI_SSTR("New global log level"), new_level) < 0)
285285
goto error;
286286
}
287287

@@ -329,10 +329,10 @@ static mi_response_t *w_log_level(const mi_params_t *params,
329329
if (!proc_item)
330330
goto error;
331331

332-
if (add_mi_int(proc_item, MI_SSTR("PID"), pt[i].pid) < 0)
332+
if (add_mi_number(proc_item, MI_SSTR("PID"), pt[i].pid) < 0)
333333
goto error;
334334

335-
if (add_mi_int(proc_item, MI_SSTR("Log level"), pt[i].log_level) < 0)
335+
if (add_mi_number(proc_item, MI_SSTR("Log level"), pt[i].log_level) < 0)
336336
goto error;
337337

338338
if (add_mi_string(proc_item, MI_SSTR("Type"),

modules/b2b_logic/b2b_logic.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -1449,16 +1449,16 @@ static inline int internal_mi_print_b2bl_entity_id(mi_item_t *item, b2bl_entity_
14491449
c->key.s, c->key.len) < 0)
14501450
goto error;
14511451

1452-
if (add_mi_int(item, MI_SSTR("disconnected"),
1452+
if (add_mi_number(item, MI_SSTR("disconnected"),
14531453
c->disconnected) < 0)
14541454
goto error;
1455-
if (add_mi_int(item, MI_SSTR("state"),
1455+
if (add_mi_number(item, MI_SSTR("state"),
14561456
c->state) < 0)
14571457
goto error;
1458-
if (add_mi_int(item, MI_SSTR("no"),
1458+
if (add_mi_number(item, MI_SSTR("no"),
14591459
c->no) < 0)
14601460
goto error;
1461-
if (add_mi_int(item, MI_SSTR("type"),
1461+
if (add_mi_number(item, MI_SSTR("type"),
14621462
c->type) < 0)
14631463
goto error;
14641464

@@ -1525,26 +1525,26 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params,
15251525
if (!tuple_item)
15261526
goto error;
15271527

1528-
if (add_mi_int(tuple_item, MI_SSTR("id"), tuple->id) < 0)
1528+
if (add_mi_number(tuple_item, MI_SSTR("id"), tuple->id) < 0)
15291529
goto error;
15301530
if (add_mi_string(tuple_item, MI_SSTR("key"),
15311531
tuple->key->s, tuple->key->len) < 0)
15321532
goto error;
1533-
if (add_mi_int(tuple_item, MI_SSTR("scenario_state"),
1533+
if (add_mi_number(tuple_item, MI_SSTR("scenario_state"),
15341534
tuple->scenario_state) < 0)
15351535
goto error;
1536-
if (add_mi_int(tuple_item, MI_SSTR("lifetime"),
1536+
if (add_mi_number(tuple_item, MI_SSTR("lifetime"),
15371537
tuple->lifetime) < 0)
15381538
goto error;
1539-
if (add_mi_int(tuple_item, MI_SSTR("db_flag"),
1539+
if (add_mi_number(tuple_item, MI_SSTR("db_flag"),
15401540
tuple->db_flag) < 0)
15411541
goto error;
15421542

15431543
if (tuple->scenario) {
15441544
if (add_mi_string(tuple_item, MI_SSTR("scenario"),
15451545
tuple->scenario->id.s, tuple->scenario->id.len) < 0)
15461546
goto error;
1547-
if (add_mi_int(tuple_item, MI_SSTR("next_scenario_state"),
1547+
if (add_mi_number(tuple_item, MI_SSTR("next_scenario_state"),
15481548
tuple->next_scenario_state) < 0)
15491549
goto error;
15501550
}
@@ -1560,7 +1560,7 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params,
15601560
if (!server_item)
15611561
goto error;
15621562

1563-
if (add_mi_int(server_item, MI_SSTR("index"), index) < 0)
1563+
if (add_mi_number(server_item, MI_SSTR("index"), index) < 0)
15641564
goto error;
15651565
if (internal_mi_print_b2bl_entity_id(server_item,
15661566
tuple->servers[index])!=0)
@@ -1579,7 +1579,7 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params,
15791579
if (!clients_item)
15801580
goto error;
15811581

1582-
if (add_mi_int(server_item, MI_SSTR("index"), index) < 0)
1582+
if (add_mi_number(server_item, MI_SSTR("index"), index) < 0)
15831583
goto error;
15841584
if (internal_mi_print_b2bl_entity_id(clients_item,
15851585
tuple->clients[index])!=0)
@@ -1598,7 +1598,7 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params,
15981598
if (!b_entities_item)
15991599
goto error;
16001600

1601-
if (add_mi_int(b_entities_item, MI_SSTR("index"), index) < 0)
1601+
if (add_mi_number(b_entities_item, MI_SSTR("index"), index) < 0)
16021602
goto error;
16031603
if (internal_mi_print_b2bl_entity_id(b_entities_item,
16041604
tuple->bridge_entities[index])!=0)

modules/call_center/call_center.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -1167,23 +1167,23 @@ static mi_response_t *mi_cc_list_flows(const mi_params_t *params,
11671167
flow->id.s, flow->id.len) < 0)
11681168
goto error;
11691169

1170-
if (add_mi_int(flow_item, MI_SSTR("Avg Call Duration"),
1170+
if (add_mi_number(flow_item, MI_SSTR("Avg Call Duration"),
11711171
flow->avg_call_duration) < 0)
11721172
goto error;
11731173

1174-
if (add_mi_int(flow_item, MI_SSTR("Processed Calls"),
1174+
if (add_mi_number(flow_item, MI_SSTR("Processed Calls"),
11751175
flow->processed_calls) < 0)
11761176
goto error;
11771177

1178-
if (add_mi_int(flow_item, MI_SSTR("Logged Agents"),
1178+
if (add_mi_number(flow_item, MI_SSTR("Logged Agents"),
11791179
flow->logged_agents) < 0)
11801180
goto error;
11811181

1182-
if (add_mi_int(flow_item, MI_SSTR("Ongoing Calls"),
1182+
if (add_mi_number(flow_item, MI_SSTR("Ongoing Calls"),
11831183
flow->ongoing_calls) < 0)
11841184
goto error;
11851185

1186-
if (add_mi_int(flow_item, MI_SSTR("Ref Calls"),
1186+
if (add_mi_number(flow_item, MI_SSTR("Ref Calls"),
11871187
flow->ref_cnt) < 0)
11881188
goto error;
11891189
}
@@ -1234,7 +1234,7 @@ static mi_response_t *mi_cc_list_agents(const mi_params_t *params,
12341234
agent->id.s, agent->id.len) < 0)
12351235
goto error;
12361236

1237-
if (add_mi_int(agent_item, MI_SSTR("Ref"),
1237+
if (add_mi_number(agent_item, MI_SSTR("Ref"),
12381238
agent->ref_cnt) < 0)
12391239
goto error;
12401240

@@ -1305,7 +1305,7 @@ static mi_response_t *mi_cc_list_calls(const mi_params_t *params,
13051305
call->b2bua_id.s, call->b2bua_id.len) < 0)
13061306
goto error;
13071307

1308-
if (add_mi_int(call_item, MI_SSTR("Ref"),
1308+
if (add_mi_number(call_item, MI_SSTR("Ref"),
13091309
call->ref_cnt) < 0)
13101310
goto error;
13111311

@@ -1321,7 +1321,7 @@ static mi_response_t *mi_cc_list_calls(const mi_params_t *params,
13211321
LM_DBG("call->recv_time= %d, ticks= %d\n", call->recv_time, get_ticks());
13221322
if(call->state != CC_CALL_ENDED)
13231323
{
1324-
if (add_mi_int(call_item, MI_SSTR("Call Time"),
1324+
if (add_mi_number(call_item, MI_SSTR("Call Time"),
13251325
(unsigned long)(call->recv_time?(get_ticks() - call->recv_time):0)) < 0)
13261326
goto error;
13271327

@@ -1483,22 +1483,22 @@ static mi_response_t *mi_cc_list_queue(const mi_params_t *params,
14831483
if (!call_item)
14841484
goto error;
14851485

1486-
if (add_mi_int(call_item, MI_SSTR("index"), n) < 0)
1486+
if (add_mi_number(call_item, MI_SSTR("index"), n) < 0)
14871487
goto error;
14881488

1489-
if (add_mi_int(call_item, MI_SSTR("Waiting for"),
1489+
if (add_mi_number(call_item, MI_SSTR("Waiting for"),
14901490
now-call->last_start) < 0)
14911491
goto error;
14921492

1493-
if (add_mi_int(call_item, MI_SSTR("ETW"), call->eta) < 0)
1493+
if (add_mi_number(call_item, MI_SSTR("ETW"), call->eta) < 0)
14941494
goto error;
14951495

14961496
/* flow data */
14971497
if (add_mi_string(call_item, MI_SSTR("Flow"),
14981498
call->flow->id.s, call->flow->id.len) < 0)
14991499
goto error;
15001500

1501-
if (add_mi_int(call_item, MI_SSTR("Priority"), call->flow->priority) < 0)
1501+
if (add_mi_number(call_item, MI_SSTR("Priority"), call->flow->priority) < 0)
15021502
goto error;
15031503

15041504
s = get_skill_by_id(data,call->flow->skill);

0 commit comments

Comments
 (0)