Example #1
0
std::string LLUrlEntryBase::getLabelFromWikiLink(const std::string &url) const
{
	// return the label part from [http://www.example.org Label]
	const char *text = url.c_str();
	S32 start = 0;
	while (! isspace(text[start]))
	{
		start++;
	}
	while (text[start] == ' ' || text[start] == '\t')
	{
		start++;
	}
	return unescapeUrl(url.substr(start, url.size()-start-1));
}
std::string LLUrlEntryBase::urlToGreyQuery(const std::string &url) const
{
	// <FS:Ansariel> Unfail URI display
	//LLUriParser up(unescapeUrl(url));
	LLUriParser up(url);
	// </FS:Ansariel>

	std::string query;
	up.extractParts();
	up.glueSecond(query);

	// <FS:Ansariel> Unfail URI display
	//return query;
	return unescapeUrl(query);
	// </FS:Ansariel>
}
std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	if (!gCacheName)
	{
		// probably at the login screen, use short string for layout
		return LLTrans::getString("AvatarNameWaiting");
	}

	std::string agent_id_string = getIDStringFromUrl(url);
	if (agent_id_string.empty())
	{
		// something went wrong, just give raw url
		return unescapeUrl(url);
	}

	LLUUID agent_id(agent_id_string);
	if (agent_id.isNull())
	{
		return LLTrans::getString("AvatarNameNobody");
	}

	LLAvatarName av_name;
	if (LLAvatarNameCache::get(agent_id, &av_name))
	{
		std::string label = av_name.getCompleteName();

		// handle suffixes like /mute or /offerteleport
		label = localize_slapp_label(url, label);
		return label;
	}
	else
	{
		// <FS:Ansariel> FIRE-11330: Names in chat get stuck as "Loading..."
		//if (mAvatarNameCacheConnection.connected())
		//{
		//	mAvatarNameCacheConnection.disconnect();
		//}
		//mAvatarNameCacheConnection = LLAvatarNameCache::get(agent_id, boost::bind(&LLUrlEntryAgent::onAvatarNameCache, this, _1, _2));
		boost::signals2::connection connection = LLAvatarNameCache::get(agent_id, boost::bind(&LLUrlEntryAgent::onAvatarNameCache, this, _1, _2));
		mAvatarNameCacheConnections.insert(std::make_pair(agent_id, connection));
		// </FS:Ansariel>
		addObserver(agent_id_string, url, cb);
		return LLTrans::getString("AvatarNameWaiting");
	}
}
std::string LLUrlEntryRegion::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	//
	// we handle SLURLs in the following formats:
	//   - secondlife:///app/region/Place/X/Y/Z
	//   - secondlife:///app/region/Place/X/Y
	//   - secondlife:///app/region/Place/X
	//   - secondlife:///app/region/Place
	//

	LLSD path_array = LLURI(url).pathArray();
	S32 path_parts = path_array.size();

	if (path_parts < 3) // no region name
	{
		llwarns << "Failed to parse url [" << url << "]" << llendl;
		return url;
	}

	std::string label = unescapeUrl(path_array[2]); // region name

	if (path_parts > 3) // secondlife:///app/region/Place/X
	{
		std::string x = path_array[3];
		label += " (" + x;

		if (path_parts > 4) // secondlife:///app/region/Place/X/Y
		{
			std::string y = path_array[4];
			label += "," + y;

			if (path_parts > 5) // secondlife:///app/region/Place/X/Y/Z
			{
				std::string z = path_array[5];
				label = label + "," + z;
			}
		}

		label += ")";
	}

	return label;
}
Example #5
0
std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	if (!gCacheName)
	{
		// probably at the login screen, use short string for layout
		return LLTrans::getString("LoadingData");
	}

	std::string agent_id_string = getIDStringFromUrl(url);
	if (agent_id_string.empty())
	{
		// something went wrong, just give raw url
		return unescapeUrl(url);
	}

	LLUUID agent_id(agent_id_string);
	if (agent_id.isNull())
	{
		return LLTrans::getString("AvatarNameNobody");
	}

	LLAvatarName av_name;
	if (LLAvatarNameCache::get(agent_id, &av_name))
	{
		std::string label = av_name.getCompleteName();

		// handle suffixes like /mute or /offerteleport
		label = localize_slapp_label(url, label);
		return label;
	}
	else
	{
		if (mAvatarNameCacheConnection.connected())
		{
			mAvatarNameCacheConnection.disconnect();
		}
		mAvatarNameCacheConnection = LLAvatarNameCache::get(agent_id, boost::bind(&LLUrlEntryAgent::onAvatarNameCache, this, _1, _2));
		addObserver(agent_id_string, url, cb);
		return LLTrans::getString("LoadingData");
	}
}
Example #6
0
std::string LLUrlEntryWorldMap::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	//
	// we handle SLURLs in the following formats:
	//   - secondlife:///app/worldmap/PLACE/X/Y/Z
	//   - secondlife:///app/worldmap/PLACE/X/Y
	//   - secondlife:///app/worldmap/PLACE/X
	//
	LLURI uri(url);
	LLSD path_array = uri.pathArray();
	S32 path_parts = path_array.size();
	if (path_parts < 3)
	{
		return url;
	}

	const std::string label = LLTrans::getString("SLurlLabelShowOnMap");
	std::string location = unescapeUrl(path_array[2]);
	std::string x = (path_parts > 3) ? path_array[3] : "128";
	std::string y = (path_parts > 4) ? path_array[4] : "128";
	std::string z = (path_parts > 5) ? path_array[5] : "0";
	return label + " " + location + " (" + x + "," + y + "," + z + ")";
}
std::string LLUrlEntryHTTPNoProtocol::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	return unescapeUrl(url);
}
std::string LLUrlEntrySL::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	std::string ret = unescapeUrl(url);
	LL_DEBUGS("UrlEntry") << "url " << ret << LL_ENDL;
	return ret;
}
Example #9
0
std::string LLUrlEntryRegion::getLocation(const std::string &url) const
{
	LLSD path_array = LLURI(url).pathArray();
	std::string region_name = unescapeUrl(path_array[2]);
	return region_name;
}
Example #10
0
std::string LLUrlEntryJira::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
	return unescapeUrl(url);
}
std::string LLUrlEntryInvalidSLURL::getTooltip(const std::string &url) const
{
	return unescapeUrl(url);
}
Example #12
0
nsresult
nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg)
{
    NS_ASSERTION(m_mime_delivery_state != nsnull, "not-null m_mime_delivery_state");

    // Close the file, but don't delete the disk file (or the file spec.)
    if (mOutFile)
    {
        mOutFile->Close();
        mOutFile = nsnull;
    }
    // this silliness is because Windows nsILocalFile caches its file size
    // so if an output stream writes to it, it will still return the original
    // cached size.
    if (mTmpFile)
    {
        nsCOMPtr <nsIFile> tmpFile;
        mTmpFile->Clone(getter_AddRefs(tmpFile));
        mTmpFile = do_QueryInterface(tmpFile);
    }
    mRequest = nsnull;

    // First things first, we are now going to see if this is an HTML
    // Doc and if it is, we need to see if we can determine the charset
    // for this part by sniffing the HTML file.
    // This is needed only when the charset is not set already.
    // (e.g. a charset may be specified in HTTP header)
    //
    if ( (m_type) &&  (*m_type) &&
            (!m_charset || !(*m_charset)) )
    {
        if (PL_strcasecmp(m_type, TEXT_HTML) == 0)
        {
            char *tmpCharset = (char *)nsMsgI18NParseMetaCharset(mTmpFile);
            if (tmpCharset[0] != '\0')
            {
                PR_Free(m_charset);
                m_charset = PL_strdup(tmpCharset);
            }
        }
    }

    nsresult mimeDeliveryStatus;
    m_mime_delivery_state->GetStatus(&mimeDeliveryStatus);

    if (mimeDeliveryStatus == NS_ERROR_ABORT)
        status = NS_ERROR_ABORT;

    if (NS_FAILED(status) && status != NS_ERROR_ABORT && NS_SUCCEEDED(mimeDeliveryStatus))
    {
        // At this point, we should probably ask a question to the user
        // if we should continue without this attachment.
        //
        PRBool            keepOnGoing = PR_TRUE;
        nsCString    turl;
        nsString     msg;
        PRUnichar         *printfString = nsnull;
        nsresult rv;
        nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv));
        NS_ENSURE_SUCCESS(rv, rv);
        nsCOMPtr<nsIStringBundle> bundle;
        rv = bundleService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(bundle));
        NS_ENSURE_SUCCESS(rv, rv);
        nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow;
        m_mime_delivery_state->GetDeliveryMode(&mode);
        if (mode == nsIMsgSend::nsMsgSaveAsDraft || mode == nsIMsgSend::nsMsgSaveAsTemplate)
            bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SAVING, getter_Copies(msg));
        else
            bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SENDING, getter_Copies(msg));
        if (m_real_name && *m_real_name)
            printfString = nsTextFormatter::smprintf(msg.get(), m_real_name);
        else if (NS_SUCCEEDED(mURL->GetSpec(turl)) && !turl.IsEmpty())
        {
            nsCAutoString unescapeUrl(turl);
            nsUnescape(unescapeUrl.BeginWriting());
            if (unescapeUrl.IsEmpty())
                printfString = nsTextFormatter::smprintf(msg.get(), turl.get());
            else
                printfString = nsTextFormatter::smprintf(msg.get(), unescapeUrl.get());
        }
        else
            printfString = nsTextFormatter::smprintf(msg.get(), "?");

        nsCOMPtr<nsIPrompt> aPrompt;
        if (m_mime_delivery_state)
            m_mime_delivery_state->GetDefaultPrompt(getter_AddRefs(aPrompt));
        nsMsgAskBooleanQuestionByString(aPrompt, printfString, &keepOnGoing);
        PR_FREEIF(printfString);

        if (keepOnGoing)
        {
            status = 0;
            m_bogus_attachment = PR_TRUE; //That will cause this attachment to be ignored.
        }
        else
        {
            status = NS_ERROR_ABORT;
            m_mime_delivery_state->SetStatus(status);
            nsresult ignoreMe;
            m_mime_delivery_state->Fail(status, nsnull, &ignoreMe);
            m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull);
            SetMimeDeliveryState(nsnull);
            return status;
        }
    }

    m_done = PR_TRUE;

    //
    // Ok, now that we have the file here on disk, we need to see if there was
    // a need to do conversion to plain text...if so, the magic happens here,
    // otherwise, just move on to other attachments...
    //
    if (NS_SUCCEEDED(status) && m_type && PL_strcasecmp(m_type, TEXT_PLAIN) )
    {
        if (m_desired_type && !PL_strcasecmp(m_desired_type, TEXT_PLAIN) )
        {
            //
            // Conversion to plain text desired.
            //
            PRInt32       width = 72;
            nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
            if (pPrefBranch)
                pPrefBranch->GetIntPref("mailnews.wraplength", &width);
            // Let sanity reign!
            if (width == 0)
                width = 72;
            else if (width < 10)
                width = 10;
            else if (width > 30000)
                width = 30000;

            //
            // Now use the converter service here to do the right
            // thing and convert this data to plain text for us!
            //
            nsAutoString      conData;

            if (NS_SUCCEEDED(LoadDataFromFile(mTmpFile, conData, PR_TRUE)))
            {
                if (NS_SUCCEEDED(ConvertBufToPlainText(conData, UseFormatFlowed(m_charset))))
                {
                    if (mDeleteFile)
                        mTmpFile->Remove(PR_FALSE);

                    nsCOMPtr<nsIOutputStream> outputStream;
                    nsresult rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mTmpFile,  PR_WRONLY | PR_CREATE_FILE, 00600);

                    if (NS_SUCCEEDED(rv))
                    {
                        nsCAutoString tData;
                        if (NS_FAILED(ConvertFromUnicode(m_charset, conData, tData)))
                            LossyCopyUTF16toASCII(conData, tData);
                        if (!tData.IsEmpty())
                        {
                            PRUint32 bytesWritten;
                            (void) outputStream->Write(tData.get(), tData.Length(), &bytesWritten);
                        }
                        outputStream->Close();
                        // this silliness is because Windows nsILocalFile caches its file size
                        // so if an output stream writes to it, it will still return the original
                        // cached size.
                        if (mTmpFile)
                        {
                            nsCOMPtr <nsIFile> tmpFile;
                            mTmpFile->Clone(getter_AddRefs(tmpFile));
                            mTmpFile = do_QueryInterface(tmpFile);
                        }

                    }
                }
            }

            PR_FREEIF(m_type);
            m_type = m_desired_type;
            m_desired_type = nsnull;
            PR_FREEIF(m_encoding);
            m_encoding = nsnull;
        }
    }

    PRUint32 pendingAttachmentCount = 0;
    m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
    NS_ASSERTION (pendingAttachmentCount > 0, "no more pending attachment");

    m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1);

    PRBool processAttachmentsSynchronously = PR_FALSE;
    m_mime_delivery_state->GetProcessAttachmentsSynchronously(&processAttachmentsSynchronously);
    if (NS_SUCCEEDED(status) && processAttachmentsSynchronously)
    {
        /* Find the next attachment which has not yet been loaded,
         if any, and start it going.
         */
        PRUint32 i;
        nsMsgAttachmentHandler *next = 0;
        nsMsgAttachmentHandler *attachments = nsnull;
        PRUint32 attachmentCount = 0;

        m_mime_delivery_state->GetAttachmentCount(&attachmentCount);
        if (attachmentCount)
            m_mime_delivery_state->GetAttachmentHandlers(&attachments);

        for (i = 0; i < attachmentCount; i++)
        {
            if (!attachments[i].m_done)
            {
                next = &attachments[i];
                //
                // rhp: We need to get a little more understanding to failed URL
                // requests. So, at this point if most of next is NULL, then we
                // should just mark it fetched and move on! We probably ignored
                // this earlier on in the send process.
                //
                if ( (!next->mURL) && (!next->m_uri) )
                {
                    attachments[i].m_done = PR_TRUE;
                    m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
                    m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1);
                    next->mPartUserOmissionOverride = PR_TRUE;
                    next = nsnull;
                    continue;
                }

                break;
            }
        }

        if (next)
        {
            int status = next->SnarfAttachment(mCompFields);
            if (NS_FAILED(status))
            {
                nsresult ignoreMe;
                m_mime_delivery_state->Fail(status, nsnull, &ignoreMe);
                m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull);
                SetMimeDeliveryState(nsnull);
                return NS_ERROR_UNEXPECTED;
            }
        }
    }

    m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
    if (pendingAttachmentCount == 0)
    {
        // If this is the last attachment, then either complete the
        // delivery (if successful) or report the error by calling
        // the exit routine and terminating the delivery.
        if (NS_FAILED(status))
        {
            nsresult ignoreMe;
            m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
            m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull);
            SetMimeDeliveryState(nsnull);
            return NS_ERROR_UNEXPECTED;
        }
        else
        {
            status = m_mime_delivery_state->GatherMimeAttachments ();
            if (NS_FAILED(status))
            {
                nsresult ignoreMe;
                m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
                m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull);
                SetMimeDeliveryState(nsnull);
                return NS_ERROR_UNEXPECTED;
            }
        }
    }
    else
    {
        // If this is not the last attachment, but it got an error,
        // then report that error and continue
        if (NS_FAILED(status))
        {
            nsresult ignoreMe;
            m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
        }
    }

    SetMimeDeliveryState(nsnull);
    return NS_OK;
}