merge patch for commands refinements.

This commit is contained in:
Simon Morlat 2013-02-14 21:17:43 +01:00
parent 378b3772dd
commit c1d860aa9e
2 changed files with 27 additions and 5 deletions

View file

@ -3,16 +3,22 @@
using namespace std;
ContactCommand::ContactCommand() :
DaemonCommand("contact", "contact <username> <hostname>", "Set a contact name.") {
DaemonCommand("contact", "contact sip:<username>@<hostname> 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);

View file

@ -2,6 +2,7 @@
#include "linphonecore.h"
#include "private.h"
#include "lpconfig.h"
#include <string.h>
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));