Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bfg/1505787 to your computer and use it in GitHub Desktop.
Save bfg/1505787 to your computer and use it in GitHub Desktop.
CodeShop ngx_http_smooth_streaming module patch, whichs adds configuration flag ism_rewrite_engine {on=default|off}; You can disable built-in rewrite engine with this patch. Applies to version 1.4.24; sample configuration: http://pastebin.com/HY9Wy6TD
diff -ur orig.nginx_mod_smooth_streaming-1.4.24/src/ngx_http_streaming_module.c nginx_mod_smooth_streaming-1.4.24/src/ngx_http_streaming_module.c
--- orig.nginx_mod_smooth_streaming-1.4.24/src/ngx_http_streaming_module.c 2011-04-24 16:55:51.000000000 +0200
+++ nginx_mod_smooth_streaming-1.4.24/src/ngx_http_streaming_module.c 2011-12-21 01:21:03.058062179 +0100
@@ -70,6 +70,13 @@
*/
#endif
+/**
+ * Configuration structure for the smooth streaming module.
+ */
+typedef struct {
+ ngx_flag_t rewrite_enable; /* built-in rewrite engine is enabled */
+} ngx_http_smooth_streaming_srv_conf_t;
+
static char* ngx_streaming(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
#if defined(BUILDING_SMOOTH_STREAMING)
static ngx_int_t ngx_http_streaming_init(ngx_conf_t* cf);
@@ -77,6 +84,11 @@
static ngx_int_t ngx_streaming_handler(ngx_http_request_t *r);
+static void *
+ngx_http_smooth_streaming_create_srv_conf (ngx_conf_t *cf);
+static char *
+ngx_http_smooth_streaming_merge_srv_conf (ngx_conf_t *cf, void *parent, void *child);
+
static ngx_command_t ngx_streaming_commands[] =
{
{
@@ -91,6 +103,18 @@
0,
NULL
},
+ {
+#if defined(BUILDING_H264_STREAMING)
+ ngx_string("mp4_rewrite_engine"),
+#elif defined(BUILDING_SMOOTH_STREAMING)
+ ngx_string("ism_rewrite_engine"),
+#endif
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_smooth_streaming_srv_conf_t, rewrite_enable),
+ NULL
+ },
ngx_null_command
};
@@ -106,8 +130,8 @@
NULL, /* create main configuration */
NULL, /* init main configuration */
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
+ ngx_http_smooth_streaming_create_srv_conf, /* create server configuration */
+ ngx_http_smooth_streaming_merge_srv_conf, /* merge server configuration */
NULL, /* create location configuration */
NULL /* merge location configuration */
@@ -134,6 +158,30 @@
NGX_MODULE_V1_PADDING
};
+static void *
+ngx_http_smooth_streaming_create_srv_conf (ngx_conf_t *cf)
+{
+ ngx_http_smooth_streaming_srv_conf_t *conf;
+
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_smooth_streaming_srv_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+ conf->rewrite_enable = NGX_CONF_UNSET;
+ return conf;
+}
+
+static char *
+ngx_http_smooth_streaming_merge_srv_conf (ngx_conf_t *cf, void *parent, void *child)
+{
+ ngx_http_smooth_streaming_srv_conf_t *prev = parent;
+ ngx_http_smooth_streaming_srv_conf_t *conf = child;
+
+ ngx_conf_merge_value(conf->rewrite_enable, prev->rewrite_enable, 1);
+
+ return NGX_CONF_OK;
+}
+
static ngx_int_t open_path(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
ngx_str_t *path, ngx_open_file_info_t *of)
{
@@ -228,6 +276,22 @@
char const* query_first = (char const*)r->args.data;
char const* query_last = query_first + r->args.len;
+ // get configuration
+ ngx_http_smooth_streaming_srv_conf_t *srv_cfg;
+#ifdef BUILDING_H264_STREAMING
+ srv_cfg = ngx_http_get_module_srv_conf(r, ngx_http_h264_streaming_module);
+#endif
+#ifdef BUILDING_SMOOTH_STREAMING
+ srv_cfg = ngx_http_get_module_srv_conf(r, ngx_http_smooth_streaming_module);
+#endif
+
+ // don't do anything if rewrites are disabled
+ if (!srv_cfg->rewrite_enable) {
+ //ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ // "ngx_streaming_rewrite_handler: rewrite disabled by server configuration.");
+ return NGX_DECLINED;
+ }
+
if((r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD) &&
mp4_rewrite_get(path_first, path_last, query_first, query_last,
new_path, sizeof(new_path), new_args, sizeof(new_args))) ||
@@ -260,6 +324,23 @@
ngx_open_file_info_t of;
ngx_http_core_loc_conf_t *clcf;
+ // get configuration
+ ngx_http_smooth_streaming_srv_conf_t *srv_cfg;
+#ifdef BUILDING_H264_STREAMING
+ srv_cfg = ngx_http_get_module_srv_conf(r, ngx_http_h264_streaming_module);
+#endif
+#ifdef BUILDING_SMOOTH_STREAMING
+ srv_cfg = ngx_http_get_module_srv_conf(r, ngx_http_smooth_streaming_module);
+#endif
+
+ // don't do anything if rewrites are disabled
+ if (!srv_cfg->rewrite_enable) {
+ //ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ // "ngx_streaming_post_rewrite_handler: rewrite disabled by server configuration.");
+ return NGX_DECLINED;
+ }
+
+
last = ngx_http_map_uri_to_path(r, &path, &root, 0);
if (last == NULL)
{
@@ -430,10 +511,18 @@
}
mp4_split_options_t* options = mp4_split_options_init();
- if(r->args.len && !mp4_split_options_set(options, (const char*)r->args.data, r->args.len))
- {
- mp4_split_options_exit(options);
- return NGX_DECLINED;
+ if (r->args.len) {
+ if(!mp4_split_options_set(options, (const char*)r->args.data, r->args.len))
+ {
+ mp4_split_options_exit(options);
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "Client sent smooth streaming request with unparseable query string.");
+ return NGX_DECLINED;
+ }
+ } else {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "Client sent smooth streaming request without query string.");
+ return NGX_HTTP_BAD_REQUEST;
}
log = r->connection->log;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment