Changeset f3af614


Ignore:
Timestamp:
2015-04-11T23:27:57Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
c5a7b8d
Parents:
16652e9
Message:

Whole bunch of changes: Added some more settings-related stuff and some calls
from plugin into BitlBee (where we *can* actually do return values). Also,
adding what I have so far for the Python counterpart, I suppose it makes sense
to have it in the source tree as well - though the naming/layout/etc is
completely made up.

Also, writing the commit message as if Git were a normal version control
system because screw arbitrary poorly documented "rules" on how commit
messages should be written in the world's most "special" VCS.

Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/rpc/rpc.c

    r16652e9 rf3af614  
    128128}
    129129
     130static JSON_Value *rpc_ser_bee_user(bee_user_t *bu) {
     131        JSON_Value *v = json_value_init_object();
     132        JSON_Object *o = json_object(v);
     133        json_object_set_string_or_null(o, "handle", bu->handle);
     134        json_object_set_string_or_null(o, "fullname", bu->fullname);
     135        json_object_set_string_or_null(o, "nick", bu->nick);
     136        json_object_set_string_or_null(o, "group", bu->group ? bu->group->name : NULL);
     137        json_object_set_number(o, "flags", bu->flags);
     138        json_object_set_string_or_null(o, "status", bu->status);
     139        json_object_set_string_or_null(o, "status_msg", bu->status_msg);
     140        json_object_set_number(o, "login_time", bu->login_time);
     141        json_object_set_number(o, "idle_time", bu->idle_time);
     142        return v;
     143}
     144
    130145static void rpc_init(account_t *acc) {
    131146        struct rpc_plugin *pd = acc->prpl->data;
     
    134149                JSON_Object *o = json_object(value);
    135150                set_t *set = set_add(&acc->set, name, json_object_get_string(o, "default"), NULL, acc);
     151                /* JSON numbers are floats. The following line "might" be a
     152                 * terrible idea. As was JSON, but hey. */
     153                set->flags |= (int) json_object_get_number(o, "flags");
     154                const char *eval = json_object_get_string(o, "type");
     155                if (eval == NULL) {
     156                } else if (strcmp(eval, "int") == 0) {
     157                        set->eval = set_eval_int;
     158                } else if (strcmp(eval, "bool") == 0) {
     159                        set->eval = set_eval_bool;
     160                } else {
     161                        /* Default is string which means no evaluator. */
     162                }
     163                /* eval_list turns out to be a memory leak so don't implement it
     164                 * for now.
     165                 * Allowing a plugin to define its own evaluator is not really
     166                 * possible without having BitlBee block on it responding which
     167                 * I don't want to do.
     168                 * Should a module want to override a user's setting, it can
     169                 * use set_setstr(). (Though ATM setting changes are not yet
     170                 * passed to the module immediately. TODO. */
    136171        }
    137172}
     
    542577}
    543578
     579static JSON_Value *rpc_set_getstr(struct im_connection *ic, void *func_, JSON_Array *params) {
     580        char *rets = set_getstr(&ic->acc->set, json_array_get_string(params, 0));
     581        JSON_Value *ret = json_value_init_object();
     582        if (rets)
     583                json_object_set_string(json_object(ret), "result", rets);
     584        else
     585                json_object_set_null(json_object(ret), "result");
     586        return ret;
     587}
     588
     589static JSON_Value *rpc_set_setstr(struct im_connection *ic, void *func_, JSON_Array *params) {
     590        /* Sadly use of const is very poor in BitlBee. :-( */
     591        char *newval = g_strdup(json_array_get_string(params, 1));
     592        set_setstr(&ic->acc->set, json_array_get_string(params, 0), newval);
     593        g_free(newval);
     594        return rpc_set_getstr(ic, func_, params);
     595}
     596
     597static JSON_Value *rpc_set_reset(struct im_connection *ic, void *func_, JSON_Array *params) {
     598        set_reset(&ic->acc->set, json_array_get_string(params, 0));
     599        return rpc_set_getstr(ic, func_, params);
     600}
     601
     602static JSON_Value *rpc_bee_user_by_handle(struct im_connection *ic, void *func_, JSON_Array *params) {
     603        bee_user_t *bu = bee_user_by_handle(ic->bee, ic, json_array_get_string(params, 0));
     604        JSON_Value *ret = json_value_init_object();
     605        if (bu)
     606                json_object_set_value(json_object(ret), "result", rpc_ser_bee_user(bu));
     607        else
     608                json_object_set_value(json_object(ret), "error", jsonrpc_error(ENOENT, "Contact not found"));
     609        return ret;
     610}
     611
    544612struct rpc_in_method {
    545613        char *name;
     
    551619static const struct rpc_in_method methods[] = {
    552620        /* All these RPCs are equivalent of BitlBee C functions but with the
    553          * struct im_connection* removed. */
     621         * struct im_connection* removed as this is in the object context. */
    554622        { "imcb_log", imcb_log, rpc_imcb_log, "s" },
    555623        { "imcb_error", imcb_error, rpc_imcb_log, "s" },
     
    576644        { "imcb_chat_remove_buddy", imcb_chat_remove_buddy, rpc_imcb_chat_remove_buddy, "nss" },
    577645        { "imcb_chat_invite", imcb_chat_invite, rpc_imcb_chat_invite, "nsss" },
     646
     647        /* These are not imcb* functions but should still be exported. */
     648        /* Setting functions. Starting with just providing access to account
     649         * settings. See later whether access to chat/chan settings is necessary.
     650         * All of these will return the (new) value of given setting. */
     651        { "set_getstr", NULL, rpc_set_getstr, "s" },
     652        { "set_setstr", NULL, rpc_set_setstr, "ss" },
     653        { "set_reset", NULL, rpc_set_reset, "s" },
     654       
     655        { "bee_user_by_handle", NULL, rpc_bee_user_by_handle, "s" },
    578656
    579657        { NULL },
     
    710788        struct prpl *ret = g_new0(struct prpl, 1);
    711789       
    712         JSON_Array *methods_a = json_object_get_array(isup, "methods");
     790        JSON_Array *methods_a = json_object_get_array(isup, "method_list");
    713791        GHashTable *methods = g_hash_table_new(g_str_hash, g_str_equal);
    714792        for (i = 0; i < json_array_get_count(methods_a); i++)
Note: See TracChangeset for help on using the changeset viewer.