<?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();
?>
- 浏览: 425964 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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)
相关推荐
Jupyter-Notebook
Jupyter-Notebook
高效甘特图模板下载-精心整理.zip
lstm Summary Framework: z = U>x, x u Uz Criteria for choosing U: • PCA: maximize projected variance • CCA: maximize projected correlation • FDA: maximize projected intraclass variance
OpenGL调试工具,适合图形开发者,包括视频开发,播放器开始以及游戏开发者。
全国行政区划shp最新图.zip
全国研究生招生与在校数据+国家线-最新.zip
Jupyter-Notebook
直播电商交流平台 SSM毕业设计 附带论文 启动教程:https://www.bilibili.com/video/BV1GK1iYyE2B
《林黛玉进贾府》课本剧剧本
2000-2020年沪深A股上市公司融资约束程度SA指数-最新数据发布.zip
PPT模版资料,PPT模版资料
CPA注会考试最新教材资料-最新发布.zip
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
内容概要:本文提供了一个完整的职工管理系统的C++源代码。通过面向对象的编程方法,实现了包括创建新职工、查询、增加、修改、删除、排序、统计以及存储和恢复职工数据在内的多个基本操作功能。该系统支持不同的用户角色(如管理员与老板),并通过菜单驱动方式让用户方便地进行相关操作。此外,还包括了错误检测机制,确保操作过程中的异常得到及时处理。 适合人群:有一定C++语言基础,特别是面向对象编程经验的程序员;企业管理人员和技术开发人员。 使用场景及目标:适用于中小型企业内部的人力资源管理部门或IT部门,用于维护员工基本信息数据库,提高工作效率。通过本项目的学习可以加深对链表、类和对象的理解。 阅读建议:建议先熟悉C++的基本语法和面向对象概念,再深入学习代码的具体实现细节。对于关键函数,比如exchange、creatilist等,应当重点关注并动手实践以加强理解。
Jupyter-Notebook
考研公共课历年真题集-最新发布.zip
Huawei-HKUST Joint Workshop on Theory for Future Wireless 15-16 September 2022 华为-香港科技大学未来无线理论联合研讨会 Speaker:Jingwen Tong
演出人员与观众疫情信息管理系统 SSM毕业设计 附带论文 启动教程:https://www.bilibili.com/video/BV1GK1iYyE2B
《林黛玉进贾府》课本剧剧本.pdf