Exemplo n.º 1
0
static void
notify_msg_sent (PurpleAccount *account,
				 PurpleConversation *conv,
				 const gchar *sender,
				 const gchar *message)
{
	PurpleBuddy *buddy;
	gchar *title, *body, *tr_name;
	gboolean blocked;

	blocked = purple_prefs_get_bool ("/plugins/gtk/libnotify/blocked");
	if (blocked && !purple_privacy_check(account, sender))
		return;

	buddy = purple_find_buddy (account, sender);
	if (buddy)
		tr_name = truncate_escape_string (best_name (buddy), 25);
	else if (conv) {
		char *name = g_strdup_printf (_("%s (%s)"), sender, purple_conversation_get_name (conv));
		tr_name = truncate_escape_string (name, 25);
		g_free (name);
	} else
		tr_name = truncate_escape_string (sender, 25);

	if (purple_prefs_get_bool("/plugins/gtk/libnotify/newmsgtxt")) {
		title = g_strdup_printf (_("%s says:"), tr_name);
		body = purple_markup_strip_html (message);

		notify (title, body, buddy, conv);

		g_free (title);
	} else {
		title = _("new message received");
		body = g_strdup_printf (_("from %s"), tr_name);

		notify (title, body, buddy, conv);
	}
	g_free (tr_name);
	g_free (body);
}
Exemplo n.º 2
0
static char *
purple_notify_user_info_get_xhtml(PurpleNotifyUserInfo *user_info)
{
	GList *l;
	GString *text;

	text = g_string_new("<span>");

	for (l = purple_notify_user_info_get_entries(user_info); l != NULL;
			l = l->next) {
		PurpleNotifyUserInfoEntry *user_info_entry = l->data;
		PurpleNotifyUserInfoEntryType type = purple_notify_user_info_entry_get_type(user_info_entry);
		const char *label = purple_notify_user_info_entry_get_label(user_info_entry);
		const char *value = purple_notify_user_info_entry_get_value(user_info_entry);

		/* Handle the label/value pair itself */
		if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER)
			g_string_append(text, "<u>");
		if (label)
			g_string_append_printf(text, "<b>%s</b>", label);
		g_string_append(text, "<span>");
		if (label && value)
			g_string_append(text, ": ");
		if (value) {
			char *strip = purple_markup_strip_html(value);
			g_string_append(text, strip);
			g_free(strip);
		}
		g_string_append(text, "</span>");
		if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER)
			g_string_append(text, "</u>");
		else if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK)
			g_string_append(text, "<HR/>");
		g_string_append(text, "<BR/>");
	}
	g_string_append(text, "</span>");

	return g_string_free(text, FALSE);
}
static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
    PurpleConversation *conv, PurpleMessageFlags flags, void *data) {
    // A workaround to avoid skipping of the first message as a result on NULL-conv:
    if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
        account, who); 
    PurpleBuddy *buddy = purple_find_buddy(account, who);
    PurplePresence *presence = purple_buddy_get_presence(buddy);
    msg_metadata_t msg;

    //Get message
    msg.text = purple_markup_strip_html(buffer);
    msg.remote_username = who;

    //LOCAL USER:
    msg.local_alias = purple_account_get_alias(account);
    msg.local_username = (char *) purple_account_get_name_for_display(account);

    //REMOTE USER (Buddy):
    //Get buddy alias
    msg.remote_alias = purple_buddy_get_alias(buddy);
    if(msg.remote_alias == NULL) msg.remote_alias = "";

    //Get buddy group
    PurpleGroup *group = purple_buddy_get_group(buddy);
    //return empty string if not in group
    msg.remote_from_group = group != NULL ? purple_group_get_name(group) : ""; 

    //Get protocol ID
    msg.protocol_id = purple_account_get_protocol_id(account);
    //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
    if(!strncmp(msg.protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) 
        msg.protocol_id += strlen(PROTOCOL_PREFIX); 

    //Get status
    PurpleStatus *status = purple_account_get_active_status(account);
    PurpleStatusType *type = purple_status_get_type(status);
    //remote
    PurpleStatus *r_status = purple_presence_get_active_status(presence);
    PurpleStatusType *r_status_type =	purple_status_get_type(r_status);

    //Get status id
    msg.local_status_id = NULL;
    msg.local_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(type));
    //remote
    msg.remote_status_id = NULL;
    msg.remote_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(r_status_type));

    //Get status message
    msg.local_status_msg = NULL;
    if (purple_status_type_get_attr(type, "message") != NULL) {
        msg.local_status_msg = purple_status_get_attr_string(status, "message");
    } else {
        PurpleSavedStatus *savedstatus = purple_savedstatus_get_current();
        if(savedstatus)
            msg.local_status_msg = purple_savedstatus_get_message(savedstatus);
    }
    //remote
    msg.remote_status_msg = NULL;
    if (purple_status_type_get_attr(r_status_type, "message") != NULL) {
        msg.remote_status_msg = purple_status_get_attr_string(r_status, "message");
    } else {
        msg.remote_status_msg = "";
    }

    run_lua(conv, msg);
}
Exemplo n.º 4
0
static void *
finch_notify_common(PurpleNotifyType ntype, PurpleNotifyMsgType msgtype,
	const char *title, const char *primary, const char *secondary)
{
	GntWidget *window, *button;
	GntTextFormatFlags pf = 0, sf = 0;

	switch (msgtype)
	{
		case PURPLE_NOTIFY_MSG_ERROR:
			sf |= GNT_TEXT_FLAG_BOLD;
			/* fall through */
		case PURPLE_NOTIFY_MSG_WARNING:
			pf |= GNT_TEXT_FLAG_UNDERLINE;
			/* fall through */
		case PURPLE_NOTIFY_MSG_INFO:
			pf |= GNT_TEXT_FLAG_BOLD;
			break;
	}

	window = gnt_window_box_new(FALSE, TRUE);
	gnt_box_set_title(GNT_BOX(window), title);
	gnt_box_set_fill(GNT_BOX(window), FALSE);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
	gnt_box_set_pad(GNT_BOX(window), 0);

	if (primary)
		gnt_box_add_widget(GNT_BOX(window),
				gnt_label_new_with_format(primary, pf));

	button = gnt_button_new(_("OK"));

	if (secondary) {
		GntWidget *msg;
		if (ntype == PURPLE_NOTIFY_FORMATTED) {
			int width = -1, height = -1;
			char *plain = (char*)secondary;
			msg = gnt_text_view_new();
			gnt_text_view_set_flag(GNT_TEXT_VIEW(msg), GNT_TEXT_VIEW_TOP_ALIGN | GNT_TEXT_VIEW_NO_SCROLL);

			plain = purple_markup_strip_html(secondary);
			if (!gnt_util_parse_xhtml_to_textview(secondary, GNT_TEXT_VIEW(msg)))
				gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(msg), plain, sf);

			gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(msg), button);
			gnt_util_get_text_bound(plain, &width, &height);
			gnt_widget_set_size(msg, width + 3, height + 1);
			if (plain != secondary)
				g_free(plain);
		} else {
			msg = gnt_label_new_with_format(secondary, sf);
		}
		gnt_box_add_widget(GNT_BOX(window), msg);
		g_object_set_data(G_OBJECT(window), "info-widget", msg);
	}

	gnt_box_add_widget(GNT_BOX(window), button);
	g_signal_connect_swapped(G_OBJECT(button), "activate",
			G_CALLBACK(gnt_widget_destroy), window);
	g_signal_connect(G_OBJECT(window), "destroy",
			G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(ntype));

	gnt_widget_show(window);
	return window;
}
Exemplo n.º 5
0
static void on_new_message(PurpleAccount *account, const char *remote,
    const char *message)
{
  const char *command = purple_prefs_get_path(PLUGIN_PREF_COMMAND);

  // the command should be never NULL
  g_return_if_fail(command);

  if (!command[0]) {
    // no command is set
    return;
  }

  const char *protocol = purple_account_get_protocol_name(account);
  char *local = g_strdup(purple_normalize(account,
        purple_account_get_username(account)));
  char *nohtml = purple_markup_strip_html(message);
  PurpleBuddy *buddy = purple_find_buddy(account, remote);
  char *icon_encoded = NULL;
  if (buddy) {
    // get buddy alias and icon
    remote = purple_buddy_get_alias(buddy);
    PurpleBuddyIcon *icon = purple_buddy_get_icon(buddy);
    if (icon) {
      size_t len;
      gconstpointer data = purple_buddy_icon_get_data(icon, &len);
      icon_encoded = g_base64_encode(data, len);
    }
  }

  char *argv[2];
  argv[0] = g_strdup(command);
  argv[1] = NULL;

  // prepare child's environment variables
  char **envp = g_get_environ();
  envp = g_environ_setenv(envp, "EVENT_TYPE", "msg", TRUE);
  envp = g_environ_setenv(envp, "EVENT_NETWORK", protocol, TRUE);
  envp = g_environ_setenv(envp, "EVENT_LOCAL_USER", local, TRUE);
  envp = g_environ_setenv(envp, "EVENT_REMOTE_USER", remote, TRUE);
  if (icon_encoded)
    envp = g_environ_setenv(envp, "EVENT_REMOTE_USER_ICON", icon_encoded, TRUE);
  envp = g_environ_setenv(envp, "EVENT_MESSAGE", nohtml, TRUE);
  envp = g_environ_setenv(envp, "EVENT_MESSAGE_HTML", message, TRUE);

  // spawn the command
  GError *err = NULL;
  if (!g_spawn_async(NULL, argv, envp, G_SPAWN_SEARCH_PATH
        | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
        NULL, &err)) {
    purple_debug_error("extaction", "%s", err->message);
    g_clear_error(&err);
  }

  // free all resources
  g_free(argv[0]);
  g_strfreev(envp);

  g_free(local);
  g_free(nohtml);
  g_free(icon_encoded);
}
Exemplo n.º 6
0
int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
  // search for outgoing embedded image tags and send them
  gchar *img = NULL;
  gchar *stripped = NULL;
  if ((img = g_strrstr (message, "<IMG")) || (img = g_strrstr (message, "<img"))) {
    if (tgl_get_peer_type(to) == TGL_PEER_ENCR_CHAT) {
      tgp_msg_err_out (TLS, "Sorry, sending documents to encrypted chats not yet supported.", to);
      return 0;
    }
    
    debug ("img found: %s", img);
    gchar *id;
    if ((id = g_strrstr (img, "ID=\"")) || (id = g_strrstr (img, "id=\""))) {
      id += 4;
      debug ("id found: %s", id);
      int imgid = atoi (id);
      if (imgid > 0) {
        PurpleStoredImage *psi = purple_imgstore_find_by_id (imgid);
        gchar *tmp = g_build_filename(g_get_tmp_dir(), purple_imgstore_get_filename (psi), NULL) ;
        GError *err = NULL;
        gconstpointer data = purple_imgstore_get_data (psi);
        g_file_set_contents (tmp, data, purple_imgstore_get_size (psi), &err);
        if (! err) {
          stripped = purple_markup_strip_html (message);
          tgl_do_send_document (TLS, to, tmp, stripped, (int)strlen (stripped), TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgp_msg_send_done, NULL);
          g_free (stripped);
          return 1;
        } else {
          failure ("Cannot store image, temp directory not available: %s\n", err->message);
          g_error_free (err);
          return 0;
        }
      }
    }
    // no image id found in image
    return 0;
  }
  
#ifndef __ADIUM_
  /*
    Adium won't escape any HTML markup and just pass any user-input through,
    while Pidgin will replace special chars with the escape chars and also add 
    additional markup for RTL languages and such.

    First, we remove any HTML markup added by Pidgin, since Telegram won't handle it properly.
    User-entered HTML is still escaped and therefore won't be harmed.
   */
  stripped = purple_markup_strip_html (message);
  
  /* 
    now unescape the markup, so that html special chars will still show
    up properly in Telegram
   */
  gchar *unescaped = purple_unescape_text (stripped);
  int ret = tgp_msg_send_split (TLS, stripped, to);
  
  g_free (unescaped);
  g_free (stripped);
  return ret;
#endif
  
  return tgp_msg_send_split (TLS, message, to);
}
Exemplo n.º 7
0
/* send a chat msg to a QQ Qun
 * called by purple */
int qq_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags)
{
	qq_data *qd;
	qq_im_format *fmt;
	gchar *msg_stripped, *tmp;
	GSList *segments, *it;
	gint msg_len;
	const gchar *start_invalid;
	gboolean is_smiley_none;
	guint8 frag_count, frag_index;

	g_return_val_if_fail(NULL != gc && NULL != gc->proto_data, -1);
	g_return_val_if_fail(id != 0 && what != NULL, -1);

	qd = (qq_data *) gc->proto_data;
	purple_debug_info("QQ", "Send chat IM to %u, len %" G_GSIZE_FORMAT ":\n%s\n", id, strlen(what), what);

	/* qq_show_packet("chat IM UTF8", (guint8 *)what, strlen(what)); */

	fmt = qq_im_fmt_new_by_purple(what);
	is_smiley_none = qq_im_smiley_none(what);

	msg_stripped = purple_markup_strip_html(what);
	g_return_val_if_fail(msg_stripped != NULL, -1);
	/* qq_show_packet("IM Stripped", (guint8 *)what, strlen(what)); */

	/* Check and valid utf8 string */
	msg_len = strlen(msg_stripped);
	if (!g_utf8_validate(msg_stripped, msg_len, &start_invalid)) {
		if (start_invalid > msg_stripped) {
			tmp = g_strndup(msg_stripped, start_invalid - msg_stripped);
			g_free(msg_stripped);
			msg_stripped = g_strconcat(tmp, _("(Invalid UTF-8 string)"), NULL);
			g_free(tmp);
		} else {
			g_free(msg_stripped);
			msg_stripped = g_strdup(_("(Invalid UTF-8 string)"));
		}
	}

	is_smiley_none = qq_im_smiley_none(what);
	segments = qq_im_get_segments(msg_stripped, is_smiley_none);
	g_free(msg_stripped);

	if (segments == NULL) {
		return -1;
	}

	qd->send_im_id++;
	fmt = qq_im_fmt_new_by_purple(what);
	frag_count = g_slist_length(segments);
	frag_index = 0;
/*
	if (frag_count <= 1) {
*/
		for (it = segments; it; it = it->next) {
			request_room_send_im(gc, id, fmt, (gchar *)it->data);
			g_free(it->data);
		}
/*
	} else {
		for (it = segments; it; it = it->next) {
			request_room_send_im_ex(gc, id, fmt, (gchar *)it->data,
					qd->send_im_id, frag_count, frag_index);
			g_free(it->data);
			frag_index++;
		}
	}
*/
	qq_im_fmt_free(fmt);
	g_slist_free(segments);
	return 1;
}
Exemplo n.º 8
0
void Notify::UserInfoDialog::update(PurpleConnection *gc, const char *who,
    PurpleNotifyUserInfo *user_info)
{
  treeview->clear();
  CppConsUI::TreeView::NodeReference parent;
  CppConsUI::Button *button;

  // local information
  PurpleAccount *account = purple_connection_get_account(gc);
  PurpleBuddy *buddy = purple_find_buddy(account, who);
  if (buddy) {
    /* Note that we should always be able to find the specified buddy, unless
     * something goes very wrong. */
    button = new CppConsUI::TreeView::ToggleCollapseButton(
        _("Local information"));
    parent = treeview->appendNode(treeview->getRootNode(), *button);

    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Alias"), purple_buddy_get_alias(buddy));
    treeview->appendNode(parent, *button);

    time_t saved_time;
    struct tm local_time;
    const char *formatted_time;

    // last_seen
    if (PURPLE_BUDDY_IS_ONLINE(buddy))
      formatted_time = _("Now");
    else {
      saved_time = static_cast<time_t>(purple_blist_node_get_int(
            PURPLE_BLIST_NODE(buddy), "last_seen"));
      if (saved_time && localtime_r(&saved_time, &local_time))
        formatted_time = purple_date_format_long(&local_time);
      else
        formatted_time = _("Unknown");
    }
    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Last seen"), formatted_time);
    treeview->appendNode(parent, *button);

    // last_activity
    saved_time = static_cast<time_t>(purple_blist_node_get_int(
          PURPLE_BLIST_NODE(buddy), "last_activity"));
    if (saved_time && localtime_r(&saved_time, &local_time))
      formatted_time = purple_date_format_long(&local_time);
    else
      formatted_time = _("Unknown");
    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Last activity"), formatted_time);
    treeview->appendNode(parent, *button);
  }

  // remote information
  button = new CppConsUI::TreeView::ToggleCollapseButton(
      _("Remote information"));
  parent = treeview->appendNode(treeview->getRootNode(), *button);
  CppConsUI::TreeView::NodeReference subparent = parent;
  for (GList *i = purple_notify_user_info_get_entries(user_info); i;
      i = i->next) {
    PurpleNotifyUserInfoEntry *entry
      = reinterpret_cast<PurpleNotifyUserInfoEntry*>(i->data);
    PurpleNotifyUserInfoEntryType type
      = purple_notify_user_info_entry_get_type(entry);

    const char *label = purple_notify_user_info_entry_get_label(entry);
    if (!label)
      continue;
    const char *value = purple_notify_user_info_entry_get_value(entry);
    char *nohtml = purple_markup_strip_html(value);
    switch (type) {
      case PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR:
        button = new CppConsUI::Button(
            nohtml ? CppConsUI::Button::FLAG_VALUE : 0, label, nohtml);
        treeview->appendNode(subparent, *button);
        break;
      case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK:
        // ignore section breaks
        break;
      case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER:
        button = new CppConsUI::TreeView::ToggleCollapseButton(label);
        subparent = treeview->appendNode(parent, *button);
        break;
      default:
        LOG->error(_("Unhandled userinfo entry type '%d'."), type);
        break;
    }
    g_free(nohtml);
  }

  treeview->grabFocus();
}
Exemplo n.º 9
0
static int 
pb_send_im(PurpleConnection *pc, const gchar *who, const gchar *message, PurpleMessageFlags flags)
{
	PushBulletAccount *pba = pc->proto_data;
	gchar *stripped, *postdata;
	gchar *guid;
	
	if (g_str_has_prefix(message, "?OTR"))
		return 0;
	
	if (PB_IS_SMS(who))
	{
		JsonObject *root = json_object_new();
		JsonObject *data = json_object_new();
		JsonArray *addresses = json_array_new();
		
		json_array_add_string_element(addresses, who);
		json_object_set_array_member(data, "addresses", addresses);
		
		guid = pb_get_next_id(pba);
		json_object_set_string_member(data, "guid", guid);
		json_object_set_string_member(data, "target_device_iden", pba->main_sms_device);
		json_object_set_boolean_member(data, "encrypted", FALSE);
		
		stripped = g_strstrip(purple_markup_strip_html(message));
		json_object_set_string_member(data, "message", stripped);
		g_free(stripped);
		
		json_object_set_object_member(root, "data", data);
		
		postdata = pb_jsonobj_to_string(root);
		pb_fetch_url(pba, "https://api.pushbullet.com/v3/create-text", postdata, NULL, NULL);
		g_free(postdata);
		
		json_object_unref(root);
		
		g_hash_table_insert(pba->sent_messages_hash, guid, guid);
		return 1;
	}
	
	if (!strchr(who, '@')) {
		return -1;
	}
	
	//<IMG ID="5"> - embedded image i.e. MMS
	
	/* Image flow:
	POST to https://api.pushbullet.com/v3/start-upload {"name":"imagename.jpg","size":12345,"type":"image/jpeg"}
	=> {"id":"abcde","piece_size":5242880,"piece_urls":["https://upload.pushbullet.com/upload-piece/12345/0"]}
	
	POST data in chunks to the pieces_urls
	
	POST to https://api.pushbullet.com/v3/finish-upload {"id":"abcde"} (from earlier)
	=> {"file_name":"imagename.jpg","file_type":"image/jpeg","file_url":"..urltoimage..."}
	
	POST to https://api.pushbullet.com/v2/pushes {"type":"file","file_name":"filename.jpg","file_url":"..urltoimage...","file_type":"image/jpeg","email":"touser"}
	*/
	
	{
		JsonObject *root = json_object_new();
		
		guid = pb_get_next_id(pba);
		json_object_set_string_member(root, "guid", guid);
		json_object_set_string_member(root, "type", "note");
		json_object_set_string_member(root, "title", "");
		json_object_set_string_member(root, "url", "");
		json_object_set_string_member(root, "email", who);
		
		stripped = g_strstrip(purple_markup_strip_html(message));
		json_object_set_string_member(root, "body", stripped);
		g_free(stripped);
		
		postdata = pb_jsonobj_to_string(root);
		pb_fetch_url(pba, "https://api.pushbullet.com/v2/pushes", postdata, NULL, NULL);
		g_free(postdata);
		
		json_object_unref(root);
		
		g_hash_table_insert(pba->sent_messages_hash, guid, guid);
		return 1;
	}
	
	return -1;
}
Exemplo n.º 10
0
/*--------------------------------------------------------------------------*
 * PUBLIC FUNCTIONS                                                         *
 *--------------------------------------------------------------------------*/
void ap_gtk_add_message (APUpdateType update_type, APMessageType type, 
                const gchar *text) 
{
  GtkTreeIter iter;
  struct tm *cur_time;
  char *time_string, *simple_text, *s;
  time_t *general_time;
  gchar *type_string;
  
  // Create the time string 
  general_time = (time_t *) malloc (sizeof(time_t));
  time (general_time);
  cur_time = ap_localtime (general_time);
  free (general_time);

  time_string = (char *) malloc (sizeof(char[32]));
  *time_string = '\0';

  strftime (time_string, 31, "<b>%I:%M %p</b>", cur_time);
  free (cur_time);
 
  // Create the type string
  type_string = strdup("<b>Status</b>");
  switch (type) {
    case AP_MESSAGE_TYPE_PROFILE:
      type_string = strdup (_("<b>User profile</b>"));
      break;
    case AP_MESSAGE_TYPE_AWAY:
      type_string = strdup (_("<b>Away message</b>"));
      break;
    case AP_MESSAGE_TYPE_AVAILABLE:
      type_string = strdup (_("<b>Available message</b>"));
      break;
    case AP_MESSAGE_TYPE_STATUS:
      type_string = strdup (_("<b>Status message</b>"));
      break;
    default:
      type_string = strdup (_("<b>Other</b>"));
      break;
  }

  // Simplify the text
  if (text != NULL) {
    simple_text = strdup (text);

    // Only show the first line 
    s = (gchar *) purple_strcasestr (simple_text, "<br>");
    if (s != NULL) {
      *s++ = '.';
      *s++ = '.';
      *s++ = '.';
      *s   = '\0';
    }

    // Strip HTML
    s = simple_text;
    simple_text = purple_markup_strip_html (simple_text);
    free (s);
    
  } else {
    simple_text = NULL;
  }  

  // Add it 
  gtk_list_store_prepend (message_list, &iter);
  gtk_list_store_set (message_list, &iter,
                      0, time_string,
                      1, type_string,
                      2, simple_text,
                      3, text,
                      -1);
  free (type_string);
  free (time_string);
  if (simple_text) free (simple_text);

  // Delete if too many
  if (gtk_tree_model_iter_nth_child 
        (GTK_TREE_MODEL(message_list), &iter, NULL, 
         AP_GTK_MAX_MESSAGES)) {
    gtk_list_store_remove (message_list, &iter);
  }

  // Move the timeout bar
  ap_gtk_timeout_start (update_type);

  // Check if it needs to be visible or not
  if (type != AP_MESSAGE_TYPE_PROFILE && 
      ap_is_currently_away () != ap_previously_away) {
    update_summary_visibility ();
  }
}
Exemplo n.º 11
0
gint qq_send_im(PurpleConnection *gc, const gchar *who, const gchar *what, PurpleMessageFlags flags)
{
	qq_data *qd;
	guint32 uid_to;
	gint type;
	qq_im_format *fmt;
	gchar *msg_stripped, *tmp;
	GSList *segments, *it;
	gint msg_len;
	const gchar *start_invalid;
	gboolean is_smiley_none;
	guint8 frag_count, frag_index;
	guint8 msg_id;

	g_return_val_if_fail(NULL != gc && NULL != gc->proto_data, -1);
	g_return_val_if_fail(who != NULL && what != NULL, -1);

	qd = (qq_data *) gc->proto_data;
	purple_debug_info("QQ", "Send IM to %s, len %" G_GSIZE_FORMAT ":\n%s\n", who, strlen(what), what);

	uid_to = purple_name_to_uid(who);
	if (uid_to == qd->uid) {
		/* if msg is to myself, bypass the network */
		serv_got_im(gc, who, what, flags, time(NULL));
		return 1;
	}

	type = (flags == PURPLE_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT);
	/* qq_show_packet("IM UTF8", (guint8 *)what, strlen(what)); */

	msg_stripped = purple_markup_strip_html(what);
	g_return_val_if_fail(msg_stripped != NULL, -1);
	/* qq_show_packet("IM Stripped", (guint8 *)what, strlen(what)); */

	/* Check and valid utf8 string */
	msg_len = strlen(msg_stripped);
	g_return_val_if_fail(msg_len > 0, -1);
	if (!g_utf8_validate(msg_stripped, msg_len, &start_invalid)) {
		if (start_invalid > msg_stripped) {
			tmp = g_strndup(msg_stripped, start_invalid - msg_stripped);
			g_free(msg_stripped);
			msg_stripped = g_strconcat(tmp, _("(Invalid UTF-8 string)"), NULL);
			g_free(tmp);
		} else {
			g_free(msg_stripped);
			msg_stripped = g_strdup(_("(Invalid UTF-8 string)"));
		}
	}

	is_smiley_none = qq_im_smiley_none(what);
	segments = qq_im_get_segments(msg_stripped, is_smiley_none);
	g_free(msg_stripped);

	if (segments == NULL) {
		return -1;
	}

	qd->send_im_id++;
	msg_id = (guint8)(qd->send_im_id && 0xFF);
	fmt = qq_im_fmt_new_by_purple(what);
	frag_count = g_slist_length(segments);
	frag_index = 0;
	for (it = segments; it; it = it->next) {
		/*
		request_send_im(gc, uid_to, type, fmt, (gchar *)it->data,
			msg_id, frag_count, frag_index);
		*/
		request_send_im(gc, uid_to, type, fmt, (gchar *)it->data, 0, 0, 0);
		g_free(it->data);
		frag_index++;
	}
	g_slist_free(segments);
	qq_im_fmt_free(fmt);
	return 1;
}
Exemplo n.º 12
0
static void fb_check_friend_request_cb(FacebookAccount *fba, gchar *data,
		gsize data_len, gpointer user_data)
{
	const char *uid_pre_text = "class=\"confirm\" id=\"friend_add_";
	const char *name_pre_text = "<td class=\"info\"><a ";
	const char *msg_pre_text = "<div class=\"personal_msg\"><span>";
	gchar *uid;
	gint32 uid_int;
	gchar *name;
	gchar *msg;
	gchar *msg_plain;
	FacebookBuddy *buddy;
	gchar *search_start = data;

	/* loop through the data and look for confirm_friend_add_([0-9]*)" */
	while ((search_start = strstr(search_start, uid_pre_text)))
	{
		search_start += strlen(uid_pre_text);
		uid = g_strndup(search_start,
				strchr(search_start, '"') - search_start);
		purple_debug_info("facebook", "uid: %s\n", uid);

		uid_int = atoi(uid);

		if (g_slist_find(fba->auth_buddies,
				GINT_TO_POINTER(uid_int)) != NULL)
		{
			/* we've already notified the user of this friend request */
			g_free(uid);
			continue;
		}

		name = strstr(search_start, name_pre_text);
		if (name != NULL)
		{
			name += strlen(name_pre_text);
			name = strchr(name, '>') + 1;
			name = g_strndup(name, strchr(name, '<') - name);
			purple_debug_info("facebook", "name: %s\n", name);
		} else {
			name = NULL;
		}

		msg = strstr(search_start, msg_pre_text);
		if (msg != NULL)
		{
			msg += strlen(msg_pre_text);
			msg = g_strndup(msg, strstr(msg, "</span></div>") - msg);
			msg_plain = purple_markup_strip_html(msg);
			g_free(msg);
			purple_debug_info("facebook", "msg: %s\n", msg_plain);
		} else {
			msg_plain = NULL;
		}

		buddy = g_new0(FacebookBuddy, 1);
		buddy->fba = fba;
		buddy->uid = uid_int;
		purple_account_request_authorization(
				fba->account, uid, NULL,
				name, msg_plain, TRUE,
				fb_auth_accept_cb, fb_auth_reject_cb, buddy);

		g_free(uid);
		/* TODO: msg_plain might be leaking here? */

		/* Don't display an auth request for this buddy again */
		fba->auth_buddies = g_slist_prepend(
				fba->auth_buddies, GINT_TO_POINTER(uid_int));
	}
}
Exemplo n.º 13
0
gchar* coincoin_convert_message(CoinCoinAccount* cca, const char* msg)
{
	GString* s;
	const gchar *start, *next;

	gchar* _msg = purple_markup_strip_html(msg);

	if(purple_account_get_bool(cca->account, "no_reformat_messages", FALSE))
		return _msg;

	s = g_string_sized_new(strlen(_msg));

	for(start = _msg; *start; start = next)
	{
		next = g_utf8_next_char(start);
		while(*next && *next != ' ')
			next = g_utf8_next_char(next);

		if(next > start+2 && *next && next[-1] == ':')
		{
			unsigned ref = 1;
			const gchar *end = start;
			gchar *nickname;

			while(*end && *end != ':' && *end != '\xc2')
				end = g_utf8_next_char(end);

			nickname = g_strndup(start, end-start);
			if (*end == ':')
				++end;
			if(*end >= '0' && *end <= '9')
			{
				ref = strtoul(end, NULL, 10);
			}
			else if(*end == '\xc2')
			{
				if(end[1] == '\xb9') ref = 1;       // ¹
				else if(end[1] == '\xb2') ref = 2;  // ²
				else if(end[1] == '\xb3') ref = 3;  // ³
			}

			GSList *m;
			CoinCoinMessage* cur = NULL;
			unsigned found = 0;
			for(m = cca->messages; m; m = m->next)
			{
				cur = m->data;
				if (!strcasecmp(cur->from, nickname) && ++found == ref)
					break;
			}
			g_free(nickname);
			if(m)
			{
				struct tm t;
				localtime_r(&cur->timestamp, &t);
				g_string_append_printf(s, "%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
				if (cur->multiple)
					g_string_append_printf(s, ":%d", cur->ref);
				continue;
			}
		}
		if(*next == ' ')
			next = g_utf8_next_char(next);

		g_string_append_len(s, start, next-start);
	}
	g_free(_msg);
	return g_string_free(s, FALSE);
}