Skip to content

Commit 34232d3

Browse files
committed
Fixed alignment issues.
1 parent e31e2c9 commit 34232d3

File tree

3 files changed

+179
-151
lines changed

3 files changed

+179
-151
lines changed

src/arduino_homekit_server.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define HOMEKIT_SOCKET_KEEPALIVE_INTERVAL_SEC 30
4646
//const int maxpkt = 4; /* Drop connection after 4 probes without response */
4747
#define HOMEKIT_SOCKET_KEEPALIVE_IDLE_COUNT 4
48-
// if 180 + 30 * 4 = 300 sec without socket response, disconected it.
48+
// if 180 + 30 * 4 = 300 sec without socket response, disconnected it.
4949

5050
// WiFiClient can not write big buff once.
5151
// TCP_SND_BUF = (2 * TCP_MSS) = 1072. See lwipopts.h
@@ -118,10 +118,10 @@ void server_free(homekit_server_t *server) {
118118
}
119119

120120
void tlv_debug(const tlv_values_t *values) {
121-
DEBUG("Got following TLV values:");
121+
printf("Got following TLV values:\n");
122122
for (tlv_t *t = values->head; t; t = t->next) {
123123
char *escaped_payload = binary_to_string(t->value, t->size);
124-
DEBUG("Type %d value (%d bytes): %s", t->type, t->size, escaped_payload);
124+
printf("\tType %d value (%d bytes): %s\n", t->type, t->size, escaped_payload);
125125
free(escaped_payload);
126126
}
127127
}
@@ -562,7 +562,7 @@ int client_send_encrypted_(client_context_t *context,
562562
memset(nonce, 0, sizeof(nonce));
563563

564564
byte encrypted[1024 + 18];
565-
int payload_offset = 0;
565+
uint payload_offset = 0;
566566

567567
while (payload_offset < size) {
568568
size_t chunk_size = size - payload_offset;
@@ -1879,7 +1879,7 @@ void homekit_server_on_get_characteristics(client_context_t *context) {
18791879

18801880
query_param_t *qp = context->endpoint_params;
18811881
while (qp) {
1882-
CLIENT_DEBUG(context, "Query paramter %s = %s", qp->name, qp->value);
1882+
CLIENT_DEBUG(context, "Query parameter %s = %s", qp->name, qp->value);
18831883
qp = qp->next;
18841884
}
18851885

@@ -2629,6 +2629,7 @@ void homekit_server_on_pairings(client_context_t *context, const byte *data, siz
26292629
INFO("Last admin pairing was removed, enabling pair setup");
26302630
context->server->paired = false;
26312631
//homekit_setup_mdns(context->server);
2632+
homekit_storage_reset_pairing_data();
26322633
}
26332634
}
26342635
}
@@ -2760,7 +2761,7 @@ int homekit_server_on_url(http_parser *parser, const char *data, size_t length)
27602761
}
27612762

27622763
int homekit_server_on_body(http_parser *parser, const char *data, size_t length) {
2763-
DEBUG("http_parser lenght=%d", length);
2764+
DEBUG("http_parser length=%d", length);
27642765
client_context_t *context = (client_context_t*) parser->data;
27652766
context->body = (char*) realloc(context->body, context->body_length + length + 1);
27662767
memcpy(context->body + context->body_length, data, length);
@@ -2888,7 +2889,7 @@ void homekit_client_process(client_context_t *context) {
28882889
}
28892890
return;
28902891
}
2891-
CLIENT_DEBUG(context, "Got %d incomming data, encrypted is %s",
2892+
CLIENT_DEBUG(context, "Got %d incoming data, encrypted is %s",
28922893
data_len, context->encrypted ? "true" : "false");
28932894
byte *payload = (byte*) context->data;
28942895
size_t payload_size = (size_t) data_len;
@@ -2942,7 +2943,7 @@ void homekit_server_close_client(homekit_server_t *server, client_context_t *con
29422943

29432944
if (context->socket) {
29442945
context->socket->stop();
2945-
CLIENT_DEBUG(context, "The sockect is stopped");
2946+
CLIENT_DEBUG(context, "The socket is stopped");
29462947
delete context->socket;
29472948
context->socket = nullptr;
29482949
}
@@ -2979,7 +2980,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
29792980
WiFiClient *wifiClient = nullptr;
29802981

29812982
if (server->wifi_server->hasClient()) {
2982-
wifiClient = new WiFiClient(server->wifi_server->available());
2983+
wifiClient = new WiFiClient(server->wifi_server->accept());
29832984
if (server->nfds >= HOMEKIT_MAX_CLIENTS) {
29842985
INFO("No more room for client connections (max %d)", HOMEKIT_MAX_CLIENTS);
29852986
wifiClient->stop();
@@ -2990,7 +2991,8 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
29902991
return NULL;
29912992
}
29922993

2993-
INFO("Got new client: local %s:%d, remote %s:%d",
2994+
INFO("Got new client %d: local %s:%d, remote %s:%d",
2995+
wifiClient,
29942996
wifiClient->localIP().toString().c_str(), wifiClient->localPort(),
29952997
wifiClient->remoteIP().toString().c_str(), wifiClient->remotePort());
29962998

@@ -3018,7 +3020,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
30183020
void homekit_server_process_notifications(homekit_server_t *server) {
30193021
client_context_t *context = server->clients;
30203022
// 把characteristic_event_t拼接成client_event_t链表
3021-
// 按照Apple的规定,Nofiy消息需合并发送
3023+
// 按照Apple的规定,Notify消息需合并发送
30223024
while (context) {
30233025
if (context->step != HOMEKIT_CLIENT_STEP_PAIR_VERIFY_2OF2) {
30243026
// Do not send event when the client is not verify over.
@@ -3114,7 +3116,7 @@ void homekit_server_process(homekit_server_t *server) {
31143116
}
31153117

31163118
//=====================================================
3117-
// Arduino ESP8266 MDNS: call this funciton only once when WiFi STA is connected!
3119+
// Arduino ESP8266 MDNS: call this function only once when WiFi STA is connected!
31183120
//=====================================================
31193121
bool homekit_mdns_started = false;
31203122

@@ -3145,7 +3147,7 @@ void homekit_mdns_init(homekit_server_t *server) {
31453147
ERROR("Invalid accessory declaration: " "no Name characteristic in AccessoryInfo service");
31463148
return;
31473149
}
3148-
3150+
31493151
homekit_characteristic_t *model = homekit_service_characteristic_by_type(accessory_info,
31503152
HOMEKIT_CHARACTERISTIC_MODEL);
31513153

@@ -3215,7 +3217,6 @@ void homekit_mdns_init(homekit_server_t *server) {
32153217

32163218
unsigned char encodedHash[9];
32173219
memset(encodedHash, 0, sizeof(encodedHash));
3218-
word32 len = sizeof(encodedHash);
32193220
base64_encode_((const unsigned char*) shaHash, 4, encodedHash);
32203221
MDNS.addServiceTxt(mdns_service, "sh", (char*) encodedHash);
32213222
}
@@ -3317,7 +3318,7 @@ void homekit_server_init(homekit_server_config_t *config) {
33173318
//homekit_server_task(server);
33183319
INFO("Starting server");
33193320

3320-
if (homekit_storage_init() != 0 ||
3321+
if (homekit_storage_init(false) != 0 ||
33213322
homekit_storage_load_accessory_id(server->accessory_id) != 0 ||
33223323
homekit_storage_load_accessory_key(&server->accessory_key) != 0) {
33233324

@@ -3399,11 +3400,11 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
33993400

34003401
if (!config->password)
34013402
return -1;
3402-
// TODO: validate password in case it is run beffore server is started
3403+
// TODO: validate password in case it is run before server is started
34033404

34043405
if (!config->setupId)
34053406
return -1;
3406-
// TODO: validate setupID in case it is run beffore server is started
3407+
// TODO: validate setupID in case it is run before server is started
34073408

34083409
homekit_accessory_t *accessory = homekit_accessory_by_id(config->accessories, 1);
34093410
if (!accessory)
@@ -3445,8 +3446,8 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
34453446
return 0;
34463447
}
34473448

3448-
// Pre-initialize the pairing_context used in Pair-Setep 1/3
3449-
// For avoiding timeout caused sockect disconnection from iOS device.
3449+
// Pre-initialize the pairing_context used in Pair-Setup 1/3
3450+
// For avoiding timeout caused socket disconnection from iOS device.
34503451
bool arduino_homekit_preinit(homekit_server_t *server) {
34513452
if (saved_preinit_pairing_context != nullptr) {
34523453
return true;

0 commit comments

Comments
 (0)