/// \brief Eat the board at the direction specified /// \param isH Is horizontal /// /// true for horizontal and false for vertical /// \param direction The direction to eat to /// /// positive for left/up and negative for right/down /// \return The number of empty grids char Eat(bool isH,int direction){ char blank=0; if(isH){ for(int i=0;i!=N;++i){ AlignLine(i,direction); blank+=EatLine(i,direction); } }else{ for(int i=0;i!=N;++i){ AlignCol(i,direction); blank+=EatCol(i,direction); } } return blank; }
void ParseMultipartFormData( webserver::http_request& req, Socket* s) { static const std::string multipart_form_data = "multipart/form-data"; if(req.content_type_.substr(0, multipart_form_data.size()) == multipart_form_data) // Difficult data... :( { AStringVector ContentTypeData = StringSplit( req.content_type_, "; " ); std::string boundary; // Find boundary for( unsigned int i = 0; i < ContentTypeData.size(); ++i ) { static const std::string boundary_ = "boundary="; if( ContentTypeData[i].substr(0, boundary_.size()) == boundary_ ) // Found boundary { boundary = ContentTypeData[i].substr( boundary_.size() ); } } //LOGINFO("Boundary: %s", boundary.c_str() ); std::string boundary_start = "--" + boundary; std::string boundary_end = boundary_start + "--"; std::string Content = s->ReceiveBytes( req.content_length_ ); //printf("Total content: \n%s\n", Content.c_str() ); // Should start with boundary! std::string line = EatLine( Content ); if( line.substr(0, boundary_start.size() ) != boundary_start ) { // Something was wrong! :( Content.clear(); } while( !Content.empty() ) { webserver::formdata FormData; static const std::string content_disposition = "Content-Disposition: "; static const std::string content_type = "Content-Type: "; std::string f_disposition; while( 1 ) { std::string line = EatLine( Content ); if( line.empty() ) break; unsigned int pos_cr_lf = line.find_first_of("\x0a\x0d"); if (pos_cr_lf == 0) break; // Empty line, indicates end of mime thingy if( line.substr(0, content_disposition.size() ) == content_disposition ) { f_disposition = line.substr(content_disposition.size()); LOGINFO("Disposition: %s", f_disposition.c_str() ); } else if( line.substr(0, content_type.size() ) == content_type ) { FormData.content_type_ = line.substr(content_type.size()); } //LOGINFO("Got line: '%s'", line.c_str() ); } // Check if we got the proper headers if( !f_disposition.empty() ) { static const std::string disp_name = "name="; static const std::string disp_filename = "filename="; // Parse the disposition AStringVector DispositionData = StringSplit( f_disposition, "; " ); for( unsigned int i = 0; i < DispositionData.size(); ++i ) { if( DispositionData[i].substr(0, disp_name.size()) == disp_name ) { FormData.name_ = GetQuotedString( DispositionData[i].substr(disp_name.size()) ); } else if( DispositionData[i].substr(0, disp_filename.size()) == disp_filename ) { FormData.filename_ = GetQuotedString( DispositionData[i].substr(disp_filename.size()) ); } } std::string ContentValue; // Parse until boundary_end is found while( 1 ) { std::string line = EatLine( Content ); if( line.empty() ) break; if( line.substr(0, boundary_end.size() ) == boundary_end ) { break; } else if( line.substr(0, boundary_start.size() ) == boundary_start ) { break; } ContentValue.append( line.c_str(), line.size() ); } FormData.value_ = ContentValue; } req.multipart_formdata_.push_back( FormData ); } } }