Diff for /libaitmqtt/src/pub.c between versions 1.1.1.1.2.5 and 1.4

version 1.1.1.1.2.5, 2012/06/11 08:37:41 version 1.4, 2013/05/30 09:18:33
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, 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 63  int Line 63  int
 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID,   mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID, 
                 u_char Dup, u_char QOS, u_char Retain, const void *pData, int datlen)                  u_char Dup, u_char QOS, u_char Retain, const void *pData, int datlen)
 {  {
        int siz = 0;        int len, siz;
         u_int n, *l;
         struct mqtthdr *hdr;          struct mqtthdr *hdr;
         mqtthdr_var_t *topic;          mqtthdr_var_t *topic;
         mqtt_len_t *mid;          mqtt_len_t *mid;
Line 80  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha Line 81  mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
                 return -1;                  return -1;
         }          }
   
        if (mqtt_msgRealloc(buf, MQTTMSG_MAX) == -1)        /* calculate message size */
         len = sizeof(mqtt_len_t) + strlen(csTopic);     /* topic */
         len += sizeof(mqtt_len_t);                      /* msgid */
         len += datlen;                                  /* data len */
 
         /* calculate header size */
         siz = sizeof(struct mqtthdr);                   /* mqtt fixed header */
         n = mqtt_encodeLen(len);                        /* message size */
         siz += mqtt_sizeLen(n) - 1;                     /* length size */
 
         if (mqtt_msgRealloc(buf, siz + len) == -1)
                 return -1;                  return -1;
         else {          else {
                hdr = (struct mqtthdr *) (buf->msg_base + siz);                data = buf->msg_base;
                siz += sizeof(struct mqtthdr);                hdr = (struct mqtthdr *) data;
         }          }
   
           /* fixed header */
           MQTTHDR_MSGINIT(hdr);
           hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH;
           hdr->mqtt_msg.qos = QOS;
           hdr->mqtt_msg.dup = Dup ? 1 : 0;
           hdr->mqtt_msg.retain = Retain ? 1 : 0;
           l = (u_int*) hdr->mqtt_len;
           *l = n;
           data += siz;
   
         /* variable header */          /* variable header */
        topic = (mqtthdr_var_t*) (buf->msg_base + siz);        topic = (mqtthdr_var_t*) data;
         topic->var_sb.val = htons(strlen(csTopic));          topic->var_sb.val = htons(strlen(csTopic));
         memcpy(topic->var_data, csTopic, ntohs(topic->var_sb.val));          memcpy(topic->var_data, csTopic, ntohs(topic->var_sb.val));
        siz += MQTTHDR_VAR_SIZEOF(topic);        data += MQTTHDR_VAR_SIZEOF(topic);
   
        mid = (mqtt_len_t*) (buf->msg_base + siz);        mid = (mqtt_len_t*) data;
         mid->val = htons(msgID);          mid->val = htons(msgID);
        siz += sizeof(mqtt_len_t);        data += sizeof(mqtt_len_t);
   
         /* load with data */          /* load with data */
        if (pData && datlen) {        if (pData && datlen)
                data = buf->msg_base + siz; 
                 memcpy(data, pData, datlen);                  memcpy(data, pData, datlen);
                 siz += datlen;  
         }  
   
        /* fixed header */        return siz + len;
        MQTTHDR_MSGINIT(hdr); 
        hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH; 
        hdr->mqtt_msg.qos = QOS; 
        hdr->mqtt_msg.dup = Dup ? 1 : 0; 
        hdr->mqtt_msg.retain = Retain ? 1 : 0; 
        *hdr->mqtt_len = mqtt_encodeLen(siz - sizeof(struct mqtthdr)); 
 
        return siz; 
 }  }
   
 static int  static int
 _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, u_short msgID)  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, u_short msgID)
 {  {
        int siz = 0;        int siz = sizeof(struct mqtthdr);
         struct mqtthdr *hdr;          struct mqtthdr *hdr;
         mqtt_len_t *v;          mqtt_len_t *v;
   
Line 127  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, Line 137  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd,
   
         if (mqtt_msgRealloc(buf, sizeof(struct mqtthdr) + sizeof(mqtt_len_t)) == -1)          if (mqtt_msgRealloc(buf, sizeof(struct mqtthdr) + sizeof(mqtt_len_t)) == -1)
                 return -1;                  return -1;
        else {        else
                hdr = (struct mqtthdr *) (buf->msg_base + siz);                hdr = (struct mqtthdr *) buf->msg_base;
                siz += sizeof(struct mqtthdr); 
                v = (mqtt_len_t*) (buf->msg_base + siz); 
                siz += sizeof(mqtt_len_t); 
        } 
   
         /* fixed header */          /* fixed header */
         MQTTHDR_MSGINIT(hdr);          MQTTHDR_MSGINIT(hdr);
Line 140  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, Line 146  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char 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 siz;
 }  }
Line 152  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, Line 160  _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd,
  * @msgID = MessageID   * @msgID = MessageID
  * return: -1 error or >-1 message size for send   * return: -1 error or >-1 message size for send
  */   */
inline intint
 mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, u_short msgID)  mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, u_short msgID)
 {  {
         return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBACK, msgID);          return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBACK, msgID);
Line 165  mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, u_short ms Line 173  mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, u_short ms
  * @msgID = MessageID   * @msgID = MessageID
  * return: -1 error or >-1 message size for send   * return: -1 error or >-1 message size for send
  */   */
inline intint
 mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, u_short msgID)  mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, u_short msgID)
 {  {
         return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREC, msgID);          return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREC, msgID);
Line 178  mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, u_short ms Line 186  mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, u_short ms
  * @msgID = MessageID   * @msgID = MessageID
  * return: -1 error or >-1 message size for send   * return: -1 error or >-1 message size for send
  */   */
inline intint
 mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, u_short msgID)  mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, u_short msgID)
 {  {
         return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREL, msgID);          return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBREL, msgID);
Line 191  mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, u_short ms Line 199  mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, u_short ms
  * @msgID = MessageID   * @msgID = MessageID
  * return: -1 error or >-1 message size for send   * return: -1 error or >-1 message size for send
  */   */
inline intint
 mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, u_short msgID)  mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, u_short msgID)
 {  {
         return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBCOMP, msgID);          return _mqtt_msgPUB_(buf, MQTT_TYPE_PUBCOMP, msgID);

Removed from v.1.1.1.1.2.5  
changed lines
  Added in v.1.4


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