git repos / oastat

commit 7ab9196b

sago007 · 2018-11-10 18:52
7ab9196b3f452c5be2e78719a678b61ec2a93318 patch · browse files
parent 801999272734700e41df0fa54602b0cf77b17660

No longer uses variable arrays

Changed files

M README.md before
M src/local.h before
M src/oastat.cpp before
diff --git a/README.md b/README.md index 382e014..28d57cd 100644 --- a/README.md +++ b/README.md
@@ -1,4 +1,4 @@
-# Introduction
+# Introduction
Here you will be introduced on how to get data into oastat and how to get the data out again. Oastat can read both from file or pipe and can write output to either an SQL server or an XML file.
@@ -30,17 +30,17 @@ cd sql/create_tables/
This will create the scripts for PostgreSQL, MySQL and SQLite
-## Details
+## Details
-### Writing to XML-files
+### Writing to XML-files
The general arguments are like this:
oastat -f FILENAME --backend BACKEND --dbarg ARGUMENTS
-
+
* FILENAME is the file to be processed. If this is blank (like "") stdin will be read instead.
* BACKEND is the name of the backend, in this case "Xml"
- * ARGUMENTS is the argument list to the backend in case of Xml-backend the possible arguments are outputdir and possible a post process script.
+ * ARGUMENTS is the argument list to the backend in case of Xml-backend the possible arguments are outputdir and possible a post process script.
Running on a file:
@@ -52,21 +52,16 @@ Reading from stdin:
This will generate XML-files in the choosen output dir in this case *~/oastat*
-### Writing to database
-Writing to a postgreSQL database is very simple, at least if the database has been setup on the local machine with unix socket authentication.
-
- oastat -f "~/.openarena/baseoa/games.log" --backend "DbiXX" --dbarg "pgsql dbname oastat username openarena"
-
-
-Note that BACKEND is DbiXX which is the libary oastat uses for DB-access. Instead it is the first argument of the ARGUMENT list that decides what database-driver to use. The rest of ARGUMENT is the parameters with key followed by value so in the example the parameter "dbname" will be set to "oastat" and the parameter "username" will be set to "openarena"
+### Writing to database
+The recommended backend is CppDb. Writing to a MySQL server is done like this:
-Writing to a mySQL database is easy too:
+ oastat --backend "CppDb" --dbarg "mysql:database=oastat;user=<USERNAME>;password=<PASSWORD>"
- oastat -f "~/.openarena/baseoa/games.log" --backend "DbiXX" --dbarg "mysql dbname oastat username openarena"
+See <http://cppcms.com/sql/cppdb/connstr.html> for details on how to create the connection string.
-## Windows version
+## Windows version
A precompiled version for Windows can be found at: https://files.poulsander.com/~poul19/public_files/oastat/
-This version is compiled on a Debian system using MXE (http://mxe.cc/).
+This version is compiled on a Debian system using MXE (http://mxe.cc/).
The windows version only has support for XMl output and sqlite. The reason it does not support mySQL and PostgreSQL is because I was not able to compile a version of cppdb that supported it.
@@ -79,6 +74,6 @@ The windows version cannot read from stdin or use the "--tail" command but it do
For looking at the sqlite-file generated I recommend Sqliteman (http://sqliteman.com/)
## License
-The program is licences under GNU GPL v2 or any later version. See COPYING for details.
+The program is licences under GNU GPL v2 or any later version. See COPYING for details.
The Windows version may include files from CPPDB (http://cppcms.com/sql/cppdb/) that are licensed under the Boost Software License 1.0 or The MIT license at your opinion.
-The windows version may also be packed with sqlite3.exe that are in the public domain.
+The windows version may also be packed with sqlite3.exe that are in the public domain.
diff --git a/src/local.h b/src/local.h index 3b424fa..4a915ac 100644 --- a/src/local.h +++ b/src/local.h
@@ -32,7 +32,7 @@ https://github.com/sago007/oastat/
extern std::vector<std::string> clientIdMap;
/* returns the SHA-1 code of the parameter */
-extern std::string getHashedId(std::string unhashedID);
+std::string getHashedId(const std::string& unhashedID);
#endif /* _LOCAL_H */
diff --git a/src/oastat.cpp b/src/oastat.cpp index 1a485a6..9e29ad3 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -172,30 +172,29 @@ static int processStdIn(std::istream &in_p, std::vector<boost::shared_ptr<Struct
* @param unhashedID - The unhashed id
* @return the hashed id
*/
-std::string getHashedId(std::string unhashedID)
+std::string getHashedId(const std::string& unhashedID)
{
int msg_len = unhashedID.length();
int hash_len = gcry_md_get_algo_dlen( GCRY_MD_SHA1 );
- unsigned char hash_binary[ hash_len ];
- char hash_hex[ hash_len*2+1 ]; //surpriseingly this works
- char *out = hash_hex; //(char *) malloc( sizeof(char) * ((hash_len*2)+1) );
+ std::vector<unsigned char> hash_binary(hash_len);
+ std::vector<char> hash_hex(hash_len*2+1);
+ char *out = &hash_hex.at(0);
char *p = out;
- gcry_md_hash_buffer( GCRY_MD_SHA1, hash_binary, unhashedID.c_str(), msg_len );
+ gcry_md_hash_buffer( GCRY_MD_SHA1, &hash_binary[0], unhashedID.c_str(), msg_len );
for ( int i = 0; i < hash_len; i++, p += 2 ) {
snprintf ( p, 3, "%02x", hash_binary[i] );
}
- unhashedID = hash_hex;
+ std::string hashedID = &hash_hex.at(0);
- return unhashedID; //Replace with md5 at some point
+ return hashedID; //Replace with md5 at some point
}
int main (int argc, const char* argv[])
{
try {
std::string dbargs = "";
- std::string filename = "";
std::string backend = "Xml";
bool useTail = false;
bool doIntegrationTest = false;
@@ -204,7 +203,7 @@ int main (int argc, const char* argv[])
//dbargs = "mysql dbname oastat";
boost::format f("%1%/.openarena/baseoa/games.log");
f % getenv("HOME");
- filename = f.str();
+ std::string filename = f.str();
////////////
boost::program_options::options_description desc("Allowed options");
desc.add_options()