Guest User

Untitled

a guest
Jul 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. ------WebKitFormBoundaryMOJKE6NQukiI7UMz
  2.  
  3. Content-Disposition: form-data; name="name"
  4.  
  5.  
  6.  
  7. Some наме
  8.  
  9. ------WebKitFormBoundaryMOJKE6NQukiI7UMz
  10.  
  11. Content-Disposition: form-data; name="datafile"; filename="GetCloudServer.sh"
  12.  
  13. Content-Type: application/octet-stream
  14.  
  15.  
  16.  
  17. File Contents here... can be binary...
  18.  
  19. ------WebKitFormBoundaryMOJKE6NQukiI7UMz--
  20.  
  21. template<typename _OutputIterator>
  22. void http_utils::split(std::string str, std::string delim, _OutputIterator result) {
  23. typedef boost::algorithm::split_iterator<std::string::iterator> string_split_iterator;
  24. for(string_split_iterator iter=boost::algorithm::make_split_iterator(str,
  25. boost::algorithm::first_finder(delim, boost::algorithm::is_equal()));
  26. iter!=string_split_iterator();
  27. ++iter) {
  28.  
  29. std::string component = boost::copy_range<std::string>(*iter);
  30. *result = component;
  31. ++result;
  32. }
  33. }
  34.  
  35. std::string http_utils::parse_file_upload_body( std::string contents )
  36. {
  37. /* Locate the start point. */
  38. unsigned startPoint = contents.find("rnrn");
  39. if (startPoint == std::string::npos) throw std::runtime_error("Malformed string.");
  40.  
  41. /* Locate the end point by finding the last newline, then backing up
  42. * to the newline before that.
  43. */
  44. unsigned endPoint = contents.rfind('n');
  45. if (endPoint == std::string::npos || endPoint == 0) throw std::runtime_error("Malformed string.");
  46. endPoint = contents.rfind('n', endPoint - 1);
  47. if (endPoint == std::string::npos) throw std::runtime_error("Malformed string.");
  48.  
  49. /* Hand back that slice of the string. */
  50. return std::string(contents.begin() + startPoint + 4, contents.begin() + endPoint-1);
  51. }
  52.  
  53. std::map<std::string, std::string> http_utils::parse_multipart_form_data( std::string form_data )
  54. {
  55. std::map<std::string, std::string> parsed_data;
  56. std::string tag_delimiter_content_disposition= "Content-Disposition: form-data; ";
  57. std::string taf_argument_name = "name";
  58. taf_argument_name += "="";
  59. std::vector < std::string > strings;
  60. std::string temp;
  61. this->split(form_data , tag_delimiter_content_disposition, std::insert_iterator<std::vector<std::string> >(strings, strings.begin()));
  62. BOOST_FOREACH(std::string str, strings)
  63. {
  64. size_t found_name = str.find(taf_argument_name);
  65. if (found_name != std::string::npos)
  66. {
  67. std::ofstream myfile;
  68.  
  69. size_t end_of_file_name = str.find(""", found_name + taf_argument_name.length());
  70. if (end_of_file_name != std::string::npos)
  71. {
  72. std::string filename(str, found_name + taf_argument_name.length(), end_of_file_name - (found_name + taf_argument_name.length()));
  73. std::string request_body_from_file_name_to_end(str, found_name + taf_argument_name.length(), str.length() - (found_name + taf_argument_name.length()));
  74. parsed_data.insert(std::pair<std::string, std::string>(filename, this->parse_file_upload_body(request_body_from_file_name_to_end)));
  75. }
  76. }
  77. }
  78. return parsed_data;
  79. }
Add Comment
Please, Sign In to add comment