[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `p
From: |
Rémi Birot-Delrue |
Subject: |
[gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `pointer->string*`. * common.scm: add `bool->int` and `int->bool`, two functions to easily convert `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to booleans. * fs/uri.scm: export `keyword-list->string`. * tests/uri.scm: test `keyword-list->string`. * scheduler.scm: add `cancel-task!`. |
Date: |
Wed, 12 Aug 2015 18:24:37 +0000 |
remibd pushed a commit to branch master
in repository gnunet.
commit 6fc73cee9beb1d9498dee6de90ff089794e55f3f
Author: RĂ©mi Birot-Delrue <address@hidden>
Date: Tue Jul 21 13:01:28 2015 +0200
Add a few utility functions.
* binding-utils.scm: add `pointer->string*`.
* common.scm: add `bool->int` and `int->bool`, two functions to easily
convert
`gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to
booleans.
* fs/uri.scm: export `keyword-list->string`.
* tests/uri.scm: test `keyword-list->string`.
* scheduler.scm: add `cancel-task!`.
---
gnu/gnunet/binding-utils.scm | 4 ++++
gnu/gnunet/common.scm | 9 +++++++++
gnu/gnunet/fs/uri.scm | 4 +++-
gnu/gnunet/scheduler.scm | 3 +++
tests/uri.scm | 4 ++++
5 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/gnu/gnunet/binding-utils.scm b/gnu/gnunet/binding-utils.scm
index 4f33306..cabbcf7 100644
--- a/gnu/gnunet/binding-utils.scm
+++ b/gnu/gnunet/binding-utils.scm
@@ -32,6 +32,7 @@
rassoc-ref
string->pointer*
+ pointer->string*
make-c-struct*))
(define (getf plist value)
@@ -74,3 +75,6 @@
if STRING is empty (\"\")."
(if (string=? "" string) %null-pointer (string->pointer string)))
+(define (pointer->string* ptr)
+ (if (eq? %null-pointer ptr) #f (pointer->string ptr)))
+
diff --git a/gnu/gnunet/common.scm b/gnu/gnunet/common.scm
index 7aa6a35..d5a56b6 100644
--- a/gnu/gnunet/common.scm
+++ b/gnu/gnunet/common.scm
@@ -24,6 +24,8 @@
gnunet-system-error
gnunet-yes
gnunet-no
+ bool->int
+ int->bool
time-relative
time-absolute
@@ -96,6 +98,13 @@
"GNUNET_STRINGS_string_to_data" : (list '* size_t '* size_t) -> int)
+(define (bool->int x) (if x gnunet-yes gnunet-no))
+(define (int->bool x)
+ (cond ((= gnunet-yes x) #t)
+ ((= gnunet-no x) #f)
+ ((= gnunet-system-error x) #:system-error)
+ (else #:unknown)))
+
(define %xfilename (string->pointer "guile"))
(define (%free pointer)
diff --git a/gnu/gnunet/fs/uri.scm b/gnu/gnunet/fs/uri.scm
index 9503408..9e43841 100644
--- a/gnu/gnunet/fs/uri.scm
+++ b/gnu/gnunet/fs/uri.scm
@@ -36,7 +36,9 @@
unwrap-uri
uri-type
uri-file-size
- uri->string))
+ uri->string
+
+ keyword-list->string))
(define-record-type <uri>
(%wrap-uri pointer type)
diff --git a/gnu/gnunet/scheduler.scm b/gnu/gnunet/scheduler.scm
index 94c147a..e45aacd 100644
--- a/gnu/gnunet/scheduler.scm
+++ b/gnu/gnunet/scheduler.scm
@@ -26,6 +26,7 @@
call-with-scheduler
add-task!
set-next-task!
+ cancel-task!
schedule-shutdown!))
@@ -52,6 +53,8 @@
"GNUNET_SCHEDULER_add_delayed_with_priority" :
(list time-relative unsigned-int '* '*) -> '*)
+(define-gnunet cancel-task! "GNUNET_SCHEDULER_cancel" : '(*) -> '*)
+
(define-gnunet %speedup-start "GNUNET_SPEEDUP_start_" : '(*) -> int)
(define-gnunet %speedup-stop "GNUNET_SPEEDUP_stop_" : '() -> void)
diff --git a/tests/uri.scm b/tests/uri.scm
index ba3660b..4453a95 100644
--- a/tests/uri.scm
+++ b/tests/uri.scm
@@ -22,6 +22,10 @@
(test-begin "test-fs-uri")
+;; keyword-list->string
+(test-equal "" (keyword-list->string '()))
+(test-equal "foo bar baz" (keyword-list->string '("foo" "bar" "baz")))
+
;; parse-uri
(test-error 'invalid-arg (parse-uri ""))
(let ((uri (parse-uri "gnunet://fs/ksk/trek")))
- [gnunet] branch master updated (c40fcac -> 2304d66), Rémi Birot-Delrue, 2015/08/12
- [gnunet] 01/17: Corrects a small bug., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `pointer->string*`. * common.scm: add `bool->int` and `int->bool`, two functions to easily convert `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to booleans. * fs/uri.scm: export `keyword-list->string`. * tests/uri.scm: test `keyword-list->string`. * scheduler.scm: add `cancel-task!`.,
Rémi Birot-Delrue <=
- [gnunet] 02/17: API cleanup: separates search and URI, adds sks URIs. * examples/search.scm: echo changes in the API; * gnu/gnunet/common.scm: add ecdsa-public-key? and string->data-pointer; * gnu/gnunet/fs.scm: replace search-service-open with open-filesharing-service, replace start-ksk-search with start-search; * gnu/gnunet/fs/uri.scm: add make-sks-uri-pointer and make-sks-uri; * tests/uri.scm: add tests for make-sks-uri-pointer and make-sks-uri., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 03/17: Bind basic download functionalities * examples/download.scm: a loose `gnunet-download' clone. * system/foreign/unions.scm: add the possibility to specify #f as a union variant to get a padding of the size of the union. * gnu/gnunet/fs/progress-info.scm: just adapted to the modification to unions.scm. * gnu/gnunet/fs/uri.scm: add a few utility functions: `parse-uri' and `uri-file-size'. * gnu/gnunet/fs/fs.scm: add `start-download` and `stop-download`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 06/17: Bind GNUNET_FS_IDENTITY_* functions and add support for publishing in namespaces. * identity.scm: complete bindings of GNUNET_FS_IDENTITY * fs.scm: add support for egos/namespaces to `start-publish` * binding-utils: remove the useless import of `assert`, Rémi Birot-Delrue, 2015/08/12
- [gnunet] 05/17: Add draft support for indexing/publication. * fs.scm: - add a `<file-information>` type and associated functions (`wrap-file-information`, `unwrap-file-information`, and `make-file-information`); - add incomplete bindings to `GNUNET_FS_directory_scan_*` functions (`start-directory-scan`, `stop-directory-scan`, `directory-scanner-result`) - add `share-tree->file-information` - add `start-publish` and `stop-publish` * examples/publish.scm: a very simple and ugly `gnunet-publish` clone., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 12/17: Complete the container/metadata bindings., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 13/17: Remove `set-next-task!`, as the corresponding functions have been removed from GNUnet., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 07/17: Small bug fixes and add publishing in namespaces for examples/publish.scm * common.scm: add `gnunet-id-ffi` (FFI for libgnunetidentity). * identity.scm: replace `define-gnunet-fs` with `define-gnunet-id`. * fs.scm: corrects a bug in `start-publish` (gave `GNUNET_FS_publish_start` a pointer to the ego in place of a pointer to its private key). * examples/publish.scm: add handling of namespaces and replace simple global variables with parameters., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 08/17: Add `examples/identity.scm`, `examples/identity-bis.scm`, `examples/search-ns.scm`, and a few minor modifications. * examples/search-ns.scm: a basic tool to search namespaces. * examples/identity.scm: a basic tool to list egos. * examples/identity-bis.scm: idem, but using `start-identity-lookup`. * fs/uri.scm: `wrap-uri` throws an `invalid-arg` exception when given a null pointer. * tests/uri.scm: c.f. ↑ * configuration.scm: add `configuration-value-set?`. * identity.scm: add `ecdsa-public-key->string`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 09/17: Rewrite of examples/publish.scm, small bug fixes and typos. * examples/publish.scm: rewritten to correctly handle namespaces. * gnu/gnunet/binding-utils.scm: add `or%`. * gnu/gnunet/fs.scm: bug fix: `start-*` function throw an error instead of returning %null-pointer. * gnu/gnunet/identity.scm: typo., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 14/17: Code cleaning: various improvements and bug fixes. * identity.scm: `open-identity-service` now throws an exception on failure. * binding-utils.scm: just add `destructuring-bind`. * common.scm: `time-rel` now throws an exception instead of returning a meaningless negative result; add `setup-log`. * container/metadata.scm: `metadata-set!` now throws an exception on error. * tests/container-metadata.scm: add tests for `metadata-copy`, `metadata-clear`, `metadata-equal?` and `add-publication-date!`, Rémi Birot-Delrue, 2015/08/12