source: abuse/tags/pd/macabuse/src/net/unix/fileman.hpp @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
File size: 1.9 KB
Line 
1#ifndef __FILEMAN_HPP_
2#define __FILEMAN_HPP_
3
4#include <unistd.h>
5#include "sock.hpp"
6#include <stdlib.h>
7#include <string.h>
8
9
10class file_manager
11{
12  net_address *default_fs;
13  int no_security;
14
15  class nfs_client
16  {
17    public :
18    net_socket *sock;
19    int file_fd;
20
21    long size_to_read; 
22    long size;
23    nfs_client *next;
24    nfs_client(net_socket *sock, int file_fd, nfs_client *next);
25    int send_read();     // flushes as much of size_to_read as possible
26    ~nfs_client();
27  } ;
28
29
30  class remote_file    // a remote client has opened this file with us
31  {
32    public :
33    net_socket *sock;
34    void r_close(char *reason);
35    long size;   // server tells us the size of the file when we open it
36    int open_local;
37    remote_file *next;
38    remote_file(net_socket *sock, char *filename, char *mode, remote_file *Next);
39
40    int unbuffered_read(void *buffer, size_t count);
41    int unbuffered_write(void *buf, size_t count) { return 0; } // not supported
42    long unbuffered_tell();
43    long unbuffered_seek(long offset);
44    long file_size() { return size; }
45    int open_failure() { return sock==NULL; }   
46    ~remote_file();
47    int fd() { if (sock) return sock->get_fd(); else return -1; }
48  } ;
49
50
51  nfs_client *nfs_list;
52  remote_file *remote_list;
53
54  int process_nfs_command(nfs_client *c);
55  void secure_filename(char *filename, char *mode);
56  remote_file *find_rf(int fd);
57  net_protocol *proto;
58  public :
59
60  file_manager(int argc, char **argv, net_protocol *proto);
61  void process_net();
62  void add_nfs_client(net_socket *sock);
63
64
65  int rf_open_file(char *&filename, char *mode);
66  long rf_tell(int fd);
67  long rf_seek(int fd, long offset);
68  int rf_read(int fd, void *buffer, size_t count);
69  int rf_close(int fd);
70  long rf_file_size(int fd);
71  void set_default_fs(net_address *def) { default_fs=def->copy(); }
72  ~file_manager() { if (default_fs) delete default_fs; }
73} ;
74
75extern file_manager *fman;
76
77
78#endif
Note: See TracBrowser for help on using the repository browser.