Introduce a command line option to pass sleep password.

And fix return code for "launching" system app.
This commit is contained in:
mdaftari
2018-10-26 15:22:08 -07:00
parent 231dd4e462
commit 3e6d3981ac
3 changed files with 38 additions and 11 deletions

View File

@@ -50,6 +50,10 @@
#define WAKE_OPTION_LONG "--wake-on-wifi-len"
#define WAKE_DESCRIPTION "Enable wake on wifi/len. Value: on/off. Default (on)"
#define SLEEP_PASSWORD "-S"
#define SLEEP_PASSWORD_LONG "--sleep-password"
#define SLEEP_PASSWORD_DESCRIPTION "Password required to put the device to deep sleep"
struct dial_options
{
const char * pOption;
@@ -88,6 +92,11 @@ struct dial_options gDialOptions[] =
WAKE_OPTION,
WAKE_OPTION_LONG,
WAKE_DESCRIPTION
},
{
SLEEP_PASSWORD,
SLEEP_PASSWORD_LONG,
SLEEP_PASSWORD_DESCRIPTION
}
};

View File

@@ -61,6 +61,8 @@ static char spUuid[BUFSIZE];
extern bool wakeOnWifiLan;
static int gDialPort;
char spSleepPassword[BUFSIZE];
static char *spAppYouTube = "chrome";
static char *spAppYouTubeMatch = "chrome.*google-chrome-dial";
static char *spAppYouTubeExecutable = "/opt/google/chrome/google-chrome";
@@ -325,6 +327,9 @@ static void processOption( int index, char * pOption )
exit(1);
}
break;
case 6:
setValue( pOption, spSleepPassword );
break;
default:
// Should not get here
fprintf( stderr, "Option %d not valid\n", index);

View File

@@ -1,26 +1,39 @@
#include <string.h>
#include <stdio.h>
#include "system_callbacks.h"
extern char spSleepPassword[];
DIALStatus system_start(DIALServer *ds, const char *appname, const char *payload, const char* query_string,
const char *additionalDataUrl, DIAL_run_t *run_id, void *callback_data) {
/* Can't launch system app */
if (0 == query_string) {
return kDIALStatusErrorForbidden;
}
/* Only sleep is supported action */
if ((0 == query_string) || (0 != strncmp( query_string, "action=sleep", sizeof("action=sleep") - 1))) {
if (0 != strncmp( query_string, "action=sleep", sizeof("action=sleep") - 1)) {
return kDIALStatusErrorNotImplemented; // Only "sleep" is valid action
}
if (strlen(spSleepPassword) != 0) {
/* Look for key */
char *key_value;
if ( (key_value = strchr(query_string, '&')) == '\0' ) {
return kDIALStatusErrorForbidden; // No key specified.
}
/* Looking for hardcoded "TEST" key */
/* Look for sleep password */
*key_value++ = '\0';
char str[512];
snprintf(str, 512, "key=%s", spSleepPassword);
printf(" str: %s \n", str);
if (0 != strncmp( key_value, "key=TEST", sizeof("key=TEST") - 1)) {
return kDIALStatusErrorUnauth; // Invalid key
}
}
/* Sleep not implemented in reference implementation */
return kDIALStatusErrorNotImplemented;
}