[xiph-cvs] cvs commit: thread thread.c

Michael Smith msmith at xiph.org
Thu Aug 8 23:52:08 PDT 2002



msmith      02/08/09 02:52:07

  Modified:    conf     icecast.xml
               src      Makefile.am config.c config.h connection.c stats.c
                        stats.h util.c util.h
               .        thread.c
  Log:
  oddsock's xslt stats support, slightly cleaned up

Revision  Changes    Path
1.6       +1 -0      icecast/conf/icecast.xml

Index: icecast.xml
===================================================================
RCS file: /usr/local/cvsroot/icecast/conf/icecast.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- icecast.xml	5 Aug 2002 14:51:22 -0000	1.5
+++ icecast.xml	9 Aug 2002 06:52:07 -0000	1.6
@@ -32,6 +32,7 @@
         <paths>
                 <basedir>/usr/local/icecast</basedir>
                 <logdir>/tmp</logdir>
+                <webroot>/usr/local/icecast/webroot</basedir>
         </paths>
 
         <logging>

<p><p>1.7       +5 -8      icecast/src/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.am	5 Aug 2002 14:48:01 -0000	1.6
+++ Makefile.am	9 Aug 2002 06:52:07 -0000	1.7
@@ -11,23 +11,20 @@
          compat.h format_mp3.h
 icecast_SOURCES = config.c main.c logging.c sighandler.c connection.c global.c\
          util.c slave.c source.c stats.c refbuf.c client.c format.c format_vorbis.c\
-	 format_mp3.c
+	 format_mp3.c xslt.c
     
 icecast_LDADD = net/libicenet.la thread/libicethread.la httpp/libicehttpp.la\
                 log/libicelog.la avl/libiceavl.la timing/libicetiming.la
 
-LIBS = @LIBS@ -lpthread @SOCKET_LIBS@ @XML_LIBS@ @OGG_LIBS@ @VORBIS_LIBS@
-CFLAGS = @CFLAGS@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@
+LIBS = @LIBS@ -lxslt -lpthread @SOCKET_LIBS@ @XML_LIBS@ @OGG_LIBS@ @VORBIS_LIBS@
+CFLAGS = -g @CFLAGS@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@
 
 INCLUDES = -I$(srcdir)/net -I$(srcdir)/thread -I$(srcdir)/avl -I$(srcdir)/httpp \
         -I$(srcdir)/log -I$(srcdir)/timing
 
-# SCCS stuff (for BitKeeper)
-GET = true
-
 debug:
-        $(MAKE) all CFLAGS="@DEBUG@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@"
+	$(MAKE) all CFLAGS="@DEBUG@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@"
 
 profile:
-        $(MAKE) all CFLAGS="@PROFILE@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@"
+	$(MAKE) all CFLAGS="@PROFILE@ @XML_CFLAGS@ @OGG_CFLAGS@ @VORBIS_CFLAGS@"
 

<p><p>1.10      +5 -0      icecast/src/config.c

Index: config.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/config.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- config.c	5 Aug 2002 14:48:01 -0000	1.9
+++ config.c	9 Aug 2002 06:52:07 -0000	1.10
@@ -28,9 +28,11 @@
 #ifndef _WIN32
 #define CONFIG_DEFAULT_BASE_DIR "/usr/local/icecast"
 #define CONFIG_DEFAULT_LOG_DIR "/usr/local/icecast/logs"
+#define CONFIG_DEFAULT_WEBROOT_DIR "/usr/local/icecast/webroot"
 #else
 #define CONFIG_DEFAULT_BASE_DIR ".\\"
 #define CONFIG_DEFAULT_LOG_DIR ".\\logs"
+#define CONFIG_DEFAULT_WEBROOT_DIR ".\\webroot"
 #endif
 
 ice_config_t _configuration;
@@ -278,6 +280,9 @@
                 } else if (strcmp(node->name, "logdir") == 0) {
                         if (_configuration.log_dir) free(_configuration.log_dir);
                         _configuration.log_dir = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+		} else if (strcmp(node->name, "webroot") == 0) {
+			if (_configuration.webroot_dir) free(_configuration.webroot_dir);
+			_configuration.webroot_dir = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
                 }
         } while ((node = node->next));
 }

<p><p>1.6       +1 -0      icecast/src/config.h

Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/config.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- config.h	5 Aug 2002 14:48:01 -0000	1.5
+++ config.h	9 Aug 2002 06:52:07 -0000	1.6
@@ -39,6 +39,7 @@
 
         char *base_dir;
         char *log_dir;
+	char *webroot_dir;
 
         char *access_log;
         char *error_log;

<p><p>1.14      +25 -0     icecast/src/connection.c

Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- connection.c	5 Aug 2002 14:48:01 -0000	1.13
+++ connection.c	9 Aug 2002 06:52:07 -0000	1.14
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <time.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #ifndef _WIN32
 #include <sys/time.h>
@@ -32,6 +33,7 @@
 #include "stats.h"
 #include "format.h"
 #include "logging.h"
+#include "xslt.h"
 
 #include "source.h"
 
@@ -333,6 +335,8 @@
         http_var_t *var;
         client_t *client;
         int bytes;
+	struct stat statbuf;
+	char	fullPath[4096];
 
         while (global.running == ICE_RUNNING) {
                 memset(header, 0, 4096);
@@ -437,6 +441,27 @@
                                         if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/stats.xml") == 0) {
                                                 printf("sending stats.xml\n");
                                                 stats_sendxml(client);
+                        client_destroy(client);
+						continue;
+					}
+
+					/* Here we are parsing the URI request to see
+					** if the extension is .xsl, if so, then process
+					** this request as an XSLT request
+					*/
+					if (util_check_valid_extension(httpp_getvar(parser, HTTPP_VAR_URI)) == XSLT_CONTENT) {
+						util_get_full_path(httpp_getvar(parser, HTTPP_VAR_URI), fullPath, sizeof(fullPath));
+							
+						/* If the file exists, then transform it, otherwise, write a 404 error */
+						if (stat(fullPath, &statbuf) == 0) {
+							sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
+                            stats_transform_xslt(client, fullPath);
+						}
+						else {
+							sock_write(client->con->sock, "HTTP/1.0 404 File Not Found\r\nContent-Type: text/html\r\n\r\n"\
+								   "<b>The file you requested could not be found.</b>\r\n");
+						}
+						client_destroy(client);
                                                 continue;
                                         }
 

<p><p>1.16      +40 -0     icecast/src/stats.c

Index: stats.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- stats.c	29 Jun 2002 04:29:37 -0000	1.15
+++ stats.c	9 Aug 2002 06:52:07 -0000	1.16
@@ -18,6 +18,7 @@
 #include "refbuf.h"
 #include "client.h"
 #include "stats.h"
+#include "xslt.h"
 
 #ifdef _WIN32
 #define vsnprintf _vsnprintf
@@ -728,6 +729,45 @@
         return node->node;
 }
 
+void stats_transform_xslt(client_t *client, char *xslpath)
+{
+    xmlDocPtr doc;
+
+    stats_get_xml(&doc);
+
+    transformXSLT(doc, xslpath, client);
+
+    xmlFreeDoc(doc);
+}
+
+void stats_get_xml(xmlDocPtr *doc)
+{
+	stats_event_t *event;
+	stats_event_t *queue;
+	xmlNodePtr node, srcnode;
+	source_xml_t *src_nodes = NULL;
+
+	queue = NULL;
+	_dump_stats_to_queue(&queue);
+
+	*doc = xmlNewDoc("1.0");
+	node = xmlNewDocNode(*doc, NULL, "icestats", NULL);
+	xmlDocSetRootElement(*doc, node);
+
+
+	event = _get_event_from_queue(&queue);
+	while (event) {
+		if (event->source == NULL) {
+			xmlNewChild(node, NULL, event->name, event->value);
+		} else {
+			srcnode = _find_xml_node(event->source, &src_nodes, node);
+			xmlNewChild(srcnode, NULL, event->name, event->value);
+		}
+
+		_free_event(event);
+		event = _get_event_from_queue(&queue);
+	}
+}
 void stats_sendxml(client_t *client)
 {
         int bytes;

<p><p>1.4       +6 -0      icecast/src/stats.h

Index: stats.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- stats.h	11 Feb 2002 09:11:17 -0000	1.3
+++ stats.h	9 Aug 2002 06:52:07 -0000	1.4
@@ -4,6 +4,10 @@
 #include "connection.h"
 #include "httpp.h"
 #include "client.h"
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
 
 typedef struct _stats_connection_tag
 {
@@ -70,7 +74,9 @@
 void *stats_connection(void *arg);
 void *stats_callback(void *arg);
 
+void stats_transform_xslt(client_t *client, char *xslpath);
 void stats_sendxml(client_t *client);
+void stats_get_xml(xmlDocPtr *doc);
 
 #endif  /* __STATS_H__ */
 

<p><p>1.5       +47 -0     icecast/src/util.c

Index: util.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- util.c	24 Jul 2002 14:52:28 -0000	1.4
+++ util.c	9 Aug 2002 06:52:07 -0000	1.5
@@ -1,4 +1,6 @@
 #include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
 
 #ifndef _WIN32
 #include <sys/time.h>
@@ -10,12 +12,17 @@
 #else
 #include <winsock2.h>
 #include <windows.h>
+#include <stdio.h>
+#define snprintf _snprintf
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
 #endif
 
 #include "sock.h"
 
 #include "config.h"
 #include "util.h"
+#include "os.h"
 
 /* Abstract out an interface to use either poll or select depending on which
  * is available (poll is preferred) to watch a single fd.
@@ -85,6 +92,46 @@
         return ret;
 }
 
+int util_get_full_path(char *uri, char *fullPath, int fullPathLen) {
+	int ret = 0;
+	if (uri) {
+		memset(fullPath, '\000', fullPathLen);
+		snprintf(fullPath, fullPathLen-1, "%s%s%s", config_get_config()->webroot_dir, PATH_SEPARATOR, uri);
+		ret = 1;
+	}
+	return ret;
+}
 
+int util_check_valid_extension(char *uri) {
+	int	ret = 0;
+	char	*p2;
+
+	if (uri) {
+		p2 = strrchr(uri, '.');
+		if (p2) {
+			p2++;
+			if (strncmp(p2, "xsl", strlen("xsl")) == 0) {
+				/* Build the full path for the request, concatenating the webroot from the config.
+				** Here would be also a good time to prevent accesses like '../../../../etc/passwd' or somesuch.
+				*/
+				ret = XSLT_CONTENT;
+			}
+			if (strncmp(p2, "htm", strlen("htm")) == 0) {
+				/* Build the full path for the request, concatenating the webroot from the config.
+				** Here would be also a good time to prevent accesses like '../../../../etc/passwd' or somesuch.
+				*/
+				ret = HTML_CONTENT;
+			}
+			if (strncmp(p2, "html", strlen("html")) == 0) {
+				/* Build the full path for the request, concatenating the webroot from the config.
+				** Here would be also a good time to prevent accesses like '../../../../etc/passwd' or somesuch.
+				*/
+				ret = HTML_CONTENT;
+			}
+
+		}
+	}
+	return ret;
+}
 
 

<p><p>1.3       +5 -0      icecast/src/util.h

Index: util.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- util.h	24 Jul 2002 14:52:28 -0000	1.2
+++ util.h	9 Aug 2002 06:52:07 -0000	1.3
@@ -1,7 +1,12 @@
 #ifndef __UTIL_H__
 #define __UTIL_H__
 
+#define XSLT_CONTENT 1
+#define HTML_CONTENT 2
+
 int util_timed_wait_for_fd(int fd, int timeout);
 int util_read_header(int sock, char *buff, unsigned long len);
+int util_get_full_path(char *uri, char *fullPath, int fullPathLen);
+int util_check_valid_extension(char *uri);
 
 #endif  /* __UTIL_H__ */

<p><p>1.12      +1 -6      thread/thread.c

Index: thread.c
===================================================================
RCS file: /usr/local/cvsroot/thread/thread.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- thread.c	5 Aug 2002 14:48:03 -0000	1.11
+++ thread.c	9 Aug 2002 06:52:07 -0000	1.12
@@ -115,11 +115,6 @@
 {
         thread_t *thread;
 
-	/* this must be called to init pthreads-win32 */
-#ifdef _WIN32
-	ptw32_processInitialize();
-#endif
-
         /* set up logging */
 
         log_initialize();
@@ -129,7 +124,7 @@
         log_set_level(_logid, THREAD_DEBUG);
 #endif
 
-	/* create all the interal mutexes, and initialize the mutex tree */
+	/* create all the internal mutexes, and initialize the mutex tree */
 
         _mutextree = avl_tree_new(_compare_mutexes, NULL);
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list