- Timestamp:
- 2015-04-12T13:46:45Z (10 years ago)
- Children:
- f15553d
- Parents:
- f3af614
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/rpc/rpc.c
rf3af614 rc5a7b8d 14 14 15 15 struct rpc_plugin { 16 /* Socket address of the RPC server. */ 16 17 struct sockaddr *addr; 17 18 socklen_t addrlen; 19 /* Full copy of the "settings" section of the init message. This info 20 * can only be applied later on, when an account is created (but well 21 * before logging in). */ 18 22 JSON_Value *settings; 23 /* Supported away states returned by the away_states() function. Since 24 * RPC servers can't do return values, just get this info at init time. 25 * This means the list of possible away states is static from init time 26 * which hopefully won't be a problem. If NULL, the away_states function 27 * will not be set on this protocol. */ 28 GList *away_states; 29 /* Account flags. See account.h. Plugin lib should provide constants. */ 30 int account_flags; 19 31 }; 20 32 … … 170 182 * passed to the module immediately. TODO. */ 171 183 } 184 185 acc->flags |= pd->account_flags; 172 186 } 173 187 … … 185 199 if (connect(rd->fd, pd->addr, pd->addrlen) == -1) { 186 200 closesocket(rd->fd); 201 imcb_error(ic, "RPC server unreachable"); 202 imc_logout(ic, TRUE); 187 203 return; 188 204 } … … 385 401 json_array_append_string(params, topic); 386 402 rpc_send(gc->ic, rpc); 403 } 404 405 static GList *rpc_away_states(struct im_connection *ic) { 406 struct rpc_plugin *pd = ic->acc->prpl->data; 407 return pd->away_states; 387 408 } 388 409 … … 787 808 788 809 struct prpl *ret = g_new0(struct prpl, 1); 789 810 struct rpc_plugin *proto_data = g_new0(struct rpc_plugin, 1); 811 proto_data->addr = g_memdup(address, addrlen); 812 proto_data->addrlen = addrlen; 813 ret->name = g_strdup(json_object_get_string(isup, "name")); 814 ret->data = proto_data; 815 816 proto_data->account_flags = json_object_get_number(isup, "account_flags"); 817 818 /* Keep a full copy of the settings list, we can only use it when we 819 * have an account to work on. */ 820 JSON_Value *settings = json_object_get_value(isup, "settings"); 821 if (json_type(settings) == JSONObject) 822 proto_data->settings = json_value_deep_copy(settings); 823 824 JSON_Array *aways_a = json_object_get_array(isup, "away_state_list"); 825 for (i = 0; i < json_array_get_count(aways_a); ++i) { 826 JSON_Value *state = json_array_get_value(aways_a, i); 827 if (json_type(state) == JSONString) 828 proto_data->away_states = 829 g_list_append(proto_data->away_states, 830 g_strdup(json_string(state))); 831 } 832 790 833 JSON_Array *methods_a = json_object_get_array(isup, "method_list"); 791 834 GHashTable *methods = g_hash_table_new(g_str_hash, g_str_equal); … … 814 857 RPC_ADD_FUNC(chat_join); 815 858 RPC_ADD_FUNC(chat_topic); 859 if (proto_data->away_states) 860 ret->away_states = rpc_away_states; 816 861 817 862 g_hash_table_destroy(methods); … … 820 865 ret->handle_cmp = g_ascii_strcasecmp; 821 866 822 struct rpc_plugin *proto_data = g_new0(struct rpc_plugin, 1);823 proto_data->addr = g_memdup(address, addrlen);824 proto_data->addrlen = addrlen;825 ret->name = g_strdup(json_object_get_string(isup, "name"));826 ret->data = proto_data;827 828 /* Keep a full copy of the settings list, we can only use it when we829 * have an account to work on. */830 JSON_Value *settings = json_object_get_value(isup, "settings");831 if (json_type(settings) == JSONObject)832 proto_data->settings = json_value_deep_copy(settings);833 834 867 register_protocol(ret); 835 868 } … … 859 892 rpc_initmodule_sock((struct sockaddr*) &su, sizeof(su)); 860 893 g_free(fn); 861 } 862 } 863 894 /* Idea: Also support textfiles containing a host:port tuple to 895 * connect to. Not that remote RPC'ing would be a great idea, 896 * but maybe some jsonrpc libs don't support Unix domain sockets. */ 897 } 898 } 899
Note: See TracChangeset
for help on using the changeset viewer.