diff --git a/y_socket_t/include/y_socket_t/y_file_handler.h b/y_socket_t/include/y_socket_t/y_file_handler.h index 25d761c..bf02981 100644 --- a/y_socket_t/include/y_socket_t/y_file_handler.h +++ b/y_socket_t/include/y_socket_t/y_file_handler.h @@ -20,6 +20,7 @@ struct arg_send_file{ struct main_list_y_NODE_T *nodes; y_NODE_T node; char * filename; + char * dst_dir; struct main_list_y_ptr_HEADER_T *m_ok_head_l_t; //struct main_list_y_ptr_VARIABLE *m_var; }; diff --git a/y_socket_t/src/y_socket_t/y_file_handler.c b/y_socket_t/src/y_socket_t/y_file_handler.c index b957ab7..999678f 100644 --- a/y_socket_t/src/y_socket_t/y_file_handler.c +++ b/y_socket_t/src/y_socket_t/y_file_handler.c @@ -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; 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); - if(sendto(fds[(c_af==AF_INET6)].fd, + } + if(sendto(fds[(c_af==AF_INET6)].fd, buf_send, len_local_header_, 0, (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; struct list_y_ptr_STRING * local_current_no_rec = m_str->begin_list; 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){ char *buf_loc = local_current->value->buf; 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; */ 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->type.object.value->code_type == jstype_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; ///printf("debug: \n****************************end of file ***\n\n"); //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 ); @@ -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; //if(strncmp(buf_cmd_v+5,"file",4)==0){ int fd_file ; - char fileNameLocal[tmpCnt_l->value->size_nameid + LEN_REPO_LOCAL + 1]; - sprintf(fileNameLocal, "%s/%s",REPO_LOCAL,tmpCnt_l->value->nameid); + size_t len_dir=MAX(len_dst_dir, LEN_REPO_LOCAL); + + 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 , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1){ 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"); } } + if(dst_dir){ + free(dst_dir); + } //if(local_current){ // printf("debug: getchar\n"); // getchar(); diff --git a/y_socket_t/src/y_socket_t/y_socket_t.c b/y_socket_t/src/y_socket_t/y_socket_t.c index 007252f..4e2dd77 100644 --- a/y_socket_t/src/y_socket_t/y_socket_t.c +++ b/y_socket_t/src/y_socket_t/y_socket_t.c @@ -250,6 +250,14 @@ void* y_socket_handler_(void *arg){ argS->nodes=nodes; argS->node=argH->node; 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; push_back_list_TYPE_PTR(argw->list_arg, argS); 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); for(;check_y_socket_go_on(argSock);){ - printf("poll: wait events\n"); + printf(">");//poll: wait events\n"); status = poll(fds, nbIpVersion + 1, -1); if(status <= 0){ 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); //fds[1].events = 0; - puts(">>"); + //puts(">>"); memset(buf, 0, sizeof buf); //scanf(" %"xstr(BUF_SIZE)"[^\n]%*c", buf); buf_len = read(0,buf,BUF_SIZE);