\Communicator.php

Show: inherited

RouterOS API client implementation.

This package allows you to read and write information from a RouterOS host using MikroTik's RouterOS API.

PHP version 5

Author
Vasil Rangelov  
Category
Net  
Copyright
2011 Vasil Rangelov  
License
LGPL License 2.1  
Link
http://netrouteros.sourceforge.net/  
Package
PEAR2_Net_RouterOS  
Version
1.0.0b1  

\PEAR2\Net\RouterOS\Communicator

Package: PEAR2\Net\RouterOS

A RouterOS communicator.

Implementation of the RouterOS API protocol. Unlike the other classes in this package, this class doesn't provide any conviniences beyond the low level implementation details (automatic word length encoding/decoding, charset translation and data integrity), and because of that, its direct usage is strongly discouraged.

See
\PEAR2\Net\RouterOS\Client  
Author
Vasil Rangelov  
Category
Net  
License
LGPL License 2.1  
Link
http://netrouteros.sourceforge.net/  

Constants

Constant  CHARSET_ALL = -1

Used when getting/setting all (default) charsets.

Constant  CHARSET_REMOTE = 0

Used when getting/setting the (default) remote charset.

The remote charset is the charset in which RouterOS stores its data. If you want to keep compatibility with your Winbox, this charset should match the default charset from your Windows' regional settings.

Constant  CHARSET_LOCAL = 1

Used when getting/setting the (default) local charset.

The local charset is the charset in which the data from RouterOS will be returned as. This charset should match the charset of the place the data will eventually be written to.

Properties

Propertyprotectedarray  $charsets= 'array('

An array with the current charset types as keys, and the current charsets as values.
Default valuearray(Details
Type
array
Propertyprotectedarray  $defaultCharsets= 'array( self::CHARSET_REMOTE => null'
static

An array with the default charset types as keys, and the default charsets as values.
Default valuearray( self::CHARSET_REMOTE => nullDetails
Type
array
Propertyprotected\PEAR2\Net\RouterOS\SocketClientTransmitter  $trans= ''

The transmitter for the connection.
Details
Type
\PEAR2\Net\RouterOS\SocketClientTransmitter

Methods

methodpublic__construct( string $host, int $port = 8728, bool $persist = false, float $timeout = null, string $key = '', resource $context = null ) : void

Creates a new connection with the specified options.

Parameters
Name Type Description
$host string

Hostname (IP or domain) of the RouterOS server.

$port int

The port on which the RouterOS server provides the API service.

$persist bool

Whether or not the connection should be a persistent one.

$timeout float

The timeout for the connection.

$key string

A string that uniquely identifies the connection.

$context resource

A context for the socket.

Details
See
\PEAR2\Net\RouterOS\sendWord()  
methodpublicclose( ) : bool

Closes the opened connection, even if it is a persistent one.

Returns
Type Description
bool TRUE on success, FALSE on failure.
methodpublicdecodeLength( \PEAR2\Net\Transmitter\StreamTransmitter $trans ) : int
static

Decodes the lenght of the incoming message.

Decodes the lenght of the incoming message, as specified by the RouterOS API.

Parameters
Name Type Description
$trans \PEAR2\Net\Transmitter\StreamTransmitter

The transmitter from which to decode the length of the incoming message.

Returns
Type Description
int The decoded length
methodpublicencodeLength( int $length ) : string
static

Encodes the length as requred by the RouterOS API.

Parameters
Name Type Description
$length int

The length to encode

Returns
Type Description
string The encoded length
methodpublicgetCharset( int $charsetType ) : string|array

Gets the charset(s) for this connection.

Parameters
Name Type Description
$charsetType int

Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}.

Returns
Type Description
string|array The current charset. If $charsetType is {@link CHARSET_ALL}, the current values will be returned as an array with the types as keys, and charsets as values.
Details
See
\PEAR2\Net\RouterOS\getDefaultCharset()  
See
\PEAR2\Net\RouterOS\setCharset()  
methodpublicgetDefaultCharset( int $charsetType ) : string|array
static

Gets the default charset(s).

Parameters
Name Type Description
$charsetType int

Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}.

Returns
Type Description
string|array The current charset. If $charsetType is {@link CHARSET_ALL}, the current values will be returned as an array with the types as keys, and charsets as values.
Details
See
\PEAR2\Net\RouterOS\setDefaultCharset()  
methodpublicgetNextWord( ) : string

Get the next word in queue as a string.

Get the next word in queue as a string, after automatically decoding its length.

Returns
Type Description
string The word.
Details
See
\PEAR2\Net\RouterOS\close()  
methodpublicgetNextWordAsStream( ) : resource

Get the next word in queue as a stream.

Get the next word in queue as a stream, after automatically decoding its length.

Returns
Type Description
resource The word, as a stream.
Details
See
\PEAR2\Net\RouterOS\close()  
methodpublicgetTransmitter( ) : \PEAR2\Net\Transmitter\SocketClientTransmitter

Gets the transmitter for this connection.

Returns
Type Description
\PEAR2\Net\Transmitter\SocketClientTransmitter The transmitter for this connection.
methodpubliciconvStream( string $in_charset, string $out_charset, resource $stream ) : resource
static

Uses iconv to convert a stream from one charset to another.

Parameters
Name Type Description
$in_charset string

The charset of the stream.

$out_charset string

The desired resulting charset.

$stream resource

The stream to convert.

Returns
Type Description
resource A new stream that uses the $out_charset. The stream is a subset from the original stream, from its current position to its end.
methodpublicsendWord( string $word ) : int

Sends a word.

Sends a word and automatically encodes its length when doing so.

Parameters
Name Type Description
$word string

The word to send.

Returns
Type Description
int The number of bytes sent.
Details
See
\PEAR2\Net\RouterOS\sendWordFromStream()  
See
\PEAR2\Net\RouterOS\getNextWord()  
methodpublicsendWordFromStream( string $prefix, resource $stream ) : int

Sends a word based on a stream.

Sends a word based on a stream and automatically encodes its length when doing so. The stream is read from its current position to its end, and then returned to its current position. Because of those operations, the supplied stream must be seekable.

Parameters
Name Type Description
$prefix string

A string to prepend before the stream contents.

$stream resource

The stream to send.

Returns
Type Description
int The number of bytes sent.
Details
See
\PEAR2\Net\RouterOS\sendWord()  
methodpublicsetCharset( mixed $charset, int $charsetType = self::CHARSET_ALL ) : string|array

Sets the charset(s) for this connection.

Sets the charset(s) for this connection. The specified charset(s) will be used for all future words. When sending, {@link CHARSET_LOCAL} is converted to {@link CHARSET_REMOTE}, and when receiving, {@link CHARSET_REMOTE} is converted to {@link CHARSET_LOCAL}. Setting NULL to either charset will disable charset convertion, and data will be both sent and received "as is".

Parameters
Name Type Description
$charset mixed

The charset to set. If $charsetType is {@link CHARSET_ALL}, you can supply either a string to use for all charsets, or an array with the charset types as keys, and the charsets as values.

$charsetType int

Which charset to set. Valid values are the Communicator::CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}.

Returns
Type Description
string|array The old charset. If $charsetType is {@link CHARSET_ALL}, the old values will be returned as an array with the types as keys, and charsets as values.
Details
See
\PEAR2\Net\RouterOS\setDefaultCharset()  
methodpublicsetDefaultCharset( mixed $charset, int $charsetType = self::CHARSET_ALL ) : string|array
static

Sets the default charset(s) for new connections.

Parameters
Name Type Description
$charset mixed

The charset to set. If $charsetType is {@link CHARSET_ALL}, you can supply either a string to use for all charsets, or an array with the charset types as keys, and the charsets as values.

$charsetType int

Which charset to set. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}.

Returns
Type Description
string|array The old charset. If $charsetType is {@link CHARSET_ALL}, the old values will be returned as an array with the types as keys, and charsets as values.
Details
See
\PEAR2\Net\RouterOS\setCharset()  
methodprotectedverifyLengthSupport( int $length ) : void
static

Verifies that the length is supported.

Verifies if the specified length is supported by the API. Throws a {@link LengthException} if that's not the case. Currently, RouterOS supports words up to 0xFFFFFFF in length, so that's the only check performed.

Parameters
Name Type Description
$length int

The length to verify.

Documentation was generated by DocBlox 0.14.1.