y_socket: trying to add dst_dir to specify destination directory when getting file

This commit is contained in:
2025-10-20 09:48:02 +02:00
parent 7c13efe055
commit a776a8cc0f
3 changed files with 39 additions and 6 deletions
@@ -20,6 +20,7 @@ struct arg_send_file{
struct main_list_y_NODE_T *nodes; struct main_list_y_NODE_T *nodes;
y_NODE_T node; y_NODE_T node;
char * filename; char * filename;
char * dst_dir;
struct main_list_y_ptr_HEADER_T *m_ok_head_l_t; struct main_list_y_ptr_HEADER_T *m_ok_head_l_t;
//struct main_list_y_ptr_VARIABLE *m_var; //struct main_list_y_ptr_VARIABLE *m_var;
}; };
+28 -4
View File
@@ -605,8 +605,12 @@ for(int tour_i=0;(tour_i<4) && (check_if_in_ok_header_l_(argS->m_ok_head_l_t, na
++seq; ++seq;
len_local_header_ = sprintf(buf_send, "{ \"cmd\" : \"post file %s\", \"seq\" : %ld , \"tm\" : \"%ld\" }",filename, seq, timeid); len_local_header_ = sprintf(buf_send, "{ \"cmd\" : \"post file %s\", \"seq\" : %ld , \"tm\" : \"%ld\" }",filename, seq, timeid);
} }
if(argS->dst_dir){
len_local_header_ = sprintf(buf_send, "{ \"cmd\" : \"post file %s\", \"seq\" : %ld , \"EOF\" : true , \"tm\" : \"%ld\" , \"dst_dir\" : \"%s\" }",filename, seq, timeid, argS->dst_dir);
}else{
len_local_header_ = sprintf(buf_send, "{ \"cmd\" : \"post file %s\", \"seq\" : %ld , \"EOF\" : true , \"tm\" : \"%ld\" }",filename, seq, timeid); len_local_header_ = sprintf(buf_send, "{ \"cmd\" : \"post file %s\", \"seq\" : %ld , \"EOF\" : true , \"tm\" : \"%ld\" }",filename, seq, timeid);
if(sendto(fds[(c_af==AF_INET6)].fd, }
if(sendto(fds[(c_af==AF_INET6)].fd,
buf_send, len_local_header_, buf_send, len_local_header_,
0, 0,
(struct sockaddr*)&((node).addr), (struct sockaddr*)&((node).addr),
@@ -855,6 +859,9 @@ void receve_from_node(struct pollfd *fds, struct main_list_y_ptr_HEADER_T *m_hea
//size_t size_m_str = 0; //size_t size_m_str = 0;
struct list_y_ptr_STRING * local_current_no_rec = m_str->begin_list; struct list_y_ptr_STRING * local_current_no_rec = m_str->begin_list;
struct list_y_ptr_STRING * local_current; struct list_y_ptr_STRING * local_current;
char *dst_dir=NULL;
size_t len_dst_dir=0;
char eof=0;
for(local_current = local_current_no_rec; local_current; local_current = local_current->next){ for(local_current = local_current_no_rec; local_current; local_current = local_current->next){
char *buf_loc = local_current->value->buf; char *buf_loc = local_current->value->buf;
char nameid[BUF_SIZE/2]=""; char nameid[BUF_SIZE/2]="";
@@ -869,7 +876,6 @@ void receve_from_node(struct pollfd *fds, struct main_list_y_ptr_HEADER_T *m_hea
char * buf_cmd_v = js_cmd->type.object.value->type.string; char * buf_cmd_v = js_cmd->type.object.value->type.string;
*/ */
struct js_value *js_seq_v = get_js_value_of_key("seq", js_header_v ); struct js_value *js_seq_v = get_js_value_of_key("seq", js_header_v );
char eof=0;
if(js_seq_v){ if(js_seq_v){
if(js_seq_v->type.object.value->code_type == jstype_number){ if(js_seq_v->type.object.value->code_type == jstype_number){
size_t seq_local = (long)(js_seq_v->type.object.value->type.number); size_t seq_local = (long)(js_seq_v->type.object.value->type.number);
@@ -881,6 +887,15 @@ void receve_from_node(struct pollfd *fds, struct main_list_y_ptr_HEADER_T *m_hea
eof=1; eof=1;
///printf("debug: \n****************************end of file ***\n\n"); ///printf("debug: \n****************************end of file ***\n\n");
//printf("debug: \n****************************end of file ***\n%s\n**********************************\n",buf_loc); //printf("debug: \n****************************end of file ***\n%s\n**********************************\n",buf_loc);
struct js_value *js_dst_dir_v = get_js_value_of_key("dst_dir", js_header_v );
if(js_dst_dir_v){
if(value_of_(js_dst_dir_v)->code_type == jstype_string){
dst_dir = value_of_(js_dst_dir_v)->type.string;
len_dst_dir = js_dst_dir_v->type.object.value->length;
// copy address of string and then remove from js by assign NULL, we have to free dst_dir after, if not string will free with js_header_v
js_dst_dir_v->type.object.value->type.string=NULL;
}
}
} }
/*struct js_value *js_dst_v = get_js_value_of_key("dst", js_header_v ); /*struct js_value *js_dst_v = get_js_value_of_key("dst", js_header_v );
@@ -909,8 +924,14 @@ void receve_from_node(struct pollfd *fds, struct main_list_y_ptr_HEADER_T *m_hea
struct list_y_ptr_MSG_CONTENT_T * tmpCnt_l = m_content_l->begin_list; struct list_y_ptr_MSG_CONTENT_T * tmpCnt_l = m_content_l->begin_list;
//if(strncmp(buf_cmd_v+5,"file",4)==0){ //if(strncmp(buf_cmd_v+5,"file",4)==0){
int fd_file ; int fd_file ;
char fileNameLocal[tmpCnt_l->value->size_nameid + LEN_REPO_LOCAL + 1]; size_t len_dir=MAX(len_dst_dir, LEN_REPO_LOCAL);
sprintf(fileNameLocal, "%s/%s",REPO_LOCAL,tmpCnt_l->value->nameid);
char fileNameLocal[tmpCnt_l->value->size_nameid + len_dir + 1];
if(dst_dir){
sprintf(fileNameLocal, "%s/%s",dst_dir,tmpCnt_l->value->nameid);
}else{
sprintf(fileNameLocal, "%s/%s",REPO_LOCAL,tmpCnt_l->value->nameid);
}
if((fd_file = open(fileNameLocal, O_WRONLY | O_CREAT , if((fd_file = open(fileNameLocal, O_WRONLY | O_CREAT ,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1){ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1){
fprintf(stderr,"erreur write %s\n",tmpCnt_l->value->nameid); fprintf(stderr,"erreur write %s\n",tmpCnt_l->value->nameid);
@@ -973,6 +994,9 @@ void receve_from_node(struct pollfd *fds, struct main_list_y_ptr_HEADER_T *m_hea
printf("\ndebug NULLL JS___HHHEADER_V \n"); printf("\ndebug NULLL JS___HHHEADER_V \n");
} }
} }
if(dst_dir){
free(dst_dir);
}
//if(local_current){ //if(local_current){
// printf("debug: getchar\n"); // printf("debug: getchar\n");
// getchar(); // getchar();
+10 -2
View File
@@ -250,6 +250,14 @@ void* y_socket_handler_(void *arg){
argS->nodes=nodes; argS->nodes=nodes;
argS->node=argH->node; argS->node=argH->node;
argS->filename=filename; argS->filename=filename;
struct js_value *js_dst_dir = get_js_value_of_key("dst_dir", js_header );
if(js_dst_dir){
argS->dst_dir=js_dst_dir->type.object.value->type.string;
push_back_list_TYPE_PTR(argw->list_arg, argS->dst_dir);
js_dst_dir->type.object.value->type.string=NULL;
}else{
argS->dst_dir = NULL;
}
argS->m_ok_head_l_t=argH->m_ok_head_l_t; argS->m_ok_head_l_t=argH->m_ok_head_l_t;
push_back_list_TYPE_PTR(argw->list_arg, argS); push_back_list_TYPE_PTR(argw->list_arg, argS);
push_back_list_TYPE_PTR(argw->list_arg, filename); push_back_list_TYPE_PTR(argw->list_arg, filename);
@@ -569,7 +577,7 @@ void *y_socket_poll_fds(void *arg){
// printf("debug: ------ //// node.addr_len = %d\n",node.addr_len); // printf("debug: ------ //// node.addr_len = %d\n",node.addr_len);
for(;check_y_socket_go_on(argSock);){ for(;check_y_socket_go_on(argSock);){
printf("poll: wait events\n"); printf(">");//poll: wait events\n");
status = poll(fds, nbIpVersion + 1, -1); status = poll(fds, nbIpVersion + 1, -1);
if(status <= 0){ if(status <= 0){
if(status == -1 && errno != EINTR){ if(status == -1 && errno != EINTR){
@@ -630,7 +638,7 @@ void *y_socket_poll_fds(void *arg){
//printf("fd = %d\n event=%d\n\n",fds[1].fd,pollEventRec); //printf("fd = %d\n event=%d\n\n",fds[1].fd,pollEventRec);
//fds[1].events = 0; //fds[1].events = 0;
puts(">>"); //puts(">>");
memset(buf, 0, sizeof buf); memset(buf, 0, sizeof buf);
//scanf(" %"xstr(BUF_SIZE)"[^\n]%*c", buf); //scanf(" %"xstr(BUF_SIZE)"[^\n]%*c", buf);
buf_len = read(0,buf,BUF_SIZE); buf_len = read(0,buf,BUF_SIZE);