8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Fixed CORE-5134: Samples of dbcrypt-related plugins contain references to internal files

This commit is contained in:
alexpeshkoff 2016-03-11 15:11:04 +00:00
parent 13bb1d3bd8
commit 0e32c78489
5 changed files with 55 additions and 55 deletions

View File

@ -24,13 +24,7 @@
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <ibase.h>
#include <firebird/Interface.h>
#include "../interfaces/ifaceExamples.h"
using namespace Firebird;

View File

@ -24,18 +24,7 @@
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "ibase.h"
#include "firebird/Interface.h"
#include "firebird.h" // Needed for atomic support
#include "../common/classes/fb_atomic.h"
using namespace Firebird;
#include "../interfaces/ifaceExamples.h"
namespace
{
@ -129,7 +118,7 @@ public:
return owner;
}
UCHAR getKey()
ISC_UCHAR getKey()
{
return key;
}
@ -144,7 +133,7 @@ private:
unsigned int callback(unsigned int, const void*, unsigned int length, void* buffer)
{
UCHAR k = holder->getKey();
ISC_UCHAR k = holder->getKey();
if (!k)
{
return 0;
@ -164,7 +153,7 @@ private:
class NamedCallback : public ICryptKeyCallbackImpl<NamedCallback, CheckStatusWrapper>
{
public:
NamedCallback(NamedCallback* n, const char* nm, UCHAR k)
NamedCallback(NamedCallback* n, const char* nm, ISC_UCHAR k)
: next(n), key(k)
{
strncpy(name, nm, sizeof(name));
@ -184,16 +173,16 @@ private:
char name[32];
NamedCallback* next;
UCHAR key;
ISC_UCHAR key;
};
CallbackInterface callbackInterface;
NamedCallback *named;
IPluginConfig* config;
UCHAR key;
ISC_UCHAR key;
AtomicCounter refCounter;
FbSampleAtomic refCounter;
IReferenceCounted* owner;
IConfigEntry* getEntry(CheckStatusWrapper* status, const char* entryName);
@ -265,7 +254,7 @@ ICryptKeyCallback* CryptKeyHolder::keyHandle(CheckStatusWrapper* status, const c
confEntry->release();
if (k > 0 && k < 256)
{
named = new NamedCallback(named, keyName, static_cast<UCHAR>(k));
named = new NamedCallback(named, keyName, static_cast<ISC_UCHAR>(k));
return named;
}
}

View File

@ -24,13 +24,7 @@
* Contributor(s): ______________________________________.
*/
#include <stdint.h>
#include "ibase.h"
#include "firebird/Interface.h"
#include "firebird.h" // Needed for atomic support
#include "../common/classes/fb_atomic.h"
#include "../interfaces/ifaceExamples.h"
using namespace Firebird;
@ -131,9 +125,9 @@ public:
private:
IPluginConfig* config;
char savedKeyName[32];
UCHAR key;
ISC_UCHAR key;
AtomicCounter refCounter;
FbSampleAtomic refCounter;
IReferenceCounted* owner;
void noKeyError(CheckStatusWrapper* status);
@ -169,8 +163,8 @@ void DbCrypt::encrypt(CheckStatusWrapper* status, unsigned int length, const voi
return;
}
const UCHAR* f = static_cast<const UCHAR*>(from);
UCHAR* t = static_cast<UCHAR*>(to);
const ISC_UCHAR* f = static_cast<const ISC_UCHAR*>(from);
ISC_UCHAR* t = static_cast<ISC_UCHAR*>(to);
while (length--)
{
@ -188,8 +182,8 @@ void DbCrypt::decrypt(CheckStatusWrapper* status, unsigned int length, const voi
return;
}
const UCHAR* f = static_cast<const UCHAR*>(from);
UCHAR* t = static_cast<UCHAR*>(to);
const ISC_UCHAR* f = static_cast<const ISC_UCHAR*>(from);
ISC_UCHAR* t = static_cast<ISC_UCHAR*>(to);
while (length--)
{

View File

@ -66,10 +66,13 @@ private:
}
};
FbSampleAtomic referenceCounter;
public:
unsigned offset, nullOffset, length;
MyMetadata()
: referenceCounter(0)
{
IUtil* utl = master->getUtilInterface();
ThrowStatusWrapper s(master->getStatus());
@ -86,16 +89,17 @@ public:
s.dispose();
}
// Dummy IReferenceCounted implementation
// JUST a SAMPLE - interface will be placed on stack, ignore reference counts !!!
// In real life please use your favorite atomic incr/decr here
// and create reference counted interfaces on heap.
void addRef()
{ }
{
++referenceCounter;
}
int release()
{
return 1;
int rc = --referenceCounter;
if (!rc)
delete this;
return rc;
}
// IMessageMetadata implementation
@ -200,15 +204,17 @@ int main()
IAttachment* att = NULL;
ITransaction* tra = NULL;
IResultSet* curs = NULL;
// Instance of our metadata
MyMetadata meta;
// allocate output buffer
buffer = new unsigned char[meta.length];
MyMetadata* meta = NULL;
try
{
// Instance of our metadata
meta = new MyMetadata;
meta->addRef();
// allocate output buffer
buffer = new unsigned char[meta->length];
// attach employee db
att = prov->attachDatabase(&status, "employee", 0, NULL);
@ -216,12 +222,12 @@ int main()
tra = att->startTransaction(&status, 0, NULL);
// open cursor
curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database", 3, NULL, NULL, &meta, NULL, 0);
curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database", 3, NULL, NULL, meta, NULL, 0);
// fetch record from cursor and print it
curs->fetchNext(&status, buffer);
ISC_SHORT l = to<ISC_SHORT>(buffer, meta.offset);
printf("<%*.*s>\n", l, l, buffer + meta.offset + sizeof(ISC_SHORT));
ISC_SHORT l = to<ISC_SHORT>(buffer, meta->offset);
printf("<%*.*s>\n", l, l, buffer + meta->offset + sizeof(ISC_SHORT));
// close interfaces
curs->close(&status);
@ -251,9 +257,11 @@ int main()
if (att)
att->release();
// generic cleanup
if (meta)
meta->release();
prov->release();
status.dispose();
delete[] buffer;
return rc;

View File

@ -28,7 +28,22 @@
#include <stdio.h>
#include <string.h>
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#include <atomic>
typedef std::atomic_int FbSampleAtomic;
#else
typedef int FbSampleAtomic;
#endif
#include <ibase.h>
#include <firebird/Interface.h>
#if defined(_WIN32)
#define FB_DLL_EXPORT __declspec(dllexport)
#elif defined(__APPLE__)
#define FB_DLL_EXPORT __attribute__((visibility("default")))
#else
#define FB_DLL_EXPORT
#endif
using namespace Firebird;