void HTTPRequestParser::parse (char *request) { char *p, *q; #ifdef VERBOSE_REQUEST_PARSER DPRINT (F("Parsing request: \"")); DPRINT (request); DPRINTLN (F("\"")); #endif url[0] = '\0'; if ((p = strstr_P (request, PSTR ("GET ")))) { if ((q = strchr (p + 4, ' '))) strlcpy (url, p + 4, q - p - 4 + 1 < MAX_URL_LEN ? q - p - 4 + 1 : MAX_URL_LEN); else strlcpy (url, p + 4, MAX_URL_LEN); #ifdef VERBOSE_REQUEST_PARSER DPRINT (F("Extracted URL: \"")); DPRINT (url); DPRINTLN (F("\"")); #endif } else { DPRINTLN (F("Cannot extract URL")); } }
const MCGame_f* QUndetGame<TFormula, TMove, _player>::add_subgame(const TMove* move, const MCGame_f* game) { if (game->get()->outcome() == _player) { if (is_pointmove<TMove>::value && move == NULL) { // compiler will optimize this away for non-pointmoves /* * The current player must not use the NULL move for their advantage. * An example where this may happen is testing whether the graph is * a complete graph: ALL x ALL y adj(x, y). * If there is a non-vertex in the PAST, the game for adj(x,y) * will return FALSE for the NULL move (due to the graph separator * property). Returning FALSE here would be wrong, when there is * no vertex left to come. We have to wait until this move is concrete. */ DPRINTLN(" --> re-check this " << formula()->variable()->identifier() << " later (when concrete)!"); QUndetGame<TFormula, TMove, _player>::set_subgame(NULL, game); return NULL; } else { DPRINTLN(" --> determines!"); delete this; return game; } } if (game->get()->outcome() == MCGame::opponent<_player>::value) { DPRINTLN(" --> ignore this " << formula()->variable()->identifier()<< "!"); delete game; return NULL; } DPRINTLN(" --> re-check this " << formula()->variable()->identifier() << " later!"); QUndetGame<TFormula, TMove, _player>::set_subgame(move, game); return NULL; }
void ApplyDynStep<Derived, ApplyGame, Solver>::init() { const TreeDecomposition* tdc = _solver->treedecomposition(); _node_bag = tdc->bag(_node); _child_bag = tdc->bag(_child); DPRINTLN("New Bag: " << *_node_bag << ", Old bag: " << *_child_bag); _terminal = find_terminal(); DPRINTLN("terminal " << _terminal << " is node " << vertex_of(_terminal)); _terminal_sym = _solver->terminal_symbol(_terminal); ((Derived*) this)->spec_init(); setup_assignment(); }
bool JPWiFly::finishCommand() { DPRINT("finishCommand : "); DPRINTLN(exitCommand); if (exitCommand > 0 && --exitCommand == 0) return exitCommandMode(); return true; }
void JPWiFly::writeDataLn_P(const prog_char *str) { DPRINT(F("writeDataLn_P: ")); DPRINTLN((const __FlashStringHelper *)str); serial->println((const __FlashStringHelper *)str); serial->flush(); }
void JPWiFly::writeData(const char *str) { DPRINT(F("writeData: ")); DPRINTLN(str); serial->print(str); serial->flush(); }
void ApplyJoinAssignment<Solver>::operator()(const SequoiaTable::const_iterator::value_type &entry) { const Assignment_f *alpha = entry.first; const GameVoidPtrMap *left_inmap = entry.second; SequoiaTable *right_table = _solver->table(_child_right); SequoiaTable::const_iterator ralpha_it = right_table->find(alpha); if (ralpha_it == right_table->end()) { // no compatible entries in the right table, no need to iterate. return; } assert(*alpha == *ralpha_it->first); const GameVoidPtrMap *right_inmap = ralpha_it->second; ApplyGameJoin<Solver> apply(_solver, _node, alpha); apply.init(); /* * Now we iterate over all games in a Cartesian manner and for each * pair we join the two games with each other. */ typedef PairIteratorStl<GameVoidPtrMap::const_iterator, GameVoidPtrMap::const_iterator> PairIt; PairIt pit(left_inmap->begin(), left_inmap->end(), right_inmap->begin(), right_inmap->end()); PairIt pitend(left_inmap->end(), right_inmap->end()); DPRINTLN("Start iterating over sets"); #ifdef HAVE_TBB tbb::parallel_do(pit, pitend, lightweight_apply(&apply)); #else std::for_each(pit, pitend, lightweight_apply(&apply)); #endif _solver->log_games_completed(apply.count()); }
boolean NetworkInterfaceWIZ5x00::begin (byte *mac, IPAddress ip, IPAddress dns, IPAddress gw, IPAddress mask) { #if defined (WEBBINO_USE_ENC28J60_UIP) DPRINTLN (F("Using UIP Ethernet library")); #else DPRINTLN (F("Using Arduino Ethernet library")); #endif memcpy (macAddress, mac, 6); Ethernet.begin (mac, ip, dns, gw, mask); server.begin (); dhcp = false; DPRINT (F("Server is at ")); DPRINTLN (Ethernet.localIP ()); return true; }
void WebServer::sendPage (WebClient* client) { unsigned int l = strlen (client -> request.url); if (l == 0 || client -> request.url[l - 1] == '/') { // Request for "/", redirect DPRINT (F("Redirecting to ")); DPRINT (client -> request.url); DPRINTLN (F(REDIRECT_ROOT_PAGE)); client -> print (F(HEADER_START REDIRECT_HEADER)); if (l == 0) client -> print ('/'); else client -> print (client -> request.url); client -> print (F(REDIRECT_ROOT_PAGE HEADER_END)); } else { const Page *page; char *pagename = client -> request.get_basename (); #if defined (WEBBINO_ENABLE_SD) || defined (WEBBINO_ENABLE_SDFAT) if (SD.exists (pagename)) { DPRINT (F("Sending page from SD file ")); DPRINTLN (pagename); SDContent content = SDContent (pagename); sendContent (client, &content); } else #endif if ((page = getPage (pagename))) { // Call page function PageFunction func = page -> getFunction (); if (func) func (client -> request); FlashContent content = FlashContent (page); sendContent (client, &content); } else { client -> print (F(HEADER_START NOT_FOUND_HEADER HEADER_END)); client -> print (F("<html><body><h3>No such page: \"")); client -> print (pagename); client -> print (F("\"</h3></body></html>")); } } client -> sendReply (); }
bool JPWiFly::startCommand() { if (exitCommand == 0 && !enterCommandMode()) return false; exitCommand++; DPRINT("startCommand : "); DPRINTLN(exitCommand); return true; }
const CacheIntroduceValue* ApplyGameIntroduce<Solver>::results(const MCGame_f* oldgame) { /* * The new alpha already contains the node and its full adjacency * (via the terminal moves). Use this to look up an entry in the cache. */ const Assignment_f* alpha = _solver->alpha(_node); const CacheIntroduceValue* cached = cache_introduce_lookup(oldgame->get()->formula(), alpha, oldgame, _intro_ts); if (cached != NULL) { DPRINTLN("Introduce Cache hit"); typename CacheIntroduceValue::const_iterator it; DEBUG({ for (it = cached->begin(); it != cached->end(); it++) { const MCGame_f *cached_game = it->second; DPRINTLN("Cache result: " << cached_game->get()->toString()); } });
void JPWiFly::terminal() { StCommand st(this); DPRINTLN(F("Terminal ready")); while (1) { if (Serial.available() > 0) serial->write(Serial.read()); if (serial->available()) Serial.write(serial->read()); } }
boolean NetworkInterfaceWIZ5x00::begin (byte *mac) { boolean ret; #if defined (WEBBINO_USE_ENC28J60_UIP) DPRINTLN (F("Using UIP Ethernet library")); #else DPRINTLN (F("Using Arduino Ethernet library")); #endif memcpy (macAddress, mac, 6); if ((ret = Ethernet.begin (mac))) { server.begin (); dhcp = true; DPRINT (F("Server is at ")); DPRINTLN (Ethernet.localIP ()); } return ret; }
boolean WebServer::loop () { WebClient *c = netint -> processPacket (); if (c != NULL) { // Got a client with a request, process it DPRINT (F("Request for \"")); DPRINT (c -> request.url); DPRINTLN (F("\"")); sendPage (c); } return c != NULL; }
void ApplyRoot<Solver>::operator()() { typename ApplyGameRoot<Solver>::ApplyGameInfo game_info; ApplyDynStepAssignment<ApplyGameRoot<Solver>, Solver> apply(_solver, _node, NULL, game_info); DPRINTLN("Start iterating over assignments..."); SequoiaTable *tab = _solver->table(_node); #ifdef HAVE_TBB tbb::parallel_do(tab->begin(), tab->end(), lightweight_apply(&apply)); #else std::for_each(tab->begin(), tab->end(), lightweight_apply(&apply)); #endif _has_solution = *game_info.has_solution; _solution = *game_info.solution; }
boolean TransducerProxy::read (char*& reply) { boolean ret; char buf[8] = {0}, *r; strcat (buf, "REA "); strcat (buf, name); strcat (buf, "\n"); if ((ret = srvpx -> sendcmd (buf, r))) { char *p[2]; if (splitString (r, p, 2) != 2) { DPRINT (F("AAA:")); DPRINTLN (r); ret = false; } else if (strcmp (p[0], name) != 0) { DPRINT (F("AAAAAA: ")); DPRINTLN (r); ret = false; } else { reply = p[1]; } } return ret; }
char *HTTPRequestParser::get_basename () { buffer[0] = '\0'; char *qMark = strchr (url, '?'); if (qMark) strlcpy (buffer, url, qMark - url + 1 < BUF_LEN ? qMark - url + 1 : BUF_LEN); else strlcpy (buffer, url, BUF_LEN); #ifdef VERBOSE_REQUEST_PARSER DPRINT (F("Extracted basename: \"")); DPRINT (buffer); DPRINTLN (F("\"")); #endif return buffer; }
boolean WebServer::begin (NetworkInterface& _netint, const Page* const _pages[] #ifdef ENABLE_TAGS , const ReplacementTag* const _substitutions[] #endif #if defined (WEBBINO_ENABLE_SD) || defined (WEBBINO_ENABLE_SDFAT) , int8_t pin #endif ) { boolean ret = true; netint = &_netint; pages = _pages; #ifndef WEBBINO_NDEBUG DPRINTLN (F("Pages available in flash memory:")); const Page *p = NULL; for (byte i = 0; pages && (p = reinterpret_cast<const Page *> (pgm_read_ptr (&pages[i]))); i++) { DPRINT (i); DPRINT (F(". ")); DPRINTLN (PSTR_TO_F (p -> getName ())); } #endif #ifdef ENABLE_TAGS substitutions = _substitutions; #ifndef WEBBINO_NDEBUG DPRINTLN (F("Tags available:")); const ReplacementTag* sub; for (byte i = 0; substitutions && (sub = reinterpret_cast<const ReplacementTag *> (pgm_read_ptr (&substitutions[i]))); i++) { DPRINT (i); DPRINT (F(". ")); DPRINTLN (PSTR_TO_F (sub -> getName ())); } #endif #endif #if defined (WEBBINO_ENABLE_SD) || defined (WEBBINO_ENABLE_SDFAT) if (pin >= 0) { DPRINT (F("Initializing SD card...")); if (!SD.begin (pin)) { DPRINTLN (F(" failed")); ret = false; } DPRINTLN (F(" done")); } #endif return ret; }
char *HTTPRequestParser::get_parameter (const char param[]) { char *start; boolean found = false; #ifdef VERBOSE_REQUEST_PARSER /* Print this now, because if we got called by * get_parameter(WebbinoFStr), param is actually stored in * buffer and will be overwritten. */ DPRINT (F("Extracting GET parameter: \"")); DPRINT (param); DPRINT (F("\": \"")); #endif for (start = strchr (url, '?'); !found && start; start = strchr (start + 1, '&')) { char *end = strchr (start, '='); if (end && (end - start - 1) == (int) strlen (param) && strncmp (start + 1, param, end - start - 1) == 0) { // Found! char *x = strchr (end + 1, '&'); if (x) strlcpy (buffer, end + 1, x - end < BUF_LEN ? x - end : BUF_LEN); else strlcpy (buffer, end + 1, BUF_LEN); found = true; } } if (!found) buffer[0] = '\0'; #ifdef VERBOSE_REQUEST_PARSER DPRINT (buffer); DPRINTLN (F("\"")); #endif return buffer; }
// Read the page, perform tag substitutions and send it over // FIXME: Handle unterminated tags void WebServer::sendContent (WebClient* client, PageContent* content) { // Send headers client -> print (F(HEADER_START OK_HEADER HEADER_END)); char c; #ifdef ENABLE_TAGS char tag[MAX_TAG_LEN]; int8_t tagLen = -1; // If >= 0 we are inside a tag #endif while ((c = content -> getNextByte ())) { #ifdef ENABLE_TAGS if (tagLen >= 0) { if (c == TAG_CHAR) { DPRINT (F("Processing replacement tag: \"")); DPRINT (tag); DPRINTLN (F("\"")); boolean found = false; if (strncmp_P (tag, PSTR ("GETP_"), 5) == 0) { char* rep = findSubstitutionTagGetParameter (client -> request, tag + 5); if (rep) { DPRINT (F("Replacement is: \"")); DPRINT (rep); DPRINTLN (F("\"")); client -> print (rep); found = true; } } else { PString* pstr = findSubstitutionTag (tag); if (pstr) { DPRINT (F("Replacement is: \"")); DPRINT (*pstr); DPRINTLN (F("\"")); client -> print (*pstr); pstr -> begin (); // Reset for next usage found = true; } } if (!found) { // Tag not found, emit it DPRINTLN (F("Tag not found")); client -> print (TAG_CHAR); client -> print (tag); client -> print (TAG_CHAR); } // Tag complete tagLen = -1; } else if (tagLen < MAX_TAG_LEN - 1) { tag[tagLen++] = c; tag[tagLen] = '\0'; } else { // Tag too long, emit what we got so far // FIXME: This will detect a fake tag at the closing TAG_CHAR client -> print (TAG_CHAR); client -> print (tag); client -> print (c); tagLen = -1; } } else { if (c == TAG_CHAR) { // Check if we have a tag to be replaced tag[0] = '\0'; tagLen = 0; } else { client -> print (c); } } #else client -> print (c); #endif } }
WebClient* NetworkInterfaceWIZ5x00::processPacket () { WebClient *ret = NULL; EthernetClient client = server.available (); if (client) { DPRINT (F("New client from ")); DPRINTLN (client.remoteIP ()); // An http request ends with a blank line boolean currentLineIsBlank = true; ethernetBufferSize = 0; boolean copy = true; while (client.connected ()) { if (client.available ()) { char c = client.read (); if (copy) { if (ethernetBufferSize < sizeof (ethernetBuffer)) { ethernetBuffer[ethernetBufferSize++] = c; } else { DPRINTLN (F("Ethernet buffer overflow")); break; } } // If you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, if (c == '\n' && currentLineIsBlank) { webClient.begin (client, (char *) ethernetBuffer); ret = &webClient; break; } if (c == '\n') { // See if we got the URL line if (strncmp_P ((char *) ethernetBuffer, PSTR ("GET "), 4) == 0) { // Yes, ignore the rest ethernetBuffer[ethernetBufferSize - 1] = '\0'; copy = false; } else { // No, start over ethernetBufferSize = 0; } // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data //delay (500); // If we are not returning a client, close the connection if (!ret) { client.stop (); DPRINTLN (F("Client disconnected")); } } return ret; }
void WebClientWIZ5x00::sendReply () { WebClient::sendReply (); internalClient.stop (); DPRINTLN (F("Client disconnected")); }
void JPWiFly::writeChar(char c) { DPRINT(F("writeChar: ")); DPRINTLN(c); serial->print(c); }
void JPWiFly::writeDataLn() { DPRINTLN(F("writeDataLn: ")); serial->println(); serial->flush(); }