Return to http_internal.h CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / contrib / libpdel / http |
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: 77: /* HTTP request/response common info */ 78: struct http_message { 79: struct http_connection *conn; /* associated connection */ 80: struct http_head *head; /* headers */ 81: char *host; /* decoded url host */ 82: char *path; /* decoded url pathname */ 83: char *query; /* encoded query string */ 84: FILE *input; /* entity input stream */ 85: u_int input_len; /* input length, or UINT_MAX */ 86: u_int input_read; /* input length read so far */ 87: FILE *output; /* entity output stream */ 88: u_char *output_buf; /* buffered output, if any */ 89: int output_len; /* buffered output length */ 90: u_char buffered; /* output is buffered */ 91: u_char no_headers; /* don't send any headers */ 92: u_char hdrs_sent; /* header was sent */ 93: u_char no_body; /* no entity data is allowed */ 94: u_char skip_body; /* no entity data to be sent */ 95: }; 96: 97: /* HTTP request */ 98: struct http_request { 99: struct http_message *msg; /* common req/reply info */ 100: int num_nvp; /* number of n-v pairs */ 101: struct http_nvp *nvp; /* name, value pairs */ 102: char *username; /* authorization username */ 103: char *password; /* authorization password */ 104: }; 105: 106: /* HTTP response */ 107: struct http_response { 108: struct http_message *msg; /* common req/reply info */ 109: u_int code; /* http response code */ 110: }; 111: 112: __BEGIN_DECLS 113: 114: /* 115: * http_head methods 116: */ 117: extern struct http_head *_http_head_new(void); 118: extern int _http_head_read(struct http_head *head, FILE *fp, int req); 119: extern int _http_head_read_headers(struct http_head *head, FILE *fp); 120: extern int _http_head_write(struct http_head *head, FILE *fp); 121: extern struct http_head *_http_head_copy(struct http_head *head); 122: extern void _http_head_reset(struct http_head *head); 123: extern void _http_head_free(struct http_head **headp); 124: extern const char *_http_head_get(struct http_head *head, const char *name); 125: extern int _http_head_get_headers(struct http_head *head, 126: const char **names, size_t max_names); 127: extern int _http_head_set(struct http_head *head, int append, 128: const char *name, const char *valfmt, ...) 129: __printflike(4, 5); 130: extern int _http_head_vset(struct http_head *head, int append, 131: const char *name, const char *valfmt, va_list args); 132: extern int _http_head_num_headers(struct http_head *head); 133: extern int _http_head_get_by_index(struct http_head *head, u_int index, 134: const char **namep, const char **valuep); 135: extern int _http_head_remove(struct http_head *head, const char *name); 136: extern int _http_head_err_response(struct http_head **headp, int code); 137: extern int _http_head_has_anything(struct http_head *head); 138: extern int _http_head_want_keepalive(struct http_head *head); 139: 140: /* 141: * http_request methods 142: */ 143: extern int _http_request_new(struct http_connection *conn); 144: extern int _http_request_read(struct http_connection *conn); 145: extern void _http_request_free(struct http_request **reqp); 146: 147: /* 148: * http_response methods 149: */ 150: extern int _http_response_new(struct http_connection *conn); 151: extern int _http_response_read(struct http_connection *conn, 152: char *errbuf, int size); 153: extern void _http_response_free(struct http_response **respp); 154: 155: /* 156: * http_message methods 157: */ 158: extern struct http_message *_http_message_new(void); 159: extern void _http_message_free(struct http_message **msgp); 160: extern int _http_message_read(struct http_message *msg, int req); 161: extern FILE *_http_message_get_output(struct http_message *msg, int buffer); 162: extern struct in_addr _http_message_get_remote_ip(struct http_message *msg); 163: extern u_int16_t _http_message_get_remote_port(struct http_message *msg); 164: extern int _http_message_has_anything(struct http_message *msg); 165: extern void _http_message_send_headers(struct http_message *msg, 166: int unbuffer); 167: extern void _http_message_send_body(struct http_message *msg); 168: extern int _http_message_vset_header(struct http_message *msg, int append, 169: const char *name, const char *valfmt, va_list args); 170: extern int _http_message_remove_header(struct http_message *msg, 171: const char *name); 172: extern const char *_http_message_connection_header(struct http_message *msg); 173: extern int _http_message_get_raw_socket(struct http_message *msg); 174: 175: /* 176: * http_connection methods 177: */ 178: extern struct http_connection *_http_connection_create(FILE *fp, int sock, 179: int server, struct in_addr ip, u_int16_t port, 180: SSL_CTX *ssl, http_logger_t *logger, u_int timeout); 181: extern void _http_connection_free(struct http_connection **connp); 182: 183: /* 184: * Client connection caching functions 185: */ 186: extern struct http_connection_cache *_http_connection_cache_create( 187: struct pevent_ctx *ctx, u_int max_num, u_int max_idle); 188: extern void _http_connection_cache_destroy( 189: struct http_connection_cache **cachep); 190: extern int _http_connection_cache_get(struct http_connection_cache *cache, 191: const struct sockaddr_in *peer, const SSL_CTX *ssl, 192: FILE **fpp, int *sockp); 193: extern int _http_connection_cache_put(struct http_connection_cache *cache, 194: const struct sockaddr_in *peer, const SSL_CTX *ssl, 195: FILE *fp, int sock); 196: 197: /* 198: * Misc 199: */ 200: extern void _http_ssl_init(void); 201: 202: __END_DECLS 203: 204: #endif /* _PDEL_HTTP_HTTP_INTERNAL_H_ */