#include <string>
Go to the source code of this file.
Classes | |
class | command |
common structure of a generic command More... | |
Defines | |
#define | register_file 1 |
Declarations for command related structures. | |
#define | unregister_file 2 |
from FS to DFR: server asking for file removal | |
#define | start_file_transfer 3 |
from CL to DFR: client asking for file transfer approval | |
#define | end_file_transfer 4 |
from CL to DFR: client signaling for file transfer completion | |
#define | reg_notification 5 |
from CL to DFR: client asking for notification | |
#define | notify 6 |
from DFR to CL: DFR signaling a notification on a file | |
#define | get_file 7 |
from CL to FS: client askinf for file transfer | |
#define | OK 11 |
command was served correctly | |
#define | ERR_FILE_NOT_REGISTERED 12 |
unregister_file command failed due to unregistered file | |
#define | ERR_TOO_MANY_CLIENTS 13 |
cannot start the trasfer, too many clients on specified file | |
#define | ERR_FILE_NOT_EXISTS 14 |
cannot start file transfer, requested file does not exists | |
#define | ERR_NO_TRANSFER 15 |
cannot stop file transfer, no file transfer was previusly requested | |
#define | ERR_NO_NOTIFICATION 16 |
no notification was requested | |
#define | ERR_UNKNOWN 17 |
unknown error occourred | |
#define | INT_AS_STRING_BYTES 11 |
maximum number of characters in a string containing an integer expression (including \0) | |
Functions | |
int | send_command (int sock, command com, int *rep_data_size, char **rep_data) |
sends a synchronized command | |
int | receive_command (int sock, command *com) |
receives a synchronized command | |
int | reply_command (int sock, int status, int add_bytes, const char *add_data) |
sends a response message to a previously received command | |
int | receive_sft_reply (int sock, int *rep_data_size, char **rep_data) |
receives a response message |
#define end_file_transfer 4 |
from CL to DFR: client signaling for file transfer completion
Definition at line 29 of file command.h.
Referenced by CL_req_s_body(), and send_end_command().
#define ERR_FILE_NOT_EXISTS 14 |
cannot start file transfer, requested file does not exists
Definition at line 46 of file command.h.
Referenced by mode_1(), mode_2(), req_server(), serve_start_file_transfer(), and transfer_file().
#define ERR_FILE_NOT_REGISTERED 12 |
unregister_file command failed due to unregistered file
Definition at line 42 of file command.h.
Referenced by FS_req_s_body().
#define ERR_NO_NOTIFICATION 16 |
no notification was requested
Definition at line 50 of file command.h.
Referenced by mode_2(), and serve_reg_notification().
#define ERR_NO_TRANSFER 15 |
cannot stop file transfer, no file transfer was previusly requested
Definition at line 48 of file command.h.
Referenced by send_end_command(), and serve_end_file_transfer().
#define ERR_TOO_MANY_CLIENTS 13 |
cannot start the trasfer, too many clients on specified file
Definition at line 44 of file command.h.
Referenced by mode_1(), mode_2(), req_server(), serve_start_file_transfer(), and transfer_file().
#define ERR_UNKNOWN 17 |
unknown error occourred
Definition at line 52 of file command.h.
Referenced by receive_sft_reply(), req_server(), and send_command().
#define get_file 7 |
from CL to FS: client askinf for file transfer
Definition at line 35 of file command.h.
Referenced by req_server(), and transfer_file().
#define INT_AS_STRING_BYTES 11 |
maximum number of characters in a string containing an integer expression (including \0)
Definition at line 55 of file command.h.
Referenced by CL_req_s_body(), FS_req_s_body(), main(), mode_1(), mode_2(), reply_command(), req_server(), serve_start_file_transfer(), and command::to_string().
#define notify 6 |
from DFR to CL: DFR signaling a notification on a file
Definition at line 33 of file command.h.
Referenced by mode_2(), and serve_reg_notification().
#define OK 11 |
command was served correctly
Definition at line 40 of file command.h.
Referenced by FS_req_s_body(), main(), mode_1(), mode_2(), req_server(), send_end_command(), serve_end_file_transfer(), serve_reg_notification(), serve_start_file_transfer(), and transfer_file().
#define reg_notification 5 |
from CL to DFR: client asking for notification
Definition at line 31 of file command.h.
Referenced by CL_req_s_body(), and mode_2().
#define register_file 1 |
Declarations for command related structures.
This file contains most of the structures related to commands server and clients can send to the DFR, and the errors that can be sent back to command originator.
notation:
Definition at line 23 of file command.h.
Referenced by FS_req_s_body(), and main().
#define start_file_transfer 3 |
from CL to DFR: client asking for file transfer approval
Definition at line 27 of file command.h.
Referenced by CL_req_s_body(), and mode_1().
#define unregister_file 2 |
from FS to DFR: server asking for file removal
Definition at line 25 of file command.h.
Referenced by FS_req_s_body().
int receive_command | ( | int | sock, | |
command * | com | |||
) |
receives a synchronized command
friend function (forward declaration)
this function receives a singular command from a channel which must have been previously initialized. It will not return until a command is received, or an error occours. received parameters are saved in the command object pointed by com.
sock | | socket from which to receive the command | |
com | | command object to be filled for the caller |
sock | | socket from which to receive the command | |
com | | command object to be filled for the caller |
Definition at line 161 of file command.cpp.
References command::fill_from_string().
Referenced by CL_req_s_body(), FS_req_s_body(), mode_2(), and req_server().
int receive_sft_reply | ( | int | sock, | |
int * | rep_data_size, | |||
char ** | rep_data | |||
) |
receives a response message
this function SHOULD be used only by the CLs, when they ask a notification and the DFR finally signals the disponibility of the file to the client, the server sends a notify command to the client. If the client replies to this message with an OK status, the server assumes that a start_file_transfer command has been initiated by the client, this means that the DFR will reply with a start_file_transfer response message. the CL can use this function to catch that response message.
sock | | socket on which the CL wants to wait for the response | |
rep_data | | pointer to data to be returned to the client (allocated dynamically) | |
rep_data_size | | pointer to an integer to return the size of the rep_data |
Definition at line 213 of file command.cpp.
References ERR_UNKNOWN.
Referenced by mode_2().
int reply_command | ( | int | sock, | |
int | status, | |||
int | add_bytes, | |||
const char * | add_data | |||
) |
sends a response message to a previously received command
each command needs a response message, allowing the corresponding send_command() call to return to the caller. the reply message is built as follows:
<status_integer|size_of_additional_data|additional_data>
status_integer is one of the following values:
size_of_additional_data is an integer-as-string field which is the number of bytes in the following field.
additional_data is the data the responder is sending to the commander which has previously sent a command.
sock | | socket to send the response message | |
status | | status of the request, as described above | |
add_bytes | | number of bytes to be sent as additional data (0 if no additional data) | |
add_data | | pointer to additional data to be sent (NULL if no additional data) |
Definition at line 178 of file command.cpp.
References INT_AS_STRING_BYTES.
Referenced by FS_req_s_body(), mode_2(), req_server(), serve_end_file_transfer(), serve_reg_notification(), and serve_start_file_transfer().
int send_command | ( | int | sock, | |
command | com, | |||
int * | rep_data_size, | |||
char ** | rep_data | |||
) |
sends a synchronized command
friend function (forward declaration)
this function sends a command to a remote server or client, the connection must be previously established. It will not return until some data are received in response on the socket, this means a state message and eventually some data.
the response data will be one of the following, depending on the command:
sock | | socket to contact the opposite end of the channel | |
com | | command to be sent | |
rep_data | | pointer to data to be returned to the caller (allocated dynamically) | |
rep_data_size | | pointer to an integer to return the size of the rep_data, if any |
the response data will be one of the following, depending on the command:
sock | | socket to contact the opposite end of the channel | |
com | | command to be sent | |
rep_data | | pointer to data to be returned to the caller (allocated dynamically) | |
rep_data_size | | pointer to an integer to return the size of the rep_data, if any |
Definition at line 112 of file command.cpp.
References ERR_UNKNOWN, and command::to_string().
Referenced by main(), mode_1(), mode_2(), send_end_command(), serve_reg_notification(), and transfer_file().