Commit 18b4a0bf authored by Antti Ajanki's avatar Antti Ajanki Committed by Rémi Denis-Courmont

core: Move httpcookies.c to core

Signed-off-by: Rémi Denis-Courmont's avatarRémi Denis-Courmont <remi@remlab.net>
parent 6e82ebed
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
* HTTP clients. * HTTP clients.
*/ */
#include <vlc_url.h>
#include <vlc_arrays.h>
/* RFC 2617: Basic and Digest Access Authentication */ /* RFC 2617: Basic and Digest Access Authentication */
typedef struct http_auth_t typedef struct http_auth_t
{ {
...@@ -64,4 +67,30 @@ VLC_API char *http_auth_FormatAuthorizationHeader ...@@ -64,4 +67,30 @@ VLC_API char *http_auth_FormatAuthorizationHeader
const char *, const char *, const char *, const char *,
const char *, const char * ) VLC_USED; const char *, const char * ) VLC_USED;
/* RFC 6265: cookies */
typedef struct vlc_array_t vlc_http_cookie_jar_t;
VLC_API vlc_http_cookie_jar_t * vlc_http_cookies_new( void ) VLC_USED;
VLC_API void vlc_http_cookies_destroy( vlc_http_cookie_jar_t * p_jar );
/**
* Parse a value of an incoming Set-Cookie header and append the
* cookie to the cookie jar if appropriate.
*
* @param p_jar cookie jar object
* @param psz_cookie_header value of Set-Cookie
* @return true, if the cookie was added, false otherwise
*/
VLC_API bool vlc_http_cookies_append( vlc_http_cookie_jar_t * p_jar, const char * psz_cookie_header, const vlc_url_t * p_url );
/**
* Returns a cookie value that match the given URL.
*
* @params p_jar a cookie jar
* @params p_url the URL for which the cookies are returned
* @return A string consisting of semicolon-separated cookie NAME=VALUE pairs.
*/
VLC_API char *vlc_http_cookies_for_url( vlc_http_cookie_jar_t * p_jar, const vlc_url_t * p_url );
#endif /* VLC_HTTP_H */ #endif /* VLC_HTTP_H */
...@@ -356,7 +356,7 @@ libftp_plugin_la_SOURCES = access/ftp.c ...@@ -356,7 +356,7 @@ libftp_plugin_la_SOURCES = access/ftp.c
libftp_plugin_la_LIBADD = $(SOCKET_LIBS) libftp_plugin_la_LIBADD = $(SOCKET_LIBS)
access_LTLIBRARIES += libftp_plugin.la access_LTLIBRARIES += libftp_plugin.la
libhttp_plugin_la_SOURCES = access/http.c access/httpcookies.h access/httpcookies.c libhttp_plugin_la_SOURCES = access/http.c
libhttp_plugin_la_LIBADD = $(SOCKET_LIBS) libhttp_plugin_la_LIBADD = $(SOCKET_LIBS)
if HAVE_ZLIB if HAVE_ZLIB
libhttp_plugin_la_LIBADD += -lz libhttp_plugin_la_LIBADD += -lz
......
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include <vlc_input.h> #include <vlc_input.h>
#include <vlc_md5.h> #include <vlc_md5.h>
#include <vlc_http.h> #include <vlc_http.h>
#include "httpcookies.h"
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
# include <zlib.h> # include <zlib.h>
...@@ -186,12 +185,12 @@ struct access_sys_t ...@@ -186,12 +185,12 @@ struct access_sys_t
bool b_persist; bool b_persist;
bool b_has_size; bool b_has_size;
http_cookie_jar_t * cookies; vlc_http_cookie_jar_t * cookies;
}; };
/* */ /* */
static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access, static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
unsigned i_redirect, http_cookie_jar_t *cookies ); unsigned i_redirect, vlc_http_cookie_jar_t *cookies );
/* */ /* */
static ssize_t Read( access_t *, uint8_t *, size_t ); static ssize_t Read( access_t *, uint8_t *, size_t );
...@@ -229,7 +228,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -229,7 +228,7 @@ static int Open( vlc_object_t *p_this )
* @return vlc error codes * @return vlc error codes
*/ */
static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access, static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
unsigned i_redirect, http_cookie_jar_t *cookies ) unsigned i_redirect, vlc_http_cookie_jar_t *cookies )
{ {
access_t *p_access = (access_t*)p_this; access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys; access_sys_t *p_sys;
...@@ -279,7 +278,7 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access, ...@@ -279,7 +278,7 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
/* Only forward an store cookies if the corresponding option is activated */ /* Only forward an store cookies if the corresponding option is activated */
if( var_CreateGetBool( p_access, "http-forward-cookies" ) ) if( var_CreateGetBool( p_access, "http-forward-cookies" ) )
p_sys->cookies = (cookies != NULL) ? cookies : http_cookies_new(); p_sys->cookies = (cookies != NULL) ? cookies : vlc_http_cookies_new();
else else
p_sys->cookies = NULL; p_sys->cookies = NULL;
...@@ -597,7 +596,7 @@ error: ...@@ -597,7 +596,7 @@ error:
Disconnect( p_access ); Disconnect( p_access );
vlc_tls_Delete( p_sys->p_creds ); vlc_tls_Delete( p_sys->p_creds );
http_cookies_destroy( p_sys->cookies ); vlc_http_cookies_destroy( p_sys->cookies );
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
inflateEnd( &p_sys->inflate.stream ); inflateEnd( &p_sys->inflate.stream );
...@@ -633,7 +632,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -633,7 +632,7 @@ static void Close( vlc_object_t *p_this )
Disconnect( p_access ); Disconnect( p_access );
vlc_tls_Delete( p_sys->p_creds ); vlc_tls_Delete( p_sys->p_creds );
http_cookies_destroy( p_sys->cookies ); vlc_http_cookies_destroy( p_sys->cookies );
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
inflateEnd( &p_sys->inflate.stream ); inflateEnd( &p_sys->inflate.stream );
...@@ -1173,7 +1172,7 @@ static int Request( access_t *p_access, uint64_t i_tell ) ...@@ -1173,7 +1172,7 @@ static int Request( access_t *p_access, uint64_t i_tell )
/* Cookies */ /* Cookies */
if( p_sys->cookies ) if( p_sys->cookies )
{ {
char * psz_cookiestring = http_cookies_for_url( p_sys->cookies, &p_sys->url ); char * psz_cookiestring = vlc_http_cookies_for_url( p_sys->cookies, &p_sys->url );
if ( psz_cookiestring ) if ( psz_cookiestring )
{ {
msg_Dbg( p_access, "Sending Cookie %s", psz_cookiestring ); msg_Dbg( p_access, "Sending Cookie %s", psz_cookiestring );
...@@ -1476,7 +1475,7 @@ static int Request( access_t *p_access, uint64_t i_tell ) ...@@ -1476,7 +1475,7 @@ static int Request( access_t *p_access, uint64_t i_tell )
{ {
if( p_sys->cookies ) if( p_sys->cookies )
{ {
if ( http_cookies_append( p_sys->cookies, p, &p_sys->url ) ) if ( vlc_http_cookies_append( p_sys->cookies, p, &p_sys->url ) )
msg_Dbg( p_access, "Accepting Cookie: %s", p ); msg_Dbg( p_access, "Accepting Cookie: %s", p );
else else
msg_Dbg( p_access, "Rejected Cookie: %s", p ); msg_Dbg( p_access, "Rejected Cookie: %s", p );
......
/*****************************************************************************
* httpcookies.h: HTTP cookie utilities
*****************************************************************************
* Copyright (C) 2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Antti Ajanki <antti.ajanki@iki.fi>
*
* 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
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* 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.
*****************************************************************************/
#ifndef HTTPCOOKIES_H_
#define HTTPCOOKIES_H_ 1
#ifdef __cplusplus
extern "C" {
#endif
#include <vlc_url.h>
#include <vlc_arrays.h>
typedef struct vlc_array_t http_cookie_jar_t;
http_cookie_jar_t * http_cookies_new( void );
void http_cookies_destroy( http_cookie_jar_t * p_jar );
/**
* Parse a value of an incoming Set-Cookie header and append the
* cookie to the cookie jar if appropriate.
*
* @param p_jar cookie jar object
* @param psz_cookie_header value of Set-Cookie
* @return true, if the cookie was added, false otherwise
*/
bool http_cookies_append( http_cookie_jar_t * p_jar, const char * psz_cookie_header, const vlc_url_t * p_url );
/**
* Returns a cookie value that match the given URL.
*
* @params p_jar a cookie jar
* @params p_url the URL for which the cookies are returned
* @return A string consisting of semicolon-separated cookie NAME=VALUE pairs.
*/
char *http_cookies_for_url( http_cookie_jar_t * p_jar, const vlc_url_t * p_url );
#ifdef __cplusplus
}
#endif
#endif
...@@ -480,6 +480,7 @@ SOURCES_libvlc_common = \ ...@@ -480,6 +480,7 @@ SOURCES_libvlc_common = \
misc/filter.c \ misc/filter.c \
misc/filter_chain.c \ misc/filter_chain.c \
misc/http_auth.c \ misc/http_auth.c \
misc/httpcookies.c \
misc/fingerprinter.c \ misc/fingerprinter.c \
misc/text_style.c \ misc/text_style.c \
misc/subpicture.c \ misc/subpicture.c \
......
...@@ -144,6 +144,10 @@ http_auth_Reset ...@@ -144,6 +144,10 @@ http_auth_Reset
http_auth_ParseWwwAuthenticateHeader http_auth_ParseWwwAuthenticateHeader
http_auth_ParseAuthenticationInfoHeader http_auth_ParseAuthenticationInfoHeader
http_auth_FormatAuthorizationHeader http_auth_FormatAuthorizationHeader
vlc_http_cookies_new
vlc_http_cookies_destroy
vlc_http_cookies_append
vlc_http_cookies_for_url
httpd_ClientIP httpd_ClientIP
httpd_FileDelete httpd_FileDelete
httpd_FileNew httpd_FileNew
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_messages.h> #include <vlc_messages.h>
#include <vlc_strings.h> #include <vlc_strings.h>
#include "httpcookies.h" #include <vlc_http.h>
typedef struct http_cookie_t typedef struct http_cookie_t
{ {
...@@ -58,12 +58,12 @@ static bool cookie_path_matches( const http_cookie_t * cookie, const char *path ...@@ -58,12 +58,12 @@ static bool cookie_path_matches( const http_cookie_t * cookie, const char *path
static bool cookie_domain_is_public_suffix( const char *domain ); static bool cookie_domain_is_public_suffix( const char *domain );
static char * cookie_default_path( const char *request_path ); static char * cookie_default_path( const char *request_path );
http_cookie_jar_t * http_cookies_new() vlc_http_cookie_jar_t * vlc_http_cookies_new()
{ {
return vlc_array_new(); return vlc_array_new();
} }
void http_cookies_destroy( http_cookie_jar_t * p_jar ) void vlc_http_cookies_destroy( vlc_http_cookie_jar_t * p_jar )
{ {
if ( !p_jar ) if ( !p_jar )
return; return;
...@@ -74,7 +74,7 @@ void http_cookies_destroy( http_cookie_jar_t * p_jar ) ...@@ -74,7 +74,7 @@ void http_cookies_destroy( http_cookie_jar_t * p_jar )
vlc_array_destroy( p_jar ); vlc_array_destroy( p_jar );
} }
bool http_cookies_append( http_cookie_jar_t * p_jar, const char * psz_cookie_header, const vlc_url_t *p_url ) bool vlc_http_cookies_append( vlc_http_cookie_jar_t * p_jar, const char * psz_cookie_header, const vlc_url_t *p_url )
{ {
int i; int i;
...@@ -111,7 +111,7 @@ bool http_cookies_append( http_cookie_jar_t * p_jar, const char * psz_cookie_hea ...@@ -111,7 +111,7 @@ bool http_cookies_append( http_cookie_jar_t * p_jar, const char * psz_cookie_hea
} }
char *http_cookies_for_url( http_cookie_jar_t * p_jar, const vlc_url_t * p_url ) char *vlc_http_cookies_for_url( vlc_http_cookie_jar_t * p_jar, const vlc_url_t * p_url )
{ {
int i; int i;
char *psz_cookiebuf = NULL; char *psz_cookiebuf = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment