410
private const string UrlSpecialRmvScm = @"{URL:RMVSCM}";
411
private const string UrlSpecialScm = @"{URL:SCM}";
412
private const string UrlSpecialHost = @"{URL:HOST}";
413
private const string UrlSpecialPort = @"{URL:PORT}";
414
private const string UrlSpecialPath = @"{URL:PATH}";
415
private const string UrlSpecialQuery = @"{URL:QUERY}";
416
414
private static string FillEntryStringsSpecial(string str, SprContext ctx,
417
415
uint uRecursionLevel)
419
if((str.IndexOf(UrlSpecialRmvScm, SprEngine.ScMethod) >= 0) ||
420
(str.IndexOf(UrlSpecialScm, SprEngine.ScMethod) >= 0) ||
421
(str.IndexOf(UrlSpecialHost, SprEngine.ScMethod) >= 0) ||
422
(str.IndexOf(UrlSpecialPort, SprEngine.ScMethod) >= 0) ||
423
(str.IndexOf(UrlSpecialPath, SprEngine.ScMethod) >= 0) ||
424
(str.IndexOf(UrlSpecialQuery, SprEngine.ScMethod) >= 0))
417
return FillUriSpecial(str, ctx, @"{URL", ctx.Entry.Strings.ReadSafe(
418
PwDefs.UrlField), false, uRecursionLevel);
421
private static string FillUriSpecial(string strText, SprContext ctx,
422
string strPlhInit, string strData, bool bDataIsEncoded,
423
uint uRecursionLevel)
425
Debug.Assert(strPlhInit.StartsWith(@"{") && !strPlhInit.EndsWith(@"}"));
426
Debug.Assert(strData != null);
428
string[] vPlhs = new string[] {
430
strPlhInit + @":RMVSCM}",
431
strPlhInit + @":SCM}",
432
strPlhInit + @":HOST}",
433
strPlhInit + @":PORT}",
434
strPlhInit + @":PATH}",
435
strPlhInit + @":QUERY}",
436
strPlhInit + @":USERINFO}",
437
strPlhInit + @":USERNAME}",
438
strPlhInit + @":PASSWORD}"
441
string str = strText;
442
string strDataCmp = null;
444
for(int i = 0; i < vPlhs.Length; ++i)
426
SprContext ctxRaw = ctx.WithoutContentTransformations();
427
string strUrl = SprEngine.FillIfExists(@"{URL}", @"{URL}",
428
ctx.Entry.Strings.GetSafe(PwDefs.UrlField), ctxRaw, uRecursionLevel);
430
str = SprEngine.FillPlaceholder(str, UrlSpecialRmvScm,
431
UrlUtil.RemoveScheme(strUrl), ctx);
435
Uri uri = new Uri(strUrl);
437
str = SprEngine.FillPlaceholder(str, UrlSpecialScm,
439
str = SprEngine.FillPlaceholder(str, UrlSpecialHost,
441
str = SprEngine.FillPlaceholder(str, UrlSpecialPort,
442
uri.Port.ToString(NumberFormatInfo.InvariantInfo), ctx);
443
str = SprEngine.FillPlaceholder(str, UrlSpecialPath,
444
uri.AbsolutePath, ctx);
445
str = SprEngine.FillPlaceholder(str, UrlSpecialQuery,
448
catch(Exception) { } // Invalid URI
446
string strPlh = vPlhs[i];
447
if(str.IndexOf(strPlh, SprEngine.ScMethod) < 0) continue;
449
if(strDataCmp == null)
451
SprContext ctxData = (bDataIsEncoded ?
452
ctx.WithoutContentTransformations() : ctx);
453
strDataCmp = SprEngine.CompileInternal(strData, ctxData,
454
uRecursionLevel + 1);
457
string strRep = null;
458
if(i == 0) strRep = strDataCmp;
459
else if(i == 1) strRep = UrlUtil.RemoveScheme(strDataCmp);
464
if(uri == null) uri = new Uri(strDataCmp);
469
case 2: strRep = uri.Scheme; break;
470
case 3: strRep = uri.Host; break;
472
strRep = uri.Port.ToString(
473
NumberFormatInfo.InvariantInfo);
475
case 5: strRep = uri.AbsolutePath; break;
476
case 6: strRep = uri.Query; break;
477
case 7: strRep = uri.UserInfo; break;
479
strRep = uri.UserInfo;
480
t = strRep.IndexOf(':');
481
if(t >= 0) strRep = strRep.Substring(0, t);
484
strRep = uri.UserInfo;
485
t = strRep.IndexOf(':');
486
if(t < 0) strRep = string.Empty;
487
else strRep = strRep.Substring(t + 1);
489
default: Debug.Assert(false); break;
492
catch(Exception) { } // Invalid URI
494
if(strRep == null) strRep = string.Empty; // No assert
496
str = StrUtil.ReplaceCaseInsensitive(str, strPlh, strRep);