30#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
38 mReproRunner(reproRunner),
43#ifdef BUILD_QPID_PROTON
48 XmlRpcHandler(std::make_shared<XmlRpcProtonServer>(*this, brokerUrl, broadcast)),
49 mReproRunner(reproRunner),
61 unsigned int requestId,
62 const Data& responseData,
63 unsigned int resultCode,
64 const Data& resultText)
67 ss <<
Symbols::CRLF <<
" <Result Code=\"" << resultCode <<
"\"";
69 if(!responseData.
empty())
75 mRpc->sendResponse(connectionId, requestId, ss.str().c_str(), resultCode >= 200 );
81 DebugLog (<<
"CommandServer::handleRequest: connectionId=" << connectionId <<
", requestId=" << requestId <<
", request=\r\n" << request);
96 handleGetStackInfoRequest(connectionId, requestId, xml);
100 handleGetStackStatsRequest(connectionId, requestId, xml);
104 handleResetStackStatsRequest(connectionId, requestId, xml);
108 handleLogDnsCacheRequest(connectionId, requestId, xml);
112 handleClearDnsCacheRequest(connectionId, requestId, xml);
116 handleGetDnsCacheRequest(connectionId, requestId, xml);
120 handleGetCongestionStatsRequest(connectionId, requestId, xml);
124 handleSetCongestionToleranceRequest(connectionId, requestId, xml);
128 handleShutdownRequest(connectionId, requestId, xml);
132 handleGetProxyConfigRequest(connectionId, requestId, xml);
136 handleRestartRequest(connectionId, requestId, xml);
140 handleAddTransportRequest(connectionId, requestId, xml);
144 handleRemoveTransportRequest(connectionId, requestId, xml);
148 handleHttpRequest(connectionId, requestId, xml);
152 WarningLog(<<
"CommandServer::handleRequest: Received XML message with unknown method: " << xml.
getTag());
158 WarningLog(<<
"CommandServer::handleRequest: ParseException: " << e);
164CommandServer::handleGetStackInfoRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
166 InfoLog(<<
"CommandServer::handleGetStackInfoRequest");
173 sendResponse(connectionId, requestId, buffer, 200,
"Stack info retrieved.");
177CommandServer::handleGetStackStatsRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
179 InfoLog(<<
"CommandServer::handleGetStackStatsRequest");
181 Lock lock(mStatisticsWaitersMutex);
182 mStatisticsWaiters.push_back(std::make_pair(connectionId, requestId));
193 Lock lock(mStatisticsWaitersMutex);
194 if(mStatisticsWaiters.size() > 0)
200 strm << payload << endl;
202 StatisticsWaitersList::iterator it = mStatisticsWaiters.begin();
203 for(; it != mStatisticsWaiters.end(); it++)
205 sendResponse(it->first, it->second, buffer, 200,
"Stack stats retrieved.");
211CommandServer::handleResetStackStatsRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
213 InfoLog(<<
"CommandServer::handleResetStackStatsRequest");
220CommandServer::handleLogDnsCacheRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
222 InfoLog(<<
"CommandServer::handleLogDnsCacheRequest");
229CommandServer::handleClearDnsCacheRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
231 InfoLog(<<
"CommandServer::handleQueryDnsCacheRequest");
238CommandServer::handleGetDnsCacheRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
240 InfoLog(<<
"CommandServer::handleGetDnsCacheRequest");
251 sendResponse(key.first, key.second,
"empty\r\n", 200,
"DNS cache retrieved.");
255 sendResponse(key.first, key.second, dnsCache, 200,
"DNS cache retrieved.");
260CommandServer::handleGetCongestionStatsRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
262 InfoLog(<<
"CommandServer::handleGetCongestionStatsRequest");
265 if(congestionManager != 0)
271 sendResponse(connectionId, requestId, buffer, 200,
"Congestion stats retrieved.");
280CommandServer::handleSetCongestionToleranceRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
282 InfoLog(<<
"CommandServer::handleSetCongestionToleranceRequest");
284 Data fifoDescription;
287 unsigned long maxTolerance=0;
290 if(congestionManager != 0)
351 sendResponse(connectionId, requestId,
Data::Empty, 400,
"Invalid metric specified: must be SIZE, TIME_DEPTH or WAIT_TIME.");
355 if(maxTolerance == 0)
357 sendResponse(connectionId, requestId,
Data::Empty, 400,
"Invalid MaxTolerance specified: must be greater than 0.");
377CommandServer::handleShutdownRequest(
unsigned int connectionId,
unsigned int requestId,
XMLCursor& xml)
379 InfoLog(<<
"CommandServer::handleShutdownRequest");
386CommandServer::handleGetProxyConfigRequest(
unsigned int connectionId,
unsigned int requestId,
resip::XMLCursor& xml)
388 InfoLog(<<
"CommandServer::handleGetProxyConfigRequest");
394 sendResponse(connectionId, requestId, buffer, 200,
"Proxy config retrieved.");
398CommandServer::handleRestartRequest(
unsigned int connectionId,
unsigned int requestId,
resip::XMLCursor& xml)
400 InfoLog(<<
"CommandServer::handleRestartRequest");
414CommandServer::handleAddTransportRequest(
unsigned int connectionId,
unsigned int requestId,
resip::XMLCursor& xml)
416 InfoLog(<<
"CommandServer::handleAddTransportRequest");
424 bool stunEnabled =
false;
428 Data certificateFilename;
429 Data privateKeyFilename;
431 bool useEmailAsSIP =
false;
529 catch (invalid_argument& e)
541 certificateFilename = xml.
getValue();
549 privateKeyFilename = xml.
getValue();
574 useEmailAsSIP =
true;
601 Data errorString(
"Invalid transport specified: must one of UDP, TCP");
602#if defined( USE_SSL )
603 errorString +=
", TLS, WS, WSS";
605#if defined( USE_DTLS )
606 errorString +=
", DTLS";
614 if(!recordRouteUri.
empty())
625 InfoLog (<<
"Transport specific record-route enabled (generated): " << rr);
632 InfoLog (<<
"Transport specific record-route enabled (generated): " << rr);
639 InfoLog (<<
"Transport specific record-route enabled: " << rr);
644 ErrLog (<<
"Invalid uri provided in rruri setting (ignoring): " << e);
649 Data transportInfoText(
"type=");
651 transportInfoText +=
", port=" +
Data(port);
652 transportInfoText +=
", ipversion=" +
Data((ipVersion ==
V4 ?
"V4" :
"V6"));
653 if(!ipInterface.
empty())
655 transportInfoText +=
", interface=" + ipInterface;
657 if(!recordRouteUri.
empty())
659 transportInfoText +=
", rruri=" +
Data::from(rr);
661 transportInfoText +=
", stun=" +
Data((stunEnabled ?
"YES" :
"NO"));
662 transportInfoText +=
", flags=" +
Data((
uint32_t)transportFlags);
665 transportInfoText +=
", udprcvbuflen=" +
Data((
uint32_t)rcvBufLen);
669 if(!sipDomainname.
empty())
671 transportInfoText +=
", domain=" + sipDomainname;
674 if(!certificateFilename.
empty())
676 transportInfoText +=
", cert=" + certificateFilename;
678 if(!privateKeyFilename.
empty())
680 transportInfoText +=
", key=" + privateKeyFilename;
683 transportInfoText +=
", tlsuseemail=" +
Data((stunEnabled ?
"YES" :
"NO"));
690 sipDomainname,
Data::Empty, sslType, transportFlags, certificateFilename,
691 privateKeyFilename, cvm, useEmailAsSIP);
704 transportInfoText +=
", transportKey=" +
Data(transport->
getKey());
706 Data text(
"Transport add requested: ");
707 text += transportInfoText;
712 Data text(
"Unknown error adding transport: ");
713 text += transportInfoText;
719 Data text(
"Exception adding transport: ");
720 text += transportInfoText;
727CommandServer::handleRemoveTransportRequest(
unsigned int connectionId,
unsigned int requestId,
resip::XMLCursor& xml)
729 unsigned int transportKey = 0;
731 InfoLog(<<
"CommandServer::handleRemoveTransportRequest");
763 if(transportKey == 0)
771 Data text(
"Transport remove requested: transportKey=");
772 text +=
Data(transportKey);
777CommandServer::handleHttpRequest(
unsigned int connectionId,
unsigned int requestId,
resip::XMLCursor& xml)
779 InfoLog(<<
"CommandServer::handleHttpRequest");
782 std::map<Data, Data> m;
784 xmlToMap(m, keys, xml);
789 ErrLog(<<
"at least one WebAdmin instance must be configured, even if it is only bound to localhost");
796 Data& user = m[
"User"];
797 Data& password = m[
"Password"];
800 s <<
"/" << m[
"Page"] <<
".html";
801 bool firstParam =
true;
802 for(
const auto& n : m)
804 const Data& k = n.first;
805 const Data& v = n.second;
806 if(k ==
"User" || k ==
"Password" || k ==
"Page")
810 s << (firstParam ?
"?" :
"&") << k <<
"=";
816 mWebAdmin->
buildPage(
"GET", uri, pageNumber, user, password);
819 catch(std::exception&)
827CommandServer::xmlToMap(std::map<Data, Data>& m, std::set<Data> keys,
resip::XMLCursor& xml)
839 if(!keys.empty() && keys.find(key) == keys.end())
841 ErrLog(<<
"unexpected key: " << key);
853 ErrLog(<<
"no value for key: " << key);
866 if(!keys.empty() && (m.size() < keys.size()))
868 ErrLog(<<
"some keys not found");
#define WarningLog(args_)
Handles cross-platform sockets compatibility.
virtual void sendResponse(unsigned int connectionId, unsigned int requestId, const resip::Data &responseData, unsigned int resultCode, const resip::Data &resultText)
CommandServer(ReproRunner &reproRunner, resip::Data ipAddr, int port, resip::IpVersion version, WebAdmin *webAdmin)
virtual void handleStatisticsMessage(resip::StatisticsMessage &statsMessage)
virtual void onDnsCacheDumpRetrieved(std::pair< unsigned long, unsigned long > key, const resip::Data &dnsEntryStrings)
virtual void handleRequest(unsigned int connectionId, unsigned int requestId, const resip::Data &request)
ProxyConfig & getConfig() noexcept
void removeTransportRecordRoute(unsigned int transportKey)
void addTransportRecordRoute(unsigned int transportKey, const resip::NameAddr &recordRoute)
resip::SipStack & getStack() noexcept
virtual Proxy * getProxy()
virtual void buildPage(const resip::Data &method, const resip::Data &uri, int pageNumber, const resip::Data &user, const resip::Data &password)
std::shared_ptr< XmlRpcServerBase > mRpc
The abstract base-class for all exceptions thrown by resip code.
const Data & getMessage() const noexcept
static SecurityTypes::SSLType parseSSLType(const Data &typeName)
Converts a string containing an SSL type name to the corresponding enum value.
Abstract base class that provides a basic congestion management interface.
virtual EncodeStream & encodeCurrentState(EncodeStream &strm) const =0
Get the current state of all monitored fifos.to a stream.
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
static const Data Empty
Constant that represents a zero-length data.
unsigned long convertUnsignedLong() const
Data xmlCharDataEncode() const
Performs in-place XML Character Data escaping of a Data.
bool empty() const noexcept
Checks whether the Data is empty.
EncodeStream & urlEncode(EncodeStream &s) const
Escapes a Data to a stream according to HTTP URL encoding rules.
static Data from(const T &x)
Converts from arbitrary other type to Data.
int convertInt() const
Takes the contents of the Data and converts them to an integer.
This is a general-purpose congestion manager.
MetricType
Enumeration of congestion metric types this class supports.
@ WAIT_TIME
The expected service time (the time it takes for new items to be serviced) This is the recommended me...
@ SIZE
The current size of the fifo.
@ TIME_DEPTH
The age of the oldest item in the fifo.
virtual bool updateFifoTolerances(const resip::Data &fifoDescription, MetricType metric, uint32_t maxTolerance)
Update the metric type and tolerances of a given fifo that the GeneralCongestionManager is already aw...
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Provides string-parsing functionality with protection from buffer overflow.
EncodeStream & dump(EncodeStream &strm) const
output current state of the stack - for debug
void clearDnsCache()
Clear the DNS Cache.
void getDnsCacheDump(std::pair< unsigned long, unsigned long > key, GetDnsCacheDumpHandler *handler)
Get a string representation of the DNS Cache.
Transport * addTransport(TransportType protocol, int port, IpVersion version=V4, StunSetting stun=StunDisabled, const Data &ipInterface=Data::Empty, const Data &sipDomainname=Data::Empty, const Data &privateKeyPassPhrase=Data::Empty, SecurityTypes::SSLType sslType=SecurityTypes::DynamicTLS, unsigned transportFlags=0, const Data &certificateFilename="", const Data &privateKeyFilename="", SecurityTypes::TlsClientVerificationMode cvm=SecurityTypes::None, bool useEmailAsSIP=false, std::shared_ptr< WsConnectionValidator >=nullptr, std::shared_ptr< WsCookieContextFactory >=nullptr, const Data &netNs=Data::Empty)
Used by the application to add in a new built-in transport.
void removeTransport(unsigned int transportKey)
Used to remove a previously added transport.
void logDnsCache()
Log the DNS Cache to WarningLog for Debugging.
void zeroOutStatistics()
Resets all of the cumulative statistics counters.
bool pollStatistics()
Immediately polls for statistics to be logged and sent to external handlers, instead of waiting for n...
void loadOut(Payload &payload) const
The base class for Transport classes.
unsigned int getKey() const
virtual void setRcvBufLen(int buflen)
static const Data & toDataLower(TransportType type)
const Data & param(const ExtensionParameter ¶m) const
Const accessor for non-natively-supported parameter types.
const Data & getValue() const
const Data & getTag() const
CongestionManager * getCongestionManager()
Accessor for the CongestionManager object the stack is using.
This Class is used to implement a primitive form of RPC using loose XML formatting.
TlsClientVerificationMode
SSLType
Note: Before adding to the SSLType enum, please see the comments about mTlsCtx in resip/stack/ssl/Sec...
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
std::string getTransportNameFromType(const TransportType typeEnum)
Function which translates a transport enum value to its corrisponding name.
TransportType toTransportType(const resip::Data &transportName)
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
bool isSecure(TransportType type)
Returns true if passed in transport type is a secure transport protocol.
TransportType
An enumeration of transport protocols.
IpVersion
An enumeration of IP versions.