forked from scymtym/rudel
/
rudel-xmpp-state.el
93 lines (76 loc) · 2.59 KB
/
rudel-xmpp-state.el
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
;;; rudel-xmpp-state.el --- Base class for states used in XMPP connections
;;
;; Copyright (C) 2009, 2010 Jan Moringen
;;
;; Author: Jan Moringen <scymtym@users.sourceforge.net>
;; Keywords: rudel, xmpp, state machine
;; X-RCS: $Id:$
;;
;; This file is part of Rudel.
;;
;; Rudel 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 3 of the License, or
;; (at your option) any later version.
;;
;; Rudel 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 Rudel. If not, see <http://www.gnu.org/licenses>.
;;; Commentary:
;;
;; The class `rudel-xmpp-state' is the base class for all states used
;; in XMPP connections.
;;; History:
;;
;; 0.1 - Initial version
;;; Code:
;;
(require 'rudel-util)
(require 'rudel-state-machine)
;; TODO
;; we also need rudel-xmpp.el for `rudel-xmpp-transport' but that
;; would create a circular dependency. It is OK not to require it,
;; since rudel-xmpp.el is always loaded first.
;;; Class rudel-xmpp-state
;;
(defclass rudel-xmpp-state (rudel-state
rudel-impersonator
rudel-delegator)
((impersonation-target-slot :initform 'transport)
(delegation-target-slot :initform 'transport)
(transport :initarg :transport
:type rudel-transport ;; TODO rudel-xmpp-transport?
:documentation
"The transport class the state
machine of which uses the state object."))
"Base class for XMPP state classes.")
(defmethod rudel-enter ((this rudel-xmpp-state) &rest args)
"Default behavior is to stay in the newly entered state."
nil)
(defmethod rudel-leave ((this rudel-xmpp-state))
"Default behavior is to do nothing when leaving a state.")
;; TODO choose one
(defmethod rudel-accept ((this rudel-xmpp-state) xml)
"Default behavior is to accept XML without taking action."
nil)
(defmethod rudel-accept ((this rudel-xmpp-state) xml)
""
(let ((name (xml-node-name xml)))
(case name
;;
;; TODO example
;; <stream:error>
;; <not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
;; </stream:error>
('stream:error ;; TODO is this qualified
'they-finalize)
;; we do not accept unexpected messages.
(t
'we-finalize)))
)
(provide 'rudel-xmpp-state)
;;; rudel-xmpp-state.el ends here