Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LDIF 4.22 KB | None | 0 0
  1. diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
  2. index e18ffa0..6b95892 100644
  3. --- a/plugins/header_rewrite/conditions.cc
  4. +++ b/plugins/header_rewrite/conditions.cc
  5. @@ -62,10 +62,7 @@ ConditionStatus::eval(const Resources &res)
  6.  void
  7.  ConditionStatus::append_value(std::string &s, const Resources &res)
  8.  {
  9. -  std::ostringstream oss;
  10. -
  11. -  oss << res.resp_status;
  12. -  s += oss.str();
  13. +  s += std::to_string(res.resp_status);
  14.    TSDebug(PLUGIN_NAME, "Appending STATUS(%d) to evaluation value -> %s", res.resp_status, s.c_str());
  15.  }
  16.  
  17. @@ -231,7 +228,7 @@ ConditionHeader::append_value(std::string &s, const Resources &res)
  18.        s.append(value, len);
  19.        // multiple headers with the same name must be semantically the same as one value which is comma separated
  20.        if (next_field_loc) {
  21. -        s.append(",");
  22. +        s += ',';
  23.        }
  24.        TSHandleMLocRelease(bufp, hdr_loc, field_loc);
  25.        field_loc = next_field_loc;
  26. @@ -348,17 +345,10 @@ ConditionUrl::set_qualifier(const std::string &q)
  27.  }
  28.  
  29.  void
  30. -ConditionUrl::append_value(std::string & /* s ATS_UNUSED */, const Resources & /* res ATS_UNUSED */)
  31. -{
  32. -}
  33. -
  34. -bool
  35. -ConditionUrl::eval(const Resources &res)
  36. +ConditionUrl::append_value(std::string &s, const Resources &res)
  37.  {
  38. -  TSDebug(PLUGIN_NAME, "ConditionUrl::eval");
  39.    TSMLoc url     = nullptr;
  40.    TSMBuffer bufp = nullptr;
  41. -  std::string s;
  42.  
  43.    if (res._rri != nullptr) {
  44.      // called at the remap hook
  45. @@ -375,7 +365,7 @@ ConditionUrl::eval(const Resources &res)
  46.        url = res._rri->mapToUrl;
  47.      } else {
  48.        TSError("[header_rewrite] Invalid option value");
  49. -      return false;
  50. +      return;
  51.      }
  52.    } else {
  53.      TSMLoc hdr_loc = nullptr;
  54. @@ -387,21 +377,63 @@ ConditionUrl::eval(const Resources &res)
  55.        hdr_loc = res.hdr_loc;
  56.      } else {
  57.        TSError("[header_rewrite] Rule not supported at this hook");
  58. -      return false;
  59. +      return;
  60.      }
  61.      if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
  62.        TSError("[header_rewrite] Error getting the URL");
  63. -      return false;
  64. +      return;
  65.      }
  66.    }
  67.  
  68. -  if (_url_qual == URL_QUAL_HOST) {
  69. -    int host_len     = 0;
  70. -    const char *host = TSUrlHostGet(bufp, url, &host_len);
  71. -    s.append(host, host_len);
  72. -    TSDebug(PLUGIN_NAME, "   Host to match is: %.*s", host_len, host);
  73. +  int i;
  74. +  const char *q_str;
  75. +
  76. +  switch (_url_qual) {
  77. +  case URL_QUAL_HOST:
  78. +    q_str = TSUrlHostGet(bufp, url, &i);
  79. +    s.append(q_str, i);
  80. +    TSDebug(PLUGIN_NAME, "   Host to match is: %.*s", i, q_str);
  81. +    break;
  82. +  case URL_QUAL_PORT:
  83. +    i = TSUrlPortGet(bufp, url);
  84. +    s.append(std::to_string(i));
  85. +    TSDebug(PLUGIN_NAME, "   Port to match is: %d", i);
  86. +    break;
  87. +  case URL_QUAL_PATH:
  88. +    q_str = TSUrlPathGet(bufp, url, &i);
  89. +    s.append(q_str, i);
  90. +    TSDebug(PLUGIN_NAME, "   Path to match is: %.*s", i, q_str);
  91. +    break;
  92. +  case URL_QUAL_QUERY:
  93. +    q_str = TSUrlHttpQueryGet(bufp, url, &i);
  94. +    s.append(q_str, i);
  95. +    TSDebug(PLUGIN_NAME, "   Query parameters to match is: %.*s", i, q_str);
  96. +    break;
  97. +  case URL_QUAL_MATRIX:
  98. +    q_str = TSUrlHttpParamsGet(bufp, url, &i);
  99. +    s.append(q_str, i);
  100. +    TSDebug(PLUGIN_NAME, "   Matrix parameters to match is: %.*s", i, q_str);
  101. +    break;
  102. +  case URL_QUAL_SCHEME:
  103. +    q_str = TSUrlSchemeGet(bufp, url, &i);
  104. +    s.append(q_str, i);
  105. +    TSDebug(PLUGIN_NAME, "   Scheme to match is: %.*s", i, q_str);
  106. +    break;
  107. +  case URL_QUAL_URL:
  108. +  case URL_QUAL_NONE:
  109. +    q_str = TSUrlStringGet(bufp, url, &i);
  110. +    s.append(q_str, i);
  111. +    TSDebug(PLUGIN_NAME, "   URL to match is: %.*s", i, q_str);
  112. +    break;
  113.    }
  114. +}
  115.  
  116. +bool
  117. +ConditionUrl::eval(const Resources &res)
  118. +{
  119. +  std::string s;
  120. +
  121. +  append_value(s, res);
  122.    return static_cast<const Matchers<std::string> *>(_matcher)->test(s);
  123.  }
  124.  
  125. @@ -577,7 +609,7 @@ ConditionClientIp::append_value(std::string &s, const Resources &res)
  126.    char ip[INET6_ADDRSTRLEN];
  127.  
  128.    if (getIP(TSHttpTxnClientAddrGet(res.txnp), ip)) {
  129. -    s.append(ip);
  130. +    s += ip;
  131.    }
  132.  }
  133.  
  134. @@ -647,7 +679,7 @@ ConditionIp::append_value(std::string &s, const Resources &res)
  135.    }
  136.  
  137.    if (ip_set) {
  138. -    s.append(ip);
  139. +    s += ip;
  140.    }
  141.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement