diff --git a/core/AmApi.cpp b/core/AmApi.cpp index 9ea2c0c6..3d3f4af6 100644 --- a/core/AmApi.cpp +++ b/core/AmApi.cpp @@ -104,3 +104,11 @@ AmCtrlInterfaceFactory::AmCtrlInterfaceFactory(const string& name) : AmPluginFactory(name) { } + +AmCtrlInterface::AmCtrlInterface() +{ +} + +AmCtrlInterface::~AmCtrlInterface() +{ +} diff --git a/core/AmApi.h b/core/AmApi.h index 7f62b4c2..698acd89 100644 --- a/core/AmApi.h +++ b/core/AmApi.h @@ -235,17 +235,20 @@ class AmInterfaceHandler; class AmCtrlInterface: public AmThread { public: - AmCtrlInterface() {} - //virtual ~AmCtrlInterface() = 0; - - //@param serKey An out parameter - virtual int send(const AmSipRequest &, string &serKey) = 0; - - virtual int send(const AmSipReply &) = 0; - - virtual string getContact(const string &displayName, - const string &userName, const string &hostName, - const string &uriParams, const string &hdrParams) = 0; + AmCtrlInterface(); + virtual ~AmCtrlInterface(); + + //@param serKey [out] An out parameter + //@param serKeyLen [out] An out parameter + + virtual int send(const AmSipRequest &, + char* serKey, unsigned int& serKeyLen) = 0; + + virtual int send(const AmSipReply &) = 0; + + virtual string getContact(const string &displayName, + const string &userName, const string &hostName, + const string &uriParams, const string &hdrParams) = 0; }; /** diff --git a/core/AmServer.cpp b/core/AmServer.cpp index 2bd4f308..05244ee8 100644 --- a/core/AmServer.cpp +++ b/core/AmServer.cpp @@ -62,9 +62,9 @@ bool AmServer::sendReply(const AmSipReply &reply) return ctrlIface->send(reply); } -bool AmServer::sendRequest(const AmSipRequest &req, string &serKey) +bool AmServer::sendRequest(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen) { - return ctrlIface->send(req, serKey); + return ctrlIface->send(req, serKey, serKeyLen); } string AmServer::getContact(const string &displayName, diff --git a/core/AmServer.h b/core/AmServer.h index e4c7ebaa..52dd97ad 100644 --- a/core/AmServer.h +++ b/core/AmServer.h @@ -66,7 +66,7 @@ public: void regIface(const AmCtrlInterface *i); bool hasIface() { return ctrlIface != NULL; }; - static bool sendRequest(const AmSipRequest &, string &); + static bool sendRequest(const AmSipRequest &, char* serKey, unsigned int& serKeyLen); static bool sendReply(const AmSipReply &); static string getContact(const string &displayName, const string &userName, const string &hostName, diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index 8d913fc7..c6898fd0 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -40,6 +40,11 @@ const char* AmSipDialog::status2str[4] = { "Disconnecting" }; +AmSipDialog::AmSipDialog(AmSipDialogEventHandler* h) + : status(Disconnected),cseq(10),hdl(h), serKeyLen(0) +{ +} + AmSipDialog::~AmSipDialog() { DBG("callid = %s\n",callid.c_str()); @@ -527,9 +532,10 @@ int AmSipDialog::cancel() req.callid = callid; req.cseq = cancel_cseq; //useful for SER-2.0.0 - req.serKey = serKey; - string empty; - return AmServer::sendRequest(req, empty) ? 0 : -1; + req.serKey = string(serKey, serKeyLen); + char empty[MAX_SER_KEY_LEN]; + unsigned int unused = 0; + return AmServer::sendRequest(req, empty, unused) ? 0 : -1; } int AmSipDialog::sendRequest(const string& method, @@ -584,7 +590,7 @@ int AmSipDialog::sendRequest(const string& method, req.body = body; } - if (AmServer::sendRequest(req, serKey)) + if (AmServer::sendRequest(req, serKey, serKeyLen)) return -1; uac_trans[cseq] = AmSipTransaction(method,cseq); diff --git a/core/AmSipDialog.h b/core/AmSipDialog.h index 3e0b0f3b..ca3bec84 100644 --- a/core/AmSipDialog.h +++ b/core/AmSipDialog.h @@ -35,6 +35,7 @@ #include using std::string; +#define MAX_SER_KEY_LEN 30 #define CONTACT_USER_PREFIX "sems" // flags which may be used when sending request/reply @@ -137,12 +138,10 @@ class AmSipDialog int cseq; // CSeq for next request - string serKey; // opaque string returned by SER, when staring a T - - AmSipDialog(AmSipDialogEventHandler* h=0) - : status(Disconnected),cseq(10),hdl(h) - {} + char serKey[MAX_SER_KEY_LEN]; // opaque string returned by SER, when staring a T + unsigned int serKeyLen; + AmSipDialog(AmSipDialogEventHandler* h=0); ~AmSipDialog(); bool getUACTransPending() { return !uac_trans.empty(); } diff --git a/core/plug-in/binrpcctrl/BrpcCtrlInterface.cpp b/core/plug-in/binrpcctrl/BrpcCtrlInterface.cpp index e5a95b01..148ebc3d 100644 --- a/core/plug-in/binrpcctrl/BrpcCtrlInterface.cpp +++ b/core/plug-in/binrpcctrl/BrpcCtrlInterface.cpp @@ -1120,7 +1120,7 @@ static inline brpc_t *build_request(const AmSipRequest &amReq, return req; } -int BrpcCtrlInterface::send(const AmSipRequest &amReq, string &serKey) +int BrpcCtrlInterface::send(const AmSipRequest &amReq, char *serKey, unsigned int &serKeyLen) { int ret = -1; brpc_t *req, *rpl = NULL; @@ -1161,7 +1161,8 @@ int BrpcCtrlInterface::send(const AmSipRequest &amReq, string &serKey) } DBG("SER's opaque/reason: `%.*s'.\n", BRPC_STR_FMT(ser_opaque)); //len must be fed, as the opaque could contain 0s - serKey = string(ser_opaque->val, ser_opaque->len); + memcpy(serKey, ser_opaque->val, ser_opaque->len); + serKeyLen = ser_opaque->len; ret = 0; end: diff --git a/core/plug-in/binrpcctrl/BrpcCtrlInterface.h b/core/plug-in/binrpcctrl/BrpcCtrlInterface.h index b8b642d0..e035cfcf 100644 --- a/core/plug-in/binrpcctrl/BrpcCtrlInterface.h +++ b/core/plug-in/binrpcctrl/BrpcCtrlInterface.h @@ -75,7 +75,7 @@ class BrpcCtrlInterface: public AmCtrlInterface void on_stop() {} // AmCtrlInterface - int send(const AmSipRequest &, string &); + int send(const AmSipRequest &, char *, unsigned int &); int send(const AmSipReply &); string getContact(const string &displayName, diff --git a/core/plug-in/sipctrl/SipCtrlInterface.cpp b/core/plug-in/sipctrl/SipCtrlInterface.cpp index 990c9454..8a22c5c0 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.cpp +++ b/core/plug-in/sipctrl/SipCtrlInterface.cpp @@ -158,8 +158,10 @@ string SipCtrlInterface::getContact(const string &displayName, } #endif -int SipCtrlInterface::send(const AmSipRequest &req, string &serKey) +int SipCtrlInterface::send(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen) { + serKeyLen = 0; + if(req.method == "CANCEL") return cancel(req); @@ -269,12 +271,10 @@ int SipCtrlInterface::send(const AmSipRequest &req, string &serKey) } } - char tid[12]; - - tl->send_request(msg,tid); + tl->send_request(msg,serKey); delete msg; - serKey = string(tid,12); + serKeyLen=12; return 0; } diff --git a/core/plug-in/sipctrl/SipCtrlInterface.h b/core/plug-in/sipctrl/SipCtrlInterface.h index ae33dec8..8eec49d2 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.h +++ b/core/plug-in/sipctrl/SipCtrlInterface.h @@ -81,8 +81,7 @@ public: /** * From AmCtrlInterface */ - - int send(const AmSipRequest &req, string &serKey); + int send(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen); int send(const AmSipReply &rep); #ifndef _STANDALONE diff --git a/core/plug-in/unixsockctrl/UnixCtrlInterface.cpp b/core/plug-in/unixsockctrl/UnixCtrlInterface.cpp index de4f4642..11f519b9 100644 --- a/core/plug-in/unixsockctrl/UnixCtrlInterface.cpp +++ b/core/plug-in/unixsockctrl/UnixCtrlInterface.cpp @@ -130,7 +130,7 @@ int UnixCtrlInterface::init(const string& socket_name) return 0; } -int UnixCtrlInterface::send(const AmSipRequest &req, string &_) +int UnixCtrlInterface::send(const AmSipRequest &req, char *, unsigned int &) { return rplAdapt.send(req, reply_socket_name, ser_socket_name); } diff --git a/core/plug-in/unixsockctrl/UnixCtrlInterface.h b/core/plug-in/unixsockctrl/UnixCtrlInterface.h index c6c79eee..2cd5f21f 100644 --- a/core/plug-in/unixsockctrl/UnixCtrlInterface.h +++ b/core/plug-in/unixsockctrl/UnixCtrlInterface.h @@ -65,7 +65,7 @@ class UnixCtrlInterface : public AmCtrlInterface ~UnixCtrlInterface(); // AmCtrlInterface - int send(const AmSipRequest &, string &); + int send(const AmSipRequest &, char *, unsigned int &); int send(const AmSipReply &); string getContact(const string &displayName,