vlc_httpd.h 5.48 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlc_httpd.h: builtin HTTP/RTSP server.
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2004-2006 VLC authors and VideoLAN
5
 * $Id$
6 7 8
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

24 25
#ifndef VLC_HTTPD_H
#define VLC_HTTPD_H 1
26

27 28
/**
 * \file
29
 * HTTP/RTSP server API.
30 31
 */

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
enum
{
    HTTPD_MSG_NONE,

    /* answer */
    HTTPD_MSG_ANSWER,

    /* http request */
    HTTPD_MSG_GET,
    HTTPD_MSG_HEAD,
    HTTPD_MSG_POST,

    /* rtsp request */
    HTTPD_MSG_OPTIONS,
    HTTPD_MSG_DESCRIBE,
    HTTPD_MSG_SETUP,
    HTTPD_MSG_PLAY,
    HTTPD_MSG_PAUSE,
50
    HTTPD_MSG_GETPARAMETER,
51 52 53 54 55 56 57 58 59
    HTTPD_MSG_TEARDOWN,

    /* just to track the count of MSG */
    HTTPD_MSG_MAX
};

enum
{
    HTTPD_PROTO_NONE,
60 61 62
    HTTPD_PROTO_HTTP,  /* HTTP/1.x */
    HTTPD_PROTO_RTSP,  /* RTSP/1.x */
    HTTPD_PROTO_HTTP0, /* HTTP/0.x */
63 64
};

65 66 67 68 69 70 71 72 73
typedef struct httpd_host_t   httpd_host_t;
typedef struct httpd_client_t httpd_client_t;
/* create a new host */
VLC_API httpd_host_t *vlc_http_HostNew( vlc_object_t * ) VLC_USED;
VLC_API httpd_host_t *vlc_https_HostNew( vlc_object_t * ) VLC_USED;
VLC_API httpd_host_t *vlc_rtsp_HostNew( vlc_object_t * ) VLC_USED;
/* delete a host */
VLC_API void httpd_HostDelete( httpd_host_t * );

74 75 76 77 78 79
typedef struct
{
    char * name;
    char * value;
} httpd_header;

80
typedef struct httpd_message_t
81 82 83
{
    httpd_client_t *cl; /* NULL if not throught a connection e vlc internal */

84 85 86
    uint8_t i_type;
    uint8_t i_proto;
    uint8_t i_version;
87 88 89 90 91 92

    /* for an answer */
    int     i_status;

    /* for a query */
    char    *psz_url;
93 94 95
    /* FIXME find a clean way to handle GET(psz_args)
       and POST(body) through the same code */
    uint8_t *psz_args;
96 97

    /* options */
98 99
    size_t       i_headers;
    httpd_header *p_headers;
100 101 102 103 104 105

    /* body */
    int64_t i_body_offset;
    int     i_body;
    uint8_t *p_body;

106
} httpd_message_t;
107

108 109 110
typedef struct httpd_url_t      httpd_url_t;
typedef struct httpd_callback_sys_t httpd_callback_sys_t;
typedef int    (*httpd_callback_t)( httpd_callback_sys_t *, httpd_client_t *, httpd_message_t *answer, const httpd_message_t *query );
111
/* register a new url */
112
VLC_API httpd_url_t * httpd_UrlNew( httpd_host_t *, const char *psz_url, const char *psz_user, const char *psz_password ) VLC_USED;
113
/* register callback on a url */
114
VLC_API int httpd_UrlCatch( httpd_url_t *, int i_msg, httpd_callback_t, httpd_callback_sys_t * );
115
/* delete a url */
116
VLC_API void httpd_UrlDelete( httpd_url_t * );
117

118 119
VLC_API char* httpd_ClientIP( const httpd_client_t *cl, char *, int * );
VLC_API char* httpd_ServerIP( const httpd_client_t *cl, char *, int * );
120 121 122

/* High level */

123 124 125
typedef struct httpd_file_t     httpd_file_t;
typedef struct httpd_file_sys_t httpd_file_sys_t;
typedef int (*httpd_file_callback_t)( httpd_file_sys_t *, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
126
VLC_API httpd_file_t * httpd_FileNew( httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const char *psz_password, httpd_file_callback_t pf_fill, httpd_file_sys_t * ) VLC_USED;
127
VLC_API httpd_file_sys_t * httpd_FileDelete( httpd_file_t * );
128 129


130
typedef struct httpd_handler_t  httpd_handler_t;
131 132 133
typedef int (*httpd_handler_callback_t)( void *, httpd_handler_t *, char *psz_url, uint8_t *psz_request, int i_type, uint8_t *p_in, int i_in, char *psz_remote_addr, char *psz_remote_host, uint8_t **pp_data, int *pi_data );
VLC_API httpd_handler_t * httpd_HandlerNew( httpd_host_t *, const char *psz_url, const char *psz_user, const char *psz_password, httpd_handler_callback_t pf_fill, void * ) VLC_USED;
VLC_API void * httpd_HandlerDelete( httpd_handler_t * );
134

135
typedef struct httpd_redirect_t httpd_redirect_t;
136
VLC_API httpd_redirect_t * httpd_RedirectNew( httpd_host_t *, const char *psz_url_dst, const char *psz_url_src ) VLC_USED;
137
VLC_API void httpd_RedirectDelete( httpd_redirect_t * );
138 139


140
typedef struct httpd_stream_t httpd_stream_t;
141
VLC_API httpd_stream_t * httpd_StreamNew( httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const char *psz_password ) VLC_USED;
142 143
VLC_API void httpd_StreamDelete( httpd_stream_t * );
VLC_API int httpd_StreamHeader( httpd_stream_t *, uint8_t *p_data, int i_data );
144
VLC_API int httpd_StreamSend( httpd_stream_t *, const block_t *p_block );
145
VLC_API int httpd_StreamSetHTTPHeaders(httpd_stream_t *, const httpd_header *, size_t);
146 147

/* Msg functions facilities */
148
VLC_API void httpd_MsgAdd( httpd_message_t *, const char *psz_name, const char *psz_value, ... ) VLC_FORMAT( 3, 4 );
149
/* return "" if not found. The string is not allocated */
150
VLC_API const char * httpd_MsgGet( const httpd_message_t *, const char *psz_name );
151 152

#endif /* _VLC_HTTPD_H */