changes upload method
This commit is contained in:
+15
-38
@@ -214,36 +214,6 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/* obsolete */
|
||||
int32_t file_upload_request(char *query, query_args_t *q_args) {
|
||||
char qbuf[INBUFSIZE];
|
||||
char fpath[512];
|
||||
char a_perm;
|
||||
sscanf(query, "file upload \"%s %c", fpath, &a_perm);
|
||||
fpath[strlen(fpath) - 1] = 0; // remove \"
|
||||
int fd = open(fpath, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror(fpath);
|
||||
return -1;
|
||||
}
|
||||
size_t fsize = lseek(fd, 0, SEEK_END);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
char *fname = strrchr(fpath, '/') + 1;
|
||||
int qlen = snprintf(qbuf, INBUFSIZE, "file upload \"%s\" %zu %c", fname,
|
||||
fsize, a_perm);
|
||||
if (qlen > INBUFSIZE) {
|
||||
fprintf(stderr, "query is too large to be sent\n");
|
||||
return -1;
|
||||
}
|
||||
q_args->file = malloc(sizeof(p_file_t));
|
||||
q_args->file->fd = fd;
|
||||
q_args->file->name = malloc(strlen(fname) + 1);
|
||||
strcpy(q_args->file->name, fname);
|
||||
q_args->file->size = fsize;
|
||||
q_args->file->rest = fsize;
|
||||
write(q_args->sd, qbuf, qlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args) {
|
||||
q_args->file = malloc(sizeof(p_file_t));
|
||||
@@ -314,7 +284,9 @@ int32_t file_upload(query_args_t *q_args) {
|
||||
void clear_file_in_query(query_args_t *q_args) {
|
||||
free(q_args->file->name);
|
||||
free(q_args->file->path);
|
||||
free(q_args->file->description);
|
||||
if (q_args->file->description != NULL) {
|
||||
free(q_args->file->description);
|
||||
}
|
||||
free(q_args->file);
|
||||
q_args->file = NULL;
|
||||
}
|
||||
@@ -332,6 +304,7 @@ void init_file_args(file_args_t *f_args) {
|
||||
static void fl_add(fl_item_t **cur, fl_item_t **start, char *line) {
|
||||
char fname[128];
|
||||
char fowner[32];
|
||||
char *descr_begin = NULL;
|
||||
int h_len;
|
||||
fl_item_t *fitem = malloc(sizeof(fl_item_t));
|
||||
sscanf(line, "%s %zu %s%n", fname, &(fitem->size), fowner, &h_len);
|
||||
@@ -342,14 +315,18 @@ static void fl_add(fl_item_t **cur, fl_item_t **start, char *line) {
|
||||
fitem->owner = malloc((sizeof(char)) * (strlen(fowner) + 1));
|
||||
strcpy(fitem->owner, fowner);
|
||||
/* file description */
|
||||
int d_len = strlen(line) - h_len;
|
||||
fitem->description = malloc((sizeof(char)) * (d_len));
|
||||
strcpy(fitem->description, line + h_len + 1); // +1 to escape the dividing \32
|
||||
int i;
|
||||
for (i = 0; i < d_len; i++) {
|
||||
if (fitem->description[i] == '\a') {
|
||||
fitem->description[i] = '\n';
|
||||
descr_begin = line + h_len + 1;
|
||||
if (strcmp(descr_begin, "\n")) {
|
||||
int d_len = strlen(line) - h_len;
|
||||
fitem->description = malloc((sizeof(char)) * (d_len));
|
||||
strcpy(fitem->description, descr_begin); // +1 to escape the dividing \32
|
||||
for (int i = 0; i < d_len; i++) {
|
||||
if (fitem->description[i] == '\a') {
|
||||
fitem->description[i] = '\n';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fitem->description = NULL;
|
||||
}
|
||||
/* fitem->description[strlen(line + line_pos)] = 0; */
|
||||
fitem->next = NULL;
|
||||
|
||||
Reference in New Issue
Block a user