--- mqtt/src/mqttd_calls.c 2012/06/29 13:46:37 1.2.2.30 +++ mqtt/src/mqttd_calls.c 2012/06/29 14:44:08 1.2.2.31 @@ -306,48 +306,44 @@ cmdSUBSCRIBE(void *srv, int len, void *arg) /* add to db */ for (i = 0; i < siz; i++, subs[i].sub_ret = MQTT_QOS_DENY) { - /* convert topic to sql search statement */ - if (mqtt_sqlTopic(subs[i].sub_topic.msg_base, buf, sizeof buf) == -1) { - ioDEBUG(5, "Error:: in db #%d - %s", mqtt_GetErrno(), mqtt_GetError()); + store = io_malloc(sizeof(struct tagStore)); + if (!store) { + ioSYSERR(0); continue; + } else { + store->st_msgid = mid; + mqtt_subCopy(&store->st_subscr, &subs[i]); } - if (call.WritePUB_subscribe(&cfg, pub, sess->sess_cid, mid, buf, - sess->sess_user, sess->sess_addr, subs[i].sub_ret) > 0) { - store = io_malloc(sizeof(struct tagStore)); - if (!store) { + + /* add to cache */ + SLIST_INSERT_HEAD(&sess->sess_subscr, store, st_node); + + /* convert topic to regexp */ + if (mqtt_expandTopic(subs[i].sub_topic.msg_base, buf, sizeof buf, 1, 1) == -1) { + ioDEBUG(5, "Error:: in regexp #%d - %s", mqtt_GetErrno(), mqtt_GetError()); + + subs[i].sub_ret = MQTT_QOS_DENY; + } else { + ptr = realloc(store->st_subscr.sub_topic.msg_base, strlen(buf) + 1); + if (!ptr) { ioSYSERR(0); continue; } else { - store->st_msgid = mid; - mqtt_subCopy(&store->st_subscr, &subs[i]); + store->st_subscr.sub_topic.msg_base = ptr; + store->st_subscr.sub_topic.msg_len = strlen(buf) + 1; + memcpy(store->st_subscr.sub_topic.msg_base, buf, + store->st_subscr.sub_topic.msg_len); } - /* add to cache */ - SLIST_INSERT_HEAD(&sess->sess_subscr, store, st_node); + call.LOG(logg, "Added [%s] SUBSCRIBE '%s'(%d) from %s\n", sess->sess_cid, + store->st_subscr.sub_topic.msg_base, + store->st_subscr.sub_topic.msg_len, sess->sess_addr); - /* convert topic to regexp */ - if (mqtt_expandTopic(subs[i].sub_topic.msg_base, buf, sizeof buf, 1, 1) == -1) { - ioDEBUG(5, "Error:: in regexp #%d - %s", mqtt_GetErrno(), mqtt_GetError()); - - subs[i].sub_ret = MQTT_QOS_DENY; - } else { - ptr = realloc(store->st_subscr.sub_topic.msg_base, strlen(buf) + 1); - if (!ptr) - ioSYSERR(0); - else { - store->st_subscr.sub_topic.msg_base = ptr; - store->st_subscr.sub_topic.msg_len = strlen(buf) + 1; - memcpy(store->st_subscr.sub_topic.msg_base, buf, - store->st_subscr.sub_topic.msg_len); - } - - call.LOG(logg, "Added [%s] SUBSCRIBE '%s'(%d) from %s\n", sess->sess_cid, - store->st_subscr.sub_topic.msg_base, - store->st_subscr.sub_topic.msg_len, sess->sess_addr); - - subs[i].sub_ret = MQTT_QOS_PASS; - } + subs[i].sub_ret = MQTT_QOS_PASS; } + + call.WritePUB_subscribe(&cfg, pub, sess->sess_cid, mid, buf, + sess->sess_user, sess->sess_addr, subs[i].sub_ret); } /* send acknowledge */