Skip to content

Commit

Permalink
hostname and user (from environ) send as is.
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Nov 2, 2011
1 parent 934afe0 commit 38a14f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
35 changes: 19 additions & 16 deletions firebirdsql/fbcore.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@


PYTHON_MAJOR_VER = sys.version_info[0] PYTHON_MAJOR_VER = sys.version_info[0]


if PYTHON_MAJOR_VER == 3: def b2i(b):
def ord(b): "byte to int"
if PYTHON_MAJOR_VER == 3:
return b return b
else:
return ord(b)


if PYTHON_MAJOR_VER == 2: if PYTHON_MAJOR_VER == 2:
def bytes(byte_array): def bytes(byte_array):
return ''.join([chr(c) for c in byte_array]) return ''.join([chr(c) for c in byte_array])


__version__ = '0.6.1' __version__ = '0.6.2'
apilevel = '2.0' apilevel = '2.0'
threadsafety = 1 threadsafety = 1
paramstyle = 'qmark' paramstyle = 'qmark'
Expand Down Expand Up @@ -235,7 +238,7 @@ def calc_blr(xsqlda):
def parse_select_items(buf, xsqlda, connection): def parse_select_items(buf, xsqlda, connection):
index = 0 index = 0
i = 0 i = 0
item = ord(buf[i]) item = b2i(buf[i])
while item != isc_info_end: while item != isc_info_end:
if item == isc_info_sql_sqlda_seq: if item == isc_info_sql_sqlda_seq:
l = bytes_to_int(buf[i+1:i+3]) l = bytes_to_int(buf[i+1:i+3])
Expand Down Expand Up @@ -285,7 +288,7 @@ def parse_select_items(buf, xsqlda, connection):
else: else:
print('\t', item, 'Invalid item [%02x] ! i=%d' % (buf[i], i)) print('\t', item, 'Invalid item [%02x] ! i=%d' % (buf[i], i))
i = i + 1 i = i + 1
item = ord(buf[i]) item = b2i(buf[i])
return -1 # no more info return -1 # no more info


def parse_xsqlda(buf, connection, stmt_handle): def parse_xsqlda(buf, connection, stmt_handle):
Expand Down Expand Up @@ -328,7 +331,7 @@ def __init__(self, cur, sql):
(h, oid, buf) = connection._op_response() (h, oid, buf) = connection._op_response()


i = 0 i = 0
if ord(buf[i]) == isc_info_sql_get_plan: if b2i(buf[i]) == isc_info_sql_get_plan:
l = bytes_to_int(buf[i+1:i+3]) l = bytes_to_int(buf[i+1:i+3])
self.plan = connection.bytes_to_str(buf[i+3:i+3+l]) self.plan = connection.bytes_to_str(buf[i+3:i+3+l])
i += 3 + l i += 3 + l
Expand Down Expand Up @@ -528,8 +531,8 @@ def uid(self):
else: else:
user = os.environ['USER'] user = os.environ['USER']
hostname = os.environ.get('HOSTNAME', '') hostname = os.environ.get('HOSTNAME', '')
user = self.str_to_bytes(user) # user = self.str_to_bytes(user)
hostname = self.str_to_bytes(hostname) # hostname = self.str_to_bytes(hostname)
return bytes([1] + [len(user)] + [ord(c) for c in user] return bytes([1] + [len(user)] + [ord(c) for c in user]
+ [4] + [len(hostname)] + [ord(c) for c in hostname] + [6, 0]) + [4] + [len(hostname)] + [ord(c) for c in hostname] + [6, 0])


Expand Down Expand Up @@ -674,7 +677,7 @@ def _db_info(self, info_requests):
i_request = 0 i_request = 0
r = [] r = []
while i < len(buf): while i < len(buf):
req = ord(buf[i]) req = b2i(buf[i])
if req == isc_info_end: if req == isc_info_end:
break break
assert req == info_requests[i_request] assert req == info_requests[i_request]
Expand All @@ -684,7 +687,7 @@ def _db_info(self, info_requests):
l = bytes_to_int(buf[i+1:i+3]) l = bytes_to_int(buf[i+1:i+3])
user_names.append(buf[i+3:i+3+l]) user_names.append(buf[i+3:i+3+l])
i = i + 3 + l i = i + 3 + l
req = ord(buf[i]) req = b2i(buf[i])
r.append(user_names) r.append(user_names)
else: else:
l = bytes_to_int(buf[i+1:i+3]) l = bytes_to_int(buf[i+1:i+3])
Expand Down Expand Up @@ -716,20 +719,20 @@ def _db_info_convert_type(self, info_request, v):


if info_request in (isc_info_base_level, ): if info_request in (isc_info_base_level, ):
# IB6 API guide p52 # IB6 API guide p52
return ord(v[1]) return b2i(v[1])
elif info_request in (isc_info_db_id, ): elif info_request in (isc_info_db_id, ):
# IB6 API guide p52 # IB6 API guide p52
conn_code = ord(v[0]) conn_code = b2i(v[0])
len1 = ord(v[1]) len1 = b2i(v[1])
filename = self.bytes_to_str(v[2:2+len1]) filename = self.bytes_to_str(v[2:2+len1])
len2 = ord(v[2+len1]) len2 = b2i(v[2+len1])
sitename = self.bytes_to_str(v[3+len1:3+len1+len2]) sitename = self.bytes_to_str(v[3+len1:3+len1+len2])
return (conn_code, filename, sitename) return (conn_code, filename, sitename)
elif info_request in (isc_info_implementation, ): elif info_request in (isc_info_implementation, ):
return (ord(v[1]), ord(v[2])) return (b2i(v[1]), b2i(v[2]))
elif info_request in (isc_info_version, isc_info_firebird_version): elif info_request in (isc_info_version, isc_info_firebird_version):
# IB6 API guide p53 # IB6 API guide p53
return self.bytes_to_str(v[2:2+ord(v[1])]) return self.bytes_to_str(v[2:2+b2i(v[1])])
elif info_request in (isc_info_user_names, ): elif info_request in (isc_info_user_names, ):
# IB6 API guide p54 # IB6 API guide p54
user_names = [] user_names = []
Expand Down
16 changes: 8 additions & 8 deletions firebirdsql/services.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -133,30 +133,30 @@ def trace_list(self, callback=None):
def _getIntegerVal(self, item_id): def _getIntegerVal(self, item_id):
self._op_service_info(bytes([]), bytes([item_id])) self._op_service_info(bytes([]), bytes([item_id]))
(h, oid, buf) = self._op_response() (h, oid, buf) = self._op_response()
assert ord(buf[0]) == item_id assert b2i(buf[0]) == item_id
return ord(buf[1]) return b2i(buf[1])


def _getStringVal(self, item_id): def _getStringVal(self, item_id):
self._op_service_info(bytes([]), bytes([item_id])) self._op_service_info(bytes([]), bytes([item_id]))
(h, oid, buf) = self._op_response() (h, oid, buf) = self._op_response()
assert ord(buf[0]) == item_id assert b2i(buf[0]) == item_id
ln = bytes_to_int(buf[1:3]) ln = bytes_to_int(buf[1:3])
return self.bytes_to_str(buf[3:3+ln]) return self.bytes_to_str(buf[3:3+ln])


def _getSvrDbInfo(self): def _getSvrDbInfo(self):
self._op_service_info(bytes([]), bytes([isc_info_svc_svr_db_info])) self._op_service_info(bytes([]), bytes([isc_info_svc_svr_db_info]))
(h, oid, buf) = self._op_response() (h, oid, buf) = self._op_response()
assert ord(buf[0]) == isc_info_svc_svr_db_info assert b2i(buf[0]) == isc_info_svc_svr_db_info
db_names=[] db_names=[]
i = 1 i = 1
while i < len(buf) and ord(buf[i]) != isc_info_flag_end: while i < len(buf) and b2i(buf[i]) != isc_info_flag_end:
if ord(buf[i]) == isc_spb_num_att: if b2i(buf[i]) == isc_spb_num_att:
num_attach = bytes_to_int(buf[i+1:i+5]) num_attach = bytes_to_int(buf[i+1:i+5])
i += 5 i += 5
elif ord(buf[i]) == isc_spb_num_db: elif b2i(buf[i]) == isc_spb_num_db:
num_db = bytes_to_int(buf[7:11]) num_db = bytes_to_int(buf[7:11])
i += 5 i += 5
elif ord(buf[i]) == isc_spb_dbname: elif b2i(buf[i]) == isc_spb_dbname:
ln = bytes_to_int(buf[i+1:i+3]) ln = bytes_to_int(buf[i+1:i+3])
db_name = self.bytes_to_str(buf[i+3:i+3+ln]) db_name = self.bytes_to_str(buf[i+3:i+3+ln])
db_names.append(db_name) db_names.append(db_name)
Expand Down

0 comments on commit 38a14f2

Please sign in to comment.