/usr/share/doc/red5/html/plugins.html is in red5-doc 1.0~svn4374-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter 19. Plugins</title><link rel="stylesheet" type="text/css" href="html.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Red5 - Reference Documentation"><link rel="up" href="core-components.html" title="Part II. Red5 Core Components"><link rel="prev" href="testing.html" title="Chapter 18. Testing Red5"><link rel="next" href="rtmp-specification.html" title="Appendix A. RTMP Specification"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns="http://www.w3.org/TR/xhtml1/transitional" style="background-color:white;border:none;height:73px;border:1px solid black;"><a style="border:none;" href="http://osflash.org/red5" title="Red5 Open Source Flash Server"><img style="border:none;" src="images/red5-banner.png"></img></a><a style="border:none;" href="http://osflash.org/red5" title="Red5 Open Source Flash Server"><img style="border:none;position:absolute;padding-top:5px;right:42px;" src="images/red5-banner-logo.png"></img></a></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="plugins"></a>Chapter 19. Plugins</h2></div></div></div>
<p>Available in Red5 is a Plugin architecture system to enable to extend features into Red5 for an entire server or application. Plugins are loaded on startup and then configured on a per application basis. </p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../images/admons/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top">
<p>
Currently only available via SVN trunk.
</p>
</td></tr></table></div>
<div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e2764"></a>19.1. Loading</h2></div></div></div>
<p>Plugins are compiled into jar files which will be loaded and parsed by the server on startup. </p>
<p>Path to load the plugins is in:</p>
<div class="literallayout"><p><br>
/path/to/red5/plugins<br>
</p></div>
</div>
<div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e2769"></a>19.2. Configuring</h2></div></div></div>
<p>Plugins can be configured via the application adaptor by setting a property inside the red5-web.xml config file. The plugins property has one child node which is a list of plugins to load for the application</p>
<pre class="programlisting">
<bean id="web.handler" class="org.red5.demos.oflaDemo.Application">
<property name="plugins">
<list>
...
</pre>
<p>Inside the list can be configured multiple plugins beans</p>
<pre class="programlisting">
<bean class="org.red5.server.plugin.PluginDescriptor">
<property name="pluginName" value="authPlugin"/>
<property name="pluginType" value="org.red5.server.plugin.auth.AuthPlugin"/>
<property name="method" value="getRed5AuthenticationHandler"/>
<property name="methodReturnType" value="org.red5.server.plugin.auth.Red5AuthenticationHandler"/>
</bean>
</pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<p>pluginName - the name of the plugin compiled into the plugin</p>
</li><li class="listitem">
<p>pluginType - the fully qualified name of the plugin class ie org.red5.server.plugin.auth.AuthPlugin</p>
</li><li class="listitem">
<p>method - method is a getter for a factory method as the plugin may provide multiple features ie getRed5AuthenticationHandler</p>
</li><li class="listitem">
<p>methodReturnType - methodReturnType is the fully qualified name of the plugin factory class to provider a certain feature ie org.red5.server.plugin.auth.Red5AuthenticationHandler</p>
</li></ul></div>
<p>Plugins are able to be configured with config properties using a property setter which is a spring hashmap list of values ie</p>
<pre class="programlisting">
<bean class="org.red5.server.plugin.PluginDescriptor">
<property name="pluginName" value="securityPlugin"/>
<property name="pluginType" value="org.red5.server.plugin.security.SecurityPlugin"/>
<property name="method" value="getPlaybackSecurityHandler"/>
<property name="methodReturnType" value="org.red5.server.plugin.security.PlaybackSecurityHandler"/>
<property name="properties">
<map>
<entry>
<key><value>htmlDomains</value></key>
<value>file:///path/to/allowedHTMLdomains.txt</value>
</entry>
<entry>
<key><value>swfDomains</value></key>
<value>file:///path/to/allowedSWFdomains.txt</value>
</entry>
</map>
</property>
</bean>
</pre>
<p>Where using spring map syntax each property key / value is within an entry tag</p>
<pre class="programlisting">
<entry>
<key><value>htmlDomains</value></key>
<value>file:///path/to/allowedHTMLdomains.txt</value>
</entry>
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../images/admons/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top">
<p>
Due to some issues with spring context paths loading in plugins, full absolute paths are required to files to be loaded ie file:///path/to/allowedHTMLdomains.txt
</p>
</td></tr></table></div>
</div>
<div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e2790"></a>19.3. Developing</h2></div></div></div>
<p>To begin developing a new plugin it's best to download already built ones from SVN to use as a template ie</p>
<div class="literallayout"><p><br>
http://red5.googlecode.com/svn/java/plugins/trunk/securityplugin/<br>
</p></div>
<p>To configure some ant properties to compile the plugin correctly, inside build.properties update the following</p>
<div class="literallayout"><p><br>
red5.root=/www/red5_server_xuggle_timestamp_fixes<br>
main-class=org.red5.server.plugin.security.SecurityPlugin<br>
</p></div>
<p>Where red5.root is the path to red5 and main-class is the fully qualified name of the plugin.</p>
<p>At the top of the ant build script, update the project name to the name of the plugin which will be used to generate the plugin jar file</p>
<pre class="programlisting">
<project name="securityplugin" basedir="." default="all" xmlns:ivy="antlib:org.apache.ivy.ant">
</pre>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../images/admons/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top">
<p>
Make sure the following ant property is set to either the main-class property or static to the plugin fully qualified name. If this is not setup correctly the Plugin loader will detect there is no manifest and not load the plugin.
<attribute name="Red5-Plugin-Main-Class" value="${main-class}"/>
</p>
</td></tr></table></div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e2801"></a>19.3.1. Plugin Main Class</h3></div></div></div>
<p>The plugin main class requires to extend the Red5Plugin base class which the plugin loader will then use this as the main class for loading the plugin and factory methods. </p>
<pre class="programlisting">
public class SecurityPlugin extends Red5Plugin {
private static Logger log = Red5LoggerFactory.getLogger(SecurityPlugin.class, "plugins");
private static Serializer serializer = new Serializer();
private MultiThreadedApplicationAdapter application;
public void doStart() throws Exception {
log.debug("Start");
}
public void doStop() throws Exception {
log.debug("Stop");
}
public String getName() {
return "securityPlugin";
}
public void setApplication(MultiThreadedApplicationAdapter app) {
log.trace("Setting application adapter: {}", app);
this.application = app;
}
//methods specific to this plug-in
public PlaybackSecurityHandler getPlaybackSecurityHandler() {
PlaybackSecurityHandler ph = null;
try {
ph = (PlaybackSecurityHandler) Class.forName("org.red5.server.plugin.security.PlaybackSecurityHandler").newInstance();
ph.setApplication(application);
} catch (Exception e) {
log.error("PlaybackSecurityHandler could not be loaded", e);
}
return ph;
}
public PublishSecurityHandler getPublishSecurityHandler() {
PublishSecurityHandler ps = null;
try {
ps = (PublishSecurityHandler) Class.forName("org.red5.server.plugin.security.PublishSecurityHandler").newInstance();
ps.setApplication(application);
} catch (Exception e) {
log.error("PublishSecurityHandler could not be loaded", e);
}
return ps;
}
public SharedObjectSecurityHandler getSharedObjectSecurityHandler() {
SharedObjectSecurityHandler sh = null;
try {
sh = (SharedObjectSecurityHandler) Class.forName("org.red5.server.plugin.security.SharedObjectSecurityHandler").newInstance();
sh.setApplication(application);
} catch (Exception e) {
log.error("SharedObjectSecurityHandler could not be loaded", e);
}
return sh;
}
//common methods
/**
* Invokes the "onStatus" event on the client, passing our derived status.
*
* @param conn
* @param status
*/
public static void writeStatus(IConnection conn, StatusObject status) {
//make a buffer to put our data in
IoBuffer buf = IoBuffer.allocate(128);
buf.setAutoExpand(true);
//create amf output
Output out = new Output(buf);
//mark it as an amf object
buf.put(AMF.TYPE_OBJECT);
//serialize our status
status.serialize(out, serializer);
//write trailer
buf.put((byte) 0x00);
buf.put((byte) 0x00);
buf.put(AMF.TYPE_END_OF_OBJECT);
//make the buffer read to be read
buf.flip();
//create an RTMP event of Notify type
IRTMPEvent event = new Notify(buf);
//construct a packet
Header header = new Header();
Packet packet = new Packet(header, event);
//get our stream id
int streamId = BaseRTMPHandler.getStreamId();
//set channel to "data" which im pretty sure is 3
header.setChannelId(3);
header.setTimer(event.getTimestamp()); //0
header.setStreamId(streamId);
header.setDataType(event.getDataType());
//write to the client
((RTMPConnection) conn).write(packet);
}
}
</pre>
<p>The getter method getName is required to be set so the plugin can be identified and loaded correctly using the plugin config in the application</p>
<pre class="programlisting">
public String getName() {
return "securityPlugin";
}
</pre>
<pre class="programlisting">
public void doStart() throws Exception {
log.debug("Start");
}
public void doStop() throws Exception {
log.debug("Stop");
}
public String getName() {
return "securityPlugin";
}
public void setApplication(MultiThreadedApplicationAdapter app) {
log.trace("Setting application adapter: {}", app);
this.application = app;
}
</pre>
<p>Other methods are doStart , doStop and setApplication setter method which is required to set a reference to the loaded application. </p>
<p>The plugin factory method is required to be configured and return a reference to the factory class which is then loaded in the application config. A reference to the application can also be set if desired so the factory method class can manipulate methods and properties on the application.</p>
<pre class="programlisting">
public PlaybackSecurityHandler getPlaybackSecurityHandler() {
PlaybackSecurityHandler ph = null;
try {
ph = (PlaybackSecurityHandler) Class.forName("org.red5.server.plugin.security.PlaybackSecurityHandler").newInstance();
ph.setApplication(application);
} catch (Exception e) {
log.error("PlaybackSecurityHandler could not be loaded", e);
}
return ph;
}
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e2811"></a>19.3.2. Factory Method Class</h3></div></div></div>
<p>The factory method class is what gets configured to load and is where the features to run happen. It is required to extend the ApplicationLifeCycle class as well as implement the IRed5PluginHandler interface.</p>
<pre class="programlisting">
public abstract class SecurityBase extends ApplicationLifecycle implements IRed5PluginHandler {
...
</pre>
<p>Setter methods for both application and properties is required so the class is able to get a reference to the application as well as have property configs set.</p>
<pre class="programlisting">
public void setApplication(MultiThreadedApplicationAdapter app) {
application = app;
}
public void setProperties(Map<String, Object> props) {
properties = props;
}
}
</pre>
<p>An init method is required to be overridden to enable the factory class to start and then enable features and manipulate the application</p>
<pre class="programlisting">
@Override
public void init() {
if (properties.containsKey("htmlDomains")) {
htmlDomains = properties.get("htmlDomains").toString();
}
if (properties.containsKey("swfDomains")) {
swfDomains = properties.get("swfDomains").toString();
}
allowedHTMLDomains = readValidDomains(htmlDomains, "HTMLDomains");
// Populating the list of domains which are allowed to host a SWF file
// which may connect to this application
allowedSWFDomains = readValidDomains(swfDomains, "SWFDomains");
// Logging
if (HTMLDomainsAuth) {
log.debug("Authentication of HTML page URL domains is enabled");
}
if (SWFDomainsAuth) {
log.debug("Authentication of SWF URL domains is enabled");
}
log.debug("...loading completed.");
//now register with the application
application.registerStreamPlaybackSecurity(this);
}
</pre>
</div>
</div>
</div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="testing.html">Prev</a> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right"> <a accesskey="n" href="rtmp-specification.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 18. Testing Red5 </td><td width="20%" align="center"><span style="color:white;font-size:90%;"><a href="http://osflash.org/red5" title="Red5">Red5 Open Source Flash Server</a></span></td><td width="40%" align="right" valign="top"> Appendix A. RTMP Specification</td></tr></table></div></body></html>
|