diff --git a/lib/config.cpp b/lib/config.cpp index e7710e7c..b5156308 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -348,6 +348,7 @@ void Util::Config::addConnectorOptions(int port, JSON::Value & capabilities){ capabilities["optional"]["port"]["name"] = "TCP port"; capabilities["optional"]["port"]["help"] = "TCP port to listen on - default if unprovided is "+option["value"][0u].asString(); capabilities["optional"]["port"]["type"] = "uint"; + capabilities["optional"]["port"]["option"] = "--port"; capabilities["optional"]["port"]["default"] = option["value"][0u]; option.null(); @@ -359,6 +360,7 @@ void Util::Config::addConnectorOptions(int port, JSON::Value & capabilities){ addOption("listen_interface", option); capabilities["optional"]["interface"]["name"] = "Interface"; capabilities["optional"]["interface"]["help"] = "Address of the interface to listen on - default if unprovided is all interfaces"; + capabilities["optional"]["interface"]["option"] = "--interface"; capabilities["optional"]["interface"]["type"] = "str"; addBasicConnectorOptions(capabilities); @@ -376,6 +378,7 @@ void Util::Config::addBasicConnectorOptions(JSON::Value & capabilities){ addOption("username", option); capabilities["optional"]["username"]["name"] = "Username"; capabilities["optional"]["username"]["help"] = "Username to drop privileges to - default if unprovided means do not drop privileges"; + capabilities["optional"]["username"]["option"] = "--username"; capabilities["optional"]["username"]["type"] = "str"; option.null(); diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index a7a83c88..f5b0a9fa 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -222,10 +222,10 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){ datapointertype = INVALID; std::string tmp = ""; if (newPack.isMember("trackid")){ - tmp = getTrackById(newPack["trackid"].asInt())["type"].asString(); + tmp = getTrackById(newPack["trackid"].asInt())["type"].asStringRef(); } if (newPack.isMember("datatype")){ - tmp = newPack["datatype"].asString(); + tmp = newPack["datatype"].asStringRef(); } if (tmp == "video"){ datapointertype = VIDEO; @@ -300,7 +300,7 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){ } } if (keySize){ - metadata["tracks"][newTrack]["keys"][keySize - 1]["parts"].append((long long int)newPack["data"].asString().size()); + metadata["tracks"][newTrack]["keys"][keySize - 1]["parts"].append((long long int)newPack["data"].asStringRef().size()); } metadata["live"] = 1ll; } @@ -468,7 +468,7 @@ DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set & allowedTrack std::set seekTracks = allowedTracks; livePos result = buffers.begin()->first; for (std::set::iterator it = allowedTracks.begin(); it != allowedTracks.end(); it++){ - if (getTrackById(*it).isMember("type") && getTrackById(*it)["type"].asString() == "video"){ + if (getTrackById(*it).isMember("type") && getTrackById(*it)["type"].asStringRef() == "video"){ int trackNo = *it; seekTracks.clear(); seekTracks.insert(trackNo); diff --git a/lib/flv_tag.cpp b/lib/flv_tag.cpp index c712881d..6f296941 100644 --- a/lib/flv_tag.cpp +++ b/lib/flv_tag.cpp @@ -355,7 +355,7 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){ case DTSC::VIDEO: len = S.lastData().length() + 16; if (track && track.isMember("codec")){ - if (track["codec"].asString() == "H264"){ + if (track["codec"].asStringRef() == "H264"){ len += 4; } } @@ -363,7 +363,7 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){ case DTSC::AUDIO: len = S.lastData().length() + 16; if (track && track.isMember("codec")){ - if (track["codec"].asString() == "AAC"){ + if (track["codec"].asStringRef() == "AAC"){ len += 1; } } @@ -407,10 +407,10 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){ data[15] = offset & 0xFF; } data[11] = 0; - if (track.isMember("codec") && track["codec"].asString() == "H264"){ + if (track.isMember("codec") && track["codec"].asStringRef() == "H264"){ data[11] += 7; } - if (track.isMember("codec") && track["codec"].asString() == "H263"){ + if (track.isMember("codec") && track["codec"].asStringRef() == "H263"){ data[11] += 2; } if (S.getPacket().isMember("keyframe")){ diff --git a/lib/json.cpp b/lib/json.cpp index 84b76de1..866ed2fe 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -380,6 +380,29 @@ const bool JSON::Value::asBool(){ return (bool) *this; } +/// Explicit conversion to std::string reference. +/// Returns a direct reference for string type JSON::Value objects, +/// but a reference to a static empty string otherwise. +/// \warning Only save to use when the JSON::Value is a string type! +const std::string & JSON::Value::asStringRef(){ + static std::string ugly_buffer; + if (myType == STRING){ + return strVal; + } + return ugly_buffer; +} + +/// Explicit conversion to c-string. +/// Returns a direct reference for string type JSON::Value objects, +/// a reference to an empty string otherwise. +/// \warning Only save to use when the JSON::Value is a string type! +const char * JSON::Value::c_str(){ + if (myType == STRING){ + return strVal.c_str(); + } + return ""; +} + /// Retrieves or sets the JSON::Value at this position in the object. /// Converts destructively to object if not already an object. JSON::Value & JSON::Value::operator[](const std::string i){ diff --git a/lib/json.h b/lib/json.h index 65aca525..c3ad40eb 100644 --- a/lib/json.h +++ b/lib/json.h @@ -64,6 +64,8 @@ namespace JSON { const std::string asString(); const long long int asInt(); const bool asBool(); + const std::string & asStringRef(); + const char * c_str(); //array operator for maps and arrays Value & operator[](const std::string i); Value & operator[](const char * i); diff --git a/lib/socket.cpp b/lib/socket.cpp index 703aed67..93d53aa6 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -477,7 +477,7 @@ void Socket::Connection::Send(const char * data){ /// Will not buffer anything but always send right away. Blocks. /// This will send the upbuffer (if non-empty) first, then the data. /// Any data that could not be send will block until it can be send or the connection is severed. -void Socket::Connection::SendNow(std::string & data){ +void Socket::Connection::SendNow(const std::string & data){ SendNow(data.c_str(), data.size()); } diff --git a/lib/socket.h b/lib/socket.h index 227cf018..afdf37ff 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -81,7 +81,7 @@ namespace Socket { void Send(std::string & data); ///< Appends data to the upbuffer. void Send(const char * data); ///< Appends data to the upbuffer. void Send(const char * data, size_t len); ///< Appends data to the upbuffer. - void SendNow(std::string & data); ///< Will not buffer anything but always send right away. Blocks. + void SendNow(const std::string & data); ///< Will not buffer anything but always send right away. Blocks. void SendNow(const char * data); ///< Will not buffer anything but always send right away. Blocks. void SendNow(const char * data, size_t len); ///< Will not buffer anything but always send right away. Blocks. //stats related methods