Diff for /libaitmqtt/src/pub.c between versions 1.2.2.2 and 1.4.4.1

version 1.2.2.2, 2012/06/28 09:01:42 version 1.4.4.1, 2022/09/14 17:37:13
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, 2012Copyright 2004 - 2022
         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.
 /*  /*
  * mqtt_msgPUBLISH() Create PUBLISH message   * mqtt_msgPUBLISH() Create PUBLISH message
  *   *
  * @buf = Message buffer  
  * @csTopic = Publish topic   * @csTopic = Publish topic
  * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE   * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
  * @Dup = Duplicate message   * @Dup = Duplicate message
Line 57  SUCH DAMAGE. Line 56  SUCH DAMAGE.
  * @Retain = Retain message   * @Retain = Retain message
  * @pData = Publish data into topic   * @pData = Publish data into topic
  * @datlen = Publish data length   * @datlen = Publish data length
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBLISH message
  */   */
intmqtt_msg_t *
mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID, mqtt_msgPUBLISH(const char *csTopic, u_short msgID, u_char Dup, 
                u_char Dup, u_char QOS, u_char Retain, const void *pData, int datlen)                u_char QOS, u_char Retain, const void *pData, int datlen)
 {  {
         int len, siz;          int len, siz;
         u_int n, *l;          u_int n, *l;
Line 69  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha Line 68  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
         mqtthdr_var_t *topic;          mqtthdr_var_t *topic;
         mqtt_len_t *mid;          mqtt_len_t *mid;
         void *data;          void *data;
           mqtt_msg_t *msg = NULL;
   
        if (!buf || !csTopic)        if (!csTopic)
                return -1;                return NULL;
         if (QOS > MQTT_QOS_EXACTLY) {          if (QOS > MQTT_QOS_EXACTLY) {
                 mqtt_SetErr(EINVAL, "Invalid QoS parameter");                  mqtt_SetErr(EINVAL, "Invalid QoS parameter");
                return -1;                return NULL;
         }          }
         if (!msgID && QOS != MQTT_QOS_ONCE) {          if (!msgID && QOS != MQTT_QOS_ONCE) {
                 mqtt_SetErr(EINVAL, "Invalid MessageID parameter must be >0");                  mqtt_SetErr(EINVAL, "Invalid MessageID parameter must be >0");
                return -1;                return NULL;
         }          }
   
         /* calculate message size */          /* calculate message size */
Line 91  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha Line 91  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
         n = mqtt_encodeLen(len);                        /* message size */          n = mqtt_encodeLen(len);                        /* message size */
         siz += mqtt_sizeLen(n) - 1;                     /* length size */          siz += mqtt_sizeLen(n) - 1;                     /* length size */
   
        if (mqtt_msgRealloc(buf, siz + len) == -1)        if (!(msg = mqtt_msgAlloc(siz + len)))
                return -1;                return NULL;
         else {          else {
                data = buf->msg_base;                data = msg->msg_base;
                 hdr = (struct mqtthdr *) data;                  hdr = (struct mqtthdr *) data;
         }          }
   
         /* fixed header */          /* fixed header */
         MQTTHDR_MSGINIT(hdr);  
         hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH;          hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH;
         hdr->mqtt_msg.qos = QOS;          hdr->mqtt_msg.qos = QOS;
         hdr->mqtt_msg.dup = Dup ? 1 : 0;          hdr->mqtt_msg.dup = Dup ? 1 : 0;
Line 122  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha Line 121  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
         if (pData && datlen)          if (pData && datlen)
                 memcpy(data, pData, datlen);                  memcpy(data, pData, datlen);
   
        return siz + len;        return msg;
 }  }
   
static intstatic mqtt_msg_t *
_mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, u_short msgID)_mqtt_msgPUB_(u_char cmd, u_short msgID)
 {  {
         int siz = sizeof(struct mqtthdr);  
         struct mqtthdr *hdr;          struct mqtthdr *hdr;
         mqtt_len_t *v;          mqtt_len_t *v;
           mqtt_msg_t *msg = NULL;
   
        if (!buf)        if (!(msg = mqtt_msgAlloc(sizeof(struct mqtthdr) + sizeof(mqtt_len_t))))
                return -1;                return NULL;
         else {
                 hdr = (struct mqtthdr *) msg->msg_base;
                 v = (mqtt_len_t*) (msg->msg_base + sizeof(struct mqtthdr));
         }
   
         if (mqtt_msgRealloc(buf, sizeof(struct mqtthdr) + sizeof(mqtt_len_t)) == -1)  
                 return -1;  
         else  
                 hdr = (struct mqtthdr *) buf->msg_base;  
   
         /* fixed header */          /* fixed header */
         MQTTHDR_MSGINIT(hdr);  
         hdr->mqtt_msg.type = cmd;          hdr->mqtt_msg.type = cmd;
         *hdr->mqtt_len = sizeof(mqtt_len_t);          *hdr->mqtt_len = sizeof(mqtt_len_t);
   
         /* MessageID */          /* MessageID */
         v = (mqtt_len_t*) (buf->msg_base + siz);  
         v->val = htons(msgID);          v->val = htons(msgID);
         siz += sizeof(mqtt_len_t);  
   
        return siz;        return msg;
 }  }
   
 /*  /*
  * mqtt_msgPUBACK() Create PUBACK message   * mqtt_msgPUBACK() Create PUBACK message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBACK message
  */   */
inline intmqtt_msg_t *
mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, u_short msgID)mqtt_msgPUBACK(u_short msgID)
 {  {
        return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBACK, msgID);        return _mqtt_msgPUB_(MQTT_TYPE_PUBACK, msgID);
 }  }
   
 /*  /*
  * mqtt_msgPUBREC() Create PUBREC message   * mqtt_msgPUBREC() Create PUBREC message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBREC message
  */   */
inline intmqtt_msg_t *
mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, u_short msgID)mqtt_msgPUBREC(u_short msgID)
 {  {
        return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREC, msgID);        return _mqtt_msgPUB_(MQTT_TYPE_PUBREC, msgID);
 }  }
   
 /*  /*
  * mqtt_msgPUBREL() Create PUBREL message   * mqtt_msgPUBREL() Create PUBREL message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBREL message
  */   */
inline intmqtt_msg_t *
mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, u_short msgID)mqtt_msgPUBREL(u_short msgID)
 {  {
        return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREL, msgID);        return _mqtt_msgPUB_(MQTT_TYPE_PUBREL, msgID);
 }  }
   
 /*  /*
  * mqtt_msgPUBCOMP() Create PUBCOMP message   * mqtt_msgPUBCOMP() Create PUBCOMP message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBCOMP message
  */   */
inline intmqtt_msg_t *
mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, u_short msgID)mqtt_msgPUBCOMP(u_short msgID)
 {  {
        return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBCOMP, msgID);        return _mqtt_msgPUB_(MQTT_TYPE_PUBCOMP, msgID);
 }  }
   
   
 /* ============= decode ============ */  /* ============= decode ============ */
   
   #if 0
 /*  /*
  * mqtt_readPUBLISH() Read PUBLISH message   * mqtt_readPUBLISH() Read PUBLISH message
  *   *
Line 387  mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf) Line 379  mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf)
   
         return ntohs(v->val);          return ntohs(v->val);
 }  }
   #endif

Removed from v.1.2.2.2  
changed lines
  Added in v.1.4.4.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>