[xiph-commits] r8205 - in icecast/trunk/icecast: conf doc src

oddsock at motherfish-iii.xiph.org oddsock at motherfish-iii.xiph.org
Mon Nov 15 20:04:03 PST 2004


Author: oddsock
Date: 2004-11-15 20:04:02 -0800 (Mon, 15 Nov 2004)
New Revision: 8205

Modified:
   icecast/trunk/icecast/conf/icecast.xml.in
   icecast/trunk/icecast/doc/icecast2_config_file.html
   icecast/trunk/icecast/src/admin.c
   icecast/trunk/icecast/src/cfgfile.c
   icecast/trunk/icecast/src/cfgfile.h
   icecast/trunk/icecast/src/format_vorbis.c
   icecast/trunk/icecast/src/logging.c
   icecast/trunk/icecast/src/logging.h
   icecast/trunk/icecast/src/main.c
Log:
this patch adds a playlist log to icecast.  This can be used to maintain an audit trail of metadata that comes through icecast.  The format of the log file may be changed in the future as we decide on a good format.


Modified: icecast/trunk/icecast/conf/icecast.xml.in
===================================================================
--- icecast/trunk/icecast/conf/icecast.xml.in	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/conf/icecast.xml.in	2004-11-16 04:04:02 UTC (rev 8205)
@@ -127,6 +127,7 @@
     <logging>
         <accesslog>access.log</accesslog>
         <errorlog>error.log</errorlog>
+        <!-- <playlistlog>playlist.log</playlistlog> -->
       	<loglevel>4</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
     </logging>
 

Modified: icecast/trunk/icecast/doc/icecast2_config_file.html
===================================================================
--- icecast/trunk/icecast/doc/icecast2_config_file.html	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/doc/icecast2_config_file.html	2004-11-16 04:04:02 UTC (rev 8205)
@@ -423,6 +423,7 @@
     &lt;logging&gt;
         &lt;accesslog&gt;access.log&lt;/accesslog&gt;
         &lt;errorlog&gt;error.log&lt;/errorlog&gt;
+        &lt;playlistlog&gt;playlist.log&lt;/playlistlog&gt;
       	&lt;loglevel&gt;4&lt;/loglevel&gt; &lt;-- 4 Debug, 3 Info, 2 Warn, 1 Error --&gt;
     &lt;/logging&gt;
 </pre>
@@ -438,6 +439,10 @@
 <div class="indentedbox">
 All icecast generated log messages will be written to this file.  If the loglevel is set too high (Debug for instance) then this file can grow fairly large over time.  Currently, there is no log-rotation implemented.
 </div>
+<h4>playlistlog</h4>
+<div class="indentedbox">
+Into this file, a log of all metadata for each mountpoint will be written.  The format of the logfile will most likely change over time as we narrow in on a standard format for this.  Currently, the file is pipe delimited.  This option is optional and can be removed entirely from the config file.
+</div>
 <h4>loglevel</h4>
 <div class="indentedbox">
 Indicates what messages are logged by icecast.  Log messages are categorized into one of 4 types, Debug, Info, Warn, and Error.<br /><br />The following mapping can be used to set the appropraite value :

Modified: icecast/trunk/icecast/src/admin.c
===================================================================
--- icecast/trunk/icecast/src/admin.c	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/admin.c	2004-11-16 04:04:02 UTC (rev 8205)
@@ -847,6 +847,9 @@
         source->mount, value);
     stats_event(source->mount, "title", value);
 
+    /* At this point, we assume that the metadata passed in
+       is encoded in UTF-8 */
+    logging_playlist(source->mount, value, source->listeners);
     /* If we get an update on the mountpoint, force a
        yp touch */
     yp_touch (source->mount);

Modified: icecast/trunk/icecast/src/cfgfile.c
===================================================================
--- icecast/trunk/icecast/src/cfgfile.c	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/cfgfile.c	2004-11-16 04:04:02 UTC (rev 8205)
@@ -42,6 +42,7 @@
 #define CONFIG_DEFAULT_FILESERVE 1
 #define CONFIG_DEFAULT_TOUCH_FREQ 5
 #define CONFIG_DEFAULT_HOSTNAME "localhost"
+#define CONFIG_DEFAULT_PLAYLIST_LOG NULL
 #define CONFIG_DEFAULT_ACCESS_LOG "access.log"
 #define CONFIG_DEFAULT_ERROR_LOG "error.log"
 #define CONFIG_DEFAULT_LOG_LEVEL 4
@@ -149,6 +150,8 @@
         xmlFree(c->adminroot_dir);
     if (c->pidfile)
         xmlFree(c->pidfile);
+    if (c->playlist_log && c->playlist_log != CONFIG_DEFAULT_PLAYLIST_LOG) 
+        xmlFree(c->playlist_log);
     if (c->access_log && c->access_log != CONFIG_DEFAULT_ACCESS_LOG) 
         xmlFree(c->access_log);
     if (c->error_log && c->error_log != CONFIG_DEFAULT_ERROR_LOG) 
@@ -330,6 +333,7 @@
     configuration->log_dir = CONFIG_DEFAULT_LOG_DIR;
     configuration->webroot_dir = CONFIG_DEFAULT_WEBROOT_DIR;
     configuration->adminroot_dir = CONFIG_DEFAULT_ADMINROOT_DIR;
+    configuration->playlist_log = CONFIG_DEFAULT_PLAYLIST_LOG;
     configuration->access_log = CONFIG_DEFAULT_ACCESS_LOG;
     configuration->error_log = CONFIG_DEFAULT_ERROR_LOG;
     configuration->loglevel = CONFIG_DEFAULT_LOG_LEVEL;
@@ -840,6 +844,9 @@
         } else if (strcmp(node->name, "errorlog") == 0) {
             if (configuration->error_log && configuration->error_log != CONFIG_DEFAULT_ERROR_LOG) xmlFree(configuration->error_log);
             configuration->error_log = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+        } else if (strcmp(node->name, "playlistlog") == 0) {
+            if (configuration->playlist_log && configuration->playlist_log != CONFIG_DEFAULT_PLAYLIST_LOG) xmlFree(configuration->playlist_log);
+            configuration->playlist_log = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
         } else if (strcmp(node->name, "loglevel") == 0) {
            char *tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
            configuration->loglevel = atoi(tmp);

Modified: icecast/trunk/icecast/src/cfgfile.h
===================================================================
--- icecast/trunk/icecast/src/cfgfile.h	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/cfgfile.h	2004-11-16 04:04:02 UTC (rev 8205)
@@ -128,6 +128,7 @@
 
     char *access_log;
     char *error_log;
+    char *playlist_log;
     int loglevel;
 
     int chroot;

Modified: icecast/trunk/icecast/src/format_vorbis.c
===================================================================
--- icecast/trunk/icecast/src/format_vorbis.c	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/format_vorbis.c	2004-11-16 04:04:02 UTC (rev 8205)
@@ -127,7 +127,10 @@
 {
     int result;
     ogg_packet op;
-    char *tag;
+    char *title_tag;
+    char *artist_tag;
+    char *metadata = NULL;
+    int   metadata_len = 0;
     refbuf_t *refbuf, *header;
     char *data;
     format_plugin_t *self = source->format;
@@ -202,13 +205,39 @@
 
                 DEBUG0 ("doing stats");
                 /* put known comments in the stats */
-                tag = vorbis_comment_query(&state->vc, "TITLE", 0);
-                if (tag) stats_event(source->mount, "title", tag);
+                title_tag = vorbis_comment_query(&state->vc, "TITLE", 0);
+                if (title_tag) stats_event(source->mount, "title", title_tag);
                 else stats_event(source->mount, "title", "unknown");
-                tag = vorbis_comment_query(&state->vc, "ARTIST", 0);
-                if (tag) stats_event(source->mount, "artist", tag);
+                artist_tag = vorbis_comment_query(&state->vc, "ARTIST", 0);
+                if (artist_tag) stats_event(source->mount, "artist", artist_tag);
                 else stats_event(source->mount, "artist", "unknown");
 
+                metadata = NULL;
+                if (artist_tag) {
+                    if (title_tag) {
+                        metadata_len = strlen(artist_tag) + strlen(title_tag) +
+                                       strlen(" - ") + 1;
+                        metadata = (char *)calloc(1, metadata_len);
+                        sprintf(metadata, "%s - %s", artist_tag, title_tag);
+                    }
+                    else {
+                        metadata_len = strlen(artist_tag) + 1;
+                        metadata = (char *)calloc(1, metadata_len);
+                        sprintf(metadata, "%s", artist_tag);
+                    }
+                }
+                else {
+                    if (title_tag) {
+                        metadata_len = strlen(title_tag) + 1;
+                        metadata = (char *)calloc(1, metadata_len);
+                        sprintf(metadata, "%s", title_tag);
+                    }
+                }
+                if (metadata) {
+                    logging_playlist(source->mount, metadata, source->listeners);
+                    free(metadata);
+                    metadata = NULL;
+                }
                 /* don't need these now */
                 ogg_stream_clear(&state->os);
                 vorbis_comment_clear(&state->vc);

Modified: icecast/trunk/icecast/src/logging.c
===================================================================
--- icecast/trunk/icecast/src/logging.c	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/logging.c	2004-11-16 04:04:02 UTC (rev 8205)
@@ -37,6 +37,7 @@
 /* the global log descriptors */
 int errorlog = 0;
 int accesslog = 0;
+int playlistlog = 0;
 
 #ifdef _WIN32
 /* Since strftime's %z option on win32 is different, we need
@@ -153,9 +154,40 @@
              user_agent,
              stayed);
 }
+/* This function will provide a log of metadata for each
+   mountpoint.  The metadata *must* be in UTF-8, and thus
+   you can assume that the log itself is UTF-8 encoded */
+void logging_playlist(char *mount, char *metadata, long listeners)
+{
+    char datebuf[128];
+    struct tm thetime;
+    time_t now;
 
+    if (playlistlog == -1) {
+        return;
+    }
 
+    now = time(NULL);
 
+    localtime_r (&now, &thetime);
+    /* build the data */
+#ifdef _WIN32
+    memset(datebuf, '\000', sizeof(datebuf));
+    get_clf_time(datebuf, sizeof(datebuf)-1, &thetime);
+#else
+    strftime (datebuf, sizeof(datebuf), LOGGING_FORMAT_CLF, &thetime);
+#endif
+    /* This format MAY CHANGE OVER TIME.  We are looking into finding a good
+       standard format for this, if you have any ideas, please let us know */
+    log_write_direct (playlistlog, "%s|%s|%d|%s",
+             datebuf,
+             mount,
+             listeners,
+             metadata);
+}
+
+
+
 void restart_logging (ice_config_t *config)
 {
     if (strcmp (config->error_log, "-"))
@@ -174,4 +206,12 @@
         log_set_filename (accesslog, fn_error);
         log_reopen (accesslog);
     }
+
+    if (config->playlist_log)
+    {
+        char fn_error[FILENAME_MAX];
+        snprintf (fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->playlist_log);
+        log_set_filename (playlistlog, fn_error);
+        log_reopen (playlistlog);
+    }
 }

Modified: icecast/trunk/icecast/src/logging.h
===================================================================
--- icecast/trunk/icecast/src/logging.h	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/logging.h	2004-11-16 04:04:02 UTC (rev 8205)
@@ -20,6 +20,7 @@
 
 extern int errorlog;
 extern int accesslog;
+extern int playlistlog;
 
 /* these are all ERRORx and WARNx where _x_ is the number of parameters
 ** it takes.  it turns out most other copmilers don't have support for
@@ -88,6 +89,7 @@
 #define LOGGING_FORMAT_CLF "%d/%b/%Y:%H:%M:%S %z"
 
 void logging_access(client_t *client);
+void logging_playlist(char *mount, char *metadata, long listeners);
 void restart_logging (ice_config_t *config);
 
 #endif  /* __LOGGING_H__ */

Modified: icecast/trunk/icecast/src/main.c
===================================================================
--- icecast/trunk/icecast/src/main.c	2004-11-15 17:29:04 UTC (rev 8204)
+++ icecast/trunk/icecast/src/main.c	2004-11-16 04:04:02 UTC (rev 8205)
@@ -87,6 +87,7 @@
 {
     log_close(errorlog);
     log_close(accesslog);
+    log_close(playlistlog);
 }
 
 static void _initialize_subsystems(void)
@@ -178,6 +179,7 @@
 {
     char fn_error[FILENAME_MAX];
     char fn_access[FILENAME_MAX];
+    char fn_playlist[FILENAME_MAX];
     char buf[1024];
     int log_to_stderr;
 
@@ -219,9 +221,26 @@
                 strerror(errno));
         _fatal_error(buf);
     }
+
+    if(config->playlist_log) {
+        snprintf(fn_playlist, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->playlist_log);
+        playlistlog = log_open(fn_playlist);
+        if (playlistlog < 0) {
+            buf[sizeof(buf)-1] = 0;
+            snprintf(buf, sizeof(buf)-1, 
+                "FATAL: could not open playlist logging (%s): %s",
+                log_to_stderr?"standard error":fn_playlist,
+                strerror(errno));
+            _fatal_error(buf);
+        }
+        log_to_stderr = 0;
+    } else {
+        playlistlog = -1;
+    }
     
     log_set_level(errorlog, config->loglevel);
     log_set_level(accesslog, 4);
+    log_set_level(playlistlog, 4);
 
     if (errorlog >= 0 && accesslog >= 0) return 1;
     



More information about the commits mailing list