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

bh_upload.c File Reference


Detailed Description

Handles the server-side of the Browse Host function.

Author:
Christian Biere

Raphael Manfredi

Date:
2005

#include "common.h"
#include "bh_upload.h"
#include "share.h"
#include "bsched.h"
#include "tx.h"
#include "tx_link.h"
#include "tx_chunk.h"
#include "tx_deflate.h"
#include "qhit.h"
#include "gmsg.h"
#include "guid.h"
#include "version.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/header.h"
#include "lib/misc.h"
#include "lib/url.h"
#include "lib/walloc.h"
#include "lib/override.h"

Data Structures

struct  browse_host_ctx

Defines

#define BH_MAX_QHIT_SIZE   3500 /**< Flush hits larger than this */
 Flush hits larger than this.

#define BH_SCAN_AHEAD   100 /**< Amount of files scanned ahead */
 Amount of files scanned ahead.

#define BH_BUFSIZ   16384 /**< Buffer size for TX deflation */
 Buffer size for TX deflation.


Enumerations

enum  bh_state {
  BH_STATE_HEADER = 0, BH_STATE_LIBRARY_INFO, BH_STATE_FILES, BH_STATE_REBUILDING,
  BH_STATE_TRAILER, BH_STATE_EOF, NUM_BH_STATES
}
enum  bh_type { BH_TYPE_HTML = 0, BH_TYPE_QHIT }

Functions

 RCSID ("$Id:bh_upload.c, v 1.21 2006/01/01 19:09:02 rmanfredi Exp $")
size_t browse_host_read_data (struct browse_host_ctx *bh, gchar *dest, size_t *size)
 Copies up to ``*size'' bytes from current data block (bh->b_data + bh->b_offset) to the buffer ``dest''.

void browse_host_next_state (struct browse_host_ctx *bh, enum bh_state state)
 Sets the state of the browse host context to ``state'' and resets the data block variables.

ssize_t browse_host_read_html (gpointer ctx, gpointer const dest, size_t size)
 Writes the browse host data of the context ``ctx'' to the buffer ``dest''.

void browse_host_record_hit (gpointer data, size_t len, gpointer udata)
 Enqueue query hit built by creating a message.

ssize_t browse_host_read_qhits (gpointer ctx, gpointer const dest, size_t size)
 Writes the browse host data of the context ``ctx'' to the buffer ``dest''.

ssize_t browse_host_write (gpointer ctx, gpointer data, size_t size)
 Write data to the TX stack.

void browse_tx_flushed (txdrv_t *unused_tx, gpointer arg)
 Callback invoked when the TX stack is fully flushed.

void browse_host_flush (gpointer ctx, bh_closed_t cb, gpointer arg)
 Flush the TX stack, invoking callback when it's done.

void browse_host_close (gpointer ctx, gboolean fully_served)
 Closes the browse host context and releases its memory.

special_ctxbrowse_host_open (gpointer owner, gnet_host_t *host, bh_writable_t writable, struct tx_deflate_cb *deflate_cb, struct tx_link_cb *link_cb, wrap_io_t *wio, gint flags)
 Creates a new browse host context.


Define Documentation

#define BH_BUFSIZ   16384 /**< Buffer size for TX deflation */
 

Buffer size for TX deflation.

#define BH_MAX_QHIT_SIZE   3500 /**< Flush hits larger than this */
 

Flush hits larger than this.

Therefore, don't generate too large ones or they might be dropped by the recipient. Still, we need a large size to avoid generating too many useless Gnutella headers and query hit trailers (like push proxies, our GUID, etc...).

#define BH_SCAN_AHEAD   100 /**< Amount of files scanned ahead */
 

Amount of files scanned ahead.


Enumeration Type Documentation

enum bh_state
 

Enumeration values:
BH_STATE_HEADER 
BH_STATE_LIBRARY_INFO 
BH_STATE_FILES 
BH_STATE_REBUILDING 
BH_STATE_TRAILER 
BH_STATE_EOF 
NUM_BH_STATES 

enum bh_type
 

Enumeration values:
BH_TYPE_HTML 
BH_TYPE_QHIT 


Function Documentation

void browse_host_close gpointer  ctx,
gboolean  fully_served
 

Closes the browse host context and releases its memory.

Returns:
An initialized browse host context.

void browse_host_flush gpointer  ctx,
bh_closed_t  cb,
gpointer  arg
[static]
 

Flush the TX stack, invoking callback when it's done.

void browse_host_next_state struct browse_host_ctx bh,
enum bh_state  state
[inline, static]
 

Sets the state of the browse host context to ``state'' and resets the data block variables.

struct special_ctx* browse_host_open gpointer  owner,
gnet_host_t host,
bh_writable_t  writable,
struct tx_deflate_cb deflate_cb,
struct tx_link_cb link_cb,
wrap_io_t wio,
gint  flags
 

Creates a new browse host context.

The context must be freed with browse_host_close().

Parameters:
owner the owner of the TX stack (the upload)
host the host to which we're talking to
writable no document
deflate_cb callbacks for the deflate layer
link_cb callbacks for the link layer
wio no document
flags opening flags
Returns:
An initialized browse host context.

size_t browse_host_read_data struct browse_host_ctx bh,
gchar *  dest,
size_t *  size
[inline, static]
 

Copies up to ``*size'' bytes from current data block (bh->b_data + bh->b_offset) to the buffer ``dest''.

Parameters:
bh an initialized browse host context.
dest the destination buffer.
size must point to a ``size_t'' variable and initialized to the number of bytes that ``dest'' can hold. It's value is automagically decreased by the amount of bytes copied.
Returns:
The amount of bytes copied. Use this to advance ``dest''.

ssize_t browse_host_read_html gpointer  ctx,
gpointer const  dest,
size_t  size
[static]
 

Writes the browse host data of the context ``ctx'' to the buffer ``dest''.

This must be called multiple times to retrieve the complete data until zero is returned i.e., the end of file is reached.

This routine deals with HTML data generation.

Parameters:
ctx an initialized browse host context.
dest the destination buffer.
size the amount of bytes ``dest'' can hold.
Returns:
-1 on failure, zero at the end-of-file condition or if size was zero. On success, the amount of bytes copied to ``dest'' is returned.

ssize_t browse_host_read_qhits gpointer  ctx,
gpointer const  dest,
size_t  size
[static]
 

Writes the browse host data of the context ``ctx'' to the buffer ``dest''.

This must be called multiple times to retrieve the complete data until zero is returned i.e., the end of file is reached.

This routine deals with query hit data generation.

Parameters:
ctx an initialized browse host context.
dest the destination buffer.
size the amount of bytes ``dest'' can hold.
Returns:
-1 on failure, zero at the end-of-file condition or if size was zero. On success, the amount of bytes copied to ``dest'' is returned.

void browse_host_record_hit gpointer  data,
size_t  len,
gpointer  udata
[static]
 

Enqueue query hit built by creating a message.

Callback for qhit_build_results().

ssize_t browse_host_write gpointer  ctx,
gpointer  data,
size_t  size
 

Write data to the TX stack.

void browse_tx_flushed txdrv_t unused_tx,
gpointer  arg
[static]
 

Callback invoked when the TX stack is fully flushed.

RCSID "$Id:bh_upload.  c,
v 1.21 2006/01/01 19:09:02 rmanfredi Exp $" 
 


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