GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
GNUNET_free(rmsg);
- GNUNET_free(csh->name);
+ GNUNET_free_non_null(csh->name);
GNUNET_free(csh);
}
csh->unique_id = sh_msg->id;
name = (char*)&sh_msg[1];
+
+ if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
+ csh->name = NULL;
+ send_shorten_response(csh, name);
+ return;
+ }
+
+ if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
+ GNUNET_GNS_TLD) != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s is not our domain. Returning\n", name);
+ csh->name = NULL;
+ send_shorten_response(csh, name);
+ return;
+ }
+
csh->name = GNUNET_malloc(strlen(name)
- strlen(GNUNET_GNS_TLD) + 1);
memset(csh->name, 0,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
GNUNET_free(rmsg);
- GNUNET_free(cah->name);
+ GNUNET_free_non_null(cah->name);
GNUNET_free(cah);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
+
+ name = (char*)&sh_msg[1];
cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
cah->client = client;
cah->unique_id = sh_msg->id;
+
+ if (strlen(name) < strlen(GNUNET_GNS_TLD))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s is too short. Returning\n", name);
+ cah->name = NULL;
+ send_get_auth_response(cah, name);
+ return;
+ }
+
+ if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
+ GNUNET_GNS_TLD) != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s is not our domain. Returning\n", name);
+ cah->name = NULL;
+ send_get_auth_response(cah, name);
+ return;
+ }
- name = (char*)&sh_msg[1];
cah->name = GNUNET_malloc(strlen(name)
- strlen(GNUNET_GNS_TLD) + 1);
memset(cah->name, 0,
"Starting resolution for %s (type=%d)!\n",
name, record_type);
+
+ if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s is canonical and gnunet not our TLD!\n", name);
+ proc(cls, 0, NULL);
+ return;
+ }
+
rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle));
rh = GNUNET_malloc(sizeof (struct ResolverHandle));
rh->authority = zone;
rh->proc_cls = rlh;
- rh->name = GNUNET_malloc(strlen(name)
- - strlen(GNUNET_GNS_TLD));
- memset(rh->name, 0,
- strlen(name)-strlen(GNUNET_GNS_TLD));
- memcpy(rh->name, name,
- strlen(name)-strlen(GNUNET_GNS_TLD) - 1);
+
+ if (strcmp(GNUNET_GNS_TLD, name) == 0)
+ {
+ rh->name = GNUNET_malloc(2);
+ strcpy(rh->name, "");
+ }
+ else
+ {
+ rh->name = GNUNET_malloc(strlen(name)
+ - strlen(GNUNET_GNS_TLD));
+ memset(rh->name, 0,
+ strlen(name)-strlen(GNUNET_GNS_TLD));
+ memcpy(rh->name, name,
+ strlen(name)-strlen(GNUNET_GNS_TLD) - 1);
+ }
+
rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH);
rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
rh->authority_chain_head->prev = NULL;
answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
result = GNUNET_malloc(answer_len);
memset(result, 0, answer_len);
- strcpy(result, rh->name);
- strcpy(result+strlen(rh->name), ".");
- strcpy(result+strlen(rh->name)+1, name);
- strcpy(result+strlen(rh->name)+strlen(name)+1, ".");
- strcpy(result+strlen(rh->name)+strlen(name)+2, GNUNET_GNS_TLD);
+ if (strlen(rh->name) > 0)
+ {
+ strcpy(result, rh->name);
+ strcpy(result+strlen(rh->name), ".");
+ }
+
+ strcpy(result+strlen(result), name);
+ strcpy(result+strlen(result), ".");
+ strcpy(result+strlen(result), GNUNET_GNS_TLD);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Sending shorten result %s\n", result);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting shorten for %s!\n", name);
+ if (is_canonical((char*)name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s is canonical. Returning verbatim\n", name);
+ proc(cls, name);
+ return;
+ }
+
nsh = GNUNET_malloc(sizeof (struct NameShortenHandle));
+
+
+ nsh->proc = proc;
+ nsh->proc_cls = cls;
+
rh = GNUNET_malloc(sizeof (struct ResolverHandle));
rh->authority = zone;
rh->name = GNUNET_malloc(strlen(name)
rh->authority_chain_head->zone = zone;
rh->proc = &handle_delegation_ns_shorten;
rh->proc_cls = nsh;
-
- nsh->proc = proc;
- nsh->proc_cls = cls;
/* Start delegation resolution in our namestore */
resolve_delegation_ns(rh);
server_version = "TinyHTTPProxy/" + __version__
rbufsize = 0 # self.rfile Be unbuffered
host_port = ()
- to_replace = ""
def handle(self):
(ip, port) = self.client_address
def _connect_to(self, netloc, soc):
i = netloc.find(':')
+ to_replace = ""
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()
+ 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()
+ 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)
try: msg = arg[1]
except: msg = arg
self.send_error(404, msg)
- return 0
- return 1
+ return (0, 0)
+ return (1, to_replace)
def do_CONNECT(self):
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
- if self._connect_to(self.path, soc):
+ res, to_repl = self._connect_to(self.path, soc)
+ if res:
self.log_request(200)
self.wfile.write(self.protocol_version +
" 200 Connection established\r\n")
self.wfile.write("Proxy-agent: %s\r\n" % self.version_string())
self.wfile.write("\r\n")
- self._read_write(soc, 300)
+ self._read_write(soc, to_repl, 300)
finally:
print "\t" "bye"
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 replace_and_shorten(self, to_repl):
+ 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()
+ #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "")
+ #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(
return
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
- if self._connect_to(netloc, soc):
+ res, to_repl = self._connect_to(netloc, soc)
+ if res:
self.log_request()
soc.send("%s %s %s\r\n" % (
self.command,
for key_val in self.headers.items():
soc.send("%s: %s\r\n" % key_val)
soc.send("\r\n")
- self._read_write(soc)
+ self._read_write(soc, to_repl)
finally:
print "\t" "bye"
soc.close()
self.connection.close()
- def _read_write(self, soc, max_idling=20):
+ def _read_write(self, soc, to_repl="", max_idling=20):
iw = [self.connection, soc]
ow = []
count = 0
arr = self.host_port[0].split('.')
arr.pop(0)
data = re.sub('(a href="http://(\w+\.)*)(\+)',
- self.replace_and_shorten, data)
+ self.replace_and_shorten(to_repl), data)
print data
out.send(data)
count = 0