ejabberd - Comments for "Developing a custom registration module" https://www.ejabberd.im/node/5085 en OK, I figured out that the https://www.ejabberd.im/node/5085#comment-58088 <p>OK, I figured out that the component was not registering itself correctly. In order for it to be invoked, it needs to hook into the right events <em>and</em> it needs to announce its ability in the protocol, otherwise clients will not even try to call it. This is the current setup:</p> <div class="codeblock"><code>start(Host, Ops) -&gt;<br />&nbsp;&nbsp;&nbsp; ejabberd_hooks:add(c2s_stream_features, Host, ?MODULE, stream_feature_register, 50),<br />&nbsp;&nbsp;&nbsp; ejabberd_hooks:add(c2s_unauthenticated_iq, Host, ?MODULE, on_c2s_unauthenticated_iq, 50),<br />&nbsp;&nbsp;&nbsp; ... <p>%% Without this, clients won&#039;t know about the availability of the registration feature<br />stream_feature_register(Acc, _Host) -&gt; [{ xmlelement, &quot;register&quot;, [{ &quot;xmlns&quot;, ?NS_FEATURE_IQREGISTER }], [] } | Acc].</p> <p>on_c2s_unauthenticated_iq(_Acc, Server, #iq{ type = get, xmlns = ?NS_REGISTER } = IQ, IP) -&gt; registration_format_iq(Server, IQ, IP);<br />on_c2s_unauthenticated_iq(_Acc, Server, #iq{ type = set, xmlns = ?NS_REGISTER } = IQ, IP) -&gt; registration_iq(Server, IQ, IP).</p> <p>%% Announce the required registration form fields<br />registration_format_iq(Server, IQ, IP) -&gt;<br />&nbsp;&nbsp;&nbsp; jlib:iq_to_xml(IQ#iq{ type = result, sub_el = [<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { xmlelement, &quot;query&quot;, [{ &quot;xmlns&quot;, ?NS_REGISTER }], [<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { xmlelement, &quot;instructions&quot;, [], [{ xmlcdata, &quot;These are my custom registration fields.&quot; }] },<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { xmlelement, &quot;email&quot;, [], [] },<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { xmlelement, &quot;phone&quot;, [], [] }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ] }<br />&nbsp;&nbsp;&nbsp; ] }).</p> <p>registration_iq(Server, #iq{ sub_el = SubEl } = IQ, IP) -&gt;<br />&nbsp;&nbsp;&nbsp; %% Handle actual registration...</p></code></div> <p>When the original mod_registration is disabled, this works fine.</p> Tue, 29 Nov 2011 09:37:54 +0000 deceze comment 58088 at https://www.ejabberd.im