unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* eval and exceptions
@ 2008-08-10 17:34 Cedric Cellier
  2008-08-11  7:26 ` Maciek Godek
  0 siblings, 1 reply; 4+ messages in thread
From: Cedric Cellier @ 2008-08-10 17:34 UTC (permalink / raw)
  To: guile-user

Hi you all in there !

In the attempt to drastially reduce the work required for a little
project (a small wargame), I want to use guile to "box" the game engine
(that is to be) written in C. I also want the players GUI to be
connected to the game via sockets established by guile (15 lines of
code, 5s for cut and paste from the guile manual, thank you so much !)

To save even more lines of code, I would like the protocol between
clients and server to be merely scheme, that is : the client sends some
scheme command, like, say :

(with-player "Joe" (attack-other-player "Jim"))

and the guile main engine reads it and merely eval-string it.

The problem is : if the client, because of a bug or an
eroneous or malicious user input, sends a string that is not valid
scheme, the whole guile engine stops.

I would like to be able to catch those parsing errors out of the eval
and simply send back an error message to the faulty client, instead of
having the whole server to stop.

Is there a way to do this, or can you point me toward a better way to
achieve my goal ? I must confess I'm new to guile and to scheme, and
have not been deep into the manual yet.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: eval and exceptions
  2008-08-10 17:34 eval and exceptions Cedric Cellier
@ 2008-08-11  7:26 ` Maciek Godek
  2008-08-11  9:17   ` cedric cellier
  0 siblings, 1 reply; 4+ messages in thread
From: Maciek Godek @ 2008-08-11  7:26 UTC (permalink / raw)
  To: Cedric Cellier; +Cc: guile-user

Cedric Cellier:

> In the attempt to drastially reduce the work required for a little
> project (a small wargame), I want to use guile to "box" the game engine
> (that is to be) written in C. I also want the players GUI to be
> connected to the game via sockets established by guile (15 lines of
> code, 5s for cut and paste from the guile manual, thank you so much !)

What a coincidence!
I have also be working on a game engine that is to be written :)
More on it later.

> To save even more lines of code, I would like the protocol between
> clients and server to be merely scheme, that is : the client sends some
> scheme command, like, say :
>
> (with-player "Joe" (attack-other-player "Jim"))
>
> and the guile main engine reads it and merely eval-string it.
>
> The problem is : if the client, because of a bug or an
> eroneous or malicious user input, sends a string that is not valid
> scheme, the whole guile engine stops.

If the user is malicious you can have much more serious problems,
like user sending "((lambda(x)(x x))(lambda(x)(x x))" (so the operation
never returns), or "(system \"rm -rf .\")". The latter can be avoided by
simply removing the "system" function, but you have to be cautious.

> I would like to be able to catch those parsing errors out of the eval
> and simply send back an error message to the faulty client, instead of
> having the whole server to stop.
>
> Is there a way to do this, or can you point me toward a better way to
> achieve my goal ? I must confess I'm new to guile and to scheme, and
> have not been deep into the manual yet.

Well, you can call your "eval-string" inside a catch, for example:
(catch #t (lambda()(eval-string packet)) (lambda (key . args) #f))
it should work (refer to the manual for details -- in the third argument
you provide an exception handler, so instead of writing #f you can
send the error back to the client; likewise, the first argument is the
key that can be used to store the client info used by the handler)

I've been trying to address this problem by implementing a network
oriented object system. I'm still working on it and it's still far from
completion, but if you're interested, you can find the specification
in this list's archives:
http://lists.gnu.org/archive/html/guile-user/2008-07/msg00094.html

I think it's more sensible to restrict the protocol to allow
only certain functions to be remotely called -- rather than arbitrary
expressions (this way, some computation can be shifted to the
client more easily and you get a better design)

Either way, this can't be done in 5 seconds :)

Regards
M.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: eval and exceptions
  2008-08-11  7:26 ` Maciek Godek
@ 2008-08-11  9:17   ` cedric cellier
  2008-08-13 10:32     ` Maciek Godek
  0 siblings, 1 reply; 4+ messages in thread
From: cedric cellier @ 2008-08-11  9:17 UTC (permalink / raw)
  To: guile-user

> Well, you can call your "eval-string" inside a catch, for example:
> (catch #t (lambda()(eval-string packet)) (lambda (key . args) #f))

Yes, it works !
I've tried it with srfi-34 extention module (guard) but for some reason
guard does not catch this kind of errors, while the genuine catch works.
Thank you very much.

For the concern about malicious users I will address this later, when
and if eventually there will be any actual user :)

> I've been trying to address this problem by implementing a network
> oriented object system. I'm still working on it and it's still far from
> completion, but if you're interested, you can find the specification
> in this list's archives:
> http://lists.gnu.org/archive/html/guile-user/2008-07/msg00094.html

I will have a look, although honestly I don't think I will understand
anything. Scheme have a tendancy to quickly turn into black magic as
soon as quotations enter the play.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: eval and exceptions
  2008-08-11  9:17   ` cedric cellier
@ 2008-08-13 10:32     ` Maciek Godek
  0 siblings, 0 replies; 4+ messages in thread
From: Maciek Godek @ 2008-08-13 10:32 UTC (permalink / raw)
  To: cedric cellier; +Cc: guile-user

cedric cellier:

> For the concern about malicious users I will address this later, when
> and if eventually there will be any actual user :)

OK, let me know how's the progress sometime,
because I'm extremely interested in the topic

>> I've been trying to address this problem by implementing a network
>> oriented object system. I'm still working on it and it's still far from
>> completion, but if you're interested, you can find the specification
>> in this list's archives:
>> http://lists.gnu.org/archive/html/guile-user/2008-07/msg00094.html
>
> I will have a look, although honestly I don't think I will understand
> anything. Scheme have a tendancy to quickly turn into black magic as
> soon as quotations enter the play.

Well, certainly scheme is magic :)
It really isn't so difficult (during the first reading just go on if you
don't understand something). I'd be more than pleased to explain it
to you if you were interested. (my biggest problem to work on the
project is the lack of motivation, since there's no one to motivate
me -- and I think we both have more or less the same goals)




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-13 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-10 17:34 eval and exceptions Cedric Cellier
2008-08-11  7:26 ` Maciek Godek
2008-08-11  9:17   ` cedric cellier
2008-08-13 10:32     ` Maciek Godek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).