Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

http.h

Go to the documentation of this file.
00001 /*
00002  * $Id: http.h,v 1.18 2005/11/09 19:16:53 cbiere Exp $
00003  *
00004  * Copyright (c) 2002-2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00036 #ifndef _core_http_h_
00037 #define _core_http_h_
00038 
00039 #include "if/core/http.h"
00040 #include "lib/host_addr.h"
00041 
00042 #define HTTP_PORT       80      
00048 typedef enum {
00049     HTTP_EXTRA_LINE,
00050     HTTP_EXTRA_CALLBACK,
00051     HTTP_EXTRA_BODY
00052 } http_extra_type_t;
00053 
00065 typedef void (*http_status_cb_t)(
00066     gchar *buf, gint *retlen, gpointer arg, guint32 flags);
00067 
00068 typedef struct {
00069     http_extra_type_t he_type;      
00070     union {
00071         gchar *u_msg;               
00072         struct {
00073             http_status_cb_t u_cb;  
00074             gpointer u_arg;         
00075         } u_cbk;
00076     } u;
00077 } http_extra_desc_t;
00078 
00079 #define he_msg  u.u_msg
00080 #define he_cb   u.u_cbk.u_cb
00081 #define he_arg  u.u_cbk.u_arg
00082 
00083 /*
00084  * Flags used during callback invocation.
00085  */
00086 
00087 #define HTTP_CBF_SMALL_REPLY    0x00000001  
00088 #define HTTP_CBF_BW_SATURATED   0x00000002  
00089 #define HTTP_CBF_BUSY_SIGNAL    0x00000004  
00090 #define HTTP_CBF_SHOW_RANGES    0x00000008  
00092 struct header;
00093 
00098 typedef gboolean (*http_header_cb_t)(
00099     gpointer h, struct header *header, gint code, const gchar *message);
00100 
00104 typedef void (*http_data_cb_t)(gpointer h, gchar *data, gint len);
00105 
00106 typedef enum {              
00107     HTTP_ASYNC_SYSERR,      
00108     HTTP_ASYNC_ERROR,       
00109     HTTP_ASYNC_HEADER,      
00110     HTTP_ASYNC_HTTP         
00111 } http_errtype_t;
00112 
00113 typedef struct {
00114     struct header *header;  
00115     gint code;              
00116     const gchar *message;   
00117 } http_error_t;
00118 
00124 typedef void (*http_error_cb_t)(gpointer h, http_errtype_t error, gpointer val);
00125 
00130 typedef void (*http_user_free_t)(gpointer data);
00131 
00136 typedef size_t (*http_op_request_t)(gpointer handle, gchar *buf, size_t len,
00137     const gchar *verb, const gchar *path, const gchar *host, guint16 port);
00138 
00139 /*
00140  * Asynchronous request error codes.
00141  */
00142 
00143 #define HTTP_ASYNC_OK               0   
00144 #define HTTP_ASYNC_BAD_URL          1   
00145 #define HTTP_ASYNC_CONN_FAILED      2   
00146 #define HTTP_ASYNC_IO_ERROR         3   
00147 #define HTTP_ASYNC_REQ2BIG          4   
00148 #define HTTP_ASYNC_HEAD2BIG         5   
00149 #define HTTP_ASYNC_CANCELLED        6   
00150 #define HTTP_ASYNC_EOF              7   
00151 #define HTTP_ASYNC_BAD_STATUS       8   
00152 #define HTTP_ASYNC_NO_LOCATION      9   
00153 #define HTTP_ASYNC_CONN_TIMEOUT     10  
00154 #define HTTP_ASYNC_TIMEOUT          11  
00155 #define HTTP_ASYNC_NESTED           12  
00156 #define HTTP_ASYNC_BAD_LOCATION_URI 13  
00157 #define HTTP_ASYNC_CLOSED           14  
00158 #define HTTP_ASYNC_REDIRECTED       15  
00160 extern guint http_async_errno;
00161 
00166 typedef enum {
00167     HTTP_URL_OK = 0,                
00168     HTTP_URL_NOT_HTTP,              
00169     HTTP_URL_MULTIPLE_CREDENTIALS,  
00170     HTTP_URL_BAD_CREDENTIALS,       
00171     HTTP_URL_BAD_PORT_PARSING,      
00172     HTTP_URL_BAD_PORT_RANGE,        
00173     HTTP_URL_BAD_HOST_PART,         
00174     HTTP_URL_HOSTNAME_UNKNOWN,      
00175     HTTP_URL_MISSING_URI            
00176 } http_url_error_t;
00177 
00178 extern http_url_error_t http_url_errno;
00179 
00184 typedef void (*http_state_change_t)(gpointer handle, http_state_t newstate);
00185 
00190 typedef struct http_buffer {
00191     gchar *hb_arena;                
00192     gchar *hb_rptr;                 
00193     gchar *hb_end;                  
00194     gint hb_len;                    
00195 } http_buffer_t;
00196 
00197 #define http_buffer_base(hb)        ((hb)->hb_arena)
00198 #define http_buffer_length(hb)      ((hb)->hb_len)
00199 #define http_buffer_read_base(hb)   ((hb)->hb_rptr)
00200 #define http_buffer_unread(hb)      ((hb)->hb_end - (hb)->hb_rptr)
00201 
00202 #define http_buffer_add_read(hb,tx) do { (hb)->hb_rptr += (tx); } while (0)
00203 
00204 /*
00205  * Public interface
00206  */
00207 
00208 struct gnutella_socket;
00209 
00210 void http_timer(time_t now);
00211 
00212 gboolean http_send_status(struct gnutella_socket *s,
00213     gint code, gboolean keep_alive, http_extra_desc_t *hev, gint hevcnt,
00214     const gchar *reason, ...) G_GNUC_PRINTF(6, 7);
00215 
00216 void http_hostname_add(
00217     gchar *buf, gint *retval, gpointer arg, guint32 flags);
00218 
00219 gint http_status_parse(const gchar *line,
00220     const gchar *proto, const gchar **msg, guint *major, guint *minor);
00221 
00222 gboolean http_extract_version(
00223     const gchar *request, gint len, guint *major, guint *minor);
00224 
00225 http_buffer_t *http_buffer_alloc(gchar *buf, size_t len, size_t written);
00226 void http_buffer_free(http_buffer_t *b);
00227 
00228 gint
00229 http_content_range_parse(const gchar *buf,
00230         filesize_t *start, filesize_t *end, filesize_t *total);
00231 
00232 filesize_t http_range_size(const GSList *list);
00233 void http_range_free(GSList *list);
00234 GSList *http_range_parse(const gchar *field, const gchar *value,
00235         filesize_t size, const gchar *vendor);
00236 gboolean http_range_contains(GSList *ranges, filesize_t from, filesize_t to);
00237 
00238 const gchar *http_url_strerror(http_url_error_t errnum);
00239 gboolean http_url_parse(
00240     const gchar *url, guint16 *port, const gchar **host, const gchar **path);
00241 
00242 gpointer http_async_get(
00243     gchar *url,
00244     http_header_cb_t header_ind,
00245     http_data_cb_t data_ind,
00246     http_error_cb_t error_ind);
00247 
00248 gpointer http_async_get_addr(
00249     gchar *path,
00250     const host_addr_t,
00251     guint16 port,
00252     http_header_cb_t header_ind,
00253     http_data_cb_t data_ind,
00254     http_error_cb_t error_ind);
00255 
00256 const gchar *http_async_strerror(guint errnum);
00257 const gchar *http_async_info(
00258     gpointer handle, const gchar **req, gchar **path,
00259     host_addr_t *addr, guint16 *port);
00260 void http_async_connected(gpointer handle);
00261 void http_async_close(gpointer handle);
00262 void http_async_cancel(gpointer handle);
00263 void http_async_error(gpointer handle, gint code);
00264 http_state_t http_async_state(gpointer handle);
00265 
00266 void http_async_set_opaque(gpointer handle, gpointer data, http_user_free_t fn);
00267 gpointer http_async_get_opaque(gpointer handle);
00268 void http_async_log_error(gpointer handle, http_errtype_t type, gpointer v);
00269 void http_async_log_error_dbg(
00270     gpointer handle, http_errtype_t type, gpointer v, guint32 dbg_level);
00271 
00272 void http_async_on_state_change(gpointer handle, http_state_change_t fn);
00273 void http_async_allow_redirects(gpointer handle, gboolean allow);
00274 void http_async_set_op_request(gpointer handle, http_op_request_t op);
00275 
00276 void http_close(void);
00277 
00278 #endif  /* _core_http_h_ */
00279 
00280 /* vi: set ts=4 sw=4 cindent: */

Generated on Sun Feb 12 10:49:56 2006 for Gtk-Gnutella by doxygen 1.3.6