2 // This script connects to a jabberserver via bosh and send messages
3 // to a participant and recieves messages and relays to it the
6 // This takes the following arguments:
8 // Tell the bridge what to do. Can have the following parameters:
10 // Initialise the connection
12 // Wait till we recieve an event
14 // Send a message to the other side
16 // Disconnects the session
18 // If op is SendMessage contains the message to be send
20 // This Script returns JSON containing the following parameters:
22 // If greater than 0: some error happend
23 // If equals to 0: everything fine
25 // Containts chat messages or presence informations
27 // A errorstring to display the user
29 ini_set('display_errors','true');
31 error_reporting(E_ALL
& E_STRICT
);
33 require_once('FirePHPCore/fb.php');
35 function handleConnection($conn) {
37 $conn->connect('http://localhost:5280/http-bind', 1, true);
38 $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'),3);
40 $conn->presence($status="Cheese!");
41 if ((is_array($payloads)) && (count($payloads) > 0)) {
42 foreach($payloads as $event) {
46 $retval = array('status' => 0, 'message' => $pl['body'], 'nick' => $pl['from']);
49 $retval = array('status' => 0, 'message' => sprintf('%s: %s', $pl['show'], $pl['status']));
53 $conn->sendVCard(array('nickname' => $_SESSION['chat_nick']));
54 $conn->presence($status="Cheese!");
55 $retval = array('status' => 0, 'message' => 'Connection established');
58 // got nothing, we need to return something, so the connection stays alive.
59 $retval = array('status' => -1, 'message' => '');
62 if (is_array($retval)) {
63 echo json_encode($retval);
65 // got nothing, we need to return something, so the connection stays alive.
66 echo json_encode(array('status' => -1, 'message' => ''));
70 // got nothing, we need to return something, so the connection stays alive.
71 echo json_encode(array('status' => -1, 'message' => ''));
73 } catch(XMPPHP_Exception
$e) {
74 echo json_encode(array('status' => 1, 'message' => sprintf('Connection error: %s', $e->getMessage())));
82 $now = microtime(true);
84 $_SETTINGS['to'] = 'tim@boese-ban.de';
86 $valid_ops = array('InitConnection', 'GetEvents', 'SendMessage', 'Disconnect');
88 if (in_array($op,$valid_ops)) {
89 // activate full error reporting
90 error_reporting(E_ALL
& E_STRICT
);
92 include 'XMPPHP/BOSH.php';
95 case 'InitConnection':
97 $_SESSION['chat_nick'] = $_POST['nick'];
98 $conn = new XMPPHP_BOSH('localhost', 5222, $_SESSION['chat_nick'], '', 'xmpphp', 'localhost');
99 $conn->autoSubscribe();
101 handleConnection($conn);
104 $conn = new XMPPHP_BOSH('localhost', 5222, $_SESSION['chat_nick'], '', 'xmpphp', 'localhost');
105 $conn->autoSubscribe();
106 handleConnection($conn);
109 $message = $_GET['message'];
110 $conn = new XMPPHP_BOSH('localhost', 5222, $_SESSION['chat_nick'], '', 'xmpphp', 'localhost');
111 $conn->autoSubscribe();
113 //printf("9: %f\n", microtime(true) - $now);
114 $conn->connect('http://localhost:5280/http-bind', 1, true);
115 //printf("10: %f\n", microtime(true) - $now);
116 $conn->message($_SETTINGS['to'], $message);
117 //printf("11: %f\n", microtime(true) - $now);
118 echo json_encode(array('status' => 0, 'message' => 'OK'));
119 } catch(XMPPHP_Exception
$e) {
120 echo json_encode(array('status' => 1, 'message' => sprintf('Connection error: %s', $e->getMessage())));