3030#include < vector>
3131
3232#ifndef _WIN32
33- #include < sys/utsname.h>
34- #include < odbcinst.h>
35- #else
33+ #ifdef PDO_SQLSRV
3634extern " C" {
3735#include " php_pdo_sqlsrv.h"
3836}
3937#include " php_pdo_sqlsrv_int.h"
38+ #elif SQLSRV
39+ extern " C" {
40+ #include " php_sqlsrv.h"
41+ }
42+ #include " php_sqlsrv_int.h"
43+ #endif
4044#endif
4145
4246// *** internal variables and constants ***
@@ -1158,7 +1162,17 @@ size_t core_str_zval_is_true(_Inout_ zval* value_z)
11581162 return 0 ; // false
11591163}
11601164
1161- void access_token_set_func::func ( _In_ connection_option const * option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str )
1165+ #ifdef _WIN32
1166+ ACCESSTOKEN** get_access_tokens () {
1167+ #ifdef PDO_SQLSRV
1168+ return PDO_SQLSRV_G (access_tokens);
1169+ #elif SQLSRV
1170+ return SQLSRV_G (access_tokens);
1171+ #endif
1172+ }
1173+ #endif
1174+
1175+ void access_token_set_func::func (_In_ connection_option const * option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str)
11621176{
11631177 SQLSRV_ASSERT (Z_TYPE_P (value) == IS_STRING, " An access token must be a byte string." );
11641178
@@ -1190,16 +1204,21 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
11901204#ifdef _WIN32
11911205 size_t next_token_position = 0 ;
11921206 bool same_token_used = false ;
1207+ #ifdef PDO_SQLSRV
1208+ unsigned int & access_tokens_size = PDO_SQLSRV_G (access_tokens_size);
1209+ #elif SQLSRV
1210+ unsigned int & access_tokens_size = SQLSRV_G (access_tokens_size);
1211+ #endif
11931212
1194- for (size_t current_token_index = 0 ; current_token_index < PDO_SQLSRV_G ( access_tokens_size) ; current_token_index++) {
1213+ for (size_t current_token_index = 0 ; current_token_index < access_tokens_size; current_token_index++) {
11951214 std::string string_token;
1196- for (size_t i = 0 ; i < PDO_SQLSRV_G (access_tokens )[current_token_index]->dataSize ; i += 2 ) {
1197- string_token.push_back (PDO_SQLSRV_G (access_tokens )[current_token_index]->data [i]);
1215+ for (size_t i = 0 ; i < get_access_tokens ( )[current_token_index]->dataSize ; i += 2 ) {
1216+ string_token.push_back (get_access_tokens ( )[current_token_index]->data [i]);
11981217 }
11991218 if (string_token == std::string (value_str)) {
12001219 // Token already exists in access_toiens
1201- memset (PDO_SQLSRV_G (access_tokens )[current_token_index]->data , 0 , PDO_SQLSRV_G (access_tokens )[current_token_index]->dataSize );
1202- sqlsrv_free (PDO_SQLSRV_G (access_tokens )[current_token_index]);
1220+ memset (get_access_tokens ( )[current_token_index]->data , 0 , get_access_tokens ( )[current_token_index]->dataSize );
1221+ sqlsrv_free (get_access_tokens ( )[current_token_index]);
12031222 next_token_position = current_token_index;
12041223 same_token_used = true ;
12051224 break ;
@@ -1208,7 +1227,6 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12081227#endif
12091228
12101229 size_t dataSize = 2 * value_len;
1211-
12121230 sqlsrv_malloc_auto_ptr<ACCESSTOKEN> accToken;
12131231 accToken = reinterpret_cast <ACCESSTOKEN*>(sqlsrv_malloc (sizeof (ACCESSTOKEN) + dataSize));
12141232
@@ -1230,10 +1248,14 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12301248 accToken.transferred ();
12311249#ifdef _WIN32
12321250 if (!same_token_used) {
1233- next_token_position = PDO_SQLSRV_G (access_tokens_size);
1234- PDO_SQLSRV_G (access_tokens_size)++;
1235- PDO_SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (PDO_SQLSRV_G (access_tokens), PDO_SQLSRV_G (access_tokens_size) * sizeof (ACCESSTOKEN)));
1251+ next_token_position = access_tokens_size;
1252+ access_tokens_size++;
1253+ #ifdef PDO_SQLSRV
1254+ PDO_SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (PDO_SQLSRV_G (access_tokens), access_tokens_size * sizeof (ACCESSTOKEN)));
1255+ #elif SQLSRV
1256+ SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (SQLSRV_G (access_tokens), access_tokens_size * sizeof (ACCESSTOKEN)));
1257+ #endif
12361258 }
1237- PDO_SQLSRV_G (access_tokens )[next_token_position] = conn->azure_ad_access_token ;
1259+ get_access_tokens ( )[next_token_position] = conn->azure_ad_access_token ;
12381260#endif
12391261}
0 commit comments