ftp/ftp.x
author Madhusudan.C.S <madhusudancs@gmail.com>
Mon, 18 Jan 2010 17:21:39 +0530
changeset 1 47438813ede2
parent 0 30d751ac6d49
permissions -rw-r--r--
Added support for handling binary files. The problem was I was using XDR strings for reading data, storing it and transferring to the client from the server. But since this is no better than null-terminated string, whenever data had \000 the data used to become corrupt from that point. So now I changed all data to be integer arrays so there is no question of corruption.

/*
 * ftp.x: FTP Protocol specification for remote file fetching
 */

const MAXLEN = 1024;

/*
 * Type for storing path
 */
typedef string filename<MAXLEN>;

/*
 * Structure for sending request. Expects the path of the file
 * and the byte number at which to start reading the file from
 */
struct request {
    filename name;
    int start;
};

/*
 * Type that represents the structute for request
 */
typedef struct request request;

/*
 * Type for storing a chunk of the file that is being
 * sent from the server to the client in the current
 * remote procedure call
 */
typedef int filechunk[MAXLEN];

/*
 * Response sent by the server to the client as a response
 * to remote procedure call, containing the filechunk for
 * the current call and number of bytes actually read
 */
struct chunkreceive {
   filechunk data;
   int items;
};

/*
 * Type that represents the structure for file's chunks
 * to be received from the server
 */
typedef struct chunkreceive chunkreceive;

/*
 * File data sent by the server from client to store
 * it on the server along with the filename and the
 * number of bytes in the data
 */
struct chunksend {
    filename name;
    filechunk data;
    int items;
};

/*
 * Type that represents the structure for file's chunks
 * to be sent to the server 
 */
typedef struct chunksend chunksend;

/*
 * union for returning from remote procedure call, returns
 * the proper chunkdata response if everything worked fine
 * or will return the error number if an error occured
 */
union readfile_res switch (int errno) {
    case 0:
        chunkreceive chunk;
    default:
        void;
};

/*
 * Remote procedure defined in the Interface Definition Language
 * of SUN RPC, contains PROGRAM and VERSION name definitions and
 * the remote procedure signature
 */
program FTPPROG {
    version FTPVER {
	readfile_res retrieve_file(request *) = 1;
	int send_file(chunksend *) = 2;
    } = 1;
} = 0x20000011;