Ejemplo n.º 1
0
static void netsoul_got_photo (PurpleUtilFetchUrlData *url, void *user_data,
			       const char *photo, size_t len, const char *error_msg)
{
  PurpleBuddy *gb = user_data;
  PurpleAccount *account = purple_buddy_get_account (gb);

  // Check if connection is still existing
  PurpleConnection *gc = purple_account_get_connection (account);
  if (gc == NULL)
    return;

  purple_debug_info("netsoul", "netsoul_got_photo (size: %d) for %s\n",
		    len,
		    gb->name);

  /* Try to put the photo in , if there's one and is readable */
  if (user_data && photo && len != 0)
  {
    if (strstr(photo, "400 Bad Request")
	|| strstr(photo, "403 Forbidden")
	|| strstr(photo, "404 Not Found"))
      purple_debug_info("netsoul", "netsoul_got_photo: error: %s\n", photo);
    else
    {
      PurpleStoredImage *img = purple_imgstore_add(g_memdup(photo, len), len, NULL);
      PurpleBuddyIcon *icon = purple_buddy_icon_new(account, gb->name,
						    purple_imgstore_get_data(img),
						    purple_imgstore_get_size(img),
						    NULL);
      purple_buddy_set_icon(gb, icon);
    }
  }
}
Ejemplo n.º 2
0
PurpleStoredImage *
purple_imgstore_new_from_file(const char *path)
{
	gchar *data = NULL;
	size_t len;
	GError *err = NULL;

	g_return_val_if_fail(path != NULL && *path != '\0', NULL);

	if (!g_file_get_contents(path, &data, &len, &err)) {
		purple_debug_error("imgstore", "Error reading %s: %s\n",
				path, err->message);
		g_error_free(err);
		return NULL;
	}
	return purple_imgstore_add(data, len, path);
}
Ejemplo n.º 3
0
int
purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename)
{
	PurpleStoredImage *img = purple_imgstore_add(data, size, filename);
	if (!img) {
		return 0;
	}

	/*
	 * Use the next unused id number.  We do it in a loop on the
	 * off chance that nextid wraps back around to 0 and the hash
	 * table still contains entries from the first time around.
	 */
	do {
		img->id = ++nextid;
	} while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL);

	g_hash_table_insert(imgstore, &(img->id), img);

	return img->id;
}
Ejemplo n.º 4
0
static PurpleStoredImage *
purple_smiley_data_new(guchar *smiley_data, size_t smiley_data_len)
{
	char *filename;
	PurpleStoredImage *stored_img;

	g_return_val_if_fail(smiley_data != NULL,   NULL);
	g_return_val_if_fail(smiley_data_len  > 0,  NULL);

	filename = purple_util_get_image_filename(smiley_data, smiley_data_len);

	if (filename == NULL) {
		g_free(smiley_data);
		return NULL;
	}

	stored_img = purple_imgstore_add(smiley_data, smiley_data_len, filename);

	g_free(filename);

	return stored_img;
}
Ejemplo n.º 5
0
static PurpleStoredImage *
purple_buddy_icon_data_new(guchar *icon_data, size_t icon_len, const char *filename)
{
	char *file;
	PurpleStoredImage *img;

	g_return_val_if_fail(icon_data != NULL, NULL);
	g_return_val_if_fail(icon_len  > 0,     NULL);

	if (filename == NULL)
	{
		file = purple_util_get_image_filename(icon_data, icon_len);
		if (file == NULL)
		{
			g_free(icon_data);
			return NULL;
		}
	}
	else
		file = g_strdup(filename);

	if ((img = g_hash_table_lookup(icon_data_cache, file)))
	{
		g_free(file);
		g_free(icon_data);
		return purple_imgstore_ref(img);
	}

	img = purple_imgstore_add(icon_data, icon_len, file);

	/* This will take ownership of file and g_free it either now or later. */
	g_hash_table_insert(icon_data_cache, file, img);

	purple_buddy_icon_data_cache(img);

	return img;
}
Ejemplo n.º 6
0
int PurpleLine::send_message(std::string to, const char *markup) {
    // Parse markup and send message as parts if it contains images

    bool any_sent = false;
	std::cout << "debug ---> " << std::endl;
	std::cout << to << std::endl;
	std::cout << markup << std::endl;

    for (const char *p = markup; p && *p; ) {
        const char *start, *end;
		const char *filestart, *fileend;
        GData *attributes;
		GData *fileattributes;

		std::cout << "Sending LINE Message..." << std::endl;
        bool img_found = purple_markup_find_tag("IMG", p, &start, &end, &attributes);
		bool imgfile_found = purple_markup_find_tag("FILE", p, &filestart, &fileend, &fileattributes);
		std::cout << "---Image file ? " << std::endl;
		std::cout << img_found << std::endl;
		std::cout << imgfile_found << std::endl;

        std::string text;

        if (img_found) {
            // Image found but there's text before it, store it

            text = std::string(p, start - p);
            p = end + 1;
        } else {
            // No image found, store the rest of the text

            text = std::string(p);

            // Break the loop

            p = NULL;
        }

        // If the text is not all whitespace, send it as a text message
        if (text.find_first_not_of("\t\n\r ") != std::string::npos && !imgfile_found)
        {
            line::Message msg;

            msg.contentType = line::ContentType::NONE;
            msg.from = profile.mid;
            msg.to = to;
            msg.text = markup_unescape(text);

            send_message(msg);

            any_sent = true;
        }

		if (imgfile_found) {
			std::cout << "Start upload file!!" << std::endl;
			char *path = (char *)g_datalist_get_data(&fileattributes, "path");
			std::cout << path << std::endl;

			gchar *data = NULL;
			size_t len;
			GError *err = NULL;

			if (!g_file_get_contents(path, &data, &len, &err))
			{
				std::cout << "Error get file contents!!" << std::endl;
				continue;
			}
			std::cout << "Success get file content!!" << std::endl;

			PurpleStoredImage *img =
				purple_imgstore_add(data, len, path);
			if (!img)
			{
				std::cout << "Error image stored add!!" << std::endl;
				continue;
			}
			std::cout << "Success image stored add!!" << std::endl;
			std::string img_data(
					(const char *)purple_imgstore_get_data(img),
					purple_imgstore_get_size(img));

            line::Message msg;
            msg.contentType = line::ContentType::IMAGE;
            msg.from = profile.mid;
            msg.to = to;

			send_message(msg, [this, img_data](line::Message &msg_back) {
				upload_media(msg_back.id, "image", img_data);
			});

            any_sent = true;
		}

        if (img_found) {
            // Image test

            int image_id = std::stoi((char *)g_datalist_get_data(&attributes, "id"));
            g_datalist_clear(&attributes);

            std::stringstream ss;
            ss << "(img ID: " << image_id << ")";

            PurpleStoredImage *img = purple_imgstore_find_by_id(image_id);
            if (!img) {
                purple_debug_warning("line", "Tried to send non-existent image: %d\n", image_id);
                continue;
            }

            std::string img_data(
                (const char *)purple_imgstore_get_data(img),
                purple_imgstore_get_size(img));

            line::Message msg;

            msg.contentType = line::ContentType::IMAGE;
            msg.from = profile.mid;
            msg.to = to;

            send_message(msg, [this, img_data](line::Message &msg_back) {
                upload_media(msg_back.id, "image", img_data);
            });

            any_sent = true;
        }
    }

    return any_sent ? 1 : 0;
}