/* send a chunk of the file from server to client */ static int clipboard_send_file_data(int streamId, int lindex, int nPositionLow, int cbRequested) { struct stream *s; int size; int rv; int fd; char full_fn[256]; struct cb_file_info *cfi; if (g_files_list == 0) { LLOGLN(10, ("clipboard_send_file_data: error g_files_list is nil")); return 1; } cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex); if (cfi == 0) { LLOGLN(10, ("clipboard_send_file_data: error cfi is nil")); return 1; } LLOGLN(10, ("clipboard_send_file_data: streamId %d lindex %d " "nPositionLow %d cbRequested %d", streamId, lindex, nPositionLow, cbRequested)); g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename); fd = g_file_open_ex(full_fn, 1, 0, 0, 0); if (fd == -1) { LLOGLN(0, ("clipboard_send_file_data: file open [%s] failed", full_fn)); return 1; } g_file_seek(fd, nPositionLow); make_stream(s); init_stream(s, cbRequested + 64); size = g_file_read(fd, s->data + 12, cbRequested); if (size < 1) { LLOGLN(0, ("clipboard_send_file_data: read error, want %d got %d", cbRequested, size)); free_stream(s); g_file_close(fd); return 1; } out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */ out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */ out_uint32_le(s, size + 4); out_uint32_le(s, streamId); s->p += size; out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); g_file_close(fd); return rv; }
/* returns error returns 0 if everything is ok returns 1 if problem reading file */ static int APP_CC l_file_read_sections(int fd, int max_file_size, struct list *names) { struct stream *s; char text[FILE_MAX_LINE_BYTES]; char c; int in_it; int in_it_index; int len; int index; int rv; rv = 0; g_file_seek(fd, 0); in_it_index = 0; in_it = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); list_clear(names); make_stream(s); init_stream(s, max_file_size); len = g_file_read(fd, s->data, max_file_size); if (len > 0) { s->end = s->p + len; for (index = 0; index < len; index++) { in_uint8(s, c); if (c == '[') { in_it = 1; } else if (c == ']') { list_add_item(names, (tbus)g_strdup(text)); in_it = 0; in_it_index = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); } else if (in_it) { text[in_it_index] = c; in_it_index++; } } } else if (len < 0) { rv = 1; } free_stream(s); return rv; }
int APP_CC dev_redir_process_write_io_request(int completion_id, int offset) { struct stream* s; int fd; char buffer[1024]; int size; make_stream(s); init_stream(s,1100); actions[completion_id].last_req = IRP_MJ_WRITE; log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[dev_redir_process_write_io_request]:" "process next io request[%s]",actions[completion_id].path); out_uint16_le(s, RDPDR_CTYP_CORE); out_uint16_le(s, PAKID_CORE_DEVICE_IOREQUEST); out_uint32_le(s, actions[completion_id].device); out_uint32_le(s, actions[completion_id].file_id); out_uint32_le(s, completion_id); out_uint32_le(s, IRP_MJ_WRITE); /* major version */ out_uint32_le(s, 0); /* minor version */ if(g_file_exist(actions[completion_id].path)){ fd = g_file_open(actions[completion_id].path); g_file_seek(fd, offset); size = g_file_read(fd, buffer, 1024); out_uint32_le(s,size); out_uint64_le(s,offset); out_uint8s(s,20); out_uint8p(s,buffer,size); s_mark_end(s); dev_redir_send(s); actions[completion_id].message_id++; free_stream(s); return 0; } log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[dev_redir_process_write_io_request]:" "the file %s did not exists",actions[completion_id].path); free_stream(s); return 1; }
/* return error */ static int l_file_read_section(int fd, int max_file_size, const char *section, xrdpList *names, xrdpList *values) { struct stream *s; char text[512]; char name[512]; char value[512]; char *lvalue; char c; int in_it; int in_it_index; int len; int index; int file_size; file_size = 32 * 1024; /* 32 K file size limit */ g_file_seek(fd, 0); in_it_index = 0; in_it = 0; g_memset(text, 0, 512); list_clear(names); list_clear(values); make_stream(s); init_stream(s, file_size); len = g_file_read(fd, s->data, file_size); if (len > 0) { s->end = s->p + len; for (index = 0; index < len; index++) { if (!s_check_rem(s, 1)) { break; } in_uint8(s, c); if ((c == '#') || (c == ';')) { file_read_line(s, text); in_it = 0; in_it_index = 0; g_memset(text, 0, 512); continue; } if (c == '[') { in_it = 1; } else if (c == ']') { if (g_strcasecmp(section, text) == 0) { file_read_line(s, text); while (file_read_line(s, text) == 0) { if (g_strlen(text) > 0) { file_split_name_value(text, name, value); list_add_item(names, (tbus) g_strdup(name)); if (value[0] == '$') { lvalue = g_getenv(value + 1); if (lvalue != 0) { list_add_item(values, (tbus) g_strdup(lvalue)); } else { list_add_item(values, (tbus) g_strdup("")); } } else { list_add_item(values, (tbus) g_strdup(value)); } } } free_stream(s); return 0; } in_it = 0; in_it_index = 0; g_memset(text, 0, 512); } else if (in_it) { text[in_it_index] = c; in_it_index++; } } } free_stream(s); return 1; }
/* return error */ static int APP_CC l_file_read_section(int fd, int max_file_size, const char *section, struct list *names, struct list *values) { struct stream *s; char *data; char *text; char *name; char *value; char *lvalue; char c; int in_it; int in_it_index; int len; int index; int file_size; data = (char *) g_malloc(FILE_MAX_LINE_BYTES * 3, 0); text = data; name = text + FILE_MAX_LINE_BYTES; value = name + FILE_MAX_LINE_BYTES; file_size = 32 * 1024; /* 32 K file size limit */ g_file_seek(fd, 0); in_it_index = 0; in_it = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); list_clear(names); list_clear(values); make_stream(s); init_stream(s, file_size); len = g_file_read(fd, s->data, file_size); if (len > 0) { s->end = s->p + len; for (index = 0; index < len; index++) { if (!s_check_rem(s, 1)) { break; } in_uint8(s, c); if ((c == '#') || (c == ';')) { if (file_read_line(s, text, FILE_MAX_LINE_BYTES) != 0) { break; } in_it = 0; in_it_index = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); continue; } if (c == '[') { in_it = 1; } else if (c == ']') { if (g_strcasecmp(section, text) == 0) { file_read_line(s, text, FILE_MAX_LINE_BYTES); while (file_read_line(s, text, FILE_MAX_LINE_BYTES) == 0) { if (g_strlen(text) > 0) { file_split_name_value(text, name, value); list_add_item(names, (tbus)g_strdup(name)); if (value[0] == '$') { lvalue = g_getenv(value + 1); if (lvalue != 0) { list_add_item(values, (tbus)g_strdup(lvalue)); } else { list_add_item(values, (tbus)g_strdup("")); } } else { list_add_item(values, (tbus)g_strdup(value)); } } } free_stream(s); g_free(data); return 0; } in_it = 0; in_it_index = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); } else if (in_it) { text[in_it_index] = c; in_it_index++; if (in_it_index >= FILE_MAX_LINE_BYTES) { break; } } } } free_stream(s); g_free(data); return 1; }