/*------------------------------------------------------------------------ * User has entered a message in a chatroom window, send it to the MXit server. * * @param gc The connection object * @param id The chat room ID * @param message The sent message data * @param flags The message flags * @return Indicates success / failure */ int mxit_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) { struct MXitSession* session = (struct MXitSession*) gc->proto_data; struct multimx* multimx = NULL; const char* nickname; purple_debug_info(MXIT_PLUGIN_ID, "Groupchat %i message send: '%s'\n", id, message); /* Find matching MultiMX group */ multimx = find_room_by_id(session, id); if (multimx == NULL) { purple_debug_error(MXIT_PLUGIN_ID, "Could not find groupchat %i\n", id); return -1; } /* Send packet to MXit */ mxit_send_message(session, multimx->roomid, message, TRUE, FALSE); /* Determine our nickname to display */ if (multimx->nickname) nickname = multimx->nickname; else nickname = purple_account_get_alias(purple_connection_get_account(gc)); /* local alias */ /* Display message in chat window */ serv_got_chat_in(gc, id, nickname, flags, message, time(NULL)); return 0; }
/*------------------------------------------------------------------------ * Send a message to a contact * * @param gc The connection object * @param who The username of the recipient * @param message The message text * @param flags Message flags (defined in conversation.h) * @return Positive value (success, and echo to conversation window) Zero (success, no echo) Negative value (error) */ static int mxit_send_im( PurpleConnection* gc, const char* who, const char* message, PurpleMessageFlags flags ) { purple_debug_info( MXIT_PLUGIN_ID, "Sending message '%s' to buddy '%s'\n", message, who ); mxit_send_message( purple_connection_get_protocol_data( gc ), who, message, TRUE, FALSE ); return 1; /* echo to conversation window */ }
/*------------------------------------------------------------------------ * Send a message to a contact * * @param gc The connection object * @param who The username of the recipient * @param message The message text * @param flags Message flags (defined in conversation.h) * @return Positive value (success, and echo to conversation window) Zero (success, no echo) Negative value (error) */ static int mxit_send_im(PurpleConnection* gc, PurpleMessage *msg) { mxit_send_message(purple_connection_get_protocol_data(gc), purple_message_get_recipient(msg), purple_message_get_contents(msg), TRUE, FALSE); return 1; /* echo to conversation window */ }
/*------------------------------------------------------------------------ * This gets called when a new chat conversation is opened by the user * * @param conv The conversation object * @param session The MXit session object */ static void mxit_cb_chat_created( PurpleConversation* conv, struct MXitSession* session ) { PurpleConnection* gc; struct contact* contact; PurpleBuddy* buddy; const char* who; char* tmp; gc = purple_conversation_get_gc( conv ); if ( session->con != gc ) { /* not our conversation */ return; } else if ( purple_conversation_get_type( conv ) != PURPLE_CONV_TYPE_IM ) { /* wrong type of conversation */ return; } /* get the contact name */ who = purple_conversation_get_name( conv ); if ( !who ) return; purple_debug_info( MXIT_PLUGIN_ID, "Conversation started with '%s'\n", who ); /* find the buddy object */ buddy = purple_find_buddy( session->acc, who ); if ( !buddy ) return; contact = purple_buddy_get_protocol_data( buddy ); if ( !contact ) return; /* we ignore all conversations with which we have chatted with in this session */ if ( find_active_chat( session->active_chats, who ) ) return; /* determine if this buddy is a MXit service */ switch ( contact->type ) { case MXIT_TYPE_BOT : case MXIT_TYPE_CHATROOM : case MXIT_TYPE_GALLERY : case MXIT_TYPE_INFO : tmp = g_strdup_printf("<font color=\"#999999\">%s</font>\n", _( "Loading menu..." )); serv_got_im( session->con, who, tmp, PURPLE_MESSAGE_NOTIFY, time( NULL ) ); g_free( tmp ); mxit_send_message( session, who, " ", FALSE, FALSE ); default : break; } }
/*------------------------------------------------------------------------ * MultiMX room has been added to the roster. * * @param session The MXit session object * @param contact The MultiMX room's contact information */ void multimx_created(struct MXitSession* session, struct contact* contact) { PurpleConnection *gc = session->con; struct multimx* multimx = NULL; purple_debug_info(MXIT_PLUGIN_ID, "Groupchat '%s' created as '%s'\n", contact->alias, contact->username); /* Find matching MultiMX group */ multimx = find_room_by_username(session, contact->username); if (multimx == NULL) { multimx = room_create(session, contact->username, contact->alias, TRUE); } else if (multimx->state == STATE_INVITED) { /* After successfully accepting an invitation */ multimx->state = STATE_JOINED; } /* Call libpurple - will trigger 'mxit_chat_join' */ serv_got_joined_chat(gc, multimx->chatid, multimx->roomname); /* Send ".list" command to GroupChat server to retrieve current member-list */ mxit_send_message(session, multimx->roomid, ".list", FALSE, FALSE); }
/*------------------------------------------------------------------------ * Handle an URI clicked on the UI * * @param link the link name which has been clicked */ static void* mxit_link_click( const char* link64 ) { PurpleAccount* account; PurpleConnection* gc; gchar** parts = NULL; gchar* link = NULL; gsize len; gboolean is_command = FALSE; purple_debug_info( MXIT_PLUGIN_ID, "mxit_link_click (%s)\n", link64 ); if ( g_ascii_strncasecmp( link64, MXIT_LINK_PREFIX, strlen( MXIT_LINK_PREFIX ) ) != 0 ) { /* this is not for us */ goto skip; } /* decode the base64 payload */ link = (gchar*) purple_base64_decode( link64 + strlen( MXIT_LINK_PREFIX ), &len ); purple_debug_info( MXIT_PLUGIN_ID, "Clicked Link: '%s'\n", link ); parts = g_strsplit( link, "|", 6 ); /* check if this is a valid mxit link */ if ( ( !parts ) || ( !parts[0] ) || ( !parts[1] ) || ( !parts[2] ) || ( !parts[3] ) || ( !parts[4] ) || ( !parts[5] ) ) { /* this is not for us */ goto skip; } else if ( g_ascii_strcasecmp( parts[0], MXIT_LINK_KEY ) != 0 ) { /* this is not for us */ goto skip; } /* find the account */ account = purple_accounts_find( parts[1], parts[2] ); if ( !account ) goto skip; gc = purple_account_get_connection( account ); if ( !gc ) goto skip; /* determine if it's a command-response to send */ is_command = ( atoi( parts[4] ) == 1 ); /* send click message back to MXit */ mxit_send_message( purple_connection_get_protocol_data( gc ), parts[3], parts[5], FALSE, is_command ); g_free( link ); link = NULL; g_strfreev( parts ); parts = NULL; return (void*) link64; skip: /* this is not an internal mxit link */ if ( link ) g_free( link ); link = NULL; if ( parts ) g_strfreev( parts ); parts = NULL; if ( mxit_pidgin_uri_cb ) return mxit_pidgin_uri_cb( link64 ); else return (void*) link64; }