Hi,

Apparently my first mail got lost. So I hereby resend it:

I hereby send a very rough (incomplete) API as I see how the
gnutella-lib API should look like.

For the configuration perhaps something like:


#define CONFIG_S_NAME "GTK_GNUTELLA_LIB_CONFIG"
#define CONFIG_S_NAME_LENGTH 23

typedef struct config_s config_t;
struct config_s {
    char    config_s_name[CONFIG_S_NAME_LENGTH];
    char    *config_name;        /**< Name. eg: Downloads.Timeout.Retry
*/
    char    *config_hint;        /**< Hint. eg: When to retry a download
that timed out */

    int        type;                /**< Boolean, nummeric, float?, 
string, enum */
    int        num_value;            /**< Assigned value. eg: 1800 */
    int        num_value_default;    /**< Default value if not set. eg: 
600 */
    int        num_min;            /**< Minimum value, or -1 if not a 
range. eg: 0 */
    int        num_max;            /**< Maximum value, or num_min if no 
maximum. eg: 0 */

    char    *str_value;            /**< string: Assigned value. eg:
~/tmp */
    char    *str_value_default;    /**< string: Default value. eg: ~ */

    char    **enum_values;       

    int        ID;                    /**< ID for translation. Must be 
unique for every config entry. */
};

/**
 * Get first setting from config file.
 *
 * Gets the first setting from the configuration data. If you want to 
retreive
 * all config items you can use gnut_config_get_items_first() and then
use
 * gnut_config_get_item_next(gnut_config_t *) to travel thru the list of
all
 * configuration items.
 *
 * @return pointer to the config item. If the pointer is NULL there are
no
 * configuration items.
 */
gnut_config_t    *gnut_config_get_item_first();

/**
 * Get next setting from config file.
 *
 * Gets the next setting from the configuration data relative to
*config.
 * If you want to retreive all config items you can use 
gnut_config_get_items_first()
 * and then use gnut_config_get_item_next(gnut_config_t *) to travel 
thru the list of
 * all configuration items.
 *
 * @param config is a pointer to the current configuration item.
 * @return pointer to the next configuration item relative to config. If
the pointer
 * is NULL there are no next configuration items.
 */
gnut_config_t    *gnut_config_get_item_next(gnut_config_t *config);

/**
 * Get previous setting from config file.
 *
 * Gets the previous setting from the configuration data relative to 
*config.
 * You can use this function to travel thru the list of configuration
items.
 *
 * @param config is a pointer to the current configuration item.
 * @return pointer to the previous configuration item relative to 
config. If the
 * pointer is NULL there are no next configuration items.
 */
gnut_config_t    *gnut_config_get_item_prev(gnut_config_t *config);

/**
 * Get the last setting from config file.
 *
 * Gets the last setting from the configuration data.
 *
 * @return pointer to the last config item. If the pointer is NULL there
are no
 * configuration items.
 */
gnut_config_t    *gnut_config_get_item_last();

/**
 * Find a configuration setting with a given name.
 *
 * @param config_name contains the name to locate.
 * @return a pointer to the configuration item with the given name. 
Returns NULL
 * if the configuration items is not found.
 */
gnut_config_t    *gnut_config_find_with_name(char *config_name);
       
char    *gnut_config_get_name(gnut_tconfig *config);
char    *gnut_config_get_hint(gnut_tconfig *config);
int         gnut_config_get_type(gnut_tconfig *config);
int         gnut_config_get_id(gnut_tconfig *config);

int         gnut_config_get_num_value(gnut_tconfig *config);
int         gnut_config_get_num_value_default(gnut_tconfig *config);
int         gnut_config_get_num_min(gnut_tconfig *config);
int         gnut_config_get_num_max(gnut_tconfig *config);

char    *gnut_config_get_str_value(gnut_tconfig *config);
char    *gnut_config_get_str_value_default(gnut_tconfig *config);

char    *gnut_config_get_enum_value(gnut_tconfig *config);
int         gnut_config_get_enum_values(gnut_tconfig *config);

int         gnut_config_get_version(gnut_tconfig *config);

gnut_config_t    *gnut_config_set_name(char *name);
void             gnut_config_set_hint(gnut_config_t *config, char
*hint);
void             gnut_config_set_type(gnut_config_t *config, int type);

void             gnut_config_set_num_value(gnut_config_t *config, int 
value);
void             gnut_config_set_num_value_default(gnut_config_t 
*config, int value);
void             gnut_config_set_name_min(gnut_config_t *config, int
min);
void             gnut_config_set_name_max(gnut_config_t *config, int
max);

void             gnut_config_set_str_value(gnut_config_t *config, char 
*value);
void             gnut_config_set_str_value_default(gnut_config_t 
*config, char *hint);

void             gnut_config_add_enum_value(gnut_config_t *config, char 
*value);
void             gnut_config_rem_enum_value(gnut_config_t *config, char 
*value);


The events are defined as in the attached files events.c and events.h.

-- 
Jeroen Asselman <[EMAIL PROTECTED]>
#include "events.h"

typedef void GList;
typedef void GSList;

/*
 * Verification define to make sure the client is messing with us
 */
#define EVENT_ID "GTK_GNUTELLA_LIB_EVENT"
#define EVENT_ID_LENGTH 22

/* All events must include this structure as the first entry of their structure */
typedef struct event_s event_t;
struct event_s {
	char event_id[EVENT_ID_LENGTH];
	tevent even_type;

	char *description;
};

typedef struct range_s range_t;
struct range_s {
	int	start;
	int end;
};


typedef struct upload upload_t;
struct upload {
	GList	*ranges_done;
	GList	*ranges_transferring;

	char	*file_name;
	int		file_size;

	int		progress;		/* In Procent * 100 */
	int		speed;			/* In bytes / sec */

	int		eta;		/* If queued, this is the PARQ ETA. Otherwise this is
						 * the transfer eta */
};



typedef struct event_upload_s event_upload_t;
struct event_upload_s {
	event_t event;
	
	int		event_reason;

	int		id;				/* The ID with which this upload is associated.
							 * This one is unique, but will be re-used when
							 * this upload is freed with EVENT_UPLOAD_REMOVED
							 */

	int		upload_id;


	int		range_start;	/* In bytes */
	int		range_end;		/* In bytes */

	int		progress;		/* In Procent * 100 */
	int		speed;			/* In bytes / sec */

	int		queue_size;		/* PARQ queue size for current queue */
	int		queue_position;	/* Position in parq */
	int		queue_parq_q_id;	/* In which queue this upload is placed */

	int		eta;		/* If queued, this is the PARQ ETA. Otherwise this is
						 * the transfer eta */

};

/**
 * Download event structure
 *
 * Represents one transfer, most likely only a small piece of a file. Use
 * the download id for more information about the download file itself
 */
typedef struct event_download_s event_download_t;
struct event_download_s {
	event_t event;
	
	int		event_reason;

	int		id;

	int		download_id;	/* Handle to a file download */
	
	int		range_start;	/* In bytes */
	int		range_end;		/* In bytes */

	int		progress;		/* In Procent * 100 */
	int		speed;			/* In bytes / sec */

	int		queue_size;		/* PARQ queue size for current queue */
	int		queue_position;	/* Position in parq */

	int		eta;		/* If queued, this is the PARQ ETA. Otherwise this is
						 * the transfer eta */
};

struct download {
	GList	*ranges_done;
	GList	*ranges_verified;
	GList	*ranges_corrupted;
	GList	*ranges_transferring;

	char	*file_name;
	int		file_size;

	int		progress;		/* In Procent * 100 */
	int		speed;			/* In bytes / sec */

	int		eta;		/* If queued, this is the PARQ ETA. Otherwise this is
						 * the transfer eta */
};


void main(void)
{
	return;
}
/*** SECTION: General ********************************************************/
typedef int		tevent;
typedef void*	tevent_data;
typedef	int		tevent_reason;
/**
 * Test for events waiting.
 *
 * Checks whether there are currently events waiting in the event queue which
 * can be retreived using get_event.
 [EMAIL PROTECTED] the number of events waiting. 0 means there are no events in the 
 * event queue.
 */
int		waiting_events();

/**
 * Get the first waiting event from the event queue.
 *
 * Gets the first waiting event from the event queue and fills the tevent_data
 * data pointer. Don't access the data directly, use the provided functions
 * to read the data. This will ensure binary compatibility when only the 
 * library gets upgraded.
 * short example: switch (int event_type = get_event(&data))
 [EMAIL PROTECTED] the event number. Returns EVENT_NONE if there are no events waiting.
 */
tevent		get_event(tevent_data data);

/* These are the ones you get when you do a 'gnut_get_event(&data)' */
#define EVENT_NONE				0x00000001
#define EVENT_UPLOAD			0x00000002
#define EVENT_DOWNLOAD			0x00000003
#define EVENT_GNET				0x00000004
#define	EVENT_SEARCH_RESULT		0x00000005

/** Contains a description of the current event. */
char	*gnut_get_event_description(tevent_data data);
void	gnut_free_event(tevent event_type, tevent_data data); 



/* Event reasons */
#define EVENT_ID_NEW						0x10000001	/* New id created */
#define EVENT_ID_REMOVED					0x10000002	/* ID removed, from now on invalid */

/* Event reasons, errors
 * This are the possible predefined error codes. These are currently valid for
 * upload, downloads and gnutella net events
 */
#define EVENT_ERROR_EOF						0xF0000001
#define EVENT_ERROR_BROKEN_PIPE				0xF0000002
#define EVENT_ERROR_TIMEOUT					0xF0000003


/*** SECTION: Gnutella network ***********************************************/

#define	EVENT_GNET_HANDSHAKING				0x00000010
#define EVENT_GNET_ACCEPTED					0x00000020
#define EVENT_GNET_DATA_RECEIVED			0x00000030
#define EVENT_GNET_DATA_TRANSMITTED			0x00000040
/* 0x0001xxx Closing connection 'friendly' */
#define EVENT_GNET_CLOSE_NORMAL_MASK		0x00001000
#define EVENT_GNET_ALLREADY_CONNECTED		0x00001001
#define EVENT_GNET_MAX_ULTRAPEER_CON		0x00001002
#define EVENT_GNET_MAX_LEAF_CON				0x00001003
#define EVENT_GNET_MAX_NORMAL_CON			0x00001004
#define EVENT_GNET_SHIELDED_LEAF			0x00001005
/* 0x0002xxx Closing connection 'banned' reason */
#define EVENT_GNET_CLOSE_BANNED_MASK		0x00002000
#define EVENT_GNET_HOSTILE_BANNED			0x00002001
#define EVENT_GNET_UNSTABLE_IP_BANNED		0x00002002
#define EVENT_GNET_UNSTABLE_SERVENT_BANNED	0x00002003

int		 gnut_event_gnet_get_id(tevent_data data);
char	*gnut_event_gnet_get_name(tevent_data data);
int		 gnut_event_gnet_get_uptime(tevent_data data);
int		 gnut_event_gnet_get_connected_time(tevent_data data);
int		 gnut_event_gnet_get_version(tevent_data data);
char	*gnut_event_gnet_get_network(tevent_data data);
char	 gnut_event_gnet_get_connection_mode(tevent_data data); /* Leaf, normal, Ultra */
int		 gnut_event_gnet_get_received(tevent_data data);
int		 gnut_event_gnet_get_transmitted(tevent_data data);
int		 gnut_event_gnet_get_received_uncompressed(tevent_data data);
int		 gnut_event_gnet_get_transmitted_uncompressed(tevent_data data);


/*** SECTION: Downloads ******************************************************/
int		 gnut_download_get_max_downloads();
void	 gnut_download_set_max_downloads(int max);

int		 gnut_download_get_max_downloads_ip();
void	 gnut_download_set_max_downloads_ip(int max);

/* Functions to parse event data */
int		 gnut_event_download_get_id(tevent_data data);
int		 gnut_event_download_get_event_reason(tevent_data data);
char	*gnut_event_download_get_download_id(tevent_data data);
int		 gnut_event_download_get_range_start(tevent_data data);
int		 gnut_event_download_get_range_end(tevent_data data);
int		 gnut_event_download_get_progress(tevent_data data);
int		 gnut_event_download_get_speed(tevent_data data);
int		 gnut_event_download_get_queue_size(tevent_data data);
int		 gnut_event_download_get_queue_position(tevent_data data);


/*** SECTION: Uploads ********************************************************/
int		 gnut_upload_get_max_downloads();
int		 gnut_upload_get_max_downloads_ip();

char	*gnut_upload_get_file_name(int upload_id);
int		 gnut_upload_get_file_size(int upload_id);
int		 gnut_upload_get_file_progress(int upload_id);
int		 gnut_upload_get_file_speed(int upload_id);
int		 gnut_upload_get_file_eta(int upload_id);

int		 gnut_parq_get_no_queues();
int		 gnut_parq_get_no_queued(int queue);
int		 gnut_parq_get_no_alive_queued(int queue);
int		 gnut_parq_get_no_dead_queued(int queue);
int		 gnut_parq_get_no_transferring(int queue);

/**
 * Upload event reasons.
 *
 * Upload events, these are the possible values you get when you do a:
 * gnut_upload_get_event_reason(data)
 */
#define EVENT_UPLOAD_HANDSHAKING		0x00000001
#define EVENT_UPLOAD_UPLOADING			0x00000002
#define	EVENT_UPLOAD_ACTIVE_QUEUED		0x00000003
/* Upload closed 'normal' reasons */
#define EVENT_UPLOAD_CLOSE_NORMAL_MASK	0x00001000
#define	EVENT_UPLOAD_NOT_FOUND			0x00001001
#define EVENT_UPLOAD_MAX_PER_IP_REACHED	0x00001002
#define EVENT_UPLOAD_PASSIVE_QUEUED		0x00001003
#define EVENT_UPLOAD_FINISHED			0x00001004
/* Upload closed 'hostile' reasons */
#define EVENT_UPLOAD_CLOSE_BANNED_MASK	0x00002000
#define EVENT_UPLOAD_BANNED_TEMP		0x00002001
#define	EVENT_UPLOAD_BANNED_LONG		0x00002002
#define EVENT_UPLOAD_BANNED_HOSTILE		0x00002003
/**
 * Upload event functions.
 */
int		 gnut_event_upload_get_id(tevent_data data);
int		 gnut_event_upload_get_upload_id(tevent_data data);
int		 gnut_event_upload_get_event_reason(tevent_data data);
int		 gnut_event_upload_get_range_start(tevent_data data);
int		 gnut_event_upload_get_range_end(tevent_data data);
int		 gnut_event_upload_get_progress(tevent_data data);
int		 gnut_event_upload_get_speed(tevent_data data);
int		 gnut_event_upload_get_queue_size(tevent_data data);
int		 gnut_event_upload_get_queue_position(tevent_data data);
int		 gnut_event_upload_get_queue_parq_q_id(tevent_data data);
int		 gnut_event_upload_get_eta(tevent_data data);

/* The following functions are faster then there equivalant none event
 * versions. */
char	*gnut_event_upload_get_file_name(tevent_data data);
int		 gnut_event_upload_get_file_size(tevent_data data);
int		 gnut_event_upload_get_file_progress(tevent_data data);
int		 gnut_event_upload_get_file_speed(tevent_data data);
int		 gnut_event_upload_get_file_eta(tevent_data data);

Attachment: signature.asc
Description: Dit berichtdeel is digitaal ondertekend

Reply via email to