Esempio n. 1
0
static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
{
	const char *fp;
	char *data;
	va_list ap;
	int ret;
	
	if (level < 0 || level > 7) {
		level = 7;
	}
	if (level > esl_log_level) {
		return;
	}
	
	fp = cut_path(file);

	va_start(ap, fmt);

	ret = esl_vasprintf(&data, fmt, ap);

	if (ret != -1) {
		fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], fp, line, func, data);
		free(data);
	}

	va_end(ap);

}
Esempio n. 2
0
/* upload files to server */
int upload_files(SSL *ssl,int order)
{
  	int n;
	int fd;
	SFT_PACK pack;
	SFT_DATA data;
	char filename[FILENAME_SIZE];
	char *line = NULL;
	int file_size;

	bzero(filename,sizeof(filename));
	/* scan local and server files */
	scan_all(ssl);
	/* get file name*/
	//sftfile_get_name(filename,"Upload");
	line = readline("Upload file name>>");	
	strncpy(filename,line,FILENAME_SIZE);
	free(line);
    /* open the local file */
	fd = sftfile_open(filename,O_RDONLY);
	if(fd < 0)
	{
		return -1;	
	}
	file_size = sftfile_get_size(filename);
	cut_path(filename);
	sprintf(data.file_attr.name,"%s/%s",LOGIN_USER.name,filename);
	data.file_attr.size = file_size;
	//strcpy(data.file_attr.name,filename);
	/* package data and send */
	sftpack_wrap(&pack,order,ASK,"\0");	
	pack.data = data;
	strcpy(pack.buf,LOGIN_USER.name);
	sftpack_send(ssl,&pack);
#if 1
	/* get respond */
	n = sftpack_recv_ack(ssl,order);
	if(n == ACCEPT)
	{
	 sftfile_send(ssl,order,fd,file_size);
	 n = sftpack_recv_ack(ssl,order);
	 if(n == FINISH)
	 {
	 	printf("upload %s to sever succeed,total %0.1fKB\n",
	   	filename,(float)file_size/1024);
		list_server(ssl,CSCS,LOGIN_USER.name,"-xF");	
		divline_ui();
	 }
	 else
	 {
	 	printf("upload %s failure!\n",filename);	
	 }
	}
	else
		fprintf(stderr,"request upload failure!\n");
#endif
  	close(fd);
	return 0;
}
Esempio n. 3
0
/* download server's file */
int download_files(SSL *ssl,int order)
{
	int size;
	int ack,fd;
	char filename[FILENAME_SIZE];
	char localname[FILENAME_SIZE];
	SFT_PACK pack;
	SFT_DATA data;

	/* scan local and server files */
	scan_all(ssl);
	sftfile_userdir(DOWNLOAD_DIR);
	bzero(localname,sizeof(localname));
	/* input filename on server to download */
	sftfile_get_name(filename,"Download");
	if(strstr(filename,"..")!=NULL)
	{
		fprintf(stderr,"filename error: deny contain '..'\n");	
		return -1;
	}
	//sprintf(serv_path,"%s/%s",LOGIN_USER.name,filename);
	sprintf(data.file_attr.name,"%s/%s",LOGIN_USER.name,filename);

	cut_path(filename);
	sprintf(localname,"%s%s",DOWNLOAD_DIR,filename);
	/*send file information to server */
	sftpack_wrap(&pack,order,ASK,"");	
	pack.data = data;
	sftpack_send(ssl,&pack);
	/* receive server respond */
	sftpack_recv(ssl,&pack);
	ack =pack.ack;
	if(ack == ACCEPT)
	{
		size = pack.data.file_attr.size;
		fd = sftfile_open(localname,O_CREAT | O_TRUNC | O_RDWR);
		if(sftfile_recv(ssl,order,fd,size) == 0)
		{
			//size = sftfile_get_size(localname);	
			printf("Downlad %s succeed\n",filename);
			list_client(DOWNLOAD_DIR," --color=auto ");
			divline_ui();
		}	
		else
		{
			printf("Download %s failure!\n",filename);	
			return -1;
		}
	}

	return 0;
}
Esempio n. 4
0
Alignment strip_from_start(const Alignment& aln, size_t drop) {
    if (!drop) return aln;
    Alignment res;
    res.set_name(aln.name());
    res.set_score(aln.score());
    //cerr << "drop " << drop << " from start" << endl;
    res.set_sequence(aln.sequence().substr(drop));
    if (!aln.has_path()) return res;
    *res.mutable_path() = cut_path(aln.path(), drop).second;
    assert(res.has_path());
    if (alignment_to_length(res) != res.sequence().size()) {
        cerr << "failed!!! drop from start 轰" << endl;
        cerr << pb2json(res) << endl << endl;
        assert(false);
    }
    return res;
}
Esempio n. 5
0
Alignment strip_from_end(const Alignment& aln, size_t drop) {
    if (!drop) return aln;
    Alignment res;
    res.set_name(aln.name());
    res.set_score(aln.score());
    //cerr << "drop " << drop << " from end" << endl;
    size_t cut_at = aln.sequence().size()-drop;
    //cerr << "Cut at " << cut_at << endl;
    res.set_sequence(aln.sequence().substr(0, cut_at));
    if (!aln.has_path()) return res;
    *res.mutable_path() = cut_path(aln.path(), cut_at).first;
    assert(res.has_path());
    if (alignment_to_length(res) != res.sequence().size()) {
        cerr << "failed!!! drop from end 轰" << endl;
        cerr << pb2json(res) << endl << endl;
        assert(false);
    }
    return res;
}
Esempio n. 6
0
size_t from_length_before_pos(const Alignment& aln, const Position& pos) {
    return path_from_length(cut_path(aln.path(), pos).first);
}
Esempio n. 7
0
size_t from_length_after_pos(const Alignment& aln, const Position& pos) {
    return path_from_length(cut_path(aln.path(), pos).second);
}