Changeset c5a7b8d


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.

Files:
2 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
  • python/implugin.py

    rf3af614 rc5a7b8d  
    3535
    3636class BitlBeeIMPlugin(BaseHandler):
     37        # Protocol name to be used in the BitlBee CLI, etc.
    3738        NAME = "rpc-test"
     39
     40        # See account.h (TODO: Add constants.)
     41        ACCOUNT_FLAGS = 3
     42       
     43        # Supported away states. If your protocol supports a specific set of
     44        # away states, put them in a list in this variable.
     45        AWAY_STATES = ["Away", "Busy"] #None
    3846       
    3947        # Filled in during initialisation:
     
    4351        # Full version string
    4452        bitlbee_version_str = None
     53        # Will become an RpcForwarder object to call into BitlBee
     54        bee = None
    4555       
    4656        @classmethod
     
    6272                        "name": self.NAME,
    6373                        "method_list": list(set(dir(self)) & set(SUPPORTED_FUNCTIONS)),
     74                        "account_flags": self.ACCOUNT_FLAGS,
     75                        "away_state_list": self.AWAY_STATES,
    6476                        "settings": {
    6577                                "oauth": {
     
    89101                print self.bee.set_setstr("test", handle)
    90102                print self.bee.set_reset("test")
     103       
     104        def set_away(self, state, message):
     105                print "You're a slacker: %s (%r)" % (state, message)
    91106
    92107def RunPlugin(plugin, debug=True):
Note: See TracChangeset for help on using the changeset viewer.