mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-20 14:57:34 +08:00
Back port db_dump from develop.
Closes #1519. Thanks to Christoph Krey.
This commit is contained in:
+61
-4
@@ -1,16 +1,73 @@
|
||||
include ../../config.mk
|
||||
|
||||
CFLAGS_FINAL=${CFLAGS} -I.. -I../../lib -I../.. -I../deps
|
||||
CFLAGS_FINAL=${CFLAGS} -I.. -I../../ -I../../lib -I../.. -I../deps -DWITH_BROKER -DWITH_PERSISTENCE
|
||||
|
||||
OBJS = \
|
||||
db_dump.o \
|
||||
print.o \
|
||||
\
|
||||
packet_datatypes.o \
|
||||
packet_mosq.o \
|
||||
persist_read.o \
|
||||
persist_read_v234.o \
|
||||
persist_read_v5.o \
|
||||
property_mosq.o \
|
||||
send_disconnect.o \
|
||||
stubs.o \
|
||||
time_mosq.o \
|
||||
utf8_mosq.o
|
||||
|
||||
.PHONY: all clean reallyclean
|
||||
|
||||
all : mosquitto_db_dump
|
||||
|
||||
mosquitto_db_dump : db_dump.o
|
||||
mosquitto_db_dump : ${OBJS}
|
||||
${CROSS_COMPILE}${CC} $^ -o $@ ${LDFLAGS} ${LIBS}
|
||||
|
||||
db_dump.o : db_dump.c ../persist.h
|
||||
db_dump.o : db_dump.c db_dump.h ../persist.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
clean :
|
||||
print.o : print.c db_dump.h ../persist.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
net_mosq.o : ../../lib/net_mosq.c ../../lib/net_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
packet_datatypes.o : ../../lib/packet_datatypes.c ../../lib/packet_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
packet_mosq.o : ../../lib/packet_mosq.c ../../lib/packet_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
persist_read.o : ../persist_read.c ../persist.h ../mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
persist_read_v234.o : ../persist_read_v234.c ../persist.h ../mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
persist_read_v5.o : ../persist_read_v5.c ../persist.h ../mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
property_mosq.o : ../../lib/property_mosq.c ../../lib/property_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
read_handle.o : ../../src/read_handle.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
stubs.o : stubs.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
send_disconnect.o : ../../lib/send_disconnect.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
time_mosq.o : ../../lib/time_mosq.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
topic_tok.o : ../../src/topic_tok.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
utf8_mosq.o : ../../lib/utf8_mosq.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
clean :
|
||||
-rm -f *.o mosquitto_db_dump
|
||||
|
||||
+226
-348
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
#ifndef DB_DUMP_H
|
||||
#define DB_DUMP_H
|
||||
/*
|
||||
Copyright (c) 2010-2019 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include <persist.h>
|
||||
|
||||
void print__client(struct P_client *chunk, int length);
|
||||
void print__client_msg(struct P_client_msg *chunk, int length);
|
||||
void print__msg_store(struct P_msg_store *chunk, int length);
|
||||
void print__sub(struct P_sub *chunk, int length);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
Copyright (c) 2010-2019 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mosquitto_broker_internal.h>
|
||||
#include <memory_mosq.h>
|
||||
#include <mqtt_protocol.h>
|
||||
#include <persist.h>
|
||||
#include <property_mosq.h>
|
||||
|
||||
|
||||
static void print__properties(mosquitto_property *properties)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(properties == NULL) return;
|
||||
|
||||
printf("\tProperties:\n");
|
||||
|
||||
while(properties){
|
||||
switch(properties->identifier){
|
||||
case MQTT_PROP_PAYLOAD_FORMAT_INDICATOR:
|
||||
printf("\t\tPayload format indicator: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_REQUEST_PROBLEM_INFORMATION:
|
||||
printf("\t\tRequest problem information: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_REQUEST_RESPONSE_INFORMATION:
|
||||
printf("\t\tRequest response information: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_MAXIMUM_QOS:
|
||||
printf("\t\tMaximum QoS: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_RETAIN_AVAILABLE:
|
||||
printf("\t\tRetain available: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_WILDCARD_SUB_AVAILABLE:
|
||||
printf("\t\tWildcard sub available: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE:
|
||||
printf("\t\tSubscription ID available: %d\n", properties->value.i8);
|
||||
break;
|
||||
case MQTT_PROP_SHARED_SUB_AVAILABLE:
|
||||
printf("\t\tShared subscription available: %d\n", properties->value.i8);
|
||||
break;
|
||||
|
||||
case MQTT_PROP_SERVER_KEEP_ALIVE:
|
||||
printf("\t\tServer keep alive: %d\n", properties->value.i16);
|
||||
break;
|
||||
case MQTT_PROP_RECEIVE_MAXIMUM:
|
||||
printf("\t\tReceive maximum: %d\n", properties->value.i16);
|
||||
break;
|
||||
case MQTT_PROP_TOPIC_ALIAS_MAXIMUM:
|
||||
printf("\t\tTopic alias maximum: %d\n", properties->value.i16);
|
||||
break;
|
||||
case MQTT_PROP_TOPIC_ALIAS:
|
||||
printf("\t\tTopic alias: %d\n", properties->value.i16);
|
||||
break;
|
||||
|
||||
case MQTT_PROP_MESSAGE_EXPIRY_INTERVAL:
|
||||
printf("\t\tMessage expiry interval: %d\n", properties->value.i32);
|
||||
break;
|
||||
case MQTT_PROP_SESSION_EXPIRY_INTERVAL:
|
||||
printf("\t\tSession expiry interval: %d\n", properties->value.i32);
|
||||
break;
|
||||
case MQTT_PROP_WILL_DELAY_INTERVAL:
|
||||
printf("\t\tWill delay interval: %d\n", properties->value.i32);
|
||||
break;
|
||||
case MQTT_PROP_MAXIMUM_PACKET_SIZE:
|
||||
printf("\t\tMaximum packet size: %d\n", properties->value.i32);
|
||||
break;
|
||||
|
||||
case MQTT_PROP_SUBSCRIPTION_IDENTIFIER:
|
||||
printf("\t\tSubscription identifier: %d\n", properties->value.varint);
|
||||
break;
|
||||
|
||||
case MQTT_PROP_CONTENT_TYPE:
|
||||
printf("\t\tContent type: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_RESPONSE_TOPIC:
|
||||
printf("\t\tResponse topic: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER:
|
||||
printf("\t\tAssigned client identifier: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_AUTHENTICATION_METHOD:
|
||||
printf("\t\tAuthentication method: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_RESPONSE_INFORMATION:
|
||||
printf("\t\tResponse information: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_SERVER_REFERENCE:
|
||||
printf("\t\tServer reference: %s\n", properties->value.s.v);
|
||||
break;
|
||||
case MQTT_PROP_REASON_STRING:
|
||||
printf("\t\tReason string: %s\n", properties->value.s.v);
|
||||
break;
|
||||
|
||||
case MQTT_PROP_AUTHENTICATION_DATA:
|
||||
printf("\t\tAuthentication data: ");
|
||||
for(i=0; i<properties->value.bin.len; i++){
|
||||
printf("%02X", properties->value.bin.v[i]);
|
||||
}
|
||||
printf("\n");
|
||||
break;
|
||||
case MQTT_PROP_CORRELATION_DATA:
|
||||
printf("\t\tCorrelation data: ");
|
||||
for(i=0; i<properties->value.bin.len; i++){
|
||||
printf("%02X", properties->value.bin.v[i]);
|
||||
}
|
||||
printf("\n");
|
||||
break;
|
||||
|
||||
case MQTT_PROP_USER_PROPERTY:
|
||||
printf("\t\tUser property: %s , %s\n", properties->name.v, properties->value.s.v);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("\t\tInvalid property type: %d\n", properties->identifier);
|
||||
break;
|
||||
}
|
||||
|
||||
properties = properties->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print__client(struct P_client *chunk, int length)
|
||||
{
|
||||
printf("DB_CHUNK_CLIENT:\n");
|
||||
printf("\tLength: %d\n", length);
|
||||
printf("\tClient ID: %s\n", chunk->client_id);
|
||||
printf("\tLast MID: %d\n", chunk->F.last_mid);
|
||||
printf("\tSession expiry time: %" PRIu64 "\n", chunk->F.session_expiry_time);
|
||||
printf("\tSession expiry interval: %u\n", chunk->F.session_expiry_interval);
|
||||
}
|
||||
|
||||
|
||||
void print__client_msg(struct P_client_msg *chunk, int length)
|
||||
{
|
||||
printf("DB_CHUNK_CLIENT_MSG:\n");
|
||||
printf("\tLength: %d\n", length);
|
||||
printf("\tClient ID: %s\n", chunk->client_id);
|
||||
printf("\tStore ID: %" PRIu64 "\n", chunk->F.store_id);
|
||||
printf("\tMID: %d\n", chunk->F.mid);
|
||||
printf("\tQoS: %d\n", chunk->F.qos);
|
||||
printf("\tRetain: %d\n", (chunk->F.retain_dup&0xF0)>>4);
|
||||
printf("\tDirection: %d\n", chunk->F.direction);
|
||||
printf("\tState: %d\n", chunk->F.state);
|
||||
printf("\tDup: %d\n", chunk->F.retain_dup&0x0F);
|
||||
print__properties(chunk->properties);
|
||||
}
|
||||
|
||||
|
||||
void print__msg_store(struct P_msg_store *chunk, int length)
|
||||
{
|
||||
printf("DB_CHUNK_MSG_STORE:\n");
|
||||
printf("\tLength: %d\n", length);
|
||||
printf("\tStore ID: %" PRIu64 "\n", chunk->F.store_id);
|
||||
//printf("\tSource ID: %s\n", chunk->source_id);
|
||||
//printf("\tSource Username: %s\n", chunk->source_username);
|
||||
printf("\tSource Port: %d\n", chunk->F.source_port);
|
||||
printf("\tSource MID: %d\n", chunk->F.source_mid);
|
||||
printf("\tTopic: %s\n", chunk->topic);
|
||||
printf("\tQoS: %d\n", chunk->F.qos);
|
||||
printf("\tRetain: %d\n", chunk->F.retain);
|
||||
printf("\tPayload Length: %d\n", chunk->F.payloadlen);
|
||||
printf("\tExpiry Time: %" PRIu64 "\n", chunk->F.expiry_time);
|
||||
|
||||
uint8_t *payload;
|
||||
|
||||
payload = UHPA_ACCESS(chunk->payload, chunk->F.payloadlen);
|
||||
if(chunk->F.payloadlen < 256){
|
||||
/* Print payloads with UTF-8 data below an arbitrary limit of 256 bytes */
|
||||
if(mosquitto_validate_utf8((char *)payload, chunk->F.payloadlen) == MOSQ_ERR_SUCCESS){
|
||||
printf("\tPayload: %s\n", payload);
|
||||
}
|
||||
}
|
||||
print__properties(chunk->properties);
|
||||
}
|
||||
|
||||
|
||||
void print__sub(struct P_sub *chunk, int length)
|
||||
{
|
||||
printf("DB_CHUNK_SUB:\n");
|
||||
printf("\tLength: %d\n", length);
|
||||
printf("\tClient ID: %s\n", chunk->client_id);
|
||||
printf("\tTopic: %s\n", chunk->topic);
|
||||
printf("\tQoS: %d\n", chunk->F.qos);
|
||||
printf("\tSubscription ID: %d\n", chunk->F.identifier);
|
||||
printf("\tOptions: 0x%02X\n", chunk->F.options);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "mosquitto_internal.h"
|
||||
|
||||
struct mosquitto *context__init(struct mosquitto_db *db, mosq_sock_t sock)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int db__message_store(struct mosquitto_db *db, const struct mosquitto *source, uint16_t source_mid, char *topic, int qos, uint32_t payloadlen, mosquitto__payload_uhpa *payload, int retain, struct mosquitto_msg_store **stored, uint32_t message_expiry_interval, mosquitto_property *properties, dbid_t store_id, enum mosquitto_msg_origin origin)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void db__msg_store_ref_inc(struct mosquitto_msg_store *store)
|
||||
{
|
||||
}
|
||||
|
||||
int handle__packet(struct mosquitto_db *db, struct mosquitto *context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int log__printf(struct mosquitto *mosq, int level, const char *fmt, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void *mosquitto__calloc(size_t nmemb, size_t len)
|
||||
{
|
||||
return calloc(nmemb, len);
|
||||
}
|
||||
|
||||
void mosquitto__free(void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq)
|
||||
{
|
||||
return mosq_cs_new;
|
||||
}
|
||||
|
||||
void *mosquitto__malloc(size_t len)
|
||||
{
|
||||
return malloc(len);
|
||||
}
|
||||
|
||||
char *mosquitto__strdup(const char *s)
|
||||
{
|
||||
return strdup(s);
|
||||
}
|
||||
|
||||
ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t net__write(struct mosquitto *mosq, void *buf, size_t count)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int retain__store(struct mosquitto_db *db, const char *topic, struct mosquitto_msg_store *stored, char **split_topics)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sub__add(struct mosquitto_db *db, struct mosquitto *context, const char *sub, int qos, uint32_t identifier, int options, struct mosquitto__subhier **root)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sub__messages_queue(struct mosquitto_db *db, const char *source_id, const char *topic, int qos, int retain, struct mosquitto_msg_store **stored)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -131,6 +131,8 @@ struct P_retain{
|
||||
int persist__read_string_len(FILE *db_fptr, char **str, uint16_t len);
|
||||
int persist__read_string(FILE *db_fptr, char **str);
|
||||
|
||||
int persist__chunk_header_read(FILE *db_fptr, int *chunk, int *length);
|
||||
|
||||
int persist__chunk_header_read_v234(FILE *db_fptr, int *chunk, int *length);
|
||||
int persist__chunk_cfg_read_v234(FILE *db_fptr, struct PF_cfg *chunk);
|
||||
int persist__chunk_client_read_v234(FILE *db_fptr, struct P_client *chunk, int db_version);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ Contributors:
|
||||
#include "misc_mosq.h"
|
||||
#include "util_mosq.h"
|
||||
|
||||
static uint32_t db_version;
|
||||
uint32_t db_version;
|
||||
|
||||
const unsigned char magic[15] = {0x00, 0xB5, 0x00, 'm','o','s','q','u','i','t','t','o',' ','d','b'};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user