ANSC_STATUS
BbhmDiageoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PBBHM_DIAG_EXEC_OBJECT          pMyObject    = (PBBHM_DIAG_EXEC_OBJECT)hThisObject;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid                          = BBHM_DIAG_EXEC_OID;
    pMyObject->Create                       = BbhmDiageoCreate;
    pMyObject->Remove                       = BbhmDiageoRemove;
    pMyObject->EnrollObjects                = BbhmDiageoEnrollObjects;
    pMyObject->Initialize                   = BbhmDiageoInitialize;

    pMyObject->bActive                      = FALSE;
    //pMyObject->hDslhDiagInfo                = (ANSC_HANDLE)NULL;
    pMyObject->bResultQueryRunning          = FALSE;

    AnscInitializeLock (&pMyObject->AccessLock);
    AnscInitializeEvent(&pMyObject->ResultQueryEvent);
    AnscInitializeEvent(&pMyObject->ResultQueryExitEvent);

    pMyObject->Reset                        = BbhmDiageoReset;

    pMyObject->Engage                       = BbhmDiageoEngage;
    pMyObject->Cancel                       = BbhmDiageoCancel;

    pMyObject->GetResult                    = BbhmDiageoGetResult;
    pMyObject->GetResultTimeStamp           = BbhmDiageoGetResultTimeStamp;
    pMyObject->SetDiagParams                = BbhmDiageoSetDiagParams;
    pMyObject->SetDiagState                 = BbhmDiageoSetDiagState;

    pMyObject->CopyDiagParams               = BbhmDiageoCopyDiagParams;
    pMyObject->CheckCanStart                = BbhmDiageoCheckCanStart;
    pMyObject->StartDiag                    = BbhmDiageoStartDiag;
    pMyObject->StopDiag                     = BbhmDiageoStopDiag;
    pMyObject->RetrieveResult               = BbhmDiageoRetrieveResult;

    pMyObject->ResultQueryTask              = BbhmDiageoResultQueryTask;

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
StunScoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PSTUN_SIMPLE_CLIENT_OBJECT      pMyObject    = (PSTUN_SIMPLE_CLIENT_OBJECT)hThisObject;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid                       = STUN_SIMPLE_CLIENT_OID;
    pMyObject->Create                    = StunScoCreate;
    pMyObject->Remove                    = StunScoRemove;
    pMyObject->EnrollObjects             = StunScoEnrollObjects;
    pMyObject->Initialize                = StunScoInitialize;

    pMyObject->hStunBsmIf                = (ANSC_HANDLE)NULL;
    pMyObject->AsyncTaskCount            = 0;
    pMyObject->bActive                   = FALSE;

    pMyObject->ClientStage               = STUN_SCO_CLIENT_STAGE_None;
    pMyObject->ClientState               = STUN_SCO_CLIENT_STATE_Idle;
    pMyObject->SocketState1              = STUN_SCO_SOCKET_STATE_Idle;
    pMyObject->SocketStateA              = STUN_SCO_SOCKET_STATE_Idle;
    pMyObject->SocketStateB              = STUN_SCO_SOCKET_STATE_Idle;
    pMyObject->RetransInterval1          = STUN_MIN_RETRANSMISSION_INTERVAL;
    pMyObject->RetransTime1              = 0;
    pMyObject->LastSendMsg1              = NULL;
    pMyObject->LastMsgSize1              = 0;
    pMyObject->bMsgIntegrity1            = FALSE;
    pMyObject->bMsgIntegrityA            = FALSE;
    pMyObject->bMsgIntegrityB            = FALSE;

    pMyObject->GetStunBsmIf              = StunScoGetStunBsmIf;
    pMyObject->SetStunBsmIf              = StunScoSetStunBsmIf;
    pMyObject->GetClientAddr             = StunScoGetClientAddr;
    pMyObject->SetClientAddr             = StunScoSetClientAddr;
    pMyObject->GetClientPort             = StunScoGetClientPort;
    pMyObject->SetClientPort             = StunScoSetClientPort;
    pMyObject->GetServerAddr             = StunScoGetServerAddr;
    pMyObject->SetServerAddr             = StunScoSetServerAddr;
    pMyObject->GetServerPort             = StunScoGetServerPort;
    pMyObject->SetServerPort             = StunScoSetServerPort;
    pMyObject->GetUsername               = StunScoGetUsername;
    pMyObject->SetUsername               = StunScoSetUsername;
    pMyObject->GetPassword               = StunScoGetPassword;
    pMyObject->SetPassword               = StunScoSetPassword;
    pMyObject->GetMinKeepAliveInterval   = StunScoGetMinKeepAliveInterval;
    pMyObject->SetMinKeepAliveInterval   = StunScoSetMinKeepAliveInterval;
    pMyObject->GetMaxKeepAliveInterval   = StunScoGetMaxKeepAliveInterval;
    pMyObject->SetMaxKeepAliveInterval   = StunScoSetMaxKeepAliveInterval;

    pMyObject->GetProperty               = StunScoGetProperty;
    pMyObject->SetProperty               = StunScoSetProperty;
    pMyObject->ResetProperty             = StunScoResetProperty;
    pMyObject->Reset                     = StunScoReset;

    pMyObject->Engage                    = StunScoEngage;
    pMyObject->Cancel                    = StunScoCancel;
    pMyObject->StageTimerInvoke          = StunScoStageTimerInvoke;
    pMyObject->RetryTimerInvoke          = StunScoRetryTimerInvoke;
    pMyObject->ProbeTimerInvoke          = StunScoProbeTimerInvoke;

    pMyObject->PlayRole1                 = StunScoPlayRole1;
    pMyObject->DiscoverBinding           = StunScoDiscoverBinding;
    pMyObject->DiscoverBindingTimeoutA   = StunScoDiscoverBindingTimeoutA;
    pMyObject->DiscoverBindingTimeoutB   = StunScoDiscoverBindingTimeoutB;
    pMyObject->MaintainBinding           = StunScoMaintainBinding;
    pMyObject->NotifyBindingChange       = StunScoNotifyBindingChange;
    pMyObject->AsyncDiscoverTask         = StunScoAsyncDiscoverTask;

    pMyObject->RecvBindingResponse1      = StunScoRecvBindingResponse1;
    pMyObject->RecvBindingResponseA      = StunScoRecvBindingResponseA;
    pMyObject->RecvBindingResponseB      = StunScoRecvBindingResponseB;
    pMyObject->RecvBindingErrorResponse1 = StunScoRecvBindingErrorResponse1;
    pMyObject->RecvBindingErrorResponseA = StunScoRecvBindingErrorResponseA;
    pMyObject->RecvBindingErrorResponseB = StunScoRecvBindingErrorResponseB;
    pMyObject->VerifyMsgIntegrity        = StunScoVerifyMsgIntegrity;

    pMyObject->SendBindingRequest1       = StunScoSendBindingRequest1;
    pMyObject->SendBindingRequestA       = StunScoSendBindingRequestA;
    pMyObject->SendBindingRequestB       = StunScoSendBindingRequestB;

    pMyObject->Scuowo1Query              = StunScoScuowo1Query;
    pMyObject->Scuowo1Process            = StunScoScuowo1Process;
    pMyObject->Scuowo1Notify             = StunScoScuowo1Notify;
    pMyObject->ScuowoAQuery              = StunScoScuowoAQuery;
    pMyObject->ScuowoAProcess            = StunScoScuowoAProcess;
    pMyObject->ScuowoANotify             = StunScoScuowoANotify;
    pMyObject->ScuowoBQuery              = StunScoScuowoBQuery;
    pMyObject->ScuowoBProcess            = StunScoScuowoBProcess;
    pMyObject->ScuowoBNotify             = StunScoScuowoBNotify;

    StunInitBindingInfo((&pMyObject->BindingInfo));

    AnscInitializeEvent(&pMyObject->SocketEventA);
    AnscResetEvent     (&pMyObject->SocketEventA);

    /*
     * We shall initialize the object properties to the default values, which may be changed later
     * via the exposed member functions. If any of the future extensions needs to change the object
     * property, the following code also needs to be changed.
     */
    pMyObject->ResetProperty((ANSC_HANDLE)pMyObject);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
AnscDetoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PANSC_DAEMON_ENGINE_TCP_OBJECT  pMyObject    = (PANSC_DAEMON_ENGINE_TCP_OBJECT)hThisObject;
    ULONG                           i            = 0;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid                 = ANSC_DAEMON_ENGINE_TCP_OID;
    pMyObject->Create              = AnscDetoCreate;
    pMyObject->Remove              = AnscDetoRemove;
    pMyObject->EnrollObjects       = AnscDetoEnrollObjects;
    pMyObject->Initialize          = AnscDetoInitialize;

    pMyObject->hDaemonServer       = (ANSC_HANDLE)NULL;
    pMyObject->CurSocketCount      = 0;
    pMyObject->MaxSocketCount      = ANSC_DETO_MAX_SOCKET_COUNT;
    pMyObject->ControlFlags        = 0;
    pMyObject->StartTime           = 0;
    pMyObject->AvgServingTime      = 0;
    pMyObject->SocketTimeOut       = ANSC_DETO_SOCKET_TIMEOUT;
    pMyObject->bStarted            = FALSE;
    pMyObject->bCleaningDemanded   = FALSE;
    pMyObject->bBusy               = FALSE;

    pMyObject->TtcCount            = 0;
    pMyObject->MtcCount            = 0;
    pMyObject->TrcCount            = 0;
    pMyObject->MrcCount            = 0;
    pMyObject->TscCount            = 0;
    pMyObject->MscCount            = 0;

    pMyObject->GetDaemonServer     = AnscDetoGetDaemonServer;
    pMyObject->SetDaemonServer     = AnscDetoSetDaemonServer;
    pMyObject->GetMaxSocketCount   = AnscDetoGetMaxSocketCount;
    pMyObject->SetMaxSocketCount   = AnscDetoSetMaxSocketCount;
    pMyObject->GetControlFlags     = AnscDetoGetControlFlags;
    pMyObject->SetControlFlags     = AnscDetoSetControlFlags;
    pMyObject->Reset               = AnscDetoReset;

    pMyObject->GetSocketByAddress  = AnscDetoGetSocketByAddress;
    pMyObject->GetSocketByAddress2 = AnscDetoGetSocketByAddress2;
    pMyObject->GetSocketByOsocket  = AnscDetoGetSocketByOsocket;
    pMyObject->GetSocketByOsocket2 = AnscDetoGetSocketByOsocket2;
    pMyObject->AddSocket           = AnscDetoAddSocket;
    pMyObject->DelSocket           = AnscDetoDelSocket;
    pMyObject->DelAllSockets       = AnscDetoDelAllSockets;
    pMyObject->ExpAllSockets       = AnscDetoExpAllSockets;
    pMyObject->EnableRecv          = AnscDetoEnableRecv;
    pMyObject->EnableSend          = AnscDetoEnableSend;

    pMyObject->RecvTask            = AnscDetoRecvTask;
    pMyObject->SendTask            = AnscDetoSendTask;

    pMyObject->Start               = AnscDetoStart;
    pMyObject->Stop                = AnscDetoStop;
    pMyObject->Cancel              = AnscDetoCancel;
    pMyObject->Clean               = AnscDetoClean;
    pMyObject->Snapshot            = AnscDetoSnapshot;
    pMyObject->CloseUp             = AnscDetoCloseUp;

    pMyObject->Recv                = AnscDetoRecv;
    pMyObject->Recv2               = AnscDetoRecv2;
    pMyObject->Send                = AnscDetoSend;
    pMyObject->Send2               = AnscDetoSend2;

    AnscInitializeEvent(&pMyObject->RecvEvent     );
    AnscSetEvent       (&pMyObject->RecvEvent     );
    AnscInitializeEvent(&pMyObject->SendEvent     );
    AnscSetEvent       (&pMyObject->SendEvent     );
    AnscInitializeEvent(&pMyObject->NewSocketEvent);
    AnscResetEvent     (&pMyObject->NewSocketEvent);

    AnscInitializeLock(&pMyObject->RecvSocketSetLock);
    AnscInitializeLock(&pMyObject->SendSocketSetLock);

    for ( i = 0; i < ANSC_DETO_SOCKET_TABLE_SIZE; i++ )
    {
        AnscSListInitializeHeader(&pMyObject->SocketTable[i]);
    }
    AnscInitializeLock(&pMyObject->SocketTableLock);

    AnscQueueInitializeHeader(&pMyObject->PacketQueue    );
    AnscInitializeLock       (&pMyObject->PacketQueueLock);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CcspCwmpsoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SESSION_OBJECT        pMyObject    = (PCCSP_CWMP_SESSION_OBJECT)hThisObject;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid                       = CCSP_CWMP_SESSION_OID;
    pMyObject->Create                    = CcspCwmpsoCreate;
    pMyObject->Remove                    = CcspCwmpsoRemove;
    pMyObject->EnrollObjects             = CcspCwmpsoEnrollObjects;
    pMyObject->Initialize                = CcspCwmpsoInitialize;

    pMyObject->hCcspCwmpCpeController        = (ANSC_HANDLE)NULL;
    pMyObject->hCcspCwmpProcessor         = (ANSC_HANDLE)NULL;
    pMyObject->AsyncTaskCount            = 0;
    pMyObject->bActive                   = FALSE;

    pMyObject->bInformWhenActive         = FALSE;

    pMyObject->GlobalRequestID           = 1;
    pMyObject->SessionState              = CCSP_CWMPSO_SESSION_STATE_idle;
    pMyObject->CpeMaxEnvelopes           = CCSP_CWMP_CPE_MAX_ENVELOPES;
    pMyObject->AcsMaxEnvelopes           = 1;
    pMyObject->ActiveResponses           = 0;
    pMyObject->bHoldRequests             = FALSE;
    pMyObject->bNoMoreRequests           = FALSE;
    pMyObject->bLastEmptyRequestSent     = FALSE;
    pMyObject->EventCount                = 0;
    pMyObject->RetryCount                = 0;
    pMyObject->ModifiedParamCount        = 0;

    pMyObject->GetCcspCwmpAcsConnection  = CcspCwmpsoGetCcspCwmpAcsConnection;
    pMyObject->GetCcspCwmpMcoIf          = CcspCwmpsoGetCcspCwmpMcoIf;
    pMyObject->GetCcspCwmpCpeController  = CcspCwmpsoGetCcspCwmpCpeController;
    pMyObject->SetCcspCwmpCpeController  = CcspCwmpsoSetCcspCwmpCpeController;
    pMyObject->GetCcspCwmpProcessor      = CcspCwmpsoGetCcspCwmpProcessor;
    pMyObject->SetCcspCwmpProcessor      = CcspCwmpsoSetCcspCwmpProcessor;
    pMyObject->Reset                     = CcspCwmpsoReset;

    pMyObject->AcqAccess                 = CcspCwmpsoAcqAccess;
    pMyObject->RelAccess                 = CcspCwmpsoRelAccess;
    pMyObject->SessionTimerInvoke        = CcspCwmpsoSessionTimerInvoke;
    pMyObject->SessionRetryTimerInvoke   = CcspCwmpsoSessionRetryTimerInvoke;
    pMyObject->DelayedActiveNotifTimerInvoke   
										 = CcspCwmpsoDelayedActiveNotifTimerInvoke;
    pMyObject->StartRetryTimer           = CcspCwmpsoStartRetryTimer;
    pMyObject->StopRetryTimer            = CcspCwmpsoStopRetryTimer;
    pMyObject->StopDelayedActiveNotifTimer 
							             = CcspCwmpsoStopDelayedActiveNotifTimer;

    pMyObject->IsAcsConnected            = CcspCwmpsoIsAcsConnected;
    pMyObject->ConnectToAcs              = CcspCwmpsoConnectToAcs;
    pMyObject->CloseConnection           = CcspCwmpsoCloseConnection;

    pMyObject->AddCwmpEvent              = CcspCwmpsoAddCwmpEvent;
    pMyObject->DiscardCwmpEvent          = CcspCwmpsoDiscardCwmpEvent;
    pMyObject->DelAllEvents              = CcspCwmpsoDelAllEvents;
    pMyObject->AddModifiedParameter      = CcspCwmpsoAddModifiedParameter;
    pMyObject->DelAllParameters          = CcspCwmpsoDelAllParameters;
    pMyObject->SaveCwmpEvent             = CcspCwmpsoSaveCwmpEvent;

    pMyObject->GetRpcMethods             = CcspCwmpsoGetRpcMethods;
    pMyObject->Inform                    = CcspCwmpsoInform;
    pMyObject->TransferComplete          = CcspCwmpsoTransferComplete;
    pMyObject->AutonomousTransferComplete= CcspCwmpsoAutonomousTransferComplete;
    pMyObject->Kicked                    = CcspCwmpsoKicked;
    pMyObject->RequestDownload           = CcspCwmpsoRequestDownload;
    pMyObject->DUStateChangeComplete     = CcspCwmpsoDUStateChangeComplete;
    pMyObject->AutonomousDUStateChangeComplete
                                         = CcspCwmpsoAutonomousDUStateChangeComplete;

    pMyObject->RecvSoapMessage           = CcspCwmpsoRecvSoapMessage;
    pMyObject->NotifySessionClosed       = CcspCwmpsoNotifySessionClosed;
    pMyObject->AsyncProcessTask          = CcspCwmpsoAsyncProcessTask;

    pMyObject->CancelRetryDelay          = CcspCwmpsoCancelRetryDelay;

    pMyObject->InformPending             = CcspCwmpsoInformPending;

    AnscInitializeLock       (&pMyObject->AccessLock       );
    AnscQueueInitializeHeader(&pMyObject->AsyncReqQueue    );
    AnscInitializeLock       (&pMyObject->AsyncReqQueueLock);
    AnscQueueInitializeHeader(&pMyObject->SavedReqQueue    );
    AnscInitializeLock       (&pMyObject->SavedReqQueueLock);
    AnscQueueInitializeHeader(&pMyObject->AsyncRepQueue    );
    AnscInitializeLock       (&pMyObject->AsyncRepQueueLock);
    AnscInitializeEvent      (&pMyObject->AsyncProcessEvent);
    AnscResetEvent           (&pMyObject->AsyncProcessEvent);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
HttpWssoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PHTTP_WEBS_SESSION_OBJECT       pMyObject    = (PHTTP_WEBS_SESSION_OBJECT)hThisObject;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid             = HTTP_WEBS_SESSION_OID;
    pMyObject->Create          = HttpWssoCreate;
    pMyObject->Remove          = HttpWssoRemove;
    pMyObject->EnrollObjects   = HttpWssoEnrollObjects;
    pMyObject->Initialize      = HttpWssoInitialize;

    pMyObject->hWspIf          = (ANSC_HANDLE)NULL;
    pMyObject->hHfpIf          = (ANSC_HANDLE)NULL;
    pMyObject->hWebSocket      = (ANSC_HANDLE)NULL;
    pMyObject->SessionState    = HTTP_WSSO_STATE_INITIALIZED;
    pMyObject->ServeCount      = 0;

    pMyObject->GetWspIf        = HttpWssoGetWspIf;
    pMyObject->SetWspIf        = HttpWssoSetWspIf;
    pMyObject->GetHfpIf        = HttpWssoGetHfpIf;
    pMyObject->SetHfpIf        = HttpWssoSetHfpIf;

    pMyObject->GetWebSocket    = HttpWssoGetWebSocket;
    pMyObject->SetWebSocket    = HttpWssoSetWebSocket;
    pMyObject->GetSessionState = HttpWssoGetSessionState;
    pMyObject->SetSessionState = HttpWssoSetSessionState;

    pMyObject->Return          = HttpWssoReturn;
    pMyObject->Reset           = HttpWssoReset;

    pMyObject->Open            = HttpWssoOpen;
    pMyObject->Close           = HttpWssoClose;

    pMyObject->AcquireAccess   = HttpWssoAcquireAccess;
    pMyObject->ReleaseAccess   = HttpWssoReleaseAccess;
    pMyObject->EnterWspServe   = HttpWssoEnterWspServe;
    pMyObject->LeaveWspServe   = HttpWssoLeaveWspServe;
    pMyObject->ClearWspServe   = HttpWssoClearWspServe;
    pMyObject->CloseConnection = HttpWssoCloseConnection;

    pMyObject->GetEndWsto      = HttpWssoGetEndWsto;
    pMyObject->GetCurWsto      = HttpWssoGetCurWsto;
    pMyObject->AddNewWsto      = HttpWssoAddNewWsto;
    pMyObject->DelAllWstos     = HttpWssoDelAllWstos;

    pMyObject->Query           = HttpWssoQuery;
    pMyObject->Recv            = HttpWssoRecv;
    pMyObject->Finish          = HttpWssoFinish;
    pMyObject->Accept          = HttpWssoAccept;

    AnscInitializeEvent      (&pMyObject->ServeEvent   );
    AnscResetEvent           (&pMyObject->ServeEvent   );

    AnscInitializeLock       (&pMyObject->AccessLock   );
    AnscSListInitializeHeader(&pMyObject->WstoSList    );
    AnscInitializeLock       (&pMyObject->WstoSListLock);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
AnscDsuoInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PANSC_DAEMON_SERVER_UDP_OBJECT  pMyObject    = (PANSC_DAEMON_SERVER_UDP_OBJECT)hThisObject;

    /*
     * Until you have to simulate C++ object-oriented programming style with standard C, you don't
     * appreciate all the nice little things come with C++ language and all the dirty works that
     * have been done by the C++ compilers. Member initialization is one of these things. While in
     * C++ you don't have to initialize all the member fields inherited from the base class since
     * the compiler will do it for you, such is not the case with C.
     */
    AnscCoInitialize((ANSC_HANDLE)pMyObject);

    /*
     * Although we have initialized some of the member fields in the "create" member function, we
     * repeat the work here for completeness. While this simulation approach is pretty stupid from
     * a C++/Java programmer perspective, it's the best we can get for universal embedded network
     * programming. Before we develop our own operating system (don't expect that to happen any
     * time soon), this is the way things gonna be.
     */
    pMyObject->Oid                   = ANSC_DAEMON_SERVER_UDP_OID;
    pMyObject->Create                = AnscDsuoCreate;
    pMyObject->Remove                = AnscDsuoRemove;
    pMyObject->EnrollObjects         = AnscDsuoEnrollObjects;
    pMyObject->Initialize            = AnscDsuoInitialize;

    pMyObject->Socket                = ANSC_SOCKET_INVALID_SOCKET;
    pMyObject->hWorker               = (ANSC_HANDLE)NULL;
    pMyObject->MaxMessageSize        = ANSC_DSUO_MAX_MESSAGE_SIZE;
    pMyObject->EngineCount           = ANSC_DSUO_DEF_ENGINE_COUNT;
    pMyObject->hNextEngineToUse      = (ANSC_HANDLE)NULL;
    pMyObject->CurSocketCount        = 0;
    pMyObject->MinSocketCount        = ANSC_DSUO_MIN_SOCKET_COUNT;
    pMyObject->MaxSocketCount        = ANSC_DSUO_MAX_SOCKET_COUNT;
    pMyObject->CurPacketCount        = 0;
    pMyObject->MinPacketCount        = ANSC_DSUO_MIN_PACKET_COUNT;
    pMyObject->MaxPacketCount        = ANSC_DSUO_MAX_PACKET_COUNT;
    pMyObject->SocketTimeOut         = ANSC_DSUO_SOCKET_TIMEOUT;
    pMyObject->PacketTimeOut         = ANSC_DSUO_PACKET_TIMEOUT;
    pMyObject->Mode                  = 0;
    pMyObject->bActive               = FALSE;

    pMyObject->GetHostAddress        = AnscDsuoGetHostAddress;
    pMyObject->SetHostAddress        = AnscDsuoSetHostAddress;
    pMyObject->GetHostPort           = AnscDsuoGetHostPort;
    pMyObject->SetHostPort           = AnscDsuoSetHostPort;

    pMyObject->GetWorker             = AnscDsuoGetWorker;
    pMyObject->SetWorker             = AnscDsuoSetWorker;
    pMyObject->GetMaxMessageSize     = AnscDsuoGetMaxMessageSize;
    pMyObject->SetMaxMessageSize     = AnscDsuoSetMaxMessageSize;
    pMyObject->GetEngineCount        = AnscDsuoGetEngineCount;
    pMyObject->SetEngineCount        = AnscDsuoSetEngineCount;
    pMyObject->GetMinSocketCount     = AnscDsuoGetMinSocketCount;
    pMyObject->SetMinSocketCount     = AnscDsuoSetMinSocketCount;
    pMyObject->GetMaxSocketCount     = AnscDsuoGetMaxSocketCount;
    pMyObject->SetMaxSocketCount     = AnscDsuoSetMaxSocketCount;
    pMyObject->GetMinPacketCount     = AnscDsuoGetMinPacketCount;
    pMyObject->SetMinPacketCount     = AnscDsuoSetMinPacketCount;
    pMyObject->GetMaxPacketCount     = AnscDsuoGetMaxPacketCount;
    pMyObject->SetMaxPacketCount     = AnscDsuoSetMaxPacketCount;
    pMyObject->GetSocketTimeOut      = AnscDsuoGetSocketTimeOut;
    pMyObject->SetSocketTimeOut      = AnscDsuoSetSocketTimeOut;
    pMyObject->GetPacketTimeOut      = AnscDsuoGetPacketTimeOut;
    pMyObject->SetPacketTimeOut      = AnscDsuoSetPacketTimeOut;
    pMyObject->GetMode               = AnscDsuoGetMode;
    pMyObject->SetMode               = AnscDsuoSetMode;
    pMyObject->Reset                 = AnscDsuoReset;

    pMyObject->AcceptTask            = AnscDsuoAcceptTask;
    pMyObject->WorkerTask            = AnscDsuoWorkerTask;

    pMyObject->Engage                = AnscDsuoEngage;
    pMyObject->Cancel                = AnscDsuoCancel;

    pMyObject->StartEngines          = AnscDsuoStartEngines;
    pMyObject->StopEngines           = AnscDsuoStopEngines;

    pMyObject->AcquireSocket         = AnscDsuoAcquireSocket;
    pMyObject->ReleaseSocket         = AnscDsuoReleaseSocket;
    pMyObject->ManufactureSocketPool = AnscDsuoManufactureSocketPool;
    pMyObject->DestroySocketPool     = AnscDsuoDestroySocketPool;

    pMyObject->AcquirePacket         = AnscDsuoAcquirePacket;
    pMyObject->ReleasePacket         = AnscDsuoReleasePacket;
    pMyObject->ManufacturePacketPool = AnscDsuoManufacturePacketPool;
    pMyObject->DestroyPacketPool     = AnscDsuoDestroyPacketPool;

    pMyObject->AssignEngine          = AnscDsuoAssignEngine;
    pMyObject->ManufactureEnginePool = AnscDsuoManufactureEnginePool;
    pMyObject->DestroyEnginePool     = AnscDsuoDestroyEnginePool;

    pMyObject->Query                 = AnscDsuoQuery;
    pMyObject->ProcessSync           = AnscDsuoProcessSync;
    pMyObject->ProcessAsync          = AnscDsuoProcessAsync;

    AnscInitializeLock       (&pMyObject->OpLock     );
    AnscInitializeEvent      (&pMyObject->AcceptEvent);
    AnscSetEvent             (&pMyObject->AcceptEvent);

    AnscInitializeLock       (&pMyObject->EngineArrayLock);
    AnscSListInitializeHeader(&pMyObject->SocketSList    );
    AnscInitializeLock       (&pMyObject->SocketSListLock);
    AnscSListInitializeHeader(&pMyObject->PacketSList    );
    AnscInitializeLock       (&pMyObject->PacketSListLock);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CcspCwmpAcscoRequest
    (
        ANSC_HANDLE                 hThisObject,
        char*                       pSoapMessage,
        char*                       pMethodName,
        ULONG                       ulReqEnvCount,
        ULONG                       ulRepEnvCount
    )
{
    PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject      = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject;
    PHTTP_SIMPLE_CLIENT_OBJECT      pHttpClient     = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient;
    PCCSP_CWMP_SESSION_OBJECT       pWmpSession     = (PCCSP_CWMP_SESSION_OBJECT   )pMyObject->hCcspCwmpSession;
    PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT)pWmpSession->hCcspCwmpCpeController;
    PCCSP_CWMP_STAT_INTERFACE       pCcspCwmpStatIf = (PCCSP_CWMP_STAT_INTERFACE)pCcspCwmpCpeController->hCcspCwmpStaIf;
	PCCSP_CWMP_CFG_INTERFACE		pCcspCwmpCfgIf	= (PCCSP_CWMP_CFG_INTERFACE)pCcspCwmpCpeController->hCcspCwmpCfgIf;
    PCCSP_CWMP_MCO_INTERFACE        pCcspCwmpMcoIf  = (PCCSP_CWMP_MCO_INTERFACE        )pWmpSession->hCcspCwmpMcoIf;
    PHTTP_HFP_INTERFACE             pHttpHfpIf      = (PHTTP_HFP_INTERFACE)pHttpClient->GetHfpIf((ANSC_HANDLE)pHttpClient);
    PHTTP_CAS_INTERFACE             pHttpCasIf      = NULL;
    PHTTP_REQUEST_URI               pHttpReqInfo    = NULL;
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PANSC_ACS_INTERN_HTTP_CONTENT   pHttpGetReq     = &intHttpContent;
    BOOL                            bApplyTls       = FALSE;
    PCHAR                           pRequestURL     = NULL;
    PCHAR                           pTempString     = NULL;
    PHTTP_AUTH_CLIENT_OBJECT        pAuthClientObj  = NULL;
    char                            pNewUrl[257]    = { 0 };
    ULONG                           uRedirect       = 0;
    ULONG                           uMaxRedirect    = 5;
	ULONG							ulRpcCallTimeout= CCSP_CWMPSO_RPCCALL_TIMEOUT; 

    /* If the response is 401 authentication required, we need to try again */
    int                             nMaxAuthRetries = 2;

    if( pMyObject->AcsUrl == NULL || AnscSizeOfString(pMyObject->AcsUrl) <= 10 || pHttpHfpIf == NULL)
    {
        return ANSC_STATUS_NOT_READY;
    }

    AnscZeroMemory(pHttpGetReq, sizeof(ANSC_ACS_INTERN_HTTP_CONTENT));

    CcspTr069PaTraceDebug(("CcspCwmpAcscoRequest -- AcsUrl = '%s'\n", pMyObject->AcsUrl));

    pHttpCasIf  = (PHTTP_CAS_INTERFACE)pHttpClient->GetCasIf((ANSC_HANDLE)pHttpClient);

    if ( pHttpCasIf != NULL)
    {
        if( pMyObject->Username == NULL || AnscSizeOfString(pMyObject->Username) == 0)
        {
            pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, FALSE);
        }
        else
        {
            pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, TRUE);

            pAuthClientObj  = (PHTTP_AUTH_CLIENT_OBJECT)pHttpClient->GetClientAuthObj((ANSC_HANDLE)pHttpClient);

            if ( pAuthClientObj != NULL)
            {
                pAuthClientObj->SetAcmIf((ANSC_HANDLE)pAuthClientObj, (ANSC_HANDLE)pMyObject->hHttpAcmIf);
            }
            else
            {
                CcspTr069PaTraceError(("Failed to Get HttpAuthClient object.\n"));
            }
        }
    }

#ifdef   _DEBUG
    if ( !pSoapMessage )
    {
        CcspTr069PaTraceDebug(("CPE Request:\n<EMPTY>\n"));
    }
    else if ( AnscSizeOfString(pSoapMessage) <= CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH )
    {
        CcspTr069PaTraceDebug(("CPE Request:\n%s\n", pSoapMessage));
    }
    else
    {
        char                        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+1+8];

        AnscCopyMemory(partSoap, pSoapMessage, CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH);
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH] = '\n';
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+1] = '.';
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+2] = '.';
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+3] = '.';
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+4] = '\n';
        partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+5] = 0;
        CcspTr069PaTraceDebug(("CPE Request:\n%s\n", partSoap));
    }
#endif
    
START:
    pRequestURL = pMyObject->AcsUrl;

    pHttpReqInfo =
        (PHTTP_REQUEST_URI)pHttpHfpIf->ParseHttpUrl
            (
                pHttpHfpIf->hOwnerContext,
                pRequestURL,
                AnscSizeOfString(pRequestURL)
            );

    if ( !pHttpReqInfo )
    {
        return ANSC_STATUS_INTERNAL_ERROR;
    }

    pHttpReqInfo->Type = HTTP_URI_TYPE_ABS_PATH;

    /* init the request */
    AnscZeroMemory(pHttpGetReq, sizeof(ANSC_ACS_INTERN_HTTP_CONTENT));
    pHttpGetReq->bIsRedirect    = FALSE;
    pHttpGetReq->SoapMessage    = pSoapMessage;

    /* When there is more than one envelope in a single HTTP Request,
     * when there is a SOAP response in an HTTP Request, or when there is a
     * SOAP Fault response in an HTTP Request, the SOAPAction header in the
     * HTTP Request MUST have no value (with no quotes), indicating that this
     * header provides no information as to the intent of the message."
     */
    if( ulReqEnvCount == 1 && ulRepEnvCount == 0)
    {
        pHttpGetReq->MethodName     = pMethodName;
    }

    AnscInitializeEvent(&pHttpGetReq->CompleteEvent);

    while ( nMaxAuthRetries > 0 )
    {
        CcspTr069PaTraceInfo(("ACS Request now at: %u\n", (unsigned int)AnscGetTickInSeconds()));

        if ( AnscEqualString2(pRequestURL, "https", 5, FALSE) )
        {
            bApplyTls = TRUE;
        }
        else if ( AnscEqualString2(pRequestURL, "http", 4, FALSE) )
        {
            if ( bIsComcastImage() ){                
#ifdef _SUPPORT_HTTP
               CcspTr069PaTraceInfo(("HTTP request from ACS is supported\n"));
               bApplyTls = FALSE;
#else
               CcspTr069PaTraceInfo(("TR-069 blocked unsecured traffic from ACS\n"));
               pHttpGetReq->CompleteStatus = ANSC_STATUS_NOT_SUPPORTED;
               pHttpGetReq->bUnauthorized = TRUE;
               pHttpGetReq->bIsRedirect = FALSE;
               break;
#endif
            }
            else {
               bApplyTls = FALSE; 
            }
        }
        else
        {
             pHttpGetReq->CompleteStatus = ANSC_STATUS_NOT_SUPPORTED;
             pHttpGetReq->bUnauthorized = FALSE;
             pHttpGetReq->bIsRedirect = FALSE;
             break;
        }

        if(pHttpGetReq->pContent != NULL)
        {
            CcspTr069PaFreeMemory(pHttpGetReq->pContent);

            pHttpGetReq->pContent = NULL;
        }

        pHttpGetReq->CompleteStatus = ANSC_STATUS_FAILURE;
        pHttpGetReq->bUnauthorized  = FALSE;
        AnscResetEvent     (&pHttpGetReq->CompleteEvent);

        returnStatus =
            pHttpClient->Request
                (
                    (ANSC_HANDLE)pHttpClient,
                    (ULONG      )HTTP_METHOD_CODE_POST,
                    (ANSC_HANDLE)pHttpReqInfo,
                    (ANSC_HANDLE)pHttpGetReq,
                    bApplyTls
                );

        if( returnStatus != ANSC_STATUS_SUCCESS)
        {
            CcspTr069PaTraceError(("ACS Request failed: returnStatus = %.X\n", (unsigned int)returnStatus));
			break;
        }

		if ( pCcspCwmpCfgIf && pCcspCwmpCfgIf->GetCwmpRpcTimeout )
		{
			ulRpcCallTimeout = pCcspCwmpCfgIf->GetCwmpRpcTimeout(pCcspCwmpCfgIf->hOwnerContext);	
			if ( ulRpcCallTimeout < CCSP_CWMPSO_RPCCALL_TIMEOUT )
			{
				ulRpcCallTimeout = CCSP_CWMPSO_RPCCALL_TIMEOUT;
			}
		}

        AnscWaitEvent(&pHttpGetReq->CompleteEvent, ulRpcCallTimeout * 1000);
        if ( pHttpGetReq->CompleteStatus == ANSC_STATUS_SUCCESS && pHttpGetReq->bUnauthorized && nMaxAuthRetries > 0 )
        {
            CcspTr069PaTraceError(("ACS Request is not authenticated, try again.\n"));
            nMaxAuthRetries --;
			
#ifdef _ANSC_USE_OPENSSL_
            if( bApplyTls )
        	{
	        	if ( ANSC_STATUS_SUCCESS == CcspTr069PaSsp_GetTr069CertificateLocationForSyndication( &openssl_client_ca_certificate_files ) )
        		{
					openssl_load_ca_certificates( SSL_CLIENT_CALLS );
        		}
        	}
#endif /* _ANSC_USE_OPENSSL_ */
        }
        else
        {
            CcspTr069PaTraceInfo(("ACS Request has completed with status code %lu, at %lu\n", pHttpGetReq->CompleteStatus, AnscGetTickInSeconds()));

            break;
        }
    }

    /* AnscResetEvent (&pHttpGetReq->CompleteEvent); */
    AnscFreeEvent(&pHttpGetReq->CompleteEvent);

    CcspTr069PaFreeMemory(pHttpReqInfo);

    if ( pHttpGetReq->CompleteStatus != ANSC_STATUS_SUCCESS )
    {
        if ( pHttpGetReq->CompleteStatus == ANSC_STATUS_RESET_SESSION )
        {
            goto  REDIRECTED;
        }
        else
        {
            returnStatus = pHttpGetReq->CompleteStatus;

            goto  EXIT;
        }
    }
    else if( pHttpGetReq->bUnauthorized)
    {
        returnStatus = ANSC_STATUS_FAILURE;

        if( pCcspCwmpStatIf)
        {
            pCcspCwmpStatIf->IncTcpFailure(pCcspCwmpStatIf->hOwnerContext);
        }

        goto EXIT;
    }

REDIRECTED:
    if( pHttpGetReq->bIsRedirect)
    {
        if( _ansc_strstr((PCHAR)pHttpGetReq->pContent, "http") == pHttpGetReq->pContent)
        {
            if ( pMyObject->AcsUrl ) CcspTr069PaFreeMemory(pMyObject->AcsUrl);
            pMyObject->AcsUrl = CcspTr069PaCloneString(pHttpGetReq->pContent);
        }
        else
        {
            /* if it's partial path */
            pTempString = _ansc_strstr(pRequestURL, "//");

            if( pTempString == NULL)
            {
                returnStatus = ANSC_STATUS_FAILURE;

                goto EXIT;
            }

            pTempString += AnscSizeOfString("//");
            pTempString  = _ansc_strstr(pTempString, "/");

            if( pTempString == NULL)
            {
                returnStatus = ANSC_STATUS_FAILURE;

                goto EXIT;
            }

            AnscCopyMemory(pNewUrl, pRequestURL, (ULONG)(pTempString - pRequestURL));
            AnscCatString(pNewUrl, (PCHAR)pHttpGetReq->pContent);

            if ( pMyObject->AcsUrl ) CcspTr069PaFreeMemory(pMyObject->AcsUrl);
            pMyObject->AcsUrl = CcspTr069PaCloneString(pNewUrl);
        }

        uRedirect ++;

        if( uRedirect >= uMaxRedirect)
        {
            CcspTr069PaTraceDebug(("Maximum Redirection reached. Give up!\n"));

            returnStatus = ANSC_STATUS_FAILURE;

            goto EXIT;
        }
        else
        {
            CcspTr069PaTraceDebug(("Acs connection redirection #%u: '%s'\n", (unsigned int)uRedirect, pMyObject->AcsUrl));

            /* in case redirected ACS challenges CPE again */
            nMaxAuthRetries = 2;

            /* tear down current HTTP session before redirecting to new ACS,
             * otherwise, there might be case that ACS sends out redirection
             * response and immediately closes the socket, CWMP may be 
             * confused by closing CWMP session prematurely. 
             */
            pHttpClient->DelAllWcsos((ANSC_HANDLE)pHttpClient);

            goto START;
        }
    }

    if(pWmpSession != NULL)
    {
        if( pHttpGetReq->ulContentSize > 0 && pHttpGetReq->pContent != NULL)
        {
            CcspTr069PaTraceDebug(("Response:\n%s\n", (char*)pHttpGetReq->pContent));

            returnStatus =
                pWmpSession->RecvSoapMessage
                    (
                       pWmpSession,
                       (PCHAR)pHttpGetReq->pContent
                    );
        }
        else
        {
            CcspTr069PaTraceDebug(("Response: <EMPTY>\n"));

            returnStatus =
                pCcspCwmpMcoIf->NotifyAcsStatus
                    (
                        pCcspCwmpMcoIf->hOwnerContext,
                        TRUE,           /* no more requests */
                        FALSE
                    );
        }
    }

EXIT:

    if(pHttpGetReq->pContent != NULL)
    {
        CcspTr069PaFreeMemory(pHttpGetReq->pContent);

        pHttpGetReq->pContent = NULL;
    }

    /******************************************************************
                GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS
    ******************************************************************/

    return returnStatus;
}