gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 43/49: examples/web: Display UTF-8 keys and data as text


From: gnunet
Subject: [gnunet-scheme] 43/49: examples/web: Display UTF-8 keys and data as text.
Date: Sat, 25 Dec 2021 23:00:20 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit 89e65eb3f6ba1af5b9026c26ac1679a04ca15f59
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Thu Oct 7 11:06:36 2021 +0200

    examples/web: Display UTF-8 keys and data as text.
    
    * examples/web.scm
      (try-utf8->string,data->string): New procedures
      (process-search-dht): Use data->string for 'key' and 'data'.
---
 examples/web.scm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/examples/web.scm b/examples/web.scm
index f3fdc60..7311376 100644
--- a/examples/web.scm
+++ b/examples/web.scm
@@ -126,6 +126,17 @@
            (decode/data (assoc-ref parameters "data-encoding")
                         (assoc-ref parameters "data"))))
 
+(define (try-utf8->string bv) ; TODO: less duplication
+  (catch 'decoding-error
+    (lambda () (utf8->string bv))
+    (lambda _ #false)))
+
+(define (data->string slice)
+  (define bv (make-bytevector (slice-length slice)))
+  (slice-copy! slice (bv-slice/read-write bv))
+  (define as-string (try-utf8->string bv))
+  (or as-string (object->string bv)))
+
 (define (process-search-dht dht-server parameters)
   (define what)
   (define found? (make-condition))
@@ -154,9 +165,9 @@
                               `((dt "Type: ")
                                 (dd ,type)
                                 (dt "Key: ")
-                                (dd ,key)
+                                (dd ,(data->string key))
                                 (dt "Data: ")
-                                (dd ,(object->string data))
+                                (dd ,(data->string data))
                                 (dt "Expiration: ")
                                 (dd ,(object->string expiration))
                                 (dt "Get path: ") ; TODO as list

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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