changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result) it reads binary (bytea) data added: DbTextStream can handle 'bool' types now (is puts 'true' of 'false' to the stream) changed: now passwords can be stored either as plain text, a hash or can be encrypted with RSA currently we have following hashes: md4, md5, sha1, sha224, sha256, sha384, sha512 we are using openssl to manage them (look at config options for more info) changed: winix version to 0.4.7 added: class Run - you can run any program from os and send a buffer to its standard input and read what the program put on its standard output added: class Crypt (in System) - calculating hashes, and crypting/decrypting git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
102
db/dbbase.cpp
102
db/dbbase.cpp
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -151,6 +151,21 @@ return temp_wide_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
|
||||
{
|
||||
result.clear();
|
||||
|
||||
const char * res = AssertValue(r, row, col);
|
||||
int len = PQgetlength(r, row, col);
|
||||
|
||||
if( len <= 0 )
|
||||
return;
|
||||
|
||||
UnescapeBin(res, len, result);
|
||||
}
|
||||
|
||||
|
||||
void DbBase::AssertValueWide(PGresult * r, int row, int col, std::wstring & result)
|
||||
{
|
||||
const char * res = AssertValue(r, row, col);
|
||||
@@ -172,7 +187,8 @@ int DbBase::AssertValueInt(PGresult * r, int row, int col)
|
||||
|
||||
bool DbBase::AssertValueBool(PGresult * r, int row, int col)
|
||||
{
|
||||
return strtol( AssertValue(r, row, col), 0, 10 ) != 0;
|
||||
const char * s = AssertValue(r, row, col);
|
||||
return (s[0]=='t' || s[0]=='y' || s[0]=='1');
|
||||
}
|
||||
|
||||
|
||||
@@ -429,3 +445,85 @@ Error DbBase::EndTrans(Error err)
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
converting from a bytea
|
||||
*/
|
||||
|
||||
int DbBase::CharToInt(char c)
|
||||
{
|
||||
return (int)(unsigned char)(c-'0');
|
||||
}
|
||||
|
||||
bool DbBase::IsCorrectOctalDigit(char c)
|
||||
{
|
||||
return c>='0' && c<='7';
|
||||
}
|
||||
|
||||
// moves 'i' at least once
|
||||
// return -1 if there is en error
|
||||
int DbBase::UnescapeBin(const char * str, size_t & i, size_t len)
|
||||
{
|
||||
if( str[i] != '\\' )
|
||||
return str[i++];
|
||||
|
||||
i += 1;
|
||||
|
||||
if( i >= len )
|
||||
return -1;
|
||||
|
||||
if( str[i] == '\\' )
|
||||
return str[i++];
|
||||
|
||||
if( i+2 >= len )
|
||||
{
|
||||
i = len;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( !IsCorrectOctalDigit(str[i]) ||
|
||||
!IsCorrectOctalDigit(str[i+1]) ||
|
||||
!IsCorrectOctalDigit(str[i+2]) )
|
||||
{
|
||||
i += 3;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int c = 8*8*CharToInt(str[i]) + 8*CharToInt(str[i+1]) + CharToInt(str[i+2]);
|
||||
|
||||
i += 3;
|
||||
|
||||
if( c<0 || c>255 )
|
||||
return -1;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void DbBase::UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out)
|
||||
{
|
||||
int c;
|
||||
size_t i = 0;
|
||||
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
|
||||
while( i < len )
|
||||
{
|
||||
c = UnescapeBin(str, i, len);
|
||||
|
||||
if( c != -1 )
|
||||
out += c;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
end of converting from bytea
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user