--- libaitmqtt/inc/mqttapi.h 2012/05/08 11:29:56 1.1.2.9 +++ libaitmqtt/inc/mqttapi.h 2012/06/29 15:23:10 1.3.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: mqttapi.h,v 1.1.2.9 2012/05/08 11:29:56 misho Exp $ +* $Id: mqttapi.h,v 1.3.2.1 2012/06/29 15:23:10 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -67,30 +67,57 @@ typedef struct { /* - * mqtt_srv_Init() Init server side actor + * mqtt_srv_cliInit() Init MQTT server side support for clients * * @sock = Client socket from accept() * @buf = Message buffer * @timeout = timeout + * @nb = Non block socket * return: NULL error or !=NULL allocated server handle */ -mqtt_srv_t *mqtt_srv_Init(int sock, mqtt_msg_t * __restrict buf, unsigned short timeout); +mqtt_srv_t *mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf, + unsigned short timeout, int nb); /* - * mqtt_srv_Fini() Finish MQTT server side support + * mqtt_srv_Fini() Finish MQTT server side support for clients * * @psrv = Server handle * return: none */ -void mqtt_srv_Fini(mqtt_srv_t ** __restrict psrv); +void mqtt_srv_cliFini(mqtt_srv_t ** __restrict psrv); /* - * mqtt_srv_Dispatch() MQTT server dispatcher + * mqtt_srv_Dispatch() MQTT server dispatcher for clients * * @srv = Server handle * @rlen = Ready bytes to parse * @arg = Argument pass to command callback * return: -1 error or 0 ok */ -int mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, int rlen, void *arg); +int mqtt_srv_cliDispatch(mqtt_srv_t * __restrict srv, int rlen, void *arg); + +/* + * mqtt_srv_Create() - Create server socket + * + * @sa = Server bind address + * @salen = Server struct sockaddr size + * return: -1 error or >-1 server socket + */ +int mqtt_srv_Create(struct sockaddr * __restrict sa, int salen); +/* + * mqtt_srv_Destroy() - Close server socket + * + * @sock = Server socket + * return: -1 error or 0 ok + */ +int mqtt_srv_Destroy(int sock); +/* + * mqtt_srv_Listen() - Listen server socket + * + * @sock = Server socket + * @maxconn = max number of pending connections + * @nb = Non block socket + * return: -1 error or 0 ok + */ +int mqtt_srv_Listen(int sock, int maxconn, int nb); #endif /* @@ -102,6 +129,16 @@ int mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, int * 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); #ifdef API_CLIENT_SIDE @@ -157,6 +194,22 @@ unsigned char *mqtt_cli_Subscribe(mqtt_cli_t * __restr int mqtt_cli_Unsubscribe(mqtt_cli_t * __restrict cli, mqtt_subscr_t * __restrict Topics, unsigned short msgID, unsigned char Dup, unsigned char QoS); +/* + * mqtt_cli_Publish() - Publish message to broker + * + * @cli = connected client + * @msgID = Message ID + * @Dup = Duplicated request + * @QoS = Message QoS + * @Retain = Retain message + * @csTopic = Topic + * @pData = Data + * @datLen = Data length + * return: -1 error or > -1 sended bytes + */ +int mqtt_cli_Publish(mqtt_cli_t * __restrict cli, unsigned short msgID, + unsigned char Dup, unsigned char QoS, unsigned char Retain, + const char *csTopic, const void *pData, int datLen); #endif