Skip to content

Commit d1a1dcd

Browse files
author
spikelin
committed
format code-style
1 parent 88690a1 commit d1a1dcd

File tree

13 files changed

+74
-74
lines changed

13 files changed

+74
-74
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ AlignConsecutiveMacros: true
55
AlignConsecutiveAssignments: true
66
AllowShortFunctionsOnASingleLine: Inline
77
AllowShortIfStatementsOnASingleLine: false
8+
SortIncludes: false
89
IndentWidth: 4
910
ColumnLimit: 120

include/exports/qcloud_iot_export_mqtt.h

100755100644
+7-7
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,22 @@ typedef struct {
175175
uint8_t auto_connect_enable; // flag of auto reconnection, 1 is enable and recommended
176176
MQTTEventHandler event_handle; // event callback
177177

178-
int err_code;
178+
int err_code;
179179

180180
} MQTTInitParams;
181181

182182
/**
183183
* Default MQTT init parameters
184184
*/
185185
#ifdef AUTH_MODE_CERT
186-
#define DEFAULT_MQTTINIT_PARAMS \
187-
{ \
188-
NULL, NULL, {0}, {0}, 5000, 240 * 1000, 1, 1, { 0 }, 0 \
186+
#define DEFAULT_MQTTINIT_PARAMS \
187+
{ \
188+
NULL, NULL, {0}, {0}, 5000, 240 * 1000, 1, 1, {0}, 0 \
189189
}
190190
#else
191-
#define DEFAULT_MQTTINIT_PARAMS \
192-
{ \
193-
NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, { 0 }, 0 \
191+
#define DEFAULT_MQTTINIT_PARAMS \
192+
{ \
193+
NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, {0}, 0 \
194194
}
195195
#endif
196196

samples/broadcast/broadcast_sample.c

100755100644
+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static void _broadcast_message_handler(void *pClient, const char *msg, uint32_t
135135
}
136136

137137
static int sg_loop_count = 5;
138-
static int parse_arguments(int argc, char **argv)
138+
static int parse_arguments(int argc, char **argv)
139139
{
140140
int c;
141141
while ((c = utils_getopt(argc, argv, "c:l:")) != EOF) switch (c) {

samples/gateway/gateway_sample.c

100755100644
+8-9
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int _publish_subdev_msg(void *client, char *topic_keyword, QoS qos, Gatew
210210
// for reply code, pls check https://cloud.tencent.com/document/product/634/45960
211211
#define GATEWAY_RC_REPEAT_BIND 809
212212
static char *new_subdev_file = NULL;
213-
static int sg_loop_count = 5;
213+
static int sg_loop_count = 5;
214214

215215
static int parse_arguments(int argc, char **argv)
216216
{
@@ -277,19 +277,19 @@ int main(int argc, char **argv)
277277

278278
// make sub-device online
279279
GatewayParam gw_param = DEFAULT_GATEWAY_PARAMS;
280-
gw_param.product_id = gw_dev_info.gw_info.product_id;
281-
gw_param.device_name = gw_dev_info.gw_info.device_name;
280+
gw_param.product_id = gw_dev_info.gw_info.product_id;
281+
gw_param.device_name = gw_dev_info.gw_info.device_name;
282282

283-
DeviceInfo *sub_dev_info = gw_dev_info.sub_dev_info;
283+
DeviceInfo *sub_dev_info = gw_dev_info.sub_dev_info;
284284

285285
// to bind a new sub device
286286
DeviceInfo new_sub_dev = {0};
287287
if (new_subdev_file) {
288-
do {
288+
do {
289289
rc = HAL_GetDevInfoFromFile(new_subdev_file, &new_sub_dev);
290290
if (rc) {
291291
Log_e("get devinfo from file failed: %d", rc);
292-
break;
292+
break;
293293
}
294294

295295
rc = IOT_Gateway_Subdev_Bind(client, &gw_param, &new_sub_dev);
@@ -300,12 +300,11 @@ int main(int argc, char **argv)
300300
} else {
301301
Log_e("bind subdev failed: %d", rc);
302302
}
303-
} while(0);
303+
} while (0);
304304
}
305305

306306
gw_param.subdev_product_id = sub_dev_info->product_id;
307307
gw_param.subdev_device_name = sub_dev_info->device_name;
308-
309308

310309
#if 0
311310
// one GatewayParam only support one sub-device
@@ -366,7 +365,7 @@ int main(int argc, char **argv)
366365
Log_e("unbind failed: %d", rc);
367366
}
368367
}
369-
368+
370369
rc = IOT_Gateway_Destroy(client);
371370

372371
return rc;

samples/rrpc/rrpc_sample.c

100755100644
+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int _setup_connect_init_params(MQTTInitParams *initParams, DeviceInfo *de
132132
static void _rrpc_message_handler(void *pClient, const char *msg, uint32_t msgLen)
133133
{
134134
char sg_rrpc_reply_buffer[128] = {0};
135-
size_t sg_rrpc_reply_buffersize = sizeof(sg_rrpc_reply_buffer) / sizeof(sg_rrpc_reply_buffer[0]);
135+
size_t sg_rrpc_reply_buffersize = sizeof(sg_rrpc_reply_buffer) / sizeof(sg_rrpc_reply_buffer[0]);
136136

137137
Log_i("rrpc message=%.*s", msgLen, msg);
138138

sdk_src/internal_inc/gateway_common.h

100755100644
+3-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define GATEWAY_BIND_OP_STR "bind"
2929
#define GATEWAY_UNBIND_OP_STR "unbind"
3030

31-
3231
/* The format of operation of gateway topic */
3332
#define GATEWAY_TOPIC_OPERATION_FMT "$gateway/operation/%s/%s"
3433

@@ -39,13 +38,13 @@
3938
#define GATEWAY_CLIENT_ID_FMT "%s/%s"
4039

4140
/* The format of operation result of gateway topic */
42-
#define GATEWAY_PAYLOAD_STATUS_FMT \
41+
#define GATEWAY_PAYLOAD_STATUS_FMT \
4342
"{\"type\":\"%s\",\"payload\":{\"devices\":[{\"product_id\":\"%s\"," \
4443
"\"device_name\":\"%s\"}]}}"
4544

4645
/* The format of bind cmd payload */
47-
#define GATEWAY_PAYLOAD_OP_FMT \
48-
"{\"type\":\"%s\",\"payload\":{\"devices\":[{\"product_id\":\"%s\"," \
46+
#define GATEWAY_PAYLOAD_OP_FMT \
47+
"{\"type\":\"%s\",\"payload\":{\"devices\":[{\"product_id\":\"%s\"," \
4948
"\"device_name\":\"%s\",\"signature\":\"%s\",\"random\":%d,\"timestamp\":%d," \
5049
"\"signmethod\":\"%s\",\"authtype\":\"%s\"}]}}"
5150

sdk_src/protocol/mqtt/mqtt_client.c

100755100644
+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void *IOT_MQTT_Construct(MQTTInitParams *pParams)
8888
Log_e("Device secret is null!");
8989
qcloud_iot_mqtt_fini(mqtt_client);
9090
HAL_Free(mqtt_client);
91-
pParams->err_code = QCLOUD_ERR_INVAL;
91+
pParams->err_code = QCLOUD_ERR_INVAL;
9292
return NULL;
9393
}
9494
size_t src_len = strlen(pParams->device_secret);
@@ -102,7 +102,7 @@ void *IOT_MQTT_Construct(MQTTInitParams *pParams)
102102
Log_e("Device secret decode err, secret:%s", pParams->device_secret);
103103
qcloud_iot_mqtt_fini(mqtt_client);
104104
HAL_Free(mqtt_client);
105-
pParams->err_code = QCLOUD_ERR_INVAL;
105+
pParams->err_code = QCLOUD_ERR_INVAL;
106106
return NULL;
107107
}
108108
#endif
@@ -112,7 +112,7 @@ void *IOT_MQTT_Construct(MQTTInitParams *pParams)
112112
Log_e("mqtt connect with id: %s failed: %d", mqtt_client->options.conn_id, rc);
113113
qcloud_iot_mqtt_fini(mqtt_client);
114114
HAL_Free(mqtt_client);
115-
pParams->err_code = rc;
115+
pParams->err_code = rc;
116116
return NULL;
117117
} else {
118118
Log_i("mqtt connect with id: %s success", mqtt_client->options.conn_id);

sdk_src/services/gateway/gateway_api.c

100755100644
+20-15
Original file line numberDiff line numberDiff line change
@@ -252,36 +252,40 @@ int IOT_Gateway_Subdev_Offline(void *client, GatewayParam *param)
252252

253253
int IOT_Gateway_Subdev_Bind(void *client, GatewayParam *param, DeviceInfo *pBindSubDevInfo)
254254
{
255-
char topic[MAX_SIZE_OF_CLOUD_TOPIC + 1];
256-
char payload[GATEWAY_PAYLOAD_BUFFER_LEN + 1];
257-
int size = 0;
258-
Gateway * gateway = (Gateway *)client;
255+
char topic[MAX_SIZE_OF_CLOUD_TOPIC + 1];
256+
char payload[GATEWAY_PAYLOAD_BUFFER_LEN + 1];
257+
int size = 0;
258+
Gateway *gateway = (Gateway *)client;
259259

260260
memset(topic, 0, MAX_SIZE_OF_CLOUD_TOPIC);
261-
size = HAL_Snprintf(topic, MAX_SIZE_OF_CLOUD_TOPIC + 1, GATEWAY_TOPIC_OPERATION_FMT, param->product_id, param->device_name);
261+
size = HAL_Snprintf(topic, MAX_SIZE_OF_CLOUD_TOPIC + 1, GATEWAY_TOPIC_OPERATION_FMT, param->product_id,
262+
param->device_name);
262263
if (size < 0 || size > MAX_SIZE_OF_CLOUD_TOPIC) {
263264
Log_e("buf size < topic length!");
264265
IOT_FUNC_EXIT_RC(QCLOUD_ERR_FAILURE);
265266
}
266267

267268
srand((unsigned)HAL_GetTimeMs());
268-
int nonce = rand();
269-
long timestamp = HAL_Timer_current_sec();
269+
int nonce = rand();
270+
long timestamp = HAL_Timer_current_sec();
270271

271272
/*cal sign*/
272273
char sign[SUBDEV_BIND_SIGN_LEN];
273274
memset(sign, 0, SUBDEV_BIND_SIGN_LEN);
274-
if (QCLOUD_RET_SUCCESS != subdev_bind_hmac_sha1_cal(pBindSubDevInfo, sign, SUBDEV_BIND_SIGN_LEN, nonce, timestamp)) {
275+
if (QCLOUD_RET_SUCCESS !=
276+
subdev_bind_hmac_sha1_cal(pBindSubDevInfo, sign, SUBDEV_BIND_SIGN_LEN, nonce, timestamp)) {
275277
Log_e("cal sign fail");
276278
return QCLOUD_ERR_FAILURE;
277279
}
278280
memset(payload, 0, GATEWAY_PAYLOAD_BUFFER_LEN);
279281
#ifdef AUTH_MODE_CERT
280282
size = HAL_Snprintf(payload, GATEWAY_PAYLOAD_BUFFER_LEN + 1, GATEWAY_PAYLOAD_OP_FMT, GATEWAY_BIND_OP_STR,
281-
pBindSubDevInfo->product_id, pBindSubDevInfo->device_name, sign, nonce, timestamp, "hmacsha1", "certificate");
283+
pBindSubDevInfo->product_id, pBindSubDevInfo->device_name, sign, nonce, timestamp, "hmacsha1",
284+
"certificate");
282285
#else
283286
size = HAL_Snprintf(payload, GATEWAY_PAYLOAD_BUFFER_LEN + 1, GATEWAY_PAYLOAD_OP_FMT, GATEWAY_BIND_OP_STR,
284-
pBindSubDevInfo->product_id, pBindSubDevInfo->device_name, sign, nonce, timestamp, "hmacsha1", "psk");
287+
pBindSubDevInfo->product_id, pBindSubDevInfo->device_name, sign, nonce, timestamp, "hmacsha1",
288+
"psk");
285289
#endif
286290

287291
if (size < 0 || size > GATEWAY_PAYLOAD_BUFFER_LEN) {
@@ -313,13 +317,14 @@ int IOT_Gateway_Subdev_Bind(void *client, GatewayParam *param, DeviceInfo *pBind
313317

314318
int IOT_Gateway_Subdev_Unbind(void *client, GatewayParam *param, DeviceInfo *pSubDevInfo)
315319
{
316-
char topic[MAX_SIZE_OF_CLOUD_TOPIC + 1];
317-
char payload[GATEWAY_PAYLOAD_BUFFER_LEN + 1];
318-
int size = 0;
319-
Gateway * gateway = (Gateway *)client;
320+
char topic[MAX_SIZE_OF_CLOUD_TOPIC + 1];
321+
char payload[GATEWAY_PAYLOAD_BUFFER_LEN + 1];
322+
int size = 0;
323+
Gateway *gateway = (Gateway *)client;
320324

321325
memset(topic, 0, MAX_SIZE_OF_CLOUD_TOPIC);
322-
size = HAL_Snprintf(topic, MAX_SIZE_OF_CLOUD_TOPIC + 1, GATEWAY_TOPIC_OPERATION_FMT, param->product_id, param->device_name);
326+
size = HAL_Snprintf(topic, MAX_SIZE_OF_CLOUD_TOPIC + 1, GATEWAY_TOPIC_OPERATION_FMT, param->product_id,
327+
param->device_name);
323328
if (size < 0 || size > MAX_SIZE_OF_CLOUD_TOPIC) {
324329
Log_e("buf size < topic length!");
325330
IOT_FUNC_EXIT_RC(QCLOUD_ERR_FAILURE);

sdk_src/services/gateway/gateway_common.c

100755100644
+18-20
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "utils_md5.h"
2121
#include "utils_hmac.h"
2222

23-
24-
2523
static bool get_json_type(char *json, char **v)
2624
{
2725
*v = LITE_json_value_of("type", json);
@@ -158,12 +156,12 @@ static void _gateway_message_handler(void *client, MQTTMessage *message, void *u
158156
Log_i("client_id(%s), offline result %d", client_id, result);
159157
gateway->gateway_data.offline.result = result;
160158
}
161-
} else if(strncmp(type, GATEWAY_BIND_OP_STR, sizeof(GATEWAY_BIND_OP_STR) - 1) == 0) {
159+
} else if (strncmp(type, GATEWAY_BIND_OP_STR, sizeof(GATEWAY_BIND_OP_STR) - 1) == 0) {
162160
if (strncmp(client_id, gateway->gateway_data.bind.client_id, size) == 0) {
163161
gateway->gateway_data.bind.result = result;
164162
Log_i("client_id(%s), bind result %d", client_id, gateway->gateway_data.bind.result);
165163
}
166-
} else if(strncmp(type, GATEWAY_UNBIND_OP_STR, sizeof(GATEWAY_UNBIND_OP_STR) - 1) == 0) {
164+
} else if (strncmp(type, GATEWAY_UNBIND_OP_STR, sizeof(GATEWAY_UNBIND_OP_STR) - 1) == 0) {
167165
if (strncmp(client_id, gateway->gateway_data.unbind.client_id, size) == 0) {
168166
gateway->gateway_data.unbind.result = result;
169167
Log_i("client_id(%s), unbind result %d", client_id, gateway->gateway_data.unbind.result);
@@ -372,27 +370,27 @@ int gateway_publish_sync(Gateway *gateway, char *topic, PublishParams *params, i
372370
#ifdef AUTH_MODE_CERT
373371
static int gen_key_from_cert_file(const char *file_path, char *keybuff, int buff_len)
374372
{
375-
FILE *fp;
373+
FILE * fp;
376374
uint32_t length;
377-
int ret = QCLOUD_RET_SUCCESS;
375+
int ret = QCLOUD_RET_SUCCESS;
378376

379377
if ((fp = fopen(file_path, "r")) == NULL) {
380378
Log_e("fail to open cert file %s", file_path);
381379
return QCLOUD_ERR_FAILURE;
382380
}
383381

384382
fseek(fp, 0L, SEEK_END);
385-
length = ftell(fp);
383+
length = ftell(fp);
386384
uint8_t *data = HAL_Malloc(length + 1);
387-
if(!data) {
385+
if (!data) {
388386
Log_e("malloc mem err");
389387
return QCLOUD_ERR_MALLOC;
390388
}
391389

392390
fseek(fp, 0, SEEK_SET);
393-
if(length != fread(data, 1, length, fp)) {
391+
if (length != fread(data, 1, length, fp)) {
394392
Log_e("read data len fail");
395-
ret = QCLOUD_ERR_FAILURE;
393+
ret = QCLOUD_ERR_FAILURE;
396394
goto exit;
397395
}
398396

@@ -411,13 +409,14 @@ static int gen_key_from_cert_file(const char *file_path, char *keybuff, int buff
411409

412410
int subdev_bind_hmac_sha1_cal(DeviceInfo *pDevInfo, char *signout, int max_signlen, int nonce, long timestamp)
413411
{
414-
int text_len,ret;
415-
size_t olen = 0;
416-
char * pSignText = NULL;
417-
const char *sign_fmt = "%s%s;%d;%d"; //${product_id}${device_name};${random};${expiration_time}
412+
int text_len, ret;
413+
size_t olen = 0;
414+
char * pSignText = NULL;
415+
const char *sign_fmt = "%s%s;%d;%d"; //${product_id}${device_name};${random};${expiration_time}
418416

419417
/*format sign data*/
420-
text_len = strlen(sign_fmt) + strlen(pDevInfo->device_name) + strlen(pDevInfo->product_id) + sizeof(int) + sizeof(long) + 10;
418+
text_len = strlen(sign_fmt) + strlen(pDevInfo->device_name) + strlen(pDevInfo->product_id) + sizeof(int) +
419+
sizeof(long) + 10;
421420
pSignText = HAL_Malloc(text_len);
422421
if (pSignText == NULL) {
423422
Log_e("malloc sign source buff fail");
@@ -426,12 +425,12 @@ int subdev_bind_hmac_sha1_cal(DeviceInfo *pDevInfo, char *signout, int max_signl
426425
memset(pSignText, 0, text_len);
427426
HAL_Snprintf((char *)pSignText, text_len, sign_fmt, pDevInfo->product_id, pDevInfo->device_name, nonce, timestamp);
428427

429-
//gen digest key
428+
// gen digest key
430429
char key[BIND_SIGN_KEY_SIZE + 1] = {0};
431430
#ifdef AUTH_MODE_CERT
432431
ret = gen_key_from_cert_file(pDevInfo->dev_cert_file_name, key, BIND_SIGN_KEY_SIZE);
433-
if(QCLOUD_RET_SUCCESS != ret) {
434-
Log_e("gen key from cert file fail, ret:%d",ret);
432+
if (QCLOUD_RET_SUCCESS != ret) {
433+
Log_e("gen key from cert file fail, ret:%d", ret);
435434
HAL_Free(pSignText);
436435
return ret;
437436
}
@@ -441,12 +440,11 @@ int subdev_bind_hmac_sha1_cal(DeviceInfo *pDevInfo, char *signout, int max_signl
441440

442441
/*cal hmac sha1*/
443442
char sign[SUBDEV_BIND_SIGN_LEN] = {0};
444-
int sign_len = utils_hmac_sha1_hex(pSignText, strlen(pSignText), sign, key, strlen(key));
443+
int sign_len = utils_hmac_sha1_hex(pSignText, strlen(pSignText), sign, key, strlen(key));
445444

446445
/*base64 encode*/
447446
ret = qcloud_iot_utils_base64encode((uint8_t *)signout, max_signlen, &olen, (const uint8_t *)sign, sign_len);
448447
HAL_Free(pSignText);
449448

450449
return (olen > max_signlen) ? QCLOUD_ERR_FAILURE : ret;
451450
}
452-

sdk_src/services/ota/ota_client.c

100755100644
+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void IOT_OTA_ResetStatus(void *handle)
129129
{
130130
OTA_Struct_t *h_ota = (OTA_Struct_t *)handle;
131131
Log_i("reset OTA state!");
132-
h_ota->state = IOT_OTAS_INITED;
132+
h_ota->state = IOT_OTAS_INITED;
133133
h_ota->err = 0;
134134

135135
if (NULL != h_ota->purl) {
@@ -248,7 +248,7 @@ static int IOT_OTA_ReportUpgradeResult(void *handle, const char *version, IOT_OT
248248

249249
if ((IOT_OTAR_UPGRADE_FAIL == reportType) || (IOT_OTAR_UPGRADE_SUCCESS == reportType) ||
250250
(IOT_OTAR_MD5_NOT_MATCH == reportType)) {
251-
IOT_OTA_ResetStatus(h_ota);
251+
IOT_OTA_ResetStatus(h_ota);
252252
}
253253

254254
do_exit:
@@ -369,7 +369,7 @@ int IOT_OTA_StartDownload(void *handle, uint32_t offset, uint32_t size)
369369

370370
// reinit ofc
371371
qcloud_ofc_deinit(h_ota->ch_fetch);
372-
h_ota->ch_fetch = ofc_Init(h_ota->purl, offset, size);
372+
h_ota->ch_fetch = ofc_Init(h_ota->purl, offset, size);
373373
if (NULL == h_ota->ch_fetch) {
374374
Log_e("Initialize fetch module failed");
375375
return QCLOUD_ERR_FAILURE;

0 commit comments

Comments
 (0)