drupal/modules/jabber.module

184 lines
5.2 KiB
Plaintext
Raw Normal View History

<?php
// $Id$
function jabber_system($field){
$system["description"] = t("Enables login with Jabber ID and password.");
return $system[$field];
}
function jabber_info($field = 0) {
$info["name"] = "Jabber";
$info["protocol"] = "Jabber";
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
function jabber_start($parser, $name, $attributes) {
global $jabber;
if ($attributes["ID"]) {
$jabber["jid"] = $attributes["ID"];
}
if (stristr($name, "error") || ($attributes["ERROR"])) {
$jabber["error"] = true;
}
}
function jabber_end($parser, $name) {
}
function jabber_data($parser, $data) {
global $jabber;
$jabber["data"] = $data;
}
function jabber_send($session, $message) {
- Bugfix: renamed the SQL field 'types' to 'nodes' because 'types' is a reserved keyword in MySQL 4. This fixes critical bug #1618. Patch by Marco. ==> This fix requires to run update.php! - Bugfix: made sessions work without warnings when register_globals is turned off. The solution is to use $_SESSION instead of session_register(). This fixes critical bug #1797. Patch by Marco. - Bugfix: sometimes error messages where being discarded when previewing a node. Patch by Craig Courtney. - Bugfix: fixed charset problems. This fixes critical bug #1549. Patch '0023.charset.patch' by Al. - Code improvements: removed some dead code from the comment module. Patch by Marco. - Documentation improvements: polished the node module help texts and form descriptions. Patch '0019.node.module.help.patch' by Al. - CSS improvements all over the map! Patch '0021.more.css.patch' by Al. - GUI improvements: improved the position of Druplicon in the admin menu. Patch '0020.admin.logo.patch' by Al. - GUI improvements: new logos for theme Marvin and theme UnConeD. Logos by Kristjan Jansen. - GUI improvements: small changes to the output emitted by the profile module. Suggestions by Steven Wittens. - GUI improvements: small fixes to Xtemplate. Patch '0022.xtemplate.css.patch' by Al. TODO: - Some modules such as the buddy list module and the annotation module in the contributions repository are also using session_register(). They should be updated. We should setup a task on Drupal. - There is code emitting '<div align="right">' which doesn't validate. - Does our XML feeds validate with the charset changes? - The forum module's SQL doesn't work properly on PostgreSQL.
2003-06-04 18:24:39 +00:00
// print "SEND: ". htmlspecialchars($message) ."<br />";
fwrite($session, $message, strlen($message));
}
function jabber_recv($session, $timout = 50) {
/*
** Returns a chunk of data, read from the socket descriptor '$session'.
** If the call fails, or if no data is read after the specified timout,
** false will be returned.
*/
while ($count < $timout) {
$data = fread($session, 1);
if ($data) {
$message .= $data;
}
else {
usleep(100);
$count = $count + 1;
}
}
if ($message) {
- Bugfix: renamed the SQL field 'types' to 'nodes' because 'types' is a reserved keyword in MySQL 4. This fixes critical bug #1618. Patch by Marco. ==> This fix requires to run update.php! - Bugfix: made sessions work without warnings when register_globals is turned off. The solution is to use $_SESSION instead of session_register(). This fixes critical bug #1797. Patch by Marco. - Bugfix: sometimes error messages where being discarded when previewing a node. Patch by Craig Courtney. - Bugfix: fixed charset problems. This fixes critical bug #1549. Patch '0023.charset.patch' by Al. - Code improvements: removed some dead code from the comment module. Patch by Marco. - Documentation improvements: polished the node module help texts and form descriptions. Patch '0019.node.module.help.patch' by Al. - CSS improvements all over the map! Patch '0021.more.css.patch' by Al. - GUI improvements: improved the position of Druplicon in the admin menu. Patch '0020.admin.logo.patch' by Al. - GUI improvements: new logos for theme Marvin and theme UnConeD. Logos by Kristjan Jansen. - GUI improvements: small changes to the output emitted by the profile module. Suggestions by Steven Wittens. - GUI improvements: small fixes to Xtemplate. Patch '0022.xtemplate.css.patch' by Al. TODO: - Some modules such as the buddy list module and the annotation module in the contributions repository are also using session_register(). They should be updated. We should setup a task on Drupal. - There is code emitting '<div align="right">' which doesn't validate. - Does our XML feeds validate with the charset changes? - The forum module's SQL doesn't work properly on PostgreSQL.
2003-06-04 18:24:39 +00:00
// print "RECV: ". htmlspecialchars($message) ."<br />";
return $message;
}
else {
return 0;
}
}
function jabber_auth($username, $password, $server) {
global $jabber;
$session = fsockopen($server, 5222, $errno, $errstr, 5);
if ($session) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "jabber_start", "jabber_end");
xml_set_character_data_handler($xml_parser, "jabber_data");
/*
** Switch the given socket descriptor '$session' to non-blocking mode:
*/
set_socket_blocking($session, false);
/*
** A jabber session consists of two parallel XML streams, one from
** the client to the server and one from the server to the client.
** On connecting to a Jabber server, a Jabber client initiates the
** client-to-server XML stream and the server responds by initiating
** the server-to-client XML stream:
*/
jabber_send($session, "<?xml version='1.0'?>");
jabber_send($session, "<stream:stream to='$server' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>");
$data = jabber_recv($session);
if (!xml_parse($xml_parser, $data, 0)) {
watchdog("error", "XML error: '". xml_error_string(xml_get_error_code($xml_parser)) ."' at line ". xml_get_current_line_number($xml_parser));
return 0;
}
if ($jabber["error"]) {
watchdog("error", "protocol error: ". $jabber["data"]);
return 0;
}
/*
** Hash the password:
*/
jabber_send($session, "<iq type='set' id='". $jabber["jid"] ."'><query xmlns='jabber:iq:auth'><username>$username</username><password>$password</password><resource>drupal</resource></query></iq>");
$data = jabber_recv($session);
if (!xml_parse($xml_parser, $data, 0)) {
watchdog("error", "XML error: '". xml_error_string(xml_get_error_code($xml_parser)) ."' at line ". xml_get_current_line_number($xml_parser));
}
if ($jabber["error"]) {
watchdog("error", "protocol error: ". $jabber["data"]);
return 0;
}
xml_parser_free($xml_parser);
return 1;
}
else {
watchdog("error", "failed to open socket to jabber server:\n $errno, $errstr");
return 0;
}
}
function jabber_page() {
theme("header");
theme("box", "Jabber", jabber_auth_help());
theme("footer");
}
function jabber_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "<p><a href=\"http://www.jabber.org/\">Jabber</a> is an <a href=\"http://www.opensource.org\">open source</a> instant messaging system designed to give the power of choice and freedom back to the users of instant messaging. Not only does Jabber allow its users to use (and create) clients for numerous platforms, but it allows people to communicate to whomever they want in the way which is most convenient for them.</p>";
$output .= "<p>You may login to %s using a <b>Jabber ID</b>. The format of a Jabber ID is the same as an email address: <b>name</b>@<i>server</i> An example of valid Jabber ID is <b>mwlily</b>@<i>jabber.com</i>. Note that you must be able to access port 111 on the Jabber server from your web server. For example, sourceforge.net blocks port 111 so Jabber authentication does not work.</p>";
return t($output, array("%s" => "<i>$site</i>"));
}
function jabber_user($type, $edit, $user) {
$module = "jabber";
$name = module_invoke($module, "info", "name");
switch ($type) {
case "view_private":
$result = user_get_authname($user, $module);
if ($result) {
$output .= form_item(t("$name ID"), $result);
}
return $output;
case "edit_form":
$result = user_get_authname($user, $module);
2003-01-06 19:51:01 +00:00
$output .= form_textfield(t("$name ID"), "authname_" . $module, $result, 30, 55, t("You may login to %s using a valid %id.", array("%s" => variable_get("site_name", "this web site"), "%id" => l("$name ID", "user/help#$module"))));
return $output;
case "edit_validate":
return user_validate_authmap($user, $edit["authname_$module"], $module);
}
}
- Bugfix: renamed the SQL field 'types' to 'nodes' because 'types' is a reserved keyword in MySQL 4. This fixes critical bug #1618. Patch by Marco. ==> This fix requires to run update.php! - Bugfix: made sessions work without warnings when register_globals is turned off. The solution is to use $_SESSION instead of session_register(). This fixes critical bug #1797. Patch by Marco. - Bugfix: sometimes error messages where being discarded when previewing a node. Patch by Craig Courtney. - Bugfix: fixed charset problems. This fixes critical bug #1549. Patch '0023.charset.patch' by Al. - Code improvements: removed some dead code from the comment module. Patch by Marco. - Documentation improvements: polished the node module help texts and form descriptions. Patch '0019.node.module.help.patch' by Al. - CSS improvements all over the map! Patch '0021.more.css.patch' by Al. - GUI improvements: improved the position of Druplicon in the admin menu. Patch '0020.admin.logo.patch' by Al. - GUI improvements: new logos for theme Marvin and theme UnConeD. Logos by Kristjan Jansen. - GUI improvements: small changes to the output emitted by the profile module. Suggestions by Steven Wittens. - GUI improvements: small fixes to Xtemplate. Patch '0022.xtemplate.css.patch' by Al. TODO: - Some modules such as the buddy list module and the annotation module in the contributions repository are also using session_register(). They should be updated. We should setup a task on Drupal. - There is code emitting '<div align="right">' which doesn't validate. - Does our XML feeds validate with the charset changes? - The forum module's SQL doesn't work properly on PostgreSQL.
2003-06-04 18:24:39 +00:00
?>