1
0
mirror of https://github.com/taigrr/tplinkController synced 2025-01-18 04:43:13 -08:00

small formatting changes

This commit is contained in:
Jason Benaim 2018-11-24 21:17:15 -08:00
parent f870b6458d
commit 4bbecdaea0
3 changed files with 47 additions and 45 deletions

15
comms.c
View File

@ -48,12 +48,14 @@ bool hs100_decrypt(uint8_t *d, uint8_t *s, size_t len)
uint8_t *hs100_encode(size_t *outlen, char *srcmsg) uint8_t *hs100_encode(size_t *outlen, char *srcmsg)
{ {
if(srcmsg == NULL) return NULL; if (srcmsg == NULL)
return NULL;
size_t srcmsg_len = strlen(srcmsg); size_t srcmsg_len = strlen(srcmsg);
*outlen = srcmsg_len + 4; *outlen = srcmsg_len + 4;
uint8_t *d = calloc(1, *outlen); uint8_t *d = calloc(1, *outlen);
if(d == NULL) return NULL; if (d == NULL)
return NULL;
if (!hs100_encrypt(d + 4, (uint8_t *) srcmsg, srcmsg_len)) { if (!hs100_encrypt(d + 4, (uint8_t *) srcmsg, srcmsg_len)) {
free(d); free(d);
return NULL; return NULL;
@ -66,8 +68,10 @@ uint8_t *hs100_encode(size_t *outlen, char *srcmsg)
char *hs100_decode(uint8_t *s, size_t s_len) char *hs100_decode(uint8_t *s, size_t s_len)
{ {
if(s == NULL) return NULL; if (s == NULL)
if(s_len <= 4) return NULL; return NULL;
if (s_len <= 4)
return NULL;
uint32_t in_s_len; uint32_t in_s_len;
memcpy(&in_s_len, s, 4); memcpy(&in_s_len, s, 4);
@ -95,7 +99,8 @@ char *hs100_send(char *servaddr, char *msg)
return NULL; return NULL;
int sock = socket(AF_INET, SOCK_STREAM, 0); int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock < 0) return NULL; if (sock < 0)
return NULL;
struct sockaddr_in address; struct sockaddr_in address;
memset(&address, '0', sizeof(struct sockaddr_in)); memset(&address, '0', sizeof(struct sockaddr_in));

15
hs100.c
View File

@ -67,8 +67,7 @@ struct cmd_s cmds[] = {
struct cmd_s *get_cmd_from_name(char *needle) struct cmd_s *get_cmd_from_name(char *needle)
{ {
int cmds_index = 0; int cmds_index = 0;
while(!cmds[cmds_index].end) while (!cmds[cmds_index].end) {
{
if (!strcmp(cmds[cmds_index].command, needle)) if (!strcmp(cmds[cmds_index].command, needle))
return &cmds[cmds_index]; return &cmds[cmds_index];
cmds_index++; cmds_index++;
@ -78,16 +77,14 @@ struct cmd_s *get_cmd_from_name(char *needle)
void print_usage() void print_usage()
{ {
fprintf(stderr, "hs100 version " VERSION_STRING ", Copyright (C) 2018 Jason Benaim.\n" fprintf(stderr, "hs100 version " VERSION_STRING
"A tool for using certain wifi smart plugs.\n" ", Copyright (C) 2018 Jason Benaim.\n"
"\n" "A tool for using certain wifi smart plugs.\n\n"
"usage: hs100 <ip> <command>\n" "usage: hs100 <ip> <command>\n\n"
"\n"
"Commands:\n" "Commands:\n"
); );
int cmds_index = 0; int cmds_index = 0;
while(!cmds[cmds_index].end) while (!cmds[cmds_index].end) {
{
fprintf(stderr, "\t%s\n\n", cmds[cmds_index].help); fprintf(stderr, "\t%s\n\n", cmds[cmds_index].help);
cmds_index++; cmds_index++;
} }