Пример #1
0
int send_file(char *path, long IPaddr, uuid_t *uuids, uint64_t num_uuids, int PN)
{
	FILE *fp = fopen(path,"r");
	char block[DEFAULT_BLOCK_SIZE];
	int i=0;
	fseek(fp,0,SEEK_SET);
	while(!feof(fp))
	{
		char *msg = 0, *err_msg_string = 0;
		uint64_t msg_len;
		int num;
		uuid_t uuid;
		char *resp_msg = 0;
		ErrorCode error;
		struct Node* resp;
		if(i>=num_uuids)
		{
			printf("Not enough uuids\n");
			fclose(fp);
			return 0;
		}
		else
		{
			memset(block,0,sizeof(block));
			num = fread(block, 1, DEFAULT_BLOCK_SIZE, fp);
			create_msg_post_block_request(uuids[i], num, block, &msg, &msg_len);
			error = mysend(msg, IPaddr, PN, msg_len);
			if(error == FAILURE || error == RETRY)
			{
				printf("error in send");
				free(msg);
				fclose(fp);
				return 0;
			}
			else
			{
				resp = myrecv(CLIENT_PORT);
				resp_msg = resp->message;
				if(get_header_type(resp_msg) == BACS_ERROR)
				{
      					parse_msg_error(resp_msg, &err_msg_string);
					printf("%s\n",err_msg_string);
					fclose(fp);
					return 0;
				}
    				else
					parse_msg_post_block_response(resp_msg, &uuid);
			}
			free(err_msg_string);
			free(resp->message);
			free(resp);
			free(msg);
		}
		i++;
	}
	printf("\nFile uploaded successfully\n");
	fclose(fp);
	return 1;
}
Пример #2
0
void make_dir(char* dir, bool l, char* path, unsigned long IPaddr, int PN)
{
  if(l==0)
  {
    char dirpath[1024];
    int result;

    strcpy(dirpath,path);
    strcat(dirpath,"/");
    strcat(dirpath,dir);
   /* printf("dirpath:%s\n",dirpath);*/
    result = mkdir(dirpath, 0777);
    if(result==0)
      printf("Local directory '%s' created at path: %s\n", dir, path);
    else
      perror("mkdir() error");
  }
  else
  {
	char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	ErrorCode error;
	struct Node* resp;
	char dirpath[1024];
    	strcpy(dirpath,path);
	if(strcmp(path,"/")!=0)
    		strcat(dirpath,"/");
    	strcat(dirpath,dir);
	create_msg_post_folder_request(dirpath, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(err_msg_string);
		free(resp->message);
		free(resp);
		return;
	}
	parse_msg_post_folder_response(resp_msg);
	printf("Remote directory '%s' created at path: %s\n", dir, path);
	free(err_msg_string);
	free(resp->message);
	free(resp);
  }
}
Пример #3
0
Файл: pci.c Проект: eparodi/NEOS
void
print_all_devices(){
  int i,j,size;
  uint16_t vendorID;
  uint16_t deviceID;
  uint16_t hType;
  uint32_t data;
  char aux[30];
  for ( i = 0 ; i <= 0xFF ; i++ ){
    for ( j = 0 ; j <= 0xFF ; j++ ){ // j+= 0x08
      vendorID = get_vendor_id(i, j);
      if (vendorID != 0xFFFF){
        size = parse_int(aux,i,10);
        aux[size] = 0;
        print_string("Bus:",0xffffff);
        print_string(aux,0xffffff);
        print_string(",",0xffffff);
        size = parse_int(aux,j>>3,10);
        aux[size] = 0;
        print_string("Device:",0xffffff);
        print_string(aux,0xffffff);
        print_string(",",0xffffff);
        size = parse_int(aux,j&0x7,10);
        aux[size] = 0;
        print_string("Function:",0xffffff);
        print_string(aux,0xffffff);
        print_string(":",0xffffff);
        size = parse_int(aux,vendorID,16);
        aux[size] = 0;
        print_string(" VendorID: 0x",0xffffff);
        print_string(aux,0xffffff);
        deviceID = get_devide_id(i, j);
        size = parse_int(aux,deviceID,16);
        aux[size] = 0;
        print_string(", DeviceID: 0x",0xffffff);
        print_string(aux,0xffffff);
        hType = get_header_type(i,j);
        size = parse_int(aux,hType,16);
        aux[size] = 0;
        print_string(", HeaderType: 0x",0xffffff);
        print_string(aux,0xffffff);
        data = _pci_read_reg(i,j,0x04);
        size = parse_int(aux,data,16);
        aux[size] = 0;
        print_string(", DATA: 0x",0xffffff);
        print_string(aux,0xffffff);
        print_string("\n",0xffffff);
      }
    }
  }
Пример #4
0
void download_folder(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
	char local_temp[1024], remote_temp[1024];
	char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	uint32_t num_metas;
	int i;
	basic_meta_t *basic_metas = 0;
	ErrorCode error;
	struct Node* resp;
    	strcpy(local_temp, local_path);
    	strcpy(remote_temp, remote_path);
    	make_dir(file_name, 0, local_path, IPaddr, PN);
    	change_dir(file_name, local_temp, 0, IPaddr, PN);
    	change_dir(file_name, remote_temp, 1, IPaddr, PN);

	create_msg_get_folder_meta_request(remote_temp, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{	printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s",err_msg_string);
		free(resp->message);
		free(resp);
		free(err_msg_string);
		return;
	}
	parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);
	free(resp->message);
	free(resp);
	free(err_msg_string);
	for(i=0; i < num_metas; i++)
	{
		if(strcmp(basic_metas[i].name,".")!=0 && strcmp(basic_metas[i].name,"..")!=0)
			download_file(basic_metas[i].name, local_temp, remote_temp, IPaddr, PN);
		//free(basic_metas[i].name);
	}
	free(basic_metas);
 	/*download file complete*/
    	printf("Directory downloaded to path: %s\n",local_path);
}
Пример #5
0
void download_file(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
	FILE *fp;   	
	char local_file[1024];
	char remote_file[1024];
	char *msg = 0;
	uint64_t msg_len;
	basic_block_t *blocks = 0;
	uint64_t num_blocks;
	int i;
	ErrorCode error;
	struct Node* resp;
	char * resp_msg = 0, *err_msg_string = 0;
	strcpy(local_file,local_path);
    	strcat(local_file,"/");
    	strcat(local_file,file_name);
	strcpy(remote_file,remote_path);
	if(strcmp(remote_path,"/")!=0)
    		strcat(remote_file,"/");
    	strcat(remote_file,file_name);
    	printf("Downloading file '%s'..\n", file_name);
	create_msg_get_file_request(remote_file, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(resp->message);
		free(resp);
		free(err_msg_string);
		return;
	}
	parse_msg_get_file_response(resp_msg, &blocks, &num_blocks);
	/*printf("UUIDS received: ");*/
	for(i=0; i<num_blocks; i++)
	{
		char *str = uuid_str(blocks[i].uuid);
    		/*printf(" - %s\n", str);*/
    		free(str);
	}
	fp = fopen(local_file, "w"); 
	free(resp->message);
	free(resp);
	free(err_msg_string);
	for(i=0; i<num_blocks; i++)
	{
		char *msg = 0, *resp_msg = 0, *err_msg_string = 0;
		uuid_t uuid;
		uint32_t size;
		char *content = 0;
		ErrorCode error;
		struct  Node* resp;
		create_msg_get_block_request(blocks[i].uuid, &msg, &msg_len);
		/*printf("in client\n");
		print_msg(msg);*/
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			free(blocks);
			close(fp);
			return;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
	      		parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			/*char *str = uuid_str(blocks[i].uuid);
    			printf(" - %s\n", str);
    			free(str);*/
			free(resp->message);
			free(resp);
			free(err_msg_string);
			free(blocks);
			close(fp);
			return;
		}
		parse_msg_get_block_response(resp_msg, &uuid, &size, &content);
		fwrite (content, sizeof(char), size, fp);
		free(content);
		free(resp->message);
		free(resp);
		free(err_msg_string);
	}	
	printf("File downloaded to path: %s\n",local_path);
	fclose(fp);
	free(blocks);
}
Пример #6
0
bool upload_file(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
    	char filepath[1024];
 	struct stat st;
	uint64_t size;
	char *msg = 0, *resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	uuid_t *uuids = 0;
	uint64_t num_uuids;
	ErrorCode error;
	struct Node* resp;
    	printf("...Uploading file '%s'...\n", file_name);
   	strcpy(filepath,local_path);
	strcat(filepath,"/");
    	strcat(filepath,file_name);
	if(stat(filepath, &st)==0)
	{
		size = st.st_size;
	/*	printf("*********************************size= %d\n", size);*/
		if(size == 0)
		{
			printf("File empty. Cannot be uploaded\n");
			return 0;
		}
	}
	else
	{	
		perror("size error: ");
		return 0;
	}
	memset(filepath, 0, 1024);
	strcpy(filepath,remote_path);
	if(strcmp(remote_path,"/")!=0)
		strcat(filepath,"/");
    	strcat(filepath,file_name);
    	create_msg_post_file_request(filepath, size, &msg, &msg_len);
	/*mysend(msg, ...) */
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return 0;
	}	
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(err_msg_string);
		free(resp->message);
		free(resp);
		return 0;
	}
	parse_msg_post_file_response(resp_msg, &uuids, &num_uuids);
	int i;
	
	for(i=0; i<num_uuids; i++)
	{
		char *str = uuid_str(uuids[i]);
    		/*printf(" - %s\n", str);*/
    		free(str);
	}
	free(err_msg_string);
	free(resp->message);
	free(resp);
	if(num_uuids==0)
	{
		printf("***************error num_uuids\n");
		free(uuids);
		return 0;
	}
	bool success;				
	memset(filepath, 0, 1024);
	strcpy(filepath,local_path);
	strcat(filepath,"/");
    	strcat(filepath,file_name);
	success = send_file(filepath, IPaddr, uuids, num_uuids, PN);
	if(success == 0)
	{
		free(uuids);
		return 0;
	}	
	free(uuids);
	return 1;
}	
Пример #7
0
bool change_dir(char* dir, char* path, bool l, unsigned long IPaddr, int PN)
{
	if(l==0)
	{
  		char dirpath[1024];
  		int result;
		memset(dirpath, 0, 1024);
		if(strcmp(path,"/")==0 && strcmp(dir,"..")==0)
			strcpy(dirpath,path);
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")!=0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,"/");
  			strcat(dirpath,dir);
		}
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")==0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,dir);
		}
		else if(strcmp(path,"/")!=0)
		{
    			char** tokens;
    			tokens = str_split(path, '/');
			if (tokens)
    			{
        			int i;
        			for (i = 0; *(tokens + i); i++);
				if(i!=1)
				{
					int j;
					for (j = 0; j<i-1; j++)
        				{
						strcat(dirpath,"/");
						strcat(dirpath,*(tokens + j));
            					free(*(tokens + j));
        				}
				}
				else
					strcpy(dirpath,"/");
        			free(tokens);
			}
		}
		else
			strcpy(dirpath,"/");
  		result = chdir(dirpath);
  		if(result==0)
  		{
    			memset(path, 0, 1024);
			strcpy(path, dirpath);
    			printf("New local path: '%s'\n", path);
  		}
  		else 
  		{
			perror("cd() error");
			return 1;
  		}
	}
	else
	{
		char dirpath[1024];
		char* msg = 0;
		uint64_t msg_len;
		uint32_t num_metas;
		int i;
		basic_meta_t *basic_metas = 0;
		ErrorCode error;
		char* resp_msg =0, *err_msg_string = 0;
		struct Node* resp;
  		memset(dirpath, 0, 1024);
		if(strcmp(path,"/")==0 && strcmp(dir,"..")==0)
			strcpy(dirpath, path);
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")!=0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,"/");
  			strcat(dirpath,dir);
		}
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")==0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,dir);
		}
		else if(strcmp(path,"/")!=0)
		{
    			char** tokens;
    			tokens = str_split(path, '/');
			if (tokens)
    			{
        			int i;
        			for (i = 0; *(tokens + i); i++);
				if(i!=1)
				{
					int j;
					for (j = 0; j<i-1; j++)
        				{
						strcat(dirpath,"/");
						strcat(dirpath,*(tokens + j));
            					free(*(tokens + j));
        				}
				}
				else
					strcpy(dirpath,"/");
        			free(tokens);
			}
		}
		else
			strcpy(dirpath,"/");
  	/*	printf("dirpath:%s\n",dirpath);		*/
		create_msg_get_folder_meta_request(dirpath, &msg, &msg_len);
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			return 1;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
      			parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			free(err_msg_string);
			free(resp->message);
			free(resp);
			return 1;
		}
		parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);
		free(err_msg_string);
		free(resp->message);
		free(resp);
	/*	printf("remote directory contains: \n");*/
		for(i=0; i < num_metas; i++)
		{
			/*printf("%s\n",basic_metas[i].name);*/
			free(basic_metas[i].name);
		}
		memset(path, 0, 1024);
		strcpy(path, dirpath);
		free(basic_metas);
		printf("New remote path: '%s'\n", path);
	}
  	return 0;
}
Пример #8
0
void list_dir(char* path, bool l, unsigned long IPaddr, int PN)
{
	if(l==0)
	{
  		DIR *dp;
  		struct dirent *ep;
		dp = opendir (path);
  		if (dp != NULL)
  		{
    			while ((ep = readdir (dp)))
      			{
				if(strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0)			
				{
					if(ep->d_type == DT_REG)
					{
						int size = -1;
						char filepath[1024];
						struct stat st;
						strcpy(filepath,path);
						strcat(filepath,"/");
						strcat(filepath,ep->d_name);
						if(stat(filepath, &st)==0)
							size = st.st_size;
						else
							perror("Unable to calculate file size: ");
						printf("%s	File	Size: %d\n",ep->d_name, size);
					}
					if(ep->d_type == DT_DIR)
						printf("%s	Folder\n",ep->d_name);	
				}	
			}
    			closedir (dp);
  		}
  		else
    			perror ("ls() error");
	}
	else
	{
		char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
		uint64_t msg_len;
		uint32_t num_metas;
		int i;
		basic_meta_t *basic_metas = 0;
		ErrorCode error;
		struct Node* resp;
		create_msg_get_folder_meta_request(path, &msg, &msg_len);
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			return;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
      			parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			free(err_msg_string);
			free(resp->message);
			free(resp);
			return;
		}
    		parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);	
		free(err_msg_string);
		free(resp->message);
		free(resp);	
		if(num_metas>0)
		{
			/*printf("remote directory contains: \n");*/
			for(i=0; i < num_metas; i++)
			{
				if(basic_metas[i].type==BACS_FILE_TYPE)
					printf("%s	FILE	Size: %d\n",basic_metas[i].name,basic_metas[i].size);
				else
					printf("%s	FOLDER\n",basic_metas[i].name);
				free(basic_metas[i].name);
			}
		}
		else
			printf("Empty folder.\n");
		free(basic_metas);
	}
}