#include class SipServer: public OsServerTask { public: SipServer(char *ip, int port, int vb); ~SipServer(); virtual UtlBoolean handleMessage(OsMsg& eventMessage); SipUserAgent *endPoint; private: int mvb; OsMsgQ* queue; }; UtlBoolean SipServer::handleMessage(OsMsg& eventMessage) { int msgType = eventMessage.getMsgType(); int msgSubType = eventMessage.getMsgSubType(); int seq; UtlBoolean ret = TRUE; if ((msgType == OsMsg::PHONE_APP) && (msgSubType == SipMessage::NET_SIP_MESSAGE)) { const SipMessage* sipMsg = ((SipMessageEvent&)eventMessage).getMessage(); UtlString method; if (sipMsg->isResponse()) { return ret; } if (sipMsg->getCSeqField(&seq, &method)) { if (0==method.compareTo(SIP_INVITE_METHOD, UtlString::ignoreCase)) { if (mvb) { UtlString data; int len; sipMsg->getBytes(&data,&len); printf(data.data()); } SipMessage Response; Response.setInviteBusyData(sipMsg); endPoint->send(Response); } } } return ret; } SipServer::SipServer(char *ip, int port, int vb) { endPoint = new SipUserAgent(port,port,0, ip, "sipX", ip); endPoint->addMessageObserver(*this->getMessageQueue(), NULL, TRUE, TRUE, TRUE, FALSE); mvb = vb; endPoint->allowMethod(SIP_INVITE_METHOD); endPoint->allowMethod(SIP_ACK_METHOD); endPoint->allowMethod(SIP_CANCEL_METHOD); endPoint->allowMethod(SIP_BYE_METHOD); endPoint->allowMethod(SIP_REFER_METHOD); endPoint->allowMethod(SIP_OPTIONS_METHOD); endPoint->start(); start(); } SipServer::~SipServer() { delete endPoint; } #include #include typedef void (*sighandler_t)(int); static int R = 1; static int handle_SIGINT(int sig) { R = 0; return 0; } int main(int argc, char *argv[]) { SipServer *Server; char *ip = "127.0.0.1"; int port = 5060; int vb = 0; if (argc > 1) { ip = argv[1]; } if (argc > 2) { port = atoi(argv[2]); } if (argc > 3) { vb = 1; } Server = new SipServer(ip, port, vb); signal(SIGINT, (sighandler_t) handle_SIGINT); while(R) { usleep(1000); sched_yield(); } printf("ShutDown\n"); usleep(2000000); delete Server; printf("DONE\n"); }