From 47c6fff690b454c882b447091637565eeb7abafe Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 12 Jul 2019 23:57:09 +0900 Subject: [PATCH] Adds AutoConnectAux::fetchElement function --- src/AutoConnectAux.cpp | 40 +++++++++++++++++++++++++--------------- src/AutoConnectAux.h | 1 + 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index c38e14c..b339a93 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -106,6 +106,29 @@ void AutoConnectAux::add(AutoConnectElementVT addons) { add(element); } +/** + * Parses the query parameters contained in the http request and fetches + * the value of AutoConnectElements carried by AutoConnectAux. + */ +void AutoConnectAux::fetchElement(void) { + WebServerClass* _webServer = _ac->_webServer.get(); + if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) { + _ac->_auxUri = _webServer->arg(String(F(AUTOCONNECT_AUXURI_PARAM))); + _ac->_auxUri.replace("/", "/"); + AC_DBG("fetch %s", _ac->_auxUri.c_str()); + AutoConnectAux* aux = _ac->_aux.get(); + while (aux) { + if (aux->_uriStr == _ac->_auxUri) { + // Save the value owned by each element contained in the POST body + // of a current HTTP request to AutoConnectElements. + aux->_storeElements(_webServer); + break; + } + aux = aux->_next.get(); + } + } +} + /** * Get already registered AutoConnectElement. * @param name Element name @@ -385,21 +408,7 @@ const String AutoConnectAux::_insertElement(PageArgument& args) { // If the current request argument contains AutoConnectElement, it is // the form data of the AutoConnectAux page and with this timing save // the value of each element. - WebServerClass* _webServer = _ac->_webServer.get(); - if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) { - _ac->_auxUri = _webServer->arg(String(F(AUTOCONNECT_AUXURI_PARAM))); - _ac->_auxUri.replace("/", "/"); - AutoConnectAux* aux = _ac->_aux.get(); - while (aux) { - if (aux->_uriStr == _ac->_auxUri) { - // Save the value owned by each element contained in the POST body - // of a current HTTP request to AutoConnectElements. - aux->_storeElements(_webServer); - break; - } - aux = aux->_next.get(); - } - } + fetchElement(); // Call user handler before HTML generation. if (_handler) { @@ -522,6 +531,7 @@ void AutoConnectAux::_storeElements(WebServerClass* webServer) { } } } + AC_DBG_DUMB(",elements stored\n"); } #ifdef AUTOCONNECT_USE_JSON diff --git a/src/AutoConnectAux.h b/src/AutoConnectAux.h index e19b5b9..4ffd1c1 100644 --- a/src/AutoConnectAux.h +++ b/src/AutoConnectAux.h @@ -53,6 +53,7 @@ class AutoConnectAux : public PageBuilder { AutoConnectElement& operator[](const String& name) { return *getElement(name); } void add(AutoConnectElement& addon); /**< Add an element to the auxiliary page */ void add(AutoConnectElementVT addons); /**< Add the element set to the auxiliary page */ + void fetchElement(void); /**< Fetch AutoConnectElements values from http query parameters */ template T& getElement(const String& name); AutoConnectElement* getElement(const String& name); /**< Get registered AutoConnectElement as specified name */