Patch title: Release 96 bulk changes
Abstract:
File: /pliant/util/pml/resolve.pli
Key:
    Removed line
    Added line
module "/pliant/language/unsafe.pli"
module "/pliant/language/context.pli"
module "/pliant/protocol/dns/name.pli"
module "/pliant/fullpliant/user.pli"
module "/pliant/protocol/http/site.pli"
module "/pliant/language/type/text/str8.pli"
module "/pliant/language/type/misc/blob.pli"
module "/pliant/util/crypto/cipher.pli"


function resolve_ip class name from_ip smart ip port forward count
  arg Str class name from_ip ; arg_w Str ip ; arg CBool smart ; arg_w Int port ; arg_w CBool forward ; arg_w Int count
function resolve_ip class name from_ip path_index forward ip port path_count
  arg Str class name from_ip ; arg Int path_index ; arg_w CBool forward ; arg_w Str ip ; arg_w Int port ; arg_w Int path_count
  plugin resolve_ip
  ip := "" ; port := undefined ; forward := false ; count := 1
  if false
    var Data:NameHost host :> name_database:data:host:computer_fullname
    if host:building<>""
      var Data:NameBuilding building :> name_database:data:building host:building
      part route_out
        each proxy building:proxy
          if proxy=computer_fullname
            leave route_out
  forward := false ; ip := "" ; port := undefined ; path_count := 1
  if class="host"
    var Data:NameHost host :> name_database:data:host:name
    if false
      if host:building<>"" and host:building<>name_database:data:host:computer_fullname:building
    var Data:NameHost me :> name_database:data:host computer_fullname
    var Data:NameHost host :> name_database:data:host name
    var Data:NameHost next_hop
    part find_next_hop
      if name=computer_fullname
        next_hop :> host
        leave find_next_hop
      if me:building=host:building
        if me:building<>""
          var Data:NameBuilding building :> name_database:data:building me:building
          each p building:proxy
            if p=computer_fullname
              forward := true
        next_hop :> host
        leave find_next_hop
      if me:building<>"" # out proxy required
        var Data:NameBuilding building :> name_database:data:building me:building
        part select_out_proxy
          var Int i := 0
          each p building:proxy
            if p=computer_fullname # no, I'm one of the proxies
              forward := true
              leave select_out_proxy
            if i=path_index
              next_hop :> name_database:data:host p
            i += 1
          path_count := building:proxy size
          if path_index>=path_count
            return
          leave find_next_hop
      if host:building<>"" # in proxy required
        var Data:NameBuilding building :> name_database:data:building host:building
    if host:ip<>""
      ip := host ip
    eif host:physical<>""
      ip := name_database:data:host:(host physical) ip
        part select_in_proxy
          var Int i := 0
          each p building:proxy
            if p=computer_fullname # no, I'm one of the in proxies
              forward := true
              leave select_in_proxy
            if i=path_index
              next_hop :> name_database:data:host p
            i += 1
          path_count := building:proxy size
          if path_index>=path_count
            return
          leave find_next_hop
      next_hop :> host      
    if next_hop:ip<>""
      ip := next_hop ip
    eif next_hop:physical<>""
      ip := (name_database:data:host next_hop:physical) ip
    port := host port
  eif class="site"
    var Data:Site site :> site_database:data:site:name
    if site:computer<>""
      resolve_ip "host" site:computer from_ip smart ip port forward count
      resolve_ip "host" site:computer from_ip path_index forward ip port path_count
      return
    ip := site ip
    port := site port    


function resolve_public_key class name -> key
  arg Str class name key
  plugin resolve_public_key
  key := ""
  if class="host"
    key := name_database:data:host:name public_key
  if class="user"
    key := user_database:data:user:name public_key
  if class="site"
    key := site_database:data:site:name public_key

function resolve_private_key class name password -> key
  arg Str class name password key
  plugin resolve_private_key
  key := ""
  if class="host"
    key := name_secret_database:data:host:name private_key
  if class="user"
    key := uncipher straight_to_Str:(user_secret_database:data:user:name private_key) password
  if class="site"
    key := site_secret_database:data:site:name private_key



function straight_to_Blob s -> b
  arg Str8 s ; arg Blob b
  b size := s len
  memory_copy s:characters b:content s:len

function straight_to_Str8 b -> s
  arg Blob b ; arg Str8 s
  s set (memory_allocate b:size addressof:s) b:size true
  memory_copy b:content s:characters b:size

function resolve_get_shared_key local_class local_name local_password remote_class remote_name remote_password -> key
  arg Str local_class local_name local_password remote_class remote_name remote_password ; arg Blob key
  plugin resolve_get_shared_key
  key size := 0
  if local_class="host" and remote_class="host"
    key := straight_to_Blob name_secret_database:data:host:local_name:session:remote_name:key
  if local_class="host" and remote_class="user"
    key := straight_to_Blob name_secret_database:data:host:local_name:user_session:remote_name:key
  if local_class="user" and remote_class="host"
    key := uncipher (straight_to_Blob user_secret_database:data:user:local_name:host_session:remote_name:key) local_password
  if local_class="site" and remote_class="user"
    key := straight_to_Blob site_secret_database:data:site:local_name:session:remote_name:key
  if local_class="user" and remote_class="site"
    key := uncipher (straight_to_Blob user_secret_database:data:user:local_name:session:remote_name:key) local_password

function resolve_set_shared_key local_class local_name local_password remote_class remote_name remote_password key
  arg Str local_class local_name local_password remote_class remote_name remote_password ; arg Blob key
  plugin resolve_set_shared_key
  if local_class="host" and remote_class="host"
    name_secret_database:data:host:local_name:session create remote_name
    name_secret_database:data:host:local_name:session:remote_name:key := straight_to_Str8 key
    name_secret_database:data:host:local_name:session:remote_name:timestamp := datetime
  if local_class="host" and remote_class="user"
    name_secret_database:data:host:local_name:user_session create remote_name
    name_secret_database:data:host:local_name:user_session:remote_name:key := straight_to_Str8 key
    name_secret_database:data:host:local_name:user_session:remote_name:timestamp := datetime
  if local_class="user" and remote_class="host"
    user_secret_database:data:user:local_name:host_session create remote_name
    user_secret_database:data:user:local_name:host_session:remote_name:key := straight_to_Str8 (cipher key remote_password)
    user_secret_database:data:user:local_name:host_session:remote_name:timestamp := datetime
    user_secret_database store
  if local_class="site" and remote_class="user"
    site_secret_database:data:site:local_name:session create remote_name
    site_secret_database:data:site:local_name:session:remote_name:key := straight_to_Str8 key
    site_secret_database:data:site:local_name:session:remote_name:timestamp := datetime
  if local_class="user" and remote_class="site"
    user_secret_database:data:user:local_name:session create remote_name
    user_secret_database:data:user:local_name:session:remote_name:key := straight_to_Str8 (cipher key remote_password)
    user_secret_database:data:user:local_name:session:remote_name:timestamp := datetime
    user_secret_database store


export resolve_ip
export resolve_public_key resolve_private_key
export resolve_get_shared_key resolve_set_shared_key