Browse Source

Generate correct isInNetEx calls. See #67.

FelisCatus 9 years ago
parent
commit
d489e2eeaf
2 changed files with 7 additions and 5 deletions
  1. 5 3
      omega-pac/src/conditions.coffee
  2. 2 2
      omega-pac/test/conditions.coffee

+ 5 - 3
omega-pac/src/conditions.coffee

@@ -520,13 +520,15 @@ module.exports = exports =
             new U2.AST_String value: cache.mask
           ]
         )
-        if cache.addr.v6
+        if not cache.addr.v4
+          # Example: isInNetEx(host,"fefe:13::abc/33")
+          # For documentation on the isInNetEx function, see:
+          # https://msdn.microsoft.com/en-us/library/windows/desktop/gg308479(v=vs.85).aspx
           hostIsInNetEx = new U2.AST_Call(
             expression: new U2.AST_SymbolRef name: 'isInNetEx'
             args: [
               new U2.AST_SymbolRef name: 'host'
-              new U2.AST_String value: cache.normalized
-              new U2.AST_String value: cache.mask
+              new U2.AST_String value: cache.normalized + cache.addr.subnet
             ]
           )
           # Use isInNetEx if possible.

+ 2 - 2
omega-pac/test/conditions.coffee

@@ -268,8 +268,8 @@ describe 'Conditions', ->
       Conditions.match(cond, request).should.be.true
 
       compiled = Conditions.compile(cond).print_to_string()
-      compiled_args = compiled.substr(compiled.lastIndexOf('('))
-      compiled_args.should.eql('(host,"fefe:13::abc","ffff:ffff:8000::")')
+      compiled.should.contain('isInNet(host,"fefe:13::abc","ffff:ffff:8000::")')
+      compiled.should.contain('isInNetEx(host,"fefe:13::abc/33")')
     it 'should support IPv6 subnet with zero prefixLength', ->
       cond =
         conditionType: "IpCondition"