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

version 1.1.1.1.2.5, 2012/06/11 08:37:41 version 1.3, 2012/06/28 11:06:17
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;
 }  }

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


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