r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Pekr
27-Dec-2005
[2994x3]
read-cgi ...
it distinguishes two types, get or post ...
it uses simple loop - read-io ....
Terry
27-Dec-2005
[2997x3]
Look.. here's  what I'm trying to build with Rebol   http://www.uniformserver.com/
 

a fully powered webserver you can take with you on a USB Stick or 
even your camera's flash drive.
even has .htaccess security
I'm just so tired monkey wrenching Rebol
Pekr
27-Dec-2005
[3000]
what is monkey wrenching?
Terry
27-Dec-2005
[3001]
trying to get things to work
Pekr
27-Dec-2005
[3002]
to get things work? you can create rebol server in one page script. 
That it is not complete solution like uniformserver? well, it is 
not .... if something is not available out of the box, you simply 
have to code it yourself ...
Terry
27-Dec-2005
[3003]
exactly.. like I've got nothihg better to do than build a webserver 
in Rebol that can handle POST data.l..
Ladislav
27-Dec-2005
[3004]
you must be kidding, aren't you?
Pekr
27-Dec-2005
[3005x3]
Ladislav, Terry is different then us - his motives are not to use 
rebol only. He is more pragmatic - while he likes rebol, he misses 
some already done solution in rebol land. He might be right, from 
his pov. His intention is to build some system, using existing components. 
The trouble is, that he can actually use rebol, but then he can easily 
find himself implementing specific details of server e.g., but his 
intention lays in some upper layers of architecture ....
I still think, that in his particular case though, implementing small 
web-server would be rather trivial task though. There are some examples 
available ...
more trouble comes with licensing of the server, if he want to encap 
it, and yet he wants to provide kind of cgi (plug-ins) to run rebol 
scripts - then he violates the license imo ...
Ladislav
27-Dec-2005
[3008x2]
 like I've got nothihg better to do than build a webserver in Rebol 
 that can handle POST data

 - I have seen nothing capable of convincing anybody such a webserver 
 was distributed as a mezzanine?
Moreover, there already are third party solutions to this specific 
problem as far as I know.
Pekr
27-Dec-2005
[3010x2]
I don't fully understand your mezzanine comment :-)
yes, at rebol.org, small webserver ... even one provided by Carl 
iirc ...
Ladislav
27-Dec-2005
[3012]
it is directly meant as a comment to "monkey wrenching REBOL"
Pekr
27-Dec-2005
[3013x4]
my experince, sometimes is, than rather then to incorporate thrid 
party technology, learning its tricks etc., I implement simpler (yet 
not so capable) solution myself ...
in that regard, I wanted to ask Ladislav, about security - is it 
possible to protect system words, even to not be unprotected? :-) 
Imagine rebol would use system/locale for things like system messages 
in order to be translatable, but then someone could change the strings, 
which could be big security risk (user answering to different question)
posted originally in rt qa group, I did not notice I am chatting 
there, sorry ...
what about kind of protect/with 'value 'key ?
Ladislav
27-Dec-2005
[3017]
you cannot protect mutable values, even if you protect the words. 
Is that an answer to your question?
Pekr
27-Dec-2005
[3018]
yes .... I thought so, but then I thought maybe there will be some 
way of how to do it :-)
Ladislav
27-Dec-2005
[3019]
only one - make a value you don't want to be changed immutable. The 
problem is, that REBOL does not have immutable strings, blocks, functions 
or objects.
Pekr
27-Dec-2005
[3020x2]
what about extending secure scheme? to allow e.g. pre-boot, post-boot 
changes etc.? hmm, not sure it has a solution in my particular case, 
e.g. that I would like to hae system/locale translated, but then 
blocked against the changes ...
just thinking loud, sorry if nonsenses :-)
Ladislav
27-Dec-2005
[3022]
the only solution to your problem is to make your values immutable. 
The trouble is, that REBOL does not have immutable datatypes you 
might need
Pekr
27-Dec-2005
[3023x3]
ok, thanks ...
but that would not solve my case, if RT would do system/locale immutable, 
then I would not be able to change it. I though about protection 
by some kind of key, e.g., but dunno if it might work. at first change 
the key would be provided, for unprotect, the key would be needed 
...
Ladislav - one more - can you imagine subinterpreter? e.g. you have 
kind of rebol interpreter master server in your school, then you 
have students, global context gets cloned for them and all they do 
they can do like in normal rebol, just that their scripts are executed 
in subcontext :-) hmm, maybe it would be easier to launch new interpreter 
for them anyway ... :-)
Ladislav
27-Dec-2005
[3026]
:-) On the other hand, this is a question of philosophy. RT did not 
forbid you to change the data, because they felt you may have a good 
reason to do so. Your "philosophy" is opposite - you think, that 
your users may not have a good reason to change the data.
Pekr
27-Dec-2005
[3027]
I just came to the request by simply thinking about localisation 
and how it can be missued. E.g. "do you want your file to be deleted?" 
could be replaced by "Do you want to keep your file?" :-)
Ladislav
27-Dec-2005
[3028]
Right you are, the above is possible in English too and it may be 
considered a safety problem in some circumstances as I pointed out 
quite long ago.
Volker
27-Dec-2005
[3029x6]
post-webserver: Cals %webserv.r with
read-cgi: func [/local data len] [
    either system/options/cgi/request-method = "POST" [

        set-modes system/ports/input [lines: false binary: true no-wait: 
        false]
        len: to-integer system/options/cgi/content-length
        data: to-string copy/part system/ports/input len
    ] [
        data: system/options/cgi/query-string
    ]
    data
 ]
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=webserv.r
I patched it a bit to be more verbose: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=volkswebserv.r

But that one has bugs after a few calls. Don't know about webserv.r 
itself, i guess it is more stable.
protecting system/locale: if user cant run code, user cant change 
it. if user can run code, he does not need to change those strings.
(my volkswebserv.r is for debugging, to show errors and such in console. 
So i can live with that instability.
Gabriele
28-Dec-2005
[3035]
if REBOL 3 is going to support modules, then it will provide the 
kind of security requested by Petr.
Pekr
28-Dec-2005
[3036]
well, I believe that rebol 3 will actually support modules, as it 
will be kind of main product release, which can afford new ideas 
here or there and new incompatibilities here or there, if done for 
good. The only question is of course the timing - Rebol 3 in two 
years? :-)
JaimeVargas
29-Dec-2005
[3037x2]
Any one interested in getting this ?

>> printf ["%10.2E %s" to decimal! 1000 "dinar"]
  1.00E+03 dinar
>> sprintf ["%10.2E %s" to decimal! 1000 "dinar"]
== "  1.00E+03 dinar"
It is an actual wrap of the C printf routines.
Graham
29-Dec-2005
[3039]
Lots of people have asked for a printf in the past.
JaimeVargas
29-Dec-2005
[3040x4]
Here it is consider it why-wire's team new years gift. team: [cyphre 
ladislav jaime]
Rebol []

comment [
	; example usage:
	kernel: load/library %kernel32.dll

 routine-call kernel "MulDiv" [int] [3 [integer!] 2 [integer!] 1 [integer!]] 
 ; == 6
]

routine-call: func [
	library [library!]
	routine-name [string!]
	return-spec [block!]
	arguments [block!] 

 /typed {Arguments is block structure is: [argument-value [datatype] 
 ...]}
	/local routine spec call argument type typed-rule
] [
	spec: make block! length? arguments
	call: make block! (length? arguments) / 2 + 1
	insert call [return routine]
	typed-rule: copy []
	if typed [typed-rule: [set type skip]]
	parse reduce arguments [
		any [
			set argument skip
			typed-rule
			(
				insert/only tail spec 'argument
				insert/only tail spec either typed [
					type
				][
					reduce [type?/word get/any 'argument]
				]
				insert/only tail call get/any 'argument
			)
		]
	]
	insert tail spec [return:]
	insert/only tail spec return-spec
	routine: make routine! spec library routine-name
	do call
]

use [libc zero-char as-rebol-string malloc][
	libc: load/library %/usr/lib/libc.dylib ; osx variable

	zero-char: #"^@"

	as-rebol-string: func [
		[catch]
		s [string!] 
		/local pos
	][

  unless pos: find s zero-char [throw make error! "s is not a c-string"]
		s: head remove/part pos tail s
		replace/all s "\n" newline
		replace/all s "\t" tab
	]
	
	malloc: func [
        size [integer!] "size in bytes"
    ][
        head insert/dup copy {} zero-char size
    ]

	sprintf: func [
		spec {block structure is: [format values ...]}
		/local s
	][
		s: malloc 4096
		insert/only head spec 's
		routine-call libc "sprintf" [int] spec
		as-rebol-string s
	]
	
	printf: func [
		spec {block structure is: [format values ...]}
	][
		print sprintf spec
	]
]
You need to change the location of your libc. The code above is hard 
coded for OSX.
Now is possible to pretty print things with short code ;-)


>> repeat i 3 [printf reduce ["%2d-station%s" i either i > 1 ["s"][""]]] 
 1-station
 2-stations
 3-stations