More client accessors.

pull/215/head
Roger A. Light 9 years ago
parent 025e56fd4c
commit b40cedaf1d

@ -1,2 +1,9 @@
_mosquitto_log_printf
_mosquitto_client_address
_mosquitto_client_clean_session
_mosquitto_client_id
_mosquitto_client_keepalive
_mosquitto_client_certificate
_mosquitto_client_protocol
_mosquitto_client_sub_count
_mosquitto_client_username

@ -1,4 +1,11 @@
{
mosquitto_log_printf;
mosquitto_client_address;
mosquitto_client_clean_session;
mosquitto_client_id;
mosquitto_client_keepalive;
mosquitto_client_certificate;
mosquitto_client_protocol;
mosquitto_client_sub_count;
mosquitto_client_username;
};

@ -24,6 +24,12 @@ struct mosquitto_opt {
char *value;
};
enum mosquitto_protocol {
mp_mqtt,
mp_mqttsn,
mp_websockets
};
/* =========================================================================
*
* Utility Functions
@ -65,6 +71,72 @@ void mosquitto_log_printf(int level, const char *fmt, ...);
*
* ========================================================================= */
/*
* Function: mosquitto_client_address
*
* Retrieve the username associated with a client, or NULL if the client
* provided no username.
*/
const char *mosquitto_client_address(const struct mosquitto *client);
/*
* Function: mosquitto_client_clean_session
*
* Retrieve the clean session flag value for a client.
*/
bool mosquitto_client_clean_session(const struct mosquitto *client);
/*
* Function: mosquitto_client_id
*
* Retrieve the client id associated with a client.
*/
const char *mosquitto_client_id(const struct mosquitto *client);
/*
* Function: mosquitto_client_keepalive
*
* Retrieve the keepalive value for a client.
*/
int mosquitto_client_keepalive(const struct mosquitto *client);
/*
* Function: mosquitto_client_certificate
*
* If TLS support is enabled, return the certificate provided by a client as an
* X509 pointer from openssl. If the client did not provide a certificate, then
* NULL will be returned. This function will only ever return a non-NULL value
* if the `require_certificate` option is set to true.
*
* If TLS is not supported, this function will always return NULL.
*/
void *mosquitto_client_certificate(const struct mosquitto *client);
/*
* Function: mosquitto_client_protocol
*
* Retrieve the protocol with which the client has connected. Can be one of:
*
* mp_mqtt (MQTT over TCP)
* mp_mqttsn (MQTT-SN)
* mp_websockets (MQTT over Websockets)
*/
int mosquitto_client_protocol(const struct mosquitto *client);
/*
* Function: mosquitto_client_sub_count
*
* Retrieve the number of subscriptions that have been made by a client.
*/
int mosquitto_client_sub_count(const struct mosquitto *client);
/*
* Function: mosquitto_client_username
*

@ -40,6 +40,7 @@ Contributors:
#endif
#include "mosquitto_internal.h"
#include "mosquitto_broker.h"
#include "mosquitto_plugin.h"
#include "mosquitto.h"
#include "tls_mosq.h"
@ -133,12 +134,6 @@ typedef union {
* End UHPA data types
* ======================================== */
enum mosquitto_protocol {
mp_mqtt,
mp_mqttsn,
mp_websockets
};
typedef uint64_t dbid_t;
struct mosquitto__listener {

@ -14,9 +14,64 @@ Contributors:
Roger Light - initial implementation and documentation.
*/
#ifdef WITH_TLS
# include <openssl/ssl.h>
#endif
#include "mosquitto_internal.h"
#include "mosquitto_broker.h"
#include "mosquitto_broker_internal.h"
const char *mosquitto_client_address(const struct mosquitto *client)
{
return client->address;
}
bool mosquitto_client_clean_session(const struct mosquitto *client)
{
return client->clean_session;
}
const char *mosquitto_client_id(const struct mosquitto *client)
{
return client->id;
}
int mosquitto_client_keepalive(const struct mosquitto *client)
{
return client->keepalive;
}
void *mosquitto_client_certificate(const struct mosquitto *client)
{
#ifdef WITH_TLS
if(client->ssl){
return SSL_get_peer_certificate(client->ssl);
}else{
return NULL;
}
#else
return NULL;
#endif
}
int mosquitto_client_protocol(const struct mosquitto *client)
{
return client->protocol;
}
int mosquitto_client_sub_count(const struct mosquitto *client)
{
return client->sub_count;
}
const char *mosquitto_client_username(const struct mosquitto *context)
{
#ifdef WITH_BRIDGE

Loading…
Cancel
Save