1 ;; jabber-register.el - registration according to JEP-0077 -*- lexical-binding: t; -*-
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\".
30 JC is the Jabber connection."
31 (interactive (list (jabber-read-account)
32 (jabber-read-jid-completing "Register with: ")))
35 '(query ((xmlns . "jabber:iq:register")))
36 #'jabber-process-data #'jabber-process-register-or-search
37 #'jabber-report-success "Registration"))
39 (defun jabber-process-register-or-search (jc xml-data)
40 "Display results from jabber:iq:{register,search} query as a form.
42 JC is the Jabber connection.
43 XML-DATA is the parsed tree data from the stream (stanzas)
44 obtained from `xml-parse-region'."
46 (let ((query (jabber-iq-query xml-data))
49 ((string= (jabber-iq-xmlns xml-data) "jabber:iq:register")
51 ((string= (jabber-iq-xmlns xml-data) "jabber:iq:search")
54 (error "Namespace %s not handled by jabber-process-register-or-search" (jabber-iq-xmlns xml-data)))))
56 (plist-get (fsm-get-state-data jc) :registerp))
58 (plist-get (fsm-get-state-data jc) :username))
60 (plist-get (fsm-get-state-data jc) :server)))
64 ;; If there is no `from' attribute, we are registering with the server
65 (jabber-init-widget-buffer (or (jabber-xml-get-attribute xml-data 'from)
70 (jabber-init-widget-buffer (jabber-xml-get-attribute xml-data 'from))))
72 (setq jabber-buffer-connection jc)
74 (widget-insert (if (eq type 'register) "Register with " "Search ") jabber-submit-to "\n\n")
76 (dolist (x (jabber-xml-get-children query 'x))
77 (when (string= (jabber-xml-get-attribute x 'xmlns) "jabber:x:data")
79 ;; If the registration form obeys XEP-0068, we know
80 ;; for sure how to put a default username in it.
81 (jabber-render-xdata-form x
82 (if (and register-account
83 (string= (jabber-xdata-formtype x) "jabber:iq:register"))
84 (list (cons "username" username))
87 (jabber-render-register-form query
88 (when register-account
91 (widget-create 'push-button :notify (if (eq type 'register)
92 #'jabber-submit-register
93 #'jabber-submit-search) "Submit")
94 (when (eq type 'register)
96 (widget-create 'push-button :notify #'jabber-remove-register "Cancel registration"))
99 (widget-minor-mode 1)))
101 (defun jabber-submit-register (&rest ignore)
102 "Submit registration input. See `jabber-process-register-or-search'."
103 (let* ((registerp (plist-get (fsm-get-state-data jabber-buffer-connection) :registerp))
104 (handler (if registerp
105 #'jabber-process-register-secondtime
106 #'jabber-report-success))
107 (text (concat "Registration with " jabber-submit-to)))
108 (jabber-send-iq jabber-buffer-connection jabber-submit-to
112 ((eq jabber-form-type 'register)
113 `(query ((xmlns . "jabber:iq:register"))
114 ,@(jabber-parse-register-form)))
115 ((eq jabber-form-type 'xdata)
116 `(query ((xmlns . "jabber:iq:register"))
117 ,(jabber-parse-xdata-form)))
119 (error "Unknown form type: %s" jabber-form-type)))
120 handler (if registerp 'success text)
121 handler (if registerp 'failure text)))
123 (message "Registration sent"))
125 (defun jabber-process-register-secondtime (jc xml-data closure-data)
126 "Receive registration success or failure.
127 CLOSURE-DATA is either 'success or 'error.
129 JC is the Jabber connection.
130 XML-DATA is the parsed tree data from the stream (stanzas)
131 obtained from `xml-parse-region'."
133 ((eq closure-data 'success)
134 (message "Registration successful. You may now connect to the server."))
136 (jabber-report-success jc xml-data "Account registration")))
138 (jabber-disconnect-one jc))
140 (defun jabber-remove-register (&rest ignore)
141 "Cancel registration. See `jabber-process-register-or-search'."
143 (if (or jabber-silent-mode (yes-or-no-p (concat "Are you sure that you want to cancel your registration to " jabber-submit-to "? ")))
144 (jabber-send-iq jabber-buffer-connection jabber-submit-to
146 '(query ((xmlns . "jabber:iq:register"))
148 #'jabber-report-success "Unregistration"
149 #'jabber-report-success "Unregistration")))
151 (provide 'jabber-register)
153 ;;; arch-tag: e6b349d6-b1ad-4d19-a412-74459dfae239