home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / srealm.rxx < prev    next >
Text File  |  1999-06-24  |  8KB  |  309 lines

  1. /* Daemon to check for superceding realm entries */
  2.  
  3. parse upper arg defrealm_file_temp,  usequeue , USESEM, max_semwait,sport
  4.  
  5. mytid=dostid()
  6.  
  7. foo=pmprintf_sref(' SRE-http S_Realm:  thread, file and queue: 'mytid ', 'defrealm_file_temp', 'usequeue,,sport)
  8.  
  9.  
  10. resetit:
  11. if usequeue="" | USESEM="" then do
  12.    call pmprintf('SRE-http S_Realm ERROR: initialization ERROR: '||usequeue)
  13.    exit
  14. end
  15.  
  16. call set_realm(defrealm_file_temp)
  17. oo=value('SREF_NO_SUPERCEDING_REALM','0 '||realms.0,'os2environment') 
  18.  
  19.  
  20. foo=pmprintf_sref(' SRE-http S_Realm:  #superceding realms= '||realms.0,,sport)
  21.  
  22.  
  23. /* Initialization now done == start waiting for requests for realm info */
  24. signal on error name iserror
  25. signal on syntax name iserror
  26. bakme:
  27.  a=rxqueue('s',usequeue)
  28.  aq=queued()
  29.  if aq=0 then do
  30.     WOW=EVENTSEM_WAIT(USESEM,max_semwait)
  31.     aq=-1
  32.     if wow=640 then do
  33.          signal bakme
  34.     end
  35.  
  36.     IF WOW<>0 THEN do         /* FATAL ERROR */
  37.        call pmprintf(' SRE-http S_Realm ERROR:  fatal semaphore error ')
  38.        exit
  39.     end
  40.  end
  41.  wow=EVENTSEM_RESET(usesem)
  42.  if aq=-1 then
  43.     if queued()=0 then    signal bakme
  44.  
  45.   PARSE pull isit0
  46.  
  47.   isit0=translate(isit0,' ','000d0a09'x)
  48.   if isit0="" then signal bakme
  49.  
  50. /* die command? */
  51.      if abbrev(isit0,'*DIE*')=1 then
  52.           exit
  53.  
  54.      parse var isit0  idnum ',' newq ',' newsem ',' ISIT
  55.      parse var idnum idnum host_nickname
  56.      isitorig=isit
  57.      if newq="" | newsem=""  then do
  58.         foo=pmprintf_sref(' SRE-http S_Realm ERROR: missing queue or semaphore ',,sport)
  59.         signal bakme
  60.      end
  61.      newq=upper(strip(newq)); newsem=upper(strip(newsem))
  62.      ISIT=STRIP(ISIT)
  63.  
  64.  
  65.    if abbrev(isit,'*LIST*') then do
  66.         dog1=''
  67.         do mm=1 to realms.0
  68.             dog1=dog1||realms.mm.!host'// 'realms.mm.!realm' 'realms.mm||'0d0a'x
  69.         end
  70.       a=rxqueue('s',newq)
  71.       push idnum ',' dog1
  72.       wow=eventsem_post(newsem)
  73.       signal bakme
  74.    end
  75.  
  76.   if abbrev(isit,'*RESET*') then do
  77.           call set_realm(defrealm_file_temp)
  78.           oo=value('SREF_NO_SUPERCEDING_REALM','0 '||realms.0,'os2environment') 
  79.           foo=pmprintf_sref(' SRE-http S_Realm reset:  #superceding realms= '||nrealms,,sport)
  80.    end
  81.    else do
  82.        if  realms.0=0 then do
  83.            dog1=' '
  84.        end
  85.        else do
  86.          dog1=fig_realms(isit,host_nickname)
  87.       end
  88.       a=rxqueue('s',newq)
  89.       push idnum ',' dog1
  90.       wow=eventsem_post(newsem)
  91.    end
  92.  
  93. signal bakme
  94.  
  95. iserror:
  96. signal off error ; signal off syntax
  97. call pmprintf(' SRE-http S_realm ERROR: error in thread 'sigl)
  98. a=rxqueue('d',usequeue)
  99. a=rxqueue('c',usequeue)
  100. a=eventsem_close(usesem)
  101. a=eventsem_create(usesem)
  102. a=rxqueue('s',newq)
  103. push idnum ', 0 '
  104. wow=eventsem_post(newsem)
  105. call pmprintf('SRE-http S_realm ERROR: done resetting S_realm thread ')
  106. signal on error name iserror
  107. signal on syntax name iserror
  108. signal bakme
  109.  
  110.  
  111.  
  112. exit
  113.  
  114.  
  115.  
  116. /* ---------- */
  117. fig_realms:procedure expose realms. xrealms.
  118.  
  119. parse arg isit , host_nickname,isit0
  120.  
  121. crlf='0d0a'x
  122.  
  123.  isit=strip(isit,'l','/')        
  124.  if pos('?',isit)>0 then do
  125.             parse var isit a1 '?' a2
  126.             a1=translate(a1,'/','\')
  127.             tsel=a1'?'||a2
  128.  end
  129.  else do
  130.            tsel=translate(isit,'/','\')
  131.  end
  132.  tsel=strip(translate(tsel))
  133.  
  134.  host_nickname=strip(upper(host_nickname))
  135.  
  136.  doexact=0
  137.  gotit=0 ; resu=' '; gotit2=''
  138.  
  139. /* is this an exact match, for a specific host? */
  140. if length(tsel)<70 & (pos('*',tsel)+pos('?',tsel)=0) & host_nickname<>'' then do
  141.      al=host_nickname'//'tsel
  142.      gotit=xrealms.al
  143.  
  144. end
  145.  
  146. /* not an exact match, check superceding host specific matches first? */
  147. if gotit=0 then do
  148. if abbrev(host_nickname,'_!')=1 then do   /* check superceding-host specific matches first */
  149.  
  150.   do m=1 to realms.0
  151.       if realms.m.!x=1 then iterate     /* not an exact match */
  152.       if host_nickname<>realms.m.!host then iterate  /* not for this host */
  153.       jlias=strip(realms.m)
  154.       aresu=sref_wild_match(tsel,jlias,resu)
  155.       if aresu=0 then iterate     /* no match */
  156.       if aresu=-1 then do  /* exact match */
  157.           resu=-1
  158.           gotit=m
  159.           gotit2=jlias
  160.           leave
  161.       end
  162.       resu=aresu
  163.       GOTIT=M
  164.       gotit2=jlias
  165.       iterate
  166.   end
  167. end
  168. end
  169.  
  170. /* no host specfic and not "strict-superceding host", try a generic match? */
  171. if gotit=0 & abbrev(host_nickname,'_!!')=0 then do
  172.  
  173. /* is this an exact match, default host? */
  174.   if length(tsel)<70 & (pos('*',tsel)+pos('?',tsel)=0) then do
  175.       al='//'tsel
  176.       gotit=xrealms.al
  177.  
  178.    end
  179.  
  180.   if gotit=0 then do
  181.   do m=1 to realms.0               
  182.       if realms.m.!x=1 then iterate     /* not an exact match */
  183.       if abbrev(host_nickname,'_!')=1 & realms.m.!host>'' then iterate  /* do not check superceding hosts */
  184.       if (realms.m.!host<>'' & realms.m.!host<>host_nickname) then iterate
  185.       jlias=strip(realms.m)
  186.       aresu=sref_wild_match(tsel,jlias,resu)
  187.       if aresu=0 then iterate     /* no match */
  188.       if aresu=-1 then do  /* exact match */
  189.           resu=-1
  190.           gotit=m
  191.           gotit2=jlias
  192.           leave
  193.       end
  194.       resu=aresu
  195.       GOTIT=M
  196.       gotit2=jlias
  197.      iterate 
  198.   end
  199.   end
  200. end
  201. if gotit=0 then return ''               /* no match */
  202.  
  203. if pos('*',gotit2)=0 then do
  204.    dalias=realms.gotit.!alias
  205. end
  206. else do
  207.    dalias=sref_wildcard(tsel,gotit2' 'realms.gotit.!alias,0)
  208.    parse var dalias ii ' , 'dalias
  209.    if ii=0 then return dalias=''        /* should never happen */
  210. end
  211.  
  212. oof=realms.gotit.!realm||crlf||realms.gotit.!origrule||crlf
  213. oof=oof||realms.gotit.!access||crlf||dalias||crlf
  214. oof=oof||realms.gotit.!puburls||crlf||realms.gotit.!virtual
  215. return oof
  216.  
  217.  
  218. /* ---------------- */
  219. /* read and set up aliases */
  220. set_realm: 
  221. parse arg defrealm
  222.  
  223. realms.=''
  224. realms.0=0
  225. crlf='0d0a'x
  226.  
  227. aa=sref_open_read(defrealm,15,'READ')
  228. if aa<=0 then return 0
  229.  
  230. ii=stream(defrealm,'c','query size')
  231. if ii=0 | ii='' then return 0
  232.  
  233. stuff=charin(defrealm,1,ii)
  234. foo=stream(defrealm,'c','close')
  235.  
  236. /* skip first two lines */
  237. parse var stuff . (crlf) . (crlf) stuff
  238.  
  239. do forever
  240.   if stuff="" then leave
  241.   parse var stuff aline (crlf) stuff
  242.   if abbrev(aline,';C_REALM')=1 then do
  243.      parse var aline . rname . 'rule=' arule
  244.      iat=realms.0+1
  245.      realms.0=iat
  246.      realms.iat=arule
  247.      realms.iat.!origrule=arule
  248.      realms.iat.!realm=rname
  249.      realms.iat.!alias='' ;realms.iat.!puburls=0 ;realms.iat.!alias=0
  250.      realms.iat.!virtual=0
  251.      do forever                         /* get alias access puburls virtual */
  252.         if stuff='' then leave
  253.         parse var stuff aline (crlf) stuff
  254.         if aline='' then leave
  255.         parse var aline atype ':' ainfo ; atype=strip(translate(atype))
  256.         parse var ainfo ahost .
  257.         if right(strip(ahost),2)='//' then do
  258.             parse var ainfo realms.iat.!host '//' ainfo
  259.         end        
  260.         aatype='!'||atype
  261.         if atype<>'VIRTUAL' then  parse var ainfo . ainfo  /* get rid of rule */
  262.         realms.iat.aatype=ainfo
  263.      end
  264.   end
  265.   else do       /* scan till next blank line */
  266.      do forever
  267.         if stuff='' then leave
  268.         parse var stuff aline (crlf) stuff
  269.         if aline='' then leave
  270.      end
  271.   end 
  272. end
  273.  
  274. /* clean up rules, and create list of exact entries */
  275. xrealms.=0
  276. do mm=1 to realms.0
  277.   arr=realms.mm
  278.   arr=translate(strip(realms.mm))
  279.   arr=strip(arr,'l','/')        
  280.   if pos('?',arr)>0 then do
  281.       parse var arr a1 '?' a2
  282.       a1=translate(a1,'/','\')
  283.       arr=a1'?'||a2
  284.   end
  285.   else do
  286.       arr=translate(arr,'/','\')
  287.   end
  288.   realms.mm=arr
  289.   if pos('*',arr)>0 | pos('?',arr)>0 | length(arr)>50 then iterate
  290.   realms.mm.!x=1
  291.   arr=strip(realms.mm.!host)'//'arr
  292.   xrealms.arr=mm
  293. end
  294.  
  295.  
  296.  
  297. /*
  298. do mm=1 to realms.0
  299. call pmprintf(mm' 'realms.mm.!realm' 'realms.mm.!host'//--'realms.mm' == 'realms.mm.!alias)
  300. end
  301. */
  302.  
  303. return 1
  304.   
  305.  
  306.  
  307.  
  308.  
  309.