annotate 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
rev   line source
paulo@0 1 /*
paulo@0 2 * $Id: gt_xfer_obj.h,v 1.23 2004/05/05 10:30:12 hipnod Exp $
paulo@0 3 *
paulo@0 4 * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net)
paulo@0 5 *
paulo@0 6 * This program is free software; you can redistribute it and/or modify it
paulo@0 7 * under the terms of the GNU General Public License as published by the
paulo@0 8 * Free Software Foundation; either version 2, or (at your option) any
paulo@0 9 * later version.
paulo@0 10 *
paulo@0 11 * This program is distributed in the hope that it will be useful, but
paulo@0 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
paulo@0 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
paulo@0 14 * General Public License for more details.
paulo@0 15 */
paulo@0 16
paulo@0 17 #ifndef GIFT_GT_XFER_OBJ_H_
paulo@0 18 #define GIFT_GT_XFER_OBJ_H_
paulo@0 19
paulo@0 20 /*****************************************************************************/
paulo@0 21
paulo@0 22 #define HTTP_DEBUG gt_config_get_int("http/debug=0")
paulo@0 23
paulo@0 24 #define HTTP_MAX_PERUSER_UPLOAD_CONNS \
paulo@0 25 gt_config_get_int("http/max_peruser_upload_connections=5")
paulo@0 26
paulo@0 27 /*****************************************************************************/
paulo@0 28
paulo@0 29 struct gt_source;
paulo@0 30
paulo@0 31 typedef enum gt_transfer_type
paulo@0 32 {
paulo@0 33 GT_TRANSFER_UPLOAD,
paulo@0 34 GT_TRANSFER_DOWNLOAD,
paulo@0 35 } GtTransferType;
paulo@0 36
paulo@0 37 typedef void (*GtTransferCB) (Chunk *chunk, unsigned char *data, size_t len);
paulo@0 38
paulo@0 39 typedef struct gt_transfer
paulo@0 40 {
paulo@0 41 TCPC *c; /* see gt_transfer_ref */
paulo@0 42 Chunk *chunk; /* ... */
paulo@0 43 Source *source; /* source for this transfer */
paulo@0 44
paulo@0 45 GtTransferCB callback; /* where to report progress
paulo@0 46 * see gt_download and gt_upload in
paulo@0 47 * xfer.c */
paulo@0 48 GtTransferType type; /* which direction this transfer is in */
paulo@0 49
paulo@0 50 Dataset *header; /* HTTP headers */
paulo@0 51 int code; /* HTTP status code last seen */
paulo@0 52
paulo@0 53 in_addr_t ip; /* address of the user who is either
paulo@0 54 * leeching our node or is being leeched
paulo@0 55 * by it */
paulo@0 56 in_port_t port; /* used only by the client routines */
paulo@0 57
paulo@0 58 char *command; /* request operator (GET, PUSH, ...) */
paulo@0 59 char *request; /* exact request operand, url encoded */
paulo@0 60 char *version; /* HTTP version resembling HTTP/1.1 */
paulo@0 61 char *request_path; /* url decoded copy of request */
paulo@0 62
paulo@0 63 char *content_type; /* Content-Type: send from server or
paulo@0 64 * to client */
paulo@0 65 char *content_urns; /* X-Gnutella-Content-URN: if requested
paulo@0 66 * by urn */
paulo@0 67 BOOL transmitted_hdrs; /* transfer completed reading HTTP
paulo@0 68 * headers */
paulo@0 69 off_t remaining_len; /* size of content remaining to be
paulo@0 70 * read */
paulo@0 71
paulo@0 72 off_t start; /* range begin */
paulo@0 73 off_t stop; /* range stop. 0 is an exception which
paulo@0 74 * will be translated to the total file
paulo@0 75 * size as soon as known */
paulo@0 76 timer_id header_timer; /* timeout for reading complete header */
paulo@0 77
paulo@0 78 timer_id detach_timer; /* fires to detach xfer and chunk */
paulo@0 79 SourceStatus detach_status; /* next status if detach_timer hits */
paulo@0 80 char *detach_msgtxt; /* next msg if detach_timer hits */
paulo@0 81
paulo@0 82 /* used by the server routines for uploading */
paulo@0 83 FILE *f; /* used only by the server routines */
paulo@0 84 Share *share_authd; /* hack for the new sharing
paulo@0 85 * interface...ugh */
paulo@0 86
paulo@0 87 char *open_path; /* path opened by the server */
paulo@0 88 off_t open_path_size; /* size of the file on disk described
paulo@0 89 * by open_path */
paulo@0 90 char *hash; /* openft's hash to deliever to the
paulo@0 91 * interface protocol when we register
paulo@0 92 * this upload */
paulo@0 93 unsigned int queue_pos; /* position in upload queue */
paulo@0 94 unsigned int queue_ttl; /* size of queue */
paulo@0 95
paulo@0 96 unsigned char shared : 1; /* see interface proto docs */
paulo@0 97 } GtTransfer;
paulo@0 98
paulo@0 99 /*****************************************************************************/
paulo@0 100
paulo@0 101 #include "gt_http_client.h"
paulo@0 102 #include "gt_http_server.h"
paulo@0 103
paulo@0 104 /*****************************************************************************/
paulo@0 105
paulo@0 106 GtTransfer *gt_transfer_new (GtTransferType type, Source *source,
paulo@0 107 in_addr_t ip, in_port_t port,
paulo@0 108 off_t start, off_t stop);
paulo@0 109 void gt_transfer_close (GtTransfer *xfer, BOOL force_close);
paulo@0 110 void gt_transfer_status (GtTransfer *xfer, SourceStatus status,
paulo@0 111 char *text);
paulo@0 112
paulo@0 113 void gt_transfer_write (GtTransfer *xfer, Chunk *chunk,
paulo@0 114 unsigned char *segment, size_t len);
paulo@0 115
paulo@0 116 /*****************************************************************************/
paulo@0 117
paulo@0 118 void gt_transfer_set_tcpc (GtTransfer *xfer, TCPC *c);
paulo@0 119 void gt_transfer_set_chunk (GtTransfer *xfer, Chunk *chunk);
paulo@0 120
paulo@0 121 TCPC *gt_transfer_get_tcpc (GtTransfer *xfer);
paulo@0 122 Chunk *gt_transfer_get_chunk (GtTransfer *xfer);
paulo@0 123
paulo@0 124 struct gt_source *gt_transfer_get_source (GtTransfer *xfer);
paulo@0 125 void gt_transfer_set_length (GtTransfer *xfer, Chunk *chunk);
paulo@0 126
paulo@0 127 /*****************************************************************************/
paulo@0 128
paulo@0 129 void gt_http_connection_close (GtTransferType type, TCPC *c,
paulo@0 130 BOOL force_close);
paulo@0 131 TCPC *gt_http_connection_open (GtTransferType type, in_addr_t ip,
paulo@0 132 in_port_t port);
paulo@0 133 TCPC *gt_http_connection_lookup (GtTransferType type,
paulo@0 134 in_addr_t ip, in_port_t port);
paulo@0 135 size_t gt_http_connection_length (GtTransferType type, in_addr_t ip);
paulo@0 136
paulo@0 137 /*****************************************************************************/
paulo@0 138
paulo@0 139 BOOL gt_transfer_set_request (GtTransfer *xfer, char *request);
paulo@0 140 FILE *gt_transfer_open_request (GtTransfer *xfer, int *code);
paulo@0 141
paulo@0 142 /*****************************************************************************/
paulo@0 143
paulo@0 144 void gt_download (Chunk *chunk, unsigned char *segment, size_t len);
paulo@0 145 void gt_upload (Chunk *chunk, unsigned char *segment, size_t len);
paulo@0 146
paulo@0 147 /*****************************************************************************/
paulo@0 148
paulo@0 149 void gt_download_cancel (Chunk *chunk, void *data);
paulo@0 150 void gt_upload_cancel (Chunk *chunk, void *data);
paulo@0 151
paulo@0 152 /*****************************************************************************/
paulo@0 153
paulo@0 154 BOOL gt_chunk_suspend (Chunk *chunk, Transfer *transfer, void *data);
paulo@0 155 BOOL gt_chunk_resume (Chunk *chunk, Transfer *transfer, void *data);
paulo@0 156
paulo@0 157 /*****************************************************************************/
paulo@0 158
paulo@0 159 #endif /* GIFT_GT_XFER_OBJ_H_ */