* httpd: fix a memory and thread leak.
[vlc.git] / include / httpd.h
index 0f13e05..5ab3791 100644 (file)
@@ -2,7 +2,7 @@
  * httpd.h
  *****************************************************************************
  * Copyright (C) 2001-2003 VideoLAN
- * $Id: httpd.h,v 1.1 2003/02/23 19:05:22 fenrir Exp $
+ * $Id: httpd.h,v 1.5 2003/06/25 15:50:52 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -30,7 +30,7 @@ typedef struct httpd_file_t     httpd_file_t;
 typedef httpd_file_t httpd_stream_t;
 
 typedef struct httpd_file_callback_args_t httpd_file_callback_args_t;
-typedef int (*httpd_file_callback)( httpd_file_callback_args_t *p_args, uint8_t **pp_data, int *pi_data );
+typedef int (*httpd_file_callback)( httpd_file_callback_args_t *p_args, uint8_t *p_request, int i_request, uint8_t **pp_data, int *pi_data );
 
 typedef struct httpd_sys_t httpd_sys_t;
 
@@ -47,7 +47,8 @@ struct httpd_t
     httpd_file_t   *(*pf_register_file)     ( httpd_t *,
                                               char *psz_file, char *psz_mime,
                                               char *psz_user, char *psz_password,
-                                              httpd_file_callback pf_fill,
+                                              httpd_file_callback pf_get,
+                                              httpd_file_callback pf_post,
                                               httpd_file_callback_args_t *p_args );
     void            (*pf_unregister_file)   ( httpd_t *, httpd_file_t * );
 
@@ -57,6 +58,9 @@ struct httpd_t
     int             (*pf_send_stream)       ( httpd_t *,
                                               httpd_stream_t *,
                                               uint8_t *, int );
+    int             (*pf_header_stream)     ( httpd_t *,
+                                              httpd_stream_t *,
+                                              uint8_t *, int );
     void            (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * );
 };
 
@@ -73,6 +77,7 @@ static inline httpd_t* httpd_Find( vlc_object_t *p_this, vlc_bool_t b_create )
     p_httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE );
     if( !p_httpd )
     {
+        msg_Info(p_this, "creating new http daemon" );
         if( !b_create )
         {
             return( NULL );
@@ -95,6 +100,7 @@ static inline httpd_t* httpd_Find( vlc_object_t *p_this, vlc_bool_t b_create )
         }
 
         vlc_object_yield( p_httpd );
+        vlc_object_attach( p_httpd, p_this->p_vlc );
     }
 
     return( p_httpd );
@@ -103,7 +109,13 @@ static inline httpd_t* httpd_Find( vlc_object_t *p_this, vlc_bool_t b_create )
 static inline void  httpd_Release( httpd_t *p_httpd )
 {
     vlc_object_release( p_httpd );
-}
-
 
+    if( p_httpd->i_refcount <= 0 )
+    {
+        msg_Info( p_httpd, "destroying unused httpd" );
+        vlc_object_detach( p_httpd );
+        module_Unneed( p_httpd, p_httpd->p_module );
+        vlc_object_destroy( p_httpd );
+    }
+}