<?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();
?>
- 浏览: 378995 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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)
相关推荐
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视频教程【www.php100.com】 绝对是PHP教程中的经典。 PHP100视频教程目录(共112集) PHP100视频教程1:环境配置与代码调试 PHP100视频教程2:PHP的数据类型与源码调试 PHP100视频教程3:常用PHP...
声明:本PHP-webshell仅供学习交流以及网站安全检测之用,功能过于强大,请不要用过非法用途,否则一切后果由使用者本人承担! 使用方法:上传至网站任意目录连接即可,其中 $admin['pass'] = "admin"; 后面引号里...
传智播客PHP就业班视频课程列表 8-11 1.html介绍 html运行原理① 8-11 2.html运行原理② html文件基本结构 html元素和属性 8-11 3.符号实体 url说明 超链接 发送电邮 8-11 4.图像 表格 实际应用-菜谱 课堂练习-课程...
境配置、表单及表单元素的应用、CSS与JavaScript脚本的应用、验证控件、构建PHP动态网页、PHP与MySQL的数据库技术、PHP与其他数据库技 术、SQL查询相关技术、MySQL高级应用技术、字符串的处理技术、PHP面向对象编程...
传智播客PHP就业班视频课程列表 8-11 1.html介绍 html运行原理① 8-11 2.html运行原理② html文件基本结构 html元素和属性 8-11 3.符号实体 url说明 超链接 发送电邮 8-11 4.图像 表格 实际应用-菜谱 课堂练习-课程...
phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站phpphp网站...
《PHP+MySQL动态网站开发》详细介绍了PHP的脚本语言基础、运行环境和PHP面向对象编程(包括MySQL数据库)的知识。全书共19章,内容分为理论部分和实战部分。理论部分包括PHP技术概述和基本语法、字符串和正则表达式、...
3.finfo_open 需要php环境支持二进制,我用的lnmp组合套件是直接支持二进制,没有的自行百度解决哦。 4.很多网上的fileupload.php文件,切片上传大于5M的成功,小于5m的失败,demo中的是已经经过优化。 5.demo中的...
本书共分为13章,涵盖了PHP开发环境的搭建、PHP语法、FORM表单、数据库设计、PHP与数据库连接、会话控制、界面设计等内容。 本书由孔祥盛主编,内容丰富、讲解深入,适用于初、中级PHP用户,可以用做各类院校相关...
PHP初学者的首选,被誉为PHP的圣经 导读 第一章 PHP 介绍 来龙去脉 功能概述 PHP 与其它 CGI 的比较 第二章 安装与配置 环境需求与准备工作 快速配置及安装 PHP 的编译配置详细选项 php.ini 配置详细选项...
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关键字(静态方法) 面向对象编程三大特性...
PHP 基础实例 在HTML中嵌入PHP 使用 PHP 标记 PHP 语句 使用 PHP 注释 PHP 语句间的空格问题 添加动态内容 使用 PHP 函数 PHP nl2br()格式化输出 PHP 打印格式化输出 PHP 字符串的整理 PHP 改变字符串中字母的大小写...
php文本站内全文检索说明: 1。文件结构: search.php和template.php(界面风格文件,可随意修改),search0.php是search.php的加强版。 2。特点 1)无需mysql支持,无需建立索引,无需设置路径,放在哪级目录下...
phpweb二次开发,phpweb破解版,phpweb后台升级,phpweb2.0.5升级,phpweb成品网站商业版v1.5.0/20111209升级包 phpweb成品网站升级包免费送给爱好phpweb成品网站朋友,已经更新到最新的v2.0.5/20120412 免责声明:此...
全书共分27章,包括初识.PHP、PHP环境搭建和开发工具、PHP语言基础、流程控制语句、字符串操作、正则表达式、PHP数组、PHP与Web页面交互、PHP与JavaScript交互、日期和时间、Cookie与Session、图形图像处理技术、...
ffmpeg-php 是一个php扩展,用来获取视频或音频信息,你可以用它从视频中截取图片、获取视频时长,视频的长、宽等。 下面介绍在windows环境下本扩展的安装,在安装本扩展之前你首先要确认你本地环境中已经安装好了...
PHP是一 种被广泛应用的开放源代码的、基于服务器端的用于产生动态网页 的、可嵌入HTML中的脚本程序语言,尤其适合 WEB 开发。下面给大家分享PHP小白必须要知道的php基础知识,超实用,感兴趣的朋友一起学习吧 很多...
PHP实例之新闻发布系统 Create TABLE `news` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `p_time` DATETIME NOT NULL , `title` VARCHAR( 80 ) NOT NULL , `detail` TEXT NOT NULL ) TYPE = innodb; ...