bool xRedisClient::zrevrange(const RedisDBIdx& dbi,  const string& key, int start, int end, VALUES& vValues, bool withscore) {
    if (0==key.length()) {
        return false;
    }
    if (withscore) {
        return command_list(dbi, vValues, "ZREVRANGE %s %d %d %s", key.c_str(), start, end, "WITHSCORES");
    }
    return command_list(dbi, vValues, "ZREVRANGE %s %d %d", key.c_str(), start, end);
}
bool xRedisClient::srandmember(const RedisDBIdx& dbi,  const KEY& key, VALUES& members, int count) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(SLAVE);
	if (0 == count) {
		return command_list(dbi, members, "SRANDMEMBER %s", key.c_str());
	}
	return command_list(dbi, members, "SRANDMEMBER %s %d", key.c_str(), count);
}
bool xRedisClient::smembers(const RedisDBIdx& dbi,  const KEY& key, VALUES& vValue) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(SLAVE);
	return command_list(dbi, vValue, "SMEMBERS %s", key.c_str());
}
/*
 * Function:    commandShell(char *command)
 * Parameters:  None
 * Returns:     None
 * Description: This functions behaves like shell answering all user commands
 */
void Server::commandShell(char *command) {
    CommandID command_id = getCommandID(command); 
    switch(command_id) {
        case COMMAND_HELP:
            // handle help command
            command_help();
            break;
        case COMMAND_CREATOR:
            // handle CREATOR command
            command_creator();
            break;
        case COMMAND_DISPLAY:
            // handle DISPLAY command
            command_display();
            break;
        case COMMAND_LIST:
            // handle LIST command
            command_list();
            break;
        default:
            printf("Please enter a valid command \n");
            printf("Type Help - to display supported commands \n");
            break;
        }
}
Exemple #5
0
static int
decode_command (int argc, char *argv[], ProgEnv *env)
{
    int opt_idx;

    for (opt_idx = 0; opt_idx < argc; opt_idx++) {
        if (strcmp (argv[opt_idx], "add") == 0) {
            ++opt_idx;
            opt_idx += command_add (argc - opt_idx, argv + opt_idx, env);
        } else if (strcmp (argv[opt_idx], "add-list") == 0) {
            ++opt_idx;
            opt_idx += command_add_list (argc - opt_idx, argv + opt_idx, env);
        } else if (strcmp (argv[opt_idx], "delete") == 0) {
            ++opt_idx;
            opt_idx += command_delete (argc - opt_idx, argv + opt_idx, env);
        } else if (strcmp (argv[opt_idx], "delete-list") == 0) {
            ++opt_idx;
            opt_idx += command_delete_list (argc - opt_idx, argv + opt_idx, env);
        } else if (strcmp (argv[opt_idx], "query") == 0) {
            ++opt_idx;
            opt_idx += command_query (argc - opt_idx, argv + opt_idx, env);
        } else if (strcmp (argv[opt_idx], "list") == 0) {
            ++opt_idx;
            opt_idx += command_list (argc - opt_idx, argv + opt_idx, env);
        } else {
            fprintf (stderr, "Unknown command: %s\n", argv[opt_idx]);
            return EXIT_FAILURE;
        }
    }

    return EXIT_SUCCESS;
}
Exemple #6
0
// This is the service loop (essentially the inside of the while(1)
int serv(int fd) {
	char * wd;
	char buf[1024] = {};
	int i = 0;
	int n = 0;
	char dir[1022] = {};
	

	do {
		n = read(fd,&buf[i],sizeof(buf)-i);
		i += n;
	} while (i < sizeof(buf) && buf[i-1] != '\0');
	if(n < 0) errexit("read problem");

//	printf("i: %i,n: %i,buf: %s\n",i,n,buf);
	
	switch(buf[0]) {
		case 'l':
			command_list(fd);
			break;
		case 'p':
			command_print_cwd(fd);
			break;
		case 'c':
			command_change_directory(fd,&buf[2]);
			break;
		case 'g':
			command_get_file(fd,&buf[2]);
			break;
		default:
			break;
	}
	return 1;
}
Exemple #7
0
bool CRedisClient::lrange(const CString &key, int start, int stop, CStringArray &listval)
{
	CString strStart, strStop;
	strStart.Format("%d", start);
	strStop.Format("%d", stop);
	return command_list(listval, "LRANGE %s %s %s", (LPCSTR)key, (LPCSTR)strStart, (LPCSTR)strStop);
}
Exemple #8
0
bool CRedisClient::zrevrange(const CString &key, int start, int stop, CStringArray &listVal, bool withscores)
{
	CString command;
	command.Format("ZREVRANGE %s %d %d", key, start, stop);
	if ( withscores == true )
		command += " WITHSCORES";
	return command_list(listVal, (LPCSTR)command);
}
Exemple #9
0
bool CRedisClient::zrangebyscore(const CString &key, INT64 min, INT64 max, CStringArray &listVal, bool withscores)
{
	CString command;
	command.Format("ZRANGEBYSCORE %s %I64d %I64d", key, min, max);
	if ( withscores == true )
		command += " WITHSCORES";
	return command_list(listVal, (LPCSTR)command);
}
Exemple #10
0
// main client handler procedure, runs in its own thread
void * thread_proc(void * param)
{
	CLIENT_INFO client_info;
	memset(&client_info, 0, sizeof(client_info));
	client_info.fd = (int)param;
	strcpy(client_info.dir, "/");

	send_code(client_info.fd, 220);

	while (1)
	{
		int result = client_read(client_info.fd, client_info.buf, &client_info.buffer_pos);
		if (result == -1) break;

		while (client_info.buffer_pos >= 4)
		{
			char line[BUFFER_SIZE] = { 0 };

			if (compare_command(client_info.buf, "USER")) command_user(&client_info);
			else if (compare_command(client_info.buf, "PASS")) command_pass(&client_info);
			else if (compare_command(client_info.buf, "PWD")) command_pwd(&client_info);
			else if (compare_command(client_info.buf, "PORT")) command_port(&client_info);
			else if (compare_command(client_info.buf, "PASV")) command_pasv(&client_info);
			else if (compare_command(client_info.buf, "LIST")) command_list(&client_info);
			else if (compare_command(client_info.buf, "CWD")) command_cwd(&client_info);
			else if (compare_command(client_info.buf, "RETR")) command_retr(&client_info);
			else if (compare_command(client_info.buf, "NOOP")) command_noop(&client_info);
			else if (compare_command(client_info.buf, "SYST")) command_syst(&client_info);
			else if (compare_command(client_info.buf, "TYPE")) command_type(&client_info);
			else if (compare_command(client_info.buf, "QUIT"))
			{
				get_line(client_info.fd, line, client_info.buf, &client_info.buffer_pos);
				send_code(client_info.fd, 221);
				close(client_info.fd);
				client_info.fd = 0;
				return NULL;
			}
			else
			{
				get_line(client_info.fd, line, client_info.buf, &client_info.buffer_pos);
				send_code(client_info.fd, 500);
			}
		}
	}

	if (client_info.fd != 0)
	{
		close(client_info.fd);
		client_info.fd = 0;
	}

	return NULL;
}
Exemple #11
0
static ret_code_t ili9341_init(void)
{
    ret_code_t err_code;

    err_code = hardware_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    command_list();

    return err_code;
}
Exemple #12
0
static ret_code_t st7735_init(void)
{
    ret_code_t err_code;

    m_st7735.tab_color = ST7735_TAB_COLOR;

    err_code = hardware_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    command_list();

    return err_code;
}
Exemple #13
0
int handle_command(Client *client, StringBuffer *msg) {

    // Skip the COMMAND_START
    char *syntax = msg->buffer + 1;
    // Extract the args of the command
    char *args = strchr(syntax, ' ');
    int syn_len = 0;

    // Store the args in command buffer
    StringBuffer *command = NULL;
    // When command has arguments
    if (args != NULL) {

        syn_len = args - syntax;        
        command = StringBuffer_construct();
        StringBuffer_concat(command, args + 1);
    }
    else {
        syn_len = msg->size;
    }
    // List command
    if (strncmp(syntax, "list", syn_len) == 0) {
        command_list(client, command);   
    }
    // Nick command
    else if (strncmp(syntax, "nick", syn_len) == 0) {
        command_nick(client, command);   
    }
    // Message command
    else if (strncmp(syntax, "msg", syn_len) == 0) {
        command_msg(client, command);   
    }
    // Unknown command!
    else {
        StringBuffer *errorMsg = StringBuffer_construct();
        StringBuffer_concat(errorMsg, "ERROR: Unbekannter Befehl '");
        StringBuffer_concat(errorMsg, syntax);
        StringBuffer_concat(errorMsg, "'!");
        sendAll(client->socket, errorMsg->buffer, errorMsg->size);
        StringBuffer_free(errorMsg);
    }

    // Free temp memory
    if (command != NULL)
        StringBuffer_free(command);
    return EXIT_SUCCESS;
}
Exemple #14
0
bool CRedisClient::keys(const CString &pattern, CStringArray &listval)
{
	return command_list(listval, "KEYS %s", (LPCSTR)pattern);
}
Exemple #15
0
/* Main function. */
int main(int argc, char *argv[]) {
	cli_t cli;
	char *hostname = DEFAULT_HOST;
	char history_file[4096];
	ybool_t interactive_mode = YTRUE;

	bzero(&cli, sizeof(cli_t));
	cli.autocheck = YTRUE;
	if (argc == 2 && argv[1][0] != '-')
		hostname = argv[1];
	if (argc == 3 && !strcmp(argv[2], "-"))
		interactive_mode = YFALSE;
	// init database connection
	if ((cli.finedb = finedb_create(hostname, 11138)) == NULL) {
		printf_color("red", "Memory error.");
		printf("\n");
		exit(1);
	}
	if (finedb_connect(cli.finedb) != FINEDB_OK) {
		printf_color("red", "Unable to connect to server '%s' on port '%d'.", argv[1], 11138);
		printf("\n");
		exit(2);
	}
	// interactive mode init
	if (interactive_mode) {
		char *home = NULL;

		if ((home = getenv("HOME")) != NULL) {
			FILE *hist;

			snprintf(history_file, sizeof(history_file), "%s/%s", home, HISTORY_FILE);
			if ((hist = fopen(history_file, "w+")) != NULL) {
				fclose(hist);
				linenoiseHistoryLoad(HISTORY_FILE);
			}
			linenoiseSetCompletionCallback(cli_completion);
		}
	}
	// main loop
	for (; ; ) {
		char buff[4096], *line = NULL, *pt, *cmd;

		if (!interactive_mode) {
			ssize_t bufsz, linesz = 0;

			while ((bufsz = read(0, buff, sizeof(buff))) > 0) {
				pt = (char*)malloc(linesz + bufsz + 1);
				memcpy(pt, line, linesz);
				memcpy((void*)((size_t)pt + linesz), buff, bufsz);
				linesz += bufsz;
				pt[linesz] = '\0';
				if (line)
					free(line);
				line = pt;
			}
		} else {
			snprintf(buff, sizeof(buff), "%s > ", (cli.dbname ? cli.dbname : "default"));
			if ((line = linenoise(buff)) == NULL)
				break;
		}
		pt = line;
		LTRIM(pt);
		cmd = pt;
		// add command line to history
		linenoiseHistoryAdd(cmd);
		linenoiseHistorySave(history_file);
		// extract the command
		while (*pt && !IS_SPACE(*pt))
			++pt;
		*pt++ = '\0';
		LTRIM(pt);
		/* command management */
		if (cmd[0] == '\0')
			goto reloop;
			//continue;
		// local commands, no need for a running connection
		if (!strcasecmp(cmd, "exit") || !strcasecmp(cmd, "quit"))
			exit(0);
		if (!strcasecmp(cmd, "help") || cmd[0] == '?') {
			command_help();
			goto reloop;
			//continue;
		} else if (!strcasecmp(cmd, "sync")) {
			command_sync(&cli);
			goto reloop;
			//continue;
		} else if (!strcasecmp(cmd, "async")) {
			command_async(&cli);
			goto reloop;
			//continue;
		}
		// commands that need a running connection
		if (!strcasecmp(cmd, "use"))
			command_use(&cli, pt);
		else if (!strcasecmp(cmd, "get"))
			command_get(&cli, pt);
		else if (!strcasecmp(cmd, "del"))
			command_del(&cli, pt);
		else if (!strcasecmp(cmd, "put"))
			command_send_data(&cli, pt, YFALSE, YFALSE);
		else if (!strcasecmp(cmd, "add"))
			command_send_data(&cli, pt, YTRUE, YFALSE);
		else if (!strcasecmp(cmd, "update"))
			command_send_data(&cli, pt, YFALSE, YTRUE);
		else if (!strcasecmp(cmd, "inc"))
			command_inc(&cli, pt);
		else if (!strcasecmp(cmd, "dec"))
			command_dec(&cli, pt);
		else if (!strcasecmp(cmd, "start"))
			command_start(&cli);
		else if (!strcasecmp(cmd, "stop"))
			command_stop(&cli);
#if 0
		else if (!strcasecmp(cmd, "list"))
			command_list(&cli, pt);
#endif
		else if (!strcasecmp(cmd, "ping"))
			command_ping(&cli);
		else if (!strcasecmp(cmd, "autocheck"))
			command_autocheck(&cli, pt);
		else {
			printf_color("red", "Bad command.");
			printf("\n");
		}
reloop:
		free(line);
	}
	return (0);
}
bool xRedisClient::smember(const RedisDBIdx& dbi,  const KEY& key, VALUES& vValue) {
    return command_list(dbi, vValue, "SMEMBER %s", key.c_str());
}
bool xRedisClient::srandmember(const RedisDBIdx& dbi,  const KEY& key, VALUES& members, int count) {
    if (0==count) {
        return command_list(dbi, members, "SRANDMEMBER %s", key.c_str());
    }
    return command_list(dbi, members, "SRANDMEMBER %s %d", key.c_str(), count);
}
Exemple #18
0
void nntp(void)
{
    char    buf[4096];
    int	    len;
    
    while (TRUE) {

	IsDoing("Waiting");
	len = get_nntp(buf, sizeof(buf) -1);
	if (len < 0)
	    return;
	if (len == 0)
	    continue;

	if (strcasestr(buf, (char *)"AUTHINFO PASS") == NULL) {
	    Syslog('n', "< \"%s\"", printable(buf, 0));
	} else {
	    Syslog('n', "< \"AUTHINFO PASS ********\"");
	}
	if (! check_free()) {
	    send_nntp("400 server closed");
	    return;
	}

	/*
	 * Process received command
	 */
	if (strncasecmp(buf, "QUIT", 4) == 0) {
	    send_nntp("205 Goodbye\r\n");
	    return;
	} else if (strncasecmp(buf, "AUTHINFO USER", 13) == 0) {
	    auth_user(buf);
	} else if (strncasecmp(buf, "AUTHINFO PASS", 13) == 0) {
	    auth_pass(buf);
	} else if (strncasecmp(buf, "ARTICLE", 7) == 0) {
	    if (check_auth(buf))
		command_abhs(buf);
	} else if (strncasecmp(buf, "BODY", 4) == 0) {
	    if (check_auth(buf))
		command_abhs(buf);
	} else if (strncasecmp(buf, "LIST", 4) == 0) {
	    if (check_auth(buf))
		command_list(buf);
	} else if (strncasecmp(buf, "GROUP", 5) == 0) {
	    if (check_auth(buf))
		command_group(buf);
	} else if (strncasecmp(buf, "HEAD", 4) == 0) {
	    if (check_auth(buf))
		command_abhs(buf);
	} else if (strncasecmp(buf, "POST", 4) == 0) {
	    if (check_auth(buf))
		command_post(buf);
	} else if (strncasecmp(buf, "IHAVE", 5) == 0) {
	    send_nntp("435 Article not wanted - do not send it");
	} else if (strncasecmp(buf, "NEWGROUPS", 9) == 0) {
	    send_nntp("235 Warning: NEWGROUPS not implemented, returning empty list");
	    send_nntp(".");
	} else if (strncasecmp(buf, "NEWNEWS", 7) == 0) {
	    send_nntp("230 Warning: NEWNEWS not implemented, returning empty list");
	    send_nntp(".");
	} else if (strncasecmp(buf, "SLAVE", 5) == 0) {
	    send_nntp("202 Slave status noted");
	} else if (strncasecmp(buf, "STAT", 4) == 0) {
	    if (check_auth(buf))
		command_abhs(buf);
	} else if (strncasecmp(buf, "MODE READER", 11) == 0) {
	    if (check_auth(buf)) {
		if (authorized)
		    send_nntp("200 Server ready, posting allowed");
		else
		    send_nntp("201 Server ready, no posting allowed");
	    }
	} else if (strncasecmp(buf, "XOVER", 5) == 0) {
	    if (check_auth(buf))
		command_xover(buf);
	} else if (strncasecmp(buf, "HELP", 4) == 0) {
	    send_nntp("100 Help text follows");
	    send_nntp("Recognized commands:");
	    send_nntp("");
	    send_nntp("ARTICLE");
	    send_nntp("AUTHINFO");
	    send_nntp("BODY");
	    send_nntp("GROUP");
	    send_nntp("HEAD");
	    send_nntp("IHAVE (not implemented, messages are always rejected)");
	    send_nntp("LIST");
	    send_nntp("NEWGROUPS (not implemented, always returns an empty list)");
	    send_nntp("NEWNEWS (not implemented, always returns an empty list)");
	    send_nntp("POST");
	    send_nntp("QUIT");
	    send_nntp("SLAVE (has no effect)");
	    send_nntp("STAT");
	    send_nntp("XOVER");
	    send_nntp("");
	    send_nntp("FTNNNTP supports most of RFC-977 and also has support for AUTHINFO and");
	    send_nntp("limited XOVER support (RFC-2980)");
	    send_nntp(".");
	} else {
	    send_nntp("500 Unknown command");
	}
    }
}
Exemple #19
0
void unix_client (int fd)
{
	GList *q = NULL;
	char temp[2048];

	memset (temp, 0, sizeof (temp));
	if (read (fd, temp, sizeof (temp)) < 0) return;

	switch (atoi (temp)) {
	case COMMAND_LIST:
		command_list (fd, g_list_first (queue), playing_mpeg);
		break;

	case COMMAND_INSERT:
	{
		int pos;
		char filename[1024];

		memset (filename, 0, sizeof (filename));
		sscanf (temp + 2, "%[^];];%d\n", filename, &pos);

		q = command_insert (fd, queue, filename,
				    pos, &playing_mpeg, unix_list_count ());
		if (q != NULL) queue = g_list_first (q);
	}
		break;

	case COMMAND_REMOVE:
	{
		int pos = 0;

		sscanf (temp + 2, "%d\n", &pos);
		q = command_remove (fd, queue, pos, &playing_mpeg);
		if (q != NULL) {
			unix_command = COMMAND_REMOVE;
			queue = g_list_first (q);
		}
	}
		break;

	case COMMAND_PLAY:
		unix_command = COMMAND_PLAY;
		break;
	
	case COMMAND_PAUSE:
		unix_command = COMMAND_PAUSE;
		break;
	
	case COMMAND_STOP:
		unix_command = COMMAND_STOP;
		break;

	case COMMAND_NEXT:
		unix_command = COMMAND_NEXT;
		break;
	
	case COMMAND_PREV:
	{
		int temp;

		if ((temp = playing_mpeg - 2) < 0) temp = unix_list_count ();
		playing_mpeg = temp;

		unix_command = COMMAND_NEXT;
	}
		break;

	case COMMAND_MUTE:
		unix_command = COMMAND_MUTE;
		break;

	default:
		dprintf (fd, "%c: Unknown command.\n%c\n",
			 COMMAND_ERROR, COMMAND_DELIM);
	}

	return;
}
bool xRedisClient::hvals(const RedisDBIdx& dbi,  const string& key, VALUES& values) {
    SETDEFAULTIOTYPE(SLAVE);
    return command_list(dbi, values, "HVALS %s", key.c_str());
}
bool xRedisClient::hkeys(const RedisDBIdx& dbi,  const string& key, KEYS& keys){
    SETDEFAULTIOTYPE(SLAVE);
    return command_list(dbi, keys, "HKEYS %s", key.c_str());
}
Exemple #22
0
bool CRedisClient::smembers(const CString &key, CStringArray &listval)
{
	return command_list(listval, "SMEMBERS %s", (LPCSTR)key);
}
Exemple #23
0
bool CRedisClient::hvals(const CString &key, CStringArray &listval)
{
	return command_list(listval, "HVALS %s", (LPCSTR)key);
}
/**
 * \brief main function
 */
int	main(int argc, char *argv[]) {
    debug_set_ident("snowmount");
    CommunicatorSingleton	communicator(argc, argv);

    int	c;
    int	longindex;
    astro::ServerName	servername;
    putenv("POSIXLY_CORRECT=1");
    while (EOF != (c = getopt_long(argc, argv, "dhc:fw", longopts,
                                   &longindex)))
        switch (c) {
        case 'd':
            debuglevel = LOG_DEBUG;
            break;
        case 'f':
            decimal = true;
            break;
        case 'h':
            usage(argv[0]);
            return EXIT_SUCCESS;
        case 'w':
            await_completion = true;
            break;
        default:
            throw std::runtime_error("unknown option");
        }

    // next comes the command
    if (argc <= optind) {
        throw std::runtime_error("command missing");
    }
    std::string	command(argv[optind++]);

    // handle the help command
    if (command == "help") {
        return command_help(argv[0]);
    }

    servername = astro::ServerName(command);

    // next argument must be the command
    if (argc <= optind) {
        throw std::runtime_error("command missing");
    }
    command = std::string(argv[optind++]);

    if (command == "help") {
        return command_help(argv[0]);
    }

    // we need a remote device proxy for all other commands
    Ice::CommunicatorPtr	ic = CommunicatorSingleton::get();
    Ice::ObjectPrx	base = ic->stringToProxy(servername.connect("Devices"));
    DevicesPrx	devices = DevicesPrx::checkedCast(base);

    // handle the list command
    if (command == "list") {
        return command_list(devices);
    }

    // for the other commands we need the mount name
    if (argc <= optind) {
        throw std::runtime_error("no mount name");
    }
    std::string	mountname(argv[optind++]);

    // get a proxy for the mount
    MountPrx	mount = devices->getMount(mountname);

    // get command
    if (command == "get") {
        return command_get(mount);
    }
    if (command == "cancel") {
        return command_cancel(mount);
    }
    if (command == "wait") {
        return command_wait(mount, true);
    }

    // two more arguments are angles
    if (command == "set") {
        if (argc < (optind + 2)) {
            throw std::runtime_error("missing angle arguments");
        }
        RaDec	radec;
        astro::Angle	ra
            = astro::Angle::hms_to_angle(argv[optind++]);
        radec.ra = ra.hours();
        astro::Angle	dec
            = astro::Angle::dms_to_angle(argv[optind++]);
        radec.dec = dec.degrees();
        return command_set(mount, radec);
    }

    // if we get here, then an unknown command was given
    throw std::runtime_error("unknown command");
}
Exemple #25
0
/*PAGE
 *
 * exec_command
 *
 * Parse and execute FTP command.
 *
 * FIXME: This section is somewhat of a hack.  We should have a better
 *        way to parse commands.
 *
 * Input parameters:
 *   info - corresponding SessionInfo structure
 *   cmd  - command to be executed (upper-case)
 *   args - arguments of the command
 *
 * Output parameters:
 *    NONE
 */
static void
exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
{
  char fname[FTPD_BUFSIZE];
  int wrong_command = 0;

  fname[0] = '\0';

  if (!strcmp("PORT", cmd))
  {
    command_port(info, args);
  }
  else if (!strcmp("PASV", cmd))
  {
    command_pasv(info);
  }
  else if (!strcmp("RETR", cmd))
  {
    strncpy(fname, args, 254);
    command_retrieve(info, fname);
  }
  else if (!strcmp("STOR", cmd))
  {
    strncpy(fname, args, 254);
    command_store(info, fname);
  }
  else if (!strcmp("LIST", cmd))
  {
    strncpy(fname, args, 254);
    command_list(info, fname, 1);
  }
  else if (!strcmp("NLST", cmd))
  {
    strncpy(fname, args, 254);
    command_list(info, fname, 0);
  }
  else if (!strcmp("MDTM", cmd))
  {
    strncpy(fname, args, 254);
    command_mdtm(info, fname);
  }
  else if (!strcmp("SYST", cmd))
  {
    send_reply(info, 215, FTPD_SYSTYPE);
  }
  else if (!strcmp("TYPE", cmd))
  {
    if (args[0] == 'I')
    {
      info->xfer_mode = TYPE_I;
      send_reply(info, 200, "Type set to I.");
    }
    else if (args[0] == 'A')
    {
      info->xfer_mode = TYPE_A;
      send_reply(info, 200, "Type set to A.");
    }
    else
    {
      info->xfer_mode = TYPE_I;
      send_reply(info, 504, "Type not implemented.  Set to I.");
    }
  }
  else if (!strcmp("USER", cmd) || !strcmp("PASS", cmd))
  {
    send_reply(info, 230, "User logged in.");
  }
  else if (!strcmp("DELE", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      unlink(fname) == 0)
    {
      send_reply(info, 257, "DELE successful.");
    }
    else
    {
      send_reply(info, 550, "DELE failed.");
    }
  }
  else if (!strcmp("SITE", cmd))
  {
    char* opts;
    split_command(args, &cmd, &opts, &args);
    if(!strcmp("CHMOD", cmd))
    {
      int mask;

      if(!can_write())
      {
        send_reply(info, 550, "Access denied.");
      }
      else {
        char *c;
        c = strchr(args, ' ');
        if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254) 
          && (chmod(fname, (mode_t)mask) == 0))
          send_reply(info, 257, "CHMOD successful.");
        else
          send_reply(info, 550, "CHMOD failed.");
      }
    }
    else
      wrong_command = 1;
  }
  else if (!strcmp("RMD", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      rmdir(fname) == 0)
    {
      send_reply(info, 257, "RMD successful.");
    }
    else
    {
      send_reply(info, 550, "RMD failed.");
    }
  }
  else if (!strcmp("MKD", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
    {
      send_reply(info, 257, "MKD successful.");
    }
    else
    {
      send_reply(info, 550, "MKD failed.");
    }
  }
  else if (!strcmp("CWD", cmd))
  {
    strncpy(fname, args, 254);
    command_cwd(info, fname);
  }
  else if (!strcmp("CDUP", cmd))
  {
    command_cwd(info, "..");
  }
  else if (!strcmp("PWD", cmd))
  {
    command_pwd(info);
  }
  else
    wrong_command = 1;

  if(wrong_command)
    send_reply(info, 500, "Command not understood.");
}