Skip to content

Commit

Permalink
Make sure the library is initialized before running the first action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aypac committed Jun 10, 2020
1 parent ca4bb91 commit 4339688
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/tr064.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ TR064::TR064(int port, String ip, String user, String pass) {
_ip = ip;
_user = user;
_pass = pass;
_ninit = true;
debug_level = DEBUG_ERROR;
}

Expand All @@ -66,6 +67,7 @@ void TR064::init() {
delay(100); // TODO: REMOVE (after testing, that it still works!)
// Get a list of all services and the associated urls
initServiceURLs();
_ninit = false;
}

/**************************************************************************/
Expand Down Expand Up @@ -149,7 +151,7 @@ String TR064::generateAuthXML() {
/**************************************************************************/
String TR064::generateAuthToken() {
String token = md5String(_secretH + ":" + _nonce);
deb_println("[generateAuthToken] The auth token is '" + token + "'.", DEBUG_INFO);
deb_println("[generateAuthToken] With nonce '" + _nonce + "', the auth token is '" + token + "'.", DEBUG_INFO);
return token;
}

Expand Down Expand Up @@ -290,6 +292,7 @@ String TR064::action(String service, String act, String params[][2], int nParam)
*/
/**************************************************************************/
String TR064::action_raw(String service, String act, String params[][2], int nParam) {
if (_ninit) init();
// Generate the XML-envelop
String xml = _requestStart + generateAuthXML() + "<s:Body><u:"+act+" xmlns:u='" + service + "'>";
// Add request-parameters to XML
Expand Down
6 changes: 4 additions & 2 deletions src/tr064.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ class TR064 {
const String _detectPage = "/tr64desc.xml";

/* TODO: We should give access to this data for users to inspect the
* possibilities of their device(s) - see #9 on Github.
TODO: Remove 100 services limits here
* possibilities of their device(s) - see #9 on Github.
* TODO: Remove 100 services limits here
*/
String _services[100][2];
// Library not initialized?
bool _ninit;
};

#endif

0 comments on commit 4339688

Please sign in to comment.