Esempio n. 1
0
/* this is the ftp server function */
int ftp(int fd, int hit) {
	int j, file_fd, filedesc;
	long i, ret, len;
	char * fstr;
	char buffer[BUFSIZE + 1] = {0};

	ret = read(fd, buffer, BUFSIZE); // read FTP request

	if (ret == 0 || ret == -1) { /* read failure stop now */
		close(fd);
		return 1;
	}
	if (ret > 0 && ret < BUFSIZE) /* return code is valid chars */
		buffer[ret] = 0; /* terminate the buffer */
	else
		buffer[0] = 0;

	for (i = 0; i < ret; i++) /* remove CF and LF characters */
		if (buffer[i] == '\r' || buffer[i] == '\n')
			buffer[i] = '*';

	printf("LOG request %s - hit %d\n", buffer, hit);

	/* null terminate after the second space to ignore extra stuff */
	/*for (i = 4; i < BUFSIZE; i++) {
		if (buffer[i] == ' ') { // string is "GET URL " +lots of other stuff
			buffer[i] = 0;
			break;
		}
	}*/

	if (!strncmp(buffer, "get ", 4)) {
		// GET
		if((buffer[5] == '.' && buffer[6] == '.') || buffer[5] == '|') {
			sprintf(buffer, "%s", "negado");
			write(fd,buffer,BUFSIZE);
			close(fd);
		} else {
			getFunction(fd, &buffer[4]);
		}
	} else if (!strncmp(buffer, "put ", 4)) {
		// PUT
		putFunction(fd,&buffer[5]);
	} else if (!strncmp(buffer, "ls ", 3)) {
		// LS
		lsFunction(fd,&buffer[3]);
	} else if (!strncmp(buffer, "mget ", 4)) {
		// MGET
		mgetFunction(fd, &buffer[5]);
	} else if (!strncmp(buffer, "cd ", 3)) {
		// CD
		cdFunction(fd,&buffer[3]);
	} else if (!strncmp(buffer, "reset ", 5)) {
		// RESET CD
		cdResetFunction(fd);
	}

	sleep(1); /* allow socket to drain before signalling the socket is closed */
	close(fd);
	return 0;
}
Esempio n. 2
0
int main()
{
     //Obtaining the path of main.c
    *getcwd(directoryPath,300);
    strcpy(rootPath,directoryPath);

    //Setting the initial directories
    rootDirectory = opendir(directoryPath);
    currentDirectory = rootDirectory;

    int c = 1;
    char d ='\0';
    char l[250];
    Word Words[30];
    printf("[TuriShell]");
    while(c!=0)
    {
        int i=0;
        int j=0;
        while((l[0]=getchar())!='\n')
        {
            if(l[0]!=' ')
            {
                Words[j].c[i]=l[0];
                i++;
            }
            else
            {
                j++;
                i=0;
            }
        }
       /*if(l[0]=='\377')
       {
            printf("LOOOL");
       }*/
        if(compareArray(&Words[0].c,&"cd",2)==1)
        {

            if(Words[1].c[0]=='\000')
            {
                currentDirectory = rootDirectory;
                strcpy(directoryPath,rootPath);
                puts(directoryPath);
            }
            else
            {
                cdFunction(&Words[1].c);
            }
        }
        if(compareArray(&Words[0].c,&"ls",2)==1)
        {
            lsFunction();
        }
        if(compareArray(&Words[0].c,&"clear",5)==1)
        {
            system("clear");
        }
        if(compareArray(&Words[0].c,&"exit",4)==1)
        {
            return 0;
        }
        if(Words[0].c[0]=='.'&&Words[0].c[1]=='/')
        {
            executeProgram(&Words[0].c[1]);
        }
        if(l[0]=='\n')
        {
            printf("[TuriShell]");
        }
        else
        {
            printf("Comando no reconocido");
            printf("[TuriShell]");
        }
        //reset the commands array
        int b =0;
        for(;b<30;b++)
        {
            int p=0;
            for(;p<250;p++)
            {
                Words[b].c[p]='\000';
            }
        }
    }
    return 0;
}