size_t bencode_path2list(const char *pathname, FILE *fp)
{
  const char *pn;
  const char *p = pathname;

  if( bencode_begin_list(fp) != 1 ) return 0;

//acw
  char *pBuf = new char[strlen(pathname) * 6 + 1];
  if(!(CSC(pBuf, (char*)pathname, strlen(pathname) * 6 + 1, strlen(pathname), '\0'))) p = pBuf;

  for(; *p;){
    pn = strchr(p, PATH_SP);
    if( pn ){
//acw
//      if( bencode_buf(p, pn - p, fp) != 1) return 0;
      if( bencode_buf(p, pn - p, fp) != 1) {delete []pBuf; return 0;}

      p = pn + 1;
    }else{
//acw
//      if( bencode_str(p, fp) != 1) return 0;
      if( bencode_str(p, fp) != 1) {delete []pBuf; return 0;}
      break;
    }
  }

//acw
  delete []pBuf;

  return bencode_end_dict_list(fp);
}
Ejemplo n.º 2
0
size_t btFiles::FillMetaInfo(FILE* fp)
{
  BTFILE *p;
  if( m_directory ){
    // multi files
    if( bencode_str("files", fp) != 1 ) return 0;

    if( bencode_begin_list(fp) != 1) return 0;
    
    for( p = m_btfhead; p; p = p->bf_next){
      if( bencode_begin_dict(fp) != 1) return 0;
      
      if( bencode_str("length", fp) != 1 ) return 0;
      if( bencode_int(p->bf_length, fp) != 1) return 0;

      if( bencode_str("path", fp) != 1) return 0;
      if( bencode_path2list(p->bf_filename, fp) != 1 ) return 0;
      
      if( bencode_end_dict_list(fp) != 1) return 0;
    }
    
    if(bencode_end_dict_list(fp) != 1 ) return 0;
    
    if(bencode_str("name", fp) != 1) return 0;
    return bencode_str(m_directory, fp);
    
  }else{
    if( bencode_str("length", fp) != 1 ) return 0;
    if( bencode_int(m_btfhead->bf_length, fp) != 1) return 0;
    
    if( bencode_str("name", fp) != 1 ) return 0;
    return bencode_str(m_btfhead->bf_filename, fp);
  }
  return 1;
}
Ejemplo n.º 3
0
size_t bencode_path2list(const char *pathname, FILE *fp)
{
  const char *pn;
  const char *p = pathname;
  
  if( bencode_begin_list(fp) != 1 ) return 0;
  
  for(; *p;){
    pn = strchr(p, PATH_SP);
    if( pn ){
      if( bencode_buf(p, pn - p, fp) != 1) return 0;
      p = pn + 1;
    }else{
      if( bencode_str(p, fp) != 1) return 0;
      break;
    }
  }
  
  return bencode_end_dict_list(fp);
}