version 1.2.2.19, 2012/06/01 10:39:48
|
version 1.2.2.24, 2012/06/20 14:51:38
|
Line 30 mkPkt(void * __restrict data, int dlen)
|
Line 30 mkPkt(void * __restrict data, int dlen)
|
} |
} |
|
|
static inline void |
static inline void |
freePkt(struct tagPkt ** __restrict p) | freePkt(struct tagPkt * __restrict p) |
{ |
{ |
if (!p || !*p) | if (!p) |
return; |
return; |
|
|
io_freeVar(&(*p)->pkt_data); | io_freeVar(&p->pkt_data); |
io_free(*p); | io_free(p); |
*p = NULL; | |
} |
} |
|
|
static void * |
static void * |
Line 61 sendPacket(sched_task_t *task)
|
Line 60 sendPacket(sched_task_t *task)
|
} |
} |
} |
} |
|
|
|
freePkt(p); |
return NULL; |
return NULL; |
} |
} |
|
|
|
/* --------------------------------------------------- */ |
|
|
static int |
static int |
pubOnce(struct tagSession *sess, u_short mid, char * __restrict psTopic, | pubOnce(struct tagSession *sess, char * __restrict psTopic, int datlen) |
int topicLen, char * __restrict data, int datlen) | |
{ |
{ |
|
struct tagPkt *p = NULL; |
|
struct tagSession *s = NULL; |
|
struct tagStore *st = NULL; |
|
regex_t re; |
|
regmatch_t match; |
|
int ret; |
|
char szStr[STRSIZ]; |
|
|
|
TAILQ_FOREACH(s, &Sessions, sess_node) { |
|
SLIST_FOREACH(st, &s->sess_subscr, st_node) { |
|
if ((ret = regcomp(&re, st->st_subscr.sub_topic.msg_base, REG_EXTENDED))) { |
|
regerror(ret, &re, szStr, sizeof szStr); |
|
regfree(&re); |
|
ioDEBUG(3, "Error:: regcomp(%s) %s\n", (char*) |
|
st->st_subscr.sub_topic.msg_base, szStr); |
|
} |
|
if (!regexec(&re, psTopic, 1, &match, 0)) { |
|
/* MATCH */ |
|
ioDEBUG(1, "+++ dlen=%d\n", datlen); |
|
p = mkPkt(sess->sess_buf->msg_base, datlen); |
|
schedWrite(root, sendPacket, p, s->sess_sock, NULL, 0); |
|
} |
|
|
|
regfree(&re); |
|
} |
|
} |
|
|
return 0; |
return 0; |
} |
} |
|
|
static int |
static int |
pubAck(struct tagSession *sess, u_short mid, char * __restrict psTopic, | pubAck(struct tagSession *sess, char * __restrict psTopic, int datlen) |
int topicLen, char * __restrict data, int datlen) | |
{ |
{ |
return 0; |
return 0; |
} |
} |
|
|
static int |
static int |
pubExactly(struct tagSession *sess, u_short mid, char * __restrict psTopic, | pubExactly(struct tagSession *sess, char * __restrict psTopic, int datlen) |
int topicLen, char * __restrict data, int datlen) | |
{ |
{ |
return 0; |
return 0; |
} |
} |
Line 92 cmdPUBLISH(void *srv, int len, void *arg)
|
Line 117 cmdPUBLISH(void *srv, int len, void *arg)
|
{ |
{ |
struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
struct tagSession *sess = (struct tagSession*) arg; |
struct tagSession *sess = (struct tagSession*) arg; |
void *data = NULL; |
|
char szTopic[STRSIZ] = { 0 }; |
char szTopic[STRSIZ] = { 0 }; |
int siz = 0; |
int siz = 0; |
u_short mid = 0; |
u_short mid = 0; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 103 cmdPUBLISH(void *srv, int len, void *arg)
|
Line 128 cmdPUBLISH(void *srv, int len, void *arg)
|
return -1; |
return -1; |
|
|
ioDEBUG(5, "Exec PUBLISH session"); |
ioDEBUG(5, "Exec PUBLISH session"); |
siz = mqtt_readPUBLISH(sess->sess_buf, szTopic, sizeof szTopic, &mid, &data); | siz = mqtt_readPUBLISH(sess->sess_buf, szTopic, sizeof szTopic, &mid, NULL); |
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in readPUBLISH #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in readPUBLISH #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
return 0; |
return 0; |
} |
} |
|
|
|
/* duplicate packet for retransmit to subscribers */ |
|
/* |
|
pubpkt = mqtt_msgDup(sess->sess_buf); |
|
if (!pubpkt) { |
|
ioDEBUG(5, "Error:: in duplicate packet #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
|
return 0; |
|
} else |
|
*/ |
|
|
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
switch (hdr->mqtt_msg.qos) { |
switch (hdr->mqtt_msg.qos) { |
case MQTT_QOS_ACK: |
case MQTT_QOS_ACK: |
pubAck(sess, mid, szTopic, sizeof szTopic, data, siz); | pubAck(sess, szTopic, mqtt_pktLen(hdr)); |
siz = mqtt_msgPUBACK(sess->sess_buf, mid); |
siz = mqtt_msgPUBACK(sess->sess_buf, mid); |
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgPUBACK #%d - %s", |
ioDEBUG(5, "Error:: in msgPUBACK #%d - %s", |
mqtt_GetErrno(), mqtt_GetError()); |
mqtt_GetErrno(), mqtt_GetError()); |
goto end; | return 0; |
} |
} |
break; |
break; |
case MQTT_QOS_EXACTLY: |
case MQTT_QOS_EXACTLY: |
pubExactly(sess, mid, szTopic, sizeof szTopic, data, siz); | pubExactly(sess, szTopic, mqtt_pktLen(hdr)); |
siz = mqtt_msgPUBREC(sess->sess_buf, mid); |
siz = mqtt_msgPUBREC(sess->sess_buf, mid); |
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgPUBREC #%d - %s", |
ioDEBUG(5, "Error:: in msgPUBREC #%d - %s", |
mqtt_GetErrno(), mqtt_GetError()); |
mqtt_GetErrno(), mqtt_GetError()); |
goto end; | return 0; |
} |
} |
break; |
break; |
case MQTT_QOS_ONCE: |
case MQTT_QOS_ONCE: |
pubOnce(sess, mid, szTopic, sizeof szTopic, data, siz); | pubOnce(sess, szTopic, mqtt_pktLen(hdr)); |
default: |
default: |
goto end; | return 0; |
} |
} |
|
|
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
else { | schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); | |
} | |
end: | |
if (data) | |
free(data); | |
return 0; |
return 0; |
} |
} |
|
|
Line 153 cmdPUBREL(void *srv, int len, void *arg)
|
Line 181 cmdPUBREL(void *srv, int len, void *arg)
|
struct tagSession *sess = (struct tagSession*) arg; |
struct tagSession *sess = (struct tagSession*) arg; |
int siz = 0; |
int siz = 0; |
u_short mid = 0; |
u_short mid = 0; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 172 cmdPUBREL(void *srv, int len, void *arg)
|
Line 201 cmdPUBREL(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgPUBCOMP #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgPUBCOMP #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
return 0; |
return 0; |
} | } else { |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | |
else { | |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
return 0; |
return 0; |
} |
} |
|
|
Line 194 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 221 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
struct tagStore *store; |
struct tagStore *store; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
void *ptr; |
void *ptr; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 229 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 257 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
SLIST_INSERT_HEAD(&sess->sess_subscr, store, st_node); |
SLIST_INSERT_HEAD(&sess->sess_subscr, store, st_node); |
|
|
/* convert topic to regexp */ |
/* convert topic to regexp */ |
if (mqtt_expandTopic(subs[i].sub_topic.msg_base, buf, sizeof buf, 1, 0) == -1) { | 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()); |
ioDEBUG(5, "Error:: in regexp #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
goto end; | |
| subs[i].sub_ret = MQTT_QOS_DENY; |
} else { |
} else { |
ptr = realloc(store->st_subscr.sub_topic.msg_base, strlen(buf) + 1); |
ptr = realloc(store->st_subscr.sub_topic.msg_base, strlen(buf) + 1); |
if (!ptr) { |
if (!ptr) { |
ioSYSERR(0); |
ioSYSERR(0); |
goto end; | |
| subs[i].sub_ret = MQTT_QOS_DENY; |
} else { |
} else { |
store->st_subscr.sub_topic.msg_base = ptr; |
store->st_subscr.sub_topic.msg_base = ptr; |
store->st_subscr.sub_topic.msg_len = strlen(buf) + 1; |
store->st_subscr.sub_topic.msg_len = strlen(buf) + 1; |
memcpy(store->st_subscr.sub_topic.msg_base, buf, |
memcpy(store->st_subscr.sub_topic.msg_base, buf, |
store->st_subscr.sub_topic.msg_len); |
store->st_subscr.sub_topic.msg_len); |
} |
} |
} |
|
|
|
call.LOG(logg, "Added [%s] SUBSCRIBE '%s'(%d) from %s\n", sess->sess_cid, | 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_base, |
store->st_subscr.sub_topic.msg_len, sess->sess_addr); | store->st_subscr.sub_topic.msg_len, sess->sess_addr); |
|
|
subs[i].sub_ret = MQTT_QOS_PASS; | subs[i].sub_ret = MQTT_QOS_PASS; |
| } |
} else |
} else |
subs[i].sub_ret = MQTT_QOS_DENY; |
subs[i].sub_ret = MQTT_QOS_DENY; |
} |
} |
Line 259 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 289 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
goto end; |
goto end; |
} | } else { |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | |
else { | |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
end: |
end: |
mqtt_subFree(&subs); |
mqtt_subFree(&subs); |
return 0; |
return 0; |
Line 280 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
Line 309 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
u_short mid = 0; |
u_short mid = 0; |
register int i; |
register int i; |
struct tagStore *store, *tmp; |
struct tagStore *store, *tmp; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 319 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
Line 349 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgUNSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgUNSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
goto end; |
goto end; |
} | } else { |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | |
else { | |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
end: |
end: |
mqtt_subFree(&subs); |
mqtt_subFree(&subs); |
return 0; |
return 0; |