fixing crashes in the network code

This commit is contained in:
Lionel Dricot 2023-08-14 12:23:09 +02:00
parent b7286b8039
commit c7740e0d5e
4 changed files with 25 additions and 13 deletions

View File

@ -5,6 +5,7 @@ List of things before release
TODO: man pages for netcache, ansicat, opnk
REGR: restore gemini certificate code
REGR: implement grep
REGR: avoid asking for user input while in non-interactive mode
This is an an experimental and unstable release. Lot of breakages are expected.
Wait for 2.1 if you are not willing to do testing/bug reporting.
- Licence has been changed to AGPL for ideological reasons
@ -12,8 +13,8 @@ Wait for 2.1 if you are not willing to do testing/bug reporting.
- New command-line tool: "ansicat"
- New command-line tool: "opnk"
- URL do not default anymore to "gemini://" if not protocol are indicated.
- Images of html files are now always downloaded with the html (slower but better experience)
- Reading position is now saved for the whole session
- Images of html files are now downloaded with the html (slower but better experience)
- Reading position is saved for the whole session
- Gopher-only: we dont support naming a page after the name of the incoming link
## 1.10 - July 31st 2023

View File

@ -1131,7 +1131,9 @@ _FORMAT_RENDERERS = {
}
def get_mime(path):
#Beware, this one is really a shaddy ad-hoc function
if path.startswith("mailto:"):
if not path:
return None
elif path.startswith("mailto:"):
mime = "mailto"
elif os.path.isdir(path):
mime = "Local Folder"
@ -1165,6 +1167,8 @@ def get_mime(path):
return mime
def renderer_from_file(path,url=None):
if not path:
return None
mime = get_mime(path)
if not url:
url = path

View File

@ -192,7 +192,7 @@ def get_cache_path(url):
# Now, we have a partial path. Lets make it full path.
if local:
cache_path = path
else:
elif scheme and host:
cache_path = os.path.expanduser(_CACHE_PATH + scheme + "/" + host + path)
#Theres an OSlimitation of 260 characters per path.
#We will thus cut the path enough to add the index afterward
@ -222,6 +222,10 @@ def get_cache_path(url):
#and we try to access folder
if os.path.isdir(cache_path):
cache_path += "/" + index
else:
#URL is missing either a supported scheme or a valid host
#print("Error: %s is not a supported url"%url)
return None
if len(cache_path) > 259:
print("Path is too long. This is an OS limitation.\n\n")
print(url)
@ -881,6 +885,7 @@ def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,**kwargs):
if status == "11":
user_input = getpass.getpass("> ")
else:
#TODO:FIXME we should not ask for user input while non-interactive
user_input = input("> ")
return _fetch_gemini(query(user_input))
# Redirects

View File

@ -1685,15 +1685,17 @@ Argument : duration of cache validity (in seconds)."""
#we should only savetotour at the first level of recursion
# The code for this was removed so, currently, we savetotour
# at every level of recursion.
links = self.get_renderer(url).get_links(mode="links_only")
subcount = [0,len(links)]
d = depth - 1
for k in links:
#recursive call (validity is always 0 in recursion)
substri = strin + " -->"
subcount[0] += 1
fetch_url(k,depth=d,validity=0,savetotour=savetotour,\
count=subcount,strin=substri)
r = self.get_renderer(url)
if r:
links = r.get_links(mode="links_only")
subcount = [0,len(links)]
d = depth - 1
for k in links:
#recursive call (validity is always 0 in recursion)
substri = strin + " -->"
subcount[0] += 1
fetch_url(k,depth=d,validity=0,savetotour=savetotour,\
count=subcount,strin=substri)
def fetch_list(list,validity=0,depth=1,tourandremove=False,tourchildren=False):
links = self.list_get_links(list)
end = len(links)