summaryrefslogtreecommitdiffstats
path: root/kio
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-24 05:52:30 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-24 05:52:30 +0000
commitbc378237e712ffea9612d6f06a302a7829aab98f (patch)
tree7c668a646a6b582f34162bb4ee068b0d4a410ef4 /kio
parent582bff44be553b868471cecac7634cc9c35e81db (diff)
downloadtdelibs-bc378237e712ffea9612d6f06a302a7829aab98f.tar.gz
tdelibs-bc378237e712ffea9612d6f06a302a7829aab98f.zip
Add ability to decode dollar encoded URLs with KIO
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1178862 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kio')
-rw-r--r--kio/kio/krun.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/kio/kio/krun.cpp b/kio/kio/krun.cpp
index 995a2121b..49c748fc4 100644
--- a/kio/kio/krun.cpp
+++ b/kio/kio/krun.cpp
@@ -920,6 +920,70 @@ void KRun::init ( const KURL& url, TQWidget* window, const TQCString& asn, mode_
void KRun::init()
{
kdDebug(7010) << "INIT called" << endl;
+ if (m_strURL.url().startsWith("$(")) {
+ // check for environment variables and make necessary translations
+ TQString aValue = m_strURL.url();
+ int nDollarPos = aValue.find( '$' );
+
+ while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
+ // there is at least one $
+ if( (aValue)[nDollarPos+1] == '(' ) {
+ uint nEndPos = nDollarPos+1;
+ // the next character is no $
+ while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
+ nEndPos++;
+ nEndPos++;
+ TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
+
+ TQString result;
+ FILE *fs = popen(TQFile::encodeName(cmd).data(), "r");
+ if (fs)
+ {
+ {
+ TQTextStream ts(fs, IO_ReadOnly);
+ result = ts.read().stripWhiteSpace();
+ }
+ pclose(fs);
+ }
+ aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
+ } else if( (aValue)[nDollarPos+1] != '$' ) {
+ uint nEndPos = nDollarPos+1;
+ // the next character is no $
+ TQString aVarName;
+ if (aValue[nEndPos]=='{')
+ {
+ while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
+ nEndPos++;
+ nEndPos++;
+ aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
+ }
+ else
+ {
+ while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
+ || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
+ nEndPos++;
+ aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
+ }
+ const char* pEnv = 0;
+ if (!aVarName.isEmpty())
+ pEnv = getenv( aVarName.ascii() );
+ if( pEnv ) {
+ // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
+ // A environment variables may contain values in 8bit
+ // locale cpecified encoding or in UTF8 encoding.
+ aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
+ } else
+ aValue.remove( nDollarPos, nEndPos-nDollarPos );
+ } else {
+ // remove one of the dollar signs
+ aValue.remove( nDollarPos, 1 );
+ nDollarPos++;
+ }
+ nDollarPos = aValue.find( '$', nDollarPos );
+ }
+ m_strURL = KURL(aValue);
+ }
+
if ( !m_strURL.isValid() )
{
d->m_showingError = true;