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

core/bitzi.c File Reference


Detailed Description

Bitzi Core search code.

This code makes searches to the Bitzi (bitzi.com) meta-data service. It is independent from any GUI functions and part of the core of GTKG.

Note:
The code requires libxml to parse the XML responses.
Author:
Alex Bennee <alex@bennee.com>
Date:
2004

#include "common.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "http.h"
#include "bitzi.h"
#include "settings.h"
#include "if/bridge/c2ui.h"
#include "if/gnet_property_priv.h"
#include "lib/atoms.h"
#include "lib/getdate.h"
#include "lib/glib-missing.h"
#include "lib/tm.h"
#include "lib/urn.h"
#include "lib/walloc.h"
#include "lib/override.h"

Data Structures

struct  bitzi_request_t
 The bitzi_request_t structure ties together each Bitzi request which are stored in the request queue. More...
struct  efj_t
 Parse (and eventually fill in) the bitzi specific data. More...

Functions

gboolean do_metadata_query (bitzi_request_t *req)
 Send a meta-data query.
void process_meta_data (bitzi_request_t *req)
 Walk the parsed document tree and free up the data.
gboolean bitzi_cache_add (bitzi_data_t *data)
void bitzi_cache_remove (bitzi_data_t *data)
void bitzi_cache_clean (void)
gchar * xml_get_string (xmlNode *node, const gchar *id)
void xml_free_null (gchar **ptr)
 Use this to free strings returned by xml_get_string().
const xmlChar * string_to_xmlChar (const gchar *s)
const gchar * xmlChar_to_gchar (const xmlChar *s)
bitzi_data_tbitzi_create (void)
void bitzi_destroy (bitzi_data_t *data)
void bitzi_host_data_ind (struct http_async *unused_handle, gchar *data, gint len)
 Populate callback: more data available.
void bitzi_host_error_ind (struct http_async *handle, http_errtype_t unused_type, gpointer unused_v)
 HTTP request is being stopped.
void process_rdf_description (xmlNode *node, bitzi_data_t *data)
 Read all the attributes we may want from the rdf ticket, some attributes will not be there in which case xmlGetProp will return a null.
void process_bitzi_ticket (xmlNode *a_node, bitzi_data_t *data)
 Iterates through the XML/RDF ticket calling various process functions to read the data into the bitzi_data_t.
void bitzi_failure (const struct sha1 *sha1, filesize_t filesize, bitzi_fj_t error)
void bitzi_request_free (bitzi_request_t **ptr)
gint bitzi_date_compare (gconstpointer p, gconstpointer q)
 Add the data entry to the cache and in expiry sorted date order to the linked list.
gboolean bitzi_heartbeat (gpointer unused_data)
 The heartbeat function is a repeating glib timeout that is used to pace queries to the bitzi metadata service.
bitzi_data_tbitzi_query_cache_by_sha1 (const struct sha1 *sha1)
gboolean bitzi_has_cached_ticket (const struct sha1 *sha1)
 Query the bitzi cache for this given SHA-1.
bitzi_data_tbitzi_query_by_sha1 (const struct sha1 *sha1, filesize_t filesize)
 A GUI/Bitzi API passes a pointer to the search type (currently only urn:sha1), a pointer to a callback function and a user data pointer.
void bitzi_load_cache (void)
void bitzi_init (void)
 Initialise any bitzi specific stuff we want to here.
void bitzi_close (void)

Variables

const gchar bitzi_url_fmt [] = "http://ticket.bitzi.com/rdf/urn:sha1:%s"
GSList * bitzi_rq
bitzi_request_tcurrent_bitzi_request
gpointer current_bitzi_request_handle
guint bitzi_heartbeat_id
GHashTable * bitzi_cache_ht
GList * bitzi_cache
FILE * bitzi_cache_file
const struct efj_t enum_fj_table []


Function Documentation

gboolean bitzi_cache_add bitzi_data_t data  )  [static]
 

void bitzi_cache_clean void   )  [static]
 

void bitzi_cache_remove bitzi_data_t data  )  [static]
 

void bitzi_close void   ) 
 

bitzi_data_t* bitzi_create void   )  [static]
 

gint bitzi_date_compare gconstpointer  p,
gconstpointer  q
[static]
 

Add the data entry to the cache and in expiry sorted date order to the linked list.

void bitzi_destroy bitzi_data_t data  )  [static]
 

void bitzi_failure const struct sha1 sha1,
filesize_t  filesize,
bitzi_fj_t  error
[static]
 

gboolean bitzi_has_cached_ticket const struct sha1 sha1  ) 
 

Query the bitzi cache for this given SHA-1.

gboolean bitzi_heartbeat gpointer  unused_data  )  [static]
 

The heartbeat function is a repeating glib timeout that is used to pace queries to the bitzi metadata service.

It also periodically runs the bitzi_cache_clean routine to clean the cache.

void bitzi_host_data_ind struct http_async unused_handle,
gchar *  data,
gint  len
[static]
 

Populate callback: more data available.

When called with 0 it stops the parsing of the document tree and processes the ticket.

void bitzi_host_error_ind struct http_async handle,
http_errtype_t  unused_type,
gpointer  unused_v
[static]
 

HTTP request is being stopped.

void bitzi_init void   ) 
 

Initialise any bitzi specific stuff we want to here.

void bitzi_load_cache void   )  [static]
 

bitzi_data_t* bitzi_query_by_sha1 const struct sha1 sha1,
filesize_t  filesize
 

A GUI/Bitzi API passes a pointer to the search type (currently only urn:sha1), a pointer to a callback function and a user data pointer.

If no query succeds then the call back is never made, however we should always get some sort of data back from the service.

bitzi_data_t* bitzi_query_cache_by_sha1 const struct sha1 sha1  )  [static]
 

void bitzi_request_free bitzi_request_t **  ptr  )  [static]
 

gboolean do_metadata_query bitzi_request_t req  )  [static]
 

Send a meta-data query.

Called directly when a request launched or via the bitzi_heartbeat tick.

void process_bitzi_ticket xmlNode *  a_node,
bitzi_data_t data
[static]
 

Iterates through the XML/RDF ticket calling various process functions to read the data into the bitzi_data_t.

This function is recursive, if the element is not explicity know we just recurse down a level.

void process_meta_data bitzi_request_t request  )  [static]
 

Walk the parsed document tree and free up the data.

void process_rdf_description xmlNode *  node,
bitzi_data_t data
[static]
 

Read all the attributes we may want from the rdf ticket, some attributes will not be there in which case xmlGetProp will return a null.

TRANSLATORS: This describes video parameters; The first part is used as <width>x<height> (resolution). fps stands for "frames per second". kbps stands for "kilobit per second" (metric kilo).

const xmlChar* string_to_xmlChar const gchar *  s  )  [inline, static]
 

void xml_free_null gchar **  ptr  )  [inline, static]
 

Use this to free strings returned by xml_get_string().

gchar* xml_get_string xmlNode *  node,
const gchar *  id
[inline, static]
 

const gchar* xmlChar_to_gchar const xmlChar *  s  )  [inline, static]
 


Variable Documentation

GList* bitzi_cache [static]
 

FILE* bitzi_cache_file [static]
 

GHashTable* bitzi_cache_ht [static]
 

guint bitzi_heartbeat_id [static]
 

GSList* bitzi_rq [static]
 

const gchar bitzi_url_fmt[] = "http://ticket.bitzi.com/rdf/urn:sha1:%s" [static]
 

bitzi_request_t* current_bitzi_request [static]
 

gpointer current_bitzi_request_handle [static]
 

const struct efj_t enum_fj_table[] [static]
 

Initial value:

 {
    { "Unknown",                BITZI_FJ_UNKNOWN },
    { "Bitzi lookup failure",   BITZI_FJ_FAILURE },
    { "Filesize mismatch",      BITZI_FJ_WRONG_FILESIZE },
    { "Dangerous/Misleading",   BITZI_FJ_DANGEROUS_MISLEADING },
    { "Incomplete/Damaged",     BITZI_FJ_INCOMPLETE_DAMAGED },
    { "Substandard",            BITZI_FJ_SUBSTANDARD },
    { "Overrated",              BITZI_FJ_OVERRATED },
    { "Normal",                 BITZI_FJ_NORMAL },
    { "Underrated",             BITZI_FJ_UNDERRATED },
    { "Complete",               BITZI_FJ_COMPLETE },
    { "Recommended",            BITZI_FJ_RECOMMENDED },
    { "Best Version",           BITZI_FJ_BEST_VERSION }
}


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1