diff --git a/server/dial_options.h b/server/dial_options.h index 6f6b970..d2fe4e9 100644 --- a/server/dial_options.h +++ b/server/dial_options.h @@ -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 } }; diff --git a/server/main.c b/server/main.c index 5dbaa4b..fcc64c2 100644 --- a/server/main.c +++ b/server/main.c @@ -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); diff --git a/server/system_callbacks.c b/server/system_callbacks.c index 29c4f5b..cf03f72 100644 --- a/server/system_callbacks.c +++ b/server/system_callbacks.c @@ -1,26 +1,39 @@ #include +#include #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 } - /* Look for key */ - char *key_value; - if ( (key_value = strchr(query_string, '&')) == '\0' ) { - return kDIALStatusErrorForbidden; // No key specified. - } + if (strlen(spSleepPassword) != 0) { - /* Looking for hardcoded "TEST" key */ - *key_value++ = '\0'; - if (0 != strncmp( key_value, "key=TEST", sizeof("key=TEST") - 1)) { - return kDIALStatusErrorUnauth; // Invalid key - } + /* Look for key */ + char *key_value; + if ( (key_value = strchr(query_string, '&')) == '\0' ) { + return kDIALStatusErrorForbidden; // No key specified. + } + /* 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; }