X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=clients%2Fgaim%2Fgaim-dolcon.c;h=f220ca0f0cfd145877be25e7d93cd1f765b95cf7;hb=3be6a9b7c6aac4fe975cbab1d9b946536dd5ddd2;hp=93a92e407e58ccad46745a6eadc6b6fb154ab950;hpb=7f6ee5dff1388e00f3b787a1a32f130290467b9a;p=doldaconnect.git diff --git a/clients/gaim/gaim-dolcon.c b/clients/gaim/gaim-dolcon.c index 93a92e4..f220ca0 100644 --- a/clients/gaim/gaim-dolcon.c +++ b/clients/gaim/gaim-dolcon.c @@ -40,6 +40,7 @@ struct conndata { }; static struct conndata *inuse = NULL; +static GaimPlugin *me; static void dcfdcb(struct conndata *data, int fd, GaimInputCondition condition); @@ -89,6 +90,39 @@ static int loginconv(int type, wchar_t *text, char **resp, struct conndata *data } } +static gboolean gi_chatjoincb(GaimConversation *conv, const char *user, GaimConvChatBuddyFlags flags, void *uudata) +{ + GaimConnection *c; + + if((c = gaim_conversation_get_gc(conv)) == NULL) + return(FALSE); + if(c->prpl == me) + return(TRUE); + return(FALSE); +} + +static gboolean gi_chatleavecb(GaimConversation *conv, const char *user, const char *reason, void *uudata) +{ + GaimConnection *c; + + if((c = gaim_conversation_get_gc(conv)) == NULL) + return(FALSE); + if(c->prpl == me) + return(TRUE); + return(FALSE); +} + +static void regsigs(void) +{ + static GaimPlugin *regged = NULL; + + if(regged != me) { + gaim_signal_connect(gaim_conversations_get_handle(), "chat-buddy-joining", me, GAIM_CALLBACK(gi_chatjoincb), NULL); + gaim_signal_connect(gaim_conversations_get_handle(), "chat-buddy-leaving", me, GAIM_CALLBACK(gi_chatleavecb), NULL); + regged = me; + } +} + static void newpeercb(struct dc_fnetpeer *peer) { struct conndata *data; @@ -96,9 +130,8 @@ static void newpeercb(struct dc_fnetpeer *peer) char *buf; data = peer->fn->udata; - if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) - { - buf = sprintf2("%i:%s", peer->fn->id, icswcstombs(peer->nick, "UTF-8", NULL)); + if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) { + buf = sprintf2("%s", icswcstombs(peer->nick, "UTF-8", NULL)); gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv), buf, NULL, GAIM_CBFLAGS_NONE, TRUE); free(buf); } @@ -111,9 +144,8 @@ static void delpeercb(struct dc_fnetpeer *peer) char *buf; data = peer->fn->udata; - if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) - { - buf = sprintf2("%i:%s", peer->fn->id, icswcstombs(peer->nick, "UTF-8", NULL)); + if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) { + buf = sprintf2("%s", icswcstombs(peer->nick, "UTF-8", NULL)); gaim_conv_chat_remove_user(GAIM_CONV_CHAT(conv), buf, NULL); free(buf); } @@ -162,22 +194,26 @@ static void dcfdcb(struct conndata *data, int fd, GaimInputCondition condition) GaimConversation *conv; char *peer, *msg; - if(((condition & GAIM_INPUT_READ) && dc_handleread()) || ((condition & GAIM_INPUT_WRITE) && dc_handlewrite())) - { + if(((condition & GAIM_INPUT_READ) && dc_handleread()) || ((condition & GAIM_INPUT_WRITE) && dc_handlewrite())) { disconnected(data); gaim_connection_error(data->gc, "Server has disconnected"); return; } while((resp = dc_getresp()) != NULL) { if(!wcscmp(resp->cmdname, L".connect")) { - if(resp->code == 200) { - gaim_connection_update_progress(data->gc, "Authenticating", 2, 3); - dc_loginasync(NULL, 1, (int (*)(int, wchar_t *, char **, void *))loginconv, (void (*)(int, wchar_t *, void *))logincb, data); - } else { + if(resp->code != 201) { dc_disconnect(); disconnected(data); gaim_connection_error(data->gc, "Server refused connection"); return; + } else if(dc_checkprotocol(resp, DC_LATEST)) { + dc_disconnect(); + disconnected(data); + gaim_connection_error(data->gc, "Server protocol revision mismatch"); + return; + } else { + gaim_connection_update_progress(data->gc, "Authenticating", 2, 3); + dc_loginasync(NULL, 1, (int (*)(int, wchar_t *, char **, void *))loginconv, (void (*)(int, wchar_t *, void *))logincb, data); } } else if(!wcscmp(resp->cmdname, L".notify")) { dc_uimisc_handlenotify(resp); @@ -193,18 +229,17 @@ static void dcfdcb(struct conndata *data, int fd, GaimInputCondition condition) if((conv = gaim_find_chat(data->gc, fn->id)) != NULL) { peer = icwcstombs(ires->argv[3].val.str, "UTF-8"); - /* XXX: No more gaim_escape_html?! */ - msg = sstrdup(icswcstombs(ires->argv[4].val.str, "UTF-8", NULL)); + msg = g_markup_escape_text(icswcstombs(ires->argv[4].val.str, "UTF-8", NULL), -1); serv_got_chat_in(data->gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), peer, 0, msg, time(NULL)); - free(msg); + g_free(msg); free(peer); } } else { peer = sprintf2("%i:%s", fn->id, icswcstombs(ires->argv[3].val.str, "UTF-8", NULL)); - msg = sstrdup(icswcstombs(ires->argv[4].val.str, "UTF-8", NULL)); + msg = g_markup_escape_text(icswcstombs(ires->argv[4].val.str, "UTF-8", NULL), -1); if(!gaim_account_get_bool(data->gc->account, "represspm", FALSE) || (gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, peer, data->gc->account) != NULL)) serv_got_im(data->gc, peer, msg, 0, time(NULL)); - free(msg); + g_free(msg); free(peer); } } @@ -249,7 +284,7 @@ static int gi_sendchat(GaimConnection *gc, int id, const char *what, GaimMessage /* XXX: Handle chat rooms */ if((wwhat = icmbstowcs((char *)what, "UTF-8")) == NULL) return(-errno); - dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", fn->id, L"1", L"", L"%%ls", wwhat, NULL); + dc_queuecmd(NULL, NULL, L"sendchat", L"%i", fn->id, L"1", L"", L"%ls", wwhat, NULL); free(wwhat); updatewrite(data); return(0); @@ -289,7 +324,7 @@ static int gi_sendim(GaimConnection *gc, const char *who, const char *what, Gaim free(wwho); return(-en); } - dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", fn->id, L"0", L"%%ls", peer->nick, L"%%ls", wwhat, NULL); + dc_queuecmd(NULL, NULL, L"sendchat", L"%i", fn->id, L"0", L"%ls", peer->nick, L"%ls", wwhat, NULL); free(wwho); free(wwhat); updatewrite(data); @@ -311,7 +346,7 @@ static char *gi_statustext(GaimBuddy *b) return(NULL); } -static void gi_tiptext(GaimBuddy *b, GString *buf, gboolean full) +static void gi_tiptext(GaimBuddy *b, GaimNotifyUserInfo *inf, gboolean full) { /* Nothing for now */ } @@ -366,7 +401,7 @@ static void gi_login(GaimAccount *act) return; } gaim_connection_update_progress(gc, "Connecting", 1, 3); - if((data->fd = dc_connect((char *)gaim_account_get_string(act, "server", "localhost"), -1)) < 0) + if((data->fd = dc_connect((char *)gaim_account_get_string(act, "server", "localhost"))) < 0) { gaim_connection_error(gc, "Could not connect to server"); return; @@ -439,6 +474,7 @@ static void gi_joinchat(GaimConnection *gc, GHashTable *chatdata) char *buf; GList *ul, *fl, *c; + regsigs(); data = gc->proto_data; if((fn = dc_findfnetnode(GPOINTER_TO_INT(g_hash_table_lookup(chatdata, "id")))) == NULL) return; @@ -447,7 +483,7 @@ static void gi_joinchat(GaimConnection *gc, GHashTable *chatdata) conv = serv_got_joined_chat(data->gc, fn->id, icswcstombs(fn->name, "UTF-8", NULL)); ul = fl = NULL; for(peer = fn->peers; peer != NULL; peer = peer->next) { - buf = sprintf2("%i:%s", fn->id, icswcstombs(peer->nick, "UTF-8", NULL)); + buf = icwcstombs(peer->nick, "UTF-8"); ul = g_list_append(ul, buf); fl = g_list_append(fl, GINT_TO_POINTER(0)); } @@ -458,6 +494,11 @@ static void gi_joinchat(GaimConnection *gc, GHashTable *chatdata) g_list_free(fl); } +static char *gi_cbname(GaimConnection *gc, int id, const char *who) +{ + return(g_strdup_printf("%i:%s", id, who)); +} + static GaimPluginProtocolInfo protinfo = { .options = OPT_PROTO_PASSWORD_OPTIONAL, .icon_spec = NO_BUDDY_ICONS, @@ -472,6 +513,7 @@ static GaimPluginProtocolInfo protinfo = { .join_chat = gi_joinchat, .chat_send = gi_sendchat, .send_im = gi_sendim, + .get_cb_real_name = gi_cbname, }; static GaimPluginInfo info = { @@ -495,12 +537,11 @@ static void init(GaimPlugin *pl) GaimAccountOption *opt; dc_init(); - opt = gaim_account_option_string_new("Server", "server", "localhost"); - protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); - opt = gaim_account_option_int_new("Port", "port", -1); + opt = gaim_account_option_string_new("Server", "server", ""); protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); opt = gaim_account_option_bool_new("Do not pop up private messages automatically", "represspm", FALSE); protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); + me = pl; } GAIM_INIT_PLUGIN(dolcon, init, info);