Callback Example
The following code snippet enables the Sybase Open Client Access Module to use external login authentication. It has a database callback class, UserSybDatabaseCallbackImp, which only redefines the producer method produceConnCallback() to create a new instance of the connection callback class, UserSybConnCallbackImp.
The Connection Callback class, UserSybConnCallbackImp, only redefines the preConnect() callback method to clear the username and password and set various login authentication properties.
This example does not provide an instance of the connection callback class in the method RWDBDatabase::connection(), as it is created from the connCallback() producer method in the UserSybDatabaseCallbackImp class. To use this code, the <ver> placeholder in any library names would need to be replaced with the actual digits representing the library version number.
 
/////////////////////////////////////////////////////////////////////
//
// UserSybConnCallbackImp
//
/////////////////////////////////////////////////////////////////////
class UserSybConnCallbackImp : public RWDBConnCallbackImp {
public:
// Callbacks
virtual void preConnect();
};
 
 
void
UserSybConnCallbackImp::preConnect()
{
RWDBSybCtLibSystemHandle* sybCtSysH =
(RWDBSybCtLibSystemHandle*)systemHandle();
CS_CONNECTION* cs_conn = sybCtSysH->csconn();
 
// Clear username and password
ct_con_props(cs_conn, CS_CLEAR, CS_USERNAME,
NULL, CS_UNUSED, (CS_INT *)NULL);
ct_con_props(cs_conn, CS_CLEAR, CS_PASSWORD,
NULL, CS_UNUSED, (CS_INT *)NULL);
 
// Apply security services
CS_BOOL boolval = CS_TRUE;
ct_con_props(cs_conn, CS_SET, CS_SEC_NETWORKAUTH,
&boolval, CS_UNUSED, NULL);
ct_con_props(cs_conn, CS_SET, CS_SEC_MUTUALAUTH,
&boolval, CS_UNUSED, NULL);
ct_con_props(cs_conn, CS_SET, CS_SEC_CONFIDENTIALITY,
&boolval, CS_UNUSED, NULL);
ct_con_props(cs_conn, CS_SET, CS_SEC_INTEGRITY,
&boolval, CS_UNUSED, NULL);
ct_con_props(cs_conn, CS_SET, CS_SEC_DETECTREPLAY,
&boolval, CS_UNUSED, NULL);
ct_con_props(cs_conn, CS_SET, CS_SEC_DETECTSEQ,
&boolval, CS_UNUSED, NULL);
}
 
 
 
/////////////////////////////////////////////////////////////////////
//
// UserSybDatabaseCallbackImp
//
/////////////////////////////////////////////////////////////////////
class UserSybDatabaseCallbackImp : public RWDBDatabaseCallbackImp {
public:
// Connection callback producer
virtual RWDBConnCallback produceConnCallback();
};
 
 
RWDBConnCallback
UserSybDatabaseCallbackImp::produceConnCallback()
{
return RWDBCONNCALLBACK(UserSybConnCallbackImp);
}
 
 
 
/////////////////////////////////////////////////////////////////////
//
// main
//
/////////////////////////////////////////////////////////////////////
int main()
{
RWDBDatabase db = RWDBManager::database(
"ctl<ver>15d.dll", "server", "", "", "",
RWDBDATABASECALLBACK(UserSybDatabaseCallbackImp));
RWDBConnection conn = db.connection();
 
return 0;
}