aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/proxy/gnunet-gns-proxy.py27
-rw-r--r--src/gns/test_gns_simple_lookup.conf1
2 files changed, 20 insertions, 8 deletions
diff --git a/src/gns/proxy/gnunet-gns-proxy.py b/src/gns/proxy/gnunet-gns-proxy.py
index f13a0adad..d53776872 100644
--- a/src/gns/proxy/gnunet-gns-proxy.py
+++ b/src/gns/proxy/gnunet-gns-proxy.py
@@ -22,7 +22,7 @@ Any help will be greatly appreciated. SUZUKI Hisao
22 22
23__version__ = "0.2.1" 23__version__ = "0.2.1"
24 24
25import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os 25import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os, sys
26 26
27class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): 27class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
28 __base = BaseHTTPServer.BaseHTTPRequestHandler 28 __base = BaseHTTPServer.BaseHTTPRequestHandler
@@ -87,22 +87,33 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
87 print "\t" "bye" 87 print "\t" "bye"
88 soc.close() 88 soc.close()
89 self.connection.close() 89 self.connection.close()
90
91 def test_re2(self, mo):
92 short = os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', ""))
93 lines = short.readlines()
94 if (len(lines) < 1):
95 return mo.group(1)
96 elif (len(lines[0].split(" ")) > 0):
97 return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
98 else:
99 return mo.group(1)
90 100
91 def shorten_zkey(self): 101 def shorten_zkey(self):
92 return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip() 102 return lambda mo: self.test_re2(mo)
103 #return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip()
93 104
94 def test_re(self, to_repl, mo): 105 def test_re(self, to_repl, mo):
95 short = os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")) 106 short = os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', ""))
96 lines = short.readlines() 107 lines = short.readlines()
97 if (len(lines) < 1): 108 if (len(lines) < 1):
98 return to_repl 109 return to_repl
99 elif (len(lines.split(" ")) > 0): 110 elif (len(lines[0].split(" ")) > 0):
100 return 'a href="http://'+lines.split(" ")[-1].rstrip() 111 return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
101 else: 112 else:
102 return to_repl 113 return to_repl
103 114
104 def replace_and_shorten(self, to_repl): 115 def replace_and_shorten(self, to_repl):
105 return lambda mo: test_re(self, to_repl, mo) 116 return lambda mo: self.test_re(to_repl, mo)
106 # return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip() 117 # return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip()
107 #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "") 118 #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "")
108 #print 'calling gnunet-gns -s '+full 119 #print 'calling gnunet-gns -s '+full
@@ -166,7 +177,7 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
166 out = soc 177 out = soc
167 data = i.recv(8192) 178 data = i.recv(8192)
168 if data: 179 if data:
169 try: 180 #try:
170 data = re.sub(r'\nAccept-Ranges: \w+', r'', data) 181 data = re.sub(r'\nAccept-Ranges: \w+', r'', data)
171 data = re.sub('(a href="http://(\w+\.)*zkey)', 182 data = re.sub('(a href="http://(\w+\.)*zkey)',
172 self.shorten_zkey(), data) 183 self.shorten_zkey(), data)
@@ -177,8 +188,8 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
177 self.replace_and_shorten(to_repl), data) 188 self.replace_and_shorten(to_repl), data)
178 out.send(data) 189 out.send(data)
179 count = 0 190 count = 0
180 except: 191 #except:
181 print "GNS exception:", sys.exc_info()[0] 192 # print "GNS exception:", sys.exc_info()[0]
182 193
183 else: 194 else:
184 print "\t" "idle", count 195 print "\t" "idle", count
diff --git a/src/gns/test_gns_simple_lookup.conf b/src/gns/test_gns_simple_lookup.conf
index b609e03b2..410fe6319 100644
--- a/src/gns/test_gns_simple_lookup.conf
+++ b/src/gns/test_gns_simple_lookup.conf
@@ -1,3 +1,4 @@
1@INLINE@ test_gns_defaults.conf
1[fs] 2[fs]
2AUTOSTART = NO 3AUTOSTART = NO
3 4