- Timestamp:
- 2015-02-27T00:54:47Z (10 years ago)
- Children:
- 9ae7332
- Parents:
- 6cdecc7
- Location:
- protocols
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r6cdecc7 r66aefeb 132 132 extern void twitter_initmodule(); 133 133 extern void purple_initmodule(); 134 extern void rpc_initmodule(); 134 135 135 136 #ifdef WITH_MSN … … 155 156 #ifdef WITH_PURPLE 156 157 purple_initmodule(); 158 #endif 159 160 #ifdef WITH_RPC 161 rpc_initmodule(); 157 162 #endif 158 163 -
protocols/rpc/rpc.c
r6cdecc7 r66aefeb 1 #include <sys/socket.h> 2 #include <sys/un.h> 3 1 4 #include "bitlbee.h" 2 5 #include "bee.h" … … 15 18 char *buf; 16 19 int buflen; 20 GHashTable *groupchats; 17 21 }; 18 22 19 23 struct rpc_groupchat { 20 struct groupchat *bee_gc;21 char *rpc_handle;24 int id; 25 struct groupchat *gc; 22 26 }; 23 27 … … 41 45 42 46 /** Sends an RPC object. Takes ownership (i.e. frees it when done). */ 43 static void rpc_send(struct im_connection *ic, JSON_Value *rpc) { 47 static gboolean rpc_send(struct im_connection *ic, JSON_Value *rpc) { 48 struct rpc_connection *rd = ic->proto_data; 44 49 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); 46 58 g_free(buf); 47 59 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; 48 68 } 49 69 … … 53 73 json_object_set_string(o, "user", acc->user); 54 74 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); 56 77 return v; 57 78 } … … 75 96 } 76 97 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); 77 99 } 78 100 … … 97 119 RPC_OUT_INIT("logout"); 98 120 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); 99 128 } 100 129 … … 171 200 static void rpc_chat_invite(struct groupchat *gc, char *who, char *message) { 172 201 RPC_OUT_INIT("chat_invite"); 202 struct rpc_groupchat *rc = gc->data; 203 json_array_append_number(params, rc->id); 173 204 json_array_append_string(params, who); 174 205 json_array_append_string(params, message); … … 178 209 static void rpc_chat_kick(struct groupchat *gc, char *who, const char *message) { 179 210 RPC_OUT_INIT("chat_kick"); 211 struct rpc_groupchat *rc = gc->data; 212 json_array_append_number(params, rc->id); 180 213 json_array_append_string(params, who); 181 214 json_array_append_string(params, message); … … 185 218 static void rpc_chat_leave(struct groupchat *gc) { 186 219 RPC_OUT_INIT("chat_leave"); 220 struct rpc_groupchat *rc = gc->data; 221 json_array_append_number(params, rc->id); 187 222 rpc_send(gc->ic, rpc); 188 223 } … … 190 225 static void rpc_chat_msg(struct groupchat *gc, char *msg, int flags) { 191 226 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); 194 229 json_array_append_string(params, msg); 195 230 json_array_append_number(params, flags); … … 197 232 } 198 233 234 static 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 199 242 static struct groupchat *rpc_chat_with(struct im_connection *ic, char *who) { 200 243 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); 201 247 json_array_append_string(params, who); 202 248 rpc_send(ic, rpc); … … 208 254 const char *password, set_t **sets) { 209 255 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); 210 259 json_array_append_string(params, room); 211 260 json_array_append_string(params, nick); … … 219 268 static void rpc_chat_topic(struct groupchat *gc, char *topic) { 220 269 RPC_OUT_INIT("chat_topic"); 270 struct rpc_groupchat *rc = gc->data; 271 json_array_append_number(params, rc->id); 221 272 json_array_append_string(params, topic); 222 273 rpc_send(gc->ic, rpc); … … 315 366 json_array_append_value(params, d); 316 367 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) { 319 374 // LOG ERROR 320 375 return; … … 337 392 if (st == 0) { 338 393 // LOG ERROR 394 closesocket(fd); 339 395 return; 340 396 } … … 348 404 continue; 349 405 // LOG ERROR 406 closesocket(fd); 350 407 return; 351 408 } … … 354 411 } 355 412 while (!(parsed = json_parse_string(resp))); 413 closesocket(fd); 356 414 357 415 JSON_Object *isup = json_object_get_object(json_object(parsed), "result"); … … 410 468 } 411 469 470 #define PDIR "/tmp/rpcplugins" 471 472 /* YA RLY :-/ */ 473 #ifndef UNIX_PATH_MAX 474 struct sockaddr_un sizecheck; 475 #define UNIX_PATH_MAX sizeof(sizecheck.sun_path) 476 #endif 477 412 478 void 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.