diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-15 16:35:54 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-15 16:35:54 +0000 |
commit | 172579d4d2c0af3986943ef1ca907ebe43b7031d (patch) | |
tree | 19657005d0174fb8278c88c72646764efac4aa42 | |
parent | 605211861dd9dfd1b3f46d4c1b8a314061eda134 (diff) | |
download | gnunet-172579d4d2c0af3986943ef1ca907ebe43b7031d.tar.gz gnunet-172579d4d2c0af3986943ef1ca907ebe43b7031d.zip |
-fixes
-rw-r--r-- | src/gns/gnunet-service-gns.c | 43 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 61 | ||||
-rw-r--r-- | src/gns/proxy/proxy.py | 39 |
3 files changed, 108 insertions, 35 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index aa3d3b3e8..ac5c74818 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -414,7 +414,7 @@ send_shorten_response(void* cls, const char* name) | |||
414 | GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); | 414 | GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); |
415 | 415 | ||
416 | GNUNET_free(rmsg); | 416 | GNUNET_free(rmsg); |
417 | GNUNET_free(csh->name); | 417 | GNUNET_free_non_null(csh->name); |
418 | GNUNET_free(csh); | 418 | GNUNET_free(csh); |
419 | 419 | ||
420 | } | 420 | } |
@@ -462,6 +462,23 @@ static void handle_shorten(void *cls, | |||
462 | csh->unique_id = sh_msg->id; | 462 | csh->unique_id = sh_msg->id; |
463 | 463 | ||
464 | name = (char*)&sh_msg[1]; | 464 | name = (char*)&sh_msg[1]; |
465 | |||
466 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { | ||
467 | csh->name = NULL; | ||
468 | send_shorten_response(csh, name); | ||
469 | return; | ||
470 | } | ||
471 | |||
472 | if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD), | ||
473 | GNUNET_GNS_TLD) != 0) | ||
474 | { | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
476 | "%s is not our domain. Returning\n", name); | ||
477 | csh->name = NULL; | ||
478 | send_shorten_response(csh, name); | ||
479 | return; | ||
480 | } | ||
481 | |||
465 | csh->name = GNUNET_malloc(strlen(name) | 482 | csh->name = GNUNET_malloc(strlen(name) |
466 | - strlen(GNUNET_GNS_TLD) + 1); | 483 | - strlen(GNUNET_GNS_TLD) + 1); |
467 | memset(csh->name, 0, | 484 | memset(csh->name, 0, |
@@ -512,7 +529,7 @@ send_get_auth_response(void *cls, const char* name) | |||
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n"); | 529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n"); |
513 | 530 | ||
514 | GNUNET_free(rmsg); | 531 | GNUNET_free(rmsg); |
515 | GNUNET_free(cah->name); | 532 | GNUNET_free_non_null(cah->name); |
516 | GNUNET_free(cah); | 533 | GNUNET_free(cah); |
517 | 534 | ||
518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n"); | 535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n"); |
@@ -557,12 +574,32 @@ static void handle_get_authority(void *cls, | |||
557 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 574 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
558 | return; | 575 | return; |
559 | } | 576 | } |
577 | |||
578 | name = (char*)&sh_msg[1]; | ||
560 | 579 | ||
561 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); | 580 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); |
562 | cah->client = client; | 581 | cah->client = client; |
563 | cah->unique_id = sh_msg->id; | 582 | cah->unique_id = sh_msg->id; |
583 | |||
584 | if (strlen(name) < strlen(GNUNET_GNS_TLD)) | ||
585 | { | ||
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
587 | "%s is too short. Returning\n", name); | ||
588 | cah->name = NULL; | ||
589 | send_get_auth_response(cah, name); | ||
590 | return; | ||
591 | } | ||
592 | |||
593 | if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD), | ||
594 | GNUNET_GNS_TLD) != 0) | ||
595 | { | ||
596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "%s is not our domain. Returning\n", name); | ||
598 | cah->name = NULL; | ||
599 | send_get_auth_response(cah, name); | ||
600 | return; | ||
601 | } | ||
564 | 602 | ||
565 | name = (char*)&sh_msg[1]; | ||
566 | cah->name = GNUNET_malloc(strlen(name) | 603 | cah->name = GNUNET_malloc(strlen(name) |
567 | - strlen(GNUNET_GNS_TLD) + 1); | 604 | - strlen(GNUNET_GNS_TLD) + 1); |
568 | memset(cah->name, 0, | 605 | memset(cah->name, 0, |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index dee082e99..a2f61af0e 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -1095,17 +1095,36 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, | |||
1095 | "Starting resolution for %s (type=%d)!\n", | 1095 | "Starting resolution for %s (type=%d)!\n", |
1096 | name, record_type); | 1096 | name, record_type); |
1097 | 1097 | ||
1098 | |||
1099 | if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0)) | ||
1100 | { | ||
1101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1102 | "%s is canonical and gnunet not our TLD!\n", name); | ||
1103 | proc(cls, 0, NULL); | ||
1104 | return; | ||
1105 | } | ||
1106 | |||
1098 | rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle)); | 1107 | rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle)); |
1099 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); | 1108 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); |
1100 | 1109 | ||
1101 | rh->authority = zone; | 1110 | rh->authority = zone; |
1102 | rh->proc_cls = rlh; | 1111 | rh->proc_cls = rlh; |
1103 | rh->name = GNUNET_malloc(strlen(name) | 1112 | |
1104 | - strlen(GNUNET_GNS_TLD)); | 1113 | if (strcmp(GNUNET_GNS_TLD, name) == 0) |
1105 | memset(rh->name, 0, | 1114 | { |
1106 | strlen(name)-strlen(GNUNET_GNS_TLD)); | 1115 | rh->name = GNUNET_malloc(2); |
1107 | memcpy(rh->name, name, | 1116 | strcpy(rh->name, ""); |
1108 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | 1117 | } |
1118 | else | ||
1119 | { | ||
1120 | rh->name = GNUNET_malloc(strlen(name) | ||
1121 | - strlen(GNUNET_GNS_TLD)); | ||
1122 | memset(rh->name, 0, | ||
1123 | strlen(name)-strlen(GNUNET_GNS_TLD)); | ||
1124 | memcpy(rh->name, name, | ||
1125 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | ||
1126 | } | ||
1127 | |||
1109 | rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH); | 1128 | rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH); |
1110 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | 1129 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); |
1111 | rh->authority_chain_head->prev = NULL; | 1130 | rh->authority_chain_head->prev = NULL; |
@@ -1164,11 +1183,15 @@ process_zone_to_name_shorten(void *cls, | |||
1164 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; | 1183 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; |
1165 | result = GNUNET_malloc(answer_len); | 1184 | result = GNUNET_malloc(answer_len); |
1166 | memset(result, 0, answer_len); | 1185 | memset(result, 0, answer_len); |
1167 | strcpy(result, rh->name); | 1186 | if (strlen(rh->name) > 0) |
1168 | strcpy(result+strlen(rh->name), "."); | 1187 | { |
1169 | strcpy(result+strlen(rh->name)+1, name); | 1188 | strcpy(result, rh->name); |
1170 | strcpy(result+strlen(rh->name)+strlen(name)+1, "."); | 1189 | strcpy(result+strlen(rh->name), "."); |
1171 | strcpy(result+strlen(rh->name)+strlen(name)+2, GNUNET_GNS_TLD); | 1190 | } |
1191 | |||
1192 | strcpy(result+strlen(result), name); | ||
1193 | strcpy(result+strlen(result), "."); | ||
1194 | strcpy(result+strlen(result), GNUNET_GNS_TLD); | ||
1172 | 1195 | ||
1173 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1196 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1174 | "Sending shorten result %s\n", result); | 1197 | "Sending shorten result %s\n", result); |
@@ -1313,7 +1336,20 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, | |||
1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1314 | "Starting shorten for %s!\n", name); | 1337 | "Starting shorten for %s!\n", name); |
1315 | 1338 | ||
1339 | if (is_canonical((char*)name)) | ||
1340 | { | ||
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1342 | "%s is canonical. Returning verbatim\n", name); | ||
1343 | proc(cls, name); | ||
1344 | return; | ||
1345 | } | ||
1346 | |||
1316 | nsh = GNUNET_malloc(sizeof (struct NameShortenHandle)); | 1347 | nsh = GNUNET_malloc(sizeof (struct NameShortenHandle)); |
1348 | |||
1349 | |||
1350 | nsh->proc = proc; | ||
1351 | nsh->proc_cls = cls; | ||
1352 | |||
1317 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); | 1353 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); |
1318 | rh->authority = zone; | 1354 | rh->authority = zone; |
1319 | rh->name = GNUNET_malloc(strlen(name) | 1355 | rh->name = GNUNET_malloc(strlen(name) |
@@ -1329,9 +1365,6 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, | |||
1329 | rh->authority_chain_head->zone = zone; | 1365 | rh->authority_chain_head->zone = zone; |
1330 | rh->proc = &handle_delegation_ns_shorten; | 1366 | rh->proc = &handle_delegation_ns_shorten; |
1331 | rh->proc_cls = nsh; | 1367 | rh->proc_cls = nsh; |
1332 | |||
1333 | nsh->proc = proc; | ||
1334 | nsh->proc_cls = cls; | ||
1335 | 1368 | ||
1336 | /* Start delegation resolution in our namestore */ | 1369 | /* Start delegation resolution in our namestore */ |
1337 | resolve_delegation_ns(rh); | 1370 | resolve_delegation_ns(rh); |
diff --git a/src/gns/proxy/proxy.py b/src/gns/proxy/proxy.py index 7a73c4797..4438f33fa 100644 --- a/src/gns/proxy/proxy.py +++ b/src/gns/proxy/proxy.py | |||
@@ -31,7 +31,6 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
31 | server_version = "TinyHTTPProxy/" + __version__ | 31 | server_version = "TinyHTTPProxy/" + __version__ |
32 | rbufsize = 0 # self.rfile Be unbuffered | 32 | rbufsize = 0 # self.rfile Be unbuffered |
33 | host_port = () | 33 | host_port = () |
34 | to_replace = "" | ||
35 | 34 | ||
36 | def handle(self): | 35 | def handle(self): |
37 | (ip, port) = self.client_address | 36 | (ip, port) = self.client_address |
@@ -43,19 +42,20 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
43 | 42 | ||
44 | def _connect_to(self, netloc, soc): | 43 | def _connect_to(self, netloc, soc): |
45 | i = netloc.find(':') | 44 | i = netloc.find(':') |
45 | to_replace = "" | ||
46 | if i >= 0: | 46 | if i >= 0: |
47 | print 'calling gnunet-gns -a '+netloc[:i] | 47 | print 'calling gnunet-gns -a '+netloc[:i] |
48 | auth = os.popen("gnunet-gns -a "+netloc[:i]) | 48 | auth = os.popen("gnunet-gns -a "+netloc[:i]) |
49 | lines = auth.readlines() | 49 | lines = auth.readlines() |
50 | print 'result: '+lines[0].split(" ")[-1].rstrip() | 50 | print 'result: '+lines[0].split(" ")[-1].rstrip() |
51 | self.to_replace = lines[0].split(" ")[-1].rstrip() | 51 | to_replace = lines[0].split(" ")[-1].rstrip() |
52 | self.host_port = netloc[:i], int(netloc[i+1:]) | 52 | self.host_port = netloc[:i], int(netloc[i+1:]) |
53 | else: | 53 | else: |
54 | print 'calling gnunet-gns -a '+netloc | 54 | print 'calling gnunet-gns -a '+netloc |
55 | auth = os.popen("gnunet-gns -a "+netloc) | 55 | auth = os.popen("gnunet-gns -a "+netloc) |
56 | lines = auth.readlines() | 56 | lines = auth.readlines() |
57 | print 'result: '+lines[0].split(" ")[-1].rstrip() | 57 | print 'result: '+lines[0].split(" ")[-1].rstrip() |
58 | self.to_replace = lines[0].split(" ")[-1].rstrip() | 58 | to_replace = lines[0].split(" ")[-1].rstrip() |
59 | self.host_port = netloc, 80 | 59 | self.host_port = netloc, 80 |
60 | print "\t" "connect to %s:%d" % self.host_port | 60 | print "\t" "connect to %s:%d" % self.host_port |
61 | try: soc.connect(self.host_port) | 61 | try: soc.connect(self.host_port) |
@@ -63,31 +63,33 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
63 | try: msg = arg[1] | 63 | try: msg = arg[1] |
64 | except: msg = arg | 64 | except: msg = arg |
65 | self.send_error(404, msg) | 65 | self.send_error(404, msg) |
66 | return 0 | 66 | return (0, 0) |
67 | return 1 | 67 | return (1, to_replace) |
68 | 68 | ||
69 | def do_CONNECT(self): | 69 | def do_CONNECT(self): |
70 | soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 70 | soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
71 | try: | 71 | try: |
72 | if self._connect_to(self.path, soc): | 72 | res, to_repl = self._connect_to(self.path, soc) |
73 | if res: | ||
73 | self.log_request(200) | 74 | self.log_request(200) |
74 | self.wfile.write(self.protocol_version + | 75 | self.wfile.write(self.protocol_version + |
75 | " 200 Connection established\r\n") | 76 | " 200 Connection established\r\n") |
76 | self.wfile.write("Proxy-agent: %s\r\n" % self.version_string()) | 77 | self.wfile.write("Proxy-agent: %s\r\n" % self.version_string()) |
77 | self.wfile.write("\r\n") | 78 | self.wfile.write("\r\n") |
78 | self._read_write(soc, 300) | 79 | self._read_write(soc, to_repl, 300) |
79 | finally: | 80 | finally: |
80 | print "\t" "bye" | 81 | print "\t" "bye" |
81 | soc.close() | 82 | soc.close() |
82 | self.connection.close() | 83 | self.connection.close() |
83 | 84 | ||
84 | def replace_and_shorten(self, mo): | 85 | def replace_and_shorten(self, to_repl): |
85 | full = string.replace(mo.group(1)+self.to_replace, 'a href="', "") | 86 | 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() |
86 | print 'calling gnunet-gns -s '+full | 87 | #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "") |
87 | s = os.popen("gnunet-gns -s "+full) | 88 | #print 'calling gnunet-gns -s '+full |
88 | lines = s.readlines() | 89 | #s = os.popen("gnunet-gns -s "+full) |
89 | print 'short: '+lines[0].split(" ")[-1].rstrip() | 90 | #lines = s.readlines() |
90 | return 'a href="'+lines[0].split(" ")[-1].rstrip() | 91 | #print 'short: '+lines[0].split(" ")[-1].rstrip() |
92 | #return 'a href="'+lines[0].split(" ")[-1].rstrip() | ||
91 | 93 | ||
92 | def do_GET(self): | 94 | def do_GET(self): |
93 | (scm, netloc, path, params, query, fragment) = urlparse.urlparse( | 95 | (scm, netloc, path, params, query, fragment) = urlparse.urlparse( |
@@ -97,7 +99,8 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
97 | return | 99 | return |
98 | soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 100 | soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
99 | try: | 101 | try: |
100 | if self._connect_to(netloc, soc): | 102 | res, to_repl = self._connect_to(netloc, soc) |
103 | if res: | ||
101 | self.log_request() | 104 | self.log_request() |
102 | soc.send("%s %s %s\r\n" % ( | 105 | soc.send("%s %s %s\r\n" % ( |
103 | self.command, | 106 | self.command, |
@@ -108,13 +111,13 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
108 | for key_val in self.headers.items(): | 111 | for key_val in self.headers.items(): |
109 | soc.send("%s: %s\r\n" % key_val) | 112 | soc.send("%s: %s\r\n" % key_val) |
110 | soc.send("\r\n") | 113 | soc.send("\r\n") |
111 | self._read_write(soc) | 114 | self._read_write(soc, to_repl) |
112 | finally: | 115 | finally: |
113 | print "\t" "bye" | 116 | print "\t" "bye" |
114 | soc.close() | 117 | soc.close() |
115 | self.connection.close() | 118 | self.connection.close() |
116 | 119 | ||
117 | def _read_write(self, soc, max_idling=20): | 120 | def _read_write(self, soc, to_repl="", max_idling=20): |
118 | iw = [self.connection, soc] | 121 | iw = [self.connection, soc] |
119 | ow = [] | 122 | ow = [] |
120 | count = 0 | 123 | count = 0 |
@@ -136,7 +139,7 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
136 | arr = self.host_port[0].split('.') | 139 | arr = self.host_port[0].split('.') |
137 | arr.pop(0) | 140 | arr.pop(0) |
138 | data = re.sub('(a href="http://(\w+\.)*)(\+)', | 141 | data = re.sub('(a href="http://(\w+\.)*)(\+)', |
139 | self.replace_and_shorten, data) | 142 | self.replace_and_shorten(to_repl), data) |
140 | print data | 143 | print data |
141 | out.send(data) | 144 | out.send(data) |
142 | count = 0 | 145 | count = 0 |