1/*
2   HTTP Request Handling
3   Copyright (C) 1999-2009, Joe Orton <joe@manyfish.co.uk>
4
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Library General Public
7   License as published by the Free Software Foundation; either
8   version 2 of the License, or (at your option) any later version.
9
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Library General Public License for more details.
14
15   You should have received a copy of the GNU Library General Public
16   License along with this library; if not, write to the Free
17   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18   MA 02111-1307, USA
19
20*/
21
22/* THIS IS NOT A PUBLIC INTERFACE. You CANNOT include this header file
23 * from an application.  */
24
25#ifndef NE_PRIVATE_H
26#define NE_PRIVATE_H
27
28#include "ne_request.h"
29#include "ne_socket.h"
30#include "ne_ssl.h"
31
32struct host_info {
33    /* Type of host represented: */
34    enum proxy_type {
35        PROXY_NONE = 0,
36        PROXY_HTTP, /* an HTTP proxy */
37        PROXY_SOCKS /* a SOCKS proxy */
38    } proxy;
39    unsigned int port;
40    /* If hostname is non-NULL, host is identified by this hostname. */
41    char *hostname, *hostport;
42    /* If address is non-NULL, the result of resolving ->hostname. */
43    ne_sock_addr *address;
44    /* If current non-NULL, current network address used in ->address. */
45    const ne_inet_addr *current;
46    /* If override is non-NULL, the host is identified by this network
47     * address. */
48    const ne_inet_addr *network;
49    struct host_info *next;
50};
51
52/* Store every registered callback in a generic container, and cast
53 * the function pointer when calling it.  */
54struct hook {
55    void (*fn)(void);
56    void *userdata;
57    const char *id; /* non-NULL for accessors. */
58    struct hook *next;
59};
60
61#define HAVE_HOOK(st,func) (st->hook->hooks->func != NULL)
62#define HOOK_FUNC(st, func) (*st->hook->hooks->func)
63
64/* Session support. */
65struct ne_session_s {
66    /* Connection information */
67    ne_socket *socket;
68
69    /* non-zero if connection has been established. */
70    int connected;
71
72    /* non-zero if connection has persisted beyond one request. */
73    int persisted;
74
75    int is_http11; /* >0 if connected server is known to be
76		    * HTTP/1.1 compliant. */
77
78    char *scheme;
79
80    /* Server host details. */
81    struct host_info server;
82    /* Proxy host details, or NULL if not using a proxy. */
83    struct host_info *proxies;
84    /* Most recently used proxy server. */
85    struct host_info *prev_proxy;
86
87    /* Pointer to the active .server or .proxies as appropriate: */
88    struct host_info *nexthop;
89
90    /* Local address to which sockets should be bound. */
91    const ne_inet_addr *local_addr;
92
93    /* Settings */
94    int use_ssl; /* whether a secure connection is required */
95    int in_connect; /* doing a proxy CONNECT */
96    int any_proxy_http; /* whether any configured proxy is an HTTP proxy */
97
98    enum ne_sock_sversion socks_ver;
99    char *socks_user, *socks_password;
100
101    int flags[NE_SESSFLAG_LAST];
102
103    ne_progress progress_cb;
104    void *progress_ud;
105
106    ne_notify_status notify_cb;
107    void *notify_ud;
108
109    int rdtimeout, cotimeout; /* read, connect timeouts. */
110
111    struct hook *create_req_hooks, *pre_send_hooks, *post_send_hooks,
112        *post_headers_hooks, *destroy_req_hooks, *destroy_sess_hooks,
113        *close_conn_hooks, *private;
114
115    char *user_agent; /* full User-Agent: header field */
116
117#ifdef NE_HAVE_SSL
118    ne_ssl_client_cert *client_cert;
119    ne_ssl_certificate *server_cert;
120    ne_ssl_context *ssl_context;
121    int ssl_cc_requested; /* set to non-zero if a client cert was
122                           * requested during initial handshake, but
123                           * none could be provided. */
124#endif
125
126    /* Server cert verification callback: */
127    ne_ssl_verify_fn ssl_verify_fn;
128    void *ssl_verify_ud;
129    /* Client cert provider callback: */
130    ne_ssl_provide_fn ssl_provide_fn;
131    void *ssl_provide_ud;
132
133    ne_session_status_info status;
134
135    /* Error string */
136    char error[512];
137};
138
139/* Pushes block of 'count' bytes at 'buf'. Returns non-zero on
140 * error. */
141typedef int (*ne_push_fn)(void *userdata, const char *buf, size_t count);
142
143/* Do the SSL negotiation. */
144NE_PRIVATE int ne__negotiate_ssl(ne_session *sess);
145
146/* Set the session error appropriate for SSL verification failures. */
147NE_PRIVATE void ne__ssl_set_verify_err(ne_session *sess, int failures);
148
149/* Return non-zero if hostname from certificate (cn) matches hostname
150 * used for session (hostname); follows RFC2818 logic. */
151NE_PRIVATE int ne__ssl_match_hostname(const char *cn, size_t cnlen,
152                                      const char *hostname);
153
154#endif /* HTTP_PRIVATE_H */
155