build: commit all the waf build files in the tree
[nivanova/samba-autobuild/.git] / source4 / lib / socket / socket.h
index fefa999e08195a0d9e6678db089724cde8ec8248..4a744797b3ab53b48e65b51f99cea2c7008fe3c3 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef _SAMBA_SOCKET_H
 #define _SAMBA_SOCKET_H
 
-#include "lib/events/events.h"
-
+struct tevent_context;
+struct tevent_fd;
 struct socket_context;
 
 enum socket_type {
@@ -102,6 +101,15 @@ enum socket_state {
 #define SOCKET_FLAG_BLOCK        0x00000001
 #define SOCKET_FLAG_PEEK         0x00000002
 #define SOCKET_FLAG_TESTNONBLOCK 0x00000004
+#define SOCKET_FLAG_ENCRYPT      0x00000008 /* This socket
+                                            * implementation requires
+                                            * that re-sends be
+                                            * consistant, because it
+                                            * is encrypting data.
+                                            * This modifies the
+                                            * TESTNONBLOCK case */
+#define SOCKET_FLAG_NOCLOSE      0x00000010 /* don't auto-close on free */
+
 
 struct socket_context {
        enum socket_type type;
@@ -113,8 +121,13 @@ struct socket_context {
        void *private_data;
        const struct socket_ops *ops;
        const char *backend_name;
+
+       /* specific to the ip backend */
+       int family;
 };
 
+struct resolve_context;
+struct tsocket_address;
 
 /* prototypes */
 NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
@@ -146,6 +159,12 @@ NTSTATUS socket_set_option(struct socket_context *sock, const char *option, cons
 char *socket_get_peer_name(struct socket_context *sock, TALLOC_CTX *mem_ctx);
 struct socket_address *socket_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
 struct socket_address *socket_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *mem_ctx,
+                                                         const struct socket_address *a);
+struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *mem_ctx,
+                                                        const struct tsocket_address *a);
+struct tsocket_address *socket_get_remote_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_get_local_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
 int socket_get_fd(struct socket_context *sock);
 NTSTATUS socket_dup(struct socket_context *sock);
 struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
@@ -155,11 +174,15 @@ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
 struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx, 
                                                    struct sockaddr *sockaddr, 
                                                    size_t addrlen);
+_PUBLIC_ void socket_address_set_port(struct socket_address *a,
+                                     uint16_t port);
+struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
+                                          const struct socket_address *oaddr);
 const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type);
-BOOL allow_access(TALLOC_CTX *mem_ctx,
+bool allow_access(TALLOC_CTX *mem_ctx,
                  const char **deny_list, const char **allow_list,
                  const char *cname, const char *caddr);
-BOOL socket_check_access(struct socket_context *sock, 
+bool socket_check_access(struct socket_context *sock, 
                         const char *service_name,
                         const char **allow_list, const char **deny_list);
 
@@ -167,27 +190,38 @@ struct composite_context *socket_connect_send(struct socket_context *sock,
                                              struct socket_address *my_address,
                                              struct socket_address *server_address, 
                                              uint32_t flags,
-                                             struct event_context *event_ctx);
+                                             struct tevent_context *event_ctx);
 NTSTATUS socket_connect_recv(struct composite_context *ctx);
 NTSTATUS socket_connect_ev(struct socket_context *sock,
                           struct socket_address *my_address,
                           struct socket_address *server_address, 
-                          uint32_t flags, struct event_context *ev);
+                          uint32_t flags, 
+                          struct tevent_context *ev);
 
 struct composite_context *socket_connect_multi_send(TALLOC_CTX *mem_ctx,
                                                    const char *server_address,
                                                    int num_server_ports,
                                                    uint16_t *server_ports,
-                                                   struct event_context *event_ctx);
+                                                   struct resolve_context *resolve_ctx,
+                                                   struct tevent_context *event_ctx);
 NTSTATUS socket_connect_multi_recv(struct composite_context *ctx,
                                   TALLOC_CTX *mem_ctx,
                                   struct socket_context **result,
                                   uint16_t *port);
 NTSTATUS socket_connect_multi(TALLOC_CTX *mem_ctx, const char *server_address,
                              int num_server_ports, uint16_t *server_ports,
-                             struct event_context *event_ctx,
+                             struct resolve_context *resolve_ctx,
+                             struct tevent_context *event_ctx,
                              struct socket_context **result,
                              uint16_t *port);
 void set_socket_options(int fd, const char *options);
+void socket_set_flags(struct socket_context *sock, unsigned flags);
+
+void socket_tevent_fd_close_fn(struct tevent_context *ev,
+                              struct tevent_fd *fde,
+                              int fd,
+                              void *private_data);
+
+extern bool testnonblock;
 
 #endif /* _SAMBA_SOCKET_H */