1 ;; jabber-register.el - registration according to JEP-0077
3 ;; Copyright (C) 2003, 2004, 2007 - Magnus Henoch - mange@freemail.hu
4 ;; Copyright (C) 2002, 2003, 2004 - tom berger - object@intelectronica.net
6 ;; This file is a part of jabber.el.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 (require 'jabber-widget
)
25 (add-to-list 'jabber-jid-service-menu
26 (cons "Register with service" 'jabber-get-register
))
27 (defun jabber-get-register (jc to
)
28 "Send IQ get request in namespace \"jabber:iq:register\"."
29 (interactive (list (jabber-read-account)
30 (jabber-read-jid-completing "Register with: ")))
33 '(query ((xmlns .
"jabber:iq:register")))
34 #'jabber-process-data
#'jabber-process-register-or-search
35 #'jabber-report-success
"Registration"))
37 (defun jabber-process-register-or-search (jc xml-data
)
38 "Display results from jabber:iq:{register,search} query as a form."
40 (let ((query (jabber-iq-query xml-data
))
43 ((string= (jabber-iq-xmlns xml-data
) "jabber:iq:register")
45 ((string= (jabber-iq-xmlns xml-data
) "jabber:iq:search")
48 (error "Namespace %s not handled by jabber-process-register-or-search" (jabber-iq-xmlns xml-data
)))))
50 (plist-get (fsm-get-state-data jc
) :registerp
))
52 (plist-get (fsm-get-state-data jc
) :username
))
54 (plist-get (fsm-get-state-data jc
) :server
)))
58 ;; If there is no `from' attribute, we are registering with the server
59 (jabber-init-widget-buffer (or (jabber-xml-get-attribute xml-data
'from
)
64 (jabber-init-widget-buffer (jabber-xml-get-attribute xml-data
'from
))))
66 (setq jabber-buffer-connection jc
)
68 (widget-insert (if (eq type
'register
) "Register with " "Search ") jabber-submit-to
"\n\n")
70 (dolist (x (jabber-xml-get-children query
'x
))
71 (when (string= (jabber-xml-get-attribute x
'xmlns
) "jabber:x:data")
73 ;; If the registration form obeys JEP-0068, we know
74 ;; for sure how to put a default username in it.
75 (jabber-render-xdata-form x
76 (if (and register-account
77 (string= (jabber-xdata-formtype x
) "jabber:iq:register"))
78 (list (cons "username" username
))
81 (jabber-render-register-form query
82 (when register-account
85 (widget-create 'push-button
:notify
(if (eq type
'register
)
86 #'jabber-submit-register
87 #'jabber-submit-search
) "Submit")
88 (when (eq type
'register
)
90 (widget-create 'push-button
:notify
#'jabber-remove-register
"Cancel registration"))
93 (widget-minor-mode 1)))
95 (defun jabber-submit-register (&rest ignore
)
96 "Submit registration input. See `jabber-process-register-or-search'."
98 (let* ((registerp (plist-get (fsm-get-state-data jabber-buffer-connection
) :registerp
))
99 (handler (if registerp
100 #'jabber-process-register-secondtime
101 #'jabber-report-success
))
102 (text (concat "Registration with " jabber-submit-to
)))
103 (jabber-send-iq jabber-buffer-connection jabber-submit-to
107 ((eq jabber-form-type
'register
)
108 `(query ((xmlns .
"jabber:iq:register"))
109 ,@(jabber-parse-register-form)))
110 ((eq jabber-form-type
'xdata
)
111 `(query ((xmlns .
"jabber:iq:register"))
112 ,(jabber-parse-xdata-form)))
114 (error "Unknown form type: %s" jabber-form-type
)))
115 handler
(if registerp
'success text
)
116 handler
(if registerp
'failure text
)))
118 (message "Registration sent"))
120 (defun jabber-process-register-secondtime (jc xml-data closure-data
)
121 "Receive registration success or failure.
122 CLOSURE-DATA is either 'success or 'error."
124 ((eq closure-data
'success
)
125 (message "Registration successful. You may now connect to the server."))
127 (jabber-report-success jc xml-data
"Account registration")))
129 (jabber-disconnect-one jc
))
131 (defun jabber-remove-register (&rest ignore
)
132 "Cancel registration. See `jabber-process-register-or-search'."
134 (if (or jabber-silent-mode
(yes-or-no-p (concat "Are you sure that you want to cancel your registration to " jabber-submit-to
"? ")))
135 (jabber-send-iq jabber-buffer-connection jabber-submit-to
137 '(query ((xmlns .
"jabber:iq:register"))
139 #'jabber-report-success
"Unregistration"
140 #'jabber-report-success
"Unregistration")))
142 (provide 'jabber-register
)
144 ;;; arch-tag: e6b349d6-b1ad-4d19-a412-74459dfae239