[vlc-commits] core: Move httpcookies.c to core

Antti Ajanki git at videolan.org
Tue Sep 16 22:32:19 CEST 2014


vlc | branch: master | Antti Ajanki <antti.ajanki at iki.fi> | Tue Sep 16 21:24:40 2014 +0300| [18b4a0bf96e1e220ed6c7f255dac526801a67595] | committer: Rémi Denis-Courmont

core: Move httpcookies.c to core

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=18b4a0bf96e1e220ed6c7f255dac526801a67595
---

 include/vlc_http.h                         |   29 +++++++++++++
 modules/access/Makefile.am                 |    2 +-
 modules/access/http.c                      |   17 ++++----
 modules/access/httpcookies.h               |   62 ----------------------------
 src/Makefile.am                            |    1 +
 src/libvlccore.sym                         |    4 ++
 {modules/access => src/misc}/httpcookies.c |   10 ++---
 7 files changed, 48 insertions(+), 77 deletions(-)

diff --git a/include/vlc_http.h b/include/vlc_http.h
index ddde13e..47e3139 100644
--- a/include/vlc_http.h
+++ b/include/vlc_http.h
@@ -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 */
diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am
index 4ef79bf..f0ad4f4 100644
--- a/modules/access/Makefile.am
+++ b/modules/access/Makefile.am
@@ -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
diff --git a/modules/access/http.c b/modules/access/http.c
index 9afca9f..37df233 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -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
index bf73191..0000000
--- a/modules/access/httpcookies.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*****************************************************************************
- * httpcookies.h: HTTP cookie utilities
- *****************************************************************************
- * Copyright (C) 2014 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Antti Ajanki <antti.ajanki at 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
diff --git a/src/Makefile.am b/src/Makefile.am
index cdddc8d..9111e73 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 2808f5f..6bab760 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -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
diff --git a/modules/access/httpcookies.c b/src/misc/httpcookies.c
similarity index 97%
rename from modules/access/httpcookies.c
rename to src/misc/httpcookies.c
index 2dc0a6b..9eccbe7 100644
--- a/modules/access/httpcookies.c
+++ b/src/misc/httpcookies.c
@@ -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;



More information about the vlc-commits mailing list