diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..90b28d5 --- /dev/null +++ b/CREDITS @@ -0,0 +1 @@ +Vasil Rangelov [boen_robot] \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..95ac40b --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +RouterOS API client implementation. +This package allows you to read and write information from a RouterOS host using MikroTik's RouterOS API. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1cd3ea9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +See the project wiki for installation instructions and other documentation. \ No newline at end of file diff --git a/RELEASE-1.0.0b1 b/RELEASE-1.0.0b1 new file mode 100644 index 0000000..6ef641c --- /dev/null +++ b/RELEASE-1.0.0b1 @@ -0,0 +1 @@ +First PEAR2 release \ No newline at end of file diff --git a/catalog.xml b/catalog.xml new file mode 100644 index 0000000..8e0ae8b --- /dev/null +++ b/catalog.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/docs/docblox.xml b/docs/docblox.xml new file mode 100644 index 0000000..d3ade05 --- /dev/null +++ b/docs/docblox.xml @@ -0,0 +1,20 @@ + + + PEAR2_Net_RouterOS documentation + + PEAR2_Net_RouterOS + PEAR2_Net_RouterOS__DocBlox_Documentation + + php + + + + ../src/PEAR2/Net/RouterOS + + + PEAR2_Net_RouterOS__DocBlox_Documentation + + diff --git a/docs/docblox.xsd b/docs/docblox.xsd new file mode 100644 index 0000000..b349401 --- /dev/null +++ b/docs/docblox.xsd @@ -0,0 +1,188 @@ + + + + + Root element of docblox's configuration. + + + + + + Tthe title for this project, may contain HTML. + + + + + + + + + + The parser section contains all settings related to the conversion of your project’s source to the intermediate structure format of DocBlox (structure.xml). + + + + + + Optional element which defines the name of the default package. This is the name of the package when none is provided. + + + + + The target location where to store the structure.xml, also used as source location for the transformer. + + + + + Contains a listing of item’s. These items identify which keywords in comments are used to identify additional sets of information. An example of this is inline comments starting with the marker TODO or FIXME. + + + + + + + + + + Contains a list of extension’s which a file must have to be interpreted. If a file does not have the extension mentioned in this list then it is not parsed. Examples: php, php3 or phtml. + + + + + + + + + + + + + + The transformer section contains most settings related to the transformation of the intermediate structure format (structure.xml) to a human-readable set of documentation. The format of this set of documentation is determined by the template choice which is present in the transformations head section. + +
The transformer determines the location of the intermediate structure format (structure.xml) by retrieving the target element in the parser section.
+
+
+ + + + + The target location where to store the generated documentation files. + + + + + With this element you can link the documentation generated by DocBlox to the URL of a library based on the prefix of the class. This element may be used multiple times and each time has a prefix and uri element which specify which class to link where. The uri element supports 2 substitution variables: {CLASS} and {LOWERCASE_CLASS}. + +
Please note that if the class is part of a namespace that the backslashes are also copied; with exception of the ‘root’ (start of the class name).
+
+
+ + + + + + +
+
+
+
+ + + The logging section contains all settings related to the logging of information in DocBlox. + +
DocBlox does not ‘care’ whether the specified logging paths exist; if they do not then no log files are generated.
+
+
+ + + + + Determines the minimum level of information that is supplied. Any priority equal to or higher than the given is included in the log files and is output to the screen. All priorities lower than the given are not logged. + + + + + Contains all folders to where DocBlox may log. + + + + + + The path of the default logging file, the name may be augmented with a {DATE} variable to provide a timestamp and {APP_ROOT} to indicate the root of the DocBlox application. + + + + + Messages with level debug are not added to the default log but in a separate log file whose path you can declare here. As with the default log file you can augment the path with the {DATE} variable. + + + + + + + +
+ + + The transformations section controls the behaviour applied in transforming the intermediate structure format to the final human-readable output. + + + + + + The name or path of a template to use. This element may be used multiple times to combine several templates though usually you only supply one. + + + + + + + + It is also possible to execute additional transformations specifically for this project by defining your own transformations here. + + + + + + + + The files section allows you to specify where the source code for your project is and what files to ignore.It is allowed to use relative paths here; just remember that these are relative from the working directory where you execute DocBlox in. + + + + + + It is possible to specify specific files or a specific set of files using the element. As with the -f parameter it supports wildcards. + + + + + In addition you can also provide entire directory trees using the element. This also supports the use of wildcards. Please note that in contrary to the element that the element is recursive and will tell DocBlox to process all files contained in this folder and every subfolder. + + + + + In some cases you will have to ignore certain files in your project; examples of these can be third party libraries and/or tests. In this case you can use the ignore element and provide a pattern (not a path) to ignore. This if you provide *test* it will ignore any file or directory containing the text test in it. + + + + + +
+
+
+ + + + + + + + + + + + + +
\ No newline at end of file diff --git a/docs/doxygen.ini b/docs/doxygen.ini new file mode 100644 index 0000000..66fc2b0 --- /dev/null +++ b/docs/doxygen.ini @@ -0,0 +1,1789 @@ +# Doxyfile 1.7.5.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or sequence of words) that should +# identify the project. Note that if you do not use Doxywizard you need +# to put quotes around the project name if it contains spaces. + +PROJECT_NAME = PEAR2_Net_RouterOS + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = SVN: $WCREV$ + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer +# a quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "A MikroTik RouterOS client" + +# With the PROJECT_LOGO tag one can specify an logo or icon that is +# included in the documentation. The maximum height of the logo should not +# exceed 55 pixels and the maximum width should not exceed 200 pixels. +# Doxygen will copy the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = "PEAR2_Net_RouterOS__Doxygen_Documentation" + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = ../src/ + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful if your file system +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given extension. +# Doxygen has a built-in mapping, but you can override or extend it using this +# tag. The format is ext=language, where ext is a file extension, and language +# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, +# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make +# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C +# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions +# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also makes the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and +# unions are shown inside the group in which they are included (e.g. using +# @ingroup) instead of on a separate page (for HTML and Man pages) or +# section (for LaTeX and RTF). + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and +# unions with only public data fields will be shown inline in the documentation +# of the scope in which they are defined (i.e. file, namespace, or group +# documentation), provided this scope is documented. If set to NO (the default), +# structs, classes, and unions are shown on a separate page (for HTML and Man +# pages) or section (for LaTeX and RTF). + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penalty. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will roughly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols + +SYMBOL_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespaces are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = YES + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to +# do proper type resolution of all parameters of a function it will reject a +# match between the prototype and the implementation of a member function even +# if there is only one candidate or it is obvious which candidate to choose +# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen +# will still accept a match between prototype and implementation in such cases. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or macro consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and macros in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. The create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. +# You can optionally specify a file name after the option, if omitted +# DoxygenLayout.xml will be used as the name of the layout file. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files +# containing the references data. This must be a list of .bib files. The +# .bib extension is automatically appended if omitted. Using this command +# requires the bibtex tool to be installed. See also +# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style +# of the bibliography can be controlled using LATEX_BIB_STYLE. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_NO_PARAMDOC option can be enabled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ../src/PEAR2/Net/RouterOS + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh +# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py +# *.f90 *.f *.for *.vhd *.vhdl + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox \ + *.py \ + *.f90 \ + *.f \ + *.for \ + *.vhd \ + *.vhdl + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# Note that relative paths are relative to directory from which doxygen is run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty or if +# non of the patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) +# and it is also possible to disable source filtering for a specific pattern +# using *.ext= (so without naming a filter). This option only has effect when +# FILTER_SOURCE_FILES is enabled. + +FILTER_SOURCE_PATTERNS = + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. Note that when using a custom header you are responsible +# for the proper inclusion of any scripts and style sheets that doxygen +# needs, which is dependent on the configuration options used. +# It is adviced to generate a default header using "doxygen -w html +# header.html footer.html stylesheet.css YourConfigFile" and then modify +# that header. Note that the header is subject to change so you typically +# have to redo this when upgrading to a newer version of doxygen or when +# changing the value of configuration settings such as GENERATE_TREEVIEW! + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that +# the files will be copied as-is; there are no commands or markers available. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the stylesheet and background images +# according to this color. Hue is specified as an angle on a colorwheel, +# see http://en.wikipedia.org/wiki/Hue for more information. +# For instance the value 0 represents red, 60 is yellow, 120 is green, +# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. +# The allowed range is 0 to 359. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of +# the colors in the HTML output. For a value of 0 the output will use +# grayscales only. A value of 255 will produce the most vivid colors. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to +# the luminance component of the colors in the HTML output. Values below +# 100 gradually make the output lighter, whereas values above 100 make +# the output darker. The value divided by 100 is the actual gamma applied, +# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, +# and 100 does not change the gamma. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. + +HTML_TIMESTAMP = YES + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = YES + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated +# that can be used as input for Qt's qhelpgenerator to generate a +# Qt Compressed Help (.qch) of the generated HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to +# add. For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see +# +# Qt Help Project / Custom Filters. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's +# filter section matches. +# +# Qt Help Project / Filter Attributes. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values +# (range [0,1..20]) that doxygen will group on one line in the generated HTML +# documentation. Note that a value of 0 will completely suppress the enum +# values from appearing in the overview section. + +ENUM_VALUES_PER_LINE = 4 + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. + +GENERATE_TREEVIEW = YES + +# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, +# and Class Hierarchy pages using a tree view instead of an ordered list. + +USE_INLINE_TREES = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open +# links to external symbols imported via tag files in a separate window. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are +# not supported properly for IE 6.0, but are supported on all modern browsers. +# Note that when changing this option you need to delete any form_*.png files +# in the HTML output before the changes have effect. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax +# (see http://www.mathjax.org) which uses client side Javascript for the +# rendering instead of using prerendered bitmaps. Use this if you do not +# have LaTeX installed or if you want to formulas look prettier in the HTML +# output. When enabled you also need to install MathJax separately and +# configure the path to it using the MATHJAX_RELPATH option. + +USE_MATHJAX = NO + +# When MathJax is enabled you need to specify the location relative to the +# HTML output directory using the MATHJAX_RELPATH option. The destination +# directory should contain the MathJax.js script. For instance, if the mathjax +# directory is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the +# mathjax.org site, so you can quickly see the result without installing +# MathJax, but it is strongly recommended to install a local copy of MathJax +# before deployment. + +MATHJAX_RELPATH = http://www.mathjax.org/mathjax + +# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension +# names that should be enabled during MathJax rendering. + +MATHJAX_EXTENSIONS = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a PHP enabled web server instead of at the web client +# using Javascript. Doxygen will generate the search PHP script and index +# file to put on the web server. The advantage of the server +# based approach is that it scales better to large projects and allows +# full text search. The disadvantages are that it is more difficult to setup +# and does not have live searching capabilities. + +SERVER_BASED_SEARCH = NO + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for +# the generated latex document. The footer should contain everything after +# the last chapter. If it is left blank doxygen will generate a +# standard footer. Notice: only use this tag if you know what you are doing! + +LATEX_FOOTER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See +# http://en.wikipedia.org/wiki/BibTeX for more info. + +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# pointed to by INCLUDE_PATH will be searched when a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition that +# overrules the definition found in the source code. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all references to function-like macros +# that are alone on a line, have an all uppercase name, and do not end with a +# semicolon, because these will confuse the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option also works with HAVE_DOT disabled, but it is recommended to +# install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = NO + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is +# allowed to run in parallel. When set to 0 (the default) doxygen will +# base this on the number of processors available in the system. You can set it +# explicitly to a value larger than 0 to get control over the balance +# between CPU load and processing speed. + +DOT_NUM_THREADS = 0 + +# By default doxygen will use the Helvetica font for all dot files that +# doxygen generates. When you want a differently looking font you can specify +# the font name using DOT_FONTNAME. You need to make sure dot is able to find +# the font, which can be done by putting it in a standard location or by setting +# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the Helvetica font. +# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to +# set the path where dot can find it. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will generate a graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are svg, png, jpg, or gif. +# If left blank png will be used. If you choose svg you need to set +# HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible in IE 9+ (other browsers do not have this requirement). + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# Note that this requires a modern browser other than Internet Explorer. +# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you +# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible. Older versions of IE do not have SVG support. + +INTERACTIVE_SVG = NO + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the +# \mscfile command). + +MSCFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff --git a/docs/tutorials/PEAR2_Net_RouterOS/Client.cls b/docs/tutorials/PEAR2_Net_RouterOS/Client.cls new file mode 100644 index 0000000..7ba2b80 --- /dev/null +++ b/docs/tutorials/PEAR2_Net_RouterOS/Client.cls @@ -0,0 +1,78 @@ + + + + Approaches with Client + Description of the various approaches in using the Client class + + + Vasil Rangelov + + {@link mailto:boen.robot@gmail.com boen.robot@gmail.com} + + + + {@toc} + + Synchonious requests + +The easiest approach in using PEAR2_Net_RouterOS is to connect, send a request, get the responses, and use them if you need to, all at one time. This is reffered to as "Synchonious request". + + + Simple requests + +If the request you want to send is just a simple command with no arguments, the easiest way is to pass it right there at the {@link Client::sendSync()} method, like this: + + {@example sync-request-simple.php} + +You can also use the syntax from RouterOS's shell (spaces between words instead of "/"), but again - no arguments. Also, the command needs to be absolute (begin with "/"). Examples in the rest of this documentation will use the API syntax. + + + + Requests with arguments + +To add arguments to a command, you need to use the {@link Request::setArgument()} method before you send the request. You can reuse the same request object by clearing its arguments and/or setting new values appropriately, as in the following example. + + {@example sync-request-arguments.php} + + + + Asynchronous requests + +You may want to deal with the responses from commands later instead of right after you send them. +Or you might only need to deal with one of the responses, and yet you need to send several requests. Or you might want to use a command which returns responses continiously, and is therefore not suitable for {@link Client::sendSync()}. +Either way, {@link Client::sendAsync()} is the method you need. Depending on the way you want to deal with the responses, there are various other methods which you may use along with it. + + + Send and forget + +If you don't care about the responses, you can just do something like the following + + {@example send-and-forget.php} + +Note that, as in the example above, different asynchronious requests need to have a different "tag", regardless of whether you care about the responses or not. A "tag" in this context is a RouterOS API specific construct that allows clients like PEAR2_Net_RouterOS to keep track of responses coming from multiple requests, since they don't appear in the order of their execution. You can only reuse a tag once you get its final response. + + + + Loop and extract + +One way to get responses is to let PEAR2_Net_RouterOS process any new ones, and then extract those that interest you. You can start processing with the {@link Client::loop()} method. +If you've made requests that you know will eventually be finished, you can use {@link Client::loop()} without an argument to let processing stop only once all requests have returned their final response. Here's an example that continues from the previous one. + + {@example loop-and-extract.php} + + + Callback and loop + +Instead of extracting responses, you may instead assign responses for a request to a callback. Once you do that, starting the processing is all you need to do. + + {@example callback-and-loop.php} + + + Send and complete + +Processing of responses can also be started with {@link Client::completeRequest()}. The difference is that {@link Client::loop()} ends when a certain timeout is reached, or when all requests are finished, and {@link Client::completeRequest()} instead ends when the final response of a specified request has been processed, regardless of the time it takes. The return value is an array of all responses, or an empty array if the request was assigned to a callback. + + {@example send-and-complete.php} + + + \ No newline at end of file diff --git a/docs/tutorials/PEAR2_Net_RouterOS/PEAR2_Net_RouterOS.pkg b/docs/tutorials/PEAR2_Net_RouterOS/PEAR2_Net_RouterOS.pkg new file mode 100644 index 0000000..475599e --- /dev/null +++ b/docs/tutorials/PEAR2_Net_RouterOS/PEAR2_Net_RouterOS.pkg @@ -0,0 +1,135 @@ + + + + Getting started + First steps in using PEAR2_Net_RouterOS + + + Vasil Rangelov + + {@link mailto:boen.robot@gmail.com boen.robot@gmail.com} + + + + {@toc} + + Introduction + +RouterOS is the flag product of the company {@link http://mikrotik.com/ MikroTik} +and is a powerful router software. One of its many abilities is to allow control over it via an API. +This package provides a client for that API, in turn allowing you to use PHP to control RouterOS hosts. + + + + Requirements + + PHP 5.3.0 or later. + A host with RouterOS v3 or later. + Enabled API service on the RouterOS host. + + +There are no dependencies from extensions that are not bundled with PHP. +The only dependency is the PCRE (Pearl Compatible Regular Expressions) extension, which is bundled and enabled by default in PHP. + + +The API service is disabled by default. To enable it, you need to execute +/ip service set numbers="api" address="0.0.0.0/0" disabled="no" +at a RouterOS terminal. The "address" argument in the command above allows you to limit access to this service only to certain IP addresses. For security's sake, it's better that you limit connections only to the IP address with which PHP will access RouterOS. + + + + Installation + + Installation with the PEAR installer. + +If you don't already have the pear installer, see the +{@link http://pear.php.net/manual/en/installation.php installation instructions in the PEAR manual}. The version of the PEAR installer that is bundled with PHP 5.3.0 should be sufficient. + + +To use the PEAR installer, you must have the TGZ version of the file. +Installation is as easy as opening up a command prompt, going to the pear installer's folder and typing + pear install "%tgz%" +Replacing %tgz% with the location of the archive. + + + + Manual installation. + +Instead of using the PEAR installer, you can also just extract the files into any directory in your include_path. +To emulate the PEAR installer, you can simply extract the contents of the folder "src" in that folder. +Note that the examples in the rest of the documentation assume installation with the PEAR installer. + + + + + Usage. + +To use this in a PHP file, you could manally include every required class, but to save yourself some hassle, it's a better idea that you just include the file Autoload.php, like: + + +<?php +include_once 'PEAR2/Net/RouterOS/Autoload.php'; +//Use any Net_RouterOS class +?> + + +Net_RouterOS uses namespaces - a feature introduced in PHP 5.3 - for its organization. +Among other things, this means that instead of you having to write long class names, you can just declare at the top that you'll be using this namespace, and then just write shorter class names. The possible approaches are as follows: + + +Using a fully qualified class name + +<?php +include_once 'PEAR2/Net/RouterOS/Autoload.php'; +$client = new PEAR2\Net\RouterOS\Client('example.com', 'admin'); +// Use the client here +?> + + + +Declaring the \PEAR2\Net\RouterOS as your default namespace + +<?php +namespace PEAR2\Net\RouterOS; +include_once 'PEAR2/Net/RouterOS/Autoload.php'; +$client = new Client('example.com', 'admin'); +// Use the client here +?> + + + +Declaring the PEAR2\Net\RouterOS as an aliased namespace + +<?php +use PEAR2\Net\RouterOS as Ros; +include_once 'PEAR2/Net/RouterOS/Autoload.php'; +$client = new Ros\Client('example.com', 'admin'); +// Use the client here +?> + + + +Declaring an alias of each class you intend to use directly. + +<?php +use PEAR2\Net\RouterOS\Client as Ros; +include_once 'PEAR2/Net/RouterOS/Autoload.php'; +$client = new Ros('example.com', 'admin'); +// Use the client here +?> + + + + +Note that namespace declarations must appear before any includes. +They must in fact be the first thing in a PHP file. The rest of the examples in this documentation will be setting \PEAR2\Net\RouterOS as the default namespace. + + + + Further information. + +Net_RouterOS is flexible in the code patterns it allows you to use, but using the +{@link Client} class with {@link Client::sendSync()} is the reccomended approach for simple scenarios. See {@tutorial Client.cls the tutorial for the Client class} for description of this and other ways to use PEAR2_Net_RouterOS. + + + \ No newline at end of file diff --git a/docs/tutorials/PEAR2_Net_RouterOS/Query.cls b/docs/tutorials/PEAR2_Net_RouterOS/Query.cls new file mode 100644 index 0000000..385124e --- /dev/null +++ b/docs/tutorials/PEAR2_Net_RouterOS/Query.cls @@ -0,0 +1,69 @@ + + + + Using queries + A brief guide to using queries + + + Vasil Rangelov + + {@link mailto:boen.robot@gmail.com boen.robot@gmail.com} + + + + {@toc} + + Commands handling queries + +Queries are a RouterOS API specific construct that allows you to limit the results returned for a request. + + +Currently, the "print" command is the only one that handles queries, since version 3.21. PEAR2_Net_RouterOS doesn't check whether the command handles queries, so if future versions of RouterOS have other such commands, you can use queries with them right away. + + + + Setting a query + +To set a query for a request, you need to use the {@link Request::setQuery()} method. If later in the script you want to remove the query, you can pass NULL to it. The rest of the examples in this tutorial will assume a script similar to the following, where the $query variable is defined separately: + + +<?php +namespace PEAR2\Net\RouterOS; +include_once 'PEAR2/Net/RouterOS/autoload.php'; +$client = new Client('192.168.0.1', 'admin'); + +$request = new Request('/ip/arp/print'); + +//Define $query here + +$request->setQuery($query); +$responses = $client->sendSync($request); + +foreach($responses as $response) { + foreach($response->getAllArguments() as $name => $value) { + echo "{$name}: {$value}\n"; + } + echo "====\n"; +} +?> + + + + A simple query + +You can create a query by calling the static {@link Query::where()} method, along with the first criteria of the query. For example, if you wanted to limit results to the entry about 192.168.0.100, you can use a query like: + + $query = Query::where('address', '192.168.0.100'); + +Using the optional third parameter, you can specify exactly what do you want to do with the value. Possible values are the Query::ACTION_* constants. For example, if you wanted to get all addresses greather than 192.168.0.100, you can use: + + $query = Query::where('address', '192.168.0.100', Query::ACTION_GREATHER_THAN); + + + Chaining conditions + +The {@link Query} class uses a "fluent" interface, i.e. it always returns the query object itself, similarly to how {@link http://jquery.com jQuery} and {@link http://framework.zend.com/manual/en/zend.db.select.html Zend_Db_Select} do it. Thanks to that, you can chain conditions right when defining the $query variable (though you can also alter it later). For example, if you wanted to get all addresses greather than or equal to 192.168.0.100, you can do: + + $query = Query::where('address', '192.168.0.100', Query::ACTION_GREATHER_THAN)->orWhere('address', '192.168.0.100'); + + \ No newline at end of file diff --git a/examples/callback-and-loop.php b/examples/callback-and-loop.php new file mode 100644 index 0000000..f8ab5c3 --- /dev/null +++ b/examples/callback-and-loop.php @@ -0,0 +1,33 @@ +getType() === Response::TYPE_FINAL) { + echo "{$response->getTag()} is done.\n"; + } +} + +$addRequest = new Request('/ip/arp/add'); + +$addRequest->setArgument('address', '192.168.0.100'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:01'); +$addRequest->setTag('arp1'); +$client->sendAsync($addRequest, 'responseHandler'); + +$addRequest->setArgument('address', '192.168.0.101'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:02'); +$addRequest->setTag('arp2'); +$client->sendAsync($addRequest, 'responseHandler'); + +$client->loop(); +//Example output: +/* +arp1 is done. +arp2 is done. +*/ +?> diff --git a/examples/loop-and-extract.php b/examples/loop-and-extract.php new file mode 100644 index 0000000..0aaab77 --- /dev/null +++ b/examples/loop-and-extract.php @@ -0,0 +1,35 @@ +setArgument('address', '192.168.0.100'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:01'); +$addRequest->setTag('arp1'); +$client->sendAsync($addRequest); + +$addRequest->setArgument('address', '192.168.0.101'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:02'); +$addRequest->setTag('arp2'); +$client->sendAsync($addRequest); + +$client->loop(); + +$responses = $client->extractNewResponses(); +foreach ($responses as $response) { + if ($responses->getType() !== Response::TYPE_FINAL) { + echo "Error with {$response->getTag()}!\n"; + } else { + echo "OK with {$response->getTag()}!\n"; + } +} +//Example output: +/* +OK with arp1 +OK with arp2 + */ +?> diff --git a/examples/send-and-complete.php b/examples/send-and-complete.php new file mode 100644 index 0000000..2635f76 --- /dev/null +++ b/examples/send-and-complete.php @@ -0,0 +1,33 @@ +setArgument('address', '192.168.0.100'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:01'); +$addRequest->setTag('arp1'); +$client->sendAsync($addRequest); + +$addRequest->setArgument('address', '192.168.0.101'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:02'); +$addRequest->setTag('arp2'); +$client->sendAsync($addRequest); + +foreach ($client->completeRequest('arp1') as $response) { + if ($response->getType() === Response::TYPE_ERROR) { + echo "Error response for 'arp1'!\n"; + } +} + +foreach ($client->completeRequest('arp2') as $response) { + if ($response->getType() === Response::TYPE_ERROR) { + echo "Error response for 'arp2'!\n"; + } +} + +echo 'OK'; +?> diff --git a/examples/send-and-forget.php b/examples/send-and-forget.php new file mode 100644 index 0000000..33a59ff --- /dev/null +++ b/examples/send-and-forget.php @@ -0,0 +1,19 @@ +setArgument('address', '192.168.0.100'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:01'); +$addRequest->setTag('arp1'); +$client->sendAsync($addRequest); + +$addRequest->setArgument('address', '192.168.0.101'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:02'); +$addRequest->setTag('arp2'); +$client->sendAsync($addRequest); +?> diff --git a/examples/sync-request-arguments.php b/examples/sync-request-arguments.php new file mode 100644 index 0000000..975f620 --- /dev/null +++ b/examples/sync-request-arguments.php @@ -0,0 +1,23 @@ +setArgument('address', '192.168.0.100'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:01'); +if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) { + die("Error when creating ARP entry for '192.168.0.100'"); +} + +$addRequest->setArgument('address', '192.168.0.101'); +$addRequest->setArgument('mac-address', '00:00:00:00:00:02'); +if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) { + die("Error when creating ARP entry for '192.168.0.101'"); +} + +echo 'OK'; +?> diff --git a/examples/sync-request-simple.php b/examples/sync-request-simple.php new file mode 100644 index 0000000..f881b7e --- /dev/null +++ b/examples/sync-request-simple.php @@ -0,0 +1,22 @@ +sendSync(new Request('/ip/arp/print')); + +foreach ($responses as $response) { + if ($response->getType() === Response::TYPE_DATA) { + echo 'IP: ', $response->getArgument('address'), + ' MAC: ', $response->getArgument('mac-address'), + "\n"; + } +} +//Example output: +/* +IP: 192.168.0.100 MAC: 00:00:00:00:00:01 +IP: 192.168.0.101 MAC: 00:00:00:00:00:02 + */ +?> diff --git a/extrasetup.php b/extrasetup.php new file mode 100644 index 0000000..37b8010 --- /dev/null +++ b/extrasetup.php @@ -0,0 +1,12 @@ +files['docs/docblox.xml']); +unset($transmitterPackage->files['docs/doxygen.ini']); +unset($transmitterPackage->files['tests/configuration.xml']); +unset($transmitterPackage->files['tests/bootstrap.php']); +$extrafiles = array($transmitterPackage); \ No newline at end of file diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..4230df0 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,7 @@ +auxiliary.org-netbeans-modules-php-phpdoc.target= +auxiliary.org-netbeans-modules-php-phpdoc.title=Net_RouterOS +copy.src.files=false +copy.src.target= +remote.connection=no-config +remote.upload=ON_RUN +run.as=SCRIPT diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..546224f --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/nbproject/private/private.xml.0.nblh~ b/nbproject/private/private.xml.0.nblh~ new file mode 100644 index 0000000..546224f --- /dev/null +++ b/nbproject/private/private.xml.0.nblh~ @@ -0,0 +1,5 @@ + + + + + diff --git a/nbproject/private/retriever/catalog.xml b/nbproject/private/retriever/catalog.xml new file mode 100644 index 0000000..f14cc8c --- /dev/null +++ b/nbproject/private/retriever/catalog.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/nbproject/private/retriever/docbook.org/xml/5.0/xsd/docbook.xsd b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/docbook.xsd new file mode 100644 index 0000000..42b9b0e --- /dev/null +++ b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/docbook.xsd @@ -0,0 +1,17458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xlink.xsd b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xlink.xsd new file mode 100644 index 0000000..ff9a7c1 --- /dev/null +++ b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xlink.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xml.xsd b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xml.xsd new file mode 100644 index 0000000..c6e9c46 --- /dev/null +++ b/nbproject/private/retriever/docbook.org/xml/5.0/xsd/xml.xsd @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/nbproject/private/retriever/pear.php.net/dtd/package-2.0.xsd b/nbproject/private/retriever/pear.php.net/dtd/package-2.0.xsd new file mode 100644 index 0000000..76e900d --- /dev/null +++ b/nbproject/private/retriever/pear.php.net/dtd/package-2.0.xsd @@ -0,0 +1,652 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uri of the package that contains the source of this extension + + + + + + + + + + + + + + + + + + this is ignored if the release type is bundle + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for php script releases + + + + + + + + + + + for extension source releases + + + + + + + + + + + + + for compiled extension source releases + + + + + + + + + + + for bundling several releases together in one release + + + + + + + + + + + + + + + + + + + + + + + tells the installer not to install the default dependency group + + + + + absolute required dependencies + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all other optional dependency groups + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + simple optional dependencies + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + version string regex + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + name of the package that contains the source of this extension (can be the same if the source and binaries are in the same package) + + + + + + + + if a package can provide one or more compatible extensions (dblib/sybase/mssql for instance) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/private/retriever/pear.php.net/dtd/tasks-1.0.xsd b/nbproject/private/retriever/pear.php.net/dtd/tasks-1.0.xsd new file mode 100644 index 0000000..e641139 --- /dev/null +++ b/nbproject/private/retriever/pear.php.net/dtd/tasks-1.0.xsd @@ -0,0 +1,89 @@ + + + + + + + standard PEAR str_replace() in-file replacement + + + + + + + + + + + + + + + + + + standard PEAR post-installation script - must be used in a role="php" file + + + + + + + + + parameter condition name, passed to install script + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + standard PEAR unix line endings package-time replacement + + + + + standard PEAR windows line ending package-time replacement + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..6c49a04 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,15 @@ +ignore.path= +include.path=\ + ${php.global.include.path} +php.version=PHP_53 +phpunit.bootstrap= +phpunit.bootstrap.create.tests=false +phpunit.configuration=tests/configuration.xml +phpunit.run.test.files=false +phpunit.suite= +source.encoding=UTF-8 +src.dir=src +tags.asp=false +tags.short=false +test.src.dir=tests +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..a9dfc72 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + PEAR2_Net_RouterOS + + + diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..8aeea20 --- /dev/null +++ b/package.xml @@ -0,0 +1,292 @@ + + + PEAR2_Net_RouterOS + pear2.php.net + RouterOS API client implementation. + This package allows you to read and write information from a RouterOS host using MikroTik's RouterOS API. + + Vasil Rangelov + boen_robot + boen.robot@gmail.com + yes + + 2011-09-26 + + 1.0.0b1 + 1.0.0 + + + beta + beta + + LGPL License 2.1 + First PEAR2 compatible release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5.3.0 + + + 1.4.0 + + + PEAR2_Net_Transmitter + pear2.php.net + + + PCRE + + + + + iconv + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packagexmlsetup.php b/packagexmlsetup.php new file mode 100644 index 0000000..9ee14b1 --- /dev/null +++ b/packagexmlsetup.php @@ -0,0 +1,123 @@ + array( + array( + 'attribs' => array( + 'from' => '../src', + 'to' => 'php_dir', + 'type' => 'pear-config' + ) + ) + ) +); + +$srcFileTasks = array( + 'tasks:replace' => array( + array( + 'attribs' => array( + 'from' => '~~summary~~', + 'to' => 'summary', + 'type' => 'package-info' + ) + ), + array( + 'attribs' => array( + 'from' => '~~description~~', + 'to' => 'description', + 'type' => 'package-info' + ) + ), + array( + 'attribs' => array( + 'from' => 'SVN: $WCREV$', + 'to' => 'version', + 'type' => 'package-info' + ) + ) + ) +); + +$compatible->license = $package->license; + +$package->files['tests/bootstrap.php'] = array_merge_recursive( + $package->files['tests/bootstrap.php']->getArrayCopy(), $srcDirTask +); + +$package->files['docs/docblox.xml'] = array_merge_recursive( + $package->files['docs/docblox.xml']->getArrayCopy(), $srcDirTask +); + +$package->files['docs/doxygen.ini'] = array_merge_recursive( + $package->files['docs/doxygen.ini']->getArrayCopy(), $srcDirTask, + array( + 'tasks:replace' => array( + array( + 'attribs' => array( + 'from' => 'SVN: $WCREV$', + 'to' => 'version', + 'type' => 'package-info' + ) + ) + ) + ) +); + +$compatible->files[ + "test/{$package->channel}/{$package->name}/bootstrap.php" + ] = array_merge_recursive( + $compatible->files[ + "test/{$package->channel}/{$package->name}/bootstrap.php" + ]->getArrayCopy(), $srcDirTask +); + +$compatible->files["doc/{$package->channel}/{$package->name}/docblox.xml"] + = array_merge_recursive( + $compatible->files[ + "doc/{$package->channel}/{$package->name}/docblox.xml" + ]->getArrayCopy(), $srcDirTask +); + +$compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"] + = array_merge_recursive( + $compatible->files[ + "doc/{$package->channel}/{$package->name}/doxygen.ini" + ]->getArrayCopy(), $srcDirTask, + array( + 'tasks:replace' => array( + array( + 'attribs' => array( + 'from' => 'SVN: $WCREV$', + 'to' => 'version', + 'type' => 'package-info' + ) + ) + ) + ) +); + +$oldCwd = getcwd(); +chdir(__DIR__); +foreach ( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + 'src', + RecursiveDirectoryIterator::UNIX_PATHS + ), + RecursiveIteratorIterator::LEAVES_ONLY + ) as $path) { + $filename = $path->getPathname(); + + $package->files[$filename] = array_merge_recursive( + $package->files[$filename]->getArrayCopy(), $srcFileTasks + ); + + $compatibleFilename = str_replace('src/', 'php/', $filename); + $compatible->files[$compatibleFilename] = array_merge_recursive( + $compatible->files[$compatibleFilename]->getArrayCopy(), + $srcFileTasks + ); +} +chdir($oldCwd); + +?> diff --git a/src/PEAR2/Net/RouterOS/Autoload.php b/src/PEAR2/Net/RouterOS/Autoload.php new file mode 100644 index 0000000..df95e7c --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Autoload.php @@ -0,0 +1,47 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Loads a specified class. + * + * Loads a specified class from the namespace. + * + * @param string $class The classname (with namespace) to load. + * + * @return void + */ +function autoload($class) +{ + $namespace = __NAMESPACE__ . '\\'; + if (strpos($class, $namespace) === 0) { + $path = __DIR__ . DIRECTORY_SEPARATOR . + strtr( + substr($class, strlen($namespace)), '\\', DIRECTORY_SEPARATOR + ) . '.php'; + $file = realpath($path); + if (is_string($file) && strpos($file, __DIR__) === 0) { + include_once $file; + } + } +} + +spl_autoload_register(__NAMESPACE__ . '\autoload', true); \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Client.php b/src/PEAR2/Net/RouterOS/Client.php new file mode 100644 index 0000000..8622914 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Client.php @@ -0,0 +1,563 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * A RouterOS client. + * + * Provides functionality for easily communicating with a RouterOS host. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class Client +{ + /** + * Used in {@link isRequestActive()} to limit search only to requests + * that have a callback. + */ + const FILTER_CALLBACK = 1; + /** + * Used in {@link isRequestActive()} to limit search only to requests + * that use the buffer. + */ + const FILTER_BUFFER = 2; + /** + * Used in {@link isRequestActive()} to indicate no limit in search. + */ + const FILTER_ALL = 3; + + /** + * @var Communicator The communicator for this client. + */ + protected $com; + + /** + * @var int The number of currently pending requests. + */ + protected $pendingRequestsCount = 0; + + /** + * @var array An array of responses that have not yet been extracted or + * passed to a callback. Key is the tag of the request, and the value + * is an array of associated responses. + */ + protected $responseBuffer = array(); + + /** + * @var array An array of callbacks to be executed as responses come. + * Key is the tag of the request, and the value is the callback for it. + */ + protected $callbacks = array(); + + /** + * @var bool Whether to stream future responses. + */ + private $_streamResponses = false; + + /** + * Opens a new instance of a RouterOS API client. + * + * Opens a new instance of a RouterOS API client with the specified + * settings. + * + * @param string $host Hostname (IP or domain) of the RouterOS server. + * @param string $username The RouterOS username. + * @param string $password The RouterOS password. + * + * @param int $port The port on which the RouterOS server provides + * the API service. + * @param bool $persist Whether or not the connection should be a + * persistent one. + * @param float $timeout The timeout for the connection. + * @param resource $context A context for the socket. + * + * @see sendSync() + * @see sendAsync() + */ + public function __construct($host, $username, $password = '', $port = 8728, + $persist = false, $timeout = null, $context = null + ) { + $this->com = new Communicator( + $host, $port, $persist, $timeout, $username, $context + ); + //Login the user if necessary + if ($this->com->getTransmitter()->isFresh()) { + if (!self::login($this->com, $username, $password)) { + $this->com->close(); + throw new DataFlowException( + 'Invalid username or password supplied.', 100 + ); + } + } + } + + /** + * Login to a RouterOS connection. + * + * @param Communicator $com The communicator to attempt to login to. + * @param string $username The RouterOS username. + * @param string $password The RouterOS password. + * + * @return bool TRUE on success, FALSE on failure. + */ + public static function login(Communicator $com, $username, $password = '') + { + try { + $request = new Request('/login'); + $request->send($com); + $response = new Response($com); + $request->setArgument('name', $username); + $request->setArgument( + 'response', '00' . md5( + chr(0) . $password + . pack('H*', $response->getArgument('ret')) + ) + ); + $request->send($com); + $response = new Response($com); + return $response->getType() === Response::TYPE_FINAL + && null === $response->getArgument('ret'); + } catch (\Exception $e) { + throw ($e instanceof NotSupportedException + || $e instanceof UnexpectedValueException + || !$com->getTransmitter()->isDataAwaiting()) ? new SocketException( + 'This is not a compatible RouterOS service', 101, $e + ) : $e; + } + } + + /** + * Sets the charset(s) for this connection. + * + * Sets the charset(s) for this connection. The specified charset(s) will be + * used for all future requests and responses. When sending, + * {@link Communicator::CHARSET_LOCAL} is converted to + * {@link Communicator::HARSET_REMOTE}, and when receiving, + * {@link Communicator::CHARSET_REMOTE} is converted to + * {@link Communicator::CHARSET_LOCAL}. Setting NULL to either charset will + * disable charset convertion, and data will be both sent and received "as + * is". + * + * @param mixed $charset The charset to set. If $charsetType is + * {@link Communicator::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. + * @param int $charsetType Which charset to set. Valid values are the + * Communicator::CHARSET_* constants. Any other value is treated as + * {@link Communicator::CHARSET_ALL}. + * + * @return string|array The old charset. If $charsetType is + * {@link Communicator::CHARSET_ALL}, the old values will be returned as an + * array with the types as keys, and charsets as values. + * @see Communicator::setDefaultCharset() + */ + public function setCharset( + $charset, $charsetType = Communicator::CHARSET_ALL + ) { + return $this->com->setCharset($charset, $charsetType); + } + + /** + * Gets the charset(s) for this connection. + * + * @param int $charsetType Which charset to get. Valid values are the + * Communicator::CHARSET_* constants. Any other value is treated as + * {@link Communicator::CHARSET_ALL}. + * + * @return string|array The current charset. If $charsetType is + * {@link Communicator::CHARSET_ALL}, the current values will be returned as + * an array with the types as keys, and charsets as values. + * @see setCharset() + */ + public function getCharset($charsetType) + { + return $this->com->getCharset($charsetType); + } + + /** + * Sends a request and waits for responses. + * + * @param Request $request The request to send. + * @param callback $callback Optional. A function that is to be executed + * when new responses for this request are available. The callback takes two + * parameters. The {@link Response} object as the first, and the + * {@link Client} object as the second one. If the function returns TRUE, + * the request is canceled. Note that the callback may be executed one last + * time after that with a response that notifies about the canceling. + * + * @return Client The client object. + * @see completeRequest() + * @see loop() + * @see cancelRequest() + */ + public function sendAsync(Request $request, $callback = null) + { + //Error checking + $tag = $request->getTag(); + if (null === $tag) { + throw new DataFlowException( + 'Asynchonous commands must have a tag.', 102 + ); + } + if ($this->isRequestActive($tag)) { + throw new DataFlowException( + 'There must not be multiple active requests sharing a tag.', 103 + ); + } + + $this->send($request); + + if (null === $callback) { + //Register the request at the buffer + $this->responseBuffer[$tag] = array(); + } else { + //Prepare the callback + $this->callbacks[$tag] = $callback; + } + return $this; + } + + /** + * Checks if a request is active. + * + * Checks if a request is active. A request is considered active if it's a + * pending request and/or has responses that are not yet extracted. + * + * @param string $tag The tag of the request to look for. + * @param int $filter One of the FILTER_* consntants. Limits the search + * to the specified places. + * + * @return bool TRUE if the request is active, FALSE otherwise. + * @see getPendingRequestsCount() + * @see completeRequest() + */ + public function isRequestActive($tag, $filter = self::FILTER_ALL) + { + $result = 0; + if (self::FILTER_CALLBACK === ($filter & self::FILTER_CALLBACK)) { + $result |= (int) array_key_exists($tag, $this->callbacks); + } + if (self::FILTER_BUFFER === ($filter & self::FILTER_BUFFER)) { + $result |= (int) array_key_exists($tag, $this->responseBuffer); + } + return 0 !== $result; + } + + /** + * Sends a request and gets the full response. + * + * @param Request $request The request to send. + * + * @return ResponseCollection The received responses as a collection. + * @see sendAsync() + * @see close() + */ + public function sendSync(Request $request) + { + $this->send($request); + return $this->completeRequest($request->getTag()); + } + + /** + * Completes a specified request. + * + * Starts an event loop for the RouterOS callbacks and finishes when a + * specified request is completed. + * + * @param string $tag The tag of the request to complete. Setting NULL + * completes all requests. + * + * @return ResponseCollection A collection of {@link Response} objects that + * haven't been passed to a callback function or previously extracted with + * {@link extractNewResponses()}. Returns an empty collection when $tag is + * set to NULL (responses can still be extracted). + */ + public function completeRequest($tag = null) + { + $isTagNull = null === $tag; + $result = $isTagNull ? array() + : $this->extractNewResponses($tag)->toArray(); + while ((!$isTagNull && $this->isRequestActive($tag)) + || ($isTagNull && 0 !== $this->getPendingRequestsCount()) + ) { + $newReply = $this->dispatchNextResponse(); + if ($newReply->getTag() === $tag) { + if ($isTagNull) { + $result[] = $newReply; + } + if ($newReply->getType() === Response::TYPE_FINAL) { + if (!$isTagNull) { + $result = array_merge( + $result, + $this->extractNewResponses($tag)->toArray() + ); + } + break; + } + } + } + return new ResponseCollection($result); + } + + /** + * Extracts responses for a request. + * + * Gets all new responses for a request that haven't been passed to a + * callback and clears the buffer from them. + * + * @param string $tag The tag of the request to extract new responses for. + * Specifying NULL with extract new responses for all requests. + * + * @return ResponseCollection A collection of {@link Response} objects for + * the specified request. + * @see loop() + */ + public function extractNewResponses($tag = null) + { + if (null === $tag) { + $result = array(); + foreach (array_keys($this->responseBuffer) as $tag) { + $result = array_merge( + $result, $this->extractNewResponses($tag)->toArray() + ); + } + return new ResponseCollection($result); + } elseif ($this->isRequestActive($tag, self::FILTER_CALLBACK)) { + return new ResponseCollection(array()); + } elseif ($this->isRequestActive($tag, self::FILTER_BUFFER)) { + $result = $this->responseBuffer[$tag]; + if (!empty($result)) { + if ($result[count($result) - 1]->getType() + === Response::TYPE_FINAL + ) { + unset($this->responseBuffer[$tag]); + } else { + $this->responseBuffer[$tag] = array(); + } + } + return new ResponseCollection($result); + } else { + throw new DataFlowException( + 'No such request, or the request has already finished.', 104 + ); + } + } + + /** + * Starts an event loop for the RouterOS callbacks. + * + * Starts an event loop for the RouterOS callbacks and finishes when there + * are no more pending requests or when a specified timeout has passed + * (whichever comes first). + * + * @param float $timeout Timeout for the loop. If 0, there is no time limit. + * + * @return bool TRUE when there are any more pending requests, FALSE + * otherwise. + * @see extractNewResponses() + * @see getPendingRequestsCount() + */ + public function loop($timeout = 0) + { + if ($this->getPendingRequestsCount() !== 0) { + $start = microtime(true); + do { + $this->dispatchNextResponse(); + } while ( + ((microtime(true) - $start) <= $timeout) + || (0 === $timeout && $this->getPendingRequestsCount() !== 0) + ); + } + return $this->getPendingRequestsCount() !== 0; + } + + /** + * Gets the number of pending requests. + * + * @return int The number of pending requests. + * @see isRequestActive() + */ + public function getPendingRequestsCount() + { + return $this->pendingRequestsCount; + } + + /** + * Cancels a request. + * + * Cancels an active request. Using this function in favor of a plain call + * to the "/cancel" command is highly reccomended, as it also updates the + * counter of pending requests properly. Note that canceling a request also + * removes any responses for it that were not previously extracted with + * {@link extractNewResponses()}. + * + * @param string $tag Tag of the request to cancel. Setting NULL will cancel + * all requests. + * + * @return Client The client object. + * @see sendAsync() + * @see close() + */ + public function cancelRequest($tag = null) + { + $cancelRequest = new Request('/cancel'); + $tagIsNotNull = !(null === $tag); + if ($tagIsNotNull) { + if ($this->isRequestActive($tag)) { + $cancelRequest->setArgument('tag', $tag); + } else { + throw new DataFlowException( + 'No such request. Canceling aborted.', 105 + ); + } + } + $this->sendSync($cancelRequest); + + if ($tagIsNotNull) { + if ($this->isRequestActive($tag, self::FILTER_BUFFER)) { + unset($this->responseBuffer[$tag]); + } elseif ($this->isRequestActive($tag, self::FILTER_CALLBACK)) { + unset($this->callbacks[$tag]); + } + $this->pendingRequestsCount--; + } else { + $this->responseBuffer = array(); + $this->callbacks = array(); + $this->pendingRequestsCount = 0; + } + return $this; + } + + /** + * Sets response streaming setting. + * + * Sets whether future responses are streamed. If responses are streamed, + * the argument values are returned as streams instead of strings. This is + * particularly useful if you expect a response that may contain one or more + * very large words. + * + * @param bool $streamResponses Whether to stream future responses. + * + * @return bool The previous value of the setting. + * @see getStreamResponses() + */ + public function setStreamResponses($streamResponses) + { + $oldStreamResponses = $this->_streamResponses; + $this->_streamResponses = (bool) $streamResponses; + return $oldStreamResponses; + } + + /** + * Gets response streaming setting. + * + * Gets whether future responses are streamed. + * + * @return bool The value of the setting. + * @see setStreamResponses() + */ + public function getStreamResponses() + { + return $this->_streamResponses; + } + + /** + * Closes the opened connection, even if it is a persistent one. + * + * Closes the opened connection, even if it is a persistent one. Note that + * {@link extractNewResponses()} can still be used to extract responses + * collected prior to the closing. + * + * @return bool TRUE on success, FALSE on failure. + */ + public function close() + { + $result = false; + try { + $response = $this->sendSync(new Request('/quit')); + $result = $this->com->close() + && $response->getType() === Response::TYPE_FATAL; + } catch (SocketException $e) { + $result = $e->getCode() === 205; + } + $this->callbacks = array(); + $this->pendingRequestsCount = 0; + return $result; + } + + /** + * Sends a request to RouterOS. + * + * @param Request $request The request to send. + * + * @return Client The client object. + * @see sendSync() + * @see sendAsync() + */ + protected function send(Request $request) + { + $request->send($this->com); + $this->pendingRequestsCount++; + return $this; + } + + /** + * Dispatches the next response in queue. + * + * Dispatches the next response in queue, i.e. it executes the associated + * callback if there is one, or places the response in the response buffer. + * + * @return Response The dispatched response. + */ + protected function dispatchNextResponse() + { + $response = new Response($this->com, $this->_streamResponses); + if ($response->getType() === Response::TYPE_FATAL) { + $this->pendingRequestsCount = 0; + $this->com->close(); + return $response; + } + + $tag = $response->getTag(); + $isLastForRequest = $response->getType() === Response::TYPE_FINAL; + if ($isLastForRequest) { + $this->pendingRequestsCount--; + } + + if (null !== $tag) { + if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) { + if ($this->callbacks[$tag]($response, $this)) { + $this->cancelRequest($tag); + } elseif ($isLastForRequest) { + unset($this->callbacks[$tag]); + } + } else { + $this->responseBuffer[$tag][] = $response; + } + } + return $response; + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Communicator.php b/src/PEAR2/Net/RouterOS/Communicator.php new file mode 100644 index 0000000..16f93c9 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Communicator.php @@ -0,0 +1,489 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Using transmitters. + */ +use PEAR2\Net\Transmitter as T; + +/** + * 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. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + * @see Client + */ +class Communicator +{ + /** + * Used when getting/setting all (default) charsets. + */ + const CHARSET_ALL = -1; + + /** + * 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. + */ + const CHARSET_REMOTE = 0; + + /** + * 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. + */ + const CHARSET_LOCAL = 1; + + /** + * @var array An array with the default charset types as keys, and the + * default charsets as values. + */ + protected static $defaultCharsets = array( + self::CHARSET_REMOTE => null, + self::CHARSET_LOCAL => null + ); + + /** + * @var array An array with the current charset types as keys, and the + * current charsets as values. + */ + protected $charsets = array(); + + /** + * @var SocketClientTransmitter The transmitter for the connection. + */ + protected $trans; + + /** + * Creates a new connection with the specified options. + * + * @param string $host Hostname (IP or domain) of the RouterOS server. + * @param int $port The port on which the RouterOS server provides + * the API service. + * @param bool $persist Whether or not the connection should be a + * persistent one. + * @param float $timeout The timeout for the connection. + * @param string $key A string that uniquely identifies the + * connection. + * @param resource $context A context for the socket. + * + * @see sendWord() + */ + public function __construct($host, $port = 8728, $persist = false, + $timeout = null, $key = '', $context = null + ) { + $this->trans = new T\SocketClientTransmitter( + $host, $port, $persist, $timeout, $key, $context + ); + $this->setCharset( + self::getDefaultCharset(self::CHARSET_ALL), self::CHARSET_ALL + ); + } + + /** + * Uses iconv to convert a stream from one charset to another. + * + * @param string $in_charset The charset of the stream. + * @param string $out_charset The desired resulting charset. + * @param resource $stream The stream to convert. + * + * @return 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. + */ + public static function iconvStream($in_charset, $out_charset, $stream) + { + $bytes = 0; + $result = fopen('php://temp', 'r+b'); + $iconvFilter = stream_filter_append( + $result, 'convert.iconv.' . $in_charset . '.' . $out_charset, + STREAM_FILTER_WRITE + ); + + flock($stream, LOCK_SH); + while (!feof($stream)) { + $bytes += stream_copy_to_stream($stream, $result, 0xFFFFF); + } + fseek($stream, -$bytes, SEEK_CUR); + flock($stream, LOCK_UN); + + stream_filter_remove($iconvFilter); + rewind($result); + return $result; + } + + /** + * Sets the default charset(s) for new connections. + * + * @param mixed $charset 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. + * @param int $charsetType Which charset to set. Valid values are the + * CHARSET_* constants. Any other value is treated as + * {@link CHARSET_ALL}. + * + * @return 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. + * @see setCharset() + */ + public static function setDefaultCharset( + $charset, $charsetType = self::CHARSET_ALL + ) { + if (array_key_exists($charsetType, self::$defaultCharsets)) { + $oldCharset = self::$defaultCharsets[$charsetType]; + self::$defaultCharsets[$charsetType] = $charset; + return $oldCharset; + } else { + $oldCharsets = self::$defaultCharsets; + self::$defaultCharsets = is_array($charset) ? $charset : array_fill( + 0, count(self::$defaultCharsets), $charset + ); + return $oldCharsets; + } + } + + /** + * Gets the default charset(s). + * + * @param int $charsetType Which charset to get. Valid values are the + * CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. + * + * @return 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. + * @see setDefaultCharset() + */ + public static function getDefaultCharset($charsetType) + { + return array_key_exists($charsetType, self::$defaultCharsets) + ? self::$defaultCharsets[$charsetType] : self::$defaultCharsets; + } + + /** + * 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". + * + * @param mixed $charset 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. + * @param int $charsetType Which charset to set. Valid values are the + * Communicator::CHARSET_* constants. Any other value is treated as + * {@link CHARSET_ALL}. + * + * @return 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. + * @see setDefaultCharset() + */ + public function setCharset($charset, $charsetType = self::CHARSET_ALL) + { + if (array_key_exists($charsetType, $this->charsets)) { + $oldCharset = $this->charsets[$charsetType]; + $this->charsets[$charsetType] = $charset; + return $oldCharset; + } else { + $oldCharsets = $this->charsets; + $this->charsets = is_array($charset) ? $charset : array_fill( + 0, count($this->charsets), $charset + ); + return $oldCharsets; + } + } + + /** + * Gets the charset(s) for this connection. + * + * @param int $charsetType Which charset to get. Valid values are the + * CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. + * + * @return 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. + * @see getDefaultCharset() + * @see setCharset() + */ + public function getCharset($charsetType) + { + return array_key_exists($charsetType, $this->charsets) + ? $this->charsets[$charsetType] : $this->charsets; + } + + /** + * Gets the transmitter for this connection. + * + * @return PEAR2\Net\Transmitter\SocketClientTransmitter The transmitter for + * this connection. + */ + public function getTransmitter() + { + return $this->trans; + } + + /** + * Sends a word. + * + * Sends a word and automatically encodes its length when doing so. + * + * @param string $word The word to send. + * + * @return int The number of bytes sent. + * @see sendWordFromStream() + * @see getNextWord() + */ + public function sendWord($word) + { + if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE)) + && null !== ($localCharset = $this->getCharset(self::CHARSET_LOCAL)) + ) { + $word = iconv( + $localCharset, + $remoteCharset . '//IGNORE//TRANSLIT', + $word + ); + } + $length = strlen($word); + static::verifyLengthSupport($length); + return $this->trans->send(self::encodeLength($length) . $word); + } + + /** + * 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. + * + * @param string $prefix A string to prepend before the stream contents. + * @param resource $stream The stream to send. + * + * @return int The number of bytes sent. + * @see sendWord() + */ + public function sendWordFromStream($prefix, $stream) + { + if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE)) + && null !== ($localCharset = $this->getCharset(self::CHARSET_LOCAL)) + ) { + $prefix = iconv( + $localCharset, + $remoteCharset . '//IGNORE//TRANSLIT', + $prefix + ); + $stream = self::iconvStream( + $localCharset, + $remoteCharset . '//IGNORE//TRANSLIT', + $stream + ); + } + + flock($stream, LOCK_SH); + + $streamPosition = (double) sprintf('%u', ftell($stream)); + fseek($stream, 0, SEEK_END); + $streamLength = ((double) sprintf('%u', ftell($stream))) + - $streamPosition; + fseek($stream, $streamPosition, SEEK_SET); + $totalLength = strlen($prefix) + $streamLength; + static::verifyLengthSupport($totalLength); + + $bytes = $this->trans->send(self::encodeLength($totalLength) . $prefix); + $bytes += $this->trans->sendStream($stream); + + flock($stream, LOCK_UN); + return $bytes; + } + + /** + * 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. + * + * @param int $length The length to verify. + * + * @return void + */ + protected static function verifyLengthSupport($length) + { + if ($length > 0xFFFFFFF) { + throw new LengthException( + 'Words with length above 0xFFFFFFF are not supported.', 10, + null, $length + ); + } + } + + /** + * Encodes the length as requred by the RouterOS API. + * + * @param int $length The length to encode + * + * @return string The encoded length + */ + public static function encodeLength($length) + { + if ($length < 0) { + throw new LengthException( + 'Length must not be negative.', 11, null, $length + ); + } elseif ($length < 0x80) { + return chr($length); + } elseif ($length < 0x4000) { + return pack('n', $length |= 0x8000); + } elseif ($length < 0x200000) { + $length |= 0xC00000; + return pack('n', $length >> 8) . chr($length & 0xFF); + } elseif ($length < 0x10000000) { + return pack('N', $length |= 0xE0000000); + } elseif ($length <= 0xFFFFFFFF) { + return chr(0xF0) . pack('N', $length); + } elseif ($length <= 0x7FFFFFFFF) { + $length = 'f' . base_convert($length, 10, 16); + return chr(hexdec(substr($length, 0, 2))) . + pack('N', hexdec(substr($length, 2))); + } + throw new LengthException( + 'Length must not be above 0x7FFFFFFFF.', 12, null, $length + ); + } + + /** + * Get the next word in queue as a string. + * + * Get the next word in queue as a string, after automatically decoding its + * length. + * + * @return string The word. + * @see close() + */ + public function getNextWord() + { + $word = $this->trans->receive(self::decodeLength($this->trans), 'word'); + if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE)) + && null !== ($localCharset = $this->getCharset(self::CHARSET_LOCAL)) + ) { + $word = iconv( + $remoteCharset, + $localCharset . '//IGNORE//TRANSLIT', + $word + ); + } + return $word; + } + + /** + * Get the next word in queue as a stream. + * + * Get the next word in queue as a stream, after automatically decoding its + * length. + * + * @return resource The word, as a stream. + * @see close() + */ + public function getNextWordAsStream() + { + $filters = array(); + if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE)) + && null !== ($localCharset = $this->getCharset(self::CHARSET_LOCAL)) + ) { + $filters[ + 'convert.iconv.' . + $remoteCharset . '.' . $localCharset . '//IGNORE//TRANSLIT' + ] = array(); + } + $stream = $this->trans->receiveStream( + self::decodeLength($this->trans), $filters, 'stream word' + ); + return $stream; + } + + /** + * Decodes the lenght of the incoming message. + * + * Decodes the lenght of the incoming message, as specified by the RouterOS + * API. + * + * @param PEAR2\Net\Transmitter\StreamTransmitter $trans The transmitter + * from which to decode the length of the incoming message. + * + * @return int The decoded length + */ + public static function decodeLength(T\StreamTransmitter $trans) + { + $byte = ord($trans->receive(1, 'initial length byte')); + if ($byte & 0x80) { + if (($byte & 0xC0) === 0x80) { + return (($byte & 077) << 8 ) + ord($trans->receive(1)); + } elseif (($byte & 0xE0) === 0xC0) { + $u = unpack('n~', $trans->receive(2)); + return (($byte & 037) << 16 ) + $u['~']; + } elseif (($byte & 0xF0) === 0xE0) { + $u = unpack('n~/C~~', $trans->receive(3)); + return (($byte & 017) << 24 ) + ($u['~'] << 8) + $u['~~']; + } elseif (($byte & 0xF8) === 0xF0) { + $u = unpack('N~', $trans->receive(4)); + return (($byte & 007) * 0x100000000/* '<< 32' or '2^32' */) + + (double) sprintf('%u', $u['~']); + } + throw new NotSupportedException( + 'Unknown control byte encountered.', 13, null, $byte + ); + } else { + return $byte; + } + } + + /** + * Closes the opened connection, even if it is a persistent one. + * + * @return bool TRUE on success, FALSE on failure. + */ + public function close() + { + return $this->trans->close(); + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/DataFlowException.php b/src/PEAR2/Net/RouterOS/DataFlowException.php new file mode 100644 index 0000000..e1637bc --- /dev/null +++ b/src/PEAR2/Net/RouterOS/DataFlowException.php @@ -0,0 +1,35 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when the request/response cycle goes an unexpected way. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class DataFlowException extends \RuntimeException implements Exception +{ + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Exception.php b/src/PEAR2/Net/RouterOS/Exception.php new file mode 100644 index 0000000..98723c8 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Exception.php @@ -0,0 +1,35 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Generic exception class of this package. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +interface Exception +{ + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/InvalidArgumentException.php b/src/PEAR2/Net/RouterOS/InvalidArgumentException.php new file mode 100644 index 0000000..fa56e28 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/InvalidArgumentException.php @@ -0,0 +1,36 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when there's something wrong with message parts. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class InvalidArgumentException extends \InvalidArgumentException + implements Exception +{ + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/LengthException.php b/src/PEAR2/Net/RouterOS/LengthException.php new file mode 100644 index 0000000..7c35cb2 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/LengthException.php @@ -0,0 +1,81 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when there is a problem with a word's length. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class LengthException extends \LengthException implements Exception +{ + + /** + * + * @var mixed The unsuppported value. + */ + private $_length = null; + + /** + * Creates a new LengthException. + * + * @param string $message The Exception message to throw. + * @param int $code The Exception code. + * @param Exception $previous The previous exception used for the exception + * chaining. + * @param number $value The length. + */ + public function __construct($message, $code = 0, $previous = null, + $value = null + ) { + parent::__construct($message, $code, $previous); + $this->_length = $value; + } + + /** + * Gets the length. + * + * @return number The length. + */ + public function getLength() + { + return $this->_length; + } + + // @codeCoverageIgnoreStart + // String representation is not reliable in testing + + /** + * Returns a string representation of the exception. + * + * @return string The exception as a string. + */ + public function __toString() + { + return parent::__toString() . "\nValue:{$this->_length}"; + } + + // @codeCoverageIgnoreEnd +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Message.php b/src/PEAR2/Net/RouterOS/Message.php new file mode 100644 index 0000000..0a45701 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Message.php @@ -0,0 +1,184 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Using transmitters. + */ +use PEAR2\Net\Transmitter as T; + +/** + * Represents a RouterOS message. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +abstract class Message +{ + + /** + * @var array An array with message arguments. Keys are the names of the + * arguments, array values are values for the corresponding argument. + */ + protected $arguments = array(); + + /** + * @var string An optional tag to associate the message with. + */ + private $_tag = null; + + /** + * Sanitizes a name of an argument (message or query one). + * + * @param mixed $name The name to sanitize. + * + * @return string The sanitized name. + */ + public static function sanitizeArgumentName($name) + { + $name = (string) $name; + if ((empty($name) && $name !== '0') + || !preg_match('/[^=\s]/s', $name) + ) { + throw new InvalidArgumentException( + 'Invalid name of argument supplied.', 200 + ); + } + return $name; + } + + /** + * Sanitizes a value of an argument (message or query one). + * + * @param mixed $value The value to sanitize. + * + * @return string The sanitized value. + */ + public static function sanitizeArgumentValue($value) + { + if (T\StreamTransmitter::isStream($value)) { + $meta = stream_get_meta_data($value); + if ($meta['seekable']) { + return $value; + } + throw new InvalidArgumentException( + 'The stream must be seekable.', 201 + ); + } else { + return (string) $value; + } + } + + /** + * Gets the tag that the message is associated with. + * + * @return string The current tag or NULL if there isn't a tag. + * @see setTag() + */ + public function getTag() + { + return $this->_tag; + } + + /** + * Sets the tag to associate the request with. + * + * Sets the tag to associate the message with. Setting NULL erases the + * currently set tag. + * + * @param string $tag The tag to set. + * + * @return Message The message object. + * @see getTag() + */ + protected function setTag($tag) + { + $this->_tag = (null === $tag) ? null : (string) $tag; + return $this; + } + + /** + * Gets the value of an argument. + * + * @param string $name The name of the argument. + * + * @return string|resource The value of the specified argument. Returns NULL + * if such an argument is not set. + * @see setArgument() + */ + public function getArgument($name) + { + $name = self::sanitizeArgumentName($name); + if (array_key_exists($name, $this->arguments)) { + return $this->arguments[$name]; + } + return null; + } + + /** + * Gets all arguments in an array. + * + * @return array An array with the keys as argument names, and the array + * values as argument values. + * @see getArgument() + * @see setArgument() + */ + public function getAllArguments() + { + return $this->arguments; + } + + /** + * Sets an argument for the message. + * + * @param string $name Name of the argument. + * @param string $value Value of the argument. Setting the value to NULL + * removes an argument of this name. + * + * @return Message The message object. + * @see getArgument() + */ + protected function setArgument($name, $value = null) + { + if (null === $value) { + unset($this->arguments[self::sanitizeArgumentName($name)]); + } else { + $this->arguments[self::sanitizeArgumentName($name)] + = self::sanitizeArgumentValue($value); + } + return $this; + } + + /** + * Removes all arguments from the message. + * + * @return Message The message object. + */ + protected function removeAllArguments() + { + $this->arguments = array(); + return $this; + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/NotSupportedException.php b/src/PEAR2/Net/RouterOS/NotSupportedException.php new file mode 100644 index 0000000..f663b1d --- /dev/null +++ b/src/PEAR2/Net/RouterOS/NotSupportedException.php @@ -0,0 +1,82 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when encountering something not supported by RouterOS or + * this package. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class NotSupportedException extends \Exception implements Exception +{ + + /** + * + * @var mixed The unsuppported value. + */ + private $_value = null; + + /** + * Creates a new NotSupportedException. + * + * @param string $message The Exception message to throw. + * @param int $code The Exception code. + * @param Exception $previous The previous exception used for the exception + * chaining. + * @param mixed $value The unsupported value. + */ + public function __construct($message, $code = 0, $previous = null, + $value = null + ) { + parent::__construct($message, $code, $previous); + $this->_value = $value; + } + + /** + * Gets the unsupported value. + * + * @return mixed The unsupported value. + */ + public function getValue() + { + return $this->_value; + } + + // @codeCoverageIgnoreStart + // String representation is not reliable in testing + + /** + * Returns a string representation of the exception. + * + * @return string The exception as a string. + */ + public function __toString() + { + return parent::__toString() . "\nValue:{$this->_value}"; + } + + // @codeCoverageIgnoreEnd +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Query.php b/src/PEAR2/Net/RouterOS/Query.php new file mode 100644 index 0000000..de8a170 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Query.php @@ -0,0 +1,216 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Represents a query for RouterOS requests. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class Query +{ + + /** + * Checks if the property exists. + */ + const ACTION_EXIST = ''; + + /** + * Checks if the property does not exist. + */ + const ACTION_NOT_EXIST = '-'; + + /** + * Checks if the property equals a certain value. + */ + const ACTION_EQUALS = '='; + + /** + * Checks if the property is less than a certain value. + */ + const ACTION_LESS_THAN = '<'; + + /** + * Checks if the property is greather than a certain value. + */ + const ACTION_GREATHER_THAN = '>'; + + /** + * @var array An array of the words forming the query. Each value is an + * array with the first member being the predicate (action and name), and + * the second member being the value for the predicate. + */ + protected $words = array(); + + /** + * This class is not to be instantiated normally, but by static methods + * instead. Use {@link where()} to create an instance of it. + */ + private function __construct() + { + + } + + /** + * Sanitizes the action of a condition. + * + * @param string $action The action to sanitize. + * + * @return string The sanitized action. + */ + protected static function sanitizeAction($action) + { + $action = (string) $action; + switch ($action) { + case Query::ACTION_EXIST: + case Query::ACTION_NOT_EXIST: + case Query::ACTION_EQUALS: + case Query::ACTION_LESS_THAN: + case Query::ACTION_GREATHER_THAN: + return $action; + default: + throw new UnexpectedValueException( + 'Unknown action specified', 208, null, $action + ); + } + } + + /** + * Creates a new query with an initial condition. + * + * @param string $name The name of the property to test. + * @param string $value The value to test against. Not required for + * existence tests. + * @param string $action One of the ACTION_* constants. Describes the + * operation to perform. + * + * @return Query The query object. + */ + public static function where( + $name, $value = null, $action = self::ACTION_EXIST + ) { + $query = new self; + return $query->addWhere($name, $value, $action); + } + + /** + * Negates the query. + * + * @return Query The query object. + */ + public function not() + { + $this->words[] = array('#!', null); + return $this; + } + + /** + * Adds a condition as an alternative to the query. + * + * @param string $name The name of the property to test. + * @param string $value The value to test against. Not required for + * existence tests. + * @param string $action One of the ACTION_* constants. Describes the + * operation to perform. + * + * @return Query The query object. + */ + public function orWhere($name, $value = null, $action = self::ACTION_EXIST) + { + $this->addWhere($name, $value, $action)->words[] = array('#|', null); + return $this; + } + + /** + * Adds a condition in addition to the query. + * + * @param string $name The name of the property to test. + * @param string $value The value to test against. Not required for + * existence tests. + * @param string $action One of the ACTION_* constants. Describes the + * operation to perform. + * + * @return Query The query object. + */ + public function andWhere($name, $value = null, $action = self::ACTION_EXIST) + { + $this->addWhere($name, $value, $action)->words[] = array('#&', null); + return $this; + } + + /** + * Sends the query over a communicator. + * + * @param Communicator $com The communicator to send the query over. + * + * @return int The number of bytes sent. + */ + public function send(Communicator $com) + { + if (!$com->getTransmitter()->isAcceptingData()) { + throw new SocketException( + 'Transmitter is invalid. Sending aborted.', 209 + ); + } + $bytes = 0; + foreach ($this->words as $queryWord) { + list($predicate, $value) = $queryWord; + $prefix = '?' . $predicate; + if (null === $value) { + $bytes += $com->sendWord($prefix); + } else { + $prefix .= '='; + if (is_string($value)) { + $bytes += $com->sendWord($prefix . $value); + } else { + $bytes += $com->sendWordFromStream($prefix, $value); + } + } + } + return $bytes; + } + + /** + * Adds a condition. + * + * @param string $name The name of the property to test. + * @param string $value The value to test against. Not required for + * existence tests. + * @param string $action One of the ACTION_* constants. Describes the + * operation to perform. + * + * @return Query The query object. + */ + protected function addWhere($name, $value, $action) + { + $this->words[] = array( + self::sanitizeAction($action) + . Message::sanitizeArgumentName($name), + (null === $value ? null : Message::sanitizeArgumentValue($value)) + ); + return $this; + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Request.php b/src/PEAR2/Net/RouterOS/Request.php new file mode 100644 index 0000000..5917392 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Request.php @@ -0,0 +1,226 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Represents a RouterOS request. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class Request extends Message +{ + + /** + * @var string The command to be executed. + */ + private $_command; + + /** + * @var Query A query for the command. + */ + private $_query = null; + + /** + * Creates a request to send to RouterOS. + * + * @param string $command The command to send. + * + * @see setCommand() + * @see setArgument() + * @see setTag() + */ + public function __construct($command) + { + $this->setCommand($command); + } + + /** + * Sets the command to send to RouterOS. + * + * Sets the command to send to RouterOS. The command can use the API or CLI + * syntax of RouterOS, but either way, it must be absolute (begin with a + * "/") and without arguments. + * + * @param string $command The command to send. + * + * @return Request The request object. + * @see getCommand() + * @see setArgument() + */ + public function setCommand($command) + { + $command = (string) $command; + if (strpos($command, '/') !== 0) { + throw new InvalidArgumentException( + 'Commands must be absolute.', 202 + ); + } + if (substr_count($command, '/') === 1) { + //Command line syntax convertion + $cmdParts = preg_split('#[\s/]+#sm', $command); + $cmdRes = array($cmdParts[0]); + for ($i = 1, $n = count($cmdParts); $i < $n; $i++) { + if ('..' === $cmdParts[$i]) { + $delIndex = count($cmdRes) - 1; + if ($delIndex < 1) { + throw new InvalidArgumentException( + 'Unable to resolve command', 203 + ); + } + unset($cmdRes[$delIndex]); + $cmdRes = array_values($cmdRes); + } else { + $cmdRes[] = $cmdParts[$i]; + } + } + $command = implode('/', $cmdRes); + } + if (!preg_match('#^/\S+$#sm', $command)) { + throw new InvalidArgumentException( + 'Invalid command supplied.', 204 + ); + } + $this->_command = $command; + return $this; + } + + /** + * Gets the command that will be send to RouterOS. + * + * Gets the command that will be send to RouterOS in its API syntax. + * + * @return string The command to send. + * @see setCommand() + */ + public function getCommand() + { + return $this->_command; + } + + /** + * Sets the query to send with the command. + * + * @param Query $query The query to be set. Setting NULL will remove the + * currently associated query. + * + * @return Request The request object. + * @see getQuery() + */ + public function setQuery(Query $query = null) + { + $this->_query = $query; + return $this; + } + + /** + * Gets the currently associated query + * + * @return Query The currently associated query. + * @see setQuery() + */ + public function getQuery() + { + return $this->_query; + } + + /** + * Sets the tag to associate the request with. + * + * Sets the tag to associate the request with. Setting NULL erases the + * currently set tag. + * + * @param string $tag The tag to set. + * + * @return Request The request object. + * @see getTag() + */ + public function setTag($tag) + { + return parent::setTag($tag); + } + + /** + * Sets an argument for the request. + * + * @param string $name Name of the argument. + * @param string $value Value of the argument. Setting the value to NULL + * removes an argument of this name. + * + * @return Request The request object. + * @see getArgument() + */ + public function setArgument($name, $value = null) + { + return parent::setArgument($name, $value); + } + + /** + * Removes all arguments from the request. + * + * @return Request The request object. + */ + public function removeAllArguments() + { + return parent::removeAllArguments(); + } + + /** + * Sends a request over a communicator. + * + * @param Communicator $com The communicator to send the request over. + * + * @return int The number of bytes sent. + * @see Client::sendSync() + * @see Client::sendAsync() + */ + public function send(Communicator $com) + { + if (!$com->getTransmitter()->isAcceptingData()) { + throw new SocketException( + 'Transmitter is invalid. Sending aborted.', 205 + ); + } + $bytes = 0; + $bytes += $com->sendWord($this->getCommand()); + if (null !== ($tag = $this->getTag())) { + $bytes += $com->sendWord('.tag=' . $tag); + } + foreach ($this->getAllArguments() as $name => $value) { + $prefix = '=' . $name . '='; + if (is_string($value)) { + $bytes += $com->sendWord($prefix . $value); + } else { + $bytes += $com->sendWordFromStream($prefix, $value); + } + } + $query = $this->getQuery(); + if ($query instanceof Query) { + $bytes += $query->send($com); + } + $bytes += $com->sendWord(''); + return $bytes; + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/Response.php b/src/PEAR2/Net/RouterOS/Response.php new file mode 100644 index 0000000..ef9c344 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/Response.php @@ -0,0 +1,179 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Represents a RouterOS response. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class Response extends Message +{ + + /** + * The last response for a request. + */ + const TYPE_FINAL = '!done'; + + /** + * A response with data. + */ + const TYPE_DATA = '!re'; + + /** + * A response signifying error. + */ + const TYPE_ERROR = '!trap'; + + /** + * A response signifying a fatal error, due to which the connection would be + * terminated. + */ + const TYPE_FATAL = '!fatal'; + + /** + * @var array An array of unrecognized words in network order. + */ + protected $unrecognizedWords = array(); + + /** + * @var string The response type. + */ + private $_type = null; + + /** + * Extracts a new response from a communicator. + * + * @param Communicator $com The communicator from which to extract the + * new response. + * @param bool $asStream Whether to populate the argument values + * with streams instead of strings. + * + * @see getType() + * @see getArgument() + */ + public function __construct(Communicator $com, $asStream = false) + { + if (!$com->getTransmitter()->isDataAwaiting()) { + throw new SocketException( + 'No data awaiting. Receiving aborted.', 206 + ); + } + $this->setType($com->getNextWord()); + if ($asStream) { + for ( + $word = $com->getNextWordAsStream(), fseek($word, 0, SEEK_END); + ftell($word) !== 0; + $word = $com->getNextWordAsStream(), fseek( + $word, 0, SEEK_END + ) + ) { + rewind($word); + $ind = fread($word, 1); + if ('=' === $ind || '.' === $ind) { + $prefix = stream_get_line($word, null, '='); + } + if ('=' === $ind) { + $value = fopen('php://temp', 'r+b'); + $bytesCopied = ftell($word); + while (!feof($word)) { + $bytesCopied += stream_copy_to_stream( + $word, $value, 0xFFFFF, $bytesCopied + ); + } + rewind($value); + $this->setArgument($prefix, $value); + continue; + } + if ('.' === $ind && 'tag' === $prefix) { + $this->setTag(stream_get_contents($word, -1, -1)); + continue; + } + rewind($word); + $this->unrecognizedWords[] = $word; + } + } else { + for ($word = $com->getNextWord(); '' !== $word; + $word = $com->getNextWord() + ) { + if (preg_match('/^=([^=]+)=(.*)$/sm', $word, $matches)) { + $this->setArgument($matches[1], $matches[2]); + } elseif (preg_match('/^\.tag=(.*)$/sm', $word, $matches)) { + $this->setTag($matches[1]); + } else { + $this->unrecognizedWords[] = $word; + } + } + } + } + + /** + * Sets the response type. + * + * Sets the response type. Valid values are the TYPE_* constants. + * + * @param string $type The new response type. + * + * @return Response The response object. + * @see getType() + */ + protected function setType($type) + { + switch ($type) { + case self::TYPE_FINAL: + case self::TYPE_DATA: + case self::TYPE_ERROR: + case self::TYPE_FATAL: + $this->_type = $type; + return $this; + default: + throw new UnexpectedValueException( + 'Unrecognized response type.', 207, null, $type + ); + } + } + + /** + * Gets the response type. + * + * @return string The response type. + * @see setType() + */ + public function getType() + { + return $this->_type; + } + + /** + * Gets a list of unrecognized words. + * + * @return array The list of unrecognized words. + */ + public function getUnrecognizedWords() + { + return $this->unrecognizedWords; + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/ResponseCollection.php b/src/PEAR2/Net/RouterOS/ResponseCollection.php new file mode 100644 index 0000000..5706ae8 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/ResponseCollection.php @@ -0,0 +1,313 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Represents a collection of RouterOS responses. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class ResponseCollection implements \ArrayAccess, \SeekableIterator, \Countable +{ + + /** + * @var array An array with all {@link Response} objects. + */ + protected $responses = array(); + + /** + * @var array An array with each {@link Response} object's type. + */ + protected $responseTypes = array(); + + /** + * @var array An array with each {@link Response} object's tag. + */ + protected $responseTags = array(); + + /** + * @var array An array with all distinct arguments across all + * {@link Response} objects. Created at the first call of + * {@link getArgumentMap()}. + */ + protected $argumentMap = null; + + /** + * @var int A pointer, as required by SeekableIterator. + */ + protected $position = 0; + + /** + * Creates a new collection. + * + * @param array $responses An array of responses, in network order. + */ + public function __construct(array $responses) + { + $index = 0; + foreach ($responses as $response) { + if ($response instanceof Response) { + $this->responseTypes[$index] = $response->getType(); + $this->responseTags[$index] = $response->getTag(); + $this->responses[$index++] = $response; + } + } + } + + /** + * Gets the whole collection as an array. + * + * @return array An array with all responses, in network order. + */ + public function toArray() + { + return $this->responses; + } + + /** + * Counts the responses in the collection. + * + * @return int The number of responses in the collection. + */ + public function count() + { + return count($this->responses); + } + + /** + * Checks if an offset exists. + * + * @param int $offset The offset to check. + * + * @return bool TRUE if the offset exists, FALSE otherwise. + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->responses); + } + + /** + * Gets a {@link Response} from a specified offset. + * + * @param int $offset The offset of the desired response. + * + * @return Response The response at the specified offset. + */ + public function offsetGet($offset) + { + return $this->responses[$offset]; + } + + /** + * N/A + * + * This method exists only because it is required for ArrayAccess. The + * collection is read only. + * + * @param int $offset N/A + * @param Response $value N/A + * + * @return void + */ + public function offsetSet($offset, $value) + { + + } + + + /** + * N/A + * + * This method exists only because it is required for ArrayAccess. The + * collection is read only. + * + * @param int $offset N/A + * + * @return void + */ + public function offsetUnset($offset) + { + + } + + /** + * Resets the pointer to 0, and returns the first response. + * + * @return Response The first response in the collection, or FALSE if the + * collection is empty. + */ + public function rewind() + { + return $this->seek(0); + } + + /** + * Moves the position pointer to a specified position. + * + * @param int $position The position to move to. + * + * @return Response The {@link Response} at the specified position, or FALSE + * if the specified position is not valid. + */ + public function seek($position) + { + $this->position = $position; + return $this->current(); + } + + /** + * Moves the pointer forward by 1, and gets the next response. + * + * @return Response The next {@link Response} object, or FALSE if the + * position is not valid. + */ + public function next() + { + ++$this->position; + return $this->current(); + } + + /** + * Gets the response at the current pointer position. + * + * @return Response The response at the current pointer position, or FALSE + * if the position is not valid. + */ + public function current() + { + return $this->valid() ? $this->responses[$this->position] : false; + } + + /** + * Gets the key at the current pointer position. + * + * @return int The key at the current pointer position, i.e. the pointer + * position itself, or FALSE if the position is not valid. + */ + public function key() + { + return $this->valid() ? $this->position : false; + } + + /** + * Checks if the pointer is still pointing to an existing offset. + * + * @return bool TRUE if the pointer is valid, FALSE otherwise. + */ + public function valid() + { + return $this->offsetExists($this->position); + } + + /** + * Gets all distinct argument names. + * + * Gets all distinct argument names across all responses. + * + * @return array An array with all distinct argument names as keys, and the + * indexes at which they occur as values. + */ + public function getArgumentMap() + { + if (null === $this->argumentMap) { + $arguments = array(); + foreach ($this->responses as $index => $response) { + foreach (array_keys($response->getAllArguments()) as $name) { + if (!isset($arguments[$name])) { + $arguments[$name] = array(); + } + $arguments[$name][] = $index; + } + } + $this->argumentMap = $arguments; + } + return $this->argumentMap; + } + + /** + * Gets all responses of a specified type. + * + * @param string $type The response type to filter by. Valid values are the + * Response::TYPE_* constants. + * + * @return ResponseCollection A new collection with responses of the + * specified type. + */ + public function getAllOfType($type) + { + $result = array(); + foreach (array_keys($this->responseTypes, $type, true) as $index) { + $result[] = $this->responses[$index]; + } + return new ResponseCollection($result); + } + + /** + * Gets all responses with a specified tag. + * + * @param string $tag The tag to filter by. + * + * @return ResponseCollection A new collection with responses having the + * specified tag. + */ + public function getAllTagged($tag) + { + $result = array(); + foreach (array_keys($this->responseTags, $tag, true) as $index) { + $result[] = $this->responses[$index]; + } + return new ResponseCollection($result); + } + + /** + * Gets the last {@link Response} in the collection. + * + * @return Response The last response in the collection. + */ + public function getLast() + { + return $this->responses[count($this->responses) - 1]; + } + + /** + * Calls a method of the response pointed by the pointer. + * + * Calls a method of the response pointed by the pointer. This is a magic + * PHP method, thanks to which any function you call on the collection that + * is not defined will be redirected to the response. + * + * @param string $method The name of the method to call. + * @param array $args The arguments to pass to the method. + * + * @return mixed Whatever the called function returns. + */ + public function __call($method, array $args) + { + return call_user_func_array( + array($this->current(), $method), $args + ); + } + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/SocketException.php b/src/PEAR2/Net/RouterOS/SocketException.php new file mode 100644 index 0000000..6ecc6f9 --- /dev/null +++ b/src/PEAR2/Net/RouterOS/SocketException.php @@ -0,0 +1,35 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when something goes wrong with the connection. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class SocketException extends \RuntimeException implements Exception +{ + +} \ No newline at end of file diff --git a/src/PEAR2/Net/RouterOS/UnexpectedValueException.php b/src/PEAR2/Net/RouterOS/UnexpectedValueException.php new file mode 100644 index 0000000..ac6c1af --- /dev/null +++ b/src/PEAR2/Net/RouterOS/UnexpectedValueException.php @@ -0,0 +1,83 @@ + + * @copyright 2011 Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $WCREV$ + * @link http://netrouteros.sourceforge.net/ + */ +/** + * The namespace declaration. + */ +namespace PEAR2\Net\RouterOS; + +/** + * Exception thrown when encountering something not supported by RouterOS or + * this package. + * + * @category Net + * @package PEAR2_Net_RouterOS + * @author Vasil Rangelov + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://netrouteros.sourceforge.net/ + */ +class UnexpectedValueException extends \UnexpectedValueException + implements Exception +{ + + /** + * + * @var mixed The unexpected value. + */ + private $_value = null; + + /** + * Creates a new UnexpectedValueException. + * + * @param string $message The Exception message to throw. + * @param int $code The Exception code. + * @param Exception $previous The previous exception used for the exception + * chaining. + * @param mixed $value The unexpected value. + */ + public function __construct($message, $code = 0, $previous = null, + $value = null + ) { + parent::__construct($message, $code, $previous); + $this->_value = $value; + } + + /** + * Gets the unexpected value. + * + * @return mixed The unexpected value. + */ + public function getValue() + { + return $this->_value; + } + + // @codeCoverageIgnoreStart + // String representation is not reliable in testing + + /** + * Returns a string representation of the exception. + * + * @return string The exception as a string. + */ + public function __toString() + { + return parent::__toString() . "\nValue:{$this->_value}"; + } + + // @codeCoverageIgnoreEnd +} \ No newline at end of file diff --git a/tests/ClientFeaturesTest.php b/tests/ClientFeaturesTest.php new file mode 100644 index 0000000..0352870 --- /dev/null +++ b/tests/ClientFeaturesTest.php @@ -0,0 +1,848 @@ +object = new Client(HOSTNAME, USERNAME, PASSWORD, PORT); + } + + protected function tearDown() + { + unset($this->object); + } + + public function testSendSyncReturningCollection() + { + $list = $this->object->sendSync(new Request('/ip/arp/print')); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertInternalType( + 'string', $list[0]->getArgument('address'), + 'The address is not a string' + ); + } + + public function testSendSyncReturningCollectionWithStreams() + { + $this->assertFalse($this->object->getStreamResponses()); + $this->assertFalse($this->object->setStreamResponses(true)); + $this->assertTrue($this->object->getStreamResponses()); + $list = $this->object->sendSync(new Request('/ip/arp/print')); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertInternalType( + 'resource', $list[0]->getArgument('address'), + 'The address is not a stream' + ); + } + + public function testSendAsyncTagRequirement() + { + $ping = new Request('/ping'); + $ping->setArgument('address', HOSTNAME_INVALID); + try { + $this->object->sendAsync($ping); + + $this->fail('The call had to fail.'); + } catch (DataFlowException $e) { + $this->assertEquals(102, $e->getCode(), 'Improper exception code.'); + } + } + + public function testSendAsyncUniqueTagRequirement() + { + $ping = new Request('/ping'); + $ping->setArgument('address', HOSTNAME_INVALID); + $ping->setTag('ping'); + $ping2 = new Request('/ping'); + $ping2->setArgument('address', HOSTNAME_INVALID); + $ping2->setTag('ping'); + $this->object->sendAsync($ping); + try { + $this->object->sendAsync($ping2); + + $this->fail('The call had to fail.'); + } catch (DataFlowException $e) { + $this->assertEquals(103, $e->getCode(), 'Improper exception code.'); + } + } + + public function testSendAsyncWithCallbackAndTempLoop() + { + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $repliesCount = 0; + $this->object->sendAsync( + $ping, + function($response, $client) use (&$repliesCount) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'ping', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $repliesCount++; + } + ); + + $this->object->loop(2); + $this->assertGreaterThan( + 0, $repliesCount, + "No responses for '" . HOSTNAME . "' in 2 seconds." + ); + } + + public function testSendAsyncAndFullCancel() + { + $ping = new Request('/ping'); + $ping->setArgument('address', HOSTNAME_INVALID); + $ping->setTag('ping1'); + $ping2 = new Request('/ping'); + $ping2->setArgument('address', HOSTNAME_INVALID); + $ping2->setTag('ping2'); + $this->object->sendAsync($ping); + $this->object->sendAsync($ping2); + $this->object->loop(2); + $this->object->cancelRequest(); + try { + $this->object->extractNewResponses('ping1'); + $this->fail('The call had to fail.'); + } catch (DataFlowException $e) { + $this->assertEquals(104, $e->getCode(), 'Improper exception code.'); + } + try { + $this->object->extractNewResponses('ping2'); + $this->fail('The call had to fail.'); + } catch (DataFlowException $e) { + $this->assertEquals(104, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidCancel() + { + $this->assertEquals( + 0, $this->object->getPendingRequestsCount(), + 'There should be no active requests.' + ); + try { + $this->object->cancelRequest('ping1'); + } catch (DataFlowException $e) { + $this->assertEquals(105, $e->getCode(), 'Improper exception code.'); + } + $this->assertEquals( + 0, $this->object->getPendingRequestsCount(), + 'There should be no active requests.' + ); + } + + public function testSendAsyncAndInvalidCancel() + { + $ping = new Request('/ping'); + $ping->setArgument('address', HOSTNAME_INVALID); + $ping->setTag('ping1'); + $ping2 = new Request('/ping'); + $ping2->setArgument('address', HOSTNAME_INVALID); + $ping2->setTag('ping2'); + $this->object->sendAsync($ping); + $this->object->sendAsync($ping2); + $this->assertEquals( + 2, $this->object->getPendingRequestsCount(), + 'Improper active request count before cancel test.' + ); + $this->object->loop(2); + try { + $this->object->cancelRequest('ping3'); + } catch (DataFlowException $e) { + $this->assertEquals(105, $e->getCode(), 'Improper exception code.'); + } + $this->assertEquals( + 2, $this->object->getPendingRequestsCount(), + 'Improper active request count after cancel test.' + ); + } + + public function testSendAsyncAndFullExtract() + { + $ping = new Request('/ping'); + $ping->setArgument('address', HOSTNAME_INVALID); + $ping->setTag('ping1'); + $ping2 = new Request('/ping'); + $ping2->setArgument('address', HOSTNAME_INVALID); + $ping2->setTag('ping2'); + $this->object->sendAsync($ping); + $this->object->sendAsync($ping2); + $this->assertEquals( + 2, $this->object->getPendingRequestsCount(), + 'Improper pending request count before extraction test.' + ); + $this->object->loop(2); + $responses = $this->object->extractNewResponses(); + + $this->assertEquals( + 2, $this->object->getPendingRequestsCount(), + 'Improper pending request count after extraction test.' + ); + + $this->assertGreaterThan( + 0, count($responses->getAllTagged('ping1')), + "No responses for 'ping1' in 2 seconds." + ); + $this->assertGreaterThan( + 0, count($responses->getAllTagged('ping2')), + "No responses for 'ping2' in 2 seconds." + ); + } + + public function testSendAsyncWithCallbackAndCancel() + { + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $finalRepliesCount = -1; + $responseCount = 0; + $this->object->sendAsync( + $ping, + function($response, $client) use (&$responseCount) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'ping', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $responseCount++; + } + ); + + $this->object->loop(2); + $bufferedReplies = count($this->object->extractNewResponses('ping')); + $this->assertEquals( + 0, $bufferedReplies, + 'Responses for requests with callbacks must not be buffered.' + ); + $finalRepliesCount = $responseCount; + $this->object->cancelRequest('ping'); + $this->object->loop(2); + $this->assertGreaterThan( + 0, $responseCount, + "No responses for '" . HOSTNAME . "' in 2 seconds." + ); + $this->assertEquals( + $finalRepliesCount + 1/* The !trap */, + $responseCount, "Extra callbacks were executed during second loop." + ); + } + + public function testSendAsyncWithCallbackAndCancelWithin() + { + $limit = 5; + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $repliesCount = 0; + $this->object->sendAsync( + $ping, + function($response, $client) use (&$repliesCount, $limit) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'ping', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $repliesCount++; + return $repliesCount === $limit; + } + ); + + $this->object->loop(); + $this->assertEquals( + $limit + 1/* The !trap */, $repliesCount, + "Extra callbacks were executed during second loop." + ); + } + + public function testSendAsyncWithCallbackAndFullLoop() + { + $arpPrint = new Request('/ip/arp/print'); + $arpPrint->setTag('arp'); + $repliesCount = 0; + $arpCallback = function($response, $client) use (&$repliesCount) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'arp', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $repliesCount++; + }; + $this->object->sendAsync($arpPrint, $arpCallback); + + $this->object->loop(); + + $this->assertGreaterThan(0, $repliesCount, "No callbacks."); + $repliesCount = 0; + + $this->object->sendAsync($arpPrint, $arpCallback); + + $this->object->loop(); + + $this->assertGreaterThan(0, $repliesCount, "No callbacks."); + } + + public function testSendAsyncAndCompleteRequest() + { + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $repliesCount = 0; + $this->object->sendAsync( + $ping, + function($response, $client) use (&$repliesCount) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'ping', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $repliesCount++; + } + ); + + + $arpPrint = new Request('/ip/arp/print'); + $arpPrint->setTag('arp'); + $this->object->sendAsync($arpPrint); + + $list = $this->object->completeRequest('arp'); + + + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + + $this->assertGreaterThan( + 0, $repliesCount, + "No responses for '" . HOSTNAME . "' before of 'arp' is done." + ); + } + + public function testSendAsyncAndCompleteRequestWithStream() + { + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $repliesCount = 0; + $this->object->sendAsync( + $ping, + function($response, $client) use (&$repliesCount) { + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Response', $response, + 'A callback must receive a single response per call' + ); + \PHPUnit_Framework_TestCase::assertInstanceOf( + __NAMESPACE__ . '\Client', $client, + 'A callback must receive a copy of the client object' + ); + + \PHPUnit_Framework_TestCase::assertEquals( + 'ping', $response->getTag(), + 'The callback must only receive responses meant for it.' + ); + $repliesCount++; + } + ); + + + $arpPrint = new Request('/ip/arp/print'); + $arpPrint->setTag('arp'); + $this->object->sendAsync($arpPrint); + $this->assertFalse($this->object->getStreamResponses()); + $this->assertFalse($this->object->setStreamResponses(true)); + $this->assertTrue($this->object->getStreamResponses()); + + $list = $this->object->completeRequest('arp'); + + + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + + $this->assertGreaterThan( + 0, $repliesCount, + "No responses for '" . HOSTNAME . "' before of 'arp' is done." + ); + $this->assertInternalType( + 'resource', $list[0]->getArgument('address'), + 'The address is not a stream' + ); + } + + public function testCompleteRequestEmptyQueue() + { + try { + $this->object->completeRequest('invalid'); + + $this->fail('No exception was thrown.'); + } catch (DataFlowException $e) { + $this->assertEquals(104, $e->getCode(), 'Improper exception code.'); + } + } + + public function testCompleteRequestInvalid() + { + try { + $arpPrint = new Request('/ip/arp/print'); + $arpPrint->setTag('arp'); + $this->object->sendAsync($arpPrint); + $this->object->completeRequest('invalid'); + + $this->fail('No exception was thrown.'); + } catch (DataFlowException $e) { + $this->assertEquals(104, $e->getCode(), 'Improper exception code.'); + } + } + + public function testSendAsyncWithoutCallbackAndLoop() + { + $arpPrint = new Request('/ip/arp/print'); + $arpPrint->setTag('arp'); + $this->object->sendAsync($arpPrint); + + $this->object->loop(); + $list = $this->object->extractNewResponses('arp'); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertGreaterThan(0, count($list), 'No responses.'); + + $ping = new Request('/ping'); + $ping->setTag('ping'); + $ping->setArgument('address', HOSTNAME); + $this->object->sendAsync($ping); + + $this->object->loop(2); + $list = $this->object->extractNewResponses('ping'); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertGreaterThan(0, count($list), 'No responses.'); + $this->assertEquals( + 0, count($list->getAllOfType(Response::TYPE_FINAL)), + 'The command should not be finished yet.' + ); + $this->assertEquals( + count($list), count($list->getAllOfType(Response::TYPE_DATA)), + 'There should be only data responses.' + ); + $this->object->cancelRequest('ping'); + } + + public function testStreamEquality() + { + $request = new Request('/queue/simple/print'); + + $request->setQuery( + Query::where('target-addresses', HOSTNAME_INVALID . '/32') + ); + + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + + $this->object->setStreamResponses(true); + $streamList = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $streamList, + 'The list is not a collection' + ); + + foreach ($list as $index => $response) { + $streamListArgs = $streamList[$index]->getAllArguments(); + foreach ($response->getAllArguments() as $argName => $value) { + $this->assertArrayHasKey( + $argName, $streamListArgs, 'Missing argument.' + ); + $this->assertEquals( + $value, stream_get_contents($streamListArgs[$argName]), + 'Argument values are not equivalent.' + ); + unset($streamListArgs[$argName]); + } + $this->assertEmpty($streamListArgs, 'Extra arguments.'); + } + } + + public function testSendSyncWithQueryEquals() + { + $request = new Request('/queue/simple/print'); + + $request->setQuery( + Query::where('target-addresses', HOSTNAME_INVALID . '/32') + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + 2, count($list), + 'The list should have only one item and a "done" reply.' + ); + + $request->setQuery( + Query::where( + 'target-addresses', HOSTNAME_INVALID . '/32', + Query::ACTION_EQUALS + ) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + 2, count($list), + 'The list should have only one item and a "done" reply.' + ); + + $invalidAddressStream = fopen('php://temp', 'r+b'); + fwrite($invalidAddressStream, HOSTNAME_INVALID . '/32'); + rewind($invalidAddressStream); + + $request->setQuery( + Query::where('target-addresses', $invalidAddressStream) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + 2, count($list), + 'The list should have only one item and a "done" reply.' + ); + + $request->setQuery( + Query::where( + 'target-addresses', $invalidAddressStream, Query::ACTION_EQUALS + ) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + 2, count($list), + 'The list should have only one item and a "done" reply.' + ); + } + + public function testSendSyncWithQueryEqualsNot() + { + $request = new Request('/queue/simple/print'); + $fullList = $this->object->sendSync($request); + + $request->setQuery( + Query::where('target-addresses', HOSTNAME_INVALID . '/32')->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 1, count($list), 'The list was never filtered.' + ); + + $request->setQuery( + Query::where( + 'target-addresses', HOSTNAME_INVALID . '/32', + Query::ACTION_EQUALS + )->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 1, count($list), 'The list was never filtered.' + ); + + $invalidAddressStream = fopen('php://temp', 'r+b'); + fwrite($invalidAddressStream, HOSTNAME_INVALID . '/32'); + rewind($invalidAddressStream); + + $request->setQuery( + Query::where('target-addresses', $invalidAddressStream)->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 1, count($list), 'The list was never filtered.' + ); + + $request->setQuery( + Query::where( + 'target-addresses', $invalidAddressStream, + Query::ACTION_EQUALS + )->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 1, count($list), 'The list was never filtered.' + ); + } + + public function testSendSyncWithQueryEnum() + { + $request = new Request('/queue/simple/print'); + $fullList = $this->object->sendSync($request); + + $request->setQuery( + Query::where('target-addresses', HOSTNAME_SILENT . '/32') + ->orWhere('target-addresses', HOSTNAME_INVALID . '/32') + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals(3, count($list), 'The list was never filtered.'); + + $invalidAddressStream = fopen('php://temp', 'r+b'); + fwrite($invalidAddressStream, HOSTNAME_INVALID . '/32'); + rewind($invalidAddressStream); + + $silentAddressStream = fopen('php://temp', 'r+b'); + fwrite($silentAddressStream, HOSTNAME_SILENT . '/32'); + rewind($silentAddressStream); + + $request->setQuery( + Query::where('target-addresses', $silentAddressStream) + ->orWhere('target-addresses', $invalidAddressStream) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals(3, count($list), 'The list was never filtered.'); + } + + public function testSendSyncWithQueryEnumNot() + { + $request = new Request('/queue/simple/print'); + $fullList = $this->object->sendSync($request); + + $request->setQuery( + Query::where('target-addresses', HOSTNAME_SILENT . '/32') + ->orWhere('target-addresses', HOSTNAME_INVALID . '/32') + ->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 2, count($list), 'The list was never filtered.' + ); + + $invalidAddressStream = fopen('php://temp', 'r+b'); + fwrite($invalidAddressStream, HOSTNAME_INVALID . '/32'); + rewind($invalidAddressStream); + + $silentAddressStream = fopen('php://temp', 'r+b'); + fwrite($silentAddressStream, HOSTNAME_SILENT . '/32'); + rewind($silentAddressStream); + + $request->setQuery( + Query::where('target-addresses', $silentAddressStream) + ->orWhere('target-addresses', $invalidAddressStream) + ->not() + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertEquals( + count($fullList) - 2, count($list), 'The list was never filtered.' + ); + } + + public function testSendSyncWithQueryBetween() + { + $request = new Request('/ip/arp/print'); + $fullList = $this->object->sendSync($request); + + $request->setQuery( + Query::where('address', HOSTNAME, Query::ACTION_GREATHER_THAN) + ->andWhere('address', HOSTNAME_INVALID, Query::ACTION_LESS_THAN) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertLessThan( + count($fullList), count($list), 'The list was never filtered.' + ); + + $invalidAddressStream = fopen('php://temp', 'r+b'); + fwrite($invalidAddressStream, HOSTNAME_INVALID . '/32'); + rewind($invalidAddressStream); + + $addressStream = fopen('php://temp', 'r+b'); + fwrite($addressStream, HOSTNAME . '/32'); + rewind($addressStream); + + $request->setQuery( + Query::where('address', $addressStream, Query::ACTION_GREATHER_THAN) + ->andWhere( + 'address', $invalidAddressStream, Query::ACTION_LESS_THAN + ) + ); + $list = $this->object->sendSync($request); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $fullList, + 'The list is not a collection' + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $list, + 'The list is not a collection' + ); + $this->assertLessThan( + count($fullList), count($list), 'The list was never filtered.' + ); + } + + public function testDefaultCharsets() + { + $this->assertNull( + $this->object->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertNull( + $this->object->getCharset(Communicator::CHARSET_LOCAL) + ); + $this->assertEquals( + array( + Communicator::CHARSET_REMOTE => null, + Communicator::CHARSET_LOCAL => null + ), + $this->object->getCharset(Communicator::CHARSET_ALL) + ); + $this->assertEquals( + array( + Communicator::CHARSET_REMOTE => null, + Communicator::CHARSET_LOCAL => null + ), + Communicator::getDefaultCharset(Communicator::CHARSET_ALL) + ); + $this->assertNull( + Communicator::getDefaultCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertNull( + Communicator::getDefaultCharset(Communicator::CHARSET_LOCAL) + ); + } + +} \ No newline at end of file diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php new file mode 100644 index 0000000..98f4c9c --- /dev/null +++ b/tests/ConnectionTest.php @@ -0,0 +1,316 @@ +assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS, + 'Object initialization failed.' + ); + } catch (Exception $e) { + $this->fail('Unable to connect normally:' . (string) $e); + } + } + + public function testNormalPersistentConnection() + { + try { + $routerOS = new Client(HOSTNAME, USERNAME, PASSWORD, PORT, true); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS, + 'Object initialization failed.' + ); + $routerOS->close(); + } catch (Exception $e) { + $this->fail('Unable to connect normally:' . (string) $e); + } + } + + public function testMultipleNormalConnection() + { + try { + $routerOS1 = new Client(HOSTNAME, USERNAME, PASSWORD, PORT); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS1, + 'Object initialization failed.' + ); + + $routerOS2 = new Client(HOSTNAME, USERNAME, PASSWORD, PORT); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS2, + 'Object initialization failed.' + ); + } catch (Exception $e) { + $this->fail('Unable to connect normally:' . (string) $e); + } + } + + public function testMultiplePersistentConnection() + { + try { + $routerOS1 = new Client(HOSTNAME, USERNAME, PASSWORD, PORT, true); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS1, + 'Object initialization failed.' + ); + + $routerOS2 = new Client(HOSTNAME, USERNAME, PASSWORD, PORT, true); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS2, + 'Object initialization failed.' + ); + + $routerOS1->close(); + $routerOS2->close(); + } catch (Exception $e) { + $this->fail('Unable to connect normally:' . (string) $e); + } + } + + public function testNormalContextConnection() + { + try { + $context = stream_context_create(); + $this->assertInternalType( + 'resource', $context, 'Failed to create context.' + ); + $this->assertEquals( + 'stream-context', get_resource_type($context), + 'Failed to create proper context.' + ); + $routerOS = new Client( + HOSTNAME, USERNAME, PASSWORD, PORT, false, null, $context + ); + } catch (SocketException $e) { + $this->fail('Unable to connect normally.'); + } + } + + public function testInvalidUsername() + { + try { + $routerOS = new Client(HOSTNAME, USERNAME_INVALID, PASSWORD, PORT); + + $this->fail( + 'No proper connection with the username "' + . USERNAME_INVALID + . '" should be available.' + ); + } catch (DataFlowException $e) { + $this->assertEquals(100, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidPassword() + { + try { + $routerOS = new Client(HOSTNAME, USERNAME, PASSWORD_INVALID, PORT); + + $this->fail( + 'No proper connection with the password "' + . PASSWORD_INVALID + . '" should be available.' + ); + } catch (DataFlowException $e) { + $this->assertEquals(100, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidUsernameAndPassword() + { + try { + $routerOS = new Client( + HOSTNAME, USERNAME_INVALID, PASSWORD_INVALID, PORT + ); + + $this->fail( + 'No proper connection with the username "' + . USERNAME_INVALID + . '" and password "' + . PASSWORD_INVALID + . '" should be available.' + ); + } catch (DataFlowException $e) { + $this->assertEquals(100, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidHost() + { + try { + $routerOS = new Client(HOSTNAME_INVALID, USERNAME, PASSWORD, PORT); + + $this->fail( + 'No proper connection over hostname "' + . HOSTNAME_INVALID + . '" should be available.' + ); + } catch (SocketException $e) { + $this->assertEquals(101, $e->getCode(), 'Improper exception code.'); + } + } + + public function testSilentHost() + { + try { + $routerOS = new Client(HOSTNAME_SILENT, USERNAME, PASSWORD, PORT); + + $this->fail( + 'No proper connection over hostname "' + . HOSTNAME_SILENT + . '" should be available.' + ); + } catch (T\SocketException $e) { + $this->assertEquals(7, $e->getCode()); + $this->assertEquals(10060, $e->getSocketErrorNumber()); + } + } + + public function testInvalidPort() + { + try { + $routerOS = new Client(HOSTNAME, USERNAME, PASSWORD, PORT_INVALID); + + $this->fail( + 'No proper connection over port "' + . PORT_INVALID + . '" should be available.' + ); + } catch (SocketException $e) { + $this->assertEquals(101, $e->getCode(), 'Improper exception code.'); + } + } + + public function testSilentPort() + { + try { + $routerOS = new Client(HOSTNAME, USERNAME, PASSWORD, PORT_SILENT); + + $this->fail( + 'No proper connection over port "' + . PORT_SILENT + . '" should be available.' + ); + } catch (T\SocketException $e) { + $this->assertEquals(7, $e->getCode()); + $this->assertEquals(10061, $e->getSocketErrorNumber()); + } + } + + public function testInvalidTimeout() + { + try { + $routerOS = new Client( + HOSTNAME, USERNAME, PASSWORD, PORT, false, 'invalidTimeout' + ); + + $this->fail('No proper connection should be available.'); + } catch (T\SocketException $e) { + $this->assertEquals(7, $e->getCode()); + } + } + + public function testInvalidContextNotResource() + { + try { + $routerOS = new Client( + HOSTNAME, USERNAME, PASSWORD, PORT_SILENT, false, null, + 'notContext' + ); + + $this->fail('No proper connection should be available.'); + } catch (T\SocketException $e) { + $this->assertEquals(6, $e->getCode()); + } + } + + public function testInvalidContextInvalidResource() + { + try { + $routerOS = new Client( + HOSTNAME, USERNAME, PASSWORD, PORT_SILENT, false, null, + fopen(__FILE__, 'a+') + ); + + $this->fail('No proper connection should be available.'); + } catch (T\SocketException $e) { + $this->assertEquals(6, $e->getCode()); + } + } + + public function testInvalidSocketOnClose() + { + try { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + $com->close(); + new Response($com); + $this->fail('Receiving had to fail.'); + } catch (SocketException $e) { + $this->assertEquals(206, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidSocketOnReceive() + { + try { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + new Response($com); + $this->fail('Receiving had to fail.'); + } catch (T\SocketException $e) { + $this->assertEquals(4, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidSocketOnStreamReceive() + { + try { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + new Response($com, true); + $this->fail('Receiving had to fail.'); + } catch (T\SocketException $e) { + $this->assertEquals(4, $e->getCode(), 'Improper exception code.'); + } + } + + public function testInvalidQuerySending() + { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + $com->sendWord('/ip/arp/print'); + $com->close(); + try { + Query::where('address', HOSTNAME_INVALID)->send($com); + $com->sendWord(''); + $this->fail('The query had to fail.'); + } catch (SocketException $e) { + $this->assertEquals(209, $e->getCode(), 'Improper exception code.'); + } + } + +} \ No newline at end of file diff --git a/tests/PseudoServer.php b/tests/PseudoServer.php new file mode 100644 index 0000000..640c467 --- /dev/null +++ b/tests/PseudoServer.php @@ -0,0 +1,279 @@ + 1) { + die("The pseudo server needs to run as a separate executable."); +} + +ini_set('memory_limit', -1); + +function hex2bin($hex, $raw = false) +{ + $result = ''; + $length = strlen($hex); + if ($raw) { + for ($i = 0; $i < $length; $i++) { + $result .= str_pad(dechex(ord($hex[$i])), 2, '0', STR_PAD_LEFT); + } + return hex2bin($result); + } elseif (preg_match('/^([0-9]|[A-F])+$/i', $hex)) { + for ($i = 0; $i < $length; $i++) { + $result .= str_pad(decbin(hexdec($hex[$i])), 4, '0', STR_PAD_LEFT); + } + return $result; + } else { + return false; + } +} + +$configName = __DIR__ . DIRECTORY_SEPARATOR . 'configuration.xml'; +$configLocation = realpath($configName); +if ($configLocation === false) { + die( + "Configuration file not found. It needs to be in the same directory as + this file and be called '{$configName}'." + ); +} +$config = new DOMDocument(); +try { + $config->load($configLocation); + $configXPath = new DOMXPath($config); + $port = $configXPath->query( + '/phpunit/php/const[@name="PSEUDO_SERVER_PORT"][last()]/@value' + )->item(0)->nodeValue; +} catch (Exception $e) { + die("Failed parsing configuration."); +} + +require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . + '../src/PEAR2/Net/RouterOS/Communicator.php') + ? : 'PEAR2/Net/RouterOS/Communicator.php'; + +$socket = @stream_socket_server("tcp://127.0.0.1:{$port}", $errno, $errstr); +if (!is_resource($socket)) { + die("Failed to start server...\n{$errno}: {$errstr}"); +} +echo "Server started...\n"; +//define('SERVER_BUFFER', 512 +// * 1024 //k +// * 1024 //m +//); +define('PSEUDO_SERVER_CONNECTION_TIMEOUT', 2 + * 60//m + * 60//h +); +while ($conn = @stream_socket_accept($socket, 4 * 60, $peername)) { + //stream_set_blocking($conn, 1); + $hostPortCombo = explode(':', $peername); + if ($hostPortCombo[0] === '127.0.0.1') { + echo "Connected with {$peername}...\n"; + echo "Creating temporary storage...\n"; + $requestBuffer = fopen('php://temp', 'r+b'); + stream_set_read_buffer($conn, 11); + stream_set_timeout($conn, PSEUDO_SERVER_CONNECTION_TIMEOUT); + echo "Receving...\n"; + $specialCommand = false; + $num = 0; + $rq = 1; + do { + $content = fread($conn, 11); + $contentLength = strlen($content); + if (0 !== $contentLength) { + fwrite($requestBuffer, $content); + } + if (ftell($requestBuffer) > 10) { + echo "Dealing with request {$rq}...\n"; + $rbPos = ftell($requestBuffer); + fseek($requestBuffer, 0, SEEK_SET); + $raw = substr(fread($requestBuffer, 11), 1); + var_dump($raw); + + echo "Normalizing the buffer...\n"; + $remains = stream_get_contents($requestBuffer, -1, -1); + rewind($requestBuffer); + ftruncate($requestBuffer, 0); + fwrite($requestBuffer, $remains); + + if (strpos($raw, 'q') === 0) { + echo "User requested termination.\n"; + break; + } elseif (strpos($raw, 'c') === 0) { + echo "Control byte test.\n"; + $controlByteToSend = substr($raw, 1, 2); + $resLength = pack('C', hexdec($controlByteToSend)); + $resLengthSize = strlen($resLength); + $sent = $lengthBytesSent = 0; + while ($lengthBytesSent < $resLengthSize) { + $lengthBytesSent += fwrite($conn, + substr($resLength, $lengthBytesSent)); + $sent += $lengthBytesSent; + echo "{$sent} bytes in total sent for this request.\n"; + } + } elseif (strpos($raw, 's') === 0) { + echo "Request sending test.\n"; + $nextRequestBuffer = fopen('php://temp', 'r+b'); + $incomingRequestLength = (double) base_convert( + substr($raw, 1), 16, 10 + ); + fwrite($nextRequestBuffer, $remains); + fseek($requestBuffer, 0, SEEK_SET); + ftruncate($requestBuffer, 0); + fseek($nextRequestBuffer, 0, SEEK_END); + + $lengthBytePortionLength = strlen( + ROS\Communicator::encodeLength( + $incomingRequestLength + ) + ); + $incomingBytes = $lengthBytePortionLength + + $incomingRequestLength; + $bytesReceived = ftell($nextRequestBuffer); + var_dump($bytesReceived); + while ($bytesReceived < $incomingBytes) { + $bytesReceivedNow = fwrite($nextRequestBuffer, + fread($conn, + min($incomingBytes, 0xFFFFF))); + if (0 !== $bytesReceivedNow) { + $bytesReceived += $bytesReceivedNow; + echo "{$bytesReceived} bytes received in total for this request.\n"; + } + } + echo "Done receiving.\n"; + + $response = base_convert($bytesReceived + - $lengthBytePortionLength, 10, 16 + ); + var_dump($response); + $responseBytes = strlen($response); + $responseLengthPortion = ROS\Communicator:: + encodeLength( + $responseBytes + ); + $responseBytes += strlen($responseLengthPortion); + $rawResponse = $responseLengthPortion . $response; + $sentBytes = 0; + while ($sentBytes < $responseBytes) { + $sentNow = fwrite($conn, + substr($rawResponse, $sentBytes)); + if (0 !== $sentNow) { + $sentBytes += $sentNow; + echo "{$sentBytes} bytes sent in total for this request.\n"; + } + } + } elseif (strpos($raw, 'r') === 0) { + echo "Response returning test.\n"; + $length = (double) base_convert(substr($raw, 1), 16, 10); + var_dump($length); + + $resLength = ROS\Communicator::encodeLength( + $length + ); + $resLengthSize = strlen($resLength); + var_dump(hex2bin($resLength, true)); + $sent = $lengthBytesSent = 0; + while ($lengthBytesSent < $resLengthSize) { + $lengthBytesSent += fwrite($conn, + substr($resLength, $lengthBytesSent)); + $sent += $lengthBytesSent; + echo "{$sent} bytes in total sent for this request.\n"; + } + $resLengthSent = 0; + while ($resLengthSent < $length) { + $resLengthSentNow = fwrite( + $conn, + str_pad('t', min(0xFFFFF, $length - $resLengthSent), + 't' + ) + ); + if (0 !== $resLengthSentNow) { + $resLengthSent += $resLengthSentNow; + $sent = $resLengthSize + $resLengthSent; + echo "{$sent} bytes in total sent for this request.\n"; + } + } + } elseif (strpos($raw, 'i') === 0) { + echo "Incomplete response test.\n"; + $length = (double) base_convert(substr($raw, 1), 16, 10); + var_dump($length); + + $resLength = ROS\Communicator::encodeLength( + $length + ); + $resLengthSize = strlen($resLength); + $sent = $lengthBytesSent = 0; + while ($lengthBytesSent < $resLengthSize) { + $lengthBytesSent += fwrite($conn, + substr($resLength, $lengthBytesSent)); + $sent += $lengthBytesSent; + echo "{$sent} bytes in total sent for this request.\n"; + } + fflush($conn); + $resLengthSent = 0; + while ($resLengthSent < $length - 1/* missing byte */) { + $resLengthSentNow = fwrite($conn, + str_pad('t', + min(0xFFFFF, + $length + - $resLengthSent + - 1/* missing byte */ + ), 't' + ) + ); + if (0 !== $resLengthSentNow) { + $resLengthSent += $resLengthSentNow; + $sent = $resLengthSize + $resLengthSent; + echo "{$sent} bytes in total sent for this request.\n"; + } + } + break; + } elseif (strpos($raw, 'p') === 0) { + echo "Premature disconnect test.\n"; + $nextRequestBuffer = fopen('php://temp', 'r+b'); + $incomingRequestLength = (double) base_convert( + substr($raw, 1), 16, 10 + ); + fwrite($nextRequestBuffer, $remains); + fseek($requestBuffer, 0, SEEK_SET); + ftruncate($requestBuffer, 0); + fseek($nextRequestBuffer, 0, SEEK_END); + + $lengthBytePortionLength = strlen( + ROS\Communicator::encodeLength( + $incomingRequestLength + ) + ); + $incomingBytes = $lengthBytePortionLength + + $incomingRequestLength; + $bytesReceived = ftell($nextRequestBuffer); + var_dump($bytesReceived); + $incomingBytes /= 4; //Receive only 1/4 of the request. + while ($bytesReceived < $incomingBytes) { + $bytesReceivedNow = fwrite($nextRequestBuffer, + fread($conn, + min($incomingBytes, 0xFFFFF))); + if (0 !== $bytesReceivedNow) { + $bytesReceived += $bytesReceivedNow; + echo "{$bytesReceived} bytes received in total for this request.\n"; + } + } + //sleep(5); + break; + } + echo "Done dealing with request {$rq}.\n"; + $rq++; + } + $meta = stream_get_meta_data($conn); + } while (!$meta['timed_out']); + echo "Terminating connection with {$peername}...\n"; + fclose($conn); + echo "Done!\n"; + continue; + //} + } else { + echo "Access attempt from {$peername}\n"; + } +} +echo "Closing server...\n"; +fclose($socket); +echo "Closed"; +?> diff --git a/tests/RequestHandlingTest.php b/tests/RequestHandlingTest.php new file mode 100644 index 0000000..a1e9cec --- /dev/null +++ b/tests/RequestHandlingTest.php @@ -0,0 +1,649 @@ +assertEquals( + 202, $e->getCode(), + "Improper exception thrown for the command '{$command}'." + ); + } + } + } + + public function testUnresolvableCommand() + { + $unresolvableCommands = array( + '/ip .. ..', + '/ip .. arp .. arp .. .. print' + ); + foreach ($unresolvableCommands as $command) { + try { + $invalidCommand = new Request($command); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 203, $e->getCode(), + "Improper exception thrown for the command '{$command}'." + ); + } + } + } + + public function testInvalidCommand() + { + $invalidCommands = array( + '/ip/arp/ print', + '/ip /arp /print', + '/ip /arp /print', + ); + foreach ($invalidCommands as $command) { + try { + $invalidCommand = new Request($command); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 204, $e->getCode(), + "Improper exception thrown for the command '{$command}'." + ); + } + } + } + + public function testCommandTranslation() + { + $commands = array( + '/ip arp print' => '/ip/arp/print', + '/ip arp .. address print' => '/ip/address/print', + '/queue simple .. tree .. simple print' => '/queue/simple/print', + '/login goback ..' => '/login' + ); + $request = new Request('/cancel'); + foreach ($commands as $command => $expected) { + $request->setCommand($command); + $this->assertEquals( + $expected, $request->getCommand(), + "Command '{$command}' was not translated properly." + ); + } + } + + public function testInvalidArgumentName() + { + $invalidNames = array( + '=', + '', + '=eqStart', + 'eq=middle', + 'eqEnd=', + 'name spaced', + 'name with multiple spaces', + "Two\nLines" + ); + foreach ($invalidNames as $name) { + try { + $request = new Request('/ping'); + $request->setArgument($name); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 200, $e->getCode(), + "Improper exception thrown for the name '{$name}'." + ); + } + } + } + + public function testInvalidArgumentValue() + { + $invalidValues = array( + fopen('php://input', 'r') + ); + foreach ($invalidValues as $value) { + try { + $request = new Request('/ping'); + $request->setArgument('address', $value); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 201, $e->getCode(), + "Improper exception thrown for the value '{$value}'." + ); + } + } + } + + public function testInvalidQueryArgumentName() + { + $invalidNames = array( + '=', + '', + '=eqStart', + 'eq=middle', + 'eqEnd=', + 'name spaced', + 'name with multiple spaces', + "Two\nLines" + ); + foreach ($invalidNames as $name) { + try { + $query = Query::where($name); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 200, $e->getCode(), + "Improper exception thrown for the name '{$name}'." + ); + } + } + } + + public function testInvalidQueryArgumentAction() + { + $invalidActions = array( + ' ', + '?', + '#', + 'address', + '>=', + '<=', + '=>', + '=<', + 1, + 0 + ); + foreach ($invalidActions as $action) { + try { + $query = Query::where('address', null, $action); + } catch (UnexpectedValueException $e) { + $this->assertEquals( + 208, $e->getCode(), + "Improper exception thrown for the action '{$action}'." + ); + $this->assertEquals($action, $e->getValue()); + } + } + } + + public function testInvalidQueryArgumentValue() + { + $invalidValues = array( + fopen('php://input', 'r') + ); + foreach ($invalidValues as $value) { + try { + $query = Query::where('address', $value); + } catch (InvalidArgumentException $e) { + $this->assertEquals( + 201, $e->getCode(), + "Improper exception thrown for the value '{$value}'." + ); + } + } + } + + public function testArgumentRemoval() + { + $request = new Request('/ip/arp/add'); + $this->assertEmpty($request->getAllArguments()); + + $request->setArgument('address', HOSTNAME_INVALID); + $this->assertNotEmpty($request->getAllArguments()); + $this->assertEquals(HOSTNAME_INVALID, $request->getArgument('address')); + + $request->removeAllArguments(); + $this->assertEmpty($request->getAllArguments()); + $this->assertEquals(null, $request->getArgument('address')); + } + + public function testLengthEncoding() + { + $lengths = array( + chr(0) => 0, + chr(0x1) => 0x1, + chr(0x7E) => 0x7E, + chr(0x7F) => 0x7F, + chr(0x80) . chr(0x80) => 0x80, + chr(0x80) . chr(0x81) => 0x81, + chr(0xBF) . chr(0xFE) => 0x3FFE, + chr(0xBF) . chr(0xFF) => 0x3FFF, + chr(0xC0) . chr(0x40) . chr(0x00) => 0x4000, + chr(0xC0) . chr(0x40) . chr(0x01) => 0x4001, + chr(0xDF) . chr(0xFF) . chr(0xFE) => 0x1FFFFE, + chr(0xDF) . chr(0xFF) . chr(0xFF) => 0x1FFFFF, + chr(0xE0) . chr(0x20) . chr(0x00) . chr(0x00) => 0x200000, + chr(0xE0) . chr(0x20) . chr(0x00) . chr(0x01) => 0x200001, + chr(0xEF) . chr(0xFF) . chr(0xFF) . chr(0xFE) => 0xFFFFFFE, + chr(0xEF) . chr(0xFF) . chr(0xFF) . chr(0xFF) => 0xFFFFFFF, + chr(0xF0) . chr(0x10) . chr(0x00) . chr(0x00) . chr(0x00) => + 0x10000000, + chr(0xF0) . chr(0x10) . chr(0x00) . chr(0x00) . chr(0x01) => + 0x10000001, + chr(0xF0) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFE) => + 0xFFFFFFFE, + chr(0xF0) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) => + 0xFFFFFFFF, + chr(0xF1) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00) => + 0x100000000, + chr(0xF1) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x01) => + 0x100000001, + chr(0xF7) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFE) + => 0x7FFFFFFFE, + chr(0xF7) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) + => 0x7FFFFFFFF + ); + foreach ($lengths as $expected => $length) { + $actual = Communicator::encodeLength($length); + $this->assertEquals( + $expected, $actual, + "Length '0x" . dechex($length) . + "' is not encoded correctly. It was encoded as '0x" . + bin2hex($actual) . "' instead of '0x" . + bin2hex($expected) . "'." + ); + } + } + + public function testLengthEncodingExceptions() + { + $smallLength = -1; + try { + Communicator::encodeLength($smallLength); + } catch (LengthException $e) { + $this->assertEquals( + 11, $e->getCode(), + "Length '{$smallLength}' must not be encodable." + ); + $this->assertEquals( + $smallLength, $e->getLength(), 'Exception is misleading.' + ); + } + $largeLength = 0x800000000; + try { + Communicator::encodeLength($largeLength); + } catch (LengthException $e) { + $this->assertEquals( + 12, $e->getCode(), + "Length '{$largeLength}' must not be encodable." + ); + $this->assertEquals( + $largeLength, $e->getLength(), 'Exception is misleading.' + ); + } + } + + public function testControlByteException() + { + $stream = fopen('php://temp', 'r+b'); + + + $controlBytes = array( + 0xF8, + 0xF9, + 0xFA, + 0xFB, + 0xFC, + 0xFD, + 0xFE, + 0xFF + ); + + foreach ($controlBytes as $controlByte) { + fwrite($stream, chr($controlByte)); + } + rewind($stream); + $trans = new T\StreamTransmitter($stream); + + foreach ($controlBytes as $controlByte) { + try { + Communicator::decodeLength($trans); + } catch (NotSupportedException $e) { + $this->assertEquals( + 13, $e->getCode(), 'Improper exception code.' + ); + $this->assertEquals( + $controlByte, $e->getValue(), 'Improper exception value.' + ); + } + } + } + + public function testLengthDecoding() + { + $lengths = array( + chr(0) => 0, + chr(0x1) => 0x1, + chr(0x7E) => 0x7E, + chr(0x7F) => 0x7F, + chr(0x80) . chr(0x80) => 0x80, + chr(0x80) . chr(0x81) => 0x81, + chr(0xBF) . chr(0xFE) => 0x3FFE, + chr(0xBF) . chr(0xFF) => 0x3FFF, + chr(0xC0) . chr(0x40) . chr(0x00) => 0x4000, + chr(0xC0) . chr(0x40) . chr(0x01) => 0x4001, + chr(0xDF) . chr(0xFF) . chr(0xFE) => 0x1FFFFE, + chr(0xDF) . chr(0xFF) . chr(0xFF) => 0x1FFFFF, + chr(0xE0) . chr(0x20) . chr(0x00) . chr(0x00) => 0x200000, + chr(0xE0) . chr(0x20) . chr(0x00) . chr(0x01) => 0x200001, + chr(0xEF) . chr(0xFF) . chr(0xFF) . chr(0xFE) => 0xFFFFFFE, + chr(0xEF) . chr(0xFF) . chr(0xFF) . chr(0xFF) => 0xFFFFFFF, + chr(0xF0) . chr(0x10) . chr(0x00) . chr(0x00) . chr(0x00) => + 0x10000000, + chr(0xF0) . chr(0x10) . chr(0x00) . chr(0x00) . chr(0x01) => + 0x10000001, + chr(0xF0) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFE) => + 0xFFFFFFFE, + chr(0xF0) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) => + 0xFFFFFFFF, + chr(0xF1) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00) => + 0x100000000, + chr(0xF1) . chr(0x00) . chr(0x00) . chr(0x00) . chr(0x01) => + 0x100000001, + chr(0xF7) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFE) + => 0x7FFFFFFFE, + chr(0xF7) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) + => 0x7FFFFFFFF + ); + $stream = fopen('php://temp', 'r+b'); + foreach ($lengths as $length) { + fwrite($stream, Communicator::encodeLength($length)); + } + rewind($stream); + $trans = new T\StreamTransmitter($stream); + + foreach ($lengths as $length => $expected) { + $this->assertEquals( + $expected, Communicator::decodeLength($trans), + "{$length} is not properly decoded." + ); + } + } + + public function testQuitMessage() + { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + $quitRequest = new Request('/quit'); + $quitRequest->send($com); + $quitResponse = new Response($com); + $this->assertEquals( + 1, count($quitResponse->getUnrecognizedWords()), 'No message.' + ); + $this->assertEquals( + 0, count($quitResponse->getAllArguments()), + 'There should be no arguments.' + ); + $com->close(); + } + + public function testQuitMessageStream() + { + $com = new Communicator(HOSTNAME, PORT); + Client::login($com, USERNAME, PASSWORD); + + $quitRequest = new Request('/quit'); + $quitRequest->send($com); + $quitResponse = new Response($com, true); + $this->assertEquals( + 1, count($quitResponse->getUnrecognizedWords()), 'No message.' + ); + $this->assertEquals( + 0, count($quitResponse->getAllArguments()), + 'There should be no arguments.' + ); + $com->close(); + } + + public function testSetDefaultCharset() + { + $com = new Communicator(HOSTNAME, PORT); + $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE)); + $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL)); + Communicator::setDefaultCharset('windows-1251'); + $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE)); + $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL)); + + $com = new Communicator(HOSTNAME, PORT); + $this->assertEquals( + 'windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertEquals( + 'windows-1251', $com->getCharset(Communicator::CHARSET_LOCAL) + ); + Communicator::setDefaultCharset( + array( + Communicator::CHARSET_REMOTE => 'ISO-8859-1', + Communicator::CHARSET_LOCAL => 'ISO-8859-1' + ) + ); + $this->assertEquals( + 'windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertEquals( + 'windows-1251', $com->getCharset(Communicator::CHARSET_LOCAL) + ); + + $com = new Communicator(HOSTNAME, PORT); + $this->assertEquals( + 'ISO-8859-1', $com->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertEquals( + 'ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL) + ); + Communicator::setDefaultCharset(null); + $this->assertEquals( + 'ISO-8859-1', $com->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertEquals( + 'ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL) + ); + + $com = new Communicator(HOSTNAME, PORT); + $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE)); + $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL)); + Communicator::setDefaultCharset( + 'windows-1251', Communicator::CHARSET_REMOTE + ); + Communicator::setDefaultCharset( + 'ISO-8859-1', Communicator::CHARSET_LOCAL + ); + $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE)); + $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL)); + + $com = new Communicator(HOSTNAME, PORT); + $this->assertEquals( + 'windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE) + ); + $this->assertEquals( + 'ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL) + ); + Communicator::setDefaultCharset(null); + } + + public function testReceivingLargeWords() + { + try { + $com = new Communicator('127.0.0.1', PSEUDO_SERVER_PORT); + } catch (\Exception $e) { + $this->markTestSkipped('The testing server is not running.'); + } + + + $lengths = array( + 0x1, + 0x7E, + 0x7F, + 0x80, + 0x81, + 0x3FFE, + 0x3FFF, + 0x4000, + 0x4001, + 0x1FFFFE, + 0x1FFFFF, + 0x200000, + 0x200001, + 0xFFFFFFE, + 0xFFFFFFF, + 0x10000000, + //0x10000001, + //0xFFFFFFFE, + //0xFFFFFFFF, + //0x100000000, + //0x100000001, + //0x7FFFFFFFE, + //0x7FFFFFFFF + ); + + foreach ($lengths as $length) { + + $com->sendWord( + 'r' . + str_pad(base_convert($length, 10, 16), 9, '0', STR_PAD_LEFT) + ); + $response = $com->getNextWordAsStream(); + + $responseSize = 0; + while (!feof($response)) { + $responseSize += strlen(fread($response, 0xFFFFF)); + } + $this->assertEquals( + $length, $responseSize, 'Content mismatch!' + ); + } + + $com->sendWord('q000000000'); + $com->close(); + } + + public function testSendingLargeWords() + { + try { + $com = new Communicator('127.0.0.1', PSEUDO_SERVER_PORT); + } catch (\Exception $e) { + $this->markTestSkipped('The testing server is not running.'); + } + + $lengths = array( + 0x1, + 0x7E, + 0x7F, + 0x80, + 0x81, + 0x3FFE, + 0x3FFF, + 0x4000, + 0x4001, + 0x1FFFFE, + 0x1FFFFF, + 0x200000, + 0x200001, + 0xFFFFFFE, + 0xFFFFFFF, + //0x10000000, + //0x10000001, + //0xFFFFFFFE, + //0xFFFFFFFF, + //0x100000000, + //0x100000001, + //0x7FFFFFFFE, + //0x7FFFFFFFF + ); + + foreach ($lengths as $length) { + + $com->sendWord( + 's' . + str_pad(base_convert($length, 10, 16), 9, '0', STR_PAD_LEFT) + ); + + $stream = fopen('php://temp', 'r+b'); + $streamSize = 0; + while ($streamSize < $length) { + $streamSize += fwrite( + $stream, + str_pad('t', min($length - $streamSize, 0xFFFFF), 't') + ); + } + rewind($stream); + + $com->sendWordFromStream('', $stream); + + $recvLength = (double) base_convert($com->getNextWord(), 16, 10); + $this->assertEquals( + (double) $length, $recvLength, 'Content mismatch!' + ); + } + + $com->sendWord('q000000000'); + $com->close(); + } + + public function testPrematureDisconnect() + { + try { + $com = new Communicator('127.0.0.1', PSEUDO_SERVER_PORT); + } catch (\Exception $e) { + $this->markTestSkipped('The testing server is not running.'); + } + + $com->sendWord('p0000fffff'); + try { + $com->sendWord(str_pad('t', 0xFFFFF, 't')); + $this->fail('Sending had to fail.'); + } catch (SocketException $e) { + $this->assertEquals(2, $e->getCode(), 'Improper exception code.'); + } + } + + public function testPrematureDisconnectWithStream() + { + try { + $com = new Communicator('127.0.0.1', PSEUDO_SERVER_PORT); + } catch (\Exception $e) { + $this->markTestSkipped('The testing server is not running.'); + } + + $com->sendWord('p0000fffff'); + try { + $stream = fopen('php://temp', 'r+b'); + fwrite($stream, str_pad('t', 0xFFFFF, 't')); + rewind($stream); + $com->sendWordFromStream('', $stream); + $this->fail('Sending had to fail.'); + } catch (SocketException $e) { + $this->assertEquals(3, $e->getCode(), 'Improper exception code.'); + } + } + + public function testIncompleteResponse() + { + try { + $com = new Communicator('127.0.0.1', PSEUDO_SERVER_PORT); + } catch (\Exception $e) { + $this->markTestSkipped('The testing server is not running.'); + } + $oldTimeout = ini_set('default_socket_timeout', 2); + $com->sendWord('i00000000f'); + try { + $response = $com->getNextWordAsStream(); + ini_set('default_socket_timeout', $oldTimeout); + $this->fail('Receiving had to fail.'); + } catch (SocketException $e) { + ini_set('default_socket_timeout', $oldTimeout); + $this->assertEquals(5, $e->getCode(), 'Improper exception code.'); + } + } + +} \ No newline at end of file diff --git a/tests/StateAlteringFeaturesTest.php b/tests/StateAlteringFeaturesTest.php new file mode 100644 index 0000000..29cd3b2 --- /dev/null +++ b/tests/StateAlteringFeaturesTest.php @@ -0,0 +1,430 @@ +object = new Client(HOSTNAME, USERNAME, PASSWORD, PORT); + } + + protected function tearDown() + { + unset($this->object); + } + + public function testMultipleDifferentPersistentConnection() + { + try { + + $routerOS1 = new Client(HOSTNAME, USERNAME2, PASSWORD2, PORT, true); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS1, + 'Object initialization failed.' + ); + + $routerOS2 = new Client(HOSTNAME, USERNAME, PASSWORD, PORT, true); + $this->assertInstanceOf( + __NAMESPACE__ . '\Client', $routerOS2, + 'Object initialization failed.' + ); + + + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $responses = $routerOS2->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getType() === Response::TYPE_FINAL + ) { + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $routerOS2->sendSync($removeRequest); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $responses, + 'Response should be one.' + ); + } + + $routerOS1->close(); + $routerOS2->close(); + } catch (Exception $e) { + $this->fail('Unable to connect normally.'); + } + } + + public function testSendSyncReturningCollectionWithOneResponse() + { + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($removeRequest); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $responses, + 'Responses should be a collection.' + ); + $this->assertEquals( + 1, count($responses), + 'Response should be one.' + ); + unset($responses[0]); + $this->assertEquals( + 1, count($responses), + 'Response should be one, even after attempted unsetting.' + ); + $responses[] = 'my attachment'; + $this->assertEquals( + 1, count($responses), + 'Response should be one, even after attempted setting.' + ); + } + } + + public function testSendSyncReturningResponseStreamData() + { + + $comment = fopen('php://temp', 'r+b'); + fwrite($comment, str_pad('t', 0xFFF, 't')); + rewind($comment); + + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $addRequest->setArgument('comment', $comment); + $responses = $this->object->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($removeRequest); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $responses, + 'Response should be one.' + ); + } + } + + public function testSendSyncReturningResponseLarge3bytesLength() + { + $this->markTestIncomplete( + 'For some reason, my RouterOS v5.6 doesn not work with this (bug?).' + ); + $systemResource = $this->object->sendSync( + new Request('/system/resource/print') + ); + $this->assertEquals(2, count($systemResource)); + $freeMemory = 1024 + * (int) $systemResource[0]->getArgument('free-memory'); + + $addCommand = '/queue/simple/add'; + $requiredMemory = 0x4000 + + strlen($addCommand) + 1 + + strlen('=name=') + strlen(TEST_QUEUE_NAME) + 1 + + strlen('=comment=') + 1 + + (8 * 1024 * 1024) /* 8MiB for processing's sake */; + if ($freeMemory < $requiredMemory) { + $this->markTestSkipped('Not enough memory on router.'); + } else { + $comment = fopen('php://temp', 'r+b'); + fwrite( + $comment, str_pad('t', 0x4000 - strlen('=comment=') + 1, 't') + ); + rewind($comment); + + $addRequest = new Request($addCommand); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $addRequest->setArgument('comment', $comment); + $responses = $this->object->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($removeRequest); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $responses, + 'Response should be one.' + ); + } + } + } + + public function testSendSyncReturningResponseLarge4bytesLength() + { + $this->markTestIncomplete( + 'For some reason, my RouterOS v5.6 doesn not work with this (bug?).' + ); + $systemResource = $this->object->sendSync( + new Request('/system/resource/print') + ); + $this->assertEquals(2, count($systemResource)); + $freeMemory = 1024 + * (int) $systemResource[0]->getArgument('free-memory'); + + $addCommand = '/queue/simple/add'; + $requiredMemory = 0x200000 + + strlen($addCommand) + 1 + + strlen('=name=') + strlen(TEST_QUEUE_NAME) + 1 + + strlen('=comment=') + 1 + + (8 * 1024 * 1024) /* 8MiB for processing's sake */; + if ($freeMemory < $requiredMemory) { + $this->markTestSkipped('Not enough memory on router.'); + } else { + $comment = fopen('php://temp', 'r+b'); + fwrite( + $comment, str_pad('t', 0x200000 - strlen('=comment=') + 1, 't') + ); + rewind($comment); + + $addRequest = new Request($addCommand); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $addRequest->setArgument('comment', $comment); + $responses = $this->object->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($removeRequest); + $this->assertInstanceOf( + __NAMESPACE__ . '\ResponseCollection', $responses, + 'Response should be one.' + ); + } + } + } + + public function testSendSyncReturningResponseLargeDataException() + { + //Required for this test + $memoryLimit = ini_set('memory_limit', -1); + try { + + $comment = fopen('php://temp', 'r+b'); + fwrite($comment, str_pad('t', 0xFFFFFF, 't')); + for ($i = 0; $i < 14; $i++) { + fwrite($comment, str_pad('t', 0xFFFFFF, 't')); + } + fwrite( + $comment, + str_pad('t', 0xFFFFFF + 0xF/* - strlen('=comment=') */, 't') + ); + rewind($comment); + + $commentString = stream_get_contents($comment); + $maxArgL = 0xFFFFFFF - strlen('=comment='); + $this->assertGreaterThan( + $maxArgL, strlen($commentString), '$comment is not long enough.' + ); + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $addRequest->setArgument('comment', $commentString); + $responses = $this->object->sendSync($addRequest); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $response = $this->object->sendSync($removeRequest); + } + + $this->fail('Lengths above 0xFFFFFFF should not be supported.'); + } catch (LengthException $e) { + $this->assertEquals( + 10, $e->getCode(), 'Improper exception thrown.' + ); + } + + //Clearing out for other tests. + ini_set('memory_limit', $memoryLimit); + } + + public function testResponseCollectionGetArgumentMap() + { + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($addRequest); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + $printRequest = new Request('/queue/simple/print'); + $printRequest->setArgument('.proplist', 'name,target-addresses'); + $printRequest->setQuery( + Query::where('name', TEST_QUEUE_NAME) + ->orWhere('target-addresses', HOSTNAME_INVALID . '/32') + ); + $responses = $this->object->sendSync($printRequest); + $this->assertEquals( + array('name' => array(0, 1), 'target-addresses' => array(0)), + $responses->getArgumentMap(), + 'Improper format of the returned array' + ); + + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $response = $this->object->sendSync($removeRequest); + } + } + + public function testSetCharset() + { + if (!extension_loaded('iconv') || !function_exists('iconv')) { + $this->markTestSkipped('iconv is not enabled.'); + } + $this->assertEquals( + array( + Communicator::CHARSET_REMOTE => null, + Communicator::CHARSET_LOCAL => null + ), + $this->object->setCharset( + array( + Communicator::CHARSET_REMOTE => 'windows-1251', + Communicator::CHARSET_LOCAL => 'UTF-8' + ) + ) + ); + + + $addRequest = new Request('/queue/simple/add'); + $addRequest->setArgument('name', TEST_QUEUE_NAME); + $addRequest->setArgument('comment', 'ПРИМЕР'); + $responses = $this->object->sendSync($addRequest); + $this->assertEquals( + 1, count($responses), 'There should be only one response.' + ); + if (count($responses) === 1 + && $responses->getLast()->getType() === Response::TYPE_FINAL + ) { + $appropriateCharsets = $this->object->setCharset( + array( + Communicator::CHARSET_REMOTE => 'ISO-8859-1', + Communicator::CHARSET_LOCAL => 'UTF-8' + ) + ); + $printRequest = new Request('/queue/simple/print'); + $printRequest->setQuery(Query::where('name', TEST_QUEUE_NAME)); + $responses = $this->object->sendSync($printRequest); + + $this->assertEquals( + TEST_QUEUE_NAME, $responses[0]->getArgument('name') + ); + $this->assertNotEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $this->object->setCharset($appropriateCharsets); + $this->assertNotEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $responses = $this->object->sendSync($printRequest); + + $this->assertEquals( + TEST_QUEUE_NAME, $responses[0]->getArgument('name') + ); + $this->assertEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $this->object->setCharset( + 'ISO-8859-1', Communicator::CHARSET_REMOTE + ); + $responses = $this->object->sendSync($printRequest); + $this->assertNotEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $this->object->setCharset( + 'ISO-8859-1', Communicator::CHARSET_LOCAL + ); + $responses = $this->object->sendSync($printRequest); + $this->assertNotEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $this->object->setCharset($appropriateCharsets); + $responses = $this->object->sendSync($printRequest); + $this->assertEquals( + 'ПРИМЕР', $responses[0]->getArgument('comment') + ); + + $this->object->setStreamResponses(true); + $responses = $this->object->sendSync($printRequest); + $this->assertEquals( + 'ПРИМЕР', stream_get_contents( + $responses[0]->getArgument('comment') + ) + ); + $this->object->setCharset( + 'ISO-8859-1', Communicator::CHARSET_REMOTE + ); + $responses = $this->object->sendSync($printRequest); + $this->assertNotEquals( + 'ПРИМЕР', stream_get_contents( + $responses[0]->getArgument('comment') + ) + ); + $this->object->setCharset('windows-1251'); + $responses = $this->object->sendSync($printRequest); + $this->assertNotEquals( + 'ПРИМЕР', stream_get_contents( + $responses[0]->getArgument('comment') + ) + ); + + $testQueueNameAsStream = fopen('php://temp', 'r+b'); + fwrite($testQueueNameAsStream, TEST_QUEUE_NAME); + rewind($testQueueNameAsStream); + $printRequest->setQuery( + Query::where('name', $testQueueNameAsStream) + ); + $responses = $this->object->sendSync($printRequest); + $this->assertNotEquals( + 'ПРИМЕР', stream_get_contents( + $responses[0]->getArgument('comment') + ) + ); + $this->object->setCharset($appropriateCharsets); + $responses = $this->object->sendSync($printRequest); + $this->assertEquals( + 'ПРИМЕР', stream_get_contents( + $responses[0]->getArgument('comment') + ) + ); + + + $removeRequest = new Request('/queue/simple/remove'); + $removeRequest->setArgument('numbers', TEST_QUEUE_NAME); + $responses = $this->object->sendSync($removeRequest); + } + } + +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..d2333c5 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ConnectionTest.php + RequestHandlingTest.php + ClientFeaturesTest.php + StateAlteringFeaturesTest.php + + + + + ../src/PEAR2/Net/RouterOS + + + \ No newline at end of file