Skip to content

Commit ebdb44b

Browse files
committed
going back to previous directory structure, or rather, a similar one, so that it's simple to load the stuff in dragonfly-framework. the other way, though better organized, makes it difficult to know where the dragonfly-framework is without forcing the user to manually enter it in
--HG-- rename : dragonfly/README.txt => CHANGES rename : site/databases/blog.nldb => databases/blog.nldb rename : site/databases/main.sqlite => databases/main.sqlite rename : dragonfly/.htaccess => dragonfly-framework/.htaccess rename : dragonfly/config/dragonfly_config.lsp => dragonfly-framework/config/dragonfly_config.lsp rename : dragonfly/config/dragonfly_routes.lsp => dragonfly-framework/config/dragonfly_routes.lsp rename : dragonfly/docs/dragonfly.lsp.html => dragonfly-framework/docs/dragonfly.lsp.html rename : dragonfly/docs/dragonfly.lsp.src.html => dragonfly-framework/docs/dragonfly.lsp.src.html rename : dragonfly/docs/index.html => dragonfly-framework/docs/index.html rename : dragonfly/dragonfly.lsp => dragonfly-framework/dragonfly.lsp rename : site/favicon.ico => favicon.ico rename : site/includes/css/forms.css => includes/css/forms.css rename : site/includes/css/screen.css => includes/css/screen.css rename : site/includes/css/twitter.css => includes/css/twitter.css rename : site/includes/images/houses.jpg => includes/images/houses.jpg rename : site/includes/images/logo.pxm => includes/images/logo.pxm rename : site/includes/images/marchildmann-com.gif => includes/images/marchildmann-com.gif rename : site/includes/images/tip-pimped.gif => includes/images/tip-pimped.gif rename : site/includes/images/tip-rounded.gif => includes/images/tip-rounded.gif rename : site/includes/images/tip.gif => includes/images/tip.gif rename : site/includes/js/dragonfly.js => includes/js/dragonfly.js rename : site/index.cgi => index.cgi rename : site/views/404 => views/404 rename : site/views/blog => views/blog rename : site/views/dragonfly_ajax => views/dragonfly_ajax rename : site/views/dragonfly_ajax-date => views/dragonfly_ajax-date rename : site/views/dragonfly_ajax-twitter => views/dragonfly_ajax-twitter rename : site/views/dragonfly_debug => views/dragonfly_debug rename : site/views/dragonfly_rssfeed => views/dragonfly_rssfeed rename : site/views/dragonfly_seo => views/dragonfly_seo rename : site/views/dragonfly_tables => views/dragonfly_tables rename : site/views/dragonfly_twitter => views/dragonfly_twitter rename : site/views/dragonfly_welcome => views/dragonfly_welcome rename : site/views/partials/doctype => views/partials/doctype rename : site/views/partials/footer => views/partials/footer rename : site/views/partials/header => views/partials/header rename : site/views/partials/navigation => views/partials/navigation
1 parent 24f9e3f commit ebdb44b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+474
-7
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dragonfly/config/dragonfly_config.lsp renamed to dragonfly-framework/config/dragonfly_config.lsp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
(context 'Dragonfly)
66

7+
; location of newlisp shared directory (for module support)
8+
(constant 'newlisp-dir "/usr/share/newlisp")
9+
710
; setting a defaultview
811
(constant 'defaultview "dragonfly_welcome")
912
; setting a defaultaction
File renamed without changes.

dragonfly/dragonfly.lsp renamed to dragonfly-framework/dragonfly.lsp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
(constant 'http-400 "Status: 400 Bad Request\r\n")
4747
(constant 'http-401 "Status: 401 Unauthorized\r\n")
4848
(constant 'http-403 "Status: 403 Forbidden\r\n")
49-
(constant 'http-404 "Status: Not Found\r\n")
50-
(constant 'http-410 "Status: Gone\r\n")
51-
(constant 'http-500 "Status: Internal Server Error\r\n")
49+
(constant 'http-404 "Status: 404 Not Found\r\n")
50+
(constant 'http-410 "Status: 410 Gone\r\n")
51+
(constant 'http-500 "Status: 500 Internal Server Error\r\n")
5252

5353
(constant 'http-html-header "Content-Type: text/html; charset=utf-8\r\nConnection: keep-alive\r\n")
5454
(constant 'http-xml-header "Content-Type: text/xml; charset=utf-8\r\nConnection: keep-alive\r\n")
@@ -336,9 +336,7 @@
336336
;; <p>Evaluates the partial and returns it.</p>
337337
;;
338338
(define (partial partialname)
339-
(set 'path-to-partials partials-path)
340-
(push partialname path-to-partials -1)
341-
(Web:eval-template (read-file path-to-partials))
339+
(Web:eval-template (read-file (append partials-path partialname)))
342340
)
343341

344342
;; @syntax (Dragonfly:title <websitename>)

dragonfly-framework/lib/request.lsp

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
;;; Note: POST data can only be read once, after which it becomes unavailable
2+
;;; to future parts of the program. Should the default cgi.lsp module precede
3+
;;; this module, POST data will be unavailable through the Request class. If
4+
;;; cgi.lsp is loaded after this module, POST data is unavailable to it.
5+
6+
;;; This module does not include output functions, including setting cookies.
7+
;;; That will be part of the Response class. The Response class may also
8+
;;; include a session framework; any session data will be available through this
9+
;;; class (once designed).
10+
11+
(context MAIN)
12+
13+
; globals must be delcared in MAIN context
14+
(unless (number? *max-post-length*)
15+
(set '*max-post-length* 1002537))
16+
17+
(global '*max-post-length*)
18+
19+
(context 'Request)
20+
21+
;; mark Public API
22+
23+
(define (method) _method)
24+
(define (segments) _segments)
25+
(define (raw-query) _rawQuery)
26+
(define (post-length) _postLength)
27+
(define (binary?) _binaryData)
28+
(define (get?) (= _method 'GET))
29+
(define (post?) (= _method 'POST))
30+
(define (cookie? key) (lookup key _cookies))
31+
32+
(define (get key)
33+
(if key
34+
(lookup key _get)
35+
_get
36+
)
37+
)
38+
39+
(define (post key)
40+
(if key
41+
(lookup key _post)
42+
_post
43+
)
44+
)
45+
46+
(define (cookies key)
47+
(if key
48+
(lookup key _cookies)
49+
_cookies
50+
)
51+
)
52+
53+
(define (segment num)
54+
(if-not (>= _current-segment (- (length _segments) 1))
55+
(nth (if num num (inc _current-segment)) _segments)
56+
(begin (set '_current-segment -1) nil) ; reset current_segment and return nil
57+
)
58+
)
59+
60+
;; mark Private API
61+
62+
;; (url-translate "What+time+is+it%3f") => "What time is it?"
63+
(define (url-translate str)
64+
(replace "+" str " ")
65+
(replace "%([0-9A-F][0-9A-F])" str (format "%c" (int (append "0x" $1))) 1)
66+
)
67+
68+
(define (parse-query query-string , (params '()) pair)
69+
(dolist (element (parse query-string "&"))
70+
(set 'pair (parse element "="))
71+
(if (= 1 (length pair))
72+
(push nil pair -1)
73+
(setf (pair 1) (url-translate (last pair)))
74+
)
75+
(push pair params -1)
76+
)
77+
params
78+
)
79+
80+
(define (regex-captcha regex-str str (options 0) (captcha 1))
81+
(if (regex regex-str str options)
82+
($ captcha)
83+
)
84+
)
85+
86+
(define (parse-multipart-chunk chunk boundary-len, idx disp var val data (params '()))
87+
(set 'idx (find "Content-Disposition" chunk))
88+
89+
(when idx
90+
(set 'chunk (idx (length chunk) chunk))
91+
(set 'disp (0 (find "\r\n" chunk) chunk))
92+
93+
(when disp
94+
(set 'var (regex-captcha {name="(.*)"} disp 512))
95+
96+
(when var
97+
(set 'data ((+ 4 (find "\r\n\r\n" chunk)) (length chunk) chunk))
98+
(set 'idx (find "\r\n--" data))
99+
100+
(when idx
101+
(set 'data (0 idx data))
102+
103+
(if (set 'val (regex-captcha (string var {="(.*)"}) disp 512))
104+
(begin
105+
(push (list var val) params -1)
106+
(push (list (append var "_data") data) params -1)
107+
(push (list (append var "_length") (length data)) params -1)
108+
)
109+
(push (list var data) params -1)
110+
)
111+
)
112+
)
113+
)
114+
)
115+
params
116+
)
117+
118+
(define (parse-multipart-query , buff bytes-read boundary-len (params '()))
119+
(set 'boundary (regex-captcha {boundary=(.*)} contentType))
120+
(set 'boundary-len (length boundary))
121+
(set '_postLength 0)
122+
123+
(while (set 'bytes-read (read-buffer (device) post-data *max-post-length* boundary))
124+
(inc _postLength bytes-read)
125+
(write-buffer _rawQuery post-data)
126+
(dolist (param (parse-multipart-chunk post-data boundary-len))
127+
(push param params -1)
128+
)
129+
)
130+
params
131+
)
132+
133+
;; mark Go!
134+
135+
; (set '_cgi-keys '("REDIRECT_STATUS" "HTTP_HOST" "HTTP_USER_AGENT" "HTTP_ACCEPT"
136+
; "HTTP_ACCEPT_LANGUAGE" "HTTP_ACCEPT_ENCODING" "HTTP_ACCEPT_CHARSET"
137+
; "HTTP_KEEP_ALIVE" "HTTP_CONNECTION" "HTTP_COOKIE" "HTTP_CACHE_CONTROL" "PATH"
138+
; "SERVER_SIGNATURE" "SERVER_SOFTWARE" "SERVER_NAME" "SERVER_ADDR" "SERVER_PORT"
139+
; "REMOTE_ADDR" "DOCUMENT_ROOT" "SERVER_ADMIN" "SCRIPT_FILENAME" "REMOTE_PORT"
140+
; "REDIRECT_URL" "GATEWAY_INTERFACE" "SERVER_PROTOCOL" "REQUEST_METHOD"
141+
; "QUERY_STRING" "REQUEST_URI" "SCRIPT_NAME" "PATH_INFO" "PATH_TRANSLATED")
142+
; )
143+
;; this shit isn't necessary, just use (env) ====== NO! it could return nil! which is not a string!
144+
;; set cleaned CGI environment parameters
145+
146+
; TODO: unset this, but make it simply create the variables instead (e.g. (set 'REQUEST_URI (env "REQUEST_URI")))
147+
; (set '_cgi-env (map (fn (key) (list key (trim (string (env key))))) _cgi-keys))
148+
149+
(set '_cookies '() '_post '() '_rawQuery "")
150+
(set '_method 'GET) ; set default method
151+
(set '_segments (parse (trim (env "REQUEST_URI") "/") "/"))
152+
(set '_current-segment -1)
153+
(set 'path (env "REQUEST_URI"))
154+
(set 'domain (env "HTTP_HOST"))
155+
(set 'contentType (string (env "CONTENT_TYPE")))
156+
(set '_binaryData (and contentType (not (or (starts-with contentType "text" 1) (find "form" contentType 1)))))
157+
158+
;; deal with GET params from QUERY_STRING
159+
(set '_rawQuery (env "QUERY_STRING"))
160+
(set '_get (parse-query _rawQuery))
161+
162+
163+
;; deal with POST params from stdin data
164+
165+
(if (starts-with contentType "multipart/form" nil)
166+
(begin
167+
(set '_method 'POST)
168+
(set '_post (parse-multipart-query))
169+
)
170+
(begin
171+
(set '_postLength (read-buffer (device) post-data *max-post-length*))
172+
(when post-data
173+
(set '_method 'POST)
174+
(if-not _binaryData
175+
(set '_post (parse-query post-data))
176+
)
177+
(set '_rawQuery post-data)
178+
)
179+
)
180+
)
181+
182+
;; deal with HTTP_COOKIE data
183+
(dolist (element (parse (string (env "HTTP_COOKIE")) ";"))
184+
(push (parse element "=") _cookies -1)
185+
)
186+
187+
(context MAIN)

dragonfly-framework/lib/response.lsp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
(context 'Response)
2+
3+
;; mark Public API
4+
5+
(define (Response:Response str)
6+
(_response 200 str)
7+
)
8+
9+
(define (redirect path)
10+
(header "Location" path)
11+
(_response 302)
12+
)
13+
14+
(define (not-found str)
15+
(_response 404 str)
16+
)
17+
18+
(define (error str)
19+
(_response 500 str)
20+
)
21+
22+
;; mark Headers
23+
24+
;; add the header with key and associated value to the list of headers
25+
;; replaces the old value if key is already in there
26+
(define (header key val)
27+
(set 'key (join (map title-case (parse key "-")) "-"))
28+
(if (member key _headers)
29+
(setf (assoc key _headers) (list key val))
30+
(push (list key val) _headers)
31+
)
32+
)
33+
34+
(define (header? key)
35+
(lookup key _headers)
36+
)
37+
38+
(define (headers)
39+
_headers
40+
)
41+
42+
43+
;; mark Cookies
44+
45+
(define (set-cookie key value domain path expires)
46+
(if (cookie-set? key '? domain path)
47+
(delete-cookie key domain path)
48+
)
49+
(push (list key value domain path expires) _cookies -1)
50+
)
51+
52+
53+
;; needs to check for set cookies in _cookies and remove
54+
(define (delete-cookie key domain path)
55+
(if (cookie-set? key '? domain path)
56+
(pop _cookies (find (list key '? domain path '?) _cookies match))
57+
(set-cookie key nil domain path (date-value))
58+
)
59+
)
60+
61+
; NOTE: bug fixed: definition was (cookie-set? key domain path)
62+
(define (cookie-set? key value domain path)
63+
(true? (find (list key value domain path '?) _cookies match))
64+
)
65+
66+
;; mark Private API
67+
68+
; returns a string version ready for sending to browser of the cookie
69+
(define (_format-cookie key value domain path expires)
70+
;; expires must be timestamp (use date-value)
71+
(set 'value (if value (string value) ""))
72+
(let (cookie "")
73+
(write-buffer cookie (format "%s=%s" key value))
74+
(if expires (write-buffer cookie (format "; expires=%s" (date (int expires) 0 "%a, %d %b %Y %H:%M:%S %Z"))))
75+
(if path (write-buffer cookie (format "; path=%s" path)))
76+
(if domain (write-buffer cookie (format "; domain=%s" domain)))
77+
cookie
78+
)
79+
)
80+
81+
; hack to get it work on both newlisp and apache because of bug in newlisp
82+
(define (print-header code , header)
83+
; (if (find "newLISP" (env "SERVER_SOFTWARE"))
84+
; (println "HTTP/1.0 " code " " (lookup code _response-codes) "\r\n")
85+
; (println "Status: " code " " (lookup code _response-codes) "\r\n")
86+
; )
87+
88+
(print "Status: " code " " (lookup code _response-codes) "\r\n")
89+
90+
; (set 'header (string code " " (lookup code _response-codes)))
91+
; (set '$status-header (append "HTTP/1.0 " header "\r\n")) ; for newlisp
92+
; (println "Status: " header)
93+
)
94+
95+
;; http://en.kioskea.net/contents/internet/http.php3
96+
;; http://hoohoo.ncsa.uiuc.edu/cgi/out.html
97+
98+
;; NOTE: completely changed
99+
(define (_response code content)
100+
; (print-header code)
101+
(print "Status: " code " " (lookup code _response-codes) "\r\n")
102+
(dolist (hdrs _headers) (print (hdrs 0) ": " (hdrs 1) "\r\n"))
103+
(dolist (cookie _cookies) (print "Set-Cookie: " (apply _format-cookie cookie) "\r\n"))
104+
(print "Content-type: " _content-type "\r\n\r\n")
105+
(print (string content))
106+
(exit)
107+
)
108+
109+
;; mark Private variables
110+
111+
(set '_response-codes
112+
'((200 "OK")
113+
(302 "Found")
114+
(404 "Not Found")
115+
(500 "Internal Error"))
116+
)
117+
118+
(set '_content-type "text/html; charset=utf-8")
119+
(set '_headers '())
120+
(set '_cookies '())
121+
122+
(context MAIN)

dragonfly-framework/lib/utils.lsp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
;; NOTE: it's OK to load this file multiple times
2+
3+
;; Copyright (C) <2009> <Greg Slepak>
4+
;;
5+
;; This program is free software: you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
;;
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
;; You should have received a copy of the GNU General Public License
15+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
;;
17+
;; @module Dragonfly
18+
;; @author Greg Slepak <greg at taoeffect.com>
19+
20+
(context 'Dragonfly)
21+
22+
(define (load-once)
23+
; check if the last argument is a context (to behave like 'load' does)
24+
(let (ctx (let (_ctx (last $args)) (if (context? _ctx) _ctx MAIN)))
25+
(doargs (file)
26+
(unless (or (context? file) (find file _loaded))
27+
(push file _loaded)
28+
(Dragonfly:saved-load file ctx)
29+
)
30+
)
31+
)
32+
)
33+
34+
; We define our own module function so that we can easily support
35+
; shared hosting services where the modules directory might not be
36+
; in /usr/share/newlisp/modules.
37+
(define (module module-to-load)
38+
(if-not newlisp-dir (throw-error "need value 'newlisp-dir' from dragonfly_config.lsp!"))
39+
(load-once (append newlisp-dir "/modules/" module-to-load))
40+
)
41+
42+
(context 'MAIN)
43+
44+
; swap the MAIN functions for ours
45+
(unless Dragonfly:saved-load
46+
(constant 'Dragonfly:saved-load MAIN:load)
47+
(constant 'MAIN:load Dragonfly:load-once)
48+
(constant 'MAIN:module Dragonfly:module)
49+
)
File renamed without changes.

0 commit comments

Comments
 (0)