Exemplo n.º 1
0
inline void CStringEx::stradd(char stringto[],int maxto,char stringfrom[],int maxfrom)
{
 int l1,l2,i;
 l1=sizestr(stringto,maxto);
 l2=sizestr(stringfrom,maxfrom);
 for(i=0;i<=l2;i++) stringto[l1+i]=stringfrom[i];
 return;
}
Exemplo n.º 2
0
inline void CStringEx::strover(char stringto[],char stringfrom[],int maxfrom)
{
 int l2,i;
 l2=sizestr(stringfrom,maxfrom)-1;
 for(i=0;i<=l2;i++) stringto[i]=stringfrom[i];
 return;
}
Exemplo n.º 3
0
// Format the file size in a short form that rounds to the largest size unit
// e.g. "3.48 GB", "12.38 MB", "23 KB"
// Caller needs to free the result.
WCHAR *FormatSizeSuccint(size_t size) {
    const WCHAR *unit = NULL;
    double s = (double)size;

    if (size > GB)
    {
        s /= GB;
        unit = _TR("GB");
    }
    else if (size > MB)
    {
        s /= MB;
        unit = _TR("MB");
    }
    else
    {
        s /= KB;
        unit = _TR("KB");
    }
    
    ScopedMem<WCHAR> sizestr(str::FormatFloatWithThousandSep(s));
    if (!unit)
        return sizestr.StealData();
    
    return str::Format(L"%s %s", sizestr, unit);
}
Exemplo n.º 4
0
static void notice_transfer(const char *nick, xdcc *xd, const char *msg)
{
    char *sizestrstr;

    sizestrstr = sizestr(0, xd->st_size);
    notice_fast(nick, "%s, which is %sB. (resume supported)", msg, sizestrstr);
    mydelete(sizestrstr);
}
Exemplo n.º 5
0
inline void CStringEx::strfill(char string[],int max,char fill)
/* max is length of string including null terminator */
{
 int l1,i;
 string[max-1]='\0';
 l1 = sizestr(string,max);
 /* l1 is length of the string 
    this matchs the position
    of the null terminator */
 for(i=l1;i<=max-2;i++) string[i]=fill;
 string[max-1]='\0';
 return;
}
Exemplo n.º 6
0
const std::string Message::GetNNTPBody() const
{
	std::string nntpbody(m_body);

	// find all LF that don't have a preceeding CR, and add the CR
	std::string::size_type lfpos=nntpbody.find('\n');
	while(lfpos!=std::string::npos)
	{
		if(lfpos==0 || nntpbody[lfpos-1]!='\r')
		{
			nntpbody.insert(lfpos,"\r");
			lfpos++;
		}
		lfpos=nntpbody.find('\n',lfpos+1);
	}

	if(m_receivedfileattachments.size()>0)
	{
		nntpbody+="\r\nAttachments";
		for(std::vector<receivedfileattachment>::const_iterator i=m_receivedfileattachments.begin(); i!=m_receivedfileattachments.end(); i++)
		{
			std::string sizestr("");
			StringFunctions::Convert((*i).m_size,sizestr);
			nntpbody+="\r\n"+(*i).m_key+"\r\n"+sizestr+" bytes\r\n";
		}
	}

	// base64 encoding if max line is more than 997 bytes
	// 997 instead of 998 because we might have added an extra \r above
	if(m_bodylinemaxbytes>997)
	{
		std::string encoded("");
		Base64::Encode(std::vector<unsigned char>(nntpbody.begin(),nntpbody.end()),encoded);
		nntpbody="";
		for(std::string::size_type pos=0; pos<encoded.size(); pos+=76)
		{
			nntpbody+=encoded.substr(pos,76)+"\r\n";
		}
	}

	return nntpbody;
}
Exemplo n.º 7
0
void MythSocket::ReadStringListReal(
    QStringList *list, uint timeoutMS, bool *ret)
{
    list->clear();
    *ret = false;

    MythTimer timer;
    timer.start();
    int elapsed = 0;

    while (m_tcpSocket->bytesAvailable() < 8)
    {
        elapsed = timer.elapsed();
        if (elapsed >= (int)timeoutMS)
        {
            LOG(VB_GENERAL, LOG_ERR, LOC + "ReadStringList: " +
                QString("Error, timed out after %1 ms.").arg(timeoutMS));
            m_tcpSocket->close();
            m_dataAvailable.fetchAndStoreOrdered(0);
            return;
        }

        if (m_tcpSocket->state() != QAbstractSocket::ConnectedState)
        {
            LOG(VB_GENERAL, LOG_ERR, LOC + "ReadStringList: Connection died.");
            m_dataAvailable.fetchAndStoreOrdered(0);
            return;
        }

        m_tcpSocket->waitForReadyRead(50);
    }

    QByteArray sizestr(8 + 1, '\0');
    if (m_tcpSocket->read(sizestr.data(), 8) < 0)
    {
        LOG(VB_GENERAL, LOG_ERR, LOC +
            QString("ReadStringList: Error, read return error (%1)")
                .arg(m_tcpSocket->errorString()));
        m_tcpSocket->close();
        m_dataAvailable.fetchAndStoreOrdered(0);
        return;
    }

    QString sizes = sizestr;
    qint64 btr = sizes.trimmed().toInt();

    if (btr < 1)
    {
        int pending = m_tcpSocket->bytesAvailable();
        LOG(VB_GENERAL, LOG_ERR, LOC +
            QString("Protocol error: '%1' is not a valid size "
                    "prefix. %2 bytes pending.")
                .arg(sizestr.data()).arg(pending));
        ResetReal();
        return;
    }

    QByteArray utf8(btr + 1, 0);

    qint64 readoffset = 0;
    int errmsgtime = 0;
    timer.start();

    while (btr > 0)
    {
        if (m_tcpSocket->bytesAvailable() < 1)
        {
            if (m_tcpSocket->state() == QAbstractSocket::ConnectedState)
            {
                m_tcpSocket->waitForReadyRead(50);
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR, LOC +
                    "ReadStringList: Connection died.");
                m_dataAvailable.fetchAndStoreOrdered(0);
                return;
            }
        }

        qint64 sret = m_tcpSocket->read(utf8.data() + readoffset, btr);
        if (sret > 0)
        {
            readoffset += sret;
            btr -= sret;
            if (btr > 0)
            {
                timer.start();
            }
        }
        else if (sret < 0)
        {
            LOG(VB_GENERAL, LOG_ERR, LOC + "ReadStringList: Error, read");
            m_tcpSocket->close();
            m_dataAvailable.fetchAndStoreOrdered(0);
            return;
        }
        else if (!m_tcpSocket->isValid())
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                "ReadStringList: Error, socket went unconnected");
            m_tcpSocket->close();
            m_dataAvailable.fetchAndStoreOrdered(0);
            return;
        }
        else
        {
            elapsed = timer.elapsed();
            if (elapsed  > 10000)
            {
                if ((elapsed - errmsgtime) > 10000)
                {
                    errmsgtime = elapsed;
                    LOG(VB_GENERAL, LOG_ERR, LOC +
                        QString("ReadStringList: Waiting for data: %1 %2")
                            .arg(readoffset).arg(btr));
                }
            }

            if (elapsed > 100000)
            {
                LOG(VB_GENERAL, LOG_ERR, LOC +
                    "Error, ReadStringList timeout (readBlock)");
                m_dataAvailable.fetchAndStoreOrdered(0);
                return;
            }
        }
    }

    QString str = QString::fromUtf8(utf8.data());

    QByteArray payload;
    payload = payload.setNum(str.length());
    payload += "        ";
    payload.truncate(8);
    payload += str;

    if (VERBOSE_LEVEL_CHECK(VB_NETWORK, LOG_INFO))
    {
        QString msg = QString("read  <- %1 %2")
            .arg(m_tcpSocket->socketDescriptor(), 2)
            .arg(payload.data());

        if (logLevel < LOG_DEBUG && msg.length() > 88)
        {
            msg.truncate(85);
            msg += "...";
        }
        LOG(VB_NETWORK, LOG_INFO, LOC + msg);
    }

    *list = str.split("[]:[]");

    m_dataAvailable.fetchAndStoreOrdered(
        (m_tcpSocket->bytesAvailable() > 0) ? 1 : 0);

    *ret = true;
}
Exemplo n.º 8
0
bool MythSocket::readStringList(QStringList &list, uint timeoutMS)
{
    list.clear();

    if (state() != Connected)
    {
        VERBOSE(VB_IMPORTANT, LOC +
                "readStringList: Error, called with unconnected socket.");
        return false;
    }

    MythTimer timer;
    timer.start();
    int elapsed = 0;

    while (waitForMore(5) < 8)
    {
        elapsed = timer.elapsed();
        if (elapsed >= (int)timeoutMS)
        {
            VERBOSE(VB_IMPORTANT, LOC + "readStringList: " +
                    QString("Error, timed out after %1 ms.").arg(timeoutMS));
            close();
            return false;
        }

        if (state() != Connected)
        {
            VERBOSE(VB_IMPORTANT, LOC +
                    "readStringList: Connection died.");
            return false;
        }

        {
            struct timeval tv;
            int maxfd;
            fd_set rfds;

            FD_ZERO(&rfds);
            FD_SET(socket(), &rfds);
            maxfd = socket();

            tv.tv_sec = 0;
            tv.tv_usec = 0;

            int rval = select(maxfd + 1, &rfds, NULL, NULL, &tv);
            if (rval)
            {
                if (bytesAvailable() == 0)
                {
                    VERBOSE(VB_IMPORTANT, LOC +
                            "readStringList: Connection died (select).");
                    return false;
                }
            }
        }
    }

    QByteArray sizestr(8 + 1, '\0');
    if (readBlock(sizestr.data(), 8) < 0)
    {
        VERBOSE(VB_GENERAL, LOC +
                QString("readStringList: Error, readBlock return error (%1)")
                .arg(errorToString()));
        close();
        return false;
    }

    QString sizes = sizestr;
    qint64 btr = sizes.trimmed().toInt();

    if (btr < 1)
    {
        int pending = bytesAvailable();
        QByteArray dump(pending + 1, 0);
        readBlock(dump.data(), pending);
        VERBOSE(VB_IMPORTANT, LOC +
                QString("Protocol error: '%1' is not a valid size "
                        "prefix. %2 bytes pending.")
                        .arg(sizestr.data()).arg(pending));
        return false;
    }

    QByteArray utf8(btr + 1, 0);

    qint64 read = 0;
    int errmsgtime = 0;
    timer.start();

    while (btr > 0)
    {
        qint64 sret = readBlock(utf8.data() + read, btr);
        if (sret > 0)
        {
            read += sret;
            btr -= sret;
            if (btr > 0)
            {
                timer.start();
            }
        }
        else if (sret < 0 && error() != MSocketDevice::NoError)
        {
            VERBOSE(VB_GENERAL, LOC +
                    QString("readStringList: Error, readBlock %1")
                    .arg(errorToString()));
            close();
            return false;
        }
        else if (!isValid())
        {
            VERBOSE(VB_IMPORTANT, LOC +
                    "readStringList: Error, socket went unconnected");
            close();
            return false;
        }
        else
        {
            elapsed = timer.elapsed();
            if (elapsed  > 10000)
            {
                if ((elapsed - errmsgtime) > 10000)
                {
                    errmsgtime = elapsed;
                    VERBOSE(VB_GENERAL, LOC +
                            QString("readStringList: Waiting for data: %1 %2")
                            .arg(read).arg(btr));
                }
            }

            if (elapsed > 100000)
            {
                VERBOSE(VB_GENERAL, LOC +
                        "Error, readStringList timeout (readBlock)");
                return false;
            }

            usleep(500);
        }
    }

    QString str = QString::fromUtf8(utf8.data());

    QByteArray payload;
    payload = payload.setNum(str.length());
    payload += "        ";
    payload.truncate(8);
    payload += str;

    if (VERBOSE_LEVEL_CHECK(VB_NETWORK))
    {
        QString msg = QString("read  <- %1 %2").arg(socket(), 2)
            .arg(payload.data());

        if (!VERBOSE_LEVEL_CHECK(VB_EXTRA) && msg.length() > 88)
        {
            msg.truncate(85);
            msg += "...";
        }
        VERBOSE(VB_NETWORK, LOC + msg);
    }

    list = str.split("[]:[]");

    m_notifyread = false;
    s_readyread_thread->WakeReadyReadThread();
    return true;
}
Exemplo n.º 9
0
const std::string ForumTemplateViewThreadPage::GenerateContent(const std::string &method, const std::map<std::string,QueryVar> &queryvars)
{
	int postcount=0;
	std::string fproxyprotocol("");
	std::string fproxyhost("");
	std::string fproxyport("");
	std::string maincontent("");
	std::string result("");
	std::map<std::string,std::string> vars;
	std::vector<std::pair<std::string,std::string> > breadcrumblinks;
	std::string threadidstr("");
	std::string boardidstr("");
	std::string pagestr("");
	std::string boardname("");
	std::string firstunreadidstr("");
	std::string threadpostrowodd("");
	std::string threadpostroweven("");
	std::string postrows("");
	std::string threadpostattachment("");
	std::string postattachments("");
	std::string trusttable("");
	bool showsignatures=false;
	bool showavatars=false;
	SQLite3DB::Transaction trans(m_db);
	Option opt(m_db);
	std::vector<std::string> skipspace;
	SQLite3DB::Statement fileattachmentst=m_db->Prepare("SELECT Key, Size FROM tblMessageFileAttachment WHERE MessageID=?;");
	SQLite3DB::Statement truststpeeronly=m_db->Prepare("SELECT PeerMessageTrust, PeerTrustListTrust FROM tblIdentity WHERE IdentityID=?;");
	SQLite3DB::Statement truststboth=m_db->Prepare("SELECT tblIdentityTrust.LocalMessageTrust, tblIdentity.PeerMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentity.PeerTrustListTrust FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE tblIdentity.IdentityID=? AND tblIdentityTrust.LocalIdentityID=?;");

	opt.GetBool("ForumShowSignatures",showsignatures);
	opt.GetBool("ForumShowAvatars",showavatars);
	opt.Get("FProxyProtocol",fproxyprotocol);
	opt.Get("FProxyHost",fproxyhost);
	opt.Get("FProxyPort",fproxyport);

	skipspace.push_back(" ");

	if(queryvars.find("messageuuid")!=queryvars.end())
	{
		SQLite3DB::Statement st=m_db->Prepare("SELECT tblMessage.MessageID, tblThreadPost.ThreadID, tblThread.BoardID FROM tblMessage LEFT JOIN tblThreadPost ON tblMessage.MessageID=tblThreadPost.MessageID LEFT JOIN tblThread ON tblThreadPost.ThreadID=tblThread.ThreadID WHERE MessageUUID=?;");
		st.Bind(0,(*queryvars.find("messageuuid")).second.GetData());
		st.Step();
		if(st.RowReturned())
		{
			int messageid=0;
			int threadid=0;
			int boardid=0;

			st.ResultInt(2,boardid);
			m_viewstate.SetBoardID(boardid);

			if(st.ResultNull(1)==false)
			{
				st.ResultInt(1,threadid);
				m_viewstate.SetThreadID(threadid);
			}
			else
			{
				m_viewstate.SetThreadID(0);
			}
		}
		st.Finalize();
	}
	if(queryvars.find("threadid")!=queryvars.end())
	{
		int temp=0;
		threadidstr=(*queryvars.find("threadid")).second.GetData();
		StringFunctions::Convert(threadidstr,temp);
		m_viewstate.SetThreadID(temp);
	}
	else
	{
		int temp=0;
		temp=m_viewstate.GetThreadID();
		StringFunctions::Convert(temp,threadidstr);
	}
	if(queryvars.find("page")!=queryvars.end())
	{
		pagestr=(*queryvars.find("page")).second.GetData();
		int temp=0;
		if(StringFunctions::Convert(pagestr,temp)==true)
		{
			m_viewstate.SetPage(temp);
		}
	}
	else
	{
		int temp=0;
		temp=m_viewstate.GetPage();
		StringFunctions::Convert(temp,pagestr);
	}
	if(queryvars.find("boardid")!=queryvars.end())
	{
		boardidstr=(*queryvars.find("boardid")).second.GetData();
		int temp=0;
		if(StringFunctions::Convert(boardidstr,temp)==true)
		{
			m_viewstate.SetBoardID(temp);
		}
	}
	else
	{
		int temp=0;
		temp=m_viewstate.GetBoardID();
		StringFunctions::Convert(temp,boardidstr);
	}

	// first unread select must come before marking read messages
	SQLite3DB::Statement firstunreadst=m_db->Prepare("SELECT tblMessage.MessageID FROM tblThreadPost INNER JOIN tblMessage ON tblThreadPost.MessageID=tblMessage.MessageID WHERE ThreadID=? AND tblMessage.Read=0;");
	firstunreadst.Bind(0,threadidstr);
	firstunreadst.Step();
	if(firstunreadst.RowReturned())
	{
		firstunreadst.ResultText(0,firstunreadidstr);
	}
	firstunreadst.Finalize();

	trans.Begin(SQLite3DB::Transaction::TRANS_IMMEDIATE);
	if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="markunread")
	{
		SQLite3DB::Statement updateread=m_db->Prepare("UPDATE tblMessage SET Read=0 WHERE tblMessage.MessageID IN (SELECT MessageID FROM tblThreadPost WHERE ThreadID=?);");
		updateread.Bind(0,threadidstr);
		trans.Step(updateread);
	}
	else
	{
		SQLite3DB::Statement updateread=m_db->Prepare("UPDATE tblMessage SET Read=1 WHERE tblMessage.MessageID IN (SELECT MessageID FROM tblThreadPost WHERE ThreadID=?);");
		updateread.Bind(0,threadidstr);
		trans.Step(updateread);
	}
	trans.Commit();
	if(trans.IsSuccessful()==false)
	{
		m_log->error("ForumTemplateViewThreadPage::GenerateContent transaction failed SQL="+trans.GetErrorSQL()+" Error="+trans.GetLastErrorStr());
	}

	// add/remove trust
	if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second.GetData().find("trust")!=std::string::npos && queryvars.find("identityid")!=queryvars.end() && ValidateFormPassword(queryvars))
	{
		trans.Begin(SQLite3DB::Transaction::TRANS_IMMEDIATE);
		SQLite3DB::Statement currenttrustst=m_db->Prepare("SELECT IFNULL(LocalMessageTrust,-1), IFNULL(LocalTrustListTrust,-1) FROM tblIdentityTrust WHERE IdentityID=? AND LocalIdentityID=?;");
		SQLite3DB::Statement updatetrustst=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=? AND LocalIdentityID=?;");

		currenttrustst.Bind(0,(*queryvars.find("identityid")).second.GetData());
		currenttrustst.Bind(1,m_viewstate.GetLocalIdentityID());
		trans.Step(currenttrustst);
		if(currenttrustst.RowReturned())
		{
			int localmessagetrust=-1;
			int localtrustlisttrust=-1;

			currenttrustst.ResultInt(0,localmessagetrust);
			currenttrustst.ResultInt(1,localtrustlisttrust);

			if((*queryvars.find("formaction")).second=="addmessagetrust")
			{
				if(localmessagetrust==-1)
				{
					localmessagetrust=50;
				}
				localmessagetrust=(std::min)(localmessagetrust+10,100);
			}
			else if((*queryvars.find("formaction")).second=="removemessagetrust")
			{
				if(localmessagetrust==-1)
				{
					localmessagetrust=50;
				}
				localmessagetrust=(std::max)(localmessagetrust-10,0);
			}
			else if((*queryvars.find("formaction")).second=="addtrustlisttrust")
			{
				if(localtrustlisttrust==-1)
				{
					localtrustlisttrust=50;
				}
				localtrustlisttrust=(std::min)(localtrustlisttrust+10,100);
			}
			else if((*queryvars.find("formaction")).second=="removetrustlisttrust")
			{
				if(localtrustlisttrust==-1)
				{
					localtrustlisttrust=50;
				}
				localtrustlisttrust=(std::max)(localtrustlisttrust-10,0);
			}

			if(localmessagetrust!=-1)
			{
				updatetrustst.Bind(0,localmessagetrust);
			}
			else
			{
				updatetrustst.Bind(0);
			}
			if(localtrustlisttrust!=-1)
			{
				updatetrustst.Bind(1,localtrustlisttrust);
			}
			else
			{
				updatetrustst.Bind(1);
			}
			updatetrustst.Bind(2,(*queryvars.find("identityid")).second.GetData());
			updatetrustst.Bind(3,m_viewstate.GetLocalIdentityID());
			trans.Step(updatetrustst);

		}
		trans.Finalize(currenttrustst);
		trans.Finalize(updatetrustst);
		trans.Commit();
		if(trans.IsSuccessful()==false)
		{
			m_log->error("ForumTemplateViewThreadPage::GenerateContent transaction failed SQL="+trans.GetErrorSQL()+" Error="+trans.GetLastErrorStr());
		}
	}

	SQLite3DB::Statement boardnamest=m_db->Prepare("SELECT tblBoard.BoardName FROM tblBoard INNER JOIN tblThread ON tblBoard.BoardID=tblThread.BoardID WHERE tblThread.ThreadID=?;");
	boardnamest.Bind(0,threadidstr);
	boardnamest.Step();
	if(boardnamest.RowReturned())
	{
		boardnamest.ResultText(0,boardname);
	}
	boardnamest.Finalize();


	breadcrumblinks.push_back(std::pair<std::string,std::string>("forummain.htm?viewstate="+m_viewstate.GetViewStateID(),SanitizeOutput(m_trans->Get("web.navlink.browseforums"))));
	breadcrumblinks.push_back(std::pair<std::string,std::string>("forumthreads.htm?viewstate="+m_viewstate.GetViewStateID()+"&boardid="+boardidstr+"&page="+pagestr,SanitizeOutput(boardname)));

	if(firstunreadidstr!="")
	{
		vars["FIRSTUNREADPOSTLINK"]="<a href=\"#"+firstunreadidstr+"\"><img src=\"images/mail_get.png\" border=\"0\" style=\"vertical-align:bottom;\">"+m_trans->Get("web.page.forumviewthread.firstunread")+"</a>";
	}
	else
	{
		vars["FIRSTUNREADPOSTLINK"]="";
	}

	m_templatehandler.GetSection("THREADPOSTATTACHMENT",threadpostattachment);
	m_templatehandler.GetSection("TRUSTTABLE",trusttable);

	vars["MARKUNREADLINK"]="<a href=\""+m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&formaction=markunread&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"\"><img src=\"images/mail_generic.png\" border=\"0\" style=\"vertical-align:bottom;\">"+m_trans->Get("web.page.forumviewthread.markunread")+"</a>";

	// thread posts
	std::vector<std::string> ignoredsig;
	ignoredsig.push_back("THREADPOSTSIGNATUREDIV");	// don't replace this div when we get the section, we'll replace it later
	m_templatehandler.GetSection("THREADPOSTROWODD",threadpostrowodd,ignoredsig);
	m_templatehandler.GetSection("THREADPOSTROWEVEN",threadpostroweven,ignoredsig);
	trans.ClearError();
	// only selects, deferred OK
	trans.Begin();
	SQLite3DB::Statement st=m_db->Prepare("SELECT tblMessage.MessageID, tblMessage.IdentityID, tblMessage.FromName, tblMessage.Subject, tblMessage.MessageDate || ' ' || tblMessage.MessageTime, tblMessage.Body, tblIdentity.PublicKey || (SELECT OptionValue FROM tblOption WHERE Option='MessageBase') || '|' || tblMessage.InsertDate || '|Message-' || tblMessage.MessageIndex, tblMessage.MessageUUID, tblIdentity.Signature, tblIdentity.ShowSignature, tblIdentity.ShowAvatar, tblIdentity.FMSAvatar, tblIdentity.SoneAvatar FROM tblMessage INNER JOIN tblThreadPost ON tblMessage.MessageID=tblThreadPost.MessageID LEFT JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE tblThreadPost.ThreadID=? ORDER BY tblThreadPost.PostOrder;");
	st.Bind(0,threadidstr);
	trans.Step(st);
	while(st.RowReturned())
	{
		std::map<std::string,std::string> postvars;
		std::string postrow("");
		int messageid(0);
		std::string messageidstr="";
		std::string identityidstr="";
		std::string fromname="";
		std::string subject="";
		std::string datetime="";
		std::string body="";
		std::string postlink="";
		std::string messageuuid="";
		std::string signature="";
		std::string showidsignature="0";
		bool allowreply=true;
		bool showidavatar=false;
		std::string fmsavatar("");
		std::string soneavatar("");
		
		st.ResultInt(0,messageid);
		st.ResultText(0,messageidstr);
		st.ResultText(1,identityidstr);
		st.ResultText(2,fromname);
		st.ResultText(3,subject);
		st.ResultText(4,datetime);
		st.ResultText(5,body);
		st.ResultText(6,postlink);
		st.ResultText(7,messageuuid);
		st.ResultText(8,signature);
		st.ResultText(9,showidsignature);
		st.ResultBool(10,showidavatar);
		st.ResultText(11,fmsavatar);
		st.ResultText(12,soneavatar);

		if(postcount==0)
		{
			if(subject!="")
			{
				m_pagetitle+=" - "+SanitizeOutput(boardname,skipspace)+" - "+SanitizeOutput(subject,skipspace);
			}
			breadcrumblinks.push_back(std::pair<std::string,std::string>(m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr,SanitizeOutput(subject,skipspace)));
		}

		postvars["THREADPOSTANCHOR"]="<a name=\""+messageidstr+"\"></a><a name=\""+FixUUIDAnchor(messageuuid)+"\"></a>";

		if(identityidstr=="")
		{
			postvars["CONDITIONALTRUSTTABLE"]="";
		}
		else
		{
			int lmt=0;
			int pmt=0;
			std::string localmessagetrust("");
			std::string localtrustlisttrust("");
			std::string peermessagetrust("");
			std::string peertrustlisttrust("");

			if(m_viewstate.GetLocalIdentityID()==0)
			{
				truststpeeronly.Bind(0,identityidstr);
				truststpeeronly.Step();
				if(truststpeeronly.RowReturned())
				{
					truststpeeronly.ResultText(0,peermessagetrust);
					truststpeeronly.ResultText(1,peertrustlisttrust);
					truststpeeronly.ResultInt(0,pmt);
					if(peermessagetrust!="" && pmt<m_minpeermessagetrust)
					{
						allowreply=false;
					}

				}
				truststpeeronly.Reset();
			}
			else
			{
				truststboth.Bind(0,identityidstr);
				truststboth.Bind(1,m_viewstate.GetLocalIdentityID());
				truststboth.Step();
				if(truststboth.RowReturned())
				{
					truststboth.ResultText(0,localmessagetrust);
					truststboth.ResultText(1,peermessagetrust);
					truststboth.ResultText(2,localtrustlisttrust);
					truststboth.ResultText(3,peertrustlisttrust);
					truststboth.ResultInt(0,lmt);
					truststboth.ResultInt(1,pmt);
					if(localmessagetrust=="")
					{
						lmt=100;
					}
					if(peermessagetrust=="")
					{
						pmt=100;
					}
					if(((m_localtrustoverrides==false || localmessagetrust=="") && (pmt<m_minpeermessagetrust || lmt<m_minlocalmessagetrust)) || (m_localtrustoverrides==true && (lmt<m_minlocalmessagetrust)))
					{
						allowreply=false;
					}
				}
				truststboth.Reset();
			}

			postvars["CONDITIONALTRUSTTABLE"]=trusttable;
			postvars["LOCALMESSAGETRUST"]=localmessagetrust;
			postvars["PEERMESSAGETRUST"]=peermessagetrust;
			postvars["LOCALTRUSTLISTTRUST"]=localtrustlisttrust;
			postvars["PEERTRUSTLISTTRUST"]=peertrustlisttrust;

			if(m_viewstate.GetLocalIdentityID()!=0)
			{
				postvars["LOCALMESSAGETRUST"]+="<a href=\""+m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&"+CreateLinkFormPassword()+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"&formaction=addmessagetrust&identityid="+identityidstr+"#"+messageidstr+"\"><img src=\"images/circleplus.png\" border=\"0\" style=\"vertical-align:bottom;\"></a>";
				postvars["LOCALMESSAGETRUST"]+="<a href=\""+m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&"+CreateLinkFormPassword()+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"&formaction=removemessagetrust&identityid="+identityidstr+"#"+messageidstr+"\"><img src=\"images/circleminus.png\" border=\"0\" style=\"vertical-align:bottom;\"></a>";
				postvars["LOCALTRUSTLISTTRUST"]+="<a href=\""+m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&"+CreateLinkFormPassword()+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"&formaction=addtrustlisttrust&identityid="+identityidstr+"#"+messageidstr+"\"><img src=\"images/circleplus.png\" border=\"0\" style=\"vertical-align:bottom;\"></a>";
				postvars["LOCALTRUSTLISTTRUST"]+="<a href=\""+m_pagename+"?viewstate="+m_viewstate.GetViewStateID()+"&"+CreateLinkFormPassword()+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"&formaction=removetrustlisttrust&identityid="+identityidstr+"#"+messageidstr+"\"><img src=\"images/circleminus.png\" border=\"0\" style=\"vertical-align:bottom;\"></a>";
			}

		}

		postvars["THREADPOSTBODY"]=FixBody(body);

		postattachments="";
		fileattachmentst.Bind(0,messageid);
		fileattachmentst.Step();
		while(fileattachmentst.RowReturned())
		{
			std::string thisattachment("");
			std::map<std::string,std::string> attachmentvars;
			std::string key("");
			int size=0;
			std::string sizestr("");
			std::string keyname("");
			std::string::size_type slashpos=std::string::npos;
				
			fileattachmentst.ResultText(0,key);
			fileattachmentst.ResultInt(0,size);
			fileattachmentst.ResultText(1,sizestr);

			if(size<0)
			{
				sizestr="?";
			}

			keyname=key;
			slashpos=keyname.find('/');
			if(slashpos!=std::string::npos && slashpos<keyname.size())
			{
				keyname=keyname.substr(slashpos+1);
			}

			attachmentvars["THREADPOSTATTACHMENTLINK"]="<a href=\"[FPROXYPROTOCOL]://[FPROXYHOST]:[FPROXYPORT]/"+StringFunctions::UriEncode(key)+"\"><img src=\"images/attach.png\" border=\"0\" style=\"vertical-align:baseline;\"> "+SanitizeOutput(keyname)+"</a>";
			attachmentvars["THREADPOSTATTACHMENTSIZE"]=sizestr+" bytes";

			m_templatehandler.PerformReplacements(threadpostattachment,attachmentvars,thisattachment);
			postattachments+=thisattachment;
			fileattachmentst.Step();
		}
		fileattachmentst.Reset();
		if(postattachments!="")
		{
			postattachments="<div class=\"postattachments\">"+postattachments+"</div>";
		}
		postvars["THREADPOSTATTACHMENTS"]=postattachments;

		if(identityidstr!="")
		{
			postvars["THREADPOSTAUTHORNAME"]="<a href=\"peerdetails.htm?identityid="+identityidstr+"\">"+FixAuthorName(fromname)+"</a>";
			if(showsignatures==true && showidsignature=="1" && signature!="")
			{
				std::vector<std::string> skipspace(1," ");
				std::string lf(1,10);
				postvars["THREADPOSTSIGNATURE"]=StringFunctions::Replace(m_htmlrenderer.Render(signature),lf,"<br />");
			}
			else
			{
				postvars["THREADPOSTSIGNATUREDIV"]="";
			}
			if(showavatars==true && showidavatar==true)
			{	/*
				std::vector<std::string> parts;
				StringFunctions::SplitMultiple(postlink,"@,",parts);
				if(parts.size()>1)
				{
					postvars["THREADPOSTAUTHORAVATAR"]="<img src=\"showavatar.htm?idpart="+StringFunctions::UriEncode(parts[1])+"\">";
				}
				else
				{
					postvars["THREADPOSTAUTHORAVATAR"]="";
				}
				*/
				if(fmsavatar!="")
				{
					postvars["THREADPOSTAUTHORAVATAR"]="<img src=\""+fproxyprotocol+"://"+fproxyhost+":"+fproxyport+"/"+StringFunctions::UriEncode(fmsavatar)+"\" style=\"max-width:150px;max-height:150px;\">";
				}
				else if(soneavatar!="")
				{
					postvars["THREADPOSTAUTHORAVATAR"]="<img src=\""+fproxyprotocol+"://"+fproxyhost+":"+fproxyport+"/"+StringFunctions::UriEncode(soneavatar)+"\" style=\"max-width:150px;max-height:150px;\">";
				}
				else
				{
					postvars["THREADPOSTAUTHORAVATAR"]="";
				}
			}
			else
			{
				postvars["THREADPOSTAUTHORAVATAR"]="";
			}
		}
		else
		{
			postvars["THREADPOSTAUTHORNAME"]=FixAuthorName(fromname);
			postvars["THREADPOSTSIGNATUREDIV"]="";
			postvars["THREADPOSTAUTHORAVATAR"]="";
		}
		postvars["THREADPOSTTITLE"]=SanitizeOutput(subject,skipspace);
		if(identityidstr!="" && postlink!="")
		{
			postvars["THREADPOSTLINK"]="<a href=\"[FPROXYPROTOCOL]://[FPROXYHOST]:[FPROXYPORT]/"+StringFunctions::UriEncode(postlink)+"?type=text/plain\"><img src=\"images/link.png\" border=\"0\" title=\""+m_trans->Get("web.page.forumviewthread.permalink")+"\"></a>";
		}
		else
		{
			postvars["THREADPOSTLINK"]="";
		}
		postvars["THREADPOSTLINK"]+="&nbsp;<a href=\""+m_pagename+"?messageuuid="+FixUUIDAnchor(messageuuid)+"#"+FixUUIDAnchor(messageuuid)+"\"><img src=\"images/link.png\" border=\"0\" title=\""+m_trans->Get("web.page.forumviewthread.shareablelink")+"\"></a>";

		postvars["THREADPOSTDATE"]=datetime;

		if(allowreply==true)
		{
			postvars["THREADPOSTREPLYLINK"]="<a href=\"forumcreatepost.htm?viewstate="+m_viewstate.GetViewStateID()+"&replytomessageid="+messageidstr+"&threadid="+threadidstr+"&boardid="+boardidstr+"&page="+pagestr+"\"><img src=\"images/mail_reply.png\" border=\"0\" style=\"vertical-align:bottom;\">"+m_trans->Get("web.page.forumviewthread.reply")+"</a>";
		}
		else
		{
			postvars["THREADPOSTREPLYLINK"]="";
		}

		postcount++;

		if(postcount%2==1)
		{
			m_templatehandler.PerformReplacements(threadpostrowodd,postvars,postrow);
		}
		else
		{
			m_templatehandler.PerformReplacements(threadpostroweven,postvars,postrow);
		}
		postrows+=postrow;

		trans.Step(st);
	}
	trans.Finalize(st);
	trans.Commit();

	vars["THREADPOSTROWS"]=postrows;

	CreateBreadcrumbLinks(breadcrumblinks,result);
	vars["LOCATIONBREADCRUMBS"]=result;

	m_templatehandler.GetSection("FORUMVIEWTHREADCONTENT",maincontent);
	m_templatehandler.PerformReplacements(maincontent,vars,result);

	return result;
}
Exemplo n.º 10
0
static VALUE cie_info_pack(VALUE UNUSED(module), VALUE rnr, VALUE rkey)
{
  xdcc *xd;
  const char *key;
  const char *val;
  char *tempstr;
  unsigned int nr;
  unsigned int ival;
  off_t oval;
  size_t len;
  VALUE rval;

  if (NIL_P(rnr) || NIL_P(rkey))
    return Qnil;

  nr = FIX2UINT(rnr);
  if (nr == 0)
    return Qnil;

  if (nr > irlist_size(&gdata.xdccs))
    return Qnil;

  xd = get_xdcc_pack(nr);
  if (xd == NULL)
    return Qnil;

  key = rb_obj_as_string_protected(rkey);
  if (!key)
    return Qnil;

  for (;;) {
    if (strcmp(key, "file") == 0) { /* NOTRANSLATE */
      val = xd->file;
      break;
    }
    if (strcmp(key, "name") == 0) { /* NOTRANSLATE */
      val = getfilename(xd->file);
      break;
    }
    if (strcmp(key, "desc") == 0) { /* NOTRANSLATE */
      val = xd->desc;
      break;
    }
    if (strcmp(key, "note") == 0) { /* NOTRANSLATE */
      val = xd->note;
      break;
    }
    if (strcmp(key, "group") == 0) { /* NOTRANSLATE */
      val = xd->group;
      break;
    }
    if (strcmp(key, "group_desc") == 0) { /* NOTRANSLATE */
      val = find_groupdesc(xd->group);
      break;
    }
    if (strcmp(key, "trigger") == 0) { /* NOTRANSLATE */
      val = xd->trigger;
      break;
    }
    if (strcmp(key, "lock") == 0) { /* NOTRANSLATE */
      val = xd->lock;
      break;
    }
    if (strcmp(key, "gets") == 0) { /* NOTRANSLATE */
      ival = xd->gets;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "color") == 0) { /* NOTRANSLATE */
      ival = xd->color;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "dlimit_max") == 0) { /* NOTRANSLATE */
      ival = xd->dlimit_max;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "dlimit_used") == 0) { /* NOTRANSLATE */
      ival = xd->dlimit_used;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "has_md5sum") == 0) { /* NOTRANSLATE */
      ival = xd->has_md5sum;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "has_crc32") == 0) { /* NOTRANSLATE */
      ival = xd->has_crc32;
      return UINT2NUM(ival);
    }
    if (strcmp(key, "bytes") == 0) { /* NOTRANSLATE */
      oval = xd->st_size;
      return OFFT2NUM(oval);
    }
    if (strcmp(key, "size") == 0) { /* NOTRANSLATE */
      tempstr = sizestr(0, xd->st_size);
      len = strlen(tempstr);
      rval = rb_str_new(tempstr, len);
      mydelete(tempstr);
      return rval;
    }
    if (strcmp(key, "mtime") == 0) { /* NOTRANSLATE */
      return rb_time_new(xd->mtime, 0);
    }
    if (strcmp(key, "xtime") == 0) { /* NOTRANSLATE */
      return rb_time_new(xd->xtime, 0);
    }
    if (strcmp(key, "crc32") == 0) { /* NOTRANSLATE */
      tempstr = mymalloc(maxtextlengthshort);
      len = add_snprintf(tempstr, maxtextlengthshort, CRC32_PRINT_FMT, xd->crc32);
      rval = rb_str_new(tempstr, len);
      mydelete(tempstr);
      return rval;
    }
    if (strcmp(key, "md5sum") == 0) { /* NOTRANSLATE */
      tempstr = mymalloc(maxtextlengthshort);
      len = add_snprintf(tempstr, maxtextlengthshort, MD5_PRINT_FMT, MD5_PRINT_DATA(xd->md5sum));
      rval = rb_str_new(tempstr, len);
      mydelete(tempstr);
      return rval;
    }
    /* minspeed, maxspeed */
    return Qnil;
  }
  if (val == NULL)
    return Qnil;
  return rb_str_new(val, strlen(val));
}