static ngx_int_t ngx_http_push_stream_channels_statistics_handler(ngx_http_request_t *r) { char *pos = NULL; ngx_str_t *id = 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); r->keepalive = cf->keepalive; ngx_http_push_stream_set_expires(r, NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH, 0); // only accept GET method if (!(r->method & NGX_HTTP_GET)) { ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET); return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL); } ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_TAG, &NGX_HTTP_PUSH_STREAM_TAG); ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_COMMIT, &NGX_HTTP_PUSH_STREAM_COMMIT); // get and check channel id value id = ngx_http_push_stream_get_channel_id(r, cf); if ((id == NULL) || (id == NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID)) { if (id == NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID) { return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_BAD_REQUEST, &NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID_MESSAGE); } return NGX_HTTP_INTERNAL_SERVER_ERROR; } // if not specify a channel id, get info about all channels in a resumed way if (id == NGX_HTTP_PUSH_STREAM_UNSET_CHANNEL_ID) { return ngx_http_push_stream_send_response_all_channels_info_summarized(r); } if ((pos = ngx_strchr(id->data, '*')) != NULL) { ngx_str_t *aux = NULL; if (pos != (char *) id->data) { *pos = '\0'; id->len = ngx_strlen(id->data); aux = id; } return ngx_http_push_stream_send_response_all_channels_info_detailed(r, aux); } // if specify a channel id equals to ALL, get info about all channels in a detailed way 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_response_all_channels_info_detailed(r, NULL); } // if specify a channel id != ALL, get info about specified channel if it exists // search for a existing channel with this id channel = ngx_http_push_stream_find_channel(id, r->connection->log); if (channel == NULL) { return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_FOUND, NULL); } return ngx_http_push_stream_send_response_channel_info(r, channel); }
static ngx_int_t ngx_http_push_stream_channels_statistics_handler(ngx_http_request_t *r) { ngx_http_push_stream_main_conf_t *mcf = ngx_http_get_module_main_conf(r, ngx_http_push_stream_module); char *pos = NULL; ngx_http_push_stream_requested_channel_t *requested_channels, *requested_channel; ngx_queue_t *q; ngx_http_push_stream_set_expires(r, NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH, 0); // only accept GET method if (!(r->method & NGX_HTTP_GET)) { ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET); return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL); } ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_TAG, &NGX_HTTP_PUSH_STREAM_TAG); ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_COMMIT, &NGX_HTTP_PUSH_STREAM_COMMIT); //get channels ids requested_channels = ngx_http_push_stream_parse_channels_ids_from_path(r, r->pool); // if not specify a channel id, get info about all channels in a resumed way if ((requested_channels == NULL) || ngx_queue_empty(&requested_channels->queue)) { return ngx_http_push_stream_send_response_all_channels_info_summarized(r); } for (q = ngx_queue_head(&requested_channels->queue); q != ngx_queue_sentinel(&requested_channels->queue); q = ngx_queue_next(q)) { requested_channel = ngx_queue_data(q, ngx_http_push_stream_requested_channel_t, queue); // could not have a large size if ((mcf->max_channel_id_length != NGX_CONF_UNSET_UINT) && (requested_channel->id->len > mcf->max_channel_id_length)) { ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: channel id is larger than allowed %d", requested_channel->id->len); return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_BAD_REQUEST, &NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID_MESSAGE); } if ((pos = ngx_strchr(requested_channel->id->data, '*')) != NULL) { ngx_str_t *aux = NULL; if (pos != (char *) requested_channel->id->data) { *pos = '\0'; requested_channel->id->len = ngx_strlen(requested_channel->id->data); aux = requested_channel->id; } return ngx_http_push_stream_send_response_all_channels_info_detailed(r, aux); } // if specify a channel id equals to ALL, get info about all channels in a detailed way if (ngx_memn2cmp(requested_channel->id->data, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.data, requested_channel->id->len, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.len) == 0) { return ngx_http_push_stream_send_response_all_channels_info_detailed(r, NULL); } requested_channel->channel = ngx_http_push_stream_find_channel(requested_channel->id, r->connection->log, mcf); } // if specify a channels ids != ALL, get info about specified channels if they exists return ngx_http_push_stream_send_response_channels_info_detailed(r, requested_channels); }