diff src/gt_xfer_obj.h @ 0:d39e1d0d75b6

initial add
author paulo@hit-nxdomain.opendns.com
date Sat, 20 Feb 2010 21:18:28 -0800
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/gt_xfer_obj.h	Sat Feb 20 21:18:28 2010 -0800
     1.3 @@ -0,0 +1,159 @@
     1.4 +/*
     1.5 + * $Id: gt_xfer_obj.h,v 1.23 2004/05/05 10:30:12 hipnod Exp $
     1.6 + *
     1.7 + * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net)
     1.8 + *
     1.9 + * This program is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License as published by the
    1.11 + * Free Software Foundation; either version 2, or (at your option) any
    1.12 + * later version.
    1.13 + *
    1.14 + * This program is distributed in the hope that it will be useful, but
    1.15 + * WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * General Public License for more details.
    1.18 + */
    1.19 +
    1.20 +#ifndef GIFT_GT_XFER_OBJ_H_
    1.21 +#define GIFT_GT_XFER_OBJ_H_
    1.22 +
    1.23 +/*****************************************************************************/
    1.24 +
    1.25 +#define HTTP_DEBUG   gt_config_get_int("http/debug=0")
    1.26 +
    1.27 +#define HTTP_MAX_PERUSER_UPLOAD_CONNS \
    1.28 +                     gt_config_get_int("http/max_peruser_upload_connections=5")
    1.29 +
    1.30 +/*****************************************************************************/
    1.31 +
    1.32 +struct gt_source;
    1.33 +
    1.34 +typedef enum gt_transfer_type
    1.35 +{
    1.36 +	GT_TRANSFER_UPLOAD,
    1.37 +	GT_TRANSFER_DOWNLOAD,
    1.38 +} GtTransferType;
    1.39 +
    1.40 +typedef void (*GtTransferCB) (Chunk *chunk, unsigned char *data, size_t len);
    1.41 +
    1.42 +typedef struct gt_transfer
    1.43 +{
    1.44 +	TCPC          *c;                  /* see gt_transfer_ref */
    1.45 +	Chunk         *chunk;              /* ...                 */
    1.46 +	Source        *source;             /* source for this transfer */
    1.47 +
    1.48 +	GtTransferCB  callback;            /* where to report progress
    1.49 +	                                    * see gt_download and gt_upload in
    1.50 +	                                    * xfer.c */
    1.51 +	GtTransferType type;               /* which direction this transfer is in */
    1.52 +
    1.53 +	Dataset       *header;             /* HTTP headers */
    1.54 +	int            code;               /* HTTP status code last seen */
    1.55 +
    1.56 +	in_addr_t      ip;                 /* address of the user who is either
    1.57 +	                                    * leeching our node or is being leeched
    1.58 +	                                    * by it */
    1.59 +	in_port_t      port;               /* used only by the client routines */
    1.60 +
    1.61 +	char          *command;            /* request operator (GET, PUSH, ...) */
    1.62 +	char          *request;            /* exact request operand, url encoded */
    1.63 +	char          *version;            /* HTTP version resembling HTTP/1.1 */
    1.64 +	char          *request_path;       /* url decoded copy of request */
    1.65 +
    1.66 +	char          *content_type;       /* Content-Type: send from server or
    1.67 +	                                    * to client */
    1.68 +	char          *content_urns;       /* X-Gnutella-Content-URN: if requested
    1.69 +	                                    * by urn */
    1.70 +	BOOL           transmitted_hdrs;   /* transfer completed reading HTTP
    1.71 +	                                    * headers */
    1.72 +	off_t          remaining_len;      /* size of content remaining to be
    1.73 +	                                    * read */
    1.74 +
    1.75 +	off_t          start;              /* range begin */
    1.76 +	off_t          stop;               /* range stop.  0 is an exception which
    1.77 +	                                    * will be translated to the total file
    1.78 +	                                    * size as soon as known */
    1.79 +	timer_id       header_timer;       /* timeout for reading complete header */
    1.80 +
    1.81 +	timer_id       detach_timer;       /* fires to detach xfer and chunk */
    1.82 +	SourceStatus   detach_status;      /* next status if detach_timer hits */
    1.83 +	char          *detach_msgtxt;      /* next msg if detach_timer hits */
    1.84 +
    1.85 +	/* used by the server routines for uploading */
    1.86 +	FILE          *f;                  /* used only by the server routines */
    1.87 +	Share         *share_authd;        /* hack for the new sharing
    1.88 +	                                    * interface...ugh */
    1.89 +
    1.90 +	char          *open_path;          /* path opened by the server */
    1.91 +	off_t          open_path_size;     /* size of the file on disk described
    1.92 +	                                    * by open_path */
    1.93 +	char          *hash;               /* openft's hash to deliever to the
    1.94 +	                                    * interface protocol when we register
    1.95 +	                                    * this upload */
    1.96 +	unsigned int   queue_pos;          /* position in upload queue */
    1.97 +	unsigned int   queue_ttl;          /* size of queue */
    1.98 +
    1.99 +	unsigned char  shared : 1;         /* see interface proto docs */
   1.100 +} GtTransfer;
   1.101 +
   1.102 +/*****************************************************************************/
   1.103 +
   1.104 +#include "gt_http_client.h"
   1.105 +#include "gt_http_server.h"
   1.106 +
   1.107 +/*****************************************************************************/
   1.108 +
   1.109 +GtTransfer  *gt_transfer_new    (GtTransferType type, Source *source,
   1.110 +                                 in_addr_t ip, in_port_t port,
   1.111 +                                 off_t start, off_t stop);
   1.112 +void         gt_transfer_close  (GtTransfer *xfer, BOOL force_close);
   1.113 +void         gt_transfer_status (GtTransfer *xfer, SourceStatus status,
   1.114 +                                 char *text);
   1.115 +
   1.116 +void         gt_transfer_write  (GtTransfer *xfer, Chunk *chunk,
   1.117 +                                 unsigned char *segment, size_t len);
   1.118 +
   1.119 +/*****************************************************************************/
   1.120 +
   1.121 +void               gt_transfer_set_tcpc   (GtTransfer *xfer, TCPC *c);
   1.122 +void               gt_transfer_set_chunk  (GtTransfer *xfer, Chunk *chunk);
   1.123 +
   1.124 +TCPC              *gt_transfer_get_tcpc   (GtTransfer *xfer);
   1.125 +Chunk             *gt_transfer_get_chunk  (GtTransfer *xfer);
   1.126 +
   1.127 +struct gt_source  *gt_transfer_get_source (GtTransfer *xfer);
   1.128 +void               gt_transfer_set_length (GtTransfer *xfer, Chunk *chunk);
   1.129 +
   1.130 +/*****************************************************************************/
   1.131 +
   1.132 +void         gt_http_connection_close  (GtTransferType type, TCPC *c,
   1.133 +                                        BOOL force_close);
   1.134 +TCPC        *gt_http_connection_open   (GtTransferType type, in_addr_t ip,
   1.135 +                                        in_port_t port);
   1.136 +TCPC        *gt_http_connection_lookup (GtTransferType type,
   1.137 +                                        in_addr_t ip, in_port_t port);
   1.138 +size_t       gt_http_connection_length (GtTransferType type, in_addr_t ip);
   1.139 +
   1.140 +/*****************************************************************************/
   1.141 +
   1.142 +BOOL  gt_transfer_set_request  (GtTransfer *xfer, char *request);
   1.143 +FILE *gt_transfer_open_request (GtTransfer *xfer, int *code);
   1.144 +
   1.145 +/*****************************************************************************/
   1.146 +
   1.147 +void gt_download (Chunk *chunk, unsigned char *segment, size_t len);
   1.148 +void gt_upload   (Chunk *chunk, unsigned char *segment, size_t len);
   1.149 +
   1.150 +/*****************************************************************************/
   1.151 +
   1.152 +void gt_download_cancel (Chunk *chunk, void *data);
   1.153 +void gt_upload_cancel   (Chunk *chunk, void *data);
   1.154 +
   1.155 +/*****************************************************************************/
   1.156 +
   1.157 +BOOL gt_chunk_suspend (Chunk *chunk, Transfer *transfer, void *data);
   1.158 +BOOL gt_chunk_resume  (Chunk *chunk, Transfer *transfer, void *data);
   1.159 +
   1.160 +/*****************************************************************************/
   1.161 +
   1.162 +#endif /* GIFT_GT_XFER_OBJ_H_ */