-mnencd : mnencd.o password.o mnenc.o
- g++ -o mnencd -g -Wall mnencd.o password.o mnenc.o
+mnencd : mnencd.o password.o mnenc.o php.o
+ g++ -o mnencd -g -Wall mnencd.o password.o mnenc.o php.o
-mnencd.o: mnencd.cpp password.hpp mnenc.hpp
+mnencd.o: mnencd.cpp password.hpp mnenc.hpp php.hpp
g++ -c -g -Wall mnencd.cpp
-password.o: password.cpp password.hpp
+password.o: password.cpp password.hpp
g++ -c -g -Wall password.cpp
mnenc.o: mnenc.cpp mnenc.hpp
g++ -c -g -Wall mnenc.cpp
+php.o: php.cpp php.hpp
+ g++ -c -g -Wall php.cpp
+
clean:
rm *.o mnencd
#include <string>
#include <iostream>
#include <fstream>
+#include "php.hpp"
+#include <vector>
+std::string masterpasswd = "";
std::string remove_char(std::string str, char c) {
std::string::size_type k = 0;
}
std::string do_something(std::string str) {
- if(str[0] == '0') {
- return "201_Created\n";
+ std::vector<std::string> request;
+ request = explode(str, "|");
+ if(request[0][0] == '0') {
+ if(masterpasswd == "") {
+ masterpasswd = request[1];
+ return "201_Created\n";
+ } else if(masterpasswd!= "") {
+ return "403 Forbidden\n";
+ } else {
+ return "400_Bad_Request " + str + '\n';
+ }
} else {
return "400_Bad_Request " + str + '\n';
}
--- /dev/null
+// php.cpp
+//
+// Copyright 2010 Micke Nordin <mickewiki@gmail.com>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301, USA.
+#include "php.hpp"
+
+vector<string> explode(string str, string separator) {
+ vector<string> results; //To hold the reslut
+ string::size_type found; //Varible to compare with
+ found = str.find_first_of(separator); //See if/where we have the separator
+ while(found != string::npos) { //While we have separators
+ if(found > 0) { //If we have a match
+ results.push_back(str.substr(0,found)); //Put it in the vector
+ }
+ str = str.substr(found+1); //Remove the part that has allready been used
+ found = str.find_first_of(separator);//Find next
+ }
+ if(str.length() > 0) { //Special case for the last bit
+ results.push_back(str);
+ }
+
+ return results;
+}
+
+string reverse(string &str) {
+ char c[str.size() + 1];
+ int j = 0;
+
+ for(int i = str.size(); i > 0; i--) {
+ c[j] = str[i];
+ j++;
+ }
+ c[str.size()] = '\0';
+ string rstr = c;
+ return rstr;
+
+}
+
+string trim(string &str, char const* sepSet) {
+ string::size_type const first = str.find_first_not_of(sepSet); //Find first char that is not the ones we want to remove
+
+ if(first==string::npos ) {
+ return string();
+ } else {
+ str = str.substr(first, str.find_last_not_of(sepSet)-first+1); //If we have chars we want to keep return those
+ str = reverse(str);
+ str.substr(first, str.find_last_not_of(sepSet)-first+1);
+ return reverse(str);
+ }
+}
--- /dev/null
+// php.hpp
+//
+// Copyright 2010 Micke Nordin <mickewiki@gmail.com>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301, USA.
+#ifndef _php_h_included_
+#define _php_h_included_
+#include <vector>
+#include <string>
+using namespace std;
+vector<string> explode(string str, string separator); //Make a vector<string> from a string by slitting by a delimiter
+string reverse(string &str); //Revers a string
+string trim(string &str, char const* sepSet); //Remove some characters from a string
+
+#endif
==Reply==
201_Created
400_Bad_Request
+403_Forbidden
500_Internal_Server_Error
503_Service_Unavailable