new growl plugin: local only, supports album art (you'll need the Growl Framework)
authorRafaël Carré <funman@videolan.org>
Mon, 18 Feb 2008 17:17:16 +0000 (17:17 +0000)
committerRafaël Carré <funman@videolan.org>
Mon, 18 Feb 2008 17:17:16 +0000 (17:17 +0000)
rename growl to growl_udp

configure.ac
modules/misc/notify/Modules.am
modules/misc/notify/growl.c [deleted file]
modules/misc/notify/growl.m [new file with mode: 0644]
modules/misc/notify/growl_udp.c [new file with mode: 0644]

index 96d45bc..4479a7d 100644 (file)
@@ -298,7 +298,7 @@ case "${host_os}" in
         VLC_ADD_LDFLAGS([vlc],[-mwindows])
         VLC_ADD_LIBS([activex mozilla],[-lgdi32])
         VLC_ADD_LIBS([cdda vcdx cddax sdl_image],[-lwinmm])
-        VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp access_output_udp access_output_shout sap slp http stream_out_standard stream_out_rtp vod_rtsp access_realrtsp telnet rc netsync gnutls growl flac ts audioscrobbler lua],[-lws2_32])
+        VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp access_output_udp access_output_shout sap slp http stream_out_standard stream_out_rtp vod_rtsp access_realrtsp telnet rc netsync gnutls growl_udp flac ts audioscrobbler lua],[-lws2_32])
     fi
     if test "${SYS}" = "mingwce"; then
         # add ws2 for closesocket, select, recv
@@ -332,9 +332,9 @@ case "${host_os}" in
     LDFLAGS_save="${LDFLAGS_save} -lintl"; LDFLAGS="${LDFLAGS_save}"
     dnl Check for BONE
     if test -f /boot/beos/system/lib/libbind.so; then
-        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lbind -lsocket])
+        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl_udp],[-lbind -lsocket])
     else
-        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lnet])
+        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl_udp],[-lnet])
     fi
 
     dnl Ugly check for Zeta
@@ -506,7 +506,7 @@ AC_CHECK_FUNCS(connect,,[
 
 AC_CHECK_FUNCS(send,,[
   AC_CHECK_LIB(socket,send,[
-    VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp sap access_output_udp stream_out_standard growl],[-lsocket])
+    VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp sap access_output_udp stream_out_standard growl_udp],[-lsocket])
   ])
 ])
 
@@ -1680,7 +1680,11 @@ dnl
 AC_ARG_ENABLE(growl,
   [  --enable-growl          growl notification plugin (default enabled)])
 AS_IF([test "${enable_growl}" != "no"], [
-    VLC_ADD_PLUGINS([growl])
+    VLC_ADD_PLUGINS([growl_udp])
+    AC_CHECK_HEADERS(Growl/GrowlDefines.h, [
+      VLC_ADD_PLUGINS([growl])
+      VLC_ADD_LDFLAGS([growl], [-Wl,-framework,Growl,-framework,AppKit])
+    ])
   ]
 )
 
@@ -5322,7 +5326,7 @@ then
   VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,QTKit])
   VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,WebKit])
   VLC_ADD_LDFLAGS([opengllayer],                      [-Wl,-framework,QuartzCore])
-  VLC_ADD_OBJCFLAGS([macosx minimal_macosx opengllayer], [-fobjc-exceptions] )
+  VLC_ADD_OBJCFLAGS([macosx minimal_macosx opengllayer growl], [-fobjc-exceptions] )
 
   VLC_ADD_PLUGINS([access_eyetv])
   VLC_ADD_BUILTINS([macosx minimal_macosx])
index be1730d..178771c 100644 (file)
@@ -1,5 +1,11 @@
+# Automake forgets to add a proper tag to libtool with Objective-C files.
+# Moreocer Libtool should default tag to CC when none is specified but
+# obviously does not. Here is a fix for that.
+LIBTOOL=@LIBTOOL@ --tag=CC
+
 SOURCES_msn = msn.c
-SOURCES_growl = growl.c
+SOURCES_growl = growl.m
+SOURCES_growl_udp = growl_udp.c
 SOURCES_notify = notify.c
 SOURCES_xosd = xosd.c
 SOURCES_telepathy = telepathy.c
diff --git a/modules/misc/notify/growl.c b/modules/misc/notify/growl.c
deleted file mode 100644 (file)
index 411b2fe..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*****************************************************************************
- * growl.c : growl notification plugin
- *****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
- * $Id$
- *
- * Authors: Jérôme Decoodt <djc -at- videolan -dot- org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc/vlc.h>
-#include <vlc_interface.h>
-#include <vlc_playlist.h>
-#include <vlc_meta.h>
-#include <vlc_network.h>
-#include <errno.h>
-#include <vlc_md5.h>
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int  Open    ( vlc_object_t * );
-static void Close   ( vlc_object_t * );
-
-static int ItemChange( vlc_object_t *, const char *,
-                       vlc_value_t, vlc_value_t, void * );
-
-static int RegisterToGrowl( vlc_object_t *p_this );
-static int NotifyToGrowl( vlc_object_t *p_this, const char *psz_desc );
-static int CheckAndSend( vlc_object_t *p_this, uint8_t* p_data, int i_offset );
-#define GROWL_MAX_LENGTH 256
-
-/*****************************************************************************
- * Module descriptor
- ****************************************************************************/
-
-#define SERVER_DEFAULT "127.0.0.1"
-#define SERVER_TEXT N_("Server")
-#define SERVER_LONGTEXT N_("This is the host to which Growl notifications " \
-   "will be sent. By default, notifications are sent locally." )
-#define PASS_DEFAULT ""
-#define PASS_TEXT N_("Password")
-#define PASS_LONGTEXT N_("Growl password on the Growl server.")
-#define PORT_TEXT N_("UDP port")
-#define PORT_LONGTEXT N_("Growl UDP port on the Growl server.")
-
-vlc_module_begin();
-    set_category( CAT_INTERFACE );
-    set_subcategory( SUBCAT_INTERFACE_CONTROL );
-    set_shortname( "Growl" );
-    set_description( _("Growl Notification Plugin") );
-
-    add_string( "growl-server", SERVER_DEFAULT, NULL,
-                SERVER_TEXT, SERVER_LONGTEXT, VLC_FALSE );
-    add_password( "growl-password", PASS_DEFAULT, NULL,
-                PASS_TEXT, PASS_LONGTEXT, VLC_FALSE );
-    add_integer( "growl-port", 9887, NULL,
-                PORT_TEXT, PORT_LONGTEXT, VLC_TRUE );
-
-    set_capability( "interface", 0 );
-    set_callbacks( Open, Close );
-vlc_module_end();
-
-/*****************************************************************************
- * Open: initialize and create stuff
- *****************************************************************************/
-static int Open( vlc_object_t *p_this )
-{
-    intf_thread_t *p_intf = (intf_thread_t *)p_this;
-
-    playlist_t *p_playlist = pl_Yield( p_intf );
-    var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
-    pl_Release( p_intf );
-
-    RegisterToGrowl( p_this );
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Close: destroy interface stuff
- *****************************************************************************/
-static void Close( vlc_object_t *p_this )
-{
-    playlist_t *p_playlist = pl_Yield( p_this );
-    var_DelCallback( p_playlist, "playlist-current", ItemChange, p_this );
-    pl_Release( p_this );
-}
-
-/*****************************************************************************
- * ItemChange: Playlist item change callback
- *****************************************************************************/
-static int ItemChange( vlc_object_t *p_this, const char *psz_var,
-                       vlc_value_t oldval, vlc_value_t newval, void *param )
-{
-    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
-    VLC_UNUSED(param);
-    char psz_tmp[GROWL_MAX_LENGTH];
-    char *psz_title = NULL;
-    char *psz_artist = NULL;
-    char *psz_album = NULL;
-    input_thread_t *p_input;
-    playlist_t *p_playlist = pl_Yield( p_this );
-
-    p_input = p_playlist->p_input;
-    vlc_object_release( p_playlist );
-
-    if( !p_input ) return VLC_SUCCESS;
-    vlc_object_yield( p_input );
-
-    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
-    if( p_input->b_dead || !psz_name )
-    {
-        /* Not playing anything ... */
-        free( psz_name );
-        vlc_object_release( p_input );
-        return VLC_SUCCESS;
-    }
-    free( psz_name );
-
-    /* Playing something ... */
-    input_item_t *p_item = input_GetItem( p_input );
-
-    psz_title = input_item_GetTitle( p_item );
-    if( psz_title == NULL || EMPTY_STR( psz_title ) )
-    {
-        free( psz_title );
-        psz_title = input_item_GetName( input_GetItem( p_input ) );
-        if( psz_title == NULL || EMPTY_STR( psz_title ) )
-        {
-            free( psz_title );
-            vlc_object_release( p_input );
-            return VLC_SUCCESS;
-        }
-    }
-
-    psz_artist = input_item_GetArtist( p_item );
-    if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
-    psz_album = input_item_GetAlbum( p_item ) ;
-    if( EMPTY_STR( psz_album ) ) FREENULL( psz_album );
-
-    if( psz_artist && psz_album )
-        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s\n%s [%s]",
-                psz_title, psz_artist, psz_album );
-    else if( psz_artist )
-        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s\n%s", psz_title, psz_artist );
-    else
-        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s", psz_title );
-
-    free( psz_title );
-    free( psz_artist );
-    free( psz_album );
-
-    NotifyToGrowl( p_this, psz_tmp );
-
-    vlc_object_release( p_input );
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Growl specific functions
- *****************************************************************************/
-#define GROWL_PROTOCOL_VERSION (1)
-#define GROWL_TYPE_REGISTRATION (0)
-#define GROWL_TYPE_NOTIFICATION (1)
-#define APPLICATION_NAME "VLC media player"
-
-#define insertstrlen( psz ) \
-{ \
-    uint16_t i_size = strlen( psz ); \
-    psz_encoded[i++] = (i_size>>8)&0xFF; \
-    psz_encoded[i++] = i_size&0xFF; \
-}
-/*****************************************************************************
- * RegisterToGrowl
- *****************************************************************************/
-static int RegisterToGrowl( vlc_object_t *p_this )
-{
-    uint8_t *psz_encoded = malloc(100);
-    uint8_t i_defaults = 0;
-    static const char *psz_notifications[] = {"Now Playing", NULL};
-    vlc_bool_t pb_defaults[] = {VLC_TRUE, VLC_FALSE};
-    int i = 0, j;
-    if( psz_encoded == NULL )
-        return VLC_FALSE;
-
-    memset( psz_encoded, 0, sizeof(psz_encoded) );
-    psz_encoded[i++] = GROWL_PROTOCOL_VERSION;
-    psz_encoded[i++] = GROWL_TYPE_REGISTRATION;
-    insertstrlen(APPLICATION_NAME);
-    i+=2;
-    strcpy( (char*)(psz_encoded+i), APPLICATION_NAME );
-    i += strlen(APPLICATION_NAME);
-    for( j = 0 ; psz_notifications[j] != NULL ; j++)
-    {
-        insertstrlen(psz_notifications[j]);
-        strcpy( (char*)(psz_encoded+i), psz_notifications[j] );
-        i += strlen(psz_notifications[j]);
-    }
-    psz_encoded[4] = j;
-    for( j = 0 ; psz_notifications[j] != NULL ; j++)
-        if(pb_defaults[j] == VLC_TRUE)
-        {
-            psz_encoded[i++] = (uint8_t)j;
-            i_defaults++;
-        }
-    psz_encoded[5] = i_defaults;
-
-    CheckAndSend(p_this, psz_encoded, i);
-    free( psz_encoded );
-    return VLC_SUCCESS;
-}
-
-static int NotifyToGrowl( vlc_object_t *p_this, const char *psz_desc )
-{
-    const char *psz_type = "Now Playing", *psz_title = "Now Playing";
-    uint8_t *psz_encoded = malloc(GROWL_MAX_LENGTH + 42);
-    uint16_t flags;
-    int i = 0;
-    if( psz_encoded == NULL )
-        return VLC_FALSE;
-
-    memset( psz_encoded, 0, sizeof(psz_encoded) );
-    psz_encoded[i++] = GROWL_PROTOCOL_VERSION;
-    psz_encoded[i++] = GROWL_TYPE_NOTIFICATION;
-    flags = 0;
-    psz_encoded[i++] = (flags>>8)&0xFF;
-    psz_encoded[i++] = flags&0xFF;
-    insertstrlen(psz_type);
-    insertstrlen(psz_title);
-    insertstrlen(psz_desc);
-    insertstrlen(APPLICATION_NAME);
-    strcpy( (char*)(psz_encoded+i), psz_type );
-    i += strlen(psz_type);
-    strcpy( (char*)(psz_encoded+i), psz_title );
-    i += strlen(psz_title);
-    strcpy( (char*)(psz_encoded+i), psz_desc );
-    i += strlen(psz_desc);
-    strcpy( (char*)(psz_encoded+i), APPLICATION_NAME );
-    i += strlen(APPLICATION_NAME);
-
-    CheckAndSend(p_this, psz_encoded, i);
-    free( psz_encoded );
-    return VLC_SUCCESS;
-}
-
-static int CheckAndSend( vlc_object_t *p_this, uint8_t* p_data, int i_offset )
-{
-    int i, i_handle;
-    struct md5_s md5;
-    intf_thread_t *p_intf = (intf_thread_t *)p_this;
-    char *psz_password = config_GetPsz( p_intf, "growl-password" );
-    char *psz_server = config_GetPsz( p_intf, "growl-server" );
-    int i_port = config_GetInt( p_intf, "growl-port" );
-    strcpy( (char*)(p_data+i_offset), psz_password );
-    i = i_offset + strlen(psz_password);
-
-    InitMD5( &md5 );
-    AddMD5( &md5, p_data, i );
-    EndMD5( &md5 );
-
-    for( i = 0 ; i < 4 ; i++ )
-    {
-        md5.p_digest[i] = md5.p_digest[i];
-        p_data[i_offset++] =  md5.p_digest[i]     &0xFF;
-        p_data[i_offset++] = (md5.p_digest[i]>> 8)&0xFF;
-        p_data[i_offset++] = (md5.p_digest[i]>>16)&0xFF;
-        p_data[i_offset++] = (md5.p_digest[i]>>24)&0xFF;
-    }
-
-    i_handle = net_ConnectUDP( p_this, psz_server, i_port, 0 );
-    if( i_handle == -1 )
-    {
-         msg_Err( p_this, "failed to open a connection (udp)" );
-         free( psz_password);
-         free( psz_server);
-         return VLC_EGENERIC;
-    }
-
-    shutdown( i_handle, SHUT_RD );
-    if( send( i_handle, p_data, i_offset, 0 )
-          == -1 )
-    {
-        msg_Warn( p_this, "send error: %m" );
-    }
-    net_Close( i_handle );
-
-    free( psz_password);
-    free( psz_server);
-    return VLC_SUCCESS;
-}
-
-#undef GROWL_PROTOCOL_VERSION
-#undef GROWL_TYPE_REGISTRATION
-#undef GROWL_TYPE_NOTIFICATION
-#undef APPLICATION_NAME
-#undef insertstrlen
diff --git a/modules/misc/notify/growl.m b/modules/misc/notify/growl.m
new file mode 100644 (file)
index 0000000..fb79f16
--- /dev/null
@@ -0,0 +1,325 @@
+/*****************************************************************************
+ * growl.m : growl notification plugin
+ *****************************************************************************
+ * VLC specific code:
+ * 
+ * Copyright © 2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Rafaël Carré <funman@videolanorg>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *
+ * Growl specific code, ripped from growlnotify:
+ *
+ * Copyright (c) The Growl Project, 2004-2005
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Growl nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#import <Foundation/Foundation.h>
+#import <Growl/GrowlDefines.h>
+
+#include <vlc/vlc.h>
+#include <vlc_playlist.h>
+#include <vlc_meta.h>
+#include <vlc_interface.h>
+
+
+/*****************************************************************************
+ * intf_sys_t
+ *****************************************************************************/
+struct intf_sys_t
+{
+    CFDataRef           default_icon;
+    NSAutoreleasePool   *p_pool;
+    CFStringRef         app_name;
+    CFStringRef         notification_type;
+};
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Open    ( vlc_object_t * );
+static void Close   ( vlc_object_t * );
+
+static int ItemChange( vlc_object_t *, const char *,
+                       vlc_value_t, vlc_value_t, void * );
+
+static void RegisterToGrowl( vlc_object_t * );
+static void NotifyToGrowl( intf_thread_t *, const char *, CFDataRef );
+
+static CFDataRef readFile(const char *);
+
+/*****************************************************************************
+ * Module descriptor
+ ****************************************************************************/
+
+vlc_module_begin();
+    set_category( CAT_INTERFACE );
+    set_subcategory( SUBCAT_INTERFACE_CONTROL );
+    set_shortname( "Growl" );
+    set_description( _("Growl Notification Plugin") );
+    set_capability( "interface", 0 );
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/*****************************************************************************
+ * Open: initialize and create stuff
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    intf_sys_t    *p_sys;
+
+    p_sys = p_intf->p_sys = calloc( sizeof(intf_sys_t), 1);
+    if( !p_sys )
+        return VLC_ENOMEM;
+
+    p_sys->p_pool = [[NSAutoreleasePool alloc] init];
+    p_sys->app_name = CFSTR( "VLC media player" );
+    p_sys->notification_type = CFSTR( "New input playing" );
+
+    const char *data_path = config_GetDataDir ();
+    char buf[strlen (data_path) + sizeof ("/vlc48x48.png")];
+    snprintf (buf, sizeof (buf), "%s/vlc48x48.png", data_path);
+    p_sys->default_icon = (CFDataRef) readFile( buf );
+
+    playlist_t *p_playlist = pl_Yield( p_intf );
+    var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
+    pl_Release( p_intf );
+
+    RegisterToGrowl( p_this );
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: destroy interface stuff
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    intf_sys_t *p_sys = ((intf_thread_t*)p_this)->p_sys;
+
+    CFRelease( p_sys->default_icon );
+    CFRelease( p_sys->app_name );
+    CFRelease( p_sys->notification_type );
+    [p_sys->p_pool release];
+    free( p_sys );
+
+    playlist_t *p_playlist = pl_Yield( p_this );
+    var_DelCallback( p_playlist, "playlist-current", ItemChange, p_this );
+    pl_Release( p_this );
+}
+
+/*****************************************************************************
+ * ItemChange: Playlist item change callback
+ *****************************************************************************/
+static int ItemChange( vlc_object_t *p_this, const char *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *param )
+{
+    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
+
+    intf_thread_t *p_intf   = (intf_thread_t*)param;
+    char *psz_tmp           = NULL;
+    char *psz_title         = NULL;
+    char *psz_artist        = NULL;
+    char *psz_album         = NULL;
+    input_thread_t *p_input;
+    playlist_t *p_playlist = pl_Yield( p_this );
+
+    p_input = p_playlist->p_input;
+    vlc_object_release( p_playlist );
+
+    if( !p_input ) return VLC_SUCCESS;
+    vlc_object_yield( p_input );
+
+    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
+    if( p_input->b_dead || !psz_name )
+    {
+        /* Not playing anything ... */
+        free( psz_name );
+        vlc_object_release( p_input );
+        return VLC_SUCCESS;
+    }
+    free( psz_name );
+
+    /* Playing something ... */
+    input_item_t *p_item = input_GetItem( p_input );
+
+    psz_title = input_item_GetTitle( p_item );
+    if( psz_title == NULL || EMPTY_STR( psz_title ) )
+    {
+        free( psz_title );
+        psz_title = input_item_GetName( input_GetItem( p_input ) );
+        if( psz_title == NULL || EMPTY_STR( psz_title ) )
+        {
+            free( psz_title );
+            vlc_object_release( p_input );
+            return VLC_SUCCESS;
+        }
+    }
+
+    psz_artist = input_item_GetArtist( p_item );
+    if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
+    psz_album = input_item_GetAlbum( p_item ) ;
+    if( EMPTY_STR( psz_album ) ) FREENULL( psz_album );
+
+    int i_ret;
+    if( psz_artist && psz_album )
+        i_ret = asprintf( &psz_tmp, "%s\n%s [%s]",
+                psz_title, psz_artist, psz_album );
+    else if( psz_artist )
+        i_ret = asprintf( &psz_tmp, "%s\n%s", psz_title, psz_artist );
+    else
+        i_ret = asprintf( &psz_tmp, "%s", psz_title );
+
+    if( i_ret == -1 )
+    {
+        free( psz_title );
+        free( psz_artist );
+        free( psz_album );
+        vlc_object_release( p_input );
+        return VLC_ENOMEM;
+    }
+
+    char *psz_arturl = input_item_GetArtURL( p_item );
+    CFDataRef art = NULL;
+    if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) &&
+                    strlen( psz_arturl ) > 7 )
+        art = (CFDataRef) readFile( psz_arturl + 7 );
+
+    free( psz_title );
+    free( psz_artist );
+    free( psz_album );
+    free( psz_arturl );
+
+    NotifyToGrowl( p_intf, psz_tmp, art );
+
+    if( art ) CFRelease( art );
+
+    vlc_object_release( p_input );
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * RegisterToGrowl
+ *****************************************************************************/
+static void RegisterToGrowl( vlc_object_t *p_this )
+{
+    intf_sys_t *p_sys = ((intf_thread_t *)p_this)->p_sys;
+
+    CFArrayRef defaultAndAllNotifications = CFArrayCreate(
+        kCFAllocatorDefault, (const void **)&(p_sys->notification_type), 1,
+        &kCFTypeArrayCallBacks );
+    
+    CFTypeRef registerKeys[4] = {
+        GROWL_APP_NAME,
+        GROWL_NOTIFICATIONS_ALL,
+        GROWL_NOTIFICATIONS_DEFAULT,
+        GROWL_APP_ICON
+    };
+
+    CFTypeRef registerValues[4] = {
+        p_sys->app_name,
+        defaultAndAllNotifications,
+        defaultAndAllNotifications,
+        p_sys->default_icon
+    };
+
+    CFDictionaryRef registerInfo = CFDictionaryCreate(
+        kCFAllocatorDefault, registerKeys, registerValues, 4,
+        &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
+
+    CFRelease( defaultAndAllNotifications );
+
+    CFNotificationCenterPostNotificationWithOptions(
+        CFNotificationCenterGetDistributedCenter(),
+        (CFStringRef)GROWL_APP_REGISTRATION, NULL, registerInfo,
+        kCFNotificationPostToAllSessions );
+    CFRelease( registerInfo );
+}
+
+static void NotifyToGrowl( intf_thread_t *p_intf, const char *psz_desc, CFDataRef art )
+{
+    intf_sys_t *p_sys = p_intf->p_sys;
+
+    CFStringRef title = CFStringCreateWithCString( kCFAllocatorDefault, _("Now playing"), kCFStringEncodingUTF8 );
+    CFStringRef desc = CFStringCreateWithCString( kCFAllocatorDefault, psz_desc, kCFStringEncodingUTF8 );
+
+    CFMutableDictionaryRef notificationInfo = CFDictionaryCreateMutable(
+        kCFAllocatorDefault, 5, &kCFTypeDictionaryKeyCallBacks,
+        &kCFTypeDictionaryValueCallBacks);
+
+    CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_NAME, p_sys->notification_type );
+    CFDictionarySetValue( notificationInfo, GROWL_APP_NAME, p_sys->app_name );
+    CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_TITLE, title );
+    CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_DESCRIPTION, desc );
+
+    CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_ICON, 
+        art ? art : p_sys->default_icon );
+
+    CFRelease( title );
+    CFRelease( desc );
+
+    CFNotificationCenterPostNotificationWithOptions(
+        CFNotificationCenterGetDistributedCenter(),
+        (CFStringRef)GROWL_NOTIFICATION, NULL, notificationInfo,
+        kCFNotificationPostToAllSessions );
+
+    CFRelease( notificationInfo );
+}
+
+/* Ripped from CFGrowlAdditions.c 
+ * Strangely, this function does exist in Growl shared library, but is not
+ * defined in public header files */
+static CFDataRef readFile(const char *filename)
+{
+    CFDataRef data;
+    // read the file into a CFDataRef
+    FILE *fp = fopen(filename, "r");
+    if( !fp )
+    return NULL;
+
+    fseek(fp, 0, SEEK_END);
+    long dataLength = ftell(fp);
+    fseek(fp, 0, SEEK_SET);
+    unsigned char *fileData = malloc(dataLength);
+    fread(fileData, 1, dataLength, fp);
+    fclose(fp);
+    return CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, fileData,
+        dataLength, kCFAllocatorMalloc);
+}
+
diff --git a/modules/misc/notify/growl_udp.c b/modules/misc/notify/growl_udp.c
new file mode 100644 (file)
index 0000000..3035c75
--- /dev/null
@@ -0,0 +1,317 @@
+/*****************************************************************************
+ * growl_udp.c : growl UDP notification plugin
+ *****************************************************************************
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Jérôme Decoodt <djc -at- videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc/vlc.h>
+#include <vlc_interface.h>
+#include <vlc_playlist.h>
+#include <vlc_meta.h>
+#include <vlc_network.h>
+#include <errno.h>
+#include <vlc_md5.h>
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Open    ( vlc_object_t * );
+static void Close   ( vlc_object_t * );
+
+static int ItemChange( vlc_object_t *, const char *,
+                       vlc_value_t, vlc_value_t, void * );
+
+static int RegisterToGrowl( vlc_object_t *p_this );
+static int NotifyToGrowl( vlc_object_t *p_this, const char *psz_desc );
+static int CheckAndSend( vlc_object_t *p_this, uint8_t* p_data, int i_offset );
+#define GROWL_MAX_LENGTH 256
+
+/*****************************************************************************
+ * Module descriptor
+ ****************************************************************************/
+
+#define SERVER_DEFAULT "127.0.0.1"
+#define SERVER_TEXT N_("Server")
+#define SERVER_LONGTEXT N_("This is the host to which Growl notifications " \
+   "will be sent. By default, notifications are sent locally." )
+#define PASS_DEFAULT ""
+#define PASS_TEXT N_("Password")
+#define PASS_LONGTEXT N_("Growl password on the Growl server.")
+#define PORT_TEXT N_("UDP port")
+#define PORT_LONGTEXT N_("Growl UDP port on the Growl server.")
+
+vlc_module_begin();
+    set_category( CAT_INTERFACE );
+    set_subcategory( SUBCAT_INTERFACE_CONTROL );
+    set_shortname( "Growl-UDP" );
+    set_description( _("Growl UDP Notification Plugin") );
+
+    add_string( "growl-server", SERVER_DEFAULT, NULL,
+                SERVER_TEXT, SERVER_LONGTEXT, VLC_FALSE );
+    add_password( "growl-password", PASS_DEFAULT, NULL,
+                PASS_TEXT, PASS_LONGTEXT, VLC_FALSE );
+    add_integer( "growl-port", 9887, NULL,
+                PORT_TEXT, PORT_LONGTEXT, VLC_TRUE );
+
+    set_capability( "interface", 0 );
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/*****************************************************************************
+ * Open: initialize and create stuff
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+
+    playlist_t *p_playlist = pl_Yield( p_intf );
+    var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
+    pl_Release( p_intf );
+
+    RegisterToGrowl( p_this );
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: destroy interface stuff
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    playlist_t *p_playlist = pl_Yield( p_this );
+    var_DelCallback( p_playlist, "playlist-current", ItemChange, p_this );
+    pl_Release( p_this );
+}
+
+/*****************************************************************************
+ * ItemChange: Playlist item change callback
+ *****************************************************************************/
+static int ItemChange( vlc_object_t *p_this, const char *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *param )
+{
+    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
+    VLC_UNUSED(param);
+    char psz_tmp[GROWL_MAX_LENGTH];
+    char *psz_title = NULL;
+    char *psz_artist = NULL;
+    char *psz_album = NULL;
+    input_thread_t *p_input;
+    playlist_t *p_playlist = pl_Yield( p_this );
+
+    p_input = p_playlist->p_input;
+    vlc_object_release( p_playlist );
+
+    if( !p_input ) return VLC_SUCCESS;
+    vlc_object_yield( p_input );
+
+    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
+    if( p_input->b_dead || !psz_name )
+    {
+        /* Not playing anything ... */
+        free( psz_name );
+        vlc_object_release( p_input );
+        return VLC_SUCCESS;
+    }
+    free( psz_name );
+
+    /* Playing something ... */
+    input_item_t *p_item = input_GetItem( p_input );
+
+    psz_title = input_item_GetTitle( p_item );
+    if( psz_title == NULL || EMPTY_STR( psz_title ) )
+    {
+        free( psz_title );
+        psz_title = input_item_GetName( input_GetItem( p_input ) );
+        if( psz_title == NULL || EMPTY_STR( psz_title ) )
+        {
+            free( psz_title );
+            vlc_object_release( p_input );
+            return VLC_SUCCESS;
+        }
+    }
+
+    psz_artist = input_item_GetArtist( p_item );
+    if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
+    psz_album = input_item_GetAlbum( p_item ) ;
+    if( EMPTY_STR( psz_album ) ) FREENULL( psz_album );
+
+    if( psz_artist && psz_album )
+        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s\n%s [%s]",
+                psz_title, psz_artist, psz_album );
+    else if( psz_artist )
+        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s\n%s", psz_title, psz_artist );
+    else
+        snprintf( psz_tmp, GROWL_MAX_LENGTH, "%s", psz_title );
+
+    free( psz_title );
+    free( psz_artist );
+    free( psz_album );
+
+    NotifyToGrowl( p_this, psz_tmp );
+
+    vlc_object_release( p_input );
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Growl specific functions
+ *****************************************************************************/
+#define GROWL_PROTOCOL_VERSION (1)
+#define GROWL_TYPE_REGISTRATION (0)
+#define GROWL_TYPE_NOTIFICATION (1)
+#define APPLICATION_NAME "VLC media player"
+
+#define insertstrlen( psz ) \
+{ \
+    uint16_t i_size = strlen( psz ); \
+    psz_encoded[i++] = (i_size>>8)&0xFF; \
+    psz_encoded[i++] = i_size&0xFF; \
+}
+/*****************************************************************************
+ * RegisterToGrowl
+ *****************************************************************************/
+static int RegisterToGrowl( vlc_object_t *p_this )
+{
+    uint8_t *psz_encoded = malloc(100);
+    uint8_t i_defaults = 0;
+    static const char *psz_notifications[] = {"Now Playing", NULL};
+    vlc_bool_t pb_defaults[] = {VLC_TRUE, VLC_FALSE};
+    int i = 0, j;
+    if( psz_encoded == NULL )
+        return VLC_FALSE;
+
+    memset( psz_encoded, 0, sizeof(psz_encoded) );
+    psz_encoded[i++] = GROWL_PROTOCOL_VERSION;
+    psz_encoded[i++] = GROWL_TYPE_REGISTRATION;
+    insertstrlen(APPLICATION_NAME);
+    i+=2;
+    strcpy( (char*)(psz_encoded+i), APPLICATION_NAME );
+    i += strlen(APPLICATION_NAME);
+    for( j = 0 ; psz_notifications[j] != NULL ; j++)
+    {
+        insertstrlen(psz_notifications[j]);
+        strcpy( (char*)(psz_encoded+i), psz_notifications[j] );
+        i += strlen(psz_notifications[j]);
+    }
+    psz_encoded[4] = j;
+    for( j = 0 ; psz_notifications[j] != NULL ; j++)
+        if(pb_defaults[j] == VLC_TRUE)
+        {
+            psz_encoded[i++] = (uint8_t)j;
+            i_defaults++;
+        }
+    psz_encoded[5] = i_defaults;
+
+    CheckAndSend(p_this, psz_encoded, i);
+    free( psz_encoded );
+    return VLC_SUCCESS;
+}
+
+static int NotifyToGrowl( vlc_object_t *p_this, const char *psz_desc )
+{
+    const char *psz_type = "Now Playing", *psz_title = "Now Playing";
+    uint8_t *psz_encoded = malloc(GROWL_MAX_LENGTH + 42);
+    uint16_t flags;
+    int i = 0;
+    if( psz_encoded == NULL )
+        return VLC_FALSE;
+
+    memset( psz_encoded, 0, sizeof(psz_encoded) );
+    psz_encoded[i++] = GROWL_PROTOCOL_VERSION;
+    psz_encoded[i++] = GROWL_TYPE_NOTIFICATION;
+    flags = 0;
+    psz_encoded[i++] = (flags>>8)&0xFF;
+    psz_encoded[i++] = flags&0xFF;
+    insertstrlen(psz_type);
+    insertstrlen(psz_title);
+    insertstrlen(psz_desc);
+    insertstrlen(APPLICATION_NAME);
+    strcpy( (char*)(psz_encoded+i), psz_type );
+    i += strlen(psz_type);
+    strcpy( (char*)(psz_encoded+i), psz_title );
+    i += strlen(psz_title);
+    strcpy( (char*)(psz_encoded+i), psz_desc );
+    i += strlen(psz_desc);
+    strcpy( (char*)(psz_encoded+i), APPLICATION_NAME );
+    i += strlen(APPLICATION_NAME);
+
+    CheckAndSend(p_this, psz_encoded, i);
+    free( psz_encoded );
+    return VLC_SUCCESS;
+}
+
+static int CheckAndSend( vlc_object_t *p_this, uint8_t* p_data, int i_offset )
+{
+    int i, i_handle;
+    struct md5_s md5;
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    char *psz_password = config_GetPsz( p_intf, "growl-password" );
+    char *psz_server = config_GetPsz( p_intf, "growl-server" );
+    int i_port = config_GetInt( p_intf, "growl-port" );
+    strcpy( (char*)(p_data+i_offset), psz_password );
+    i = i_offset + strlen(psz_password);
+
+    InitMD5( &md5 );
+    AddMD5( &md5, p_data, i );
+    EndMD5( &md5 );
+
+    for( i = 0 ; i < 4 ; i++ )
+    {
+        md5.p_digest[i] = md5.p_digest[i];
+        p_data[i_offset++] =  md5.p_digest[i]     &0xFF;
+        p_data[i_offset++] = (md5.p_digest[i]>> 8)&0xFF;
+        p_data[i_offset++] = (md5.p_digest[i]>>16)&0xFF;
+        p_data[i_offset++] = (md5.p_digest[i]>>24)&0xFF;
+    }
+
+    i_handle = net_ConnectUDP( p_this, psz_server, i_port, 0 );
+    if( i_handle == -1 )
+    {
+         msg_Err( p_this, "failed to open a connection (udp)" );
+         free( psz_password);
+         free( psz_server);
+         return VLC_EGENERIC;
+    }
+
+    shutdown( i_handle, SHUT_RD );
+    if( send( i_handle, p_data, i_offset, 0 )
+          == -1 )
+    {
+        msg_Warn( p_this, "send error: %m" );
+    }
+    net_Close( i_handle );
+
+    free( psz_password);
+    free( psz_server);
+    return VLC_SUCCESS;
+}
+
+#undef GROWL_PROTOCOL_VERSION
+#undef GROWL_TYPE_REGISTRATION
+#undef GROWL_TYPE_NOTIFICATION
+#undef APPLICATION_NAME
+#undef insertstrlen