Exemplo n.º 1
0
bool SessionManager::addSession( std::string address, SessionType type )
{
    lockSessions();

    bool ret = true;
    bool audio = ( type == AUDIOSESSION );
    SessionEntry* entry = new SessionEntry( address, audio );
    Group* sessions = sessionMap[ type ];
    entry->setPos( sessions->getX(), sessions->getY() );
    Texture t = GLUtil::getInstance()->getTexture( "circle" );
    entry->setTexture( t.ID, t.width, t.height );

    if ( type != AVAILABLEVIDEOSESSION )
    {
        ret = ret && initSession( entry );
    }

    /*
     * Note - used to delete entries on fail. Now will display an entry in a
     * failed state, so it can potentially be reenabled when it could work.
     * (But still returns false on failed init)
     */

    sessions->add( entry );
    objectManager->lockSources();
    objectManager->addToDrawList( entry );
    objectManager->unlockSources();
    entry->show( shown, !shown );

    recalculateSize();

    unlockSessions();
    return ret;
}
Exemplo n.º 2
0
UdpSession::UdpSession(IcqLink *link, const char *name, uint32 uin)
: IcqSession(link, name, uin)
{
	memset(&destAddr, 0, sizeof(destAddr));

	initSession();
}
Exemplo n.º 3
0
struct Session *newSession(const char *sessionKey, Server *server,
                           const char *peerName) {
  struct Session *session;
  check(session = malloc(sizeof(struct Session)));
  initSession(session, sessionKey, server, peerName);
  return session;
}
Exemplo n.º 4
0
Session *SessionServer::createSession(const SessionId &id, const QString &protocolVersion, const QString &founder)
{
	Q_ASSERT(!id.isEmpty());
	Q_ASSERT(getSessionDescriptionById(id.id()).id.isEmpty());

	Session *session = new Session(id, protocolVersion, founder, this);

	initSession(session);

	logger::debug() << session << "Session created by" << founder;

	return session;
}
Exemplo n.º 5
0
void 
main( int argc, char **argv )
{
    SOCKET	sock;
    int		arg;
    char	*host = DEFAULT_HOST;
    u_short	port = (u_short)DEFAULT_PORT;

    for( arg = 1; arg < argc; arg++ )
    {
	if ( argv[ arg ][0] != '-' )
	{
	    fprintf( stderr, "Invalid command line argument: %s\n", argv[ arg ] );
	    exit(1);
	}

	switch( argv[ arg ][1] )
	{
	case 'h':
	    printf( "-t <host>\tTarget host name (default 'localhost')\n" );
	    printf( "-p <port>\tTarget port number (default 16903)\n" );
	    printf( "-e\t\tAES Mode ECB\n" );
	    printf( "-v\t\tVerbose\n" );
	    exit(0);

	case 't' :  host = argv[ ++arg ];		break;
	case 'p' :  port = atoi( argv[ ++arg ] );	break;
	case 'e' :  sessKeyMode = CRYPT_MODE_ECB;	break;
	case 'v' :  verbose = TRUE;			break;

	default:
	    fprintf( stderr, "Invalid command line flag: %s\n", argv[ arg ] );
	    exit(1);
	}
    }

    if ( ! initCrypt() )  exit(1);
    sock = tcpConnect( host, port );
    if ( ! initSession( sock ) )  exit(1);
    if ( ! clientRequest( sock, host, port ) )  exit(1);
    shutdown( sock, 2 );
    closesocket( sock );

    if ( WSACleanup() == SOCKET_ERROR )
	fprintf( stderr, "Problem with socket cleanup\n" );

    termCrypt();

    exit(0);
}
Exemplo n.º 6
0
MainWindow::MainWindow(QString torrent, QString downloadPath, QString mountPath, QString rate, bool gui, QObject *parent): QObject(parent) {
    initSession(rate);
    initscr();
    nodelay(stdscr, true);
    noecho();
    main = NULL;
    if (!gui)
        realAddTorrent(torrent, downloadPath, mountPath);
    else {
        fake = new QMainWindow;
        if (QFile(torrent).exists() || isMagnet(torrent))
            findPaths(torrent);
        else
            addTorrent();
    }
}
Exemplo n.º 7
0
SessionState *SessionServer::getSessionById(const QString &id)
{
	for(SessionState *s : _sessions) {
		if(s->id() == id)
			return s;
	}

	if(_store) {
		SessionState *session = _store->takeSession(id);
		if(session) {
			session->setParent(this);
			initSession(session);
			logger::info() << session << "Restored from hibernation";
			return session;
		}
	}

	return nullptr;
}
Exemplo n.º 8
0
bool SessionManager::shiftSession( SessionEntry* entry )
{
    Group* to;
    Group* from = entry->getGroup();

    if ( from == videoSessions )
    {
        to = availableVideoSessions;
        disableSession( entry );
    }
    else if ( from = availableVideoSessions )
    {
        to = videoSessions;

        if ( !entry->isSessionEnabled() )
        {
            initSession( entry );
        }

        int i = indexOf( entry );
        // shift rotate position back if what we're removing is before or at it,
        // so we don't skip any
        if ( i <= rotatePos && i != -1 )
            rotatePos--;
    }
    else
    {
        const char* name = from != NULL ? from->getName().c_str() : "NULL";
        gravUtil::logWarning( "SessionManager::shiftSession: invalid source "
                              "group input (%s)\n", name );
        return false;
    }

    from->remove( entry );
    to->add( entry );

    recalculateSize();

    return true;
}
Exemplo n.º 9
0
bool Session2c::open()
{
	QMutexLocker ml(&m_mutex);
	// Initialize a "session" that defines who we're going to talk to
	netsnmp_session session;
	initSession(session);

	session.version = SNMP_VERSION_2c;
	
	session.community = new u_char[m_community.length()+1];
	memcpy(session.community, m_community.latin1(), m_community.length()+1);
	session.community_len = m_community.length();
	
	m_session = snmp_open(&session);
	
	delete session.community;
	delete session.peername;
	
	if ( ! m_session )
		return false;
	
	return true;
}
void ServerSocketInterface::readClient()
{
    QByteArray data = socket->readAll();
    servatrice->incRxBytes(data.size());
    inputBuffer.append(data);

    do {
        if (!messageInProgress) {
            if (inputBuffer.size() >= 4) {
                messageLength =   (((quint32) (unsigned char) inputBuffer[0]) << 24)
                                + (((quint32) (unsigned char) inputBuffer[1]) << 16)
                                + (((quint32) (unsigned char) inputBuffer[2]) << 8)
                                + ((quint32) (unsigned char) inputBuffer[3]);
                inputBuffer.remove(0, 4);
                messageInProgress = true;
            } else
                return;
        }
        if (inputBuffer.size() < messageLength)
            return;

        CommandContainer newCommandContainer;
        newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength);
        inputBuffer.remove(0, messageLength);
        messageInProgress = false;

        // dirty hack to make v13 client display the correct error message
        if (handshakeStarted)
            processCommandContainer(newCommandContainer);
        else if (!newCommandContainer.has_cmd_id()) {
            handshakeStarted = true;
            if (!initSession())
                prepareDestroy();
        }
        // end of hack
    } while (!inputBuffer.isEmpty());
}
Exemplo n.º 11
0
void ServerSocketInterface::readClient()
{
    QByteArray data = socket->readAll();
    servatrice->incRxBytes(data.size());
    inputBuffer.append(data);

    do {
        if (!messageInProgress) {
            if (inputBuffer.size() >= 4) {
                messageLength =   (((quint32) (unsigned char) inputBuffer[0]) << 24)
                                + (((quint32) (unsigned char) inputBuffer[1]) << 16)
                                + (((quint32) (unsigned char) inputBuffer[2]) << 8)
                                + ((quint32) (unsigned char) inputBuffer[3]);
                inputBuffer.remove(0, 4);
                messageInProgress = true;
            } else
                return;
        }
        if (inputBuffer.size() < messageLength)
            return;

        CommandContainer newCommandContainer;
        try {
            newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength);
        }
        catch(std::exception &e) {
            qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ << 
#ifdef _MSC_VER // Visual Studio
                __FUNCTION__;
#else
                __PRETTY_FUNCTION__;
#endif
            qDebug() << "Exception:" << e.what();
            qDebug() << "Message coming from:" << getAddress();
            qDebug() << "Message length:" << messageLength;
            qDebug() << "Message content:" << inputBuffer.toHex();
        }
        catch(...) {
            qDebug() << "Unhandled exception in" << __FILE__ << __LINE__ <<
#ifdef _MSC_VER // Visual Studio
                __FUNCTION__;
#else
                __PRETTY_FUNCTION__;
#endif
            qDebug() << "Message coming from:" << getAddress();
        }

        inputBuffer.remove(0, messageLength);
        messageInProgress = false;

        // dirty hack to make v13 client display the correct error message
        if (handshakeStarted)
            processCommandContainer(newCommandContainer);
        else if (!newCommandContainer.has_cmd_id()) {
            handshakeStarted = true;
            if (!initSession())
                prepareDestroy();
        }
        // end of hack
    } while (!inputBuffer.isEmpty());
}
Exemplo n.º 12
0
bool SessionManager::rotateTo( std::string addr, bool audio )
{
    lockSessions();

    int numSessions = availableVideoSessions->numObjects();
    int lastRotatePos = rotatePos;
    if ( lastRotatePos != -1 )
        lastRotateSession =
            dynamic_cast<SessionEntry*>( (*availableVideoSessions)[ rotatePos ] );
    if ( numSessions == 0 )
    {
        unlockSessions();
        return false;
    }

    SessionEntry* current;

    // if arg is an empty string, just rotate to next. otherwise, figure out
    // rotate pos of string arg
    if ( addr.compare( "" ) == 0 )
    {
        if ( ++rotatePos >= numSessions )
        {
            rotatePos = 0;
        }
        current =
            dynamic_cast<SessionEntry*>( (*availableVideoSessions)[ rotatePos ] );
    }
    else
    {
        current = findSessionByAddress( addr, AVAILABLEVIDEOSESSION );

        if ( current != NULL )
        {
            rotatePos = indexOf( current );
        }
    }

    if ( current == NULL )
    {
        gravUtil::logWarning( "SessionManager::rotateTo: session %s"
                              " not found\n", addr.c_str() );
        unlockSessions();
        return false;
    }

    // only rotate if there is a valid old one & it isn't the same as
    // current
    if ( lastRotateSession != NULL && current != NULL &&
            lastRotateSession != current )
    {
        disableSession( lastRotateSession );
        initSession( current );
    }
    // case for first rotate
    else if ( lastRotatePos == -1 )
    {
        initSession( current );
    }

    unlockSessions();

    return true;
}
Exemplo n.º 13
0
int
main (int argc, char **argv)
{
    CompIOCtx ctx;
    char      *displayName = 0;
    char      *plugin[256];
    int	      i, nPlugin = 0;
    Bool      disableSm = FALSE;
    char      *clientId = NULL;
    char      *refreshRateArg = NULL;

    programName = argv[0];
    programArgc = argc;
    programArgv = argv;

    signal (SIGHUP, signalHandler);
    signal (SIGCHLD, signalHandler);
    signal (SIGINT, signalHandler);
    signal (SIGTERM, signalHandler);
    signal (SIGSEGV, signalHandler);

    emptyRegion.rects = &emptyRegion.extents;
    emptyRegion.numRects = 0;
    emptyRegion.extents.x1 = 0;
    emptyRegion.extents.y1 = 0;
    emptyRegion.extents.x2 = 0;
    emptyRegion.extents.y2 = 0;
    emptyRegion.size = 0;

    infiniteRegion.rects = &infiniteRegion.extents;
    infiniteRegion.numRects = 1;
    infiniteRegion.extents.x1 = MINSHORT;
    infiniteRegion.extents.y1 = MINSHORT;
    infiniteRegion.extents.x2 = MAXSHORT;
    infiniteRegion.extents.y2 = MAXSHORT;

    memset (&ctx, 0, sizeof (ctx));

    for (i = 1; i < argc; i++)
    {
	if (!strcmp (argv[i], "--help"))
	{
	    usage ();
	    return 0;
	}
	else if (!strcmp (argv[i], "--version"))
	{
	    printf (PACKAGE_STRING "\n");
	    return 0;
	}
	else if (!strcmp (argv[i], "--debug"))
	{
	    debugOutput = TRUE;
	}
	else if (!strcmp (argv[i], "--display"))
	{
	    if (i + 1 < argc)
		displayName = argv[++i];
	}
	else if (!strcmp (argv[i], "--refresh-rate"))
	{
	    if (i + 1 < argc)
	    {
		refreshRateArg = programArgv[++i];
		defaultRefreshRate = atoi (refreshRateArg);
		defaultRefreshRate = RESTRICT_VALUE (defaultRefreshRate,
						     1, 1000);
	    }
	}
	else if (!strcmp (argv[i], "--fast-filter"))
	{
	    ctx.textureFilterData = "<default>Fast</default>";
	    defaultTextureFilter = "Fast";
	}
	else if (!strcmp (argv[i], "--indirect-rendering"))
	{
	    /* force Mesa libGL into indirect rendering mode, because
	       glXQueryExtensionsString is context-independant */
	    setenv ("LIBGL_ALWAYS_INDIRECT", "1", True);
	    indirectRendering = TRUE;
	}
	else if (!strcmp (argv[i], "--loose-binding"))
	{
	    strictBinding = FALSE;
	}
	else if (!strcmp (argv[i], "--ignore-desktop-hints"))
	{
	    /* keep command line parameter for backward compatibility */
	    useDesktopHints = FALSE;
	}
	else if (!strcmp (argv[i], "--keep-desktop-hints"))
	{
	    useDesktopHints = TRUE;
	}
	else if (!strcmp (argv[i], "--only-current-screen"))
	{
	    onlyCurrentScreen = TRUE;
	}
	else if (!strcmp (argv[i], "--no-fbo"))
	{
		noFBO = TRUE;
	}

#ifdef USE_COW
	else if (!strcmp (argv[i], "--use-root-window"))
	{
	    useCow = FALSE;
	}
#endif

	else if (!strcmp (argv[i], "--replace"))
	{
	    replaceCurrentWm = TRUE;
	}
	else if (!strcmp (argv[i], "--sm-disable"))
	{
	    disableSm = TRUE;
	}
	else if (!strcmp (argv[i], "--sm-client-id"))
	{
	    if (i + 1 < argc)
		clientId = argv[++i];
	}
	else if (!strcmp (argv[i], "--no-detection"))
	{
	    noDetection = TRUE;
	}
	else if (!strcmp (argv[i], "--bg-image"))
	{
	    if (i + 1 < argc)
		backgroundImage = argv[++i];
	}
	else if (*argv[i] == '-')
	{
	    compLogMessage ("core", CompLogLevelWarn,
			    "Unknown option '%s'\n", argv[i]);
	}
	else
	{
	    if (nPlugin < 256)
		plugin[nPlugin++] = argv[i];
	}
    }

    /* add in default plugins if none are given */
    if (nPlugin == 0)
    {
        plugin[nPlugin++] = "ccp";
        plugin[nPlugin++] = "move";
        plugin[nPlugin++] = "resize";
        plugin[nPlugin++] = "place";
        plugin[nPlugin++] = "decoration";
    }

    if (refreshRateArg)
    {
	ctx.refreshRateData = malloc (strlen (refreshRateArg) + 256);
	if (ctx.refreshRateData)
	    sprintf (ctx.refreshRateData,
		     "<min>1</min><default>%s</default>",
		     refreshRateArg);
    }

    if (nPlugin)
    {
	int size = 256;

	for (i = 0; i < nPlugin; i++)
	    size += strlen (plugin[i]) + 16;

	ctx.pluginData = malloc (size);
	if (ctx.pluginData)
	{
	    char *ptr = ctx.pluginData;

	    ptr += sprintf (ptr, "<type>string</type><default>");

	    for (i = 0; i < nPlugin; i++)
		ptr += sprintf (ptr, "<value>%s</value>", plugin[i]);

	    ptr += sprintf (ptr, "</default>");
	}

	initialPlugins = malloc (nPlugin * sizeof (char *));
	if (initialPlugins)
	{
	    memcpy (initialPlugins, plugin, nPlugin * sizeof (char *));
	    nInitialPlugins = nPlugin;
	}
	else
	{
	    nInitialPlugins = 0;
	}
    }

    xmlInitParser ();

    LIBXML_TEST_VERSION;

    if (!compInitMetadata (&coreMetadata))
    {
	compLogMessage ("core", CompLogLevelFatal,
			"Couldn't initialize core metadata");
	return 1;
    }

    if (!compAddMetadataFromIO (&coreMetadata,
				readCoreXmlCallback, NULL,
				&ctx))
	return 1;

    if (ctx.refreshRateData)
	free (ctx.refreshRateData);

    if (ctx.pluginData)
	free (ctx.pluginData);

    compAddMetadataFromFile (&coreMetadata, "core");

    if (!initCore ())
	return 1;

    coreInitialized = TRUE;

    if (!disableSm)
    {
	if (clientId == NULL)
	{
	    char *desktop_autostart_id = getenv ("DESKTOP_AUTOSTART_ID");
	    if (desktop_autostart_id != NULL)
		clientId = strdup (desktop_autostart_id);
	    unsetenv ("DESKTOP_AUTOSTART_ID");
	}

	initSession (clientId);
    }

    if (!addDisplay (displayName))
	return 1;

    eventLoop ();

    if (!disableSm)
	closeSession ();

    coreInitialized = FALSE;

    finiCore ();
    compFiniMetadata (&coreMetadata);

    xmlCleanupParser ();

    if (initialPlugins)
        free (initialPlugins);

    if (restartSignal)
    {
	execvp (programName, programArgv);
	return 1;
    }

    return 0;
}