comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bd266e0ae7f6
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 */
16
17 #ifndef GIFT_GT_XFER_OBJ_H_
18 #define GIFT_GT_XFER_OBJ_H_
19
20 /*****************************************************************************/
21
22 #define HTTP_DEBUG gt_config_get_int("http/debug=0")
23
24 #define HTTP_MAX_PERUSER_UPLOAD_CONNS \
25 gt_config_get_int("http/max_peruser_upload_connections=5")
26
27 /*****************************************************************************/
28
29 struct gt_source;
30
31 typedef enum gt_transfer_type
32 {
33 GT_TRANSFER_UPLOAD,
34 GT_TRANSFER_DOWNLOAD,
35 } GtTransferType;
36
37 typedef void (*GtTransferCB) (Chunk *chunk, unsigned char *data, size_t len);
38
39 typedef struct gt_transfer
40 {
41 TCPC *c; /* see gt_transfer_ref */
42 Chunk *chunk; /* ... */
43 Source *source; /* source for this transfer */
44
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 */
49
50 Dataset *header; /* HTTP headers */
51 int code; /* HTTP status code last seen */
52
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 */
57
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 */
62
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 */
71
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 */
77
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 */
81
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 */
86
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 */
95
96 unsigned char shared : 1; /* see interface proto docs */
97 } GtTransfer;
98
99 /*****************************************************************************/
100
101 #include "gt_http_client.h"
102 #include "gt_http_server.h"
103
104 /*****************************************************************************/
105
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);
112
113 void gt_transfer_write (GtTransfer *xfer, Chunk *chunk,
114 unsigned char *segment, size_t len);
115
116 /*****************************************************************************/
117
118 void gt_transfer_set_tcpc (GtTransfer *xfer, TCPC *c);
119 void gt_transfer_set_chunk (GtTransfer *xfer, Chunk *chunk);
120
121 TCPC *gt_transfer_get_tcpc (GtTransfer *xfer);
122 Chunk *gt_transfer_get_chunk (GtTransfer *xfer);
123
124 struct gt_source *gt_transfer_get_source (GtTransfer *xfer);
125 void gt_transfer_set_length (GtTransfer *xfer, Chunk *chunk);
126
127 /*****************************************************************************/
128
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);
136
137 /*****************************************************************************/
138
139 BOOL gt_transfer_set_request (GtTransfer *xfer, char *request);
140 FILE *gt_transfer_open_request (GtTransfer *xfer, int *code);
141
142 /*****************************************************************************/
143
144 void gt_download (Chunk *chunk, unsigned char *segment, size_t len);
145 void gt_upload (Chunk *chunk, unsigned char *segment, size_t len);
146
147 /*****************************************************************************/
148
149 void gt_download_cancel (Chunk *chunk, void *data);
150 void gt_upload_cancel (Chunk *chunk, void *data);
151
152 /*****************************************************************************/
153
154 BOOL gt_chunk_suspend (Chunk *chunk, Transfer *transfer, void *data);
155 BOOL gt_chunk_resume (Chunk *chunk, Transfer *transfer, void *data);
156
157 /*****************************************************************************/
158
159 #endif /* GIFT_GT_XFER_OBJ_H_ */