简体   繁体   中英

Cannot access elements of struct mosquitto at Mosquitto MQTT Broker plugin

I'm implementing a plugin for the mosquitto MQTT broker (version 1.5) and I'm struggling at accessing some elements of the pointer to the struct of mosquitto client inside of my plugin implementation:

#include <mosquitto_plugin.h>
...
int mosquitto_auth_acl_check(void *userdata, int access, const struct mosquitto *client, const struct mosquitto_acl_msg *msg)
{
     const char *clientid = client->id;
     const char *username = client->username;
     ...
}

At compile time I retrieve the error:

error: dereferencing pointer to incomplete type const char *clientid = client->id;

Can anybody give me some advice how to access the client data?

Edit: struct mosquitto is defined inside of the mosquitto source code (mosquitto_internal.h):

struct mosquitto {
      ...
      char *id;
      char *username;
      ...
 }

But mosquitto_internal.h is just for internal usage at mosquitto and cannot be accessed by my plugin (At least I think so...)

Inside of mosquitto_plugin.h (which is provided by the mosquitto and included by my plugin) there is just a "reference" to the mosquitto struct:

struct mosquitto;

Thus, as long as I'm not accessing any data of the mosquitto struct it compiles successfully, but if I try to access some data like the id it crashes.

请使用mosquitto_broker.h提供的访问器功能,例如

const char *mosquitto_client_id(const struct mosquitto *client);

let download source code, include needed header file in your plugin implement and using this Makefile

NAME = mosquitto_auth_plugin_http

MOSQUITTO = ./mosquitto-1.5.2

INC = -I. -I$(MOSQUITTO)/ -I$(MOSQUITTO)/lib -I$(MOSQUITTO)/src

CFLAGS = -Wall -Werror -fPIC

DEBUG = -DMQAP_DEBUG

LIBS = -lcurl

all: $(NAME).so

$(NAME).so: $(NAME).o $(CC) $(CFLAGS) $(INC) -shared $^ -o $@ $(LIBS)

%.o : %.c $(CC) -c $(CFLAGS) $(DEBUG) $(INC) $< -o $@

clean: rm -f *.o *.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM