Changeset c5a7b8d for protocols/rpc


Ignore:
Timestamp:
2015-04-12T13:46:45Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
f15553d
Parents:
f3af614
Message:

Away states/messages, account flags, error reporting, some comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/rpc/rpc.c

    rf3af614 rc5a7b8d  
    1414
    1515struct rpc_plugin {
     16        /* Socket address of the RPC server. */
    1617        struct sockaddr *addr;
    1718        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). */
    1822        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;
    1931};
    2032
     
    170182                 * passed to the module immediately. TODO. */
    171183        }
     184
     185        acc->flags |= pd->account_flags;
    172186}
    173187
     
    185199        if (connect(rd->fd, pd->addr, pd->addrlen) == -1) {
    186200                closesocket(rd->fd);
     201                imcb_error(ic, "RPC server unreachable");
     202                imc_logout(ic, TRUE);
    187203                return;
    188204        }
     
    385401        json_array_append_string(params, topic);
    386402        rpc_send(gc->ic, rpc);
     403}
     404
     405static GList *rpc_away_states(struct im_connection *ic) {
     406        struct rpc_plugin *pd = ic->acc->prpl->data;
     407        return pd->away_states;
    387408}
    388409
     
    787808
    788809        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
    790833        JSON_Array *methods_a = json_object_get_array(isup, "method_list");
    791834        GHashTable *methods = g_hash_table_new(g_str_hash, g_str_equal);
     
    814857        RPC_ADD_FUNC(chat_join);
    815858        RPC_ADD_FUNC(chat_topic);
     859        if (proto_data->away_states)
     860                ret->away_states = rpc_away_states;
    816861       
    817862        g_hash_table_destroy(methods);
     
    820865        ret->handle_cmp = g_ascii_strcasecmp;
    821866       
    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 we
    829          * 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 
    834867        register_protocol(ret);
    835868}
     
    859892                rpc_initmodule_sock((struct sockaddr*) &su, sizeof(su));
    860893                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.