[xmppd-dev] commit r1546 - in branches/RELEASE-1_6_1: . jabberd

mail at jabberd.org mail at jabberd.org
Mon Dec 8 19:04:35 CET 2008


Author: mawis
Date: Mon Dec  8 19:04:35 2008
New Revision: 1546

Log:
Support for Flash cross-domain-policy
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

Modified:
   branches/RELEASE-1_6_1/ChangeLog
   branches/RELEASE-1_6_1/jabber.xml.dist.in
   branches/RELEASE-1_6_1/jabberd/jabberd.h
   branches/RELEASE-1_6_1/jabberd/mio.cc
   branches/RELEASE-1_6_1/jabberd/mio_xml.cc

Modified: branches/RELEASE-1_6_1/ChangeLog
==============================================================================
--- branches/RELEASE-1_6_1/ChangeLog	Mon Dec  8 18:03:20 2008	(r1545)
+++ branches/RELEASE-1_6_1/ChangeLog	Mon Dec  8 19:04:35 2008	(r1546)
@@ -1,6 +1,7 @@
 2008-12-08  Matthias Wimmer  <m at tthias.eu>
 
-    * jabberd/mio_xml.cc: implemented mini-HTTP-server in jabberd14
+    * jabberd/mio_xml.cc: implemented mini-HTTP-server and additional flash
+	support (returning of cross-domain-policies) in jabberd14
     * jabberd/mio.cc: same
     * jabberd/jabberd.h: same
 

Modified: branches/RELEASE-1_6_1/jabber.xml.dist.in
==============================================================================
--- branches/RELEASE-1_6_1/jabber.xml.dist.in	Mon Dec  8 18:03:20 2008	(r1545)
+++ branches/RELEASE-1_6_1/jabber.xml.dist.in	Mon Dec  8 19:04:35 2008	(r1546)
@@ -1097,6 +1097,14 @@
     <mini-webserver>@localstatedir@/lib/jabberd/mini-webserver</mini-webserver>
     <bounce>http://www.example.com/</bounce>
     -->
+
+    <!-- The next option can be used to configure a cross-domain-policy -->
+    <!-- file, that is returned for flash clients. For more details     -->
+    <!-- about the flash basics on this, please look at:		-->
+    <!-- http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html -->
+    <!--
+    <flash-policy-file>@localstatedir@/lib/jabberd/cross-domain-policy.xml</flash-policy-file>
+    -->
   </io>
 
   <!-- Global configuration settings, affect a complete jabberd14	-->

Modified: branches/RELEASE-1_6_1/jabberd/jabberd.h
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/jabberd.h	Mon Dec  8 18:03:20 2008	(r1545)
+++ branches/RELEASE-1_6_1/jabberd/jabberd.h	Mon Dec  8 19:04:35 2008	(r1546)
@@ -414,6 +414,7 @@
     int rate_t, rate_p; /**< default rate, if any */
     char const* bounce_uri;	/**< where to bounce HTTP requests to */
     char const* webserver_path;	/**< location where small HTTP requests are handled from */
+    char const* flash_policy;	/**< location of the flash policy file */
 } _ios,*ios;
 
 /* MIO SOCKET HANDLERS */

Modified: branches/RELEASE-1_6_1/jabberd/mio.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/mio.cc	Mon Dec  8 18:03:20 2008	(r1545)
+++ branches/RELEASE-1_6_1/jabberd/mio.cc	Mon Dec  8 19:04:35 2008	(r1546)
@@ -1120,6 +1120,7 @@
     // HTTP configuration
     mio__data->bounce_uri = pstrdup(mio__data->p, xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(io, "bounce", namespaces, temp_pool), 0)));
     mio__data->webserver_path = pstrdup(mio__data->p, xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(io, "mini-webserver", namespaces, temp_pool), 0)));
+    mio__data->flash_policy = pstrdup(mio__data->p, xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(io, "flash-policy", namespaces, temp_pool), 0)));
 
     if (karma != NULL) {
         mio__data->k->val	  = j_atoi(xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(karma, "init", namespaces, temp_pool), 0)), KARMA_INIT);

Modified: branches/RELEASE-1_6_1/jabberd/mio_xml.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/mio_xml.cc	Mon Dec  8 18:03:20 2008	(r1545)
+++ branches/RELEASE-1_6_1/jabberd/mio_xml.cc	Mon Dec  8 19:04:35 2008	(r1546)
@@ -446,6 +446,47 @@
 	    // we handled the request now
 	    return;
 	}
+
+	// check for Flash policy requests
+	if (first_line.substr(0, 20) == "<policy-file-request") {
+	    // is there a configured flash policy?
+	    if (mio__data->flash_policy) {
+		struct stat stat_buf;
+		int stat_ret = ::stat(mio__data->flash_policy, &stat_buf);
+		if (stat_ret == 0 && S_ISREG(stat_buf.st_mode)) {
+		    // try to open file
+		    std::ifstream file(mio__data->flash_policy, std::ifstream::binary);
+		    if (file.is_open()) {
+			// get the file size
+			file.seekg(0, std::ios::end);
+			std::streampos file_size = file.tellg();
+			file.seekg(0, std::ios::beg);
+
+
+			if (file_size < 1024*1024) {
+			    char *result_buffer = new char[file_size];
+			    file.read(result_buffer, file_size);
+			    mio_write(m, NULL, result_buffer, file_size);
+			    delete[] result_buffer;
+
+			    mio_close(m);
+			    file.close();
+			    return;
+			}
+
+			log_warn(NULL, "Flash policy file is too big for being returned to the flash client.");
+			file.close();
+		    }
+		}
+	    }
+
+	    // no configured flash policy, or policy too big. Send default
+	    log_notice(NULL, "Received Flash policy-file-request, but none is configured. Returning (empty) default policy.");
+	    mio_write(m, NULL, "<?xml version='1.0'?>\n<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\n<cross-domain-policy/>\n", -1);
+	    mio_close(m);
+	    return;
+
+	}
     }
 
     /* XXX more http hack to catch the end of the headers */


More information about the dev mailing list