version 1.2.2.3, 2012/04/27 10:07:51
|
version 1.2.2.5, 2012/05/01 22:30:31
|
Line 54 Subscribe(int sock, FILE *lf)
|
Line 54 Subscribe(int sock, FILE *lf)
|
{ |
{ |
int siz; |
int siz; |
u_char *qoses; |
u_char *qoses; |
u_short mid; | u_short mid[2]; |
|
|
siz = mqtt_msgSUBSCRIBE(args->msg, args->subscr, AIT_GET_U16(&args->ConnID), args->Dup, args->QoS); | srandomdev(); |
| mid[0] = random() % USHRT_MAX; |
| |
| siz = mqtt_msgSUBSCRIBE(args->msg, args->subscr, mid[0], args->Dup, args->QoS); |
if (siz == -1) { |
if (siz == -1) { |
printf("Error:: in msgSUBSCRIBE #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
printf("Error:: in msgSUBSCRIBE #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
return -1; |
return -1; |
Line 68 Subscribe(int sock, FILE *lf)
|
Line 71 Subscribe(int sock, FILE *lf)
|
siz = RecvFrom(sock); |
siz = RecvFrom(sock); |
if (siz == -1) |
if (siz == -1) |
return -1; |
return -1; |
siz = mqtt_readSUBACK(args->msg, &mid, &qoses); | siz = mqtt_readSUBACK(args->msg, &mid[1], &qoses); |
if (siz == -1) { |
if (siz == -1) { |
printf("Error:: in readSUBACK #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
printf("Error:: in readSUBACK #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); |
return -1; |
return -1; |
} |
} |
if (mid != AIT_GET_U16(&args->ConnID)) { | if (mid[1] != mid[0]) { |
printf("Error:: received different connection ID %d != %d\n", | printf("Error:: received different connection ID %d != %d\n", mid[1], mid[0]); |
mid, AIT_GET_U16(&args->ConnID)); | |
return -1; |
return -1; |
} |
} |
|
|
|
free(qoses); |
return 0; |
return 0; |
} |
} |
|
|
Line 90 main(int argc, char **argv)
|
Line 93 main(int argc, char **argv)
|
ait_val_t val; |
ait_val_t val; |
u_short port = atoi(MQTT_PORT); |
u_short port = atoi(MQTT_PORT); |
mqtt_subscr_t *sub; |
mqtt_subscr_t *sub; |
int sock, ret = 0; | int ret = 0; |
char *str, szStr[STRSIZ], szLogName[MAXPATHLEN] = { 0 }; |
char *str, szStr[STRSIZ], szLogName[MAXPATHLEN] = { 0 }; |
FILE *lf; |
FILE *lf; |
|
|
Line 113 main(int argc, char **argv)
|
Line 116 main(int argc, char **argv)
|
return 1; |
return 1; |
} |
} |
|
|
|
AIT_SET_STR(&args->ConnID, ""); |
AIT_SET_STR(&args->User, ""); |
AIT_SET_STR(&args->User, ""); |
AIT_SET_STR(&args->Pass, ""); |
AIT_SET_STR(&args->Pass, ""); |
|
|
Line 203 main(int argc, char **argv)
|
Line 207 main(int argc, char **argv)
|
free(args); |
free(args); |
Usage(); |
Usage(); |
return 1; |
return 1; |
} else | } else { |
AIT_SET_U16(&args->ConnID, strtol(argv[1], NULL, 0)); | AIT_FREE_VAL(&args->ConnID); |
| AIT_SET_STR(&args->ConnID, argv[1]); |
| } |
if (argc > 2) { |
if (argc > 2) { |
AIT_FREE_VAL(&args->Value); |
AIT_FREE_VAL(&args->Value); |
AIT_SET_STR(&args->Value, argv[2]); |
AIT_SET_STR(&args->Value, argv[2]); |
Line 219 main(int argc, char **argv)
|
Line 225 main(int argc, char **argv)
|
printf("Connecting to %s:%d ... ", io_n2addr(&args->addr, &val), io_n2port(&args->addr)); |
printf("Connecting to %s:%d ... ", io_n2addr(&args->addr, &val), io_n2port(&args->addr)); |
AIT_FREE_VAL(&val); |
AIT_FREE_VAL(&val); |
|
|
if ((sock = InitClient()) == -1) { | if (!(args->cli = mqtt_cli_Open(&args->addr.sa))) { |
args->free(args); |
args->free(args); |
free(args); |
free(args); |
return 2; |
return 2; |
} |
} |
|
|
switch ((ret = ConnectClient(sock))) { | switch ((ret = ConnectClient(args->cli->sock))) { |
case -1: |
case -1: |
printf(">> FAILED!\n"); |
printf(">> FAILED!\n"); |
break; |
break; |
Line 255 main(int argc, char **argv)
|
Line 261 main(int argc, char **argv)
|
else |
else |
lf = stdout; |
lf = stdout; |
if (lf) { |
if (lf) { |
ret = Subscribe(sock, lf); | ret = Subscribe(args->cli->sock, lf); |
fclose(lf); |
fclose(lf); |
} else |
} else |
printf("Error:: in subscribe file #%d - %s\n", errno, strerror(errno)); |
printf("Error:: in subscribe file #%d - %s\n", errno, strerror(errno)); |
CloseClient(sock); | } else |
} else { | |
close(sock); | |
ret = 3; |
ret = 3; |
} | |
| mqtt_cli_Close(&args->cli); |
|
|
args->free(args); |
args->free(args); |
free(args); |
free(args); |