bt_info_t parseBencode(char * txt, int len){
  bt_info_t inf;
  //printf("%s\n",txt);
  memset(&inf,0,sizeof(inf));
  int i=0;
  parseDict(txt,len,&i,&inf);
  return inf;
}
Beispiel #2
0
bool MorkParser::parse()
{
	bool Result = true;
	char cur = 0;

	// Run over mork chars and parse each term
	cur = nextChar();

	int i = 0;

	while ( Result && cur )
	{
		if ( !isWhiteSpace( cur ) )
		{
			i++;
			// Figure out what a term
			switch ( cur )
			{
			case '<':
				// Dict
				Result = parseDict();
				break;
			case '/':
				// Comment
				Result = parseComment();
				break;
			case '{':
				Result = parseTable();
				// Table
				break;
			case '[':
				Result = parseRow( 0, 0 );
				// Row
				break;
			case '@':
				Result = parseGroup();
				// Group
				break;
			default:
				error_ = DefectedFormat;
				Result = false;
				break;
			}
		}

		// Get next char
		cur = nextChar();
	}

	return Result;
}
Beispiel #3
0
// Functions to parse plist format are borrowed from pluginsystem.cpp from qutIM instant messenger (see:
// http://www.qutim.org/)
QSettings::SettingsMap parseDict(const QDomNode &rootElement)
{
    QSettings::SettingsMap styleHash;

    if (rootElement.isNull())
        return styleHash;

    QDomNode subelement = rootElement;

    QString key;

    for (QDomNode node = subelement.firstChild(); !node.isNull(); node = node.nextSibling())
    {
        QDomElement element = node.toElement();
        if (element.nodeName() == "key")
            key = element.text();
        else
        {
            QVariant value;
            if (element.nodeName() == "true")
                value = QVariant(true);
            else if (element.nodeName() == "false")
                value = QVariant(false);
            else if (element.nodeName() == "real")
                value = QVariant(element.text().toDouble());
            else if (element.nodeName() == "string")
                value = QVariant(element.text());
            else if (element.nodeName() == "integer")
                value = QVariant(element.text().toInt());
            else if (element.nodeName() == "dict")
                value = parseDict(node);
            styleHash.insert(key, value);
        }
    }
    return styleHash;
}
void processInfo(char * txt, char * info , int * i, int len, bt_info_t *inf){
  //needs to increment i pass next item in dict
  //we care about:

  //char name[FILE_NAME_MAX]; //name of file
  //int piece_length; //number of bytes in each piece
  //int length; //length of the file in bytes
  //int num_pieces; //number of pieces, computed based on above two values
  //char ** piece_hashes; //pointer to 20 byte data buffers containing the sha1sum of each of the pieces

  if(!strcmp(info,"name")){
    char * name=parseString(txt,len,i);
    strcpy(inf->name,name);
    return;
  }
  if(!strcmp(info,"piece length")){
    inf->piece_length=parseInt(txt,len,i);
    //now i should be on the character after the "e"
    return;
  }
  if(!strcmp(info,"length")){
    inf->length=parseInt(txt,len,i);
    //now i should be on the character after the "e"
    return;
  }
  if(txt[*i]=='p'){
      return parseDict(txt,len,i,inf);
  }
  if(!strcmp(info,"pieces")){
    //shoudl be on colon now
    inf->num_pieces=(strToInt(txt,len,i)/20);
    if(txt[*i]==':') *i=*i+1;
    else fprintf(stderr,"wrong stuff bro\n");
    int j;
    //printf("pl=%d\n",inf->num_pieces);
    inf->piece_hashes=(char**)malloc(sizeof(char*)*inf->num_pieces);
    for(j=0;j<inf->num_pieces;j++){
        *(inf->piece_hashes+j)=(char*)malloc(20);
    }
    for(j=0;j<inf->num_pieces;j++){
        char * s=parsePiece(txt,len,i);
        memcpy(*(inf->piece_hashes+j), s, 20);
        free(s);
    }
    return;
  }
  else {
    char * temp; 
    //need to go through whatever follows the item in the dict
    switch (txt[*i]) {
      case '0' ... '9':
      //case '1':
      //case '2':
      //case '3':
      //case '4':
      //case '5':
      //case '6':
      //case '7':
      //case '8':
      //case '9':      
        temp=parseString(txt, len, i);
        free(temp);
        break;
      case 'd':
        parseDict(txt,len, i, inf);
        break;
      case 'i':
        parseInt(txt, len, i);
        break;
    }
  }

}