James Fleming | 4 Mar 2006 04:03

POST variables in araneida

Stupid question time: when using POST to submit a form, how do I
retrieve the data sent by the browser?

GET works nicely, with (url-query-alist (request-url request)), but I'm
apparently just not quite bright enough to find the POST equivalent.

Could somebody please point me in the right direction? Just the name of
the appropriate function would be enough.
I'm assuming it's right in front of me, so please be gentle with the
cluestick.

Thanks in advance,
James
--

-- 
Stupidity killed the cat.
Curiosity was framed.
_______________________________________________
lispweb mailing list
lispweb <at> red-bean.com
http://www.red-bean.com/mailman/listinfo/lispweb
James Fleming | 4 Mar 2006 05:00

Re: POST variables in araneida

> Stupid question time: when using POST to submit a form, how do I
> retrieve the data sent by the browser?

Embarrassing answer time: the clue I needed was on the Cliki page.
(request-body request) gives me what I need.

In penance, I shall write a HOWTO for araneida, once I've gotten the
whole thing running.

Cheers,
James
--

-- 
Stupidity killed the cat.
Curiosity was framed.
_______________________________________________
lispweb mailing list
lispweb <at> red-bean.com
http://www.red-bean.com/mailman/listinfo/lispweb
Richard Newman | 4 Mar 2006 06:05
Picon
Picon

Re: POST variables in araneida

James,
   You might be interested in something like

   (flet
     ((write-body-bindings (binding-specifiers body)
        "Auxiliary function for with-request-params."
        (loop for (var param &optional type-fun) in binding-specifiers
              collecting
              (list var
                    (if type-fun
                      (list type-fun (list 'body-param param body))
                      (list 'body-param param body))))))

     (defmacro with-body-params (request binding-specifiers &body body)
       "Each binding specifier is a triple, (var param &optional type- 
fun).
        If TYPE-FUN is not provided, CAR is used to get rid of the  
wrapping
        list that URL-QUERY-PARAM returns."
       (let ((r-body (gensym)))
         `(let ((,r-body (request-body ,request)))
            (let (, <at> (write-body-bindings binding-specifiers r-body))
              , <at> body)))))

   which will save you typing out a load of calls to BODY-PARAM, if  
you're using form-encoded bodies.

   I'm sure Alan has something a lot more integrated!

   Take a look in (IIRC) daemon.lisp to see how bodies are handled.  
(Continue reading)

Alan Shields | 4 Mar 2006 06:23

Re: POST variables in araneida

On Sat, Mar 04, 2006 at 03:00:38PM +1100, James Fleming wrote:
> > Stupid question time: when using POST to submit a form, how do I
> > retrieve the data sent by the browser?
> 
> Embarrassing answer time: the clue I needed was on the Cliki page.
> (request-body request) gives me what I need.
> 
> In penance, I shall write a HOWTO for araneida, once I've gotten the
> whole thing running.

You're not the first person to have claimed that. I'd be one of the more
recent ones.

Seriously, the documentation on Araneida IS getting better - but there are
glaring ommissions. How to handle body parameters is one of them.

After school stops being insane for at least a little bit, and I get traction
on my current Lisp project, body parameters are on my list to "deal with."

Seriously not happy with them right now.

Patches or even doc suggestions are always welcome.

Alan
--

-- 
"You think you're so smart, but I've seen you naked."
    -- Barenaked Ladies, Blame it on Me
James Fleming | 4 Mar 2006 09:05

Re: POST variables in araneida

> James,
>   You might be interested in something like
<snip>
>   which will save you typing out a load of calls to BODY-PARAM, if  
> you're using form-encoded bodies.

Thankye kindly. I'm still slowly coming to grips with lisp, so this will
take a little while to digest. Looks rather useful, though.

>   Take a look in (IIRC) daemon.lisp to see how bodies are handled.  
I shall; thanks for the pointer.

> We had some discussion of this many moons ago.
Oops; my bad for forgetting to trawl the archives.

Thanks,
James

> -R
> 
> On 3 Mar 2006, at 20:00, James Fleming wrote:
> 
> >>Stupid question time: when using POST to submit a form, how do I
> >>retrieve the data sent by the browser?
> >
> >Embarrassing answer time: the clue I needed was on the Cliki page.
> >(request-body request) gives me what I need.
> >
> >In penance, I shall write a HOWTO for araneida, once I've gotten the
> >whole thing running.
(Continue reading)

Jonathon McKitrick | 10 Mar 2006 03:15

Cookie help, anyone?


Hi all,

I'm new to the list, and I'm using cl-ajax/araneida/sbcl for a webapp.  I'm at
the point where I need authorization, and I'm not sure where to start.

I've been asking Richard Newman some questions, but now that I found this
list, I'll try here.

I really only know enough http to get by.  I'm not quite sure how the handler
classes access cookies, and when.  I'm hoping someone could help me set up a
handler that on each file request, checks a cookie.  At least, I think that's
what I want.

-Jonathon
--
"I am sure that Jesus would use a command prompt.  Hello?  Ten Commandments??"
Alan Shields | 10 Mar 2006 07:22

Re: Cookie help, anyone?

On Fri, Mar 10, 2006 at 02:15:20AM +0000, Jonathon McKitrick wrote:
> I really only know enough http to get by.  I'm not quite sure how the handler
> classes access cookies, and when.  I'm hoping someone could help me set up a
> handler that on each file request, checks a cookie.  At least, I think that's
> what I want.

In test-server.lisp inside Araneida, find the line:

url: /authenticated/test

That contains some example code. It's pretty dumb, admittedly, but it does do the
trick.

You can use that form to handle authorization for any handler.

Now, as for cookies. The method REQUEST-COOKIE returns the string value
of the cookie (that is, the parsed value for the cookie). That should
get you started.

You can also use session variables, if you're of that bent. I believe
there's documentation in the doc/ directory on session variables.

Let us know if you have more questions.

Share and enjoy,
Alan
--

-- 
"I hate to advocate drugs, alcohol, violence or insanity to anyone, but they've
always worked for me."
    -- Hunter S. Thompson
(Continue reading)

Naveen Garg | 10 Mar 2006 18:16
Picon

lisp / ubuntu and system identification agent / environment

I'd like to create a lisp agent / environment with system identification abilities like so:
environment:  a number that changes periodically or according to some rules maybe even randomly sometimes.
agent:  has methods to increment or decrement the current number in the environment
goal:  agent must learn when the next number is due to its actions or by environment determinism.
do you know if this has been done?
right now I'm bogged down in just switching my lisp server from allegro / windows onto sbcl or gnu/lisp and ubuntu...
does any one have any suggestions / help on which lisp to use and how to easily set it up?
I've been using allegro lisp / windows but would like to switch to more open software.
Thanks,
Naveen

_______________________________________________
lispweb mailing list
lispweb <at> red-bean.com
http://www.red-bean.com/mailman/listinfo/lispweb
James Fleming | 11 Mar 2006 05:21

Re: Cookie help, anyone?

Let's try this again, from the address that's actually subscribed to the
list. *facepalm* How did I manage to learn to type, again?

> I'm new to the list, and I'm using cl-ajax/araneida/sbcl for a webapp.  I'm at
> the point where I need authorization, and I'm not sure where to start.

Hi, Jonathon. I'm about to implement authorization in
apache/araneida/sbcl myself, but have the headstart of having done it in
other environments first. The bad news is that there are all sorts of
ways of doing it; the good news is that at least one of them should be
suited to what you need.

> I really only know enough http to get by.  I'm not quite sure how the handler
> classes access cookies, and when.

As Alan mentioned, the (request-cookie <request> <cookie-name>) method
will do that for you.

> I'm hoping someone could help me set up a
> handler that on each file request, checks a cookie.  At least, I think that's
> what I want.

Easy done:

(defmacro with-cookies (&body body)
  "Cookie-handling macro to save even more typing"
  `(let ((received-cookie (request-cookie request "session")))
     (setf received-cookie (set-cookie-if-needed received-cookie
request))
     , <at> body))

In this case, I'm retrieving a cookie called "session", and setting it
if it's absent. (set-cookie-if-needed) is a function of my own devising
which does what it sounds, but also does a bunch of housekeeping while
it's at it, so is a fraction too involved to post to the list. Unless,
of course, everybody really wants to laugh at my approach to
implementing a shopping cart.

What I do to make use of the cookie's value is wrap the handler method
in (with-cookies ), and refer to received-cookie when I want to check
their session ID. E.g:

(defmethod handle-request-response ((handler checkout)
									(method (eql :post))
									request)
  (with-cookies
    <method body goes here>))

The housekeeping stuff in (set-cookie-if-needed) checks whether they
already have a valid session, kills it if it's too old, and sets a new
cookie if necessary, storing it in the database on the way. It's amazing
how complex it can all get and how quickly. It's equally amazing a)how
compactly you can do it in lisp, and b)how fraggin' steep the learning
curve can be. Satisfying, though.

As an aside, I realised recently that I seemed to be encountering
nothing but frustration in writing this app; every time I tried to add a
new kind of functionality, there'd be a new puzzle to solve. Now, I love
puzzle-solving, which is why I play with these things, but it was
frustrating that I hadn't yet managed to implement a section entirely
with stuff I already knew. Eventually, I realised that once I'd figured
out how to do something, I'd thereafter do it so quickly and easily that
I just didn't notice doing it. The language itself is just naturally
almost frictionless.

For setting a cookie:

(request-send-headers request
	:set-cookie (list (cookie-string <name> <value>
						:max-age <maximum age in seconds>
						:domain <your domain goes here>)))

There are other attributes you can set, and neither of those are
madatory, iirc; they're just useful to me. This, of course, is at the
heart of (set-cookie-if-needed).

Just what kind of authorization system will suit you depends on exactly
what you need, though. Is it for the whole site? Certain functions?
Condition-dependent? Just certain sub-trees of the site? Do you have
apache in front of araneida? Do all users get the same access, or do you
need to grant different things to different user IDs?

I don't mean to intimidate with this; rather, I'll be happy to help you
zero in on what you need. My dayjob is e-commerce platform support for a
faceless megacorporate, so I've seen a stack of different ways of
securing things; some of them even seem to work :)

HTH,
James
--

-- 
Stupidity killed the cat.
Curiosity was framed.
_______________________________________________
lispweb mailing list
lispweb <at> red-bean.com
http://www.red-bean.com/mailman/listinfo/lispweb
Alan Shields | 11 Mar 2006 07:08

Re: Cookie help, anyone?

James,

Most of what you're doing there has been implemented in the
session code. Of course, it was probably implemented AFTER
you did your work, but that's how it goes, eh? ;-p

Give it a look see, and tell me what you think.

Yes, we solve that problem you were referring to.

Alan
--

-- 
"It's useful, being top banana in the shock department."
    -- Holly Golightly

Gmane