boolean CanAccess::transmit(CanMessage& message, boolean isPost, unsigned long waitMillis, void* consumer) { if (&message == NULL) return false; if (isPost ? doPost(message) : doSend(message)) { handleMessage(message, message.isRTR(), consumer); return true; } if (waitMillis == CAN_NO_WAIT) return false; if (waitMillis == CAN_FOREVER) { while(isPost ? !doPost(message) : !doSend(message)) delay(1); handleMessage(message, message.isRTR(), consumer); return true; } unsigned long stop = millis() + waitMillis; while(stop > millis()) { delay(1); if(isPost ? post(message) : send(message)) { handleMessage(message, message.isRTR(), consumer); return true; } } return false; }
int RockComMailbox::loginRequest() { // LOG_ENTER("RockComMailbox::loginRequest"); const std::string vars = std::string("show_frame=Enter&action=login&domain=") + escape("rock.com") + "&mail_language=us&longlogin=1&login="******"&password="******"&submit.x=41&submit.y=8"; // setState(Mailbox::LoginIP); // LOG_ENTER(getUser()); // LOG_ENTER(getPassword()); page=doPost("http://webmail.rock.com/scripts/common/proxy.main", vars); boost::regex re("a"); boost::smatch match; if (boost::regex_search(page, match, re)) { // setState(Mailbox::LoginDone); // logged in auth = match[1]; // LOG(Log::Debug, "auth=" + auth); return 0; } else { // setState(Mailbox::LoginError); //login failure return 1; } }
void loop() { gpsCommunicator.listen(); delay(5000); if(feedGps()) gps.f_get_position(&actualLatitude, &actualLongitude); if((actualLatitude==0.0f) || (actualLongitude==0.0f)) return; cell.listen(); delay(5000); if(doPost(&connectionId, &path, &actualLatitude, &actualLongitude)) { treatServerResponse(&responseFromServer); #ifdef DEBUG_MESSAGES Serial.println(F("Delay")); #endif delay(TIME_TO_SEND); } #ifdef DEBUG_MESSAGES Serial.println(responseFromServer); #endif responseFromServer = ""; }
bool http_servlet::doPropfind(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { handled_ = true; out_.format(">>> request method: PROPFIND <<<\r\n"); return doPost(req, res); }
bool http_servlet::doOther(acl::HttpServletRequest& req, acl::HttpServletResponse& res, const char* method) { handled_ = true; out_.format(">>> request method: %s <<<\r\n", method); return doPost(req, res); }
bool http_servlet::doOptions(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { handled_ = true; out_.format(">>> request method: OPTIONS <<<\r\n"); return doPost(req, res); }
void Nimbits::recordValue(double value, String pointId) { EthernetClient client; String json; json = "{\"d\":\""; json += floatToString(value, 4); json += "\"}"; String content; content += "&json="; content += json; content += "&id="; content += pointId; if (client.connect(_hostname.c_str(), _port)) { doPost(client, VALUE_API, content); String response = getFullResponse(client); client.stop(); } else { client.stop(); } }
bool http_servlet::doHead(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { handled_ = true; out_.format(">>> request method: HEAD <<<\r\n"); logger_request(req); return doPost(req, res); }
boolean OlcbLink::transmit(OlcbEvent& event, unsigned long waitMillis, void* consumer) { if (&event == NULL) return false; event.setSource(nodeId); if (!doPost(event, waitMillis)) return false; handleEvent(event, consumer); return true; }
String Nimbits::login(String email, String password) { EthernetClient client; _email = email; _password = password; String content; content = "email="; content += email; content += "&token="; content += _password; if (client.connect(_hostname.c_str(), _port)) { doPost(client, SESSION_API, content); String response = getFullResponse(client); String str = getContent(response); Serial.println(str); client.stop(); int str_len = str.length() + 1; StaticJsonBuffer<1024> jsonBuffer; char char_array[str_len]; // Copy it over str.toCharArray(char_array, str_len); JsonObject& root = jsonBuffer.parseObject(char_array); if (!root.success()) { _authToken = ""; return ""; } _authToken = root["token"]; } else { client.stop(); } return _authToken; }
int GoogleAppsMailbox::loginRequest() { //const QRegExp moorhuntHashRegex("(<<a[a-h].*>>)"); page = doGet("https://www.google.com/a/"+getMailbox()); int pos = 0; QRegExp re3("GALX\\\".*value=\\\"(.*)\\\"./>"); re3.setMinimal(true); if (re3.indexIn(page, pos) == -1) return 1; //LOG(Log::Info, page); const QString vars = QString("ltmpl=default<mplcache=2&continue=") + escape("https://mail.google.com/a/"+getMailbox()+"/") +"&service=mail&GALX=" + escape(re3.cap(1)) +"&rm=false&hl=pl&Email="+escape(getUser()) +"&Passwd="+escape(getPassword()) +"&rmShown=1"; page = doPost("https://www.google.com/a/"+getMailbox()+"/LoginAction2?service=mail",vars, true); QString username = getUser(); QRegExp re(username); QRegExp re2("&"); QRegExp authre("auth=([\\w\\d-]+)"); // To Do if (re.indexIn(page, pos) != -1) { QString url = re.cap(1); LOG(Log::Info, page + " <f"); if(url.indexOf("answer=40695") != -1) { LOG(Log::Info, "Niestety, konto zostało wyłączone. - " + getMailbox()); return 1; } url.replace(re2, "&"); url = unescape(url); if (authre.indexIn(page, pos) != -1) auth = authre.cap(1); LOG(Log::Info, auth + " <s"); return 0; } else return 1; }
int MyNetMailbox::loginRequest() { // LOG(Log::Debug,"MyNetMailbox::loginRequest"); // LOG(Log::Debug,"MyNetMailbox::State"); std::string page,url,purl; url="http://eposta.mynet.com/index/mymail.html"; page=doGet(url); purl="http://uyeler.mynet.com/login/login.asp?loginRequestingURL=http%3A%2F%2Feposta.mynet.com%2Findex%2Fmymail.html&formname=eposta"; const std::string vars = std::string("faultCount=&faultyUser=&loginRequestingURL=") + escape(url) +"&nameofservice=eposta&pageURL=" + escape(purl) +"&password="******"&rememberstate=2&rememberstatep=2&username="******"&x=0&y=0"; // setState(Mailbox::LoginIP); doPost("https://uyeler.mynet.com/index/uyegiris.html",vars); page=doGet(url,true); if(page.find("Merhaba "+getUser())==std::string::npos) { // setState(Mailbox::LoginError); //login failure // throw MoorieException("Login failed"); return 1; } // setState(Mailbox::LoginDone); boost::smatch match; //regex re("Location: (http[^\r\n]*)"); //regex_search(page,match,re); //page=doGet(match[1]); boost::regex re("<a href=\"([^\"]*mynet.com/web2/src/showFolder.php\\?adu[^\"&]*)"); boost::regex_search(page,match,re); auth=match[1]; // setState(Mailbox::Connected); return 0; }
bool logger_servlet::doGet(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { return doPost(req, res); }
bool HttpServlet::start() { socket_stream* in; socket_stream* out; bool cgi_mode; bool first = first_; if (first_) first_ = false; if (stream_ == NULL) { // 数据流为空,则当 CGI 模式处理,将标准输入输出 // 作为数据流 in = NEW socket_stream(); in->open(ACL_VSTREAM_IN); out = NEW socket_stream(); out->open(ACL_VSTREAM_OUT); cgi_mode = true; } else { in = out = stream_; cgi_mode = false; } // 在 HTTP 长连接重复请求情况下,以防万一,需要首先删除请求/响应对象 delete req_; delete res_; res_ = NEW HttpServletResponse(*out); req_ = NEW HttpServletRequest(*res_, *session_, *in, local_charset_, parse_body_enable_, parse_body_limit_); // 设置 HttpServletRequest 对象 res_->setHttpServletRequest(req_); if (rw_timeout_ >= 0) req_->setRwTimeout(rw_timeout_); res_->setCgiMode(cgi_mode); string method_s(32); http_method_t method = req_->getMethod(&method_s); // 根据请求的值自动设定是否需要保持长连接 if (!cgi_mode) res_->setKeepAlive(req_->isKeepAlive()); bool ret; switch (method) { case HTTP_METHOD_GET: if (upgradeWebsocket(*req_, *res_)) { if (res_->sendHeader() == false) { logger_error("sendHeader error!"); return false; } ret = doWebsocket(*req_, *res_); } else ret = doGet(*req_, *res_); break; case HTTP_METHOD_POST: ret = doPost(*req_, *res_); break; case HTTP_METHOD_PUT: ret = doPut(*req_, *res_); break; case HTTP_METHOD_CONNECT: ret = doConnect(*req_, *res_); break; case HTTP_METHOD_PURGE: ret = doPurge(*req_, *res_); break; case HTTP_METHOD_DELETE: ret = doDelete(*req_, *res_); break; case HTTP_METHOD_HEAD: ret = doHead(*req_, *res_); break; case HTTP_METHOD_OPTION: ret = doOptions(*req_, *res_); break; case HTTP_METHOD_PROPFIND: ret = doPropfind(*req_, *res_); break; case HTTP_METHOD_OTHER: ret = doOther(*req_, *res_, method_s.c_str()); break; default: ret = false; // 有可能是IO失败或未知方法 if (req_->getLastError() == HTTP_REQ_ERR_METHOD) doUnknown(*req_, *res_); else if (first) doError(*req_, *res_); break; } if (in != out) { // 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑, // 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性 // 这样可以保证与客户端保持长连接 in->unbind(); out->unbind(); delete in; delete out; } return ret; }
bool http_servlet::doGet(request_t& req, response_t& res) { return doPost(req, res); }
bool HttpServlet::doRun(dbuf_pool* dbuf) { socket_stream* in; socket_stream* out; bool cgi_mode; bool first = first_; if (first_) first_ = false; if (stream_ == NULL) { // 数据流为空,则当 CGI 模式处理,将标准输入输出 // 作为数据流 in = NEW socket_stream(); in->open(ACL_VSTREAM_IN); out = NEW socket_stream(); out->open(ACL_VSTREAM_OUT); cgi_mode = true; } else { in = out = stream_; cgi_mode = false; } // req/res 采用栈变量,减少内存分配次数 HttpServletResponse res(*out, dbuf); HttpServletRequest req(res, *session_, *in, local_charset_, parse_body_enable_, parse_body_limit_, dbuf); // 设置 HttpServletRequest 对象 res.setHttpServletRequest(&req); if (rw_timeout_ >= 0) req.setRwTimeout(rw_timeout_); res.setCgiMode(cgi_mode); string method_s(32); http_method_t method = req.getMethod(&method_s); // 根据请求的值自动设定是否需要保持长连接 if (!cgi_mode) res.setKeepAlive(req.isKeepAlive()); bool ret; switch (method) { case HTTP_METHOD_GET: ret = doGet(req, res); break; case HTTP_METHOD_POST: ret = doPost(req, res); break; case HTTP_METHOD_PUT: ret = doPut(req, res); break; case HTTP_METHOD_CONNECT: ret = doConnect(req, res); break; case HTTP_METHOD_PURGE: ret = doPurge(req, res); break; case HTTP_METHOD_DELETE: ret = doDelete(req, res); break; case HTTP_METHOD_HEAD: ret = doHead(req, res); break; case HTTP_METHOD_OPTION: ret = doOptions(req, res); break; case HTTP_METHOD_PROPFIND: ret = doPropfind(req, res); break; case HTTP_METHOD_OTHER: ret = doOther(req, res, method_s.c_str()); break; default: ret = false; // 有可能是IO失败或未知方法 if (req.getLastError() == HTTP_REQ_ERR_METHOD) doUnknown(req, res); else if (first) doError(req, res); break; } if (in != out) { // 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑, // 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性 // 这样可以保证与客户端保持长连接 in->unbind(); out->unbind(); delete in; delete out; } // 返回给上层调用者:true 表示继续保持长连接,否则表示需断开连接 return ret && req.isKeepAlive() && res.getHttpHeader().get_keep_alive(); }
bool WebsocketServlet_impl::doGet(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { return doPost(req, res); }
bool http_servlet::doGet(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { printf("in doGet\r\n"); return doPost(req, res); }
bool HttpServlet::doRun(session& session, socket_stream* stream /* = NULL */) { socket_stream* in; socket_stream* out; bool cgi_mode; if (stream == NULL) { // 数据流为空,则当 CGI 模式处理,将标准输入输出 // 作为数据流 stream = NEW socket_stream(); (void) stream->open(ACL_VSTREAM_IN); in = stream; stream = NEW socket_stream(); (void) stream->open(ACL_VSTREAM_OUT); out = stream; cgi_mode = true; } else { in = out = stream; cgi_mode = false; } // req/res 采用栈变量,减少内存分配次数 HttpServletResponse res(*out); HttpServletRequest req(res, session, *in, local_charset_, parse_body_enable_, parse_body_limit_); if (rw_timeout_ >= 0) req.setRwTimeout(rw_timeout_); res.setCgiMode(cgi_mode); bool ret; http_method_t method = req.getMethod(); switch (method) { case HTTP_METHOD_GET: ret = doGet(req, res); break; case HTTP_METHOD_POST: ret = doPost(req, res); break; case HTTP_METHOD_PUT: ret = doPut(req, res); break; case HTTP_METHOD_CONNECT: ret = doConnect(req, res); break; case HTTP_METHOD_PURGE: ret = doPurge(req, res); break; case HTTP_METHOD_DELETE: ret = doDelete(req, res); break; case HTTP_METHOD_HEAD: ret = doHead(req, res); break; case HTTP_METHOD_OPTION: ret = doOption(req, res); break; default: ret = false; // 有可能是IO失败或未知方法 if (req.getLastError() == HTTP_REQ_ERR_METHOD) doUnknown(req, res); else doError(req, res); break; } if (in != out) { // 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑, // 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性 // 这样可以保证与客户端保持长连接 in->unbind(); out->unbind(); delete in; delete out; } return ret; }
bool HttpServlet::doRun(session& session, socket_stream* stream /* = NULL */, bool body_parse /* = true */, int body_limit /* = 102400 */) { socket_stream* in; socket_stream* out; bool cgi_mode; if (stream == NULL) { // 数据流为空,则当 CGI 模式处理,将标准输入输出 // 作为数据流 stream = NEW socket_stream(); (void) stream->open(ACL_VSTREAM_IN); in = stream; stream = NEW socket_stream(); (void) stream->open(ACL_VSTREAM_OUT); out = stream; cgi_mode = true; } else { in = out = stream; cgi_mode = false; } // req/res 采用栈变量,减少内存分配次数 HttpServletResponse res(*out); HttpServletRequest req(res, session, *in, local_charset_, body_parse, body_limit); if (rw_timeout_ >= 0) req.setRwTimeout(rw_timeout_); res.setCgiMode(cgi_mode); bool ret; http_method_t method = req.getMethod(); if (method == HTTP_METHOD_GET) ret = doGet(req, res); else if (method == HTTP_METHOD_POST) ret = doPost(req, res); else if (method == HTTP_METHOD_PUT) ret = doPut(req, res); else if (method == HTTP_METHOD_CONNECT) ret = doConnect(req, res); else if (method == HTTP_METHOD_PURGE) ret = doPurge(req, res); else { ret = false; // 有可能是IO失败或未知方法 http_request_error_t n = req.getLastError(); if (n == HTTP_REQ_ERR_METHOD) doUnknown(req, res); else doError(req, res); } if (in != out) { // 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑, // 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性 // 这样可以保证与客户端保持长连接 in->unbind(); out->unbind(); delete in; delete out; } return ret; }