version 1.4, 2012/07/03 12:46:00
|
version 1.5, 2017/10/08 22:49:25
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 49 SUCH DAMAGE.
|
Line 49 SUCH DAMAGE.
|
#include "client.h" |
#include "client.h" |
|
|
|
|
io_enableDEBUG; |
|
|
|
extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
volatile intptr_t Kill; |
volatile intptr_t Kill; |
sched_root_task_t *root; |
sched_root_task_t *root; |
Line 173 execProc(sched_task_t *task)
|
Line 171 execProc(sched_task_t *task)
|
snprintf(szLine, sizeof szLine, "%s '%s' %hu %u", AIT_GET_STR(&args->Value), |
snprintf(szLine, sizeof szLine, "%s '%s' %hu %u", AIT_GET_STR(&args->Value), |
(char*) TASK_ARG(task), (u_short) TASK_VAL(task), (u_int) TASK_DATLEN(task)); |
(char*) TASK_ARG(task), (u_short) TASK_VAL(task), (u_int) TASK_DATLEN(task)); |
if (TASK_ARG(task)) |
if (TASK_ARG(task)) |
io_free(TASK_ARG(task)); | e_free(TASK_ARG(task)); |
|
|
f = popen(szLine, "w"); |
f = popen(szLine, "w"); |
if (!f) { |
if (!f) { |
ioSYSERR(0); | ESYSERR(0); |
return NULL; |
return NULL; |
} else |
} else |
fputs(TASK_DATA(task), f); |
fputs(TASK_DATA(task), f); |
Line 214 pubRX(sched_task_t *task)
|
Line 212 pubRX(sched_task_t *task)
|
else { |
else { |
siz = mqtt_pktLen(hdr); |
siz = mqtt_pktLen(hdr); |
rlen -= siz; |
rlen -= siz; |
ioVERBOSE(4) printf("Remains %d bytes, packet %d bytes\n", | EVERBS(4) printf("Remains %d bytes, packet %d bytes\n", rlen, siz); |
rlen, siz); | |
} |
} |
|
|
/* send to output */ |
/* send to output */ |
Line 235 pubRX(sched_task_t *task)
|
Line 232 pubRX(sched_task_t *task)
|
|
|
/* if exists exec script */ |
/* if exists exec script */ |
if (!AIT_ISEMPTY(&args->Value)) |
if (!AIT_ISEMPTY(&args->Value)) |
schedEvent(root, execProc, io_strdup(szTopic), mid, data, siz); | schedEvent(root, execProc, e_strdup(szTopic), mid, data, siz); |
|
|
memmove(args->msg->msg_base, args->msg->msg_base + siz, rlen); |
memmove(args->msg->msg_base, args->msg->msg_base + siz, rlen); |
break; |
break; |
Line 253 pubRX(sched_task_t *task)
|
Line 250 pubRX(sched_task_t *task)
|
memmove(args->msg->msg_base, args->msg->msg_base + siz, rlen); |
memmove(args->msg->msg_base, args->msg->msg_base + siz, rlen); |
break; |
break; |
default: |
default: |
ioVERBOSE(1) printf("Unwanted message type #%d ...\n", hdr->mqtt_msg.type); | EVERBS(1) printf("Unwanted message type #%d ...\n", hdr->mqtt_msg.type); |
goto end; |
goto end; |
} |
} |
} |
} |
Line 275 main(int argc, char **argv)
|
Line 272 main(int argc, char **argv)
|
FILE *lf; |
FILE *lf; |
struct sigaction sa; |
struct sigaction sa; |
|
|
if (!(args = io_malloc(sizeof(struct tagArgs)))) { | if (!(args = e_malloc(sizeof(struct tagArgs)))) { |
printf("Error:: in arguments #%d - %s\n", errno, strerror(errno)); |
printf("Error:: in arguments #%d - %s\n", errno, strerror(errno)); |
return 1; |
return 1; |
} else |
} else |
memset(args, 0, sizeof(struct tagArgs)); |
memset(args, 0, sizeof(struct tagArgs)); |
if (!(args->subscr = mqtt_subAlloc(idx))) { |
if (!(args->subscr = mqtt_subAlloc(idx))) { |
printf("Error:: in subscribes array #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
printf("Error:: in subscribes array #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
io_free(args); | e_free(args); |
return 1; |
return 1; |
} else |
} else |
args->free = cleanArgs; |
args->free = cleanArgs; |
Line 290 main(int argc, char **argv)
|
Line 287 main(int argc, char **argv)
|
if (!(args->msg = mqtt_msgAlloc(USHRT_MAX))) { |
if (!(args->msg = mqtt_msgAlloc(USHRT_MAX))) { |
printf("Error:: in mqtt buffer #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
printf("Error:: in mqtt buffer #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
return 1; |
return 1; |
} |
} |
|
|
Line 328 main(int argc, char **argv)
|
Line 325 main(int argc, char **argv)
|
if (!sub) { |
if (!sub) { |
printf("Error:: #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
printf("Error:: #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
return 1; |
return 1; |
} else |
} else |
sub += idx++; |
sub += idx++; |
Line 351 main(int argc, char **argv)
|
Line 348 main(int argc, char **argv)
|
if (args->QoS > MQTT_QOS_EXACTLY) { |
if (args->QoS > MQTT_QOS_EXACTLY) { |
printf("Error:: invalid QoS level %d\n", args->QoS); |
printf("Error:: invalid QoS level %d\n", args->QoS); |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
return 1; |
return 1; |
} |
} |
break; |
break; |
Line 368 main(int argc, char **argv)
|
Line 365 main(int argc, char **argv)
|
batch = 0; |
batch = 0; |
break; |
break; |
case 'v': |
case 'v': |
io_incDebug; | e_incVerbose; |
break; |
break; |
case 'u': |
case 'u': |
un = 1; |
un = 1; |
Line 376 main(int argc, char **argv)
|
Line 373 main(int argc, char **argv)
|
case 'h': |
case 'h': |
default: |
default: |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
Usage(); |
Usage(); |
return 1; |
return 1; |
} |
} |
Line 385 main(int argc, char **argv)
|
Line 382 main(int argc, char **argv)
|
if (argc < 2) { |
if (argc < 2) { |
printf("Error:: host for connect not found, connection id or topic not supplied!\n\n"); |
printf("Error:: host for connect not found, connection id or topic not supplied!\n\n"); |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
Usage(); |
Usage(); |
return 1; |
return 1; |
} else { |
} else { |
Line 396 main(int argc, char **argv)
|
Line 393 main(int argc, char **argv)
|
AIT_FREE_VAL(&args->Value); |
AIT_FREE_VAL(&args->Value); |
AIT_SET_STR(&args->Value, argv[2]); |
AIT_SET_STR(&args->Value, argv[2]); |
} |
} |
if (!io_gethostbyname(*argv, port, &args->addr)) { | if (!e_gethostbyname(*argv, port, &args->addr)) { |
printf("Error:: host not valid #%d - %s\n", io_GetErrno(), io_GetError()); | printf("Error:: host not valid #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
Usage(); |
Usage(); |
return 1; |
return 1; |
} |
} |
printf("Connecting to %s:%d ... ", io_n2addr(&args->addr, &val), io_n2port(&args->addr)); | printf("Connecting to %s:%d ... ", e_n2addr(&args->addr, &val), e_n2port(&args->addr)); |
AIT_FREE_VAL(&val); |
AIT_FREE_VAL(&val); |
|
|
|
memset(&sa, 0, sizeof sa); |
sa.sa_handler = sigz; |
sa.sa_handler = sigz; |
sigemptyset(&sa.sa_mask); |
sigemptyset(&sa.sa_mask); |
sigaction(SIGTERM, &sa, NULL); |
sigaction(SIGTERM, &sa, NULL); |
Line 490 main(int argc, char **argv)
|
Line 488 main(int argc, char **argv)
|
mqtt_cli_Close(&args->cli); |
mqtt_cli_Close(&args->cli); |
end: |
end: |
args->free(args); |
args->free(args); |
io_free(args); | e_free(args); |
return ret; |
return ret; |
} |
} |