tMove Zenroom code to separate file in damlib. - tordam - A library for peer discovery inside the Tor network HTML git clone https://git.parazyd.org/tordam DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit cb46327f82f7046159fc637a76f9bb955f320382 DIR parent fed0429355edea309d795101fa670b12d81a3ece HTML Author: parazyd <parazyd@dyne.org> Date: Mon, 29 Oct 2018 17:19:58 +0100 Move Zenroom code to separate file in damlib. Diffstat: M pkg/damlib/helpers.go | 11 ----------- A pkg/damlib/zenroom.go | 48 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) --- DIR diff --git a/pkg/damlib/helpers.go b/pkg/damlib/helpers.go t@@ -20,12 +20,6 @@ package damlib * along with this source code. If not, see <http://www.gnu.org/licenses/>. */ -// #cgo LDFLAGS: -lzenroomgo -// -// #include <stdlib.h> -// #include "zenroom.h" -import "C" - import ( "bytes" "compress/gzip" t@@ -85,8 +79,3 @@ func ParseDirs(sl []string, data []byte) []string { } return sl } - -func ZenroomExec(script, conf, keys, data string, verbosity int) int { - return int(C.zenroom_exec(C.CString(script), C.CString(conf), - C.CString(keys), C.CString(data), C.int(verbosity))) -} DIR diff --git a/pkg/damlib/zenroom.go b/pkg/damlib/zenroom.go t@@ -0,0 +1,48 @@ +package damlib + +/* + * Copyright (c) 2018 Dyne.org Foundation + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org> + * + * This file is part of tor-dam + * + * This source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code. If not, see <http://www.gnu.org/licenses/>. + */ + +// #cgo LDFLAGS: -lzenroomgo +// +// #include <stddef.h> +// #include "zenroom.h" +import "C" +import "unsafe" + +// ZenroomExec is Zenroom's simple API call. +func ZenroomExec(script, conf, keys, data string, verbosity int) int { + return int(C.zenroom_exec(C.CString(script), C.CString(conf), + C.CString(keys), C.CString(data), C.int(verbosity))) +} + +// ZenroomExecToBuf is Zenroom's simple API call with buffers. It will return +// stdout and stderr. +func ZenroomExecToBuf(script, conf, keys, data string, verbosity int) (int, []byte, []byte) { + var bufsize = 1024 * 8 + + outbuf := make([]byte, bufsize) + errbuf := make([]byte, bufsize) + + return int(C.zenroom_exec_tobuf(C.CString(script), C.CString(conf), + C.CString(keys), C.CString(data), C.int(verbosity), + (*C.char)(unsafe.Pointer(&outbuf[0])), C.size_t(bufsize), + (*C.char)(unsafe.Pointer(&errbuf[0])), C.size_t(bufsize))), outbuf, errbuf +}