Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Room config and bookmarks #57

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/nbproject/
composer.lock
composer.phar
/phpunit.xml
.idea
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.7.0 (2017-05-23)

- [MAJOR]: [PR #46](https://github.com/fabiang/xmpp/pull/46) Added support for password-protected chatrooms
- [MAJOR]: [PR #44](https://github.com/fabiang/xmpp/pull/44) Added anonymous authentication method
- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added support for registereing user
- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added vCard support
- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added support for blocking and unblocking an user
- [MAJOR]: Drop support for PHP lower than 5.6
- [MAJOR]: [PR #31](https://github.com/fabiang/xmpp/pull/31): Possibility to set context for SocketClient

## 0.6.1 (2014-11-20)

- [PATCH] [Issue #4](https://github.com/fabiang/xmpp/issues/4): Incomplete buffer response
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simplified BSD License
======================

Copyright 2014 Fabian Grutschus.
Copyright 2014-2017 Fabian Grutschus.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# fabiang/xmpp

[![Latest Stable Version](https://poser.pugx.org/fabiang/xmpp/v/stable.svg)](https://packagist.org/packages/fabiang/xmpp) [![Total Downloads](https://poser.pugx.org/fabiang/xmpp/downloads.svg)](https://packagist.org/packages/fabiang/xmpp) [![Latest Unstable Version](https://poser.pugx.org/fabiang/xmpp/v/unstable.svg)](https://packagist.org/packages/fabiang/xmpp) [![License](https://poser.pugx.org/fabiang/xmpp/license.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Build Status](https://travis-ci.org/fabiang/xmpp.png?branch=master)](https://travis-ci.org/fabiang/xmpp) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fabiang/xmpp/badges/quality-score.png?s=2605ad2bc987ff8501b8f749addff43ec1ac7098)](https://scrutinizer-ci.com/g/fabiang/xmpp/) [![Coverage Status](https://img.shields.io/coveralls/fabiang/xmpp.svg)](https://coveralls.io/r/fabiang/xmpp?branch=master) [![Dependency Status](https://gemnasium.com/fabiang/xmpp.png)](https://gemnasium.com/fabiang/xmpp) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74/mini.png)](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74)

Library for XMPP protocol connections (Jabber) for PHP.

[![License](https://poser.pugx.org/fabiang/xmpp/license.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Latest Stable Version](https://poser.pugx.org/fabiang/xmpp/v/stable.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Total Downloads](https://poser.pugx.org/fabiang/xmpp/downloads.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Dependency Status](https://gemnasium.com/fabiang/xmpp.svg)](https://gemnasium.com/fabiang/xmpp)
[![Build Status](https://travis-ci.org/fabiang/xmpp.png?branch=master)](https://travis-ci.org/fabiang/xmpp)
[![Coverage Status](https://img.shields.io/coveralls/fabiang/xmpp.svg)](https://coveralls.io/r/fabiang/xmpp?branch=master)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fabiang/xmpp/badges/quality-score.png?s=2605ad2bc987ff8501b8f749addff43ec1ac7098)](https://scrutinizer-ci.com/g/fabiang/xmpp/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74/mini.png)](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74)

## SYSTEM REQUIREMENTS

- PHP >= 5.3.3
- PHP minimum 5.6 or minimum 7.0
- psr/log
- psr/log-implementation - like monolog/monolog for logging (optional)
- (optional) psr/log-implementation - like monolog/monolog for logging

## INSTALLATION

New to Composer? Read the [introduction](https://getcomposer.org/doc/00-intro.md#introduction). Add the following to your composer file:

```json
{
"require": {
"fabiang/xmpp": "*"
}
}
```bash
composer require fabiang/xmpp
```

## DOCUMENTATION
Expand Down Expand Up @@ -73,6 +75,7 @@ $client->send($message);
// join a channel
$channel = new Presence;
$channel->setTo('channelname@conference.myjabber.com')
->setPassword('channelpassword')
->setNickName('mynick');
$client->send($channel);

Expand All @@ -95,14 +98,14 @@ $client->disconnect();
If you like this library and you want to contribute, make sure the unit-tests and integration tests are running.
Composer will help you to install the right version of PHPUnit and [Behat](http://behat.org/).

composer install --dev
composer install

After that:

./vendor/bin/phpunit -c tests
./vendor/bin/behat --config=tests/behat.yml --strict
./vendor/bin/phpunit
./vendor/bin/behat

New features should allways tested with Behat.
New features should always tested with Behat.

## LICENSE

Expand All @@ -112,5 +115,4 @@ BSD-2-Clause. See the [LICENSE](LICENSE.md).

- Better integration of channels
- Factory method for server addresses
- Add support von vCard
- improve documentation
6 changes: 6 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default:
paths:
features: %behat.paths.base%/tests/features
bootstrap: %behat.paths.features%/bootstrap
context:
class: Fabiang\Xmpp\Integration\FeatureContext
21 changes: 15 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
}
},
"require": {
"php": ">=5.3.3",
"psr/log": "~1.0"
"php": "^5.6 || ^7.0",
"psr/log": "^1.0"
},
"require-dev": {
"monolog/monolog": "~1.11",
"phpunit/phpunit": "~4.3",
"behat/behat": "~2.5",
"satooshi/php-coveralls": "~0.6"
"behat/behat": "^2.5.5",
"monolog/monolog": "^1.22",
"phpunit/phpunit": "^5.7.20",
"satooshi/php-coveralls": "^1.0",
"symfony/console": "^2.8",
"symfony/dependency-injection": "^2.8",
"symfony/finder": "^2.8"
},
"suggest": {
"psr/log-implementation": "Allows more advanced logging of the xmpp connection"
Expand All @@ -43,6 +46,12 @@
"dev-master": "1.0.x-dev"
}
},
"config": {
"platform": {
"php": "5.6"
},
"sort-packages": true
},
"archive": {
"exclude": [
".gitignore",
Expand Down
Binary file added examples/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions examples/config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
return [
'host' => 'xmpp.example.com',
'conference' => 'conference.example.com',
'port' => 5222,
'connectionType' => 'tcp',
'verifyPeer' => true,
'login' => 'admin',
'password' => '123456',
];
47 changes: 47 additions & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = require('config.inc.php');

error_reporting(-1);

use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\Message;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Roster;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));

$hostname = 'localhost';
$port = 5222;
$connectionType = 'tcp';
$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];


$options = new Options($address);
$options->setLogger($logger)
->setUsername($config['login'])
->setPassword($config['password']);

if ($config['verifyPeer'] === false) {
$options->setContextOptions([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]);
}

$client = new Client($options);

$client->connect();
$client->send(new Roster);
$client->send(new Presence);
$client->send(new Message);

$client->disconnect();
57 changes: 57 additions & 0 deletions examples/invitation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = require('config.inc.php');
error_reporting(-1);

use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Exception\Stream\StreamErrorException;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\Room\DirectInvite;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));

$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];

$room = 'new-room';
$password = '';
$newUser = 'testuser';

$options = new Options($address);
$options->setLogger($logger)
->setUsername($config['login'])
->setPassword($config['password']);


if ($config['verifyPeer'] === false) {
$options->setContextOptions([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]);
}

$client = new Client($options);

$client->connect();
$invitation = new DirectInvite(
$config['login'] . '@' . $config['host'],
$newUser . '@' . $config['host'],
$room . '@' . $config['conference'],
$password,
'This is a cool party room! Join to it!'
);
try {
$client->send($invitation);

fwrite(STDOUT, 'Invitation sent' . PHP_EOL);
} catch (StreamErrorException $e) {
fwrite(STDOUT, 'Invitation failed' . PHP_EOL);
fwrite(STDOUT, $e->getMessage() . PHP_EOL);
}

$client->disconnect();
91 changes: 91 additions & 0 deletions examples/register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$config = require('config.inc.php');
error_reporting(-1);

use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Exception\Stream\StanzasErrorException;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\User\ChangeUserPassword;
use Fabiang\Xmpp\Protocol\User\RegisterUser;
use Fabiang\Xmpp\Protocol\User\RequestChangePasswordForm;
use Fabiang\Xmpp\Protocol\User\RequestUserRegisterForm;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler( 'php://stdout', Logger::DEBUG));

$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];

$newUser = 'testuser';
$newPassword = '123456';

$options = new Options($address);
$options->setLogger($logger)
->setUsername($config['login'])
->setPassword($config['password']);

if ($config['verifyPeer'] === false) {
$options->setContextOptions([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]);
}


$client = new Client($options);

$client->connect();
$request = new RequestUserRegisterForm($config['login'] . '@' . $config['host'], $config['host']);
$client->send($request);

$form = $client->getOptions()->getForm();
$user = new RegisterUser(
$newUser . '@' . $config['host'],
$newPassword,
$config['login'] . '@' . $config['host'],
$config['host'],
$form
);

try {
$client->send($user);
print 'User is registered' . PHP_EOL;
} catch (StanzasErrorException $e) {
/**
* @see https://xmpp.org/extensions/xep-0086.html#sect-idm139696314152720
*/
if ($e->getCode() == StanzasErrorException::ERROR_CONFLICT) { // conflict
fwrite(STDOUT, 'User already exists. Try to change password' . PHP_EOL);
$request = new RequestChangePasswordForm(
$config['login'] . '@' . $config['host'],
$config['host']
);

try {
$client->send($request);

$form = $client->getOptions()->getForm();
$user = new ChangeUserPassword(
$newUser . '@' . $config['host'],
$newPassword,
$config['login'] . '@' . $config['host'],
$config['host'],
$form
);
} catch (StanzasErrorException $e) {
fwrite(STDOUT, 'Failed to change password of user!' . PHP_EOL);
fwrite(STDOUT, $e->getMessage() . PHP_EOL);
}

} else {
fwrite(STDOUT, 'Failed to register user!' . PHP_EOL);
fwrite(STDOUT, $e->getMessage() . PHP_EOL);
}
}
$client->disconnect();
Loading