static int irc_chat_send(GaimConnection *gc, int id, const char *what, GaimMessageFlags flags) { struct irc_conn *irc = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return irc_parse_cmd(irc, convo->name, what + 1); } #endif tmp = gaim_unescape_html(what); args[0] = convo->name; args[1] = tmp; irc_cmd_privmsg(irc, "msg", NULL, args); serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, what, time(NULL)); g_free(tmp); return 0; }
int yahoo_c_send(GaimConnection *gc, int id, const char *what, GaimMessageFlags flags) { GaimConversation *c; int ret; struct yahoo_data *yd; yd = (struct yahoo_data *) gc->proto_data; if (!yd) return -1; c = gaim_find_chat(gc, id); if (!c) return -1; if (id != YAHOO_CHAT_ID) { ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); } else { ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), what, flags); if (!ret) serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), gaim_connection_get_display_name(gc), 0, what, time(NULL)); } return ret; }
void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) { char *who = NULL; char *room = NULL; GSList *l; struct yahoo_data *yd; yd = gc->proto_data; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 104) room = yahoo_string_decode(gc, pair->value, TRUE); if (pair->key == 109) who = pair->value; } if (who && room) { GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (c && !gaim_utf8_strcasecmp(gaim_conversation_get_name(c), room)) gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); } if (room) g_free(room); }
static int gaym_chat_send(GaimConnection * gc, int id, const char *what) { struct gaym_conn *gaym = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "gaym", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return gaym_parse_cmd(gaym, convo->name, what + 1); } #endif args[0] = convo->name; args[1] = what; gaym_cmd_privmsg(gaym, "msg", NULL, args); tmp = gaim_escape_html(what); serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); g_free(tmp); return 0; }
void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) { char *room = NULL, *who = NULL, *msg = NULL, *msg2; int msgtype = 1, utf8 = 1; /* default to utf8 */ GaimConversation *c = NULL; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 97: utf8 = strtol(pair->value, NULL, 10); break; case 104: room = yahoo_string_decode(gc, pair->value, TRUE); break; case 109: who = pair->value; break; case 117: msg = pair->value; break; case 124: msgtype = strtol(pair->value, NULL, 10); break; } } c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (!who || !c) { if (room) g_free(room); /* we still get messages after we part, funny that */ return; } if (!msg) { gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); return; } msg2 = yahoo_string_decode(gc, msg, utf8); msg = yahoo_codes_to_html(msg2); g_free(msg2); if (msgtype == 2 || msgtype == 3) { char *tmp; tmp = g_strdup_printf("/me %s", msg); g_free(msg); msg = tmp; } serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); g_free(msg); g_free(room); }
static void gaym_chat_leave(GaimConnection * gc, int id) { struct gaym_conn *gaym = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; if (!convo) return; args[0] = gaim_conversation_get_name(convo); args[1] = NULL; gaym_cmd_part(gaym, "part", gaim_conversation_get_name(convo), args); serv_got_chat_left(gc, id); }
static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) { struct irc_conn *irc = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); return; } args[0] = name; args[1] = gaim_conversation_get_name(convo); irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); }
void yahoo_c_invite(GaimConnection *gc, int id, const char *msg, const char *name) { GaimConversation *c; c = gaim_find_chat(gc, id); if (!c || !c->name) return; if (id != YAHOO_CHAT_ID) { yahoo_conf_invite(gc, c, gaim_connection_get_display_name(gc), name, gaim_conversation_get_name(c), msg); } else { yahoo_chat_invite(gc, gaim_connection_get_display_name(gc), name, gaim_conversation_get_name(c), msg); } }
static void irc_chat_set_topic(GaimConnection *gc, int id, const char *topic) { char *buf; const char *name = NULL; struct irc_conn *irc; irc = gc->proto_data; name = gaim_conversation_get_name(gaim_find_chat(gc, id)); if (name == NULL) return; buf = irc_format(irc, "vt:", "TOPIC", name, topic); irc_send(irc, buf); g_free(buf); }
static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout) { struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; GaimConversation *c; char *eroom; gboolean utf8 = 1; if (yd->wm) { g_return_if_fail(yd->ycht != NULL); ycht_chat_leave(yd->ycht, room, logout); return; } eroom = yahoo_string_encode(gc, room, &utf8); pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, "sss", 104, eroom, 109, dn, 108, "1"); yahoo_packet_hash_str(pkt, 112, "0"); /* what does this one mean? */ yahoo_packet_send_and_free(pkt, yd); yd->in_chat = 0; if (yd->chat_name) { g_free(yd->chat_name); yd->chat_name = NULL; } if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) serv_got_chat_left(gc, YAHOO_CHAT_ID); if (!logout) return; pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash_str(pkt, 1, dn); yahoo_packet_send_and_free(pkt, yd); yd->chat_online = 0; g_free(eroom); }
void yahoo_c_leave(GaimConnection *gc, int id) { struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GaimConversation *c; if (!yd) return; c = gaim_find_chat(gc, id); if (!c) return; if (id != YAHOO_CHAT_ID) { yahoo_conf_leave(yd, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); yd->confs = g_slist_remove(yd->confs, c); } else { yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); } serv_got_chat_left(gc, id); }
void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) { char *who = NULL; GSList *l; struct yahoo_data *yd; yd = gc->proto_data; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 109) who = pair->value; } if (who) { GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (c) gaim_chat_remove_user(GAIM_CHAT(c), who, NULL); } }
void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt) { GaimAccount *account = gaim_connection_get_account(gc); struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GaimConversation *c = NULL; GSList *l; GList *members = NULL; GList *roomies = NULL; char *room = NULL; char *topic = NULL; char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; if (pkt->status == -1) { /* We can't join */ struct yahoo_pair *pair = pkt->hash->data; gchar const *failed_to_join = _("Failed to join chat"); switch (atoi(pair->value)) { case 0xFFFFFFFA: /* -6 */ gaim_notify_error(gc, NULL, failed_to_join, _("Unknown room")); break; case 0xFFFFFFF1: /* -15 */ gaim_notify_error(gc, NULL, failed_to_join, _("Maybe the room is full")); break; case 0xFFFFFFDD: /* -35 */ gaim_notify_error(gc, NULL, failed_to_join, _("Not available")); break; default: gaim_notify_error(gc, NULL, failed_to_join, _("Unknown error. You may need to logout and wait five minutes before being able to rejoin a chatroom")); } return; } for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: room = yahoo_string_decode(gc, pair->value, TRUE); break; case 105: topic = yahoo_string_decode(gc, pair->value, TRUE); break; case 128: someid = pair->value; break; case 108: /* number of joiners */ break; case 129: someotherid = pair->value; break; case 130: somebase64orhashosomething = pair->value; break; case 126: somenegativenumber = pair->value; break; case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ break; case 61: /*this looks similar to 130 */ break; /* the previous section was just room info. this next section is info about individual room members, (including us) */ case 109: /* the yahoo id */ members = g_list_append(members, pair->value); break; case 110: /* age */ break; case 141: /* nickname */ break; case 142: /* location */ break; case 113: /* bitmask */ break; } } if (room && yd->chat_name && gaim_utf8_strcasecmp(room, yd->chat_name)) yahoo_chat_leave(gc, room, gaim_connection_get_display_name(gc), FALSE); c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (room && (!c || gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) && members && ((g_list_length(members) > 1) || !g_ascii_strcasecmp(members->data, gaim_connection_get_display_name(gc)))) { int i; GList *flags = NULL; for (i = 0; i < g_list_length(members); i++) flags = g_list_append(flags, GINT_TO_POINTER(GAIM_CBFLAGS_NONE)); if (c && gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) { /* this might be a hack, but oh well, it should nicely */ char *tmpmsg; gaim_conversation_set_name(c, room); c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, NULL, flags, FALSE); tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); gaim_conv_chat_write(GAIM_CONV_CHAT(c), "", tmpmsg, GAIM_MESSAGE_SYSTEM, time(NULL)); g_free(tmpmsg); } else { c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, NULL, flags, FALSE); } g_list_free(flags); } else if (c) { yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); } if (account->deny && c) { GaimConversationUiOps *ops = gaim_conversation_get_ui_ops(c); for (l = account->deny; l != NULL; l = l->next) { for (roomies = members; roomies; roomies = roomies->next) { if (!gaim_utf8_strcasecmp((char *)l->data, roomies->data)) { gaim_debug_info("yahoo", "Ignoring room member %s in room %s\n" , roomies->data, room ? room : ""); gaim_conv_chat_ignore(GAIM_CONV_CHAT(c),roomies->data); ops->chat_update_user(c, roomies->data); } } } } g_list_free(roomies); g_list_free(members); g_free(room); g_free(topic); }
/************************************************************************** * Message Handlers **************************************************************************/ static void plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GaimConnection *gc; MsnSwitchBoard *swboard; const char *body; char *body_str; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = cmdproc->session->account->gc; swboard = cmdproc->data; body = msn_message_get_bin_data(msg, &body_len); body_str = g_strndup(body, body_len); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { gaim_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { char *pre, *post; msn_parse_format(value, &pre, &post); body_final = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(pre); g_free(post); g_free(body_enc); } else { body_final = body_enc; } swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { /* If current_users is always ok as it should then there is no need to * check if this is a chat. */ if (swboard->current_users <= 1) gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_chat(gc, swboard->chat_id); swboard->flag |= MSN_SB_FLAG_IM; } } else { serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, gaim_connection_get_account(gc)); swboard->flag |= MSN_SB_FLAG_IM; } } g_free(body_final); }
void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt) { struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GaimConversation *c = NULL; GSList *l; GList *members = NULL; char *room = NULL; char *topic = NULL; char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; if (pkt->status == -1) { gaim_notify_error(gc, NULL, _("Failed to join chat"), _("Maybe the room is full?")); return; } for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: room = pair->value; break; case 105: topic = pair->value; break; case 128: someid = pair->value; break; case 108: /* number of joiners */ break; case 129: someotherid = pair->value; break; case 130: somebase64orhashosomething = pair->value; break; case 126: somenegativenumber = pair->value; break; case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ break; case 61: /*this looks similiar to 130 */ break; /* the previous section was just room info. this next section is info about individual room members, (including us) */ case 109: /* the yahoo id */ members = g_list_append(members, pair->value); break; case 110: /* age */ break; case 141: /* nickname */ break; case 142: /* location */ break; case 113: /* bitmask */ break; } } if (!room) return; if (yd->chat_name && gaim_utf8_strcasecmp(room, yd->chat_name)) yahoo_c_leave(gc, YAHOO_CHAT_ID); c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (!c) { c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) gaim_chat_set_topic(GAIM_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); gaim_chat_add_users(GAIM_CHAT(c), members); } else { yahoo_chat_add_users(GAIM_CHAT(c), members); } g_list_free(members); }