Changeset 66aefeb


Ignore:
Timestamp:
2015-02-27T00:54:47Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
9ae7332
Parents:
6cdecc7
Message:

init works. Still very rough otherwise, and next to no callbacks into
BitlBee implemented yet.

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r6cdecc7 r66aefeb  
    132132        extern void twitter_initmodule();
    133133        extern void purple_initmodule();
     134        extern void rpc_initmodule();
    134135
    135136#ifdef WITH_MSN
     
    155156#ifdef WITH_PURPLE
    156157        purple_initmodule();
     158#endif
     159
     160#ifdef WITH_RPC
     161        rpc_initmodule();
    157162#endif
    158163
  • protocols/rpc/rpc.c

    r6cdecc7 r66aefeb  
     1#include <sys/socket.h>
     2#include <sys/un.h>
     3
    14#include "bitlbee.h"
    25#include "bee.h"
     
    1518        char *buf;
    1619        int buflen;
     20        GHashTable *groupchats;
    1721};
    1822
    1923struct rpc_groupchat {
    20         struct groupchat *bee_gc;
    21         char *rpc_handle;
     24        int id;
     25        struct groupchat *gc;
    2226};
    2327
     
    4145
    4246/** Sends an RPC object. Takes ownership (i.e. frees it when done). */
    43 static void rpc_send(struct im_connection *ic, JSON_Value *rpc) {
     47static gboolean rpc_send(struct im_connection *ic, JSON_Value *rpc) {
     48        struct rpc_connection *rd = ic->proto_data;
    4449        char *buf = json_serialize_to_string(rpc);
    45 
     50        int len = strlen(buf);
     51        int st;
     52
     53        buf = g_realloc(buf, len + 3);
     54        strcpy(buf + len, "\r\n");
     55        len += 2;
     56
     57        st = write(rd->fd, buf, len);
    4658        g_free(buf);
    4759        json_value_free(rpc);
     60
     61        if (st != len) {
     62                imcb_log(ic, "Write error");
     63                imc_logout(ic, TRUE);
     64                return FALSE;
     65        }
     66
     67        return TRUE;
    4868}
    4969
     
    5373        json_object_set_string(o, "user", acc->user);
    5474        json_object_set_string(o, "pass", acc->user);
    55         json_object_set_string(o, "server", acc->server);
     75        if (acc->server)
     76                json_object_set_string(o, "server", acc->server);
    5677        return v;
    5778}
     
    7596        }
    7697        ic->inpa = b_input_add(rd->fd, B_EV_IO_WRITE, rpc_login_cb, ic);
     98        rd->groupchats = g_hash_table_new(g_int_hash, g_int_equal);
    7799}
    78100
     
    97119        RPC_OUT_INIT("logout");
    98120        rpc_send(ic, rpc);
     121
     122        struct rpc_connection *rd = ic->proto_data;
     123        b_event_remove(ic->inpa);
     124        closesocket(rd->fd);
     125        g_free(rd->buf);
     126        g_hash_table_destroy(rd->groupchats);
     127        g_free(rd);
    99128}
    100129
     
    171200static void rpc_chat_invite(struct groupchat *gc, char *who, char *message) {
    172201        RPC_OUT_INIT("chat_invite");
     202        struct rpc_groupchat *rc = gc->data;
     203        json_array_append_number(params, rc->id);
    173204        json_array_append_string(params, who);
    174205        json_array_append_string(params, message);
     
    178209static void rpc_chat_kick(struct groupchat *gc, char *who, const char *message) {
    179210        RPC_OUT_INIT("chat_kick");
     211        struct rpc_groupchat *rc = gc->data;
     212        json_array_append_number(params, rc->id);
    180213        json_array_append_string(params, who);
    181214        json_array_append_string(params, message);
     
    185218static void rpc_chat_leave(struct groupchat *gc) {
    186219        RPC_OUT_INIT("chat_leave");
     220        struct rpc_groupchat *rc = gc->data;
     221        json_array_append_number(params, rc->id);
    187222        rpc_send(gc->ic, rpc);
    188223}
     
    190225static void rpc_chat_msg(struct groupchat *gc, char *msg, int flags) {
    191226        RPC_OUT_INIT("chat_msg");       
    192         struct rpc_groupchat *data = gc->data;
    193         json_array_append_string(params, data->rpc_handle);
     227        struct rpc_groupchat *rc = gc->data;
     228        json_array_append_number(params, rc->id);
    194229        json_array_append_string(params, msg);
    195230        json_array_append_number(params, flags);
     
    197232}
    198233
     234static struct groupchat *rpc_groupchat_new(struct im_connection *ic, const char *handle) {
     235        struct groupchat *gc = imcb_chat_new(ic, handle);
     236        struct rpc_groupchat *rc = gc->data = g_new0(struct rpc_groupchat, 1);
     237        rc->id = next_rpc_id;
     238        rc->gc = gc;
     239        return gc;
     240}
     241
    199242static struct groupchat *rpc_chat_with(struct im_connection *ic, char *who) {
    200243        RPC_OUT_INIT("chat_with");
     244        struct groupchat *gc = rpc_groupchat_new(ic, who);
     245        struct rpc_groupchat *rc = gc->data;
     246        json_array_append_number(params, rc->id);
    201247        json_array_append_string(params, who);
    202248        rpc_send(ic, rpc);
     
    208254                                       const char *password, set_t **sets) {
    209255        RPC_OUT_INIT("chat_join");
     256        struct groupchat *gc = rpc_groupchat_new(ic, room);
     257        struct rpc_groupchat *rc = gc->data;
     258        json_array_append_number(params, rc->id);
    210259        json_array_append_string(params, room);
    211260        json_array_append_string(params, nick);
     
    219268static void rpc_chat_topic(struct groupchat *gc, char *topic) {
    220269        RPC_OUT_INIT("chat_topic");
     270        struct rpc_groupchat *rc = gc->data;
     271        json_array_append_number(params, rc->id);
    221272        json_array_append_string(params, topic);
    222273        rpc_send(gc->ic, rpc);
     
    315366        json_array_append_value(params, d);
    316367        char *s = json_serialize_to_string(rpc);
    317 
    318         if ((st = write(fd, s, strlen(s))) != strlen(s)) {
     368        int len = strlen(s);
     369        s = g_realloc(s, len + 3);
     370        strcpy(s + len, "\r\n");
     371        len += 2;
     372
     373        if ((st = write(fd, s, len)) != len) {
    319374                // LOG ERROR
    320375                return;
     
    337392                if (st == 0) {
    338393                        // LOG ERROR
     394                        closesocket(fd);
    339395                        return;
    340396                }
     
    348404                                continue;
    349405                        // LOG ERROR
     406                        closesocket(fd);
    350407                        return;
    351408                }
     
    354411        }
    355412        while (!(parsed = json_parse_string(resp)));
     413        closesocket(fd);
    356414
    357415        JSON_Object *isup = json_object_get_object(json_object(parsed), "result");
     
    410468}
    411469
     470#define PDIR "/tmp/rpcplugins"
     471
     472/* YA RLY :-/ */
     473#ifndef UNIX_PATH_MAX
     474struct sockaddr_un sizecheck;
     475#define UNIX_PATH_MAX sizeof(sizecheck.sun_path)
     476#endif
     477
    412478void rpc_initmodule() {
    413 }
    414 
     479        DIR *pdir = opendir(PDIR);
     480        struct dirent *de;
     481
     482        if (!pdir)
     483                return;
     484
     485        while ((de = readdir(pdir))) {
     486                char *fn = g_build_filename(PDIR, de->d_name, NULL);
     487                struct sockaddr_un su;
     488
     489                strncpy(su.sun_path, fn, UNIX_PATH_MAX);
     490                su.sun_path[UNIX_PATH_MAX-1] = '\0';
     491                su.sun_family = AF_UNIX;
     492                rpc_initmodule_sock((struct sockaddr*) &su, sizeof(su));
     493                g_free(fn);
     494        }
     495}
     496
Note: See TracChangeset for help on using the changeset viewer.