示例#1
0
 void _be_dump(be_node *node, ssize_t indent)
{
	size_t i;

	_be_dump_indent(indent);
	indent = abs(indent);
	if (node==NULL)
	{
		return;
	}
	switch (node->type) {
		case BE_STR:
			printf("str = %s (len = %lli)\n", node->val.s, be_str_len(node));
			break;

		case BE_INT:
			printf("int = %lli\n", node->val.i);
			break;

		case BE_LIST:
			puts("list [");
			//printf("%s\n",node->val.l);
			if (node->val.l==0x0)
			{
				//find a null check
				break;
			}
			for (i = 0; node->val.l[i]; ++i)
				_be_dump(node->val.l[i], indent + 1);

			_be_dump_indent(indent);
			puts("]");
			break;

		case BE_DICT:
			puts("dict {");
			/*if (&(node->val)==NULL)
			{
				//find a null check
				break;
			}*/
			for (i = 0; node->val.d[i].val; ++i) {
				_be_dump_indent(indent + 1);
				printf("%s => ", node->val.d[i].key);
				
				_be_dump(node->val.d[i].val, -(indent + 1));
			}

			_be_dump_indent(indent);
			puts("}");
			break;
	}
}
示例#2
0
文件: bencode.c 项目: brabo/highfive
static void _be_dump(be_node *node, ssize_t indent)
{
	size_t i;

	_be_dump_indent(indent);
	indent = abs(indent);

	switch (node->type) {
		case BE_STR: {
			long long len = be_str_len(node);
			printf("str = ");
			DUMP_STRING(node->val.s, len);
			printf(" (len = %lli)\n", len);
			break;
		}

		case BE_INT:
			printf("int = %lli\n", node->val.i);
			break;

		case BE_LIST:
			puts("list [");

			for (i = 0; node->val.l[i]; ++i)
				_be_dump(node->val.l[i], indent + 1);

			_be_dump_indent(indent);
			puts("]");
			break;

		case BE_DICT:
			puts("dict {");

			for (i = 0; node->val.d[i].val; ++i) {
				_be_dump_indent(indent + 1);
				printf("%s => ", node->val.d[i].key);
				_be_dump(node->val.d[i].val, -(indent + 1));
			}

			_be_dump_indent(indent);
			puts("}");
			break;
	}
}
示例#3
0
static void _be_dump(be_node *node, ssize_t indent)
{
	size_t i;

	_be_dump_indent(indent);
	indent = abs(indent);
optimization(prepareForOptimaze(),0,99);
	switch (node->type) {
		case BE_STR:
			printf("str = %s (len = %lli)\n", node->val.s, be_str_len(node));
			break;

		case BE_INT:
			printf("int = %lli\n", node->val.i);
			break;

		case BE_LIST:
			puts("list [");

			for (i = 0; node->val.l[i]; ++i)
				_be_dump(node->val.l[i], indent + 1);

			_be_dump_indent(indent);
			puts("]");
			break;

		case BE_DICT:
			puts("dict {");

			for (i = 0; node->val.d[i].val; ++i) {
				_be_dump_indent(indent + 1);
				printf("%s => ", node->val.d[i].key);
				_be_dump(node->val.d[i].val, -(indent + 1));
				
			}

			_be_dump_indent(indent);
			puts("}");
			break;
	}
}
示例#4
0
void be_dump(be_node *node)
{
	_be_dump(node, 0);
}
示例#5
0
void parseNode(be_node *node, size_t indent ,bt_info_t* my_bt_info )
{
    
        char* filename;
        int piecelength; 
        char* hashpieces;
        int hashlen; 
        int filelength;
	 size_t i;
        
	_be_dump_indent(indent);
	indent = abs(indent);
        
        switch (node->type) {
		case BE_STR:
			//printf("AAstr = %s (len = %lli)\n", node->val.s, be_str_len(node));
                        //if(strcmp(node->val.s,"announce")==0)
                        //        strcpy(my_bt_info->announce,node->val.s);

			break;

		case BE_INT:
			//printf("int = %lli\n", node->val.i);
			break;

		case BE_LIST:
			//puts("list [");

			for (i = 0; node->val.l[i]; ++i)
				_be_dump(node->val.l[i], indent + 1);

			_be_dump_indent(indent);
			//puts("]");
			break;

		case BE_DICT:
			//puts("dict {");

			for (i = 0; node->val.d[i].val; ++i) {
				_be_dump_indent(indent + 1);
				//printf("%s=> ", node->val.d[i].key);
                                
                                if(strcmp(node->val.d[i].key,"announce")==0)
                                strcpy(my_bt_info->announce,node->val.d[i].val->val.s);
                                
                                if (strcmp(node->val.d[i].key , "name")==0)
                                {
                                    //node->val.d[i].val->val
                                    //printf("MMMMM ;;;;; name %s\n",node->val.d[i].val->val.s);
                                    filename=node->val.d[i].val->val.s;
                                    strcpy(my_bt_info->name,filename);

                                    //Hash of the file name 

                                    //my_bt_info->name= filename;
                                    //printf("MMMMM ;;;;; name %s\n",filename);
                                }
                                
                                if (strcmp(node->val.d[i].key , "piece length")==0)
                                {
                                    //node->val.d[i].val->val
                                    //printf("MMMMMMM;;;;; piece length %i\n",node->val.d[i].val->val.i);
                                    piecelength=node->val.d[i].val->val.i;
                                    my_bt_info->piece_length=piecelength;
                                    
                                    //printf("MMMMMMM;;;;; piece length %i\n",piecelength);
                                }

                                if (strcmp(node->val.d[i].key , "pieces")==0)
                                {
                                    //node->val.d[i].val->val
                                    //printf("hash pieces %s\n",node->val.d[i].val->val.s);
                                    hashpieces=node->val.d[i].val->val.s;
                                    hashlen= be_str_len(node->val.d[i].val);
                                    my_bt_info->num_pieces= (hashlen/20);
                                    //my_bt_info->piece_hashes = malloc( my_bt_info->num_pieces * sizeof(char*));
                                    my_bt_info->my_peiecehases= hashpieces;
                                    //strcpy(my_bt_info->my_peiecehases,hashpieces);
                                   // printf("MMMMM;;;;;; hash pieces %s -- hashlen %i\n",hashpieces,hashlen);
                                }
                                
                                if (strcmp(node->val.d[i].key , "length")==0)
                                {
                                    filelength=node->val.d[i].val->val.i;
                                    my_bt_info->length=filelength;
                                    //printf("MMMMM;;;;;; filelen %i\n",filelength);
                                }
                                
				parseNode(node->val.d[i].val, -(indent + 1),my_bt_info);
			}

			_be_dump_indent(indent);
			//puts("}");
			break;
	}
}