示例#1
0
void
translate_receiving_chat_msg_cb(const gchar *original_phrase, const gchar *translated_phrase, const gchar *detected_language, gpointer userdata)
{
	struct TranslateConvMessage *convmsg = userdata;
	PurpleChat *chat;
	gchar *html_text;
	const gchar *stored_lang = "";
	const gchar *language_name = NULL;
	gchar *message;
	
	if (detected_language)
	{
		chat = purple_blist_find_chat(convmsg->account, convmsg->conv->name);
		stored_lang = purple_blist_node_get_string((PurpleBlistNode *)chat, DEST_LANG_SETTING);
		purple_blist_node_set_string((PurpleBlistNode *)chat, DEST_LANG_SETTING, detected_language);
		
		language_name = get_language_name(detected_language);
		
		if (language_name != NULL)
		{
			message = g_strdup_printf("Now translating to %s (auto-detected)", language_name);
			purple_conversation_write(convmsg->conv, NULL, message, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
			g_free(message);
		}
	}
	
	html_text = purple_strdup_withhtml(translated_phrase);
	
	purple_conversation_write(convmsg->conv, convmsg->sender, html_text, convmsg->flags, time(NULL));
	
	g_free(html_text);
	g_free(convmsg->sender);
	g_free(convmsg);
}
示例#2
0
文件: f_chat.c 项目: scljz/fetion
void SendMsgTimeout_cb(struct fetion_account_data *sip, struct sipmsg *msg, struct transaction *tc)
{
	PurpleConversation *conv;
	const gchar *who;
	char *reason;
	who = sipmsg_find_header(msg,"T");
	if(!who) 
		return;

	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, who, sip->gc->account);
	if(conv)
	{
		switch (msg->response)
		{
			case 401:
				reason = g_strdup_printf(_("Message may have not been sent,because of Unauthoried !"));
				break;
			case 504:
				reason = g_strdup_printf(_("Message may have not been sent,because of Server Time-out !"));
				break;
			default:
				reason = g_strdup_printf(_("Message may have not been sent,because of timeout!"));
				
		}
		purple_conversation_write(conv, NULL, reason, PURPLE_MESSAGE_ERROR, time(NULL));
		purple_conversation_write(conv, NULL, msg->body, PURPLE_MESSAGE_RAW, time(NULL));

		g_free(reason);
	}


}
示例#3
0
/* ------------------
 * send public key to other person in conversation
 * ------------------ */
static void
menu_action_sendkey_cb(PurpleConversation *conv, void* data)
{
	// check if user selected a main key
	const char* fpr = purple_prefs_get_string(PREF_MY_KEY);
	if (fpr == NULL)
		fpr = "";
	if (strcmp(fpr,"") != 0)
	{
		char* key = NULL;
		// get key
		key = get_key_armored(fpr);

		if (key != NULL)
		{
			// send key
			PurpleConvIm* im_data = purple_conversation_get_im_data(conv);
			if (im_data != NULL)
			{
				purple_conv_im_send_with_flags(im_data,key,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_INVISIBLE | PURPLE_MESSAGE_RAW );
				purple_conversation_write(conv,"","Public key sent!",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
			}
		}
	}else
	{
		purple_conversation_write(conv,"","You haven't selected a personal key yet.",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
	}
}
示例#4
0
/* ------------------
 * try to retrieve key from server
 * ------------------ */
static void
menu_action_retrievekey_cb(PurpleConversation *conv, void* data)
{
	char sys_msg_buffer[1000];
	// check if the user with the jid=conv->name has signed his presence
	char* bare_jid = get_bare_jid(conv->name);

	// get stored info about user
	struct list_item* item = g_hash_table_lookup(list_fingerprints,bare_jid);
	if (item != NULL)
	{
		char* userid = NULL;
		if (is_key_available(item->fpr,FALSE,TRUE,&userid) == FALSE)
		{
			sprintf(sys_msg_buffer,"Did not find key with ID '%s' on keyservers.",item->fpr);
			purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
		}else
		{
			// found key -> enable mode_enc
			sprintf(sys_msg_buffer,"Found key with ID '%s'/'%s' for '%s' on keyservers.",item->fpr,userid,bare_jid);
			purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
			purple_conversation_write(conv,"","Encryption enabled",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
			item->mode_sec = TRUE;
		}
		if (userid != NULL)
			free(userid);
	}

	free(bare_jid);
}
示例#5
0
/* ------------------
 * called on new conversations
 * ------------------ */
void conversation_created_cb(PurpleConversation *conv, char* data)
{
	char sys_msg_buffer[1000];
	if (purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM)
		return;

	purple_debug_info(PLUGIN_ID, "conversation name: %s\n",conv->name);

	// check if the user with the jid=conv->name has signed his presence
	char* bare_jid = get_bare_jid(conv->name);

	// get stored info about user
	struct list_item* item = g_hash_table_lookup(list_fingerprints,bare_jid);
	if (item == NULL)
	{
		sprintf(sys_msg_buffer,"No encryption support in client of '%s'",bare_jid);
	}else
	{
		sprintf(sys_msg_buffer,"Client of user %s supports encryption",bare_jid);
	}

	// display a basic message
	purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));

	if (item != NULL)
	{
		char* userid = NULL;
		// check if we have key locally
		if (is_key_available(item->fpr,FALSE,FALSE,&userid) == FALSE)
		{
			if (userid != NULL)
				free(userid);
			userid = NULL;

			sprintf(sys_msg_buffer,"User has key with ID '%s', but we do not have it locally, try Options->\"Try to retrieve key of '%s' from server\"",item->fpr,bare_jid);
			purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
		}else
		{
			// key is already available locally -> enable mode_enc
			sprintf(sys_msg_buffer,"'%s' uses key with id '%s'/'%s'",bare_jid,userid,item->fpr);
			purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
			item->mode_sec = TRUE;
		}
		if (userid != NULL)
			free(userid);
		userid = NULL;
		// if we have the key now, move to secure mode
		if (item->mode_sec == TRUE)
			sprintf(sys_msg_buffer,"Encryption enabled");
		else
			sprintf(sys_msg_buffer,"Encryption disabled");
	}else
		sprintf(sys_msg_buffer,"Encryption disabled");

	// display message about received message
	purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));

	free(bare_jid);
}
示例#6
0
static int fx_im_send(PurpleConnection *gc, const gchar *who, const gchar *what, PurpleMessageFlags UNUSED(flags))
{
	PurpleBuddy    *buddy;
	PurplePresence *presence;
	PurpleStatus   *status;
	const gchar    *status_id;
	fetion_account  *sec;
	PurpleConversation *conv;
	fetion_account  *ac = purple_connection_get_protocol_data(gc);

	Contact        *cnt;
	gint            shutdown = 0;

	if(!(buddy = purple_find_buddy(ac->account, who))) return 0;
	presence = purple_buddy_get_presence(buddy);
	status   = purple_presence_get_active_status(presence);
	status_id = purple_status_get_id(status);

	cnt = fetion_contact_list_find_by_userid(ac->user->contactList, who);
	if(cnt->relationStatus == RELATION_STATUS_UNAUTHENTICATED) {
		if(!(conv = purple_find_conversation_with_account(
						PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1;
			purple_conversation_write(conv, NULL,
					  _("Failed to send message: Unverified Buddy!"),
					  PURPLE_MESSAGE_ERROR, time(NULL));
			return -1;
	}
	
	if(cnt->serviceStatus == BASIC_SERVICE_ABNORMAL){
		if(cnt->carrierStatus == CARRIER_STATUS_CLOSED){
			shutdown = 1;
		}else{
			if((cnt->carrier[0] != '\0' && cnt->mobileno[0] == '\0') || cnt->carrier[0] == '\0')
				shutdown = 1;
		}
	}else if(cnt->carrierStatus == CARRIER_STATUS_DOWN)
		if(cnt->carrier[0] != '\0') shutdown = 1;

	if(shutdown) {
		if(!(conv = purple_find_conversation_with_account(
						PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1;
			purple_conversation_write(conv, NULL,
					  _("Fail to send message: Buddy has cancled Fetion service!"),
					  PURPLE_MESSAGE_ERROR, time(NULL));
			return -1;
	}

	/* online,need invite */
	if(strcmp(status_id, "Offline") != 0) {
		if(!(sec = session_find(who))) new_chat(ac, who, what);
		else  fetion_send_sms(sec, who, what);
		return 1;
	}

	fetion_send_sms(ac, who, what);
	return 1;
}
示例#7
0
void Poller::op_notified_kickout_from_group(line::Operation &op) {
    std::string msg;

    if (op.param3 == parent.profile.mid) {
        msg = "You were removed from the group by ";
        parent.blist_remove_chat(op.param1, ChatType::GROUP);
    } else {
        msg = "Removed from the group by ";
        parent.blist_update_chat(op.param1, ChatType::GROUP);
    }

    if (parent.contacts.count(op.param2) == 1)
        msg += parent.contacts[op.param2].displayName;
    else
        msg += "(unknown contact)";

    PurpleConversation *conv = purple_find_conversation_with_account(
        PURPLE_CONV_TYPE_CHAT,
        op.param1.c_str(),
        parent.acct);

    if (conv) {
        purple_conversation_write(
            conv,
            op.param3.c_str(),
            msg.c_str(),
            PURPLE_MESSAGE_SYSTEM,
            time(NULL));
    }
}
示例#8
0
/* ------------------
 * called before display of received messages
 * ------------------ */
static gboolean
receiving_im_msg_cb(PurpleAccount *account, char **sender, char **buffer,
				    PurpleConversation *conv, PurpleMessageFlags *flags, void *data)
{
	char sys_msg_buffer[1000];

	// check if the user with the jid=conv->name has signed his presence
	char* bare_jid = get_bare_jid(*sender);

	// set default message
	sprintf(sys_msg_buffer,"Encryption disabled");

	// get encryption key
	struct list_item* item = g_hash_table_lookup(list_fingerprints,bare_jid);
	if (item != NULL)
	{
		if (item->mode_sec == TRUE)
			sprintf(sys_msg_buffer,"Encryption enabled");

		// display a basic message, only if mode changed
		if (item->mode_sec != item->mode_sec_old)
			purple_conversation_write(conv,"",sys_msg_buffer,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
		item->mode_sec_old = item->mode_sec;
	}
	free(bare_jid);

	return FALSE;
}
示例#9
0
/* ------------------
 * called before message is sent
 * ------------------ */
void sending_im_msg_cb(PurpleAccount *account, const char *receiver,
                       char **message)
{
	PurpleConversation *gconv = NULL;

	// search for conversation
	gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, receiver, account);
	if(gconv)
	{
		// check if the user with the jid=conv->name has signed his presence
		char* bare_jid = get_bare_jid(gconv->name);
		// get stored info about user
		struct list_item* item = g_hash_table_lookup(list_fingerprints,bare_jid);
		if (item != NULL)
		{
			// if we are in private mode
			if (item->mode_sec == TRUE)
			{
				// try to get key
				if (is_key_available(item->fpr,FALSE,FALSE,NULL) == FALSE)
				{
					// we do not have key of receiver
					// -> cancel message sending
					free (*message);
					*message = NULL;

					// tell user of this
					purple_conversation_write(gconv,"","The key of the receiver is not available, please ask the receiver for the key before trying to encrypt messages.",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL));
				}
			}
		}
		free(bare_jid);
	}
}
示例#10
0
static void
translate_conversation_created(PurpleConversation *conv)
{
	PurpleBlistNode *node = NULL;
	gchar *message;
	const gchar *language_key;
	const gchar *language_name;
	
	if (conv->type == PURPLE_CONV_TYPE_IM)
		node = (PurpleBlistNode *) purple_find_buddy(conv->account, conv->name);
	else if (conv->type == PURPLE_CONV_TYPE_CHAT)
		node = (PurpleBlistNode *) purple_blist_find_chat(conv->account, conv->name);
	
	if (node != NULL)
	{
		language_key = purple_blist_node_get_string(node, DEST_LANG_SETTING);
		
		if (language_key != NULL)
		{
			language_name = get_language_name(language_key);
		
			message = g_strdup_printf(_("Now translating to %s"), language_name);
			purple_conversation_write(conv, NULL, message, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
			g_free(message);
		}
	}
}
示例#11
0
文件: jabber.c 项目: Draghtnod/pidgin
static void
_start_stream(gpointer data, gint source, PurpleInputCondition condition)
{
	BonjourJabberConversation *bconv = data;
	struct _stream_start_data *ss = bconv->stream_data;
	int len, ret;

	len = strlen(ss->msg);

	/* Start Stream */
	ret = send(source, ss->msg, len, 0);

	if (ret == -1 && errno == EAGAIN)
		return;
	else if (ret <= 0) {
		const char *err = g_strerror(errno);
		PurpleConversation *conv;
		const char *bname = bconv->buddy_name;
		BonjourBuddy *bb = NULL;

		if(bconv->pb) {
			bb = purple_buddy_get_protocol_data(bconv->pb);
			bname = purple_buddy_get_name(bconv->pb);
		}

		purple_debug_error("bonjour", "Error starting stream with buddy %s at %s error: %s\n",
				   bname ? bname : "(unknown)", bconv->ip, err ? err : "(null)");

		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bname, bconv->account);
		if (conv != NULL)
			purple_conversation_write(conv, NULL,
				  _("Unable to send the message, the conversation couldn't be started."),
				  PURPLE_MESSAGE_SYSTEM, time(NULL));

		bonjour_jabber_close_conversation(bconv);
		if(bb != NULL)
			bb->conversation = NULL;

		return;
	}

	/* This is EXTREMELY unlikely to happen */
	if (ret < len) {
		char *tmp = g_strdup(ss->msg + ret);
		g_free(ss->msg);
		ss->msg = tmp;
		return;
	}

	g_free(ss->msg);
	g_free(ss);
	bconv->stream_data = NULL;

	/* Stream started; process the send buffer if there is one */
	purple_input_remove(bconv->tx_handler);
	bconv->tx_handler = 0;
	bconv->sent_stream_start = FULLY_SENT;

	bonjour_jabber_stream_started(bconv);
}
示例#12
0
void tgp_msg_sys_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to_id, int no_log) {
  int flags = PURPLE_MESSAGE_SYSTEM;
  if (no_log) {
    flags |= PURPLE_MESSAGE_NO_LOG;
  }
  time_t now;
  time (&now);
  
  switch (tgl_get_peer_type (to_id)) {
    case TGL_PEER_CHAT:
      p2tgl_got_chat_in (TLS, to_id, to_id, msg, flags, now);
      break;
    case TGL_PEER_USER:
    case TGL_PEER_ENCR_CHAT: {
      const char *name = tgp_blist_lookup_purple_name (TLS, to_id);
      PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id);
      
      g_return_if_fail (name);

      if (! conv) {
        conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, tls_get_pa (TLS), name);
      }
      purple_conversation_write (conv, name, msg, flags, now);
      break;
    }
  }
}
示例#13
0
static void
conversation_created_cb (PurpleConversation *conv, gpointer data)
{
    gchar *str;
    const gchar *tmp_user, *friendly_name;
    MsnSession *session = data;
    struct pn_contact *contact;

    tmp_user = purple_conversation_get_name (conv);
    contact = pn_contactlist_find_contact (session->contactlist, tmp_user);
    if (contact)
        friendly_name = pn_contact_get_friendly_name (contact);
    else
        friendly_name = tmp_user;
    if (!friendly_name)
        friendly_name = tmp_user;

    if (contact && !(contact->list_op & (1 << MSN_LIST_RL)))
    {
        str = g_strdup_printf (_("You are not in %s's contact list."), friendly_name);

        purple_conversation_write (conv, NULL, str, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NOTIFY, time (NULL));

        g_free (str);
    }
}
示例#14
0
文件: jabber.c 项目: Draghtnod/pidgin
static void bonjour_jabber_stream_ended(BonjourJabberConversation *bconv) {

	/* Inform the user that the conversation has been closed */
	BonjourBuddy *bb = NULL;
	const gchar *name = bconv->pb ? purple_buddy_get_name(bconv->pb) : "(unknown)";

	purple_debug_info("bonjour", "Received conversation close notification from %s.\n", name);

	if(bconv->pb != NULL)
		bb = purple_buddy_get_protocol_data(bconv->pb);
#if 0
	if(bconv->pb != NULL) {
		PurpleConversation *conv;
		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bconv->pb->name, bconv->pb->account);
		if (conv != NULL) {
			char *tmp = g_strdup_printf(_("%s has closed the conversation."), bconv->pb->name);
			purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL));
			g_free(tmp);
		}
	}
#endif
	/* Close the socket, clear the watcher and free memory */
	bonjour_jabber_close_conversation(bconv);
	if(bb)
		bb->conversation = NULL;
}
示例#15
0
void qq_sys_msg_write(qq_account* ac,LwqqMsgType m_t,const char* serv_id,const char* msg,PurpleMessageFlags type,time_t t)
{
	//ac->qq->dispatch(vp_func_2p,(CALLBACK_FUNC)sys_msg_write,ac->qq,system_msg_new(m_t,serv_id,ac,msg,type,t));

	PurpleConversation* conv = find_conversation(m_t,serv_id,ac);
	if(conv)
		purple_conversation_write(conv,NULL,msg,type,t);
}
示例#16
0
void yahoo_process_conference_decline(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	GSList *l;
	char *room = NULL;
	char *who = NULL;
	char *msg = NULL;
	PurpleConversation *c = NULL;
	int utf8 = 0;

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		switch (pair->key) {
		case 57:
			g_free(room);
			room = yahoo_string_decode(gc, pair->value, FALSE);
			break;
		case 54:
			who = pair->value;
			break;
		case 14:
			g_free(msg);
			msg = yahoo_string_decode(gc, pair->value, FALSE);
			break;
		case 97:
			utf8 = strtol(pair->value, NULL, 10);
			break;
		}
	}
	if (!purple_privacy_check(purple_connection_get_account(gc), who))
	{
		g_free(room);
		g_free(msg);
		return;
	}

	if (who && room) {
		/* make sure we're in the room before we process a decline message for it */
		if((c = yahoo_find_conference(gc, room))) {
			char *tmp = NULL, *msg_tmp = NULL;
			if(msg)
			{
				msg_tmp = yahoo_string_decode(gc, msg, utf8);
				msg = yahoo_codes_to_html(msg_tmp);
				serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), who, 0, msg, time(NULL));
				g_free(msg_tmp);
				g_free(msg);
			}

			tmp = g_strdup_printf(_("%s has declined to join."), who);
			purple_conversation_write(c, NULL, tmp, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY, time(NULL));

			g_free(tmp);
		}

		g_free(room);
	}
}
示例#17
0
文件: hon.c 项目: theli-ua/honpurple
void hon_parse_userinfo(PurpleConnection* gc,gchar* buffer,guint16 packet_id){
    hon_account* hon = gc->proto_data;
    /* TODO: this is not right .. conversation could be closed already */
    gchar* message = NULL;
    gchar* name = NULL,*strtime = NULL;
    gchar* user = read_string(buffer);
    if (!hon->whois_conv)
        return;

    switch (packet_id){
    case 0x2b:
        message = g_strdup_printf(_("Cannot find user %s"),user);
        break;
    case 0x2c:
        message = g_strdup_printf(_("User %s is offline, last seen %s"),user,buffer);
        break;
    case 0x2d:
        {
            GString* msg = g_string_new(NULL);
            guint32 chan_count = read_guint32(buffer);
            if (chan_count > 0)
                g_string_printf(msg,_("User %s is online and in channels: "),user);
            else
                g_string_printf(msg,_("User %s is online."),user);
            while (chan_count--)
            {
                msg = g_string_append(msg,buffer);
                if (chan_count == 0)
                    msg = g_string_append(msg,".");
                else
                    msg = g_string_append(msg,", ");
                read_string(buffer);
            }
            message = g_string_free(msg,FALSE);
        }
        break;
    case 0x2e:
        name = read_string(buffer);
        strtime = read_string(buffer);
        message = g_strdup_printf(_("User %s is ingame, game name: %s, game time: %s"),user,name,strtime);
        break;
    }

    purple_conversation_write(hon->whois_conv, "",message, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
    g_free(message);
    
    
#ifdef MINBIF
    if (packet_id == 0x2e)
        message = g_strdup_printf("%s %s %d %s %s", MINBIF_INFO,user,packet_id, strtime, name);
    else
        message = g_strdup_printf("%s %s %d", MINBIF_INFO,user,packet_id);
    serv_got_im(gc,MINBIF_USER,message,PURPLE_MESSAGE_RECV,time(NULL));
    g_free(message);
#endif
    hon->whois_conv = NULL;
}
示例#18
0
/* put Message to User Conversation
 *
 * 	passport - the one want to talk to you
 */
void
msn_session_report_user(MsnSession *session,const char *passport,const char *msg,PurpleMessageFlags flags)
{
	PurpleConversation * conv;

	if ((conv = msn_session_get_conv(session,passport)) != NULL){
		purple_conversation_write(conv, NULL, msg, flags, time(NULL));
	}
}
示例#19
0
文件: gtkmedia.c 项目: dylex/pidgin
static void
pidgin_media_emit_message(PidginMedia *gtkmedia, const char *msg)
{
	PurpleConversation *conv = purple_find_conversation_with_account(
			PURPLE_CONV_TYPE_ANY, gtkmedia->priv->screenname,
			purple_media_get_account(gtkmedia->priv->media));
	if (conv != NULL)
		purple_conversation_write(conv, NULL, msg,
				PURPLE_MESSAGE_SYSTEM, time(NULL));
}
示例#20
0
static void 
purple_xfer_conversation_write_internal(PurpleXfer *xfer,
	const char *message, gboolean is_error, gboolean print_thumbnail)
{
	PurpleConversation *conv = NULL;
	PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM;
	char *escaped;
	gconstpointer thumbnail_data;
	gsize size;

	g_return_if_fail(xfer != NULL);
	g_return_if_fail(message != NULL);

	thumbnail_data = purple_xfer_get_thumbnail(xfer, &size);

	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who,
											   purple_xfer_get_account(xfer));

	if (conv == NULL)
		return;

	escaped = g_markup_escape_text(message, -1);

	if (is_error)
		flags |= PURPLE_MESSAGE_ERROR;

	if (print_thumbnail && thumbnail_data) {
		gchar *message_with_img;
		gpointer data = g_memdup(thumbnail_data, size); 
		int id = purple_imgstore_add_with_id(data, size, NULL);

		message_with_img = 
			g_strdup_printf("<img id='%d'> %s", id, escaped);
		purple_conversation_write(conv, NULL, message_with_img, flags, 
			time(NULL));
		purple_imgstore_unref_by_id(id);
		g_free(message_with_img);
	} else {
		purple_conversation_write(conv, NULL, escaped, flags, time(NULL));
	}
	g_free(escaped);
}
示例#21
0
文件: jabber.c 项目: Draghtnod/pidgin
static gboolean bonjour_jabber_send_stream_init(BonjourJabberConversation *bconv, int client_socket)
{
	int ret, len;
	char *stream_start;
	const char *bname = bconv->buddy_name;

	if (bconv->pb != NULL)
		bname = purple_buddy_get_name(bconv->pb);

	/* If we have no idea who "to" is, use an empty string.
	 * If we don't know now, it is because the other side isn't playing nice, so they can't complain. */
	if (bname == NULL)
		bname = "";

	stream_start = g_strdup_printf(DOCTYPE, bonjour_get_jid(bconv->account), bname);
	len = strlen(stream_start);

	bconv->sent_stream_start = PARTIALLY_SENT;

	/* Start the stream */
	ret = send(client_socket, stream_start, len, 0);

	if (ret == -1 && errno == EAGAIN)
		ret = 0;
	else if (ret <= 0) {
		const char *err = g_strerror(errno);

		purple_debug_error("bonjour", "Error starting stream with buddy %s at %s error: %s\n",
				   (*bname) ? bname : "(unknown)", bconv->ip, err ? err : "(null)");

		if (bconv->pb) {
			PurpleConversation *conv;
			conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bname, bconv->account);
			if (conv != NULL)
				purple_conversation_write(conv, NULL,
					  _("Unable to send the message, the conversation couldn't be started."),
					  PURPLE_MESSAGE_SYSTEM, time(NULL));
		}

		close(client_socket);
		g_free(stream_start);

		return FALSE;
	}

	/* This is unlikely to happen */
	if (ret < len) {
		struct _stream_start_data *ss = g_new(struct _stream_start_data, 1);
		ss->msg = g_strdup(stream_start + ret);
		bconv->stream_data = ss;
		/* Finish sending the stream start */
		bconv->tx_handler = purple_input_add(client_socket,
			PURPLE_INPUT_WRITE, _start_stream, bconv);
	} else
示例#22
0
static void
pidgin_media_error_cb(PidginMedia *media, const char *error, PidginMedia *gtkmedia)
{
	PurpleConversation *conv = purple_find_conversation_with_account(
			PURPLE_CONV_TYPE_ANY, gtkmedia->priv->screenname,
			purple_media_get_account(gtkmedia->priv->media));
	if (conv != NULL)
		purple_conversation_write(conv, NULL, error,
				PURPLE_MESSAGE_ERROR, time(NULL));
	gtk_statusbar_push(GTK_STATUSBAR(gtkmedia->priv->statusbar),
			0, error);
}
示例#23
0
文件: jabber.c 项目: Draghtnod/pidgin
static gint
_send_data(PurpleBuddy *pb, char *message)
{
	gint ret;
	int len = strlen(message);
	BonjourBuddy *bb = purple_buddy_get_protocol_data(pb);
	BonjourJabberConversation *bconv = bb->conversation;

	/* If we're not ready to actually send, append it to the buffer */
	if (bconv->tx_handler != 0
			|| bconv->connect_data != NULL
			|| bconv->sent_stream_start != FULLY_SENT
			|| !bconv->recv_stream_start
			|| purple_circ_buffer_get_max_read(bconv->tx_buf) > 0) {
		ret = -1;
		errno = EAGAIN;
	} else {
		ret = send(bconv->socket, message, len, 0);
	}

	if (ret == -1 && errno == EAGAIN)
		ret = 0;
	else if (ret <= 0) {
		PurpleConversation *conv;
		PurpleAccount *account;
		const char *error = g_strerror(errno);

		purple_debug_error("bonjour", "Error sending message to buddy %s error: %s\n",
				   purple_buddy_get_name(pb), error ? error : "(null)");

		account = purple_buddy_get_account(pb);

		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, account);
		if (conv != NULL)
			purple_conversation_write(conv, NULL,
				  _("Unable to send message."),
				  PURPLE_MESSAGE_SYSTEM, time(NULL));

		bonjour_jabber_close_conversation(bb->conversation);
		bb->conversation = NULL;
		return -1;
	}

	if (ret < len) {
		/* Don't interfere with the stream starting */
		if (bconv->sent_stream_start == FULLY_SENT && bconv->recv_stream_start && bconv->tx_handler == 0)
			bconv->tx_handler = purple_input_add(bconv->socket, PURPLE_INPUT_WRITE,
				_send_data_write_cb, pb);
		purple_circ_buffer_append(bconv->tx_buf, message + ret, len - ret);
	}

	return ret;
}
示例#24
0
static void
msn_switchboard_report_user(MsnSwitchBoard *swboard, PurpleMessageFlags flags, const char *msg)
{
	PurpleConversation *conv;

	g_return_if_fail(swboard != NULL);
	g_return_if_fail(msg != NULL);

	if ((conv = msn_switchboard_get_conv(swboard)) != NULL)
	{
		purple_conversation_write(conv, NULL, msg, flags, time(NULL));
	}
}
示例#25
0
static void
timezone_createconv_cb(PurpleConversation * conv, void *data)
{
    const char *name;
    PurpleBuddy *buddy;
    struct tm tm;
    const char *timezone;
    double diff;
    int ret;

    if (purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM)
        return;

    name = purple_conversation_get_name(conv);
    buddy = purple_find_buddy(purple_conversation_get_account(conv), name);
    if (!buddy)
        return;

    timezone = buddy_get_timezone((PurpleBlistNode *) buddy, TRUE, NULL);

    if (!timezone)
        return;

    ret = timezone_get_time(timezone, &tm, &diff, NULL);

    if (ret == 0)
    {
        const char *text = purple_time_format(&tm);

        char *str;
	if (diff < 0)
	{
            diff = 0 - diff;
            str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Remote Local Time: %s (%.4g hour behind)",
                                            "Remote Local Time: %s (%.4g hours behind)", diff),
                                  text, diff);
	}
	else
	{
            str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Remote Local Time: %s (%.4g hour ahead)",
                                            "Remote Local Time: %s (%.4g hours ahead)", diff),
                                  text, diff);
	}

        purple_conversation_write(conv, PLUGIN_STATIC_NAME, str, PURPLE_MESSAGE_SYSTEM, time(NULL));

        g_free(str);
    }
}
示例#26
0
void
SendMsgTimeout_cb(struct fetion_account_data *sip, struct sipmsg *msg,
		  struct transaction *tc)
{
	PurpleConversation *conv;
	const gchar *who;
	who = sipmsg_find_header(msg, "T");
	if (!who)
		return;

	conv =
	    purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, who,
						  sip->gc->account);
	if (conv) {
		purple_conversation_write(conv, NULL,
					  _
					  ("Message may have not been sent,because of timeout! "),
					  PURPLE_MESSAGE_ERROR, time(NULL));
		purple_conversation_write(conv, NULL, msg->body,
					  PURPLE_MESSAGE_RAW, time(NULL));
	}

}
示例#27
0
void qq_sys_msg_write(qq_account* ac, LwqqMsgType m_t, const char* serv_id,
                      const char* msg, PurpleMessageFlags type, time_t t)
{
   // ac->qq->dispatch(vp_func_2p,(CALLBACK_FUNC)sys_msg_write,ac->qq,system_msg_new(m_t,serv_id,ac,msg,type,t));

   const char* local_id;
   PurpleConversation* conv = find_conversation(m_t, serv_id, ac, &local_id);
   if (conv) {
      purple_conversation_write(conv, NULL, msg, type, t);
      const char* signal = (m_t == LWQQ_MS_BUDDY_MSG || m_t == LWQQ_MS_SESS_MSG)
                               ? "received-im-msg"
                               : "recieved-chat-msg";
      purple_signal_emit(purple_conversations_get_handle(), signal, ac->account,
                         conv->name, msg, conv, type);
   }
}
/*static void
toggle_nickchange_pref(const char *name, PurplePrefType type, gconstpointer val, gpointer data)
{
	
}*/
static void nickchange_chat_rename_user
(PurpleConversation *conv, const char *old_user, const char *new_user, const char *new_alias)
{
	if (!should_hide_notice(conv, old_user, userstable)) {
		PurpleConvChat *chat = PURPLE_CONV_CHAT(conv);
		char tmp[2048];
		
		if (purple_strequal(chat->nick, purple_normalize(conv->account, old_user))) {
			// Its me!
			char *escaped = g_markup_escape_text(new_user, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("You are now known as %s"), escaped);
			g_free(escaped);
		} else {
			const char *old_alias = old_user;
			const char *new_alias = new_user;
			char *escaped;
			char *escaped2;
			PurpleConnection *gc = purple_conversation_get_gc(conv);
			PurplePluginProtocolInfo *prpl_info;
			
			prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
			if (prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
				PurpleBuddy *buddy;

				if ((buddy = purple_find_buddy(gc->account, old_user)) != NULL)
					old_alias = purple_buddy_get_contact_alias(buddy);
				if ((buddy = purple_find_buddy(gc->account, new_user)) != NULL)
					new_alias = purple_buddy_get_contact_alias(buddy);
			}

			escaped = g_markup_escape_text(old_alias, -1);
			escaped2 = g_markup_escape_text(new_alias, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("%s is now known as %s"), escaped, escaped2);
			g_free(escaped);
			g_free(escaped2);
		}

		purple_conversation_write(conv, NULL, tmp,
				PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY,
				time(NULL));
	}
	
	if (orig_chat_rename_user)
		return orig_chat_rename_user(conv, old_user, new_user, new_alias);
}
示例#29
0
static void
buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
  PurpleConversation *gconv;

  if(purple_prefs_get_bool(PREF_STATUS) &&
     ! purple_status_is_available(purple_account_get_active_status(acct))) {
    purple_debug_info("psychic", "not available, doing nothing\n");
    return;
  }

  if(purple_prefs_get_bool(PREF_BUDDIES) &&
     ! purple_find_buddy(acct, name)) {
    purple_debug_info("psychic", "not in blist, doing nothing\n");
    return;
  }

  if(FALSE == purple_privacy_check(acct, name)) {
    purple_debug_info("psychic", "user %s is blocked\n", name);
    return;
  }

  gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, acct);
  if(! gconv) {
    purple_debug_info("psychic", "no previous conversation exists\n");
    gconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, name);

    if(purple_prefs_get_bool(PREF_RAISE)) {
      purple_conversation_present(gconv);
    }

    if(purple_prefs_get_bool(PREF_NOTICE)) {

      /* This is a quote from Star Wars.  You should probably not
	 translate it literally.  If you can't find a fitting cultural
	 reference in your language, consider translating something
	 like this instead: "You feel a new message coming." */
      purple_conversation_write(gconv, NULL,
			      _("You feel a disturbance in the force..."),
			      PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY,
			      time(NULL));
    }

    /* Necessary because we may be creating a new conversation window. */
    purple_conv_im_set_typing_state(PURPLE_CONV_IM(gconv), PURPLE_TYPING);
  }
}
示例#30
0
void
purple_xfer_set_completed(PurpleXfer *xfer, gboolean completed)
{
	PurpleXferUiOps *ui_ops;

	g_return_if_fail(xfer != NULL);

	if (completed == TRUE) {
		char *msg = NULL;
		PurpleConversation *conv;

		purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_DONE);

		if (purple_xfer_get_filename(xfer) != NULL)
		{
			char *filename = g_markup_escape_text(purple_xfer_get_filename(xfer), -1);
			if (purple_xfer_get_local_filename(xfer)
			 && purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE)
			{
				char *local = g_markup_escape_text(purple_xfer_get_local_filename(xfer), -1);
				msg = g_strdup_printf(_("Transfer of file <A HREF=\"file://%s\">%s</A> complete"),
				                      local, filename);
				g_free(local);
			}
			else
				msg = g_strdup_printf(_("Transfer of file %s complete"),
				                      filename);
			g_free(filename);
		}
		else
			msg = g_strdup(_("File transfer complete"));

		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who,
		                                             purple_xfer_get_account(xfer));

		if (conv != NULL)
			purple_conversation_write(conv, NULL, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
		g_free(msg);
	}

	ui_ops = purple_xfer_get_ui_ops(xfer);

	if (ui_ops != NULL && ui_ops->update_progress != NULL)
		ui_ops->update_progress(xfer, purple_xfer_get_progress(xfer));
}