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