Ejemplo n.º 1
0
wxTreeItemId SessionTreeControl::findSession( wxTreeItemId root,
                                                std::string address )
{
    wxTreeItemIdValue temp; // unused var, needed in getchild
    wxTreeItemId targetItem;
    wxTreeItemId current = GetFirstChild( root, temp );

    while ( current.IsOk() )
    {
        wxString text = GetItemText( current );
        std::string target = std::string( text.char_str() );
        if ( target.compare( address ) == 0 )
            return current;

        if ( ItemHasChildren( current ) )
        {
            targetItem = findSession( current, address );
            if ( targetItem.IsOk() )
                return targetItem;
        }
        current = GetNextChild( root, temp );
    }

    wxTreeItemId none;
    return none; // return default value if not found
}
Ejemplo n.º 2
0
void SessionTreeControl::removeSession( std::string address )
{
    wxTreeItemId item = findSession( rootID, address );
    if ( !item.IsOk() )
    {
        gravUtil::logWarning( "SessionTreeControl::removeObject: "
                "item %s not found?\n", address.c_str() );
        return;
    }

    SessionType type;
    wxTreeItemId parent = GetItemParent( item );

    if ( parent == videoNodeID )
        type = VIDEOSESSION;
    else if ( parent == audioNodeID )
        type = AUDIOSESSION;
    else if ( parent == availableVideoNodeID )
        type = AVAILABLEVIDEOSESSION;
    else
    {
        gravUtil::logError( "SessionTreeControl::removeObject: "
                    "cannot remove %s - invalid tree\n", address.c_str() );
        return;
    }

    if ( sessionManager->removeSession( address, type ) )
        Delete( item );
    else
    {
        gravUtil::logError( "SessionTreeControl::removeObject: "
                        "removal of %s failed \n", address.c_str() );
        // TODO throw GUI error dialog
    }
}
Ejemplo n.º 3
0
int logoffUser(TCHAR *userToLogoff)
{
    wprintf(L"Logging off %s\n", userToLogoff);

    int sessionId = findSession(userToLogoff);

    if (sessionId != -1)
    {
        wprintf(L"  session %d\n", sessionId);
        if (!WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE, sessionId, TRUE))
        {
            printError(L"WTSLogoffSession failed: %s");
            return 3;
        }
        else 
            wprintf(L"  ...done.\n");
    }
    else 
    {
		std::wstring msg;
		msg.append(L"Session for ")
			.append(userToLogoff)
			.append(L" not found");
		wprintf(msg.c_str());
		showBalloonTip(msg.c_str());

        return 2;
    }

    return 0;
}
Ejemplo n.º 4
0
void InspectorReplayAgent::insertSessionSegment(ErrorString& errorString, Inspector::Protocol::Replay::SessionIdentifier sessionIdentifier, SegmentIdentifier segmentIdentifier, int segmentIndex)
{
    ASSERT_ARG(sessionIdentifier, sessionIdentifier > 0);
    ASSERT_ARG(segmentIdentifier, segmentIdentifier > 0);
    ASSERT_ARG(segmentIndex, segmentIndex >= 0);

    RefPtr<ReplaySession> session = findSession(errorString, sessionIdentifier);
    RefPtr<ReplaySessionSegment> segment = findSegment(errorString, segmentIdentifier);

    if (!session || !segment)
        return;

    if (static_cast<size_t>(segmentIndex) > session->size()) {
        errorString = ASCIILiteral("Invalid segment index.");
        return;
    }

    if (session == m_page.replayController().loadedSession() && sessionState() != WebCore::SessionState::Inactive) {
        errorString = ASCIILiteral("Can't modify a loaded session unless the session is inactive.");
        return;
    }

    session->insertSegment(segmentIndex, WTF::move(segment));
    sessionModified(WTF::move(session));
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void CaClientNotifierProxy::unregisterNotifier(
    const CaNotifierFilter &notifierFilter,
    CaNotifierPrivate::NotifierType notifierType)
{
    qDebug() << "CaClientProxy::unregisterNotifier notifierType:"
             << notifierType;

    CCaInnerNotifierFilter::TNotifierType innerNotifierType(
        CCaInnerNotifierFilter::EEntryChangedWithId);
    CaObjectAdapter::convert(
        notifierType,
        innerNotifierType);
    TInt pos = findSession(notifierFilter, innerNotifierType);
    if (pos != KErrNotFound) {
        // Lock the access to mSessions.
        // It will be automatically unlocked at the end of the current range.
        QMutexLocker locker(&mMutex);
        mSessions[pos].UnregisterNotifier(&notifierFilter,
                                          innerNotifierType);
        if (mSessions[pos].SubsessionsCount() == 0) {
            mSessions[pos].Close();
            mSessions.Remove(pos);
        }
    }
}
Ejemplo n.º 6
0
/**********************************************************************
*%FUNCTION: relayHandlePADT
*%ARGUMENTS:
* iface -- interface on which packet was received
* packet -- the PADT packet
*%RETURNS:
* Nothing
*%DESCRIPTION:
* Receives and processes a PADT packet.
***********************************************************************/
void
relayHandlePADT(PPPoEInterface const *iface,
		PPPoEPacket *packet,
		int size)
{
    SessionHash *sh;
    PPPoESession *ses;

    /* Destination address must be interface's MAC address */
    if (memcmp(packet->ethHdr.h_dest, iface->mac, ETH_ALEN)) {
	return;
    }

    sh = findSession(packet->ethHdr.h_source, packet->session);
    if (!sh) {
	return;
    }
    /* Relay the PADT to the peer */
    sh = sh->peer;
    ses = sh->ses;
    packet->session = sh->sesNum;
    memcpy(packet->ethHdr.h_source, sh->interface->mac, ETH_ALEN);
    memcpy(packet->ethHdr.h_dest, sh->peerMac, ETH_ALEN);
    sendPacket(NULL, sh->interface->sessionSock, packet, size);

    /* Destroy the session */
    freeSession(ses, "Received PADT");
}
Ejemplo n.º 7
0
int ShmCacheManager::isPurgedByTag(
    const char *pTag, CacheEntry *pEntry, CacheKey *pKey, bool isCheckPrivate)
{
    if (isCheckPrivate)
    {
        //assert( "NO_PRIVATE_PURGE_YET" == NULL );
        ShmPrivatePurgeData privatePurge;
        int ret = findSession(pKey, &privatePurge);
        if (ret == 1)
        {
            if (privatePurge.isFlushed(pEntry->getHeader().m_tmCreated,
                                       pEntry->getHeader().m_msCreated))
                return 1;
            int tagId = findTagId(pTag, pEntry->getHeader().m_tagLen);
            if (tagId == -1)
                return 0;
            if (privatePurge.shouldPurge(tagId,
                                         pEntry->getHeader().m_tmCreated,
                                         pEntry->getHeader().m_msCreated))
                return 1;
        }
    }
    else
    {
        if (shouldPurge(pTag, pEntry->getHeader().m_tagLen,
                        pEntry->getHeader().m_tmCreated, pEntry->getHeader().m_msCreated))
            return 1;

    }
    return 0;
}
Ejemplo n.º 8
0
EdgeSession* RTMFPServerEdge::findEdgeSession(UInt32 id) {
	EdgeSession* pSession= dynamic_cast<EdgeSession*>(findSession(id));
	if(pSession)
		return pSession;
	DEBUG("Unknown edge session %u",id);
	return NULL;
}
Ejemplo n.º 9
0
/**
 * popuplate the side bar with all sessions inside the current window. Information
 * is gathered from the tab control, which remains active (but invisible) when the
 * switch bar is in use.
 *
 * This is needed when the user switches from tabs to a switchbar layout while a
 * window is open.
 */
void CSideBar::populateAll()
{
	HWND	hwndTab = ::GetDlgItem(m_pContainer->hwnd, IDC_MSGTABS);
	if (hwndTab == NULL)
		return;

	int iItems = (int)TabCtrl_GetItemCount(hwndTab);

	TCITEM item = { 0 };
	item.mask = TCIF_PARAM;

	m_iTopButtons = 0;

	for (int i = 0; i < iItems; i++) {
		TabCtrl_GetItem(hwndTab, i, &item);
		if (item.lParam == 0 || !IsWindow((HWND)item.lParam))
			continue;

		TWindowData *dat = (TWindowData*)::GetWindowLongPtr((HWND)item.lParam, GWLP_USERDATA);
		if (dat == NULL)
			continue;

		CSideBarButton *b_item = findSession(dat);
		if (b_item == NULL)
			addSession(dat, i);
		else {
			b_item->setLayout(m_currentLayout);
			if (m_dwFlags & SIDEBARLAYOUT_VERTICALORIENTATION) {
				b_item->measureItem();
				m_topHeight += b_item->getHeight() + 1;
			}
			else m_topHeight += m_elementHeight + 1;
		}
	}
}
Ejemplo n.º 10
0
int switchUser(TCHAR *username, TCHAR *password)
{
    int sessionId = findSession(username);

    if (password == NULL)
        password = L"";

    if (sessionId == -1) 
    {	
		std::wstring msg;
		msg.append(L"Session for ")
			.append(username)
			.append(L" not found");

		wprintf(msg.c_str());
		showBalloonTip(msg.c_str());
        return 2;
    }

    if(!WTSConnectSession(sessionId, WTSGetActiveConsoleSessionId(), password, true))
    {
        wprintf(L"SessionId: %d\n", sessionId);
        printError(L"WTSConnectSession error: %s\n");
        return 2;
    }

    return 0;
}
Ejemplo n.º 11
0
/**
* @brief Resets the server side timeout for this session
*/
void MemorySessionStore::touch(const string& cookie) {
    ReadOnlyLock lock(_lock);
    Session* session = findSession(lock, cookie);
    if (session != 0) {
        ReadWriteLock bigLock(_lock);
        session->updateLoginTime();
    }
}
Ejemplo n.º 12
0
/**
 * Sets the active session item
 * called from the global update handler in msgdialog/group room window
 * on every tab activation to ensure consistency
 *
 * @param dat    _MessageWindowData*: session data
 *
 * @return The previously active item (that can be zero)
 */
const CSideBarButton* CSideBar::setActiveItem(const TWindowData *dat)
{
	CSideBarButton *item = findSession(dat);
	if (item != NULL)
		return setActiveItem(item);

	return 0;
}
Ejemplo n.º 13
0
void CSideBar::invalidateButton(const TWindowData *dat)
{
	if (m_isActive && m_isVisible) {
		CSideBarButton *item = findSession(dat);
		if (item != NULL)
			RedrawWindow(item->m_buttonControl->hwnd, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
	}
}
Ejemplo n.º 14
0
void InspectorReplayAgent::getSessionData(ErrorString& errorString, Inspector::Protocol::Replay::SessionIdentifier identifier, RefPtr<Inspector::Protocol::Replay::ReplaySession>& serializedObject)
{
    RefPtr<ReplaySession> session = findSession(errorString, identifier);
    if (!session) {
        errorString = ASCIILiteral("Couldn't find the specified session.");
        return;
    }

    serializedObject = buildInspectorObjectForSession(WTF::move(session));
}
Ejemplo n.º 15
0
void SessionTreeControl::unrotateVideoSessions()
{
    wxTreeItemId current = findSession( availableVideoNodeID,
            sessionManager->getCurrentRotateSessionAddress() );
    if ( current.IsOk() )
    {
        SetItemBackgroundColour( current, *wxBLUE );
        SetItemTextColour( current, *wxBLACK );
    }

    sessionManager->unrotate( false );
}
Ejemplo n.º 16
0
void SessionTreeControl::rotateToVideoSession( std::string addr, bool fromAuto )
{
    if ( !sessionManager->rotateTo( addr, false ) )
    {
        gravUtil::logVerbose( "SessionTreeControl::rotateTo %s failed\n",
                                addr.c_str() );
        return;
    }

    wxTreeItemId current = findSession( availableVideoNodeID,
            sessionManager->getCurrentRotateSessionAddress() );
    wxTreeItemId last = findSession( availableVideoNodeID,
            sessionManager->getLastRotateSessionAddress() );

    if ( last.IsOk() )
    {
        SetItemBackgroundColour( last, *wxBLUE );
        SetItemTextColour( last, *wxBLACK );
    }
    if ( current.IsOk() )
    {
        if ( sessionManager->isInFailedState(
                sessionManager->getCurrentRotateSessionAddress(),
                AVAILABLEVIDEOSESSION ) )
        {
            SetItemBackgroundColour( current, *wxRED );
        }
        else
        {
            SetItemBackgroundColour( current, *wxWHITE );
            SetItemTextColour( current, *wxBLUE );
        }
    }

    // if manually rotated & currently autorotating, stop autorotating
    if ( !fromAuto && timer->IsRunning() )
    {
        toggleAutomaticRotate();
    }
}
Ejemplo n.º 17
0
ATerm get_session_by_path(int cid, const char *path) {
  EM_Session session;
  EM_Sid sid;

  assert(path != NULL);

  session = findSession(path);
  if (session == NULL) {
    return sndValue(ATmake("no-such-session"));
  }

  sid = EM_getSessionId(session);
  return sndValue(ATmake("session(<term>)", EM_SidToTerm(sid)));
}
Ejemplo n.º 18
0
void InspectorReplayAgent::switchSession(ErrorString& errorString, Inspector::Protocol::Replay::SessionIdentifier identifier)
{
    ASSERT_ARG(identifier, identifier > 0);

    if (sessionState() != WebCore::SessionState::Inactive) {
        errorString = ASCIILiteral("Can't switch sessions unless the session is neither capturing or replaying.");
        return;
    }

    RefPtr<ReplaySession> session = findSession(errorString, identifier);
    if (!session)
        return;

    m_page.replayController().switchSession(WTF::move(session));
}
Ejemplo n.º 19
0
QByteArray TSessionManager::generateId()
{
    QByteArray id;
    int i;
    for (i = 0; i < 3; ++i) {
        id = randomString();
        if (findSession(id).isEmpty())
            break;
    }

    if (i == 3)
        throw RuntimeException("Unable to generate a unique session ID", __FILE__, __LINE__);
    
    return id;
}
Ejemplo n.º 20
0
/**
* @brief Returns the userId of the currently logged in user.
* Throws std::invalid_argument if no user with that cookie found.
*
* @param cookie the cookie that the client browser gave us
* @param touch If true, updates the session time out
*
* @return userId of the currently logged in user
*/
int MemorySessionStore::userId(const string& cookie, bool touch) {
    ReadOnlyLock lock(_lock);
    Session* session = findSession(lock, cookie);
    if (session != 0) {
        if (session->age() < _timeout) {
            if (touch) {
                ReadWriteLock touchLock(_lock);
                // Session is still good, update its timeout on our end
                session->updateLoginTime();
            }
            return session->userId();
        } else {
            // Cookie is expired - delete its session and return empty
            ReadWriteLock eraseLock(_lock);
            sessions.erase(cookie);
        }
    }
    throw invalid_argument("No user with cookie " + cookie + " found");
}
Ejemplo n.º 21
0
/**
 * Remove a new session from the switchbar.
 *
 * @param dat    _MessageWindowData *: session data for a client session.
 */
HRESULT CSideBar::removeSession(const TWindowData *dat)
{
	if (dat) {
		CSideBarButton *item = findSession(dat);

		if (item != NULL) {
			m_iTopButtons--;
			if (m_dwFlags & SIDEBARLAYOUT_DYNHEIGHT) {
				SIZE sz = item->getSize();
				m_topHeight -= (sz.cy + 1);
			}
			else m_topHeight -= (m_elementHeight + 1);

			m_buttonlist.remove(item);
			Invalidate();
			return(S_OK);
		}
	}
	return(S_FALSE);
}
Ejemplo n.º 22
0
ATerm create_session(int cid, const char *path) {
  EM_Session session;

  assert(path != NULL);

  session = findSession(path);
  if (session != NULL) {
    EM_SessionStatus status = EM_getSessionStatus(session);
    if (!EM_isSessionStatusZombie(status)) {
      return sndValue(ATmake("session(<term>)", EM_getSessionId(session)));
    }
  }

  EM_Sid sid = makeUniqueSessionId();
  EM_EditorTypeList list = EM_makeEditorTypeListEmpty();
  EM_SessionStatus status = EM_makeSessionStatusRunning();
  session = EM_makeSessionDefault(sid, path, status, 0, list);
  putSession(session);

  return sndValue(ATmake("session(<term>)", EM_getSessionId(session)));
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
int CaClientNotifierProxy::registerNotifier(
    const CaNotifierFilter *notifierFilter,
    CaNotifierPrivate::NotifierType notifierType,
    const IDataObserver *observer)
{
    qDebug() << "CaClientProxy::registerNotifier notifierType:"
             << notifierType;

    CCaInnerNotifierFilter::TNotifierType innerNotifierType(
        CCaInnerNotifierFilter::EEntryChangedWithId);

    CaObjectAdapter::convert(notifierType,
                             innerNotifierType);
    CCaInnerNotifierFilter *innerNotifierFilter(NULL);

    TRAPD(error,
          innerNotifierFilter =
              CCaInnerNotifierFilter::NewLC(innerNotifierType);
          CaObjectAdapter::convertL(*notifierFilter, *innerNotifierFilter);
          CleanupStack::Pop(innerNotifierFilter)
         );

    if (!error) {
        // Lock the access to mSessions.
        // It will be automatically unlocked at the end of the current range.
        QMutexLocker locker(&mMutex);
        RCaClientNotifierSession *session = findSession();
        if (!session) {
            session = newSession(error);
        }
        if (!error) {
            error = session->RegisterNotifier(innerNotifierFilter,
                                              notifierFilter, observer);
        }
    }

    qDebug() << "CaClientProxy::registerNotifier result:" << error;

    return error;
}
Ejemplo n.º 24
0
IDE_RC mmtServiceThread::planGetProtocolA5(cmiProtocolContext *aProtocolContext,
                                         cmiProtocol        *aProtocol,
                                         void               *aSessionOwner,
                                         void               *aUserContext)
{
    cmpArgDBPlanGetA5  *sArg    = CMI_PROTOCOL_GET_ARG(*aProtocol, DB, PlanGet);
    mmcTask          *sTask   = (mmcTask *)aSessionOwner;
    mmtServiceThread *sThread = (mmtServiceThread *)aUserContext;
    mmcSession       *sSession;
    mmcStatement     *sStatement;

    IDE_CLEAR();

    IDE_TEST(findSession(sTask, &sSession, sThread) != IDE_SUCCESS);

    IDE_TEST(checkSessionState(sSession, MMC_SESSION_STATE_SERVICE) != IDE_SUCCESS);

    IDE_TEST(findStatement(&sStatement,
                           sSession,
                           &sArg->mStatementID,
                           sThread) != IDE_SUCCESS);

    if (sStatement->isPlanPrinted() != ID_TRUE)
    {
        IDE_TEST(checkStatementState(sStatement, MMC_STMT_STATE_PREPARED) != IDE_SUCCESS);

        IDE_TEST(sStatement->makePlanTreeText(ID_TRUE) != IDE_SUCCESS);
    }

    return answerPlanGetResult(aProtocolContext,
                               sStatement->getStmtID(),
                               sStatement->getPlanString());

    IDE_EXCEPTION_END;

    return sThread->answerErrorResultA5(aProtocolContext,
                                      CMI_PROTOCOL_OPERATION(DB, PlanGet),
                                      0);
}
Ejemplo n.º 25
0
/**
 * Invalidate the button associated with the given session.
 *
 * @param dat    _MessageWindowData*: Session data
 */
void CSideBar::updateSession(const TWindowData *dat)
{
	if (!m_isVisible || !m_isActive)
		return;

	CSideBarButton *item = findSession(dat);
	if (item == NULL)
		return;

	if (m_dwFlags & SIDEBARLAYOUT_DYNHEIGHT) {
		LONG oldHeight = item->getHeight();
		m_topHeight -= (oldHeight + 1);
		SIZE sz = item->measureItem();
		m_topHeight += (sz.cy + 1);
		if (sz.cy != oldHeight) {
			Invalidate();
			::InvalidateRect(item->getHwnd(), NULL, TRUE);
		}
		else ::InvalidateRect(item->getHwnd(), NULL, FALSE);
	}
	else ::InvalidateRect(item->getHwnd(), NULL, FALSE);
}
void InspectorReplayAgent::removeSessionSegment(ErrorString* errorString, Inspector::Protocol::Replay::SessionIdentifier identifier, int segmentIndex)
{
    ASSERT(identifier > 0);
    ASSERT(segmentIndex >= 0);

    RefPtr<ReplaySession> session = findSession(errorString, identifier);

    if (!session)
        return;

    if (static_cast<size_t>(segmentIndex) >= session->size()) {
        *errorString = ASCIILiteral("Invalid segment index.");
        return;
    }

    if (session == m_page.replayController().loadedSession() && sessionState() != WebCore::SessionState::Inactive) {
        *errorString = ASCIILiteral("Can't modify a loaded session unless the session is inactive.");
        return;
    }

    session->removeSegment(segmentIndex);
    sessionModified(session);
}
Ejemplo n.º 27
0
/**********************************************************************
*%FUNCTION: relayGotSessionPacket
*%ARGUMENTS:
* iface -- interface on which packet is waiting
*%RETURNS:
* Nothing
*%DESCRIPTION:
* Receives and processes a session packet.
***********************************************************************/
void
relayGotSessionPacket(PPPoEInterface const *iface)
{
    PPPoEPacket packet;
    int size;
    SessionHash *sh;
    PPPoESession *ses;

    if (receivePacket(iface->sessionSock, &packet, &size) < 0) {
	return;
    }

    /* Ignore unknown code/version */
    if (packet.ver != 1 || packet.type != 1) {
	return;
    }

    /* Must be a session packet */
    if (packet.code != CODE_SESS) {
	syslog(LOG_ERR, "Session packet with code %d", (int) packet.code);
	return;
    }

    /* Ignore session packets whose destination address isn't ours */
    if (memcmp(packet.ethHdr.h_dest, iface->mac, ETH_ALEN)) {
	return;
    }

    /* Validate length */
    if (ntohs(packet.length) + HDR_SIZE > size) {
	syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
	       (unsigned int) ntohs(packet.length));
	return;
    }

    /* Drop Ethernet frame padding */
    if (size > ntohs(packet.length) + HDR_SIZE) {
	size = ntohs(packet.length) + HDR_SIZE;
    }

    /* We're in business!  Find the hash */
    sh = findSession(packet.ethHdr.h_source, packet.session);
    if (!sh) {
	/* Don't log this.  Someone could be running the client and the
	   relay on the same box. */
	return;
    }

    /* Relay it */
    ses = sh->ses;
    ses->epoch = Epoch;
    sh = sh->peer;
    packet.session = sh->sesNum;
    memcpy(packet.ethHdr.h_source, sh->interface->mac, ETH_ALEN);
    memcpy(packet.ethHdr.h_dest, sh->peerMac, ETH_ALEN);
#if 0
    printf( "Relaying %02x:%02x:%02x:%02x:%02x:%02x(%s:%d) to %02x:%02x:%02x:%02x:%02x:%02x(%s:%d)\n",
	    sh->peer->peerMac[0], sh->peer->peerMac[1], sh->peer->peerMac[2],
	    sh->peer->peerMac[3], sh->peer->peerMac[4], sh->peer->peerMac[5],
	    sh->peer->interface->name, ntohs(sh->peer->sesNum),
	    sh->peerMac[0], sh->peerMac[1], sh->peerMac[2],
	    sh->peerMac[3], sh->peerMac[4], sh->peerMac[5],
	    sh->interface->name, ntohs(sh->sesNum));
#endif
    sendPacket(NULL, sh->interface->sessionSock, &packet, size);
}
Ejemplo n.º 28
0
/**********************************************************************
*%FUNCTION: relayHandlePADS
*%ARGUMENTS:
* iface -- interface on which packet was received
* packet -- the PADS packet
*%RETURNS:
* Nothing
*%DESCRIPTION:
* Receives and processes a PADS packet.
***********************************************************************/
void
relayHandlePADS(PPPoEInterface const *iface,
		PPPoEPacket *packet,
		int size)
{
    PPPoETag tag;
    unsigned char *loc;
    int ifIndex;
    int acIndex;
    PPPoESession *ses = NULL;
    SessionHash *sh;

    /* Can a server legally be behind this interface? */
    if (!iface->acOK) {
	syslog(LOG_ERR,
	       "PADS packet from %02x:%02x:%02x:%02x:%02x:%02x on interface %s not permitted",
	       packet->ethHdr.h_source[0],
	       packet->ethHdr.h_source[1],
	       packet->ethHdr.h_source[2],
	       packet->ethHdr.h_source[3],
	       packet->ethHdr.h_source[4],
	       packet->ethHdr.h_source[5],
	       iface->name);
	return;
    }

    acIndex = iface - Interfaces;

    /* Source address must be unicast */
    if (NOT_UNICAST(packet->ethHdr.h_source)) {
	syslog(LOG_ERR,
	       "PADS packet from %02x:%02x:%02x:%02x:%02x:%02x on interface %s not from a unicast address",
	       packet->ethHdr.h_source[0],
	       packet->ethHdr.h_source[1],
	       packet->ethHdr.h_source[2],
	       packet->ethHdr.h_source[3],
	       packet->ethHdr.h_source[4],
	       packet->ethHdr.h_source[5],
	       iface->name);
	return;
    }

    /* Destination address must be interface's MAC address */
    if (memcmp(packet->ethHdr.h_dest, iface->mac, ETH_ALEN)) {
	return;
    }

    /* Find relay tag */
    loc = findTag(packet, TAG_RELAY_SESSION_ID, &tag);
    if (!loc) {
	syslog(LOG_ERR,
	       "PADS packet from %02x:%02x:%02x:%02x:%02x:%02x on interface %s does not have Relay-Session-Id tag",
	       packet->ethHdr.h_source[0],
	       packet->ethHdr.h_source[1],
	       packet->ethHdr.h_source[2],
	       packet->ethHdr.h_source[3],
	       packet->ethHdr.h_source[4],
	       packet->ethHdr.h_source[5],
	       iface->name);
	return;
    }

    /* If it's the wrong length, ignore it */
    if (ntohs(tag.length) != MY_RELAY_TAG_LEN) {
	syslog(LOG_ERR,
	       "PADS packet from %02x:%02x:%02x:%02x:%02x:%02x on interface %s does not have correct length Relay-Session-Id tag",
	       packet->ethHdr.h_source[0],
	       packet->ethHdr.h_source[1],
	       packet->ethHdr.h_source[2],
	       packet->ethHdr.h_source[3],
	       packet->ethHdr.h_source[4],
	       packet->ethHdr.h_source[5],
	       iface->name);
	return;
    }

    /* Extract interface index */
    memcpy(&ifIndex, tag.payload, sizeof(ifIndex));

    if (ifIndex < 0 || ifIndex >= NumInterfaces ||
	!Interfaces[ifIndex].clientOK ||
	iface == &Interfaces[ifIndex]) {
	syslog(LOG_ERR,
	       "PADS packet from %02x:%02x:%02x:%02x:%02x:%02x on interface %s has invalid interface in Relay-Session-Id tag",
	       packet->ethHdr.h_source[0],
	       packet->ethHdr.h_source[1],
	       packet->ethHdr.h_source[2],
	       packet->ethHdr.h_source[3],
	       packet->ethHdr.h_source[4],
	       packet->ethHdr.h_source[5],
	       iface->name);
	return;
    }

    /* If session ID is zero, it's the AC respoding with an error.
       Just relay it; do not create a session */
    if (packet->session != htons(0)) {
	/* Check for existing session */
	sh = findSession(packet->ethHdr.h_source, packet->session);
	if (sh) ses = sh->ses;

	/* If already an existing session, assume it's a duplicate PADS.  Send
	   the frame, but do not create a new session.  Is this the right
	   thing to do?  Arguably, should send an error to the client and
	   a PADT to the server, because this could happen due to a
	   server crash and reboot. */

	if (!ses) {
	    /* Create a new session */
	    ses = createSession(iface, &Interfaces[ifIndex],
				packet->ethHdr.h_source,
				loc + TAG_HDR_SIZE + sizeof(ifIndex), packet->session);
	    if (!ses) {
		/* Can't allocate session -- send error PADS to client and
		   PADT to server */
		PPPoETag hostUniq, *hu;
		if (findTag(packet, TAG_HOST_UNIQ, &hostUniq)) {
		    hu = &hostUniq;
		} else {
		    hu = NULL;
		}
		relaySendError(CODE_PADS, htons(0), &Interfaces[ifIndex],
			       loc + TAG_HDR_SIZE + sizeof(ifIndex),
			       hu, "RP-PPPoE: Relay: Unable to allocate session");
		relaySendError(CODE_PADT, packet->session, iface,
			       packet->ethHdr.h_source, NULL,
			       "RP-PPPoE: Relay: Unable to allocate session");
		return;
	    }
	}
	/* Replace session number */
	packet->session = ses->sesNum;
    }

    /* Remove relay-ID tag */
    removeBytes(packet, loc, MY_RELAY_TAG_LEN + TAG_HDR_SIZE);
    size -= (MY_RELAY_TAG_LEN + TAG_HDR_SIZE);

    /* Set destination address to MAC address in relay ID */
    memcpy(packet->ethHdr.h_dest, tag.payload + sizeof(ifIndex), ETH_ALEN);

    /* Set source address to MAC address of interface */
    memcpy(packet->ethHdr.h_source, Interfaces[ifIndex].mac, ETH_ALEN);

    /* Send the PADS to the proper client */
    sendPacket(NULL, Interfaces[ifIndex].discoverySock, packet, size);
}
Ejemplo n.º 29
0
IDE_RC mmtServiceThread::prepareProtocolA5(cmiProtocolContext *aProtocolContext,
                                         cmiProtocol        *aProtocol,
                                         void               *aSessionOwner,
                                         void               *aUserContext)
{
    cmpArgDBPrepareA5  *sArg    = CMI_PROTOCOL_GET_ARG(*aProtocol, DB, Prepare);
    mmcTask          *sTask   = (mmcTask *)aSessionOwner;
    mmtServiceThread *sThread = (mmtServiceThread *)aUserContext;
    mmcSession       *sSession;
    //fix BUG-18284.
    mmcStatement     *sStatement = NULL;
    SChar            *sQuery;
    UInt              sQueryLen;
    IDE_RC            sRet;

    IDE_CLEAR();

    IDE_TEST(findSession(sTask, &sSession, sThread) != IDE_SUCCESS);

    IDE_TEST(checkSessionState(sSession, MMC_SESSION_STATE_SERVICE) != IDE_SUCCESS);

    if (sArg->mStatementID == 0)
    {
        IDE_TEST(mmcStatementManager::allocStatement(&sStatement, sSession, NULL) != IDE_SUCCESS);

        sThread->setStatement(sStatement);
    }
    else
    {
        IDE_TEST(findStatement(&sStatement,
                               sSession,
                               &sArg->mStatementID,
                               sThread) != IDE_SUCCESS);

        /* PROJ-2223 Altibase Auditing */
        mmtAuditManager::auditBySession( sStatement );

        IDE_TEST(sStatement->clearPlanTreeText() != IDE_SUCCESS);

        IDE_TEST_RAISE(sStatement->getStmtState() >= MMC_STMT_STATE_EXECUTED,
                       InvalidStatementState);

        IDE_TEST(qci::clearStatement(sStatement->getQciStmt(),
                                     sStatement->getSmiStmt(),
                                     QCI_STMT_STATE_INITIALIZED) != IDE_SUCCESS);

        sStatement->setStmtState(MMC_STMT_STATE_ALLOC);
    }
    // bug-34746: query_timeout flag is cleared by other stmt
    // query_timeout 확인시 mCurrStmtID로 비교한다
    sSession->getInfo()->mCurrStmtID = sStatement->getStmtID();

    /* BUG-38472 Query timeout applies to one statement. */
    IDU_SESSION_CLR_TIMEOUT( *sSession->getEventFlag() );

    sQueryLen = cmtVariableGetSize(&sArg->mStatementString);

    IDE_TEST_RAISE(sQueryLen == 0, NullQuery);

    IDU_FIT_POINT("mmtServiceThread::prepareProtocolA5::malloc::Query");
    IDE_TEST(iduMemMgr::malloc(IDU_MEM_MMC,
                               sQueryLen + 1,
                               (void **)&sQuery,
                               IDU_MEM_IMMEDIATE) != IDE_SUCCESS);

    IDE_TEST(cmtVariableGetData(&sArg->mStatementString,
                                (UChar *)sQuery,
                                sQueryLen) != IDE_SUCCESS);

    sQuery[sQueryLen] = 0;

    sStatement->setStmtExecMode(sArg->mMode ? MMC_STMT_EXEC_DIRECT : MMC_STMT_EXEC_PREPARED);

    IDE_TEST(sStatement->prepare(sQuery, sQueryLen) != IDE_SUCCESS);

    return answerPrepareResult(aProtocolContext, sStatement);

    IDE_EXCEPTION(InvalidStatementState);
    {
        IDE_SET(ideSetErrorCode(mmERR_ABORT_INVALID_STATEMENT_STATE_ERROR));
    }
    IDE_EXCEPTION(NullQuery);
    {
        IDE_SET(ideSetErrorCode(mmERR_ABORT_INSUFFICIENT_QUERY_ERROR));
    }
    IDE_EXCEPTION_END;
    {
        sRet = sThread->answerErrorResultA5(aProtocolContext,
                                          CMI_PROTOCOL_OPERATION(DB, Prepare),
                                          0);

        if (sRet == IDE_SUCCESS)
        {
            sThread->mErrorFlag = ID_TRUE;
        }
        //fix BUG-18284.
        // do exactly same as CMP_DB_FREE_DROP
        if (sArg->mStatementID == 0)
        {
            if(sStatement != NULL)
            {    
                sThread->setStatement(NULL);

                /* BUG-38585 IDE_ASSERT remove */
                IDE_ASSERT(sStatement->closeCursor(ID_TRUE) == IDE_SUCCESS);
                IDE_ASSERT(mmcStatementManager::freeStatement(sStatement) == IDE_SUCCESS);

            }//if
        }//if
    }
    
    return sRet;
}
Ejemplo n.º 30
0
IDE_RC mmtServiceThread::freeProtocolA5(cmiProtocolContext *aProtocolContext,
                                      cmiProtocol        *aProtocol,
                                      void               *aSessionOwner,
                                      void               *aUserContext)
{
    cmpArgDBFreeA5     *sArg    = CMI_PROTOCOL_GET_ARG(*aProtocol, DB, Free);
    mmcTask          *sTask   = (mmcTask *)aSessionOwner;
    mmtServiceThread *sThread = (mmtServiceThread *)aUserContext;
    mmcSession       *sSession;
    mmcStatement     *sStatement;

    IDE_CLEAR();

    IDE_TEST(findSession(sTask, &sSession, sThread) != IDE_SUCCESS);

    IDE_TEST(checkSessionState(sSession, MMC_SESSION_STATE_SERVICE) != IDE_SUCCESS);

    IDE_TEST(findStatement(&sStatement,
                           sSession,
                           &sArg->mStatementID,
                           sThread) != IDE_SUCCESS);

    switch (sArg->mMode)
    {
        case CMP_DB_FREE_CLOSE:
            if ((sStatement->getStmtState() >= MMC_STMT_STATE_EXECUTED) &&
                (sSession->getExplainPlan() == QCI_EXPLAIN_PLAN_ON))
            {
                IDE_TEST(sStatement->makePlanTreeText(ID_FALSE) != IDE_SUCCESS);
            }

            IDE_TEST(sStatement->closeCursor(ID_TRUE) != IDE_SUCCESS);

            break;

        case CMP_DB_FREE_DROP:
            sThread->setStatement(NULL);

            IDE_TEST(sStatement->closeCursor(ID_TRUE) != IDE_SUCCESS);

            IDE_TEST(mmcStatementManager::freeStatement(sStatement) != IDE_SUCCESS);

            break;

        default:
            IDE_RAISE(InvalidFreeMode);
            break;
    }

    return answerFreeResult(aProtocolContext);

    IDE_EXCEPTION(InvalidFreeMode);
    {
        IDE_SET(ideSetErrorCode(mmERR_ABORT_INVALID_STATEMENT_FREE_MODE));
    }
    IDE_EXCEPTION_END;

    return sThread->answerErrorResultA5(aProtocolContext,
                                      CMI_PROTOCOL_OPERATION(DB, Free),
                                      0);
}