Arc Forumnew | comments | leaders | submitlogin
Defsop on the git
4 points by sacado 6122 days ago | 1 comment
Well, defsop is on the git now. It is a macro similar to defop, but taking an dditional parameter which is an IP address (or a list of IP addresses) from which the operator can be accessed. From any other address, the message "Permission denied" is returned.

for example, (defsop hello req "127.0.0.1" (pr "hello")) displays hello when accessing /hello locally, but displays the error message when accessed remotely.

defop's definition is :

  (mac defsop (name parm auth . body)
    (w/uniq test
      `(let ,test (if (acons ,auth) [some _ ,auth] (testify ,auth))
          (defop ,name ,parm
             (if (,test (,parm 'ip))
                 ,@body
                 (pr "Permission denied"))))))
As a side effect, the additional parameter can also be a unary function whose parameter is the IP address of the caller. This way, you could for example check that the URL is accessed from somebody whose address follows the regex "123.45..".


3 points by almkglor 6122 days ago | link

I've since modified this macro to evaluate auth only once, in a (withs ...) form. Also, it might be better to insert the local variable binding inside the defop form - we might want to base auth on the parameter(s) to the operation. Not very likely, of course, but hey, a gun which can't shoot feet might not shoot lions.

-----