//+=====================================================================================================================
// Setup the command system
//
bool  cmdSetup (cmd_t* list,  int max)
{
	cmd_t*  cmdp;

	cmdMax = max;                    
	cmd    = (char*)malloc(cmdMax + 1);  // Allow for NUL terminator

	// Traverse the command list and discover the value for "most arguments"
	argMax  = 1;     // The command itself is the first (0th) argument
	cmdList = list;
	for (cmdp = cmdList;  cmdp->cmd;  cmdp++)
		// 1+ for argv[0]==<command> ... +1 for overflow parameters
		if (1 + cmdp->argMax + 1 > argMax)  argMax = 1 + cmdp->argMax + 1;  
		
	argList = (char*)malloc(cmdMax);
	argPtr  = (char**)malloc(sizeof(*argPtr) * (argMax + 1));  // +1 for NULL terminator

	// Ensure all memory was allocated successfully
	isSetup = cmd && argList && argPtr;

	// Initialise the input buffer
	cmdClear();

	// Announce the system
	Serial.print(txtLibName);
	Serial.print(" v");
	Serial.print(CMDP_VERMIN, DEC);
	Serial.print(".");
	Serial.print(CMDP_VERMAJ, DEC);
	Serial.print(" ");
	Serial.println( (isSetup) ? txtSetupOK : txtSetupFail );

	return isSetup;
}
void Console::onEnter()
{
    if(textCursor().position() == prompt.length())
    {
        insertPrompt();
        return;
    }
    QString cmd = textCursor().block().text().mid(prompt.length()).simplified();
    isLocked = true;
    historyAdd(cmd);
    QTextCharFormat format;
    format.setForeground(Qt::green);
    textCursor().setBlockCharFormat(format);
    this->_currentCommand = cmd;


    if (cmd.startsWith("connect") && !isConnected)
    {
        cmdConnect(cmd.section(" ",1));
    }
    else if (cmd.startsWith("clear"))
    {
        cmdClear();
    }
    else
    {
        if (isConnected) {
            emit onCommand(cmd);
        }
        else
        {
            ConsoleWriteRequest(cmd + ": command unknown");
            CommandFinished();
        }
    }
}
Exemple #3
0
void cmdQuit(heap *ops, bool print)
{
	cmdClear(ops, print);
	hpFree(ops);
	exit(0);
}
Exemple #4
0
// this function is called when we have received a new socket.   We need to 
// create a new node, and add it to our node list.  We need to pass to the node 
// any pointers to other sub-systems that it will need to have, and then we 
// insert the node into the 'node-circle' somewhere.  Finally, we need to add 
// the new node to the event base.
static void server_event_handler(int hid, short flags, void *data)
{
	server_t *server;
	socklen_t addrlen;
	struct sockaddr_storage addr;
	int sfd;
	node_t *node = NULL;
	
	assert(hid >= 0);
	assert(data != NULL);
	
	
  server = (server_t *) data;
	assert(server->handle == hid);

	addrlen = sizeof(addr);
	if ((sfd = accept(hid, (struct sockaddr *)&addr, &addrlen)) == -1) {
		if (errno == EAGAIN || errno == EWOULDBLOCK) {
				/* these are transient, so don't log anything */
		} else if (errno == EMFILE) {
			if (server->verbose > 0)
					fprintf(stderr, "Too many open connections\n");
// 			accept_new_conns(false);
		} else {
			perror("accept()");
		}
	}
	
	// mark socket as non-blocking
	if ((flags = fcntl(sfd, F_GETFL, 0)) < 0 || fcntl(sfd, F_SETFL, flags | O_NONBLOCK) < 0) {
			perror("setting O_NONBLOCK");
			close(sfd);
	}

	printf("New Connection [%d]\n", sfd);


	assert(node == NULL);
	if (server->nodes[sfd] == NULL) {
		printf("Creating a new node\n");

		node = (node_t *) malloc(sizeof(node_t));
		node_init(node);

		server->nodes[sfd] = node;
		node->handle = sfd;
		node->verbose = server->verbose;
		
		assert(node->active == false);
		node->active = true;

		assert(server->stats != NULL);
		node->stats = server->stats;
		
		assert(server->risp != NULL);
		node->risp = server->risp;
		
		assert(server->storepath != NULL);
		node->storepath = server->storepath;
	}
	else {
	
		node = server->nodes[sfd];
		assert(node->storepath != NULL);
		if (node->active == false) {
			printf("Re-using an existing node\n");

			node->handle = sfd;
			node->active = true;
			
			// clear our base out... just to be sure.
			cmdClear(node);
		}
		else {
			assert(node->handle != sfd);
			assert(0);

			// need to code for an instance where we use some other slot.
			
		}
	}
	
	assert(server->event.ev_base != NULL);
	
	// setup the event handling...
	event_set(&node->event, sfd, EV_READ | EV_PERSIST, node_event_handler, (void *)node);
	event_base_set(server->event.ev_base, &node->event);
	event_add(&node->event, 0);
}
QString Commands::execute()
{
    if (strDataList.size() == 0)
        return QString::null;

    QString strCmd = strDataList.at(0).toLower();

    if ((strCmd == "amsg") || (strCmd == "all"))
        return cmdAmsg();
    else if (strCmd == "away")
        return cmdAway();
    else if (strCmd == "busy")
        return cmdBusy();
    else if (strCmd == "clear")
        return cmdClear();
    else if (strCmd == "friend")
        return cmdFriend();
    else if (strCmd == "help" || (Settings::instance()->get("language") == "pl" && strCmd == "pomoc"))
        return cmdHelp();
    else if (strCmd == "ignore")
        return cmdIgnore();
    else if ((strCmd == "join") || (strCmd == "j"))
        return cmdJoin();
    else if ((strCmd == "logout") || (strCmd == "quit") || (strCmd == "q"))
        return cmdQuit();
    else if ((strCmd == "mp3") || (strCmd == "winamp"))
        return cmdMp3();
    else if (strCmd == "offmsg")
        return cmdOffmsg();
    else if ((strCmd == "priv") || (strCmd == "query"))
        return cmdPriv();
    else if ((strCmd == "raw") || (strCmd == "quote"))
        return cmdRaw();
    else if ((strCmd == "whereis") || (strCmd == "whois"))
        return cmdWhereis();

    if ((strChan != DEBUG_WINDOW) && (strChan != STATUS_WINDOW))
    {
        if (strCmd == "ban")
            return cmdBan();
        else if (strCmd == "banip")
            return cmdBanip();
        else if ((strCmd == "cycle") || (strCmd == "hop"))
            return cmdCycle();
        else if (strCmd == "invite")
            return cmdInvite();
        else if (strCmd == "kban")
            return cmdKBan();
        else if (strCmd == "kbanip")
            return cmdKBanip();
        else if ((strCmd == "kick") || (strCmd == "k"))
            return cmdKick();
        else if (strCmd == "me")
            return cmdMe();
        else if ((strCmd == "moder") || (strCmd == "moderator"))
            return cmdModer();
        else if (strCmd == "op")
            return cmdOp();
        else if ((strCmd == "part") || (strCmd == "p"))
            return cmdPart();
        else if (strCmd == "sop")
            return cmdSop();
        else if (strCmd == "topic")
            return cmdTopic();
        else if (strCmd == "vip")
            return cmdVip();
    }

    return strData;
}