static void waprpl_set_buddy_icon(PurpleConnection * gc, PurpleStoredImage * img) { /* Send the picture the user has selected! */ whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); size_t size = purple_imgstore_get_size(img); const void *data = purple_imgstore_get_data(img); if (data) { // First of all make the picture a square char * sqbuffer; int sqsize; imgProfile(data, size, (void**)&sqbuffer, &sqsize, 640); char * pbuffer; int osize; imgProfile(data, size, (void**)&pbuffer, &osize, 96); waAPI_setavatar(wconn->waAPI, sqbuffer, sqsize, pbuffer, osize); free(sqbuffer); free(pbuffer); } else { waAPI_setavatar(wconn->waAPI, 0,0,0,0); } waprpl_check_output(gc); }
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); } } }
static void request_own_user_display(MsnUser *user) { PurpleAccount *account; MsnSession *session; MsnObject *my_obj = NULL; gconstpointer data = NULL; const char *info = NULL; size_t len = 0; if (purple_debug_is_verbose()) purple_debug_info("msn", "Requesting our own user display\n"); session = user->userlist->session; account = session->account; my_obj = msn_user_get_object(user); if (my_obj != NULL) { PurpleStoredImage *img = msn_object_get_image(my_obj); data = purple_imgstore_get_data(img); len = purple_imgstore_get_size(img); info = msn_object_get_sha1(my_obj); } purple_buddy_icons_set_for_user(account, user->passport, g_memdup(data, len), len, info); /* Free one window slot */ session->userlist->buddy_icon_window++; if (purple_debug_is_verbose()) purple_debug_info("msn", "msn_request_user_display(): buddy_icon_window++ yields =%d\n", session->userlist->buddy_icon_window); msn_release_buddy_icon_request(session->userlist); }
static void purple_buddy_icon_data_cache(PurpleStoredImage *img) { const char *dirname; char *path; g_return_if_fail(img != NULL); if (!purple_buddy_icons_is_caching()) return; dirname = purple_buddy_icons_get_cache_dir(); path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { purple_debug_info("buddyicon", "Creating icon cache directory.\n"); if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { purple_debug_error("buddyicon", "Unable to create directory %s: %s\n", dirname, g_strerror(errno)); } } if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) { purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); } g_free(path); }
static void waprpl_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) { // Send the picture the user has selected! whatsapp_connection * wconn = purple_connection_get_protocol_data(gc); size_t size = purple_imgstore_get_size(img); const void * data = purple_imgstore_get_data(img); waAPI_setavatar(wconn->waAPI, data, size); waprpl_check_output(gc); }
/*------------------------------------------------------------------------ * Set or clear our Buddy icon. * * @param gc The connection object * @param img The buddy icon data */ static void mxit_set_buddy_icon( PurpleConnection *gc, PurpleStoredImage *img ) { struct MXitSession* session = purple_connection_get_protocol_data( gc ); if ( img == NULL ) mxit_set_avatar( session, NULL, 0 ); else mxit_set_avatar( session, purple_imgstore_get_data( img ), purple_imgstore_get_size( img ) ); }
void msn_slpmsg_set_image(MsnSlpMessage *slpmsg, PurpleStoredImage *img) { /* We can only have one data source at a time. */ g_return_if_fail(slpmsg->buffer == NULL); g_return_if_fail(slpmsg->img == NULL); g_return_if_fail(slpmsg->ft == FALSE); slpmsg->img = purple_imgstore_ref(img); slpmsg->buffer = (guchar *)purple_imgstore_get_data(img); slpmsg->size = purple_imgstore_get_size(img); }
gconstpointer purple_smiley_get_data(const PurpleSmiley *smiley, size_t *len) { g_return_val_if_fail(smiley != NULL, NULL); if (smiley->img) { if (len != NULL) *len = purple_imgstore_get_size(smiley->img); return purple_imgstore_get_data(smiley->img); } return NULL; }
gconstpointer purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len) { g_return_val_if_fail(icon != NULL, NULL); if (icon->img) { if (len != NULL) *len = purple_imgstore_get_size(icon->img); return purple_imgstore_get_data(icon->img); } return NULL; }
static void purple_smiley_data_store(PurpleStoredImage *stored_img) { const char *dirname; char *path; FILE *file = NULL; g_return_if_fail(stored_img != NULL); if (!smileys_loaded) return; dirname = purple_smileys_get_storing_dir(); path = g_build_filename(dirname, purple_imgstore_get_filename(stored_img), NULL); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { purple_debug_info(SMILEYS_LOG_ID, "Creating smileys directory.\n"); if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { purple_debug_error(SMILEYS_LOG_ID, "Unable to create directory %s: %s\n", dirname, g_strerror(errno)); } } if ((file = g_fopen(path, "wb")) != NULL) { if (!fwrite(purple_imgstore_get_data(stored_img), purple_imgstore_get_size(stored_img), 1, file)) { purple_debug_error(SMILEYS_LOG_ID, "Error writing %s: %s\n", path, g_strerror(errno)); } else { purple_debug_info(SMILEYS_LOG_ID, "Wrote cache file: %s\n", path); } fclose(file); } else { purple_debug_error(SMILEYS_LOG_ID, "Unable to create file %s: %s\n", path, g_strerror(errno)); g_free(path); return; } g_free(path); }
gconstpointer purple_smiley_get_data(const PurpleSmiley *smiley, size_t *len) { PurpleSmileyPrivate *priv = NULL; g_return_val_if_fail(smiley != NULL, NULL); priv = PURPLE_SMILEY_GET_PRIVATE(smiley); if (priv->img) { if (len != NULL) *len = purple_imgstore_get_size(priv->img); return purple_imgstore_get_data(priv->img); } return NULL; }
void UploadPortrait(gpointer data, gint source, const gchar * error_message) { struct fetion_account_data *sip = data; PurpleStoredImage *img = sip->icon; gchar *head; gchar *buf; gint head_len; gint ret, lenth, writed; gconstpointer img_data = purple_imgstore_get_data(img); size_t size = purple_imgstore_get_size(img); head = g_strdup_printf("POST /%s/setportrait.aspx HTTP/1.1\r\n" "User-Agent: IIC2.0/PC 3.3.0370\r\n" "Content-Type: image/jpeg\r\n" "Host: %s\r\n" "Cookie: ssic=%s\r\n" "Content-Length: %d\r\n\r\n", sip->UploadPrefix, sip->UploadServer, sip->ssic, size); purple_debug_info("fetion:", "UploadPortrait:head[%s][%d]\n", head, size); head_len = strlen(head); buf = g_malloc(head_len + size); memcpy(buf, head, head_len); memcpy(buf + head_len, img_data, size); lenth = size + strlen(head); writed = 0; ret = write(source, buf, lenth); if (ret < 0 && errno == EAGAIN) ret = 0; g_return_if_fail(ret >= 0); if (ret < lenth) { purple_circ_buffer_append(sip->icon_buf, buf + ret, lenth - ret); sip->icon_handler = purple_input_add(source, PURPLE_INPUT_WRITE, (PurpleInputFunction) UploadPortrait_cb, sip); } g_free(head); sip->icon = NULL; purple_imgstore_unref(img); }
void msn_session_finish_login (MsnSession *session) { PurpleAccount *account; PurpleStoredImage *img; if (session->logged_in) return; account = msn_session_get_user_data (session); #ifdef HAVE_LIBPURPLE sync_users (session); #endif img = purple_buddy_icons_find_account_icon (account); { struct pn_buffer *image; if (img) image = pn_buffer_new_memdup ((const gpointer) purple_imgstore_get_data (img), purple_imgstore_get_size (img)); else image = NULL; pn_contact_set_buddy_icon (session->user, image); } purple_imgstore_unref (img); session->logged_in = TRUE; /** @todo move this to msn.c */ pn_update_status (session); pn_update_personal_message (session); pn_timeout_tune_status (session); { PurpleConnection *connection; connection = purple_account_get_connection (account); purple_connection_set_state (connection, PURPLE_CONNECTED); } pn_contactlist_check_pending (session->contactlist); }
ggp_image_prepare_result ggp_image_prepare(PurpleConversation *conv, const int stored_id, uint64_t *id) { PurpleConnection *gc = purple_conversation_get_connection(conv); ggp_image_session_data *sdata = ggp_image_get_sdata(gc); PurpleStoredImage *image = purple_imgstore_find_by_id(stored_id); size_t image_size; gconstpointer image_data; uint32_t image_crc; ggp_image_sent *sent_image; if (!image) { purple_debug_error("gg", "ggp_image_prepare: image %d " "not found in image store\n", stored_id); return GGP_IMAGE_PREPARE_FAILURE; } image_size = purple_imgstore_get_size(image); if (image_size > GGP_IMAGE_SIZE_MAX) { purple_debug_warning("gg", "ggp_image_prepare: image " "is too big (max bytes: %d)\n", GGP_IMAGE_SIZE_MAX); return GGP_IMAGE_PREPARE_TOO_BIG; } purple_imgstore_ref(image); image_data = purple_imgstore_get_data(image); image_crc = gg_crc32(0, image_data, image_size); purple_debug_info("gg", "ggp_image_prepare: image prepared " "[id=%d, crc=%u, size=%" G_GSIZE_FORMAT "]\n", stored_id, image_crc, image_size); *id = ggp_image_params_to_id(image_crc, image_size); sent_image = g_new(ggp_image_sent, 1); sent_image->id = stored_id; sent_image->conv_name = g_strdup(purple_conversation_get_name(conv)); g_hash_table_insert(sdata->sent_images, ggp_uint64dup(*id), sent_image); return GGP_IMAGE_PREPARE_OK; }
void bonjour_dns_sd_update_buddy_icon(BonjourDnsSd *data) { PurpleStoredImage *img; if ((img = purple_buddy_icons_find_account_icon(data->account))) { gconstpointer avatar_data; gsize avatar_len; avatar_data = purple_imgstore_get_data(img); avatar_len = purple_imgstore_get_size(img); if (_mdns_set_buddy_icon_data(data, avatar_data, avatar_len)) { /* The filename is a SHA-1 hash of the data (conveniently what we need) */ const char *p, *filename = purple_imgstore_get_filename(img); g_free(data->phsh); data->phsh = NULL; /* Get rid of the extension */ p = strchr(filename, '.'); if (p) data->phsh = g_strndup(filename, p - filename); else purple_debug_error("bonjour", "account buddy icon returned unexpected filename (%s)" "; unable to extract hash. Clearing buddy icon\n", filename); /* Update our TXT record */ publish_presence(data, PUBLISH_UPDATE); } purple_imgstore_unref(img); } else { /* We need to do this regardless of whether data->phsh is set so that we * cancel any icons that are currently in the process of being set */ _mdns_set_buddy_icon_data(data, NULL, 0); if (data->phsh != NULL) { /* Clear the buddy icon */ g_free(data->phsh); data->phsh = NULL; /* Update our TXT record */ publish_presence(data, PUBLISH_UPDATE); } } }
void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img) { SilcPurple sg = gc->proto_data; SilcClient client = sg->client; SilcClientConnection conn = sg->conn; SilcMime mime; char type[32]; unsigned char *icon; const char *t; SilcAttributeObjMime obj; /* Remove */ if (!img) { silc_client_attribute_del(client, conn, SILC_ATTRIBUTE_USER_ICON, NULL); return; } /* Add */ mime = silc_mime_alloc(); if (!mime) return; t = purple_imgstore_get_extension(img); if (!t || purple_strequal(t, "icon")) { silc_mime_free(mime); return; } if (purple_strequal(t, "jpg")) t = "jpeg"; g_snprintf(type, sizeof(type), "image/%s", t); silc_mime_add_field(mime, "Content-Type", type); silc_mime_add_data(mime, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); obj.mime = icon = silc_mime_encode(mime, &obj.mime_len); if (obj.mime) silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_USER_ICON, &obj, sizeof(obj)); silc_free(icon); silc_mime_free(mime); }
/*------------------------------------------------------------------------ * Insert an inline image command. * * @param mx The message text as processed so far. * @oaram id The imgstore ID of the inline image. */ static void inline_image_add( GString* mx, int id ) { PurpleStoredImage *image; gconstpointer img_data; gsize img_size; gchar* enc; image = purple_imgstore_find_by_id( id ); if ( image == NULL ) return; img_data = purple_imgstore_get_data( image ); img_size = purple_imgstore_get_size( image ); enc = purple_base64_encode( img_data, img_size ); g_string_append( mx, "::op=img|dat=" ); g_string_append( mx, enc ); g_string_append_c( mx, ':' ); g_free( enc ); }
static void purple_smiley_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *spec) { PurpleSmiley *smiley = PURPLE_SMILEY(object); PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley); switch (param_id) { case PROP_SHORTCUT: { const char *shortcut = g_value_get_string(value); purple_smiley_set_shortcut(smiley, shortcut); } break; case PROP_IMGSTORE: { PurpleStoredImage *img = g_value_get_pointer(value); purple_imgstore_unref(priv->img); g_free(priv->checksum); priv->img = img; if (img) { priv->checksum = g_compute_checksum_for_data( G_CHECKSUM_SHA1, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); purple_smiley_data_store(img); } else { priv->checksum = NULL; } } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, spec); break; } }
static void purple_smiley_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *spec) { PurpleSmiley *smiley = PURPLE_SMILEY(object); switch (param_id) { case PROP_SHORTCUT: { const char *shortcut = g_value_get_string(value); purple_smiley_set_shortcut(smiley, shortcut); } break; case PROP_IMGSTORE: { PurpleStoredImage *img = g_value_get_pointer(value); purple_imgstore_unref(smiley->img); g_free(smiley->checksum); smiley->img = img; if (img) { smiley->checksum = purple_util_get_image_checksum( purple_imgstore_get_data(img), purple_imgstore_get_size(img)); purple_smiley_data_store(img); } else { smiley->checksum = NULL; } g_object_notify(object, PROP_IMGSTORE_S); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, spec); break; } }
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; }
void ggp_image_send(PurpleConnection *gc, const struct gg_event_image_request *image_request) { GGPInfo *accdata = purple_connection_get_protocol_data(gc); ggp_image_session_data *sdata = ggp_image_get_sdata(gc); ggp_image_sent *sent_image; PurpleStoredImage *image; PurpleConversation *conv; uint64_t id; gchar *gg_filename; purple_debug_info("gg", "ggp_image_send: got image request " "[uin=%u, crc=%u, size=%u]\n", image_request->sender, image_request->crc32, image_request->size); id = ggp_image_params_to_id(image_request->crc32, image_request->size); sent_image = g_hash_table_lookup(sdata->sent_images, &id); if (sent_image == NULL && image_request->sender == ggp_str_to_uin( purple_account_get_username(purple_connection_get_account(gc)))) { purple_debug_misc("gg", "ggp_image_send: requested image " "not found, but this may be another session request\n"); return; } if (sent_image == NULL) { purple_debug_warning("gg", "ggp_image_send: requested image " "not found\n"); return; } purple_debug_misc("gg", "ggp_image_send: requested image found " "[id=" GGP_IMAGE_ID_FORMAT ", stored id=%d, conv=%s]\n", id, sent_image->id, sent_image->conv_name); image = purple_imgstore_find_by_id(sent_image->id); if (!image) { purple_debug_error("gg", "ggp_image_send: requested image " "found, but doesn't exists in image store\n"); g_hash_table_remove(sdata->sent_images, GINT_TO_POINTER(image_request->crc32)); return; } /* TODO: check allowed recipients */ gg_filename = g_strdup_printf(GGP_IMAGE_ID_FORMAT, id); gg_image_reply(accdata->session, image_request->sender, gg_filename, purple_imgstore_get_data(image), purple_imgstore_get_size(image)); g_free(gg_filename); conv = purple_conversations_find_with_account( sent_image->conv_name, purple_connection_get_account(gc)); if (conv != NULL) { gchar *msg = g_strdup_printf(_("Image delivered to %u."), image_request->sender); purple_conversation_write(conv, "", msg, PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_NOTIFY, time(NULL)); g_free(msg); } }
static void got_sessionreq(MsnSlpCall *slpcall, const char *branch, const char *euf_guid, const char *context) { pecan_debug ("euf_guid=[%s]", euf_guid); if (!strcmp(euf_guid, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6")) { /* Emoticon or UserDisplay */ char *content; gsize len; MsnSlpSession *slpsession; MsnSlpLink *slplink; MsnSlpMessage *slpmsg; MsnObject *obj; char *msnobj_data; PecanBuffer *image; int type; /* Send Ok */ content = pecan_strdup_printf("SessionID: %lu\r\n\r\n", slpcall->session_id); send_ok(slpcall, branch, "application/x-msnmsgr-sessionreqbody", content); g_free(content); slplink = slpcall->slplink; msnobj_data = (char *)purple_base64_decode(context, &len); obj = msn_object_new_from_string(msnobj_data); type = msn_object_get_type(obj); g_free(msnobj_data); if (type == MSN_OBJECT_USERTILE) { /* image is owned by a local object, not obj */ image = msn_object_get_image(obj); } #if PURPLE_VERSION_CHECK(2,5,0) else if (type == MSN_OBJECT_EMOTICON) { PurpleStoredImage *img; char *path; path = g_build_filename(purple_smileys_get_storing_dir(), msn_object_get_location(obj), NULL); img = purple_imgstore_new_from_file(path); image = pecan_buffer_new_memdup ((const gpointer) purple_imgstore_get_data (img), purple_imgstore_get_size (img)); purple_imgstore_unref(img); g_free(path); } #endif /* PURPLE_VERSION_CHECK(2,5,0) */ else { pecan_error ("Wrong object?"); msn_object_destroy(obj); g_return_if_reached(); } if (!image) { pecan_error ("Wrong object"); msn_object_destroy (obj); g_return_if_reached (); } msn_object_destroy(obj); { gchar *tmp; tmp = msn_object_to_string (obj); pecan_info ("object requested: %s", tmp); g_free (tmp); } slpsession = msn_slplink_find_slp_session(slplink, slpcall->session_id); /* DATA PREP */ slpmsg = msn_slpmsg_new(slplink); slpmsg->slpcall = slpcall; slpmsg->slpsession = slpsession; slpmsg->session_id = slpsession->id; msn_slpmsg_set_body(slpmsg, NULL, 4); #ifdef PECAN_DEBUG_SLP slpmsg->info = "SLP DATA PREP"; #endif msn_slplink_queue_slpmsg(slplink, slpmsg); /* DATA */ slpmsg = msn_slpmsg_new(slplink); slpmsg->slpcall = slpcall; slpmsg->slpsession = slpsession; slpmsg->flags = 0x20; #ifdef PECAN_DEBUG_SLP slpmsg->info = "SLP DATA"; #endif msn_slpmsg_set_image (slpmsg, image); msn_slplink_queue_slpmsg(slplink, slpmsg); } else if (!strcmp(euf_guid, "5D3E02AB-6190-11D3-BBBB-00C04F795683")) { /* File Transfer */ PurpleAccount *account; PurpleXfer *xfer; char *bin; gsize bin_len; guint32 file_size; char *file_name; gunichar2 *uni_name; account = slpcall->slplink->session->account; slpcall->cb = msn_xfer_completed_cb; slpcall->end_cb = msn_xfer_end_cb; slpcall->progress_cb = msn_xfer_progress_cb; slpcall->branch = g_strdup(branch); slpcall->pending = TRUE; xfer = purple_xfer_new(account, PURPLE_XFER_RECEIVE, slpcall->slplink->remote_user); if (xfer) { bin = (char *)purple_base64_decode(context, &bin_len); file_size = GUINT32_FROM_LE(*(gsize *)(bin + 8)); uni_name = (gunichar2 *)(bin + 20); while(*uni_name != 0 && ((char *)uni_name - (bin + 20)) < MAX_FILE_NAME_LEN) { *uni_name = GUINT16_FROM_LE(*uni_name); uni_name++; } file_name = g_utf16_to_utf8((const gunichar2 *)(bin + 20), -1, NULL, NULL, NULL); g_free(bin); purple_xfer_set_filename(xfer, file_name); purple_xfer_set_size(xfer, file_size); purple_xfer_set_init_fnc(xfer, msn_xfer_init); purple_xfer_set_request_denied_fnc(xfer, msn_xfer_cancel); purple_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel); slpcall->xfer = xfer; purple_xfer_ref(slpcall->xfer); xfer->data = slpcall; purple_xfer_request(xfer); } } }
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); }
SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags) { SilcMime mime = NULL, p; SilcDList list, parts = NULL; const char *start, *end, *last; GData *attribs; char *type; gboolean images = FALSE; last = msg; while (last && *last && purple_markup_find_tag("img", last, &start, &end, &attribs)) { PurpleStoredImage *image = NULL; const char *id; /* Check if there is text before image */ if (start - last) { char *text, *tmp; p = silc_mime_alloc(); /* Add content type */ silc_mime_add_field(p, "Content-Type", "text/plain; charset=utf-8"); tmp = g_strndup(last, start - last); text = purple_unescape_html(tmp); g_free(tmp); /* Add text */ silc_mime_add_data(p, (const unsigned char *)text, strlen(text)); g_free(text); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); } id = g_datalist_get_data(&attribs, "id"); if (id && (image = purple_imgstore_find_by_id(atoi(id)))) { unsigned long imglen = purple_imgstore_get_size(image); gconstpointer img = purple_imgstore_get_data(image); p = silc_mime_alloc(); /* Add content type */ type = silcpurple_file2mime(purple_imgstore_get_filename(image)); if (!type) { g_datalist_clear(&attribs); last = end + 1; continue; } silc_mime_add_field(p, "Content-Type", type); g_free(type); /* Add content transfer encoding */ silc_mime_add_field(p, "Content-Transfer-Encoding", "binary"); /* Add image data */ silc_mime_add_data(p, img, imglen); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); images = TRUE; } g_datalist_clear(&attribs); /* Continue after tag */ last = end + 1; } /* Check for text after the image(s) */ if (images && last && *last) { char *tmp = purple_unescape_html(last); p = silc_mime_alloc(); /* Add content type */ silc_mime_add_field(p, "Content-Type", "text/plain; charset=utf-8"); /* Add text */ silc_mime_add_data(p, (const unsigned char *)tmp, strlen(tmp)); g_free(tmp); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); } /* If there weren't any images, don't return anything. */ if (!images) { if (parts) silc_dlist_uninit(parts); return NULL; } if (silc_dlist_count(parts) > 1) { /* Multipart MIME message */ char b[32]; mime = silc_mime_alloc(); silc_mime_add_field(mime, "MIME-Version", "1.0"); g_snprintf(b, sizeof(b), "b%4X%4X", (unsigned int)time(NULL), silc_dlist_count(parts)); silc_mime_set_multipart(mime, "mixed", b); silc_dlist_start(parts); while ((p = silc_dlist_get(parts)) != SILC_LIST_END) silc_mime_add_multipart(mime, p); } else { /* Simple MIME message */ silc_dlist_start(parts); mime = silc_dlist_get(parts); silc_mime_add_field(mime, "MIME-Version", "1.0"); } *mflags &= ~SILC_MESSAGE_FLAG_UTF8; *mflags |= SILC_MESSAGE_FLAG_DATA; /* Encode message. Fragment if it is too large */ list = silc_mime_encode_partial(mime, 0xfc00); silc_dlist_uninit(parts); /* Added multiparts gets freed here */ silc_mime_free(mime); return list; }
MsnObject* msn_object_new_from_image(PurpleStoredImage *img, const char *location, const char *creator, MsnObjectType type) { MsnObject *msnobj; PurpleHash *hash; char *buf; gconstpointer data; size_t size; char *base64; unsigned char digest[20]; msnobj = NULL; if (img == NULL) return msnobj; size = purple_imgstore_get_size(img); data = purple_imgstore_get_data(img); /* New object */ msnobj = msn_object_new(); msn_object_set_local(msnobj); msn_object_set_type(msnobj, type); msn_object_set_location(msnobj, location); msn_object_set_creator(msnobj, creator); msn_object_set_image(msnobj, img); /* Compute the SHA1D field. */ memset(digest, 0, sizeof(digest)); hash = purple_sha1_hash_new(); purple_hash_append(hash, data, size); purple_hash_digest(hash, digest, sizeof(digest)); base64 = purple_base64_encode(digest, sizeof(digest)); msn_object_set_sha1d(msnobj, base64); g_free(base64); msn_object_set_size(msnobj, size); /* Compute the SHA1C field. */ buf = g_strdup_printf( "Creator%sSize%dType%dLocation%sFriendly%sSHA1D%s", msn_object_get_creator(msnobj), msn_object_get_size(msnobj), msn_object_get_type(msnobj), msn_object_get_location(msnobj), msn_object_get_friendly(msnobj), msn_object_get_sha1d(msnobj)); memset(digest, 0, sizeof(digest)); purple_hash_reset(hash); purple_hash_append(hash, (const guchar *)buf, strlen(buf)); purple_hash_digest(hash, digest, sizeof(digest)); g_object_unref(hash); g_free(buf); base64 = purple_base64_encode(digest, sizeof(digest)); msn_object_set_sha1c(msnobj, base64); g_free(base64); return msnobj; }