Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
ec18573c
Commit
ec18573c
authored
Jun 08, 2011
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor of publisher to put post handler in a different function to be reusable
parent
7777234d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
35 deletions
+45
-35
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+1
-1
ngx_http_push_stream_module_publisher.c
src/ngx_http_push_stream_module_publisher.c
+44
-34
No files found.
include/ngx_http_push_stream_module.h
View file @
ec18573c
...
@@ -206,7 +206,7 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_ALLOW = ngx_string("Allow");
...
@@ -206,7 +206,7 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_ALLOW = ngx_string("Allow");
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_HEADER_EXPLAIN
=
ngx_string
(
"X-Nginx-PushStream-Explain"
);
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_HEADER_EXPLAIN
=
ngx_string
(
"X-Nginx-PushStream-Explain"
);
// other stuff
// other stuff
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_ALLOW
ED
_METHODS
=
ngx_string
(
"GET, POST"
);
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_ALLOW
_GET_POST
_METHODS
=
ngx_string
(
"GET, POST"
);
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_ALLOW_GET
=
ngx_string
(
"GET"
);
static
const
ngx_str_t
NGX_HTTP_PUSH_STREAM_ALLOW_GET
=
ngx_string
(
"GET"
);
#define NGX_HTTP_PUSH_STREAM_CHECK_AND_FINALIZE_REQUEST_ON_ERROR(val, fail, r, errormessage) \
#define NGX_HTTP_PUSH_STREAM_CHECK_AND_FINALIZE_REQUEST_ON_ERROR(val, fail, r, errormessage) \
...
...
src/ngx_http_push_stream_module_publisher.c
View file @
ec18573c
...
@@ -25,10 +25,11 @@
...
@@ -25,10 +25,11 @@
#include <ngx_http_push_stream_module_publisher.h>
#include <ngx_http_push_stream_module_publisher.h>
static
ngx_int_t
ngx_http_push_stream_publisher_handle_post
(
ngx_http_push_stream_loc_conf_t
*
cf
,
ngx_http_request_t
*
r
,
ngx_str_t
*
id
);
static
ngx_int_t
static
ngx_int_t
ngx_http_push_stream_publisher_handler
(
ngx_http_request_t
*
r
)
ngx_http_push_stream_publisher_handler
(
ngx_http_request_t
*
r
)
{
{
ngx_int_t
rc
;
ngx_str_t
*
id
=
NULL
;
ngx_str_t
*
id
=
NULL
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
...
@@ -38,7 +39,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
...
@@ -38,7 +39,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
// only accept GET and POST methods
// only accept GET and POST methods
if
(
!
(
r
->
method
&
(
NGX_HTTP_GET
|
NGX_HTTP_POST
)))
{
if
(
!
(
r
->
method
&
(
NGX_HTTP_GET
|
NGX_HTTP_POST
)))
{
ngx_http_push_stream_add_response_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_ALLOW
,
&
NGX_HTTP_PUSH_STREAM_ALLOW
ED
_METHODS
);
ngx_http_push_stream_add_response_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_ALLOW
,
&
NGX_HTTP_PUSH_STREAM_ALLOW
_GET_POST
_METHODS
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_NOT_ALLOWED
,
NULL
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_NOT_ALLOWED
,
NULL
);
}
}
...
@@ -59,47 +60,56 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
...
@@ -59,47 +60,56 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
channel
=
ngx_http_push_stream_find_channel
(
id
,
r
->
connection
->
log
);
channel
=
ngx_http_push_stream_find_channel
(
id
,
r
->
connection
->
log
);
if
(
r
->
method
==
NGX_HTTP_POST
)
{
if
(
r
->
method
==
NGX_HTTP_POST
)
{
// check if channel id isn't equals to ALL
return
ngx_http_push_stream_publisher_handle_post
(
cf
,
r
,
id
);
if
(
ngx_memn2cmp
(
id
->
data
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
data
,
id
->
len
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
len
)
==
0
)
{
}
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_NOT_AUTHORIZED_MESSAGE
);
}
// create the channel if doesn't exist
// GET only make sense with a previous existing channel
channel
=
ngx_http_push_stream_get_channel
(
id
,
r
->
connection
->
log
,
cf
);
if
(
channel
==
NULL
)
{
if
(
channel
==
NULL
)
{
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_NOT_FOUND
,
NULL
);
ngx_log_error
(
NGX_LOG_ERR
,
(
r
)
->
connection
->
log
,
0
,
"push stream module: unable to allocate memory for new channel"
);
}
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
,
NULL
);
}
if
(
channel
==
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED
)
{
return
ngx_http_push_stream_send_response_channel_info
(
r
,
channel
);
ngx_log_error
(
NGX_LOG_ERR
,
(
r
)
->
connection
->
log
,
0
,
"push stream module: number of channels were exceeded"
);
}
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED_MESSAGE
);
}
/*
static
ngx_int_t
* Instruct ngx_http_read_subscriber_request_body to store the request
ngx_http_push_stream_publisher_handle_post
(
ngx_http_push_stream_loc_conf_t
*
cf
,
ngx_http_request_t
*
r
,
ngx_str_t
*
id
)
* body entirely in a memory buffer or in a file.
{
*/
ngx_int_t
rc
;
r
->
request_body_in_single_buf
=
0
;
ngx_http_push_stream_channel_t
*
channel
=
NULL
;
r
->
request_body_in_persistent_file
=
1
;
r
->
request_body_in_clean_file
=
0
;
r
->
request_body_file_log_level
=
0
;
// parse the body message and return
rc
=
ngx_http_read_client_request_body
(
r
,
ngx_http_push_stream_publisher_body_handler
);
if
(
rc
>=
NGX_HTTP_SPECIAL_RESPONSE
)
{
return
rc
;
}
return
NGX_DONE
;
// check if channel id isn't equals to ALL
if
(
ngx_memn2cmp
(
id
->
data
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
data
,
id
->
len
,
NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID
.
len
)
==
0
)
{
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_NOT_AUTHORIZED_MESSAGE
);
}
}
// GET only make sense with a previous existing channel
// create the channel if doesn't exist
channel
=
ngx_http_push_stream_get_channel
(
id
,
r
->
connection
->
log
,
cf
);
if
(
channel
==
NULL
)
{
if
(
channel
==
NULL
)
{
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_NOT_FOUND
,
NULL
);
ngx_log_error
(
NGX_LOG_ERR
,
(
r
)
->
connection
->
log
,
0
,
"push stream module: unable to allocate memory for new channel"
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_INTERNAL_SERVER_ERROR
,
NULL
);
}
}
return
ngx_http_push_stream_send_response_channel_info
(
r
,
channel
);
if
(
channel
==
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED
)
{
ngx_log_error
(
NGX_LOG_ERR
,
(
r
)
->
connection
->
log
,
0
,
"push stream module: number of channels were exceeded"
);
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_FORBIDDEN
,
&
NGX_HTTP_PUSH_STREAM_NUMBER_OF_CHANNELS_EXCEEDED_MESSAGE
);
}
/*
* Instruct ngx_http_read_subscriber_request_body to store the request
* body entirely in a memory buffer or in a file.
*/
r
->
request_body_in_single_buf
=
0
;
r
->
request_body_in_persistent_file
=
1
;
r
->
request_body_in_clean_file
=
0
;
r
->
request_body_file_log_level
=
0
;
// parse the body message and return
rc
=
ngx_http_read_client_request_body
(
r
,
ngx_http_push_stream_publisher_body_handler
);
if
(
rc
>=
NGX_HTTP_SPECIAL_RESPONSE
)
{
return
rc
;
}
return
NGX_DONE
;
}
}
static
void
static
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment