<?php
/*
*
*
*
*
*
*/
/**
* See @p StartLine.php @p for details
*/
include_once dirname(dirname(__FILE__)) . "/xml/StartLine.php";
/**
* See @p Element.php @p for details
*/
include_once dirname(dirname(__FILE__)) . "/xml/Element.php";
/**
* See @p Tag.php @p for details
*/
include_once dirname(dirname(__FILE__)) . "/aml/Tag.php";
/**
* See @p SSocket.php @p for details
*/
include_once dirname(dirname(__FILE__)) . "/net/SSocket.php";
/**
* See @p SocketContext.php @p for details
*/
include_once dirname(__FILE__) . "/SocketContext.php";
/**
* See @p SSocketHandler @p for details
*/
include_once dirname(__FILE__) . "/SSocketHandler.php";
/**
*
*
*
*
*/
class XMPPEndpoint {
/*
*
*
*
*
*/
var $targetAddress;
/*
*
*
*
*
*/
var $targetPort;
/*
*
*
*
*
*
*/
var $socket;
/*
*
*
*
*
*
*
*/
var $socketContext;
/*
*
*
*
*
*
*/
var $socketHandler;
/*
*
*
*
*
*/
var $loginID;
/*
*
*
*
*
*
*/
function __construct($targetAddress, $targetPort) {
echo get_class($this)."#__construct(".get_class($targetAddress).", ".get_class($targetPort).")\n";
$this->targetAddress = $targetAddress;
$this->targetPort = $targetPort;
$this->init();
}
/*
*
*
*
*
*/
function init() {
$this->socket = new SSocket("tcp://{$this->targetAddress}:{$this->targetPort}");
}
/*
*
*
*
*
*
*
*/
function connect() {
$this->socket->connect($this->targetAddress, $this->targetPort);
//$sock = $this->socket->getSocket();
$this->socketContext = $this->createSocketContext();
}
function reconnect() {
$this->init();
$this->connect();
}
/*
*
*
*
*
*
*
*
*/
function process() {
$cursor = $this->socketHandler->getCursor();
while (true) {
$firstChild = $cursor->getFirstChild();
//echo "&&&&&&&&&&&&&&&&&&&&&&&&:\n";
//var_dump($cursor);
//stream:features
if ($firstChild != null) {
$name = $firstChild->getName();
$name = strtolower($name);
if ($name == "stream:features") {
break;
}
}
echo "...\n";
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Failure: " . $e->getMessage() . "\n";
return false;
}
}
return true;
}
/*
*
*
*
*
*
*
*/
function toStream() {
$bf = '<stream:stream to="gmail.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">';
//$bf = '<xstream to="gmail.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">';
//$bf = '<stream:stream>';
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Failure: " . $e->getMessage() . "\n";
return false;
}
return true;
}
/*
*
*
*
*
*
*
*/
function openStream() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
echo "Open stream...\n";
$b = $this->toStream();
if ($b) {
echo "Success to open stream...Ok\n";
}
$this->process();
return $b;
}
/*
*
*
*
*
*
*
*
*/
function createSocketContext($socket = null) {
if ($socket == null) {
$socket = $this->socket;
}
if ($socket instanceof SSocket) {
$socket = $socket->getSocket();
}
$socketContext = new SocketContext($socket);
$this->socketHandler = new SSocketHandler($socket);
$socketContext->addObserver($this->socketHandler);
return $socketContext;
}
/*
*
*
*
*
*
*
*/
function startTLS() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
echo "Starting TLS...\n";
$bf = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>";
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail: " . $e->getMessage() . "\n";
return false;
}
return true;
}
/*
*
*
*
*
*
*
*
*/
function getAuthenticateRequest() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
$this->socket->crypto(STREAM_CRYPTO_METHOD_TLS_CLIENT, true);
$b = $this->toStream();
$this->process();
echo "Attempting Auth...\n";
$auth = base64_encode("\x00"."*********"."\x00"."*********");
$bf = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>".$auth."</auth>";
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
return true;
}
function setBind() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
//$this->socket->crypto(STREAM_CRYPTO_METHOD_TLS_CLIENT, false);
//$this->reconnect();
$b = $this->toStream();
$this->process();
echo "Attempting bind...\n";
$bf = '<iq xmlns="jabber:client" type="set" id="1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>gtalk</resource></bind></iq>';
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
/*
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
*/
$cursor = $this->socketHandler->getCurrentNode();
$this->loginID = $cursor->getText();
echo "****************************************************************\n";
//var_dump($cursor);
echo "****************************************************************\n";
return true;
}
/*
* <iq xmlns='jabber:client' type='set' id='2'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>
*
*
*
*
*
*/
function openSession() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
//$this->socket->crypto(STREAM_CRYPTO_METHOD_TLS_CLIENT, false);
//$this->reconnect();
//$b = $this->toStream();
//$this->process();
echo "Open session...\n";
$bf = "<iq xmlns='jabber:client' type='set' id='2'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>";
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
/*
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
*/
return true;
}
/*
* <message from='luoix0423@gmail.com/xmpphp81E902FF' to='atm.luo@gmail.com' type='chat'><body>abcdefg!</body></message>
*
*
*
*
*/
function messaging() {
/*
if (! ($socketContext instanceof SocketContext)) {
throw new Exception("Illegal argument ".get_class($socket));
}
$socket = $socketContext->getSocket();
*/
//$this->socket->crypto(STREAM_CRYPTO_METHOD_TLS_CLIENT, false);
//$this->reconnect();
//$b = $this->toStream();
//$this->process();
echo "Open session...\n";
echo "Auth-ID: ", $this->loginID, "\n";
$bf = "<message from='".$this->loginID."' to='atm.luo@gmail.com' type='chat'><body>Hello, This is ".$this->loginID."!</body></message>";
$outputStream = $this->socket->getOutputStream();
$outputStream->write($bf);
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
/*
try {
$this->socketContext->notify();
} catch (Exception $e) {
echo "Fail to request authentication: " . $e->getMessage() . "\n";
return false;
}
*/
return true;
}
/*
//
$bf = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>";
$b = socket_write($socket, $bf);
if ($b == false) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Error occurs while writing data: ", $bf, "\n";
}
echo "Ok to write data: ", $bf, "\n";
try {
$socketContext->notify();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
//$bf = socket_read($socket, 1024);
//echo "Ok to read data: ", $bf, "\n";
//
$bf = '<stream:stream to="gmail.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">';
$b = socket_write($socket, $bf);
if ($b == false) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Error occurs while writing data: ", $bf, "\n";
}
echo "Ok to write data: ", $bf, "\n";
try {
$socketContext->notify();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
//$bf = socket_read($socket, 1024);
//echo "Ok to read data: ", $bf, "\n";
//
$bf = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AGx1b2l4MDQyMwBqeGNvY28xMTI4</auth>";
$b = socket_write($socket, $bf);
if ($b == false) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Error occurs while writing data: ", $bf, "\n";
}
echo "Ok to write data: ", $bf, "\n";
try {
$socketContext->notify();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
//$bf = socket_read($socket, 1024);
//echo "Ok to read data: ", $bf, "\n";
*/
}
/*
function connect($targetAddress, $targetPort) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (! $socket) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Error occurs while create socket... Error, error code: ".$error_code.", error message: ".$message."\n";
return false;
}
echo "Socket create... "."Ok\n";
echo "---------", "---------", "\n";
//
$b = socket_bind($socket, "localhost", 1192);
if (! $b) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Failure to bind socket to localhost:", 1192, "... Failure, error code: ".$error_code.", error message: ".$message."\n";
}
echo "Bind socket to localhost:", 1192, "... Ok\n";
//
echo "Connecting to ".$targetAddress.":".$targetPort."...\n";
$b = socket_connect($socket, $targetAddress, $targetPort);
if ($b == false) {
$error_code = socket_last_error();
$message = socket_strerror($error_code);
echo "Failure to connect $targetAddress:", $targetPort, "... Failure, error code: ".$error_code.", error message: ".$message."\n";
return false;
}
return $socket;
}
*/
/**
*
*
*
*
*
*/
class GTalk {
/*
// talk.google.com:5222
// talk.google.com:5223
*
*
*
*
*/
var $targetAddress = "talk.google.com";
/*
*
*
*
*
*
*/
var $targetPort = 5222;
/*
*
*
*
*
*
*
*/
var $endpoint;
/*
*
*
*
*
*
*
*/
function __construct() {
$this->init();
}
/*
*
*
*
*
*
*
*/
function init() {
$this->endpoint = new XMPPEndpoint($this->targetAddress, $this->targetPort);
$this->endpoint->connect();
}
/*
*
*
*
*
*
*
*/
function start() {
$this->endpoint->openStream();
$this->endpoint->startTLS();
$this->endpoint->getAuthenticateRequest();
$this->endpoint->setBind();
$this->endpoint->openSession();
$this->endpoint->messaging();
}
}
/*
*
*
*
*
*
*
*/
$gtalk = new GTalk();
$gtalk->start();
?>
- 浏览: 426104 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (433)
- 编程语言-JAVA/Scala/Clojure/Grovvy (86)
- 编程语言-C (227)
- 编程语言-Rust/C++/Objective-C/Objective-C++ (97)
- 编程语言-PHP (4)
- 编程语言-Perl (4)
- 编程语言-Javascript (6)
- 编程语言-Scheme/Lisp (9)
- 编程语言-lua (5)
- 编程语言-erl (4)
- 编程语言-go (4)
- 编程语言-Ruby (3)
- 编程语言-python (4)
- 编程语言-smalltalk (3)
- 编程语言-guile (3)
- 算法结构 (32)
- 多线程编程 (2)
- 网络编程 (7)
- 并发编程 (21)
- 并行编程 (2)
- 事务 (4)
- 架构/编程-模型/模式/思想 (6)
- 开发框架-Spring (2)
- 开发框架-ibatis (0)
- 开发框架-Struts (0)
- 开发框架-Hibernate (0)
- 开发框架-mybatis (0)
- 分布式 (38)
- 分布式存储 (10)
- 分布式文件系统-dfs (4)
- 分布式计算 (2)
- 分布式事务 (10)
- 分布式数据中间件 (1)
- 分布式服务框架 (12)
- rpc (8)
- 通信 (23)
- 电信 (3)
- 电商 (1)
- 互联网应用 (2)
- 大前端 (5)
- 第三方支付 (2)
- CSS (1)
- android (3)
- ios (0)
- html5 (0)
- kafka (0)
- memcached (2)
- nginx (1)
- 并行计算 (1)
- 实时计算 (0)
- Storm (0)
- 数据库 (7)
- mysql (6)
- oracle (3)
- redis (4)
- mongodb (2)
- hbase (1)
- dal (0)
- handoop (1)
- 机器学习-ML (3)
- 深度学习-DL (0)
- 神经网络 (0)
- netty (4)
- mina (0)
- 大数据 (7)
- 大数据-算法 (0)
- 大数据-框架&平台 (3)
- 人工智能 (7)
- 人工智能-算法 (4)
- 人工智能-框架&平台 (0)
- 协议 (42)
- 安全 (15)
- 消息队列 (2)
- os(linux、windows) (85)
相关推荐
《PHPMailer邮件发送类详解与应用》 在PHP开发中,发送邮件是一项常见的需求,而PHPMailer是一个强大的、广泛使用的邮件发送类库,尤其适用于PHP5及以上版本。它提供了丰富的功能,包括支持SMTP验证、POP3收信以及...
PHP 基础实例 在HTML中嵌入PHP 使用 PHP 标记 PHP 语句 使用 PHP 注释 PHP 语句间的空格问题 添加动态内容 使用 PHP 函数 PHP nl2br()格式化输出 PHP 打印格式化输出 PHP 字符串的整理 PHP 改变字符串中字母的大小写...
php实现RS232串口通信 下载php_ser_5.2.0.zip 解冻把php_ser放到ext目录下, php.ini里加上: extension=php_ser.dll PHP code string ser_version( void ) void ser_open( string port, int baudrate, int databits, ...
标题:PHP基础教程 出处:风流的CG网络日志 时间:Mon, 28 Aug 2006 07:24:34 +0000 作者:yufeng 地址:http:///read.php?38 内容: 提供给新手学习的 PHP新手教程,是一个比较有价值的PHP新手教程! 一、PHP...
支持 PHP 版本 (Thread Safe): 5.5.* x86 5.5.* x64 5.6.* x86 5.6.* x64 测试环境 Windows7 64bit PHP 5.5.35 TS x86 PHP 5.5.35 TS x64 PHP 5.6.21 TS x86 PHP 5.6.21 TS x64 将对应的版本 ...
张恩民 老师 的PHP视频教程【www.php100.com】 绝对是PHP教程中的经典。 PHP100视频教程目录(共112集) PHP100视频教程1:环境配置与代码调试 PHP100视频教程2:PHP的数据类型与源码调试 PHP100视频教程3:常用PHP...
【PHP网站模板与源码详解】 在Web开发领域,PHP是一种广泛应用的服务器端脚本语言,尤其在构建动态网站方面有着显著的优势。"精美php网站模板"是指预先设计和编码完成的网页布局,用于快速搭建具有专业外观和功能的...
总结来说,"json for PHP4.0"提供了一种在PHP 4.0环境下处理JSON数据的方法,通过自定义的`Json`类模拟了`json_encode`的功能,允许开发者在不支持内置JSON功能的PHP版本中进行数据交换。通过学习和理解这个类的工作...
FPDF(Free PDF Generator)是一个用PHP编写的开源库,用于生成PDF文档。这个库的主要优点是它完全用PHP编写,无需任何外部依赖,因此在服务器端生成PDF文档时非常方便。"chinese.php"是FPDF的一个扩展,专门为解决...
php_igbinary-1.2.1-5.5-nts-vc11-x64 php_igbinary-1.2.1-5.5-nts-vc11-x86 php_igbinary-1.2.1-5.5-ts-vc11-x64 php_igbinary-1.2.1-5.5-ts-vc11-x86 php_redis-2.2.7-5.6-nts-vc11-x64 ...
PHP php_igbinary.dll PHP5.4以上所有版本扩展分别包括 php_igbinary-2.0.1-5.5-nts-vc11-x86 php_igbinary-2.0.1-5.5-ts-vc11-x64 php_igbinary-2.0.1-5.5-ts-vc11-x86 php_igbinary-2.0.1-5.6-nts-vc11-x64 ...
《PHP 5.4.7在Linux环境下的部署与应用详解》 PHP(Hypertext Preprocessor)是一种广泛使用的开源脚本语言,尤其在Web开发领域有着重要地位。本文将聚焦于PHP 5.4.7版本,这个版本在Linux操作系统上的部署、配置...
声明:本PHP-webshell仅供学习交流以及网站安全检测之用,功能过于强大,请不要用过非法用途,否则一切后果由使用者本人承担! 使用方法:上传至网站任意目录连接即可,其中 $admin['pass'] = "admin"; 后面引号里...
这篇PHP动态网页作业是针对大学生设计的,旨在教授如何结合PHP和MySQL技术创建交互式的Web应用。PHP是一种广泛使用的开源脚本语言,尤其适合于Web开发,可以嵌入到HTML中,实现动态网页内容的生成。而MySQL则是一种...
PHP 期末考试试题解析 以下是对 PHP 期末考试试题的详细解析和知识点总结: 一、选择题部分 1. 该题考察了 PHP 的作用域和变量的使用。函数 `test` 中访问了全局变量 `$a`,但由于变量 `$a` 在函数外部定义,因此...
9-6 4.php xml编程⑨-综合练习-基于xml的在线词典 phpdom使用xpath 9-6 5.php xml编程(10)-SimpleXML 9-7 1.回顾 9-7 2.析构方法 9-7 3.static关键字(静态变量) 9-7 4.static关键字(静态方法) 面向对象编程三大特性...
1,中小型企业内部自动化办公管理………PHP源码 2,网上社区系统……………………………PHP源码 3, 供求信息网………………………………PHP源码 4, 网络在线考试网站………………………PHP源码 5,电子商务购物商城...
这个程序对于初学者理解PHP、HTTP协议以及数据库交互原理非常有帮助。在这个项目中,我们将探讨以下几个关键知识点: 1. **PHP基础**:PHP是一种服务器端的脚本语言,常用于网页开发。在登录和注册系统中,PHP处理...