-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.cl
217 lines (182 loc) · 5.83 KB
/
defs.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
(eval-when (compile eval load)
(require :ef-e-crcrlf)
(require :list2)
(require :acldns)
(require :smtp)
(require :osi)
(require :shell)
(require :datetime)
(require :anydate)
(require :ssl)
(require :aserve)
#+(version= 10 0) (require :acache "acache-3.0.5.fasl")
#+(version= 10 1) (require :acache "acache-3.1.1.fasl")
(require :autozoom))
(defpackage :user
(:use #:common-lisp #:excl #:excl.osi #:excl.shell
#:util.date-time #:net.post-office))
(in-package :user)
;; Started getting 308 codes from TBN, and turning this off fixed it.
(defvar *avoid-https* nil)
;; Non-nil if we're using --add command line argument
(defvar *manual-add-mode* nil)
(defvar *tget-data-directory* "~/.tget.d/")
(defvar *auto-backup* t)
(defvar *main* nil) ; main acache database
(defvar *temp* nil) ; temp acache database
(defvar *database-main-name* nil)
(defvar *database-temp-name* nil)
(defvar *version-file* nil)
(defvar *config-file* nil)
(defvar *debug* nil)
(defvar *test* nil)
(defvar *init-forms* nil)
(defvar *log-rss-stream* nil)
(defvar *now* nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; [some] user-settable variables (in config file)
(defvar *log-rss*
;; if non-nil, a pathanme to log rss feed info
nil)
(defvar *log-xml*
;; if non-nil, a pathname to log the XML feed should there be an error
;; parsing it
nil)
(defvar *log-file*
;; if non-nil, a pathanme to log episode info
nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct tracker
name
url
debug-feed
public
download-delay
disabled
ratio
upload-limit
;;;; for --cleanup
;; regexp to identify tracker
re
;; the single char name for the tracker
char
;; function to set torrent values, like ratio-limit, seed-min-time, etc
setter)
(defvar *tracker-name-to-tracker* (make-hash-table :size 777 :test #'eq))
(push '(clrhash *tracker-name-to-tracker*)
*init-forms*)
(defun tracker-name-to-tracker (tracker-name)
(gethash tracker-name *tracker-name-to-tracker*))
(defun (setf tracker-name-to-tracker) (tracker tracker-name)
(setf (gethash tracker-name *tracker-name-to-tracker*) tracker))
(defun tracker-name-to-instance (string-name)
(maphash
(lambda (tname tinstance)
(declare (ignore tname))
(when (match-re (tracker-re tinstance) string-name :return nil)
(return-from tracker-name-to-instance tinstance)))
*tracker-name-to-tracker*))
(defvar *all-trackers* nil)
(setq *all-trackers* nil)
(push '(setq *all-trackers* nil)
*init-forms*)
(defmacro deftracker (name &key url debug-feed public download-delay
disabled ratio upload-limit
re char setter)
`(push (.make-tracker
:name ,name
:url ,url
:debug-feed ,debug-feed
:public ,public
:download-delay ,download-delay
:disabled ,disabled
:ratio ,ratio
:upload-limit ,upload-limit
:re ,re
:char ,char
:setter ,setter)
*all-trackers*))
(defmacro .make-tracker (&key name url debug-feed public download-delay
disabled ratio upload-limit re char setter)
(when (tracker-name-to-tracker name)
(.error "Tracker ~s defined more than once in config file." name))
(check-url "Tracker :url" url)
;; Don't check debug-feed because it's a function
(check-integer "Tracker :download-delay" download-delay)
(check-integer "Tracker :upload-limit" upload-limit)
(check-ratio ratio)
(setf (tracker-name-to-tracker name)
(make-tracker
:name name
:url url
:debug-feed debug-feed
:public public
:download-delay download-delay
:disabled disabled
:ratio ratio
:upload-limit upload-limit
:re re
:char char
:setter setter)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun check-url (what item)
(when item
(or (and (stringp item) (=~ "^http" item))
(.error "~a must be a URL: ~s." what item))))
(defun check-filename (what item)
(when item
(or (and (or (stringp item)
(pathnamep item))
(probe-file item))
(.error "~a must be the name of an existing file: ~s." what item))))
(defun check-integer (what item)
(when item
(or (integerp item)
(.error "~a must be an integer: ~s." what item))))
(defun check-boolean (what item)
(when item
(or (eq 't item)
(.error "~a must be `t' or `nil': ~s." what item))))
(defun check-rss-url (rss-url)
(and rss-url
(and (dolist (u (if (consp rss-url) rss-url (list rss-url)))
(if* (or (symbolp u)
(and (stringp u)
(match-re "^http" u)))
thenret
else (return t)))
(.error "Bad rss-url: ~s." rss-url))))
(defun check-trackers (tracker-thing &aux tracker (trackers '()))
(and tracker-thing
(dolist (tracker-name (if* (consp tracker-thing)
then tracker-thing
else (list tracker-thing))
(nreverse trackers))
(when (not (symbolp tracker-name))
(.error "Bad tracker name: ~s." tracker-name))
(when (not (setq tracker (tracker-name-to-tracker tracker-name)))
(.error "Unknown tracker: ~s." tracker-name))
(push tracker trackers))))
(defun check-delay (delay)
(and delay
(or (numberp delay)
(.error "Bad delay, must be a number: ~s." delay))))
(defun check-ratio (ratio)
(and ratio
(or (and (stringp ratio)
(match-re "^-?[0-9.]+$" ratio))
(floatp ratio)
(.error "Bad ratio: ~s." ratio))))
(defun check-group (group-name)
(and group-name
(or (keywordp group-name)
(.error "Bad group: ~s." group-name))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-condition tget (error) ())
(defun .error (format-string &rest format-arguments)
;; This separates known tget errors from unexpected program errors. All
;; calls to error in this code should be to this function. Any calls to
;; error or cerror cause a stack trace.
(error 'tget :format-control format-string
:format-arguments format-arguments))
(provide :tget-defs)