Changeset 1a81c83 for protocols/rpc
- Timestamp:
- 2015-05-06T15:48:16Z (10 years ago)
- Children:
- 6f903c3
- Parents:
- f81d8b8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/rpc/rpc.c
rf81d8b8 r1a81c83 50 50 * Not sure whether to use it. */ 51 51 JSON_Value *error = json_value_init_object(); 52 json_object_set_ number(json_object(error), "code", code);52 json_object_set_integer(json_object(error), "code", code); 53 53 json_object_set_string(json_object(error), "message", msg); 54 54 json_object_set_value(json_object(ret), "error", error); … … 78 78 JSON_Value *rpc = json_value_init_object(); 79 79 json_object_set_string(json_object(rpc), "method", method); 80 json_object_set_ number(json_object(rpc), "id", next_rpc_id++);80 json_object_set_integer(json_object(rpc), "id", next_rpc_id++); 81 81 82 82 JSON_Value *params = json_value_init_array(); … … 147 147 json_object_set_string_or_null(o, "nick", bu->nick); 148 148 json_object_set_string_or_null(o, "group", bu->group ? bu->group->name : NULL); 149 json_object_set_ number(o, "flags", bu->flags);149 json_object_set_integer(o, "flags", bu->flags); 150 150 json_object_set_string_or_null(o, "status", bu->status); 151 151 json_object_set_string_or_null(o, "status_msg", bu->status_msg); 152 json_object_set_ number(o, "login_time", bu->login_time);153 json_object_set_ number(o, "idle_time", bu->idle_time);152 json_object_set_integer(o, "login_time", bu->login_time); 153 json_object_set_integer(o, "idle_time", bu->idle_time); 154 154 return v; 155 155 } … … 163 163 JSON_Object *o = json_object(value); 164 164 set_t *set = set_add(&acc->set, name, json_object_get_string(o, "default"), NULL, acc); 165 /* JSON numbers are floats. The following line "might" be a 166 * terrible idea. As was JSON, but hey. */ 167 set->flags |= (int) json_object_get_number(o, "flags"); 165 set->flags |= json_object_get_integer(o, "flags"); 168 166 set->eval = rpc_set_evaluator; 169 167 set->eval_data = o; … … 210 208 /* Evaluator already did validation so ignore retval. */ 211 209 sscanf(value, "%d", &num); 212 json_array_append_ number(params, num);210 json_array_append_integer(params, num); 213 211 } else if (type_eval == set_eval_bool) { 214 212 json_array_append_boolean(params, bool2int(value)); … … 285 283 json_array_append_string(params, to); 286 284 json_array_append_string(params, message); 287 json_array_append_ number(params, flags);285 json_array_append_integer(params, flags); 288 286 return rpc_send(ic, rpc); 289 287 } … … 299 297 RPC_OUT_INIT("send_typing"); 300 298 json_array_append_string(params, who); 301 json_array_append_ number(params, flags);299 json_array_append_integer(params, flags); 302 300 return rpc_send(ic, rpc); 303 301 } … … 350 348 RPC_OUT_INIT("chat_invite"); 351 349 struct rpc_groupchat *rc = gc->data; 352 json_array_append_ number(params, rc->id);350 json_array_append_integer(params, rc->id); 353 351 json_array_append_string(params, who); 354 352 json_array_append_string_or_null(params, message); … … 359 357 RPC_OUT_INIT("chat_kick"); 360 358 struct rpc_groupchat *rc = gc->data; 361 json_array_append_ number(params, rc->id);359 json_array_append_integer(params, rc->id); 362 360 json_array_append_string(params, who); 363 361 json_array_append_string_or_null(params, message); … … 368 366 RPC_OUT_INIT("chat_leave"); 369 367 struct rpc_groupchat *rc = gc->data; 370 json_array_append_ number(params, rc->id);368 json_array_append_integer(params, rc->id); 371 369 rpc_send(gc->ic, rpc); 372 370 } … … 375 373 RPC_OUT_INIT("chat_msg"); 376 374 struct rpc_groupchat *rc = gc->data; 377 json_array_append_ number(params, rc->id);375 json_array_append_integer(params, rc->id); 378 376 json_array_append_string(params, msg); 379 json_array_append_ number(params, flags);377 json_array_append_integer(params, flags); 380 378 rpc_send(gc->ic, rpc); 381 379 } … … 402 400 #define SET_GROUPCHAT(rc) \ 403 401 do { \ 404 rc = rpc_groupchat_by_id(ic, json_array_get_ number(params, 0)); \402 rc = rpc_groupchat_by_id(ic, json_array_get_integer(params, 0)); \ 405 403 if (rc == NULL) \ 406 404 return jsonrpc_error(ENOENT, "No groupchat with that id."); \ … … 410 408 RPC_OUT_INIT("chat_with"); 411 409 struct rpc_groupchat *rc = rpc_groupchat_new(ic, who); 412 json_array_append_ number(params, rc->id);410 json_array_append_integer(params, rc->id); 413 411 json_array_append_string(params, who); 414 412 rpc_send(ic, rpc); … … 421 419 RPC_OUT_INIT("chat_join"); 422 420 struct rpc_groupchat *rc = rpc_groupchat_new(ic, room); 423 json_array_append_ number(params, rc->id);421 json_array_append_integer(params, rc->id); 424 422 json_array_append_string(params, room); 425 423 json_array_append_string_or_null(params, nick); … … 434 432 RPC_OUT_INIT("chat_topic"); 435 433 struct rpc_groupchat *rc = gc->data; 436 json_array_append_ number(params, rc->id);434 json_array_append_integer(params, rc->id); 437 435 json_array_append_string(params, topic); 438 436 rpc_send(gc->ic, rpc); … … 551 549 static JSON_Value *rpc_imcb_buddy_status(struct im_connection *ic, void *func_, JSON_Array *params) { 552 550 void (*func)(struct im_connection*, const char*, int, const char*, const char*) = func_; 553 func(ic, json_array_get_string(params, 0), json_array_get_ number(params, 1),551 func(ic, json_array_get_string(params, 0), json_array_get_integer(params, 1), 554 552 json_array_get_string(params, 2), json_array_get_string(params, 3)); 555 553 return NULL; … … 558 556 static JSON_Value *rpc_imcb_buddy_times(struct im_connection *ic, void *func_, JSON_Array *params) { 559 557 void (*func)(struct im_connection*, const char*, int, int) = func_; 560 func(ic, json_array_get_string(params, 0), json_array_get_ number(params, 1),561 json_array_get_ number(params, 2));558 func(ic, json_array_get_string(params, 0), json_array_get_integer(params, 1), 559 json_array_get_integer(params, 2)); 562 560 return NULL; 563 561 } … … 566 564 void (*func)(struct im_connection*, const char*, const char*, int, int) = func_; 567 565 func(ic, json_array_get_string(params, 0), json_array_get_string(params, 1), 568 json_array_get_ number(params, 2), json_array_get_number(params, 3));566 json_array_get_integer(params, 2), json_array_get_integer(params, 3)); 569 567 return NULL; 570 568 } … … 572 570 static JSON_Value *rpc_imcb_buddy_typing(struct im_connection *ic, void *func_, JSON_Array *params) { 573 571 void (*func)(struct im_connection*, const char*, int) = func_; 574 func(ic, (char*) json_array_get_string(params, 0), json_array_get_ number(params, 1));572 func(ic, (char*) json_array_get_string(params, 0), json_array_get_integer(params, 1)); 575 573 return NULL; 576 574 } … … 579 577 struct rpc_groupchat *rc = rpc_groupchat_new(ic, json_array_get_string(params, 0)); 580 578 JSON_Value *resp = json_value_init_object(); 581 json_object_set_ number(json_object(resp), "result", rc->id);579 json_object_set_integer(json_object(resp), "result", rc->id); 582 580 return resp; 583 581 } … … 596 594 SET_GROUPCHAT(rc); 597 595 func(rc->gc, json_array_get_string(params, 1), json_array_get_string(params, 2), 598 json_array_get_ number(params, 3), json_array_get_number(params, 4));596 json_array_get_integer(params, 3), json_array_get_integer(params, 4)); 599 597 return NULL; 600 598 } … … 613 611 SET_GROUPCHAT(rc); 614 612 func(rc->gc, json_array_get_string(params, 1), json_array_get_string(params, 2), 615 json_array_get_ number(params, 3));613 json_array_get_integer(params, 3)); 616 614 return NULL; 617 615 } … … 687 685 { "imcb_buddy_status", imcb_buddy_status, rpc_imcb_buddy_status, "snss" }, 688 686 { "imcb_buddy_status_msg", imcb_buddy_status_msg, rpc_imcb_add_buddy, "ss" }, 689 { "imcb_buddy_times", imcb_buddy_times, rpc_imcb_buddy_times, "s nn" },690 { "imcb_buddy_msg", imcb_buddy_msg, rpc_imcb_buddy_msg, "ss nn" },691 { "imcb_buddy_typing", imcb_buddy_typing, rpc_imcb_buddy_typing, "s n" },687 { "imcb_buddy_times", imcb_buddy_times, rpc_imcb_buddy_times, "sii" }, 688 { "imcb_buddy_msg", imcb_buddy_msg, rpc_imcb_buddy_msg, "ssii" }, 689 { "imcb_buddy_typing", imcb_buddy_typing, rpc_imcb_buddy_typing, "si" }, 692 690 { "imcb_chat_new", NULL, rpc_imcb_chat_new, "s" }, 693 691 694 692 /* RPCs below are equivalent, but with the struct groupchat* replaced 695 693 * with the numeric id of the chat. */ 696 { "imcb_chat_name_hint", imcb_chat_name_hint, rpc_imcb_chat_name_hint, " ns" },697 { "imcb_chat_msg", imcb_chat_msg, rpc_imcb_chat_msg, " nssnn" },698 { "imcb_chat_log", imcb_chat_log, rpc_imcb_chat_log, " ns" },699 { "imcb_chat_topic", imcb_chat_topic, rpc_imcb_chat_topic, " nssn" },700 { "imcb_chat_add_buddy", imcb_chat_add_buddy, rpc_imcb_chat_name_hint, " ns" },701 { "imcb_chat_remove_buddy", imcb_chat_remove_buddy, rpc_imcb_chat_remove_buddy, " nss" },702 { "imcb_chat_invite", imcb_chat_invite, rpc_imcb_chat_invite, " nsss" },694 { "imcb_chat_name_hint", imcb_chat_name_hint, rpc_imcb_chat_name_hint, "is" }, 695 { "imcb_chat_msg", imcb_chat_msg, rpc_imcb_chat_msg, "issii" }, 696 { "imcb_chat_log", imcb_chat_log, rpc_imcb_chat_log, "is" }, 697 { "imcb_chat_topic", imcb_chat_topic, rpc_imcb_chat_topic, "issi" }, 698 { "imcb_chat_add_buddy", imcb_chat_add_buddy, rpc_imcb_chat_name_hint, "is" }, 699 { "imcb_chat_remove_buddy", imcb_chat_remove_buddy, rpc_imcb_chat_remove_buddy, "iss" }, 700 { "imcb_chat_invite", imcb_chat_invite, rpc_imcb_chat_invite, "isss" }, 703 701 704 702 /* These are not imcb* functions but should still be exported. */ … … 722 720 if (json_array_get_count(params) != strlen(methods[i].args)) { 723 721 imcb_error(ic, "Invalid argument count to method %s: %d, wanted %zd", cmd, (int) json_array_get_count(params), strlen(methods[i].args)); 724 return jsonrpc_error(E2BIG, "Invalid number of arguments");722 return jsonrpc_error(E2BIG, "Invalid integer of arguments"); 725 723 } 726 724 int j; … … 732 730 ok = type == JSONString || type == JSONNull; 733 731 break; 734 case ' n':735 ok = type == JSON Number;732 case 'i': 733 ok = type == JSONInteger; 736 734 break; 737 735 case 'o': … … 758 756 759 757 #define RPC_ADD_FUNC(func) \ 758 ret->func = rpc_ ## func 759 #define RPC_ADD_OPT_FUNC(func) \ 760 760 if (g_hash_table_contains(methods, #func)) \ 761 ret->func = rpc_ ## func761 RPC_ADD_FUNC(func) 762 762 763 763 static JSON_Value *rpc_init_isup() { … … 767 767 JSON_Value *d = json_value_init_object(); 768 768 json_object_set_string(json_object(d), "version_str", BITLBEE_VERSION); 769 json_object_set_ number(json_object(d), "version", BITLBEE_VERSION_CODE);769 json_object_set_integer(json_object(d), "version", BITLBEE_VERSION_CODE); 770 770 771 771 JSON_Value *ml = json_value_init_array(); … … 854 854 ret->data = proto_data; 855 855 856 proto_data->account_flags = json_object_get_ number(isup, "account_flags");856 proto_data->account_flags = json_object_get_integer(isup, "account_flags"); 857 857 858 858 /* Keep a full copy of the settings list, we can only use it when we … … 878 878 ret->init = rpc_init; 879 879 RPC_ADD_FUNC(login); 880 RPC_ADD_ FUNC(keepalive);880 RPC_ADD_OPT_FUNC(keepalive); 881 881 RPC_ADD_FUNC(logout); 882 882 RPC_ADD_FUNC(buddy_msg); 883 RPC_ADD_ FUNC(set_away);884 RPC_ADD_ FUNC(send_typing);885 RPC_ADD_FUNC(add_buddy); 883 RPC_ADD_OPT_FUNC(set_away); 884 RPC_ADD_OPT_FUNC(send_typing); 885 RPC_ADD_FUNC(add_buddy); /* Consider making these two optional? */ 886 886 RPC_ADD_FUNC(remove_buddy); 887 RPC_ADD_ FUNC(add_permit);888 RPC_ADD_ FUNC(add_deny);889 RPC_ADD_ FUNC(rem_permit);890 RPC_ADD_ FUNC(rem_deny);891 RPC_ADD_ FUNC(get_info);892 RPC_ADD_ FUNC(chat_invite);893 RPC_ADD_ FUNC(chat_kick);894 RPC_ADD_ FUNC(chat_leave);895 RPC_ADD_ FUNC(chat_msg);896 RPC_ADD_ FUNC(chat_with);897 RPC_ADD_ FUNC(chat_join);898 RPC_ADD_ FUNC(chat_topic);887 RPC_ADD_OPT_FUNC(add_permit); 888 RPC_ADD_OPT_FUNC(add_deny); 889 RPC_ADD_OPT_FUNC(rem_permit); 890 RPC_ADD_OPT_FUNC(rem_deny); 891 RPC_ADD_OPT_FUNC(get_info); 892 RPC_ADD_OPT_FUNC(chat_invite); 893 RPC_ADD_OPT_FUNC(chat_kick); 894 RPC_ADD_OPT_FUNC(chat_leave); 895 RPC_ADD_OPT_FUNC(chat_msg); 896 RPC_ADD_OPT_FUNC(chat_with); 897 RPC_ADD_OPT_FUNC(chat_join); 898 RPC_ADD_OPT_FUNC(chat_topic); 899 899 if (proto_data->away_states) 900 900 ret->away_states = rpc_away_states;
Note: See TracChangeset
for help on using the changeset viewer.