From c1d860aa9e748c234df9d2f910c9f6622053bce7 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Thu, 14 Feb 2013 21:17:43 +0100 Subject: [PATCH] merge patch for commands refinements. --- daemon/commands/contact.cc | 10 ++++++++-- daemon/commands/register.cc | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/daemon/commands/contact.cc b/daemon/commands/contact.cc index 3f0ef52f3..81872f579 100644 --- a/daemon/commands/contact.cc +++ b/daemon/commands/contact.cc @@ -3,16 +3,22 @@ using namespace std; ContactCommand::ContactCommand() : - DaemonCommand("contact", "contact ", "Set a contact name.") { + DaemonCommand("contact", "contact sip:@ or contact username hostname", "Set a contact name.") { addExample(new DaemonCommandExample("contact sip:root@unknown-host", "Status: Ok\n\n")); } void ContactCommand::exec(Daemon *app, const char *args) { LinphoneCore *lc = app->getCore(); + int result; char *contact; char username[256] = { 0 }; char hostname[256] = { 0 }; - if (sscanf(args, "%255s %255s", username, hostname) >= 1) { + result = sscanf(args, "%255s %255s", username, hostname); + if (result == 1) { + linphone_core_set_primary_contact(lc,username); + app->sendResponse(Response("", Response::Ok)); + } + else if (result > 1) { contact=ortp_strdup_printf("sip:%s@%s",username,hostname); linphone_core_set_primary_contact(lc,contact); ms_free(contact); diff --git a/daemon/commands/register.cc b/daemon/commands/register.cc index d708ccd39..84778de65 100644 --- a/daemon/commands/register.cc +++ b/daemon/commands/register.cc @@ -2,6 +2,7 @@ #include "linphonecore.h" #include "private.h" #include "lpconfig.h" +#include using namespace std; @@ -14,8 +15,23 @@ RegisterCommand::RegisterCommand() : } void RegisterCommand::exec(Daemon *app, const char *args) { LinphoneCore *lc = app->getCore(); - char proxy[256] = { 0 }, identity[128] = { 0 }, password[64] = { 0 }, userid[128] = { 0 }, realm[128] = { 0 }; - if (sscanf(args, "%255s %127s %63s %127s %127s", identity, proxy, password, userid, realm) >= 2) { + ostringstream ostr; + char proxy[256] = { 0 }, identity[128] = { 0 }, password[64] = { 0 }, userid[128] = { 0 }, realm[128] = { 0 }, parameter[256] = { 0 }; + if (sscanf(args, "%255s %127s %63s %127s %127s %255s", identity, proxy, password, userid, realm, parameter) >= 2) { + app->sendResponse(Response(ostr.str().c_str(), Response::Ok)); + if (strcmp(password, "NULL") == 0) { + password[0] = 0; + } + if (strcmp(userid, "NULL") == 0) { + userid[0] = 0; + } + if (strcmp(realm, "NULL") == 0) { + realm[0] = 0; + } + if (strcmp(parameter, "NULL") == 0) { + parameter[0] = 0; + } + app->sendResponse(Response(ostr.str().c_str(), Response::Ok)); LinphoneProxyConfig *cfg = linphone_proxy_config_new(); if (password[0] != '\0') { LinphoneAddress *from = linphone_address_new(identity); @@ -29,7 +45,7 @@ void RegisterCommand::exec(Daemon *app, const char *args) { linphone_proxy_config_set_identity(cfg, identity); linphone_proxy_config_set_server_addr(cfg, proxy); linphone_proxy_config_enable_register(cfg, TRUE); - ostringstream ostr; + linphone_proxy_config_set_contact_parameters(cfg, parameter); ostr << "Id: " << app->updateProxyId(cfg) << "\n"; linphone_core_add_proxy_config(lc, cfg); app->sendResponse(Response(ostr.str().c_str(), Response::Ok));