Debianization. Socket target options. Internet binding.
[fwd] / addr.h
diff --git a/addr.h b/addr.h
index cc5b790..adc4cd1 100644 (file)
--- a/addr.h
+++ b/addr.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: addr.h,v 1.2 1999/07/27 18:30:53 mdw Exp $
+ * $Id: addr.h,v 1.3 2003/11/25 14:08:23 mdw Exp $
  *
  * Generic interface to network address handlers
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: addr.h,v $
+ * Revision 1.3  2003/11/25 14:08:23  mdw
+ * Debianization.  Socket target options.  Internet binding.
+ *
  * Revision 1.2  1999/07/27 18:30:53  mdw
  * Various minor portability fixes.
  *
 #include <sys/socket.h>
 
 #include <mLib/dstr.h>
+#include <mLib/conn.h>
 
 #ifndef REFFD_H
 #  include "reffd.h"
 #endif
 
+#ifndef ENDPT_H
+#  include "endpt.h"
+#endif
+
 #ifndef SCAN_H
 #  include "scan.h"
 #endif
@@ -73,11 +81,6 @@ typedef struct addr {
   size_t sz;
 } addr;
 
-typedef struct gen_addr {
-  addr a;
-  struct sockaddr sa;
-} gen_addr;
-
 #define ADDRSZ(sz) (sizeof(addr) + (sz))
 
 /* --- Address configuration --- *
@@ -99,14 +102,14 @@ typedef struct addr_opts {
 
 enum {
   ADDR_SRC,
-  ADDR_DEST
+  ADDR_DEST,
+  ADDR_GLOBAL
 };
 
 /* --- Description of an address type handler --- */
 
 typedef struct addr_ops {
   const char *name;                    /* Protocol's internal name */
-  int pf;                              /* Protocol family number */
 
   /* --- @read@ --- *
    *
@@ -145,7 +148,7 @@ typedef struct addr_ops {
 
   void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/);
 
-  /* --- @initopts@ --- *
+  /* --- @initsrcopts@ --- *
    *
    * Arguments:        ---
    *
@@ -156,19 +159,57 @@ typedef struct addr_ops {
    *           are added to the block when necessary.
    */
 
-  addr_opts *(*initopts)(void);
+  addr_opts *(*initsrcopts)(void);
 
   /* --- @option@ --- *
    *
    * Arguments:        @scanner *sc@ = pointer to a scanner to read from
+   *           @unsigned type@ = kind of option this is
    *           @addr_opts *ao@ = data block to modify (from @init@), or null
    *
    * Returns:  Nonzero to claim the option.
    *
-   * Use:      Parses an option, either global or listener-specific.
+   * Use:      Parses a source option, either global or listener-specific.
+   */
+
+  int (*option)(scanner */*sc*/, addr_opts */*ao*/, unsigned /*type*/);
+
+  /* --- @freesrcopts@ --- *
+   *
+   * Arguments:        @addr_opts *ao@ = data block to remove
+   *
+   * Returns:  ---
+   *
+   * Use:      Throws away all the configuration data for an address type.
+   */
+
+  void (*freesrcopts)(addr_opts */*ao*/);
+
+  /* --- @bind@ --- *
+   *
+   * Arguments:        @addr *a@ = the address to bind to
+   *           @addr_opts *ao@ = the address options
+   *
+   * Returns:  File descriptor of bound socket if OK, or @-1@ on error.
+   *
+   * Use:      Binds a listening socket.  The tedious stuff with @listen@
+   *           isn't necessary.
+   */
+
+  int (*bind)(addr */*a*/, addr_opts */*ao*/);
+
+  /* --- @unbind@ --- *
+   *
+   * Arguments:        @addr *a@ = pointer to an address
+   *
+   * Returns:  ---
+   *
+   * Use:      Unbinds an address.  This is used when tidying up.  The main
+   *           purpose is to let the Unix-domain handler remove its socket
+   *           node from the filesystem.
    */
 
-  int (*option)(scanner */*sc*/, addr_opts */*ao*/);
+  void (*unbind)(addr */*a*/);
 
   /* --- @accept@ --- *
    *
@@ -183,42 +224,52 @@ typedef struct addr_ops {
 
   reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
 
-  /* --- @freeopts@ --- *
+  /* --- @inittargopts@ --- *
    *
-   * Arguments:        @addr_opts *ao@ = data block to remove
+   * Arguments:        ---
    *
-   * Returns:  ---
+   * Returns:  A pointer to a protocol-specific data block for a connecter
    *
-   * Use:      Throws away all the configuration data for an address type.
+   * Use:      Creates a data block for a target.  This is attached to the
+   *           target data structure.  Options can then be requested, and
+   *           are added to the block when necessary.
    */
 
-  void (*freeopts)(addr_opts */*ao*/);
+  addr_opts *(*inittargopts)(void);
 
-  /* --- @bound@ --- *
+  /* --- @freetargopts@ --- *
    *
-   * Arguments:        @addr *a@ = pointer to an address
-   *           @addr_opts *ao@ = pointer to attributes block
+   * Arguments:        @addr_opts *ao@ = data block to remove
    *
    * Returns:  ---
    *
-   * Use:      Reports that a file descriptor has been (successfully) bound
-   *           to an address.
+   * Use:      Throws away all the configuration data for an address type.
    */
 
-  void (*bound)(addr */*a*/, addr_opts */*ao*/);
+  void (*freetargopts)(addr_opts */*ao*/);
 
-  /* --- @unbind@ --- *
+  /* --- @connect@ --- *
    *
-   * Arguments:        @addr *a@ = pointer to an address
+   * Arguments:        @addr *a@ = destination address
+   *           @addr_opts *ao@ = target address options
+   *           @conn *c@ = connection structure
+   *           @endpt *e@ = endpoint structure
    *
-   * Returns:  ---
+   * Returns:  Zero if OK, @-1@ on some error.
    *
-   * Use:      Unbinds an address.  This is used when tidying up.  The main
-   *           purpose is to let the Unix-domain handler remove its socket
-   *           node from the filesystem.
+   * Use:      Requests that a connection be made, or at least set in
+   *           motion.  An address may do one of these things:
+   *
+   *             * Return @-1@.
+   *
+   *             * Call @starget_connected@ with @-1@ or a connected file
+   *               descriptor and the pointer @e@.
+   *
+   *             * Call @conn_init@ or @conn_fd@, giving @starget_connected@
+   *               and @e@ as the function to call.
    */
 
-  void (*unbind)(addr */*a*/);
+  int (*connect)(addr */*a*/, addr_opts */*ao*/, conn */*c*/, endpt */*e*/);
 
 } addr_ops;