我正在为 mosquitto MQTT 代理(版本 1.5)实现一个插件,我正在努力访问我的插件实现中指向 mosquitto 客户端结构的指针的一些元素:
#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;
...
}
在编译时,我检索到错误:
错误:取消引用指向不完整类型 const char *clientid = client->id 的指针;
任何人都可以给我一些关于如何访问客户数据的建议吗?
编辑: struct mosquitto 是在 mosquitto 源代码 (mosquitto_internal.h) 中定义的:
struct mosquitto {
...
char *id;
char *username;
...
}
但是 mosquitto_internal.h 仅供 mosquitto 内部使用,我的插件无法访问(至少我是这么认为的...)
在 mosquitto_plugin.h(由 mosquitto 提供并包含在我的插件中)内部,只有一个对 mosquitto 结构的“引用”:
struct mosquitto;
因此,只要我不访问 mosquitto 结构的任何数据,它就会成功编译,但是如果我尝试访问某些数据,例如 id,它就会崩溃。
请使用中提供的访问器函数mosquitto_broker.h
,例如
const char *mosquitto_client_id(const struct mosquitto *client);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句