Skip to content
Snippets Groups Projects
Commit 5402e58e authored by yanmorin's avatar yanmorin
Browse files

ResponseMessage encoding fix
Hangup response fix
parent a395bfe0
Branches
Tags
No related merge requests found
...@@ -35,8 +35,8 @@ public: ...@@ -35,8 +35,8 @@ public:
/* Parent class to child class */ /* Parent class to child class */
virtual int incomingCall (short id, const std::string& accountId, const std::string& from) = 0; virtual int incomingCall (short id, const std::string& accountId, const std::string& from) = 0;
virtual void peerAnsweredCall (short id) = 0; virtual void peerAnsweredCall (short id) = 0;
virtual int peerRingingCall (short id) = 0; virtual void peerRingingCall (short id) = 0;
virtual int peerHungupCall (short id) = 0; virtual void peerHungupCall (short id) = 0;
virtual void displayStatus (const std::string& status) = 0; virtual void displayStatus (const std::string& status) = 0;
virtual void displayConfigError (const std::string& error) = 0; virtual void displayConfigError (const std::string& error) = 0;
virtual void displayTextMessage (short id, const std::string& message) = 0; virtual void displayTextMessage (short id, const std::string& message) = 0;
......
...@@ -244,6 +244,10 @@ GUIServerImpl::hangupCall(const std::string& callId) ...@@ -244,6 +244,10 @@ GUIServerImpl::hangupCall(const std::string& callId)
return false; return false;
} }
/*
* we hangup everything in callmap, and flush it
* @return false if atleast one hangup failed
*/
bool bool
GUIServerImpl::hangupAll() GUIServerImpl::hangupAll()
{ {
...@@ -303,8 +307,7 @@ GUIServerImpl::incomingCall (short id, const std::string& accountId, const std:: ...@@ -303,8 +307,7 @@ GUIServerImpl::incomingCall (short id, const std::string& accountId, const std::
insertSubCall(id, subcall); insertSubCall(id, subcall);
_requestManager.sendResponse(ResponseMessage("001", _getEventsSequenceId, _requestManager.sendResponse(ResponseMessage("001", _getEventsSequenceId,arg));
arg));
return 0; return 0;
} }
...@@ -315,39 +318,32 @@ GUIServerImpl::peerAnsweredCall (short id) ...@@ -315,39 +318,32 @@ GUIServerImpl::peerAnsweredCall (short id)
CallMap::iterator iter = _callMap.find(id); CallMap::iterator iter = _callMap.find(id);
if ( iter != _callMap.end() ) { if ( iter != _callMap.end() ) {
_requestManager.sendResponse(ResponseMessage("200", iter->second.sequenceId(), "OK")); _requestManager.sendResponse(ResponseMessage("200", iter->second.sequenceId(), "OK"));
} else {
std::ostringstream responseMessage;
responseMessage << "Peer Answered Call: " << id;
_requestManager.sendResponse(ResponseMessage("500", _getEventsSequenceId,
responseMessage.str()));
} }
} }
int void
GUIServerImpl::peerRingingCall (short id) GUIServerImpl::peerRingingCall (short id)
{ {
CallMap::iterator iter = _callMap.find(id); CallMap::iterator iter = _callMap.find(id);
if ( iter != _callMap.end() ) { if ( iter != _callMap.end() ) {
_requestManager.sendResponse(ResponseMessage("151", iter->second.sequenceId(), "Ringing")); _requestManager.sendResponse(ResponseMessage("151", iter->second.sequenceId(), "Ringing"));
} }
return 0;
} }
int void
GUIServerImpl::peerHungupCall (short id) GUIServerImpl::peerHungupCall (short id)
{ {
CallMap::iterator iter = _callMap.find(id); CallMap::iterator iter = _callMap.find(id);
if ( iter != _callMap.end() ) { if ( iter != _callMap.end() ) {
std::ostringstream responseMessage; TokenList tk;
responseMessage << iter->second.callId() << " hangup"; tk.push_back(iter->second.callId());
tk.push_back("hangup");
_requestManager.sendResponse(ResponseMessage("002", _getEventsSequenceId, _requestManager.sendResponse(ResponseMessage("002", _getEventsSequenceId,tk));
responseMessage.str()));
// remove this call... // remove this call...
_callMap.erase(id); _callMap.erase(id);
} }
return 0;
} }
void void
...@@ -453,9 +449,10 @@ GUIServerImpl::callFailure(short id) ...@@ -453,9 +449,10 @@ GUIServerImpl::callFailure(short id)
{ {
CallMap::iterator iter = _callMap.find(id); CallMap::iterator iter = _callMap.find(id);
if ( iter != _callMap.end() ) { if ( iter != _callMap.end() ) {
std::ostringstream responseMessage; TokenList tk;
responseMessage << iter->second.callId() << " Wrong number"; tk.push_back(iter->second.callId());
tk.push_back("Wrong number");
_requestManager.sendResponse(ResponseMessage("504", iter->second.sequenceId(), responseMessage.str())); _requestManager.sendResponse(ResponseMessage("504", iter->second.sequenceId(), tk));
} }
} }
...@@ -44,8 +44,8 @@ public: ...@@ -44,8 +44,8 @@ public:
int incomingCall(short id, const std::string& accountId, const std::string& from); int incomingCall(short id, const std::string& accountId, const std::string& from);
void peerAnsweredCall (short id); void peerAnsweredCall (short id);
int peerRingingCall (short id); void peerRingingCall (short id);
int peerHungupCall (short id); void peerHungupCall (short id);
void displayStatus (const std::string& status); void displayStatus (const std::string& status);
void displayConfigError(const std::string& error); void displayConfigError(const std::string& error);
void displayTextMessage (short id, const std::string& message); void displayTextMessage (short id, const std::string& message);
......
...@@ -29,14 +29,8 @@ ResponseMessage::ResponseMessage(const std::string& code, ...@@ -29,14 +29,8 @@ ResponseMessage::ResponseMessage(const std::string& code,
const std::string& seq, const std::string& seq,
const std::string& message) : _code(code), _seq(seq) const std::string& message) : _code(code), _seq(seq)
{ {
int len = message.length(); _message = "";
if (len) { appendMessage(message);
char *tmp = new char[len*3+2];
ost::urlEncode(message.c_str(), tmp, len*3+2);
// we don't have to put a '\0' right?
_message = tmp;
delete [] tmp; tmp = NULL;
}
} }
/* /*
...@@ -49,20 +43,13 @@ ResponseMessage::ResponseMessage(const std::string& code, ...@@ -49,20 +43,13 @@ ResponseMessage::ResponseMessage(const std::string& code,
{ {
TokenList::iterator iter=arg.begin(); TokenList::iterator iter=arg.begin();
if (iter!=arg.end()) { if (iter!=arg.end()) {
_message = *iter; appendMessage(*iter);
iter++; iter++;
} }
// add space between each // add space between each
while(iter!=arg.end()) { while(iter!=arg.end()) {
_message.append(" "); _message.append(" ");
int len = iter->length(); appendMessage(*iter);
if (len) {
char *tmp = new char[len*3+2];
ost::urlEncode(iter->c_str(), tmp, len*3+2);
// we don't have to put a '\0' right?
_message.append(tmp);
delete [] tmp; tmp = NULL;
}
iter++; iter++;
} }
} }
...@@ -102,4 +89,16 @@ ResponseMessage::isFinal() const ...@@ -102,4 +89,16 @@ ResponseMessage::isFinal() const
return final; return final;
} }
void
ResponseMessage::appendMessage(const std::string& strToken)
{
int len = strToken.length();
if (len) {
char *tmp = new char[len*3+2];
ost::urlEncode(strToken.c_str(), tmp, len*3+2);
// we don't have to put a '\0' right?
_message.append(tmp);
delete [] tmp; tmp = NULL;
}
}
...@@ -42,7 +42,10 @@ public: ...@@ -42,7 +42,10 @@ public:
std::string toString() const; std::string toString() const;
bool isFinal() const; bool isFinal() const;
private: private:
// 3 numbers long sequenceId // append an encoded string to the message
void appendMessage(const std::string& strToken);
// 3 numbers long code
std::string _code; std::string _code;
std::string _seq; std::string _seq;
std::string _message; std::string _message;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment