initial commit

This commit is contained in:
Dan Bastone committed 2021-10-29 14:41:03 -04:00
commit 636959b37b
2474 files changed
+1343178

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,73 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_CONFIG_HPP__
#define __PJSUA2_CONFIG_HPP__
/**
* @file pjsua2/config.hpp
* @brief PJSUA2 Base Agent Operation
*/
#include <pjsua-lib/pjsua.h>
/**
* @defgroup PJSUA2_CFG_Compile Compile time settings
* @ingroup PJSUA2_DS
* @{
*/
/**
* Specify if the Error exception info should contain operation and source
* file information.
*/
#ifndef PJSUA2_ERROR_HAS_EXTRA_INFO
# define PJSUA2_ERROR_HAS_EXTRA_INFO 1
#endif
/**
* Maximum buffer length to print SDP content for SdpSession. Set this to 0
* if the printed SDP is not needed.
*/
#ifndef PJSUA2_MAX_SDP_BUF_LEN
# define PJSUA2_MAX_SDP_BUF_LEN 1024
#endif
/**
* Ticket #2189 described some lists of objects which is not thread safe.
* The ticket deprecated some APIs which uses those lists and introduce new one
* to replace them. This settings will disable the deprecated API all together.
* See also https://trac.pjsip.org/repos/ticket/2232
*/
#ifndef DEPRECATED_FOR_TICKET_2232
# define DEPRECATED_FOR_TICKET_2232 1
#endif
/*
* C++11 deprecated dynamic exception specification, but SWIG needs it.
*/
#ifndef SWIG
# define PJSUA2_THROW(x)
#else
# define PJSUA2_THROW(x) throw(x)
#endif
/**
* @} PJSUA2_CFG
*/
#endif /* __PJSUA2_CONFIG_HPP__ */
@@ -0,0 +1,52 @@
/* $Id$ */
/*
* Copyright (C) 2008-2012 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_DOXYGEN_HPP__
#define __PJSUA2_DOXYGEN_HPP__
/**
* @file pjsua2/doxygen.hpp
* @brief PJSUA2 Doxygen documentation
*/
/**
@mainpage pjsua2 API
This documentation contains the API Reference for pjsua2. Please
go to <b>Modules</b> section above for navigation.
For more info regarding pjsua2, including some tutorials, please
see The PJSIP Book.
*/
/**
* @defgroup PJSUA2_Ref pjsua2 API Reference
*/
/**
* @defgroup PJSUA2_DS Data Structure
* @ingroup PJSUA2_Ref
*/
/**
* @} PJSUA2_CFG
*/
#endif /* __PJSUA2_DOXYGEN_HPP__ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,116 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_JSON_HPP__
#define __PJSUA2_JSON_HPP__
/**
* @file pjsua2/persistent.hpp
* @brief PJSUA2 Persistent Services
*/
#include <pjsua2/persistent.hpp>
#include <pjlib-util/json.h>
#include <pj/pool.h>
#include <string>
/** PJSUA2 API is inside pj namespace */
namespace pj
{
/**
* @defgroup PJSUA2_JSON JSON Persistent Support
* @ingroup PJSUA2_PERSISTENT
* @{
* Provides object serialization and deserialization to/from JSON document.
*/
using std::string;
/**
* Persistent document (file) with JSON format.
*/
class JsonDocument : public PersistentDocument
{
public:
/** Default constructor */
JsonDocument();
/** Destructor */
~JsonDocument();
/**
* Load this document from a file.
*
* @param filename The file name.
*/
virtual void loadFile(const string &filename) PJSUA2_THROW(Error);
/**
* Load this document from string.
*
* @param input The string.
*/
virtual void loadString(const string &input) PJSUA2_THROW(Error);
/**
* Write this document to a file.
*
* @param filename The file name.
*/
virtual void saveFile(const string &filename) PJSUA2_THROW(Error);
/**
* Write this document to string.
*/
virtual string saveString() PJSUA2_THROW(Error);
/**
* Get the root container node for this document
*/
virtual ContainerNode & getRootContainer() const;
/**
* An internal function to create JSON element.
*/
pj_json_elem* allocElement() const;
/**
* An internal function to get the pool.
*/
pj_pool_t* getPool();
private:
pj_caching_pool cp;
mutable ContainerNode rootNode;
mutable pj_json_elem *root;
mutable pj_pool_t *pool;
void initRoot() const;
};
/**
* @} PJSUA2
*/
} // namespace pj
#endif /* __PJSUA2_JSON_HPP__ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,710 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_PERSISTENT_HPP__
#define __PJSUA2_PERSISTENT_HPP__
/**
* @file pjsua2/persistent.hpp
* @brief PJSUA2 Persistent Services
*/
#include <pjsua2/types.hpp>
#include <string>
#include <vector>
/** PJSUA2 API is inside pj namespace */
namespace pj
{
/**
* @defgroup PJSUA2_PERSISTENT Persistent API
* @ingroup PJSUA2_Ref
* @{
* The persistent API provides functionality to read/write data from/to
* a document (string or file). The data can be simple data types such
* as boolean, number, string, and string arrays, or a user defined object.
* Currently the implementation supports reading and writing from/to JSON
* document, but the framework allows application to extend the API to
* support other document formats.
*/
using std::string;
using std::vector;
/* Forward declaration for ContainerNode */
class ContainerNode;
/**
* This is the abstract base class of objects that can be serialized to/from
* persistent document.
*/
class PersistentObject
{
public:
/**
* Virtual destructor
*/
virtual ~PersistentObject()
{}
/**
* Read this object from a container node.
*
* @param node Container to read values from.
*/
virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error) = 0;
/**
* Write this object to a container node.
*
* @param node Container to write values to.
*/
virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error) = 0;
};
/**
* This a the abstract base class for a persistent document. A document
* is created either by loading from a string or a file, or by constructing
* it manually when writing data to it. The document then can be saved
* to either string or to a file. A document contains one root ContainerNode
* where all data are stored under.
*
* Document is read and written serially, hence the order of reading must be
* the same as the order of writing. The PersistentDocument class provides
* API to read and write to the root node, but for more flexible operations
* application can use the ContainerNode methods instead. Indeed the read
* and write API in PersistentDocument is just a shorthand which calls the
* relevant methods in the ContainerNode. As a tip, normally application only
* uses the readObject() and writeObject() methods declared here to read/write
* top level objects, and use the macros that are explained in ContainerNode
* documentation to read/write more detailed data.
*/
class PersistentDocument
{
public:
/**
* Virtual destructor
*/
virtual ~PersistentDocument()
{}
/**
* Load this document from a file.
*
* @param filename The file name.
*/
virtual void loadFile(const string &filename)
PJSUA2_THROW(Error) = 0;
/**
* Load this document from string.
*
* @param input The string.
*/
virtual void loadString(const string &input)
PJSUA2_THROW(Error) = 0;
/**
* Write this document to a file.
*
* @param filename The file name.
*/
virtual void saveFile(const string &filename)
PJSUA2_THROW(Error) = 0;
/**
* Write this document to string.
*
* @return The string document.
*/
virtual string saveString() PJSUA2_THROW(Error) = 0;
/**
* Get the root container node for this document
*
* @return The root node.
*/
virtual ContainerNode & getRootContainer() const = 0;
/*
* Shorthand functions for reading and writing from/to the root container
*/
/**
* Determine if there is unread element. If yes, then app can use one of
* the readXxx() functions to read it.
*
* @return True if there is.
*/
bool hasUnread() const;
/**
* Get the name of the next unread element. It will throw Error if there
* is no more element to read.
*
* @return The name of the next element .
*/
string unreadName() const PJSUA2_THROW(Error);
/**
* Read an integer value from the document and return the value.
* This will throw Error if the current element is not a number.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
int readInt(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a float value from the document and return the value.
* This will throw Error if the current element is not a number.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
float readNumber(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a boolean value from the container and return the value.
* This will throw Error if the current element is not a boolean.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
bool readBool(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a string value from the container and return the value.
* This will throw Error if the current element is not a string.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
string readString(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a string array from the container. This will throw Error
* if the current element is not a string array. The read position
* will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
StringVector readStringVector(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read the specified object from the container. This is equal to
* calling PersistentObject.readObject(ContainerNode);
*
* @param obj The object to read.
*/
void readObject(PersistentObject &obj) const
PJSUA2_THROW(Error);
/**
* Read a container from the container. This will throw Error if the
* current element is not an object. The read position will be advanced
* to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return Container object.
*/
ContainerNode readContainer(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read array container from the container. This will throw Error if the
* current element is not an array. The read position will be advanced
* to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return Container object.
*/
ContainerNode readArray(const string &name="") const
PJSUA2_THROW(Error);
/**
* Write a number value to the container.
*
* @param name The name for the value in the container.
* @param num The value to be written.
*/
void writeNumber(const string &name,
float num) PJSUA2_THROW(Error);
/**
* Write a number value to the container.
*
* @param name The name for the value in the container.
* @param num The value to be written.
*/
void writeInt(const string &name,
int num) PJSUA2_THROW(Error);
/**
* Write a boolean value to the container.
*
* @param name The name for the value in the container.
* @param value The value to be written.
*/
void writeBool(const string &name,
bool value) PJSUA2_THROW(Error);
/**
* Write a string value to the container.
*
* @param name The name for the value in the container.
* @param value The value to be written.
*/
void writeString(const string &name,
const string &value) PJSUA2_THROW(Error);
/**
* Write string vector to the container.
*
* @param name The name for the value in the container.
* @param arr The vector to be written.
*/
void writeStringVector(const string &name,
const StringVector &arr)
PJSUA2_THROW(Error);
/**
* Write an object to the container. This is equal to calling
* PersistentObject.writeObject(ContainerNode);
*
* @param obj The object to be written
*/
void writeObject(const PersistentObject &obj)
PJSUA2_THROW(Error);
/**
* Create and write an empty Object node that can be used as parent
* for subsequent write operations.
*
* @param name The name for the new container in the container.
*
* @return A sub-container.
*/
ContainerNode writeNewContainer(const string &name)
PJSUA2_THROW(Error);
/**
* Create and write an empty array node that can be used as parent
* for subsequent write operations.
*
* @param name The name for the array.
*
* @return A sub-container.
*/
ContainerNode writeNewArray(const string &name)
PJSUA2_THROW(Error);
};
/**
* Forward declaration of container_node_op.
*/
struct container_node_op;
/**
* Internal data for ContainerNode. See ContainerNode implementation notes
* for more info.
*/
struct container_node_internal_data
{
void *doc; /**< The document. */
void *data1; /**< Internal data 1 */
void *data2; /**< Internal data 2 */
};
/**
* A container node is a placeholder for storing other data elements, which
* could be boolean, number, string, array of strings, or another container.
* Each data in the container is basically a name/value pair, with a type
* internally associated with it so that written data can be read in the
* correct type. Data is read and written serially, hence the order of
* reading must be the same as the order of writing.
*
* Application can read data from it by using the various read methods, and
* write data to it using the various write methods. Alternatively, it
* may be more convenient to use the provided macros below to read and write
* the data, because these macros set the name automatically:
* - NODE_READ_BOOL(node,item)
* - NODE_READ_UNSIGNED(node,item)
* - NODE_READ_INT(node,item)
* - NODE_READ_FLOAT(node,item)
* - NODE_READ_NUM_T(node,type,item)
* - NODE_READ_STRING(node,item)
* - NODE_READ_STRINGV(node,item)
* - NODE_READ_OBJ(node,item)
* - NODE_WRITE_BOOL(node,item)
* - NODE_WRITE_UNSIGNED(node,item)
* - NODE_WRITE_INT(node,item)
* - NODE_WRITE_FLOAT(node,item)
* - NODE_WRITE_NUM_T(node,type,item)
* - NODE_WRITE_STRING(node,item)
* - NODE_WRITE_STRINGV(node,item)
* - NODE_WRITE_OBJ(node,item)
*
* Implementation notes:
*
* The ContainerNode class is subclass-able, but not in the usual C++ way.
* With the usual C++ inheritance, some methods will be made pure virtual
* and must be implemented by the actual class. However, doing so will
* require dynamic instantiation of the ContainerNode class, which means
* we will need to pass around the class as pointer, for example as the
* return value of readContainer() and writeNewContainer() methods. Then
* we will need to establish who needs or how to delete these objects, or
* use shared pointer mechanism, each of which is considered too inconvenient
* or complicated for the purpose.
*
* So hence we use C style "inheritance", where the methods are declared in
* container_node_op and the data in container_node_internal_data structures.
* An implementation of ContainerNode class will need to set up these members
* with values that makes sense to itself. The methods in container_node_op
* contains the pointer to the actual implementation of the operation, which
* would be specific according to the format of the document. The methods in
* this ContainerNode class are just thin wrappers which call the
* implementation in the container_node_op structure.
*
*/
class ContainerNode
{
public:
/**
* Determine if there is unread element. If yes, then app can use one of
* the readXxx() functions to read it.
*/
bool hasUnread() const;
/**
* Get the name of the next unread element.
*/
string unreadName() const PJSUA2_THROW(Error);
/**
* Read an integer value from the document and return the value.
* This will throw Error if the current element is not a number.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
int readInt(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a number value from the document and return the value.
* This will throw Error if the current element is not a number.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
float readNumber(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a boolean value from the container and return the value.
* This will throw Error if the current element is not a boolean.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
bool readBool(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a string value from the container and return the value.
* This will throw Error if the current element is not a string.
* The read position will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
string readString(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read a string array from the container. This will throw Error
* if the current element is not a string array. The read position
* will be advanced to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return The value.
*/
StringVector readStringVector(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read the specified object from the container. This is equal to
* calling PersistentObject.readObject(ContainerNode);
*
* @param obj The object to read.
*/
void readObject(PersistentObject &obj) const
PJSUA2_THROW(Error);
/**
* Read a container from the container. This will throw Error if the
* current element is not a container. The read position will be advanced
* to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return Container object.
*/
ContainerNode readContainer(const string &name="") const
PJSUA2_THROW(Error);
/**
* Read array container from the container. This will throw Error if the
* current element is not an array. The read position will be advanced
* to the next element.
*
* @param name If specified, then the function will check if the
* name of the next element matches the specified
* name and throw Error if it doesn't match.
*
* @return Container object.
*/
ContainerNode readArray(const string &name="") const
PJSUA2_THROW(Error);
/**
* Write a number value to the container.
*
* @param name The name for the value in the container.
* @param num The value to be written.
*/
void writeNumber(const string &name,
float num) PJSUA2_THROW(Error);
/**
* Write a number value to the container.
*
* @param name The name for the value in the container.
* @param num The value to be written.
*/
void writeInt(const string &name,
int num) PJSUA2_THROW(Error);
/**
* Write a boolean value to the container.
*
* @param name The name for the value in the container.
* @param value The value to be written.
*/
void writeBool(const string &name,
bool value) PJSUA2_THROW(Error);
/**
* Write a string value to the container.
*
* @param name The name for the value in the container.
* @param value The value to be written.
*/
void writeString(const string &name,
const string &value) PJSUA2_THROW(Error);
/**
* Write string vector to the container.
*
* @param name The name for the value in the container.
* @param arr The vector to be written.
*/
void writeStringVector(const string &name,
const StringVector &arr)
PJSUA2_THROW(Error);
/**
* Write an object to the container. This is equal to calling
* PersistentObject.writeObject(ContainerNode);
*
* @param obj The object to be written
*/
void writeObject(const PersistentObject &obj)
PJSUA2_THROW(Error);
/**
* Create and write an empty Object node that can be used as parent
* for subsequent write operations.
*
* @param name The name for the new container in the container.
*
* @return A sub-container.
*/
ContainerNode writeNewContainer(const string &name)
PJSUA2_THROW(Error);
/**
* Create and write an empty array node that can be used as parent
* for subsequent write operations.
*
* @param name The name for the array.
*
* @return A sub-container.
*/
ContainerNode writeNewArray(const string &name)
PJSUA2_THROW(Error);
public:
/* internal data */
container_node_op *op; /**< Method table. */
container_node_internal_data data; /**< Internal data */
};
/**
* Pointer to actual ContainerNode implementation. See ContainerNode
* implementation notes for more info.
*/
//! @cond Doxygen_Suppress
struct container_node_op
{
bool (*hasUnread)(const ContainerNode*);
string (*unreadName)(const ContainerNode*)
PJSUA2_THROW(Error);
float (*readNumber)(const ContainerNode*,
const string&)
PJSUA2_THROW(Error);
bool (*readBool)(const ContainerNode*,
const string&)
PJSUA2_THROW(Error);
string (*readString)(const ContainerNode*,
const string&)
PJSUA2_THROW(Error);
StringVector (*readStringVector)(const ContainerNode*,
const string&)
PJSUA2_THROW(Error);
ContainerNode (*readContainer)(const ContainerNode*,
const string &)
PJSUA2_THROW(Error);
ContainerNode (*readArray)(const ContainerNode*,
const string &)
PJSUA2_THROW(Error);
void (*writeNumber)(ContainerNode*,
const string &name,
float num)
PJSUA2_THROW(Error);
void (*writeBool)(ContainerNode*,
const string &name,
bool value)
PJSUA2_THROW(Error);
void (*writeString)(ContainerNode*,
const string &name,
const string &value)
PJSUA2_THROW(Error);
void (*writeStringVector)(ContainerNode*,
const string &name,
const StringVector &value)
PJSUA2_THROW(Error);
ContainerNode (*writeNewContainer)(ContainerNode*,
const string &name)
PJSUA2_THROW(Error);
ContainerNode (*writeNewArray)(ContainerNode*,
const string &name)
PJSUA2_THROW(Error);
};
/*
* Convenient macros.
*/
#define NODE_READ_BOOL(node,item) item = node.readBool(#item)
#define NODE_READ_UNSIGNED(node,item) item = (unsigned)node.readNumber(#item)
#define NODE_READ_INT(node,item) item = (int) node.readNumber(#item)
#define NODE_READ_FLOAT(node,item) item = node.readNumber(#item)
#define NODE_READ_NUM_T(node,T,item) item = (T)(int)node.readNumber(#item)
#define NODE_READ_STRING(node,item) item = node.readString(#item)
#define NODE_READ_STRINGV(node,item) item = node.readStringVector(#item)
#define NODE_READ_OBJ(node,item) node.readObject(item)
#define NODE_WRITE_BOOL(node,item) node.writeBool(#item, item)
#define NODE_WRITE_UNSIGNED(node,item) node.writeNumber(#item, (float)item)
#define NODE_WRITE_INT(node,item) node.writeNumber(#item, (float)item)
#define NODE_WRITE_NUM_T(node,T,item) node.writeNumber(#item, (float)item)
#define NODE_WRITE_FLOAT(node,item) node.writeNumber(#item, item)
#define NODE_WRITE_STRING(node,item) node.writeString(#item, item)
#define NODE_WRITE_STRINGV(node,item) node.writeStringVector(#item, item)
#define NODE_WRITE_OBJ(node,item) node.writeObject(item)
//! @endcond
/**
* @} PJSUA2
*/
} // namespace pj
#endif /* __PJSUA2_PERSISTENT_HPP__ */
@@ -0,0 +1,360 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_PRESENCE_HPP__
#define __PJSUA2_PRESENCE_HPP__
/**
* @file pjsua2/presence.hpp
* @brief PJSUA2 Presence Operations
*/
#include <pjsua2/persistent.hpp>
#include <pjsua2/siptypes.hpp>
/** PJSUA2 API is inside pj namespace */
namespace pj
{
/**
* @defgroup PJSUA2_PRES Presence
* @ingroup PJSUA2_Ref
* @{
*/
using std::string;
using std::vector;
/**
* This describes presence status.
*/
struct PresenceStatus
{
/**
* Buddy's online status.
*/
pjsua_buddy_status status;
/**
* Text to describe buddy's online status.
*/
string statusText;
/**
* Activity type.
*/
pjrpid_activity activity;
/**
* Optional text describing the person/element.
*/
string note;
/**
* Optional RPID ID string.
*/
string rpidId;
public:
/**
* Constructor.
*/
PresenceStatus();
};
/**
* This structure describes buddy configuration when adding a buddy to
* the buddy list with Buddy::create().
*/
struct BuddyConfig : public PersistentObject
{
/**
* Buddy URL or name address.
*/
string uri;
/**
* Specify whether presence subscription should start immediately.
*/
bool subscribe;
public:
/**
* Read this object from a container node.
*
* @param node Container to read values from.
*/
virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
/**
* Write this object to a container node.
*
* @param node Container to write values to.
*/
virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
};
/**
* This structure describes buddy info, which can be retrieved by via
* Buddy::getInfo().
*/
struct BuddyInfo
{
/**
* The full URI of the buddy, as specified in the configuration.
*/
string uri;
/**
* Buddy's Contact, only available when presence subscription has
* been established to the buddy.
*/
string contact;
/**
* Flag to indicate that we should monitor the presence information for
* this buddy (normally yes, unless explicitly disabled).
*/
bool presMonitorEnabled;
/**
* If \a presMonitorEnabled is true, this specifies the last state of
* the presence subscription. If presence subscription session is currently
* active, the value will be PJSIP_EVSUB_STATE_ACTIVE. If presence
* subscription request has been rejected, the value will be
* PJSIP_EVSUB_STATE_TERMINATED, and the termination reason will be
* specified in \a subTermReason.
*/
pjsip_evsub_state subState;
/**
* String representation of subscription state.
*/
string subStateName;
/**
* Specifies the last presence subscription termination code. This would
* return the last status of the SUBSCRIBE request. If the subscription
* is terminated with NOTIFY by the server, this value will be set to
* 200, and subscription termination reason will be given in the
* \a subTermReason field.
*/
pjsip_status_code subTermCode;
/**
* Specifies the last presence subscription termination reason. If
* presence subscription is currently active, the value will be empty.
*/
string subTermReason;
/**
* Presence status.
*/
PresenceStatus presStatus;
public:
/**
* Default constructor
*/
BuddyInfo() : subState(PJSIP_EVSUB_STATE_UNKNOWN),
subTermCode(PJSIP_SC_NULL)
{}
/** Import from pjsip structure */
void fromPj(const pjsua_buddy_info &pbi);
};
/**
* This structure contains parameters for Buddy::onBuddyEvSubState() callback.
*/
struct OnBuddyEvSubStateParam
{
/**
* * The event which triggers state change event.
*/
SipEvent e;
};
/**
* Buddy. This is a lite wrapper class for PJSUA-LIB buddy, i.e: this class
* only maintains one data member, PJSUA-LIB buddy ID, and the methods are
* simply proxies for PJSUA-LIB buddy operations.
*
* Application can use create() to register a buddy to PJSUA-LIB, and
* the destructor of the original instance (i.e: the instance that calls
* create()) will unregister and delete the buddy from PJSUA-LIB. Application
* must delete all Buddy instances belong to an account before shutting down
* the account (via Account::shutdown()).
*
* The library will not keep a list of Buddy instances, so any Buddy (or
* descendant) instances instantiated by application must be maintained
* and destroyed by the application itself. Any PJSUA2 APIs that return Buddy
* instance(s) such as Account::enumBuddies2() or Account::findBuddy2() will
* just return generated copy. All Buddy methods should work normally on this
* generated copy instance.
*/
class Buddy
{
public:
/**
* Constructor.
*/
Buddy();
/**
* Destructor. Note that if the Buddy original instance (i.e: the instance
* that calls Buddy::create()) is destroyed, it will also delete the
* corresponding buddy in the PJSUA-LIB. While the destructor of
* a generated copy (i.e: Buddy instance returned by PJSUA2 APIs such as
* Account::enumBuddies2() or Account::findBuddy2()) will do nothing.
*/
virtual ~Buddy();
/**
* Create buddy and register the buddy to PJSUA-LIB.
*
* Note that application should maintain the Buddy original instance, i.e:
* the instance that calls this create() method as it is only the original
* instance destructor that will delete the underlying Buddy in PJSUA-LIB.
*
* @param acc The account for this buddy.
* @param cfg The buddy config.
*/
void create(Account &acc, const BuddyConfig &cfg) PJSUA2_THROW(Error);
/**
* Check if this buddy is valid.
*
* @return True if it is.
*/
bool isValid() const;
/**
* Get detailed buddy info.
*
* @return Buddy info.
*/
BuddyInfo getInfo() const PJSUA2_THROW(Error);
/**
* Enable/disable buddy's presence monitoring. Once buddy's presence is
* subscribed, application will be informed about buddy's presence status
* changed via \a onBuddyState() callback.
*
* @param subscribe Specify true to activate presence
* subscription.
*/
void subscribePresence(bool subscribe) PJSUA2_THROW(Error);
/**
* Update the presence information for the buddy. Although the library
* periodically refreshes the presence subscription for all buddies,
* some application may want to refresh the buddy's presence subscription
* immediately, and in this case it can use this function to accomplish
* this.
*
* Note that the buddy's presence subscription will only be initiated
* if presence monitoring is enabled for the buddy. See
* subscribePresence() for more info. Also if presence subscription for
* the buddy is already active, this function will not do anything.
*
* Once the presence subscription is activated successfully for the buddy,
* application will be notified about the buddy's presence status in the
* \a onBuddyState() callback.
*/
void updatePresence(void) PJSUA2_THROW(Error);
/**
* Send instant messaging outside dialog, using this buddy's specified
* account for route set and authentication.
*
* @param prm Sending instant message parameter.
*/
void sendInstantMessage(const SendInstantMessageParam &prm)
PJSUA2_THROW(Error);
/**
* Send typing indication outside dialog.
*
* @param prm Sending instant message parameter.
*/
void sendTypingIndication(const SendTypingIndicationParam &prm)
PJSUA2_THROW(Error);
public:
/*
* Callbacks
*/
/**
* Notify application when the buddy state has changed.
* Application may then query the buddy info to get the details.
*/
virtual void onBuddyState()
{}
/**
* Notify application when the state of client subscription session
* associated with a buddy has changed. Application may use this
* callback to retrieve more detailed information about the state
* changed event.
*
* @param prm Callback parameter.
*/
virtual void onBuddyEvSubState(OnBuddyEvSubStateParam &prm)
{ PJ_UNUSED_ARG(prm); }
private:
/**
* Buddy ID.
*/
pjsua_buddy_id id;
private:
friend class Endpoint;
friend class Account;
/* Internal constructor/methods used by Endpoint and Account */
Buddy(pjsua_buddy_id buddy_id);
Buddy *getOriginalInstance();
};
/**
* Warning: deprecated, use BuddyVector2 instead.
*
* Array of buddies.
*/
typedef std::vector<Buddy*> BuddyVector;
/** Array of buddies */
typedef std::vector<Buddy> BuddyVector2;
/**
* @} // PJSUA2_PRES
*/
} // namespace pj
#endif /* __PJSUA2_PRESENCE_HPP__ */
@@ -0,0 +1,960 @@
/* $Id$ */
/*
* Copyright (C) 2032 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_SIPTYPES_HPP__
#define __PJSUA2_SIPTYPES_HPP__
/**
* @file pjsua2/types.hpp
* @brief PJSUA2 Base Types
*/
#include <pjsua2/types.hpp>
#include <pjsua2/persistent.hpp>
#include <string>
#include <vector>
/** PJSUA2 API is inside pj namespace */
namespace pj
{
/**
* @defgroup PJSUA2_SIP_Types SIP Types
* @ingroup PJSUA2_DS
* @{
*/
/**
* Credential information. Credential contains information to authenticate
* against a service.
*/
struct AuthCredInfo : public PersistentObject
{
/**
* The authentication scheme (e.g. "digest").
*/
string scheme;
/**
* Realm on which this credential is to be used. Use "*" to make
* a credential that can be used to authenticate against any challenges.
*/
string realm;
/**
* Authentication user name.
*/
string username;
/**
* Type of data that is contained in the "data" field. Use 0 if the data
* contains plain text password.
*/
int dataType;
/**
* The data, which can be a plain text password or a hashed digest.
*/
string data;
/*
* Digest AKA credential information. Note that when AKA credential
* is being used, the \a data field of this pjsip_cred_info is
* not used, but it still must be initialized to an empty string.
* Please see PJSIP_AUTH_AKA_API for more information.
*/
/** Permanent subscriber key. */
string akaK;
/** Operator variant key. */
string akaOp;
/** Authentication Management Field */
string akaAmf;
public:
/** Default constructor */
AuthCredInfo();
/** Construct a credential with the specified parameters */
AuthCredInfo(const string &scheme,
const string &realm,
const string &user_name,
const int data_type,
const string data);
/**
* Read this object from a container node.
*
* @param node Container to read values from.
*/
virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
/**
* Write this object to a container node.
*
* @param node Container to write values to.
*/
virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
};
//////////////////////////////////////////////////////////////////////////////
/**
* TLS transport settings, to be specified in TransportConfig.
*/
struct TlsConfig : public PersistentObject
{
/**
* Certificate of Authority (CA) list file.
*/
string CaListFile;
/**
* Public endpoint certificate file, which will be used as client-
* side certificate for outgoing TLS connection, and server-side
* certificate for incoming TLS connection.
*/
string certFile;
/**
* Optional private key of the endpoint certificate to be used.
*/
string privKeyFile;
/**
* Password to open private key.
*/
string password;
/**
* Certificate of Authority (CA) buffer. If CaListFile, certFile or
* privKeyFile are set, this setting will be ignored.
*/
string CaBuf;
/**
* Public endpoint certificate buffer, which will be used as client-
* side certificate for outgoing TLS connection, and server-side
* certificate for incoming TLS connection. If CaListFile, certFile or
* privKeyFile are set, this setting will be ignored.
*/
string certBuf;
/**
* Optional private key buffer of the endpoint certificate to be used.
* If CaListFile, certFile or privKeyFile are set, this setting will
* be ignored.
*/
string privKeyBuf;
/**
* TLS protocol method from #pjsip_ssl_method. In the future, this field
* might be deprecated in favor of <b>proto</b> field. For now, this field
* is only applicable only when <b>proto</b> field is set to zero.
*
* Default is PJSIP_SSL_UNSPECIFIED_METHOD (0), which in turn will
* use PJSIP_SSL_DEFAULT_METHOD, which default value is PJSIP_TLSV1_METHOD.
*/
pjsip_ssl_method method;
/**
* TLS protocol type from #pj_ssl_sock_proto. Use this field to enable
* specific protocol type. Use bitwise OR operation to combine the protocol
* type.
*
* Default is PJSIP_SSL_DEFAULT_PROTO.
*/
unsigned proto;
/**
* Ciphers and order preference. The Endpoint::utilSslGetAvailableCiphers()
* can be used to check the available ciphers supported by backend.
* If the array is empty, then default cipher list of the backend
* will be used.
*/
IntVector ciphers;
/**
* Specifies TLS transport behavior on the server TLS certificate
* verification result:
* - If \a verifyServer is disabled, TLS transport will just notify
* the application via pjsip_tp_state_callback with state
* PJSIP_TP_STATE_CONNECTED regardless TLS verification result.
* - If \a verifyServer is enabled, TLS transport will be shutdown
* and application will be notified with state
* PJSIP_TP_STATE_DISCONNECTED whenever there is any TLS verification
* error, otherwise PJSIP_TP_STATE_CONNECTED will be notified.
*
* In any cases, application can inspect pjsip_tls_state_info in the
* callback to see the verification detail.
*
* Default value is false.
*/
bool verifyServer;
/**
* Specifies TLS transport behavior on the client TLS certificate
* verification result:
* - If \a verifyClient is disabled, TLS transport will just notify
* the application via pjsip_tp_state_callback with state
* PJSIP_TP_STATE_CONNECTED regardless TLS verification result.
* - If \a verifyClient is enabled, TLS transport will be shutdown
* and application will be notified with state
* PJSIP_TP_STATE_DISCONNECTED whenever there is any TLS verification
* error, otherwise PJSIP_TP_STATE_CONNECTED will be notified.
*
* In any cases, application can inspect pjsip_tls_state_info in the
* callback to see the verification detail.
*
* Default value is PJ_FALSE.
*/
bool verifyClient;
/**
* When acting as server (incoming TLS connections), reject incoming
* connection if client doesn't supply a TLS certificate.
*
* This setting corresponds to SSL_VERIFY_FAIL_IF_NO_PEER_CERT flag.
* Default value is PJ_FALSE.
*/
bool requireClientCert;
/**
* TLS negotiation timeout to be applied for both outgoing and incoming
* connection, in milliseconds. If zero, the SSL negotiation doesn't
* have a timeout.
*
* Default: zero
*/
unsigned msecTimeout;
/**
* QoS traffic type to be set on this transport. When application wants
* to apply QoS tagging to the transport, it's preferable to set this
* field rather than \a qosParam fields since this is more portable.
*
* Default value is PJ_QOS_TYPE_BEST_EFFORT.
*/
pj_qos_type qosType;
/**
* Set the low level QoS parameters to the transport. This is a lower
* level operation than setting the \a qosType field and may not be
* supported on all platforms.
*
* By default all settings in this structure are disabled.
*/
pj_qos_params qosParams;
/**
* Specify if the transport should ignore any errors when setting the QoS
* traffic type/parameters.
*
* Default: PJ_TRUE
*/
bool qosIgnoreError;
public:
/** Default constructor initialises with default values */
TlsConfig();
/** Convert to pjsip */
pjsip_tls_setting toPj() const;
/** Convert from pjsip */
void fromPj(const pjsip_tls_setting &prm);
/**
* Read this object from a container node.
*
* @param node Container to read values from.
*/
virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
/**
* Write this object to a container node.
*
* @param node Container to write values to.
*/
virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
};
/**
* Parameters to create a transport instance.
*/
struct TransportConfig : public PersistentObject
{
/**
* UDP port number to bind locally. This setting MUST be specified
* even when default port is desired. If the value is zero, the
* transport will be bound to any available port, and application
* can query the port by querying the transport info.
*/
unsigned port;
/**
* Specify the port range for socket binding, relative to the start
* port number specified in \a port. Note that this setting is only
* applicable when the start port number is non zero.
*
* Default value is zero.
*/
unsigned portRange;
/**
* Optional address to advertise as the address of this transport.
* Application can specify any address or hostname for this field,
* for example it can point to one of the interface address in the
* system, or it can point to the public address of a NAT router
* where port mappings have been configured for the application.
*
* Note: this option can be used for both UDP and TCP as well!
*/
string publicAddress;
/**
* Optional address where the socket should be bound to. This option
* SHOULD only be used to selectively bind the socket to particular
* interface (instead of 0.0.0.0), and SHOULD NOT be used to set the
* published address of a transport (the public_addr field should be
* used for that purpose).
*
* Note that unlike public_addr field, the address (or hostname) here
* MUST correspond to the actual interface address in the host, since
* this address will be specified as bind() argument.
*/
string boundAddress;
/**
* This specifies TLS settings for TLS transport. It is only be used
* when this transport config is being used to create a SIP TLS
* transport.
*/
TlsConfig tlsConfig;
/**
* QoS traffic type to be set on this transport. When application wants
* to apply QoS tagging to the transport, it's preferable to set this
* field rather than \a qosParam fields since this is more portable.
*
* Default is QoS not set.
*/
pj_qos_type qosType;
/**
* Set the low level QoS parameters to the transport. This is a lower
* level operation than setting the \a qosType field and may not be
* supported on all platforms.
*
* Default is QoS not set.
*/
pj_qos_params qosParams;
public:
/** Default constructor initialises with default values */
TransportConfig();
/** Convert from pjsip */
void fromPj(const pjsua_transport_config &prm);
/** Convert to pjsip */
pjsua_transport_config toPj() const;
/**
* Read this object from a container node.
*
* @param node Container to read values from.
*/
virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
/**
* Write this object to a container node.
*
* @param node Container to write values to.
*/
virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
};
/**
* This structure describes transport information returned by
* Endpoint::transportGetInfo() function.
*/
struct TransportInfo
{
/** PJSUA transport identification. */
TransportId id;
/** Transport type. */
pjsip_transport_type_e type;
/** Transport type name. */
string typeName;
/** Transport string info/description. */
string info;
/** Transport flags (see pjsip_transport_flags_e). */
unsigned flags;
/** Local/bound address. */
SocketAddress localAddress;
/** Published address (or transport address name). */
SocketAddress localName;
/** Current number of objects currently referencing this transport. */
unsigned usageCount;
public:
/**
* Default constructor.
*/
TransportInfo();
/** Construct from pjsua_transport_info */
void fromPj(const pjsua_transport_info &info);
};
//////////////////////////////////////////////////////////////////////////////
/**
* This structure describes an incoming SIP message. It corresponds to the
* pjsip_rx_data structure in PJSIP library.
*/
struct SipRxData
{
/**
* A short info string describing the request, which normally contains
* the request method and its CSeq.
*/
string info;
/**
* The whole message data as a string, containing both the header section
* and message body section.
*/
string wholeMsg;
/**
* Source address of the message.
*/
SocketAddress srcAddress;
/**
* Pointer to original pjsip_rx_data. Only valid when the struct
* is constructed from PJSIP's pjsip_rx_data.
*/
void *pjRxData;
public:
/**
* Default constructor.
*/
SipRxData();
/**
* Construct from PJSIP's pjsip_rx_data
*/
void fromPj(pjsip_rx_data &rdata);
};
/**
* This structure describes an outgoing SIP message. It corresponds to the
* pjsip_tx_data structure in PJSIP library.
*/
struct SipTxData
{
/**
* A short info string describing the request, which normally contains
* the request method and its CSeq.
*/
string info;
/**
* The whole message data as a string, containing both the header section
* and message body section.
*/
string wholeMsg;
/**
* Destination address of the message.
*/
SocketAddress dstAddress;
/**
* Pointer to original pjsip_tx_data. Only valid when the struct
* is constructed from PJSIP's pjsip_tx_data.
*/
void *pjTxData;
public:
/**
* Default constructor.
*/
SipTxData();
/**
* Construct from PJSIP's pjsip_tx_data
*/
void fromPj(pjsip_tx_data &tdata);
};
/**
* This structure describes SIP transaction object. It corresponds to the
* pjsip_transaction structure in PJSIP library.
*/
struct SipTransaction
{
/* Transaction identification. */
pjsip_role_e role; /**< Role (UAS or UAC) */
string method; /**< The method. */
/* State and status. */
int statusCode; /**< Last status code seen. */
string statusText; /**< Last reason phrase. */
pjsip_tsx_state_e state; /**< State. */
/* Messages and timer. */
SipTxData lastTx; /**< Msg kept for retrans. */
/* Original pjsip_transaction. */
void *pjTransaction; /**< pjsip_transaction. */
public:
/**
* Default constructor.
*/
SipTransaction();
/**
* Construct from PJSIP's pjsip_transaction
*/
void fromPj(pjsip_transaction &tsx);
};
/**
* This structure describes timer event.
*/
struct TimerEvent
{
TimerEntry entry; /**< The timer entry. */
};
/**
* This structure describes transaction state event source.
*/
struct TsxStateEventSrc
{
SipRxData rdata; /**< The incoming message. */
SipTxData tdata; /**< The outgoing message. */
TimerEntry timer; /**< The timer. */
pj_status_t status; /**< Transport error status. */
GenericData data; /**< Generic data. */
TsxStateEventSrc() : status() {}
};
/**
* This structure describes transaction state changed event.
*/
struct TsxStateEvent
{
TsxStateEventSrc src; /**< Event source. */
SipTransaction tsx; /**< The transaction. */
pjsip_tsx_state_e prevState; /**< Previous state. */
pjsip_event_id_e type; /**< Type of event source:
* - PJSIP_EVENT_TX_MSG
* - PJSIP_EVENT_RX_MSG,
* - PJSIP_EVENT_TRANSPORT_ERROR
* - PJSIP_EVENT_TIMER
* - PJSIP_EVENT_USER
*/
TsxStateEvent();
};
/**
* This structure describes message transmission event.
*/
struct TxMsgEvent
{
SipTxData tdata; /**< The transmit data buffer. */
};
/**
* This structure describes transmission error event.
*/
struct TxErrorEvent
{
SipTxData tdata; /**< The transmit data. */
SipTransaction tsx; /**< The transaction. */
};
/**
* This structure describes message arrival event.
*/
struct RxMsgEvent
{
SipRxData rdata; /**< The receive data buffer. */
};
/**
* This structure describes user event.
*/
struct UserEvent
{
GenericData user1; /**< User data 1. */
GenericData user2; /**< User data 2. */
GenericData user3; /**< User data 3. */
GenericData user4; /**< User data 4. */
};
/**
* The event body.
*/
struct SipEventBody
{
/**
* Timer event.
*/
TimerEvent timer;
/**
* Transaction state has changed event.
*/
TsxStateEvent tsxState;
/**
* Message transmission event.
*/
TxMsgEvent txMsg;
/**
* Transmission error event.
*/
TxErrorEvent txError;
/**
* Message arrival event.
*/
RxMsgEvent rxMsg;
/**
* User event.
*/
UserEvent user;
};
/**
* This structure describe event descriptor to fully identify a SIP event. It
* corresponds to the pjsip_event structure in PJSIP library.
*/
struct SipEvent
{
/**
* The event type, can be any value of \b pjsip_event_id_e.
*/
pjsip_event_id_e type;
/**
* The event body, which fields depends on the event type.
*/
SipEventBody body;
/**
* Pointer to its original pjsip_event. Only valid when the struct is
* constructed from PJSIP's pjsip_event.
*/
void *pjEvent;
public:
/**
* Default constructor.
*/
SipEvent();
/**
* Construct from PJSIP's pjsip_event
*/
void fromPj(const pjsip_event &ev);
};
//////////////////////////////////////////////////////////////////////////////
/**
* SIP media type containing type and subtype. For example, for
* "application/sdp", the type is "application" and the subtype is "sdp".
*/
struct SipMediaType
{
/** Media type. */
string type;
/** Media subtype. */
string subType;
public:
/**
* Construct from PJSIP's pjsip_media_type
*/
void fromPj(const pjsip_media_type &prm);
/**
* Convert to PJSIP's pjsip_media_type.
*/
pjsip_media_type toPj() const;
};
/**
* Simple SIP header.
*/
struct SipHeader
{
/**
* Header name.
*/
string hName;
/**
* Header value.
*/
string hValue;
public:
/**
* Initiaize from PJSIP header.
*/
void fromPj(const pjsip_hdr *) PJSUA2_THROW(Error);
/**
* Convert to PJSIP header.
*/
pjsip_generic_string_hdr &toPj() const;
private:
/** Interal buffer for conversion to PJSIP header */
mutable pjsip_generic_string_hdr pjHdr;
};
/** Array of strings */
typedef std::vector<SipHeader> SipHeaderVector;
/**
* This describes each multipart part.
*/
struct SipMultipartPart
{
/**
* Optional headers to be put in this multipart part.
*/
SipHeaderVector headers;
/**
* The MIME type of the body part of this multipart part.
*/
SipMediaType contentType;
/**
* The body part of tthis multipart part.
*/
string body;
public:
/**
* Initiaize from PJSIP's pjsip_multipart_part.
*/
void fromPj(const pjsip_multipart_part &prm) PJSUA2_THROW(Error);
/**
* Convert to PJSIP's pjsip_multipart_part.
*/
pjsip_multipart_part& toPj() const;
private:
/** Interal buffer for conversion to PJSIP pjsip_multipart_part */
mutable pjsip_multipart_part pjMpp;
mutable pjsip_msg_body pjMsgBody;
};
/** Array of multipart parts */
typedef std::vector<SipMultipartPart> SipMultipartPartVector;
/**
* Additional options when sending outgoing SIP message. This corresponds to
* pjsua_msg_data structure in PJSIP library.
*/
struct SipTxOption
{
/**
* Optional remote target URI (i.e. Target header). If empty (""), the
* target will be set to the remote URI (To header). At the moment this
* field is only used when sending initial INVITE and MESSAGE requests.
*/
string targetUri;
/**
* Additional message headers to be included in the outgoing message.
*/
SipHeaderVector headers;
/**
* MIME type of the message body, if application specifies the messageBody
* in this structure.
*/
string contentType;
/**
* Optional message body to be added to the message, only when the
* message doesn't have a body.
*/
string msgBody;
/**
* Content type of the multipart body. If application wants to send
* multipart message bodies, it puts the parts in multipartParts and set
* the content type in multipartContentType. If the message already
* contains a body, the body will be added to the multipart bodies.
*/
SipMediaType multipartContentType;
/**
* Array of multipart parts. If application wants to send multipart
* message bodies, it puts the parts in \a parts and set the content
* type in \a multipart_ctype. If the message already contains a body,
* the body will be added to the multipart bodies.
*/
SipMultipartPartVector multipartParts;
public:
/**
* Check if the options are empty. If the options are set with empty
* values, there will be no additional information sent with outgoing
* SIP message.
*
* @return True if the options are empty.
*/
bool isEmpty() const;
/**
* Initiaize from PJSUA's pjsua_msg_data.
*/
void fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error);
/**
* Convert to PJSUA's pjsua_msg_data.
*/
void toPj(pjsua_msg_data &msg_data) const;
};
//////////////////////////////////////////////////////////////////////////////
/**
* This structure contains parameters for sending instance message methods,
* e.g: Buddy::sendInstantMessage(), Call:sendInstantMessage().
*/
struct SendInstantMessageParam
{
/**
* MIME type. Default is "text/plain".
*/
string contentType;
/**
* The message content.
*/
string content;
/**
* List of headers etc to be included in outgoing request.
*/
SipTxOption txOption;
/**
* User data, which will be given back when the IM callback is called.
*/
Token userData;
public:
/**
* Default constructor initializes with zero/empty values.
*/
SendInstantMessageParam();
};
/**
* This structure contains parameters for sending typing indication methods,
* e.g: Buddy::sendTypingIndication(), Call:sendTypingIndication().
*/
struct SendTypingIndicationParam
{
/**
* True to indicate to remote that local person is currently typing an IM.
*/
bool isTyping;
/**
* List of headers etc to be included in outgoing request.
*/
SipTxOption txOption;
public:
/**
* Default constructor initializes with zero/empty values.
*/
SendTypingIndicationParam();
};
/* Utilities */
#ifndef SWIG
//! @cond Doxygen_Suppress
void readIntVector( ContainerNode &node,
const string &array_name,
IntVector &v) PJSUA2_THROW(Error);
void writeIntVector(ContainerNode &node,
const string &array_name,
const IntVector &v) PJSUA2_THROW(Error);
void readQosParams( ContainerNode &node,
pj_qos_params &qos) PJSUA2_THROW(Error);
void writeQosParams( ContainerNode &node,
const pj_qos_params &qos) PJSUA2_THROW(Error);
void readSipHeaders( const ContainerNode &node,
const string &array_name,
SipHeaderVector &headers) PJSUA2_THROW(Error);
void writeSipHeaders(ContainerNode &node,
const string &array_name,
const SipHeaderVector &headers) PJSUA2_THROW(Error);
//! @endcond
#endif // SWIG
/**
* @} PJSUA2
*/
} // namespace pj
#endif /* __PJSUA2_SIPTYPES_HPP__ */
@@ -0,0 +1,266 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSUA2_TYPES_HPP__
#define __PJSUA2_TYPES_HPP__
#ifdef _MSC_VER
# pragma warning( disable : 4290 ) // exception spec ignored
# pragma warning( disable : 4512 ) // can't generate assignment op
#endif
/**
* @file pjsua2/types.hpp
* @brief PJSUA2 Base Types
*/
#include <pjsua2/config.hpp>
#include <string>
#include <vector>
/** PJSUA2 API is inside pj namespace */
namespace pj
{
/**
* @defgroup PJSUA2_TYPES General Data Structure
* @ingroup PJSUA2_DS
* @{
*/
using std::string;
using std::vector;
/** Array of strings */
typedef std::vector<std::string> StringVector;
/** Array of integers */
typedef std::vector<int> IntVector;
/**
* Type of token, i.e. arbitrary application user data
*/
typedef void *Token;
/**
* Socket address, encoded as string. The socket address contains host
* and port number in "host[:port]" format. The host part may contain
* hostname, domain name, IPv4 or IPv6 address. For IPv6 address, the
* address will be enclosed with square brackets, e.g. "[::1]:5060".
*/
typedef string SocketAddress;
/**
* Transport ID is an integer.
*/
typedef int TransportId;
/**
* Transport handle, corresponds to pjsip_transport instance.
*/
typedef void *TransportHandle;
/**
* Timer entry, corresponds to pj_timer_entry
*/
typedef void *TimerEntry;
/**
* Generic data
*/
typedef void *GenericData;
/*
* Forward declaration of Account and Call to be used
* by Endpoint.
*/
class Account;
class Call;
/**
* Constants
*/
enum
{
/** Invalid ID, equal to PJSUA_INVALID_ID */
INVALID_ID = -1,
/** Success, equal to PJ_SUCCESS */
SUCCESS = 0
};
//////////////////////////////////////////////////////////////////////////////
/**
* This structure contains information about an error that is thrown
* as an exception.
*/
struct Error
{
/** The error code. */
pj_status_t status;
/** The PJSUA API operation that throws the error. */
string title;
/** The error message */
string reason;
/** The PJSUA source file that throws the error */
string srcFile;
/** The line number of PJSUA source file that throws the error */
int srcLine;
/** Build error string. */
string info(bool multi_line=false) const;
/** Default constructor */
Error();
/**
* Construct an Error instance from the specified parameters. If
* \a prm_reason is empty, it will be filled with the error description
* for the status code.
*/
Error(pj_status_t prm_status,
const string &prm_title,
const string &prm_reason,
const string &prm_src_file,
int prm_src_line);
};
/*
* Error utilities.
*/
#if PJSUA2_ERROR_HAS_EXTRA_INFO
# define PJSUA2_RAISE_ERROR(status) \
PJSUA2_RAISE_ERROR2(status, __FUNCTION__)
# define PJSUA2_RAISE_ERROR2(status,op) \
PJSUA2_RAISE_ERROR3(status, op, string())
# define PJSUA2_RAISE_ERROR3(status,op,txt) \
do { \
Error err_ = Error(status, op, txt, __FILE__, __LINE__); \
PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
throw err_; \
} while (0)
#else
/** Raise Error exception */
# define PJSUA2_RAISE_ERROR(status) \
PJSUA2_RAISE_ERROR2(status, string())
/** Raise Error exception */
# define PJSUA2_RAISE_ERROR2(status,op) \
PJSUA2_RAISE_ERROR3(status, op, string())
/** Raise Error exception */
# define PJSUA2_RAISE_ERROR3(status,op,txt) \
do { \
Error err_ = Error(status, op, txt, string(), 0); \
PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
throw err_; \
} while (0)
#endif
/** Raise Error exception if the expression fails */
#define PJSUA2_CHECK_RAISE_ERROR2(status, op) \
do { \
if (status != PJ_SUCCESS) { \
PJSUA2_RAISE_ERROR2(status, op); \
} \
} while (0)
/** Raise Error exception if the status fails */
#define PJSUA2_CHECK_RAISE_ERROR(status) \
PJSUA2_CHECK_RAISE_ERROR2(status, "")
/** Raise Error exception if the expression fails */
#define PJSUA2_CHECK_EXPR(expr) \
do { \
pj_status_t the_status = expr; \
PJSUA2_CHECK_RAISE_ERROR2(the_status, #expr); \
} while (0)
//////////////////////////////////////////////////////////////////////////////
/**
* Version information.
*/
struct Version
{
/** Major number */
int major;
/** Minor number */
int minor;
/** Additional revision number */
int rev;
/** Version suffix (e.g. "-svn") */
string suffix;
/** The full version info (e.g. "2.1.0-svn") */
string full;
/**
* PJLIB version number as three bytes with the following format:
* 0xMMIIRR00, where MM: major number, II: minor number, RR: revision
* number, 00: always zero for now.
*/
unsigned numeric;
};
//////////////////////////////////////////////////////////////////////////////
/**
* Representation of time value.
*/
struct TimeVal
{
/**
* The seconds part of the time.
*/
long sec;
/**
* The miliseconds fraction of the time.
*/
long msec;
public:
/**
* Convert from pjsip
*/
void fromPj(const pj_time_val &prm);
};
/**
* @} PJSUA2
*/
} // namespace pj
#endif /* __PJSUA2_TYPES_HPP__ */