]> git.sesse.net Git - vlc/commitdiff
core: Move httpcookies.c to core
authorAntti Ajanki <antti.ajanki@iki.fi>
Tue, 16 Sep 2014 18:24:40 +0000 (21:24 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 16 Sep 2014 20:31:30 +0000 (23:31 +0300)
Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
include/vlc_http.h
modules/access/Makefile.am
modules/access/http.c
modules/access/httpcookies.h [deleted file]
src/Makefile.am
src/libvlccore.sym
src/misc/httpcookies.c [moved from modules/access/httpcookies.c with 97% similarity]

index ddde13efed1e11a15632f17e1da4437f59750988..47e3139e275d89f040da31cf872fb0ccb38c99fd 100644 (file)
@@ -33,6 +33,9 @@
  * HTTP clients.
  */
 
+#include <vlc_url.h>
+#include <vlc_arrays.h>
+
 /* RFC 2617: Basic and Digest Access Authentication */
 typedef struct http_auth_t
 {
@@ -64,4 +67,30 @@ VLC_API char *http_auth_FormatAuthorizationHeader
               const char *, const char *,
               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 */
index 4ef79bf386dd7b702359ceff7b8ff1980549118c..f0ad4f455d766b9b5259301486ecf9f142e353e3 100644 (file)
@@ -356,7 +356,7 @@ libftp_plugin_la_SOURCES = access/ftp.c
 libftp_plugin_la_LIBADD = $(SOCKET_LIBS)
 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)
 if HAVE_ZLIB
 libhttp_plugin_la_LIBADD += -lz
index 9afca9feb764bd66fcabe1af273c575a98d73ae1..37df2337967db389a1414ab8de20fcf3ad8daa70 100644 (file)
@@ -47,7 +47,6 @@
 #include <vlc_input.h>
 #include <vlc_md5.h>
 #include <vlc_http.h>
-#include "httpcookies.h"
 
 #ifdef HAVE_ZLIB_H
 #   include <zlib.h>
@@ -186,12 +185,12 @@ struct access_sys_t
     bool b_persist;
     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,
-                            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 );
@@ -229,7 +228,7 @@ static int Open( vlc_object_t *p_this )
  * @return vlc error codes
  */
 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_sys_t *p_sys;
@@ -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 */
     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
         p_sys->cookies = NULL;
 
@@ -597,7 +596,7 @@ error:
     Disconnect( p_access );
     vlc_tls_Delete( p_sys->p_creds );
 
-    http_cookies_destroy( p_sys->cookies );
+    vlc_http_cookies_destroy( p_sys->cookies );
 
 #ifdef HAVE_ZLIB_H
     inflateEnd( &p_sys->inflate.stream );
@@ -633,7 +632,7 @@ static void Close( vlc_object_t *p_this )
     Disconnect( p_access );
     vlc_tls_Delete( p_sys->p_creds );
 
-    http_cookies_destroy( p_sys->cookies );
+    vlc_http_cookies_destroy( p_sys->cookies );
 
 #ifdef HAVE_ZLIB_H
     inflateEnd( &p_sys->inflate.stream );
@@ -1173,7 +1172,7 @@ static int Request( access_t *p_access, uint64_t i_tell )
     /* 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 )
         {
             msg_Dbg( p_access, "Sending Cookie %s", psz_cookiestring );
@@ -1476,7 +1475,7 @@ static int Request( access_t *p_access, uint64_t i_tell )
         {
             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 );
                 else
                     msg_Dbg( p_access, "Rejected Cookie: %s", p );
diff --git a/modules/access/httpcookies.h b/modules/access/httpcookies.h
deleted file mode 100644 (file)
index bf73191..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*****************************************************************************
- * 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
index cdddc8dafcfab7b37592b5861a81ea41d62489bd..9111e73fe5f6a017c5d460c89b2fbe184576d80a 100644 (file)
@@ -480,6 +480,7 @@ SOURCES_libvlc_common = \
        misc/filter.c \
        misc/filter_chain.c \
        misc/http_auth.c \
+       misc/httpcookies.c \
        misc/fingerprinter.c \
        misc/text_style.c \
        misc/subpicture.c \
index 2808f5f9bec6e2ee412cbd937fb41ff1f008f61c..6bab76093077d51bd2f9446e97012922e2044f9b 100644 (file)
@@ -144,6 +144,10 @@ http_auth_Reset
 http_auth_ParseWwwAuthenticateHeader
 http_auth_ParseAuthenticationInfoHeader
 http_auth_FormatAuthorizationHeader
+vlc_http_cookies_new
+vlc_http_cookies_destroy
+vlc_http_cookies_append
+vlc_http_cookies_for_url
 httpd_ClientIP
 httpd_FileDelete
 httpd_FileNew
similarity index 97%
rename from modules/access/httpcookies.c
rename to src/misc/httpcookies.c
index 2dc0a6b6bc511aa0f5603ef9fb8e13c10d430978..9eccbe74860ddf2602a9ba583f63f7de4f1a1349 100644 (file)
@@ -33,7 +33,7 @@
 #include <vlc_common.h>
 #include <vlc_messages.h>
 #include <vlc_strings.h>
-#include "httpcookies.h"
+#include <vlc_http.h>
 
 typedef struct http_cookie_t
 {
@@ -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 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();
 }
 
-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 )
         return;
@@ -74,7 +74,7 @@ void http_cookies_destroy( http_cookie_jar_t * 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;
 
@@ -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;
     char *psz_cookiebuf = NULL;