static void go_spectre_load_data (GOImage *image, GsfXMLIn *xin) { #ifdef GOFFICE_WITH_EPS GOSpectre *spectre = GO_SPECTRE (image); int width, height; char *tmpname; #endif image->data_length = gsf_base64_decode_simple (xin->content->str, strlen(xin->content->str)); image->data = g_malloc (image->data_length); memcpy (image->data, xin->content->str, image->data_length); #ifdef GOFFICE_WITH_EPS spectre->doc = spectre_document_new (); if (spectre->doc == NULL) return; /* libspectre can only load files, see https://bugs.freedesktop.org/show_bug.cgi?id=42424 */ tmpname = create_file (image->data, image->data_length); if (!tmpname) return; spectre_document_load (spectre->doc, tmpname); if (spectre_document_status (spectre->doc) != SPECTRE_STATUS_SUCCESS) return; spectre_document_get_page_size (spectre->doc, &width, &height); image->width = width; image->height = height; unlink (tmpname); g_free (tmpname); #endif }
UT_Error AbiCollabSessionManager::deserializeDocument(PD_Document** pDoc, const std::string& document, bool isEncodedBase64) { UT_return_val_if_fail(pDoc, UT_ERROR); UT_Error res = UT_ERROR; // really bad abuse of std::string's below, but more efficient than copying // the whole buffer (which could be massive) into a temporary buffer GsfInput *source; if (isEncodedBase64) { char* base64gzBuf = const_cast<char*>(document.c_str()); size_t gzbufLen = gsf_base64_decode_simple((guint8*)base64gzBuf, strlen(base64gzBuf)); char* gzBuf = base64gzBuf; source = gsf_input_memory_new((guint8*)gzBuf, gzbufLen, false); } else { // string contains raw zipped data source = gsf_input_memory_new((guint8*)document.c_str(), document.size(), false); } if (source) { GsfInput *gzabwBuf = gsf_input_gzip_new (source, NULL); // todo: don't pass null here, but check for errors if (gzabwBuf) { bool create = (*pDoc == NULL); if (create) { UT_DEBUGMSG(("Creating a new document in AbiCollabSessionManager::deserializeDocument()\n")); (*pDoc) = new PD_Document(); (*pDoc)->createRawDocument(); } IE_Imp* imp = (IE_Imp*)new IE_Imp_AbiWord_1(*pDoc); imp->importFile(gzabwBuf); // todo: check for errors (*pDoc)->repairDoc(); if (create) (*pDoc)->finishRawCreation(); DELETEP(imp); g_object_unref(G_OBJECT(gzabwBuf)); res = UT_OK; } else { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); } g_object_unref(G_OBJECT(source)); } else { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); } return res; }
static void content_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *unknown) { SheetObject *so = gnm_xml_in_cur_obj (xin); SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so); soi->bytes.len = gsf_base64_decode_simple ( xin->content->str, xin->content->len); soi->bytes.data = g_memdup (xin->content->str, soi->bytes.len); }
static void content_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *unknown) { SheetObject *so = gnm_xml_in_cur_obj (xin); SheetObjectImage *soi = GNM_SO_IMAGE (so); GString *data = xin->content; if (data->len >= 4) { size_t len = gsf_base64_decode_simple (data->str, data->len); if (soi->image) g_object_unref (soi->image); soi->image = go_image_new_from_data (soi->type, data->str, len, NULL, NULL); } }
static void content_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *unknown) { SheetObject *so = gnm_xml_in_cur_obj (xin); SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so); GString *data = xin->content; if (data->len >= 4) { size_t len = gsf_base64_decode_simple (data->str, data->len); soi->bytes.len = len; soi->bytes.data = g_memdup (data->str, len); soi->image = go_image_new_from_data (soi->type, soi->bytes.data, len, NULL, NULL); } }
void XMPPAccountHandler::handleMessage(const gchar* packet_data, const std::string& from_address) { UT_return_if_fail(packet_data); UT_return_if_fail(from_address.size() > 0); XMPPBuddyPtr pBuddy = _getBuddy(from_address); if (!pBuddy) { // yay, a message from a new buddy pBuddy = XMPPBuddyPtr(new XMPPBuddy(this, from_address.c_str())); addBuddy(pBuddy); } // construct the packet // NOTE: all packets are base64 encoded when sent over this backend, so we need to decode them // FIXME: inefficient copying of data std::string packet_str = packet_data; size_t len = gsf_base64_decode_simple((guint8*)(&packet_str[0]), packet_str.size()); packet_str.resize(len); Packet* pPacket = _createPacket(packet_str, pBuddy); UT_return_if_fail(pPacket); AccountHandler::handleMessage(pPacket, pBuddy); }