reSIProcate/DialogUsageManager  9694
ServerOutOfDialogReq.cxx
Go to the documentation of this file.
00001 #include "resip/stack/SipMessage.hxx"
00002 #include "resip/stack/MethodTypes.hxx"
00003 #include "resip/dum/ServerOutOfDialogReq.hxx"
00004 #include "resip/dum/OutOfDialogHandler.hxx"
00005 #include "resip/dum/DialogUsageManager.hxx"
00006 #include "resip/dum/Dialog.hxx"
00007 #include "resip/dum/MasterProfile.hxx"
00008 #include "rutil/Logger.hxx"
00009 #include "rutil/WinLeakCheck.hxx"
00010 
00011 using namespace resip;
00012 
00013 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
00014 
00015 ServerOutOfDialogReqHandle 
00016 ServerOutOfDialogReq::getHandle()
00017 {
00018    return ServerOutOfDialogReqHandle(mDum, getBaseHandle().getId());
00019 }
00020 
00021 
00022 ServerOutOfDialogReq::ServerOutOfDialogReq(DialogUsageManager& dum,
00023                                            DialogSet& dialogSet,
00024                                            const SipMessage& req)
00025    : NonDialogUsage(dum, dialogSet),
00026      mResponse(new SipMessage)
00027 {
00028 
00029 }
00030 
00031 ServerOutOfDialogReq::~ServerOutOfDialogReq()
00032 {
00033    mDialogSet.mServerOutOfDialogRequest = 0;
00034 }
00035 
00036 void
00037 ServerOutOfDialogReq::end()
00038 {
00039    delete this;
00040 }
00041 
00042 void 
00043 ServerOutOfDialogReq::dispatch(const SipMessage& msg)
00044 {
00045         assert(msg.isRequest());
00046 
00047         OutOfDialogHandler *pHandler = mDum.getOutOfDialogHandler(msg.header(h_CSeq).method());
00048         if(pHandler != NULL)
00049         {
00050                 // Let handler deal with message
00051                 mRequest = msg; 
00052             DebugLog ( << "ServerOutOfDialogReq::dispatch - handler found for " << getMethodName(msg.header(h_CSeq).method()) << " method.");   
00053                 pHandler->onReceivedRequest(getHandle(), msg);  // Wait for application to send response
00054         }
00055         else
00056         {
00057                 if(msg.header(h_CSeq).method() == OPTIONS)
00058                 {
00059            DebugLog ( << "ServerOutOfDialogReq::dispatch - handler not found for OPTIONS - sending autoresponse.");   
00060                         // If no handler exists for OPTIONS then handle internally
00061                         mRequest = msg; 
00062                         mDum.send(answerOptions());
00063                         delete this;
00064                 }
00065                 else
00066                 {
00067            DebugLog ( << "ServerOutOfDialogReq::dispatch - handler not found for " << getMethodName(msg.header(h_CSeq).method()) << " method - sending 405.");   
00068                         // No handler found for out of dialog request - return a 405
00069                         mDum.makeResponse(*mResponse, msg, 405);
00070                         mDum.send(mResponse);
00071                         delete this;
00072                 }
00073         }
00074 }
00075 
00076 void
00077 ServerOutOfDialogReq::dispatch(const DumTimeout& msg)
00078 {
00079 }
00080 
00081 SharedPtr<SipMessage>
00082 ServerOutOfDialogReq::answerOptions()
00083 {
00084         mDum.makeResponse(*mResponse, mRequest, 200);
00085 
00086         // Add in Allow, Accept, Accept-Encoding, Accept-Language, and Supported Headers from Profile
00087         mResponse->header(h_Allows) = mDum.getMasterProfile()->getAllowedMethods();
00088         mResponse->header(h_Accepts) = mDum.getMasterProfile()->getSupportedMimeTypes(INVITE);
00089         mResponse->header(h_AcceptEncodings) = mDum.getMasterProfile()->getSupportedEncodings();
00090         mResponse->header(h_AcceptLanguages) = mDum.getMasterProfile()->getSupportedLanguages();
00091         mResponse->header(h_AllowEvents) = mDum.getMasterProfile()->getAllowedEvents();
00092         mResponse->header(h_Supporteds) = mDum.getMasterProfile()->getSupportedOptionTags();
00093 
00094         return mResponse;
00095 }
00096 
00097 void 
00098 ServerOutOfDialogReq::send(SharedPtr<SipMessage> response)
00099 {
00100    assert(response->isResponse());
00101    mDum.send(response);
00102    delete this;
00103 }
00104 
00105 SharedPtr<SipMessage>
00106 ServerOutOfDialogReq::accept(int statusCode)
00107 {   
00109    mDum.makeResponse(*mResponse, mRequest, statusCode);
00110    return mResponse;
00111 }
00112 
00113 SharedPtr<SipMessage>
00114 ServerOutOfDialogReq::reject(int statusCode)
00115 {
00117    mDum.makeResponse(*mResponse, mRequest, statusCode);
00118    return mResponse;
00119 }
00120 
00121 EncodeStream& 
00122 ServerOutOfDialogReq::dump(EncodeStream& strm) const
00123 {
00124    if(mRequest.exists(h_CSeq))
00125    {
00126       strm << "ServerOutOfDialogReq " << getMethodName(mRequest.header(h_RequestLine).method()) 
00127            << " cseq=" << mRequest.header(h_CSeq).sequence();
00128    }
00129    else
00130    {
00131       strm << "ServerOutOfDialogReq, dispatch has not occured yet.";
00132    }
00133    return strm;
00134 }
00135 
00136 /* ====================================================================
00137  * The Vovida Software License, Version 1.0 
00138  * 
00139  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00140  * 
00141  * Redistribution and use in source and binary forms, with or without
00142  * modification, are permitted provided that the following conditions
00143  * are met:
00144  * 
00145  * 1. Redistributions of source code must retain the above copyright
00146  *    notice, this list of conditions and the following disclaimer.
00147  * 
00148  * 2. Redistributions in binary form must reproduce the above copyright
00149  *    notice, this list of conditions and the following disclaimer in
00150  *    the documentation and/or other materials provided with the
00151 
00152  *    distribution.
00153  * 
00154  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00155  *    and "Vovida Open Communication Application Library (VOCAL)" must
00156  *    not be used to endorse or promote products derived from this
00157  *    software without prior written permission. For written
00158  *    permission, please contact vocal@vovida.org.
00159  *
00160  * 4. Products derived from this software may not be called "VOCAL", nor
00161  *    may "VOCAL" appear in their name, without prior written
00162  *    permission of Vovida Networks, Inc.
00163  * 
00164  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00165  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00166  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00167  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00168  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00169  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00170  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00171  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00172  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00173  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00174  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00175  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00176  * DAMAGE.
00177  * 
00178  * ====================================================================
00179  * 
00180  * This software consists of voluntary contributions made by Vovida
00181  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00182  * Inc.  For more information on Vovida Networks, Inc., please see
00183  * <http://www.vovida.org/>.
00184  *
00185  */
00186