Changeset bc73e2ba
- Timestamp:
- 2015-04-04T00:33:30Z (10 years ago)
- Children:
- 16652e9
- Parents:
- 578790e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/rpc/rpc.c
r578790e rbc73e2ba 27 27 28 28 static JSON_Value *jsonrpc_error(int code, const char *msg) { 29 JSON_Value *error = json_value_init_object();30 json_object_set_number(json_object(error), "code", code);31 json_object_set_string(json_object(error), "message", msg);32 29 JSON_Value *ret = json_value_init_object(); 33 json_object_set_value(json_object(ret), "error", error); 30 json_object_set_null(json_object(ret), "result"); 31 if (TRUE) { 32 /* Format from http://jsonrpc.org/historical/json-rpc-1-1-alt.html. 33 * Not sure whether to use it. */ 34 JSON_Value *error = json_value_init_object(); 35 json_object_set_number(json_object(error), "code", code); 36 json_object_set_string(json_object(error), "message", msg); 37 json_object_set_value(json_object(ret), "error", error); 38 } else { 39 json_object_set_string(json_object(ret), "error", msg); 40 } 34 41 35 42 return ret; 43 } 44 45 static void json_array_append_string_or_null(JSON_Array *params, const char *string) { 46 if (string) 47 json_array_append_string(params, string); 48 else 49 json_array_append_null(params); 36 50 } 37 51 … … 150 164 static void rpc_set_away(struct im_connection *ic, char *state, char *message) { 151 165 RPC_OUT_INIT("set_away"); 152 json_array_append_string (params, state);153 json_array_append_string (params, message);166 json_array_append_string_or_null(params, state); 167 json_array_append_string_or_null(params, message); 154 168 rpc_send(ic, rpc); 155 169 } … … 165 179 RPC_OUT_INIT("add_buddy"); 166 180 json_array_append_string(params, name); 167 json_array_append_string (params, group);181 json_array_append_string_or_null(params, group); 168 182 rpc_send(ic, rpc); 169 183 } … … 172 186 RPC_OUT_INIT("remove_buddy"); 173 187 json_array_append_string(params, name); 174 json_array_append_string (params, group);188 json_array_append_string_or_null(params, group); 175 189 rpc_send(ic, rpc); 176 190 } … … 211 225 json_array_append_number(params, rc->id); 212 226 json_array_append_string(params, who); 213 json_array_append_string (params, message);227 json_array_append_string_or_null(params, message); 214 228 rpc_send(gc->ic, rpc); 215 229 } … … 220 234 json_array_append_number(params, rc->id); 221 235 json_array_append_string(params, who); 222 json_array_append_string (params, message);236 json_array_append_string_or_null(params, message); 223 237 rpc_send(gc->ic, rpc); 224 238 } … … 282 296 json_array_append_number(params, rc->id); 283 297 json_array_append_string(params, room); 284 json_array_append_string (params, nick);285 json_array_append_string (params, password);298 json_array_append_string_or_null(params, nick); 299 json_array_append_string_or_null(params, password); 286 300 //json_array_append_value(params, rpc_ser_sets(sets)); 287 301 rpc_send(ic, rpc); … … 303 317 const char *cmd = json_object_get_string(rpc, "method"); 304 318 JSON_Value *id = json_object_get_value(rpc, "id"); 319 JSON_Value *error = json_object_get_value(rpc, "error"); 305 320 JSON_Array *params = json_object_get_array(rpc, "params"); 306 321 … … 322 337 json_object_set_value(json_object(resp), "id", json_value_deep_copy(id)); 323 338 return rpc_send(ic, resp); 339 } else if (error && json_type(error) != JSONNull) { 340 char *error_str = json_serialize_to_string(error); 341 /* Maybe sanitise/truncate? Though really that should be done at 342 * a different layer. */ 343 imcb_error(ic, "RPC Error: %s", error_str); 344 g_free(error_str); 324 345 } 325 346 … … 534 555 switch (methods[i].args[j]) { 535 556 case 's': 536 ok = type == JSONString ;557 ok = type == JSONString || type == JSONNull; 537 558 break; 538 559 case 'n': … … 663 684 664 685 // TODO: Property for a few standard nickcmp implementations. 686 ret->handle_cmp = g_ascii_strcasecmp; 665 687 666 688 struct rpc_plugin *proto_data = g_new0(struct rpc_plugin, 1);
Note: See TracChangeset
for help on using the changeset viewer.