def _check_proxy(self): ''' check the proxy object ''' if not self.has_key('proxy'): self['proxy'] = {} c = self['proxy'] for i in c.iterkeys(): a = inet_string(i) if not a['host']: print('ERROR: invalid proxy server name = %s' % pss_name) raise ValueError c[i]['addr'] = a['host'] if not a['port']: a['port'] = 18889 c[i]['port'] = int(a['port']) # if c[i].has_key('ea') and c[i].has_key('en'): print('ERROR: only "ea" or "en" can be specified.') raise ValueError if not c[i].has_key('ea') and not c[i].has_key('en'): print('ERROR: either "ea" or "en" is required at least.') raise ValueError # # update the wstc object # if c[i].has_key('ea'): j = c[i]['ea'] if j not in self['wstc']: self['wstc'][j] = {'ee': 'yes', 'nm': self.west_name} elif c[i].has_key('en'): j = c[i]['en'] if j not in self['wstc']: self['wstc'][j] = {'ee': 'no', 'nm': self.west_name} self['wstc'][j]['so'] = 'unconnected' # # configuration for the url mapping. # for j in c[i].iterkeys(): if j in ['ea', 'en', 'addr', 'port']: continue if not j[0] == '/': raise ValueError('invalid keyword= %s' % c[i][j]) for k in c[i][j]: p = c[i][j] # if not p.has_key('ou'): raise ValueError('key "ou" is requred in %s%s.' % (i, j)) # if p.has_key('ca'): if not isinstance(p['ca'], list): raise ValueError( 'key "ca" must be a list in %s%s.' % (i, j))
def _check_proxy(self): ''' check the proxy object ''' if not self.has_key('proxy'): self['proxy'] = {} c = self['proxy'] for i in c.iterkeys(): a = inet_string(i) if not a['host']: print('ERROR: invalid proxy server name = %s' % pss_name) raise ValueError c[i]['addr'] = a['host'] if not a['port']: a['port'] = 18889 c[i]['port'] = int(a['port']) # if c[i].has_key('ea') and c[i].has_key('en'): print('ERROR: only "ea" or "en" can be specified.') raise ValueError if not c[i].has_key('ea') and not c[i].has_key('en'): print('ERROR: either "ea" or "en" is required at least.') raise ValueError # # update the wstc object # if c[i].has_key('ea'): j = c[i]['ea'] if j not in self['wstc']: self['wstc'][j] = { 'ee' : 'yes', 'nm' : self.west_name } elif c[i].has_key('en'): j = c[i]['en'] if j not in self['wstc']: self['wstc'][j] = { 'ee' : 'no', 'nm' : self.west_name } self['wstc'][j]['so'] = 'unconnected' # # configuration for the url mapping. # for j in c[i].iterkeys(): if j in [ 'ea', 'en', 'addr', 'port' ]: continue if not j[0] == '/': raise ValueError('invalid keyword= %s' % c[i][j]) for k in c[i][j]: p = c[i][j] # if not p.has_key('ou'): raise ValueError( 'key "ou" is requred in %s%s.' % (i, j)) # if p.has_key('ca'): if not isinstance(p['ca'], list): raise ValueError( 'key "ca" must be a list in %s%s.' % (i, j))
def _check_wsts(self): ''' check the wsts object ''' if not self.has_key('wsts'): self['wsts'] = {} c = self['wsts'] if c.has_key('sp'): a = inet_string(c['sp']) c['addr'] = a['host'] c['port'] = int(a['port']) if c.has_key('ca'): print('WARNING: key "ca" is not supported yet.')
def _check_west(self): ''' check the west object ''' if not self.has_key('west'): raise ValueError('the west object is required.') c = self['west'] self.west_name = c.get('nm') if not self.west_name: raise ValueError('nm attribute in the west object is required.') if c.has_key('cp'): a = inet_string(c['cp']) c['addr'] = a['host'] c['port'] = int(a['port'])
def __init__(self, url, host_in_header=None, debug_level=0): self.debug_level = debug_level a = inet_string(url) if host_in_header: self.host = host_in_header elif a['url_host']: self.host = a['url_host'] else: print('ERROR: Host field or URL host part are not defined.') return if self.debug_level: print('DEBUG: connecting to %s' % self.host) self.conn = httplib.HTTPConnection(self.host) self.path = a['url_path'] if a['url_path'] else '/'
def post_read(self, contents): ''' it called after the whole message from the client has been read. ''' # # convert Path into the outgoing URL, and Host into the HTTP server. # a = inet_string(self.server.jc_mine[self.path]['ou']) self.headers = dict(self.headers) if self.headers.has_key('host'): if is_debug(2, self.server.west): print('DEBUG: convert Host into %s from %s' % (self.headers['host'], a['url_host'])) self.headers['host'] = a['url_host'] if is_debug(2, self.server.west): print('DEBUG: convert Path into %s from %s' % (self.path, a['url_path'])) # msg_list = [] msg_list.append(' '.join([self.command, a['url_path'], self.request_version])) msg_list.append('\r\n') msg_list.extend(['%s: %s\r\n' % (k,v) for k,v in self.headers.iteritems()]) msg_list.append('\r\n') msg_list.extend(contents) # msg = ''.join(msg_list) if is_debug(1, self.server.west): print('DEBUG: sending proxy message length=', len(msg)) if is_debug(2, self.server.west): print('DEBUG: ---BEGIN: proxy server sending---') print(msg) print('DEBUG: ---END---') # ''' http sessions must be identified. each session must be assigned uuid. chunked data have to be assiened an identical uuid. ''' self.session_id = str(uuid.uuid4()) # # double check again whether there is a socket for the peer. # if self.server.s_ws: response = self.server.s_ws.send(self, msg, self.session_id, proxy_protocol='http') else: print('ERROR: The peer proxy is not available.') self.send_error(503) self.end_headers() return # # waiting for a response from the server # if is_debug(1, self.server.west): print('DEBUG: waiting for response from http server in %d seconds' % self.server_response_timer) self.waiting_for_server = Event() self.waiting_for_server.wait(self.server_response_timer) if not self.waiting_for_server.is_set(): print('INFO: timeout for waiting a response from http server')
def post_read(self, contents): ''' it called after the whole message from the client has been read. ''' # # convert Path into the outgoing URL, and Host into the HTTP server. # a = inet_string(self.server.jc_mine[self.path]['ou']) self.headers = dict(self.headers) if self.headers.has_key('host'): if is_debug(2, self.server.west): print('DEBUG: convert Host into %s from %s' % (self.headers['host'], a['url_host'])) self.headers['host'] = a['url_host'] if is_debug(2, self.server.west): print('DEBUG: convert Path into %s from %s' % (self.path, a['url_path'])) # msg_list = [] msg_list.append(' '.join( [self.command, a['url_path'], self.request_version])) msg_list.append('\r\n') msg_list.extend( ['%s: %s\r\n' % (k, v) for k, v in self.headers.iteritems()]) msg_list.append('\r\n') msg_list.extend(contents) # msg = ''.join(msg_list) if is_debug(1, self.server.west): print('DEBUG: sending proxy message length=', len(msg)) if is_debug(2, self.server.west): print('DEBUG: ---BEGIN: proxy server sending---') print(msg) print('DEBUG: ---END---') # ''' http sessions must be identified. each session must be assigned uuid. chunked data have to be assiened an identical uuid. ''' self.session_id = str(uuid.uuid4()) # # double check again whether there is a socket for the peer. # if self.server.s_ws: response = self.server.s_ws.send(self, msg, self.session_id, proxy_protocol='http') else: print('ERROR: The peer proxy is not available.') self.send_error(503) self.end_headers() return # # waiting for a response from the server # if is_debug(1, self.server.west): print( 'DEBUG: waiting for response from http server in %d seconds' % self.server_response_timer) self.waiting_for_server = Event() self.waiting_for_server.wait(self.server_response_timer) if not self.waiting_for_server.is_set(): print('INFO: timeout for waiting a response from http server')