David
David

Reputation: 23

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.

Upvotes: 0

Views: 1439

Answers (2)

ralight
ralight

Reputation: 11608

Please use the accessor functions provided in mosquitto_broker.h, e.g.

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

Upvotes: 2

Phuc Le Minh
Phuc Le Minh

Reputation: 1

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

Upvotes: 0

Related Questions