mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-23 20:11:49 +00:00
Add mg_ prefix to mongoose sources
CL: none PUBLISHED_FROM=d6ebe5fa88c61ae3b8569897d9b09d54610bec73
This commit is contained in:
1 parent
f29457e967
commit
aba60dadec
214 files changed
+179
-3304
No files matched your search
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
* This software is dual-licensed: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. For the terms of this
|
||||
* license, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* You are free to use this software under the terms of the GNU General
|
||||
* Public License, 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.
|
||||
*
|
||||
* Alternatively, you can license this software under a commercial
|
||||
* license, as set out in <https://www.cesanta.com/license>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* === MQTT Server API reference
|
||||
*/
|
||||
|
||||
#ifndef CS_MONGOOSE_SRC_MQTT_BROKER_H_
|
||||
#define CS_MONGOOSE_SRC_MQTT_BROKER_H_
|
||||
|
||||
#if MG_ENABLE_MQTT_BROKER
|
||||
|
||||
#include "common/queue.h"
|
||||
#include "mongoose/src/mg_mqtt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef MG_MQTT_MAX_SESSION_SUBSCRIPTIONS
|
||||
#define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512
|
||||
#endif
|
||||
|
||||
struct mg_mqtt_broker;
|
||||
|
||||
/* MQTT session (Broker side). */
|
||||
struct mg_mqtt_session {
|
||||
struct mg_mqtt_broker *brk; /* Broker */
|
||||
LIST_ENTRY(mg_mqtt_session) link; /* mg_mqtt_broker::sessions linkage */
|
||||
struct mg_connection *nc; /* Connection with the client */
|
||||
size_t num_subscriptions; /* Size of `subscriptions` array */
|
||||
void *user_data; /* User data */
|
||||
struct mg_mqtt_topic_expression *subscriptions;
|
||||
};
|
||||
|
||||
/* MQTT broker. */
|
||||
struct mg_mqtt_broker {
|
||||
LIST_HEAD(_mg_sesshead, mg_mqtt_session) sessions; /* Session list */
|
||||
void *user_data; /* User data */
|
||||
};
|
||||
|
||||
/* Initialises a MQTT broker. */
|
||||
void mg_mqtt_broker_init(struct mg_mqtt_broker *brk, void *user_data);
|
||||
|
||||
/*
|
||||
* Processes a MQTT broker message.
|
||||
*
|
||||
* The listening connection expects a pointer to an initialised
|
||||
* `mg_mqtt_broker` structure in the `user_data` field.
|
||||
*
|
||||
* Basic usage:
|
||||
*
|
||||
* ```c
|
||||
* mg_mqtt_broker_init(&brk, NULL);
|
||||
*
|
||||
* if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
|
||||
* // fail;
|
||||
* }
|
||||
* nc->user_data = &brk;
|
||||
* ```
|
||||
*
|
||||
* New incoming connections will receive a `mg_mqtt_session` structure
|
||||
* in the connection `user_data`. The original `user_data` will be stored
|
||||
* in the `user_data` field of the session structure. This allows the user
|
||||
* handler to store user data before `mg_mqtt_broker` creates the session.
|
||||
*
|
||||
* Since only the MG_EV_ACCEPT message is processed by the listening socket,
|
||||
* for most events the `user_data` will thus point to a `mg_mqtt_session`.
|
||||
*/
|
||||
void mg_mqtt_broker(struct mg_connection *brk, int ev, void *data);
|
||||
|
||||
/*
|
||||
* Iterates over all MQTT session connections. Example:
|
||||
*
|
||||
* ```c
|
||||
* struct mg_mqtt_session *s;
|
||||
* for (s = mg_mqtt_next(brk, NULL); s != NULL; s = mg_mqtt_next(brk, s)) {
|
||||
* // Do something
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
struct mg_mqtt_session *mg_mqtt_next(struct mg_mqtt_broker *brk,
|
||||
struct mg_mqtt_session *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* MG_ENABLE_MQTT_BROKER */
|
||||
#endif /* CS_MONGOOSE_SRC_MQTT_BROKER_H_ */
|
||||
Reference in new issue
Block a user