paulo@0: /* paulo@0: * $Id: gt_xfer_obj.h,v 1.23 2004/05/05 10:30:12 hipnod Exp $ paulo@0: * paulo@0: * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #ifndef GIFT_GT_XFER_OBJ_H_ paulo@0: #define GIFT_GT_XFER_OBJ_H_ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #define HTTP_DEBUG gt_config_get_int("http/debug=0") paulo@0: paulo@0: #define HTTP_MAX_PERUSER_UPLOAD_CONNS \ paulo@0: gt_config_get_int("http/max_peruser_upload_connections=5") paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: struct gt_source; paulo@0: paulo@0: typedef enum gt_transfer_type paulo@0: { paulo@0: GT_TRANSFER_UPLOAD, paulo@0: GT_TRANSFER_DOWNLOAD, paulo@0: } GtTransferType; paulo@0: paulo@0: typedef void (*GtTransferCB) (Chunk *chunk, unsigned char *data, size_t len); paulo@0: paulo@0: typedef struct gt_transfer paulo@0: { paulo@0: TCPC *c; /* see gt_transfer_ref */ paulo@0: Chunk *chunk; /* ... */ paulo@0: Source *source; /* source for this transfer */ paulo@0: paulo@0: GtTransferCB callback; /* where to report progress paulo@0: * see gt_download and gt_upload in paulo@0: * xfer.c */ paulo@0: GtTransferType type; /* which direction this transfer is in */ paulo@0: paulo@0: Dataset *header; /* HTTP headers */ paulo@0: int code; /* HTTP status code last seen */ paulo@0: paulo@0: in_addr_t ip; /* address of the user who is either paulo@0: * leeching our node or is being leeched paulo@0: * by it */ paulo@0: in_port_t port; /* used only by the client routines */ paulo@0: paulo@0: char *command; /* request operator (GET, PUSH, ...) */ paulo@0: char *request; /* exact request operand, url encoded */ paulo@0: char *version; /* HTTP version resembling HTTP/1.1 */ paulo@0: char *request_path; /* url decoded copy of request */ paulo@0: paulo@0: char *content_type; /* Content-Type: send from server or paulo@0: * to client */ paulo@0: char *content_urns; /* X-Gnutella-Content-URN: if requested paulo@0: * by urn */ paulo@0: BOOL transmitted_hdrs; /* transfer completed reading HTTP paulo@0: * headers */ paulo@0: off_t remaining_len; /* size of content remaining to be paulo@0: * read */ paulo@0: paulo@0: off_t start; /* range begin */ paulo@0: off_t stop; /* range stop. 0 is an exception which paulo@0: * will be translated to the total file paulo@0: * size as soon as known */ paulo@0: timer_id header_timer; /* timeout for reading complete header */ paulo@0: paulo@0: timer_id detach_timer; /* fires to detach xfer and chunk */ paulo@0: SourceStatus detach_status; /* next status if detach_timer hits */ paulo@0: char *detach_msgtxt; /* next msg if detach_timer hits */ paulo@0: paulo@0: /* used by the server routines for uploading */ paulo@0: FILE *f; /* used only by the server routines */ paulo@0: Share *share_authd; /* hack for the new sharing paulo@0: * interface...ugh */ paulo@0: paulo@0: char *open_path; /* path opened by the server */ paulo@0: off_t open_path_size; /* size of the file on disk described paulo@0: * by open_path */ paulo@0: char *hash; /* openft's hash to deliever to the paulo@0: * interface protocol when we register paulo@0: * this upload */ paulo@0: unsigned int queue_pos; /* position in upload queue */ paulo@0: unsigned int queue_ttl; /* size of queue */ paulo@0: paulo@0: unsigned char shared : 1; /* see interface proto docs */ paulo@0: } GtTransfer; paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #include "gt_http_client.h" paulo@0: #include "gt_http_server.h" paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: GtTransfer *gt_transfer_new (GtTransferType type, Source *source, paulo@0: in_addr_t ip, in_port_t port, paulo@0: off_t start, off_t stop); paulo@0: void gt_transfer_close (GtTransfer *xfer, BOOL force_close); paulo@0: void gt_transfer_status (GtTransfer *xfer, SourceStatus status, paulo@0: char *text); paulo@0: paulo@0: void gt_transfer_write (GtTransfer *xfer, Chunk *chunk, paulo@0: unsigned char *segment, size_t len); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_transfer_set_tcpc (GtTransfer *xfer, TCPC *c); paulo@0: void gt_transfer_set_chunk (GtTransfer *xfer, Chunk *chunk); paulo@0: paulo@0: TCPC *gt_transfer_get_tcpc (GtTransfer *xfer); paulo@0: Chunk *gt_transfer_get_chunk (GtTransfer *xfer); paulo@0: paulo@0: struct gt_source *gt_transfer_get_source (GtTransfer *xfer); paulo@0: void gt_transfer_set_length (GtTransfer *xfer, Chunk *chunk); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_http_connection_close (GtTransferType type, TCPC *c, paulo@0: BOOL force_close); paulo@0: TCPC *gt_http_connection_open (GtTransferType type, in_addr_t ip, paulo@0: in_port_t port); paulo@0: TCPC *gt_http_connection_lookup (GtTransferType type, paulo@0: in_addr_t ip, in_port_t port); paulo@0: size_t gt_http_connection_length (GtTransferType type, in_addr_t ip); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: BOOL gt_transfer_set_request (GtTransfer *xfer, char *request); paulo@0: FILE *gt_transfer_open_request (GtTransfer *xfer, int *code); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_download (Chunk *chunk, unsigned char *segment, size_t len); paulo@0: void gt_upload (Chunk *chunk, unsigned char *segment, size_t len); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_download_cancel (Chunk *chunk, void *data); paulo@0: void gt_upload_cancel (Chunk *chunk, void *data); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: BOOL gt_chunk_suspend (Chunk *chunk, Transfer *transfer, void *data); paulo@0: BOOL gt_chunk_resume (Chunk *chunk, Transfer *transfer, void *data); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #endif /* GIFT_GT_XFER_OBJ_H_ */