| 1 |
<?php |
<?php |
| 2 |
// $Id: userauth_iq.module,v 1.2 2008/09/25 08:23:38 t0talmeltd0wn Exp $ |
// $Id: userauth_iq.module,v 1.3 2008/09/25 21:55:22 t0talmeltd0wn Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_xmpp_server_xml(). |
* Implementation of hook_xmpp_server_xml(). |
| 99 |
|
|
| 100 |
$acct->uid = $user; |
$acct->uid = $user; |
| 101 |
|
|
| 102 |
//Reset the user access cache each time. See README.txt. |
$jid['name'] = $user->name; |
| 103 |
if ($user && user_access('access xmpp server', $acct, TRUE)) { |
$jid['domain'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']); |
| 104 |
|
$jid['resource'] = $res->data; |
| 105 |
|
|
| 106 |
|
$existing = xmpp_server_id_map(xmpp_serialize_jid($jid), 'jid'); |
| 107 |
|
|
| 108 |
|
if (!empty($existing)) { |
| 109 |
|
$response->options['type'] = 'error'; |
| 110 |
|
|
| 111 |
|
$bind = new XmlNode(); |
| 112 |
|
$bind->tag = 'bind'; |
| 113 |
|
$bind->options['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-bind'; |
| 114 |
|
|
| 115 |
|
$res = new XmlNode(); |
| 116 |
|
$res->tag = 'resource'; |
| 117 |
|
$res->data = $jid['resource']; |
| 118 |
|
|
| 119 |
|
$bind->children[] = $res; |
| 120 |
|
|
| 121 |
|
$err = new XmlNode(); |
| 122 |
|
$err->tag = 'error'; |
| 123 |
|
$err->options['type'] = 'cancel'; |
| 124 |
|
|
| 125 |
|
$na = new XmlNode(); |
| 126 |
|
$na->tag = 'conflict'; |
| 127 |
|
$na->options['xmlns'] = 'urn:ietf:params:xml_ns_xmpp-stanzas'; |
| 128 |
|
|
| 129 |
|
$text = new XmlNode(); |
| 130 |
|
$text->tag = 'text'; |
| 131 |
|
$text->options['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-stanzas'; |
| 132 |
|
$text->data = t('There was a conflict with another resource on the server.'); |
| 133 |
|
|
| 134 |
|
$err->children[] = $na; |
| 135 |
|
$err->children[] = $text; |
| 136 |
|
|
| 137 |
|
$response->children[] = $bind; |
| 138 |
|
$response->children[] = $err; |
| 139 |
|
} |
| 140 |
|
elseif ($user && user_access('access xmpp server', $acct, TRUE)) { |
| 141 |
$response->options['type'] = 'result'; |
$response->options['type'] = 'result'; |
| 142 |
|
|
| 143 |
$session = xmpp_server_get_session($client); |
$session = xmpp_server_get_session($client); |
| 144 |
$session['uid'] = $user->uid; |
$session['uid'] = $user->uid; |
| 145 |
|
|
| 146 |
$session['jid']['name'] = $user->name; |
$session['jid'] = $jid; |
|
$session['jid']['domain'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']); |
|
|
$session['jid']['resource'] = $res->data; |
|
| 147 |
|
|
| 148 |
$session['authed'] = true; |
$session['authed'] = true; |
| 149 |
$session['bound'] = true; |
$session['bound'] = true; |
| 151 |
xmpp_server_save_session($session); |
xmpp_server_save_session($session); |
| 152 |
|
|
| 153 |
xmpp_server_id_map(xmpp_serialize_jid($session['jid']), 'jid', $client->id); |
xmpp_server_id_map(xmpp_serialize_jid($session['jid']), 'jid', $client->id); |
| 154 |
xmpp_server_id_map($session['uid'], 'uid', $client->id); |
xmpp_server_id_map($session['uid'] . "/{$jid['resource']}", 'uid', $client->id); |
| 155 |
|
|
| 156 |
//Now that we've set up the session and the ID map, call the hook. |
//Now that we've set up the session and the ID map, call the hook. |
| 157 |
module_invoke_all('xmpp_server_client_login', $client); |
module_invoke_all('xmpp_server_client_login', $client); |