Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ VerifySetDefaults()

bool System.Net.Cookie.VerifySetDefaults ( CookieVariant variant,
Uri uri,
bool isLocalDomain,
string localDomain,
bool setDefault,
bool shouldThrow )
inlinepackage

Definition at line 376 of file Cookie.cs.

377 {
378 string host = uri.Host;
379 int port = uri.Port;
380 string absolutePath = uri.AbsolutePath;
381 bool flag = true;
382 if (setDefault)
383 {
384 if (Version == 0)
385 {
386 variant = CookieVariant.Plain;
387 }
388 else if (Version == 1 && variant == CookieVariant.Unknown)
389 {
390 variant = CookieVariant.Rfc2109;
391 }
393 }
394 if (string.IsNullOrEmpty(m_name) || m_name[0] == '$' || m_name.IndexOfAny(ReservedToName) != -1 || m_name[0] == ' ' || m_name[m_name.Length - 1] == ' ')
395 {
396 if (shouldThrow)
397 {
398 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Name", (m_name == null) ? "<null>" : m_name));
399 }
400 return false;
401 }
402 if (m_value == null || ((m_value.Length <= 2 || m_value[0] != '"' || m_value[m_value.Length - 1] != '"') && m_value.IndexOfAny(ReservedToValue) != -1))
403 {
404 if (shouldThrow)
405 {
406 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Value", (m_value == null) ? "<null>" : m_value));
407 }
408 return false;
409 }
410 if (Comment != null && (Comment.Length <= 2 || Comment[0] != '"' || Comment[Comment.Length - 1] != '"') && Comment.IndexOfAny(ReservedToValue) != -1)
411 {
412 if (shouldThrow)
413 {
414 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Comment", Comment));
415 }
416 return false;
417 }
418 if (Path != null && (Path.Length <= 2 || Path[0] != '"' || Path[Path.Length - 1] != '"') && Path.IndexOfAny(ReservedToValue) != -1)
419 {
420 if (shouldThrow)
421 {
422 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Path", Path));
423 }
424 return false;
425 }
427 {
428 m_domain = host;
429 }
430 else
431 {
433 {
434 string text = m_domain;
435 if (!DomainCharsTest(text))
436 {
437 if (shouldThrow)
438 {
439 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Domain", (text == null) ? "<null>" : text));
440 }
441 return false;
442 }
443 if (text[0] != '.')
444 {
445 text = "." + text;
446 }
447 int num = host.IndexOf('.');
448 if (isLocalDomain && string.Equals(localDomain, text, StringComparison.OrdinalIgnoreCase))
449 {
450 flag = true;
451 }
452 else if (text.IndexOf('.', 1, text.Length - 2) == -1)
453 {
455 {
456 flag = false;
457 }
458 }
459 else if (variant == CookieVariant.Plain)
460 {
461 if (!IsDomainEqualToHost(text, host) && (host.Length <= text.Length || string.Compare(host, host.Length - text.Length, text, 0, text.Length, StringComparison.OrdinalIgnoreCase) != 0))
462 {
463 flag = false;
464 }
465 }
466 else if ((num == -1 || text.Length != host.Length - num || string.Compare(host, num, text, 0, text.Length, StringComparison.OrdinalIgnoreCase) != 0) && !IsDomainEqualToHost(text, host))
467 {
468 flag = false;
469 }
470 if (flag)
471 {
472 m_domainKey = text.ToLowerInvariant();
473 }
474 }
475 else if (!string.Equals(host, m_domain, StringComparison.OrdinalIgnoreCase))
476 {
477 flag = false;
478 }
479 if (!flag)
480 {
481 if (shouldThrow)
482 {
483 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Domain", m_domain));
484 }
485 return false;
486 }
487 }
489 {
490 switch (m_cookieVariant)
491 {
492 case CookieVariant.Plain:
493 {
494 int length;
495 if (absolutePath.Length == 0 || absolutePath[0] != '/' || (length = absolutePath.LastIndexOf('/')) == 0)
496 {
497 m_path = "/";
498 }
499 else
500 {
501 m_path = absolutePath.Substring(0, length);
502 }
503 break;
504 }
505 case CookieVariant.Rfc2109:
506 m_path = absolutePath.Substring(0, absolutePath.LastIndexOf('/'));
507 break;
508 default:
509 m_path = absolutePath.Substring(0, absolutePath.LastIndexOf('/') + 1);
510 break;
511 }
512 }
513 if (setDefault && !m_port_implicit && m_port.Length == 0)
514 {
515 m_port_list = new int[1] { port };
516 }
517 if (!m_port_implicit)
518 {
519 flag = false;
520 int[] port_list = m_port_list;
521 foreach (int num2 in port_list)
522 {
523 if (num2 == port)
524 {
525 flag = true;
526 break;
527 }
528 }
529 if (!flag)
530 {
531 if (shouldThrow)
532 {
533 throw new CookieException(System.SR.Format(System.SR.net_cookie_attribute, "Port", m_port));
534 }
535 return false;
536 }
537 }
538 return true;
539 }
string Comment
Definition Cookie.cs:64
static bool DomainCharsTest(string name)
Definition Cookie.cs:541
string m_name
Definition Cookie.cs:34
string m_path
Definition Cookie.cs:36
bool m_path_implicit
Definition Cookie.cs:38
static readonly char[] ReservedToValue
Definition Cookie.cs:18
bool m_domain_implicit
Definition Cookie.cs:30
string m_value
Definition Cookie.cs:53
bool m_port_implicit
Definition Cookie.cs:42
CookieVariant m_cookieVariant
Definition Cookie.cs:24
int[] m_port_list
Definition Cookie.cs:44
string m_domainKey
Definition Cookie.cs:57
static bool IsDomainEqualToHost(string domain, string host)
Definition Cookie.cs:367
static readonly char[] ReservedToName
Definition Cookie.cs:16
string m_domain
Definition Cookie.cs:28
string m_port
Definition Cookie.cs:40
static string net_cookie_attribute
Definition SR.cs:36
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7

References System.Uri.AbsolutePath, System.Net.Cookie.Comment, System.Runtime.Serialization.Dictionary, System.Net.Cookie.DomainCharsTest(), System.Net.Equals, System.SR.Format(), System.Uri.Host, System.Net.Cookie.IsDomainEqualToHost(), System.length, System.Net.Cookie.m_cookieVariant, System.Net.Cookie.m_domain, System.Net.Cookie.m_domain_implicit, System.Net.Cookie.m_domainKey, System.Net.Cookie.m_name, System.Net.Cookie.m_path, System.Net.Cookie.m_path_implicit, System.Net.Cookie.m_port, System.Net.Cookie.m_port_implicit, System.Net.Cookie.m_port_list, System.Net.Cookie.m_value, System.SR.net_cookie_attribute, System.Net.Cookie.Path, System.Uri.Port, System.Net.Cookie.ReservedToName, System.Net.Cookie.ReservedToValue, and System.text.