new method to get the server's listening socket.
[platform/upstream/libsoup.git] / libsoup / soup-socket.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2000-2003, Ximian, Inc.
4  */
5
6 #ifndef SOUP_SOCKET_H
7 #define SOUP_SOCKET_H 1
8
9 #include <libsoup/soup-types.h>
10
11 #define SOUP_TYPE_SOCKET            (soup_socket_get_type ())
12 #define SOUP_SOCKET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOCKET, SoupSocket))
13 #define SOUP_SOCKET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOCKET, SoupSocketClass))
14 #define SOUP_IS_SOCKET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOCKET))
15 #define SOUP_IS_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_SOCKET))
16 #define SOUP_SOCKET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOCKET, SoupSocketClass))
17
18 struct SoupSocket {
19         GObject parent;
20
21 };
22
23 typedef struct {
24         GObjectClass parent_class;
25
26         /* signals */
27         void (*connect_result) (SoupSocket *, guint);
28         void (*readable)       (SoupSocket *);
29         void (*writable)       (SoupSocket *);
30         void (*disconnected)   (SoupSocket *);
31
32         void (*new_connection) (SoupSocket *, SoupSocket *);
33 } SoupSocketClass;
34
35 #define SOUP_SOCKET_FLAG_NONBLOCKING "non-blocking"
36 #define SOUP_SOCKET_FLAG_NODELAY     "nodelay"
37 #define SOUP_SOCKET_FLAG_REUSEADDR   "reuseaddr"
38 #define SOUP_SOCKET_FLAG_CLOEXEC     "cloexec"
39 #define SOUP_SOCKET_IS_SERVER        "is-server"
40 #define SOUP_SOCKET_SSL_CREDENTIALS  "ssl-creds"
41
42 /**
43  * SoupSocketCallback:
44  * @sock: the #SoupSocket
45  * @status: an HTTP status code indicating success or failure
46  * @user_data: the data passed to soup_socket_client_new_async()
47  *
48  * The callback function passed to soup_socket_client_new_async().
49  **/
50 typedef void (*SoupSocketCallback)            (SoupSocket         *sock,
51                                                guint               status,
52                                                gpointer            user_data);
53
54 /**
55  * SoupSocketListenerCallback:
56  * @listener: the listening #SoupSocket
57  * @sock: the newly-received #SoupSocket
58  * @user_data: the data passed to soup_socket_server_new().
59  *
60  * The callback function passed to soup_socket_server_new(), which
61  * receives new connections.
62  **/
63 typedef void (*SoupSocketListenerCallback)    (SoupSocket         *listener,
64                                                SoupSocket         *sock,
65                                                gpointer            user_data);
66
67 GType soup_socket_get_type (void);
68
69 SoupSocket    *soup_socket_new                (const char         *optname1,
70                                                ...);
71
72 guint          soup_socket_connect            (SoupSocket         *sock,
73                                                SoupAddress        *remote_addr);
74 gboolean       soup_socket_listen             (SoupSocket         *sock,
75                                                SoupAddress        *local_addr);
76 gboolean       soup_socket_start_ssl          (SoupSocket         *sock);
77 gboolean       soup_socket_start_proxy_ssl    (SoupSocket         *sock,
78                                                const char         *ssl_host);
79
80 void           soup_socket_disconnect         (SoupSocket         *sock);
81 gboolean       soup_socket_is_connected       (SoupSocket         *sock);
82
83 SoupSocket    *soup_socket_client_new_async   (const char         *hostname,
84                                                guint               port,
85                                                gpointer            ssl_creds,
86                                                SoupSocketCallback  callback,
87                                                gpointer            user_data);
88 SoupSocket    *soup_socket_client_new_sync    (const char         *hostname,
89                                                guint               port,
90                                                gpointer            ssl_creds,
91                                                guint              *status_ret);
92 SoupSocket    *soup_socket_server_new         (SoupAddress        *local_addr,
93                                                gpointer            ssl_creds,
94                                                SoupSocketListenerCallback callback,
95                                                gpointer            user_data);
96
97 SoupAddress   *soup_socket_get_local_address  (SoupSocket         *sock);
98 SoupAddress   *soup_socket_get_remote_address (SoupSocket         *sock);
99
100
101 /**
102  * SoupSocketIOStatus:
103  * @SOUP_SOCKET_OK: Success
104  * @SOUP_SOCKET_WOULD_BLOCK: Cannot read/write any more at this time
105  * @SOUP_SOCKET_EOF: End of file
106  * @SOUP_SOCKET_ERROR: Other error
107  *
108  * Return value from the #SoupSocket IO methods.
109  **/
110 typedef enum {
111         SOUP_SOCKET_OK,
112         SOUP_SOCKET_WOULD_BLOCK,
113         SOUP_SOCKET_EOF,
114         SOUP_SOCKET_ERROR
115 } SoupSocketIOStatus;
116
117 SoupSocketIOStatus  soup_socket_read       (SoupSocket         *sock,
118                                             gpointer            buffer,
119                                             gsize               len,
120                                             gsize              *nread);
121 SoupSocketIOStatus  soup_socket_read_until (SoupSocket         *sock,
122                                             gpointer            buffer,
123                                             gsize               len,
124                                             gconstpointer       boundary,
125                                             gsize               boundary_len,
126                                             gsize              *nread,
127                                             gboolean           *got_boundary);
128
129 SoupSocketIOStatus  soup_socket_write      (SoupSocket         *sock,
130                                             gconstpointer       buffer,
131                                             gsize               len,
132                                             gsize              *nwrote);
133
134
135 #endif /* SOUP_SOCKET_H */