Ignore:
Timestamp:
Mar 18, 2008, 9:36:56 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Get rid of ugly tabs and trailing spaces everywhere.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/net/fileman.cpp

    r90 r124  
    3131
    3232file_manager::file_manager(int argc, char **argv, net_protocol *proto) : proto(proto)
    33 { 
     33{
    3434  default_fs=NULL;
    3535  no_security=0;
     
    5959      ok=0;
    6060      //fprintf(stderr,"Killing nfs client, socket went bad\n");
    61     } 
     61    }
    6262    else if (nc->size_to_read && nc->sock->ready_to_write())
    6363      ok=nc->send_read();
    6464    else if (nc->sock->ready_to_read())
    6565      ok=process_nfs_command(nc);    // if we couldn't process the packeted, delete the connection
    66    
     66
    6767    if (ok)
    6868    {
     
    117117      return 1;
    118118    } break;
    119    
     119
    120120    default :
    121121    { fprintf(stderr,"net driver : bad command from nfs client\n");
    122122      return 0;
    123123    }
    124   } 
     124  }
    125125}
    126126
     
    132132    if (sock->ready_to_write())
    133133    {
    134       char buf[READ_PACKET_SIZE];   
     134      char buf[READ_PACKET_SIZE];
    135135      short read_total;
    136136      short actual;
    137137
    138138      do
    139       {     
    140         read_total=size_to_read>(READ_PACKET_SIZE-2) ? (READ_PACKET_SIZE-2) : size_to_read;
    141 
    142         actual=read(file_fd,buf+2,read_total);
    143         *((ushort *)buf)=lstl(actual);
    144 
    145         int write_amount=sock->write(buf,actual+2);
    146         if (write_amount!=actual+2)
    147         {
    148           fprintf(stderr,"write failed\n");
    149           return 0;
    150         }
    151 
    152         size_to_read-=actual;
    153 
    154         if (!sock->ready_to_write())
    155         {
    156           sock->read_unselectable();
    157           sock->write_selectable();
    158           return 1;    // not ok to write anymore, try again latter
    159         }
     139      {
     140    read_total=size_to_read>(READ_PACKET_SIZE-2) ? (READ_PACKET_SIZE-2) : size_to_read;
     141
     142    actual=read(file_fd,buf+2,read_total);
     143    *((ushort *)buf)=lstl(actual);
     144
     145    int write_amount=sock->write(buf,actual+2);
     146    if (write_amount!=actual+2)
     147    {
     148      fprintf(stderr,"write failed\n");
     149      return 0;
     150    }
     151
     152    size_to_read-=actual;
     153
     154    if (!sock->ready_to_write())
     155    {
     156      sock->read_unselectable();
     157      sock->write_selectable();
     158      return 1;    // not ok to write anymore, try again latter
     159    }
    160160
    161161      } while (size_to_read && actual==read_total);
     
    166166      size_to_read=0;
    167167      return 1;
    168     } else 
     168    } else
    169169    {
    170170      sock->read_unselectable();
     
    180180{
    181181  if (!no_security)
    182   {   
     182  {
    183183    if (filename[0]=='/') { filename[0]=0; return ; }
    184184    int level=0;
     
    189189      else if (*f=='.' && f[1]=='.')
    190190      {
    191         if (f[3]=='.') while (*f!='.') f++;
    192         else
    193         {
    194           f+=2;
    195           level--;
    196         }
    197       } else f++; 
    198      
     191    if (f[3]=='.') while (*f!='.') f++;
     192    else
     193    {
     194      f+=2;
     195      level--;
     196    }
     197      } else f++;
     198
    199199    }
    200200    if (level<0)
     
    206206
    207207
    208 file_manager::nfs_client::nfs_client(net_socket *sock, int file_fd, nfs_client *next) : 
     208file_manager::nfs_client::nfs_client(net_socket *sock, int file_fd, nfs_client *next) :
    209209  sock(sock),file_fd(file_fd),next(next),size_to_read(0)
    210 { 
     210{
    211211  sock->read_selectable();
    212 } 
    213 
    214 
    215 file_manager::nfs_client::~nfs_client() 
    216 { 
     212}
     213
     214
     215file_manager::nfs_client::~nfs_client()
     216{
    217217  delete sock;
    218218  if (file_fd>=0)
     
    228228  if (sock->read(filename,size[0])!=size[0]) { delete sock; return ; }
    229229  if (sock->read(mode,size[1])!=size[1]) { delete sock; return ; }
    230  
     230
    231231
    232232  secure_filename(filename,mode);  // make sure this filename isn't a security risk
     
    242242    mp++;
    243243  }
    244      
     244
    245245  int f=open(filename,flags,S_IRWXU | S_IRWXG | S_IRWXO);
    246246
    247   FILE *fp=fopen("open.log","ab"); 
     247  FILE *fp=fopen("open.log","ab");
    248248  fprintf(fp,"open file %s, fd=%d\n",filename,f);
    249249  fclose(fp);
    250  
    251   if (f<0) 
     250
     251  if (f<0)
    252252    f=-1;  // make sure this is -1
    253253
     
    273273
    274274
    275 void file_manager::remote_file::r_close(char const *reason) 
    276 { 
     275void file_manager::remote_file::r_close(char const *reason)
     276{
    277277//  if (reason) fprintf(stderr,"remote_file : %s\n",reason);
    278278
     
    296296
    297297  int32_t remote_file_fd;
    298   if (sock->read(&remote_file_fd,sizeof(remote_file_fd))!=sizeof(remote_file_fd)) 
    299   { r_close("could not read remote fd"); return ; }   
     298  if (sock->read(&remote_file_fd,sizeof(remote_file_fd))!=sizeof(remote_file_fd))
     299  { r_close("could not read remote fd"); return ; }
    300300  remote_file_fd=lltl(remote_file_fd);
    301301  if (remote_file_fd<0) { r_close("remote fd is bad"); return ; }
    302302
    303   if (sock->read(&size,sizeof(size))!=sizeof(size)) { r_close("could not read remote filesize"); return ; } 
     303  if (sock->read(&size,sizeof(size))!=sizeof(size)) { r_close("could not read remote filesize"); return ; }
    304304
    305305  size=lltl(size);
     
    322322    do
    323323    {
    324       if (sock->read(&packet_size,sizeof(packet_size))!=sizeof(packet_size)) 
     324      if (sock->read(&packet_size,sizeof(packet_size))!=sizeof(packet_size))
    325325      {
    326         fprintf(stderr,"could not read packet size\n");
    327         return 0;
     326    fprintf(stderr,"could not read packet size\n");
     327    return 0;
    328328      }
    329329
    330330      packet_size=lstl(packet_size);
    331331
    332       ushort size_read=sock->read(buf,packet_size); 
    333 
    334       if (size_read!=packet_size) 
    335       { 
    336         if (sock->read(buf+2+size_read,packet_size-size_read)!=packet_size-size_read)
    337         {
    338           fprintf(stderr,"incomplete packet\n");
    339           return 0;
    340         }
     332      ushort size_read=sock->read(buf,packet_size);
     333
     334      if (size_read!=packet_size)
     335      {
     336    if (sock->read(buf+2+size_read,packet_size-size_read)!=packet_size-size_read)
     337    {
     338      fprintf(stderr,"incomplete packet\n");
     339      return 0;
     340    }
    341341      }
    342342
     
    346346      total_read+=packet_size;
    347347      count-=packet_size;
    348     } while (packet_size==READ_PACKET_SIZE-2 && count);     
     348    } while (packet_size==READ_PACKET_SIZE-2 && count);
    349349    return total_read;
    350350  }
     
    360360
    361361    int32_t offset;
    362     if (sock->read(&offset,sizeof(offset))!=sizeof(offset)) { r_close("tell : could not read offset"); return 0; }   
     362    if (sock->read(&offset,sizeof(offset))!=sizeof(offset)) { r_close("tell : could not read offset"); return 0; }
    363363    return lltl(offset);
    364   }   
     364  }
    365365  return 0;
    366366}
     
    376376    if (sock->write(&off,sizeof(off))!=sizeof(off)) { r_close("seek : could not send offset"); return 0; }
    377377
    378     if (sock->read(&offset,sizeof(offset))!=sizeof(offset)) { r_close("seek : could not read offset"); return 0; }   
     378    if (sock->read(&offset,sizeof(offset))!=sizeof(offset)) { r_close("seek : could not read offset"); return 0; }
    379379    return lltl(offset);
    380   }   
     380  }
    381381  return 0;
    382382}
     
    402402  } else if (default_fs)
    403403    fs_server_addr=default_fs->copy();
    404  
     404
    405405  if (fs_server_addr)
    406406  {
     
    409409
    410410    if (!sock)
    411     { 
     411    {
    412412      fprintf(stderr,"unable to connect\n");
    413413      return -1;
     
    420420      return -1;
    421421    }
    422     else 
     422    else
    423423    {
    424424      remote_list=rf;
    425425      return rf->sock->get_fd();
    426     }     
     426    }
    427427  }
    428428
     
    450450    return -2;
    451451  }
    452  
     452
    453453  return -1;
    454454}
     
    501501    delete rf;
    502502    return 1;
    503   } else 
    504   {
    505     fprintf(stderr,"Bad fd for remote file %d\n",fd); 
     503  } else
     504  {
     505    fprintf(stderr,"Bad fd for remote file %d\n",fd);
    506506    return 0;
    507   } 
     507  }
    508508}
    509509
Note: See TracChangeset for help on using the changeset viewer.