home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / abuse / src / net / inc / sock.hpp < prev   
Encoding:
C/C++ Source or Header  |  1996-04-12  |  3.7 KB  |  105 lines

  1. #ifndef __SOCK_HPP_
  2. #define __SOCK_HPP_
  3.  
  4. extern const char notify_signature[];
  5. extern const char notify_response[];
  6.  
  7. class net_address
  8.   public :
  9.   enum protocol { IP, IPX, MODEM, NETBIOS, OTHER };
  10.   virtual protocol protocol_type() const = 0;
  11.   virtual int equal(const net_address *who) const = 0;
  12.   int operator==(const net_address &who) { return equal(&who); }
  13.   virtual int set_port(int port) = 0;
  14.   virtual int get_port() = 0;
  15.   virtual void print()               { ; }
  16.   virtual net_address *copy()    = 0;
  17.   virtual void store_string(char *st, int st_length) = 0;    // this should be able to be used get_node_address()
  18. } ;
  19.  
  20.  
  21. class net_socket
  22. {
  23.   public :
  24.   enum socket_type { SOCKET_SECURE, SOCKET_FAST } ;
  25.  
  26.   virtual int error()                                              = 0;
  27.   virtual int ready_to_read()                                      = 0;
  28.   virtual int ready_to_write()                                     = 0;
  29.   virtual int write(void *buf, int size, net_address *addr=0)   = 0;
  30.   virtual int read(void *buf, int size, net_address **addr=0)      = 0;
  31.   virtual int get_fd()                                             = 0;
  32.   virtual ~net_socket()              { ; }
  33.   virtual void read_selectable()     { ; }
  34.   virtual void read_unselectable()   { ; }
  35.   virtual void write_selectable()    { ; }
  36.   virtual void write_unselectable()  { ; }
  37.   virtual int listen(int port)       { return 0; }
  38.   virtual net_socket *accept(net_address *&from) { from=0; return 0; }
  39. } ;
  40.  
  41. class net_protocol
  42. {
  43. public :
  44.   enum debug_type
  45.     { DB_OFF,                // no debug printing
  46.       DB_MAJOR_EVENT,        // print major events
  47.       DB_IMPORTANT_EVENT,    // anything that would tell where a lockup occures
  48.       DB_MINOR_EVENT } ;     // anything you can think off
  49.  
  50. private :
  51.   debug_type debug_setting;
  52. public :
  53.  
  54.   enum connect_flags
  55.   { READ_WRITE,          // flags for connect to server
  56.          WRITE_ONLY } ;
  57.  
  58.  
  59.   int debug_level(debug_type min_level) { return min_level<=debug_setting; }
  60.   void set_debug_printing(debug_type level) { debug_setting=level; }
  61.  
  62.   static net_protocol *first;
  63.   net_protocol *next;
  64.  
  65.   virtual net_address *get_local_address() = 0;
  66.   virtual net_address *get_node_address(char *&server_name, int def_port, int force_port) = 0;
  67.   virtual net_socket *connect_to_server(net_address *addr, 
  68.                     net_socket::socket_type sock_type=net_socket::SOCKET_SECURE) =0;
  69.   virtual net_socket *create_listen_socket(int port, net_socket::socket_type sock_type) = 0;
  70.   virtual int installed() = 0;
  71.   virtual char *name() = 0;
  72.   virtual int select(int block) = 0;          // return # of sockets available for read & writing
  73.   virtual void cleanup() { ; }                // should do any needed pre-exit cleanup stuff
  74.   net_socket *connect_to_server(char *&server_name, int port, int force_port=0, 
  75.                 net_socket::socket_type sock_type=net_socket::SOCKET_SECURE); 
  76.  
  77.     // Notification methods
  78.     virtual net_socket *start_notify(int port, void *data, int len) { return 0; }
  79.     virtual void end_notify() {}
  80.     // for protocols that don't know how to find address without help, start_notify creates
  81.     //   a fast/connectionless socket to respond to find address request packets.  After start_notify,
  82.     //   protocol::select should automatically forward the specified data to all requesters.
  83.     //   find_address should "broadcast" a notification request packet to all addresses it can
  84.     //   and wait for any responses 
  85.  
  86.     // Find methods
  87.   virtual net_address *find_address(int port, char *name) { return 0; }   // name should be a 256 byte buffer
  88.   virtual void reset_find_list() { ; }
  89.  
  90.   net_protocol() { next=first; first=this; debug_setting=DB_OFF; }
  91.   virtual ~net_protocol() { cleanup(); }
  92. } ;
  93.  
  94. #endif
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.