1 /* -*- linux-c -*- 2 Copyright (C) 2007 Tom Szilagyi 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 $Id: httpc.h 1237 2012-02-04 10:30:17Z assworth $ 19 */ 20 21 #ifndef AQUALUNG_HTTPC_H 22 #define AQUALUNG_HTTPC_H 23 24 #include "decoder/file_decoder.h" 25 #include "metadata.h" 26 27 28 #define HTTPC_OK 0 29 #define HTTPC_URL_ERROR -1 30 #define HTTPC_CONNECTION_ERROR -2 31 #define HTTPC_HEADER_ERROR -3 32 #define HTTPC_REDIRECT_ERROR -4 33 34 #define HTTPC_SESSION_NORMAL 1 35 #define HTTPC_SESSION_CHUNKED 2 36 #define HTTPC_SESSION_STREAM 3 37 38 typedef struct { 39 char * status; 40 char * location; 41 int content_length; 42 char * content_type; 43 char * transfer_encoding; 44 int icy_metaint; 45 int icy_br; 46 char * icy_genre; 47 char * icy_name; 48 char * icy_description; 49 } http_header_t; 50 51 typedef struct { 52 /* original session parameters */ 53 char * URL; 54 int use_proxy; 55 char * proxy; 56 int proxy_port; 57 char * noproxy_domains; 58 59 int sock; 60 int is_active; 61 http_header_t headers; 62 63 int type; /* one of HTTPC_SESSION_* */ 64 65 /* variables for normal download: */ 66 long long byte_pos; 67 68 /* variables for chunked download: */ 69 char * chunk_buf; 70 int chunk_size; 71 int chunk_pos; 72 int end_of_data; 73 74 /* variables for stream download: */ 75 int metapos; 76 77 /* file decoder that uses us - if that is the case */ 78 file_decoder_t * fdec; 79 } http_session_t; 80 81 82 int httpc_is_url(const char * str); 83 84 http_session_t * httpc_new(void); 85 void httpc_del(http_session_t * session); 86 87 /* Initiate a HTTP/1.1 request. 88 * fdec: associated file_decoder (may be NULL if HTTPC is used 89 * for purposes other than streaming audio data). 90 * URL: string containing location including protocol (http://), 91 * host, port (optional), path. 92 * proxy_URL: may be NULL if none used 93 * proxy_port : integer 94 * start_byte : first byte of content we are interested in, 95 * should be 0L for most cases. 96 * 97 * Return: one of HTTPC_* 98 */ 99 int httpc_init(http_session_t * session, file_decoder_t * fdec, char * URL, 100 int use_proxy, char * proxy, int proxy_port, 101 char * noproxy_domains, long long start_byte); 102 103 int httpc_read(http_session_t * session, char * buf, int num); 104 int httpc_seek(http_session_t * session, long long offset, int whence); 105 long long httpc_tell(http_session_t * session); 106 void httpc_close(http_session_t * session); 107 108 int httpc_reconnect(http_session_t * session); 109 110 void httpc_add_headers_meta(http_session_t * session, metadata_t * meta); 111 112 113 #endif /* AQUALUNG_HTTPC_H */ 114 115 116 // vim: shiftwidth=8:tabstop=8:softtabstop=8 : 117 118