Annotation of embedaddon/mpd/src/contrib/libpdel/http/http_internal.h, revision 1.1.1.2
1.1 misho 1:
2: /*
3: * Copyright (c) 2001-2002 Packet Design, LLC.
4: * All rights reserved.
5: *
6: * Subject to the following obligations and disclaimer of warranty,
7: * use and redistribution of this software, in source or object code
8: * forms, with or without modifications are expressly permitted by
9: * Packet Design; provided, however, that:
10: *
11: * (i) Any and all reproductions of the source or object code
12: * must include the copyright notice above and the following
13: * disclaimer of warranties; and
14: * (ii) No rights are granted, in any manner or form, to use
15: * Packet Design trademarks, including the mark "PACKET DESIGN"
16: * on advertising, endorsements, or otherwise except as such
17: * appears in the above copyright notice or in the software.
18: *
19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
36: * THE POSSIBILITY OF SUCH DAMAGE.
37: *
38: * Author: Archie Cobbs <archie@freebsd.org>
39: */
40:
41: #ifndef _PDEL_HTTP_HTTP_INTERNAL_H_
42: #define _PDEL_HTTP_HTTP_INTERNAL_H_
43:
44: #include "debug/debug.h"
45:
46: #ifndef __FreeBSD__
47: #define __printflike(x,y)
48: #endif
49:
50: /* HTTP connection */
51: struct http_connection {
52: void *owner; /* owner (server or client) */
53: struct http_request *req; /* request structure */
54: struct http_response *resp; /* response structure */
55: struct in_addr local_ip; /* local host ip */
56: u_int16_t local_port; /* local host port */
57: struct in_addr remote_ip; /* remote host ip */
58: u_int16_t remote_port; /* remote host port */
59: FILE *fp; /* connection to peer */
60: pthread_t tid; /* connection thread id */
61: u_char keep_alive; /* connection keep-alive */
62: u_char server; /* we are server (not client) */
63: u_char proxy; /* proxy request/response */
64: u_char started; /* conn. thread has started */
65: LIST_ENTRY(http_connection) next; /* next in connection list */
66: http_logger_t *logger; /* error logging routine */
67: SSL_CTX *ssl; /* ssl context, if doing ssl */
68: int sock; /* socket cached */
69: };
70:
71: /* HTTP request name, value pair */
72: struct http_nvp {
73: char *name;
74: char *value;
75: };
76:
1.1.1.2 ! misho 77: struct const_http_nvp {
! 78: const char *name;
! 79: char *value;
! 80: };
! 81:
1.1 misho 82: /* HTTP request/response common info */
83: struct http_message {
84: struct http_connection *conn; /* associated connection */
85: struct http_head *head; /* headers */
86: char *host; /* decoded url host */
87: char *path; /* decoded url pathname */
88: char *query; /* encoded query string */
89: FILE *input; /* entity input stream */
90: u_int input_len; /* input length, or UINT_MAX */
91: u_int input_read; /* input length read so far */
92: FILE *output; /* entity output stream */
93: u_char *output_buf; /* buffered output, if any */
94: int output_len; /* buffered output length */
95: u_char buffered; /* output is buffered */
96: u_char no_headers; /* don't send any headers */
97: u_char hdrs_sent; /* header was sent */
98: u_char no_body; /* no entity data is allowed */
99: u_char skip_body; /* no entity data to be sent */
100: };
101:
102: /* HTTP request */
103: struct http_request {
104: struct http_message *msg; /* common req/reply info */
105: int num_nvp; /* number of n-v pairs */
106: struct http_nvp *nvp; /* name, value pairs */
107: char *username; /* authorization username */
108: char *password; /* authorization password */
109: };
110:
111: /* HTTP response */
112: struct http_response {
113: struct http_message *msg; /* common req/reply info */
114: u_int code; /* http response code */
115: };
116:
117: __BEGIN_DECLS
118:
119: /*
120: * http_head methods
121: */
122: extern struct http_head *_http_head_new(void);
123: extern int _http_head_read(struct http_head *head, FILE *fp, int req);
124: extern int _http_head_read_headers(struct http_head *head, FILE *fp);
125: extern int _http_head_write(struct http_head *head, FILE *fp);
126: extern struct http_head *_http_head_copy(struct http_head *head);
127: extern void _http_head_reset(struct http_head *head);
128: extern void _http_head_free(struct http_head **headp);
129: extern const char *_http_head_get(struct http_head *head, const char *name);
130: extern int _http_head_get_headers(struct http_head *head,
131: const char **names, size_t max_names);
132: extern int _http_head_set(struct http_head *head, int append,
133: const char *name, const char *valfmt, ...)
134: __printflike(4, 5);
135: extern int _http_head_vset(struct http_head *head, int append,
1.1.1.2 ! misho 136: const char *name, const char *valfmt, va_list args)
! 137: __printflike(4, 0);
1.1 misho 138: extern int _http_head_num_headers(struct http_head *head);
139: extern int _http_head_get_by_index(struct http_head *head, u_int index,
140: const char **namep, const char **valuep);
141: extern int _http_head_remove(struct http_head *head, const char *name);
142: extern int _http_head_err_response(struct http_head **headp, int code);
143: extern int _http_head_has_anything(struct http_head *head);
144: extern int _http_head_want_keepalive(struct http_head *head);
145:
146: /*
147: * http_request methods
148: */
149: extern int _http_request_new(struct http_connection *conn);
150: extern int _http_request_read(struct http_connection *conn);
151: extern void _http_request_free(struct http_request **reqp);
152:
153: /*
154: * http_response methods
155: */
156: extern int _http_response_new(struct http_connection *conn);
157: extern int _http_response_read(struct http_connection *conn,
158: char *errbuf, int size);
159: extern void _http_response_free(struct http_response **respp);
160:
161: /*
162: * http_message methods
163: */
164: extern struct http_message *_http_message_new(void);
165: extern void _http_message_free(struct http_message **msgp);
166: extern int _http_message_read(struct http_message *msg, int req);
167: extern FILE *_http_message_get_output(struct http_message *msg, int buffer);
168: extern struct in_addr _http_message_get_remote_ip(struct http_message *msg);
169: extern u_int16_t _http_message_get_remote_port(struct http_message *msg);
170: extern int _http_message_has_anything(struct http_message *msg);
171: extern void _http_message_send_headers(struct http_message *msg,
172: int unbuffer);
173: extern void _http_message_send_body(struct http_message *msg);
174: extern int _http_message_vset_header(struct http_message *msg, int append,
1.1.1.2 ! misho 175: const char *name, const char *valfmt, va_list args)
! 176: __printflike(4, 0);
1.1 misho 177: extern int _http_message_remove_header(struct http_message *msg,
178: const char *name);
179: extern const char *_http_message_connection_header(struct http_message *msg);
180: extern int _http_message_get_raw_socket(struct http_message *msg);
181:
182: /*
183: * http_connection methods
184: */
185: extern struct http_connection *_http_connection_create(FILE *fp, int sock,
186: int server, struct in_addr ip, u_int16_t port,
187: SSL_CTX *ssl, http_logger_t *logger, u_int timeout);
188: extern void _http_connection_free(struct http_connection **connp);
189:
190: /*
191: * Client connection caching functions
192: */
193: extern struct http_connection_cache *_http_connection_cache_create(
194: struct pevent_ctx *ctx, u_int max_num, u_int max_idle);
195: extern void _http_connection_cache_destroy(
196: struct http_connection_cache **cachep);
197: extern int _http_connection_cache_get(struct http_connection_cache *cache,
198: const struct sockaddr_in *peer, const SSL_CTX *ssl,
199: FILE **fpp, int *sockp);
200: extern int _http_connection_cache_put(struct http_connection_cache *cache,
201: const struct sockaddr_in *peer, const SSL_CTX *ssl,
202: FILE *fp, int sock);
203:
204: /*
205: * Misc
206: */
207: extern void _http_ssl_init(void);
208:
209: __END_DECLS
210:
211: #endif /* _PDEL_HTTP_HTTP_INTERNAL_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>