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-- |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
* ftp.x: FTP Protocol specification for remote file fetching |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
const MAXLEN = 1024; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
* Type for storing path |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
typedef string filename<MAXLEN>; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
* Structure for sending request. Expects the path of the file |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
* and the byte number at which to start reading the file from |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
struct request { |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
17 |
filename name; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
int start; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
}; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
* Type that represents the structute for request |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
typedef struct request request; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
* Type for storing a chunk of the file that is being |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
* sent from the server to the client in the current |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
* remote procedure call |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
*/ |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
31 |
typedef int filechunk[MAXLEN]; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
* Response sent by the server to the client as a response |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
* to remote procedure call, containing the filechunk for |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
* the current call and number of bytes actually read |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
struct chunkreceive { |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
39 |
filechunk data; |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
40 |
int items; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
}; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
* Type that represents the structure for file's chunks |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
* to be received from the server |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
typedef struct chunkreceive chunkreceive; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
* File data sent by the server from client to store |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
* it on the server along with the filename and the |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
* number of bytes in the data |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
struct chunksend { |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
55 |
filename name; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
filechunk data; |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
57 |
int items; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
}; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
* Type that represents the structure for file's chunks |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
* to be sent to the server |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
typedef struct chunksend chunksend; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
* union for returning from remote procedure call, returns |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
* the proper chunkdata response if everything worked fine |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
* or will return the error number if an error occured |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
union readfile_res switch (int errno) { |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
72 |
case 0: |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
73 |
chunkreceive chunk; |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
74 |
default: |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
75 |
void; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
}; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
|
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
/* |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
* Remote procedure defined in the Interface Definition Language |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
* of SUN RPC, contains PROGRAM and VERSION name definitions and |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
* the remote procedure signature |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
*/ |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
program FTPPROG { |
1
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
84 |
version FTPVER { |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
85 |
readfile_res retrieve_file(request *) = 1; |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
86 |
int send_file(chunksend *) = 2; |
47438813ede2
Added support for handling binary files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
87 |
} = 1; |
0
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
} = 0x20000011; |
30d751ac6d49
Solution to first assignment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |