source: trunk/libtransmission/http.h @ 920

Last change on this file since 920 was 920, checked in by joshe, 15 years ago

Merge nat-traversal branch to trunk.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.0 KB
Line 
1/******************************************************************************
2 * $Id: http.h 920 2006-09-25 18:37:45Z joshe $
3 *
4 * Copyright (c) 2006 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TR_HTTP_H
26#define TR_HTTP_H 1
27
28/*
29  Parse an HTTP request header to find the method, uri, and version.
30  The version will be 11, 10, or -1 on parse error.  The method and/or
31  uri pointers may be NULL if the caller is not interested.
32*/
33int         tr_httpRequestType( const char * data, int len,
34                            char ** method, char ** uri );
35
36/* Return the HTTP status code for the response, or -1 for parse error */
37int         tr_httpResponseCode( const char * data, int len );
38
39#define TR_HTTP_STATUS_OK( st )       ( 200 <= (st) && 299 >= (st) )
40#define TR_HTTP_STATUS_REDIRECT( st ) ( 300 <= (st) && 399 >= (st) )
41#define TR_HTTP_STATUS_FAIL( st )     ( 400 <= (st) && 599 >= (st) )
42
43/*
44  Parse an HTTP request or response, locating specified headers and
45  the body.  The length of the body will be len - ( body - data ).
46*/
47typedef struct { const char * name; const char * data; int len; }
48tr_http_header_t;
49char *      tr_httpParse( const char * data, int len, tr_http_header_t *headers );
50
51int         tr_httpParseUrl( const char *, int, char **, int *, char ** );
52
53/* fetch a file via HTTP from a standard http:// url */
54typedef struct tr_http_s tr_http_t;
55#define TR_HTTP_GET             1
56#define TR_HTTP_POST            2
57#define TR_HTTP_M_POST          3
58tr_http_t   * tr_httpClient( int, const char *, int, const char *, ... )
59              PRINTF( 4, 5 );
60/* only add headers or body before first pulse */
61void          tr_httpAddHeader( tr_http_t *, const char *, const char * );
62void          tr_httpAddBody( tr_http_t *, const char *, ... ) PRINTF( 2, 3 );
63tr_tristate_t tr_httpPulse( tr_http_t *, const char **, int * );
64char        * tr_httpWhatsMyAddress( tr_http_t * );
65void          tr_httpClose( tr_http_t * );
66
67#endif
Note: See TracBrowser for help on using the repository browser.