]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/dump.c
access_filter_record: use key-action
[vlc] / modules / access_filter / dump.c
index 154517aceef7f47eeea6e66533e2d2a9d2dc30aa..24e656d9b5b968e552505e6518f331a4b450e1c6 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <assert.h>
 #include <time.h>
 #include <errno.h>
 
-#include "vlc_access.h"
-#include "vlc_block.h"
-#include "charset.h"
+#include <vlc_access.h>
+
+#include <vlc_charset.h>
 #include "vlc_keys.h"
 
 #define DEFAULT_MARGIN 32 // megabytes
@@ -62,7 +64,7 @@ vlc_module_begin ();
                  MARGIN_LONGTEXT, VLC_FALSE);
 vlc_module_end();
 
-static int Read (access_t *access, uint8_t *buffer, int len);
+static ssize_t Read (access_t *access, uint8_t *buffer, size_t len);
 static block_t *Block (access_t *access);
 static int Seek (access_t *access, int64_t offset);
 static int Control (access_t *access, int cmd, va_list ap);
@@ -113,13 +115,13 @@ static int Open (vlc_object_t *obj)
 
     if ((p_sys->stream = tmpfile ()) == NULL)
     {
-        msg_Err (access, "cannot create temporary file: %s", strerror (errno));
+        msg_Err (access, "cannot create temporary file: %m");
         free (p_sys);
         return VLC_EGENERIC;
     }
     p_sys->tmp_max = ((int64_t)var_CreateGetInteger (access, "dump-margin")) << 20;
 
-    var_AddCallback (access->p_libvlc, "key-pressed", KeyHandler, access);
+    var_AddCallback (access->p_libvlc, "key-action", KeyHandler, access);
 
     return VLC_SUCCESS;
 }
@@ -133,7 +135,7 @@ static void Close (vlc_object_t *obj)
     access_t *access = (access_t *)obj;
     access_sys_t *p_sys = access->p_sys;
 
-    var_DelCallback (access->p_libvlc, "key-pressed", KeyHandler, access);
+    var_DelCallback (access->p_libvlc, "key-action", KeyHandler, access);
 
     if (p_sys->stream != NULL)
         fclose (p_sys->stream);
@@ -169,7 +171,7 @@ static void Dump (access_t *access, const uint8_t *buffer, size_t len)
     assert (len > 0);
     if (fwrite (buffer, len, 1, stream) != 1)
     {
-        msg_Err (access, "cannot write to file: %s", strerror (errno));
+        msg_Err (access, "cannot write to file: %m");
         goto error;
     }
 
@@ -182,7 +184,7 @@ error:
 }
 
 
-static int Read (access_t *access, uint8_t *buffer, int len)
+static ssize_t Read (access_t *access, uint8_t *buffer, size_t len)
 {
     access_t *src = access->p_source;
 
@@ -242,26 +244,6 @@ static int Seek (access_t *access, int64_t offset)
     return ret;
 }
 
-
-#ifndef HAVE_LOCALTIME_R
-static inline struct tm *localtime_r (const time_t *now, struct tm *res)
-{
-    struct tm *unsafe = localtime (now);
-    /*
-     * This is not thread-safe. Blame your C library.
-     * On Win32 there SHOULD be _localtime_s instead, but of course
-     * Cygwin and Mingw32 don't know about it. You're on your own if you
-     * this platform.
-     */
-    if (unsafe == NULL)
-        return NULL;
-
-    memcpy (res, unsafe, sizeof (*res));
-    return res;
-}
-#endif
-
-
 static void Trigger (access_t *access)
 {
     access_sys_t *p_sys = access->p_sys;
@@ -296,8 +278,7 @@ static void Trigger (access_t *access)
     FILE *newstream = utf8_fopen (filename, "wb");
     if (newstream == NULL)
     {
-        msg_Err (access, "cannot create dump file \"%s\": %s", filename,
-                 strerror (errno));
+        msg_Err (access, "cannot create dump file \"%s\": %m", filename);
         return;
     }
 
@@ -313,8 +294,7 @@ static void Trigger (access_t *access)
         {
             if (ferror (oldstream))
             {
-                msg_Err (access, "cannot read temporary file: %s",
-                         strerror (errno));
+                msg_Err (access, "cannot read temporary file: %m");
                 break;
             }
 
@@ -327,7 +307,7 @@ static void Trigger (access_t *access)
 
         if (fwrite (buf, len, 1, newstream) != 1)
         {
-            msg_Err (access, "cannot write dump file: %s", strerror (errno));
+            msg_Err (access, "cannot write dump file: %m");
             break;
         }
     }
@@ -347,16 +327,7 @@ static int KeyHandler (vlc_object_t *obj, char const *varname,
     (void)oldval;
     (void)obj;
 
-    for (struct hotkey *key = access->p_libvlc->p_hotkeys;
-         key->psz_action != NULL; key++)
-    {
-        if (key->i_key == newval.i_int)
-        {
-            if (key->i_action == ACTIONID_DUMP)
-                Trigger ((access_t *)data);
-            break;
-        }
-    }
-
+    if (newval.i_int == ACTIONID_DUMP)
+        Trigger (access);
     return VLC_SUCCESS;
 }