Changeset 839 for branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
- Timestamp:
- Aug 7, 2017, 2:56:24 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
r822 r839 9 9 * by the French National Research Agency 10 10 * 11 * permission is hereby granted, free of charge, to any person obtaining a copy11 * Permission is hereby granted, free of charge, to any person obtaining a copy 12 12 * of this software and associated documentation files (the "Software"), to deal 13 13 * in the Software without restriction, including without limitation the rights … … 249 249 * @return true in case of success, false if failure occured 250 250 */ 251 size_t ssh_file_exists(maps* conf,const char* targetPath ){251 size_t ssh_file_exists(maps* conf,const char* targetPath,int cnt){ 252 252 size_t result=-1; 253 int cnt=ssh_get_cnt(conf);254 253 if(cnt>0) 255 254 cnt-=1; … … 303 302 * @return true in case of success, false if failure occured 304 303 */ 305 bool ssh_copy(maps* conf,const char* localPath,const char* targetPath ){304 bool ssh_copy(maps* conf,const char* localPath,const char* targetPath,int cnt){ 306 305 char mem[1024 * 1000]; 307 306 size_t nread; … … 310 309 long total = 0; 311 310 int duration; 312 int cnt=ssh_get_cnt(conf);313 311 int rc; 314 312 LIBSSH2_SFTP_HANDLE *sftp_handle; … … 323 321 if (!local) { 324 322 fprintf(stderr, "Can't open local file %s\n", localPath); 325 return -1;323 return false; 326 324 } 327 325 … … 382 380 duration = (int)(time(NULL)-start); 383 381 fclose(local); 384 libssh2_sftp_close (sftp_handle);382 libssh2_sftp_close_handle(sftp_handle); 385 383 386 384 libssh2_sftp_shutdown(sessions[cnt]->sftp_session); … … 396 394 * @return true in case of success, false if failure occured 397 395 */ 398 int ssh_fetch(maps* conf,const char* localPath,const char* targetPath ){396 int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){ 399 397 char mem[1024]; 400 398 size_t nread; … … 403 401 long total = 0; 404 402 int duration; 405 int cnt=ssh_get_cnt(conf);406 403 int rc; 407 404 LIBSSH2_SFTP_HANDLE *sftp_handle; … … 428 425 if (!sftp_handle) { 429 426 if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) { 430 431 427 fprintf(stderr, "Unable to open file with SFTP\n"); 432 428 return -1; … … 443 439 do { 444 440 rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); 445 fprintf(stderr, "libssh2_sftp_read returned %d\n", 446 rc); 447 441 /*fprintf(stderr, "libssh2_sftp_read returned %d\n", 442 rc);*/ 448 443 if(rc > 0) { 449 444 //write(2, mem, rc); 450 445 fwrite(mem, rc, 1, local); 451 446 } … … 479 474 duration = (int)(time(NULL)-start); 480 475 fclose(local); 481 libssh2_sftp_close (sftp_handle);476 libssh2_sftp_close_handle(sftp_handle); 482 477 483 478 libssh2_sftp_shutdown(sessions[cnt]->sftp_session); … … 491 486 * @return bytecount resulting from the execution of the command 492 487 */ 493 int ssh_exec(maps* conf,const char* command){ 494 int cnt=ssh_get_cnt(conf); 488 int ssh_exec(maps* conf,const char* command,int cnt){ 495 489 LIBSSH2_CHANNEL *channel; 496 490 int rc; … … 571 565 while (libssh2_session_disconnect(con->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi") 572 566 == LIBSSH2_ERROR_EAGAIN); 573 libssh2_session_free(con->session);574 567 #ifdef WIN32 575 568 closesocket(con->sock_id); … … 577 570 close(con->sock_id); 578 571 #endif 572 libssh2_session_free(con->session); 579 573 return true; 580 574 } … … 596 590 return true; 597 591 } 592 593 bool addToUploadQueue(maps** conf,maps* input){ 594 map* queueMap=getMapFromMaps(*conf,"uploadQueue","length"); 595 if(queueMap==NULL){ 596 maps* queueMaps=createMaps("uploadQueue"); 597 queueMaps->content=createMap("length","0"); 598 addMapsToMaps(conf,queueMaps); 599 freeMaps(&queueMaps); 600 free(queueMaps); 601 queueMap=getMapFromMaps(*conf,"uploadQueue","length"); 602 } 603 maps* queueMaps=getMaps(*conf,"uploadQueue"); 604 int queueIndex=atoi(queueMap->value); 605 if(input!=NULL){ 606 if(getMap(input->content,"cache_file")!=NULL){ 607 map* length=getMap(input->content,"length"); 608 if(length==NULL){ 609 addToMap(input->content,"length","1"); 610 length=getMap(input->content,"length"); 611 } 612 int len=atoi(length->value); 613 int i=0; 614 for(i=0;i<len;i++){ 615 616 map* tmp[2]={getMapArray(input->content,"localPath",i), 617 getMapArray(input->content,"targetPath",i)}; 618 619 setMapArray(queueMaps->content,"input",queueIndex,input->name); 620 setMapArray(queueMaps->content,"localPath",queueIndex,tmp[0]->value); 621 setMapArray(queueMaps->content,"targetPath",queueIndex,tmp[1]->value); 622 queueIndex+=1; 623 } 624 } 625 } 626 #ifdef DEBUG 627 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 628 fflush(stderr); 629 dumpMaps(queueMaps); 630 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 631 fflush(stderr); 632 dumpMaps(*conf); 633 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 634 fflush(stderr); 635 #endif 636 return true; 637 } 638 639 bool runUpload(maps** conf){ 640 SSHCON *test=ssh_connect(*conf); 641 if(test==NULL){ 642 return false; 643 } 644 #ifdef DEBUG 645 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 646 fflush(stderr); 647 dumpMaps(getMaps(*conf,"uploadQueue")); 648 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 649 fflush(stderr); 650 #endif 651 map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length"); 652 maps* queueMaps=getMaps(*conf,"uploadQueue"); 653 if(queueLengthMap!=NULL){ 654 int cnt=atoi(queueLengthMap->value); 655 int i=0; 656 for(i=0;i<cnt;i++){ 657 map* argv[3]={ 658 getMapArray(queueMaps->content,"input",i), 659 getMapArray(queueMaps->content,"localPath",i), 660 getMapArray(queueMaps->content,"targetPath",i) 661 }; 662 fprintf(stderr,"%s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value); 663 ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf)); 664 } 665 } 666 return true; 667 }
Note: See TracChangeset
for help on using the changeset viewer.