--- libaitmqtt/inc/defs.h 2012/01/26 13:07:33 1.1.1.1 +++ libaitmqtt/inc/defs.h 2022/09/15 15:04:44 1.4.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: defs.h,v 1.1.1.1 2012/01/26 13:07:33 misho Exp $ +* $Id: defs.h,v 1.4.2.4 2022/09/15 15:04:44 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004 - 2022 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -47,31 +47,66 @@ SUCH DAMAGE. #define __DEFS_H +#ifndef STRSIZ #define STRSIZ 256 -#define MAX_CONNID 24 -#define MAX_CRED 13 -#define MQTTMSG_MAX 65529 +#endif + #define WILDCARDS "/#+" #define MQTT_CONNFLGS_INIT { 1, 1, 1, 3, 1, 1, 1 } -#define MQTT_DATA_MAX 268435455 -#define MQTT_CONN_STR "MQIsdp" -#define MQTT_PROTO_VER 3 -#define MQTT_KEEPALIVE 10 #define MQTT_DEFAULT_MSGID 0xDEBA +#define MQTT_PROTO_STR "MQTT" +#define MQTT_CONN_STR "MQIsdp" + #define LOGERR { \ mqtt_Errno = errno; \ strlcpy(mqtt_Error, strerror(errno), sizeof mqtt_Error); \ } +#ifndef HAVE_STRLCAT +size_t strlcat(char * __restrict dst, const char * __restrict src, size_t siz); +#endif +#ifndef HAVE_STRLCPY +size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t siz); +#endif +#ifndef __ELWIX +#define e_malloc malloc +#define e_calloc calloc +#define e_realloc realloc +#define e_free free +#define e_strdup strdup +#endif + + extern int mqtt_Errno; extern char mqtt_Error[STRSIZ]; -inline void mqtt_SetErr(int eno, char *estr, ...); -inline struct mqtthdr *_mqtt_readHEADER(mqtt_msg_t * __restrict, u_char, int *, int *); +void mqtt_SetErr(int, char *, ...); +//struct mqtthdr *_mqtt_readHEADER(mqtt_msg_t * __restrict, u_char, int *, int *); + +int mqtt_wait4data(int, u_short, short); +/* + * mqtt_KeepAlive() - Keep Alive check routine + * + * @sock = connected socket + * @ka = keep alive timeout + * @tries = tries for receive correct ping response, usually ==1 + * return: -1 error, 0 host is alive, 1 timeout session or 2 broken session + */ +int mqtt_KeepAlive(int sock, unsigned short ka, unsigned char tries); +/* + * mqtt_WillMessage() - Publish WILL message + * + * @sock = connected socket + * @ka = keep alive timeout + * @topic = will topic + * @data = will message + * return: -1 error, 1 timeout, 2 not ack or 0 ok + */ +int mqtt_WillMessage(int sock, unsigned short ka, const char *topic, const char *data); #endif