/* Jungle Monkey
 * Copyright (C) 1999-2001  The Regents of the University of Michigan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _MTP_CLIENT_H
#define _MTP_CLIENT_H

#include <glib.h>
#include <gnet/gnet.h>
#include <stdio.h>


/* **************************************** */
/* MTP Client				    */


typedef struct _MtpClient MtpClient;

typedef enum {
  MTP_CLIENT_STATUS_OK,
  MTP_CLIENT_STATUS_UPDATE,
  MTP_CLIENT_STATUS_ERROR

} MtpClientStatus;

/* After these callbacks, the callee is responsible for deleting the
   client. */

typedef void (*MtpClientMirrorsFunc) (MtpClient* client, MtpClientStatus status, 
				      GSList* conns, gpointer user_data);
/* User has ref to conns, so should be unrefed. */

typedef void (*MtpClientInfoFunc) (MtpClient* client, MtpClientStatus status, 
				   gint length, gpointer user_data);

typedef void (*MtpClientMirrorFunc) (MtpClient* client, MtpClientStatus status, 
				     GConn* conn, gpointer user_data);
/* User has ref to conn, so should be unrefed. */

typedef guint (*MtpClientRecvFunc) (MtpClient* client, MtpClientStatus status,
				    const void* buffer, guint length, 
				    gpointer user_data);
/* First call has buffer and length set to 0 and client->file set to
   the file length.  After that, buffer and length will be set. */

typedef void (*MtpClientFileFunc) (MtpClient* client, MtpClientStatus status,
				   gpointer user_data);
/* Calls with OK when done, UPDATE when it reads, and ERROR on error */



/*
  
  MtpClient.  url, length, and offset are public.  The other fields
  are not.

 */
struct _MtpClient
{
  GURL*		url;		/* URL of host			*/

  GConn*	conn;		/* Connection (can be refed)	*/

  GSList*   	children;	/* Children clients		*/

  guint   	length;		/* File length			*/		
  guint8* 	buffer;		/* Buffer			*/
  guint		offset;		/* Offset in file		*/

  gchar*	path;		/* Path to file			*/
  FILE*		file;		/* File				*/
  GSHA*		sha;		/* SHA of file			*/

  gpointer	func;		/* Callback			*/
  gpointer	user_data;	/* User data for callback	*/
};



void	   mtp_client_delete (MtpClient* client);
/* MtpClient creator must delete client when done. */

MtpClient* mtp_client_get_mirrors (const GURL* url, MtpClientMirrorsFunc func, 
				   gpointer user_data);
	   
MtpClient* mtp_client_get_info (const GURL* url, MtpClientInfoFunc func, 
				gpointer user_data);
	   
MtpClient* mtp_client_get_mirror (const GURL* url, MtpClientMirrorFunc func, 
				  gpointer user_data);
	   
MtpClient* mtp_client_get_file_mirror (const GURL* url, MtpClientRecvFunc func, 
				       gpointer user_data);
	   
MtpClient* mtp_client_get_file_rendezvous (const GURL* url, MtpClientRecvFunc func, 
					   gpointer user_data);
	   
MtpClient* mtp_client_get_file (const GURL* url, const gchar* path, 
				MtpClientFileFunc func, gpointer user_data);


#endif /* _MTP_CLIENT_H */


syntax highlighted by Code2HTML, v. 0.9.1