-(defun elpher-make-address (type &optional selector host port use-tls)
- "Create an address of a gopher object with TYPE, SELECTOR, HOST and PORT.
-Although selector host and port are optional, they are only omitted for
-special address types, such as 'start for the start page.
-
-Setting the USE-TLS parameter to non-nil causes Elpher to engage TLS mode
-before attempting to connect to the server."
- (if use-tls
- (list type selector host port 'tls)
- (list type selector host port)))
-
-(defun elpher-address-type (address)
- "Retrieve type from ADDRESS."
- (elt address 0))
-
-(defun elpher-address-selector (address)
- "Retrieve selector from ADDRESS."
- (elt address 1))
-
-(defun elpher-address-host (address)
- "Retrieve host from ADDRESS."
- (elt address 2))
-
-(defun elpher-address-port (address)
- "Retrieve port from ADDRESS."
- (elt address 3))
-
-(defun elpher-address-use-tls-p (address)
- "Return non-nil if ADDRESS is marked as needing TLS."
- (elt address 4))
-
-(defun elpher-address-special-p (address)
- "Return non-nil if ADDRESS is special (e.g. start page, bookmarks page)."
- (not (elpher-address-host address)))
+(defun elpher-url-from-string (url-string)
+ "Create a URL object corresponding to the given URL-STRING."
+ (let ((url (url-generic-parse-url url-string)))
+ (if (and (url-type url)
+ (url-host url))
+ (setf (url-filename url) (url-unhex-string (url-filename url)))
+ (error "Malformed URL" url))))
+
+(defun elpher-url-to-url-string (url)
+ "Get string representation of URL."
+ (url-encode-url (url-recreate url)))
+
+(defun elpher-url-gopher-p (url)
+ "Return non-nil if URL object specifies a gopher address."
+ (let ((protocol (url-type url)))
+ (if (or (string-equal protocol "gopher")
+ (string-equal protocol "gophers")))))
+
+(defun elpher-gopher-url-selector-type (url)
+ "Retrieve selector type from URL object."
+ (let ((filename (url-filename url)))
+ (if (> (length filename) 0)
+ (string-to-char filename)
+ ?1)))
+
+(defun elpher-gopher-url-selector (url)
+ "Retrieve selector from URL object."
+ (let ((filename (url-filename url)))
+ (if (> (length filename) 0)
+ (substring filename 1)
+ "")))
+
+(defun elpher-url-host (url)
+ "Retrieve host from URL object."
+ (url-host url))
+
+(defun elpher-url-port (url)
+ "Retrieve port from URL object."
+ (url-port url))
+
+(defun elpher-url-use-tls-p (url)
+ "Return non-nil if URL is marked as needing TLS."
+ (string-equal (url-type address) "gophers"))
+
+(defun elpher-url-special-p (url)
+ "Return non-nil if URL object is special (e.g. start page, bookmarks page)."
+ (symbolp url))