diff --git a/daemon/commands/audio-codec-disable.cc b/daemon/commands/audio-codec-disable.cc index 82d365de0..5fc28864b 100644 --- a/daemon/commands/audio-codec-disable.cc +++ b/daemon/commands/audio-codec-disable.cc @@ -1,9 +1,10 @@ #include "audio-codec-disable.h" +#include "audio-codec-get.h" using namespace std; AudioCodecDisableCommand::AudioCodecDisableCommand() : - DaemonCommand("audio-codec-disable", "audio-codec-disable ", + DaemonCommand("audio-codec-disable", "audio-codec-disable ", "Disable an audio codec.\n" " is of the form mime/rate/channels, eg. speex/16000/1") { } @@ -15,26 +16,34 @@ void AudioCodecDisableCommand::exec(Daemon *app, const char *args) { app->sendResponse(Response("Missing parameter.", Response::Error)); } else { string mime_type; - int ptnum; + int ptnum = -1; ist >> mime_type; - PayloadTypeParser parser(app->getCore(), mime_type); + PayloadTypeParser parser(app->getCore(), mime_type, true); if (!parser.successful()) { app->sendResponse(Response("Incorrect mime type format.", Response::Error)); return; } - ptnum = parser.payloadTypeNumber(); + if (!parser.all()) ptnum = parser.payloadTypeNumber(); int index = 0; for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) { PayloadType *payload = reinterpret_cast(node->data); - if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { + if (parser.all()) { linphone_core_enable_payload_type(app->getCore(), payload, false); - app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); - return; + } else { + if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { + linphone_core_enable_payload_type(app->getCore(), payload, false); + app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); + return; + } } ++index; } - app->sendResponse(Response("Audio codec not found.", Response::Error)); + if (parser.all()) { + AudioCodecGetCommand getCommand; + getCommand.exec(app, ""); + } else { + app->sendResponse(Response("Audio codec not found.", Response::Error)); + } } } - diff --git a/daemon/commands/audio-codec-enable.cc b/daemon/commands/audio-codec-enable.cc index fa6e05819..00a5c8dab 100644 --- a/daemon/commands/audio-codec-enable.cc +++ b/daemon/commands/audio-codec-enable.cc @@ -1,9 +1,10 @@ #include "audio-codec-enable.h" +#include "audio-codec-get.h" using namespace std; AudioCodecEnableCommand::AudioCodecEnableCommand() : - DaemonCommand("audio-codec-enable", "audio-codec-enable ", + DaemonCommand("audio-codec-enable", "audio-codec-enable ", "Enable an audio codec.\n" " is of the form mime/rate/channels, eg. speex/16000/1") { } @@ -15,25 +16,34 @@ void AudioCodecEnableCommand::exec(Daemon *app, const char *args) { app->sendResponse(Response("Missing parameter.", Response::Error)); } else { string mime_type; - int ptnum; + int ptnum = -1; ist >> mime_type; - PayloadTypeParser parser(app->getCore(), mime_type); + PayloadTypeParser parser(app->getCore(), mime_type, true); if (!parser.successful()) { app->sendResponse(Response("Incorrect mime type format.", Response::Error)); return; } - ptnum = parser.payloadTypeNumber(); + if (!parser.all()) ptnum = parser.payloadTypeNumber(); int index = 0; for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) { PayloadType *payload = reinterpret_cast(node->data); - if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { + if (parser.all()) { linphone_core_enable_payload_type(app->getCore(), payload, true); - app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); - return; + } else { + if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { + linphone_core_enable_payload_type(app->getCore(), payload, true); + app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); + return; + } } ++index; } - app->sendResponse(Response("Audio codec not found.", Response::Error)); + if (parser.all()) { + AudioCodecGetCommand getCommand; + getCommand.exec(app, ""); + } else { + app->sendResponse(Response("Audio codec not found.", Response::Error)); + } } } diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 6c7f489c0..359aeea97 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -176,7 +176,11 @@ PayloadTypeResponse::PayloadTypeResponse(LinphoneCore *core, const PayloadType * } } -PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type) : mSuccesful(true), mPayloadTypeNumber(-1) { +PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type, bool accept_all) : mAll(false), mSuccesful(true), mPayloadTypeNumber(-1) { + if (accept_all && (mime_type.compare("ALL") == 0)) { + mAll = true; + return; + } istringstream ist(mime_type); ist >> mPayloadTypeNumber; if (ist.fail()) { diff --git a/daemon/daemon.h b/daemon/daemon.h index 5bf88c3c8..51cb46580 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -128,10 +128,12 @@ private: class PayloadTypeParser { public: - PayloadTypeParser(LinphoneCore *core, const std::string &mime_type); + PayloadTypeParser(LinphoneCore *core, const std::string &mime_type, bool accept_all = false); + inline bool all() { return mAll; }; inline bool successful() { return mSuccesful; }; inline int payloadTypeNumber() { return mPayloadTypeNumber; }; private: + bool mAll; bool mSuccesful; int mPayloadTypeNumber; };