Diff for /mqtt/src/mqttd_calls.c between versions 1.2.2.3 and 1.2.2.7

version 1.2.2.3, 2012/04/11 16:37:17 version 1.2.2.7, 2012/04/27 10:07:51
Line 51  cmdPUBREL(void *srv, void *arg) Line 51  cmdPUBREL(void *srv, void *arg)
 int  int
 cmdSUBSCRIBE(void *srv, void *arg)  cmdSUBSCRIBE(void *srv, void *arg)
 {  {
         struct mqtthdr *hdr;  
         struct tagSession *sess = (struct tagSession*) arg;          struct tagSession *sess = (struct tagSession*) arg;
           mqtt_subscr_t *subs = NULL;
           int siz = 0;
           u_short mid = 0;
           register int i;
           struct tagStore *store;
   
         ioTRACE(2);          ioTRACE(2);
   
         if (!sess)          if (!sess)
                 return -1;                  return -1;
   
        hdr = (struct mqtthdr*) sess->sess_buf->msg_base;        ioDEBUG(5, "Exec SUBSCRIBE session");
         siz = mqtt_readSUBSCRIBE(sess->sess_buf, &mid, &subs);
         if (siz == -1) {
                 ioDEBUG(5, "Error:: in readSUBSCRIBE #%d - %s", mqtt_GetErrno(), mqtt_GetError());
                 return 0;
         }
   
           /* add to db */
           for (i = 0; i < siz; i++) {
                   if ((siz = call.WritePUB_subscribe(&cfg, pub, mid, subs[i].sub_topic.msg_base, 
                                   sess->sess_user, sess->sess_addr, subs[i].sub_ret)) > 0) {
                           store = malloc(sizeof(struct tagStore));
                           if (!store) {
                                   ioSYSERR(0);
                                   goto end;
                           } else {
                                   store->st_msgid = mid;
                                   store->st_subscr = subs[i];
                           }
   
                           /* add to cache */
                           SESS_ELEM_LOCK(sess);
                           SLIST_INSERT_HEAD(&sess->sess_subscr, store, st_node);
                           SESS_ELEM_UNLOCK(sess);
   
                           subs[i].sub_ret = MQTT_QOS_PASS;
                   } else
                           subs[i].sub_ret = MQTT_QOS_DENY;
           }
   
           /* send acknowledge */
           siz = mqtt_msgSUBACK(sess->sess_buf, subs, mid);
           if (siz == -1) {
                   ioDEBUG(5, "Error:: in msgSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError());
                   goto end;
           }
           if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, 0)) == -1)
                   ioSYSERR(0);
           else
                   ioDEBUG(5, "Sended %d bytes.", siz);
   end:
           mqtt_subFree(&subs);
         return 0;          return 0;
 }  }
   
 int  int
 cmdUNSUBSCRIBE(void *srv, void *arg)  cmdUNSUBSCRIBE(void *srv, void *arg)
 {  {
         struct mqtthdr *hdr;  
         struct tagSession *sess = (struct tagSession*) arg;          struct tagSession *sess = (struct tagSession*) arg;
   
         ioTRACE(2);          ioTRACE(2);
Line 75  cmdUNSUBSCRIBE(void *srv, void *arg) Line 118  cmdUNSUBSCRIBE(void *srv, void *arg)
         if (!sess)          if (!sess)
                 return -1;                  return -1;
   
         hdr = (struct mqtthdr*) sess->sess_buf->msg_base;  
   
         return 0;          return 0;
 }  }
   
 int  int
 cmdPINGREQ(void *srv, void *arg)  cmdPINGREQ(void *srv, void *arg)
 {  {
         struct mqtthdr *hdr;  
         struct tagSession *sess = (struct tagSession*) arg;          struct tagSession *sess = (struct tagSession*) arg;
         int siz = 0;          int siz = 0;
   
Line 92  cmdPINGREQ(void *srv, void *arg) Line 132  cmdPINGREQ(void *srv, void *arg)
         if (!sess)          if (!sess)
                 return -1;                  return -1;
   
        hdr = (struct mqtthdr*) sess->sess_buf->msg_base;        ioDEBUG(5, "Exec PINGREQ session");
         siz = mqtt_msgPINGRESP(sess->sess_buf);          siz = mqtt_msgPINGRESP(sess->sess_buf);
         if (siz == -1) {          if (siz == -1) {
                 ioDEBUG(5, "Error:: in msgPINGRESP #%d - %s", mqtt_GetErrno(), mqtt_GetError());                  ioDEBUG(5, "Error:: in msgPINGRESP #%d - %s", mqtt_GetErrno(), mqtt_GetError());
Line 112  cmdCONNECT(void *srv, void *arg) Line 152  cmdCONNECT(void *srv, void *arg)
 {  {
         struct tagStore *store;          struct tagStore *store;
         struct tagSession *sess = (struct tagSession*) arg;          struct tagSession *sess = (struct tagSession*) arg;
         register int i;  
   
         ioTRACE(2);          ioTRACE(2);
   
         if (!sess)          if (!sess)
                 return -1;                  return -1;
   
           ioDEBUG(5, "Exec CONNECT session");
         SESS_LOCK;          SESS_LOCK;
         TAILQ_REMOVE(&Sessions, sess, sess_node);          TAILQ_REMOVE(&Sessions, sess, sess_node);
         SESS_UNLOCK;          SESS_UNLOCK;
Line 127  cmdCONNECT(void *srv, void *arg) Line 167  cmdCONNECT(void *srv, void *arg)
                 call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%");                  call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%");
   
         SESS_ELEM_LOCK(sess);          SESS_ELEM_LOCK(sess);
        for (i = 0; i < MQTT_QOS_RESERVED; i++)        while ((store = SLIST_FIRST(&sess->sess_subscr))) {
                while ((store = SLIST_FIRST(&sess->sess_txque[i]))) {                SLIST_REMOVE_HEAD(&sess->sess_subscr, st_node);
                        SLIST_REMOVE_HEAD(&sess->sess_txque[i], st_node); 
   
                        if (store->st_subscr.sub_topic.msg_base)                if (store->st_subscr.sub_topic.msg_base)
                                free(store->st_subscr.sub_topic.msg_base);                        free(store->st_subscr.sub_topic.msg_base);
                        if (store->st_subscr.sub_value.msg_base)                if (store->st_subscr.sub_value.msg_base)
                                free(store->st_subscr.sub_value.msg_base);                        free(store->st_subscr.sub_value.msg_base);
   
                        free(store);                free(store);
                }        }
         SESS_ELEM_UNLOCK(sess);          SESS_ELEM_UNLOCK(sess);
   
         if (sess->sess_will.msg)          if (sess->sess_will.msg)
Line 160  cmdDISCONNECT(void *srv, void *arg) Line 199  cmdDISCONNECT(void *srv, void *arg)
         if (!sess)          if (!sess)
                 return -1;                  return -1;
   
           ioDEBUG(5, "Exec DISCONNECT session");
         SESS_LOCK;          SESS_LOCK;
         TAILQ_REMOVE(&Sessions, sess, sess_node);          TAILQ_REMOVE(&Sessions, sess, sess_node);
         SESS_UNLOCK;          SESS_UNLOCK;

Removed from v.1.2.2.3  
changed lines
  Added in v.1.2.2.7


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