~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to libtransmission/http.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2008-01-05 09:16:52 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20080105091652-8cf0z4rb3pu8d6jt
Tags: upstream-1.00
ImportĀ upstreamĀ versionĀ 1.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * $Id: http.h 2568 2007-07-31 01:21:10Z charles $
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
 
*/
33
 
int         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 */
37
 
int         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
 
#define TR_HTTP_STATUS_FAIL_CLIENT( st )    ( 400 <= (st) && 499 >= (st) )
43
 
#define TR_HTTP_STATUS_FAIL_SERVER( st )    ( 500 <= (st) && 599 >= (st) )
44
 
 
45
 
/*
46
 
  Parse an HTTP request or response, locating specified headers and
47
 
  the body.  The length of the body will be len - ( body - data ).
48
 
*/
49
 
typedef struct { const char * name; const char * data; int len; }
50
 
tr_http_header_t;
51
 
char *      tr_httpParse( const char * data, int len, tr_http_header_t *headers );
52
 
 
53
 
int         tr_httpIsUrl( const char *, int );
54
 
int         tr_httpParseUrl( const char *, int, char **, int *, char ** );
55
 
 
56
 
/* fetch a file via HTTP from a standard http:// url */
57
 
typedef struct tr_http_s tr_http_t;
58
 
#define TR_HTTP_GET             1
59
 
#define TR_HTTP_POST            2
60
 
#define TR_HTTP_M_POST          3
61
 
tr_http_t   * tr_httpClient( int, const char *, int, const char *, ... );
62
 
tr_http_t   * tr_httpClientUrl( int, const char *, ... );
63
 
/* only add headers or body before first pulse */
64
 
void          tr_httpAddHeader( tr_http_t *, const char *, const char * );
65
 
void          tr_httpAddBody( tr_http_t *, const char *, ... );
66
 
void          tr_httpGetHeaders( tr_http_t *, const char **, int * );
67
 
void          tr_httpGetBody( tr_http_t *, const char **, int * );
68
 
tr_tristate_t tr_httpPulse( tr_http_t *, const char **, int * );
69
 
char        * tr_httpWhatsMyAddress( tr_http_t * );
70
 
void          tr_httpClose( tr_http_t * );
71
 
 
72
 
#endif