Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timeout to policy prompt for Linux. #581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions webinos/core/manager/policy_manager/lib/policymanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
var policyFile = null;
var decisionStorage = null;

var promptTimeout = 10;

var policyManager = function(policyFilename) {
var self = this;
// Load the native module
Expand Down Expand Up @@ -104,8 +106,11 @@
choices[0] = "Deny always";
choices[1] = "Deny this time";
choices[2] = "Allow this time";
selected = promptMan.display(message, choices);
if(selected == 0 || selected == 1)
selected = promptMan.display(message, choices, promptTimeout);
// promptman.display returns following negative values:
// -1 ==> prompt timeout
// -2 ==> generic error
if(selected < 0 || selected == 0 || selected == 1)
res = 1;
if(selected == 2)
res = 0;
Expand All @@ -120,8 +125,8 @@
choices[2] = "Deny this time";
choices[3] = "Allow this time";
choices[4] = "Allow for this session";
selected = promptMan.display(message, choices);
if(selected == 0 || selected == 1 || selected == 2)
selected = promptMan.display(message, choices, promptTimeout);
if(selected < 0 || selected == 0 || selected == 1 || selected == 2)
res = 1;
if(selected == 3 || selected == 4)
res = 0;
Expand All @@ -140,8 +145,8 @@
choices[3] = "Allow this time";
choices[4] = "Allow for this session";
choices[5] = "Allow always";
selected = promptMan.display(message, choices);
if(selected == 0 || selected == 1 || selected == 2)
selected = promptMan.display(message, choices, promptTimeout);
if(selected < 0 || selected == 0 || selected == 1 || selected == 2)
res = 1;
if(selected == 3 || selected == 4 || selected == 5)
res = 0;
Expand All @@ -152,6 +157,10 @@
decisionStorage.addDecision(request, sessionId, res, 1);
}
}
// In case of prompt timeout take needed actions...
if (selected == -1) {
console.log('Policy Manager - prompt timed out');
}
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions webinos/core/manager/policy_manager/src/promptMan/promptMan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PromptManInt: ObjectWrap{
PromptManInt* pmtmp = ObjectWrap::Unwrap<PromptManInt>(args.This());
pmtmp->m_count++;

if (args.Length() < 2) {
if (args.Length() < 3) {
return ThrowException(Exception::TypeError(String::New("Argument(s) missing")));
}

Expand All @@ -83,10 +83,16 @@ class PromptManInt: ObjectWrap{
return ThrowException(Exception::TypeError(String::New("Bad type argument")));
}

if (!args[2]->IsNumber()) {
return ThrowException(Exception::TypeError(String::New("Bad type argument")));
}

v8::String::AsciiValue message(args[0]->ToString());

Handle<Array> choiceArray = Handle<Array>::Cast(args[1]);

Local<Integer> timeout = args[2]->ToInteger();

//Prepare Xmessage cmdline
std::stringstream cmdstream(std::stringstream::out);
cmdstream << "xmessage -buttons ";
Expand All @@ -102,14 +108,28 @@ class PromptManInt: ObjectWrap{
else {
cmdstream << ",";
}
cmdstream << "\"" << *choice << "\"" << ":" << i;
cmdstream << "\"" << *choice << "\"" << ":" << (i+2);
}

//cmdstream << " -default \"Deny this time\"" ;
cmdstream << " -timeout " << (int)(timeout->Int32Value()) ;
cmdstream << " -center \"" << *message << "\"";
std::string cmdline = cmdstream.str();

LOGD("cmdline is %s", cmdline.data());
int res=(system(cmdline.data()))>>8;
// res == 0 => timeout
if (res == 0) {
res = -1;
}
// res == 1 => error (for example xmessage closed)
else if (res == 1) {
res = -2;
}
// valid answer
else {
res = res-2;
}
LOGD("Answer is %d", res);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
}
};

promptManager.prototype.display = function(message, choices ) {
promptManager.prototype.display = function(message, choices, timeout) {
if(os.platform() === 'linux' || os.platform() === 'darwin' ) {
return(this.promptCore.display(message, choices));
return(this.promptCore.display(message, choices, timeout));
}
else if(os.platform() === 'win32') {
}
Expand Down