Tetsing void pointer from C to Go.

This commit is contained in:
Ignacio Gómez 2017-11-22 22:08:37 -03:00
parent a79f0da256
commit f40e332947
5 changed files with 76 additions and 7 deletions

View File

@ -2,11 +2,10 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <curl/curl.h>
#include <mosquitto.h>
#include <mosquitto_plugin.h>
#include "auth-plugin.h"
#include "go-auth.h"
int mosquitto_auth_plugin_version(void) {
return MOSQ_AUTH_PLUGIN_VERSION;
@ -16,9 +15,10 @@ int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth
/*
Pass auth_opts hash to Go in order to initialize them there.
*/
GoSlice auth_opts = {mosquitto_auth_opt, auth_opt_count, auth_opt_count};
//GoSlice auth_opts = {mosquitto_auth_opt, auth_opt_count, auth_opt_count};
GoInt32 opts_count = auth_opt_count;
AuthPluginInit(auth_opts, opts_count);
GoMap opts = auth_opts;
AuthPluginInit(opts, opts_count);
return MOSQ_ERR_SUCCESS;
}

66
go-auth-plug.h Normal file
View File

@ -0,0 +1,66 @@
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/iegomez/mosquitto-go-auth-plugin */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern void AuthPluginInit(GoMap p0, GoInt p1);
extern GoUint8 AuthUnpwdCheck(GoString p0, GoString p1);
extern GoUint8 AuthAclCheck(GoString p0, GoString p1, GoString p2, GoInt p3);
extern GoUint8 AuthPskKeyGet();
#ifdef __cplusplus
}
#endif

View File

@ -2,13 +2,16 @@ package main
import "C"
import "fmt"
import "unsafe"
var jsonJwtOpts []string
var pgOpts []string
var redisOpts []string
//export AuthPluginInit
func AuthPluginInit(authOpts []string, authOptsNum int) {
func AuthPluginInit(authOpts map[string]string, authOptsNum int) {
fmt.Printf("authOpts: %v\n", unsafe.Pointer(&authOpts))
}
//export AuthUnpwdCheck

View File

@ -53,7 +53,7 @@ extern "C" {
#endif
extern void AuthPluginInit(GoSlice p0, GoInt p1);
extern void AuthPluginInit(GoMap p0, GoInt p1);
extern GoUint8 AuthUnpwdCheck(GoString p0, GoString p1);

BIN
go-auth.o

Binary file not shown.