development release newLISP v.9.9.91

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

development release newLISP v.9.9.91

Post by Lutz »

• more changes towards version 10.0

files and changes notes: http://www.newlisp.org/downloads/development

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Last newlisp-tk.exe is no more running with 9.9.91

One change is needed in newlisp-tk.tcl to get it back running:

Code: Select all

(define (net-read-line socket buff)
        (net-receive socket buff 1000 "\n")
        (set 'buff (chop (eval buff))))	;buff now quoted for 9.991
Edit: With this change demo.lsp runs fine.
Hans-Peter

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Lutz,

The ! and utf8 extention in the manual is very usefull for quick information.

Is it possible to extent it with function that return float and integer too?

Something im realy realy missing in the manual is a quick-list
of all functions that return 'nil or return "out of bound...." or empty lists..



Errors in the manual 9991->

define &nbap;! should be define !


PS: "System Symbols and Constants" nice addon table ...
PPS: I like those chinese examples inside the doc! very nice..
(utf8-len "我能吞下玻璃而不伤身体。") → 12
(length "我能吞下玻璃而不伤身体。") → 36
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Lutz,

A question regarding ->

***
New 'net-interface' allows selecting a default network interface card on
multihoned network nodes. In previous versions only net-listen could
specify a specific interface IP address, now a different interface card can also
be selected for outgoing communications by changing the default IP-address.
***

Why would you limit this to multihomed-Nic's ?

If you would remove that limitation the function 'net-interface is able
to realtime switch ip-identity's without being on a multihomed machine.

This is particular usefull for packet forwarding to different remote machines.
Where the remote machines expect the originator address
and not the ip-address of the man-in-the-middle.

personaly i would remove the limitation of "being" multihomed and
make net-interface variable by forcing the source-ip address from
net-interface into the packet...

PS: on tcp its upto the remote to make sure the originator ip exists
its not upto the sender...

Norman.


PS: edited... I looked into the C code and you actualy dont do anything..
You arnt even touching the tcp packets...mmmm... pitty ;-)
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

personally i would remove the limitation of "being" multihomed and
make net-interface variable by forcing the source-ip address from
net-interface into the packet...
'net-interface' will let you configure whatever IP the OS allows you with normal user access rights and whatever that machine is configured for. Address spoofing is not allowed and to implement that, you would need special access rights for raw socket access. 'net-ping' does this, but needs newLISP to be run in super-user mode.

There are so many utilities available in the UNIX word for packet forwarding, IP configuration etc. In my opinion it is not wise to burden newLISP with this. The exception is 'net-ping', where a minimum is done to support node discovery in a network for distributed applications.

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

The system variable $status-header can be set to a different string. Currently
"HTTP/1.0 200 OK\r\n" is the fixed response. As an example for a no response
header you would specify:
(set '$status-header "HTTP/1.0 204 No Response\r\n")
So I tried this in my code and it doesn't appear to work...

Take a look, I'm using a heavily modified version of Jeff's Response class (see the print-header function):

Code: Select all

(context 'Response)

;; mark Public API

(define (Response:Response str)
	(_response 200 str)
)

(define (redirect path)
	(header "Location" path)
	(_response 302)
)

(define (not-found str)
	(_response 404 str)
)

(define (error str)
	(_response 500 str)
)

;; mark Headers

;; add the header with key and associated value to the list of headers
;; replaces the old value if key is already in there
(define (header key val)
	(set 'key (join (map title-case (parse key "-")) "-"))
	(if (member key _headers)
    	(setf (assoc key _headers) (list key val))
    	(push (list key val) _headers)
	)
)

(define (header? key)
	(lookup key _headers)
)

(define (headers)
	_headers
)


;; mark Cookies

(define (set-cookie key value domain path expires)
	(if (cookie-set? key '? domain path)
		(delete-cookie key domain path)
	)
	(push (list key value domain path expires) _cookies -1)
)


;; needs to check for set cookies in _cookies and remove
(define (delete-cookie key domain path)
	(if (cookie-set? key '? domain path)
		(pop _cookies (find (list key '? domain path '?) _cookies match))
		(set-cookie key nil domain path (date-value))
	)
)

; NOTE: bug fixed: definition was (cookie-set? key domain path)
(define (cookie-set? key value domain path)
	(true? (find (list key value domain path '?) _cookies match))
)

;; mark Private API

; returns a string version ready for sending to browser of the cookie
(define (_format-cookie key value domain path expires)
	;; expires must be timestamp (use date-value)
	(set 'value (if value (string value) ""))
	(let (cookie "")
		(write-buffer cookie (format "%s=%s;" key value))
		(if domain (write-buffer cookie (format "; domain=.%s" domain)))
		(if path (write-buffer cookie (format "; path=%s" path)))
		(if expires (write-buffer cookie (format "; expires=%s" (date (int expires) 0 "%a, %d %b %Y %H:%M:%S %Z"))))
		cookie
	)
)

; hack to get it work on both newlisp and apache because of bug in newlisp
(define (print-header code , header)
	; (if (env "SERVER_PROTOCOL")
	; 	(println "Status: " code " " (lookup code _response-codes))
	; 	(println "HTTP/1.0 " code " " (lookup code _response-codes))
	; )
	(set 'header (string code " " (lookup code _response-codes)))
	(set '$status-header (append "HTTP/1.0 " header "\r\n")) ; for newlisp
	(println "Status: " header)
)

;; http://en.kioskea.net/contents/internet/http.php3
;; http://hoohoo.ncsa.uiuc.edu/cgi/out.html

;; NOTE: completely changed
(define (_response code content)
	(print-header code)
	(dolist (hdrs _headers) (println (hdrs 0) ": " (hdrs 1)))
	(dolist (cookie _cookies) (println "Set-Cookie: " (apply _format-cookie cookie)))
	(println "Content-type: " _content-type "\n")
	(print (string content))
	(exit)
)

;; mark Private variables

(set '_response-codes
  '((200 "OK")
	(302 "Found")
    (404 "Not Found")
    (500 "Internal Error"))
)

(set '_content-type "text/html; charset=utf-8")
(set '_headers '())
(set '_cookies '())

(context MAIN)
Get your Objective newLISP groove on.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Yes, its not working, wait for the next development version 9.9.92, November 1st.

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

Lutz wrote:Yes, its not working, wait for the next development version 9.9.92, November 1st.
No probs! Thanks again!
Get your Objective newLISP groove on.

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

newdep wrote:"我能吞下玻璃而不伤身体。"
"I can swallow down the glass not to burst oneself the body."

o.O

Locked