services.el 30.2 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991  Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 1, or (at your option) 
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
Per Cederqvist's avatar
.  
Per Cederqvist committed
25
26
27
28
29
30
31
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; This file contains functions for sending requests to the server
;;;; and parsing the result.
;;;;

32
33
34
35
36
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))


Per Cederqvist's avatar
.  
Per Cederqvist committed
37
38
39
40
41
42
43
44
45
46
47
;;; ================================================================
;;;                     Requests for services


(defun initiate-login (kom-queue handler pers-no password &rest data)
  "Log in on server.
Args: KOM-QUEUE HANDLER PERS-NO PASSWORD &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 0 pers-no password)))


48
49
50
51
52
53
54
55
56
57
(defun initiate-login-new (kom-queue handler pers-no password status 
				     &rest data)
  "Log in on server.
Args: KOM-QUEUE HANDLER PERS-NO PASSWORD STATUS &rest DATA.
Status is 0 for visible login and 1 for invisible login."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 62 pers-no
						       password status)))


Per Cederqvist's avatar
.  
Per Cederqvist committed
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
(defun initiate-logout (kom-queue handler &rest data)
  "Log out from server.
Args: KOM-QUEUE HANDLER &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 1)))


(defun initiate-pepsi (kom-queue handler conf-no &rest data)
  "Change working conference.
Args: KOM-QUEUE HANDLER CONF-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 2 conf-no)))

(defun initiate-change-name (kom-queue handler
				       conf-no new-name
				       &rest data)
  "Change the name of a conference.
Args: KOM-QUEUE HANDLER CONF-NO NEW-NAME &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 3 conf-no new-name)))


(defun initiate-change-what-i-am-doing (kom-queue handler what &rest data)
  "Tell server what you are doing.
Args: KOM-QUEUE HANDLER WHAT &rest DATA.
WHAT is a string."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 4 what)))
  

(defun initiate-create-person (kom-queue handler name password &rest data)
  "Create a new person.
Args: KOM-QUEUE HANDLER NAME PASSWORD &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue (lyskom-format-objects 5 name password)))

;;; Call 6 is get-person-stat-old, and is obsoleted by call 49.

(defun initiate-set-priv-bits (kom-queue handler pers-no priv-bits &rest data)
  "Set priv-bits of a person.
Args: KOM-QUEUE HANDLER PERS-NO PRIV-BITS &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 7 pers-no priv-bits)))


(defun initiate-set-passwd (kom-queue handler
				      pers-no old-pw new-pw
				      &rest data)
  "Set the password of a person.
Args: KOM-QUEUE HANDLER PERS-NO OLD-PW NEW-PW &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 8 pers-no old-pw new-pw)))


;;; 
;;; This function has a ridiculous name!  It ought to be called
;;; get-membership.  Unfortunately this name is already taken
;;; by another call.
;;;
(defun initiate-query-read-texts (kom-queue handler
					    pers-no conf-no &rest data)
  "Get a membership struct describing the membership of PERS-NO in CONF-NO.
Args: KOM-QUEUE HANDLER PERS-NO CONF-NO &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-membership)
  (lyskom-send-packet kom-queue 
		      (lyskom-format-objects 9 pers-no conf-no)))


(defun initiate-create-conf (kom-queue handler
				       conf-name conf-type &rest data)
  "Add a member to a conference.
Args: KOM-QUEUE HANDLER CONF-NAME CONF-TYPE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 10 conf-name conf-type)))


(defun initiate-delete-conf (kom-queue handler conf-no &rest data)
  "Delete a conference.
Args: KOM-QUEUE HANDLER CONF-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 11 conf-no)))



(defun initiate-lookup-name (kom-queue handler name &rest data)
  "See what conferences match NAME.
Args: KOM-QUEUE HANDLER NAME &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-conf-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 12 name)))
					    

;;; Call 13 is get-conf-stat-old, which is obsoleted by 50.


(defun initiate-add-member (kom-queue handler
				      conf-no pers-no priority where
				      &rest data)
  "Add a member to a conference.
Args: KOM-QUEUE HANDLER CONF-NO PERS-NO PRIORITY WHERE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 14 conf-no pers-no 
					        priority where)))


(defun initiate-sub-member (kom-queue handler
				      conf-no pers-no
				      &rest data)
  "Subtract a member from a conference.
Args: KOM-QUEUE HANDLER CONF-NO PERS-NO  &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		     (lyskom-format-objects 15 conf-no pers-no)))


(defun initiate-set-presentation (kom-queue handler
					    conf-no text-no
					    &rest data)
  "Set presentation of a conference.
Args: KOM-QUEUE HANDLER CONF-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 16 conf-no text-no)))


(defun initiate-set-conf-motd (kom-queue handler conf-no text-no &rest data)
  "Set motd of a conference.
Args: KOM-QUEUE HANDLER CONF-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 17 conf-no text-no)))


(defun initiate-set-user-area (kom-queue handler pers-no text-no &rest data)
  "Set user-area of a person.
Args: KOM-QUEUE HANDLER PERS-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 57 pers-no text-no)))


(defun initiate-set-supervisor (kom-queue handler conf-no admin
					  &rest data)
  "Set supervisor of a conference.
Args: KOM-QUEUE HANDLER CONF-NO ADMIN &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 18 conf-no admin)))


(defun initiate-set-permitted-submitters (kom-queue handler conf-no perm-sub
						    &rest data)
  "Set permitted submitters of a conference.
Args: KOM-QUEUE HANDLER CONF-NO PERM-SUB &rest DATA.
PERM-SUB is a conference number. All members in that conference might
write texts in CONF-NO. If PERM-SUB is zero everyone is allowed to
write texts in CONF-NO."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 19 conf-no perm-sub)))


(defun initiate-set-super-conf (kom-queue handler conf-no super-conf
					  &rest data)
  "Set superconference of a conference.
Args: KOM-QUEUE HANDLER CONF-NO SUPER-CONF &rest DATA.
Unauthorized attempts to write texts to CONF-NO will bounce to SUPER-CONF."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue 
		      (lyskom-format-objects 20 conf-no super-conf)))


(defun initiate-set-conf-type (kom-queue handler conf-no conf-type &rest data)
  "Set type of a conference.
Args: KOM-QUEUE HANDLER CONF-NO CONF-TYPE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 21 conf-no conf-type)))


(defun initiate-set-garb-nice (kom-queue handler conf-no garb-nice &rest data)
  "Set garb-nice of a conference.
Args: KOM-QUEUE HANDLER CONF-NO GARB-NICE &rest DATA.
Texts in CONF-NO will live approximately GARB-NICE days."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 22 conf-no garb-nice)))


(defun initiate-get-marks (kom-queue handler &rest data)
  "Get all marked texts.
Args: KOM-QUEUE HANDLER &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-mark-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 23)))


(defun initiate-mark-text (kom-queue handler
				     text-no mark-type	
				     &rest data)
  "Mark a text.
Args: KOM-QUEUE HANDLER TEXT-NO MARK-TYPE &rest DATA.
MARK-TYPE is currently a number, but this should maybe be
changed (internally in the elisp-klient) to something similar to
a conf-type (with several bits that are 't' or 'nil' that is)."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 24 text-no mark-type)))


265
266
267
268
269
270
271
272
273
274
275
276
(defun initiate-find-next-text-no (kom-queue handler text-no &rest data)
  "Find the text following the text TEXT-NO"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue (lyskom-format-objects 60 text-no)))

(defun initiate-find-previous-text-no (kom-queue handler text-no &rest data)
  "Find the text preceding the text TEXT-NO"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue (lyskom-format-objects 61 text-no)))



Per Cederqvist's avatar
.  
Per Cederqvist committed
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
(defun initiate-get-text (kom-queue handler text-no &rest data)
  "Get text from LysKOM server.
Args: KOM-QUEUE HANDLER TEXT-NO &rest DATA."
  (let ((text (cache-get-text text-no)))
    (cond
     ((null text)			;Cached info?
      (lyskom-call kom-queue		;No, ask the server.
		   lyskom-ref-no
		   handler data
		   'lyskom-parse-text text-no)
      ;(princ text-no (get-buffer-create "text"))+++
      ;(terpri (get-buffer-create "text"))
      (lyskom-send-packet kom-queue (lyskom-format-objects 25 text-no
							   0 lyskom-max-int)))
     (t
	;Cached info. 
      (lyskom-call-add kom-queue 'PARSED text handler data)
      (lyskom-check-call kom-queue))))) ;This might call the handler.


(defun initiate-get-text-stat (kom-queue handler text-no &rest data)
  "Get text-stat from LysKOM server.
Args: KOM-QUEUE HANDLER TEXT-NO &rest DATA."
  (let ((text-stat (cache-get-text-stat text-no)))
    (cond
     ((null text-stat)			;Cached info?
      (lyskom-call kom-queue		;No, ask the server.
		   lyskom-ref-no
		   handler data
		   'lyskom-parse-text-stat text-no)
      ;(princ text-no (get-buffer-create "text-stat"))+++
      ;(terpri (get-buffer-create "text-stat"))
      (lyskom-send-packet kom-queue (lyskom-format-objects 26 text-no)))
     (t
	;Cached info. 
      (lyskom-call-add kom-queue 'PARSED text-stat handler data)
      (lyskom-check-call kom-queue))))) ;This might call the handler.


(defun initiate-mark-as-read (kom-queue handler conf-no text-list &rest data)
  "Mark all texts in TEXT-LIST as read in CONF-NO. Args: CONF-NO TEXT-LIST."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 27 conf-no 
					     (cons 'LIST text-list))))


(defun initiate-create-text (kom-queue handler message misc-list &rest data)
  "Create a new text.
Args: KOM-QUEUE HANDLER MESSAGE MISC-LIST &rest DATA.
MESSAGE is a string. MISC-LIST should be created by lyskom-create-misc-list."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 28 message misc-list)))
331
332
333
334
335
336
337
338
339

(defun initiate-create-anonymous-text (kom-queue handler message 
						 misc-list &rest data)
  "Create a new anonymous text.
Args: KOM-QUEUE HANDLER MESSAGE MISC-LIST &rest DATA.
MESSAGE is a string. MISC-LIST should be created by lyskom-create-misc-list."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 59 message misc-list)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
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
				     
(defun initiate-delete-text (kom-queue handler text-no &rest data)
  "Delete a text.
Args: KOM-QUEUE HANDLER TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 29 text-no)))


(defun initiate-add-recipient (kom-queue handler
					 text-no conf-no type
					 &rest data)
  "Add a recipient to a text.
Args: KOM-QUEUE HANDLER TEXT-NO CONF-NO TYPE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 30 text-no conf-no
				     (if (eq type 'recpt)
					 0
				       1))))

(defun initiate-sub-recipient (kom-queue handler
					 text-no conf-no 
					 &rest data)
  "Subtract a recipient from a text.
Args: KOM-QUEUE HANDLER TEXT-NO CONF-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 31 text-no conf-no)))


(defun initiate-add-comment (kom-queue handler
					 comment-text-no text-no
					 &rest data)
  "Add a comment to a text.
Args: KOM-QUEUE HANDLER COMMENT-TEXT-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 32 comment-text-no text-no)))

				       

(defun initiate-sub-comment (kom-queue handler
					 comment-text-no text-no
					 &rest data)
  "Subtract a comment from a text.
Args: KOM-QUEUE HANDLER COMMENT-TEXT-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 33 comment-text-no text-no)))


392
393
(defun initiate-get-map (kom-queue handler conf-no first-local
				   no-of-texts &rest data-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
394
395
396
397
398
399
400
401
402
403
  "Get mapping from local to global text-nos for CONF-NO from server.
Args: KOM-QUEUE HANDLER CONF-NO FIRST-LOCAL NO-OF-TEXTS DATA-LIST.
Use initiate-get-map instead. This function has severe performance losses
with big maps."
  (lyskom-call kom-queue lyskom-ref-no handler data-list
	       'lyskom-parse-map)
  (lyskom-send-packet kom-queue 
		      (lyskom-format-objects 34 conf-no
					     first-local no-of-texts)))

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
;; As far as I can tell, this function is not used. /davidk
;;(defun z-initiate-get-map  (kom-queue handler conf-no first-local
;;					     no-of-texts &rest data)
;;  "Get mapping from local to global text-nos for CONF-NO from server.
;;Args: KOM-QUEUE HANDLER CONF-NO FIRST-LOCAL NO-OF-TEXTS &rest DATA.
;;This function will automatically split fetching of big maps to small
;;chunks of lyskom-fetch-map-nos texts/chunk if KOM-QUEUE is not already
;;used to collect a result. This currently gives a big performance gain.
;;Unfortunately it is impossible (or at least very hard) to do the same
;;thing when a collect is in progress. This will of course be fixed in
;;protocol B."
;;  (cond
;;   ((lyskom-kom-queue-collect-p kom-queue)
;;    ;; Use oldstyle single big map. Sorry.
;;    (initiate-get-map kom-queue handler conf-no
;;		      first-local no-of-texts data))
;;   (t
;;    ;; You win.
;;    (lyskom-collect-ignore-err kom-queue)
;;    (while (> no-of-texts 0)
;;      (initiate-get-map kom-queue nil conf-no
;;				  first-local lyskom-fetch-map-nos data)
;;      (setq first-local (+ lyskom-fetch-map-nos first-local))
;;      (setq no-of-texts (- no-of-texts lyskom-fetch-map-nos)))
;;    (lyskom-list-use kom-queue 'lyskom-receive-get-map handler data))))

Per Cederqvist's avatar
.  
Per Cederqvist committed
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

(defun lyskom-receive-get-map (map-list handler data-list)
  "Receive a list of maps.
Args: MAP-LIST HANDLER DATA-LIST."
  (apply handler (apply 'lyskom-map-concat map-list) data-list))
    

(defun initiate-get-time (kom-queue handler &rest data)
  "Get time from server.
Args: KOM-QUEUE HANDLER &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-time)
  (lyskom-send-packet kom-queue (lyskom-format-objects 35)))


(defun initiate-get-server-info (kom-queue handler &rest data)
  "Get info about the server"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-server-info)
  (lyskom-send-packet kom-queue (lyskom-format-objects 36)))


(defun initiate-add-footnote (kom-queue handler
					footnote-text-no text-no
					&rest data)
  "Add a footnote to a text.
Args: KOM-QUEUE HANDLER FOOTNOTE-TEXT-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 37 footnote-text-no text-no)))


(defun initiate-sub-footnote (kom-queue handler
					footnote-text-no text-no
					&rest data)
  "Subtract a footnote from a text.
Args: KOM-QUEUE HANDLER FOOTNOTE-TEXT-NO TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 38 footnote-text-no text-no)))


;;; Call 39, who-is-on-old, is obsoleted by call 51.


(defun initiate-set-unread (kom-queue handler conf-no no-of-unread &rest data)
  "Set number of unread texts in a certain conference.
Args: KOM-QUEUE HANDLER CONF-NO NO-OF-UNREAD &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 40 conf-no no-of-unread)))


(defun initiate-set-motd-of-lyskom (kom-queue handler text-no &rest data)
  "Set message of the day of LysKOM.
Args: KOM-QUEUE HANDLER TEXT-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 41 text-no)))


(defun initiate-enable (kom-queue handler level &rest data)
  "Set security level.
Args: KOM-QUEUE HANDLER LEVEL &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 42 level)))

;;; Call 43 is sync. That should not be done too often, so no
;;; function is written... Use 'kill -SIGUSR1' instead.

;;; Call 44 is shutdown. Use 'kill -HUP' instead.

(defun initiate-shutdown (kom-queue handler parameter &rest data)
  "Shutdown the server.
Args: KOM-QUEUE HANDLER PARAMETER &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 44 parameter)))


(defun initiate-broadcast (kom-queue handler message &rest data)
  "Send a broadcast message to all logged in users.
Args: KOM-QUEUE HANDLER MESSAGE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 45 message)))



(defun initiate-get-membership (kom-queue handler pers-no &rest data)
  "Get membership-list for PERS-NO from server.
Args: KOM-QUEUE HANDLER PERS-NO &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-membership-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 46 pers-no
						0 lyskom-max-int ;all confs.
						1))) ;want read texts.


525
526
527
528
529
530
531
532
533
534
535
(defun initiate-get-part-of-membership (kom-queue handler pers-no first length
						  &rest data)
  "Get membership-list for PERS-NO from server.
Args: KOM-QUEUE HANDLER PERS-NO FIRST-IN-LIST LENGHT &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-membership-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 46 pers-no
						first length ;all confs.
						1)))


Per Cederqvist's avatar
.  
Per Cederqvist committed
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
(defun initiate-get-created-texts (kom-queue handler pers-no first-local
					     no-of-texts &rest data)
  "Get a part of the list of created texts for a person.
Args: KOM-QUEUE HANDLER PERS-NO FIRST-LOCAL NO-OF-TEXTS &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-map)
  (lyskom-send-packet kom-queue (lyskom-format-objects 47 pers-no
					       first-local no-of-texts)))


(defun initiate-get-members (kom-queue handler conf-no first-local
				       no-of-members &rest data)
  "Get a part of the list of members in a conference.
Args: KOM-QUEUE HANDLER CONF-NO FIRST-LOCAL NO-OF-MEMBERS &rest DATA.
Returns a conf-no-list."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-conf-no-list)
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 48 conf-no
					     first-local no-of-members)))


(defun initiate-get-pers-stat (kom-queue handler pers-no &rest data)
  "Get status for person PERS-NO.
Args: KOM-QUEUE HANDLER PERS-NO &rest DATA."
  (let ((pers-stat (cache-get-pers-stat pers-no)))
    (cond
     ((null pers-stat)			;Cached info?
      (lyskom-call kom-queue		;No, ask the server.
		   lyskom-ref-no
		   handler data
		   'lyskom-parse-pers-stat pers-no)
      ;(princ pers-no (get-buffer-create "pers-stat")) +++
      ;(terpri (get-buffer-create "pers-stat"))
      (lyskom-send-packet kom-queue (lyskom-format-objects 49 pers-no)))
     (t
	;Cached info. 
      (lyskom-call-add kom-queue 'PARSED pers-stat handler data)
      (lyskom-check-call kom-queue)))))

(defun initiate-get-conf-stat (kom-queue handler conf-no &rest data)
  "Get conf-stat from LysKOM server.
Args: KOM-QUEUE HANDLER CONF-NO &rest DATA."
  (let ((conf-stat (cache-get-conf-stat conf-no)))
    (cond
581
582
583
     ((zerop conf-no)			;No real user.
      (lyskom-call-add kom-queue 'PARSED nil handler data)
      (lyskom-check-call kom-queue))
Per Cederqvist's avatar
.  
Per Cederqvist committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
     ((null conf-stat)			;Cached info?
      (lyskom-call kom-queue		;No, ask the server.
		   lyskom-ref-no
		   handler data
		   'lyskom-parse-conf-stat conf-no)
      ;(princ conf-no (get-buffer-create "conf-stat")) +++
      ;(terpri (get-buffer-create "conf-stat"))
      (lyskom-send-packet kom-queue (lyskom-format-objects 50 conf-no)))
     (t
	;Cached info. 
      (lyskom-call-add kom-queue 'PARSED conf-stat handler data)
      (lyskom-check-call kom-queue))))) ;This might call the handler.


598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
(defun initiate-get-uconf-stat (kom-queue handler conf-no &rest data)
  "Get an uconf-sstat from LysKOM server.
Args: KOM-QUEUE HANDLER CONF-NO &rest DATA."
  (let ((conf-stat (cache-get-uconf-stat conf-no)))
    (cond ((zerop conf-no)
	   (lyskom-call-add kom-queue 'PARSED nil handler data)
	   (lyskom-check-call kom-queue))
	  ((null conf-stat)
	   (lyskom-call kom-queue
			lyskom-ref-no
			handler data
			'lyskom-parse-uconf-stat conf-no)
	   (lyskom-send-packet kom-queue (lyskom-format-objects 78 conf-no)))
	  (t
	   (lyskom-call-add kom-queue 'PARSED conf-stat handler data)
	   (lyskom-check-call kom-queue)))))


Per Cederqvist's avatar
.  
Per Cederqvist committed
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
(defun initiate-who-is-on (kom-queue handler &rest data)
  "Ask server who is on.
Args: KOM-QUEUE HANDLER &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-who-info-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 51)))


(defun initiate-get-unread-confs (kom-queue handler pers-no &rest data)
  "Return a list of confs that may have unread texts.
Args: KOM-QUEUE HANDLER PERS-NO &rest DATA.
PERS-NO is the number of the person whos confs we are checking."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-conf-no-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 52 pers-no)))


(defun initiate-send-message (kom-queue handler recipient message &rest data)
  "Send a message to one or all logged in users.
Args: KOM-QUEUE HANDLER RECIPIENT MESSAGE &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 53 recipient message)))


(defun initiate-get-session-info (kom-queue handler session-no &rest data)
  "Ask server about info about a session.
Args: KOM-QUEUE HANDLER SESSION-NO &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-session-info)
  (lyskom-send-packet kom-queue (lyskom-format-objects 54 session-no)))


(defun initiate-disconnect (kom-queue handler session-no &rest data)
  "Disconnect a session.
Args: KOM-QUEUE HANDLER SESSION &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 55 session-no)))


(defun initiate-who-am-i (kom-queue handler &rest data)
  "Ask the server which connection we are using.
Args: KOM-QUEUE HANDLER &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-num)
  (lyskom-send-packet kom-queue (lyskom-format-objects 56)))

663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684

(defun initiate-set-client-version (kom-queue handler name version &rest data)
  "Tell the server to set the client name and version of this session."
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
  (lyskom-send-packet kom-queue (lyskom-format-objects 69 name version)))


(defun initiate-get-client-name (kom-queue handler session &rest data)
  "Tell the server to set the highest unread article in conference CONF-NO
to TEXT-NO
Args: KOM-QUEUE HANDLER CONF-NO TEXT-NO &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-string)
  (lyskom-send-packet kom-queue (lyskom-format-objects 70 session)))


(defun initiate-get-client-version (kom-queue handler session &rest data)
  "Tell the server to set the highest unread article in conference CONF-NO
to TEXT-NO
Args: KOM-QUEUE HANDLER CONF-NO TEXT-NO &rest DATA"
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-string)
  (lyskom-send-packet kom-queue (lyskom-format-objects 71 session)))

685
686
687
688
689
690
691
692
(defun initiate-re-z-lookup (kom-queue handler regexp want-persons want-confs
				       &rest data)
  "Perform a regexp lookup.
Args: KOM-QUEUE HANDLER REGEXP WANT-PERSONS WANT-CONFS &rest DATA."
  (lyskom-call kom-queue lyskom-ref-no handler data
	       'lyskom-parse-conf-z-info-list)
  (lyskom-send-packet kom-queue (lyskom-format-objects 74 regexp want-persons
						       want-confs)))
693

694
695
696
697
(defun initiate-set-last-read (kom-queue handler conf-no text-no &rest data)
  "Tell the server to set the highest unread article in conference CONF-NO
to TEXT-NO
Args: KOM-QUEUE HANDLER CONF-NO TEXT-NO &rest DATA"
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
  (if lyskom-set-last-read-flag
      (progn
        (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
        (lyskom-send-packet kom-queue (lyskom-format-objects 77
                                                             conf-no text-no)))
    (initiate-get-conf-stat kom-queue 
                            'initiate-set-last-read-2 
                            conf-no
                            kom-queue
                            handler 
                            conf-no
                            text-no
                            data)))

(defun initiate-set-last-read-2 (conf-stat 
                                 kom-queue
                                 handler
                                 conf-no
                                 text-no
                                 data)
  (let ((no-of-unread (- (1- (+ (conf-stat->first-local-no conf-stat)
                                (conf-stat->no-of-texts conf-stat)))
                         text-no)))
    (if (< no-of-unread 0)
        (setq no-of-unread 0))

724
  (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
725
726
727
728
  (lyskom-send-packet kom-queue
		      (lyskom-format-objects 40 conf-no no-of-unread))))
                                 

729
730


Per Cederqvist's avatar
.  
Per Cederqvist committed
731
732

;;; ================================================================
733
734
735
736


;; Blocking reading from server:

Linus Tolke's avatar
Linus Tolke committed
737
738
739
(defvar lyskom-blocking-return nil
  "Return from blocking-do.")

740
741
742
743
744
745
746
747
748
749
(defun blocking-return (retval)
  "Sets blocking variable."
  (setq lyskom-blocking-return retval))

(defun blocking-do (command &rest data)
  "Does the COMMAND agains the lyskom-server and returns the result.
COMMAND is one lyskom-command (like the initiate-* but the initiate- is 
stripped.
The cache is consulted when command is get-conf-stat, get-pers-stat
or get-text-stat."
David Kågedal's avatar
David Kågedal committed
750
751
  ;; Here we could check if lyskom-blocking-return is non-nil, in
  ;; which case there is a bug in the code
752

753
754
  (save-excursion
    (set-buffer (process-buffer (or lyskom-proc
Linus Tolke's avatar
Linus Tolke committed
755
				    lyskom-blocking-process)))
756
757
758
759
    ;; If this happens, we're in trouble
    (if lyskom-is-parsing
	(lyskom-really-serious-bug))

760
761
762
763
764
    (let ((lyskom-blocking-return 'not-yet-gotten))
      (apply (intern-soft (concat "initiate-"
				  (symbol-name command)))
	     'blocking 'blocking-return
	     data)
David Kågedal's avatar
David Kågedal committed
765
      (while (and (eq lyskom-blocking-return 'not-yet-gotten)
766
		  (memq (process-status lyskom-proc) '(open run))
David Kågedal's avatar
David Kågedal committed
767
		  (not lyskom-quit-flag))
768
769
770
;;        (if (input-pending-p)
;;            (execute-kbd-macro (read-key-sequence ""))
        (accept-process-output nil lyskom-apo-timeout-s lyskom-apo-timeout-ms))
David Kågedal's avatar
David Kågedal committed
771
772
      (if lyskom-quit-flag
	  (progn
773
	    (setq lyskom-quit-flag nil)
David Kågedal's avatar
David Kågedal committed
774
775
	    (lyskom-insert-before-prompt (lyskom-get-string 'interrupted))
	    (signal 'quit nil)))
776
      lyskom-blocking-return)))
777
778


779

David Kågedal's avatar
David Kågedal committed
780
781
782
783
784
785
786
787
788
(defun lyskom-wait-queue (queue)
  "Waits until all data on QUEUE has been processed"
  (save-excursion
    (set-buffer (process-buffer (or lyskom-proc
				    lyskom-blocking-process)))
    (let ((lyskom-blocking-return 'not-yet-gotten))
      (lyskom-run queue 'blocking-return (list t))
      (while (and (eq lyskom-blocking-return 'not-yet-gotten)
		  (not lyskom-quit-flag))
David Byers's avatar
David Byers committed
789
	(accept-process-output nil lyskom-apo-timeout-s lyskom-apo-timeout-ms))
David Kågedal's avatar
David Kågedal committed
790
791
792
793
794
795
      (if lyskom-quit-flag
	  (progn
	    (lyskom-insert-before-prompt (lyskom-get-string 'interrupted))
	    (signal 'quit nil)))
      (setq lyskom-quit-flag nil)
      lyskom-blocking-return)))