-
Notifications
You must be signed in to change notification settings - Fork 30
/
publish.cl
3211 lines (2668 loc) · 101 KB
/
publish.cl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; -*- mode: common-lisp; package: net.aserve -*-
;;
;; publish.cl
;;
;; See the file LICENSE for the full license governing this code.
;; Description:
;; publishing urls
;;- This code in this file obeys the Lisp Coding Standard found in
;;- http://www.franz.com/~jkf/coding_standards.html
;;-
(in-package :net.aserve)
(eval-when (compile) (declaim (optimize (speed 3))))
(defclass entity ()
;; an object to be published
;; host and port may be nil, meaning "don't care", or a list of
;; items or just an item
((host
:initarg :host
:initform nil
:reader host)
(port :initarg :port
:initform nil
:reader port)
(path :initarg :path
:reader path
:initform "--unspecified-path--"
)
(location :initarg :location
:reader location)
(prefix :initarg :prefix
:initform nil
:reader prefix)
(last-modified :initarg :last-modified
:accessor last-modified
:initform nil ; means always considered new
)
; ut string format for last-modified cached here.
(last-modified-string :initarg :last-modified-string
:accessor last-modified-string
:initform nil)
(format :initarg :format ;; :text or :binary
:initform :text
:reader entity-format)
(content-type :initarg :content-type
:reader content-type
:initform nil)
; can be a single object or a list of objects
(authorizer :initarg :authorizer
:accessor entity-authorizer
:initform nil)
; if not nil then the timeout to be used in a with-http-response
; for this entity
(timeout :initarg :timeout
:initform nil
:accessor entity-timeout)
; property list for storing info on this entity
(plist :initarg :plist
:initform nil
:accessor entity-plist)
; function of 3 args (req ent extra) called between
; with-http-request and with-http-body for entity types
; where the user has no control (i.e. non function types)
(hook :initarg :hook
:initform nil
:accessor entity-hook)
; cons holding extra headers to send with this entity
(headers :initarg :headers
:initform nil
:accessor entity-headers)
; if true then aserve is permitted (but not required) to
; send this entity back compressed. There is also a
; global compress switch in the wserver object that must be true
; in order for compression to be done
(compress :initarg :compress
:initform t
:accessor entity-compress)
; extra holds random info we need for a particular entity
(extra :initarg :extra :reader entity-extra)
;; should aserve auto-send a 100 Continue response for
;; this entity if an 'Expect: 100-continue' header is
;; in the request.
(will-handle-expect-continue
:initarg :will-handle-expect-continue
:initform nil
:reader entity-will-handle-expect-continue)
))
(defclass file-entity (entity)
;; a file to be published
(
(file :initarg :file :reader file)
(contents :initarg :contents :accessor contents
:initform nil)
(cache-p
;; true if the contents should be cached when accessed
:initarg :cache-p
:initform nil
:accessor cache-p)
))
(defclass computed-entity (entity)
;; entity computed each time it's called
((function :initarg :function :reader entity-function)))
(defvar *dummy-computed-entity*
;; needed when intercepting and sending a computed entity in place
;; of the entity being published
(make-instance 'computed-entity))
(defvar *redirect-computed-entity*
(make-instance 'computed-entity
:function #'(lambda (req ent)
(with-http-response (req ent
:response *response-moved-permanently*)
(setf (reply-header-slot-value req :location) (request-redirect-to req))
(with-http-body (req ent))))))
(defclass access-file-mixin ()
;; slots needed if you want to use access files during
;; the handling of this entity
; if non-nil the name of the file to look for in directories to
; personalize the creation of file entities
((access-file :initarg :access-file
:initform nil
:accessor directory-entity-access-file)
; internal slot used to cache the files we've read
; is a list of
; (whole-access-filename last-write-dat cached-value)
;
(access-file-cache :initform nil
:accessor directory-entity-access-file-cache)
))
(defclass directory-entity (entity access-file-mixin)
;; entity that displays the contents of a directory
((directory :initarg :directory ; directory to display
:reader entity-directory)
(prefix :initarg :prefix ; url prefix pointing to ths dir
:reader prefix
:initform "")
(recurse :initarg :recurse ; t to descend to sub directories
:initform nil
:reader recurse)
(cache-p
;; settting for file entities created:
;; true if the contents should be cached when accessed
:initarg :cache-p
:initform nil
:accessor cache-p)
; list of name of files that can be used to index this directory
(indexes :initarg :indexes
:initform nil
:accessor directory-entity-indexes)
; filter is nil or a function of req ent filename info
; which can process the request or return nil
(filter :initarg :filter
:initform nil
:accessor directory-entity-filter)
;: fcn of req ent realname
; it should create and publish an entity and return it
(publisher :initarg :publisher
:initform nil
:accessor directory-entity-publisher)
(hidden-index-redirect
:initform nil
:initarg :hidden-index-redirect
:reader directory-hidden-index-redirect)
))
(defclass special-entity (entity)
;; used to hold a certain body we want to always return
;; nil means we'll return no body
((content :initform nil
:initarg :content
:reader special-entity-content)))
(setq *not-modified-entity* (make-instance 'special-entity))
;; the multi-entity contains list of items. the items can be
;;
;; atom - assumed to be a namestring or pathname that can be opened
;; function - function to run to compute a result
;; function takes req ent last-modified-time
(defclass multi-entity (entity)
;; handle multiple files and compute entities
((items
;; list of multi-item structs
:initarg :items
:reader items)
(content-length :initform 0
:accessor multi-entity-content-length))
)
(defstruct multi-item
kind ; :file, :function
data ; for :file, the filename for :function the function
cache ; nil or unsigned-byte 8 array
last-modified)
;;-------- locators - objects which find the entity to return
(defclass locator ()
((name :initform :unnamed
:initarg :name
:reader locator-name)
; info is where the locator will likely store data related
; to mapping
(info :initform nil
:initarg :info
:accessor locator-info)
; for random extra info
(extra :initarg :extra :reader locator-extra)
))
(defclass locator-exact (locator)
;; used to map specific uri paths to entities
;; the table slot holds the hash table that's used
()
(:default-initargs :info (make-hash-table :test #'equal)))
;; Mention class in make-instance after class def to avoid bug24329.
(defun make-instance-locator-exact+name (name)
(make-instance 'locator-exact :name name))
(defclass locator-prefix (locator)
;; use to map prefixes to entities
()
)
;; Mention class in make-instance after class def to avoid bug24329.
(defun make-instance-locator-prefix+name (name)
(make-instance 'locator-prefix :name name))
;; the info slot of a locator-prefix class is a list of
;; prefix-handler objects, sorted by the length of the path
;; (from longest to smallest).
(defstruct (prefix-handler (:type list))
path ;; string which must be the prefix of the url part to match
host-handlers ;; list of host-handlers
)
(defstruct (host-handler (:type list))
host ;; vhost object to match or :wild meaning match anything
entity ;; entity object to handle this request
)
; we can specify either an exact url or one that handles all
; urls with a common prefix.
;;
;; if the prefix is given as a list: e.g. ("ReadMe") then it says that
;; this mime type applie to file named ReadMe. Note that file types
;; are checked first and if no match then a filename match is done.
;
(defparameter *file-type-to-mime-type*
;; this list constructed by generate-mime-table in parse.cl
'(("application/EDI-Consent") ("application/EDI-X12")
("application/EDIFACT") ("application/activemessage")
("application/andrew-inset" "ez") ("application/applefile")
("application/atomicmail") ("application/batch-SMTP")
("application/beep+xml") ("application/cals-1840")
("application/commonground") ("application/cybercash")
("application/dca-rft") ("application/dec-dx") ("application/dvcs")
("application/eshop") ("application/http") ("application/hyperstudio")
("application/iges") ("application/index") ("application/index.cmd")
("application/index.obj") ("application/index.response")
("application/index.vnd") ("application/iotp") ("application/ipp")
("application/isup") ("application/font-tdpfr")
("application/mac-binhex40" "hqx")
("application/mac-compactpro" "cpt") ("application/macwriteii")
("application/marc") ("application/mathematica")
("application/mathematica-old") ("application/msword" "doc")
("application/news-message-id") ("application/news-transmission")
("application/ocsp-request") ("application/ocsp-response")
("application/octet-stream" "bin" "dms" "lha" "lzh" "exe" "class" "so"
"dll" "img" "iso")
("application/ogg" "ogg") ("application/parityfec")
("application/pdf" "pdf") ("application/pgp-encrypted")
("application/pgp-keys") ("application/pgp-signature")
("application/pkcs10") ("application/pkcs7-mime")
("application/pkcs7-signature") ("application/pkix-cert")
("application/pkix-crl") ("application/pkixcmp")
("application/postscript" "ai" "eps" "ps")
("application/prs.alvestrand.titrax-sheet") ("application/prs.cww")
("application/prs.nprend") ("application/qsig")
("application/remote-printing") ("application/riscos")
("application/rtf" "rtf") ("application/sdp")
("application/set-payment") ("application/set-payment-initiation")
("application/set-registration")
("application/set-registration-initiation") ("application/sgml")
("application/sgml-open-catalog") ("application/sieve")
("application/slate") ("application/smil" "smi" "smil")
("application/timestamp-query") ("application/timestamp-reply")
("application/vemmi") ("application/vnd.3M.Post-it-Notes")
("application/vnd.FloGraphIt") ("application/vnd.accpac.simply.aso")
("application/vnd.accpac.simply.imp") ("application/vnd.acucobol")
("application/vnd.aether.imp")
("application/vnd.anser-web-certificate-issue-initiation")
("application/vnd.anser-web-funds-transfer-initiation")
("application/vnd.audiograph") ("application/vnd.businessobjects")
("application/vnd.bmi") ("application/vnd.canon-cpdl")
("application/vnd.canon-lips") ("application/vnd.claymore")
("application/vnd.commerce-battelle") ("application/vnd.commonspace")
("application/vnd.comsocaller") ("application/vnd.contact.cmsg")
("application/vnd.cosmocaller") ("application/vnd.cups-postscript")
("application/vnd.cups-raster") ("application/vnd.cups-raw")
("application/vnd.ctc-posml") ("application/vnd.cybank")
("application/vnd.dna") ("application/vnd.dpgraph")
("application/vnd.dxr") ("application/vnd.ecdis-update")
("application/vnd.ecowin.chart")
("application/vnd.ecowin.filerequest")
("application/vnd.ecowin.fileupdate")
("application/vnd.ecowin.series")
("application/vnd.ecowin.seriesrequest")
("application/vnd.ecowin.seriesupdate") ("application/vnd.enliven")
("application/vnd.epson.esf") ("application/vnd.epson.msf")
("application/vnd.epson.quickanime") ("application/vnd.epson.salt")
("application/vnd.epson.ssf") ("application/vnd.ericsson.quickcall")
("application/vnd.eudora.data") ("application/vnd.fdf")
("application/vnd.ffsns") ("application/vnd.framemaker")
("application/vnd.fsc.weblaunch") ("application/vnd.fujitsu.oasys")
("application/vnd.fujitsu.oasys2") ("application/vnd.fujitsu.oasys3")
("application/vnd.fujitsu.oasysgp")
("application/vnd.fujitsu.oasysprs") ("application/vnd.fujixerox.ddd")
("application/vnd.fujixerox.docuworks")
("application/vnd.fujixerox.docuworks.binder")
("application/vnd.fut-misnet") ("application/vnd.grafeq")
("application/vnd.groove-account")
("application/vnd.groove-identity-message")
("application/vnd.groove-injector")
("application/vnd.groove-tool-message")
("application/vnd.groove-tool-template")
("application/vnd.groove-vcard") ("application/vnd.hhe.lesson-player")
("application/vnd.hp-HPGL") ("application/vnd.hp-PCL")
("application/vnd.hp-PCLXL") ("application/vnd.hp-hpid")
("application/vnd.hp-hps") ("application/vnd.httphone")
("application/vnd.hzn-3d-crossword")
("application/vnd.ibm.afplinedata") ("application/vnd.ibm.MiniPay")
("application/vnd.ibm.modcap") ("application/vnd.informix-visionary")
("application/vnd.intercon.formnet")
("application/vnd.intertrust.digibox")
("application/vnd.intertrust.nncp") ("application/vnd.intu.qbo")
("application/vnd.intu.qfx")
("application/vnd.irepository.package+xml") ("application/vnd.is-xpr")
("application/vnd.japannet-directory-service")
("application/vnd.japannet-jpnstore-wakeup")
("application/vnd.japannet-payment-wakeup")
("application/vnd.japannet-registration")
("application/vnd.japannet-registration-wakeup")
("application/vnd.japannet-setstore-wakeup")
("application/vnd.japannet-verification")
("application/vnd.japannet-verification-wakeup")
("application/vnd.koan") ("application/vnd.lotus-1-2-3")
("application/vnd.lotus-approach") ("application/vnd.lotus-freelance")
("application/vnd.lotus-notes") ("application/vnd.lotus-organizer")
("application/vnd.lotus-screencam") ("application/vnd.lotus-wordpro")
("application/vnd.mcd") ("application/vnd.mediastation.cdkey")
("application/vnd.meridian-slingshot") ("application/vnd.mif" "mif")
("application/vnd.minisoft-hp3000-save")
("application/vnd.mitsubishi.misty-guard.trustweb")
("application/vnd.mobius.daf") ("application/vnd.mobius.dis")
("application/vnd.mobius.msl") ("application/vnd.mobius.plc")
("application/vnd.mobius.txf") ("application/vnd.motorola.flexsuite")
("application/vnd.motorola.flexsuite.adsi")
("application/vnd.motorola.flexsuite.fis")
("application/vnd.motorola.flexsuite.gotap")
("application/vnd.motorola.flexsuite.kmr")
("application/vnd.motorola.flexsuite.ttc")
("application/vnd.motorola.flexsuite.wem")
("application/vnd.mozilla.xul+xml") ("application/vnd.ms-artgalry")
("application/vnd.ms-asf") ("application/vnd.ms-excel" "xls")
("application/vnd.ms-lrm") ("application/vnd.ms-powerpoint" "ppt")
("application/vnd.ms-project") ("application/vnd.ms-tnef")
("application/vnd.ms-works") ("application/vnd.mseq")
("application/vnd.msign") ("application/vnd.music-niff")
("application/vnd.musician") ("application/vnd.netfpx")
("application/vnd.noblenet-directory")
("application/vnd.noblenet-sealer") ("application/vnd.noblenet-web")
("application/vnd.novadigm.EDM") ("application/vnd.novadigm.EDX")
("application/vnd.novadigm.EXT")
("application/vnd.oasis.opendocument.chart" "odc")
("application/vnd.oasis.opendocument.database" "odb")
("application/vnd.oasis.opendocument.formula" "odf")
("application/vnd.oasis.opendocument.graphics" "odg")
("application/vnd.oasis.opendocument.graphics-template" "otg")
("application/vnd.oasis.opendocument.image" "odi")
("application/vnd.oasis.opendocument.presentation" "odp")
("application/vnd.oasis.opendocument.presentation-template" "otp")
("application/vnd.oasis.opendocument.spreadsheet" "ods")
("application/vnd.oasis.opendocument.spreadsheet-template" "ots")
("application/vnd.oasis.opendocument.text" "odt")
("application/vnd.oasis.opendocument.text-master" "odm")
("application/vnd.oasis.opendocument.text-template" "ott")
("application/vnd.oasis.opendocument.text-web" "oth")
("application/vnd.osa.netdeploy") ("application/vnd.palm")
("application/vnd.pg.format") ("application/vnd.pg.osasli")
("application/vnd.powerbuilder6") ("application/vnd.powerbuilder6-s")
("application/vnd.powerbuilder7") ("application/vnd.powerbuilder7-s")
("application/vnd.powerbuilder75")
("application/vnd.powerbuilder75-s")
("application/vnd.previewsystems.box")
("application/vnd.publishare-delta-tree")
("application/vnd.pvi.ptid1") ("application/vnd.pwg-xhtml-print+xml")
("application/vnd.rapid") ("application/vnd.s3sms")
("application/vnd.seemail")
("application/vnd.shana.informed.formdata")
("application/vnd.shana.informed.formtemplate")
("application/vnd.shana.informed.interchange")
("application/vnd.shana.informed.package") ("application/vnd.sss-cod")
("application/vnd.sss-dtf") ("application/vnd.sss-ntf")
("application/vnd.street-stream")
("application/vnd.sun.xml.writer" "sxw")
("application/vnd.sun.xml.writer.template" "stw")
("application/vnd.sun.xml.calc" "sxc")
("application/vnd.sun.xml.calc.template" "stc")
("application/vnd.sun.xml.draw" "sxd")
("application/vnd.sun.xml.draw.template" "std")
("application/vnd.sun.xml.impress" "sxi")
("application/vnd.sun.xml.impress.template" "sti")
("application/vnd.sun.xml.writer.global" "sxg")
("application/vnd.sun.xml.math" "sxm") ("application/vnd.svd")
("application/vnd.swiftview-ics")
("application/vnd.symbian.install" "sis")
("application/vnd.triscape.mxs") ("application/vnd.trueapp")
("application/vnd.truedoc") ("application/vnd.tve-trigger")
("application/vnd.ufdl") ("application/vnd.uplanet.alert")
("application/vnd.uplanet.alert-wbxml")
("application/vnd.uplanet.bearer-choice-wbxml")
("application/vnd.uplanet.bearer-choice")
("application/vnd.uplanet.cacheop")
("application/vnd.uplanet.cacheop-wbxml")
("application/vnd.uplanet.channel")
("application/vnd.uplanet.channel-wbxml")
("application/vnd.uplanet.list")
("application/vnd.uplanet.list-wbxml")
("application/vnd.uplanet.listcmd")
("application/vnd.uplanet.listcmd-wbxml")
("application/vnd.uplanet.signal") ("application/vnd.vcx")
("application/vnd.vectorworks")
("application/vnd.vidsoft.vidconference") ("application/vnd.visio")
("application/vnd.vividence.scriptfile") ("application/vnd.wap.sic")
("application/vnd.wap.slc") ("application/vnd.wap.wbxml" "wbxml")
("application/vnd.wap.wmlc" "wmlc")
("application/vnd.wap.wmlscriptc" "wmlsc")
("application/vnd.webturbo") ("application/vnd.wrq-hp3000-labelled")
("application/vnd.wt.stf") ("application/vnd.xara")
("application/vnd.xfdl") ("application/vnd.yellowriver-custom-menu")
("application/whoispp-query") ("application/whoispp-response")
("application/wita") ("application/wordperfect5.1")
("application/x-apple-diskimage" "dmg")
("application/x-bcpio" "bcpio") ("application/x-bittorrent" "torrent")
("application/x-bzip2" "bz2") ("application/x-cdlink" "vcd")
("application/x-chess-pgn" "pgn") ("application/x-compress")
("application/x-cpio" "cpio") ("application/x-csh" "csh")
("application/x-director" "dcr" "dir" "dxr")
("application/x-dvi" "dvi") ("application/x-futuresplash" "spl")
("application/x-gtar" "gtar") ("application/x-gzip" "gz" "tgz")
("application/x-hdf" "hdf") ("application/x-java-archive" "jar")
("application/x-javascript" "js") ("application/x-kword" "kwd" "kwt")
("application/x-kspread" "ksp")
("application/x-kpresenter" "kpr" "kpt")
("application/x-kchart" "chrt") ("application/x-killustrator" "kil")
("application/x-koan" "skp" "skd" "skt" "skm")
("application/x-latex" "latex") ("application/x-netcdf" "nc" "cdf")
("application/x-rpm" "rpm") ("application/x-sh" "sh")
("application/x-shar" "shar") ("application/x-shockwave-flash" "swf")
("application/x-stuffit" "sit") ("application/x-sv4cpio" "sv4cpio")
("application/x-sv4crc" "sv4crc") ("application/x-tar" "tar")
("application/x-tcl" "tcl") ("application/x-tex" "tex")
("application/x-texinfo" "texinfo" "texi")
("application/x-troff" "t" "tr" "roff")
("application/x-troff-man" "man") ("application/x-troff-me" "me")
("application/x-troff-ms" "ms") ("application/x-ustar" "ustar")
("application/x-wais-source" "src") ("application/x400-bp")
("application/xhtml+xml" "xhtml" "xht") ("application/xml")
("application/xml-dtd") ("application/xml-external-parsed-entity")
("application/zip" "zip") ("audio/32kadpcm")
("audio/basic" "au" "snd") ("audio/g.722.1") ("audio/l16")
("audio/midi" "mid" "midi" "kar") ("audio/mp4a-latm")
("audio/mpa-robust") ("audio/mpeg" "mpga" "mp2" "mp3")
("audio/parityfec") ("audio/prs.sid") ("audio/telephone-event")
("audio/tone") ("audio/vnd.cisco.nse") ("audio/vnd.cns.anp1")
("audio/vnd.cns.inf1") ("audio/vnd.digital-winds")
("audio/vnd.everad.plj") ("audio/vnd.lucent.voice")
("audio/vnd.nortel.vbk") ("audio/vnd.nuera.ecelp4800")
("audio/vnd.nuera.ecelp7470") ("audio/vnd.nuera.ecelp9600")
("audio/vnd.octel.sbc") ("audio/vnd.qcelp")
("audio/vnd.rhetorex.32kadpcm") ("audio/vnd.vmx.cvsd")
("audio/x-aiff" "aif" "aiff" "aifc") ("audio/x-mpegurl" "m3u")
("audio/x-pn-realaudio" "ram" "rm") ("audio/x-realaudio" "ra")
("audio/x-wav" "wav") ("audio/x-ms-wma" "wma")
("audio/x-ms-wax" "wax") ("chemical/x-pdb" "pdb")
("chemical/x-xyz" "xyz") ("image/bmp" "bmp") ("image/cgm")
("image/g3fax") ("image/gif" "gif") ("image/ief" "ief")
("image/jpeg" "jpeg" "jpg" "jpe") ("image/naplps") ("image/png" "png")
("image/prs.btif") ("image/prs.pti") ("image/svg+xml" "svg")
("image/tiff" "tiff" "tif")
("image/vnd.cns.inf2") ("image/vnd.djvu" "djvu" "djv")
("image/vnd.dwg") ("image/vnd.dxf") ("image/vnd.fastbidsheet")
("image/vnd.fpx") ("image/vnd.fst") ("image/vnd.fujixerox.edmics-mmr")
("image/vnd.fujixerox.edmics-rlc") ("image/vnd.mix")
("image/vnd.net-fpx") ("image/vnd.svf") ("image/vnd.wap.wbmp" "wbmp")
("image/vnd.xiff") ("image/x-cmu-raster" "ras")
("image/x-portable-anymap" "pnm") ("image/x-portable-bitmap" "pbm")
("image/x-portable-graymap" "pgm") ("image/x-portable-pixmap" "ppm")
("image/x-rgb" "rgb") ("image/x-xbitmap" "xbm")
("image/x-xpixmap" "xpm") ("image/x-xwindowdump" "xwd")
("message/delivery-status") ("message/disposition-notification")
("message/external-body") ("message/http") ("message/news")
("message/partial") ("message/rfc822") ("message/s-http")
("model/iges" "igs" "iges") ("model/mesh" "msh" "mesh" "silo")
("model/vnd.dwf") ("model/vnd.flatland.3dml") ("model/vnd.gdl")
("model/vnd.gs-gdl") ("model/vnd.gtw") ("model/vnd.mts")
("model/vnd.vtu") ("model/vrml" "wrl" "vrml")
("multipart/alternative") ("multipart/appledouble")
("multipart/byteranges") ("multipart/digest") ("multipart/encrypted")
("multipart/form-data") ("multipart/header-set") ("multipart/mixed")
("multipart/parallel") ("multipart/related") ("multipart/report")
("multipart/signed") ("multipart/voice-message") ("text/calendar")
("text/css" "css") ("text/directory") ("text/enriched")
("text/html" "html" "htm") ("text/parityfec")
("text/plain" "asc" "txt") ("text/prs.lines.tag")
("text/rfc822-headers") ("text/richtext" "rtx") ("text/rtf" "rtf")
("text/sgml" "sgml" "sgm") ("text/tab-separated-values" "tsv")
("text/t140") ("text/uri-list") ("text/vnd.DMClientScript")
("text/vnd.IPTC.NITF") ("text/vnd.IPTC.NewsML") ("text/vnd.abc")
("text/vnd.curl") ("text/vnd.flatland.3dml") ("text/vnd.fly")
("text/vnd.fmi.flexstor") ("text/vnd.in3d.3dml")
("text/vnd.in3d.spot") ("text/vnd.latex-z")
("text/vnd.motorola.reflex") ("text/vnd.ms-mediapackage")
("text/vnd.sun.j2me.app-descriptor" "jad") ("text/vnd.wap.si")
("text/vnd.wap.sl") ("text/vnd.wap.wml" "wml")
("text/vnd.wap.wmlscript" "wmls") ("text/x-setext" "etx")
("text/xml" "xml" "xsl") ("text/xml-external-parsed-entity")
("text/yaml" "yaml")
("video/mp4v-es") ("video/mpeg" "mpeg" "mpg" "mpe")
("video/parityfec") ("video/pointer") ("video/quicktime" "qt" "mov")
("video/vnd.fvt") ("video/vnd.motorola.video")
("video/vnd.motorola.videop") ("video/vnd.mpegurl" "mxu")
("video/vnd.mts") ("video/vnd.nokia.interleaved-multimedia")
("video/vnd.vivo") ("video/x-flv" "flv")
("video/x-ms-asf" "asf" "asx") ("video/x-ms-wm" "wm")
("video/x-ms-wmv" "wmv") ("video/x-ms-wmx" "wmx")
("video/x-ms-wvx" "wvx") ("video/x-msvideo" "avi")
("video/x-sgi-movie" "movie") ("x-conference/x-cooltalk" "ice")
;; hand-added by cox 27-jul-2015. video/mp4 entry is in ubuntu 15.04's
;; /etc/mime.types
("video/mp4" "mp4")
))
(defvar *mime-types* nil)
(defun build-mime-types-table ()
(if* (null *mime-types*)
then (setf *mime-types* (make-hash-table :test #'equalp))
(dolist (ent *file-type-to-mime-type*)
(dolist (type (cdr ent))
(setf (gethash type *mime-types*) (car ent))))))
(build-mime-types-table) ;; build the table now
(defmethod lookup-mime-type (filename)
;; return mime type if known
(if* (pathnamep filename)
then (setq filename (namestring filename)))
(multiple-value-bind (root tail name type)
(split-namestring filename)
(declare (ignore root name))
(if* (and type (gethash type *mime-types*))
thenret
elseif (gethash (list tail) *mime-types*)
thenret)))
(defun unpublish (&key all (server *wserver*))
(if* all
then (dolist (locator (wserver-locators server))
(unpublish-locator locator))
else (error "not done yet")))
;; methods on entity objects
;-- content-length -- how long is the body of the response, if we know
(defmethod content-length ((ent entity))
;; by default we don't know, and that's what nil means
nil)
(defmethod content-length ((ent file-entity))
(let ((contents (contents ent)))
(if* contents
then (length contents)
else ; may be a file on the disk, we could
; compute it.. this is
;** to be done
nil)))
(defmethod content-length ((ent special-entity))
(let ((body (special-entity-content ent)))
(if* body
then (length body)
else 0)))
(defmethod content-length ((ent multi-entity))
(multi-entity-content-length ent))
;- transfer-mode - will the body be sent in :text or :binary mode.
; use :binary if you're not sure
(defmethod transfer-mode ((ent entity))
(or (entity-format ent) :binary)
)
;; url exporting
(defun publish (&key (host nil host-p) port path function class format
content-type
(server *wserver*)
locator
remove
authorizer
timeout
plist
hook
headers
(compress t)
will-handle-expect-continue
)
;; publish the given url
;; if file is given then it specifies a file to return
;;
(let (hval)
(if* (null locator)
then (setq locator (find-locator :exact server)))
(setq hval (convert-to-vhosts (if* (and host (atom host))
then (list host)
else host)
server))
(if* remove
then ; eliminate the entity if it exists
(unpublish-entity locator path hval host-p)
else
(let ((ent (make-instance (or class 'computed-entity)
:host hval
:port port
:path path
:function function
:format format
:content-type content-type
:authorizer authorizer
:plist plist
:timeout timeout
:hook hook
:headers headers
:compress compress
:will-handle-expect-continue will-handle-expect-continue
)))
(publish-entity ent locator path hval)))))
(defun publish-prefix (&key (host nil host-p) port prefix
function class format
content-type
(server *wserver*)
locator
remove
authorizer
timeout
plist
headers
(compress t)
will-handle-expect-continue
)
;; publish a handler for all urls with a certain prefix
;;
(let (hval)
(if* (null locator)
then (setq locator (find-locator :prefix server)))
(setq hval (convert-to-vhosts (if* (and host (atom host))
then (list host)
else host)
server))
(if* remove
then ; eliminate the entity if it exists
(publish-prefix-entity nil prefix locator hval host-p t)
nil
else
(let ((ent (make-instance (or class 'computed-entity)
:host hval
:port port
:prefix prefix
:function function
:format format
:content-type content-type
:authorizer authorizer
:plist plist
:timeout timeout
:headers headers
:compress compress
:will-handle-expect-continue will-handle-expect-continue
)))
(publish-prefix-entity ent prefix locator hval
host-p nil)
ent))))
(defun publish-file (&key (server *wserver*)
locator
(host nil host-p)
port path
file content-type class preload
cache-p
remove
authorizer
plist
(timeout #+io-timeout #.(* 100 24 60 60)
#-io-timeout nil)
hook
headers
(compress t)
will-handle-expect-continue
)
;; return the given file as the value of the url
;; for the given host.
;; If host is nil then return for any host
(let (ent got c-type hval)
(if* (null locator)
then (setq locator (find-locator :exact server)))
(setq hval (convert-to-vhosts (if* (and host (atom host))
then (list host)
else host)
server))
(if* remove
then (unpublish-entity locator path
hval
host-p)
(return-from publish-file nil))
(setq c-type (or content-type
(lookup-mime-type file)
"application/octet-stream"))
(if* preload
then ; keep the content in core for fast display
(with-open-file (p file
#-(and allegro (version>= 6))
:element-type
#-(and allegro (version>= 6))
'(unsigned-byte 8))
(let ((size (excl::filesys-size (stream-input-fn p)))
(lastmod (excl::filesys-write-date (stream-input-fn p)))
(guts))
(setq guts (make-array size :element-type '(unsigned-byte 8)))
(if* (not (eql size (setq got (read-sequence guts p))))
then (error "~s should have been ~d bytes but was ~d"
file
size
got))
(setq ent (make-instance (or class 'file-entity)
:host hval
:port port
:path path
:file file
:content-type c-type
:contents guts
:last-modified lastmod
:last-modified-string (when lastmod (universal-time-to-date lastmod))
:cache-p cache-p
:authorizer authorizer
:timeout timeout
:plist plist
:hook hook
:headers headers
:compress compress
:will-handle-expect-continue will-handle-expect-continue
))))
else (setq ent (make-instance (or class 'file-entity)
:host hval
:port port
:path path
:file file
:content-type c-type
:cache-p cache-p
:authorizer authorizer
:timeout timeout
:plist plist
:hook hook
:headers headers
:compress compress
:will-handle-expect-continue will-handle-expect-continue
)))
(publish-entity ent locator path hval)))
(defun publish-directory (&key prefix
(host nil host-p)
port
destination
(server *wserver*)
locator
remove
authorizer
(indexes '("index.html" "index.htm"))
filter
(timeout #+io-timeout #.(* 100 24 60 60)
#-io-timeout nil)
publisher
access-file
plist
hook
headers
(compress t)
hidden-index-redirect
will-handle-expect-continue
)
;; make a whole directory available
(if* (null locator)
then (setq locator (find-locator :prefix server)))
(if* (and host (atom host))
then (setq host (list host)))
(setq host (convert-to-vhosts host server)) ; now a list of vhosts
(if* remove
then (publish-prefix-entity nil prefix locator
host host-p t)
(return-from publish-directory nil))
(let ((ent (make-instance 'directory-entity
:directory (if* (atom destination)
then (list destination)
else destination)
:prefix prefix
:host host
:port port
:authorizer authorizer
:indexes indexes
:filter filter
:timeout timeout
:publisher publisher
:access-file access-file
:plist plist
:hook hook
:headers headers
:compress compress
:hidden-index-redirect hidden-index-redirect
:will-handle-expect-continue will-handle-expect-continue
)))
(publish-prefix-entity ent prefix locator host host-p nil)
ent
))
(defun publish-prefix-entity (ent prefix locator host host-p remove)
;; add or remove an entity ent from the locator
;;
(dolist (entpair (locator-info locator))
(if* (equal (prefix-handler-path entpair) prefix)
then ; match, prefix
(if* (and remove (not host-p))
then ; remove all entries for all hosts
(setf (locator-info locator)
(remove entpair (locator-info locator)))
(return-from publish-prefix-entity nil))
(let ((handlers (prefix-handler-host-handlers entpair)))
(dolist (host host)
(dolist (hostpair handlers
; not found, add it if we're not removing
(if* (not remove)
then (push (make-host-handler :host host
:entity ent)
handlers)))
(if* (eq host (host-handler-host hostpair))
then ; a match
(if* remove
then (setq handlers
(remove hostpair handlers :test #'eq))
else ; change
(setf (host-handler-entity hostpair) ent))
(return))))
(setf (prefix-handler-host-handlers entpair) handlers))
; has been processed, time to leave
(return-from publish-prefix-entity ent)))
; prefix not present, must add.
; keep prefixes in order, with max length first, so we match
; more specific before less specific
(if* remove
then ; no work to do
(return-from publish-prefix-entity nil))
(let ((len (length prefix))
(list (locator-info locator))