- Use MIME based on executable name for CLI/URI handlers

- Rework CLI/URI execution
This commit is contained in:
Julien Wadel 2021-10-22 21:09:28 +02:00
parent b53f2eacfe
commit 0591d882af
5 changed files with 81 additions and 55 deletions

View file

@ -7,5 +7,5 @@ Exec=@EXECUTABLE_NAME@ %u
Icon=@EXECUTABLE_NAME@
Terminal=false
Categories=Network;Telephony;
MimeType=x-scheme-handler/sip-linphone;x-scheme-handler/sip;x-scheme-handler/sips-linphone;x-scheme-handler/sips;x-scheme-handler/tel;x-scheme-handler/callto;x-scheme-handler/linphone-config;
MimeType=x-scheme-handler/sip-@EXECUTABLE_NAME@;x-scheme-handler/sip;x-scheme-handler/sips-@EXECUTABLE_NAME@;x-scheme-handler/sips;x-scheme-handler/tel;x-scheme-handler/callto;x-scheme-handler/@EXECUTABLE_NAME@-config;
X-PulseAudio-Properties=media.role=phone

View file

@ -40,12 +40,12 @@
<key>CFBundleURLSchemes</key>
<array>
<string>sip</string>
<string>sip-linphone</string>
<string>sip-@EXECUTABLE_NAME@</string>
<string>sips</string>
<string>sips-linphone</string>
<string>sips-@EXECUTABLE_NAME@</string>
<string>tel</string>
<string>callto</string>
<string>linphone-config</string>
<string>@EXECUTABLE_NAME@-config</string>
</array>
</dict>
</array>

View file

@ -16,17 +16,17 @@ WriteRegStr HKLM "SOFTWARE\IM Providers\@APPLICATION_NAME@" "FriendlyName" "@APP
WriteRegStr HKCR "sip" "" "URL:sip Protocol"
WriteRegStr HKCR "sip" "URL Protocol" ""
WriteRegStr HKCR "sip-linphone" "" "URL:sip-linphone Protocol"
WriteRegStr HKCR "sip-linphone" "URL Protocol" ""
WriteRegStr HKCR "sip-@EXECUTABLE_NAME@" "" "URL:sip-@EXECUTABLE_NAME@ Protocol"
WriteRegStr HKCR "sip-@EXECUTABLE_NAME@" "URL Protocol" ""
WriteRegStr HKCR "linphone-config" "" "URL:linphone-config Protocol"
WriteRegStr HKCR "linphone-config" "URL Protocol" ""
WriteRegStr HKCR "@EXECUTABLE_NAME@-config" "" "URL:@EXECUTABLE_NAME@-config Protocol"
WriteRegStr HKCR "@EXECUTABLE_NAME@-config" "URL Protocol" ""
WriteRegStr HKCR "sips" "" "URL:sips Protocol"
WriteRegStr HKCR "sips" "URL Protocol" ""
WriteRegStr HKCR "sips-linphone" "" "URL:sips-linphone Protocol"
WriteRegStr HKCR "sips-linphone" "URL Protocol" ""
WriteRegStr HKCR "sips-@EXECUTABLE_NAME@" "" "URL:sips-@EXECUTABLE_NAME@ Protocol"
WriteRegStr HKCR "sips-@EXECUTABLE_NAME@" "URL Protocol" ""
WriteRegStr HKCR "tel" "" "URL:tel Protocol"
WriteRegStr HKCR "tel" "URL Protocol" ""
@ -44,12 +44,12 @@ WriteRegStr HKCR "@APPLICATION_NAME@.sip\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sip\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sip" "@APPLICATION_NAME@.sip"
## SIP-LINPHONE
WriteRegStr HKCR "@APPLICATION_NAME@.sip-linphone" "" "@APPLICATION_NAME@ sip-linphone Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.sip-linphone\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sip-linphone\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sip-linphone\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sip-linphone" "@APPLICATION_NAME@.sip-linphone"
## SIP-@EXECUTABLE_NAME@
WriteRegStr HKCR "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@" "" "@APPLICATION_NAME@ sip-@EXECUTABLE_NAME@ Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sip-@EXECUTABLE_NAME@" "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@"
## SIPS
WriteRegStr HKCR "@APPLICATION_NAME@.sips" "" "@APPLICATION_NAME@ sips Protocol"
@ -58,19 +58,19 @@ WriteRegStr HKCR "@APPLICATION_NAME@.sips\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sips\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sips" "@APPLICATION_NAME@.sips"
## SIPS-LINPHONE
WriteRegStr HKCR "@APPLICATION_NAME@.sips-linphone" "" "@APPLICATION_NAME@ sips-linphone Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.sips-linphone\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sips-linphone\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sips-linphone\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sips-linphone" "@APPLICATION_NAME@.sips-linphone"
## SIPS-@EXECUTABLE_NAME@
WriteRegStr HKCR "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@" "" "@APPLICATION_NAME@ sips-@EXECUTABLE_NAME@ Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "sips-@EXECUTABLE_NAME@" "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@"
## LINPHONE-CONFIG
WriteRegStr HKCR "@APPLICATION_NAME@.linphone-config" "" "@APPLICATION_NAME@ linphone-config Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.linphone-config\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.linphone-config\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.linphone-config\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "linphone-config" "@APPLICATION_NAME@.linphone-config"
## @EXECUTABLE_NAME@-CONFIG
WriteRegStr HKCR "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config" "" "@APPLICATION_NAME@ @EXECUTABLE_NAME@-config Protocol"
WriteRegStr HKCR "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config\Shell" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config\Shell\Open" "" ""
WriteRegStr HKCR "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config\Shell\Open\Command" "" "$INSTDIR\bin\@EXECUTABLE_NAME@.exe $\"%1$\""
WriteRegStr HKLM "SOFTWARE\@APPLICATION_VENDOR@\@APPLICATION_NAME@\Capabilities\URLAssociations" "@EXECUTABLE_NAME@-config" "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config"
## TEL
WriteRegStr HKCR "@APPLICATION_NAME@.tel" "" "@APPLICATION_NAME@ tel Protocol"

View file

@ -14,10 +14,10 @@ DeleteRegValue HKLM "SOFTWARE\RegisteredApplications" "@APPLICATION_NAME@"
## Handlers
DeleteRegKey HKCR "@APPLICATION_NAME@.sip"
DeleteRegKey HKCR "@APPLICATION_NAME@.sip-linphone"
DeleteRegKey HKCR "@APPLICATION_NAME@.sip-@EXECUTABLE_NAME@"
DeleteRegKey HKCR "@APPLICATION_NAME@.sips"
DeleteRegKey HKCR "@APPLICATION_NAME@.sips-linphone"
DeleteRegKey HKCR "@APPLICATION_NAME@.linphone-config"
DeleteRegKey HKCR "@APPLICATION_NAME@.sips-@EXECUTABLE_NAME@"
DeleteRegKey HKCR "@APPLICATION_NAME@.@EXECUTABLE_NAME@-config"
DeleteRegKey HKCR "@APPLICATION_NAME@.tel"
DeleteRegKey HKCR "@APPLICATION_NAME@.callto"

View file

@ -51,6 +51,8 @@ static void cliShow (QHash<QString, QString> &args) {
}
static void cliCall (QHash<QString, QString> &args) {
QString addressToCall = args["sip-address"];
if(args.size() > 1){// Call with options
App *app = App::getInstance();
args["call"] = args["sip-address"];// Swap cli def to parser
@ -429,42 +431,65 @@ QMap<QString, Cli::Command> Cli::mCommands = {
};
// -----------------------------------------------------------------------------
void Cli::executeCommand (const QString &command, CommandFormat *format) {
shared_ptr<linphone::Address> address;
QStringList tempSipAddress = command.split(':');
bool ok = false;
/*
string Cli::getScheme(const QString& address){
QStringList tempSipAddress = address->split(':');
if( tempSipAddress.size() > 0)
return tempSipAddress[0].toStdString();
else
return "";
}
bool Cli::changeScheme(QString * address){
QStringList tempSipAddress = address->split(':');
string scheme;
bool ok = false;
if(tempSipAddress.size() > 1) {
scheme = tempSipAddress[0].toStdString();
for (const string &validScheme : { "sip", "sip-linphone", "sips", "sips-linphone", "tel", "callto", "linphone-config" })
for (const string &validScheme : { string("sip"), "sip-"+string(EXECUTABLE_NAME), string("sips"), "sips-"+string(EXECUTABLE_NAME), string("tel"), string("callto"), string(EXECUTABLE_NAME)+ "-config" })
if (scheme == validScheme)
ok = true;
if( !ok){
qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.").arg(command).arg(Utils::coreStringToAppString(scheme));
qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.").arg(*address).arg(Utils::coreStringToAppString(scheme));
}else{
tempSipAddress[0] = "sip";// In order to pass bellesip parsing.
QString bellesipAddress = tempSipAddress.join(':');
address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(bellesipAddress));
*address = tempSipAddress.join(':');
}
}
return ok;
}
*/
void Cli::executeCommand (const QString &command, CommandFormat *format) {
// Execute cli command.
if (!address) {
// Detect if command is a CLI by testing commands
const QString &functionName = parseFunctionName(command);
if(!functionName.isEmpty()){// It is a CLI
qInfo() << QStringLiteral("Detecting cli command: `%1`...").arg(command);
const QString &functionName = parseFunctionName(command);
if (!functionName.isEmpty()) {
QHash<QString, QString> args = parseArgs(command);
mCommands[functionName].execute(args);
if (format)
*format = CliFormat;
return;
QHash<QString, QString> args = parseArgs(command);
mCommands[functionName].execute(args);
if (format)
*format = CliFormat;
return;
}else{// It is a URI
QStringList tempSipAddress = command.split(':');
string scheme="sip";
QString transformedCommand; // In order to pass bellesip parsing, set scheme to 'sip:'.
if( tempSipAddress.size() == 1){
transformedCommand = "sip:"+command;
}else{
scheme = tempSipAddress[0].toStdString();
bool ok = false;
for (const string &validScheme : { string("sip"), "sip-"+string(EXECUTABLE_NAME), string("sips"), "sips-"+string(EXECUTABLE_NAME), string("tel"), string("callto"), string(EXECUTABLE_NAME)+ "-config" })
if (scheme == validScheme)
ok = true;
if( !ok){
qWarning() << QStringLiteral("Not a valid URI: `%1` Unsupported scheme: `%2`.").arg(command).arg(Utils::coreStringToAppString(scheme));
return;
}
tempSipAddress[0] = "sip";
transformedCommand = tempSipAddress.join(':');
}
}
// Execute uri
if(ok){
if( scheme == "linphone-config" ){
if( scheme == string(EXECUTABLE_NAME)+"-config" ){
QHash<QString, QString> args = parseArgs(command);
if(args.contains("fetch-config"))
args["fetch-config"] = QByteArray::fromBase64(args["fetch-config"].toUtf8() );
@ -477,9 +502,10 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) {
*format = CliFormat;
mCommands["show"].execute(args);
}else{
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(transformedCommand));// Test if command is an address
if (format)
*format = UriFormat;
qInfo() << QStringLiteral("Detecting uri command: `%1`...").arg(command);
qInfo() << QStringLiteral("Detecting URI command: `%1`...").arg(command);
QString functionName;
if( address) {
functionName = Utils::coreStringToAppString(address->getHeader("method")).isEmpty()