1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

use system utility for string finds

This commit is contained in:
winlin 2015-10-13 16:06:37 +08:00
parent ca73534d7e
commit d9f991ed2f
16 changed files with 111 additions and 112 deletions

View file

@ -377,11 +377,7 @@ int SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r,
}
if (true) {
size_t pos;
std::string ext = fullpath;
if ((pos = ext.rfind(".")) != string::npos) {
ext = ext.substr(pos);
}
std::string ext = srs_path_filext(fullpath);
if (_mime.find(ext) == _mime.end()) {
w->header()->set_content_type("application/octet-stream");

View file

@ -44,7 +44,7 @@ using namespace std;
void srs_discovery_tc_url(
string tcUrl,
string& schema, string& host, string& vhost,
string& app, int& port, std::string& param
string& app, int& port, string& param
) {
size_t pos = std::string::npos;
std::string url = tcUrl;
@ -229,7 +229,7 @@ int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, in
return ret;
}
std::string srs_generate_stream_url(std::string vhost, std::string app, std::string stream)
string srs_generate_stream_url(string vhost, string app, string stream)
{
std::string url = "";
@ -244,6 +244,18 @@ std::string srs_generate_stream_url(std::string vhost, std::string app, std::str
return url;
}
void srs_parse_rtmp_url(string url, string& tcUrl, string& stream)
{
size_t pos;
if ((pos = url.rfind("/")) != string::npos) {
stream = url.substr(pos + 1);
tcUrl = url.substr(0, pos);
} else {
tcUrl = url;
}
}
string srs_generate_rtmp_url(string server, int port, string vhost, string app, string stream)
{
std::stringstream ss;

View file

@ -101,16 +101,34 @@ extern bool srs_bytes_equals(void* pa, void* pb, int size);
* @param data the packet bytes. user should never free it.
* @param ppmsg output the shared ptr message. user should free it.
*/
extern int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, int stream_id, SrsSharedPtrMessage** ppmsg);
extern int srs_rtmp_create_msg(
char type, u_int32_t timestamp, char* data, int size, int stream_id,
SrsSharedPtrMessage** ppmsg
);
// get the stream identify, vhost/app/stream.
extern std::string srs_generate_stream_url(std::string vhost, std::string app, std::string stream);
extern std::string srs_generate_stream_url(
std::string vhost, std::string app, std::string stream
);
// parse the rtmp url to tcUrl/stream,
// for example, rtmp://v.ossrs.net/live/livestream to
// tcUrl: rtmp://v.ossrs.net/live
// stream: livestream
extern void srs_parse_rtmp_url(
std::string url, std::string& tcUrl, std::string& stream
);
// genereate the rtmp url, for instance, rtmp://server:port/app...vhost...vhost/stream
extern std::string srs_generate_rtmp_url(std::string server, int port, std::string vhost, std::string app, std::string stream);
extern std::string srs_generate_rtmp_url(
std::string server, int port, std::string vhost, std::string app, std::string stream
);
// write large numbers of iovs.
extern int srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite = NULL);
extern int srs_write_large_iovs(
ISrsProtocolReaderWriter* skt, iovec* iovs, int size,
ssize_t* pnwrite = NULL
);
#endif

View file

@ -988,10 +988,7 @@ int SrsRtspStack::do_recv_message(SrsRtspRequest* req)
// for setup, parse the stream id from uri.
if (req->is_setup()) {
size_t pos = string::npos;
std::string stream_id;
if ((pos = req->uri.rfind("/")) != string::npos) {
stream_id = req->uri.substr(pos + 1);
}
std::string stream_id = srs_path_basename(req->uri);
if ((pos = stream_id.find("=")) != string::npos) {
stream_id = stream_id.substr(pos + 1);
}