Repository: ossrs/srs
File: trunk/src/app/srs_app_http_static.cpp (C++)

Code before:
using namespace std;

#include <srs_protocol_stream.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_st.hpp>
#include <srs_core_autofree.hpp>
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_rtmp_stack.hpp>
#include <srs_app_source.hpp>
#include <srs_rtmp_msg_array.hpp>
#include <srs_kernel_aac.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_source.hpp>
#include <srs_app_server.hpp>
#include <srs_service_utility.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_statistic.hpp>

#define SRS_SECRET_IN_HLS "srs_secret"

SrsVodStream::SrsVodStream(string root_dir) : SrsHttpFileServer(root_dir)
{
    _srs_hybrid->timer5s()->subscribe(this);
}

SrsVodStream::~SrsVodStream()
{
    _srs_hybrid->timer5s()->unsubscribe(this);
    std::map<std::string, SrsRequest*>::iterator it;
    for (it = map_secret_req_.begin(); it != map_secret_req_.end(); ++it) {
        srs_freep(it->second);
    }
    map_secret_req_.clear();
    map_secret_validity_.clear();
}

srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int offset)
{
    srs_error_t err = srs_success;
    
    SrsFileReader* fs = fs_factory->create_file_reader();
    SrsAutoFree(SrsFileReader, fs);
    
    // open flv file

Review comment (security):
secret' feels like it would be better to change the name. My first reaction is always "key"... If you don't look closely, you might think this is some kind of authentication code. Maybe changing it to 'userid', 'uniqueid', or 'magicid' would be better?

`TRANS_BY_GPT3`

Code after:
using namespace std;

#include <srs_protocol_stream.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_st.hpp>
#include <srs_core_autofree.hpp>
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_rtmp_stack.hpp>
#include <srs_app_source.hpp>
#include <srs_rtmp_msg_array.hpp>
#include <srs_kernel_aac.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_source.hpp>
#include <srs_app_server.hpp>
#include <srs_service_utility.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_statistic.hpp>

#define SRS_CONTEXT_IN_HLS "hls_ctx"

SrsVodStream::SrsVodStream(string root_dir) : SrsHttpFileServer(root_dir)
{
    _srs_hybrid->timer5s()->subscribe(this);
}

SrsVodStream::~SrsVodStream()
{
    _srs_hybrid->timer5s()->unsubscribe(this);
    std::map<std::string, SrsM3u8CtxInfo>::iterator it;
    for (it = map_ctx_info_.begin(); it != map_ctx_info_.end(); ++it) {
        srs_freep(it->second.req);
    }
    map_ctx_info_.clear();
}

srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int offset)
{
    srs_error_t err = srs_success;
    
    SrsFileReader* fs = fs_factory->create_file_reader();
    SrsAutoFree(SrsFileReader, fs);
    
    // open flv file
    if ((err = fs->open(fullpath)) != srs_success) {