gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20501 - in gnunet/src/gns: . proxy


From: gnunet
Subject: [GNUnet-SVN] r20501 - in gnunet/src/gns: . proxy
Date: Wed, 14 Mar 2012 18:07:11 +0100

Author: schanzen
Date: 2012-03-14 18:07:11 +0100 (Wed, 14 Mar 2012)
New Revision: 20501

Modified:
   gnunet/src/gns/gnunet-service-gns_interceptor.c
   gnunet/src/gns/proxy/proxy.py
Log:
-proxy magic, interceptor fix


Modified: gnunet/src/gns/gnunet-service-gns_interceptor.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_interceptor.c     2012-03-14 15:36:52 UTC 
(rev 20500)
+++ gnunet/src/gns/gnunet-service-gns_interceptor.c     2012-03-14 17:07:11 UTC 
(rev 20501)
@@ -107,7 +107,6 @@
     
     if (rd[i].record_type == ilh->query->type)
     {
-      num_answers++;
       answer_records[i].name = ilh->query->name;
       answer_records[i].type = rd[i].record_type;
       answer_records[i].data.raw.data_len = rd[i].data_size;
@@ -279,6 +278,8 @@
     if (*(tldoffset-i) == '.')
       break;
   }
+
+  i--;
   
   if ((i==strlen(GNUNET_GNS_TLD)-1)
       && (0 == strcmp(tldoffset-i, GNUNET_GNS_TLD)))

Modified: gnunet/src/gns/proxy/proxy.py
===================================================================
--- gnunet/src/gns/proxy/proxy.py       2012-03-14 15:36:52 UTC (rev 20500)
+++ gnunet/src/gns/proxy/proxy.py       2012-03-14 17:07:11 UTC (rev 20501)
@@ -22,7 +22,7 @@
 
 __version__ = "0.2.1"
 
-import BaseHTTPServer, select, socket, SocketServer, urlparse, re
+import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os
 
 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
     __base = BaseHTTPServer.BaseHTTPRequestHandler
@@ -31,6 +31,7 @@
     server_version = "TinyHTTPProxy/" + __version__
     rbufsize = 0                        # self.rfile Be unbuffered
     host_port = ()
+    to_replace = ""
 
     def handle(self):
         (ip, port) =  self.client_address
@@ -43,8 +44,18 @@
     def _connect_to(self, netloc, soc):
         i = netloc.find(':')
         if i >= 0:
+            print 'calling gnunet-gns -a '+netloc[:i]
+            auth = os.popen("gnunet-gns -a "+netloc[:i])
+            lines = auth.readlines()
+            print 'result: '+lines[0].split(" ")[-1].rstrip()
+            self.to_replace = lines[0].split(" ")[-1].rstrip()
             self.host_port = netloc[:i], int(netloc[i+1:])
         else:
+            print 'calling gnunet-gns -a '+netloc
+            auth = os.popen("gnunet-gns -a "+netloc)
+            lines = auth.readlines()
+            print 'result: '+lines[0].split(" ")[-1].rstrip()
+            self.to_replace = lines[0].split(" ")[-1].rstrip()
             self.host_port = netloc, 80
         print "\t" "connect to %s:%d" % self.host_port
         try: soc.connect(self.host_port)
@@ -70,6 +81,14 @@
             soc.close()
             self.connection.close()
 
+    def replace_and_shorten(self, mo):
+      full = string.replace(mo.group(1)+self.to_replace, 'a href="', "")
+      print 'calling gnunet-gns -s '+full
+      s = os.popen("gnunet-gns -s "+full)
+      lines = s.readlines()
+      print 'short: '+lines[0].split(" ")[-1].rstrip()
+      return 'a href="'+lines[0].split(" ")[-1].rstrip()
+
     def do_GET(self):
         (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
             self.path, 'http')
@@ -116,8 +135,8 @@
                         if (re.match("(\w+\.)*gnunet", self.host_port[0])):
                             arr = self.host_port[0].split('.')
                             arr.pop(0)
-                            data = re.sub(r'(a href="http://(\w+\.)*)(\+)',
-                                r'\1'+'.'.join(arr), data)
+                            data = re.sub('(a href="http://(\w+\.)*)(\+)',
+                                self.replace_and_shorten, data)
                         print data
                         out.send(data)
                         count = 0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]