def do_GET(self):
        if self.path.find('?') < 0:
            self.send_response(404)
            self.end_headers()
            self.wfile.write('404')
            return
        try:
            (stuff, args) = self.path.split('?', 1)
        except ValueError:  ## dummy
            args = self.path
        arglist = cgi.parse_qs(args)
        try:
            s = urllib.unquote(arglist['i'][0])
            sessionlist.add(s, arglist['t'][0], arglist['h'][0],
                            arglist['p'][0])
            sitem = sessionlist.get(s)
        except KeyError:
            s = None
            sitem = None

        if sitem and sitem.work:
            try:
                item = sitem.q.qin.get(True, QUEUE_TIMEOUT)
            except (Queue.Empty, ):
                item = None

            self.send_response(200)
            self.end_headers()

            count = 0

            if item:
                print 'snd: ', item.strip()
                self.wfile.write(httpencode(item))
                count = count + len(item)
                try:
                    while count < REQUES_MAX_SIZE:
                        item = sitem.q.qin.get(False)
                        if item:
                            print 'snd: ', item.strip()
                            self.wfile.write(httpencode(item))
                            count = count + len(item)
                except Queue.Empty:
                    item = None
        else:
            self.send_response(404)
            self.wfile.write('404')
            self.end_headers()
            if sitem:
                sitem.clean()
	def do_GET(self):
		if self.path.find('?') < 0:
			self.send_response(404)
			self.end_headers()
			self.wfile.write('404')
			return
		try:
			(stuff, args) = self.path.split('?',1)
		except ValueError: ## dummy
			args = self.path
		arglist = cgi.parse_qs(args)
		try:
			s = urllib.unquote(arglist['i'][0])
			sessionlist.add(s, arglist['t'][0], arglist['h'][0], arglist['p'][0])
			sitem = sessionlist.get(s)
		except KeyError:
			s = None
			sitem = None

		if sitem and sitem.work:
			try:
				item = sitem.q.qin.get(True, QUEUE_TIMEOUT)
			except (Queue.Empty, ):
				item = None
				
			self.send_response(200)
			self.end_headers()
			
			count = 0
			
			if item:
				print 'snd: ' , item.strip()
				self.wfile.write(httpencode(item))
				count = count + len(item)
				try:
					while count < REQUES_MAX_SIZE:
						item = sitem.q.qin.get(False)
						if item:
							print 'snd: ' , item.strip()
							self.wfile.write(httpencode(item))
							count = count + len(item)
				except Queue.Empty:
					item = None
		else:
			self.send_response(404)
			self.wfile.write('404')
			self.end_headers()
			if sitem:
				sitem.clean()
Exemple #3
0
 def pushData(self):
     item = None
     while self.work:
         try:
             item = self.q.qin.get(True, QUEUE_TIMEOUT)
         except (Queue.Empty, ):
             continue
             item = None
         while self.sid == '':
             print 'no sid'
             print 'item ', item
             time.sleep(QUEUE_TIMEOUT)
         m = myHash(time.time())
         datalist = [('i', self.sid), ('t', self.destType),
                     ('h', self.destHost), ('p', self.destPort), ('b', m)]
         post = None
         if item:
             try:
                 try:
                     while len(item) < REQUES_MAX_SIZE:
                         item = item + self.q.qin.get(False)
                 except Queue.Empty:
                     pass
                 post = httpencode(item)
             except AttributeError:
                 item = None
         else:
             continue
         myurl = self.url + '?' + urllib.urlencode(datalist)
         fetched = False
         try:
             req = urllib2.Request(url=myurl, data=post)
             if self.needAuth and self.authUsr and self.authPwd:
                 base64string = base64.encodestring(
                     '%s:%s' % (self.authUsr, self.authPwd))[:-1]
                 req.add_header("Authorization", "Basic %s" % base64string)
             f = urllib2.urlopen(req)
             fetched = True
         except urllib2.HTTPError, e:
             if e.code == 401:
                 self.needAuth = True
                 try:
                     if self.authUsr and self.authPwd:
                         base64string = base64.encodestring(
                             '%s:%s' % (self.authUsr, self.authPwd))[:-1]
                         req.add_header("Authorization",
                                        "Basic %s" % base64string)
                         f = urllib2.urlopen(req)
                         fetched = True
                 except urllib2.HTTPError:
                     fetched = False
         if fetched:
             ret = f.read()
             while ret:
                 if ret and ret != '':
                     #print 'rcv: ', ret.strip()
                     self.q.qout.put(httpdecode(ret))
                 ret = f.read()
         else:
             self.sl.terminate()
Exemple #4
0
    def do_GET(self):
        if self.path.find('?') < 0:
            if options.hide:
                self.send_response(404)
                self.send_header('Content-length', '3')
                self.send_header("Content-type", "text/html")
                self.end_headers()
                self.wfile.write('404')
            else:
                self.send_response(302, "Moved")
                self.send_header('Content-length', '0')
                self.send_header("Content-type", "text/html")
                self.send_header("Location", 'http://hstop.berlios.de/')
                self.end_headers()
            return
        try:
            (stuff, args) = self.path.split('?', 1)
        except ValueError:  ## dummy
            args = self.path
        arglist = cgi.parse_qs(args)
        try:
            s = urllib.unquote(arglist['i'][0])
            sessionlist.add(s, arglist['t'][0], arglist['h'][0],
                            arglist['p'][0], self.client_address)
            sitem = sessionlist.get(s)
        except KeyError:
            s = None
            sitem = None

        if sitem and sitem.work:
            try:
                item = sitem.q.qin.get(True, QUEUE_TIMEOUT)
            except (Queue.Empty, ):
                item = None

            if item:
                try:
                    while len(item) < REQUES_MAX_SIZE:
                        item = item + sitem.q.qin.get(False)
                except Queue.Empty:
                    pass
                self.send_response(200)
                self.send_header('Content-length', str(len(item)))
                self.end_headers()
                #print 'snd: ' , item.strip()
                self.wfile.write(httpencode(item))
            else:
                self.send_response(200)
                self.send_header('Content-length', '0')
                self.end_headers()
        else:
            self.send_response(404)
            self.send_header('Content-length', '3')
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write('404')
            if sitem:
                sitem.clean()
	def do_GET(self):
		if self.path.find('?') < 0:
			if options.hide:
				self.send_response(404)
				self.send_header('Content-length', '3')
				self.send_header("Content-type", "text/html")
				self.end_headers()
				self.wfile.write('404')
			else:
				self.send_response(302, "Moved")
				self.send_header('Content-length', '0')
				self.send_header("Content-type", "text/html")
				self.send_header("Location", 'http://hstop.berlios.de/')
				self.end_headers()
			return
		try:
			(stuff, args) = self.path.split('?',1)
		except ValueError: ## dummy
			args = self.path
		arglist = cgi.parse_qs(args)
		try:
			s = urllib.unquote(arglist['i'][0])
			sessionlist.add(s, arglist['t'][0], arglist['h'][0], arglist['p'][0], self.client_address)
			sitem = sessionlist.get(s)
		except KeyError:
			s = None
			sitem = None

		if sitem and sitem.work:
			try:
				item = sitem.q.qin.get(True, QUEUE_TIMEOUT)
			except (Queue.Empty, ):
				item = None
				
			if item:
				try:
					while len(item) < REQUES_MAX_SIZE:
						item = item + sitem.q.qin.get(False)
				except Queue.Empty:
					pass
				self.send_response(200)
				self.send_header('Content-length', str(len(item)))
				self.end_headers()
				#print 'snd: ' , item.strip()
				self.wfile.write(httpencode(item))
			else:
				self.send_response(200)
				self.send_header('Content-length', '0')
				self.end_headers()
		else:
			self.send_response(404)
			self.send_header('Content-length', '3')
			self.send_header("Content-type", "text/html")
			self.end_headers()
			self.wfile.write('404')
			if sitem:
				sitem.clean()
	def pushData(self):
		item = None
		while self.work:
			try:
				item = self.q.qin.get(True, QUEUE_TIMEOUT)
			except (Queue.Empty, ):
				continue
				item = None
			while self.sid == '':
				print 'no sid'
				print 'item ', item
				time.sleep(QUEUE_TIMEOUT)
			m = myHash(time.time())
			datalist = [('i', self.sid), ('t', self.destType), ('h', self.destHost), ('p', self.destPort), ('b', m)]
			post = None
			if item:
				try:
					try:
						while len(item) < REQUES_MAX_SIZE:
							item = item + self.q.qin.get(False)
					except Queue.Empty:
						pass
					post = httpencode(item)
				except AttributeError:
					item = None
			else:
				continue
			myurl = self.url + '?' + urllib.urlencode(datalist)
			fetched = False
			try:
				req = urllib2.Request(url=myurl,data=post)
				if self.needAuth and self.authUsr and self.authPwd:
					base64string = base64.encodestring('%s:%s' % (self.authUsr, self.authPwd))[:-1]
					req.add_header("Authorization", "Basic %s" % base64string)
				f = urllib2.urlopen(req)
				fetched = True
			except urllib2.HTTPError, e:
				if e.code == 401:
					self.needAuth = True
					try:
						if self.authUsr and self.authPwd:
							base64string = base64.encodestring('%s:%s' % (self.authUsr, self.authPwd))[:-1]
							req.add_header("Authorization", "Basic %s" % base64string)
							f = urllib2.urlopen(req)
							fetched = True
					except urllib2.HTTPError:
						fetched = False
			if fetched:
				ret = f.read()
				while ret:
					if ret and ret != '':
						#print 'rcv: ', ret.strip()
						self.q.qout.put(httpdecode(ret))
					ret = f.read()
			else:
				self.sl.terminate()