ãã®ã¬ãã¥ãŒã¯ã圌ãã®ã¹ã¿ãŒãã¢ããã®æªæ¥ããã®çŽ æŽãããèšèªã«å§ããããšã決å®ïŒãŸãã¯æ±ºå®ïŒãã人ã
ã®ããã®å°ããªã¬ã€ãã§ãã äž»ã«ãŠã§ãéçºã«éç¹ã眮ããããšããäºå®ã«ãããããããç§ã¯Common Lispã«é¢é£ããäœããã®äžè¬çãªãããã¯ãã«ããŒããããšããŸãã è³æã¯ã
AlterMobyèªèº«ã®WebéçºçµéšããåéãããŸãã
ãã®ã¬ãã¥ãŒã®3çªç®ã®éšåã¯ãHunchentoot WebãµãŒããŒã«åœãŠãããŸãã ãã®ã¢ãŒããã¯ãã£ãšåºæ¬æ©èœãæ€èšããŠãã ããã ããã«ãããã€ãã®é¢é£ããåé¡ãç¹ã«HTML / XMLã®çæã«è§ŠããŸãã
WebãµãŒããŒã®éžæ
ãã®ã¬ãã¥ãŒã®
æåŸã®éšåã§æå°éã®Lispã·ã¹ãã ããããã€ããåŸãWebãµãŒããŒãéžæããŸãã ãã®è³ªåã¯æããã§ã¯ãããŸãã-åãCLikiã¯7ã€ã®ç°ãªãã©ã€ãã©ãªãžã®ãªã³ã¯ãæäŸããŸãã ä»äºçšã«WebãµãŒããŒãéžæãããšããããã€ãã®èŠå ããé²ããŸããã ãŸããCLã³ãã¥ããã£ã§åºãç¥ãããå¹
åºãæ奜家ã«æ¯ããããææ°ã®ãã®ã§ãªããã°ãªããŸããã 第äºã«ãå°ãªããšã1ã€ã®ææãªWebãã¬ãŒã ã¯ãŒã¯ãããã«åºã¥ããŠããå¿
èŠããããŸãã ããã«ãããã«åºã¥ããŠåæ¥çã«æåãããµã€ãã®å¯çšæ§ã確èªããããšããå§ãããŸãã ãããã®åºæºã«åºã¥ããŠã2ã€ã®è£œåïŒPortable AllegroServãšHunchentootïŒã ããç§ã®èŠéã«å
¥ã£ãŠããŸããã
ããŒã¿ãã«AllegroServã¯ãAllegro CLå°çšã«äœæããããªãªãžãã«ã®WebãµãŒããŒã§ãã
AllegroServã®ããŒãžã§ã³ã§ãã åŸè
ã®ãœãŒã¹ã³ãŒãã¯ããã€ãã£ãã³ã³ãã€ã©ã®éæšæºã®æ¡åŒµæ©èœã䜿çšãããããCommon Lispãšäºææ§ããããŸããã å®éã®ãšãããAllegroServã®äœæè
ã¯æ倧ã®å¹çãéæããããšãããããå³å¯ãªåºæºããã®éžè±ãäœåãªããããŸããã ãã®çµæãé«éã§ãšã¬ã¬ã³ããªWebãµãŒããŒãã§ããŸãããããã¯ãããããä»æ¥ã®Allegro CLã«ãšã£ãŠæé©ãªéžæè¢ã§ãã AllegroServã®ãœãŒã¹ã³ãŒãã¯LLGPLã©ã€ã»ã³ã¹ã®äžã§ãªãªãŒã¹ããããããæšæºã®Common Lispã«ãããé©åãããæ奜家ãããŸããã åŸããã補åã¯ãPortable AllegroServãšåŒã°ããŠããŸããã äžéšã®ãªã¹ããŒã«ããã°ãåŸè
ã¯ããã©ãŒãã³ã¹ãšä¿¡é Œæ§ã®äž¡æ¹ã«ãããŠããªãªãžãã«ãããå£ã£ãŠããŸãã
ã¬ãã¥ãŒã®ãã®éšåã®äž»åœ¹ã§ãããå¥åŠãªååã®
Hunchentootãæã€WebãµãŒããŒã¯ãæåã¯æšæºã®Common Lispã«ãã£ãŠã¬ã€ããããŠããŸããã ãããã«äœ¿ãããã®ã§ãã»ãšãã©ã®äžè¬çãªã³ã³ãã€ã©ã§åäœããŸãã ç§ã«ãšã£ãŠãHunchentootãæ¯æããéèŠãªè°è«ã¯ãææãªWebãã¬ãŒã ã¯ãŒã¯
Weblocksã«åºã¥ããŠãããšããäºå®
ã§ãã ã ãããžã§ã¯ãã§ãã®ãã¬ãŒã ã¯ãŒã¯ã䜿çšããããšãæçµçã«æåŠãããšããäºå®ã«ãããããããHunchentootã¯ç§ãå
šã倱æãããŸããã§ããã 次ã«ããã®çŽ ââæŽããã補åã®æ§é ãšæ©èœãæ€èšããŸãã
Hunchentootã®çŽ¹ä»
ãŸããHunchentootãã€ã³ã¹ããŒã«ããããšã確èªããŠãã ããã
( asdf:oos 'asdf:load-op :hunchentoot )
次ã«ã
ã¢ã¯ã»ãã¿ãŒã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ïŒhttpãªã¯ãšã¹ãã¬ã·ãŒããŒïŒãäœæããŠå®è¡ããŸãã
( hunchentoot:start ( make-instance 'hunchentoot:acceptor :port 8080 ))
HunchentootãhttpsèŠæ±ãåãå
¥ããããšãã§ããããã«ã蚌ææžãšããŒãã¡ã€ã«ã®æå®ãå¿ããã«ã
ãacceptor ãã
ãssl-acceptor ïŒãã®åå«ïŒ
ãã«çœ®ãæããå¿
èŠããããŸãã
Hunchentootãã«ãããååŸããæãåçŽãªãã³ãã©ãŒãèããŠã¿ãŸãããã
( hunchentoot:define-easy-handler ( say-yo :uri "/yo" ) ( name )
( setf ( hunchentoot:content-type* ) "text/plain" )
( format nil "Hey~@[ ~a~]!" name ))
ãã®ãã³ãã©ãŒã¯say-yoãšåŒã°ããURL / yoã«ãã€ã³ãããåäžã®ååãã©ã¡ãŒã¿ãŒãååŸããŸãïŒGETãŸãã¯POSTçµç±ïŒã ãã³ãã©ãŒã¯ããHey nameïŒããå«ãããã¹ãããã¥ã¡ã³ããçæããŸããnameã¯nameãã©ã¡ãŒã¿ãŒã®å€ããŸãã¯nameãã©ã¡ãŒã¿ãŒãæå®ãããŠããªãå ŽåïŒã€ãŸããnilïŒã¯åã«ãHeyïŒãã§ãã è€éãªæååãã©ãŒãããã«æ··ä¹±ããŠããå Žåã¯ã
ãã©ãŒãããé¢æ°ãã£ã¬ã¯ãã£ãã確èªããŠãã ããã / yoããã³/ yoïŒã«ç§»åããŠããã®ãã³ãã©ãŒã®åäœã確èªããŸããïŒName = Vasiaã
ããã¹ãã®ä»£ããã«ããã³ãã©ãŒã¯ç®çã®ãã¡ã€ã«ãæäŸã§ããŸãã
( hunchentoot:define-easy-handler ( get-file :uri "/file" ) ( name )
( handle-static-file ( format nil "/home/me/folder/~a" name ))
ååãšããŠããã®æ©èœã¯å°ããªã¢ããã¥ã¢ã¯ã©ãããäœæããã®ã«ååãªã¯ãã§ãã ããæ·±å»ãªäœæ¥ã§ã¯ããã¯ã
define-easy-handlerãæŸæ£ãããªã¯ãšã¹ãããã£ã¹ãããããã¡ã«ããºã ãç解
ããå¿
èŠããããŸãã åŸè
ã®äž»ãªæ©èœã®æŠèŠã説æããŸãã
ã¢ã¯ã»ãã¿ãŒã¯ã©ã¹ïŒããã³
ssl-acceptorã¯ã©ã¹ ïŒã®åã€ã³ã¹ã¿ã³ã¹ã«ã¯ã
ãªã¯ãšã¹ããããŒãžã£ãŒããããŸãã ãªã¯ãšã¹ããããŒãžã£ãŒã¯ã
ãªã¯ãšã¹ãã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ïŒhttpãªã¯ãšã¹ãïŒãåãåããåºåhttpã¹ããªãŒã ïŒHTML / XMLãŸãã¯ãã€ããªããŒã¿ïŒãè¿ãé¢æ°ã§ãã åºåã¹ããªãŒã ã¯æå®ãããURLã«äŸåãããããå®éã«ã¯ãã¯ãšãªãããŒãžã£ãŒã¯ãããçæããããã®ããŒã«ãå§ä»»ããé©åãªãã³ãã©ãŒãæ€çŽ¢ããŸãã ããã©ã«ãã§ã¯ãQuery Managerã¯
ãã£ã¹ãããé¢æ°ãå«ã
* dispatch-table *ãªã¹ããã¹ãã£ã³
ããŸã ã åã¹ã±ãžã¥ãŒãªã³ã°é¢æ°ã¯ãèŠæ±ãªããžã§ã¯ããåãå
¥ãããã®åºæºã«åŸã£ãŠåæããäžèŽããå Žåã¯
ãã³ãã©ãŒãè¿ããŸããåºåã¹ããªãŒã ãçæããé¢æ°ã§ãïŒäžèŽããªãå Žåã¯nilãè¿ããŸãïŒã ãããã£ãŠãæšæºãªã¯ãšã¹ããããŒãžã£ã¯ããã£ã¹ãããé¢æ°ã®1ã€ããã³ãã©ãŒãè¿ããŸã§ãã£ã¹ãããé¢æ°ãéå§ããŸãã
* dispatch-table *ã®æåŸã«
㯠ãéåžž
default-dispatcherããã
ãŸã -åžžã«ãã³ãã©ãŒãè¿ããã£ã¹ãããé¢æ°ã§ãïŒããã©ã«ãã§ã¯ãããã¯ããŒãžãèŠã€ãããªããšããã¡ãã»ãŒãžã§ãïŒã
äžèšã®ã¹ã±ãžã¥ãŒãªã³ã°æ¹åŒã¯ããè€éã«èŠãããããããŸããããå®éã«ã¯ããã®ãããªæ§é ã¯å€§ããªæè»æ§ãå¯èœã«ããŸãã ç¹ã«ããã³ãã©ãŒãªã¿ãŒã³ã¢ãããŒãã䜿çšãããšããšã¬ã¬ã³ããªãã£ã¹ãããé¢æ°ãäœæã§ããŸãã
define-easy-handlersãã¯ãã«ãã£ãŠäœæããããã£ã¹ããããã³ãã©ãŒã¯ã次ã®æšæºã¹ããŒã ã䜿çšã
ãŸã ã
* dispatch-table *ã¯
dispatch-easy-handlersãã£ã¹ãããé¢æ°ãå«ã¿ãŸãã åŸè
ã¯ãåçŽåããããã£ã¹ãããã£ãå®è£
ããç¬èªã®å
éšãªã¹ãã調ã¹ãŸãã ãã®ãªã¹ãã«ã¯ã
define-easy-handlersã§
å®çŸ©ããããã¹ãŠã®ãã³ãã©ãŒã®èª¬æãå«ãŸããŠã
ãŸã ã ãããã£ãŠãã¹ã±ãžã¥ãŒãªã³ã°ã¯ããã³ãã©ãŒãéžæããããã®ç¬èªã®ããžãã¯ãæã€å€ãã®ç¬ç«ãããã©ã³ãã«åå²ã§ããŸãã
Hunchentootã¯
ãæšæºçãªãã£ã¹ãããé¢æ°ã®ããã€ãã®
ãžã§ãã¬ãŒã¿ãŒãšãããã€ãã®
æšæºçãªãã³ãã©ãŒãå®çŸ©ããŠã
ãŸã ã ããšãã°ãæå®
ãããURLãã¬ãã£ãã¯ã¹ããã³ãã³ãã©ãŒã«ãã
create-prefix-dispatcherã¯ãURLãªã¯ãšã¹ããæå®ããããã¬ãã£ãã¯ã¹ã«æºæ ããŠãããã©ããããã§ãã¯ãããã£ã¹ãããé¢æ°ãçæããŸãã
create-regex-dispatcheré¢æ°ã¯åã®ãã®ãšäŒŒãŠããŸãããURLãç¹å®ã®æ£èŠè¡šçŸãã¿ãŒã³ã«ãããã³ã°ãããã£ã¹ãããé¢æ°ãçæããŸãã
create-folder-dispatcher-and-handleré¢æ°ã¯ãURLãã¬ãã£ãã¯ã¹ãšãã£ã¬ã¯ããªãã¹ãåãå
¥ããæå®ããããã£ã¬ã¯ããªãããã¡ã€ã«ãé
åžãããã£ã¹ãããé¢æ°ãè¿ããŸãã æšæºãã³ãã©ã«ã¯ãget-fileã®å®çŸ©ã§äœ¿çšãã
handle-static-fileãå«ãŸããŸãã
Common Lispã®æè»æ§ã«ããããªã³ã¶ãã©ã€ã§æ¢åã®é¢æ°ãšã¡ãœãããåå®çŸ©ã§ããŸããããã¯ãHunchentootã®æè»æ§ã«è²¢ç®ããããåŸãŸããã ãã®æ¹æ³ã§ã¯ã
ã¢ã¯ã»ãã¿ã¯ã©ã¹ã®æ°ããåå«ãäœæã§ããã ãã§ãªããäžèšã®ãã³ãã©æ€çŽ¢ã¹ããŒã ãå®å
šã«æŸæ£ããããšã§ããã©ã«ãã®ãã£ã¹ãããã£ããªãŒããŒã©ã€ããããããªã¯ãšã¹ãåŠçããžãã¯ãå®å
šã«å€æŽãããã§ããŸãã ããšãã°ãç§ã®ãããžã§ã¯ãã«åãçµãéçšã§ãHunchentootã«ãããŒã¿ãããŠã³ããŒãããããã»ã¹äžã«ããã«ãããŒã/ãã©ãŒã ããŒã¿ãªã¯ãšã¹ãã®åœ¢åŒããã§ãã¯ãããå®å
šã«åãå
¥ããåŸã§ã¯ãããŸããã ããã«ãããDoSæ»æäžã«å€ãã®ãã·ã³ããã«ãã¡ã¬ãã€ãã®ã¬ããŒãžããµãŒããŒã«éä¿¡ããç¶æ³ãåé¿ã§ããŸãã
匷åã§ææ°ã®WebãµãŒããŒãšããŠãHunchentootã¯å€ãã®æšæºæ©èœããµããŒãããŠããŸãã ãããã«ã¯ãCookieã®ãµããŒãã䟿å©ãªãããã°ãšãã®ã³ã°ãªã©ãå«ãŸããŸãã WebããŒãžã§ãã®æ©èœã®èª¬æãèŠã€ããããšãã§ããŸãã
HTML / XMLçæ
ã¬ãã¥ãŒã®ãã®éšåãç· ããããããã«ãHTML / XMLãçæããããã®ã·ã³ãã«ã§äŸ¿å©ãªDSLãå®çŸ©ãã
CL-WHOã©ã€ãã©ãªãæ€èšããŠãã ããã ãã€ãã®ããã«ãäžåºŠèŠãã»ããããã§ãïŒ
( push :tag3 *html-empty-tags* )
( with-html-output-to-string ( http-stream )
( :tag1 :attr1 1 :attr2 "2"
( :tag2 :attr3 ( + 1 2 ))
( loop for i from 1 to 3 do
( with-html-output ( http-stream )
( :tag3 :attr4 ( when ( oddp i ) "odd" ))))))
ãã®æ§é ã®çµæã¯çŽèŠ³ãšççŸããŸããïŒ
"<tag1 attr1='1' attr2='2'><tag2 attr3='3'></tag2>
<tag3 attr4='odd' /><tag3 /><tag3 attr4='odd' /></tag1>"
ã芧ã®ãšããã
with-html-output-to-stringãã¯ãã¯ããã®s-expressionã«å¯Ÿå¿ããéå§ã¿ã°ãšçµäºã¿ã°ããXMLã³ã³ã¹ãã©ã¯ããæ§ç¯ããŸãã æåã®ã³ãã³ãã¯ãåäžã¿ã°ã®ãªã¹ãã«tag3ã¿ã°ãè¿œå ããŸãã ãã®ãããªã¿ã°ã®å Žåãæ·»ä»ãã¡ã€ã«ããªãå Žåãçµäºã¿ã°ã¯çæãããŸããã 次ã«ã
with-html-output-to-stringãã¯ããåŒã³åºãããŸããããã¯ãã¡ã€ã³CL-WHOãã¯ãã§ãã
with-html-outputã®ã©ãããŒã§ãã ãã®äŸãããããããã«ãä»»æã®å¶åŸ¡æ§é ã䜿çšããŠã³ãŒãçæãèªååã§ããŸãã
çµæã®æååã¯XMLã¢ãŒãã§äœæãããŸããã ãã®ã¢ãŒãã§ã¯ãXML / XHTMLããã¥ã¡ã³ããçæãã䟡å€ããããŸãã HTMLã䜿çšããå Žåã¯ã空ã®ã¿ã°ã«çµäºã¹ã©ãã·ã¥ãå«ãŸããªãSGMLã¢ãŒãããããå±æ§ã«ã¯å€ããªããŠãããŸããŸããã Hunchentootã®å Žåã®ããã«ãCL-WHOãããã«è©³ãã玹ä»ããããã«ãWebããŒãžã«éããŸãã